Orginize
This commit is contained in:
@@ -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) }
|
||||
}
|
||||
Reference in New Issue
Block a user