@cortexkit/opencode-antigravity-auth 2.2.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +95 -89
- package/dist/cli.js +18469 -810
- package/dist/cli.js.map +4 -4
- package/dist/cli.meta.json +4079 -0
- package/dist/index.js +40914 -16441
- package/dist/index.js.map +4 -4
- package/dist/index.meta.json +6949 -0
- package/dist/server.js +50948 -0
- package/dist/server.js.map +7 -0
- package/dist/server.meta.json +7284 -0
- package/dist/src/cli.d.ts +46 -1
- package/dist/src/cli.d.ts.map +1 -1
- package/dist/src/cli.js +207 -2
- package/dist/src/cli.js.map +1 -1
- package/dist/src/common-auth-embedded/NOTICE.txt +21 -0
- package/dist/src/common-auth-embedded/auth-menu/accounts.d.ts +97 -0
- package/dist/src/common-auth-embedded/auth-menu/accounts.js +387 -0
- package/dist/src/common-auth-embedded/auth-menu/ansi.d.ts +26 -0
- package/dist/src/common-auth-embedded/auth-menu/ansi.js +98 -0
- package/dist/src/common-auth-embedded/auth-menu/confirm.d.ts +7 -0
- package/dist/src/common-auth-embedded/auth-menu/confirm.js +21 -0
- package/dist/src/common-auth-embedded/auth-menu/doctor.d.ts +52 -0
- package/dist/src/common-auth-embedded/auth-menu/doctor.js +81 -0
- package/dist/src/common-auth-embedded/auth-menu/index.d.ts +17 -0
- package/dist/src/common-auth-embedded/auth-menu/index.js +12 -0
- package/dist/src/common-auth-embedded/auth-menu/login.d.ts +55 -0
- package/dist/src/common-auth-embedded/auth-menu/login.js +83 -0
- package/dist/src/common-auth-embedded/auth-menu/menu.d.ts +59 -0
- package/dist/src/common-auth-embedded/auth-menu/menu.js +73 -0
- package/dist/src/common-auth-embedded/auth-menu/opencode-v1.d.ts +49 -0
- package/dist/src/common-auth-embedded/auth-menu/opencode-v1.js +47 -0
- package/dist/src/common-auth-embedded/auth-menu/select.d.ts +21 -0
- package/dist/src/common-auth-embedded/auth-menu/select.js +159 -0
- package/dist/src/common-auth-embedded/auth-menu/terminal.d.ts +43 -0
- package/dist/src/common-auth-embedded/auth-menu/terminal.js +19 -0
- package/dist/src/common-auth-embedded/claustrum/consumer.d.ts +102 -0
- package/dist/src/common-auth-embedded/claustrum/consumer.js +298 -0
- package/dist/src/common-auth-embedded/claustrum/custody.d.ts +175 -0
- package/dist/src/common-auth-embedded/claustrum/custody.js +354 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.d.ts +158 -0
- package/dist/src/common-auth-embedded/claustrum/enrollment.js +759 -0
- package/dist/src/common-auth-embedded/claustrum/errors.d.ts +16 -0
- package/dist/src/common-auth-embedded/claustrum/errors.js +8 -0
- package/dist/src/common-auth-embedded/claustrum/host-slot.d.ts +39 -0
- package/dist/src/common-auth-embedded/claustrum/host-slot.js +72 -0
- package/dist/src/common-auth-embedded/claustrum/index.d.ts +18 -0
- package/dist/src/common-auth-embedded/claustrum/index.js +22 -0
- package/dist/src/common-auth-embedded/claustrum/interlock.d.ts +27 -0
- package/dist/src/common-auth-embedded/claustrum/interlock.js +29 -0
- package/dist/src/common-auth-embedded/claustrum/roster.d.ts +208 -0
- package/dist/src/common-auth-embedded/claustrum/roster.js +536 -0
- package/dist/src/common-auth-embedded/commands/builtins.d.ts +71 -0
- package/dist/src/common-auth-embedded/commands/builtins.js +534 -0
- package/dist/src/common-auth-embedded/commands/index.d.ts +10 -0
- package/dist/src/common-auth-embedded/commands/index.js +5 -0
- package/dist/src/common-auth-embedded/commands/menu.d.ts +61 -0
- package/dist/src/common-auth-embedded/commands/menu.js +300 -0
- package/dist/src/common-auth-embedded/commands/model.d.ts +238 -0
- package/dist/src/common-auth-embedded/commands/model.js +16 -0
- package/dist/src/common-auth-embedded/commands/pi.d.ts +23 -0
- package/dist/src/common-auth-embedded/commands/pi.js +206 -0
- package/dist/src/common-auth-embedded/commands/seam.d.ts +72 -0
- package/dist/src/common-auth-embedded/commands/seam.js +301 -0
- package/dist/src/common-auth-embedded/fs/atomic-write.d.ts +20 -0
- package/dist/src/common-auth-embedded/fs/atomic-write.js +80 -0
- package/dist/src/common-auth-embedded/fs/index.d.ts +7 -0
- package/dist/src/common-auth-embedded/fs/index.js +6 -0
- package/dist/src/common-auth-embedded/fs/lock-constants.d.ts +14 -0
- package/dist/src/common-auth-embedded/fs/lock-constants.js +14 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.d.ts +33 -0
- package/dist/src/common-auth-embedded/fs/refresh-file-lock.js +501 -0
- package/dist/src/common-auth-embedded/fs/with-lock.d.ts +33 -0
- package/dist/src/common-auth-embedded/fs/with-lock.js +48 -0
- package/dist/src/common-auth-embedded/logger/capture-sink.d.ts +14 -0
- package/dist/src/common-auth-embedded/logger/capture-sink.js +13 -0
- package/dist/src/common-auth-embedded/logger/engine.d.ts +100 -0
- package/dist/src/common-auth-embedded/logger/engine.js +246 -0
- package/dist/src/common-auth-embedded/logger/index.d.ts +6 -0
- package/dist/src/common-auth-embedded/logger/index.js +3 -0
- package/dist/src/common-auth-embedded/logger/redact.d.ts +11 -0
- package/dist/src/common-auth-embedded/logger/redact.js +83 -0
- package/dist/src/common-auth-embedded/opencode2/errors.d.ts +25 -0
- package/dist/src/common-auth-embedded/opencode2/errors.js +15 -0
- package/dist/src/common-auth-embedded/opencode2/index.d.ts +8 -0
- package/dist/src/common-auth-embedded/opencode2/index.js +4 -0
- package/dist/src/common-auth-embedded/opencode2/install.d.ts +55 -0
- package/dist/src/common-auth-embedded/opencode2/install.js +886 -0
- package/dist/src/common-auth-embedded/opencode2/integration.d.ts +112 -0
- package/dist/src/common-auth-embedded/opencode2/integration.js +143 -0
- package/dist/src/common-auth-embedded/opencode2/sse.d.ts +12 -0
- package/dist/src/common-auth-embedded/opencode2/sse.js +60 -0
- package/dist/src/common-auth-embedded/opencode2/types.d.ts +413 -0
- package/dist/src/common-auth-embedded/pi-slot/index.d.ts +3 -0
- package/dist/src/common-auth-embedded/pi-slot/index.js +2 -0
- package/dist/src/common-auth-embedded/pi-slot/lock.js +212 -0
- package/dist/src/common-auth-embedded/pi-slot/slot.d.ts +49 -0
- package/dist/src/common-auth-embedded/pi-slot/slot.js +383 -0
- package/dist/src/common-auth-embedded/quota/codec.d.ts +11 -0
- package/dist/src/common-auth-embedded/quota/codec.js +12 -0
- package/dist/src/common-auth-embedded/quota/format.d.ts +46 -0
- package/dist/src/common-auth-embedded/quota/format.js +138 -0
- package/dist/src/common-auth-embedded/quota/index.d.ts +10 -0
- package/dist/src/common-auth-embedded/quota/index.js +5 -0
- package/dist/src/common-auth-embedded/quota/map.d.ts +63 -0
- package/dist/src/common-auth-embedded/quota/map.js +105 -0
- package/dist/src/common-auth-embedded/quota/merge.d.ts +48 -0
- package/dist/src/common-auth-embedded/quota/merge.js +162 -0
- package/dist/src/common-auth-embedded/quota/projection.d.ts +64 -0
- package/dist/src/common-auth-embedded/quota/projection.js +134 -0
- package/dist/src/common-auth-embedded/routing/admission.d.ts +93 -0
- package/dist/src/common-auth-embedded/routing/admission.js +142 -0
- package/dist/src/common-auth-embedded/routing/index.d.ts +8 -0
- package/dist/src/common-auth-embedded/routing/index.js +4 -0
- package/dist/src/common-auth-embedded/routing/ordered.d.ts +47 -0
- package/dist/src/common-auth-embedded/routing/ordered.js +58 -0
- package/dist/src/common-auth-embedded/routing/pins.d.ts +22 -0
- package/dist/src/common-auth-embedded/routing/pins.js +34 -0
- package/dist/src/common-auth-embedded/routing/sticky.d.ts +158 -0
- package/dist/src/common-auth-embedded/routing/sticky.js +339 -0
- package/dist/src/common-auth-embedded/rpc/client.d.ts +3 -0
- package/dist/src/common-auth-embedded/rpc/client.js +2 -0
- package/dist/src/common-auth-embedded/rpc/index.d.ts +10 -0
- package/dist/src/common-auth-embedded/rpc/index.js +5 -0
- package/dist/src/common-auth-embedded/rpc/notifications.d.ts +73 -0
- package/dist/src/common-auth-embedded/rpc/notifications.js +100 -0
- package/dist/src/common-auth-embedded/rpc/port-file.d.ts +33 -0
- package/dist/src/common-auth-embedded/rpc/port-file.js +217 -0
- package/dist/src/common-auth-embedded/rpc/rpc-client.d.ts +30 -0
- package/dist/src/common-auth-embedded/rpc/rpc-client.js +253 -0
- package/dist/src/common-auth-embedded/rpc/rpc-server.d.ts +58 -0
- package/dist/src/common-auth-embedded/rpc/rpc-server.js +311 -0
- package/dist/src/common-auth-embedded/rpc/server-registry.d.ts +11 -0
- package/dist/src/common-auth-embedded/rpc/server-registry.js +47 -0
- package/dist/src/common-auth-embedded/source-output.json +1326 -0
- package/dist/src/common-auth-embedded/store/attribution.d.ts +28 -0
- package/dist/src/common-auth-embedded/store/attribution.js +60 -0
- package/dist/src/common-auth-embedded/store/errors.d.ts +55 -0
- package/dist/src/common-auth-embedded/store/errors.js +38 -0
- package/dist/src/common-auth-embedded/store/hooks.d.ts +12 -0
- package/dist/src/common-auth-embedded/store/hooks.js +34 -0
- package/dist/src/common-auth-embedded/store/identity.d.ts +39 -0
- package/dist/src/common-auth-embedded/store/identity.js +79 -0
- package/dist/src/common-auth-embedded/store/index.d.ts +21 -0
- package/dist/src/common-auth-embedded/store/index.js +7 -0
- package/dist/src/common-auth-embedded/store/mutate.d.ts +189 -0
- package/dist/src/common-auth-embedded/store/mutate.js +500 -0
- package/dist/src/common-auth-embedded/store/pool.d.ts +196 -0
- package/dist/src/common-auth-embedded/store/pool.js +120 -0
- package/dist/src/common-auth-embedded/store/provider-state.d.ts +131 -0
- package/dist/src/common-auth-embedded/store/provider-state.js +226 -0
- package/dist/src/common-auth-embedded/store/publication.d.ts +47 -0
- package/dist/src/common-auth-embedded/store/publication.js +304 -0
- package/dist/src/common-auth-embedded/store/pull.d.ts +36 -0
- package/dist/src/common-auth-embedded/store/pull.js +143 -0
- package/dist/src/common-auth-embedded/store/refresh-lock.d.ts +63 -0
- package/dist/src/common-auth-embedded/store/refresh-lock.js +136 -0
- package/dist/src/common-auth-embedded/store/refresh.d.ts +72 -0
- package/dist/src/common-auth-embedded/store/refresh.js +225 -0
- package/dist/src/common-auth-embedded/store/reserved.js +13 -0
- package/dist/src/common-auth-embedded/store/rows.d.ts +313 -0
- package/dist/src/common-auth-embedded/store/rows.js +1258 -0
- package/dist/src/common-auth-embedded/store/runtime.d.ts +36 -0
- package/dist/src/common-auth-embedded/store/runtime.js +68 -0
- package/dist/src/common-auth-embedded/store/schema.d.ts +443 -0
- package/dist/src/common-auth-embedded/store/schema.js +754 -0
- package/dist/src/common-auth-embedded/store/settings.d.ts +63 -0
- package/dist/src/common-auth-embedded/store/settings.js +120 -0
- package/dist/src/common-auth-embedded/store/torn.d.ts +78 -0
- package/dist/src/common-auth-embedded/store/torn.js +294 -0
- package/dist/src/common-auth-embedded/tui/index.d.ts +8 -0
- package/dist/src/common-auth-embedded/tui/index.js +21 -0
- package/dist/src/common-auth-embedded/util/any-signal.js +42 -0
- package/dist/src/constants.d.ts +1 -0
- package/dist/src/constants.d.ts.map +1 -1
- package/dist/src/constants.js +4 -0
- package/dist/src/constants.js.map +1 -1
- package/dist/src/ga/proxy-guard.d.ts +120 -0
- package/dist/src/ga/proxy-guard.d.ts.map +1 -0
- package/dist/src/ga/proxy-guard.js +269 -0
- package/dist/src/ga/proxy-guard.js.map +1 -0
- package/dist/src/ga/rpc/protocol.d.ts +504 -0
- package/dist/src/ga/rpc/protocol.d.ts.map +1 -0
- package/dist/src/ga/rpc/protocol.js +1278 -0
- package/dist/src/ga/rpc/protocol.js.map +1 -0
- package/dist/src/ga/server/auth.d.ts +9 -0
- package/dist/src/ga/server/auth.d.ts.map +1 -0
- package/dist/src/ga/server/auth.js +37 -0
- package/dist/src/ga/server/auth.js.map +1 -0
- package/dist/src/ga/server/index.d.ts +576 -0
- package/dist/src/ga/server/index.d.ts.map +1 -0
- package/dist/src/ga/server/index.js +1012 -0
- package/dist/src/ga/server/index.js.map +1 -0
- package/dist/src/ga/tui/host-ga.d.ts +350 -0
- package/dist/src/ga/tui/host-ga.d.ts.map +1 -0
- package/dist/src/ga/tui/host-ga.js +1242 -0
- package/dist/src/ga/tui/host-ga.js.map +1 -0
- package/dist/src/logging/provider-key-policy.d.ts +9 -0
- package/dist/src/logging/provider-key-policy.d.ts.map +1 -0
- package/dist/src/logging/provider-key-policy.js +11 -0
- package/dist/src/logging/provider-key-policy.js.map +1 -0
- package/dist/src/plugin/account-access.d.ts +130 -15
- package/dist/src/plugin/account-access.d.ts.map +1 -1
- package/dist/src/plugin/account-access.js +331 -129
- package/dist/src/plugin/account-access.js.map +1 -1
- package/dist/src/plugin/account-blocks.d.ts +102 -0
- package/dist/src/plugin/account-blocks.d.ts.map +1 -0
- package/dist/src/plugin/account-blocks.js +196 -0
- package/dist/src/plugin/account-blocks.js.map +1 -0
- package/dist/src/plugin/accounts.d.ts +85 -1
- package/dist/src/plugin/accounts.d.ts.map +1 -1
- package/dist/src/plugin/accounts.js +127 -3
- package/dist/src/plugin/accounts.js.map +1 -1
- package/dist/src/plugin/auth-loader.d.ts +69 -5
- package/dist/src/plugin/auth-loader.d.ts.map +1 -1
- package/dist/src/plugin/auth-loader.js +355 -52
- package/dist/src/plugin/auth-loader.js.map +1 -1
- package/dist/src/plugin/background-quota-refresh.d.ts +54 -8
- package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -1
- package/dist/src/plugin/background-quota-refresh.js +81 -24
- package/dist/src/plugin/background-quota-refresh.js.map +1 -1
- package/dist/src/plugin/cache/index.d.ts +1 -1
- package/dist/src/plugin/cache/index.d.ts.map +1 -1
- package/dist/src/plugin/cache/index.js +1 -1
- package/dist/src/plugin/cache/index.js.map +1 -1
- package/dist/src/plugin/cache/signature-cache.d.ts +55 -10
- package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/src/plugin/cache/signature-cache.js +100 -41
- package/dist/src/plugin/cache/signature-cache.js.map +1 -1
- package/dist/src/plugin/cache.d.ts +80 -16
- package/dist/src/plugin/cache.d.ts.map +1 -1
- package/dist/src/plugin/cache.js +339 -200
- package/dist/src/plugin/cache.js.map +1 -1
- package/dist/src/plugin/catalog.d.ts +4 -18
- package/dist/src/plugin/catalog.d.ts.map +1 -1
- package/dist/src/plugin/catalog.js +11 -41
- package/dist/src/plugin/catalog.js.map +1 -1
- package/dist/src/plugin/command-apply.d.ts +58 -0
- package/dist/src/plugin/command-apply.d.ts.map +1 -0
- package/dist/src/plugin/command-apply.js +168 -0
- package/dist/src/plugin/command-apply.js.map +1 -0
- package/dist/src/plugin/command-data.d.ts +1 -0
- package/dist/src/plugin/command-data.d.ts.map +1 -1
- package/dist/src/plugin/command-data.js +2 -0
- package/dist/src/plugin/command-data.js.map +1 -1
- package/dist/src/plugin/commands.d.ts +142 -132
- package/dist/src/plugin/commands.d.ts.map +1 -1
- package/dist/src/plugin/commands.js +214 -686
- package/dist/src/plugin/commands.js.map +1 -1
- package/dist/src/plugin/config/index.d.ts +1 -1
- package/dist/src/plugin/config/index.d.ts.map +1 -1
- package/dist/src/plugin/config/index.js +1 -1
- package/dist/src/plugin/config/index.js.map +1 -1
- package/dist/src/plugin/config/loader.d.ts +37 -1
- package/dist/src/plugin/config/loader.d.ts.map +1 -1
- package/dist/src/plugin/config/loader.js +64 -9
- package/dist/src/plugin/config/loader.js.map +1 -1
- package/dist/src/plugin/config/operator-settings-schema.d.ts +2 -2
- package/dist/src/plugin/config/schema.d.ts +2 -2
- package/dist/src/plugin/config/writer.d.ts +7 -0
- package/dist/src/plugin/config/writer.d.ts.map +1 -1
- package/dist/src/plugin/config/writer.js +10 -1
- package/dist/src/plugin/config/writer.js.map +1 -1
- package/dist/src/plugin/debug.d.ts +72 -29
- package/dist/src/plugin/debug.d.ts.map +1 -1
- package/dist/src/plugin/debug.js +353 -239
- package/dist/src/plugin/debug.js.map +1 -1
- package/dist/src/plugin/fetch/retry-state.d.ts +1 -1
- package/dist/src/plugin/fetch/retry-state.d.ts.map +1 -1
- package/dist/src/plugin/fetch/retry-state.js.map +1 -1
- package/dist/src/plugin/fetch-interceptor.d.ts +66 -11
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -1
- package/dist/src/plugin/fetch-interceptor.js +228 -1352
- package/dist/src/plugin/fetch-interceptor.js.map +1 -1
- package/dist/src/plugin/fetch-routing.d.ts +7 -2
- package/dist/src/plugin/fetch-routing.d.ts.map +1 -1
- package/dist/src/plugin/fetch-routing.js +7 -4
- package/dist/src/plugin/fetch-routing.js.map +1 -1
- package/dist/src/plugin/ga-location-services.d.ts +389 -0
- package/dist/src/plugin/ga-location-services.d.ts.map +1 -0
- package/dist/src/plugin/ga-location-services.js +1838 -0
- package/dist/src/plugin/ga-location-services.js.map +1 -0
- package/dist/src/plugin/gemini-dump.d.ts +37 -12
- package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
- package/dist/src/plugin/gemini-dump.js +42 -21
- package/dist/src/plugin/gemini-dump.js.map +1 -1
- package/dist/src/plugin/google-search-tool.d.ts +2 -1
- package/dist/src/plugin/google-search-tool.d.ts.map +1 -1
- package/dist/src/plugin/google-search-tool.js +4 -1
- package/dist/src/plugin/google-search-tool.js.map +1 -1
- package/dist/src/plugin/index.d.ts.map +1 -1
- package/dist/src/plugin/index.js +505 -141
- package/dist/src/plugin/index.js.map +1 -1
- package/dist/src/plugin/killswitch.d.ts +1 -2
- package/dist/src/plugin/killswitch.d.ts.map +1 -1
- package/dist/src/plugin/lifecycle.d.ts +24 -1
- package/dist/src/plugin/lifecycle.d.ts.map +1 -1
- package/dist/src/plugin/lifecycle.js +95 -8
- package/dist/src/plugin/lifecycle.js.map +1 -1
- package/dist/src/plugin/logger.d.ts +61 -10
- package/dist/src/plugin/logger.d.ts.map +1 -1
- package/dist/src/plugin/logger.js +134 -63
- package/dist/src/plugin/logger.js.map +1 -1
- package/dist/src/plugin/neutral-types.d.ts +42 -0
- package/dist/src/plugin/neutral-types.d.ts.map +1 -0
- package/dist/src/plugin/neutral-types.js +12 -0
- package/dist/src/plugin/neutral-types.js.map +1 -0
- package/dist/src/plugin/oauth-methods.d.ts +2 -1
- package/dist/src/plugin/oauth-methods.d.ts.map +1 -1
- package/dist/src/plugin/oauth-methods.js +173 -88
- package/dist/src/plugin/oauth-methods.js.map +1 -1
- package/dist/src/plugin/operator-settings.d.ts +34 -0
- package/dist/src/plugin/operator-settings.d.ts.map +1 -1
- package/dist/src/plugin/operator-settings.js +105 -2
- package/dist/src/plugin/operator-settings.js.map +1 -1
- package/dist/src/plugin/persist-account-pool.d.ts +63 -2
- package/dist/src/plugin/persist-account-pool.d.ts.map +1 -1
- package/dist/src/plugin/persist-account-pool.js +125 -2
- package/dist/src/plugin/persist-account-pool.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +335 -35
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +825 -95
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/refresh-queue.d.ts +35 -5
- package/dist/src/plugin/refresh-queue.d.ts.map +1 -1
- package/dist/src/plugin/refresh-queue.js +50 -16
- package/dist/src/plugin/refresh-queue.js.map +1 -1
- package/dist/src/plugin/request-helpers.d.ts +30 -5
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +82 -17
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/request.d.ts +63 -15
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +190 -60
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/session-context.d.ts.map +1 -1
- package/dist/src/plugin/session-context.js +5 -2
- package/dist/src/plugin/session-context.js.map +1 -1
- package/dist/src/plugin/shared/local-grant.d.ts +26 -0
- package/dist/src/plugin/shared/local-grant.d.ts.map +1 -0
- package/dist/src/plugin/shared/local-grant.js +19 -0
- package/dist/src/plugin/shared/local-grant.js.map +1 -0
- package/dist/src/plugin/shared/request-cancellation.d.ts +12 -0
- package/dist/src/plugin/shared/request-cancellation.d.ts.map +1 -0
- package/dist/src/plugin/shared/request-cancellation.js +118 -0
- package/dist/src/plugin/shared/request-cancellation.js.map +1 -0
- package/dist/src/plugin/shared/request-services.d.ts +375 -0
- package/dist/src/plugin/shared/request-services.d.ts.map +1 -0
- package/dist/src/plugin/shared/request-services.js +1743 -0
- package/dist/src/plugin/shared/request-services.js.map +1 -0
- package/dist/src/plugin/shared/runtime.d.ts +217 -0
- package/dist/src/plugin/shared/runtime.d.ts.map +1 -0
- package/dist/src/plugin/shared/runtime.js +345 -0
- package/dist/src/plugin/shared/runtime.js.map +1 -0
- package/dist/src/plugin/shared/source-sidebar.d.ts +15 -0
- package/dist/src/plugin/shared/source-sidebar.d.ts.map +1 -0
- package/dist/src/plugin/shared/source-sidebar.js +41 -0
- package/dist/src/plugin/shared/source-sidebar.js.map +1 -0
- package/dist/src/plugin/shared/vault-menu.d.ts +5 -0
- package/dist/src/plugin/shared/vault-menu.d.ts.map +1 -0
- package/dist/src/plugin/shared/vault-menu.js +49 -0
- package/dist/src/plugin/shared/vault-menu.js.map +1 -0
- package/dist/src/plugin/shared/vault-request-credentials.d.ts +168 -0
- package/dist/src/plugin/shared/vault-request-credentials.d.ts.map +1 -0
- package/dist/src/plugin/shared/vault-request-credentials.js +485 -0
- package/dist/src/plugin/shared/vault-request-credentials.js.map +1 -0
- package/dist/src/plugin/storage.d.ts +127 -1
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +188 -3
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/token.d.ts +23 -1
- package/dist/src/plugin/token.d.ts.map +1 -1
- package/dist/src/plugin/token.js +117 -58
- package/dist/src/plugin/token.js.map +1 -1
- package/dist/src/plugin/ui/quota-status.d.ts +1 -10
- package/dist/src/plugin/ui/quota-status.d.ts.map +1 -1
- package/dist/src/plugin/ui/quota-status.js +6 -42
- package/dist/src/plugin/ui/quota-status.js.map +1 -1
- package/dist/src/plugin/vault-activation.d.ts +11 -0
- package/dist/src/plugin/vault-activation.d.ts.map +1 -0
- package/dist/src/plugin/vault-activation.js +53 -0
- package/dist/src/plugin/vault-activation.js.map +1 -0
- package/dist/src/plugin/vault-custody.d.ts +131 -0
- package/dist/src/plugin/vault-custody.d.ts.map +1 -0
- package/dist/src/plugin/vault-custody.js +381 -0
- package/dist/src/plugin/vault-custody.js.map +1 -0
- package/dist/src/quota-presentation.d.ts +18 -0
- package/dist/src/quota-presentation.d.ts.map +1 -0
- package/dist/src/quota-presentation.js +58 -0
- package/dist/src/quota-presentation.js.map +1 -0
- package/dist/src/rpc/notifications.d.ts +2 -2
- package/dist/src/rpc/notifications.d.ts.map +1 -1
- package/dist/src/rpc/notifications.js +1 -1
- package/dist/src/rpc/notifications.js.map +1 -1
- package/dist/src/rpc/port-file.d.ts +2 -12
- package/dist/src/rpc/port-file.d.ts.map +1 -1
- package/dist/src/rpc/port-file.js +5 -107
- package/dist/src/rpc/port-file.js.map +1 -1
- package/dist/src/rpc/protocol.d.ts +47 -16
- package/dist/src/rpc/protocol.d.ts.map +1 -1
- package/dist/src/rpc/rpc-client.d.ts +27 -3
- package/dist/src/rpc/rpc-client.d.ts.map +1 -1
- package/dist/src/rpc/rpc-client.js +55 -45
- package/dist/src/rpc/rpc-client.js.map +1 -1
- package/dist/src/rpc/rpc-server.d.ts +13 -2
- package/dist/src/rpc/rpc-server.d.ts.map +1 -1
- package/dist/src/rpc/rpc-server.js +38 -212
- package/dist/src/rpc/rpc-server.js.map +1 -1
- package/dist/src/server.d.ts +30 -0
- package/dist/src/server.d.ts.map +1 -0
- package/dist/src/server.js +29 -0
- package/dist/src/server.js.map +1 -0
- package/dist/src/sidebar-projection.d.ts +102 -0
- package/dist/src/sidebar-projection.d.ts.map +1 -0
- package/dist/src/sidebar-projection.js +146 -0
- package/dist/src/sidebar-projection.js.map +1 -0
- package/dist/src/sidebar-state.d.ts +13 -5
- package/dist/src/sidebar-state.d.ts.map +1 -1
- package/dist/src/sidebar-state.js +49 -16
- package/dist/src/sidebar-state.js.map +1 -1
- package/dist/src/tui/command-dialogs.d.ts +58 -52
- package/dist/src/tui/command-dialogs.d.ts.map +1 -1
- package/dist/src/tui/command-dialogs.js +379 -571
- package/dist/src/tui/command-dialogs.js.map +1 -1
- package/dist/src/tui/file-logger.d.ts +2 -3
- package/dist/src/tui/file-logger.d.ts.map +1 -1
- package/dist/src/tui/file-logger.js +21 -7
- package/dist/src/tui/file-logger.js.map +1 -1
- package/dist/src/tui/host-api.d.ts +196 -0
- package/dist/src/tui/host-api.d.ts.map +1 -0
- package/dist/src/tui/host-api.js +357 -0
- package/dist/src/tui/host-api.js.map +1 -0
- package/dist/src/tui/host-v1.d.ts +60 -0
- package/dist/src/tui/host-v1.d.ts.map +1 -0
- package/dist/src/tui/host-v1.js +147 -0
- package/dist/src/tui/host-v1.js.map +1 -0
- package/dist/src/tui/vault-setup.d.ts +98 -0
- package/dist/src/tui/vault-setup.d.ts.map +1 -0
- package/dist/src/tui/vault-setup.js +198 -0
- package/dist/src/tui/vault-setup.js.map +1 -0
- package/dist/src/tui.d.ts +4 -11
- package/dist/src/tui.d.ts.map +1 -1
- package/dist/src/tui.js +33 -75
- package/dist/src/tui.js.map +1 -1
- package/dist/tui-build-map.json +380 -0
- package/dist/tui-ga-build-map.json +187 -0
- package/dist/types/src/antigravity/oauth.d.ts +2 -0
- package/dist/types/src/antigravity/oauth.d.ts.map +1 -0
- package/dist/types/src/cli.d.ts +66 -0
- package/dist/types/src/cli.d.ts.map +1 -0
- package/dist/types/src/common-auth-embedded/commands/builtins.d.ts +71 -0
- package/dist/types/src/common-auth-embedded/commands/index.d.ts +10 -0
- package/dist/types/src/common-auth-embedded/commands/menu.d.ts +61 -0
- package/dist/types/src/common-auth-embedded/commands/model.d.ts +238 -0
- package/dist/types/src/common-auth-embedded/commands/pi.d.ts +23 -0
- package/dist/types/src/common-auth-embedded/commands/seam.d.ts +72 -0
- package/dist/types/src/common-auth-embedded/fs/refresh-file-lock.d.ts +33 -0
- package/dist/types/src/common-auth-embedded/logger/capture-sink.d.ts +14 -0
- package/dist/types/src/common-auth-embedded/logger/engine.d.ts +100 -0
- package/dist/types/src/common-auth-embedded/logger/index.d.ts +6 -0
- package/dist/types/src/common-auth-embedded/logger/redact.d.ts +11 -0
- package/dist/types/src/common-auth-embedded/quota/codec.d.ts +11 -0
- package/dist/types/src/common-auth-embedded/quota/format.d.ts +46 -0
- package/dist/types/src/common-auth-embedded/quota/index.d.ts +10 -0
- package/dist/types/src/common-auth-embedded/quota/map.d.ts +63 -0
- package/dist/types/src/common-auth-embedded/quota/merge.d.ts +48 -0
- package/dist/types/src/common-auth-embedded/quota/projection.d.ts +64 -0
- package/dist/types/src/common-auth-embedded/store/attribution.d.ts +28 -0
- package/dist/types/src/common-auth-embedded/store/errors.d.ts +55 -0
- package/dist/types/src/common-auth-embedded/store/hooks.d.ts +12 -0
- package/dist/types/src/common-auth-embedded/store/identity.d.ts +39 -0
- package/dist/types/src/common-auth-embedded/store/index.d.ts +21 -0
- package/dist/types/src/common-auth-embedded/store/mutate.d.ts +189 -0
- package/dist/types/src/common-auth-embedded/store/pool.d.ts +196 -0
- package/dist/types/src/common-auth-embedded/store/provider-state.d.ts +131 -0
- package/dist/types/src/common-auth-embedded/store/publication.d.ts +47 -0
- package/dist/types/src/common-auth-embedded/store/pull.d.ts +36 -0
- package/dist/types/src/common-auth-embedded/store/refresh-lock.d.ts +63 -0
- package/dist/types/src/common-auth-embedded/store/refresh.d.ts +72 -0
- package/dist/types/src/common-auth-embedded/store/rows.d.ts +313 -0
- package/dist/types/src/common-auth-embedded/store/runtime.d.ts +36 -0
- package/dist/types/src/common-auth-embedded/store/schema.d.ts +443 -0
- package/dist/types/src/common-auth-embedded/store/settings.d.ts +63 -0
- package/dist/types/src/common-auth-embedded/store/torn.d.ts +78 -0
- package/dist/types/src/constants.d.ts +3 -0
- package/dist/types/src/constants.d.ts.map +1 -0
- package/dist/types/src/ga/proxy-guard.d.ts +120 -0
- package/dist/types/src/ga/proxy-guard.d.ts.map +1 -0
- package/dist/types/src/ga/rpc/protocol.d.ts +504 -0
- package/dist/types/src/ga/rpc/protocol.d.ts.map +1 -0
- package/dist/types/src/ga/server/auth.d.ts +9 -0
- package/dist/types/src/ga/server/auth.d.ts.map +1 -0
- package/dist/types/src/ga/server/index.d.ts +576 -0
- package/dist/types/src/ga/server/index.d.ts.map +1 -0
- package/dist/types/src/hooks/auto-update-checker/cache.d.ts +3 -0
- package/dist/types/src/hooks/auto-update-checker/cache.d.ts.map +1 -0
- package/dist/types/src/hooks/auto-update-checker/checker.d.ts +16 -0
- package/dist/types/src/hooks/auto-update-checker/checker.d.ts.map +1 -0
- package/dist/types/src/hooks/auto-update-checker/constants.d.ts +9 -0
- package/dist/types/src/hooks/auto-update-checker/constants.d.ts.map +1 -0
- package/dist/types/src/hooks/auto-update-checker/index.d.ts +34 -0
- package/dist/types/src/hooks/auto-update-checker/index.d.ts.map +1 -0
- package/dist/types/src/hooks/auto-update-checker/logging.d.ts +3 -0
- package/dist/types/src/hooks/auto-update-checker/logging.d.ts.map +1 -0
- package/dist/types/src/hooks/auto-update-checker/types.d.ts +25 -0
- package/dist/types/src/hooks/auto-update-checker/types.d.ts.map +1 -0
- package/dist/types/src/logging/provider-key-policy.d.ts +9 -0
- package/dist/types/src/logging/provider-key-policy.d.ts.map +1 -0
- package/dist/types/src/plugin/account-access.d.ts +214 -0
- package/dist/types/src/plugin/account-access.d.ts.map +1 -0
- package/dist/types/src/plugin/account-blocks.d.ts +102 -0
- package/dist/types/src/plugin/account-blocks.d.ts.map +1 -0
- package/dist/types/src/plugin/account-command-oauth.d.ts +34 -0
- package/dist/types/src/plugin/account-command-oauth.d.ts.map +1 -0
- package/dist/types/src/plugin/accounts.d.ts +94 -0
- package/dist/types/src/plugin/accounts.d.ts.map +1 -0
- package/dist/types/src/plugin/agy-request-metadata.d.ts +2 -0
- package/dist/types/src/plugin/agy-request-metadata.d.ts.map +1 -0
- package/dist/types/src/plugin/agy-transport.d.ts +2 -0
- package/dist/types/src/plugin/agy-transport.d.ts.map +1 -0
- package/dist/types/src/plugin/auth-doctor.d.ts +30 -0
- package/dist/types/src/plugin/auth-doctor.d.ts.map +1 -0
- package/dist/types/src/plugin/auth-drift.d.ts +13 -0
- package/dist/types/src/plugin/auth-drift.d.ts.map +1 -0
- package/dist/types/src/plugin/auth-loader.d.ts +114 -0
- package/dist/types/src/plugin/auth-loader.d.ts.map +1 -0
- package/dist/types/src/plugin/auth.d.ts +2 -0
- package/dist/types/src/plugin/auth.d.ts.map +1 -0
- package/dist/types/src/plugin/background-quota-refresh.d.ts +192 -0
- package/dist/types/src/plugin/background-quota-refresh.d.ts.map +1 -0
- package/dist/types/src/plugin/cache/signature-cache.d.ts +156 -0
- package/dist/types/src/plugin/cache/signature-cache.d.ts.map +1 -0
- package/dist/types/src/plugin/cache.d.ts +109 -0
- package/dist/types/src/plugin/cache.d.ts.map +1 -0
- package/dist/types/src/plugin/catalog.d.ts +9 -0
- package/dist/types/src/plugin/catalog.d.ts.map +1 -0
- package/dist/types/src/plugin/cli.d.ts +44 -0
- package/dist/types/src/plugin/cli.d.ts.map +1 -0
- package/dist/types/src/plugin/command-apply.d.ts +58 -0
- package/dist/types/src/plugin/command-apply.d.ts.map +1 -0
- package/dist/types/src/plugin/command-data.d.ts +330 -0
- package/dist/types/src/plugin/command-data.d.ts.map +1 -0
- package/dist/types/src/plugin/commands.d.ts +164 -0
- package/dist/types/src/plugin/commands.d.ts.map +1 -0
- package/dist/types/src/plugin/config/index.d.ts +16 -0
- package/dist/types/src/plugin/config/index.d.ts.map +1 -0
- package/dist/types/src/plugin/config/loader.d.ts +72 -0
- package/dist/types/src/plugin/config/loader.d.ts.map +1 -0
- package/dist/types/src/plugin/config/models.d.ts +3 -0
- package/dist/types/src/plugin/config/models.d.ts.map +1 -0
- package/dist/types/src/plugin/config/operator-settings-schema.d.ts +29 -0
- package/dist/types/src/plugin/config/operator-settings-schema.d.ts.map +1 -0
- package/dist/types/src/plugin/config/schema.d.ts +162 -0
- package/dist/types/src/plugin/config/schema.d.ts.map +1 -0
- package/dist/types/src/plugin/config/updater.d.ts +55 -0
- package/dist/types/src/plugin/config/updater.d.ts.map +1 -0
- package/dist/types/src/plugin/config/writer.d.ts +41 -0
- package/dist/types/src/plugin/config/writer.d.ts.map +1 -0
- package/dist/types/src/plugin/core/streaming/index.d.ts +3 -0
- package/dist/types/src/plugin/core/streaming/index.d.ts.map +1 -0
- package/dist/types/src/plugin/core/streaming/transformer.d.ts +12 -0
- package/dist/types/src/plugin/core/streaming/transformer.d.ts.map +1 -0
- package/dist/types/src/plugin/core/streaming/types.d.ts +34 -0
- package/dist/types/src/plugin/core/streaming/types.d.ts.map +1 -0
- package/dist/types/src/plugin/debug.d.ts +144 -0
- package/dist/types/src/plugin/debug.d.ts.map +1 -0
- package/dist/types/src/plugin/dependencies.d.ts +129 -0
- package/dist/types/src/plugin/dependencies.d.ts.map +1 -0
- package/dist/types/src/plugin/errors.d.ts +55 -0
- package/dist/types/src/plugin/errors.d.ts.map +1 -0
- package/dist/types/src/plugin/event-handler.d.ts +53 -0
- package/dist/types/src/plugin/event-handler.d.ts.map +1 -0
- package/dist/types/src/plugin/fetch/retry-state.d.ts +61 -0
- package/dist/types/src/plugin/fetch/retry-state.d.ts.map +1 -0
- package/dist/types/src/plugin/fetch/warmup.d.ts +30 -0
- package/dist/types/src/plugin/fetch/warmup.d.ts.map +1 -0
- package/dist/types/src/plugin/fetch-interceptor.d.ts +114 -0
- package/dist/types/src/plugin/fetch-interceptor.d.ts.map +1 -0
- package/dist/types/src/plugin/fetch-routing.d.ts +31 -0
- package/dist/types/src/plugin/fetch-routing.d.ts.map +1 -0
- package/dist/types/src/plugin/fingerprint.d.ts +2 -0
- package/dist/types/src/plugin/fingerprint.d.ts.map +1 -0
- package/dist/types/src/plugin/ga-location-services.d.ts +389 -0
- package/dist/types/src/plugin/ga-location-services.d.ts.map +1 -0
- package/dist/types/src/plugin/gemini-dump.d.ts +72 -0
- package/dist/types/src/plugin/gemini-dump.d.ts.map +1 -0
- package/dist/types/src/plugin/google-search-tool.d.ts +10 -0
- package/dist/types/src/plugin/google-search-tool.d.ts.map +1 -0
- package/dist/types/src/plugin/image-saver.d.ts +6 -0
- package/dist/types/src/plugin/image-saver.d.ts.map +1 -0
- package/dist/types/src/plugin/index.d.ts +30 -0
- package/dist/types/src/plugin/index.d.ts.map +1 -0
- package/dist/types/src/plugin/killswitch.d.ts +93 -0
- package/dist/types/src/plugin/killswitch.d.ts.map +1 -0
- package/dist/types/src/plugin/lifecycle.d.ts +63 -0
- package/dist/types/src/plugin/lifecycle.d.ts.map +1 -0
- package/dist/types/src/plugin/logger.d.ts +83 -0
- package/dist/types/src/plugin/logger.d.ts.map +1 -0
- package/dist/types/src/plugin/logging-utils.d.ts +57 -0
- package/dist/types/src/plugin/logging-utils.d.ts.map +1 -0
- package/dist/types/src/plugin/model-registry.d.ts +2 -0
- package/dist/types/src/plugin/model-registry.d.ts.map +1 -0
- package/dist/types/src/plugin/neutral-types.d.ts +42 -0
- package/dist/types/src/plugin/neutral-types.d.ts.map +1 -0
- package/dist/types/src/plugin/oauth-login.d.ts +22 -0
- package/dist/types/src/plugin/oauth-login.d.ts.map +1 -0
- package/dist/types/src/plugin/oauth-methods.d.ts +43 -0
- package/dist/types/src/plugin/oauth-methods.d.ts.map +1 -0
- package/dist/types/src/plugin/operator-settings.d.ts +74 -0
- package/dist/types/src/plugin/operator-settings.d.ts.map +1 -0
- package/dist/types/src/plugin/persist-account-pool.d.ts +98 -0
- package/dist/types/src/plugin/persist-account-pool.d.ts.map +1 -0
- package/dist/types/src/plugin/project.d.ts +2 -0
- package/dist/types/src/plugin/project.d.ts.map +1 -0
- package/dist/types/src/plugin/prompt-context.d.ts +18 -0
- package/dist/types/src/plugin/prompt-context.d.ts.map +1 -0
- package/dist/types/src/plugin/quota.d.ts +441 -0
- package/dist/types/src/plugin/quota.d.ts.map +1 -0
- package/dist/types/src/plugin/recovery/constants.d.ts +22 -0
- package/dist/types/src/plugin/recovery/constants.d.ts.map +1 -0
- package/dist/types/src/plugin/recovery/storage.d.ts +24 -0
- package/dist/types/src/plugin/recovery/storage.d.ts.map +1 -0
- package/dist/types/src/plugin/recovery/types.d.ts +116 -0
- package/dist/types/src/plugin/recovery/types.d.ts.map +1 -0
- package/dist/types/src/plugin/recovery.d.ts +61 -0
- package/dist/types/src/plugin/recovery.d.ts.map +1 -0
- package/dist/types/src/plugin/refresh-queue.d.ts +133 -0
- package/dist/types/src/plugin/refresh-queue.d.ts.map +1 -0
- package/dist/types/src/plugin/request-helpers.d.ts +304 -0
- package/dist/types/src/plugin/request-helpers.d.ts.map +1 -0
- package/dist/types/src/plugin/request.d.ts +161 -0
- package/dist/types/src/plugin/request.d.ts.map +1 -0
- package/dist/types/src/plugin/rotation.d.ts +2 -0
- package/dist/types/src/plugin/rotation.d.ts.map +1 -0
- package/dist/types/src/plugin/search.d.ts +25 -0
- package/dist/types/src/plugin/search.d.ts.map +1 -0
- package/dist/types/src/plugin/server.d.ts +23 -0
- package/dist/types/src/plugin/server.d.ts.map +1 -0
- package/dist/types/src/plugin/session-context.d.ts +22 -0
- package/dist/types/src/plugin/session-context.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/local-grant.d.ts +26 -0
- package/dist/types/src/plugin/shared/local-grant.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/request-cancellation.d.ts +12 -0
- package/dist/types/src/plugin/shared/request-cancellation.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/request-services.d.ts +375 -0
- package/dist/types/src/plugin/shared/request-services.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/runtime.d.ts +217 -0
- package/dist/types/src/plugin/shared/runtime.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/source-sidebar.d.ts +15 -0
- package/dist/types/src/plugin/shared/source-sidebar.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/vault-menu.d.ts +5 -0
- package/dist/types/src/plugin/shared/vault-menu.d.ts.map +1 -0
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts +168 -0
- package/dist/types/src/plugin/shared/vault-request-credentials.d.ts.map +1 -0
- package/dist/types/src/plugin/storage.d.ts +221 -0
- package/dist/types/src/plugin/storage.d.ts.map +1 -0
- package/dist/types/src/plugin/stores/signature-store.d.ts +5 -0
- package/dist/types/src/plugin/stores/signature-store.d.ts.map +1 -0
- package/dist/types/src/plugin/thinking-recovery.d.ts +90 -0
- package/dist/types/src/plugin/thinking-recovery.d.ts.map +1 -0
- package/dist/types/src/plugin/token.d.ts +41 -0
- package/dist/types/src/plugin/token.d.ts.map +1 -0
- package/dist/types/src/plugin/transform/cross-model-sanitizer.d.ts +2 -0
- package/dist/types/src/plugin/transform/cross-model-sanitizer.d.ts.map +1 -0
- package/dist/types/src/plugin/transform/index.d.ts +2 -0
- package/dist/types/src/plugin/transform/index.d.ts.map +1 -0
- package/dist/types/src/plugin/transform/model-resolver.d.ts +2 -0
- package/dist/types/src/plugin/transform/model-resolver.d.ts.map +1 -0
- package/dist/types/src/plugin/transform/types.d.ts +2 -0
- package/dist/types/src/plugin/transform/types.d.ts.map +1 -0
- package/dist/types/src/plugin/types.d.ts +36 -0
- package/dist/types/src/plugin/types.d.ts.map +1 -0
- package/dist/types/src/plugin/ui/ansi.d.ts +32 -0
- package/dist/types/src/plugin/ui/ansi.d.ts.map +1 -0
- package/dist/types/src/plugin/ui/auth-menu.d.ts +59 -0
- package/dist/types/src/plugin/ui/auth-menu.d.ts.map +1 -0
- package/dist/types/src/plugin/ui/confirm.d.ts +2 -0
- package/dist/types/src/plugin/ui/confirm.d.ts.map +1 -0
- package/dist/types/src/plugin/ui/quota-status.d.ts +73 -0
- package/dist/types/src/plugin/ui/quota-status.d.ts.map +1 -0
- package/dist/types/src/plugin/ui/select.d.ts +23 -0
- package/dist/types/src/plugin/ui/select.d.ts.map +1 -0
- package/dist/types/src/plugin/vault-activation.d.ts +11 -0
- package/dist/types/src/plugin/vault-activation.d.ts.map +1 -0
- package/dist/types/src/plugin/vault-custody.d.ts +131 -0
- package/dist/types/src/plugin/vault-custody.d.ts.map +1 -0
- package/dist/types/src/plugin/version.d.ts +2 -0
- package/dist/types/src/plugin/version.d.ts.map +1 -0
- package/dist/types/src/quota-presentation.d.ts +18 -0
- package/dist/types/src/quota-presentation.d.ts.map +1 -0
- package/dist/types/src/rpc/notifications.d.ts +6 -0
- package/dist/types/src/rpc/notifications.d.ts.map +1 -0
- package/dist/types/src/rpc/protocol.d.ts +53 -0
- package/dist/types/src/rpc/protocol.d.ts.map +1 -0
- package/dist/types/src/rpc/rpc-dir.d.ts +4 -0
- package/dist/types/src/rpc/rpc-dir.d.ts.map +1 -0
- package/dist/types/src/rpc/rpc-server.d.ts +24 -0
- package/dist/types/src/rpc/rpc-server.d.ts.map +1 -0
- package/dist/types/src/server.d.ts +30 -0
- package/dist/types/src/server.d.ts.map +1 -0
- package/dist/types/src/sidebar-state.d.ts +365 -0
- package/dist/types/src/sidebar-state.d.ts.map +1 -0
- package/dist/types/src/tui/host-api.d.ts +196 -0
- package/dist/types/src/tui/host-api.d.ts.map +1 -0
- package/package.json +45 -18
- package/server.js +6 -0
- package/src/common-auth-embedded/NOTICE.txt +21 -0
- package/src/common-auth-embedded/auth-menu/accounts.d.ts +97 -0
- package/src/common-auth-embedded/auth-menu/accounts.js +387 -0
- package/src/common-auth-embedded/auth-menu/ansi.d.ts +26 -0
- package/src/common-auth-embedded/auth-menu/ansi.js +98 -0
- package/src/common-auth-embedded/auth-menu/confirm.d.ts +7 -0
- package/src/common-auth-embedded/auth-menu/confirm.js +21 -0
- package/src/common-auth-embedded/auth-menu/doctor.d.ts +52 -0
- package/src/common-auth-embedded/auth-menu/doctor.js +81 -0
- package/src/common-auth-embedded/auth-menu/index.d.ts +17 -0
- package/src/common-auth-embedded/auth-menu/index.js +12 -0
- package/src/common-auth-embedded/auth-menu/login.d.ts +55 -0
- package/src/common-auth-embedded/auth-menu/login.js +83 -0
- package/src/common-auth-embedded/auth-menu/menu.d.ts +59 -0
- package/src/common-auth-embedded/auth-menu/menu.js +73 -0
- package/src/common-auth-embedded/auth-menu/opencode-v1.d.ts +49 -0
- package/src/common-auth-embedded/auth-menu/opencode-v1.js +47 -0
- package/src/common-auth-embedded/auth-menu/select.d.ts +21 -0
- package/src/common-auth-embedded/auth-menu/select.js +159 -0
- package/src/common-auth-embedded/auth-menu/terminal.d.ts +43 -0
- package/src/common-auth-embedded/auth-menu/terminal.js +19 -0
- package/src/common-auth-embedded/claustrum/consumer.d.ts +102 -0
- package/src/common-auth-embedded/claustrum/consumer.js +298 -0
- package/src/common-auth-embedded/claustrum/custody.d.ts +175 -0
- package/src/common-auth-embedded/claustrum/custody.js +354 -0
- package/src/common-auth-embedded/claustrum/enrollment.d.ts +158 -0
- package/src/common-auth-embedded/claustrum/enrollment.js +759 -0
- package/src/common-auth-embedded/claustrum/errors.d.ts +16 -0
- package/src/common-auth-embedded/claustrum/errors.js +8 -0
- package/src/common-auth-embedded/claustrum/host-slot.d.ts +39 -0
- package/src/common-auth-embedded/claustrum/host-slot.js +72 -0
- package/src/common-auth-embedded/claustrum/index.d.ts +18 -0
- package/src/common-auth-embedded/claustrum/index.js +22 -0
- package/src/common-auth-embedded/claustrum/interlock.d.ts +27 -0
- package/src/common-auth-embedded/claustrum/interlock.js +29 -0
- package/src/common-auth-embedded/claustrum/roster.d.ts +208 -0
- package/src/common-auth-embedded/claustrum/roster.js +536 -0
- package/src/common-auth-embedded/commands/builtins.d.ts +71 -0
- package/src/common-auth-embedded/commands/builtins.js +534 -0
- package/src/common-auth-embedded/commands/index.d.ts +10 -0
- package/src/common-auth-embedded/commands/index.js +5 -0
- package/src/common-auth-embedded/commands/menu.d.ts +61 -0
- package/src/common-auth-embedded/commands/menu.js +300 -0
- package/src/common-auth-embedded/commands/model.d.ts +238 -0
- package/src/common-auth-embedded/commands/model.js +16 -0
- package/src/common-auth-embedded/commands/pi.d.ts +23 -0
- package/src/common-auth-embedded/commands/pi.js +206 -0
- package/src/common-auth-embedded/commands/seam.d.ts +72 -0
- package/src/common-auth-embedded/commands/seam.js +301 -0
- package/src/common-auth-embedded/fs/atomic-write.d.ts +20 -0
- package/src/common-auth-embedded/fs/atomic-write.js +80 -0
- package/src/common-auth-embedded/fs/index.d.ts +7 -0
- package/src/common-auth-embedded/fs/index.js +6 -0
- package/src/common-auth-embedded/fs/lock-constants.d.ts +14 -0
- package/src/common-auth-embedded/fs/lock-constants.js +14 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.d.ts +33 -0
- package/src/common-auth-embedded/fs/refresh-file-lock.js +501 -0
- package/src/common-auth-embedded/fs/with-lock.d.ts +33 -0
- package/src/common-auth-embedded/fs/with-lock.js +48 -0
- package/src/common-auth-embedded/logger/capture-sink.d.ts +14 -0
- package/src/common-auth-embedded/logger/capture-sink.js +13 -0
- package/src/common-auth-embedded/logger/engine.d.ts +100 -0
- package/src/common-auth-embedded/logger/engine.js +246 -0
- package/src/common-auth-embedded/logger/index.d.ts +6 -0
- package/src/common-auth-embedded/logger/index.js +3 -0
- package/src/common-auth-embedded/logger/redact.d.ts +11 -0
- package/src/common-auth-embedded/logger/redact.js +83 -0
- package/src/common-auth-embedded/opencode2/errors.d.ts +25 -0
- package/src/common-auth-embedded/opencode2/errors.js +15 -0
- package/src/common-auth-embedded/opencode2/index.d.ts +8 -0
- package/src/common-auth-embedded/opencode2/index.js +4 -0
- package/src/common-auth-embedded/opencode2/install.d.ts +55 -0
- package/src/common-auth-embedded/opencode2/install.js +886 -0
- package/src/common-auth-embedded/opencode2/integration.d.ts +112 -0
- package/src/common-auth-embedded/opencode2/integration.js +143 -0
- package/src/common-auth-embedded/opencode2/sse.d.ts +12 -0
- package/src/common-auth-embedded/opencode2/sse.js +60 -0
- package/src/common-auth-embedded/opencode2/types.d.ts +413 -0
- package/src/common-auth-embedded/pi-slot/index.d.ts +3 -0
- package/src/common-auth-embedded/pi-slot/index.js +2 -0
- package/src/common-auth-embedded/pi-slot/lock.js +212 -0
- package/src/common-auth-embedded/pi-slot/slot.d.ts +49 -0
- package/src/common-auth-embedded/pi-slot/slot.js +383 -0
- package/src/common-auth-embedded/quota/codec.d.ts +11 -0
- package/src/common-auth-embedded/quota/codec.js +12 -0
- package/src/common-auth-embedded/quota/format.d.ts +46 -0
- package/src/common-auth-embedded/quota/format.js +138 -0
- package/src/common-auth-embedded/quota/index.d.ts +10 -0
- package/src/common-auth-embedded/quota/index.js +5 -0
- package/src/common-auth-embedded/quota/map.d.ts +63 -0
- package/src/common-auth-embedded/quota/map.js +105 -0
- package/src/common-auth-embedded/quota/merge.d.ts +48 -0
- package/src/common-auth-embedded/quota/merge.js +162 -0
- package/src/common-auth-embedded/quota/projection.d.ts +64 -0
- package/src/common-auth-embedded/quota/projection.js +134 -0
- package/src/common-auth-embedded/routing/admission.d.ts +93 -0
- package/src/common-auth-embedded/routing/admission.js +142 -0
- package/src/common-auth-embedded/routing/index.d.ts +8 -0
- package/src/common-auth-embedded/routing/index.js +4 -0
- package/src/common-auth-embedded/routing/ordered.d.ts +47 -0
- package/src/common-auth-embedded/routing/ordered.js +58 -0
- package/src/common-auth-embedded/routing/pins.d.ts +22 -0
- package/src/common-auth-embedded/routing/pins.js +34 -0
- package/src/common-auth-embedded/routing/sticky.d.ts +158 -0
- package/src/common-auth-embedded/routing/sticky.js +339 -0
- package/src/common-auth-embedded/rpc/client.d.ts +3 -0
- package/src/common-auth-embedded/rpc/client.js +2 -0
- package/src/common-auth-embedded/rpc/index.d.ts +10 -0
- package/src/common-auth-embedded/rpc/index.js +5 -0
- package/src/common-auth-embedded/rpc/notifications.d.ts +73 -0
- package/src/common-auth-embedded/rpc/notifications.js +100 -0
- package/src/common-auth-embedded/rpc/port-file.d.ts +33 -0
- package/src/common-auth-embedded/rpc/port-file.js +217 -0
- package/src/common-auth-embedded/rpc/rpc-client.d.ts +30 -0
- package/src/common-auth-embedded/rpc/rpc-client.js +253 -0
- package/src/common-auth-embedded/rpc/rpc-server.d.ts +58 -0
- package/src/common-auth-embedded/rpc/rpc-server.js +311 -0
- package/src/common-auth-embedded/rpc/server-registry.d.ts +11 -0
- package/src/common-auth-embedded/rpc/server-registry.js +47 -0
- package/src/common-auth-embedded/source-output.json +1326 -0
- package/src/common-auth-embedded/store/attribution.d.ts +28 -0
- package/src/common-auth-embedded/store/attribution.js +60 -0
- package/src/common-auth-embedded/store/errors.d.ts +55 -0
- package/src/common-auth-embedded/store/errors.js +38 -0
- package/src/common-auth-embedded/store/hooks.d.ts +12 -0
- package/src/common-auth-embedded/store/hooks.js +34 -0
- package/src/common-auth-embedded/store/identity.d.ts +39 -0
- package/src/common-auth-embedded/store/identity.js +79 -0
- package/src/common-auth-embedded/store/index.d.ts +21 -0
- package/src/common-auth-embedded/store/index.js +7 -0
- package/src/common-auth-embedded/store/mutate.d.ts +189 -0
- package/src/common-auth-embedded/store/mutate.js +500 -0
- package/src/common-auth-embedded/store/pool.d.ts +196 -0
- package/src/common-auth-embedded/store/pool.js +120 -0
- package/src/common-auth-embedded/store/provider-state.d.ts +131 -0
- package/src/common-auth-embedded/store/provider-state.js +226 -0
- package/src/common-auth-embedded/store/publication.d.ts +47 -0
- package/src/common-auth-embedded/store/publication.js +304 -0
- package/src/common-auth-embedded/store/pull.d.ts +36 -0
- package/src/common-auth-embedded/store/pull.js +143 -0
- package/src/common-auth-embedded/store/refresh-lock.d.ts +63 -0
- package/src/common-auth-embedded/store/refresh-lock.js +136 -0
- package/src/common-auth-embedded/store/refresh.d.ts +72 -0
- package/src/common-auth-embedded/store/refresh.js +225 -0
- package/src/common-auth-embedded/store/reserved.js +13 -0
- package/src/common-auth-embedded/store/rows.d.ts +313 -0
- package/src/common-auth-embedded/store/rows.js +1258 -0
- package/src/common-auth-embedded/store/runtime.d.ts +36 -0
- package/src/common-auth-embedded/store/runtime.js +68 -0
- package/src/common-auth-embedded/store/schema.d.ts +443 -0
- package/src/common-auth-embedded/store/schema.js +754 -0
- package/src/common-auth-embedded/store/settings.d.ts +63 -0
- package/src/common-auth-embedded/store/settings.js +120 -0
- package/src/common-auth-embedded/store/torn.d.ts +78 -0
- package/src/common-auth-embedded/store/torn.js +294 -0
- package/src/common-auth-embedded/tui/index.d.ts +8 -0
- package/src/common-auth-embedded/tui/index.js +21 -0
- package/src/common-auth-embedded/util/any-signal.js +42 -0
- package/src/plugin/command-data.ts +3 -0
- package/src/rpc/port-file.ts +6 -140
- package/src/rpc/protocol.ts +59 -24
- package/src/rpc/rpc-client.ts +101 -71
- package/src/sidebar-state.ts +82 -24
- package/src/tui/command-dialogs.tsx +412 -776
- package/src/tui/entry.d.mts +17 -0
- package/src/tui/entry.mjs +34 -66
- package/src/tui/file-logger.ts +22 -7
- package/src/tui-compiled/common-auth-embedded/logger/capture-sink.js +13 -0
- package/src/tui-compiled/common-auth-embedded/logger/engine.js +246 -0
- package/src/tui-compiled/common-auth-embedded/logger/index.js +3 -0
- package/src/tui-compiled/common-auth-embedded/logger/redact.js +83 -0
- package/src/tui-compiled/common-auth-embedded/quota/codec.js +12 -0
- package/src/tui-compiled/common-auth-embedded/quota/format.js +138 -0
- package/src/tui-compiled/common-auth-embedded/quota/index.js +5 -0
- package/src/tui-compiled/common-auth-embedded/quota/map.js +105 -0
- package/src/tui-compiled/common-auth-embedded/quota/merge.js +162 -0
- package/src/tui-compiled/common-auth-embedded/quota/projection.js +134 -0
- package/src/tui-compiled/common-auth-embedded/rpc/client.js +2 -0
- package/src/tui-compiled/common-auth-embedded/rpc/port-file.js +217 -0
- package/src/tui-compiled/common-auth-embedded/rpc/rpc-client.js +253 -0
- package/src/tui-compiled/logging/provider-key-policy.js +3 -0
- package/src/tui-compiled/quota-presentation.js +42 -0
- package/src/tui-compiled/rpc/rpc-client.js +35 -0
- package/src/tui-compiled/rpc/rpc-dir.js +13 -0
- package/src/tui-compiled/selector.js +21 -0
- package/src/tui-compiled/sidebar-state.js +401 -0
- package/src/tui-compiled/tui/command-dialogs.js +424 -0
- package/src/tui-compiled/tui/file-logger.js +73 -0
- package/src/tui-compiled/tui/host-api.js +269 -0
- package/src/tui-compiled/tui/host-v1.js +228 -0
- package/src/tui-compiled/tui-preferences.js +230 -0
- package/src/tui-compiled/{tui.tsx → tui.js} +140 -231
- package/src/tui-ga-compiled/host-ga.js +1304 -0
- package/src/tui-ga-compiled/selector.js +21 -0
- package/src/tui-ga-compiled/shared/07365a7d2ccade4c-host-api.js +269 -0
- package/src/tui-ga-compiled/shared/0e19a88ff3535906-command-dialogs.js +424 -0
- package/src/tui-ga-compiled/shared/1ff34afa7c42d196-projection.js +134 -0
- package/src/tui-ga-compiled/shared/77138df80c7ae006-map.js +105 -0
- package/src/tui-ga-compiled/shared/8ae1927e5910ea81-sidebar-projection.js +112 -0
- package/src/tui-ga-compiled/shared/98cc0c186c46c42d-quota-presentation.js +42 -0
- package/src/tui-ga-compiled/shared/aef2402f8fc342f0-format.js +138 -0
- package/src/tui-ga-compiled/shared/bf17cbee28e58197-index.js +5 -0
- package/src/tui-ga-compiled/shared/ca21dc417b36dc5d-codec.js +12 -0
- package/src/tui-ga-compiled/shared/ecc214300932dfb6-merge.js +162 -0
- package/src/tui-ga-raw/host-ga.tsx +1740 -0
- package/src/tui-ga-raw/selector.js +21 -0
- package/src/tui-ga-raw/shared/07365a7d2ccade4c-host-api.js +269 -0
- package/src/tui-ga-raw/shared/0e19a88ff3535906-command-dialogs.tsx +468 -0
- package/src/tui-ga-raw/shared/1ff34afa7c42d196-projection.js +134 -0
- package/src/tui-ga-raw/shared/77138df80c7ae006-map.js +105 -0
- package/src/tui-ga-raw/shared/8ae1927e5910ea81-sidebar-projection.js +112 -0
- package/src/tui-ga-raw/shared/98cc0c186c46c42d-quota-presentation.js +42 -0
- package/src/tui-ga-raw/shared/aef2402f8fc342f0-format.js +138 -0
- package/src/tui-ga-raw/shared/bf17cbee28e58197-index.js +5 -0
- package/src/tui-ga-raw/shared/ca21dc417b36dc5d-codec.js +12 -0
- package/src/tui-ga-raw/shared/ecc214300932dfb6-merge.js +162 -0
- package/src/tui-raw/common-auth-embedded/logger/capture-sink.js +13 -0
- package/src/tui-raw/common-auth-embedded/logger/engine.js +246 -0
- package/src/tui-raw/common-auth-embedded/logger/index.js +3 -0
- package/src/tui-raw/common-auth-embedded/logger/redact.js +83 -0
- package/src/tui-raw/common-auth-embedded/quota/codec.js +12 -0
- package/src/tui-raw/common-auth-embedded/quota/format.js +138 -0
- package/src/tui-raw/common-auth-embedded/quota/index.js +5 -0
- package/src/tui-raw/common-auth-embedded/quota/map.js +105 -0
- package/src/tui-raw/common-auth-embedded/quota/merge.js +162 -0
- package/src/tui-raw/common-auth-embedded/quota/projection.js +134 -0
- package/src/tui-raw/common-auth-embedded/rpc/client.js +2 -0
- package/src/tui-raw/common-auth-embedded/rpc/port-file.js +217 -0
- package/src/tui-raw/common-auth-embedded/rpc/rpc-client.js +253 -0
- package/src/tui-raw/logging/provider-key-policy.js +3 -0
- package/src/tui-raw/quota-presentation.js +42 -0
- package/src/tui-raw/rpc/rpc-client.js +35 -0
- package/src/tui-raw/rpc/rpc-dir.js +13 -0
- package/src/tui-raw/selector.js +21 -0
- package/src/tui-raw/sidebar-state.js +401 -0
- package/src/tui-raw/tui/command-dialogs.tsx +468 -0
- package/src/tui-raw/tui/file-logger.js +73 -0
- package/src/tui-raw/tui/host-api.js +269 -0
- package/src/tui-raw/tui/host-v1.tsx +249 -0
- package/src/tui-raw/tui-preferences.js +230 -0
- package/src/tui-raw/tui.tsx +1088 -0
- package/src/tui.tsx +58 -141
- package/tui.js +6 -0
- package/src/tui-compiled/plugin/command-data.ts +0 -931
- package/src/tui-compiled/rpc/port-file.ts +0 -143
- package/src/tui-compiled/rpc/protocol.ts +0 -31
- package/src/tui-compiled/rpc/rpc-client.ts +0 -102
- package/src/tui-compiled/rpc/rpc-dir.ts +0 -24
- package/src/tui-compiled/sidebar-state.ts +0 -991
- package/src/tui-compiled/tui/command-dialogs.tsx +0 -779
- package/src/tui-compiled/tui/file-logger.ts +0 -145
- package/src/tui-compiled/tui-preferences.ts +0 -416
|
@@ -1,195 +1,190 @@
|
|
|
1
|
-
import { fetchWithAgyCliTransport } from '@cortexkit/antigravity-auth-core';
|
|
2
|
-
import {
|
|
3
|
-
import { upsertSidebarActiveRouting, } from '../sidebar-state';
|
|
1
|
+
import { fetchWithAgyCliTransport, } from '@cortexkit/antigravity-auth-core';
|
|
2
|
+
import { upsertSidebarActiveRouting } from '../sidebar-state';
|
|
4
3
|
import { extractAccountAccessErrorDetails } from './account-access';
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import
|
|
8
|
-
import {
|
|
9
|
-
import { createRetryState, } from './fetch/retry-state';
|
|
10
|
-
import { createWarmupState } from './fetch/warmup';
|
|
11
|
-
import { extractModelFromUrl, getModelFamilyFromUrl, isCapacityRetryBudgetExhausted, MAX_TOTAL_CAPACITY_RETRIES, resolveHeaderRoutingDecision, resolveQuotaFallbackHeaderStyle, toUrlString, toWarmupStreamUrl, } from './fetch-routing';
|
|
12
|
-
import { dumpGeminiRequest, noteGeminiDumpResponse } from './gemini-dump';
|
|
13
|
-
import { evaluateKillswitchForAccount, throwIfAllKilled } from './killswitch';
|
|
4
|
+
import { createLocalAccountCredentials, StaleAccountGrantError, } from './accounts';
|
|
5
|
+
import { isOAuthAuth } from './auth';
|
|
6
|
+
import * as moduleDebug from './debug';
|
|
7
|
+
import { dumpGeminiRequest } from './gemini-dump';
|
|
14
8
|
import { createLogger } from './logger';
|
|
15
9
|
import { ensureProjectContext } from './project';
|
|
16
10
|
import { buildThinkingWarmupBody, getImageModelLocalTitle, getLastCacheStats, isGenerativeLanguageRequest, prepareAntigravityRequest, transformAntigravityResponse, } from './request';
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import { extractOpenCodeSessionIdentity, } from './session-context';
|
|
11
|
+
import { createLocalQuotaRefresh, createRequestExecutor, } from './shared/request-services';
|
|
12
|
+
import { createVaultAccountPool, } from './shared/vault-request-credentials';
|
|
20
13
|
import { AntigravityTokenRefreshError, refreshAccessToken } from './token';
|
|
21
14
|
const log = createLogger('fetch-interceptor');
|
|
22
|
-
/**
|
|
23
|
-
* Per-call delay applied before the first 429 retry on the same account.
|
|
24
|
-
* Matches the legacy plugin so callers that compare timing logs see parity.
|
|
25
|
-
*/
|
|
26
|
-
const FIRST_RETRY_DELAY_MS = 1000;
|
|
27
15
|
/** Production transport — used when the interceptor context omits one. */
|
|
28
16
|
const defaultAgyTransport = (url, init, options) => fetchWithAgyCliTransport(url, init, options);
|
|
29
17
|
/** Default `fetchImpl` used when the interceptor context omits one. */
|
|
30
18
|
const defaultFetchImpl = (input, init) => globalThis.fetch(input, init);
|
|
31
19
|
/**
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
* a 200 SSE body pretending to be a Gemini stream. That hid the underlying
|
|
36
|
-
* misconfiguration from any caller that inspected `response.status`. Callers
|
|
37
|
-
* (notably OpenCode's HTTP layer) treat 200 as success and silently swallow
|
|
38
|
-
* the payload, so the user sees nothing. Surfacing a real 401 with the
|
|
39
|
-
* standard Google error envelope makes the failure actionable.
|
|
20
|
+
* A pool-file account: the selected account's stored OAuth record is
|
|
21
|
+
* refreshed through the host's OAuth refresh, and a grant is sent only while
|
|
22
|
+
* that account is still in the pool, enabled and still holds the token.
|
|
40
23
|
*/
|
|
41
|
-
function
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
24
|
+
function poolFileCredentials(accountManager, client, providerId) {
|
|
25
|
+
return {
|
|
26
|
+
refresh: (account) => refreshAccessToken(accountManager.toAuthDetails(account), client, providerId),
|
|
27
|
+
// A pool-file row has no repository identity; its grant is checked
|
|
28
|
+
// against the pool itself.
|
|
29
|
+
captureGrant: ({ account, accessToken }) => ({
|
|
30
|
+
source: 'pool-file',
|
|
31
|
+
check() {
|
|
32
|
+
if (!accountManager.getAccounts().includes(account) ||
|
|
33
|
+
account.enabled === false ||
|
|
34
|
+
accountManager.toAuthDetails(account).access !== accessToken) {
|
|
35
|
+
throw new StaleAccountGrantError();
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
ensureProject: (auth) => ensureProjectContext(auth),
|
|
40
|
+
isInvalidGrant: (error) => error instanceof AntigravityTokenRefreshError &&
|
|
41
|
+
error.code === 'invalid_grant',
|
|
48
42
|
};
|
|
49
|
-
return new Response(JSON.stringify(body), {
|
|
50
|
-
status: 401,
|
|
51
|
-
headers: {
|
|
52
|
-
'Content-Type': 'application/json',
|
|
53
|
-
'X-Antigravity-Error-Type': 'no_accounts',
|
|
54
|
-
'X-Antigravity-Requested-Model': model,
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
}
|
|
58
|
-
function terminalFetchError(lastError, fallbackMessage) {
|
|
59
|
-
// A synthetic HTTP 200 is parsed as successful assistant text, bypassing the
|
|
60
|
-
// host's retry and error pipeline. Preserve the original exception rather
|
|
61
|
-
// than replacing it with a message-only synthetic response.
|
|
62
|
-
return lastError ?? new Error(fallbackMessage);
|
|
63
|
-
}
|
|
64
|
-
/** Reads `retry-after-ms` / `retry-after` headers, in that order. */
|
|
65
|
-
function retryAfterMsFromResponse(response, defaultRetryMs = 60_000) {
|
|
66
|
-
const retryAfterMsHeader = response.headers.get('retry-after-ms');
|
|
67
|
-
if (retryAfterMsHeader) {
|
|
68
|
-
const parsed = Number.parseInt(retryAfterMsHeader, 10);
|
|
69
|
-
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
70
|
-
return parsed;
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
const retryAfterHeader = response.headers.get('retry-after');
|
|
74
|
-
if (retryAfterHeader) {
|
|
75
|
-
const parsed = Number.parseInt(retryAfterHeader, 10);
|
|
76
|
-
if (!Number.isNaN(parsed) && parsed > 0) {
|
|
77
|
-
return parsed * 1000;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
return defaultRetryMs;
|
|
81
|
-
}
|
|
82
|
-
/** Formats a millisecond duration the way the legacy toast pipeline did. */
|
|
83
|
-
function formatWaitTime(ms) {
|
|
84
|
-
if (ms < 1000)
|
|
85
|
-
return `${ms}ms`;
|
|
86
|
-
const seconds = Math.ceil(ms / 1000);
|
|
87
|
-
if (seconds < 60)
|
|
88
|
-
return `${seconds}s`;
|
|
89
|
-
const minutes = Math.floor(seconds / 60);
|
|
90
|
-
const remainingSeconds = seconds % 60;
|
|
91
|
-
if (minutes < 60) {
|
|
92
|
-
return remainingSeconds > 0
|
|
93
|
-
? `${minutes}m ${remainingSeconds}s`
|
|
94
|
-
: `${minutes}m`;
|
|
95
|
-
}
|
|
96
|
-
const hours = Math.floor(minutes / 60);
|
|
97
|
-
const remainingMinutes = minutes % 60;
|
|
98
|
-
return remainingMinutes > 0 ? `${hours}h ${remainingMinutes}m` : `${hours}h`;
|
|
99
43
|
}
|
|
100
44
|
/**
|
|
101
|
-
*
|
|
102
|
-
*
|
|
45
|
+
* An account-store account: refresh, grant check and invalid-grant
|
|
46
|
+
* recognition are the store adapter's own (`createLocalAccountCredentials`
|
|
47
|
+
* over the manager's repository), so a token is refreshed only through the
|
|
48
|
+
* repository on the selected account's row reference and never through the
|
|
49
|
+
* host client. The row reference is captured when the grant is resolved;
|
|
50
|
+
* every send is checked against that exact row, never against whatever the
|
|
51
|
+
* account object holds later, and a grant without one is never sent.
|
|
103
52
|
*/
|
|
104
|
-
function
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
reject(signal.reason instanceof Error ? signal.reason : new Error('Aborted'));
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
const timeout = setTimeout(() => {
|
|
111
|
-
cleanup();
|
|
112
|
-
resolve();
|
|
113
|
-
}, ms);
|
|
114
|
-
const onAbort = () => {
|
|
115
|
-
cleanup();
|
|
116
|
-
reject(signal?.reason instanceof Error ? signal.reason : new Error('Aborted'));
|
|
117
|
-
};
|
|
118
|
-
const cleanup = () => {
|
|
119
|
-
clearTimeout(timeout);
|
|
120
|
-
signal?.removeEventListener('abort', onAbort);
|
|
121
|
-
};
|
|
122
|
-
signal?.addEventListener('abort', onAbort, { once: true });
|
|
53
|
+
function storeCredentials(accountManager, repository) {
|
|
54
|
+
const credentials = createLocalAccountCredentials(accountManager, {
|
|
55
|
+
repository,
|
|
123
56
|
});
|
|
57
|
+
return {
|
|
58
|
+
refresh: (account) => credentials.refresh(account),
|
|
59
|
+
captureGrant: (grant) => credentials.captureGrant(grant),
|
|
60
|
+
ensureProject: (auth) => credentials.ensureProject(auth),
|
|
61
|
+
isInvalidGrant: (error) => credentials.isInvalidGrant(error),
|
|
62
|
+
};
|
|
124
63
|
}
|
|
125
64
|
/**
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
65
|
+
* The engine collaborators every OpenCode 1 interceptor shares, whatever
|
|
66
|
+
* holds its accounts: wire functions, the module-level debug, dump and
|
|
67
|
+
* logger bindings, host toasts and the sidebar routing file.
|
|
68
|
+
*/
|
|
69
|
+
function openCode1EngineCollaborators(common) {
|
|
70
|
+
const { client } = common;
|
|
71
|
+
return {
|
|
72
|
+
config: common.config,
|
|
73
|
+
sessions: common.agySessionRegistry,
|
|
74
|
+
operatorSettings: common.operatorSettings,
|
|
75
|
+
transport: common.transport,
|
|
76
|
+
fetchImpl: common.fetchImpl,
|
|
77
|
+
wire: {
|
|
78
|
+
prepare: prepareAntigravityRequest,
|
|
79
|
+
transformResponse: transformAntigravityResponse,
|
|
80
|
+
buildThinkingWarmupBody,
|
|
81
|
+
getImageModelLocalTitle,
|
|
82
|
+
getLastCacheStats,
|
|
83
|
+
},
|
|
84
|
+
// OpenCode 1's module-level debug namespace provides the debug methods
|
|
85
|
+
// the engine calls.
|
|
86
|
+
debug: moduleDebug,
|
|
87
|
+
dump: { dumpRequest: dumpGeminiRequest },
|
|
88
|
+
logger: log,
|
|
89
|
+
classifyAccessError: extractAccountAccessErrorDetails,
|
|
90
|
+
notify: (message, variant) => client.tui.showToast({ body: { message, variant } }),
|
|
91
|
+
onRouting: common.onRouting ??
|
|
92
|
+
((sessionId, entry) => {
|
|
93
|
+
void upsertSidebarActiveRouting(sessionId, entry, {
|
|
94
|
+
authoritative: true,
|
|
95
|
+
}).catch((error) => {
|
|
96
|
+
log.debug('sidebar-routing-upsert-failed', {
|
|
97
|
+
sessionId,
|
|
98
|
+
error: String(error),
|
|
99
|
+
});
|
|
100
|
+
});
|
|
101
|
+
}),
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
/**
|
|
105
|
+
* OpenCode 1 binding of the shared request engine for accounts this plugin
|
|
106
|
+
* holds itself (pool file or account store). The retry, rotation and
|
|
107
|
+
* quota-fallback pipeline lives in `createRequestExecutor`; this wrapper
|
|
108
|
+
* decides which requests reach it and binds the account manager, its
|
|
109
|
+
* source's credential operations and OpenCode 1's collaborators.
|
|
129
110
|
*/
|
|
130
111
|
export function createFetchInterceptor(context) {
|
|
131
|
-
const { client, providerId,
|
|
112
|
+
const { client, providerId, accountManager, accountSource, quotaManager, getAuth, agyTransport = defaultAgyTransport, fetchImpl = defaultFetchImpl,
|
|
132
113
|
// directory is part of the contract but not consumed by this interceptor;
|
|
133
114
|
// callers use it when constructing sibling services (e.g. project context).
|
|
134
115
|
} = context;
|
|
135
116
|
void context.directory;
|
|
136
|
-
const retryState = createRetryState();
|
|
137
|
-
const warmupState = createWarmupState();
|
|
138
|
-
let disposed = false;
|
|
139
117
|
// Capture the host fetch at factory time so the interceptor never shadows
|
|
140
118
|
// it with its own (recursive) fetch binding. Production wires this up via
|
|
141
119
|
// the OpenCode plugin runtime; tests inject a mock by stubbing globalThis
|
|
142
120
|
// OR — preferred for e2e — pass `fetchImpl` through the context so the
|
|
143
121
|
// stub survives a process-wide fetch replacement.
|
|
144
122
|
const upstreamFetch = fetchImpl;
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
123
|
+
const refreshQuotaAfterSuccess = createLocalQuotaRefresh(accountManager, quotaManager, log);
|
|
124
|
+
const executor = createRequestExecutor({
|
|
125
|
+
assertAdmission: context.assertAdmission,
|
|
126
|
+
...openCode1EngineCollaborators({
|
|
127
|
+
...context,
|
|
128
|
+
transport: agyTransport,
|
|
129
|
+
fetchImpl: upstreamFetch,
|
|
130
|
+
}),
|
|
131
|
+
accounts: accountManager,
|
|
132
|
+
credentials: {
|
|
133
|
+
domain: 'local',
|
|
134
|
+
toAuthDetails: (account) => accountManager.toAuthDetails(account),
|
|
135
|
+
updateFromAuth: (account, auth) => accountManager.updateFromAuth(account, auth),
|
|
136
|
+
removeAccount: (account) => accountManager.removeAccount(account),
|
|
137
|
+
saveToDisk: () => accountManager.saveToDisk(),
|
|
138
|
+
saveToDiskReplace: () => accountManager.saveToDiskReplace(),
|
|
139
|
+
...(accountSource.kind === 'store'
|
|
140
|
+
? storeCredentials(accountManager, accountSource.repository)
|
|
141
|
+
: poolFileCredentials(accountManager, client, providerId)),
|
|
142
|
+
clearStoredAuth: async () => {
|
|
143
|
+
await context.assertAdmission?.();
|
|
144
|
+
await client.auth.set({
|
|
145
|
+
path: { id: providerId },
|
|
146
|
+
body: { type: 'oauth', refresh: '', access: '', expires: 0 },
|
|
147
|
+
});
|
|
148
|
+
},
|
|
149
|
+
refreshQuotaAfterSuccess: async (account, intervalMinutes) => {
|
|
150
|
+
await context.assertAdmission?.();
|
|
151
|
+
await refreshQuotaAfterSuccess(account, intervalMinutes);
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
// The trackers the manager selects with: its own for a store-backed
|
|
155
|
+
// manager, the process-wide ones for the pool-file manager.
|
|
156
|
+
trackers: {
|
|
157
|
+
get health() {
|
|
158
|
+
return accountManager.healthTracker;
|
|
159
|
+
},
|
|
160
|
+
get token() {
|
|
161
|
+
return accountManager.tokenTracker;
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
});
|
|
165
|
+
let disposed = false;
|
|
166
|
+
let disposePromise;
|
|
167
|
+
let retired = false;
|
|
168
|
+
let retirePromise;
|
|
169
|
+
// Requests that entered `fetch` but have not yet reached the executor
|
|
170
|
+
// (they wait on admission or the host sign-in). Retirement waits for them
|
|
171
|
+
// so the executor admits them before it stops admitting; disposal waits
|
|
172
|
+
// for them so none resumes after it reports done.
|
|
173
|
+
const entering = new Set();
|
|
174
|
+
async function intercept(input, init) {
|
|
175
|
+
await context.assertAdmission?.();
|
|
176
|
+
// Disposal may have begun during the admission read; nothing more is
|
|
177
|
+
// read or sent for this request.
|
|
178
|
+
if (disposed)
|
|
179
|
+
throw new Error('The local request runtime is disposed');
|
|
180
|
+
if (accountSource.kind === 'pool-file') {
|
|
181
|
+
const latestAuth = await getAuth();
|
|
182
|
+
if (disposed)
|
|
183
|
+
throw new Error('The local request runtime is disposed');
|
|
184
|
+
if (!isOAuthAuth(latestAuth))
|
|
185
|
+
return upstreamFetch(input, init);
|
|
192
186
|
}
|
|
187
|
+
return executor.execute(input, init);
|
|
193
188
|
}
|
|
194
189
|
async function fetch(input, init) {
|
|
195
190
|
if (disposed) {
|
|
@@ -201,1204 +196,85 @@ export function createFetchInterceptor(context) {
|
|
|
201
196
|
if (!isGenerativeLanguageRequest(input)) {
|
|
202
197
|
return upstreamFetch(input, init);
|
|
203
198
|
}
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
const bodyBuffer = req.body
|
|
222
|
-
? await req.clone().arrayBuffer()
|
|
223
|
-
: undefined;
|
|
224
|
-
init = {
|
|
225
|
-
method: init?.method ?? req.method,
|
|
226
|
-
headers,
|
|
227
|
-
body: init?.body ?? (bodyBuffer ? Buffer.from(bodyBuffer) : undefined),
|
|
228
|
-
signal: init?.signal ?? req.signal,
|
|
229
|
-
};
|
|
230
|
-
input = req.url;
|
|
231
|
-
}
|
|
232
|
-
else {
|
|
233
|
-
input = String(input.href ?? input);
|
|
234
|
-
}
|
|
235
|
-
}
|
|
236
|
-
const localImageTitle = getImageModelLocalTitle(input, init);
|
|
237
|
-
if (localImageTitle !== undefined) {
|
|
238
|
-
return createSyntheticTextResponse(localImageTitle, {
|
|
239
|
-
'X-Antigravity-Response-Type': 'local_title',
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
const requestSessionIdentity = extractOpenCodeSessionIdentity(init?.headers);
|
|
243
|
-
const agyRequestScope = agySessionRegistry.beginRequest(requestSessionIdentity);
|
|
244
|
-
const agyRequestSession = agyRequestScope.session;
|
|
245
|
-
const accountSessionIdentity = requestSessionIdentity.sessionId
|
|
246
|
-
? {
|
|
247
|
-
id: requestSessionIdentity.sessionId,
|
|
248
|
-
parentId: requestSessionIdentity.parentSessionId,
|
|
249
|
-
}
|
|
250
|
-
: undefined;
|
|
251
|
-
const isChildRequest = requestSessionIdentity.parentSessionId !== null;
|
|
252
|
-
if (accountManager.getAccountCount() === 0) {
|
|
253
|
-
// Surface a real 401 with the Google error envelope instead of a
|
|
254
|
-
// 200 SSE body — OpenCode's HTTP layer treats 200 as success and
|
|
255
|
-
// would otherwise swallow the misconfiguration silently.
|
|
256
|
-
const urlString = typeof input === 'string' ? input : toUrlString(input);
|
|
257
|
-
const modelFromUrl = extractModelFromUrl(urlString) ?? 'unknown';
|
|
258
|
-
return createNoAccountResponse('No Antigravity accounts configured. Run `opencode auth login`.', modelFromUrl);
|
|
259
|
-
}
|
|
260
|
-
const urlString = toUrlString(input);
|
|
261
|
-
const family = getModelFamilyFromUrl(urlString);
|
|
262
|
-
const model = extractModelFromUrl(urlString);
|
|
263
|
-
const debugLines = [];
|
|
264
|
-
const pushDebug = (line) => {
|
|
265
|
-
if (!isDebugEnabled())
|
|
266
|
-
return;
|
|
267
|
-
debugLines.push(line);
|
|
268
|
-
};
|
|
269
|
-
pushDebug(`request=${urlString}`);
|
|
270
|
-
if (requestSessionIdentity.sessionId) {
|
|
271
|
-
pushDebug(`[Session] id=${requestSessionIdentity.sessionId}` +
|
|
272
|
-
` parent=${requestSessionIdentity.parentSessionId ?? 'none'}` +
|
|
273
|
-
` child=${isChildRequest}`);
|
|
274
|
-
}
|
|
275
|
-
const cachedStats = getLastCacheStats();
|
|
276
|
-
if (cachedStats) {
|
|
277
|
-
const label = cachedStats.hitRate > 0 ? 'HIT' : 'MISS';
|
|
278
|
-
pushDebug(`[Cache] ${label} model=${cachedStats.model} read=${cachedStats.read} total=${cachedStats.total} hitRate=${cachedStats.hitRate}%`);
|
|
279
|
-
}
|
|
280
|
-
let lastFailure = null;
|
|
281
|
-
let lastError = null;
|
|
282
|
-
const abortSignal = init?.signal ?? undefined;
|
|
283
|
-
const checkAborted = () => {
|
|
284
|
-
if (abortSignal?.aborted) {
|
|
285
|
-
throw abortSignal.reason instanceof Error
|
|
286
|
-
? abortSignal.reason
|
|
287
|
-
: new Error('Aborted');
|
|
288
|
-
}
|
|
289
|
-
};
|
|
290
|
-
const quietMode = config.quiet_mode;
|
|
291
|
-
const toastScope = config.toast_scope;
|
|
292
|
-
// Apply operator-controlled routing overrides live. The slash
|
|
293
|
-
// commands mutate these values through `applyCommand`; reading
|
|
294
|
-
// them per-request means a runtime flip takes effect on the next
|
|
295
|
-
// dispatched call without restarting the plugin.
|
|
296
|
-
const operatorRouting = operatorSettings?.get().routing;
|
|
297
|
-
const effectiveConfig = {
|
|
298
|
-
...config,
|
|
299
|
-
cli_first: operatorRouting?.cli_first ?? config.cli_first,
|
|
300
|
-
quota_style_fallback: operatorRouting?.quota_style_fallback ?? config.quota_style_fallback,
|
|
301
|
-
};
|
|
302
|
-
const showToast = async (message, variant) => {
|
|
303
|
-
log.debug('toast', {
|
|
304
|
-
message,
|
|
305
|
-
variant,
|
|
306
|
-
isChildSession: isChildRequest,
|
|
307
|
-
toastScope,
|
|
308
|
-
});
|
|
309
|
-
if (quietMode)
|
|
310
|
-
return;
|
|
311
|
-
if (abortSignal?.aborted)
|
|
312
|
-
return;
|
|
313
|
-
if (toastScope === 'root_only' && isChildRequest) {
|
|
314
|
-
log.debug('toast-suppressed-child-session', {
|
|
315
|
-
message,
|
|
316
|
-
variant,
|
|
317
|
-
parentID: requestSessionIdentity.parentSessionId,
|
|
318
|
-
});
|
|
319
|
-
return;
|
|
320
|
-
}
|
|
321
|
-
if (variant === 'warning' && message.toLowerCase().includes('rate')) {
|
|
322
|
-
if (!retryState.shouldShowRateLimitToast(message)) {
|
|
323
|
-
return;
|
|
324
|
-
}
|
|
325
|
-
}
|
|
326
|
-
try {
|
|
327
|
-
await client.tui.showToast({ body: { message, variant } });
|
|
328
|
-
}
|
|
329
|
-
catch {
|
|
330
|
-
// TUI may not be available
|
|
331
|
-
}
|
|
332
|
-
};
|
|
333
|
-
const hasOtherAccountWithAntigravity = (currentAccount) => {
|
|
334
|
-
if (family !== 'gemini')
|
|
335
|
-
return false;
|
|
336
|
-
return accountManager.hasOtherAccountWithAntigravityAvailable(currentAccount.index, family, model);
|
|
337
|
-
};
|
|
338
|
-
let accountSwitchCount = 0;
|
|
339
|
-
const maxAccountSwitches = config.max_account_switches ?? 2;
|
|
340
|
-
let previousAccountIndex = -1;
|
|
341
|
-
let needsCacheWarmup = false;
|
|
342
|
-
while (true) {
|
|
343
|
-
checkAborted();
|
|
344
|
-
const accountCount = accountManager.getAccountCount();
|
|
345
|
-
const routingDecision = resolveHeaderRoutingDecision(urlString, family, effectiveConfig);
|
|
346
|
-
const { preferredHeaderStyle, explicitQuota, allowQuotaFallback } = routingDecision;
|
|
347
|
-
if (accountCount === 0) {
|
|
348
|
-
// Mirror the no-account short-circuit inside the retry loop so callers
|
|
349
|
-
// that race with account removal still get a proper 401 instead of a
|
|
350
|
-
// hang or a synthetic 200.
|
|
351
|
-
return createNoAccountResponse('No Antigravity accounts available. Run `opencode auth login`.', model ?? 'unknown');
|
|
352
|
-
}
|
|
353
|
-
const softQuotaCacheTtlMs = computeSoftQuotaCacheTtlMs(config.soft_quota_cache_ttl_minutes, config.quota_refresh_interval_minutes);
|
|
354
|
-
// Operator killswitch — drop candidates whose freshest cached
|
|
355
|
-
// quota remaining-percent is below the configured floor. Fail
|
|
356
|
-
// open on missing/stale quota so a cold start cannot deadlock
|
|
357
|
-
// the pipeline. The evaluation is model-aware: a `gemini-pro`
|
|
358
|
-
// request checks ONLY the `gemini-pro` quota group, not the max
|
|
359
|
-
// of pro+flash.
|
|
360
|
-
const operatorKillswitch = operatorSettings?.get().killswitch;
|
|
361
|
-
const eligibleIndexes = operatorKillswitch?.enabled
|
|
362
|
-
? new Set(accountManager
|
|
363
|
-
.getAccounts()
|
|
364
|
-
.filter((entry) => {
|
|
365
|
-
const decision = evaluateKillswitchForAccount(entry, family, {
|
|
366
|
-
routing: effectiveConfig.cli_first !== undefined
|
|
367
|
-
? {
|
|
368
|
-
cli_first: effectiveConfig.cli_first,
|
|
369
|
-
quota_style_fallback: !!effectiveConfig.quota_style_fallback,
|
|
370
|
-
}
|
|
371
|
-
: { cli_first: false, quota_style_fallback: false },
|
|
372
|
-
killswitch: operatorKillswitch,
|
|
373
|
-
log_level: 'info',
|
|
374
|
-
}, { now: Date.now(), model });
|
|
375
|
-
return decision.allowed;
|
|
376
|
-
})
|
|
377
|
-
.map((entry) => entry.index))
|
|
378
|
-
: null;
|
|
379
|
-
if (eligibleIndexes !== null &&
|
|
380
|
-
eligibleIndexes.size === 0 &&
|
|
381
|
-
accountCount > 0) {
|
|
382
|
-
try {
|
|
383
|
-
throwIfAllKilled({
|
|
384
|
-
family,
|
|
385
|
-
model: model ?? 'unknown',
|
|
386
|
-
accounts: accountManager.getAccounts(),
|
|
387
|
-
settings: {
|
|
388
|
-
routing: { cli_first: false, quota_style_fallback: false },
|
|
389
|
-
killswitch: operatorKillswitch ?? {
|
|
390
|
-
enabled: false,
|
|
391
|
-
minimum_remaining_percent: 0,
|
|
392
|
-
},
|
|
393
|
-
log_level: 'info',
|
|
394
|
-
},
|
|
395
|
-
quotaModel: model,
|
|
396
|
-
});
|
|
397
|
-
}
|
|
398
|
-
catch (error) {
|
|
399
|
-
if (error instanceof AntigravityKillswitchError) {
|
|
400
|
-
log.warn('killswitch-all-excluded', {
|
|
401
|
-
family,
|
|
402
|
-
model,
|
|
403
|
-
threshold: error.thresholdPercent,
|
|
404
|
-
summaries: error.summaries,
|
|
405
|
-
});
|
|
406
|
-
return createSyntheticErrorResponse(error.message, model ?? 'unknown');
|
|
407
|
-
}
|
|
408
|
-
throw error;
|
|
409
|
-
}
|
|
410
|
-
}
|
|
411
|
-
// Feed the killswitch verdict INTO selection: every index the
|
|
412
|
-
// precomputed eligible set rules out is excluded at the source,
|
|
413
|
-
// so a killed current account falls through to the next eligible
|
|
414
|
-
// account instead of collapsing the request into the rate-limit
|
|
415
|
-
// wait path below. The precomputed set is the source of truth —
|
|
416
|
-
// selection never re-evaluates quota, so a long-running request
|
|
417
|
-
// cannot see a different answer than the pre-filter above.
|
|
418
|
-
const killedIndexes = eligibleIndexes === null
|
|
419
|
-
? undefined
|
|
420
|
-
: new Set(accountManager
|
|
421
|
-
.getAccounts()
|
|
422
|
-
.map((entry) => entry.index)
|
|
423
|
-
.filter((index) => !eligibleIndexes.has(index)));
|
|
424
|
-
let account = accountManager.getCurrentOrNextForFamily(family, model, config.account_selection_strategy, preferredHeaderStyle, config.pid_offset_enabled, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity, killedIndexes);
|
|
425
|
-
// Belt-and-suspenders re-check on the chosen candidate against
|
|
426
|
-
// the precomputed eligible set (selection already excluded the
|
|
427
|
-
// killed indexes; this guards the fallback paths below).
|
|
428
|
-
if (account &&
|
|
429
|
-
eligibleIndexes !== null &&
|
|
430
|
-
!eligibleIndexes.has(account.index)) {
|
|
431
|
-
pushDebug(`killswitch-excluded idx=${account.index} (precomputed eligible set)`);
|
|
432
|
-
account = null;
|
|
433
|
-
}
|
|
434
|
-
if (!account && allowQuotaFallback) {
|
|
435
|
-
const alternateHeaderStyle = preferredHeaderStyle === 'antigravity' ? 'gemini-cli' : 'antigravity';
|
|
436
|
-
account = accountManager.getCurrentOrNextForFamily(family, model, config.account_selection_strategy, alternateHeaderStyle, config.pid_offset_enabled, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity, killedIndexes);
|
|
437
|
-
if (account) {
|
|
438
|
-
pushDebug(`selected-by-fallback idx=${account.index} preferred=${preferredHeaderStyle} alternate=${alternateHeaderStyle}`);
|
|
439
|
-
}
|
|
440
|
-
// The fallback path also has to clear the killswitch — a
|
|
441
|
-
// previous pre-filter scoped to the preferred-header accounts
|
|
442
|
-
// may have allowed an account only on the fallback header.
|
|
443
|
-
if (account &&
|
|
444
|
-
eligibleIndexes !== null &&
|
|
445
|
-
!eligibleIndexes.has(account.index)) {
|
|
446
|
-
pushDebug(`killswitch-excluded idx=${account.index} after fallback (precomputed eligible set)`);
|
|
447
|
-
account = null;
|
|
448
|
-
}
|
|
449
|
-
}
|
|
450
|
-
if (!account) {
|
|
451
|
-
if (accountManager.areAllAccountsOverSoftQuota(family, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, model)) {
|
|
452
|
-
const threshold = config.soft_quota_threshold_percent;
|
|
453
|
-
const softQuotaWaitMs = accountManager.getMinWaitTimeForSoftQuota(family, threshold, softQuotaCacheTtlMs, model);
|
|
454
|
-
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1000;
|
|
455
|
-
if (softQuotaWaitMs === null ||
|
|
456
|
-
(maxWaitMs > 0 && softQuotaWaitMs > maxWaitMs)) {
|
|
457
|
-
const waitTimeFormatted = softQuotaWaitMs
|
|
458
|
-
? formatWaitTime(softQuotaWaitMs)
|
|
459
|
-
: 'unknown';
|
|
460
|
-
await showToast(`All accounts over ${threshold}% quota threshold. Resets in ${waitTimeFormatted}.`, 'error');
|
|
461
|
-
return createSyntheticErrorResponse(`Quota protection: All ${accountCount} account(s) are over ${threshold}% usage for ${family}. ` +
|
|
462
|
-
`Quota resets in ${waitTimeFormatted}. ` +
|
|
463
|
-
`Add more accounts, wait for quota reset, or set soft_quota_threshold_percent: 100 to disable.`, model ?? 'unknown');
|
|
464
|
-
}
|
|
465
|
-
pushDebug(`all-over-soft-quota family=${family} accounts=${accountCount} waitMs=${softQuotaWaitMs}`);
|
|
466
|
-
if (!retryState.softQuotaToastShown()) {
|
|
467
|
-
await showToast(`All ${accountCount} account(s) over ${threshold}% quota. Waiting ${formatWaitTime(softQuotaWaitMs)}...`, 'warning');
|
|
468
|
-
retryState.markSoftQuotaToastShown();
|
|
469
|
-
}
|
|
470
|
-
await sleep(softQuotaWaitMs, abortSignal);
|
|
471
|
-
continue;
|
|
472
|
-
}
|
|
473
|
-
const strictWait = !allowQuotaFallback;
|
|
474
|
-
const waitMs = accountManager.getMinWaitTimeForFamily(family, model, preferredHeaderStyle, strictWait) || 60_000;
|
|
475
|
-
pushDebug(`all-rate-limited family=${family} accounts=${accountCount} waitMs=${waitMs}`);
|
|
476
|
-
if (isDebugEnabled()) {
|
|
477
|
-
logAccountContext('All accounts rate-limited', {
|
|
478
|
-
index: -1,
|
|
479
|
-
family,
|
|
480
|
-
totalAccounts: accountCount,
|
|
481
|
-
});
|
|
482
|
-
logRateLimitSnapshot(family, accountManager.getAccountsSnapshot());
|
|
483
|
-
}
|
|
484
|
-
const maxWaitMs = (config.max_rate_limit_wait_seconds ?? 300) * 1000;
|
|
485
|
-
if (maxWaitMs > 0 && waitMs > maxWaitMs) {
|
|
486
|
-
const waitTimeFormatted = formatWaitTime(waitMs);
|
|
487
|
-
await showToast(`Rate limited for ${waitTimeFormatted}. Try again later or add another account.`, 'error');
|
|
488
|
-
return createSyntheticErrorResponse(`All ${accountCount} account(s) rate-limited for ${family}. ` +
|
|
489
|
-
`Quota resets in ${waitTimeFormatted}. ` +
|
|
490
|
-
`Add more accounts with \`opencode auth login\` or wait and retry.`, model ?? 'unknown');
|
|
491
|
-
}
|
|
492
|
-
if (!retryState.rateLimitToastShown()) {
|
|
493
|
-
const waitSecValue = Math.max(1, Math.ceil(waitMs / 1000));
|
|
494
|
-
await showToast(`All ${accountCount} account(s) rate-limited for ${family}. Waiting ${waitSecValue}s...`, 'warning');
|
|
495
|
-
retryState.markRateLimitToastShown();
|
|
496
|
-
}
|
|
497
|
-
await sleep(waitMs, abortSignal);
|
|
498
|
-
continue;
|
|
499
|
-
}
|
|
500
|
-
// Account is available - reset the toast flag
|
|
501
|
-
retryState.resetAllAccountsBlockedToasts();
|
|
502
|
-
pushDebug(`selected idx=${account.index} email=${account.email ?? ''} family=${family} accounts=${accountCount} strategy=${config.account_selection_strategy}`);
|
|
503
|
-
if (previousAccountIndex >= 0 && previousAccountIndex !== account.index) {
|
|
504
|
-
needsCacheWarmup = config.cache_warmup_on_switch;
|
|
505
|
-
pushDebug(`account-switch: ${previousAccountIndex} → ${account.index}, warmup=${needsCacheWarmup}`);
|
|
506
|
-
}
|
|
507
|
-
previousAccountIndex = account.index;
|
|
508
|
-
accountManager.recordSessionUsage(account.index, accountSessionIdentity);
|
|
509
|
-
if (isDebugEnabled()) {
|
|
510
|
-
logAccountContext('Selected', {
|
|
511
|
-
index: account.index,
|
|
512
|
-
email: account.email,
|
|
513
|
-
family,
|
|
514
|
-
totalAccounts: accountCount,
|
|
515
|
-
rateLimitState: account.rateLimitResetTimes,
|
|
516
|
-
});
|
|
517
|
-
}
|
|
518
|
-
if (accountCount > 1 &&
|
|
519
|
-
accountManager.shouldShowAccountToast(account.index)) {
|
|
520
|
-
const accountLabel = account.email || `Account ${account.index + 1}`;
|
|
521
|
-
const enabledAccounts = accountManager.getEnabledAccounts();
|
|
522
|
-
const enabledPosition = enabledAccounts.findIndex((a) => a.index === account.index) + 1;
|
|
523
|
-
await showToast(`Using ${accountLabel} (${enabledPosition}/${accountCount})`, 'info');
|
|
524
|
-
accountManager.markToastShown(account.index);
|
|
525
|
-
}
|
|
526
|
-
accountManager.requestSaveToDisk();
|
|
527
|
-
let authRecord = accountManager.toAuthDetails(account);
|
|
528
|
-
if (accessTokenExpired(authRecord)) {
|
|
529
|
-
try {
|
|
530
|
-
const refreshed = await refreshAccessToken(authRecord, client, providerId);
|
|
531
|
-
if (!refreshed) {
|
|
532
|
-
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
533
|
-
getHealthTracker().recordFailure(account.index);
|
|
534
|
-
lastError = new Error('Antigravity token refresh failed');
|
|
535
|
-
if (shouldCooldown) {
|
|
536
|
-
accountManager.markAccountCoolingDown(account, cooldownMs, 'auth-failure');
|
|
537
|
-
accountManager.markRateLimited(account, cooldownMs, family, 'antigravity', model);
|
|
538
|
-
pushDebug(`token-refresh-failed: cooldown ${cooldownMs}ms after ${failures} failures`);
|
|
539
|
-
}
|
|
540
|
-
continue;
|
|
541
|
-
}
|
|
542
|
-
retryState.resetAccountFailureState(account.index);
|
|
543
|
-
accountManager.updateFromAuth(account, refreshed);
|
|
544
|
-
authRecord = refreshed;
|
|
545
|
-
try {
|
|
546
|
-
await accountManager.saveToDisk();
|
|
547
|
-
}
|
|
548
|
-
catch (error) {
|
|
549
|
-
log.error('Failed to persist refreshed auth', {
|
|
550
|
-
error: String(error),
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
}
|
|
554
|
-
catch (error) {
|
|
555
|
-
if (error instanceof AntigravityTokenRefreshError &&
|
|
556
|
-
error.code === 'invalid_grant') {
|
|
557
|
-
const removed = accountManager.removeAccount(account);
|
|
558
|
-
if (removed) {
|
|
559
|
-
log.warn('Removed revoked account from pool - reauthenticate via `opencode auth login`');
|
|
560
|
-
try {
|
|
561
|
-
await accountManager.saveToDiskReplace();
|
|
562
|
-
}
|
|
563
|
-
catch (persistError) {
|
|
564
|
-
log.error('Failed to persist revoked account removal', {
|
|
565
|
-
error: String(persistError),
|
|
566
|
-
});
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
if (accountManager.getAccountCount() === 0) {
|
|
570
|
-
try {
|
|
571
|
-
await client.auth.set({
|
|
572
|
-
path: { id: providerId },
|
|
573
|
-
body: { type: 'oauth', refresh: '', access: '', expires: 0 },
|
|
574
|
-
});
|
|
575
|
-
}
|
|
576
|
-
catch (storeError) {
|
|
577
|
-
log.error('Failed to clear stored Antigravity OAuth credentials', {
|
|
578
|
-
error: String(storeError),
|
|
579
|
-
});
|
|
580
|
-
}
|
|
581
|
-
return createNoAccountResponse('All Antigravity accounts have invalid refresh tokens. Run `opencode auth login` and reauthenticate.', model ?? 'unknown');
|
|
582
|
-
}
|
|
583
|
-
lastError = error;
|
|
584
|
-
continue;
|
|
585
|
-
}
|
|
586
|
-
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
587
|
-
getHealthTracker().recordFailure(account.index);
|
|
588
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
589
|
-
if (shouldCooldown) {
|
|
590
|
-
accountManager.markAccountCoolingDown(account, cooldownMs, 'auth-failure');
|
|
591
|
-
accountManager.markRateLimited(account, cooldownMs, family, 'antigravity', model);
|
|
592
|
-
pushDebug(`token-refresh-error: cooldown ${cooldownMs}ms after ${failures} failures`);
|
|
593
|
-
}
|
|
594
|
-
continue;
|
|
595
|
-
}
|
|
596
|
-
}
|
|
597
|
-
const accessToken = authRecord.access;
|
|
598
|
-
if (!accessToken) {
|
|
599
|
-
lastError = new Error('Missing access token');
|
|
600
|
-
if (accountCount <= 1) {
|
|
601
|
-
return createSyntheticErrorResponse('Missing access token. Run `opencode auth login` to reauthenticate.', model ?? 'unknown');
|
|
602
|
-
}
|
|
603
|
-
continue;
|
|
604
|
-
}
|
|
605
|
-
let projectContext;
|
|
606
|
-
try {
|
|
607
|
-
projectContext = await ensureProjectContext(authRecord);
|
|
608
|
-
retryState.resetAccountFailureState(account.index);
|
|
609
|
-
}
|
|
610
|
-
catch (error) {
|
|
611
|
-
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
612
|
-
getHealthTracker().recordFailure(account.index);
|
|
613
|
-
lastError = error instanceof Error ? error : new Error(String(error));
|
|
614
|
-
if (shouldCooldown) {
|
|
615
|
-
accountManager.markAccountCoolingDown(account, cooldownMs, 'project-error');
|
|
616
|
-
accountManager.markRateLimited(account, cooldownMs, family, 'antigravity', model);
|
|
617
|
-
pushDebug(`project-context-error: cooldown ${cooldownMs}ms after ${failures} failures`);
|
|
618
|
-
}
|
|
619
|
-
continue;
|
|
620
|
-
}
|
|
621
|
-
if (projectContext.auth.refresh !== authRecord.refresh ||
|
|
622
|
-
projectContext.auth.access !== authRecord.access) {
|
|
623
|
-
accountManager.updateFromAuth(account, projectContext.auth);
|
|
624
|
-
authRecord = projectContext.auth;
|
|
625
|
-
try {
|
|
626
|
-
await accountManager.saveToDisk();
|
|
627
|
-
}
|
|
628
|
-
catch (error) {
|
|
629
|
-
log.error('Failed to persist project context', {
|
|
630
|
-
error: String(error),
|
|
631
|
-
});
|
|
632
|
-
}
|
|
633
|
-
}
|
|
634
|
-
const runThinkingWarmup = async (prepared, projectId) => {
|
|
635
|
-
if (!config.thinking_warmup)
|
|
636
|
-
return;
|
|
637
|
-
if (!prepared.needsSignedThinkingWarmup || !prepared.sessionId)
|
|
638
|
-
return;
|
|
639
|
-
if (!warmupState.trackAttempt(prepared.sessionId))
|
|
640
|
-
return;
|
|
641
|
-
const warmupBody = buildThinkingWarmupBody(typeof prepared.init.body === 'string'
|
|
642
|
-
? prepared.init.body
|
|
643
|
-
: undefined, Boolean(prepared.effectiveModel?.toLowerCase().includes('claude') &&
|
|
644
|
-
prepared.effectiveModel?.toLowerCase().includes('thinking')));
|
|
645
|
-
if (!warmupBody)
|
|
646
|
-
return;
|
|
647
|
-
const warmupUrl = toWarmupStreamUrl(prepared.request);
|
|
648
|
-
const warmupHeaders = new Headers(prepared.init.headers ?? {});
|
|
649
|
-
warmupHeaders.set('accept', 'text/event-stream');
|
|
650
|
-
const warmupInit = {
|
|
651
|
-
...prepared.init,
|
|
652
|
-
method: prepared.init.method ?? 'POST',
|
|
653
|
-
headers: warmupHeaders,
|
|
654
|
-
body: warmupBody,
|
|
655
|
-
};
|
|
656
|
-
const warmupDebugContext = startAntigravityDebugRequest({
|
|
657
|
-
originalUrl: warmupUrl,
|
|
658
|
-
resolvedUrl: warmupUrl,
|
|
659
|
-
method: warmupInit.method,
|
|
660
|
-
headers: warmupHeaders,
|
|
661
|
-
body: warmupBody,
|
|
662
|
-
streaming: true,
|
|
663
|
-
projectId,
|
|
664
|
-
});
|
|
665
|
-
try {
|
|
666
|
-
pushDebug('thinking-warmup: start');
|
|
667
|
-
const warmupResponse = prepared.headerStyle === 'antigravity'
|
|
668
|
-
? await transport(warmupUrl, warmupInit, {
|
|
669
|
-
signal: abortSignal,
|
|
670
|
-
onDebug: pushDebug,
|
|
671
|
-
})
|
|
672
|
-
: await upstreamFetch(warmupUrl, warmupInit);
|
|
673
|
-
const transformed = await transformAntigravityResponse(warmupResponse, true, warmupDebugContext, prepared.requestedModel, projectId, warmupUrl, prepared.effectiveModel, prepared.sessionId);
|
|
674
|
-
await transformed.text();
|
|
675
|
-
warmupState.markSuccess(prepared.sessionId);
|
|
676
|
-
pushDebug('thinking-warmup: done');
|
|
677
|
-
}
|
|
678
|
-
catch (error) {
|
|
679
|
-
warmupState.clearWarmupAttempt(prepared.sessionId);
|
|
680
|
-
pushDebug(`thinking-warmup: failed ${error instanceof Error ? error.message : String(error)}`);
|
|
681
|
-
}
|
|
682
|
-
};
|
|
683
|
-
const runCacheWarmupProbe = async (prepared) => {
|
|
684
|
-
if (!needsCacheWarmup)
|
|
685
|
-
return;
|
|
686
|
-
needsCacheWarmup = false;
|
|
687
|
-
const bodyStr = typeof prepared.init.body === 'string'
|
|
688
|
-
? prepared.init.body
|
|
689
|
-
: undefined;
|
|
690
|
-
if (!bodyStr)
|
|
691
|
-
return;
|
|
692
|
-
try {
|
|
693
|
-
pushDebug('cache-warmup-probe: start');
|
|
694
|
-
const probeInit = {
|
|
695
|
-
...prepared.init,
|
|
696
|
-
method: 'POST',
|
|
697
|
-
body: bodyStr,
|
|
698
|
-
};
|
|
699
|
-
const probeResponse = prepared.headerStyle === 'antigravity'
|
|
700
|
-
? await transport(toUrlString(prepared.request), probeInit, {
|
|
701
|
-
signal: abortSignal,
|
|
702
|
-
onDebug: pushDebug,
|
|
703
|
-
})
|
|
704
|
-
: await upstreamFetch(toUrlString(prepared.request), probeInit);
|
|
705
|
-
if (probeResponse.body) {
|
|
706
|
-
const reader = probeResponse.body.getReader();
|
|
707
|
-
await reader.read();
|
|
708
|
-
await reader.cancel();
|
|
709
|
-
}
|
|
710
|
-
const status = probeResponse.status;
|
|
711
|
-
if (status >= 400) {
|
|
712
|
-
let errorSnippet = '';
|
|
713
|
-
try {
|
|
714
|
-
const errText = await probeResponse.text().catch(() => '');
|
|
715
|
-
errorSnippet = errText.slice(0, 200);
|
|
716
|
-
}
|
|
717
|
-
catch {
|
|
718
|
-
/* ignore */
|
|
719
|
-
}
|
|
720
|
-
pushDebug(`cache-warmup-probe: done status=${status}${errorSnippet ? ` error=${errorSnippet}` : ''}`);
|
|
721
|
-
}
|
|
722
|
-
else {
|
|
723
|
-
pushDebug(`cache-warmup-probe: done status=${status} (aborted after first chunk)`);
|
|
724
|
-
}
|
|
725
|
-
}
|
|
726
|
-
catch (error) {
|
|
727
|
-
pushDebug(`cache-warmup-probe: failed ${error instanceof Error ? error.message : String(error)}`);
|
|
728
|
-
}
|
|
729
|
-
};
|
|
730
|
-
let apiRequestCount = 0;
|
|
731
|
-
let shouldSwitchAccount = false;
|
|
732
|
-
let headerStyle = preferredHeaderStyle;
|
|
733
|
-
pushDebug(`headerStyle=${headerStyle} explicit=${explicitQuota}`);
|
|
734
|
-
if (account.fingerprint) {
|
|
735
|
-
pushDebug(`fingerprint: deviceId=${account.fingerprint.deviceId.slice(0, 8)}...`);
|
|
736
|
-
}
|
|
737
|
-
if (accountManager.isRateLimitedForHeaderStyle(account, family, headerStyle, model)) {
|
|
738
|
-
if (allowQuotaFallback &&
|
|
739
|
-
family === 'gemini' &&
|
|
740
|
-
headerStyle === 'antigravity') {
|
|
741
|
-
if (accountManager.hasOtherAccountWithAntigravityAvailable(account.index, family, model)) {
|
|
742
|
-
pushDebug(`antigravity rate-limited on account ${account.index}, but available on other accounts. Switching.`);
|
|
743
|
-
shouldSwitchAccount = true;
|
|
744
|
-
}
|
|
745
|
-
else {
|
|
746
|
-
const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
|
|
747
|
-
const fallbackStyle = resolveQuotaFallbackHeaderStyle({
|
|
748
|
-
family,
|
|
749
|
-
headerStyle,
|
|
750
|
-
alternateStyle,
|
|
751
|
-
});
|
|
752
|
-
if (fallbackStyle) {
|
|
753
|
-
await showToast(`Antigravity quota exhausted on all accounts. Using Gemini CLI quota.`, 'warning');
|
|
754
|
-
headerStyle = fallbackStyle;
|
|
755
|
-
pushDebug(`all-accounts antigravity exhausted, quota fallback: ${headerStyle}`);
|
|
756
|
-
}
|
|
757
|
-
else {
|
|
758
|
-
shouldSwitchAccount = true;
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
}
|
|
762
|
-
else if (allowQuotaFallback && family === 'gemini') {
|
|
763
|
-
const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
|
|
764
|
-
const fallbackStyle = resolveQuotaFallbackHeaderStyle({
|
|
765
|
-
family,
|
|
766
|
-
headerStyle,
|
|
767
|
-
alternateStyle,
|
|
768
|
-
});
|
|
769
|
-
if (fallbackStyle) {
|
|
770
|
-
const quotaName = headerStyle === 'gemini-cli' ? 'Gemini CLI' : 'Antigravity';
|
|
771
|
-
const altQuotaName = fallbackStyle === 'gemini-cli' ? 'Gemini CLI' : 'Antigravity';
|
|
772
|
-
await showToast(`${quotaName} quota exhausted, using ${altQuotaName} quota`, 'warning');
|
|
773
|
-
headerStyle = fallbackStyle;
|
|
774
|
-
pushDebug(`quota fallback: ${headerStyle}`);
|
|
775
|
-
}
|
|
776
|
-
else {
|
|
777
|
-
shouldSwitchAccount = true;
|
|
778
|
-
}
|
|
779
|
-
}
|
|
780
|
-
else {
|
|
781
|
-
shouldSwitchAccount = true;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
let totalCapacityRetries = 0;
|
|
785
|
-
while (!shouldSwitchAccount) {
|
|
786
|
-
let forceThinkingRecovery = false;
|
|
787
|
-
let tokenConsumed = false;
|
|
788
|
-
let capacityRetryCount = 0;
|
|
789
|
-
let lastEndpointIndex = -1;
|
|
790
|
-
for (let i = 0; i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length; i++) {
|
|
791
|
-
if (i !== lastEndpointIndex) {
|
|
792
|
-
capacityRetryCount = 0;
|
|
793
|
-
lastEndpointIndex = i;
|
|
794
|
-
}
|
|
795
|
-
const currentEndpoint = ANTIGRAVITY_ENDPOINT_FALLBACKS[i];
|
|
796
|
-
if (headerStyle === 'gemini-cli' &&
|
|
797
|
-
currentEndpoint !== 'https://cloudcode-pa.googleapis.com') {
|
|
798
|
-
pushDebug(`Skipping sandbox endpoint ${currentEndpoint} for gemini-cli headerStyle`);
|
|
799
|
-
continue;
|
|
800
|
-
}
|
|
801
|
-
try {
|
|
802
|
-
const prepared = prepareAntigravityRequest(input, init, accessToken, projectContext.effectiveProjectId, currentEndpoint, headerStyle, forceThinkingRecovery, {
|
|
803
|
-
claudeToolHardening: config.claude_tool_hardening,
|
|
804
|
-
claudePromptAutoCaching: config.claude_prompt_auto_caching,
|
|
805
|
-
fingerprint: account.fingerprint,
|
|
806
|
-
agySession: agyRequestSession,
|
|
807
|
-
agyRequestTimestamp: agyRequestScope.timestamp,
|
|
808
|
-
});
|
|
809
|
-
const originalUrl = toUrlString(input);
|
|
810
|
-
const resolvedUrl = toUrlString(prepared.request);
|
|
811
|
-
pushDebug(`endpoint=${currentEndpoint}`);
|
|
812
|
-
pushDebug(`resolved=${resolvedUrl}`);
|
|
813
|
-
const debugContext = startAntigravityDebugRequest({
|
|
814
|
-
originalUrl,
|
|
815
|
-
resolvedUrl,
|
|
816
|
-
method: prepared.init.method,
|
|
817
|
-
headers: prepared.init.headers,
|
|
818
|
-
body: prepared.init.body,
|
|
819
|
-
streaming: prepared.streaming,
|
|
820
|
-
projectId: projectContext.effectiveProjectId,
|
|
821
|
-
});
|
|
822
|
-
const dumpContext = dumpGeminiRequest({
|
|
823
|
-
originalUrl,
|
|
824
|
-
resolvedUrl,
|
|
825
|
-
method: prepared.init.method,
|
|
826
|
-
headers: prepared.init.headers,
|
|
827
|
-
body: prepared.init.body,
|
|
828
|
-
streaming: prepared.streaming,
|
|
829
|
-
requestedModel: prepared.requestedModel,
|
|
830
|
-
effectiveModel: prepared.effectiveModel,
|
|
831
|
-
sessionId: prepared.sessionId,
|
|
832
|
-
projectId: projectContext.effectiveProjectId,
|
|
833
|
-
});
|
|
834
|
-
const createFailureContext = (failureResponse) => ({
|
|
835
|
-
response: failureResponse,
|
|
836
|
-
streaming: prepared.streaming,
|
|
837
|
-
debugContext,
|
|
838
|
-
requestedModel: prepared.requestedModel,
|
|
839
|
-
projectId: prepared.projectId,
|
|
840
|
-
endpoint: prepared.endpoint,
|
|
841
|
-
effectiveModel: prepared.effectiveModel,
|
|
842
|
-
sessionId: prepared.sessionId,
|
|
843
|
-
toolDebugMissing: prepared.toolDebugMissing,
|
|
844
|
-
toolDebugSummary: prepared.toolDebugSummary,
|
|
845
|
-
toolDebugPayload: prepared.toolDebugPayload,
|
|
846
|
-
dumpContext,
|
|
847
|
-
});
|
|
848
|
-
await runThinkingWarmup(prepared, projectContext.effectiveProjectId);
|
|
849
|
-
await runCacheWarmupProbe(prepared);
|
|
850
|
-
if (config.request_jitter_max_ms > 0) {
|
|
851
|
-
const jitterMs = Math.floor(Math.random() * config.request_jitter_max_ms);
|
|
852
|
-
if (jitterMs > 0) {
|
|
853
|
-
await sleep(jitterMs, abortSignal);
|
|
854
|
-
}
|
|
855
|
-
}
|
|
856
|
-
if (config.account_selection_strategy === 'hybrid') {
|
|
857
|
-
tokenConsumed = getTokenTracker().consume(account.index);
|
|
858
|
-
}
|
|
859
|
-
pushDebug(`dispatching request via ${prepared.headerStyle} transport`);
|
|
860
|
-
const response = prepared.headerStyle === 'antigravity'
|
|
861
|
-
? await transport(toUrlString(prepared.request), prepared.init, { signal: abortSignal, onDebug: pushDebug })
|
|
862
|
-
: await upstreamFetch(prepared.request, prepared.init);
|
|
863
|
-
apiRequestCount++;
|
|
864
|
-
accountManager.recordRequest(account.index, family);
|
|
865
|
-
const requestCounts = accountManager.getDailyRequestCounts(account.index);
|
|
866
|
-
if (requestCounts) {
|
|
867
|
-
pushDebug(`[Quota] account=${account.index} ${family}_today=${requestCounts[family]} total_${family}_today=${accountManager.getTotalDailyRequests(family)}`);
|
|
868
|
-
}
|
|
869
|
-
pushDebug(`status=${response.status} ${response.statusText} (api_request #${apiRequestCount})`);
|
|
870
|
-
noteGeminiDumpResponse(dumpContext, response);
|
|
871
|
-
// Record the final route selection so the sidebar renders the
|
|
872
|
-
// actual account/header-style used by this request. Fire-and-
|
|
873
|
-
// forget — the dispatch path must not wait on a state write.
|
|
874
|
-
const sessionKey = requestSessionIdentity.sessionId;
|
|
875
|
-
if (sessionKey) {
|
|
876
|
-
const routingEntry = {
|
|
877
|
-
accountId: `acct-${account.index}`,
|
|
878
|
-
modelFamily: family,
|
|
879
|
-
headerStyle: prepared.headerStyle,
|
|
880
|
-
strategy: config.account_selection_strategy,
|
|
881
|
-
updatedAt: Date.now(),
|
|
882
|
-
};
|
|
883
|
-
void upsertSidebarActiveRouting(sessionKey, routingEntry, {
|
|
884
|
-
authoritative: true,
|
|
885
|
-
}).catch((error) => {
|
|
886
|
-
log.debug('sidebar-routing-upsert-failed', {
|
|
887
|
-
sessionId: sessionKey,
|
|
888
|
-
error: String(error),
|
|
889
|
-
});
|
|
890
|
-
});
|
|
891
|
-
}
|
|
892
|
-
if (response.status === 429 ||
|
|
893
|
-
response.status === 503 ||
|
|
894
|
-
response.status === 529) {
|
|
895
|
-
if (tokenConsumed) {
|
|
896
|
-
getTokenTracker().refund(account.index);
|
|
897
|
-
tokenConsumed = false;
|
|
898
|
-
}
|
|
899
|
-
const defaultRetryMs = (config.default_retry_after_seconds ?? 60) * 1000;
|
|
900
|
-
const _maxBackoffMs = (config.max_backoff_seconds ?? 60) * 1000;
|
|
901
|
-
const headerRetryMs = retryAfterMsFromResponse(response, defaultRetryMs);
|
|
902
|
-
const bodyInfo = await (async () => {
|
|
903
|
-
try {
|
|
904
|
-
const text = await response.clone().text();
|
|
905
|
-
try {
|
|
906
|
-
return JSON.parse(text);
|
|
907
|
-
}
|
|
908
|
-
catch {
|
|
909
|
-
return null;
|
|
910
|
-
}
|
|
911
|
-
}
|
|
912
|
-
catch {
|
|
913
|
-
return null;
|
|
914
|
-
}
|
|
915
|
-
})();
|
|
916
|
-
const reasonInfo = bodyInfo
|
|
917
|
-
? extractRateLimitBodyInfo(bodyInfo)
|
|
918
|
-
: { retryDelayMs: null };
|
|
919
|
-
const serverRetryMs = reasonInfo.retryDelayMs ?? headerRetryMs;
|
|
920
|
-
const rateLimitReason = parseRateLimitReason(reasonInfo.reason, reasonInfo.message, response.status);
|
|
921
|
-
if (rateLimitReason === 'MODEL_CAPACITY_EXHAUSTED' ||
|
|
922
|
-
rateLimitReason === 'SERVER_ERROR') {
|
|
923
|
-
totalCapacityRetries++;
|
|
924
|
-
if (isCapacityRetryBudgetExhausted(totalCapacityRetries)) {
|
|
925
|
-
pushDebug(`Total capacity retries (${MAX_TOTAL_CAPACITY_RETRIES}) exhausted, switching account`);
|
|
926
|
-
lastFailure = createFailureContext(response);
|
|
927
|
-
shouldSwitchAccount = true;
|
|
928
|
-
break;
|
|
929
|
-
}
|
|
930
|
-
const baseDelayMs = 1000;
|
|
931
|
-
const maxDelayMs = 8000;
|
|
932
|
-
const exponentialDelay = Math.min(baseDelayMs * 2 ** capacityRetryCount, maxDelayMs);
|
|
933
|
-
const jitter = exponentialDelay * (0.9 + Math.random() * 0.2);
|
|
934
|
-
const waitMs = Math.round(jitter);
|
|
935
|
-
const waitSec = Math.round(waitMs / 1000);
|
|
936
|
-
pushDebug(`Server busy (${rateLimitReason}) on account ${account.index}, exponential backoff ${waitMs}ms (attempt ${capacityRetryCount + 1}, total ${totalCapacityRetries}/${MAX_TOTAL_CAPACITY_RETRIES})`);
|
|
937
|
-
await showToast(`⏳ Server busy (${response.status}). Retrying in ${waitSec}s...`, 'warning');
|
|
938
|
-
await sleep(waitMs, abortSignal);
|
|
939
|
-
if (capacityRetryCount < 1) {
|
|
940
|
-
capacityRetryCount++;
|
|
941
|
-
i -= 1;
|
|
942
|
-
continue;
|
|
943
|
-
}
|
|
944
|
-
else {
|
|
945
|
-
pushDebug(`Max capacity retries (1) exhausted for endpoint ${currentEndpoint}, regenerating fingerprint...`);
|
|
946
|
-
const newFingerprint = accountManager.regenerateAccountFingerprint(account.index);
|
|
947
|
-
if (newFingerprint) {
|
|
948
|
-
pushDebug(`Fingerprint regenerated for account ${account.index}`);
|
|
949
|
-
}
|
|
950
|
-
continue;
|
|
951
|
-
}
|
|
952
|
-
}
|
|
953
|
-
const quotaKey = retryState.headerStyleToQuotaKey(headerStyle, family);
|
|
954
|
-
const backoff = retryState.getRateLimitBackoff(account.index, quotaKey, serverRetryMs);
|
|
955
|
-
const smartBackoffMs = calculateBackoffMs(rateLimitReason, account.consecutiveFailures ?? 0, serverRetryMs);
|
|
956
|
-
const effectiveDelayMs = Math.max(backoff.delayMs, smartBackoffMs);
|
|
957
|
-
pushDebug(`429 idx=${account.index} email=${account.email ?? ''} family=${family} delayMs=${effectiveDelayMs} attempt=${backoff.attempt} reason=${rateLimitReason}`);
|
|
958
|
-
if (reasonInfo.message)
|
|
959
|
-
pushDebug(`429 message=${reasonInfo.message}`);
|
|
960
|
-
if (reasonInfo.quotaResetTime)
|
|
961
|
-
pushDebug(`429 quotaResetTime=${reasonInfo.quotaResetTime}`);
|
|
962
|
-
if (reasonInfo.reason)
|
|
963
|
-
pushDebug(`429 reason=${reasonInfo.reason}`);
|
|
964
|
-
logRateLimitEvent(account.index, account.email, family, response.status, effectiveDelayMs, reasonInfo);
|
|
965
|
-
await logResponseBody(debugContext, response, 429);
|
|
966
|
-
getHealthTracker().recordRateLimit(account.index);
|
|
967
|
-
const _accountLabel = account.email || `Account ${account.index + 1}`;
|
|
968
|
-
if (backoff.attempt === 1 &&
|
|
969
|
-
rateLimitReason !== 'QUOTA_EXHAUSTED') {
|
|
970
|
-
await showToast(`Rate limited. Quick retry in 1s...`, 'warning');
|
|
971
|
-
await sleep(FIRST_RETRY_DELAY_MS, abortSignal);
|
|
972
|
-
if (config.scheduling_mode === 'cache_first') {
|
|
973
|
-
const maxCacheFirstWaitMs = config.max_cache_first_wait_seconds * 1000;
|
|
974
|
-
if (effectiveDelayMs <= maxCacheFirstWaitMs) {
|
|
975
|
-
pushDebug(`cache_first: waiting ${effectiveDelayMs}ms for same account to recover`);
|
|
976
|
-
await showToast(`⏳ Waiting ${Math.ceil(effectiveDelayMs / 1000)}s for same account (prompt cache preserved)...`, 'info');
|
|
977
|
-
accountManager.markRateLimitedWithReason(account, family, headerStyle, model, rateLimitReason, serverRetryMs);
|
|
978
|
-
await sleep(effectiveDelayMs, abortSignal);
|
|
979
|
-
i -= 1;
|
|
980
|
-
continue;
|
|
981
|
-
}
|
|
982
|
-
pushDebug(`cache_first: wait ${effectiveDelayMs}ms exceeds max ${maxCacheFirstWaitMs}ms, switching account`);
|
|
983
|
-
}
|
|
984
|
-
if (config.switch_on_first_rate_limit && accountCount > 1) {
|
|
985
|
-
accountManager.markRateLimitedWithReason(account, family, headerStyle, model, rateLimitReason, serverRetryMs, config.failure_ttl_seconds * 1000);
|
|
986
|
-
shouldSwitchAccount = true;
|
|
987
|
-
break;
|
|
988
|
-
}
|
|
989
|
-
i -= 1;
|
|
990
|
-
continue;
|
|
991
|
-
}
|
|
992
|
-
accountManager.markRateLimitedWithReason(account, family, headerStyle, model, rateLimitReason, serverRetryMs, config.failure_ttl_seconds * 1000);
|
|
993
|
-
accountManager.requestSaveToDisk();
|
|
994
|
-
const switchAccountDelayMs = config.switch_account_delay_ms ?? 500;
|
|
995
|
-
if (family === 'gemini') {
|
|
996
|
-
if (headerStyle === 'antigravity') {
|
|
997
|
-
if (hasOtherAccountWithAntigravity(account)) {
|
|
998
|
-
pushDebug(`antigravity exhausted on account ${account.index}, but available on others. Switching account.`);
|
|
999
|
-
await showToast(`Rate limited again. Switching account in ${formatWaitTime(switchAccountDelayMs)}...`, 'warning');
|
|
1000
|
-
await sleep(switchAccountDelayMs, abortSignal);
|
|
1001
|
-
shouldSwitchAccount = true;
|
|
1002
|
-
break;
|
|
1003
|
-
}
|
|
1004
|
-
if (allowQuotaFallback) {
|
|
1005
|
-
const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
|
|
1006
|
-
const fallbackStyle = resolveQuotaFallbackHeaderStyle({
|
|
1007
|
-
family,
|
|
1008
|
-
headerStyle,
|
|
1009
|
-
alternateStyle,
|
|
1010
|
-
});
|
|
1011
|
-
if (fallbackStyle) {
|
|
1012
|
-
const safeModelName = model || 'this model';
|
|
1013
|
-
await showToast(`Antigravity quota exhausted for ${safeModelName}. Switching to Gemini CLI quota...`, 'warning');
|
|
1014
|
-
headerStyle = fallbackStyle;
|
|
1015
|
-
pushDebug(`quota fallback: ${headerStyle}`);
|
|
1016
|
-
continue;
|
|
1017
|
-
}
|
|
1018
|
-
}
|
|
1019
|
-
}
|
|
1020
|
-
else if (headerStyle === 'gemini-cli') {
|
|
1021
|
-
if (allowQuotaFallback) {
|
|
1022
|
-
const alternateStyle = accountManager.getAvailableHeaderStyle(account, family, model);
|
|
1023
|
-
const fallbackStyle = resolveQuotaFallbackHeaderStyle({
|
|
1024
|
-
family,
|
|
1025
|
-
headerStyle,
|
|
1026
|
-
alternateStyle,
|
|
1027
|
-
});
|
|
1028
|
-
if (fallbackStyle) {
|
|
1029
|
-
const safeModelName = model || 'this model';
|
|
1030
|
-
await showToast(`Gemini CLI quota exhausted for ${safeModelName}. Switching to Antigravity quota...`, 'warning');
|
|
1031
|
-
headerStyle = fallbackStyle;
|
|
1032
|
-
pushDebug(`quota fallback: ${headerStyle}`);
|
|
1033
|
-
continue;
|
|
1034
|
-
}
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
if (accountCount > 1) {
|
|
1039
|
-
const quotaMsg = reasonInfo.quotaResetTime
|
|
1040
|
-
? ` (quota resets ${reasonInfo.quotaResetTime})`
|
|
1041
|
-
: ``;
|
|
1042
|
-
await showToast(`Rate limited again. Switching account in ${formatWaitTime(switchAccountDelayMs)}...${quotaMsg}`, 'warning');
|
|
1043
|
-
await sleep(switchAccountDelayMs, abortSignal);
|
|
1044
|
-
}
|
|
1045
|
-
else {
|
|
1046
|
-
const expBackoffMs = Math.min(FIRST_RETRY_DELAY_MS * 2 ** (backoff.attempt - 1), 60000);
|
|
1047
|
-
const expBackoffFormatted = expBackoffMs >= 1000
|
|
1048
|
-
? `${Math.round(expBackoffMs / 1000)}s`
|
|
1049
|
-
: `${expBackoffMs}ms`;
|
|
1050
|
-
await showToast(`Rate limited. Retrying in ${expBackoffFormatted} (attempt ${backoff.attempt})...`, 'warning');
|
|
1051
|
-
await sleep(expBackoffMs, abortSignal);
|
|
1052
|
-
}
|
|
1053
|
-
lastFailure = createFailureContext(response);
|
|
1054
|
-
shouldSwitchAccount = true;
|
|
1055
|
-
break;
|
|
1056
|
-
}
|
|
1057
|
-
const quotaKey = retryState.headerStyleToQuotaKey(headerStyle, family);
|
|
1058
|
-
retryState.resetRateLimitState(account.index, quotaKey);
|
|
1059
|
-
retryState.resetAccountFailureState(account.index);
|
|
1060
|
-
if (response.status === 403) {
|
|
1061
|
-
const errorBodyText = await response
|
|
1062
|
-
.clone()
|
|
1063
|
-
.text()
|
|
1064
|
-
.catch(() => '');
|
|
1065
|
-
const extracted = extractAccountAccessErrorDetails(errorBodyText);
|
|
1066
|
-
if (extracted.accountIneligible) {
|
|
1067
|
-
const ineligibleReason = extracted.message ??
|
|
1068
|
-
'Google marked this account as ineligible for Antigravity.';
|
|
1069
|
-
accountManager.markAccountIneligible(account.index, ineligibleReason);
|
|
1070
|
-
const label = account.email || `Account ${account.index + 1}`;
|
|
1071
|
-
if (accountManager.shouldShowAccountToast(account.index, 60000)) {
|
|
1072
|
-
await showToast(`${label} is not eligible for Antigravity and has been disabled. ` +
|
|
1073
|
-
'Recheck it from opencode auth login > Verify accounts.', 'warning');
|
|
1074
|
-
accountManager.markToastShown(account.index);
|
|
1075
|
-
}
|
|
1076
|
-
pushDebug(`account-ineligible: disabled account ${account.index}`);
|
|
1077
|
-
getHealthTracker().recordFailure(account.index);
|
|
1078
|
-
lastFailure = createFailureContext(response);
|
|
1079
|
-
shouldSwitchAccount = true;
|
|
1080
|
-
break;
|
|
1081
|
-
}
|
|
1082
|
-
if (extracted.validationRequired) {
|
|
1083
|
-
const verificationReason = extracted.message ?? 'Google requires account verification.';
|
|
1084
|
-
const cooldownMs = 10 * 60 * 1000;
|
|
1085
|
-
accountManager.markAccountVerificationRequired(account.index, verificationReason, extracted.verifyUrl);
|
|
1086
|
-
accountManager.markAccountCoolingDown(account, cooldownMs, 'validation-required');
|
|
1087
|
-
accountManager.markRateLimited(account, cooldownMs, family, headerStyle, model);
|
|
1088
|
-
const label = account.email || `Account ${account.index + 1}`;
|
|
1089
|
-
if (accountManager.shouldShowAccountToast(account.index, 60000)) {
|
|
1090
|
-
await showToast(`⚠ ${label} needs verification. Run 'opencode auth login' and use Verify accounts.`, 'warning');
|
|
1091
|
-
accountManager.markToastShown(account.index);
|
|
1092
|
-
}
|
|
1093
|
-
pushDebug(`verification-required: disabled account ${account.index}`);
|
|
1094
|
-
getHealthTracker().recordFailure(account.index);
|
|
1095
|
-
lastFailure = createFailureContext(response);
|
|
1096
|
-
shouldSwitchAccount = true;
|
|
1097
|
-
break;
|
|
1098
|
-
}
|
|
1099
|
-
}
|
|
1100
|
-
const shouldRetryEndpoint = response.status === 403 ||
|
|
1101
|
-
response.status === 404 ||
|
|
1102
|
-
response.status >= 500;
|
|
1103
|
-
if (shouldRetryEndpoint &&
|
|
1104
|
-
i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
|
|
1105
|
-
await logResponseBody(debugContext, response, response.status);
|
|
1106
|
-
lastFailure = createFailureContext(response);
|
|
1107
|
-
continue;
|
|
1108
|
-
}
|
|
1109
|
-
if (response.ok) {
|
|
1110
|
-
account.consecutiveFailures = 0;
|
|
1111
|
-
getHealthTracker().recordSuccess(account.index);
|
|
1112
|
-
accountManager.markAccountUsed(account.index);
|
|
1113
|
-
void triggerAsyncQuotaRefreshForAccount(account.index, config.quota_refresh_interval_minutes);
|
|
1114
|
-
const proactiveThreshold = config.proactive_rotation_threshold_percent ?? 20;
|
|
1115
|
-
if (proactiveThreshold > 0 &&
|
|
1116
|
-
accountManager.shouldProactivelyRotate(family, model, proactiveThreshold, softQuotaCacheTtlMs, accountSessionIdentity)) {
|
|
1117
|
-
const rotated = accountManager.proactivelyRotateForFamily(family, model, headerStyle, config.soft_quota_threshold_percent, softQuotaCacheTtlMs, accountSessionIdentity);
|
|
1118
|
-
if (rotated) {
|
|
1119
|
-
const remaining = account.cachedQuota?.[resolveQuotaGroup(family, model)]
|
|
1120
|
-
?.remainingFraction;
|
|
1121
|
-
const remainingPct = remaining != null ? `${(remaining * 100).toFixed(1)}%` : '?';
|
|
1122
|
-
pushDebug(`[ProactiveRotation] account ${account.index} quota ${remainingPct} < ${proactiveThreshold}%, pre-switched to account ${rotated.index} for next request`);
|
|
1123
|
-
pushDebug(`[ProactiveRotation] ${account.index} → ${rotated.index}` +
|
|
1124
|
-
` (warm=${accountManager.wasUsedInSession(rotated.index, accountSessionIdentity)})`);
|
|
1125
|
-
}
|
|
1126
|
-
}
|
|
1127
|
-
}
|
|
1128
|
-
logAntigravityDebugResponse(debugContext, response, {
|
|
1129
|
-
note: response.ok ? 'Success' : `Error ${response.status}`,
|
|
1130
|
-
});
|
|
1131
|
-
if (response.ok && !prepared.streaming) {
|
|
1132
|
-
await logResponseBody(debugContext, response, response.status);
|
|
1133
|
-
}
|
|
1134
|
-
if (!response.ok) {
|
|
1135
|
-
await logResponseBody(debugContext, response, response.status);
|
|
1136
|
-
if (response.status === 400) {
|
|
1137
|
-
const cloned = response.clone();
|
|
1138
|
-
const bodyText = await cloned.text();
|
|
1139
|
-
if (bodyText.includes('Prompt is too long') ||
|
|
1140
|
-
bodyText.includes('prompt_too_long')) {
|
|
1141
|
-
await showToast('Context too long - use /compact to reduce size', 'warning');
|
|
1142
|
-
const errorMessage = `[Antigravity Error] Context is too long for this model.\n\nPlease use /compact to reduce context size, then retry your request.\n\nAlternatively, you can:\n- Use /clear to start fresh\n- Use /undo to remove recent messages\n- Switch to a model with larger context window`;
|
|
1143
|
-
return createSyntheticErrorResponse(errorMessage, prepared.requestedModel);
|
|
1144
|
-
}
|
|
1145
|
-
}
|
|
1146
|
-
}
|
|
1147
|
-
if (response.ok && !prepared.streaming) {
|
|
1148
|
-
const maxAttempts = config.empty_response_max_attempts ?? 4;
|
|
1149
|
-
const retryDelayMs = config.empty_response_retry_delay_ms ?? 2000;
|
|
1150
|
-
const clonedForCheck = response.clone();
|
|
1151
|
-
const bodyText = await clonedForCheck.text();
|
|
1152
|
-
if (isEmptyResponseBody(bodyText)) {
|
|
1153
|
-
const emptyAttemptKey = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
|
|
1154
|
-
const currentAttempts = retryState.recordEmptyResponseAttempt(emptyAttemptKey);
|
|
1155
|
-
pushDebug(`empty-response: attempt ${currentAttempts}/${maxAttempts}`);
|
|
1156
|
-
if (currentAttempts < maxAttempts) {
|
|
1157
|
-
await showToast(`Empty response received. Retrying (${currentAttempts}/${maxAttempts})...`, 'warning');
|
|
1158
|
-
await sleep(retryDelayMs, abortSignal);
|
|
1159
|
-
continue;
|
|
1160
|
-
}
|
|
1161
|
-
retryState.clearEmptyResponseAttempts();
|
|
1162
|
-
return createSyntheticErrorResponse(`Empty response after ${currentAttempts} attempts for model ${prepared.effectiveModel ?? 'unknown'}.`, prepared.effectiveModel ?? 'unknown');
|
|
1163
|
-
}
|
|
1164
|
-
const _emptyAttemptKeyClean = `${prepared.sessionId ?? 'none'}:${prepared.effectiveModel ?? 'unknown'}`;
|
|
1165
|
-
retryState.clearEmptyResponseAttempts();
|
|
1166
|
-
}
|
|
1167
|
-
const transformedResponse = await transformAntigravityResponse(response, prepared.streaming, debugContext, prepared.requestedModel, prepared.projectId, prepared.endpoint, prepared.effectiveModel, prepared.sessionId, prepared.toolDebugMissing, prepared.toolDebugSummary, prepared.toolDebugPayload, debugLines, dumpContext);
|
|
1168
|
-
const contextError = transformedResponse.headers.get('x-antigravity-context-error');
|
|
1169
|
-
if (contextError) {
|
|
1170
|
-
if (contextError === 'prompt_too_long') {
|
|
1171
|
-
await showToast('Context too long - use /compact to reduce size, or trim your request', 'warning');
|
|
1172
|
-
}
|
|
1173
|
-
else if (contextError === 'tool_pairing') {
|
|
1174
|
-
await showToast('Tool call/result mismatch - use /compact to fix, or /undo last message', 'warning');
|
|
1175
|
-
}
|
|
1176
|
-
}
|
|
1177
|
-
if (apiRequestCount > 1) {
|
|
1178
|
-
pushDebug(`[Quota] Total API requests for this user message: ${apiRequestCount} (${apiRequestCount - 1} retries)`);
|
|
1179
|
-
}
|
|
1180
|
-
const dailyCounts = accountManager.getDailyRequestCounts(account.index);
|
|
1181
|
-
if (dailyCounts) {
|
|
1182
|
-
pushDebug(`[Quota] Account ${account.index} (${account.email ?? 'unknown'}) today: claude=${dailyCounts.claude} gemini=${dailyCounts.gemini}`);
|
|
1183
|
-
}
|
|
1184
|
-
const totalToday = accountManager.getTotalDailyRequests(family);
|
|
1185
|
-
pushDebug(`[Quota] Total ${family} requests today (all accounts): ${totalToday}`);
|
|
1186
|
-
const cachedQuota = account.cachedQuota;
|
|
1187
|
-
if (cachedQuota) {
|
|
1188
|
-
const quotaFamily = resolveQuotaGroup(family, model);
|
|
1189
|
-
const groupQuota = cachedQuota[quotaFamily];
|
|
1190
|
-
if (groupQuota?.remainingFraction != null) {
|
|
1191
|
-
const pct = Math.round(groupQuota.remainingFraction * 100);
|
|
1192
|
-
pushDebug(`[Quota] Account ${account.index} cached ${quotaFamily} remaining: ${pct}%${groupQuota.resetTime ? ` (resets ${groupQuota.resetTime})` : ''}`);
|
|
1193
|
-
}
|
|
1194
|
-
}
|
|
1195
|
-
const sessionSummary = accountManager.getSessionSummary();
|
|
1196
|
-
if (sessionSummary.durationMinutes >= 1) {
|
|
1197
|
-
const familyTotal = family === 'claude'
|
|
1198
|
-
? sessionSummary.totalClaude
|
|
1199
|
-
: sessionSummary.totalGemini;
|
|
1200
|
-
if (familyTotal > 0) {
|
|
1201
|
-
const ratePerHour = sessionSummary.requestsPerHour;
|
|
1202
|
-
pushDebug(`[Quota] Session: ${sessionSummary.durationMinutes}min, ${familyTotal} ${family} reqs, ~${ratePerHour} reqs/hr, ${sessionSummary.accountsUsed} accounts used`);
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
return transformedResponse;
|
|
1206
|
-
}
|
|
1207
|
-
catch (error) {
|
|
1208
|
-
if (tokenConsumed) {
|
|
1209
|
-
getTokenTracker().refund(account.index);
|
|
1210
|
-
tokenConsumed = false;
|
|
1211
|
-
}
|
|
1212
|
-
if (error instanceof Error &&
|
|
1213
|
-
error.message === 'THINKING_RECOVERY_NEEDED') {
|
|
1214
|
-
if (!forceThinkingRecovery) {
|
|
1215
|
-
pushDebug('thinking-recovery: API error detected, retrying with forced recovery');
|
|
1216
|
-
forceThinkingRecovery = true;
|
|
1217
|
-
i = -1;
|
|
1218
|
-
continue;
|
|
1219
|
-
}
|
|
1220
|
-
const recoveryError = error;
|
|
1221
|
-
const originalError = recoveryError.originalError || {
|
|
1222
|
-
error: { message: 'Thinking recovery triggered' },
|
|
1223
|
-
};
|
|
1224
|
-
const recoveryMessage = `${originalError.error?.message || 'Session recovery failed'}\n\n[RECOVERY] Thinking block corruption could not be resolved. Try starting a new session.`;
|
|
1225
|
-
return new Response(JSON.stringify({
|
|
1226
|
-
type: 'error',
|
|
1227
|
-
error: {
|
|
1228
|
-
type: 'unrecoverable_error',
|
|
1229
|
-
message: recoveryMessage,
|
|
1230
|
-
},
|
|
1231
|
-
}), {
|
|
1232
|
-
status: 400,
|
|
1233
|
-
headers: { 'Content-Type': 'application/json' },
|
|
1234
|
-
});
|
|
1235
|
-
}
|
|
1236
|
-
if (i < ANTIGRAVITY_ENDPOINT_FALLBACKS.length - 1) {
|
|
1237
|
-
lastError =
|
|
1238
|
-
error instanceof Error ? error : new Error(String(error));
|
|
1239
|
-
continue;
|
|
1240
|
-
}
|
|
1241
|
-
const { failures, shouldCooldown, cooldownMs } = retryState.trackAccountFailure(account.index);
|
|
1242
|
-
lastError =
|
|
1243
|
-
error instanceof Error ? error : new Error(String(error));
|
|
1244
|
-
if (shouldCooldown) {
|
|
1245
|
-
accountManager.markAccountCoolingDown(account, cooldownMs, 'network-error');
|
|
1246
|
-
accountManager.markRateLimited(account, cooldownMs, family, headerStyle, model);
|
|
1247
|
-
pushDebug(`endpoint-error: cooldown ${cooldownMs}ms after ${failures} failures`);
|
|
1248
|
-
}
|
|
1249
|
-
shouldSwitchAccount = true;
|
|
1250
|
-
break;
|
|
1251
|
-
}
|
|
1252
|
-
}
|
|
1253
|
-
}
|
|
1254
|
-
if (shouldSwitchAccount) {
|
|
1255
|
-
accountSwitchCount++;
|
|
1256
|
-
if (accountSwitchCount > maxAccountSwitches) {
|
|
1257
|
-
pushDebug(`account-switch-cap: exceeded max_account_switches=${maxAccountSwitches}, giving up`);
|
|
1258
|
-
if (lastFailure) {
|
|
1259
|
-
return transformAntigravityResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, lastFailure.toolDebugPayload, debugLines, lastFailure.dumpContext);
|
|
1260
|
-
}
|
|
1261
|
-
throw terminalFetchError(lastError, `Exceeded max account switches (${maxAccountSwitches}). All accounts rate-limited.`);
|
|
1262
|
-
}
|
|
1263
|
-
if (accountCount <= 1) {
|
|
1264
|
-
if (lastFailure) {
|
|
1265
|
-
return transformAntigravityResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, lastFailure.toolDebugPayload, debugLines, lastFailure.dumpContext);
|
|
1266
|
-
}
|
|
1267
|
-
throw terminalFetchError(lastError, 'All Antigravity endpoints failed');
|
|
1268
|
-
}
|
|
1269
|
-
continue;
|
|
1270
|
-
}
|
|
1271
|
-
if (lastFailure) {
|
|
1272
|
-
return transformAntigravityResponse(lastFailure.response, lastFailure.streaming, lastFailure.debugContext, lastFailure.requestedModel, lastFailure.projectId, lastFailure.endpoint, lastFailure.effectiveModel, lastFailure.sessionId, lastFailure.toolDebugMissing, lastFailure.toolDebugSummary, lastFailure.toolDebugPayload, debugLines, lastFailure.dumpContext);
|
|
1273
|
-
}
|
|
1274
|
-
throw terminalFetchError(lastError, 'All Antigravity accounts failed');
|
|
1275
|
-
}
|
|
199
|
+
// A retired interceptor has been replaced; a request reaching it now is
|
|
200
|
+
// refused rather than sent without this plugin's credentials.
|
|
201
|
+
if (retired)
|
|
202
|
+
throw new Error('The local request runtime is retired');
|
|
203
|
+
const pending = intercept(input, init);
|
|
204
|
+
entering.add(pending);
|
|
205
|
+
void pending.then(() => entering.delete(pending), () => entering.delete(pending));
|
|
206
|
+
return pending;
|
|
207
|
+
}
|
|
208
|
+
function retire() {
|
|
209
|
+
retired = true;
|
|
210
|
+
retirePromise ??= (async () => {
|
|
211
|
+
while (entering.size > 0)
|
|
212
|
+
await Promise.allSettled([...entering]);
|
|
213
|
+
await executor.retire();
|
|
214
|
+
})();
|
|
215
|
+
return retirePromise;
|
|
1276
216
|
}
|
|
1277
217
|
function dispose() {
|
|
1278
|
-
if (disposed)
|
|
1279
|
-
return;
|
|
1280
218
|
disposed = true;
|
|
1281
|
-
|
|
1282
|
-
|
|
219
|
+
disposePromise ??= (async () => {
|
|
220
|
+
await executor.dispose();
|
|
221
|
+
// Requests still reading their admission or the host sign-in stop at
|
|
222
|
+
// their next check; disposal reports done only once they have.
|
|
223
|
+
while (entering.size > 0)
|
|
224
|
+
await Promise.allSettled([...entering]);
|
|
225
|
+
// A retirement still waiting on those requests settles with them.
|
|
226
|
+
await retirePromise;
|
|
227
|
+
})();
|
|
228
|
+
return disposePromise;
|
|
1283
229
|
}
|
|
1284
|
-
return { fetch, dispose };
|
|
230
|
+
return { fetch, retire, dispose };
|
|
1285
231
|
}
|
|
1286
|
-
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1295
|
-
|
|
1296
|
-
|
|
1297
|
-
|
|
1298
|
-
|
|
1299
|
-
|
|
1300
|
-
|
|
1301
|
-
|
|
1302
|
-
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1309
|
-
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1319
|
-
|
|
1320
|
-
|
|
1321
|
-
|
|
1322
|
-
|
|
1323
|
-
}
|
|
1324
|
-
for (const detail of details) {
|
|
1325
|
-
if (!detail || typeof detail !== 'object')
|
|
1326
|
-
continue;
|
|
1327
|
-
const metadata = detail
|
|
1328
|
-
.metadata;
|
|
1329
|
-
if (metadata && typeof metadata === 'object') {
|
|
1330
|
-
const quotaResetDelay = metadata.quotaResetDelay;
|
|
1331
|
-
const quotaResetTime = metadata.quotaResetTimeStamp;
|
|
1332
|
-
if (typeof quotaResetDelay === 'string') {
|
|
1333
|
-
const quotaResetDelayMs = parseDurationToMs(quotaResetDelay);
|
|
1334
|
-
if (quotaResetDelayMs !== null) {
|
|
1335
|
-
return {
|
|
1336
|
-
retryDelayMs: quotaResetDelayMs,
|
|
1337
|
-
message,
|
|
1338
|
-
quotaResetTime,
|
|
1339
|
-
reason,
|
|
1340
|
-
};
|
|
1341
|
-
}
|
|
1342
|
-
}
|
|
1343
|
-
}
|
|
1344
|
-
}
|
|
1345
|
-
}
|
|
1346
|
-
if (message) {
|
|
1347
|
-
const afterMatch = message.match(/reset after\s+([0-9hms.]+)/i);
|
|
1348
|
-
const rawDuration = afterMatch?.[1];
|
|
1349
|
-
if (rawDuration) {
|
|
1350
|
-
const parsed = parseDurationToMs(rawDuration);
|
|
1351
|
-
if (parsed !== null) {
|
|
1352
|
-
return { retryDelayMs: parsed, message, reason };
|
|
1353
|
-
}
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
return { retryDelayMs: null, message, reason };
|
|
1357
|
-
}
|
|
1358
|
-
function parseDurationToMs(duration) {
|
|
1359
|
-
const simpleMatch = duration.match(/^(\d+(?:\.\d+)?)(ms|s|m|h)?$/i);
|
|
1360
|
-
if (simpleMatch) {
|
|
1361
|
-
const value = parseFloat(simpleMatch[1]);
|
|
1362
|
-
const unit = (simpleMatch[2] || 's').toLowerCase();
|
|
1363
|
-
switch (unit) {
|
|
1364
|
-
case 'h':
|
|
1365
|
-
return value * 3600 * 1000;
|
|
1366
|
-
case 'm':
|
|
1367
|
-
return value * 60 * 1000;
|
|
1368
|
-
case 's':
|
|
1369
|
-
return value * 1000;
|
|
1370
|
-
case 'ms':
|
|
1371
|
-
return value;
|
|
1372
|
-
default:
|
|
1373
|
-
return value * 1000;
|
|
1374
|
-
}
|
|
232
|
+
/**
|
|
233
|
+
* OpenCode 1 binding of the shared request engine for vault-held accounts.
|
|
234
|
+
* Selection runs on an `AccountSelector` over the vault's selectable routes
|
|
235
|
+
* (metadata rows, no credential). Every physical send takes a fresh receipt
|
|
236
|
+
* for the selected route through `createVaultRequestCredentials`: its token
|
|
237
|
+
* and project serve that one send, and a 401 is reported against it.
|
|
238
|
+
* Nothing is refreshed locally, cached or copied from the host's own Google
|
|
239
|
+
* sign-in, which is why no host auth is read here.
|
|
240
|
+
*/
|
|
241
|
+
export function createVaultFetchInterceptor(context) {
|
|
242
|
+
const { source, agyTransport = defaultAgyTransport, fetchImpl = defaultFetchImpl, } = context;
|
|
243
|
+
const upstreamFetch = fetchImpl;
|
|
244
|
+
const pool = context.pool ?? createVaultAccountPool({ source });
|
|
245
|
+
const selector = pool.selector;
|
|
246
|
+
const executor = createRequestExecutor({
|
|
247
|
+
assertAdmission: context.assertAdmission,
|
|
248
|
+
...openCode1EngineCollaborators({
|
|
249
|
+
...context,
|
|
250
|
+
transport: agyTransport,
|
|
251
|
+
fetchImpl: upstreamFetch,
|
|
252
|
+
}),
|
|
253
|
+
accounts: selector,
|
|
254
|
+
credentials: pool.credentials,
|
|
255
|
+
trackers: {
|
|
256
|
+
health: selector.healthTracker,
|
|
257
|
+
token: selector.tokenTracker,
|
|
258
|
+
},
|
|
259
|
+
});
|
|
260
|
+
let disposed = false;
|
|
261
|
+
let disposePromise;
|
|
262
|
+
async function fetch(input, init) {
|
|
263
|
+
if (!isGenerativeLanguageRequest(input))
|
|
264
|
+
return upstreamFetch(input, init);
|
|
265
|
+
if (disposed)
|
|
266
|
+
throw new Error('The vault request runtime is disposed');
|
|
267
|
+
await pool.sync();
|
|
268
|
+
return executor.execute(input, init);
|
|
1375
269
|
}
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1379
|
-
|
|
1380
|
-
|
|
1381
|
-
|
|
1382
|
-
|
|
1383
|
-
break;
|
|
1384
|
-
matchFound = true;
|
|
1385
|
-
const value = parseFloat(match[1]);
|
|
1386
|
-
const unit = match[2]?.toLowerCase();
|
|
1387
|
-
switch (unit) {
|
|
1388
|
-
case 'h':
|
|
1389
|
-
totalMs += value * 3600 * 1000;
|
|
1390
|
-
break;
|
|
1391
|
-
case 'm':
|
|
1392
|
-
totalMs += value * 60 * 1000;
|
|
1393
|
-
break;
|
|
1394
|
-
case 's':
|
|
1395
|
-
totalMs += value * 1000;
|
|
1396
|
-
break;
|
|
1397
|
-
case 'ms':
|
|
1398
|
-
totalMs += value;
|
|
1399
|
-
break;
|
|
1400
|
-
}
|
|
270
|
+
function dispose() {
|
|
271
|
+
disposed = true;
|
|
272
|
+
disposePromise ??= (async () => {
|
|
273
|
+
await executor.dispose();
|
|
274
|
+
await pool.flush();
|
|
275
|
+
})();
|
|
276
|
+
return disposePromise;
|
|
1401
277
|
}
|
|
1402
|
-
return
|
|
278
|
+
return { fetch, dispose };
|
|
1403
279
|
}
|
|
1404
280
|
//# sourceMappingURL=fetch-interceptor.js.map
|