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.
Files changed (86) hide show
  1. package/backend/dist/auth/api-keys.js +11 -0
  2. package/backend/dist/auth/key-models.d.ts +36 -0
  3. package/backend/dist/auth/key-models.js +99 -0
  4. package/backend/dist/cli/clients/activity.js +2 -0
  5. package/backend/dist/cli/clients/codex.d.ts +70 -0
  6. package/backend/dist/cli/clients/codex.js +470 -57
  7. package/backend/dist/cli/clients/follow-catalog-sync.d.ts +62 -0
  8. package/backend/dist/cli/clients/follow-catalog-sync.js +435 -0
  9. package/backend/dist/cli/clients/opencode.js +3 -2
  10. package/backend/dist/cli/clients/reserved.js +2 -0
  11. package/backend/dist/cli/types.d.ts +9 -0
  12. package/backend/dist/config/comments-en.js +5 -1
  13. package/backend/dist/config/comments-zh.js +5 -1
  14. package/backend/dist/config/defaults.d.ts +98 -1
  15. package/backend/dist/config/defaults.js +98 -1
  16. package/backend/dist/config/index.d.ts +15 -1
  17. package/backend/dist/config/index.js +35 -1
  18. package/backend/dist/config/migrations/v4-to-v5.d.ts +36 -0
  19. package/backend/dist/config/migrations/v4-to-v5.js +42 -0
  20. package/backend/dist/config/migrations/v5-to-v6.d.ts +27 -0
  21. package/backend/dist/config/migrations/v5-to-v6.js +29 -0
  22. package/backend/dist/config/schema.d.ts +3 -3
  23. package/backend/dist/config/schema.js +8 -4
  24. package/backend/dist/config/types.d.ts +54 -3
  25. package/backend/dist/forward-proxy/egress.js +13 -0
  26. package/backend/dist/forward-proxy/h2-forward.js +6 -5
  27. package/backend/dist/forward-proxy/index.js +5 -0
  28. package/backend/dist/forward-proxy/server.d.ts +12 -0
  29. package/backend/dist/forward-proxy/server.js +113 -15
  30. package/backend/dist/index.js +6 -1
  31. package/backend/dist/ir/adapters/openai-chat.js +5 -3
  32. package/backend/dist/ir/adapters/openai-responses-output.js +2 -2
  33. package/backend/dist/ir/adapters/openai-responses.d.ts +33 -0
  34. package/backend/dist/ir/adapters/openai-responses.js +44 -2
  35. package/backend/dist/ir/capabilities.js +4 -0
  36. package/backend/dist/ir/validate.d.ts +24 -0
  37. package/backend/dist/ir/validate.js +113 -63
  38. package/backend/dist/opencode/catalog/auto-pull.js +8 -7
  39. package/backend/dist/opencode/catalog/ocr-store.d.ts +7 -6
  40. package/backend/dist/opencode/catalog/ocr-store.js +2 -2
  41. package/backend/dist/opencode/catalog/overrides-store.d.ts +5 -3
  42. package/backend/dist/opencode/catalog/overrides-store.js +22 -19
  43. package/backend/dist/opencode/catalog/repository.js +3 -3
  44. package/backend/dist/opencode/catalog/sources/models-dev.d.ts +3 -3
  45. package/backend/dist/opencode/catalog/sources/models-dev.js +29 -11
  46. package/backend/dist/opencode/catalog/types.d.ts +7 -9
  47. package/backend/dist/opencode/credentials/def-materialize.js +27 -21
  48. package/backend/dist/opencode/migrate/engine.d.ts +20 -0
  49. package/backend/dist/opencode/migrate/engine.js +71 -0
  50. package/backend/dist/opencode/migrate/migrator.d.ts +11 -0
  51. package/backend/dist/opencode/migrate/migrator.js +6 -0
  52. package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.d.ts +6 -0
  53. package/backend/dist/opencode/migrate/steps/overrides-v1-to-v2.js +31 -0
  54. package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.d.ts +6 -0
  55. package/backend/dist/opencode/migrate/steps/providers-v1-to-v2.js +62 -0
  56. package/backend/dist/opencode/provider-def-adapters.d.ts +12 -11
  57. package/backend/dist/opencode/provider-def-adapters.js +43 -27
  58. package/backend/dist/opencode/provider-defs.d.ts +10 -16
  59. package/backend/dist/opencode/provider-defs.js +45 -45
  60. package/backend/dist/opencode/user-config.d.ts +23 -26
  61. package/backend/dist/opencode/user-config.js +95 -77
  62. package/backend/dist/pipeline/orchestrator.js +17 -7
  63. package/backend/dist/plugins/builtin/model-gateway.js +38 -12
  64. package/backend/dist/plugins/host.d.ts +2 -2
  65. package/backend/dist/plugins/host.js +15 -12
  66. package/backend/dist/providers/boot-direct.js +32 -8
  67. package/backend/dist/providers/dial-wire.d.ts +17 -0
  68. package/backend/dist/providers/dial-wire.js +49 -0
  69. package/backend/dist/providers/protocols-field.d.ts +24 -0
  70. package/backend/dist/providers/protocols-field.js +66 -0
  71. package/backend/dist/providers/registry.d.ts +3 -1
  72. package/backend/dist/providers/registry.js +23 -7
  73. package/backend/dist/quota/cli-login.js +3 -1
  74. package/backend/dist/routes/console.js +115 -95
  75. package/backend/dist/server.js +91 -2
  76. package/backend/dist/surfaces/anthropic.js +4 -1
  77. package/backend/dist/surfaces/body-admission.d.ts +279 -0
  78. package/backend/dist/surfaces/body-admission.js +613 -0
  79. package/backend/dist/surfaces/transport-node-http.d.ts +44 -5
  80. package/backend/dist/surfaces/transport-node-http.js +86 -13
  81. package/backend/dist/utils/server-liveness.d.ts +27 -0
  82. package/backend/dist/utils/server-liveness.js +31 -0
  83. package/frontend/dist/assets/{index-55VVwfFQ.js → index-Dk76uc7e.js} +367 -366
  84. package/frontend/dist/assets/{index-DxZ9MHKB.css → index-KI1OW5x6.css} +1 -1
  85. package/frontend/dist/index.html +2 -2
  86. 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 = 2;
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
- def.provider = { ...(def.provider || {}), npm: v };
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
- * Defs written by older builds carry retired package spellings
41
- * (`@opencode/ai/providers/*`, `@ai-sdk/*`). Normalize them to the OCR
42
- * protocol id on every read AND write so the book converges without a
43
- * separate migration pass; the retired spelling is never emitted again.
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 currentPackageNodes(providers) {
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
- if (typeof node.package === 'string') {
54
- const pkg = currentPackageFor(node.package);
55
- if (pkg !== node.package)
56
- next = { ...next, package: pkg };
57
- }
58
- if (typeof node.npm === 'string') {
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
- let nextProvider = provider;
70
- if (typeof provider.package === 'string') {
71
- const pkg = currentPackageFor(provider.package);
72
- if (pkg !== provider.package)
73
- nextProvider = { ...nextProvider, package: pkg };
74
- }
75
- if (typeof provider.npm === 'string') {
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
- if (modelsChanged)
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 !== 1 || typeof parsed.providers !== 'object' || parsed.providers === null) {
102
+ if (parsed?.version !== PROVIDERS_SCHEMA || typeof parsed.providers !== 'object' || parsed.providers === null) {
103
103
  return null;
104
104
  }
105
- return { ...parsed, providers: currentPackageNodes(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: 1, updated: Date.now(), providers: currentPackageNodes(providers) };
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`, verbatim);
141
- * - opencode-v1 → `provider` (`npm`/`options`, translated by its adapter).
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 → package/settings`,
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
- * No legacy compatibility: provider defs have ONE shape and ONE home — the v2
42
- * node (`package`/`settings`/`headers`/`env`/`canonical`/`body`) in the defs
43
- * file's `providers` map. opencode v1 installs are not supported, so there is
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
- npm?: string;
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
- npm?: string;
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 opencode-v2 shaped provider def to the internal (opencode v1) shape every
109
- * consumer below boot already reads:
110
- * - `package` ≙ `npm`
111
- * - `settings` ≙ `options` (fill-missing overlay — an opencode v1 `options` mixed into
112
- * a partially migrated file wins on conflict)
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 v2 `providers` decoder cannot read: node-level `npm`
150
- * and `options` (moved to `package`/`settings`).
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 v2
188
- * node shape (`package`/`settings`/`headers`/`env`/`canonical`/`body`).
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) and is written verbatim — v2's
229
- * file decoder reads that shape natively (see legacyShapedProviderPaths for
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 DEFAULT_NPM = 'openai-chat';
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
- * Opencode v2 provider defs replace opencode v1 `npm`/`options` with
154
- * `name`/`env`/`package`/`canonical`/`settings`/`headers`/`body`. Only
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 isOpencodeV2ShapedDef(raw) {
160
- return (raw.package !== undefined ||
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 opencode-v2 shaped provider def to the internal (opencode v1) shape every
167
- * consumer below boot already reads:
168
- * - `package` ≙ `npm`
169
- * - `settings` ≙ `options` (fill-missing overlay — an opencode v1 `options` mixed into
170
- * a partially migrated file wins on conflict)
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 (!isOpencodeV2ShapedDef(rec))
175
+ if (!isSettingsShapedDef(rec))
185
176
  return raw;
186
177
  const def = { ...rec };
187
- if (typeof def.npm === 'string')
188
- def.npm = currentPackageFor(def.npm);
189
- if (typeof rec.package === 'string') {
190
- const pkg = currentPackageFor(rec.package);
191
- def.package = pkg;
192
- if (def.npm === undefined)
193
- def.npm = pkg;
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 of normalizeProviderDef: `provider.package` ≙
221
- * `provider.npm` — the boot-direct npm precedence chain (d.provider.npm >
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
- if (typeof provider.npm === 'string') {
238
- const normalized = currentPackageFor(provider.npm);
239
- return normalized === provider.npm ? raw : { ...rec, provider: { ...provider, npm: normalized } };
240
- }
241
- if (provider.npm !== undefined || typeof provider.package !== 'string')
242
- return raw;
243
- return { ...rec, provider: { ...provider, npm: currentPackageFor(provider.package) } };
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 v2 `providers` decoder cannot read: node-level `npm`
282
- * and `options` (moved to `package`/`settings`).
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
- * Model-level write normalization — the reverse of normalizeModelDef: the
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 opencodeV2ModelDefs(models) {
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 && typeof provider.npm === 'string' && provider.package === undefined) {
318
- const providerOut = { ...provider };
319
- const npmValue = provider.npm;
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
- else {
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
- node.package = def.npm || DEFAULT_NPM;
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 = opencodeV2ModelDefs(def.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
- npm: def?.npm || undefined,
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 v2
487
- * node shape (`package`/`settings`/`headers`/`env`/`canonical`/`body`).
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) and is written verbatim — v2's
591
- * file decoder reads that shape natively (see legacyShapedProviderPaths for
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
- const servedWire = actualModel.wire ?? 'openai-chat';
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(candidate.wire)
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(candidate.wire ?? 'openai-chat')).reasoningSignature &&
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: candidate.id,
2241
+ modelUsed: dialCandidate.id,
2232
2242
  tierUsed: candidateAccessTier,
2233
- protocolUsed: protocolForWire(candidate.wire ?? 'openai-chat'),
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, candidate, upstreamEventContext, credentialPrefix, timingRelay, opts.sessionId);
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: candidate,
2441
+ modelUsed: dialCandidate,
2432
2442
  tierUsed: candidateAccessTier,
2433
2443
  failoverOccurred: failoverAttempts > 1,
2434
2444
  failoverAttempts,