Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Merge remote-tracking branch 'origin/main' into fix/llm-stream-clean-close-10883
Elian Doran2652c1309eb3
diff --cc apps/client/src/services/llm_chat.tsindex d9a39a6b5b,a124166e3a..f63b1381af--- a/apps/client/src/services/llm_chat.ts+++ b/apps/client/src/services/llm_chat.ts@@@ -149,10 -179,7 +186,10 @@@ async function streamChatOverSsefor (const line of lines) {if (line.startsWith("data: ")) {try {- const terminal = await handleChunk(JSON.parse(line.slice(6)), callbacks);- await handleChunk(streamId, JSON.parse(line.slice(6)), callbacks);++ const terminal = await handleChunk(streamId, JSON.parse(line.slice(6)), callbacks);+ if (terminal) {+ terminalChunk = terminal;+ }} catch (e) {console.error("Failed to parse SSE data line:", line, e);}@@@ -263,9 -281,15 +300,16 @@@ function rejectWhenAborted(signal?: Abo* Dispatch one chunk to the callbacks. Shared by both transports, so a chunk means* the same thing however it arrived.*/+/** Returns the stream's terminal chunk type when this chunk ends it, else null. */- async function handleChunk(chunk: LlmStreamChunk, callbacks: StreamCallbacks): Promise<"done" | "error" | null> {+ async function handleChunk(+ streamId: string,+ chunk: LlmStreamChunk,+ callbacks: StreamCallbacks-): Promise<void> {++): Promise<"done" | "error" | null> {switch (chunk.type) {+ case "status":+ callbacks.onStatus?.(chunk.status);+ break;case "text":callbacks.onChunk(chunk.content);break;