feat(agent): control reasoning visibility

This commit is contained in:
2026-07-17 14:05:54 +08:00
parent bfaf2ebf67
commit a879dc2ff1
18 changed files with 368 additions and 51 deletions

View File

@@ -83,7 +83,8 @@ export async function streamChat(
sessionId: number,
message: string,
onChunk: (chunk: string) => void,
onStatus?: (message: string, type: string) => void,
onReasoning?: (chunk: string) => void,
onStatus?: (message: string, type: string, reasoningVisible: boolean) => void,
signal?: AbortSignal,
) {
const token = getToken();
@@ -114,15 +115,21 @@ export async function streamChat(
if (!dataLines.length) continue;
const payload = dataLines.map((line) => line.slice(5).trimStart()).join("\n").trim();
if (payload === "[DONE]") return;
const parsed = JSON.parse(payload) as { type?: string; content?: string; message?: string };
const parsed = JSON.parse(payload) as {
type?: string;
content?: string;
message?: string;
reasoningVisible?: boolean;
};
if (parsed.type === "queued" || parsed.type === "generating") {
onStatus?.(parsed.message || "", parsed.type);
onStatus?.(parsed.message || "", parsed.type, Boolean(parsed.reasoningVisible));
continue;
}
if (parsed.type === "error") {
throw new Error(parsed.message || "AI 回复失败");
}
if (parsed.content) onChunk(parsed.content);
if (parsed.type === "reasoning" && parsed.content) onReasoning?.(parsed.content);
if (parsed.type === "content" && parsed.content) onChunk(parsed.content);
}
}
}