@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
@@ -0,0 +1,16 @@
1
+ import type { AliasSelectionConfig, AliasSelectionStrategy } from '../types.js';
2
+ type NativeAliasQueuePinPayload = {
3
+ queue: string[];
4
+ desiredOrder: string[];
5
+ excludedAliases: string[];
6
+ aliasBuckets: Record<string, string[]>;
7
+ candidateOrder: string[];
8
+ availabilityByAlias: Record<string, boolean>;
9
+ };
10
+ type NativeAliasQueuePinOutput = {
11
+ queue: string[];
12
+ selectedCandidates: string[];
13
+ };
14
+ export declare function resolveAliasSelectionStrategyWithNative(providerId: string, cfg: AliasSelectionConfig | undefined): AliasSelectionStrategy;
15
+ export declare function pinAliasQueueWithNative(payload: NativeAliasQueuePinPayload): NativeAliasQueuePinOutput;
16
+ export {};
@@ -0,0 +1,96 @@
1
+ import { failNativeRequired } from './native-router-hotpath-policy.js';
2
+ import { loadNativeRouterHotpathBindingForInternalUse } from './native-router-hotpath.js';
3
+ function readNativeFunction(name) {
4
+ const binding = loadNativeRouterHotpathBindingForInternalUse();
5
+ const fn = binding?.[name];
6
+ return typeof fn === 'function' ? fn : null;
7
+ }
8
+ function safeStringify(value) {
9
+ try {
10
+ return JSON.stringify(value);
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ }
16
+ function parseAliasSelectionStrategy(raw) {
17
+ try {
18
+ const parsed = JSON.parse(raw);
19
+ if (parsed === 'none' || parsed === 'sticky-queue') {
20
+ return parsed;
21
+ }
22
+ return null;
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ function parseAliasQueuePinOutput(raw) {
29
+ try {
30
+ const parsed = JSON.parse(raw);
31
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
32
+ return null;
33
+ }
34
+ const row = parsed;
35
+ if (!Array.isArray(row.queue) || !Array.isArray(row.selectedCandidates)) {
36
+ return null;
37
+ }
38
+ const queue = row.queue.filter((v) => typeof v === 'string');
39
+ const selectedCandidates = row.selectedCandidates.filter((v) => typeof v === 'string');
40
+ return {
41
+ queue,
42
+ selectedCandidates
43
+ };
44
+ }
45
+ catch {
46
+ return null;
47
+ }
48
+ }
49
+ export function resolveAliasSelectionStrategyWithNative(providerId, cfg) {
50
+ const capability = 'resolveAliasSelectionStrategyJson';
51
+ const fail = (reason) => failNativeRequired(capability, reason);
52
+ const fn = readNativeFunction('resolveAliasSelectionStrategyJson');
53
+ if (!fn) {
54
+ return fail();
55
+ }
56
+ const cfgJson = safeStringify(cfg ?? null);
57
+ if (!cfgJson) {
58
+ return fail('json stringify failed');
59
+ }
60
+ try {
61
+ const raw = fn(String(providerId || ''), cfgJson);
62
+ if (typeof raw !== 'string' || !raw) {
63
+ return fail('empty result');
64
+ }
65
+ const parsed = parseAliasSelectionStrategy(raw);
66
+ return parsed ?? fail('invalid payload');
67
+ }
68
+ catch (error) {
69
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
70
+ return fail(reason);
71
+ }
72
+ }
73
+ export function pinAliasQueueWithNative(payload) {
74
+ const capability = 'pinAliasQueueJson';
75
+ const fail = (reason) => failNativeRequired(capability, reason);
76
+ const fn = readNativeFunction('pinAliasQueueJson');
77
+ if (!fn) {
78
+ return fail();
79
+ }
80
+ const payloadJson = safeStringify(payload);
81
+ if (!payloadJson) {
82
+ return fail('json stringify failed');
83
+ }
84
+ try {
85
+ const raw = fn(payloadJson);
86
+ if (typeof raw !== 'string' || !raw) {
87
+ return fail('empty result');
88
+ }
89
+ const parsed = parseAliasQueuePinOutput(raw);
90
+ return parsed ?? fail('invalid payload');
91
+ }
92
+ catch (error) {
93
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
94
+ return fail(reason);
95
+ }
96
+ }
@@ -0,0 +1,6 @@
1
+ export type NativeStopMessageActionPatch = {
2
+ applied: boolean;
3
+ set: Record<string, unknown>;
4
+ unset: string[];
5
+ };
6
+ export declare function applyStopMessageInstructionWithNative(instruction: unknown, state: unknown, nowMs: number): NativeStopMessageActionPatch;
@@ -0,0 +1,85 @@
1
+ import { failNativeRequired } from './native-router-hotpath-policy.js';
2
+ import { loadNativeRouterHotpathBindingForInternalUse } from './native-router-hotpath.js';
3
+ const STOP_MESSAGE_FIELDS = new Set([
4
+ 'stopMessageSource',
5
+ 'stopMessageText',
6
+ 'stopMessageMaxRepeats',
7
+ 'stopMessageUsed',
8
+ 'stopMessageUpdatedAt',
9
+ 'stopMessageLastUsedAt',
10
+ 'stopMessageStageMode',
11
+ 'stopMessageAiMode',
12
+ 'stopMessageAiSeedPrompt',
13
+ 'stopMessageAiHistory'
14
+ ]);
15
+ function readNativeFunction(name) {
16
+ const binding = loadNativeRouterHotpathBindingForInternalUse();
17
+ const fn = binding?.[name];
18
+ return typeof fn === 'function' ? fn : null;
19
+ }
20
+ function safeStringify(value) {
21
+ try {
22
+ return JSON.stringify(value);
23
+ }
24
+ catch {
25
+ return undefined;
26
+ }
27
+ }
28
+ function parseActionPatchPayload(raw) {
29
+ try {
30
+ const parsed = JSON.parse(raw);
31
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
32
+ return null;
33
+ }
34
+ const row = parsed;
35
+ if (typeof row.applied !== 'boolean') {
36
+ return null;
37
+ }
38
+ const setRaw = row.set;
39
+ const unsetRaw = row.unset;
40
+ const normalizedSet = {};
41
+ if (setRaw && typeof setRaw === 'object' && !Array.isArray(setRaw)) {
42
+ for (const [key, value] of Object.entries(setRaw)) {
43
+ if (value !== undefined) {
44
+ normalizedSet[key] = value;
45
+ }
46
+ }
47
+ }
48
+ const normalizedUnset = Array.isArray(unsetRaw)
49
+ ? unsetRaw.filter((key) => typeof key === 'string')
50
+ : [];
51
+ return {
52
+ applied: row.applied,
53
+ set: normalizedSet,
54
+ unset: Array.from(new Set(normalizedUnset))
55
+ };
56
+ }
57
+ catch {
58
+ return null;
59
+ }
60
+ }
61
+ export function applyStopMessageInstructionWithNative(instruction, state, nowMs) {
62
+ const capability = 'applyStopMessageInstructionJson';
63
+ const fail = (reason) => failNativeRequired(capability, reason);
64
+ const fn = readNativeFunction(capability);
65
+ if (!fn) {
66
+ return fail();
67
+ }
68
+ const instructionJson = safeStringify(instruction);
69
+ const stateJson = safeStringify(state);
70
+ if (!instructionJson || !stateJson) {
71
+ return fail('json stringify failed');
72
+ }
73
+ try {
74
+ const result = fn(instructionJson, stateJson, Math.floor(nowMs));
75
+ if (typeof result !== 'string' || !result) {
76
+ return fail('empty result');
77
+ }
78
+ const parsed = parseActionPatchPayload(result);
79
+ return parsed ?? fail('invalid payload');
80
+ }
81
+ catch (error) {
82
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
83
+ return fail(reason);
84
+ }
85
+ }
@@ -0,0 +1,9 @@
1
+ export type StopMessageNativeParseOutput = {
2
+ kind: 'clear';
3
+ } | {
4
+ kind: 'set';
5
+ text: string;
6
+ maxRepeats: number;
7
+ aiMode?: 'on' | 'off';
8
+ };
9
+ export declare function parseStopMessageInstructionWithNative(instruction: string): StopMessageNativeParseOutput | null;
@@ -0,0 +1,70 @@
1
+ import { failNativeRequired } from './native-router-hotpath-policy.js';
2
+ import { loadNativeRouterHotpathBindingForInternalUse } from './native-router-hotpath.js';
3
+ function readNativeFunction(name) {
4
+ const binding = loadNativeRouterHotpathBindingForInternalUse();
5
+ const fn = binding?.[name];
6
+ return typeof fn === 'function' ? fn : null;
7
+ }
8
+ function normalizeMode(value) {
9
+ if (value !== 'on' && value !== 'off') {
10
+ return undefined;
11
+ }
12
+ return value;
13
+ }
14
+ function parseStopMessageNativePayload(raw) {
15
+ let parsed = null;
16
+ try {
17
+ parsed = JSON.parse(raw);
18
+ }
19
+ catch {
20
+ return null;
21
+ }
22
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
23
+ return null;
24
+ }
25
+ const kindRaw = parsed.kind;
26
+ if (kindRaw !== 'set' && kindRaw !== 'clear') {
27
+ return null;
28
+ }
29
+ const kind = kindRaw;
30
+ if (kind === 'clear') {
31
+ return { kind: 'clear' };
32
+ }
33
+ const text = typeof parsed.text === 'string' ? parsed.text : '';
34
+ const maxRepeats = typeof parsed.maxRepeats === 'number' && Number.isFinite(parsed.maxRepeats)
35
+ ? Math.floor(parsed.maxRepeats)
36
+ : 10;
37
+ if (!text || maxRepeats <= 0) {
38
+ return null;
39
+ }
40
+ const aiMode = normalizeMode(parsed.aiMode);
41
+ return {
42
+ kind: 'set',
43
+ text,
44
+ maxRepeats,
45
+ ...(aiMode ? { aiMode } : {})
46
+ };
47
+ }
48
+ export function parseStopMessageInstructionWithNative(instruction) {
49
+ const capability = 'parseStopMessageInstructionJson';
50
+ const fail = (reason) => failNativeRequired(capability, reason);
51
+ const fn = readNativeFunction('parseStopMessageInstructionJson');
52
+ if (!fn) {
53
+ return fail();
54
+ }
55
+ try {
56
+ const result = fn(String(instruction || ''));
57
+ if (typeof result !== 'string') {
58
+ return fail('non-string result');
59
+ }
60
+ if (!result || result === 'null') {
61
+ return null;
62
+ }
63
+ const parsed = parseStopMessageNativePayload(result);
64
+ return parsed ?? fail('invalid payload');
65
+ }
66
+ catch (error) {
67
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
68
+ return fail(reason);
69
+ }
70
+ }
@@ -0,0 +1,2 @@
1
+ export declare function serializeStopMessageStateWithNative(state: unknown): Record<string, unknown>;
2
+ export declare function deserializeStopMessageStateWithNative(data: Record<string, unknown>, state: unknown): Record<string, unknown>;
@@ -0,0 +1,76 @@
1
+ import { failNativeRequired } from './native-router-hotpath-policy.js';
2
+ import { loadNativeRouterHotpathBindingForInternalUse } from './native-router-hotpath.js';
3
+ function readNativeFunction(name) {
4
+ const binding = loadNativeRouterHotpathBindingForInternalUse();
5
+ const fn = binding?.[name];
6
+ return typeof fn === 'function' ? fn : null;
7
+ }
8
+ function safeStringify(value) {
9
+ try {
10
+ return JSON.stringify(value);
11
+ }
12
+ catch {
13
+ return undefined;
14
+ }
15
+ }
16
+ function parseRecordPayload(raw) {
17
+ try {
18
+ const parsed = JSON.parse(raw);
19
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed)) {
20
+ return null;
21
+ }
22
+ return parsed;
23
+ }
24
+ catch {
25
+ return null;
26
+ }
27
+ }
28
+ export function serializeStopMessageStateWithNative(state) {
29
+ const capability = 'serializeStopMessageStateJson';
30
+ const fail = (reason) => failNativeRequired(capability, reason);
31
+ const fn = readNativeFunction(capability);
32
+ if (!fn) {
33
+ return fail();
34
+ }
35
+ const stateJson = safeStringify(state);
36
+ if (!stateJson) {
37
+ return fail('json stringify failed');
38
+ }
39
+ try {
40
+ const result = fn(stateJson);
41
+ if (typeof result !== 'string' || !result) {
42
+ return fail('empty result');
43
+ }
44
+ const parsed = parseRecordPayload(result);
45
+ return parsed ?? fail('invalid payload');
46
+ }
47
+ catch (error) {
48
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
49
+ return fail(reason);
50
+ }
51
+ }
52
+ export function deserializeStopMessageStateWithNative(data, state) {
53
+ const capability = 'deserializeStopMessageStateJson';
54
+ const fail = (reason) => failNativeRequired(capability, reason);
55
+ const fn = readNativeFunction(capability);
56
+ if (!fn) {
57
+ return fail();
58
+ }
59
+ const dataJson = safeStringify(data);
60
+ const stateJson = safeStringify(state);
61
+ if (!dataJson || !stateJson) {
62
+ return fail('json stringify failed');
63
+ }
64
+ try {
65
+ const result = fn(dataJson, stateJson);
66
+ if (typeof result !== 'string' || !result) {
67
+ return fail('empty result');
68
+ }
69
+ const parsed = parseRecordPayload(result);
70
+ return parsed ?? fail('invalid payload');
71
+ }
72
+ catch (error) {
73
+ const reason = error instanceof Error ? error.message : String(error ?? 'unknown');
74
+ return fail(reason);
75
+ }
76
+ }
@@ -63,7 +63,7 @@ export function buildRouteCandidates(requestedRoute, classificationCandidates, f
63
63
  baseList.unshift('multimodal');
64
64
  }
