@jsonstudio/rcc 0.89.168 → 0.89.524
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 +18 -15
- package/dist/build-info.js +3 -3
- package/dist/build-info.js.map +1 -1
- package/dist/cli.js +94 -0
- package/dist/cli.js.map +1 -1
- package/dist/client/gemini-cli/gemini-cli-protocol-client.js +28 -5
- package/dist/client/gemini-cli/gemini-cli-protocol-client.js.map +1 -1
- package/dist/commands/token-daemon.d.ts +2 -0
- package/dist/commands/token-daemon.js +183 -0
- package/dist/commands/token-daemon.js.map +1 -0
- package/dist/error-handling/quiet-error-handling-center.d.ts +9 -0
- package/dist/error-handling/quiet-error-handling-center.js +141 -0
- package/dist/error-handling/quiet-error-handling-center.js.map +1 -0
- package/dist/error-handling/route-error-hub.js +8 -2
- package/dist/error-handling/route-error-hub.js.map +1 -1
- package/dist/index.js +4 -3
- package/dist/index.js.map +1 -1
- package/dist/modules/llmswitch/bridge.d.ts +1 -1
- package/dist/modules/llmswitch/bridge.js +3 -2
- package/dist/modules/llmswitch/bridge.js.map +1 -1
- package/dist/modules/pipeline/utils/colored-logger.d.ts +2 -0
- package/dist/modules/pipeline/utils/colored-logger.js +22 -3
- package/dist/modules/pipeline/utils/colored-logger.js.map +1 -1
- package/dist/providers/auth/antigravity-userinfo-helper.d.ts +10 -0
- package/dist/providers/auth/antigravity-userinfo-helper.js +140 -0
- package/dist/providers/auth/antigravity-userinfo-helper.js.map +1 -0
- package/dist/providers/auth/gemini-cli-userinfo-helper.js +12 -2
- package/dist/providers/auth/gemini-cli-userinfo-helper.js.map +1 -1
- package/dist/providers/auth/oauth-lifecycle.js +395 -24
- package/dist/providers/auth/oauth-lifecycle.js.map +1 -1
- package/dist/providers/auth/token-scanner/index.d.ts +32 -0
- package/dist/providers/auth/token-scanner/index.js +86 -0
- package/dist/providers/auth/token-scanner/index.js.map +1 -0
- package/dist/providers/auth/tokenfile-auth.d.ts +17 -0
- package/dist/providers/auth/tokenfile-auth.js +27 -5
- package/dist/providers/auth/tokenfile-auth.js.map +1 -1
- package/dist/providers/core/api/provider-types.d.ts +10 -0
- package/dist/providers/core/config/oauth-flows.d.ts +25 -0
- package/dist/providers/core/config/oauth-flows.js +92 -5
- package/dist/providers/core/config/oauth-flows.js.map +1 -1
- package/dist/providers/core/config/provider-oauth-configs.js +93 -2
- package/dist/providers/core/config/provider-oauth-configs.js.map +1 -1
- package/dist/providers/core/config/service-profiles.js +18 -10
- package/dist/providers/core/config/service-profiles.js.map +1 -1
- package/dist/providers/core/runtime/base-provider.d.ts +2 -0
- package/dist/providers/core/runtime/base-provider.js +135 -15
- package/dist/providers/core/runtime/base-provider.js.map +1 -1
- package/dist/providers/core/runtime/gemini-cli-http-provider.d.ts +8 -3
- package/dist/providers/core/runtime/gemini-cli-http-provider.js +332 -67
- package/dist/providers/core/runtime/gemini-cli-http-provider.js.map +1 -1
- package/dist/providers/core/runtime/http-request-executor.d.ts +1 -0
- package/dist/providers/core/runtime/http-request-executor.js +41 -1
- package/dist/providers/core/runtime/http-request-executor.js.map +1 -1
- package/dist/providers/core/runtime/http-transport-provider.d.ts +27 -0
- package/dist/providers/core/runtime/http-transport-provider.js +342 -69
- package/dist/providers/core/runtime/http-transport-provider.js.map +1 -1
- package/dist/providers/core/runtime/provider-error-classifier.d.ts +2 -2
- package/dist/providers/core/runtime/provider-error-classifier.js +14 -4
- package/dist/providers/core/runtime/provider-error-classifier.js.map +1 -1
- package/dist/providers/core/runtime/provider-factory.d.ts +1 -0
- package/dist/providers/core/runtime/provider-factory.js +37 -8
- package/dist/providers/core/runtime/provider-factory.js.map +1 -1
- package/dist/providers/core/runtime/responses-provider.d.ts +3 -3
- package/dist/providers/core/runtime/responses-provider.js +56 -117
- package/dist/providers/core/runtime/responses-provider.js.map +1 -1
- package/dist/providers/core/runtime/vision-debug-utils.d.ts +13 -0
- package/dist/providers/core/runtime/vision-debug-utils.js +114 -0
- package/dist/providers/core/runtime/vision-debug-utils.js.map +1 -0
- package/dist/providers/core/strategies/oauth-auth-code-flow.js +82 -25
- package/dist/providers/core/strategies/oauth-auth-code-flow.js.map +1 -1
- package/dist/providers/core/utils/http-client.d.ts +5 -0
- package/dist/providers/core/utils/http-client.js +31 -4
- package/dist/providers/core/utils/http-client.js.map +1 -1
- package/dist/providers/core/utils/provider-error-reporter.js +8 -2
- package/dist/providers/core/utils/provider-error-reporter.js.map +1 -1
- package/dist/providers/core/utils/snapshot-writer.d.ts +1 -1
- package/dist/providers/core/utils/snapshot-writer.js +5 -1
- package/dist/providers/core/utils/snapshot-writer.js.map +1 -1
- package/dist/providers/profile/provider-profile-loader.js +8 -4
- package/dist/providers/profile/provider-profile-loader.js.map +1 -1
- package/dist/runtime/runtime-flags.d.ts +4 -0
- package/dist/runtime/runtime-flags.js +32 -0
- package/dist/runtime/runtime-flags.js.map +1 -0
- package/dist/server/handlers/handler-utils.js +29 -2
- package/dist/server/handlers/handler-utils.js.map +1 -1
- package/dist/server/handlers/messages-handler.js +27 -26
- package/dist/server/handlers/messages-handler.js.map +1 -1
- package/dist/server/handlers/responses-handler.js +35 -1
- package/dist/server/handlers/responses-handler.js.map +1 -1
- package/dist/server/handlers/sse-dispatcher.js +22 -2
- package/dist/server/handlers/sse-dispatcher.js.map +1 -1
- package/dist/server/runtime/http-server/index.d.ts +10 -0
- package/dist/server/runtime/http-server/index.js +551 -148
- package/dist/server/runtime/http-server/index.js.map +1 -1
- package/dist/server/runtime/http-server/request-executor.d.ts +14 -0
- package/dist/server/runtime/http-server/request-executor.js +638 -149
- package/dist/server/runtime/http-server/request-executor.js.map +1 -1
- package/dist/server/runtime/http-server/routes.d.ts +5 -0
- package/dist/server/runtime/http-server/routes.js +69 -0
- package/dist/server/runtime/http-server/routes.js.map +1 -1
- package/dist/server/runtime/http-server/runtime-manager.js +18 -0
- package/dist/server/runtime/http-server/runtime-manager.js.map +1 -1
- package/dist/server/utils/sse-request-parser.d.ts +1 -0
- package/dist/server/utils/sse-request-parser.js +17 -6
- package/dist/server/utils/sse-request-parser.js.map +1 -1
- package/dist/server/utils/utf8-chunk-buffer.d.ts +43 -0
- package/dist/server/utils/utf8-chunk-buffer.js +132 -0
- package/dist/server/utils/utf8-chunk-buffer.js.map +1 -0
- package/dist/server/utils/warmup-detector.d.ts +7 -0
- package/dist/server/utils/warmup-detector.js +125 -0
- package/dist/server/utils/warmup-detector.js.map +1 -0
- package/dist/server/utils/warmup-storm-tracker.d.ts +9 -0
- package/dist/server/utils/warmup-storm-tracker.js +61 -0
- package/dist/server/utils/warmup-storm-tracker.js.map +1 -0
- package/dist/token-daemon/index.d.ts +7 -0
- package/dist/token-daemon/index.js +242 -0
- package/dist/token-daemon/index.js.map +1 -0
- package/dist/token-daemon/server-utils.d.ts +33 -0
- package/dist/token-daemon/server-utils.js +155 -0
- package/dist/token-daemon/server-utils.js.map +1 -0
- package/dist/token-daemon/token-daemon.d.ts +20 -0
- package/dist/token-daemon/token-daemon.js +144 -0
- package/dist/token-daemon/token-daemon.js.map +1 -0
- package/dist/token-daemon/token-types.d.ts +44 -0
- package/dist/token-daemon/token-types.js +18 -0
- package/dist/token-daemon/token-types.js.map +1 -0
- package/dist/token-daemon/token-utils.d.ts +17 -0
- package/dist/token-daemon/token-utils.js +153 -0
- package/dist/token-daemon/token-utils.js.map +1 -0
- package/dist/tools/semantic-replay.js +7 -6
- package/dist/tools/semantic-replay.js.map +1 -1
- package/dist/utils/debug-utils.js +14 -0
- package/dist/utils/debug-utils.js.map +1 -1
- package/dist/utils/error-handler-registry.d.ts +36 -0
- package/dist/utils/error-handler-registry.js +99 -12
- package/dist/utils/error-handler-registry.js.map +1 -1
- package/dist/utils/error-handling-utils.js +4 -3
- package/dist/utils/error-handling-utils.js.map +1 -1
- package/dist/utils/log-helpers.d.ts +6 -0
- package/dist/utils/log-helpers.js +90 -0
- package/dist/utils/log-helpers.js.map +1 -0
- package/dist/utils/logger.d.ts +8 -0
- package/dist/utils/logger.js +55 -2
- package/dist/utils/logger.js.map +1 -1
- package/dist/utils/snapshot-writer.js +2 -6
- package/dist/utils/snapshot-writer.js.map +1 -1
- package/node_modules/@jsonstudio/llms/README.md +2 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/codecs/gemini-openai-codec.js +152 -6
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/auto-thinking.d.ts +6 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/auto-thinking.js +25 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/field-mapping.d.ts +14 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/field-mapping.js +155 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/gemini-web-search.d.ts +17 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/gemini-web-search.js +68 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-image-content.d.ts +2 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-image-content.js +83 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-tool-extraction.d.ts +2 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-tool-extraction.js +264 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-vision-prompt.d.ts +11 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-vision-prompt.js +177 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-web-search.d.ts +2 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-web-search.js +63 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/qwen-transform.d.ts +3 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/qwen-transform.js +209 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/request-rules.d.ts +24 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/request-rules.js +63 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-blacklist.d.ts +14 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-blacklist.js +85 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-normalize.d.ts +5 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-normalize.js +121 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-validate.d.ts +5 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-validate.js +76 -0
- package/{dist/providers/compat/utils/snapshot-writer.d.ts → node_modules/@jsonstudio/llms/dist/conversion/compat/actions/snapshot.d.ts} +2 -2
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/snapshot.js +21 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/tool-schema.d.ts +6 -0
- package/{dist/providers/compat/glm/utils/tool-schema-helpers.js → node_modules/@jsonstudio/llms/dist/conversion/compat/actions/tool-schema.js} +6 -1
- package/{dist/providers/compat/filters → node_modules/@jsonstudio/llms/dist/conversion/compat/actions}/universal-shape-filter.d.ts +17 -22
- package/{dist/providers/compat/filters → node_modules/@jsonstudio/llms/dist/conversion/compat/actions}/universal-shape-filter.js +46 -99
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-gemini.json +17 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-glm.json +196 -13
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-iflow.json +194 -26
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-lmstudio.json +43 -35
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-qwen.json +20 -16
- package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/responses-c4m.json +42 -42
- package/node_modules/@jsonstudio/llms/dist/conversion/config/sample-config.json +1 -1
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-engine.d.ts +7 -2
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-engine.js +5 -665
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.d.ts +9 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +869 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-types.d.ts +55 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/hub-pipeline.d.ts +2 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/hub-pipeline.js +74 -5
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +2 -2
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/target-utils.js +9 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/process/chat-process.js +213 -1
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/provider-response.d.ts +34 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/provider-response.js +84 -24
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/response-runtime.js +19 -2
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/server-side-tools.d.ts +26 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/server-side-tools.js +383 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/semantic-mappers/gemini-mapper.js +241 -14
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/semantic-mappers/responses-mapper.js +17 -1
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/standardized-bridge.js +14 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/hub/types/standardized.d.ts +1 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-host-policy.d.ts +6 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-host-policy.js +14 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-openai-bridge.js +133 -5
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/anthropic-message-utils.js +98 -3
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/bridge-message-utils.js +137 -10
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-output-builder.js +43 -2
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-reasoning-registry.d.ts +4 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-reasoning-registry.js +62 -1
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-response-utils.js +23 -1
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/snapshot-utils.js +17 -47
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/tool-canonicalizer.d.ts +2 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/tool-filter-pipeline.js +12 -0
- package/node_modules/@jsonstudio/llms/dist/conversion/shared/tool-mapping.js +25 -2
- package/node_modules/@jsonstudio/llms/dist/index.d.ts +1 -0
- package/node_modules/@jsonstudio/llms/dist/index.js +1 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/bootstrap.js +540 -36
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/classifier.js +12 -11
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/context-advisor.d.ts +19 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/context-advisor.js +64 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/engine.d.ts +26 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/engine.js +450 -54
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/features.js +23 -458
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/health-manager.js +2 -7
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/message-utils.d.ts +7 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/message-utils.js +78 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/provider-registry.js +7 -2
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-counter.js +14 -3
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-estimator.d.ts +2 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-estimator.js +16 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-file-scanner.d.ts +15 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-file-scanner.js +56 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/tool-signals.d.ts +13 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/tool-signals.js +403 -0
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/types.d.ts +86 -2
- package/node_modules/@jsonstudio/llms/dist/router/virtual-router/types.js +3 -1
- package/node_modules/@jsonstudio/llms/dist/servertool/engine.d.ts +27 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/engine.js +60 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/flow-types.d.ts +40 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/flow-types.js +1 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/handlers/vision.d.ts +1 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/handlers/vision.js +194 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/handlers/web-search.d.ts +1 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/handlers/web-search.js +638 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/orchestration-types.d.ts +33 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/orchestration-types.js +1 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/registry.d.ts +18 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/registry.js +27 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/server-side-tools.d.ts +8 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/server-side-tools.js +208 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/types.d.ts +88 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/types.js +1 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/vision-tool.d.ts +2 -0
- package/node_modules/@jsonstudio/llms/dist/servertool/vision-tool.js +185 -0
- package/node_modules/@jsonstudio/llms/dist/sse/json-to-sse/event-generators/responses.js +15 -3
- package/node_modules/@jsonstudio/llms/dist/sse/sse-to-json/builders/response-builder.js +6 -3
- package/node_modules/@jsonstudio/llms/dist/sse/sse-to-json/gemini-sse-to-json-converter.js +27 -1
- package/node_modules/@jsonstudio/llms/dist/sse/types/gemini-types.d.ts +20 -1
- package/node_modules/@jsonstudio/llms/dist/sse/types/responses-types.js +1 -1
- package/node_modules/@jsonstudio/llms/dist/telemetry/stats-center.d.ts +73 -0
- package/node_modules/@jsonstudio/llms/dist/telemetry/stats-center.js +280 -0
- package/node_modules/@jsonstudio/llms/package.json +2 -2
- package/package.json +11 -10
- package/scripts/README.md +26 -12
- package/scripts/auth-antigravity-token.mjs +64 -0
- package/scripts/auth-gemini-cli-token.mjs +96 -0
- package/scripts/auth-iflow-manual.mjs +81 -0
- package/scripts/auth-iflow-token-direct.mjs +87 -0
- package/scripts/auth-iflow-token.mjs +77 -0
- package/scripts/copy-compat-assets.mjs +3 -15
- package/scripts/install-verify.mjs +1 -0
- package/scripts/pack-mode.mjs +2 -1
- package/scripts/publish-rcc.mjs +20 -4
- package/scripts/replay-codex-sample.mjs +13 -8
- package/scripts/tests/chat-pipeline-blackbox.mjs +1 -1
- package/scripts/tests/virtual-router-health.mjs +141 -6
- package/scripts/tools/capture-provider-goldens.mjs +8 -7
- package/scripts/verify-client-headers.mjs +224 -0
- package/dist/providers/compat/base-compatibility.d.ts +0 -27
- package/dist/providers/compat/base-compatibility.js +0 -143
- package/dist/providers/compat/base-compatibility.js.map +0 -1
- package/dist/providers/compat/compat-directory-loader.d.ts +0 -4
- package/dist/providers/compat/compat-directory-loader.js +0 -85
- package/dist/providers/compat/compat-directory-loader.js.map +0 -1
- package/dist/providers/compat/compatibility-adapter.d.ts +0 -18
- package/dist/providers/compat/compatibility-adapter.js +0 -104
- package/dist/providers/compat/compatibility-adapter.js.map +0 -1
- package/dist/providers/compat/compatibility-factory.d.ts +0 -57
- package/dist/providers/compat/compatibility-factory.js +0 -155
- package/dist/providers/compat/compatibility-factory.js.map +0 -1
- package/dist/providers/compat/compatibility-interface.d.ts +0 -35
- package/dist/providers/compat/compatibility-interface.js +0 -2
- package/dist/providers/compat/compatibility-interface.js.map +0 -1
- package/dist/providers/compat/compatibility-manager.d.ts +0 -85
- package/dist/providers/compat/compatibility-manager.js +0 -368
- package/dist/providers/compat/compatibility-manager.js.map +0 -1
- package/dist/providers/compat/config/config-compatibility.d.ts +0 -28
- package/dist/providers/compat/config/config-compatibility.js +0 -95
- package/dist/providers/compat/config/config-compatibility.js.map +0 -1
- package/dist/providers/compat/field-mapping.d.ts +0 -102
- package/dist/providers/compat/field-mapping.js +0 -447
- package/dist/providers/compat/field-mapping.js.map +0 -1
- package/dist/providers/compat/filters/blacklist-sanitizer.d.ts +0 -45
- package/dist/providers/compat/filters/blacklist-sanitizer.js +0 -133
- package/dist/providers/compat/filters/blacklist-sanitizer.js.map +0 -1
- package/dist/providers/compat/filters/response-blacklist-sanitizer.d.ts +0 -28
- package/dist/providers/compat/filters/response-blacklist-sanitizer.js +0 -138
- package/dist/providers/compat/filters/response-blacklist-sanitizer.js.map +0 -1
- package/dist/providers/compat/filters/universal-shape-filter.js.map +0 -1
- package/dist/providers/compat/glm/config/blacklist-rules.json +0 -22
- package/dist/providers/compat/glm/config/field-mappings.json +0 -92
- package/dist/providers/compat/glm/config/response-blacklist.json +0 -7
- package/dist/providers/compat/glm/config/shape-filters.json +0 -37
- package/dist/providers/compat/glm/field-mapping/field-mapping-processor.d.ts +0 -28
- package/dist/providers/compat/glm/field-mapping/field-mapping-processor.js +0 -306
- package/dist/providers/compat/glm/field-mapping/field-mapping-processor.js.map +0 -1
- package/dist/providers/compat/glm/functions/glm-processor.d.ts +0 -50
- package/dist/providers/compat/glm/functions/glm-processor.js +0 -134
- package/dist/providers/compat/glm/functions/glm-processor.js.map +0 -1
- package/dist/providers/compat/glm/glm-compatibility.d.ts +0 -34
- package/dist/providers/compat/glm/glm-compatibility.js +0 -117
- package/dist/providers/compat/glm/glm-compatibility.js.map +0 -1
- package/dist/providers/compat/glm/hooks/base-hook.d.ts +0 -21
- package/dist/providers/compat/glm/hooks/base-hook.js +0 -53
- package/dist/providers/compat/glm/hooks/base-hook.js.map +0 -1
- package/dist/providers/compat/glm/hooks/glm-request-validation-hook.d.ts +0 -24
- package/dist/providers/compat/glm/hooks/glm-request-validation-hook.js +0 -268
- package/dist/providers/compat/glm/hooks/glm-request-validation-hook.js.map +0 -1
- package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.d.ts +0 -21
- package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.js +0 -171
- package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.js.map +0 -1
- package/dist/providers/compat/glm/hooks/glm-response-validation-hook.d.ts +0 -25
- package/dist/providers/compat/glm/hooks/glm-response-validation-hook.js +0 -236
- package/dist/providers/compat/glm/hooks/glm-response-validation-hook.js.map +0 -1
- package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.d.ts +0 -26
- package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.js +0 -186
- package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.js.map +0 -1
- package/dist/providers/compat/glm/index.d.ts +0 -24
- package/dist/providers/compat/glm/index.js +0 -29
- package/dist/providers/compat/glm/index.js.map +0 -1
- package/dist/providers/compat/glm/utils/tool-schema-helpers.d.ts +0 -3
- package/dist/providers/compat/glm/utils/tool-schema-helpers.js.map +0 -1
- package/dist/providers/compat/iflow/config/field-mappings.json +0 -92
- package/dist/providers/compat/iflow/config/shape-filters.json +0 -37
- package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.d.ts +0 -34
- package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.js +0 -386
- package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.js.map +0 -1
- package/dist/providers/compat/iflow/functions/iflow-processor.d.ts +0 -53
- package/dist/providers/compat/iflow/functions/iflow-processor.js +0 -215
- package/dist/providers/compat/iflow/functions/iflow-processor.js.map +0 -1
- package/dist/providers/compat/iflow/hooks/base-hook.d.ts +0 -23
- package/dist/providers/compat/iflow/hooks/base-hook.js +0 -59
- package/dist/providers/compat/iflow/hooks/base-hook.js.map +0 -1
- package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.d.ts +0 -23
- package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.js +0 -279
- package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.js.map +0 -1
- package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.d.ts +0 -20
- package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.js +0 -180
- package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.js.map +0 -1
- package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.d.ts +0 -23
- package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.js +0 -232
- package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.js.map +0 -1
- package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.d.ts +0 -25
- package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.js +0 -216
- package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.js.map +0 -1
- package/dist/providers/compat/iflow/iflow-compatibility.d.ts +0 -24
- package/dist/providers/compat/iflow/iflow-compatibility.js +0 -94
- package/dist/providers/compat/iflow/iflow-compatibility.js.map +0 -1
- package/dist/providers/compat/index.d.ts +0 -59
- package/dist/providers/compat/index.js +0 -83
- package/dist/providers/compat/index.js.map +0 -1
- package/dist/providers/compat/lmstudio-compatibility.d.ts +0 -44
- package/dist/providers/compat/lmstudio-compatibility.js +0 -193
- package/dist/providers/compat/lmstudio-compatibility.js.map +0 -1
- package/dist/providers/compat/passthrough-compatibility.d.ts +0 -29
- package/dist/providers/compat/passthrough-compatibility.js +0 -83
- package/dist/providers/compat/passthrough-compatibility.js.map +0 -1
- package/dist/providers/compat/profiles/chat/glm/index.d.ts +0 -6
- package/dist/providers/compat/profiles/chat/glm/index.js +0 -6
- package/dist/providers/compat/profiles/chat/glm/index.js.map +0 -1
- package/dist/providers/compat/profiles/chat/iflow/index.d.ts +0 -6
- package/dist/providers/compat/profiles/chat/iflow/index.js +0 -6
- package/dist/providers/compat/profiles/chat/iflow/index.js.map +0 -1
- package/dist/providers/compat/profiles/chat/lmstudio/index.d.ts +0 -6
- package/dist/providers/compat/profiles/chat/lmstudio/index.js +0 -6
- package/dist/providers/compat/profiles/chat/lmstudio/index.js.map +0 -1
- package/dist/providers/compat/profiles/chat/qwen/index.d.ts +0 -6
- package/dist/providers/compat/profiles/chat/qwen/index.js +0 -6
- package/dist/providers/compat/profiles/chat/qwen/index.js.map +0 -1
- package/dist/providers/compat/profiles/compat/passthrough/index.d.ts +0 -6
- package/dist/providers/compat/profiles/compat/passthrough/index.js +0 -6
- package/dist/providers/compat/profiles/compat/passthrough/index.js.map +0 -1
- package/dist/providers/compat/profiles/responses/c4m/index.d.ts +0 -6
- package/dist/providers/compat/profiles/responses/c4m/index.js +0 -6
- package/dist/providers/compat/profiles/responses/c4m/index.js.map +0 -1
- package/dist/providers/compat/profiles/responses/default/index.d.ts +0 -6
- package/dist/providers/compat/profiles/responses/default/index.js +0 -6
- package/dist/providers/compat/profiles/responses/default/index.js.map +0 -1
- package/dist/providers/compat/profiles/responses/fai/index.d.ts +0 -6
- package/dist/providers/compat/profiles/responses/fai/index.js +0 -6
- package/dist/providers/compat/profiles/responses/fai/index.js.map +0 -1
- package/dist/providers/compat/profiles/responses/fc/index.d.ts +0 -6
- package/dist/providers/compat/profiles/responses/fc/index.js +0 -6
- package/dist/providers/compat/profiles/responses/fc/index.js.map +0 -1
- package/dist/providers/compat/qwen/index.d.ts +0 -4
- package/dist/providers/compat/qwen/index.js +0 -6
- package/dist/providers/compat/qwen/index.js.map +0 -1
- package/dist/providers/compat/qwen-compatibility.d.ts +0 -52
- package/dist/providers/compat/qwen-compatibility.js +0 -330
- package/dist/providers/compat/qwen-compatibility.js.map +0 -1
- package/dist/providers/compat/register-compat-module.d.ts +0 -8
- package/dist/providers/compat/register-compat-module.js +0 -53
- package/dist/providers/compat/register-compat-module.js.map +0 -1
- package/dist/providers/compat/responses/c4m-responses-compatibility.d.ts +0 -27
- package/dist/providers/compat/responses/c4m-responses-compatibility.js +0 -197
- package/dist/providers/compat/responses/c4m-responses-compatibility.js.map +0 -1
- package/dist/providers/compat/standard-compatibility-utils.d.ts +0 -1
- package/dist/providers/compat/standard-compatibility-utils.js +0 -77
- package/dist/providers/compat/standard-compatibility-utils.js.map +0 -1
- package/dist/providers/compat/standard-compatibility.d.ts +0 -31
- package/dist/providers/compat/standard-compatibility.js +0 -118
- package/dist/providers/compat/standard-compatibility.js.map +0 -1
- package/dist/providers/compat/utils/snapshot-writer.js +0 -62
- package/dist/providers/compat/utils/snapshot-writer.js.map +0 -1
- package/dist/tools/replay-request.d.ts +0 -0
- package/dist/tools/replay-request.js +0 -2
- package/dist/tools/replay-request.js.map +0 -1
- package/scripts/check-glm-compat.mjs +0 -47
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
export interface VirtualRouterHitEvent {
|
|
2
|
+
requestId: string;
|
|
3
|
+
timestamp: number;
|
|
4
|
+
entryEndpoint: string;
|
|
5
|
+
routeName: string;
|
|
6
|
+
pool: string;
|
|
7
|
+
providerKey: string;
|
|
8
|
+
runtimeKey?: string;
|
|
9
|
+
providerType?: string;
|
|
10
|
+
modelId?: string;
|
|
11
|
+
}
|
|
12
|
+
export interface ProviderUsageEvent {
|
|
13
|
+
requestId: string;
|
|
14
|
+
timestamp: number;
|
|
15
|
+
providerKey: string;
|
|
16
|
+
runtimeKey?: string;
|
|
17
|
+
providerType: string;
|
|
18
|
+
modelId?: string;
|
|
19
|
+
routeName?: string;
|
|
20
|
+
entryEndpoint?: string;
|
|
21
|
+
success: boolean;
|
|
22
|
+
latencyMs: number;
|
|
23
|
+
promptTokens?: number;
|
|
24
|
+
completionTokens?: number;
|
|
25
|
+
totalTokens?: number;
|
|
26
|
+
}
|
|
27
|
+
export interface RouterStatsBucket {
|
|
28
|
+
requestCount: number;
|
|
29
|
+
poolHitCount: Record<string, number>;
|
|
30
|
+
routeHitCount: Record<string, number>;
|
|
31
|
+
providerHitCount: Record<string, number>;
|
|
32
|
+
}
|
|
33
|
+
export interface RouterStatsSnapshot {
|
|
34
|
+
global: RouterStatsBucket;
|
|
35
|
+
byEntryEndpoint: Record<string, RouterStatsBucket>;
|
|
36
|
+
}
|
|
37
|
+
export interface ProviderStatsBucket {
|
|
38
|
+
requestCount: number;
|
|
39
|
+
successCount: number;
|
|
40
|
+
errorCount: number;
|
|
41
|
+
latencySumMs: number;
|
|
42
|
+
minLatencyMs: number;
|
|
43
|
+
maxLatencyMs: number;
|
|
44
|
+
usage: {
|
|
45
|
+
promptTokens: number;
|
|
46
|
+
completionTokens: number;
|
|
47
|
+
totalTokens: number;
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
export interface ProviderStatsSnapshot {
|
|
51
|
+
global: ProviderStatsBucket;
|
|
52
|
+
byProviderKey: Record<string, ProviderStatsBucket>;
|
|
53
|
+
byRoute: Record<string, ProviderStatsBucket>;
|
|
54
|
+
byEntryEndpoint: Record<string, ProviderStatsBucket>;
|
|
55
|
+
}
|
|
56
|
+
export interface StatsSnapshot {
|
|
57
|
+
router: RouterStatsSnapshot;
|
|
58
|
+
providers: ProviderStatsSnapshot;
|
|
59
|
+
}
|
|
60
|
+
export interface StatsCenterOptions {
|
|
61
|
+
enable?: boolean;
|
|
62
|
+
autoPrintOnExit?: boolean;
|
|
63
|
+
persistPath?: string | null;
|
|
64
|
+
}
|
|
65
|
+
export interface StatsCenter {
|
|
66
|
+
recordVirtualRouterHit(ev: VirtualRouterHitEvent): void;
|
|
67
|
+
recordProviderUsage(ev: ProviderUsageEvent): void;
|
|
68
|
+
getSnapshot(): StatsSnapshot;
|
|
69
|
+
flushToDisk(): Promise<void>;
|
|
70
|
+
reset(): void;
|
|
71
|
+
}
|
|
72
|
+
export declare function initStatsCenter(options?: StatsCenterOptions): StatsCenter;
|
|
73
|
+
export declare function getStatsCenter(): StatsCenter;
|
|
@@ -0,0 +1,280 @@
|
|
|
1
|
+
import os from 'node:os';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import fs from 'node:fs/promises';
|
|
4
|
+
function createEmptyRouterBucket() {
|
|
5
|
+
return {
|
|
6
|
+
requestCount: 0,
|
|
7
|
+
poolHitCount: {},
|
|
8
|
+
routeHitCount: {},
|
|
9
|
+
providerHitCount: {}
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
function createEmptyProviderBucket() {
|
|
13
|
+
return {
|
|
14
|
+
requestCount: 0,
|
|
15
|
+
successCount: 0,
|
|
16
|
+
errorCount: 0,
|
|
17
|
+
latencySumMs: 0,
|
|
18
|
+
minLatencyMs: Number.POSITIVE_INFINITY,
|
|
19
|
+
maxLatencyMs: 0,
|
|
20
|
+
usage: {
|
|
21
|
+
promptTokens: 0,
|
|
22
|
+
completionTokens: 0,
|
|
23
|
+
totalTokens: 0
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function createEmptySnapshot() {
|
|
28
|
+
return {
|
|
29
|
+
router: {
|
|
30
|
+
global: createEmptyRouterBucket(),
|
|
31
|
+
byEntryEndpoint: {}
|
|
32
|
+
},
|
|
33
|
+
providers: {
|
|
34
|
+
global: createEmptyProviderBucket(),
|
|
35
|
+
byProviderKey: {},
|
|
36
|
+
byRoute: {},
|
|
37
|
+
byEntryEndpoint: {}
|
|
38
|
+
}
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
class NoopStatsCenter {
|
|
42
|
+
recordVirtualRouterHit() { }
|
|
43
|
+
recordProviderUsage() { }
|
|
44
|
+
getSnapshot() { return createEmptySnapshot(); }
|
|
45
|
+
async flushToDisk() { }
|
|
46
|
+
reset() { }
|
|
47
|
+
}
|
|
48
|
+
class DefaultStatsCenter {
|
|
49
|
+
snapshot = createEmptySnapshot();
|
|
50
|
+
dirty = false;
|
|
51
|
+
flushInFlight = false;
|
|
52
|
+
persistPath;
|
|
53
|
+
constructor(persistPath) {
|
|
54
|
+
if (persistPath === null) {
|
|
55
|
+
this.persistPath = null;
|
|
56
|
+
}
|
|
57
|
+
else if (typeof persistPath === 'string' && persistPath.trim().length) {
|
|
58
|
+
this.persistPath = persistPath.trim();
|
|
59
|
+
}
|
|
60
|
+
else {
|
|
61
|
+
const base = path.join(os.homedir(), '.routecodex', 'stats');
|
|
62
|
+
this.persistPath = path.join(base, 'stats.json');
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
recordVirtualRouterHit(ev) {
|
|
66
|
+
if (!ev || !ev.routeName || !ev.providerKey) {
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
const snap = this.snapshot;
|
|
70
|
+
this.applyRouterHitToBucket(snap.router.global, ev);
|
|
71
|
+
const entryKey = ev.entryEndpoint || 'unknown';
|
|
72
|
+
if (!snap.router.byEntryEndpoint[entryKey]) {
|
|
73
|
+
snap.router.byEntryEndpoint[entryKey] = createEmptyRouterBucket();
|
|
74
|
+
}
|
|
75
|
+
this.applyRouterHitToBucket(snap.router.byEntryEndpoint[entryKey], ev);
|
|
76
|
+
this.dirty = true;
|
|
77
|
+
}
|
|
78
|
+
recordProviderUsage(ev) {
|
|
79
|
+
if (!ev || !ev.providerKey || !ev.providerType) {
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
const snap = this.snapshot;
|
|
83
|
+
this.applyProviderUsageToBucket(snap.providers.global, ev);
|
|
84
|
+
const providerKey = ev.providerKey;
|
|
85
|
+
if (!snap.providers.byProviderKey[providerKey]) {
|
|
86
|
+
snap.providers.byProviderKey[providerKey] = createEmptyProviderBucket();
|
|
87
|
+
}
|
|
88
|
+
this.applyProviderUsageToBucket(snap.providers.byProviderKey[providerKey], ev);
|
|
89
|
+
const routeKey = ev.routeName || 'unknown';
|
|
90
|
+
if (!snap.providers.byRoute[routeKey]) {
|
|
91
|
+
snap.providers.byRoute[routeKey] = createEmptyProviderBucket();
|
|
92
|
+
}
|
|
93
|
+
this.applyProviderUsageToBucket(snap.providers.byRoute[routeKey], ev);
|
|
94
|
+
const entryKey = ev.entryEndpoint || 'unknown';
|
|
95
|
+
if (!snap.providers.byEntryEndpoint[entryKey]) {
|
|
96
|
+
snap.providers.byEntryEndpoint[entryKey] = createEmptyProviderBucket();
|
|
97
|
+
}
|
|
98
|
+
this.applyProviderUsageToBucket(snap.providers.byEntryEndpoint[entryKey], ev);
|
|
99
|
+
this.dirty = true;
|
|
100
|
+
}
|
|
101
|
+
getSnapshot() {
|
|
102
|
+
return this.snapshot;
|
|
103
|
+
}
|
|
104
|
+
reset() {
|
|
105
|
+
this.snapshot = createEmptySnapshot();
|
|
106
|
+
this.dirty = false;
|
|
107
|
+
}
|
|
108
|
+
async flushToDisk() {
|
|
109
|
+
if (!this.persistPath || !this.dirty || this.flushInFlight) {
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
this.flushInFlight = true;
|
|
113
|
+
try {
|
|
114
|
+
const dir = path.dirname(this.persistPath);
|
|
115
|
+
await fs.mkdir(dir, { recursive: true });
|
|
116
|
+
const payload = JSON.stringify(this.snapshot, null, 2);
|
|
117
|
+
await fs.writeFile(this.persistPath, payload, 'utf-8');
|
|
118
|
+
this.dirty = false;
|
|
119
|
+
}
|
|
120
|
+
catch {
|
|
121
|
+
// ignore persistence errors
|
|
122
|
+
}
|
|
123
|
+
finally {
|
|
124
|
+
this.flushInFlight = false;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
applyRouterHitToBucket(bucket, ev) {
|
|
128
|
+
bucket.requestCount += 1;
|
|
129
|
+
if (ev.pool) {
|
|
130
|
+
bucket.poolHitCount[ev.pool] = (bucket.poolHitCount[ev.pool] || 0) + 1;
|
|
131
|
+
}
|
|
132
|
+
if (ev.routeName) {
|
|
133
|
+
bucket.routeHitCount[ev.routeName] = (bucket.routeHitCount[ev.routeName] || 0) + 1;
|
|
134
|
+
}
|
|
135
|
+
if (ev.providerKey) {
|
|
136
|
+
bucket.providerHitCount[ev.providerKey] = (bucket.providerHitCount[ev.providerKey] || 0) + 1;
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
applyProviderUsageToBucket(bucket, ev) {
|
|
140
|
+
bucket.requestCount += 1;
|
|
141
|
+
if (ev.success) {
|
|
142
|
+
bucket.successCount += 1;
|
|
143
|
+
}
|
|
144
|
+
else {
|
|
145
|
+
bucket.errorCount += 1;
|
|
146
|
+
}
|
|
147
|
+
if (Number.isFinite(ev.latencyMs) && ev.latencyMs >= 0) {
|
|
148
|
+
bucket.latencySumMs += ev.latencyMs;
|
|
149
|
+
if (ev.latencyMs < bucket.minLatencyMs) {
|
|
150
|
+
bucket.minLatencyMs = ev.latencyMs;
|
|
151
|
+
}
|
|
152
|
+
if (ev.latencyMs > bucket.maxLatencyMs) {
|
|
153
|
+
bucket.maxLatencyMs = ev.latencyMs;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
if (typeof ev.promptTokens === 'number' && Number.isFinite(ev.promptTokens)) {
|
|
157
|
+
bucket.usage.promptTokens += Math.max(0, ev.promptTokens);
|
|
158
|
+
}
|
|
159
|
+
if (typeof ev.completionTokens === 'number' && Number.isFinite(ev.completionTokens)) {
|
|
160
|
+
bucket.usage.completionTokens += Math.max(0, ev.completionTokens);
|
|
161
|
+
}
|
|
162
|
+
if (typeof ev.totalTokens === 'number' && Number.isFinite(ev.totalTokens)) {
|
|
163
|
+
bucket.usage.totalTokens += Math.max(0, ev.totalTokens);
|
|
164
|
+
}
|
|
165
|
+
else {
|
|
166
|
+
const derivedTotal = (typeof ev.promptTokens === 'number' ? Math.max(0, ev.promptTokens) : 0) +
|
|
167
|
+
(typeof ev.completionTokens === 'number' ? Math.max(0, ev.completionTokens) : 0);
|
|
168
|
+
bucket.usage.totalTokens += derivedTotal;
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
let instance = null;
|
|
173
|
+
function resolveEnableFlag(defaultValue) {
|
|
174
|
+
const raw = process.env.ROUTECODEX_STATS;
|
|
175
|
+
if (!raw)
|
|
176
|
+
return defaultValue;
|
|
177
|
+
const normalized = raw.trim().toLowerCase();
|
|
178
|
+
if (['1', 'true', 'yes', 'on'].includes(normalized))
|
|
179
|
+
return true;
|
|
180
|
+
if (['0', 'false', 'no', 'off'].includes(normalized))
|
|
181
|
+
return false;
|
|
182
|
+
return defaultValue;
|
|
183
|
+
}
|
|
184
|
+
function printStatsToConsole(snapshot) {
|
|
185
|
+
const router = snapshot.router;
|
|
186
|
+
const providers = snapshot.providers;
|
|
187
|
+
const totalRequests = router.global.requestCount;
|
|
188
|
+
const poolEntries = Object.entries(router.global.poolHitCount);
|
|
189
|
+
const providerEntries = Object.entries(router.global.providerHitCount);
|
|
190
|
+
// Router summary
|
|
191
|
+
// eslint-disable-next-line no-console
|
|
192
|
+
console.log('[stats] Virtual Router:');
|
|
193
|
+
// eslint-disable-next-line no-console
|
|
194
|
+
console.log(` total requests: ${totalRequests}`);
|
|
195
|
+
if (poolEntries.length) {
|
|
196
|
+
// eslint-disable-next-line no-console
|
|
197
|
+
console.log(' pools:');
|
|
198
|
+
for (const [pool, count] of poolEntries) {
|
|
199
|
+
const ratio = totalRequests > 0 ? (count / totalRequests) * 100 : 0;
|
|
200
|
+
// eslint-disable-next-line no-console
|
|
201
|
+
console.log(` ${pool}: ${count} (${ratio.toFixed(2)}%)`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
if (providerEntries.length) {
|
|
205
|
+
// eslint-disable-next-line no-console
|
|
206
|
+
console.log(' top providers:');
|
|
207
|
+
const sorted = providerEntries.sort((a, b) => b[1] - a[1]).slice(0, 5);
|
|
208
|
+
for (const [providerKey, count] of sorted) {
|
|
209
|
+
// eslint-disable-next-line no-console
|
|
210
|
+
console.log(` ${providerKey}: ${count}`);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
const globalProvider = providers.global;
|
|
214
|
+
const totalProviderRequests = globalProvider.requestCount;
|
|
215
|
+
const avgLatency = globalProvider.successCount > 0 ? globalProvider.latencySumMs / globalProvider.successCount : 0;
|
|
216
|
+
// Provider summary
|
|
217
|
+
// eslint-disable-next-line no-console
|
|
218
|
+
console.log('\n[stats] Providers:');
|
|
219
|
+
// eslint-disable-next-line no-console
|
|
220
|
+
console.log(` total requests : ${totalProviderRequests} (success=${globalProvider.successCount}, error=${globalProvider.errorCount})`);
|
|
221
|
+
// eslint-disable-next-line no-console
|
|
222
|
+
console.log(` avg latency : ${avgLatency.toFixed(1)} ms`);
|
|
223
|
+
// eslint-disable-next-line no-console
|
|
224
|
+
console.log(` total tokens : prompt=${globalProvider.usage.promptTokens} completion=${globalProvider.usage.completionTokens} total=${globalProvider.usage.totalTokens}`);
|
|
225
|
+
}
|
|
226
|
+
export function initStatsCenter(options) {
|
|
227
|
+
if (instance) {
|
|
228
|
+
return instance;
|
|
229
|
+
}
|
|
230
|
+
const enabled = resolveEnableFlag(options?.enable ?? true);
|
|
231
|
+
if (!enabled) {
|
|
232
|
+
instance = new NoopStatsCenter();
|
|
233
|
+
return instance;
|
|
234
|
+
}
|
|
235
|
+
const center = new DefaultStatsCenter(options?.persistPath);
|
|
236
|
+
instance = center;
|
|
237
|
+
const autoPrint = options?.autoPrintOnExit !== false;
|
|
238
|
+
if (autoPrint && typeof process !== 'undefined' && typeof process.on === 'function') {
|
|
239
|
+
const handler = async () => {
|
|
240
|
+
try {
|
|
241
|
+
await center.flushToDisk();
|
|
242
|
+
}
|
|
243
|
+
catch {
|
|
244
|
+
// ignore
|
|
245
|
+
}
|
|
246
|
+
try {
|
|
247
|
+
const snapshot = center.getSnapshot();
|
|
248
|
+
printStatsToConsole(snapshot);
|
|
249
|
+
}
|
|
250
|
+
catch {
|
|
251
|
+
// ignore
|
|
252
|
+
}
|
|
253
|
+
};
|
|
254
|
+
try {
|
|
255
|
+
process.once('beforeExit', handler);
|
|
256
|
+
}
|
|
257
|
+
catch {
|
|
258
|
+
// ignore
|
|
259
|
+
}
|
|
260
|
+
try {
|
|
261
|
+
process.once('SIGINT', handler);
|
|
262
|
+
}
|
|
263
|
+
catch {
|
|
264
|
+
// ignore
|
|
265
|
+
}
|
|
266
|
+
try {
|
|
267
|
+
process.once('SIGTERM', handler);
|
|
268
|
+
}
|
|
269
|
+
catch {
|
|
270
|
+
// ignore
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
return instance;
|
|
274
|
+
}
|
|
275
|
+
export function getStatsCenter() {
|
|
276
|
+
if (!instance) {
|
|
277
|
+
return initStatsCenter();
|
|
278
|
+
}
|
|
279
|
+
return instance;
|
|
280
|
+
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsonstudio/llms",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.375",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test:looprt:gemini": "npm run build && node scripts/tests/loop-rt-gemini.mjs",
|
|
26
26
|
"replay:responses:chat-sse": "node scripts/exp3-responses-sse-to-chat-sse.mjs",
|
|
27
27
|
"replay:responses:loop": "node scripts/exp4-responses-sse-loop.mjs",
|
|
28
|
-
"test:virtual-router": "npm run build:dev && node scripts/tests/virtual-router-dry-run.mjs",
|
|
28
|
+
"test:virtual-router": "npm run build:dev && node scripts/tests/virtual-router-dry-run.mjs && node scripts/tests/virtual-router-context.mjs",
|
|
29
29
|
"test:virtual-router-health": "npm run build:dev && node scripts/tests/virtual-router-health.mjs"
|
|
30
30
|
},
|
|
31
31
|
"dependencies": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jsonstudio/rcc",
|
|
3
|
-
"version": "0.89.
|
|
3
|
+
"version": "0.89.524",
|
|
4
4
|
"description": "Multi-provider OpenAI proxy server with anthropic/responses/chat support (dev)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -39,13 +39,14 @@
|
|
|
39
39
|
"build:watch": "tsc --watch",
|
|
40
40
|
"start": "npm run -s start:bg",
|
|
41
41
|
"dev": "tsx watch src/index.ts",
|
|
42
|
-
"
|
|
43
|
-
"test
|
|
44
|
-
"test:
|
|
45
|
-
"test:
|
|
46
|
-
"test:
|
|
47
|
-
"test:
|
|
48
|
-
"test:
|
|
42
|
+
"jest:run": "node --experimental-vm-modules ./node_modules/jest/bin/jest.js",
|
|
43
|
+
"test": "npm run jest:run",
|
|
44
|
+
"test:watch": "npm run jest:run -- --watch",
|
|
45
|
+
"test:coverage": "npm run jest:run -- --coverage",
|
|
46
|
+
"test:integration": "npm run jest:run -- --testPathPattern=integration",
|
|
47
|
+
"test:e2e": "npm run jest:run -- --testPathPattern=e2e",
|
|
48
|
+
"test:performance": "npm run jest:run -- --testPathPattern=performance",
|
|
49
|
+
"test:protocol": "npm run jest:run -- --testPathPattern=protocol-tools-e2e.spec.ts --runInBand --detectOpenHandles --forceExit",
|
|
49
50
|
"test:dry-run": "node tests/basic-dry-run.mjs",
|
|
50
51
|
"test:lmstudio-dryrun": "node tests/lmstudio-tools-bidir-dry-run.mjs",
|
|
51
52
|
"lint": "eslint --no-eslintrc -c .eslintrc.json src --ext .ts --no-cache",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
"start:verify:fg": "node scripts/start-verify.mjs --mode fg --timeout 90",
|
|
84
85
|
"rc-config": "node scripts/rc-config.mjs",
|
|
85
86
|
"config:validate:providers": "node scripts/validate-config-providers.mjs",
|
|
86
|
-
"verify:e2e-toolcall": "node scripts/verify-e2e-toolcall.mjs",
|
|
87
|
+
"verify:e2e-toolcall": "node scripts/verify-e2e-toolcall.mjs && node scripts/verify-client-headers.mjs",
|
|
87
88
|
"test:anthropic-roundtrip": "node scripts/tests/anthropic-roundtrip.mjs",
|
|
88
89
|
"replay:codex-sample": "node scripts/replay-codex-sample.mjs",
|
|
89
90
|
"config:update:providers": "node scripts/update-config-providers.mjs",
|
|
@@ -125,7 +126,7 @@
|
|
|
125
126
|
},
|
|
126
127
|
"dependencies": {
|
|
127
128
|
"@anthropic-ai/sdk": "^0.65.0",
|
|
128
|
-
"@jsonstudio/llms": "^0.6.
|
|
129
|
+
"@jsonstudio/llms": "^0.6.375",
|
|
129
130
|
"@lmstudio/sdk": "^1.5.0",
|
|
130
131
|
"@radix-ui/react-switch": "^1.2.6",
|
|
131
132
|
"@types/socket.io": "^3.0.1",
|
package/scripts/README.md
CHANGED
|
@@ -1,20 +1,34 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Build & Install Scripts
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
> **AGENTS.md rules apply** – always build shared modules first, never skip verification, never mix dev/release modes.
|
|
4
4
|
|
|
5
|
-
##
|
|
6
|
-
|
|
7
|
-
### install-user-global.sh(推荐)
|
|
5
|
+
## Dev CLI (routecodex)
|
|
8
6
|
|
|
9
7
|
```bash
|
|
10
|
-
#
|
|
8
|
+
# 1. build sharedmodule first
|
|
9
|
+
npm --prefix sharedmodule/llmswitch-core run build
|
|
10
|
+
|
|
11
|
+
# 2. build host
|
|
12
|
+
cd - && npm run build:dev
|
|
13
|
+
|
|
14
|
+
# 3. install globally
|
|
11
15
|
npm run install:global
|
|
12
16
|
```
|
|
13
17
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
## Release CLI (rcc)
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
# 1. build sharedmodule first
|
|
22
|
+
npm --prefix sharedmodule/llmswitch-core run build
|
|
23
|
+
|
|
24
|
+
# 2. build release variant
|
|
25
|
+
npm run build:release
|
|
26
|
+
|
|
27
|
+
# 3. install globally
|
|
28
|
+
npm run install:release
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
## Verification
|
|
19
32
|
|
|
20
|
-
|
|
33
|
+
- Never use `ROUTECODEX_VERIFY_SKIP=1`; golden samples are up-to-date.
|
|
34
|
+
- CI runs `npm run build:dev && npm run build:release` with full verification.
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Antigravity OAuth authentication script
|
|
3
|
+
// Usage:
|
|
4
|
+
// # 默认使用 ~/.routecodex/auth/antigravity-oauth.json(自动创建/更新)
|
|
5
|
+
// node scripts/auth-antigravity-token.mjs
|
|
6
|
+
//
|
|
7
|
+
// # 或通过环境变量显式指定 token 文件(支持 ~ 展开):
|
|
8
|
+
// // ANTIGRAVITY_TOKEN_FILE="~/.routecodex/auth/antigravity-oauth-alt.json" node scripts/auth-antigravity-token.mjs
|
|
9
|
+
|
|
10
|
+
import os from 'os';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import fs from 'fs/promises';
|
|
13
|
+
|
|
14
|
+
async function resolveAntigravityTokenPath() {
|
|
15
|
+
const envFile =
|
|
16
|
+
(process.env.ANTIGRAVITY_TOKEN_FILE && process.env.ANTIGRAVITY_TOKEN_FILE.trim()) ||
|
|
17
|
+
(process.env.ROUTECODEX_ANTIGRAVITY_TOKEN_FILE && process.env.ROUTECODEX_ANTIGRAVITY_TOKEN_FILE.trim()) ||
|
|
18
|
+
'';
|
|
19
|
+
|
|
20
|
+
if (envFile) {
|
|
21
|
+
const normalized = envFile.startsWith('~')
|
|
22
|
+
? envFile.replace(/^~(?=$|\/)/, os.homedir())
|
|
23
|
+
: envFile;
|
|
24
|
+
return path.resolve(normalized);
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const home = os.homedir();
|
|
28
|
+
return path.join(home, '.routecodex', 'auth', 'antigravity-oauth.json');
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
async function run() {
|
|
32
|
+
const tokenPath = await resolveAntigravityTokenPath();
|
|
33
|
+
const dir = path.dirname(tokenPath);
|
|
34
|
+
await fs.mkdir(dir, { recursive: true });
|
|
35
|
+
try {
|
|
36
|
+
await fs.access(tokenPath);
|
|
37
|
+
} catch {
|
|
38
|
+
await fs.writeFile(tokenPath, '{}', 'utf-8');
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const { ensureValidOAuthToken } = await import('../dist/providers/auth/oauth-lifecycle.js');
|
|
42
|
+
|
|
43
|
+
console.log(`[antigravity-auth] Authenticating token: ${tokenPath}`);
|
|
44
|
+
|
|
45
|
+
await ensureValidOAuthToken(
|
|
46
|
+
'antigravity',
|
|
47
|
+
{
|
|
48
|
+
type: 'antigravity-oauth',
|
|
49
|
+
tokenFile: tokenPath
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
forceReauthorize: true,
|
|
53
|
+
openBrowser: true
|
|
54
|
+
}
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
console.log(`[antigravity-auth] Token saved to: ${tokenPath}`);
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
run().catch((err) => {
|
|
61
|
+
console.error('[antigravity-auth] Error:', err);
|
|
62
|
+
process.exit(1);
|
|
63
|
+
});
|
|
64
|
+
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
// Gemini CLI OAuth authentication script
|
|
3
|
+
// Usage:
|
|
4
|
+
// # 默认使用 ~/.routecodex/auth/gemini-oauth.json(自动创建/更新)
|
|
5
|
+
// node scripts/auth-gemini-cli-token.mjs
|
|
6
|
+
//
|
|
7
|
+
// # 或通过环境变量显式指定 token 文件(支持 ~ 展开):
|
|
8
|
+
// // GEMINI_CLI_TOKEN_FILE="~/.routecodex/auth/gemini-oauth-1-primary.json" node scripts/auth-gemini-cli-token.mjs
|
|
9
|
+
|
|
10
|
+
import os from 'os';
|
|
11
|
+
import path from 'path';
|
|
12
|
+
import fs from 'fs/promises';
|
|
13
|
+
|
|
14
|
+
async function resolveGeminiTokenPath() {
|
|
15
|
+
const envFile =
|
|
16
|
+
(process.env.GEMINI_CLI_TOKEN_FILE && process.env.GEMINI_CLI_TOKEN_FILE.trim()) ||
|
|
17
|
+
(process.env.ROUTECODEX_GEMINI_TOKEN_FILE && process.env.ROUTECODEX_GEMINI_TOKEN_FILE.trim()) ||
|
|
18
|
+
'';
|
|
19
|
+
|
|
20
|
+
if (envFile) {
|
|
21
|
+
const normalized = envFile.startsWith('~')
|
|
22
|
+
? envFile.replace(/^~\//, `${os.homedir()}/`)
|
|
23
|
+
: envFile;
|
|
24
|
+
return { tokenPath: normalized, duplicates: [] };
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
const authDir = path.join(os.homedir(), '.routecodex', 'auth');
|
|
28
|
+
const primaryName = 'gemini-oauth.json';
|
|
29
|
+
|
|
30
|
+
let entries = [];
|
|
31
|
+
try {
|
|
32
|
+
entries = await fs.readdir(authDir);
|
|
33
|
+
} catch {
|
|
34
|
+
// directory may not exist yet
|
|
35
|
+
entries = [];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
const matches = entries
|
|
39
|
+
.filter((entry) => entry.endsWith('.json'))
|
|
40
|
+
.filter((entry) => entry === primaryName || entry.startsWith('gemini-oauth-'));
|
|
41
|
+
|
|
42
|
+
matches.sort();
|
|
43
|
+
if (matches.length > 0) {
|
|
44
|
+
const canonical = path.join(authDir, matches[0]);
|
|
45
|
+
const duplicates = matches.slice(1).map((name) => path.join(authDir, name));
|
|
46
|
+
return { tokenPath: canonical, duplicates };
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const canonical = path.join(authDir, primaryName);
|
|
50
|
+
return { tokenPath: canonical, duplicates: [] };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
async function run() {
|
|
54
|
+
const { tokenPath, duplicates } = await resolveGeminiTokenPath();
|
|
55
|
+
console.log(`[gemini-cli-auth] Authenticating token: ${tokenPath}`);
|
|
56
|
+
|
|
57
|
+
// ensure token file exists so re-auth can recreate after delete
|
|
58
|
+
await fs.mkdir(path.dirname(tokenPath), { recursive: true });
|
|
59
|
+
try {
|
|
60
|
+
await fs.access(tokenPath);
|
|
61
|
+
} catch {
|
|
62
|
+
await fs.writeFile(tokenPath, '{}', 'utf-8');
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
const { ensureValidOAuthToken } = await import('../dist/providers/auth/oauth-lifecycle.js');
|
|
66
|
+
|
|
67
|
+
await ensureValidOAuthToken(
|
|
68
|
+
'gemini-cli',
|
|
69
|
+
{
|
|
70
|
+
type: 'gemini-cli-oauth',
|
|
71
|
+
tokenFile: tokenPath
|
|
72
|
+
},
|
|
73
|
+
{
|
|
74
|
+
forceReauthorize: true,
|
|
75
|
+
openBrowser: true
|
|
76
|
+
}
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
// clean up duplicate token files for the same family
|
|
80
|
+
for (const dup of duplicates) {
|
|
81
|
+
if (dup === tokenPath) continue;
|
|
82
|
+
try {
|
|
83
|
+
await fs.unlink(dup);
|
|
84
|
+
console.log(`[gemini-cli-auth] Removed duplicate token file: ${dup}`);
|
|
85
|
+
} catch {
|
|
86
|
+
// ignore
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
console.log(`[gemini-cli-auth] Token saved to: ${tokenPath}`);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
run().catch((err) => {
|
|
94
|
+
console.error('[gemini-cli-auth] Error:', err);
|
|
95
|
+
process.exit(1);
|
|
96
|
+
});
|