@bitkyc08/opencodex 2.96.0 → 2.97.0
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/bin/ocx.mjs +214 -19
- package/gui/dist/assets/{App-bwugJRKn.js → App-DuNhggE1.js} +15 -15
- package/gui/dist/assets/{Tray-BOPQyDbH.js → Tray-CEw0y0jR.js} +1 -1
- package/gui/dist/assets/index-CynE_Rue.js +94 -0
- package/gui/dist/assets/{quota-summary-6HsrHQAy.js → quota-summary-VHFSlUuM.js} +1 -1
- package/gui/dist/index.html +1 -1
- package/package.json +1 -1
- package/src/adapters/command-code.ts +15 -16
- package/src/adapters/cursor/transport-retry.ts +2 -2
- package/src/adapters/devin/cloud-direct/chat.ts +15 -6
- package/src/adapters/kiro/stream.ts +63 -4
- package/src/adapters/kiro-constants.ts +15 -1
- package/src/adapters/kiro-events.ts +31 -1
- package/src/adapters/kiro-retry.ts +3 -3
- package/src/adapters/ollama-native.ts +11 -1
- package/src/adapters/openai-responses/empty-assistant.ts +15 -3
- package/src/adapters/openai-responses/passthrough.ts +5 -4
- package/src/adapters/openai-responses/reasoning.ts +9 -4
- package/src/adapters/openai-responses/request-strips.ts +1 -1
- package/src/adapters/physical-send.ts +3 -3
- package/src/adapters/zed-openai-stream.ts +2 -1
- package/src/bridge/errors.ts +11 -2
- package/src/bridge/response-json.ts +2 -1
- package/src/bridge/sse.ts +14 -6
- package/src/chat/failure-verdict.ts +21 -0
- package/src/chat/outbound.ts +139 -21
- package/src/claude/outbound.ts +49 -2
- package/src/cli/capabilities-base.ts +25 -3
- package/src/cli/capabilities-command.ts +12 -3
- package/src/cli/capability-contracts.ts +2 -0
- package/src/cli/codex-launch-auth.ts +30 -1
- package/src/cli/codex-launcher.ts +12 -5
- package/src/cli/codex-shim-autorestore.ts +5 -4
- package/src/cli/dispatch.ts +11 -176
- package/src/cli/help.ts +2 -2
- package/src/cli/index.ts +5 -1
- package/src/cli/link.ts +1 -1
- package/src/cli/registry.ts +11 -3
- package/src/cli/root.ts +8 -0
- package/src/cli/sync-command.ts +243 -0
- package/src/cli/sync-fanout-process.ts +92 -0
- package/src/cli/sync-fanout.ts +150 -0
- package/src/cli/sync-flags.ts +10 -0
- package/src/cli/sync-link-status.ts +39 -0
- package/src/cli/sync-update-guard.ts +18 -0
- package/src/client/connect.ts +31 -14
- package/src/client/link-home.ts +3 -2
- package/src/client/machine-listener.ts +3 -0
- package/src/client/restore-ownership.ts +19 -1
- package/src/client/runtime-restart.ts +12 -4
- package/src/client/runtime.ts +40 -11
- package/src/client/stop-routing.ts +62 -0
- package/src/client/sync-runtime.ts +65 -0
- package/src/clients/config-export.ts +32 -3
- package/src/codex/auth-context.ts +49 -103
- package/src/codex/catalog/antigravity-discovery.ts +16 -5
- package/src/codex/catalog/provider-models.ts +6 -8
- package/src/codex/forward-transport-headers.ts +35 -6
- package/src/codex/inject/config-toml.ts +88 -0
- package/src/codex/inject/multi-agent-v2.ts +30 -4
- package/src/codex/inject/plan.ts +34 -7
- package/src/codex/inject-coordination.ts +11 -0
- package/src/codex/inject.ts +18 -7
- package/src/codex/lineage.ts +13 -7
- package/src/codex/quota.ts +22 -6
- package/src/codex/request-owned-affinity-key.ts +11 -0
- package/src/codex/request-owned-affinity.ts +118 -0
- package/src/codex/request-owned-main-pin.ts +86 -0
- package/src/codex/role-capability.ts +52 -41
- package/src/codex/routing/active-account.ts +13 -5
- package/src/codex/routing/selection.ts +40 -1
- package/src/codex/routing/thread-affinity-store.ts +916 -0
- package/src/codex/routing/thread-affinity.ts +90 -12
- package/src/codex/toml-source-lines.ts +72 -13
- package/src/combos/failover.ts +6 -109
- package/src/combos/request.ts +2 -2
- package/src/combos/resolve.ts +29 -11
- package/src/config/process-state.ts +5 -0
- package/src/config/schema/leaf-validators.ts +1 -0
- package/src/generated/compatibility-version.json +433 -165
- package/src/images/loop.ts +2 -1
- package/src/lib/client-error-body.ts +184 -0
- package/src/lib/client-retry-after.ts +66 -0
- package/src/lib/config-ownership.ts +4 -0
- package/src/lib/context-overflow-verdict.ts +113 -0
- package/src/lib/desktop-cli-handoff.d.mts +1 -1
- package/src/lib/desktop-cli-handoff.mjs +11 -1
- package/src/lib/empty-tool-catalog.ts +25 -3
- package/src/lib/error-destination.ts +47 -0
- package/src/lib/failure-detail.ts +66 -0
- package/src/lib/model-identity.ts +44 -0
- package/src/lib/private-sqlite-path.ts +124 -0
- package/src/lib/response-service-tier.ts +17 -0
- package/src/lib/retry-after.ts +3 -0
- package/src/lib/spend-ledger-owner.ts +43 -4
- package/src/lib/upstream-condition.ts +142 -0
- package/src/lib/upstream-retry.ts +14 -11
- package/src/lib/windows-owner-acl.ts +13 -6
- package/src/link/remote-platform.ts +14 -0
- package/src/link/remote-windows.ts +51 -9
- package/src/link/ssh-argv.ts +63 -10
- package/src/oauth/generic-account-failover.ts +13 -11
- package/src/oauth/index.ts +36 -74
- package/src/oauth/oauth-errors.ts +67 -0
- package/src/oauth/store.ts +1 -1
- package/src/protocols/codecs/ollama.ts +197 -0
- package/src/protocols/encoders/adapter-events.ts +4 -0
- package/src/protocols/encoders/chat.ts +18 -10
- package/src/protocols/trace.ts +18 -0
- package/src/providers/fastwire.ts +3 -2
- package/src/providers/quota/anthropic-usage-windows.ts +13 -3
- package/src/providers/quota/vendor-probes-key.ts +60 -24
- package/src/providers/request-pacing.ts +3 -2
- package/src/responses/apply-patch-envelope.ts +45 -19
- package/src/responses/compaction-history-framing.ts +5 -1
- package/src/responses/freeform-wrapper-scan.ts +5 -3
- package/src/responses/progressive-freeform-input.ts +354 -45
- package/src/routing/fallback-policy.ts +3 -1
- package/src/server/admission-model-scope.ts +17 -6
- package/src/server/admitted-http-turn.ts +56 -0
- package/src/server/auth-cors.ts +5 -0
- package/src/server/chat-completions.ts +45 -20
- package/src/server/chat-native-sse.ts +52 -7
- package/src/server/chat-native.ts +60 -35
- package/src/server/claude-bridge-pool-session.ts +59 -0
- package/src/server/claude-messages.ts +51 -24
- package/src/server/context-history.ts +5 -1
- package/src/server/inbound-body-admission.ts +11 -4
- package/src/server/index/ollama-routes.ts +89 -0
- package/src/server/index/serve-options.ts +21 -4
- package/src/server/index/websocket-handler.ts +4 -2
- package/src/server/index.ts +6 -36
- package/src/server/inference/client-encoder-delivery.ts +4 -2
- package/src/server/json-serialized-bytes.ts +44 -0
- package/src/server/management/agent-settings-routes.ts +24 -21
- package/src/server/management/codex-cli-update-routes.ts +2 -1
- package/src/server/management/route-registry.ts +1 -1
- package/src/server/messages-native-scope.ts +2 -1
- package/src/server/messages-native-tool-guard.ts +1 -1
- package/src/server/messages-native.ts +12 -7
- package/src/server/messages-shared.ts +6 -2
- package/src/server/native-final-log.ts +93 -0
- package/src/server/ollama-inbound.ts +349 -0
- package/src/server/ollama-native-paths.ts +21 -0
- package/src/server/ollama-route-policy.ts +73 -0
- package/src/server/relay.ts +22 -3
- package/src/server/request-decompress.ts +4 -2
- package/src/server/request-log-failure-attribution.ts +22 -0
- package/src/server/request-log-failure-detail.ts +80 -0
- package/src/server/request-log-terminal-status.ts +4 -2
- package/src/server/request-log.ts +79 -42
- package/src/server/response-log-body.ts +6 -1
- package/src/server/responses/account-change-state.ts +17 -6
- package/src/server/responses/adapter-continuation.ts +9 -4
- package/src/server/responses/adapter-delivery.ts +5 -4
- package/src/server/responses/adapter-dispatch.ts +31 -30
- package/src/server/responses/anthropic-thinking-recovery.ts +3 -0
- package/src/server/responses/codex-auth-error.ts +19 -18
- package/src/server/responses/codex-ws-exchange.ts +11 -8
- package/src/server/responses/codex-ws-metadata.ts +94 -21
- package/src/server/responses/codex-ws-request.ts +3 -1
- package/src/server/responses/compact.ts +53 -23
- package/src/server/responses/compaction-recovery.ts +4 -2
- package/src/server/responses/compaction-routing.ts +9 -4
- package/src/server/responses/core-auth.ts +32 -14
- package/src/server/responses/core-codex-account.ts +17 -6
- package/src/server/responses/core-combo-failure.ts +5 -1
- package/src/server/responses/core-combo-native.ts +2 -1
- package/src/server/responses/core-combo.ts +41 -27
- package/src/server/responses/core-errors.ts +22 -20
- package/src/server/responses/core-lifetime.ts +6 -3
- package/src/server/responses/core-normalize.ts +1 -0
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-pipeline.ts +4 -3
- package/src/server/responses/fetch-helpers.ts +7 -1
- package/src/server/responses/input-admission.ts +28 -2
- package/src/server/responses/native-injection.ts +1 -1
- package/src/server/responses/native-response-json.ts +13 -4
- package/src/server/responses/native-response-output.ts +1 -2
- package/src/server/responses/non-replayable-error.ts +2 -1
- package/src/server/responses/pacing-overload.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +55 -14
- package/src/server/responses/passthrough-dispatch.ts +19 -17
- package/src/server/responses/passthrough-error.ts +9 -9
- package/src/server/responses/policy-fallback.ts +2 -1
- package/src/server/responses/request-prepare.ts +67 -48
- package/src/server/responses/request-transport.ts +35 -31
- package/src/server/responses/run-turn-execution.ts +6 -6
- package/src/server/responses/sidecar-execution.ts +16 -12
- package/src/server/responses/spend-storage-error.ts +2 -1
- package/src/server/responses/ws-upstream.ts +9 -0
- package/src/server/responses-custom-tool-repair.ts +14 -3
- package/src/server/responses-terminal-repair.ts +5 -2
- package/src/server/responses-undeclared-tool-guard.ts +39 -16
- package/src/server/safe-response-headers.ts +162 -13
- package/src/server/turn-state-handles.ts +164 -0
- package/src/server/workflow-refusal.ts +2 -1
- package/src/service/ownership-mutation-lease.d.mts +11 -2
- package/src/service/ownership-mutation-lease.mjs +53 -11
- package/src/types/config.ts +2 -0
- package/src/update/index.ts +133 -25
- package/src/update/npm-install.d.mts +8 -0
- package/src/update/npm-install.mjs +20 -1
- package/src/update/orchestrated-admission.d.mts +4 -0
- package/src/update/orchestrated-admission.mjs +12 -0
- package/src/update/orchestrated-arguments.d.mts +12 -0
- package/src/update/orchestrated-arguments.mjs +64 -0
- package/src/update/orchestrated-child.d.mts +12 -0
- package/src/update/orchestrated-child.mjs +70 -0
- package/src/update/orchestrated-entry.ts +234 -0
- package/src/update/orchestrated-identity-probe-entry.ts +20 -0
- package/src/update/orchestrated-identity.ts +53 -0
- package/src/update/orchestrated-live-identity.ts +48 -0
- package/src/update/orchestrated-node-driver.mjs +99 -0
- package/src/update/orchestrated-outcome.d.mts +21 -0
- package/src/update/orchestrated-outcome.mjs +40 -0
- package/src/update/orchestrated-plan.ts +49 -0
- package/src/update/orchestrated-pnpm.d.mts +8 -0
- package/src/update/orchestrated-pnpm.mjs +33 -0
- package/src/update/orchestrated-session.d.mts +37 -0
- package/src/update/orchestrated-session.mjs +264 -0
- package/src/update/orchestrated-token.d.mts +10 -0
- package/src/update/orchestrated-token.mjs +21 -0
- package/src/update/orchestrated-token.ts +3 -0
- package/src/update/orchestrated-tree.d.mts +1 -0
- package/src/update/orchestrated-tree.mjs +14 -0
- package/src/update/pnpm-global-install.d.mts +6 -0
- package/src/update/pnpm-global-install.mjs +9 -2
- package/src/update/posix-install-supervisor-entry.mjs +6 -0
- package/src/update/posix-install-supervisor.d.mts +10 -0
- package/src/update/posix-install-supervisor.mjs +88 -0
- package/src/update/sync-update-mutex.d.mts +10 -0
- package/src/update/sync-update-mutex.mjs +164 -0
- package/src/update/sync-update-mutex.ts +1 -0
- package/src/update/test-home-guard.mjs +33 -0
- package/src/update/transactional-install.mjs +2 -2
- package/src/usage/error-detail.ts +225 -0
- package/src/usage/log.ts +60 -27
- package/src/web-search/loop.ts +31 -5
- package/gui/dist/assets/index-ebuVUtB7.js +0 -94
|
@@ -1,5 +1,11 @@
|
|
|
1
|
+
import { clientFacingModelText } from "../../lib/error-destination";
|
|
2
|
+
import { projectLocalModelRefusalLog } from "../request-log-failure-detail";
|
|
3
|
+
import { markProxyError, rememberProxyErrorMessage, carryProxyError } from "../../lib/client-error-body";
|
|
4
|
+
import { releaseRequestOwnedMainOnOutcome, isKeyedRequestOwnedMain } from "../../codex/request-owned-affinity";
|
|
1
5
|
import { wasPermanentAccountRefusal } from "../../oauth/account-auto-pause";
|
|
2
6
|
import { hasResponseMediaType } from "../../lib/http-response-semantics";
|
|
7
|
+
import { routeKnownModels } from "../../usage/log";
|
|
8
|
+
import type { OcxProviderConfig } from "../../types";
|
|
3
9
|
import { isNativeControlResponse } from "./native-response-control";
|
|
4
10
|
import { guardBufferedComboRequiredTool } from "./combo-required-tool-contract";
|
|
5
11
|
import { createComboRequiredToolStreamGuard } from "./combo-required-tool-stream";
|
|
@@ -34,6 +40,7 @@ import {
|
|
|
34
40
|
codexDenialOutcomeMeta,
|
|
35
41
|
isFixedCodexAccount,
|
|
36
42
|
shouldDeferCodexResetDerivedCooldown,
|
|
43
|
+
shouldRetryCodexPoolAccountQuota,
|
|
37
44
|
} from "./core-codex-account";
|
|
38
45
|
import { isMainQuotaDispatchLive, isMainQuotaDispatchWsClaimed } from "../../codex/main-account-cache";
|
|
39
46
|
import { MAIN_CODEX_ACCOUNT_ID } from "../../codex/account-id";
|
|
@@ -482,9 +489,16 @@ export async function deliverPassthroughResponse(
|
|
|
482
489
|
});
|
|
483
490
|
}
|
|
484
491
|
|
|
485
|
-
|
|
492
|
+
// Every relayed header set below goes through this filter with the route's known models, so a
|
|
493
|
+
// reported model (row and header) is only ever a model id this route or a catalog already names.
|
|
494
|
+
const passthroughHeaderOptions = {
|
|
495
|
+
...codexSafetyBufferingOptions,
|
|
496
|
+
knownModels: [...routeKnownModels(logCtx), ...providerKnownModels(route.provider)],
|
|
497
|
+
provider: logCtx.provider,
|
|
498
|
+
};
|
|
499
|
+
const headers = sanitizePassthroughHeaders(upstreamResponse.headers, passthroughHeaderOptions);
|
|
486
500
|
if (!upstreamResponse.ok) noteUpstreamRequestId(logCtx, headers);
|
|
487
|
-
const resolvedModel = headers.get("openai-model")
|
|
501
|
+
const resolvedModel = headers.get("openai-model") ?? undefined;
|
|
488
502
|
if (resolvedModel) {
|
|
489
503
|
logCtx.servedModel = resolvedModel;
|
|
490
504
|
if (!logCtx.preserveResolvedModelFromRoute) logCtx.resolvedModel = resolvedModel;
|
|
@@ -571,6 +585,18 @@ export async function deliverPassthroughResponse(
|
|
|
571
585
|
});
|
|
572
586
|
}
|
|
573
587
|
} else {
|
|
588
|
+
if (terminalBodyWillRecord) {
|
|
589
|
+
options.setTerminalOutcomeRecorder?.((status, httpStatusOverride) => {
|
|
590
|
+
terminalRecorder?.(status, httpStatusOverride);
|
|
591
|
+
options.onNativePassthroughTerminal?.(status);
|
|
592
|
+
});
|
|
593
|
+
}
|
|
594
|
+
if (isKeyedRequestOwnedMain(admissionState.authCtx) && !terminalBodyWillRecord && !upstreamResponse.ok && !isNonReplayableResponse(upstreamResponse)
|
|
595
|
+
&& !isReplayRefusalResponse(upstreamResponse) && !wasPermanentAccountRefusal(upstreamResponse) && isCanonicalOpenAiForwardProvider(route.provider)) {
|
|
596
|
+
const outcome = upstreamResponse.status >= 500 && await shouldRetryCodexPoolAccountQuota(upstreamResponse, options.abortSignal)
|
|
597
|
+
? 429 : upstreamResponse.status;
|
|
598
|
+
releaseRequestOwnedMainOnOutcome(admissionState.authCtx, outcome, route.modelId);
|
|
599
|
+
}
|
|
574
600
|
// The WS observer is the only plain-main publisher for a WebSocket exchange;
|
|
575
601
|
// a prelude projection carries the prelude snapshot, not fresh evidence.
|
|
576
602
|
// The dispatch claim is authoritative because downstream wrappers can replace the Response.
|
|
@@ -602,7 +628,7 @@ export async function deliverPassthroughResponse(
|
|
|
602
628
|
return new Response(upstreamResponse.body, {
|
|
603
629
|
status: upstreamResponse.status,
|
|
604
630
|
statusText: upstreamResponse.statusText,
|
|
605
|
-
headers: sanitizePassthroughHeaders(upstreamResponse.headers,
|
|
631
|
+
headers: sanitizePassthroughHeaders(upstreamResponse.headers, passthroughHeaderOptions),
|
|
606
632
|
});
|
|
607
633
|
}
|
|
608
634
|
if (!upstreamResponse.ok) {
|
|
@@ -621,27 +647,28 @@ export async function deliverPassthroughResponse(
|
|
|
621
647
|
// Unsafe partial data falls back to #452's non-empty status-only JSON.
|
|
622
648
|
const errorText = await readDisplaySafeErrorText(upstreamResponse, upstream.signal, "");
|
|
623
649
|
if (upstreamResponse.status === 413) {
|
|
650
|
+
if (options.clientModelLabel) projectLocalModelRefusalLog(logCtx, options.clientModelLabel);
|
|
624
651
|
return clientRequestedStream
|
|
625
|
-
? streamingContextOverflowResponse(
|
|
652
|
+
? streamingContextOverflowResponse(clientFacingModelText(options.clientModelLabel), translatorBudget)
|
|
626
653
|
: jsonContextOverflowResponse();
|
|
627
654
|
}
|
|
628
655
|
const policyRefusal = rewriteUpstreamPolicyRefusal({
|
|
629
656
|
status: upstreamResponse.status,
|
|
630
657
|
errorText,
|
|
631
658
|
stream: clientRequestedStream,
|
|
632
|
-
modelId:
|
|
659
|
+
modelId: clientFacingModelText(options.clientModelLabel),
|
|
633
660
|
destinationIsXai: isXaiResponsesDestination(route.provider),
|
|
634
661
|
translatorBudget,
|
|
635
662
|
turnAdmissionLease: options.turnAdmissionLease,
|
|
636
663
|
});
|
|
637
664
|
if (policyRefusal) return policyRefusal;
|
|
638
|
-
return formatPassthroughUpstreamError(upstreamResponse.status, errorText, {
|
|
665
|
+
return carryProxyError(upstreamResponse, formatPassthroughUpstreamError(upstreamResponse.status, errorText, {
|
|
639
666
|
statusText: upstreamResponse.statusText,
|
|
640
667
|
headers,
|
|
641
668
|
// Provenance, not inference: `errorText` is empty when the bounded read finds nothing
|
|
642
669
|
// display-safe, and an empty body is exactly what the retryable-429 default fires on.
|
|
643
670
|
replayRefusal: isReplayRefusalResponse(upstreamResponse),
|
|
644
|
-
});
|
|
671
|
+
}));
|
|
645
672
|
}
|
|
646
673
|
|
|
647
674
|
if (options.nativeControl && isNativeControlResponse(upstreamResponse) && upstreamResponse.body) {
|
|
@@ -707,7 +734,7 @@ export async function deliverPassthroughResponse(
|
|
|
707
734
|
upstream,
|
|
708
735
|
terminalRepairPolicy,
|
|
709
736
|
translatorBudget,
|
|
710
|
-
options.responsesTerminalRepairScheduler,
|
|
737
|
+
options.responsesTerminalRepairScheduler, logCtx,
|
|
711
738
|
)
|
|
712
739
|
: upstreamResponse.body;
|
|
713
740
|
passthroughSseBody = webSearchBridgePlan
|
|
@@ -749,7 +776,7 @@ export async function deliverPassthroughResponse(
|
|
|
749
776
|
upstream,
|
|
750
777
|
terminalRepairPolicy,
|
|
751
778
|
translatorBudget,
|
|
752
|
-
options.responsesTerminalRepairScheduler,
|
|
779
|
+
options.responsesTerminalRepairScheduler, logCtx,
|
|
753
780
|
),
|
|
754
781
|
continuation,
|
|
755
782
|
);
|
|
@@ -912,7 +939,8 @@ export async function deliverPassthroughResponse(
|
|
|
912
939
|
providerExecutedCallTypes,
|
|
913
940
|
declaredBareWireToolNames,
|
|
914
941
|
recoverableBareCustomWireToolNames,
|
|
915
|
-
{ refuseUndeclared: nativeExchange.undeclaredToolGuardActive
|
|
942
|
+
{ refuseUndeclared: nativeExchange.undeclaredToolGuardActive,
|
|
943
|
+
onRefusal: message => rememberProxyErrorMessage(logCtx, message, { status: 502, type: "upstream_error", code: UNDECLARED_TOOL_CALL_ERROR_CODE }) },
|
|
916
944
|
)
|
|
917
945
|
: undefined,
|
|
918
946
|
grokUpstreamEchoEnabled
|
|
@@ -1147,7 +1175,7 @@ export async function deliverPassthroughResponse(
|
|
|
1147
1175
|
rememberPassthroughResponseChecked(client.terminal.response);
|
|
1148
1176
|
}
|
|
1149
1177
|
|
|
1150
|
-
const jsonHeaders = sanitizePassthroughHeaders(headers,
|
|
1178
|
+
const jsonHeaders = sanitizePassthroughHeaders(headers, passthroughHeaderOptions);
|
|
1151
1179
|
jsonHeaders.set("content-type", "application/json");
|
|
1152
1180
|
return markPreinspectedJsonResponse(new Response(clientJson, {
|
|
1153
1181
|
status: upstreamResponse.status,
|
|
@@ -1415,9 +1443,9 @@ export async function deliverPassthroughResponse(
|
|
|
1415
1443
|
}
|
|
1416
1444
|
})();
|
|
1417
1445
|
if (undeclared !== undefined) {
|
|
1418
|
-
return formatErrorResponse(502, "upstream_error", undeclaredToolCallMessage(
|
|
1446
|
+
return markProxyError(formatErrorResponse(502, "upstream_error", undeclaredToolCallMessage(), {
|
|
1419
1447
|
code: UNDECLARED_TOOL_CALL_ERROR_CODE,
|
|
1420
|
-
});
|
|
1448
|
+
}));
|
|
1421
1449
|
}
|
|
1422
1450
|
}
|
|
1423
1451
|
// Same split as the SSE rewrite: normalization applies whenever a declared name exists,
|
|
@@ -1489,7 +1517,7 @@ export async function deliverPassthroughResponse(
|
|
|
1489
1517
|
}
|
|
1490
1518
|
throw error;
|
|
1491
1519
|
}
|
|
1492
|
-
const sseHeaders = sanitizePassthroughHeaders(headers,
|
|
1520
|
+
const sseHeaders = sanitizePassthroughHeaders(headers, passthroughHeaderOptions);
|
|
1493
1521
|
sseHeaders.set("content-type", "text/event-stream");
|
|
1494
1522
|
sseHeaders.set("cache-control", "no-store");
|
|
1495
1523
|
return new Response(stream, {
|
|
@@ -1537,3 +1565,16 @@ export async function deliverPassthroughResponse(
|
|
|
1537
1565
|
headers,
|
|
1538
1566
|
});
|
|
1539
1567
|
}
|
|
1568
|
+
|
|
1569
|
+
/**
|
|
1570
|
+
* Model ids the user configured for the selected provider: its models and retention lists and
|
|
1571
|
+
* default. A provider-owned model hint that names one of them is relayed as the proxy's copy.
|
|
1572
|
+
* Live-discovered ids are not trusted here, because the upstream's own /models answer chose them;
|
|
1573
|
+
* neither is the selection list, which a model preset fills from that same discovered catalog.
|
|
1574
|
+
*/
|
|
1575
|
+
function providerKnownModels(provider: OcxProviderConfig): string[] {
|
|
1576
|
+
return [
|
|
1577
|
+
...(provider.models ?? []), ...(provider.retainModels ?? []),
|
|
1578
|
+
...(provider.defaultModel ? [provider.defaultModel] : []),
|
|
1579
|
+
];
|
|
1580
|
+
}
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { clientFacingModelText } from "../../lib/error-destination";
|
|
2
|
+
import { markProxyError } from "../../lib/client-error-body";
|
|
1
3
|
import { CodexInstallationIdUnavailableError } from "../../codex/installation-id";
|
|
2
4
|
import { passthroughBuildErrorResponse } from "./passthrough-build-error";
|
|
3
5
|
import { recoverAutoPausedAccount, rotatePassthroughKeyOn429 } from "./passthrough-key-rotation";
|
|
@@ -118,7 +120,7 @@ import type { CodexAuthContext } from "../../codex/auth-context";
|
|
|
118
120
|
import { checkOutboundBodySize, describeOutboundBodyRefusal } from "./outbound-body-guard";
|
|
119
121
|
import { streamingContextOverflowResponse } from "./context-overflow";
|
|
120
122
|
import {
|
|
121
|
-
SendBudgetExhaustedError,
|
|
123
|
+
SendBudgetExhaustedError, errorDestinationLabel,
|
|
122
124
|
fetchWithTransientRetry,
|
|
123
125
|
applyUpstreamRecoveryInit,
|
|
124
126
|
isNonReplayableResponse,
|
|
@@ -841,7 +843,7 @@ export async function preparePassthroughExchange(
|
|
|
841
843
|
// Charged to the SAME request counter every other send goes through. The
|
|
842
844
|
// replacement is bought here rather than by a nested retry helper, so there is
|
|
843
845
|
// one charge for one send and no per-layer counter to reconcile.
|
|
844
|
-
if (report.beforeSend?.() === false) throw new SendBudgetExhaustedError(
|
|
846
|
+
if (report.beforeSend?.() === false) throw new SendBudgetExhaustedError(errorDestinationLabel(request.url));
|
|
845
847
|
started = true;
|
|
846
848
|
},
|
|
847
849
|
}),
|
|
@@ -876,14 +878,14 @@ export async function preparePassthroughExchange(
|
|
|
876
878
|
console.warn(
|
|
877
879
|
`[responses] refused an oversized outbound body: bytes=${result.bytes} limit=${result.limit} `
|
|
878
880
|
+ `input_images=${result.imageCount} image_bytes=${result.imageBytes} `
|
|
879
|
-
+ `model=${JSON.stringify(
|
|
881
|
+
+ `model=${JSON.stringify(clientFacingModelText(options.clientModelLabel))}`,
|
|
880
882
|
);
|
|
881
883
|
// A streaming client treats HTTP 413 as a retryable transport error and resends the same
|
|
882
884
|
// oversized body — the reconnect loop #3177 exists to stop. Terminal overflow is the
|
|
883
885
|
// honest shape, and it is what the upstream-413 path already returns.
|
|
884
886
|
if (clientRequestedStream) {
|
|
885
887
|
return streamingContextOverflowResponse(
|
|
886
|
-
|
|
888
|
+
clientFacingModelText(options.clientModelLabel),
|
|
887
889
|
translatorBudget,
|
|
888
890
|
);
|
|
889
891
|
}
|
|
@@ -911,7 +913,7 @@ export async function preparePassthroughExchange(
|
|
|
911
913
|
nativeHostState.lease = null;
|
|
912
914
|
releaseCodexAuthContextProbeLease(admissionState.authCtx);
|
|
913
915
|
return unboundPoolSpendRefusalResponse(logCtx)
|
|
914
|
-
?? formatErrorResponse(429, "request_send_budget_exhausted", err.message);
|
|
916
|
+
?? markProxyError(formatErrorResponse(429, "request_send_budget_exhausted", err.message));
|
|
915
917
|
}
|
|
916
918
|
const refusal = unwrapUpstreamRetryEvidenceError(err);
|
|
917
919
|
if (refusal instanceof CopilotAutoAdapterHandoff) {
|
|
@@ -932,12 +934,12 @@ export async function preparePassthroughExchange(
|
|
|
932
934
|
nativeHostState.lease = null;
|
|
933
935
|
releaseCodexAuthContextProbeLease(admissionState.authCtx);
|
|
934
936
|
if (refusal instanceof OAuthLoginRequiredError) {
|
|
935
|
-
return formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(refusal));
|
|
937
|
+
return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(refusal)));
|
|
936
938
|
}
|
|
937
939
|
if (refusal instanceof AnthropicAccountCooldownError) {
|
|
938
940
|
return anthropicPoolCooldownResponse(refusal, { comboAttempt: options.comboAttempt, logCtx });
|
|
939
941
|
}
|
|
940
|
-
return formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(refusal));
|
|
942
|
+
return markProxyError(formatErrorResponse(403, "permission_error", publicOAuthAuthenticationErrorMessage(refusal)));
|
|
941
943
|
}
|
|
942
944
|
const localRefusal = spendLedgerStorageErrorResponse(err, logCtx) ?? mapCodexAuthContextErrorToResponse(refusal, {
|
|
943
945
|
now: Date.now(), accountSelector: route.codexAccountNamespace,
|
|
@@ -1032,7 +1034,7 @@ export async function preparePassthroughExchange(
|
|
|
1032
1034
|
// retry wrapper replaces — proves the host was reached (#914 review).
|
|
1033
1035
|
.then(adoptObservedResponse).then(preOutputRefusals.observe);
|
|
1034
1036
|
},
|
|
1035
|
-
{ abortSignal: upstream.signal, label: safeHostLabel(request.url),
|
|
1037
|
+
{ abortSignal: upstream.signal, label: safeHostLabel(request.url), destination: errorDestinationLabel(request.url),
|
|
1036
1038
|
attempts: sendBudgetState.initialSendAllowance(transientSendAttempts()),
|
|
1037
1039
|
// Reporter path: direct requests and enforced spend. Receipt-mode sends are settled
|
|
1038
1040
|
// by `onPhysicalDispatch`; a reporter as well would count them twice.
|
|
@@ -1145,7 +1147,7 @@ export async function preparePassthroughExchange(
|
|
|
1145
1147
|
// Gated on the return, not fire-and-forget: a consumed permit means this leg
|
|
1146
1148
|
// already sent once, and letting the second call through would be a free send.
|
|
1147
1149
|
if (allowance.permit && !allowance.permit.use()) {
|
|
1148
|
-
throw new SendBudgetExhaustedError(
|
|
1150
|
+
throw new SendBudgetExhaustedError(errorDestinationLabel(request.url));
|
|
1149
1151
|
}
|
|
1150
1152
|
transportState.noteRoutedAttemptSend(passthroughEstimate, innerRecovery ?? recovery);
|
|
1151
1153
|
return fetchWithHeaderTimeout(request.url, applyUpstreamRecoveryInit({
|
|
@@ -1169,7 +1171,7 @@ export async function preparePassthroughExchange(
|
|
|
1169
1171
|
route.provider.authMode === "forward")
|
|
1170
1172
|
.then(adoptObservedResponse);
|
|
1171
1173
|
},
|
|
1172
|
-
{ abortSignal: upstream.signal, label: safeHostLabel(request.url), attempts: allowance.attempts,
|
|
1174
|
+
{ abortSignal: upstream.signal, label: safeHostLabel(request.url), destination: errorDestinationLabel(request.url), attempts: allowance.attempts,
|
|
1173
1175
|
onSendsConsumed: transientSendReporter(allowance.permit),
|
|
1174
1176
|
claimAmbiguousResend: recovery === "empty-completion" ? undefined : claimPreHeaderResend },
|
|
1175
1177
|
);
|
|
@@ -1311,7 +1313,7 @@ export async function preparePassthroughExchange(
|
|
|
1311
1313
|
route.provider.authMode === "forward",
|
|
1312
1314
|
).then(adoptObservedResponse);
|
|
1313
1315
|
},
|
|
1314
|
-
{ abortSignal: upstream.signal, label: safeHostLabel(request.url),
|
|
1316
|
+
{ abortSignal: upstream.signal, label: safeHostLabel(request.url), destination: errorDestinationLabel(request.url),
|
|
1315
1317
|
attempts: remainingTransientSendBudget(transientSendAttempts()),
|
|
1316
1318
|
onSendsConsumed: transientSendReporter(), claimAmbiguousResend: claimPreHeaderResend },
|
|
1317
1319
|
);
|
|
@@ -1348,13 +1350,13 @@ export async function preparePassthroughExchange(
|
|
|
1348
1350
|
upstream.abort();
|
|
1349
1351
|
releaseCodexAuthContextProbeLease(admissionState.authCtx);
|
|
1350
1352
|
if (options.abortSignal?.aborted || req.signal.aborted) return clientCancelledResponse();
|
|
1351
|
-
if (err instanceof OAuthTokenRefreshBusyError) return formatErrorResponse(503, "server_error", publicOAuthAuthenticationErrorMessage(err), { retryAfter: "1" });
|
|
1352
|
-
return formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(err));
|
|
1353
|
+
if (err instanceof OAuthTokenRefreshBusyError) return markProxyError(formatErrorResponse(503, "server_error", publicOAuthAuthenticationErrorMessage(err), { retryAfter: "1" }));
|
|
1354
|
+
return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(err)));
|
|
1353
1355
|
}
|
|
1354
1356
|
if (route.provider.googleMode === "cloud-code-assist" && !refreshed.projectId) {
|
|
1355
1357
|
upstream.abort();
|
|
1356
1358
|
releaseCodexAuthContextProbeLease(admissionState.authCtx);
|
|
1357
|
-
return formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(new Error("Cloud Code Assist project is required")));
|
|
1359
|
+
return markProxyError(formatErrorResponse(401, "authentication_error", publicOAuthAuthenticationErrorMessage(new Error("Cloud Code Assist project is required"))));
|
|
1358
1360
|
}
|
|
1359
1361
|
transportState.sentOAuthSnapshot = refreshed;
|
|
1360
1362
|
transportState.replayOAuthCredentialSnapshot = {
|
|
@@ -1436,7 +1438,7 @@ export async function preparePassthroughExchange(
|
|
|
1436
1438
|
route.provider.authMode === "forward")
|
|
1437
1439
|
.then(adoptObservedResponse);
|
|
1438
1440
|
},
|
|
1439
|
-
{ abortSignal: upstream.signal, label: safeHostLabel(request.url), attempts: remainingTransientSendBudget(transientSendAttempts()),
|
|
1441
|
+
{ abortSignal: upstream.signal, label: safeHostLabel(request.url), destination: errorDestinationLabel(request.url), attempts: remainingTransientSendBudget(transientSendAttempts()),
|
|
1440
1442
|
onSendsConsumed: transientSendReporter(), claimAmbiguousResend: claimPreHeaderResend },
|
|
1441
1443
|
);
|
|
1442
1444
|
} catch (err) {
|
|
@@ -1583,7 +1585,7 @@ export async function preparePassthroughExchange(
|
|
|
1583
1585
|
route.provider.authMode === "forward")
|
|
1584
1586
|
.then(adoptObservedResponse);
|
|
1585
1587
|
},
|
|
1586
|
-
{ abortSignal: upstream.signal, label: safeHostLabel(request.url), attempts: remainingTransientSendBudget(transientSendAttempts()),
|
|
1588
|
+
{ abortSignal: upstream.signal, label: safeHostLabel(request.url), destination: errorDestinationLabel(request.url), attempts: remainingTransientSendBudget(transientSendAttempts()),
|
|
1587
1589
|
onSendsConsumed: transientSendReporter(), claimAmbiguousResend: claimPreHeaderResend },
|
|
1588
1590
|
);
|
|
1589
1591
|
} catch (err) {
|
|
@@ -1908,7 +1910,7 @@ export async function preparePassthroughExchange(
|
|
|
1908
1910
|
error,
|
|
1909
1911
|
{
|
|
1910
1912
|
abortSignal: upstream.signal,
|
|
1911
|
-
label: safeHostLabel(request.url),
|
|
1913
|
+
label: safeHostLabel(request.url), destination: errorDestinationLabel(request.url),
|
|
1912
1914
|
attempts: remainingTransientSendBudget(transientSendAttempts()),
|
|
1913
1915
|
// The whole decision, including the stage the preflight observed and the grant the
|
|
1914
1916
|
// pre-header helper shares. A committed stage refuses here without touching the
|
|
@@ -7,8 +7,8 @@ import {
|
|
|
7
7
|
UPSTREAM_RESET_REPLAY_REFUSED_CODE,
|
|
8
8
|
} from "../../lib/upstream-retry";
|
|
9
9
|
import {
|
|
10
|
+
formatClientRetryAfter,
|
|
10
11
|
resolveClientRetryAfter,
|
|
11
|
-
validateClientRetryAfterHeader,
|
|
12
12
|
} from "../../lib/retry-after";
|
|
13
13
|
|
|
14
14
|
function isCyberPolicyBody(body: string): boolean {
|
|
@@ -93,7 +93,6 @@ export function formatPassthroughUpstreamError(
|
|
|
93
93
|
const trimmed = bodyText.trim();
|
|
94
94
|
const now = options?.now ?? Date.now();
|
|
95
95
|
const upstreamRetryAfter = options?.headers?.get("retry-after")?.trim() || undefined;
|
|
96
|
-
const originalValid = validateClientRetryAfterHeader(upstreamRetryAfter, now);
|
|
97
96
|
const cyberPolicyFailure = isCyberPolicyBody(trimmed);
|
|
98
97
|
const replayRefusal = options?.replayRefusal === true || isReplayRefusalBody(trimmed);
|
|
99
98
|
// Two different reasons to answer with no wait at all, handled the same way: a hard policy
|
|
@@ -108,12 +107,12 @@ export function formatPassthroughUpstreamError(
|
|
|
108
107
|
now,
|
|
109
108
|
});
|
|
110
109
|
|
|
110
|
+
// The header leaves in this proxy's own format: an integer of seconds, never the upstream bytes.
|
|
111
|
+
const formatted = resolved === undefined ? undefined : formatClientRetryAfter(resolved, now);
|
|
112
|
+
|
|
111
113
|
if (trimmed) {
|
|
112
|
-
const needsSet =
|
|
113
|
-
const needsDelete =
|
|
114
|
-
|| (resolved === undefined
|
|
115
|
-
&& upstreamRetryAfter !== undefined
|
|
116
|
-
&& originalValid === undefined);
|
|
114
|
+
const needsSet = formatted !== undefined && upstreamRetryAfter !== formatted;
|
|
115
|
+
const needsDelete = formatted === undefined && upstreamRetryAfter !== undefined;
|
|
117
116
|
|
|
118
117
|
// A refusal always takes the rewriting path: it has a header to add even when the
|
|
119
118
|
// upstream named no wait for it to remove.
|
|
@@ -128,7 +127,7 @@ export function formatPassthroughUpstreamError(
|
|
|
128
127
|
const headers = options?.headers
|
|
129
128
|
? new Headers(options.headers)
|
|
130
129
|
: new Headers({ "Content-Type": "application/json" });
|
|
131
|
-
if (needsSet) headers.set("Retry-After",
|
|
130
|
+
if (needsSet) headers.set("Retry-After", formatted!);
|
|
132
131
|
else headers.delete("Retry-After");
|
|
133
132
|
if (replayRefusal) applyReplayRefusalClientHeaders(headers);
|
|
134
133
|
const rewritten = new Response(bodyText, {
|
|
@@ -152,7 +151,8 @@ export function formatPassthroughUpstreamError(
|
|
|
152
151
|
);
|
|
153
152
|
const headers = new Headers(response.headers);
|
|
154
153
|
headers.set("Content-Type", "application/json");
|
|
155
|
-
if (
|
|
154
|
+
if (formatted !== undefined) headers.set("Retry-After", formatted);
|
|
155
|
+
else headers.delete("Retry-After");
|
|
156
156
|
if (replayRefusal) applyReplayRefusalClientHeaders(headers);
|
|
157
157
|
const wrapped = new Response(response.body, { status: response.status, headers });
|
|
158
158
|
return replayRefusal ? retainReplayRefusal(wrapped) : wrapped;
|
|
@@ -16,6 +16,7 @@ import { routeConcreteModel } from "../../router";
|
|
|
16
16
|
import { isPolicyCandidateRefusal, policyWireDestination, type PolicyRequestScope } from "./policy-request-scope";
|
|
17
17
|
import { fallbackTriggerForStatus, guardFallbackHop } from "../../routing/fallback-policy";
|
|
18
18
|
import { captureAdmissionPolicy } from "../capture-admission-policy";
|
|
19
|
+
import { upstreamCodeForComboFailure } from "../../bridge/errors";
|
|
19
20
|
|
|
20
21
|
type CoreHandler = typeof handleResponsesCore;
|
|
21
22
|
type CoreOptions = Parameters<CoreHandler>[3];
|
|
@@ -133,7 +134,7 @@ async function shouldHopPolicyCandidate(response: Response, signal?: AbortSignal
|
|
|
133
134
|
const inspected = await readBoundedResponseBody(response.clone(), { signal });
|
|
134
135
|
const text = inspected.displaySafe && !inspected.truncated ? inspected.text : "";
|
|
135
136
|
return comboFailureDecision(response.status, text, {
|
|
136
|
-
code: errorCodeFromText(text),
|
|
137
|
+
code: upstreamCodeForComboFailure(response, errorCodeFromText(text)),
|
|
137
138
|
// A passthrough candidate returns its upstream body unchanged, so the code is not provenance.
|
|
138
139
|
verifiedPlanRefusal: isVerifiedModelNotInPlanResponse(response),
|
|
139
140
|
}) === "hop";
|