omnicell-router 0.8.2 → 0.8.4
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/auth/api-keys.js +11 -0
- package/backend/dist/auth/key-models.d.ts +36 -0
- package/backend/dist/auth/key-models.js +99 -0
- package/backend/dist/cli/clients/activity.js +2 -0
- package/backend/dist/cli/clients/codex.d.ts +70 -0
- package/backend/dist/cli/clients/codex.js +470 -57
- package/backend/dist/cli/clients/follow-catalog-sync.d.ts +62 -0
- package/backend/dist/cli/clients/follow-catalog-sync.js +435 -0
- package/backend/dist/cli/clients/opencode.js +3 -2
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/types.d.ts +9 -0
- package/backend/dist/config/comments-en.js +5 -1
- package/backend/dist/config/comments-zh.js +5 -1
- package/backend/dist/config/defaults.d.ts +98 -1
- package/backend/dist/config/defaults.js +98 -1
- package/backend/dist/config/index.d.ts +15 -1
- package/backend/dist/config/index.js +35 -1
- package/backend/dist/config/migrations/v4-to-v5.d.ts +36 -0
- package/backend/dist/config/migrations/v4-to-v5.js +42 -0
- package/backend/dist/config/migrations/v5-to-v6.d.ts +27 -0
- package/backend/dist/config/migrations/v5-to-v6.js +29 -0
- package/backend/dist/config/schema.d.ts +3 -3
- package/backend/dist/config/schema.js +8 -4
- package/backend/dist/config/types.d.ts +54 -3
- package/backend/dist/forward-proxy/egress.js +13 -0
- package/backend/dist/forward-proxy/h2-forward.js +6 -5
- package/backend/dist/forward-proxy/index.js +5 -0
- package/backend/dist/forward-proxy/server.d.ts +12 -0
- package/backend/dist/forward-proxy/server.js +113 -15
- package/backend/dist/index.js +6 -1
- package/backend/dist/ir/adapters/openai-chat.js +5 -3
- package/backend/dist/ir/adapters/openai-responses-output.js +2 -2
- package/backend/dist/ir/adapters/openai-responses.d.ts +33 -0
- package/backend/dist/ir/adapters/openai-responses.js +44 -2
- package/backend/dist/ir/capabilities.js +4 -0
- package/backend/dist/ir/validate.d.ts +24 -0
- package/backend/dist/ir/validate.js +113 -63
- package/backend/dist/opencode/catalog/auto-pull.js +8 -7
- package/backend/dist/opencode/catalog/ocr-store.d.ts +7 -6
- package/backend/dist/opencode/catalog/ocr-store.js +2 -2
- package/backend/dist/opencode/catalog/overrides-store.d.ts +5 -3
- package/backend/dist/opencode/catalog/overrides-store.js +22 -19
- package/backend/dist/opencode/catalog/repository.js +3 -3
- package/backend/dist/opencode/catalog/sources/models-dev.d.ts +3 -3
- package/backend/dist/opencode/catalog/sources/models-dev.js +29 -11
- package/backend/dist/opencode/catalog/types.d.ts +7 -9
- package/backend/dist/opencode/credentials/def-materialize.js +27 -21
- package/backend/dist/opencode/migrate/engine.d.ts +20 -0
- package/backend/dist/opencode/migrate/engine.js +71 -0
- package/backend/dist/opencode/migrate/migrator.d.ts +11 -0
- package/backend/dist/opencode/migrate/migrator.js +6 -0
- package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.d.ts +6 -0
- package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.js +31 -0
- package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.d.ts +6 -0
- package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.js +62 -0
- package/backend/dist/opencode/provider-def-adapters.d.ts +12 -11
- package/backend/dist/opencode/provider-def-adapters.js +43 -27
- package/backend/dist/opencode/provider-defs.d.ts +10 -16
- package/backend/dist/opencode/provider-defs.js +45 -45
- package/backend/dist/opencode/user-config.d.ts +23 -26
- package/backend/dist/opencode/user-config.js +95 -77
- package/backend/dist/pipeline/orchestrator.js +17 -7
- package/backend/dist/plugins/builtin/model-gateway.js +38 -12
- package/backend/dist/plugins/host.d.ts +2 -2
- package/backend/dist/plugins/host.js +15 -12
- package/backend/dist/providers/boot-direct.js +32 -8
- package/backend/dist/providers/dial-wire.d.ts +17 -0
- package/backend/dist/providers/dial-wire.js +49 -0
- package/backend/dist/providers/protocols-field.d.ts +24 -0
- package/backend/dist/providers/protocols-field.js +66 -0
- package/backend/dist/providers/registry.d.ts +3 -1
- package/backend/dist/providers/registry.js +23 -7
- package/backend/dist/quota/cli-login.js +3 -1
- package/backend/dist/routes/console.js +115 -95
- package/backend/dist/server.js +91 -2
- package/backend/dist/surfaces/anthropic.js +4 -1
- package/backend/dist/surfaces/body-admission.d.ts +279 -0
- package/backend/dist/surfaces/body-admission.js +613 -0
- package/backend/dist/surfaces/transport-node-http.d.ts +44 -5
- package/backend/dist/surfaces/transport-node-http.js +86 -13
- package/backend/dist/utils/server-liveness.d.ts +27 -0
- package/backend/dist/utils/server-liveness.js +31 -0
- package/frontend/dist/assets/{index-55VVwfFQ.js → index-Dk76uc7e.js} +367 -366
- package/frontend/dist/assets/{index-DxZ9MHKB.css → index-KI1OW5x6.css} +1 -1
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { PROVIDER_ID_RULE, isValidProviderId, readJsonc } from './user-config.js';
|
|
4
|
-
import { currentPackageFor } from './provider-package.js';
|
|
5
4
|
import { resolveDefaultPaths, resolveOpencodeConfigPath } from './credentials/paths.js';
|
|
6
5
|
import { detectClientFlavor } from './credentials/paths.js';
|
|
7
6
|
import { providerDefAdapter } from './provider-def-adapters.js';
|
|
8
7
|
import { renameWithRetry } from '../utils/atomic-write.js';
|
|
8
|
+
import { migrateProvidersFile, PROVIDERS_SCHEMA } from './migrate/engine.js';
|
|
9
|
+
import { normalizeProtocols, protocolsFromLegacyNode } from '../providers/protocols-field.js';
|
|
10
|
+
import { currentPackageFor } from './provider-package.js';
|
|
9
11
|
/** Bump when the import learns a new source or a new shape conversion. */
|
|
10
|
-
export const PROVIDER_DEFS_IMPORT_VERSION =
|
|
12
|
+
export const PROVIDER_DEFS_IMPORT_VERSION = 3;
|
|
11
13
|
export function getProviderDefsPath(paths = resolveDefaultPaths()) {
|
|
12
14
|
return path.join(paths.ocrHome, 'providers.json');
|
|
13
15
|
}
|
|
@@ -24,8 +26,10 @@ export function catalogModelToDef(m) {
|
|
|
24
26
|
continue;
|
|
25
27
|
if (v === undefined)
|
|
26
28
|
continue;
|
|
27
|
-
if (k === 'npm') {
|
|
28
|
-
|
|
29
|
+
if (k === 'protocols' || k === 'npm') {
|
|
30
|
+
const list = normalizeProtocols(k === 'protocols' ? v : [v]);
|
|
31
|
+
if (list.length > 0)
|
|
32
|
+
def.provider = { ...(def.provider || {}), protocols: list };
|
|
29
33
|
continue;
|
|
30
34
|
}
|
|
31
35
|
def[k] = v;
|
|
@@ -37,72 +41,68 @@ export function catalogModelToDef(m) {
|
|
|
37
41
|
return def;
|
|
38
42
|
}
|
|
39
43
|
/**
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* protocol
|
|
43
|
-
*
|
|
44
|
+
* Normalize protocol ids on every read/write. Retired SDK spellings inside a
|
|
45
|
+
* `protocols` entry are translated. Callers that still pass singular
|
|
46
|
+
* `npm`/`package`/`protocol` (e.g. OpenCode setup's router node) are lifted
|
|
47
|
+
* here so the write path cannot silently drop the dial slot — materialize
|
|
48
|
+
* then re-emits client `package` from `protocols[]`.
|
|
44
49
|
*/
|
|
45
|
-
function
|
|
50
|
+
function currentProtocolNodes(providers) {
|
|
46
51
|
const out = {};
|
|
47
52
|
for (const [id, node] of Object.entries(providers)) {
|
|
48
53
|
if (!node || typeof node !== 'object') {
|
|
49
54
|
out[id] = node;
|
|
50
55
|
continue;
|
|
51
56
|
}
|
|
52
|
-
let next = node;
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
const pkg = currentPackageFor(node.npm);
|
|
60
|
-
if (pkg !== node.npm)
|
|
61
|
-
next = { ...next, npm: pkg };
|
|
57
|
+
let next = { ...node };
|
|
58
|
+
const lifted = protocolsFromLegacyNode(node);
|
|
59
|
+
delete next.npm;
|
|
60
|
+
delete next.package;
|
|
61
|
+
delete next.protocol;
|
|
62
|
+
if (lifted && lifted.length > 0) {
|
|
63
|
+
next.protocols = normalizeProtocols(lifted.map((p) => currentPackageFor(p)));
|
|
62
64
|
}
|
|
65
|
+
else
|
|
66
|
+
delete next.protocols;
|
|
63
67
|
if (node.models && typeof node.models === 'object') {
|
|
64
|
-
let modelsChanged = false;
|
|
65
68
|
const models = {};
|
|
66
69
|
for (const [mid, model] of Object.entries(node.models)) {
|
|
67
70
|
const provider = model?.provider;
|
|
68
71
|
if (provider && typeof provider === 'object') {
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
const pkg = currentPackageFor(provider.npm);
|
|
77
|
-
if (pkg !== provider.npm)
|
|
78
|
-
nextProvider = { ...nextProvider, npm: pkg };
|
|
79
|
-
}
|
|
80
|
-
if (nextProvider !== provider) {
|
|
81
|
-
models[mid] = { ...model, provider: nextProvider };
|
|
82
|
-
modelsChanged = true;
|
|
83
|
-
continue;
|
|
72
|
+
const nextProvider = { ...provider };
|
|
73
|
+
const mp = protocolsFromLegacyNode(provider);
|
|
74
|
+
delete nextProvider.npm;
|
|
75
|
+
delete nextProvider.package;
|
|
76
|
+
delete nextProvider.protocol;
|
|
77
|
+
if (mp && mp.length > 0) {
|
|
78
|
+
nextProvider.protocols = normalizeProtocols(mp.map((p) => currentPackageFor(p)));
|
|
84
79
|
}
|
|
80
|
+
else
|
|
81
|
+
delete nextProvider.protocols;
|
|
82
|
+
models[mid] = { ...model, provider: nextProvider };
|
|
83
|
+
}
|
|
84
|
+
else {
|
|
85
|
+
models[mid] = model;
|
|
85
86
|
}
|
|
86
|
-
models[mid] = model;
|
|
87
87
|
}
|
|
88
|
-
|
|
89
|
-
next = { ...next, models };
|
|
88
|
+
next = { ...next, models };
|
|
90
89
|
}
|
|
91
90
|
out[id] = next;
|
|
92
91
|
}
|
|
93
92
|
return out;
|
|
94
93
|
}
|
|
95
|
-
/** Tolerant read: missing / corrupt / wrong version → null. */
|
|
94
|
+
/** Tolerant read: missing / corrupt / wrong version → null. Runs the hop first. */
|
|
96
95
|
export function readProviderDefsFile(paths = resolveDefaultPaths()) {
|
|
97
96
|
try {
|
|
98
97
|
const file = getProviderDefsPath(paths);
|
|
99
98
|
if (!fs.existsSync(file))
|
|
100
99
|
return null;
|
|
100
|
+
migrateProvidersFile(file);
|
|
101
101
|
const parsed = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
102
|
-
if (parsed?.version !==
|
|
102
|
+
if (parsed?.version !== PROVIDERS_SCHEMA || typeof parsed.providers !== 'object' || parsed.providers === null) {
|
|
103
103
|
return null;
|
|
104
104
|
}
|
|
105
|
-
return { ...parsed, providers:
|
|
105
|
+
return { ...parsed, version: 2, providers: currentProtocolNodes(parsed.providers) };
|
|
106
106
|
}
|
|
107
107
|
catch {
|
|
108
108
|
return null;
|
|
@@ -112,7 +112,7 @@ export function readProviderDefsFile(paths = resolveDefaultPaths()) {
|
|
|
112
112
|
export function writeProviderDefs(providers, paths = resolveDefaultPaths()) {
|
|
113
113
|
const file = getProviderDefsPath(paths);
|
|
114
114
|
fs.mkdirSync(path.dirname(file), { recursive: true });
|
|
115
|
-
const next = { version:
|
|
115
|
+
const next = { version: 2, updated: Date.now(), providers: currentProtocolNodes(providers) };
|
|
116
116
|
const tmp = `${file}.tmp.${process.pid}.${Date.now()}`;
|
|
117
117
|
fs.writeFileSync(tmp, `${JSON.stringify(next, null, 2)}\n`, 'utf8');
|
|
118
118
|
renameWithRetry(tmp, file);
|
|
@@ -137,8 +137,8 @@ export function setProviderDefsMutationHook(hook) {
|
|
|
137
137
|
* caller's client id (the sync client being run) OR this machine's detected
|
|
138
138
|
* flavor (`credentials/paths.ts`) selects the adapter (`provider-def-adapters.ts`),
|
|
139
139
|
* which owns the slot key AND the node shape:
|
|
140
|
-
* - opencode-v2 → `providers` (`package`/`settings
|
|
141
|
-
* - opencode-v1 → `provider` (`npm`/`options
|
|
140
|
+
* - opencode-v2 → `providers` (`package`/`settings` → OCR `protocols`/`settings`);
|
|
141
|
+
* - opencode-v1 → `provider` (`npm`/`options` → OCR `protocols`/`settings`).
|
|
142
142
|
* Exactly one adapter runs per pass, so an id can only be seen once and the
|
|
143
143
|
* retired spelling of the other flavor is never read.
|
|
144
144
|
*
|
|
@@ -227,7 +227,7 @@ export function importProviderDefsFromClient(opts = {}) {
|
|
|
227
227
|
provider: id,
|
|
228
228
|
action: 'converted',
|
|
229
229
|
source: adapter.flavor,
|
|
230
|
-
reason: `translated ${adapter.flavor} node shape →
|
|
230
|
+
reason: `translated ${adapter.flavor} node shape → protocols/settings`,
|
|
231
231
|
});
|
|
232
232
|
imported += 1;
|
|
233
233
|
converted += 1;
|
|
@@ -38,15 +38,15 @@ export declare function maskSecret(secret?: string): string;
|
|
|
38
38
|
export declare function expandEnvTemplate(value?: string): string;
|
|
39
39
|
export declare const ROUTER_PROVIDER_ID = "omnicell-router";
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
* no v1 emit path and no legacy `provider`-slot reader.
|
|
41
|
+
* OCR provider defs have ONE shape and ONE home — `protocols`/`settings`/
|
|
42
|
+
* `headers`/`env`/`canonical`/`body` in the defs file's `providers` map
|
|
43
|
+
* (ADR-0010). The opencode client's `package` spelling is materialize-only.
|
|
45
44
|
*/
|
|
46
45
|
export interface ProviderDefInput {
|
|
47
46
|
id: string;
|
|
48
47
|
name?: string;
|
|
49
|
-
|
|
48
|
+
/** Ordered outbound protocol set. */
|
|
49
|
+
protocols?: string[];
|
|
50
50
|
baseURL?: string;
|
|
51
51
|
apiKey?: string;
|
|
52
52
|
/**
|
|
@@ -70,7 +70,7 @@ export interface ProviderDefInput {
|
|
|
70
70
|
export interface OpenCodeProviderView {
|
|
71
71
|
id: string;
|
|
72
72
|
name?: string;
|
|
73
|
-
|
|
73
|
+
protocols?: string[];
|
|
74
74
|
baseURL?: string;
|
|
75
75
|
models: string[];
|
|
76
76
|
/** Per-provider auto-pull whitelist (catalog.autoPullPatterns) — shown/prefilled by the console. */
|
|
@@ -105,19 +105,11 @@ export declare function isValidProviderId(id: string): boolean;
|
|
|
105
105
|
* never drift apart. */
|
|
106
106
|
export declare const PROVIDER_ID_RULE = "lowercase letters, digits, \".\", \"_\" or \"-\" only, starting with a letter or digit";
|
|
107
107
|
/**
|
|
108
|
-
* Normalize one
|
|
109
|
-
*
|
|
110
|
-
*
|
|
111
|
-
* - `settings` ≙ `options` (fill-missing overlay
|
|
112
|
-
*
|
|
113
|
-
* - top-level `headers` ≙ `options.headers` (opencode v2 moved that slot out; opencode v1 kept
|
|
114
|
-
* it inside options)
|
|
115
|
-
* - `env`/`body`/`canonical` ride through unchanged (no internal slot
|
|
116
|
-
* consumes them yet) and `settings` stays on the def too — boot-direct's
|
|
117
|
-
* model path still reads raw `settings.reasoningEffort`.
|
|
118
|
-
* opencode-v1 shaped defs are returned BY REFERENCE, untouched — zero behavior change
|
|
119
|
-
* for existing files. WRITE side emits both shapes via
|
|
120
|
-
* `upsertProviderDef({schema})` (P4).
|
|
108
|
+
* Normalize one provider def for OCR consumers:
|
|
109
|
+
* - `protocols` is the dial set (import may still carry client `package` —
|
|
110
|
+
* lifted here into protocols, then dropped)
|
|
111
|
+
* - `settings` ≙ `options` (fill-missing overlay)
|
|
112
|
+
* - top-level `headers` ≙ `options.headers`
|
|
121
113
|
*/
|
|
122
114
|
export declare function normalizeProviderDef(raw: unknown): any;
|
|
123
115
|
/**
|
|
@@ -146,8 +138,9 @@ export declare const CLIENT_COMPATIBLE_PACKAGE = "openai-chat";
|
|
|
146
138
|
* retired-shape nodes instead of routing providers opencode never registered.
|
|
147
139
|
*/
|
|
148
140
|
/**
|
|
149
|
-
* Retired NODE spellings the
|
|
150
|
-
*
|
|
141
|
+
* Retired NODE spellings the defs reader cannot route: node-level `npm`/
|
|
142
|
+
* `package`/`protocol` (the boot hop rewrites them to `protocols`) and the
|
|
143
|
+
* opencode-v1 `options` bag (moved to `settings`).
|
|
151
144
|
*
|
|
152
145
|
* MODEL-level defs are deliberately NOT gated. Verified against the decoder schema
|
|
153
146
|
* embedded in opencode v2.0.15: `providers.<id>.models` validates the models.dev
|
|
@@ -159,6 +152,11 @@ export declare const CLIENT_COMPATIBLE_PACKAGE = "openai-chat";
|
|
|
159
152
|
* broke every cache-priced model (pull + editor save) — a false positive, not a guard.
|
|
160
153
|
*/
|
|
161
154
|
export declare function legacyShapedProviderPaths(def: Record<string, any>): string[];
|
|
155
|
+
/**
|
|
156
|
+
* Materialize-time: OCR `provider.protocols` → client `provider.package`
|
|
157
|
+
* (singular primary). Used only when writing the opencode client copy.
|
|
158
|
+
*/
|
|
159
|
+
export declare function opencodeV2ModelDefs(models: Record<string, any> | undefined): Record<string, any> | undefined;
|
|
162
160
|
/**
|
|
163
161
|
* Assemble the opencode-v2 shaped `provider.<id>` node from a ProviderDefInput.
|
|
164
162
|
* Returns {error} without touching the file when the def cannot be written
|
|
@@ -184,8 +182,8 @@ export declare function getProviderNodeById(id: string): any | undefined;
|
|
|
184
182
|
/** Masked, management-safe view of every provider defined in the defs file. */
|
|
185
183
|
export declare function listConfigProviders(): OpenCodeProviderView[];
|
|
186
184
|
/**
|
|
187
|
-
* Upsert a custom provider into the OCR defs file's `providers` map, in the
|
|
188
|
-
* node shape (`
|
|
185
|
+
* Upsert a custom provider into the OCR defs file's `providers` map, in the OCR
|
|
186
|
+
* node shape (`protocols`/`settings`/`headers`/`env`/`canonical`/`body`).
|
|
189
187
|
*
|
|
190
188
|
* This writer NEVER touches credential files: the bound credential store owns
|
|
191
189
|
* secrets, so a non-inline key is pushed through store.connectKey once the def
|
|
@@ -225,9 +223,8 @@ export declare function getProviderModelDefs(id: string): Record<string, any> |
|
|
|
225
223
|
/**
|
|
226
224
|
* Add or replace one model inside `providers.<id>.models` (atomic defs-file
|
|
227
225
|
* rewrite). `definition` is the models.dev FILE shape (flat cost cache keys,
|
|
228
|
-
* keyed variants, model-level provider.npm)
|
|
229
|
-
*
|
|
230
|
-
* the retired-shape analysis).
|
|
226
|
+
* keyed variants, model-level provider.npm); the protocol slot is normalized
|
|
227
|
+
* to `provider.protocols` on write (ADR-0010), everything else is verbatim.
|
|
231
228
|
*/
|
|
232
229
|
export declare function upsertProviderModel(providerId: string, modelId: string, definition: Record<string, any>): {
|
|
233
230
|
success: boolean;
|
|
@@ -5,6 +5,7 @@ import { applyEdits, modify, parse, } from 'jsonc-parser';
|
|
|
5
5
|
import { renameWithRetry } from '../utils/atomic-write.js';
|
|
6
6
|
import { readProviderDefsFile, writeProviderDefs } from './provider-defs.js';
|
|
7
7
|
import { currentPackageFor } from './provider-package.js';
|
|
8
|
+
import { normalizeProtocols, primaryProtocol, DEFAULT_PROTOCOL } from '../providers/protocols-field.js';
|
|
8
9
|
import { resolveDefaultPaths, resolveOpencodeConfigPath } from './credentials/paths.js';
|
|
9
10
|
/**
|
|
10
11
|
* OpenCode-adjacent configuration management.
|
|
@@ -129,7 +130,7 @@ export function expandEnvTemplate(value) {
|
|
|
129
130
|
// Provider definitions (the OCR provider-defs file — `providers` map)
|
|
130
131
|
// ---------------------------------------------------------------------------
|
|
131
132
|
export const ROUTER_PROVIDER_ID = 'omnicell-router';
|
|
132
|
-
const
|
|
133
|
+
const DEFAULT_PROTOCOLS = [DEFAULT_PROTOCOL];
|
|
133
134
|
/**
|
|
134
135
|
* Valid custom-provider id - lowercase slug only (`[a-z0-9._-]`, leading
|
|
135
136
|
* letter/digit). The id is a verbatim key across case-sensitive stores (defs
|
|
@@ -150,48 +151,41 @@ export const PROVIDER_ID_RULE = 'lowercase letters, digits, ".", "_" or "-" only
|
|
|
150
151
|
// opencode v2 provider-shape READ normalization
|
|
151
152
|
// ---------------------------------------------------------------------------
|
|
152
153
|
/**
|
|
153
|
-
*
|
|
154
|
-
* `
|
|
155
|
-
* markers an opencode v1 def can never carry count as evidence — `env`, top-level
|
|
156
|
-
* `headers` and `name` are ambiguous across the two shapes and are
|
|
157
|
-
* deliberately NOT detection signals.
|
|
154
|
+
* OCR / client-shaped provider nodes carry `settings` (and optionally
|
|
155
|
+
* `protocols` or, on import-only client copies, `package`).
|
|
158
156
|
*/
|
|
159
|
-
function
|
|
160
|
-
return (raw.
|
|
157
|
+
function isSettingsShapedDef(raw) {
|
|
158
|
+
return (raw.protocols !== undefined ||
|
|
159
|
+
raw.package !== undefined ||
|
|
161
160
|
raw.settings !== undefined ||
|
|
162
161
|
raw.canonical !== undefined ||
|
|
163
162
|
raw.body !== undefined);
|
|
164
163
|
}
|
|
165
164
|
/**
|
|
166
|
-
* Normalize one
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* - `settings` ≙ `options` (fill-missing overlay
|
|
170
|
-
*
|
|
171
|
-
* - top-level `headers` ≙ `options.headers` (opencode v2 moved that slot out; opencode v1 kept
|
|
172
|
-
* it inside options)
|
|
173
|
-
* - `env`/`body`/`canonical` ride through unchanged (no internal slot
|
|
174
|
-
* consumes them yet) and `settings` stays on the def too — boot-direct's
|
|
175
|
-
* model path still reads raw `settings.reasoningEffort`.
|
|
176
|
-
* opencode-v1 shaped defs are returned BY REFERENCE, untouched — zero behavior change
|
|
177
|
-
* for existing files. WRITE side emits both shapes via
|
|
178
|
-
* `upsertProviderDef({schema})` (P4).
|
|
165
|
+
* Normalize one provider def for OCR consumers:
|
|
166
|
+
* - `protocols` is the dial set (import may still carry client `package` —
|
|
167
|
+
* lifted here into protocols, then dropped)
|
|
168
|
+
* - `settings` ≙ `options` (fill-missing overlay)
|
|
169
|
+
* - top-level `headers` ≙ `options.headers`
|
|
179
170
|
*/
|
|
180
171
|
export function normalizeProviderDef(raw) {
|
|
181
172
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
182
173
|
return raw;
|
|
183
174
|
const rec = raw;
|
|
184
|
-
if (!
|
|
175
|
+
if (!isSettingsShapedDef(rec))
|
|
185
176
|
return raw;
|
|
186
177
|
const def = { ...rec };
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
178
|
+
delete def.npm;
|
|
179
|
+
delete def.package;
|
|
180
|
+
delete def.protocol;
|
|
181
|
+
const fromPackage = typeof rec.package === 'string' ? normalizeProtocols(currentPackageFor(rec.package)) : [];
|
|
182
|
+
const fromNpm = typeof rec.npm === 'string' ? normalizeProtocols(currentPackageFor(rec.npm)) : [];
|
|
183
|
+
const fromProtocols = normalizeProtocols(normalizeProtocols(rec.protocols).map((p) => currentPackageFor(p)));
|
|
184
|
+
const protocols = fromProtocols.length > 0 ? fromProtocols : fromPackage.length > 0 ? fromPackage : fromNpm;
|
|
185
|
+
if (protocols.length > 0)
|
|
186
|
+
def.protocols = protocols;
|
|
187
|
+
else
|
|
188
|
+
delete def.protocols;
|
|
195
189
|
const settings = rec.settings && typeof rec.settings === 'object' ? rec.settings : {};
|
|
196
190
|
const options = rec.options && typeof rec.options === 'object' ? { ...rec.options } : {};
|
|
197
191
|
for (const [k, v] of Object.entries(settings)) {
|
|
@@ -201,11 +195,6 @@ export function normalizeProviderDef(raw) {
|
|
|
201
195
|
if (options.headers === undefined && rec.headers && typeof rec.headers === 'object') {
|
|
202
196
|
options.headers = rec.headers;
|
|
203
197
|
}
|
|
204
|
-
// Credential slot: opencode v2 names the ENV VARS a provider reads instead of
|
|
205
|
-
// holding an inline template. Materialize the first name that actually resolves so
|
|
206
|
-
// OCR's existing `{env:X}` expansion (boot-direct, the console's inline badge) keeps
|
|
207
|
-
// working on a v2-shaped node — otherwise an env-supplied key reads as "no
|
|
208
|
-
// credential" while opencode itself routes fine with it.
|
|
209
198
|
if (options.apiKey === undefined && Array.isArray(rec.env) && rec.env.length > 0) {
|
|
210
199
|
const names = rec.env.filter((n) => typeof n === 'string' && n.length > 0);
|
|
211
200
|
const resolved = names.find((n) => (process.env[n] ?? '') !== '');
|
|
@@ -217,15 +206,8 @@ export function normalizeProviderDef(raw) {
|
|
|
217
206
|
return def;
|
|
218
207
|
}
|
|
219
208
|
/**
|
|
220
|
-
* Model-def sibling
|
|
221
|
-
* `provider.
|
|
222
|
-
* catModel.npm > def.npm > rec.npm) then flows the npm into wireFor. A retired
|
|
223
|
-
* opencode-v2 package value is translated to the OCR protocol id here, so wireFor
|
|
224
|
-
* only ever sees current spellings. NOTE: model-level `settings` is ALREADY
|
|
225
|
-
* the opencode v1 shape's slot (reasoningEffort/effort are read raw there by
|
|
226
|
-
* boot-direct), so unlike the provider level there is no settings→options
|
|
227
|
-
* overlay — only the `package` alias is normalized. Untouched opencode v1
|
|
228
|
-
* model defs pass through by reference.
|
|
209
|
+
* Model-def sibling: lift `provider.package`/`provider.npm` into
|
|
210
|
+
* `provider.protocols` for boot-direct resolution.
|
|
229
211
|
*/
|
|
230
212
|
function normalizeModelDef(raw) {
|
|
231
213
|
if (!raw || typeof raw !== 'object' || Array.isArray(raw))
|
|
@@ -234,13 +216,19 @@ function normalizeModelDef(raw) {
|
|
|
234
216
|
const provider = rec.provider && typeof rec.provider === 'object' ? rec.provider : undefined;
|
|
235
217
|
if (!provider)
|
|
236
218
|
return raw;
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
219
|
+
const fromProtocols = normalizeProtocols(normalizeProtocols(provider.protocols).map((p) => currentPackageFor(p)));
|
|
220
|
+
const fromPackage = typeof provider.package === 'string' ? normalizeProtocols(currentPackageFor(provider.package)) : [];
|
|
221
|
+
const fromNpm = typeof provider.npm === 'string' ? normalizeProtocols(currentPackageFor(provider.npm)) : [];
|
|
222
|
+
const protocols = fromProtocols.length > 0 ? fromProtocols : fromPackage.length > 0 ? fromPackage : fromNpm;
|
|
223
|
+
const nextProvider = { ...provider };
|
|
224
|
+
delete nextProvider.npm;
|
|
225
|
+
delete nextProvider.package;
|
|
226
|
+
delete nextProvider.protocol;
|
|
227
|
+
if (protocols.length > 0)
|
|
228
|
+
nextProvider.protocols = protocols;
|
|
229
|
+
else
|
|
230
|
+
delete nextProvider.protocols;
|
|
231
|
+
return { ...rec, provider: nextProvider };
|
|
244
232
|
}
|
|
245
233
|
/**
|
|
246
234
|
* Retired package spellings are translated by the shared protocol map
|
|
@@ -278,8 +266,9 @@ function isPlainRecord(v) {
|
|
|
278
266
|
* retired-shape nodes instead of routing providers opencode never registered.
|
|
279
267
|
*/
|
|
280
268
|
/**
|
|
281
|
-
* Retired NODE spellings the
|
|
282
|
-
*
|
|
269
|
+
* Retired NODE spellings the defs reader cannot route: node-level `npm`/
|
|
270
|
+
* `package`/`protocol` (the boot hop rewrites them to `protocols`) and the
|
|
271
|
+
* opencode-v1 `options` bag (moved to `settings`).
|
|
283
272
|
*
|
|
284
273
|
* MODEL-level defs are deliberately NOT gated. Verified against the decoder schema
|
|
285
274
|
* embedded in opencode v2.0.15: `providers.<id>.models` validates the models.dev
|
|
@@ -292,38 +281,67 @@ function isPlainRecord(v) {
|
|
|
292
281
|
*/
|
|
293
282
|
export function legacyShapedProviderPaths(def) {
|
|
294
283
|
const bad = [];
|
|
284
|
+
// OCR truth forbids retired singular protocol slots and the opencode-v1 options bag.
|
|
295
285
|
if (def.npm !== undefined)
|
|
296
286
|
bad.push('npm');
|
|
287
|
+
if (def.package !== undefined)
|
|
288
|
+
bad.push('package');
|
|
289
|
+
if (def.protocol !== undefined)
|
|
290
|
+
bad.push('protocol');
|
|
297
291
|
if (def.options !== undefined)
|
|
298
292
|
bad.push('options');
|
|
299
293
|
return bad;
|
|
300
294
|
}
|
|
301
295
|
/**
|
|
302
|
-
*
|
|
303
|
-
* internal `provider.npm` slot becomes the client shape's `provider.package`
|
|
304
|
-
* slot. The value is the npm string VERBATIM: the retired
|
|
305
|
-
* `@opencode/ai/providers/*` vocabulary is never emitted again.
|
|
306
|
-
* Everything else in a model def is already the client's file shape
|
|
307
|
-
* (console.ts's bodyToModelDef is the single catalog-style→def converter
|
|
308
|
-
* shared by the model editor routes; this mirror does NOT fork a second
|
|
309
|
-
* converter).
|
|
296
|
+
* Persist model defs with OCR `provider.protocols` only (no npm/package).
|
|
310
297
|
*/
|
|
311
|
-
function
|
|
298
|
+
function ocrModelDefs(models) {
|
|
312
299
|
if (!models)
|
|
313
300
|
return undefined;
|
|
314
301
|
const out = {};
|
|
315
302
|
for (const [mid, m] of Object.entries(models)) {
|
|
316
303
|
const provider = isPlainRecord(m) && isPlainRecord(m.provider) ? m.provider : undefined;
|
|
317
|
-
if (provider
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
delete providerOut.npm;
|
|
321
|
-
providerOut.package = npmValue;
|
|
322
|
-
out[mid] = { ...m, provider: providerOut };
|
|
304
|
+
if (!provider) {
|
|
305
|
+
out[mid] = m;
|
|
306
|
+
continue;
|
|
323
307
|
}
|
|
324
|
-
|
|
308
|
+
const protocols = normalizeProtocols(provider.protocols ?? provider.package ?? provider.npm);
|
|
309
|
+
const providerOut = { ...provider };
|
|
310
|
+
delete providerOut.npm;
|
|
311
|
+
delete providerOut.package;
|
|
312
|
+
delete providerOut.protocol;
|
|
313
|
+
if (protocols.length > 0)
|
|
314
|
+
providerOut.protocols = protocols;
|
|
315
|
+
else
|
|
316
|
+
delete providerOut.protocols;
|
|
317
|
+
out[mid] = { ...m, provider: providerOut };
|
|
318
|
+
}
|
|
319
|
+
return out;
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Materialize-time: OCR `provider.protocols` → client `provider.package`
|
|
323
|
+
* (singular primary). Used only when writing the opencode client copy.
|
|
324
|
+
*/
|
|
325
|
+
export function opencodeV2ModelDefs(models) {
|
|
326
|
+
if (!models)
|
|
327
|
+
return undefined;
|
|
328
|
+
const out = {};
|
|
329
|
+
for (const [mid, m] of Object.entries(models)) {
|
|
330
|
+
const provider = isPlainRecord(m) && isPlainRecord(m.provider) ? m.provider : undefined;
|
|
331
|
+
if (!provider) {
|
|
325
332
|
out[mid] = m;
|
|
333
|
+
continue;
|
|
326
334
|
}
|
|
335
|
+
const protocols = normalizeProtocols(provider.protocols ?? provider.package ?? provider.npm);
|
|
336
|
+
const providerOut = { ...provider };
|
|
337
|
+
delete providerOut.npm;
|
|
338
|
+
delete providerOut.protocols;
|
|
339
|
+
delete providerOut.protocol;
|
|
340
|
+
if (protocols.length > 0)
|
|
341
|
+
providerOut.package = primaryProtocol(protocols);
|
|
342
|
+
else
|
|
343
|
+
delete providerOut.package;
|
|
344
|
+
out[mid] = { ...m, provider: providerOut };
|
|
327
345
|
}
|
|
328
346
|
return out;
|
|
329
347
|
}
|
|
@@ -378,7 +396,8 @@ export function buildV2ProviderNode(def) {
|
|
|
378
396
|
const node = {};
|
|
379
397
|
if (def.name)
|
|
380
398
|
node.name = def.name;
|
|
381
|
-
|
|
399
|
+
const protocols = normalizeProtocols(normalizeProtocols(def.protocols).map((p) => currentPackageFor(p)));
|
|
400
|
+
node.protocols = protocols.length > 0 ? protocols : [...DEFAULT_PROTOCOLS];
|
|
382
401
|
if (def.canonical)
|
|
383
402
|
node.canonical = def.canonical;
|
|
384
403
|
if (envNames.size > 0)
|
|
@@ -389,7 +408,7 @@ export function buildV2ProviderNode(def) {
|
|
|
389
408
|
node.headers = headers;
|
|
390
409
|
if (isPlainRecord(def.body) && Object.keys(def.body).length > 0)
|
|
391
410
|
node.body = def.body;
|
|
392
|
-
const models =
|
|
411
|
+
const models = ocrModelDefs(def.models);
|
|
393
412
|
if (models && Object.keys(models).length > 0)
|
|
394
413
|
node.models = models;
|
|
395
414
|
return { node };
|
|
@@ -471,7 +490,7 @@ export function listConfigProviders() {
|
|
|
471
490
|
return {
|
|
472
491
|
id,
|
|
473
492
|
name: def?.name || undefined,
|
|
474
|
-
|
|
493
|
+
protocols: normalizeProtocols(def?.protocols),
|
|
475
494
|
baseURL: options.baseURL || undefined,
|
|
476
495
|
models,
|
|
477
496
|
auth: {
|
|
@@ -483,8 +502,8 @@ export function listConfigProviders() {
|
|
|
483
502
|
});
|
|
484
503
|
}
|
|
485
504
|
/**
|
|
486
|
-
* Upsert a custom provider into the OCR defs file's `providers` map, in the
|
|
487
|
-
* node shape (`
|
|
505
|
+
* Upsert a custom provider into the OCR defs file's `providers` map, in the OCR
|
|
506
|
+
* node shape (`protocols`/`settings`/`headers`/`env`/`canonical`/`body`).
|
|
488
507
|
*
|
|
489
508
|
* This writer NEVER touches credential files: the bound credential store owns
|
|
490
509
|
* secrets, so a non-inline key is pushed through store.connectKey once the def
|
|
@@ -587,9 +606,8 @@ export function getProviderModelDefs(id) {
|
|
|
587
606
|
/**
|
|
588
607
|
* Add or replace one model inside `providers.<id>.models` (atomic defs-file
|
|
589
608
|
* rewrite). `definition` is the models.dev FILE shape (flat cost cache keys,
|
|
590
|
-
* keyed variants, model-level provider.npm)
|
|
591
|
-
*
|
|
592
|
-
* the retired-shape analysis).
|
|
609
|
+
* keyed variants, model-level provider.npm); the protocol slot is normalized
|
|
610
|
+
* to `provider.protocols` on write (ADR-0010), everything else is verbatim.
|
|
593
611
|
*/
|
|
594
612
|
export function upsertProviderModel(providerId, modelId, definition) {
|
|
595
613
|
if (!getProviderNodeById(providerId)) {
|
|
@@ -13,6 +13,7 @@ import { DEFAULT_LAYER2_EFFORT_FLOOR } from '../config/defaults.js';
|
|
|
13
13
|
import { appendRoutingLedger } from '../router/routing-ledger.js';
|
|
14
14
|
import { SchemaAssertion } from '../validator/schema-assertion.js';
|
|
15
15
|
import { FallbackContextBuilder } from '../validator/parser.js';
|
|
16
|
+
import { pickDialWire } from '../providers/dial-wire.js';
|
|
16
17
|
import { applyEffortMap } from '../providers/member-match.js';
|
|
17
18
|
import { protocolForWire } from '../providers/vocabulary.js';
|
|
18
19
|
import { capabilitiesFor } from '../ir/capabilities.js';
|
|
@@ -1112,7 +1113,10 @@ export class PipelineOrchestrator {
|
|
|
1112
1113
|
// the default pin / effort matching below, so capability clamps and the
|
|
1113
1114
|
// X-OCR-Thinking-* headers see it; the budget itself stays on the request
|
|
1114
1115
|
// for wires that consume it natively.
|
|
1115
|
-
|
|
1116
|
+
// Prefer-native dial (same pickDialWire registry.execute uses) — effort
|
|
1117
|
+
// prep and X-OCR-Protocol must name the wire THIS attempt will dial, not
|
|
1118
|
+
// protocols[0] / the boot primary alone.
|
|
1119
|
+
const servedWire = pickDialWire(actualModel.protocols ?? (actualModel.wire ? [actualModel.wire] : undefined), context?.wire, normalizedRequest);
|
|
1116
1120
|
const budgetTokens = normalizedRequest.reasoning?.budgetTokens;
|
|
1117
1121
|
if (effortOf(normalizedRequest) === undefined &&
|
|
1118
1122
|
typeof budgetTokens === 'number' &&
|
|
@@ -1379,6 +1383,7 @@ export class PipelineOrchestrator {
|
|
|
1379
1383
|
requestedEffort,
|
|
1380
1384
|
variantUsed,
|
|
1381
1385
|
},
|
|
1386
|
+
inboundWire: context?.wire,
|
|
1382
1387
|
}, upstreamEventContext);
|
|
1383
1388
|
if (!plusResult.success || !plusResult.response) {
|
|
1384
1389
|
if (plusResult.policyDenied) {
|
|
@@ -1527,6 +1532,7 @@ export class PipelineOrchestrator {
|
|
|
1527
1532
|
requestedEffort,
|
|
1528
1533
|
variantUsed,
|
|
1529
1534
|
},
|
|
1535
|
+
inboundWire: context?.wire,
|
|
1530
1536
|
}, upstreamEventContext);
|
|
1531
1537
|
if (!execResult.success || !execResult.response) {
|
|
1532
1538
|
if (execResult.policyDenied) {
|
|
@@ -2174,6 +2180,10 @@ export class PipelineOrchestrator {
|
|
|
2174
2180
|
noteCode: forcedPass.noteCode,
|
|
2175
2181
|
});
|
|
2176
2182
|
}
|
|
2183
|
+
// Prefer-native dial for THIS attempt — effort prep, staging headers, and
|
|
2184
|
+
// the returned modelUsed.wire must match what registry.execute dials.
|
|
2185
|
+
const dialWire = pickDialWire(candidate.protocols ?? (candidate.wire ? [candidate.wire] : undefined), opts.inboundWire, request);
|
|
2186
|
+
const dialCandidate = dialWire === candidate.wire ? candidate : { ...candidate, wire: dialWire };
|
|
2177
2187
|
// per-candidate effort translation. Each chain member serves
|
|
2178
2188
|
// through ITS OWN effortMap (`none` included), clamped by its declared
|
|
2179
2189
|
// capability — the request copy carries exactly what gets sent (a
|
|
@@ -2183,7 +2193,7 @@ export class PipelineOrchestrator {
|
|
|
2183
2193
|
const budgetAsk = opts.requestedEffort === undefined &&
|
|
2184
2194
|
typeof request.reasoning?.budgetTokens === 'number' &&
|
|
2185
2195
|
request.reasoning.budgetTokens > 0 &&
|
|
2186
|
-
!this.wireConsumesBudgetNatively(
|
|
2196
|
+
!this.wireConsumesBudgetNatively(dialCandidate.wire)
|
|
2187
2197
|
? effortFromThinkingBudget(request.reasoning.budgetTokens)
|
|
2188
2198
|
: undefined;
|
|
2189
2199
|
const ask = opts.requestedEffort ?? budgetAsk ?? 'none';
|
|
@@ -2211,7 +2221,7 @@ export class PipelineOrchestrator {
|
|
|
2211
2221
|
// signatures / encrypted blobs so long multi-turn threads can still fail over
|
|
2212
2222
|
// to Chat-only upstreams instead of failing with 400 on the backup model.
|
|
2213
2223
|
if (failoverAttempts > 1 &&
|
|
2214
|
-
!capabilitiesFor(protocolForWire(
|
|
2224
|
+
!capabilitiesFor(protocolForWire(dialCandidate.wire ?? 'openai-chat')).reasoningSignature &&
|
|
2215
2225
|
candidateReq.input.some((item) => item.type === 'reasoning' && (item.signature !== undefined || item.encrypted !== undefined))) {
|
|
2216
2226
|
const strippedInput = candidateReq.input.flatMap((item) => {
|
|
2217
2227
|
if (item.type !== 'reasoning' || (item.signature === undefined && item.encrypted === undefined))
|
|
@@ -2228,9 +2238,9 @@ export class PipelineOrchestrator {
|
|
|
2228
2238
|
if (opts.relay) {
|
|
2229
2239
|
opts.relay.stageRouting({
|
|
2230
2240
|
...opts.streamRouting,
|
|
2231
|
-
modelUsed:
|
|
2241
|
+
modelUsed: dialCandidate.id,
|
|
2232
2242
|
tierUsed: candidateAccessTier,
|
|
2233
|
-
protocolUsed: protocolForWire(
|
|
2243
|
+
protocolUsed: protocolForWire(dialCandidate.wire ?? 'openai-chat'),
|
|
2234
2244
|
});
|
|
2235
2245
|
}
|
|
2236
2246
|
// In-place retry loop on the SAME candidate model
|
|
@@ -2298,7 +2308,7 @@ export class PipelineOrchestrator {
|
|
|
2298
2308
|
// Resolve egress at the dial: the proxy config hot-applies, so a
|
|
2299
2309
|
// read at trace time could describe a different dial than this one.
|
|
2300
2310
|
attemptEgress = this.registry.egressFor(candidate);
|
|
2301
|
-
candidateResponse = await this.registry.execute(candidateReq,
|
|
2311
|
+
candidateResponse = await this.registry.execute(candidateReq, dialCandidate, upstreamEventContext, credentialPrefix, timingRelay, opts.sessionId, opts.inboundWire);
|
|
2302
2312
|
if (firstChunkAt !== undefined)
|
|
2303
2313
|
streamEndAt = Date.now();
|
|
2304
2314
|
// Scope-aware success: undefined prefix degenerates to the exact
|
|
@@ -2428,7 +2438,7 @@ export class PipelineOrchestrator {
|
|
|
2428
2438
|
return {
|
|
2429
2439
|
success: true,
|
|
2430
2440
|
response: candidateResponse,
|
|
2431
|
-
modelUsed:
|
|
2441
|
+
modelUsed: dialCandidate,
|
|
2432
2442
|
tierUsed: candidateAccessTier,
|
|
2433
2443
|
failoverOccurred: failoverAttempts > 1,
|
|
2434
2444
|
failoverAttempts,
|