omnicell-router 0.7.0 → 0.8.2
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/cli/clients/activity.d.ts +35 -0
- package/backend/dist/cli/clients/activity.js +67 -0
- package/backend/dist/cli/clients/base.d.ts +13 -2
- package/backend/dist/cli/clients/claude.d.ts +2 -2
- package/backend/dist/cli/clients/codex.d.ts +2 -2
- package/backend/dist/cli/clients/core-adapters.d.ts +3 -4
- package/backend/dist/cli/clients/core-adapters.js +3 -4
- package/backend/dist/cli/clients/cursor-proxy.d.ts +88 -0
- package/backend/dist/cli/clients/cursor-proxy.js +421 -0
- package/backend/dist/cli/clients/dsh.d.ts +2 -2
- package/backend/dist/cli/clients/grok.d.ts +2 -2
- package/backend/dist/cli/clients/index.d.ts +8 -1
- package/backend/dist/cli/clients/index.js +55 -21
- package/backend/dist/cli/clients/kimi.d.ts +2 -2
- package/backend/dist/cli/clients/launcher.d.ts +8 -0
- package/backend/dist/cli/clients/model-meta.js +1 -1
- package/backend/dist/cli/clients/omp.d.ts +2 -2
- package/backend/dist/cli/clients/openclaw.d.ts +2 -2
- package/backend/dist/cli/clients/opencode-proxy.d.ts +11 -0
- package/backend/dist/cli/clients/opencode-proxy.js +351 -0
- package/backend/dist/cli/clients/opencode.d.ts +2 -2
- package/backend/dist/cli/clients/pi.d.ts +2 -2
- package/backend/dist/cli/clients/plugin-adapters.d.ts +3 -1
- package/backend/dist/cli/clients/plugin-adapters.js +6 -29
- package/backend/dist/cli/clients/qoder-proxy.d.ts +84 -0
- package/backend/dist/cli/clients/qoder-proxy.js +497 -0
- package/backend/dist/cli/clients/reserved.d.ts +2 -6
- package/backend/dist/cli/clients/reserved.js +2 -0
- package/backend/dist/cli/clients/workbuddy.d.ts +2 -2
- package/backend/dist/cli/index.js +60 -9
- package/backend/dist/cli/types.d.ts +29 -8
- package/backend/dist/compression/caveman-prompts.d.ts +1 -1
- package/backend/dist/config/comments-en.js +6 -12
- package/backend/dist/config/comments-zh.js +6 -12
- package/backend/dist/config/defaults.d.ts +56 -1
- package/backend/dist/config/defaults.js +68 -0
- package/backend/dist/config/index.d.ts +9 -2
- package/backend/dist/config/index.js +26 -3
- package/backend/dist/config/types.d.ts +55 -43
- package/backend/dist/forward-proxy/egress.d.ts +10 -2
- package/backend/dist/forward-proxy/egress.js +42 -4
- package/backend/dist/forward-proxy/ordered-relay.d.ts +29 -0
- package/backend/dist/forward-proxy/ordered-relay.js +46 -0
- package/backend/dist/forward-proxy/rules.d.ts +66 -19
- package/backend/dist/forward-proxy/rules.js +61 -14
- package/backend/dist/forward-proxy/server.js +226 -77
- package/backend/dist/forward-proxy/system-proxy.d.ts +42 -2
- package/backend/dist/forward-proxy/system-proxy.js +199 -22
- package/backend/dist/harness/common/market.d.ts +3 -3
- package/backend/dist/harness/host/adapters/amp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/antigravity.d.ts +1 -1
- package/backend/dist/harness/host/adapters/claude.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cline.d.ts +1 -1
- package/backend/dist/harness/host/adapters/codex.d.ts +1 -1
- package/backend/dist/harness/host/adapters/cursor.d.ts +1 -1
- package/backend/dist/harness/host/adapters/dsh.d.ts +2 -2
- package/backend/dist/harness/host/adapters/factory.d.ts +1 -1
- package/backend/dist/harness/host/adapters/gemini-cli.d.ts +1 -1
- package/backend/dist/harness/host/adapters/grok.d.ts +1 -1
- package/backend/dist/harness/host/adapters/kimi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/omp.d.ts +1 -1
- package/backend/dist/harness/host/adapters/openclaw.d.ts +1 -1
- package/backend/dist/harness/host/adapters/opencode.d.ts +1 -1
- package/backend/dist/harness/host/adapters/pi.d.ts +1 -1
- package/backend/dist/harness/host/adapters/universal.d.ts +1 -1
- package/backend/dist/harness/host/adapters/windsurf.d.ts +1 -1
- package/backend/dist/harness/host/adapters/zed.d.ts +1 -1
- package/backend/dist/harness/skill/skills-sh.d.ts +1 -1
- package/backend/dist/harness/translation.js +64 -21
- package/backend/dist/harness/types.d.ts +1 -1
- package/backend/dist/harness/types.js +1 -1
- package/backend/dist/index.js +31 -18
- package/backend/dist/ir/adapters/anthropic-stream.d.ts +18 -0
- package/backend/dist/ir/adapters/anthropic-stream.js +247 -0
- package/backend/dist/ir/adapters/anthropic.d.ts +29 -0
- package/backend/dist/ir/adapters/anthropic.js +788 -0
- package/backend/dist/ir/adapters/chat.d.ts +15 -0
- package/backend/dist/ir/adapters/chat.js +602 -0
- package/backend/dist/ir/adapters/google-stream.d.ts +22 -0
- package/backend/dist/ir/adapters/google-stream.js +242 -0
- package/backend/dist/ir/adapters/google.d.ts +9 -0
- package/backend/dist/ir/adapters/google.js +317 -0
- package/backend/dist/ir/adapters/openai-responses-output.js +8 -5
- package/backend/dist/ir/adapters/openai-responses.d.ts +15 -0
- package/backend/dist/ir/adapters/openai-responses.js +26 -1
- package/backend/dist/ir/adapters/responses-output.d.ts +50 -0
- package/backend/dist/ir/adapters/responses-output.js +348 -0
- package/backend/dist/ir/adapters/responses-stream.d.ts +12 -0
- package/backend/dist/ir/adapters/responses-stream.js +178 -0
- package/backend/dist/ir/adapters/responses.d.ts +14 -0
- package/backend/dist/ir/adapters/responses.js +646 -0
- package/backend/dist/ir/errors.d.ts +2 -2
- package/backend/dist/ir/types.d.ts +2 -1
- package/backend/dist/metrics/request-cost.d.ts +11 -2
- package/backend/dist/metrics/request-cost.js +12 -3
- package/backend/dist/observability/request-identity.d.ts +1 -1
- package/backend/dist/observability/trace-id.d.ts +40 -0
- package/backend/dist/observability/trace-id.js +134 -0
- package/backend/dist/observability/upstream-events.d.ts +82 -60
- package/backend/dist/observability/upstream-events.js +142 -67
- package/backend/dist/opencode/catalog/types.d.ts +9 -0
- package/backend/dist/opencode/credentials/types.d.ts +2 -2
- package/backend/dist/opencode/probe.d.ts +24 -1
- package/backend/dist/opencode/probe.js +28 -4
- package/backend/dist/opencode/user-config.d.ts +5 -0
- package/backend/dist/pipeline/directives.d.ts +6 -2
- package/backend/dist/pipeline/directives.js +7 -3
- package/backend/dist/pipeline/orchestrator.d.ts +28 -27
- package/backend/dist/pipeline/orchestrator.js +220 -194
- package/backend/dist/pipeline/unresolved-model.d.ts +33 -0
- package/backend/dist/pipeline/unresolved-model.js +43 -0
- package/backend/dist/plugins/catalog-def.d.ts +143 -0
- package/backend/dist/plugins/catalog-def.js +177 -0
- package/backend/dist/plugins/gateways.d.ts +62 -3
- package/backend/dist/plugins/gateways.js +139 -2
- package/backend/dist/plugins/host.d.ts +42 -5
- package/backend/dist/plugins/host.js +454 -38
- package/backend/dist/plugins/manifest.d.ts +119 -10
- package/backend/dist/plugins/manifest.js +265 -14
- package/backend/dist/plugins/pack.js +26 -0
- package/backend/dist/plugins/types.d.ts +187 -21
- package/backend/dist/protocols/systemone/convert.d.ts +1 -0
- package/backend/dist/protocols/systemone/convert.js +6 -1
- package/backend/dist/protocols/systemone/decide.js +18 -8
- package/backend/dist/providers/anthropic-messages.d.ts +12 -0
- package/backend/dist/providers/anthropic-messages.js +53 -0
- package/backend/dist/providers/anthropic.d.ts +7 -8
- package/backend/dist/providers/anthropic.js +36 -324
- package/backend/dist/providers/base.d.ts +14 -2
- package/backend/dist/providers/boot-direct.js +68 -38
- package/backend/dist/providers/dispatch.d.ts +5 -19
- package/backend/dist/providers/dispatch.js +46 -58
- package/backend/dist/providers/executors/anthropic-messages.d.ts +1 -0
- package/backend/dist/providers/executors/anthropic-messages.js +3 -0
- package/backend/dist/providers/executors/dispatch.d.ts +16 -2
- package/backend/dist/providers/executors/dispatch.js +39 -9
- package/backend/dist/providers/executors/google-gemini.d.ts +1 -0
- package/backend/dist/providers/executors/google-gemini.js +3 -0
- package/backend/dist/providers/executors/http-stream.js +16 -3
- package/backend/dist/providers/executors/openai-chat.d.ts +1 -0
- package/backend/dist/providers/executors/openai-chat.js +3 -0
- package/backend/dist/providers/executors/openai-responses.d.ts +1 -0
- package/backend/dist/providers/executors/openai-responses.js +3 -0
- package/backend/dist/providers/executors/plugin-adapter.js +4 -4
- package/backend/dist/providers/google-gemini.d.ts +12 -0
- package/backend/dist/providers/google-gemini.js +50 -0
- package/backend/dist/providers/google.d.ts +7 -8
- package/backend/dist/providers/google.js +35 -308
- package/backend/dist/providers/http-json.d.ts +19 -0
- package/backend/dist/providers/http-json.js +104 -0
- package/backend/dist/providers/http-stream.d.ts +52 -0
- package/backend/dist/providers/http-stream.js +423 -0
- package/backend/dist/providers/member-match.d.ts +4 -5
- package/backend/dist/providers/member-match.js +4 -5
- package/backend/dist/providers/openai-chat.d.ts +13 -0
- package/backend/dist/providers/openai-chat.js +99 -0
- package/backend/dist/providers/openai-compatible.d.ts +7 -4
- package/backend/dist/providers/openai-compatible.js +71 -368
- package/backend/dist/providers/openai-responses.d.ts +12 -0
- package/backend/dist/providers/openai-responses.js +68 -0
- package/backend/dist/providers/opencode-proxy.d.ts +5 -5
- package/backend/dist/providers/opencode-proxy.js +49 -125
- package/backend/dist/providers/plugin-adapter.d.ts +9 -0
- package/backend/dist/providers/plugin-adapter.js +31 -0
- package/backend/dist/providers/registry.d.ts +49 -24
- package/backend/dist/providers/registry.js +97 -55
- package/backend/dist/providers/responses.d.ts +7 -28
- package/backend/dist/providers/responses.js +45 -253
- package/backend/dist/providers/tool-markup-leak.d.ts +41 -0
- package/backend/dist/providers/tool-markup-leak.js +57 -0
- package/backend/dist/providers/tool-markup-recovery.d.ts +27 -0
- package/backend/dist/providers/tool-markup-recovery.js +786 -0
- package/backend/dist/providers/virtual-meta.d.ts +21 -2
- package/backend/dist/providers/virtual-meta.js +49 -9
- package/backend/dist/proxy/asset-download.d.ts +54 -0
- package/backend/dist/proxy/asset-download.js +420 -0
- package/backend/dist/proxy/manual-node-spec.d.ts +16 -16
- package/backend/dist/proxy/mihomo-binary.d.ts +17 -2
- package/backend/dist/proxy/mihomo-binary.js +62 -51
- package/backend/dist/proxy/mihomo-client.js +15 -1
- package/backend/dist/proxy/mihomo-config.js +11 -2
- package/backend/dist/proxy/mihomo-geo.d.ts +87 -0
- package/backend/dist/proxy/mihomo-geo.js +213 -0
- package/backend/dist/proxy/mihomo-logs.d.ts +27 -0
- package/backend/dist/proxy/mihomo-logs.js +70 -0
- package/backend/dist/proxy/mihomo-pac.d.ts +11 -0
- package/backend/dist/proxy/mihomo-pac.js +15 -0
- package/backend/dist/proxy/mihomo-rules-import.d.ts +1 -1
- package/backend/dist/proxy/mihomo-rules-import.js +7 -7
- package/backend/dist/proxy/mihomo-sidecar.d.ts +17 -1
- package/backend/dist/proxy/mihomo-sidecar.js +148 -26
- package/backend/dist/quota/adapters/minimax.js +36 -13
- package/backend/dist/quota/cli-login.d.ts +8 -0
- package/backend/dist/quota/cli-login.js +18 -0
- package/backend/dist/quota/declarations.js +10 -0
- package/backend/dist/quota/dsl.js +18 -5
- package/backend/dist/quota/engine.d.ts +22 -1
- package/backend/dist/quota/engine.js +170 -29
- package/backend/dist/quota/prober.d.ts +5 -0
- package/backend/dist/quota/prober.js +11 -2
- package/backend/dist/quota/types.d.ts +87 -8
- package/backend/dist/quota/verdict.d.ts +35 -0
- package/backend/dist/quota/verdict.js +135 -0
- package/backend/dist/ratelimit/admission.d.ts +131 -0
- package/backend/dist/ratelimit/admission.js +233 -0
- package/backend/dist/ratelimit/rate-limiter.js +6 -0
- package/backend/dist/resilience/types.d.ts +2 -2
- package/backend/dist/router/layer2-decision.d.ts +1 -1
- package/backend/dist/router/layer2-decision.js +5 -8
- package/backend/dist/routes/console.js +248 -52
- package/backend/dist/routes/mihomo.d.ts +2 -0
- package/backend/dist/routes/mihomo.js +334 -29
- package/backend/dist/routes/responses.d.ts +87 -8
- package/backend/dist/routes/responses.js +314 -33
- package/backend/dist/server.js +34 -6
- package/backend/dist/session/session-manager.d.ts +6 -0
- package/backend/dist/session/session-manager.js +20 -9
- package/backend/dist/surfaces/chat-pipeline.d.ts +2 -2
- package/backend/dist/surfaces/chat-pipeline.js +17 -7
- package/backend/dist/surfaces/chat.js +15 -0
- package/backend/dist/surfaces/decision-pipeline.js +7 -10
- package/backend/dist/surfaces/direct-forward.d.ts +3 -0
- package/backend/dist/surfaces/direct-forward.js +206 -0
- package/backend/dist/surfaces/rate-limit-response.d.ts +17 -0
- package/backend/dist/surfaces/rate-limit-response.js +57 -0
- package/backend/dist/surfaces/types.d.ts +11 -0
- package/backend/dist/trace/tracker.d.ts +32 -1
- package/backend/dist/trace/tracker.js +29 -4
- package/backend/dist/types/router.d.ts +34 -12
- package/backend/dist/types/router.js +35 -6
- package/backend/dist/utils/chat-stream.d.ts +21 -8
- package/backend/dist/utils/chat-stream.js +46 -9
- package/backend/dist/utils/event-ring.d.ts +4 -0
- package/backend/dist/utils/event-ring.js +4 -0
- package/backend/dist/utils/popularity.js +29 -4
- package/backend/dist/utils/proxy.d.ts +7 -0
- package/backend/dist/utils/proxy.js +35 -10
- package/backend/dist/utils/retry-after.d.ts +21 -0
- package/backend/dist/utils/retry-after.js +36 -0
- package/bin/ocr.js +2 -2
- package/frontend/dist/assets/index-55VVwfFQ.js +1521 -0
- package/frontend/dist/assets/{index-CQSLGFTV.css → index-DxZ9MHKB.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
- package/frontend/dist/assets/index-CLvxJjp_.js +0 -1476
|
@@ -14,6 +14,7 @@ import { canonicalProtocol } from './protocol.js';
|
|
|
14
14
|
import { CircuitBreakerManager, UpstreamError } from '../resilience/index.js';
|
|
15
15
|
import { globMatchAny } from '../utils/glob.js';
|
|
16
16
|
import { loadConfig } from '../config/index.js';
|
|
17
|
+
import { redactProxyUrl, resolveProxyUrl } from '../utils/proxy.js';
|
|
17
18
|
import { resolveTierMembers, claimModel, claimInTier, matchingTiers, applyEffortMap, MEMBER_TIER_ORDER, TIER_DESCENDING_ORDER, comboMemberRefsOf, expandComboRefs, RESERVED_IDS } from './member-match.js';
|
|
18
19
|
/**
|
|
19
20
|
* Normalize a client-supplied upstream host for provider matching: lowercase,
|
|
@@ -108,8 +109,8 @@ export class ProviderRegistry {
|
|
|
108
109
|
*/
|
|
109
110
|
credentialChains = new Map();
|
|
110
111
|
mockMode = false;
|
|
111
|
-
|
|
112
|
-
|
|
112
|
+
autoRefreshMembers = true;
|
|
113
|
+
lastMembersRefreshAt = 0;
|
|
113
114
|
constructor(config, mockMode = false, providerConfigs = []) {
|
|
114
115
|
this.mockMode = mockMode;
|
|
115
116
|
this.tierPolicies = config.tiers || {};
|
|
@@ -267,13 +268,15 @@ export class ProviderRegistry {
|
|
|
267
268
|
this.models.set(model.id, model);
|
|
268
269
|
this.circuitBreakerManager.registerModel(model);
|
|
269
270
|
this.indexVariants(model);
|
|
270
|
-
// an UNCLAIMED model must never become a tier's
|
|
271
|
-
// it joins no pool, so promoting it would hand routing a
|
|
272
|
-
// themselves filter out. Explicit `isDefault` pinning stays
|
|
273
|
-
|
|
271
|
+
// an UNCLAIMED model (no home tier) must never become a tier's
|
|
272
|
+
// representative — it joins no pool, so promoting it would hand routing a
|
|
273
|
+
// model the pools themselves filter out. Explicit `isDefault` pinning stays
|
|
274
|
+
// authoritative.
|
|
275
|
+
if (model.tier === undefined && !isDefault)
|
|
274
276
|
return;
|
|
275
|
-
|
|
276
|
-
|
|
277
|
+
const home = model.tier;
|
|
278
|
+
if (home !== undefined && (isDefault || !this.tierDefaults.has(home))) {
|
|
279
|
+
this.tierDefaults.set(home, model);
|
|
277
280
|
}
|
|
278
281
|
}
|
|
279
282
|
getCircuitBreakerManager() {
|
|
@@ -328,6 +331,18 @@ export class ProviderRegistry {
|
|
|
328
331
|
for (const m of models) {
|
|
329
332
|
const existing = this.models.get(m.id);
|
|
330
333
|
if (existing) {
|
|
334
|
+
// Replace-in-place, NOT Object.assign: a fresh record that OMITS a
|
|
335
|
+
// provenance/capability key must not leave the old value routable.
|
|
336
|
+
// Boot emits EITHER configTier OR autoTier, and reasoningDisableable /
|
|
337
|
+
// pricing only when the vendor states them — Object.assign would keep
|
|
338
|
+
// a stale autoTier (silently re-claiming a freshly pinned model), a
|
|
339
|
+
// stale always-think fact, or a stale price forever after the source
|
|
340
|
+
// changed. Identity is preserved (the Map entry and any held reference
|
|
341
|
+
// stay valid) while absent keys are reset.
|
|
342
|
+
for (const key of Object.keys(existing)) {
|
|
343
|
+
if (!(key in m))
|
|
344
|
+
delete existing[key];
|
|
345
|
+
}
|
|
331
346
|
Object.assign(existing, m);
|
|
332
347
|
this.indexVariants(existing);
|
|
333
348
|
}
|
|
@@ -397,7 +412,9 @@ export class ProviderRegistry {
|
|
|
397
412
|
hits.push(m);
|
|
398
413
|
}
|
|
399
414
|
// Locale-independent tiebreak: strict code-unit order, not localeCompare.
|
|
400
|
-
|
|
415
|
+
// Unpriced models sort last: an unknown price cannot claim to be the
|
|
416
|
+
// cheapest, and `Infinity` keeps that ordering without inventing a number.
|
|
417
|
+
const byPrice = (a, b) => (a.pricing?.input ?? Infinity) - (b.pricing?.input ?? Infinity) ||
|
|
401
418
|
(a.id < b.id ? -1 : a.id > b.id ? 1 : 0);
|
|
402
419
|
const host = normalizeHostHeader(upstreamHost);
|
|
403
420
|
if (host) {
|
|
@@ -431,9 +448,8 @@ export class ProviderRegistry {
|
|
|
431
448
|
}
|
|
432
449
|
/**
|
|
433
450
|
* Why a model is rejected from every pool ('' = allowed). The ONLY pool
|
|
434
|
-
* filter
|
|
435
|
-
*
|
|
436
|
-
* and the model-side excludeTiers live inside the classification gate.
|
|
451
|
+
* filter: the GLOBAL denylist (tiers.exclude) — unconditional, it outranks
|
|
452
|
+
* even an explicit pin.
|
|
437
453
|
*/
|
|
438
454
|
policyRejectionReason(policies, m) {
|
|
439
455
|
const exclude = policies?.exclude;
|
|
@@ -500,9 +516,10 @@ export class ProviderRegistry {
|
|
|
500
516
|
* Membership is a PER-TIER projection of the member lists: every rule in
|
|
501
517
|
* THIS tier's list claims models independently of the other tiers, so a
|
|
502
518
|
* model (or a combo's expanded members) may join several pools at once.
|
|
503
|
-
* Hand-configured models (no
|
|
504
|
-
* join exactly their explicit tier, with weight
|
|
505
|
-
* rule when one exists (default 1). Chain order =
|
|
519
|
+
* Hand-configured models (no autoTier stamp) never move: their explicit
|
|
520
|
+
* tier is permanent. They join exactly their explicit tier, with weight
|
|
521
|
+
* from this tier's matching rule when one exists (default 1). Chain order =
|
|
522
|
+
* claiming-rule weight
|
|
506
523
|
* (desc) then rule list position (asc); entries carry the claiming rule's
|
|
507
524
|
* weight and effortMap — the translation that applies when the model
|
|
508
525
|
* serves from THIS pool.
|
|
@@ -510,9 +527,9 @@ export class ProviderRegistry {
|
|
|
510
527
|
buildTierPoolEntries(tier, members) {
|
|
511
528
|
const entries = [];
|
|
512
529
|
for (const m of this.models.values()) {
|
|
513
|
-
if (!m.
|
|
530
|
+
if (!m.autoTier) {
|
|
514
531
|
// Hand-configured model: explicit tier, member rules never move it.
|
|
515
|
-
if (m.
|
|
532
|
+
if (m.tier !== tier)
|
|
516
533
|
continue;
|
|
517
534
|
const claim = claimInTier(tier, m.id, members);
|
|
518
535
|
entries.push({
|
|
@@ -540,12 +557,12 @@ export class ProviderRegistry {
|
|
|
540
557
|
* The effort translation that applies when `model` serves from `tier`'s
|
|
541
558
|
* pool: the claiming rule's effortMap in THAT tier (a model holding
|
|
542
559
|
* membership in several tiers translates differently per pool).
|
|
543
|
-
* Hand-configured models keep their stored translation
|
|
544
|
-
* (
|
|
545
|
-
*
|
|
560
|
+
* Hand-configured models keep their stored translation; a model absent from
|
|
561
|
+
* this tier (escalation-tail resolution) falls back to the stored home-tier
|
|
562
|
+
* translation.
|
|
546
563
|
*/
|
|
547
564
|
effortMapFor(model, tier) {
|
|
548
|
-
if (!model.
|
|
565
|
+
if (!model.autoTier)
|
|
549
566
|
return model.effortMap;
|
|
550
567
|
const claim = claimInTier(tier, model.id, this.committedMembers);
|
|
551
568
|
if (claim)
|
|
@@ -558,24 +575,24 @@ export class ProviderRegistry {
|
|
|
558
575
|
* checks. Hand-configured models expose exactly their explicit tier.
|
|
559
576
|
*/
|
|
560
577
|
tiersOf(model) {
|
|
561
|
-
if (!model.
|
|
562
|
-
return model.
|
|
578
|
+
if (!model.autoTier)
|
|
579
|
+
return model.tier === undefined ? [] : [model.tier];
|
|
563
580
|
return matchingTiers(model.id, this.committedMembers);
|
|
564
581
|
}
|
|
565
582
|
/**
|
|
566
|
-
* Runtime tier
|
|
583
|
+
* Runtime tier membership replay — membership is pure file-derived data
|
|
567
584
|
* (config `tiers[t].members`), replayed against each model id on
|
|
568
585
|
* pool resolution instead of waiting for a gateway restart. Model UNIVERSE
|
|
569
586
|
* (providers/credentials/wire) stays a boot snapshot.
|
|
570
587
|
*/
|
|
571
588
|
/** Hot-path guard: replay member lists + the combo map + policies at most every 2 seconds. */
|
|
572
|
-
|
|
573
|
-
if (!this.
|
|
589
|
+
maybeRefreshMembers() {
|
|
590
|
+
if (!this.autoRefreshMembers)
|
|
574
591
|
return;
|
|
575
592
|
const now = Date.now();
|
|
576
|
-
if (now - this.
|
|
593
|
+
if (now - this.lastMembersRefreshAt < 2000)
|
|
577
594
|
return;
|
|
578
|
-
this.
|
|
595
|
+
this.lastMembersRefreshAt = now;
|
|
579
596
|
try {
|
|
580
597
|
const fresh = loadConfig();
|
|
581
598
|
// Combos share the hand-edited-YAML safety net: a combo write that
|
|
@@ -591,16 +608,16 @@ export class ProviderRegistry {
|
|
|
591
608
|
this.reclassifyTiers(this.expandedMemberRules(tiers).tiers);
|
|
592
609
|
}
|
|
593
610
|
catch {
|
|
594
|
-
// transient config/IO error — keep the current
|
|
611
|
+
// transient config/IO error — keep the current membership
|
|
595
612
|
}
|
|
596
613
|
}
|
|
597
|
-
/** Latest committed `tiers` config (snapshot; updated by applyTierConfigNow /
|
|
614
|
+
/** Latest committed `tiers` config (snapshot; updated by applyTierConfigNow / maybeRefreshMembers). */
|
|
598
615
|
getTierPolicies() {
|
|
599
616
|
return this.tierPolicies;
|
|
600
617
|
}
|
|
601
618
|
/** Test hook: silence the lazy config re-read (explicit reclassifyTiers still works). */
|
|
602
|
-
|
|
603
|
-
this.
|
|
619
|
+
setAutoRefreshMembers(on) {
|
|
620
|
+
this.autoRefreshMembers = on;
|
|
604
621
|
}
|
|
605
622
|
/** Registered member refs of one combo (config order, deduped, unregistered
|
|
606
623
|
dropped) — null when the ref is dead: unknown id, operator-disabled, or
|
|
@@ -623,7 +640,7 @@ export class ProviderRegistry {
|
|
|
623
640
|
/**
|
|
624
641
|
* COMMIT path — the only one that rewrites live pool membership. Called on
|
|
625
642
|
* every config-save event (console routes) so edits take effect immediately;
|
|
626
|
-
* the lazy
|
|
643
|
+
* the lazy maybeRefreshMembers replay (tiers AND combos) remains only as
|
|
627
644
|
* the out-of-band (hand-edited YAML) safety net.
|
|
628
645
|
*/
|
|
629
646
|
applyTierConfigNow() {
|
|
@@ -631,10 +648,10 @@ export class ProviderRegistry {
|
|
|
631
648
|
return;
|
|
632
649
|
const tiers = loadConfig().tiers || {};
|
|
633
650
|
this.tierPolicies = tiers;
|
|
634
|
-
this.
|
|
651
|
+
this.lastMembersRefreshAt = Date.now(); // the file was just read — skip the TTL replay
|
|
635
652
|
this.reclassifyTiers(this.expandedMemberRules(tiers).tiers);
|
|
636
653
|
}
|
|
637
|
-
/** Replays the member lists over every
|
|
654
|
+
/** Replays the member lists over every stamped model and stores
|
|
638
655
|
* them as the committed pool view (buildTierPoolEntries reads exactly this
|
|
639
656
|
* snapshot). What is stored per model is the DERIVED HOME view used by
|
|
640
657
|
* single-tier consumers (pinned force_tier, tier-keyed reporting,
|
|
@@ -646,16 +663,15 @@ export class ProviderRegistry {
|
|
|
646
663
|
return;
|
|
647
664
|
this.committedMembers = members;
|
|
648
665
|
for (const m of this.models.values()) {
|
|
649
|
-
if (!m.
|
|
666
|
+
if (!m.autoTier)
|
|
650
667
|
continue; // hand-configured: never moved
|
|
651
668
|
const home = claimModel(m.id, members);
|
|
652
669
|
if (home === 'unclassified') {
|
|
653
|
-
m.
|
|
670
|
+
m.tier = undefined;
|
|
654
671
|
m.isDefaultInTier = false;
|
|
655
672
|
delete m.effortMap;
|
|
656
673
|
continue;
|
|
657
674
|
}
|
|
658
|
-
m.unclassified = false;
|
|
659
675
|
m.tier = home.tier;
|
|
660
676
|
m.priority = home.index + 1; // home list order (derived view)
|
|
661
677
|
m.isDefaultInTier = home.index === 0; // the home list leader
|
|
@@ -679,12 +695,12 @@ export class ProviderRegistry {
|
|
|
679
695
|
* Returns all candidate models registered for a given tier, in chain order
|
|
680
696
|
* (member-list order). If healthyOnly is true, only returns models
|
|
681
697
|
* where the circuit breaker allows execution. The global denylist
|
|
682
|
-
* (tiers.exclude) is applied first;
|
|
683
|
-
* pool. Membership is the per-tier projection
|
|
684
|
-
* a model may serve in several tiers at once.
|
|
698
|
+
* (tiers.exclude) is applied first; models no member list claims (no home
|
|
699
|
+
* tier) join no pool. Membership is the per-tier projection
|
|
700
|
+
* (buildTierPoolEntries) — a model may serve in several tiers at once.
|
|
685
701
|
*/
|
|
686
702
|
getCandidateModelsForTier(tier, healthyOnly = true, opts) {
|
|
687
|
-
this.
|
|
703
|
+
this.maybeRefreshMembers();
|
|
688
704
|
return this.tierPoolEntries(tier, healthyOnly, opts).map(({ model }) => model);
|
|
689
705
|
}
|
|
690
706
|
/**
|
|
@@ -783,9 +799,13 @@ export class ProviderRegistry {
|
|
|
783
799
|
best = { model: m, actualEffort: 'none', gap };
|
|
784
800
|
continue;
|
|
785
801
|
}
|
|
786
|
-
const supported = modelSupportsEfforts(m.supportedReasoningEfforts, m.supportsReasoningEffort);
|
|
802
|
+
const supported = modelSupportsEfforts(m.supportedReasoningEfforts, m.supportsReasoningEffort, m.reasoningDisableable);
|
|
787
803
|
if (!supported)
|
|
788
804
|
continue; // no explicit effort control → cannot serve a mapped level
|
|
805
|
+
// Deliberately the 2-arg form: this is ROUTING, where an unreachable ask
|
|
806
|
+
// means SKIP the candidate (never serve above what was asked). The
|
|
807
|
+
// always-think floor belongs to the sites that must serve one fixed model
|
|
808
|
+
// (orchestrator / directives), not here.
|
|
789
809
|
const actual = downgradeReasoning(target, supported);
|
|
790
810
|
if (actual === 'none')
|
|
791
811
|
continue; // capability can't reach any real level → skip
|
|
@@ -819,14 +839,14 @@ export class ProviderRegistry {
|
|
|
819
839
|
const chain = order.filter((t, i, all) => t !== tier && all.indexOf(t) === i);
|
|
820
840
|
for (const step of chain) {
|
|
821
841
|
const rep = this.tierDefaults.get(step);
|
|
822
|
-
if (rep &&
|
|
842
|
+
if (rep && rep.tier !== undefined) {
|
|
823
843
|
console.warn(`[Registry] Tier '${tier}' has no candidate model — falling back to '${step}' (${rep.id}), reason=empty-pool`);
|
|
824
844
|
return rep;
|
|
825
845
|
}
|
|
826
846
|
}
|
|
827
|
-
const any = Array.from(this.models.values()).find((m) =>
|
|
847
|
+
const any = Array.from(this.models.values()).find((m) => m.tier !== undefined);
|
|
828
848
|
if (!any) {
|
|
829
|
-
throw new Error(`No routable models registered (
|
|
849
|
+
throw new Error(`No routable models registered (no model's tier membership is claimed by any pool).`);
|
|
830
850
|
}
|
|
831
851
|
console.warn(`[Registry] Tier '${tier}' has no candidate model — falling back to the first registered model (${any.id}), reason=empty-pool`);
|
|
832
852
|
return any;
|
|
@@ -907,7 +927,7 @@ export class ProviderRegistry {
|
|
|
907
927
|
// ─── Custom model combos ────────────────────────────────────────────────
|
|
908
928
|
/**
|
|
909
929
|
* (Re)register combo definitions — used at boot, for hot-apply on console
|
|
910
|
-
* config saves, and by the lazy
|
|
930
|
+
* config saves, and by the lazy maybeRefreshMembers safety net. A section
|
|
911
931
|
* byte-identical to the last applied one is a no-op (keeps round-robin
|
|
912
932
|
* cursors, avoids repeat skip warnings): skip outcomes depend only on the
|
|
913
933
|
* section plus the monotonically grown model map, and every read path
|
|
@@ -1033,9 +1053,10 @@ export class ProviderRegistry {
|
|
|
1033
1053
|
* freshly-edited form state for previews without committing; runtime
|
|
1034
1054
|
* callers omit it and get the construction-time snapshot. Pool order =
|
|
1035
1055
|
* rule weight (desc) then member-list order; entries carry the claiming
|
|
1036
|
-
* rule's weight (default 1). `unclassified` is the diagnostic fourth state:
|
|
1056
|
+
* rule's weight (default 1). `'unclassified'` is the diagnostic fourth state:
|
|
1037
1057
|
* models claimed by NO tier (it is never hidden by the denylist — the
|
|
1038
|
-
* console must show it for the unpooled view / one-click join).
|
|
1058
|
+
* console must show it for the unpooled view / one-click join). A model is
|
|
1059
|
+
* in this view exactly when its home tier is undefined.
|
|
1039
1060
|
*/
|
|
1040
1061
|
resolveTierPool(tier, policiesOverride) {
|
|
1041
1062
|
const policies = policiesOverride ?? this.tierPolicies;
|
|
@@ -1045,9 +1066,9 @@ export class ProviderRegistry {
|
|
|
1045
1066
|
if (tier === 'unclassified') {
|
|
1046
1067
|
const pool = [];
|
|
1047
1068
|
for (const m of this.models.values()) {
|
|
1048
|
-
if (!m.
|
|
1049
|
-
// Hand-configured model:
|
|
1050
|
-
if (m.
|
|
1069
|
+
if (!m.autoTier) {
|
|
1070
|
+
// Hand-configured model: unclaimed exactly when registered so.
|
|
1071
|
+
if (m.tier === undefined)
|
|
1051
1072
|
pool.push({ model: m, weight: 1 });
|
|
1052
1073
|
continue;
|
|
1053
1074
|
}
|
|
@@ -1067,6 +1088,25 @@ export class ProviderRegistry {
|
|
|
1067
1088
|
}
|
|
1068
1089
|
return { pool, excluded };
|
|
1069
1090
|
}
|
|
1091
|
+
/**
|
|
1092
|
+
* Outbound egress the CORE transport will take for `model`, resolved from
|
|
1093
|
+
* the same `resolveProxyUrl` the executors call at dial time (ADR-0018 /
|
|
1094
|
+
* ADR-0022). Call this IMMEDIATELY before `execute()` and keep the value
|
|
1095
|
+
* with the attempt: the proxy config hot-applies, so a read after a long
|
|
1096
|
+
* stream can describe a different dial.
|
|
1097
|
+
*
|
|
1098
|
+
* `undefined` = UNKNOWN, never direct: nothing was dialed (mock mode) or
|
|
1099
|
+
* the transport does not report its dial base (plugin-owned executors).
|
|
1100
|
+
*/
|
|
1101
|
+
egressFor(model) {
|
|
1102
|
+
if (this.mockMode)
|
|
1103
|
+
return undefined;
|
|
1104
|
+
const base = this.providers.get(model.provider)?.dialBaseFor?.(model);
|
|
1105
|
+
if (!base)
|
|
1106
|
+
return undefined;
|
|
1107
|
+
const proxy = resolveProxyUrl(base, { provider: model.provider, model: model.id });
|
|
1108
|
+
return proxy ? { mode: 'proxy', origin: redactProxyUrl(proxy) } : { mode: 'direct' };
|
|
1109
|
+
}
|
|
1070
1110
|
/**
|
|
1071
1111
|
* Execute one completion. `credentialKeyHashPrefix`
|
|
1072
1112
|
* selects one credential of the provider's registered chain by its Decision 5
|
|
@@ -1076,7 +1116,9 @@ export class ProviderRegistry {
|
|
|
1076
1116
|
* when a chain is registered — the attribution seam for the P3 pair-level
|
|
1077
1117
|
* breaker work (no classification changes here).
|
|
1078
1118
|
*/
|
|
1079
|
-
async execute(request, model, upstreamEventContext, credentialKeyHashPrefix, relay
|
|
1119
|
+
async execute(request, model, upstreamEventContext, credentialKeyHashPrefix, relay,
|
|
1120
|
+
/** Resolved OCR conversation id. Not a capture field. */
|
|
1121
|
+
sessionId) {
|
|
1080
1122
|
if (this.mockMode) {
|
|
1081
1123
|
relay?.onTransport?.('buffered');
|
|
1082
1124
|
return this.mockExecute(request, model);
|
|
@@ -1103,7 +1145,7 @@ export class ProviderRegistry {
|
|
|
1103
1145
|
const scanner = recovery ? null : createToolMarkupScanner();
|
|
1104
1146
|
const rewrite = recovery ? createToolMarkupStreamRecovery(request) : null;
|
|
1105
1147
|
relay.onTransport?.('sse');
|
|
1106
|
-
const stream = await provider.createStream(request, model, upstreamEventContext, credential);
|
|
1148
|
+
const stream = await provider.createStream(request, model, upstreamEventContext, credential, sessionId);
|
|
1107
1149
|
// Drain for terminal usage even if the client disconnected. Relay and
|
|
1108
1150
|
// accounting consume the same event objects without history copies.
|
|
1109
1151
|
for await (const event of stream) {
|
|
@@ -1126,7 +1168,7 @@ export class ProviderRegistry {
|
|
|
1126
1168
|
}
|
|
1127
1169
|
relay.onTransport?.('buffered');
|
|
1128
1170
|
}
|
|
1129
|
-
const buffered = await provider.createCompletion(request, model, upstreamEventContext, credential);
|
|
1171
|
+
const buffered = await provider.createCompletion(request, model, upstreamEventContext, credential, sessionId);
|
|
1130
1172
|
const finished = recovery ? recoverToolMarkupInResponse(buffered, request) : buffered;
|
|
1131
1173
|
const leak = recovery ? finished.toolMarkupLeak ?? null : detectToolMarkupLeak(finished);
|
|
1132
1174
|
if (!leak)
|
|
@@ -1,33 +1,12 @@
|
|
|
1
|
-
import { LLMProvider,
|
|
2
|
-
import { ModelRegistration, ProviderConfig } from '../config/types.js';
|
|
3
|
-
import {
|
|
4
|
-
/**
|
|
5
|
-
* OpenAI Responses API wire (`@ai-sdk/openai`) — POST {base}/responses.
|
|
6
|
-
* Serves providers (or single models, via model-level npm override) that reject
|
|
7
|
-
* chat/completions with `ModelProtocolUnsupported` — e.g. Zen's gpt-6-luna.
|
|
8
|
-
*
|
|
9
|
-
* Tools are fully mapped both directions (2026-10): the pipeline canonicalizes
|
|
10
|
-
* tools in the chat-completions (nested) shape; request.tools → payload tools
|
|
11
|
-
* re-flattens to the Responses wire (identical flat function shape), assistant
|
|
12
|
-
* tool_calls in history →
|
|
13
|
-
* function_call items, tool role messages → function_call_output items, and
|
|
14
|
-
* upstream function_call output items → chat tool_calls. Without this, a
|
|
15
|
-
* /v1/responses tool-loop client routed here would silently lose tool calling.
|
|
16
|
-
*/
|
|
17
|
-
/**
|
|
18
|
-
* OpenAI Responses wire shares the same response-header semantics as the
|
|
19
|
-
* chat-completions wire (x-ratelimit-*, retry-after, x-request-id) — the
|
|
20
|
-
* upstream is the same family. Headers are now sanitized uniformly via
|
|
21
|
-
* `sanitizeHeadersForCapture` (full names + credential redaction) so the
|
|
22
|
-
* wire-specific extractor is no longer needed.
|
|
23
|
-
*/
|
|
24
|
-
/** Pure payload builder: chat-completions request → OpenAI Responses payload. */
|
|
25
|
-
export declare function buildResponsesPayload(request: ChatCompletionRequest, model: ModelRegistration): Record<string, any>;
|
|
26
|
-
/** Pure response mapper: OpenAI Responses payload → chat-completions response. */
|
|
27
|
-
export declare function responsesToChatCompletion(data: any, model: ModelRegistration): ChatCompletionResponse;
|
|
1
|
+
import type { LLMProvider, UpstreamEventContext, CallCredential } from './base.js';
|
|
2
|
+
import type { ModelRegistration, ProviderConfig } from '../config/types.js';
|
|
3
|
+
import type { CanonicalRequest, CanonicalResponse, StreamEvent } from '../ir/types.js';
|
|
4
|
+
/** OpenAI Responses upstream. The provider speaks Canonical IR only. */
|
|
28
5
|
export declare class ResponsesProvider implements LLMProvider {
|
|
29
6
|
name: string;
|
|
30
7
|
private config;
|
|
31
8
|
constructor(config: ProviderConfig);
|
|
32
|
-
|
|
9
|
+
private headers;
|
|
10
|
+
createCompletion(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<CanonicalResponse>;
|
|
11
|
+
createStream(request: CanonicalRequest, model: ModelRegistration, upstreamEventContext?: UpstreamEventContext, credential?: CallCredential): Promise<AsyncIterable<StreamEvent>>;
|
|
33
12
|
}
|