@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.
Files changed (431) hide show
  1. package/README.md +18 -15
  2. package/dist/build-info.js +3 -3
  3. package/dist/build-info.js.map +1 -1
  4. package/dist/cli.js +94 -0
  5. package/dist/cli.js.map +1 -1
  6. package/dist/client/gemini-cli/gemini-cli-protocol-client.js +28 -5
  7. package/dist/client/gemini-cli/gemini-cli-protocol-client.js.map +1 -1
  8. package/dist/commands/token-daemon.d.ts +2 -0
  9. package/dist/commands/token-daemon.js +183 -0
  10. package/dist/commands/token-daemon.js.map +1 -0
  11. package/dist/error-handling/quiet-error-handling-center.d.ts +9 -0
  12. package/dist/error-handling/quiet-error-handling-center.js +141 -0
  13. package/dist/error-handling/quiet-error-handling-center.js.map +1 -0
  14. package/dist/error-handling/route-error-hub.js +8 -2
  15. package/dist/error-handling/route-error-hub.js.map +1 -1
  16. package/dist/index.js +4 -3
  17. package/dist/index.js.map +1 -1
  18. package/dist/modules/llmswitch/bridge.d.ts +1 -1
  19. package/dist/modules/llmswitch/bridge.js +3 -2
  20. package/dist/modules/llmswitch/bridge.js.map +1 -1
  21. package/dist/modules/pipeline/utils/colored-logger.d.ts +2 -0
  22. package/dist/modules/pipeline/utils/colored-logger.js +22 -3
  23. package/dist/modules/pipeline/utils/colored-logger.js.map +1 -1
  24. package/dist/providers/auth/antigravity-userinfo-helper.d.ts +10 -0
  25. package/dist/providers/auth/antigravity-userinfo-helper.js +140 -0
  26. package/dist/providers/auth/antigravity-userinfo-helper.js.map +1 -0
  27. package/dist/providers/auth/gemini-cli-userinfo-helper.js +12 -2
  28. package/dist/providers/auth/gemini-cli-userinfo-helper.js.map +1 -1
  29. package/dist/providers/auth/oauth-lifecycle.js +395 -24
  30. package/dist/providers/auth/oauth-lifecycle.js.map +1 -1
  31. package/dist/providers/auth/token-scanner/index.d.ts +32 -0
  32. package/dist/providers/auth/token-scanner/index.js +86 -0
  33. package/dist/providers/auth/token-scanner/index.js.map +1 -0
  34. package/dist/providers/auth/tokenfile-auth.d.ts +17 -0
  35. package/dist/providers/auth/tokenfile-auth.js +27 -5
  36. package/dist/providers/auth/tokenfile-auth.js.map +1 -1
  37. package/dist/providers/core/api/provider-types.d.ts +10 -0
  38. package/dist/providers/core/config/oauth-flows.d.ts +25 -0
  39. package/dist/providers/core/config/oauth-flows.js +92 -5
  40. package/dist/providers/core/config/oauth-flows.js.map +1 -1
  41. package/dist/providers/core/config/provider-oauth-configs.js +93 -2
  42. package/dist/providers/core/config/provider-oauth-configs.js.map +1 -1
  43. package/dist/providers/core/config/service-profiles.js +18 -10
  44. package/dist/providers/core/config/service-profiles.js.map +1 -1
  45. package/dist/providers/core/runtime/base-provider.d.ts +2 -0
  46. package/dist/providers/core/runtime/base-provider.js +135 -15
  47. package/dist/providers/core/runtime/base-provider.js.map +1 -1
  48. package/dist/providers/core/runtime/gemini-cli-http-provider.d.ts +8 -3
  49. package/dist/providers/core/runtime/gemini-cli-http-provider.js +332 -67
  50. package/dist/providers/core/runtime/gemini-cli-http-provider.js.map +1 -1
  51. package/dist/providers/core/runtime/http-request-executor.d.ts +1 -0
  52. package/dist/providers/core/runtime/http-request-executor.js +41 -1
  53. package/dist/providers/core/runtime/http-request-executor.js.map +1 -1
  54. package/dist/providers/core/runtime/http-transport-provider.d.ts +27 -0
  55. package/dist/providers/core/runtime/http-transport-provider.js +342 -69
  56. package/dist/providers/core/runtime/http-transport-provider.js.map +1 -1
  57. package/dist/providers/core/runtime/provider-error-classifier.d.ts +2 -2
  58. package/dist/providers/core/runtime/provider-error-classifier.js +14 -4
  59. package/dist/providers/core/runtime/provider-error-classifier.js.map +1 -1
  60. package/dist/providers/core/runtime/provider-factory.d.ts +1 -0
  61. package/dist/providers/core/runtime/provider-factory.js +37 -8
  62. package/dist/providers/core/runtime/provider-factory.js.map +1 -1
  63. package/dist/providers/core/runtime/responses-provider.d.ts +3 -3
  64. package/dist/providers/core/runtime/responses-provider.js +56 -117
  65. package/dist/providers/core/runtime/responses-provider.js.map +1 -1
  66. package/dist/providers/core/runtime/vision-debug-utils.d.ts +13 -0
  67. package/dist/providers/core/runtime/vision-debug-utils.js +114 -0
  68. package/dist/providers/core/runtime/vision-debug-utils.js.map +1 -0
  69. package/dist/providers/core/strategies/oauth-auth-code-flow.js +82 -25
  70. package/dist/providers/core/strategies/oauth-auth-code-flow.js.map +1 -1
  71. package/dist/providers/core/utils/http-client.d.ts +5 -0
  72. package/dist/providers/core/utils/http-client.js +31 -4
  73. package/dist/providers/core/utils/http-client.js.map +1 -1
  74. package/dist/providers/core/utils/provider-error-reporter.js +8 -2
  75. package/dist/providers/core/utils/provider-error-reporter.js.map +1 -1
  76. package/dist/providers/core/utils/snapshot-writer.d.ts +1 -1
  77. package/dist/providers/core/utils/snapshot-writer.js +5 -1
  78. package/dist/providers/core/utils/snapshot-writer.js.map +1 -1
  79. package/dist/providers/profile/provider-profile-loader.js +8 -4
  80. package/dist/providers/profile/provider-profile-loader.js.map +1 -1
  81. package/dist/runtime/runtime-flags.d.ts +4 -0
  82. package/dist/runtime/runtime-flags.js +32 -0
  83. package/dist/runtime/runtime-flags.js.map +1 -0
  84. package/dist/server/handlers/handler-utils.js +29 -2
  85. package/dist/server/handlers/handler-utils.js.map +1 -1
  86. package/dist/server/handlers/messages-handler.js +27 -26
  87. package/dist/server/handlers/messages-handler.js.map +1 -1
  88. package/dist/server/handlers/responses-handler.js +35 -1
  89. package/dist/server/handlers/responses-handler.js.map +1 -1
  90. package/dist/server/handlers/sse-dispatcher.js +22 -2
  91. package/dist/server/handlers/sse-dispatcher.js.map +1 -1
  92. package/dist/server/runtime/http-server/index.d.ts +10 -0
  93. package/dist/server/runtime/http-server/index.js +551 -148
  94. package/dist/server/runtime/http-server/index.js.map +1 -1
  95. package/dist/server/runtime/http-server/request-executor.d.ts +14 -0
  96. package/dist/server/runtime/http-server/request-executor.js +638 -149
  97. package/dist/server/runtime/http-server/request-executor.js.map +1 -1
  98. package/dist/server/runtime/http-server/routes.d.ts +5 -0
  99. package/dist/server/runtime/http-server/routes.js +69 -0
  100. package/dist/server/runtime/http-server/routes.js.map +1 -1
  101. package/dist/server/runtime/http-server/runtime-manager.js +18 -0
  102. package/dist/server/runtime/http-server/runtime-manager.js.map +1 -1
  103. package/dist/server/utils/sse-request-parser.d.ts +1 -0
  104. package/dist/server/utils/sse-request-parser.js +17 -6
  105. package/dist/server/utils/sse-request-parser.js.map +1 -1
  106. package/dist/server/utils/utf8-chunk-buffer.d.ts +43 -0
  107. package/dist/server/utils/utf8-chunk-buffer.js +132 -0
  108. package/dist/server/utils/utf8-chunk-buffer.js.map +1 -0
  109. package/dist/server/utils/warmup-detector.d.ts +7 -0
  110. package/dist/server/utils/warmup-detector.js +125 -0
  111. package/dist/server/utils/warmup-detector.js.map +1 -0
  112. package/dist/server/utils/warmup-storm-tracker.d.ts +9 -0
  113. package/dist/server/utils/warmup-storm-tracker.js +61 -0
  114. package/dist/server/utils/warmup-storm-tracker.js.map +1 -0
  115. package/dist/token-daemon/index.d.ts +7 -0
  116. package/dist/token-daemon/index.js +242 -0
  117. package/dist/token-daemon/index.js.map +1 -0
  118. package/dist/token-daemon/server-utils.d.ts +33 -0
  119. package/dist/token-daemon/server-utils.js +155 -0
  120. package/dist/token-daemon/server-utils.js.map +1 -0
  121. package/dist/token-daemon/token-daemon.d.ts +20 -0
  122. package/dist/token-daemon/token-daemon.js +144 -0
  123. package/dist/token-daemon/token-daemon.js.map +1 -0
  124. package/dist/token-daemon/token-types.d.ts +44 -0
  125. package/dist/token-daemon/token-types.js +18 -0
  126. package/dist/token-daemon/token-types.js.map +1 -0
  127. package/dist/token-daemon/token-utils.d.ts +17 -0
  128. package/dist/token-daemon/token-utils.js +153 -0
  129. package/dist/token-daemon/token-utils.js.map +1 -0
  130. package/dist/tools/semantic-replay.js +7 -6
  131. package/dist/tools/semantic-replay.js.map +1 -1
  132. package/dist/utils/debug-utils.js +14 -0
  133. package/dist/utils/debug-utils.js.map +1 -1
  134. package/dist/utils/error-handler-registry.d.ts +36 -0
  135. package/dist/utils/error-handler-registry.js +99 -12
  136. package/dist/utils/error-handler-registry.js.map +1 -1
  137. package/dist/utils/error-handling-utils.js +4 -3
  138. package/dist/utils/error-handling-utils.js.map +1 -1
  139. package/dist/utils/log-helpers.d.ts +6 -0
  140. package/dist/utils/log-helpers.js +90 -0
  141. package/dist/utils/log-helpers.js.map +1 -0
  142. package/dist/utils/logger.d.ts +8 -0
  143. package/dist/utils/logger.js +55 -2
  144. package/dist/utils/logger.js.map +1 -1
  145. package/dist/utils/snapshot-writer.js +2 -6
  146. package/dist/utils/snapshot-writer.js.map +1 -1
  147. package/node_modules/@jsonstudio/llms/README.md +2 -0
  148. package/node_modules/@jsonstudio/llms/dist/conversion/codecs/gemini-openai-codec.js +152 -6
  149. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/auto-thinking.d.ts +6 -0
  150. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/auto-thinking.js +25 -0
  151. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/field-mapping.d.ts +14 -0
  152. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/field-mapping.js +155 -0
  153. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/gemini-web-search.d.ts +17 -0
  154. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/gemini-web-search.js +68 -0
  155. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-image-content.d.ts +2 -0
  156. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-image-content.js +83 -0
  157. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-tool-extraction.d.ts +2 -0
  158. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-tool-extraction.js +264 -0
  159. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-vision-prompt.d.ts +11 -0
  160. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-vision-prompt.js +177 -0
  161. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-web-search.d.ts +2 -0
  162. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-web-search.js +63 -0
  163. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/qwen-transform.d.ts +3 -0
  164. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/qwen-transform.js +209 -0
  165. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/request-rules.d.ts +24 -0
  166. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/request-rules.js +63 -0
  167. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-blacklist.d.ts +14 -0
  168. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-blacklist.js +85 -0
  169. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-normalize.d.ts +5 -0
  170. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-normalize.js +121 -0
  171. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-validate.d.ts +5 -0
  172. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-validate.js +76 -0
  173. package/{dist/providers/compat/utils/snapshot-writer.d.ts → node_modules/@jsonstudio/llms/dist/conversion/compat/actions/snapshot.d.ts} +2 -2
  174. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/snapshot.js +21 -0
  175. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/tool-schema.d.ts +6 -0
  176. package/{dist/providers/compat/glm/utils/tool-schema-helpers.js → node_modules/@jsonstudio/llms/dist/conversion/compat/actions/tool-schema.js} +6 -1
  177. package/{dist/providers/compat/filters → node_modules/@jsonstudio/llms/dist/conversion/compat/actions}/universal-shape-filter.d.ts +17 -22
  178. package/{dist/providers/compat/filters → node_modules/@jsonstudio/llms/dist/conversion/compat/actions}/universal-shape-filter.js +46 -99
  179. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-gemini.json +17 -0
  180. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-glm.json +196 -13
  181. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-iflow.json +194 -26
  182. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-lmstudio.json +43 -35
  183. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-qwen.json +20 -16
  184. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/responses-c4m.json +42 -42
  185. package/node_modules/@jsonstudio/llms/dist/conversion/config/sample-config.json +1 -1
  186. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-engine.d.ts +7 -2
  187. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-engine.js +5 -665
  188. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.d.ts +9 -0
  189. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +869 -0
  190. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-types.d.ts +55 -0
  191. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/hub-pipeline.d.ts +2 -0
  192. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/hub-pipeline.js +74 -5
  193. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +2 -2
  194. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/target-utils.js +9 -0
  195. package/node_modules/@jsonstudio/llms/dist/conversion/hub/process/chat-process.js +213 -1
  196. package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/provider-response.d.ts +34 -0
  197. package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/provider-response.js +84 -24
  198. package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/response-runtime.js +19 -2
  199. package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/server-side-tools.d.ts +26 -0
  200. package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/server-side-tools.js +383 -0
  201. package/node_modules/@jsonstudio/llms/dist/conversion/hub/semantic-mappers/gemini-mapper.js +241 -14
  202. package/node_modules/@jsonstudio/llms/dist/conversion/hub/semantic-mappers/responses-mapper.js +17 -1
  203. package/node_modules/@jsonstudio/llms/dist/conversion/hub/standardized-bridge.js +14 -0
  204. package/node_modules/@jsonstudio/llms/dist/conversion/hub/types/standardized.d.ts +1 -0
  205. package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-host-policy.d.ts +6 -0
  206. package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-host-policy.js +14 -0
  207. package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-openai-bridge.js +133 -5
  208. package/node_modules/@jsonstudio/llms/dist/conversion/shared/anthropic-message-utils.js +98 -3
  209. package/node_modules/@jsonstudio/llms/dist/conversion/shared/bridge-message-utils.js +137 -10
  210. package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-output-builder.js +43 -2
  211. package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-reasoning-registry.d.ts +4 -0
  212. package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-reasoning-registry.js +62 -1
  213. package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-response-utils.js +23 -1
  214. package/node_modules/@jsonstudio/llms/dist/conversion/shared/snapshot-utils.js +17 -47
  215. package/node_modules/@jsonstudio/llms/dist/conversion/shared/tool-canonicalizer.d.ts +2 -0
  216. package/node_modules/@jsonstudio/llms/dist/conversion/shared/tool-filter-pipeline.js +12 -0
  217. package/node_modules/@jsonstudio/llms/dist/conversion/shared/tool-mapping.js +25 -2
  218. package/node_modules/@jsonstudio/llms/dist/index.d.ts +1 -0
  219. package/node_modules/@jsonstudio/llms/dist/index.js +1 -0
  220. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/bootstrap.js +540 -36
  221. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/classifier.js +12 -11
  222. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/context-advisor.d.ts +19 -0
  223. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/context-advisor.js +64 -0
  224. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/engine.d.ts +26 -0
  225. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/engine.js +450 -54
  226. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/features.js +23 -458
  227. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/health-manager.js +2 -7
  228. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/message-utils.d.ts +7 -0
  229. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/message-utils.js +78 -0
  230. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/provider-registry.js +7 -2
  231. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-counter.js +14 -3
  232. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-estimator.d.ts +2 -0
  233. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-estimator.js +16 -0
  234. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-file-scanner.d.ts +15 -0
  235. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-file-scanner.js +56 -0
  236. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/tool-signals.d.ts +13 -0
  237. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/tool-signals.js +403 -0
  238. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/types.d.ts +86 -2
  239. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/types.js +3 -1
  240. package/node_modules/@jsonstudio/llms/dist/servertool/engine.d.ts +27 -0
  241. package/node_modules/@jsonstudio/llms/dist/servertool/engine.js +60 -0
  242. package/node_modules/@jsonstudio/llms/dist/servertool/flow-types.d.ts +40 -0
  243. package/node_modules/@jsonstudio/llms/dist/servertool/flow-types.js +1 -0
  244. package/node_modules/@jsonstudio/llms/dist/servertool/handlers/vision.d.ts +1 -0
  245. package/node_modules/@jsonstudio/llms/dist/servertool/handlers/vision.js +194 -0
  246. package/node_modules/@jsonstudio/llms/dist/servertool/handlers/web-search.d.ts +1 -0
  247. package/node_modules/@jsonstudio/llms/dist/servertool/handlers/web-search.js +638 -0
  248. package/node_modules/@jsonstudio/llms/dist/servertool/orchestration-types.d.ts +33 -0
  249. package/node_modules/@jsonstudio/llms/dist/servertool/orchestration-types.js +1 -0
  250. package/node_modules/@jsonstudio/llms/dist/servertool/registry.d.ts +18 -0
  251. package/node_modules/@jsonstudio/llms/dist/servertool/registry.js +27 -0
  252. package/node_modules/@jsonstudio/llms/dist/servertool/server-side-tools.d.ts +8 -0
  253. package/node_modules/@jsonstudio/llms/dist/servertool/server-side-tools.js +208 -0
  254. package/node_modules/@jsonstudio/llms/dist/servertool/types.d.ts +88 -0
  255. package/node_modules/@jsonstudio/llms/dist/servertool/types.js +1 -0
  256. package/node_modules/@jsonstudio/llms/dist/servertool/vision-tool.d.ts +2 -0
  257. package/node_modules/@jsonstudio/llms/dist/servertool/vision-tool.js +185 -0
  258. package/node_modules/@jsonstudio/llms/dist/sse/json-to-sse/event-generators/responses.js +15 -3
  259. package/node_modules/@jsonstudio/llms/dist/sse/sse-to-json/builders/response-builder.js +6 -3
  260. package/node_modules/@jsonstudio/llms/dist/sse/sse-to-json/gemini-sse-to-json-converter.js +27 -1
  261. package/node_modules/@jsonstudio/llms/dist/sse/types/gemini-types.d.ts +20 -1
  262. package/node_modules/@jsonstudio/llms/dist/sse/types/responses-types.js +1 -1
  263. package/node_modules/@jsonstudio/llms/dist/telemetry/stats-center.d.ts +73 -0
  264. package/node_modules/@jsonstudio/llms/dist/telemetry/stats-center.js +280 -0
  265. package/node_modules/@jsonstudio/llms/package.json +2 -2
  266. package/package.json +11 -10
  267. package/scripts/README.md +26 -12
  268. package/scripts/auth-antigravity-token.mjs +64 -0
  269. package/scripts/auth-gemini-cli-token.mjs +96 -0
  270. package/scripts/auth-iflow-manual.mjs +81 -0
  271. package/scripts/auth-iflow-token-direct.mjs +87 -0
  272. package/scripts/auth-iflow-token.mjs +77 -0
  273. package/scripts/copy-compat-assets.mjs +3 -15
  274. package/scripts/install-verify.mjs +1 -0
  275. package/scripts/pack-mode.mjs +2 -1
  276. package/scripts/publish-rcc.mjs +20 -4
  277. package/scripts/replay-codex-sample.mjs +13 -8
  278. package/scripts/tests/chat-pipeline-blackbox.mjs +1 -1
  279. package/scripts/tests/virtual-router-health.mjs +141 -6
  280. package/scripts/tools/capture-provider-goldens.mjs +8 -7
  281. package/scripts/verify-client-headers.mjs +224 -0
  282. package/dist/providers/compat/base-compatibility.d.ts +0 -27
  283. package/dist/providers/compat/base-compatibility.js +0 -143
  284. package/dist/providers/compat/base-compatibility.js.map +0 -1
  285. package/dist/providers/compat/compat-directory-loader.d.ts +0 -4
  286. package/dist/providers/compat/compat-directory-loader.js +0 -85
  287. package/dist/providers/compat/compat-directory-loader.js.map +0 -1
  288. package/dist/providers/compat/compatibility-adapter.d.ts +0 -18
  289. package/dist/providers/compat/compatibility-adapter.js +0 -104
  290. package/dist/providers/compat/compatibility-adapter.js.map +0 -1
  291. package/dist/providers/compat/compatibility-factory.d.ts +0 -57
  292. package/dist/providers/compat/compatibility-factory.js +0 -155
  293. package/dist/providers/compat/compatibility-factory.js.map +0 -1
  294. package/dist/providers/compat/compatibility-interface.d.ts +0 -35
  295. package/dist/providers/compat/compatibility-interface.js +0 -2
  296. package/dist/providers/compat/compatibility-interface.js.map +0 -1
  297. package/dist/providers/compat/compatibility-manager.d.ts +0 -85
  298. package/dist/providers/compat/compatibility-manager.js +0 -368
  299. package/dist/providers/compat/compatibility-manager.js.map +0 -1
  300. package/dist/providers/compat/config/config-compatibility.d.ts +0 -28
  301. package/dist/providers/compat/config/config-compatibility.js +0 -95
  302. package/dist/providers/compat/config/config-compatibility.js.map +0 -1
  303. package/dist/providers/compat/field-mapping.d.ts +0 -102
  304. package/dist/providers/compat/field-mapping.js +0 -447
  305. package/dist/providers/compat/field-mapping.js.map +0 -1
  306. package/dist/providers/compat/filters/blacklist-sanitizer.d.ts +0 -45
  307. package/dist/providers/compat/filters/blacklist-sanitizer.js +0 -133
  308. package/dist/providers/compat/filters/blacklist-sanitizer.js.map +0 -1
  309. package/dist/providers/compat/filters/response-blacklist-sanitizer.d.ts +0 -28
  310. package/dist/providers/compat/filters/response-blacklist-sanitizer.js +0 -138
  311. package/dist/providers/compat/filters/response-blacklist-sanitizer.js.map +0 -1
  312. package/dist/providers/compat/filters/universal-shape-filter.js.map +0 -1
  313. package/dist/providers/compat/glm/config/blacklist-rules.json +0 -22
  314. package/dist/providers/compat/glm/config/field-mappings.json +0 -92
  315. package/dist/providers/compat/glm/config/response-blacklist.json +0 -7
  316. package/dist/providers/compat/glm/config/shape-filters.json +0 -37
  317. package/dist/providers/compat/glm/field-mapping/field-mapping-processor.d.ts +0 -28
  318. package/dist/providers/compat/glm/field-mapping/field-mapping-processor.js +0 -306
  319. package/dist/providers/compat/glm/field-mapping/field-mapping-processor.js.map +0 -1
  320. package/dist/providers/compat/glm/functions/glm-processor.d.ts +0 -50
  321. package/dist/providers/compat/glm/functions/glm-processor.js +0 -134
  322. package/dist/providers/compat/glm/functions/glm-processor.js.map +0 -1
  323. package/dist/providers/compat/glm/glm-compatibility.d.ts +0 -34
  324. package/dist/providers/compat/glm/glm-compatibility.js +0 -117
  325. package/dist/providers/compat/glm/glm-compatibility.js.map +0 -1
  326. package/dist/providers/compat/glm/hooks/base-hook.d.ts +0 -21
  327. package/dist/providers/compat/glm/hooks/base-hook.js +0 -53
  328. package/dist/providers/compat/glm/hooks/base-hook.js.map +0 -1
  329. package/dist/providers/compat/glm/hooks/glm-request-validation-hook.d.ts +0 -24
  330. package/dist/providers/compat/glm/hooks/glm-request-validation-hook.js +0 -268
  331. package/dist/providers/compat/glm/hooks/glm-request-validation-hook.js.map +0 -1
  332. package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.d.ts +0 -21
  333. package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.js +0 -171
  334. package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.js.map +0 -1
  335. package/dist/providers/compat/glm/hooks/glm-response-validation-hook.d.ts +0 -25
  336. package/dist/providers/compat/glm/hooks/glm-response-validation-hook.js +0 -236
  337. package/dist/providers/compat/glm/hooks/glm-response-validation-hook.js.map +0 -1
  338. package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.d.ts +0 -26
  339. package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.js +0 -186
  340. package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.js.map +0 -1
  341. package/dist/providers/compat/glm/index.d.ts +0 -24
  342. package/dist/providers/compat/glm/index.js +0 -29
  343. package/dist/providers/compat/glm/index.js.map +0 -1
  344. package/dist/providers/compat/glm/utils/tool-schema-helpers.d.ts +0 -3
  345. package/dist/providers/compat/glm/utils/tool-schema-helpers.js.map +0 -1
  346. package/dist/providers/compat/iflow/config/field-mappings.json +0 -92
  347. package/dist/providers/compat/iflow/config/shape-filters.json +0 -37
  348. package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.d.ts +0 -34
  349. package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.js +0 -386
  350. package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.js.map +0 -1
  351. package/dist/providers/compat/iflow/functions/iflow-processor.d.ts +0 -53
  352. package/dist/providers/compat/iflow/functions/iflow-processor.js +0 -215
  353. package/dist/providers/compat/iflow/functions/iflow-processor.js.map +0 -1
  354. package/dist/providers/compat/iflow/hooks/base-hook.d.ts +0 -23
  355. package/dist/providers/compat/iflow/hooks/base-hook.js +0 -59
  356. package/dist/providers/compat/iflow/hooks/base-hook.js.map +0 -1
  357. package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.d.ts +0 -23
  358. package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.js +0 -279
  359. package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.js.map +0 -1
  360. package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.d.ts +0 -20
  361. package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.js +0 -180
  362. package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.js.map +0 -1
  363. package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.d.ts +0 -23
  364. package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.js +0 -232
  365. package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.js.map +0 -1
  366. package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.d.ts +0 -25
  367. package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.js +0 -216
  368. package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.js.map +0 -1
  369. package/dist/providers/compat/iflow/iflow-compatibility.d.ts +0 -24
  370. package/dist/providers/compat/iflow/iflow-compatibility.js +0 -94
  371. package/dist/providers/compat/iflow/iflow-compatibility.js.map +0 -1
  372. package/dist/providers/compat/index.d.ts +0 -59
  373. package/dist/providers/compat/index.js +0 -83
  374. package/dist/providers/compat/index.js.map +0 -1
  375. package/dist/providers/compat/lmstudio-compatibility.d.ts +0 -44
  376. package/dist/providers/compat/lmstudio-compatibility.js +0 -193
  377. package/dist/providers/compat/lmstudio-compatibility.js.map +0 -1
  378. package/dist/providers/compat/passthrough-compatibility.d.ts +0 -29
  379. package/dist/providers/compat/passthrough-compatibility.js +0 -83
  380. package/dist/providers/compat/passthrough-compatibility.js.map +0 -1
  381. package/dist/providers/compat/profiles/chat/glm/index.d.ts +0 -6
  382. package/dist/providers/compat/profiles/chat/glm/index.js +0 -6
  383. package/dist/providers/compat/profiles/chat/glm/index.js.map +0 -1
  384. package/dist/providers/compat/profiles/chat/iflow/index.d.ts +0 -6
  385. package/dist/providers/compat/profiles/chat/iflow/index.js +0 -6
  386. package/dist/providers/compat/profiles/chat/iflow/index.js.map +0 -1
  387. package/dist/providers/compat/profiles/chat/lmstudio/index.d.ts +0 -6
  388. package/dist/providers/compat/profiles/chat/lmstudio/index.js +0 -6
  389. package/dist/providers/compat/profiles/chat/lmstudio/index.js.map +0 -1
  390. package/dist/providers/compat/profiles/chat/qwen/index.d.ts +0 -6
  391. package/dist/providers/compat/profiles/chat/qwen/index.js +0 -6
  392. package/dist/providers/compat/profiles/chat/qwen/index.js.map +0 -1
  393. package/dist/providers/compat/profiles/compat/passthrough/index.d.ts +0 -6
  394. package/dist/providers/compat/profiles/compat/passthrough/index.js +0 -6
  395. package/dist/providers/compat/profiles/compat/passthrough/index.js.map +0 -1
  396. package/dist/providers/compat/profiles/responses/c4m/index.d.ts +0 -6
  397. package/dist/providers/compat/profiles/responses/c4m/index.js +0 -6
  398. package/dist/providers/compat/profiles/responses/c4m/index.js.map +0 -1
  399. package/dist/providers/compat/profiles/responses/default/index.d.ts +0 -6
  400. package/dist/providers/compat/profiles/responses/default/index.js +0 -6
  401. package/dist/providers/compat/profiles/responses/default/index.js.map +0 -1
  402. package/dist/providers/compat/profiles/responses/fai/index.d.ts +0 -6
  403. package/dist/providers/compat/profiles/responses/fai/index.js +0 -6
  404. package/dist/providers/compat/profiles/responses/fai/index.js.map +0 -1
  405. package/dist/providers/compat/profiles/responses/fc/index.d.ts +0 -6
  406. package/dist/providers/compat/profiles/responses/fc/index.js +0 -6
  407. package/dist/providers/compat/profiles/responses/fc/index.js.map +0 -1
  408. package/dist/providers/compat/qwen/index.d.ts +0 -4
  409. package/dist/providers/compat/qwen/index.js +0 -6
  410. package/dist/providers/compat/qwen/index.js.map +0 -1
  411. package/dist/providers/compat/qwen-compatibility.d.ts +0 -52
  412. package/dist/providers/compat/qwen-compatibility.js +0 -330
  413. package/dist/providers/compat/qwen-compatibility.js.map +0 -1
  414. package/dist/providers/compat/register-compat-module.d.ts +0 -8
  415. package/dist/providers/compat/register-compat-module.js +0 -53
  416. package/dist/providers/compat/register-compat-module.js.map +0 -1
  417. package/dist/providers/compat/responses/c4m-responses-compatibility.d.ts +0 -27
  418. package/dist/providers/compat/responses/c4m-responses-compatibility.js +0 -197
  419. package/dist/providers/compat/responses/c4m-responses-compatibility.js.map +0 -1
  420. package/dist/providers/compat/standard-compatibility-utils.d.ts +0 -1
  421. package/dist/providers/compat/standard-compatibility-utils.js +0 -77
  422. package/dist/providers/compat/standard-compatibility-utils.js.map +0 -1
  423. package/dist/providers/compat/standard-compatibility.d.ts +0 -31
  424. package/dist/providers/compat/standard-compatibility.js +0 -118
  425. package/dist/providers/compat/standard-compatibility.js.map +0 -1
  426. package/dist/providers/compat/utils/snapshot-writer.js +0 -62
  427. package/dist/providers/compat/utils/snapshot-writer.js.map +0 -1
  428. package/dist/tools/replay-request.d.ts +0 -0
  429. package/dist/tools/replay-request.js +0 -2
  430. package/dist/tools/replay-request.js.map +0 -1
  431. 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,5 @@
