@jsonstudio/llms 0.6.2172 → 0.6.2979

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 (362) hide show
  1. package/README.md +2 -0
  2. package/dist/conversion/compat/antigravity-session-signature.js +35 -1
  3. package/dist/conversion/compat/profiles/chat-gemini-cli.json +0 -7
  4. package/dist/conversion/compat/profiles/chat-gemini.json +0 -6
  5. package/dist/conversion/hub/core/detour-registry.d.ts +2 -0
  6. package/dist/conversion/hub/core/hub-context.d.ts +3 -1
  7. package/dist/conversion/hub/core/index.d.ts +1 -0
  8. package/dist/conversion/hub/core/stage-driver.js +2 -0
  9. package/dist/conversion/hub/format-adapters/anthropic-format-adapter.js +15 -4
  10. package/dist/conversion/hub/format-adapters/chat-format-adapter.js +15 -4
  11. package/dist/conversion/hub/format-adapters/gemini-format-adapter.js +15 -4
  12. package/dist/conversion/hub/format-adapters/responses-format-adapter.js +15 -4
  13. package/dist/conversion/hub/hub-feature.js +3 -2
  14. package/dist/conversion/hub/node-support.js +9 -4
  15. package/dist/conversion/hub/operation-table/operation-table-runner.js +10 -6
  16. package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +2 -2
  17. package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +10 -10
  18. package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +4 -8
  19. package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +19 -65
  20. package/dist/conversion/hub/ops/operations.js +2 -121
  21. package/dist/conversion/hub/pipeline/compat/compat-engine.js +6 -0
  22. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.d.ts +1 -1
  23. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +33 -1042
  24. package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.js +2 -0
  25. package/dist/conversion/hub/pipeline/compat/compat-profile-store.js +2 -0
  26. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +14 -17
  27. package/dist/conversion/hub/pipeline/compat/native-adapter-context.d.ts +3 -0
  28. package/dist/conversion/hub/pipeline/compat/native-adapter-context.js +39 -0
  29. package/dist/conversion/hub/pipeline/hub-pipeline.js +115 -262
  30. package/dist/conversion/hub/pipeline/session-identifiers.js +6 -196
  31. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.d.ts +1 -2
  32. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js +37 -1
  33. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +12 -86
  34. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.d.ts +14 -0
  35. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.js +24 -0
  36. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.d.ts +2 -0
  37. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.js +157 -0
  38. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.d.ts +16 -0
  39. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.js +29 -0
  40. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-factories.js +3 -1
  41. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.d.ts +2 -15
  42. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +8 -595
  43. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.d.ts +8 -0
  44. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.js +28 -0
  45. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.d.ts +2 -0
  46. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.js +4 -0
  47. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.d.ts +10 -0
  48. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.js +12 -0
  49. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.d.ts +3 -0
  50. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.js +30 -0
  51. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +9 -129
  52. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.d.ts +1 -4
  53. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.js +9 -26
  54. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +32 -14
  55. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.d.ts +2 -2
  56. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +48 -8
  57. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +18 -3
  58. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +10 -198
  59. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.d.ts +3 -0
  60. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.js +81 -0
  61. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.d.ts +1 -2
  62. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.js +36 -1
  63. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_semantic_map/index.js +3 -1
  64. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.d.ts +6 -0
  65. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.js +17 -0
  66. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.d.ts +9 -0
  67. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.js +28 -0
  68. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.d.ts +1 -2
  69. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +14 -102
  70. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage2_sse_stream/index.js +3 -1
  71. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +12 -10
  72. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +6 -5
  73. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.d.ts +11 -1
  74. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.js +10 -32
  75. package/dist/conversion/hub/pipeline/stages/utils.js +17 -1
  76. package/dist/conversion/hub/pipeline/target-utils.js +14 -91
  77. package/dist/conversion/hub/pipelines/inbound.js +3 -1
  78. package/dist/conversion/hub/pipelines/outbound.js +2 -0
  79. package/dist/conversion/hub/policy/policy-engine.js +9 -3
  80. package/dist/conversion/hub/policy/protocol-spec.js +20 -148
  81. package/dist/conversion/hub/process/chat-process-anthropic-alias.d.ts +2 -0
  82. package/dist/conversion/hub/process/chat-process-anthropic-alias.js +36 -0
  83. package/dist/conversion/hub/process/chat-process-clock-directive-parser.d.ts +5 -0
  84. package/dist/conversion/hub/process/chat-process-clock-directive-parser.js +48 -0
  85. package/dist/conversion/hub/process/chat-process-clock-directives.d.ts +24 -0
  86. package/dist/conversion/hub/process/chat-process-clock-directives.js +98 -0
  87. package/dist/conversion/hub/process/chat-process-clock-reminder-directives.d.ts +8 -0
  88. package/dist/conversion/hub/process/chat-process-clock-reminder-directives.js +42 -0
  89. package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.d.ts +14 -0
  90. package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.js +10 -0
  91. package/dist/conversion/hub/process/chat-process-clock-reminder-messages.d.ts +5 -0
  92. package/dist/conversion/hub/process/chat-process-clock-reminder-messages.js +10 -0
  93. package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.d.ts +30 -0
  94. package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.js +68 -0
  95. package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.d.ts +9 -0
  96. package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.js +18 -0
  97. package/dist/conversion/hub/process/chat-process-clock-reminders.d.ts +2 -0
  98. package/dist/conversion/hub/process/chat-process-clock-reminders.js +104 -0
  99. package/dist/conversion/hub/process/chat-process-clock-tool-schemas.d.ts +3 -0
  100. package/dist/conversion/hub/process/chat-process-clock-tool-schemas.js +233 -0
  101. package/dist/conversion/hub/process/chat-process-clock-tools.d.ts +6 -0
  102. package/dist/conversion/hub/process/chat-process-clock-tools.js +41 -0
  103. package/dist/conversion/hub/process/chat-process-continue-execution.d.ts +11 -0
  104. package/dist/conversion/hub/process/chat-process-continue-execution.js +82 -0
  105. package/dist/conversion/hub/process/chat-process-governance-context.d.ts +15 -0
  106. package/dist/conversion/hub/process/chat-process-governance-context.js +7 -0
  107. package/dist/conversion/hub/process/chat-process-governance-finalize.d.ts +16 -0
  108. package/dist/conversion/hub/process/chat-process-governance-finalize.js +11 -0
  109. package/dist/conversion/hub/process/chat-process-governance-orchestration.d.ts +9 -0
  110. package/dist/conversion/hub/process/chat-process-governance-orchestration.js +47 -0
  111. package/dist/conversion/hub/process/chat-process-governed-control-ops.d.ts +8 -0
  112. package/dist/conversion/hub/process/chat-process-governed-control-ops.js +5 -0
  113. package/dist/conversion/hub/process/chat-process-governed-filter-call.d.ts +12 -0
  114. package/dist/conversion/hub/process/chat-process-governed-filter-call.js +18 -0
  115. package/dist/conversion/hub/process/chat-process-governed-merge.d.ts +8 -0
  116. package/dist/conversion/hub/process/chat-process-governed-merge.js +11 -0
  117. package/dist/conversion/hub/process/chat-process-media.d.ts +3 -0
  118. package/dist/conversion/hub/process/chat-process-media.js +18 -0
  119. package/dist/conversion/hub/process/chat-process-node-result.d.ts +23 -0
  120. package/dist/conversion/hub/process/chat-process-node-result.js +24 -0
  121. package/dist/conversion/hub/process/chat-process-pending-tool-sync.d.ts +14 -0
  122. package/dist/conversion/hub/process/chat-process-pending-tool-sync.js +52 -0
  123. package/dist/conversion/hub/process/chat-process-post-governed-normalization.d.ts +8 -0
  124. package/dist/conversion/hub/process/chat-process-post-governed-normalization.js +16 -0
  125. package/dist/conversion/hub/process/chat-process-review.d.ts +2 -0
  126. package/dist/conversion/hub/process/chat-process-review.js +8 -0
  127. package/dist/conversion/hub/process/chat-process-servertool-orchestration.d.ts +8 -0
  128. package/dist/conversion/hub/process/chat-process-servertool-orchestration.js +22 -0
  129. package/dist/conversion/hub/process/chat-process-tool-normalization.d.ts +2 -0
  130. package/dist/conversion/hub/process/chat-process-tool-normalization.js +4 -0
  131. package/dist/conversion/hub/process/chat-process-web-search-intent.d.ts +12 -0
  132. package/dist/conversion/hub/process/chat-process-web-search-intent.js +13 -0
  133. package/dist/conversion/hub/process/chat-process-web-search-tool-schema.d.ts +3 -0
  134. package/dist/conversion/hub/process/chat-process-web-search-tool-schema.js +4 -0
  135. package/dist/conversion/hub/process/chat-process-web-search.d.ts +8 -0
  136. package/dist/conversion/hub/process/chat-process-web-search.js +26 -0
  137. package/dist/conversion/hub/process/chat-process.d.ts +2 -19
  138. package/dist/conversion/hub/process/chat-process.js +12 -1701
  139. package/dist/conversion/hub/process/client-inject-readiness.d.ts +1 -0
  140. package/dist/conversion/hub/process/client-inject-readiness.js +4 -0
  141. package/dist/conversion/hub/registry.js +5 -2
  142. package/dist/conversion/hub/response/chat-response-utils.js +5 -86
  143. package/dist/conversion/hub/response/provider-response.d.ts +9 -0
  144. package/dist/conversion/hub/response/provider-response.js +6 -21
  145. package/dist/conversion/hub/response/response-mappers.js +2 -26
  146. package/dist/conversion/hub/response/response-runtime.js +2 -93
  147. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.d.ts +1 -0
  148. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +1 -0
  149. package/dist/conversion/hub/semantic-mappers/chat-mapper.d.ts +1 -0
  150. package/dist/conversion/hub/semantic-mappers/chat-mapper.js +1 -0
  151. package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +1 -0
  152. package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +1 -0
  153. package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +1 -0
  154. package/dist/conversion/hub/semantic-mappers/responses-mapper.js +1 -0
  155. package/dist/conversion/hub/snapshot-recorder.js +10 -3
  156. package/dist/conversion/hub/standardized-bridge.js +11 -288
  157. package/dist/conversion/hub/tool-governance/engine.js +5 -0
  158. package/dist/conversion/hub/tool-governance/rules.js +10 -10
  159. package/dist/conversion/hub/tool-session-compat.d.ts +2 -2
  160. package/dist/conversion/hub/tool-session-compat.js +17 -231
  161. package/dist/conversion/hub/tool-surface/tool-surface-engine.js +5 -3
  162. package/dist/conversion/responses/responses-host-policy.js +2 -12
  163. package/dist/conversion/responses/responses-openai-bridge/response-payload.js +6 -82
  164. package/dist/conversion/responses/responses-openai-bridge/types.d.ts +1 -0
  165. package/dist/conversion/responses/responses-openai-bridge.js +21 -54
  166. package/dist/conversion/shared/anthropic-message-utils.js +151 -13
  167. package/dist/conversion/shared/args-mapping.js +2 -146
  168. package/dist/conversion/shared/bridge-actions.js +203 -718
  169. package/dist/conversion/shared/bridge-id-utils.js +5 -71
  170. package/dist/conversion/shared/bridge-instructions.js +2 -1
  171. package/dist/conversion/shared/bridge-message-types.d.ts +2 -0
  172. package/dist/conversion/shared/bridge-message-utils.js +1 -2
  173. package/dist/conversion/shared/bridge-metadata.d.ts +1 -0
  174. package/dist/conversion/shared/bridge-metadata.js +4 -0
  175. package/dist/conversion/shared/bridge-policies.js +5 -189
  176. package/dist/conversion/shared/chat-envelope-validator.js +2 -126
  177. package/dist/conversion/shared/chat-output-normalizer.js +2 -54
  178. package/dist/conversion/shared/compaction-detect.js +2 -57
  179. package/dist/conversion/shared/gemini-tool-utils.js +9 -524
  180. package/dist/conversion/shared/jsonish.js +3 -160
  181. package/dist/conversion/shared/mcp-injection.js +3 -169
  182. package/dist/conversion/shared/media.js +2 -7
  183. package/dist/conversion/shared/metadata-passthrough.js +9 -46
  184. package/dist/conversion/shared/openai-finalizer.js +2 -1
  185. package/dist/conversion/shared/openai-message-normalize.js +11 -283
  186. package/dist/conversion/shared/output-content-normalizer.js +9 -112
  187. package/dist/conversion/shared/payload-budget.js +2 -85
  188. package/dist/conversion/shared/protocol-state.js +11 -7
  189. package/dist/conversion/shared/reasoning-mapping.js +2 -6
  190. package/dist/conversion/shared/reasoning-normalizer.js +4 -1
  191. package/dist/conversion/shared/reasoning-tool-normalizer.js +14 -126
  192. package/dist/conversion/shared/reasoning-tool-parser.js +4 -87
  193. package/dist/conversion/shared/reasoning-utils.js +2 -6
  194. package/dist/conversion/shared/responses-conversation-store.js +4 -82
  195. package/dist/conversion/shared/responses-output-builder.js +11 -47
  196. package/dist/conversion/shared/responses-reasoning-registry.js +7 -1
  197. package/dist/conversion/shared/responses-request-adapter.d.ts +7 -1
  198. package/dist/conversion/shared/responses-request-adapter.js +14 -1
  199. package/dist/conversion/shared/responses-response-utils.js +6 -7
  200. package/dist/conversion/shared/responses-tool-utils.d.ts +1 -0
  201. package/dist/conversion/shared/responses-tool-utils.js +90 -14
  202. package/dist/conversion/shared/runtime-metadata.js +13 -5
  203. package/dist/conversion/shared/streaming-text-extractor.js +2 -7
  204. package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +1 -1
  205. package/dist/conversion/shared/text-markup-normalizer/normalize.js +43 -17
  206. package/dist/conversion/shared/text-markup-normalizer.d.ts +1 -0
  207. package/dist/conversion/shared/text-markup-normalizer.js +1 -0
  208. package/dist/conversion/shared/thought-signature-validator.js +3 -2
  209. package/dist/conversion/shared/tool-argument-repairer.js +2 -2
  210. package/dist/conversion/shared/tool-call-id-manager.js +5 -7
  211. package/dist/conversion/shared/tool-call-utils.js +3 -45
  212. package/dist/conversion/shared/tool-canonicalizer.js +25 -29
  213. package/dist/conversion/shared/tool-filter-pipeline.js +4 -99
  214. package/dist/conversion/shared/tool-governor.d.ts +6 -0
  215. package/dist/conversion/shared/tool-governor.js +43 -125
  216. package/dist/conversion/shared/tool-harvester.js +2 -8
  217. package/dist/conversion/shared/tool-mapping.js +2 -5
  218. package/dist/conversion/shared/tooling.d.ts +0 -4
  219. package/dist/conversion/shared/tooling.js +18 -0
  220. package/dist/native/router_hotpath_napi.node +0 -0
  221. package/dist/router/virtual-router/engine/provider-key/parse.d.ts +1 -6
  222. package/dist/router/virtual-router/engine/provider-key/parse.js +1 -43
  223. package/dist/router/virtual-router/engine/routing-state/store.js +48 -12
  224. package/dist/router/virtual-router/engine-logging.js +4 -3
  225. package/dist/router/virtual-router/engine-selection/alias-selection.js +45 -83
  226. package/dist/router/virtual-router/engine-selection/key-parsing.js +9 -23
  227. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.d.ts +20 -0
  228. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.js +163 -0
  229. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.d.ts +7 -0
  230. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.js +103 -0
  231. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.d.ts +10 -0
  232. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.js +110 -0
  233. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.d.ts +8 -0
  234. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.js +281 -0
  235. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.d.ts +1 -0
  236. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.js +25 -0
  237. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.d.ts +4 -0
  238. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.js +44 -0
  239. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.d.ts +2 -0
  240. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.js +62 -0
  241. package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.d.ts +40 -0
  242. package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.js +484 -0
  243. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.d.ts +9 -0
  244. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.js +64 -0
  245. package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.d.ts +5 -0
  246. package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.js +163 -0
  247. package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.d.ts +1 -0
  248. package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.js +49 -0
  249. package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.d.ts +30 -0
  250. package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.js +446 -0
  251. package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.d.ts +1 -0
  252. package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.js +49 -0
  253. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +134 -0
  254. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +729 -0
  255. package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.d.ts +62 -0
  256. package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js +338 -0
  257. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.d.ts +18 -0
  258. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js +317 -0
  259. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.d.ts +22 -0
  260. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.js +426 -0
  261. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.d.ts +57 -0
  262. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.js +705 -0
  263. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.d.ts +46 -0
  264. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js +503 -0
  265. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.d.ts +146 -0
  266. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js +570 -0
  267. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.d.ts +25 -0
  268. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.js +148 -0
  269. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.d.ts +25 -0
  270. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js +637 -0
  271. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.d.ts +11 -0
  272. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.js +207 -0
  273. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.d.ts +3 -0
  274. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.js +128 -0
  275. package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.d.ts +57 -0
  276. package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.js +217 -0
  277. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.d.ts +5 -0
  278. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +284 -0
  279. package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.d.ts +5 -0
  280. package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.js +18 -0
  281. package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.d.ts +25 -0
  282. package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.js +85 -0
  283. package/dist/router/virtual-router/engine-selection/native-router-hotpath.d.ts +59 -0
  284. package/dist/router/virtual-router/engine-selection/native-router-hotpath.js +117 -0
  285. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +76 -0
  286. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +1166 -0
  287. package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.d.ts +16 -0
  288. package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.js +96 -0
  289. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.d.ts +6 -0
  290. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.js +85 -0
  291. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.d.ts +9 -0
  292. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.js +70 -0
  293. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.d.ts +2 -0
  294. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.js +76 -0
  295. package/dist/router/virtual-router/engine-selection/route-utils.js +1 -1
  296. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.d.ts +10 -0
  297. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.js +231 -0
  298. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.d.ts +4 -0
  299. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.js +43 -0
  300. package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.d.ts +27 -0
  301. package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.js +116 -0
  302. package/dist/router/virtual-router/engine-selection/tier-selection-select.d.ts +1 -1
  303. package/dist/router/virtual-router/engine-selection/tier-selection-select.js +29 -129
  304. package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -265
  305. package/dist/router/virtual-router/engine.js +258 -249
  306. package/dist/router/virtual-router/features.js +2 -2
  307. package/dist/router/virtual-router/routing-instructions.d.ts +5 -7
  308. package/dist/router/virtual-router/routing-instructions.js +93 -66
  309. package/dist/router/virtual-router/routing-stop-message-actions.js +91 -112
  310. package/dist/router/virtual-router/routing-stop-message-parser.js +9 -132
  311. package/dist/router/virtual-router/routing-stop-message-state-codec.d.ts +1 -0
  312. package/dist/router/virtual-router/routing-stop-message-state-codec.js +58 -71
  313. package/dist/router/virtual-router/sticky-session-store.js +4 -2
  314. package/dist/router/virtual-router/stop-message-file-resolver.d.ts +1 -0
  315. package/dist/router/virtual-router/stop-message-file-resolver.js +10 -0
  316. package/dist/router/virtual-router/stop-message-state-sync.d.ts +1 -1
  317. package/dist/router/virtual-router/stop-message-state-sync.js +3 -7
  318. package/dist/router/virtual-router/token-counter.js +0 -9
  319. package/dist/router/virtual-router/types.d.ts +9 -7
  320. package/dist/servertool/clock/config.js +23 -51
  321. package/dist/servertool/clock/io.js +1 -0
  322. package/dist/servertool/clock/session-scope.d.ts +2 -2
  323. package/dist/servertool/clock/session-scope.js +5 -47
  324. package/dist/servertool/engine.d.ts +9 -0
  325. package/dist/servertool/engine.js +196 -79
  326. package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +2 -2
  327. package/dist/servertool/handlers/clock.js +1 -1
  328. package/dist/servertool/handlers/continue-execution.js +8 -4
  329. package/dist/servertool/handlers/followup-request-builder.js +18 -1
  330. package/dist/servertool/handlers/gemini-empty-reply-continue.js +7 -1
  331. package/dist/servertool/handlers/review.js +180 -0
  332. package/dist/servertool/handlers/stop-message-auto/blocked-report.js +59 -1
  333. package/dist/servertool/handlers/stop-message-auto/iflow-followup.d.ts +23 -2
  334. package/dist/servertool/handlers/stop-message-auto/iflow-followup.js +397 -89
  335. package/dist/servertool/handlers/stop-message-auto/routing-state.d.ts +5 -15
  336. package/dist/servertool/handlers/stop-message-auto/routing-state.js +29 -55
  337. package/dist/servertool/handlers/stop-message-auto/runtime-utils.d.ts +6 -0
  338. package/dist/servertool/handlers/stop-message-auto/runtime-utils.js +35 -61
  339. package/dist/servertool/handlers/stop-message-auto.js +392 -76
  340. package/dist/servertool/server-side-tools.d.ts +1 -0
  341. package/dist/servertool/server-side-tools.js +90 -52
  342. package/dist/servertool/types.d.ts +17 -0
  343. package/dist/tools/apply-patch/patch-text/normalize.js +11 -0
  344. package/dist/tools/exec-command/validator.d.ts +4 -1
  345. package/dist/tools/exec-command/validator.js +87 -3
  346. package/dist/tools/tool-registry.d.ts +7 -1
  347. package/dist/tools/tool-registry.js +3 -2
  348. package/package.json +115 -7
  349. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.d.ts +0 -18
  350. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.js +0 -398
  351. package/dist/servertool/handlers/stop-message-stage-policy/decision.d.ts +0 -9
  352. package/dist/servertool/handlers/stop-message-stage-policy/decision.js +0 -127
  353. package/dist/servertool/handlers/stop-message-stage-policy/observation.d.ts +0 -2
  354. package/dist/servertool/handlers/stop-message-stage-policy/observation.js +0 -179
  355. package/dist/servertool/handlers/stop-message-stage-policy/templates.d.ts +0 -4
  356. package/dist/servertool/handlers/stop-message-stage-policy/templates.js +0 -96
  357. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.d.ts +0 -9
  358. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.js +0 -89
  359. package/dist/servertool/handlers/stop-message-stage-policy/types.d.ts +0 -59
  360. package/dist/servertool/handlers/stop-message-stage-policy.d.ts +0 -3
  361. package/dist/servertool/handlers/stop-message-stage-policy.js +0 -2
  362. /package/dist/servertool/handlers/{stop-message-stage-policy/types.js → review.d.ts} +0 -0
