@cortexkit/opencode-antigravity-auth 1.1.0 → 2.0.1
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 +225 -569
- package/dist/cli.js +4017 -0
- package/dist/cli.js.map +7 -0
- package/dist/index.d.ts +1 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +20742 -14586
- package/dist/index.js.map +4 -4
- package/dist/src/antigravity/oauth.d.ts +1 -1
- package/dist/src/antigravity/oauth.js +1 -1
- package/dist/src/cli.d.ts +21 -0
- package/dist/src/cli.d.ts.map +1 -0
- package/dist/src/cli.js +237 -0
- package/dist/src/cli.js.map +1 -0
- package/dist/src/constants.d.ts +1 -1
- package/dist/src/constants.js +1 -1
- package/dist/src/hooks/auto-update-checker/cache.d.ts.map +1 -1
- package/dist/src/hooks/auto-update-checker/cache.js +13 -13
- package/dist/src/hooks/auto-update-checker/cache.js.map +1 -1
- package/dist/src/hooks/auto-update-checker/checker.d.ts +1 -1
- package/dist/src/hooks/auto-update-checker/checker.d.ts.map +1 -1
- package/dist/src/hooks/auto-update-checker/checker.js +75 -51
- package/dist/src/hooks/auto-update-checker/checker.js.map +1 -1
- package/dist/src/hooks/auto-update-checker/constants.d.ts.map +1 -1
- package/dist/src/hooks/auto-update-checker/constants.js +12 -12
- package/dist/src/hooks/auto-update-checker/constants.js.map +1 -1
- package/dist/src/hooks/auto-update-checker/index.d.ts +6 -6
- package/dist/src/hooks/auto-update-checker/index.d.ts.map +1 -1
- package/dist/src/hooks/auto-update-checker/index.js +17 -17
- package/dist/src/hooks/auto-update-checker/index.js.map +1 -1
- package/dist/src/hooks/auto-update-checker/logging.js +2 -2
- package/dist/src/hooks/auto-update-checker/logging.js.map +1 -1
- package/dist/src/hooks/auto-update-checker/types.d.ts.map +1 -1
- package/dist/src/plugin/account-access.d.ts +99 -0
- package/dist/src/plugin/account-access.d.ts.map +1 -0
- package/dist/src/plugin/account-access.js +480 -0
- package/dist/src/plugin/account-access.js.map +1 -0
- package/dist/src/plugin/account-command-oauth.d.ts +34 -0
- package/dist/src/plugin/account-command-oauth.d.ts.map +1 -0
- package/dist/src/plugin/account-command-oauth.js +156 -0
- package/dist/src/plugin/account-command-oauth.js.map +1 -0
- package/dist/src/plugin/accounts.d.ts +7 -256
- package/dist/src/plugin/accounts.d.ts.map +1 -1
- package/dist/src/plugin/accounts.js +31 -1367
- package/dist/src/plugin/accounts.js.map +1 -1
- package/dist/src/plugin/agy-request-metadata.d.ts +1 -1
- package/dist/src/plugin/agy-request-metadata.js +1 -1
- package/dist/src/plugin/agy-transport.d.ts +1 -1
- package/dist/src/plugin/agy-transport.js +1 -1
- package/dist/src/plugin/auth-doctor.d.ts +6 -6
- package/dist/src/plugin/auth-doctor.d.ts.map +1 -1
- package/dist/src/plugin/auth-doctor.js +74 -66
- package/dist/src/plugin/auth-doctor.js.map +1 -1
- package/dist/src/plugin/auth-drift.d.ts +4 -4
- package/dist/src/plugin/auth-drift.d.ts.map +1 -1
- package/dist/src/plugin/auth-drift.js +15 -15
- package/dist/src/plugin/auth-drift.js.map +1 -1
- package/dist/src/plugin/auth-loader.d.ts +50 -0
- package/dist/src/plugin/auth-loader.d.ts.map +1 -0
- package/dist/src/plugin/auth-loader.js +225 -0
- package/dist/src/plugin/auth-loader.js.map +1 -0
- package/dist/src/plugin/auth.d.ts +1 -1
- package/dist/src/plugin/auth.js +1 -1
- package/dist/src/plugin/background-quota-refresh.d.ts +146 -0
- package/dist/src/plugin/background-quota-refresh.d.ts.map +1 -0
- package/dist/src/plugin/background-quota-refresh.js +347 -0
- package/dist/src/plugin/background-quota-refresh.js.map +1 -0
- 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 +1 -1
- package/dist/src/plugin/cache/signature-cache.d.ts.map +1 -1
- package/dist/src/plugin/cache/signature-cache.js +23 -24
- package/dist/src/plugin/cache/signature-cache.js.map +1 -1
- package/dist/src/plugin/cache.d.ts +6 -5
- package/dist/src/plugin/cache.d.ts.map +1 -1
- package/dist/src/plugin/cache.js +21 -7
- package/dist/src/plugin/cache.js.map +1 -1
- package/dist/src/plugin/catalog.d.ts +23 -0
- package/dist/src/plugin/catalog.d.ts.map +1 -0
- package/dist/src/plugin/catalog.js +60 -0
- package/dist/src/plugin/catalog.js.map +1 -0
- package/dist/src/plugin/cli.d.ts +7 -7
- package/dist/src/plugin/cli.d.ts.map +1 -1
- package/dist/src/plugin/cli.js +62 -55
- package/dist/src/plugin/cli.js.map +1 -1
- package/dist/src/plugin/command-data.d.ts +329 -0
- package/dist/src/plugin/command-data.d.ts.map +1 -0
- package/dist/src/plugin/command-data.js +517 -0
- package/dist/src/plugin/command-data.js.map +1 -0
- package/dist/src/plugin/commands.d.ts +154 -0
- package/dist/src/plugin/commands.d.ts.map +1 -0
- package/dist/src/plugin/commands.js +746 -0
- package/dist/src/plugin/commands.js.map +1 -0
- package/dist/src/plugin/config/index.d.ts +2 -2
- package/dist/src/plugin/config/index.d.ts.map +1 -1
- package/dist/src/plugin/config/index.js +2 -2
- package/dist/src/plugin/config/index.js.map +1 -1
- package/dist/src/plugin/config/loader.d.ts +1 -1
- package/dist/src/plugin/config/loader.d.ts.map +1 -1
- package/dist/src/plugin/config/loader.js +18 -16
- package/dist/src/plugin/config/loader.js.map +1 -1
- package/dist/src/plugin/config/models.d.ts +2 -2
- package/dist/src/plugin/config/models.d.ts.map +1 -1
- package/dist/src/plugin/config/models.js +1 -1
- package/dist/src/plugin/config/models.js.map +1 -1
- package/dist/src/plugin/config/operator-settings-schema.d.ts +29 -0
- package/dist/src/plugin/config/operator-settings-schema.d.ts.map +1 -0
- package/dist/src/plugin/config/operator-settings-schema.js +28 -0
- package/dist/src/plugin/config/operator-settings-schema.js.map +1 -0
- package/dist/src/plugin/config/schema.d.ts +23 -2
- package/dist/src/plugin/config/schema.d.ts.map +1 -1
- package/dist/src/plugin/config/schema.js +109 -25
- package/dist/src/plugin/config/schema.js.map +1 -1
- package/dist/src/plugin/config/updater.d.ts.map +1 -1
- package/dist/src/plugin/config/updater.js +15 -15
- package/dist/src/plugin/config/updater.js.map +1 -1
- package/dist/src/plugin/config/writer.d.ts +34 -0
- package/dist/src/plugin/config/writer.d.ts.map +1 -0
- package/dist/src/plugin/config/writer.js +81 -0
- package/dist/src/plugin/config/writer.js.map +1 -0
- package/dist/src/plugin/core/streaming/index.d.ts +1 -1
- package/dist/src/plugin/core/streaming/index.d.ts.map +1 -1
- package/dist/src/plugin/core/streaming/index.js +1 -1
- package/dist/src/plugin/core/streaming/index.js.map +1 -1
- package/dist/src/plugin/core/streaming/transformer.d.ts.map +1 -1
- package/dist/src/plugin/core/streaming/transformer.js +85 -44
- package/dist/src/plugin/core/streaming/transformer.js.map +1 -1
- package/dist/src/plugin/core/streaming/types.d.ts.map +1 -1
- package/dist/src/plugin/debug.d.ts +10 -3
- package/dist/src/plugin/debug.d.ts.map +1 -1
- package/dist/src/plugin/debug.js +110 -47
- package/dist/src/plugin/debug.js.map +1 -1
- package/dist/src/plugin/dependencies.d.ts +129 -0
- package/dist/src/plugin/dependencies.d.ts.map +1 -0
- package/dist/src/plugin/dependencies.js +107 -0
- package/dist/src/plugin/dependencies.js.map +1 -0
- package/dist/src/plugin/errors.d.ts +27 -0
- package/dist/src/plugin/errors.d.ts.map +1 -1
- package/dist/src/plugin/errors.js +29 -3
- package/dist/src/plugin/errors.js.map +1 -1
- package/dist/src/plugin/event-handler.d.ts +53 -0
- package/dist/src/plugin/event-handler.d.ts.map +1 -0
- package/dist/src/plugin/event-handler.js +101 -0
- package/dist/src/plugin/event-handler.js.map +1 -0
- package/dist/src/plugin/fetch/retry-state.d.ts +61 -0
- package/dist/src/plugin/fetch/retry-state.d.ts.map +1 -0
- package/dist/src/plugin/fetch/retry-state.js +248 -0
- package/dist/src/plugin/fetch/retry-state.js.map +1 -0
- package/dist/src/plugin/fetch/warmup.d.ts +30 -0
- package/dist/src/plugin/fetch/warmup.d.ts.map +1 -0
- package/dist/src/plugin/fetch/warmup.js +76 -0
- package/dist/src/plugin/fetch/warmup.js.map +1 -0
- package/dist/src/plugin/fetch-interceptor.d.ts +59 -0
- package/dist/src/plugin/fetch-interceptor.d.ts.map +1 -0
- package/dist/src/plugin/fetch-interceptor.js +1399 -0
- package/dist/src/plugin/fetch-interceptor.js.map +1 -0
- package/dist/src/plugin/fetch-routing.d.ts +26 -0
- package/dist/src/plugin/fetch-routing.d.ts.map +1 -0
- package/dist/src/plugin/fetch-routing.js +99 -0
- package/dist/src/plugin/fetch-routing.js.map +1 -0
- package/dist/src/plugin/fingerprint.d.ts +1 -1
- package/dist/src/plugin/fingerprint.js +1 -1
- package/dist/src/plugin/gemini-dump.d.ts +5 -5
- package/dist/src/plugin/gemini-dump.d.ts.map +1 -1
- package/dist/src/plugin/gemini-dump.js +109 -55
- package/dist/src/plugin/gemini-dump.js.map +1 -1
- package/dist/src/plugin/google-search-tool.d.ts +9 -0
- package/dist/src/plugin/google-search-tool.d.ts.map +1 -0
- package/dist/src/plugin/google-search-tool.js +56 -0
- package/dist/src/plugin/google-search-tool.js.map +1 -0
- package/dist/src/plugin/image-saver.d.ts.map +1 -1
- package/dist/src/plugin/image-saver.js +16 -16
- package/dist/src/plugin/image-saver.js.map +1 -1
- package/dist/src/plugin/index.d.ts +30 -0
- package/dist/src/plugin/index.d.ts.map +1 -0
- package/dist/src/plugin/index.js +411 -0
- package/dist/src/plugin/index.js.map +1 -0
- package/dist/src/plugin/killswitch.d.ts +94 -0
- package/dist/src/plugin/killswitch.d.ts.map +1 -0
- package/dist/src/plugin/killswitch.js +197 -0
- package/dist/src/plugin/killswitch.js.map +1 -0
- package/dist/src/plugin/lifecycle.d.ts +40 -0
- package/dist/src/plugin/lifecycle.d.ts.map +1 -0
- package/dist/src/plugin/lifecycle.js +73 -0
- package/dist/src/plugin/lifecycle.js.map +1 -0
- package/dist/src/plugin/logger.d.ts +10 -1
- package/dist/src/plugin/logger.d.ts.map +1 -1
- package/dist/src/plugin/logger.js +38 -12
- package/dist/src/plugin/logger.js.map +1 -1
- package/dist/src/plugin/logging-utils.d.ts +35 -1
- package/dist/src/plugin/logging-utils.d.ts.map +1 -1
- package/dist/src/plugin/logging-utils.js +98 -15
- package/dist/src/plugin/logging-utils.js.map +1 -1
- package/dist/src/plugin/model-registry.d.ts +1 -1
- package/dist/src/plugin/model-registry.js +1 -1
- package/dist/src/plugin/oauth-login.d.ts +22 -0
- package/dist/src/plugin/oauth-login.d.ts.map +1 -0
- package/dist/src/plugin/oauth-login.js +37 -0
- package/dist/src/plugin/oauth-login.js.map +1 -0
- package/dist/src/plugin/oauth-methods.d.ts +42 -0
- package/dist/src/plugin/oauth-methods.d.ts.map +1 -0
- package/dist/src/plugin/oauth-methods.js +1276 -0
- package/dist/src/plugin/oauth-methods.js.map +1 -0
- package/dist/src/plugin/operator-settings.d.ts +40 -0
- package/dist/src/plugin/operator-settings.d.ts.map +1 -0
- package/dist/src/plugin/operator-settings.js +148 -0
- package/dist/src/plugin/operator-settings.js.map +1 -0
- package/dist/src/plugin/persist-account-pool.d.ts +37 -0
- package/dist/src/plugin/persist-account-pool.d.ts.map +1 -0
- package/dist/src/plugin/persist-account-pool.js +142 -0
- package/dist/src/plugin/persist-account-pool.js.map +1 -0
- package/dist/src/plugin/project.d.ts +1 -1
- package/dist/src/plugin/project.js +1 -1
- package/dist/src/plugin/prompt-context.d.ts.map +1 -1
- package/dist/src/plugin/prompt-context.js +11 -11
- package/dist/src/plugin/prompt-context.js.map +1 -1
- package/dist/src/plugin/quota.d.ts +138 -41
- package/dist/src/plugin/quota.d.ts.map +1 -1
- package/dist/src/plugin/quota.js +417 -285
- package/dist/src/plugin/quota.js.map +1 -1
- package/dist/src/plugin/recovery/constants.d.ts.map +1 -1
- package/dist/src/plugin/recovery/constants.js +24 -15
- package/dist/src/plugin/recovery/constants.js.map +1 -1
- package/dist/src/plugin/recovery/index.d.ts +3 -3
- package/dist/src/plugin/recovery/index.d.ts.map +1 -1
- package/dist/src/plugin/recovery/index.js +3 -3
- package/dist/src/plugin/recovery/index.js.map +1 -1
- package/dist/src/plugin/recovery/storage.d.ts +1 -1
- package/dist/src/plugin/recovery/storage.d.ts.map +1 -1
- package/dist/src/plugin/recovery/storage.js +31 -39
- package/dist/src/plugin/recovery/storage.js.map +1 -1
- package/dist/src/plugin/recovery/types.d.ts +12 -12
- package/dist/src/plugin/recovery/types.d.ts.map +1 -1
- package/dist/src/plugin/recovery.d.ts +3 -3
- package/dist/src/plugin/recovery.d.ts.map +1 -1
- package/dist/src/plugin/recovery.js +62 -58
- package/dist/src/plugin/recovery.js.map +1 -1
- package/dist/src/plugin/refresh-queue.d.ts +5 -2
- package/dist/src/plugin/refresh-queue.d.ts.map +1 -1
- package/dist/src/plugin/refresh-queue.js +37 -15
- package/dist/src/plugin/refresh-queue.js.map +1 -1
- package/dist/src/plugin/request-helpers.d.ts +1 -1
- package/dist/src/plugin/request-helpers.d.ts.map +1 -1
- package/dist/src/plugin/request-helpers.js +451 -352
- package/dist/src/plugin/request-helpers.js.map +1 -1
- package/dist/src/plugin/request.d.ts +7 -7
- package/dist/src/plugin/request.d.ts.map +1 -1
- package/dist/src/plugin/request.js +622 -384
- package/dist/src/plugin/request.js.map +1 -1
- package/dist/src/plugin/rotation.d.ts +1 -168
- package/dist/src/plugin/rotation.d.ts.map +1 -1
- package/dist/src/plugin/rotation.js +1 -327
- package/dist/src/plugin/rotation.js.map +1 -1
- package/dist/src/plugin/search.d.ts.map +1 -1
- package/dist/src/plugin/search.js +39 -35
- package/dist/src/plugin/search.js.map +1 -1
- package/dist/src/plugin/server.d.ts +1 -1
- package/dist/src/plugin/server.d.ts.map +1 -1
- package/dist/src/plugin/server.js +42 -37
- package/dist/src/plugin/server.js.map +1 -1
- package/dist/src/plugin/session-context.d.ts +2 -1
- package/dist/src/plugin/session-context.d.ts.map +1 -1
- package/dist/src/plugin/session-context.js +11 -7
- package/dist/src/plugin/session-context.js.map +1 -1
- package/dist/src/plugin/storage.d.ts +59 -120
- package/dist/src/plugin/storage.d.ts.map +1 -1
- package/dist/src/plugin/storage.js +140 -485
- package/dist/src/plugin/storage.js.map +1 -1
- package/dist/src/plugin/stores/signature-store.d.ts.map +1 -1
- package/dist/src/plugin/stores/signature-store.js.map +1 -1
- package/dist/src/plugin/thinking-recovery.d.ts.map +1 -1
- package/dist/src/plugin/thinking-recovery.js +35 -33
- package/dist/src/plugin/thinking-recovery.js.map +1 -1
- package/dist/src/plugin/token.d.ts +2 -2
- package/dist/src/plugin/token.d.ts.map +1 -1
- package/dist/src/plugin/token.js +30 -21
- package/dist/src/plugin/token.js.map +1 -1
- package/dist/src/plugin/transform/cross-model-sanitizer.d.ts +1 -1
- package/dist/src/plugin/transform/cross-model-sanitizer.js +1 -1
- package/dist/src/plugin/transform/index.d.ts +1 -1
- package/dist/src/plugin/transform/index.js +1 -1
- package/dist/src/plugin/transform/model-resolver.d.ts +1 -1
- package/dist/src/plugin/transform/model-resolver.js +1 -1
- package/dist/src/plugin/transform/types.d.ts +1 -1
- package/dist/src/plugin/transform/types.js +1 -1
- package/dist/src/plugin/types.d.ts +25 -69
- package/dist/src/plugin/types.d.ts.map +1 -1
- package/dist/src/plugin/ui/ansi.d.ts.map +1 -1
- package/dist/src/plugin/ui/ansi.js.map +1 -1
- package/dist/src/plugin/ui/auth-menu.d.ts +1 -1
- package/dist/src/plugin/ui/auth-menu.d.ts.map +1 -1
- package/dist/src/plugin/ui/auth-menu.js +84 -35
- package/dist/src/plugin/ui/auth-menu.js.map +1 -1
- package/dist/src/plugin/ui/confirm.d.ts.map +1 -1
- package/dist/src/plugin/ui/confirm.js.map +1 -1
- package/dist/src/plugin/ui/model-status.d.ts +3 -3
- package/dist/src/plugin/ui/model-status.d.ts.map +1 -1
- package/dist/src/plugin/ui/model-status.js +3 -3
- package/dist/src/plugin/ui/model-status.js.map +1 -1
- package/dist/src/plugin/ui/quota-status.d.ts +4 -4
- package/dist/src/plugin/ui/quota-status.d.ts.map +1 -1
- package/dist/src/plugin/ui/quota-status.js +49 -49
- package/dist/src/plugin/ui/quota-status.js.map +1 -1
- package/dist/src/plugin/ui/select.d.ts.map +1 -1
- package/dist/src/plugin/ui/select.js +22 -12
- package/dist/src/plugin/ui/select.js.map +1 -1
- package/dist/src/plugin/version.d.ts +1 -1
- package/dist/src/plugin/version.js +1 -1
- package/dist/src/rpc/notifications.d.ts +6 -0
- package/dist/src/rpc/notifications.d.ts.map +1 -0
- package/dist/src/rpc/notifications.js +46 -0
- package/dist/src/rpc/notifications.js.map +1 -0
- package/dist/src/rpc/port-file.d.ts +13 -0
- package/dist/src/rpc/port-file.d.ts.map +1 -0
- package/dist/src/rpc/port-file.js +109 -0
- package/dist/src/rpc/port-file.js.map +1 -0
- package/dist/src/rpc/protocol.d.ts +22 -0
- package/dist/src/rpc/protocol.d.ts.map +1 -0
- package/dist/src/rpc/protocol.js +1 -0
- package/dist/src/rpc/protocol.js.map +1 -0
- package/dist/src/rpc/rpc-client.d.ts +10 -0
- package/dist/src/rpc/rpc-client.d.ts.map +1 -0
- package/dist/src/rpc/rpc-client.js +58 -0
- package/dist/src/rpc/rpc-client.js.map +1 -0
- package/dist/src/rpc/rpc-dir.d.ts +4 -0
- package/dist/src/rpc/rpc-dir.d.ts.map +1 -0
- package/dist/src/rpc/rpc-dir.js +19 -0
- package/dist/src/rpc/rpc-dir.js.map +1 -0
- package/dist/src/rpc/rpc-server.d.ts +13 -0
- package/dist/src/rpc/rpc-server.d.ts.map +1 -0
- package/dist/src/rpc/rpc-server.js +231 -0
- package/dist/src/rpc/rpc-server.js.map +1 -0
- package/dist/src/sidebar-state.d.ts +357 -0
- package/dist/src/sidebar-state.d.ts.map +1 -0
- package/dist/src/sidebar-state.js +680 -0
- package/dist/src/sidebar-state.js.map +1 -0
- package/dist/src/tui/command-dialogs.d.ts +61 -0
- package/dist/src/tui/command-dialogs.d.ts.map +1 -0
- package/dist/src/tui/command-dialogs.js +595 -0
- package/dist/src/tui/command-dialogs.js.map +1 -0
- package/dist/src/tui/file-logger.d.ts +41 -0
- package/dist/src/tui/file-logger.d.ts.map +1 -0
- package/dist/src/tui/file-logger.js +114 -0
- package/dist/src/tui/file-logger.js.map +1 -0
- package/dist/src/tui-preferences.d.ts +40 -0
- package/dist/src/tui-preferences.d.ts.map +1 -0
- package/dist/src/tui-preferences.js +328 -0
- package/dist/src/tui-preferences.js.map +1 -0
- package/dist/src/tui.d.ts +68 -0
- package/dist/src/tui.d.ts.map +1 -0
- package/dist/src/tui.js +697 -0
- package/dist/src/tui.js.map +1 -0
- package/package.json +46 -22
- package/src/plugin/command-data.ts +931 -0
- package/src/rpc/port-file.ts +143 -0
- package/src/rpc/protocol.ts +31 -0
- package/src/rpc/rpc-client.ts +102 -0
- package/src/rpc/rpc-dir.ts +24 -0
- package/src/sidebar-state.ts +991 -0
- package/src/tui/command-dialogs.tsx +832 -0
- package/src/tui/entry.mjs +74 -0
- package/src/tui/file-logger.ts +145 -0
- package/src/tui-compiled/plugin/command-data.ts +931 -0
- package/src/tui-compiled/rpc/port-file.ts +143 -0
- package/src/tui-compiled/rpc/protocol.ts +31 -0
- package/src/tui-compiled/rpc/rpc-client.ts +102 -0
- package/src/tui-compiled/rpc/rpc-dir.ts +24 -0
- package/src/tui-compiled/sidebar-state.ts +991 -0
- package/src/tui-compiled/tui/command-dialogs.tsx +779 -0
- package/src/tui-compiled/tui/file-logger.ts +145 -0
- package/src/tui-compiled/tui-preferences.ts +416 -0
- package/src/tui-compiled/tui.tsx +1193 -0
- package/src/tui-preferences.ts +416 -0
- package/src/tui.tsx +1171 -0
- package/dist/src/plugin.d.ts +0 -48
- package/dist/src/plugin.d.ts.map +0 -1
- package/dist/src/plugin.js +0 -3311
- package/dist/src/plugin.js.map +0 -1
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
import { createHash } from 'node:crypto';
|
|
2
|
+
import { getHealthTracker } from '@cortexkit/antigravity-auth-core';
|
|
3
|
+
import { buildSidebarMachineStateFromAccounts, isAccountCurrent, setSidebarMachineState, toCapturedTier, } from '../sidebar-state';
|
|
4
|
+
import { AccountManager } from './accounts';
|
|
5
|
+
import { isOAuthAuth } from './auth';
|
|
6
|
+
import { buildAuthFromStoredAccount, detectAuthStorageDrift, } from './auth-drift';
|
|
7
|
+
import { getLogFilePath, isDebugEnabled } from './debug';
|
|
8
|
+
import { createLogger } from './logger';
|
|
9
|
+
import { createProactiveRefreshQueue, } from './refresh-queue';
|
|
10
|
+
import { AccountStorageUnreadableError, clearAccounts, loadAccounts, } from './storage';
|
|
11
|
+
const log = createLogger('auth-loader');
|
|
12
|
+
/**
|
|
13
|
+
* Opaque identity derived from a refresh token. Mirrors the local
|
|
14
|
+
* helper in `account-manager.ts` and `command-data.ts` — the auth-loader
|
|
15
|
+
* stays independent because it ships in the plugin's import graph and
|
|
16
|
+
* can't reach into the core barrel for `quotaAccountIdentity`. The
|
|
17
|
+
* sidebar projection uses this hash to detect a stale quota snapshot
|
|
18
|
+
* captured for a different account after an index shift.
|
|
19
|
+
*/
|
|
20
|
+
function refreshTokenIdentity(refreshToken) {
|
|
21
|
+
return createHash('sha256').update(refreshToken).digest('hex').slice(0, 16);
|
|
22
|
+
}
|
|
23
|
+
export function createAuthLoader({ client, providerId, config, lifecycle, createFetch, onGetAuth, dependencies, }) {
|
|
24
|
+
const deps = {
|
|
25
|
+
loadAccounts: dependencies?.loadAccounts ?? loadAccounts,
|
|
26
|
+
clearAccounts: dependencies?.clearAccounts ?? clearAccounts,
|
|
27
|
+
loadAccountManager: dependencies?.loadAccountManager ??
|
|
28
|
+
((auth) => AccountManager.loadFromDisk(auth)),
|
|
29
|
+
createRefreshQueue: dependencies?.createRefreshQueue ?? createProactiveRefreshQueue,
|
|
30
|
+
isDebugEnabled: dependencies?.isDebugEnabled ?? isDebugEnabled,
|
|
31
|
+
getLogFilePath: dependencies?.getLogFilePath ?? getLogFilePath,
|
|
32
|
+
};
|
|
33
|
+
let fetchRuntime = null;
|
|
34
|
+
// Reload chain — `installRuntime` swaps the fetch runtime and
|
|
35
|
+
// (previously) discarded the previous runtime's dispose with `void`,
|
|
36
|
+
// so two overlapping reloads could interleave teardown. Serialize
|
|
37
|
+
// reloads through a single shared promise so each new install waits
|
|
38
|
+
// for the previous one to fully settle (including its dispose)
|
|
39
|
+
// before tearing down the runtime it depends on.
|
|
40
|
+
let reloadChain = Promise.resolve();
|
|
41
|
+
lifecycle.register({
|
|
42
|
+
async dispose() {
|
|
43
|
+
const runtime = fetchRuntime;
|
|
44
|
+
fetchRuntime = null;
|
|
45
|
+
await runtime?.dispose();
|
|
46
|
+
},
|
|
47
|
+
}, 'producer');
|
|
48
|
+
// Reload hook: invoked after out-of-band storage mutations (e.g.
|
|
49
|
+
// OAuth add) so the live AccountManager + fetch interceptor see the
|
|
50
|
+
// newly-persisted account without waiting for a plugin restart. The
|
|
51
|
+
// handle returned below wires this through to the OAuth finish flow.
|
|
52
|
+
let reloadRuntime = async () => { };
|
|
53
|
+
const installRuntime = async (accountManager, getAuth) => {
|
|
54
|
+
if (accountManager.getAccountCount() > 0) {
|
|
55
|
+
accountManager.requestSaveToDisk();
|
|
56
|
+
}
|
|
57
|
+
let refreshQueue = null;
|
|
58
|
+
if (config.proactive_token_refresh &&
|
|
59
|
+
accountManager.getAccountCount() > 0) {
|
|
60
|
+
refreshQueue = deps.createRefreshQueue(client, providerId, {
|
|
61
|
+
enabled: config.proactive_token_refresh,
|
|
62
|
+
bufferSeconds: config.proactive_refresh_buffer_seconds,
|
|
63
|
+
checkIntervalSeconds: config.proactive_refresh_check_interval_seconds,
|
|
64
|
+
});
|
|
65
|
+
refreshQueue.setAccountManager(accountManager);
|
|
66
|
+
}
|
|
67
|
+
await lifecycle.replaceAccountRuntime(accountManager, refreshQueue);
|
|
68
|
+
refreshQueue?.start();
|
|
69
|
+
// Swap the fetch runtime FIRST so the host's captured fetch
|
|
70
|
+
// reference (a call-time delegating wrapper below) immediately
|
|
71
|
+
// routes through the new interceptor, then await the previous
|
|
72
|
+
// runtime's dispose. The swap-then-dispose order guarantees there
|
|
73
|
+
// is no fetch gap between the old and new runtimes.
|
|
74
|
+
const previousRuntime = fetchRuntime;
|
|
75
|
+
fetchRuntime = createFetch({ accountManager, getAuth });
|
|
76
|
+
await previousRuntime?.dispose();
|
|
77
|
+
// Push the freshly materialized account pool into the sidebar so the
|
|
78
|
+
// TUI's next poll renders the labels / health / cooldown it needs
|
|
79
|
+
// without waiting for the first fetch to complete.
|
|
80
|
+
await setSidebarMachineState(buildSidebarMachineStateFromAccounts(accountManager.getAccounts().map((entry) => {
|
|
81
|
+
const activeByFamily = accountManager.getActiveIndexByFamily();
|
|
82
|
+
return {
|
|
83
|
+
index: entry.index,
|
|
84
|
+
label: entry.label,
|
|
85
|
+
enabled: entry.enabled,
|
|
86
|
+
current: isAccountCurrent(entry.index, activeByFamily),
|
|
87
|
+
coolingDownUntil: entry.coolingDownUntil,
|
|
88
|
+
healthScore: getHealthTracker().getScore(entry.index),
|
|
89
|
+
cachedQuota: entry.cachedQuota,
|
|
90
|
+
// Stamp the sidebar snapshot so the projection can detect a
|
|
91
|
+
// stale cache that landed on the wrong account (the manager's
|
|
92
|
+
// `cachedQuotaAccountId` is keyed to whatever account actually
|
|
93
|
+
// produced the snapshot — the live refresh-token hash is the
|
|
94
|
+
// expected identity at this slot).
|
|
95
|
+
cachedQuotaAccountId: entry.cachedQuotaAccountId,
|
|
96
|
+
currentQuotaAccountId: refreshTokenIdentity(entry.parts.refreshToken),
|
|
97
|
+
tier: toCapturedTier(entry),
|
|
98
|
+
};
|
|
99
|
+
})));
|
|
100
|
+
};
|
|
101
|
+
async function runLoader(getAuth, provider) {
|
|
102
|
+
onGetAuth?.(getAuth);
|
|
103
|
+
let auth = await getAuth();
|
|
104
|
+
if (!isOAuthAuth(auth)) {
|
|
105
|
+
let storedAccounts;
|
|
106
|
+
try {
|
|
107
|
+
storedAccounts = await deps.loadAccounts();
|
|
108
|
+
}
|
|
109
|
+
catch (error) {
|
|
110
|
+
// Fail closed: do NOT proceed with `clearAccounts()` (which
|
|
111
|
+
// would destroy a recoverable corrupt file) and do NOT
|
|
112
|
+
// fabricate an empty pool. Surface the unreadable error so
|
|
113
|
+
// the caller can prompt the user to repair or remove the
|
|
114
|
+
// file. Backup path + reason are carried in `error.details`.
|
|
115
|
+
if (error instanceof AccountStorageUnreadableError) {
|
|
116
|
+
log.error('Refusing to start: account storage is unreadable', {
|
|
117
|
+
path: error.details.path,
|
|
118
|
+
reason: error.details.reason,
|
|
119
|
+
backupPath: error.details.backupPath,
|
|
120
|
+
});
|
|
121
|
+
try {
|
|
122
|
+
await client.tui.showToast({
|
|
123
|
+
body: {
|
|
124
|
+
message: `Account storage at ${error.details.path} is unreadable (${error.details.reason}). The plugin will not start until the file is repaired or removed.${error.details.backupPath ? ` A backup was written to ${error.details.backupPath}.` : ''}`,
|
|
125
|
+
variant: 'error',
|
|
126
|
+
duration: 30_000,
|
|
127
|
+
},
|
|
128
|
+
});
|
|
129
|
+
}
|
|
130
|
+
catch { }
|
|
131
|
+
}
|
|
132
|
+
throw error;
|
|
133
|
+
}
|
|
134
|
+
const drift = detectAuthStorageDrift(auth, storedAccounts);
|
|
135
|
+
if (drift.status === 'restorable' && drift.account) {
|
|
136
|
+
auth = buildAuthFromStoredAccount(drift.account);
|
|
137
|
+
try {
|
|
138
|
+
await client.auth.set({
|
|
139
|
+
path: { id: providerId },
|
|
140
|
+
body: {
|
|
141
|
+
type: 'oauth',
|
|
142
|
+
refresh: auth.refresh,
|
|
143
|
+
access: auth.access ?? '',
|
|
144
|
+
expires: auth.expires ?? 0,
|
|
145
|
+
},
|
|
146
|
+
});
|
|
147
|
+
log.info('Restored Antigravity OAuth auth from account storage', {
|
|
148
|
+
reason: drift.reason,
|
|
149
|
+
email: drift.account.email,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
catch (error) {
|
|
153
|
+
log.warn('Failed to restore Antigravity OAuth auth from account storage', { error: String(error) });
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
if (!isOAuthAuth(auth)) {
|
|
158
|
+
try {
|
|
159
|
+
await deps.clearAccounts();
|
|
160
|
+
}
|
|
161
|
+
catch { }
|
|
162
|
+
return {};
|
|
163
|
+
}
|
|
164
|
+
const accountManager = await deps.loadAccountManager(auth);
|
|
165
|
+
await installRuntime(accountManager, getAuth);
|
|
166
|
+
if (deps.isDebugEnabled()) {
|
|
167
|
+
const logPath = deps.getLogFilePath();
|
|
168
|
+
if (logPath) {
|
|
169
|
+
try {
|
|
170
|
+
await client.tui.showToast({
|
|
171
|
+
body: { message: `Debug log: ${logPath}`, variant: 'info' },
|
|
172
|
+
});
|
|
173
|
+
}
|
|
174
|
+
catch { }
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
if (provider.models) {
|
|
178
|
+
for (const model of Object.values(provider.models)) {
|
|
179
|
+
if (model)
|
|
180
|
+
model.cost = { input: 0, output: 0 };
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
apiKey: '',
|
|
185
|
+
// Return a stable delegating wrapper that reads `fetchRuntime`
|
|
186
|
+
// at CALL time. A direct `fetchRuntime!.fetch` reference would
|
|
187
|
+
// capture the current runtime; the host keeps that reference
|
|
188
|
+
// across `reload()` calls, so a captured fetch would still route
|
|
189
|
+
// through the OLD interceptor after an OAuth add. The wrapper
|
|
190
|
+
// matches the host's `LoaderResult.fetch` signature exactly
|
|
191
|
+
// (no `this` binding) so behavior is preserved.
|
|
192
|
+
fetch: (input, init) => fetchRuntime.fetch(input, init),
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
reloadRuntime = async (getAuth) => {
|
|
196
|
+
const auth = await getAuth();
|
|
197
|
+
if (!isOAuthAuth(auth))
|
|
198
|
+
return;
|
|
199
|
+
const nextManager = await deps.loadAccountManager(auth);
|
|
200
|
+
await installRuntime(nextManager, getAuth);
|
|
201
|
+
};
|
|
202
|
+
// Return a callable object: `plugin.auth.loader` is invoked with
|
|
203
|
+
// `(getAuth, provider)` (host contract), and `authLoader.reload(...)`
|
|
204
|
+
// rebuilds the runtime after out-of-band storage mutations (OAuth add).
|
|
205
|
+
// The callable closes over `runLoader` directly so the `this`-context
|
|
206
|
+
// binding stays unbound.
|
|
207
|
+
async function authLoaderCallable(getAuth, provider) {
|
|
208
|
+
return runLoader(getAuth, provider);
|
|
209
|
+
}
|
|
210
|
+
async function reload(getAuth) {
|
|
211
|
+
const next = reloadChain.then(() => reloadRuntime(getAuth));
|
|
212
|
+
reloadChain = next.catch(() => { });
|
|
213
|
+
return next;
|
|
214
|
+
}
|
|
215
|
+
// `load` mirrors the authLoaderCallable so the public handle
|
|
216
|
+
// (`AuthLoaderHandle.load`) exposes the same entry point the host
|
|
217
|
+
// invokes. Without this assignment, contract consumers read
|
|
218
|
+
// `.load` as undefined and the documented type would lie.
|
|
219
|
+
const authLoader = Object.assign(authLoaderCallable, {
|
|
220
|
+
reload,
|
|
221
|
+
load: authLoaderCallable,
|
|
222
|
+
});
|
|
223
|
+
return authLoader;
|
|
224
|
+
}
|
|
225
|
+
//# sourceMappingURL=auth-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-loader.js","sourceRoot":"","sources":["../../../src/plugin/auth-loader.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,kCAAkC,CAAA;AACnE,OAAO,EACL,oCAAoC,EACpC,gBAAgB,EAChB,sBAAsB,EACtB,cAAc,GACf,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAC3C,OAAO,EAAE,WAAW,EAAE,MAAM,QAAQ,CAAA;AACpC,OAAO,EACL,0BAA0B,EAC1B,sBAAsB,GACvB,MA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,UAAU,GAAG,MAAM,CAAC,MAAM,CAAC,kBAAkB,EAAE;QACnD,MAAM;QACN,IAAI,EAAE,kBAAkB;KACzB,CAAC,CAAA;IACF,OAAO,UAAsD,CAAA;AAC/D,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export * from
|
|
1
|
+
export * from '@cortexkit/antigravity-auth-core';
|
|
2
2
|
//# sourceMappingURL=auth.d.ts.map
|
package/dist/src/plugin/auth.js
CHANGED
|
@@ -0,0 +1,146 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Background quota poller.
|
|
3
|
+
*
|
|
4
|
+
* Runs a jittered, `unref()`'d timer that periodically refreshes quota for
|
|
5
|
+
* all accounts and pushes ONE sidebar snapshot per tick. Three-layer
|
|
6
|
+
* cross-process dedup:
|
|
7
|
+
*
|
|
8
|
+
* 1. Freshness gate — the only hard correctness bound for quota snapshots.
|
|
9
|
+
* Reads `checkedAt` from the on-disk sidebar state; skips quota work when
|
|
10
|
+
* it is fresher than
|
|
11
|
+
* `max(intervalMs − 60_000, floor(intervalMs / 2))`. The /2 floor
|
|
12
|
+
* ensures the gate still fires at the 1-minute minimum interval.
|
|
13
|
+
*
|
|
14
|
+
* 2. Advisory fenced lock — an optimization that lets a single process do
|
|
15
|
+
* the network work when several wake up simultaneously. Held → skip.
|
|
16
|
+
*
|
|
17
|
+
* 3. Lock throws → FAIL CLOSED (skip this tick, add jitter to next). A
|
|
18
|
+
* fallback mutex is NOT used here. The correct reasoning is: the
|
|
19
|
+
* freshness gate (layer 1) already bounds how many refreshes can land;
|
|
20
|
+
* a secondary "claim marker" file is just a worse re-implementation of
|
|
21
|
+
* the fenced lock we just failed to acquire — it replicates the same
|
|
22
|
+
* ownership problem without the protocol guarantees, and any transient
|
|
23
|
+
* I/O error that made the lock throw will likely affect a claim file
|
|
24
|
+
* too. The previous poller attempt fell into this trap across three
|
|
25
|
+
* review rounds; this comment exists so a future reviewer stops
|
|
26
|
+
* re-litigating it.
|
|
27
|
+
*/
|
|
28
|
+
import type { AccountMetadataV3, QuotaGroup, QuotaGroupSummary } from '@cortexkit/antigravity-auth-core';
|
|
29
|
+
import { acquireFencedFileLock } from '@cortexkit/antigravity-auth-core/file-lock';
|
|
30
|
+
import type { QuotaManager } from './quota';
|
|
31
|
+
/**
|
|
32
|
+
* The subset of AccountManager that the poller needs. Using a narrow
|
|
33
|
+
* interface keeps the module decoupled from the large concrete class and
|
|
34
|
+
* lets tests pass minimal stubs without satisfying 90+ methods.
|
|
35
|
+
*/
|
|
36
|
+
export interface PollerAccountView {
|
|
37
|
+
getAccounts(): Array<{
|
|
38
|
+
index: number;
|
|
39
|
+
label?: string;
|
|
40
|
+
enabled?: boolean;
|
|
41
|
+
parts: {
|
|
42
|
+
refreshToken: string;
|
|
43
|
+
};
|
|
44
|
+
cachedQuota?: Partial<Record<QuotaGroup, QuotaGroupSummary>>;
|
|
45
|
+
cachedQuotaAccountId?: string;
|
|
46
|
+
coolingDownUntil?: number;
|
|
47
|
+
/** Captured plan tier ID (raw upstream string). */
|
|
48
|
+
capturedTierId?: string;
|
|
49
|
+
/** Captured paid-tier ID (raw upstream string). */
|
|
50
|
+
capturedPaidTierId?: string;
|
|
51
|
+
/** Epoch ms when capturedTierId was last recorded. */
|
|
52
|
+
capturedTierAt?: number;
|
|
53
|
+
/** Schema version of the most recent tier capture. */
|
|
54
|
+
capturedTierSchemaVersion?: number;
|
|
55
|
+
}>;
|
|
56
|
+
/** Must return the full AccountMetadataV3 shape so the quota manager
|
|
57
|
+
* can use token-refresh and project-context fields inside each fetch. */
|
|
58
|
+
getAccountsForQuotaCheck(): AccountMetadataV3[];
|
|
59
|
+
updateQuotaCache(accountIndex: number, quotaGroups: Partial<Record<QuotaGroup, QuotaGroupSummary>>, expectedRefreshToken?: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Apply a subset of quota-result fields (e.g. captured tier) onto the
|
|
62
|
+
* in-memory account record without touching the quota cache itself.
|
|
63
|
+
*/
|
|
64
|
+
applyUpdatedAccount(accountIndex: number, patch: {
|
|
65
|
+
capturedTierId?: string;
|
|
66
|
+
capturedPaidTierId?: string;
|
|
67
|
+
capturedTierAt?: number;
|
|
68
|
+
capturedTierSchemaVersion?: number;
|
|
69
|
+
}, expectedRefreshToken?: string): void;
|
|
70
|
+
requestSaveToDisk(): void;
|
|
71
|
+
/**
|
|
72
|
+
* Returns the active account index per model family so the sidebar
|
|
73
|
+
* snapshot can stamp the `current` flag on the right account.
|
|
74
|
+
*/
|
|
75
|
+
getActiveIndexByFamily(): {
|
|
76
|
+
claude: number;
|
|
77
|
+
gemini: number;
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
export interface BackgroundQuotaRefreshOptions {
|
|
81
|
+
intervalMs: number;
|
|
82
|
+
sidebarStateFile: string;
|
|
83
|
+
/**
|
|
84
|
+
* Supplier for the live account pool. Called inside each locked phase, so it
|
|
85
|
+
* observes any concurrent add/remove that completed while waiting for the
|
|
86
|
+
* lock.
|
|
87
|
+
*/
|
|
88
|
+
getAccountManager: () => PollerAccountView | null;
|
|
89
|
+
quotaManager: QuotaManager;
|
|
90
|
+
/**
|
|
91
|
+
* Optional tier-refresh callback. When provided, the poller calls this
|
|
92
|
+
* once per tick for the account whose capturedTierAt is missing or older
|
|
93
|
+
* than TIER_STALENESS_TTL_MS. The callback handles its own token-refresh
|
|
94
|
+
* and must resolve to a tier object (or null on failure / nothing to
|
|
95
|
+
* report) -- failure must never reject, since tier is best-effort.
|
|
96
|
+
*
|
|
97
|
+
* Wired in index.ts through the same agyTransport seam the quota manager
|
|
98
|
+
* uses, so e2e tests can inject a mock alongside the mock quota fetch.
|
|
99
|
+
*/
|
|
100
|
+
loadAccountTier?: (account: AccountMetadataV3) => Promise<{
|
|
101
|
+
id: string;
|
|
102
|
+
paidId?: string;
|
|
103
|
+
capturedAt: number;
|
|
104
|
+
} | null>;
|
|
105
|
+
/**
|
|
106
|
+
* Clock / randomness seam. Defaults to the system clock.
|
|
107
|
+
*/
|
|
108
|
+
now?: () => number;
|
|
109
|
+
random?: () => number;
|
|
110
|
+
/** Lock acquisition seam used by deterministic concurrency tests. */
|
|
111
|
+
acquireLock?: typeof acquireFencedFileLock;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Per-loader-instance background quota poller.
|
|
115
|
+
*
|
|
116
|
+
* Must be created after the plugin has initialised (so `getAccountManager()`
|
|
117
|
+
* is populated) and disposed via the producer lifecycle phase.
|
|
118
|
+
*/
|
|
119
|
+
export declare class BackgroundQuotaRefresh {
|
|
120
|
+
private readonly intervalMs;
|
|
121
|
+
private readonly sidebarStateFile;
|
|
122
|
+
private readonly getAccountManager;
|
|
123
|
+
private readonly quotaManager;
|
|
124
|
+
private readonly loadAccountTier?;
|
|
125
|
+
private readonly now;
|
|
126
|
+
private readonly random;
|
|
127
|
+
private readonly acquireLock;
|
|
128
|
+
private timer;
|
|
129
|
+
/** Resolves when the currently-running tick completes (or immediately if none). */
|
|
130
|
+
private inFlight;
|
|
131
|
+
private disposed;
|
|
132
|
+
constructor(options: BackgroundQuotaRefreshOptions);
|
|
133
|
+
/** Start the background timer. Idempotent: a second call is a no-op. */
|
|
134
|
+
start(): void;
|
|
135
|
+
/** Stop the timer and await any in-flight tick. */
|
|
136
|
+
dispose(): Promise<void>;
|
|
137
|
+
private jitteredStartDelay;
|
|
138
|
+
private jitteredInterval;
|
|
139
|
+
private scheduleNext;
|
|
140
|
+
private runTick;
|
|
141
|
+
private refresh;
|
|
142
|
+
private refreshQuota;
|
|
143
|
+
private refreshTierSlot;
|
|
144
|
+
private pushSnapshot;
|
|
145
|
+
}
|
|
146
|
+
//# sourceMappingURL=background-quota-refresh.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"background-quota-refresh.d.ts","sourceRoot":"","sources":["../../../src/plugin/background-quota-refresh.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AAGH,OAAO,KAAK,EACV,iB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