omnicell-router 0.8.1 → 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.d.ts +35 -0
- package/backend/dist/cli/clients/activity.js +69 -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/index.js +7 -1
- 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 +18 -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 +120 -95
- package/backend/dist/server.js +99 -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-Cn3QMOQx.js → index-Dk76uc7e.js} +398 -363
- package/frontend/dist/assets/{index-DxZ9MHKB.css → index-KI1OW5x6.css} +1 -1
- package/frontend/dist/assets/workbuddy.color-DOMpQkxJ.svg +29 -0
- package/frontend/dist/index.html +2 -2
- package/package.json +1 -1
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
import { getAllClientStatuses, setupClient, teardownClient } from '../cli/clients/index.js';
|
|
4
|
+
import { clientActivitySnapshot } from '../cli/clients/activity.js';
|
|
4
5
|
import { VIRTUAL_AUTO_IDS } from '../cli/types.js';
|
|
5
6
|
import { MEMBER_TIER_ORDER } from '../providers/member-match.js';
|
|
6
7
|
import { refreshDirectPool } from '../providers/boot-direct.js';
|
|
@@ -47,7 +48,8 @@ import { maskSecret, isValidProviderId, PROVIDER_ID_RULE, getProviderNodeById }
|
|
|
47
48
|
import { listOpenCodeAgentsLive } from '../opencode/agents.js';
|
|
48
49
|
import { listApiKeys, createApiKey, updateApiKey, deleteApiKey, validateApiKey, validateModelAccess, } from '../auth/api-keys.js';
|
|
49
50
|
import { toCallCredential } from '../providers/boot-direct.js';
|
|
50
|
-
import {
|
|
51
|
+
import { buildKeyModelsView } from '../auth/key-models.js';
|
|
52
|
+
import { clearClientProfileMemory, getFollowCatalogIssue, getFollowCatalogSyncState, isFollowCatalogPending, retryFollowCatalogPending, stampClientProfileMemory, } from '../cli/clients/follow-catalog-sync.js';
|
|
51
53
|
import { validateRateLimitRules, getRateLimiter, credentialSubject } from '../ratelimit/rate-limiter.js';
|
|
52
54
|
import { getQuotaProber } from '../quota/prober.js';
|
|
53
55
|
import { getQuotaStore } from '../quota/store.js';
|
|
@@ -1026,11 +1028,45 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1026
1028
|
// "Refresh Status" button must never serve a stale snapshot.
|
|
1027
1029
|
app.get('/api/admin/clients', async (req) => {
|
|
1028
1030
|
const refresh = req.query.refresh === '1';
|
|
1031
|
+
// The activity ledger rides along per row (lastActiveAt / lastSetupAt);
|
|
1032
|
+
// SORTING stays on the console — the CLI's roster table must keep the
|
|
1033
|
+
// registry order regardless of live traffic.
|
|
1034
|
+
const activity = clientActivitySnapshot();
|
|
1029
1035
|
return {
|
|
1030
1036
|
status: 'ok',
|
|
1031
|
-
clients: await getAllClientStatuses({ refresh })
|
|
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
|
+
}),
|
|
1032
1057
|
};
|
|
1033
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
|
+
});
|
|
1034
1070
|
// 3A1'. Release update check — display-only and cached in-process. The
|
|
1035
1071
|
// first console read starts the GitHub call in the background and answers
|
|
1036
1072
|
// `checking: true`; the console polls until the snapshot settles. A stale
|
|
@@ -1853,7 +1889,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1853
1889
|
// 4. Client Interception Setup / Teardown
|
|
1854
1890
|
const handleSetup = async (req, reply) => {
|
|
1855
1891
|
const { client } = req.params;
|
|
1856
|
-
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 || {});
|
|
1857
1893
|
const cleaned = models && typeof models === 'object'
|
|
1858
1894
|
? Object.fromEntries(Object.entries(models).map(([k, v]) => [k, String(v ?? 'auto').trim() || 'auto']))
|
|
1859
1895
|
: undefined;
|
|
@@ -1916,6 +1952,21 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1916
1952
|
});
|
|
1917
1953
|
if (!result.success)
|
|
1918
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
|
+
}
|
|
1919
1970
|
return result;
|
|
1920
1971
|
};
|
|
1921
1972
|
const handleTeardown = async (req, reply) => {
|
|
@@ -1927,6 +1978,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
1927
1978
|
});
|
|
1928
1979
|
if (!result.success)
|
|
1929
1980
|
return reply.status(400).send(result);
|
|
1981
|
+
clearClientProfileMemory(client);
|
|
1930
1982
|
return result;
|
|
1931
1983
|
};
|
|
1932
1984
|
app.post('/api/admin/client/:client/setup', handleSetup);
|
|
@@ -3096,7 +3148,9 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3096
3148
|
// at all) is by definition custom.
|
|
3097
3149
|
custom: u ? u.custom : true,
|
|
3098
3150
|
logo: u?.logo ?? v.logo,
|
|
3099
|
-
|
|
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,
|
|
3100
3154
|
// Operator takedown: routing state, never a defs-file field (ADR-0010).
|
|
3101
3155
|
// The card stays listed so the operator can restore it with one click.
|
|
3102
3156
|
disabled: takedown !== undefined,
|
|
@@ -3130,7 +3184,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3130
3184
|
id: p.id,
|
|
3131
3185
|
name: p.name,
|
|
3132
3186
|
logo: p.logo,
|
|
3133
|
-
|
|
3187
|
+
protocols: p.protocols,
|
|
3134
3188
|
api: p.api,
|
|
3135
3189
|
baseURL: p.baseURL,
|
|
3136
3190
|
doc: p.doc,
|
|
@@ -3187,7 +3241,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3187
3241
|
// preset's own baseURL/npm.
|
|
3188
3242
|
providers.splice(idx, 1);
|
|
3189
3243
|
}
|
|
3190
|
-
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 });
|
|
3191
3245
|
}
|
|
3192
3246
|
}
|
|
3193
3247
|
catch {
|
|
@@ -3318,7 +3372,7 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3318
3372
|
const result = upsertProviderDef({
|
|
3319
3373
|
id,
|
|
3320
3374
|
name: body.name,
|
|
3321
|
-
|
|
3375
|
+
protocols: body.protocols,
|
|
3322
3376
|
baseURL: body.baseURL,
|
|
3323
3377
|
apiKey: keyToStore ? undefined : body.apiKey,
|
|
3324
3378
|
apiKeyInline: Boolean(body.apiKeyInline),
|
|
@@ -3441,7 +3495,9 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3441
3495
|
const result = upsertProviderDef({
|
|
3442
3496
|
id,
|
|
3443
3497
|
name: body.name ?? existing.name,
|
|
3444
|
-
|
|
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,
|
|
3445
3501
|
baseURL: body.baseURL ?? existing.options?.baseURL,
|
|
3446
3502
|
apiKey: keyToStore ? undefined : body.apiKey,
|
|
3447
3503
|
apiKeyInline: inline,
|
|
@@ -3498,7 +3554,9 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3498
3554
|
id,
|
|
3499
3555
|
baseURL: body.baseURL,
|
|
3500
3556
|
name: existing?.name,
|
|
3501
|
-
|
|
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,
|
|
3502
3560
|
headers: existing?.options?.headers,
|
|
3503
3561
|
models: existing?.models,
|
|
3504
3562
|
options: existing?.options,
|
|
@@ -3578,10 +3636,13 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3578
3636
|
}
|
|
3579
3637
|
if (!def)
|
|
3580
3638
|
return { error: `provider '${id}' not found` };
|
|
3639
|
+
const { primaryProtocol } = await import('../providers/protocols-field.js');
|
|
3581
3640
|
const node = def;
|
|
3582
3641
|
const baseURL = (node.options?.baseURL ?? node.baseURL ?? '').replace(/\/+$/, '');
|
|
3583
|
-
|
|
3584
|
-
|
|
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';
|
|
3585
3646
|
const plugin = (await import('../plugins/host.js')).getModelServicePlugin(wire);
|
|
3586
3647
|
if (!plugin?.webLogin) {
|
|
3587
3648
|
return { error: `provider '${id}' is not on a plugin wire with a web-login capability` };
|
|
@@ -3845,6 +3906,42 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3845
3906
|
});
|
|
3846
3907
|
}
|
|
3847
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
|
+
}
|
|
3848
3945
|
// The verdict's egress (ADR-0018 / ADR-0022 vocabulary) is taken from the
|
|
3849
3946
|
// attempt that produced it and rides on the reply, so "Test" answers "did
|
|
3850
3947
|
// my model-scoped split apply" — the include/exclude page can only state
|
|
@@ -3878,10 +3975,14 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
3878
3975
|
for (const modelId of modelCandidates) {
|
|
3879
3976
|
if (!tried.includes(modelId))
|
|
3880
3977
|
tried.push(modelId);
|
|
3881
|
-
//
|
|
3882
|
-
//
|
|
3883
|
-
|
|
3884
|
-
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));
|
|
3885
3986
|
// The model's own capability flags, read from the def the console
|
|
3886
3987
|
// holds — a plugin probe builds a REAL request, so guessing
|
|
3887
3988
|
// "not a reasoning model" makes it send thinking-off to a model that
|
|
@@ -5218,87 +5319,11 @@ export function registerConsoleRoutes(app, registry, orchestrator) {
|
|
|
5218
5319
|
// addressable-id namespace a row belongs to.
|
|
5219
5320
|
const handleGetKeyModels = async (req, reply) => {
|
|
5220
5321
|
const { id } = req.params;
|
|
5221
|
-
const
|
|
5222
|
-
if (
|
|
5223
|
-
return reply.status(404).send(
|
|
5224
|
-
}
|
|
5225
|
-
const policy = getModelAccessPolicy(key);
|
|
5226
|
-
const registered = registry.getAllModels().map((m) => ({
|
|
5227
|
-
id: m.id,
|
|
5228
|
-
kind: 'model',
|
|
5229
|
-
provider: m.provider,
|
|
5230
|
-
// FULL membership set (pools are a per-tier projection — a model may
|
|
5231
|
-
// belong to several tiers): tierAllowed counts every pool the model can
|
|
5232
|
-
// route toward, so auto-X viability never misses a multi-pool member.
|
|
5233
|
-
tiers: registry.tiersOf(m),
|
|
5234
|
-
virtual: false,
|
|
5235
|
-
allowed: isModelAllowedInTiers(m.id, policy, registry.tiersOf(m)),
|
|
5236
|
-
}));
|
|
5237
|
-
const tierAllowed = (t) => registered.some((m) => m.tiers?.includes(t) && m.allowed);
|
|
5238
|
-
// Virtual auto* rows honor runtime viability (mirrors /v1/models): bare
|
|
5239
|
-
// `auto` needs an allowed model in ANY tier, auto-X in tier X.
|
|
5240
|
-
const virtual = ['auto', 'lite', 'plus', 'pro', 'ultra'].map((id) => ({
|
|
5241
|
-
id,
|
|
5242
|
-
kind: (id === 'auto' ? 'auto' : 'tier'),
|
|
5243
|
-
provider: 'omnicell-router',
|
|
5244
|
-
tier: tierFromVirtualEntry(id),
|
|
5245
|
-
virtual: true,
|
|
5246
|
-
allowed: isAutoEntryUsable(id, policy, tierAllowed),
|
|
5247
|
-
}));
|
|
5248
|
-
// Combo rows (mirrors /v1/models): routable virtual ids, but concrete
|
|
5249
|
-
// selectable entries — NOT auto*-virtual, so follow-mode snapshots keep
|
|
5250
|
-
// them. A combo passes only when EVERY member is allowed (the inference
|
|
5251
|
-
// entry gate; no silent composition change).
|
|
5252
|
-
const combos = registry.getCombos().map((c) => ({
|
|
5253
|
-
id: c.id,
|
|
5254
|
-
kind: 'combo',
|
|
5255
|
-
provider: 'omnicell-router',
|
|
5256
|
-
tier: '',
|
|
5257
|
-
virtual: false,
|
|
5258
|
-
allowed: registry.resolveCombo(c.id).every((mem) => isModelAllowed(mem.id, policy, mem.tier)),
|
|
5259
|
-
}));
|
|
5260
|
-
// Variant rows (mirrors /v1/models): `base-variant` ids resolve to the
|
|
5261
|
-
// base model with a pinned reasoning effort; the policy verdict inherits
|
|
5262
|
-
// from the base id.
|
|
5263
|
-
const variants = registry.getVariantExposures().map(({ id, base }) => ({
|
|
5264
|
-
id,
|
|
5265
|
-
kind: 'variant',
|
|
5266
|
-
provider: base.provider,
|
|
5267
|
-
tiers: registry.tiersOf(base),
|
|
5268
|
-
virtual: false,
|
|
5269
|
-
allowed: isModelAllowedInTiers(base.id, policy, registry.tiersOf(base)),
|
|
5270
|
-
}));
|
|
5271
|
-
// Order mirrors the /v1/models wire body EXACTLY (the console list is a
|
|
5272
|
-
// pure re-rendering of that payload — same rows, same sequence). The wire
|
|
5273
|
-
// builds a provider map whose insertion order IS the display order: the
|
|
5274
|
-
// omnicell-router virtual provider (auto alias → tier aliases → combos)
|
|
5275
|
-
// first, then concrete providers in registry first-appearance order, each
|
|
5276
|
-
// carrying its concrete models then its variant siblings.
|
|
5277
|
-
const providerRows = new Map();
|
|
5278
|
-
const ensureProviderRows = (pid) => {
|
|
5279
|
-
let rows = providerRows.get(pid);
|
|
5280
|
-
if (!rows) {
|
|
5281
|
-
rows = [];
|
|
5282
|
-
providerRows.set(pid, rows);
|
|
5283
|
-
}
|
|
5284
|
-
return rows;
|
|
5285
|
-
};
|
|
5286
|
-
for (const m of registry.getAllModels()) {
|
|
5287
|
-
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);
|
|
5288
5325
|
}
|
|
5289
|
-
|
|
5290
|
-
ensureProviderRows(v.provider).push(v);
|
|
5291
|
-
const models = [
|
|
5292
|
-
...virtual,
|
|
5293
|
-
...combos,
|
|
5294
|
-
...[...providerRows.entries()].filter(([pid]) => pid !== 'omnicell-router').flatMap(([, rows]) => rows),
|
|
5295
|
-
];
|
|
5296
|
-
return {
|
|
5297
|
-
status: 'ok',
|
|
5298
|
-
mode: policy?.mode ?? 'none',
|
|
5299
|
-
policyModels: policy?.models ?? [],
|
|
5300
|
-
models,
|
|
5301
|
-
};
|
|
5326
|
+
return view;
|
|
5302
5327
|
};
|
|
5303
5328
|
app.get('/api/admin/api-keys/:id/models', handleGetKeyModels);
|
|
5304
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';
|
|
@@ -22,6 +24,7 @@ import { ProviderRegistry } from './providers/registry.js';
|
|
|
22
24
|
import { FinOpsTracker } from './metrics/finops-tracker.js';
|
|
23
25
|
import { APP_VERSION } from './version.js';
|
|
24
26
|
import { setGatewayMetaDeps } from './cli/clients/model-meta.js';
|
|
27
|
+
import { noteClientActivityFromUserAgent } from './cli/clients/activity.js';
|
|
25
28
|
import { comboEnvelope, findMemberCatalogRecords, modelsDevBlock, tierAliasEnvelope, virtualModelsDevBlock, } from './providers/virtual-meta.js';
|
|
26
29
|
import { modelSupportsEfforts } from './types/router.js';
|
|
27
30
|
import { isInternalSessionId } from './session/session-manager.js';
|
|
@@ -214,6 +217,11 @@ export function createServer(config, mockMode = false, customRegistry, customOrc
|
|
|
214
217
|
/** Extra provider configs for the bootstrapped registry (test seam only —
|
|
215
218
|
* production chat providers enter via `registerProvider` post-boot). */
|
|
216
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);
|
|
217
225
|
// disableRequestLogging: Fastify's built-in per-request lifecycle logs
|
|
218
226
|
// ("incoming request" / "request completed" at info) are pure noise here —
|
|
219
227
|
// every UI poll of /health + /api/* produced a pair, drowning ocr.log.
|
|
@@ -227,6 +235,66 @@ providerConfigs = []) {
|
|
|
227
235
|
level: process.env.LOG_LEVEL || 'info',
|
|
228
236
|
},
|
|
229
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);
|
|
230
298
|
});
|
|
231
299
|
app.addHook('onError', async (req, _reply, err) => {
|
|
232
300
|
req.log.error(err, 'request errored');
|
|
@@ -462,6 +530,13 @@ providerConfigs = []) {
|
|
|
462
530
|
}
|
|
463
531
|
// Attach client identity onto request for tracing and logging
|
|
464
532
|
req.authInfo = validation;
|
|
533
|
+
// Display-only client-activity stamp for the Clients page's dynamic sort:
|
|
534
|
+
// fingerprint the User-Agent on the four inference wires only (model /
|
|
535
|
+
// admin browsing is not "using a client"). Forgeable by design of HTTP —
|
|
536
|
+
// never routing state, a spoofed UA costs at most a wrong card position.
|
|
537
|
+
if (path !== null && INFERENCE_ROUTE_PATHS.has(path)) {
|
|
538
|
+
noteClientActivityFromUserAgent(req.headers['user-agent']);
|
|
539
|
+
}
|
|
465
540
|
// ── Inbound sliding-window enforcement (apiKeys[].limits) ───────────────
|
|
466
541
|
// The client key's window caps are a CONTRACT with the caller, enforced at
|
|
467
542
|
// the gate: an over-limit request never enters the pipeline and never
|
|
@@ -1445,10 +1520,32 @@ providerConfigs = []) {
|
|
|
1445
1520
|
// former server-level capture hooks are deleted). `return reply` mirrors
|
|
1446
1521
|
// the old handler's terminal pattern — the Fastify transport has already
|
|
1447
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.
|
|
1448
1539
|
for (const surface of SURFACES) {
|
|
1449
|
-
app.post(surface.routePath, async (req, reply) => {
|
|
1540
|
+
app.post(surface.routePath, surfaceBodyAdmissionOptions(surface), async (req, reply) => {
|
|
1450
1541
|
const t = createFastifyTransport(req, reply, orchestrator);
|
|
1451
|
-
|
|
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));
|
|
1452
1549
|
return reply;
|
|
1453
1550
|
});
|
|
1454
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
|
},
|