22 lines
872 B
TypeScript
22 lines
872 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"> & {
|
|
verification?: AgentRunSnapshot["verification"];
|
|
},
|
|
) {
|
|
const final = publicAssistantText(snapshot.message || "").trim();
|
|
if (snapshot.verification && snapshot.verification.passed === false && final) {
|
|
return final;
|
|
}
|
|
const text = snapshot.assistantText || "";
|
|
return !final || text.trimEnd().endsWith(final) ? text : text ? `${text.trimEnd()}\n\n${final}` : final;
|
|
}
|