export function splitStreamContent(state, delta, flush = false) { state.pending += delta; if (!state.thinking) { const content = state.pending; state.pending = ""; return { content }; } const end = state.pending.indexOf(""); if (end >= 0) { const reasoning_content = state.pending.slice(0, end), content = state.pending.slice(end + 8); state.pending = ""; state.thinking = false; return { reasoning_content, content }; } let keep = 0; if (!flush) for (let n = 1; n < 8; n++) if (state.pending.endsWith("".slice(0, n))) keep = n; const reasoning_content = state.pending.slice(0, state.pending.length - keep); state.pending = state.pending.slice(state.pending.length - keep); return { reasoning_content }; }