@bitkyc08/opencodex 2.100.5 → 2.100.6
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/README.md +1 -1
- package/bin/ocx.mjs +2 -0
- package/gui/dist/assets/App-BI8LQ7Qk.css +1 -0
- package/gui/dist/assets/App-CsZ1Gr7S.js +60 -0
- package/gui/dist/assets/Tray-CVqm4S4W.js +1 -0
- package/gui/dist/assets/brand-mark-BebhnAtV.js +1 -0
- package/gui/dist/assets/index-BtwVlpeQ.css +2 -0
- package/gui/dist/assets/index-CEeMegqE.js +138 -0
- package/gui/dist/assets/{segment-thumb-features-Bquysdn5.js → segment-thumb-features-COdzmORE.js} +1 -1
- package/gui/dist/classic/assets/App-BJgUWNJ8.js +59 -0
- package/gui/dist/classic/assets/App-CoiVLRW3.css +1 -0
- package/gui/dist/classic/assets/Tray-BDlcOLDK.js +1 -0
- package/gui/dist/classic/assets/index-B9Jgli_W.js +138 -0
- package/gui/dist/classic/assets/usage-companion-chart-vbzDcND0.js +1 -0
- package/gui/dist/classic/index.html +1 -1
- package/gui/dist/index.html +2 -2
- package/native/ocx-child/Cargo.lock +62 -0
- package/native/ocx-child/Cargo.toml +1 -0
- package/native/ocx-child/src/journal.rs +32 -10
- package/native/ocx-child/src/state.rs +2 -1
- package/native/ocx-child/src/toml_surgeon.rs +183 -72
- package/package.json +2 -2
- package/src/adapters/agy-acp/acp.ts +202 -0
- package/src/adapters/agy-acp/adapter.ts +554 -0
- package/src/adapters/agy-acp/binary.ts +79 -0
- package/src/adapters/agy-acp/options.ts +163 -0
- package/src/adapters/agy-acp/output-redaction.ts +270 -0
- package/src/adapters/agy-acp/policy.ts +105 -0
- package/src/adapters/agy-acp/process.ts +218 -0
- package/src/adapters/anthropic/account-metadata.ts +4 -1
- package/src/adapters/anthropic/advisor-tool.ts +43 -9
- package/src/adapters/anthropic/client-identity.ts +2 -0
- package/src/adapters/anthropic.ts +102 -14
- package/src/adapters/antigravity-refusal.ts +5 -1
- package/src/adapters/base.ts +25 -2
- package/src/adapters/claude-cli/adapter.ts +1 -0
- package/src/adapters/claude-cli/usage-admission.ts +12 -9
- package/src/adapters/codebuddy/adapter.ts +1 -0
- package/src/adapters/command-code.ts +2 -2
- package/src/adapters/cursor/http1-bidi.ts +7 -2
- package/src/adapters/cursor/live-transport.ts +2 -0
- package/src/adapters/cursor/request-builder.ts +4 -4
- package/src/adapters/cursor/tool-naming.ts +5 -5
- package/src/adapters/cursor/transport-retry.ts +14 -8
- package/src/adapters/cursor/transport.ts +2 -0
- package/src/adapters/cursor.ts +8 -2
- package/src/adapters/google-error-details.ts +105 -0
- package/src/adapters/google-errors.ts +183 -31
- package/src/adapters/google-http.ts +66 -22
- package/src/adapters/google-truncation.ts +48 -3
- package/src/adapters/google-vertex-endpoint.ts +12 -1
- package/src/adapters/google.ts +54 -26
- package/src/adapters/kiro/adapter.ts +39 -38
- package/src/adapters/kiro/stream.ts +59 -9
- package/src/adapters/kiro-retry.ts +5 -3
- package/src/adapters/m365-copilot/LICENSE +21 -0
- package/src/adapters/m365-copilot/fenced.ts +745 -0
- package/src/adapters/m365-copilot/images.ts +89 -0
- package/src/adapters/m365-copilot/tools.ts +284 -0
- package/src/adapters/m365-copilot/transport.ts +232 -0
- package/src/adapters/m365-copilot.ts +143 -0
- package/src/adapters/openai-chat/tool-schema.ts +2 -2
- package/src/adapters/openai-responses/passthrough.ts +1 -0
- package/src/adapters/openai-responses/reasoning.ts +23 -3
- package/src/adapters/physical-send.ts +11 -4
- package/src/adapters/qoder/adapter.ts +17 -3
- package/src/adapters/registry.ts +15 -1
- package/src/adapters/zed.ts +2 -1
- package/src/advisor/consult.ts +1 -0
- package/src/bridge/response-json.ts +6 -2
- package/src/bridge/sse.ts +21 -9
- package/src/chat/inbound.ts +11 -8
- package/src/chat/outbound.ts +28 -7
- package/src/claude/context-windows.ts +32 -8
- package/src/claude/desktop-3p.ts +18 -14
- package/src/claude/desktop-picker-platform.ts +1 -1
- package/src/claude/desktop-picker.ts +3 -3
- package/src/claude/inbound-content-options.ts +11 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +17 -5
- package/src/claude/intercept/picker-ca.ts +162 -27
- package/src/claude/intercept/picker-trust-linux.ts +411 -0
- package/src/claude/intercept/picker-trust.ts +35 -3
- package/src/claude/intercept/runtime.ts +2 -2
- package/src/claude/subagent-force-status.ts +24 -5
- package/src/claude/subscription-reserve.ts +87 -0
- package/src/cli/account-api.ts +3 -0
- package/src/cli/account-auth.ts +65 -11
- package/src/cli/account-extended.ts +1 -1
- package/src/cli/account-next-actions.ts +4 -1
- package/src/cli/account-policy-dto.ts +1 -1
- package/src/cli/account-policy.ts +6 -3
- package/src/cli/account-probe.ts +66 -0
- package/src/cli/account.ts +8 -2
- package/src/cli/capabilities-accounts.ts +8 -1
- package/src/cli/capabilities-agents-routing.ts +2 -2
- package/src/cli/capabilities-base.ts +4 -4
- package/src/cli/capabilities-integrations.ts +44 -4
- package/src/cli/capabilities-provider-models.ts +6 -0
- package/src/cli/claude-context-settings.ts +60 -0
- package/src/cli/claude-desktop.ts +2 -2
- package/src/cli/claude.ts +15 -7
- package/src/cli/client-start-fence.ts +64 -1
- package/src/cli/combo-result.ts +1 -0
- package/src/cli/combo-stats.ts +1 -1
- package/src/cli/combo.ts +19 -2
- package/src/cli/config-command.ts +21 -8
- package/src/cli/connect.ts +16 -0
- package/src/cli/cross-home-owner.ts +65 -18
- package/src/cli/dispatch.ts +4 -0
- package/src/cli/gateway-client-command.ts +128 -0
- package/src/cli/index.ts +98 -97
- package/src/cli/init.ts +20 -4
- package/src/cli/integrations.ts +23 -3
- package/src/cli/launcher-context.ts +12 -1
- package/src/cli/link.ts +24 -5
- package/src/cli/models-runtime-subcommands.ts +1 -0
- package/src/cli/models-runtime.ts +32 -0
- package/src/cli/start-owner-fence.ts +5 -2
- package/src/cli/status.ts +3 -3
- package/src/cli/stop-client-process.ts +51 -0
- package/src/cli/stop-restore.ts +383 -36
- package/src/cli/sync-command.ts +2 -2
- package/src/cli/uninstall-client-state.ts +7 -0
- package/src/client/connect.ts +72 -13
- package/src/client/hub-client.ts +38 -0
- package/src/client/hub-relay.ts +61 -36
- package/src/client/hub-session.ts +106 -0
- package/src/client/lifecycle-lock.ts +6 -1
- package/src/client/link-relay.ts +2 -1
- package/src/client/machine-listener.ts +60 -1
- package/src/client/runtime-restart.ts +1 -0
- package/src/client/runtime.ts +104 -34
- package/src/client/state.ts +11 -0
- package/src/client/stop-darwin-process.ts +73 -0
- package/src/client/stop-file-routing.ts +49 -0
- package/src/client/stop-native-handoff.ts +108 -0
- package/src/client/stop-routing.ts +41 -7
- package/src/client/stop-teardown-owner.ts +173 -0
- package/src/client/sync-runtime.ts +23 -4
- package/src/clients/config-export/opencode-wire.ts +24 -0
- package/src/clients/config-export.ts +28 -19
- package/src/codex/auth-api/login-flow.ts +68 -33
- package/src/codex/auth-api/main-account-probe.ts +3 -3
- package/src/codex/auth-api/pool-quota-probe.ts +8 -7
- package/src/codex/auth-api/routes.ts +1 -1
- package/src/codex/catalog/aggregation.ts +22 -10
- package/src/codex/catalog/gather-capture.ts +11 -2
- package/src/codex/catalog/m365-copilot-models.ts +52 -0
- package/src/codex/catalog/provider-models.ts +126 -53
- package/src/codex/catalog/routed-gather.ts +26 -12
- package/src/codex/catalog-admission.ts +4 -6
- package/src/codex/catalog-auto-refresh.ts +4 -2
- package/src/codex/catalog-self-heal.ts +4 -2
- package/src/codex/control-plane-models.ts +6 -0
- package/src/codex/convergence.ts +10 -0
- package/src/codex/desktop-app/picker-freshness.ts +3 -14
- package/src/codex/desktop-app/types.ts +6 -0
- package/src/codex/desktop-app/windows-command-payload.ts +9 -0
- package/src/codex/desktop-app/windows.ts +20 -12
- package/src/codex/desktop-compatibility/installed-build.ts +61 -58
- package/src/codex/desktop-compatibility/runtime-ownership.ts +11 -5
- package/src/codex/desktop-compatibility/runtime.ts +51 -14
- package/src/codex/desktop-compatibility/windows-activation-source.ts +28 -13
- package/src/codex/desktop-compatibility/windows-package-command.ts +73 -33
- package/src/codex/desktop-compatibility/windows-package-launch.ts +41 -9
- package/src/codex/desktop-compatibility/windows-package-proof.ts +104 -0
- package/src/codex/inject/config-toml.ts +67 -73
- package/src/codex/inject/plan.ts +11 -10
- package/src/codex/inject/remove.ts +4 -1
- package/src/codex/inject.ts +1 -0
- package/src/codex/journal-config-restore.ts +31 -4
- package/src/codex/journal.ts +16 -4
- package/src/codex/model-cache.ts +98 -27
- package/src/codex/native-residue.ts +14 -13
- package/src/codex/paths.ts +65 -28
- package/src/codex/quota-observation-freshness.ts +4 -0
- package/src/codex/quota.ts +71 -8
- package/src/codex/routing/selection.ts +32 -8
- package/src/combos/capability-policy.ts +31 -0
- package/src/combos/failover.ts +82 -74
- package/src/combos/identifiers.ts +2 -2
- package/src/combos/index.ts +3 -0
- package/src/combos/jev-model-backend.ts +12 -4
- package/src/combos/jev-session-pin-config.ts +22 -9
- package/src/combos/jev.ts +15 -4
- package/src/combos/request-capability.ts +214 -0
- package/src/combos/request.ts +22 -15
- package/src/combos/resolve.ts +5 -2
- package/src/combos/suggestion-channel.ts +89 -0
- package/src/combos/types.ts +14 -1
- package/src/config/account-auto-pause-revisions.ts +33 -10
- package/src/config/atomic-write.ts +1 -1
- package/src/config/codex-ws-incremental-setting.ts +34 -0
- package/src/config/diagnostics.ts +47 -8
- package/src/config/live-topology.ts +4 -2
- package/src/config/load-degrade.ts +96 -2
- package/src/config/mutation-lock.ts +7 -3
- package/src/config/paths.ts +3 -0
- package/src/config/pending-teardown.ts +19 -3
- package/src/config/process-state.ts +30 -12
- package/src/config/provider-validation.ts +10 -0
- package/src/config/salvage.ts +2 -2
- package/src/config/schema/account-auto-pause.ts +15 -1
- package/src/config/schema/agy-acp-references.ts +257 -0
- package/src/config/schema/config-schema.ts +32 -0
- package/src/config/schema/leaf-validators.ts +42 -0
- package/src/config/schema/subscription-reserve.ts +33 -0
- package/src/config/windows-process-command-line.ts +27 -9
- package/src/config.ts +6 -0
- package/src/generated/compatibility-version.json +806 -402
- package/src/images/loop.ts +79 -39
- package/src/integrations/catalog-refresh.ts +19 -1
- package/src/integrations/gateway-clients/agy.ts +340 -0
- package/src/integrations/gateway-clients/antigravity.ts +224 -0
- package/src/integrations/gateway-clients/index.ts +89 -0
- package/src/integrations/gateway-clients/io.ts +278 -0
- package/src/integrations/gateway-clients/types.ts +80 -0
- package/src/integrations/route-intent-disconnect.ts +37 -21
- package/src/lib/app-owned-memory-stores.ts +9 -0
- package/src/lib/cloud-code-appeal-link.ts +30 -0
- package/src/lib/errors.ts +32 -0
- package/src/lib/executor-physical-send-receipt.ts +42 -0
- package/src/lib/failure-detail.ts +1 -0
- package/src/lib/gcp-adc.ts +5 -0
- package/src/lib/http-date.ts +91 -0
- package/src/lib/lab-passive-linker-registration.ts +2 -1
- package/src/lib/local-chat-completion.ts +13 -3
- package/src/lib/local-internal-call-capability.ts +1 -3
- package/src/lib/messages-error-body.ts +2 -1
- package/src/lib/outbound-credential-registry.ts +40 -4
- package/src/lib/pinned-http.ts +7 -2
- package/src/lib/process-control.ts +1 -0
- package/src/lib/provider-egress.ts +16 -0
- package/src/lib/provider-outbound.ts +3 -0
- package/src/lib/redact-folding.ts +12 -3
- package/src/lib/redact.ts +37 -19
- package/src/lib/request-execution-budget.ts +241 -32
- package/src/lib/request-peer-scope.ts +64 -0
- package/src/lib/response-send-readings.ts +41 -0
- package/src/lib/state-store-registrations.ts +5 -0
- package/src/lib/tool-envelope-echo-filter.ts +33 -5
- package/src/lib/upstream-condition.ts +10 -3
- package/src/lib/upstream-retry.ts +95 -20
- package/src/lib/windows-secret-acl.ts +24 -7
- package/src/link/child-activity.ts +60 -4
- package/src/link/codex-settings.ts +2 -1
- package/src/link/relay-auth.ts +1 -0
- package/src/link/route-rounds.ts +32 -9
- package/src/link/status-projection.ts +42 -5
- package/src/link/supervisor.ts +96 -11
- package/src/link/tunnel-history.ts +5 -0
- package/src/oauth/account-auto-pause-policy.ts +72 -19
- package/src/oauth/account-auto-pause.ts +40 -16
- package/src/oauth/anthropic-account-refusal.ts +7 -0
- package/src/oauth/anthropic-continuity.ts +70 -9
- package/src/oauth/anthropic-identity.ts +75 -11
- package/src/oauth/anthropic-login-slot.ts +258 -0
- package/src/oauth/anthropic-routing.ts +24 -9
- package/src/oauth/anthropic-send-ownership.ts +4 -3
- package/src/oauth/anthropic.ts +30 -11
- package/src/oauth/health.ts +7 -2
- package/src/oauth/index.ts +50 -48
- package/src/oauth/key-providers.ts +2 -0
- package/src/oauth/login-cli.ts +11 -0
- package/src/oauth/login-flow-state.ts +10 -4
- package/src/oauth/m365-copilot-browser.ts +222 -0
- package/src/oauth/m365-copilot-web-session.ts +25 -0
- package/src/oauth/m365-copilot.ts +57 -0
- package/src/oauth/model-discovery-auth.ts +5 -0
- package/src/oauth/plan.ts +44 -0
- package/src/oauth/pool-kernel.ts +22 -8
- package/src/oauth/pool-settings-capability.ts +14 -3
- package/src/oauth/reauth-precheck.ts +27 -0
- package/src/oauth/store-anthropic-instance.ts +3 -1
- package/src/oauth/store.ts +121 -23
- package/src/oauth/types.ts +27 -2
- package/src/protocols/codecs/chat-ir.ts +7 -4
- package/src/protocols/codecs/gemini-interactions.ts +770 -0
- package/src/protocols/codecs/gemini.ts +470 -0
- package/src/protocols/contract.ts +2 -0
- package/src/protocols/encoders/adapter-events.ts +5 -3
- package/src/protocols/encoders/chat.ts +23 -7
- package/src/protocols/settings.ts +3 -0
- package/src/providers/account-quota-disk.ts +26 -8
- package/src/providers/api-key-pause.ts +2 -2
- package/src/providers/api-key-response-ownership.ts +14 -4
- package/src/providers/claude-cli-usage-state.ts +1 -0
- package/src/providers/claude-cli-usage.ts +24 -7
- package/src/providers/default-aliases.ts +11 -5
- package/src/providers/derive.ts +5 -1
- package/src/providers/fastwire.ts +6 -5
- package/src/providers/free-directory.ts +2 -2
- package/src/providers/google-vertex-location.ts +2 -1
- package/src/providers/google-vertex-model-discovery.ts +22 -0
- package/src/providers/key-failover.ts +18 -23
- package/src/providers/m365-copilot-discovery-fetch.ts +17 -0
- package/src/providers/m365-copilot-discovery.ts +68 -0
- package/src/providers/m365-copilot-models.ts +32 -0
- package/src/providers/model-rename-fields.ts +6 -0
- package/src/providers/new-model-policy-runtime.ts +27 -6
- package/src/providers/openai-forward-destination.ts +19 -0
- package/src/providers/openai-tiers-destination.ts +3 -19
- package/src/providers/quota/account-cache.ts +183 -27
- package/src/providers/quota/anthropic-account-quota.ts +21 -17
- package/src/providers/quota/anthropic-cooldown-recovery.ts +57 -27
- package/src/providers/quota/anthropic-decision-windows.ts +7 -3
- package/src/providers/quota/anthropic-usage-windows.ts +34 -4
- package/src/providers/quota/antigravity-account-probe.ts +165 -0
- package/src/providers/quota/antigravity.ts +71 -3
- package/src/providers/quota/vendor-probes-oauth.ts +52 -28
- package/src/providers/quota-decision-publication.ts +1 -1
- package/src/providers/quota-decision-snapshot.ts +4 -1
- package/src/providers/quota-types.ts +2 -0
- package/src/providers/quota.ts +8 -7
- package/src/providers/registry/agy-acp-models.ts +3 -0
- package/src/providers/registry/entries-core.ts +9 -0
- package/src/providers/registry/entries-extended.ts +60 -0
- package/src/providers/registry/model-seeds.ts +51 -0
- package/src/providers/request-pacing.ts +37 -7
- package/src/providers/service-tier.ts +2 -0
- package/src/providers/xai-privacy-mode.ts +52 -0
- package/src/remote/hub-management-relay.ts +74 -0
- package/src/responses/id-limits.ts +2 -0
- package/src/responses/input-media.ts +15 -3
- package/src/responses/parser-tools.ts +74 -11
- package/src/responses/parser.ts +16 -14
- package/src/responses/provider-opaque-metadata.ts +10 -0
- package/src/responses/reasoning-envelope.ts +3 -0
- package/src/responses/schema.ts +2 -3
- package/src/responses/spill-store.ts +5 -3
- package/src/responses/state/connection-scope.ts +232 -0
- package/src/responses/state/entry-types.ts +47 -0
- package/src/responses/state/snapshot-codec.ts +75 -14
- package/src/responses/state/snapshot-select.ts +2 -0
- package/src/responses/state/spill-codec.ts +59 -0
- package/src/responses/state/spill-queue.ts +11 -2
- package/src/responses/state.ts +178 -159
- package/src/router.ts +2 -6
- package/src/routing/compatibility/behavior.ts +6 -2
- package/src/routing/compatibility/subject.ts +17 -12
- package/src/routing/machine-weighted-routing.ts +58 -0
- package/src/server/advisor-admission-scope.ts +15 -7
- package/src/server/auth-cors.ts +27 -0
- package/src/server/chat-completions.ts +37 -17
- package/src/server/chat-native-eligibility.ts +21 -0
- package/src/server/chat-native.ts +15 -6
- package/src/server/claude-messages.ts +54 -6
- package/src/server/credential-recovery-attempt.ts +32 -0
- package/src/server/effort-policy.ts +6 -3
- package/src/server/gemini-inbound.ts +267 -0
- package/src/server/gemini-interactions-inbound.ts +229 -0
- package/src/server/gemini-interactions-store.ts +129 -0
- package/src/server/gemini-native-catalog.ts +64 -0
- package/src/server/gemini-native-log.ts +33 -0
- package/src/server/gemini-native-paths.ts +88 -0
- package/src/server/gemini-native-wire.ts +201 -0
- package/src/server/gemini-native.ts +218 -0
- package/src/server/grok-upstream-envelope-echo.ts +8 -2
- package/src/server/hub-relay-auth.ts +87 -0
- package/src/server/hub-usage-windows.ts +135 -0
- package/src/server/hub-usage.ts +16 -3
- package/src/server/inbound-body-admission.ts +2 -1
- package/src/server/index/anthropic-model-listing.ts +75 -0
- package/src/server/index/gemini-routes.ts +147 -0
- package/src/server/index/link-management.ts +3 -22
- package/src/server/index/link-relay-sessions.ts +71 -13
- package/src/server/index/link-websocket.ts +2 -0
- package/src/server/index/passive-management-read.ts +55 -0
- package/src/server/index/serve-options.ts +93 -107
- package/src/server/index/websocket-handler.ts +15 -2
- package/src/server/index.ts +10 -0
- package/src/server/inference/client-encoder-delivery.ts +2 -1
- package/src/server/inference/context.ts +33 -6
- package/src/server/management/agent-settings-routes.ts +33 -16
- package/src/server/management/claude-code-settings-patch.ts +6 -0
- package/src/server/management/combo-routes.ts +21 -1
- package/src/server/management/combo-suggestion-routes.ts +212 -0
- package/src/server/management/config-routes.ts +12 -4
- package/src/server/management/context.ts +2 -0
- package/src/server/management/gateway-client-routes.ts +62 -0
- package/src/server/management/integration-routes.ts +5 -0
- package/src/server/management/link-routes.ts +5 -1
- package/src/server/management/m365-copilot-provider-probe.ts +23 -0
- package/src/server/management/model-routes.ts +32 -2
- package/src/server/management/model-rows.ts +36 -3
- package/src/server/management/oauth-account-routes.ts +68 -15
- package/src/server/management/protocol-settings-patch.ts +1 -0
- package/src/server/management/provider-omitted-fields.ts +25 -0
- package/src/server/management/provider-overwrite-carry.ts +33 -8
- package/src/server/management/provider-routes.ts +10 -16
- package/src/server/management/request-history-routes.ts +2 -2
- package/src/server/management/route-registry.ts +10 -0
- package/src/server/management/shared.ts +118 -30
- package/src/server/management/sibling-guard.ts +2 -1
- package/src/server/management/system-routes.ts +6 -0
- package/src/server/management-auth.ts +8 -1
- package/src/server/messages-native-scope.ts +19 -0
- package/src/server/messages-native.ts +156 -59
- package/src/server/messages-shared.ts +6 -0
- package/src/server/models-capabilities.ts +24 -0
- package/src/server/native-chat-bridge.ts +259 -0
- package/src/server/ollama-inbound.ts +36 -184
- package/src/server/passive-route-linker.ts +3 -1
- package/src/server/port-reclaim.ts +48 -4
- package/src/server/proxy-liveness.ts +79 -22
- package/src/server/relay.ts +16 -9
- package/src/server/request-log-account-rotation.ts +2 -1
- package/src/server/request-log-attempt-recovery.ts +24 -2
- package/src/server/request-log-attempt-usage.ts +5 -4
- package/src/server/request-log-committed-terminal.ts +87 -0
- package/src/server/request-log-failure-attribution.ts +3 -3
- package/src/server/request-log-failure-detail.ts +34 -0
- package/src/server/request-log-key-failure.ts +27 -0
- package/src/server/request-log-terminal-status.ts +25 -12
- package/src/server/request-log.ts +59 -63
- package/src/server/responses/adapter-continuation.ts +77 -44
- package/src/server/responses/adapter-delivery.ts +47 -22
- package/src/server/responses/adapter-dispatch.ts +150 -149
- package/src/server/responses/advisor-retention.ts +12 -4
- package/src/server/responses/advisor-slot.ts +97 -2
- package/src/server/responses/agent-task-recovery.ts +44 -11
- package/src/server/responses/agy-acp-preflight.ts +41 -0
- package/src/server/responses/anthropic-image-context.ts +44 -0
- package/src/server/responses/antigravity-validation-refusal.ts +25 -1
- package/src/server/responses/buffered-sse-json.ts +18 -1
- package/src/server/responses/codex-ws-correlation.ts +5 -2
- package/src/server/responses/codex-ws-exchange.ts +91 -8
- package/src/server/responses/codex-ws-incremental.ts +136 -0
- package/src/server/responses/codex-ws-pool.ts +22 -8
- package/src/server/responses/codex-ws-request.ts +5 -0
- package/src/server/responses/codex-ws-send-accounting.ts +8 -0
- package/src/server/responses/codex-ws-session.ts +14 -0
- package/src/server/responses/codex-ws-wire.ts +44 -22
- package/src/server/responses/combo-admission-snapshot.ts +93 -0
- package/src/server/responses/combo-required-tool-stream.ts +16 -4
- package/src/server/responses/combo-selection-keepalive.ts +5 -0
- package/src/server/responses/combo-stream-preflight.ts +182 -73
- package/src/server/responses/compact-response-body.ts +27 -0
- package/src/server/responses/compact.ts +174 -121
- package/src/server/responses/compaction-recovery.ts +7 -0
- package/src/server/responses/core-codex-account.ts +88 -62
- package/src/server/responses/core-combo-failure.ts +15 -0
- package/src/server/responses/core-combo-native.ts +12 -1
- package/src/server/responses/core-combo.ts +340 -94
- package/src/server/responses/core-normalize.ts +19 -12
- package/src/server/responses/core-opaque-recovery.ts +15 -4
- package/src/server/responses/core-options.ts +50 -5
- package/src/server/responses/core-pipeline.ts +11 -0
- package/src/server/responses/core.ts +7 -1
- package/src/server/responses/empty-completion-guard.ts +21 -7
- package/src/server/responses/estimated-usage.ts +2 -1
- package/src/server/responses/fetch-helpers.ts +95 -19
- package/src/server/responses/history-slim.ts +204 -0
- package/src/server/responses/hosted-advisor-spend.ts +49 -0
- package/src/server/responses/image-context-recovery.ts +199 -0
- package/src/server/responses/input-admission.ts +36 -11
- package/src/server/responses/jev-model-invoke.ts +23 -16
- package/src/server/responses/non-replayable-error.ts +12 -2
- package/src/server/responses/passthrough-build-error.ts +5 -3
- package/src/server/responses/passthrough-delivery.ts +74 -33
- package/src/server/responses/passthrough-dispatch.ts +170 -197
- package/src/server/responses/policy-fallback.ts +7 -2
- package/src/server/responses/policy-request-scope.ts +36 -2
- package/src/server/responses/replay-owner.ts +20 -0
- package/src/server/responses/request-prepare.ts +97 -16
- package/src/server/responses/request-send-budget.ts +97 -25
- package/src/server/responses/request-sidecar-auth.ts +138 -65
- package/src/server/responses/request-spend-target.ts +13 -1
- package/src/server/responses/request-spend.ts +228 -47
- package/src/server/responses/request-transport.ts +395 -70
- package/src/server/responses/run-turn-execution.ts +40 -9
- package/src/server/responses/sidecar-execution.ts +214 -67
- package/src/server/responses/sidecar-send-budget.ts +9 -9
- package/src/server/responses/terminal-guard.ts +35 -9
- package/src/server/responses/ws-upstream.ts +27 -6
- package/src/server/responses-phase-inference.ts +32 -9
- package/src/server/responses-terminal-repair.ts +14 -35
- package/src/server/system-env.ts +8 -5
- package/src/server/ws-bridge.ts +23 -17
- package/src/service/health-sentinel-linux.ts +16 -7
- package/src/service/systemd.ts +11 -2
- package/src/service/windows-checked-stop-live.ts +60 -55
- package/src/service/windows-checked-stop.ts +29 -11
- package/src/service/windows-guarded-manager.ts +14 -26
- package/src/service/windows-process-evidence.ts +82 -74
- package/src/service/windows-process-native.ts +69 -20
- package/src/service/windows-service-stop.ts +14 -12
- package/src/service/windows-stop-binding.ts +14 -5
- package/src/service/windows-stop-confirm.ts +1 -1
- package/src/service/windows-task-instance-stop.ts +98 -0
- package/src/service/windows-taskxml.ts +30 -7
- package/src/sidecar/anthropic-binding.ts +1 -1
- package/src/stall-timeout.ts +30 -0
- package/src/telemetry/aggregate.ts +6 -3
- package/src/types/account-auto-pause.ts +19 -1
- package/src/types/accounts.ts +21 -0
- package/src/types/anthropic-account-pool.ts +1 -1
- package/src/types/combo-capability-policy.ts +19 -0
- package/src/types/config.ts +22 -2
- package/src/types/provider.ts +42 -8
- package/src/types/request.ts +15 -0
- package/src/types/tools.ts +22 -5
- package/src/types/wire.ts +1 -0
- package/src/types.ts +4 -0
- package/src/update/check-types.ts +2 -0
- package/src/update/job.ts +8 -3
- package/src/update/managed-release.ts +6 -0
- package/src/update/orchestrated-entry.ts +13 -4
- package/src/update/refresh-scheduler.ts +17 -7
- package/src/usage/attempt-delivery.ts +6 -0
- package/src/usage/cache-provenance.ts +71 -0
- package/src/usage/cost.ts +216 -27
- package/src/usage/credit-billing.ts +88 -0
- package/src/usage/jev-stats.ts +13 -9
- package/src/usage/log.ts +5 -33
- package/src/usage/summary.ts +8 -43
- package/src/usage/user-cost-overlays.ts +13 -1
- package/src/vision/index.ts +8 -3
- package/src/vision/plan.ts +28 -14
- package/src/vision/routed-describe.ts +24 -36
- package/src/web-search/header-deadline.ts +14 -3
- package/src/web-search/index.ts +6 -4
- package/src/web-search/loop.ts +240 -78
- package/src/web-search/progress-stream.ts +29 -2
- package/src/web-search/run-turn-loop.ts +5 -1
- package/gui/dist/assets/App-BGP8I0V4.css +0 -1
- package/gui/dist/assets/App-BRExzhwL.js +0 -60
- package/gui/dist/assets/Tray-DHCWAn8V.js +0 -1
- package/gui/dist/assets/brand-mark-C70PuQ3j.js +0 -1
- package/gui/dist/assets/index-DJxM-imn.css +0 -2
- package/gui/dist/assets/index-Dy1jIGty.js +0 -138
- package/gui/dist/classic/assets/App-B4j-Txmb.css +0 -1
- package/gui/dist/classic/assets/App-CaC-E6Vl.js +0 -59
- package/gui/dist/classic/assets/Tray-BG253fiL.js +0 -1
- package/gui/dist/classic/assets/index-CR_AThOp.js +0 -138
- package/gui/dist/classic/assets/quota-summary-B7KQPpEC.js +0 -1
package/src/codex/quota.ts
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { bindRawCodexDecisionResets, publishCodexDecisionQuota } from "../providers/quota-decision-publication";
|
|
2
2
|
import { clearDecisionAccountQuotas, decisionQuotaSinkActive } from "../lib/decision-quota-sink";
|
|
3
|
-
import { parseCodexCredits } from "./credits";
|
|
3
|
+
import { parseCodexCredits, type CodexCredits } from "./credits";
|
|
4
4
|
import { forgetMainAccountUsage, observeMainAccountUsage, type FreshWindow } from "./main-account-external-usage";
|
|
5
5
|
import { closeSync, constants as fsConstants, existsSync, fstatSync, openSync, readSync, unlinkSync } from "node:fs";
|
|
6
6
|
import { join } from "node:path";
|
|
7
7
|
import { atomicWriteFile, getConfigDir } from "../config";
|
|
8
8
|
import { withConfigDirHardeningSettled } from "../config/paths";
|
|
9
9
|
import { captureConfigGeneration, type GenerationContext } from "../lib/state-store-sweeper";
|
|
10
|
-
import { isThirtyDayOnlyCodexPlan } from "./plan";
|
|
10
|
+
import { codexPlanKey, isThirtyDayOnlyCodexPlan } from "./plan";
|
|
11
11
|
import { stampCodexQuotaUsageObservation } from "./quota-observation-freshness";
|
|
12
12
|
import { observeCodexLowQuota } from "./low-quota-observer";
|
|
13
13
|
import { MAIN_CODEX_ACCOUNT_ID } from "./account-id";
|
|
@@ -175,14 +175,25 @@ function finitePercent(value: number | undefined): value is number {
|
|
|
175
175
|
return typeof value === "number" && Number.isFinite(value);
|
|
176
176
|
}
|
|
177
177
|
|
|
178
|
-
|
|
178
|
+
function parseFiniteUsagePercent(value: unknown): number | undefined {
|
|
179
179
|
const numeric = typeof value === "number"
|
|
180
180
|
? value
|
|
181
181
|
: typeof value === "string" && value.trim() !== ""
|
|
182
182
|
? Number(value)
|
|
183
183
|
: undefined;
|
|
184
|
-
|
|
185
|
-
|
|
184
|
+
return typeof numeric === "number" && Number.isFinite(numeric) ? numeric : undefined;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
export function normalizeUsagePercent(value: unknown): number | undefined {
|
|
188
|
+
const numeric = parseFiniteUsagePercent(value);
|
|
189
|
+
return numeric === undefined ? undefined : Math.max(0, Math.min(100, numeric));
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
/** Undefined marks an absent group reading. Null marks invalid evidence. */
|
|
193
|
+
function parseGroupUsagePercent(value: unknown): number | null | undefined {
|
|
194
|
+
if (value == null) return undefined;
|
|
195
|
+
const percent = parseFiniteUsagePercent(value);
|
|
196
|
+
return percent === undefined || percent < 0 || percent > 100 ? null : percent;
|
|
186
197
|
}
|
|
187
198
|
|
|
188
199
|
/** Reject numeric policy evidence before legacy clamping can fabricate a valid reading. */
|
|
@@ -1097,8 +1108,10 @@ function filterMainPolicyMonthlyQuota(
|
|
|
1097
1108
|
* Null supplies no usable evidence.
|
|
1098
1109
|
*/
|
|
1099
1110
|
export function parseMainPolicyUsageQuota(data: WhamUsageResponse): MainPolicyQuotaObservation | null {
|
|
1111
|
+
const individualLimit = extractGroupBasedSpendControlLimit(data);
|
|
1100
1112
|
const windows = [data.rate_limit?.primary_window, data.rate_limit?.secondary_window, data.rate_limit?.tertiary_window];
|
|
1101
|
-
if (windows.some(window => isInvalidPolicyUsagePercent(window?.used_percent))
|
|
1113
|
+
if (windows.some(window => isInvalidPolicyUsagePercent(window?.used_percent))
|
|
1114
|
+
|| parseGroupUsagePercent(individualLimit?.used_percent) === null) return null;
|
|
1102
1115
|
const quota = filterMainPolicyMonthlyQuota(parseUsageQuota(data), isThirtyDayOnlyCodexPlan(data.plan_type));
|
|
1103
1116
|
// #8596: a complete, allowed main read retires a carried monthly tuple under the pool proof (#8067).
|
|
1104
1117
|
return quota ? withWhamMonthlyWindowAbsence(data, withWhamShortWindowAbsence(data, quota)) : null;
|
|
@@ -1177,6 +1190,30 @@ function spendControlAllowsCredits(control: unknown): boolean | undefined {
|
|
|
1177
1190
|
&& "reached" in control && control.reached === false;
|
|
1178
1191
|
}
|
|
1179
1192
|
|
|
1193
|
+
/** Extract group-based individual spend limit for Business/Enterprise plans when rate_limit is absent. */
|
|
1194
|
+
function extractGroupBasedSpendControlLimit(data: WhamUsageResponse): Record<string, unknown> | null {
|
|
1195
|
+
if (data.rate_limit || codexPlanKey(data.plan_type) !== "business") return null;
|
|
1196
|
+
const control = data.spend_control;
|
|
1197
|
+
if (!control || typeof control !== "object" || Array.isArray(control)) return null;
|
|
1198
|
+
const individualLimit = (control as Record<string, unknown>).individual_limit;
|
|
1199
|
+
if (!individualLimit || typeof individualLimit !== "object" || Array.isArray(individualLimit)) return null;
|
|
1200
|
+
const limitRecord = individualLimit as Record<string, unknown>;
|
|
1201
|
+
return limitRecord.source === "group_based_spend_controls" ? limitRecord : null;
|
|
1202
|
+
}
|
|
1203
|
+
|
|
1204
|
+
/** Normalize WHAM credits for both the quota snapshot and the account DTO. */
|
|
1205
|
+
export function parseWhamCredits(data: WhamUsageResponse): CodexCredits | null | undefined {
|
|
1206
|
+
const credits = parseCodexCredits(data.credits);
|
|
1207
|
+
if (!credits || (credits.balance !== undefined && Number.isFinite(Number(credits.balance)))) return credits;
|
|
1208
|
+
const raw = extractGroupBasedSpendControlLimit(data)?.remaining;
|
|
1209
|
+
const remaining = typeof raw === "number" ? raw
|
|
1210
|
+
: typeof raw === "string" && raw.trim() !== "" ? Number(raw) : undefined;
|
|
1211
|
+
if (remaining === undefined || !Number.isFinite(remaining) || remaining < 0) return credits;
|
|
1212
|
+
// Keep a plain decimal in the DTO and preserve the number when the snapshot parses it back.
|
|
1213
|
+
credits.balance = Math.abs(remaining).toLocaleString("en-US", { useGrouping: false, maximumSignificantDigits: 17 });
|
|
1214
|
+
return credits;
|
|
1215
|
+
}
|
|
1216
|
+
|
|
1180
1217
|
/**
|
|
1181
1218
|
* Normalize WHAM windows into the display snapshot, preserving declared short-window shape.
|
|
1182
1219
|
* Finite percentages are clamped for compatibility; policy callers must validate raw readings
|
|
@@ -1192,7 +1229,7 @@ export function parseUsageQuota(data: WhamUsageResponse): Omit<StoredAccountQuot
|
|
|
1192
1229
|
if (resetCredits !== undefined) quota.resetCredits = resetCredits;
|
|
1193
1230
|
if (data.credits !== undefined) {
|
|
1194
1231
|
quota.credits = null;
|
|
1195
|
-
const parsed =
|
|
1232
|
+
const parsed = parseWhamCredits(data);
|
|
1196
1233
|
if (parsed) {
|
|
1197
1234
|
const balance = parsed.balance === undefined ? undefined : Number(parsed.balance);
|
|
1198
1235
|
quota.credits = {
|
|
@@ -1210,7 +1247,31 @@ export function parseUsageQuota(data: WhamUsageResponse): Omit<StoredAccountQuot
|
|
|
1210
1247
|
// A missing/malformed summary retracts spending authority, but is re-observable.
|
|
1211
1248
|
// Explicit spending vetoes and legacy unmarked null retain conservative retry advice.
|
|
1212
1249
|
if (quota.credits === null && creditsAllowed !== false) quota.creditObservationUnavailable = true;
|
|
1213
|
-
if (!data.rate_limit)
|
|
1250
|
+
if (!data.rate_limit) {
|
|
1251
|
+
const individualLimit = extractGroupBasedSpendControlLimit(data);
|
|
1252
|
+
if (individualLimit) {
|
|
1253
|
+
// An out-of-range or malformed raw reading must not be clamped into a valid-looking bar;
|
|
1254
|
+
// leaving the monthly tuple unset lets the merge carry the stored reading forward.
|
|
1255
|
+
const usedPercent = parseGroupUsagePercent(individualLimit.used_percent);
|
|
1256
|
+
const monthlyPercent = usedPercent === undefined && (data.spend_control as Record<string, unknown>).reached === true
|
|
1257
|
+
? CODEX_EXHAUSTED_USAGE_PERCENT : usedPercent;
|
|
1258
|
+
if (monthlyPercent != null) {
|
|
1259
|
+
quota.monthlyPercent = monthlyPercent;
|
|
1260
|
+
const resetAt = normalizeResetAt(individualLimit.reset_at);
|
|
1261
|
+
if (resetAt !== undefined) quota.monthlyResetAt = resetAt;
|
|
1262
|
+
quota.monthlyIsPrimaryWindow = true;
|
|
1263
|
+
}
|
|
1264
|
+
if (decisionQuotaSinkActive() && quota.monthlyPercent !== undefined) {
|
|
1265
|
+
bindRawCodexDecisionResets(quota, {
|
|
1266
|
+
short: undefined,
|
|
1267
|
+
weekly: undefined,
|
|
1268
|
+
monthly: individualLimit.reset_at,
|
|
1269
|
+
}, Date.now());
|
|
1270
|
+
}
|
|
1271
|
+
return hasKnownQuotaValue(quota) || snapshotHasCredits(quota) ? quota : null;
|
|
1272
|
+
}
|
|
1273
|
+
return snapshotHasCredits(quota) ? quota : null;
|
|
1274
|
+
}
|
|
1214
1275
|
const thirtyDayOnly = codexQuotaWindowForPlan(data.plan_type) === "monthly";
|
|
1215
1276
|
const primaryWindow = data.rate_limit.primary_window;
|
|
1216
1277
|
const secondaryWindow = data.rate_limit.secondary_window;
|
|
@@ -1289,6 +1350,8 @@ export interface QuotaObservationEvidence {
|
|
|
1289
1350
|
|
|
1290
1351
|
/** Reject raw invalid readings before the compatibility parser clamps them into valid-looking bars. */
|
|
1291
1352
|
export function isValidWhamHistoryObservation(data: WhamUsageResponse): boolean {
|
|
1353
|
+
const individualLimit = extractGroupBasedSpendControlLimit(data);
|
|
1354
|
+
if (parseGroupUsagePercent(individualLimit?.used_percent) === null) return false;
|
|
1292
1355
|
const windows = [data.rate_limit?.primary_window, data.rate_limit?.secondary_window, data.rate_limit?.tertiary_window];
|
|
1293
1356
|
for (const limit of Array.isArray(data.additional_rate_limits) ? data.additional_rate_limits : []) {
|
|
1294
1357
|
if (limit && typeof limit === "object") windows.push(limit.rate_limit?.primary_window, limit.rate_limit?.secondary_window);
|
|
@@ -33,6 +33,8 @@ import {
|
|
|
33
33
|
type CodexQuotaScope,
|
|
34
34
|
} from "./health-store";
|
|
35
35
|
import { bindThreadAffinity, type CodexAffinityReason } from "./thread-affinity";
|
|
36
|
+
import { resetNearWeightOf } from "../../routing/machine-weighted-routing";
|
|
37
|
+
import { codexQuotaUsageObservedAt } from "../quota-observation-freshness";
|
|
36
38
|
import {
|
|
37
39
|
getEffectiveActiveCodexAccountId,
|
|
38
40
|
manualPreferenceBlocks,
|
|
@@ -268,7 +270,24 @@ function listEligibleCodexAccountIds(
|
|
|
268
270
|
/** Shared reset timestamps are not evidence for independent model-quota groups. */
|
|
269
271
|
export function accountPoolStrategyForScope(config: OcxConfig, quotaScope?: CodexQuotaScope) {
|
|
270
272
|
const strategy = normalizeCodexAccountPoolStrategy(config.accountPoolStrategy);
|
|
271
|
-
|
|
273
|
+
if (!isIndependentCodexQuotaScope(quotaScope)) return strategy;
|
|
274
|
+
if (strategy === "reset-first") return "quota";
|
|
275
|
+
return strategy === "reset-near-weighted" ? "round-robin" : strategy;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
function codexResetNearWeightOf(eligible: readonly string[], now: number) {
|
|
279
|
+
return resetNearWeightOf(eligible, id => {
|
|
280
|
+
const quota = getAccountQuota(id);
|
|
281
|
+
if (quota?.shortWindowSeconds !== 5 * 60 * 60) return null;
|
|
282
|
+
return {
|
|
283
|
+
weeklyPercent: quota.weeklyPercent,
|
|
284
|
+
weeklyResetAt: quota.weeklyResetAt,
|
|
285
|
+
weeklyObservedAt: codexQuotaUsageObservedAt(quota, "weeklyPercent"),
|
|
286
|
+
fiveHourPercent: quota.shortPercent,
|
|
287
|
+
fiveHourResetAt: quota.shortResetAt,
|
|
288
|
+
fiveHourObservedAt: codexQuotaUsageObservedAt(quota, "shortPercent"),
|
|
289
|
+
};
|
|
290
|
+
}, now);
|
|
272
291
|
}
|
|
273
292
|
|
|
274
293
|
function stickyLimitForConfig(config: OcxConfig): number {
|
|
@@ -507,7 +526,8 @@ export function pickUnboundStrategyAccount(
|
|
|
507
526
|
const poolKey = codexPoolKeyForScope(quotaScope);
|
|
508
527
|
|
|
509
528
|
let picked: string | null = null;
|
|
510
|
-
|
|
529
|
+
const resetNearWeighted = strategy === "reset-near-weighted";
|
|
530
|
+
if (strategy === "round-robin" || resetNearWeighted) {
|
|
511
531
|
const eligible = roundRobinPlacementCandidates(
|
|
512
532
|
config,
|
|
513
533
|
listEligibleCodexAccountIds(config, now, quotaScope, selectionOptions),
|
|
@@ -515,11 +535,12 @@ export function pickUnboundStrategyAccount(
|
|
|
515
535
|
quotaScope,
|
|
516
536
|
selectionOptions,
|
|
517
537
|
);
|
|
538
|
+
const weightOf = resetNearWeighted ? codexResetNearWeightOf(eligible, now) : undefined;
|
|
518
539
|
const limit = stickyLimitForConfig(config);
|
|
519
540
|
if (!commit) {
|
|
520
|
-
return peekRoundRobinAccount(poolKey, eligible, limit);
|
|
541
|
+
return peekRoundRobinAccount(poolKey, eligible, limit, weightOf);
|
|
521
542
|
}
|
|
522
|
-
picked = pickRoundRobinAccount(poolKey, eligible, limit);
|
|
543
|
+
picked = pickRoundRobinAccount(poolKey, eligible, limit, weightOf);
|
|
523
544
|
if (!picked) return null;
|
|
524
545
|
if (commitSharedActive && sharesActiveSelection(picked, selectionOptions)) {
|
|
525
546
|
if (!isIndependentCodexQuotaScope(quotaScope)
|
|
@@ -698,9 +719,10 @@ export function pickAlternateCodexAccount(
|
|
|
698
719
|
// result: when the excluded account is the only healthy member of the top
|
|
699
720
|
// tier, the tier walk must be free to descend instead of selecting that tier
|
|
700
721
|
// and then handing back an empty list.
|
|
701
|
-
if (strategy === "round-robin") {
|
|
722
|
+
if (strategy === "round-robin" || strategy === "reset-near-weighted") {
|
|
702
723
|
const eligible = getEligiblePoolAccounts(config, excludeId, now, quotaScope, selectionOptions);
|
|
703
|
-
|
|
724
|
+
const weightOf = strategy === "reset-near-weighted" ? codexResetNearWeightOf(eligible, now) : undefined;
|
|
725
|
+
return pickRoundRobinAccount(codexPoolKeyForScope(quotaScope), eligible, stickyLimitForConfig(config), weightOf);
|
|
704
726
|
}
|
|
705
727
|
if (strategy === "fill-first") {
|
|
706
728
|
const eligible = getEligiblePoolAccounts(config, excludeId, now, quotaScope, selectionOptions);
|
|
@@ -731,9 +753,11 @@ export function peekAlternateCodexAccount(
|
|
|
731
753
|
quotaScope?: CodexQuotaScope,
|
|
732
754
|
selectionOptions?: CodexAccountUsabilityOptions,
|
|
733
755
|
): string | null {
|
|
734
|
-
|
|
756
|
+
const strategy = accountPoolStrategyForScope(config, quotaScope);
|
|
757
|
+
if (strategy === "round-robin" || strategy === "reset-near-weighted") {
|
|
735
758
|
const eligible = getEligiblePoolAccounts(config, excludeId, now, quotaScope, selectionOptions);
|
|
736
|
-
|
|
759
|
+
const weightOf = strategy === "reset-near-weighted" ? codexResetNearWeightOf(eligible, now) : undefined;
|
|
760
|
+
return peekRoundRobinAccount(codexPoolKeyForScope(quotaScope), eligible, stickyLimitForConfig(config), weightOf);
|
|
737
761
|
}
|
|
738
762
|
return pickAlternateCodexAccount(config, excludeId, now, quotaScope, selectionOptions);
|
|
739
763
|
}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { codexEffortRank } from "../reasoning-effort";
|
|
2
|
+
import type { OcxComboCapabilityPolicy, OcxComboReasoningEffortMode } from "../types";
|
|
3
|
+
|
|
4
|
+
/** Distinct values across every list, in first-seen order. */
|
|
5
|
+
export function unionStrings(values: readonly (readonly string[])[]): string[] {
|
|
6
|
+
return [...new Set(values.flat())];
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
/** Distinct rungs across every ladder; known rungs sort by rank, unknown ones keep first-seen order last. */
|
|
10
|
+
export function unionEfforts(ladders: readonly (readonly string[])[]): string[] {
|
|
11
|
+
const rank = (effort: string): number => {
|
|
12
|
+
const value = codexEffortRank(effort);
|
|
13
|
+
return value < 0 ? Number.MAX_SAFE_INTEGER : value;
|
|
14
|
+
};
|
|
15
|
+
return unionStrings(ladders)
|
|
16
|
+
.map((effort, index) => ({ effort, index }))
|
|
17
|
+
.sort((a, b) => rank(a.effort) - rank(b.effort) || a.index - b.index)
|
|
18
|
+
.map(item => item.effort);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* Whether a combo advertises the union of its members' effort ladders. Only `union` combos in
|
|
23
|
+
* `adaptive` mode do: `strict` still promises that every member serves the advertised rung as
|
|
24
|
+
* is, and dispatch snaps a caller rung to each member's ladder (`clampComboCallerEffort`).
|
|
25
|
+
*/
|
|
26
|
+
export function comboAdvertisesEffortUnion(
|
|
27
|
+
policy: OcxComboCapabilityPolicy | undefined,
|
|
28
|
+
mode: OcxComboReasoningEffortMode,
|
|
29
|
+
): boolean {
|
|
30
|
+
return policy === "union" && mode === "adaptive";
|
|
31
|
+
}
|
package/src/combos/failover.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { parseResetCooldownMs } from "../codex/routing";
|
|
2
2
|
import { CYBER_POLICY_FALLBACK_MESSAGE, TERMINAL_REFUSAL_FALLBACK_MESSAGE, classifyError, isCyberPolicyCode, isCyberPolicyMessage, isRateLimitOrQuotaFailureMessage, isSubscriptionGateMessage, isTerminalRefusalCode, safetyRefusalCodeFromMessage } from "../lib/errors";
|
|
3
3
|
import { isHardPolicyOrOriginRefusal } from "../lib/hard-refusal";
|
|
4
|
+
import { parseHttpDate } from "../lib/http-date";
|
|
4
5
|
import { isNonReplayableUpstreamCode } from "../lib/upstream-retry";
|
|
5
6
|
import { isAnthropicBillingFailure, isAnthropicExtraUsageFailure } from "../providers/anthropic-billing-refusal";
|
|
6
7
|
import { hasConflictingReasoningEffortCode } from "../providers/reasoning-metadata";
|
|
@@ -43,14 +44,6 @@ const QUOTA_LIMIT_CODES = new Set([
|
|
|
43
44
|
"insufficient_quota",
|
|
44
45
|
]);
|
|
45
46
|
const TRANSIENT_REQUEST_RATE_CODES = new Set(["1302", "1305"]);
|
|
46
|
-
const IMF_FIXDATE_RE = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun), (\d{2}) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) (\d{4}) (\d{2}):(\d{2}):(\d{2}) GMT$/i;
|
|
47
|
-
const RFC850_DATE_RE = /^(?:Monday|Tuesday|Wednesday|Thursday|Friday|Saturday|Sunday), (\d{2})-(Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec)-(\d{2}) (\d{2}):(\d{2}):(\d{2}) GMT$/i;
|
|
48
|
-
const ASCTIME_DATE_RE = /^(?:Mon|Tue|Wed|Thu|Fri|Sat|Sun) (Jan|Feb|Mar|Apr|May|Jun|Jul|Aug|Sep|Oct|Nov|Dec) ( \d|\d{2}) (\d{2}):(\d{2}):(\d{2}) (\d{4})$/i;
|
|
49
|
-
const HTTP_MONTH_INDEX: Record<string, number> = {
|
|
50
|
-
jan: 0, feb: 1, mar: 2, apr: 3, may: 4, jun: 5,
|
|
51
|
-
jul: 6, aug: 7, sep: 8, oct: 9, nov: 10, dec: 11,
|
|
52
|
-
};
|
|
53
|
-
|
|
54
47
|
/** Map<`${comboId}\0${provider/model}`, TargetCooldown> */
|
|
55
48
|
// Never reset: an in-flight reservation may still refer to an entry cleared from the map.
|
|
56
49
|
let nextCooldownRevision = 0;
|
|
@@ -67,71 +60,6 @@ function cooldownMapKey(
|
|
|
67
60
|
return `${comboId}\0${targetKey(target)}`;
|
|
68
61
|
}
|
|
69
62
|
|
|
70
|
-
function parseUtcDateParts(
|
|
71
|
-
year: number,
|
|
72
|
-
monthName: string,
|
|
73
|
-
day: number,
|
|
74
|
-
hour: number,
|
|
75
|
-
minute: number,
|
|
76
|
-
second: number,
|
|
77
|
-
): number | undefined {
|
|
78
|
-
const month = HTTP_MONTH_INDEX[monthName.toLowerCase()];
|
|
79
|
-
if (month === undefined) return undefined;
|
|
80
|
-
const timestamp = Date.UTC(year, month, day, hour, minute, second);
|
|
81
|
-
const parsed = new Date(timestamp);
|
|
82
|
-
return parsed.getUTCFullYear() === year
|
|
83
|
-
&& parsed.getUTCMonth() === month
|
|
84
|
-
&& parsed.getUTCDate() === day
|
|
85
|
-
&& parsed.getUTCHours() === hour
|
|
86
|
-
&& parsed.getUTCMinutes() === minute
|
|
87
|
-
&& parsed.getUTCSeconds() === second
|
|
88
|
-
? timestamp
|
|
89
|
-
: undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function parseHttpDate(value: string, now: number): number | undefined {
|
|
93
|
-
const imf = IMF_FIXDATE_RE.exec(value);
|
|
94
|
-
if (imf) {
|
|
95
|
-
return parseUtcDateParts(
|
|
96
|
-
Number(imf[3]), imf[2]!, Number(imf[1]),
|
|
97
|
-
Number(imf[4]), Number(imf[5]), Number(imf[6]),
|
|
98
|
-
);
|
|
99
|
-
}
|
|
100
|
-
const rfc850 = RFC850_DATE_RE.exec(value);
|
|
101
|
-
if (rfc850) {
|
|
102
|
-
const current = new Date(now);
|
|
103
|
-
const currentYear = current.getUTCFullYear();
|
|
104
|
-
const month = HTTP_MONTH_INDEX[rfc850[2]!.toLowerCase()];
|
|
105
|
-
if (month === undefined) return undefined;
|
|
106
|
-
let year = Math.floor(currentYear / 100) * 100 + Number(rfc850[3]);
|
|
107
|
-
const yearDelta = year - currentYear;
|
|
108
|
-
const candidateTimeOfYear = Date.UTC(
|
|
109
|
-
2000, month, Number(rfc850[1]),
|
|
110
|
-
Number(rfc850[4]), Number(rfc850[5]), Number(rfc850[6]),
|
|
111
|
-
);
|
|
112
|
-
const currentTimeOfYear = Date.UTC(
|
|
113
|
-
2000, current.getUTCMonth(), current.getUTCDate(),
|
|
114
|
-
current.getUTCHours(), current.getUTCMinutes(), current.getUTCSeconds(),
|
|
115
|
-
current.getUTCMilliseconds(),
|
|
116
|
-
);
|
|
117
|
-
if (yearDelta < -50 || (yearDelta === -50 && candidateTimeOfYear < currentTimeOfYear)) {
|
|
118
|
-
year += 100;
|
|
119
|
-
} else if (yearDelta > 50 || (yearDelta === 50 && candidateTimeOfYear > currentTimeOfYear)) {
|
|
120
|
-
year -= 100;
|
|
121
|
-
}
|
|
122
|
-
return parseUtcDateParts(
|
|
123
|
-
year, rfc850[2]!, Number(rfc850[1]),
|
|
124
|
-
Number(rfc850[4]), Number(rfc850[5]), Number(rfc850[6]),
|
|
125
|
-
);
|
|
126
|
-
}
|
|
127
|
-
const asctime = ASCTIME_DATE_RE.exec(value);
|
|
128
|
-
if (!asctime) return undefined;
|
|
129
|
-
return parseUtcDateParts(
|
|
130
|
-
Number(asctime[6]), asctime[1]!, Number(asctime[2]),
|
|
131
|
-
Number(asctime[3]), Number(asctime[4]), Number(asctime[5]),
|
|
132
|
-
);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
63
|
/** Parse a Retry-After delay, optionally retaining an upstream delay up to one day. */
|
|
136
64
|
export function parseRetryAfterMs(
|
|
137
65
|
value: string | null | undefined,
|
|
@@ -154,7 +82,7 @@ export function parseRetryAfterMs(
|
|
|
154
82
|
return Math.min(Math.max(Math.ceil(seconds * 1000), 1), maximum);
|
|
155
83
|
}
|
|
156
84
|
}
|
|
157
|
-
const timestamp = parseHttpDate(text, now);
|
|
85
|
+
const timestamp = parseHttpDate(text, now, { legacy: true });
|
|
158
86
|
if (timestamp === undefined) return undefined;
|
|
159
87
|
const delay = timestamp - now;
|
|
160
88
|
if (delay > 0) return Math.min(delay, maximum);
|
|
@@ -330,6 +258,81 @@ export function coolComboTarget(
|
|
|
330
258
|
return true;
|
|
331
259
|
}
|
|
332
260
|
|
|
261
|
+
/**
|
|
262
|
+
* failureDetail codes that cool a combo target after a COMMITTED terminal.
|
|
263
|
+
* Pre-commit failures already cool through the hop path; these are the
|
|
264
|
+
* post-commit `incomplete` terminals that path never sees, so without this
|
|
265
|
+
* the next request picks the same target and burns the same budget again.
|
|
266
|
+
*/
|
|
267
|
+
export type CommittedIncompleteReason = "max_output_tokens" | "upstream_stall_timeout";
|
|
268
|
+
|
|
269
|
+
const COMMITTED_TERMINAL_COOLDOWN_MS: Readonly<Record<CommittedIncompleteReason, number>> = {
|
|
270
|
+
// The target cannot emit more than its output ceiling; a request that
|
|
271
|
+
// exhausted it will exhaust it again, so this uses the local cooldown cap.
|
|
272
|
+
max_output_tokens: MAX_COOLDOWN_MS,
|
|
273
|
+
// Upstream went silent mid-stream after committing output — a health
|
|
274
|
+
// signal, but transient, so the standard short cooldown applies.
|
|
275
|
+
upstream_stall_timeout: DEFAULT_COOLDOWN_MS,
|
|
276
|
+
};
|
|
277
|
+
|
|
278
|
+
export interface CommittedTerminalServingAttempt {
|
|
279
|
+
provider: string;
|
|
280
|
+
model: string;
|
|
281
|
+
status: number;
|
|
282
|
+
locallyAnswered?: boolean;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
export interface CommittedTerminalCooldownFacts {
|
|
286
|
+
comboId?: string;
|
|
287
|
+
terminalStatus?: string;
|
|
288
|
+
terminalReason?: CommittedIncompleteReason;
|
|
289
|
+
servingAttempt?: CommittedTerminalServingAttempt;
|
|
290
|
+
httpStatus?: number;
|
|
291
|
+
target?: Pick<OcxComboTarget, "provider" | "model">;
|
|
292
|
+
writerGeneration?: number;
|
|
293
|
+
outputTokens?: number;
|
|
294
|
+
outputCeiling?: number | null;
|
|
295
|
+
isPaused?: boolean;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
/**
|
|
299
|
+
* Record a bounded cooldown when a combo child commits output and then ends
|
|
300
|
+
* `incomplete` for a target-capacity or upstream-silence reason. The response
|
|
301
|
+
* is already delivered — this only shapes the NEXT pick, so the caller's
|
|
302
|
+
* effort and context configuration stay untouched.
|
|
303
|
+
*/
|
|
304
|
+
export function coolComboTargetForCommittedTerminal(facts: CommittedTerminalCooldownFacts): void {
|
|
305
|
+
if (!facts.comboId || facts.terminalStatus !== "incomplete") return;
|
|
306
|
+
const cooldownMs = facts.terminalReason === undefined
|
|
307
|
+
? undefined
|
|
308
|
+
: COMMITTED_TERMINAL_COOLDOWN_MS[facts.terminalReason];
|
|
309
|
+
if (cooldownMs === undefined) return;
|
|
310
|
+
if (facts.terminalReason === "max_output_tokens") {
|
|
311
|
+
// Reaching the caller's own allowance (routine for Claude Code) or an Anthropic pause_turn
|
|
312
|
+
// must not cool a healthy target. Cool only when the turn was unpaused, the target's own
|
|
313
|
+
// ceiling is known, and the output actually reached that ceiling.
|
|
314
|
+
if (facts.isPaused === true) return;
|
|
315
|
+
if (facts.outputCeiling == null || (facts.outputTokens ?? 0) < facts.outputCeiling) return;
|
|
316
|
+
}
|
|
317
|
+
const attempt = facts.servingAttempt;
|
|
318
|
+
// The incomplete terminal is itself proof the target ran: a late stall surfaces to
|
|
319
|
+
// the client as a 5xx attempt status, so gating on status < 400 would silence exactly
|
|
320
|
+
// the case this cooldown exists for.
|
|
321
|
+
if (!attempt || attempt.locallyAnswered === true) return;
|
|
322
|
+
// Combo selection evaluates cooldowns against pick.target (which preserves any alias selector
|
|
323
|
+
// the combo named); fall back to the routed physical attempt only when facts omits the target.
|
|
324
|
+
const target = facts.target ?? { provider: attempt.provider, model: attempt.model };
|
|
325
|
+
// A shorter committed-terminal cooldown must not shorten a longer live one — a
|
|
326
|
+
// server Retry-After or reset already recorded for this target stays authoritative.
|
|
327
|
+
const existing = targetCooldowns.get(cooldownMapKey(facts.comboId, target));
|
|
328
|
+
if (existing && existing.cooldownUntil > Date.now() + cooldownMs) return;
|
|
329
|
+
coolComboTarget(facts.comboId, target, {
|
|
330
|
+
cooldownMs,
|
|
331
|
+
status: facts.httpStatus,
|
|
332
|
+
writerGeneration: facts.writerGeneration,
|
|
333
|
+
});
|
|
334
|
+
}
|
|
335
|
+
|
|
333
336
|
export function earliestComboCooldown(
|
|
334
337
|
comboId: string,
|
|
335
338
|
targets: Iterable<Pick<OcxComboTarget, "provider" | "model">>,
|
|
@@ -1758,6 +1761,11 @@ function decideComboFailure(
|
|
|
1758
1761
|
if (rawCode === "input_admission_refused" || error.code === "input_admission_refused") {
|
|
1759
1762
|
return "hop";
|
|
1760
1763
|
}
|
|
1764
|
+
// A degenerate completion is target-local evidence: the child ended its turn carrying only
|
|
1765
|
+
// reasoning/commentary prelude. Another target can still serve the same request.
|
|
1766
|
+
if (rawCode === "degenerate_completion" || error.code === "degenerate_completion") {
|
|
1767
|
+
return "hop";
|
|
1768
|
+
}
|
|
1761
1769
|
if (isProviderScopedQuotaCap(status, message, rawCode || error.code)) {
|
|
1762
1770
|
return "hop";
|
|
1763
1771
|
}
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { SUPPORTED_NATIVE_OPENAI_SLUGS } from "../codex/catalog/native-models";
|
|
2
|
-
import type { OcxComboConfig, OcxComboTarget
|
|
2
|
+
import type { OcxComboConfig, OcxComboTarget } from "../types";
|
|
3
3
|
|
|
4
4
|
export const COMBO_NAMESPACE = "combo";
|
|
5
5
|
|
|
6
6
|
export function preservesPhysicalComboProvider(
|
|
7
|
-
config:
|
|
7
|
+
config: { providers: Record<string, unknown>; combos?: Record<string, unknown> },
|
|
8
8
|
): boolean {
|
|
9
9
|
return Object.hasOwn(config.providers, COMBO_NAMESPACE)
|
|
10
10
|
&& Object.keys(config.combos ?? {}).length === 0;
|
package/src/combos/index.ts
CHANGED
|
@@ -47,6 +47,7 @@ export {
|
|
|
47
47
|
comboCooldownRetryAfterSeconds,
|
|
48
48
|
COMBO_REQUEST_RATE_COOLDOWN_MS,
|
|
49
49
|
coolComboTarget,
|
|
50
|
+
coolComboTargetForCommittedTerminal,
|
|
50
51
|
earliestComboCooldown,
|
|
51
52
|
earliestComboCooldownExpiry,
|
|
52
53
|
isComboTargetInCooldown,
|
|
@@ -57,6 +58,8 @@ export {
|
|
|
57
58
|
comboFailureCooldownScope,
|
|
58
59
|
type ComboFailureDecision,
|
|
59
60
|
type ComboFailureCooldownScope,
|
|
61
|
+
type CommittedTerminalCooldownFacts,
|
|
62
|
+
type CommittedTerminalServingAttempt,
|
|
60
63
|
} from "./failover";
|
|
61
64
|
export {
|
|
62
65
|
comboIdFromRawBody,
|
|
@@ -17,7 +17,11 @@ import {
|
|
|
17
17
|
} from "./jev";
|
|
18
18
|
|
|
19
19
|
export class JevModelInvokeError extends Error {
|
|
20
|
-
constructor(
|
|
20
|
+
constructor(
|
|
21
|
+
readonly gate: "http" | "network" | "malformed" | "missing_key",
|
|
22
|
+
message?: string,
|
|
23
|
+
readonly usage?: Record<string, number>,
|
|
24
|
+
) {
|
|
21
25
|
super(message);
|
|
22
26
|
this.name = "JevModelInvokeError";
|
|
23
27
|
}
|
|
@@ -125,14 +129,15 @@ export async function resolveJevModelDecision(
|
|
|
125
129
|
if (result.quotaOmitted) candidates = candidates.map(({ quota: _quota, ...row }) => row);
|
|
126
130
|
if (options.signal?.aborted) throw options.signal.reason;
|
|
127
131
|
if (timeoutSignal.aborted) return failed("timeout");
|
|
132
|
+
const usage = jevUsage({ usage: result.usage });
|
|
128
133
|
let choice: string;
|
|
129
134
|
try {
|
|
130
135
|
choice = parseJevModelChoice(result.text, new Set(routeOptions.map(option => option.key)));
|
|
131
136
|
} catch (error) {
|
|
132
|
-
|
|
137
|
+
const decision = failed(error instanceof JevModelInvokeError ? error.gate : "invalid");
|
|
138
|
+
return usage ? { ...decision, usage } : decision;
|
|
133
139
|
}
|
|
134
140
|
const selected = routeOptions.find(option => option.key === choice)!;
|
|
135
|
-
const usage = jevUsage({ usage: result.usage });
|
|
136
141
|
if (options.signal?.aborted) throw options.signal.reason;
|
|
137
142
|
return withJevQuotaSummary({
|
|
138
143
|
backend: "model",
|
|
@@ -145,6 +150,9 @@ export async function resolveJevModelDecision(
|
|
|
145
150
|
} catch (error) {
|
|
146
151
|
if (options.signal?.aborted) throw options.signal.reason;
|
|
147
152
|
if (timeoutSignal.aborted || (error instanceof Error && error.name === "TimeoutError")) return failed("timeout");
|
|
148
|
-
|
|
153
|
+
if (!(error instanceof JevModelInvokeError)) return failed("network");
|
|
154
|
+
const decision = failed(error.gate);
|
|
155
|
+
const usage = jevUsage({ usage: error.usage });
|
|
156
|
+
return usage ? { ...decision, usage } : decision;
|
|
149
157
|
}
|
|
150
158
|
}
|
|
@@ -11,11 +11,18 @@ export const JEV_SESSION_PIN_TTL_MAX_MS = 86_400_000;
|
|
|
11
11
|
export interface JevSessionPinConfig {
|
|
12
12
|
/** Idle window after the last successful pinned turn; a quieter session is decided afresh. */
|
|
13
13
|
ttlMs: number;
|
|
14
|
+
/**
|
|
15
|
+
* `per-turn` keeps the pinned target but asks the decision backend for its effort on every
|
|
16
|
+
* pinned turn, offering only the pinned target's efforts. Absent (the default) reuses the
|
|
17
|
+
* pinned effort too. `pinned` is accepted as input and normalized away.
|
|
18
|
+
*/
|
|
19
|
+
effort?: "per-turn";
|
|
14
20
|
}
|
|
15
21
|
|
|
16
22
|
/**
|
|
17
23
|
* Closed persisted vocabulary: `session` marks a turn that reused its pin; every other value names
|
|
18
|
-
* why an existing pin was released before a fresh decision.
|
|
24
|
+
* why an existing pin was released before a fresh decision. `session_effort` marks a pinned turn
|
|
25
|
+
* whose effort was decided afresh (`effort: "per-turn"`), so it also sent a decision request.
|
|
19
26
|
*/
|
|
20
27
|
export const JEV_SESSION_PIN_REASONS = [
|
|
21
28
|
"session",
|
|
@@ -24,20 +31,26 @@ export const JEV_SESSION_PIN_REASONS = [
|
|
|
24
31
|
"target_unavailable",
|
|
25
32
|
"effort_unavailable",
|
|
26
33
|
"quota_nearly_exhausted",
|
|
34
|
+
"session_effort",
|
|
27
35
|
] as const;
|
|
28
36
|
export type JevSessionPinReason = (typeof JEV_SESSION_PIN_REASONS)[number];
|
|
29
|
-
export type JevSessionPinRelease = Exclude<JevSessionPinReason, "session">;
|
|
37
|
+
export type JevSessionPinRelease = Exclude<JevSessionPinReason, "session" | "session_effort">;
|
|
38
|
+
/** Reasons persisted with `pinned: true`: the turn kept its session target. */
|
|
39
|
+
export const JEV_SESSION_PINNED_REASONS: readonly JevSessionPinReason[] = ["session", "session_effort"];
|
|
30
40
|
|
|
31
|
-
/**
|
|
41
|
+
/**
|
|
42
|
+
* The canonical pin setting, or undefined for anything other than `{ ttlMs }` in range with an
|
|
43
|
+
* optional `effort` of `pinned` or `per-turn`.
|
|
44
|
+
*/
|
|
32
45
|
export function normalizeJevSessionPin(value: unknown): JevSessionPinConfig | undefined {
|
|
33
46
|
if (!value || typeof value !== "object" || Array.isArray(value)) return undefined;
|
|
34
47
|
const keys = Object.keys(value);
|
|
35
|
-
if (keys.
|
|
36
|
-
const ttlMs =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
48
|
+
if (!keys.includes("ttlMs") || keys.some(key => key !== "ttlMs" && key !== "effort")) return undefined;
|
|
49
|
+
const { ttlMs, effort } = value as { ttlMs?: unknown; effort?: unknown };
|
|
50
|
+
if (effort !== undefined && effort !== "pinned" && effort !== "per-turn") return undefined;
|
|
51
|
+
if (typeof ttlMs !== "number" || !Number.isSafeInteger(ttlMs)
|
|
52
|
+
|| ttlMs < JEV_SESSION_PIN_TTL_MIN_MS || ttlMs > JEV_SESSION_PIN_TTL_MAX_MS) return undefined;
|
|
53
|
+
return effort === "per-turn" ? { ttlMs, effort } : { ttlMs };
|
|
41
54
|
}
|
|
42
55
|
|
|
43
56
|
const DURATION_UNITS_MS: Readonly<Record<string, number>> = { ms: 1, s: 1_000, m: 60_000, h: 3_600_000 };
|
package/src/combos/jev.ts
CHANGED
|
@@ -112,9 +112,9 @@ export interface JevDecision {
|
|
|
112
112
|
confidence?: number;
|
|
113
113
|
chosenProbability?: number;
|
|
114
114
|
usage?: Record<string, number>;
|
|
115
|
-
/** Set when
|
|
115
|
+
/** Set when the turn reused a session pin (#7525). */
|
|
116
116
|
pinned?: true;
|
|
117
|
-
/** `session` with `pinned`; otherwise why
|
|
117
|
+
/** `session` or `session_effort` with `pinned`; otherwise why the original pin was released. */
|
|
118
118
|
pinReason?: import("./jev-session-pin-config").JevSessionPinReason;
|
|
119
119
|
}
|
|
120
120
|
|
|
@@ -701,6 +701,7 @@ export async function resolveJevDecision(options: ResolveJevDecisionOptions): Pr
|
|
|
701
701
|
if (!candidatesFitRequestBounds(options.candidates)) return failed("invalid");
|
|
702
702
|
|
|
703
703
|
let candidates = options.candidates;
|
|
704
|
+
let rejectedUsage: JevDecision["usage"];
|
|
704
705
|
const exchanged = await exchangeJevDecision(options, (endpoint) => {
|
|
705
706
|
const isDecisions = Boolean(endpoint.url && isDecisionsEndpoint(endpoint.url));
|
|
706
707
|
const optionCount = candidateOptions(options.candidates).size;
|
|
@@ -748,8 +749,18 @@ export async function resolveJevDecision(options: ResolveJevDecisionOptions): Pr
|
|
|
748
749
|
}), REQUEST_LIMIT);
|
|
749
750
|
candidates = payload.candidates;
|
|
750
751
|
return { body: payload.body };
|
|
751
|
-
}, (payload) =>
|
|
752
|
-
|
|
752
|
+
}, (payload) => {
|
|
753
|
+
try {
|
|
754
|
+
return parseJevDecision(payload, options.candidates);
|
|
755
|
+
} catch (error) {
|
|
756
|
+
if (isRecord(payload)) rejectedUsage = jevUsage(payload);
|
|
757
|
+
throw error;
|
|
758
|
+
}
|
|
759
|
+
});
|
|
760
|
+
if ("gate" in exchanged) {
|
|
761
|
+
const decision = failed(exchanged.gate);
|
|
762
|
+
return withJevQuotaSummary(rejectedUsage ? { ...decision, usage: rejectedUsage } : decision, candidates);
|
|
763
|
+
}
|
|
753
764
|
return withJevQuotaSummary({
|
|
754
765
|
backend,
|
|
755
766
|
...exchanged.value,
|