xkzoom 1.5.5 → 1.5.6

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 (387) hide show
  1. package/README.md +36 -0
  2. package/dist/{chunk-VHRFLCMY.mjs → chunk-22VRM3T3.mjs} +1 -1
  3. package/dist/{chunk-XL3MUGFG.mjs → chunk-2B3A3C2V.mjs} +1 -1
  4. package/dist/{chunk-UQLGVSQH.mjs → chunk-2F65KBU2.mjs} +8 -9
  5. package/dist/chunk-2L4VMCM2.mjs +15 -0
  6. package/dist/{chunk-WQSQXDUL.mjs → chunk-2LN3ODBA.mjs} +1 -1
  7. package/dist/{chunk-MTRG3ZME.mjs → chunk-2YB6BHIB.mjs} +13 -13
  8. package/dist/chunk-35SKU3FL.mjs +279 -0
  9. package/dist/{chunk-OMLMLZUY.mjs → chunk-3JHD7MGZ.mjs} +2 -2
  10. package/dist/{chunk-CVIZMDMZ.mjs → chunk-3QE7GUJC.mjs} +1 -1
  11. package/dist/{chunk-YFKOQIA7.mjs → chunk-4XJFA7V3.mjs} +1 -1
  12. package/dist/{chunk-EYK3W2NV.mjs → chunk-5G3UUQ36.mjs} +2 -2
  13. package/dist/{chunk-CRYBNNZU.mjs → chunk-5MXGINNQ.mjs} +11 -11
  14. package/dist/{chunk-RVW5XO4A.mjs → chunk-6KCPL45H.mjs} +3 -3
  15. package/dist/{chunk-64QYTQH7.mjs → chunk-6OY3GOUH.mjs} +6 -6
  16. package/dist/{chunk-LBZCBBHU.mjs → chunk-72IPGTJZ.mjs} +1 -1
  17. package/dist/{chunk-ND44D2ZA.mjs → chunk-74S3DUNZ.mjs} +1 -1
  18. package/dist/{chunk-NUXJHSSQ.mjs → chunk-7C7HREZO.mjs} +14 -14
  19. package/dist/{chunk-BFSOQ5IG.mjs → chunk-7HQEB7IJ.mjs} +3 -3
  20. package/dist/{chunk-XDR276NG.mjs → chunk-7TKZKTS5.mjs} +1 -1
  21. package/dist/{chunk-APQRVOZQ.mjs → chunk-A4BZZNPW.mjs} +2 -2
  22. package/dist/{chunk-BJ6YI2DJ.mjs → chunk-AEE3DM6S.mjs} +1 -1
  23. package/dist/{chunk-2NBVNRMZ.mjs → chunk-ANGNUW6F.mjs} +5 -5
  24. package/dist/{chunk-GZZ7KO57.mjs → chunk-BJFTC4GW.mjs} +21 -1
  25. package/dist/{chunk-GYZ4IXUD.mjs → chunk-CLN4OVFM.mjs} +3 -6
  26. package/dist/{chunk-FAB2ZZYB.mjs → chunk-CLVSQ3FG.mjs} +2 -2
  27. package/dist/{chunk-IKQ7CLX3.mjs → chunk-CSKP6E6Y.mjs} +2 -2
  28. package/dist/{chunk-LWCO2YNI.mjs → chunk-CVWDLRQI.mjs} +1 -1
  29. package/dist/{chunk-H7DNHHNA.mjs → chunk-D4TNMY2O.mjs} +2 -2
  30. package/dist/{chunk-FLVJABFP.mjs → chunk-DODTDJSF.mjs} +10 -8
  31. package/dist/{chunk-XF4EURDX.mjs → chunk-E36MAP7Y.mjs} +1 -1
  32. package/dist/chunk-F3Y7WDC6.mjs +108 -0
  33. package/dist/{chunk-MLHV7EMJ.mjs → chunk-FEEEY457.mjs} +73 -57
  34. package/dist/{chunk-G4JWJKD7.mjs → chunk-G3E2E6DD.mjs} +36 -36
  35. package/dist/{chunk-WXELBVXY.mjs → chunk-GC2H3KNZ.mjs} +1 -1
  36. package/dist/{chunk-EBVVOJVN.mjs → chunk-GHWAAAG6.mjs} +298 -251
  37. package/dist/{chunk-QEED7NAG.mjs → chunk-GNDVHDPO.mjs} +53 -53
  38. package/dist/chunk-H4NINXMV.mjs +95 -0
  39. package/dist/{chunk-SLBCSYGP.mjs → chunk-H6W42R46.mjs} +199 -159
  40. package/dist/chunk-H7ILBOZU.mjs +48 -0
  41. package/dist/{chunk-HVDIL2V7.mjs → chunk-H7QNACAJ.mjs} +5 -5
  42. package/dist/chunk-HCYIE2PR.mjs +130 -0
  43. package/dist/{chunk-XADONCIM.mjs → chunk-HHPHIVCC.mjs} +8 -8
  44. package/dist/{chunk-P262PAGZ.mjs → chunk-HLYVEYML.mjs} +15 -2
  45. package/dist/{chunk-G5LQ2PQ6.mjs → chunk-HNYI45WM.mjs} +23 -4
  46. package/dist/{chunk-O7MFL7L4.mjs → chunk-HOII5XBJ.mjs} +13 -13
  47. package/dist/{chunk-AINHKBJW.mjs → chunk-HPZG5VVI.mjs} +6 -12
  48. package/dist/chunk-HQHICFPO.mjs +58 -0
  49. package/dist/{chunk-DRY7AJMM.mjs → chunk-HQPA2MV5.mjs} +7 -7
  50. package/dist/{chunk-NJAPWQ4D.mjs → chunk-ICKBF7KF.mjs} +2 -60
  51. package/dist/{chunk-54GVKP6B.mjs → chunk-IEF2AMNW.mjs} +4 -4
  52. package/dist/{chunk-IT2GAHAL.mjs → chunk-IHMPR5HT.mjs} +1 -1
  53. package/dist/{chunk-BHT6B2TV.mjs → chunk-J4FQVXEA.mjs} +7 -7
  54. package/dist/{chunk-H4BNL7XG.mjs → chunk-JN5EMEXS.mjs} +1 -1
  55. package/dist/{chunk-4WWT6OC2.mjs → chunk-JTKSYLZE.mjs} +26 -48
  56. package/dist/{chunk-5IAQOOZ2.mjs → chunk-JX3URYQG.mjs} +6 -6
  57. package/dist/{chunk-DQ7J7RST.mjs → chunk-K5JMXCH5.mjs} +1 -1
  58. package/dist/{chunk-PN6I6DTV.mjs → chunk-KBEY4ZQV.mjs} +1 -1
  59. package/dist/{chunk-EL6TOIFZ.mjs → chunk-KHQPC6I7.mjs} +1 -16
  60. package/dist/{chunk-DZDEUZD2.mjs → chunk-L3PV2ZNB.mjs} +13 -13
  61. package/dist/{chunk-ZE6GJFY7.mjs → chunk-L7N2B4LX.mjs} +5 -5
  62. package/dist/{chunk-ED4H2DM7.mjs → chunk-LNPOTNGJ.mjs} +1 -1
  63. package/dist/chunk-LOMDPHVQ.mjs +42 -0
  64. package/dist/chunk-LQHI5VK2.mjs +26 -0
  65. package/dist/{chunk-N6VFFREI.mjs → chunk-LTTSUVF5.mjs} +54 -54
  66. package/dist/{chunk-LMIEVEGA.mjs → chunk-LV3CI5A4.mjs} +1 -1
  67. package/dist/{chunk-NIV5GVCE.mjs → chunk-M3E2R3PT.mjs} +1 -1
  68. package/dist/{chunk-6SYECCCG.mjs → chunk-M7DB4RAC.mjs} +5 -5
  69. package/dist/{chunk-AP4WVS6L.mjs → chunk-MCJPAZBQ.mjs} +1 -1
  70. package/dist/{chunk-T6XDJ2QQ.mjs → chunk-MGIGU4G6.mjs} +119 -18
  71. package/dist/{chunk-TNBK63NV.mjs → chunk-MNLMVNF5.mjs} +5 -5
  72. package/dist/{chunk-TER7DFHP.mjs → chunk-MXKSS63B.mjs} +2 -2
  73. package/dist/{chunk-6VSIGHGI.mjs → chunk-N4X2MAF2.mjs} +14 -28
  74. package/dist/{chunk-E7BFLHLM.mjs → chunk-NDPDPELV.mjs} +1 -16
  75. package/dist/{chunk-WQFYA2BW.mjs → chunk-NI2PDCVA.mjs} +3 -3
  76. package/dist/{chunk-BSG6WLML.mjs → chunk-NI4N35JN.mjs} +1 -1
  77. package/dist/{chunk-Z2JNJLJM.mjs → chunk-NLUF66E7.mjs} +1 -1
  78. package/dist/{chunk-SKQOHRBI.mjs → chunk-NRPE77A3.mjs} +2 -2
  79. package/dist/{chunk-UPD527M4.mjs → chunk-NTVWS2MO.mjs} +3 -3
  80. package/dist/{chunk-DXPZNBSQ.mjs → chunk-NV7SYEH7.mjs} +2 -2
  81. package/dist/{chunk-GSIZ5FR6.mjs → chunk-NXVXMXL5.mjs} +3 -3
  82. package/dist/{chunk-PINXXWFJ.mjs → chunk-OGT25PYJ.mjs} +1 -1
  83. package/dist/{chunk-3STOFADV.mjs → chunk-OHCBAEML.mjs} +1 -0
  84. package/dist/{chunk-LKHL3NCW.mjs → chunk-OPTSEYTI.mjs} +1 -1
  85. package/dist/{chunk-YSLLUNNZ.mjs → chunk-PH5QACOX.mjs} +23 -23
  86. package/dist/{chunk-6MOIFLPP.mjs → chunk-PKJLFQRF.mjs} +1 -1
  87. package/dist/{chunk-W6JEB555.mjs → chunk-POOU2U4R.mjs} +2 -2
  88. package/dist/{chunk-S5ROBD7X.mjs → chunk-PPMT66BN.mjs} +3 -3
  89. package/dist/{chunk-RZOILUDC.mjs → chunk-PSZPHCUP.mjs} +1 -1
  90. package/dist/{chunk-MXXTDG5V.mjs → chunk-PVSCARHF.mjs} +1 -1
  91. package/dist/chunk-PW6NSDMI.mjs +117 -0
  92. package/dist/{chunk-RYSPXH7G.mjs → chunk-PZAMMLMJ.mjs} +3 -3
  93. package/dist/{chunk-JK5ZK32E.mjs → chunk-QDN74R5G.mjs} +5 -5
  94. package/dist/{chunk-UFURP7VS.mjs → chunk-QHIZRYTO.mjs} +1 -1
  95. package/dist/{chunk-UAUV2GYH.mjs → chunk-QITZ7SAD.mjs} +429 -873
  96. package/dist/{chunk-N2CMVW47.mjs → chunk-QRHBGABQ.mjs} +7 -3
  97. package/dist/{chunk-3K6WOVYD.mjs → chunk-RM6GZ2SF.mjs} +3 -3
  98. package/dist/{chunk-P4WX5RWE.mjs → chunk-RUMRGCYN.mjs} +83 -40
  99. package/dist/{chunk-U6ONSC6B.mjs → chunk-S54MBJWY.mjs} +6 -4
  100. package/dist/{chunk-YKACMPVT.mjs → chunk-S573TMN6.mjs} +2 -2
  101. package/dist/{chunk-UFV3WER4.mjs → chunk-SJ5LNKAH.mjs} +1 -1
  102. package/dist/chunk-SJWQGIQU.mjs +99 -0
  103. package/dist/{chunk-KWQEFCOY.mjs → chunk-SMHFMHQ2.mjs} +1 -1
  104. package/dist/{chunk-LGNLS7ZN.mjs → chunk-SPUVJNKO.mjs} +2 -2
  105. package/dist/{chunk-MFIBP6MD.mjs → chunk-T3EJW65E.mjs} +6 -6
  106. package/dist/{chunk-6ZVXCJTG.mjs → chunk-TBLUKDLO.mjs} +91 -1
  107. package/dist/{chunk-3TTLV2GM.mjs → chunk-TKZWE5DB.mjs} +1 -1
  108. package/dist/{chunk-3CPVI6Y2.mjs → chunk-TRSW7QJW.mjs} +1 -1
  109. package/dist/{chunk-FZ7NLBVP.mjs → chunk-TSS3NVRA.mjs} +12 -11
  110. package/dist/{chunk-WRZWEAMN.mjs → chunk-TU75ILAE.mjs} +1 -1
  111. package/dist/{chunk-E5LABIPO.mjs → chunk-U2NKGGVL.mjs} +3 -2
  112. package/dist/{chunk-KLQSTA6K.mjs → chunk-U7TPS3MS.mjs} +1 -1
  113. package/dist/chunk-UOCUHKR5.mjs +21 -0
  114. package/dist/{chunk-VA7SUI2L.mjs → chunk-VD4DIRCW.mjs} +1 -1
  115. package/dist/chunk-VHQ5WHXF.mjs +17 -0
  116. package/dist/{chunk-5U4JST47.mjs → chunk-VMRVJ2VF.mjs} +9 -9
  117. package/dist/{chunk-MJDJIPB4.mjs → chunk-VRG32WNZ.mjs} +1 -1
  118. package/dist/chunk-W5XO4T4J.mjs +63 -0
  119. package/dist/{chunk-5ZMY6RTR.mjs → chunk-WASHQYUB.mjs} +2 -2
  120. package/dist/{chunk-XNQJRIGR.mjs → chunk-WHP2GNEC.mjs} +66 -15
  121. package/dist/chunk-WI7PS7YW.mjs +79 -0
  122. package/dist/{chunk-4BCLMOYG.mjs → chunk-WMLZDHER.mjs} +51 -33
  123. package/dist/{chunk-4POYX4AW.mjs → chunk-WVTJXJY4.mjs} +1 -1
  124. package/dist/{chunk-WOHFGPTL.mjs → chunk-WYCMXDZT.mjs} +1 -1
  125. package/dist/{chunk-LJ6RMHC6.mjs → chunk-XD5XGGQA.mjs} +1 -1
  126. package/dist/{chunk-NEDXMES6.mjs → chunk-YAGU7I25.mjs} +2 -2
  127. package/dist/{chunk-TRMEHTAT.mjs → chunk-YSI3ZONB.mjs} +1 -1
  128. package/dist/chunk-YYUB3HQR.mjs +119 -0
  129. package/dist/{chunk-CTKIQWTE.mjs → chunk-ZOJEC5RT.mjs} +1 -1
  130. package/dist/{chunk-YW5STVWH.mjs → chunk-ZXJY3JIP.mjs} +2 -2
  131. package/dist/index.js +7432 -6635
  132. package/dist/index.mjs +205 -191
  133. package/dist/mobile/action-planner.js +492 -389
  134. package/dist/mobile/action-planner.mjs +128 -128
  135. package/dist/mobile/agent-capabilities.js +492 -389
  136. package/dist/mobile/agent-capabilities.mjs +127 -127
  137. package/dist/mobile/agent-shop/handlers.mjs +4 -4
  138. package/dist/mobile/anthropic-incremental-deliver.mjs +4 -4
  139. package/dist/mobile/anthropic-messages-turn-runner.js +1160 -887
  140. package/dist/mobile/anthropic-messages-turn-runner.mjs +146 -144
  141. package/dist/mobile/anthropic-owned-tool-executor.js +542 -435
  142. package/dist/mobile/anthropic-owned-tool-executor.mjs +143 -143
  143. package/dist/mobile/anthropic-provider-adapter.js +23 -18
  144. package/dist/mobile/anthropic-provider-adapter.mjs +3 -2
  145. package/dist/mobile/api.js +236 -147
  146. package/dist/mobile/api.mjs +63 -62
  147. package/dist/mobile/chinese-monologue-deliver-partition.js +21 -1
  148. package/dist/mobile/chinese-monologue-deliver-partition.mjs +1 -1
  149. package/dist/mobile/context-compact/compact-artifact-enrich.mjs +13 -13
  150. package/dist/mobile/context-compact/compact-artifact-writer.mjs +2 -2
  151. package/dist/mobile/context-compact/compact-engine-artifacts.mjs +3 -3
  152. package/dist/mobile/context-compact/compact-orchestrator.js +8 -22
  153. package/dist/mobile/context-compact/compact-orchestrator.mjs +31 -31
  154. package/dist/mobile/context-compact/compact-resume-prefetch.mjs +2 -2
  155. package/dist/mobile/context-compact/compact-summarizer-engine-artifact.mjs +15 -15
  156. package/dist/mobile/context-compact/compact-summarizer-llm-request.js +2 -1
  157. package/dist/mobile/context-compact/compact-summarizer-llm-request.mjs +8 -8
  158. package/dist/mobile/context-compact/compact-summarizer-llm.js +5 -19
  159. package/dist/mobile/context-compact/compact-summarizer-llm.mjs +9 -9
  160. package/dist/mobile/context-compact/compact-summarizer.js +5 -19
  161. package/dist/mobile/context-compact/compact-summarizer.mjs +12 -12
  162. package/dist/mobile/context-compact/compact-visible-tool-chain.mjs +2 -2
  163. package/dist/mobile/context-compact/context-budget-gate.js +111 -84
  164. package/dist/mobile/context-compact/context-budget-gate.mjs +5 -5
  165. package/dist/mobile/context-compact/native-transcript-budget.js +151 -79
  166. package/dist/mobile/context-compact/native-transcript-budget.mjs +7 -3
  167. package/dist/mobile/context-compact/runtime-compact-hook.js +592 -468
  168. package/dist/mobile/context-compact/runtime-compact-hook.mjs +131 -131
  169. package/dist/mobile/dispatch/compact-resume-contract.js +567 -0
  170. package/dist/mobile/dispatch/compact-resume-contract.mjs +39 -0
  171. package/dist/mobile/dispatch/dispatch-context-assembly.js +588 -0
  172. package/dist/mobile/dispatch/dispatch-context-assembly.mjs +20 -0
  173. package/dist/mobile/dispatch/dispatch-route.js +547 -0
  174. package/dist/mobile/dispatch/dispatch-route.mjs +23 -0
  175. package/dist/mobile/dispatch/dispatch-streaming.js +51 -0
  176. package/dist/mobile/dispatch/dispatch-streaming.mjs +9 -0
  177. package/dist/mobile/dispatch/finalize-contract.js +147 -0
  178. package/dist/mobile/dispatch/finalize-contract.mjs +38 -0
  179. package/dist/mobile/dispatch/inbound-prep.js +671 -0
  180. package/dist/mobile/dispatch/inbound-prep.mjs +31 -0
  181. package/dist/mobile/dispatch/interrupted-snapshot.js +190 -0
  182. package/dist/mobile/dispatch/interrupted-snapshot.mjs +11 -0
  183. package/dist/mobile/dispatch/mobile-dispatch-error.js +41 -0
  184. package/dist/mobile/dispatch/mobile-dispatch-error.mjs +7 -0
  185. package/dist/mobile/dispatch/native-turn-executor.js +42662 -0
  186. package/dist/mobile/dispatch/native-turn-executor.mjs +320 -0
  187. package/dist/mobile/dispatch/native-turn-route.js +1465 -0
  188. package/dist/mobile/dispatch/native-turn-route.mjs +34 -0
  189. package/dist/mobile/dispatch/native-turn-transcript.js +1134 -0
  190. package/dist/mobile/dispatch/native-turn-transcript.mjs +29 -0
  191. package/dist/mobile/group/conductor-llm.js +5 -19
  192. package/dist/mobile/group/conductor-llm.mjs +10 -10
  193. package/dist/mobile/group/conductor-plan-llm.js +5 -19
  194. package/dist/mobile/group/conductor-plan-llm.mjs +16 -16
  195. package/dist/mobile/group/delivery-verification.js +61 -13
  196. package/dist/mobile/group/delivery-verification.mjs +5 -5
  197. package/dist/mobile/group/direct-chat-group-context.mjs +5 -5
  198. package/dist/mobile/group/execution-plan.js +61 -13
  199. package/dist/mobile/group/execution-plan.mjs +6 -6
  200. package/dist/mobile/group/floor-scheduler.mjs +6 -6
  201. package/dist/mobile/group/floor-state-store.mjs +7 -7
  202. package/dist/mobile/group/group-api-handlers.js +3 -0
  203. package/dist/mobile/group/group-api-handlers.mjs +43 -42
  204. package/dist/mobile/group/group-peer-private-context.mjs +4 -4
  205. package/dist/mobile/group/group-session.mjs +18 -18
  206. package/dist/mobile/group/index.js +63 -17
  207. package/dist/mobile/group/index.mjs +40 -39
  208. package/dist/mobile/group/memory-supplement.mjs +5 -5
  209. package/dist/mobile/group/mention.mjs +3 -3
  210. package/dist/mobile/group/normal-group-router.mjs +2 -2
  211. package/dist/mobile/group/orchestrator.js +62 -17
  212. package/dist/mobile/group/orchestrator.mjs +30 -30
  213. package/dist/mobile/group/pipeline-ceo-dept-mention-parse.mjs +3 -3
  214. package/dist/mobile/group/pipeline-handoff-verification.js +4 -10
  215. package/dist/mobile/group/pipeline-handoff-verification.mjs +4 -4
  216. package/dist/mobile/group/pipeline-turn-outcome.js +5 -14
  217. package/dist/mobile/group/pipeline-turn-outcome.mjs +3 -3
  218. package/dist/mobile/group/plan-runtime.js +61 -13
  219. package/dist/mobile/group/plan-runtime.mjs +18 -18
  220. package/dist/mobile/group/relation-distill.mjs +7 -7
  221. package/dist/mobile/group/remarks.mjs +4 -4
  222. package/dist/mobile/group/runtime-integration.js +65 -17
  223. package/dist/mobile/group/runtime-integration.mjs +41 -40
  224. package/dist/mobile/group/transcript-projection.js +1 -0
  225. package/dist/mobile/group/transcript-projection.mjs +4 -3
  226. package/dist/mobile/index.js +8122 -7324
  227. package/dist/mobile/index.mjs +196 -182
  228. package/dist/mobile/memory-contract-r1-prefetch.mjs +6 -6
  229. package/dist/mobile/memory-contract-r1.js +1 -1
  230. package/dist/mobile/memory-contract-r1.mjs +1 -1
  231. package/dist/mobile/memory-contract-r5-empty-result.mjs +7 -7
  232. package/dist/mobile/memory-runtime-v2/checkpoint-policy.js +1 -61
  233. package/dist/mobile/memory-runtime-v2/checkpoint-policy.mjs +2 -2
  234. package/dist/mobile/memory-runtime-v2/context-pack.js +16 -2
  235. package/dist/mobile/memory-runtime-v2/context-pack.mjs +2 -2
  236. package/dist/mobile/memory-runtime-v2/eval-runner.js +231 -145
  237. package/dist/mobile/memory-runtime-v2/eval-runner.mjs +16 -10
  238. package/dist/mobile/memory-runtime-v2/evidence-plan.js +233 -147
  239. package/dist/mobile/memory-runtime-v2/evidence-plan.mjs +19 -13
  240. package/dist/mobile/memory-runtime-v2/index.js +242 -147
  241. package/dist/mobile/memory-runtime-v2/index.mjs +48 -36
  242. package/dist/mobile/memory-runtime-v2/long-run-guard.js +1 -119
  243. package/dist/mobile/memory-runtime-v2/long-run-guard.mjs +3 -3
  244. package/dist/mobile/memory-runtime-v2/memory-control-plane.js +233 -147
  245. package/dist/mobile/memory-runtime-v2/memory-control-plane.mjs +19 -13
  246. package/dist/mobile/memory-runtime-v2/memory-evidence-graph.mjs +2 -2
  247. package/dist/mobile/memory-runtime-v2/memory-readiness.js +232 -146
  248. package/dist/mobile/memory-runtime-v2/memory-readiness.mjs +19 -13
  249. package/dist/mobile/memory-runtime-v2/orchestrator.js +17 -3
  250. package/dist/mobile/memory-runtime-v2/orchestrator.mjs +6 -6
  251. package/dist/mobile/memory-runtime-v2/public-api.js +233 -147
  252. package/dist/mobile/memory-runtime-v2/public-api.mjs +22 -16
  253. package/dist/mobile/memory-runtime-v2/run-ledger.js +29 -48
  254. package/dist/mobile/memory-runtime-v2/run-ledger.mjs +7 -1
  255. package/dist/mobile/minimax-m3.js +2 -20
  256. package/dist/mobile/minimax-m3.mjs +3 -9
  257. package/dist/mobile/model-context-window-budget.js +19 -4
  258. package/dist/mobile/model-context-window-budget.mjs +7 -3
  259. package/dist/mobile/model-turn-runner.js +61 -2
  260. package/dist/mobile/model-turn-runner.mjs +12 -6
  261. package/dist/mobile/native-anthropic-messages-stream.js +7 -22
  262. package/dist/mobile/native-anthropic-messages-stream.mjs +7 -7
  263. package/dist/mobile/native-openai-text-stream.js +1 -2
  264. package/dist/mobile/native-openai-text-stream.mjs +3 -3
  265. package/dist/mobile/native-provider-api-key.js +2 -2
  266. package/dist/mobile/native-provider-api-key.mjs +1 -1
  267. package/dist/mobile/native-reply-route.js +25 -4
  268. package/dist/mobile/native-reply-route.mjs +10 -8
  269. package/dist/mobile/native-reply-system-prompt-layers.js +497 -392
  270. package/dist/mobile/native-reply-system-prompt-layers.mjs +128 -128
  271. package/dist/mobile/native-reply-system-prompt.js +1 -0
  272. package/dist/mobile/native-reply-system-prompt.mjs +1 -1
  273. package/dist/mobile/native-reply-transcript.js +125 -0
  274. package/dist/mobile/native-reply-transcript.mjs +7 -2
  275. package/dist/mobile/native-request-diagnostics.js +4 -2
  276. package/dist/mobile/native-request-diagnostics.mjs +3 -1
  277. package/dist/mobile/native-stream-block-emit.mjs +3 -3
  278. package/dist/mobile/openai-completions-turn-runner.js +874 -608
  279. package/dist/mobile/openai-completions-turn-runner.mjs +146 -144
  280. package/dist/mobile/runtime.js +8122 -7324
  281. package/dist/mobile/runtime.mjs +195 -181
  282. package/dist/mobile/store.mjs +3 -3
  283. package/dist/mobile/stream-inbound/mobile-text-stream-pipeline.js +321 -9
  284. package/dist/mobile/stream-inbound/mobile-text-stream-pipeline.mjs +11 -4
  285. package/dist/mobile/system-prompt-snapshot.mjs +4 -4
  286. package/dist/mobile/tool-result-final-summary.js +145 -0
  287. package/dist/mobile/tool-result-final-summary.mjs +11 -0
  288. package/dist/mobile/tool-use-input-normalize.js +492 -389
  289. package/dist/mobile/tool-use-input-normalize.mjs +131 -131
  290. package/dist/mobile/tools/mobile-compact-tool-bridge.js +492 -389
  291. package/dist/mobile/tools/mobile-compact-tool-bridge.mjs +130 -130
  292. package/dist/mobile/workspace-startup-pointer.js +1 -1
  293. package/dist/mobile/workspace-startup-pointer.mjs +1 -1
  294. package/dist/org/dept-context.mjs +3 -3
  295. package/dist/owned-tools/agent-tool-config.mjs +2 -2
  296. package/dist/owned-tools/agents-list.mjs +5 -5
  297. package/dist/owned-tools/ceo-confirm-requirements.mjs +8 -8
  298. package/dist/owned-tools/ceo-decision.js +72 -18
  299. package/dist/owned-tools/ceo-decision.mjs +15 -15
  300. package/dist/owned-tools/ceo-ops-brief.mjs +8 -8
  301. package/dist/owned-tools/ceo-redirect.js +3 -0
  302. package/dist/owned-tools/ceo-redirect.mjs +42 -41
  303. package/dist/owned-tools/commit-stack-lesson.mjs +9 -9
  304. package/dist/owned-tools/compact/execute.js +492 -389
  305. package/dist/owned-tools/compact/execute.mjs +128 -128
  306. package/dist/owned-tools/compact/gateway-tool-factory.js +492 -389
  307. package/dist/owned-tools/compact/gateway-tool-factory.mjs +129 -129
  308. package/dist/owned-tools/compact/registry.js +492 -389
  309. package/dist/owned-tools/compact/registry.mjs +127 -127
  310. package/dist/owned-tools/context-compact.js +8 -22
  311. package/dist/owned-tools/context-compact.mjs +55 -49
  312. package/dist/owned-tools/edit.mjs +2 -2
  313. package/dist/owned-tools/exec-primitives.mjs +2 -2
  314. package/dist/owned-tools/exec.js +112 -9
  315. package/dist/owned-tools/exec.mjs +12 -8
  316. package/dist/owned-tools/groups-history.mjs +8 -8
  317. package/dist/owned-tools/handoff.mjs +14 -14
  318. package/dist/owned-tools/internal-tool-names.js +40 -0
  319. package/dist/owned-tools/internal-tool-names.mjs +9 -0
  320. package/dist/owned-tools/media-asset-library.mjs +2 -2
  321. package/dist/owned-tools/memory-control.mjs +21 -15
  322. package/dist/owned-tools/memory-get.js +7 -3
  323. package/dist/owned-tools/memory-get.mjs +1 -1
  324. package/dist/owned-tools/memory-runtime-eval.js +232 -146
  325. package/dist/owned-tools/memory-runtime-eval.mjs +20 -14
  326. package/dist/owned-tools/message.mjs +5 -5
  327. package/dist/owned-tools/owned-reply.mjs +5 -5
  328. package/dist/owned-tools/owned-tool-payload-failure.js +3 -6
  329. package/dist/owned-tools/owned-tool-payload-failure.mjs +1 -1
  330. package/dist/owned-tools/process-registry.mjs +2 -2
  331. package/dist/owned-tools/process.mjs +3 -3
  332. package/dist/owned-tools/providers/minimax-files.mjs +2 -2
  333. package/dist/owned-tools/providers/minimax-video-generate.mjs +3 -3
  334. package/dist/owned-tools/providers/minimax-voice.mjs +3 -3
  335. package/dist/owned-tools/read.mjs +2 -2
  336. package/dist/owned-tools/register-owned-providers.mjs +12 -12
  337. package/dist/owned-tools/registry.js +497 -389
  338. package/dist/owned-tools/registry.mjs +131 -126
  339. package/dist/owned-tools/router.js +554 -451
  340. package/dist/owned-tools/router.mjs +127 -127
  341. package/dist/owned-tools/runtime-bridge.js +554 -451
  342. package/dist/owned-tools/runtime-bridge.mjs +129 -129
  343. package/dist/owned-tools/runtime-data.mjs +4 -4
  344. package/dist/owned-tools/session-status.mjs +6 -6
  345. package/dist/owned-tools/sessions-history-resolver.mjs +7 -7
  346. package/dist/owned-tools/sessions-history.mjs +6 -6
  347. package/dist/owned-tools/sessions-list.mjs +5 -5
  348. package/dist/owned-tools/sessions-send.mjs +6 -6
  349. package/dist/owned-tools/skills-create.mjs +5 -5
  350. package/dist/owned-tools/subagents.mjs +6 -6
  351. package/dist/owned-tools/tool-contract-prompt.js +497 -392
  352. package/dist/owned-tools/tool-contract-prompt.mjs +127 -127
  353. package/dist/owned-tools/tool-result-envelope.js +526 -405
  354. package/dist/owned-tools/tool-result-envelope.mjs +132 -132
  355. package/dist/owned-tools/tool-usage-guide.js +492 -389
  356. package/dist/owned-tools/tool-usage-guide.mjs +126 -126
  357. package/dist/owned-tools/tool-validation.mjs +2 -2
  358. package/dist/owned-tools/tts.mjs +5 -5
  359. package/dist/owned-tools/web-smoke.mjs +6 -6
  360. package/dist/owned-tools/write.mjs +2 -2
  361. package/dist/project/file-tool-scope-default.mjs +3 -3
  362. package/dist/project/file-tool-scope.js +1 -1
  363. package/dist/project/file-tool-scope.mjs +1 -1
  364. package/dist/project-pipeline/handlers.js +3 -0
  365. package/dist/project-pipeline/handlers.mjs +42 -41
  366. package/dist/project-pipeline/index.js +3 -0
  367. package/dist/project-pipeline/index.mjs +42 -41
  368. package/dist/project-pipeline/pipeline-routing.mjs +2 -2
  369. package/dist/project-pipeline/post-close-skill-evolution.mjs +4 -4
  370. package/dist/project-pipeline/project-store.mjs +2 -2
  371. package/gateway-core/runtime/reply/chinese-monologue-deliver-partition.cjs +27 -6
  372. package/package.json +2 -2
  373. package/dist/chunk-4IWTTXQE.mjs +0 -113
  374. package/dist/chunk-Z3COATFF.mjs +0 -25
  375. package/dist/{chunk-QCSNRVL2.mjs → chunk-2YNBEBKQ.mjs} +7 -7
  376. package/dist/{chunk-BRJJML7A.mjs → chunk-5NFOBSYF.mjs} +3 -3
  377. package/dist/{chunk-6ZWKLMY3.mjs → chunk-BYGWNFCJ.mjs} +4 -4
  378. package/dist/{chunk-MIXYB6BH.mjs → chunk-EHL345OC.mjs} +3 -3
  379. package/dist/{chunk-2PWU4VN6.mjs → chunk-IGJFAE72.mjs} +3 -3
  380. package/dist/{chunk-OWIXULFQ.mjs → chunk-K5IQLMJQ.mjs} +3 -3
  381. package/dist/{chunk-H2UCPL5O.mjs → chunk-LY7M7Z7M.mjs} +3 -3
  382. package/dist/{chunk-3OXBG4OP.mjs → chunk-MK32KUVI.mjs} +4 -4
  383. package/dist/{chunk-QVEQRCOD.mjs → chunk-PIDPHIN6.mjs} +4 -4
  384. package/dist/{chunk-F5KN3REF.mjs → chunk-PX55IRYL.mjs} +4 -4
  385. package/dist/{chunk-TQOUQIVS.mjs → chunk-V3XUPTZQ.mjs} +3 -3
  386. package/dist/{chunk-CVXJ45WI.mjs → chunk-WTOP2LEF.mjs} +5 -5
  387. package/dist/{chunk-FY2QAWA6.mjs → chunk-YI7E3RUY.mjs} +5 -5
