@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
@@ -4,6 +4,7 @@ import { buildGeminiToolsFromBridge, prepareGeminiToolsForBridge } from '../../s
4
4
  import { mapAnthropicToolsToChat, mapChatToolsToAnthropicTools } from '../../shared/anthropic-message-utils.js';
5
5
  import { convertBridgeInputToChatMessages, convertMessagesToBridgeInput } from '../../shared/bridge-message-utils.js';
6
6
  import { resolveHubProtocolSpec } from '../policy/protocol-spec.js';
7
+ import { normalizeProviderProtocolTokenWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
7
8
  function clampSampleRate(value) {
8
9
  const num = typeof value === 'number' && Number.isFinite(value) ? value : 1;
9
10
  if (num <= 0)
@@ -428,16 +429,17 @@ export function applyProviderOutboundToolSurface(args) {
428
429
  if (!shouldSample(config, args.requestId)) {
429
430
  return args.payload;
430
431
  }
432
+ const normalizedProviderProtocol = normalizeProviderProtocolTokenWithNative(args.providerProtocol) ?? args.providerProtocol;
431
433
  const payload = args.payload;
432
434
  const tools = payload.tools;
433
- const candidate = buildCandidateTools({ providerProtocol: args.providerProtocol, tools });
435
+ const candidate = buildCandidateTools({ providerProtocol: normalizedProviderProtocol, tools });
434
436
  if (!candidate) {
435
437
  // Still allow history/tool-call surface observation even when tool definitions don't need conversion.
436
438
  }
437
439
  const stageBase = `hub_toolsurface.${config.mode}.provider_outbound`;
438
440
  const toolSchemaCandidate = candidate?.candidateTools;
439
441
  const schemaDiff = candidate ? computeToolSchemaDiff(tools, toolSchemaCandidate) : { diffCount: 0, diffHead: [] };
440
- const expectedHistoryCarrier = resolveExpectedHistoryCarrier(args.providerProtocol);
442
+ const expectedHistoryCarrier = resolveExpectedHistoryCarrier(normalizedProviderProtocol);
441
443
  let historyReason = undefined;
442
444
  let historyBaseline = undefined;
443
445
  let historyCandidate = undefined;
@@ -492,7 +494,7 @@ export function applyProviderOutboundToolSurface(args) {
492
494
  }
493
495
  args.stageRecorder?.record(stageBase, {
494
496
  kind: 'provider_outbound',
495
- providerProtocol: args.providerProtocol,
497
+ providerProtocol: normalizedProviderProtocol,
496
498
  reason: candidate?.reason ?? historyReason,
497
499
  diffCount: totalDiffCount,
498
500
  diffHead: diffHeadMerged,
@@ -1,14 +1,4 @@
1
+ import { evaluateResponsesHostPolicyWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
1
2
  export function evaluateResponsesHostPolicy(context, targetProtocol) {
2
- const protocol = typeof targetProtocol === 'string' && targetProtocol.trim()
3
- ? targetProtocol
4
- : (typeof context?.targetProtocol === 'string' && context.targetProtocol.trim()
5
- ? context.targetProtocol
6
- : 'responses');
7
- const normalized = protocol.toLowerCase();
8
- const shouldStrip = normalized !== 'openai-responses' &&
9
- normalized !== 'responses';
10
- return {
11
- shouldStripHostManagedFields: shouldStrip,
12
- targetProtocol: normalized
13
- };
3
+ return evaluateResponsesHostPolicyWithNative(context, targetProtocol);
14
4
  }
@@ -7,6 +7,7 @@ import { buildResponsesOutputFromChat } from '../../shared/responses-output-buil
7
7
  import { consumeResponsesPayloadSnapshot, consumeResponsesPassthrough } from '../../shared/responses-reasoning-registry.js';
8
8
  import { sanitizeResponsesFunctionName, stripInternalToolingMetadata } from '../../shared/responses-tool-utils.js';
9
9
  import { ProviderProtocolError } from '../../shared/errors.js';
10
+ import { normalizeResponsesToolCallArgumentsForClientWithNative } from '../../../router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js';
10
11
  function isPlainObject(value) {
11
12
  return Boolean(value && typeof value === 'object' && !Array.isArray(value));
12
13
  }
@@ -267,90 +268,13 @@ function normalizeResponsesToolCallArgumentsForClient(responsesPayload, context)
267
268
  if (!toolsRaw.length) {
268
269
  return;
269
270
  }
270
- const toolIndex = buildClientToolIndex(toolsRaw);
271
- if (!toolIndex.size) {
272
- return;
273
- }
274
- const normalizeCallArgs = (toolName, argsRaw) => {
275
- const spec = toolIndex.get(toolName);
276
- if (!spec)
277
- return argsRaw;
278
- // format:"freeform" means client expects raw text (not JSON) in the arguments field.
279
- if (typeof spec.format === 'string' && spec.format.trim().toLowerCase() === 'freeform') {
280
- const rawText = extractFreeformTextFromArgs(argsRaw);
281
- if (rawText && rawText.trim().length) {
282
- return rawText;
283
- }
284
- return argsRaw;
285
- }
286
- // Schema-aware key alignment for common server-side tools.
287
- const params = spec.parameters;
288
- if (!params)
289
- return argsRaw;
290
- const schema = extractJsonSchemaLike(params);
291
- if (!schema)
292
- return argsRaw;
293
- const parsed = tryParseJson(argsRaw);
294
- if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
295
- return argsRaw;
296
- }
297
- const record = parsed;
298
- const repaired = repairToolArgsBySchemaKeys(toolName, record, schema);
299
- if (!repaired) {
300
- return argsRaw;
301
- }
302
- try {
303
- return JSON.stringify(repaired);
304
- }
305
- catch {
306
- return argsRaw;
307
- }
308
- };
309
- // 1) output[] function_call items
310
- const output = Array.isArray(responsesPayload.output) ? responsesPayload.output : [];
311
- for (const item of output) {
312
- if (!item || typeof item !== 'object')
313
- continue;
314
- const type = typeof item.type === 'string' ? String(item.type).trim().toLowerCase() : '';
315
- if (type !== 'function_call')
316
- continue;
317
- const name = typeof item.name === 'string' ? String(item.name).trim() : '';
318
- if (!name)
319
- continue;
320
- const targetName = resolveClientToolName(toolIndex, name);
321
- if (!targetName)
322
- continue;
323
- if (targetName !== name) {
324
- item.name = targetName;
325
- }
326
- item.arguments = normalizeCallArgs(targetName, item.arguments);
327
- }
328
- // 2) required_action.submit_tool_outputs.tool_calls[] tool calls
329
- const toolCalls = responsesPayload?.required_action?.submit_tool_outputs?.tool_calls;
330
- const calls = Array.isArray(toolCalls) ? toolCalls : [];
331
- for (const call of calls) {
332
- if (!call || typeof call !== 'object')
333
- continue;
334
- const fn = call.function && typeof call.function === 'object' && !Array.isArray(call.function) ? call.function : null;
335
- const name = (typeof fn?.name === 'string' ? String(fn.name).trim() : '') ||
336
- (typeof call.name === 'string' ? String(call.name).trim() : '');
337
- if (!name)
338
- continue;
339
- const targetName = resolveClientToolName(toolIndex, name);
340
- if (!targetName)
341
- continue;
342
- if (typeof call.name === 'string' && call.name !== targetName) {
343
- call.name = targetName;
344
- }
345
- if (fn && typeof fn === 'object' && fn.name !== targetName) {
346
- fn.name = targetName;
347
- }
348
- const normalizedArgs = normalizeCallArgs(targetName, fn?.arguments ?? call.arguments);
349
- if (fn && typeof fn === 'object') {
350
- fn.arguments = normalizedArgs;
271
+ const normalized = normalizeResponsesToolCallArgumentsForClientWithNative(responsesPayload, toolsRaw);
272
+ for (const key of Object.keys(responsesPayload)) {
273
+ if (!Object.prototype.hasOwnProperty.call(normalized, key)) {
274
+ delete responsesPayload[key];
351
275
  }
352
- call.arguments = normalizedArgs;
353
276
  }
277
+ Object.assign(responsesPayload, normalized);
354
278
  }
355
279
  function unwrapData(value) {
356
280
  let current = value;
@@ -5,6 +5,7 @@ import type { ToolCallIdStyle } from '../../shared/responses-tool-utils.js';
5
5
  export type Unknown = Record<string, unknown>;
6
6
  export interface ResponsesRequestContext extends Unknown {
7
7
  requestId?: string;
8
+ targetProtocol?: string;
8
9
  originalSystemMessages?: string[];
9
10
  input?: BridgeInputItem[];
10
11
  include?: unknown;
@@ -3,13 +3,15 @@ import os from 'node:os';
3
3
  import path from 'node:path';
4
4
  import { ensureBridgeInstructions } from '../shared/bridge-instructions.js';
5
5
  import { evaluateResponsesHostPolicy } from './responses-host-policy.js';
6
- import { convertMessagesToBridgeInput, convertBridgeInputToChatMessages } from '../shared/bridge-message-utils.js';
6
+ import { convertBridgeInputToChatMessages } from '../shared/bridge-message-utils.js';
7
7
  import { createToolCallIdTransformer, enforceToolCallIdStyle, resolveToolCallIdStyle, sanitizeResponsesFunctionName } from '../shared/responses-tool-utils.js';
8
- import { mapBridgeToolsToChat, mapChatToolsToBridge } from '../shared/tool-mapping.js';
8
+ import { mapChatToolsToBridge } from '../shared/tool-mapping.js';
9
9
  import { ProviderProtocolError } from '../shared/errors.js';
10
10
  import { readRuntimeMetadata } from '../shared/runtime-metadata.js';
11
11
  import { clampResponsesInputItemId } from '../shared/bridge-id-utils.js';
12
12
  import { isImagePath } from '../shared/media.js';
13
+ import { captureReqInboundResponsesContextSnapshotWithNative, mapReqInboundBridgeToolsToChatWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
14
+ import { buildBridgeHistoryWithNative } from '../../router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js';
13
15
  // --- Utilities (ported strictly) ---
14
16
  import { createBridgeActionState, runBridgeActionPipeline } from '../shared/bridge-actions.js';
15
17
  import { resolveBridgePolicy, resolvePolicyActions } from '../shared/bridge-policies.js';
@@ -236,65 +238,30 @@ function appendLocalImageBlockOnLatestUserInput(messages, context) {
236
238
  export function captureResponsesContext(payload, dto) {
237
239
  const preservedInput = cloneBridgeEntries(payload.input);
238
240
  ensureBridgeInstructions(payload);
239
- const inheritedParameters = payload.parameters && typeof payload.parameters === 'object'
240
- ? { ...payload.parameters }
241
- : {};
242
- const topLevelParameterKeys = [
243
- 'temperature',
244
- 'top_p',
245
- 'max_tokens',
246
- 'max_output_tokens',
247
- 'seed',
248
- 'logit_bias',
249
- 'user',
250
- 'parallel_tool_calls',
251
- 'tool_choice',
252
- 'response_format',
253
- 'service_tier',
254
- 'truncation',
255
- 'include',
256
- 'store',
257
- 'prompt_cache_key',
258
- 'reasoning'
259
- ];
260
- for (const key of topLevelParameterKeys) {
261
- if (payload[key] !== undefined && inheritedParameters[key] === undefined) {
262
- inheritedParameters[key] = payload[key];
263
- }
264
- }
265
- const context = {
266
- requestId: dto?.route?.requestId,
267
- input: preservedInput,
268
- include: payload.include,
269
- store: payload.store,
270
- serviceTier: payload.service_tier,
271
- truncation: payload.truncation,
272
- toolChoice: payload.tool_choice,
273
- parallelToolCalls: typeof payload.parallel_tool_calls === 'boolean' ? payload.parallel_tool_calls : undefined,
274
- metadata: (payload.metadata && typeof payload.metadata === 'object') ? payload.metadata : undefined,
275
- responseFormat: payload.response_format,
276
- stream: typeof payload.stream === 'boolean' ? payload.stream : undefined,
277
- isChatPayload: Array.isArray(payload.messages)
241
+ const requestForCapture = {
242
+ ...payload,
243
+ ...(preservedInput ? { input: preservedInput } : {})
278
244
  };
279
- if (Object.keys(inheritedParameters).length) {
280
- context.parameters = inheritedParameters;
281
- }
282
- if (typeof payload.instructions === 'string' && payload.instructions.trim().length) {
283
- context.systemInstruction = payload.instructions;
245
+ const captured = captureReqInboundResponsesContextSnapshotWithNative({
246
+ rawRequest: requestForCapture,
247
+ requestId: dto?.route?.requestId,
248
+ toolCallIdStyle: payload?.toolCallIdStyle ?? payload?.metadata?.toolCallIdStyle
249
+ });
250
+ if (preservedInput) {
251
+ captured.input = preservedInput;
284
252
  }
285
- if (Array.isArray(payload.tools)) {
286
- context.toolsRaw = cloneBridgeEntries(payload.tools);
253
+ if (!captured.systemInstruction && typeof payload.instructions === 'string' && payload.instructions.trim().length) {
254
+ captured.systemInstruction = payload.instructions;
287
255
  }
288
- context.isResponsesPayload = !context.isChatPayload && Array.isArray(context.input);
289
- return context;
256
+ return captured;
290
257
  }
291
258
  export function buildChatRequestFromResponses(payload, context) {
292
259
  // V3: 对 Responses 路径仅做“形状转换”,不做参数解析/修复。
293
260
  // 将顶层 { type,name,description,parameters,strict } 归一为 OpenAI Chat tools 形状:
294
261
  // { type:'function', function:{ name,description,parameters,strict? } }
295
- const toolsNormalized = mapBridgeToolsToChat(payload.tools, {
296
- sanitizeName: sanitizeResponsesFunctionName
297
- });
262
+ const toolsNormalized = Array.isArray(context.toolsNormalized) && context.toolsNormalized.length
263
+ ? cloneBridgeEntries(context.toolsNormalized)
264
+ : mapReqInboundBridgeToolsToChatWithNative(payload.tools);
298
265
  // 不在 Responses 路径进行 MCP 工具注入;统一由 Chat 后半段治理注入
299
266
  let messages = convertBridgeInputToChatMessages({
300
267
  input: context.input,
@@ -614,7 +581,7 @@ export function buildResponsesRequestFromChat(payload, ctx, extras) {
614
581
  sanitizeBridgeHistory(normalizeBridgeHistory(envelopeMetadata?.bridgeHistory)) ??
615
582
  sanitizeBridgeHistory(fallbackHistory);
616
583
  const history = historySeed ??
617
- sanitizeBridgeHistory(convertMessagesToBridgeInput({
584
+ sanitizeBridgeHistory(buildBridgeHistoryWithNative({
618
585
  messages,
619
586
  tools: Array.isArray(out.tools) ? out.tools : undefined
620
587
  }));
@@ -4,6 +4,7 @@ import { normalizeChatMessageContent } from './chat-output-normalizer.js';
4
4
  import { mapBridgeToolsToChat, mapChatToolsToBridge } from './tool-mapping.js';
5
5
  import { jsonClone } from '../hub/types/json.js';
6
6
  import { ProviderProtocolError } from './errors.js';
7
+ import { parseLenientJsonishWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
7
8
  function isObject(v) {
8
9
  return !!v && typeof v === 'object' && !Array.isArray(v);
9
10
  }
@@ -15,6 +16,27 @@ function safeJson(v) {
15
16
  return '{}';
16
17
  }
17
18
  }
19
+ function stripOpenAIChatToolAliasFields(messages) {
20
+ for (const message of messages) {
21
+ if (!message || typeof message !== 'object') {
22
+ continue;
23
+ }
24
+ const role = String(message.role || '').toLowerCase();
25
+ if (role === 'assistant' && Array.isArray(message.tool_calls)) {
26
+ for (const call of message.tool_calls) {
27
+ if (!call || typeof call !== 'object') {
28
+ continue;
29
+ }
30
+ delete call.tool_call_id;
31
+ delete call.call_id;
32
+ }
33
+ continue;
34
+ }
35
+ if (role === 'tool') {
36
+ delete message.call_id;
37
+ }
38
+ }
39
+ }
18
40
  function sanitizeToolUseId(raw) {
19
41
  const trimmed = typeof raw === 'string' ? raw.trim() : '';
20
42
  if (!trimmed) {
@@ -186,6 +208,28 @@ const ANTHROPIC_TOP_LEVEL_FIELDS = new Set([
186
208
  'tool_choice',
187
209
  'thinking'
188
210
  ]);
211
+ const ANTHROPIC_STABLE_TOOL_SCHEMA_NAMES = new Set([
212
+ 'exec_command',
213
+ 'write_stdin',
214
+ 'apply_patch',
215
+ 'request_user_input',
216
+ 'update_plan',
217
+ 'view_image',
218
+ 'web_search',
219
+ 'clock',
220
+ 'continue_execution',
221
+ 'review'
222
+ ]);
223
+ const ANTHROPIC_STABLE_TOOL_SCHEMA_KEYS = new Map([
224
+ ['exec_command', new Set(['cmd', 'command', 'workdir', 'justification', 'login', 'max_output_tokens', 'sandbox_permissions', 'shell', 'yield_time_ms', 'tty', 'prefix_rule'])],
225
+ ['write_stdin', new Set(['session_id', 'chars', 'text', 'yield_time_ms', 'max_output_tokens'])],
226
+ ['apply_patch', new Set(['patch', 'input', 'instructions', 'text', 'file', 'changes'])],
227
+ ['request_user_input', new Set(['questions'])],
228
+ ['update_plan', new Set(['explanation', 'plan'])],
229
+ ['view_image', new Set(['path'])],
230
+ ['web_search', new Set(['query', 'q', 'domains', 'recency'])],
231
+ ['clock', new Set(['action', 'items', 'taskId'])]
232
+ ]);
189
233
  export function normalizeAnthropicToolName(value) {
190
234
  if (typeof value !== 'string') {
191
235
  return undefined;
@@ -505,6 +549,7 @@ export function buildOpenAIChatFromAnthropic(payload) {
505
549
  catch {
506
550
  // ignore policy failures
507
551
  }
552
+ stripOpenAIChatToolAliasFields(newMessages);
508
553
  return request;
509
554
  }
510
555
  export function buildAnthropicFromOpenAIChat(oa, options) {
@@ -564,12 +609,8 @@ export function buildAnthropicFromOpenAIChat(oa, options) {
564
609
  const argsRaw = fn.arguments;
565
610
  let input;
566
611
  if (typeof argsRaw === 'string') {
567
- try {
568
- input = JSON.parse(argsRaw);
569
- }
570
- catch {
571
- input = { _raw: argsRaw };
572
- }
612
+ const parsed = parseLenientJsonishWithNative(argsRaw);
613
+ input = parsed && typeof parsed === 'object' ? parsed : { _raw: argsRaw };
573
614
  }
574
615
  else {
575
616
  input = argsRaw ?? {};
@@ -991,12 +1032,8 @@ export function buildAnthropicRequestFromOpenAIChat(chatReq) {
991
1032
  const argsRaw = fn.arguments;
992
1033
  let input;
993
1034
  if (typeof argsRaw === 'string') {
994
- try {
995
- input = JSON.parse(argsRaw);
996
- }
997
- catch {
998
- input = { _raw: argsRaw };
999
- }
1035
+ const parsed = parseLenientJsonishWithNative(argsRaw);
1036
+ input = parsed && typeof parsed === 'object' ? parsed : { _raw: argsRaw };
1000
1037
  }
1001
1038
  else {
1002
1039
  input = argsRaw ?? {};
@@ -1095,6 +1132,107 @@ function cloneAnthropicSchema(value) {
1095
1132
  }
1096
1133
  return { type: 'object', properties: {} };
1097
1134
  }
1135
+ function normalizeAnthropicSchemaType(value) {
1136
+ if (typeof value === 'string') {
1137
+ const trimmed = value.trim().toLowerCase();
1138
+ if (trimmed === 'string' ||
1139
+ trimmed === 'number' ||
1140
+ trimmed === 'integer' ||
1141
+ trimmed === 'boolean' ||
1142
+ trimmed === 'object' ||
1143
+ trimmed === 'array') {
1144
+ return trimmed;
1145
+ }
1146
+ return undefined;
1147
+ }
1148
+ if (Array.isArray(value)) {
1149
+ for (const entry of value) {
1150
+ const normalized = normalizeAnthropicSchemaType(entry);
1151
+ if (normalized) {
1152
+ return normalized;
1153
+ }
1154
+ }
1155
+ }
1156
+ return undefined;
1157
+ }
1158
+ function compactAnthropicPropertySchema(schema) {
1159
+ if (!isPlainRecord(schema)) {
1160
+ return { type: 'string' };
1161
+ }
1162
+ const out = {};
1163
+ const type = normalizeAnthropicSchemaType(schema.type);
1164
+ if (type) {
1165
+ out.type = type;
1166
+ }
1167
+ if (typeof schema.description === 'string' && schema.description.trim()) {
1168
+ out.description = schema.description;
1169
+ }
1170
+ const enumRaw = Array.isArray(schema.enum) ? schema.enum : undefined;
1171
+ if (enumRaw && enumRaw.length) {
1172
+ const enumValues = enumRaw
1173
+ .filter((entry) => {
1174
+ const entryType = typeof entry;
1175
+ return entryType === 'string' || entryType === 'number' || entryType === 'boolean';
1176
+ })
1177
+ .slice(0, 64);
1178
+ if (enumValues.length) {
1179
+ out.enum = enumValues;
1180
+ if (!out.type) {
1181
+ const inferred = typeof enumValues[0];
1182
+ out.type = inferred === 'boolean' ? 'boolean' : inferred === 'number' ? 'number' : 'string';
1183
+ }
1184
+ }
1185
+ }
1186
+ if (out.type === 'array') {
1187
+ const items = isPlainRecord(schema.items) ? schema.items : {};
1188
+ const itemType = normalizeAnthropicSchemaType(items.type) ?? 'string';
1189
+ out.items = { type: itemType };
1190
+ }
1191
+ else if (out.type === 'object') {
1192
+ out.properties = {};
1193
+ out.additionalProperties = false;
1194
+ }
1195
+ if (!out.type) {
1196
+ out.type = 'string';
1197
+ }
1198
+ return out;
1199
+ }
1200
+ function sanitizeAnthropicBuiltinInputSchema(toolName, schemaSource) {
1201
+ const normalizedName = toolName.trim().toLowerCase();
1202
+ if (!ANTHROPIC_STABLE_TOOL_SCHEMA_NAMES.has(normalizedName)) {
1203
+ return cloneAnthropicSchema(schemaSource);
1204
+ }
1205
+ const source = cloneAnthropicSchema(schemaSource);
1206
+ const sourceProperties = isPlainRecord(source.properties) ? source.properties : {};
1207
+ const allowedKeys = ANTHROPIC_STABLE_TOOL_SCHEMA_KEYS.get(normalizedName);
1208
+ const sanitizedProperties = {};
1209
+ for (const [key, value] of Object.entries(sourceProperties)) {
1210
+ if (allowedKeys && !allowedKeys.has(key)) {
1211
+ continue;
1212
+ }
1213
+ sanitizedProperties[key] = compactAnthropicPropertySchema(value);
1214
+ }
1215
+ const required = Array.isArray(source.required)
1216
+ ? source.required.filter((entry) => typeof entry === 'string' && entry.trim().length > 0)
1217
+ : [];
1218
+ const filteredRequired = allowedKeys
1219
+ ? required.filter((key) => allowedKeys.has(key))
1220
+ : required;
1221
+ for (const key of filteredRequired) {
1222
+ if (!Object.prototype.hasOwnProperty.call(sanitizedProperties, key)) {
1223
+ sanitizedProperties[key] = { type: 'string' };
1224
+ }
1225
+ }
1226
+ const output = {
1227
+ type: 'object',
1228
+ properties: sanitizedProperties,
1229
+ additionalProperties: false
1230
+ };
1231
+ if (filteredRequired.length) {
1232
+ output.required = Array.from(new Set(filteredRequired));
1233
+ }
1234
+ return output;
1235
+ }
1098
1236
  function prepareAnthropicBridgeTools(rawTools, missing) {
1099
1237
  if (!Array.isArray(rawTools) || rawTools.length === 0) {
1100
1238
  return undefined;
@@ -1151,7 +1289,7 @@ function convertBridgeToolToAnthropic(def) {
1151
1289
  ? def.description
1152
1290
  : undefined;
1153
1291
  const schemaSource = fnNode?.parameters ?? def.parameters;
1154
- const inputSchema = cloneAnthropicSchema(schemaSource);
1292
+ const inputSchema = sanitizeAnthropicBuiltinInputSchema(name, schemaSource);
1155
1293
  const tool = {
1156
1294
  name,
1157
1295
  input_schema: inputSchema
@@ -1,154 +1,10 @@
1
1
  import { buildShellDescription, hasApplyPatchToolDeclared, isShellToolName } from '../../tools/tool-description-utils.js';
2
+ import { normalizeArgsBySchemaWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
2
3
  function isObject(v) {
3
4
  return !!v && typeof v === 'object' && !Array.isArray(v);
4
5
  }
5
- const normKey = (k) => k.toLowerCase().replace(/[^a-z0-9]+/g, '');
6
- function getDefaultAliases(prop) {
7
- const p = prop.toLowerCase();
8
- switch (p) {
9
- case 'file_path': return ['path', 'file', 'filepath', 'filePath'];
10
- case 'pattern': return ['glob', 'include', 'includes', 'query', 'regex'];
11
- case 'content': return ['text', 'data', 'body'];
12
- case 'old_string': return ['old', 'from', 'before', 'oldString', 'previous'];
13
- case 'new_string': return ['new', 'to', 'after', 'newString', 'next'];
14
- case 'command': return ['cmd', 'command_list', 'commandList'];
15
- case 'path': return ['dir', 'directory'];
16
- case 'glob': return ['include', 'includes', 'patterns'];
17
- case 'todos': return ['items', 'list', 'tasks'];
18
- case 'replace_all': return ['replaceAll', 'all', 'allOccurrences'];
19
- default: return [];
20
- }
21
- }
22
- function buildPropertyMap(schema) {
23
- const map = new Map();
24
- const props = schema?.properties || {};
25
- for (const [p, s] of Object.entries(props)) {
26
- map.set(normKey(p), p);
27
- const aliases = s['x-aliases'];
28
- if (Array.isArray(aliases)) {
29
- for (const a of aliases) {
30
- if (typeof a === 'string') {
31
- map.set(normKey(a), p);
32
- }
33
- }
34
- }
35
- for (const a of getDefaultAliases(p)) {
36
- map.set(normKey(a), p);
37
- }
38
- }
39
- return map;
40
- }
41
- function coerceType(value, schema) {
42
- const t = schema?.type;
43
- const want = Array.isArray(t) ? t[0] : t;
44
- if (!want) {
45
- return value;
46
- }
47
- switch (want) {
48
- case 'string':
49
- if (typeof value === 'string')
50
- return value;
51
- if (Array.isArray(value))
52
- return value.map(v => String(v)).join(' ');
53
- if (value === null || value === undefined)
54
- return value;
55
- return String(value);
56
- case 'number':
57
- if (typeof value === 'number')
58
- return value;
59
- if (typeof value === 'string') {
60
- const n = Number(value);
61
- return Number.isFinite(n) ? n : value;
62
- }
63
- return value;
64
- case 'integer':
65
- if (typeof value === 'number')
66
- return Math.trunc(value);
67
- if (typeof value === 'string') {
68
- const n = parseInt(value, 10);
69
- return Number.isFinite(n) ? n : value;
70
- }
71
- return value;
72
- case 'boolean':
73
- if (typeof value === 'boolean')
74
- return value;
75
- if (typeof value === 'string') {
76
- const s = value.toLowerCase();
77
- if (s === 'true')
78
- return true;
79
- if (s === 'false')
80
- return false;
81
- }
82
- return value;
83
- case 'array':
84
- if (Array.isArray(value))
85
- return value;
86
- if (typeof value === 'string') {
87
- // conservative: split commas/newlines; caller controls format
88
- const parts = value.split(/[\n,]+/).map(s => s.trim()).filter(Boolean);
89
- return parts.length ? parts : value;
90
- }
91
- return value;
92
- case 'object':
93
- if (value && typeof value === 'object')
94
- return value;
95
- return value;
96
- default:
97
- return value;
98
- }
99
- }
100
6
  export function normalizeArgsBySchema(input, schema) {
101
- if (!schema || !schema.properties || !isObject(input)) {
102
- const ok = !!(isObject(input) && Object.keys(input).length > 0);
103
- return ok ? { ok: true, value: input } : { ok: false, errors: ['no_schema_or_invalid_input'] };
104
- }
105
- const propMap = buildPropertyMap(schema);
106
- const out = {};
107
- const errors = [];
108
- const additional = schema.additionalProperties !== false;
109
- const reqList = Array.isArray(schema.required) ? schema.required : [];
110
- if (Object.keys(input).length === 1 && typeof input._raw === 'string' && reqList.length === 1) {
111
- const only = reqList[0];
112
- const child = (schema.properties || {})[only];
113
- if (child) {
114
- const coerced = coerceType(input._raw, child);
115
- if (typeof coerced === 'string' && coerced.trim().length > 0)
116
- out[only] = coerced;
117
- }
118
- }
119
- for (const [k, v] of Object.entries(input)) {
120
- const key = normKey(k);
121
- const target = propMap.get(key);
122
- if (target) {
123
- const childSchema = schema.properties[target];
124
- out[target] = coerceType(v, childSchema);
125
- }
126
- else if (additional) {
127
- out[k] = v;
128
- }
129
- }
130
- const req = schema.required || [];
131
- for (const r of req) {
132
- if (!(r in out)) {
133
- errors.push(`missing_required:${r}`);
134
- continue;
135
- }
136
- const v = out[r];
137
- if (typeof v === 'string' && v.trim().length === 0) {
138
- errors.push(`missing_required:${r}`);
139
- continue;
140
- }
141
- if (Array.isArray(v) && v.length === 0) {
142
- errors.push(`missing_required:${r}`);
143
- continue;
144
- }
145
- if (v && typeof v === 'object' && !Array.isArray(v) && Object.keys(v).length === 0) {
146
- errors.push(`missing_required:${r}`);
147
- continue;
148
- }
149
- }
150
- const ok = errors.length === 0;
151
- return ok ? { ok, value: out } : { ok, value: out, errors };
7
+ return normalizeArgsBySchemaWithNative(input, schema);
152
8
  }
153
9
  // Tools normalizer (OpenAI-like)
154
10
  export function normalizeTools(tools) {