@bitkyc08/opencodex 2.100.0 → 2.100.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/gui/dist/assets/App-BpJOzw4F.js +59 -0
- package/gui/dist/assets/Tray-BcaI-VCr.js +1 -0
- package/gui/dist/assets/brand-mark-DU-0Vdkr.js +1 -0
- package/gui/dist/assets/index-Bbor_y80.js +94 -0
- package/gui/dist/assets/index-DJEkIDAi.css +2 -0
- package/gui/dist/assets/{segment-thumb-features-CcxZBnxv.js → segment-thumb-features-e9A_FogJ.js} +1 -1
- package/gui/dist/classic/assets/{App-aYgIQMxI.js → App-BrIlUiLc.js} +18 -18
- package/gui/dist/classic/assets/{Tray-D8jfUXpQ.js → Tray-DT146AhS.js} +1 -1
- package/gui/dist/classic/assets/index-DyJHagvT.js +94 -0
- package/gui/dist/classic/assets/quota-summary-CakPe9Ni.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/package.json +2 -2
- package/src/adapters/anthropic-image-normalize.ts +1 -1
- package/src/adapters/client-fingerprint.ts +6 -4
- package/src/adapters/cursor/native-exec.ts +3 -2
- package/src/adapters/cursor/tool-guidance.ts +3 -3
- package/src/adapters/cursor/tool-wording.ts +10 -1
- package/src/adapters/devin/cloud-direct/tool-schema.ts +20 -2
- package/src/adapters/google-antigravity-wire.ts +13 -6
- package/src/adapters/google-truncation.ts +4 -2
- package/src/adapters/google.ts +8 -2
- package/src/adapters/openai-chat/mistral-image-limit.ts +28 -15
- package/src/adapters/openai-chat/tool-schema.ts +9 -0
- package/src/adapters/openai-chat-images.ts +100 -0
- package/src/adapters/openai-chat.ts +6 -9
- package/src/adapters/openai-responses/tool-schema.ts +18 -4
- package/src/adapters/run-turn-queue.ts +139 -5
- package/src/adapters/upstream-http-error.ts +4 -2
- package/src/bridge/sse.ts +8 -1
- package/src/claude/chat-tool-dispatch.ts +233 -0
- package/src/claude/inbound-tool-loading.ts +42 -17
- package/src/cli/account-api.ts +6 -0
- package/src/cli/account-extended.ts +60 -6
- package/src/cli/account-key-quota.ts +22 -2
- package/src/cli/account.ts +1 -1
- package/src/cli/capabilities-access-remote.ts +10 -0
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +2 -2
- package/src/cli/claude.ts +19 -14
- package/src/cli/config-command.ts +24 -1
- package/src/cli/connect.ts +36 -3
- package/src/cli/gui-pair-client.ts +23 -2
- package/src/cli/help.ts +1 -1
- package/src/cli/hub.ts +18 -1
- package/src/cli/link-child-ops.ts +136 -0
- package/src/cli/link-status-child.ts +94 -0
- package/src/cli/link.ts +22 -9
- package/src/cli/registry.ts +3 -2
- package/src/cli/sync-command.ts +3 -1
- package/src/cli/sync-fanout.ts +8 -81
- package/src/client/link-readiness.ts +16 -6
- package/src/client/link-tunnel-status.ts +76 -0
- package/src/clients/config-export.ts +14 -1
- package/src/codex/account-resume-health.ts +41 -0
- package/src/codex/auth-api/login-flow.ts +6 -0
- package/src/codex/auth-api/routes.ts +35 -2
- package/src/codex/catalog/gather-capture.ts +2 -0
- package/src/codex/catalog/provider-models.ts +13 -8
- package/src/codex/convergence-types.ts +2 -0
- package/src/codex/quota.ts +111 -6
- package/src/combos/cooldown-store.ts +208 -0
- package/src/combos/failover.ts +432 -35
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +6 -3
- package/src/config/schema/leaf-validators.ts +34 -12
- package/src/generated/compatibility-version.json +227 -135
- package/src/lib/catalog-etag.ts +10 -0
- package/src/lib/client-error-body.ts +15 -0
- package/src/lib/config-ownership.ts +9 -2
- package/src/lib/context-overflow-verdict.ts +266 -9
- package/src/lib/failure-detail.ts +72 -3
- package/src/lib/hard-refusal.ts +259 -0
- package/src/link/child-activity.ts +57 -0
- package/src/link/child-catalog-freshness.ts +149 -0
- package/src/link/child-gated-ocx.ts +117 -0
- package/src/link/child-observations.ts +205 -0
- package/src/link/child-observe.ts +121 -0
- package/src/link/child-ops-engine.ts +162 -0
- package/src/link/child-update-contract.ts +165 -0
- package/src/link/paths.ts +5 -0
- package/src/link/remote-windows.ts +42 -6
- package/src/link/ssh-argv.ts +126 -32
- package/src/link/status-projection.ts +73 -0
- package/src/link/sync-fanout-classify.ts +98 -0
- package/src/link/tunnel-state.ts +10 -4
- package/src/messaging/mcp-queue-rpc.ts +2 -1
- package/src/messaging/mcp-queue-server.ts +5 -0
- package/src/messaging/mcp-reply-tools.ts +24 -9
- package/src/messaging/mcp-reply-wait.ts +70 -0
- package/src/oauth/account-resume-health.ts +60 -0
- package/src/oauth/anthropic-model-quota.ts +12 -0
- package/src/oauth/anthropic-routing.ts +11 -4
- package/src/oauth/index.ts +1 -0
- package/src/oauth/kiro-iam-identity-center.ts +4 -1
- package/src/oauth/store.ts +44 -1
- package/src/providers/api-key-pause-state.ts +23 -0
- package/src/providers/api-key-pause.ts +68 -10
- package/src/providers/api-key-selection-capture.ts +3 -1
- package/src/providers/api-key-selection.ts +3 -2
- package/src/providers/api-keys.ts +18 -5
- package/src/providers/claude-cli-identity.ts +9 -3
- package/src/providers/claude-cli-usage-state.ts +11 -6
- package/src/providers/claude-cli-usage.ts +27 -8
- package/src/providers/codex-capacity.ts +11 -2
- package/src/providers/key-failover.ts +13 -6
- package/src/providers/model-discovery-config.ts +31 -0
- package/src/providers/model-discovery-diagnostic.ts +34 -3
- package/src/providers/model-discovery.ts +43 -7
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/openai-sidecar.ts +15 -2
- package/src/providers/provider-id-rewrite.ts +3 -0
- package/src/providers/quota/account-cache.ts +52 -34
- package/src/providers/quota/anthropic-family-headers.ts +8 -1
- package/src/providers/quota/anthropic-usage-windows.ts +66 -9
- package/src/providers/quota/report-cache.ts +53 -5
- package/src/providers/quota/vendor-probes-key.ts +73 -0
- package/src/providers/quota/vendor-probes-oauth.ts +57 -3
- package/src/providers/quota-key-accounts.ts +12 -5
- package/src/providers/quota-mistral-budget.ts +18 -0
- package/src/providers/quota-types.ts +32 -0
- package/src/providers/quota.ts +22 -22
- package/src/providers/reasoning-metadata.ts +1051 -12
- package/src/providers/registry/entries-extended.ts +3 -1
- package/src/providers/registry/model-ids.ts +1 -0
- package/src/providers/registry/types.ts +6 -0
- package/src/quota/reset-observer.ts +4 -2
- package/src/quota/reset-seen-store.ts +9 -0
- package/src/quota/window-mapping.ts +1 -0
- package/src/quota-pool/assemble.ts +4 -1
- package/src/responses/hosted-tool-policy.ts +56 -12
- package/src/responses/retained-compaction.ts +31 -5
- package/src/router.ts +2 -0
- package/src/server/auth-cors.ts +11 -8
- package/src/server/catalog-download.ts +3 -5
- package/src/server/chat-native.ts +11 -2
- package/src/server/claude-messages.ts +2 -1
- package/src/server/images.ts +41 -13
- package/src/server/index/link-listener.ts +16 -2
- package/src/server/index/link-relay-sessions.ts +43 -2
- package/src/server/index/optional-listeners.ts +18 -0
- package/src/server/management/config-routes.ts +7 -1
- package/src/server/management/context.ts +1 -1
- package/src/server/management/link-child-ops-routes.ts +116 -0
- package/src/server/management/link-route-state.ts +10 -0
- package/src/server/management/link-routes.ts +10 -0
- package/src/server/management/oauth-account-routes.ts +33 -4
- package/src/server/management/provider-overwrite-carry.ts +28 -3
- package/src/server/management/provider-routes.ts +16 -11
- package/src/server/management/route-registry.ts +3 -0
- package/src/server/messages-native.ts +5 -0
- package/src/server/request-log-failure-detail.ts +59 -1
- package/src/server/responses/adapter-dispatch.ts +35 -44
- package/src/server/responses/combo-stream-preflight.ts +146 -29
- package/src/server/responses/compact.ts +27 -4
- package/src/server/responses/context-overflow.ts +58 -2
- package/src/server/responses/core-combo-failure.ts +29 -4
- package/src/server/responses/core-combo-native.ts +3 -1
- package/src/server/responses/core-combo.ts +30 -3
- package/src/server/responses/core-errors.ts +3 -1
- package/src/server/responses/core-opaque-recovery.ts +45 -2
- package/src/server/responses/core-options.ts +12 -0
- package/src/server/responses/passthrough-dispatch.ts +30 -38
- package/src/server/responses/request-transport.ts +43 -14
- package/src/server/responses/reset-replay.ts +58 -2
- package/src/server/responses/run-turn-execution.ts +56 -30
- package/src/types/claude-tool-loading.ts +48 -0
- package/src/types/config.ts +5 -35
- package/src/types/provider.ts +21 -0
- package/src/types.ts +1 -0
- package/src/web-search/parse.ts +44 -4
- package/gui/dist/assets/App-CitvEefy.js +0 -59
- package/gui/dist/assets/Tray-CeKVWQyB.js +0 -1
- package/gui/dist/assets/brand-mark-M92UnxX2.js +0 -1
- package/gui/dist/assets/index-BP47do6-.js +0 -94
- package/gui/dist/assets/index-DmDooSAG.css +0 -2
- package/gui/dist/classic/assets/index-CfGqHooN.js +0 -94
- package/gui/dist/classic/assets/quota-summary-R-ih7OlS.js +0 -1
|
@@ -522,7 +522,9 @@ export const PROVIDER_REGISTRY_EXTENDED: readonly ProviderRegistryEntry[] = [
|
|
|
522
522
|
preserveReasoningContentModels: NVIDIA_NIM_KIMI_THINKING_MODELS,
|
|
523
523
|
note: "Free tier on NVIDIA NIM — API key still required (get a free key at build.nvidia.com).",
|
|
524
524
|
},
|
|
525
|
-
|
|
525
|
+
// Venice returns 400 for any image under 64x64, which a wide screenshot hits after
|
|
526
|
+
// the shared normalizer floors older images to a 320px long edge (320x25).
|
|
527
|
+
{ id: "venice", label: "Venice", baseUrl: "https://api.venice.ai/api/v1", adapter: "openai-chat", authKind: "key", dashboardUrl: "https://venice.ai/settings/api", minImageEdge: 64 },
|
|
526
528
|
// 260710 GLM-5.2 context and path-specific ids: Tier-2 evidence in
|
|
527
529
|
// devlog/_plan/260710_provider_hardening/002_research_cn.md.
|
|
528
530
|
// 260814: glm-5.3 / glm-5.3[1m] added per docs.z.ai/devpack/latest-model, which lists them as
|
|
@@ -81,6 +81,7 @@ export const REGISTRY_FIELD_MODEL_ID_ROLES = {
|
|
|
81
81
|
annotateEmptyToolOutputs: NONE,
|
|
82
82
|
supportsServiceTier: NONE,
|
|
83
83
|
supportsOpenAiWebSearchToolFields: NONE,
|
|
84
|
+
minImageEdge: NONE,
|
|
84
85
|
supportsResponsesCustomTools: NONE,
|
|
85
86
|
modelSupportsServiceTier: RECORD_KEYS,
|
|
86
87
|
keyAuthServiceTier: KEY_AUTH_SERVICE_TIER,
|
|
@@ -260,6 +260,12 @@ export interface ProviderRegistryEntry {
|
|
|
260
260
|
supportsServiceTier?: boolean;
|
|
261
261
|
/** Registry default for OpenAI extended hosted web_search field support. */
|
|
262
262
|
supportsOpenAiWebSearchToolFields?: boolean;
|
|
263
|
+
/**
|
|
264
|
+
* Registry-only smallest image edge, in pixels, that the upstream accepts on the
|
|
265
|
+
* `openai-chat` wire. Inline images below it are upscaled before sending, because the
|
|
266
|
+
* upstream rejects the whole request otherwise (Venice: "images must be at least 64x64").
|
|
267
|
+
*/
|
|
268
|
+
minImageEdge?: number;
|
|
263
269
|
/** Registry default for native Responses custom-tool support. */
|
|
264
270
|
supportsResponsesCustomTools?: boolean;
|
|
265
271
|
/** Registry default for exact model service-tier capability; explicit config keys win. */
|
|
@@ -56,17 +56,19 @@ export function observeQuotaSnapshot(input: {
|
|
|
56
56
|
readonly windows: ReadonlyArray<QuotaWindowObservation>;
|
|
57
57
|
readonly now?: number;
|
|
58
58
|
readonly retainAbsentShortWindow?: boolean;
|
|
59
|
+
/** Display-only windows the producer reports as unknown; their last baseline is kept. */
|
|
60
|
+
readonly retainUnknownWindows?: ReadonlyArray<{ window: string; resetAt: number }>;
|
|
59
61
|
}): QuotaResetEvent[] {
|
|
60
62
|
try {
|
|
61
63
|
if (!sink) return [];
|
|
62
|
-
if (input.windows.length === 0) return [];
|
|
64
|
+
if (input.windows.length === 0 && input.retainUnknownWindows === undefined) return [];
|
|
63
65
|
const now = input.now ?? Date.now();
|
|
64
66
|
const accountTag = quotaAccountTag(input.accountKey, quotaResetAccountSalt());
|
|
65
67
|
// Stamp the observation time as it becomes the baseline. The detector needs the gap
|
|
66
68
|
// between two observations to tell a rolling window's natural decay from a real reset,
|
|
67
69
|
// and only this layer knows when the snapshot was taken.
|
|
68
70
|
const stamped = input.windows.map(window => ({ ...window, observedAt: now }));
|
|
69
|
-
const previous = swapLastObservedWindows(input.scope, accountTag, stamped, input.retainAbsentShortWindow);
|
|
71
|
+
const previous = swapLastObservedWindows(input.scope, accountTag, stamped, input.retainAbsentShortWindow, input.retainUnknownWindows);
|
|
70
72
|
if (!previous) return [];
|
|
71
73
|
|
|
72
74
|
const detected = detectQuotaResets({
|
|
@@ -307,6 +307,7 @@ export function swapLastObservedWindows(
|
|
|
307
307
|
accountTag: string,
|
|
308
308
|
windows: ReadonlyArray<QuotaWindowObservation>,
|
|
309
309
|
retainAbsentShortWindow = false,
|
|
310
|
+
retainUnknownWindows: ReadonlyArray<{ window: string; resetAt: number }> = [],
|
|
310
311
|
): ReadonlyArray<QuotaWindowObservation> | undefined {
|
|
311
312
|
hydrate();
|
|
312
313
|
const key = observedKey(scope, accountTag);
|
|
@@ -325,6 +326,14 @@ export function swapLastObservedWindows(
|
|
|
325
326
|
const short = previous?.find(window => window.window === "5h");
|
|
326
327
|
if (short) next.push({ ...short });
|
|
327
328
|
}
|
|
329
|
+
// An explicitly unknown budget is not a new measurement. Carry its last measured baseline
|
|
330
|
+
// only when the reported deadline still identifies the same window; a moved deadline is a
|
|
331
|
+
// different window and starts a fresh baseline instead of firing a false reset.
|
|
332
|
+
for (const unknown of retainUnknownWindows) {
|
|
333
|
+
if (next.some(window => window.window === unknown.window)) continue;
|
|
334
|
+
const prior = previous?.find(window => window.window === unknown.window && window.resetAt === unknown.resetAt);
|
|
335
|
+
if (prior) next.push({ ...prior });
|
|
336
|
+
}
|
|
328
337
|
observed.set(key, next);
|
|
329
338
|
if (observed.size > MAX_OBSERVED_SCOPES) {
|
|
330
339
|
// Least-recently-observed first. Evicting only costs a re-baseline, never a duplicate
|
|
@@ -27,6 +27,7 @@ type ProviderLikeQuota = {
|
|
|
27
27
|
monthlyPercent?: number;
|
|
28
28
|
monthlyResetAt?: number;
|
|
29
29
|
customWindows?: ReadonlyArray<{ label: string; percent: number; resetAt?: number; modelId?: string }>;
|
|
30
|
+
unknownBudgetWindows?: ReadonlyArray<{ label: string; resetAt?: number }>;
|
|
30
31
|
};
|
|
31
32
|
|
|
32
33
|
function window(
|
|
@@ -24,6 +24,7 @@
|
|
|
24
24
|
*/
|
|
25
25
|
import type { OcxConfig, OcxProviderConfig } from "../types";
|
|
26
26
|
import type { ProviderQuota, ProviderQuotaWindow } from "../providers/quota-types";
|
|
27
|
+
import { isDisplayOnlyQuota } from "../providers/quota-types";
|
|
27
28
|
import type { StoredAccountQuota } from "../codex/quota-types";
|
|
28
29
|
import { isTerminalShortWindow, resetAtToMs } from "../codex/quota-types";
|
|
29
30
|
import { runPassiveRead } from "../lib/passive-read";
|
|
@@ -168,6 +169,8 @@ function customWindow(window: ProviderQuotaWindow, source: QuotaPoolSource, upda
|
|
|
168
169
|
|
|
169
170
|
/** A `ProviderQuota` (provider report or per-account cache row). */
|
|
170
171
|
export function providerQuotaWindows(quota: ProviderQuota, source: QuotaPoolSource, now: number): QuotaPoolWindow[] {
|
|
172
|
+
// Display-only readings (Mistral budgets) never become pool capacity or exhaustion evidence.
|
|
173
|
+
if (isDisplayOnlyQuota(quota)) return [];
|
|
171
174
|
const out: QuotaPoolWindow[] = [];
|
|
172
175
|
const push = (window: QuotaPoolWindow | null) => { if (window) out.push(window); };
|
|
173
176
|
const at = quota.updatedAt;
|
|
@@ -311,7 +314,7 @@ function enabled(provider: OcxProviderConfig | undefined): provider is OcxProvid
|
|
|
311
314
|
async function assemble(config: OcxConfig, identity: QuotaPoolIdentity, deps: QuotaPoolDeps): Promise<QuotaPool> {
|
|
312
315
|
const now = (deps.now ?? Date.now)();
|
|
313
316
|
const names = Object.keys(config.providers).filter(name => enabled(config.providers[name])).sort();
|
|
314
|
-
const reports = new Map(heldProviderQuotaReports(
|
|
317
|
+
const reports = new Map(heldProviderQuotaReports(config).reports.map(report => [report.provider, report]));
|
|
315
318
|
const codexPool = hasCodexPoolProvider(config);
|
|
316
319
|
const codex = codexPool ? (await (deps.codexSnapshot ?? listCodexAuthAccountsSnapshot)(config)).accounts : [];
|
|
317
320
|
const providers: QuotaPoolProvider[] = [];
|
|
@@ -22,7 +22,8 @@ const UNSUPPORTED_HOSTED_TOOLS: ReadonlyArray<{
|
|
|
22
22
|
];
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Hosted-tool declaration names an operator may list in `unsupportedHostedTools
|
|
25
|
+
* Hosted-tool declaration names an operator may list in `unsupportedHostedTools` or
|
|
26
|
+
* `unsupportedHostedToolsWithClientTools`.
|
|
26
27
|
*
|
|
27
28
|
* A gateway must be able to deny anything a client can send it, so this is the set of
|
|
28
29
|
* nameless hosted/private declaration types the proxy recognizes on a Responses request.
|
|
@@ -66,17 +67,8 @@ const HOSTED_TOOL_ALIAS_GROUPS: ReadonlyArray<ReadonlySet<string>> = [
|
|
|
66
67
|
|
|
67
68
|
const NO_DECLARED_HOSTED_TOOLS: ReadonlySet<string> = new Set();
|
|
68
69
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
* per-tool predicate stays a set lookup. Returns a shared empty set when the provider
|
|
72
|
-
* declares nothing, keeping the common path allocation-free.
|
|
73
|
-
*/
|
|
74
|
-
export function declaredUnsupportedHostedTools(
|
|
75
|
-
provider?: { unsupportedHostedTools?: readonly string[] },
|
|
76
|
-
): ReadonlySet<string> {
|
|
77
|
-
const declared = provider?.unsupportedHostedTools;
|
|
78
|
-
if (!Array.isArray(declared) || declared.length === 0) return NO_DECLARED_HOSTED_TOOLS;
|
|
79
|
-
const out = new Set<string>();
|
|
70
|
+
function addDeclaredHostedTools(out: Set<string>, declared: readonly string[] | undefined): void {
|
|
71
|
+
if (!Array.isArray(declared)) return;
|
|
80
72
|
for (const raw of declared) {
|
|
81
73
|
if (typeof raw !== "string") continue;
|
|
82
74
|
const tool = raw.trim();
|
|
@@ -87,9 +79,61 @@ export function declaredUnsupportedHostedTools(
|
|
|
87
79
|
for (const alias of group) out.add(alias);
|
|
88
80
|
}
|
|
89
81
|
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Expand a provider's declared denials through the alias groups once per request, so the
|
|
86
|
+
* per-tool predicate stays a set lookup. Returns a shared empty set when the provider
|
|
87
|
+
* declares nothing, keeping the common path allocation-free.
|
|
88
|
+
*
|
|
89
|
+
* `withClientTools` says whether the request being shaped also declares client tools. Only
|
|
90
|
+
* then does `unsupportedHostedToolsWithClientTools` join the unconditional list (#8204);
|
|
91
|
+
* config-time callers leave it false and see the unconditional denials alone.
|
|
92
|
+
*/
|
|
93
|
+
export function declaredUnsupportedHostedTools(
|
|
94
|
+
provider?: {
|
|
95
|
+
unsupportedHostedTools?: readonly string[];
|
|
96
|
+
unsupportedHostedToolsWithClientTools?: readonly string[];
|
|
97
|
+
},
|
|
98
|
+
withClientTools = false,
|
|
99
|
+
): ReadonlySet<string> {
|
|
100
|
+
const declared = provider?.unsupportedHostedTools;
|
|
101
|
+
const conditional = withClientTools ? provider?.unsupportedHostedToolsWithClientTools : undefined;
|
|
102
|
+
const hasDeclared = Array.isArray(declared) && declared.length > 0;
|
|
103
|
+
const hasConditional = Array.isArray(conditional) && conditional.length > 0;
|
|
104
|
+
if (!hasDeclared && !hasConditional) return NO_DECLARED_HOSTED_TOOLS;
|
|
105
|
+
const out = new Set<string>();
|
|
106
|
+
addDeclaredHostedTools(out, declared);
|
|
107
|
+
addDeclaredHostedTools(out, conditional);
|
|
90
108
|
return out.size > 0 ? out : NO_DECLARED_HOSTED_TOOLS;
|
|
91
109
|
}
|
|
92
110
|
|
|
111
|
+
/** A declaration the client executes and answers: a function, a custom tool, or a namespace of them. */
|
|
112
|
+
function isClientToolDeclaration(tool: unknown): boolean {
|
|
113
|
+
if (tool === null || typeof tool !== "object" || Array.isArray(tool)) return false;
|
|
114
|
+
const entry = tool as { type?: unknown; tools?: unknown };
|
|
115
|
+
if (entry.type === "function" || entry.type === "custom") return true;
|
|
116
|
+
return entry.type === "namespace" && Array.isArray(entry.tools) && entry.tools.some(isClientToolDeclaration);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/**
|
|
120
|
+
* Whether a Responses body declares any client tool the upstream will see: in `tools`, in a
|
|
121
|
+
* client-loaded `additional_tools` catalog, or in the definitions a client-executed
|
|
122
|
+
* `tool_search_output` returned. Hosted declarations never count, so stripping them cannot
|
|
123
|
+
* change the answer.
|
|
124
|
+
*/
|
|
125
|
+
export function responsesBodyDeclaresClientTools(body: Record<string, unknown>): boolean {
|
|
126
|
+
if (Array.isArray(body.tools) && body.tools.some(isClientToolDeclaration)) return true;
|
|
127
|
+
if (!Array.isArray(body.input)) return false;
|
|
128
|
+
return body.input.some(item => {
|
|
129
|
+
if (item === null || typeof item !== "object" || Array.isArray(item)) return false;
|
|
130
|
+
const entry = item as { type?: unknown; tools?: unknown };
|
|
131
|
+
return (entry.type === "additional_tools" || entry.type === "tool_search_output")
|
|
132
|
+
&& Array.isArray(entry.tools)
|
|
133
|
+
&& entry.tools.some(isClientToolDeclaration);
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
|
|
93
137
|
/**
|
|
94
138
|
* True when forwarding this hosted tool to the model would be rejected upstream.
|
|
95
139
|
*
|
|
@@ -8,6 +8,14 @@ export interface RetainedCompaction {
|
|
|
8
8
|
reasoning: string[];
|
|
9
9
|
}
|
|
10
10
|
|
|
11
|
+
/** Raised when a proxy-owned retained compaction envelope fails to decode. */
|
|
12
|
+
export class InvalidRetainedCompactionEnvelopeError extends Error {
|
|
13
|
+
constructor() {
|
|
14
|
+
super("Invalid OpenCodex retained compaction envelope");
|
|
15
|
+
this.name = "InvalidRetainedCompactionEnvelopeError";
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
|
|
11
19
|
export function encodeRetainedCompaction(summary: string, reasoning: string[]): string {
|
|
12
20
|
return RETAINED_COMPACTION_PREFIX + Buffer.from(JSON.stringify({ version: 2, summary, reasoning }), "utf-8").toString("base64");
|
|
13
21
|
}
|
|
@@ -28,16 +36,34 @@ export function decodeRetainedCompaction(value: string): RetainedCompaction | nu
|
|
|
28
36
|
} catch { return null; }
|
|
29
37
|
}
|
|
30
38
|
|
|
39
|
+
/** True when `item` carries a proxy-owned retained envelope marker, valid payload or not. */
|
|
40
|
+
function isRetainedCompactionEnvelopeItem(item: unknown): item is { type: string; encrypted_content: string } {
|
|
41
|
+
if (!item || typeof item !== "object") return false;
|
|
42
|
+
const candidate = item as { type?: unknown; encrypted_content?: unknown };
|
|
43
|
+
return typeof candidate.type === "string"
|
|
44
|
+
&& ["compaction", "compaction_summary", "context_compaction"].includes(candidate.type)
|
|
45
|
+
&& typeof candidate.encrypted_content === "string"
|
|
46
|
+
&& candidate.encrypted_content.startsWith(RETAINED_COMPACTION_PREFIX);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** First malformed proxy-owned retained envelope in `input`, if any. */
|
|
50
|
+
export function findInvalidRetainedCompactionEnvelope(input: unknown): InvalidRetainedCompactionEnvelopeError | null {
|
|
51
|
+
if (!Array.isArray(input)) return null;
|
|
52
|
+
for (const item of input) {
|
|
53
|
+
if (!isRetainedCompactionEnvelopeItem(item)) continue;
|
|
54
|
+
if (!decodeRetainedCompaction(item.encrypted_content)) return new InvalidRetainedCompactionEnvelopeError();
|
|
55
|
+
}
|
|
56
|
+
return null;
|
|
57
|
+
}
|
|
58
|
+
|
|
31
59
|
/** Expand only our structured envelopes; callers retain their existing native/ocx1 policy. */
|
|
32
60
|
export function expandRetainedCompactionInput(input: unknown): unknown {
|
|
33
61
|
if (!Array.isArray(input)) return input;
|
|
34
|
-
if (!input.some(
|
|
35
|
-
&& typeof item.encrypted_content === "string" && item.encrypted_content.startsWith(RETAINED_COMPACTION_PREFIX))) return input;
|
|
62
|
+
if (!input.some(isRetainedCompactionEnvelopeItem)) return input;
|
|
36
63
|
return input.flatMap(item => {
|
|
37
|
-
if (!item
|
|
38
|
-
|| typeof item.encrypted_content !== "string" || !item.encrypted_content.startsWith(RETAINED_COMPACTION_PREFIX)) return [item];
|
|
64
|
+
if (!isRetainedCompactionEnvelopeItem(item)) return [item];
|
|
39
65
|
const data = decodeRetainedCompaction(item.encrypted_content);
|
|
40
|
-
if (!data) throw new
|
|
66
|
+
if (!data) throw new InvalidRetainedCompactionEnvelopeError();
|
|
41
67
|
return [
|
|
42
68
|
{ ...item, encrypted_content: "ocx1:" + Buffer.from(data.summary, "utf-8").toString("base64") },
|
|
43
69
|
...data.reasoning.map(text => ({ type: "message", role: "user", content: [{ type: "input_text", text }] })),
|
package/src/router.ts
CHANGED
|
@@ -14,6 +14,7 @@ import {
|
|
|
14
14
|
import type { NormalizedComboConfig } from "./combos/types";
|
|
15
15
|
import { hasOwnProvider } from "./config/provider-name";
|
|
16
16
|
import { anthropicInstanceRowShapeMatches } from "./providers/anthropic-instance-id";
|
|
17
|
+
import { isProviderApiKeyPaused } from "./providers/api-key-pause";
|
|
17
18
|
import { reconcileRouterWarningMemos, routedProviderConfig } from "./providers/routed-config";
|
|
18
19
|
import { assertProviderDestinationAllowed } from "./lib/destination-policy";
|
|
19
20
|
import {
|
|
@@ -317,6 +318,7 @@ function crossProviderRedirectTarget(config: OcxConfig, providerName: string, va
|
|
|
317
318
|
);
|
|
318
319
|
return usable ? value : undefined;
|
|
319
320
|
}
|
|
321
|
+
if (isProviderApiKeyPaused(effective)) return undefined;
|
|
320
322
|
return authMode === "local" || effective.keyOptional === true || Boolean(effective.apiKey?.trim())
|
|
321
323
|
|| (authMode === "key" && effective.adapter === "google" && effective.googleMode === "vertex")
|
|
322
324
|
? value : undefined;
|
package/src/server/auth-cors.ts
CHANGED
|
@@ -51,6 +51,7 @@ import { googleVertexLocationConfigError } from "../providers/google-vertex-loca
|
|
|
51
51
|
import { xaiResponsesOptInState } from "../providers/xai-responses-opt-in";
|
|
52
52
|
import { authorizationCredential } from "../lib/authorization-scheme";
|
|
53
53
|
import { noteTurnStateCaller } from "./turn-state-handles";
|
|
54
|
+
import { providerModelDiscoveryConfigError } from "../providers/model-discovery-config";
|
|
54
55
|
|
|
55
56
|
let _corsOrigin = "http://localhost:10100";
|
|
56
57
|
// Listener identity is process-local. Never infer this trust from forwarded headers: the
|
|
@@ -993,24 +994,24 @@ export function providerManagementConfigError(
|
|
|
993
994
|
if (jsonSchemaOptOutError) return `provider ${name} ${jsonSchemaOptOutError}`;
|
|
994
995
|
const retainModelsError = nonBlankStringArrayConfigError(raw.retainModels, "retainModels");
|
|
995
996
|
if (retainModelsError) return `provider ${name} ${retainModelsError}`;
|
|
997
|
+
const modelDiscoveryError = providerModelDiscoveryConfigError(raw.modelDiscovery);
|
|
998
|
+
if (modelDiscoveryError) return `provider ${JSON.stringify(redactSecretString(name))} ${modelDiscoveryError}`;
|
|
996
999
|
const toolReasoningOptOutError = nonBlankStringArrayConfigError(
|
|
997
1000
|
raw.omitReasoningEffortWithToolsModels,
|
|
998
1001
|
"omitReasoningEffortWithToolsModels",
|
|
999
1002
|
);
|
|
1000
1003
|
if (toolReasoningOptOutError) return `provider ${name} ${toolReasoningOptOutError}`;
|
|
1001
|
-
const
|
|
1002
|
-
raw
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
if (unsupportedHostedToolsError) return `provider ${name} ${unsupportedHostedToolsError}`;
|
|
1006
|
-
if (Array.isArray(raw.unsupportedHostedTools)) {
|
|
1004
|
+
for (const field of ["unsupportedHostedTools", "unsupportedHostedToolsWithClientTools"] as const) {
|
|
1005
|
+
const hostedToolsError = nonBlankStringArrayConfigError(raw[field], field);
|
|
1006
|
+
if (hostedToolsError) return `provider ${name} ${hostedToolsError}`;
|
|
1007
|
+
if (!Array.isArray(raw[field])) continue;
|
|
1007
1008
|
// Closed vocabulary, same reason as the config schema: an unrecognized name would be
|
|
1008
1009
|
// stored and then strip nothing, so the operator would keep getting the upstream 400
|
|
1009
1010
|
// this field exists to prevent.
|
|
1010
|
-
const unknownTool = (raw
|
|
1011
|
+
const unknownTool = (raw[field] as unknown[])
|
|
1011
1012
|
.find(tool => typeof tool === "string" && !DECLARABLE_HOSTED_TOOL_TYPES.has(tool.trim()));
|
|
1012
1013
|
if (unknownTool !== undefined) {
|
|
1013
|
-
return `provider ${name}
|
|
1014
|
+
return `provider ${name} ${field} must name only hosted tool types: `
|
|
1014
1015
|
+ `${[...DECLARABLE_HOSTED_TOOL_TYPES].join(", ")}`;
|
|
1015
1016
|
}
|
|
1016
1017
|
}
|
|
@@ -1136,6 +1137,7 @@ const PROVIDER_CONFIG_FIELD_POLICY = {
|
|
|
1136
1137
|
defaultModel: "editor",
|
|
1137
1138
|
models: "editor",
|
|
1138
1139
|
liveModels: "editor",
|
|
1140
|
+
modelDiscovery: "editor",
|
|
1139
1141
|
selectedModels: "editor",
|
|
1140
1142
|
initialModelSelection: "runtime",
|
|
1141
1143
|
retainModels: "editor",
|
|
@@ -1190,6 +1192,7 @@ const PROVIDER_CONFIG_FIELD_POLICY = {
|
|
|
1190
1192
|
zaiResponsesDefaultVersion: "runtime",
|
|
1191
1193
|
supportsResponsesCustomTools: "editor",
|
|
1192
1194
|
unsupportedHostedTools: "editor",
|
|
1195
|
+
unsupportedHostedToolsWithClientTools: "editor",
|
|
1193
1196
|
responsesSnapshotRepair: "editor",
|
|
1194
1197
|
webSearchBridge: "editor",
|
|
1195
1198
|
reasoningEffortMap: "editor",
|
|
@@ -10,7 +10,9 @@
|
|
|
10
10
|
* If each route serialized independently they would drift, and the data-plane
|
|
11
11
|
* copy is the one nobody looks at in the dashboard.
|
|
12
12
|
*/
|
|
13
|
-
import {
|
|
13
|
+
import { catalogEtag } from "../lib/catalog-etag";
|
|
14
|
+
|
|
15
|
+
export { catalogEtag };
|
|
14
16
|
|
|
15
17
|
/**
|
|
16
18
|
* Upper bound for the REMOTE route only.
|
|
@@ -37,10 +39,6 @@ export interface SerializedCatalog {
|
|
|
37
39
|
bytes?: number;
|
|
38
40
|
}
|
|
39
41
|
|
|
40
|
-
export function catalogEtag(body: string): string {
|
|
41
|
-
return `"${createHash("sha256").update(body).digest("hex")}"`;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
42
|
/**
|
|
45
43
|
* Read and serialize the persisted catalog once.
|
|
46
44
|
*
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { recordUpstreamProviderErrorDetail } from "./request-log-failure-detail";
|
|
2
2
|
import { normalizeNativeChatContent } from "../adapters/openai-chat/native-content";
|
|
3
3
|
import { attachComboFailureEvidence, ownedChatErrorPayload, type ClientErrorContract } from "../lib/client-error-body";
|
|
4
4
|
import type { FailureVerdictSink } from "../chat/failure-verdict";
|
|
@@ -68,6 +68,7 @@ import { fastPolicyForModel } from "../providers/service-tier";
|
|
|
68
68
|
import { RequestPacingQueueOverloadError } from "../providers/request-pacing";
|
|
69
69
|
import { stampApiKeyAccountLabel } from "../providers/label";
|
|
70
70
|
import { distributedKeyPhysicalFetch, distributedKeyResponseOwner } from "../providers/api-key-response-ownership";
|
|
71
|
+
import { isProviderApiKeyPaused, ProviderApiKeyPausedError } from "../providers/api-key-pause";
|
|
71
72
|
import { providerApiKeySelectionIsCurrent, resolveCurrentProviderApiKeyTransport } from "../providers/api-key-selection";
|
|
72
73
|
import type { OcxProviderTransport } from "../providers/xai-transport";
|
|
73
74
|
import type { RouteResult } from "../router";
|
|
@@ -359,8 +360,12 @@ export async function runNativeChatAttempt(
|
|
|
359
360
|
try {
|
|
360
361
|
const proactiveKeyProvider = selectProactiveApiKeyTransport(config, route.providerName, route.provider);
|
|
361
362
|
if (proactiveKeyProvider) route.provider = proactiveKeyProvider;
|
|
363
|
+
if (isProviderApiKeyPaused(route.provider)) throw new ProviderApiKeyPausedError();
|
|
362
364
|
} catch (error) {
|
|
363
365
|
cleanupAbort(); upstream.abort();
|
|
366
|
+
if (error instanceof ProviderApiKeyPausedError) {
|
|
367
|
+
return failLocal(403, error.message, "permission_error");
|
|
368
|
+
}
|
|
364
369
|
if (!(error instanceof RequestPacingQueueOverloadError)) throw error;
|
|
365
370
|
const refusal = failLocal(429, error.message, "rate_limit_error");
|
|
366
371
|
const advice = formatClientRetryAfter(error.retryAfterSeconds);
|
|
@@ -526,6 +531,7 @@ export async function runNativeChatAttempt(
|
|
|
526
531
|
if (fresh) current = selectProactiveApiKeyTransport(config, route.providerName, fresh) ?? fresh;
|
|
527
532
|
}
|
|
528
533
|
if (!current || !isNativeChatRouteEligible({ ...route, provider: current }, execution.chatBody, config)) {
|
|
534
|
+
if (!current && isProviderApiKeyPaused(config.providers[route.providerName])) throw new ProviderApiKeyPausedError();
|
|
529
535
|
throw new Error("Provider key selection is no longer available for native Chat");
|
|
530
536
|
}
|
|
531
537
|
activeProvider = current;
|
|
@@ -699,6 +705,9 @@ export async function runNativeChatAttempt(
|
|
|
699
705
|
upstream.abort();
|
|
700
706
|
if (req.signal.aborted) return failLocal(499, "Client cancelled request", "client_cancelled");
|
|
701
707
|
const sendError = error instanceof UpstreamRetryEvidenceError ? error.cause : error;
|
|
708
|
+
if (sendError instanceof ProviderApiKeyPausedError) {
|
|
709
|
+
return failLocal(403, sendError.message, "permission_error");
|
|
710
|
+
}
|
|
702
711
|
if (sendError instanceof RequestPacingQueueOverloadError) {
|
|
703
712
|
const refusal = failLocal(429, sendError.message, "rate_limit_error");
|
|
704
713
|
const advice = formatClientRetryAfter(sendError.retryAfterSeconds);
|
|
@@ -745,7 +754,7 @@ export async function runNativeChatAttempt(
|
|
|
745
754
|
let upstreamMessage: string | undefined;
|
|
746
755
|
try {
|
|
747
756
|
const parsedError = JSON.parse(bodyText) as Rec;
|
|
748
|
-
|
|
757
|
+
recordUpstreamProviderErrorDetail(logCtx, response.status, parsedError);
|
|
749
758
|
const nested = isRec(parsedError.error) ? parsedError.error : undefined;
|
|
750
759
|
const details = nested ?? parsedError;
|
|
751
760
|
if (typeof details.type === "string") upstreamType = details.type;
|
|
@@ -1314,7 +1314,8 @@ async function handleClaudeMessagesWithBudget(
|
|
|
1314
1314
|
anthropicSystemCachePrefix: isRec(anthropicBody) ? systemCachePrefix(anthropicBody.system) : undefined,
|
|
1315
1315
|
// Preserve the original catalog through late fallback; only the physical adapter projects it.
|
|
1316
1316
|
anthropicToolLoadingSource: cacheKeySource === "metadata" && isRec(anthropicBody)
|
|
1317
|
-
&& Array.isArray(cc?.appendOnlyToolLoadingModels) && cc.appendOnlyToolLoadingModels.length > 0
|
|
1317
|
+
&& ((Array.isArray(cc?.appendOnlyToolLoadingModels) && cc.appendOnlyToolLoadingModels.length > 0)
|
|
1318
|
+
|| (Array.isArray(cc?.chatToolDispatchModels) && cc.chatToolDispatchModels.length > 0))
|
|
1318
1319
|
? { tools: anthropicBody.tools, messages: anthropicBody.messages, tool_choice: anthropicBody.tool_choice } : undefined,
|
|
1319
1320
|
claudeGoAffinity: { sessionLane: claudeGoSessionLane },
|
|
1320
1321
|
claudeNativeSessionId,
|
package/src/server/images.ts
CHANGED
|
@@ -32,6 +32,8 @@ import { sidecarEnter } from "../lib/sidecar-tracker";
|
|
|
32
32
|
import { isNonReplayableResponse } from "../lib/upstream-retry";
|
|
33
33
|
import type { OcxConfig } from "../types";
|
|
34
34
|
import { resolveFirstUsableOpenAiSidecar, selectImagesProvider } from "../providers/openai-sidecar";
|
|
35
|
+
import { isProviderApiKeyPaused, ProviderApiKeyPausedError } from "../providers/api-key-pause";
|
|
36
|
+
import { resolveCurrentProviderApiKeyTransport } from "../providers/api-key-selection";
|
|
35
37
|
import { recordDistributedKeyFailure, selectProactiveApiKeyTransport } from "../providers/key-failover";
|
|
36
38
|
import { requestPacingOverloadResponse } from "./responses/pacing-overload";
|
|
37
39
|
import { getProviderRegistryEntry } from "../providers/registry";
|
|
@@ -669,8 +671,8 @@ export async function handleImages(
|
|
|
669
671
|
const xaiRelay = await tryXaiImageRelay(body, config, logCtx, req.signal, endpoint, admission);
|
|
670
672
|
if (xaiRelay) return xaiRelay;
|
|
671
673
|
}
|
|
672
|
-
if (candidates.error) {
|
|
673
|
-
return formatErrorResponse(400, "invalid_request_error", candidates.error);
|
|
674
|
+
if (candidates.error && (config.images?.provider !== undefined || !candidates.paused)) {
|
|
675
|
+
return formatErrorResponse(candidates.paused ? 403 : 400, candidates.paused ? "permission_error" : "invalid_request_error", candidates.error);
|
|
674
676
|
}
|
|
675
677
|
const explicitKeyedProvider = config.images?.provider !== undefined && candidates.keyed !== undefined;
|
|
676
678
|
// Admission bearer is valid proxy auth (requireApiAuth already passed) but must never be
|
|
@@ -709,6 +711,9 @@ export async function handleImages(
|
|
|
709
711
|
const ccaResponse = await tryCcaImageGeneration(body, config, logCtx, req.signal, endpoint, admission);
|
|
710
712
|
if (ccaResponse) return ccaResponse;
|
|
711
713
|
if (forwardScopeDenial) return forwardScopeDenial;
|
|
714
|
+
if (candidates.paused) {
|
|
715
|
+
return formatErrorResponse(403, "permission_error", candidates.error ?? new ProviderApiKeyPausedError().message);
|
|
716
|
+
}
|
|
712
717
|
// 400, not 5xx: codex retries every 5xx up to 5 total attempts, and this is a permanent
|
|
713
718
|
// configuration state that must surface on the first attempt.
|
|
714
719
|
return formatErrorResponse(
|
|
@@ -812,27 +817,47 @@ export async function handleImages(
|
|
|
812
817
|
// Transport variant: this branch reads `provider.baseUrl` and `provider.headers` to build
|
|
813
818
|
// the URL and the request, and it comes back with the credential already resolved.
|
|
814
819
|
let warmKeyProvider;
|
|
815
|
-
|
|
816
|
-
|
|
820
|
+
let currentKeyProvider;
|
|
821
|
+
try {
|
|
822
|
+
warmKeyProvider = selectProactiveApiKeyTransport(config, providerName, candidates.keyed.provider);
|
|
823
|
+
currentKeyProvider = warmKeyProvider ?? resolveCurrentProviderApiKeyTransport(
|
|
824
|
+
config,
|
|
825
|
+
providerName,
|
|
826
|
+
{ ...candidates.keyed.provider, _apiKeyAttempt: undefined },
|
|
827
|
+
);
|
|
828
|
+
if (isProviderApiKeyPaused(currentKeyProvider ?? config.providers[providerName])) {
|
|
829
|
+
throw new ProviderApiKeyPausedError();
|
|
830
|
+
}
|
|
831
|
+
} catch (error) {
|
|
832
|
+
if (error instanceof ProviderApiKeyPausedError) {
|
|
833
|
+
if (config.images?.provider === undefined) {
|
|
834
|
+
const ccaResponse = await tryCcaImageGeneration(body, config, logCtx, req.signal, endpoint, admission);
|
|
835
|
+
if (ccaResponse) return ccaResponse;
|
|
836
|
+
}
|
|
837
|
+
return formatErrorResponse(403, "permission_error", error.message);
|
|
838
|
+
}
|
|
839
|
+
if (error instanceof OAuthAccountPausedError) {
|
|
840
|
+
return formatErrorResponse(403, "permission_error", error.message);
|
|
841
|
+
}
|
|
817
842
|
const refusal = requestPacingOverloadResponse(error);
|
|
818
843
|
if (refusal) return refusal;
|
|
819
844
|
throw error;
|
|
820
845
|
}
|
|
821
|
-
const provider =
|
|
822
|
-
|
|
823
|
-
// No fall back to the earlier snapshot once a pick has happened. The picker COMMITS its
|
|
824
|
-
// choice before returning, so if the chosen reference will not resolve -- revoked keychain
|
|
825
|
-
// entry, unset env var -- sending the previous key would authenticate a non-idempotent
|
|
826
|
-
// POST with a credential the config no longer considers active, and the previous key is
|
|
827
|
-
// the one that was cooling. Fail loudly instead.
|
|
828
|
-
if (warmKeyProvider && !warmKeyProvider.apiKey?.trim()) {
|
|
846
|
+
const provider = currentKeyProvider;
|
|
847
|
+
if (!provider || !provider.apiKey?.trim()) {
|
|
829
848
|
return formatErrorResponse(
|
|
830
849
|
500,
|
|
831
850
|
"configuration_error",
|
|
832
851
|
`image generation selected an API key for "${providerName}" that cannot be resolved`,
|
|
833
852
|
);
|
|
834
853
|
}
|
|
835
|
-
|
|
854
|
+
recordKeyFailure = (status, retryAfter) => { recordDistributedKeyFailure(config, providerName, provider._apiKeyAttempt, status, Date.now(), retryAfter); };
|
|
855
|
+
// No fall back to the earlier snapshot once a pick has happened. The picker COMMITS its
|
|
856
|
+
// choice before returning, so if the chosen reference will not resolve -- revoked keychain
|
|
857
|
+
// entry, unset env var -- sending the previous key would authenticate a non-idempotent
|
|
858
|
+
// POST with a credential the config no longer considers active, and the previous key is
|
|
859
|
+
// the one that was cooling. Fail loudly instead.
|
|
860
|
+
const apiKey = provider.apiKey;
|
|
836
861
|
try {
|
|
837
862
|
for (const [name, value] of Object.entries(provider.headers ?? {})) headers.set(name, value);
|
|
838
863
|
headers.set("authorization", `Bearer ${apiKey}`);
|
|
@@ -847,6 +872,9 @@ export async function handleImages(
|
|
|
847
872
|
// No usable OpenAI credential — try CCA before giving up.
|
|
848
873
|
const ccaResponse = await tryCcaImageGeneration(body, config, logCtx, req.signal, endpoint, admission);
|
|
849
874
|
if (ccaResponse) return ccaResponse;
|
|
875
|
+
if (candidates.paused) {
|
|
876
|
+
return formatErrorResponse(403, "permission_error", candidates.error ?? new ProviderApiKeyPausedError().message);
|
|
877
|
+
}
|
|
850
878
|
return formatErrorResponse(
|
|
851
879
|
401,
|
|
852
880
|
"authentication_error",
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { createLinkRelaySessions } from "./link-relay-sessions";
|
|
1
|
+
import { createLinkRelaySessions, type LinkCatalogServed } from "./link-relay-sessions";
|
|
2
2
|
import { createLinkPeerObservations, type LinkPeerEntry } from "../../link/peer-report";
|
|
3
|
+
import { createLinkActivity, type LinkActivitySnapshot } from "../../link/child-activity";
|
|
3
4
|
import type { Server } from "bun";
|
|
4
5
|
import {
|
|
5
6
|
emptyLinkStore,
|
|
@@ -57,6 +58,10 @@ export interface LinkListenerLifecycle<T> {
|
|
|
57
58
|
notifyAuthenticatedCatalog(apiKeyId: string): void;
|
|
58
59
|
/** What this Home last learned of a Child over the link; empty until it relays a request. */
|
|
59
60
|
peerObservation(linkId: string): LinkPeerEntry;
|
|
61
|
+
/** Relayed model traffic for one link (D5); legacy key admissions count against every link. */
|
|
62
|
+
linkActivity(linkId: string, now: number): LinkActivitySnapshot;
|
|
63
|
+
/** A Child read a whole 200 `GET /v1/catalog` body through the relay. */
|
|
64
|
+
onCatalogServed(listener: (served: LinkCatalogServed) => void): () => void;
|
|
60
65
|
status(): LinkListenerStatus;
|
|
61
66
|
close(): Promise<void>;
|
|
62
67
|
stop(): Promise<void>;
|
|
@@ -81,8 +86,11 @@ export function createLinkListenerLifecycle<T>(deps: LinkListenerDeps = {}): Lin
|
|
|
81
86
|
let closeFlight: Promise<void> | undefined;
|
|
82
87
|
let stopped = false;
|
|
83
88
|
const authenticatedCatalogListeners = new Set<(apiKeyId: string) => void>();
|
|
89
|
+
const catalogServedListeners = new Set<(served: LinkCatalogServed) => void>();
|
|
84
90
|
let lifecycleStatus: LinkListenerStatus = { state: "off", port: null, reason: null };
|
|
85
91
|
const peers = createLinkPeerObservations();
|
|
92
|
+
// Lifecycle-owned so a rebind keeps the book.
|
|
93
|
+
const activity = createLinkActivity();
|
|
86
94
|
|
|
87
95
|
const setStatus = (state: LinkListenerStatus["state"], port: number | null, reason: string | null): void => {
|
|
88
96
|
lifecycleStatus = { state, port, reason };
|
|
@@ -114,7 +122,8 @@ export function createLinkListenerLifecycle<T>(deps: LinkListenerDeps = {}): Lin
|
|
|
114
122
|
return;
|
|
115
123
|
}
|
|
116
124
|
const requestedPort = store.listenerPort ?? 0;
|
|
117
|
-
const sessions = createLinkRelaySessions({ peers, connectionGeneration: linkId => startContext?.connectionGeneration?.(linkId),
|
|
125
|
+
const sessions = createLinkRelaySessions({ peers, activity, connectionGeneration: linkId => startContext?.connectionGeneration?.(linkId),
|
|
126
|
+
catalogServed: served => { for (const listener of catalogServedListeners) listener(served); }, fingerprints: (keyId, linkId) => {
|
|
118
127
|
if (!readStoreForAdmission().links.some(link => link.id === linkId && link.apiKeyId === keyId)) return [];
|
|
119
128
|
return startContext?.keyFingerprints?.(keyId) ?? [];
|
|
120
129
|
} });
|
|
@@ -225,6 +234,11 @@ export function createLinkListenerLifecycle<T>(deps: LinkListenerDeps = {}): Lin
|
|
|
225
234
|
for (const listener of authenticatedCatalogListeners) listener(apiKeyId);
|
|
226
235
|
},
|
|
227
236
|
peerObservation: linkId => peers.get(linkId),
|
|
237
|
+
linkActivity: (linkId, now) => activity.snapshot(linkId, now),
|
|
238
|
+
onCatalogServed(listener) {
|
|
239
|
+
catalogServedListeners.add(listener);
|
|
240
|
+
return () => { catalogServedListeners.delete(listener); };
|
|
241
|
+
},
|
|
228
242
|
status() {
|
|
229
243
|
return { ...lifecycleStatus };
|
|
230
244
|
},
|