Implement chat queue fallback

This commit is contained in:
2026-07-08 16:57:40 +08:00
parent 10b6de0622
commit 6f3bbd3803
10 changed files with 367 additions and 31 deletions

View File

@@ -49,6 +49,7 @@ export async function streamChat(
sessionId: number,
message: string,
onChunk: (chunk: string) => void,
onStatus?: (message: string, type: string) => void,
signal?: AbortSignal,
) {
const token = getToken();
@@ -79,7 +80,14 @@ export async function streamChat(
if (!line.startsWith("data:")) continue;
const payload = line.slice(5).trim();
if (payload === "[DONE]") return;
const parsed = JSON.parse(payload) as { content?: string };
const parsed = JSON.parse(payload) as { type?: string; content?: string; message?: string };
if (parsed.type === "queued" || parsed.type === "generating") {
onStatus?.(parsed.message || "", parsed.type);
continue;
}
if (parsed.type === "error") {
throw new Error(parsed.message || "AI 回复失败");
}
if (parsed.content) onChunk(parsed.content);
}
}