incognitolm commited on
Commit ·
68425fa
1
Parent(s): 3ff6f4d
Update chatStream.js
Browse files- server/chatStream.js +7 -1
server/chatStream.js
CHANGED
|
@@ -65,7 +65,13 @@ export async function websocketChatStream(body, headers, onToken, abortSignal) {
|
|
| 65 |
const ws = new WebSocket(wsURL);
|
| 66 |
|
| 67 |
const safeParse = (str) => {
|
| 68 |
-
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
};
|
| 70 |
|
| 71 |
await new Promise((resolve, reject) => {
|
|
|
|
| 65 |
const ws = new WebSocket(wsURL);
|
| 66 |
|
| 67 |
const safeParse = (str) => {
|
| 68 |
+
try {
|
| 69 |
+
// Strip "data: " prefix if present (Server-Sent Events format)
|
| 70 |
+
const cleaned = str.startsWith('data: ') ? str.slice(6) : str;
|
| 71 |
+
return JSON.parse(cleaned);
|
| 72 |
+
} catch {
|
| 73 |
+
return null;
|
| 74 |
+
}
|
| 75 |
};
|
| 76 |
|
| 77 |
await new Promise((resolve, reject) => {
|