@jsonstudio/llms 0.6.2172 → 0.6.2979

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (362) hide show
  1. package/README.md +2 -0
  2. package/dist/conversion/compat/antigravity-session-signature.js +35 -1
  3. package/dist/conversion/compat/profiles/chat-gemini-cli.json +0 -7
  4. package/dist/conversion/compat/profiles/chat-gemini.json +0 -6
  5. package/dist/conversion/hub/core/detour-registry.d.ts +2 -0
  6. package/dist/conversion/hub/core/hub-context.d.ts +3 -1
  7. package/dist/conversion/hub/core/index.d.ts +1 -0
  8. package/dist/conversion/hub/core/stage-driver.js +2 -0
  9. package/dist/conversion/hub/format-adapters/anthropic-format-adapter.js +15 -4
  10. package/dist/conversion/hub/format-adapters/chat-format-adapter.js +15 -4
  11. package/dist/conversion/hub/format-adapters/gemini-format-adapter.js +15 -4
  12. package/dist/conversion/hub/format-adapters/responses-format-adapter.js +15 -4
  13. package/dist/conversion/hub/hub-feature.js +3 -2
  14. package/dist/conversion/hub/node-support.js +9 -4
  15. package/dist/conversion/hub/operation-table/operation-table-runner.js +10 -6
  16. package/dist/conversion/hub/operation-table/semantic-mappers/anthropic-mapper.js +2 -2
  17. package/dist/conversion/hub/operation-table/semantic-mappers/chat-mapper.js +10 -10
  18. package/dist/conversion/hub/operation-table/semantic-mappers/gemini-mapper.js +4 -8
  19. package/dist/conversion/hub/operation-table/semantic-mappers/responses-mapper.js +19 -65
  20. package/dist/conversion/hub/ops/operations.js +2 -121
  21. package/dist/conversion/hub/pipeline/compat/compat-engine.js +6 -0
  22. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.d.ts +1 -1
  23. package/dist/conversion/hub/pipeline/compat/compat-pipeline-executor.js +33 -1042
  24. package/dist/conversion/hub/pipeline/compat/compat-profile-resolver.js +2 -0
  25. package/dist/conversion/hub/pipeline/compat/compat-profile-store.js +2 -0
  26. package/dist/conversion/hub/pipeline/compat/compat-types.d.ts +14 -17
  27. package/dist/conversion/hub/pipeline/compat/native-adapter-context.d.ts +3 -0
  28. package/dist/conversion/hub/pipeline/compat/native-adapter-context.js +39 -0
  29. package/dist/conversion/hub/pipeline/hub-pipeline.js +115 -262
  30. package/dist/conversion/hub/pipeline/session-identifiers.js +6 -196
  31. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.d.ts +1 -2
  32. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage1_format_parse/index.js +37 -1
  33. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/index.js +12 -86
  34. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.d.ts +14 -0
  35. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage2_semantic_map/semantic-lift.js +24 -0
  36. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.d.ts +2 -0
  37. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/archive/shell-like-tool-call-normalization-fallback.js +157 -0
  38. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.d.ts +16 -0
  39. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-capture-orchestration.js +29 -0
  40. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/context-factories.js +3 -1
  41. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.d.ts +2 -15
  42. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/index.js +8 -595
  43. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.d.ts +8 -0
  44. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/responses-context-snapshot.js +28 -0
  45. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.d.ts +2 -0
  46. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-diagnostics.js +4 -0
  47. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.d.ts +10 -0
  48. package/dist/conversion/hub/pipeline/stages/req_inbound/req_inbound_stage3_context_capture/tool-output-snapshot.js +12 -0
  49. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.d.ts +3 -0
  50. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/context-merge.js +30 -0
  51. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage1_semantic_map/index.js +9 -129
  52. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.d.ts +1 -4
  53. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage2_format_build/index.js +9 -26
  54. package/dist/conversion/hub/pipeline/stages/req_outbound/req_outbound_stage3_compat/index.js +32 -14
  55. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.d.ts +2 -2
  56. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage1_tool_governance/index.js +48 -8
  57. package/dist/conversion/hub/pipeline/stages/req_process/req_process_stage2_route_select/index.js +18 -3
  58. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/index.js +10 -198
  59. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.d.ts +3 -0
  60. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage1_sse_decode/stream-json-sniffer.js +81 -0
  61. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.d.ts +1 -2
  62. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage2_format_parse/index.js +36 -1
  63. package/dist/conversion/hub/pipeline/stages/resp_inbound/resp_inbound_stage3_semantic_map/index.js +3 -1
  64. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.d.ts +6 -0
  65. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/chat-process-semantics-bridge.js +17 -0
  66. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.d.ts +9 -0
  67. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/client-remap-protocol-switch.js +28 -0
  68. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.d.ts +1 -2
  69. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage1_client_remap/index.js +14 -102
  70. package/dist/conversion/hub/pipeline/stages/resp_outbound/resp_outbound_stage2_sse_stream/index.js +3 -1
  71. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage1_tool_governance/index.js +12 -10
  72. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage2_finalize/index.js +6 -5
  73. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.d.ts +11 -1
  74. package/dist/conversion/hub/pipeline/stages/resp_process/resp_process_stage3_servertool_orchestration/index.js +10 -32
  75. package/dist/conversion/hub/pipeline/stages/utils.js +17 -1
  76. package/dist/conversion/hub/pipeline/target-utils.js +14 -91
  77. package/dist/conversion/hub/pipelines/inbound.js +3 -1
  78. package/dist/conversion/hub/pipelines/outbound.js +2 -0
  79. package/dist/conversion/hub/policy/policy-engine.js +9 -3
  80. package/dist/conversion/hub/policy/protocol-spec.js +20 -148
  81. package/dist/conversion/hub/process/chat-process-anthropic-alias.d.ts +2 -0
  82. package/dist/conversion/hub/process/chat-process-anthropic-alias.js +36 -0
  83. package/dist/conversion/hub/process/chat-process-clock-directive-parser.d.ts +5 -0
  84. package/dist/conversion/hub/process/chat-process-clock-directive-parser.js +48 -0
  85. package/dist/conversion/hub/process/chat-process-clock-directives.d.ts +24 -0
  86. package/dist/conversion/hub/process/chat-process-clock-directives.js +98 -0
  87. package/dist/conversion/hub/process/chat-process-clock-reminder-directives.d.ts +8 -0
  88. package/dist/conversion/hub/process/chat-process-clock-reminder-directives.js +42 -0
  89. package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.d.ts +14 -0
  90. package/dist/conversion/hub/process/chat-process-clock-reminder-finalize.js +10 -0
  91. package/dist/conversion/hub/process/chat-process-clock-reminder-messages.d.ts +5 -0
  92. package/dist/conversion/hub/process/chat-process-clock-reminder-messages.js +10 -0
  93. package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.d.ts +30 -0
  94. package/dist/conversion/hub/process/chat-process-clock-reminder-orchestration.js +68 -0
  95. package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.d.ts +9 -0
  96. package/dist/conversion/hub/process/chat-process-clock-reminder-time-tag.js +18 -0
  97. package/dist/conversion/hub/process/chat-process-clock-reminders.d.ts +2 -0
  98. package/dist/conversion/hub/process/chat-process-clock-reminders.js +104 -0
  99. package/dist/conversion/hub/process/chat-process-clock-tool-schemas.d.ts +3 -0
  100. package/dist/conversion/hub/process/chat-process-clock-tool-schemas.js +233 -0
  101. package/dist/conversion/hub/process/chat-process-clock-tools.d.ts +6 -0
  102. package/dist/conversion/hub/process/chat-process-clock-tools.js +41 -0
  103. package/dist/conversion/hub/process/chat-process-continue-execution.d.ts +11 -0
  104. package/dist/conversion/hub/process/chat-process-continue-execution.js +82 -0
  105. package/dist/conversion/hub/process/chat-process-governance-context.d.ts +15 -0
  106. package/dist/conversion/hub/process/chat-process-governance-context.js +7 -0
  107. package/dist/conversion/hub/process/chat-process-governance-finalize.d.ts +16 -0
  108. package/dist/conversion/hub/process/chat-process-governance-finalize.js +11 -0
  109. package/dist/conversion/hub/process/chat-process-governance-orchestration.d.ts +9 -0
  110. package/dist/conversion/hub/process/chat-process-governance-orchestration.js +47 -0
  111. package/dist/conversion/hub/process/chat-process-governed-control-ops.d.ts +8 -0
  112. package/dist/conversion/hub/process/chat-process-governed-control-ops.js +5 -0
  113. package/dist/conversion/hub/process/chat-process-governed-filter-call.d.ts +12 -0
  114. package/dist/conversion/hub/process/chat-process-governed-filter-call.js +18 -0
  115. package/dist/conversion/hub/process/chat-process-governed-merge.d.ts +8 -0
  116. package/dist/conversion/hub/process/chat-process-governed-merge.js +11 -0
  117. package/dist/conversion/hub/process/chat-process-media.d.ts +3 -0
  118. package/dist/conversion/hub/process/chat-process-media.js +18 -0
  119. package/dist/conversion/hub/process/chat-process-node-result.d.ts +23 -0
  120. package/dist/conversion/hub/process/chat-process-node-result.js +24 -0
  121. package/dist/conversion/hub/process/chat-process-pending-tool-sync.d.ts +14 -0
  122. package/dist/conversion/hub/process/chat-process-pending-tool-sync.js +52 -0
  123. package/dist/conversion/hub/process/chat-process-post-governed-normalization.d.ts +8 -0
  124. package/dist/conversion/hub/process/chat-process-post-governed-normalization.js +16 -0
  125. package/dist/conversion/hub/process/chat-process-review.d.ts +2 -0
  126. package/dist/conversion/hub/process/chat-process-review.js +8 -0
  127. package/dist/conversion/hub/process/chat-process-servertool-orchestration.d.ts +8 -0
  128. package/dist/conversion/hub/process/chat-process-servertool-orchestration.js +22 -0
  129. package/dist/conversion/hub/process/chat-process-tool-normalization.d.ts +2 -0
  130. package/dist/conversion/hub/process/chat-process-tool-normalization.js +4 -0
  131. package/dist/conversion/hub/process/chat-process-web-search-intent.d.ts +12 -0
  132. package/dist/conversion/hub/process/chat-process-web-search-intent.js +13 -0
  133. package/dist/conversion/hub/process/chat-process-web-search-tool-schema.d.ts +3 -0
  134. package/dist/conversion/hub/process/chat-process-web-search-tool-schema.js +4 -0
  135. package/dist/conversion/hub/process/chat-process-web-search.d.ts +8 -0
  136. package/dist/conversion/hub/process/chat-process-web-search.js +26 -0
  137. package/dist/conversion/hub/process/chat-process.d.ts +2 -19
  138. package/dist/conversion/hub/process/chat-process.js +12 -1701
  139. package/dist/conversion/hub/process/client-inject-readiness.d.ts +1 -0
  140. package/dist/conversion/hub/process/client-inject-readiness.js +4 -0
  141. package/dist/conversion/hub/registry.js +5 -2
  142. package/dist/conversion/hub/response/chat-response-utils.js +5 -86
  143. package/dist/conversion/hub/response/provider-response.d.ts +9 -0
  144. package/dist/conversion/hub/response/provider-response.js +6 -21
  145. package/dist/conversion/hub/response/response-mappers.js +2 -26
  146. package/dist/conversion/hub/response/response-runtime.js +2 -93
  147. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.d.ts +1 -0
  148. package/dist/conversion/hub/semantic-mappers/anthropic-mapper.js +1 -0
  149. package/dist/conversion/hub/semantic-mappers/chat-mapper.d.ts +1 -0
  150. package/dist/conversion/hub/semantic-mappers/chat-mapper.js +1 -0
  151. package/dist/conversion/hub/semantic-mappers/gemini-mapper.d.ts +1 -0
  152. package/dist/conversion/hub/semantic-mappers/gemini-mapper.js +1 -0
  153. package/dist/conversion/hub/semantic-mappers/responses-mapper.d.ts +1 -0
  154. package/dist/conversion/hub/semantic-mappers/responses-mapper.js +1 -0
  155. package/dist/conversion/hub/snapshot-recorder.js +10 -3
  156. package/dist/conversion/hub/standardized-bridge.js +11 -288
  157. package/dist/conversion/hub/tool-governance/engine.js +5 -0
  158. package/dist/conversion/hub/tool-governance/rules.js +10 -10
  159. package/dist/conversion/hub/tool-session-compat.d.ts +2 -2
  160. package/dist/conversion/hub/tool-session-compat.js +17 -231
  161. package/dist/conversion/hub/tool-surface/tool-surface-engine.js +5 -3
  162. package/dist/conversion/responses/responses-host-policy.js +2 -12
  163. package/dist/conversion/responses/responses-openai-bridge/response-payload.js +6 -82
  164. package/dist/conversion/responses/responses-openai-bridge/types.d.ts +1 -0
  165. package/dist/conversion/responses/responses-openai-bridge.js +21 -54
  166. package/dist/conversion/shared/anthropic-message-utils.js +151 -13
  167. package/dist/conversion/shared/args-mapping.js +2 -146
  168. package/dist/conversion/shared/bridge-actions.js +203 -718
  169. package/dist/conversion/shared/bridge-id-utils.js +5 -71
  170. package/dist/conversion/shared/bridge-instructions.js +2 -1
  171. package/dist/conversion/shared/bridge-message-types.d.ts +2 -0
  172. package/dist/conversion/shared/bridge-message-utils.js +1 -2
  173. package/dist/conversion/shared/bridge-metadata.d.ts +1 -0
  174. package/dist/conversion/shared/bridge-metadata.js +4 -0
  175. package/dist/conversion/shared/bridge-policies.js +5 -189
  176. package/dist/conversion/shared/chat-envelope-validator.js +2 -126
  177. package/dist/conversion/shared/chat-output-normalizer.js +2 -54
  178. package/dist/conversion/shared/compaction-detect.js +2 -57
  179. package/dist/conversion/shared/gemini-tool-utils.js +9 -524
  180. package/dist/conversion/shared/jsonish.js +3 -160
  181. package/dist/conversion/shared/mcp-injection.js +3 -169
  182. package/dist/conversion/shared/media.js +2 -7
  183. package/dist/conversion/shared/metadata-passthrough.js +9 -46
  184. package/dist/conversion/shared/openai-finalizer.js +2 -1
  185. package/dist/conversion/shared/openai-message-normalize.js +11 -283
  186. package/dist/conversion/shared/output-content-normalizer.js +9 -112
  187. package/dist/conversion/shared/payload-budget.js +2 -85
  188. package/dist/conversion/shared/protocol-state.js +11 -7
  189. package/dist/conversion/shared/reasoning-mapping.js +2 -6
  190. package/dist/conversion/shared/reasoning-normalizer.js +4 -1
  191. package/dist/conversion/shared/reasoning-tool-normalizer.js +14 -126
  192. package/dist/conversion/shared/reasoning-tool-parser.js +4 -87
  193. package/dist/conversion/shared/reasoning-utils.js +2 -6
  194. package/dist/conversion/shared/responses-conversation-store.js +4 -82
  195. package/dist/conversion/shared/responses-output-builder.js +11 -47
  196. package/dist/conversion/shared/responses-reasoning-registry.js +7 -1
  197. package/dist/conversion/shared/responses-request-adapter.d.ts +7 -1
  198. package/dist/conversion/shared/responses-request-adapter.js +14 -1
  199. package/dist/conversion/shared/responses-response-utils.js +6 -7
  200. package/dist/conversion/shared/responses-tool-utils.d.ts +1 -0
  201. package/dist/conversion/shared/responses-tool-utils.js +90 -14
  202. package/dist/conversion/shared/runtime-metadata.js +13 -5
  203. package/dist/conversion/shared/streaming-text-extractor.js +2 -7
  204. package/dist/conversion/shared/text-markup-normalizer/normalize.d.ts +1 -1
  205. package/dist/conversion/shared/text-markup-normalizer/normalize.js +43 -17
  206. package/dist/conversion/shared/text-markup-normalizer.d.ts +1 -0
  207. package/dist/conversion/shared/text-markup-normalizer.js +1 -0
  208. package/dist/conversion/shared/thought-signature-validator.js +3 -2
  209. package/dist/conversion/shared/tool-argument-repairer.js +2 -2
  210. package/dist/conversion/shared/tool-call-id-manager.js +5 -7
  211. package/dist/conversion/shared/tool-call-utils.js +3 -45
  212. package/dist/conversion/shared/tool-canonicalizer.js +25 -29
  213. package/dist/conversion/shared/tool-filter-pipeline.js +4 -99
  214. package/dist/conversion/shared/tool-governor.d.ts +6 -0
  215. package/dist/conversion/shared/tool-governor.js +43 -125
  216. package/dist/conversion/shared/tool-harvester.js +2 -8
  217. package/dist/conversion/shared/tool-mapping.js +2 -5
  218. package/dist/conversion/shared/tooling.d.ts +0 -4
  219. package/dist/conversion/shared/tooling.js +18 -0
  220. package/dist/native/router_hotpath_napi.node +0 -0
  221. package/dist/router/virtual-router/engine/provider-key/parse.d.ts +1 -6
  222. package/dist/router/virtual-router/engine/provider-key/parse.js +1 -43
  223. package/dist/router/virtual-router/engine/routing-state/store.js +48 -12
  224. package/dist/router/virtual-router/engine-logging.js +4 -3
  225. package/dist/router/virtual-router/engine-selection/alias-selection.js +45 -83
  226. package/dist/router/virtual-router/engine-selection/key-parsing.js +9 -23
  227. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.d.ts +20 -0
  228. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-directive-parser.js +163 -0
  229. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.d.ts +7 -0
  230. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-directives.js +103 -0
  231. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.d.ts +10 -0
  232. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-orchestration-semantics.js +110 -0
  233. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.d.ts +8 -0
  234. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-semantics.js +281 -0
  235. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.d.ts +1 -0
  236. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminder-time-tag-semantics.js +25 -0
  237. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.d.ts +4 -0
  238. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-reminders-semantics.js +44 -0
  239. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.d.ts +2 -0
  240. package/dist/router/virtual-router/engine-selection/native-chat-process-clock-tool-schema-semantics.js +62 -0
  241. package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.d.ts +40 -0
  242. package/dist/router/virtual-router/engine-selection/native-chat-process-governance-semantics.js +484 -0
  243. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.d.ts +9 -0
  244. package/dist/router/virtual-router/engine-selection/native-chat-process-governed-filter-semantics.js +64 -0
  245. package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.d.ts +5 -0
  246. package/dist/router/virtual-router/engine-selection/native-chat-process-node-result-semantics.js +163 -0
  247. package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.d.ts +1 -0
  248. package/dist/router/virtual-router/engine-selection/native-chat-process-post-governed-normalization-semantics.js +49 -0
  249. package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.d.ts +30 -0
  250. package/dist/router/virtual-router/engine-selection/native-chat-process-servertool-orchestration-semantics.js +446 -0
  251. package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.d.ts +1 -0
  252. package/dist/router/virtual-router/engine-selection/native-chat-process-web-search-intent-semantics.js +49 -0
  253. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.d.ts +134 -0
  254. package/dist/router/virtual-router/engine-selection/native-hub-bridge-action-semantics.js +729 -0
  255. package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.d.ts +62 -0
  256. package/dist/router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js +338 -0
  257. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.d.ts +18 -0
  258. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js +317 -0
  259. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.d.ts +22 -0
  260. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-inbound-outbound-semantics.js +426 -0
  261. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.d.ts +57 -0
  262. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-orchestration-semantics.js +705 -0
  263. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.d.ts +46 -0
  264. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js +503 -0
  265. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.d.ts +146 -0
  266. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-outbound-semantics.js +570 -0
  267. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.d.ts +25 -0
  268. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-req-process-semantics.js +148 -0
  269. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.d.ts +25 -0
  270. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-resp-semantics.js +637 -0
  271. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.d.ts +11 -0
  272. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-session-identifiers-semantics.js +207 -0
  273. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.d.ts +3 -0
  274. package/dist/router/virtual-router/engine-selection/native-hub-pipeline-target-semantics.js +128 -0
  275. package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.d.ts +57 -0
  276. package/dist/router/virtual-router/engine-selection/native-router-hotpath-analysis.js +217 -0
  277. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.d.ts +5 -0
  278. package/dist/router/virtual-router/engine-selection/native-router-hotpath-loader.js +284 -0
  279. package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.d.ts +5 -0
  280. package/dist/router/virtual-router/engine-selection/native-router-hotpath-policy.js +18 -0
  281. package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.d.ts +25 -0
  282. package/dist/router/virtual-router/engine-selection/native-router-hotpath-quota-buckets.js +85 -0
  283. package/dist/router/virtual-router/engine-selection/native-router-hotpath.d.ts +59 -0
  284. package/dist/router/virtual-router/engine-selection/native-router-hotpath.js +117 -0
  285. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.d.ts +76 -0
  286. package/dist/router/virtual-router/engine-selection/native-shared-conversion-semantics.js +1166 -0
  287. package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.d.ts +16 -0
  288. package/dist/router/virtual-router/engine-selection/native-virtual-router-alias-selection-semantics.js +96 -0
  289. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.d.ts +6 -0
  290. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-actions-semantics.js +85 -0
  291. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.d.ts +9 -0
  292. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-semantics.js +70 -0
  293. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.d.ts +2 -0
  294. package/dist/router/virtual-router/engine-selection/native-virtual-router-stop-message-state-semantics.js +76 -0
  295. package/dist/router/virtual-router/engine-selection/route-utils.js +1 -1
  296. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.d.ts +10 -0
  297. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-session-lease.js +231 -0
  298. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.d.ts +4 -0
  299. package/dist/router/virtual-router/engine-selection/tier-selection-antigravity-target-split.js +43 -0
  300. package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.d.ts +27 -0
  301. package/dist/router/virtual-router/engine-selection/tier-selection-quota-integration.js +116 -0
  302. package/dist/router/virtual-router/engine-selection/tier-selection-select.d.ts +1 -1
  303. package/dist/router/virtual-router/engine-selection/tier-selection-select.js +29 -129
  304. package/dist/router/virtual-router/engine-selection/tier-selection.js +2 -265
  305. package/dist/router/virtual-router/engine.js +258 -249
  306. package/dist/router/virtual-router/features.js +2 -2
  307. package/dist/router/virtual-router/routing-instructions.d.ts +5 -7
  308. package/dist/router/virtual-router/routing-instructions.js +93 -66
  309. package/dist/router/virtual-router/routing-stop-message-actions.js +91 -112
  310. package/dist/router/virtual-router/routing-stop-message-parser.js +9 -132
  311. package/dist/router/virtual-router/routing-stop-message-state-codec.d.ts +1 -0
  312. package/dist/router/virtual-router/routing-stop-message-state-codec.js +58 -71
  313. package/dist/router/virtual-router/sticky-session-store.js +4 -2
  314. package/dist/router/virtual-router/stop-message-file-resolver.d.ts +1 -0
  315. package/dist/router/virtual-router/stop-message-file-resolver.js +10 -0
  316. package/dist/router/virtual-router/stop-message-state-sync.d.ts +1 -1
  317. package/dist/router/virtual-router/stop-message-state-sync.js +3 -7
  318. package/dist/router/virtual-router/token-counter.js +0 -9
  319. package/dist/router/virtual-router/types.d.ts +9 -7
  320. package/dist/servertool/clock/config.js +23 -51
  321. package/dist/servertool/clock/io.js +1 -0
  322. package/dist/servertool/clock/session-scope.d.ts +2 -2
  323. package/dist/servertool/clock/session-scope.js +5 -47
  324. package/dist/servertool/engine.d.ts +9 -0
  325. package/dist/servertool/engine.js +196 -79
  326. package/dist/servertool/handlers/antigravity-thought-signature-bootstrap.js +2 -2
  327. package/dist/servertool/handlers/clock.js +1 -1
  328. package/dist/servertool/handlers/continue-execution.js +8 -4
  329. package/dist/servertool/handlers/followup-request-builder.js +18 -1
  330. package/dist/servertool/handlers/gemini-empty-reply-continue.js +7 -1
  331. package/dist/servertool/handlers/review.js +180 -0
  332. package/dist/servertool/handlers/stop-message-auto/blocked-report.js +59 -1
  333. package/dist/servertool/handlers/stop-message-auto/iflow-followup.d.ts +23 -2
  334. package/dist/servertool/handlers/stop-message-auto/iflow-followup.js +397 -89
  335. package/dist/servertool/handlers/stop-message-auto/routing-state.d.ts +5 -15
  336. package/dist/servertool/handlers/stop-message-auto/routing-state.js +29 -55
  337. package/dist/servertool/handlers/stop-message-auto/runtime-utils.d.ts +6 -0
  338. package/dist/servertool/handlers/stop-message-auto/runtime-utils.js +35 -61
  339. package/dist/servertool/handlers/stop-message-auto.js +392 -76
  340. package/dist/servertool/server-side-tools.d.ts +1 -0
  341. package/dist/servertool/server-side-tools.js +90 -52
  342. package/dist/servertool/types.d.ts +17 -0
  343. package/dist/tools/apply-patch/patch-text/normalize.js +11 -0
  344. package/dist/tools/exec-command/validator.d.ts +4 -1
  345. package/dist/tools/exec-command/validator.js +87 -3
  346. package/dist/tools/tool-registry.d.ts +7 -1
  347. package/dist/tools/tool-registry.js +3 -2
  348. package/package.json +115 -7
  349. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.d.ts +0 -18
  350. package/dist/servertool/handlers/stop-message-stage-policy/bd-runtime.js +0 -398
  351. package/dist/servertool/handlers/stop-message-stage-policy/decision.d.ts +0 -9
  352. package/dist/servertool/handlers/stop-message-stage-policy/decision.js +0 -127
  353. package/dist/servertool/handlers/stop-message-stage-policy/observation.d.ts +0 -2
  354. package/dist/servertool/handlers/stop-message-stage-policy/observation.js +0 -179
  355. package/dist/servertool/handlers/stop-message-stage-policy/templates.d.ts +0 -4
  356. package/dist/servertool/handlers/stop-message-stage-policy/templates.js +0 -96
  357. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.d.ts +0 -9
  358. package/dist/servertool/handlers/stop-message-stage-policy/text-utils.js +0 -89
  359. package/dist/servertool/handlers/stop-message-stage-policy/types.d.ts +0 -59
  360. package/dist/servertool/handlers/stop-message-stage-policy.d.ts +0 -3
  361. package/dist/servertool/handlers/stop-message-stage-policy.js +0 -2
  362. /package/dist/servertool/handlers/{stop-message-stage-policy/types.js → review.d.ts} +0 -0
