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
|
@@ -1,223 +1,10 @@
|
|
|
1
|
-
import
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
/**
|
|
8
|
-
* Anthropic Messages upstream wire. Tools are fully mapped both directions
|
|
9
|
-
* (2026-10): request.tools → Anthropic tools (input_schema), assistant
|
|
10
|
-
* tool_calls in history → tool_use blocks, tool role messages → tool_result
|
|
11
|
-
* blocks, and upstream tool_use blocks → chat tool_calls. Without this,
|
|
12
|
-
* tool-driving clients routed to Anthropic upstreams silently lose tools.
|
|
13
|
-
*/
|
|
14
|
-
/** Parse tool arguments into an object; never throws (tool loops must survive). */
|
|
15
|
-
function parseArgs(raw) {
|
|
16
|
-
if (raw && typeof raw === 'object')
|
|
17
|
-
return raw;
|
|
18
|
-
if (typeof raw !== 'string' || !raw.trim())
|
|
19
|
-
return {};
|
|
20
|
-
try {
|
|
21
|
-
const v = JSON.parse(raw);
|
|
22
|
-
return v && typeof v === 'object' ? v : { result: v };
|
|
23
|
-
}
|
|
24
|
-
catch {
|
|
25
|
-
return { result: raw };
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
function contentToText(content) {
|
|
29
|
-
return typeof content === 'string' ? content : JSON.stringify(content);
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Chat content parts → Anthropic content blocks. Text passes through; images
|
|
33
|
-
* map to source blocks (base64 data URLs → inline source, HTTP(S) URLs → url
|
|
34
|
-
* source). Non-text non-image parts degrade to their JSON form rather than
|
|
35
|
-
* vanishing (fail-visible in the payload).
|
|
36
|
-
*/
|
|
37
|
-
function toAnthropicBlocks(content) {
|
|
38
|
-
if (typeof content === 'string')
|
|
39
|
-
return [{ type: 'text', text: content }];
|
|
40
|
-
return content.map((p) => {
|
|
41
|
-
if (p.type === 'text')
|
|
42
|
-
return { type: 'text', text: p.text || '' };
|
|
43
|
-
const url = p.image_url?.url || '';
|
|
44
|
-
const m = DATA_URL_RE.exec(url);
|
|
45
|
-
if (m)
|
|
46
|
-
return { type: 'image', source: { type: 'base64', media_type: m[1], data: m[2] } };
|
|
47
|
-
if (url.startsWith('http'))
|
|
48
|
-
return { type: 'image', source: { type: 'url', url } };
|
|
49
|
-
return { type: 'text', text: `[unsupported part: ${p.type}]` };
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
/** Pure payload builder: chat-completions request → Anthropic Messages payload. */
|
|
53
|
-
export function buildAnthropicPayload(request, model) {
|
|
54
|
-
let systemPrompt = undefined;
|
|
55
|
-
const anthropicMessages = [];
|
|
56
|
-
for (const msg of request.messages) {
|
|
57
|
-
if (msg.role === 'system' || msg.role === 'developer') {
|
|
58
|
-
const text = contentToText(msg.content);
|
|
59
|
-
// Prompt caching block for Anthropic
|
|
60
|
-
systemPrompt = [
|
|
61
|
-
{
|
|
62
|
-
type: 'text',
|
|
63
|
-
text,
|
|
64
|
-
cache_control: { type: 'ephemeral' },
|
|
65
|
-
},
|
|
66
|
-
];
|
|
67
|
-
}
|
|
68
|
-
else if (msg.role === 'tool') {
|
|
69
|
-
anthropicMessages.push({
|
|
70
|
-
role: 'user',
|
|
71
|
-
content: [
|
|
72
|
-
{
|
|
73
|
-
type: 'tool_result',
|
|
74
|
-
tool_use_id: msg.tool_call_id || '',
|
|
75
|
-
content: contentToText(msg.content),
|
|
76
|
-
},
|
|
77
|
-
],
|
|
78
|
-
});
|
|
79
|
-
}
|
|
80
|
-
else if (msg.role === 'assistant' && Array.isArray(msg.tool_calls) && msg.tool_calls.length > 0) {
|
|
81
|
-
const blocks = [];
|
|
82
|
-
const text = contentToText(msg.content);
|
|
83
|
-
if (text)
|
|
84
|
-
blocks.push({ type: 'text', text });
|
|
85
|
-
for (const tc of msg.tool_calls) {
|
|
86
|
-
blocks.push({ type: 'tool_use', id: tc.id, name: tc.function.name, input: parseArgs(tc.function.arguments) });
|
|
87
|
-
}
|
|
88
|
-
anthropicMessages.push({ role: 'assistant', content: blocks });
|
|
89
|
-
}
|
|
90
|
-
else {
|
|
91
|
-
const role = msg.role === 'assistant' ? 'assistant' : 'user';
|
|
92
|
-
anthropicMessages.push({ role, content: toAnthropicBlocks(msg.content) });
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
const payload = {
|
|
96
|
-
model: model.upstreamModel,
|
|
97
|
-
max_tokens: request.max_tokens || request.max_completion_tokens || 4096,
|
|
98
|
-
messages: anthropicMessages,
|
|
99
|
-
system: systemPrompt,
|
|
100
|
-
// Models the catalog marks temperature:false (next-gen Claude etc.) have
|
|
101
|
-
// deprecated sampling params — strip it to avoid the upstream 400
|
|
102
|
-
// "`temperature` is deprecated for this model". undefined is dropped
|
|
103
|
-
// automatically by JSON.stringify, i.e. the field is simply not sent.
|
|
104
|
-
temperature: model.temperature === false ? undefined : request.temperature,
|
|
105
|
-
};
|
|
106
|
-
// Extended thinking: Anthropic requires `thinking.type=enabled` plus a positive
|
|
107
|
-
// `budget_tokens`; budget is the upper bound on thinking tokens consumed
|
|
108
|
-
// before the final answer (must be < max_tokens). Map the gateway's 5-level
|
|
109
|
-
// effort level → token budget. The full 6-level table; `none` maps
|
|
110
|
-
// to 0 as a defensive value even though the guard below skips the
|
|
111
|
-
// thinking block for it. Numbers for the other 5 are engineering
|
|
112
|
-
// estimates; operators with strict cost caps should pass an explicit
|
|
113
|
-
// `max_thinking_tokens` instead.
|
|
114
|
-
const EFFORT_TO_BUDGET = {
|
|
115
|
-
none: 0,
|
|
116
|
-
low: 1024,
|
|
117
|
-
medium: 4096,
|
|
118
|
-
high: 16384,
|
|
119
|
-
xhigh: 32768,
|
|
120
|
-
max: 65536,
|
|
121
|
-
};
|
|
122
|
-
const effort = request.reasoning_effort;
|
|
123
|
-
const explicitBudget = request.max_thinking_tokens != null && request.max_thinking_tokens > 0
|
|
124
|
-
? request.max_thinking_tokens
|
|
125
|
-
: undefined;
|
|
126
|
-
// `effort === undefined` (client omitted) and `effort === 'none'`
|
|
127
|
-
// (client explicitly asked for no thinking) both skip the thinking
|
|
128
|
-
// block — the upstream picks its own default. Mirrors google.ts.
|
|
129
|
-
if ((effort && effort !== 'none') || explicitBudget != null) {
|
|
130
|
-
const budget = explicitBudget ?? EFFORT_TO_BUDGET[effort];
|
|
131
|
-
// Anthropic requires budget_tokens < max_tokens; bump max_tokens to leave headroom.
|
|
132
|
-
if (typeof budget === 'number' && budget > 0) {
|
|
133
|
-
const headroom = Math.max(payload.max_tokens, budget + 1024);
|
|
134
|
-
if (headroom > payload.max_tokens)
|
|
135
|
-
payload.max_tokens = headroom;
|
|
136
|
-
payload.thinking = { type: 'enabled', budget_tokens: budget };
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
if (request.tools?.length) {
|
|
140
|
-
payload.tools = request.tools.map((t) => ({
|
|
141
|
-
name: t.function.name,
|
|
142
|
-
description: t.function.description,
|
|
143
|
-
input_schema: t.function.parameters,
|
|
144
|
-
}));
|
|
145
|
-
}
|
|
146
|
-
if (request.tool_choice) {
|
|
147
|
-
if (request.tool_choice === 'auto')
|
|
148
|
-
payload.tool_choice = { type: 'auto' };
|
|
149
|
-
else if (request.tool_choice === 'none')
|
|
150
|
-
payload.tool_choice = { type: 'none' };
|
|
151
|
-
else if (request.tool_choice === 'required')
|
|
152
|
-
payload.tool_choice = { type: 'any' };
|
|
153
|
-
else if (typeof request.tool_choice === 'object')
|
|
154
|
-
payload.tool_choice = { type: 'tool', name: request.tool_choice.function.name };
|
|
155
|
-
}
|
|
156
|
-
if (request.stop?.length)
|
|
157
|
-
payload.stop_sequences = Array.isArray(request.stop) ? request.stop : [request.stop];
|
|
158
|
-
return payload;
|
|
159
|
-
}
|
|
160
|
-
/** Pure response mapper: Anthropic Messages payload → chat-completions response. */
|
|
161
|
-
export function anthropicToChatCompletion(data, model) {
|
|
162
|
-
let textContent = '';
|
|
163
|
-
const toolCalls = [];
|
|
164
|
-
if (Array.isArray(data.content)) {
|
|
165
|
-
for (const block of data.content) {
|
|
166
|
-
if (block.type === 'text') {
|
|
167
|
-
textContent += block.text;
|
|
168
|
-
}
|
|
169
|
-
else if (block.type === 'tool_use') {
|
|
170
|
-
toolCalls.push({
|
|
171
|
-
id: block.id || `call_${crypto.randomBytes(8).toString('hex')}`,
|
|
172
|
-
type: 'function',
|
|
173
|
-
function: { name: block.name, arguments: JSON.stringify(block.input ?? {}) },
|
|
174
|
-
});
|
|
175
|
-
}
|
|
176
|
-
}
|
|
177
|
-
}
|
|
178
|
-
const cachedTokens = data.usage?.cache_read_input_tokens || 0;
|
|
179
|
-
const uncachedInput = data.usage?.input_tokens || 0;
|
|
180
|
-
const outputTokens = data.usage?.output_tokens || 0;
|
|
181
|
-
// Anthropic extended-thinking tokens ride in `usage.output_tokens_details.thinking_tokens`
|
|
182
|
-
// (Anthropic Messages API reference). Surface them as OpenAI's
|
|
183
|
-
// `completion_tokens_details.reasoning_tokens` so downstream cost math + clients see them.
|
|
184
|
-
const thinkingTokens = data.usage?.output_tokens_details?.thinking_tokens || 0;
|
|
185
|
-
const finishReason = data.stop_reason === 'tool_use' ? 'tool_calls' : data.stop_reason === 'max_tokens' ? 'length' : 'stop';
|
|
186
|
-
return {
|
|
187
|
-
id: data.id || `chatcmpl-${Date.now()}`,
|
|
188
|
-
object: 'chat.completion',
|
|
189
|
-
created: Math.floor(Date.now() / 1000),
|
|
190
|
-
model: model.id,
|
|
191
|
-
choices: [
|
|
192
|
-
{
|
|
193
|
-
index: 0,
|
|
194
|
-
message: {
|
|
195
|
-
role: 'assistant',
|
|
196
|
-
content: textContent,
|
|
197
|
-
...(toolCalls.length ? { tool_calls: toolCalls } : {}),
|
|
198
|
-
},
|
|
199
|
-
finish_reason: finishReason,
|
|
200
|
-
},
|
|
201
|
-
],
|
|
202
|
-
usage: {
|
|
203
|
-
prompt_tokens: uncachedInput + cachedTokens,
|
|
204
|
-
completion_tokens: outputTokens,
|
|
205
|
-
total_tokens: uncachedInput + cachedTokens + outputTokens,
|
|
206
|
-
prompt_tokens_details: {
|
|
207
|
-
cached_tokens: cachedTokens,
|
|
208
|
-
},
|
|
209
|
-
// Only attach the thinking breakdown when there are actual thinking
|
|
210
|
-
// tokens — keeps the response shape tight for non-thinking calls.
|
|
211
|
-
...(thinkingTokens > 0
|
|
212
|
-
? {
|
|
213
|
-
completion_tokens_details: {
|
|
214
|
-
reasoning_tokens: thinkingTokens,
|
|
215
|
-
},
|
|
216
|
-
}
|
|
217
|
-
: {}),
|
|
218
|
-
},
|
|
219
|
-
};
|
|
220
|
-
}
|
|
1
|
+
import { anthropicResponseToIR, canonicalToAnthropicPayload } from '../ir/adapters/anthropic.js';
|
|
2
|
+
import { AnthropicStreamDecoder } from '../ir/adapters/anthropic-stream.js';
|
|
3
|
+
import { DEFAULT_PROVIDER_TIMEOUT_MS, DEFAULT_STREAM_IDLE_TIMEOUT_MS, DEFAULT_STREAM_TIMEOUT_MS, } from '../config/defaults.js';
|
|
4
|
+
import { anthropicMessagesUrl } from './wire.js';
|
|
5
|
+
import { postProviderJson } from './http-json.js';
|
|
6
|
+
import { postProviderStream } from './http-stream.js';
|
|
7
|
+
/** Anthropic Messages upstream. The provider speaks Canonical IR only. */
|
|
221
8
|
export class AnthropicProvider {
|
|
222
9
|
name;
|
|
223
10
|
config;
|
|
@@ -225,116 +12,41 @@ export class AnthropicProvider {
|
|
|
225
12
|
this.name = config.name;
|
|
226
13
|
this.config = config;
|
|
227
14
|
}
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
const headers = {
|
|
15
|
+
headers(credential) {
|
|
16
|
+
return {
|
|
231
17
|
'Content-Type': 'application/json',
|
|
232
|
-
// Per-call credential outranks the boot-baked key.
|
|
233
18
|
'x-api-key': credential?.key ?? this.config.apiKey,
|
|
234
19
|
'anthropic-version': '2023-06-01',
|
|
235
20
|
'anthropic-beta': 'prompt-caching-2024-07-31',
|
|
236
21
|
...this.config.headers,
|
|
237
22
|
};
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
const
|
|
241
|
-
url,
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
23
|
+
}
|
|
24
|
+
async createCompletion(request, model, upstreamEventContext, credential) {
|
|
25
|
+
const data = await postProviderJson({
|
|
26
|
+
url: anthropicMessagesUrl(this.config.baseUrl),
|
|
27
|
+
headers: this.headers(credential),
|
|
28
|
+
payload: canonicalToAnthropicPayload(request, model),
|
|
29
|
+
model,
|
|
30
|
+
provider: this.name,
|
|
31
|
+
label: 'anthropic',
|
|
32
|
+
timeoutMs: this.config.timeoutMs || DEFAULT_PROVIDER_TIMEOUT_MS,
|
|
33
|
+
upstreamEventContext,
|
|
34
|
+
});
|
|
35
|
+
return anthropicResponseToIR(data);
|
|
36
|
+
}
|
|
37
|
+
async createStream(request, model, upstreamEventContext, credential) {
|
|
38
|
+
return postProviderStream({
|
|
39
|
+
url: anthropicMessagesUrl(this.config.baseUrl),
|
|
40
|
+
headers: this.headers(credential),
|
|
41
|
+
payload: { ...canonicalToAnthropicPayload(request, model), stream: true },
|
|
42
|
+
model,
|
|
43
|
+
provider: this.name,
|
|
44
|
+
label: 'anthropic',
|
|
45
|
+
timeoutMs: this.config.streamTimeoutMs || DEFAULT_STREAM_TIMEOUT_MS,
|
|
46
|
+
idleTimeoutMs: this.config.streamIdleTimeoutMs || DEFAULT_STREAM_IDLE_TIMEOUT_MS,
|
|
47
|
+
upstreamEventContext,
|
|
48
|
+
createDecoder: () => new AnthropicStreamDecoder(),
|
|
49
|
+
parseBuffered: (body) => anthropicResponseToIR(body),
|
|
247
50
|
});
|
|
248
|
-
const controller = new AbortController();
|
|
249
|
-
// Wall-clock cap on the non-streaming upstream execution — see the
|
|
250
|
-
// openai-compatible provider: agent coding traffic legitimately runs past
|
|
251
|
-
// a minute, so the default is 300 s.
|
|
252
|
-
const timeout = setTimeout(() => controller.abort(), this.config.timeoutMs || DEFAULT_PROVIDER_TIMEOUT_MS);
|
|
253
|
-
try {
|
|
254
|
-
// The guard emits a paired failure response event on ANY thrown error
|
|
255
|
-
// so console readers never see a dangling request event.
|
|
256
|
-
const res = await withUpstreamFailureGuard(upstreamEventContext, exchangeId, url, 'POST', () => proxiedFetch(url, {
|
|
257
|
-
method: 'POST',
|
|
258
|
-
headers,
|
|
259
|
-
body: JSON.stringify(payload),
|
|
260
|
-
signal: controller.signal,
|
|
261
|
-
}, { provider: this.config.name, model: model.id }), model.upstreamModel);
|
|
262
|
-
if (!res.ok) {
|
|
263
|
-
// Body read can fail mid-stream (connection reset) — pair the request
|
|
264
|
-
// event with a failure response before rethrowing.
|
|
265
|
-
let errorText;
|
|
266
|
-
try {
|
|
267
|
-
errorText = await res.text();
|
|
268
|
-
}
|
|
269
|
-
catch (err) {
|
|
270
|
-
emitUpstreamFailureOnce(upstreamEventContext, {
|
|
271
|
-
model: model.upstreamModel,
|
|
272
|
-
exchangeId,
|
|
273
|
-
url,
|
|
274
|
-
method: 'POST',
|
|
275
|
-
status: res.status,
|
|
276
|
-
statusText: res.statusText,
|
|
277
|
-
error: `Response body read failed: ${err?.message ?? err}`,
|
|
278
|
-
});
|
|
279
|
-
throw err;
|
|
280
|
-
}
|
|
281
|
-
const retryAfterHeader = res.headers.get('retry-after');
|
|
282
|
-
const retryAfterSeconds = retryAfterHeader ? parseInt(retryAfterHeader, 10) : undefined;
|
|
283
|
-
emitUpstreamFailureOnce(upstreamEventContext, {
|
|
284
|
-
model: model.upstreamModel,
|
|
285
|
-
exchangeId,
|
|
286
|
-
url,
|
|
287
|
-
method: 'POST',
|
|
288
|
-
status: res.status,
|
|
289
|
-
statusText: res.statusText,
|
|
290
|
-
responseHeaders: res.headers,
|
|
291
|
-
responseBody: errorText,
|
|
292
|
-
error: `Anthropic error [${res.status}]`,
|
|
293
|
-
});
|
|
294
|
-
throw new UpstreamError({
|
|
295
|
-
message: `Anthropic error [${res.status}]: ${errorText}`,
|
|
296
|
-
status: res.status,
|
|
297
|
-
errorBody: errorText,
|
|
298
|
-
provider: this.name,
|
|
299
|
-
modelId: model.id,
|
|
300
|
-
retryAfterSeconds: isNaN(retryAfterSeconds) ? undefined : retryAfterSeconds,
|
|
301
|
-
});
|
|
302
|
-
}
|
|
303
|
-
// Emit the response event the moment the body BYTES arrive — before
|
|
304
|
-
// JSON.parse. A 200-with-garbage body (e.g. misconfigured baseUrl
|
|
305
|
-
// returning an HTML error page) must still leave the response event
|
|
306
|
-
// on disk; likewise a mid-body connection reset gets a failure event.
|
|
307
|
-
let rawBody;
|
|
308
|
-
try {
|
|
309
|
-
rawBody = await res.text();
|
|
310
|
-
}
|
|
311
|
-
catch (err) {
|
|
312
|
-
emitUpstreamFailureOnce(upstreamEventContext, {
|
|
313
|
-
model: model.upstreamModel,
|
|
314
|
-
exchangeId,
|
|
315
|
-
url,
|
|
316
|
-
method: 'POST',
|
|
317
|
-
status: res.status,
|
|
318
|
-
statusText: res.statusText,
|
|
319
|
-
error: `Response body read failed: ${err?.message ?? err}`,
|
|
320
|
-
});
|
|
321
|
-
throw err;
|
|
322
|
-
}
|
|
323
|
-
emitUpstreamResponseOnce(upstreamEventContext, {
|
|
324
|
-
model: model.upstreamModel,
|
|
325
|
-
exchangeId,
|
|
326
|
-
url,
|
|
327
|
-
method: 'POST',
|
|
328
|
-
status: res.status,
|
|
329
|
-
statusText: res.statusText,
|
|
330
|
-
responseHeaders: res.headers,
|
|
331
|
-
responseBody: rawBody,
|
|
332
|
-
});
|
|
333
|
-
const data = JSON.parse(rawBody);
|
|
334
|
-
return anthropicToChatCompletion(data, model);
|
|
335
|
-
}
|
|
336
|
-
finally {
|
|
337
|
-
clearTimeout(timeout);
|
|
338
|
-
}
|
|
339
51
|
}
|
|
340
52
|
}
|
|
@@ -6,9 +6,21 @@ export type { CallCredential, UpstreamEventContext };
|
|
|
6
6
|
/** The sole southbound execution contract: Canonical IR in, Canonical IR out. */
|
|
7
7
|
export interface LLMProvider {
|
|
8
8
|
name: string;
|
|
9
|
-
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential
|
|
9
|
+
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential,
|
|
10
|
+
/** Resolved OCR conversation id. Independent of request capture. */
|
|
11
|
+
sessionId?: string): Promise<CanonicalResponse>;
|
|
10
12
|
/** Probe before fetch; absent createStream means buffered-only. */
|
|
11
13
|
supportsStreaming?(model: ModelRegistration): boolean;
|
|
14
|
+
/**
|
|
15
|
+
* Base URL this transport will dial for `model`. The trace's egress stamp
|
|
16
|
+
* resolves the outbound-proxy decision against THIS url at dial time —
|
|
17
|
+
* never against registry-level provider config: a dispatching provider
|
|
18
|
+
* dials a different base per wire. Absent = the transport does not report
|
|
19
|
+
* its dial base (plugin-owned executors), which reads as UNKNOWN egress.
|
|
20
|
+
*/
|
|
21
|
+
dialBaseFor?(model: ModelRegistration): string | undefined;
|
|
12
22
|
/** Native upstream stream, decoded once at the protocol boundary. */
|
|
13
|
-
createStream?(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential
|
|
23
|
+
createStream?(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential,
|
|
24
|
+
/** Resolved OCR conversation id. Independent of request capture. */
|
|
25
|
+
sessionId?: string): Promise<AsyncIterable<StreamEvent>>;
|
|
14
26
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { DispatchingProvider } from './executors/dispatch.js';
|
|
2
2
|
import { EFFORT_LADDER } from '../types/router.js';
|
|
3
3
|
import { loadConfig } from '../config/index.js';
|
|
4
|
-
import { resolveTierMatch, classifyTier } from './tier-match.js';
|
|
5
4
|
import { resolveTierMembers, claimModel, comboRefLookupFromConfig, expandComboRefs } from './member-match.js';
|
|
5
|
+
import { pricingFromCost } from './virtual-meta.js';
|
|
6
6
|
import { catalogRepository } from '../opencode/catalog/repository.js';
|
|
7
7
|
import { getProviderNodeById, getProviderModelDefs, expandEnvTemplate, legacyShapedSlotEntries, } from '../opencode/user-config.js';
|
|
8
8
|
import { getCredentialStore, getCredentialStoreStatus } from '../opencode/credentials/index.js';
|
|
@@ -11,6 +11,7 @@ import { sanitizeExtraHeaders } from '../utils/http-headers.js';
|
|
|
11
11
|
import { assertAllowedUpstream, UpstreamUrlError } from '../utils/upstream-url-guard.js';
|
|
12
12
|
import { wireFor, unroutableInfo, baseForWire } from './wire.js';
|
|
13
13
|
import { getProviderTakedownStore } from './provider-takedown.js';
|
|
14
|
+
import { getModelServicePlugin, pluginDeclinesCredentials } from '../plugins/host.js';
|
|
14
15
|
/** Raw key + display identity → the per-call selectable credential (P3 step 1).
|
|
15
16
|
* `label` stays absent when the operator never named the credential — the
|
|
16
17
|
* store's machine id is NOT a display name (it used to leak as a UUID).
|
|
@@ -64,28 +65,42 @@ export function routableVariants(raw) {
|
|
|
64
65
|
export function effortLadderFor(catModel, isReasoning) {
|
|
65
66
|
const opts = catModel?.reasoningOptions;
|
|
66
67
|
if (!Array.isArray(opts) || opts.length === 0) {
|
|
67
|
-
|
|
68
|
+
// Legacy data with no reasoning_options: the boolean expands to the full
|
|
69
|
+
// ladder — minus `none` when the def states the model always thinks.
|
|
70
|
+
return isReasoning ? fullLadder(catModel?.reasoningDisableable) : undefined;
|
|
68
71
|
}
|
|
69
72
|
const effortOpt = opts.find((o) => o?.type === 'effort');
|
|
70
73
|
if (effortOpt && Array.isArray(effortOpt.values) && effortOpt.values.length > 0) {
|
|
71
74
|
const allowed = effortOpt.values.filter((v) => EFFORT_LADDER.includes(v));
|
|
72
75
|
if (allowed.length > 0)
|
|
73
|
-
return allowed;
|
|
76
|
+
return withoutForbiddenNone(allowed, catModel?.reasoningDisableable);
|
|
74
77
|
}
|
|
75
78
|
if (opts.some((o) => o?.type === 'budget_tokens'))
|
|
76
|
-
return
|
|
79
|
+
return fullLadder(catModel?.reasoningDisableable);
|
|
80
|
+
// A declared table with NO usable level is "no explicit level control" —
|
|
81
|
+
// never expanded into a full ladder. `[]` already withholds `none`: the
|
|
82
|
+
// router reads it as "no level to offer", and the wire-side clamp keeps the
|
|
83
|
+
// model's own always-think behaviour (the qoder 1210 replay is the net).
|
|
77
84
|
return [];
|
|
78
85
|
}
|
|
86
|
+
/** The boolean-expanded ladder, honouring an always-think declaration. */
|
|
87
|
+
function fullLadder(disableable) {
|
|
88
|
+
return disableable === false ? EFFORT_LADDER.filter((e) => e !== 'none') : EFFORT_LADDER;
|
|
89
|
+
}
|
|
90
|
+
/** Strip `none` from a declared table when the def says the model always
|
|
91
|
+
* thinks. A table that empties under the strip stays EMPTY (no level control)
|
|
92
|
+
* — it must never fall back to a ladder that re-admits the forbidden level. */
|
|
93
|
+
function withoutForbiddenNone(levels, disableable) {
|
|
94
|
+
if (disableable !== false)
|
|
95
|
+
return levels;
|
|
96
|
+
return levels.filter((e) => e !== 'none');
|
|
97
|
+
}
|
|
79
98
|
/** One shared line for a node the reader refuses to route (Decision 11). */
|
|
80
99
|
function retiredShapeReason(paths) {
|
|
81
100
|
return `provider def node is a retired shape (${paths.join(', ')}): retired shapes are not routable — use the package/settings v2 shape`;
|
|
82
101
|
}
|
|
83
102
|
export async function buildDirectPool() {
|
|
84
103
|
const catalog = await catalogRepository.list();
|
|
85
|
-
// Boot-time smart match (config `tiers[t].match` over the built-in
|
|
86
|
-
// baseline). The registry replays it live on every config-save event
|
|
87
|
-
// (applyTierConfigNow) — no gateway restart required for tier edits.
|
|
88
|
-
const tierMatch = resolveTierMatch(loadConfig().tiers);
|
|
89
104
|
// credentials come from the BOOT-BOUND CredentialStore, not
|
|
90
105
|
// from auth.json directly. buildDirectPool is the boot/pool-rebuild path,
|
|
91
106
|
// the ONLY sanctioned caller class for the raw `resolveKey`/`resolveKeyChain`
|
|
@@ -148,8 +163,16 @@ export async function buildDirectPool() {
|
|
|
148
163
|
// Bake the default credential (P3 step 1); `resolved?.key` stays the defensive
|
|
149
164
|
// fallback for a store whose chain read came back empty while resolveKey
|
|
150
165
|
// answered — head === baked key is an invariant the registry relies on.
|
|
151
|
-
const
|
|
152
|
-
|
|
166
|
+
const pkg = typeof def?.npm === 'string' ? def.npm : typeof rec.npm === 'string' ? rec.npm : '';
|
|
167
|
+
// A plugin that declares only `none` owns login. A stored OCR key is not an account and is not required to route.
|
|
168
|
+
const credentialless = pkg ? pluginDeclinesCredentials(getModelServicePlugin(wireFor(pkg))) : false;
|
|
169
|
+
let apiKey = inlineKey || storeCreds[0]?.key || resolved?.key;
|
|
170
|
+
if (credentialless) {
|
|
171
|
+
apiKey = '';
|
|
172
|
+
storeCreds = [];
|
|
173
|
+
resolved = null;
|
|
174
|
+
}
|
|
175
|
+
else if (!apiKey) {
|
|
153
176
|
// catalog-universe providers without credentials are structural noise —
|
|
154
177
|
// only surface when the user actually defined a config node for them.
|
|
155
178
|
// the credential candidates are the inline def and
|
|
@@ -247,21 +270,19 @@ export async function buildDirectPool() {
|
|
|
247
270
|
wires.add(wire);
|
|
248
271
|
wireBases.set(wire, baseForWire(wire, baseURL));
|
|
249
272
|
const isReasoning = catModel?.reasoning === true || d?.capabilities?.reasoning === true;
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
//
|
|
254
|
-
|
|
255
|
-
//
|
|
256
|
-
//
|
|
257
|
-
//
|
|
258
|
-
//
|
|
273
|
+
// No pricing fallback: a model whose price is unknown keeps `undefined`
|
|
274
|
+
// (a fabricated number is indistinguishable from a real quote downstream
|
|
275
|
+
// and erases the per-model differences the cost surfaces exist to show).
|
|
276
|
+
// The one cost→pricing rule is shared with the combo envelope.
|
|
277
|
+
const pricing = pricingFromCost(catModel?.cost);
|
|
278
|
+
// The defs-file model definition may declare an EXPLICIT tier — an operator
|
|
279
|
+
// pin that the member lists can never move (no `autoTier` stamp below).
|
|
280
|
+
// Everything else starts with NO home tier: the member lists are the one
|
|
281
|
+
// membership source, and the loop over `claimModel` at the end of this
|
|
282
|
+
// function assigns the derived home view for every claimed model. Nothing
|
|
283
|
+
// classifies by price, name pattern or capability any more.
|
|
259
284
|
const explicitTier = (v) => v === 'lite' || v === 'plus' || v === 'pro' || v === 'ultra' ? v : undefined;
|
|
260
|
-
const rawInputPerM = catModel?.cost?.input;
|
|
261
285
|
const configTier = explicitTier(d?.tier);
|
|
262
|
-
const membership = configTier ?? classifyTier({ modelId: mid, inputPerM: rawInputPerM, reasoningFlag: isReasoning }, tierMatch);
|
|
263
|
-
const unclassified = membership === 'unclassified';
|
|
264
|
-
const tier = unclassified ? 'plus' : membership;
|
|
265
286
|
const variants = routableVariants(d?.variants ?? catModel?.variants);
|
|
266
287
|
// Model-default thinking level: override (catalog) wins over the def's
|
|
267
288
|
// `settings.reasoningEffort`; invalid values are dropped defensively.
|
|
@@ -273,13 +294,19 @@ export async function buildDirectPool() {
|
|
|
273
294
|
id: `${rec.id}/${mid}`,
|
|
274
295
|
provider: rec.id,
|
|
275
296
|
upstreamModel: (d && typeof d === 'object' && d.modelID ? String(d.modelID) : mid),
|
|
276
|
-
|
|
297
|
+
// Absent for machine-derived models: the claim loop at the end of this
|
|
298
|
+
// function assigns the home tier from the member lists.
|
|
299
|
+
tier: configTier,
|
|
277
300
|
isDefaultInTier: false,
|
|
278
301
|
// Catalog reasoning_options → the real effort tiers (see effortLadderFor).
|
|
279
302
|
// The legacy `supportsReasoningEffort` boolean is intentionally NOT set:
|
|
280
303
|
// `supportedReasoningEfforts` is always resolved here, and the legacy
|
|
281
304
|
// true-branch would resurrect a full-ladder claim for [] (toggle) models.
|
|
282
305
|
supportedReasoningEfforts: effortLadderFor(catModel, isReasoning),
|
|
306
|
+
// The vendor's on/off fact rides the registration so EVERY routing
|
|
307
|
+
// resolution (modelSupportsEfforts) withholds `none` for an always-think
|
|
308
|
+
// model — not only the boot ladder above (ADR-0035 rule 2).
|
|
309
|
+
...(catModel?.reasoningDisableable === false ? { reasoningDisableable: false } : {}),
|
|
283
310
|
// Tri-state sampling-parameter capability flag — the provider layer
|
|
284
311
|
// strips params for temperature:false models.
|
|
285
312
|
temperature: catModel?.temperature,
|
|
@@ -293,17 +320,12 @@ export async function buildDirectPool() {
|
|
|
293
320
|
// Pinned when the client omits `reasoning_effort` (orchestrator).
|
|
294
321
|
defaultEffort,
|
|
295
322
|
wire,
|
|
296
|
-
//
|
|
297
|
-
//
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
...(
|
|
301
|
-
pricing: {
|
|
302
|
-
input: inputCost,
|
|
303
|
-
output: outputCost,
|
|
304
|
-
cacheRead,
|
|
305
|
-
...(catModel?.cost?.cache_write != null ? { cacheWrite: catModel.cost.cache_write } : {}),
|
|
306
|
-
},
|
|
323
|
+
// Provenance stamp: the registry is allowed to re-project this model's
|
|
324
|
+
// home tier from the member lists at every commit. Only machine-derived
|
|
325
|
+
// models carry it — an explicit `tier` in the defs file keeps it out so
|
|
326
|
+
// member-list edits can never move a hand-configured model.
|
|
327
|
+
...(configTier ? { configTier } : { autoTier: true }),
|
|
328
|
+
...(pricing ? { pricing } : {}),
|
|
307
329
|
});
|
|
308
330
|
}
|
|
309
331
|
if (wires.size === 0) {
|
|
@@ -323,7 +345,7 @@ export async function buildDirectPool() {
|
|
|
323
345
|
// Inline {env}/options.apiKey outranks the store for the baked default
|
|
324
346
|
// (Decision 1) — it becomes the chain HEAD too, keeping the invariant
|
|
325
347
|
// head === config.apiKey; store credentials stay selectable below it.
|
|
326
|
-
if (inlineKey)
|
|
348
|
+
if (inlineKey && !credentialless)
|
|
327
349
|
credentialChain.unshift(toCallCredential(inlineKey, 'inline'));
|
|
328
350
|
instances.push({
|
|
329
351
|
name: rec.id,
|
|
@@ -398,13 +420,21 @@ export async function buildDirectPool() {
|
|
|
398
420
|
}
|
|
399
421
|
let claimed = 0;
|
|
400
422
|
for (const m of models) {
|
|
423
|
+
// An explicit defs-file tier is an operator PIN: the member lists may
|
|
424
|
+
// project the model into pools, but they never rewrite its home view.
|
|
425
|
+
// It still POPULATES its tier pool (hand-configured branch), so it counts
|
|
426
|
+
// toward "pools are non-empty" — otherwise an all-pinned deployment would
|
|
427
|
+
// log a false "pools are EMPTY" warning.
|
|
428
|
+
if (m.configTier) {
|
|
429
|
+
claimed++;
|
|
430
|
+
continue;
|
|
431
|
+
}
|
|
401
432
|
const home = claimModel(m.id, resolved.tiers);
|
|
402
433
|
if (home === 'unclassified') {
|
|
403
|
-
m.
|
|
434
|
+
m.tier = undefined;
|
|
404
435
|
continue;
|
|
405
436
|
}
|
|
406
437
|
claimed++;
|
|
407
|
-
delete m.unclassified;
|
|
408
438
|
m.tier = home.tier;
|
|
409
439
|
m.priority = home.index + 1; // home list order (derived view)
|
|
410
440
|
m.isDefaultInTier = home.index === 0; // the home list leader
|
|
@@ -1,28 +1,14 @@
|
|
|
1
1
|
import { LLMProvider, type UpstreamEventContext, type CallCredential } from './base.js';
|
|
2
|
-
import { ModelRegistration, ProviderConfig } from '../config/types.js';
|
|
3
|
-
import {
|
|
2
|
+
import type { ModelRegistration, ProviderConfig } from '../config/types.js';
|
|
3
|
+
import type { CanonicalRequest, CanonicalResponse, StreamEvent } from '../ir/types.js';
|
|
4
4
|
import { WireKind } from './wire.js';
|
|
5
|
-
/**
|
|
6
|
-
* one logical provider may host models on different wires
|
|
7
|
-
* (e.g. Zen: chat/completions for most, Responses API for gpt-6-luna,
|
|
8
|
-
* Anthropic Messages for claude-*) — and even different MOUNTS per wire
|
|
9
|
-
* (Zen: /zen/v1 vs /inference/anthropic/v1). Dispatch is driven purely by
|
|
10
|
-
* `ModelRegistration.wire`, resolved at boot through the shared wireFor()/
|
|
11
|
-
* baseForWire() that the console probe also uses — test ≡ inference by structure.
|
|
12
|
-
*/
|
|
5
|
+
/** Resolve each model's physical wire to one canonical executor. */
|
|
13
6
|
export declare class DispatchingProvider implements LLMProvider {
|
|
14
7
|
name: string;
|
|
15
8
|
private execs;
|
|
16
9
|
constructor(config: ProviderConfig, wireBases: Partial<Record<WireKind, string>>);
|
|
17
10
|
private exec;
|
|
18
|
-
createCompletion(request:
|
|
19
|
-
/**
|
|
20
|
-
* Streaming capability: only executors with a native streaming reader are
|
|
21
|
-
* admitted to the streamed relay path — the OpenAI `chat/completions` SSE
|
|
22
|
-
* reader and the Qoder gRPC server-streaming bridge. Anthropic /
|
|
23
|
-
* Google / Responses executors still return a buffered JSON document, so
|
|
24
|
-
* their models keep the buffered path and the fake-stream re-chunker.
|
|
25
|
-
*/
|
|
11
|
+
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<CanonicalResponse>;
|
|
26
12
|
supportsStreaming(model: ModelRegistration): boolean;
|
|
27
|
-
createStream(request:
|
|
13
|
+
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<AsyncIterable<StreamEvent>>;
|
|
28
14
|
}
|