@cortexkit/opencode-antigravity-auth 3.0.5 → 3.0.7
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 +38 -352
- package/dist/cli.js +13757 -12857
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +1362 -1056
- package/dist/index.js +16038 -16162
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +1447 -1375
- package/dist/server.js +11254 -10921
- package/dist/server.js.map +4 -4
- package/dist/server.meta.json +1 -1
- package/dist/src/auth-method-labels.d.ts +3 -0
- package/dist/src/auth-method-labels.d.ts.map +1 -0
- package/dist/src/auth-method-labels.js +5 -0
- package/dist/src/auth-method-labels.js.map +1 -0
- package/dist/src/cli.d.ts +3 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +98 -12
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +44 -4
- package/dist/src/common-auth-embedded/claustrum/consumer.js +134 -2
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +33 -1
- package/dist/src/common-auth-embedded/claustrum/custody.js +17 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +6 -1
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +6 -1
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +3 -2
- package/dist/src/common-auth-embedded/claustrum/index.js +5 -3
- package/dist/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
- package/dist/src/common-auth-embedded/claustrum/insula.js +152 -0
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +13 -0
- package/dist/src/common-auth-embedded/claustrum/roster.js +33 -3
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +26 -12
- package/dist/src/common-auth-embedded/pi-slot/lock.js +7 -3
- package/dist/src/common-auth-embedded/quota/codec.d.ts +2 -0
- package/dist/src/common-auth-embedded/quota/codec.js +2 -1
- package/dist/src/common-auth-embedded/quota/format.d.ts +40 -3
- package/dist/src/common-auth-embedded/quota/format.js +196 -43
- package/dist/src/common-auth-embedded/quota/index.d.ts +4 -4
- package/dist/src/common-auth-embedded/quota/index.js +2 -2
- package/dist/src/common-auth-embedded/quota/map.d.ts +11 -0
- package/dist/src/common-auth-embedded/quota/map.js +36 -1
- package/dist/src/common-auth-embedded/quota/merge.d.ts +3 -1
- package/dist/src/common-auth-embedded/quota/merge.js +21 -5
- package/dist/src/common-auth-embedded/quota/projection.d.ts +2 -1
- package/dist/src/common-auth-embedded/quota/projection.js +3 -1
- package/dist/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/dist/src/common-auth-embedded/setup/command-error.js +79 -0
- package/dist/src/common-auth-embedded/setup/command-runner.js +143 -0
- package/dist/src/common-auth-embedded/setup/command.d.ts +3 -0
- package/dist/src/common-auth-embedded/setup/command.js +271 -0
- package/dist/src/common-auth-embedded/setup/config-write.js +60 -0
- package/dist/src/common-auth-embedded/setup/detect.d.ts +6 -0
- package/dist/src/common-auth-embedded/setup/detect.js +224 -0
- package/dist/src/common-auth-embedded/setup/enroll.js +82 -0
- package/dist/src/common-auth-embedded/setup/index.d.ts +6 -0
- package/dist/src/common-auth-embedded/setup/index.js +5 -0
- package/dist/src/common-auth-embedded/setup/paths.js +33 -0
- package/dist/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
- package/dist/src/common-auth-embedded/setup/process-fence.js +270 -0
- package/dist/src/common-auth-embedded/setup/prompts.js +26 -0
- package/dist/src/common-auth-embedded/setup/register.d.ts +11 -0
- package/dist/src/common-auth-embedded/setup/register.js +136 -0
- package/dist/src/common-auth-embedded/setup/types.d.ts +150 -0
- package/dist/src/common-auth-embedded/source-output.json +265 -101
- package/dist/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/dist/src/common-auth-embedded/store/pool.js +0 -1
- package/dist/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/dist/src/common-auth-embedded/store/refresh-lock.js +0 -1
- package/dist/src/common-auth-embedded/store/schema.d.ts +2 -0
- package/dist/src/common-auth-embedded/store/schema.js +3 -2
- package/dist/src/ga/rpc/protocol.d.ts +4 -7
- package/dist/src/ga/rpc/protocol.d.ts.map +1 -1
- package/dist/src/ga/rpc/protocol.js +5 -13
- package/dist/src/ga/rpc/protocol.js.map +1 -1
- package/dist/src/ga/server/auth.d.ts +8 -3
- package/dist/src/ga/server/auth.d.ts.map +1 -1
- package/dist/src/ga/server/auth.js +25 -9
- package/dist/src/ga/server/auth.js.map +1 -1
- package/dist/src/ga/server/index.d.ts +39 -12
- package/dist/src/ga/server/index.d.ts.map +1 -1
- package/dist/src/ga/server/index.js +218 -55
- package/dist/src/ga/server/index.js.map +1 -1
- package/dist/src/ga/server/pool-login.d.ts +22 -0
- package/dist/src/ga/server/pool-login.d.ts.map +1 -0
- package/dist/src/ga/server/pool-login.js +150 -0
- package/dist/src/ga/server/pool-login.js.map +1 -0
- package/dist/src/ga/tui/host-ga.d.ts +2 -5
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -1
- package/dist/src/ga/tui/host-ga.js +54 -52
- package/dist/src/ga/tui/host-ga.js.map +1 -1
- package/dist/src/plugin/accounts.d.ts +1 -1
- package/dist/src/plugin/accounts.d.ts.map +1 -1
- package/dist/src/plugin/accounts.js +1 -0
- package/dist/src/plugin/accounts.js.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.d.ts +2 -0
- package/dist/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-vault-quota-refresh.js +125 -10
- package/dist/src/plugin/background-vault-quota-refresh.js.map +1 -1
- package/dist/src/plugin/command-apply.d.ts +2 -2
- package/dist/src/plugin/command-apply.d.ts.map +1 -1
- package/dist/src/plugin/command-apply.js +3 -10
- package/dist/src/plugin/command-apply.js.map +1 -1
- package/dist/src/plugin/commands.d.ts +1 -0
- package/dist/src/plugin/commands.d.ts.map +1 -1
- package/dist/src/plugin/commands.js +2 -2
- package/dist/src/plugin/commands.js.map +1 -1
- package/dist/src/plugin/config/operator-settings-schema.d.ts +0 -4
- package/dist/src/plugin/config/operator-settings-schema.d.ts.map +1 -1
- package/dist/src/plugin/config/operator-settings-schema.js +0 -5
- package/dist/src/plugin/config/operator-settings-schema.js.map +1 -1
- package/dist/src/plugin/config/schema.d.ts +0 -7
- package/dist/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/src/plugin/config/schema.js +2 -44
- package/dist/src/plugin/config/schema.js.map +1 -1
- package/dist/src/plugin/config/writer.d.ts +1 -1
- package/dist/src/plugin/config/writer.js +1 -1
- package/dist/src/plugin/fetch/retry-state.d.ts +19 -3
- package/dist/src/plugin/fetch/retry-state.d.ts.map +1 -1
- package/dist/src/plugin/fetch/retry-state.js +0 -6
- package/dist/src/plugin/fetch/retry-state.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +0 -3
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/fetch-routing.d.ts +0 -16
- package/dist/src/plugin/fetch-routing.d.ts.map +1 -1
- package/dist/src/plugin/fetch-routing.js +0 -49
- package/dist/src/plugin/fetch-routing.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts +14 -9
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/src/plugin/ga-location-services.js +124 -43
- package/dist/src/plugin/ga-location-services.js.map +1 -1
- package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
- package/dist/src/plugin/gemini-dump.js +2 -5
- package/dist/src/plugin/gemini-dump.js.map +1 -1
- package/dist/src/plugin/google-origin.d.ts +7 -0
- package/dist/src/plugin/google-origin.d.ts.map +1 -0
- package/dist/src/plugin/google-origin.js +14 -0
- package/dist/src/plugin/google-origin.js.map +1 -0
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +18 -7
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/logging-utils.d.ts.map +1 -1
- package/dist/src/plugin/logging-utils.js +2 -5
- package/dist/src/plugin/logging-utils.js.map +1 -1
- package/dist/src/plugin/oauth-methods.d.ts.map +1 -1
- package/dist/src/plugin/oauth-methods.js +0 -33
- package/dist/src/plugin/oauth-methods.js.map +1 -1
- package/dist/src/plugin/operator-settings.d.ts +1 -1
- package/dist/src/plugin/operator-settings.d.ts.map +1 -1
- package/dist/src/plugin/operator-settings.js +1 -8
- package/dist/src/plugin/operator-settings.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +11 -7
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +128 -102
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/request.d.ts +6 -5
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +95 -180
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/server.d.ts.map +1 -1
- package/dist/src/plugin/server.js +60 -53
- package/dist/src/plugin/server.js.map +1 -1
- package/dist/src/plugin/shared/advisory-repository.d.ts +20 -0
- package/dist/src/plugin/shared/advisory-repository.d.ts.map +1 -0
- package/dist/src/plugin/shared/advisory-repository.js +91 -0
- package/dist/src/plugin/shared/advisory-repository.js.map +1 -0
- package/dist/src/plugin/shared/request-services.d.ts +27 -26
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/src/plugin/shared/request-services.js +244 -245
- package/dist/src/plugin/shared/request-services.js.map +1 -1
- package/dist/src/plugin/shared/runtime.js +4 -2
- package/dist/src/plugin/shared/runtime.js.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +16 -4
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/src/plugin/shared/vault-request-credentials.js +44 -7
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -1
- package/dist/src/plugin/storage.d.ts +2 -2
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/vault-custody.d.ts +14 -1
- package/dist/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/src/plugin/vault-custody.js +203 -44
- package/dist/src/plugin/vault-custody.js.map +1 -1
- package/dist/src/plugin/vault-quota-outcome.d.ts +19 -0
- package/dist/src/plugin/vault-quota-outcome.d.ts.map +1 -0
- package/dist/src/plugin/vault-quota-outcome.js +47 -0
- package/dist/src/plugin/vault-quota-outcome.js.map +1 -0
- package/dist/src/quota-presentation.d.ts +29 -1
- package/dist/src/quota-presentation.d.ts.map +1 -1
- package/dist/src/quota-presentation.js +52 -17
- package/dist/src/quota-presentation.js.map +1 -1
- package/dist/src/setup.d.ts +15 -0
- package/dist/src/setup.d.ts.map +1 -0
- package/dist/src/setup.js +320 -0
- package/dist/src/setup.js.map +1 -0
- package/dist/src/sidebar-projection.d.ts +5 -1
- package/dist/src/sidebar-projection.d.ts.map +1 -1
- package/dist/src/sidebar-projection.js +6 -2
- package/dist/src/sidebar-projection.js.map +1 -1
- package/dist/src/sidebar-state.d.ts +1 -1
- package/dist/src/sidebar-state.d.ts.map +1 -1
- package/dist/src/sidebar-state.js +19 -1
- package/dist/src/sidebar-state.js.map +1 -1
- package/dist/src/tui/quota-layout.d.ts +94 -0
- package/dist/src/tui/quota-layout.d.ts.map +1 -0
- package/dist/src/tui/quota-layout.js +139 -0
- package/dist/src/tui/quota-layout.js.map +1 -0
- package/dist/src/tui/route-layout.d.ts +8 -0
- package/dist/src/tui/route-layout.d.ts.map +1 -0
- package/dist/src/tui/route-layout.js +36 -0
- package/dist/src/tui/route-layout.js.map +1 -0
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +120 -127
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +66 -37
- package/dist/tui-ga-build-map.json +66 -37
- package/dist/types/src/auth-method-labels.d.ts +3 -0
- package/dist/types/src/auth-method-labels.d.ts.map +1 -0
- package/dist/types/src/cli.d.ts +3 -1
- package/dist/types/src/cli.d.ts.map +1 -1
- package/dist/types/src/common-auth-embedded/auth-menu/terminal.d.ts +43 -0
- package/dist/types/src/common-auth-embedded/claustrum/consumer.d.ts +142 -0
- package/dist/types/src/common-auth-embedded/claustrum/custody.d.ts +207 -0
- package/dist/types/src/common-auth-embedded/claustrum/enrollment.d.ts +164 -0
- package/dist/types/src/common-auth-embedded/claustrum/errors.d.ts +16 -0
- package/dist/types/src/common-auth-embedded/claustrum/host-slot.d.ts +39 -0
- package/dist/types/src/common-auth-embedded/claustrum/index.d.ts +19 -0
- package/dist/types/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
- package/dist/types/src/common-auth-embedded/claustrum/interlock.d.ts +27 -0
- package/dist/types/src/common-auth-embedded/claustrum/roster.d.ts +221 -0
- package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/dist/types/src/common-auth-embedded/opencode2/errors.d.ts +25 -0
- package/dist/types/src/common-auth-embedded/opencode2/index.d.ts +8 -0
- package/dist/types/src/common-auth-embedded/opencode2/install.d.ts +55 -0
- package/dist/types/src/common-auth-embedded/opencode2/integration.d.ts +112 -0
- package/dist/types/src/common-auth-embedded/opencode2/sse.d.ts +12 -0
- package/dist/types/src/common-auth-embedded/opencode2/types.d.ts +413 -0
- package/dist/types/src/common-auth-embedded/quota/codec.d.ts +2 -0
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +40 -3
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +4 -4
- package/dist/types/src/common-auth-embedded/quota/map.d.ts +11 -0
- package/dist/types/src/common-auth-embedded/quota/merge.d.ts +3 -1
- package/dist/types/src/common-auth-embedded/quota/projection.d.ts +2 -1
- package/dist/types/src/common-auth-embedded/routing/admission.d.ts +93 -0
- package/dist/types/src/common-auth-embedded/routing/index.d.ts +8 -0
- package/dist/types/src/common-auth-embedded/routing/ordered.d.ts +47 -0
- package/dist/types/src/common-auth-embedded/routing/pins.d.ts +22 -0
- package/dist/types/src/common-auth-embedded/routing/sticky.d.ts +158 -0
- package/dist/types/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/dist/types/src/common-auth-embedded/setup/command.d.ts +3 -0
- package/dist/types/src/common-auth-embedded/setup/detect.d.ts +6 -0
- package/dist/types/src/common-auth-embedded/setup/index.d.ts +6 -0
- package/dist/types/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
- package/dist/types/src/common-auth-embedded/setup/register.d.ts +11 -0
- package/dist/types/src/common-auth-embedded/setup/types.d.ts +150 -0
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/dist/types/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/dist/types/src/common-auth-embedded/store/schema.d.ts +2 -0
- package/dist/types/src/ga/rpc/protocol.d.ts +4 -7
- package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -1
- package/dist/types/src/ga/server/auth.d.ts +8 -3
- package/dist/types/src/ga/server/auth.d.ts.map +1 -1
- package/dist/types/src/ga/server/index.d.ts +39 -12
- package/dist/types/src/ga/server/index.d.ts.map +1 -1
- package/dist/types/src/ga/server/pool-login.d.ts +22 -0
- package/dist/types/src/ga/server/pool-login.d.ts.map +1 -0
- package/dist/types/src/plugin/accounts.d.ts +1 -1
- package/dist/types/src/plugin/accounts.d.ts.map +1 -1
- package/dist/types/src/plugin/background-vault-quota-refresh.d.ts +2 -0
- package/dist/types/src/plugin/background-vault-quota-refresh.d.ts.map +1 -1
- package/dist/types/src/plugin/command-apply.d.ts +2 -2
- package/dist/types/src/plugin/command-apply.d.ts.map +1 -1
- package/dist/types/src/plugin/commands.d.ts +1 -0
- package/dist/types/src/plugin/commands.d.ts.map +1 -1
- package/dist/types/src/plugin/config/operator-settings-schema.d.ts +0 -4
- package/dist/types/src/plugin/config/operator-settings-schema.d.ts.map +1 -1
- package/dist/types/src/plugin/config/schema.d.ts +0 -7
- package/dist/types/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/types/src/plugin/config/writer.d.ts +1 -1
- package/dist/types/src/plugin/fetch/retry-state.d.ts +19 -3
- package/dist/types/src/plugin/fetch/retry-state.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/types/src/plugin/fetch-routing.d.ts +0 -16
- package/dist/types/src/plugin/fetch-routing.d.ts.map +1 -1
- package/dist/types/src/plugin/ga-location-services.d.ts +14 -9
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -1
- package/dist/types/src/plugin/gemini-dump.d.ts.map +1 -1
- package/dist/types/src/plugin/google-origin.d.ts +7 -0
- package/dist/types/src/plugin/google-origin.d.ts.map +1 -0
- package/dist/types/src/plugin/index.d.ts.map +1 -1
- package/dist/types/src/plugin/logging-utils.d.ts.map +1 -1
- package/dist/types/src/plugin/oauth-methods.d.ts.map +1 -1
- package/dist/types/src/plugin/operator-settings.d.ts +1 -1
- package/dist/types/src/plugin/operator-settings.d.ts.map +1 -1
- package/dist/types/src/plugin/quota.d.ts +11 -7
- package/dist/types/src/plugin/quota.d.ts.map +1 -1
- package/dist/types/src/plugin/request.d.ts +6 -5
- package/dist/types/src/plugin/request.d.ts.map +1 -1
- package/dist/types/src/plugin/server.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/advisory-repository.d.ts +20 -0
- package/dist/types/src/plugin/shared/advisory-repository.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +27 -26
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -1
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +16 -4
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -1
- package/dist/types/src/plugin/storage.d.ts +2 -2
- package/dist/types/src/plugin/storage.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-custody.d.ts +14 -1
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -1
- package/dist/types/src/plugin/vault-quota-outcome.d.ts +19 -0
- package/dist/types/src/plugin/vault-quota-outcome.d.ts.map +1 -0
- package/dist/types/src/setup.d.ts +15 -0
- package/dist/types/src/setup.d.ts.map +1 -0
- package/dist/types/src/sidebar-state.d.ts +1 -1
- package/dist/types/src/sidebar-state.d.ts.map +1 -1
- package/package.json +5 -4
- package/src/common-auth-embedded/claustrum/consumer.d.ts +44 -4
- package/src/common-auth-embedded/claustrum/consumer.js +134 -2
- package/src/common-auth-embedded/claustrum/custody.d.ts +33 -1
- package/src/common-auth-embedded/claustrum/custody.js +17 -0
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +6 -1
- package/src/common-auth-embedded/claustrum/enrollment.js +6 -1
- package/src/common-auth-embedded/claustrum/index.d.ts +3 -2
- package/src/common-auth-embedded/claustrum/index.js +5 -3
- package/src/common-auth-embedded/claustrum/insula.d.ts +69 -0
- package/src/common-auth-embedded/claustrum/insula.js +152 -0
- package/src/common-auth-embedded/claustrum/roster.d.ts +13 -0
- package/src/common-auth-embedded/claustrum/roster.js +33 -3
- package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +8 -2
- package/src/common-auth-embedded/fs/refresh-file-lock.js +26 -12
- package/src/common-auth-embedded/pi-slot/lock.js +7 -3
- package/src/common-auth-embedded/quota/codec.d.ts +2 -0
- package/src/common-auth-embedded/quota/codec.js +2 -1
- package/src/common-auth-embedded/quota/format.d.ts +40 -3
- package/src/common-auth-embedded/quota/format.js +196 -43
- package/src/common-auth-embedded/quota/index.d.ts +4 -4
- package/src/common-auth-embedded/quota/index.js +2 -2
- package/src/common-auth-embedded/quota/map.d.ts +11 -0
- package/src/common-auth-embedded/quota/map.js +36 -1
- package/src/common-auth-embedded/quota/merge.d.ts +3 -1
- package/src/common-auth-embedded/quota/merge.js +21 -5
- package/src/common-auth-embedded/quota/projection.d.ts +2 -1
- package/src/common-auth-embedded/quota/projection.js +3 -1
- package/src/common-auth-embedded/setup/command-error.d.ts +32 -0
- package/src/common-auth-embedded/setup/command-error.js +79 -0
- package/src/common-auth-embedded/setup/command-runner.js +143 -0
- package/src/common-auth-embedded/setup/command.d.ts +3 -0
- package/src/common-auth-embedded/setup/command.js +271 -0
- package/src/common-auth-embedded/setup/config-write.js +60 -0
- package/src/common-auth-embedded/setup/detect.d.ts +6 -0
- package/src/common-auth-embedded/setup/detect.js +224 -0
- package/src/common-auth-embedded/setup/enroll.js +82 -0
- package/src/common-auth-embedded/setup/index.d.ts +6 -0
- package/src/common-auth-embedded/setup/index.js +5 -0
- package/src/common-auth-embedded/setup/paths.js +33 -0
- package/src/common-auth-embedded/setup/process-fence.d.ts +43 -0
- package/src/common-auth-embedded/setup/process-fence.js +270 -0
- package/src/common-auth-embedded/setup/prompts.js +26 -0
- package/src/common-auth-embedded/setup/register.d.ts +11 -0
- package/src/common-auth-embedded/setup/register.js +136 -0
- package/src/common-auth-embedded/setup/types.d.ts +150 -0
- package/src/common-auth-embedded/source-output.json +265 -101
- package/src/common-auth-embedded/store/pool.d.ts +1 -1
- package/src/common-auth-embedded/store/pool.js +0 -1
- package/src/common-auth-embedded/store/refresh-lock.d.ts +0 -1
- package/src/common-auth-embedded/store/refresh-lock.js +0 -1
- package/src/common-auth-embedded/store/schema.d.ts +2 -0
- package/src/common-auth-embedded/store/schema.js +3 -2
- package/src/sidebar-state.ts +19 -2
- package/src/tui-compiled/common-auth-embedded/quota/codec.js +2 -1
- package/src/tui-compiled/common-auth-embedded/quota/format.js +196 -43
- package/src/tui-compiled/common-auth-embedded/quota/index.js +2 -2
- package/src/tui-compiled/common-auth-embedded/quota/map.js +36 -1
- package/src/tui-compiled/common-auth-embedded/quota/merge.js +21 -5
- package/src/tui-compiled/common-auth-embedded/quota/projection.js +3 -1
- package/src/tui-compiled/quota-presentation.js +42 -9
- package/src/tui-compiled/sidebar-state.js +15 -1
- package/src/tui-compiled/tui/quota-layout.js +378 -0
- package/src/tui-compiled/tui/route-layout.js +30 -0
- package/src/tui-compiled/tui.js +271 -371
- package/src/tui-ga-compiled/host-ga.js +93 -90
- package/src/tui-ga-compiled/shared/1ff34afa7c42d196-projection.js +3 -1
- package/src/tui-ga-compiled/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
- package/src/tui-ga-compiled/shared/77138df80c7ae006-map.js +36 -1
- package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
- package/src/tui-ga-compiled/shared/98cc0c186c46c42d-quota-presentation.js +42 -9
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +196 -43
- package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +2 -2
- package/src/tui-ga-compiled/shared/ca21dc417b36dc5d-codec.js +2 -1
- package/src/tui-ga-compiled/shared/dd4c9e1a907f8ef0-quota-layout.js +378 -0
- package/src/tui-ga-compiled/shared/ecc214300932dfb6-merge.js +21 -5
- package/src/tui-ga-raw/host-ga.tsx +102 -92
- package/src/tui-ga-raw/shared/1ff34afa7c42d196-projection.js +3 -1
- package/src/tui-ga-raw/shared/6ca47cd4ec33fe72-route-layout.js +30 -0
- package/src/tui-ga-raw/shared/77138df80c7ae006-map.js +36 -1
- package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +2 -2
- package/src/tui-ga-raw/shared/98cc0c186c46c42d-quota-presentation.js +42 -9
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +196 -43
- package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +2 -2
- package/src/tui-ga-raw/shared/ca21dc417b36dc5d-codec.js +2 -1
- package/src/tui-ga-raw/shared/dd4c9e1a907f8ef0-quota-layout.tsx +391 -0
- package/src/tui-ga-raw/shared/ecc214300932dfb6-merge.js +21 -5
- package/src/tui-raw/common-auth-embedded/quota/codec.js +2 -1
- package/src/tui-raw/common-auth-embedded/quota/format.js +196 -43
- package/src/tui-raw/common-auth-embedded/quota/index.js +2 -2
- package/src/tui-raw/common-auth-embedded/quota/map.js +36 -1
- package/src/tui-raw/common-auth-embedded/quota/merge.js +21 -5
- package/src/tui-raw/common-auth-embedded/quota/projection.js +3 -1
- package/src/tui-raw/quota-presentation.js +42 -9
- package/src/tui-raw/sidebar-state.js +15 -1
- package/src/tui-raw/tui/quota-layout.tsx +391 -0
- package/src/tui-raw/tui/route-layout.js +30 -0
- package/src/tui-raw/tui.tsx +218 -272
- package/src/tui.tsx +218 -272
- package/dist/src/tui/vault-setup.d.ts +0 -98
- package/dist/src/tui/vault-setup.d.ts.map +0 -1
- package/dist/src/tui/vault-setup.js +0 -198
- package/dist/src/tui/vault-setup.js.map +0 -1
- package/dist/types/src/plugin/transform/model-resolver.d.ts +0 -2
- package/dist/types/src/plugin/transform/model-resolver.d.ts.map +0 -1
- package/dist/types/src/quota-presentation.d.ts +0 -18
- package/dist/types/src/quota-presentation.d.ts.map +0 -1
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Shared Antigravity request engine: account selection, retries, endpoint
|
|
3
|
-
*
|
|
3
|
+
* fallback, warmups and response handling for one plugin location.
|
|
4
4
|
*
|
|
5
5
|
* OpenCode 1's `createFetchInterceptor` and the GA location services both
|
|
6
6
|
* call `createRequestExecutor`, so there is exactly one retry loop. Every
|
|
@@ -16,12 +16,12 @@
|
|
|
16
16
|
* `RequestWire`, which `createRequestWire` binds to one location's signature
|
|
17
17
|
* cache, debug log and logger; the raw sender is called unchanged.
|
|
18
18
|
*/
|
|
19
|
-
import { accessTokenExpired, calculateBackoffMs, computeSoftQuotaCacheTtlMs, getPublicModelDefinitions, getResolverAliasMap, isClaudeThinkingModel, isImageGenerationModel, isRetiredAgyModel, parseRateLimitReason, preserveResponseMetadata, RETIRED_AGY_MODEL_MESSAGE, redactCredentialError, redactCredentialResponse, redactCredentialText, resolveQuotaGroup, VAULT_ACCOUNT_REMEDY, } from '@cortexkit/antigravity-auth-core';
|
|
20
|
-
import { ANTIGRAVITY_ENDPOINT_FALLBACKS
|
|
19
|
+
import { accessTokenExpired, calculateBackoffMs, computeSoftQuotaCacheTtlMs, getPublicModelDefinitions, getQuotaKey, getResolverAliasMap, isClaudeThinkingModel, isImageGenerationModel, isRetiredAgyModel, PRE_RESPONSE_DEADLINE_MS, PreResponseDeadline, PreResponseTimeoutError, parseRateLimitReason, parseRefreshParts, preResponseTimeoutResponse, preserveResponseMetadata, RETIRED_AGY_MODEL_MESSAGE, redactCredentialError, redactCredentialResponse, redactCredentialText, resolveQuotaGroup, VAULT_ACCOUNT_REMEDY, } from '@cortexkit/antigravity-auth-core';
|
|
20
|
+
import { ANTIGRAVITY_ENDPOINT_FALLBACKS } from '../../constants';
|
|
21
21
|
import { AntigravityKillswitchError } from '../errors';
|
|
22
22
|
import { createRetryState, } from '../fetch/retry-state';
|
|
23
23
|
import { createWarmupState } from '../fetch/warmup';
|
|
24
|
-
import { extractModelFromUrl, getModelFamilyFromUrl, isCapacityRetryBudgetExhausted, MAX_TOTAL_CAPACITY_RETRIES,
|
|
24
|
+
import { extractModelFromUrl, getModelFamilyFromUrl, isCapacityRetryBudgetExhausted, MAX_TOTAL_CAPACITY_RETRIES, toUrlString, toWarmupStreamUrl, } from '../fetch-routing';
|
|
25
25
|
import { noteGeminiDumpResponse } from '../gemini-dump';
|
|
26
26
|
import { evaluateKillswitchForAccount, throwIfAllKilled } from '../killswitch';
|
|
27
27
|
import { createNativeGoogleErrorResponse, createSyntheticTextResponse, isEmptyResponseBody, } from '../request-helpers';
|
|
@@ -39,7 +39,7 @@ const FIRST_RETRY_DELAY_MS = 1000;
|
|
|
39
39
|
* `RequestWire.prepare`'s.
|
|
40
40
|
*/
|
|
41
41
|
export function prepareAgyWireRequest(wire, request) {
|
|
42
|
-
return wire.prepare(request.input, request.init, request.accessToken, request.projectId, request.endpoint, request.
|
|
42
|
+
return wire.prepare(request.input, request.init, request.accessToken, request.projectId, request.endpoint, request.forceThinkingRecovery ?? false, request.options);
|
|
43
43
|
}
|
|
44
44
|
/**
|
|
45
45
|
* The model a title request is sent to when the host selected one this
|
|
@@ -61,6 +61,22 @@ export function routeTitleModel(url) {
|
|
|
61
61
|
return url;
|
|
62
62
|
return url.replace(`/models/${model}`, `/models/${TITLE_FALLBACK_MODEL}`);
|
|
63
63
|
}
|
|
64
|
+
/**
|
|
65
|
+
* Return the retired-model error using only the model registry: callers need
|
|
66
|
+
* neither an initialized account store nor an available vault to reject it.
|
|
67
|
+
*/
|
|
68
|
+
export function retiredModelResponse(url) {
|
|
69
|
+
const model = extractModelFromUrl(url);
|
|
70
|
+
if (!model || !isRetiredAgyModel(model))
|
|
71
|
+
return undefined;
|
|
72
|
+
return new Response(JSON.stringify({
|
|
73
|
+
error: {
|
|
74
|
+
code: 412,
|
|
75
|
+
status: 'FAILED_PRECONDITION',
|
|
76
|
+
message: RETIRED_AGY_MODEL_MESSAGE,
|
|
77
|
+
},
|
|
78
|
+
}), { status: 412, headers: { 'Content-Type': 'application/json' } });
|
|
79
|
+
}
|
|
64
80
|
/**
|
|
65
81
|
* The AGY metadata key for a request: the host session for primary (and
|
|
66
82
|
* kind-less) requests, a separate per-kind key for every other kind.
|
|
@@ -174,7 +190,7 @@ function sleep(ms, signal) {
|
|
|
174
190
|
* dropped.
|
|
175
191
|
*/
|
|
176
192
|
export function createLocalQuotaRefresh(accountManager, quotaManager, log) {
|
|
177
|
-
return async function refreshQuotaAfterSuccess(account, intervalMinutes) {
|
|
193
|
+
return async function refreshQuotaAfterSuccess(account, intervalMinutes, signal) {
|
|
178
194
|
if (intervalMinutes <= 0)
|
|
179
195
|
return;
|
|
180
196
|
const accountIndex = accountManager.getAccounts().indexOf(account);
|
|
@@ -197,7 +213,11 @@ export function createLocalQuotaRefresh(accountManager, quotaManager, log) {
|
|
|
197
213
|
const expectedRefreshToken = singleAccount.refreshToken;
|
|
198
214
|
const result = await quotaManager.refreshAccount(singleAccount, {
|
|
199
215
|
index: accountIndex,
|
|
216
|
+
purpose: 'advisory',
|
|
217
|
+
...(signal ? { signal } : {}),
|
|
200
218
|
});
|
|
219
|
+
if (signal?.aborted)
|
|
220
|
+
return;
|
|
201
221
|
if (result.status === 'ok' && result.quota?.groups) {
|
|
202
222
|
// Re-resolve the selected row itself. If it was removed meanwhile,
|
|
203
223
|
// drop the reading rather than writing onto whichever row shifted
|
|
@@ -219,11 +239,13 @@ export function createLocalQuotaRefresh(accountManager, quotaManager, log) {
|
|
|
219
239
|
* warmup bookkeeping, so disposing it releases every counter.
|
|
220
240
|
*/
|
|
221
241
|
export function createRequestExecutor(deps) {
|
|
222
|
-
const { config, accounts: accountManager, credentials, sessions: agySessionRegistry, operatorSettings, transport: defaultTransport,
|
|
242
|
+
const { config, accounts: accountManager, credentials, sessions: agySessionRegistry, operatorSettings, transport: defaultTransport, wire, debug, dump, logger: log, trackers, classifyAccessError, notify, onRouting, } = deps;
|
|
223
243
|
const retryState = createRetryState();
|
|
224
244
|
const warmupState = createWarmupState();
|
|
225
245
|
const shutdown = new AbortController();
|
|
226
246
|
const inFlight = new Set();
|
|
247
|
+
const advisoryWork = new Set();
|
|
248
|
+
let advisoryClosing = false;
|
|
227
249
|
const bufferedOverflow = new WeakMap();
|
|
228
250
|
let retired = false;
|
|
229
251
|
let drainPromise;
|
|
@@ -248,12 +270,11 @@ export function createRequestExecutor(deps) {
|
|
|
248
270
|
log.debug('routing-report-failed', { sessionId, error: String(error) });
|
|
249
271
|
}
|
|
250
272
|
};
|
|
251
|
-
async function execute(input, init, options
|
|
273
|
+
async function execute(input, init, options, selectedCredentials, selectedProjectIds, deadline, waitPolicy) {
|
|
252
274
|
const assertAdmission = async () => {
|
|
253
|
-
|
|
254
|
-
await deps.assertAdmission?.();
|
|
255
|
-
init?.signal?.throwIfAborted();
|
|
275
|
+
await deadline.wait(() => deps.assertAdmission?.());
|
|
256
276
|
};
|
|
277
|
+
const logResponseBody = (...args) => deadline.wait(() => debug.logResponseBody(...args));
|
|
257
278
|
await assertAdmission();
|
|
258
279
|
// Normalize Request/URL inputs to (urlString, init) so the string-based
|
|
259
280
|
// transform pipeline sees the real method/headers/body. Without this,
|
|
@@ -269,7 +290,7 @@ export function createRequestExecutor(deps) {
|
|
|
269
290
|
});
|
|
270
291
|
}
|
|
271
292
|
const bodyBuffer = req.body
|
|
272
|
-
? await req.clone().arrayBuffer()
|
|
293
|
+
? await deadline.wait(() => req.clone().arrayBuffer())
|
|
273
294
|
: undefined;
|
|
274
295
|
init = {
|
|
275
296
|
method: init?.method ?? req.method,
|
|
@@ -295,23 +316,46 @@ export function createRequestExecutor(deps) {
|
|
|
295
316
|
});
|
|
296
317
|
}
|
|
297
318
|
}
|
|
319
|
+
let selectedVariant = options.variant;
|
|
298
320
|
if (kind === 'title') {
|
|
299
|
-
|
|
321
|
+
const routed = routeTitleModel(input);
|
|
322
|
+
// A variant belongs to its catalog model, not the replacement title model.
|
|
323
|
+
if (routed !== input)
|
|
324
|
+
selectedVariant = undefined;
|
|
325
|
+
input = routed;
|
|
300
326
|
}
|
|
327
|
+
const retired = retiredModelResponse(input);
|
|
328
|
+
if (retired)
|
|
329
|
+
return retired;
|
|
301
330
|
const selectedModel = extractModelFromUrl(input);
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
331
|
+
let variant;
|
|
332
|
+
if (selectedVariant !== undefined) {
|
|
333
|
+
const definitions = getPublicModelDefinitions();
|
|
334
|
+
const variants = selectedModel && Object.hasOwn(definitions, selectedModel)
|
|
335
|
+
? definitions[selectedModel]?.variants
|
|
336
|
+
: undefined;
|
|
337
|
+
const registered = variants && Object.hasOwn(variants, selectedVariant)
|
|
338
|
+
? variants[selectedVariant]
|
|
339
|
+
: undefined;
|
|
340
|
+
if (!registered || registered.disabled === true) {
|
|
341
|
+
return new Response(JSON.stringify({
|
|
342
|
+
error: {
|
|
343
|
+
code: 412,
|
|
344
|
+
status: 'FAILED_PRECONDITION',
|
|
345
|
+
message: 'This Antigravity thinking level is unavailable. Choose another thinking level.',
|
|
346
|
+
},
|
|
347
|
+
}), { status: 412, headers: { 'Content-Type': 'application/json' } });
|
|
348
|
+
}
|
|
349
|
+
variant = {
|
|
350
|
+
thinkingLevel: registered.thinkingLevel,
|
|
351
|
+
thinkingBudget: registered.thinkingConfig?.thinkingBudget,
|
|
352
|
+
};
|
|
310
353
|
}
|
|
311
354
|
// A host that sends each request through its own raw sender (the GA
|
|
312
355
|
// loopback bridge) supplies it per request; every send of this request,
|
|
313
356
|
// warmups included, then goes through it with the same AbortSignal.
|
|
314
|
-
const
|
|
357
|
+
const sender = options.transport ?? defaultTransport;
|
|
358
|
+
const transport = (url, sendInit, sendOptions) => deadline.open(() => sender(url, sendInit, { ...sendOptions, signal: deadline.signal }));
|
|
315
359
|
const requestSessionIdentity = options.session ?? extractOpenCodeSessionIdentity(init?.headers);
|
|
316
360
|
// AGY conversation/trajectory/step metadata is kept per session and
|
|
317
361
|
// request kind: a title or compaction request never advances the
|
|
@@ -332,7 +376,7 @@ export function createRequestExecutor(deps) {
|
|
|
332
376
|
const urlString = typeof input === 'string' ? input : toUrlString(input);
|
|
333
377
|
const modelFromUrl = extractModelFromUrl(urlString) ?? 'unknown';
|
|
334
378
|
return createNoAccountResponse(credentials.domain === 'vault'
|
|
335
|
-
? VAULT_ACCOUNT_REMEDY
|
|
379
|
+
? (credentials.emptyRosterRefusal?.() ?? VAULT_ACCOUNT_REMEDY)
|
|
336
380
|
: 'No Antigravity accounts configured. Run `opencode auth login`.', modelFromUrl);
|
|
337
381
|
}
|
|
338
382
|
const urlString = toUrlString(input);
|
|
@@ -342,7 +386,7 @@ export function createRequestExecutor(deps) {
|
|
|
342
386
|
const pushDebug = (line) => {
|
|
343
387
|
if (!debug.isDebugEnabled())
|
|
344
388
|
return;
|
|
345
|
-
debugLines.push(redactCredentialText(line, [...selectedCredentials]));
|
|
389
|
+
debugLines.push(redactCredentialText(line, [...selectedCredentials], [...selectedProjectIds]));
|
|
346
390
|
};
|
|
347
391
|
pushDebug(`request=${urlString}`);
|
|
348
392
|
if (requestSessionIdentity.sessionId) {
|
|
@@ -359,6 +403,7 @@ export function createRequestExecutor(deps) {
|
|
|
359
403
|
let lastError = null;
|
|
360
404
|
const abortSignal = init?.signal ?? undefined;
|
|
361
405
|
const checkAborted = () => {
|
|
406
|
+
deadline.check();
|
|
362
407
|
if (abortSignal?.aborted) {
|
|
363
408
|
throw abortSignal.reason instanceof Error
|
|
364
409
|
? abortSignal.reason
|
|
@@ -367,16 +412,6 @@ export function createRequestExecutor(deps) {
|
|
|
367
412
|
};
|
|
368
413
|
const quietMode = config.quiet_mode;
|
|
369
414
|
const toastScope = config.toast_scope;
|
|
370
|
-
// Apply operator-controlled routing overrides live. The slash
|
|
371
|
-
// commands mutate these values through `applyCommand`; reading
|
|
372
|
-
// them per-request means a runtime flip takes effect on the next
|
|
373
|
-
// dispatched call without restarting the plugin.
|
|
374
|
-
const operatorRouting = operatorSettings?.get().routing;
|
|
375
|
-
const effectiveConfig = {
|
|
376
|
-
...config,
|
|
377
|
-
cli_first: operatorRouting?.cli_first ?? config.cli_first,
|
|
378
|
-
quota_style_fallback: operatorRouting?.quota_style_fallback ?? config.quota_style_fallback,
|
|
379
|
-
};
|
|
380
415
|
const showToast = async (message, variant) => {
|
|
381
416
|
log.debug('toast', {
|
|
382
417
|
message,
|
|
@@ -402,28 +437,24 @@ export function createRequestExecutor(deps) {
|
|
|
402
437
|
}
|
|
403
438
|
}
|
|
404
439
|
try {
|
|
405
|
-
await notify?.(message, variant);
|
|
440
|
+
await deadline.wait(() => notify?.(message, variant));
|
|
406
441
|
}
|
|
407
442
|
catch {
|
|
443
|
+
checkAborted();
|
|
408
444
|
// TUI may not be available
|
|
409
445
|
}
|
|
410
446
|
};
|
|
411
|
-
const hasOtherAccountWithAntigravity = (currentAccount) => {
|
|
412
|
-
if (family !== 'gemini')
|
|
413
|
-
return false;
|
|
414
|
-
return accountManager.hasOtherAccountWithAntigravityAvailable(currentAccount.index, family, model);
|
|
415
|
-
};
|
|
416
447
|
let accountSwitchCount = 0;
|
|
417
448
|
const maxAccountSwitches = config.max_account_switches ?? 2;
|
|
418
449
|
let previousAccountIndex = -1;
|
|
419
450
|
let needsCacheWarmup = false;
|
|
420
451
|
let localRecaptureUsed = false;
|
|
452
|
+
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1000;
|
|
453
|
+
let allAccountsBlockedAt;
|
|
421
454
|
while (true) {
|
|
422
455
|
await assertAdmission();
|
|
423
456
|
checkAborted();
|
|
424
457
|
const accountCount = accountManager.getAccountCount();
|
|
425
|
-
const routingDecision = resolveHeaderRoutingDecision(urlString, family, effectiveConfig);
|
|
426
|
-
const { preferredHeaderStyle, explicitQuota, allowQuotaFallback } = routingDecision;
|
|
427
458
|
if (accountCount === 0) {
|
|
428
459
|
// Mirror the no-account short-circuit inside the retry loop so callers
|
|
429
460
|
// that race with account removal still get a proper 401 instead of a
|
|
@@ -441,12 +472,6 @@ export function createRequestExecutor(deps) {
|
|
|
441
472
|
.getAccounts()
|
|
442
473
|
.filter((entry) => {
|
|
443
474
|
const decision = evaluateKillswitchForAccount(entry, family, {
|
|
444
|
-
routing: effectiveConfig.cli_first !== undefined
|
|
445
|
-
? {
|
|
446
|
-
cli_first: effectiveConfig.cli_first,
|
|
447
|
-
quota_style_fallback: !!effectiveConfig.quota_style_fallback,
|
|
448
|
-
}
|
|
449
|
-
: { cli_first: false, quota_style_fallback: false },
|
|
450
475
|
killswitch: operatorKillswitch,
|
|
451
476
|
log_level: 'info',
|
|
452
477
|
}, { now: Date.now(), model });
|
|
@@ -463,7 +488,6 @@ export function createRequestExecutor(deps) {
|
|
|
463
488
|
model: model ?? 'unknown',
|
|
464
489
|
accounts: accountManager.getAccounts(),
|
|
465
490
|
settings: {
|
|
466
|
-
routing: { cli_first: false, quota_style_fallback: false },
|
|
467
491
|
killswitch: operatorKillswitch ?? {
|
|
468
492
|
enabled: false,
|
|
469
493
|
minimum_remaining_percent: 0,
|
|
@@ -490,8 +514,7 @@ export function createRequestExecutor(deps) {
|
|
|
490
514
|
}
|
|
491
515
|
}
|
|
492
516
|
// The eligibility mask above is computed once for this selection
|
|
493
|
-
// pass and applies to
|
|
494
|
-
// fallback below. Selection does not re-evaluate quota, so a killed
|
|
517
|
+
// pass and applies to the account selection below. Selection does not re-evaluate quota, so a killed
|
|
495
518
|
// current account falls through to the next eligible account.
|
|
496
519
|
const killedIndexes = eligibleIndexes === null
|
|
497
520
|
? undefined
|
|
@@ -499,7 +522,7 @@ export function createRequestExecutor(deps) {
|
|
|
499
522
|
.getAccounts()
|
|
500
523
|
.map((entry) => entry.index)
|
|
501
524
|
.filter((index) => !eligibleIndexes.has(index)));
|
|
502
|
-
let account = accountManager.getCurrentOrNextForFamily(family, model, config.account_selection_strategy,
|
|
525
|
+
let account = accountManager.getCurrentOrNextForFamily(family, model, config.account_selection_strategy, config.pid_offset_enabled, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity, killedIndexes);
|
|
503
526
|
// The selected account must be inside the eligibility mask.
|
|
504
527
|
if (account &&
|
|
505
528
|
eligibleIndexes !== null &&
|
|
@@ -507,27 +530,29 @@ export function createRequestExecutor(deps) {
|
|
|
507
530
|
pushDebug(`killswitch-excluded idx=${account.index} (precomputed eligible set)`);
|
|
508
531
|
account = null;
|
|
509
532
|
}
|
|
510
|
-
if (!account && allowQuotaFallback) {
|
|
511
|
-
const alternateHeaderStyle = preferredHeaderStyle === 'antigravity' ? 'gemini-cli' : 'antigravity';
|
|
512
|
-
account = accountManager.getCurrentOrNextForFamily(family, model, config.account_selection_strategy, alternateHeaderStyle, config.pid_offset_enabled, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity, killedIndexes);
|
|
513
|
-
if (account) {
|
|
514
|
-
pushDebug(`selected-by-fallback idx=${account.index} preferred=${preferredHeaderStyle} alternate=${alternateHeaderStyle}`);
|
|
515
|
-
}
|
|
516
|
-
// The header-style fallback may not select an account outside the
|
|
517
|
-
// eligibility mask.
|
|
518
|
-
if (account &&
|
|
519
|
-
eligibleIndexes !== null &&
|
|
520
|
-
!eligibleIndexes.has(account.index)) {
|
|
521
|
-
pushDebug(`killswitch-excluded idx=${account.index} after fallback (precomputed eligible set)`);
|
|
522
|
-
account = null;
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
533
|
if (!account) {
|
|
534
|
+
// Rate-limit and soft-quota waits belong to the same blocked period.
|
|
535
|
+
// Selection of an eligible account below starts a fresh budget.
|
|
536
|
+
allAccountsBlockedAt ??= Date.now();
|
|
537
|
+
const blockedSince = allAccountsBlockedAt;
|
|
538
|
+
const remainingWaitMs = () => maxWaitMs > 0
|
|
539
|
+
? Math.max(0, maxWaitMs - (Date.now() - blockedSince))
|
|
540
|
+
: Number.POSITIVE_INFINITY;
|
|
541
|
+
// At an equal deadline, retain the classified blocked-pool refusal.
|
|
542
|
+
// This priority never changes either clock or replenishes the request.
|
|
543
|
+
const quotaWins = remainingWaitMs() <= deadline.remainingMs();
|
|
526
544
|
if (accountManager.areAllAccountsOverSoftQuota(family, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, model)) {
|
|
527
545
|
const threshold = config.soft_quota_threshold_percent;
|
|
528
546
|
const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(family, threshold, softQuotaCacheTtlMs, model);
|
|
529
|
-
|
|
547
|
+
waitPolicy.refusal = quotaWins
|
|
548
|
+
? () => createNativeGoogleErrorResponse({
|
|
549
|
+
status: 412,
|
|
550
|
+
reason: 'soft_quota',
|
|
551
|
+
resetAfterMs: softQuotaWaitMs,
|
|
552
|
+
})
|
|
553
|
+
: undefined;
|
|
530
554
|
if (softQuotaWaitMs === null ||
|
|
555
|
+
remainingWaitMs() <= 0 ||
|
|
531
556
|
(maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs)) {
|
|
532
557
|
const waitTimeFormatted = softQuotaWaitMs
|
|
533
558
|
? formatWaitTime(softQuotaWaitMs)
|
|
@@ -544,12 +569,18 @@ export function createRequestExecutor(deps) {
|
|
|
544
569
|
await showToast(`All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(softQuotaWaitMs)}...`, 'warning');
|
|
545
570
|
retryState.markSoftQuotaToastShown();
|
|
546
571
|
}
|
|
547
|
-
await sleep(softQuotaWaitMs, abortSignal);
|
|
572
|
+
await sleep(Math.min(softQuotaWaitMs, remainingWaitMs()), abortSignal);
|
|
548
573
|
continue;
|
|
549
574
|
}
|
|
550
|
-
const
|
|
551
|
-
const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model, preferredHeaderStyle, strictWait);
|
|
575
|
+
const minWaitMs = accountManager.getMinWaitTimeForFamily(family, model);
|
|
552
576
|
const waitMs = minWaitMs || 60_000;
|
|
577
|
+
waitPolicy.refusal = quotaWins
|
|
578
|
+
? () => createNativeGoogleErrorResponse({
|
|
579
|
+
status: 412,
|
|
580
|
+
reason: 'pool_unavailable',
|
|
581
|
+
resetAfterMs: minWaitMs > 0 ? minWaitMs : undefined,
|
|
582
|
+
})
|
|
583
|
+
: undefined;
|
|
553
584
|
pushDebug(`all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`);
|
|
554
585
|
if (debug.isDebugEnabled()) {
|
|
555
586
|
debug.logAccountContext('All accounts rate-limited', {
|
|
@@ -559,8 +590,7 @@ export function createRequestExecutor(deps) {
|
|
|
559
590
|
});
|
|
560
591
|
debug.logRateLimitSnapshot(family, accountManager.getAccountsSnapshot());
|
|
561
592
|
}
|
|
562
|
-
|
|
563
|
-
if (maxWaitMs > 0 && waitMs > maxWaitMs) {
|
|
593
|
+
if (remainingWaitMs() <= 0 || (maxWaitMs > 0 && waitMs > maxWaitMs)) {
|
|
564
594
|
const waitTimeFormatted = formatWaitTime(waitMs);
|
|
565
595
|
await showToast(`Rate limited for ${waitTimeFormatted}. Try again later or add another account.`, 'error');
|
|
566
596
|
return createNativeGoogleErrorResponse({
|
|
@@ -576,10 +606,12 @@ export function createRequestExecutor(deps) {
|
|
|
576
606
|
await showToast(`All ${accountCount} account(s) rate-limited for ${family}. Waiting ${waitSecValue}s...`, 'warning');
|
|
577
607
|
retryState.markRateLimitToastShown();
|
|
578
608
|
}
|
|
579
|
-
await sleep(waitMs, abortSignal);
|
|
609
|
+
await sleep(Math.min(waitMs, remainingWaitMs()), abortSignal);
|
|
580
610
|
continue;
|
|
581
611
|
}
|
|
582
|
-
//
|
|
612
|
+
// An eligible account ends the contiguous all-accounts-blocked period.
|
|
613
|
+
allAccountsBlockedAt = undefined;
|
|
614
|
+
waitPolicy.refusal = undefined;
|
|
583
615
|
retryState.resetAllAccountsBlockedToasts();
|
|
584
616
|
pushDebug(`selected idx=${account.index} email=${account.email ?? ''} family=${family} accounts=${accountCount} strategy=${config.account_selection_strategy}`);
|
|
585
617
|
if (previousAccountIndex >= 0 && previousAccountIndex !== account.index) {
|
|
@@ -620,11 +652,21 @@ export function createRequestExecutor(deps) {
|
|
|
620
652
|
// Project resolution can use this bearer before the main model send.
|
|
621
653
|
if (auth.access)
|
|
622
654
|
selectedCredentials.add(auth.access);
|
|
623
|
-
const
|
|
624
|
-
|
|
655
|
+
const packedProject = parseRefreshParts(auth.refresh);
|
|
656
|
+
for (const projectId of [
|
|
657
|
+
packedProject.projectId,
|
|
658
|
+
packedProject.managedProjectId,
|
|
659
|
+
]) {
|
|
660
|
+
if (projectId)
|
|
661
|
+
selectedProjectIds.add(projectId);
|
|
662
|
+
}
|
|
663
|
+
const context = await deadline
|
|
664
|
+
.wait(() => credentials.ensureProject(auth))
|
|
625
665
|
.catch((error) => {
|
|
626
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
666
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
627
667
|
});
|
|
668
|
+
if (context.effectiveProjectId)
|
|
669
|
+
selectedProjectIds.add(context.effectiveProjectId);
|
|
628
670
|
await assertAdmission();
|
|
629
671
|
// A project cache may carry an older bearer. Only the token fixed
|
|
630
672
|
// before this await belongs to the newly prepared request.
|
|
@@ -636,9 +678,10 @@ export function createRequestExecutor(deps) {
|
|
|
636
678
|
if (persistProject && projectAuth.refresh !== auth.refresh) {
|
|
637
679
|
credentials.updateFromAuth(account, projectAuth);
|
|
638
680
|
try {
|
|
639
|
-
await credentials.saveToDisk();
|
|
681
|
+
await deadline.wait(() => credentials.saveToDisk());
|
|
640
682
|
}
|
|
641
683
|
catch (error) {
|
|
684
|
+
checkAborted();
|
|
642
685
|
log.error('Failed to persist project context', {
|
|
643
686
|
error: String(error),
|
|
644
687
|
});
|
|
@@ -666,7 +709,7 @@ export function createRequestExecutor(deps) {
|
|
|
666
709
|
if (accessTokenExpired(authRecord)) {
|
|
667
710
|
try {
|
|
668
711
|
await assertAdmission();
|
|
669
|
-
const refreshed = await credentials.refresh(account);
|
|
712
|
+
const refreshed = await deadline.wait(() => credentials.refresh(account));
|
|
670
713
|
if (!refreshed) {
|
|
671
714
|
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
672
715
|
trackers.health.recordFailure(account.index);
|
|
@@ -683,7 +726,7 @@ export function createRequestExecutor(deps) {
|
|
|
683
726
|
}
|
|
684
727
|
if (shouldCooldown) {
|
|
685
728
|
accountManager.markAccountCoolingDown(account, cooldownMs, 'auth-failure');
|
|
686
|
-
accountManager.markRateLimited(account, cooldownMs, family,
|
|
729
|
+
accountManager.markRateLimited(account, cooldownMs, family, model);
|
|
687
730
|
pushDebug(`token-refresh-failed: cooldown ${cooldownMs}ms after ${failures} failures`);
|
|
688
731
|
}
|
|
689
732
|
continue;
|
|
@@ -693,23 +736,26 @@ export function createRequestExecutor(deps) {
|
|
|
693
736
|
authRecord = refreshed;
|
|
694
737
|
grantCheck = captureFor(authRecord);
|
|
695
738
|
try {
|
|
696
|
-
await credentials.saveToDisk();
|
|
739
|
+
await deadline.wait(() => credentials.saveToDisk());
|
|
697
740
|
}
|
|
698
741
|
catch (error) {
|
|
742
|
+
checkAborted();
|
|
699
743
|
log.error('Failed to persist refreshed auth', {
|
|
700
744
|
error: String(error),
|
|
701
745
|
});
|
|
702
746
|
}
|
|
703
747
|
}
|
|
704
748
|
catch (error) {
|
|
749
|
+
checkAborted();
|
|
705
750
|
if (credentials.isInvalidGrant(error)) {
|
|
706
751
|
const removed = credentials.removeAccount(account);
|
|
707
752
|
if (removed) {
|
|
708
753
|
log.warn('Removed revoked account from pool - reauthenticate via `opencode auth login`');
|
|
709
754
|
try {
|
|
710
|
-
await credentials.saveToDiskReplace();
|
|
755
|
+
await deadline.wait(() => credentials.saveToDiskReplace());
|
|
711
756
|
}
|
|
712
757
|
catch (persistError) {
|
|
758
|
+
checkAborted();
|
|
713
759
|
log.error('Failed to persist revoked account removal', {
|
|
714
760
|
error: String(persistError),
|
|
715
761
|
});
|
|
@@ -717,9 +763,10 @@ export function createRequestExecutor(deps) {
|
|
|
717
763
|
}
|
|
718
764
|
if (accountManager.getAccountCount() === 0) {
|
|
719
765
|
try {
|
|
720
|
-
await credentials.clearStoredAuth();
|
|
766
|
+
await deadline.wait(() => credentials.clearStoredAuth());
|
|
721
767
|
}
|
|
722
768
|
catch (storeError) {
|
|
769
|
+
checkAborted();
|
|
723
770
|
log.error('Failed to clear stored Antigravity OAuth credentials', {
|
|
724
771
|
error: String(storeError),
|
|
725
772
|
});
|
|
@@ -736,7 +783,7 @@ export function createRequestExecutor(deps) {
|
|
|
736
783
|
error instanceof Error ? error : new Error(String(error));
|
|
737
784
|
if (shouldCooldown) {
|
|
738
785
|
accountManager.markAccountCoolingDown(account, cooldownMs, 'auth-failure');
|
|
739
|
-
accountManager.markRateLimited(account, cooldownMs, family,
|
|
786
|
+
accountManager.markRateLimited(account, cooldownMs, family, model);
|
|
740
787
|
pushDebug(`token-refresh-error: cooldown ${cooldownMs}ms after ${failures} failures`);
|
|
741
788
|
}
|
|
742
789
|
continue;
|
|
@@ -760,12 +807,13 @@ export function createRequestExecutor(deps) {
|
|
|
760
807
|
retryState.resetAccountFailureState(account.index);
|
|
761
808
|
}
|
|
762
809
|
catch (error) {
|
|
810
|
+
checkAborted();
|
|
763
811
|
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
764
812
|
trackers.health.recordFailure(account.index);
|
|
765
813
|
lastError = error instanceof Error ? error : new Error(String(error));
|
|
766
814
|
if (shouldCooldown) {
|
|
767
815
|
accountManager.markAccountCoolingDown(account, cooldownMs, 'project-error');
|
|
768
|
-
accountManager.markRateLimited(account, cooldownMs, family,
|
|
816
|
+
accountManager.markRateLimited(account, cooldownMs, family, model);
|
|
769
817
|
pushDebug(`project-context-error: cooldown ${cooldownMs}ms after ${failures} failures`);
|
|
770
818
|
}
|
|
771
819
|
continue;
|
|
@@ -781,10 +829,10 @@ export function createRequestExecutor(deps) {
|
|
|
781
829
|
const credentialForAuxiliarySend = async (sendInit, preparedProjectId) => {
|
|
782
830
|
await assertAdmission();
|
|
783
831
|
if (credentials.domain === 'vault') {
|
|
784
|
-
const admission = await credentials.admit({
|
|
832
|
+
const admission = await deadline.wait(() => credentials.admit({
|
|
785
833
|
account: selected,
|
|
786
834
|
signal: abortSignal,
|
|
787
|
-
});
|
|
835
|
+
}));
|
|
788
836
|
selectedCredentials.add(admission.accessToken);
|
|
789
837
|
if (admission.projectId !== preparedProjectId) {
|
|
790
838
|
throw new Error('The vault served another project for this send; skipping it');
|
|
@@ -796,7 +844,7 @@ export function createRequestExecutor(deps) {
|
|
|
796
844
|
if (!localGrant) {
|
|
797
845
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
798
846
|
}
|
|
799
|
-
await localGrant.captured.check();
|
|
847
|
+
await deadline.wait(() => localGrant.captured.check());
|
|
800
848
|
await assertAdmission();
|
|
801
849
|
return { init: sendInit };
|
|
802
850
|
};
|
|
@@ -833,20 +881,21 @@ export function createRequestExecutor(deps) {
|
|
|
833
881
|
try {
|
|
834
882
|
pushDebug('thinking-warmup: start');
|
|
835
883
|
const warmupSend = await credentialForAuxiliarySend(warmupInit, projectId);
|
|
836
|
-
const warmupResponse =
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
})
|
|
841
|
-
: await upstreamFetch(warmupUrl, warmupSend.init);
|
|
884
|
+
const warmupResponse = await transport(warmupUrl, warmupSend.init, {
|
|
885
|
+
signal: abortSignal,
|
|
886
|
+
onDebug: pushDebug,
|
|
887
|
+
});
|
|
842
888
|
reportVault401(warmupSend.admission, warmupResponse.status);
|
|
843
|
-
const transformed = await wire.transformResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId);
|
|
844
|
-
await transformed.text();
|
|
889
|
+
const transformed = await deadline.wait(() => wire.transformResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId));
|
|
890
|
+
await deadline.wait(() => transformed.text());
|
|
845
891
|
warmupState.markSuccess(prepared.sessionId);
|
|
846
892
|
pushDebug('thinking-warmup: done');
|
|
847
893
|
}
|
|
848
894
|
catch (error) {
|
|
849
895
|
warmupState.clearWarmupAttempt(prepared.sessionId);
|
|
896
|
+
if (error instanceof PreResponseTimeoutError)
|
|
897
|
+
throw error;
|
|
898
|
+
checkAborted();
|
|
850
899
|
if (isLocalGrantError(error))
|
|
851
900
|
throw error;
|
|
852
901
|
pushDebug(`thinking-warmup: failed ${error instanceof Error ? error.message : String(error)}`);
|
|
@@ -864,23 +913,21 @@ export function createRequestExecutor(deps) {
|
|
|
864
913
|
try {
|
|
865
914
|
pushDebug('cache-warmup-probe: start');
|
|
866
915
|
const probeSend = await credentialForAuxiliarySend({ ...prepared.init, method: 'POST', body: bodyStr }, prepared.projectId ?? '');
|
|
867
|
-
const probeResponse = prepared.
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
})
|
|
872
|
-
: await upstreamFetch(toUrlString(prepared.request), probeSend.init);
|
|
916
|
+
const probeResponse = await transport(toUrlString(prepared.request), probeSend.init, {
|
|
917
|
+
signal: abortSignal,
|
|
918
|
+
onDebug: pushDebug,
|
|
919
|
+
});
|
|
873
920
|
reportVault401(probeSend.admission, probeResponse.status);
|
|
874
921
|
if (probeResponse.body) {
|
|
875
922
|
const reader = probeResponse.body.getReader();
|
|
876
|
-
await reader.read();
|
|
877
|
-
await reader.cancel();
|
|
923
|
+
await deadline.wait(() => reader.read());
|
|
924
|
+
await deadline.wait(() => reader.cancel());
|
|
878
925
|
}
|
|
879
926
|
const status = probeResponse.status;
|
|
880
927
|
if (status >= 400) {
|
|
881
928
|
let errorSnippet = '';
|
|
882
929
|
try {
|
|
883
|
-
const errText = await probeResponse.text().catch(() => '');
|
|
930
|
+
const errText = await deadline.wait(() => probeResponse.text().catch(() => ''));
|
|
884
931
|
errorSnippet = errText.slice(0, 200);
|
|
885
932
|
}
|
|
886
933
|
catch {
|
|
@@ -893,6 +940,9 @@ export function createRequestExecutor(deps) {
|
|
|
893
940
|
}
|
|
894
941
|
}
|
|
895
942
|
catch (error) {
|
|
943
|
+
if (error instanceof PreResponseTimeoutError)
|
|
944
|
+
throw error;
|
|
945
|
+
checkAborted();
|
|
896
946
|
if (isLocalGrantError(error)) {
|
|
897
947
|
needsCacheWarmup = true;
|
|
898
948
|
throw error;
|
|
@@ -902,57 +952,11 @@ export function createRequestExecutor(deps) {
|
|
|
902
952
|
};
|
|
903
953
|
let apiRequestCount = 0;
|
|
904
954
|
let shouldSwitchAccount = false;
|
|
905
|
-
let headerStyle = preferredHeaderStyle;
|
|
906
|
-
pushDebug(`headerStyle=${headerStyle} explicit=${explicitQuota}`);
|
|
907
955
|
if (account.fingerprint) {
|
|
908
956
|
pushDebug(`fingerprint: deviceId=${account.fingerprint.deviceId.slice(0, 8)}...`);
|
|
909
957
|
}
|
|
910
|
-
if (accountManager.
|
|
911
|
-
|
|
912
|
-
family === 'gemini' &&
|
|
913
|
-
headerStyle === 'antigravity') {
|
|
914
|
-
if (accountManager.hasOtherAccountWithAntigravityAvailable(account.index, family, model)) {
|
|
915
|
-
pushDebug(`antigravity rate-limited on account ${account.index}, but available on other accounts. Switching.`);
|
|
916
|
-
shouldSwitchAccount = true;
|
|
917
|
-
}
|
|
918
|
-
else {
|
|
919
|
-
const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
|
|
920
|
-
const fallbackStyle = resolveQuotaFallbackHeaderStyle({
|
|
921
|
-
family,
|
|
922
|
-
headerStyle,
|
|
923
|
-
alternateStyle,
|
|
924
|
-
});
|
|
925
|
-
if (fallbackStyle) {
|
|
926
|
-
await showToast(`Antigravity quota exhausted on all accounts. Using Gemini CLI quota.`, 'warning');
|
|
927
|
-
headerStyle = fallbackStyle;
|
|
928
|
-
pushDebug(`all-accounts antigravity exhausted, quota fallback: ${headerStyle}`);
|
|
929
|
-
}
|
|
930
|
-
else {
|
|
931
|
-
shouldSwitchAccount = true;
|
|
932
|
-
}
|
|
933
|
-
}
|
|
934
|
-
}
|
|
935
|
-
else if (allowQuotaFallback && family === 'gemini') {
|
|
936
|
-
const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
|
|
937
|
-
const fallbackStyle = resolveQuotaFallbackHeaderStyle({
|
|
938
|
-
family,
|
|
939
|
-
headerStyle,
|
|
940
|
-
alternateStyle,
|
|
941
|
-
});
|
|
942
|
-
if (fallbackStyle) {
|
|
943
|
-
const quotaName = headerStyle === 'gemini-cli' ? 'Gemini CLI' : 'Antigravity';
|
|
944
|
-
const altQuotaName = fallbackStyle === 'gemini-cli' ? 'Gemini CLI' : 'Antigravity';
|
|
945
|
-
await showToast(`${quotaName} quota exhausted, using ${altQuotaName} quota`, 'warning');
|
|
946
|
-
headerStyle = fallbackStyle;
|
|
947
|
-
pushDebug(`quota fallback: ${headerStyle}`);
|
|
948
|
-
}
|
|
949
|
-
else {
|
|
950
|
-
shouldSwitchAccount = true;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
else {
|
|
954
|
-
shouldSwitchAccount = true;
|
|
955
|
-
}
|
|
958
|
+
if (accountManager.isRateLimited(account, family, model)) {
|
|
959
|
+
shouldSwitchAccount = true;
|
|
956
960
|
}
|
|
957
961
|
let totalCapacityRetries = 0;
|
|
958
962
|
while (!shouldSwitchAccount) {
|
|
@@ -969,11 +973,6 @@ export function createRequestExecutor(deps) {
|
|
|
969
973
|
lastEndpointIndex = i;
|
|
970
974
|
}
|
|
971
975
|
const currentEndpoint = ANTIGRAVITY_ENDPOINT_FALLBACKS[i];
|
|
972
|
-
if (headerStyle === 'gemini-cli' &&
|
|
973
|
-
currentEndpoint !== 'https://cloudcode-pa.googleapis.com') {
|
|
974
|
-
pushDebug(`Skipping sandbox endpoint ${currentEndpoint} for gemini-cli headerStyle`);
|
|
975
|
-
continue;
|
|
976
|
-
}
|
|
977
976
|
let tokenConsumed = false;
|
|
978
977
|
let physicalAttemptStarted = false;
|
|
979
978
|
try {
|
|
@@ -989,10 +988,10 @@ export function createRequestExecutor(deps) {
|
|
|
989
988
|
// retry it was taken for, then is gone.
|
|
990
989
|
sendAdmission =
|
|
991
990
|
rotatedAdmission ??
|
|
992
|
-
(await credentials.admit({
|
|
991
|
+
(await deadline.wait(() => credentials.admit({
|
|
993
992
|
account,
|
|
994
993
|
signal: abortSignal,
|
|
995
|
-
}));
|
|
994
|
+
})));
|
|
996
995
|
rotatedAdmission = undefined;
|
|
997
996
|
sendAccessToken = sendAdmission.accessToken;
|
|
998
997
|
sendProjectId = sendAdmission.projectId;
|
|
@@ -1004,6 +1003,8 @@ export function createRequestExecutor(deps) {
|
|
|
1004
1003
|
else {
|
|
1005
1004
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
1006
1005
|
}
|
|
1006
|
+
if (sendProjectId)
|
|
1007
|
+
selectedProjectIds.add(sendProjectId);
|
|
1007
1008
|
selectedCredentials.add(sendAccessToken);
|
|
1008
1009
|
const prepared = prepareAgyWireRequest(wire, {
|
|
1009
1010
|
input,
|
|
@@ -1011,7 +1012,6 @@ export function createRequestExecutor(deps) {
|
|
|
1011
1012
|
accessToken: sendAccessToken,
|
|
1012
1013
|
projectId: sendProjectId,
|
|
1013
1014
|
endpoint: currentEndpoint,
|
|
1014
|
-
headerStyle,
|
|
1015
1015
|
forceThinkingRecovery,
|
|
1016
1016
|
options: {
|
|
1017
1017
|
claudeToolHardening: config.claude_tool_hardening,
|
|
@@ -1019,6 +1019,7 @@ export function createRequestExecutor(deps) {
|
|
|
1019
1019
|
fingerprint: account.fingerprint,
|
|
1020
1020
|
agySession: agyRequestSession,
|
|
1021
1021
|
agyRequestTimestamp: agyRequestScope.timestamp,
|
|
1022
|
+
variant,
|
|
1022
1023
|
},
|
|
1023
1024
|
});
|
|
1024
1025
|
const originalUrl = toUrlString(input);
|
|
@@ -1057,7 +1058,6 @@ export function createRequestExecutor(deps) {
|
|
|
1057
1058
|
sessionId: prepared.sessionId,
|
|
1058
1059
|
toolDebugMissing: prepared.toolDebugMissing,
|
|
1059
1060
|
toolDebugSummary: prepared.toolDebugSummary,
|
|
1060
|
-
toolDebugPayload: prepared.toolDebugPayload,
|
|
1061
1061
|
dumpContext,
|
|
1062
1062
|
});
|
|
1063
1063
|
await runThinkingWarmup(prepared, sendProjectId);
|
|
@@ -1076,14 +1076,14 @@ export function createRequestExecutor(deps) {
|
|
|
1076
1076
|
if (!localGrant) {
|
|
1077
1077
|
throw new Error('Local credentials were not resolved for the selected account');
|
|
1078
1078
|
}
|
|
1079
|
-
await localGrant.captured.check();
|
|
1079
|
+
await deadline.wait(() => localGrant.captured.check());
|
|
1080
1080
|
await assertAdmission();
|
|
1081
1081
|
}
|
|
1082
1082
|
pushDebug(`dispatching request via ${prepared.headerStyle} transport`);
|
|
1083
1083
|
physicalAttemptStarted = true;
|
|
1084
|
-
const response = prepared.
|
|
1085
|
-
|
|
1086
|
-
|
|
1084
|
+
const response = await transport(toUrlString(prepared.request), prepared.init, { signal: abortSignal, onDebug: pushDebug });
|
|
1085
|
+
if (response.ok)
|
|
1086
|
+
deadline.acceptHeaders();
|
|
1087
1087
|
apiRequestCount++;
|
|
1088
1088
|
accountManager.recordRequest(account.index, family);
|
|
1089
1089
|
const requestCounts = accountManager.getDailyRequestCounts(account.index);
|
|
@@ -1100,18 +1100,19 @@ export function createRequestExecutor(deps) {
|
|
|
1100
1100
|
// version of the same credential and account may retry this
|
|
1101
1101
|
// endpoint, once; otherwise the 401 stands.
|
|
1102
1102
|
try {
|
|
1103
|
-
await sendAdmission.report401(response.status);
|
|
1103
|
+
await deadline.wait(() => sendAdmission.report401(response.status));
|
|
1104
1104
|
}
|
|
1105
1105
|
catch (error) {
|
|
1106
|
+
checkAborted();
|
|
1106
1107
|
log.debug('send-admission-401-report-failed', {
|
|
1107
1108
|
error: String(error),
|
|
1108
1109
|
});
|
|
1109
1110
|
}
|
|
1110
1111
|
if (!vault401Retried) {
|
|
1111
|
-
const next = await credentials.admit({
|
|
1112
|
+
const next = await deadline.wait(() => credentials.admit({
|
|
1112
1113
|
account,
|
|
1113
1114
|
signal: abortSignal,
|
|
1114
|
-
});
|
|
1115
|
+
}));
|
|
1115
1116
|
if (next.credentialId === sendAdmission.credentialId &&
|
|
1116
1117
|
next.accountIdentity === sendAdmission.accountIdentity &&
|
|
1117
1118
|
next.recordVersion > sendAdmission.recordVersion) {
|
|
@@ -1150,7 +1151,7 @@ export function createRequestExecutor(deps) {
|
|
|
1150
1151
|
const headerRetryMs = retryAfterMsFromResponse(response, defaultRetryMs);
|
|
1151
1152
|
const bodyInfo = await (async () => {
|
|
1152
1153
|
try {
|
|
1153
|
-
const text = await response.clone().text();
|
|
1154
|
+
const text = await deadline.wait(() => response.clone().text());
|
|
1154
1155
|
try {
|
|
1155
1156
|
return JSON.parse(text);
|
|
1156
1157
|
}
|
|
@@ -1159,6 +1160,7 @@ export function createRequestExecutor(deps) {
|
|
|
1159
1160
|
}
|
|
1160
1161
|
}
|
|
1161
1162
|
catch {
|
|
1163
|
+
checkAborted();
|
|
1162
1164
|
return null;
|
|
1163
1165
|
}
|
|
1164
1166
|
})();
|
|
@@ -1199,7 +1201,7 @@ export function createRequestExecutor(deps) {
|
|
|
1199
1201
|
continue;
|
|
1200
1202
|
}
|
|
1201
1203
|
}
|
|
1202
|
-
const quotaKey =
|
|
1204
|
+
const quotaKey = getQuotaKey(family, model);
|
|
1203
1205
|
const backoff = retryState.getRateLimitBackoff(account.index, quotaKey, serverRetryMs);
|
|
1204
1206
|
const smartBackoffMs = calculateBackoffMs(rateLimitReason, account.consecutiveFailures ?? 0, serverRetryMs);
|
|
1205
1207
|
const effectiveDelayMs = Math.max(backoff.delayMs, smartBackoffMs);
|
|
@@ -1211,7 +1213,7 @@ export function createRequestExecutor(deps) {
|
|
|
1211
1213
|
if (reasonInfo.reason)
|
|
1212
1214
|
pushDebug(`429 reason=${reasonInfo.reason}`);
|
|
1213
1215
|
debug.logRateLimitEvent(account.index, account.email, family, response.status, effectiveDelayMs, reasonInfo);
|
|
1214
|
-
await
|
|
1216
|
+
await logResponseBody(debugContext, response, 429);
|
|
1215
1217
|
trackers.health.recordRateLimit(account.index);
|
|
1216
1218
|
const _accountLabel = account.email || `Account ${account.index + 1}`;
|
|
1217
1219
|
if (backoff.attempt === 1 &&
|
|
@@ -1223,7 +1225,7 @@ export function createRequestExecutor(deps) {
|
|
|
1223
1225
|
if (effectiveDelayMs <= maxCacheFirstWaitMs) {
|
|
1224
1226
|
pushDebug(`cache_first: waiting ${effectiveDelayMs}ms for same account to recover`);
|
|
1225
1227
|
await showToast(`⏳ Waiting ${Math.ceil(effectiveDelayMs / 1000)}s for same account (prompt cache preserved)...`, 'info');
|
|
1226
|
-
accountManager.markRateLimitedWithReason(account, family,
|
|
1228
|
+
accountManager.markRateLimitedWithReason(account, family, model, rateLimitReason, serverRetryMs);
|
|
1227
1229
|
await sleep(effectiveDelayMs, abortSignal);
|
|
1228
1230
|
i -= 1;
|
|
1229
1231
|
continue;
|
|
@@ -1231,59 +1233,16 @@ export function createRequestExecutor(deps) {
|
|
|
1231
1233
|
pushDebug(`cache_first: wait ${effectiveDelayMs}ms exceeds max ${maxCacheFirstWaitMs}ms, switching account`);
|
|
1232
1234
|
}
|
|
1233
1235
|
if (config.switch_on_first_rate_limit && accountCount > 1) {
|
|
1234
|
-
accountManager.markRateLimitedWithReason(account, family,
|
|
1236
|
+
accountManager.markRateLimitedWithReason(account, family, model, rateLimitReason, serverRetryMs, config.failure_ttl_seconds * 1000);
|
|
1235
1237
|
shouldSwitchAccount = true;
|
|
1236
1238
|
break;
|
|
1237
1239
|
}
|
|
1238
1240
|
i -= 1;
|
|
1239
1241
|
continue;
|
|
1240
1242
|
}
|
|
1241
|
-
accountManager.markRateLimitedWithReason(account, family,
|
|
1243
|
+
accountManager.markRateLimitedWithReason(account, family, model, rateLimitReason, serverRetryMs, config.failure_ttl_seconds * 1000);
|
|
1242
1244
|
accountManager.requestSaveToDisk();
|
|
1243
1245
|
const switchAccountDelayMs = config.switch_account_delay_ms ?? 500;
|
|
1244
|
-
if (family === 'gemini') {
|
|
1245
|
-
if (headerStyle === 'antigravity') {
|
|
1246
|
-
if (hasOtherAccountWithAntigravity(account)) {
|
|
1247
|
-
pushDebug(`antigravity exhausted on account ${account.index}, but available on others. Switching account.`);
|
|
1248
|
-
await showToast(`Rate limited again. Switching account in ${formatWaitTime(switchAccountDelayMs)}...`, 'warning');
|
|
1249
|
-
await sleep(switchAccountDelayMs, abortSignal);
|
|
1250
|
-
shouldSwitchAccount = true;
|
|
1251
|
-
break;
|
|
1252
|
-
}
|
|
1253
|
-
if (allowQuotaFallback) {
|
|
1254
|
-
const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
|
|
1255
|
-
const fallbackStyle = resolveQuotaFallbackHeaderStyle({
|
|
1256
|
-
family,
|
|
1257
|
-
headerStyle,
|
|
1258
|
-
alternateStyle,
|
|
1259
|
-
});
|
|
1260
|
-
if (fallbackStyle) {
|
|
1261
|
-
const safeModelName = model || 'this model';
|
|
1262
|
-
await showToast(`Antigravity quota exhausted for ${safeModelName}. Switching to Gemini CLI quota...`, 'warning');
|
|
1263
|
-
headerStyle = fallbackStyle;
|
|
1264
|
-
pushDebug(`quota fallback: ${headerStyle}`);
|
|
1265
|
-
continue;
|
|
1266
|
-
}
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
else if (headerStyle === 'gemini-cli') {
|
|
1270
|
-
if (allowQuotaFallback) {
|
|
1271
|
-
const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
|
|
1272
|
-
const fallbackStyle = resolveQuotaFallbackHeaderStyle({
|
|
1273
|
-
family,
|
|
1274
|
-
headerStyle,
|
|
1275
|
-
alternateStyle,
|
|
1276
|
-
});
|
|
1277
|
-
if (fallbackStyle) {
|
|
1278
|
-
const safeModelName = model || 'this model';
|
|
1279
|
-
await showToast(`Gemini CLI quota exhausted for ${safeModelName}. Switching to Antigravity quota...`, 'warning');
|
|
1280
|
-
headerStyle = fallbackStyle;
|
|
1281
|
-
pushDebug(`quota fallback: ${headerStyle}`);
|
|
1282
|
-
continue;
|
|
1283
|
-
}
|
|
1284
|
-
}
|
|
1285
|
-
}
|
|
1286
|
-
}
|
|
1287
1246
|
if (accountCount > 1) {
|
|
1288
1247
|
const quotaMsg = reasonInfo.quotaResetTime
|
|
1289
1248
|
? ` (quota resets ${reasonInfo.quotaResetTime})`
|
|
@@ -1303,14 +1262,14 @@ export function createRequestExecutor(deps) {
|
|
|
1303
1262
|
shouldSwitchAccount = true;
|
|
1304
1263
|
break;
|
|
1305
1264
|
}
|
|
1306
|
-
const quotaKey =
|
|
1265
|
+
const quotaKey = getQuotaKey(family, model);
|
|
1307
1266
|
retryState.resetRateLimitState(account.index, quotaKey);
|
|
1308
1267
|
retryState.resetAccountFailureState(account.index);
|
|
1309
1268
|
if (response.status === 403) {
|
|
1310
|
-
const errorBodyText = await response
|
|
1269
|
+
const errorBodyText = await deadline.wait(() => response
|
|
1311
1270
|
.clone()
|
|
1312
1271
|
.text()
|
|
1313
|
-
.catch(() => '');
|
|
1272
|
+
.catch(() => ''));
|
|
1314
1273
|
const extracted = classifyAccessError(errorBodyText);
|
|
1315
1274
|
if (extracted.accountIneligible) {
|
|
1316
1275
|
const ineligibleReason = extracted.message ??
|
|
@@ -1333,7 +1292,7 @@ export function createRequestExecutor(deps) {
|
|
|
1333
1292
|
const cooldownMs = 10 * 60 * 1000;
|
|
1334
1293
|
accountManager.markAccountVerificationRequired(account.index, verificationReason, extracted.verifyUrl);
|
|
1335
1294
|
accountManager.markAccountCoolingDown(account, cooldownMs, 'validation-required');
|
|
1336
|
-
accountManager.markRateLimited(account, cooldownMs, family,
|
|
1295
|
+
accountManager.markRateLimited(account, cooldownMs, family, model);
|
|
1337
1296
|
const label = account.email || `Account ${account.index + 1}`;
|
|
1338
1297
|
if (accountManager.shouldShowAccountToast(account.index, 60000)) {
|
|
1339
1298
|
await showToast(`⚠ ${label} needs verification. Run 'opencode auth login' and use Verify accounts.`, 'warning');
|
|
@@ -1351,24 +1310,35 @@ export function createRequestExecutor(deps) {
|
|
|
1351
1310
|
response.status >= 500;
|
|
1352
1311
|
if (shouldRetryEndpoint &&
|
|
1353
1312
|
i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
|
|
1354
|
-
await
|
|
1313
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1355
1314
|
lastFailure = createFailureContext(response);
|
|
1356
1315
|
continue;
|
|
1357
1316
|
}
|
|
1358
1317
|
if (response.ok) {
|
|
1359
1318
|
account.consecutiveFailures = 0;
|
|
1360
1319
|
trackers.health.recordSuccess(account.index);
|
|
1361
|
-
|
|
1320
|
+
if (!advisoryClosing)
|
|
1321
|
+
accountManager.markAccountUsed(account.index);
|
|
1362
1322
|
if (credentials.domain === 'local' &&
|
|
1323
|
+
!advisoryClosing &&
|
|
1363
1324
|
credentials.refreshQuotaAfterSuccess) {
|
|
1364
|
-
|
|
1365
|
-
.
|
|
1366
|
-
.
|
|
1325
|
+
const quotaCancellation = createRequestCancellation(init?.signal
|
|
1326
|
+
? [init.signal, shutdown.signal]
|
|
1327
|
+
: [shutdown.signal]);
|
|
1328
|
+
const work = credentials
|
|
1329
|
+
.refreshQuotaAfterSuccess(account, config.quota_refresh_interval_minutes, quotaCancellation.signal)
|
|
1330
|
+
.catch(() => {
|
|
1331
|
+
log.debug('post-response-advisory-work-failed');
|
|
1332
|
+
})
|
|
1333
|
+
.finally(() => quotaCancellation.release());
|
|
1334
|
+
advisoryWork.add(work);
|
|
1335
|
+
void work.then(() => advisoryWork.delete(work), () => advisoryWork.delete(work));
|
|
1367
1336
|
}
|
|
1368
1337
|
const proactiveThreshold = config.proactive_rotation_threshold_percent ?? 20;
|
|
1369
|
-
if (
|
|
1338
|
+
if (!advisoryClosing &&
|
|
1339
|
+
proactiveThreshold > 0 &&
|
|
1370
1340
|
accountManager.shouldProactivelyRotate(family, model, proactiveThreshold, softQuotaCacheTtlMs, accountSessionIdentity)) {
|
|
1371
|
-
const rotated = accountManager.proactivelyRotateForFamily(family, model,
|
|
1341
|
+
const rotated = accountManager.proactivelyRotateForFamily(family, model, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity);
|
|
1372
1342
|
if (rotated) {
|
|
1373
1343
|
const remaining = account.cachedQuota?.[resolveQuotaGroup(family, model)]
|
|
1374
1344
|
?.remainingFraction;
|
|
@@ -1383,13 +1353,13 @@ export function createRequestExecutor(deps) {
|
|
|
1383
1353
|
note: response.ok ? 'Success' : `Error ${response.status}`,
|
|
1384
1354
|
});
|
|
1385
1355
|
if (response.ok && !prepared.streaming) {
|
|
1386
|
-
await
|
|
1356
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1387
1357
|
}
|
|
1388
1358
|
if (!response.ok) {
|
|
1389
|
-
await
|
|
1359
|
+
await logResponseBody(debugContext, response, response.status);
|
|
1390
1360
|
if (response.status === 400) {
|
|
1391
1361
|
const cloned = response.clone();
|
|
1392
|
-
const bodyText = await cloned.text();
|
|
1362
|
+
const bodyText = await deadline.wait(() => cloned.text());
|
|
1393
1363
|
if (bodyText.includes('Prompt is too long') ||
|
|
1394
1364
|
bodyText.includes('prompt_too_long')) {
|
|
1395
1365
|
await showToast('Context too long - use /compact to reduce size', 'warning');
|
|
@@ -1404,12 +1374,13 @@ export function createRequestExecutor(deps) {
|
|
|
1404
1374
|
const maxAttempts = config.empty_response_max_attempts ?? 4;
|
|
1405
1375
|
const retryDelayMs = config.empty_response_retry_delay_ms ?? 2000;
|
|
1406
1376
|
const clonedForCheck = response.clone();
|
|
1407
|
-
const bodyText = await clonedForCheck.text();
|
|
1377
|
+
const bodyText = await deadline.wait(() => clonedForCheck.text());
|
|
1408
1378
|
if (isEmptyResponseBody(bodyText)) {
|
|
1409
1379
|
const emptyAttemptKey = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
|
|
1410
1380
|
const currentAttempts = retryState.recordEmptyResponseAttempt(emptyAttemptKey);
|
|
1411
1381
|
pushDebug(`empty-response: attempt ${currentAttempts}/${maxAttempts}`);
|
|
1412
1382
|
if (currentAttempts < maxAttempts) {
|
|
1383
|
+
deadline.resume();
|
|
1413
1384
|
await showToast(`Empty response received. Retrying (${currentAttempts}/${maxAttempts})...`, 'warning');
|
|
1414
1385
|
await sleep(retryDelayMs, abortSignal);
|
|
1415
1386
|
continue;
|
|
@@ -1423,7 +1394,7 @@ export function createRequestExecutor(deps) {
|
|
|
1423
1394
|
const _emptyAttemptKeyClean = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
|
|
1424
1395
|
retryState.clearEmptyResponseAttempts();
|
|
1425
1396
|
}
|
|
1426
|
-
const transformedResponse = await wire.transformResponse(response, prepared.streaming, debugContext, prepared.requestedModel, prepared.projectId, prepared.endpoint, prepared.effectiveModel, prepared.sessionId, prepared.toolDebugMissing, prepared.toolDebugSummary,
|
|
1397
|
+
const transformedResponse = await deadline.wait(() => wire.transformResponse(response, prepared.streaming, debugContext, prepared.requestedModel, prepared.projectId, prepared.endpoint, prepared.effectiveModel, prepared.sessionId, prepared.toolDebugMissing, prepared.toolDebugSummary, debugLines, dumpContext));
|
|
1427
1398
|
const contextError = transformedResponse.headers.get('x-antigravity-context-error');
|
|
1428
1399
|
if (contextError) {
|
|
1429
1400
|
if (contextError === 'prompt_too_long') {
|
|
@@ -1464,6 +1435,9 @@ export function createRequestExecutor(deps) {
|
|
|
1464
1435
|
return transformedResponse;
|
|
1465
1436
|
}
|
|
1466
1437
|
catch (error) {
|
|
1438
|
+
if (error instanceof PreResponseTimeoutError)
|
|
1439
|
+
throw error;
|
|
1440
|
+
checkAborted();
|
|
1467
1441
|
if (tokenConsumed &&
|
|
1468
1442
|
(!isLocalGrantError(error) || !physicalAttemptStarted)) {
|
|
1469
1443
|
trackers.token.refund(account.index);
|
|
@@ -1479,7 +1453,8 @@ export function createRequestExecutor(deps) {
|
|
|
1479
1453
|
!localRecaptureUsed) {
|
|
1480
1454
|
localRecaptureUsed = true;
|
|
1481
1455
|
try {
|
|
1482
|
-
|
|
1456
|
+
const originalGrant = localGrant.captured;
|
|
1457
|
+
await deadline.wait(() => originalGrant.resolveCurrent());
|
|
1483
1458
|
const auth = credentials.toAuthDetails(account);
|
|
1484
1459
|
if (!auth.access || accessTokenExpired(auth))
|
|
1485
1460
|
return createNativeGoogleErrorResponse({
|
|
@@ -1506,6 +1481,7 @@ export function createRequestExecutor(deps) {
|
|
|
1506
1481
|
if (error instanceof Error &&
|
|
1507
1482
|
error.message === 'THINKING_RECOVERY_NEEDED') {
|
|
1508
1483
|
if (!forceThinkingRecovery) {
|
|
1484
|
+
deadline.resume();
|
|
1509
1485
|
pushDebug('thinking-recovery: API error detected, retrying with forced recovery');
|
|
1510
1486
|
forceThinkingRecovery = true;
|
|
1511
1487
|
i = -1;
|
|
@@ -1537,7 +1513,7 @@ export function createRequestExecutor(deps) {
|
|
|
1537
1513
|
error instanceof Error ? error : new Error(String(error));
|
|
1538
1514
|
if (shouldCooldown) {
|
|
1539
1515
|
accountManager.markAccountCoolingDown(account, cooldownMs, 'network-error');
|
|
1540
|
-
accountManager.markRateLimited(account, cooldownMs, family,
|
|
1516
|
+
accountManager.markRateLimited(account, cooldownMs, family, model);
|
|
1541
1517
|
pushDebug(`endpoint-error: cooldown ${cooldownMs}ms after ${failures} failures`);
|
|
1542
1518
|
}
|
|
1543
1519
|
shouldSwitchAccount = true;
|
|
@@ -1550,20 +1526,20 @@ export function createRequestExecutor(deps) {
|
|
|
1550
1526
|
if (accountSwitchCount > maxAccountSwitches) {
|
|
1551
1527
|
pushDebug(`account-switch-cap: exceeded max_account_switches=${maxAccountSwitches}, giving up`);
|
|
1552
1528
|
if (lastFailure) {
|
|
1553
|
-
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary,
|
|
1529
|
+
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
|
|
1554
1530
|
}
|
|
1555
1531
|
throw terminalFetchError(lastError, `Exceeded max account switches (${maxAccountSwitches}). All accounts rate-limited.`);
|
|
1556
1532
|
}
|
|
1557
1533
|
if (accountCount <= 1) {
|
|
1558
1534
|
if (lastFailure) {
|
|
1559
|
-
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary,
|
|
1535
|
+
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
|
|
1560
1536
|
}
|
|
1561
1537
|
throw terminalFetchError(lastError, 'All Antigravity endpoints failed');
|
|
1562
1538
|
}
|
|
1563
1539
|
continue;
|
|
1564
1540
|
}
|
|
1565
1541
|
if (lastFailure) {
|
|
1566
|
-
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary,
|
|
1542
|
+
return wire.transformResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, debugLines, lastFailure.dumpContext);
|
|
1567
1543
|
}
|
|
1568
1544
|
throw terminalFetchError(lastError, 'All Antigravity accounts failed');
|
|
1569
1545
|
}
|
|
@@ -1571,10 +1547,13 @@ export function createRequestExecutor(deps) {
|
|
|
1571
1547
|
// Waits for every admitted request and retained body, then releases the
|
|
1572
1548
|
// bookkeeping they use. Runs once, whether `retire` or `dispose` asks first.
|
|
1573
1549
|
function drain() {
|
|
1550
|
+
advisoryClosing = true;
|
|
1574
1551
|
drainPromise ??= (async () => {
|
|
1575
1552
|
// A refresh that already exchanged tokens must finish its owned store write.
|
|
1576
1553
|
while (inFlight.size > 0)
|
|
1577
1554
|
await Promise.allSettled([...inFlight]);
|
|
1555
|
+
while (advisoryWork.size > 0)
|
|
1556
|
+
await Promise.allSettled([...advisoryWork]);
|
|
1578
1557
|
retryState.dispose();
|
|
1579
1558
|
warmupState.dispose();
|
|
1580
1559
|
})();
|
|
@@ -1602,26 +1581,46 @@ export function createRequestExecutor(deps) {
|
|
|
1602
1581
|
const cancellation = createRequestCancellation(requestedSignal
|
|
1603
1582
|
? [requestedSignal, shutdown.signal]
|
|
1604
1583
|
: [shutdown.signal]);
|
|
1584
|
+
const deadline = new PreResponseDeadline(cancellation.signal, deps.preResponseClock);
|
|
1585
|
+
log.debug('pre-response-start', { limitMs: PRE_RESPONSE_DEADLINE_MS });
|
|
1586
|
+
const waitPolicy = {};
|
|
1605
1587
|
const selectedCredentials = new Set();
|
|
1606
|
-
const
|
|
1588
|
+
const selectedProjectIds = new Set();
|
|
1589
|
+
const pending = deadline
|
|
1590
|
+
.wait(() => execute(input, { ...init, signal: deadline.signal }, requestOptions ?? {}, selectedCredentials, selectedProjectIds, deadline, waitPolicy))
|
|
1591
|
+
.catch((error) => {
|
|
1592
|
+
cancellation.signal.throwIfAborted();
|
|
1593
|
+
if (error instanceof PreResponseTimeoutError) {
|
|
1594
|
+
log.debug('pre-response-timeout', { reason: error.reason });
|
|
1595
|
+
return waitPolicy.refusal?.() ?? preResponseTimeoutResponse();
|
|
1596
|
+
}
|
|
1597
|
+
throw error;
|
|
1598
|
+
})
|
|
1607
1599
|
.then(async (response) => {
|
|
1600
|
+
// Retain caller cancellation over the accepted response body;
|
|
1601
|
+
// only the pre-response timer ends at accepted headers.
|
|
1602
|
+
deadline.acceptTerminalResponse();
|
|
1608
1603
|
// Overflow classification read a clone to EOF. Reuse that text
|
|
1609
1604
|
// for redaction; safe diagnostics retain the original unread response.
|
|
1610
1605
|
if (bufferedOverflow.has(response)) {
|
|
1606
|
+
deadline.dispose();
|
|
1611
1607
|
cancellation.release();
|
|
1612
|
-
return redactCredentialResponse(response, [...selectedCredentials], bufferedOverflow.get(response));
|
|
1608
|
+
return redactCredentialResponse(response, [...selectedCredentials], bufferedOverflow.get(response), [...selectedProjectIds]);
|
|
1613
1609
|
}
|
|
1614
1610
|
const retained = await retainResponseLifetime(response, cancellation);
|
|
1615
1611
|
inFlight.add(retained.settled);
|
|
1616
1612
|
void retained.settled.then(() => inFlight.delete(retained.settled));
|
|
1617
|
-
|
|
1613
|
+
void retained.settled.then(() => deadline.dispose());
|
|
1614
|
+
return redactCredentialResponse(preserveResponseMetadata(retained.response, response), [...selectedCredentials], undefined, [...selectedProjectIds]);
|
|
1618
1615
|
}, (error) => {
|
|
1616
|
+
deadline.dispose();
|
|
1619
1617
|
cancellation.release();
|
|
1620
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
1618
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
1621
1619
|
})
|
|
1622
1620
|
.catch((error) => {
|
|
1621
|
+
deadline.dispose();
|
|
1623
1622
|
cancellation.release();
|
|
1624
|
-
throw redactCredentialError(error, [...selectedCredentials]);
|
|
1623
|
+
throw redactCredentialError(error, [...selectedCredentials], [...selectedProjectIds]);
|
|
1625
1624
|
});
|
|
1626
1625
|
inFlight.add(pending);
|
|
1627
1626
|
void pending.then(() => inFlight.delete(pending), () => inFlight.delete(pending));
|