omnicell-router 0.7.0 → 0.8.2
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/backend/dist/cli/clients/activity.d.ts +35 -0
- package/backend/dist/cli/clients/activity.js +67 -0
- package/backend/dist/cli/clients/base.d.ts +13 -2
- package/backend/dist/cli/clients/claude.d.ts +2 -2
- package/backend/dist/cli/clients/codex.d.ts +2 -2
- package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
- package/backend/dist/cli/clients/core-adapters.js +3 -4
- package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
- package/backend/dist/cli/clients/cursor-proxy.js +421 -0
- package/backend/dist/cli/clients/dsh.d.ts +2 -2
- package/backend/dist/cli/clients/grok.d.ts +2 -2
- package/backend/dist/cli/clients/index.d.ts +8 -1
- package/backend/dist/cli/clients/index.js +55 -21
- package/backend/dist/cli/clients/kimi.d.ts +2 -2
- package/backend/dist/cli/clients/launcher.d.ts +8 -0
- package/backend/dist/cli/clients/model-meta.js +1 -1
- package/backend/dist/cli/clients/omp.d.ts +2 -2
- package/backend/dist/cli/clients/openclaw.d.ts +2 -2
- package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
- package/backend/dist/cli/clients/opencode-proxy.js +351 -0
- package/backend/dist/cli/clients/opencode.d.ts +2 -2
- package/backend/dist/cli/clients/pi.d.ts +2 -2
- package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
- package/backend/dist/cli/clients/plugin-adapters.js +6 -29
- package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
- package/backend/dist/cli/clients/qoder-proxy.js +497 -0
- package/backend/dist/cli/clients/reserved.d.ts +2 -6
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
- package/backend/dist/cli/index.js +60 -9
- package/backend/dist/cli/types.d.ts +29 -8
- package/backend/dist/compression/caveman-prompts.d.ts +1 -1
- package/backend/dist/config/comments-en.js +6 -12
- package/backend/dist/config/comments-zh.js +6 -12
- package/backend/dist/config/defaults.d.ts +56 -1
- package/backend/dist/config/defaults.js +68 -0
- package/backend/dist/config/index.d.ts +9 -2
- package/backend/dist/config/index.js +26 -3
- package/backend/dist/config/types.d.ts +55 -43
- package/backend/dist/forward-proxy/egress.d.ts +10 -2
- package/backend/dist/forward-proxy/egress.js +42 -4
- package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/forward-proxy/ordered-relay.js +46 -0
- package/backend/dist/forward-proxy/rules.d.ts +66 -19
- package/backend/dist/forward-proxy/rules.js +61 -14
- package/backend/dist/forward-proxy/server.js +226 -77
- package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
- package/backend/dist/forward-proxy/system-proxy.js +199 -22
- package/backend/dist/harness/common/market.d.ts +3 -3
- package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
- package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
- package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
- package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
- package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
- package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
- package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
- package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
- package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
- package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
- package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
- package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
- package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
- package/backend/dist/harness/translation.js +64 -21
- package/backend/dist/harness/types.d.ts +1 -1
- package/backend/dist/harness/types.js +1 -1
- package/backend/dist/index.js +31 -18
- package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
- package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
- package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
- package/backend/dist/ir/adapters/anthropic.js +788 -0
- package/backend/dist/ir/adapters/chat.d.ts +15 -0
- package/backend/dist/ir/adapters/chat.js +602 -0
- package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
- package/backend/dist/ir/adapters/google-stream.js +242 -0
- package/backend/dist/ir/adapters/google.d.ts +9 -0
- package/backend/dist/ir/adapters/google.js +317 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
- package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
- package/backend/dist/ir/adapters/openai-responses.js +26 -1
- package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
- package/backend/dist/ir/adapters/responses-output.js +348 -0
- package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
- package/backend/dist/ir/adapters/responses-stream.js +178 -0
- package/backend/dist/ir/adapters/responses.d.ts +14 -0
- package/backend/dist/ir/adapters/responses.js +646 -0
- package/backend/dist/ir/errors.d.ts +2 -2
- package/backend/dist/ir/types.d.ts +2 -1
- package/backend/dist/metrics/request-cost.d.ts +11 -2
- package/backend/dist/metrics/request-cost.js +12 -3
- package/backend/dist/observability/request-identity.d.ts +1 -1
- package/backend/dist/observability/trace-id.d.ts +40 -0
- package/backend/dist/observability/trace-id.js +134 -0
- package/backend/dist/observability/upstream-events.d.ts +82 -60
- package/backend/dist/observability/upstream-events.js +142 -67
- package/backend/dist/opencode/catalog/types.d.ts +9 -0
- package/backend/dist/opencode/credentials/types.d.ts +2 -2
- package/backend/dist/opencode/probe.d.ts +24 -1
- package/backend/dist/opencode/probe.js +28 -4
- package/backend/dist/opencode/user-config.d.ts +5 -0
- package/backend/dist/pipeline/directives.d.ts +6 -2
- package/backend/dist/pipeline/directives.js +7 -3
- package/backend/dist/pipeline/orchestrator.d.ts +28 -27
- package/backend/dist/pipeline/orchestrator.js +220 -194
- package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
- package/backend/dist/pipeline/unresolved-model.js +43 -0
- package/backend/dist/plugins/catalog-def.d.ts +143 -0
- package/backend/dist/plugins/catalog-def.js +177 -0
- package/backend/dist/plugins/gateways.d.ts +62 -3
- package/backend/dist/plugins/gateways.js +139 -2
- package/backend/dist/plugins/host.d.ts +42 -5
- package/backend/dist/plugins/host.js +454 -38
- package/backend/dist/plugins/manifest.d.ts +119 -10
- package/backend/dist/plugins/manifest.js +265 -14
- package/backend/dist/plugins/pack.js +26 -0
- package/backend/dist/plugins/types.d.ts +187 -21
- package/backend/dist/protocols/systemone/convert.d.ts +1 -0
- package/backend/dist/protocols/systemone/convert.js +6 -1
- package/backend/dist/protocols/systemone/decide.js +18 -8
- package/backend/dist/providers/anthropic-messages.d.ts +12 -0
- package/backend/dist/providers/anthropic-messages.js +53 -0
- package/backend/dist/providers/anthropic.d.ts +7 -8
- package/backend/dist/providers/anthropic.js +36 -324
- package/backend/dist/providers/base.d.ts +14 -2
- package/backend/dist/providers/boot-direct.js +68 -38
- package/backend/dist/providers/dispatch.d.ts +5 -19
- package/backend/dist/providers/dispatch.js +46 -58
- package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
- package/backend/dist/providers/executors/anthropic-messages.js +3 -0
- package/backend/dist/providers/executors/dispatch.d.ts +16 -2
- package/backend/dist/providers/executors/dispatch.js +39 -9
- package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
- package/backend/dist/providers/executors/google-gemini.js +3 -0
- package/backend/dist/providers/executors/http-stream.js +16 -3
- package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
- package/backend/dist/providers/executors/openai-chat.js +3 -0
- package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
- package/backend/dist/providers/executors/openai-responses.js +3 -0
- package/backend/dist/providers/executors/plugin-adapter.js +4 -4
- package/backend/dist/providers/google-gemini.d.ts +12 -0
- package/backend/dist/providers/google-gemini.js +50 -0
- package/backend/dist/providers/google.d.ts +7 -8
- package/backend/dist/providers/google.js +35 -308
- package/backend/dist/providers/http-json.d.ts +19 -0
- package/backend/dist/providers/http-json.js +104 -0
- package/backend/dist/providers/http-stream.d.ts +52 -0
- package/backend/dist/providers/http-stream.js +423 -0
- package/backend/dist/providers/member-match.d.ts +4 -5
- package/backend/dist/providers/member-match.js +4 -5
- package/backend/dist/providers/openai-chat.d.ts +13 -0
- package/backend/dist/providers/openai-chat.js +99 -0
- package/backend/dist/providers/openai-compatible.d.ts +7 -4
- package/backend/dist/providers/openai-compatible.js +71 -368
- package/backend/dist/providers/openai-responses.d.ts +12 -0
- package/backend/dist/providers/openai-responses.js +68 -0
- package/backend/dist/providers/opencode-proxy.d.ts +5 -5
- package/backend/dist/providers/opencode-proxy.js +49 -125
- package/backend/dist/providers/plugin-adapter.d.ts +9 -0
- package/backend/dist/providers/plugin-adapter.js +31 -0
- package/backend/dist/providers/registry.d.ts +49 -24
- package/backend/dist/providers/registry.js +97 -55
- package/backend/dist/providers/responses.d.ts +7 -28
- package/backend/dist/providers/responses.js +45 -253
- package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
- package/backend/dist/providers/tool-markup-leak.js +57 -0
- package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
- package/backend/dist/providers/tool-markup-recovery.js +786 -0
- package/backend/dist/providers/virtual-meta.d.ts +21 -2
- package/backend/dist/providers/virtual-meta.js +49 -9
- package/backend/dist/proxy/asset-download.d.ts +54 -0
- package/backend/dist/proxy/asset-download.js +420 -0
- package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
- package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
- package/backend/dist/proxy/mihomo-binary.js +62 -51
- package/backend/dist/proxy/mihomo-client.js +15 -1
- package/backend/dist/proxy/mihomo-config.js +11 -2
- package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/proxy/mihomo-geo.js +213 -0
- package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
- package/backend/dist/proxy/mihomo-logs.js +70 -0
- package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
- package/backend/dist/proxy/mihomo-pac.js +15 -0
- package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
- package/backend/dist/proxy/mihomo-rules-import.js +7 -7
- package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
- package/backend/dist/proxy/mihomo-sidecar.js +148 -26
- package/backend/dist/quota/adapters/minimax.js +36 -13
- package/backend/dist/quota/cli-login.d.ts +8 -0
- package/backend/dist/quota/cli-login.js +18 -0
- package/backend/dist/quota/declarations.js +10 -0
- package/backend/dist/quota/dsl.js +18 -5
- package/backend/dist/quota/engine.d.ts +22 -1
- package/backend/dist/quota/engine.js +170 -29
- package/backend/dist/quota/prober.d.ts +5 -0
- package/backend/dist/quota/prober.js +11 -2
- package/backend/dist/quota/types.d.ts +87 -8
- package/backend/dist/quota/verdict.d.ts +35 -0
- package/backend/dist/quota/verdict.js +135 -0
- package/backend/dist/ratelimit/admission.d.ts +131 -0
- package/backend/dist/ratelimit/admission.js +233 -0
- package/backend/dist/ratelimit/rate-limiter.js +6 -0
- package/backend/dist/resilience/types.d.ts +2 -2
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +5 -8
- package/backend/dist/routes/console.js +248 -52
- package/backend/dist/routes/mihomo.d.ts +2 -0
- package/backend/dist/routes/mihomo.js +334 -29
- package/backend/dist/routes/responses.d.ts +87 -8
- package/backend/dist/routes/responses.js +314 -33
- package/backend/dist/server.js +34 -6
- package/backend/dist/session/session-manager.d.ts +6 -0
- package/backend/dist/session/session-manager.js +20 -9
- package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
- package/backend/dist/surfaces/chat-pipeline.js +17 -7
- package/backend/dist/surfaces/chat.js +15 -0
- package/backend/dist/surfaces/decision-pipeline.js +7 -10
- package/backend/dist/surfaces/direct-forward.d.ts +3 -0
- package/backend/dist/surfaces/direct-forward.js +206 -0
- package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
- package/backend/dist/surfaces/rate-limit-response.js +57 -0
- package/backend/dist/surfaces/types.d.ts +11 -0
- package/backend/dist/trace/tracker.d.ts +32 -1
- package/backend/dist/trace/tracker.js +29 -4
- package/backend/dist/types/router.d.ts +34 -12
- package/backend/dist/types/router.js +35 -6
- package/backend/dist/utils/chat-stream.d.ts +21 -8
- package/backend/dist/utils/chat-stream.js +46 -9
- package/backend/dist/utils/event-ring.d.ts +4 -0
- package/backend/dist/utils/event-ring.js +4 -0
- package/backend/dist/utils/popularity.js +29 -4
- package/backend/dist/utils/proxy.d.ts +7 -0
- package/backend/dist/utils/proxy.js +35 -10
- package/backend/dist/utils/retry-after.d.ts +21 -0
- package/backend/dist/utils/retry-after.js +36 -0
- package/bin/ocr.js +2 -2
- package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
- package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.css} +1 -1
- package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
- package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
|
@@ -65,12 +65,30 @@ export function effortFromThinkingBudget(tokens) {
|
|
|
65
65
|
* `EFFORT_LADDER` (assume the model supports everything); an explicit
|
|
66
66
|
* EMPTY array → `'none'` (the model serves no explicit level).
|
|
67
67
|
*/
|
|
68
|
-
export function downgradeReasoning(requested, supported) {
|
|
68
|
+
export function downgradeReasoning(requested, supported, alwaysThink = false) {
|
|
69
69
|
const reqRank = EFFORT_LADDER.indexOf(requested);
|
|
70
70
|
const candidates = (supported ?? EFFORT_LADDER)
|
|
71
71
|
.filter((lvl) => EFFORT_LADDER.indexOf(lvl) <= reqRank)
|
|
72
72
|
.sort((a, b) => EFFORT_LADDER.indexOf(b) - EFFORT_LADDER.indexOf(a));
|
|
73
|
-
|
|
73
|
+
if (candidates.length > 0)
|
|
74
|
+
return candidates[0];
|
|
75
|
+
// Nothing in the ladder sits at or below the ask. An ALWAYS-THINK model
|
|
76
|
+
// carries no `none` by construction (ADR-0035 withholding), so answering
|
|
77
|
+
// thinking-off here would send a level its vendor refuses — land on the
|
|
78
|
+
// lowest rung the model actually declares. A plain table that merely omits
|
|
79
|
+
// `none` keeps the ADR-0011 down-direction contract: thinking-off is legal.
|
|
80
|
+
if (alwaysThink)
|
|
81
|
+
return lowestSupportedEffort(supported) ?? 'none';
|
|
82
|
+
return 'none';
|
|
83
|
+
}
|
|
84
|
+
/** The lowest level a DECLARED support set can serve (`undefined` for an empty
|
|
85
|
+
* or undeclared set). The floor an always-think model is clamped to when an
|
|
86
|
+
* ask or a directive step would otherwise land on `none` the vendor forbids
|
|
87
|
+
* (ADR-0035: a table without `none` can never serve thinking-off). */
|
|
88
|
+
export function lowestSupportedEffort(supported) {
|
|
89
|
+
if (!supported || supported.length === 0)
|
|
90
|
+
return undefined;
|
|
91
|
+
return [...supported].sort((a, b) => EFFORT_LADDER.indexOf(a) - EFFORT_LADDER.indexOf(b))[0];
|
|
74
92
|
}
|
|
75
93
|
/**
|
|
76
94
|
* Shared resolution of a model's explicit-effort support (registry pick +
|
|
@@ -79,11 +97,22 @@ export function downgradeReasoning(requested, supported) {
|
|
|
79
97
|
* - the legacy boolean `true` → the full EFFORT_LADDER;
|
|
80
98
|
* - otherwise `undefined` = "no explicit effort control" (callers decide:
|
|
81
99
|
* selection skips the candidate; wire-side recompute clamps to `[]`).
|
|
100
|
+
* `disableable === false` (the vendor's always-think fact, ADR-0035) strips
|
|
101
|
+
* `none` from the resolved set on EVERY branch — the withholding must hold at
|
|
102
|
+
* the routing plane, not only on the published effort table.
|
|
82
103
|
*/
|
|
83
|
-
export function modelSupportsEfforts(supported, legacyFlag) {
|
|
84
|
-
|
|
85
|
-
|
|
104
|
+
export function modelSupportsEfforts(supported, legacyFlag, disableable) {
|
|
105
|
+
// An always-think model NEVER serves `none` (ADR-0035): strip it from any
|
|
106
|
+
// resolved set — a stale config table, a legacy boolean expansion, a hand-
|
|
107
|
+
// written registration. A set that empties under the strip falls through to
|
|
108
|
+
// "no explicit effort control", never back to a ladder that re-admits it.
|
|
109
|
+
const withoutNone = (levels) => disableable === false ? levels.filter((e) => e !== 'none') : [...levels];
|
|
110
|
+
if (supported && supported.length > 0) {
|
|
111
|
+
const kept = withoutNone(supported);
|
|
112
|
+
if (kept.length > 0)
|
|
113
|
+
return kept;
|
|
114
|
+
}
|
|
86
115
|
if (legacyFlag === true)
|
|
87
|
-
return
|
|
116
|
+
return withoutNone(EFFORT_LADDER);
|
|
88
117
|
return undefined;
|
|
89
118
|
}
|
|
@@ -56,6 +56,17 @@ export interface StreamRelay {
|
|
|
56
56
|
stageRouting(facts: StreamRoutingFacts): void;
|
|
57
57
|
/** One upstream chunk, in arrival order. Flushes headers on the first call. */
|
|
58
58
|
onChunk(chunk: ChatCompletionChunk): void;
|
|
59
|
+
/**
|
|
60
|
+
* Which transport the served attempt actually used (called ONCE per
|
|
61
|
+
* attempt, before the first chunk): `'sse'` = the upstream SSE reader ran,
|
|
62
|
+
* `'buffered'` = one `createCompletion` call (wire without a streaming
|
|
63
|
+
* executor, mock mode, or `streaming.upstream.mode: buffered`).
|
|
64
|
+
*
|
|
65
|
+
* Optional so test relays stay one-liners. The pool uses it to tag the
|
|
66
|
+
* trace / `X-OCR-Upstream-Stream` without guessing from timing (a stream
|
|
67
|
+
* that produced no chunks still says `'sse'`).
|
|
68
|
+
*/
|
|
69
|
+
onTransport?(kind: 'sse' | 'buffered'): void;
|
|
59
70
|
/** True once any byte has reached the client — the no-failover boundary. */
|
|
60
71
|
readonly committed: boolean;
|
|
61
72
|
}
|
|
@@ -64,15 +75,17 @@ export interface StreamRelay {
|
|
|
64
75
|
* `chat.completion` response shape — the object every post-turn consumer and the
|
|
65
76
|
* non-streaming wire already depend on.
|
|
66
77
|
*
|
|
67
|
-
* The typed `delta` carries only role/content/tool_calls;
|
|
68
|
-
* DeepSeek
|
|
69
|
-
* folded into the assembled response:
|
|
70
|
-
*
|
|
71
|
-
*
|
|
72
|
-
*
|
|
73
|
-
*
|
|
78
|
+
* The typed `delta` carries only role/content/reasoning_content/tool_calls;
|
|
79
|
+
* upstreams (Qwen, DeepSeek, ...) additionally send `reasoning_content`.
|
|
80
|
+
* Thinking text IS folded into the assembled response: thinking-mode upstreams
|
|
81
|
+
* (DeepSeek in particular) require the previous turns' reasoning to be passed
|
|
82
|
+
* back on the next request, so every wire that rebuilds history from this
|
|
83
|
+
* accumulator — the Responses encoder, the session echo, the buffered SSE
|
|
84
|
+
* synthesis — must be able to replay it verbatim.
|
|
74
85
|
*/
|
|
75
|
-
export declare function createChunkAccumulator(
|
|
86
|
+
export declare function createChunkAccumulator(options?: {
|
|
87
|
+
maxChars?: number;
|
|
88
|
+
}): {
|
|
76
89
|
push: (chunk: ChatCompletionChunk) => void;
|
|
77
90
|
finish: () => ChatCompletionResponse;
|
|
78
91
|
};
|
|
@@ -1,23 +1,51 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Maximum assistant payload (content + tool-call arguments) one accumulator
|
|
3
|
+
* may hold: 32 Mi chars ≈ 32–128 MiB depending on script density. Declared
|
|
4
|
+
* once — the streamed transport and the accumulate-only transport share this
|
|
5
|
+
* ceiling, so a runaway upstream cannot turn into unbounded heap growth.
|
|
6
|
+
*/
|
|
7
|
+
const ACCUMULATE_MAX_CHARS = 32 * 1024 * 1024;
|
|
1
8
|
/**
|
|
2
9
|
* Accumulate an OpenAI `chat.completion.chunk` stream back into the buffered
|
|
3
10
|
* `chat.completion` response shape — the object every post-turn consumer and the
|
|
4
11
|
* non-streaming wire already depend on.
|
|
5
12
|
*
|
|
6
|
-
* The typed `delta` carries only role/content/tool_calls;
|
|
7
|
-
* DeepSeek
|
|
8
|
-
* folded into the assembled response:
|
|
9
|
-
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
13
|
+
* The typed `delta` carries only role/content/reasoning_content/tool_calls;
|
|
14
|
+
* upstreams (Qwen, DeepSeek, ...) additionally send `reasoning_content`.
|
|
15
|
+
* Thinking text IS folded into the assembled response: thinking-mode upstreams
|
|
16
|
+
* (DeepSeek in particular) require the previous turns' reasoning to be passed
|
|
17
|
+
* back on the next request, so every wire that rebuilds history from this
|
|
18
|
+
* accumulator — the Responses encoder, the session echo, the buffered SSE
|
|
19
|
+
* synthesis — must be able to replay it verbatim.
|
|
13
20
|
*/
|
|
14
|
-
export function createChunkAccumulator() {
|
|
21
|
+
export function createChunkAccumulator(options = {}) {
|
|
22
|
+
/**
|
|
23
|
+
* Hard ceiling on the accumulated assistant payload — the memory bound for
|
|
24
|
+
* BOTH transports that use this accumulator: a streamed turn (frames also go
|
|
25
|
+
* to the client) and `streaming.upstream.mode: stream`, where a JSON client's
|
|
26
|
+
* whole answer is assembled here. The provider wall-clock timeout already
|
|
27
|
+
* bounds the LIFETIME of an accumulation (an abandoned or stalled stream is
|
|
28
|
+
* aborted, `finally` clears the timer, the buffer is dropped); this bounds its
|
|
29
|
+
* SIZE, because a hostile or broken upstream can emit megabytes per second
|
|
30
|
+
* for the full timeout budget. Exceeding it fails the turn instead of growing
|
|
31
|
+
* the heap — the same discipline as the capture body cap.
|
|
32
|
+
*/
|
|
33
|
+
const maxChars = options.maxChars ?? ACCUMULATE_MAX_CHARS;
|
|
34
|
+
let accumulatedChars = 0;
|
|
35
|
+
const charge = (delta) => {
|
|
36
|
+
accumulatedChars += delta;
|
|
37
|
+
if (accumulatedChars > maxChars) {
|
|
38
|
+
throw new Error(`Upstream stream exceeded the accumulation cap (${maxChars} characters); the turn was aborted instead of buffered`);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
15
41
|
let id = '';
|
|
16
42
|
let created = 0;
|
|
17
43
|
let model = '';
|
|
18
44
|
let systemFingerprint;
|
|
19
45
|
let content = '';
|
|
20
46
|
let contentSeen = false;
|
|
47
|
+
let reasoning = '';
|
|
48
|
+
let reasoningSeen = false;
|
|
21
49
|
let finishReason = null;
|
|
22
50
|
let usage;
|
|
23
51
|
/** index -> accumulated call; the output array is ordered by that index. */
|
|
@@ -38,8 +66,14 @@ export function createChunkAccumulator() {
|
|
|
38
66
|
for (const choice of chunk.choices ?? []) {
|
|
39
67
|
if (typeof choice.delta?.content === 'string') {
|
|
40
68
|
contentSeen = true;
|
|
69
|
+
charge(choice.delta.content.length);
|
|
41
70
|
content += choice.delta.content;
|
|
42
71
|
}
|
|
72
|
+
if (typeof choice.delta?.reasoning_content === 'string') {
|
|
73
|
+
reasoningSeen = true;
|
|
74
|
+
charge(choice.delta.reasoning_content.length);
|
|
75
|
+
reasoning += choice.delta.reasoning_content;
|
|
76
|
+
}
|
|
43
77
|
const fragments = choice.delta?.tool_calls;
|
|
44
78
|
if (Array.isArray(fragments)) {
|
|
45
79
|
fragments.forEach((frag, pos) => {
|
|
@@ -59,8 +93,10 @@ export function createChunkAccumulator() {
|
|
|
59
93
|
acc.type = frag.type;
|
|
60
94
|
if (frag.function?.name)
|
|
61
95
|
acc.function.name += frag.function.name;
|
|
62
|
-
if (frag.function?.arguments)
|
|
96
|
+
if (frag.function?.arguments) {
|
|
97
|
+
charge(frag.function.arguments.length);
|
|
63
98
|
acc.function.arguments += frag.function.arguments;
|
|
99
|
+
}
|
|
64
100
|
});
|
|
65
101
|
}
|
|
66
102
|
if (choice.finish_reason)
|
|
@@ -86,6 +122,7 @@ export function createChunkAccumulator() {
|
|
|
86
122
|
// session fingerprinting and schema assertion read exactly this
|
|
87
123
|
// field — never substitute '' for an absent content.
|
|
88
124
|
content: contentSeen ? content : null,
|
|
125
|
+
...(reasoningSeen ? { reasoning_content: reasoning } : {}),
|
|
89
126
|
...(calls.length ? { tool_calls: calls } : {}),
|
|
90
127
|
},
|
|
91
128
|
finish_reason: calls.length ? 'tool_calls' : finishReason ?? 'stop',
|
|
@@ -13,6 +13,10 @@ export declare const EVENT_RING_CAPACITY = 500;
|
|
|
13
13
|
* EventRing constructor; never re-declare per module).
|
|
14
14
|
*/
|
|
15
15
|
export declare const PROXY_ACCESS_RING_CAPACITY = 300;
|
|
16
|
+
/** Clash-core output ring capacity — memory-only, but a captured line is wide,
|
|
17
|
+
* so it carries its own budget (pass to the EventRing constructor; never
|
|
18
|
+
* re-declare per module). */
|
|
19
|
+
export declare const MIHOMO_LOG_RING_CAPACITY = 500;
|
|
16
20
|
/** Repeats of the same coalescing key inside this window fold into one row. */
|
|
17
21
|
export declare const EVENT_COALESCE_WINDOW_MS = 10000;
|
|
18
22
|
/** Error/note text bound — a row is an observation, not an archive of the wire body. */
|
|
@@ -13,6 +13,10 @@ export const EVENT_RING_CAPACITY = 500;
|
|
|
13
13
|
* EventRing constructor; never re-declare per module).
|
|
14
14
|
*/
|
|
15
15
|
export const PROXY_ACCESS_RING_CAPACITY = 300;
|
|
16
|
+
/** Clash-core output ring capacity — memory-only, but a captured line is wide,
|
|
17
|
+
* so it carries its own budget (pass to the EventRing constructor; never
|
|
18
|
+
* re-declare per module). */
|
|
19
|
+
export const MIHOMO_LOG_RING_CAPACITY = 500;
|
|
16
20
|
/** Repeats of the same coalescing key inside this window fold into one row. */
|
|
17
21
|
export const EVENT_COALESCE_WINDOW_MS = 10_000;
|
|
18
22
|
/** Error/note text bound — a row is an observation, not an archive of the wire body. */
|
|
@@ -1,11 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ONE popularity order for every runtime this build lists — the Clients page's
|
|
3
|
+
* one-click roster and the harness artifact rail share it, so the two surfaces
|
|
4
|
+
* can never disagree about which product is more popular.
|
|
5
|
+
*
|
|
6
|
+
* Evidence (researched 2026-11-10):
|
|
7
|
+
* - gradually.ai AI-harness popularity index, 2026-11-09: Claude Code 93,
|
|
8
|
+
* Cursor/Codex 83, Antigravity/Zed 81, Pi 75, OpenCode 73, Gemini CLI 69,
|
|
9
|
+
* Windsurf/Cline 65, Amp/Kimi 58, omp 55, Grok 52, Qoder 48, Factory 44.
|
|
10
|
+
* - Near-ties (≤3 index points) are resolved by direct install/usage signals:
|
|
11
|
+
* JetBrains Developer Ecosystem Survey 2026 (at-work share), weekly npm
|
|
12
|
+
* downloads 2026-11-03..09 (`@openai/codex` 26.1M, Claude Code 15.3M,
|
|
13
|
+
* OpenCode 3.3M, omp 225k, Pi 405k, Cline 99k, Amp 27k, Kimi 2.2k), and
|
|
14
|
+
* OpenRouter 30-day tokens (Cline 20.0T, Pi 12.3T, omp 10.4T, OpenClaw 6.96T).
|
|
15
|
+
* That moves Codex above Cursor, OpenCode above Pi, and Amp/omp above Kimi.
|
|
16
|
+
* - Not covered by the index: DeepSeek Harness (278k GitHub stars in its first
|
|
17
|
+
* three months, 2026-11-10) ranks between the 81 and 75 tiers; OpenClaw
|
|
18
|
+
* (394k stars, but personal-agent traffic) ranks below OpenCode/Pi.
|
|
19
|
+
* WorkBuddy (Tencent's office-agent IDE) has no index figure — it sits with
|
|
20
|
+
* the other vendor IDEs between Grok and Qoder by judgment, not measurement.
|
|
21
|
+
*
|
|
22
|
+
* Package client ids (cursor-proxy, opencode-gateway, …) rank via their
|
|
23
|
+
* manifest's `clientRank`, not this table — core never string-references a
|
|
24
|
+
* package hook id (ADR-0027). `universal` is not a
|
|
25
|
+
* product and is deliberately absent — the rail pins it first by id. A runtime
|
|
26
|
+
* absent here sorts after every ranked one (the host catalog breaks the tie).
|
|
27
|
+
*/
|
|
1
28
|
const POPULARITY_ROWS = [
|
|
2
29
|
['claude'],
|
|
3
30
|
['codex'],
|
|
4
|
-
['cursor'
|
|
31
|
+
['cursor'],
|
|
5
32
|
['antigravity'],
|
|
6
33
|
['zed'],
|
|
7
34
|
['dsh'],
|
|
8
|
-
['opencode'
|
|
35
|
+
['opencode'],
|
|
9
36
|
['pi'],
|
|
10
37
|
['openclaw'],
|
|
11
38
|
['gemini-cli'],
|
|
@@ -16,8 +43,6 @@ const POPULARITY_ROWS = [
|
|
|
16
43
|
['kimi'],
|
|
17
44
|
['grok'],
|
|
18
45
|
['workbuddy'],
|
|
19
|
-
['qoder-proxy'],
|
|
20
|
-
['jetbrains-proxy'],
|
|
21
46
|
['factory'],
|
|
22
47
|
];
|
|
23
48
|
const RANK = new Map();
|
|
@@ -36,3 +36,10 @@ export declare function proxiedFetch(url: string, init?: RequestInit, match?: {
|
|
|
36
36
|
provider?: string;
|
|
37
37
|
model?: string;
|
|
38
38
|
}): Promise<Response>;
|
|
39
|
+
/**
|
|
40
|
+
* fetch through an EXPLICIT proxy endpoint, bypassing the `proxy.enabled` /
|
|
41
|
+
* include-exclude policy. Callers that already decided the egress themselves
|
|
42
|
+
* (the geo download legs, ADR-0022) name the endpoint they mean. Bun honors
|
|
43
|
+
* the `proxy` option; Node's fetch cannot, so the request opens the proxy.
|
|
44
|
+
*/
|
|
45
|
+
export declare function fetchViaProxy(url: string, init: RequestInit, proxy: string): Promise<Response>;
|
|
@@ -8,15 +8,17 @@ import { nodeProxiedFetch } from './proxy-node.js';
|
|
|
8
8
|
* 1. Loopback targets (localhost / 127.0.0.1 / ::1) are NEVER proxied, so local
|
|
9
9
|
* services (OpenCode, Ollama) keep working even with a global proxy set.
|
|
10
10
|
* 2. excludes — a matching provider/model forces direct.
|
|
11
|
-
* 3. includes —
|
|
12
|
-
*
|
|
13
|
-
*
|
|
11
|
+
* 3. includes — the ALLOWLIST: only a matching provider/model is proxied. An
|
|
12
|
+
* empty (or absent) list proxies NOTHING — no rule configured means no
|
|
13
|
+
* outbound proxy (ADR-0022 amendment 2026-12).
|
|
14
|
+
* 4. undefined — direct; Bun fetch then still honors HTTP_PROXY/HTTPS_PROXY/NO_PROXY.
|
|
14
15
|
*
|
|
15
16
|
* List patterns match BOTH the composite `provider/modelId` and the bare model id,
|
|
16
17
|
* so one syntax covers both levels: `providerName/asterisk` (slash-star) selects
|
|
17
18
|
* every model of a provider; a leading star-slash prefix scopes a model pattern
|
|
18
19
|
* to any provider; a bare `claude-*` matches the model id (no wildcard = substring). Calls without a match target (catalog/logo sync) are
|
|
19
|
-
* unlisted: a
|
|
20
|
+
* unlisted: a call with no match target is never proxied, because the empty
|
|
21
|
+
* includes list is direct.
|
|
20
22
|
*
|
|
21
23
|
* proxiedFetch passes the resolved proxy via Bun's fetch `proxy` option
|
|
22
24
|
* (verified on bun 1.3.14). Node's fetch ignores that option, so the Node
|
|
@@ -44,7 +46,20 @@ export function isLoopbackUrl(url) {
|
|
|
44
46
|
return false;
|
|
45
47
|
}
|
|
46
48
|
}
|
|
47
|
-
/**
|
|
49
|
+
/**
|
|
50
|
+
* A pattern hits when it matches `provider/modelId`, the bare provider, the bare
|
|
51
|
+
* model id, or — for a call that has no model at all — the provider's own
|
|
52
|
+
* `provider/` prefix.
|
|
53
|
+
*
|
|
54
|
+
* That last target exists because a model-LESS call (a quota read, a catalog
|
|
55
|
+
* pull, a sign-in exchange) would otherwise be unreachable by the natural way
|
|
56
|
+
* to write "everything under this provider": `qoder/*` requires a model
|
|
57
|
+
* segment, so it silently matched inference ONLY and left the same provider's
|
|
58
|
+
* quota traffic direct. Offering `provider/` (which `provider/*` matches, `*`
|
|
59
|
+
* being allowed to match the empty string) makes one pattern cover the whole
|
|
60
|
+
* provider. A model-scoped pattern like `workbuddy/gpt-*` still does NOT hit a
|
|
61
|
+
* model-less call — there is no model to test, and guessing one would be wrong.
|
|
62
|
+
*/
|
|
48
63
|
function patternHits(pattern, match) {
|
|
49
64
|
if (!match)
|
|
50
65
|
return false;
|
|
@@ -53,8 +68,10 @@ function patternHits(pattern, match) {
|
|
|
53
68
|
targets.push(match.model);
|
|
54
69
|
if (match.provider && match.model)
|
|
55
70
|
targets.push(`${match.provider}/${match.model}`);
|
|
56
|
-
else if (match.provider)
|
|
71
|
+
else if (match.provider) {
|
|
57
72
|
targets.push(match.provider);
|
|
73
|
+
targets.push(`${match.provider}/`);
|
|
74
|
+
}
|
|
58
75
|
return targets.some((t) => globMatch(pattern, t));
|
|
59
76
|
}
|
|
60
77
|
let warnedInvalidProxyUrl = false;
|
|
@@ -123,10 +140,9 @@ export function resolveProxyUrl(targetUrl, match) {
|
|
|
123
140
|
return undefined;
|
|
124
141
|
if (cfg.excludes?.length && cfg.excludes.some((p) => patternHits(p, match)))
|
|
125
142
|
return undefined;
|
|
126
|
-
if (cfg.includes?.length)
|
|
127
|
-
return
|
|
128
|
-
|
|
129
|
-
return globalProxyUrl();
|
|
143
|
+
if (!cfg.includes?.length || !match)
|
|
144
|
+
return undefined;
|
|
145
|
+
return cfg.includes.some((p) => patternHits(p, match)) ? globalProxyUrl() : undefined;
|
|
130
146
|
}
|
|
131
147
|
/**
|
|
132
148
|
* Redact a proxy URL to its origin (`scheme://host:port`). Proxy URLs may
|
|
@@ -147,6 +163,15 @@ export async function proxiedFetch(url, init = {}, match) {
|
|
|
147
163
|
const proxy = resolveProxyUrl(url, match);
|
|
148
164
|
if (!proxy)
|
|
149
165
|
return fetch(url, init);
|
|
166
|
+
return fetchViaProxy(url, init, proxy);
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* fetch through an EXPLICIT proxy endpoint, bypassing the `proxy.enabled` /
|
|
170
|
+
* include-exclude policy. Callers that already decided the egress themselves
|
|
171
|
+
* (the geo download legs, ADR-0022) name the endpoint they mean. Bun honors
|
|
172
|
+
* the `proxy` option; Node's fetch cannot, so the request opens the proxy.
|
|
173
|
+
*/
|
|
174
|
+
export async function fetchViaProxy(url, init, proxy) {
|
|
150
175
|
if (isBunRuntime()) {
|
|
151
176
|
return fetch(url, { ...init, proxy });
|
|
152
177
|
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared lossless `Retry-After` parsing (ADR-0023).
|
|
3
|
+
*
|
|
4
|
+
* Delta-seconds (including fractions like `0.5`) survive; HTTP-date and other
|
|
5
|
+
* unparseable values degrade to `undefined` so callers take the "no
|
|
6
|
+
* Retry-After" branch instead of inventing a wait from `parseInt` truncation.
|
|
7
|
+
* Shape matches the former private helper in `harness/net.ts`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Parse a `Retry-After` header/value into milliseconds.
|
|
11
|
+
* - Finite non-negative Number → delta-seconds × 1000 (rounded).
|
|
12
|
+
* - Missing / blank / HTTP-date / NaN → `undefined`.
|
|
13
|
+
*/
|
|
14
|
+
export declare function parseRetryAfterMs(raw: unknown): number | undefined;
|
|
15
|
+
/**
|
|
16
|
+
* Same as {@link parseRetryAfterMs}, kept in seconds (fractional allowed) for
|
|
17
|
+
* diagnosis / UpstreamError fields that historically store seconds.
|
|
18
|
+
*/
|
|
19
|
+
export declare function parseRetryAfterSeconds(raw: unknown): number | undefined;
|
|
20
|
+
/** Wire `Retry-After` / `RateLimit-Reset` delta-seconds: `max(1, ceil(ms/1000))`. */
|
|
21
|
+
export declare function retryAfterSecFromMs(ms: number): number;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Shared lossless `Retry-After` parsing (ADR-0023).
|
|
3
|
+
*
|
|
4
|
+
* Delta-seconds (including fractions like `0.5`) survive; HTTP-date and other
|
|
5
|
+
* unparseable values degrade to `undefined` so callers take the "no
|
|
6
|
+
* Retry-After" branch instead of inventing a wait from `parseInt` truncation.
|
|
7
|
+
* Shape matches the former private helper in `harness/net.ts`.
|
|
8
|
+
*/
|
|
9
|
+
/**
|
|
10
|
+
* Parse a `Retry-After` header/value into milliseconds.
|
|
11
|
+
* - Finite non-negative Number → delta-seconds × 1000 (rounded).
|
|
12
|
+
* - Missing / blank / HTTP-date / NaN → `undefined`.
|
|
13
|
+
*/
|
|
14
|
+
export function parseRetryAfterMs(raw) {
|
|
15
|
+
if (raw === null || raw === undefined)
|
|
16
|
+
return undefined;
|
|
17
|
+
const text = String(raw).trim();
|
|
18
|
+
if (!text)
|
|
19
|
+
return undefined;
|
|
20
|
+
const seconds = Number(text);
|
|
21
|
+
if (!Number.isFinite(seconds) || seconds < 0)
|
|
22
|
+
return undefined;
|
|
23
|
+
return Math.round(seconds * 1000);
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Same as {@link parseRetryAfterMs}, kept in seconds (fractional allowed) for
|
|
27
|
+
* diagnosis / UpstreamError fields that historically store seconds.
|
|
28
|
+
*/
|
|
29
|
+
export function parseRetryAfterSeconds(raw) {
|
|
30
|
+
const ms = parseRetryAfterMs(raw);
|
|
31
|
+
return ms === undefined ? undefined : ms / 1000;
|
|
32
|
+
}
|
|
33
|
+
/** Wire `Retry-After` / `RateLimit-Reset` delta-seconds: `max(1, ceil(ms/1000))`. */
|
|
34
|
+
export function retryAfterSecFromMs(ms) {
|
|
35
|
+
return Math.max(1, Math.ceil(ms / 1000));
|
|
36
|
+
}
|
package/bin/ocr.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import '../backend/dist/cli/index.js';
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import '../backend/dist/cli/index.js';
|