@jsonstudio/rcc 0.89.164 → 0.89.333

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 (337) 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 +32 -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/error-handling/quiet-error-handling-center.d.ts +9 -0
  9. package/dist/error-handling/quiet-error-handling-center.js +141 -0
  10. package/dist/error-handling/quiet-error-handling-center.js.map +1 -0
  11. package/dist/error-handling/route-error-hub.js +8 -2
  12. package/dist/error-handling/route-error-hub.js.map +1 -1
  13. package/dist/modules/pipeline/utils/colored-logger.d.ts +2 -0
  14. package/dist/modules/pipeline/utils/colored-logger.js +20 -3
  15. package/dist/modules/pipeline/utils/colored-logger.js.map +1 -1
  16. package/dist/providers/auth/antigravity-userinfo-helper.d.ts +10 -0
  17. package/dist/providers/auth/antigravity-userinfo-helper.js +140 -0
  18. package/dist/providers/auth/antigravity-userinfo-helper.js.map +1 -0
  19. package/dist/providers/auth/oauth-lifecycle.js +140 -8
  20. package/dist/providers/auth/oauth-lifecycle.js.map +1 -1
  21. package/dist/providers/auth/token-scanner/index.d.ts +32 -0
  22. package/dist/providers/auth/token-scanner/index.js +86 -0
  23. package/dist/providers/auth/token-scanner/index.js.map +1 -0
  24. package/dist/providers/auth/tokenfile-auth.d.ts +17 -0
  25. package/dist/providers/auth/tokenfile-auth.js +27 -5
  26. package/dist/providers/auth/tokenfile-auth.js.map +1 -1
  27. package/dist/providers/core/api/provider-types.d.ts +10 -0
  28. package/dist/providers/core/config/oauth-flows.d.ts +2 -0
  29. package/dist/providers/core/config/oauth-flows.js.map +1 -1
  30. package/dist/providers/core/config/provider-oauth-configs.js +85 -0
  31. package/dist/providers/core/config/provider-oauth-configs.js.map +1 -1
  32. package/dist/providers/core/config/service-profiles.js +15 -1
  33. package/dist/providers/core/config/service-profiles.js.map +1 -1
  34. package/dist/providers/core/runtime/base-provider.d.ts +8 -1
  35. package/dist/providers/core/runtime/base-provider.js +176 -108
  36. package/dist/providers/core/runtime/base-provider.js.map +1 -1
  37. package/dist/providers/core/runtime/gemini-cli-http-provider.d.ts +9 -5
  38. package/dist/providers/core/runtime/gemini-cli-http-provider.js +271 -69
  39. package/dist/providers/core/runtime/gemini-cli-http-provider.js.map +1 -1
  40. package/dist/providers/core/runtime/gemini-http-provider.d.ts +1 -2
  41. package/dist/providers/core/runtime/gemini-http-provider.js +0 -12
  42. package/dist/providers/core/runtime/gemini-http-provider.js.map +1 -1
  43. package/dist/providers/core/runtime/http-request-executor.d.ts +42 -0
  44. package/dist/providers/core/runtime/http-request-executor.js +133 -0
  45. package/dist/providers/core/runtime/http-request-executor.js.map +1 -0
  46. package/dist/providers/core/runtime/http-transport-provider.d.ts +32 -12
  47. package/dist/providers/core/runtime/http-transport-provider.js +464 -426
  48. package/dist/providers/core/runtime/http-transport-provider.js.map +1 -1
  49. package/dist/providers/core/runtime/provider-error-classifier.d.ts +25 -0
  50. package/dist/providers/core/runtime/provider-error-classifier.js +149 -0
  51. package/dist/providers/core/runtime/provider-error-classifier.js.map +1 -0
  52. package/dist/providers/core/runtime/provider-error-types.d.ts +23 -0
  53. package/dist/providers/core/runtime/provider-error-types.js +2 -0
  54. package/dist/providers/core/runtime/provider-error-types.js.map +1 -0
  55. package/dist/providers/core/runtime/provider-factory.d.ts +1 -0
  56. package/dist/providers/core/runtime/provider-factory.js +43 -8
  57. package/dist/providers/core/runtime/provider-factory.js.map +1 -1
  58. package/dist/providers/core/runtime/responses-provider.d.ts +3 -3
  59. package/dist/providers/core/runtime/responses-provider.js +48 -114
  60. package/dist/providers/core/runtime/responses-provider.js.map +1 -1
  61. package/dist/providers/core/strategies/oauth-auth-code-flow.js +11 -3
  62. package/dist/providers/core/strategies/oauth-auth-code-flow.js.map +1 -1
  63. package/dist/providers/core/utils/http-client.d.ts +5 -0
  64. package/dist/providers/core/utils/http-client.js +29 -3
  65. package/dist/providers/core/utils/http-client.js.map +1 -1
  66. package/dist/providers/core/utils/provider-error-reporter.js +8 -2
  67. package/dist/providers/core/utils/provider-error-reporter.js.map +1 -1
  68. package/dist/providers/core/utils/snapshot-writer.js +5 -1
  69. package/dist/providers/core/utils/snapshot-writer.js.map +1 -1
  70. package/dist/providers/profile/provider-profile-loader.js +8 -4
  71. package/dist/providers/profile/provider-profile-loader.js.map +1 -1
  72. package/dist/runtime/runtime-flags.d.ts +4 -0
  73. package/dist/runtime/runtime-flags.js +32 -0
  74. package/dist/runtime/runtime-flags.js.map +1 -0
  75. package/dist/server/handlers/handler-utils.js +29 -2
  76. package/dist/server/handlers/handler-utils.js.map +1 -1
  77. package/dist/server/handlers/messages-handler.js +27 -26
  78. package/dist/server/handlers/messages-handler.js.map +1 -1
  79. package/dist/server/handlers/responses-handler.js +35 -1
  80. package/dist/server/handlers/responses-handler.js.map +1 -1
  81. package/dist/server/runtime/http-server/index.d.ts +1 -0
  82. package/dist/server/runtime/http-server/index.js +39 -4
  83. package/dist/server/runtime/http-server/index.js.map +1 -1
  84. package/dist/server/runtime/http-server/request-executor.d.ts +4 -0
  85. package/dist/server/runtime/http-server/request-executor.js +99 -4
  86. package/dist/server/runtime/http-server/request-executor.js.map +1 -1
  87. package/dist/server/utils/sse-request-parser.d.ts +1 -0
  88. package/dist/server/utils/sse-request-parser.js +17 -6
  89. package/dist/server/utils/sse-request-parser.js.map +1 -1
  90. package/dist/server/utils/warmup-detector.d.ts +7 -0
  91. package/dist/server/utils/warmup-detector.js +125 -0
  92. package/dist/server/utils/warmup-detector.js.map +1 -0
  93. package/dist/server/utils/warmup-storm-tracker.d.ts +9 -0
  94. package/dist/server/utils/warmup-storm-tracker.js +61 -0
  95. package/dist/server/utils/warmup-storm-tracker.js.map +1 -0
  96. package/dist/utils/debug-utils.js +14 -0
  97. package/dist/utils/debug-utils.js.map +1 -1
  98. package/dist/utils/error-handler-registry.js +6 -5
  99. package/dist/utils/error-handler-registry.js.map +1 -1
  100. package/dist/utils/error-handling-utils.js +4 -3
  101. package/dist/utils/error-handling-utils.js.map +1 -1
  102. package/dist/utils/log-helpers.d.ts +6 -0
  103. package/dist/utils/log-helpers.js +90 -0
  104. package/dist/utils/log-helpers.js.map +1 -0
  105. package/dist/utils/logger.d.ts +8 -0
  106. package/dist/utils/logger.js +55 -2
  107. package/dist/utils/logger.js.map +1 -1
  108. package/dist/utils/snapshot-writer.js +2 -6
  109. package/dist/utils/snapshot-writer.js.map +1 -1
  110. package/node_modules/@jsonstudio/llms/dist/conversion/codecs/gemini-openai-codec.js +15 -1
  111. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/auto-thinking.d.ts +6 -0
  112. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/auto-thinking.js +25 -0
  113. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/field-mapping.d.ts +14 -0
  114. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/field-mapping.js +155 -0
  115. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-tool-extraction.d.ts +2 -0
  116. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/glm-tool-extraction.js +264 -0
  117. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/qwen-transform.d.ts +3 -0
  118. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/qwen-transform.js +209 -0
  119. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/request-rules.d.ts +24 -0
  120. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/request-rules.js +63 -0
  121. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-blacklist.d.ts +14 -0
  122. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-blacklist.js +85 -0
  123. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-normalize.d.ts +5 -0
  124. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-normalize.js +121 -0
  125. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-validate.d.ts +5 -0
  126. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/response-validate.js +76 -0
  127. package/{dist/providers/compat/utils/snapshot-writer.d.ts → node_modules/@jsonstudio/llms/dist/conversion/compat/actions/snapshot.d.ts} +2 -2
  128. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/snapshot.js +21 -0
  129. package/node_modules/@jsonstudio/llms/dist/conversion/compat/actions/tool-schema.d.ts +6 -0
  130. package/{dist/providers/compat/glm/utils/tool-schema-helpers.js → node_modules/@jsonstudio/llms/dist/conversion/compat/actions/tool-schema.js} +6 -1
  131. package/{dist/providers/compat/filters → node_modules/@jsonstudio/llms/dist/conversion/compat/actions}/universal-shape-filter.d.ts +17 -22
  132. package/{dist/providers/compat/filters → node_modules/@jsonstudio/llms/dist/conversion/compat/actions}/universal-shape-filter.js +35 -99
  133. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-glm.json +187 -13
  134. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-iflow.json +177 -9
  135. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-lmstudio.json +10 -2
  136. package/node_modules/@jsonstudio/llms/dist/conversion/compat/profiles/chat-qwen.json +14 -10
  137. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-engine.d.ts +7 -2
  138. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-engine.js +5 -665
  139. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.d.ts +9 -0
  140. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +845 -0
  141. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/compat/compat-types.d.ts +47 -0
  142. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/hub-pipeline.d.ts +2 -0
  143. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/hub-pipeline.js +35 -1
  144. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +2 -2
  145. package/node_modules/@jsonstudio/llms/dist/conversion/hub/pipeline/target-utils.js +3 -0
  146. package/node_modules/@jsonstudio/llms/dist/conversion/hub/response/response-runtime.js +19 -2
  147. package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-host-policy.d.ts +6 -0
  148. package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-host-policy.js +14 -0
  149. package/node_modules/@jsonstudio/llms/dist/conversion/responses/responses-openai-bridge.js +51 -2
  150. package/node_modules/@jsonstudio/llms/dist/conversion/shared/anthropic-message-utils.js +6 -0
  151. package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-reasoning-registry.d.ts +4 -0
  152. package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-reasoning-registry.js +62 -1
  153. package/node_modules/@jsonstudio/llms/dist/conversion/shared/responses-response-utils.js +23 -1
  154. package/node_modules/@jsonstudio/llms/dist/conversion/shared/tool-canonicalizer.d.ts +2 -0
  155. package/node_modules/@jsonstudio/llms/dist/conversion/shared/tool-filter-pipeline.js +11 -0
  156. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/bootstrap.js +251 -12
  157. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/classifier.js +11 -4
  158. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/context-advisor.d.ts +21 -0
  159. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/context-advisor.js +76 -0
  160. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/engine.d.ts +11 -0
  161. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/engine.js +187 -28
  162. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/features.js +22 -457
  163. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/health-manager.js +2 -7
  164. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/message-utils.d.ts +7 -0
  165. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/message-utils.js +66 -0
  166. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/provider-registry.js +6 -2
  167. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-estimator.d.ts +2 -0
  168. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-estimator.js +16 -0
  169. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-file-scanner.d.ts +15 -0
  170. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/token-file-scanner.js +56 -0
  171. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/tool-signals.d.ts +13 -0
  172. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/tool-signals.js +403 -0
  173. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/types.d.ts +21 -1
  174. package/node_modules/@jsonstudio/llms/dist/router/virtual-router/types.js +1 -0
  175. package/node_modules/@jsonstudio/llms/package.json +2 -2
  176. package/package.json +13 -11
  177. package/scripts/README.md +26 -12
  178. package/scripts/auth-antigravity-token.mjs +64 -0
  179. package/scripts/auth-gemini-cli-token.mjs +96 -0
  180. package/scripts/auth-iflow-manual.mjs +81 -0
  181. package/scripts/auth-iflow-token-direct.mjs +87 -0
  182. package/scripts/auth-iflow-token.mjs +77 -0
  183. package/scripts/copy-compat-assets.mjs +3 -15
  184. package/scripts/install-verify.mjs +1 -0
  185. package/scripts/pack-mode.mjs +30 -1
  186. package/scripts/publish-rcc.mjs +31 -0
  187. package/scripts/replay-codex-sample.mjs +13 -8
  188. package/scripts/tests/chat-pipeline-blackbox.mjs +1 -1
  189. package/scripts/tools/capture-provider-goldens.mjs +8 -7
  190. package/scripts/verify-client-headers.mjs +224 -0
  191. package/dist/providers/compat/base-compatibility.d.ts +0 -27
  192. package/dist/providers/compat/base-compatibility.js +0 -143
  193. package/dist/providers/compat/base-compatibility.js.map +0 -1
  194. package/dist/providers/compat/compat-directory-loader.d.ts +0 -4
  195. package/dist/providers/compat/compat-directory-loader.js +0 -85
  196. package/dist/providers/compat/compat-directory-loader.js.map +0 -1
  197. package/dist/providers/compat/compatibility-adapter.d.ts +0 -18
  198. package/dist/providers/compat/compatibility-adapter.js +0 -104
  199. package/dist/providers/compat/compatibility-adapter.js.map +0 -1
  200. package/dist/providers/compat/compatibility-factory.d.ts +0 -57
  201. package/dist/providers/compat/compatibility-factory.js +0 -155
  202. package/dist/providers/compat/compatibility-factory.js.map +0 -1
  203. package/dist/providers/compat/compatibility-interface.d.ts +0 -35
  204. package/dist/providers/compat/compatibility-interface.js +0 -2
  205. package/dist/providers/compat/compatibility-interface.js.map +0 -1
  206. package/dist/providers/compat/compatibility-manager.d.ts +0 -85
  207. package/dist/providers/compat/compatibility-manager.js +0 -368
  208. package/dist/providers/compat/compatibility-manager.js.map +0 -1
  209. package/dist/providers/compat/config/config-compatibility.d.ts +0 -28
  210. package/dist/providers/compat/config/config-compatibility.js +0 -95
  211. package/dist/providers/compat/config/config-compatibility.js.map +0 -1
  212. package/dist/providers/compat/field-mapping.d.ts +0 -102
  213. package/dist/providers/compat/field-mapping.js +0 -447
  214. package/dist/providers/compat/field-mapping.js.map +0 -1
  215. package/dist/providers/compat/filters/blacklist-sanitizer.d.ts +0 -45
  216. package/dist/providers/compat/filters/blacklist-sanitizer.js +0 -133
  217. package/dist/providers/compat/filters/blacklist-sanitizer.js.map +0 -1
  218. package/dist/providers/compat/filters/response-blacklist-sanitizer.d.ts +0 -28
  219. package/dist/providers/compat/filters/response-blacklist-sanitizer.js +0 -138
  220. package/dist/providers/compat/filters/response-blacklist-sanitizer.js.map +0 -1
  221. package/dist/providers/compat/filters/universal-shape-filter.js.map +0 -1
  222. package/dist/providers/compat/glm/config/blacklist-rules.json +0 -22
  223. package/dist/providers/compat/glm/config/field-mappings.json +0 -92
  224. package/dist/providers/compat/glm/config/response-blacklist.json +0 -7
  225. package/dist/providers/compat/glm/config/shape-filters.json +0 -37
  226. package/dist/providers/compat/glm/field-mapping/field-mapping-processor.d.ts +0 -28
  227. package/dist/providers/compat/glm/field-mapping/field-mapping-processor.js +0 -306
  228. package/dist/providers/compat/glm/field-mapping/field-mapping-processor.js.map +0 -1
  229. package/dist/providers/compat/glm/functions/glm-processor.d.ts +0 -50
  230. package/dist/providers/compat/glm/functions/glm-processor.js +0 -134
  231. package/dist/providers/compat/glm/functions/glm-processor.js.map +0 -1
  232. package/dist/providers/compat/glm/glm-compatibility.d.ts +0 -34
  233. package/dist/providers/compat/glm/glm-compatibility.js +0 -117
  234. package/dist/providers/compat/glm/glm-compatibility.js.map +0 -1
  235. package/dist/providers/compat/glm/hooks/base-hook.d.ts +0 -21
  236. package/dist/providers/compat/glm/hooks/base-hook.js +0 -53
  237. package/dist/providers/compat/glm/hooks/base-hook.js.map +0 -1
  238. package/dist/providers/compat/glm/hooks/glm-request-validation-hook.d.ts +0 -24
  239. package/dist/providers/compat/glm/hooks/glm-request-validation-hook.js +0 -268
  240. package/dist/providers/compat/glm/hooks/glm-request-validation-hook.js.map +0 -1
  241. package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.d.ts +0 -21
  242. package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.js +0 -171
  243. package/dist/providers/compat/glm/hooks/glm-response-normalization-hook.js.map +0 -1
  244. package/dist/providers/compat/glm/hooks/glm-response-validation-hook.d.ts +0 -25
  245. package/dist/providers/compat/glm/hooks/glm-response-validation-hook.js +0 -236
  246. package/dist/providers/compat/glm/hooks/glm-response-validation-hook.js.map +0 -1
  247. package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.d.ts +0 -26
  248. package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.js +0 -186
  249. package/dist/providers/compat/glm/hooks/glm-tool-cleaning-hook.js.map +0 -1
  250. package/dist/providers/compat/glm/index.d.ts +0 -24
  251. package/dist/providers/compat/glm/index.js +0 -29
  252. package/dist/providers/compat/glm/index.js.map +0 -1
  253. package/dist/providers/compat/glm/utils/tool-schema-helpers.d.ts +0 -3
  254. package/dist/providers/compat/glm/utils/tool-schema-helpers.js.map +0 -1
  255. package/dist/providers/compat/iflow/config/field-mappings.json +0 -92
  256. package/dist/providers/compat/iflow/config/shape-filters.json +0 -37
  257. package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.d.ts +0 -34
  258. package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.js +0 -386
  259. package/dist/providers/compat/iflow/field-mapping/iflow-field-mapping-processor.js.map +0 -1
  260. package/dist/providers/compat/iflow/functions/iflow-processor.d.ts +0 -53
  261. package/dist/providers/compat/iflow/functions/iflow-processor.js +0 -215
  262. package/dist/providers/compat/iflow/functions/iflow-processor.js.map +0 -1
  263. package/dist/providers/compat/iflow/hooks/base-hook.d.ts +0 -23
  264. package/dist/providers/compat/iflow/hooks/base-hook.js +0 -59
  265. package/dist/providers/compat/iflow/hooks/base-hook.js.map +0 -1
  266. package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.d.ts +0 -23
  267. package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.js +0 -279
  268. package/dist/providers/compat/iflow/hooks/iflow-request-validation-hook.js.map +0 -1
  269. package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.d.ts +0 -20
  270. package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.js +0 -180
  271. package/dist/providers/compat/iflow/hooks/iflow-response-normalization-hook.js.map +0 -1
  272. package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.d.ts +0 -23
  273. package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.js +0 -232
  274. package/dist/providers/compat/iflow/hooks/iflow-response-validation-hook.js.map +0 -1
  275. package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.d.ts +0 -25
  276. package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.js +0 -216
  277. package/dist/providers/compat/iflow/hooks/iflow-tool-cleaning-hook.js.map +0 -1
  278. package/dist/providers/compat/iflow/iflow-compatibility.d.ts +0 -24
  279. package/dist/providers/compat/iflow/iflow-compatibility.js +0 -94
  280. package/dist/providers/compat/iflow/iflow-compatibility.js.map +0 -1
  281. package/dist/providers/compat/index.d.ts +0 -59
  282. package/dist/providers/compat/index.js +0 -83
  283. package/dist/providers/compat/index.js.map +0 -1
  284. package/dist/providers/compat/lmstudio-compatibility.d.ts +0 -44
  285. package/dist/providers/compat/lmstudio-compatibility.js +0 -193
  286. package/dist/providers/compat/lmstudio-compatibility.js.map +0 -1
  287. package/dist/providers/compat/passthrough-compatibility.d.ts +0 -29
  288. package/dist/providers/compat/passthrough-compatibility.js +0 -83
  289. package/dist/providers/compat/passthrough-compatibility.js.map +0 -1
  290. package/dist/providers/compat/profiles/chat/glm/index.d.ts +0 -6
  291. package/dist/providers/compat/profiles/chat/glm/index.js +0 -6
  292. package/dist/providers/compat/profiles/chat/glm/index.js.map +0 -1
  293. package/dist/providers/compat/profiles/chat/iflow/index.d.ts +0 -6
  294. package/dist/providers/compat/profiles/chat/iflow/index.js +0 -6
  295. package/dist/providers/compat/profiles/chat/iflow/index.js.map +0 -1
  296. package/dist/providers/compat/profiles/chat/lmstudio/index.d.ts +0 -6
  297. package/dist/providers/compat/profiles/chat/lmstudio/index.js +0 -6
  298. package/dist/providers/compat/profiles/chat/lmstudio/index.js.map +0 -1
  299. package/dist/providers/compat/profiles/chat/qwen/index.d.ts +0 -6
  300. package/dist/providers/compat/profiles/chat/qwen/index.js +0 -6
  301. package/dist/providers/compat/profiles/chat/qwen/index.js.map +0 -1
  302. package/dist/providers/compat/profiles/compat/passthrough/index.d.ts +0 -6
  303. package/dist/providers/compat/profiles/compat/passthrough/index.js +0 -6
  304. package/dist/providers/compat/profiles/compat/passthrough/index.js.map +0 -1
  305. package/dist/providers/compat/profiles/responses/c4m/index.d.ts +0 -6
  306. package/dist/providers/compat/profiles/responses/c4m/index.js +0 -6
  307. package/dist/providers/compat/profiles/responses/c4m/index.js.map +0 -1
  308. package/dist/providers/compat/profiles/responses/default/index.d.ts +0 -6
  309. package/dist/providers/compat/profiles/responses/default/index.js +0 -6
  310. package/dist/providers/compat/profiles/responses/default/index.js.map +0 -1
  311. package/dist/providers/compat/profiles/responses/fai/index.d.ts +0 -6
  312. package/dist/providers/compat/profiles/responses/fai/index.js +0 -6
  313. package/dist/providers/compat/profiles/responses/fai/index.js.map +0 -1
  314. package/dist/providers/compat/profiles/responses/fc/index.d.ts +0 -6
  315. package/dist/providers/compat/profiles/responses/fc/index.js +0 -6
  316. package/dist/providers/compat/profiles/responses/fc/index.js.map +0 -1
  317. package/dist/providers/compat/qwen/index.d.ts +0 -4
  318. package/dist/providers/compat/qwen/index.js +0 -6
  319. package/dist/providers/compat/qwen/index.js.map +0 -1
  320. package/dist/providers/compat/qwen-compatibility.d.ts +0 -52
  321. package/dist/providers/compat/qwen-compatibility.js +0 -330
  322. package/dist/providers/compat/qwen-compatibility.js.map +0 -1
  323. package/dist/providers/compat/register-compat-module.d.ts +0 -8
  324. package/dist/providers/compat/register-compat-module.js +0 -53
  325. package/dist/providers/compat/register-compat-module.js.map +0 -1
  326. package/dist/providers/compat/responses/c4m-responses-compatibility.d.ts +0 -27
  327. package/dist/providers/compat/responses/c4m-responses-compatibility.js +0 -197
  328. package/dist/providers/compat/responses/c4m-responses-compatibility.js.map +0 -1
  329. package/dist/providers/compat/standard-compatibility-utils.d.ts +0 -1
  330. package/dist/providers/compat/standard-compatibility-utils.js +0 -77
  331. package/dist/providers/compat/standard-compatibility-utils.js.map +0 -1
  332. package/dist/providers/compat/standard-compatibility.d.ts +0 -31
  333. package/dist/providers/compat/standard-compatibility.js +0 -118
  334. package/dist/providers/compat/standard-compatibility.js.map +0 -1
  335. package/dist/providers/compat/utils/snapshot-writer.js +0 -62
  336. package/dist/providers/compat/utils/snapshot-writer.js.map +0 -1
  337. package/scripts/check-glm-compat.mjs +0 -47
