fix: handle surfsense stream format correctly
Surfsense sends data: {"type":"text-delta","delta":"text"} — use
raw.delta (not raw.content) and filter events by type. Skip non-text
events (thinking steps, start, etc) to produce clean Anthropic SSE.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Fable 5
parent
2fead57d0f
commit
2be57c0838
+5
-3
@@ -76,11 +76,13 @@ export const MODEL_ROUTES: Record<string, BackendConfig> = {
|
||||
messages: req.messages,
|
||||
}),
|
||||
adaptStreamLine: (line) => {
|
||||
// surfsense returns lines like: data: {"content":"Hello","done":false}
|
||||
if (!line.startsWith("data: ")) return null;
|
||||
try {
|
||||
const raw = JSON.parse(line.slice(6));
|
||||
if (raw.done) return "data: [DONE]";
|
||||
if (raw.type === "finish" || raw.done) return "data: [DONE]";
|
||||
if (raw.type !== "text-delta") return null;
|
||||
const text = raw.delta ?? raw.content ?? "";
|
||||
if (!text) return null;
|
||||
return `data: ${JSON.stringify({
|
||||
id: `chatcmpl-${Date.now()}`,
|
||||
object: "chat.completion.chunk",
|
||||
@@ -89,7 +91,7 @@ export const MODEL_ROUTES: Record<string, BackendConfig> = {
|
||||
choices: [
|
||||
{
|
||||
index: 0,
|
||||
delta: { content: raw.content ?? "" },
|
||||
delta: { content: text },
|
||||
finish_reason: null,
|
||||
},
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user