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
|
@@ -48,7 +48,8 @@ import { maskSecret, isValidProviderId, PROVIDER_ID_RULE, getProviderNodeById }
|
|
|
48
48
|
import { listOpenCodeAgentsLive } from '../opencode/agents.js';
|
|
49
49
|
import { listApiKeys, createApiKey, updateApiKey, deleteApiKey, validateApiKey, validateModelAccess, } from '../auth/api-keys.js';
|
|
50
50
|
import { toCallCredential } from '../providers/boot-direct.js';
|
|
51
|
-
import {
|
|
51
|
+
import { buildKeyModelsView } from '../auth/key-models.js';
|
|
52
|
+
import { clearClientProfileMemory, getFollowCatalogIssue, getFollowCatalogSyncState, isFollowCatalogPending, retryFollowCatalogPending, stampClientProfileMemory, } from '../cli/clients/follow-catalog-sync.js';
|
|
52
53
|
import { validateRateLimitRules, getRateLimiter, credentialSubject } from '../ratelimit/rate-limiter.js';
|
|
53
54
|
import { getQuotaProber } from '../quota/prober.js';
|
|
54
55
|
import { getQuotaStore } from '../quota/store.js';
|
|
@@ -1033,9 +1034,39 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1033
1034
|
const activity = clientActivitySnapshot();
|
|
1034
1035
|
return {
|
|
1035
1036
|
status: 'ok',
|
|
1036
|
-
clients: (await getAllClientStatuses({ refresh })).map((c) =>
|
|
1037
|
+
clients: (await getAllClientStatuses({ refresh })).map((c) => {
|
|
1038
|
+
const issue = getFollowCatalogIssue(c.name) ||
|
|
1039
|
+
(c.catalogPlugin ? getFollowCatalogIssue(c.catalogPlugin) : undefined);
|
|
1040
|
+
return {
|
|
1041
|
+
...c,
|
|
1042
|
+
...(activity[c.name] ?? {}),
|
|
1043
|
+
...(issue?.status === 'pending' || isFollowCatalogPending(c.name) ||
|
|
1044
|
+
(c.catalogPlugin && isFollowCatalogPending(c.catalogPlugin))
|
|
1045
|
+
? { followCatalogPending: true }
|
|
1046
|
+
: {}),
|
|
1047
|
+
...(issue
|
|
1048
|
+
? {
|
|
1049
|
+
followCatalogIssue: {
|
|
1050
|
+
status: issue.status,
|
|
1051
|
+
reason: issue.reason,
|
|
1052
|
+
},
|
|
1053
|
+
}
|
|
1054
|
+
: {}),
|
|
1055
|
+
};
|
|
1056
|
+
}),
|
|
1037
1057
|
};
|
|
1038
1058
|
});
|
|
1059
|
+
app.get('/api/admin/clients/follow-catalog-sync', async () => ({
|
|
1060
|
+
status: 'ok',
|
|
1061
|
+
...getFollowCatalogSyncState(),
|
|
1062
|
+
}));
|
|
1063
|
+
app.post('/api/admin/clients/follow-catalog-sync/retry', async (req) => {
|
|
1064
|
+
const body = (req.body || {});
|
|
1065
|
+
const run = await retryFollowCatalogPending({
|
|
1066
|
+
acknowledgeRunning: body.acknowledgeRunning === true,
|
|
1067
|
+
});
|
|
1068
|
+
return { status: 'ok', ...run };
|
|
1069
|
+
});
|
|
1039
1070
|
// 3A1'. Release update check — display-only and cached in-process. The
|
|
1040
1071
|
// first console read starts the GitHub call in the background and answers
|
|
1041
1072
|
// `checking: true`; the console polls until the snapshot settles. A stale
|
|
@@ -1858,7 +1889,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1858
1889
|
// 4. Client Interception Setup / Teardown
|
|
1859
1890
|
const handleSetup = async (req, reply) => {
|
|
1860
1891
|
const { client } = req.params;
|
|
1861
|
-
const { models, apiKey, contextWindow, extraModels, virtualModels, agentModels, product, acknowledgeRunning } = (req.body || {});
|
|
1892
|
+
const { models, apiKey, contextWindow, extraModels, virtualModels, agentModels, product, acknowledgeRunning, modelMode, apiKeyId } = (req.body || {});
|
|
1862
1893
|
const cleaned = models && typeof models === 'object'
|
|
1863
1894
|
? Object.fromEntries(Object.entries(models).map(([k, v]) => [k, String(v ?? 'auto').trim() || 'auto']))
|
|
1864
1895
|
: undefined;
|
|
@@ -1921,6 +1952,21 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1921
1952
|
});
|
|
1922
1953
|
if (!result.success)
|
|
1923
1954
|
return reply.status(400).send(result);
|
|
1955
|
+
// Authoritative follow-resync index: stamp after a successful setup so a
|
|
1956
|
+
// failed frontend rememberDraft cannot orphan a hooked follow client.
|
|
1957
|
+
const mode = modelMode === 'follow' || modelMode === 'custom' || modelMode === 'default' ? modelMode : undefined;
|
|
1958
|
+
const keyId = typeof apiKeyId === 'string' && apiKeyId.trim() ? apiKeyId.trim() : undefined;
|
|
1959
|
+
if (mode || keyId || cleaned || agentModelsPayload || (Number.isFinite(cw) && cw > 0)) {
|
|
1960
|
+
stampClientProfileMemory(client, {
|
|
1961
|
+
...(mode ? { modelMode: mode } : {}),
|
|
1962
|
+
...(keyId ? { apiKeyId: keyId } : {}),
|
|
1963
|
+
...(cleaned ? { models: cleaned } : {}),
|
|
1964
|
+
...(agentModelsPayload ? { agentModels: agentModelsPayload } : {}),
|
|
1965
|
+
...(cleanedExtra ? { extraModels: cleanedExtra } : {}),
|
|
1966
|
+
...(cleanedVirtual !== undefined ? { virtualModels: cleanedVirtual } : {}),
|
|
1967
|
+
...(Number.isFinite(cw) && cw > 0 ? { contextWindow: Math.floor(cw) } : {}),
|
|
1968
|
+
});
|
|
1969
|
+
}
|
|
1924
1970
|
return result;
|
|
1925
1971
|
};
|
|
1926
1972
|
const handleTeardown = async (req, reply) => {
|
|
@@ -1932,6 +1978,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1932
1978
|
});
|
|
1933
1979
|
if (!result.success)
|
|
1934
1980
|
return reply.status(400).send(result);
|
|
1981
|
+
clearClientProfileMemory(client);
|
|
1935
1982
|
return result;
|
|
1936
1983
|
};
|
|
1937
1984
|
app.post('/api/admin/client/:client/setup', handleSetup);
|
|
@@ -3101,7 +3148,9 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3101
3148
|
// at all) is by definition custom.
|
|
3102
3149
|
custom: u ? u.custom : true,
|
|
3103
3150
|
logo: u?.logo ?? v.logo,
|
|
3104
|
-
|
|
3151
|
+
// The dial set: the def view's own protocols win, the catalog row
|
|
3152
|
+
// only fills a def that declared nothing (ADR-0033 precedence).
|
|
3153
|
+
protocols: v.protocols?.length ? v.protocols : u?.protocols,
|
|
3105
3154
|
// Operator takedown: routing state, never a defs-file field (ADR-0010).
|
|
3106
3155
|
// The card stays listed so the operator can restore it with one click.
|
|
3107
3156
|
disabled: takedown !== undefined,
|
|
@@ -3135,7 +3184,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3135
3184
|
id: p.id,
|
|
3136
3185
|
name: p.name,
|
|
3137
3186
|
logo: p.logo,
|
|
3138
|
-
|
|
3187
|
+
protocols: p.protocols,
|
|
3139
3188
|
api: p.api,
|
|
3140
3189
|
baseURL: p.baseURL,
|
|
3141
3190
|
doc: p.doc,
|
|
@@ -3192,7 +3241,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3192
3241
|
// preset's own baseURL/npm.
|
|
3193
3242
|
providers.splice(idx, 1);
|
|
3194
3243
|
}
|
|
3195
|
-
providers.push({ id: preset.id, name: preset.name, logo: preset.logo,
|
|
3244
|
+
providers.push({ id: preset.id, name: preset.name, logo: preset.logo, protocols: preset.protocols, api: undefined, baseURL: preset.baseURL, doc: undefined, env: undefined, custom: preset.custom, connected: preset.connected, webLogin: preset.webLogin, webLoginSubmit: preset.webLoginSubmit, authTypes: preset.authTypes, keyHint: preset.keyHint, pluginOrigin: origins[preset.id], sources: preset.sources, modelCount: 0, priceFrom: undefined });
|
|
3196
3245
|
}
|
|
3197
3246
|
}
|
|
3198
3247
|
catch {
|
|
@@ -3323,7 +3372,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3323
3372
|
const result = upsertProviderDef({
|
|
3324
3373
|
id,
|
|
3325
3374
|
name: body.name,
|
|
3326
|
-
|
|
3375
|
+
protocols: body.protocols,
|
|
3327
3376
|
baseURL: body.baseURL,
|
|
3328
3377
|
apiKey: keyToStore ? undefined : body.apiKey,
|
|
3329
3378
|
apiKeyInline: Boolean(body.apiKeyInline),
|
|
@@ -3446,7 +3495,9 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3446
3495
|
const result = upsertProviderDef({
|
|
3447
3496
|
id,
|
|
3448
3497
|
name: body.name ?? existing.name,
|
|
3449
|
-
|
|
3498
|
+
// An explicit [] (the editor cleared every protocol) is a real edit:
|
|
3499
|
+
// upsertProviderDef falls back to the default set only for undefined.
|
|
3500
|
+
protocols: body.protocols ?? existing.protocols,
|
|
3450
3501
|
baseURL: body.baseURL ?? existing.options?.baseURL,
|
|
3451
3502
|
apiKey: keyToStore ? undefined : body.apiKey,
|
|
3452
3503
|
apiKeyInline: inline,
|
|
@@ -3503,7 +3554,9 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3503
3554
|
id,
|
|
3504
3555
|
baseURL: body.baseURL,
|
|
3505
3556
|
name: existing?.name,
|
|
3506
|
-
|
|
3557
|
+
// A baseURL connect must not reset the dial set — upsert falls back
|
|
3558
|
+
// to the default protocol only when NOTHING was carried over.
|
|
3559
|
+
protocols: existing?.protocols,
|
|
3507
3560
|
headers: existing?.options?.headers,
|
|
3508
3561
|
models: existing?.models,
|
|
3509
3562
|
options: existing?.options,
|
|
@@ -3583,10 +3636,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3583
3636
|
}
|
|
3584
3637
|
if (!def)
|
|
3585
3638
|
return { error: `provider '${id}' not found` };
|
|
3639
|
+
const { primaryProtocol } = await import('../providers/protocols-field.js');
|
|
3586
3640
|
const node = def;
|
|
3587
3641
|
const baseURL = (node.options?.baseURL ?? node.baseURL ?? '').replace(/\/+$/, '');
|
|
3588
|
-
|
|
3589
|
-
|
|
3642
|
+
// Boot doctrine: the protocol vocabulary decides first; a bare-URL def
|
|
3643
|
+
// without any declared protocol still fingerprints its wire from baseURL.
|
|
3644
|
+
const wire = node.protocols?.length ? wireFor(primaryProtocol(node.protocols))
|
|
3645
|
+
: baseURL ? wireFor(undefined, baseURL) : 'unroutable';
|
|
3590
3646
|
const plugin = (await import('../plugins/host.js')).getModelServicePlugin(wire);
|
|
3591
3647
|
if (!plugin?.webLogin) {
|
|
3592
3648
|
return { error: `provider '${id}' is not on a plugin wire with a web-login capability` };
|
|
@@ -3850,6 +3906,42 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3850
3906
|
});
|
|
3851
3907
|
}
|
|
3852
3908
|
const { probeProvider, probeKindFor } = await import('../opencode/probe.js');
|
|
3909
|
+
const { wireFor } = await import('../providers/wire.js');
|
|
3910
|
+
const { normalizeProtocols, primaryProtocol } = await import('../providers/protocols-field.js');
|
|
3911
|
+
// A protocol pin is a PRECONDITION, not a dial hint: refuse before any
|
|
3912
|
+
// upstream byte leaves. One attempt speaks exactly one wire, so the pin
|
|
3913
|
+
// replaces the whole dial ladder rather than sitting on top of it.
|
|
3914
|
+
let pinnedWire;
|
|
3915
|
+
if (body.protocol !== undefined && body.protocol !== null && String(body.protocol).trim()) {
|
|
3916
|
+
const pin = normalizeProtocols(String(body.protocol))[0];
|
|
3917
|
+
const offered = new Set(protocolVocabulary().map((e) => e.alias));
|
|
3918
|
+
const wire = pin ? wireFor(pin) : 'unroutable';
|
|
3919
|
+
if (!pin || !offered.has(pin) || wire === 'unroutable') {
|
|
3920
|
+
return reply.status(400).send({
|
|
3921
|
+
success: false,
|
|
3922
|
+
reasonCode: 'protocol_invalid',
|
|
3923
|
+
provider: id,
|
|
3924
|
+
protocol: String(body.protocol),
|
|
3925
|
+
error: `'${body.protocol}' is not an offered OCR protocol id.`,
|
|
3926
|
+
});
|
|
3927
|
+
}
|
|
3928
|
+
// ONE level fully wins (never patched across levels) — the same
|
|
3929
|
+
// precedence boot-direct uses, so a pin cannot pass a check the dial
|
|
3930
|
+
// itself would resolve differently (no test-vs-inference divergence).
|
|
3931
|
+
const defLevel = normalizeProtocols(def?.protocols);
|
|
3932
|
+
const declared = defLevel.length > 0 ? defLevel : normalizeProtocols(cat?.protocols);
|
|
3933
|
+
if (!declared.includes(pin)) {
|
|
3934
|
+
return reply.status(400).send({
|
|
3935
|
+
success: false,
|
|
3936
|
+
reasonCode: 'protocol_not_declared',
|
|
3937
|
+
provider: id,
|
|
3938
|
+
protocol: pin,
|
|
3939
|
+
declared,
|
|
3940
|
+
error: `'${pin}' is not declared by '${id}' (${declared.join(', ') || 'no protocols'}).`,
|
|
3941
|
+
});
|
|
3942
|
+
}
|
|
3943
|
+
pinnedWire = wire;
|
|
3944
|
+
}
|
|
3853
3945
|
// The verdict's egress (ADR-0018 / ADR-0022 vocabulary) is taken from the
|
|
3854
3946
|
// attempt that produced it and rides on the reply, so "Test" answers "did
|
|
3855
3947
|
// my model-scoped split apply" — the include/exclude page can only state
|
|
@@ -3883,10 +3975,14 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3883
3975
|
for (const modelId of modelCandidates) {
|
|
3884
3976
|
if (!tried.includes(modelId))
|
|
3885
3977
|
tried.push(modelId);
|
|
3886
|
-
//
|
|
3887
|
-
//
|
|
3888
|
-
|
|
3889
|
-
const
|
|
3978
|
+
// Wire shape for this attempt: the console pin wins outright;
|
|
3979
|
+
// otherwise the model's own declared protocols beat the provider
|
|
3980
|
+
// list (prefer-native dial, ADR-0033).
|
|
3981
|
+
const modelProtocols = normalizeProtocols(cat?.models.find((mm) => mm.id === modelId)?.protocols);
|
|
3982
|
+
const dialProtocols = modelProtocols.length > 0
|
|
3983
|
+
? modelProtocols
|
|
3984
|
+
: normalizeProtocols(def?.protocols ?? cat?.protocols);
|
|
3985
|
+
const kind = pinnedWire ?? probeKindFor(cat?.api, primaryProtocol(dialProtocols));
|
|
3890
3986
|
// The model's own capability flags, read from the def the console
|
|
3891
3987
|
// holds — a plugin probe builds a REAL request, so guessing
|
|
3892
3988
|
// "not a reasoning model" makes it send thinking-off to a model that
|
|
@@ -5223,87 +5319,11 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
5223
5319
|
// addressable-id namespace a row belongs to.
|
|
5224
5320
|
const handleGetKeyModels = async (req, reply) => {
|
|
5225
5321
|
const { id } = req.params;
|
|
5226
|
-
const
|
|
5227
|
-
if (
|
|
5228
|
-
return reply.status(404).send(
|
|
5229
|
-
}
|
|
5230
|
-
const policy = getModelAccessPolicy(key);
|
|
5231
|
-
const registered = registry.getAllModels().map((m) => ({
|
|
5232
|
-
id: m.id,
|
|
5233
|
-
kind: 'model',
|
|
5234
|
-
provider: m.provider,
|
|
5235
|
-
// FULL membership set (pools are a per-tier projection — a model may
|
|
5236
|
-
// belong to several tiers): tierAllowed counts every pool the model can
|
|
5237
|
-
// route toward, so auto-X viability never misses a multi-pool member.
|
|
5238
|
-
tiers: registry.tiersOf(m),
|
|
5239
|
-
virtual: false,
|
|
5240
|
-
allowed: isModelAllowedInTiers(m.id, policy, registry.tiersOf(m)),
|
|
5241
|
-
}));
|
|
5242
|
-
const tierAllowed = (t) => registered.some((m) => m.tiers?.includes(t) && m.allowed);
|
|
5243
|
-
// Virtual auto* rows honor runtime viability (mirrors /v1/models): bare
|
|
5244
|
-
// `auto` needs an allowed model in ANY tier, auto-X in tier X.
|
|
5245
|
-
const virtual = ['auto', 'lite', 'plus', 'pro', 'ultra'].map((id) => ({
|
|
5246
|
-
id,
|
|
5247
|
-
kind: (id === 'auto' ? 'auto' : 'tier'),
|
|
5248
|
-
provider: 'omnicell-router',
|
|
5249
|
-
tier: tierFromVirtualEntry(id),
|
|
5250
|
-
virtual: true,
|
|
5251
|
-
allowed: isAutoEntryUsable(id, policy, tierAllowed),
|
|
5252
|
-
}));
|
|
5253
|
-
// Combo rows (mirrors /v1/models): routable virtual ids, but concrete
|
|
5254
|
-
// selectable entries — NOT auto*-virtual, so follow-mode snapshots keep
|
|
5255
|
-
// them. A combo passes only when EVERY member is allowed (the inference
|
|
5256
|
-
// entry gate; no silent composition change).
|
|
5257
|
-
const combos = registry.getCombos().map((c) => ({
|
|
5258
|
-
id: c.id,
|
|
5259
|
-
kind: 'combo',
|
|
5260
|
-
provider: 'omnicell-router',
|
|
5261
|
-
tier: '',
|
|
5262
|
-
virtual: false,
|
|
5263
|
-
allowed: registry.resolveCombo(c.id).every((mem) => isModelAllowed(mem.id, policy, mem.tier)),
|
|
5264
|
-
}));
|
|
5265
|
-
// Variant rows (mirrors /v1/models): `base-variant` ids resolve to the
|
|
5266
|
-
// base model with a pinned reasoning effort; the policy verdict inherits
|
|
5267
|
-
// from the base id.
|
|
5268
|
-
const variants = registry.getVariantExposures().map(({ id, base }) => ({
|
|
5269
|
-
id,
|
|
5270
|
-
kind: 'variant',
|
|
5271
|
-
provider: base.provider,
|
|
5272
|
-
tiers: registry.tiersOf(base),
|
|
5273
|
-
virtual: false,
|
|
5274
|
-
allowed: isModelAllowedInTiers(base.id, policy, registry.tiersOf(base)),
|
|
5275
|
-
}));
|
|
5276
|
-
// Order mirrors the /v1/models wire body EXACTLY (the console list is a
|
|
5277
|
-
// pure re-rendering of that payload — same rows, same sequence). The wire
|
|
5278
|
-
// builds a provider map whose insertion order IS the display order: the
|
|
5279
|
-
// omnicell-router virtual provider (auto alias → tier aliases → combos)
|
|
5280
|
-
// first, then concrete providers in registry first-appearance order, each
|
|
5281
|
-
// carrying its concrete models then its variant siblings.
|
|
5282
|
-
const providerRows = new Map();
|
|
5283
|
-
const ensureProviderRows = (pid) => {
|
|
5284
|
-
let rows = providerRows.get(pid);
|
|
5285
|
-
if (!rows) {
|
|
5286
|
-
rows = [];
|
|
5287
|
-
providerRows.set(pid, rows);
|
|
5288
|
-
}
|
|
5289
|
-
return rows;
|
|
5290
|
-
};
|
|
5291
|
-
for (const m of registry.getAllModels()) {
|
|
5292
|
-
ensureProviderRows(m.provider).push(registered.find((r) => r.id === m.id));
|
|
5322
|
+
const view = buildKeyModelsView(id, registry);
|
|
5323
|
+
if (view.status === 'error') {
|
|
5324
|
+
return reply.status(404).send(view);
|
|
5293
5325
|
}
|
|
5294
|
-
|
|
5295
|
-
ensureProviderRows(v.provider).push(v);
|
|
5296
|
-
const models = [
|
|
5297
|
-
...virtual,
|
|
5298
|
-
...combos,
|
|
5299
|
-
...[...providerRows.entries()].filter(([pid]) => pid !== 'omnicell-router').flatMap(([, rows]) => rows),
|
|
5300
|
-
];
|
|
5301
|
-
return {
|
|
5302
|
-
status: 'ok',
|
|
5303
|
-
mode: policy?.mode ?? 'none',
|
|
5304
|
-
policyModels: policy?.models ?? [],
|
|
5305
|
-
models,
|
|
5306
|
-
};
|
|
5326
|
+
return view;
|
|
5307
5327
|
};
|
|
5308
5328
|
app.get('/api/admin/api-keys/:id/models', handleGetKeyModels);
|
|
5309
5329
|
// 9c. Full gateway catalog for CONSOLE-internal consumers (model pickers).
|
package/backend/dist/server.js
CHANGED
|
@@ -12,7 +12,9 @@ import { registerTranslationRoutes } from './routes/translation.js';
|
|
|
12
12
|
import { MarketplaceRescanScheduler } from './harness/common/marketplace-rescan-scheduler.js';
|
|
13
13
|
import { allHostProbes, probeOptionsFor } from './harness/plugin/adapters/index.js';
|
|
14
14
|
import { INFERENCE_ROUTE_PATHS, SURFACES } from './surfaces/table.js';
|
|
15
|
+
import { adminBodyErrorHandler, bodyLimitFor, configureBodyLimits, normalizeNativeBody, settleContinuationExpectation, surfaceBodyAdmissionOptions, } from './surfaces/body-admission.js';
|
|
15
16
|
import { createFastifyTransport } from './surfaces/transport-fastify.js';
|
|
17
|
+
import { applyInboundLiveness } from './utils/server-liveness.js';
|
|
16
18
|
import { dispatchSurface } from './surfaces/dispatch.js';
|
|
17
19
|
import { purgeResponseChainForSession } from './surfaces/responses.js';
|
|
18
20
|
import fastify, { LogController } from 'fastify';
|
|
@@ -215,6 +217,11 @@ export function createServer(config, mockMode = false, customRegistry, customOrc
|
|
|
215
217
|
/** Extra provider configs for the bootstrapped registry (test seam only —
|
|
216
218
|
* production chat providers enter via `registerProvider` post-boot). */
|
|
217
219
|
providerConfigs = []) {
|
|
220
|
+
// Install the operator-tunable admission caps (`client.bodyLimits`) BEFORE
|
|
221
|
+
// Fastify reads any `bodyLimit` — a route's cap is captured at registration
|
|
222
|
+
// time, which is exactly why the knob is restart-only (ADR-0007). With no
|
|
223
|
+
// configured value this returns the shipped constants unchanged.
|
|
224
|
+
configureBodyLimits(config.bodyLimits);
|
|
218
225
|
// disableRequestLogging: Fastify's built-in per-request lifecycle logs
|
|
219
226
|
// ("incoming request" / "request completed" at info) are pure noise here —
|
|
220
227
|
// every UI poll of /health + /api/* produced a pair, drowning ocr.log.
|
|
@@ -228,6 +235,66 @@ providerConfigs = []) {
|
|
|
228
235
|
level: process.env.LOG_LEVEL || 'info',
|
|
229
236
|
},
|
|
230
237
|
logController: new LogController({ disableRequestLogging: true }),
|
|
238
|
+
// Instance-wide body cap = the ADMIN tier. Fastify's own default is 1 MiB,
|
|
239
|
+
// which every console/API route inherited: a multi-MB `config.yaml` save
|
|
240
|
+
// failed as `413 "Payload Too Large"` in a shape the UI cannot render.
|
|
241
|
+
// Inference routes override this per route with the gateway tier cap, and
|
|
242
|
+
// the two upload routes declare their own bigger caps.
|
|
243
|
+
bodyLimit: bodyLimitFor('admin'),
|
|
244
|
+
});
|
|
245
|
+
// Inbound liveness, spelled from ONE source (utils/server-liveness + the
|
|
246
|
+
// SERVER_* constants): relying on runtime defaults is the same class of bug as
|
|
247
|
+
// the original 413 — Node arms 300s/60s/5s, Bun arms nothing, so which clients
|
|
248
|
+
// got served depended on which runtime started the process. Applied to the
|
|
249
|
+
// instance rather than passed as options because these keys are ambiguous across
|
|
250
|
+
// Fastify's http2 overloads and switch its inferred server type.
|
|
251
|
+
applyInboundLiveness(app.server);
|
|
252
|
+
// Admin-plane admission errors (413 oversized / 400 malformed body / 415
|
|
253
|
+
// undecodable) must answer `{ success: false, message }` — the shape the
|
|
254
|
+
// console already reads. Everything else is re-thrown to Fastify's default
|
|
255
|
+
// handler, so this never becomes a second error serializer.
|
|
256
|
+
app.setErrorHandler(adminBodyErrorHandler);
|
|
257
|
+
// `Expect: 100-continue` guard (RFC 9110 10.1.1): a client that declared a body
|
|
258
|
+
// over the cap of the route that would serve it is refused from the HEADERS
|
|
259
|
+
// alone, so it never pays for an upload we will throw away. Registering the
|
|
260
|
+
// listener switches off Node's automatic continue, so every continuation flows
|
|
261
|
+
// through `settleContinuationExpectation`, which always settles the request —
|
|
262
|
+
// either 413 or `100 Continue`.
|
|
263
|
+
//
|
|
264
|
+
// The cap comes from the route's OWN registration (recorded by `onRoute` below),
|
|
265
|
+
// never from a constant guessed here: the two upload routes accept more than the
|
|
266
|
+
// admin default, and refusing one of them early would reject a body the route
|
|
267
|
+
// would have taken. An unknown path or a route with no explicit cap gets no
|
|
268
|
+
// early answer — that costs one wasted upload, the other direction costs data.
|
|
269
|
+
const explicitRouteCaps = new Map();
|
|
270
|
+
app.addHook('onRoute', (routeOptions) => {
|
|
271
|
+
if (typeof routeOptions.bodyLimit === 'number') {
|
|
272
|
+
explicitRouteCaps.set(routeOptions.url, routeOptions.bodyLimit);
|
|
273
|
+
}
|
|
274
|
+
});
|
|
275
|
+
app.server.on('checkContinue', (req, res) => {
|
|
276
|
+
const answered = settleContinuationExpectation(req, res, (url) => {
|
|
277
|
+
const path = url.split('?')[0];
|
|
278
|
+
const capBytes = explicitRouteCaps.get(path);
|
|
279
|
+
if (capBytes === undefined)
|
|
280
|
+
return undefined;
|
|
281
|
+
const surface = SURFACES.find((s) => s.routePath === path);
|
|
282
|
+
return {
|
|
283
|
+
capBytes,
|
|
284
|
+
errorBody: surface
|
|
285
|
+
? (err) => surface.errorBody(err.statusCode, err.message, err.code)
|
|
286
|
+
: (err) => ({ success: false, message: err.message }),
|
|
287
|
+
log: app.log,
|
|
288
|
+
};
|
|
289
|
+
});
|
|
290
|
+
if (answered)
|
|
291
|
+
return;
|
|
292
|
+
// Installing the listener above suppressed the server's own delivery: verified
|
|
293
|
+
// on Bun 1.3.14 and Node 24, a `checkContinue` listener that only writes the
|
|
294
|
+
// continue leaves the request UNDISPATCHED (the client hangs until timeout).
|
|
295
|
+
// So the continue is written by the guard and the exchange is handed to the
|
|
296
|
+
// router here -- the same re-emit Node's own documentation prescribes.
|
|
297
|
+
app.server.emit('request', req, res);
|
|
231
298
|
});
|
|
232
299
|
app.addHook('onError', async (req, _reply, err) => {
|
|
233
300
|
req.log.error(err, 'request errored');
|
|
@@ -1453,10 +1520,32 @@ providerConfigs = []) {
|
|
|
1453
1520
|
// former server-level capture hooks are deleted). `return reply` mirrors
|
|
1454
1521
|
// the old handler's terminal pattern — the Fastify transport has already
|
|
1455
1522
|
// sent via reply / reply.raw.
|
|
1523
|
+
//
|
|
1524
|
+
// bodyLimit is NOT decoration: Fastify's instance default is 1 MiB, so an
|
|
1525
|
+
// unset value makes the native leg answer 413 "Payload Too Large" on any
|
|
1526
|
+
// ordinary agent context (Claude Code / opencode routinely post several
|
|
1527
|
+
// MB) while the MITM leg of the SAME request admits 32 MB. One constant,
|
|
1528
|
+
// both legs — see config/defaults.ts and surfaces/body-admission.ts.
|
|
1529
|
+
//
|
|
1530
|
+
// surfaceBodyAdmissionOptions carries the whole admission policy for this
|
|
1531
|
+
// leg: Content-Encoding decode (gzip/deflate/br, 415 for anything else),
|
|
1532
|
+
// the cap on the DECOMPRESSED body, and rejection answers shaped with the
|
|
1533
|
+
// surface's own error envelope (ADR-0008: 400/413 precede process, so no
|
|
1534
|
+
// transport and no capture event exists to shape them later). Left to
|
|
1535
|
+
// Fastify's default it answers {statusCode, code, error, message}, which
|
|
1536
|
+
// client SDKs surface as an opaque `413 "Payload Too Large"` naming neither
|
|
1537
|
+
// the cap nor the gateway as its author. Non-admission errors are re-thrown
|
|
1538
|
+
// to the parent handler per fastify/docs/Reference/Errors.md.
|
|
1456
1539
|
for (const surface of SURFACES) {
|
|
1457
|
-
app.post(surface.routePath, async (req, reply) => {
|
|
1540
|
+
app.post(surface.routePath, surfaceBodyAdmissionOptions(surface), async (req, reply) => {
|
|
1458
1541
|
const t = createFastifyTransport(req, reply, orchestrator);
|
|
1459
|
-
|
|
1542
|
+
// `normalizeNativeBody` closes the parser-shape gap: a tolerated but
|
|
1543
|
+
// non-json declaration (text/plain) hands Fastify's parser a raw STRING,
|
|
1544
|
+
// which would otherwise reach the pipeline and fail as a misleading
|
|
1545
|
+
// "messages array is required" 400 for a perfectly valid body. A wrong
|
|
1546
|
+
// shape throws BodyAdmissionError, which the route handler above answers
|
|
1547
|
+
// in the surface envelope.
|
|
1548
|
+
await dispatchSurface(t, surface, orchestrator, normalizeNativeBody(req.body));
|
|
1460
1549
|
return reply;
|
|
1461
1550
|
});
|
|
1462
1551
|
}
|
|
@@ -84,7 +84,10 @@ function anthropicErrorBody(status, message, code) {
|
|
|
84
84
|
return {
|
|
85
85
|
type: 'error',
|
|
86
86
|
error: {
|
|
87
|
-
type
|
|
87
|
+
// Anthropic's own error-type table gives 413 a dedicated type
|
|
88
|
+
// (`request_too_large`); folding it into `invalid_request_error` would
|
|
89
|
+
// tell a Claude Code client to fix its request shape rather than its size.
|
|
90
|
+
type: status >= 500 ? 'api_error' : status === 413 ? 'request_too_large' : 'invalid_request_error',
|
|
88
91
|
message,
|
|
89
92
|
...(code ? { code } : {}),
|
|
90
93
|
},
|