@bitkyc08/opencodex 2.91.0 → 2.93.0-preview.20261027
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/ocx.mjs +47 -8
- package/gui/dist/assets/App-CJZoq-uF.js +58 -0
- package/gui/dist/assets/{Tray-BuLy7hL1.js → Tray-BWQPcgZn.js} +1 -1
- package/gui/dist/assets/index-DRe8Hhfz.css +1 -0
- package/gui/dist/assets/index-Xfct8owH.js +94 -0
- package/gui/dist/assets/quota-summary-DxToX1rV.js +1 -0
- package/gui/dist/index.html +2 -2
- package/gui/dist/provider-icons/workbuddy-color.svg +29 -0
- package/package.json +8 -7
- package/src/adapters/anthropic.ts +28 -5
- package/src/adapters/coding-agent/batch-dispatcher.ts +122 -0
- package/src/adapters/coding-agent/profile.ts +54 -16
- package/src/adapters/coding-agent/turn.ts +30 -2
- package/src/adapters/command-code.ts +114 -7
- package/src/adapters/cursor/native-exec-fs.ts +11 -9
- package/src/adapters/devin/live-models.ts +4 -0
- package/src/adapters/google-vertex-endpoint.ts +9 -1
- package/src/adapters/google-vertex-key-project.ts +223 -0
- package/src/adapters/google-wire-compiler.ts +1 -2
- package/src/adapters/google.ts +13 -3
- package/src/adapters/kiro/reasoning.ts +2 -0
- package/src/adapters/kiro-refusal.ts +6 -1
- package/src/adapters/kiro-wire.ts +1 -1
- package/src/adapters/openai-chat/messages.ts +8 -2
- package/src/adapters/openai-chat/passthrough.ts +35 -14
- package/src/adapters/openai-chat/reasoning-replay.ts +27 -16
- package/src/adapters/openai-chat/reasoning-wire.ts +117 -8
- package/src/adapters/openai-chat/required-tool-result.ts +64 -0
- package/src/adapters/openai-chat/tool-name-registry.ts +3 -1
- package/src/adapters/openai-chat.ts +9 -10
- package/src/adapters/openai-responses/passthrough.ts +7 -4
- package/src/adapters/openai-responses/reasoning.ts +13 -0
- package/src/adapters/openai-responses/request-strips.ts +60 -0
- package/src/adapters/qoder/adapter.ts +129 -8
- package/src/adapters/qoder/scaffold-guard.ts +5 -0
- package/src/adapters/reasoning-controls.ts +16 -0
- package/src/adapters/registry.ts +5 -0
- package/src/adapters/tool-call-id.ts +1 -3
- package/src/adapters/workbuddy-schema.ts +61 -0
- package/src/adapters/workbuddy.ts +68 -0
- package/src/bridge/errors.ts +27 -0
- package/src/bridge/response-json.ts +1 -1
- package/src/bridge/sse.ts +1 -1
- package/src/bridge.ts +1 -1
- package/src/chat/inbound.ts +4 -1
- package/src/chat/outbound.ts +20 -6
- package/src/chat/reasoning-details.ts +28 -5
- package/src/claude/desktop-first-party.ts +54 -4
- package/src/claude/desktop-picker.ts +11 -8
- package/src/claude/first-party-settings.ts +3 -1
- package/src/claude/inbound.ts +2 -1
- package/src/claude/intercept/local-ca.ts +2 -1
- package/src/claude/intercept/picker-ca-cleanup.ts +4 -2
- package/src/claude/intercept/picker-ca-startup.ts +3 -1
- package/src/claude/intercept/picker-models.ts +6 -3
- package/src/claude/intercept/picker-runtime.ts +3 -2
- package/src/claude/intercept/runtime.ts +6 -3
- package/src/claude/model-info.ts +31 -8
- package/src/cli/account-api.ts +11 -0
- package/src/cli/capabilities-agents-routing.ts +3 -3
- package/src/cli/capabilities-base.ts +7 -1
- package/src/cli/capabilities-observe-system.ts +10 -0
- package/src/cli/claude-desktop.ts +9 -8
- package/src/cli/claude.ts +3 -2
- package/src/cli/codex-cli-update.ts +8 -0
- package/src/cli/codex-shim-autorestore.ts +9 -0
- package/src/cli/combo-result.ts +13 -0
- package/src/cli/combo-stats.ts +3 -0
- package/src/cli/combo.ts +83 -41
- package/src/cli/cross-home-owner.ts +13 -1
- package/src/cli/dispatch.ts +25 -6
- package/src/cli/ensure-desired-integrations.ts +8 -6
- package/src/cli/export-command.ts +4 -1
- package/src/cli/help.ts +2 -1
- package/src/cli/index.ts +45 -45
- package/src/cli/integration-plan-dto.ts +4 -0
- package/src/cli/launcher-context.ts +49 -2
- package/src/cli/link.ts +45 -32
- package/src/cli/opencode.ts +20 -9
- package/src/cli/provider.ts +2 -1
- package/src/cli/registry.ts +6 -4
- package/src/cli/root.ts +9 -0
- package/src/cli/status.ts +59 -1
- package/src/cli/stop-restore.ts +113 -0
- package/src/cli/sync-expectation.ts +60 -0
- package/src/cli/uninstall-integrations.ts +41 -7
- package/src/cli/usage-compare.ts +68 -12
- package/src/client/connect.ts +40 -3
- package/src/client/link-home.ts +10 -1
- package/src/client/link-ingress.ts +1 -1
- package/src/client/link-readiness.ts +97 -0
- package/src/client/link-relay-transport.ts +79 -11
- package/src/client/link-relay.ts +74 -15
- package/src/client/link-tunnel.ts +45 -18
- package/src/client/machine-api.ts +3 -1
- package/src/client/machine-listener.ts +20 -2
- package/src/client/runtime.ts +20 -2
- package/src/client/sync-expectation.ts +118 -0
- package/src/clients/config-export/agent-clients.ts +96 -0
- package/src/clients/config-export/contracts.ts +25 -7
- package/src/clients/config-export/qoder.ts +38 -23
- package/src/clients/config-export/reasoning-metadata.ts +55 -8
- package/src/clients/config-export.ts +12 -0
- package/src/clients/lazycodex.ts +7 -2
- package/src/clients/reasoning-controls.ts +49 -0
- package/src/codex/account-store.ts +17 -3
- package/src/codex/app-server-restart-service.ts +6 -5
- package/src/codex/auth-api/account-identity.ts +14 -0
- package/src/codex/auth-api/account-list.ts +29 -2
- package/src/codex/auth-api/http.ts +13 -0
- package/src/codex/auth-api/main-account-probe.ts +2 -2
- package/src/codex/auth-api/pool-mode-gate.ts +16 -3
- package/src/codex/auth-api/pool-quota-probe.ts +15 -0
- package/src/codex/auth-context.ts +15 -12
- package/src/codex/catalog/build-entries.ts +22 -0
- package/src/codex/catalog/configured-tiers.ts +70 -0
- package/src/codex/catalog/effort.ts +52 -11
- package/src/codex/catalog/gather-capture.ts +5 -2
- package/src/codex/catalog/heal-observation.ts +155 -13
- package/src/codex/catalog/metadata.ts +6 -0
- package/src/codex/catalog/model-hints.ts +60 -11
- package/src/codex/catalog/model-visibility.ts +3 -2
- package/src/codex/catalog/native-models.ts +18 -3
- package/src/codex/catalog/parsing.ts +10 -8
- package/src/codex/catalog/pinned-models.ts +2 -1
- package/src/codex/catalog/provider-models.ts +18 -13
- package/src/codex/catalog/retained-sync.ts +2 -1
- package/src/codex/catalog/routed-gather.ts +19 -20
- package/src/codex/catalog/write-audit.ts +3 -2
- package/src/codex/catalog-self-heal.ts +43 -23
- package/src/codex/chatgpt-refresh-failure.ts +6 -2
- package/src/codex/cli-install-provenance.ts +418 -0
- package/src/codex/cli-installation-targets.ts +5 -1
- package/src/codex/cli-update-plan.ts +43 -16
- package/src/codex/collision-identity.ts +30 -5
- package/src/codex/convergence.ts +4 -3
- package/src/codex/data/roster-pinned-models.json +177 -1
- package/src/codex/desired-state.ts +6 -1
- package/src/codex/desktop-app/picker-freshness.ts +10 -8
- package/src/codex/desktop-compatibility/installed-build.ts +88 -12
- package/src/codex/desktop-compatibility/runtime.ts +29 -5
- package/src/codex/desktop-compatibility/usage-activation.ts +2 -1
- package/src/codex/desktop-compatibility/usage-controller.ts +9 -1
- package/src/codex/desktop-compatibility/windows-certificate-trust.ts +46 -12
- package/src/codex/inject/config-toml.ts +0 -18
- package/src/codex/inject/plan.ts +18 -3
- package/src/codex/inject/remove.ts +6 -2
- package/src/codex/inject.ts +1 -1
- package/src/codex/journal.ts +61 -1
- package/src/codex/model-entitlements.ts +1 -1
- package/src/codex/native-main-owner.ts +27 -1
- package/src/codex/native-profile-store.ts +2 -1
- package/src/codex/pool-credit-policy.ts +35 -1
- package/src/codex/pool-refresh-backoff.ts +3 -1
- package/src/codex/quota-types.ts +3 -0
- package/src/codex/quota.ts +24 -4
- package/src/codex/role-auto-assign.ts +6 -2
- package/src/codex/subagent-defaults.ts +49 -4
- package/src/codex/user-identity.ts +35 -6
- package/src/codex/windows-current-sid.ts +162 -0
- package/src/combos/failover.ts +17 -2
- package/src/combos/jev-decision-contract.ts +22 -1
- package/src/combos/jev-quota-activation.ts +5 -1
- package/src/combos/jev-quota-route.ts +1 -1
- package/src/combos/jev-quota.ts +9 -1
- package/src/combos/jev-service-exchange.ts +3 -1
- package/src/combos/jev-session-pin-config.ts +51 -0
- package/src/combos/jev.ts +101 -9
- package/src/combos/resolve.ts +45 -1
- package/src/combos/types.ts +43 -0
- package/src/config/load-degrade.ts +5 -0
- package/src/config/paths.ts +19 -3
- package/src/config/pending-teardown.ts +22 -1
- package/src/config/provider-validation.ts +22 -4
- package/src/config/removed-opencode-free.ts +11 -0
- package/src/config/schema/leaf-validators.ts +6 -0
- package/src/generated/compatibility-version.json +467 -311
- package/src/generated/model-metadata.ts +5 -5
- package/src/images/loop.ts +16 -2
- package/src/integrations/catalog-refresh.ts +1 -1
- package/src/integrations/hermes-profiles.ts +251 -0
- package/src/integrations/merge.ts +8 -0
- package/src/integrations/mutation-plan.ts +19 -4
- package/src/integrations/registry.ts +5 -0
- package/src/integrations/state.ts +36 -1
- package/src/integrations/writer.ts +18 -4
- package/src/lib/bun-path-runtime.mjs +2 -1
- package/src/lib/decision-quota-sink.ts +10 -0
- package/src/lib/errors.ts +62 -0
- package/src/lib/eventstream-decoder.ts +81 -37
- package/src/lib/opaque-proxy-tunnel.ts +32 -8
- package/src/lib/pinned-http.ts +35 -2
- package/src/lib/process-control.ts +13 -1
- package/src/lib/socks5-fetch.ts +59 -64
- package/src/lib/socks5-upload-waiter.ts +50 -0
- package/src/lib/sse-decoder.ts +7 -2
- package/src/lib/state-store-sweeper.ts +40 -14
- package/src/lib/translator-budget.ts +4 -4
- package/src/lib/upstream-retry.ts +4 -1
- package/src/lib/windows-native-principal-worker.ts +14 -0
- package/src/lib/windows-native-principal.ts +188 -0
- package/src/lib/windows-secret-acl.ts +39 -3
- package/src/lib/windows-user-principal.ts +62 -18
- package/src/link/diagnostics.ts +193 -0
- package/src/link/relay-auth.ts +6 -0
- package/src/link/ssh-config.ts +35 -3
- package/src/link/status-projection.ts +39 -0
- package/src/link/supervisor.ts +45 -12
- package/src/link/tunnel-history.ts +109 -0
- package/src/link/tunnel-state.ts +80 -17
- package/src/messaging/remote-files.ts +24 -1
- package/src/oauth/generic-account-failover.ts +91 -7
- package/src/oauth/index.ts +15 -0
- package/src/oauth/model-discovery-auth.ts +5 -0
- package/src/oauth/store.ts +4 -1
- package/src/oauth/token-guardian.ts +7 -0
- package/src/oauth/types.ts +9 -0
- package/src/oauth/workbuddy.ts +139 -0
- package/src/providers/account-quota-disk.ts +12 -4
- package/src/providers/antigravity-quota-identity.ts +37 -0
- package/src/providers/base-url-choices.ts +8 -5
- package/src/providers/codebuddy-models.ts +6 -0
- package/src/providers/codex-capacity.ts +3 -1
- package/src/providers/derive.ts +51 -3
- package/src/providers/kiro-models.ts +3 -0
- package/src/providers/mimo-thinking.ts +12 -0
- package/src/providers/model-discovery.ts +2 -0
- package/src/providers/model-rename-fields.ts +2 -0
- package/src/providers/model-rename-migration.ts +10 -0
- package/src/providers/openai-sidecar-credit.ts +2 -2
- package/src/providers/quota/account-cache.ts +3 -2
- package/src/providers/quota/antigravity.ts +25 -14
- package/src/providers/quota/report-cache.ts +13 -4
- package/src/providers/quota/vendor-probes-key.ts +60 -0
- package/src/providers/quota/workbuddy.ts +83 -0
- package/src/providers/quota-decision-antigravity.ts +64 -0
- package/src/providers/quota-decision-publication.ts +11 -0
- package/src/providers/quota-decision-snapshot.ts +21 -4
- package/src/providers/quota-types.ts +2 -0
- package/src/providers/quota.ts +3 -1
- package/src/providers/reasoning-capabilities.ts +76 -0
- package/src/providers/registry/entries-core.ts +23 -12
- package/src/providers/registry/entries-extended.ts +83 -27
- package/src/providers/registry/model-ids.ts +5 -0
- package/src/providers/registry/model-seeds.ts +120 -56
- package/src/providers/registry/types.ts +29 -2
- package/src/providers/resolved-model-policy.ts +30 -10
- package/src/providers/routed-config.ts +24 -1
- package/src/providers/stale-model-roster-migration.ts +123 -18
- package/src/providers/workbuddy-credit-balance.ts +81 -0
- package/src/providers/workbuddy-models.ts +37 -0
- package/src/providers/workbuddy.ts +60 -0
- package/src/remote-control/workspace-pi-runtime.ts +11 -6
- package/src/responses/compaction-summary.ts +45 -0
- package/src/responses/muse-tool-name-alias.ts +1 -2
- package/src/responses/parser.ts +3 -2
- package/src/responses/reasoning-replay-cache.ts +18 -14
- package/src/responses/schema.ts +1 -0
- package/src/responses/thought-signature-replay.ts +10 -2
- package/src/router.ts +2 -0
- package/src/routing/analytics.ts +2 -3
- package/src/routing/capability.ts +8 -2
- package/src/routing/fallback-policy.ts +3 -3
- package/src/routing/history/ingest.ts +28 -3
- package/src/server/auth-cors.ts +4 -2
- package/src/server/chat-completions.ts +21 -1
- package/src/server/chat-native-eligibility.ts +7 -0
- package/src/server/chat-native-reasoning.ts +24 -7
- package/src/server/chat-native.ts +13 -2
- package/src/server/claude-messages.ts +3 -0
- package/src/server/direct-local-http.ts +5 -2
- package/src/server/effort-policy.ts +5 -1
- package/src/server/index/link-relay-sessions.ts +9 -5
- package/src/server/index/live-sideband.ts +18 -15
- package/src/server/index/optional-listeners.ts +4 -0
- package/src/server/index/serve-options.ts +5 -4
- package/src/server/local-management-read-client.ts +3 -1
- package/src/server/management/agent-settings-routes.ts +27 -15
- package/src/server/management/combo-routes.ts +14 -4
- package/src/server/management/config-routes.ts +2 -2
- package/src/server/management/decision-discovery.ts +12 -2
- package/src/server/management/hermes-profile-routes.ts +156 -0
- package/src/server/management/integration-routes.ts +85 -24
- package/src/server/management/link-routes.ts +5 -2
- package/src/server/management/model-routes.ts +2 -2
- package/src/server/management/model-row-export-metadata.ts +25 -6
- package/src/server/management/model-rows.ts +15 -20
- package/src/server/management/native-integration-routes.ts +11 -8
- package/src/server/management/provider-routes.ts +1 -1
- package/src/server/management/route-registry.ts +4 -0
- package/src/server/management-api.ts +5 -0
- package/src/server/models-capabilities.ts +21 -3
- package/src/server/port-reclaim.ts +51 -9
- package/src/server/request-log-conversation.ts +49 -0
- package/src/server/request-log.ts +2 -0
- package/src/server/responses/adapter-delivery.ts +11 -1
- package/src/server/responses/adapter-dispatch.ts +2 -2
- package/src/server/responses/anthropic-thinking-recovery.ts +1 -0
- package/src/server/responses/codex-ws-exchange.ts +39 -9
- package/src/server/responses/codex-ws-session.ts +38 -4
- package/src/server/responses/codex-ws-wire.ts +6 -1
- package/src/server/responses/combo-required-tool-contract.ts +103 -0
- package/src/server/responses/combo-stream-preflight.ts +8 -1
- package/src/server/responses/compact.ts +14 -5
- package/src/server/responses/context-overflow.ts +8 -1
- package/src/server/responses/core-combo-failure.ts +10 -0
- package/src/server/responses/core-combo.ts +74 -44
- package/src/server/responses/core-lifetime.ts +5 -2
- package/src/server/responses/core-normalize.ts +17 -4
- package/src/server/responses/core-opaque-recovery.ts +1 -0
- package/src/server/responses/core-options.ts +7 -0
- package/src/server/responses/core-replay.ts +2 -1
- package/src/server/responses/jev-combo-choice.ts +39 -0
- package/src/server/responses/jev-session-pin.ts +203 -0
- package/src/server/responses/main-hard-lock-routing.ts +60 -44
- package/src/server/responses/passthrough-delivery.ts +44 -2
- package/src/server/responses/policy-fallback.ts +6 -1
- package/src/server/responses/request-compression.ts +12 -7
- package/src/server/responses/request-prepare.ts +32 -7
- package/src/server/responses/request-sidecar-auth.ts +2 -0
- package/src/server/responses/request-transport.ts +25 -6
- package/src/server/responses/response-effects.ts +22 -10
- package/src/server/responses/run-turn-execution.ts +2 -4
- package/src/server/responses/sidecar-execution.ts +13 -7
- package/src/server/responses-phase-inference.ts +267 -0
- package/src/server/sse-payload-rewrite.ts +14 -1
- package/src/server/stop-teardown.ts +36 -1
- package/src/server/ws-bridge.ts +1 -1
- package/src/service/definition.ts +20 -8
- package/src/service/desktop-supervision.d.mts +7 -4
- package/src/service/desktop-supervision.mjs +90 -13
- package/src/service/ownership-mutation-lease.mjs +21 -7
- package/src/types/config.ts +14 -2
- package/src/types/provider.ts +29 -7
- package/src/types/request.ts +11 -0
- package/src/types/wire.ts +1 -0
- package/src/types.ts +1 -0
- package/src/update/bind-probe.ts +29 -0
- package/src/update/codex-cli-update-launch-policy.d.mts +9 -0
- package/src/update/codex-cli-update-launch-policy.mjs +30 -0
- package/src/update/job.ts +10 -29
- package/src/update/npm-install-job.ps1 +173 -0
- package/src/update/npm-install.mjs +70 -0
- package/src/update/stop-contract.d.mts +1 -0
- package/src/update/stop-contract.mjs +14 -0
- package/src/update/stop-decision.d.mts +1 -1
- package/src/update/stop-decision.mjs +13 -3
- package/src/update/teardown-handover.ts +166 -0
- package/src/update/transactional-install.d.mts +14 -3
- package/src/update/transactional-install.mjs +33 -7
- package/src/usage/expected-prices.ts +64 -31
- package/src/usage/jev-stats.ts +54 -14
- package/src/usage/timeline.ts +19 -9
- package/src/vision/eligibility.ts +15 -5
- package/src/vision/plan.ts +2 -2
- package/src/web-search/loop.ts +16 -2
- package/gui/dist/assets/App-nZ34cR5G.js +0 -58
- package/gui/dist/assets/index-DGXS51sp.js +0 -94
- package/gui/dist/assets/index-DPeB9HpV.css +0 -1
- package/gui/dist/assets/quota-summary-DO1Sx5TM.js +0 -1
|
@@ -15,6 +15,12 @@ import { buildNonOpenAIToolCatalogNudgeForTools } from "./tool-catalog-nudge";
|
|
|
15
15
|
import { parseDataUrl } from "./image";
|
|
16
16
|
import { createAdapterPhysicalSend } from "./physical-send";
|
|
17
17
|
import { SendBudgetExhaustedError } from "../lib/upstream-retry";
|
|
18
|
+
import {
|
|
19
|
+
isVerifiedModelNotInPlanResponse,
|
|
20
|
+
markVerifiedModelNotInPlanResponse,
|
|
21
|
+
MODEL_NOT_IN_PLAN_CODE,
|
|
22
|
+
MODEL_NOT_IN_PLAN_REFUSAL_MARKER,
|
|
23
|
+
} from "../lib/errors";
|
|
18
24
|
import { CommandCodeToolTextFilter, type CommandCodeDeclaredTools } from "./command-code-tool-text";
|
|
19
25
|
import { EMPTY_COMMAND_CODE_PROJECT_CONTEXT, loadCommandCodeProjectContext } from "./command-code-project-context";
|
|
20
26
|
|
|
@@ -493,6 +499,35 @@ function isReasoningEffortRejection(status: number, payload: string): boolean {
|
|
|
493
499
|
return (status === 400 || status === 422) && /reasoning[_ -]?effort|unsupported effort|invalid effort/i.test(payload);
|
|
494
500
|
}
|
|
495
501
|
|
|
502
|
+
/** Command Code reports exhausted credits as BAD_REQUEST; normalize only that refusal
|
|
503
|
+
* so every caller can reuse the existing OAuth quota rotation and send budget. Key and
|
|
504
|
+
* forward rows keep the 400: a canonical key row has a same-key 429 retry ladder
|
|
505
|
+
* (`rateLimitRetryPolicyFor`) that would replay a credential whose credits are gone. */
|
|
506
|
+
async function normalizeCommandCodeCreditRefusal(
|
|
507
|
+
response: Response, oauth: boolean, signal?: AbortSignal,
|
|
508
|
+
): Promise<Response> {
|
|
509
|
+
if (!oauth || response.status !== 400) return response;
|
|
510
|
+
try {
|
|
511
|
+
const observed = await readBoundedResponseBody(response.clone(), {
|
|
512
|
+
signal,
|
|
513
|
+
maxBytes: 8 * 1024,
|
|
514
|
+
fatalUtf8: true,
|
|
515
|
+
});
|
|
516
|
+
if (!observed.displaySafe) return response;
|
|
517
|
+
const payload = JSON.parse(observed.text);
|
|
518
|
+
if (payload?.success !== false || payload.error?.code !== "BAD_REQUEST"
|
|
519
|
+
|| typeof payload.error?.message !== "string"
|
|
520
|
+
|| !payload.error.message.startsWith("You have insufficient credits to make this request.")) return response;
|
|
521
|
+
const headers = new Headers(response.headers);
|
|
522
|
+
headers.set("x-opencodex-upstream-status", "400");
|
|
523
|
+
headers.set("x-opencodex-refusal", "insufficient-credits");
|
|
524
|
+
return new Response(response.body, { status: 429, statusText: "Too Many Requests", headers });
|
|
525
|
+
} catch (error) {
|
|
526
|
+
if (signal?.aborted && error === signal.reason) throw error;
|
|
527
|
+
return response;
|
|
528
|
+
}
|
|
529
|
+
}
|
|
530
|
+
|
|
496
531
|
function requestWithoutReasoningEffort(request: AdapterRequest): AdapterRequest | undefined {
|
|
497
532
|
try {
|
|
498
533
|
const body = JSON.parse(request.body) as { params?: Record<string, unknown> };
|
|
@@ -504,6 +539,75 @@ function requestWithoutReasoningEffort(request: AdapterRequest): AdapterRequest
|
|
|
504
539
|
}
|
|
505
540
|
}
|
|
506
541
|
|
|
542
|
+
/** The upstream's plan refusal prefix; `MODEL_NOT_IN_PLAN_OTHER` and later mentions do not count. */
|
|
543
|
+
const COMMAND_CODE_PLAN_REFUSAL = /^MODEL_NOT_IN_PLAN(?::|$)/;
|
|
544
|
+
/** A model id the message may quote; anything else is described without repeating it. */
|
|
545
|
+
const DISPLAYABLE_MODEL_ID = /^[A-Za-z0-9][A-Za-z0-9._:/-]{0,127}$/;
|
|
546
|
+
|
|
547
|
+
/**
|
|
548
|
+
* Fixed client copy for a plan refusal. The upstream detail is never quoted: it is free text this
|
|
549
|
+
* proxy does not control, and quota or reasoning-effort words in it would steer the downstream
|
|
550
|
+
* classifiers (quota recording, effort repair) on a refusal that no resend can change.
|
|
551
|
+
*/
|
|
552
|
+
function commandCodePlanRefusalMessage(modelId: string | undefined): string {
|
|
553
|
+
const model = modelId && DISPLAYABLE_MODEL_ID.test(modelId) ? `the model "${modelId}"` : "the requested model";
|
|
554
|
+
return `Command Code refused ${model}: this account's plan does not include it (MODEL_NOT_IN_PLAN). `
|
|
555
|
+
+ "Choose a model the plan includes or change the Command Code plan; retrying this request will not succeed.";
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
/**
|
|
559
|
+
* Command Code refuses a model the account's plan excludes with HTTP 403 and
|
|
560
|
+
* `MODEL_NOT_IN_PLAN: ...` (#7684). Codex reconnects on every 403 through its whole retry budget,
|
|
561
|
+
* and a combo reads a 403 as a provider-wide credential verdict. The refusal names one model on one
|
|
562
|
+
* account, so it becomes a 400 `invalid_request_error` carrying `model_not_in_plan`, which Codex
|
|
563
|
+
* reports without retrying and combo or policy fallback treat as target-local. Every auth mode
|
|
564
|
+
* gets it: no account, key or provider cooldown is involved. Any other 403 stays untouched.
|
|
565
|
+
*/
|
|
566
|
+
async function normalizeCommandCodePlanRefusal(
|
|
567
|
+
response: Response, modelId: string | undefined, signal?: AbortSignal,
|
|
568
|
+
): Promise<Response> {
|
|
569
|
+
if (response.status !== 403) return response;
|
|
570
|
+
try {
|
|
571
|
+
const observed = await readBoundedResponseBody(response.clone(), {
|
|
572
|
+
signal,
|
|
573
|
+
maxBytes: 8 * 1024,
|
|
574
|
+
fatalUtf8: true,
|
|
575
|
+
});
|
|
576
|
+
if (!observed.displaySafe || observed.truncated) return response;
|
|
577
|
+
const payload = JSON.parse(observed.text);
|
|
578
|
+
if (payload?.success !== false || payload.error?.code !== "FORBIDDEN"
|
|
579
|
+
|| typeof payload.error?.message !== "string"
|
|
580
|
+
|| !COMMAND_CODE_PLAN_REFUSAL.test(payload.error.message)) return response;
|
|
581
|
+
try { void response.body?.cancel().catch(() => {}); } catch { /* already closed */ }
|
|
582
|
+
const headers = new Headers({ "Content-Type": "application/json" });
|
|
583
|
+
headers.set("x-opencodex-upstream-status", "403");
|
|
584
|
+
headers.set("x-opencodex-refusal", MODEL_NOT_IN_PLAN_REFUSAL_MARKER);
|
|
585
|
+
const refusal = new Response(JSON.stringify({ error: {
|
|
586
|
+
type: "invalid_request_error", code: MODEL_NOT_IN_PLAN_CODE, message: commandCodePlanRefusalMessage(modelId),
|
|
587
|
+
} }), { status: 400, statusText: "Bad Request", headers });
|
|
588
|
+
// Identity is the provenance dispatch, combo and policy fallback check; the header is diagnostic.
|
|
589
|
+
markVerifiedModelNotInPlanResponse(refusal);
|
|
590
|
+
return refusal;
|
|
591
|
+
} catch (error) {
|
|
592
|
+
if (signal?.aborted && error === signal.reason) throw error;
|
|
593
|
+
return response;
|
|
594
|
+
}
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/** Both Command Code refusal rewrites, in the order every send applies them. */
|
|
598
|
+
async function normalizeCommandCodeRefusal(
|
|
599
|
+
response: Response, oauth: boolean, modelId: string | undefined, signal?: AbortSignal,
|
|
600
|
+
): Promise<Response> {
|
|
601
|
+
return normalizeCommandCodePlanRefusal(await normalizeCommandCodeCreditRefusal(response, oauth, signal), modelId, signal);
|
|
602
|
+
}
|
|
603
|
+
|
|
604
|
+
function requestModelId(request: AdapterRequest): string | undefined {
|
|
605
|
+
try {
|
|
606
|
+
const model = (JSON.parse(request.body) as { params?: { model?: unknown } }).params?.model;
|
|
607
|
+
return typeof model === "string" ? model : undefined;
|
|
608
|
+
} catch { return undefined; }
|
|
609
|
+
}
|
|
610
|
+
|
|
507
611
|
async function fetchCommandCode(request: AdapterRequest, ctx: AdapterFetchContext | undefined, executor: typeof globalThis.fetch): Promise<Response> {
|
|
508
612
|
const timeout = new AbortController();
|
|
509
613
|
const timer = setTimeout(() => timeout.abort(new DOMException("Timeout elapsed", "TimeoutError")), ctx?.timeoutMs ?? 200_000);
|
|
@@ -589,6 +693,8 @@ function supportedCommandCodeEffort(provider: OcxProviderConfig, modelId: string
|
|
|
589
693
|
|
|
590
694
|
export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderAdapter {
|
|
591
695
|
const executor = (provider as OcxProviderConfig & { fetch?: typeof globalThis.fetch }).fetch ?? globalThis.fetch;
|
|
696
|
+
// Only an OAuth row has sibling accounts for the rewritten 429 to rotate to.
|
|
697
|
+
const creditRefusalRotates = provider.authMode === "oauth";
|
|
592
698
|
// The server builds one adapter per routed request and hands parseStream a guarded wrapper
|
|
593
699
|
// rather than the Response fetchResponse returned, so the stream reads the declared catalog of
|
|
594
700
|
// the request this instance last built. A parser with no built request restores nothing.
|
|
@@ -651,8 +757,12 @@ export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderA
|
|
|
651
757
|
},
|
|
652
758
|
async fetchResponse(request: AdapterRequest, ctx?: AdapterFetchContext): Promise<Response> {
|
|
653
759
|
const send = createAdapterPhysicalSend(ctx, executor);
|
|
654
|
-
const
|
|
655
|
-
|
|
760
|
+
const modelId = requestModelId(request);
|
|
761
|
+
const response = await normalizeCommandCodeRefusal(
|
|
762
|
+
await send({ url: request.url, dispatch: physical => fetchCommandCode(request, ctx, physical) }), creditRefusalRotates, modelId, ctx?.abortSignal,
|
|
763
|
+
);
|
|
764
|
+
// A plan refusal is final for this model: no effort downgrade can change the plan.
|
|
765
|
+
if (response.ok || isVerifiedModelNotInPlanResponse(response)) return response;
|
|
656
766
|
const currentEffort = (() => {
|
|
657
767
|
try { return (JSON.parse(request.body) as { params?: { reasoning_effort?: unknown } }).params?.reasoning_effort; } catch { return undefined; }
|
|
658
768
|
})();
|
|
@@ -664,9 +774,6 @@ export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderA
|
|
|
664
774
|
body = observed.text;
|
|
665
775
|
} catch { return response; }
|
|
666
776
|
if (!isReasoningEffortRejection(response.status, body)) return response;
|
|
667
|
-
const modelId = (() => {
|
|
668
|
-
try { return (JSON.parse(request.body) as { params?: { model?: unknown } }).params?.model; } catch { return undefined; }
|
|
669
|
-
})();
|
|
670
777
|
if (typeof modelId !== "string") return response;
|
|
671
778
|
// An operator who wrote this ladder authorized the rung deliberately. Replaying the turn
|
|
672
779
|
// without it would answer at the provider default and hide a wrong configuration behind a
|
|
@@ -678,9 +785,9 @@ export function createCommandCodeAdapter(provider: OcxProviderConfig): ProviderA
|
|
|
678
785
|
const retry = requestWithoutReasoningEffort(request);
|
|
679
786
|
if (!retry) return response;
|
|
680
787
|
try {
|
|
681
|
-
return await send({ url: retry.url, sendClass: "repair", recovery: "reasoning-effort-downgrade",
|
|
788
|
+
return await normalizeCommandCodeRefusal(await send({ url: retry.url, sendClass: "repair", recovery: "reasoning-effort-downgrade",
|
|
682
789
|
beforeDispatch: () => { try { void response.body?.cancel().catch(() => {}); } catch { /* already closed */ } },
|
|
683
|
-
dispatch: physical => fetchCommandCode(retry, ctx, physical) });
|
|
790
|
+
dispatch: physical => fetchCommandCode(retry, ctx, physical) }), creditRefusalRotates, modelId, ctx?.abortSignal);
|
|
684
791
|
} catch (error) {
|
|
685
792
|
if (error instanceof SendBudgetExhaustedError) return response;
|
|
686
793
|
throw error;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, readdirSync, readFileSync, rmSync, statSync, writeFileSync } from "node:fs";
|
|
2
|
-
import { basename, dirname, extname, join, relative, resolve } from "node:path";
|
|
2
|
+
import { basename, dirname, extname, join, relative, resolve, sep } from "node:path";
|
|
3
3
|
import { create } from "@bufbuild/protobuf";
|
|
4
4
|
import {
|
|
5
5
|
DeleteErrorSchema,
|
|
@@ -235,19 +235,21 @@ export function lsExec(execMsg: ExecServerMessage): Uint8Array {
|
|
|
235
235
|
}
|
|
236
236
|
}
|
|
237
237
|
|
|
238
|
-
function
|
|
239
|
-
if (!glob) return true;
|
|
240
|
-
|
|
241
|
-
|
|
238
|
+
function grepFileMatcher(root: string, glob?: string): (file: string) => boolean {
|
|
239
|
+
if (!glob) return () => true;
|
|
240
|
+
const matcher = new Bun.Glob(glob.replace(/^(?:\.\/)+/, ""));
|
|
241
|
+
// Bare patterns apply to each basename; slash patterns are relative to the selected root.
|
|
242
|
+
const pathPattern = glob.includes("/");
|
|
243
|
+
return file => matcher.match(pathPattern ? relative(root, file).split(sep).join("/") : basename(file));
|
|
242
244
|
}
|
|
243
245
|
|
|
244
|
-
function collectFiles(root: string,
|
|
246
|
+
function collectFiles(root: string, matchesFile: (file: string) => boolean, out: string[] = []): string[] {
|
|
245
247
|
if (out.length >= MAX_GREP_FILES) return out;
|
|
246
248
|
for (const entry of readdirSync(root, { withFileTypes: true })) {
|
|
247
249
|
if (entry.name === "node_modules" || entry.name === ".git") continue;
|
|
248
250
|
const path = join(root, entry.name);
|
|
249
|
-
if (entry.isDirectory()) collectFiles(path,
|
|
250
|
-
if (entry.isFile() &&
|
|
251
|
+
if (entry.isDirectory()) collectFiles(path, matchesFile, out);
|
|
252
|
+
if (entry.isFile() && matchesFile(path)) out.push(path);
|
|
251
253
|
if (out.length >= MAX_GREP_FILES) break;
|
|
252
254
|
}
|
|
253
255
|
return out;
|
|
@@ -269,7 +271,7 @@ export function grepExec(execMsg: ExecServerMessage): Uint8Array {
|
|
|
269
271
|
const root = resolve(args.path || process.cwd());
|
|
270
272
|
try {
|
|
271
273
|
const pattern = new RegExp(args.pattern, args.caseInsensitive ? "i" : "");
|
|
272
|
-
const files = existsSync(root) && statSync(root).isDirectory() ? collectFiles(root, args.glob) : [root];
|
|
274
|
+
const files = existsSync(root) && statSync(root).isDirectory() ? collectFiles(root, grepFileMatcher(root, args.glob)) : [root];
|
|
273
275
|
const matches = [];
|
|
274
276
|
for (const file of files) {
|
|
275
277
|
if (matches.length >= MAX_GREP_RESULTS) break;
|
|
@@ -27,6 +27,8 @@ export const DEVIN_STATIC_MODELS = [
|
|
|
27
27
|
// 260930 preemptive: GPT-6.1 Sol (devin.ai/blog/gpt-6-1-sol says it is live; the uid is not published).
|
|
28
28
|
// Spelled the way Devin spells gpt-5.6-sol; live discovery replaces this seed once a credential is present.
|
|
29
29
|
"gpt-6-1-sol",
|
|
30
|
+
// 261027 preemptive: GPT-6.1 Terra (mirrors Devin's GPT-6.1 Sol seed; uid unverified).
|
|
31
|
+
"gpt-6-1-terra",
|
|
30
32
|
"claude-opus-4-8",
|
|
31
33
|
"claude-fable-5-1",
|
|
32
34
|
"claude-sonnet-5",
|
|
@@ -66,6 +68,8 @@ export const DEVIN_MODEL_CONTEXT_WINDOWS: Record<string, number> = {
|
|
|
66
68
|
"gpt-6-luna": 1_000_000,
|
|
67
69
|
// 260930 preemptive: unmeasured; mirrors the GPT-6 Sol row Cognition serves.
|
|
68
70
|
"gpt-6-1-sol": 1_000_000,
|
|
71
|
+
// 261027 preemptive: GPT-6.1 Terra (unmeasured; mirrors Devin's GPT-6.1 Sol window).
|
|
72
|
+
"gpt-6-1-terra": 1_000_000,
|
|
69
73
|
"claude-opus-4-8": 1_000_000,
|
|
70
74
|
// 260923: read from the live catalog (devin/claude-opus-5-5 context_length 1_000_000).
|
|
71
75
|
"claude-opus-5-5": 1_000_000,
|
|
@@ -1,10 +1,13 @@
|
|
|
1
1
|
import { googleVertexLocationConfigError } from "../providers/google-vertex-location";
|
|
2
|
+
import { VERTEX_PROJECT_AUTO } from "./google-vertex-key-project";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* Vertex endpoint selection, shared by inference and replay identity.
|
|
5
6
|
*
|
|
6
7
|
* API keys follow explicit provider configuration only: `provider.project` selects the project
|
|
7
8
|
* endpoint (location defaults to `global`), otherwise the projectless express endpoint is used.
|
|
9
|
+
* `provider.project: "auto"` resolves the project of each key it sends (see
|
|
10
|
+
* google-vertex-key-project.ts), so one key pool may span several projects.
|
|
8
11
|
* Ambient GOOGLE_CLOUD_PROJECT / GCLOUD_PROJECT / GOOGLE_CLOUD_LOCATION belong to ADC, so an
|
|
9
12
|
* unrelated gcloud default in the shell cannot move an express-mode key onto another project.
|
|
10
13
|
*/
|
|
@@ -20,11 +23,16 @@ export function selectVertexEndpoint(
|
|
|
20
23
|
env: NodeJS.ProcessEnv = process.env,
|
|
21
24
|
): VertexEndpointSelection {
|
|
22
25
|
// A blank or whitespace-only project is unset: it must not select a /projects/%20/ endpoint.
|
|
23
|
-
const
|
|
26
|
+
const rawProject = provider.project?.trim() || undefined;
|
|
27
|
+
const configuredProject = rawProject?.toLowerCase() === VERTEX_PROJECT_AUTO ? VERTEX_PROJECT_AUTO : rawProject;
|
|
24
28
|
if (hasApiKey) {
|
|
25
29
|
if (!configuredProject) return { kind: "express" };
|
|
26
30
|
return { kind: "project", project: configuredProject, location: provider.location || "global" };
|
|
27
31
|
}
|
|
32
|
+
// "auto" names a per-key lookup, never a project id; ADC has no key to resolve it from.
|
|
33
|
+
if (configuredProject === VERTEX_PROJECT_AUTO) {
|
|
34
|
+
throw new Error('Vertex AI project "auto" requires an API key; set provider.project to a project id for ADC.');
|
|
35
|
+
}
|
|
28
36
|
const project = configuredProject || env.GOOGLE_CLOUD_PROJECT || env.GCLOUD_PROJECT;
|
|
29
37
|
if (!project) throw new Error("Vertex AI requires a project id (provider.project or GOOGLE_CLOUD_PROJECT/GCLOUD_PROJECT).");
|
|
30
38
|
const location = provider.location || env.GOOGLE_CLOUD_LOCATION;
|
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import { readBoundedResponseBody } from "../lib/bounded-body";
|
|
2
|
+
import { markEgressTransparentExecutor, providerEgressSendInit } from "../lib/provider-egress";
|
|
3
|
+
import { configuredOutboundFetch } from "../lib/proxy-env";
|
|
4
|
+
import { withUpstreamHttpVersion } from "../lib/upstream-http-version";
|
|
5
|
+
import type { OcxProviderConfig } from "../types";
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Per-key project discovery for Vertex express-mode API keys (`provider.project: "auto"`).
|
|
9
|
+
*
|
|
10
|
+
* An express-mode key belongs to one Google Cloud project, and Google's projectless endpoint
|
|
11
|
+
* echoes `projects/<number>/locations/<region>/...` in its 404 body for a nonexistent model
|
|
12
|
+
* (observed 2026-10-18 across five express-mode keys on `aiplatform.googleapis.com`). That is an
|
|
13
|
+
* undocumented upstream error shape rather than a stable discovery API, so `"auto"` is strictly
|
|
14
|
+
* opt-in and any non-404, truncated, oversized, invalid-UTF-8 or non-matching body falls back to
|
|
15
|
+
* the projectless express endpoint without caching.
|
|
16
|
+
*/
|
|
17
|
+
export const VERTEX_PROJECT_AUTO = "auto";
|
|
18
|
+
|
|
19
|
+
const PROBE_URL = "https://aiplatform.googleapis.com/v1/publishers/google/models/ocx-project-probe:countTokens";
|
|
20
|
+
const PROBE_TIMEOUT_MS = 10_000;
|
|
21
|
+
/** Google's 404 JSON for a missing publisher model is ~320 bytes; 4 KiB bounds untrusted bodies. */
|
|
22
|
+
export const VERTEX_PROBE_MAX_BYTES = 4096;
|
|
23
|
+
const PROJECT_NUMBER = /\bprojects\/(\d{1,20})\/locations\//;
|
|
24
|
+
/** Pool sizes are small; the cap only bounds a pathological rotation of distinct keys. */
|
|
25
|
+
const CACHE_LIMIT = 64;
|
|
26
|
+
|
|
27
|
+
/** Keyed by a SHA-256 digest so the cache never retains raw key material. Insertion-order LRU. */
|
|
28
|
+
const resolved = new Map<string, string>();
|
|
29
|
+
|
|
30
|
+
interface ProbeWaiter {
|
|
31
|
+
signal?: AbortSignal;
|
|
32
|
+
resolve: (project: string | undefined) => void;
|
|
33
|
+
reject: (reason: unknown) => void;
|
|
34
|
+
onAbort?: () => void;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface InflightProbe {
|
|
38
|
+
controller: AbortController;
|
|
39
|
+
waiters: Set<ProbeWaiter>;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
const inflight = new Map<string, InflightProbe>();
|
|
43
|
+
|
|
44
|
+
/** Computes the non-reversible SHA-256 cache key for an API key. */
|
|
45
|
+
function cacheKey(apiKey: string): string {
|
|
46
|
+
return new Bun.CryptoHasher("sha256").update(apiKey).digest("base64url");
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Records a resolved project number in the bounded insertion-order LRU cache. */
|
|
50
|
+
function remember(key: string, project: string): void {
|
|
51
|
+
resolved.delete(key);
|
|
52
|
+
resolved.set(key, project);
|
|
53
|
+
while (resolved.size > CACHE_LIMIT) resolved.delete(resolved.keys().next().value!);
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** Extracts the project number from Google's projectless NOT_FOUND body; exported for tests. */
|
|
57
|
+
export function parseVertexProbeProjectNumber(body: string): string | undefined {
|
|
58
|
+
return PROJECT_NUMBER.exec(body)?.[1];
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export interface VertexKeyProjectOptions {
|
|
62
|
+
fetch?: typeof fetch;
|
|
63
|
+
signal?: AbortSignal;
|
|
64
|
+
provider?: OcxProviderConfig;
|
|
65
|
+
providerName?: string;
|
|
66
|
+
/** Test seam for the bounded-body and request deadline. */
|
|
67
|
+
timeoutMs?: number;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const defaultOutboundFetch = markEgressTransparentExecutor(
|
|
71
|
+
((input: Parameters<typeof fetch>[0], init?: RequestInit) => configuredOutboundFetch(input, init)) as typeof fetch,
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
/** Builds the side-effect-free outbound transport honoring provider egress and HTTP version. */
|
|
75
|
+
function selectProbeFetch(options: VertexKeyProjectOptions): typeof fetch {
|
|
76
|
+
if (options.fetch) return options.fetch;
|
|
77
|
+
const provider = options.provider;
|
|
78
|
+
const customFetch = (provider as (OcxProviderConfig & { fetch?: typeof fetch }) | undefined)?.fetch;
|
|
79
|
+
if (!provider) return customFetch ?? globalThis.fetch;
|
|
80
|
+
const base = customFetch ?? defaultOutboundFetch;
|
|
81
|
+
const providerName = options.providerName ?? "google-vertex";
|
|
82
|
+
return ((input: Parameters<typeof fetch>[0], init?: RequestInit) => {
|
|
83
|
+
const egressInit = providerEgressSendInit({ providerName, provider }, base, input);
|
|
84
|
+
const versioned = withUpstreamHttpVersion(input, init, provider);
|
|
85
|
+
return base(input, { ...versioned, ...egressInit });
|
|
86
|
+
}) as typeof fetch;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** Sends one bounded countTokens probe to Google and extracts the project number from a 404 body. */
|
|
90
|
+
async function probe(
|
|
91
|
+
apiKey: string,
|
|
92
|
+
fetchImpl: typeof fetch,
|
|
93
|
+
signal: AbortSignal,
|
|
94
|
+
timeoutMs: number,
|
|
95
|
+
): Promise<string | undefined> {
|
|
96
|
+
const probeSignal = AbortSignal.any([signal, AbortSignal.timeout(timeoutMs)]);
|
|
97
|
+
try {
|
|
98
|
+
const res = await fetchImpl(PROBE_URL, {
|
|
99
|
+
method: "POST",
|
|
100
|
+
redirect: "manual",
|
|
101
|
+
headers: { "content-type": "application/json", "x-goog-api-key": apiKey },
|
|
102
|
+
body: JSON.stringify({ contents: [{ role: "user", parts: [{ text: "x" }] }] }),
|
|
103
|
+
signal: probeSignal,
|
|
104
|
+
});
|
|
105
|
+
// Only Google's model NOT_FOUND names the key's project; 401/403/429 and redirects do not.
|
|
106
|
+
if (res.status !== 404) {
|
|
107
|
+
void res.body?.cancel().catch(() => {});
|
|
108
|
+
return undefined;
|
|
109
|
+
}
|
|
110
|
+
const body = await readBoundedResponseBody(res, {
|
|
111
|
+
maxBytes: VERTEX_PROBE_MAX_BYTES,
|
|
112
|
+
totalTimeoutMs: timeoutMs,
|
|
113
|
+
inactivityTimeoutMs: timeoutMs,
|
|
114
|
+
firstByteTimeoutMs: timeoutMs,
|
|
115
|
+
signal: probeSignal,
|
|
116
|
+
reportUtf8Validity: true,
|
|
117
|
+
});
|
|
118
|
+
if (body.truncated || body.oversized || body.timedOut || !body.displaySafe || body.utf8Valid === false) {
|
|
119
|
+
return undefined;
|
|
120
|
+
}
|
|
121
|
+
return parseVertexProbeProjectNumber(body.text);
|
|
122
|
+
} catch {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Detaches the abort listener registered for a coalesced probe waiter. */
|
|
128
|
+
function cleanupWaiter(waiter: ProbeWaiter): void {
|
|
129
|
+
if (waiter.signal && waiter.onAbort) {
|
|
130
|
+
waiter.signal.removeEventListener("abort", waiter.onAbort);
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** Starts a shared in-flight probe and fans the result out to all active waiters. */
|
|
135
|
+
function startInflight(
|
|
136
|
+
key: string,
|
|
137
|
+
apiKey: string,
|
|
138
|
+
fetchImpl: typeof fetch,
|
|
139
|
+
timeoutMs: number,
|
|
140
|
+
): InflightProbe {
|
|
141
|
+
const controller = new AbortController();
|
|
142
|
+
const waiters = new Set<ProbeWaiter>();
|
|
143
|
+
const entry: InflightProbe = { controller, waiters };
|
|
144
|
+
inflight.set(key, entry);
|
|
145
|
+
|
|
146
|
+
void (async () => {
|
|
147
|
+
let project: string | undefined;
|
|
148
|
+
try {
|
|
149
|
+
project = await probe(apiKey, fetchImpl, controller.signal, timeoutMs);
|
|
150
|
+
} finally {
|
|
151
|
+
if (inflight.get(key) === entry) inflight.delete(key);
|
|
152
|
+
}
|
|
153
|
+
if (project && !controller.signal.aborted) remember(key, project);
|
|
154
|
+
for (const waiter of Array.from(waiters)) {
|
|
155
|
+
cleanupWaiter(waiter);
|
|
156
|
+
if (waiter.signal?.aborted) waiter.reject(waiter.signal.reason);
|
|
157
|
+
else waiter.resolve(project);
|
|
158
|
+
}
|
|
159
|
+
})();
|
|
160
|
+
|
|
161
|
+
return entry;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
/**
|
|
165
|
+
* Resolves the project number that owns `apiKey`, or undefined when Google does not reveal it.
|
|
166
|
+
* Successful lookups are cached per key; failures are not, so a transient error retries next time.
|
|
167
|
+
* Concurrent callers for the same uncached key share one probe; an aborted caller detaches
|
|
168
|
+
* immediately without cancelling the shared probe unless every waiter has aborted.
|
|
169
|
+
*/
|
|
170
|
+
export async function resolveVertexApiKeyProject(
|
|
171
|
+
apiKey: string,
|
|
172
|
+
options: VertexKeyProjectOptions | typeof fetch = {},
|
|
173
|
+
): Promise<string | undefined> {
|
|
174
|
+
const opts: VertexKeyProjectOptions = typeof options === "function" ? { fetch: options } : options;
|
|
175
|
+
const signal = opts.signal;
|
|
176
|
+
signal?.throwIfAborted();
|
|
177
|
+
|
|
178
|
+
const key = cacheKey(apiKey);
|
|
179
|
+
const cached = resolved.get(key);
|
|
180
|
+
if (cached) {
|
|
181
|
+
remember(key, cached);
|
|
182
|
+
return cached;
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Synchronous egress validation (for example an opaque custom fetch combined with an explicit
|
|
186
|
+
// provider.proxy) must reject the caller rather than being swallowed into an express fallback.
|
|
187
|
+
const fetchImpl = selectProbeFetch(opts);
|
|
188
|
+
const timeoutMs = opts.timeoutMs ?? PROBE_TIMEOUT_MS;
|
|
189
|
+
const entry = inflight.get(key) ?? startInflight(key, apiKey, fetchImpl, timeoutMs);
|
|
190
|
+
|
|
191
|
+
return new Promise<string | undefined>((resolve, reject) => {
|
|
192
|
+
if (signal?.aborted) {
|
|
193
|
+
if (entry.waiters.size === 0) {
|
|
194
|
+
if (inflight.get(key) === entry) inflight.delete(key);
|
|
195
|
+
entry.controller.abort(signal.reason);
|
|
196
|
+
}
|
|
197
|
+
reject(signal.reason);
|
|
198
|
+
return;
|
|
199
|
+
}
|
|
200
|
+
const waiter: ProbeWaiter = { signal, resolve, reject };
|
|
201
|
+
if (signal) {
|
|
202
|
+
const onAbort = () => {
|
|
203
|
+
signal.removeEventListener("abort", onAbort);
|
|
204
|
+
entry.waiters.delete(waiter);
|
|
205
|
+
reject(signal.reason);
|
|
206
|
+
if (entry.waiters.size === 0) {
|
|
207
|
+
if (inflight.get(key) === entry) inflight.delete(key);
|
|
208
|
+
entry.controller.abort(signal.reason);
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
waiter.onAbort = onAbort;
|
|
212
|
+
signal.addEventListener("abort", onAbort, { once: true });
|
|
213
|
+
}
|
|
214
|
+
entry.waiters.add(waiter);
|
|
215
|
+
});
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
/** Clears the resolved project cache and aborts any in-flight probes for tests. */
|
|
219
|
+
export function __resetVertexApiKeyProjectCache(): void {
|
|
220
|
+
resolved.clear();
|
|
221
|
+
for (const entry of inflight.values()) entry.controller.abort();
|
|
222
|
+
inflight.clear();
|
|
223
|
+
}
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { createHash } from "node:crypto";
|
|
2
1
|
import {
|
|
3
2
|
addGoogleToolSchemaLoss,
|
|
4
3
|
createGoogleToolSchemaLossReport,
|
|
@@ -59,7 +58,7 @@ function toolNameCodec(names: readonly string[]): {
|
|
|
59
58
|
const prefix = (cleaned || "tool").slice(0, 55);
|
|
60
59
|
for (let salt = 0; ; salt++) {
|
|
61
60
|
const hashInput = salt === 0 ? name : `${name}#${salt}`;
|
|
62
|
-
const suffix =
|
|
61
|
+
const suffix = Bun.SHA256.hash(hashInput, "hex").slice(0, 8);
|
|
63
62
|
const candidate = `${prefix}_${suffix}`;
|
|
64
63
|
if (used.has(candidate)) continue;
|
|
65
64
|
toWire.set(name, candidate);
|
package/src/adapters/google.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { openCodeZenGeminiEndpoint } from "../types/opencode-zen";
|
|
2
|
-
import type { AdapterFetchContext, AdapterRequest, ProviderAdapter } from "./base";
|
|
2
|
+
import type { AdapterFetchContext, AdapterRequest, IncomingMeta, ProviderAdapter } from "./base";
|
|
3
3
|
import { debugDroppedFrame, debugProviderDiagnosticLazy } from "../lib/debug";
|
|
4
4
|
import { createToolCallIdAllocator } from "./tool-call-id";
|
|
5
5
|
import { openCodeGoGeminiEndpoint } from "../types/opencode-go";
|
|
@@ -37,6 +37,7 @@ import {
|
|
|
37
37
|
} from "./google-antigravity-replay";
|
|
38
38
|
import { canonicalAntigravityUsageModel, resolveAntigravityEffortWireModel } from "../providers/antigravity-models";
|
|
39
39
|
import { selectVertexEndpoint, vertexInferenceUrl, vertexReplayModelKey } from "./google-vertex-endpoint";
|
|
40
|
+
import { resolveVertexApiKeyProject, VERTEX_PROJECT_AUTO } from "./google-vertex-key-project";
|
|
40
41
|
import { forgetThoughtSignatureForReplay, lookupReplayThoughtSignature } from "../responses/thought-signature-replay";
|
|
41
42
|
import {
|
|
42
43
|
isTranslatorBudgetExceededError,
|
|
@@ -992,7 +993,7 @@ export function createGoogleAdapter(provider: OcxProviderConfig): ProviderAdapte
|
|
|
992
993
|
: {}),
|
|
993
994
|
|
|
994
995
|
/** Compile an admitted request into the selected Gemini endpoint, body and authentication. */
|
|
995
|
-
async buildRequest(parsed: OcxParsedRequest) {
|
|
996
|
+
async buildRequest(parsed: OcxParsedRequest, incoming?: IncomingMeta) {
|
|
996
997
|
// Structured-output admission runs FIRST, before messagesToGeminiFormat writes
|
|
997
998
|
// lastInjectedCallIds/lastReasoningReplayScope: a refused request must not leave
|
|
998
999
|
// adapter-scoped replay state pointing at call ids that never went out. These
|
|
@@ -1225,7 +1226,16 @@ export function createGoogleAdapter(provider: OcxProviderConfig): ProviderAdapte
|
|
|
1225
1226
|
reportToolSchemaLoss(compiled.toolSchemaLossReport);
|
|
1226
1227
|
restoreGoogleToolName = compiled.restoreToolName;
|
|
1227
1228
|
const apiKey = resolveVertexApiKey(provider.apiKey);
|
|
1228
|
-
|
|
1229
|
+
let vertexEndpoint = selectVertexEndpoint(provider, Boolean(apiKey));
|
|
1230
|
+
if (apiKey && vertexEndpoint.kind === "project" && vertexEndpoint.project === VERTEX_PROJECT_AUTO) {
|
|
1231
|
+
// Unresolved keys use express for this request so Google's status drives key failover.
|
|
1232
|
+
const project = await resolveVertexApiKeyProject(apiKey, {
|
|
1233
|
+
signal: incoming?.abortSignal,
|
|
1234
|
+
provider,
|
|
1235
|
+
providerName: incoming?.providerName,
|
|
1236
|
+
});
|
|
1237
|
+
vertexEndpoint = project ? { ...vertexEndpoint, project } : { kind: "express" };
|
|
1238
|
+
}
|
|
1229
1239
|
const url = vertexInferenceUrl(vertexEndpoint, parsed.modelId, method, streamParam);
|
|
1230
1240
|
vertexReplayModel = vertexReplayModelKey(vertexEndpoint, parsed.modelId);
|
|
1231
1241
|
vertexReplaySession = vertexReplaySessionId(parsed);
|
|
@@ -28,6 +28,8 @@ export const KIRO_NATIVE_EFFORT_FIELDS: Record<string, "reasoning" | "output_con
|
|
|
28
28
|
"gpt-6-luna": "reasoning",
|
|
29
29
|
// 260930 preemptive (see kiro-models.ts): same native field as GPT-6 Sol.
|
|
30
30
|
"gpt-6.1-sol": "reasoning",
|
|
31
|
+
// 261027 preemptive: GPT-6.1 Terra (mirrors GPT-6.1 Sol; see kiro-models.ts).
|
|
32
|
+
"gpt-6.1-terra": "reasoning",
|
|
31
33
|
"claude-opus-5": "output_config",
|
|
32
34
|
// 260923 preemptive (see kiro-models.ts): same Claude-specific field as Opus 5.
|
|
33
35
|
"claude-opus-5.5": "output_config",
|
|
@@ -13,6 +13,10 @@ const SUSPENSION_WORDS = [
|
|
|
13
13
|
"locked your account", "locked it as a",
|
|
14
14
|
] as const;
|
|
15
15
|
|
|
16
|
+
/**
|
|
17
|
+
* Classify a Kiro HTTP error for account rotation and quota or suspension evidence.
|
|
18
|
+
* Reads bounded, top-level JSON fields; unrecognized 429 bodies retain rate recovery.
|
|
19
|
+
*/
|
|
16
20
|
export function classifyKiroRefusal(status: number, bodyText: string): KiroRefusal {
|
|
17
21
|
if (Buffer.byteLength(bodyText, "utf8") > BOUNDED_BODY_MAX_BYTES)
|
|
18
22
|
return { kind: status === 429 ? "rate" : "other" };
|
|
@@ -25,7 +29,8 @@ export function classifyKiroRefusal(status: number, bodyText: string): KiroRefus
|
|
|
25
29
|
message = (row as Record<string, unknown>).message;
|
|
26
30
|
}
|
|
27
31
|
} catch { /* Unrecognised bodies cannot establish an account verdict. */ }
|
|
28
|
-
if ((status === 400 || status === 429)
|
|
32
|
+
if ((status === 400 || status === 429)
|
|
33
|
+
&& (reason === "MONTHLY_REQUEST_COUNT" || reason === "OVERAGE_REQUEST_LIMIT_EXCEEDED"))
|
|
29
34
|
return { kind: "monthly_quota" };
|
|
30
35
|
// A 400 whose own validator calls the body improperly formed is not proof that the request is
|
|
31
36
|
// impossible: Kiro answers this shape when the identity a request was routed under cannot serve
|
|
@@ -62,7 +62,7 @@ export function kiroToolName(wireName: string, used?: Set<string>): string {
|
|
|
62
62
|
const base = cleaned.slice(0, 55) || "tool";
|
|
63
63
|
for (let salt = 0; ; salt++) {
|
|
64
64
|
const hashInput = salt === 0 ? wireName : `${wireName}#${salt}`;
|
|
65
|
-
const suffix =
|
|
65
|
+
const suffix = Bun.SHA256.hash(hashInput, "hex").slice(0, 8);
|
|
66
66
|
const candidate = `${base}_${suffix}`;
|
|
67
67
|
if (!(used?.has(candidate))) {
|
|
68
68
|
used?.add(candidate);
|
|
@@ -7,7 +7,7 @@ import { EMPTY_TOOL_OUTPUT_ANNOTATION, isWhitespaceOnlyTextPartArray } from "../
|
|
|
7
7
|
import { identifyRoutedModel } from "../identity";
|
|
8
8
|
import { buildNonOpenAIToolCatalogNudgeForTools, shouldInjectNonOpenAIToolCatalogNudge } from "../tool-catalog-nudge";
|
|
9
9
|
import { peekReasoningForCall } from "../../responses/reasoning-replay-cache";
|
|
10
|
-
import { chatReasoningReplayPolicy } from "./reasoning-replay";
|
|
10
|
+
import { chatReasoningReplayPolicy, isReflectionThinkingModel } from "./reasoning-replay";
|
|
11
11
|
import type { ClaudeThinkingProjection } from "../../lib/claude-request-projection";
|
|
12
12
|
import { inlineDocumentDataUrl } from "../../responses/inline-document";
|
|
13
13
|
import type { OcxAssistantMessage, OcxContentPart, OcxParsedRequest, OcxProviderConfig, OcxTextContent, OcxThinkingContent, OcxToolCall } from "../../types";
|
|
@@ -282,9 +282,15 @@ export function messagesToChatFormat(parsed: OcxParsedRequest, provider: OcxProv
|
|
|
282
282
|
const chatMsg: Record<string, unknown> = { role: "assistant" };
|
|
283
283
|
if (textParts.length > 0) chatMsg.content = textParts.map(p => p.text).join("");
|
|
284
284
|
let reasoningContent = thinkingParts.map(p => p.thinking).join("");
|
|
285
|
+
// Reflection/Stealth replay a placeholder even on a tool-less turn, but never on an
|
|
286
|
+
// empty turn inside an unfinished tool batch: that turn is dropped below, and a
|
|
287
|
+
// fabricated reasoning block there would split the call from its real result.
|
|
288
|
+
const reflectionPlaceholder = isReflectionThinkingModel(parsed.modelId)
|
|
289
|
+
&& chatReasoningReplayPolicy(provider, parsed.modelId).placeholder
|
|
290
|
+
&& !(pendingToolCalls.length > 0 && !chatMsg.content && toolCalls.length === 0 && thinkingParts.length === 0);
|
|
285
291
|
if (
|
|
286
292
|
reasoningContent.length === 0
|
|
287
|
-
&& (toolCalls.length > 0 || thinkingParts.length > 0)
|
|
293
|
+
&& (toolCalls.length > 0 || thinkingParts.length > 0 || reflectionPlaceholder)
|
|
288
294
|
&& wireSerializesThinking
|
|
289
295
|
) {
|
|
290
296
|
const cached = toolCalls
|