@@ -2,38 +2,47 @@ import {
2
2
  STREAMABLE_ARGS_FIELD_BY_TOOL,
3
3
  ToolArgsTextDeltaExtractor
4
4
  } from "./chunk-PUZNRJEW.mjs";
5
+ import {
6
+ synthesizeFinalTextFromToolResult,
7
+ toolResultContentToString
8
+ } from "./chunk-YYUB3HQR.mjs";
9
+ import {
10
+ formatModelTurnLoopGuardDetails,
11
+ modelTurnNeedsFollowUp,
12
+ runModelTurnLoop
13
+ } from "./chunk-W5XO4T4J.mjs";
5
14
  import {
6
15
  buildMvpAnthropicToolSchemas,
7
16
  executeAnthropicToolUse
8
- } from "./chunk-6VSIGHGI.mjs";
17
+ } from "./chunk-N4X2MAF2.mjs";
9
18
  import {
10
19
  diagnoseToolUseInputReadiness,
11
20
  formatToolInputDiagLine,
12
21
  isExecutableToolUseInput,
13
22
  resolveToolUseInput
14
- } from "./chunk-FAB2ZZYB.mjs";
23
+ } from "./chunk-CLVSQ3FG.mjs";
15
24
  import {
16
25
  selectAnthropicAdapter
17
- } from "./chunk-UQLGVSQH.mjs";
26
+ } from "./chunk-2F65KBU2.mjs";
18
27
  import {
19
28
  isMinimaxM3Model
20
- } from "./chunk-E7BFLHLM.mjs";
29
+ } from "./chunk-NDPDPELV.mjs";
21
30
  import {
22
31
  readAnthropicSseEventStream
23
32
  } from "./chunk-SPO74LMZ.mjs";
