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,6 +1,7 @@
|
|
|
1
1
|
import { dispatchSurface } from '../../surfaces/dispatch.js';
|
|
2
2
|
import { detectSurface } from '../../surfaces/table.js';
|
|
3
3
|
import { createNodeHttpTransport, readRequestBody, sendPreDispatchError } from '../../surfaces/transport-node-http.js';
|
|
4
|
+
import { decompressBody, invalidJsonBody, isBodyAdmissionError, logBodyRejection, parseJsonBody, requestContentEncoding, preflightBodyAdmission, bodyLimitFor } from '../../surfaces/body-admission.js';
|
|
4
5
|
/**
|
|
5
6
|
* The BUILT-IN universal gateway — the canonical model wires, expressed as a
|
|
6
7
|
* gateway like any other (ADR-0026 revision 2).
|
|
@@ -52,24 +53,49 @@ export function createBuiltinModelGateway(orchestrator) {
|
|
|
52
53
|
res.end(JSON.stringify({ error: { message: 'No canonical surface for this path' } }));
|
|
53
54
|
return;
|
|
54
55
|
}
|
|
55
|
-
let
|
|
56
|
-
try {
|
|
57
|
-
raw = await readRequestBody(req);
|
|
58
|
-
}
|
|
59
|
-
catch (err) {
|
|
60
|
-
sendPreDispatchError(res, surface, 413, err instanceof Error ? err.message : 'Request body too large');
|
|
61
|
-
return;
|
|
62
|
-
}
|
|
56
|
+
let receivedBytes;
|
|
63
57
|
let body;
|
|
64
58
|
try {
|
|
65
|
-
body
|
|
59
|
+
// Media type and request coding are checked BEFORE the body is read:
|
|
60
|
+
// a form-urlencoded or XML upload must be refused rather than buffered and
|
|
61
|
+
// then rejected as "invalid JSON", and a body claiming a coding the gateway
|
|
62
|
+
// cannot decode must not pay for its own upload. The native leg refuses the
|
|
63
|
+
// same types (Fastify's own media-type gate) and the same codings, so the two
|
|
64
|
+
// legs cannot disagree about serviceability.
|
|
65
|
+
const preRefusal = preflightBodyAdmission(req.headers);
|
|
66
|
+
if (preRefusal)
|
|
67
|
+
throw preRefusal;
|
|
68
|
+
const raw = await readRequestBody(req);
|
|
69
|
+
receivedBytes = raw.length;
|
|
70
|
+
// Same admission policy as the native leg: decode Content-Encoding with
|
|
71
|
+
// the cap re-checked on the INFLATED size (readRequestBody bounded the
|
|
72
|
+
// wire size), then parse. Both throw BodyAdmissionError carrying status,
|
|
73
|
+
// code and the client-facing message, so the two legs cannot drift.
|
|
74
|
+
body = parseJsonBody(decompressBody(raw, req.headers));
|
|
66
75
|
}
|
|
67
|
-
catch {
|
|
68
|
-
|
|
76
|
+
catch (err) {
|
|
77
|
+
if (!isBodyAdmissionError(err)) {
|
|
78
|
+
// A socket/read failure is not an admission decision — answer 400 with
|
|
79
|
+
// the underlying reason rather than hanging the client.
|
|
80
|
+
sendPreDispatchError(res, surface, 400, err instanceof Error ? err.message : 'Unreadable request body');
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
logBodyRejection({
|
|
84
|
+
leg: 'mitm',
|
|
85
|
+
path: req.url || '',
|
|
86
|
+
err,
|
|
87
|
+
capBytes: bodyLimitFor('gateway'),
|
|
88
|
+
receivedBytes,
|
|
89
|
+
encoding: requestContentEncoding(req.headers),
|
|
90
|
+
}, undefined);
|
|
91
|
+
sendPreDispatchError(res, surface, err.statusCode, err.message, err.code, err.headers);
|
|
69
92
|
return;
|
|
70
93
|
}
|
|
71
94
|
if (!body || typeof body !== 'object') {
|
|
72
|
-
|
|
95
|
+
// Valid JSON, wrong shape (array/string/number/null). Same 400 and the
|
|
96
|
+
// same code and words as the native leg's shape check — the client's fix
|
|
97
|
+
// is identical to a parse failure's.
|
|
98
|
+
sendPreDispatchError(res, surface, 400, invalidJsonBody().message, 'invalid_json_body');
|
|
73
99
|
return;
|
|
74
100
|
}
|
|
75
101
|
// surface.capture is the PROTOCOL-LEVEL capture policy (chat family:
|
|
@@ -166,7 +166,7 @@ export declare function forgetProviderRegistration(providerId: string): void;
|
|
|
166
166
|
/** Register every not-yet-defined preset of every loaded plugin, and RETIRE the
|
|
167
167
|
* ones the plugin no longer declares. A preset is skipped whenever the defs
|
|
168
168
|
* file already holds a MEANINGFUL node with that id, so presets never take
|
|
169
|
-
* over operator file state; a bare
|
|
169
|
+
* over operator file state; a bare protocol-only stub (the New-custom form or
|
|
170
170
|
* the boot bind sweep's node — machine-written, no operator content) is fair
|
|
171
171
|
* game and the preset overwrites it. The ONE exception is an unroutable wire
|
|
172
172
|
* spelling (an older plugin generation's SDK package, e.g.
|
|
@@ -197,7 +197,7 @@ export declare function pluginPresetCatalogEntries(lang?: string): Promise<{
|
|
|
197
197
|
name: string;
|
|
198
198
|
defaultName: string;
|
|
199
199
|
logo?: string;
|
|
200
|
-
|
|
200
|
+
protocols?: string[];
|
|
201
201
|
baseURL?: string;
|
|
202
202
|
custom: boolean;
|
|
203
203
|
connected: boolean;
|
|
@@ -1291,17 +1291,17 @@ function matchesRegistration(snapshot, current) {
|
|
|
1291
1291
|
}
|
|
1292
1292
|
/** A MEANINGFUL def is operator-owned and never overwritten/deleted, and
|
|
1293
1293
|
* joins the ledger (provenance tag/filter). A bare stub (New-custom leftover:
|
|
1294
|
-
* only a
|
|
1295
|
-
* operator file node the plugin never created; an existing node is NEVER
|
|
1294
|
+
* only a protocol-slot field) is left un-ledgered so uninstall never deletes
|
|
1295
|
+
* an operator file node the plugin never created; an existing node is NEVER
|
|
1296
1296
|
* taken over by a preset (syncPluginPresets skips every id already present).
|
|
1297
1297
|
* Reads the RAW defs-file node:
|
|
1298
|
-
* getProviderNodeById returns a normalized view that derives
|
|
1299
|
-
*
|
|
1298
|
+
* getProviderNodeById returns a normalized view that derives protocols/options
|
|
1299
|
+
* from settings, which would make even a bare stub look meaningful. */
|
|
1300
1300
|
function isMeaningfulDef(raw) {
|
|
1301
1301
|
return Boolean(raw &&
|
|
1302
1302
|
Object.entries(raw).some(([key, value]) => {
|
|
1303
|
-
if (key === 'package')
|
|
1304
|
-
return false; // a New-custom stub is ONLY a
|
|
1303
|
+
if (key === 'package' || key === 'protocols')
|
|
1304
|
+
return false; // a New-custom stub is ONLY a protocol-slot field
|
|
1305
1305
|
if (key === 'models')
|
|
1306
1306
|
return Boolean(value && typeof value === 'object' && Object.keys(value).length > 0);
|
|
1307
1307
|
return value !== undefined && value !== null && value !== '' && !(typeof value === 'object' && Object.keys(value).length === 0);
|
|
@@ -1311,7 +1311,8 @@ function isMeaningfulDef(raw) {
|
|
|
1311
1311
|
* the console probe and the web-login resolver use (`wireFor(npm)` first,
|
|
1312
1312
|
* baseURL fingerprint only when no package is declared). */
|
|
1313
1313
|
function defWireOf(raw) {
|
|
1314
|
-
const
|
|
1314
|
+
const protocols = Array.isArray(raw.protocols) ? raw.protocols.filter((x) => typeof x === 'string') : [];
|
|
1315
|
+
const pkg = protocols[0] ?? (typeof raw.package === 'string' ? raw.package : typeof raw.npm === 'string' ? raw.npm : '');
|
|
1315
1316
|
if (pkg)
|
|
1316
1317
|
return wireFor(pkg);
|
|
1317
1318
|
const settings = raw.settings && typeof raw.settings === 'object' ? raw.settings : {};
|
|
@@ -1336,8 +1337,10 @@ function presetWireIsBroken(raw) {
|
|
|
1336
1337
|
* through untouched — the def could not have routed anywhere before, so no
|
|
1337
1338
|
* working configuration is lost. */
|
|
1338
1339
|
function repairPresetWire(raw, presetWire) {
|
|
1339
|
-
const next = { ...raw,
|
|
1340
|
+
const next = { ...raw, protocols: [presetWire] };
|
|
1340
1341
|
delete next.npm;
|
|
1342
|
+
delete next.package;
|
|
1343
|
+
delete next.protocol;
|
|
1341
1344
|
return next;
|
|
1342
1345
|
}
|
|
1343
1346
|
/** Def name a preset registers: the manifest's `displayName` (plain string) or
|
|
@@ -1350,7 +1353,7 @@ function presetDefName(preset) {
|
|
|
1350
1353
|
/** Register every not-yet-defined preset of every loaded plugin, and RETIRE the
|
|
1351
1354
|
* ones the plugin no longer declares. A preset is skipped whenever the defs
|
|
1352
1355
|
* file already holds a MEANINGFUL node with that id, so presets never take
|
|
1353
|
-
* over operator file state; a bare
|
|
1356
|
+
* over operator file state; a bare protocol-only stub (the New-custom form or
|
|
1354
1357
|
* the boot bind sweep's node — machine-written, no operator content) is fair
|
|
1355
1358
|
* game and the preset overwrites it. The ONE exception is an unroutable wire
|
|
1356
1359
|
* spelling (an older plugin generation's SDK package, e.g.
|
|
@@ -1440,7 +1443,7 @@ export async function syncPluginPresets() {
|
|
|
1440
1443
|
const result = upsertProviderDef({
|
|
1441
1444
|
id: preset.providerId,
|
|
1442
1445
|
name: presetDefName(preset),
|
|
1443
|
-
|
|
1446
|
+
protocols: [presetWire],
|
|
1444
1447
|
baseURL: preset.baseUrl,
|
|
1445
1448
|
});
|
|
1446
1449
|
if (result.success) {
|
|
@@ -1504,7 +1507,7 @@ export async function ensurePresetProvider(providerId) {
|
|
|
1504
1507
|
return upsertProviderDef({
|
|
1505
1508
|
id: preset.providerId,
|
|
1506
1509
|
name: presetDefName(preset),
|
|
1507
|
-
|
|
1510
|
+
protocols: [presetWire],
|
|
1508
1511
|
baseURL: preset.baseUrl,
|
|
1509
1512
|
}).success;
|
|
1510
1513
|
}
|
|
@@ -1601,7 +1604,7 @@ export async function pluginPresetCatalogEntries(lang) {
|
|
|
1601
1604
|
name,
|
|
1602
1605
|
defaultName,
|
|
1603
1606
|
logo: logoUrl,
|
|
1604
|
-
|
|
1607
|
+
protocols: [currentProtocol(preset.protocol || preset.npm)],
|
|
1605
1608
|
baseURL: preset.baseUrl,
|
|
1606
1609
|
custom: true,
|
|
1607
1610
|
// A plugin that owns login is connected when its def exists. A stored
|
|
@@ -10,6 +10,7 @@ import { keyHashPrefix } from '../opencode/credentials/types.js';
|
|
|
10
10
|
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
|
+
import { normalizeProtocols, primaryProtocol } from './protocols-field.js';
|
|
13
14
|
import { getProviderTakedownStore } from './provider-takedown.js';
|
|
14
15
|
import { getModelServicePlugin, pluginDeclinesCredentials } from '../plugins/host.js';
|
|
15
16
|
/** Raw key + display identity → the per-call selectable credential (P3 step 1).
|
|
@@ -97,7 +98,7 @@ function withoutForbiddenNone(levels, disableable) {
|
|
|
97
98
|
}
|
|
98
99
|
/** One shared line for a node the reader refuses to route (Decision 11). */
|
|
99
100
|
function retiredShapeReason(paths) {
|
|
100
|
-
return `provider def node is a retired shape (${paths.join(', ')}): retired shapes are not routable — use the
|
|
101
|
+
return `provider def node is a retired shape (${paths.join(', ')}): retired shapes are not routable — use the protocols/settings shape`;
|
|
101
102
|
}
|
|
102
103
|
export async function buildDirectPool() {
|
|
103
104
|
const catalog = await catalogRepository.list();
|
|
@@ -111,11 +112,11 @@ export async function buildDirectPool() {
|
|
|
111
112
|
const instances = [];
|
|
112
113
|
const models = [];
|
|
113
114
|
const excluded = [];
|
|
114
|
-
// Decision 11: a retired-shape node is dropped by the reader (its
|
|
115
|
-
//
|
|
116
|
-
// would point the provider at a silently wrong endpoint), so the
|
|
117
|
-
// reported here rather than leaving the operator to wonder where their
|
|
118
|
-
// went.
|
|
115
|
+
// Decision 11: a retired-shape node is dropped by the reader (its wire config
|
|
116
|
+
// is unproven — the node parses, but a retired opencode-v1 `options` bag may be
|
|
117
|
+
// ignored, which would point the provider at a silently wrong endpoint), so the
|
|
118
|
+
// drop is reported here rather than leaving the operator to wonder where their
|
|
119
|
+
// provider went.
|
|
119
120
|
const retiredShapes = new Map(legacyShapedSlotEntries().map((e) => [e.id, e.paths]));
|
|
120
121
|
for (const rec of catalog) {
|
|
121
122
|
const takedown = getProviderTakedownStore().get(rec.id);
|
|
@@ -163,7 +164,7 @@ export async function buildDirectPool() {
|
|
|
163
164
|
// Bake the default credential (P3 step 1); `resolved?.key` stays the defensive
|
|
164
165
|
// fallback for a store whose chain read came back empty while resolveKey
|
|
165
166
|
// answered — head === baked key is an invariant the registry relies on.
|
|
166
|
-
const pkg =
|
|
167
|
+
const pkg = primaryProtocol(normalizeProtocols(def?.protocols));
|
|
167
168
|
// A plugin that declares only `none` owns login. A stored OCR key is not an account and is not required to route.
|
|
168
169
|
const credentialless = pkg ? pluginDeclinesCredentials(getModelServicePlugin(wireFor(pkg))) : false;
|
|
169
170
|
let apiKey = inlineKey || storeCreds[0]?.key || resolved?.key;
|
|
@@ -255,7 +256,18 @@ export async function buildDirectPool() {
|
|
|
255
256
|
excluded.push({ provider: rec.id, model: `${rec.id}/${mid}`, reason: `non-text output model (modalities.output=${outMods.join('/')}), not in the text routing pool` });
|
|
256
257
|
continue;
|
|
257
258
|
}
|
|
258
|
-
|
|
259
|
+
// Ordered dial set (ADR-0033): model override → catalog model → provider
|
|
260
|
+
// def → catalog provider. ONE level fully wins (a declared list is never
|
|
261
|
+
// patched item-by-item across levels); the boot primary is its head, and
|
|
262
|
+
// the per-attempt dialer re-picks from the same list.
|
|
263
|
+
const modelProtocols = normalizeProtocols(d?.provider?.protocols).length > 0
|
|
264
|
+
? normalizeProtocols(d?.provider?.protocols)
|
|
265
|
+
: normalizeProtocols(catModel?.protocols).length > 0
|
|
266
|
+
? normalizeProtocols(catModel?.protocols)
|
|
267
|
+
: normalizeProtocols(def?.protocols).length > 0
|
|
268
|
+
? normalizeProtocols(def?.protocols)
|
|
269
|
+
: normalizeProtocols(rec.protocols);
|
|
270
|
+
const npm = modelProtocols.length > 0 ? modelProtocols[0] : undefined;
|
|
259
271
|
const wire = wireFor(npm, baseURL || rec.api);
|
|
260
272
|
if (wire === 'unroutable') {
|
|
261
273
|
const info = unroutableInfo(npm);
|
|
@@ -320,6 +332,8 @@ export async function buildDirectPool() {
|
|
|
320
332
|
// Pinned when the client omits `reasoning_effort` (orchestrator).
|
|
321
333
|
defaultEffort,
|
|
322
334
|
wire,
|
|
335
|
+
// The full ordered dial set the boot primary above heads (ADR-0033).
|
|
336
|
+
...(modelProtocols.length > 0 ? { protocols: modelProtocols } : {}),
|
|
323
337
|
// Provenance stamp: the registry is allowed to re-project this model's
|
|
324
338
|
// home tier from the member lists at every commit. Only machine-derived
|
|
325
339
|
// models carry it — an explicit `tier` in the defs file keeps it out so
|
|
@@ -465,5 +479,15 @@ export async function refreshDirectPool(registry) {
|
|
|
465
479
|
config: inst.config,
|
|
466
480
|
credentialChain: inst.credentialChain,
|
|
467
481
|
})), boot.models);
|
|
482
|
+
// Event-drive follow-catalog rewrites off the same seam every pool rebuild
|
|
483
|
+
// already shares (console mutations, catalog auto-pull, config save). Fail-open:
|
|
484
|
+
// a sync scheduling error must never undo a successful pool rebuild.
|
|
485
|
+
try {
|
|
486
|
+
const { requestFollowCatalogSync } = await import('../cli/clients/follow-catalog-sync.js');
|
|
487
|
+
requestFollowCatalogSync({ reason: 'pool' });
|
|
488
|
+
}
|
|
489
|
+
catch (err) {
|
|
490
|
+
console.warn(`[pool] follow-catalog sync schedule failed: ${err instanceof Error ? err.message : String(err)}`);
|
|
491
|
+
}
|
|
468
492
|
return boot;
|
|
469
493
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefer-native southbound dial from a model's `protocols[]` (ADR-0033).
|
|
3
|
+
*
|
|
4
|
+
* One attempt speaks exactly one wire. Selection:
|
|
5
|
+
* 1. inbound surface id if listed in `protocols`
|
|
6
|
+
* 2. first declaration-order entry that admits the canonical request
|
|
7
|
+
* 3. otherwise `protocols[0]` (existing gate honesty)
|
|
8
|
+
*/
|
|
9
|
+
import type { CanonicalRequest } from '../ir/types.js';
|
|
10
|
+
import type { WireKind } from './wire.js';
|
|
11
|
+
/**
|
|
12
|
+
* Pick the outbound wire for this attempt.
|
|
13
|
+
* @param protocols ordered dial set (already resolved for the model)
|
|
14
|
+
* @param inboundWire client surface protocol id, when known
|
|
15
|
+
* @param request canonical IR for capability escalate
|
|
16
|
+
*/
|
|
17
|
+
export declare function pickDialWire(protocols: readonly string[] | undefined, inboundWire: string | undefined, request: CanonicalRequest): WireKind;
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Prefer-native southbound dial from a model's `protocols[]` (ADR-0033).
|
|
3
|
+
*
|
|
4
|
+
* One attempt speaks exactly one wire. Selection:
|
|
5
|
+
* 1. inbound surface id if listed in `protocols`
|
|
6
|
+
* 2. first declaration-order entry that admits the canonical request
|
|
7
|
+
* 3. otherwise `protocols[0]` (existing gate honesty)
|
|
8
|
+
*/
|
|
9
|
+
import { assertCanonicalRequestSupported } from '../ir/validate.js';
|
|
10
|
+
import { primaryProtocol } from './protocols-field.js';
|
|
11
|
+
const CORE_SURFACE_WIRES = new Set([
|
|
12
|
+
'openai-chat',
|
|
13
|
+
'openai-responses',
|
|
14
|
+
'anthropic-messages',
|
|
15
|
+
]);
|
|
16
|
+
function admits(ir, protocol) {
|
|
17
|
+
if (!CORE_SURFACE_WIRES.has(protocol) && protocol !== 'google-gemini') {
|
|
18
|
+
// Plugin / decision wires: capability matrix may not list them; keep them
|
|
19
|
+
// eligible only via inbound match or as declaration fallback.
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
try {
|
|
23
|
+
assertCanonicalRequestSupported(ir, protocol);
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
catch {
|
|
27
|
+
return false;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Pick the outbound wire for this attempt.
|
|
32
|
+
* @param protocols ordered dial set (already resolved for the model)
|
|
33
|
+
* @param inboundWire client surface protocol id, when known
|
|
34
|
+
* @param request canonical IR for capability escalate
|
|
35
|
+
*/
|
|
36
|
+
export function pickDialWire(protocols, inboundWire, request) {
|
|
37
|
+
const list = protocols && protocols.length > 0 ? [...protocols] : [primaryProtocol(undefined)];
|
|
38
|
+
const inbound = inboundWire?.trim();
|
|
39
|
+
if (inbound && list.includes(inbound)) {
|
|
40
|
+
return inbound;
|
|
41
|
+
}
|
|
42
|
+
for (const id of list) {
|
|
43
|
+
if (inbound && id === inbound)
|
|
44
|
+
continue;
|
|
45
|
+
if (admits(request, id))
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
return list[0];
|
|
49
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCR-owned `protocols: string[]` helpers (ADR-0010 clean schema).
|
|
3
|
+
*
|
|
4
|
+
* Steady-state truth never stores `npm` / `package` / `protocol` as the dial
|
|
5
|
+
* slot. Migrators may call `protocolsFromLegacyNode` once while rewriting a
|
|
6
|
+
* file; after the hop, readers use `normalizeProtocols` / `primaryProtocol`
|
|
7
|
+
* only.
|
|
8
|
+
*/
|
|
9
|
+
declare const DEFAULT_PROTOCOL = "openai-chat";
|
|
10
|
+
/** Coerce any value into a deduped, ordered list of OCR protocol ids. */
|
|
11
|
+
export declare function normalizeProtocols(raw: unknown): string[];
|
|
12
|
+
/** First declared protocol, or the chat default when the list is empty. */
|
|
13
|
+
export declare function primaryProtocol(protocols: readonly string[] | undefined): string;
|
|
14
|
+
/**
|
|
15
|
+
* Migrator-only: lift retired singular slots on one object into `protocols`.
|
|
16
|
+
* Does not mutate `node`. Returns undefined when nothing protocol-shaped was found.
|
|
17
|
+
*/
|
|
18
|
+
export declare function protocolsFromLegacyNode(node: Record<string, unknown> | null | undefined): string[] | undefined;
|
|
19
|
+
/**
|
|
20
|
+
* Strip retired protocol-slot keys from a shallow copy of `node`.
|
|
21
|
+
* Used by migrators after writing `protocols`.
|
|
22
|
+
*/
|
|
23
|
+
export declare function stripLegacyProtocolKeys<T extends Record<string, unknown>>(node: T): T;
|
|
24
|
+
export { DEFAULT_PROTOCOL };
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* OCR-owned `protocols: string[]` helpers (ADR-0010 clean schema).
|
|
3
|
+
*
|
|
4
|
+
* Steady-state truth never stores `npm` / `package` / `protocol` as the dial
|
|
5
|
+
* slot. Migrators may call `protocolsFromLegacyNode` once while rewriting a
|
|
6
|
+
* file; after the hop, readers use `normalizeProtocols` / `primaryProtocol`
|
|
7
|
+
* only.
|
|
8
|
+
*/
|
|
9
|
+
import { currentProtocol } from './protocol.js';
|
|
10
|
+
const DEFAULT_PROTOCOL = 'openai-chat';
|
|
11
|
+
/** Coerce any value into a deduped, ordered list of OCR protocol ids. */
|
|
12
|
+
export function normalizeProtocols(raw) {
|
|
13
|
+
if (Array.isArray(raw)) {
|
|
14
|
+
const out = [];
|
|
15
|
+
const seen = new Set();
|
|
16
|
+
for (const item of raw) {
|
|
17
|
+
if (typeof item !== 'string' || !item.trim())
|
|
18
|
+
continue;
|
|
19
|
+
const id = currentProtocol(item.trim());
|
|
20
|
+
if (seen.has(id))
|
|
21
|
+
continue;
|
|
22
|
+
seen.add(id);
|
|
23
|
+
out.push(id);
|
|
24
|
+
}
|
|
25
|
+
return out;
|
|
26
|
+
}
|
|
27
|
+
if (typeof raw === 'string' && raw.trim()) {
|
|
28
|
+
return [currentProtocol(raw.trim())];
|
|
29
|
+
}
|
|
30
|
+
return [];
|
|
31
|
+
}
|
|
32
|
+
/** First declared protocol, or the chat default when the list is empty. */
|
|
33
|
+
export function primaryProtocol(protocols) {
|
|
34
|
+
return protocols && protocols.length > 0 ? protocols[0] : DEFAULT_PROTOCOL;
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Migrator-only: lift retired singular slots on one object into `protocols`.
|
|
38
|
+
* Does not mutate `node`. Returns undefined when nothing protocol-shaped was found.
|
|
39
|
+
*/
|
|
40
|
+
export function protocolsFromLegacyNode(node) {
|
|
41
|
+
if (!node || typeof node !== 'object')
|
|
42
|
+
return undefined;
|
|
43
|
+
if (Array.isArray(node.protocols) || typeof node.protocols === 'string') {
|
|
44
|
+
const list = normalizeProtocols(node.protocols);
|
|
45
|
+
return list.length > 0 ? list : undefined;
|
|
46
|
+
}
|
|
47
|
+
for (const key of ['package', 'npm', 'protocol']) {
|
|
48
|
+
const v = node[key];
|
|
49
|
+
if (typeof v === 'string' && v.trim()) {
|
|
50
|
+
return normalizeProtocols(v);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
return undefined;
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Strip retired protocol-slot keys from a shallow copy of `node`.
|
|
57
|
+
* Used by migrators after writing `protocols`.
|
|
58
|
+
*/
|
|
59
|
+
export function stripLegacyProtocolKeys(node) {
|
|
60
|
+
const next = { ...node };
|
|
61
|
+
delete next.npm;
|
|
62
|
+
delete next.package;
|
|
63
|
+
delete next.protocol;
|
|
64
|
+
return next;
|
|
65
|
+
}
|
|
66
|
+
export { DEFAULT_PROTOCOL };
|
|
@@ -403,6 +403,8 @@ export declare class ProviderRegistry {
|
|
|
403
403
|
*/
|
|
404
404
|
execute(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credentialKeyHashPrefix?: string, relay?: StreamRelay,
|
|
405
405
|
/** Resolved OCR conversation id. Not a capture field. */
|
|
406
|
-
sessionId?: string
|
|
406
|
+
sessionId?: string,
|
|
407
|
+
/** Inbound client surface protocol — prefer-native dial (ADR-0033). */
|
|
408
|
+
inboundWire?: string): Promise<CanonicalResponse>;
|
|
407
409
|
private mockExecute;
|
|
408
410
|
}
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
+
import { pickDialWire } from './dial-wire.js';
|
|
1
2
|
import { OpenAIChatProvider } from './executors/openai-chat.js';
|
|
2
3
|
import { AnthropicMessagesProvider } from './executors/anthropic-messages.js';
|
|
3
4
|
import { OpenAIResponsesProvider } from './executors/openai-responses.js';
|
|
4
5
|
import { GoogleGeminiProvider } from './executors/google-gemini.js';
|
|
5
6
|
import { getModelServicePlugin } from '../plugins/host.js';
|
|
6
7
|
import { EFFORT_LADDER, downgradeReasoning, modelSupportsEfforts } from '../types/router.js';
|
|
8
|
+
import { IrUnsupportedError } from '../ir/errors.js';
|
|
9
|
+
import { withDialContext } from '../ir/validate.js';
|
|
7
10
|
import { createEventAccumulator } from '../ir/stream.js';
|
|
8
11
|
import { createToolMarkupScanner, detectToolMarkupLeak } from './compat/tool-markup-leak.js';
|
|
9
12
|
import { createToolMarkupStreamRecovery, recoverToolMarkupInResponse, toolMarkupRecoveryFor } from './compat/tool-markup-recovery.js';
|
|
@@ -1118,7 +1121,9 @@ export class ProviderRegistry {
|
|
|
1118
1121
|
*/
|
|
1119
1122
|
async execute(request, model, upstreamEventContext, credentialKeyHashPrefix, relay,
|
|
1120
1123
|
/** Resolved OCR conversation id. Not a capture field. */
|
|
1121
|
-
sessionId
|
|
1124
|
+
sessionId,
|
|
1125
|
+
/** Inbound client surface protocol — prefer-native dial (ADR-0033). */
|
|
1126
|
+
inboundWire) {
|
|
1122
1127
|
if (this.mockMode) {
|
|
1123
1128
|
relay?.onTransport?.('buffered');
|
|
1124
1129
|
return this.mockExecute(request, model);
|
|
@@ -1126,6 +1131,8 @@ export class ProviderRegistry {
|
|
|
1126
1131
|
const provider = this.providers.get(model.provider);
|
|
1127
1132
|
if (!provider)
|
|
1128
1133
|
throw new Error(`Provider '${model.provider}' not found for model '${model.id}'`);
|
|
1134
|
+
const dialWire = pickDialWire(model.protocols ?? (model.wire ? [model.wire] : undefined), inboundWire, request);
|
|
1135
|
+
const dialModel = dialWire === model.wire ? model : { ...model, wire: dialWire };
|
|
1129
1136
|
const chain = this.credentialChains.get(model.provider);
|
|
1130
1137
|
let credential;
|
|
1131
1138
|
if (credentialKeyHashPrefix !== undefined) {
|
|
@@ -1135,17 +1142,17 @@ export class ProviderRegistry {
|
|
|
1135
1142
|
}
|
|
1136
1143
|
}
|
|
1137
1144
|
try {
|
|
1138
|
-
const recovery = toolMarkupRecoveryFor(request,
|
|
1145
|
+
const recovery = toolMarkupRecoveryFor(request, dialModel, this.providerConfigs.get(model.provider));
|
|
1139
1146
|
if (relay) {
|
|
1140
1147
|
const streams = provider.supportsStreaming
|
|
1141
|
-
? provider.supportsStreaming(
|
|
1148
|
+
? provider.supportsStreaming(dialModel)
|
|
1142
1149
|
: typeof provider.createStream === 'function';
|
|
1143
1150
|
if (streams) {
|
|
1144
1151
|
const accumulate = createEventAccumulator();
|
|
1145
1152
|
const scanner = recovery ? null : createToolMarkupScanner();
|
|
1146
1153
|
const rewrite = recovery ? createToolMarkupStreamRecovery(request) : null;
|
|
1147
1154
|
relay.onTransport?.('sse');
|
|
1148
|
-
const stream = await provider.createStream(request,
|
|
1155
|
+
const stream = await provider.createStream(request, dialModel, upstreamEventContext, credential, sessionId);
|
|
1149
1156
|
// Drain for terminal usage even if the client disconnected. Relay and
|
|
1150
1157
|
// accounting consume the same event objects without history copies.
|
|
1151
1158
|
for await (const event of stream) {
|
|
@@ -1163,17 +1170,17 @@ export class ProviderRegistry {
|
|
|
1163
1170
|
}
|
|
1164
1171
|
const accumulated = accumulate.finish();
|
|
1165
1172
|
const finished = rewrite ? rewrite.finishResponse(accumulated) : accumulated;
|
|
1166
|
-
reportToolMarkupLeak(rewrite ? finished.toolMarkupLeak ?? null : scanner.leak(),
|
|
1173
|
+
reportToolMarkupLeak(rewrite ? finished.toolMarkupLeak ?? null : scanner.leak(), dialModel);
|
|
1167
1174
|
return finished;
|
|
1168
1175
|
}
|
|
1169
1176
|
relay.onTransport?.('buffered');
|
|
1170
1177
|
}
|
|
1171
|
-
const buffered = await provider.createCompletion(request,
|
|
1178
|
+
const buffered = await provider.createCompletion(request, dialModel, upstreamEventContext, credential, sessionId);
|
|
1172
1179
|
const finished = recovery ? recoverToolMarkupInResponse(buffered, request) : buffered;
|
|
1173
1180
|
const leak = recovery ? finished.toolMarkupLeak ?? null : detectToolMarkupLeak(finished);
|
|
1174
1181
|
if (!leak)
|
|
1175
1182
|
return finished;
|
|
1176
|
-
reportToolMarkupLeak(leak,
|
|
1183
|
+
reportToolMarkupLeak(leak, dialModel);
|
|
1177
1184
|
return { ...finished, toolMarkupLeak: leak };
|
|
1178
1185
|
}
|
|
1179
1186
|
catch (err) {
|
|
@@ -1181,6 +1188,15 @@ export class ProviderRegistry {
|
|
|
1181
1188
|
if (used && err && (typeof err === 'object' || typeof err === 'function')) {
|
|
1182
1189
|
err.usedCredentialKeyHashPrefix = used.keyHashPrefix;
|
|
1183
1190
|
}
|
|
1191
|
+
// Layer model + declared protocols onto IR refusals so the client sees
|
|
1192
|
+
// which dial was incompatible — not only the bare protocol id.
|
|
1193
|
+
if (err instanceof IrUnsupportedError) {
|
|
1194
|
+
throw withDialContext(err, {
|
|
1195
|
+
modelId: dialModel.id,
|
|
1196
|
+
dialWire: dialWire,
|
|
1197
|
+
protocols: dialModel.protocols ?? (dialModel.wire ? [dialModel.wire] : undefined),
|
|
1198
|
+
});
|
|
1199
|
+
}
|
|
1184
1200
|
throw err;
|
|
1185
1201
|
}
|
|
1186
1202
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { getModelServicePlugin, pluginDeclinesCredentials } from '../plugins/host.js';
|
|
2
2
|
import { wireFor } from '../providers/wire.js';
|
|
3
|
+
import { primaryProtocol, normalizeProtocols } from '../providers/protocols-field.js';
|
|
3
4
|
import { getProviderNodeById } from '../opencode/user-config.js';
|
|
4
5
|
/**
|
|
5
6
|
* One quota pair for a provider whose plugin owns login (`authTypes: ['none']`).
|
|
@@ -10,7 +11,8 @@ export const CLI_LOGIN_QUOTA_PREFIX = 'cli-login';
|
|
|
10
11
|
/** True when the provider's model-service plugin refuses an OCR credential. */
|
|
11
12
|
export function providerUsesCliLogin(providerId) {
|
|
12
13
|
const def = getProviderNodeById(providerId);
|
|
13
|
-
const
|
|
14
|
+
const protocols = normalizeProtocols(def?.protocols ?? def?.package ?? def?.npm);
|
|
15
|
+
const npm = protocols.length > 0 ? primaryProtocol(protocols) : undefined;
|
|
14
16
|
const options = def?.options;
|
|
15
17
|
const settings = def?.settings;
|
|
16
18
|
const base = typeof options?.baseURL === 'string' ? options.baseURL : typeof settings?.baseURL === 'string' ? settings.baseURL : undefined;
|