@@ -1,79 +1,13 @@
1
- import { createHash } from 'node:crypto';
2
- const MAX_RESPONSES_ITEM_ID_LENGTH = 64;
3
- function sanitizeCore(value) {
4
- return value
5
- .replace(/[^A-Za-z0-9_-]/g, '_')
6
- .replace(/_{2,}/g, '_')
7
- .replace(/^_+/, '')
8
- .replace(/_+$/, '');
9
- }
10
- function shortHash(value) {
11
- try {
12
- return createHash('sha1').update(value).digest('hex').slice(0, 10);
13
- }
14
- catch {
15
- return Math.random().toString(36).slice(2, 12);
16
- }
17
- }
18
- function clampPrefixedId(prefix, core, hashSource) {
19
- const sanitized = sanitizeCore(core) || Math.random().toString(36).slice(2, 10);
20
- const direct = `${prefix}${sanitized}`;
21
- if (direct.length <= MAX_RESPONSES_ITEM_ID_LENGTH) {
22
- return direct;
23
- }
24
- const hash = shortHash(`${prefix}|${hashSource}|${sanitized}`);
25
- const room = Math.max(1, MAX_RESPONSES_ITEM_ID_LENGTH - prefix.length - 1 - hash.length);
26
- const head = sanitizeCore(sanitized.slice(0, room)) || 'id';
27
- return `${prefix}${head}_${hash}`;
28
- }
29
- function extractCore(value) {
30
- if (typeof value !== 'string')
31
- return null;
32
- const trimmed = value.trim();
33
- if (!trimmed)
34
- return null;
35
- let sanitized = sanitizeCore(trimmed);
36
- if (!sanitized)
37
- return null;
38
- if (/^fc[_-]/i.test(sanitized)) {
39
- sanitized = sanitized.replace(/^fc[_-]?/i, '');
40
- }
41
- else if (/^call[_-]/i.test(sanitized)) {
42
- sanitized = sanitized.replace(/^call[_-]?/i, '');
43
- }
44
- return sanitizeCore(sanitized) || null;
45
- }
46
- function normalizeWithFallback(options, prefix) {
47
- const callCore = extractCore(options.callId);
48
- if (callCore) {
49
- return clampPrefixedId(prefix, callCore, String(options.callId));
50
- }
51
- const fallbackCore = extractCore(options.fallback);
52
- if (fallbackCore) {
53
- return clampPrefixedId(prefix, fallbackCore, String(options.fallback));
54
- }
55
- const randomCore = Math.random().toString(36).slice(2, 10);
56
- return clampPrefixedId(prefix, randomCore, randomCore);
57
- }
1
+ import { clampResponsesInputItemIdWithNative, normalizeFunctionCallIdWithNative, normalizeFunctionCallOutputIdWithNative, normalizeResponsesCallIdWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
58
2
  export function normalizeFunctionCallId(options) {
59
- return normalizeWithFallback(options, 'fc_');
3
+ return normalizeFunctionCallIdWithNative(options);
60
4
  }
61
5
  export function normalizeFunctionCallOutputId(options) {
62
- return normalizeWithFallback(options, 'fc_');
6
+ return normalizeFunctionCallOutputIdWithNative(options);
63
7
  }
64
8
  export function normalizeResponsesCallId(options) {
65
- return normalizeWithFallback(options, 'call_');
9
+ return normalizeResponsesCallIdWithNative(options);
66
10
  }
67
11
  export function clampResponsesInputItemId(raw) {
68
- const trimmed = typeof raw === 'string' ? raw.trim() : '';
69
- if (!trimmed) {
70
- return undefined;
71
- }
72
- if (trimmed.length <= MAX_RESPONSES_ITEM_ID_LENGTH) {
73
- return trimmed;
74
- }
75
- const hash = shortHash(trimmed);
76
- const room = Math.max(1, MAX_RESPONSES_ITEM_ID_LENGTH - 1 - hash.length);
77
- const head = trimmed.slice(0, room);
78
- return `${head}_${hash}`;
12
+ return clampResponsesInputItemIdWithNative(raw);
79
13
  }
@@ -1,3 +1,4 @@
1
+ import { sanitizeReasoningTaggedTextWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
1
2
  function collectTextFromBlocks(blocks) {
2
3
  const parts = [];
3
4
  for (const block of blocks) {
@@ -77,7 +78,7 @@ function extractSystemInstruction(entry) {
77
78
  collected.push(text);
78
79
  }
79
80
  }
80
- const merged = collected.join('\n').trim();
81
+ const merged = sanitizeReasoningTaggedTextWithNative(collected.join('\n')).trim();
81
82
  return merged ? merged : null;
82
83
  }
83
84
  export function ensureBridgeInstructions(payload) {
@@ -1,3 +1,4 @@
1
+ import type { NativeReqInboundSemanticLiftApplyInput } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
1
2
  export type BridgeContentPart = {
2
3
  type: string;
3
4
  text?: string;
@@ -37,3 +38,4 @@ export type BridgeToolDefinition = {
37
38
  parameters?: unknown;
38
39
  };
39
40
  };
41
+ export type BridgeNativeEnvelope = NativeReqInboundSemanticLiftApplyInput['chatEnvelope'];
@@ -1,6 +1,5 @@
1
- import { normalizeFunctionCallId, normalizeFunctionCallOutputId } from './bridge-id-utils.js';
2
1
  import { normalizeChatMessageContent } from './chat-output-normalizer.js';
3
- import { repairToolArguments } from './tool-argument-repairer.js';
2
+ import { normalizeFunctionCallIdWithNative as normalizeFunctionCallId, normalizeFunctionCallOutputIdWithNative as normalizeFunctionCallOutputId, repairArgumentsToStringWithNative as repairToolArguments } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
4
3
  function ensureAssistantToolCallIdentity(call, fallbackId) {
5
4
  const resolved = (typeof call.id === 'string' && call.id.trim().length ? call.id.trim() : undefined) ??
6
5
  (typeof call.tool_call_id === 'string' && call.tool_call_id.trim().length
@@ -1 +1,2 @@
1
1
  export declare const BRIDGE_RAW_SYSTEM_METADATA_KEY = "__rcc_raw_system";
2
+ export declare function resolveBridgeMetadataNativeProtocol(): string;
@@ -1 +1,5 @@
1
1
  export const BRIDGE_RAW_SYSTEM_METADATA_KEY = '__rcc_raw_system';
2
+ import { normalizeProviderProtocolTokenWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-req-inbound-semantics.js';
3
+ export function resolveBridgeMetadataNativeProtocol() {
4
+ return normalizeProviderProtocolTokenWithNative('openai-responses') ?? 'openai-responses';
5
+ }
@@ -1,195 +1,11 @@
1
- import { RESPONSES_INSTRUCTIONS_REASONING_FIELD } from './reasoning-normalizer.js';
2
- import { ANTHROPIC_ALLOWED_FIELDS, GEMINI_ALLOWED_FIELDS, OPENAI_CHAT_ALLOWED_FIELDS, OPENAI_RESPONSES_ALLOWED_FIELDS } from './protocol-field-allowlists.js';
3
- function reasoningAction(idPrefix) {
4
- return {
5
- name: 'reasoning.extract',
6
- options: {
7
- dropFromContent: true,
8
- idPrefix
9
- }
10
- };
11
- }
12
- function toolCallNormalizationAction(idPrefix) {
13
- if (idPrefix && idPrefix.trim().length) {
14
- return {
15
- name: 'tools.normalize-call-ids',
16
- options: { idPrefix: idPrefix.trim() }
17
- };
18
- }
19
- return { name: 'tools.normalize-call-ids' };
20
- }
21
- const RESPONSES_POLICY = {
22
- id: 'openai-responses-default',
23
- protocol: 'openai-responses',
24
- request: {
25
- inbound: [
26
- {
27
- name: 'messages.inject-system-instruction',
28
- options: {
29
- field: 'instructions',
30
- reasoningField: RESPONSES_INSTRUCTIONS_REASONING_FIELD
31
- }
32
- },
33
- { name: 'messages.ensure-system-instruction' },
34
- reasoningAction('responses_reasoning'),
35
- toolCallNormalizationAction('responses_tool_call'),
36
- { name: 'tools.ensure-placeholders' },
37
- { name: 'metadata.extra-fields', options: { allowedKeys: OPENAI_RESPONSES_ALLOWED_FIELDS } },
38
- { name: 'metadata.provider-field', options: { field: 'metadata', target: 'providerMetadata' } },
39
- { name: 'metadata.provider-sentinel', options: { sentinel: '__rcc_provider_metadata', target: 'providerMetadata' } }
40
- ],
41
- outbound: [
42
- { name: 'messages.normalize-history' },
43
- { name: 'tools.capture-results' },
44
- toolCallNormalizationAction('responses_tool_call'),
45
- { name: 'tools.ensure-placeholders' },
46
- { name: 'messages.ensure-output-fields', options: { toolFallback: 'Tool call completed (no output).' } },
47
- { name: 'messages.ensure-system-instruction' },
48
- reasoningAction('responses_reasoning'),
49
- { name: 'metadata.extra-fields', options: { allowedKeys: OPENAI_RESPONSES_ALLOWED_FIELDS } },
50
- { name: 'metadata.provider-field', options: { field: 'metadata', target: 'providerMetadata' } },
51
- { name: 'metadata.provider-sentinel', options: { sentinel: '__rcc_provider_metadata', target: 'providerMetadata' } }
52
- ]
53
- },
54
- response: {
55
- inbound: [
56
- { name: 'reasoning.attach-output' },
57
- reasoningAction('responses_reasoning'),
58
- toolCallNormalizationAction('responses_tool_call'),
59
- { name: 'metadata.extra-fields', options: { allowedKeys: OPENAI_RESPONSES_ALLOWED_FIELDS } }
60
- ],
61
- outbound: [
62
- reasoningAction('responses_reasoning'),
63
- toolCallNormalizationAction('responses_tool_call'),
64
- { name: 'metadata.extra-fields', options: { allowedKeys: OPENAI_RESPONSES_ALLOWED_FIELDS } }
65
- ]
66
- }
67
- };
68
- const OPENAI_CHAT_POLICY = {
69
- id: 'openai-chat-default',
70
- protocol: 'openai-chat',
71
- request: {
72
- inbound: [
73
- reasoningAction('openai_chat_reasoning'),
74
- toolCallNormalizationAction('openai_chat_tool_call'), { name: 'compat.fix-apply-patch' },
75
- { name: 'messages.ensure-system-instruction' },
76
- { name: 'metadata.extra-fields', options: { allowedKeys: OPENAI_CHAT_ALLOWED_FIELDS } },
77
- { name: 'metadata.provider-field', options: { field: 'metadata', target: 'providerMetadata' } },
78
- { name: 'metadata.provider-sentinel', options: { sentinel: '__rcc_provider_metadata', target: 'providerMetadata' } }
79
- ],
80
- outbound: [
81
- { name: 'messages.normalize-history' },
82
- { name: 'tools.capture-results' },
83
- toolCallNormalizationAction('openai_chat_tool_call'), { name: 'compat.fix-apply-patch' },
84
- { name: 'tools.ensure-placeholders' },
85
- { name: 'messages.ensure-output-fields', options: { toolFallback: 'Tool call completed (no output).' } },
86
- { name: 'messages.ensure-system-instruction' },
87
- reasoningAction('openai_chat_reasoning'),
88
- { name: 'metadata.extra-fields', options: { allowedKeys: OPENAI_CHAT_ALLOWED_FIELDS } },
89
- { name: 'metadata.provider-field', options: { field: 'metadata', target: 'providerMetadata' } },
90
- { name: 'metadata.provider-sentinel', options: { sentinel: '__rcc_provider_metadata', target: 'providerMetadata' } }
91
- ]
92
- },
93
- response: {
94
- inbound: [
95
- reasoningAction('openai_chat_reasoning'),
96
- toolCallNormalizationAction('openai_chat_tool_call'), { name: 'compat.fix-apply-patch' },
97
- { name: 'metadata.extra-fields', options: { allowedKeys: OPENAI_CHAT_ALLOWED_FIELDS } }
98
- ],
99
- outbound: [
100
- reasoningAction('openai_chat_reasoning'),
101
- toolCallNormalizationAction('openai_chat_tool_call'), { name: 'compat.fix-apply-patch' },
102
- { name: 'metadata.extra-fields', options: { allowedKeys: OPENAI_CHAT_ALLOWED_FIELDS } }
103
- ]
104
- }
105
- };
106
- const ANTHROPIC_POLICY = {
107
- id: 'anthropic-messages-default',
108
- protocol: 'anthropic-messages',
109
- request: {
110
- inbound: [
111
- reasoningAction('anthropic_reasoning'),
112
- toolCallNormalizationAction('anthropic_tool_call'),
113
- { name: 'messages.ensure-system-instruction' },
114
- { name: 'metadata.extra-fields', options: { allowedKeys: ANTHROPIC_ALLOWED_FIELDS } }
115
- ],
116
- outbound: [
117
- { name: 'messages.normalize-history' },
118
- { name: 'tools.capture-results' },
119
- toolCallNormalizationAction('anthropic_tool_call'),
120
- { name: 'tools.ensure-placeholders' },
121
- { name: 'messages.ensure-output-fields', options: { toolFallback: 'Tool call completed (no output).' } },
122
- { name: 'messages.ensure-system-instruction' },
123
- reasoningAction('anthropic_reasoning'),
124
- { name: 'metadata.extra-fields', options: { allowedKeys: ANTHROPIC_ALLOWED_FIELDS } }
125
- ]
126
- },
127
- response: {
128
- inbound: [
129
- reasoningAction('anthropic_reasoning'),
130
- toolCallNormalizationAction('anthropic_tool_call'),
131
- { name: 'metadata.extra-fields', options: { allowedKeys: ANTHROPIC_ALLOWED_FIELDS } }
132
- ],
133
- outbound: [
134
- reasoningAction('anthropic_reasoning'),
135
- toolCallNormalizationAction('anthropic_tool_call'),
136
- { name: 'metadata.extra-fields', options: { allowedKeys: ANTHROPIC_ALLOWED_FIELDS } }
137
- ]
138
- }
139
- };
140
- const GEMINI_POLICY = {
141
- id: 'gemini-chat-default',
142
- protocol: 'gemini-chat',
143
- request: {
144
- inbound: [
145
- reasoningAction('gemini_reasoning'), { name: 'compat.fix-apply-patch' },
146
- { name: 'messages.ensure-system-instruction' },
147
- { name: 'metadata.extra-fields', options: { allowedKeys: GEMINI_ALLOWED_FIELDS } }
148
- ],
149
- outbound: [
150
- { name: 'messages.normalize-history' },
151
- { name: 'tools.capture-results' },
152
- { name: 'tools.ensure-placeholders' },
153
- { name: 'messages.ensure-output-fields', options: { toolFallback: 'Tool call completed (no output).' } },
154
- { name: 'messages.ensure-system-instruction' },
155
- reasoningAction('gemini_reasoning'), { name: 'compat.fix-apply-patch' },
156
- { name: 'metadata.extra-fields', options: { allowedKeys: GEMINI_ALLOWED_FIELDS } }
157
- ]
158
- },
159
- response: {
160
- inbound: [
161
- reasoningAction('gemini_reasoning'), { name: 'compat.fix-apply-patch' },
162
- { name: 'metadata.extra-fields', options: { allowedKeys: GEMINI_ALLOWED_FIELDS } }
163
- ],
164
- outbound: [
165
- reasoningAction('gemini_reasoning'), { name: 'compat.fix-apply-patch' },
166
- { name: 'metadata.extra-fields', options: { allowedKeys: GEMINI_ALLOWED_FIELDS } }
167
- ]
168
- }
169
- };
170
- const POLICIES = [RESPONSES_POLICY, OPENAI_CHAT_POLICY, ANTHROPIC_POLICY, GEMINI_POLICY];
1
+ import { resolveBridgePolicyActionsWithNative, resolveBridgePolicyWithNative } from '../../router/virtual-router/engine-selection/native-hub-bridge-policy-semantics.js';
171
2
  export function resolveBridgePolicy(options) {
172
- if (!options)
3
+ const resolved = resolveBridgePolicyWithNative(options);
4
+ if (!resolved) {
173
5
  return undefined;
174
- const { protocol, moduleType } = options;
175
- if (protocol) {
176
- const match = POLICIES.find((policy) => policy.protocol === protocol);
177
- if (match)
178
- return match;
179
- }
180
- if (moduleType) {
181
- const match = POLICIES.find((policy) => policy.moduleType === moduleType);
182
- if (match)
183
- return match;
184
6
  }
185
- return undefined;
7
+ return resolved;
186
8
  }
187
9
  export function resolvePolicyActions(policy, stage) {
188
- if (!policy)
189
- return undefined;
190
- const [phaseKey, directionKey] = stage.split('_');
191
- const phase = policy[phaseKey];
192
- if (!phase)
193
- return undefined;
194
- return phase[directionKey];
10
+ return resolveBridgePolicyActionsWithNative(policy, stage);
195
11
  }
@@ -1,128 +1,4 @@
1
- import { isJsonObject } from '../hub/types/json.js';
2
- const ALLOWED_ROLES = new Set(['system', 'user', 'assistant', 'tool']);
3
- const RESERVED_EXACT_KEYS = new Set(['stages', 'stageExpectations']);
4
- const RESERVED_PREFIXES = ['__rcc_'];
1
+ import { validateChatEnvelopeWithNative } from '../../router/virtual-router/engine-selection/native-hub-pipeline-edge-stage-semantics.js';
5
2
  export function validateChatEnvelope(chat, options) {
6
- if (!chat || typeof chat !== 'object') {
7
- throw buildError('chatEnvelope_missing', 'Chat envelope must be an object', options);
8
- }
9
- assertNoReservedKeys(chat, 'chatEnvelope', options);
10
- if (!Array.isArray(chat.messages) || chat.messages.length === 0) {
11
- throw buildError('messages_missing', 'Chat envelope must include at least one message', options);
12
- }
13
- chat.messages.forEach((message, index) => {
14
- if (!message || typeof message !== 'object') {
15
- throw buildError('message_shape', `messages[${index}] must be an object`, options);
16
- }
17
- assertNoReservedKeys(message, `messages[${index}]`, options);
18
- if (typeof message.role !== 'string' || !ALLOWED_ROLES.has(message.role)) {
19
- throw buildError('message_role', `messages[${index}].role must be one of ${Array.from(ALLOWED_ROLES).join(', ')}`, options);
20
- }
21
- validateToolCalls(message, index, options);
22
- });
23
- if (!isJsonObject(chat.parameters) || typeof chat.parameters.model !== 'string' || !chat.parameters.model.trim()) {
24
- throw buildError('parameters_model', 'Chat envelope parameters.model must be a string', options);
25
- }
26
- assertNoReservedKeys(chat.parameters, 'parameters', options);
27
- validateTools(chat.tools, options);
28
- validateToolOutputs(chat.toolOutputs, options);
29
- validateMetadata(chat.metadata, options);
30
- }
31
- function validateToolCalls(message, messageIndex, options) {
32
- if (!Array.isArray(message.tool_calls)) {
33
- return;
34
- }
35
- message.tool_calls.forEach((entry, callIndex) => {
36
- if (!entry || typeof entry !== 'object') {
37
- throw buildError('tool_call_shape', `messages[${messageIndex}].tool_calls[${callIndex}] must be an object`, options);
38
- }
39
- if (entry.type !== 'function') {
40
- throw buildError('tool_call_type', `messages[${messageIndex}].tool_calls[${callIndex}].type must equal "function"`, options);
41
- }
42
- const fnNode = entry.function;
43
- if (!fnNode || typeof fnNode !== 'object') {
44
- throw buildError('tool_call_function', `messages[${messageIndex}].tool_calls[${callIndex}].function must be an object`, options);
45
- }
46
- const fnRecord = fnNode;
47
- if (typeof fnRecord.name !== 'string' || !fnRecord.name.trim()) {
48
- throw buildError('tool_call_name', `messages[${messageIndex}].tool_calls[${callIndex}].function.name must be a string`, options);
49
- }
50
- if (typeof fnRecord.arguments !== 'string') {
51
- throw buildError('tool_call_arguments', `messages[${messageIndex}].tool_calls[${callIndex}].function.arguments must be a JSON string`, options);
52
- }
53
- });
54
- }
55
- function validateTools(tools, options) {
56
- if (tools === undefined) {
57
- return;
58
- }
59
- if (!Array.isArray(tools)) {
60
- throw buildError('tools_shape', 'Chat envelope tools must be an array when provided', options);
61
- }
62
- tools.forEach((tool, index) => {
63
- if (!tool || typeof tool !== 'object') {
64
- throw buildError('tools_shape', `tools[${index}] must be an object`, options);
65
- }
66
- if (tool.type !== 'function') {
67
- throw buildError('tools_type', `tools[${index}].type must equal "function"`, options);
68
- }
69
- const fnNode = tool.function;
70
- if (!fnNode || typeof fnNode !== 'object' || typeof fnNode.name !== 'string' || !fnNode.name.trim()) {
71
- throw buildError('tools_function', `tools[${index}].function.name must be a string`, options);
72
- }
73
- });
74
- }
75
- function validateToolOutputs(outputs, options) {
76
- if (outputs === undefined) {
77
- return;
78
- }
79
- if (!Array.isArray(outputs)) {
80
- throw buildError('tool_outputs_shape', 'toolOutputs must be an array when provided', options);
81
- }
82
- outputs.forEach((entry, index) => {
83
- if (!entry || typeof entry !== 'object') {
84
- throw buildError('tool_outputs_shape', `toolOutputs[${index}] must be an object`, options);
85
- }
86
- if (typeof entry.tool_call_id !== 'string' || !entry.tool_call_id.trim()) {
87
- throw buildError('tool_outputs_id', `toolOutputs[${index}].tool_call_id must be a string`, options);
88
- }
89
- if (typeof entry.content !== 'string') {
90
- throw buildError('tool_outputs_content', `toolOutputs[${index}].content must be a string`, options);
91
- }
92
- });
93
- }
94
- function validateMetadata(metadata, options) {
95
- if (!isJsonObject(metadata)) {
96
- throw buildError('metadata_shape', 'Chat envelope metadata must be an object', options);
97
- }
98
- assertNoReservedKeys(metadata, 'metadata', options);
99
- if (!isJsonObject(metadata.context)) {
100
- throw buildError('metadata_context', 'metadata.context must be an object', options);
101
- }
102
- if (metadata.extraFields !== undefined) {
103
- if (!isJsonObject(metadata.extraFields)) {
104
- throw buildError('metadata_extra_fields', 'metadata.extraFields must be an object when provided', options);
105
- }
106
- assertNoReservedKeys(metadata.extraFields, 'metadata.extraFields', options, true);
107
- }
108
- if (metadata.providerMetadata !== undefined && !isJsonObject(metadata.providerMetadata)) {
109
- throw buildError('metadata_provider', 'metadata.providerMetadata must be an object when provided', options);
110
- }
111
- }
112
- function assertNoReservedKeys(target, path, options, allowStageKeys = false) {
113
- if (!target || typeof target !== 'object') {
114
- return;
115
- }
116
- for (const key of Object.keys(target)) {
117
- if (!allowStageKeys && RESERVED_EXACT_KEYS.has(key)) {
118
- throw buildError('reserved_key', `${path} contains reserved field "${key}"`, options);
119
- }
120
- if (RESERVED_PREFIXES.some((prefix) => key.startsWith(prefix))) {
121
- throw buildError('reserved_key', `${path} contains reserved field "${key}"`, options);
122
- }
123
- }
124
- }
125
- function buildError(code, detail, options) {
126
- const source = options.source ? ` source=${options.source}` : '';
127
- return new Error(`ChatEnvelopeValidationError(${options.stage}/${options.direction})[${code}] ${detail}${source}`);
3
+ validateChatEnvelopeWithNative(chat, options);
128
4
  }
@@ -1,56 +1,4 @@
1
- import { extractReasoningSegments, sanitizeReasoningTaggedText } from './reasoning-utils.js';
2
- function collectText(value, collector) {
3
- if (value == null) {
4
- return;
5
- }
6
- if (typeof value === 'string') {
7
- const cleaned = extractReasoningSegments(value, collector.reasoningParts);
8
- if (cleaned.length) {
9
- collector.textParts.push(cleaned);
10
- }
11
- return;
12
- }
13
- if (Array.isArray(value)) {
14
- for (const entry of value) {
15
- collectText(entry, collector);
16
- }
17
- return;
18
- }
19
- if (typeof value === 'object') {
20
- const record = value;
21
- if (typeof record.text === 'string') {
22
- collectText(record.text, collector);
23
- return;
24
- }
25
- if (typeof record.content === 'string') {
26
- collectText(record.content, collector);
27
- return;
28
- }
29
- if (Array.isArray(record.content)) {
30
- collectText(record.content, collector);
31
- return;
32
- }
33
- if (record.type === 'image_url' && typeof record.image_url === 'string') {
34
- collector.textParts.push(`[image:${record.image_url}]`);
35
- return;
36
- }
37
- try {
38
- collector.textParts.push(sanitizeReasoningTaggedText(JSON.stringify(record)));
39
- }
40
- catch {
41
- collector.textParts.push(String(record));
42
- }
43
- return;
44
- }
45
- collector.textParts.push(sanitizeReasoningTaggedText(String(value)));
46
- }
1
+ import { normalizeChatMessageContentWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
47
2
  export function normalizeChatMessageContent(content) {
48
- const collector = { textParts: [], reasoningParts: [] };
49
- collectText(content, collector);
50
- const text = collector.textParts.join('');
51
- const reasoning = collector.reasoningParts.join('\n');
52
- return {
53
- contentText: text.length ? text : undefined,
54
- reasoningText: reasoning.length ? reasoning : undefined
55
- };
3
+ return normalizeChatMessageContentWithNative(content);
56
4
  }
@@ -1,59 +1,4 @@
1
- function hasCompactionMarker(value) {
2
- // Compaction markers are intended to be explicit “header-like” sentinels produced by
3
- // our own compaction flows, not arbitrary substrings inside user/dev instructions.
4
- //
5
- // If we treat any occurrence as a compaction request, normal conversations that
6
- // contain phrases like “handoff summary …” (e.g. debug summaries pasted into chat)
7
- // will get misclassified and will disable stopMessage / other servertools.
8
- const lower = value.trimStart().toLowerCase();
9
- return (lower.startsWith('context checkpoint compaction') ||
10
- lower.startsWith('checkpoint compaction') ||
11
- lower.startsWith('handoff summary for another llm'));
12
- }
13
- function containsMarker(value) {
14
- if (typeof value === 'string') {
15
- return hasCompactionMarker(value);
16
- }
17
- if (!value || typeof value !== 'object') {
18
- return false;
19
- }
20
- if (Array.isArray(value)) {
21
- return value.some((entry) => containsMarker(entry));
22
- }
23
- const record = value;
24
- if (typeof record.text === 'string' && hasCompactionMarker(record.text)) {
25
- return true;
26
- }
27
- if (typeof record.content === 'string' && hasCompactionMarker(record.content)) {
28
- return true;
29
- }
30
- if (Array.isArray(record.content) && record.content.some((entry) => containsMarker(entry))) {
31
- return true;
32
- }
33
- if (Array.isArray(record.parts) && record.parts.some((entry) => containsMarker(entry))) {
34
- return true;
35
- }
36
- return false;
37
- }
1
+ import { isCompactionRequestWithNative } from '../../router/virtual-router/engine-selection/native-shared-conversion-semantics.js';
38
2
  export function isCompactionRequest(payload) {
39
- if (containsMarker(payload)) {
40
- return true;
41
- }
42
- const messages = payload.messages;
43
- if (Array.isArray(messages) && messages.some((msg) => containsMarker(msg))) {
44
- return true;
45
- }
46
- const input = payload.input;
47
- if (containsMarker(input)) {
48
- return true;
49
- }
50
- const system = payload.system;
51
- if (containsMarker(system)) {
52
- return true;
53
- }
54
- const instructions = payload.instructions;
55
- if (containsMarker(instructions)) {
56
- return true;
57
- }
58
- return false;
3
+ return isCompactionRequestWithNative(payload);
59
4
  }