This commit is contained in:
2026-08-18 18:11:28 -04:00
parent 0e9a650fa2
commit bbaf47028f
259 changed files with 0 additions and 0 deletions
@@ -0,0 +1,33 @@
/** SSE line split + data payload parse (shared by agent-openai + tests). */
/**
* Parse one SSE `data:` JSON line after the `data: ` prefix.
* @param {string} dataLine content after `data: ` prefix
*/
function bareAgentParseSseDataPayload(dataLine) {
const t = String(dataLine).trim()
if (t === '[DONE]') return { kind: 'done' }
try {
const j = JSON.parse(t)
return { kind: 'json', value: j }
} catch {
return { kind: 'raw', value: t }
}
}
/**
* Split SSE buffer into lines (keep incomplete tail).
* @param {string} buf
* @returns {{ lines: string[], rest: string }}
*/
function bareAgentSplitSseLines(buf) {
const lines = []
let start = 0
for (let i = 0; i < buf.length; i++) {
if (buf.charCodeAt(i) === 10) {
lines.push(buf.slice(start, i))
start = i + 1
}
}
return { lines, rest: buf.slice(start) }
}