24
33
  import {
25
34
  assistantTurnTranscriptMessage,
26
35
  toolResultsTranscriptMessage
27
- } from "./chunk-6ZVXCJTG.mjs";
36
+ } from "./chunk-TBLUKDLO.mjs";
28
37
  import {
29
38
  AnthropicIncrementalDeliverer
30
- } from "./chunk-3TTLV2GM.mjs";
39
+ } from "./chunk-TKZWE5DB.mjs";
31
40
  import {
32
41
  applyConfiguredMaxTokens,
33
42
  fetchNativeProviderWithRetry,
34
43
  formatRequestShape,
35
44
  stringifyJsonRequestBody
36
- } from "./chunk-E5LABIPO.mjs";
45
+ } from "./chunk-U2NKGGVL.mjs";
37
46
  import {
38
47
  applyAnthropicProviderAccelerationToRequestBody
39
48
  } from "./chunk-JHQIGDVB.mjs";
@@ -64,11 +73,9 @@ function resolveMaxIterations(explicit, env = process.env) {
64
73
  }
65
74
  return cap;
66
75
  }
67
- function toolResultContentToString(content) {
68
- if (typeof content === "string") {
69
- return content;
70
- }
71
- return content.map((c) => c.text).join("");
76
+ function isNativeToolTurnSpeculativeLiveDeliverEnabled(env = process.env) {
77
+ const raw = (env.XKZOOM_NATIVE_TOOL_TURN_SPECULATIVE_LIVE_DELIVER ?? "").trim().toLowerCase();
78
+ return raw === "1" || raw === "true" || raw === "yes";
72
79
  }
73
80
  function trackEarlyToolUseStart(params) {
74
81
  const effect = interpretAnthropicStreamEvent(params.event);
@@ -223,278 +230,304 @@ async function runAnthropicMessagesTurn(params) {
223
230
  let firstSseEventAtMs = null;
224
231
  let finalStreamIdleTimeout = false;
225
232
  let lastToolName = "";
233
+ let lastToolResult = null;
226
234
  const maxIterations = resolveMaxIterations(params.maxIterations);
235
+ const toolsAvailable = params.tools.length > 0;
236
+ const allowSpeculativeToolTurnLiveDeliver = toolsAvailable && isNativeToolTurnSpeculativeLiveDeliverEnabled();
227
237
  let forcedIterationsUsed = 0;
228
238
  const basePolicy = params.toolChoicePolicy ?? { kind: "auto" };
229
239
  const baseForces = basePolicy.kind === "required" || basePolicy.kind === "tool";
230
240
  const canWireForce = params.wireForcedToolChoice !== false;
231
241
  const turnEarlyToolStartIds = /* @__PURE__ */ new Set();
232
- for (let iteration = 0; iteration < maxIterations; iteration += 1) {
233
- iterations = iteration + 1;
234
- let iterAnswer = "";
235
- let iterReasoning = "";
236
- const iterPolicy = canWireForce && baseForces && iteration === 0 ? basePolicy : { kind: "auto" };
237
- const thisIterForced = canWireForce && iterPolicy.kind !== "auto";
238
- const allowLiveDeliver = !thisIterForced;
239
- const pendingToolUseByIndex = /* @__PURE__ */ new Map();
240
- let assembler = new AnthropicStreamAssembler();
241
- let liveDeliver = new AnthropicIncrementalDeliverer(params.dispatcher, reasoningOn, params.log);
242
- let streamIdleTimeout = false;
243
- let toolUses = [];
244
- let finalized = assembler.finalize();
245
- for (let streamAttempt = 0; streamAttempt < 2; streamAttempt += 1) {
246
- iterAnswer = "";
247
- iterReasoning = "";
248
- assembler = new AnthropicStreamAssembler();
249
- liveDeliver = new AnthropicIncrementalDeliverer(params.dispatcher, reasoningOn, params.log);
250
- streamIdleTimeout = false;
251
- let streamSseEvents = 0;
252
- const bufferedStreamEvents = [];
253
- const argsDeltaExtractor = streamAttempt === 0 && params.onToolEvent ? new ToolArgsTextDeltaExtractor() : null;
254
- const stream = params.streamFn(
255
- {
256
- systemPrompt: params.systemPrompt,
257
- messages,
258
- tools: params.tools,
259
- reasoningMode: params.reasoningMode,
260
- iteration,
261
- toolChoicePolicy: iterPolicy
262
- },
263
- params.signal
264
- );
265
- for await (const event of stream) {
266
- if (firstSseEventAtMs === null && !isAnthropicSseStreamMeta(event)) {
267
- firstSseEventAtMs = Date.now();
268
- params.log(
269
- `[XKZOOM][native-reply][stream-diag] first-sse-event ms=${firstSseEventAtMs - turnStartedAtMs} iteration=${iteration}`
270
- );
271
- }
272
- if (params.signal.aborted) {
273
- params.log(
274
- `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} aborted before stream complete`
275
- );
276
- throw new DOMException("Aborted", "AbortError");
277
- }
278
- if (isAnthropicSseStreamMeta(event)) {
279
- streamIdleTimeout = event.idleTimeout;
280
- continue;
281
- }
282
- if (argsDeltaExtractor) {
283
- const argsEffect = interpretAnthropicStreamEvent(event);
284
- if (argsEffect?.kind === "block-start" && argsEffect.block.type === "tool_use") {
285
- const earlyId = (argsEffect.block.id ?? "").trim();
286
- const earlyName = (argsEffect.block.name ?? "").trim();
287
- argsDeltaExtractor.onToolUseBlockStart(argsEffect.index, earlyId, earlyName);
288
- if (earlyId && earlyName && STREAMABLE_ARGS_FIELD_BY_TOOL[earlyName] && !turnEarlyToolStartIds.has(earlyId)) {
289
- turnEarlyToolStartIds.add(earlyId);
290
- params.onToolEvent?.({ phase: "start", toolCallId: earlyId, name: earlyName });
291
- }
292
- } else if (argsEffect?.kind === "input-json-delta") {
293
- const delta = argsDeltaExtractor.onInputJsonDelta(argsEffect.index, argsEffect.partialJson);
294
- if (delta) {
295
- params.onToolEvent?.({
296
- phase: "update",
297
- toolCallId: delta.toolCallId,
298
- argsDelta: { field: delta.field, textDelta: delta.textDelta }
299
- });
300
- }
301
- } else if (argsEffect?.kind === "block-stop") {
302
- argsDeltaExtractor.onBlockStop(argsEffect.index);
242
+ const loopResult = await runModelTurnLoop({
243
+ maxIterations,
244
+ runIteration: async ({ iteration }) => {
245
+ iterations = iteration + 1;
246
+ let iterAnswer = "";
247
+ let iterReasoning = "";
248
+ const iterPolicy = canWireForce && baseForces && iteration === 0 ? basePolicy : { kind: "auto" };
249
+ const thisIterForced = canWireForce && iterPolicy.kind !== "auto";
250
+ const allowLiveDeliver = !thisIterForced && (!toolsAvailable || allowSpeculativeToolTurnLiveDeliver);
251
+ const pendingToolUseByIndex = /* @__PURE__ */ new Map();
252
+ let assembler = new AnthropicStreamAssembler();
253
+ let liveDeliver = new AnthropicIncrementalDeliverer(params.dispatcher, reasoningOn, params.log);
254
+ let streamIdleTimeout = false;
255
+ let toolUses = [];
256
+ let finalized = assembler.finalize();
257
+ for (let streamAttempt = 0; streamAttempt < 2; streamAttempt += 1) {
258
+ iterAnswer = "";
259
+ iterReasoning = "";
260
+ assembler = new AnthropicStreamAssembler();
261
+ liveDeliver = new AnthropicIncrementalDeliverer(params.dispatcher, reasoningOn, params.log);
262
+ streamIdleTimeout = false;
263
+ let streamSseEvents = 0;
264
+ const bufferedStreamEvents = [];
265
+ const argsDeltaExtractor = streamAttempt === 0 && params.onToolEvent ? new ToolArgsTextDeltaExtractor() : null;
266
+ const stream = params.streamFn(
267
+ {
268
+ systemPrompt: params.systemPrompt,
269
+ messages,
270
+ tools: params.tools,
271
+ reasoningMode: params.reasoningMode,
272
+ iteration,
273
+ toolChoicePolicy: iterPolicy
274
+ },
275
+ params.signal
276
+ );
277
+ for await (const event of stream) {
278
+ if (firstSseEventAtMs === null && !isAnthropicSseStreamMeta(event)) {
279
+ firstSseEventAtMs = Date.now();
280
+ params.log(
281
+ `[XKZOOM][native-reply][stream-diag] first-sse-event ms=${firstSseEventAtMs - turnStartedAtMs} iteration=${iteration}`
282
+ );
303
283
  }
304
- }
305
- const { error } = assembler.handle(event, (delta) => {
306
- if (delta.thinkingDelta && reasoningOn) {
307
- iterReasoning += delta.thinkingDelta;
284
+ if (params.signal.aborted) {
285
+ params.log(
286
+ `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} aborted before stream complete`
287
+ );
288
+ throw new DOMException("Aborted", "AbortError");
308
289
  }
309
- if (delta.textDelta) {
310
- iterAnswer += delta.textDelta;
290
+ if (isAnthropicSseStreamMeta(event)) {
291
+ streamIdleTimeout = event.idleTimeout;
292
+ continue;
311
293
  }
312
- if (allowLiveDeliver) {
294
+ if (argsDeltaExtractor) {
295
+ const argsEffect = interpretAnthropicStreamEvent(event);
296
+ if (argsEffect?.kind === "block-start" && argsEffect.block.type === "tool_use") {
297
+ const earlyId = (argsEffect.block.id ?? "").trim();
298
+ const earlyName = (argsEffect.block.name ?? "").trim();
299
+ argsDeltaExtractor.onToolUseBlockStart(argsEffect.index, earlyId, earlyName);
300
+ if (earlyId && earlyName && STREAMABLE_ARGS_FIELD_BY_TOOL[earlyName] && !turnEarlyToolStartIds.has(earlyId)) {
301
+ turnEarlyToolStartIds.add(earlyId);
302
+ params.onToolEvent?.({ phase: "start", toolCallId: earlyId, name: earlyName });
303
+ }
304
+ } else if (argsEffect?.kind === "input-json-delta") {
305
+ const delta = argsDeltaExtractor.onInputJsonDelta(argsEffect.index, argsEffect.partialJson);
306
+ if (delta) {
307
+ params.onToolEvent?.({
308
+ phase: "update",
309
+ toolCallId: delta.toolCallId,
310
+ argsDelta: { field: delta.field, textDelta: delta.textDelta }
311
+ });
312
+ }
313
+ } else if (argsEffect?.kind === "block-stop") {
314
+ argsDeltaExtractor.onBlockStop(argsEffect.index);
315
+ }
316
+ }
317
+ const { error } = assembler.handle(event, (delta) => {
313
318
  if (delta.thinkingDelta && reasoningOn) {
314
- liveDeliver.onThinkingDelta(delta.thinkingDelta);
319
+ iterReasoning += delta.thinkingDelta;
315
320
  }
316
- if (delta.textDelta && !assembler.hasToolUseBlock) {
317
- liveDeliver.onTextDelta(delta.textDelta);
321
+ if (delta.textDelta) {
322
+ iterAnswer += delta.textDelta;
318
323
  }
324
+ if (allowLiveDeliver) {
325
+ if (delta.thinkingDelta && reasoningOn) {
326
+ liveDeliver.onThinkingDelta(delta.thinkingDelta);
327
+ }
328
+ if (delta.textDelta && !assembler.hasToolUseBlock) {
329
+ liveDeliver.onTextDelta(delta.textDelta);
330
+ }
331
+ }
332
+ });
333
+ if (error) {
334
+ throw new Error(`native anthropic-turn stream error: ${error}`);
335
+ }
336
+ bufferedStreamEvents.push(event);
337
+ streamSseEvents += 1;
338
+ if (assembler.hasToolUseBlock && streamSseEvents % 25 === 0) {
339
+ params.log(
340
+ `[XKZOOM][native-reply][anthropic-turn] tool_use stream-progress iteration=${iteration} events=${streamSseEvents} answerLen=${iterAnswer.length}`
341
+ );
319
342
  }
320
- });
321
- if (error) {
322
- throw new Error(`native anthropic-turn stream error: ${error}`);
323
343
  }
324
- bufferedStreamEvents.push(event);
325
- streamSseEvents += 1;
326
- if (assembler.hasToolUseBlock && streamSseEvents % 25 === 0) {
327
- params.log(
328
- `[XKZOOM][native-reply][anthropic-turn] tool_use stream-progress iteration=${iteration} events=${streamSseEvents} answerLen=${iterAnswer.length}`
329
- );
344
+ finalized = assembler.finalize();
345
+ toolUses = resolveToolUsesFromAssembler(assembler);
346
+ const hasIncomplete = toolUses.length > 0 && toolUses.some((tu) => !isExecutableToolUseInput(tu.name, tu.input));
347
+ if (!hasIncomplete) {
348
+ for (const bufferedEvent of bufferedStreamEvents) {
349
+ trackEarlyToolUseStart({
350
+ event: bufferedEvent,
351
+ iteration,
352
+ turnEmittedStartIds: turnEarlyToolStartIds,
353
+ pendingByIndex: pendingToolUseByIndex,
354
+ onToolEvent: params.onToolEvent,
355
+ log: params.log
356
+ });
357
+ }
358
+ break;
330
359
  }
331
- }
332
- finalized = assembler.finalize();
333
- toolUses = resolveToolUsesFromAssembler(assembler);
334
- const hasIncomplete = toolUses.length > 0 && toolUses.some((tu) => !isExecutableToolUseInput(tu.name, tu.input));
335
- if (!hasIncomplete) {
336
- for (const bufferedEvent of bufferedStreamEvents) {
337
- trackEarlyToolUseStart({
338
- event: bufferedEvent,
339
- iteration,
340
- turnEmittedStartIds: turnEarlyToolStartIds,
341
- pendingByIndex: pendingToolUseByIndex,
342
- onToolEvent: params.onToolEvent,
343
- log: params.log
344
- });
360
+ if (streamAttempt === 1) {
361
+ break;
345
362
  }
346
- break;
363
+ const incompleteSummary = toolUses.filter((tu) => !isExecutableToolUseInput(tu.name, tu.input)).map((tu) => `${tu.name}:${tu.id}`).join(",");
364
+ params.log(
365
+ `[XKZOOM][native-reply][anthropic-turn] tool_use batch has incomplete input; retrying provider stream once iteration=${iteration} incomplete=${incompleteSummary}`
366
+ );
347
367
  }
348
- if (streamAttempt === 1) {
349
- break;
368
+ stopReason = finalized.stopReason;
369
+ if (streamIdleTimeout) {
370
+ finalStreamIdleTimeout = true;
350
371
  }
351
- const incompleteSummary = toolUses.filter((tu) => !isExecutableToolUseInput(tu.name, tu.input)).map((tu) => `${tu.name}:${tu.id}`).join(",");
352
- params.log(
353
- `[XKZOOM][native-reply][anthropic-turn] tool_use batch has incomplete input; retrying provider stream once iteration=${iteration} incomplete=${incompleteSummary}`
354
- );
355
- }
356
- stopReason = finalized.stopReason;
357
- if (streamIdleTimeout) {
358
- finalStreamIdleTimeout = true;
359
- }
360
- const blockStats = assembler.getBlockStats();
361
- const usage = assembler.getUsageSnapshot();
362
- params.log(
363
- `[XKZOOM][native-reply][anthropic-turn] block_stats iteration=${iteration} ${formatBlockStats(blockStats)} usage=${formatUsageSnapshot(usage)}`
364
- );
365
- if (!stopReason && toolUses.length > 0) {
366
- stopReason = "tool_use";
367
- params.log(
368
- `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop_reason_synthesized=tool_use toolCalls=${toolUses.length} idleTimeout=${streamIdleTimeout ? 1 : 0}`
369
- );
370
- } else if (!stopReason && iterAnswer.trim().length > 0) {
371
- stopReason = "end_turn";
372
- params.log(
373
- `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop_reason_synthesized=end_turn answerLen=${iterAnswer.length} idleTimeout=${streamIdleTimeout ? 1 : 0}`
374
- );
375
- } else if (streamIdleTimeout && iterAnswer.trim().length > 0 && assembler.hasToolUseBlock && toolUses.length === 0) {
376
- stopReason = "end_turn";
377
- params.log(
378
- `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} incomplete_tool_use_dropped answerLen=${iterAnswer.length} idleTimeout=1`
379
- );
380
- } else if (streamIdleTimeout) {
372
+ const blockStats = assembler.getBlockStats();
373
+ const usage = assembler.getUsageSnapshot();
381
374
  params.log(
382
- `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stream_idle_timeout answerLen=${iterAnswer.length} toolUseBlocks=${assembler.hasToolUseBlock ? 1 : 0}`
375
+ `[XKZOOM][native-reply][anthropic-turn] block_stats iteration=${iteration} ${formatBlockStats(blockStats)} usage=${formatUsageSnapshot(usage)}`
383
376
  );
384
- }
385
- if (stopReason === "tool_use" && toolUses.length === 0) {
386
- params.log(
387
- `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop=tool_use tool_use blocks missing id (provider SSE); retrying`
388
- );
389
- continue;
390
- }
391
- if (stopReason === "tool_use" && toolUses.length > 0) {
392
- const maxToolUsesPerAssistant = params.maxToolUsesPerAssistant && params.maxToolUsesPerAssistant > 0 ? Math.floor(params.maxToolUsesPerAssistant) : Number.POSITIVE_INFINITY;
393
- const limited = limitToolUsesForAssistantMessage({
394
- toolUses,
395
- blocks: finalized.blocks,
396
- maxToolUses: maxToolUsesPerAssistant
397
- });
398
- lastToolName = limited.toolUses[limited.toolUses.length - 1]?.name ?? lastToolName;
399
- if (limited.dropped.length > 0) {
377
+ if (!stopReason && toolUses.length > 0) {
378
+ stopReason = "tool_use";
379
+ params.log(
380
+ `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop_reason_synthesized=tool_use toolCalls=${toolUses.length} idleTimeout=${streamIdleTimeout ? 1 : 0}`
381
+ );
382
+ } else if (!stopReason && iterAnswer.trim().length > 0) {
383
+ stopReason = "end_turn";
384
+ params.log(
385
+ `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop_reason_synthesized=end_turn answerLen=${iterAnswer.length} idleTimeout=${streamIdleTimeout ? 1 : 0}`
386
+ );
387
+ } else if (streamIdleTimeout && iterAnswer.trim().length > 0 && assembler.hasToolUseBlock && toolUses.length === 0) {
388
+ stopReason = "end_turn";
389
+ params.log(
390
+ `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} incomplete_tool_use_dropped answerLen=${iterAnswer.length} idleTimeout=1`
391
+ );
392
+ } else if (streamIdleTimeout) {
400
393
  params.log(
401
- `[XKZOOM][native-reply][anthropic-turn] tool_use serial-limit iteration=${iteration} kept=${limited.toolUses.map((tu) => `${tu.name}:${tu.id}`).join(",")} dropped=${limited.dropped.map((tu) => `${tu.name}:${tu.id}`).join(",")}`
394
+ `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stream_idle_timeout answerLen=${iterAnswer.length} toolUseBlocks=${assembler.hasToolUseBlock ? 1 : 0}`
402
395
  );
403
396
  }
404
- const assistantBlocks = mergeResolvedToolInputsIntoAssistantBlocks(limited.blocks, limited.toolUses);
405
- const blockPartsById = indexToolUseBlockParts(assembler.collectToolUseBlockParts());
406
- const notExecutable = limited.toolUses.filter((tu) => !isExecutableToolUseInput(tu.name, tu.input));
407
- if (notExecutable.length > 0) {
408
- for (const toolUse of notExecutable) {
409
- const readiness = diagnoseToolUseInputReadiness(toolUse.name, toolUse.input);
410
- const streamParts = blockPartsById.get(toolUse.id) ?? {
411
- id: toolUse.id,
412
- name: toolUse.name,
413
- partialJson: ""
414
- };
415
- params.log(formatToolInputDiagLine({ iteration, parts: streamParts, readiness }));
416
- }
397
+ const needsFollowUp = modelTurnNeedsFollowUp(toolUses.length);
398
+ if (stopReason === "tool_use" && !needsFollowUp) {
417
399
  params.log(
418
- `[XKZOOM][native-reply][anthropic-turn] tool_use incomplete input after retry; delegating error envelope iteration=${iteration} tools=${notExecutable.map((tu) => `${tu.name}:${tu.id}`).join(",")}`
400
+ `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop=tool_use tool_use blocks missing id (provider SSE); retrying`
419
401
  );
402
+ return { kind: "follow_up", reason: "tool_use_missing_id" };
420
403
  }
421
- const thinkingByToolId = toolThinkingById(assistantBlocks, limited.toolUses);
422
- messages = [...messages, assistantTurnTranscriptMessage(assistantBlocks)];
423
- const results = await Promise.all(
424
- limited.toolUses.map(async (toolUse) => {
425
- const args = visibleToolUseArgs(toolUse.input);
426
- const readiness = diagnoseToolUseInputReadiness(toolUse.name, toolUse.input);
427
- const streamParts = blockPartsById.get(toolUse.id) ?? {
428
- id: toolUse.id,
429
- name: toolUse.name,
430
- partialJson: ""
431
- };
432
- params.log(formatToolInputDiagLine({ iteration, parts: streamParts, readiness }));
433
- if (!turnEarlyToolStartIds.has(toolUse.id)) {
434
- emitToolUseStartEvent({
435
- toolUse,
436
- thinking: thinkingByToolId.get(toolUse.id),
437
- onToolEvent: params.onToolEvent
438
- });
439
- turnEarlyToolStartIds.add(toolUse.id);
440
- } else if (Object.keys(args).length > 0 || thinkingByToolId.has(toolUse.id)) {
441
- emitToolUseStartEvent({
442
- toolUse,
443
- thinking: thinkingByToolId.get(toolUse.id),
444
- onToolEvent: params.onToolEvent
445
- });
446
- params.log(
447
- `[XKZOOM][native-reply][anthropic-turn] tool_use execute iteration=${iteration} id=${toolUse.id} name=${toolUse.name} argsKeys=${Object.keys(args).join(",")}`
448
- );
404
+ if (needsFollowUp) {
405
+ if (stopReason !== "tool_use") {
406
+ params.log(
407
+ `[XKZOOM][native-reply][anthropic-turn] needs_follow_up_by_tool_use iteration=${iteration} stop=${stopReason ?? "none"} toolCalls=${toolUses.length}`
408
+ );
409
+ }
410
+ const maxToolUsesPerAssistant = params.maxToolUsesPerAssistant && params.maxToolUsesPerAssistant > 0 ? Math.floor(params.maxToolUsesPerAssistant) : Number.POSITIVE_INFINITY;
411
+ const limited = limitToolUsesForAssistantMessage({
412
+ toolUses,
413
+ blocks: finalized.blocks,
414
+ maxToolUses: maxToolUsesPerAssistant
415
+ });
416
+ lastToolName = limited.toolUses[limited.toolUses.length - 1]?.name ?? lastToolName;
417
+ if (limited.dropped.length > 0) {
418
+ params.log(
419
+ `[XKZOOM][native-reply][anthropic-turn] tool_use serial-limit iteration=${iteration} kept=${limited.toolUses.map((tu) => `${tu.name}:${tu.id}`).join(",")} dropped=${limited.dropped.map((tu) => `${tu.name}:${tu.id}`).join(",")}`
420
+ );
421
+ }
422
+ const assistantBlocks = mergeResolvedToolInputsIntoAssistantBlocks(limited.blocks, limited.toolUses);
423
+ const blockPartsById = indexToolUseBlockParts(assembler.collectToolUseBlockParts());
424
+ const notExecutable = limited.toolUses.filter((tu) => !isExecutableToolUseInput(tu.name, tu.input));
425
+ if (notExecutable.length > 0) {
426
+ for (const toolUse of notExecutable) {
427
+ const readiness = diagnoseToolUseInputReadiness(toolUse.name, toolUse.input);
428
+ const streamParts = blockPartsById.get(toolUse.id) ?? {
429
+ id: toolUse.id,
430
+ name: toolUse.name,
431
+ partialJson: ""
432
+ };
433
+ params.log(formatToolInputDiagLine({ iteration, parts: streamParts, readiness }));
449
434
  }
450
- const result = await params.executeToolUse(toolUse);
451
- params.onToolEvent?.({
452
- phase: "result",
453
- toolCallId: toolUse.id,
454
- result: toolResultContentToString(result.content),
455
- isError: result.is_error === true
456
- });
457
- return result;
458
- })
459
- );
460
- messages = [...messages, toolResultsTranscriptMessage(results)];
461
- toolCalls += limited.toolUses.length;
462
- params.log(
463
- `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop=tool_use toolCalls=${limited.toolUses.length} cumulativeToolCalls=${toolCalls}` + (limited.toolUses.length > 1 ? ` parallel=1` : "")
464
- );
465
- continue;
466
- }
467
- finalAnswer = iterAnswer;
468
- finalReasoning = iterReasoning;
469
- if (reasoningOn && !iterReasoning.trim()) {
470
- const thinkingFromBlocks = finalized.blocks.filter((b) => b.type === "thinking").map((b) => b.thinking).join("");
471
- if (thinkingFromBlocks.trim()) {
472
- iterReasoning = thinkingFromBlocks;
473
- finalReasoning = thinkingFromBlocks;
435
+ params.log(
436
+ `[XKZOOM][native-reply][anthropic-turn] tool_use incomplete input after retry; delegating error envelope iteration=${iteration} tools=${notExecutable.map((tu) => `${tu.name}:${tu.id}`).join(",")}`
437
+ );
438
+ }
439
+ const thinkingByToolId = toolThinkingById(assistantBlocks, limited.toolUses);
440
+ messages = [...messages, assistantTurnTranscriptMessage(assistantBlocks)];
441
+ const results = await Promise.all(
442
+ limited.toolUses.map(async (toolUse) => {
443
+ const args = visibleToolUseArgs(toolUse.input);
444
+ const readiness = diagnoseToolUseInputReadiness(toolUse.name, toolUse.input);
445
+ const streamParts = blockPartsById.get(toolUse.id) ?? {
446
+ id: toolUse.id,
447
+ name: toolUse.name,
448
+ partialJson: ""
449
+ };
450
+ params.log(formatToolInputDiagLine({ iteration, parts: streamParts, readiness }));
451
+ if (!turnEarlyToolStartIds.has(toolUse.id)) {
452
+ emitToolUseStartEvent({
453
+ toolUse,
454
+ thinking: thinkingByToolId.get(toolUse.id),
455
+ onToolEvent: params.onToolEvent
456
+ });
457
+ turnEarlyToolStartIds.add(toolUse.id);
458
+ } else if (Object.keys(args).length > 0 || thinkingByToolId.has(toolUse.id)) {
459
+ emitToolUseStartEvent({
460
+ toolUse,
461
+ thinking: thinkingByToolId.get(toolUse.id),
462
+ onToolEvent: params.onToolEvent
463
+ });
464
+ params.log(
465
+ `[XKZOOM][native-reply][anthropic-turn] tool_use execute iteration=${iteration} id=${toolUse.id} name=${toolUse.name} argsKeys=${Object.keys(args).join(",")}`
466
+ );
467
+ }
468
+ const result = await params.executeToolUse(toolUse);
469
+ params.onToolEvent?.({
470
+ phase: "result",
471
+ toolCallId: toolUse.id,
472
+ result: toolResultContentToString(result.content),
473
+ isError: result.is_error === true
474
+ });
475
+ return result;
476
+ })
477
+ );
478
+ lastToolResult = results[results.length - 1] ?? lastToolResult;
479
+ messages = [...messages, toolResultsTranscriptMessage(results)];
480
+ toolCalls += limited.toolUses.length;
481
+ params.log(
482
+ `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop=tool_use toolCalls=${limited.toolUses.length} cumulativeToolCalls=${toolCalls}` + (limited.toolUses.length > 1 ? ` parallel=1` : "")
483
+ );
484
+ return { kind: "follow_up", reason: "tool_use" };
474
485
  }
475
- }
476
- if (reasoningOn && blockStats.thinkingBlocks === 0) {
486
+ finalAnswer = iterAnswer;
487
+ finalReasoning = iterReasoning;
488
+ if (reasoningOn && !iterReasoning.trim()) {
489
+ const thinkingFromBlocks = finalized.blocks.filter((b) => b.type === "thinking").map((b) => b.thinking).join("");
490
+ if (thinkingFromBlocks.trim()) {
491
+ iterReasoning = thinkingFromBlocks;
492
+ finalReasoning = thinkingFromBlocks;
493
+ }
494
+ }
495
+ if (reasoningOn && blockStats.thinkingBlocks === 0) {
496
+ params.log(
497
+ `[XKZOOM][native-reply][anthropic-turn] reasoning_requested_but_no_thinking_block iteration=${iteration} stop=${stopReason ?? "none"} answerLen=${iterAnswer.length}`
498
+ );
499
+ }
500
+ const finalThinkingBlock = finalized.blocks.find((b) => b.type === "thinking");
501
+ finalReasoningSignature = finalThinkingBlock?.type === "thinking" ? finalThinkingBlock.signature ?? "" : "";
502
+ if (!assembler.hasToolUseBlock || stopReason === "end_turn") {
503
+ liveDeliver.flush();
504
+ if (reasoningOn && iterReasoning.trim()) {
505
+ liveDeliver.ensureReasoningTextDelivered(iterReasoning);
506
+ }
507
+ }
508
+ finalLiveDeliver = liveDeliver;
477
509
  params.log(
478
- `[XKZOOM][native-reply][anthropic-turn] reasoning_requested_but_no_thinking_block iteration=${iteration} stop=${stopReason ?? "none"} answerLen=${iterAnswer.length}`
510
+ `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop=${stopReason ?? "none"} answerLen=${finalAnswer.length} reasoningLen=${finalReasoning.length} liveDelivered=${liveDeliver.hasDelivered ? 1 : 0} done`
479
511
  );
512
+ return { kind: "final", value: void 0 };
480
513
  }
481
- const finalThinkingBlock = finalized.blocks.find((b) => b.type === "thinking");
482
- finalReasoningSignature = finalThinkingBlock?.type === "thinking" ? finalThinkingBlock.signature ?? "" : "";
483
- if (!assembler.hasToolUseBlock || stopReason === "end_turn") {
484
- liveDeliver.flush();
485
- if (reasoningOn && iterReasoning.trim()) {
486
- liveDeliver.ensureReasoningTextDelivered(iterReasoning);
487
- }
488
- }
489
- finalLiveDeliver = liveDeliver;
514
+ });
515
+ iterations = loopResult.iterations;
516
+ let answerToDeliver = finalAnswer;
517
+ const initialVisibleLen = answerToDeliver.trim().length + (reasoningOn ? finalReasoning.trim().length : 0);
518
+ if (initialVisibleLen === 0 && toolCalls > 0) {
519
+ answerToDeliver = synthesizeFinalTextFromToolResult({
520
+ toolName: lastToolName,
521
+ toolCalls,
522
+ result: lastToolResult
523
+ });
524
+ finalAnswer = answerToDeliver;
490
525
  params.log(
491
- `[XKZOOM][native-reply][anthropic-turn] iteration=${iteration} stop=${stopReason ?? "none"} answerLen=${finalAnswer.length} reasoningLen=${finalReasoning.length} liveDelivered=${liveDeliver.hasDelivered ? 1 : 0} done`
526
+ `[XKZOOM][native-reply][anthropic-turn] synthesized final from last tool_result toolCalls=${toolCalls} lastToolName=${lastToolName || "unknown"} answerLen=${answerToDeliver.length}`
492
527
  );
493
- break;
494
528
  }
495
- const answerToDeliver = finalAnswer;
496
- if (iterations >= maxIterations && stopReason === "tool_use") {
497
- const details = formatStreamEmptyDetails({
529
+ if (loopResult.kind === "exhausted" && loopResult.lastFollowUpReason) {
530
+ const streamDetails = formatStreamEmptyDetails({
498
531
  iterations,
499
532
  stopReason,
500
533
  toolCalls,
@@ -504,9 +537,15 @@ async function runAnthropicMessagesTurn(params) {
504
537
  idleTimeout: finalStreamIdleTimeout,
505
538
  lastToolName
506
539
  });
540
+ const details = `${formatModelTurnLoopGuardDetails({
541
+ maxIterations,
542
+ iterations,
543
+ lastFollowUpReason: loopResult.lastFollowUpReason,
544
+ lastToolName
545
+ })} (${streamDetails})`;
507
546
  params.log(`[XKZOOM][native-reply][anthropic-turn] loop_guard ${details}`);
508
547
  throw new Error(
509
- `native anthropic-turn loop_guard: maxIterations=${maxIterations} reached before final answer (${details})`
548
+ `native anthropic-turn loop_guard: ${details}`
510
549
  );
511
550
  }
512
551
  const visibleLen = answerToDeliver.trim().length + (reasoningOn ? finalReasoning.trim().length : 0);
@@ -542,6 +581,14 @@ async function runAnthropicMessagesTurn(params) {
542
581
  `[XKZOOM][native-reply][anthropic-turn] forced-tool-no-call fallback_to_final_text=1 ${details}`
543
582
  );
544
583
  }
584
+ const liveDeliverySuppressedForToolTurn = toolsAvailable && !allowSpeculativeToolTurnLiveDeliver;
585
+ if (liveDeliverySuppressedForToolTurn && finalLiveDeliver && answerToDeliver.trim().length > 0 && finalLiveDeliver.answerLen === 0 && !finalLiveDeliver.isAnswerFullyDelivered(answerToDeliver)) {
586
+ finalLiveDeliver.onTextDelta(answerToDeliver);
587
+ finalLiveDeliver.flush();
588
+ params.log(
589
+ `[XKZOOM][native-reply][anthropic-turn] tool-turn final replay via pure_delta answerLen=${answerToDeliver.length}`
590
+ );
591
+ }
545
592
  if (finalLiveDeliver?.isAnswerFullyDelivered(answerToDeliver)) {
546
593
  params.log(
547
594
  `[XKZOOM][native-reply][anthropic-turn] skip duplicate sendFinalReply answerLen=${answerToDeliver.length}`