@jsonstudio/llms 0.6.2172 → 0.6.3214

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 (524) hide show
  1. package/README.md +2 -0
  2. package/dist/conversion/args-mapping.js +8 -0
  3. package/dist/conversion/bridge-actions.js +367 -0
  4. package/dist/conversion/bridge-id-utils.js +13 -0
  5. package/dist/conversion/{shared/bridge-instructions.js → bridge-instructions.js} +2 -1
  6. package/dist/conversion/{shared/bridge-message-utils.d.ts → bridge-message-utils.d.ts} +1 -1
  7. package/dist/conversion/{shared/bridge-message-utils.js → bridge-message-utils.js} +5 -150
  8. package/dist/conversion/{shared/bridge-metadata.d.ts → bridge-metadata.d.ts} +1 -0
  9. package/dist/conversion/bridge-metadata.js +5 -0
  10. package/dist/conversion/bridge-policies.js +11 -0
  11. package/dist/conversion/codecs/gemini-openai-codec.js +27 -8
  12. package/dist/conversion/codecs/responses-openai-codec.js +1 -1
  13. package/dist/conversion/{shared/compaction-detect.d.ts → compaction-detect.d.ts} +1 -1
  14. package/dist/conversion/compaction-detect.js +4 -0
  15. package/dist/conversion/compat/actions/apply-patch-fixer.js +2 -2
  16. package/dist/conversion/compat/actions/deepseek-web-response.d.ts +0 -1
  17. package/dist/conversion/compat/actions/deepseek-web-response.js +15 -405
  18. package/dist/conversion/compat/actions/harvest-tool-calls-from-text.js +1 -1
  19. package/dist/conversion/compat/actions/lmstudio-responses-fc-ids.js +1 -1
  20. package/dist/conversion/compat/actions/qwen-transform.js +74 -2
  21. package/dist/conversion/compat/actions/snapshot.js +1 -1
  22. package/dist/conversion/compat/antigravity-session-signature.js +71 -1
  23. package/dist/conversion/compat/profiles/chat-deepseek-web.json +0 -22
  24. package/dist/conversion/compat/profiles/chat-gemini-cli.json +0 -7
  25. package/dist/conversion/compat/profiles/chat-gemini.json +0 -6
  26. package/dist/conversion/compat/profiles/chat-glm.json +251 -72
  27. package/dist/conversion/compat/profiles/chat-iflow.json +174 -39
  28. package/dist/conversion/compat/profiles/chat-lmstudio.json +43 -14
  29. package/dist/conversion/hub/core/detour-registry.d.ts +2 -0
  30. package/dist/conversion/hub/core/hub-context.d.ts +3 -1
  31. package/dist/conversion/hub/core/index.d.ts +1 -0
  32. package/dist/conversion/hub/core/stage-driver.js +2 -0
  33. package/dist/conversion/hub/format-adapters/anthropic-format-adapter.js +15 -4
  34. package/dist/conversion/hub/format-adapters/chat-format-adapter.js +15 -4
  35. package/dist/conversion/hub/format-adapters/gemini-format-adapter.js +15 -4
  36. package/dist/conversion/hub/format-adapters/responses-format-adapter.js +15 -4
  37. package/dist/conversion/hub/hub-feature.js +3 -2
  38. package/dist/conversion/hub/node-support.js +9 -4
  39. package/dist/conversion/hub/operation-table/operation-table-runner.js +12 -8
  40. package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +3 -3
  41. package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +16 -13
  42. package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +6 -10
  43. package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +21 -73
  44. package/dist/conversion/hub/ops/operations.js +2 -121
  45. package/dist/conversion/hub/pipeline/compat/compat-engine.js +6 -0
  46. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.d.ts +1 -1
  47. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +33 -1042
  48. package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.js +2 -0
  49. package/dist/conversion/hub/pipeline/compat/compat-profile-store.js +2 -0
  50. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +14 -17
  51. package/dist/conversion/hub/pipeline/compat/native-adapter-context.d.ts +3 -0
  52. package/dist/conversion/hub/pipeline/compat/native-adapter-context.js +39 -0
  53. package/dist/conversion/hub/pipeline/hub-pipeline.d.ts +1 -0
  54. package/dist/conversion/hub/pipeline/hub-pipeline.js +165 -265
  55. package/dist/conversion/hub/pipeline/session-identifiers.js +6 -196
  56. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.d.ts +1 -2
  57. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js +37 -1
  58. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.d.ts +1 -1
  59. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +69 -81
  60. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.d.ts +14 -0
  61. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.js +24 -0
  62. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.d.ts +2 -0
  63. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.js +157 -0
  64. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.d.ts +16 -0
  65. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.js +29 -0
  66. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-factories.js +3 -1
  67. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.d.ts +2 -15
  68. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +8 -595
  69. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.d.ts +8 -0
  70. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.js +28 -0
  71. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.d.ts +2 -0
  72. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.js +4 -0
  73. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.d.ts +10 -0
  74. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.js +12 -0
  75. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.d.ts +3 -0
  76. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.js +30 -0
  77. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +9 -129
  78. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.d.ts +1 -4
  79. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.js +9 -26
  80. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +32 -14
  81. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.d.ts +2 -2
  82. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +48 -8
  83. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +20 -3
  84. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +11 -199
  85. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.d.ts +3 -0
  86. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.js +81 -0
  87. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.d.ts +1 -2
  88. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.js +36 -1
  89. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_semantic_map/index.js +3 -1
  90. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.d.ts +6 -0
  91. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.js +17 -0
  92. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.d.ts +9 -0
  93. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.js +28 -0
  94. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.d.ts +1 -2
  95. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +14 -102
  96. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage2_sse_stream/index.js +3 -1
  97. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +54 -39
  98. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +18 -5
  99. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.d.ts +11 -1
  100. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.js +10 -32
  101. package/dist/conversion/hub/pipeline/stages/utils.js +17 -1
  102. package/dist/conversion/hub/pipeline/target-utils.js +14 -91
  103. package/dist/conversion/hub/pipelines/inbound.js +3 -1
  104. package/dist/conversion/hub/pipelines/outbound.js +2 -0
  105. package/dist/conversion/hub/policy/policy-engine.js +9 -3
  106. package/dist/conversion/hub/policy/protocol-spec.js +21 -149
  107. package/dist/conversion/hub/process/chat-process-anthropic-alias.d.ts +2 -0
  108. package/dist/conversion/hub/process/chat-process-anthropic-alias.js +36 -0
  109. package/dist/conversion/hub/process/chat-process-clock-directive-parser.d.ts +5 -0
  110. package/dist/conversion/hub/process/chat-process-clock-directive-parser.js +48 -0
  111. package/dist/conversion/hub/process/chat-process-clock-directives.d.ts +24 -0
  112. package/dist/conversion/hub/process/chat-process-clock-directives.js +98 -0
  113. package/dist/conversion/hub/process/chat-process-clock-reminder-directives.d.ts +8 -0
  114. package/dist/conversion/hub/process/chat-process-clock-reminder-directives.js +42 -0
  115. package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.d.ts +14 -0
  116. package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.js +10 -0
  117. package/dist/conversion/hub/process/chat-process-clock-reminder-messages.d.ts +5 -0
  118. package/dist/conversion/hub/process/chat-process-clock-reminder-messages.js +10 -0
  119. package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.d.ts +30 -0
  120. package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.js +68 -0
  121. package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.d.ts +9 -0
  122. package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.js +18 -0
  123. package/dist/conversion/hub/process/chat-process-clock-reminders.d.ts +2 -0
  124. package/dist/conversion/hub/process/chat-process-clock-reminders.js +104 -0
  125. package/dist/conversion/hub/process/chat-process-clock-tool-schemas.d.ts +3 -0
  126. package/dist/conversion/hub/process/chat-process-clock-tool-schemas.js +233 -0
  127. package/dist/conversion/hub/process/chat-process-clock-tools.d.ts +6 -0
  128. package/dist/conversion/hub/process/chat-process-clock-tools.js +41 -0
  129. package/dist/conversion/hub/process/chat-process-continue-execution.d.ts +11 -0
  130. package/dist/conversion/hub/process/chat-process-continue-execution.js +82 -0
  131. package/dist/conversion/hub/process/chat-process-governance-context.d.ts +15 -0
  132. package/dist/conversion/hub/process/chat-process-governance-context.js +7 -0
  133. package/dist/conversion/hub/process/chat-process-governance-finalize.d.ts +16 -0
  134. package/dist/conversion/hub/process/chat-process-governance-finalize.js +11 -0
  135. package/dist/conversion/hub/process/chat-process-governance-orchestration.d.ts +9 -0
  136. package/dist/conversion/hub/process/chat-process-governance-orchestration.js +47 -0
  137. package/dist/conversion/hub/process/chat-process-governed-control-ops.d.ts +8 -0
  138. package/dist/conversion/hub/process/chat-process-governed-control-ops.js +5 -0
  139. package/dist/conversion/hub/process/chat-process-governed-filter-call.d.ts +12 -0
  140. package/dist/conversion/hub/process/chat-process-governed-filter-call.js +18 -0
  141. package/dist/conversion/hub/process/chat-process-governed-merge.d.ts +8 -0
  142. package/dist/conversion/hub/process/chat-process-governed-merge.js +11 -0
  143. package/dist/conversion/hub/process/chat-process-media.d.ts +3 -0
  144. package/dist/conversion/hub/process/chat-process-media.js +18 -0
  145. package/dist/conversion/hub/process/chat-process-node-result.d.ts +23 -0
  146. package/dist/conversion/hub/process/chat-process-node-result.js +24 -0
  147. package/dist/conversion/hub/process/chat-process-pending-tool-sync.d.ts +14 -0
  148. package/dist/conversion/hub/process/chat-process-pending-tool-sync.js +52 -0
  149. package/dist/conversion/hub/process/chat-process-post-governed-normalization.d.ts +8 -0
  150. package/dist/conversion/hub/process/chat-process-post-governed-normalization.js +16 -0
  151. package/dist/conversion/hub/process/chat-process-review.d.ts +2 -0
  152. package/dist/conversion/hub/process/chat-process-review.js +8 -0
  153. package/dist/conversion/hub/process/chat-process-servertool-orchestration.d.ts +8 -0
  154. package/dist/conversion/hub/process/chat-process-servertool-orchestration.js +22 -0
  155. package/dist/conversion/hub/process/chat-process-tool-normalization.d.ts +2 -0
  156. package/dist/conversion/hub/process/chat-process-tool-normalization.js +4 -0
  157. package/dist/conversion/hub/process/chat-process-web-search-intent.d.ts +12 -0
  158. package/dist/conversion/hub/process/chat-process-web-search-intent.js +13 -0
  159. package/dist/conversion/hub/process/chat-process-web-search-tool-schema.d.ts +3 -0
  160. package/dist/conversion/hub/process/chat-process-web-search-tool-schema.js +4 -0
  161. package/dist/conversion/hub/process/chat-process-web-search.d.ts +8 -0
  162. package/dist/conversion/hub/process/chat-process-web-search.js +26 -0
  163. package/dist/conversion/hub/process/chat-process.d.ts +2 -19
  164. package/dist/conversion/hub/process/chat-process.js +12 -1701
  165. package/dist/conversion/hub/process/client-inject-readiness.d.ts +1 -0
  166. package/dist/conversion/hub/process/client-inject-readiness.js +4 -0
  167. package/dist/conversion/hub/registry.js +5 -2
  168. package/dist/conversion/hub/response/chat-response-utils.js +5 -86
  169. package/dist/conversion/hub/response/provider-response.d.ts +9 -0
  170. package/dist/conversion/hub/response/provider-response.js +20 -26
  171. package/dist/conversion/hub/response/response-mappers.js +25 -27
  172. package/dist/conversion/hub/response/response-runtime.js +30 -98
  173. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.d.ts +1 -0
  174. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +1 -0
  175. package/dist/conversion/hub/semantic-mappers/chat-mapper.d.ts +1 -0
  176. package/dist/conversion/hub/semantic-mappers/chat-mapper.js +1 -0
  177. package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +1 -0
  178. package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +1 -0
  179. package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +1 -0
  180. package/dist/conversion/hub/semantic-mappers/responses-mapper.js +1 -0
  181. package/dist/conversion/hub/snapshot-recorder.js +11 -4
  182. package/dist/conversion/hub/standardized-bridge.js +11 -288
  183. package/dist/conversion/hub/tool-governance/engine.d.ts +8 -0
  184. package/dist/conversion/hub/tool-governance/engine.js +25 -63
  185. package/dist/conversion/hub/tool-governance/rules.js +73 -69
  186. package/dist/conversion/hub/tool-session-compat.d.ts +2 -2
  187. package/dist/conversion/hub/tool-session-compat.js +17 -231
  188. package/dist/conversion/hub/tool-surface/tool-surface-engine.js +6 -4
  189. package/dist/conversion/index.d.ts +1 -2
  190. package/dist/conversion/index.js +1 -2
  191. package/dist/conversion/jsonish.js +20 -0
  192. package/dist/conversion/mcp-injection.js +7 -0
  193. package/dist/conversion/media.js +4 -0
  194. package/dist/conversion/{shared/metadata-passthrough.d.ts → metadata-passthrough.d.ts} +1 -1
  195. package/dist/conversion/metadata-passthrough.js +20 -0
  196. package/dist/conversion/payload-budget.js +47 -0
  197. package/dist/conversion/protocol-field-allowlists.d.ts +7 -0
  198. package/dist/conversion/protocol-field-allowlists.js +9 -0
  199. package/dist/conversion/{shared/protocol-state.d.ts → protocol-state.d.ts} +2 -2
  200. package/dist/conversion/protocol-state.js +27 -0
  201. package/dist/conversion/{shared/errors.d.ts → provider-protocol-error.d.ts} +0 -3
  202. package/dist/conversion/provider-protocol-error.js +25 -0
  203. package/dist/conversion/responses/responses-host-policy.js +2 -12
  204. package/dist/conversion/responses/responses-openai-bridge/response-payload.js +14 -87
  205. package/dist/conversion/responses/responses-openai-bridge/types.d.ts +2 -1
  206. package/dist/conversion/responses/responses-openai-bridge.d.ts +1 -1
  207. package/dist/conversion/responses/responses-openai-bridge.js +62 -62
  208. package/dist/conversion/{shared/runtime-metadata.d.ts → runtime-metadata.d.ts} +1 -1
  209. package/dist/conversion/runtime-metadata.js +31 -0
  210. package/dist/conversion/shared/anthropic-message-utils.js +170 -21
  211. package/dist/conversion/shared/chat-envelope-validator.js +2 -126
  212. package/dist/conversion/shared/chat-output-normalizer.js +2 -54
  213. package/dist/conversion/shared/chat-request-filters.d.ts +3 -4
  214. package/dist/conversion/shared/chat-request-filters.js +22 -78
  215. package/dist/conversion/shared/gemini-tool-utils.d.ts +1 -1
  216. package/dist/conversion/shared/gemini-tool-utils.js +9 -524
  217. package/dist/conversion/shared/openai-finalizer.js +3 -1
  218. package/dist/conversion/shared/openai-message-normalize.js +13 -285
  219. package/dist/conversion/shared/output-content-normalizer.js +9 -112
  220. package/dist/conversion/shared/reasoning-mapping.js +2 -6
  221. package/dist/conversion/shared/reasoning-normalizer.js +10 -1
  222. package/dist/conversion/shared/reasoning-tool-normalizer.js +14 -126
  223. package/dist/conversion/shared/reasoning-tool-parser.js +4 -87
  224. package/dist/conversion/shared/reasoning-utils.js +7 -8
  225. package/dist/conversion/shared/responses-conversation-store.js +5 -83
  226. package/dist/conversion/shared/responses-output-builder.js +63 -55
  227. package/dist/conversion/shared/responses-reasoning-registry.d.ts +14 -2
  228. package/dist/conversion/shared/responses-reasoning-registry.js +41 -7
  229. package/dist/conversion/shared/responses-request-adapter.d.ts +7 -1
  230. package/dist/conversion/shared/responses-request-adapter.js +14 -1
  231. package/dist/conversion/shared/responses-response-utils.js +103 -14
  232. package/dist/conversion/shared/responses-tool-utils.d.ts +1 -0
  233. package/dist/conversion/shared/responses-tool-utils.js +91 -15
  234. package/dist/conversion/shared/streaming-text-extractor.js +2 -7
  235. package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +2 -2
  236. package/dist/conversion/shared/text-markup-normalizer/normalize.js +43 -17
  237. package/dist/conversion/shared/text-markup-normalizer.d.ts +3 -2
  238. package/dist/conversion/shared/text-markup-normalizer.js +2 -1
  239. package/dist/conversion/shared/thought-signature-validator.js +3 -2
  240. package/dist/conversion/shared/tool-argument-repairer.js +2 -2
  241. package/dist/conversion/shared/tool-call-id-manager.js +5 -7
  242. package/dist/conversion/shared/tool-call-utils.js +3 -45
  243. package/dist/conversion/shared/tool-filter-pipeline.js +5 -100
  244. package/dist/conversion/shared/tool-governor.d.ts +6 -0
  245. package/dist/conversion/shared/tool-governor.js +45 -127
  246. package/dist/conversion/shared/tool-harvester.js +2 -8
  247. package/dist/conversion/shared/tool-mapping.d.ts +1 -1
  248. package/dist/conversion/shared/tool-mapping.js +2 -5
  249. package/dist/conversion/shared/tooling.d.ts +0 -4
  250. package/dist/conversion/shared/tooling.js +18 -0
  251. package/dist/conversion/{shared/snapshot-utils.d.ts → snapshot-utils.d.ts} +11 -0
  252. package/dist/conversion/{shared/snapshot-utils.js → snapshot-utils.js} +14 -23
  253. package/dist/conversion/{shared → types}/bridge-message-types.d.ts +2 -0
  254. package/dist/conversion/types/text-markup-normalizer.d.ts +13 -0
  255. package/dist/filters/special/request-tools-normalize.js +1 -1
  256. package/dist/filters/special/response-tool-text-canonicalize.js +2 -2
  257. package/dist/native/router_hotpath_napi.node +0 -0
  258. package/dist/quota/quota-manager.js +31 -59
  259. package/dist/quota/quota-state.js +14 -7
  260. package/dist/router/virtual-router/bootstrap/profile-builder.d.ts +1 -0
  261. package/dist/router/virtual-router/bootstrap/profile-builder.js +13 -0
  262. package/dist/router/virtual-router/bootstrap/provider-normalization.d.ts +2 -0
  263. package/dist/router/virtual-router/bootstrap/provider-normalization.js +4 -1
  264. package/dist/router/virtual-router/bootstrap/streaming-helpers.d.ts +7 -0
  265. package/dist/router/virtual-router/bootstrap/streaming-helpers.js +44 -0
  266. package/dist/router/virtual-router/bootstrap.js +2 -0
  267. package/dist/router/virtual-router/engine/provider-key/parse.d.ts +1 -6
  268. package/dist/router/virtual-router/engine/provider-key/parse.js +1 -43
  269. package/dist/router/virtual-router/engine/routing-state/store.d.ts +1 -2
  270. package/dist/router/virtual-router/engine/routing-state/store.js +50 -14
  271. package/dist/router/virtual-router/engine-legacy/config.d.ts +11 -0
  272. package/dist/router/virtual-router/engine-legacy/config.js +108 -0
  273. package/dist/router/virtual-router/engine-legacy/direct-model.d.ts +10 -0
  274. package/dist/router/virtual-router/engine-legacy/direct-model.js +38 -0
  275. package/dist/router/virtual-router/engine-legacy/health.d.ts +13 -0
  276. package/dist/router/virtual-router/engine-legacy/health.js +104 -0
  277. package/dist/router/virtual-router/engine-legacy/helpers.d.ts +16 -0
  278. package/dist/router/virtual-router/engine-legacy/helpers.js +226 -0
  279. package/dist/router/virtual-router/engine-legacy/route-finalize.d.ts +9 -0
  280. package/dist/router/virtual-router/engine-legacy/route-finalize.js +84 -0
  281. package/dist/router/virtual-router/engine-legacy/route-selection.d.ts +17 -0
  282. package/dist/router/virtual-router/engine-legacy/route-selection.js +205 -0
  283. package/dist/router/virtual-router/engine-legacy/route-state-allowlist.d.ts +3 -0
  284. package/dist/router/virtual-router/engine-legacy/route-state-allowlist.js +36 -0
  285. package/dist/router/virtual-router/engine-legacy/route-state.d.ts +12 -0
  286. package/dist/router/virtual-router/engine-legacy/route-state.js +386 -0
  287. package/dist/router/virtual-router/engine-legacy/route-utils.d.ts +19 -0
  288. package/dist/router/virtual-router/engine-legacy/route-utils.js +212 -0
  289. package/dist/router/virtual-router/engine-legacy/routing.d.ts +8 -0
  290. package/dist/router/virtual-router/engine-legacy/routing.js +8 -0
  291. package/dist/router/virtual-router/engine-legacy/selection-core.d.ts +28 -0
  292. package/dist/router/virtual-router/engine-legacy/selection-core.js +112 -0
  293. package/dist/router/virtual-router/engine-legacy/selection-state.d.ts +16 -0
  294. package/dist/router/virtual-router/engine-legacy/selection-state.js +187 -0
  295. package/dist/router/virtual-router/engine-legacy/state-accessors.d.ts +21 -0
  296. package/dist/router/virtual-router/engine-legacy/state-accessors.js +118 -0
  297. package/dist/router/virtual-router/engine-legacy.d.ts +123 -0
  298. package/dist/router/virtual-router/engine-legacy.js +194 -0
  299. package/dist/router/virtual-router/engine-logging.d.ts +2 -0
  300. package/dist/router/virtual-router/engine-logging.js +11 -5
  301. package/dist/router/virtual-router/engine-selection/alias-selection.js +45 -83
  302. package/dist/router/virtual-router/engine-selection/key-parsing.js +9 -26
  303. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.d.ts +20 -0
  304. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.js +163 -0
  305. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.d.ts +7 -0
  306. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.js +103 -0
  307. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.d.ts +10 -0
  308. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.js +110 -0
  309. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.d.ts +8 -0
  310. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.js +281 -0
  311. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.d.ts +1 -0
  312. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.js +25 -0
  313. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.d.ts +4 -0
  314. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.js +44 -0
  315. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.d.ts +2 -0
  316. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.js +62 -0
  317. package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.d.ts +40 -0
  318. package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.js +484 -0
  319. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.d.ts +9 -0
  320. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.js +64 -0
  321. package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.d.ts +5 -0
  322. package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.js +163 -0
  323. package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.d.ts +1 -0
  324. package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.js +49 -0
  325. package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.d.ts +30 -0
  326. package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.js +446 -0
  327. package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.d.ts +1 -0
  328. package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.js +49 -0
  329. package/dist/router/virtual-router/engine-selection/native-chat-request-filter-semantics.d.ts +1 -0
  330. package/dist/router/virtual-router/engine-selection/native-chat-request-filter-semantics.js +54 -0
  331. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +134 -0
  332. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +729 -0
  333. package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.d.ts +72 -0
  334. package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js +405 -0
  335. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.d.ts +18 -0
  336. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js +317 -0
  337. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.d.ts +22 -0
  338. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-governance-semantics.js +154 -0
  339. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.d.ts +22 -0
  340. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.js +426 -0
  341. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.d.ts +57 -0
  342. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.js +705 -0
  343. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.d.ts +46 -0
  344. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js +503 -0
  345. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.d.ts +146 -0
  346. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js +570 -0
  347. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.d.ts +25 -0
  348. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.js +148 -0
  349. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.d.ts +25 -0
  350. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js +637 -0
  351. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.d.ts +11 -0
  352. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.js +207 -0
  353. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.d.ts +3 -0
  354. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.js +128 -0
  355. package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.d.ts +57 -0
  356. package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.js +217 -0
  357. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.d.ts +5 -0
  358. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +320 -0
  359. package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.d.ts +5 -0
  360. package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.js +18 -0
  361. package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.d.ts +25 -0
  362. package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.js +85 -0
  363. package/dist/router/virtual-router/engine-selection/native-router-hotpath.d.ts +59 -0
  364. package/dist/router/virtual-router/engine-selection/native-router-hotpath.js +117 -0
  365. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +151 -0
  366. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +1371 -0
  367. package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.d.ts +2 -0
  368. package/dist/router/virtual-router/engine-selection/native-snapshot-hooks.js +69 -0
  369. package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.d.ts +16 -0
  370. package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.js +96 -0
  371. package/dist/router/virtual-router/engine-selection/native-virtual-router-engine-proxy.d.ts +16 -0
  372. package/dist/router/virtual-router/engine-selection/native-virtual-router-engine-proxy.js +14 -0
  373. package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.d.ts +2 -0
  374. package/dist/router/virtual-router/engine-selection/native-virtual-router-routing-instructions-semantics.js +86 -0
  375. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.d.ts +6 -0
  376. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.js +85 -0
  377. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.d.ts +9 -0
  378. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.js +70 -0
  379. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.d.ts +2 -0
  380. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.js +76 -0
  381. package/dist/router/virtual-router/engine-selection/route-utils.js +1 -1
  382. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.d.ts +10 -0
  383. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.js +231 -0
  384. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.d.ts +4 -0
  385. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.js +43 -0
  386. package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.d.ts +27 -0
  387. package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.js +216 -0
  388. package/dist/router/virtual-router/engine-selection/tier-selection-select.d.ts +1 -1
  389. package/dist/router/virtual-router/engine-selection/tier-selection-select.js +128 -129
  390. package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -265
  391. package/dist/router/virtual-router/engine.d.ts +22 -105
  392. package/dist/router/virtual-router/engine.js +274 -1632
  393. package/dist/router/virtual-router/features.js +2 -2
  394. package/dist/router/virtual-router/load-balancer.d.ts +8 -0
  395. package/dist/router/virtual-router/load-balancer.js +65 -2
  396. package/dist/router/virtual-router/provider-registry.js +2 -0
  397. package/dist/router/virtual-router/routing-instructions/clean.d.ts +3 -0
  398. package/dist/router/virtual-router/routing-instructions/clean.js +34 -0
  399. package/dist/router/virtual-router/routing-instructions/parse.d.ts +18 -0
  400. package/dist/router/virtual-router/routing-instructions/parse.js +377 -0
  401. package/dist/router/virtual-router/routing-instructions/state.d.ts +4 -0
  402. package/dist/router/virtual-router/routing-instructions/state.js +245 -0
  403. package/dist/router/virtual-router/routing-instructions/types.d.ts +70 -0
  404. package/dist/router/virtual-router/routing-instructions/types.js +2 -0
  405. package/dist/router/virtual-router/routing-instructions.d.ts +5 -91
  406. package/dist/router/virtual-router/routing-instructions.js +4 -628
  407. package/dist/router/virtual-router/routing-stop-message-actions.js +91 -112
  408. package/dist/router/virtual-router/routing-stop-message-parser.js +9 -132
  409. package/dist/router/virtual-router/routing-stop-message-state-codec.d.ts +1 -0
  410. package/dist/router/virtual-router/routing-stop-message-state-codec.js +58 -71
  411. package/dist/router/virtual-router/sticky-session-store.d.ts +4 -0
  412. package/dist/router/virtual-router/sticky-session-store.js +23 -83
  413. package/dist/router/virtual-router/stop-message-file-resolver.d.ts +1 -0
  414. package/dist/router/virtual-router/stop-message-file-resolver.js +10 -0
  415. package/dist/router/virtual-router/stop-message-state-sync.d.ts +1 -1
  416. package/dist/router/virtual-router/stop-message-state-sync.js +3 -7
  417. package/dist/router/virtual-router/token-counter.js +0 -9
  418. package/dist/router/virtual-router/tool-signals.js +21 -3
  419. package/dist/router/virtual-router/types.d.ts +13 -7
  420. package/dist/servertool/clock/config.js +23 -51
  421. package/dist/servertool/clock/io.js +1 -0
  422. package/dist/servertool/clock/session-scope.d.ts +2 -2
  423. package/dist/servertool/clock/session-scope.js +29 -40
  424. package/dist/servertool/engine.d.ts +9 -0
  425. package/dist/servertool/engine.js +267 -79
  426. package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +3 -3
  427. package/dist/servertool/handlers/clock-auto.js +1 -1
  428. package/dist/servertool/handlers/clock.js +2 -2
  429. package/dist/servertool/handlers/compaction-detect.d.ts +1 -1
  430. package/dist/servertool/handlers/compaction-detect.js +1 -1
  431. package/dist/servertool/handlers/continue-execution.js +8 -4
  432. package/dist/servertool/handlers/followup-request-builder.js +18 -1
  433. package/dist/servertool/handlers/gemini-empty-reply-continue.js +8 -2
  434. package/dist/servertool/handlers/iflow-model-error-retry.js +1 -1
  435. package/dist/servertool/handlers/recursive-detection-guard.js +1 -1
  436. package/dist/servertool/handlers/review.d.ts +1 -0
  437. package/dist/servertool/handlers/review.js +180 -0
  438. package/dist/servertool/handlers/stop-message-auto/blocked-report.js +59 -1
  439. package/dist/servertool/handlers/stop-message-auto/iflow-followup.d.ts +23 -2
  440. package/dist/servertool/handlers/stop-message-auto/iflow-followup.js +398 -90
  441. package/dist/servertool/handlers/stop-message-auto/routing-state.d.ts +5 -15
  442. package/dist/servertool/handlers/stop-message-auto/routing-state.js +29 -55
  443. package/dist/servertool/handlers/stop-message-auto/runtime-utils.d.ts +6 -0
  444. package/dist/servertool/handlers/stop-message-auto/runtime-utils.js +36 -62
  445. package/dist/servertool/handlers/stop-message-auto.js +393 -77
  446. package/dist/servertool/handlers/vision.js +1 -1
  447. package/dist/servertool/handlers/web-search.js +1 -1
  448. package/dist/servertool/reenter-backend.js +1 -1
  449. package/dist/servertool/server-side-tools.d.ts +1 -0
  450. package/dist/servertool/server-side-tools.js +92 -54
  451. package/dist/servertool/stop-gateway-context.js +1 -1
  452. package/dist/servertool/stop-message-compare-context.js +1 -1
  453. package/dist/servertool/types.d.ts +17 -0
  454. package/dist/sse/json-to-sse/event-generators/responses.d.ts +4 -0
  455. package/dist/sse/json-to-sse/event-generators/responses.js +95 -1
  456. package/dist/sse/json-to-sse/sequencers/responses-sequencer.js +6 -4
  457. package/dist/sse/sse-to-json/builders/response-builder.d.ts +8 -0
  458. package/dist/sse/sse-to-json/builders/response-builder.js +162 -4
  459. package/dist/sse/sse-to-json/responses-sse-to-json-converter.js +2 -0
  460. package/dist/sse/types/responses-types.d.ts +6 -2
  461. package/dist/tools/apply-patch/patch-text/normalize.js +11 -0
  462. package/dist/tools/apply-patch/structured/coercion.js +5 -0
  463. package/dist/tools/args-json.js +29 -0
  464. package/dist/tools/exec-command/validator.d.ts +4 -1
  465. package/dist/tools/exec-command/validator.js +87 -3
  466. package/dist/tools/tool-registry.d.ts +7 -1
  467. package/dist/tools/tool-registry.js +3 -2
  468. package/package.json +121 -10
  469. package/dist/conversion/shared/args-mapping.js +0 -221
  470. package/dist/conversion/shared/bridge-actions.js +0 -881
  471. package/dist/conversion/shared/bridge-id-utils.js +0 -79
  472. package/dist/conversion/shared/bridge-metadata.js +0 -1
  473. package/dist/conversion/shared/bridge-policies.js +0 -195
  474. package/dist/conversion/shared/compaction-detect.js +0 -59
  475. package/dist/conversion/shared/errors.js +0 -31
  476. package/dist/conversion/shared/jsonish.js +0 -177
  477. package/dist/conversion/shared/mcp-injection.js +0 -173
  478. package/dist/conversion/shared/media.js +0 -9
  479. package/dist/conversion/shared/metadata-passthrough.js +0 -57
  480. package/dist/conversion/shared/payload-budget.js +0 -248
  481. package/dist/conversion/shared/protocol-field-allowlists.d.ts +0 -7
  482. package/dist/conversion/shared/protocol-field-allowlists.js +0 -149
  483. package/dist/conversion/shared/protocol-state.js +0 -23
  484. package/dist/conversion/shared/runtime-metadata.js +0 -23
  485. package/dist/conversion/shared/snapshot-hooks.d.ts +0 -11
  486. package/dist/conversion/shared/snapshot-hooks.js +0 -503
  487. package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.d.ts +0 -2
  488. package/dist/conversion/shared/text-markup-normalizer/extractors-apply-patch.js +0 -129
  489. package/dist/conversion/shared/text-markup-normalizer/extractors-json.d.ts +0 -4
  490. package/dist/conversion/shared/text-markup-normalizer/extractors-json.js +0 -637
  491. package/dist/conversion/shared/text-markup-normalizer/extractors-shared.d.ts +0 -21
  492. package/dist/conversion/shared/text-markup-normalizer/extractors-shared.js +0 -177
  493. package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.d.ts +0 -5
  494. package/dist/conversion/shared/text-markup-normalizer/extractors-transcript.js +0 -385
  495. package/dist/conversion/shared/text-markup-normalizer/extractors-xml.d.ts +0 -10
  496. package/dist/conversion/shared/text-markup-normalizer/extractors-xml.js +0 -602
  497. package/dist/conversion/shared/text-markup-normalizer/extractors.d.ts +0 -5
  498. package/dist/conversion/shared/text-markup-normalizer/extractors.js +0 -4
  499. package/dist/conversion/shared/tool-canonicalizer.d.ts +0 -2
  500. package/dist/conversion/shared/tool-canonicalizer.js +0 -42
  501. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.d.ts +0 -18
  502. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.js +0 -398
  503. package/dist/servertool/handlers/stop-message-stage-policy/decision.d.ts +0 -9
  504. package/dist/servertool/handlers/stop-message-stage-policy/decision.js +0 -127
  505. package/dist/servertool/handlers/stop-message-stage-policy/observation.d.ts +0 -2
  506. package/dist/servertool/handlers/stop-message-stage-policy/observation.js +0 -179
  507. package/dist/servertool/handlers/stop-message-stage-policy/templates.d.ts +0 -4
  508. package/dist/servertool/handlers/stop-message-stage-policy/templates.js +0 -96
  509. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.d.ts +0 -9
  510. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.js +0 -89
  511. package/dist/servertool/handlers/stop-message-stage-policy/types.d.ts +0 -59
  512. package/dist/servertool/handlers/stop-message-stage-policy.d.ts +0 -3
  513. package/dist/servertool/handlers/stop-message-stage-policy.js +0 -2
  514. /package/dist/conversion/{shared/args-mapping.d.ts → args-mapping.d.ts} +0 -0
  515. /package/dist/conversion/{shared/bridge-actions.d.ts → bridge-actions.d.ts} +0 -0
  516. /package/dist/conversion/{shared/bridge-id-utils.d.ts → bridge-id-utils.d.ts} +0 -0
  517. /package/dist/conversion/{shared/bridge-instructions.d.ts → bridge-instructions.d.ts} +0 -0
  518. /package/dist/conversion/{shared/bridge-policies.d.ts → bridge-policies.d.ts} +0 -0
  519. /package/dist/conversion/{shared/jsonish.d.ts → jsonish.d.ts} +0 -0
  520. /package/dist/conversion/{shared/mcp-injection.d.ts → mcp-injection.d.ts} +0 -0
  521. /package/dist/conversion/{shared/media.d.ts → media.d.ts} +0 -0
  522. /package/dist/conversion/{shared/payload-budget.d.ts → payload-budget.d.ts} +0 -0
  523. /package/dist/conversion/{shared → types}/bridge-message-types.js +0 -0
  524. /package/dist/{servertool/handlers/stop-message-stage-policy/types.js → conversion/types/text-markup-normalizer.js} +0 -0
