incognitolm commited on
Commit ·
f75d6ae
1
Parent(s): da25d85
Update chatStream.js
Browse files- server/chatStream.js +4 -3
server/chatStream.js
CHANGED
|
@@ -32,7 +32,8 @@ async function getSafeWebSocket() {
|
|
| 32 |
try {
|
| 33 |
const cleaned = str.startsWith("data: ") ? str.slice(6) : str;
|
| 34 |
return JSON.parse(cleaned);
|
| 35 |
-
} catch {
|
|
|
|
| 36 |
return null;
|
| 37 |
}
|
| 38 |
};
|
|
@@ -194,7 +195,7 @@ export async function websocketChatStream(body, headers, onToken, abortSignal) {
|
|
| 194 |
if (!payload) return;
|
| 195 |
|
| 196 |
if (payload.error && !payload.choices) {
|
| 197 |
-
if (onToken) onToken(`[ERROR] ${payload.error}`);
|
| 198 |
if (!finished) { finished = true; cleanup(); resolve({ assistantText, toolCalls: [...toolCallBuffer.values()] }); }
|
| 199 |
return;
|
| 200 |
}
|
|
@@ -372,7 +373,7 @@ export async function streamChat({
|
|
| 372 |
const followUpBody = {
|
| 373 |
model: model || "lightning",
|
| 374 |
messages: followUpMessages,
|
| 375 |
-
tools: enabledTools
|
| 376 |
stream: true,
|
| 377 |
};
|
| 378 |
|
|
|
|
| 32 |
try {
|
| 33 |
const cleaned = str.startsWith("data: ") ? str.slice(6) : str;
|
| 34 |
return JSON.parse(cleaned);
|
| 35 |
+
} catch (err) {
|
| 36 |
+
console.warn("[WS] JSON parse error:", err, "on string:", str);
|
| 37 |
return null;
|
| 38 |
}
|
| 39 |
};
|
|
|
|
| 195 |
if (!payload) return;
|
| 196 |
|
| 197 |
if (payload.error && !payload.choices) {
|
| 198 |
+
if (onToken) onToken(`[ERROR] ${JSON.stringify(payload.error)}`);
|
| 199 |
if (!finished) { finished = true; cleanup(); resolve({ assistantText, toolCalls: [...toolCallBuffer.values()] }); }
|
| 200 |
return;
|
| 201 |
}
|
|
|
|
| 373 |
const followUpBody = {
|
| 374 |
model: model || "lightning",
|
| 375 |
messages: followUpMessages,
|
| 376 |
+
tools: enabledTools,
|
| 377 |
stream: true,
|
| 378 |
};
|
| 379 |
|