@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,264 @@
|
|
|
1
|
+
function flattenContent(content, depth = 0) {
|
|
2
|
+
if (depth > 4 || content == null) {
|
|
3
|
+
return '';
|
|
4
|
+
}
|
|
5
|
+
if (typeof content === 'string') {
|
|
6
|
+
return content;
|
|
7
|
+
}
|
|
8
|
+
if (Array.isArray(content)) {
|
|
9
|
+
return content.map((entry) => flattenContent(entry, depth + 1)).join('');
|
|
10
|
+
}
|
|
11
|
+
if (typeof content === 'object') {
|
|
12
|
+
const record = content;
|
|
13
|
+
if (typeof record.text === 'string') {
|
|
14
|
+
return record.text;
|
|
15
|
+
}
|
|
16
|
+
if (record.content !== undefined) {
|
|
17
|
+
return flattenContent(record.content, depth + 1);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
return '';
|
|
21
|
+
}
|
|
22
|
+
const GLM_CUSTOM_TAG = /<tool_call(?:\s+name="([^"]+)")?>([\s\S]*?)<\/tool_call>/gi;
|
|
23
|
+
const GLM_TAGGED_SEQUENCE = /<tool_call(?:\s+name="([^"]+)")?\s*>([\s\S]*?)(?:<\/tool_call>|(?=<tool_call)|$)/gi;
|
|
24
|
+
const GLM_TAGGED_BLOCK = /<arg_key>([\s\S]*?)<\/arg_key>\s*<arg_value>([\s\S]*?)<\/arg_value>/gi;
|
|
25
|
+
const GLM_INLINE_NAME = /^[\s\r\n]*([A-Za-z0-9_.:-]+)/;
|
|
26
|
+
const GENERIC_PATTERNS = [
|
|
27
|
+
[
|
|
28
|
+
/```(?:tool|function|tool_call|function_call)?\s*([\s\S]*?)\s*```/gi,
|
|
29
|
+
(match) => ({ body: match[1] ?? '' })
|
|
30
|
+
],
|
|
31
|
+
[
|
|
32
|
+
/\[(tool_call|function_call)(?:\s+name="([^"]+)")?\]([\s\S]*?)\[\/\1\]/gi,
|
|
33
|
+
(match) => ({ body: match[3] ?? '', nameHint: match[2] })
|
|
34
|
+
],
|
|
35
|
+
[
|
|
36
|
+
/(tool_call|function_call)\s*[:=]\s*({[\s\S]+?})/gi,
|
|
37
|
+
(match) => ({ body: match[2] ?? '' })
|
|
38
|
+
]
|
|
39
|
+
];
|
|
40
|
+
export function extractGlmToolMarkup(root) {
|
|
41
|
+
const choicesRaw = root?.choices;
|
|
42
|
+
const choices = Array.isArray(choicesRaw) ? choicesRaw : [];
|
|
43
|
+
choices.forEach((choice, index) => {
|
|
44
|
+
if (!choice || typeof choice !== 'object') {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
const message = choice.message;
|
|
48
|
+
if (!message || typeof message !== 'object') {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const msgRecord = message;
|
|
52
|
+
const contentField = msgRecord.content;
|
|
53
|
+
const reasoningField = msgRecord.reasoning_content;
|
|
54
|
+
const text = contentField !== undefined
|
|
55
|
+
? flattenContent(contentField)
|
|
56
|
+
: typeof reasoningField === 'string'
|
|
57
|
+
? reasoningField
|
|
58
|
+
: '';
|
|
59
|
+
if (!text) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
const extraction = extractToolCallsFromText(text, index + 1);
|
|
63
|
+
if (!extraction) {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
if (extraction.toolCalls.length) {
|
|
67
|
+
msgRecord.tool_calls = extraction.toolCalls;
|
|
68
|
+
if (contentField !== undefined) {
|
|
69
|
+
msgRecord.content = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (extraction.reasoningText) {
|
|
73
|
+
msgRecord.reasoning_content = extraction.reasoningText;
|
|
74
|
+
}
|
|
75
|
+
else if ('reasoning_content' in msgRecord) {
|
|
76
|
+
delete msgRecord.reasoning_content;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
}
|
|
80
|
+
function extractToolCallsFromText(text, choiceIndex) {
|
|
81
|
+
const matches = [];
|
|
82
|
+
const applyPattern = (pattern, factory) => {
|
|
83
|
+
pattern.lastIndex = 0;
|
|
84
|
+
let exec;
|
|
85
|
+
while ((exec = pattern.exec(text))) {
|
|
86
|
+
const payload = factory(exec);
|
|
87
|
+
if (!payload)
|
|
88
|
+
continue;
|
|
89
|
+
const parsed = parseToolCall(payload.body, payload.nameHint);
|
|
90
|
+
if (!parsed)
|
|
91
|
+
continue;
|
|
92
|
+
matches.push({
|
|
93
|
+
start: exec.index,
|
|
94
|
+
end: exec.index + exec[0].length,
|
|
95
|
+
call: parsed
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
applyPattern(GLM_CUSTOM_TAG, (match) => ({ body: match[2] ?? '', nameHint: match[1] }));
|
|
100
|
+
for (const [pattern, factory] of GENERIC_PATTERNS) {
|
|
101
|
+
applyPattern(pattern, factory);
|
|
102
|
+
}
|
|
103
|
+
applyTaggedArgPatterns(text, matches);
|
|
104
|
+
if (!matches.length && typeof text === 'string' && text.includes('<arg_key>')) {
|
|
105
|
+
GLM_INLINE_NAME.lastIndex = 0;
|
|
106
|
+
const inline = GLM_INLINE_NAME.exec(text);
|
|
107
|
+
GLM_INLINE_NAME.lastIndex = 0;
|
|
108
|
+
if (inline && inline[1]) {
|
|
109
|
+
const name = inline[1].trim();
|
|
110
|
+
const block = text.slice(inline[0].length);
|
|
111
|
+
const argsRecord = parseTaggedArgBlock(block);
|
|
112
|
+
if (name && argsRecord) {
|
|
113
|
+
matches.push({
|
|
114
|
+
start: 0,
|
|
115
|
+
end: text.length,
|
|
116
|
+
call: {
|
|
117
|
+
name,
|
|
118
|
+
args: safeStringify(argsRecord)
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
matches.sort((a, b) => a.start - b.start);
|
|
125
|
+
const toolCalls = matches.map((entry, idx) => ({
|
|
126
|
+
id: `glm_tool_${choiceIndex}_${idx + 1}`,
|
|
127
|
+
type: 'function',
|
|
128
|
+
function: {
|
|
129
|
+
name: entry.call.name,
|
|
130
|
+
arguments: entry.call.args
|
|
131
|
+
}
|
|
132
|
+
}));
|
|
133
|
+
matches.sort((a, b) => b.start - a.start);
|
|
134
|
+
let cleaned = text;
|
|
135
|
+
for (const entry of matches) {
|
|
136
|
+
cleaned = cleaned.slice(0, entry.start) + cleaned.slice(entry.end);
|
|
137
|
+
}
|
|
138
|
+
const reasoningText = cleaned.trim();
|
|
139
|
+
return {
|
|
140
|
+
toolCalls,
|
|
141
|
+
reasoningText: reasoningText.length ? reasoningText : undefined
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function parseToolCall(body, nameHint) {
|
|
145
|
+
if (!body || typeof body !== 'string') {
|
|
146
|
+
return null;
|
|
147
|
+
}
|
|
148
|
+
const trimmed = body.trim();
|
|
149
|
+
if (!trimmed.length) {
|
|
150
|
+
return null;
|
|
151
|
+
}
|
|
152
|
+
try {
|
|
153
|
+
const parsed = JSON.parse(trimmed);
|
|
154
|
+
if (!parsed || typeof parsed !== 'object') {
|
|
155
|
+
return null;
|
|
156
|
+
}
|
|
157
|
+
const record = parsed;
|
|
158
|
+
const candidateName = (typeof record.name === 'string' && record.name.trim().length
|
|
159
|
+
? record.name.trim()
|
|
160
|
+
: undefined) ??
|
|
161
|
+
(typeof record.tool_name === 'string' && record.tool_name.trim().length
|
|
162
|
+
? record.tool_name.trim()
|
|
163
|
+
: undefined) ??
|
|
164
|
+
(typeof record.tool === 'string' && record.tool.trim().length
|
|
165
|
+
? record.tool.trim()
|
|
166
|
+
: undefined) ??
|
|
167
|
+
(nameHint && nameHint.trim().length ? nameHint.trim() : undefined);
|
|
168
|
+
if (!candidateName) {
|
|
169
|
+
return null;
|
|
170
|
+
}
|
|
171
|
+
const argsSource = record.arguments ??
|
|
172
|
+
record.input ??
|
|
173
|
+
record.params ??
|
|
174
|
+
record.parameters ??
|
|
175
|
+
record.payload ??
|
|
176
|
+
{};
|
|
177
|
+
let args = '{}';
|
|
178
|
+
if (typeof argsSource === 'string' && argsSource.trim().length) {
|
|
179
|
+
args = argsSource.trim();
|
|
180
|
+
}
|
|
181
|
+
else {
|
|
182
|
+
try {
|
|
183
|
+
args = JSON.stringify(argsSource ?? {});
|
|
184
|
+
}
|
|
185
|
+
catch {
|
|
186
|
+
args = '{}';
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
return { name: candidateName, args };
|
|
190
|
+
}
|
|
191
|
+
catch {
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
function applyTaggedArgPatterns(text, matches) {
|
|
196
|
+
if (!text || typeof text !== 'string') {
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
GLM_TAGGED_SEQUENCE.lastIndex = 0;
|
|
200
|
+
let exec;
|
|
201
|
+
while ((exec = GLM_TAGGED_SEQUENCE.exec(text))) {
|
|
202
|
+
let name = typeof exec[1] === 'string' ? exec[1].trim() : '';
|
|
203
|
+
let block = exec[2] ?? '';
|
|
204
|
+
if (!name) {
|
|
205
|
+
const inline = GLM_INLINE_NAME.exec(block);
|
|
206
|
+
if (inline && inline[1]) {
|
|
207
|
+
name = inline[1].trim();
|
|
208
|
+
block = block.slice(inline[0].length);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
if (!name) {
|
|
212
|
+
continue;
|
|
213
|
+
}
|
|
214
|
+
const argsRecord = parseTaggedArgBlock(block);
|
|
215
|
+
if (!argsRecord) {
|
|
216
|
+
continue;
|
|
217
|
+
}
|
|
218
|
+
matches.push({
|
|
219
|
+
start: exec.index,
|
|
220
|
+
end: exec.index + exec[0].length,
|
|
221
|
+
call: {
|
|
222
|
+
name,
|
|
223
|
+
args: safeStringify(argsRecord)
|
|
224
|
+
}
|
|
225
|
+
});
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
function parseTaggedArgBlock(block) {
|
|
229
|
+
if (!block || typeof block !== 'string') {
|
|
230
|
+
return null;
|
|
231
|
+
}
|
|
232
|
+
const record = {};
|
|
233
|
+
GLM_TAGGED_BLOCK.lastIndex = 0;
|
|
234
|
+
let exec;
|
|
235
|
+
while ((exec = GLM_TAGGED_BLOCK.exec(block))) {
|
|
236
|
+
const key = typeof exec[1] === 'string' ? exec[1].trim() : '';
|
|
237
|
+
if (!key) {
|
|
238
|
+
continue;
|
|
239
|
+
}
|
|
240
|
+
const rawValue = typeof exec[2] === 'string' ? exec[2].trim() : '';
|
|
241
|
+
record[key] = coerceTaggedValue(rawValue);
|
|
242
|
+
}
|
|
243
|
+
return Object.keys(record).length ? record : null;
|
|
244
|
+
}
|
|
245
|
+
function coerceTaggedValue(raw) {
|
|
246
|
+
if (!raw) {
|
|
247
|
+
return '';
|
|
248
|
+
}
|
|
249
|
+
const trimmed = raw.trim();
|
|
250
|
+
try {
|
|
251
|
+
return JSON.parse(trimmed);
|
|
252
|
+
}
|
|
253
|
+
catch {
|
|
254
|
+
return trimmed;
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
function safeStringify(value) {
|
|
258
|
+
try {
|
|
259
|
+
return JSON.stringify(value ?? {});
|
|
260
|
+
}
|
|
261
|
+
catch {
|
|
262
|
+
return '{}';
|
|
263
|
+
}
|
|
264
|
+
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { JsonObject } from '../../hub/types/json.js';
|
|
2
|
+
/**
|
|
3
|
+
* GLM 4.6V 专用视觉提示裁剪:
|
|
4
|
+
* - 仅在 model 为 glm-4.6v 且存在携带图片的 user 消息时生效;
|
|
5
|
+
* - 丢弃原有 system 与历史对话,只保留一条新的 system + 一条 user;
|
|
6
|
+
* - system:要求模型以结构化 JSON 描述截图内容、标记(圈/箭头等)及其大致 bbox;
|
|
7
|
+
* - user:保留原始用户文字(如果有)+ 单一 image_url 块。
|
|
8
|
+
*
|
|
9
|
+
* 其他模型(包括 glm-4.7、Gemini 等)不受影响。
|
|
10
|
+
*/
|
|
11
|
+
export declare function applyGlmVisionPromptTransform(payload: JsonObject): JsonObject;
|
|
@@ -0,0 +1,177 @@
|
|
|
1
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2
|
+
function extractImageUrlFromPart(part) {
|
|
3
|
+
const imageUrlBlock = isRecord(part.image_url)
|
|
4
|
+
? part.image_url
|
|
5
|
+
: undefined;
|
|
6
|
+
let url;
|
|
7
|
+
if (imageUrlBlock && typeof imageUrlBlock.url === 'string') {
|
|
8
|
+
url = imageUrlBlock.url;
|
|
9
|
+
}
|
|
10
|
+
else if (typeof part.image_url === 'string') {
|
|
11
|
+
url = part.image_url;
|
|
12
|
+
}
|
|
13
|
+
else if (typeof part.url === 'string') {
|
|
14
|
+
url = part.url;
|
|
15
|
+
}
|
|
16
|
+
else if (typeof part.uri === 'string') {
|
|
17
|
+
url = part.uri;
|
|
18
|
+
}
|
|
19
|
+
else if (typeof part.data === 'string') {
|
|
20
|
+
url = part.data;
|
|
21
|
+
}
|
|
22
|
+
const trimmed = (url ?? '').trim();
|
|
23
|
+
return trimmed.length ? trimmed : null;
|
|
24
|
+
}
|
|
25
|
+
function collectUserTextFromMessage(msg) {
|
|
26
|
+
const content = msg.content;
|
|
27
|
+
if (!Array.isArray(content)) {
|
|
28
|
+
if (typeof content === 'string') {
|
|
29
|
+
return content;
|
|
30
|
+
}
|
|
31
|
+
return '';
|
|
32
|
+
}
|
|
33
|
+
const parts = [];
|
|
34
|
+
for (const entry of content) {
|
|
35
|
+
if (!isRecord(entry))
|
|
36
|
+
continue;
|
|
37
|
+
const text = entry.text;
|
|
38
|
+
if (typeof text === 'string' && text.trim().length) {
|
|
39
|
+
parts.push(text.trim());
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return parts.join('\n');
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* GLM 4.6V 专用视觉提示裁剪:
|
|
46
|
+
* - 仅在 model 为 glm-4.6v 且存在携带图片的 user 消息时生效;
|
|
47
|
+
* - 丢弃原有 system 与历史对话,只保留一条新的 system + 一条 user;
|
|
48
|
+
* - system:要求模型以结构化 JSON 描述截图内容、标记(圈/箭头等)及其大致 bbox;
|
|
49
|
+
* - user:保留原始用户文字(如果有)+ 单一 image_url 块。
|
|
50
|
+
*
|
|
51
|
+
* 其他模型(包括 glm-4.7、Gemini 等)不受影响。
|
|
52
|
+
*/
|
|
53
|
+
export function applyGlmVisionPromptTransform(payload) {
|
|
54
|
+
const root = structuredClone(payload);
|
|
55
|
+
const modelRaw = root.model;
|
|
56
|
+
const model = typeof modelRaw === 'string' ? modelRaw.trim() : '';
|
|
57
|
+
if (!model.startsWith('glm-4.6v')) {
|
|
58
|
+
return root;
|
|
59
|
+
}
|
|
60
|
+
const messagesValue = root.messages;
|
|
61
|
+
if (!Array.isArray(messagesValue)) {
|
|
62
|
+
return root;
|
|
63
|
+
}
|
|
64
|
+
const messages = messagesValue.filter((msg) => isRecord(msg));
|
|
65
|
+
if (!messages.length) {
|
|
66
|
+
return root;
|
|
67
|
+
}
|
|
68
|
+
// 从末尾开始查找最近一条带图片的 user 消息。
|
|
69
|
+
let latestUserWithImage = null;
|
|
70
|
+
let imageUrl = null;
|
|
71
|
+
for (let i = messages.length - 1; i >= 0; i -= 1) {
|
|
72
|
+
const msg = messages[i];
|
|
73
|
+
const role = typeof msg.role === 'string' ? msg.role.toLowerCase() : '';
|
|
74
|
+
if (role !== 'user') {
|
|
75
|
+
continue;
|
|
76
|
+
}
|
|
77
|
+
const content = msg.content;
|
|
78
|
+
if (!Array.isArray(content)) {
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
for (const part of content) {
|
|
82
|
+
if (!isRecord(part))
|
|
83
|
+
continue;
|
|
84
|
+
const typeValue = typeof part.type === 'string' ? part.type.toLowerCase() : '';
|
|
85
|
+
if (typeValue === 'image' || typeValue === 'image_url' || typeValue === 'input_image') {
|
|
86
|
+
const candidateUrl = extractImageUrlFromPart(part);
|
|
87
|
+
if (candidateUrl) {
|
|
88
|
+
latestUserWithImage = msg;
|
|
89
|
+
imageUrl = candidateUrl;
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
if (latestUserWithImage && imageUrl) {
|
|
95
|
+
break;
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (!latestUserWithImage || !imageUrl) {
|
|
99
|
+
return root;
|
|
100
|
+
}
|
|
101
|
+
const systemContent = '你是 Codex 的截图理解子系统,专门用于分析 UI 截图和网页图片。请仅根据用户提供的图片,输出一个结构化的 JSON,用于后续自动化处理,不要输出额外解释性文字或自然语言说明。\n' +
|
|
102
|
+
'\n' +
|
|
103
|
+
'输出必须是**单个合法 JSON 对象**,不要包含 Markdown、代码块标记或多余文本。请严格遵循下面的结构(字段可以为空数组,但必须存在):\n' +
|
|
104
|
+
'{\n' +
|
|
105
|
+
' "summary": "用 1-3 句整体描述这张图片(例如页面类型、主要区域、核心信息)",\n' +
|
|
106
|
+
' "marks": [\n' +
|
|
107
|
+
' {\n' +
|
|
108
|
+
' "type": "circle | arrow | underline | box | other",\n' +
|
|
109
|
+
' "color": "red | green | blue | yellow | other",\n' +
|
|
110
|
+
' "bbox": [x, y, width, height],\n' +
|
|
111
|
+
' "description": "该标记所圈出/指向/强调的内容,包含相关文字或 UI 元素描述"\n' +
|
|
112
|
+
' }\n' +
|
|
113
|
+
' ],\n' +
|
|
114
|
+
' "regions": [\n' +
|
|
115
|
+
' {\n' +
|
|
116
|
+
' "bbox": [x, y, width, height],\n' +
|
|
117
|
+
' "description": "该区域的可见内容(控件/图标/布局,以及其中出现的所有清晰可辨的文字)",\n' +
|
|
118
|
+
' "is_marked": true | false\n' +
|
|
119
|
+
' }\n' +
|
|
120
|
+
' ],\n' +
|
|
121
|
+
' "metadata": {\n' +
|
|
122
|
+
' "image_size_hint": "如果能推断出大致分辨率,请给出类似 1920x1080 的字符串;无法判断时用 null",\n' +
|
|
123
|
+
' "screenshot": true\n' +
|
|
124
|
+
' }\n' +
|
|
125
|
+
'}\n' +
|
|
126
|
+
'\n' +
|
|
127
|
+
'细则:\n' +
|
|
128
|
+
'1. 文字提取要求:\n' +
|
|
129
|
+
' - 如果图片中存在清晰可辨的文字(包括标题、菜单、按钮、标签、提示信息、弹窗、错误信息等),必须在对应的 regions.description 中**完整抄写**这些文字,按自然阅读顺序组织,避免遗漏。\n' +
|
|
130
|
+
' - 如果有多行文字,可以用换行符分隔,但仍放在同一个 description 字段中。\n' +
|
|
131
|
+
' - 对确实无法看清的文字,用类似 "(模糊,无法辨认)" 标注即可;没有任何文字也视为正常情况,此时只需描述界面结构。\n' +
|
|
132
|
+
'2. 标记识别(marks):\n' +
|
|
133
|
+
' - 对所有明显的圈选、箭头、下划线、高亮框等标记,必须在 marks 中列出,每一项提供大致 bbox、颜色和简短说明,说明其强调或指向的内容。\n' +
|
|
134
|
+
'3. 区域划分(regions):\n' +
|
|
135
|
+
' - 将截图拆分为若干有意义的区域:如导航栏、侧边栏、主内容区、弹窗、对话框、表格、代码块、表单等。\n' +
|
|
136
|
+
' - 每个区域的 description 中,既要描述布局/控件类型,也要包含该区域内的全部清晰文字内容。\n' +
|
|
137
|
+
' - is_marked 为 true 表示该区域与某个标记(marks)相关或被标记强调。\n' +
|
|
138
|
+
'4. 坐标规范:所有 bbox 使用相对于当前图片的像素坐标,左上角为 (0,0),width/height 为正数近似值。\n' +
|
|
139
|
+
'5. 无论图片内容如何,最终回答必须是合法 JSON,不能在 JSON 前后添加任何额外文本。';
|
|
140
|
+
const systemMessage = {
|
|
141
|
+
role: 'system',
|
|
142
|
+
content: systemContent
|
|
143
|
+
};
|
|
144
|
+
const originalUserText = collectUserTextFromMessage(latestUserWithImage);
|
|
145
|
+
const userBlocks = [];
|
|
146
|
+
if (originalUserText && originalUserText.trim().length) {
|
|
147
|
+
userBlocks.push({
|
|
148
|
+
type: 'text',
|
|
149
|
+
text: originalUserText.trim()
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
else {
|
|
153
|
+
userBlocks.push({
|
|
154
|
+
type: 'text',
|
|
155
|
+
text: '请按照上面的 JSON 结构,详细描述这张图片的内容和标记。'
|
|
156
|
+
});
|
|
157
|
+
}
|
|
158
|
+
userBlocks.push({
|
|
159
|
+
type: 'image_url',
|
|
160
|
+
image_url: {
|
|
161
|
+
url: imageUrl
|
|
162
|
+
}
|
|
163
|
+
});
|
|
164
|
+
const userMessage = {
|
|
165
|
+
role: 'user',
|
|
166
|
+
content: userBlocks
|
|
167
|
+
};
|
|
168
|
+
// 丢弃原有 messages,仅保留新的 system + user。
|
|
169
|
+
root.messages = [systemMessage, userMessage];
|
|
170
|
+
// 对于专用视觉模型,限制 max_tokens,避免过大的 completion 预算进一步触发上下文相关错误。
|
|
171
|
+
const maxTokensValue = root.max_tokens;
|
|
172
|
+
if (typeof maxTokensValue === 'number' && Number.isFinite(maxTokensValue)) {
|
|
173
|
+
// 将超大值收敛到一个相对安全的上限;真实上限由上游再校验。
|
|
174
|
+
root.max_tokens = Math.min(maxTokensValue, 4096);
|
|
175
|
+
}
|
|
176
|
+
return root;
|
|
177
|
+
}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const isRecord = (value) => typeof value === 'object' && value !== null && !Array.isArray(value);
|
|
2
|
+
const DEBUG_GLM_WEB_SEARCH = (process.env.ROUTECODEX_DEBUG_GLM_WEB_SEARCH || '').trim() === '1';
|
|
3
|
+
export function applyGlmWebSearchRequestTransform(payload) {
|
|
4
|
+
const root = structuredClone(payload);
|
|
5
|
+
const webSearchRaw = root.web_search;
|
|
6
|
+
if (!isRecord(webSearchRaw)) {
|
|
7
|
+
return root;
|
|
8
|
+
}
|
|
9
|
+
const webSearch = webSearchRaw;
|
|
10
|
+
const queryValue = webSearch.query;
|
|
11
|
+
const recencyValue = webSearch.recency;
|
|
12
|
+
const countValue = webSearch.count;
|
|
13
|
+
const query = typeof queryValue === 'string' ? queryValue.trim() : '';
|
|
14
|
+
const recency = typeof recencyValue === 'string' ? recencyValue.trim() : undefined;
|
|
15
|
+
let count;
|
|
16
|
+
if (typeof countValue === 'number' && Number.isFinite(countValue)) {
|
|
17
|
+
const normalized = Math.floor(countValue);
|
|
18
|
+
if (normalized >= 1 && normalized <= 50) {
|
|
19
|
+
count = normalized;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
if (!query) {
|
|
23
|
+
// No meaningful search query, drop the helper object and passthrough.
|
|
24
|
+
delete root.web_search;
|
|
25
|
+
return root;
|
|
26
|
+
}
|
|
27
|
+
const webSearchConfig = {
|
|
28
|
+
// 按 GLM 文档要求:search_engine 为必填,默认使用 search_std。
|
|
29
|
+
search_engine: 'search_std',
|
|
30
|
+
enable: true,
|
|
31
|
+
search_query: query,
|
|
32
|
+
// 返回搜索结果详情,便于我们在响应中提取摘要或调试。
|
|
33
|
+
search_result: true
|
|
34
|
+
};
|
|
35
|
+
if (recency) {
|
|
36
|
+
webSearchConfig.search_recency_filter = recency;
|
|
37
|
+
}
|
|
38
|
+
if (typeof count === 'number') {
|
|
39
|
+
webSearchConfig.count = count;
|
|
40
|
+
}
|
|
41
|
+
// 根据 OpenAPI:tools.anyOf[*] = WebSearchToolSchema[],即一次只能选择一种工具类型。
|
|
42
|
+
// 在 web_search 路由下,我们只保留 WebSearchToolSchema,丢弃其它 function/retrieval/MCP 工具,
|
|
43
|
+
// 避免混用导致后端忽略 web_search 配置。
|
|
44
|
+
const baseTool = {
|
|
45
|
+
type: 'web_search',
|
|
46
|
+
web_search: webSearchConfig
|
|
47
|
+
};
|
|
48
|
+
root.tools = [baseTool];
|
|
49
|
+
delete root.web_search;
|
|
50
|
+
if (DEBUG_GLM_WEB_SEARCH) {
|
|
51
|
+
try {
|
|
52
|
+
// eslint-disable-next-line no-console
|
|
53
|
+
console.log('\x1b[38;5;27m[compat][glm_web_search_request] applied web_search transform ' +
|
|
54
|
+
`search_engine=${String(baseTool?.web_search?.search_engine ?? 'search_std')} ` +
|
|
55
|
+
`query=${JSON.stringify(query).slice(0, 200)} ` +
|
|
56
|
+
`count=${String(count ?? '')}\x1b[0m`);
|
|
57
|
+
}
|
|
58
|
+
catch {
|
|
59
|
+
// logging best-effort
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
return root;
|
|
63
|
+
}
|