llm-switcher 1.6.8 → 1.6.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,11 +1,13 @@
1
1
  // SSE dispatches one event at a blank line; data fields are joined with newlines.
2
2
  // Vertex also sends bare JSON lines. Keep both framings without parsing data fields separately.
3
- export async function* readUpstreamPayloads(upstreamRes) {
3
+ // `state.done` turns true on an OpenAI [DONE] line, which ends a stream cleanly even without a finish reason.
4
+ export async function* readUpstreamPayloads(upstreamRes, state = {}) {
4
5
  const reader = upstreamRes.body.getReader();
5
6
  const decoder = new TextDecoder();
6
7
  let buffer = '', data = [], finished = false;
7
8
  const parse = value => {
8
9
  const text = value.trim();
10
+ if (text === '[DONE]') state.done = true;
9
11
  if (!text || text === '[DONE]') return null;
10
12
  return JSON.parse(text);
11
13
  };