Implement chat queue fallback
This commit is contained in:
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user