llm-switcher 1.6.5 → 1.6.7
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.
- package/CHANGELOG.md +12 -0
- package/compaction.mjs +72 -0
- package/docs/goal-check.md +75 -0
- package/formats.mjs +107 -35
- package/goalcheck-call.mjs +208 -0
- package/goalcheck.mjs +498 -0
- package/maintenance/gateway-upstream-watch/REPOSITORIES.md +64 -0
- package/maintenance/gateway-upstream-watch/SKILL.md +18 -0
- package/maintenance/gateway-upstream-watch/prompt.vi.md +11 -0
- package/maintenance/gateway-upstream-watch/references/repos.json +570 -0
- package/maintenance/gateway-upstream-watch/watch.py +222 -0
- package/package.json +1 -1
- package/preflight-check.mjs +188 -0
- package/proxy.mjs +393 -53
- package/shim.mjs +13 -2
- package/state.mjs +5 -0
- package/tests/codex-daemon.test.mjs +1 -0
- package/tests/compaction.e2e.test.mjs +79 -0
- package/tests/gateway-contract.test.mjs +59 -0
- package/tests/gateway.e2e.test.mjs +47 -0
- package/tests/goalcheck.e2e.test.mjs +316 -0
- package/tests/goalcheck.test.mjs +312 -0
- package/tests/preflight.test.mjs +119 -0
- package/tests/tool-repair.test.mjs +119 -2
- package/tests/update.test.mjs +2 -2
- package/tests/upstream-stream.test.mjs +30 -0
- package/toolvocab.mjs +59 -11
- package/ui.html +676 -1
- package/upstream-stream.mjs +37 -0
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
// SSE dispatches one event at a blank line; data fields are joined with newlines.
|
|
2
|
+
// Vertex also sends bare JSON lines. Keep both framings without parsing data fields separately.
|
|
3
|
+
export async function* readUpstreamPayloads(upstreamRes) {
|
|
4
|
+
const reader = upstreamRes.body.getReader();
|
|
5
|
+
const decoder = new TextDecoder();
|
|
6
|
+
let buffer = '', data = [], finished = false;
|
|
7
|
+
const parse = value => {
|
|
8
|
+
const text = value.trim();
|
|
9
|
+
if (!text || text === '[DONE]') return null;
|
|
10
|
+
return JSON.parse(text);
|
|
11
|
+
};
|
|
12
|
+
function line(value) {
|
|
13
|
+
if (value.endsWith('\r')) value = value.slice(0, -1);
|
|
14
|
+
if (!value) { const payload = data.join('\n'); data = []; return parse(payload); }
|
|
15
|
+
if (value.startsWith('data:')) { data.push(value.slice(5).replace(/^ /, '')); return null; }
|
|
16
|
+
if (value.startsWith('{') && !data.length) return parse(value);
|
|
17
|
+
return null;
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
while (true) {
|
|
21
|
+
const chunk = await reader.read();
|
|
22
|
+
if (chunk.done) { finished = true; buffer += decoder.decode(); break; }
|
|
23
|
+
buffer += decoder.decode(chunk.value, { stream: true });
|
|
24
|
+
let newline;
|
|
25
|
+
while ((newline = buffer.indexOf('\n')) !== -1) {
|
|
26
|
+
const payload = line(buffer.slice(0, newline)); buffer = buffer.slice(newline + 1);
|
|
27
|
+
if (payload) yield payload;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
if (buffer) { const payload = line(buffer); if (payload) yield payload; }
|
|
31
|
+
// Tolerate an upstream's missing final blank line; completion is validated by the caller.
|
|
32
|
+
const tail = parse(data.join('\n')); if (tail) yield tail;
|
|
33
|
+
} finally {
|
|
34
|
+
if (!finished) await reader.cancel().catch(() => {});
|
|
35
|
+
reader.releaseLock();
|
|
36
|
+
}
|
|
37
|
+
}
|