@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,247 +1,21 @@
|
|
|
1
|
-
import { writeClientSnapshot } from '../../../providers/core/utils/snapshot-writer.js';
|
|
2
1
|
import { asRecord } from './provider-utils.js';
|
|
3
2
|
import { attachProviderRuntimeMetadata } from '../../../providers/core/runtime/provider-runtime-metadata.js';
|
|
4
|
-
import { extractAnthropicToolAliasMap } from './anthropic-tool-alias.js';
|
|
5
|
-
import { enhanceProviderRequestId } from '../../utils/request-id-manager.js';
|
|
6
3
|
import { buildRequestMetadata, cloneClientHeaders, decorateMetadataForAttempt, ensureClientHeadersOnPayload, resolveClientRequestId } from './executor-metadata.js';
|
|
7
|
-
import {
|
|
8
|
-
import { convertProviderResponse as bridgeConvertProviderResponse, createSnapshotRecorder as bridgeCreateSnapshotRecorder, } from '../../../modules/llmswitch/bridge.js';
|
|
9
|
-
import { getClockClientRegistry, injectClockClientPrompt } from './clock-client-registry.js';
|
|
4
|
+
import { convertProviderResponseIfNeeded as convertProviderResponseWithBridge } from './executor/provider-response-converter.js';
|
|
10
5
|
import { ensureHubPipeline, runHubPipeline } from './executor-pipeline.js';
|
|
11
|
-
|
|
6
|
+
// Import from new executor submodules
|
|
7
|
+
import { isUsageLoggingEnabled, isVerboseErrorLoggingEnabled } from './executor/env-config.js';
|
|
8
|
+
import { resolveMaxProviderAttempts, describeRetryReason, shouldRetryProviderError, waitBeforeRetry } from './executor/retry-engine.js';
|
|
9
|
+
import {} from './executor/sse-error-handler.js';
|
|
10
|
+
import { extractUsageFromResult, mergeUsageMetrics } from './executor/usage-aggregator.js';
|
|
11
|
+
import { bindClockConversationSession, extractRetryErrorSignature, extractStatusCodeFromError, injectAntigravityRetrySignal, isAntigravityProviderKey, isAntigravityReauthRequired403, isGoogleAccountVerificationRequiredError, isSseDecodeRateLimitError, resolveAntigravityMaxProviderAttempts, shouldRotateAntigravityAliasOnRetry } from './executor/request-retry-helpers.js';
|
|
12
|
+
import { cloneRequestPayload, extractProviderModel, extractResponseStatus, normalizeProviderResponse, resolveRequestSemantics } from './executor/provider-response-utils.js';
|
|
13
|
+
import { isPoolExhaustedPipelineError, writeInboundClientSnapshot } from './executor/request-executor-core-utils.js';
|
|
14
|
+
import { resolveProviderRuntimeOrThrow } from './executor/provider-runtime-resolver.js';
|
|
15
|
+
import { resolveProviderRequestContext } from './executor/provider-request-context.js';
|
|
16
|
+
import { logUsageSummary } from './executor/usage-logger.js';
|
|
17
|
+
import { isServerToolEnabled } from './servertool-admin-state.js';
|
|
12
18
|
const DEFAULT_MAX_PROVIDER_ATTEMPTS = 6;
|
|
13
|
-
const DEFAULT_ANTIGRAVITY_MAX_PROVIDER_ATTEMPTS = 20;
|
|
14
|
-
const RETRYABLE_SSE_ERROR_CODE_HINTS = [
|
|
15
|
-
'internal_network_failure',
|
|
16
|
-
'network_error',
|
|
17
|
-
'api_connection_error',
|
|
18
|
-
'service_unavailable',
|
|
19
|
-
'internal_server_error',
|
|
20
|
-
'overloaded_error',
|
|
21
|
-
'rate_limit_error',
|
|
22
|
-
'request_timeout',
|
|
23
|
-
'timeout'
|
|
24
|
-
];
|
|
25
|
-
const RETRYABLE_SSE_MESSAGE_HINTS = [
|
|
26
|
-
'internal network failure',
|
|
27
|
-
'network failure',
|
|
28
|
-
'network error',
|
|
29
|
-
'temporarily unavailable',
|
|
30
|
-
'temporarily unreachable',
|
|
31
|
-
'upstream disconnected',
|
|
32
|
-
'connection reset',
|
|
33
|
-
'connection closed',
|
|
34
|
-
'timed out',
|
|
35
|
-
'timeout'
|
|
36
|
-
];
|
|
37
|
-
function firstNonEmptyString(candidates) {
|
|
38
|
-
for (const candidate of candidates) {
|
|
39
|
-
if (typeof candidate !== 'string') {
|
|
40
|
-
continue;
|
|
41
|
-
}
|
|
42
|
-
const trimmed = candidate.trim();
|
|
43
|
-
if (trimmed) {
|
|
44
|
-
return trimmed;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
return undefined;
|
|
48
|
-
}
|
|
49
|
-
function firstFiniteNumber(candidates) {
|
|
50
|
-
for (const candidate of candidates) {
|
|
51
|
-
if (typeof candidate === 'number' && Number.isFinite(candidate)) {
|
|
52
|
-
return candidate;
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
return undefined;
|
|
56
|
-
}
|
|
57
|
-
function isRetryableSseWrapperError(message, errorCode, status) {
|
|
58
|
-
if (typeof status === 'number' && Number.isFinite(status)) {
|
|
59
|
-
if (status === 408 || status === 425 || status === 429 || status >= 500) {
|
|
60
|
-
return true;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
const normalizedCode = typeof errorCode === 'string' ? errorCode.trim().toLowerCase() : '';
|
|
64
|
-
if (normalizedCode && RETRYABLE_SSE_ERROR_CODE_HINTS.some((hint) => normalizedCode.includes(hint))) {
|
|
65
|
-
return true;
|
|
66
|
-
}
|
|
67
|
-
const loweredMessage = message.toLowerCase();
|
|
68
|
-
return RETRYABLE_SSE_MESSAGE_HINTS.some((hint) => loweredMessage.includes(hint));
|
|
69
|
-
}
|
|
70
|
-
function resolveBoolFromEnv(value, fallback) {
|
|
71
|
-
if (!value) {
|
|
72
|
-
return fallback;
|
|
73
|
-
}
|
|
74
|
-
const normalized = value.trim().toLowerCase();
|
|
75
|
-
if (['1', 'true', 'yes', 'on'].includes(normalized)) {
|
|
76
|
-
return true;
|
|
77
|
-
}
|
|
78
|
-
if (['0', 'false', 'no', 'off'].includes(normalized)) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return fallback;
|
|
82
|
-
}
|
|
83
|
-
function isUsageLoggingEnabled() {
|
|
84
|
-
return resolveBoolFromEnv(process.env.ROUTECODEX_USAGE_LOG ?? process.env.RCC_USAGE_LOG, buildInfo.mode !== 'release');
|
|
85
|
-
}
|
|
86
|
-
function resolveMaxProviderAttempts() {
|
|
87
|
-
const raw = String(process.env.ROUTECODEX_MAX_PROVIDER_ATTEMPTS || process.env.RCC_MAX_PROVIDER_ATTEMPTS || '')
|
|
88
|
-
.trim()
|
|
89
|
-
.toLowerCase();
|
|
90
|
-
const parsed = raw ? Number.parseInt(raw, 10) : NaN;
|
|
91
|
-
const candidate = Number.isFinite(parsed) ? parsed : DEFAULT_MAX_PROVIDER_ATTEMPTS;
|
|
92
|
-
return Math.max(1, Math.min(20, candidate));
|
|
93
|
-
}
|
|
94
|
-
function resolveAntigravityMaxProviderAttempts() {
|
|
95
|
-
const raw = String(process.env.ROUTECODEX_ANTIGRAVITY_MAX_PROVIDER_ATTEMPTS || process.env.RCC_ANTIGRAVITY_MAX_PROVIDER_ATTEMPTS || '')
|
|
96
|
-
.trim()
|
|
97
|
-
.toLowerCase();
|
|
98
|
-
const parsed = raw ? Number.parseInt(raw, 10) : NaN;
|
|
99
|
-
const candidate = Number.isFinite(parsed) ? parsed : DEFAULT_ANTIGRAVITY_MAX_PROVIDER_ATTEMPTS;
|
|
100
|
-
return Math.max(1, Math.min(60, candidate));
|
|
101
|
-
}
|
|
102
|
-
function isAntigravityProviderKey(providerKey) {
|
|
103
|
-
return typeof providerKey === 'string' && providerKey.startsWith('antigravity.');
|
|
104
|
-
}
|
|
105
|
-
function isGoogleAccountVerificationRequiredError(err) {
|
|
106
|
-
if (!err || typeof err !== 'object') {
|
|
107
|
-
return false;
|
|
108
|
-
}
|
|
109
|
-
const messageRaw = err.message;
|
|
110
|
-
const message = typeof messageRaw === 'string' ? messageRaw : '';
|
|
111
|
-
if (!message) {
|
|
112
|
-
return false;
|
|
113
|
-
}
|
|
114
|
-
const lowered = message.toLowerCase();
|
|
115
|
-
return (lowered.includes('verify your account') ||
|
|
116
|
-
// Antigravity-Manager alignment: 403 validation gating keywords.
|
|
117
|
-
lowered.includes('validation_required') ||
|
|
118
|
-
lowered.includes('validation required') ||
|
|
119
|
-
lowered.includes('validation_url') ||
|
|
120
|
-
lowered.includes('validation url') ||
|
|
121
|
-
lowered.includes('accounts.google.com/signin/continue') ||
|
|
122
|
-
lowered.includes('support.google.com/accounts?p=al_alert'));
|
|
123
|
-
}
|
|
124
|
-
function isAntigravityReauthRequired403(err) {
|
|
125
|
-
if (!err || typeof err !== 'object') {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
const status = extractStatusCodeFromError(err);
|
|
129
|
-
if (status !== 403) {
|
|
130
|
-
return false;
|
|
131
|
-
}
|
|
132
|
-
if (isGoogleAccountVerificationRequiredError(err)) {
|
|
133
|
-
return false;
|
|
134
|
-
}
|
|
135
|
-
const messageRaw = err.message;
|
|
136
|
-
const message = typeof messageRaw === 'string' ? messageRaw : '';
|
|
137
|
-
if (!message) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
const lowered = message.toLowerCase();
|
|
141
|
-
return (lowered.includes('please authenticate with google oauth first') ||
|
|
142
|
-
lowered.includes('authenticate with google oauth') ||
|
|
143
|
-
lowered.includes('missing required authentication credential') ||
|
|
144
|
-
lowered.includes('request is missing required authentication') ||
|
|
145
|
-
lowered.includes('unauthenticated') ||
|
|
146
|
-
lowered.includes('invalid token') ||
|
|
147
|
-
lowered.includes('invalid_grant') ||
|
|
148
|
-
lowered.includes('unauthorized') ||
|
|
149
|
-
lowered.includes('token expired') ||
|
|
150
|
-
lowered.includes('expired token'));
|
|
151
|
-
}
|
|
152
|
-
function shouldRotateAntigravityAliasOnRetry(error) {
|
|
153
|
-
// Antigravity safety: do not rotate between Antigravity aliases within a single request.
|
|
154
|
-
// Multi-account switching (especially during 4xx/429 states) can cascade into cross-account reauth (403 verify) events.
|
|
155
|
-
return false;
|
|
156
|
-
}
|
|
157
|
-
function extractStatusCodeFromError(err) {
|
|
158
|
-
if (!err || typeof err !== 'object')
|
|
159
|
-
return undefined;
|
|
160
|
-
const direct = err.statusCode;
|
|
161
|
-
if (typeof direct === 'number')
|
|
162
|
-
return direct;
|
|
163
|
-
const nested = err.status;
|
|
164
|
-
if (typeof nested === 'number')
|
|
165
|
-
return nested;
|
|
166
|
-
return undefined;
|
|
167
|
-
}
|
|
168
|
-
function extractRetryErrorSignature(err) {
|
|
169
|
-
if (!err || typeof err !== 'object') {
|
|
170
|
-
return 'unknown';
|
|
171
|
-
}
|
|
172
|
-
const status = extractStatusCodeFromError(err);
|
|
173
|
-
if (status === 403 && isGoogleAccountVerificationRequiredError(err)) {
|
|
174
|
-
return '403:GOOGLE_VERIFY';
|
|
175
|
-
}
|
|
176
|
-
if (status === 403 && isAntigravityReauthRequired403(err)) {
|
|
177
|
-
return '403:OAUTH_REAUTH';
|
|
178
|
-
}
|
|
179
|
-
const codeRaw = err.code;
|
|
180
|
-
const upstreamCodeRaw = err.upstreamCode;
|
|
181
|
-
const upstreamCode = typeof upstreamCodeRaw === 'string' && upstreamCodeRaw.trim() ? upstreamCodeRaw.trim() : undefined;
|
|
182
|
-
const code = typeof codeRaw === 'string' && codeRaw.trim() ? codeRaw.trim() : undefined;
|
|
183
|
-
const parts = [
|
|
184
|
-
typeof status === 'number' && Number.isFinite(status) ? String(status) : '',
|
|
185
|
-
upstreamCode || '',
|
|
186
|
-
code || ''
|
|
187
|
-
].filter((p) => p.length > 0);
|
|
188
|
-
return parts.length ? parts.join(':') : 'unknown';
|
|
189
|
-
}
|
|
190
|
-
function injectAntigravityRetrySignal(metadata, signal) {
|
|
191
|
-
if (!signal || !signal.signature || signal.consecutive <= 0) {
|
|
192
|
-
return;
|
|
193
|
-
}
|
|
194
|
-
const carrier = metadata;
|
|
195
|
-
const existing = carrier.__rt && typeof carrier.__rt === 'object' && !Array.isArray(carrier.__rt) ? carrier.__rt : {};
|
|
196
|
-
carrier.__rt = {
|
|
197
|
-
...existing,
|
|
198
|
-
antigravityRetryErrorSignature: signal.signature,
|
|
199
|
-
antigravityRetryErrorConsecutive: signal.consecutive,
|
|
200
|
-
...(signal.avoidAllOnRetry === true ? { antigravityAvoidAllOnRetry: true } : {})
|
|
201
|
-
};
|
|
202
|
-
}
|
|
203
|
-
function normalizeSessionToken(value) {
|
|
204
|
-
if (typeof value !== 'string') {
|
|
205
|
-
return undefined;
|
|
206
|
-
}
|
|
207
|
-
const trimmed = value.trim();
|
|
208
|
-
return trimmed || undefined;
|
|
209
|
-
}
|
|
210
|
-
function inferClockClientTypeFromMetadata(metadata) {
|
|
211
|
-
const direct = normalizeSessionToken(metadata.clockClientType) ?? normalizeSessionToken(metadata.clientType);
|
|
212
|
-
if (direct) {
|
|
213
|
-
return direct;
|
|
214
|
-
}
|
|
215
|
-
const userAgent = normalizeSessionToken(metadata.userAgent)?.toLowerCase() ?? '';
|
|
216
|
-
if (userAgent.includes('codex')) {
|
|
217
|
-
return 'codex';
|
|
218
|
-
}
|
|
219
|
-
if (userAgent.includes('claude')) {
|
|
220
|
-
return 'claude';
|
|
221
|
-
}
|
|
222
|
-
return undefined;
|
|
223
|
-
}
|
|
224
|
-
function bindClockConversationSession(metadata) {
|
|
225
|
-
const conversationSessionId = normalizeSessionToken(metadata.sessionId);
|
|
226
|
-
if (!conversationSessionId) {
|
|
227
|
-
return;
|
|
228
|
-
}
|
|
229
|
-
const tmuxSessionId = normalizeSessionToken(metadata.tmuxSessionId);
|
|
230
|
-
const daemonId = normalizeSessionToken(metadata.clockDaemonId)
|
|
231
|
-
?? normalizeSessionToken(metadata.clockClientDaemonId);
|
|
232
|
-
const clientType = inferClockClientTypeFromMetadata(metadata);
|
|
233
|
-
try {
|
|
234
|
-
getClockClientRegistry().bindConversationSession({
|
|
235
|
-
conversationSessionId,
|
|
236
|
-
...(tmuxSessionId ? { tmuxSessionId } : {}),
|
|
237
|
-
...(daemonId ? { daemonId } : {}),
|
|
238
|
-
...(clientType ? { clientType } : {})
|
|
239
|
-
});
|
|
240
|
-
}
|
|
241
|
-
catch {
|
|
242
|
-
// best-effort only
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
19
|
export class HubRequestExecutor {
|
|
246
20
|
deps;
|
|
247
21
|
constructor(deps) {
|
|
@@ -268,32 +42,12 @@ export class HubRequestExecutor {
|
|
|
268
42
|
endpoint: input.entryEndpoint,
|
|
269
43
|
stream: initialMetadata.stream === true
|
|
270
44
|
});
|
|
271
|
-
|
|
272
|
-
const headerUa = (typeof input.headers?.['user-agent'] === 'string' && input.headers['user-agent']) ||
|
|
273
|
-
(typeof input.headers?.['User-Agent'] === 'string' && input.headers['User-Agent']);
|
|
274
|
-
const headerOriginator = (typeof input.headers?.['originator'] === 'string' && input.headers['originator']) ||
|
|
275
|
-
(typeof input.headers?.['Originator'] === 'string' && input.headers['Originator']);
|
|
276
|
-
await writeClientSnapshot({
|
|
277
|
-
entryEndpoint: input.entryEndpoint,
|
|
278
|
-
requestId: input.requestId,
|
|
279
|
-
headers: asRecord(input.headers),
|
|
280
|
-
body: input.body,
|
|
281
|
-
metadata: {
|
|
282
|
-
...initialMetadata,
|
|
283
|
-
clientRequestId,
|
|
284
|
-
userAgent: headerUa,
|
|
285
|
-
clientOriginator: headerOriginator
|
|
286
|
-
}
|
|
287
|
-
});
|
|
288
|
-
}
|
|
289
|
-
catch {
|
|
290
|
-
/* snapshot failure should not block request path */
|
|
291
|
-
}
|
|
45
|
+
await writeInboundClientSnapshot({ input, initialMetadata, clientRequestId });
|
|
292
46
|
const pipelineLabel = 'hub';
|
|
293
47
|
let aggregatedUsage;
|
|
294
48
|
const excludedProviderKeys = new Set();
|
|
295
49
|
let maxAttempts = resolveMaxProviderAttempts();
|
|
296
|
-
const originalRequestSnapshot =
|
|
50
|
+
const originalRequestSnapshot = cloneRequestPayload(input.body);
|
|
297
51
|
let attempt = 0;
|
|
298
52
|
let lastError;
|
|
299
53
|
let initialRoutePool = null;
|
|
@@ -301,7 +55,7 @@ export class HubRequestExecutor {
|
|
|
301
55
|
while (attempt < maxAttempts) {
|
|
302
56
|
attempt += 1;
|
|
303
57
|
if (originalRequestSnapshot && typeof originalRequestSnapshot === 'object') {
|
|
304
|
-
const cloned =
|
|
58
|
+
const cloned = cloneRequestPayload(originalRequestSnapshot) ??
|
|
305
59
|
{ ...originalRequestSnapshot };
|
|
306
60
|
input.body = cloned;
|
|
307
61
|
}
|
|
@@ -322,17 +76,7 @@ export class HubRequestExecutor {
|
|
|
322
76
|
pipelineResult = await runHubPipeline(hubPipeline, input, metadataForAttempt);
|
|
323
77
|
}
|
|
324
78
|
catch (pipelineError) {
|
|
325
|
-
|
|
326
|
-
? String(pipelineError.code).trim()
|
|
327
|
-
: '';
|
|
328
|
-
const pipelineErrorMessage = pipelineError instanceof Error
|
|
329
|
-
? pipelineError.message
|
|
330
|
-
: String(pipelineError ?? 'Unknown error');
|
|
331
|
-
const isPoolExhaustedError = pipelineErrorCode === 'PROVIDER_NOT_AVAILABLE' ||
|
|
332
|
-
pipelineErrorCode === 'ERR_NO_PROVIDER_TARGET' ||
|
|
333
|
-
/all providers unavailable/i.test(pipelineErrorMessage) ||
|
|
334
|
-
/virtual router did not produce a provider target/i.test(pipelineErrorMessage);
|
|
335
|
-
if (lastError && isPoolExhaustedError) {
|
|
79
|
+
if (lastError && isPoolExhaustedPipelineError(pipelineError)) {
|
|
336
80
|
throw lastError;
|
|
337
81
|
}
|
|
338
82
|
throw pipelineError;
|
|
@@ -360,120 +104,44 @@ export class HubRequestExecutor {
|
|
|
360
104
|
requestId: input.requestId
|
|
361
105
|
});
|
|
362
106
|
}
|
|
363
|
-
// Ensure response-side conversion
|
|
364
|
-
//
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
if (!mergedMetadata.compatibilityProfile && typeof target.compatibilityProfile === 'string' && target.compatibilityProfile.trim()) {
|
|
107
|
+
// Ensure response-side conversion always uses the route-selected target metadata.
|
|
108
|
+
// ServerTool followups may carry stale metadata from the previous hop; response compat
|
|
109
|
+
// must follow the current target/provider, not the inherited request profile.
|
|
110
|
+
mergedMetadata.target = target;
|
|
111
|
+
if (typeof target.compatibilityProfile === 'string' && target.compatibilityProfile.trim()) {
|
|
369
112
|
mergedMetadata.compatibilityProfile = target.compatibilityProfile.trim();
|
|
370
113
|
}
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
const runtimeResolveError = Object.assign(new Error(`Runtime for provider ${target.providerKey} not initialized`), {
|
|
374
|
-
code: 'ERR_RUNTIME_NOT_FOUND',
|
|
375
|
-
requestId: input.requestId,
|
|
376
|
-
retryable: true
|
|
377
|
-
});
|
|
378
|
-
try {
|
|
379
|
-
const { emitProviderError } = await import('../../../providers/core/utils/provider-error-reporter.js');
|
|
380
|
-
emitProviderError({
|
|
381
|
-
error: runtimeResolveError,
|
|
382
|
-
stage: 'provider.runtime.resolve',
|
|
383
|
-
runtime: {
|
|
384
|
-
requestId: input.requestId,
|
|
385
|
-
providerKey: target.providerKey,
|
|
386
|
-
providerId: target.providerKey.split('.')[0],
|
|
387
|
-
providerType: String(target.providerType || 'unknown'),
|
|
388
|
-
providerProtocol: String(target.outboundProfile || ''),
|
|
389
|
-
routeName: pipelineResult.routingDecision?.routeName,
|
|
390
|
-
pipelineId: target.providerKey,
|
|
391
|
-
target
|
|
392
|
-
},
|
|
393
|
-
dependencies: this.deps.getModuleDependencies(),
|
|
394
|
-
recoverable: false,
|
|
395
|
-
affectsHealth: true,
|
|
396
|
-
details: {
|
|
397
|
-
reason: 'runtime_not_initialized',
|
|
398
|
-
providerKey: target.providerKey
|
|
399
|
-
}
|
|
400
|
-
});
|
|
401
|
-
}
|
|
402
|
-
catch {
|
|
403
|
-
// best-effort
|
|
404
|
-
}
|
|
405
|
-
throw Object.assign(new Error(`Runtime for provider ${target.providerKey} not initialized`), {
|
|
406
|
-
code: 'ERR_RUNTIME_NOT_FOUND',
|
|
407
|
-
requestId: input.requestId
|
|
408
|
-
});
|
|
409
|
-
}
|
|
410
|
-
const handle = this.deps.runtimeManager.getHandleByRuntimeKey(runtimeKey);
|
|
411
|
-
if (!handle) {
|
|
412
|
-
const runtimeMissingError = Object.assign(new Error(`Provider runtime ${runtimeKey} not found`), {
|
|
413
|
-
code: 'ERR_PROVIDER_NOT_FOUND',
|
|
414
|
-
requestId: input.requestId,
|
|
415
|
-
retryable: true
|
|
416
|
-
});
|
|
417
|
-
try {
|
|
418
|
-
const { emitProviderError } = await import('../../../providers/core/utils/provider-error-reporter.js');
|
|
419
|
-
emitProviderError({
|
|
420
|
-
error: runtimeMissingError,
|
|
421
|
-
stage: 'provider.runtime.resolve',
|
|
422
|
-
runtime: {
|
|
423
|
-
requestId: input.requestId,
|
|
424
|
-
providerKey: target.providerKey,
|
|
425
|
-
providerId: target.providerKey.split('.')[0],
|
|
426
|
-
providerType: String(target.providerType || 'unknown'),
|
|
427
|
-
providerProtocol: String(target.outboundProfile || ''),
|
|
428
|
-
routeName: pipelineResult.routingDecision?.routeName,
|
|
429
|
-
pipelineId: target.providerKey,
|
|
430
|
-
runtimeKey,
|
|
431
|
-
target
|
|
432
|
-
},
|
|
433
|
-
dependencies: this.deps.getModuleDependencies(),
|
|
434
|
-
recoverable: false,
|
|
435
|
-
affectsHealth: true,
|
|
436
|
-
details: {
|
|
437
|
-
reason: 'runtime_handle_missing',
|
|
438
|
-
providerKey: target.providerKey,
|
|
439
|
-
runtimeKey
|
|
440
|
-
}
|
|
441
|
-
});
|
|
442
|
-
}
|
|
443
|
-
catch {
|
|
444
|
-
// best-effort
|
|
445
|
-
}
|
|
446
|
-
throw Object.assign(new Error(`Provider runtime ${runtimeKey} not found`), {
|
|
447
|
-
code: 'ERR_PROVIDER_NOT_FOUND',
|
|
448
|
-
requestId: input.requestId
|
|
449
|
-
});
|
|
450
|
-
}
|
|
451
|
-
const providerProtocol = target.outboundProfile || handle.providerProtocol;
|
|
452
|
-
const metadataModel = mergedMetadata?.target && typeof mergedMetadata.target === 'object'
|
|
453
|
-
? mergedMetadata.target.clientModelId
|
|
454
|
-
: undefined;
|
|
455
|
-
const rawModel = this.extractProviderModel(providerPayload) ||
|
|
456
|
-
(typeof metadataModel === 'string' ? metadataModel : undefined);
|
|
457
|
-
const providerAlias = typeof target.providerKey === 'string' && target.providerKey.includes('.')
|
|
458
|
-
? target.providerKey.split('.').slice(0, 2).join('.')
|
|
459
|
-
: target.providerKey;
|
|
460
|
-
const providerIdToken = providerAlias || handle.providerId || runtimeKey;
|
|
461
|
-
if (!providerIdToken) {
|
|
462
|
-
throw Object.assign(new Error('Provider identifier missing for request'), {
|
|
463
|
-
code: 'ERR_PROVIDER_ID_MISSING',
|
|
464
|
-
requestId: providerRequestId
|
|
465
|
-
});
|
|
114
|
+
else if (Object.prototype.hasOwnProperty.call(mergedMetadata, 'compatibilityProfile')) {
|
|
115
|
+
delete mergedMetadata.compatibilityProfile;
|
|
466
116
|
}
|
|
467
|
-
const
|
|
117
|
+
const { runtimeKey, handle } = await resolveProviderRuntimeOrThrow({
|
|
118
|
+
requestId: input.requestId,
|
|
119
|
+
target: {
|
|
120
|
+
providerKey: target.providerKey,
|
|
121
|
+
outboundProfile: String(target.outboundProfile || ''),
|
|
122
|
+
providerType: String(target.providerType || '')
|
|
123
|
+
},
|
|
124
|
+
routeName: pipelineResult.routingDecision?.routeName,
|
|
125
|
+
runtimeKeyHint: target.runtimeKey,
|
|
126
|
+
runtimeManager: this.deps.runtimeManager,
|
|
127
|
+
dependencies: this.deps.getModuleDependencies()
|
|
128
|
+
});
|
|
129
|
+
const providerContext = resolveProviderRequestContext({
|
|
130
|
+
providerRequestId,
|
|
468
131
|
entryEndpoint: input.entryEndpoint,
|
|
469
|
-
|
|
470
|
-
|
|
132
|
+
target: {
|
|
133
|
+
providerKey: target.providerKey,
|
|
134
|
+
outboundProfile: target.outboundProfile
|
|
135
|
+
},
|
|
136
|
+
handle,
|
|
137
|
+
runtimeKey,
|
|
138
|
+
providerPayload,
|
|
139
|
+
mergedMetadata
|
|
471
140
|
});
|
|
472
|
-
if (
|
|
473
|
-
input.requestId =
|
|
141
|
+
if (providerContext.requestId !== input.requestId) {
|
|
142
|
+
input.requestId = providerContext.requestId;
|
|
474
143
|
}
|
|
475
|
-
const providerModel =
|
|
476
|
-
const providerLabel = this.buildProviderLabel(target.providerKey, providerModel);
|
|
144
|
+
const { providerProtocol, providerModel, providerLabel } = providerContext;
|
|
477
145
|
if (clientHeadersForAttempt) {
|
|
478
146
|
ensureClientHeadersOnPayload(providerPayload, clientHeadersForAttempt);
|
|
479
147
|
}
|
|
@@ -518,7 +186,7 @@ export class HubRequestExecutor {
|
|
|
518
186
|
});
|
|
519
187
|
try {
|
|
520
188
|
const providerResponse = await handle.instance.processIncoming(providerPayload);
|
|
521
|
-
const responseStatus =
|
|
189
|
+
const responseStatus = extractResponseStatus(providerResponse);
|
|
522
190
|
this.logStage('provider.send.completed', input.requestId, {
|
|
523
191
|
providerKey: target.providerKey,
|
|
524
192
|
status: responseStatus,
|
|
@@ -529,19 +197,14 @@ export class HubRequestExecutor {
|
|
|
529
197
|
attempt
|
|
530
198
|
});
|
|
531
199
|
const wantsStreamBase = Boolean(input.metadata?.inboundStream ?? input.metadata?.stream);
|
|
532
|
-
const normalized =
|
|
533
|
-
const
|
|
534
|
-
const pipelineStandardized = pipelineResult.standardizedRequest;
|
|
535
|
-
const requestSemantics = pipelineProcessed && typeof pipelineProcessed === 'object' && typeof pipelineProcessed.semantics === 'object'
|
|
536
|
-
? pipelineProcessed.semantics
|
|
537
|
-
: pipelineStandardized && typeof pipelineStandardized === 'object' && typeof pipelineStandardized.semantics === 'object'
|
|
538
|
-
? pipelineStandardized.semantics
|
|
539
|
-
: undefined;
|
|
200
|
+
const normalized = normalizeProviderResponse(providerResponse);
|
|
201
|
+
const requestSemantics = resolveRequestSemantics(pipelineResult.processedRequest, pipelineResult.standardizedRequest);
|
|
540
202
|
const converted = await this.convertProviderResponseIfNeeded({
|
|
541
203
|
entryEndpoint: input.entryEndpoint,
|
|
542
204
|
providerProtocol,
|
|
543
205
|
providerType: handle.providerType,
|
|
544
206
|
requestId: input.requestId,
|
|
207
|
+
serverToolsEnabled: isServerToolEnabled(),
|
|
545
208
|
wantsStream: wantsStreamBase,
|
|
546
209
|
originalRequest: originalRequestSnapshot,
|
|
547
210
|
requestSemantics,
|
|
@@ -602,8 +265,8 @@ export class HubRequestExecutor {
|
|
|
602
265
|
}
|
|
603
266
|
throw errorToThrow;
|
|
604
267
|
}
|
|
605
|
-
const usage =
|
|
606
|
-
aggregatedUsage =
|
|
268
|
+
const usage = extractUsageFromResult(converted, mergedMetadata);
|
|
269
|
+
aggregatedUsage = mergeUsageMetrics(aggregatedUsage, usage);
|
|
607
270
|
if (converted.body && typeof converted.body === 'object') {
|
|
608
271
|
const body = converted.body;
|
|
609
272
|
if (!('__sse_responses' in body)) {
|
|
@@ -611,7 +274,7 @@ export class HubRequestExecutor {
|
|
|
611
274
|
}
|
|
612
275
|
}
|
|
613
276
|
recordAttempt({ usage: aggregatedUsage, error: false });
|
|
614
|
-
|
|
277
|
+
logUsageSummary(input.requestId, {
|
|
615
278
|
providerKey: target.providerKey,
|
|
616
279
|
model: providerModel,
|
|
617
280
|
usage: aggregatedUsage,
|
|
@@ -620,9 +283,10 @@ export class HubRequestExecutor {
|
|
|
620
283
|
return converted;
|
|
621
284
|
}
|
|
622
285
|
catch (error) {
|
|
286
|
+
const errorMessage = error instanceof Error ? error.message : String(error ?? 'Unknown error');
|
|
623
287
|
this.logStage('provider.send.error', input.requestId, {
|
|
624
288
|
providerKey: target.providerKey,
|
|
625
|
-
message:
|
|
289
|
+
message: errorMessage,
|
|
626
290
|
providerType: handle.providerType,
|
|
627
291
|
providerFamily: handle.providerFamily,
|
|
628
292
|
model: providerModel,
|
|
@@ -641,6 +305,40 @@ export class HubRequestExecutor {
|
|
|
641
305
|
antigravityRetrySignal = null;
|
|
642
306
|
}
|
|
643
307
|
const status = extractStatusCodeFromError(error);
|
|
308
|
+
if (isSseDecodeRateLimitError(error, status)) {
|
|
309
|
+
try {
|
|
310
|
+
const { emitProviderError } = await import('../../../providers/core/utils/provider-error-reporter.js');
|
|
311
|
+
emitProviderError({
|
|
312
|
+
error,
|
|
313
|
+
stage: 'provider.sse_decode',
|
|
314
|
+
runtime: {
|
|
315
|
+
requestId: input.requestId,
|
|
316
|
+
providerKey: target.providerKey,
|
|
317
|
+
providerId: handle.providerId,
|
|
318
|
+
providerType: handle.providerType,
|
|
319
|
+
providerFamily: handle.providerFamily,
|
|
320
|
+
providerProtocol,
|
|
321
|
+
routeName: pipelineResult.routingDecision?.routeName,
|
|
322
|
+
pipelineId: target.providerKey,
|
|
323
|
+
target,
|
|
324
|
+
runtimeKey
|
|
325
|
+
},
|
|
326
|
+
dependencies: this.deps.getModuleDependencies(),
|
|
327
|
+
statusCode: 429,
|
|
328
|
+
recoverable: true,
|
|
329
|
+
affectsHealth: true,
|
|
330
|
+
details: {
|
|
331
|
+
source: 'sse_decode_rate_limit',
|
|
332
|
+
errorCode: typeof error?.code === 'string' ? String(error.code) : undefined,
|
|
333
|
+
upstreamCode: typeof error?.upstreamCode === 'string' ? String(error.upstreamCode) : undefined,
|
|
334
|
+
message: errorMessage
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
}
|
|
338
|
+
catch {
|
|
339
|
+
// best-effort; never block retry/failover path
|
|
340
|
+
}
|
|
341
|
+
}
|
|
644
342
|
const isVerify = status === 403 && isGoogleAccountVerificationRequiredError(error);
|
|
645
343
|
const isReauth = status === 403 && isAntigravityReauthRequired403(error);
|
|
646
344
|
const shouldRetry = attempt < maxAttempts &&
|
|
@@ -701,571 +399,11 @@ export class HubRequestExecutor {
|
|
|
701
399
|
throw error;
|
|
702
400
|
}
|
|
703
401
|
}
|
|
704
|
-
extractResponseStatus(response) {
|
|
705
|
-
if (!response || typeof response !== 'object') {
|
|
706
|
-
return undefined;
|
|
707
|
-
}
|
|
708
|
-
const candidate = response.status;
|
|
709
|
-
return typeof candidate === 'number' ? candidate : undefined;
|
|
710
|
-
}
|
|
711
|
-
normalizeProviderResponse(response) {
|
|
712
|
-
const status = this.extractResponseStatus(response);
|
|
713
|
-
const headers = this.normalizeProviderResponseHeaders(response && typeof response === 'object' ? response.headers : undefined);
|
|
714
|
-
const body = response && typeof response === 'object' && 'data' in response
|
|
715
|
-
? response.data
|
|
716
|
-
: response;
|
|
717
|
-
return { status, headers, body };
|
|
718
|
-
}
|
|
719
|
-
normalizeProviderResponseHeaders(headers) {
|
|
720
|
-
if (!headers || typeof headers !== 'object') {
|
|
721
|
-
return undefined;
|
|
722
|
-
}
|
|
723
|
-
const normalized = {};
|
|
724
|
-
for (const [key, value] of Object.entries(headers)) {
|
|
725
|
-
if (typeof value === 'string') {
|
|
726
|
-
normalized[key.toLowerCase()] = value;
|
|
727
|
-
}
|
|
728
|
-
}
|
|
729
|
-
return Object.keys(normalized).length ? normalized : undefined;
|
|
730
|
-
}
|
|
731
|
-
async convertProviderResponseIfNeeded(options) {
|
|
732
|
-
const body = options.response.body;
|
|
733
|
-
if (body && typeof body === 'object') {
|
|
734
|
-
const wrapperError = this.extractSseWrapperError(body);
|
|
735
|
-
if (wrapperError) {
|
|
736
|
-
const codeSuffix = wrapperError.errorCode ? ` [${wrapperError.errorCode}]` : '';
|
|
737
|
-
const error = new Error(`Upstream SSE error event${codeSuffix}: ${wrapperError.message}`);
|
|
738
|
-
error.code = 'SSE_DECODE_ERROR';
|
|
739
|
-
if (wrapperError.errorCode) {
|
|
740
|
-
error.upstreamCode = wrapperError.errorCode;
|
|
741
|
-
}
|
|
742
|
-
error.retryable = wrapperError.retryable;
|
|
743
|
-
if (wrapperError.retryable) {
|
|
744
|
-
error.status = 503;
|
|
745
|
-
error.statusCode = 503;
|
|
746
|
-
}
|
|
747
|
-
throw error;
|
|
748
|
-
}
|
|
749
|
-
}
|
|
750
|
-
if (options.processMode === 'passthrough' && !options.wantsStream) {
|
|
751
|
-
return options.response;
|
|
752
|
-
}
|
|
753
|
-
const entry = (options.entryEndpoint || '').toLowerCase();
|
|
754
|
-
const needsAnthropicConversion = entry.includes('/v1/messages');
|
|
755
|
-
const needsResponsesConversion = entry.includes('/v1/responses');
|
|
756
|
-
const needsChatConversion = entry.includes('/v1/chat/completions');
|
|
757
|
-
if (!needsAnthropicConversion && !needsResponsesConversion && !needsChatConversion) {
|
|
758
|
-
return options.response;
|
|
759
|
-
}
|
|
760
|
-
if (!body || typeof body !== 'object') {
|
|
761
|
-
return options.response;
|
|
762
|
-
}
|
|
763
|
-
try {
|
|
764
|
-
const metadataBag = asRecord(options.pipelineMetadata);
|
|
765
|
-
const originalModelId = this.extractClientModelId(metadataBag, options.originalRequest);
|
|
766
|
-
const assignedModelId = typeof metadataBag?.assignedModelId === 'string'
|
|
767
|
-
? String(metadataBag.assignedModelId)
|
|
768
|
-
: metadataBag &&
|
|
769
|
-
typeof metadataBag === 'object' &&
|
|
770
|
-
metadataBag.target &&
|
|
771
|
-
typeof metadataBag.target === 'object' &&
|
|
772
|
-
typeof metadataBag.target.modelId === 'string'
|
|
773
|
-
? metadataBag.target.modelId
|
|
774
|
-
: typeof metadataBag?.modelId === 'string'
|
|
775
|
-
? String(metadataBag.modelId)
|
|
776
|
-
: undefined;
|
|
777
|
-
const baseContext = {
|
|
778
|
-
...(metadataBag ?? {})
|
|
779
|
-
};
|
|
780
|
-
if (baseContext.capturedChatRequest === undefined &&
|
|
781
|
-
options.originalRequest &&
|
|
782
|
-
typeof options.originalRequest === 'object' &&
|
|
783
|
-
!Array.isArray(options.originalRequest)) {
|
|
784
|
-
baseContext.capturedChatRequest = options.originalRequest;
|
|
785
|
-
}
|
|
786
|
-
if (typeof metadataBag?.routeName === 'string') {
|
|
787
|
-
baseContext.routeId = metadataBag.routeName;
|
|
788
|
-
}
|
|
789
|
-
baseContext.requestId = options.requestId;
|
|
790
|
-
baseContext.entryEndpoint = options.entryEndpoint || entry;
|
|
791
|
-
baseContext.providerProtocol = options.providerProtocol;
|
|
792
|
-
baseContext.originalModelId = originalModelId;
|
|
793
|
-
if (assignedModelId && assignedModelId.trim()) {
|
|
794
|
-
baseContext.modelId = assignedModelId.trim();
|
|
795
|
-
}
|
|
796
|
-
const adapterContext = baseContext;
|
|
797
|
-
const compatProfile = typeof metadataBag?.compatibilityProfile === 'string'
|
|
798
|
-
? String(metadataBag.compatibilityProfile)
|
|
799
|
-
: metadataBag &&
|
|
800
|
-
typeof metadataBag === 'object' &&
|
|
801
|
-
metadataBag.target &&
|
|
802
|
-
typeof metadataBag.target === 'object' &&
|
|
803
|
-
typeof metadataBag.target.compatibilityProfile === 'string'
|
|
804
|
-
? metadataBag.target.compatibilityProfile
|
|
805
|
-
: undefined;
|
|
806
|
-
if (compatProfile && compatProfile.trim()) {
|
|
807
|
-
adapterContext.compatibilityProfile = compatProfile.trim();
|
|
808
|
-
}
|
|
809
|
-
const stageRecorder = await bridgeCreateSnapshotRecorder(adapterContext, typeof adapterContext.entryEndpoint === 'string'
|
|
810
|
-
? adapterContext.entryEndpoint
|
|
811
|
-
: options.entryEndpoint || entry);
|
|
812
|
-
const providerInvoker = async (invokeOptions) => {
|
|
813
|
-
// 将 server-side 工具的 routeHint 注入到内部 payload 的 metadata,
|
|
814
|
-
// 以便后续在标准 HubPipeline 中保持路由上下文一致(例如强制 web_search)。
|
|
815
|
-
if (invokeOptions.routeHint) {
|
|
816
|
-
const carrier = invokeOptions.payload;
|
|
817
|
-
const existingMeta = carrier.metadata && typeof carrier.metadata === 'object'
|
|
818
|
-
? carrier.metadata
|
|
819
|
-
: {};
|
|
820
|
-
carrier.metadata = {
|
|
821
|
-
...existingMeta,
|
|
822
|
-
routeHint: existingMeta.routeHint ?? invokeOptions.routeHint
|
|
823
|
-
};
|
|
824
|
-
}
|
|
825
|
-
// Delegate to existing runtimeManager / Provider V2 stack.
|
|
826
|
-
const runtimeKey = this.deps.runtimeManager.resolveRuntimeKey(invokeOptions.providerKey);
|
|
827
|
-
if (!runtimeKey) {
|
|
828
|
-
throw new Error(`Runtime for provider ${invokeOptions.providerKey} not initialized`);
|
|
829
|
-
}
|
|
830
|
-
const handle = this.deps.runtimeManager.getHandleByRuntimeKey(runtimeKey);
|
|
831
|
-
if (!handle) {
|
|
832
|
-
throw new Error(`Provider runtime ${runtimeKey} not found`);
|
|
833
|
-
}
|
|
834
|
-
const providerResponse = await handle.instance.processIncoming(invokeOptions.payload);
|
|
835
|
-
const normalized = this.normalizeProviderResponse(providerResponse);
|
|
836
|
-
const bodyPayload = normalized.body && typeof normalized.body === 'object'
|
|
837
|
-
? normalized.body
|
|
838
|
-
: normalized;
|
|
839
|
-
return { providerResponse: bodyPayload };
|
|
840
|
-
};
|
|
841
|
-
const reenterPipeline = async (reenterOpts) => {
|
|
842
|
-
const nestedEntry = reenterOpts.entryEndpoint || options.entryEndpoint || entry;
|
|
843
|
-
const nestedExtra = asRecord(reenterOpts.metadata) ?? {};
|
|
844
|
-
// 基于首次 HubPipeline metadata + 调用方注入的 metadata 构建新的请求 metadata。
|
|
845
|
-
// 不在 Host 层编码 servertool/web_search 等语义,由 llmswitch-core 负责。
|
|
846
|
-
const nestedMetadata = {
|
|
847
|
-
...(metadataBag ?? {}),
|
|
848
|
-
...nestedExtra,
|
|
849
|
-
entryEndpoint: nestedEntry,
|
|
850
|
-
direction: 'request',
|
|
851
|
-
stage: 'inbound'
|
|
852
|
-
};
|
|
853
|
-
// E1: merge internal runtime metadata carrier (`__rt`) instead of clobbering it.
|
|
854
|
-
// ServerTool followup metadata always adds fields under __rt, while the base pipeline
|
|
855
|
-
// metadata may already contain runtime configs (webSearch/clock/etc).
|
|
856
|
-
try {
|
|
857
|
-
const baseRt = asRecord(metadataBag?.__rt) ?? {};
|
|
858
|
-
const extraRt = asRecord(nestedExtra?.__rt) ?? {};
|
|
859
|
-
if (Object.keys(baseRt).length || Object.keys(extraRt).length) {
|
|
860
|
-
nestedMetadata.__rt = { ...baseRt, ...extraRt };
|
|
861
|
-
}
|
|
862
|
-
}
|
|
863
|
-
catch {
|
|
864
|
-
// best-effort
|
|
865
|
-
}
|
|
866
|
-
// servertool followup 是内部二跳请求:不应继承客户端 headers 偏好(尤其是 Accept),
|
|
867
|
-
// 否则会导致上游返回非 SSE 响应而被当作 SSE 解析,出现“空回复”。
|
|
868
|
-
if (asRecord(nestedMetadata.__rt)?.serverToolFollowup === true) {
|
|
869
|
-
delete nestedMetadata.clientHeaders;
|
|
870
|
-
delete nestedMetadata.clientRequestId;
|
|
871
|
-
}
|
|
872
|
-
bindClockConversationSession(nestedMetadata);
|
|
873
|
-
const nestedInput = {
|
|
874
|
-
entryEndpoint: nestedEntry,
|
|
875
|
-
method: 'POST',
|
|
876
|
-
requestId: reenterOpts.requestId,
|
|
877
|
-
headers: {},
|
|
878
|
-
query: {},
|
|
879
|
-
body: reenterOpts.body,
|
|
880
|
-
metadata: nestedMetadata
|
|
881
|
-
};
|
|
882
|
-
try {
|
|
883
|
-
const requestBody = reenterOpts.body;
|
|
884
|
-
const messages = Array.isArray(requestBody.messages) ? requestBody.messages : [];
|
|
885
|
-
const lastUser = [...messages]
|
|
886
|
-
.reverse()
|
|
887
|
-
.find((entry) => entry && typeof entry === 'object' && entry.role === 'user');
|
|
888
|
-
const text = typeof lastUser?.content === 'string' ? String(lastUser.content) : '';
|
|
889
|
-
if (text.includes('<**clock:{') && text.includes('}**>')) {
|
|
890
|
-
await injectClockClientPrompt({
|
|
891
|
-
tmuxSessionId: typeof nestedMetadata.tmuxSessionId === 'string' ? nestedMetadata.tmuxSessionId : undefined,
|
|
892
|
-
sessionId: typeof nestedMetadata.sessionId === 'string' ? nestedMetadata.sessionId : undefined,
|
|
893
|
-
text,
|
|
894
|
-
requestId: reenterOpts.requestId,
|
|
895
|
-
source: 'servertool.reenter'
|
|
896
|
-
});
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
catch {
|
|
900
|
-
// best-effort only
|
|
901
|
-
}
|
|
902
|
-
const nestedResult = await this.execute(nestedInput);
|
|
903
|
-
const nestedBody = nestedResult.body && typeof nestedResult.body === 'object'
|
|
904
|
-
? nestedResult.body
|
|
905
|
-
: undefined;
|
|
906
|
-
return { body: nestedBody };
|
|
907
|
-
};
|
|
908
|
-
const converted = await bridgeConvertProviderResponse({
|
|
909
|
-
providerProtocol: options.providerProtocol,
|
|
910
|
-
providerResponse: body,
|
|
911
|
-
context: adapterContext,
|
|
912
|
-
entryEndpoint: options.entryEndpoint || entry,
|
|
913
|
-
wantsStream: options.wantsStream,
|
|
914
|
-
requestSemantics: options.requestSemantics,
|
|
915
|
-
providerInvoker,
|
|
916
|
-
stageRecorder,
|
|
917
|
-
reenterPipeline
|
|
918
|
-
});
|
|
919
|
-
if (converted.__sse_responses) {
|
|
920
|
-
return {
|
|
921
|
-
...options.response,
|
|
922
|
-
body: { __sse_responses: converted.__sse_responses }
|
|
923
|
-
};
|
|
924
|
-
}
|
|
925
|
-
return {
|
|
926
|
-
...options.response,
|
|
927
|
-
body: converted.body ?? body
|
|
928
|
-
};
|
|
929
|
-
}
|
|
930
|
-
catch (error) {
|
|
931
|
-
const err = error;
|
|
932
|
-
const message = err instanceof Error ? err.message : String(err ?? 'Unknown error');
|
|
933
|
-
// 对于 SSE 解码失败(含上游终止),直接抛出错误并透传到 HTTP 层。
|
|
934
|
-
// 否则回退到原始 payload 会让客户端挂起,无法感知失败。
|
|
935
|
-
const errRecord = err;
|
|
936
|
-
const errCode = typeof errRecord.code === 'string' ? errRecord.code : undefined;
|
|
937
|
-
const errName = typeof errRecord.name === 'string' ? errRecord.name : undefined;
|
|
938
|
-
const isSseDecodeError = errCode === 'SSE_DECODE_ERROR' ||
|
|
939
|
-
(errName === 'ProviderProtocolError' && message.toLowerCase().includes('sse'));
|
|
940
|
-
const isServerToolFollowupError = errCode === 'SERVERTOOL_FOLLOWUP_FAILED' ||
|
|
941
|
-
errCode === 'SERVERTOOL_EMPTY_FOLLOWUP' ||
|
|
942
|
-
(typeof errCode === 'string' && errCode.startsWith('SERVERTOOL_'));
|
|
943
|
-
if (isSseDecodeError || isServerToolFollowupError) {
|
|
944
|
-
console.error('[RequestExecutor] Fatal conversion error, bubbling as HTTP error', error);
|
|
945
|
-
throw error;
|
|
946
|
-
}
|
|
947
|
-
console.error('[RequestExecutor] Failed to convert provider response via llmswitch-core', error);
|
|
948
|
-
return options.response;
|
|
949
|
-
}
|
|
950
|
-
}
|
|
951
|
-
extractSseWrapperError(payload) {
|
|
952
|
-
return this.findSseWrapperError(payload, 2);
|
|
953
|
-
}
|
|
954
|
-
findSseWrapperError(record, depth) {
|
|
955
|
-
if (!record || typeof record !== 'object' || depth < 0) {
|
|
956
|
-
return undefined;
|
|
957
|
-
}
|
|
958
|
-
if (record.mode === 'sse') {
|
|
959
|
-
const normalized = this.normalizeSseWrapperErrorValue(record.error, depth);
|
|
960
|
-
if (normalized) {
|
|
961
|
-
return normalized;
|
|
962
|
-
}
|
|
963
|
-
}
|
|
964
|
-
const nestedKeys = ['body', 'data', 'payload', 'response'];
|
|
965
|
-
for (const key of nestedKeys) {
|
|
966
|
-
const nested = record[key];
|
|
967
|
-
if (!nested || typeof nested !== 'object' || Array.isArray(nested)) {
|
|
968
|
-
continue;
|
|
969
|
-
}
|
|
970
|
-
const found = this.findSseWrapperError(nested, depth - 1);
|
|
971
|
-
if (found) {
|
|
972
|
-
return found;
|
|
973
|
-
}
|
|
974
|
-
}
|
|
975
|
-
return undefined;
|
|
976
|
-
}
|
|
977
|
-
normalizeSseWrapperErrorValue(value, depth) {
|
|
978
|
-
if (value === undefined || value === null || depth < 0) {
|
|
979
|
-
return undefined;
|
|
980
|
-
}
|
|
981
|
-
if (typeof value === 'string') {
|
|
982
|
-
const trimmed = value.trim();
|
|
983
|
-
if (!trimmed) {
|
|
984
|
-
return undefined;
|
|
985
|
-
}
|
|
986
|
-
if (depth > 0 && (trimmed.startsWith('{') || trimmed.startsWith('['))) {
|
|
987
|
-
try {
|
|
988
|
-
const parsed = JSON.parse(trimmed);
|
|
989
|
-
const parsedInfo = this.normalizeSseWrapperErrorValue(parsed, depth - 1);
|
|
990
|
-
if (parsedInfo) {
|
|
991
|
-
return parsedInfo;
|
|
992
|
-
}
|
|
993
|
-
}
|
|
994
|
-
catch {
|
|
995
|
-
// fallback to raw string
|
|
996
|
-
}
|
|
997
|
-
}
|
|
998
|
-
return {
|
|
999
|
-
message: trimmed,
|
|
1000
|
-
retryable: isRetryableSseWrapperError(trimmed)
|
|
1001
|
-
};
|
|
1002
|
-
}
|
|
1003
|
-
if (typeof value !== 'object' || Array.isArray(value)) {
|
|
1004
|
-
return undefined;
|
|
1005
|
-
}
|
|
1006
|
-
const record = value;
|
|
1007
|
-
const directMessage = firstNonEmptyString([
|
|
1008
|
-
record.message,
|
|
1009
|
-
record.error_message,
|
|
1010
|
-
record.errorMessage
|
|
1011
|
-
]);
|
|
1012
|
-
const directCode = firstNonEmptyString([
|
|
1013
|
-
record.code,
|
|
1014
|
-
record.error_code,
|
|
1015
|
-
record.errorCode,
|
|
1016
|
-
record.type
|
|
1017
|
-
]);
|
|
1018
|
-
const directStatus = firstFiniteNumber([
|
|
1019
|
-
record.status,
|
|
1020
|
-
record.statusCode,
|
|
1021
|
-
record.status_code,
|
|
1022
|
-
record.http_status
|
|
1023
|
-
]);
|
|
1024
|
-
if (depth > 0) {
|
|
1025
|
-
for (const key of ['error', 'data', 'payload', 'details', 'body', 'response']) {
|
|
1026
|
-
const nestedInfo = this.normalizeSseWrapperErrorValue(record[key], depth - 1);
|
|
1027
|
-
if (nestedInfo) {
|
|
1028
|
-
const mergedCode = nestedInfo.errorCode ?? directCode;
|
|
1029
|
-
const retryable = nestedInfo.retryable || isRetryableSseWrapperError(nestedInfo.message, mergedCode, directStatus);
|
|
1030
|
-
return {
|
|
1031
|
-
message: nestedInfo.message,
|
|
1032
|
-
...(mergedCode ? { errorCode: mergedCode } : {}),
|
|
1033
|
-
retryable
|
|
1034
|
-
};
|
|
1035
|
-
}
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
if (directMessage) {
|
|
1039
|
-
return {
|
|
1040
|
-
message: directMessage,
|
|
1041
|
-
...(directCode ? { errorCode: directCode } : {}),
|
|
1042
|
-
retryable: isRetryableSseWrapperError(directMessage, directCode, directStatus)
|
|
1043
|
-
};
|
|
1044
|
-
}
|
|
1045
|
-
try {
|
|
1046
|
-
const serialized = JSON.stringify(record);
|
|
1047
|
-
if (serialized && serialized !== '{}') {
|
|
1048
|
-
return {
|
|
1049
|
-
message: serialized,
|
|
1050
|
-
...(directCode ? { errorCode: directCode } : {}),
|
|
1051
|
-
retryable: isRetryableSseWrapperError(serialized, directCode, directStatus)
|
|
1052
|
-
};
|
|
1053
|
-
}
|
|
1054
|
-
}
|
|
1055
|
-
catch {
|
|
1056
|
-
// ignore stringify failures
|
|
1057
|
-
}
|
|
1058
|
-
return undefined;
|
|
1059
|
-
}
|
|
1060
|
-
extractClientModelId(metadata, originalRequest) {
|
|
1061
|
-
const candidates = [
|
|
1062
|
-
metadata.clientModelId,
|
|
1063
|
-
metadata.originalModelId,
|
|
1064
|
-
(metadata.target && typeof metadata.target === 'object'
|
|
1065
|
-
? metadata.target.clientModelId
|
|
1066
|
-
: undefined),
|
|
1067
|
-
originalRequest && typeof originalRequest === 'object'
|
|
1068
|
-
? originalRequest.model
|
|
1069
|
-
: undefined,
|
|
1070
|
-
originalRequest && typeof originalRequest === 'object'
|
|
1071
|
-
? originalRequest.originalModelId
|
|
1072
|
-
: undefined
|
|
1073
|
-
];
|
|
1074
|
-
for (const candidate of candidates) {
|
|
1075
|
-
if (typeof candidate === 'string' && candidate.trim()) {
|
|
1076
|
-
return candidate.trim();
|
|
1077
|
-
}
|
|
1078
|
-
}
|
|
1079
|
-
return undefined;
|
|
1080
|
-
}
|
|
1081
|
-
cloneRequestPayload(payload) {
|
|
1082
|
-
if (!payload || typeof payload !== 'object') {
|
|
1083
|
-
return undefined;
|
|
1084
|
-
}
|
|
1085
|
-
try {
|
|
1086
|
-
return JSON.parse(JSON.stringify(payload));
|
|
1087
|
-
}
|
|
1088
|
-
catch {
|
|
1089
|
-
return undefined;
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
extractProviderModel(payload) {
|
|
1093
|
-
if (!payload) {
|
|
1094
|
-
return undefined;
|
|
1095
|
-
}
|
|
1096
|
-
const source = payload.data && typeof payload.data === 'object'
|
|
1097
|
-
? payload.data
|
|
1098
|
-
: payload;
|
|
1099
|
-
const raw = source.model;
|
|
1100
|
-
if (typeof raw === 'string' && raw.trim()) {
|
|
1101
|
-
return raw.trim();
|
|
1102
|
-
}
|
|
1103
|
-
return undefined;
|
|
1104
|
-
}
|
|
1105
|
-
buildProviderLabel(providerKey, model) {
|
|
1106
|
-
const key = typeof providerKey === 'string' && providerKey.trim() ? providerKey.trim() : undefined;
|
|
1107
|
-
const modelId = typeof model === 'string' && model.trim() ? model.trim() : undefined;
|
|
1108
|
-
if (!key && !modelId) {
|
|
1109
|
-
return undefined;
|
|
1110
|
-
}
|
|
1111
|
-
if (key && modelId) {
|
|
1112
|
-
return `${key}.${modelId}`;
|
|
1113
|
-
}
|
|
1114
|
-
return key || modelId;
|
|
1115
|
-
}
|
|
1116
402
|
logStage(stage, requestId, details) {
|
|
1117
403
|
this.deps.logStage(stage, requestId, details);
|
|
1118
404
|
}
|
|
1119
|
-
|
|
1120
|
-
|
|
1121
|
-
return;
|
|
1122
|
-
}
|
|
1123
|
-
const providerLabel = this.buildProviderLabel(info.providerKey, info.model) ?? '-';
|
|
1124
|
-
const prompt = info.usage?.prompt_tokens;
|
|
1125
|
-
const completion = info.usage?.completion_tokens;
|
|
1126
|
-
const total = info.usage?.total_tokens ?? (prompt !== undefined && completion !== undefined ? prompt + completion : undefined);
|
|
1127
|
-
const usageText = `prompt=${prompt ?? 'n/a'} completion=${completion ?? 'n/a'} total=${total ?? 'n/a'}`;
|
|
1128
|
-
const latency = info.latencyMs.toFixed(1);
|
|
1129
|
-
console.log(`[usage] request ${requestId} provider=${providerLabel} latency=${latency}ms (${usageText})`);
|
|
1130
|
-
}
|
|
1131
|
-
extractUsageFromResult(result, metadata) {
|
|
1132
|
-
const estimatedInput = this.extractEstimatedInputTokens(metadata);
|
|
1133
|
-
const candidates = [];
|
|
1134
|
-
if (metadata && typeof metadata === 'object') {
|
|
1135
|
-
const bag = metadata;
|
|
1136
|
-
if (bag.usage) {
|
|
1137
|
-
candidates.push(bag.usage);
|
|
1138
|
-
}
|
|
1139
|
-
}
|
|
1140
|
-
if (result.body && typeof result.body === 'object') {
|
|
1141
|
-
const body = result.body;
|
|
1142
|
-
if (body.usage) {
|
|
1143
|
-
candidates.push(body.usage);
|
|
1144
|
-
}
|
|
1145
|
-
if (body.response && typeof body.response === 'object') {
|
|
1146
|
-
const responseNode = body.response;
|
|
1147
|
-
if (responseNode.usage) {
|
|
1148
|
-
candidates.push(responseNode.usage);
|
|
1149
|
-
}
|
|
1150
|
-
}
|
|
1151
|
-
}
|
|
1152
|
-
for (const candidate of candidates) {
|
|
1153
|
-
const normalized = this.normalizeUsage(candidate);
|
|
1154
|
-
if (normalized) {
|
|
1155
|
-
const reconciled = this.reconcileUsageWithEstimate(normalized, estimatedInput, candidate);
|
|
1156
|
-
return reconciled;
|
|
1157
|
-
}
|
|
1158
|
-
}
|
|
1159
|
-
return undefined;
|
|
1160
|
-
}
|
|
1161
|
-
normalizeUsage(value) {
|
|
1162
|
-
if (!value || typeof value !== 'object') {
|
|
1163
|
-
return undefined;
|
|
1164
|
-
}
|
|
1165
|
-
const record = value;
|
|
1166
|
-
const basePrompt = typeof record.prompt_tokens === 'number'
|
|
1167
|
-
? record.prompt_tokens
|
|
1168
|
-
: typeof record.input_tokens === 'number'
|
|
1169
|
-
? record.input_tokens
|
|
1170
|
-
: undefined;
|
|
1171
|
-
let cacheRead = typeof record.cache_read_input_tokens === 'number' ? record.cache_read_input_tokens : undefined;
|
|
1172
|
-
if (cacheRead === undefined && record.input_tokens_details && typeof record.input_tokens_details === 'object') {
|
|
1173
|
-
const details = record.input_tokens_details;
|
|
1174
|
-
if (typeof details.cached_tokens === 'number') {
|
|
1175
|
-
cacheRead = details.cached_tokens;
|
|
1176
|
-
}
|
|
1177
|
-
}
|
|
1178
|
-
const prompt = basePrompt !== undefined || cacheRead !== undefined
|
|
1179
|
-
? (basePrompt ?? 0) + (cacheRead ?? 0)
|
|
1180
|
-
: undefined;
|
|
1181
|
-
const completion = typeof record.completion_tokens === 'number'
|
|
1182
|
-
? record.completion_tokens
|
|
1183
|
-
: typeof record.output_tokens === 'number'
|
|
1184
|
-
? record.output_tokens
|
|
1185
|
-
: undefined;
|
|
1186
|
-
let total = typeof record.total_tokens === 'number'
|
|
1187
|
-
? record.total_tokens
|
|
1188
|
-
: undefined;
|
|
1189
|
-
if (total === undefined && prompt !== undefined && completion !== undefined) {
|
|
1190
|
-
total = prompt + completion;
|
|
1191
|
-
}
|
|
1192
|
-
if (prompt === undefined && completion === undefined && total === undefined) {
|
|
1193
|
-
return undefined;
|
|
1194
|
-
}
|
|
1195
|
-
return {
|
|
1196
|
-
prompt_tokens: prompt,
|
|
1197
|
-
completion_tokens: completion,
|
|
1198
|
-
total_tokens: total
|
|
1199
|
-
};
|
|
1200
|
-
}
|
|
1201
|
-
extractEstimatedInputTokens(metadata) {
|
|
1202
|
-
if (!metadata || typeof metadata !== 'object') {
|
|
1203
|
-
return undefined;
|
|
1204
|
-
}
|
|
1205
|
-
const bag = metadata;
|
|
1206
|
-
const raw = bag.estimatedInputTokens ??
|
|
1207
|
-
bag.estimated_tokens ??
|
|
1208
|
-
bag.estimatedTokens;
|
|
1209
|
-
const value = typeof raw === 'number' ? raw : Number(raw);
|
|
1210
|
-
if (!Number.isFinite(value) || value <= 0) {
|
|
1211
|
-
return undefined;
|
|
1212
|
-
}
|
|
1213
|
-
return value;
|
|
1214
|
-
}
|
|
1215
|
-
reconcileUsageWithEstimate(usage, estimatedInput, candidate) {
|
|
1216
|
-
if (!estimatedInput || !Number.isFinite(estimatedInput) || estimatedInput <= 0) {
|
|
1217
|
-
return usage;
|
|
1218
|
-
}
|
|
1219
|
-
const upstreamPrompt = usage.prompt_tokens ?? usage.total_tokens ?? undefined;
|
|
1220
|
-
const completion = usage.completion_tokens ?? 0;
|
|
1221
|
-
// 若上游缺失 prompt/total,直接使用我们估算的输入 token。
|
|
1222
|
-
if (upstreamPrompt === undefined || upstreamPrompt <= 0) {
|
|
1223
|
-
const total = estimatedInput + completion;
|
|
1224
|
-
this.patchUsageCandidate(candidate, estimatedInput, completion, total);
|
|
1225
|
-
return {
|
|
1226
|
-
prompt_tokens: estimatedInput,
|
|
1227
|
-
completion_tokens: completion,
|
|
1228
|
-
total_tokens: total
|
|
1229
|
-
};
|
|
1230
|
-
}
|
|
1231
|
-
const ratio = upstreamPrompt > 0 ? upstreamPrompt / estimatedInput : 1;
|
|
1232
|
-
// 差异过大(数量级不一致)时,优先采用本地估算值。
|
|
1233
|
-
if (ratio > 5 || ratio < 0.2) {
|
|
1234
|
-
const total = estimatedInput + completion;
|
|
1235
|
-
this.patchUsageCandidate(candidate, estimatedInput, completion, total);
|
|
1236
|
-
return {
|
|
1237
|
-
prompt_tokens: estimatedInput,
|
|
1238
|
-
completion_tokens: completion,
|
|
1239
|
-
total_tokens: total
|
|
1240
|
-
};
|
|
1241
|
-
}
|
|
1242
|
-
return usage;
|
|
1243
|
-
}
|
|
1244
|
-
patchUsageCandidate(candidate, prompt, completion, total) {
|
|
1245
|
-
if (!candidate || typeof candidate !== 'object') {
|
|
1246
|
-
return;
|
|
1247
|
-
}
|
|
1248
|
-
const record = candidate;
|
|
1249
|
-
record.prompt_tokens = prompt;
|
|
1250
|
-
record.input_tokens = prompt;
|
|
1251
|
-
record.completion_tokens = completion;
|
|
1252
|
-
record.output_tokens = completion;
|
|
1253
|
-
record.total_tokens = total;
|
|
1254
|
-
}
|
|
1255
|
-
mergeUsageMetrics(base, delta) {
|
|
1256
|
-
if (!delta) {
|
|
1257
|
-
return base;
|
|
1258
|
-
}
|
|
1259
|
-
if (!base) {
|
|
1260
|
-
return { ...delta };
|
|
1261
|
-
}
|
|
1262
|
-
const merged = {
|
|
1263
|
-
prompt_tokens: (base.prompt_tokens ?? 0) + (delta.prompt_tokens ?? 0),
|
|
1264
|
-
completion_tokens: (base.completion_tokens ?? 0) + (delta.completion_tokens ?? 0)
|
|
1265
|
-
};
|
|
1266
|
-
const total = (base.total_tokens ?? 0) + (delta.total_tokens ?? 0);
|
|
1267
|
-
merged.total_tokens = total || undefined;
|
|
1268
|
-
return merged;
|
|
405
|
+
async convertProviderResponseIfNeeded(options) {
|
|
406
|
+
return convertProviderResponseWithBridge(options, { runtimeManager: this.deps.runtimeManager, executeNested: (nestedInput) => this.execute(nestedInput) });
|
|
1269
407
|
}
|
|
1270
408
|
}
|
|
1271
409
|
export function createRequestExecutor(deps) {
|