ai-chatbot/lib/ai/zcode-agent/assistant-output.ts
Codex 03b8a0deb0 chore(repo): preserve production-48 source snapshot
Recover the existing 19 modified tracked files and 6 untracked source files
from the production working tree without changing their contents.

Production source HEAD: 439fd56fe120fdb9f855b50fa4df9ce2e71bb72a
Production build ID: QhoygcZ4-x42PwCgCEj1d
Captured: 2026-10-30; all 25 source file SHA256 values verified.
This is a source recovery checkpoint; no deployment was performed.
2026-10-30 15:37:23 +08:00

15 lines
702 B
TypeScript

import type { AgentRunSnapshot } from "../canvas-agent-runtime/protocol";
/** Only ordinary assistant text belongs in chat; never use reasoning/tool events. */
export function publicAssistantText(text: string) {
return text.replace(/<think>[\s\S]*?<\/think>/gi, "")
.replace(/\bZCode\b/gi, "Agent")
.replace(/(?:sk-[\w-]{12,}|Bearer\s+[\w.-]+)/gi, "[已隐藏]");
}
export function canvasAgentReplyText(snapshot: Pick<AgentRunSnapshot, "assistantText" | "message">) {
const text = snapshot.assistantText || "";
const final = publicAssistantText(snapshot.message || "").trim();
return !final || text.trimEnd().endsWith(final) ? text : text ? `${text.trimEnd()}\n\n${final}` : final;
}