mirror of
https://github.com/binaricat/Netcatty.git
synced 2026-11-23 16:42:19 +00:00
Older AxonHub 0.9 and some intranet OpenAI-compat proxies emit
`data:{json}` instead of `data: {json}`. The stream parser required
the space, so chat chunks were dropped while the model-list probe
still succeeded.
Parse `data:` per the EventSource spec (optional single space) and
cover both the line and end-of-stream flush paths.
Closes #3020
20 lines
703 B
JavaScript
20 lines
703 B
JavaScript
/**
|
|
* Extract the payload of an SSE `data:` field.
|
|
*
|
|
* The WHATWG EventSource spec treats the space after the colon as optional
|
|
* and strips at most one leading U+0020. Older AxonHub (0.9) and some
|
|
* intranet OpenAI-compat proxies emit `data:{json}` with no space, which
|
|
* a `data: ` prefix check silently drops (issue #3020).
|
|
*
|
|
* @param {unknown} line
|
|
* @returns {string | null}
|
|
*/
|
|
function extractSseDataPayload(line) {
|
|
const trimmed = typeof line === "string" ? line.trim() : "";
|
|
if (!trimmed.startsWith("data:")) return null;
|
|
const payload = trimmed.slice("data:".length);
|
|
return payload.startsWith(" ") ? payload.slice(1) : payload;
|
|
}
|
|
|
|
module.exports = { extractSseDataPayload };
|