@jsonstudio/rcc 0.89.1968 → 0.89.2202
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 +22 -0
- package/config/file-line-limit-policy.json +21 -0
- package/configsamples/config.json +1 -1
- package/configsamples/config.v1.quickstart.sanitized.json +6 -6
- package/configsamples/provider/iflow/config.v1.json +1 -1
- package/dist/app/config-readers.d.ts +18 -0
- package/dist/app/config-readers.js +95 -0
- package/dist/app/config-readers.js.map +1 -0
- package/dist/app/index.d.ts +9 -0
- package/dist/app/index.js +8 -0
- package/dist/app/index.js.map +1 -0
- package/dist/app/shutdown.d.ts +32 -0
- package/dist/app/shutdown.js +41 -0
- package/dist/app/shutdown.js.map +1 -0
- package/dist/bootstrap/index.d.ts +7 -0
- package/dist/bootstrap/index.js +7 -0
- package/dist/bootstrap/index.js.map +1 -0
- package/dist/bootstrap/log-filter.d.ts +15 -0
- package/dist/bootstrap/log-filter.js +81 -0
- package/dist/bootstrap/log-filter.js.map +1 -0
- package/dist/build-info.js +2 -2
- package/dist/cli/commands/claude.js +6 -5
- package/dist/cli/commands/claude.js.map +1 -1
- package/dist/cli/commands/init/basic.d.ts +1 -7
- package/dist/cli/commands/init/basic.js +0 -79
- package/dist/cli/commands/init/basic.js.map +1 -1
- package/dist/cli/commands/init/prompt-utils.d.ts +7 -0
- package/dist/cli/commands/init/prompt-utils.js +80 -0
- package/dist/cli/commands/init/prompt-utils.js.map +1 -0
- package/dist/cli/commands/init/workflows.js +2 -1
- package/dist/cli/commands/init/workflows.js.map +1 -1
- package/dist/cli/commands/init.js +74 -2
- package/dist/cli/commands/init.js.map +1 -1
- package/dist/cli/commands/launcher/index.d.ts +7 -0
- package/dist/cli/commands/launcher/index.js +7 -0
- package/dist/cli/commands/launcher/index.js.map +1 -0
- package/dist/cli/commands/launcher/types.d.ts +112 -0
- package/dist/cli/commands/launcher/types.js +7 -0
- package/dist/cli/commands/launcher/types.js.map +1 -0
- package/dist/cli/commands/launcher/utils.d.ts +114 -0
- package/dist/cli/commands/launcher/utils.js +378 -0
- package/dist/cli/commands/launcher/utils.js.map +1 -0
- package/dist/cli/commands/launcher-kernel.d.ts +2 -74
- package/dist/cli/commands/launcher-kernel.js +141 -143
- package/dist/cli/commands/launcher-kernel.js.map +1 -1
- package/dist/cli/commands/start-types.d.ts +67 -0
- package/dist/cli/commands/start-types.js +3 -0
- package/dist/cli/commands/start-types.js.map +1 -0
- package/dist/cli/commands/start-utils.d.ts +19 -0
- package/dist/cli/commands/start-utils.js +78 -0
- package/dist/cli/commands/start-utils.js.map +1 -0
- package/dist/cli/commands/start.d.ts +2 -67
- package/dist/cli/commands/start.js +201 -48
- package/dist/cli/commands/start.js.map +1 -1
- package/dist/cli/commands/stop.js +17 -1
- package/dist/cli/commands/stop.js.map +1 -1
- package/dist/cli/commands/tmux-inject.js +1 -1
- package/dist/cli/commands/tmux-inject.js.map +1 -1
- package/dist/cli/config/init-config.js +60 -2
- package/dist/cli/config/init-config.js.map +1 -1
- package/dist/cli/config/init-provider-catalog.js +3 -1
- package/dist/cli/config/init-provider-catalog.js.map +1 -1
- package/dist/cli/config/precommand-default-script.d.ts +17 -0
- package/dist/cli/config/precommand-default-script.js +47 -0
- package/dist/cli/config/precommand-default-script.js.map +1 -0
- package/dist/cli/server/port-utils.js +63 -51
- package/dist/cli/server/port-utils.js.map +1 -1
- package/dist/cli.js +2 -0
- package/dist/cli.js.map +1 -1
- package/dist/client/gemini-cli/gemini-cli-protocol-client.js +55 -5
- package/dist/client/gemini-cli/gemini-cli-protocol-client.js.map +1 -1
- package/dist/commands/oauth.js +28 -4
- package/dist/commands/oauth.js.map +1 -1
- package/dist/commands/quota-daemon.js +12 -0
- package/dist/commands/quota-daemon.js.map +1 -1
- package/dist/configsamples/config.v1.quickstart.sanitized.json +6 -6
- package/dist/constants/index.d.ts +34 -0
- package/dist/constants/index.js +57 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/docs/daemon-admin-ui.html +268 -11
- package/dist/error-handling/quiet-error-handling-center.js +19 -1
- package/dist/error-handling/quiet-error-handling-center.js.map +1 -1
- package/dist/index.js +233 -30
- package/dist/index.js.map +1 -1
- package/dist/manager/index.js +4 -4
- package/dist/manager/index.js.map +1 -1
- package/dist/manager/modules/quota/antigravity-quota-core.d.ts +26 -0
- package/dist/manager/modules/quota/antigravity-quota-core.js +23 -0
- package/dist/manager/modules/quota/antigravity-quota-core.js.map +1 -0
- package/dist/manager/modules/quota/antigravity-quota-helpers.d.ts +16 -0
- package/dist/manager/modules/quota/antigravity-quota-helpers.js +167 -0
- package/dist/manager/modules/quota/antigravity-quota-helpers.js.map +1 -0
- package/dist/manager/modules/quota/antigravity-quota-manager.d.ts +10 -39
- package/dist/manager/modules/quota/antigravity-quota-manager.js +167 -464
- package/dist/manager/modules/quota/antigravity-quota-manager.js.map +1 -1
- package/dist/manager/modules/quota/antigravity-quota-persistence.d.ts +20 -0
- package/dist/manager/modules/quota/antigravity-quota-persistence.js +139 -0
- package/dist/manager/modules/quota/antigravity-quota-persistence.js.map +1 -0
- package/dist/manager/modules/quota/antigravity-quota-runtime.d.ts +55 -0
- package/dist/manager/modules/quota/antigravity-quota-runtime.js +174 -0
- package/dist/manager/modules/quota/antigravity-quota-runtime.js.map +1 -0
- package/dist/manager/modules/quota/antigravity-quota-sync.d.ts +46 -0
- package/dist/manager/modules/quota/antigravity-quota-sync.js +162 -0
- package/dist/manager/modules/quota/antigravity-quota-sync.js.map +1 -0
- package/dist/manager/modules/quota/index.d.ts +1 -0
- package/dist/manager/modules/quota/provider-quota-daemon.error-helpers.d.ts +13 -0
- package/dist/manager/modules/quota/provider-quota-daemon.error-helpers.js +149 -0
- package/dist/manager/modules/quota/provider-quota-daemon.error-helpers.js.map +1 -0
- package/dist/manager/modules/quota/provider-quota-daemon.events.js +1 -148
- package/dist/manager/modules/quota/provider-quota-daemon.events.js.map +1 -1
- package/dist/manager/modules/quota/provider-quota-daemon.js.map +1 -1
- package/dist/manager/modules/quota/quota-adapter.d.ts +111 -0
- package/dist/manager/modules/quota/quota-adapter.js +325 -0
- package/dist/manager/modules/quota/quota-adapter.js.map +1 -0
- package/dist/manager/quota/provider-quota-center.d.ts +10 -0
- package/dist/manager/quota/provider-quota-center.js +15 -2
- package/dist/manager/quota/provider-quota-center.js.map +1 -1
- package/dist/modules/llmswitch/bridge/antigravity-signature.d.ts +28 -0
- package/dist/modules/llmswitch/bridge/antigravity-signature.js +180 -0
- package/dist/modules/llmswitch/bridge/antigravity-signature.js.map +1 -0
- package/dist/modules/llmswitch/bridge/index.d.ts +13 -0
- package/dist/modules/llmswitch/bridge/index.js +14 -0
- package/dist/modules/llmswitch/bridge/index.js.map +1 -0
- package/dist/modules/llmswitch/bridge/module-loader.d.ts +16 -0
- package/dist/modules/llmswitch/bridge/module-loader.js +59 -0
- package/dist/modules/llmswitch/bridge/module-loader.js.map +1 -0
- package/dist/modules/llmswitch/bridge/quota-manager.d.ts +8 -0
- package/dist/modules/llmswitch/bridge/quota-manager.js +37 -0
- package/dist/modules/llmswitch/bridge/quota-manager.js.map +1 -0
- package/dist/modules/llmswitch/bridge/response-converter.d.ts +11 -0
- package/dist/modules/llmswitch/bridge/response-converter.js +68 -0
- package/dist/modules/llmswitch/bridge/response-converter.js.map +1 -0
- package/dist/modules/llmswitch/bridge/routing-integrations.d.ts +12 -0
- package/dist/modules/llmswitch/bridge/routing-integrations.js +56 -0
- package/dist/modules/llmswitch/bridge/routing-integrations.js.map +1 -0
- package/dist/modules/llmswitch/bridge/runtime-integrations.d.ts +34 -0
- package/dist/modules/llmswitch/bridge/runtime-integrations.js +87 -0
- package/dist/modules/llmswitch/bridge/runtime-integrations.js.map +1 -0
- package/dist/modules/llmswitch/bridge/snapshot-recorder.d.ts +13 -0
- package/dist/modules/llmswitch/bridge/snapshot-recorder.js +484 -0
- package/dist/modules/llmswitch/bridge/snapshot-recorder.js.map +1 -0
- package/dist/modules/llmswitch/bridge/state-integrations.d.ts +59 -0
- package/dist/modules/llmswitch/bridge/state-integrations.js +264 -0
- package/dist/modules/llmswitch/bridge/state-integrations.js.map +1 -0
- package/dist/modules/llmswitch/bridge.d.ts +14 -131
- package/dist/modules/llmswitch/bridge.js +14 -834
- package/dist/modules/llmswitch/bridge.js.map +1 -1
- package/dist/modules/pipeline/types/provider-config-types.d.ts +240 -0
- package/dist/modules/pipeline/types/provider-config-types.js +2 -0
- package/dist/modules/pipeline/types/provider-config-types.js.map +1 -0
- package/dist/modules/pipeline/types/provider-types.d.ts +2 -239
- package/dist/modules/pipeline/types/provider-types.js +1 -1
- package/dist/modules/pipeline/types/provider-types.js.map +1 -1
- package/dist/modules/pipeline/utils/debug-logger.js +3 -5
- package/dist/modules/pipeline/utils/debug-logger.js.map +1 -1
- package/dist/providers/auth/apikey-auth.d.ts +57 -1
- package/dist/providers/auth/apikey-auth.js +131 -1
- package/dist/providers/auth/apikey-auth.js.map +1 -1
- package/dist/providers/auth/oauth-lifecycle/error-detection.d.ts +8 -0
- package/dist/providers/auth/oauth-lifecycle/error-detection.js +71 -0
- package/dist/providers/auth/oauth-lifecycle/error-detection.js.map +1 -0
- package/dist/providers/auth/oauth-lifecycle/index.d.ts +10 -0
- package/dist/providers/auth/oauth-lifecycle/index.js +11 -0
- package/dist/providers/auth/oauth-lifecycle/index.js.map +1 -0
- package/dist/providers/auth/oauth-lifecycle/path-resolver.d.ts +18 -0
- package/dist/providers/auth/oauth-lifecycle/path-resolver.js +121 -0
- package/dist/providers/auth/oauth-lifecycle/path-resolver.js.map +1 -0
- package/dist/providers/auth/oauth-lifecycle/throttle.d.ts +22 -0
- package/dist/providers/auth/oauth-lifecycle/throttle.js +37 -0
- package/dist/providers/auth/oauth-lifecycle/throttle.js.map +1 -0
- package/dist/providers/auth/oauth-lifecycle/token-helpers.d.ts +36 -0
- package/dist/providers/auth/oauth-lifecycle/token-helpers.js +127 -0
- package/dist/providers/auth/oauth-lifecycle/token-helpers.js.map +1 -0
- package/dist/providers/auth/oauth-lifecycle/token-io.d.ts +14 -0
- package/dist/providers/auth/oauth-lifecycle/token-io.js +151 -0
- package/dist/providers/auth/oauth-lifecycle/token-io.js.map +1 -0
- package/dist/providers/auth/oauth-lifecycle.js +70 -446
- package/dist/providers/auth/oauth-lifecycle.js.map +1 -1
- package/dist/providers/auth/oauth-repair-cooldown.js +8 -3
- package/dist/providers/auth/oauth-repair-cooldown.js.map +1 -1
- package/dist/providers/auth/oauth-repair-env.js +5 -3
- package/dist/providers/auth/oauth-repair-env.js.map +1 -1
- package/dist/providers/auth/oauth-token-utils.d.ts +61 -0
- package/dist/providers/auth/oauth-token-utils.js +187 -0
- package/dist/providers/auth/oauth-token-utils.js.map +1 -0
- package/dist/providers/auth/oauth-utils/camoufox-helper.d.ts +21 -0
- package/dist/providers/auth/oauth-utils/camoufox-helper.js +82 -0
- package/dist/providers/auth/oauth-utils/camoufox-helper.js.map +1 -0
- package/dist/providers/auth/oauth-utils/error-extraction.d.ts +17 -0
- package/dist/providers/auth/oauth-utils/error-extraction.js +80 -0
- package/dist/providers/auth/oauth-utils/error-extraction.js.map +1 -0
- package/dist/providers/auth/oauth-utils/index.d.ts +7 -0
- package/dist/providers/auth/oauth-utils/index.js +8 -0
- package/dist/providers/auth/oauth-utils/index.js.map +1 -0
- package/dist/providers/auth/token-refresh/index.d.ts +6 -0
- package/dist/providers/auth/token-refresh/index.js +7 -0
- package/dist/providers/auth/token-refresh/index.js.map +1 -0
- package/dist/providers/auth/token-refresh/token-state.d.ts +17 -0
- package/dist/providers/auth/token-refresh/token-state.js +30 -0
- package/dist/providers/auth/token-refresh/token-state.js.map +1 -0
- package/dist/providers/auth/token-storage/index.d.ts +7 -0
- package/dist/providers/auth/token-storage/index.js +8 -0
- package/dist/providers/auth/token-storage/index.js.map +1 -0
- package/dist/providers/auth/token-storage/token-file-resolver.d.ts +12 -0
- package/dist/providers/auth/token-storage/token-file-resolver.js +117 -0
- package/dist/providers/auth/token-storage/token-file-resolver.js.map +1 -0
- package/dist/providers/auth/token-storage/token-persistence.d.ts +22 -0
- package/dist/providers/auth/token-storage/token-persistence.js +86 -0
- package/dist/providers/auth/token-storage/token-persistence.js.map +1 -0
- package/dist/providers/auth/tokenfile-auth.js +12 -9
- package/dist/providers/auth/tokenfile-auth.js.map +1 -1
- package/dist/providers/core/api/provider-config.d.ts +8 -0
- package/dist/providers/core/config/camoufox-launcher.d.ts +1 -0
- package/dist/providers/core/config/camoufox-launcher.js +40 -9
- package/dist/providers/core/config/camoufox-launcher.js.map +1 -1
- package/dist/providers/core/config/oauth-flows.js +7 -2
- package/dist/providers/core/config/oauth-flows.js.map +1 -1
- package/dist/providers/core/config/provider-debug-hooks.d.ts +0 -12
- package/dist/providers/core/config/provider-debug-hooks.js +16 -56
- package/dist/providers/core/config/provider-debug-hooks.js.map +1 -1
- package/dist/providers/core/config/provider-debug-output-utils.d.ts +38 -0
- package/dist/providers/core/config/provider-debug-output-utils.js +46 -0
- package/dist/providers/core/config/provider-debug-output-utils.js.map +1 -0
- package/dist/providers/core/config/provider-oauth-configs.js +13 -9
- package/dist/providers/core/config/provider-oauth-configs.js.map +1 -1
- package/dist/providers/core/runtime/antigravity-request-type.d.ts +2 -0
- package/dist/providers/core/runtime/antigravity-request-type.js +126 -0
- package/dist/providers/core/runtime/antigravity-request-type.js.map +1 -0
- package/dist/providers/core/runtime/base-provider-runtime-helpers.d.ts +27 -0
- package/dist/providers/core/runtime/base-provider-runtime-helpers.js +105 -0
- package/dist/providers/core/runtime/base-provider-runtime-helpers.js.map +1 -0
- package/dist/providers/core/runtime/base-provider-series-cooldown.d.ts +19 -0
- package/dist/providers/core/runtime/base-provider-series-cooldown.js +363 -0
- package/dist/providers/core/runtime/base-provider-series-cooldown.js.map +1 -0
- package/dist/providers/core/runtime/base-provider.d.ts +4 -35
- package/dist/providers/core/runtime/base-provider.js +20 -501
- package/dist/providers/core/runtime/base-provider.js.map +1 -1
- package/dist/providers/core/runtime/deepseek-http-provider-helpers.d.ts +32 -0
- package/dist/providers/core/runtime/deepseek-http-provider-helpers.js +301 -0
- package/dist/providers/core/runtime/deepseek-http-provider-helpers.js.map +1 -0
- package/dist/providers/core/runtime/deepseek-http-provider.d.ts +0 -3
- package/dist/providers/core/runtime/deepseek-http-provider.js +5 -127
- package/dist/providers/core/runtime/deepseek-http-provider.js.map +1 -1
- package/dist/providers/core/runtime/deepseek-session-pow-helpers.d.ts +21 -0
- package/dist/providers/core/runtime/deepseek-session-pow-helpers.js +99 -0
- package/dist/providers/core/runtime/deepseek-session-pow-helpers.js.map +1 -0
- package/dist/providers/core/runtime/deepseek-session-pow.js +13 -108
- package/dist/providers/core/runtime/deepseek-session-pow.js.map +1 -1
- package/dist/providers/core/runtime/gemini-cli-http-provider.d.ts +0 -15
- package/dist/providers/core/runtime/gemini-cli-http-provider.js +13 -303
- package/dist/providers/core/runtime/gemini-cli-http-provider.js.map +1 -1
- package/dist/providers/core/runtime/gemini-cli-response-postprocessor.d.ts +9 -0
- package/dist/providers/core/runtime/gemini-cli-response-postprocessor.js +85 -0
- package/dist/providers/core/runtime/gemini-cli-response-postprocessor.js.map +1 -0
- package/dist/providers/core/runtime/gemini-http-provider.js +2 -2
- package/dist/providers/core/runtime/gemini-http-provider.js.map +1 -1
- package/dist/providers/core/runtime/gemini-sse-normalizer.d.ts +25 -0
- package/dist/providers/core/runtime/gemini-sse-normalizer.js +159 -0
- package/dist/providers/core/runtime/gemini-sse-normalizer.js.map +1 -0
- package/dist/providers/core/runtime/http-request-executor.js +1 -48
- package/dist/providers/core/runtime/http-request-executor.js.map +1 -1
- package/dist/providers/core/runtime/http-transport-provider.d.ts +2 -48
- package/dist/providers/core/runtime/http-transport-provider.js +158 -1273
- package/dist/providers/core/runtime/http-transport-provider.js.map +1 -1
- package/dist/providers/core/runtime/provider-bootstrap-utils.d.ts +20 -0
- package/dist/providers/core/runtime/provider-bootstrap-utils.js +78 -0
- package/dist/providers/core/runtime/provider-bootstrap-utils.js.map +1 -0
- package/dist/providers/core/runtime/provider-factory-helpers.d.ts +19 -0
- package/dist/providers/core/runtime/provider-factory-helpers.js +203 -0
- package/dist/providers/core/runtime/provider-factory-helpers.js.map +1 -0
- package/dist/providers/core/runtime/provider-factory.d.ts +9 -7
- package/dist/providers/core/runtime/provider-factory.js +57 -214
- package/dist/providers/core/runtime/provider-factory.js.map +1 -1
- package/dist/providers/core/runtime/provider-family-profile-utils.d.ts +23 -0
- package/dist/providers/core/runtime/provider-family-profile-utils.js +57 -0
- package/dist/providers/core/runtime/provider-family-profile-utils.js.map +1 -0
- package/dist/providers/core/runtime/provider-http-executor-utils.d.ts +32 -0
- package/dist/providers/core/runtime/provider-http-executor-utils.js +92 -0
- package/dist/providers/core/runtime/provider-http-executor-utils.js.map +1 -0
- package/dist/providers/core/runtime/provider-iflow-business-error-utils.d.ts +15 -0
- package/dist/providers/core/runtime/provider-iflow-business-error-utils.js +49 -0
- package/dist/providers/core/runtime/provider-iflow-business-error-utils.js.map +1 -0
- package/dist/providers/core/runtime/provider-request-executor-deps-factory.d.ts +29 -0
- package/dist/providers/core/runtime/provider-request-executor-deps-factory.js +41 -0
- package/dist/providers/core/runtime/provider-request-executor-deps-factory.js.map +1 -0
- package/dist/providers/core/runtime/provider-request-header-orchestrator.d.ts +30 -0
- package/dist/providers/core/runtime/provider-request-header-orchestrator.js +91 -0
- package/dist/providers/core/runtime/provider-request-header-orchestrator.js.map +1 -0
- package/dist/providers/core/runtime/provider-request-preprocessor.d.ts +5 -0
- package/dist/providers/core/runtime/provider-request-preprocessor.js +39 -0
- package/dist/providers/core/runtime/provider-request-preprocessor.js.map +1 -0
- package/dist/providers/core/runtime/provider-request-shaping-utils.d.ts +37 -0
- package/dist/providers/core/runtime/provider-request-shaping-utils.js +65 -0
- package/dist/providers/core/runtime/provider-request-shaping-utils.js.map +1 -0
- package/dist/providers/core/runtime/provider-response-postprocessor.d.ts +7 -0
- package/dist/providers/core/runtime/provider-response-postprocessor.js +28 -0
- package/dist/providers/core/runtime/provider-response-postprocessor.js.map +1 -0
- package/dist/providers/core/runtime/provider-runtime-utils.d.ts +16 -0
- package/dist/providers/core/runtime/provider-runtime-utils.js +51 -0
- package/dist/providers/core/runtime/provider-runtime-utils.js.map +1 -0
- package/dist/providers/core/runtime/responses-provider-helpers.d.ts +37 -0
- package/dist/providers/core/runtime/responses-provider-helpers.js +212 -0
- package/dist/providers/core/runtime/responses-provider-helpers.js.map +1 -0
- package/dist/providers/core/runtime/responses-provider.d.ts +0 -10
- package/dist/providers/core/runtime/responses-provider.js +14 -224
- package/dist/providers/core/runtime/responses-provider.js.map +1 -1
- package/dist/providers/core/runtime/runtime-endpoint-resolver.d.ts +21 -0
- package/dist/providers/core/runtime/runtime-endpoint-resolver.js +64 -0
- package/dist/providers/core/runtime/runtime-endpoint-resolver.js.map +1 -0
- package/dist/providers/core/runtime/service-profile-resolver.d.ts +29 -0
- package/dist/providers/core/runtime/service-profile-resolver.js +88 -0
- package/dist/providers/core/runtime/service-profile-resolver.js.map +1 -0
- package/dist/providers/core/runtime/transport/auth-mode-utils.d.ts +13 -0
- package/dist/providers/core/runtime/transport/auth-mode-utils.js +43 -0
- package/dist/providers/core/runtime/transport/auth-mode-utils.js.map +1 -0
- package/dist/providers/core/runtime/transport/auth-provider-factory.d.ts +37 -0
- package/dist/providers/core/runtime/transport/auth-provider-factory.js +131 -0
- package/dist/providers/core/runtime/transport/auth-provider-factory.js.map +1 -0
- package/dist/providers/core/runtime/transport/header-utils.d.ts +15 -0
- package/dist/providers/core/runtime/transport/header-utils.js +85 -0
- package/dist/providers/core/runtime/transport/header-utils.js.map +1 -0
- package/dist/providers/core/runtime/transport/iflow-signer.d.ts +12 -0
- package/dist/providers/core/runtime/transport/iflow-signer.js +63 -0
- package/dist/providers/core/runtime/transport/iflow-signer.js.map +1 -0
- package/dist/providers/core/runtime/transport/index.d.ts +15 -0
- package/dist/providers/core/runtime/transport/index.js +16 -0
- package/dist/providers/core/runtime/transport/index.js.map +1 -0
- package/dist/providers/core/runtime/transport/oauth-header-preflight.d.ts +12 -0
- package/dist/providers/core/runtime/transport/oauth-header-preflight.js +56 -0
- package/dist/providers/core/runtime/transport/oauth-header-preflight.js.map +1 -0
- package/dist/providers/core/runtime/transport/oauth-recovery-handler.d.ts +34 -0
- package/dist/providers/core/runtime/transport/oauth-recovery-handler.js +126 -0
- package/dist/providers/core/runtime/transport/oauth-recovery-handler.js.map +1 -0
- package/dist/providers/core/runtime/transport/provider-payload-utils.d.ts +21 -0
- package/dist/providers/core/runtime/transport/provider-payload-utils.js +88 -0
- package/dist/providers/core/runtime/transport/provider-payload-utils.js.map +1 -0
- package/dist/providers/core/runtime/transport/request-header-builder.d.ts +24 -0
- package/dist/providers/core/runtime/transport/request-header-builder.js +90 -0
- package/dist/providers/core/runtime/transport/request-header-builder.js.map +1 -0
- package/dist/providers/core/runtime/transport/runtime-detector.d.ts +22 -0
- package/dist/providers/core/runtime/transport/runtime-detector.js +63 -0
- package/dist/providers/core/runtime/transport/runtime-detector.js.map +1 -0
- package/dist/providers/core/runtime/transport/session-header-utils.d.ts +8 -0
- package/dist/providers/core/runtime/transport/session-header-utils.js +72 -0
- package/dist/providers/core/runtime/transport/session-header-utils.js.map +1 -0
- package/dist/providers/core/runtime/vision-debug-utils.d.ts +2 -0
- package/dist/providers/core/runtime/vision-debug-utils.js +31 -0
- package/dist/providers/core/runtime/vision-debug-utils.js.map +1 -1
- package/dist/providers/core/strategies/oauth-auth-code-flow.d.ts +13 -0
- package/dist/providers/core/strategies/oauth-auth-code-flow.js +272 -55
- package/dist/providers/core/strategies/oauth-auth-code-flow.js.map +1 -1
- package/dist/providers/core/utils/snapshot-writer-buffer.d.ts +13 -0
- package/dist/providers/core/utils/snapshot-writer-buffer.js +39 -0
- package/dist/providers/core/utils/snapshot-writer-buffer.js.map +1 -0
- package/dist/providers/core/utils/snapshot-writer.js +75 -54
- package/dist/providers/core/utils/snapshot-writer.js.map +1 -1
- package/dist/providers/profile/families/antigravity-profile.js +2 -10
- package/dist/providers/profile/families/antigravity-profile.js.map +1 -1
- package/dist/providers/profile/families/deepseek-profile.d.ts +2 -0
- package/dist/providers/profile/families/deepseek-profile.js +110 -0
- package/dist/providers/profile/families/deepseek-profile.js.map +1 -0
- package/dist/providers/profile/families/iflow-profile.js +89 -10
- package/dist/providers/profile/families/iflow-profile.js.map +1 -1
- package/dist/providers/profile/provider-profile-loader.d.ts +5 -0
- package/dist/providers/profile/provider-profile-loader.js +35 -0
- package/dist/providers/profile/provider-profile-loader.js.map +1 -1
- package/dist/providers/profile/provider-profile.d.ts +16 -1
- package/dist/runtime/runtime-flags.js +1 -1
- package/dist/runtime/runtime-flags.js.map +1 -1
- package/dist/runtime/wasm-runtime/index.d.ts +56 -0
- package/dist/runtime/wasm-runtime/index.js +69 -0
- package/dist/runtime/wasm-runtime/index.js.map +1 -0
- package/dist/scripts/camoufox/launch-auth.mjs +158 -10
- package/dist/server/handlers/handler-response-utils.d.ts +13 -0
- package/dist/server/handlers/handler-response-utils.js +427 -0
- package/dist/server/handlers/handler-response-utils.js.map +1 -0
- package/dist/server/handlers/handler-utils.d.ts +2 -11
- package/dist/server/handlers/handler-utils.js +21 -421
- package/dist/server/handlers/handler-utils.js.map +1 -1
- package/dist/server/runtime/http-server/clock-client-reaper.d.ts +23 -0
- package/dist/server/runtime/http-server/clock-client-reaper.js +159 -0
- package/dist/server/runtime/http-server/clock-client-reaper.js.map +1 -0
- package/dist/server/runtime/http-server/clock-client-registry-utils.d.ts +87 -0
- package/dist/server/runtime/http-server/clock-client-registry-utils.js +276 -0
- package/dist/server/runtime/http-server/clock-client-registry-utils.js.map +1 -0
- package/dist/server/runtime/http-server/clock-client-registry.d.ts +5 -50
- package/dist/server/runtime/http-server/clock-client-registry.js +74 -320
- package/dist/server/runtime/http-server/clock-client-registry.js.map +1 -1
- package/dist/server/runtime/http-server/clock-client-route-utils.d.ts +12 -0
- package/dist/server/runtime/http-server/clock-client-route-utils.js +210 -0
- package/dist/server/runtime/http-server/clock-client-route-utils.js.map +1 -0
- package/dist/server/runtime/http-server/clock-client-routes.js +27 -201
- package/dist/server/runtime/http-server/clock-client-routes.js.map +1 -1
- package/dist/server/runtime/http-server/clock-daemon-log-throttle.d.ts +12 -0
- package/dist/server/runtime/http-server/clock-daemon-log-throttle.js +56 -0
- package/dist/server/runtime/http-server/clock-daemon-log-throttle.js.map +1 -0
- package/dist/server/runtime/http-server/daemon-admin/control-handler.js +143 -14
- package/dist/server/runtime/http-server/daemon-admin/control-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/credentials-handler-utils.d.ts +19 -0
- package/dist/server/runtime/http-server/daemon-admin/credentials-handler-utils.js +107 -0
- package/dist/server/runtime/http-server/daemon-admin/credentials-handler-utils.js.map +1 -0
- package/dist/server/runtime/http-server/daemon-admin/credentials-handler.js +2 -104
- package/dist/server/runtime/http-server/daemon-admin/credentials-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/providers-handler-routing-utils.d.ts +28 -0
- package/dist/server/runtime/http-server/daemon-admin/providers-handler-routing-utils.js +298 -0
- package/dist/server/runtime/http-server/daemon-admin/providers-handler-routing-utils.js.map +1 -0
- package/dist/server/runtime/http-server/daemon-admin/providers-handler-utils.d.ts +22 -0
- package/dist/server/runtime/http-server/daemon-admin/providers-handler-utils.js +211 -0
- package/dist/server/runtime/http-server/daemon-admin/providers-handler-utils.js.map +1 -0
- package/dist/server/runtime/http-server/daemon-admin/providers-handler.js +25 -454
- package/dist/server/runtime/http-server/daemon-admin/providers-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/quota-handler.js +81 -32
- package/dist/server/runtime/http-server/daemon-admin/quota-handler.js.map +1 -1
- package/dist/server/runtime/http-server/daemon-admin/routecodex-x7e-gate.d.ts +22 -0
- package/dist/server/runtime/http-server/daemon-admin/routecodex-x7e-gate.js +70 -0
- package/dist/server/runtime/http-server/daemon-admin/routecodex-x7e-gate.js.map +1 -0
- package/dist/server/runtime/http-server/executor/antigravity-detector.d.ts +34 -0
- package/dist/server/runtime/http-server/executor/antigravity-detector.js +118 -0
- package/dist/server/runtime/http-server/executor/antigravity-detector.js.map +1 -0
- package/dist/server/runtime/http-server/executor/env-config.d.ts +13 -0
- package/dist/server/runtime/http-server/executor/env-config.js +20 -0
- package/dist/server/runtime/http-server/executor/env-config.js.map +1 -0
- package/dist/server/runtime/http-server/executor/index.d.ts +11 -0
- package/dist/server/runtime/http-server/executor/index.js +18 -0
- package/dist/server/runtime/http-server/executor/index.js.map +1 -0
- package/dist/server/runtime/http-server/executor/provider-request-context.d.ts +20 -0
- package/dist/server/runtime/http-server/executor/provider-request-context.js +38 -0
- package/dist/server/runtime/http-server/executor/provider-request-context.js.map +1 -0
- package/dist/server/runtime/http-server/executor/provider-response-converter.d.ts +23 -0
- package/dist/server/runtime/http-server/executor/provider-response-converter.js +337 -0
- package/dist/server/runtime/http-server/executor/provider-response-converter.js.map +1 -0
- package/dist/server/runtime/http-server/executor/provider-response-utils.d.ts +8 -0
- package/dist/server/runtime/http-server/executor/provider-response-utils.js +93 -0
- package/dist/server/runtime/http-server/executor/provider-response-utils.js.map +1 -0
- package/dist/server/runtime/http-server/executor/provider-runtime-resolver.d.ts +23 -0
- package/dist/server/runtime/http-server/executor/provider-runtime-resolver.js +85 -0
- package/dist/server/runtime/http-server/executor/provider-runtime-resolver.js.map +1 -0
- package/dist/server/runtime/http-server/executor/request-executor-core-utils.d.ts +7 -0
- package/dist/server/runtime/http-server/executor/request-executor-core-utils.js +39 -0
- package/dist/server/runtime/http-server/executor/request-executor-core-utils.js.map +1 -0
- package/dist/server/runtime/http-server/executor/request-retry-helpers.d.ts +16 -0
- package/dist/server/runtime/http-server/executor/request-retry-helpers.js +218 -0
- package/dist/server/runtime/http-server/executor/request-retry-helpers.js.map +1 -0
- package/dist/server/runtime/http-server/executor/retry-engine.d.ts +21 -0
- package/dist/server/runtime/http-server/executor/retry-engine.js +73 -0
- package/dist/server/runtime/http-server/executor/retry-engine.js.map +1 -0
- package/dist/server/runtime/http-server/executor/sse-error-handler.d.ts +14 -0
- package/dist/server/runtime/http-server/executor/sse-error-handler.js +127 -0
- package/dist/server/runtime/http-server/executor/sse-error-handler.js.map +1 -0
- package/dist/server/runtime/http-server/executor/usage-aggregator.d.ts +39 -0
- package/dist/server/runtime/http-server/executor/usage-aggregator.js +177 -0
- package/dist/server/runtime/http-server/executor/usage-aggregator.js.map +1 -0
- package/dist/server/runtime/http-server/executor/usage-logger.d.ts +7 -0
- package/dist/server/runtime/http-server/executor/usage-logger.js +13 -0
- package/dist/server/runtime/http-server/executor/usage-logger.js.map +1 -0
- package/dist/server/runtime/http-server/executor/utils.d.ts +21 -0
- package/dist/server/runtime/http-server/executor/utils.js +62 -0
- package/dist/server/runtime/http-server/executor/utils.js.map +1 -0
- package/dist/server/runtime/http-server/executor-metadata.js +83 -2
- package/dist/server/runtime/http-server/executor-metadata.js.map +1 -1
- package/dist/server/runtime/http-server/executor-response.js +17 -9
- package/dist/server/runtime/http-server/executor-response.js.map +1 -1
- package/dist/server/runtime/http-server/http-server-bootstrap.d.ts +31 -0
- package/dist/server/runtime/http-server/http-server-bootstrap.js +367 -0
- package/dist/server/runtime/http-server/http-server-bootstrap.js.map +1 -0
- package/dist/server/runtime/http-server/http-server-clock-daemon.d.ts +5 -0
- package/dist/server/runtime/http-server/http-server-clock-daemon.js +242 -0
- package/dist/server/runtime/http-server/http-server-clock-daemon.js.map +1 -0
- package/dist/server/runtime/http-server/http-server-legacy-pipeline.d.ts +2 -0
- package/dist/server/runtime/http-server/http-server-legacy-pipeline.js +65 -0
- package/dist/server/runtime/http-server/http-server-legacy-pipeline.js.map +1 -0
- package/dist/server/runtime/http-server/http-server-lifecycle.d.ts +27 -0
- package/dist/server/runtime/http-server/http-server-lifecycle.js +285 -0
- package/dist/server/runtime/http-server/http-server-lifecycle.js.map +1 -0
- package/dist/server/runtime/http-server/http-server-runtime-providers.d.ts +10 -0
- package/dist/server/runtime/http-server/http-server-runtime-providers.js +415 -0
- package/dist/server/runtime/http-server/http-server-runtime-providers.js.map +1 -0
- package/dist/server/runtime/http-server/http-server-runtime-setup.d.ts +2 -0
- package/dist/server/runtime/http-server/http-server-runtime-setup.js +93 -0
- package/dist/server/runtime/http-server/http-server-runtime-setup.js.map +1 -0
- package/dist/server/runtime/http-server/index.d.ts +2 -46
- package/dist/server/runtime/http-server/index.js +96 -2615
- package/dist/server/runtime/http-server/index.js.map +1 -1
- package/dist/server/runtime/http-server/request-executor.d.ts +8 -21
- package/dist/server/runtime/http-server/request-executor.js +94 -956
- package/dist/server/runtime/http-server/request-executor.js.map +1 -1
- package/dist/server/runtime/http-server/routes.js +2 -2
- package/dist/server/runtime/http-server/routes.js.map +1 -1
- package/dist/server/runtime/http-server/servertool-admin-state.d.ts +42 -0
- package/dist/server/runtime/http-server/servertool-admin-state.js +210 -0
- package/dist/server/runtime/http-server/servertool-admin-state.js.map +1 -0
- package/dist/server/runtime/http-server/stats-manager-internals.d.ts +96 -0
- package/dist/server/runtime/http-server/stats-manager-internals.js +311 -0
- package/dist/server/runtime/http-server/stats-manager-internals.js.map +1 -0
- package/dist/server/runtime/http-server/stats-manager-table.d.ts +6 -0
- package/dist/server/runtime/http-server/stats-manager-table.js +135 -0
- package/dist/server/runtime/http-server/stats-manager-table.js.map +1 -0
- package/dist/server/runtime/http-server/stats-manager.d.ts +0 -23
- package/dist/server/runtime/http-server/stats-manager.js +95 -483
- package/dist/server/runtime/http-server/stats-manager.js.map +1 -1
- package/dist/server/utils/client-connection-state.js +61 -0
- package/dist/server/utils/client-connection-state.js.map +1 -1
- package/dist/server/utils/request-id-manager.d.ts +6 -0
- package/dist/server/utils/request-id-manager.js +105 -15
- package/dist/server/utils/request-id-manager.js.map +1 -1
- package/dist/server/utils/stage-logger.js +14 -4
- package/dist/server/utils/stage-logger.js.map +1 -1
- package/dist/server-lifecycle/index.d.ts +6 -0
- package/dist/server-lifecycle/index.js +7 -0
- package/dist/server-lifecycle/index.js.map +1 -0
- package/dist/server-lifecycle/port-utils.d.ts +18 -0
- package/dist/server-lifecycle/port-utils.js +204 -0
- package/dist/server-lifecycle/port-utils.js.map +1 -0
- package/dist/sharedmodule/process-snapshot.d.ts +26 -0
- package/dist/sharedmodule/process-snapshot.js +141 -0
- package/dist/sharedmodule/process-snapshot.js.map +1 -0
- package/dist/token-daemon/index.js +10 -3
- package/dist/token-daemon/index.js.map +1 -1
- package/dist/token-daemon/token-daemon.js +9 -11
- package/dist/token-daemon/token-daemon.js.map +1 -1
- package/dist/token-daemon/token-utils.d.ts +1 -1
- package/dist/token-daemon/token-utils.js +19 -3
- package/dist/token-daemon/token-utils.js.map +1 -1
- package/dist/tools/semantic-replay-snapshot-loader.d.ts +4 -0
- package/dist/tools/semantic-replay-snapshot-loader.js +396 -0
- package/dist/tools/semantic-replay-snapshot-loader.js.map +1 -0
- package/dist/tools/semantic-replay.js +2 -393
- package/dist/tools/semantic-replay.js.map +1 -1
- package/dist/utils/daemon-stop-intent.d.ts +17 -0
- package/dist/utils/daemon-stop-intent.js +104 -0
- package/dist/utils/daemon-stop-intent.js.map +1 -0
- package/dist/utils/key-429-tracker.js +6 -5
- package/dist/utils/key-429-tracker.js.map +1 -1
- package/dist/utils/managed-server-pids.js +44 -6
- package/dist/utils/managed-server-pids.js.map +1 -1
- package/dist/utils/pipeline-health-manager.js +7 -6
- package/dist/utils/pipeline-health-manager.js.map +1 -1
- package/dist/utils/process-lifecycle-logger.js +45 -1
- package/dist/utils/process-lifecycle-logger.js.map +1 -1
- package/dist/utils/runtime-exit-forensics.d.ts +2 -2
- package/dist/utils/runtime-exit-forensics.js +10 -5
- package/dist/utils/runtime-exit-forensics.js.map +1 -1
- package/dist/utils/snapshot-writer.js +3 -3
- package/dist/utils/snapshot-writer.js.map +1 -1
- package/docs/QUOTA_MANAGER_V3.md +3 -0
- package/docs/VIRTUAL_ROUTER_PRIORITY_AND_HEALTH.md +114 -0
- package/docs/daemon-admin-ui.html +268 -11
- package/docs/file-line-limit-gate.md +30 -0
- package/docs/refactoring/host-164.3-responsibility-migration.md +62 -0
- package/docs/release-iflow-400-gate.md +58 -0
- package/docs/replay-evidence-iflow-400.txt +33 -0
- package/docs/stop-message-auto.md +4 -3
- package/package.json +4 -3
- package/scripts/auth-iflow-manual.mjs +13 -23
- package/scripts/camoufox/launch-auth.mjs +158 -10
- package/scripts/ci/check-file-line-limit.mjs +149 -0
- package/scripts/copy-compat-assets.mjs +26 -0
- package/scripts/tests/ci-jest.mjs +4 -0
- package/scripts/verify-codex-error-samples.mjs +27 -6
|
@@ -1,22 +1,25 @@
|
|
|
1
|
-
import fs from 'node:fs';
|
|
2
|
-
import path from 'node:path';
|
|
3
1
|
import { homedir } from 'node:os';
|
|
4
|
-
import fsAsync from 'node:fs/promises';
|
|
5
|
-
import { fetchAntigravityQuotaSnapshot, loadAntigravityAccessToken } from '../../../providers/core/runtime/antigravity-quota-client.js';
|
|
6
|
-
import { scanProviderTokenFiles } from '../../../providers/auth/token-scanner/index.js';
|
|
7
|
-
import { resolveAntigravityApiBase } from '../../../providers/auth/antigravity-userinfo-helper.js';
|
|
8
2
|
import * as llmsBridge from '../../../modules/llmswitch/bridge.js';
|
|
9
|
-
import {
|
|
3
|
+
import { assertCoreQuotaManagerApis } from './antigravity-quota-core.js';
|
|
4
|
+
import { buildAntigravitySnapshotKey, computeResetAt, extractAntigravityAlias, isAntigravityModelProtected, parseAntigravityProviderKey, parseAntigravitySnapshotKey, readProtectedModelsFromTokenFile } from './antigravity-quota-helpers.js';
|
|
5
|
+
import { createQuotaStore, loadAntigravitySnapshotFromDisk, saveAntigravitySnapshotToDisk } from './antigravity-quota-persistence.js';
|
|
6
|
+
import { applyAntigravityQuotaToCore, refreshAllAntigravityQuotas, syncAntigravityTokensFromDisk } from './antigravity-quota-sync.js';
|
|
7
|
+
import { getSnapshotRecordByAliasAndModel, handleQuotaPersistenceIssue, reconcileProtectedStates, scheduleNextRefresh as scheduleNextQuotaRefresh, subscribeToProviderCenters as subscribeQuotaProviderCenters } from './antigravity-quota-runtime.js';
|
|
8
|
+
const ANTIGRAVITY_PROTECTED_REASON = 'protected';
|
|
10
9
|
export class QuotaManagerModule {
|
|
11
10
|
id = 'quota';
|
|
12
11
|
snapshot = {};
|
|
13
12
|
antigravityTokens = new Map();
|
|
13
|
+
antigravityProtectedModels = new Map();
|
|
14
|
+
registeredProviderKeys = new Set();
|
|
14
15
|
refreshTimer = null;
|
|
15
16
|
quotaRoutingEnabled = true;
|
|
16
17
|
refreshFailures = 0;
|
|
17
18
|
refreshDisabled = false;
|
|
18
19
|
providerErrorUnsub = null;
|
|
19
20
|
providerSuccessUnsub = null;
|
|
21
|
+
quotaStorePersistenceStatus = 'unknown';
|
|
22
|
+
quotaStoreLastUnbindReason = null;
|
|
20
23
|
coreQuotaManager = null;
|
|
21
24
|
quotaStorePath = null;
|
|
22
25
|
resolveHomeDir() {
|
|
@@ -27,59 +30,58 @@ export class QuotaManagerModule {
|
|
|
27
30
|
return homedir();
|
|
28
31
|
}
|
|
29
32
|
async init(context) {
|
|
30
|
-
this.snapshot = this.
|
|
33
|
+
this.snapshot = loadAntigravitySnapshotFromDisk(() => this.resolveHomeDir());
|
|
31
34
|
this.quotaRoutingEnabled = context.quotaRoutingEnabled !== false;
|
|
32
|
-
// IMPORTANT: prune persisted quota aliases using current token files on disk.
|
|
33
|
-
// We must not “invent” aliases; admin UI should only show aliases that have a token file.
|
|
34
|
-
// This is cheap (local fs read) and prevents stale entries like antigravity://a1/... lingering forever.
|
|
35
35
|
try {
|
|
36
36
|
await this.syncAntigravityTokensFromDisk();
|
|
37
37
|
}
|
|
38
38
|
catch {
|
|
39
39
|
// best-effort; never block server init
|
|
40
40
|
}
|
|
41
|
-
// Core-owned quota manager: host provides only persistence I/O.
|
|
42
|
-
// When quota routing is enabled, this must be available; otherwise Virtual Router quotaView becomes non-deterministic.
|
|
43
41
|
if (!this.quotaRoutingEnabled) {
|
|
44
42
|
this.coreQuotaManager = null;
|
|
45
43
|
return;
|
|
46
44
|
}
|
|
47
|
-
const store =
|
|
45
|
+
const store = createQuotaStore({
|
|
46
|
+
resolveHomeDir: () => this.resolveHomeDir(),
|
|
47
|
+
onStorePath: (filePath) => {
|
|
48
|
+
this.quotaStorePath = filePath;
|
|
49
|
+
},
|
|
50
|
+
onStatus: (status) => {
|
|
51
|
+
this.quotaStorePersistenceStatus = status;
|
|
52
|
+
if (status === 'loaded') {
|
|
53
|
+
this.quotaStoreLastUnbindReason = null;
|
|
54
|
+
}
|
|
55
|
+
},
|
|
56
|
+
onSessionUnbindIssue: (reason) => {
|
|
57
|
+
this.handleSessionUnbindForQuotaPersistenceIssue(reason);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
48
60
|
this.coreQuotaManager = (await llmsBridge.createCoreQuotaManager({ store }));
|
|
49
|
-
|
|
50
|
-
const missingApis = !mgrAny ||
|
|
51
|
-
typeof mgrAny.getQuotaView !== 'function' ||
|
|
52
|
-
typeof mgrAny.getSnapshot !== 'function' ||
|
|
53
|
-
typeof mgrAny.updateProviderPoolState !== 'function' ||
|
|
54
|
-
typeof mgrAny.resetProvider !== 'function' ||
|
|
55
|
-
typeof mgrAny.recoverProvider !== 'function' ||
|
|
56
|
-
typeof mgrAny.disableProvider !== 'function';
|
|
57
|
-
if (missingApis) {
|
|
58
|
-
const detail = {
|
|
59
|
-
hasMgr: Boolean(mgrAny),
|
|
60
|
-
getQuotaView: typeof mgrAny?.getQuotaView,
|
|
61
|
-
getSnapshot: typeof mgrAny?.getSnapshot,
|
|
62
|
-
updateProviderPoolState: typeof mgrAny?.updateProviderPoolState,
|
|
63
|
-
resetProvider: typeof mgrAny?.resetProvider,
|
|
64
|
-
recoverProvider: typeof mgrAny?.recoverProvider,
|
|
65
|
-
disableProvider: typeof mgrAny?.disableProvider
|
|
66
|
-
};
|
|
67
|
-
throw new Error(`core quota manager missing expected APIs: ${JSON.stringify(detail)}`);
|
|
68
|
-
}
|
|
61
|
+
assertCoreQuotaManagerApis(this.coreQuotaManager);
|
|
69
62
|
if (this.coreQuotaManager && typeof this.coreQuotaManager.hydrateFromStore === 'function') {
|
|
70
63
|
await this.coreQuotaManager.hydrateFromStore().catch(() => { });
|
|
71
64
|
}
|
|
72
|
-
|
|
73
|
-
|
|
65
|
+
if (this.quotaStorePersistenceStatus === 'missing' || this.quotaStorePersistenceStatus === 'load_error') {
|
|
66
|
+
this.handleSessionUnbindForQuotaPersistenceIssue(`quota_store_${this.quotaStorePersistenceStatus}`);
|
|
67
|
+
}
|
|
74
68
|
try {
|
|
75
69
|
const nowMs = Date.now();
|
|
76
70
|
for (const [key, record] of Object.entries(this.snapshot)) {
|
|
77
|
-
const parsed =
|
|
71
|
+
const parsed = parseAntigravitySnapshotKey(key);
|
|
78
72
|
if (!parsed) {
|
|
79
73
|
continue;
|
|
80
74
|
}
|
|
81
|
-
|
|
75
|
+
applyAntigravityQuotaToCore({
|
|
76
|
+
coreQuotaManager: this.coreQuotaManager,
|
|
77
|
+
providerKey: `antigravity.${parsed.alias}.${parsed.modelId}`,
|
|
78
|
+
record,
|
|
79
|
+
nowMs,
|
|
80
|
+
protectedReason: ANTIGRAVITY_PROTECTED_REASON,
|
|
81
|
+
isProviderProtected: (providerKey) => this.isAntigravityProviderProtected(providerKey)
|
|
82
|
+
});
|
|
82
83
|
}
|
|
84
|
+
this.reconcileProtectedStatesForRegisteredProviders();
|
|
83
85
|
}
|
|
84
86
|
catch {
|
|
85
87
|
// ignore snapshot apply failures
|
|
@@ -89,15 +91,12 @@ export class QuotaManagerModule {
|
|
|
89
91
|
if (!this.quotaRoutingEnabled) {
|
|
90
92
|
return;
|
|
91
93
|
}
|
|
92
|
-
// Subscribe provider error/success streams -> core quota manager.
|
|
93
94
|
try {
|
|
94
95
|
void this.subscribeToProviderCenters();
|
|
95
96
|
}
|
|
96
97
|
catch {
|
|
97
98
|
// ignore subscription failures
|
|
98
99
|
}
|
|
99
|
-
// IMPORTANT: startup must never block server initialization.
|
|
100
|
-
// Run the initial refresh best-effort in the background; axios timeouts apply per request.
|
|
101
100
|
const refreshPromise = this.refreshAllAntigravityQuotas()
|
|
102
101
|
.then((result) => {
|
|
103
102
|
if (result.attempted > 0 && result.successCount === 0) {
|
|
@@ -113,7 +112,6 @@ export class QuotaManagerModule {
|
|
|
113
112
|
void this.scheduleNextRefresh().catch(() => {
|
|
114
113
|
// ignore scheduling failures
|
|
115
114
|
});
|
|
116
|
-
// In Jest, await the refresh to keep unit tests deterministic.
|
|
117
115
|
if (process.env.JEST_WORKER_ID || process.env.NODE_ENV === 'test') {
|
|
118
116
|
return refreshPromise;
|
|
119
117
|
}
|
|
@@ -128,14 +126,18 @@ export class QuotaManagerModule {
|
|
|
128
126
|
try {
|
|
129
127
|
this.providerErrorUnsub();
|
|
130
128
|
}
|
|
131
|
-
catch {
|
|
129
|
+
catch {
|
|
130
|
+
// ignore
|
|
131
|
+
}
|
|
132
132
|
this.providerErrorUnsub = null;
|
|
133
133
|
}
|
|
134
134
|
if (this.providerSuccessUnsub) {
|
|
135
135
|
try {
|
|
136
136
|
this.providerSuccessUnsub();
|
|
137
137
|
}
|
|
138
|
-
catch {
|
|
138
|
+
catch {
|
|
139
|
+
// ignore
|
|
140
|
+
}
|
|
139
141
|
this.providerSuccessUnsub = null;
|
|
140
142
|
}
|
|
141
143
|
try {
|
|
@@ -146,12 +148,10 @@ export class QuotaManagerModule {
|
|
|
146
148
|
catch {
|
|
147
149
|
// ignore persistence failures
|
|
148
150
|
}
|
|
149
|
-
this.saveSnapshotToDisk()
|
|
151
|
+
void this.saveSnapshotToDisk().catch(() => {
|
|
152
|
+
// best-effort; ignore persistence errors
|
|
153
|
+
});
|
|
150
154
|
}
|
|
151
|
-
/**
|
|
152
|
-
* Admin operation: force-refresh quota snapshots immediately (best-effort).
|
|
153
|
-
* Exposed via daemon-admin endpoint `/quota/refresh`.
|
|
154
|
-
*/
|
|
155
155
|
async refreshNow() {
|
|
156
156
|
const refreshedAt = Date.now();
|
|
157
157
|
try {
|
|
@@ -170,19 +170,15 @@ export class QuotaManagerModule {
|
|
|
170
170
|
catch {
|
|
171
171
|
// ignore scheduling failures
|
|
172
172
|
}
|
|
173
|
-
return {
|
|
173
|
+
return {
|
|
174
|
+
refreshedAt,
|
|
175
|
+
tokenCount: this.antigravityTokens.size,
|
|
176
|
+
recordCount: Object.keys(this.snapshot).length
|
|
177
|
+
};
|
|
174
178
|
}
|
|
175
|
-
/**
|
|
176
|
-
* daemon-admin "reset" semantics for quota module = refresh now.
|
|
177
|
-
* Keeps module UX consistent across admin actions.
|
|
178
|
-
*/
|
|
179
179
|
async reset() {
|
|
180
180
|
return await this.refreshNow();
|
|
181
181
|
}
|
|
182
|
-
/**
|
|
183
|
-
* 用于 antigravity:注册需要追踪配额的 alias/token。
|
|
184
|
-
* 多次调用同一 alias 会覆盖最新配置。
|
|
185
|
-
*/
|
|
186
182
|
registerAntigravityToken(alias, tokenFile, apiBase) {
|
|
187
183
|
const cleanAlias = alias.trim();
|
|
188
184
|
const cleanToken = tokenFile.trim();
|
|
@@ -195,10 +191,20 @@ export class QuotaManagerModule {
|
|
|
195
191
|
tokenFile: cleanToken,
|
|
196
192
|
apiBase: cleanBase
|
|
197
193
|
});
|
|
194
|
+
void readProtectedModelsFromTokenFile(cleanToken)
|
|
195
|
+
.then((protectedModels) => {
|
|
196
|
+
if (protectedModels.size > 0) {
|
|
197
|
+
this.antigravityProtectedModels.set(cleanAlias, protectedModels);
|
|
198
|
+
}
|
|
199
|
+
else {
|
|
200
|
+
this.antigravityProtectedModels.delete(cleanAlias);
|
|
201
|
+
}
|
|
202
|
+
this.reconcileProtectedStatesForRegisteredProviders();
|
|
203
|
+
})
|
|
204
|
+
.catch(() => {
|
|
205
|
+
// best-effort only
|
|
206
|
+
});
|
|
198
207
|
}
|
|
199
|
-
/**
|
|
200
|
-
* 用于 antigravity:根据 alias+model 更新配额快照。
|
|
201
|
-
*/
|
|
202
208
|
updateAntigravityQuota(alias, quota) {
|
|
203
209
|
const aliasId = alias.trim();
|
|
204
210
|
if (!aliasId) {
|
|
@@ -207,41 +213,44 @@ export class QuotaManagerModule {
|
|
|
207
213
|
const now = Date.now();
|
|
208
214
|
const next = { ...this.snapshot };
|
|
209
215
|
for (const [modelId, info] of Object.entries(quota.models)) {
|
|
210
|
-
const key =
|
|
216
|
+
const key = buildAntigravitySnapshotKey(aliasId, modelId);
|
|
211
217
|
const record = {
|
|
212
218
|
remainingFraction: Number.isFinite(info.remainingFraction) ? info.remainingFraction : null,
|
|
213
219
|
fetchedAt: quota.fetchedAt
|
|
214
220
|
};
|
|
215
|
-
const resetAt =
|
|
216
|
-
// Keep resetAt even if it's already in the past so admin UI can inspect drift/staleness.
|
|
217
|
-
// Routing gate still treats `resetAt <= now` as unknown quota and will block entry.
|
|
221
|
+
const resetAt = computeResetAt(info.resetTimeRaw);
|
|
218
222
|
if (resetAt) {
|
|
219
223
|
record.resetAt = resetAt;
|
|
220
224
|
}
|
|
221
225
|
next[key] = record;
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
226
|
+
applyAntigravityQuotaToCore({
|
|
227
|
+
coreQuotaManager: this.coreQuotaManager,
|
|
228
|
+
providerKey: `antigravity.${aliasId}.${modelId}`,
|
|
229
|
+
record,
|
|
230
|
+
nowMs: now,
|
|
231
|
+
protectedReason: ANTIGRAVITY_PROTECTED_REASON,
|
|
232
|
+
isProviderProtected: (providerKey) => this.isAntigravityProviderProtected(providerKey)
|
|
233
|
+
});
|
|
225
234
|
}
|
|
226
235
|
this.snapshot = next;
|
|
227
|
-
this.saveSnapshotToDisk()
|
|
236
|
+
void this.saveSnapshotToDisk().catch(() => {
|
|
237
|
+
// best-effort; ignore persistence errors
|
|
238
|
+
});
|
|
228
239
|
}
|
|
229
|
-
/**
|
|
230
|
-
* 判断给定 providerKey+model 是否有可用配额(仅针对 antigravity 语义)。
|
|
231
|
-
*/
|
|
232
240
|
hasQuotaForAntigravity(providerKey, modelId) {
|
|
233
|
-
const alias =
|
|
241
|
+
const alias = extractAntigravityAlias(providerKey);
|
|
234
242
|
if (!alias || !modelId) {
|
|
235
243
|
return true;
|
|
236
244
|
}
|
|
237
|
-
|
|
245
|
+
if (this.isAntigravityModelProtected(alias, modelId)) {
|
|
246
|
+
return false;
|
|
247
|
+
}
|
|
248
|
+
const key = buildAntigravitySnapshotKey(alias, modelId);
|
|
238
249
|
const record = this.snapshot[key];
|
|
239
250
|
if (!record) {
|
|
240
|
-
// 没有任何配额记录时视为“无配额”,禁止进入路由池。
|
|
241
251
|
return false;
|
|
242
252
|
}
|
|
243
253
|
const now = Date.now();
|
|
244
|
-
// 如果已经超过 resetAt,但尚未刷新到新一轮配额,视为配额状态未知,同样禁止。
|
|
245
254
|
if (record.resetAt && record.resetAt <= now) {
|
|
246
255
|
return false;
|
|
247
256
|
}
|
|
@@ -253,16 +262,12 @@ export class QuotaManagerModule {
|
|
|
253
262
|
getRawSnapshot() {
|
|
254
263
|
return { ...this.snapshot };
|
|
255
264
|
}
|
|
256
|
-
/**
|
|
257
|
-
* VirtualRouter consumes this via HubPipeline `quotaView` injection.
|
|
258
|
-
*/
|
|
259
265
|
getQuotaView() {
|
|
260
266
|
const mgr = this.coreQuotaManager;
|
|
261
267
|
if (!mgr || typeof mgr.getQuotaView !== 'function') {
|
|
262
268
|
return () => null;
|
|
263
269
|
}
|
|
264
270
|
try {
|
|
265
|
-
// IMPORTANT: call as a bound method; core quota manager uses `this.states`.
|
|
266
271
|
return mgr.getQuotaView();
|
|
267
272
|
}
|
|
268
273
|
catch {
|
|
@@ -270,8 +275,6 @@ export class QuotaManagerModule {
|
|
|
270
275
|
}
|
|
271
276
|
}
|
|
272
277
|
getQuotaViewReadOnly() {
|
|
273
|
-
// Current core quota view is already side-effect free for routing semantics;
|
|
274
|
-
// keep the same view function to avoid duplicate logic.
|
|
275
278
|
return this.getQuotaView();
|
|
276
279
|
}
|
|
277
280
|
getAdminSnapshot() {
|
|
@@ -282,6 +285,9 @@ export class QuotaManagerModule {
|
|
|
282
285
|
: {};
|
|
283
286
|
return providers;
|
|
284
287
|
}
|
|
288
|
+
getCoreQuotaManager() {
|
|
289
|
+
return this.quotaRoutingEnabled ? this.coreQuotaManager : null;
|
|
290
|
+
}
|
|
285
291
|
registerProviderStaticConfig(providerKey, config = {}) {
|
|
286
292
|
const key = typeof providerKey === 'string' ? providerKey.trim() : '';
|
|
287
293
|
if (!key)
|
|
@@ -298,8 +304,10 @@ export class QuotaManagerModule {
|
|
|
298
304
|
...(authType === 'apikey' || authType === 'oauth' ? { authType: authType } : {}),
|
|
299
305
|
...(apikeyDailyResetTime ? { apikeyDailyResetTime } : {})
|
|
300
306
|
};
|
|
307
|
+
this.registeredProviderKeys.add(key);
|
|
301
308
|
try {
|
|
302
309
|
this.coreQuotaManager?.registerProviderStaticConfig?.(key, cfg);
|
|
310
|
+
this.reconcileProtectedStatesForRegisteredProviders();
|
|
303
311
|
}
|
|
304
312
|
catch {
|
|
305
313
|
// ignore
|
|
@@ -332,406 +340,101 @@ export class QuotaManagerModule {
|
|
|
332
340
|
await mgr.persistNow?.().catch(() => { });
|
|
333
341
|
return { ok: true };
|
|
334
342
|
}
|
|
335
|
-
|
|
336
|
-
return
|
|
343
|
+
isAntigravityModelProtected(alias, modelId) {
|
|
344
|
+
return isAntigravityModelProtected(this.antigravityProtectedModels, alias, modelId);
|
|
337
345
|
}
|
|
338
|
-
|
|
339
|
-
const
|
|
340
|
-
if (!
|
|
341
|
-
return
|
|
342
|
-
}
|
|
343
|
-
const rest = raw.slice('antigravity://'.length);
|
|
344
|
-
const idx = rest.indexOf('/');
|
|
345
|
-
if (idx <= 0) {
|
|
346
|
-
return null;
|
|
347
|
-
}
|
|
348
|
-
const alias = rest.slice(0, idx).trim();
|
|
349
|
-
const modelId = rest.slice(idx + 1).trim();
|
|
350
|
-
if (!alias || !modelId) {
|
|
351
|
-
return null;
|
|
352
|
-
}
|
|
353
|
-
return { alias, modelId };
|
|
354
|
-
}
|
|
355
|
-
extractAntigravityAlias(providerKey) {
|
|
356
|
-
if (!providerKey || typeof providerKey !== 'string') {
|
|
357
|
-
return null;
|
|
358
|
-
}
|
|
359
|
-
const trimmed = providerKey.trim();
|
|
360
|
-
if (!trimmed.toLowerCase().startsWith('antigravity.')) {
|
|
361
|
-
return null;
|
|
362
|
-
}
|
|
363
|
-
const segments = trimmed.split('.');
|
|
364
|
-
if (segments.length < 2) {
|
|
365
|
-
return null;
|
|
366
|
-
}
|
|
367
|
-
return segments[1];
|
|
368
|
-
}
|
|
369
|
-
computeResetAt(raw) {
|
|
370
|
-
if (!raw || typeof raw !== 'string' || !raw.trim()) {
|
|
371
|
-
return undefined;
|
|
372
|
-
}
|
|
373
|
-
const value = raw.trim();
|
|
374
|
-
try {
|
|
375
|
-
const normalized = value.endsWith('Z') ? value.replace(/Z$/, '+00:00') : value;
|
|
376
|
-
const parsed = Date.parse(normalized);
|
|
377
|
-
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
378
|
-
return undefined;
|
|
379
|
-
}
|
|
380
|
-
return parsed;
|
|
381
|
-
}
|
|
382
|
-
catch {
|
|
383
|
-
return undefined;
|
|
346
|
+
isAntigravityProviderProtected(providerKey) {
|
|
347
|
+
const parsed = parseAntigravityProviderKey(providerKey);
|
|
348
|
+
if (!parsed) {
|
|
349
|
+
return false;
|
|
384
350
|
}
|
|
351
|
+
return this.isAntigravityModelProtected(parsed.alias, parsed.modelId);
|
|
385
352
|
}
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
failureCount += 1;
|
|
404
|
-
continue;
|
|
405
|
-
}
|
|
406
|
-
this.updateAntigravityQuota(alias, snapshot);
|
|
407
|
-
successCount += 1;
|
|
408
|
-
}
|
|
409
|
-
catch {
|
|
410
|
-
failureCount += 1;
|
|
411
|
-
// 单个 alias 失败不影响其他 alias 的刷新
|
|
353
|
+
reconcileProtectedStatesForRegisteredProviders() {
|
|
354
|
+
reconcileProtectedStates({
|
|
355
|
+
coreQuotaManager: this.coreQuotaManager,
|
|
356
|
+
protectedReason: ANTIGRAVITY_PROTECTED_REASON,
|
|
357
|
+
registeredProviderKeys: this.registeredProviderKeys,
|
|
358
|
+
adminSnapshot: this.getAdminSnapshot(),
|
|
359
|
+
isModelProtected: (alias, modelId) => this.isAntigravityModelProtected(alias, modelId),
|
|
360
|
+
getSnapshotRecord: (alias, modelId) => getSnapshotRecordByAliasAndModel(this.snapshot, alias, modelId),
|
|
361
|
+
applyQuotaRecord: (providerKey, record) => {
|
|
362
|
+
applyAntigravityQuotaToCore({
|
|
363
|
+
coreQuotaManager: this.coreQuotaManager,
|
|
364
|
+
providerKey,
|
|
365
|
+
record,
|
|
366
|
+
nowMs: Date.now(),
|
|
367
|
+
protectedReason: ANTIGRAVITY_PROTECTED_REASON,
|
|
368
|
+
isProviderProtected: (key) => this.isAntigravityProviderProtected(key)
|
|
369
|
+
});
|
|
412
370
|
}
|
|
413
|
-
}
|
|
414
|
-
return { attempted, successCount, failureCount };
|
|
415
|
-
}
|
|
416
|
-
applyAntigravityQuotaToCore(providerKey, record, nowMs) {
|
|
417
|
-
const mgr = this.coreQuotaManager;
|
|
418
|
-
if (!mgr || typeof mgr.updateProviderPoolState !== 'function') {
|
|
419
|
-
return;
|
|
420
|
-
}
|
|
421
|
-
const remaining = record.remainingFraction;
|
|
422
|
-
const resetAt = typeof record.resetAt === 'number' && Number.isFinite(record.resetAt) ? record.resetAt : null;
|
|
423
|
-
const withinResetWindow = typeof resetAt === 'number' && resetAt > nowMs;
|
|
424
|
-
const hasQuota = typeof remaining === 'number' && Number.isFinite(remaining) && remaining > 0 && (resetAt === null || withinResetWindow);
|
|
425
|
-
if (hasQuota) {
|
|
426
|
-
mgr.updateProviderPoolState({ providerKey, inPool: true, reason: 'ok', cooldownUntil: null, blacklistUntil: null });
|
|
427
|
-
return;
|
|
428
|
-
}
|
|
429
|
-
mgr.updateProviderPoolState({
|
|
430
|
-
providerKey,
|
|
431
|
-
inPool: false,
|
|
432
|
-
reason: 'quotaDepleted',
|
|
433
|
-
cooldownUntil: null,
|
|
434
|
-
blacklistUntil: null
|
|
435
371
|
});
|
|
436
372
|
}
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
load: async () => {
|
|
443
|
-
// Preferred: new snapshot.
|
|
444
|
-
try {
|
|
445
|
-
const raw = await fsAsync.readFile(filePath, 'utf8');
|
|
446
|
-
const parsed = JSON.parse(String(raw || '').trim() || 'null');
|
|
447
|
-
if (parsed && typeof parsed === 'object' && parsed.providers && typeof parsed.providers === 'object') {
|
|
448
|
-
return parsed;
|
|
449
|
-
}
|
|
450
|
-
}
|
|
451
|
-
catch {
|
|
452
|
-
// ignore
|
|
453
|
-
}
|
|
454
|
-
// Fallback: migrate from legacy provider-quota snapshot if present.
|
|
455
|
-
try {
|
|
456
|
-
const legacy = await loadProviderQuotaSnapshot();
|
|
457
|
-
if (legacy && legacy.providers && typeof legacy.providers === 'object') {
|
|
458
|
-
const nowMs = Date.now();
|
|
459
|
-
return {
|
|
460
|
-
savedAtMs: Number.isFinite(Date.parse(legacy.updatedAt)) ? Date.parse(legacy.updatedAt) : nowMs,
|
|
461
|
-
providers: legacy.providers
|
|
462
|
-
};
|
|
463
|
-
}
|
|
464
|
-
}
|
|
465
|
-
catch {
|
|
466
|
-
// ignore
|
|
467
|
-
}
|
|
468
|
-
return null;
|
|
373
|
+
async refreshAllAntigravityQuotas() {
|
|
374
|
+
return await refreshAllAntigravityQuotas({
|
|
375
|
+
tokens: this.antigravityTokens,
|
|
376
|
+
syncTokensFromDisk: async () => {
|
|
377
|
+
await this.syncAntigravityTokensFromDisk();
|
|
469
378
|
},
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
await fsAsync.mkdir(dir, { recursive: true });
|
|
473
|
-
}
|
|
474
|
-
catch {
|
|
475
|
-
// ignore
|
|
476
|
-
}
|
|
477
|
-
const tmp = `${filePath}.tmp`;
|
|
478
|
-
const text = `${JSON.stringify(snapshot, null, 2)}\n`;
|
|
479
|
-
try {
|
|
480
|
-
await fsAsync.writeFile(tmp, text, 'utf8');
|
|
481
|
-
await fsAsync.rename(tmp, filePath);
|
|
482
|
-
}
|
|
483
|
-
catch {
|
|
484
|
-
try {
|
|
485
|
-
await fsAsync.unlink(tmp);
|
|
486
|
-
}
|
|
487
|
-
catch { /* ignore */ }
|
|
488
|
-
}
|
|
379
|
+
updateAntigravityQuota: (alias, quota) => {
|
|
380
|
+
this.updateAntigravityQuota(alias, quota);
|
|
489
381
|
}
|
|
490
|
-
};
|
|
382
|
+
});
|
|
491
383
|
}
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
}
|
|
500
|
-
return base;
|
|
384
|
+
handleSessionUnbindForQuotaPersistenceIssue(reason) {
|
|
385
|
+
this.quotaStoreLastUnbindReason = handleQuotaPersistenceIssue({
|
|
386
|
+
reason,
|
|
387
|
+
lastReason: this.quotaStoreLastUnbindReason,
|
|
388
|
+
quotaStorePath: this.quotaStorePath,
|
|
389
|
+
clearSessionAliasPins: () => llmsBridge.clearAntigravitySessionAliasPins?.({ hydrate: true })
|
|
390
|
+
});
|
|
501
391
|
}
|
|
502
392
|
async subscribeToProviderCenters() {
|
|
503
|
-
const
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
errorCenter = (await llmsBridge.getProviderErrorCenter());
|
|
510
|
-
}
|
|
511
|
-
catch {
|
|
512
|
-
errorCenter = null;
|
|
513
|
-
}
|
|
514
|
-
if (errorCenter && typeof errorCenter.subscribe === 'function' && typeof mgr.onProviderError === 'function') {
|
|
515
|
-
try {
|
|
516
|
-
this.providerErrorUnsub = errorCenter.subscribe((ev) => {
|
|
517
|
-
try {
|
|
518
|
-
mgr.onProviderError?.(ev);
|
|
519
|
-
}
|
|
520
|
-
catch { /* ignore */ }
|
|
521
|
-
});
|
|
522
|
-
}
|
|
523
|
-
catch {
|
|
524
|
-
this.providerErrorUnsub = null;
|
|
525
|
-
}
|
|
526
|
-
}
|
|
527
|
-
let successCenter = null;
|
|
528
|
-
try {
|
|
529
|
-
successCenter = (await llmsBridge.getProviderSuccessCenter());
|
|
530
|
-
}
|
|
531
|
-
catch {
|
|
532
|
-
successCenter = null;
|
|
533
|
-
}
|
|
534
|
-
if (successCenter && typeof successCenter.subscribe === 'function' && typeof mgr.onProviderSuccess === 'function') {
|
|
535
|
-
try {
|
|
536
|
-
this.providerSuccessUnsub = successCenter.subscribe((ev) => {
|
|
537
|
-
try {
|
|
538
|
-
mgr.onProviderSuccess?.(ev);
|
|
539
|
-
}
|
|
540
|
-
catch { /* ignore */ }
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
catch {
|
|
544
|
-
this.providerSuccessUnsub = null;
|
|
545
|
-
}
|
|
546
|
-
}
|
|
393
|
+
const { providerErrorUnsub, providerSuccessUnsub } = await subscribeQuotaProviderCenters({
|
|
394
|
+
bridge: llmsBridge,
|
|
395
|
+
coreQuotaManager: this.coreQuotaManager
|
|
396
|
+
});
|
|
397
|
+
this.providerErrorUnsub = providerErrorUnsub;
|
|
398
|
+
this.providerSuccessUnsub = providerSuccessUnsub;
|
|
547
399
|
}
|
|
548
|
-
/**
|
|
549
|
-
* 每 5 分钟刷新一次 quota(固定间隔)。
|
|
550
|
-
* 启动时会立即刷新一次,随后由该定时器维持周期刷新。
|
|
551
|
-
*/
|
|
552
400
|
async scheduleNextRefresh() {
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
this.
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
}
|
|
571
|
-
else if (result.successCount > 0) {
|
|
572
|
-
this.refreshFailures = 0;
|
|
573
|
-
}
|
|
574
|
-
})
|
|
575
|
-
.catch(() => {
|
|
576
|
-
this.refreshFailures += 1;
|
|
577
|
-
if (this.refreshFailures >= 3) {
|
|
578
|
-
this.refreshDisabled = true;
|
|
579
|
-
}
|
|
580
|
-
})
|
|
581
|
-
.finally(() => {
|
|
582
|
-
if (!this.refreshDisabled) {
|
|
583
|
-
void this.scheduleNextRefresh().catch(() => {
|
|
584
|
-
// ignore reschedule failure
|
|
585
|
-
});
|
|
586
|
-
}
|
|
587
|
-
});
|
|
588
|
-
}, delayMs);
|
|
589
|
-
this.refreshTimer.unref?.();
|
|
401
|
+
this.refreshTimer = scheduleNextQuotaRefresh({
|
|
402
|
+
currentTimer: this.refreshTimer,
|
|
403
|
+
getRefreshDisabled: () => this.refreshDisabled,
|
|
404
|
+
getRefreshFailures: () => this.refreshFailures,
|
|
405
|
+
refreshAllAntigravityQuotas: () => this.refreshAllAntigravityQuotas(),
|
|
406
|
+
onRefreshFailuresChange: (nextFailures) => {
|
|
407
|
+
this.refreshFailures = nextFailures;
|
|
408
|
+
},
|
|
409
|
+
onRefreshDisabledChange: (nextDisabled) => {
|
|
410
|
+
this.refreshDisabled = nextDisabled;
|
|
411
|
+
},
|
|
412
|
+
onReschedule: () => {
|
|
413
|
+
void this.scheduleNextRefresh().catch(() => {
|
|
414
|
+
// ignore reschedule failure
|
|
415
|
+
});
|
|
416
|
+
}
|
|
417
|
+
});
|
|
590
418
|
}
|
|
591
|
-
/**
|
|
592
|
-
* 自动从本地 auth 目录扫描 antigravity OAuth token,并同步到内存注册表。
|
|
593
|
-
* 这确保「每个 token」都能定期刷新 quota,而不依赖额外的显式注册流程。
|
|
594
|
-
*/
|
|
595
419
|
async syncAntigravityTokensFromDisk() {
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
this.saveSnapshotToDisk();
|
|
609
|
-
}
|
|
610
|
-
return;
|
|
611
|
-
}
|
|
612
|
-
const base = resolveAntigravityApiBase();
|
|
613
|
-
const next = new Map();
|
|
614
|
-
const legacyAliases = [];
|
|
615
|
-
for (const match of matches) {
|
|
616
|
-
// IMPORTANT: alias must match providerKey alias used by VirtualRouter/provider registry:
|
|
617
|
-
// providerKey is `antigravity.<alias>.<modelId>`, where `<alias>` comes from user config entries.
|
|
618
|
-
// Do not prefix with sequence number here, otherwise QUOTA_* events will target keys that routing never uses.
|
|
619
|
-
const alias = (match.alias && match.alias !== 'default' ? match.alias : String(match.sequence)).trim();
|
|
620
|
-
if (!alias) {
|
|
621
|
-
continue;
|
|
622
|
-
}
|
|
623
|
-
const legacyAlias = match.alias && match.alias !== 'default' ? `${match.sequence}-${match.alias}`.trim() : null;
|
|
624
|
-
if (legacyAlias) {
|
|
625
|
-
legacyAliases.push(legacyAlias);
|
|
626
|
-
}
|
|
627
|
-
next.set(alias, {
|
|
628
|
-
alias,
|
|
629
|
-
tokenFile: match.filePath,
|
|
630
|
-
apiBase: base
|
|
420
|
+
const result = await syncAntigravityTokensFromDisk({
|
|
421
|
+
currentTokens: this.antigravityTokens,
|
|
422
|
+
currentSnapshot: this.snapshot,
|
|
423
|
+
parseSnapshotKey: parseAntigravitySnapshotKey,
|
|
424
|
+
readProtectedModelsFromTokenFile
|
|
425
|
+
});
|
|
426
|
+
this.antigravityTokens = result.tokens;
|
|
427
|
+
this.antigravityProtectedModels = result.protectedModels;
|
|
428
|
+
this.snapshot = result.snapshot;
|
|
429
|
+
if (result.snapshotChanged) {
|
|
430
|
+
void this.saveSnapshotToDisk().catch(() => {
|
|
431
|
+
// best-effort; ignore persistence errors
|
|
631
432
|
});
|
|
632
433
|
}
|
|
633
|
-
|
|
634
|
-
for (const [alias, reg] of this.antigravityTokens.entries()) {
|
|
635
|
-
if (!next.has(alias)) {
|
|
636
|
-
next.set(alias, reg);
|
|
637
|
-
}
|
|
638
|
-
}
|
|
639
|
-
this.antigravityTokens = next;
|
|
640
|
-
// Cleanup legacy snapshot keys created by older builds (sequence-prefixed alias like "1-foo").
|
|
641
|
-
// Those keys never match VirtualRouter providerKey aliases and only cause duplicate/stale rows in admin views.
|
|
642
|
-
if (legacyAliases.length && this.snapshot && typeof this.snapshot === 'object') {
|
|
643
|
-
const legacyPrefixes = legacyAliases.map((a) => `antigravity://${a}/`);
|
|
644
|
-
const rawEntries = Object.entries(this.snapshot);
|
|
645
|
-
let changed = false;
|
|
646
|
-
const cleaned = {};
|
|
647
|
-
for (const [key, value] of rawEntries) {
|
|
648
|
-
const drop = legacyPrefixes.some((prefix) => key.startsWith(prefix));
|
|
649
|
-
if (drop) {
|
|
650
|
-
changed = true;
|
|
651
|
-
continue;
|
|
652
|
-
}
|
|
653
|
-
cleaned[key] = value;
|
|
654
|
-
}
|
|
655
|
-
if (changed) {
|
|
656
|
-
this.snapshot = cleaned;
|
|
657
|
-
this.saveSnapshotToDisk();
|
|
658
|
-
}
|
|
659
|
-
}
|
|
660
|
-
// Cleanup stale snapshot keys for aliases that no longer exist on disk.
|
|
661
|
-
// This prevents “phantom aliases” (e.g. a1) from showing up in admin UI when the token file is gone.
|
|
662
|
-
if (this.snapshot && typeof this.snapshot === 'object') {
|
|
663
|
-
const allowedAliases = new Set(Array.from(this.antigravityTokens.keys()));
|
|
664
|
-
const rawEntries = Object.entries(this.snapshot);
|
|
665
|
-
let changed = false;
|
|
666
|
-
const cleaned = {};
|
|
667
|
-
for (const [key, value] of rawEntries) {
|
|
668
|
-
const parsed = this.parseAntigravitySnapshotKey(key);
|
|
669
|
-
if (parsed && !allowedAliases.has(parsed.alias)) {
|
|
670
|
-
changed = true;
|
|
671
|
-
continue;
|
|
672
|
-
}
|
|
673
|
-
cleaned[key] = value;
|
|
674
|
-
}
|
|
675
|
-
if (changed) {
|
|
676
|
-
this.snapshot = cleaned;
|
|
677
|
-
this.saveSnapshotToDisk();
|
|
678
|
-
}
|
|
679
|
-
}
|
|
434
|
+
this.reconcileProtectedStatesForRegisteredProviders();
|
|
680
435
|
}
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
try {
|
|
684
|
-
fs.mkdirSync(baseDir, { recursive: true });
|
|
685
|
-
}
|
|
686
|
-
catch {
|
|
687
|
-
// best effort
|
|
688
|
-
}
|
|
689
|
-
return path.join(baseDir, 'antigravity.json');
|
|
690
|
-
}
|
|
691
|
-
loadSnapshotFromDisk() {
|
|
692
|
-
const filePath = this.resolveStatePath();
|
|
693
|
-
try {
|
|
694
|
-
if (!fs.existsSync(filePath)) {
|
|
695
|
-
return {};
|
|
696
|
-
}
|
|
697
|
-
const content = fs.readFileSync(filePath, 'utf8');
|
|
698
|
-
const parsed = content.trim() ? JSON.parse(content) : {};
|
|
699
|
-
if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
|
|
700
|
-
return {};
|
|
701
|
-
}
|
|
702
|
-
const raw = parsed;
|
|
703
|
-
const result = {};
|
|
704
|
-
for (const [key, value] of Object.entries(raw)) {
|
|
705
|
-
if (!value || typeof value !== 'object') {
|
|
706
|
-
continue;
|
|
707
|
-
}
|
|
708
|
-
let remainingFraction = null;
|
|
709
|
-
if (typeof value.remainingFraction === 'number') {
|
|
710
|
-
remainingFraction = value.remainingFraction ?? null;
|
|
711
|
-
}
|
|
712
|
-
let resetAt;
|
|
713
|
-
if (typeof value.resetAt === 'number') {
|
|
714
|
-
resetAt = value.resetAt;
|
|
715
|
-
}
|
|
716
|
-
const fetchedAt = typeof value.fetchedAt === 'number'
|
|
717
|
-
? value.fetchedAt
|
|
718
|
-
: Date.now();
|
|
719
|
-
result[key] = { remainingFraction, resetAt, fetchedAt };
|
|
720
|
-
}
|
|
721
|
-
return result;
|
|
722
|
-
}
|
|
723
|
-
catch {
|
|
724
|
-
return {};
|
|
725
|
-
}
|
|
726
|
-
}
|
|
727
|
-
saveSnapshotToDisk() {
|
|
728
|
-
const filePath = this.resolveStatePath();
|
|
729
|
-
try {
|
|
730
|
-
fs.writeFileSync(filePath, `${JSON.stringify(this.snapshot, null, 2)}\n`, 'utf8');
|
|
731
|
-
}
|
|
732
|
-
catch {
|
|
733
|
-
// best effort
|
|
734
|
-
}
|
|
436
|
+
async saveSnapshotToDisk() {
|
|
437
|
+
await saveAntigravitySnapshotToDisk(() => this.resolveHomeDir(), this.snapshot);
|
|
735
438
|
}
|
|
736
439
|
}
|
|
737
440
|
//# sourceMappingURL=antigravity-quota-manager.js.map
|