| 4512 | } |
| 4513 | |
| 4514 | function parseSseFrame(frame) { |
| 4515 | const lines = frame.split(/\r?\n/); |
| 4516 | let event = "message"; |
| 4517 | const dataLines = []; |
| 4518 | lines.forEach((line) => { |
| 4519 | if (line.startsWith("event:")) event = line.slice(6).trim(); |
| 4520 | if (line.startsWith("data:")) dataLines.push(line.slice(5).trimStart()); |
| 4521 | }); |
| 4522 | if (!dataLines.length) return null; |
| 4523 | return { event, data: JSON.parse(dataLines.join("\n")) }; |
| 4524 | } |
| 4525 | |
| 4526 | async function streamWikiAsk(payload, answerTarget, message) { |
| 4527 | const response = await fetch("/api/wiki/ask/stream", { |