@@ -1,1055 +1,46 @@
1
- import { getCompatProfile } from './compat-profile-store.js';
2
- import { UniversalShapeFilter } from '../../../compat/actions/universal-shape-filter.js';
3
- import { ResponseBlacklistSanitizer } from '../../../compat/actions/response-blacklist.js';
4
- import { applyFieldMappings } from '../../../compat/actions/field-mapping.js';
5
- import { sanitizeToolSchema } from '../../../compat/actions/tool-schema.js';
6
- import { applyRequestRules } from '../../../compat/actions/request-rules.js';
7
- import { applyAutoThinking as runAutoThinking } from '../../../compat/actions/auto-thinking.js';
8
- import { normalizeResponsePayload } from '../../../compat/actions/response-normalize.js';
9
- import { validateResponsePayload } from '../../../compat/actions/response-validate.js';
10
- import { writeCompatSnapshot } from '../../../compat/actions/snapshot.js';
11
- import { applyQwenRequestTransform, applyQwenResponseTransform } from '../../../compat/actions/qwen-transform.js';
12
- import { extractGlmToolMarkup } from '../../../compat/actions/glm-tool-extraction.js';
13
- import { applyGlmWebSearchRequestTransform } from '../../../compat/actions/glm-web-search.js';
14
- import { applyGeminiWebSearchCompat } from '../../../compat/actions/gemini-web-search.js';
15
- import { applyIflowWebSearchRequestTransform } from '../../../compat/actions/iflow-web-search.js';
16
- import { applyIflowToolTextFallback } from '../../../compat/actions/iflow-tool-text-fallback.js';
17
- import { unwrapIflowResponseBodyEnvelope } from '../../../compat/actions/iflow-response-body-unwrap.js';
18
- import { applyDeepSeekWebRequestTransform } from '../../../compat/actions/deepseek-web-request.js';
19
- import { applyDeepSeekWebResponseTransform } from '../../../compat/actions/deepseek-web-response.js';
20
- import { applyIflowKimiHistoryMediaPlaceholder } from '../../../compat/actions/iflow-kimi-history-media-placeholder.js';
21
- import { applyIflowKimiCliDefaults } from '../../../compat/actions/iflow-kimi-cli-defaults.js';
22
- import { fillIflowKimiThinkingReasoningContent } from '../../../compat/actions/iflow-kimi-thinking-reasoning-fill.js';
23
- import { applyGlmImageContentTransform } from '../../../compat/actions/glm-image-content.js';
24
- import { applyGlmVisionPromptTransform } from '../../../compat/actions/glm-vision-prompt.js';
25
- import { applyClaudeThinkingToolSchemaCompat } from '../../../compat/actions/claude-thinking-tools.js';
26
- import { wrapGeminiCliRequest } from '../../../compat/actions/gemini-cli-request.js';
27
- import { prepareAntigravityThoughtSignatureForGeminiRequest } from '../../../compat/actions/antigravity-thought-signature-prepare.js';
28
- import { cacheAntigravityThoughtSignatureFromGeminiResponse } from '../../../compat/actions/antigravity-thought-signature-cache.js';
29
- import { applyAnthropicClaudeCodeSystemPromptCompat } from '../../../compat/actions/anthropic-claude-code-system-prompt.js';
30
- import { normalizeToolCallIdsInPlace } from '../../../compat/actions/normalize-tool-call-ids.js';
31
- import { harvestToolCallsFromTextWithConfig } from '../../../compat/actions/harvest-tool-calls-from-text.js';
32
- import { stripOrphanFunctionCallsTag } from '../../../compat/actions/strip-orphan-function-calls-tag.js';
33
- import { stringifyLmstudioResponsesInput } from '../../../compat/actions/lmstudio-responses-input-stringify.js';
34
- import { enforceLmstudioResponsesFcToolCallIds } from '../../../compat/actions/lmstudio-responses-fc-ids.js';
35
- import { applyToolTextRequestGuidance } from '../../../compat/actions/tool-text-request-guidance.js';
1
+ import { runReqOutboundStage3CompatWithNative, runRespInboundStage3CompatWithNative } from '../../../../router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js';
2
+ import { buildNativeReqOutboundCompatAdapterContext } from './native-adapter-context.js';
36
3
  const RATE_LIMIT_ERROR = 'ERR_COMPAT_RATE_LIMIT_DETECTED';
