Skip to content

LLM Wiki is a cross-platform desktop application that turns your documents into an organized, interlinked knowledge base — automatically. Instead of traditional RAG (retrieve-and-answer from scratch every time), the LLM incrementally builds and maintains a persistent wiki from your sources。

TypeScript

fix: harden provider sse parsing

nash_su3b0d17bd3ce6
diff --git a/src/lib/__tests__/llm-providers.test.ts b/src/lib/__tests__/llm-providers.test.ts
index e38b7f29..cc56c5a9 100644
--- a/src/lib/__tests__/llm-providers.test.ts
+++ b/src/lib/__tests__/llm-providers.test.ts
@@ -128,6 +128,11 @@ describe("parseGoogleLine — Gemini SSE parsing", () => {
expect(parseGoogleLine(line)).toBe("Hello")
})
+ it("accepts SSE data lines without a space after the colon", () => {
+ const line = 'data:{"candidates":[{"content":{"parts":[{"text":"Hello"}]}}]}'
+ expect(parseGoogleLine(line)).toBe("Hello")
+ })
+
it("concatenates text across multiple parts in one event", () => {
// Gemini 2.5/3.x reasoning models sometimes split output across
// multiple parts in a single streaming chunk. The old parser only
@@ -178,6 +183,12 @@ describe("parseAnthropicLine — Anthropic SSE parsing", () => {
expect(parseAnthropicLine(line)).toBe("Hello world")
})
+ it("concatenates all text blocks from a complete message event", () => {
+ const line =
+ 'data: {"type":"message","id":"msg_01","role":"assistant","content":[{"type":"text","text":"Hello "},{"type":"tool_use","id":"tool_1"},{"type":"text","text":"world"}]}'
+ expect(parseAnthropicLine(line)).toBe("Hello world")
+ })
+
it("falls back to OpenAI-shaped delta.content when present", () => {
const line = 'data: {"choices":[{"delta":{"content":"fallback"}}]}'
expect(parseAnthropicLine(line)).toBe("fallback")
@@ -194,6 +205,14 @@ describe("parseAnthropicLine — Anthropic SSE parsing", () => {
})
})
+describe("parseOpenAiLine — OpenAI-compatible SSE parsing", () => {
+ it("accepts SSE data lines without a space after the colon", () => {
+ const cfg = getProviderConfig(makeConfig({ provider: "openai", model: "gpt-4.1" }))
+ const line = 'data:{"choices":[{"delta":{"content":"Hello"}}]}'
+ expect(cfg.parseStream(line)).toBe("Hello")
+ })
+})
+
describe("Claude Code CLI provider — not reachable via getProviderConfig", () => {
it("throws, because the subprocess transport dispatches one layer up in streamChat", () => {
// If this ever stops throwing, someone wired claude-code into the
diff --git a/src/lib/llm-providers.ts b/src/lib/llm-providers.ts
index e0d8bff7..a0fde2c4 100644
--- a/src/lib/llm-providers.ts
+++ b/src/lib/llm-providers.ts
@@ -153,11 +153,12 @@ export function parseAnthropicLine(line: string): string | null {
// of incremental content_block_delta chunks.
if (
parsed.type === "message" &&
- Array.isArray(parsed.content) &&
- parsed.content.length > 0 &&
- typeof (parsed.content as Array<Record<string, unknown>>)[0].text === "string"
+ Array.isArray(parsed.content)
) {
- return (parsed.content as Array<Record<string, unknown>>)[0].text as string
+ const text = (parsed.content as Array<Record<string, unknown>>)
+ .map((block) => typeof block.text === "string" ? block.text : "")
+ .join("")
+ return text.length > 0 ? text : null
}
// Fallback: misconfigured proxies occasionally return OpenAI-shaped