@@ -0,0 +1,729 @@
1
+ import { failNativeRequired, isNativeDisabledByEnv } from './native-router-hotpath-policy.js';
2
+ import { loadNativeRouterHotpathBindingForInternalUse } from './native-router-hotpath.js';
3
+ function readNativeFunction(name) {
4
+ const binding = loadNativeRouterHotpathBindingForInternalUse();
5
+ const fn = binding?.[name];
6
+ return typeof fn === 'function' ? fn : null;
7
+ }
8
+ function safeStringify(value) {
9
+ try {
10
+ return JSON.stringify(value);
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ }
16
+ function parseOutput(raw) {
17
+ try {
18
+ const parsed = JSON.parse(raw);
19
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
20
+ return null;
21
+ }
22
+ const row = parsed;
23
+ if (!Array.isArray(row.messages)) {
24
+ return null;
25
+ }
26
+ const output = {
27
+ messages: row.messages
28
+ };
29
+ if (row.rawRequest && typeof row.rawRequest === 'object' && !Array.isArray(row.rawRequest)) {
30
+ output.rawRequest = row.rawRequest;
31
+ }
32
+ if (Array.isArray(row.capturedToolResults)) {
33
+ output.capturedToolResults = row.capturedToolResults.filter((entry) => Boolean(entry) && typeof entry === 'object' && !Array.isArray(entry));
34
+ }
35
+ return output;
36
+ }
37
+ catch {
38
+ return null;
39
+ }
40
+ }
41
+ function parseBridgeHistoryOutput(raw) {
42
+ try {
43
+ const parsed = JSON.parse(raw);
44
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
45
+ return null;
46
+ }
47
+ const row = parsed;
48
+ if (!Array.isArray(row.input) || !Array.isArray(row.originalSystemMessages)) {
49
+ return null;
50
+ }
51
+ const originalSystemMessages = row.originalSystemMessages.filter((entry) => typeof entry === 'string');
52
+ if (originalSystemMessages.length !== row.originalSystemMessages.length) {
53
+ return null;
54
+ }
55
+ const output = {
56
+ input: row.input,
57
+ originalSystemMessages
58
+ };
59
+ if (typeof row.combinedSystemInstruction === 'string' && row.combinedSystemInstruction.trim().length) {
60
+ output.combinedSystemInstruction = row.combinedSystemInstruction;
61
+ }
62
+ if (typeof row.latestUserInstruction === 'string' && row.latestUserInstruction.trim().length) {
63
+ output.latestUserInstruction = row.latestUserInstruction;
64
+ }
65
+ return output;
66
+ }
67
+ catch {
68
+ return null;
69
+ }
70
+ }
71
+ function parseApplyBridgeNormalizeHistoryOutput(raw) {
72
+ try {
73
+ const parsed = JSON.parse(raw);
74
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
75
+ return null;
76
+ }
77
+ const row = parsed;
78
+ if (!Array.isArray(row.messages)) {
79
+ return null;
80
+ }
81
+ const output = {
82
+ messages: row.messages
83
+ };
84
+ if (row.bridgeHistory && typeof row.bridgeHistory === 'object' && !Array.isArray(row.bridgeHistory)) {
85
+ output.bridgeHistory = row.bridgeHistory;
86
+ }
87
+ return output;
88
+ }
89
+ catch {
90
+ return null;
91
+ }
92
+ }
93
+ function parseApplyBridgeCaptureToolResultsOutput(raw) {
94
+ try {
95
+ const parsed = JSON.parse(raw);
96
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
97
+ return null;
98
+ }
99
+ const row = parsed;
100
+ const output = {};
101
+ if (Array.isArray(row.capturedToolResults)) {
102
+ output.capturedToolResults = row.capturedToolResults.filter((entry) => Boolean(entry) && typeof entry === 'object' && !Array.isArray(entry));
103
+ }
104
+ if (row.metadata && typeof row.metadata === 'object' && !Array.isArray(row.metadata)) {
105
+ output.metadata = row.metadata;
106
+ }
107
+ return output;
108
+ }
109
+ catch {
110
+ return null;
111
+ }
112
+ }
113
+ function parseApplyBridgeEnsureToolPlaceholdersOutput(raw) {
114
+ try {
115
+ const parsed = JSON.parse(raw);
116
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
117
+ return null;
118
+ }
119
+ const row = parsed;
120
+ if (!Array.isArray(row.messages)) {
121
+ return null;
122
+ }
123
+ const output = {
124
+ messages: row.messages
125
+ };
126
+ if (Array.isArray(row.toolOutputs)) {
127
+ output.toolOutputs = row.toolOutputs.filter((entry) => Boolean(entry) && typeof entry === 'object' && !Array.isArray(entry));
128
+ }
129
+ return output;
130
+ }
131
+ catch {
132
+ return null;
133
+ }
134
+ }
135
+ function parseEnsureBridgeOutputFieldsOutput(raw) {
136
+ try {
137
+ const parsed = JSON.parse(raw);
138
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
139
+ return null;
140
+ }
141
+ const row = parsed;
142
+ if (!Array.isArray(row.messages)) {
143
+ return null;
144
+ }
145
+ return {
146
+ messages: row.messages
147
+ };
148
+ }
149
+ catch {
150
+ return null;
151
+ }
152
+ }
153
+ function parseApplyBridgeMetadataActionOutput(raw) {
154
+ try {
155
+ const parsed = JSON.parse(raw);
156
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
157
+ return null;
158
+ }
159
+ const row = parsed;
160
+ const output = {};
161
+ if (row.rawRequest && typeof row.rawRequest === 'object' && !Array.isArray(row.rawRequest)) {
162
+ output.rawRequest = row.rawRequest;
163
+ }
164
+ if (row.rawResponse && typeof row.rawResponse === 'object' && !Array.isArray(row.rawResponse)) {
165
+ output.rawResponse = row.rawResponse;
166
+ }
167
+ if (row.metadata && typeof row.metadata === 'object' && !Array.isArray(row.metadata)) {
168
+ output.metadata = row.metadata;
169
+ }
170
+ return output;
171
+ }
172
+ catch {
173
+ return null;
174
+ }
175
+ }
176
+ function parseApplyBridgeReasoningExtractOutput(raw) {
177
+ try {
178
+ const parsed = JSON.parse(raw);
179
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
180
+ return null;
181
+ }
182
+ const row = parsed;
183
+ if (!Array.isArray(row.messages)) {
184
+ return null;
185
+ }
186
+ return {
187
+ messages: row.messages
188
+ };
189
+ }
190
+ catch {
191
+ return null;
192
+ }
193
+ }
194
+ function parseApplyBridgeResponsesOutputReasoningOutput(raw) {
195
+ try {
196
+ const parsed = JSON.parse(raw);
197
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
198
+ return null;
199
+ }
200
+ const row = parsed;
201
+ if (!Array.isArray(row.messages)) {
202
+ return null;
203
+ }
204
+ return {
205
+ messages: row.messages
206
+ };
207
+ }
208
+ catch {
209
+ return null;
210
+ }
211
+ }
212
+ function parseApplyBridgeInjectSystemInstructionOutput(raw) {
213
+ try {
214
+ const parsed = JSON.parse(raw);
215
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
216
+ return null;
217
+ }
218
+ const row = parsed;
219
+ if (!Array.isArray(row.messages)) {
220
+ return null;
221
+ }
222
+ return {
223
+ messages: row.messages
224
+ };
225
+ }
226
+ catch {
227
+ return null;
228
+ }
229
+ }
230
+ function parseApplyBridgeEnsureSystemInstructionOutput(raw) {
231
+ try {
232
+ const parsed = JSON.parse(raw);
233
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
234
+ return null;
235
+ }
236
+ const row = parsed;
237
+ if (!Array.isArray(row.messages)) {
238
+ return null;
239
+ }
240
+ const output = {
241
+ messages: row.messages
242
+ };
243
+ if (row.metadata && typeof row.metadata === 'object' && !Array.isArray(row.metadata)) {
244
+ output.metadata = row.metadata;
245
+ }
246
+ return output;
247
+ }
248
+ catch {
249
+ return null;
250
+ }
251
+ }
252
+ function parseNormalizeMessageReasoningToolsOutput(raw) {
253
+ try {
254
+ const parsed = JSON.parse(raw);
255
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
256
+ return null;
257
+ }
258
+ const row = parsed;
259
+ if (!row.message || typeof row.message !== 'object' || Array.isArray(row.message)) {
260
+ return null;
261
+ }
262
+ const toolCallsAdded = typeof row.toolCallsAdded === 'number' && Number.isFinite(row.toolCallsAdded)
263
+ ? Math.max(0, Math.floor(row.toolCallsAdded))
264
+ : null;
265
+ if (toolCallsAdded === null) {
266
+ return null;
267
+ }
268
+ const output = {
269
+ message: row.message,
270
+ toolCallsAdded
271
+ };
272
+ if (typeof row.cleanedReasoning === 'string') {
273
+ output.cleanedReasoning = row.cleanedReasoning;
274
+ }
275
+ return output;
276
+ }
277
+ catch {
278
+ return null;
279
+ }
280
+ }
281
+ function parseRecord(raw) {
282
+ try {
283
+ const parsed = JSON.parse(raw);
284
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
285
+ return null;
286
+ }
287
+ return parsed;
288
+ }
289
+ catch {
290
+ return null;
291
+ }
292
+ }
293
+ export function normalizeBridgeToolCallIdsWithNative(input) {
294
+ const capability = 'normalizeBridgeToolCallIdsJson';
295
+ const fail = (reason) => failNativeRequired(capability, reason);
296
+ if (isNativeDisabledByEnv()) {
297
+ return fail('native disabled');
298
+ }
299
+ const fn = readNativeFunction(capability);
300
+ if (!fn) {
301
+ return fail();
302
+ }
303
+ const payloadJson = safeStringify({
304
+ messages: input.messages,
305
+ rawRequest: input.rawRequest,
306
+ capturedToolResults: input.capturedToolResults,
307
+ idPrefix: input.idPrefix
308
+ });
309
+ if (!payloadJson) {
310
+ return fail('json stringify failed');
311
+ }
312
+ try {
313
+ const raw = fn(payloadJson);
314
+ if (typeof raw !== 'string' || !raw) {
315
+ return fail('empty result');
316
+ }
317
+ const parsed = parseOutput(raw);
318
+ return parsed ?? fail('invalid payload');
319
+ }
320
+ catch (error) {
321
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
322
+ return fail(reason);
323
+ }
324
+ }
325
+ export function applyBridgeNormalizeToolIdentifiersWithNative(input) {
326
+ const capability = 'applyBridgeNormalizeToolIdentifiersJson';
327
+ const fail = (reason) => failNativeRequired(capability, reason);
328
+ if (isNativeDisabledByEnv()) {
329
+ return fail('native disabled');
330
+ }
331
+ const fn = readNativeFunction(capability);
332
+ if (!fn) {
333
+ return fail();
334
+ }
335
+ const payloadJson = safeStringify({
336
+ stage: input.stage,
337
+ protocol: input.protocol,
338
+ moduleType: input.moduleType,
339
+ messages: input.messages,
340
+ rawRequest: input.rawRequest,
341
+ capturedToolResults: input.capturedToolResults,
342
+ idPrefix: input.idPrefix
343
+ });
344
+ if (!payloadJson) {
345
+ return fail('json stringify failed');
346
+ }
347
+ try {
348
+ const raw = fn(payloadJson);
349
+ if (typeof raw !== 'string' || !raw) {
350
+ return fail('empty result');
351
+ }
352
+ const parsed = parseOutput(raw);
353
+ return parsed ?? fail('invalid payload');
354
+ }
355
+ catch (error) {
356
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
357
+ return fail(reason);
358
+ }
359
+ }
360
+ export function buildBridgeHistoryWithNative(input) {
361
+ const capability = 'buildBridgeHistoryJson';
362
+ const fail = (reason) => failNativeRequired(capability, reason);
363
+ if (isNativeDisabledByEnv()) {
364
+ return fail('native disabled');
365
+ }
366
+ const fn = readNativeFunction(capability);
367
+ if (!fn) {
368
+ return fail();
369
+ }
370
+ const payloadJson = safeStringify({
371
+ messages: input.messages,
372
+ tools: input.tools
373
+ });
374
+ if (!payloadJson) {
375
+ return fail('json stringify failed');
376
+ }
377
+ try {
378
+ const raw = fn(payloadJson);
379
+ if (typeof raw !== 'string' || !raw) {
380
+ return fail('empty result');
381
+ }
382
+ const parsed = parseBridgeHistoryOutput(raw);
383
+ return parsed ?? fail('invalid payload');
384
+ }
385
+ catch (error) {
386
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
387
+ return fail(reason);
388
+ }
389
+ }
390
+ export function applyBridgeNormalizeHistoryWithNative(input) {
391
+ const capability = 'applyBridgeNormalizeHistoryJson';
392
+ const fail = (reason) => failNativeRequired(capability, reason);
393
+ if (isNativeDisabledByEnv()) {
394
+ return fail('native disabled');
395
+ }
396
+ const fn = readNativeFunction(capability);
397
+ if (!fn) {
398
+ return fail();
399
+ }
400
+ const payloadJson = safeStringify({
401
+ messages: input.messages,
402
+ tools: input.tools
403
+ });
404
+ if (!payloadJson) {
405
+ return fail('json stringify failed');
406
+ }
407
+ try {
408
+ const raw = fn(payloadJson);
409
+ if (typeof raw !== 'string' || !raw) {
410
+ return fail('empty result');
411
+ }
412
+ const parsed = parseApplyBridgeNormalizeHistoryOutput(raw);
413
+ return parsed ?? fail('invalid payload');
414
+ }
415
+ catch (error) {
416
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
417
+ return fail(reason);
418
+ }
419
+ }
420
+ export function applyBridgeCaptureToolResultsWithNative(input) {
421
+ const capability = 'applyBridgeCaptureToolResultsJson';
422
+ const fail = (reason) => failNativeRequired(capability, reason);
423
+ if (isNativeDisabledByEnv()) {
424
+ return fail('native disabled');
425
+ }
426
+ const fn = readNativeFunction(capability);
427
+ if (!fn) {
428
+ return fail();
429
+ }
430
+ const payloadJson = safeStringify({
431
+ stage: input.stage,
432
+ capturedToolResults: input.capturedToolResults,
433
+ rawRequest: input.rawRequest,
434
+ rawResponse: input.rawResponse,
435
+ metadata: input.metadata
436
+ });
437
+ if (!payloadJson) {
438
+ return fail('json stringify failed');
439
+ }
440
+ try {
441
+ const raw = fn(payloadJson);
442
+ if (typeof raw !== 'string' || !raw) {
443
+ return fail('empty result');
444
+ }
445
+ const parsed = parseApplyBridgeCaptureToolResultsOutput(raw);
446
+ return parsed ?? fail('invalid payload');
447
+ }
448
+ catch (error) {
449
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
450
+ return fail(reason);
451
+ }
452
+ }
453
+ export function applyBridgeEnsureToolPlaceholdersWithNative(input) {
454
+ const capability = 'applyBridgeEnsureToolPlaceholdersJson';
455
+ const fail = (reason) => failNativeRequired(capability, reason);
456
+ if (isNativeDisabledByEnv()) {
457
+ return fail('native disabled');
458
+ }
459
+ const fn = readNativeFunction(capability);
460
+ if (!fn) {
461
+ return fail();
462
+ }
463
+ const payloadJson = safeStringify({
464
+ stage: input.stage,
465
+ messages: input.messages,
466
+ capturedToolResults: input.capturedToolResults,
467
+ rawRequest: input.rawRequest,
468
+ rawResponse: input.rawResponse
469
+ });
470
+ if (!payloadJson) {
471
+ return fail('json stringify failed');
472
+ }
473
+ try {
474
+ const raw = fn(payloadJson);
475
+ if (typeof raw !== 'string' || !raw) {
476
+ return fail('empty result');
477
+ }
478
+ const parsed = parseApplyBridgeEnsureToolPlaceholdersOutput(raw);
479
+ return parsed ?? fail('invalid payload');
480
+ }
481
+ catch (error) {
482
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
483
+ return fail(reason);
484
+ }
485
+ }
486
+ export function ensureBridgeOutputFieldsWithNative(input) {
487
+ const capability = 'ensureBridgeOutputFieldsJson';
488
+ const fail = (reason) => failNativeRequired(capability, reason);
489
+ if (isNativeDisabledByEnv()) {
490
+ return fail('native disabled');
491
+ }
492
+ const fn = readNativeFunction(capability);
493
+ if (!fn) {
494
+ return fail();
495
+ }
496
+ const payloadJson = safeStringify({
497
+ messages: input.messages,
498
+ toolFallback: input.toolFallback,
499
+ assistantFallback: input.assistantFallback
500
+ });
501
+ if (!payloadJson) {
502
+ return fail('json stringify failed');
503
+ }
504
+ try {
505
+ const raw = fn(payloadJson);
506
+ if (typeof raw !== 'string' || !raw) {
507
+ return fail('empty result');
508
+ }
509
+ const parsed = parseEnsureBridgeOutputFieldsOutput(raw);
510
+ return parsed ?? fail('invalid payload');
511
+ }
512
+ catch (error) {
513
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
514
+ return fail(reason);
515
+ }
516
+ }
517
+ export function applyBridgeMetadataActionWithNative(input) {
518
+ const capability = 'applyBridgeMetadataActionJson';
519
+ const fail = (reason) => failNativeRequired(capability, reason);
520
+ if (isNativeDisabledByEnv()) {
521
+ return fail('native disabled');
522
+ }
523
+ const fn = readNativeFunction(capability);
524
+ if (!fn) {
525
+ return fail();
526
+ }
527
+ const payloadJson = safeStringify({
528
+ actionName: input.actionName,
529
+ stage: input.stage,
530
+ options: input.options,
531
+ rawRequest: input.rawRequest,
532
+ rawResponse: input.rawResponse,
533
+ metadata: input.metadata
534
+ });
535
+ if (!payloadJson) {
536
+ return fail('json stringify failed');
537
+ }
538
+ try {
539
+ const raw = fn(payloadJson);
540
+ if (typeof raw !== 'string' || !raw) {
541
+ return fail('empty result');
542
+ }
543
+ const parsed = parseApplyBridgeMetadataActionOutput(raw);
544
+ return parsed ?? fail('invalid payload');
545
+ }
546
+ catch (error) {
547
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
548
+ return fail(reason);
549
+ }
550
+ }
551
+ export function applyBridgeReasoningExtractWithNative(input) {
552
+ const capability = 'applyBridgeReasoningExtractJson';
553
+ const fail = (reason) => failNativeRequired(capability, reason);
554
+ if (isNativeDisabledByEnv()) {
555
+ return fail('native disabled');
556
+ }
557
+ const fn = readNativeFunction(capability);
558
+ if (!fn) {
559
+ return fail();
560
+ }
561
+ const payloadJson = safeStringify({
562
+ messages: input.messages,
563
+ dropFromContent: input.dropFromContent,
564
+ idPrefixBase: input.idPrefixBase
565
+ });
566
+ if (!payloadJson) {
567
+ return fail('json stringify failed');
568
+ }
569
+ try {
570
+ const raw = fn(payloadJson);
571
+ if (typeof raw !== 'string' || !raw) {
572
+ return fail('empty result');
573
+ }
574
+ const parsed = parseApplyBridgeReasoningExtractOutput(raw);
575
+ return parsed ?? fail('invalid payload');
576
+ }
577
+ catch (error) {
578
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
579
+ return fail(reason);
580
+ }
581
+ }
582
+ export function applyBridgeResponsesOutputReasoningWithNative(input) {
583
+ const capability = 'applyBridgeResponsesOutputReasoningJson';
584
+ const fail = (reason) => failNativeRequired(capability, reason);
585
+ if (isNativeDisabledByEnv()) {
586
+ return fail('native disabled');
587
+ }
588
+ const fn = readNativeFunction(capability);
589
+ if (!fn) {
590
+ return fail();
591
+ }
592
+ const payloadJson = safeStringify({
593
+ messages: input.messages,
594
+ rawResponse: input.rawResponse,
595
+ idPrefix: input.idPrefix
596
+ });
597
+ if (!payloadJson) {
598
+ return fail('json stringify failed');
599
+ }
600
+ try {
601
+ const raw = fn(payloadJson);
602
+ if (typeof raw !== 'string' || !raw) {
603
+ return fail('empty result');
604
+ }
605
+ const parsed = parseApplyBridgeResponsesOutputReasoningOutput(raw);
606
+ return parsed ?? fail('invalid payload');
607
+ }
608
+ catch (error) {
609
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
610
+ return fail(reason);
611
+ }
612
+ }
613
+ export function applyBridgeInjectSystemInstructionWithNative(input) {
614
+ const capability = 'applyBridgeInjectSystemInstructionJson';
615
+ const fail = (reason) => failNativeRequired(capability, reason);
616
+ if (isNativeDisabledByEnv()) {
617
+ return fail('native disabled');
618
+ }
619
+ const fn = readNativeFunction(capability);
620
+ if (!fn) {
621
+ return fail();
622
+ }
623
+ const payloadJson = safeStringify({
624
+ stage: input.stage,
625
+ options: input.options,
626
+ messages: input.messages,
627
+ rawRequest: input.rawRequest
628
+ });
629
+ if (!payloadJson) {
630
+ return fail('json stringify failed');
631
+ }
632
+ try {
633
+ const raw = fn(payloadJson);
634
+ if (typeof raw !== 'string' || !raw) {
635
+ return fail('empty result');
636
+ }
637
+ const parsed = parseApplyBridgeInjectSystemInstructionOutput(raw);
638
+ return parsed ?? fail('invalid payload');
639
+ }
640
+ catch (error) {
641
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
642
+ return fail(reason);
643
+ }
644
+ }
645
+ export function applyBridgeEnsureSystemInstructionWithNative(input) {
646
+ const capability = 'applyBridgeEnsureSystemInstructionJson';
647
+ const fail = (reason) => failNativeRequired(capability, reason);
648
+ if (isNativeDisabledByEnv()) {
649
+ return fail('native disabled');
650
+ }
651
+ const fn = readNativeFunction(capability);
652
+ if (!fn) {
653
+ return fail();
654
+ }
655
+ const payloadJson = safeStringify({
656
+ stage: input.stage,
657
+ messages: input.messages,
658
+ metadata: input.metadata
659
+ });
660
+ if (!payloadJson) {
661
+ return fail('json stringify failed');
662
+ }
663
+ try {
664
+ const raw = fn(payloadJson);
665
+ if (typeof raw !== 'string' || !raw) {
666
+ return fail('empty result');
667
+ }
668
+ const parsed = parseApplyBridgeEnsureSystemInstructionOutput(raw);
669
+ return parsed ?? fail('invalid payload');
670
+ }
671
+ catch (error) {
672
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
673
+ return fail(reason);
674
+ }
675
+ }
676
+ export function normalizeMessageReasoningToolsWithNative(message, idPrefix) {
677
+ const capability = 'normalizeMessageReasoningToolsJson';
678
+ const fail = (reason) => failNativeRequired(capability, reason);
679
+ if (isNativeDisabledByEnv()) {
680
+ return fail('native disabled');
681
+ }
682
+ const fn = readNativeFunction(capability);
683
+ if (!fn) {
684
+ return fail();
685
+ }
686
+ const messageJson = safeStringify(message);
687
+ if (!messageJson) {
688
+ return fail('json stringify failed');
689
+ }
690
+ try {
691
+ const raw = fn(messageJson, typeof idPrefix === 'string' && idPrefix.trim().length ? idPrefix.trim() : undefined);
692
+ if (typeof raw !== 'string' || !raw) {
693
+ return fail('empty result');
694
+ }
695
+ const parsed = parseNormalizeMessageReasoningToolsOutput(raw);
696
+ return parsed ?? fail('invalid payload');
697
+ }
698
+ catch (error) {
699
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
700
+ return fail(reason);
701
+ }
702
+ }
703
+ export function normalizeChatResponseReasoningToolsWithNative(response, idPrefixBase) {
704
+ const capability = 'normalizeChatResponseReasoningToolsJson';
705
+ const fail = (reason) => failNativeRequired(capability, reason);
706
+ if (isNativeDisabledByEnv()) {
707
+ return fail('native disabled');
708
+ }
709
+ const fn = readNativeFunction(capability);
710
+ if (!fn) {
711
+ return fail();
712
+ }
713
+ const responseJson = safeStringify(response);
714
+ if (!responseJson) {
715
+ return fail('json stringify failed');
716
+ }
717
+ try {
718
+ const raw = fn(responseJson, typeof idPrefixBase === 'string' && idPrefixBase.trim().length ? idPrefixBase.trim() : undefined);
719
+ if (typeof raw !== 'string' || !raw) {
720
+ return fail('empty result');
721
+ }
722
+ const parsed = parseRecord(raw);
723
+ return parsed ?? fail('invalid payload');
724
+ }
725
+ catch (error) {
726
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
727
+ return fail(reason);
728
+ }
729
+ }