37
- const INTERNAL_STATE = Symbol('compat.internal_state');
38
- export function runRequestCompatPipeline(profileId, payload, options) {
39
- const profile = getCompatProfile(profileId);
40
- if (!profile) {
41
- return { payload };
42
- }
43
- if (!isProtocolCompatible(profile, options?.adapterContext)) {
44
- return { payload };
45
- }
46
- const stage = pickStageConfig(profile, 'request');
47
- if (!stage) {
48
- return { payload };
49
- }
50
- const mutated = structuredClone(payload);
51
- const state = initializeInternalState(mutated, 'request', options?.adapterContext);
52
- if (Array.isArray(stage.mappings)) {
53
- for (const mapping of stage.mappings) {
54
- applyMapping(mutated, mapping, state);
55
- }
56
- }
57
- return {
58
- payload: mutated,
59
- appliedProfile: profile.id
60
- };
61
- }
62
- export function runResponseCompatPipeline(profileId, payload, options) {
63
- const profile = getCompatProfile(profileId);
64
- if (!profile) {
65
- return { payload };
66
- }
67
- if (!isProtocolCompatible(profile, options?.adapterContext)) {
68
- return { payload };
69
- }
70
- const stage = pickStageConfig(profile, 'response');
71
- if (!stage) {
72
- return { payload };
73
- }
74
- const mutated = structuredClone(payload);
75
- const state = initializeInternalState(mutated, 'response', options?.adapterContext);
76
- if (Array.isArray(stage.mappings)) {
77
- for (const mapping of stage.mappings) {
78
- applyMapping(mutated, mapping, state);
79
- }
80
- }
81
- if (Array.isArray(stage.filters)) {
82
- for (const filter of stage.filters) {
83
- applyFilter(mutated, filter);
84
- }
85
- }
86
- const requestIdFallback = state.originalRequestId || state.adapterContext?.requestId;
87
- if (requestIdFallback && typeof mutated.request_id !== 'string') {
88
- mutated.request_id = requestIdFallback;
89
- }
90
- return {
91
- payload: mutated,
92
- appliedProfile: profile.id
93
- };
94
- }
95
- function pickStageConfig(profile, stage) {
96
- if (!profile) {
97
- return null;
98
- }
99
- if (stage === 'request' && profile.request) {
100
- return profile.request;
101
- }
102
- if (stage === 'response' && profile.response) {
103
- return profile.response;
104
- }
105
- if (profile.direction && profile.direction !== stage) {
106
- return null;
107
- }
108
- if (profile.mappings || profile.filters) {
109
- return {
110
- mappings: profile.mappings,
111
- filters: profile.filters
112
- };
113
- }
114
- return null;
115
- }
116
- function isProtocolCompatible(profile, adapterContext) {
117
- const required = typeof profile.protocol === 'string' ? profile.protocol.trim().toLowerCase() : '';
118
- if (!required) {
119
- return true;
120
- }
121
- const actual = typeof adapterContext?.providerProtocol === 'string' && adapterContext.providerProtocol.trim()
122
- ? adapterContext.providerProtocol.trim().toLowerCase()
123
- : '';
124
- return Boolean(actual) && actual === required;
125
- }
126
- function applyMapping(root, mapping, state) {
127
- switch (mapping.action) {
128
- case 'remove':
129
- removePath(root, mapping.path);
130
- break;
131
- case 'shallow_pick': {
132
- const allow = new Set(Array.isArray(mapping.allowTopLevel) ? mapping.allowTopLevel : []);
133
- const next = {};
134
- for (const [key, value] of Object.entries(root)) {
135
- if (allow.has(key)) {
136
- next[key] = value;
137
- }
138
- }
139
- replaceRoot(root, next);
140
- break;
141
- }
142
- case 'rename':
143
- renamePath(root, mapping.from, mapping.to);
144
- break;
145
- case 'set':
146
- setPath(root, mapping.path, mapping.value);
147
- break;
148
- case 'stringify':
149
- stringifyPath(root, mapping.path, mapping.fallback);
150
- break;
151
- case 'parse_json':
152
- parseJsonPath(root, mapping.path, mapping.fallback);
153
- break;
154
- case 'set_default':
155
- setDefaultPath(root, mapping.path, mapping.value, mapping.valueSource);
156
- break;
157
- case 'normalize_tool_choice':
158
- normalizeToolChoice(root, mapping);
159
- break;
160
- case 'normalize_tool_call_ids':
161
- normalizeToolCallIdsInPlace(root);
162
- break;
163
- case 'lmstudio_responses_fc_ids':
164
- if (state.direction === 'request') {
165
- replaceRoot(root, enforceLmstudioResponsesFcToolCallIds(root));
166
- }
167
- break;
168
- case 'lmstudio_responses_input_stringify':
169
- if (state.direction === 'request') {
170
- replaceRoot(root, stringifyLmstudioResponsesInput(root, state.adapterContext));
171
- }
172
- break;
173
- case 'inject_instruction':
174
- injectInstruction(root, mapping);
175
- break;
176
- case 'convert_responses_output_to_choices':
177
- convertResponsesOutputToChoices(root);
178
- break;
179
- case 'extract_glm_tool_markup':
180
- extractGlmToolMarkup(root);
181
- break;
182
- case 'harvest_tool_calls_from_text':
183
- if (state.direction === 'response') {
184
- replaceRoot(root, harvestToolCallsFromTextWithConfig(root, mapping.config));
185
- }
186
- break;
187
- case 'tool_text_request_guidance':
188
- if (state.direction === 'request') {
189
- replaceRoot(root, applyToolTextRequestGuidance(root, mapping.config));
190
- }
191
- break;
192
- case 'strip_orphan_function_calls_tag':
193
- if (state.direction === 'response') {
194
- replaceRoot(root, stripOrphanFunctionCallsTag(root));
195
- }
196
- break;
197
- case 'iflow_kimi_thinking_reasoning_fill':
198
- if (state.direction === 'request') {
199
- replaceRoot(root, fillIflowKimiThinkingReasoningContent(root));
200
- }
201
- break;
202
- case 'iflow_kimi_history_media_placeholder':
203
- if (state.direction === 'request') {
204
- replaceRoot(root, applyIflowKimiHistoryMediaPlaceholder(root));
205
- }
206
- break;
207
- case 'iflow_kimi_cli_defaults':
208
- if (state.direction === 'request') {
209
- replaceRoot(root, applyIflowKimiCliDefaults(root));
210
- }
211
- break;
212
- case 'dto_unwrap':
213
- dtoUnwrap(root, state);
214
- break;
215
- case 'dto_rewrap':
216
- dtoRewrap(root, state);
217
- break;
218
- case 'shape_filter':
219
- applyShapeFilterMapping(root, mapping, state);
220
- break;
221
- case 'field_map':
222
- applyFieldMap(root, mapping, state);
223
- break;
224
- case 'tool_schema_sanitize':
225
- applyToolSchemaSanitize(root, mapping);
226
- break;
227
- case 'apply_rules':
228
- applyRules(root, mapping, state);
229
- break;
230
- case 'auto_thinking':
231
- applyAutoThinkingAction(root, mapping, state);
232
- break;
233
- case 'snapshot':
234
- triggerSnapshot(root, mapping, state);
235
- break;
236
- case 'resp_blacklist':
237
- applyResponseBlacklist(root, mapping, state);
238
- break;
239
- case 'response_normalize':
240
- applyResponseNormalize(root, mapping, state);
241
- break;
242
- case 'response_validate':
243
- if (state.direction === 'response') {
244
- validateResponsePayload(root, mapping.config);
245
- }
246
- break;
247
- case 'qwen_request_transform':
248
- replaceRoot(root, applyQwenRequestTransform(root));
249
- break;
250
- case 'qwen_response_transform':
251
- replaceRoot(root, applyQwenResponseTransform(root));
252
- break;
253
- case 'glm_web_search_request':
254
- if (state.direction === 'request') {
255
- replaceRoot(root, applyGlmWebSearchRequestTransform(root));
256
- }
257
- break;
258
- case 'gemini_web_search_request':
259
- if (state.direction === 'request') {
260
- replaceRoot(root, applyGeminiWebSearchCompat(root, state.adapterContext));
261
- }
262
- break;
263
- case 'iflow_web_search_request':
264
- if (state.direction === 'request') {
265
- replaceRoot(root, applyIflowWebSearchRequestTransform(root, state.adapterContext));
266
- }
267
- break;
268
- case 'iflow_tool_text_fallback':
269
- if (state.direction === 'request') {
270
- replaceRoot(root, applyIflowToolTextFallback(root, {
271
- models: mapping.models,
272
- routeId: typeof state.adapterContext?.routeId === 'string' ? state.adapterContext.routeId : undefined
273
- }));
274
- }
275
- break;
276
- case 'iflow_response_body_unwrap':
277
- if (state.direction === 'response') {
278
- replaceRoot(root, unwrapIflowResponseBodyEnvelope(root));
279
- }
280
- break;
281
- case 'deepseek_web_request':
282
- if (state.direction === 'request') {
283
- replaceRoot(root, applyDeepSeekWebRequestTransform(root, state.adapterContext));
284
- }
285
- break;
286
- case 'deepseek_web_response':
287
- if (state.direction === 'response') {
288
- replaceRoot(root, applyDeepSeekWebResponseTransform(root, state.adapterContext, mapping.config));
289
- }
290
- break;
291
- case 'claude_thinking_tool_schema':
292
- if (state.direction === 'request') {
293
- replaceRoot(root, applyClaudeThinkingToolSchemaCompat(root, state.adapterContext));
294
- }
295
- break;
296
- case 'gemini_cli_request_wrap':
297
- if (state.direction === 'request') {
298
- replaceRoot(root, wrapGeminiCliRequest(root, state.adapterContext));
299
- }
300
- break;
301
- case 'antigravity_thought_signature_prepare':
302
- if (state.direction === 'request') {
303
- replaceRoot(root, prepareAntigravityThoughtSignatureForGeminiRequest(root, state.adapterContext));
304
- }
305
- break;
306
- case 'antigravity_thought_signature_cache':
307
- if (state.direction === 'response') {
308
- replaceRoot(root, cacheAntigravityThoughtSignatureFromGeminiResponse(root, state.adapterContext));
309
- }
310
- break;
311
- case 'anthropic_claude_code_system_prompt':
312
- if (state.direction === 'request') {
313
- replaceRoot(root, applyAnthropicClaudeCodeSystemPromptCompat(root, mapping.config, state.adapterContext));
314
- }
315
- break;
316
- case 'glm_image_content':
317
- if (state.direction === 'request') {
318
- replaceRoot(root, applyGlmImageContentTransform(root));
319
- }
320
- break;
321
- case 'glm_vision_prompt':
322
- if (state.direction === 'request') {
323
- replaceRoot(root, applyGlmVisionPromptTransform(root));
324
- }
325
- break;
326
- default:
327
- break;
328
- }
329
- }
330
- function applyFilter(payload, filter) {
331
- if (filter.action === 'rate_limit_text') {
332
- if (detectRateLimitText(payload, filter.needle)) {
333
- const err = new Error('Provider returned rate limit notice');
334
- err.code = RATE_LIMIT_ERROR;
335
- err.statusCode = 429;
336
- throw err;
337
- }
338
- }
339
- }
340
- function initializeInternalState(root, direction, adapterContext) {
341
- const state = {
342
- direction,
343
- adapterContext,
344
- originalRequestId: direction === 'response' ? extractRequestId(root) : undefined
345
- };
346
- Object.defineProperty(root, INTERNAL_STATE, {
347
- value: state,
348
- enumerable: false,
349
- configurable: true
350
- });
351
- return state;
352
- }
353
- function replaceRoot(target, source) {
354
- if (target === source) {
355
- return;
356
- }
357
- for (const key of Object.keys(target)) {
358
- delete target[key];
359
- }
360
- for (const [key, value] of Object.entries(source)) {
361
- target[key] = value;
362
- }
363
- }
364
- function dtoUnwrap(root, state) {
365
- const original = structuredClone(root);
366
- const data = original.data;
367
- if (isRecord(data)) {
368
- state.dtoEnvelope = { original, isDto: true };
369
- replaceRoot(root, data);
370
- return;
371
- }
372
- // Transport compatibility: some upstreams return JSON bodies but mislabel the content-type,
373
- // causing HTTP clients to surface `data` as a string. When a compat profile opts into dto_unwrap,
374
- // best-effort parse JSON strings so downstream semantic mapping sees canonical objects.
375
- if (typeof data === 'string') {
376
- const parsed = tryParseJsonRecord(data);
377
- if (parsed) {
378
- state.dtoEnvelope = { original, isDto: true };
379
- replaceRoot(root, parsed);
380
- return;
381
- }
382
- }
383
- state.dtoEnvelope = { original, isDto: false };
384
- }
385
- function dtoRewrap(root, state) {
386
- const envelope = state.dtoEnvelope;
387
- if (!envelope) {
388
- return;
389
- }
390
- if (!envelope.isDto) {
391
- state.dtoEnvelope = undefined;
392
- return;
393
- }
394
- const rebuilt = structuredClone(envelope.original);
395
- rebuilt.data = structuredClone(root);
396
- replaceRoot(root, rebuilt);
397
- state.dtoEnvelope = undefined;
398
- }
399
- function tryParseJsonRecord(raw) {
400
- try {
401
- let text = typeof raw === 'string' ? raw.trim() : '';
402
- if (!text)
403
- return null;
404
- // anti-XSSI prefix: ")]}',\n{...}"
405
- text = text.replace(/^\)\]\}',?\s*/u, '');
406
- // single-line SSE-like wrapper sometimes returned as plain text
407
- text = text.replace(/^data:\s*/iu, '');
408
- // Quick structural guards to avoid parsing random prose.
409
- const first = text.charAt(0);
410
- const last = text.charAt(text.length - 1);
411
- if (first !== '{' || last !== '}') {
412
- return null;
413
- }
414
- // Guard: avoid unbounded parsing for pathological payloads.
415
- if (text.length > 10 * 1024 * 1024) {
416
- return null;
417
- }
418
- const parsed = JSON.parse(text);
419
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
420
- return null;
421
- }
422
- return parsed;
423
- }
424
- catch {
425
- return null;
426
- }
427
- }
428
- function applyShapeFilterMapping(root, mapping, state) {
429
- const target = mapping.target ?? state.direction;
430
- const filter = new UniversalShapeFilter(mapping.config);
431
- const filtered = target === 'request'
432
- ? filter.applyRequestFilter(root)
433
- : filter.applyResponseFilter(root, state.adapterContext);
434
- if (filtered === root) {
435
- return;
436
- }
437
- replaceRoot(root, filtered);
438
- }
439
- function applyFieldMap(root, mapping, state) {
440
- const direction = mapping.direction ?? state.direction;
441
- const result = applyFieldMappings(root, mapping.config);
442
- replaceRoot(root, result);
443
- }
444
- function applyToolSchemaSanitize(root, mapping) {
445
- const sanitized = sanitizeToolSchema(root, mapping.mode ?? 'glm_shell');
446
- replaceRoot(root, sanitized);
447
- }
448
- function applyRules(root, mapping, state) {
449
- if (state.direction !== 'request') {
450
- return;
451
- }
452
- const result = applyRequestRules(root, mapping.config);
453
- replaceRoot(root, result);
454
- }
455
- function applyAutoThinkingAction(root, mapping, state) {
456
- if (state.direction !== 'request') {
457
- return;
458
- }
459
- runAutoThinking(root, mapping.config);
460
- }
461
- function triggerSnapshot(root, mapping, state) {
462
- void writeCompatSnapshot({
463
- phase: mapping.phase,
464
- requestId: state.adapterContext?.requestId,
465
- entryEndpoint: state.adapterContext?.entryEndpoint,
466
- data: structuredClone(root)
467
- });
468
- }
469
- function applyResponseBlacklist(root, mapping, state) {
470
- if (state.direction !== 'response') {
471
- return;
472
- }
473
- const sanitizer = new ResponseBlacklistSanitizer(mapping.config);
474
- const result = sanitizer.apply(root);
475
- replaceRoot(root, result);
476
- }
477
- function applyResponseNormalize(root, mapping, state) {
478
- if (state.direction !== 'response') {
479
- return;
480
- }
481
- const result = normalizeResponsePayload(root, mapping.config);
482
- replaceRoot(root, result);
483
- }
484
- function detectRateLimitText(payload, needle) {
485
- if (!needle || !payload) {
486
- return false;
487
- }
488
- const normalizedNeedle = needle.toLowerCase();
489
- const stack = [payload];
490
- while (stack.length) {
491
- const current = stack.pop();
492
- if (typeof current === 'string') {
493
- if (current.toLowerCase().includes(normalizedNeedle)) {
494
- return true;
495
- }
496
- continue;
497
- }
498
- if (Array.isArray(current)) {
499
- for (const entry of current) {
500
- stack.push(entry);
501
- }
502
- continue;
503
- }
504
- if (isRecord(current)) {
505
- for (const value of Object.values(current)) {
506
- stack.push(value);
507
- }
508
- }
509
- }
510
- return false;
511
- }
512
- function parsePath(path) {
513
- if (!path || typeof path !== 'string') {
514
- return [];
515
- }
516
- return path
517
- .split('.')
518
- .map((segment) => segment.trim())
519
- .filter(Boolean)
520
- .map((segment) => {
521
- if (segment.endsWith('[*]')) {
522
- return {
523
- key: segment.slice(0, -3),
524
- wildcard: true
525
- };
526
- }
527
- return {
528
- key: segment,
529
- wildcard: false
530
- };
531
- });
532
- }
533
- function removePath(root, path) {
534
- const steps = parsePath(path);
535
- if (!steps.length) {
536
- return;
537
- }
538
- const parentSteps = steps.slice(0, -1);
539
- const finalStep = steps[steps.length - 1];
540
- const targets = resolveTargets(root, parentSteps);
541
- for (const target of targets) {
542
- if (isRecord(target) && finalStep && finalStep.key in target) {
543
- delete target[finalStep.key];
544
- }
545
- }
546
- }
547
- function renamePath(root, fromPath, toPath) {
548
- const value = getPathValue(root, fromPath);
549
- if (value === undefined) {
550
- return;
551
- }
552
- setPath(root, toPath, value);
553
- removePath(root, fromPath);
554
- }
555
- function setPath(root, path, value) {
556
- const steps = parsePath(path);
557
- if (!steps.length) {
558
- return;
559
- }
560
- let cursor = root;
561
- for (let i = 0; i < steps.length; i++) {
562
- const step = steps[i];
563
- if (step.wildcard) {
564
- throw new Error(`Cannot set wildcard path: ${path}`);
565
- }
566
- if (i === steps.length - 1) {
567
- if (isRecord(cursor)) {
568
- cursor[step.key] = structuredClone(value);
569
- }
570
- }
571
- else {
572
- if (!isRecord(cursor[step.key])) {
573
- cursor[step.key] = {};
574
- }
575
- cursor = cursor[step.key];
576
- }
577
- }
578
- }
579
- function getPathValue(root, path) {
580
- const steps = parsePath(path);
581
- if (!steps.length) {
4
+ function normalizeProfileId(profileId) {
5
+ if (typeof profileId !== 'string') {
582
6
  return undefined;
583
7
  }
584
- let cursor = root;
585
- for (const step of steps) {
586
- if (step.wildcard) {
587
- if (!isRecord(cursor)) {
588
- return undefined;
589
- }
590
- const arr = cursor[step.key];
591
- if (!Array.isArray(arr) || !arr.length) {
592
- return undefined;
593
- }
594
- cursor = arr[0];
595
- continue;
596
- }
597
- if (!isRecord(cursor)) {
598
- return undefined;
599
- }
600
- cursor = cursor[step.key];
601
- if (cursor === undefined) {
602
- return undefined;
603
- }
604
- }
605
- return cursor;
606
- }
607
- function stringifyPath(root, path, fallback) {
608
- const steps = parsePath(path);
609
- if (!steps.length) {
610
- return;
611
- }
612
- const parentSteps = steps.slice(0, -1);
613
- const finalStep = steps[steps.length - 1];
614
- const targets = resolveTargets(root, parentSteps);
615
- for (const target of targets) {
616
- if (!isRecord(target) || !finalStep) {
617
- continue;
618
- }
619
- const current = target[finalStep.key];
620
- if (typeof current === 'string') {
621
- continue;
622
- }
623
- try {
624
- if (current === undefined) {
625
- target[finalStep.key] = JSON.stringify(fallback ?? {});
626
- }
627
- else {
628
- target[finalStep.key] = JSON.stringify(current);
629
- }
630
- }
631
- catch {
632
- try {
633
- target[finalStep.key] = JSON.stringify(fallback ?? {});
634
- }
635
- catch {
636
- target[finalStep.key] = '{}';
637
- }
638
- }
639
- }
640
- }
641
- function parseJsonPath(root, path, fallback) {
642
- const steps = parsePath(path);
643
- if (!steps.length) {
644
- return;
645
- }
646
- const parentSteps = steps.slice(0, -1);
647
- const finalStep = steps[steps.length - 1];
648
- const targets = resolveTargets(root, parentSteps);
649
- for (const target of targets) {
650
- if (!isRecord(target) || !finalStep) {
651
- continue;
652
- }
653
- const current = target[finalStep.key];
654
- if (current === undefined || current === null) {
655
- if (fallback !== undefined) {
656
- target[finalStep.key] = structuredClone(fallback);
657
- }
658
- continue;
659
- }
660
- if (typeof current !== 'string') {
661
- continue;
662
- }
663
- const trimmed = current.trim();
664
- if (!trimmed) {
665
- if (fallback !== undefined) {
666
- target[finalStep.key] = structuredClone(fallback);
667
- }
668
- continue;
669
- }
670
- try {
671
- target[finalStep.key] = JSON.parse(trimmed);
672
- }
673
- catch {
674
- if (fallback !== undefined) {
675
- target[finalStep.key] = structuredClone(fallback);
676
- }
677
- }
678
- }
679
- }
680
- function setDefaultPath(root, path, value, source) {
681
- const current = getPathValue(root, path);
682
- if (current !== undefined) {
683
- return;
684
- }
685
- let finalValue = value;
686
- if (source === 'timestamp_seconds') {
687
- finalValue = Math.floor(Date.now() / 1000);
688
- }
689
- else if (source === 'chat_completion_id') {
690
- finalValue = `chatcmpl_${Date.now().toString(36)}_${Math.random().toString(36).slice(2)}`;
691
- }
692
- if (finalValue === undefined) {
693
- return;
694
- }
695
- setPath(root, path, finalValue);
696
- }
697
- function normalizeToolChoice(root, mapping) {
698
- const path = mapping.path || 'tool_choice';
699
- const current = getPathValue(root, path);
700
- if (!current || typeof current !== 'object' || Array.isArray(current)) {
701
- return;
702
- }
703
- const replacement = mapping.objectReplacement ?? 'required';
704
- setPath(root, path, replacement);
705
- }
706
- function injectInstruction(root, mapping) {
707
- const raw = getPathValue(root, mapping.sourcePath);
708
- removePath(root, mapping.sourcePath);
709
- const value = typeof raw === 'string' ? raw.trim() : '';
710
- if (!value) {
711
- return;
712
- }
713
- let text = value;
714
- if (mapping.stripHtml) {
715
- text = stripHtml(text);
716
- }
717
- const maxLength = resolveMaxLength(mapping.maxLengthEnv);
718
- if (maxLength && text.length > maxLength) {
719
- text = text.slice(0, maxLength);
720
- }
721
- if (!text) {
722
- return;
723
- }
724
- const targetPath = mapping.targetPath || 'input';
725
- const targetArray = ensureArray(root, targetPath);
726
- const message = {
727
- type: 'message',
728
- role: mapping.role || 'system',
729
- content: [
730
- {
731
- type: mapping.contentType || 'input_text',
732
- text
733
- }
734
- ]
735
- };
736
- targetArray.unshift(message);
737
- }
738
- function resolveTargets(root, steps) {
739
- if (!steps.length) {
740
- return [root];
741
- }
742
- const results = [];
743
- const traverse = (node, index) => {
744
- const step = steps[index];
745
- if (!step || !isRecord(node)) {
746
- return;
747
- }
748
- const next = node[step.key];
749
- if (step.wildcard && Array.isArray(next)) {
750
- if (index === steps.length - 1) {
751
- for (const child of next) {
752
- if (isRecord(child)) {
753
- results.push(child);
754
- }
755
- }
756
- }
757
- else {
758
- for (const child of next) {
759
- traverse(child, index + 1);
760
- }
761
- }
762
- return;
763
- }
764
- if (!step.wildcard && isRecord(next)) {
765
- if (index === steps.length - 1) {
766
- results.push(next);
767
- }
768
- else {
769
- traverse(next, index + 1);
770
- }
771
- }
772
- };
773
- traverse(root, 0);
774
- return results;
775
- }
776
- function isRecord(value) {
777
- return typeof value === 'object' && value !== null;
778
- }
779
- function ensureArray(root, path) {
780
- const steps = parsePath(path);
781
- if (!steps.length) {
782
- throw new Error(`Invalid array path: ${path}`);
783
- }
784
- let cursor = root;
785
- for (let i = 0; i < steps.length; i++) {
786
- const step = steps[i];
787
- if (step.wildcard) {
788
- throw new Error(`Array path does not support wildcards: ${path}`);
789
- }
790
- if (i === steps.length - 1) {
791
- if (!Array.isArray(cursor[step.key])) {
792
- cursor[step.key] = [];
793
- }
794
- if (!Array.isArray(cursor[step.key])) {
795
- cursor[step.key] = [];
796
- }
797
- return cursor[step.key];
798
- }
799
- if (!isRecord(cursor[step.key])) {
800
- cursor[step.key] = {};
801
- }
802
- cursor = cursor[step.key];
803
- }
804
- throw new Error(`Failed to resolve array path: ${path}`);
805
- }
806
- function stripHtml(value) {
807
- return value.replace(/<\/?[^>]+(>|$)/g, '');
8
+ const trimmed = profileId.trim();
9
+ return trimmed.length ? trimmed : undefined;
808
10
  }
809
- function resolveMaxLength(envVars) {
810
- if (!envVars || !envVars.length) {
811
- return undefined;
11
+ function toCompatResult(payload, appliedProfile) {
12
+ if (typeof appliedProfile === 'string' && appliedProfile.trim().length) {
13
+ return { payload, appliedProfile: appliedProfile.trim() };
812
14
  }
813
- for (const envName of envVars) {
814
- if (!envName)
815
- continue;
816
- const raw = process.env[envName];
817
- if (!raw) {
818
- continue;
819
- }
820
- const parsed = Number(raw);
821
- if (Number.isFinite(parsed) && parsed > 0) {
822
- return Math.floor(parsed);
823
- }
824
- }
825
- return undefined;
15
+ return { payload };
826
16
  }
827
- function convertResponsesOutputToChoices(root) {
828
- if (!isRecord(root)) {
829
- return;
830
- }
831
- const existingChoices = root.choices;
832
- if (Array.isArray(existingChoices) && existingChoices.length > 0) {
833
- return;
834
- }
835
- const choicesFromOutput = buildChoicesFromResponsesOutput(root);
836
- if (choicesFromOutput.length > 0) {
837
- root.choices = choicesFromOutput;
838
- return;
839
- }
840
- const fallbackText = extractOutputText(root);
841
- if (typeof fallbackText === 'string') {
842
- root.choices = [
843
- {
844
- index: 0,
845
- finish_reason: normalizeFinishReason(typeof root.status === 'string' ? root.status : 'stop'),
846
- message: {
847
- role: 'assistant',
848
- content: fallbackText
849
- }
850
- }
851
- ];
17
+ export function runRequestCompatPipeline(profileId, payload, options) {
18
+ const explicitProfile = normalizeProfileId(profileId);
19
+ if (!explicitProfile) {
20
+ return { payload };
852
21
  }
853
- }
854
- function buildChoicesFromResponsesOutput(root) {
855
- const outputEntries = Array.isArray(root.output) ? root.output : [];
856
- const choices = [];
857
- outputEntries.forEach((entry) => {
858
- if (!isRecord(entry)) {
859
- return;
860
- }
861
- if ('type' in entry && typeof entry.type === 'string' && entry.type !== 'message') {
862
- return;
863
- }
864
- const choice = convertOutputEntryToChoice(entry, choices.length, root);
865
- if (choice) {
866
- choices.push(choice);
867
- }
22
+ const nativeCompat = runReqOutboundStage3CompatWithNative({
23
+ payload,
24
+ explicitProfile,
25
+ adapterContext: buildNativeReqOutboundCompatAdapterContext(options?.adapterContext)
868
26
  });
869
- return choices;
27
+ return toCompatResult(nativeCompat.payload, nativeCompat.appliedProfile);
870
28
  }
871
- function convertOutputEntryToChoice(entry, index, root) {
872
- const message = buildMessageFromOutputEntry(entry, index);
873
- if (!message) {
874
- return null;
29
+ export function runResponseCompatPipeline(profileId, payload, options) {
30
+ const explicitProfile = normalizeProfileId(profileId);
31
+ if (!explicitProfile) {
32
+ return { payload };
875
33
  }
876
- const finishReasonCandidate = (typeof entry.stop_reason === 'string' && entry.stop_reason) ||
877
- (typeof entry.finish_reason === 'string' && entry.finish_reason) ||
878
- (typeof entry.status === 'string' && entry.status) ||
879
- (typeof root.status === 'string' && root.status) ||
880
- 'stop';
881
- const hasToolCalls = message &&
882
- typeof message === 'object' &&
883
- Array.isArray(message.tool_calls) &&
884
- message.tool_calls.length > 0;
885
- return {
886
- index,
887
- finish_reason: hasToolCalls ? 'tool_calls' : normalizeFinishReason(finishReasonCandidate),
888
- message
889
- };
890
- }
891
- function buildMessageFromOutputEntry(entry, choiceIndex) {
892
- const role = normalizeRole(typeof entry.role === 'string' ? entry.role : 'assistant');
893
- const contentArray = Array.isArray(entry.content) ? entry.content : [];
894
- const textSegments = [];
895
- const toolCalls = [];
896
- contentArray.forEach((part, partIndex) => {
897
- if (!isRecord(part)) {
898
- const fallback = coerceText(part);
899
- if (fallback) {
900
- textSegments.push(fallback);
901
- }
902
- return;
903
- }
904
- const type = typeof part.type === 'string'
905
- ? part.type
906
- : typeof part.content_type === 'string'
907
- ? part.content_type
908
- : '';
909
- switch (type) {
910
- case 'output_text': {
911
- const txt = typeof part.text === 'string'
912
- ? part.text
913
- : coerceText(part.text);
914
- if (txt) {
915
- textSegments.push(txt);
916
- }
917
- break;
918
- }
919
- case 'tool_call': {
920
- const normalized = normalizeToolCall(part, choiceIndex, toolCalls.length);
921
- if (normalized) {
922
- toolCalls.push(normalized);
923
- }
924
- break;
925
- }
926
- case 'input_text':
927
- case 'reasoning_content': {
928
- const txt = typeof part.text === 'string'
929
- ? part.text
930
- : coerceText(part.text);
931
- if (txt) {
932
- textSegments.push(txt);
933
- }
934
- break;
935
- }
936
- default: {
937
- const fallback = coerceText(part);
938
- if (fallback) {
939
- textSegments.push(fallback);
940
- }
941
- break;
942
- }
943
- }
34
+ const nativeCompat = runRespInboundStage3CompatWithNative({
35
+ payload,
36
+ explicitProfile,
37
+ adapterContext: buildNativeReqOutboundCompatAdapterContext(options?.adapterContext)
944
38
  });
945
- const message = {
946
- role,
947
- content: textSegments.join('')
948
- };
949
- if (toolCalls.length) {
950
- message.tool_calls = toolCalls;
951
- if (typeof message.content !== 'string') {
952
- message.content = '';
953
- }
954
- }
955
- return message;
956
- }
957
- function normalizeToolCall(part, choiceIndex, callIndex) {
958
- const payload = isRecord(part.tool_call) ? part.tool_call : part;
959
- const fnPayload = isRecord(payload.function)
960
- ? payload.function
961
- : isRecord(part.function)
962
- ? part.function
963
- : null;
964
- const name = typeof fnPayload?.name === 'string' ? fnPayload.name : undefined;
965
- if (!name) {
966
- return null;
967
- }
968
- const rawArgs = fnPayload?.arguments;
969
- let argString;
970
- if (typeof rawArgs === 'string') {
971
- argString = rawArgs;
972
- }
973
- else {
974
- try {
975
- argString = JSON.stringify(rawArgs ?? {});
976
- }
977
- catch {
978
- argString = '{}';
979
- }
980
- }
981
- const idCandidate = (typeof payload.id === 'string' && payload.id) ||
982
- (typeof payload.tool_call_id === 'string'
983
- ? payload.tool_call_id
984
- : undefined) ||
985
- (typeof payload.call_id === 'string'
986
- ? payload.call_id
987
- : undefined);
988
- return {
989
- id: idCandidate || `call_${choiceIndex}_${callIndex}`,
990
- type: 'function',
991
- function: {
992
- name,
993
- arguments: argString
994
- }
995
- };
996
- }
997
- function extractOutputText(root) {
998
- const textCandidate = root.output_text;
999
- if (typeof textCandidate === 'string' && textCandidate.length > 0) {
1000
- return textCandidate;
1001
- }
1002
- return undefined;
1003
- }
1004
- function normalizeRole(role) {
1005
- const normalized = role.toLowerCase();
1006
- if (normalized === 'assistant' || normalized === 'system' || normalized === 'user' || normalized === 'tool') {
1007
- return normalized;
1008
- }
1009
- return 'assistant';
1010
- }
1011
- function coerceText(value) {
1012
- if (typeof value === 'string') {
1013
- return value;
1014
- }
1015
- if (typeof value === 'number' || typeof value === 'boolean') {
1016
- return String(value);
1017
- }
1018
- if (Array.isArray(value)) {
1019
- return value.map((entry) => coerceText(entry)).join('');
1020
- }
1021
- if (isRecord(value)) {
1022
- try {
1023
- return JSON.stringify(value);
1024
- }
1025
- catch {
1026
- return '';
1027
- }
1028
- }
1029
- return '';
1030
- }
1031
- function normalizeFinishReason(reason) {
1032
- const normalized = reason.toLowerCase();
1033
- if (normalized.includes('tool')) {
1034
- return 'tool_calls';
1035
- }
1036
- if (normalized.includes('length') || normalized.includes('max_token') || normalized.includes('in_progress')) {
1037
- return 'length';
1038
- }
1039
- if (normalized.includes('filter')) {
1040
- return 'content_filter';
1041
- }
1042
- return 'stop';
1043
- }
1044
- function extractRequestId(node) {
1045
- if (typeof node.request_id === 'string') {
1046
- return node.request_id;
1047
- }
1048
- const dataNode = isRecord(node.data)
1049
- ? node.data
1050
- : undefined;
1051
- if (dataNode && typeof dataNode.request_id === 'string') {
1052
- return dataNode.request_id;
39
+ if (nativeCompat.nativeApplied === true && nativeCompat.rateLimitDetected === true) {
40
+ const err = new Error('Provider returned rate limit notice');
41
+ err.code = RATE_LIMIT_ERROR;
42
+ err.statusCode = 429;
43
+ throw err;
1053
44
  }
1054
- return undefined;
45
+ return toCompatResult(nativeCompat.payload, nativeCompat.appliedProfile);
1055
46
  }