@bitkyc08/opencodex 2.93.0-preview.20261027 → 2.94.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/README.md +27 -8
- package/bin/ocx.mjs +215 -63
- package/gui/dist/assets/App-DmvwlhQq.js +58 -0
- package/gui/dist/assets/Tray-CZatQdoF.js +1 -0
- package/gui/dist/assets/index-3EPO_KbX.js +94 -0
- package/gui/dist/assets/index-CHWwDo9L.css +1 -0
- package/gui/dist/assets/{quota-summary-DxToX1rV.js → quota-summary-BHvWg9mi.js} +1 -1
- package/gui/dist/index.html +2 -2
- package/gui/dist/provider-icons/t3code.svg +4 -0
- package/package.json +7 -4
- package/src/adapters/anthropic/account-metadata.ts +34 -3
- package/src/adapters/anthropic/beta-allowlist.ts +5 -5
- package/src/adapters/anthropic/passthrough.ts +5 -2
- package/src/adapters/anthropic.ts +17 -4
- package/src/adapters/antigravity-refusal.ts +29 -0
- package/src/adapters/base.ts +11 -1
- package/src/adapters/client-fingerprint.ts +43 -9
- package/src/adapters/coding-agent/protocol.ts +19 -9
- package/src/adapters/command-code.ts +4 -5
- package/src/adapters/cursor/catalog.ts +5 -3
- package/src/adapters/cursor/claude-id.ts +30 -19
- package/src/adapters/cursor/cursor-errors.ts +5 -2
- package/src/adapters/cursor/h2-pool.ts +9 -7
- package/src/adapters/cursor/http1-bidi.ts +1 -0
- package/src/adapters/cursor/live-models.ts +4 -2
- package/src/adapters/cursor.ts +4 -1
- package/src/adapters/devin/cloud-direct/chat.ts +18 -2
- package/src/adapters/google-antigravity-replay.ts +13 -2
- package/src/adapters/google-antigravity-wire.ts +8 -3
- package/src/adapters/google-errors.ts +33 -0
- package/src/adapters/google-http.ts +41 -16
- package/src/adapters/google-wire-compiler.ts +4 -0
- package/src/adapters/google.ts +21 -10
- package/src/adapters/kiro/adapter.ts +3 -0
- package/src/adapters/kiro/stream.ts +18 -13
- package/src/adapters/openai-chat/completed-tool-blocks.ts +65 -0
- package/src/adapters/openai-chat/messages.ts +22 -10
- package/src/adapters/openai-chat/required-tool-result.ts +3 -3
- package/src/adapters/openai-chat/serialized-tool-call-content.ts +5 -0
- package/src/adapters/openai-chat/wire.ts +9 -0
- package/src/adapters/openai-chat.ts +18 -17
- package/src/adapters/openai-responses/image-gen.ts +15 -1
- package/src/adapters/openai-responses/passthrough.ts +11 -34
- package/src/adapters/openai-responses/transport.ts +20 -2
- package/src/adapters/openai-responses/usage.ts +34 -0
- package/src/adapters/qoder/adapter.ts +9 -15
- package/src/adapters/qoder/image-input.ts +52 -0
- package/src/adapters/unique-tool-call-ids.ts +2 -2
- package/src/adapters/zed-additional-tools.ts +51 -0
- package/src/adapters/zed-diagnostic-usage.ts +22 -0
- package/src/adapters/zed-json-tokens.ts +166 -0
- package/src/adapters/zed-openai-stream.ts +723 -0
- package/src/adapters/zed-tool-arguments.ts +79 -0
- package/src/adapters/zed.ts +53 -3
- package/src/advisor/consult.ts +22 -0
- package/src/advisor/runtime.ts +3 -0
- package/src/bridge/errors.ts +22 -1
- package/src/bridge/response-json.ts +4 -1
- package/src/bridge/sse.ts +21 -12
- package/src/chat/inbound.ts +13 -2
- package/src/chatgpt/app-server-shim/bundle-trust-async.ts +111 -0
- package/src/chatgpt/app-server-shim/bundle-trust-policy.ts +83 -0
- package/src/chatgpt/app-server-shim/bundle-trust.ts +15 -72
- package/src/claude/desktop-first-party.ts +16 -5
- package/src/claude/desktop-gateway-state.ts +4 -0
- package/src/claude/inbound-tool-loading.ts +93 -0
- package/src/claude/intercept/picker-listener.ts +33 -1
- package/src/claude/model-info.ts +29 -4
- package/src/claude/outbound.ts +33 -13
- package/src/cli/account-main.ts +43 -5
- package/src/cli/capabilities-base.ts +22 -5
- package/src/cli/capabilities-integrations.ts +4 -4
- package/src/cli/claude-desktop.ts +139 -98
- package/src/cli/codex-cli-update.ts +102 -48
- package/src/cli/codex-launch-auth.ts +93 -0
- package/src/cli/codex-launch-command.ts +32 -0
- package/src/cli/codex-launch-diagnostics.ts +37 -0
- package/src/cli/codex-launch-ownership.ts +307 -0
- package/src/cli/codex-launch-policy.ts +84 -0
- package/src/cli/codex-launcher.ts +310 -0
- package/src/cli/codex-shim-autorestore.ts +2 -0
- package/src/cli/config-command.ts +9 -4
- package/src/cli/config-mutation.ts +13 -0
- package/src/cli/dispatch.ts +13 -7
- package/src/cli/effort.ts +19 -14
- package/src/cli/ensure-desired-integrations.ts +21 -14
- package/src/cli/ensure-desktop-cold-start.ts +41 -10
- package/src/cli/export-command.ts +8 -4
- package/src/cli/help.ts +3 -1
- package/src/cli/index.ts +58 -64
- package/src/cli/integration-input.ts +12 -0
- package/src/cli/integration-plan-dto.ts +2 -0
- package/src/cli/integration-preview.ts +6 -3
- package/src/cli/integrations.ts +2 -1
- package/src/cli/link-cleanup.ts +8 -23
- package/src/cli/link-enrollment.ts +1 -4
- package/src/cli/link.ts +1 -1
- package/src/cli/loopback-family.ts +2 -31
- package/src/cli/models.ts +62 -49
- package/src/cli/provider.ts +146 -139
- package/src/cli/registry.ts +34 -3
- package/src/cli/root.ts +2 -0
- package/src/cli/start-owner-fence.ts +22 -3
- package/src/cli/status-link.ts +28 -0
- package/src/cli/status.ts +15 -0
- package/src/cli/stop-restore-guard.ts +48 -0
- package/src/cli/stop-restore.ts +117 -36
- package/src/cli/system-command.ts +2 -0
- package/src/cli/v2.ts +17 -4
- package/src/client/lifecycle-lock.ts +1 -1
- package/src/client/link-connection.ts +19 -0
- package/src/client/link-relay-transport.ts +25 -3
- package/src/client/link-tunnel.ts +10 -0
- package/src/client/machine-listener.ts +7 -1
- package/src/client/restore-ownership.ts +45 -0
- package/src/client/runtime.ts +13 -1
- package/src/client/state.ts +1 -1
- package/src/clients/client-ids.ts +7 -0
- package/src/clients/client-path.ts +13 -5
- package/src/clients/config-export/agent-clients.ts +3 -6
- package/src/clients/config-export/alias-selectors.ts +85 -0
- package/src/clients/config-export/contracts.ts +6 -25
- package/src/clients/config-export/dsh.ts +8 -1
- package/src/clients/config-export/model-metadata.ts +19 -0
- package/src/clients/config-export/model-names.ts +31 -0
- package/src/clients/config-export/qoder.ts +3 -11
- package/src/clients/config-export/t3code.ts +141 -0
- package/src/clients/config-export.ts +51 -15
- package/src/clients/gentle-shell-path.ts +3 -3
- package/src/codex/account-lifecycle.ts +27 -13
- package/src/codex/account-store.ts +32 -6
- package/src/codex/app-server-processes.ts +84 -1
- package/src/codex/auth-api/main-account-probe.ts +50 -11
- package/src/codex/auth-api/pool-mode-gate.ts +16 -8
- package/src/codex/auth-context.ts +45 -4
- package/src/codex/catalog/antigravity-discovery.ts +59 -0
- package/src/codex/catalog/build-entries.ts +12 -13
- package/src/codex/catalog/bundled.ts +59 -9
- package/src/codex/catalog/derive-entry.ts +2 -0
- package/src/codex/catalog/gather-capture.ts +3 -0
- package/src/codex/catalog/metadata.ts +6 -5
- package/src/codex/catalog/model-hints.ts +36 -4
- package/src/codex/catalog/native-priority.ts +63 -0
- package/src/codex/catalog/provider-models.ts +20 -4
- package/src/codex/catalog/retained-sync.ts +1 -1
- package/src/codex/chatgpt-refresh-failure.ts +2 -2
- package/src/codex/cli-install-provenance.ts +57 -29
- package/src/codex/cli-installation-identity.ts +1 -1
- package/src/codex/cli-installation-limits.ts +7 -0
- package/src/codex/cli-update-apply.ts +391 -0
- package/src/codex/cli-update-artifacts.ts +257 -0
- package/src/codex/cli-update-files.ts +100 -0
- package/src/codex/cli-update-inspection-context.ts +49 -0
- package/src/codex/cli-update-job-execution.ts +77 -0
- package/src/codex/cli-update-job-store-windows.ts +1010 -0
- package/src/codex/cli-update-job-worker.ts +393 -0
- package/src/codex/cli-update-job.ts +369 -0
- package/src/codex/cli-update-lease.ts +71 -0
- package/src/codex/cli-update-paths.ts +76 -0
- package/src/codex/cli-update-plan.ts +180 -47
- package/src/codex/cli-update-recovery.ts +236 -0
- package/src/codex/cli-update-selection-gate.ts +235 -0
- package/src/codex/cli-update-windows-apply.ts +308 -0
- package/src/codex/cli-update-windows-layout.ts +110 -0
- package/src/codex/cli-update-windows-observation.ts +91 -0
- package/src/codex/cli-update-windows-paths.ts +26 -0
- package/src/codex/cli-update-worker-recovery.ts +32 -0
- package/src/codex/cli-update-worker.ts +185 -0
- package/src/codex/cli-windows-plan-provenance.ts +250 -0
- package/src/codex/desktop-app-restart.ts +22 -3
- package/src/codex/exec-boundary.ts +208 -0
- package/src/codex/forward-transport-headers.ts +80 -0
- package/src/codex/history-job.ts +7 -0
- package/src/codex/history-provider.ts +5 -2
- package/src/codex/history-worker.ts +20 -1
- package/src/codex/inject/restore.ts +57 -25
- package/src/codex/internal/history-writer.ts +2 -1
- package/src/codex/mac-app-bundle.ts +52 -0
- package/src/codex/main-account.ts +161 -23
- package/src/codex/native-main-auth-temp.ts +3 -2
- package/src/codex/native-main-refresh-mode.ts +18 -3
- package/src/codex/native-profile-manager.ts +8 -6
- package/src/codex/native-profile-store.ts +9 -0
- package/src/codex/ocx-compaction-history.ts +3 -2
- package/src/codex/prompt-text-probe.ts +211 -69
- package/src/codex/quota.ts +9 -0
- package/src/codex/role-model-history.ts +253 -0
- package/src/codex/runtime.ts +120 -71
- package/src/codex/shim-overlay.ts +22 -3
- package/src/codex/shim-templates.ts +5 -2
- package/src/codex/shim-wrapper-write.ts +136 -0
- package/src/codex/shim.ts +24 -125
- package/src/codex/windows-cli-child-native.ts +119 -0
- package/src/codex/windows-cli-child-pipe.ts +87 -0
- package/src/codex/windows-cli-child.ts +260 -0
- package/src/codex/windows-cli-recovery-guardian.ts +89 -0
- package/src/codex/windows-cli-recovery.ts +39 -0
- package/src/codex/windows-installation-files.ts +52 -6
- package/src/codex/windows-npm-execution.ts +25 -0
- package/src/combos/failover.ts +84 -5
- package/src/combos/index.ts +1 -0
- package/src/combos/resolve.ts +60 -22
- package/src/config/atomic-write.ts +75 -22
- package/src/config/diagnostics.ts +18 -10
- package/src/config/live-reconcile.ts +11 -3
- package/src/config/owner-registry.ts +5 -4
- package/src/config/persist-unlocked.ts +34 -8
- package/src/config/persisted-mutation.ts +7 -0
- package/src/config/process-state.ts +9 -5
- package/src/config/removed-opencode-free-backup.ts +99 -0
- package/src/config/removed-opencode-free.ts +4 -8
- package/src/config/salvage.ts +1 -0
- package/src/config/schema/config-schema.ts +16 -1
- package/src/config/schema/leaf-validators.ts +15 -0
- package/src/config.ts +4 -4
- package/src/generated/compatibility-version.json +743 -315
- package/src/grok/inject.ts +2 -1
- package/src/grok/sync.ts +5 -2
- package/src/images/loop.ts +14 -5
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/hermes-refresh.ts +28 -0
- package/src/integrations/model-name-guard.ts +31 -0
- package/src/integrations/mutation-plan.ts +17 -4
- package/src/integrations/ownership.ts +3 -0
- package/src/integrations/registry.ts +10 -1
- package/src/integrations/state.ts +6 -0
- package/src/integrations/writer.ts +64 -59
- package/src/lib/abort.ts +8 -4
- package/src/lib/bounded-body.ts +7 -1
- package/src/lib/config-ownership.ts +4 -0
- package/src/lib/errors.ts +2 -0
- package/src/lib/eventstream-decoder.ts +3 -2
- package/src/lib/http-response-semantics.ts +9 -6
- package/src/lib/inbound-body-policy.ts +11 -0
- package/src/lib/jsonc.ts +7 -2
- package/src/lib/local-management-capability.ts +3 -1
- package/src/lib/local-upstream.ts +22 -26
- package/src/lib/loopback-family.ts +31 -0
- package/src/lib/plain-data.ts +7 -5
- package/src/lib/process-control.ts +30 -5
- package/src/lib/shadow-call.ts +55 -1
- package/src/lib/tool-argument-integers.ts +99 -7
- package/src/lib/upstream-retry.ts +6 -1
- package/src/lib/windows-elevation.ts +34 -11
- package/src/lib/windows-owner-acl.ts +272 -32
- package/src/lib/windows-secret-acl.ts +310 -44
- package/src/lib/windows-service-wrappers.ts +10 -7
- package/src/lib/winsw.ts +8 -4
- package/src/link/relay-auth.ts +38 -1
- package/src/link/remote-platform.ts +11 -23
- package/src/link/remote-probe.ts +3 -1
- package/src/link/remote-windows.ts +150 -0
- package/src/link/ssh-argv.ts +13 -5
- package/src/link/store.ts +4 -1
- package/src/link/supervisor.ts +9 -0
- package/src/local-credentials/generation.ts +238 -0
- package/src/local-credentials/inventory.ts +281 -0
- package/src/local-credentials/observation-lease.ts +83 -0
- package/src/local-credentials/publication-fence.ts +81 -0
- package/src/local-credentials/references.ts +36 -0
- package/src/local-credentials/runtime-observation.ts +28 -0
- package/src/oauth/account-auto-pause-policy.ts +11 -0
- package/src/oauth/anthropic-account-refusal.ts +1 -0
- package/src/oauth/anthropic-rate-limit-policy.ts +26 -2
- package/src/oauth/anthropic-routing.ts +34 -44
- package/src/oauth/anthropic-session-affinity-store.ts +177 -0
- package/src/oauth/chatgpt.ts +11 -9
- package/src/oauth/cursor.ts +8 -2
- package/src/oauth/generic-account-failover.ts +33 -2
- package/src/oauth/generic-session-affinity.ts +7 -0
- package/src/oauth/google-antigravity.ts +29 -5
- package/src/oauth/index.ts +1 -0
- package/src/oauth/store.ts +32 -4
- package/src/protocols/encoders/adapter-events.ts +7 -4
- package/src/protocols/encoders/messages.ts +1 -1
- package/src/providers/antigravity-account-roster.ts +73 -7
- package/src/providers/antigravity-models.ts +8 -4
- package/src/providers/api-key-resolve.ts +16 -3
- package/src/providers/claude-cli-identity.ts +2 -0
- package/src/providers/codex-capacity.ts +3 -2
- package/src/providers/free-directory.ts +10 -2
- package/src/providers/key-store.ts +7 -2
- package/src/providers/provider-id-rewrite.ts +3 -0
- package/src/providers/quota/antigravity.ts +6 -4
- package/src/providers/quota/vendor-probes-oauth.ts +0 -1
- package/src/providers/stale-model-roster-migration.ts +3 -0
- package/src/quota-pool/assemble.ts +51 -21
- package/src/quota-pool/pooled.ts +162 -0
- package/src/remote-control/workspace-codex-runtime.ts +63 -20
- package/src/responses/apply-patch-envelope.ts +35 -0
- package/src/responses/compaction-history-framing.ts +15 -4
- package/src/responses/turn-membership.ts +111 -0
- package/src/server/advisor-admission-scope.ts +43 -0
- package/src/server/audio-upstream.ts +10 -2
- package/src/server/auth-cors.ts +23 -0
- package/src/server/bind-host.ts +5 -0
- package/src/server/chat-completions.ts +17 -2
- package/src/server/chat-native.ts +16 -11
- package/src/server/claude-messages.ts +9 -1
- package/src/server/codex-model-list.ts +46 -0
- package/src/server/gui-session.ts +5 -2
- package/src/server/inbound-body-admission.ts +21 -13
- package/src/server/inbound-body-budget.ts +128 -0
- package/src/server/index/link-listener.ts +3 -1
- package/src/server/index/link-relay-sessions.ts +9 -2
- package/src/server/index/optional-listeners.ts +1 -0
- package/src/server/index/serve-options.ts +9 -43
- package/src/server/index/websocket-handler.ts +7 -0
- package/src/server/index.ts +6 -5
- package/src/server/inference/client-encoder-delivery.ts +3 -1
- package/src/server/lifecycle.ts +8 -1
- package/src/server/management/advisor-routes.ts +26 -9
- package/src/server/management/agent-settings-routes.ts +424 -543
- package/src/server/management/anthropic-reset-grant-routes.ts +2 -1
- package/src/server/management/claude-code-settings-patch.ts +211 -0
- package/src/server/management/claude-desktop-config-writers.ts +78 -0
- package/src/server/management/codex-agent-role-routes.ts +79 -2
- package/src/server/management/codex-cli-update-routes.ts +55 -0
- package/src/server/management/codex-prompt-routes.ts +2 -1
- package/src/server/management/config-routes.ts +444 -380
- package/src/server/management/consent-session.ts +6 -0
- package/src/server/management/desktop-compatibility-authorization.ts +12 -0
- package/src/server/management/desktop-compatibility-routes.ts +3 -2
- package/src/server/management/desktop-compatibility-runtime-routes.ts +2 -1
- package/src/server/management/desktop-compatibility-settings-routes.ts +2 -1
- package/src/server/management/integration-routes.ts +45 -5
- package/src/server/management/link-enrollment.ts +21 -32
- package/src/server/management/link-route-state.ts +1 -0
- package/src/server/management/link-routes.ts +4 -1
- package/src/server/management/model-routes.ts +22 -6
- package/src/server/management/model-rows.ts +3 -1
- package/src/server/management/native-integration-routes.ts +90 -38
- package/src/server/management/oauth-account-routes.ts +8 -7
- package/src/server/management/route-registry.ts +8 -3
- package/src/server/management/session-routes.ts +20 -2
- package/src/server/management/shadow-call-validation.ts +43 -2
- package/src/server/management/sidebar-routes.ts +2 -1
- package/src/server/management/system-restart.ts +47 -7
- package/src/server/management-api.ts +61 -51
- package/src/server/management-auth.ts +11 -3
- package/src/server/messages-native.ts +21 -7
- package/src/server/messages-shared.ts +110 -18
- package/src/server/persistent-gui-session.ts +155 -0
- package/src/server/port-reclaim.ts +29 -5
- package/src/server/proxy-liveness.ts +110 -33
- package/src/server/request-decompress.ts +5 -1
- package/src/server/responses/account-change-state.ts +14 -2
- package/src/server/responses/adapter-continuation.ts +5 -4
- package/src/server/responses/adapter-delivery.ts +20 -5
- package/src/server/responses/adapter-dispatch.ts +39 -45
- package/src/server/responses/advisor-plan-slot.ts +3 -0
- package/src/server/responses/advisor-slot.ts +4 -2
- package/src/server/responses/antigravity-model-denial-recovery.ts +70 -0
- package/src/server/responses/antigravity-validation-refusal.ts +6 -0
- package/src/server/responses/combo-required-tool-contract.ts +2 -1
- package/src/server/responses/combo-required-tool-fulfillments.ts +58 -0
- package/src/server/responses/combo-required-tool-stream.ts +119 -0
- package/src/server/responses/combo-stream-preflight.ts +47 -7
- package/src/server/responses/compact.ts +14 -7
- package/src/server/responses/compaction-recovery.ts +2 -1
- package/src/server/responses/core-auth.ts +2 -1
- package/src/server/responses/core-codex-account.ts +1 -0
- package/src/server/responses/core-combo-failure.ts +11 -6
- package/src/server/responses/core-combo-native.ts +6 -5
- package/src/server/responses/core-combo.ts +93 -20
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/fetch-helpers.ts +5 -1
- package/src/server/responses/jev-model-invoke.ts +8 -3
- package/src/server/responses/memory-models.ts +3 -2
- package/src/server/responses/passthrough-delivery.ts +36 -8
- package/src/server/responses/passthrough-dispatch.ts +12 -12
- package/src/server/responses/request-prepare.ts +10 -1
- package/src/server/responses/request-transport.ts +41 -6
- package/src/server/responses/run-turn-execution.ts +11 -3
- package/src/server/responses/sidecar-execution.ts +5 -0
- package/src/server/responses/turn-membership.ts +30 -0
- package/src/server/responses-custom-tool-repair.ts +86 -11
- package/src/server/responses-image-gen-repair.ts +1 -1
- package/src/server/restart-parent-ownership.ts +49 -0
- package/src/server/stop-teardown.ts +46 -9
- package/src/server/windows-tcp-drop.ts +4 -2
- package/src/service/desktop-recovery-process.ts +341 -0
- package/src/service/desktop-recovery.ts +172 -0
- package/src/service/windows-ops.ts +6 -3
- package/src/service/windows-scheduler.ts +29 -6
- package/src/stall-timeout.ts +47 -0
- package/src/tray/windows.ts +6 -4
- package/src/types/config.ts +61 -10
- package/src/types/request.ts +1 -1
- package/src/types.ts +1 -0
- package/src/update/async-check.ts +4 -3
- package/src/update/bind-probe.ts +2 -2
- package/src/update/codex-cli-update-launch-policy.mjs +9 -0
- package/src/update/guarded-port-reclaim.ts +14 -0
- package/src/update/guarded-runtime-ops.ts +58 -0
- package/src/update/guarded-tray-ops.ts +9 -0
- package/src/update/index.ts +196 -58
- package/src/update/job-pinned-start.ts +53 -0
- package/src/update/job-supervised-restart.ts +23 -6
- package/src/update/job-update-home.ts +62 -0
- package/src/update/job-update-tray.ts +29 -0
- package/src/update/job-windows-restart.ts +39 -0
- package/src/update/job.ts +179 -193
- package/src/update/mutation-guard.d.mts +30 -0
- package/src/update/mutation-guard.mjs +103 -0
- package/src/update/notify.ts +2 -2
- package/src/update/npm-cache-preflight.mjs +4 -4
- package/src/update/npm-install.mjs +5 -3
- package/src/update/pnpm-read-policy.mjs +3 -2
- package/src/update/proxy-liveness-probe.mjs +2 -2
- package/src/update/service-home-authority.ts +35 -0
- package/src/update/service-home-package-only-protocol.json +1 -0
- package/src/update/service-home-policy.d.mts +25 -0
- package/src/update/service-home-policy.mjs +112 -0
- package/src/update/service-home-probe-entry.ts +9 -0
- package/src/update/service-home-probe.d.mts +15 -0
- package/src/update/service-home-probe.mjs +79 -0
- package/src/update/service-home-protocol.json +1 -0
- package/src/update/supervised-recovery.d.mts +2 -2
- package/src/update/supervised-recovery.mjs +14 -7
- package/src/update/transactional-install.d.mts +3 -1
- package/src/update/transactional-install.mjs +29 -19
- package/src/update/update-failure-guidance.mjs +1 -1
- package/src/update/worker-launch.ts +3 -3
- package/src/vision/anthropic-describe.ts +2 -1
- package/src/web-search/anthropic-executor.ts +2 -1
- package/src/web-search/anthropic-history.ts +1 -0
- package/src/web-search/format-result.ts +3 -2
- package/src/web-search/header-deadline.ts +3 -2
- package/src/web-search/loop.ts +10 -4
- package/src/web-search/parse.ts +191 -38
- package/gui/dist/assets/App-CJZoq-uF.js +0 -58
- package/gui/dist/assets/Tray-BWQPcgZn.js +0 -1
- package/gui/dist/assets/index-DRe8Hhfz.css +0 -1
- package/gui/dist/assets/index-Xfct8owH.js +0 -94
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import type { AdmissionModelScope } from "./admission-model-scope";
|
|
2
|
+
|
|
3
|
+
/** Scope metadata accepted only alongside the process-owned Advisor capability. */
|
|
4
|
+
export const ADVISOR_ADMISSION_SCOPE_HEADER = "x-opencodex-advisor-admission-scope";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* The wire bound both ends share: the decoder refuses a longer value, so the encoder must
|
|
8
|
+
* refuse first rather than emit a header the peer is guaranteed to reject mid-request.
|
|
9
|
+
*/
|
|
10
|
+
export const MAX_ADVISOR_ADMISSION_SCOPE_VALUE_LENGTH = 16_384;
|
|
11
|
+
|
|
12
|
+
/** A scope whose encoded form exceeds the shared wire bound. */
|
|
13
|
+
export class AdvisorAdmissionScopeEncodedBoundExceeded extends Error {
|
|
14
|
+
constructor() {
|
|
15
|
+
super("advisor admission scope exceeds encoded bound");
|
|
16
|
+
this.name = "AdvisorAdmissionScopeEncodedBoundExceeded";
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export function encodeAdvisorAdmissionScope(scope: AdmissionModelScope): string {
|
|
21
|
+
const value = Buffer.from(JSON.stringify({ providers: scope.providers, models: scope.models }), "utf8").toString("base64url");
|
|
22
|
+
// Never truncate or drop the scope silently: losing it would let the consult run wider
|
|
23
|
+
// than the caller is allowed. The caller turns this into a controlled pre-fetch failure.
|
|
24
|
+
if (value.length > MAX_ADVISOR_ADMISSION_SCOPE_VALUE_LENGTH) {
|
|
25
|
+
throw new AdvisorAdmissionScopeEncodedBoundExceeded();
|
|
26
|
+
}
|
|
27
|
+
return value;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function decodeAdvisorAdmissionScope(value: string | null): AdmissionModelScope | undefined {
|
|
31
|
+
if (!value || value.length > MAX_ADVISOR_ADMISSION_SCOPE_VALUE_LENGTH) return undefined;
|
|
32
|
+
try {
|
|
33
|
+
const parsed: unknown = JSON.parse(Buffer.from(value, "base64url").toString("utf8"));
|
|
34
|
+
if (!parsed || typeof parsed !== "object") return undefined;
|
|
35
|
+
const { providers, models } = parsed as { providers?: unknown; models?: unknown };
|
|
36
|
+
if (!Array.isArray(providers) || !Array.isArray(models)
|
|
37
|
+
|| providers.some(item => typeof item !== "string")
|
|
38
|
+
|| models.some(item => typeof item !== "string")) return undefined;
|
|
39
|
+
return { providers, models };
|
|
40
|
+
} catch {
|
|
41
|
+
return undefined;
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -1,15 +1,18 @@
|
|
|
1
1
|
import { formatErrorResponse } from "../bridge";
|
|
2
2
|
import {
|
|
3
3
|
CodexAccountCooldownError,
|
|
4
|
+
CodexAuthContextError,
|
|
4
5
|
CodexMainProfileDrainingError,
|
|
5
6
|
codexMainProfileDrainingResponse,
|
|
6
7
|
cooldownErrorResponse,
|
|
7
8
|
isCodexAuthContextUsable,
|
|
8
|
-
|
|
9
|
+
materializeCodexUpstreamAuthAsync,
|
|
9
10
|
releaseCodexAuthContextProbeLease,
|
|
10
11
|
resolveCodexAuthContext,
|
|
11
12
|
type CodexAuthContext,
|
|
12
13
|
} from "../codex/auth-context";
|
|
14
|
+
import { MAIN_CODEX_ACCOUNT_ID, MainAccountTokenRefreshError, MainAuthJsonChangedDuringRefreshError } from "../codex/main-account";
|
|
15
|
+
import { NativeProfileError } from "../codex/native-profile-types";
|
|
13
16
|
import { formatCodexProviderForLog } from "../codex/routing";
|
|
14
17
|
import type { AdmissionLease } from "../lib/admission";
|
|
15
18
|
import { captureExplicitOpenAiCallerAuth, resolveFirstUsableOpenAiSidecar, selectOpenAiImagesProvider } from "../providers/openai-sidecar";
|
|
@@ -25,6 +28,7 @@ import {
|
|
|
25
28
|
import { codexAccountSelectionForTurn } from "./lifecycle";
|
|
26
29
|
import type { RequestLogContext } from "./request-log";
|
|
27
30
|
import { authorizationCredential } from "../lib/authorization-scheme";
|
|
31
|
+
import { nativeMainRefreshFailureResponse } from "./responses/codex-auth-error";
|
|
28
32
|
|
|
29
33
|
export const TRANSCRIPTION_MODEL = "gpt-4o-transcribe";
|
|
30
34
|
export const LIVE_AUDIO_MODEL = "gpt-live-1-codex";
|
|
@@ -103,10 +107,11 @@ export async function resolveAudioUpstream(
|
|
|
103
107
|
signal: options.signal,
|
|
104
108
|
});
|
|
105
109
|
options.signal?.throwIfAborted();
|
|
106
|
-
selected =
|
|
110
|
+
selected = await materializeCodexUpstreamAuthAsync(headers, context, {
|
|
107
111
|
config,
|
|
108
112
|
admission: options.admission,
|
|
109
113
|
substituteMainCredential: true,
|
|
114
|
+
signal: options.signal,
|
|
110
115
|
});
|
|
111
116
|
} else {
|
|
112
117
|
const resolved = await resolveFirstUsableOpenAiSidecar(candidates.forwardCandidates, headers, config, {
|
|
@@ -172,6 +177,9 @@ export async function resolveAudioUpstream(
|
|
|
172
177
|
releaseCodexAuthContextProbeLease(context);
|
|
173
178
|
if (error instanceof CodexAccountCooldownError) return cooldownErrorResponse(error);
|
|
174
179
|
if (error instanceof CodexMainProfileDrainingError) return codexMainProfileDrainingResponse();
|
|
180
|
+
const mainCause = error instanceof CodexAuthContextError && error.accountId === MAIN_CODEX_ACCOUNT_ID ? error.cause : error;
|
|
181
|
+
if (mainCause instanceof MainAccountTokenRefreshError || mainCause instanceof MainAuthJsonChangedDuringRefreshError
|
|
182
|
+
|| (mainCause instanceof NativeProfileError && mainCause.retryable)) return nativeMainRefreshFailureResponse(mainCause);
|
|
175
183
|
return formatErrorResponse(401, "authentication_error", "Audio account authentication unavailable; reconnect the selected OpenAI account");
|
|
176
184
|
}
|
|
177
185
|
}
|
package/src/server/auth-cors.ts
CHANGED
|
@@ -53,6 +53,7 @@ let _corsOrigin = "http://localhost:10100";
|
|
|
53
53
|
// Listener identity is process-local. Never infer this trust from forwarded headers: the
|
|
54
54
|
// request handler marks a Request only after resolving the actual Bun Server instance.
|
|
55
55
|
const trustedHubManagementRequests = new WeakSet<Request>();
|
|
56
|
+
export function isTrustedHubManagementRequest(req: Request): boolean { return trustedHubManagementRequests.has(req); }
|
|
56
57
|
|
|
57
58
|
export function markTrustedHubManagementRequest(req: Request): void {
|
|
58
59
|
trustedHubManagementRequests.add(req);
|
|
@@ -513,6 +514,28 @@ export function resolveContextPrincipal(req: Request, config: OcxConfig, admissi
|
|
|
513
514
|
return undefined;
|
|
514
515
|
}
|
|
515
516
|
|
|
517
|
+
/** Stable structural replay identity. This does not replace process-local opaque-state ownership. */
|
|
518
|
+
export function resolveDurableReplayPrincipal(
|
|
519
|
+
req: Request,
|
|
520
|
+
config: Pick<OcxConfig, "apiKeys">,
|
|
521
|
+
admission: DataPlaneAdmission | undefined,
|
|
522
|
+
signingKey: Uint8Array,
|
|
523
|
+
): string | undefined {
|
|
524
|
+
if (!admission || signingKey.length !== 32) return undefined;
|
|
525
|
+
// The managed client sends this dedicated local credential; a thread id, User-Agent,
|
|
526
|
+
// loopback address or upstream bearer never establishes structural replay ownership.
|
|
527
|
+
const token = req.headers.get("x-opencodex-api-key")?.trim();
|
|
528
|
+
if (!token) return undefined;
|
|
529
|
+
const resolved = resolveDataPlaneAdmissionSecret(token, config, "dedicated");
|
|
530
|
+
if (!resolved) return undefined;
|
|
531
|
+
if (admission.kind !== "loopback" && (admission.kind !== resolved.kind
|
|
532
|
+
|| (admission.kind === "configured" && (resolved.kind !== "configured" || admission.keyId !== resolved.keyId)))) return undefined;
|
|
533
|
+
return createHmac("sha256", signingKey)
|
|
534
|
+
.update("opencodex.structural-replay-principal.v1\0")
|
|
535
|
+
.update(JSON.stringify([resolved.kind, resolved.kind === "configured" ? resolved.keyId : "", token]))
|
|
536
|
+
.digest("hex");
|
|
537
|
+
}
|
|
538
|
+
|
|
516
539
|
/** Whether `token` is a data-plane admission secret. */
|
|
517
540
|
export function isDataPlaneAdmissionSecret(token: string, config: OcxConfig): boolean {
|
|
518
541
|
return resolveDataPlaneAdmissionSecret(token, config) !== null;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/** The public listener's bind spelling, shared with ownership discovery. */
|
|
2
|
+
export function normalizeBindHostname(hostname: string | undefined): string {
|
|
3
|
+
const configuredHost = hostname?.trim();
|
|
4
|
+
return !configuredHost || /^localhost\.?$/i.test(configuredHost) ? "127.0.0.1" : configuredHost;
|
|
5
|
+
}
|
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
import { FORWARD_HEADERS } from "../adapters/openai-responses";
|
|
9
9
|
import {
|
|
10
10
|
assertChatCompletionsRoutingBody,
|
|
11
|
+
chatRawReasoningVisible,
|
|
11
12
|
ChatCompletionsRequestError,
|
|
12
13
|
} from "../chat/inbound";
|
|
13
14
|
import { chatSettingsBody, chatToResponsesBody } from "../protocols/codecs/chat";
|
|
@@ -22,6 +23,7 @@ import {
|
|
|
22
23
|
responsesSseToChatCompletionsSse,
|
|
23
24
|
} from "../chat/outbound";
|
|
24
25
|
import { ADVISOR_INTERNAL_CAPABILITY_HEADER, isInternalCallCapability } from "../lib/local-internal-call-capability";
|
|
26
|
+
import { ADVISOR_ADMISSION_SCOPE_HEADER, decodeAdvisorAdmissionScope } from "./advisor-admission-scope";
|
|
25
27
|
import { classifyError, cyberPolicyErrorType, CYBER_POLICY_ERROR_CODE, isCyberPolicyCode, UNDECLARED_TOOL_CALL_ERROR_CODE } from "../lib/errors";
|
|
26
28
|
import { redactSecretString } from "../lib/redact";
|
|
27
29
|
import { resolveClientRetryAfter } from "../lib/retry-after";
|
|
@@ -69,6 +71,7 @@ import type { AdmissionLease } from "../lib/admission";
|
|
|
69
71
|
import {
|
|
70
72
|
admissionModelDeniedResponse,
|
|
71
73
|
AdmissionModelDeniedError,
|
|
74
|
+
MODEL_NOT_ALLOWED_FOR_KEY,
|
|
72
75
|
assertRouteAllowedByScope,
|
|
73
76
|
resolveAdmissionModelScope,
|
|
74
77
|
} from "./admission-model-scope";
|
|
@@ -151,6 +154,15 @@ async function handleChatCompletionsWithBudget(
|
|
|
151
154
|
translatorBudget: TranslatorBudget,
|
|
152
155
|
logIds?: { requestId: string; start: number; turnAdmissionLease?: AdmissionLease; admission?: DataPlaneAdmission },
|
|
153
156
|
): Promise<Response> {
|
|
157
|
+
const advisorInternal = isInternalCallCapability(req.headers.get(ADVISOR_INTERNAL_CAPABILITY_HEADER));
|
|
158
|
+
const inheritedAdmissionScope = advisorInternal
|
|
159
|
+
? decodeAdvisorAdmissionScope(req.headers.get(ADVISOR_ADMISSION_SCOPE_HEADER))
|
|
160
|
+
: undefined;
|
|
161
|
+
if (advisorInternal && req.headers.has(ADVISOR_ADMISSION_SCOPE_HEADER) && !inheritedAdmissionScope) {
|
|
162
|
+
// Refused requests still own a final log row like every other early rejection.
|
|
163
|
+
if (logIds) addFinalRequestLog(logIds.requestId, logIds.start, logCtx, 403, { closeReason: "non_stream" });
|
|
164
|
+
return chatCompletionsErrorResponse(403, "invalid inherited advisor admission scope", "permission_error", MODEL_NOT_ALLOWED_FOR_KEY);
|
|
165
|
+
}
|
|
154
166
|
let chatBody: Rec;
|
|
155
167
|
try {
|
|
156
168
|
const rawBody = await readChatBody(req, translatorBudget, resolveInboundBodyLimitBytes(config.maxInboundBodyBytes));
|
|
@@ -177,6 +189,8 @@ async function handleChatCompletionsWithBudget(
|
|
|
177
189
|
const droidDefaultEffort = effortRow
|
|
178
190
|
? undefined
|
|
179
191
|
: droidReasoningDefault(req.headers.get(DROID_DEFAULT_EFFORT_HEADER), chatBody);
|
|
192
|
+
// Read the caller's delivery choice before any generation default (Droid effort) is written.
|
|
193
|
+
const rawReasoningVisible = chatRawReasoningVisible(chatBody);
|
|
180
194
|
if (effortRow) chatBody.model = effortRow.baseId;
|
|
181
195
|
if (fastRow) {
|
|
182
196
|
chatBody.model = fastRow.baseId;
|
|
@@ -206,7 +220,7 @@ async function handleChatCompletionsWithBudget(
|
|
|
206
220
|
);
|
|
207
221
|
// Native Chat must check its own destination; translated xAI OAuth turns
|
|
208
222
|
// preview the billed Fast lane before their final Responses scope check.
|
|
209
|
-
assertRouteAllowedByScope(resolveAdmissionModelScope(config, logIds?.admission), requestedModel, {
|
|
223
|
+
assertRouteAllowedByScope(inheritedAdmissionScope ?? resolveAdmissionModelScope(config, logIds?.admission), requestedModel, {
|
|
210
224
|
providerName: route.providerName,
|
|
211
225
|
modelId: previewXaiOauthWireModel({ options: {
|
|
212
226
|
serviceTier: typeof chatBody.service_tier === "string" ? chatBody.service_tier : undefined,
|
|
@@ -429,7 +443,6 @@ async function handleChatCompletionsWithBudget(
|
|
|
429
443
|
// authority comes from a process-owned capability minted at random per process and compared in
|
|
430
444
|
// constant time, so a forged header — or a token captured from an older process — is treated
|
|
431
445
|
// as an ordinary external request.
|
|
432
|
-
const advisorInternal = isInternalCallCapability(req.headers.get(ADVISOR_INTERNAL_CAPABILITY_HEADER));
|
|
433
446
|
// Concrete helper targets must fail before optional stored-main credential enrichment.
|
|
434
447
|
// Unresolved combos are checked after their concrete child route is selected in Responses.
|
|
435
448
|
if (settledRoute && !settledRoute.combo && isCanonicalOpenAiForwardProvider(settledRoute.provider)
|
|
@@ -518,6 +531,7 @@ async function handleChatCompletionsWithBudget(
|
|
|
518
531
|
abortSignal: req.signal,
|
|
519
532
|
// Body is Responses-shaped by now, but the client spoke Chat Completions.
|
|
520
533
|
inboundWire: "chat",
|
|
534
|
+
chatRawReasoningVisible: rawReasoningVisible,
|
|
521
535
|
// A Chat caller may send an explicit empty `tools` array — a deny-all declaration the
|
|
522
536
|
// translation drops along with the whole catalog. Carried separately so the
|
|
523
537
|
// undeclared-tool guard can still enforce it; absent/partial catalogs stay deferred.
|
|
@@ -539,6 +553,7 @@ async function handleChatCompletionsWithBudget(
|
|
|
539
553
|
// header — so the fact is detected here and carried as an option flag.
|
|
540
554
|
...(visionDescribeTerminal ? { visionDescribeTerminal: true } : {}),
|
|
541
555
|
...(advisorInternal ? { advisorInternal: true } : {}),
|
|
556
|
+
...(inheritedAdmissionScope ? { admissionScope: inheritedAdmissionScope } : {}),
|
|
542
557
|
translatorBudget,
|
|
543
558
|
...(logIds ? { onFirstOutput: () => recordFirstOutput(logCtx, logIds.start) } : {}),
|
|
544
559
|
onNativePassthroughTerminal: status => finalizeNativeLog(httpStatusForRequestLogTerminal(status, logCtx), { terminalStatus: status, closeReason: "terminal" }),
|
|
@@ -68,6 +68,7 @@ import type { RouteResult } from "../router";
|
|
|
68
68
|
import type { OcxConfig, OcxProviderConfig } from "../types";
|
|
69
69
|
import { fetchWithHeaderTimeout, physicalSendObserverInit, providerFetch, safeHostLabel, sendWithConnectionPolicy } from "./responses/fetch-helpers";
|
|
70
70
|
import { isLocalUpstream } from "../lib/local-upstream";
|
|
71
|
+
import { resolveConnectTimeoutMs, resolveJsonBodyReadTimeoutMs } from "../stall-timeout";
|
|
71
72
|
import { linkAbortSignal } from "./responses";
|
|
72
73
|
import {
|
|
73
74
|
noteProviderAttemptSend,
|
|
@@ -326,7 +327,8 @@ export async function runNativeChatAttempt(
|
|
|
326
327
|
streamTurnRegistered = false;
|
|
327
328
|
unregisterTurn(upstream);
|
|
328
329
|
};
|
|
329
|
-
|
|
330
|
+
// Set only at the final send boundary; queued refresh can replace the destination.
|
|
331
|
+
let localUpstream = false;
|
|
330
332
|
// Native chat is its own entry path -- chat-completions.ts routes here directly and never
|
|
331
333
|
// through the Responses core -- so the pre-dispatch key preference is applied again here
|
|
332
334
|
// rather than inherited. Assigned before the adapter binds below, for the same reason it is
|
|
@@ -483,7 +485,7 @@ export async function runNativeChatAttempt(
|
|
|
483
485
|
body: request.body,
|
|
484
486
|
}, effectiveRecovery),
|
|
485
487
|
upstream.signal,
|
|
486
|
-
|
|
488
|
+
0, // Final physical send owns the header clock after queued credential/destination refresh.
|
|
487
489
|
requestedStream,
|
|
488
490
|
providerFetch(activeProvider, undefined, {
|
|
489
491
|
providerName: route.providerName,
|
|
@@ -545,19 +547,21 @@ export async function runNativeChatAttempt(
|
|
|
545
547
|
noteProviderAttemptSend(logCtx, route.providerName, activeProvider, logCtx.usageLogInputTokens, transportRecovery ?? recovery);
|
|
546
548
|
// A reselected provider transport is still a physical send: the connection policy
|
|
547
549
|
// and manual-redirect ownership wrap the selected implementation (#4992).
|
|
548
|
-
|
|
550
|
+
const physicalFetch = ((input, physicalInit) => sendWithConnectionPolicy(
|
|
549
551
|
distributedKeyPhysicalFetch((activeProvider as OcxProviderTransport).fetch ?? execute,
|
|
550
552
|
route.providerName, activeProvider, request.url),
|
|
553
|
+
String(input), physicalInit, { providerName: route.providerName, provider: activeProvider },
|
|
554
|
+
)) as typeof fetch;
|
|
555
|
+
localUpstream = isLocalUpstream(request.url);
|
|
556
|
+
dispatched = await fetchWithHeaderTimeout(
|
|
551
557
|
request.url,
|
|
552
558
|
applyUpstreamRecoveryInit({
|
|
553
559
|
...init, method: request.method, headers, body: request.body,
|
|
554
560
|
...physicalSendObserverInit(observeAutoPause, request.url),
|
|
555
561
|
}, transportRecovery),
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
// because that transport wins over the executor that carries the binding.
|
|
560
|
-
{ providerName: route.providerName, provider: activeProvider },
|
|
562
|
+
init.signal ?? upstream.signal,
|
|
563
|
+
resolveConnectTimeoutMs(config.connectTimeoutMs, { localUpstream }),
|
|
564
|
+
requestedStream, physicalFetch,
|
|
561
565
|
);
|
|
562
566
|
} finally {
|
|
563
567
|
try { if (physicalBudget.spendEnforced) spendReport(1); }
|
|
@@ -816,7 +820,7 @@ export async function runNativeChatAttempt(
|
|
|
816
820
|
translatorBudget,
|
|
817
821
|
signal: upstream.signal,
|
|
818
822
|
stallTimeoutSec: config.stallTimeoutSec,
|
|
819
|
-
localUpstream
|
|
823
|
+
localUpstream,
|
|
820
824
|
clientDeclaredEmptyToolCatalog,
|
|
821
825
|
declaredLegacyFunctionNames,
|
|
822
826
|
onFirstOutput,
|
|
@@ -888,11 +892,12 @@ export async function runNativeChatAttempt(
|
|
|
888
892
|
|
|
889
893
|
let body;
|
|
890
894
|
try {
|
|
895
|
+
const jsonBodyReadMs = resolveJsonBodyReadTimeoutMs(config.stallTimeoutSec, { localUpstream }, config.connectTimeoutMs);
|
|
891
896
|
body = await readBoundedResponseBody(response, {
|
|
892
897
|
signal: upstream.signal,
|
|
893
898
|
maxBytes: MAX_NATIVE_CHAT_JSON_BYTES,
|
|
894
|
-
totalTimeoutMs:
|
|
895
|
-
inactivityTimeoutMs:
|
|
899
|
+
totalTimeoutMs: localUpstream ? 0 : jsonBodyReadMs,
|
|
900
|
+
inactivityTimeoutMs: jsonBodyReadMs,
|
|
896
901
|
});
|
|
897
902
|
} catch (error) {
|
|
898
903
|
cleanupAbort();
|
|
@@ -58,6 +58,8 @@ import {
|
|
|
58
58
|
responsesSseToAnthropicSse,
|
|
59
59
|
} from "../claude/outbound";
|
|
60
60
|
import { clearableDeadline, idleDeadline } from "../lib/abort";
|
|
61
|
+
import { isLocalUpstream } from "../lib/local-upstream";
|
|
62
|
+
import { resolveConnectTimeoutMs } from "../stall-timeout";
|
|
61
63
|
import {
|
|
62
64
|
CLAUDE_NATIVE_THINKING,
|
|
63
65
|
type ClaudeThinkingProjection,
|
|
@@ -358,7 +360,9 @@ async function anthropicNativePassthrough(
|
|
|
358
360
|
const result = await fetchWithHeaderDeadline(
|
|
359
361
|
`${base}${pathname}${search}`,
|
|
360
362
|
{ method: "POST", headers, body: JSON.stringify(body) },
|
|
361
|
-
|
|
363
|
+
// Local Anthropic-compatible endpoints (a self-hosted base URL) disable the header deadline
|
|
364
|
+
// when the operator sets none, so a slow local prefill is not cut before the first header.
|
|
365
|
+
resolveConnectTimeoutMs(config.connectTimeoutMs, { localUpstream: isLocalUpstream(base) }),
|
|
362
366
|
req.signal,
|
|
363
367
|
);
|
|
364
368
|
if (result.kind === "timeout") {
|
|
@@ -1138,6 +1142,10 @@ async function handleClaudeMessagesWithBudget(
|
|
|
1138
1142
|
// Out of body like the replay above: the core hands these to an Anthropic destination only.
|
|
1139
1143
|
anthropicServerTools: declaredAnthropicServerTools(anthropicBody),
|
|
1140
1144
|
anthropicServerReplay: replayedAnthropicServerBlocks(anthropicBody),
|
|
1145
|
+
// Preserve the original catalog through late fallback; only the physical adapter projects it.
|
|
1146
|
+
anthropicToolLoadingSource: cacheKeySource === "metadata" && isRec(anthropicBody)
|
|
1147
|
+
&& Array.isArray(cc?.appendOnlyToolLoadingModels) && cc.appendOnlyToolLoadingModels.length > 0
|
|
1148
|
+
? { tools: anthropicBody.tools, messages: anthropicBody.messages, tool_choice: anthropicBody.tool_choice } : undefined,
|
|
1141
1149
|
claudeGoAffinity: { sessionLane: claudeGoSessionLane },
|
|
1142
1150
|
claudeNativeSessionId,
|
|
1143
1151
|
stripClaudeMainAuthForNoncanonicalForward: true,
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { websocketsEnabled } from "../config";
|
|
2
|
+
import type { OcxConfig } from "../types";
|
|
3
|
+
import { buildCatalogEntries } from "../codex/catalog/build-entries";
|
|
4
|
+
import { loadCatalogTemplate } from "../codex/catalog/bundled";
|
|
5
|
+
import { applyNativeVisibility, nativeContextLimits } from "../codex/catalog/metadata";
|
|
6
|
+
import { readCatalog, readCodexCatalogPath, type CatalogModel } from "../codex/catalog/parsing";
|
|
7
|
+
import { readNativeBaseline, retainedNativeSourcePriorities } from "../codex/catalog/native-priority";
|
|
8
|
+
|
|
9
|
+
interface CodexModelListInput {
|
|
10
|
+
config: OcxConfig;
|
|
11
|
+
nativeSlugs: string[];
|
|
12
|
+
availableAccountNativeSlugs: string[];
|
|
13
|
+
accountNativeSlugs: string[];
|
|
14
|
+
accountNativeSlugsBySelector: ReadonlyMap<string, readonly string[]>;
|
|
15
|
+
goOrdered: CatalogModel[];
|
|
16
|
+
exactComboSlugs: ReadonlySet<string>;
|
|
17
|
+
accountSelectors: string[];
|
|
18
|
+
suppressedBareNativeSlugs: ReadonlySet<string>;
|
|
19
|
+
disabledModels: ReadonlySet<string>;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Read-only Codex-shaped discovery; publication and backup creation belong to sync. */
|
|
23
|
+
export function buildCodexModelList({
|
|
24
|
+
config, nativeSlugs, availableAccountNativeSlugs, accountNativeSlugs,
|
|
25
|
+
accountNativeSlugsBySelector, goOrdered, exactComboSlugs, accountSelectors,
|
|
26
|
+
suppressedBareNativeSlugs, disabledModels,
|
|
27
|
+
}: CodexModelListInput) {
|
|
28
|
+
const catalogPath = readCodexCatalogPath();
|
|
29
|
+
const nativeSource = {
|
|
30
|
+
baseline: readNativeBaseline(catalogPath),
|
|
31
|
+
retainedBySlug: retainedNativeSourcePriorities(readCatalog(catalogPath)?.models ?? []),
|
|
32
|
+
};
|
|
33
|
+
const maMode = config.multiAgentMode === "v1" || config.multiAgentMode === "v2" ? config.multiAgentMode : "default";
|
|
34
|
+
// Account rows include hidden supported ids so newly re-enabled natives reappear before sync.
|
|
35
|
+
const catalogNativeSlugs = accountSelectors.length > 0
|
|
36
|
+
? [...new Set([...availableAccountNativeSlugs, ...accountNativeSlugs])]
|
|
37
|
+
: nativeSlugs;
|
|
38
|
+
const entries = buildCatalogEntries(
|
|
39
|
+
loadCatalogTemplate(), catalogNativeSlugs, goOrdered, config.subagentModels,
|
|
40
|
+
websocketsEnabled(config), maMode, exactComboSlugs, accountSelectors,
|
|
41
|
+
suppressedBareNativeSlugs, new Set(), nativeContextLimits(config), accountNativeSlugs,
|
|
42
|
+
accountNativeSlugsBySelector, config.keepNativeChatGptOnV1 === true, config.modelPickerOrder,
|
|
43
|
+
nativeSource,
|
|
44
|
+
);
|
|
45
|
+
return { models: applyNativeVisibility(entries, disabledModels, accountSelectors.length > 0, new Set(accountNativeSlugs)) };
|
|
46
|
+
}
|
|
@@ -12,10 +12,13 @@ import {
|
|
|
12
12
|
|
|
13
13
|
export type GuiSessionIssuance =
|
|
14
14
|
| "loopback"
|
|
15
|
+
| "remembered-admin"
|
|
15
16
|
| "tailscale-identity"
|
|
16
17
|
| "pairing";
|
|
17
18
|
|
|
18
19
|
export interface GuiSessionRecord {
|
|
20
|
+
persistentDigest?: string;
|
|
21
|
+
persistentExpiresAt?: number;
|
|
19
22
|
serverOrigin: string;
|
|
20
23
|
browserOrigin: string;
|
|
21
24
|
csrfToken: string;
|
|
@@ -129,7 +132,7 @@ function evictOldestSession(state: GuiSessionState): void {
|
|
|
129
132
|
}
|
|
130
133
|
}
|
|
131
134
|
|
|
132
|
-
function mintSession(
|
|
135
|
+
export function mintSession(
|
|
133
136
|
serverOrigin: string,
|
|
134
137
|
browserOrigin: string,
|
|
135
138
|
issuance: GuiSessionIssuance,
|
|
@@ -458,6 +461,6 @@ export function authorizeGuiSessionRequest(
|
|
|
458
461
|
const csrf = req.headers.get("x-opencodex-csrf-token")?.trim();
|
|
459
462
|
if (!csrf || !equalSecret(csrf, session.csrfToken)) return { ok: false, reason: "csrf" };
|
|
460
463
|
}
|
|
461
|
-
if (session.issuance !== "loopback" && !session.localPairing) session.expiresAt = now + REMOTE_GUI_SESSION_TTL_MS;
|
|
464
|
+
if (session.issuance !== "loopback" && !session.localPairing) session.expiresAt = Math.min(now + REMOTE_GUI_SESSION_TTL_MS, session.persistentExpiresAt ?? Infinity);
|
|
462
465
|
return { ok: true, principal: "gui-session", session };
|
|
463
466
|
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import {
|
|
2
|
-
MAX_CONFIGURABLE_INBOUND_BODY_BYTES,
|
|
3
2
|
MAX_DECOMPRESSED_BODY_BYTES,
|
|
4
3
|
resolveInboundBodyLimitBytes,
|
|
5
4
|
} from "./request-decompress";
|
|
@@ -7,17 +6,16 @@ import { withCors, type RequestPolicyView } from "./auth-cors";
|
|
|
7
6
|
import { codexCompatibleUrl } from "../codex/context-compat";
|
|
8
7
|
import { addFinalRequestLog, markLocalRequestLogRefusal } from "./request-log";
|
|
9
8
|
import type { WorkflowRefusalLog } from "./workflow-refusal";
|
|
9
|
+
import { inboundBodyBudget, bindInboundBodyLease, type InboundBodyBudget } from "./inbound-body-budget";
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
export const MAX_CONCURRENT_INBOUND_BODY_BYTES = MAX_CONFIGURABLE_INBOUND_BODY_BYTES;
|
|
13
|
-
let reservedInboundBodyBytes = 0;
|
|
11
|
+
export { configureInboundBodyBudget, MAX_CONCURRENT_INBOUND_BODY_BYTES } from "./inbound-body-budget";
|
|
14
12
|
|
|
15
13
|
// Match the HTTP routes whose JSON readers use maxInboundBodyBytes. Keep the
|
|
16
14
|
// current image/search/count_tokens support; management, audio, context relay,
|
|
17
15
|
// and WebSocket frames have separate limits and are not part of this gate.
|
|
18
16
|
// Exported so the contract tests classify the dispatcher's own route list
|
|
19
17
|
// instead of copying it: a new loopback route has to land in one of these two
|
|
20
|
-
// sets, or `tests/server/
|
|
18
|
+
// sets, or `tests/server/inbound-body-admission.test.ts` fails.
|
|
21
19
|
export const CONFIGURABLE_JSON_BODY_ROUTES: ReadonlySet<string> = new Set([
|
|
22
20
|
"/v1/responses",
|
|
23
21
|
"/v1/responses/compact",
|
|
@@ -139,6 +137,7 @@ function retainUntilResponseSettles(response: Response, signal: AbortSignal, rel
|
|
|
139
137
|
* EOF/error or settled cancellation. Call only at the admitted HTTP boundary,
|
|
140
138
|
* after auth/origin checks, not from readers or internal combo/translation hops.
|
|
141
139
|
* pathname is the same canonical pathname used by the server's dispatcher.
|
|
140
|
+
* The optional budget/wait override isolates lifecycle tests from the process-wide owner.
|
|
142
141
|
*/
|
|
143
142
|
export async function withRaisedInboundBodyAdmission(
|
|
144
143
|
req: Request,
|
|
@@ -146,6 +145,7 @@ export async function withRaisedInboundBodyAdmission(
|
|
|
146
145
|
configuredLimit: number | undefined,
|
|
147
146
|
work: () => Promise<Response>,
|
|
148
147
|
onRefusal: (response: Response) => Response = response => response,
|
|
148
|
+
options?: { budget?: InboundBodyBudget; maxWaitMs?: number },
|
|
149
149
|
): Promise<Response> {
|
|
150
150
|
const maxBytes = resolveInboundBodyLimitBytes(configuredLimit);
|
|
151
151
|
if (req.method !== "POST" || !CONFIGURABLE_JSON_BODY_ROUTES.has(pathname)
|
|
@@ -159,18 +159,26 @@ export async function withRaisedInboundBodyAdmission(
|
|
|
159
159
|
// protocol-specific 413 win over temporary capacity refusal, unchanged.
|
|
160
160
|
return work();
|
|
161
161
|
}
|
|
162
|
-
|
|
162
|
+
let lease;
|
|
163
|
+
try {
|
|
164
|
+
lease = await (options?.budget ?? inboundBodyBudget).acquire(maxBytes, req.signal, options?.maxWaitMs);
|
|
165
|
+
} catch (error) {
|
|
166
|
+
cancelUnreadBody(req, error);
|
|
167
|
+
throw error;
|
|
168
|
+
}
|
|
169
|
+
if (!lease) {
|
|
163
170
|
const error = new InboundBodyCapacityError();
|
|
164
171
|
cancelUnreadBody(req, error);
|
|
165
172
|
return onRefusal(capacityResponse(pathname, error));
|
|
166
173
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
+
// An immediate grant can race a disconnect before this async function resumes.
|
|
175
|
+
if (req.signal.aborted) {
|
|
176
|
+
lease.release();
|
|
177
|
+
cancelUnreadBody(req, req.signal.reason);
|
|
178
|
+
throw req.signal.reason;
|
|
179
|
+
}
|
|
180
|
+
const unbind = bindInboundBodyLease(req, lease);
|
|
181
|
+
const release = (): void => { unbind(); lease.release(); };
|
|
174
182
|
try {
|
|
175
183
|
return retainUntilResponseSettles(await work(), req.signal, release);
|
|
176
184
|
} catch (error) {
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { DEFAULT_CONCURRENT_INBOUND_BODY_BYTES, resolveConcurrentInboundBodyLimitBytes } from "../lib/inbound-body-policy";
|
|
2
|
+
export { DEFAULT_CONCURRENT_INBOUND_BODY_BYTES, MAX_CONCURRENT_INBOUND_BODY_BYTES } from "../lib/inbound-body-policy";
|
|
3
|
+
export const MAX_QUEUED_INBOUND_BODIES = 32;
|
|
4
|
+
export const INBOUND_BODY_QUEUE_TIMEOUT_MS = 120_000;
|
|
5
|
+
|
|
6
|
+
export interface InboundBodyLease {
|
|
7
|
+
/** Return unused allowance after the bounded reader measures the accepted body. */
|
|
8
|
+
shrink(bytes: number): void;
|
|
9
|
+
/** Return the remaining charge exactly once when the HTTP owner settles. */
|
|
10
|
+
release(): void;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/** FIFO admission whose bounded waiters neither read uploads nor own reservations. */
|
|
14
|
+
export function createInboundBodyBudget(capacity: number, maxQueued = MAX_QUEUED_INBOUND_BODIES) {
|
|
15
|
+
if (!Number.isSafeInteger(capacity) || capacity <= 0
|
|
16
|
+
|| !Number.isSafeInteger(maxQueued) || maxQueued < 0) {
|
|
17
|
+
throw new RangeError("Invalid inbound body budget");
|
|
18
|
+
}
|
|
19
|
+
let reservedBytes = 0;
|
|
20
|
+
let activeLeases = 0;
|
|
21
|
+
const pending: Array<{ bytes: number; admit(): void }> = [];
|
|
22
|
+
/** Only the FIFO head may consume newly available capacity. */
|
|
23
|
+
const drain = (): void => {
|
|
24
|
+
while (pending.length && pending[0]!.bytes <= capacity - reservedBytes) pending[0]!.admit();
|
|
25
|
+
};
|
|
26
|
+
/** Charge an allowance and give its HTTP owner an idempotent release handle. */
|
|
27
|
+
const grant = (bytes: number): InboundBodyLease => {
|
|
28
|
+
let held = bytes;
|
|
29
|
+
let released = false;
|
|
30
|
+
reservedBytes += held;
|
|
31
|
+
activeLeases++;
|
|
32
|
+
return {
|
|
33
|
+
/** Never increase a reservation or accept an invalid measurement. */
|
|
34
|
+
shrink(measured) {
|
|
35
|
+
if (released || !Number.isFinite(measured) || measured < 0) return;
|
|
36
|
+
const next = Math.min(held, Math.max(1, Math.ceil(measured)));
|
|
37
|
+
reservedBytes -= held - next;
|
|
38
|
+
held = next;
|
|
39
|
+
drain();
|
|
40
|
+
},
|
|
41
|
+
/** Free only this lease, including when EOF and cancellation race. */
|
|
42
|
+
release() {
|
|
43
|
+
if (released) return;
|
|
44
|
+
released = true;
|
|
45
|
+
reservedBytes -= held;
|
|
46
|
+
activeLeases--;
|
|
47
|
+
drain();
|
|
48
|
+
},
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
return {
|
|
52
|
+
/** Report the current shared allowance without confusing it with measured charges. */
|
|
53
|
+
capacity: () => capacity,
|
|
54
|
+
/** Startup configuration changes the same owner; existing leases and FIFO waiters survive. */
|
|
55
|
+
setCapacity(bytes: number): void {
|
|
56
|
+
if (!Number.isSafeInteger(bytes) || bytes <= 0) throw new RangeError("Invalid inbound body capacity");
|
|
57
|
+
capacity = bytes;
|
|
58
|
+
drain();
|
|
59
|
+
},
|
|
60
|
+
/** Observe counters without exposing request bodies or identities. */
|
|
61
|
+
snapshot: () => ({ reservedBytes, activeLeases, queuedRequests: pending.length }),
|
|
62
|
+
/** Wait for an entire upload allowance; null preserves the caller's overload response. */
|
|
63
|
+
acquire(bytes: number, signal: AbortSignal, waitMs = INBOUND_BODY_QUEUE_TIMEOUT_MS): Promise<InboundBodyLease | null> {
|
|
64
|
+
if (!Number.isSafeInteger(bytes) || bytes <= 0 || bytes > capacity) {
|
|
65
|
+
return Promise.reject(new RangeError("Invalid inbound body reservation"));
|
|
66
|
+
}
|
|
67
|
+
if (signal.aborted) return Promise.reject(signal.reason);
|
|
68
|
+
if (!pending.length && bytes <= capacity - reservedBytes) return Promise.resolve(grant(bytes));
|
|
69
|
+
if (pending.length >= maxQueued || !Number.isFinite(waitMs) || waitMs <= 0) return Promise.resolve(null);
|
|
70
|
+
return new Promise<InboundBodyLease | null>((resolve, reject) => {
|
|
71
|
+
let settled = false;
|
|
72
|
+
let timer: ReturnType<typeof setTimeout>;
|
|
73
|
+
/** Detach every waiter resource before admitting, timing out, or rejecting it. */
|
|
74
|
+
const cleanup = (): void => {
|
|
75
|
+
settled = true;
|
|
76
|
+
clearTimeout(timer);
|
|
77
|
+
signal.removeEventListener("abort", onAbort);
|
|
78
|
+
const index = pending.indexOf(entry);
|
|
79
|
+
if (index >= 0) pending.splice(index, 1);
|
|
80
|
+
};
|
|
81
|
+
/** A cancelled head must not strand a smaller eligible follower. */
|
|
82
|
+
const onAbort = (): void => {
|
|
83
|
+
if (settled) return;
|
|
84
|
+
cleanup();
|
|
85
|
+
reject(signal.reason);
|
|
86
|
+
drain();
|
|
87
|
+
};
|
|
88
|
+
const entry = { bytes,
|
|
89
|
+
/** Transfer a queued caller to a charged lease once, before resolving it. */
|
|
90
|
+
admit() {
|
|
91
|
+
if (settled) return;
|
|
92
|
+
cleanup();
|
|
93
|
+
resolve(grant(bytes));
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
pending.push(entry);
|
|
97
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
98
|
+
timer = setTimeout(() => {
|
|
99
|
+
if (settled) return;
|
|
100
|
+
cleanup();
|
|
101
|
+
resolve(null);
|
|
102
|
+
drain();
|
|
103
|
+
}, Math.min(waitMs, INBOUND_BODY_QUEUE_TIMEOUT_MS));
|
|
104
|
+
if (signal.aborted) onAbort();
|
|
105
|
+
});
|
|
106
|
+
},
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export type InboundBodyBudget = ReturnType<typeof createInboundBodyBudget>;
|
|
111
|
+
export const inboundBodyBudget = createInboundBodyBudget(DEFAULT_CONCURRENT_INBOUND_BODY_BYTES);
|
|
112
|
+
const requestLeases = new WeakMap<Request, InboundBodyLease>();
|
|
113
|
+
|
|
114
|
+
/** Adopt one startup policy for every listener without resetting live accounting. */
|
|
115
|
+
export function configureInboundBodyBudget(configured?: number): void {
|
|
116
|
+
inboundBodyBudget.setCapacity(resolveConcurrentInboundBodyLimitBytes(configured));
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** Connect only the admitted HTTP request to its bounded reader; internal reads own no lease. */
|
|
120
|
+
export function bindInboundBodyLease(req: Request, lease: InboundBodyLease): () => void {
|
|
121
|
+
requestLeases.set(req, lease);
|
|
122
|
+
return () => { if (requestLeases.get(req) === lease) requestLeases.delete(req); };
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/** Only an accepted, measured body can replace an HTTP owner's upload allowance. */
|
|
126
|
+
export function updateInboundBodyReservation(req: Request, bytes: number): void {
|
|
127
|
+
requestLeases.get(req)?.shrink(bytes);
|
|
128
|
+
}
|
|
@@ -26,6 +26,8 @@ export interface LinkListenerStartContext<T> {
|
|
|
26
26
|
dispatch: (req: Request, server: Server<T>) => Promise<Response>;
|
|
27
27
|
maxRequestBodySize: number;
|
|
28
28
|
keyFingerprints?: (apiKeyId: string) => readonly string[];
|
|
29
|
+
/** The Home supervisor's current tunnel connection for a link (relay-auth.ts). */
|
|
30
|
+
connectionGeneration?: (linkId: string) => string | undefined;
|
|
29
31
|
}
|
|
30
32
|
|
|
31
33
|
export interface LinkListenerDeps {
|
|
@@ -112,7 +114,7 @@ export function createLinkListenerLifecycle<T>(deps: LinkListenerDeps = {}): Lin
|
|
|
112
114
|
return;
|
|
113
115
|
}
|
|
114
116
|
const requestedPort = store.listenerPort ?? 0;
|
|
115
|
-
const sessions = createLinkRelaySessions({ peers, fingerprints: (keyId, linkId) => {
|
|
117
|
+
const sessions = createLinkRelaySessions({ peers, connectionGeneration: linkId => startContext?.connectionGeneration?.(linkId), fingerprints: (keyId, linkId) => {
|
|
116
118
|
if (!readStoreForAdmission().links.some(link => link.id === linkId && link.apiKeyId === keyId)) return [];
|
|
117
119
|
return startContext?.keyFingerprints?.(keyId) ?? [];
|
|
118
120
|
} });
|