Files
Jyotisha/frontend/src/lib/public-thinking.ts
T
Jesse_Chen 4e247c112e fix(web): keep thinking off the spoken consult and rectification answer
Enumerate evidence kinds so education cannot be proposed as a kind, and stream Chinese thinking on a separate channel that collapses when the reply arrives.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-08-21 21:30:55 +08:00

20 lines
804 B
TypeScript

/**
* Sanitize text that may appear on the public thinking channel.
*
* English-only process narration, tool ids and UUIDs stay off the client.
* Chinese thinking fragments are allowed through a dedicated event type,
* never through the spoken answer.
*/
const CJK_RE = /[\u4e00-\u9fff]/;
const PUBLIC_THINKING_UUID_RE = /[0-9a-f]{8}-[0-9a-f]{4}-[1-5][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}/gi;
const PUBLIC_THINKING_TOOL_RE = /(?:rectification|run-jyotish)-[a-z0-9-]+/gi;
export function sanitizePublicThinkingText(text: string): string | null {
const cleaned = text
.replace(PUBLIC_THINKING_UUID_RE, "")
.replace(PUBLIC_THINKING_TOOL_RE, "");
if (!cleaned) return null;
if (/[A-Za-z]{4,}/.test(cleaned) && !CJK_RE.test(cleaned)) return null;
return cleaned.slice(0, 4_000);
}