65
65
  }
66
- if (hasVisionTargets) {
66
+ if (hasVisionTargets && (!hasMultimodalTargets || forceVision)) {
67
67
  if (!baseList.includes('vision')) {
68
68
  baseList.push('vision');
69
69
  }
@@ -0,0 +1,10 @@
1
+ import type { SelectionDeps } from './selection-deps.js';
2
+ export declare function isAntigravityGeminiModelKey(providerKey: string, deps: SelectionDeps): boolean;
3
+ export declare function extractLeaseRuntimeKey(providerKey: string, deps: SelectionDeps): string | null;
4
+ export declare function applyAntigravityAliasSessionLeases(targets: string[], deps: SelectionDeps, metadata: unknown): {
5
+ targets: string[];
6
+ blocked: number;
7
+ preferredPinned: boolean;
8
+ pinnedStrict: boolean;
9
+ preferredRuntimeKey?: string;
10
+ };
@@ -0,0 +1,231 @@
1
+ import { getProviderModelId, extractProviderId } from './key-parsing.js';
2
+ import { lookupAntigravityPinnedAliasForSessionIdWithNative, unpinAntigravitySessionAliasForSessionIdWithNative } from './native-router-hotpath.js';
3
+ import { lookupAntigravityPinnedAliasForSessionId, unpinAntigravitySessionAliasForSessionId } from '../../../conversion/compat/antigravity-session-signature.js';
4
+ const DEFAULT_ANTIGRAVITY_ALIAS_SESSION_COOLDOWN_MS = 5 * 60_000;
5
+ export function isAntigravityGeminiModelKey(providerKey, deps) {
6
+ if ((extractProviderId(providerKey) ?? '') !== 'antigravity') {
7
+ return false;
8
+ }
9
+ const modelId = getProviderModelId(providerKey, deps.providerRegistry) ?? '';
10
+ return modelId.trim().toLowerCase().startsWith('gemini-');
11
+ }
12
+ function extractAntigravityRuntimeBase(providerKey) {
13
+ const value = typeof providerKey === 'string' ? providerKey.trim() : '';
14
+ if (!value)
15
+ return null;
16
+ const firstDot = value.indexOf('.');
17
+ if (firstDot <= 0 || firstDot === value.length - 1)
18
+ return null;
19
+ const secondDot = value.indexOf('.', firstDot + 1);
20
+ if (secondDot <= firstDot + 1)
21
+ return null;
22
+ const providerId = value.slice(0, firstDot);
23
+ const alias = value.slice(firstDot + 1, secondDot);
24
+ if (!providerId || !alias)
25
+ return null;
26
+ return `${providerId}.${alias}`;
27
+ }
28
+ function buildAntigravityLeaseRuntimeKey(runtimeBase) {
29
+ return `${runtimeBase}::gemini`;
30
+ }
31
+ function isAntigravityGeminiSessionBindingDisabled(metadata) {
32
+ if (!metadata || typeof metadata !== 'object') {
33
+ return false;
34
+ }
35
+ const rtRaw = metadata.__rt;
36
+ if (!rtRaw || typeof rtRaw !== 'object' || Array.isArray(rtRaw)) {
37
+ return false;
38
+ }
39
+ const rt = rtRaw;
40
+ if (rt.disableAntigravitySessionBinding === true) {
41
+ return true;
42
+ }
43
+ const mode = rt.antigravitySessionBinding;
44
+ if (mode === false) {
45
+ return true;
46
+ }
47
+ if (typeof mode === 'string' && ['0', 'false', 'off', 'disabled', 'none'].includes(mode.trim().toLowerCase())) {
48
+ return true;
49
+ }
50
+ return false;
51
+ }
52
+ function resolveSessionScopeKey(metadata) {
53
+ if (!metadata || typeof metadata !== 'object') {
54
+ return null;
55
+ }
56
+ const record = metadata;
57
+ const sessionId = typeof record.sessionId === 'string' ? record.sessionId.trim() : '';
58
+ if (sessionId) {
59
+ return `session:${sessionId}`;
60
+ }
61
+ const conversationId = typeof record.conversationId === 'string' ? record.conversationId.trim() : '';
62
+ if (conversationId) {
63
+ return `conversation:${conversationId}`;
64
+ }
65
+ const antigravitySessionId = typeof record.antigravitySessionId === 'string'
66
+ ? String(record.antigravitySessionId).trim()
67
+ : '';
68
+ if (antigravitySessionId) {
69
+ return `session:${antigravitySessionId}`;
70
+ }
71
+ return null;
72
+ }
73
+ function buildScopedSessionKey(sessionKey) {
74
+ return `${sessionKey}::gemini`;
75
+ }
76
+ export function extractLeaseRuntimeKey(providerKey, deps) {
77
+ const base = extractAntigravityRuntimeBase(providerKey);
78
+ if (!base)
79
+ return null;
80
+ if ((extractProviderId(providerKey) ?? '') !== 'antigravity')
81
+ return base;
82
+ if (!isAntigravityGeminiModelKey(providerKey, deps)) {
83
+ return null;
84
+ }
85
+ return buildAntigravityLeaseRuntimeKey(base);
86
+ }
87
+ export function applyAntigravityAliasSessionLeases(targets, deps, metadata) {
88
+ if (!Array.isArray(targets) || targets.length === 0) {
89
+ return { targets, blocked: 0, preferredPinned: false, pinnedStrict: false };
90
+ }
91
+ if (isAntigravityGeminiSessionBindingDisabled(metadata)) {
92
+ return { targets, blocked: 0, preferredPinned: false, pinnedStrict: false };
93
+ }
94
+ const leaseStore = deps.antigravityAliasLeaseStore;
95
+ const sessionAliasStore = deps.antigravitySessionAliasStore;
96
+ if (!leaseStore || !sessionAliasStore) {
97
+ return { targets, blocked: 0, preferredPinned: false, pinnedStrict: false };
98
+ }
99
+ const sessionKey = resolveSessionScopeKey(metadata);
100
+ if (!sessionKey) {
101
+ return { targets, blocked: 0, preferredPinned: false, pinnedStrict: false };
102
+ }
103
+ const cooldownMs = typeof deps.antigravityAliasReuseCooldownMs === 'number' && Number.isFinite(deps.antigravityAliasReuseCooldownMs)
104
+ ? Math.max(0, Math.floor(deps.antigravityAliasReuseCooldownMs))
105
+ : DEFAULT_ANTIGRAVITY_ALIAS_SESSION_COOLDOWN_MS;
106
+ const now = Date.now();
107
+ const bindingModeRaw = deps.loadBalancer.getPolicy().aliasSelection
108
+ ?.antigravitySessionBinding;
109
+ const strictRequested = typeof bindingModeRaw === 'string' && bindingModeRaw.trim().toLowerCase() === 'strict';
110
+ const agSessionId = metadata && typeof metadata === 'object' && typeof metadata.antigravitySessionId === 'string'
111
+ ? String(metadata.antigravitySessionId).trim()
112
+ : '';
113
+ const hasAntigravityGeminiTargets = targets.some((key) => isAntigravityGeminiModelKey(key, deps));
114
+ const lookupPinnedRuntimeKey = () => {
115
+ if (!(strictRequested && agSessionId && hasAntigravityGeminiTargets)) {
116
+ return undefined;
117
+ }
118
+ const nativePinned = lookupAntigravityPinnedAliasForSessionIdWithNative(agSessionId, { hydrate: true });
119
+ if (nativePinned && nativePinned.trim()) {
120
+ return nativePinned.trim();
121
+ }
122
+ const persistedPinned = lookupAntigravityPinnedAliasForSessionId(agSessionId, { hydrate: true });
123
+ if (!persistedPinned || !persistedPinned.trim()) {
124
+ return undefined;
125
+ }
126
+ return persistedPinned.trim();
127
+ };
128
+ let pinnedRuntimeKey = lookupPinnedRuntimeKey();
129
+ const pinnedLeaseKey = pinnedRuntimeKey ? buildAntigravityLeaseRuntimeKey(pinnedRuntimeKey) : undefined;
130
+ if (pinnedRuntimeKey && deps.quotaView && agSessionId) {
131
+ const pinnedKeys = targets.filter((key) => isAntigravityGeminiModelKey(key, deps) && extractLeaseRuntimeKey(key, deps) === pinnedLeaseKey);
132
+ if (pinnedKeys.length > 0) {
133
+ const allOutOfPool = pinnedKeys.every((key) => deps.quotaView?.(key)?.inPool === false);
134
+ if (allOutOfPool) {
135
+ const releasedRuntimeKey = pinnedRuntimeKey;
136
+ unpinAntigravitySessionAliasForSessionIdWithNative(agSessionId);
137
+ unpinAntigravitySessionAliasForSessionId(agSessionId);
138
+ pinnedRuntimeKey = undefined;
139
+ sessionAliasStore.delete(buildScopedSessionKey(sessionKey));
140
+ try {
141
+ const raw = String(process.env.ROUTECODEX_STAGE_LOG || process.env.RCC_STAGE_LOG || '').trim().toLowerCase();
142
+ const enabled = raw !== '' && raw !== '0' && raw !== 'false' && raw !== 'no';
143
+ if (enabled) {
144
+ console.log('[virtual-router][antigravity-session-binding] unpin', JSON.stringify({ agSessionId, runtimeKey: releasedRuntimeKey }));
145
+ }
146
+ }
147
+ catch {
148
+ // ignore
149
+ }
150
+ }
151
+ }
152
+ }
153
+ const strictBinding = strictRequested && Boolean(pinnedLeaseKey);
154
+ const geminiSessionKey = buildScopedSessionKey(sessionKey);
155
+ let preferredGeminiRuntimeKey = pinnedLeaseKey || sessionAliasStore.get(geminiSessionKey);
156
+ if (preferredGeminiRuntimeKey && !preferredGeminiRuntimeKey.includes('::')) {
157
+ preferredGeminiRuntimeKey = buildAntigravityLeaseRuntimeKey(preferredGeminiRuntimeKey);
158
+ }
159
+ if (preferredGeminiRuntimeKey && !pinnedLeaseKey) {
160
+ const lease = leaseStore.get(preferredGeminiRuntimeKey);
161
+ if (lease && lease.sessionKey !== geminiSessionKey && now - lease.lastSeenAt < cooldownMs) {
162
+ preferredGeminiRuntimeKey = undefined;
163
+ }
164
+ }
165
+ if (deps.quotaView && !pinnedLeaseKey && preferredGeminiRuntimeKey) {
166
+ const pinnedKeys = targets.filter((key) => isAntigravityGeminiModelKey(key, deps) && extractLeaseRuntimeKey(key, deps) === preferredGeminiRuntimeKey);
167
+ if (pinnedKeys.length > 0) {
168
+ const allOutOfPool = pinnedKeys.every((key) => deps.quotaView?.(key)?.inPool === false);
169
+ if (allOutOfPool) {
170
+ const releasedRuntimeKey = preferredGeminiRuntimeKey;
171
+ sessionAliasStore.delete(geminiSessionKey);
172
+ preferredGeminiRuntimeKey = undefined;
173
+ try {
174
+ const raw = String(process.env.ROUTECODEX_STAGE_LOG || process.env.RCC_STAGE_LOG || '').trim().toLowerCase();
175
+ const enabled = raw !== '' && raw !== '0' && raw !== 'false' && raw !== 'no';
176
+ if (enabled) {
177
+ console.log('[virtual-router][antigravity-session-binding] release', JSON.stringify({ sessionKey: geminiSessionKey, runtimeKey: releasedRuntimeKey }));
178
+ }
179
+ }
180
+ catch {
181
+ // ignore
182
+ }
183
+ }
184
+ }
185
+ }
186
+ const pinnedGemini = preferredGeminiRuntimeKey
187
+ ? targets.filter((key) => isAntigravityGeminiModelKey(key, deps) && extractLeaseRuntimeKey(key, deps) === preferredGeminiRuntimeKey)
188
+ : [];
189
+ const preferredPinned = pinnedGemini.length > 0;
190
+ const pinnedSet = preferredPinned ? new Set([...pinnedGemini]) : null;
191
+ const candidates = preferredPinned
192
+ ? [...pinnedGemini, ...targets.filter((key) => !pinnedSet.has(key))]
193
+ : targets;
194
+ const pinnedStrict = strictBinding && Boolean(preferredGeminiRuntimeKey);
195
+ let blocked = 0;
196
+ const filtered = candidates.filter((key) => {
197
+ const providerId = extractProviderId(key);
198
+ if (providerId !== 'antigravity') {
199
+ return true;
200
+ }
201
+ if (!isAntigravityGeminiModelKey(key, deps)) {
202
+ return true;
203
+ }
204
+ const scopedSessionKey = geminiSessionKey;
205
+ const runtimeKey = extractLeaseRuntimeKey(key, deps);
206
+ if (!runtimeKey) {
207
+ return true;
208
+ }
209
+ if (pinnedStrict) {
210
+ if (!isAntigravityGeminiModelKey(key, deps)) {
211
+ return true;
212
+ }
213
+ if (preferredGeminiRuntimeKey && runtimeKey !== preferredGeminiRuntimeKey) {
214
+ return false;
215
+ }
216
+ }
217
+ const lease = leaseStore.get(runtimeKey);
218
+ if (!lease) {
219
+ return true;
220
+ }
221
+ if (lease.sessionKey === scopedSessionKey) {
222
+ return true;
223
+ }
224
+ if (now - lease.lastSeenAt >= cooldownMs) {
225
+ return true;
226
+ }
227
+ blocked += 1;
228
+ return false;
229
+ });
230
+ return { targets: filtered, blocked, preferredPinned, pinnedStrict, preferredRuntimeKey: preferredGeminiRuntimeKey };
231
+ }
@@ -0,0 +1,4 @@
1
+ export declare function shouldAvoidAllAntigravityOnRetry(metadata: unknown): boolean;
2
+ export declare function shouldAvoidAntigravityAfterRepeatedError(metadata: unknown): boolean;
3
+ export declare function preferNonAntigravityWhenPossible(candidates: string[]): string[];
4
+ export declare function extractNonAntigravityTargets(targets: string[]): string[];
@@ -0,0 +1,43 @@
1
+ import { splitAntigravityTargets } from './native-router-hotpath.js';
2
+ export function shouldAvoidAllAntigravityOnRetry(metadata) {
3
+ if (!metadata || typeof metadata !== 'object') {
4
+ return false;
5
+ }
6
+ const rtRaw = metadata.__rt;
7
+ if (!rtRaw || typeof rtRaw !== 'object' || Array.isArray(rtRaw)) {
8
+ return false;
9
+ }
10
+ const rt = rtRaw;
11
+ return rt.antigravityAvoidAllOnRetry === true;
12
+ }
13
+ export function shouldAvoidAntigravityAfterRepeatedError(metadata) {
14
+ if (!metadata || typeof metadata !== 'object') {
15
+ return false;
16
+ }
17
+ const rtRaw = metadata.__rt;
18
+ if (!rtRaw || typeof rtRaw !== 'object' || Array.isArray(rtRaw)) {
19
+ return false;
20
+ }
21
+ const rt = rtRaw;
22
+ if (rt.antigravityAvoidAllOnRetry === true) {
23
+ return true;
24
+ }
25
+ const signature = typeof rt.antigravityRetryErrorSignature === 'string' ? rt.antigravityRetryErrorSignature.trim() : '';
26
+ const consecutive = typeof rt.antigravityRetryErrorConsecutive === 'number' && Number.isFinite(rt.antigravityRetryErrorConsecutive)
27
+ ? Math.max(0, Math.floor(rt.antigravityRetryErrorConsecutive))
28
+ : 0;
29
+ return signature.length > 0 && signature !== 'unknown' && consecutive >= 2;
30
+ }
31
+ export function preferNonAntigravityWhenPossible(candidates) {
32
+ if (!Array.isArray(candidates) || candidates.length < 2) {
33
+ return candidates;
34
+ }
35
+ const nonAntigravity = splitAntigravityTargets(candidates).nonAntigravity;
36
+ return nonAntigravity.length > 0 ? nonAntigravity : candidates;
37
+ }
38
+ export function extractNonAntigravityTargets(targets) {
39
+ if (!Array.isArray(targets) || targets.length === 0) {
40
+ return [];
41
+ }
42
+ return splitAntigravityTargets(targets).nonAntigravity;
43
+ }