@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
|
@@ -731,11 +731,16 @@ function imagePart(imageUrl: string): WireContentPart | undefined {
|
|
|
731
731
|
return undefined;
|
|
732
732
|
}
|
|
733
733
|
|
|
734
|
-
|
|
734
|
+
/** Render replay prose; only Qoder opts into unsupported-reference history markers. */
|
|
735
|
+
export function formatMessageForHistory(message: OcxMessage, vendorNameByWire?: ReadonlyMap<string, string>, markUnsupportedImages = false): string {
|
|
735
736
|
if (message.role === "user") {
|
|
736
737
|
const text = typeof message.content === "string"
|
|
737
738
|
? message.content
|
|
738
|
-
: message.content.map(p =>
|
|
739
|
+
: message.content.map(p => {
|
|
740
|
+
if (p.type === "text" || p.type === "document") return p.text;
|
|
741
|
+
if (markUnsupportedImages && p.type === "image" && !imagePart(p.imageUrl)) return "[image omitted: unsupported reference]";
|
|
742
|
+
return `[${p.type}]`;
|
|
743
|
+
}).join("\n");
|
|
739
744
|
return `USER:\n${text}`;
|
|
740
745
|
}
|
|
741
746
|
if (message.role === "assistant") {
|
|
@@ -758,7 +763,11 @@ export function formatMessageForHistory(message: OcxMessage, vendorNameByWire?:
|
|
|
758
763
|
if (message.role === "toolResult") {
|
|
759
764
|
const text = typeof message.content === "string"
|
|
760
765
|
? message.content
|
|
761
|
-
: message.content.map(p =>
|
|
766
|
+
: message.content.map(p => {
|
|
767
|
+
if (p.type === "text" || p.type === "document") return p.text;
|
|
768
|
+
if (markUnsupportedImages && p.type === "image" && !imagePart(p.imageUrl)) return "[image omitted: unsupported reference]";
|
|
769
|
+
return "[image]";
|
|
770
|
+
}).join("");
|
|
762
771
|
const status = message.isError ? " (error)" : "";
|
|
763
772
|
return `TOOL RESULT (call_id: ${message.toolCallId})${status}:\n${text}`;
|
|
764
773
|
}
|
|
@@ -774,7 +783,7 @@ export function formatMessageForHistory(message: OcxMessage, vendorNameByWire?:
|
|
|
774
783
|
*/
|
|
775
784
|
export function buildInputLines(
|
|
776
785
|
message: OcxMessage,
|
|
777
|
-
options: { vendorNameByWire?: ReadonlyMap<string, string
|
|
786
|
+
options: { vendorNameByWire?: ReadonlyMap<string, string>; markUnsupportedImages?: boolean } = {},
|
|
778
787
|
): string[] {
|
|
779
788
|
if (message.role === "developer") return [];
|
|
780
789
|
|
|
@@ -788,6 +797,7 @@ export function buildInputLines(
|
|
|
788
797
|
else if (part.type === "image") {
|
|
789
798
|
const image = imagePart(part.imageUrl);
|
|
790
799
|
if (image) content.push(image);
|
|
800
|
+
else if (options.markUnsupportedImages) content.push(textPart("[image omitted: unsupported reference]"));
|
|
791
801
|
} else if (part.type === "document") {
|
|
792
802
|
content.push(textPart(part.text));
|
|
793
803
|
} else {
|
|
@@ -796,7 +806,7 @@ export function buildInputLines(
|
|
|
796
806
|
}
|
|
797
807
|
}
|
|
798
808
|
} else {
|
|
799
|
-
const formatted = formatMessageForHistory(message, options.vendorNameByWire);
|
|
809
|
+
const formatted = formatMessageForHistory(message, options.vendorNameByWire, options.markUnsupportedImages);
|
|
800
810
|
if (formatted) content.push(textPart(formatted));
|
|
801
811
|
}
|
|
802
812
|
|
|
@@ -832,7 +842,7 @@ export function buildSystemPrompt(parsed: OcxParsedRequest): string | undefined
|
|
|
832
842
|
*/
|
|
833
843
|
export function buildConversationInput(
|
|
834
844
|
parsed: OcxParsedRequest,
|
|
835
|
-
options: { maxHistoryChars?: number; vendorNameByWire?: ReadonlyMap<string, string
|
|
845
|
+
options: { maxHistoryChars?: number; vendorNameByWire?: ReadonlyMap<string, string>; markUnsupportedImages?: boolean } = {},
|
|
836
846
|
): string[] {
|
|
837
847
|
const nonDev = parsed.context.messages.filter(m => m.role !== "developer");
|
|
838
848
|
if (nonDev.length === 0) {
|
|
@@ -840,7 +850,7 @@ export function buildConversationInput(
|
|
|
840
850
|
}
|
|
841
851
|
|
|
842
852
|
if (nonDev.length === 1 && nonDev[0]!.role === "user") {
|
|
843
|
-
return buildInputLines(nonDev[0]!,
|
|
853
|
+
return buildInputLines(nonDev[0]!, options);
|
|
844
854
|
}
|
|
845
855
|
|
|
846
856
|
// Multi-turn conversation or history with tool results:
|
|
@@ -911,14 +921,14 @@ export function buildConversationInput(
|
|
|
911
921
|
const status = currentMessage.isError ? " (error)" : "";
|
|
912
922
|
currentRequestText = `TOOL RESULT (call_id: ${currentMessage.toolCallId})${status}:\n${text}\n\nPlease proceed based on the above tool result.`;
|
|
913
923
|
} else {
|
|
914
|
-
currentRequestText = formatMessageForHistory(currentMessage, options.vendorNameByWire);
|
|
924
|
+
currentRequestText = formatMessageForHistory(currentMessage, options.vendorNameByWire, options.markUnsupportedImages);
|
|
915
925
|
}
|
|
916
926
|
|
|
917
927
|
const imageBlocks: WireContentPart[] = [...historyImageBlocks, ...currentImageBlocks];
|
|
918
928
|
|
|
919
929
|
const maxHistoryChars = options.maxHistoryChars ?? MAX_PROJECTED_HISTORY_CHARS;
|
|
920
930
|
let historyText = historyMessages
|
|
921
|
-
.map(msg => formatMessageForHistory(msg, options.vendorNameByWire))
|
|
931
|
+
.map(msg => formatMessageForHistory(msg, options.vendorNameByWire, options.markUnsupportedImages))
|
|
922
932
|
.filter(Boolean)
|
|
923
933
|
.join("\n\n");
|
|
924
934
|
if (historyText.length > maxHistoryChars) {
|
|
@@ -7,6 +7,7 @@ import { isAllowedToolChoice, namespacedToolName, resolveToolChoiceWireName, too
|
|
|
7
7
|
import type { AdapterFetchContext, AdapterRequest, ProviderAdapter } from "./base";
|
|
8
8
|
import type { TranslatorBudget } from "../lib/translator-budget";
|
|
9
9
|
import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
10
|
+
import { clearableDeadline } from "../lib/abort";
|
|
10
11
|
import { debugDroppedFrame } from "../lib/debug";
|
|
11
12
|
import { configuredReasoningEfforts, modelRecordValue } from "../reasoning-effort";
|
|
12
13
|
import { commandCodeReasoningEfforts, refreshCommandCodeReasoningEfforts } from "../providers/command-code-efforts";
|
|
@@ -609,19 +610,17 @@ function requestModelId(request: AdapterRequest): string | undefined {
|
|
|
609
610
|
}
|
|
610
611
|
|
|
611
612
|
async function fetchCommandCode(request: AdapterRequest, ctx: AdapterFetchContext | undefined, executor: typeof globalThis.fetch): Promise<Response> {
|
|
612
|
-
const
|
|
613
|
-
const timer = setTimeout(() => timeout.abort(new DOMException("Timeout elapsed", "TimeoutError")), ctx?.timeoutMs ?? 200_000);
|
|
614
|
-
const callerSignal = ctx?.abortSignal ?? new AbortController().signal;
|
|
613
|
+
const deadline = clearableDeadline(ctx?.timeoutMs ?? 200_000, ctx?.abortSignal);
|
|
615
614
|
try {
|
|
616
615
|
return await executor(request.url, {
|
|
617
616
|
method: request.method,
|
|
618
617
|
headers: request.headers,
|
|
619
618
|
body: request.body,
|
|
620
619
|
redirect: "manual",
|
|
621
|
-
signal:
|
|
620
|
+
signal: deadline.signal,
|
|
622
621
|
});
|
|
623
622
|
} finally {
|
|
624
|
-
|
|
623
|
+
deadline.clear();
|
|
625
624
|
}
|
|
626
625
|
}
|
|
627
626
|
|
|
@@ -473,9 +473,11 @@ export function parseCursorVariantId(rawId: string): ParsedCursorVariantId {
|
|
|
473
473
|
}
|
|
474
474
|
let thinking = false;
|
|
475
475
|
let level: string | undefined;
|
|
476
|
-
const
|
|
477
|
-
|
|
478
|
-
|
|
476
|
+
const thinkingAt = stem.lastIndexOf("-thinking-");
|
|
477
|
+
const thinkingBase = thinkingAt < 0 ? "" : stem.slice(0, thinkingAt);
|
|
478
|
+
const thinkingLevel = thinkingAt < 0 ? "" : stem.slice(thinkingAt + "-thinking-".length);
|
|
479
|
+
if (/^[a-z-]+$/.test(thinkingLevel) && CURSOR_CAPABILITIES[thinkingBase] && (LEVEL_TOKENS as readonly string[]).includes(thinkingLevel)) {
|
|
480
|
+
return finishParse(thinkingBase, true, fast, thinkingLevel);
|
|
479
481
|
}
|
|
480
482
|
const levelThinking = stem.endsWith("-thinking") ? stripLevelSuffix(stem.slice(0, -"-thinking".length)) : undefined;
|
|
481
483
|
if (levelThinking && CURSOR_CAPABILITIES[levelThinking.stem]) {
|
|
@@ -42,26 +42,37 @@ function parseClaudeBase(raw: string): { canonicalBaseId: string; sourceBaseId:
|
|
|
42
42
|
|
|
43
43
|
export function normalizeCursorClaudeId(raw: string): NormalizedCursorClaudeId | undefined {
|
|
44
44
|
const id = raw.trim().toLowerCase();
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
45
|
+
// Recognize the numeric base first; suffix parsing never searches backwards
|
|
46
|
+
// through arbitrary repetitions of model-name delimiters.
|
|
47
|
+
const match = /^(claude-(?:fable|haiku|opus|sonnet)-\d+(?:[.-]\d+)*|claude-\d+(?:\.\d+)*-(?:fable|haiku|opus|sonnet))(?=-|$)/.exec(id);
|
|
48
|
+
if (!match) return undefined;
|
|
49
|
+
const base = parseClaudeBase(match[1]!);
|
|
50
|
+
if (!base) return undefined;
|
|
51
|
+
let suffix = id.slice(match[1]!.length);
|
|
52
|
+
if (!suffix) return { ...base, thinking: false, fast: false };
|
|
53
|
+
const fast = suffix.endsWith("-fast");
|
|
54
|
+
if (fast) suffix = suffix.slice(0, -"-fast".length);
|
|
55
|
+
let thinking = false;
|
|
56
|
+
let level: string | undefined;
|
|
57
|
+
if (suffix === "-thinking") {
|
|
58
|
+
thinking = true;
|
|
59
|
+
} else if (suffix.startsWith("-thinking-")) {
|
|
60
|
+
thinking = true;
|
|
61
|
+
level = suffix.slice("-thinking-".length);
|
|
62
|
+
} else if (suffix.endsWith("-thinking")) {
|
|
63
|
+
thinking = true;
|
|
64
|
+
level = suffix.slice(1, -"-thinking".length);
|
|
65
|
+
// The legacy greedy prefix leaves only the final hyphen-delimited token.
|
|
66
|
+
if (level.includes("-")) return undefined;
|
|
67
|
+
} else if (fast && suffix) {
|
|
68
|
+
level = suffix.slice(1);
|
|
69
|
+
if (level.includes("-")) return undefined;
|
|
70
|
+
} else if (suffix) {
|
|
71
|
+
return undefined;
|
|
62
72
|
}
|
|
63
|
-
|
|
64
|
-
|
|
73
|
+
if (level !== undefined && !CLAUDE_LEVELS.has(level)) return undefined;
|
|
74
|
+
const parsed = { base: base.sourceBaseId, thinking, fast, ...(level !== undefined ? { level } : {}) };
|
|
75
|
+
return { ...base, ...parsed };
|
|
65
76
|
}
|
|
66
77
|
|
|
67
78
|
export function composeCursorClaudeWireId(
|
|
@@ -297,7 +297,8 @@ export function classifyCursorError(message: string, sizeContext?: CursorSizeCon
|
|
|
297
297
|
lower.includes("rate limit") ||
|
|
298
298
|
lower.includes("rate-limit") ||
|
|
299
299
|
lower.includes("too many requests") ||
|
|
300
|
-
lower.includes("throttling")
|
|
300
|
+
lower.includes("throttling") ||
|
|
301
|
+
lower.includes("failed with http 429")
|
|
301
302
|
) return "Cursor rate limit exceeded";
|
|
302
303
|
|
|
303
304
|
if (
|
|
@@ -309,7 +310,9 @@ export function classifyCursorError(message: string, sizeContext?: CursorSizeCon
|
|
|
309
310
|
lower.includes("invalid token") ||
|
|
310
311
|
lower.includes("expired token") ||
|
|
311
312
|
lower.includes("authentication") ||
|
|
312
|
-
lower.includes("access denied")
|
|
313
|
+
lower.includes("access denied") ||
|
|
314
|
+
lower.includes("failed with http 401") ||
|
|
315
|
+
lower.includes("failed with http 403")
|
|
313
316
|
) return "Cursor authentication failed";
|
|
314
317
|
|
|
315
318
|
// gRPC FAILED_PRECONDITION is deterministic and non-retryable (unlike UNAVAILABLE):
|
|
@@ -38,11 +38,13 @@ export class CursorH2SessionPool {
|
|
|
38
38
|
request(
|
|
39
39
|
url: string,
|
|
40
40
|
headers: http2.OutgoingHttpHeaders,
|
|
41
|
+
credentialScope?: string,
|
|
41
42
|
): http2.ClientHttp2Stream {
|
|
42
43
|
if (this.closed) throw new Error("Cursor H2 session pool is closed");
|
|
43
44
|
this.armShutdownHook?.();
|
|
44
45
|
const origin = new URL(url).origin;
|
|
45
|
-
const
|
|
46
|
+
const poolKey = credentialScope ? `${origin}\0${credentialScope}` : origin;
|
|
47
|
+
const entry = this.usableEntry(poolKey) ?? this.createEntry(origin, poolKey);
|
|
46
48
|
try {
|
|
47
49
|
const stream = entry.session.request(headers);
|
|
48
50
|
entry.streams.add(stream);
|
|
@@ -74,33 +76,33 @@ export class CursorH2SessionPool {
|
|
|
74
76
|
|
|
75
77
|
get size(): number { return this.entries.size; }
|
|
76
78
|
|
|
77
|
-
private usableEntry(
|
|
78
|
-
const entry = this.entries.get(
|
|
79
|
+
private usableEntry(poolKey: string): PoolEntry | undefined {
|
|
80
|
+
const entry = this.entries.get(poolKey);
|
|
79
81
|
if (!entry) return undefined;
|
|
80
82
|
if (entry.usable && !entry.session.closed && !entry.session.destroyed) return entry;
|
|
81
83
|
this.drain(entry, false);
|
|
82
84
|
return undefined;
|
|
83
85
|
}
|
|
84
86
|
|
|
85
|
-
private createEntry(origin: string): PoolEntry {
|
|
87
|
+
private createEntry(origin: string, poolKey = origin): PoolEntry {
|
|
86
88
|
const session = http2.connect(origin);
|
|
87
89
|
const entry: PoolEntry = {
|
|
88
90
|
session,
|
|
89
91
|
streams: new Set(),
|
|
90
92
|
usable: true,
|
|
91
93
|
};
|
|
92
|
-
this.entries.set(
|
|
94
|
+
this.entries.set(poolKey, entry);
|
|
93
95
|
session.once("goaway", () => { this.drain(entry, true); });
|
|
94
96
|
session.on("error", () => { this.drain(entry, false); });
|
|
95
97
|
session.once("close", () => {
|
|
96
98
|
// Identity check: a stale close event from an old session must not evict
|
|
97
99
|
// a healthy replacement entry that was created after drain() removed the old one.
|
|
98
|
-
if (this.entries.get(
|
|
100
|
+
if (this.entries.get(poolKey) === entry) this.entries.delete(poolKey);
|
|
99
101
|
});
|
|
100
102
|
// Enforce bound: evict oldest when over capacity.
|
|
101
103
|
while (this.entries.size > this.maxSessions) {
|
|
102
104
|
const oldest = this.entries.keys().next().value;
|
|
103
|
-
if (!oldest || oldest ===
|
|
105
|
+
if (!oldest || oldest === poolKey) break;
|
|
104
106
|
const old = this.entries.get(oldest);
|
|
105
107
|
if (old) this.drain(old, true);
|
|
106
108
|
}
|
|
@@ -220,6 +220,7 @@ export class CursorHttp1BidiConnection {
|
|
|
220
220
|
"connect-protocol-version": "1",
|
|
221
221
|
authorization: `Bearer ${this.options.token}`,
|
|
222
222
|
"x-ghost-mode": "true",
|
|
223
|
+
"x-cursor-streaming": "true",
|
|
223
224
|
"x-cursor-client-version": this.options.clientVersion,
|
|
224
225
|
"x-cursor-client-type": "cli",
|
|
225
226
|
"x-request-id": this.options.requestId,
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
* and NO argument; `req.end(Buffer.alloc(0))` triggers `NGHTTP2_FRAME_SIZE_ERROR` on Bun, and a
|
|
14
14
|
* 5-byte gRPC/Connect frame makes the server mis-parse it ("illegal tag: field no 0").
|
|
15
15
|
*/
|
|
16
|
+
import { createHash } from "node:crypto";
|
|
16
17
|
import http2 from "node:http2";
|
|
17
18
|
import { cursorH2Pool } from "./h2-pool";
|
|
18
19
|
import { fromBinary } from "@bufbuild/protobuf";
|
|
@@ -27,7 +28,7 @@ import { isValidModelDiscoveryModelId } from "../../providers/model-discovery-li
|
|
|
27
28
|
import { GetUsableModelsResponseSchema } from "./gen/agent_pb";
|
|
28
29
|
|
|
29
30
|
const CURSOR_GET_USABLE_MODELS_PATH = "/agent.v1.AgentService/GetUsableModels";
|
|
30
|
-
const CURSOR_DISCOVERY_CLIENT_VERSION = "cli-2026.
|
|
31
|
+
const CURSOR_DISCOVERY_CLIENT_VERSION = "cli-2026.07.08-0c04a8a";
|
|
31
32
|
const CURSOR_MODEL_DISCOVERY_MAX_BYTES = 4 * 1024 * 1024;
|
|
32
33
|
type CursorUsableModelsFetcher = (opts: CursorUsableModelsOptions) => Promise<CursorUsableModelsResult>;
|
|
33
34
|
let cursorUsableModelsFetcherForTests: CursorUsableModelsFetcher | null = null;
|
|
@@ -226,11 +227,12 @@ async function fetchCursorUsableModelsHttp2Once(opts: CursorUsableModelsOptions)
|
|
|
226
227
|
|
|
227
228
|
let req: http2.ClientHttp2Stream;
|
|
228
229
|
try {
|
|
230
|
+
const credentialScope = createHash("sha256").update(opts.apiKey).digest("hex").slice(0, 16);
|
|
229
231
|
req = cursorH2Pool.request(baseUrl, {
|
|
230
232
|
":method": "POST",
|
|
231
233
|
":path": CURSOR_GET_USABLE_MODELS_PATH,
|
|
232
234
|
...cursorDiscoveryHeaders(opts),
|
|
233
|
-
|
|
235
|
+
}, credentialScope);
|
|
234
236
|
} catch {
|
|
235
237
|
return close({ ok: false, error: "transport", detail: "HTTP/2 request setup failed" });
|
|
236
238
|
}
|
package/src/adapters/cursor.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { createHash } from "node:crypto";
|
|
2
2
|
import type { AdapterEvent, OcxProviderConfig } from "../types";
|
|
3
3
|
import type { ProviderAdapter } from "./base";
|
|
4
|
+
import { decodeCursorJwtPayload } from "../oauth/cursor";
|
|
4
5
|
import { isTranslatorBudgetExceededError } from "../lib/translator-budget";
|
|
5
6
|
import { cursorExecDeniedMessage, cursorRequestDeclaresFullAccess } from "./cursor/exec-policy";
|
|
6
7
|
import { isCursorBenignCancelError, isCursorIncompleteToolCallMessage, isCursorInvalidArgumentError, isCursorOverflowRemintCandidate, isCursorRootEnvelopeError, safeCursorErrorMessage, type CursorSizeContext } from "./cursor/cursor-errors";
|
|
@@ -182,9 +183,11 @@ export function createCursorAdapter(provider: OcxProviderConfig, deps: CursorAda
|
|
|
182
183
|
try {
|
|
183
184
|
const token = resolveCursorToken(provider, incoming.headers);
|
|
184
185
|
liveRosterScope = cursorLiveRosterScope(provider.baseUrl, token);
|
|
186
|
+
const jwtSub = decodeCursorJwtPayload(token)?.sub;
|
|
187
|
+
const identitySeed = typeof jwtSub === "string" && jwtSub.trim() ? `sub:${jwtSub.trim()}` : token;
|
|
185
188
|
_parsed._cursorIdentityScope = createHash("sha256")
|
|
186
189
|
.update("ocx:cursor:acct:")
|
|
187
|
-
.update(
|
|
190
|
+
.update(identitySeed)
|
|
188
191
|
.digest("hex")
|
|
189
192
|
.slice(0, 16);
|
|
190
193
|
} catch {
|
|
@@ -1172,6 +1172,18 @@ function safeConnectCode(value: unknown): string | undefined {
|
|
|
1172
1172
|
*/
|
|
1173
1173
|
const TRAILER_QUOTA_RE = /\b(?:limit will reset|rate limit|quota exceeded|out of credits)\b/i;
|
|
1174
1174
|
|
|
1175
|
+
/**
|
|
1176
|
+
* Spent-window wording. A `failed_precondition` trailer is a 429 only with this evidence, and only
|
|
1177
|
+
* this evidence earns the synthesized "usage limit reached" label: an ordinary rate limit or a
|
|
1178
|
+
* per-minute "quota exceeded" stays out of both (#7625).
|
|
1179
|
+
*/
|
|
1180
|
+
const TRAILER_EXHAUSTED_RE = /\b(?:usage limit (?:has been )?reached|out of credits|(?:weekly|monthly|daily|usage(?:\s+window)?)\s+(?:usage\s+)?quota (?:has been|is) exhausted|usage window (?:has been|is) exhausted)\b/i;
|
|
1181
|
+
const TRAILER_TRANSIENT_LIMIT_RE = /\b(?:per[-\s](?:minute|hour)|rate)\b/i;
|
|
1182
|
+
|
|
1183
|
+
function isSpentTrailerWindow(message: string): boolean {
|
|
1184
|
+
return TRAILER_EXHAUSTED_RE.test(message) && !TRAILER_TRANSIENT_LIMIT_RE.test(message);
|
|
1185
|
+
}
|
|
1186
|
+
|
|
1175
1187
|
/**
|
|
1176
1188
|
* Connect error code to HTTP status.
|
|
1177
1189
|
*
|
|
@@ -1182,7 +1194,8 @@ const TRAILER_QUOTA_RE = /\b(?:limit will reset|rate limit|quota exceeded|out of
|
|
|
1182
1194
|
* acts on.
|
|
1183
1195
|
*/
|
|
1184
1196
|
export function connectTrailerHttpStatus(code: string | undefined, message: string): number | undefined {
|
|
1185
|
-
if (code === 'permission_denied' && TRAILER_QUOTA_RE.test(message)) return 429;
|
|
1197
|
+
if (code === 'permission_denied' && (TRAILER_QUOTA_RE.test(message) || isSpentTrailerWindow(message))) return 429;
|
|
1198
|
+
if (code === 'failed_precondition' && isSpentTrailerWindow(message)) return 429;
|
|
1186
1199
|
switch (code) {
|
|
1187
1200
|
case 'unauthenticated': return 401;
|
|
1188
1201
|
case 'permission_denied': return 403;
|
|
@@ -1635,8 +1648,11 @@ export async function* streamChatEvents(req: CloudChatRequest): AsyncGenerator<C
|
|
|
1635
1648
|
// is disabled. The `~` marks the delay as approximate; the shared
|
|
1636
1649
|
// parser accepts it once after Retry-After, so the outer client cooldown
|
|
1637
1650
|
// reads this same delay back from the message.
|
|
1651
|
+
const isQuotaExhausted = connectTrailerHttpStatus(trailerError.code, trailerError.message) === 429
|
|
1652
|
+
&& isSpentTrailerWindow(trailerError.message);
|
|
1653
|
+
const quotaSuffix = isQuotaExhausted ? ': usage limit reached' : '';
|
|
1638
1654
|
throw new CloudChatError(
|
|
1639
|
-
`Cognition chat failed${trailerError.code ? ` (${trailerError.code})` : ''} ` +
|
|
1655
|
+
`Cognition chat failed${trailerError.code ? ` (${trailerError.code}${quotaSuffix})` : ''} ` +
|
|
1640
1656
|
`(cloud trace ID: ${trailerError.traceId ?? 'n/a'})` +
|
|
1641
1657
|
(trailerError.retryAfterSeconds === undefined
|
|
1642
1658
|
? ''
|
|
@@ -512,10 +512,20 @@ export function antigravityReplaySessionKeysForTests(): string[] {
|
|
|
512
512
|
|
|
513
513
|
function extractSignature(part: Record<string, unknown>): string | undefined {
|
|
514
514
|
const direct = part.thoughtSignature ?? part.thought_signature;
|
|
515
|
-
if (
|
|
515
|
+
if (
|
|
516
|
+
typeof direct === "string"
|
|
517
|
+
&& direct.length >= MIN_SIGNATURE_LEN
|
|
518
|
+
&& direct !== THOUGHT_SIGNATURE_BYPASS
|
|
519
|
+
&& direct !== THOUGHT_SIGNATURE_CONTEXT_BYPASS
|
|
520
|
+
) return direct;
|
|
516
521
|
const extra = part.extra_content as { google?: { thought_signature?: unknown } } | undefined;
|
|
517
522
|
const nested = extra?.google?.thought_signature;
|
|
518
|
-
if (
|
|
523
|
+
if (
|
|
524
|
+
typeof nested === "string"
|
|
525
|
+
&& nested.length >= MIN_SIGNATURE_LEN
|
|
526
|
+
&& nested !== THOUGHT_SIGNATURE_BYPASS
|
|
527
|
+
&& nested !== THOUGHT_SIGNATURE_CONTEXT_BYPASS
|
|
528
|
+
) return nested;
|
|
519
529
|
return undefined;
|
|
520
530
|
}
|
|
521
531
|
|
|
@@ -630,6 +640,7 @@ export function antigravityUsesReplayCache(model: string): boolean {
|
|
|
630
640
|
* validator-bypass token.
|
|
631
641
|
*/
|
|
632
642
|
export const THOUGHT_SIGNATURE_BYPASS = "skip_thought_signature_validator";
|
|
643
|
+
export const THOUGHT_SIGNATURE_CONTEXT_BYPASS = "context_engineering_is_the_way_to_go";
|
|
633
644
|
|
|
634
645
|
/**
|
|
635
646
|
* True when the model speaks the Gemini wire dialect that requires a thought signature on the
|
|
@@ -54,7 +54,7 @@ export function isLikelyRealThoughtSignature(sig: string | undefined): boolean {
|
|
|
54
54
|
// signature exists. It is alphanumeric with underscores, so it would otherwise satisfy every
|
|
55
55
|
// check below and be re-ingested as genuine — cached, replayed, and eventually treated as
|
|
56
56
|
// evidence that a turn was signed. It is never a real signature.
|
|
57
|
-
if (sig === "skip_thought_signature_validator") return false;
|
|
57
|
+
if (sig === "skip_thought_signature_validator" || sig === "context_engineering_is_the_way_to_go") return false;
|
|
58
58
|
// Reject synthetic Responses/tool-call ids and Anthropic tool-use ids (`_` or `-` separators).
|
|
59
59
|
if (/^(fc|ctc|tsc|call|msg|rs|resp|reasoning|item|ws|toolu|tool|func|function)[-_]/i.test(sig)) return false;
|
|
60
60
|
// Real Gemini thought signatures are opaque base64/base64url blobs: only [A-Za-z0-9+/_=-].
|
|
@@ -80,7 +80,7 @@ function firstUserText(parsed: OcxParsedRequest): string | undefined {
|
|
|
80
80
|
* CLIProxyAPI `generateStableSessionID`: sha256(firstUserText) → BigEndian uint64 masked with
|
|
81
81
|
* 0x7FFFFFFFFFFFFFFF, prefixed with "-". Falls back to a random "-<digits>" id when there is no text.
|
|
82
82
|
*/
|
|
83
|
-
export function antigravitySessionId(parsed: OcxParsedRequest): string {
|
|
83
|
+
export function antigravitySessionId(parsed: OcxParsedRequest, accountScope?: string): string {
|
|
84
84
|
// The id must be IDENTICAL on turn N and turn N+1: the replay cache observes thought signatures
|
|
85
85
|
// on turn N's response and re-injects them on turn N+1's request, so a changing id loses the
|
|
86
86
|
// association entirely. (A *shared* id does not — signatures are keyed on functionCall identity,
|
|
@@ -103,7 +103,12 @@ export function antigravitySessionId(parsed: OcxParsedRequest): string {
|
|
|
103
103
|
// repair, not a universal one.
|
|
104
104
|
const text = codexThreadAnchor(parsed).preimage ?? firstUserText(parsed);
|
|
105
105
|
if (!text) return `-${Math.floor(Math.random() * 9e18).toString()}`;
|
|
106
|
-
const
|
|
106
|
+
const scope = parsed._reasoningReplayScope?.current?.credentialDurableIdentity?.trim()
|
|
107
|
+
|| parsed._reasoningReplayScope?.current?.credentialIdentity?.trim()
|
|
108
|
+
|| accountScope?.trim()
|
|
109
|
+
|| "";
|
|
110
|
+
const preimage = scope ? `acct:${scope}\0${text}` : text;
|
|
111
|
+
const digest = createHash("sha256").update(preimage, "utf8").digest();
|
|
107
112
|
const masked = digest.readBigUInt64BE(0) & 0x7fffffffffffffffn;
|
|
108
113
|
return `-${masked.toString()}`;
|
|
109
114
|
}
|
|
@@ -144,3 +144,36 @@ export function isQuotaExhaustedBody(payloadText: string): boolean {
|
|
|
144
144
|
if (status && status !== "RESOURCE_EXHAUSTED") return false;
|
|
145
145
|
return isGoogleQuotaExhaustedText(message ?? payloadText);
|
|
146
146
|
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* Extract a server-stated retry delay (seconds) from a Google 429 JSON error body's
|
|
150
|
+
* RetryInfo.retryDelay or ErrorInfo.metadata.quotaResetDelay (e.g. "42.5s" -> "43").
|
|
151
|
+
*/
|
|
152
|
+
export function extractGoogleRetryAfterSeconds(payloadText: string): string | undefined {
|
|
153
|
+
let parsed: unknown;
|
|
154
|
+
try { parsed = JSON.parse(payloadText); } catch { return undefined; }
|
|
155
|
+
const root = parsed && typeof parsed === "object" && !Array.isArray(parsed)
|
|
156
|
+
? (Array.isArray((parsed as { error?: unknown }).error)
|
|
157
|
+
? (parsed as { error: unknown[] }).error[0]
|
|
158
|
+
: ((parsed as { error?: unknown }).error ?? parsed))
|
|
159
|
+
: undefined;
|
|
160
|
+
if (!root || typeof root !== "object" || Array.isArray(root)) return undefined;
|
|
161
|
+
const details = (root as { details?: unknown }).details;
|
|
162
|
+
if (!Array.isArray(details)) return undefined;
|
|
163
|
+
for (const item of details) {
|
|
164
|
+
if (!item || typeof item !== "object" || Array.isArray(item)) continue;
|
|
165
|
+
const rec = item as Record<string, unknown>;
|
|
166
|
+
const raw = typeof rec.retryDelay === "string"
|
|
167
|
+
? rec.retryDelay
|
|
168
|
+
: (rec.metadata && typeof rec.metadata === "object" && !Array.isArray(rec.metadata)
|
|
169
|
+
&& typeof (rec.metadata as { quotaResetDelay?: unknown }).quotaResetDelay === "string"
|
|
170
|
+
? (rec.metadata as { quotaResetDelay: string }).quotaResetDelay
|
|
171
|
+
: undefined);
|
|
172
|
+
if (!raw) continue;
|
|
173
|
+
const match = /^\s*(\d+(?:\.\d+)?)\s*s\s*$/i.exec(raw);
|
|
174
|
+
if (!match) continue;
|
|
175
|
+
const seconds = Math.ceil(Number(match[1]));
|
|
176
|
+
if (Number.isFinite(seconds) && seconds > 0) return String(seconds);
|
|
177
|
+
}
|
|
178
|
+
return undefined;
|
|
179
|
+
}
|
|
@@ -4,15 +4,17 @@ import { createAdapterPhysicalSend } from "./physical-send";
|
|
|
4
4
|
import type { SendClass } from "../lib/request-execution-budget";
|
|
5
5
|
import type { AttemptRecoveryKind } from "../usage/log";
|
|
6
6
|
import { debugProviderDiagnosticLazy } from "../lib/debug";
|
|
7
|
-
import { isQuotaExhaustedBody, retryableGoogleStatus, safeGoogleHttpErrorMessage } from "./google-errors";
|
|
7
|
+
import { extractGoogleRetryAfterSeconds, isQuotaExhaustedBody, retryableGoogleStatus, safeGoogleHttpErrorMessage } from "./google-errors";
|
|
8
8
|
import { repairGoogleInvalidRequestBodyWithReport } from "./google-wire-compiler";
|
|
9
9
|
import type { GoogleToolSchemaPolicy, GoogleToolSchemaProfile } from "./google-tool-schema";
|
|
10
10
|
import { normalizeUpstreamHttpErrorResponse, readDisplaySafeErrorPayloadText } from "./upstream-http-error";
|
|
11
11
|
import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
12
|
+
import { markAntigravityModelNotFound } from "./antigravity-refusal";
|
|
12
13
|
import {
|
|
13
14
|
abortError,
|
|
14
15
|
cancelResponseBodyBestEffort,
|
|
15
16
|
fetchWithAttemptDeadline,
|
|
17
|
+
RETRY_AFTER_CEILING_MS,
|
|
16
18
|
retryBackoffDelayMs,
|
|
17
19
|
sleepWithAbort,
|
|
18
20
|
SendBudgetExhaustedError,
|
|
@@ -30,19 +32,27 @@ export interface GoogleRetryOptions {
|
|
|
30
32
|
toolSchemaPolicy?: GoogleToolSchemaPolicy;
|
|
31
33
|
}
|
|
32
34
|
|
|
33
|
-
async function normalizeFinalGoogleError(label: string, res: Response, signal?: AbortSignal): Promise<Response> {
|
|
34
|
-
if (label === "Antigravity" && res.status === 403) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
35
|
+
async function normalizeFinalGoogleError(label: string, res: Response, request: AdapterRequest, signal?: AbortSignal): Promise<Response> {
|
|
36
|
+
if (label === "Antigravity" && (res.status === 403 || res.status === 404)) {
|
|
37
|
+
let payloadText = "";
|
|
38
|
+
try {
|
|
39
|
+
const body = await readBoundedResponseBody(res, {
|
|
40
|
+
maxBytes: 4096, totalTimeoutMs: 2000, firstByteTimeoutMs: 2000,
|
|
41
|
+
inactivityTimeoutMs: 2000, signal,
|
|
42
|
+
});
|
|
43
|
+
if (body.displaySafe && !body.truncated && !body.timedOut && !body.oversized) payloadText = body.text;
|
|
44
|
+
} catch (error) {
|
|
45
|
+
if (signal?.aborted) throw error;
|
|
46
|
+
}
|
|
39
47
|
const headers = new Headers(res.headers);
|
|
40
48
|
headers.delete("content-encoding");
|
|
41
49
|
headers.delete("content-length");
|
|
42
|
-
|
|
43
|
-
|
|
50
|
+
const normalized = inheritAccountAutoPauseResponse(res, new Response(safeGoogleHttpErrorMessage(label, res.status,
|
|
51
|
+
payloadText), {
|
|
44
52
|
status: res.status, statusText: res.statusText, headers,
|
|
45
53
|
}));
|
|
54
|
+
if (!signal?.aborted) markAntigravityModelNotFound(normalized, request.body, payloadText);
|
|
55
|
+
return normalized;
|
|
46
56
|
}
|
|
47
57
|
return normalizeUpstreamHttpErrorResponse(res, {
|
|
48
58
|
signal,
|
|
@@ -109,7 +119,7 @@ export async function fetchGoogleWithRetry(
|
|
|
109
119
|
changedSendAllowed,
|
|
110
120
|
}));
|
|
111
121
|
if (!changedSendAllowed) {
|
|
112
|
-
return ctx.returnRawErrors ? res : normalizeFinalGoogleError(label, res, ctx.abortSignal);
|
|
122
|
+
return ctx.returnRawErrors ? res : normalizeFinalGoogleError(label, res, activeRequest, ctx.abortSignal);
|
|
113
123
|
}
|
|
114
124
|
}
|
|
115
125
|
compatibilityReplayUsed = true;
|
|
@@ -121,7 +131,7 @@ export async function fetchGoogleWithRetry(
|
|
|
121
131
|
}
|
|
122
132
|
}
|
|
123
133
|
if (!retryableGoogleStatus(res.status) || attempt === TRANSIENT_RETRY_MAX_ATTEMPTS - 1) {
|
|
124
|
-
return ctx.returnRawErrors ? res : normalizeFinalGoogleError(label, res, ctx.abortSignal);
|
|
134
|
+
return ctx.returnRawErrors ? res : normalizeFinalGoogleError(label, res, activeRequest, ctx.abortSignal);
|
|
125
135
|
}
|
|
126
136
|
// A 429 may be a transient rate limit (retry) or hard quota exhaustion (do NOT retry —
|
|
127
137
|
// it won't recover for hours and burns retries). Peek the body to tell them apart.
|
|
@@ -129,19 +139,34 @@ export async function fetchGoogleWithRetry(
|
|
|
129
139
|
const peekTarget = res.clone();
|
|
130
140
|
const peek = await readDisplaySafeErrorPayloadText(peekTarget, ctx.abortSignal);
|
|
131
141
|
if (isQuotaExhaustedBody(peek)) {
|
|
132
|
-
|
|
142
|
+
if (ctx.returnRawErrors) return res;
|
|
143
|
+
const normalized = await normalizeUpstreamHttpErrorResponse(res, {
|
|
133
144
|
signal: ctx.abortSignal,
|
|
134
145
|
formatMessage: payloadText => safeGoogleHttpErrorMessage(label, res.status, payloadText || peek),
|
|
135
146
|
});
|
|
147
|
+
if (!normalized.headers.has("retry-after")) {
|
|
148
|
+
const retryAfter = extractGoogleRetryAfterSeconds(peek);
|
|
149
|
+
if (retryAfter) normalized.headers.set("retry-after", retryAfter);
|
|
150
|
+
}
|
|
151
|
+
return normalized;
|
|
136
152
|
}
|
|
137
153
|
}
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
154
|
+
// Retry-After names the earliest send Google will serve (#7802). The local maximum bounds
|
|
155
|
+
// only our own backoff; it must not shorten the provider's instruction into a send it
|
|
156
|
+
// already said it would refuse. An instruction past the shared wait deadline ends with
|
|
157
|
+
// this upstream answer, Retry-After intact, exactly as fetchWithTransientRetry does.
|
|
158
|
+
const delayMs = retryBackoffDelayMs(attempt, {
|
|
141
159
|
baseDelayMs: GOOGLE_RETRY_BASE_MS,
|
|
142
160
|
maxDelayMs: GOOGLE_RETRY_MAX_MS,
|
|
143
161
|
headers: res.headers,
|
|
162
|
+
retryAfterIsLowerBound: true,
|
|
144
163
|
});
|
|
164
|
+
if (delayMs > RETRY_AFTER_CEILING_MS) {
|
|
165
|
+
return ctx.returnRawErrors ? res : normalizeFinalGoogleError(label, res, activeRequest, ctx.abortSignal);
|
|
166
|
+
}
|
|
167
|
+
pendingResponse = res;
|
|
168
|
+
recovery = res.status === 429 ? "rate-limit-429" : "transient-5xx";
|
|
169
|
+
retryDelayMs = delayMs;
|
|
145
170
|
} catch (err) {
|
|
146
171
|
if (ctx.abortSignal?.aborted) throw err;
|
|
147
172
|
if (err instanceof SendBudgetExhaustedError) {
|
|
@@ -151,7 +176,7 @@ export async function fetchGoogleWithRetry(
|
|
|
151
176
|
// upstream answer — but it used to leave the log indistinguishable from a request
|
|
152
177
|
// where no retry was ever eligible (#5044).
|
|
153
178
|
ctx.onRecoveryWithheld?.({ reason: "retry-send-budget" });
|
|
154
|
-
return ctx.returnRawErrors ? pendingResponse : normalizeFinalGoogleError(label, pendingResponse, ctx.abortSignal);
|
|
179
|
+
return ctx.returnRawErrors ? pendingResponse : normalizeFinalGoogleError(label, pendingResponse, activeRequest, ctx.abortSignal);
|
|
155
180
|
}
|
|
156
181
|
throw err;
|
|
157
182
|
}
|
|
@@ -172,6 +172,10 @@ function compileGenerationConfig(value: unknown): JsonObject | undefined {
|
|
|
172
172
|
: (["xhigh", "max", "ultra"].includes(raw) ? "high" : undefined);
|
|
173
173
|
if (thinkingLevel) thinking.thinkingLevel = thinkingLevel;
|
|
174
174
|
}
|
|
175
|
+
const rawBudget = finiteNumber(value.thinkingConfig.thinkingBudget ?? value.thinkingConfig.thinking_budget);
|
|
176
|
+
if (!thinking.thinkingLevel && rawBudget !== undefined && (rawBudget === -1 || rawBudget >= 0)) {
|
|
177
|
+
thinking.thinkingBudget = Math.floor(rawBudget);
|
|
178
|
+
}
|
|
175
179
|
// The one key that makes Google return `thought: true` text. Cloud Code Assist serves
|
|
176
180
|
// thinking either way (thoughtsTokenCount stays non-zero) but withholds the text unless the
|
|
177
181
|
// request opts in, so dropping it here silently reinstates the missing-thinking behavior.
|