feat(agent): control reasoning visibility
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user