1
+ import type { JsonObject } from '../../hub/types/json.js';
2
+ export interface ResponseNormalizeConfig {
3
+ finishReasonMap?: Record<string, string>;
4
+ }
5
+ export declare function normalizeResponsePayload(payload: JsonObject, config?: ResponseNormalizeConfig): JsonObject;
@@ -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,5 @@
1
+ import type { JsonObject } from '../../hub/types/json.js';
2
+ export interface ResponseValidateConfig {
3
+ strict?: boolean;
4
+ }
5
+ export declare function validateResponsePayload(payload: JsonObject, _config?: ResponseValidateConfig): void;
@@ -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
+ }
@@ -1,8 +1,8 @@
1
1
  type Phase = 'compat-pre' | 'compat-post';
2
2
  export declare function writeCompatSnapshot(options: {
3
3
  phase: Phase;
4
- requestId: string;
5
- data: unknown;
4
+ requestId?: string;
6
5
  entryEndpoint?: string;
6
+ data: unknown;
7
7
  }): Promise<void>;
8
8
  export {};
@@ -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
- //# sourceMappingURL=tool-schema-helpers.js.map
86
+ export function sanitizeToolSchema(payload, mode = 'glm_shell') {
87
+ if (mode === 'glm_shell') {
88
+ return sanitizeGLMToolsSchema(payload);
89
+ }
90
+ return payload;
91
+ }