@@ -1,667 +1,7 @@
1
- import { getCompatProfile } from './compat-profile-store.js';
2
- const RATE_LIMIT_ERROR = 'ERR_COMPAT_RATE_LIMIT_DETECTED';
3
- export function applyRequestCompat(profileId, payload) {
4
- const profile = getCompatProfile(profileId);
5
- if (!profile) {
6
- return { payload };
7
- }
8
- const stage = pickStageConfig(profile, 'request');
9
- if (!stage) {
10
- return { payload };
11
- }
12
- const mutated = structuredClone(payload);
13
- if (Array.isArray(stage.mappings)) {
14
- for (const mapping of stage.mappings) {
15
- applyMapping(mutated, mapping);
16
- }
17
- }
18
- return {
19
- payload: mutated,
20
- appliedProfile: profile.id
21
- };
1
+ import { runRequestCompatPipeline, runResponseCompatPipeline } from './compat-pipeline-executor.js';
2
+ export function applyRequestCompat(profileId, payload, options) {
3
+ return runRequestCompatPipeline(profileId, payload, options);
22
4
  }
23
- export function applyResponseCompat(profileId, payload) {
24
- const profile = getCompatProfile(profileId);
25
- if (!profile) {
26
- return { payload };
27
- }
28
- const stage = pickStageConfig(profile, 'response');
29
- if (!stage) {
30
- return { payload };
31
- }
32
- const mutated = structuredClone(payload);
33
- if (Array.isArray(stage.mappings)) {
34
- for (const mapping of stage.mappings) {
35
- applyMapping(mutated, mapping);
36
- }
37
- }
38
- if (Array.isArray(stage.filters)) {
39
- for (const filter of stage.filters) {
40
- applyFilter(mutated, filter);
41
- }
42
- }
43
- return {
44
- payload: mutated,
45
- appliedProfile: profile.id
46
- };
47
- }
48
- function pickStageConfig(profile, stage) {
49
- if (!profile) {
50
- return null;
51
- }
52
- if (stage === 'request' && profile.request) {
53
- return profile.request;
54
- }
55
- if (stage === 'response' && profile.response) {
56
- return profile.response;
57
- }
58
- if (profile.direction && profile.direction !== stage) {
59
- return null;
60
- }
61
- if (profile.mappings || profile.filters) {
62
- return {
63
- mappings: profile.mappings,
64
- filters: profile.filters
65
- };
66
- }
67
- return null;
68
- }
69
- function applyMapping(root, mapping) {
70
- switch (mapping.action) {
71
- case 'remove':
72
- removePath(root, mapping.path);
73
- break;
74
- case 'rename':
75
- renamePath(root, mapping.from, mapping.to);
76
- break;
77
- case 'set':
78
- setPath(root, mapping.path, mapping.value);
79
- break;
80
- case 'stringify':
81
- stringifyPath(root, mapping.path, mapping.fallback);
82
- break;
83
- case 'parse_json':
84
- parseJsonPath(root, mapping.path, mapping.fallback);
85
- break;
86
- case 'set_default':
87
- setDefaultPath(root, mapping.path, mapping.value, mapping.valueSource);
88
- break;
89
- case 'normalize_tool_choice':
90
- normalizeToolChoice(root, mapping);
91
- break;
92
- case 'inject_instruction':
93
- injectInstruction(root, mapping);
94
- break;
95
- case 'convert_responses_output_to_choices':
96
- convertResponsesOutputToChoices(root);
97
- break;
98
- default:
99
- break;
100
- }
101
- }
102
- function applyFilter(payload, filter) {
103
- if (filter.action === 'rate_limit_text') {
104
- if (detectRateLimitText(payload, filter.needle)) {
105
- const err = new Error('Provider returned rate limit notice');
106
- err.code = RATE_LIMIT_ERROR;
107
- err.statusCode = 429;
108
- throw err;
109
- }
110
- }
111
- }
112
- function detectRateLimitText(payload, needle) {
113
- if (!needle || !payload) {
114
- return false;
115
- }
116
- const normalizedNeedle = needle.toLowerCase();
117
- const stack = [payload];
118
- while (stack.length) {
119
- const current = stack.pop();
120
- if (typeof current === 'string') {
121
- if (current.toLowerCase().includes(normalizedNeedle)) {
122
- return true;
123
- }
124
- continue;
125
- }
126
- if (Array.isArray(current)) {
127
- for (const entry of current) {
128
- stack.push(entry);
129
- }
130
- continue;
131
- }
132
- if (isRecord(current)) {
133
- for (const value of Object.values(current)) {
134
- stack.push(value);
135
- }
136
- }
137
- }
138
- return false;
139
- }
140
- function parsePath(path) {
141
- if (!path || typeof path !== 'string') {
142
- return [];
143
- }
144
- return path
145
- .split('.')
146
- .map((segment) => segment.trim())
147
- .filter(Boolean)
148
- .map((segment) => {
149
- if (segment.endsWith('[*]')) {
150
- return {
151
- key: segment.slice(0, -3),
152
- wildcard: true
153
- };
154
- }
155
- return {
156
- key: segment,
157
- wildcard: false
158
- };
159
- });
160
- }
161
- function removePath(root, path) {
162
- const steps = parsePath(path);
163
- if (!steps.length) {
164
- return;
165
- }
166
- const parentSteps = steps.slice(0, -1);
167
- const finalStep = steps[steps.length - 1];
168
- const targets = resolveTargets(root, parentSteps);
169
- for (const target of targets) {
170
- if (isRecord(target) && finalStep && finalStep.key in target) {
171
- delete target[finalStep.key];
172
- }
173
- }
174
- }
175
- function renamePath(root, fromPath, toPath) {
176
- const value = getPathValue(root, fromPath);
177
- if (value === undefined) {
178
- return;
179
- }
180
- setPath(root, toPath, value);
181
- removePath(root, fromPath);
182
- }
183
- function setPath(root, path, value) {
184
- const steps = parsePath(path);
185
- if (!steps.length) {
186
- return;
187
- }
188
- let cursor = root;
189
- for (let i = 0; i < steps.length; i++) {
190
- const step = steps[i];
191
- if (step.wildcard) {
192
- throw new Error(`Cannot set wildcard path: ${path}`);
193
- }
194
- if (i === steps.length - 1) {
195
- if (isRecord(cursor)) {
196
- cursor[step.key] = structuredClone(value);
197
- }
198
- }
199
- else {
200
- if (!isRecord(cursor[step.key])) {
201
- cursor[step.key] = {};
202
- }
203
- cursor = cursor[step.key];
204
- }
205
- }
206
- }
207
- function getPathValue(root, path) {
208
- const steps = parsePath(path);
209
- if (!steps.length) {
210
- return undefined;
211
- }
212
- let cursor = root;
213
- for (const step of steps) {
214
- if (step.wildcard) {
215
- if (!isRecord(cursor)) {
216
- return undefined;
217
- }
218
- const arr = cursor[step.key];
219
- if (!Array.isArray(arr) || !arr.length) {
220
- return undefined;
221
- }
222
- cursor = arr[0];
223
- continue;
224
- }
225
- if (!isRecord(cursor)) {
226
- return undefined;
227
- }
228
- cursor = cursor[step.key];
229
- if (cursor === undefined) {
230
- return undefined;
231
- }
232
- }
233
- return cursor;
234
- }
235
- function stringifyPath(root, path, fallback) {
236
- const steps = parsePath(path);
237
- if (!steps.length) {
238
- return;
239
- }
240
- const parentSteps = steps.slice(0, -1);
241
- const finalStep = steps[steps.length - 1];
242
- const targets = resolveTargets(root, parentSteps);
243
- for (const target of targets) {
244
- if (!isRecord(target) || !finalStep) {
245
- continue;
246
- }
247
- const current = target[finalStep.key];
248
- if (typeof current === 'string') {
249
- continue;
250
- }
251
- try {
252
- if (current === undefined) {
253
- target[finalStep.key] = JSON.stringify(fallback ?? {});
254
- }
255
- else {
256
- target[finalStep.key] = JSON.stringify(current);
257
- }
258
- }
259
- catch {
260
- try {
261
- target[finalStep.key] = JSON.stringify(fallback ?? {});
262
- }
263
- catch {
264
- target[finalStep.key] = '{}';
265
- }
266
- }
267
- }
268
- }
269
- function parseJsonPath(root, path, fallback) {
270
- const steps = parsePath(path);
271
- if (!steps.length) {
272
- return;
273
- }
274
- const parentSteps = steps.slice(0, -1);
275
- const finalStep = steps[steps.length - 1];
276
- const targets = resolveTargets(root, parentSteps);
277
- for (const target of targets) {
278
- if (!isRecord(target) || !finalStep) {
279
- continue;
280
- }
281
- const current = target[finalStep.key];
282
- if (current === undefined || current === null) {
283
- if (fallback !== undefined) {
284
- target[finalStep.key] = structuredClone(fallback);
285
- }
286
- continue;
287
- }
288
- if (typeof current !== 'string') {
289
- continue;
290
- }
291
- const trimmed = current.trim();
292
- if (!trimmed) {
293
- if (fallback !== undefined) {
294
- target[finalStep.key] = structuredClone(fallback);
295
- }
296
- continue;
297
- }
298
- try {
299
- target[finalStep.key] = JSON.parse(trimmed);
300
- }
301
- catch {
302
- if (fallback !== undefined) {
303
- target[finalStep.key] = structuredClone(fallback);
304
- }
305
- }
306
- }
307
- }
308
- function setDefaultPath(root, path, value, source) {
309
- const current = getPathValue(root, path);
310
- if (current !== undefined) {
311
- return;
312
- }
313
- let finalValue = value;
314
- if (source === 'timestamp_seconds') {
315
- finalValue = Math.floor(Date.now() / 1000);
316
- }
317
- else if (source === 'chat_completion_id') {
318
- finalValue = `chatcmpl_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`;
319
- }
320
- if (finalValue === undefined) {
321
- return;
322
- }
323
- setPath(root, path, finalValue);
324
- }
325
- function normalizeToolChoice(root, mapping) {
326
- const path = mapping.path || 'tool_choice';
327
- const current = getPathValue(root, path);
328
- if (!current || typeof current !== 'object' || Array.isArray(current)) {
329
- return;
330
- }
331
- const replacement = mapping.objectReplacement ?? 'required';
332
- setPath(root, path, replacement);
333
- }
334
- function injectInstruction(root, mapping) {
335
- const raw = getPathValue(root, mapping.sourcePath);
336
- removePath(root, mapping.sourcePath);
337
- const value = typeof raw === 'string' ? raw.trim() : '';
338
- if (!value) {
339
- return;
340
- }
341
- let text = value;
342
- if (mapping.stripHtml) {
343
- text = stripHtml(text);
344
- }
345
- const maxLength = resolveMaxLength(mapping.maxLengthEnv);
346
- if (maxLength && text.length > maxLength) {
347
- text = text.slice(0, maxLength);
348
- }
349
- if (!text) {
350
- return;
351
- }
352
- const targetPath = mapping.targetPath || 'input';
353
- const targetArray = ensureArray(root, targetPath);
354
- const message = {
355
- type: 'message',
356
- role: mapping.role || 'system',
357
- content: [
358
- {
359
- type: mapping.contentType || 'input_text',
360
- text
361
- }
362
- ]
363
- };
364
- targetArray.unshift(message);
365
- }
366
- function resolveTargets(root, steps) {
367
- if (!steps.length) {
368
- return [root];
369
- }
370
- const results = [];
371
- const traverse = (node, index) => {
372
- const step = steps[index];
373
- if (!step || !isRecord(node)) {
374
- return;
375
- }
376
- const next = node[step.key];
377
- if (step.wildcard && Array.isArray(next)) {
378
- if (index === steps.length - 1) {
379
- for (const child of next) {
380
- if (isRecord(child)) {
381
- results.push(child);
382
- }
383
- }
384
- }
385
- else {
386
- for (const child of next) {
387
- traverse(child, index + 1);
388
- }
389
- }
390
- return;
391
- }
392
- if (!step.wildcard && isRecord(next)) {
393
- if (index === steps.length - 1) {
394
- results.push(next);
395
- }
396
- else {
397
- traverse(next, index + 1);
398
- }
399
- }
400
- };
401
- traverse(root, 0);
402
- return results;
403
- }
404
- function isRecord(value) {
405
- return typeof value === 'object' && value !== null;
406
- }
407
- function ensureArray(root, path) {
408
- const steps = parsePath(path);
409
- if (!steps.length) {
410
- throw new Error(`Invalid array path: ${path}`);
411
- }
412
- let cursor = root;
413
- for (let i = 0; i < steps.length; i++) {
414
- const step = steps[i];
415
- if (step.wildcard) {
416
- throw new Error(`Array path does not support wildcards: ${path}`);
417
- }
418
- if (i === steps.length - 1) {
419
- if (!Array.isArray(cursor[step.key])) {
420
- cursor[step.key] = [];
421
- }
422
- if (!Array.isArray(cursor[step.key])) {
423
- cursor[step.key] = [];
424
- }
425
- return cursor[step.key];
426
- }
427
- if (!isRecord(cursor[step.key])) {
428
- cursor[step.key] = {};
429
- }
430
- cursor = cursor[step.key];
431
- }
432
- throw new Error(`Failed to resolve array path: ${path}`);
433
- }
434
- function stripHtml(value) {
435
- return value.replace(/<\/?[^>]+(>|$)/g, '');
436
- }
437
- function resolveMaxLength(envVars) {
438
- if (!envVars || !envVars.length) {
439
- return undefined;
440
- }
441
- for (const envName of envVars) {
442
- if (!envName)
443
- continue;
444
- const raw = process.env[envName];
445
- if (!raw) {
446
- continue;
447
- }
448
- const parsed = Number(raw);
449
- if (Number.isFinite(parsed) && parsed > 0) {
450
- return Math.floor(parsed);
451
- }
452
- }
453
- return undefined;
454
- }
455
- function convertResponsesOutputToChoices(root) {
456
- if (!isRecord(root)) {
457
- return;
458
- }
459
- const existingChoices = root.choices;
460
- if (Array.isArray(existingChoices) && existingChoices.length > 0) {
461
- return;
462
- }
463
- const choicesFromOutput = buildChoicesFromResponsesOutput(root);
464
- if (choicesFromOutput.length > 0) {
465
- root.choices = choicesFromOutput;
466
- return;
467
- }
468
- const fallbackText = extractOutputText(root);
469
- if (typeof fallbackText === 'string') {
470
- root.choices = [
471
- {
472
- index: 0,
473
- finish_reason: normalizeFinishReason(typeof root.status === 'string' ? root.status : 'stop'),
474
- message: {
475
- role: 'assistant',
476
- content: fallbackText
477
- }
478
- }
479
- ];
480
- }
481
- }
482
- function buildChoicesFromResponsesOutput(root) {
483
- const outputEntries = Array.isArray(root.output) ? root.output : [];
484
- const choices = [];
485
- outputEntries.forEach((entry) => {
486
- if (!isRecord(entry)) {
487
- return;
488
- }
489
- if ('type' in entry && typeof entry.type === 'string' && entry.type !== 'message') {
490
- return;
491
- }
492
- const choice = convertOutputEntryToChoice(entry, choices.length, root);
493
- if (choice) {
494
- choices.push(choice);
495
- }
496
- });
497
- return choices;
498
- }
499
- function convertOutputEntryToChoice(entry, index, root) {
500
- const message = buildMessageFromOutputEntry(entry, index);
501
- if (!message) {
502
- return null;
503
- }
504
- const finishReasonCandidate = (typeof entry.stop_reason === 'string' && entry.stop_reason) ||
505
- (typeof entry.finish_reason === 'string' && entry.finish_reason) ||
506
- (typeof entry.status === 'string' && entry.status) ||
507
- (typeof root.status === 'string' && root.status) ||
508
- 'stop';
509
- return {
510
- index,
511
- finish_reason: normalizeFinishReason(finishReasonCandidate),
512
- message
513
- };
514
- }
515
- function buildMessageFromOutputEntry(entry, choiceIndex) {
516
- const role = normalizeRole(typeof entry.role === 'string' ? entry.role : 'assistant');
517
- const contentArray = Array.isArray(entry.content) ? entry.content : [];
518
- const textSegments = [];
519
- const toolCalls = [];
520
- contentArray.forEach((part, partIndex) => {
521
- if (!isRecord(part)) {
522
- const fallback = coerceText(part);
523
- if (fallback) {
524
- textSegments.push(fallback);
525
- }
526
- return;
527
- }
528
- const type = typeof part.type === 'string'
529
- ? part.type
530
- : typeof part.content_type === 'string'
531
- ? part.content_type
532
- : '';
533
- switch (type) {
534
- case 'output_text': {
535
- const txt = typeof part.text === 'string'
536
- ? part.text
537
- : coerceText(part.text);
538
- if (txt) {
539
- textSegments.push(txt);
540
- }
541
- break;
542
- }
543
- case 'tool_call': {
544
- const normalized = normalizeToolCall(part, choiceIndex, toolCalls.length);
545
- if (normalized) {
546
- toolCalls.push(normalized);
547
- }
548
- break;
549
- }
550
- case 'input_text':
551
- case 'reasoning_content': {
552
- const txt = typeof part.text === 'string'
553
- ? part.text
554
- : coerceText(part.text);
555
- if (txt) {
556
- textSegments.push(txt);
557
- }
558
- break;
559
- }
560
- default: {
561
- const fallback = coerceText(part);
562
- if (fallback) {
563
- textSegments.push(fallback);
564
- }
565
- break;
566
- }
567
- }
568
- });
569
- const message = {
570
- role,
571
- content: textSegments.join('')
572
- };
573
- if (toolCalls.length) {
574
- message.tool_calls = toolCalls;
575
- if (typeof message.content !== 'string') {
576
- message.content = '';
577
- }
578
- }
579
- return message;
580
- }
581
- function normalizeToolCall(part, choiceIndex, callIndex) {
582
- const payload = isRecord(part.tool_call) ? part.tool_call : part;
583
- const fnPayload = isRecord(payload.function)
584
- ? payload.function
585
- : isRecord(part.function)
586
- ? part.function
587
- : null;
588
- const name = typeof fnPayload?.name === 'string' ? fnPayload.name : undefined;
589
- if (!name) {
590
- return null;
591
- }
592
- const rawArgs = fnPayload?.arguments;
593
- let argString;
594
- if (typeof rawArgs === 'string') {
595
- argString = rawArgs;
596
- }
597
- else {
598
- try {
599
- argString = JSON.stringify(rawArgs ?? {});
600
- }
601
- catch {
602
- argString = '{}';
603
- }
604
- }
605
- const idCandidate = (typeof payload.id === 'string' && payload.id) ||
606
- (typeof payload.tool_call_id === 'string'
607
- ? payload.tool_call_id
608
- : undefined) ||
609
- (typeof payload.call_id === 'string'
610
- ? payload.call_id
611
- : undefined);
612
- return {
613
- id: idCandidate || `call_${choiceIndex}_${callIndex}`,
614
- type: 'function',
615
- function: {
616
- name,
617
- arguments: argString
618
- }
619
- };
620
- }
621
- function extractOutputText(root) {
622
- const textCandidate = root.output_text;
623
- if (typeof textCandidate === 'string' && textCandidate.length > 0) {
624
- return textCandidate;
625
- }
626
- return undefined;
627
- }
628
- function normalizeRole(role) {
629
- const normalized = role.toLowerCase();
630
- if (normalized === 'assistant' || normalized === 'system' || normalized === 'user' || normalized === 'tool') {
631
- return normalized;
632
- }
633
- return 'assistant';
634
- }
635
- function coerceText(value) {
636
- if (typeof value === 'string') {
637
- return value;
638
- }
639
- if (typeof value === 'number' || typeof value === 'boolean') {
640
- return String(value);
641
- }
642
- if (Array.isArray(value)) {
643
- return value.map((entry) => coerceText(entry)).join('');
644
- }
645
- if (isRecord(value)) {
646
- try {
647
- return JSON.stringify(value);
648
- }
649
- catch {
650
- return '';
651
- }
652
- }
653
- return '';
654
- }
655
- function normalizeFinishReason(reason) {
656
- const normalized = reason.toLowerCase();
657
- if (normalized.includes('tool')) {
658
- return 'tool_calls';
659
- }
660
- if (normalized.includes('length') || normalized.includes('max_token') || normalized.includes('in_progress')) {
661
- return 'length';
662
- }
663
- if (normalized.includes('filter')) {
664
- return 'content_filter';
665
- }
666
- return 'stop';
5
+ export function applyResponseCompat(profileId, payload, options) {
6
+ return runResponseCompatPipeline(profileId, payload, options);
667
7
  }
@@ -0,0 +1,9 @@
1
+ import type { JsonObject } from '../../types/json.js';
2
+ import type { AdapterContext } from '../../types/chat-envelope.js';
3
+ import type { CompatApplicationResult } from './compat-types.js';
4
+ export declare function runRequestCompatPipeline(profileId: string | undefined, payload: JsonObject, options?: {
5
+ adapterContext?: AdapterContext;
6
+ }): CompatApplicationResult;
7
+ export declare function runResponseCompatPipeline(profileId: string | undefined, payload: JsonObject, options?: {
8
+ adapterContext?: AdapterContext;
9
+ }): CompatApplicationResult;