@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,209 @@
|
|
|
1
|
+
const MODEL_MAP = {
|
|
2
|
+
'gpt-3.5-turbo': 'qwen-turbo',
|
|
3
|
+
'gpt-4': 'qwen3-coder-plus',
|
|
4
|
+
'gpt-4-turbo': 'qwen3-coder-plus',
|
|
5
|
+
'gpt-4o': 'qwen3-coder-plus'
|
|
6
|
+
};
|
|
7
|
+
const FINISH_REASON_MAP = {
|
|
8
|
+
stop: 'stop',
|
|
9
|
+
length: 'length',
|
|
10
|
+
tool_calls: 'tool_calls',
|
|
11
|
+
content_filter: 'content_filter'
|
|
12
|
+
};
|
|
13
|
+
const isRecord = (value) => typeof value === 'object' && value !== null;
|
|
14
|
+
export function applyQwenRequestTransform(payload) {
|
|
15
|
+
const cloned = structuredClone(payload);
|
|
16
|
+
const transformed = convertToQwenRequest(cloned);
|
|
17
|
+
return transformed;
|
|
18
|
+
}
|
|
19
|
+
export function applyQwenResponseTransform(payload) {
|
|
20
|
+
const cloned = structuredClone(payload);
|
|
21
|
+
const transformed = transformQwenResponseToOpenAI(cloned);
|
|
22
|
+
return transformed;
|
|
23
|
+
}
|
|
24
|
+
function convertToQwenRequest(request) {
|
|
25
|
+
const qwenRequest = {};
|
|
26
|
+
const mappedModel = mapModelName(typeof request.model === 'string' ? request.model : undefined);
|
|
27
|
+
if (mappedModel) {
|
|
28
|
+
qwenRequest.model = mappedModel;
|
|
29
|
+
}
|
|
30
|
+
if (Array.isArray(request.messages)) {
|
|
31
|
+
qwenRequest.messages = structuredClone(request.messages);
|
|
32
|
+
const normalizedMessages = request.messages
|
|
33
|
+
.map(message => normalizeMessage(message))
|
|
34
|
+
.filter((entry) => entry !== null);
|
|
35
|
+
if (normalizedMessages.length > 0) {
|
|
36
|
+
qwenRequest.input = normalizedMessages;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
const parameters = extractParameters(request);
|
|
40
|
+
if (Object.keys(parameters).length > 0) {
|
|
41
|
+
qwenRequest.parameters = parameters;
|
|
42
|
+
}
|
|
43
|
+
if (typeof request.stream === 'boolean') {
|
|
44
|
+
qwenRequest.stream = request.stream;
|
|
45
|
+
}
|
|
46
|
+
if (isRecord(request.response_format)) {
|
|
47
|
+
qwenRequest.response_format = structuredClone(request.response_format);
|
|
48
|
+
}
|
|
49
|
+
if (typeof request.user === 'string') {
|
|
50
|
+
qwenRequest.user = request.user;
|
|
51
|
+
}
|
|
52
|
+
if (Array.isArray(request.tools)) {
|
|
53
|
+
qwenRequest.tools = sanitizeTools(request.tools);
|
|
54
|
+
}
|
|
55
|
+
if (isRecord(request.metadata)) {
|
|
56
|
+
qwenRequest.metadata = structuredClone(request.metadata);
|
|
57
|
+
}
|
|
58
|
+
return qwenRequest;
|
|
59
|
+
}
|
|
60
|
+
function sanitizeTools(tools) {
|
|
61
|
+
return tools.map(tool => {
|
|
62
|
+
if (!isRecord(tool)) {
|
|
63
|
+
return tool;
|
|
64
|
+
}
|
|
65
|
+
const normalized = {};
|
|
66
|
+
if (typeof tool.type === 'string') {
|
|
67
|
+
normalized.type = tool.type;
|
|
68
|
+
}
|
|
69
|
+
if (isRecord(tool.function)) {
|
|
70
|
+
normalized.function = structuredClone(tool.function);
|
|
71
|
+
}
|
|
72
|
+
return Object.keys(normalized).length > 0 ? normalized : tool;
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function normalizeMessage(message) {
|
|
76
|
+
if (!isRecord(message)) {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
const role = typeof message.role === 'string' ? message.role : 'user';
|
|
80
|
+
const content = normalizeMessageContent(message.content);
|
|
81
|
+
return { role, content };
|
|
82
|
+
}
|
|
83
|
+
function normalizeMessageContent(content) {
|
|
84
|
+
if (content === undefined || content === null) {
|
|
85
|
+
return [{ text: '' }];
|
|
86
|
+
}
|
|
87
|
+
if (typeof content === 'string') {
|
|
88
|
+
return [{ text: content }];
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(content)) {
|
|
91
|
+
return content.map(chunk => normalizeContentChunk(chunk));
|
|
92
|
+
}
|
|
93
|
+
if (isRecord(content) && typeof content.text === 'string') {
|
|
94
|
+
return [{ text: content.text }];
|
|
95
|
+
}
|
|
96
|
+
return [{ text: JSON.stringify(content) }];
|
|
97
|
+
}
|
|
98
|
+
function normalizeContentChunk(chunk) {
|
|
99
|
+
if (typeof chunk === 'string') {
|
|
100
|
+
return { text: chunk };
|
|
101
|
+
}
|
|
102
|
+
if (isRecord(chunk)) {
|
|
103
|
+
if (typeof chunk.text === 'string') {
|
|
104
|
+
return { text: chunk.text };
|
|
105
|
+
}
|
|
106
|
+
return structuredClone(chunk);
|
|
107
|
+
}
|
|
108
|
+
return { text: String(chunk) };
|
|
109
|
+
}
|
|
110
|
+
function extractParameters(request) {
|
|
111
|
+
const parameters = {};
|
|
112
|
+
const numericFields = [
|
|
113
|
+
{ key: 'temperature', target: 'temperature' },
|
|
114
|
+
{ key: 'top_p', target: 'top_p' },
|
|
115
|
+
{ key: 'frequency_penalty', target: 'frequency_penalty' },
|
|
116
|
+
{ key: 'presence_penalty', target: 'presence_penalty' },
|
|
117
|
+
{ key: 'max_tokens', target: 'max_output_tokens' }
|
|
118
|
+
];
|
|
119
|
+
for (const field of numericFields) {
|
|
120
|
+
const value = request[field.key];
|
|
121
|
+
if (typeof value === 'number') {
|
|
122
|
+
parameters[field.target] = value;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
if (request.stop !== undefined) {
|
|
126
|
+
const stops = Array.isArray(request.stop) ? request.stop : [request.stop];
|
|
127
|
+
const sequences = stops.filter(item => typeof item === 'string');
|
|
128
|
+
if (sequences.length > 0) {
|
|
129
|
+
parameters.stop_sequences = sequences;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
if (typeof request.debug === 'boolean') {
|
|
133
|
+
parameters.debug = request.debug;
|
|
134
|
+
}
|
|
135
|
+
return parameters;
|
|
136
|
+
}
|
|
137
|
+
function transformQwenResponseToOpenAI(response) {
|
|
138
|
+
const data = isRecord(response.data) ? response.data : response;
|
|
139
|
+
const usage = isRecord(data.usage)
|
|
140
|
+
? structuredClone(data.usage)
|
|
141
|
+
: {
|
|
142
|
+
prompt_tokens: 0,
|
|
143
|
+
completion_tokens: 0,
|
|
144
|
+
total_tokens: 0
|
|
145
|
+
};
|
|
146
|
+
const transformed = {
|
|
147
|
+
id: typeof data.id === 'string' ? data.id : `chatcmpl-${Date.now()}`,
|
|
148
|
+
object: 'chat.completion',
|
|
149
|
+
created: typeof data.created === 'number' ? data.created : Math.floor(Date.now() / 1000),
|
|
150
|
+
model: typeof data.model === 'string' ? data.model : 'qwen-turbo',
|
|
151
|
+
choices: transformChoices(data.choices),
|
|
152
|
+
usage,
|
|
153
|
+
_transformed: true,
|
|
154
|
+
_originalFormat: 'qwen',
|
|
155
|
+
_targetFormat: 'openai'
|
|
156
|
+
};
|
|
157
|
+
return transformed;
|
|
158
|
+
}
|
|
159
|
+
function transformChoices(rawChoices) {
|
|
160
|
+
if (!Array.isArray(rawChoices)) {
|
|
161
|
+
return [];
|
|
162
|
+
}
|
|
163
|
+
return rawChoices.map((choice, index) => {
|
|
164
|
+
const choiceObj = isRecord(choice) ? choice : {};
|
|
165
|
+
const messageObj = isRecord(choiceObj.message) ? choiceObj.message : {};
|
|
166
|
+
return {
|
|
167
|
+
index: typeof choiceObj.index === 'number' ? choiceObj.index : index,
|
|
168
|
+
message: {
|
|
169
|
+
role: typeof messageObj.role === 'string' ? messageObj.role : 'assistant',
|
|
170
|
+
content: typeof messageObj.content === 'string' ? messageObj.content : '',
|
|
171
|
+
tool_calls: transformToolCalls(messageObj.tool_calls)
|
|
172
|
+
},
|
|
173
|
+
finish_reason: transformFinishReason(typeof choiceObj.finish_reason === 'string' ? choiceObj.finish_reason : undefined)
|
|
174
|
+
};
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
function transformToolCalls(toolCalls) {
|
|
178
|
+
if (!Array.isArray(toolCalls)) {
|
|
179
|
+
return [];
|
|
180
|
+
}
|
|
181
|
+
return toolCalls.map((toolCall, index) => {
|
|
182
|
+
const toolCallObj = isRecord(toolCall) ? toolCall : {};
|
|
183
|
+
const fnObj = isRecord(toolCallObj.function) ? toolCallObj.function : {};
|
|
184
|
+
const id = typeof toolCallObj.id === 'string'
|
|
185
|
+
? toolCallObj.id
|
|
186
|
+
: `call_${Date.now()}_${index}`;
|
|
187
|
+
const name = typeof fnObj.name === 'string' ? fnObj.name : '';
|
|
188
|
+
const args = typeof fnObj.arguments === 'string'
|
|
189
|
+
? fnObj.arguments
|
|
190
|
+
: JSON.stringify(fnObj.arguments ?? {});
|
|
191
|
+
return {
|
|
192
|
+
id,
|
|
193
|
+
type: 'function',
|
|
194
|
+
function: { name, arguments: args }
|
|
195
|
+
};
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
function transformFinishReason(reason) {
|
|
199
|
+
if (!reason) {
|
|
200
|
+
return 'stop';
|
|
201
|
+
}
|
|
202
|
+
return FINISH_REASON_MAP[reason] ?? reason;
|
|
203
|
+
}
|
|
204
|
+
function mapModelName(model) {
|
|
205
|
+
if (!model) {
|
|
206
|
+
return undefined;
|
|
207
|
+
}
|
|
208
|
+
return MODEL_MAP[model] ?? model;
|
|
209
|
+
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { JsonObject } from '../../hub/types/json.js';
|
|
2
|
+
export interface RequestRulesConfig {
|
|
3
|
+
tools?: {
|
|
4
|
+
function?: {
|
|
5
|
+
removeKeys?: string[];
|
|
6
|
+
};
|
|
7
|
+
};
|
|
8
|
+
messages?: {
|
|
9
|
+
assistantToolCalls?: {
|
|
10
|
+
function?: {
|
|
11
|
+
removeKeys?: string[];
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
};
|
|
15
|
+
topLevel?: {
|
|
16
|
+
conditional?: Array<{
|
|
17
|
+
when?: {
|
|
18
|
+
tools?: 'empty' | 'present';
|
|
19
|
+
};
|
|
20
|
+
remove?: string[];
|
|
21
|
+
}>;
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
export declare function applyRequestRules(payload: JsonObject, config?: RequestRulesConfig): JsonObject;
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2
|
+
export function applyRequestRules(payload, config) {
|
|
3
|
+
if (!config) {
|
|
4
|
+
return payload;
|
|
5
|
+
}
|
|
6
|
+
const cloned = { ...payload };
|
|
7
|
+
const toolRule = config.tools?.['function'];
|
|
8
|
+
if (toolRule?.removeKeys && Array.isArray(cloned.tools)) {
|
|
9
|
+
for (const toolEntry of cloned.tools) {
|
|
10
|
+
if (!isRecord(toolEntry)) {
|
|
11
|
+
continue;
|
|
12
|
+
}
|
|
13
|
+
const fnNode = toolEntry.function;
|
|
14
|
+
if (!isRecord(fnNode)) {
|
|
15
|
+
continue;
|
|
16
|
+
}
|
|
17
|
+
for (const key of toolRule.removeKeys) {
|
|
18
|
+
delete fnNode[key];
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
const assistantRule = config.messages?.assistantToolCalls?.['function'];
|
|
23
|
+
if (Array.isArray(cloned.messages) && assistantRule?.removeKeys) {
|
|
24
|
+
for (const message of cloned.messages) {
|
|
25
|
+
if (!isRecord(message) || !Array.isArray(message.tool_calls)) {
|
|
26
|
+
continue;
|
|
27
|
+
}
|
|
28
|
+
for (const callEntry of message.tool_calls) {
|
|
29
|
+
if (!isRecord(callEntry)) {
|
|
30
|
+
continue;
|
|
31
|
+
}
|
|
32
|
+
const fnNode = callEntry.function;
|
|
33
|
+
if (!isRecord(fnNode)) {
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
for (const key of assistantRule.removeKeys) {
|
|
37
|
+
delete fnNode[key];
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
if (Array.isArray(config.topLevel?.conditional)) {
|
|
43
|
+
for (const rule of config.topLevel.conditional) {
|
|
44
|
+
if (!rule)
|
|
45
|
+
continue;
|
|
46
|
+
if (rule.when?.tools === 'empty') {
|
|
47
|
+
if (Array.isArray(cloned.tools) && cloned.tools.length === 0) {
|
|
48
|
+
for (const field of rule.remove || []) {
|
|
49
|
+
delete cloned[field];
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (rule.when?.tools === 'present') {
|
|
54
|
+
if (Array.isArray(cloned.tools) && cloned.tools.length > 0) {
|
|
55
|
+
for (const field of rule.remove || []) {
|
|
56
|
+
delete cloned[field];
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return cloned;
|
|
63
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { JsonObject } from '../../hub/types/json.js';
|
|
2
|
+
export interface ResponseBlacklistConfig {
|
|
3
|
+
paths?: string[];
|
|
4
|
+
keepCritical?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export declare class ResponseBlacklistSanitizer {
|
|
7
|
+
private readonly cfg;
|
|
8
|
+
private readonly criticalPaths;
|
|
9
|
+
constructor(config: ResponseBlacklistConfig);
|
|
10
|
+
private isCritical;
|
|
11
|
+
private unwrapPayload;
|
|
12
|
+
private deleteByPath;
|
|
13
|
+
apply(payload: JsonObject): JsonObject;
|
|
14
|
+
}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
function isRecord(value) {
|
|
2
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
3
|
+
}
|
|
4
|
+
function isTraversable(value) {
|
|
5
|
+
return Array.isArray(value) || isRecord(value);
|
|
6
|
+
}
|
|
7
|
+
export class ResponseBlacklistSanitizer {
|
|
8
|
+
cfg;
|
|
9
|
+
criticalPaths = new Set([
|
|
10
|
+
'status',
|
|
11
|
+
'output',
|
|
12
|
+
'output_text',
|
|
13
|
+
'required_action',
|
|
14
|
+
'choices[].message.content',
|
|
15
|
+
'choices[].message.tool_calls',
|
|
16
|
+
'choices[].finish_reason'
|
|
17
|
+
]);
|
|
18
|
+
constructor(config) {
|
|
19
|
+
this.cfg = config;
|
|
20
|
+
}
|
|
21
|
+
isCritical(pathStr) {
|
|
22
|
+
if (!this.cfg.keepCritical) {
|
|
23
|
+
return false;
|
|
24
|
+
}
|
|
25
|
+
return this.criticalPaths.has(pathStr);
|
|
26
|
+
}
|
|
27
|
+
unwrapPayload(payload) {
|
|
28
|
+
if (!isRecord(payload)) {
|
|
29
|
+
return {};
|
|
30
|
+
}
|
|
31
|
+
const rootCandidate = payload.data;
|
|
32
|
+
return isRecord(rootCandidate) ? rootCandidate : payload;
|
|
33
|
+
}
|
|
34
|
+
deleteByPath(obj, pathStr) {
|
|
35
|
+
const tokens = pathStr.split('.');
|
|
36
|
+
const recurse = (current, idx) => {
|
|
37
|
+
if (!isTraversable(current) || idx >= tokens.length) {
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const token = tokens[idx];
|
|
41
|
+
const isArrayWildcard = token.endsWith('[]');
|
|
42
|
+
const key = isArrayWildcard ? token.slice(0, -2) : token;
|
|
43
|
+
if (idx === tokens.length - 1) {
|
|
44
|
+
if (!isArrayWildcard && isRecord(current) && Object.prototype.hasOwnProperty.call(current, key)) {
|
|
45
|
+
delete current[key];
|
|
46
|
+
}
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
if (isArrayWildcard) {
|
|
50
|
+
if (isRecord(current)) {
|
|
51
|
+
const arr = current[key];
|
|
52
|
+
if (Array.isArray(arr)) {
|
|
53
|
+
for (const item of arr) {
|
|
54
|
+
recurse(item, idx + 1);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else if (isRecord(current)) {
|
|
60
|
+
recurse(current[key], idx + 1);
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
recurse(obj, 0);
|
|
64
|
+
}
|
|
65
|
+
apply(payload) {
|
|
66
|
+
const out = isRecord(payload) ? payload : {};
|
|
67
|
+
try {
|
|
68
|
+
const root = this.unwrapPayload(out);
|
|
69
|
+
const configPaths = Array.isArray(this.cfg?.paths) ? this.cfg.paths ?? [] : [];
|
|
70
|
+
for (const p of configPaths) {
|
|
71
|
+
if (typeof p !== 'string' || !p) {
|
|
72
|
+
continue;
|
|
73
|
+
}
|
|
74
|
+
if (this.isCritical(p)) {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
this.deleteByPath(root, p);
|
|
78
|
+
}
|
|
79
|
+
return out;
|
|
80
|
+
}
|
|
81
|
+
catch {
|
|
82
|
+
return out;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2
|
+
export function normalizeResponsePayload(payload, config) {
|
|
3
|
+
const normalized = { ...payload };
|
|
4
|
+
if (isRecord(normalized.usage)) {
|
|
5
|
+
normalized.usage = normalizeUsageFields(normalized.usage);
|
|
6
|
+
}
|
|
7
|
+
if (typeof normalized.created_at === 'number') {
|
|
8
|
+
normalized.created = normalized.created_at;
|
|
9
|
+
delete normalized.created_at;
|
|
10
|
+
}
|
|
11
|
+
if (Array.isArray(normalized.choices)) {
|
|
12
|
+
normalized.choices = normalizeChoices(normalized.choices, config);
|
|
13
|
+
}
|
|
14
|
+
return normalized;
|
|
15
|
+
}
|
|
16
|
+
function normalizeUsageFields(usage) {
|
|
17
|
+
const normalizedUsage = { ...usage };
|
|
18
|
+
const fieldMappings = {
|
|
19
|
+
input_tokens: 'prompt_tokens',
|
|
20
|
+
output_tokens: 'completion_tokens',
|
|
21
|
+
total_input_tokens: 'prompt_tokens',
|
|
22
|
+
total_output_tokens: 'completion_tokens'
|
|
23
|
+
};
|
|
24
|
+
for (const [glmField, standardField] of Object.entries(fieldMappings)) {
|
|
25
|
+
const value = normalizedUsage[glmField];
|
|
26
|
+
if (typeof value === 'number') {
|
|
27
|
+
normalizedUsage[standardField] = value;
|
|
28
|
+
delete normalizedUsage[glmField];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
const promptTokens = typeof normalizedUsage.prompt_tokens === 'number' ? normalizedUsage.prompt_tokens : 0;
|
|
32
|
+
const completionTokens = typeof normalizedUsage.completion_tokens === 'number'
|
|
33
|
+
? normalizedUsage.completion_tokens
|
|
34
|
+
: 0;
|
|
35
|
+
normalizedUsage.prompt_tokens = promptTokens;
|
|
36
|
+
normalizedUsage.completion_tokens = completionTokens;
|
|
37
|
+
if (typeof normalizedUsage.total_tokens !== 'number') {
|
|
38
|
+
normalizedUsage.total_tokens = promptTokens + completionTokens;
|
|
39
|
+
}
|
|
40
|
+
return normalizedUsage;
|
|
41
|
+
}
|
|
42
|
+
function normalizeChoices(choices, config) {
|
|
43
|
+
const map = config?.finishReasonMap || {};
|
|
44
|
+
return choices.map((choice, idx) => {
|
|
45
|
+
if (!isRecord(choice)) {
|
|
46
|
+
return choice;
|
|
47
|
+
}
|
|
48
|
+
const normalizedChoice = {
|
|
49
|
+
index: typeof choice.index === 'number' ? choice.index : idx,
|
|
50
|
+
...choice
|
|
51
|
+
};
|
|
52
|
+
if (typeof normalizedChoice.finish_reason === 'string') {
|
|
53
|
+
normalizedChoice.finish_reason = map[normalizedChoice.finish_reason] ?? normalizedChoice.finish_reason;
|
|
54
|
+
}
|
|
55
|
+
if (isRecord(normalizedChoice.message)) {
|
|
56
|
+
normalizedChoice.message = normalizeChoiceMessage(normalizedChoice.message);
|
|
57
|
+
}
|
|
58
|
+
return normalizedChoice;
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
function normalizeChoiceMessage(message) {
|
|
62
|
+
const normalizedMessage = { ...message };
|
|
63
|
+
if (normalizedMessage.content !== undefined && typeof normalizedMessage.content !== 'string') {
|
|
64
|
+
normalizedMessage.content = normalizeMessageContent(normalizedMessage.content);
|
|
65
|
+
}
|
|
66
|
+
if (Array.isArray(normalizedMessage.tool_calls)) {
|
|
67
|
+
normalizedMessage.tool_calls = normalizeToolCalls(normalizedMessage.tool_calls);
|
|
68
|
+
}
|
|
69
|
+
return normalizedMessage;
|
|
70
|
+
}
|
|
71
|
+
function normalizeMessageContent(content) {
|
|
72
|
+
if (typeof content === 'string') {
|
|
73
|
+
return content;
|
|
74
|
+
}
|
|
75
|
+
if (Array.isArray(content)) {
|
|
76
|
+
return content.map(item => (typeof item === 'string' ? item : JSON.stringify(item))).join('');
|
|
77
|
+
}
|
|
78
|
+
if (isRecord(content)) {
|
|
79
|
+
return JSON.stringify(content);
|
|
80
|
+
}
|
|
81
|
+
return String(content ?? '');
|
|
82
|
+
}
|
|
83
|
+
function normalizeToolCalls(toolCalls) {
|
|
84
|
+
return toolCalls.map(toolCall => {
|
|
85
|
+
if (!isRecord(toolCall)) {
|
|
86
|
+
return toolCall;
|
|
87
|
+
}
|
|
88
|
+
const normalizedToolCall = { ...toolCall };
|
|
89
|
+
const func = normalizedToolCall.function;
|
|
90
|
+
if (isRecord(func) && func.arguments !== undefined) {
|
|
91
|
+
func.arguments = normalizeToolArguments(func.arguments);
|
|
92
|
+
normalizedToolCall.function = func;
|
|
93
|
+
}
|
|
94
|
+
return normalizedToolCall;
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
function normalizeToolArguments(args) {
|
|
98
|
+
let normalized = '';
|
|
99
|
+
if (typeof args === 'string') {
|
|
100
|
+
normalized = args;
|
|
101
|
+
}
|
|
102
|
+
else {
|
|
103
|
+
try {
|
|
104
|
+
normalized = JSON.stringify(args ?? {});
|
|
105
|
+
}
|
|
106
|
+
catch {
|
|
107
|
+
normalized = String(args ?? '');
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
const trimmed = normalized.trim();
|
|
111
|
+
if (!trimmed.length) {
|
|
112
|
+
return '';
|
|
113
|
+
}
|
|
114
|
+
try {
|
|
115
|
+
const parsed = JSON.parse(trimmed);
|
|
116
|
+
return JSON.stringify(parsed);
|
|
117
|
+
}
|
|
118
|
+
catch {
|
|
119
|
+
return trimmed;
|
|
120
|
+
}
|
|
121
|
+
}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2
|
+
export function validateResponsePayload(payload, _config) {
|
|
3
|
+
const errors = [];
|
|
4
|
+
if (!payload.id || typeof payload.id !== 'string') {
|
|
5
|
+
errors.push('响应缺少有效的id字段');
|
|
6
|
+
}
|
|
7
|
+
if (!payload.created || typeof payload.created !== 'number') {
|
|
8
|
+
errors.push('响应缺少有效的created字段');
|
|
9
|
+
}
|
|
10
|
+
if (!payload.model || typeof payload.model !== 'string') {
|
|
11
|
+
errors.push('响应缺少有效的model字段');
|
|
12
|
+
}
|
|
13
|
+
if (!Array.isArray(payload.choices) || payload.choices.length === 0) {
|
|
14
|
+
errors.push('choices数组不能为空');
|
|
15
|
+
}
|
|
16
|
+
else {
|
|
17
|
+
payload.choices.forEach((choice, idx) => {
|
|
18
|
+
if (!isRecord(choice)) {
|
|
19
|
+
errors.push(`choices[${idx}]必须是对象`);
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
if (!choice.message || typeof choice.message !== 'object') {
|
|
23
|
+
errors.push(`choices[${idx}].message字段必须是对象`);
|
|
24
|
+
}
|
|
25
|
+
else if (Array.isArray(choice.message.tool_calls)) {
|
|
26
|
+
choice.message.tool_calls.forEach((toolCall, tIdx) => {
|
|
27
|
+
if (!isRecord(toolCall)) {
|
|
28
|
+
errors.push(`choices[${idx}].message.tool_calls[${tIdx}]必须是对象`);
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
if (!toolCall.function || typeof toolCall.function !== 'object') {
|
|
32
|
+
errors.push(`choices[${idx}].message.tool_calls[${tIdx}].function字段必须是对象`);
|
|
33
|
+
return;
|
|
34
|
+
}
|
|
35
|
+
const fn = toolCall.function;
|
|
36
|
+
if (typeof fn.name !== 'string') {
|
|
37
|
+
errors.push(`choices[${idx}].message.tool_calls[${tIdx}].function.name字段必须是字符串`);
|
|
38
|
+
}
|
|
39
|
+
if (typeof fn.arguments !== 'string') {
|
|
40
|
+
errors.push(`choices[${idx}].message.tool_calls[${tIdx}].function.arguments字段必须是字符串`);
|
|
41
|
+
}
|
|
42
|
+
else {
|
|
43
|
+
try {
|
|
44
|
+
JSON.parse(fn.arguments);
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
errors.push(`choices[${idx}].message.tool_calls[${tIdx}].function.arguments必须是有效JSON`);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
if (payload.usage && typeof payload.usage === 'object') {
|
|
55
|
+
const usage = payload.usage;
|
|
56
|
+
const promptTokens = usage.prompt_tokens;
|
|
57
|
+
const completionTokens = usage.completion_tokens;
|
|
58
|
+
const totalTokens = usage.total_tokens;
|
|
59
|
+
if (!isNonNegativeNumber(promptTokens) ||
|
|
60
|
+
!isNonNegativeNumber(completionTokens) ||
|
|
61
|
+
!isNonNegativeNumber(totalTokens)) {
|
|
62
|
+
errors.push('usage字段的token必须是非负数');
|
|
63
|
+
}
|
|
64
|
+
else if (promptTokens + completionTokens !== totalTokens) {
|
|
65
|
+
errors.push('usage.total_tokens 应等于 prompt_tokens 与 completion_tokens 之和');
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
if (errors.length) {
|
|
69
|
+
const error = new Error(`GLM响应校验失败:\n${errors.join('\n')}`);
|
|
70
|
+
error.code = 'compat_response_validation_failed';
|
|
71
|
+
throw error;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
function isNonNegativeNumber(value) {
|
|
75
|
+
return typeof value === 'number' && Number.isFinite(value) && value >= 0;
|
|
76
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { writeSnapshotViaHooks } from '../../shared/snapshot-hooks.js';
|
|
2
|
+
const SNAPSHOT_FLAG = String(process.env.ROUTECODEX_SNAPSHOT ?? '').toLowerCase();
|
|
3
|
+
const SNAPSHOT_ENABLED = SNAPSHOT_FLAG === '1' || SNAPSHOT_FLAG === 'true';
|
|
4
|
+
export async function writeCompatSnapshot(options) {
|
|
5
|
+
if (!SNAPSHOT_ENABLED) {
|
|
6
|
+
return;
|
|
7
|
+
}
|
|
8
|
+
try {
|
|
9
|
+
const endpoint = options.entryEndpoint || '/v1/chat/completions';
|
|
10
|
+
await writeSnapshotViaHooks({
|
|
11
|
+
endpoint,
|
|
12
|
+
stage: options.phase,
|
|
13
|
+
requestId: options.requestId || 'unknown',
|
|
14
|
+
data: options.data,
|
|
15
|
+
verbosity: 'verbose'
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
catch {
|
|
19
|
+
// snapshots are best-effort
|
|
20
|
+
}
|
|
21
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { JsonObject } from '../../hub/types/json.js';
|
|
2
|
+
type UnknownRecord = Record<string, unknown>;
|
|
3
|
+
export declare const sanitizeGLMToolsSchema: (data: UnknownRecord) => UnknownRecord;
|
|
4
|
+
export declare const sanitizeGLMToolsSchemaInPlace: (data: UnknownRecord) => void;
|
|
5
|
+
export declare function sanitizeToolSchema(payload: JsonObject, mode?: 'glm_shell'): JsonObject;
|
|
6
|
+
export {};
|
|
@@ -83,4 +83,9 @@ export const sanitizeGLMToolsSchemaInPlace = (data) => {
|
|
|
83
83
|
const sanitized = sanitizeGLMToolsSchema(data);
|
|
84
84
|
data.tools = sanitized.tools;
|
|
85
85
|
};
|
|
86
|
-
|
|
86
|
+
export function sanitizeToolSchema(payload, mode = 'glm_shell') {
|
|
87
|
+
if (mode === 'glm_shell') {
|
|
88
|
+
return sanitizeGLMToolsSchema(payload);
|
|
89
|
+
}
|
|
90
|
+
return payload;
|
|
91
|
+
}
|