xkzoom 1.5.4 → 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 (423) hide show
  1. package/README.md +65 -0
  2. package/dist/{chunk-YPKHMAO4.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-OBYPZT2S.mjs → chunk-2YB6BHIB.mjs} +9 -9
  8. package/dist/chunk-35SKU3FL.mjs +279 -0
  9. package/dist/{chunk-PETWGCGB.mjs → chunk-3JHD7MGZ.mjs} +2 -2
  10. package/dist/{chunk-PW3ULDNL.mjs → chunk-3QE7GUJC.mjs} +1 -1
  11. package/dist/{chunk-JI67TW4E.mjs → chunk-4XJFA7V3.mjs} +1 -1
  12. package/dist/{chunk-CQUISJWG.mjs → chunk-5G3UUQ36.mjs} +2 -2
  13. package/dist/{chunk-HYSOWPIC.mjs → chunk-6KCPL45H.mjs} +5 -5
  14. package/dist/{chunk-2IQAT3PE.mjs → chunk-6OY3GOUH.mjs} +6 -6
  15. package/dist/{chunk-LBZCBBHU.mjs → chunk-72IPGTJZ.mjs} +1 -1
  16. package/dist/{chunk-TVH4LII3.mjs → chunk-74S3DUNZ.mjs} +1 -1
  17. package/dist/{chunk-MPGMU75K.mjs → chunk-7C7HREZO.mjs} +12 -12
  18. package/dist/{chunk-BFSOQ5IG.mjs → chunk-7HQEB7IJ.mjs} +3 -3
  19. package/dist/{chunk-3VA3YDYL.mjs → chunk-7TKZKTS5.mjs} +1 -1
  20. package/dist/{chunk-M3ISDSQP.mjs → chunk-A4BZZNPW.mjs} +5 -5
  21. package/dist/{chunk-BJ6YI2DJ.mjs → chunk-AEE3DM6S.mjs} +1 -1
  22. package/dist/{chunk-4JXTPCOE.mjs → chunk-ANGNUW6F.mjs} +5 -5
  23. package/dist/{chunk-GZZ7KO57.mjs → chunk-BJFTC4GW.mjs} +21 -1
  24. package/dist/{chunk-GYZ4IXUD.mjs → chunk-CLN4OVFM.mjs} +3 -6
  25. package/dist/{chunk-3KJHUTOO.mjs → chunk-CLVSQ3FG.mjs} +2 -2
  26. package/dist/{chunk-IKQ7CLX3.mjs → chunk-CSKP6E6Y.mjs} +2 -2
  27. package/dist/{chunk-LWCO2YNI.mjs → chunk-CVWDLRQI.mjs} +1 -1
  28. package/dist/{chunk-FG6QCRVN.mjs → chunk-D4TNMY2O.mjs} +2 -2
  29. package/dist/{chunk-FLVJABFP.mjs → chunk-DODTDJSF.mjs} +10 -8
  30. package/dist/{chunk-MWRQORKQ.mjs → chunk-E36MAP7Y.mjs} +1 -1
  31. package/dist/{chunk-CFZVBILR.mjs → chunk-EHL345OC.mjs} +4 -4
  32. package/dist/chunk-F3Y7WDC6.mjs +108 -0
  33. package/dist/{chunk-Q33JD64H.mjs → chunk-FCK6QFJB.mjs} +1 -1
  34. package/dist/{chunk-3ZH273T7.mjs → chunk-FEEEY457.mjs} +71 -55
  35. package/dist/{chunk-MDZUWIBH.mjs → chunk-G3E2E6DD.mjs} +38 -38
  36. package/dist/{chunk-WXELBVXY.mjs → chunk-GC2H3KNZ.mjs} +1 -1
  37. package/dist/{chunk-5SE4JOKE.mjs → chunk-GHWAAAG6.mjs} +309 -262
  38. package/dist/{chunk-5YEFG7BF.mjs → chunk-GNDVHDPO.mjs} +52 -52
  39. package/dist/chunk-H4NINXMV.mjs +95 -0
  40. package/dist/{chunk-TQBVFKCT.mjs → chunk-H6W42R46.mjs} +194 -154
  41. package/dist/chunk-H7ILBOZU.mjs +48 -0
  42. package/dist/{chunk-7LEEVP5O.mjs → chunk-H7QNACAJ.mjs} +12 -12
  43. package/dist/chunk-HCYIE2PR.mjs +130 -0
  44. package/dist/{chunk-E2TTUY6R.mjs → chunk-HHPHIVCC.mjs} +11 -11
  45. package/dist/{chunk-P262PAGZ.mjs → chunk-HLYVEYML.mjs} +15 -2
  46. package/dist/{chunk-GZJMFCRG.mjs → chunk-HNYI45WM.mjs} +23 -4
  47. package/dist/{chunk-JFFBD5TV.mjs → chunk-HOII5XBJ.mjs} +17 -17
  48. package/dist/{chunk-T23H5D4O.mjs → chunk-HPZG5VVI.mjs} +3 -9
  49. package/dist/chunk-HQHICFPO.mjs +58 -0
  50. package/dist/{chunk-DRY7AJMM.mjs → chunk-HQPA2MV5.mjs} +7 -7
  51. package/dist/{chunk-NJAPWQ4D.mjs → chunk-ICKBF7KF.mjs} +2 -60
  52. package/dist/{chunk-HAI7DJD2.mjs → chunk-IEF2AMNW.mjs} +7 -7
  53. package/dist/{chunk-VIZQURO5.mjs → chunk-IGJFAE72.mjs} +9 -9
  54. package/dist/{chunk-IT2GAHAL.mjs → chunk-IHMPR5HT.mjs} +1 -1
  55. package/dist/{chunk-PJKLQF3K.mjs → chunk-INFZEMQK.mjs} +1 -1
  56. package/dist/{chunk-MKYCBV3H.mjs → chunk-J4FQVXEA.mjs} +7 -7
  57. package/dist/{chunk-27BXVTXH.mjs → chunk-JN5EMEXS.mjs} +1 -1
  58. package/dist/{chunk-4WWT6OC2.mjs → chunk-JTKSYLZE.mjs} +26 -48
  59. package/dist/{chunk-ZTKJR7OC.mjs → chunk-K5IQLMJQ.mjs} +4 -4
  60. package/dist/{chunk-GIAML5K5.mjs → chunk-K5JMXCH5.mjs} +1 -1
  61. package/dist/{chunk-JJKRD5DL.mjs → chunk-KBEY4ZQV.mjs} +4 -4
  62. package/dist/{chunk-EL6TOIFZ.mjs → chunk-KHQPC6I7.mjs} +1 -16
  63. package/dist/{chunk-VNEPNUBZ.mjs → chunk-L3PV2ZNB.mjs} +15 -15
  64. package/dist/{chunk-MQKREMOB.mjs → chunk-L7N2B4LX.mjs} +8 -8
  65. package/dist/{chunk-PS6X3CND.mjs → chunk-LKSRZTSL.mjs} +1 -0
  66. package/dist/{chunk-DCSERRXG.mjs → chunk-LNPOTNGJ.mjs} +1 -1
  67. package/dist/chunk-LOMDPHVQ.mjs +42 -0
  68. package/dist/chunk-LQHI5VK2.mjs +26 -0
  69. package/dist/{chunk-J5AXFEDQ.mjs → chunk-LTTSUVF5.mjs} +52 -52
  70. package/dist/{chunk-LESS4N25.mjs → chunk-LV3CI5A4.mjs} +5 -5
  71. package/dist/{chunk-JG3K4N5B.mjs → chunk-M3E2R3PT.mjs} +1 -1
  72. package/dist/{chunk-WPMJCKI2.mjs → chunk-M7DB4RAC.mjs} +9 -9
  73. package/dist/{chunk-COYZO24J.mjs → chunk-MCD5TOFD.mjs} +1 -1
  74. package/dist/{chunk-AP4WVS6L.mjs → chunk-MCJPAZBQ.mjs} +1 -1
  75. package/dist/{chunk-T6XDJ2QQ.mjs → chunk-MGIGU4G6.mjs} +119 -18
  76. package/dist/{chunk-ZMQ3UOGP.mjs → chunk-MMWLRPKT.mjs} +13 -1
  77. package/dist/{chunk-NIU6GWKB.mjs → chunk-MNLMVNF5.mjs} +5 -5
  78. package/dist/{chunk-W75Z6CZR.mjs → chunk-MXKSS63B.mjs} +2 -2
  79. package/dist/{chunk-TADSGGK2.mjs → chunk-N4X2MAF2.mjs} +14 -28
  80. package/dist/{chunk-E7BFLHLM.mjs → chunk-NDPDPELV.mjs} +1 -16
  81. package/dist/{chunk-24GJWXMG.mjs → chunk-NI2PDCVA.mjs} +3 -3
  82. package/dist/{chunk-BSG6WLML.mjs → chunk-NI4N35JN.mjs} +1 -1
  83. package/dist/{chunk-Z2JNJLJM.mjs → chunk-NLUF66E7.mjs} +1 -1
  84. package/dist/{chunk-RKZ56GST.mjs → chunk-NRPE77A3.mjs} +2 -2
  85. package/dist/{chunk-76TKUYY3.mjs → chunk-NTVWS2MO.mjs} +6 -6
  86. package/dist/{chunk-YYDDQEY4.mjs → chunk-NV7SYEH7.mjs} +2 -2
  87. package/dist/{chunk-6W4W5JLG.mjs → chunk-NXVXMXL5.mjs} +3 -3
  88. package/dist/{chunk-PINXXWFJ.mjs → chunk-OGT25PYJ.mjs} +1 -1
  89. package/dist/{chunk-3STOFADV.mjs → chunk-OHCBAEML.mjs} +1 -0
  90. package/dist/{chunk-L252ASZW.mjs → chunk-OPTSEYTI.mjs} +1 -1
  91. package/dist/{chunk-B4YKXZ5W.mjs → chunk-OQMIECO2.mjs} +1 -1
  92. package/dist/{chunk-D3N7EHB2.mjs → chunk-PH5QACOX.mjs} +19 -19
  93. package/dist/{chunk-6MOIFLPP.mjs → chunk-PKJLFQRF.mjs} +1 -1
  94. package/dist/{chunk-M5IU6U3O.mjs → chunk-POOU2U4R.mjs} +2 -2
  95. package/dist/{chunk-IGDJGBAI.mjs → chunk-PPMT66BN.mjs} +3 -3
  96. package/dist/{chunk-RZOILUDC.mjs → chunk-PSZPHCUP.mjs} +1 -1
  97. package/dist/{chunk-MXXTDG5V.mjs → chunk-PVSCARHF.mjs} +1 -1
  98. package/dist/chunk-PW6NSDMI.mjs +117 -0
  99. package/dist/{chunk-NHICONJ3.mjs → chunk-PZAMMLMJ.mjs} +3 -3
  100. package/dist/{chunk-IDQ5B572.mjs → chunk-QDN74R5G.mjs} +5 -5
  101. package/dist/{chunk-VWAUDB4X.mjs → chunk-QHIZRYTO.mjs} +2 -2
  102. package/dist/{chunk-2DR5RT3I.mjs → chunk-QITZ7SAD.mjs} +499 -943
  103. package/dist/{chunk-N2CMVW47.mjs → chunk-QRHBGABQ.mjs} +7 -3
  104. package/dist/{chunk-F35EHL5U.mjs → chunk-RM6GZ2SF.mjs} +7 -7
  105. package/dist/{chunk-JXDHNASC.mjs → chunk-RUMRGCYN.mjs} +85 -42
  106. package/dist/{chunk-K7RZQIPZ.mjs → chunk-S54MBJWY.mjs} +6 -4
  107. package/dist/{chunk-MBOWNG3A.mjs → chunk-S573TMN6.mjs} +2 -2
  108. package/dist/{chunk-UFV3WER4.mjs → chunk-SJ5LNKAH.mjs} +1 -1
  109. package/dist/chunk-SJWQGIQU.mjs +99 -0
  110. package/dist/{chunk-KWQEFCOY.mjs → chunk-SMHFMHQ2.mjs} +1 -1
  111. package/dist/{chunk-LGNLS7ZN.mjs → chunk-SPUVJNKO.mjs} +2 -2
  112. package/dist/{chunk-JBKRS62W.mjs → chunk-T3EJW65E.mjs} +6 -6
  113. package/dist/{chunk-6ZVXCJTG.mjs → chunk-TBLUKDLO.mjs} +91 -1
  114. package/dist/{chunk-76MFE24I.mjs → chunk-TKZWE5DB.mjs} +1 -1
  115. package/dist/{chunk-3CPVI6Y2.mjs → chunk-TRSW7QJW.mjs} +1 -1
  116. package/dist/{chunk-UXEZFEB3.mjs → chunk-TSS3NVRA.mjs} +18 -17
  117. package/dist/{chunk-WRZWEAMN.mjs → chunk-TU75ILAE.mjs} +1 -1
  118. package/dist/{chunk-E5LABIPO.mjs → chunk-U2NKGGVL.mjs} +3 -2
  119. package/dist/{chunk-KLQSTA6K.mjs → chunk-U7TPS3MS.mjs} +1 -1
  120. package/dist/chunk-UOCUHKR5.mjs +21 -0
  121. package/dist/{chunk-VA7SUI2L.mjs → chunk-VD4DIRCW.mjs} +1 -1
  122. package/dist/chunk-VHQ5WHXF.mjs +17 -0
  123. package/dist/{chunk-MRTQWCNC.mjs → chunk-VMRVJ2VF.mjs} +9 -9
  124. package/dist/{chunk-MJDJIPB4.mjs → chunk-VRG32WNZ.mjs} +1 -1
  125. package/dist/chunk-W5XO4T4J.mjs +63 -0
  126. package/dist/{chunk-5ZMY6RTR.mjs → chunk-WASHQYUB.mjs} +2 -2
  127. package/dist/{chunk-XNQJRIGR.mjs → chunk-WHP2GNEC.mjs} +66 -15
  128. package/dist/chunk-WI7PS7YW.mjs +79 -0
  129. package/dist/{chunk-GIC2RBVM.mjs → chunk-WMLZDHER.mjs} +51 -33
  130. package/dist/{chunk-4POYX4AW.mjs → chunk-WVTJXJY4.mjs} +1 -1
  131. package/dist/{chunk-KPDVZFJY.mjs → chunk-WYCMXDZT.mjs} +1 -1
  132. package/dist/{chunk-LFZAVCVW.mjs → chunk-XD5XGGQA.mjs} +1 -1
  133. package/dist/{chunk-NEDXMES6.mjs → chunk-YAGU7I25.mjs} +2 -2
  134. package/dist/{chunk-TRMEHTAT.mjs → chunk-YSI3ZONB.mjs} +1 -1
  135. package/dist/chunk-YTBKWX7J.mjs +102 -0
  136. package/dist/chunk-YYUB3HQR.mjs +119 -0
  137. package/dist/{chunk-CTKIQWTE.mjs → chunk-ZOJEC5RT.mjs} +1 -1
  138. package/dist/{chunk-2VSERWT6.mjs → chunk-ZXJY3JIP.mjs} +2 -2
  139. package/dist/index.js +7773 -6876
  140. package/dist/index.mjs +271 -256
  141. package/dist/mobile/action-planner.js +492 -389
  142. package/dist/mobile/action-planner.mjs +155 -155
  143. package/dist/mobile/agent-capabilities.js +492 -389
  144. package/dist/mobile/agent-capabilities.mjs +155 -155
  145. package/dist/mobile/agent-shop/handlers.mjs +5 -5
  146. package/dist/mobile/agents-watch.js +346 -0
  147. package/dist/mobile/agents-watch.mjs +13 -0
  148. package/dist/mobile/anthropic-incremental-deliver.mjs +4 -4
  149. package/dist/mobile/anthropic-messages-turn-runner.js +1160 -887
  150. package/dist/mobile/anthropic-messages-turn-runner.mjs +172 -170
  151. package/dist/mobile/anthropic-owned-tool-executor.js +542 -435
  152. package/dist/mobile/anthropic-owned-tool-executor.mjs +169 -169
  153. package/dist/mobile/anthropic-provider-adapter.js +23 -18
  154. package/dist/mobile/anthropic-provider-adapter.mjs +3 -2
  155. package/dist/mobile/api.js +236 -147
  156. package/dist/mobile/api.mjs +84 -83
  157. package/dist/mobile/auth.mjs +1 -1
  158. package/dist/mobile/bucket-events/emit-bucket-frame.js +327 -0
  159. package/dist/mobile/bucket-events/emit-bucket-frame.mjs +8 -3
  160. package/dist/mobile/bucket-events/register-bucket-gateway-bridge.js +320 -3
  161. package/dist/mobile/bucket-events/register-bucket-gateway-bridge.mjs +9 -4
  162. package/dist/mobile/channel.mjs +2 -2
  163. package/dist/mobile/chinese-monologue-deliver-partition.js +21 -1
  164. package/dist/mobile/chinese-monologue-deliver-partition.mjs +1 -1
  165. package/dist/mobile/context-compact/compact-artifact-enrich.mjs +18 -18
  166. package/dist/mobile/context-compact/compact-artifact-writer.mjs +3 -3
  167. package/dist/mobile/context-compact/compact-engine-artifacts.mjs +5 -5
  168. package/dist/mobile/context-compact/compact-memory-distill-job.mjs +3 -3
  169. package/dist/mobile/context-compact/compact-message-collector.mjs +2 -2
  170. package/dist/mobile/context-compact/compact-orchestrator.js +8 -22
  171. package/dist/mobile/context-compact/compact-orchestrator.mjs +41 -41
  172. package/dist/mobile/context-compact/compact-resume-prefetch.mjs +3 -3
  173. package/dist/mobile/context-compact/compact-summarizer-engine-artifact.mjs +20 -20
  174. package/dist/mobile/context-compact/compact-summarizer-llm-request.js +2 -1
  175. package/dist/mobile/context-compact/compact-summarizer-llm-request.mjs +11 -11
  176. package/dist/mobile/context-compact/compact-summarizer-llm.js +5 -19
  177. package/dist/mobile/context-compact/compact-summarizer-llm.mjs +12 -12
  178. package/dist/mobile/context-compact/compact-summarizer.js +5 -19
  179. package/dist/mobile/context-compact/compact-summarizer.mjs +17 -17
  180. package/dist/mobile/context-compact/compact-visible-tool-chain.mjs +2 -2
  181. package/dist/mobile/context-compact/compact-write-verifier.mjs +2 -2
  182. package/dist/mobile/context-compact/context-budget-gate.js +111 -84
  183. package/dist/mobile/context-compact/context-budget-gate.mjs +5 -5
  184. package/dist/mobile/context-compact/native-transcript-budget.js +151 -79
  185. package/dist/mobile/context-compact/native-transcript-budget.mjs +7 -3
  186. package/dist/mobile/context-compact/runtime-compact-hook.js +592 -468
  187. package/dist/mobile/context-compact/runtime-compact-hook.mjs +158 -158
  188. package/dist/mobile/dispatch/compact-resume-contract.js +567 -0
  189. package/dist/mobile/dispatch/compact-resume-contract.mjs +39 -0
  190. package/dist/mobile/dispatch/dispatch-context-assembly.js +588 -0
  191. package/dist/mobile/dispatch/dispatch-context-assembly.mjs +20 -0
  192. package/dist/mobile/dispatch/dispatch-route.js +547 -0
  193. package/dist/mobile/dispatch/dispatch-route.mjs +23 -0
  194. package/dist/mobile/dispatch/dispatch-streaming.js +51 -0
  195. package/dist/mobile/dispatch/dispatch-streaming.mjs +9 -0
  196. package/dist/mobile/dispatch/finalize-contract.js +147 -0
  197. package/dist/mobile/dispatch/finalize-contract.mjs +38 -0
  198. package/dist/mobile/dispatch/inbound-prep.js +671 -0
  199. package/dist/mobile/dispatch/inbound-prep.mjs +31 -0
  200. package/dist/mobile/dispatch/interrupted-snapshot.js +190 -0
  201. package/dist/mobile/dispatch/interrupted-snapshot.mjs +11 -0
  202. package/dist/mobile/dispatch/mobile-dispatch-error.js +41 -0
  203. package/dist/mobile/dispatch/mobile-dispatch-error.mjs +7 -0
  204. package/dist/mobile/dispatch/native-turn-executor.js +42662 -0
  205. package/dist/mobile/dispatch/native-turn-executor.mjs +320 -0
  206. package/dist/mobile/dispatch/native-turn-route.js +1465 -0
  207. package/dist/mobile/dispatch/native-turn-route.mjs +34 -0
  208. package/dist/mobile/dispatch/native-turn-transcript.js +1134 -0
  209. package/dist/mobile/dispatch/native-turn-transcript.mjs +29 -0
  210. package/dist/mobile/group/conductor-llm.js +5 -19
  211. package/dist/mobile/group/conductor-llm.mjs +15 -15
  212. package/dist/mobile/group/conductor-plan-llm.js +5 -19
  213. package/dist/mobile/group/conductor-plan-llm.mjs +22 -22
  214. package/dist/mobile/group/delivery-verification.js +61 -13
  215. package/dist/mobile/group/delivery-verification.mjs +4 -4
  216. package/dist/mobile/group/direct-chat-group-context.mjs +6 -6
  217. package/dist/mobile/group/execution-plan.js +61 -13
  218. package/dist/mobile/group/execution-plan.mjs +5 -5
  219. package/dist/mobile/group/floor-scheduler.mjs +9 -9
  220. package/dist/mobile/group/floor-state-store.mjs +6 -6
  221. package/dist/mobile/group/group-api-handlers.js +3 -0
  222. package/dist/mobile/group/group-api-handlers.mjs +61 -60
  223. package/dist/mobile/group/group-peer-private-context.mjs +5 -5
  224. package/dist/mobile/group/group-session.mjs +25 -25
  225. package/dist/mobile/group/index.js +63 -17
  226. package/dist/mobile/group/index.mjs +51 -50
  227. package/dist/mobile/group/memory-supplement.mjs +9 -9
  228. package/dist/mobile/group/mention.mjs +3 -3
  229. package/dist/mobile/group/normal-group-router.mjs +2 -2
  230. package/dist/mobile/group/orchestrator.js +62 -17
  231. package/dist/mobile/group/orchestrator.mjs +44 -44
  232. package/dist/mobile/group/pipeline-ceo-dept-mention-parse.mjs +3 -3
  233. package/dist/mobile/group/pipeline-handoff-verification.js +4 -10
  234. package/dist/mobile/group/pipeline-handoff-verification.mjs +3 -3
  235. package/dist/mobile/group/pipeline-turn-outcome.js +5 -14
  236. package/dist/mobile/group/pipeline-turn-outcome.mjs +2 -2
  237. package/dist/mobile/group/plan-runtime.js +61 -13
  238. package/dist/mobile/group/plan-runtime.mjs +26 -26
  239. package/dist/mobile/group/relation-distill.mjs +10 -10
  240. package/dist/mobile/group/remarks.mjs +4 -4
  241. package/dist/mobile/group/runtime-integration.js +65 -17
  242. package/dist/mobile/group/runtime-integration.mjs +59 -58
  243. package/dist/mobile/group/team-memory-runtime.mjs +3 -3
  244. package/dist/mobile/group/transcript-projection.js +1 -0
  245. package/dist/mobile/group/transcript-projection.mjs +4 -3
  246. package/dist/mobile/index.js +8046 -7126
  247. package/dist/mobile/index.mjs +256 -241
  248. package/dist/mobile/memory-contract-r1-prefetch.mjs +10 -10
  249. package/dist/mobile/memory-contract-r1.js +1 -1
  250. package/dist/mobile/memory-contract-r1.mjs +1 -1
  251. package/dist/mobile/memory-contract-r5-empty-result.mjs +11 -11
  252. package/dist/mobile/memory-runtime-v2/checkpoint-policy.js +1 -61
  253. package/dist/mobile/memory-runtime-v2/checkpoint-policy.mjs +2 -2
  254. package/dist/mobile/memory-runtime-v2/context-pack.js +16 -2
  255. package/dist/mobile/memory-runtime-v2/context-pack.mjs +2 -2
  256. package/dist/mobile/memory-runtime-v2/eval-runner.js +231 -145
  257. package/dist/mobile/memory-runtime-v2/eval-runner.mjs +20 -14
  258. package/dist/mobile/memory-runtime-v2/evidence-plan.js +233 -147
  259. package/dist/mobile/memory-runtime-v2/evidence-plan.mjs +22 -16
  260. package/dist/mobile/memory-runtime-v2/index.js +242 -147
  261. package/dist/mobile/memory-runtime-v2/index.mjs +58 -46
  262. package/dist/mobile/memory-runtime-v2/local-source-import.mjs +3 -3
  263. package/dist/mobile/memory-runtime-v2/long-run-guard.js +1 -119
  264. package/dist/mobile/memory-runtime-v2/long-run-guard.mjs +3 -3
  265. package/dist/mobile/memory-runtime-v2/memory-control-plane.js +233 -147
  266. package/dist/mobile/memory-runtime-v2/memory-control-plane.mjs +22 -16
  267. package/dist/mobile/memory-runtime-v2/memory-evidence-graph.mjs +2 -2
  268. package/dist/mobile/memory-runtime-v2/memory-readiness.js +232 -146
  269. package/dist/mobile/memory-runtime-v2/memory-readiness.mjs +22 -16
  270. package/dist/mobile/memory-runtime-v2/orchestrator.js +17 -3
  271. package/dist/mobile/memory-runtime-v2/orchestrator.mjs +7 -7
  272. package/dist/mobile/memory-runtime-v2/project-tool-event.mjs +2 -2
  273. package/dist/mobile/memory-runtime-v2/public-api.js +233 -147
  274. package/dist/mobile/memory-runtime-v2/public-api.mjs +23 -17
  275. package/dist/mobile/memory-runtime-v2/retrieval.mjs +2 -2
  276. package/dist/mobile/memory-runtime-v2/run-ledger.js +29 -48
  277. package/dist/mobile/memory-runtime-v2/run-ledger.mjs +7 -1
  278. package/dist/mobile/minimax-m3.js +2 -20
  279. package/dist/mobile/minimax-m3.mjs +3 -9
  280. package/dist/mobile/model-context-window-budget.js +19 -4
  281. package/dist/mobile/model-context-window-budget.mjs +7 -3
  282. package/dist/mobile/model-turn-runner.js +61 -2
  283. package/dist/mobile/model-turn-runner.mjs +12 -6
  284. package/dist/mobile/native-anthropic-messages-stream.js +7 -22
  285. package/dist/mobile/native-anthropic-messages-stream.mjs +12 -12
  286. package/dist/mobile/native-openai-text-stream.js +1 -2
  287. package/dist/mobile/native-openai-text-stream.mjs +3 -3
  288. package/dist/mobile/native-provider-api-key.js +2 -2
  289. package/dist/mobile/native-provider-api-key.mjs +1 -1
  290. package/dist/mobile/native-reply-route.js +25 -4
  291. package/dist/mobile/native-reply-route.mjs +13 -11
  292. package/dist/mobile/native-reply-system-prompt-layers.js +497 -392
  293. package/dist/mobile/native-reply-system-prompt-layers.mjs +155 -155
  294. package/dist/mobile/native-reply-system-prompt.js +1 -0
  295. package/dist/mobile/native-reply-system-prompt.mjs +1 -1
  296. package/dist/mobile/native-reply-transcript.js +125 -0
  297. package/dist/mobile/native-reply-transcript.mjs +7 -2
  298. package/dist/mobile/native-request-diagnostics.js +4 -2
  299. package/dist/mobile/native-request-diagnostics.mjs +3 -1
  300. package/dist/mobile/native-stream-block-emit.mjs +3 -3
  301. package/dist/mobile/openai-completions-turn-runner.js +874 -608
  302. package/dist/mobile/openai-completions-turn-runner.mjs +172 -170
  303. package/dist/mobile/reply-dispatch-warmup.mjs +5 -5
  304. package/dist/mobile/runtime.js +8272 -7353
  305. package/dist/mobile/runtime.mjs +253 -238
  306. package/dist/mobile/session-dispatch/mobile-session-agent-event-bridge.mjs +1 -1
  307. package/dist/mobile/store.mjs +3 -3
  308. package/dist/mobile/stream-inbound/mobile-text-stream-pipeline.js +321 -9
  309. package/dist/mobile/stream-inbound/mobile-text-stream-pipeline.mjs +11 -4
  310. package/dist/mobile/system-prompt-snapshot.mjs +4 -4
  311. package/dist/mobile/tool-result-final-summary.js +145 -0
  312. package/dist/mobile/tool-result-final-summary.mjs +11 -0
  313. package/dist/mobile/tool-use-input-normalize.js +492 -389
  314. package/dist/mobile/tool-use-input-normalize.mjs +158 -158
  315. package/dist/mobile/tools/mobile-compact-tool-bridge.js +492 -389
  316. package/dist/mobile/tools/mobile-compact-tool-bridge.mjs +157 -157
  317. package/dist/mobile/types.js +1 -0
  318. package/dist/mobile/types.mjs +1 -1
  319. package/dist/mobile/websocket.js +327 -0
  320. package/dist/mobile/websocket.mjs +7 -2
  321. package/dist/mobile/workspace-startup-pointer.js +1 -1
  322. package/dist/mobile/workspace-startup-pointer.mjs +1 -1
  323. package/dist/org/dept-context.mjs +4 -4
  324. package/dist/org/index.mjs +8 -8
  325. package/dist/owned-tools/agent-tool-config.mjs +2 -2
  326. package/dist/owned-tools/agents-list.mjs +6 -6
  327. package/dist/owned-tools/ceo-confirm-requirements.mjs +15 -15
  328. package/dist/owned-tools/ceo-decision.js +72 -18
  329. package/dist/owned-tools/ceo-decision.mjs +22 -22
  330. package/dist/owned-tools/ceo-ops-brief.mjs +15 -15
  331. package/dist/owned-tools/ceo-redirect.js +3 -0
  332. package/dist/owned-tools/ceo-redirect.mjs +60 -59
  333. package/dist/owned-tools/commit-stack-lesson.mjs +16 -16
  334. package/dist/owned-tools/compact/execute.js +492 -389
  335. package/dist/owned-tools/compact/execute.mjs +155 -155
  336. package/dist/owned-tools/compact/gateway-tool-factory.js +492 -389
  337. package/dist/owned-tools/compact/gateway-tool-factory.mjs +156 -156
  338. package/dist/owned-tools/compact/registry.js +492 -389
  339. package/dist/owned-tools/compact/registry.mjs +154 -154
  340. package/dist/owned-tools/context-compact.js +8 -22
  341. package/dist/owned-tools/context-compact.mjs +69 -63
  342. package/dist/owned-tools/edit.mjs +2 -2
  343. package/dist/owned-tools/exec-primitives.mjs +2 -2
  344. package/dist/owned-tools/exec.js +112 -9
  345. package/dist/owned-tools/exec.mjs +12 -8
  346. package/dist/owned-tools/groups-history.mjs +10 -10
  347. package/dist/owned-tools/handoff.mjs +21 -21
  348. package/dist/owned-tools/internal-tool-names.js +40 -0
  349. package/dist/owned-tools/internal-tool-names.mjs +9 -0
  350. package/dist/owned-tools/media-asset-library.mjs +2 -2
  351. package/dist/owned-tools/memory-control.mjs +24 -18
  352. package/dist/owned-tools/memory-get.js +7 -3
  353. package/dist/owned-tools/memory-get.mjs +1 -1
  354. package/dist/owned-tools/memory-runtime-eval.js +232 -146
  355. package/dist/owned-tools/memory-runtime-eval.mjs +23 -17
  356. package/dist/owned-tools/message.mjs +7 -7
  357. package/dist/owned-tools/models-list.mjs +2 -2
  358. package/dist/owned-tools/owned-reply.mjs +6 -6
  359. package/dist/owned-tools/owned-tool-payload-failure.js +3 -6
  360. package/dist/owned-tools/owned-tool-payload-failure.mjs +1 -1
  361. package/dist/owned-tools/process-registry.mjs +2 -2
  362. package/dist/owned-tools/process.mjs +3 -3
  363. package/dist/owned-tools/providers/minimax-video-generate.mjs +2 -2
  364. package/dist/owned-tools/providers/minimax-voice.mjs +2 -2
  365. package/dist/owned-tools/read.mjs +2 -2
  366. package/dist/owned-tools/register-owned-providers.mjs +12 -12
  367. package/dist/owned-tools/registry.js +497 -389
  368. package/dist/owned-tools/registry.mjs +158 -153
  369. package/dist/owned-tools/router.js +554 -451
  370. package/dist/owned-tools/router.mjs +154 -154
  371. package/dist/owned-tools/runtime-bridge.js +554 -451
  372. package/dist/owned-tools/runtime-bridge.mjs +156 -156
  373. package/dist/owned-tools/runtime-data.mjs +5 -5
  374. package/dist/owned-tools/session-status.mjs +7 -7
  375. package/dist/owned-tools/sessions-history-resolver.mjs +9 -9
  376. package/dist/owned-tools/sessions-history.mjs +8 -8
  377. package/dist/owned-tools/sessions-list.mjs +6 -6
  378. package/dist/owned-tools/sessions-send.mjs +7 -7
  379. package/dist/owned-tools/skills-create.mjs +6 -6
  380. package/dist/owned-tools/subagents.mjs +7 -7
  381. package/dist/owned-tools/tool-contract-prompt.js +497 -392
  382. package/dist/owned-tools/tool-contract-prompt.mjs +154 -154
  383. package/dist/owned-tools/tool-result-envelope.js +526 -405
  384. package/dist/owned-tools/tool-result-envelope.mjs +159 -159
  385. package/dist/owned-tools/tool-usage-guide.js +492 -389
  386. package/dist/owned-tools/tool-usage-guide.mjs +153 -153
  387. package/dist/owned-tools/tool-validation.mjs +2 -2
  388. package/dist/owned-tools/tts.mjs +6 -6
  389. package/dist/owned-tools/web-smoke.mjs +9 -9
  390. package/dist/owned-tools/write.mjs +2 -2
  391. package/dist/project/file-tool-scope-default.mjs +6 -6
  392. package/dist/project/file-tool-scope.js +1 -1
  393. package/dist/project/file-tool-scope.mjs +1 -1
  394. package/dist/project-pipeline/handlers.js +3 -0
  395. package/dist/project-pipeline/handlers.mjs +60 -59
  396. package/dist/project-pipeline/index.js +3 -0
  397. package/dist/project-pipeline/index.mjs +62 -61
  398. package/dist/project-pipeline/pipeline-routing.mjs +2 -2
  399. package/dist/project-pipeline/post-close-skill-evolution.mjs +5 -5
  400. package/dist/project-pipeline/project-store.mjs +5 -5
  401. package/gateway-core/runtime/reply/chinese-monologue-deliver-partition.cjs +27 -6
  402. package/package.json +2 -2
  403. package/dist/chunk-4IWTTXQE.mjs +0 -113
  404. package/dist/chunk-ETD5LGJY.mjs +0 -25
  405. package/gateway-core/README.md +0 -6
  406. package/dist/{chunk-MGWYJD5Q.mjs → chunk-2YNBEBKQ.mjs} +14 -14
  407. package/dist/{chunk-QM7MTC5Q.mjs → chunk-522D52FC.mjs} +3 -3
  408. package/dist/{chunk-QADC4VKT.mjs → chunk-5MXGINNQ.mjs} +4 -4
  409. package/dist/{chunk-BRJJML7A.mjs → chunk-5NFOBSYF.mjs} +3 -3
  410. package/dist/{chunk-NRJWLPTI.mjs → chunk-6AY6OPO5.mjs} +3 -3
  411. package/dist/{chunk-JA65ZG3H.mjs → chunk-BYGWNFCJ.mjs} +4 -4
  412. package/dist/{chunk-I7O5UR24.mjs → chunk-JX3URYQG.mjs} +4 -4
  413. package/dist/{chunk-2QCX6RPN.mjs → chunk-KCZIK3TH.mjs} +3 -3
  414. package/dist/{chunk-WPLDZLAL.mjs → chunk-L7PMYQN5.mjs} +3 -3
  415. package/dist/{chunk-H2UCPL5O.mjs → chunk-LY7M7Z7M.mjs} +3 -3
  416. package/dist/{chunk-UNZ3D3B3.mjs → chunk-MK32KUVI.mjs} +6 -6
  417. package/dist/{chunk-5LUTMHVL.mjs → chunk-NXKHSX4M.mjs} +3 -3
  418. package/dist/{chunk-QVEQRCOD.mjs → chunk-PIDPHIN6.mjs} +4 -4
  419. package/dist/{chunk-UR6LPERL.mjs → chunk-Q7NYATKS.mjs} +3 -3
  420. package/dist/{chunk-TQOUQIVS.mjs → chunk-V3XUPTZQ.mjs} +3 -3
  421. package/dist/{chunk-HWGRW6YP.mjs → chunk-VS2URZFN.mjs} +3 -3
  422. package/dist/{chunk-CVXJ45WI.mjs → chunk-WTOP2LEF.mjs} +5 -5
  423. package/dist/{chunk-FY2QAWA6.mjs → chunk-YI7E3RUY.mjs} +5 -5
@@ -1,50 +1,113 @@
1
- import {
2
- MobileTextStreamPipeline
3
- } from "./chunk-XNQJRIGR.mjs";
4
- import {
5
- buildRuntimeTextDeliverPayload
6
- } from "./chunk-WMKSZMB7.mjs";
7
1
  import {
8
2
  MobileSessionAgentEventBridge
9
3
  } from "./chunk-JDHB2EC6.mjs";
4
+ import {
5
+ dispatchNontextReplyFromExtracted
6
+ } from "./chunk-TKW3XDFP.mjs";
7
+ import {
8
+ MobileTextStreamPipeline
9
+ } from "./chunk-WHP2GNEC.mjs";
10
10
  import {
11
11
  MobileStreamRoundToolFlight
12
12
  } from "./chunk-6B2OT7ND.mjs";
13
13
  import {
14
- dispatchNontextReplyFromExtracted
15
- } from "./chunk-TKW3XDFP.mjs";
14
+ buildRuntimeTextDeliverPayload
15
+ } from "./chunk-WMKSZMB7.mjs";
16
16
  import {
17
17
  buildDirectChatGroupContextBlock
18
- } from "./chunk-LGNLS7ZN.mjs";
18
+ } from "./chunk-SPUVJNKO.mjs";
19
+ import {
20
+ callPostAgentIntentLlm
21
+ } from "./chunk-22VRM3T3.mjs";
22
+ import {
23
+ callConductorPlanLlm
24
+ } from "./chunk-3JHD7MGZ.mjs";
25
+ import {
26
+ assertNoInlineDataBlobUplink,
27
+ prepareInboundDispatchRequest,
28
+ prepareUserMessagePersistence
29
+ } from "./chunk-HCYIE2PR.mjs";
19
30
  import {
20
31
  inferMobileUpstreamDispatchFailureMeta
21
32
  } from "./chunk-7L46MOG4.mjs";
22
33
  import {
23
- callPostAgentIntentLlm
24
- } from "./chunk-YPKHMAO4.mjs";
34
+ persistMobileDispatchInterruptedTurnSnapshot
35
+ } from "./chunk-H7ILBOZU.mjs";
25
36
  import {
26
- callConductorPlanLlm
27
- } from "./chunk-PETWGCGB.mjs";
37
+ runNativeDispatchTurn
38
+ } from "./chunk-35SKU3FL.mjs";
28
39
  import {
29
- buildRunningSummaryContextBlock
30
- } from "./chunk-42NDWKUN.mjs";
40
+ resolveNativeDispatchReplyRoute
41
+ } from "./chunk-UOCUHKR5.mjs";
31
42
  import {
32
- detectCompactDoneFromAssistantText,
33
- evaluateAndMaybeRunContextCompact
34
- } from "./chunk-F35EHL5U.mjs";
43
+ buildNativeDispatchTranscriptForTurn
44
+ } from "./chunk-HQHICFPO.mjs";
35
45
  import {
36
46
  createFinalTraceLogger,
37
47
  previewFinalTraceText
38
48
  } from "./chunk-5PZJDP37.mjs";
49
+ import {
50
+ COMPACT_NATIVE_RESUME_TOOL_CONTRACT_BLOCK,
51
+ buildCompactGatewayTurnContext,
52
+ buildCompactNativeMemoryEvidenceBlocks,
53
+ buildCompactNativeResumeTaskId,
54
+ buildCompactTurnExtraSystemPrompt,
55
+ createCompactGatewayTurnReplyOptions,
56
+ isCompactArchiveTurn,
57
+ resolveCompactTurnStreamPolicy,
58
+ shouldSurfaceCompactTurnToClient
59
+ } from "./chunk-SJWQGIQU.mjs";
60
+ import {
61
+ buildMobileDispatchInboundContext
62
+ } from "./chunk-H4NINXMV.mjs";
63
+ import {
64
+ assertMobileChannelEnabledForDispatch,
65
+ resolveDirectDispatchRoute,
66
+ resolveGroupDispatchRoute
67
+ } from "./chunk-PW6NSDMI.mjs";
68
+ import {
69
+ MobileDispatchError
70
+ } from "./chunk-VHQ5WHXF.mjs";
71
+ import {
72
+ resolveMobileDispatchStreamingState
73
+ } from "./chunk-LQHI5VK2.mjs";
74
+ import {
75
+ NO_USER_VISIBLE_REPLY_CODE,
76
+ NO_USER_VISIBLE_REPLY_FAILURE_KIND,
77
+ NO_USER_VISIBLE_REPLY_MESSAGE,
78
+ buildNoUserVisibleReplyDetails,
79
+ buildNoUserVisibleReplyErrorPayload,
80
+ createAttachmentBatchAckPlaceholder,
81
+ createNoUserVisibleReplyPlaceholder,
82
+ createOutboundBridgeDeliveredPlaceholder,
83
+ resolveMobileDispatchFinalizeState
84
+ } from "./chunk-F3Y7WDC6.mjs";
85
+ import {
86
+ buildSessionTranscriptMeterFromProjection
87
+ } from "./chunk-LOMDPHVQ.mjs";
88
+ import {
89
+ buildRunningSummaryContextBlock
90
+ } from "./chunk-42NDWKUN.mjs";
91
+ import {
92
+ detectCompactDoneFromAssistantText,
93
+ evaluateAndMaybeRunContextCompact
94
+ } from "./chunk-RM6GZ2SF.mjs";
39
95
  import {
40
96
  registerXreBucketGatewayBridge
41
- } from "./chunk-PJKLQF3K.mjs";
97
+ } from "./chunk-INFZEMQK.mjs";
42
98
  import {
43
99
  resolveDefaultFileToolScopeForTurn
44
- } from "./chunk-JG3K4N5B.mjs";
100
+ } from "./chunk-M3E2R3PT.mjs";
45
101
  import {
46
102
  applyStateRootHygiene
47
103
  } from "./chunk-BAS4J57E.mjs";
104
+ import {
105
+ resolveWorkspaceStartupBlock,
106
+ shouldAttachWorkspaceStartup
107
+ } from "./chunk-2LN3ODBA.mjs";
108
+ import {
109
+ detectToolChoicePolicyForTurn
110
+ } from "./chunk-O6YH4BTO.mjs";
48
111
  import {
49
112
  buildToolResultMediaUrlList,
50
113
  mapRawSourcePerDeliveredPart,
@@ -52,84 +115,68 @@ import {
52
115
  } from "./chunk-BIEZNK2B.mjs";
53
116
  import {
54
117
  getMobileWebSocketServer
55
- } from "./chunk-ZMQ3UOGP.mjs";
118
+ } from "./chunk-MMWLRPKT.mjs";
56
119
  import {
57
- resolveWorkspaceStartupBlock,
58
- shouldAttachWorkspaceStartup
59
- } from "./chunk-WQSQXDUL.mjs";
120
+ sliceSessionMessagesV2Page
121
+ } from "./chunk-M2WHIUNH.mjs";
122
+ import {
123
+ settleMobileReasoningDeliverAfterInboundIdle
124
+ } from "./chunk-GSWQMKOE.mjs";
60
125
  import {
61
126
  buildMobileSystemPromptSnapshot
62
- } from "./chunk-AP4WVS6L.mjs";
127
+ } from "./chunk-MCJPAZBQ.mjs";
63
128
  import {
64
129
  applyToolCallEventToMessage,
65
130
  healStaleToolCallsAfterStreamFinalize
66
131
  } from "./chunk-ZNRN6DTK.mjs";
67
132
  import {
68
- detectToolChoicePolicyForTurn
69
- } from "./chunk-O6YH4BTO.mjs";
133
+ detectFakeProviderImageUrl,
134
+ rehostRemoteImageUrlIfNeeded
135
+ } from "./chunk-E6MVUDMP.mjs";
136
+ import {
137
+ createOwnedReplyTextCapture
138
+ } from "./chunk-EOWUJO75.mjs";
70
139
  import {
71
140
  ensureReplyDispatchWarmupComplete,
72
141
  startReplyDispatchWarmup
73
- } from "./chunk-COYZO24J.mjs";
142
+ } from "./chunk-MCD5TOFD.mjs";
74
143
  import {
75
144
  resolveWebchatSendSessionKeyFromSessions
76
145
  } from "./chunk-BD3VJKX4.mjs";
77
146
  import {
78
- sliceSessionMessagesV2Page
79
- } from "./chunk-M2WHIUNH.mjs";
80
- import {
81
- settleMobileReasoningDeliverAfterInboundIdle
82
- } from "./chunk-GSWQMKOE.mjs";
147
+ composeNativeReplySystemPrompt
148
+ } from "./chunk-OHCBAEML.mjs";
83
149
  import {
84
150
  appendMobileOfflineBatchGatewayTranscriptMaybe,
85
151
  offlineSyncPartToGatewayPlainText
86
152
  } from "./chunk-CYVEZZL5.mjs";
87
153
  import {
88
154
  runNativeOpenAiCompletionsTurnToDispatcher
89
- } from "./chunk-TQBVFKCT.mjs";
90
- import {
91
- detectFakeProviderImageUrl,
92
- rehostRemoteImageUrlIfNeeded
93
- } from "./chunk-E6MVUDMP.mjs";
155
+ } from "./chunk-H6W42R46.mjs";
94
156
  import {
95
- createOwnedReplyTextCapture
96
- } from "./chunk-EOWUJO75.mjs";
157
+ isMobileSuppressFinalBlockAssistTextDeliverEnabled,
158
+ shouldSuppressAssistTextFromNativeDeliver
159
+ } from "./chunk-ZJEZUSIG.mjs";
97
160
  import {
98
161
  promoteExactOutboundPathTextToNativeReply
99
162
  } from "./chunk-IWVFK6JY.mjs";
100
163
  import {
101
164
  nativeAnthropicTurnLoopEnabled,
165
+ nativeOwnedTurnOverridesHostToolLoop,
102
166
  nativeReplyTransportForced,
103
- resolveNativeReplyRoute,
104
- resolveNativeReplyRouteAsync,
105
- shouldResolveNativeReplyRouteAsync
106
- } from "./chunk-GZJMFCRG.mjs";
167
+ resolveNativeChatContextWindow,
168
+ resolveNativeReplyRouteAsync
169
+ } from "./chunk-HNYI45WM.mjs";
107
170
  import {
108
- buildNativeAnthropicTurnToolBlocks,
109
- buildNativeOpenAiTurnToolBlocks,
110
171
  buildNativeReplyRuntimeContextBlocks,
111
172
  buildOwnedNativeReplyChildTurnBlocks
112
- } from "./chunk-4JXTPCOE.mjs";
113
- import {
114
- composeNativeReplySystemPrompt
115
- } from "./chunk-3STOFADV.mjs";
116
- import {
117
- formatNativeAnthropicTurnUserMessage
118
- } from "./chunk-EE3NRJLQ.mjs";
119
- import {
120
- isMobileSuppressFinalBlockAssistTextDeliverEnabled,
121
- shouldSuppressAssistTextFromNativeDeliver
122
- } from "./chunk-ZJEZUSIG.mjs";
123
- import {
124
- MOBILE_PLUGIN_HTTP_ROUTE_DEFS
125
- } from "./chunk-VMM5GYS2.mjs";
173
+ } from "./chunk-ANGNUW6F.mjs";
126
174
  import {
127
175
  buildMobileReasoningReplyOptions
128
176
  } from "./chunk-46TY43IV.mjs";
129
177
  import {
130
- buildMemoryContractR1ExtraSystemPrompt,
131
- shouldAttachMemoryContractR1Prompt
132
- } from "./chunk-6MOIFLPP.mjs";
178
+ formatNativeAnthropicTurnUserMessage
179
+ } from "./chunk-EE3NRJLQ.mjs";
133
180
  import {
134
181
  buildMemoryContractR3StrongDeliveryHint,
135
182
  buildR3AuditNote,
@@ -138,41 +185,26 @@ import {
138
185
  } from "./chunk-CTOIVB2P.mjs";
139
186
  import {
140
187
  runR5EmptyResultInvestigation
141
- } from "./chunk-27BXVTXH.mjs";
142
- import {
143
- prefetchMemoryR1Block
144
- } from "./chunk-PW3ULDNL.mjs";
188
+ } from "./chunk-JN5EMEXS.mjs";
145
189
  import {
146
- rehydrateChatMessageForClient,
147
- rehydrateChatMessagesForClient
148
- } from "./chunk-USRORWYS.mjs";
149
- import {
150
- resolveOutboundLocalMediaAbsolutePath
151
- } from "./chunk-I77V2ROO.mjs";
152
- import {
153
- tryInlineLocalImageAsDataUrl
154
- } from "./chunk-JOT5IE27.mjs";
155
- import {
156
- deriveFileMetaFromUrlOrPath,
157
- parseAnyDataUrlPayload,
158
- tryInlineLocalMediaAsDataUrl
159
- } from "./chunk-5HQXZCIX.mjs";
190
+ MOBILE_PLUGIN_HTTP_ROUTE_DEFS
191
+ } from "./chunk-VMM5GYS2.mjs";
160
192
  import {
161
193
  buildInterruptedTurnResumeContextBlock,
162
194
  classifyTurnTimeoutKind,
163
- createInterruptedTurnSnapshot,
164
- extractLastToolNameFromError,
165
- extractTurnMetricFromError,
166
195
  findActiveInterruptedTurnSnapshotBefore,
167
- hasInterruptedTurnRecoveryEvidence,
168
196
  isInterruptedTurnResumeRequest
169
197
  } from "./chunk-ULXTQSV6.mjs";
170
198
  import {
171
199
  expandMediaUrlWildcards
172
200
  } from "./chunk-RXRZEWNK.mjs";
173
201
  import {
174
- mergeComposerContextUsageForFinalize
175
- } from "./chunk-37TO75LW.mjs";
202
+ prefetchMemoryR1Block
203
+ } from "./chunk-3QE7GUJC.mjs";
204
+ import {
205
+ buildMemoryContractR1ExtraSystemPrompt,
206
+ shouldAttachMemoryContractR1Prompt
207
+ } from "./chunk-PKJLFQRF.mjs";
176
208
  import {
177
209
  tryExtractContextUsageRatioFromDeliverPayload
178
210
  } from "./chunk-OCARTQYW.mjs";
@@ -187,7 +219,6 @@ import {
187
219
  inboundFilesFromAttachments,
188
220
  inboundMediaFromAttachments,
189
221
  materializeFileContextInboundAttachments,
190
- parseFileContextPayload,
191
222
  persistedInboundAttachmentsFromPaths,
192
223
  resolveFileContextInboundAttachments,
193
224
  resolvePrimaryFileContextMeta,
@@ -198,22 +229,34 @@ import {
198
229
  createChatAbortOpsFromContext,
199
230
  tryParseGatewayChatAbortContext
200
231
  } from "./chunk-CI47MU64.mjs";
232
+ import {
233
+ rehydrateChatMessageForClient,
234
+ rehydrateChatMessagesForClient
235
+ } from "./chunk-USRORWYS.mjs";
236
+ import {
237
+ resolveOutboundLocalMediaAbsolutePath
238
+ } from "./chunk-I77V2ROO.mjs";
239
+ import {
240
+ tryInlineLocalImageAsDataUrl
241
+ } from "./chunk-JOT5IE27.mjs";
242
+ import {
243
+ deriveFileMetaFromUrlOrPath,
244
+ parseAnyDataUrlPayload,
245
+ tryInlineLocalMediaAsDataUrl
246
+ } from "./chunk-5HQXZCIX.mjs";
201
247
  import {
202
248
  createEmptyMobileBodyHuntRoundTrace,
203
249
  formatBodyHuntPreview
204
250
  } from "./chunk-3T3BHHE7.mjs";
205
251
  import {
206
- MOBILE_CHANNEL_ID,
207
- isMobileChannelEnabled,
208
- resolveMobileInboundIdentity,
209
- resolveMobileRouteAgent
210
- } from "./chunk-B4YKXZ5W.mjs";
252
+ resolveMobileInboundIdentity
253
+ } from "./chunk-OQMIECO2.mjs";
211
254
  import {
212
- runNativeAnthropicMessagesTurnToDispatcher
213
- } from "./chunk-5SE4JOKE.mjs";
255
+ mergeComposerContextUsageForFinalize
256
+ } from "./chunk-37TO75LW.mjs";
214
257
  import {
215
258
  createMobileApiRequestHandler
216
- } from "./chunk-JBKRS62W.mjs";
259
+ } from "./chunk-T3EJW65E.mjs";
217
260
  import {
218
261
  consumeInboundMobileUploadRef,
219
262
  looksLikeXkzoomMediaRefV1
@@ -223,15 +266,14 @@ import {
223
266
  } from "./chunk-FU5NWQEP.mjs";
224
267
  import {
225
268
  buildAgentCapabilities
226
- } from "./chunk-LESS4N25.mjs";
269
+ } from "./chunk-LV3CI5A4.mjs";
270
+ import {
271
+ runNativeAnthropicMessagesTurnToDispatcher
272
+ } from "./chunk-GHWAAAG6.mjs";
227
273
  import {
228
- OWNED_TURN_TOOL_NAMES,
229
274
  buildOwnedToolsCatalog,
230
275
  buildOwnedTurnToolSchemas
231
- } from "./chunk-3ZH273T7.mjs";
232
- import {
233
- buildSessionTranscriptMeterFromMessages
234
- } from "./chunk-4IWTTXQE.mjs";
276
+ } from "./chunk-FEEEY457.mjs";
235
277
  import {
236
278
  drainMemoryMaintenanceQueue,
237
279
  scheduleMemoryMaintenance
@@ -243,12 +285,15 @@ import {
243
285
  joinRuntimeExtraSystemPrompt,
244
286
  resolveProjectContextPromptInfo
245
287
  } from "./chunk-4ELPLFOH.mjs";
246
- import {
247
- buildNativeTranscriptBudgetForContextWindow
248
- } from "./chunk-P262PAGZ.mjs";
249
288
  import {
250
289
  runNativeAnthropicMessagesStreamToDispatcher
251
- } from "./chunk-UXEZFEB3.mjs";
290
+ } from "./chunk-TSS3NVRA.mjs";
291
+ import {
292
+ enforceR2Write
293
+ } from "./chunk-GU4CQC5I.mjs";
294
+ import {
295
+ enforceR6IndexAfterWrite
296
+ } from "./chunk-GOSSEVA6.mjs";
252
297
  import {
253
298
  MemoryContractR1Tracker,
254
299
  MemoryContractR2Tracker,
@@ -258,85 +303,75 @@ import {
258
303
  isMemoryContractRuntimeEnforceEnabled,
259
304
  logMemoryContractR6Deferred
260
305
  } from "./chunk-XQFQO4EA.mjs";
261
- import {
262
- enforceR2Write
263
- } from "./chunk-GU4CQC5I.mjs";
264
- import {
265
- enforceR6IndexAfterWrite
266
- } from "./chunk-GOSSEVA6.mjs";
267
306
  import {
268
307
  buildRecentDiaryContextBlock,
269
308
  buildRecentDiaryInjectSummary
270
309
  } from "./chunk-BW737ZQN.mjs";
271
- import {
272
- runNativeOpenAiTextStreamToDispatcher
273
- } from "./chunk-MKYCBV3H.mjs";
274
- import {
275
- diagnoseNativeReplyRouteMiss,
276
- formatNativeReplyRouteMissMessage
277
- } from "./chunk-NEDXMES6.mjs";
278
- import {
279
- applyModelOverrideToGatewayConfig,
280
- gatewayAgentWantsFullToolLoop,
281
- init_native_gateway_config,
282
- normalizeModelOverrideKey,
283
- resolveGatewayAgentToolsProfile
284
- } from "./chunk-LR5GC3NZ.mjs";
285
310
  import {
286
311
  dispatchGroupSessionMessage,
287
312
  forceStopGroupFloorState,
288
313
  initGroupCollaborationEngine
289
- } from "./chunk-JFFBD5TV.mjs";
314
+ } from "./chunk-HOII5XBJ.mjs";
290
315
  import {
291
316
  buildGroupPeerTranscriptProjection
292
- } from "./chunk-BSG6WLML.mjs";
317
+ } from "./chunk-NI4N35JN.mjs";
293
318
  import {
294
319
  OWNED_REPLY_ORCHESTRATION_TOOL_DENY
295
- } from "./chunk-BJ6YI2DJ.mjs";
320
+ } from "./chunk-AEE3DM6S.mjs";
296
321
  import {
297
322
  createRemarkResolver,
298
323
  getAgentRemark
299
- } from "./chunk-4POYX4AW.mjs";
324
+ } from "./chunk-WVTJXJY4.mjs";
300
325
  import {
301
326
  buildContextPackForTurn
302
- } from "./chunk-MPGMU75K.mjs";
303
- import {
304
- renderContextPackStablePrefixForProviderCache
305
- } from "./chunk-XL3MUGFG.mjs";
327
+ } from "./chunk-7C7HREZO.mjs";
306
328
  import {
307
329
  maybeCheckpointRunLedger
308
- } from "./chunk-EL6TOIFZ.mjs";
330
+ } from "./chunk-KHQPC6I7.mjs";
331
+ import {
332
+ renderContextPackStablePrefixForProviderCache
333
+ } from "./chunk-2B3A3C2V.mjs";
309
334
  import {
310
335
  updateRunLedger
311
- } from "./chunk-4WWT6OC2.mjs";
336
+ } from "./chunk-JTKSYLZE.mjs";
312
337
  import {
313
338
  ingestMemoryEvent
314
339
  } from "./chunk-EZ2UKNOZ.mjs";
315
340
  import {
316
341
  registerOwnedNativeReplyDispatcher
317
- } from "./chunk-3CPVI6Y2.mjs";
342
+ } from "./chunk-TRSW7QJW.mjs";
318
343
  import {
319
- getMobileChatStore
320
- } from "./chunk-CVXJ45WI.mjs";
344
+ assessDeliveryVerification
345
+ } from "./chunk-WI7PS7YW.mjs";
321
346
  import {
322
- SessionIdAgentConflictError
323
- } from "./chunk-KPJOJH6H.mjs";
347
+ getMobileChatStore
348
+ } from "./chunk-WTOP2LEF.mjs";
324
349
  import {
325
350
  registerMobileOutboundBridge
326
351
  } from "./chunk-LCR7EVVU.mjs";
327
352
  import {
328
353
  buildNativeReplyOpenAiMessages,
329
- buildNativeReplyTranscriptMessages,
330
- findFirstVisibleUserMessage
331
- } from "./chunk-6ZVXCJTG.mjs";
354
+ findFirstVisibleUserMessage,
355
+ projectMessagesForAPI
356
+ } from "./chunk-TBLUKDLO.mjs";
332
357
  import {
333
358
  extractLegacyDeliveryConversationIdFromSessionKey
334
359
  } from "./chunk-GEXTQELG.mjs";
335
360
  import {
336
- GATEWAY_WEBCHAT_CHANNEL_ID,
337
- MOBILE_SOURCE,
338
361
  XKZOOM_CHAT_CHANNEL_ID
339
- } from "./chunk-PS6X3CND.mjs";
362
+ } from "./chunk-LKSRZTSL.mjs";
363
+ import {
364
+ runNativeOpenAiTextStreamToDispatcher
365
+ } from "./chunk-J4FQVXEA.mjs";
366
+ import {
367
+ diagnoseNativeReplyRouteMiss,
368
+ formatNativeReplyRouteMissMessage
369
+ } from "./chunk-YAGU7I25.mjs";
370
+ import {
371
+ gatewayAgentWantsFullToolLoop,
372
+ init_native_gateway_config,
373
+ resolveGatewayAgentToolsProfile
374
+ } from "./chunk-LR5GC3NZ.mjs";
340
375
  import {
341
376
  init_state_dir,
342
377
  resolveXkzoomStateDirForProcess
@@ -347,7 +382,6 @@ import { createHash, randomUUID } from "crypto";
347
382
  import fs from "fs";
348
383
  import { createRequire } from "module";
349
384
  import path from "path";
350
- import { pathToFileURL } from "url";
351
385
  init_state_dir();
352
386
  init_native_gateway_config();
353
387
  var mobileGatewayPluginSdkAdapter = null;
@@ -411,18 +445,6 @@ var FILE_STREAM_CHUNK_CHARS = 64 * 1024;
411
445
  function createMessageId() {
412
446
  return `msg-${Date.now()}-${randomUUID().slice(0, 8)}`;
413
447
  }
414
- var INLINE_UPLINK_DATA_BLOB_RE = /^data:[^;,]+;base64,/i;
415
- function isInlineUplinkDataBlobContent(content) {
416
- return INLINE_UPLINK_DATA_BLOB_RE.test(typeof content === "string" ? content.trim() : "");
417
- }
418
- function throwInlineUplinkDeprecated(details) {
419
- throw new MobileDispatchError(
420
- "\u5185\u5D4C data URL \u4E0A\u884C\u5DF2\u79FB\u9664\uFF0C\u8BF7\u5148\u901A\u8FC7 HTTP \u4E0A\u4F20\u5E76\u4F7F\u7528 xkzoom:media:v1 \u5F15\u7528",
421
- details,
422
- "inline_uplink_deprecated",
423
- false
424
- );
425
- }
426
448
  function buildMobileInboundBodyAndMedia(type, content, caption, fileMimeHint) {
427
449
  const cap = typeof caption === "string" && caption.trim() ? caption.trim() : "";
428
450
  if (type === "image") {
@@ -510,18 +532,6 @@ function resolveMemoryRuntimeV2MaintenanceDrainIntervalMs() {
510
532
  }
511
533
  return 10 * 60 * 1e3;
512
534
  }
513
- var MobileDispatchError = class extends Error {
514
- code;
515
- retryable;
516
- details;
517
- constructor(message, details, code = "dispatch_failed", retryable = true) {
518
- super(message);
519
- this.name = "MobileDispatchError";
520
- this.code = code;
521
- this.retryable = retryable;
522
- this.details = details;
523
- }
524
- };
525
535
  function normalizeReplayInboundMediaTypes(paths, types, messageType) {
526
536
  if (types && types.length === paths.length) {
527
537
  return types.map(
@@ -1607,11 +1617,13 @@ var MobileGatewayRuntime = class {
1607
1617
  }
1608
1618
  getSessionTranscriptMeter(sessionId) {
1609
1619
  const sid = sessionId.trim();
1610
- if (!sid || !this.store.getSession(sid)) {
1620
+ const session = sid ? this.store.getSession(sid) : null;
1621
+ if (!session) {
1611
1622
  return null;
1612
1623
  }
1613
1624
  const messages = this.store.getSessionMessages(sid);
1614
- return buildSessionTranscriptMeterFromMessages(messages);
1625
+ const contextWindow = resolveNativeChatContextWindow(this.loadConfig?.(), session.agentId);
1626
+ return buildSessionTranscriptMeterFromProjection(projectMessagesForAPI(messages), contextWindow);
1615
1627
  }
1616
1628
  /**
1617
1629
  * v2 分页:先切片再 rehydrate,避免大会话全量读盘内联图片导致 Relay 10s+ 超时。
@@ -1758,6 +1770,7 @@ var MobileGatewayRuntime = class {
1758
1770
  const isGroupPeerTurn = session.sessionType === "group" && Boolean(peerAgentId);
1759
1771
  const persistToSession = params.persistToSession ?? !isGroupPeerTurn;
1760
1772
  const runtimeAgentId = isGroupPeerTurn && peerAgentId ? peerAgentId : session.agentId;
1773
+ const ownedNativeRunLedgerTaskId = isGroupPeerTurn ? `session:${session.id}:group-peer:${runtimeAgentId}` : `session:${session.id}`;
1761
1774
  if (persistToSession) {
1762
1775
  this.store.addMessage(session.id, {
1763
1776
  id: mkId("u"),
@@ -1781,9 +1794,9 @@ var MobileGatewayRuntime = class {
1781
1794
  resolveRemark: createRemarkResolver()
1782
1795
  });
1783
1796
  } else {
1784
- transcript = buildNativeReplyTranscriptMessages(sessionMessagesForReply, {
1797
+ transcript = projectMessagesForAPI(sessionMessagesForReply, {
1785
1798
  includeOwnedInjection: true
1786
- });
1799
+ }).messages;
1787
1800
  }
1788
1801
  if (!persistToSession) {
1789
1802
  transcript = [
@@ -1809,14 +1822,53 @@ var MobileGatewayRuntime = class {
1809
1822
  const agentInfo = this.store.getAgentById(runtimeAgentId);
1810
1823
  const snapshot = buildMobileSystemPromptSnapshot(runtimeAgentId, agentInfo);
1811
1824
  const ownedProjectInfo = resolveProjectContextPromptInfo(runtimeAgentId);
1812
- const ownedRuntimeContextBlocks = buildNativeReplyRuntimeContextBlocks({
1813
- providerId: route.chat.providerId,
1814
- model: route.chat.model,
1815
- agentName: snapshot?.agentName,
1816
- agentId: runtimeAgentId,
1817
- project: ownedProjectInfo.project,
1818
- agentWorkspaceRoot: ownedProjectInfo.agentWorkspaceRoot
1819
- });
1825
+ const buildOwnedNativeRuntimeContext = async () => {
1826
+ const fallbackBlocks = () => buildNativeReplyRuntimeContextBlocks({
1827
+ providerId: route.chat.providerId,
1828
+ model: route.chat.model,
1829
+ agentName: snapshot?.agentName,
1830
+ agentId: runtimeAgentId,
1831
+ project: ownedProjectInfo.project,
1832
+ agentWorkspaceRoot: ownedProjectInfo.agentWorkspaceRoot
1833
+ });
1834
+ try {
1835
+ const contextPack = await buildContextPackForTurn({
1836
+ agentId: runtimeAgentId,
1837
+ sessionId: session.id,
1838
+ surface: session.sessionType === "group" ? "group" : "direct",
1839
+ ...session.teamId ? { teamId: session.teamId } : {},
1840
+ providerId: route.chat.providerId,
1841
+ model: route.chat.model,
1842
+ agentName: snapshot?.agentName ?? session.agentName,
1843
+ project: ownedProjectInfo.project,
1844
+ agentWorkspaceRoot: ownedProjectInfo.agentWorkspaceRoot,
1845
+ taskId: ownedNativeRunLedgerTaskId,
1846
+ recentTurnsBlock: isGroupPeerTurn ? "Group peer transcript is supplied as projected API messages; this ContextPack carries durable ledger and evidence state only." : void 0,
1847
+ queryText: userText,
1848
+ toolContractBlock: "Owned-native reply tool schemas are injected separately. Use tool results as evidence before reporting completion, and persist durable progress through RunLedger, artifact refs, and memory records."
1849
+ });
1850
+ return {
1851
+ extraBlocks: buildNativeReplyRuntimeContextBlocks({
1852
+ providerId: route.chat.providerId,
1853
+ model: route.chat.model,
1854
+ agentName: snapshot?.agentName,
1855
+ agentId: runtimeAgentId,
1856
+ project: ownedProjectInfo.project,
1857
+ agentWorkspaceRoot: ownedProjectInfo.agentWorkspaceRoot,
1858
+ contextPack
1859
+ }),
1860
+ ...contextPack.providerAccelerationPlan ? { providerAccelerationPlan: contextPack.providerAccelerationPlan } : {},
1861
+ providerAccelerationCachePrefix: renderContextPackStablePrefixForProviderCache(contextPack)
1862
+ };
1863
+ } catch (err) {
1864
+ this.logWarn(
1865
+ `[XKZOOM][owned-native-reply][context-pack] build failed session=${session.id} agent=${runtimeAgentId} err=${err instanceof Error ? err.message : String(err)}`
1866
+ );
1867
+ return { extraBlocks: fallbackBlocks() };
1868
+ }
1869
+ };
1870
+ const ownedNativeRuntimeContext = await buildOwnedNativeRuntimeContext();
1871
+ const ownedRuntimeContextBlocks = ownedNativeRuntimeContext.extraBlocks;
1820
1872
  const systemPrompt = composeNativeReplySystemPrompt({
1821
1873
  agentSnapshot: snapshot,
1822
1874
  providerId: route.chat.providerId,
@@ -1950,6 +2002,36 @@ var MobileGatewayRuntime = class {
1950
2002
  assistantRunId: streamCtx?.streamId ?? toolCallCaptureMessage.id
1951
2003
  };
1952
2004
  applyToolCallEventToMessage(toolCallCaptureMessage, event, agentEventPayload.timestamp);
2005
+ if (event.phase === "start" || event.phase === "result") {
2006
+ const capturedTool = toolCallCaptureMessage.toolCalls?.find((tc) => tc.toolCallId === toolCallId);
2007
+ const toolName = capturedTool?.name || (event.phase === "start" ? event.name : void 0) || (typeof ev.name === "string" && ev.name.trim() ? ev.name.trim() : void 0);
2008
+ const argsHash = event.phase === "start" ? hashLedgerArgs(capturedTool?.args) : void 0;
2009
+ void updateRunLedger({
2010
+ taskId: ownedNativeRunLedgerTaskId,
2011
+ agentId: runtimeAgentId,
2012
+ sessionId: session.id,
2013
+ ...session.teamId ? { teamId: session.teamId } : {},
2014
+ event: {
2015
+ kind: "tool",
2016
+ summary: `tool ${event.phase}${toolName ? ` ${toolName}` : ""}`,
2017
+ ...toolName ? { toolName } : {},
2018
+ ...argsHash ? { toolArgsHash: argsHash } : {},
2019
+ ...event.phase === "result" ? { outcome: event.isError ? "failed" : "ok" } : {},
2020
+ newEvidence: event.phase === "result" && !event.isError && typeof event.result === "string" && event.result.trim().length > 0
2021
+ }
2022
+ }).then(async (ledger) => {
2023
+ const checkpoint = await maybeCheckpointRunLedger({ ledger });
2024
+ if (checkpoint.checkpointed) {
2025
+ scheduleMemoryMaintenance({
2026
+ scopes: memoryRuntimeScopesForSession(session),
2027
+ trigger: "checkpoint",
2028
+ reason: `owned-native-checkpoint:${session.id}:${checkpoint.decision.reason ?? "policy"}`
2029
+ });
2030
+ }
2031
+ }).catch((err) => {
2032
+ this.logWarn(`[XKZOOM][owned-native-reply][run-ledger] update failed: ${String(err)}`);
2033
+ });
2034
+ }
1953
2035
  if (!streamCtx) {
1954
2036
  return;
1955
2037
  }
@@ -1979,20 +2061,12 @@ var MobileGatewayRuntime = class {
1979
2061
  if (route.platform === "anthropic-messages") {
1980
2062
  if (nativeAnthropicTurnLoopEnabled()) {
1981
2063
  const ownedChildTools = buildOwnedTurnToolSchemas({ deny: OWNED_REPLY_ORCHESTRATION_TOOL_DENY });
1982
- const projectInfo = resolveProjectContextPromptInfo(runtimeAgentId);
1983
2064
  const turnSystemPrompt = composeNativeReplySystemPrompt({
1984
2065
  agentSnapshot: snapshot,
1985
2066
  providerId: route.chat.providerId,
1986
2067
  model: route.chat.model,
1987
2068
  extraBlocks: [
1988
- ...buildNativeReplyRuntimeContextBlocks({
1989
- providerId: route.chat.providerId,
1990
- model: route.chat.model,
1991
- agentName: snapshot?.agentName,
1992
- agentId: runtimeAgentId,
1993
- project: projectInfo.project,
1994
- agentWorkspaceRoot: projectInfo.agentWorkspaceRoot
1995
- }),
2069
+ ...ownedRuntimeContextBlocks,
1996
2070
  ...buildOwnedNativeReplyChildTurnBlocks()
1997
2071
  ]
1998
2072
  });
@@ -2018,7 +2092,9 @@ var MobileGatewayRuntime = class {
2018
2092
  signal,
2019
2093
  log,
2020
2094
  reasoningMode,
2021
- ...isGroupPeerTurn ? { onToolEvent: emitGroupPeerToolEvent } : {}
2095
+ onToolEvent: emitGroupPeerToolEvent,
2096
+ ...ownedNativeRuntimeContext.providerAccelerationPlan ? { providerAccelerationPlan: ownedNativeRuntimeContext.providerAccelerationPlan } : {},
2097
+ ...ownedNativeRuntimeContext.providerAccelerationCachePrefix ? { providerAccelerationCachePrefix: ownedNativeRuntimeContext.providerAccelerationCachePrefix } : {}
2022
2098
  });
2023
2099
  } catch (turnErr) {
2024
2100
  const message = turnErr instanceof Error ? turnErr.message : String(turnErr);
@@ -2095,7 +2171,8 @@ var MobileGatewayRuntime = class {
2095
2171
  signal,
2096
2172
  log,
2097
2173
  reasoningMode,
2098
- ...isGroupPeerTurn ? { onToolEvent: emitGroupPeerToolEvent } : {}
2174
+ onToolEvent: emitGroupPeerToolEvent,
2175
+ ...ownedNativeRuntimeContext.providerAccelerationPlan ? { providerAccelerationPlan: ownedNativeRuntimeContext.providerAccelerationPlan } : {}
2099
2176
  });
2100
2177
  toolCalls = result.toolCalls;
2101
2178
  iterations = result.iterations;
@@ -2103,6 +2180,8 @@ var MobileGatewayRuntime = class {
2103
2180
  healStaleToolCallsAfterStreamFinalize(toolCallCaptureMessage);
2104
2181
  const replyText = ownedReplyCapture.getReplyText();
2105
2182
  const replyBuckets = ownedReplyCapture.getBuckets();
2183
+ const toolCallStates = toolCallCaptureMessage.toolCalls?.length ? toolCallCaptureMessage.toolCalls.map((tc) => ({ ...tc })) : void 0;
2184
+ const deliveryVerification = assessDeliveryVerification(replyText, toolCallStates);
2106
2185
  if (replyText && persistToSession) {
2107
2186
  this.store.addMessage(session.id, {
2108
2187
  id: mkId("a"),
@@ -2112,7 +2191,10 @@ var MobileGatewayRuntime = class {
2112
2191
  type: "text",
2113
2192
  isSelf: false,
2114
2193
  timestamp: nowIso(),
2115
- status: "sent"
2194
+ status: "sent",
2195
+ ...replyBuckets,
2196
+ ...toolCallStates?.length ? { toolCalls: toolCallStates } : {},
2197
+ ...deliveryVerification ? { deliveryVerification } : {}
2116
2198
  });
2117
2199
  }
2118
2200
  return {
@@ -2121,7 +2203,7 @@ var MobileGatewayRuntime = class {
2121
2203
  agentId: runtimeAgentId,
2122
2204
  replyText,
2123
2205
  toolCalls,
2124
- ...toolCallCaptureMessage.toolCalls?.length ? { toolCallStates: toolCallCaptureMessage.toolCalls.map((tc) => ({ ...tc })) } : {},
2206
+ ...toolCallStates?.length ? { toolCallStates } : {},
2125
2207
  iterations,
2126
2208
  ...replyBuckets,
2127
2209
  streamStarted,
@@ -2507,127 +2589,51 @@ var MobileGatewayRuntime = class {
2507
2589
  return { deviceId, connId: void 0, isAdmin: false };
2508
2590
  }
2509
2591
  async dispatchMessage(request, replyTarget) {
2510
- const parsedFileContext = parseFileContextPayload(request.fileContext);
2511
- const hasFileContextItems = Boolean(parsedFileContext?.items.length);
2512
- let content = request.content.trim();
2513
- if (!content && hasFileContextItems) {
2514
- content = "\uFF08\u7528\u6237\u53D1\u9001\u4E86\u56FE\u7247\uFF09";
2515
- request = { ...request, content };
2516
- }
2517
- const isGroupControlOnly = request.groupControl === "continue" || request.groupControl === "stop_topic";
2518
- if (!content && !hasFileContextItems && !isGroupControlOnly) {
2519
- throw new Error("message content is required");
2520
- }
2521
- if ((request.type === "image" || request.type === "file") && isInlineUplinkDataBlobContent(content)) {
2522
- throwInlineUplinkDeprecated({
2523
- sessionId: request.sessionId,
2524
- clientMessageId: request.clientMessageId
2525
- });
2526
- }
2527
- if (looksLikeXkzoomMediaRefV1(content) && request.type !== "image" && request.type !== "file") {
2528
- throw new MobileDispatchError(
2529
- "mediaRef \u4EC5\u5141\u8BB8 type=image \u6216 type=file",
2530
- {
2531
- sessionId: request.sessionId,
2532
- clientMessageId: request.clientMessageId
2533
- },
2534
- "invalid_send_message_payload",
2535
- false
2536
- );
2537
- }
2592
+ const inboundPrep = prepareInboundDispatchRequest(request);
2593
+ request = inboundPrep.request;
2594
+ const content = inboundPrep.content;
2538
2595
  if (!this.loadConfig) {
2539
2596
  throw new Error("gateway mobile runtime is not initialized");
2540
2597
  }
2541
2598
  const baseCfg = this.loadConfig();
2542
- if (!isMobileChannelEnabled(baseCfg)) {
2543
- throw new MobileDispatchError(
2544
- "\u79FB\u52A8\u7AEF\u6B63\u5F0F\u901A\u9053\u5F53\u524D\u672A\u542F\u7528\uFF0C\u8BF7\u68C0\u67E5 channels.mobile.enabled \u914D\u7F6E",
2545
- {
2546
- sessionId: request.sessionId,
2547
- clientMessageId: request.clientMessageId
2548
- },
2549
- "mobile_channel_disabled",
2550
- false
2551
- );
2552
- }
2553
- const groupSession = this.store.getSession(request.sessionId.trim());
2554
- if (groupSession?.sessionType === "group") {
2555
- const groupIdentity = resolveMobileInboundIdentity(baseCfg, {
2556
- channelId: request.channelId,
2557
- sessionId: request.sessionId,
2558
- accountId: request.accountId,
2559
- deviceId: request.deviceId,
2560
- peerId: request.peerId,
2561
- senderName: request.senderName
2562
- });
2563
- this.store.registerDeliveryConversationId(groupSession.id, groupIdentity.conversationId);
2599
+ assertMobileChannelEnabledForDispatch(baseCfg, request);
2600
+ const groupRoute = resolveGroupDispatchRoute({
2601
+ baseCfg,
2602
+ request,
2603
+ store: this.store
2604
+ });
2605
+ if (groupRoute) {
2564
2606
  void this.writeGroupDurableUserSignal({
2565
- session: groupSession,
2607
+ session: groupRoute.session,
2566
2608
  userText: typeof request.content === "string" ? request.content : ""
2567
2609
  });
2568
2610
  return await this.withAssistantDispatchExclusiveForSession(
2569
- groupSession.id,
2611
+ groupRoute.session.id,
2570
2612
  async () => dispatchGroupSessionMessage(
2571
2613
  this.buildGroupRuntimeHost(),
2572
- groupSession,
2614
+ groupRoute.session,
2573
2615
  request,
2574
2616
  replyTarget
2575
2617
  )
2576
2618
  );
2577
2619
  }
2578
- const identity = resolveMobileInboundIdentity(baseCfg, {
2579
- channelId: request.channelId,
2580
- sessionId: request.sessionId,
2581
- accountId: request.accountId,
2582
- deviceId: request.deviceId,
2583
- peerId: request.peerId,
2584
- senderName: request.senderName
2620
+ const directRoute = resolveDirectDispatchRoute({
2621
+ baseCfg,
2622
+ request,
2623
+ store: this.store
2585
2624
  });
2586
- const requestedAgentId = typeof request.agentId === "string" && request.agentId.trim() ? request.agentId.trim() : null;
2587
- const boundAgentId = resolveMobileRouteAgent(baseCfg, identity);
2588
- const resolvedAgentId = requestedAgentId || boundAgentId;
2589
- if (!resolvedAgentId) {
2590
- throw new MobileDispatchError(
2591
- "\u79FB\u52A8\u7AEF\u901A\u9053\u672A\u7ED1\u5B9A\u9ED8\u8BA4 Agent\uFF0C\u8BF7\u5728\u914D\u7F6E\u4E2D\u8865\u5145 bindings \u6216\u663E\u5F0F\u4F20\u5165 agentId",
2592
- {
2593
- sessionId: request.sessionId,
2594
- clientMessageId: request.clientMessageId,
2595
- channelId: identity.channelId,
2596
- accountId: identity.accountId
2597
- },
2598
- "mobile_agent_binding_required",
2599
- false
2600
- );
2601
- }
2602
- let session;
2603
- try {
2604
- session = this.store.getOrCreateSession(resolvedAgentId, request.sessionId);
2605
- this.store.registerDeliveryConversationId(session.id, identity.conversationId);
2606
- } catch (error) {
2607
- if (error instanceof SessionIdAgentConflictError) {
2608
- throw new MobileDispatchError(
2609
- error.message,
2610
- {
2611
- sessionId: request.sessionId,
2612
- requestedSessionId: error.details.requestedSessionId,
2613
- canonicalSessionId: error.details.canonicalSessionId,
2614
- agentId: error.details.agentId,
2615
- clientMessageId: request.clientMessageId
2616
- },
2617
- error.code,
2618
- error.retryable
2619
- );
2620
- }
2621
- throw error;
2622
- }
2623
- const requestedModelOverride = typeof request.modelOverride === "string" ? request.modelOverride.trim() : "";
2624
- const modelOverride = normalizeModelOverrideKey(requestedModelOverride);
2625
- if (requestedModelOverride && !modelOverride) {
2625
+ const {
2626
+ identity,
2627
+ session,
2628
+ cfg,
2629
+ requestedModelOverride,
2630
+ modelOverride
2631
+ } = directRoute;
2632
+ if (directRoute.ignoredInvalidModelOverride) {
2626
2633
  this.logInfo(
2627
2634
  `[XKZOOM][mobile-model] ignored invalid modelOverride session=${session.id} agent=${session.agentId}`
2628
2635
  );
2629
2636
  }
2630
- const cfg = modelOverride ? applyModelOverrideToGatewayConfig(baseCfg, session.agentId, modelOverride) : baseCfg;
2631
2637
  if (modelOverride) {
2632
2638
  this.logInfo(
2633
2639
  `[XKZOOM][mobile-model] override session=${session.id} agent=${session.agentId} model=${modelOverride}`
@@ -2892,63 +2898,29 @@ ${inbound.bodyText}` : inbound.bodyText;
2892
2898
  );
2893
2899
  userMessage = existingInvisibleReplayAnchor;
2894
2900
  } else {
2895
- const USER_IMAGE_PLACEHOLDER_BODIES = /* @__PURE__ */ new Set([
2896
- "\uFF08\u7528\u6237\u53D1\u9001\u4E86\u56FE\u7247\uFF09",
2897
- "\uFF08\u7528\u6237\u53D1\u9001\u4E86\u4E00\u5F20\u56FE\u7247\uFF09",
2898
- "\uFF08\u7528\u6237\u53D1\u4E86\u4E00\u5F20\u56FE\u7247\uFF09"
2899
- ]);
2900
- const USER_FILE_PLACEHOLDER_BODIES = /* @__PURE__ */ new Set([
2901
- "\uFF08\u7528\u6237\u53D1\u9001\u4E86\u6587\u4EF6\uFF09",
2902
- "\uFF08\u7528\u6237\u53D1\u9001\u4E86\u9644\u4EF6\uFF09"
2903
- ]);
2904
- const hasPersistedImage = persistedInbound && persistedInbound.paths.length > 0 && persistedInbound.mediaTypes[0]?.startsWith("image/");
2905
- const hasPersistedFile = persistedInbound && persistedInbound.paths.length > 0 && !persistedInbound.mediaTypes[0]?.startsWith("image/");
2906
- let storeContent = userVisibleInboundBody;
2907
- let storeType = request.type;
2908
- let storeCaption = (request.type === "image" || request.type === "file") && request.caption?.trim() ? request.caption.trim() : void 0;
2909
- if (hasPersistedImage) {
2910
- storeType = "image";
2911
- const visibleTrim = userVisibleInboundBody.trim();
2912
- if (!visibleTrim || USER_IMAGE_PLACEHOLDER_BODIES.has(visibleTrim)) {
2913
- storeContent = "";
2914
- storeCaption = void 0;
2915
- } else if (/^data:/i.test(visibleTrim)) {
2916
- storeContent = "";
2917
- storeCaption = void 0;
2918
- } else {
2919
- storeCaption = visibleTrim;
2920
- storeContent = "";
2921
- }
2922
- } else if (hasPersistedFile) {
2923
- storeType = "file";
2924
- const visibleTrim = userVisibleInboundBody.trim();
2925
- if (!visibleTrim || USER_FILE_PLACEHOLDER_BODIES.has(visibleTrim)) {
2926
- storeContent = "";
2927
- storeCaption = void 0;
2928
- } else {
2929
- storeCaption = visibleTrim;
2930
- storeContent = "";
2931
- }
2932
- }
2933
- if ((storeType === "image" || storeType === "file") && /^\s*data:[a-zA-Z0-9.+-]+\/[a-zA-Z0-9.+-]+;base64,/i.test(storeContent)) {
2934
- storeContent = "";
2935
- }
2901
+ const persistedUserMessage = prepareUserMessagePersistence({
2902
+ requestType: request.type,
2903
+ requestCaption: request.caption,
2904
+ userVisibleInboundBody,
2905
+ persistedInbound,
2906
+ fileMeta
2907
+ });
2936
2908
  userMessage = this.createChatMessage({
2937
2909
  sessionId: session.id,
2938
2910
  agentId: session.agentId,
2939
- content: storeContent,
2940
- type: storeType,
2911
+ content: persistedUserMessage.content,
2912
+ type: persistedUserMessage.type,
2941
2913
  isSelf: true,
2942
2914
  clientMessageId: request.clientMessageId,
2943
- caption: storeCaption,
2944
- ...persistedInbound ? {
2945
- persistedInboundPaths: [...persistedInbound.paths],
2946
- persistedInboundMediaTypes: [...persistedInbound.mediaTypes]
2915
+ caption: persistedUserMessage.caption,
2916
+ ...persistedUserMessage.persistedInboundPaths ? {
2917
+ persistedInboundPaths: [...persistedUserMessage.persistedInboundPaths],
2918
+ persistedInboundMediaTypes: [...persistedUserMessage.persistedInboundMediaTypes ?? []]
2947
2919
  } : {},
2948
- ...fileMeta ? {
2949
- ...fileMeta.fileName ? { fileName: fileMeta.fileName } : {},
2950
- ...fileMeta.fileMime ? { fileMime: fileMeta.fileMime } : {},
2951
- ...typeof fileMeta.fileSize === "number" && fileMeta.fileSize > 0 ? { fileSize: fileMeta.fileSize } : {}
2920
+ ...persistedUserMessage.fileName || persistedUserMessage.fileMime || persistedUserMessage.fileSize ? {
2921
+ ...persistedUserMessage.fileName ? { fileName: persistedUserMessage.fileName } : {},
2922
+ ...persistedUserMessage.fileMime ? { fileMime: persistedUserMessage.fileMime } : {},
2923
+ ...typeof persistedUserMessage.fileSize === "number" && persistedUserMessage.fileSize > 0 ? { fileSize: persistedUserMessage.fileSize } : {}
2952
2924
  } : {}
2953
2925
  });
2954
2926
  this.store.addMessage(session.id, userMessage);
@@ -2974,14 +2946,7 @@ ${inbound.bodyText}` : inbound.bodyText;
2974
2946
  this.logInfo(
2975
2947
  `[XKZOOM] mobile dispatch: attachment batch frame persisted without assistant turn (session=${session.id} message=${userMessage.id})`
2976
2948
  );
2977
- const placeholder = {
2978
- ...userMessage,
2979
- id: `${userMessage.id}-batch-ack-placeholder`,
2980
- isSelf: false,
2981
- status: "sent",
2982
- content: "",
2983
- type: "text"
2984
- };
2949
+ const placeholder = createAttachmentBatchAckPlaceholder(userMessage);
2985
2950
  return { messageId: userMessage.id, response: placeholder };
2986
2951
  }
2987
2952
  await ensureReplyDispatchWarmupComplete();
@@ -2989,14 +2954,17 @@ ${inbound.bodyText}` : inbound.bodyText;
2989
2954
  this.maybeLogReplyRuntimeMode(replyRuntimeModule);
2990
2955
  const { dispatchInboundMessage, createReplyDispatcher, finalizeInboundContext } = replyRuntimeModule;
2991
2956
  const replies = [];
2992
- const cidForStream = typeof identity.conversationId === "string" && identity.conversationId.trim() !== "" ? identity.conversationId.trim() : "";
2993
- const wssProbe = this.websocket;
2994
- const convHasStreamingSubscriber = cidForStream !== "" && typeof wssProbe.conversationHasStreamingSubscriber === "function" && wssProbe.conversationHasStreamingSubscriber(cidForStream);
2995
- const isMobileInbound = identity.provider === MOBILE_SOURCE || identity.surface === MOBILE_SOURCE || identity.channelId === MOBILE_CHANNEL_ID;
2996
- const streamingEnabled = this.isStreamingSubscriber(replyTarget ?? null) || convHasStreamingSubscriber || isMobileInbound && cidForStream !== "";
2957
+ const streamingState = resolveMobileDispatchStreamingState({
2958
+ identity,
2959
+ replyTargetIsStreaming: this.isStreamingSubscriber(replyTarget ?? null),
2960
+ websocket: this.websocket
2961
+ });
2962
+ const cidForStream = streamingState.conversationId;
2963
+ const isMobileInbound = streamingState.isMobileInbound;
2964
+ const streamingEnabled = streamingState.streamingEnabled;
2997
2965
  if (isMobileAssistantMirrorDebugEnabled()) {
2998
2966
  this.logInfo(
2999
- `[XKZOOM][assistant-mirror] streamingEnabled=${streamingEnabled} replyWs=${this.isStreamingSubscriber(replyTarget ?? null)} convSub=${convHasStreamingSubscriber} mobileFallback=${isMobileInbound && cidForStream !== ""} isMobileInbound=${isMobileInbound} session=${session.id} cidLen=${cidForStream.length}`
2967
+ `[XKZOOM][assistant-mirror] streamingEnabled=${streamingEnabled} replyWs=${streamingState.replyTargetIsStreaming} convSub=${streamingState.conversationHasStreamingSubscriber} mobileFallback=${streamingState.mobileInboundStreamingFallback} isMobileInbound=${isMobileInbound} session=${session.id} cidLen=${cidForStream.length}`
3000
2968
  );
3001
2969
  }
3002
2970
  const streamId = createMessageId();
@@ -3306,68 +3274,18 @@ ${inbound.bodyText}` : inbound.bodyText;
3306
3274
  }
3307
3275
  const projectContextPromptInfo = resolveProjectContextPromptInfo(session.agentId);
3308
3276
  const projectContextPromptBlock = projectContextPromptInfo.promptBlock;
3309
- const defaultMediaType = inbound.mediaType ?? (request.type === "image" ? "image/jpeg" : "application/octet-stream");
3310
- const baseContext = {
3311
- Body: inboundBodyForAgentDispatch,
3312
- BodyForAgent: inboundBodyForAgentDispatch,
3313
- BodyForCommands: inboundBodyForAgentDispatch,
3314
- RawBody: inboundBodyForAgentDispatch,
3315
- CommandBody: inboundBodyForAgentDispatch,
3316
- SessionKey: session.sessionKey,
3317
- Provider: identity.provider,
3318
- Surface: identity.surface,
3319
- ChannelId: XKZOOM_CHAT_CHANNEL_ID,
3320
- AccountId: identity.accountId,
3321
- ConversationId: identity.conversationId,
3322
- ChatType: "direct",
3323
- ConversationLabel: session.agentName,
3324
- SenderId: identity.senderId,
3325
- /** `message` 工具 `to` 须用本字段(或 `To`),勿用 `SenderId`(`mobile-device:*` 仅入站元数据)。 */
3326
- MessageToolTo: session.sessionKey,
3327
- SenderName: identity.senderName,
3328
- PeerId: identity.peerId,
3329
- Timestamp: Date.now(),
3330
- CommandAuthorized: true,
3331
- OriginatingChannel: XKZOOM_CHAT_CHANNEL_ID,
3332
- LegacyChannel: GATEWAY_WEBCHAT_CHANNEL_ID,
3333
- WebchatTransportChannel: GATEWAY_WEBCHAT_CHANNEL_ID,
3334
- OriginatingTo: session.sessionKey,
3335
- To: session.sessionKey
3336
- };
3337
- if (projectContextPromptBlock) {
3338
- baseContext.GroupSystemPrompt = projectContextPromptBlock;
3339
- }
3340
- if (projectContextPromptInfo.project) {
3341
- baseContext.ProjectRoot = projectContextPromptInfo.project.root_path;
3342
- baseContext.ProjectName = projectContextPromptInfo.project.project_name;
3343
- }
3344
- if (projectContextPromptInfo.agentWorkspaceRoot) {
3345
- baseContext.AgentWorkspaceRoot = projectContextPromptInfo.agentWorkspaceRoot;
3346
- }
3347
- const stagedInboundMedia = inboundMediaFromAttachments(stagedInboundAttachments);
3348
- if (stagedInboundMedia.paths.length > 0) {
3349
- baseContext.MediaPaths = stagedInboundMedia.paths;
3350
- baseContext.MediaTypes = stagedInboundMedia.mediaTypes;
3351
- baseContext.MediaType = stagedInboundMedia.mediaTypes[0] ?? inbound.mediaType ?? defaultMediaType;
3352
- baseContext.MediaUrls = stagedInboundMedia.paths.map((p) => pathToFileURL(p).href);
3353
- } else if (inbound.mediaUrls && inbound.mediaUrls.length > 0) {
3354
- if (persistedInbound && persistedInbound.paths.length === inbound.mediaUrls.length && persistedInbound.mediaTypes.length === inbound.mediaUrls.length) {
3355
- baseContext.MediaPaths = persistedInbound.paths;
3356
- baseContext.MediaTypes = persistedInbound.mediaTypes;
3357
- baseContext.MediaType = persistedInbound.mediaTypes[0] ?? inbound.mediaType ?? defaultMediaType;
3358
- baseContext.MediaUrls = persistedInbound.paths.map((p) => pathToFileURL(p).href);
3359
- } else {
3360
- baseContext.MediaUrls = inbound.mediaUrls;
3361
- baseContext.MediaType = inbound.mediaType ?? defaultMediaType;
3362
- }
3363
- }
3364
- if (stagedInboundFiles.items.length > 0) {
3365
- baseContext.FilePaths = stagedInboundFiles.items.map((item) => item.path);
3366
- baseContext.FileTypes = stagedInboundFiles.items.map((item) => item.mediaType);
3367
- baseContext.FileUrls = stagedInboundFiles.items.map((item) => item.fileUrl);
3368
- baseContext.FileRelativePaths = stagedInboundFiles.items.map((item) => item.relativePath);
3369
- }
3370
- const ctx = typeof finalizeInboundContext === "function" ? finalizeInboundContext(baseContext) : baseContext;
3277
+ const { ctx } = buildMobileDispatchInboundContext({
3278
+ session,
3279
+ identity,
3280
+ requestType: request.type,
3281
+ inbound,
3282
+ inboundBodyForAgentDispatch,
3283
+ projectContextPromptInfo,
3284
+ stagedInboundAttachments,
3285
+ stagedInboundFiles,
3286
+ persistedInbound,
3287
+ finalizeInboundContext: typeof finalizeInboundContext === "function" ? finalizeInboundContext : void 0
3288
+ });
3371
3289
  const mobileReasoningReplyOptions = buildMobileReasoningReplyOptions(request.reasoningMode);
3372
3290
  const primaryReasoningLevel = mobileReasoningReplyOptions.reasoningLevel;
3373
3291
  const attachMemoryContractR1 = shouldAttachMemoryContractR1Prompt({
@@ -3436,38 +3354,25 @@ ${inbound.bodyText}` : inbound.bodyText;
3436
3354
  }
3437
3355
  }
3438
3356
  const persistInterruptedTurnSnapshot = (params) => {
3439
- const assistantMessage = params.assistantMessage ?? [...replies].reverse().find((m) => !m.isSelf && (m.type === "text" || m.type === "code")) ?? null;
3440
- const target = assistantMessage ?? userMessage;
3441
- const snapshot = createInterruptedTurnSnapshot({
3357
+ return persistMobileDispatchInterruptedTurnSnapshot({
3442
3358
  kind: params.kind,
3443
3359
  sessionId: session.id,
3444
3360
  conversationId: identity.conversationId,
3445
3361
  userMessage,
3446
- assistantMessage,
3362
+ replies,
3363
+ assistantMessage: params.assistantMessage,
3447
3364
  assistantPartialText: params.assistantPartialText,
3448
3365
  streamId,
3449
3366
  assistantRunId,
3450
- elapsedMs: params.elapsedMs ?? Date.now() - dispatchStartAt,
3367
+ dispatchStartAt,
3368
+ elapsedMs: params.elapsedMs,
3451
3369
  iteration: params.iteration,
3452
- lastToolName: params.lastToolName ?? lastToolNameForInterruptedTurn,
3453
- error: params.error
3370
+ lastToolName: params.lastToolName,
3371
+ defaultLastToolName: lastToolNameForInterruptedTurn,
3372
+ error: params.error,
3373
+ persistMessage: (sessionId, messageId) => this.store.persistMessage(sessionId, messageId),
3374
+ logInfo: (message) => this.logInfo(message)
3454
3375
  });
3455
- if (!hasInterruptedTurnRecoveryEvidence(snapshot)) {
3456
- this.logInfo(
3457
- `[XKZOOM][turn-timeout][snapshot] skipped session=${session.id} conversationId=${identity.conversationId ?? "none"} userMessage=${userMessage.id} targetMessage=${target.id} assistantMessage=${assistantMessage?.id ?? "none"} turn_timeout_kind=${snapshot.turn_timeout_kind} recoverableEvidence=0 visibleTextLength=${snapshot.visibleTextLength}`
3458
- );
3459
- return null;
3460
- }
3461
- target.interruptedTurn = snapshot;
3462
- this.store.persistMessage(session.id, target.id);
3463
- this.logInfo(
3464
- `[XKZOOM][turn-timeout][snapshot] persisted session=${session.id} conversationId=${identity.conversationId ?? "none"} userMessage=${userMessage.id} targetMessage=${target.id} assistantMessage=${assistantMessage?.id ?? "none"} snapshot=${snapshot.id} turn_timeout_kind=${snapshot.turn_timeout_kind} elapsedMs=${snapshot.elapsedMs ?? -1} iteration=${snapshot.iteration ?? -1} lastToolName=${snapshot.lastToolName ?? "none"} visibleTextLength=${snapshot.visibleTextLength}`
3465
- );
3466
- return {
3467
- snapshotId: snapshot.id,
3468
- targetMessageId: target.id,
3469
- visibleTextLength: snapshot.visibleTextLength
3470
- };
3471
3376
  };
3472
3377
  let primaryDispatchSucceeded = false;
3473
3378
  let userAbortedDispatch = false;
@@ -3643,25 +3548,16 @@ ${inbound.bodyText}` : inbound.bodyText;
3643
3548
  replyOptions
3644
3549
  };
3645
3550
  const runCompactGatewayTurn = async (turn) => {
3646
- let summarizeToolCalled = false;
3647
3551
  let compactDoneLineSeen = false;
3648
3552
  const replyCountBefore = replies.length;
3649
- const turnCtx = {
3650
- ...ctx,
3651
- Body: turn.userBody,
3652
- BodyForAgent: turn.userBody,
3653
- BodyForCommands: turn.userBody,
3654
- RawBody: turn.userBody,
3655
- CommandBody: turn.userBody
3656
- };
3657
- if (turn.suppressProjectContext) {
3658
- delete turnCtx.GroupSystemPrompt;
3659
- }
3660
- const r1ForTurn = turn.suppressR1Prefetch || !attachMemoryContractR1 ? "" : memoryContractExtraSystemPrompt;
3661
- const isCompactArchiveTask = turn.userBody === "[XKZOOM_CONTEXT_COMPACT_SYSTEM_TASK]";
3553
+ const turnCtx = buildCompactGatewayTurnContext({
3554
+ baseContext: ctx,
3555
+ userBody: turn.userBody,
3556
+ suppressProjectContext: turn.suppressProjectContext
3557
+ });
3662
3558
  let turnDiaryBlock = "";
3663
3559
  let turnRunningBlock = "";
3664
- if (!isCompactArchiveTask) {
3560
+ if (!isCompactArchiveTurn(turn)) {
3665
3561
  try {
3666
3562
  turnDiaryBlock = await buildRecentDiaryContextBlock({ agentId: session.agentId });
3667
3563
  turnRunningBlock = await buildRunningSummaryContextBlock(session.id);
@@ -3670,42 +3566,36 @@ ${inbound.bodyText}` : inbound.bodyText;
3670
3566
  turnRunningBlock = "";
3671
3567
  }
3672
3568
  }
3673
- const turnExtra = joinRuntimeExtraSystemPrompt([
3674
- turn.suppressProjectContext ? "" : projectContextPromptBlock,
3569
+ const turnExtra = buildCompactTurnExtraSystemPrompt({
3570
+ turn,
3571
+ attachMemoryContractR1,
3572
+ memoryContractExtraSystemPrompt,
3573
+ projectContextPromptBlock,
3675
3574
  workspaceStartupBlock,
3676
- turnDiaryBlock,
3677
- turnRunningBlock,
3678
- turn.extraSystemPrompt,
3679
- r1ForTurn
3680
- ]);
3681
- const priorOnAgentEvent = replyOptions.onAgentEvent;
3682
- const surfaceStream = turn.surfaceStreamToClient === true;
3575
+ diaryBlock: turnDiaryBlock,
3576
+ runningSummaryBlock: turnRunningBlock
3577
+ });
3578
+ const streamPolicy = resolveCompactTurnStreamPolicy({
3579
+ turn,
3580
+ baseDisableBlockStreaming: replyOptions.disableBlockStreaming
3581
+ });
3582
+ const surfaceStream = streamPolicy.surfaceStream;
3683
3583
  if (surfaceStream) {
3684
3584
  textStream.resetStreamBubbleForCompactResume({ preserveToolCalls: true });
3685
3585
  } else {
3686
3586
  compactClientStreamSuppressed = true;
3687
3587
  }
3688
- const turnReplyOptions = {
3689
- ...replyOptions,
3690
- ...turnExtra.length > 0 ? { extraSystemPrompt: turnExtra } : {},
3691
- disableBlockStreaming: surfaceStream ? replyOptions.disableBlockStreaming : true,
3692
- onAgentEvent: (evt) => {
3693
- const e = evt;
3694
- if (e?.stream === "tool") {
3695
- const name = typeof e.data?.name === "string" ? e.data.name : "";
3696
- if (name === "summarize") summarizeToolCalled = true;
3697
- }
3698
- if (surfaceStream) {
3699
- priorOnAgentEvent?.(evt);
3700
- }
3701
- }
3702
- };
3588
+ const compactReplyOptions = createCompactGatewayTurnReplyOptions({
3589
+ baseReplyOptions: replyOptions,
3590
+ turnExtraSystemPrompt: turnExtra,
3591
+ streamPolicy
3592
+ });
3703
3593
  try {
3704
3594
  await dispatchInboundMessage({
3705
3595
  ctx: turnCtx,
3706
3596
  cfg,
3707
3597
  dispatcher,
3708
- replyOptions: turnReplyOptions
3598
+ replyOptions: compactReplyOptions.replyOptions
3709
3599
  });
3710
3600
  await dispatcher.waitForIdle();
3711
3601
  if (!surfaceStream) {
@@ -3722,7 +3612,11 @@ ${inbound.bodyText}` : inbound.bodyText;
3722
3612
  compactDoneLineSeen = true;
3723
3613
  }
3724
3614
  }
3725
- return { ok: true, summarizeToolCalled, compactDoneLineSeen };
3615
+ return {
3616
+ ok: true,
3617
+ summarizeToolCalled: compactReplyOptions.summarizeToolCalled(),
3618
+ compactDoneLineSeen
3619
+ };
3726
3620
  } catch (err) {
3727
3621
  compactClientStreamSuppressed = false;
3728
3622
  return { ok: false, error: err instanceof Error ? err.message : String(err) };
@@ -3730,13 +3624,13 @@ ${inbound.bodyText}` : inbound.bodyText;
3730
3624
  };
3731
3625
  const runCompactNativeTurn = async (turn) => {
3732
3626
  try {
3733
- const surfaceStream = turn.surfaceStreamToClient === true;
3627
+ const surfaceStream = shouldSurfaceCompactTurnToClient(turn);
3734
3628
  if (surfaceStream) {
3735
3629
  textStream.resetStreamBubbleForCompactResume({ preserveToolCalls: true });
3736
3630
  } else {
3737
3631
  compactClientStreamSuppressed = true;
3738
3632
  }
3739
- let nativeReplyRoute2 = resolveNativeReplyRoute({
3633
+ const nativeReplyRoute2 = await resolveNativeDispatchReplyRoute({
3740
3634
  requestType: request.type,
3741
3635
  streamingEnabled,
3742
3636
  hasInboundMedia: false,
@@ -3745,17 +3639,6 @@ ${inbound.bodyText}` : inbound.bodyText;
3745
3639
  cfg,
3746
3640
  agentId: session.agentId
3747
3641
  });
3748
- if (shouldResolveNativeReplyRouteAsync(cfg, session.agentId, Boolean(nativeReplyRoute2))) {
3749
- nativeReplyRoute2 = await resolveNativeReplyRouteAsync({
3750
- requestType: request.type,
3751
- streamingEnabled,
3752
- hasInboundMedia: false,
3753
- hasResolvedUpload: false,
3754
- content: turn.userBody,
3755
- cfg,
3756
- agentId: session.agentId
3757
- });
3758
- }
3759
3642
  if (!nativeReplyRoute2) {
3760
3643
  compactClientStreamSuppressed = false;
3761
3644
  return { ok: false, error: "native_resume_route_unavailable" };
@@ -3771,18 +3654,14 @@ ${inbound.bodyText}` : inbound.bodyText;
3771
3654
  }
3772
3655
  const projectInfo = resolveProjectContextPromptInfo(session.agentId);
3773
3656
  const sessionMessagesForCompactResume = this.store.getSessionMessages(session.id);
3774
- const compactResumeTranscriptBudget = buildNativeTranscriptBudgetForContextWindow(
3775
- nativeReplyRoute2.chat.contextWindow
3776
- );
3777
- let nativeTranscriptMessages = buildNativeReplyTranscriptMessages(
3778
- sessionMessagesForCompactResume,
3779
- compactResumeTranscriptBudget ? { budget: compactResumeTranscriptBudget } : void 0
3780
- );
3781
- if (nativeTranscriptMessages.length === 0 && turn.userBody.trim()) {
3782
- nativeTranscriptMessages = [
3783
- { role: "user", content: [{ type: "text", text: turn.userBody.trim() }] }
3784
- ];
3785
- }
3657
+ const compactResumeTranscript = buildNativeDispatchTranscriptForTurn({
3658
+ sessionMessages: sessionMessagesForCompactResume,
3659
+ contextWindow: nativeReplyRoute2.chat.contextWindow,
3660
+ fallbackUserText: turn.userBody
3661
+ });
3662
+ const compactResumeTranscriptBudget = compactResumeTranscript.budget;
3663
+ const compactResumeTranscriptUsage = compactResumeTranscript.usage;
3664
+ const nativeTranscriptMessages = compactResumeTranscript.messages;
3786
3665
  const nativeAgentInfo = this.store.getAgentById(session.agentId);
3787
3666
  const nativeAgentSnapshot = buildMobileSystemPromptSnapshot(session.agentId, nativeAgentInfo);
3788
3667
  const buildCompactNativeExtraContext = async (providerId, model) => {
@@ -3797,16 +3676,16 @@ ${inbound.bodyText}` : inbound.bodyText;
3797
3676
  agentName,
3798
3677
  project: projectInfo.project,
3799
3678
  agentWorkspaceRoot: projectInfo.agentWorkspaceRoot,
3800
- taskId: `session:${session.id}:compact-resume`,
3679
+ taskId: buildCompactNativeResumeTaskId(session.id),
3801
3680
  workspaceStartup: workspaceStartupBlock,
3802
- memoryEvidenceBlocks: [
3803
- turnDiaryBlock,
3804
- turnRunningBlock,
3805
- turn.extraSystemPrompt
3806
- ],
3681
+ memoryEvidenceBlocks: buildCompactNativeMemoryEvidenceBlocks({
3682
+ diaryBlock: turnDiaryBlock,
3683
+ runningSummaryBlock: turnRunningBlock,
3684
+ extraSystemPrompt: turn.extraSystemPrompt
3685
+ }),
3807
3686
  recentTurnsBlock: sessionFirstUserMessageBlock,
3808
3687
  queryText: turn.userBody,
3809
- toolContractBlock: "Runtime tool schemas are injected separately. During compact resume, use tools only when they add new evidence."
3688
+ toolContractBlock: COMPACT_NATIVE_RESUME_TOOL_CONTRACT_BLOCK
3810
3689
  });
3811
3690
  return {
3812
3691
  extraBlocks: buildNativeReplyRuntimeContextBlocks({
@@ -3822,142 +3701,35 @@ ${inbound.bodyText}` : inbound.bodyText;
3822
3701
  providerAccelerationCachePrefix: renderContextPackStablePrefixForProviderCache(contextPack)
3823
3702
  };
3824
3703
  };
3825
- const nativeAnthropicDeliverPromises = [];
3826
- const nativeAnthropicDispatcher = {
3827
- sendBlockReply: (payload) => {
3828
- nativeAnthropicDeliverPromises.push(Promise.resolve(dispatcher.sendBlockReply(payload)));
3829
- return true;
3830
- },
3831
- sendFinalReply: (payload) => {
3832
- nativeAnthropicDeliverPromises.push(Promise.resolve(dispatcher.sendFinalReply(payload)));
3833
- return true;
3834
- },
3835
- markComplete: () => {
3836
- dispatcher.markComplete();
3837
- }
3838
- };
3839
3704
  const forwardToolEvent = surfaceStream && onAgentEvent ? (ev) => {
3840
3705
  onAgentEvent({ stream: "tool", data: ev });
3841
3706
  } : void 0;
3842
- switch (nativeReplyRoute2.platform) {
3843
- case "openai-completions": {
3844
- const { chat: nativeOpenAiChatConfig } = nativeReplyRoute2;
3845
- const nativeContext = await buildCompactNativeExtraContext(
3846
- nativeOpenAiChatConfig.providerId,
3847
- nativeOpenAiChatConfig.model
3848
- );
3849
- const nativeOpenAiSystemPrompt = composeNativeReplySystemPrompt({
3850
- agentSnapshot: nativeAgentSnapshot,
3851
- providerId: nativeOpenAiChatConfig.providerId,
3852
- model: nativeOpenAiChatConfig.model,
3853
- extraBlocks: [
3854
- ...nativeContext.extraBlocks,
3855
- ...buildNativeOpenAiTurnToolBlocks()
3856
- ]
3857
- });
3858
- const nativeOpenAiMessages = buildNativeReplyOpenAiMessages(
3859
- nativeOpenAiSystemPrompt,
3860
- nativeTranscriptMessages
3861
- );
3862
- const toolChoicePolicy = detectToolChoicePolicyForTurn({
3863
- userText: turn.userBody,
3864
- enabledToolNames: OWNED_TURN_TOOL_NAMES
3865
- });
3866
- this.logInfo(
3867
- `[XKZOOM][context-compact] NATIVE_RESUME_TURN session=${session.id} platform=openai-completions tool_choice_policy=${toolChoicePolicy.kind} provider=${nativeOpenAiChatConfig.providerId} model=${nativeOpenAiChatConfig.model} contextWindow=${nativeOpenAiChatConfig.contextWindow ?? "unknown"} transcriptBudgetBytes=${compactResumeTranscriptBudget?.maxBytes ?? "fallback"} transcriptTurns=${nativeTranscriptMessages.length}`
3868
- );
3869
- const nativeOpenAiDeliverPromises = [];
3870
- await runNativeOpenAiCompletionsTurnToDispatcher({
3871
- dispatcher: {
3872
- sendBlockReply: (payload) => {
3873
- nativeOpenAiDeliverPromises.push(Promise.resolve(dispatcher.sendBlockReply(payload)));
3874
- return true;
3875
- },
3876
- sendFinalReply: (payload) => {
3877
- nativeOpenAiDeliverPromises.push(Promise.resolve(dispatcher.sendFinalReply(payload)));
3878
- return true;
3879
- },
3880
- markComplete: () => {
3881
- dispatcher.markComplete();
3882
- }
3883
- },
3884
- chatConfig: nativeOpenAiChatConfig,
3885
- messages: nativeOpenAiMessages,
3886
- agentId: session.agentId,
3887
- ownedToolDeps: buildTurnOwnedToolDeps(session, turn.userBody, cfg),
3888
- toolChoicePolicy,
3889
- signal: dispatchAbortController.signal,
3890
- log: (m) => this.logInfo(m),
3891
- reasoningMode: primaryReasoningLevel,
3892
- providerAccelerationPlan: nativeContext.providerAccelerationPlan,
3893
- onToolEvent: forwardToolEvent ? (ev) => {
3894
- forwardToolEvent(ev);
3895
- } : void 0
3896
- });
3897
- await Promise.all(nativeOpenAiDeliverPromises);
3898
- break;
3899
- }
3900
- case "anthropic-messages": {
3901
- const { chat: nativeAnthropicChatConfig } = nativeReplyRoute2;
3902
- const useNativeAnthropicTurn = nativeAnthropicTurnLoopEnabled();
3903
- const nativeContext = await buildCompactNativeExtraContext(
3904
- nativeAnthropicChatConfig.providerId,
3905
- nativeAnthropicChatConfig.model
3906
- );
3907
- const toolChoicePolicy = detectToolChoicePolicyForTurn({
3908
- userText: turn.userBody,
3909
- enabledToolNames: OWNED_TURN_TOOL_NAMES
3910
- });
3911
- const turnSystemPrompt = composeNativeReplySystemPrompt({
3912
- agentSnapshot: nativeAgentSnapshot,
3913
- providerId: nativeAnthropicChatConfig.providerId,
3914
- model: nativeAnthropicChatConfig.model,
3915
- extraBlocks: useNativeAnthropicTurn ? [...nativeContext.extraBlocks, ...buildNativeAnthropicTurnToolBlocks()] : nativeContext.extraBlocks
3916
- });
3917
- this.logInfo(
3918
- `[XKZOOM][context-compact] NATIVE_RESUME_TURN session=${session.id} platform=anthropic-messages path=${useNativeAnthropicTurn ? "turn" : "stream"} provider=${nativeAnthropicChatConfig.providerId} model=${nativeAnthropicChatConfig.model} contextWindow=${nativeAnthropicChatConfig.contextWindow ?? "unknown"} transcriptBudgetBytes=${compactResumeTranscriptBudget?.maxBytes ?? "fallback"} transcriptTurns=${nativeTranscriptMessages.length}`
3919
- );
3920
- if (useNativeAnthropicTurn) {
3921
- await runNativeAnthropicMessagesTurnToDispatcher({
3922
- dispatcher: nativeAnthropicDispatcher,
3923
- chatConfig: nativeAnthropicChatConfig,
3924
- messages: nativeTranscriptMessages,
3925
- systemPrompt: turnSystemPrompt,
3926
- agentId: session.agentId,
3927
- inboundSessionId: session.id,
3928
- ownedToolDeps: buildTurnOwnedToolDeps(session, turn.userBody, cfg),
3929
- toolChoicePolicy,
3930
- signal: dispatchAbortController.signal,
3931
- log: (m) => this.logInfo(m),
3932
- reasoningMode: primaryReasoningLevel,
3933
- onToolEvent: forwardToolEvent,
3934
- providerAccelerationPlan: nativeContext.providerAccelerationPlan,
3935
- providerAccelerationCachePrefix: nativeContext.providerAccelerationCachePrefix
3936
- });
3937
- } else {
3938
- await runNativeAnthropicMessagesStreamToDispatcher({
3939
- dispatcher: nativeAnthropicDispatcher,
3940
- chatConfig: nativeAnthropicChatConfig,
3941
- messages: nativeTranscriptMessages,
3942
- systemPrompt: turnSystemPrompt,
3943
- signal: dispatchAbortController.signal,
3944
- log: (m) => this.logInfo(m),
3945
- reasoningMode: primaryReasoningLevel,
3946
- providerAccelerationPlan: nativeContext.providerAccelerationPlan,
3947
- providerAccelerationCachePrefix: nativeContext.providerAccelerationCachePrefix
3948
- });
3949
- }
3950
- await Promise.all(nativeAnthropicDeliverPromises);
3951
- break;
3952
- }
3953
- default: {
3954
- compactClientStreamSuppressed = false;
3955
- return {
3956
- ok: false,
3957
- error: `native_resume_unsupported_platform:${String(nativeReplyRoute2.platform)}`
3958
- };
3959
- }
3960
- }
3707
+ this.logInfo(
3708
+ `[XKZOOM][context-compact] NATIVE_RESUME_TURN session=${session.id} platform=${nativeReplyRoute2.platform} provider=${nativeReplyRoute2.chat.providerId} model=${nativeReplyRoute2.chat.model} contextWindow=${nativeReplyRoute2.chat.contextWindow ?? "unknown"} transcriptBudgetBytes=${compactResumeTranscriptBudget?.maxBytes ?? "fallback"} transcriptRawBytes=${compactResumeTranscriptUsage.rawBytes} transcriptSummarizableBytes=${compactResumeTranscriptUsage.summarizableBytes} transcriptTurns=${nativeTranscriptMessages.length}`
3709
+ );
3710
+ await runNativeDispatchTurn({
3711
+ route: nativeReplyRoute2,
3712
+ dispatcher,
3713
+ transcriptMessages: nativeTranscriptMessages,
3714
+ ...compactResumeTranscriptBudget?.maxBytes !== void 0 ? { transcriptBudgetMaxBytes: compactResumeTranscriptBudget.maxBytes } : {},
3715
+ agentId: session.agentId,
3716
+ sessionId: session.id,
3717
+ streamId,
3718
+ userMessageId: userMessage.id,
3719
+ ...identity.conversationId ? { conversationId: identity.conversationId } : {},
3720
+ userText: turn.userBody,
3721
+ ownedToolDeps: buildTurnOwnedToolDeps(session, turn.userBody, cfg),
3722
+ agentSnapshot: nativeAgentSnapshot,
3723
+ signal: dispatchAbortController.signal,
3724
+ dispatchStartAt,
3725
+ reasoningMode: primaryReasoningLevel,
3726
+ buildRuntimeExtraContext: buildCompactNativeExtraContext,
3727
+ peekFinalAnswerText: () => textStream.peekFinalAnswerText(),
3728
+ logInfo: (m) => this.logInfo(m),
3729
+ logWarn: (m) => this.logWarn(m),
3730
+ ...forwardToolEvent ? { onToolEvent: forwardToolEvent } : {},
3731
+ turnFailureMode: "throw"
3732
+ });
3961
3733
  await dispatcher.waitForIdle();
3962
3734
  if (!surfaceStream) {
3963
3735
  compactClientStreamSuppressed = false;
@@ -4022,7 +3794,7 @@ ${inbound.bodyText}` : inbound.bodyText;
4022
3794
  }
4023
3795
  });
4024
3796
  const compactHandled = compactResult.handled;
4025
- let nativeReplyRoute = resolveNativeReplyRoute({
3797
+ const nativeReplyRoute = await resolveNativeDispatchReplyRoute({
4026
3798
  requestType: request.type,
4027
3799
  streamingEnabled,
4028
3800
  hasInboundMedia: Boolean(inbound.mediaUrls && inbound.mediaUrls.length > 0),
@@ -4031,17 +3803,6 @@ ${inbound.bodyText}` : inbound.bodyText;
4031
3803
  cfg,
4032
3804
  agentId: session.agentId
4033
3805
  });
4034
- if (shouldResolveNativeReplyRouteAsync(cfg, session.agentId, Boolean(nativeReplyRoute))) {
4035
- nativeReplyRoute = await resolveNativeReplyRouteAsync({
4036
- requestType: request.type,
4037
- streamingEnabled,
4038
- hasInboundMedia: Boolean(inbound.mediaUrls && inbound.mediaUrls.length > 0),
4039
- hasResolvedUpload: Boolean(resolvedHttpUpload),
4040
- content: inboundBodyForAgentDispatch,
4041
- cfg,
4042
- agentId: session.agentId
4043
- });
4044
- }
4045
3806
  if (!compactHandled && nativeReplyRoute) {
4046
3807
  const toolsProfile = resolveGatewayAgentToolsProfile(cfg, session.agentId) || "(unset)";
4047
3808
  const toolLoopWanted = gatewayAgentWantsFullToolLoop(cfg, session.agentId);
@@ -4050,241 +3811,57 @@ ${inbound.bodyText}` : inbound.bodyText;
4050
3811
  `[XKZOOM] native-reply-chain route=${nativeReplyRoute.platform} session=${session.id} toolsProfile=${toolsProfile} toolLoopWanted=${toolLoopWanted ? 1 : 0} nativeForced=${nativeForced ? 1 : 0} xreCore=${process.env.XKZOOM_XRE_CORE === "1" ? 1 : 0} (native OpenAI turn wires owned tools; Anthropic turn controlled by flag)`
4051
3812
  );
4052
3813
  const sessionMessagesForNativeReply = this.store.getSessionMessages(session.id);
4053
- const nativeTranscriptBudget = buildNativeTranscriptBudgetForContextWindow(
4054
- nativeReplyRoute.chat.contextWindow
4055
- );
4056
- let nativeTranscriptMessages = buildNativeReplyTranscriptMessages(
4057
- sessionMessagesForNativeReply,
4058
- nativeTranscriptBudget ? { budget: nativeTranscriptBudget } : void 0
4059
- );
4060
- if (nativeTranscriptMessages.length === 0) {
4061
- const fallbackUserText = inboundBodyForAgentDispatch.trim();
4062
- if (fallbackUserText) {
4063
- nativeTranscriptMessages = [
4064
- { role: "user", content: [{ type: "text", text: fallbackUserText }] }
4065
- ];
4066
- }
4067
- }
4068
- const transcriptAudit = sessionMessagesForNativeReply.reduce(
4069
- (acc, msg) => {
4070
- if (msg.compactModelExcluded) acc.compactExcluded++;
4071
- if (msg.continuationInjected) acc.continuationInjected++;
4072
- if (msg.interruptedTurn) acc.interruptedSnapshots++;
4073
- if (!msg.compactModelExcluded && !msg.continuationInjected) {
4074
- if (msg.isSelf) acc.visibleUserTurns++;
4075
- else acc.visibleAssistantTurns++;
4076
- }
4077
- return acc;
4078
- },
4079
- {
4080
- compactExcluded: 0,
4081
- continuationInjected: 0,
4082
- interruptedSnapshots: 0,
4083
- visibleAssistantTurns: 0,
4084
- visibleUserTurns: 0
4085
- }
4086
- );
3814
+ const nativeTranscript = buildNativeDispatchTranscriptForTurn({
3815
+ sessionMessages: sessionMessagesForNativeReply,
3816
+ contextWindow: nativeReplyRoute.chat.contextWindow,
3817
+ fallbackUserText: inboundBodyForAgentDispatch
3818
+ });
3819
+ const nativeTranscriptBudget = nativeTranscript.budget;
3820
+ const nativeTranscriptMessages = nativeTranscript.messages;
3821
+ const nativeTranscriptUsage = nativeTranscript.usage;
3822
+ const transcriptAudit = nativeTranscript.audit;
4087
3823
  this.logInfo(
4088
- `[XKZOOM][native-reply-chain][transcript-audit] session=${session.id} conversationId=${identity.conversationId ?? "none"} provider=${nativeReplyRoute.chat.providerId} model=${nativeReplyRoute.chat.model} contextWindow=${nativeReplyRoute.chat.contextWindow ?? "unknown"} transcriptBudgetBytes=${nativeTranscriptBudget?.maxBytes ?? "fallback"} priorMessages=${priorSessionMessageCount} storeMessages=${sessionMessagesForNativeReply.length} visibleUserTurns=${transcriptAudit.visibleUserTurns} visibleAssistantTurns=${transcriptAudit.visibleAssistantTurns} compactExcluded=${transcriptAudit.compactExcluded} continuationInjected=${transcriptAudit.continuationInjected} interruptedSnapshots=${transcriptAudit.interruptedSnapshots} activeInterrupted=${activeInterruptedTurn?.snapshot.id ?? "none"} currentUser=${userMessage.id} transcriptTurns=${nativeTranscriptMessages.length}`
3824
+ `[XKZOOM][native-reply-chain][transcript-audit] session=${session.id} conversationId=${identity.conversationId ?? "none"} provider=${nativeReplyRoute.chat.providerId} model=${nativeReplyRoute.chat.model} contextWindow=${nativeReplyRoute.chat.contextWindow ?? "unknown"} transcriptBudgetBytes=${nativeTranscriptBudget?.maxBytes ?? "fallback"} transcriptRawBytes=${nativeTranscriptUsage.rawBytes} transcriptSummarizableBytes=${nativeTranscriptUsage.summarizableBytes} priorMessages=${priorSessionMessageCount} storeMessages=${nativeTranscript.storeMessageCount} visibleUserTurns=${transcriptAudit.visibleUserTurns} visibleAssistantTurns=${transcriptAudit.visibleAssistantTurns} compactExcluded=${transcriptAudit.compactExcluded} continuationInjected=${transcriptAudit.continuationInjected} interruptedSnapshots=${transcriptAudit.interruptedSnapshots} activeInterrupted=${activeInterruptedTurn?.snapshot.id ?? "none"} currentUser=${userMessage.id} transcriptTurns=${nativeTranscriptMessages.length}`
4089
3825
  );
4090
3826
  const nativeAgentInfo = this.store.getAgentById(session.agentId);
4091
3827
  const nativeAgentSnapshot = buildMobileSystemPromptSnapshot(session.agentId, nativeAgentInfo);
4092
- switch (nativeReplyRoute.platform) {
4093
- case "openai-completions": {
4094
- const { chat: nativeOpenAiChatConfig } = nativeReplyRoute;
4095
- const nativeContext = await buildNativeRuntimeExtraContext(
4096
- nativeOpenAiChatConfig.providerId,
4097
- nativeOpenAiChatConfig.model,
4098
- nativeAgentSnapshot?.agentName
4099
- );
4100
- const nativeOpenAiSystemPrompt = composeNativeReplySystemPrompt({
4101
- agentSnapshot: nativeAgentSnapshot,
4102
- providerId: nativeOpenAiChatConfig.providerId,
4103
- model: nativeOpenAiChatConfig.model,
4104
- extraBlocks: [
4105
- ...nativeContext.extraBlocks,
4106
- ...buildNativeOpenAiTurnToolBlocks()
4107
- ]
4108
- });
4109
- const nativeOpenAiMessages = buildNativeReplyOpenAiMessages(
4110
- nativeOpenAiSystemPrompt,
4111
- nativeTranscriptMessages
4112
- );
4113
- const toolChoicePolicy = detectToolChoicePolicyForTurn({
4114
- userText: inboundBodyForAgentDispatch,
4115
- enabledToolNames: OWNED_TURN_TOOL_NAMES,
4116
- priorSessionMessageCount
4117
- });
4118
- this.logInfo(
4119
- `[XKZOOM] native-reply-chain platform=openai-completions session=${session.id} provider=${nativeOpenAiChatConfig.providerId} model=${nativeOpenAiChatConfig.model} contextWindow=${nativeOpenAiChatConfig.contextWindow ?? "unknown"} transcriptBudgetBytes=${nativeTranscriptBudget?.maxBytes ?? "fallback"} transcriptTurns=${nativeTranscriptMessages.length} tool_choice_policy=${toolChoicePolicy.kind}` + (nativeAgentSnapshot ? ` identitySource=${nativeAgentSnapshot.source}` : " identitySource=none") + (process.env.XKZOOM_XRE_CORE === "1" ? " xreCore=1" : "")
4120
- );
4121
- const nativeOpenAiDeliverPromises = [];
4122
- await runNativeOpenAiCompletionsTurnToDispatcher({
4123
- dispatcher: {
4124
- sendBlockReply: (payload) => {
4125
- nativeOpenAiDeliverPromises.push(Promise.resolve(dispatcher.sendBlockReply(payload)));
4126
- return true;
4127
- },
4128
- sendFinalReply: (payload) => {
4129
- nativeOpenAiDeliverPromises.push(Promise.resolve(dispatcher.sendFinalReply(payload)));
4130
- return true;
4131
- },
4132
- markComplete: () => {
4133
- dispatcher.markComplete();
4134
- }
4135
- },
4136
- chatConfig: nativeOpenAiChatConfig,
4137
- messages: nativeOpenAiMessages,
4138
- agentId: session.agentId,
4139
- ownedToolDeps: buildTurnOwnedToolDeps(session, inboundBodyForAgentDispatch, cfg),
4140
- toolChoicePolicy,
4141
- signal: dispatchAbortController.signal,
4142
- log: (m) => this.logInfo(m),
4143
- reasoningMode: primaryReasoningLevel,
4144
- providerAccelerationPlan: nativeContext.providerAccelerationPlan,
4145
- onToolEvent: onAgentEvent ? (ev) => {
4146
- onAgentEvent({ stream: "tool", data: ev });
4147
- } : void 0
4148
- });
4149
- await Promise.all(nativeOpenAiDeliverPromises);
4150
- break;
4151
- }
4152
- case "anthropic-messages": {
4153
- const { chat: nativeAnthropicChatConfig } = nativeReplyRoute;
4154
- const nativeContext = await buildNativeRuntimeExtraContext(
4155
- nativeAnthropicChatConfig.providerId,
4156
- nativeAnthropicChatConfig.model,
4157
- nativeAgentSnapshot?.agentName
4158
- );
4159
- const nativeAnthropicSystemPrompt = composeNativeReplySystemPrompt({
4160
- agentSnapshot: nativeAgentSnapshot,
4161
- providerId: nativeAnthropicChatConfig.providerId,
4162
- model: nativeAnthropicChatConfig.model,
4163
- extraBlocks: nativeContext.extraBlocks
4164
- });
4165
- const useNativeAnthropicTurn = nativeAnthropicTurnLoopEnabled();
4166
- this.logInfo(
4167
- `[XKZOOM] native-reply-chain platform=anthropic-messages session=${session.id} provider=${nativeAnthropicChatConfig.providerId} model=${nativeAnthropicChatConfig.model} contextWindow=${nativeAnthropicChatConfig.contextWindow ?? "unknown"} transcriptBudgetBytes=${nativeTranscriptBudget?.maxBytes ?? "fallback"} transcriptTurns=${nativeTranscriptMessages.length} reply_path=${useNativeAnthropicTurn ? "native_anthropic_turn" : "native_anthropic_stream"}` + (nativeAgentSnapshot ? ` identitySource=${nativeAgentSnapshot.source}` : " identitySource=none") + (process.env.XKZOOM_XRE_CORE === "1" ? " xreCore=1" : "")
4168
- );
4169
- const nativeAnthropicDeliverPromises = [];
4170
- let turnReasoningSignatureToPersist;
4171
- const nativeAnthropicDispatcher = {
4172
- sendBlockReply: (payload) => {
4173
- nativeAnthropicDeliverPromises.push(Promise.resolve(dispatcher.sendBlockReply(payload)));
4174
- return true;
4175
- },
4176
- sendFinalReply: (payload) => {
4177
- nativeAnthropicDeliverPromises.push(Promise.resolve(dispatcher.sendFinalReply(payload)));
4178
- return true;
4179
- },
4180
- markComplete: () => {
4181
- dispatcher.markComplete();
4182
- }
4183
- };
4184
- if (useNativeAnthropicTurn) {
4185
- const toolChoicePolicy = detectToolChoicePolicyForTurn({
4186
- userText: inboundBodyForAgentDispatch,
4187
- enabledToolNames: OWNED_TURN_TOOL_NAMES,
4188
- priorSessionMessageCount
4189
- });
4190
- const turnSystemPrompt = composeNativeReplySystemPrompt({
4191
- agentSnapshot: nativeAgentSnapshot,
4192
- providerId: nativeAnthropicChatConfig.providerId,
4193
- model: nativeAnthropicChatConfig.model,
4194
- extraBlocks: [
4195
- ...nativeContext.extraBlocks,
4196
- ...buildNativeAnthropicTurnToolBlocks()
4197
- ]
4198
- });
4199
- this.logInfo(
4200
- `[XKZOOM] native-reply-chain rfa-scope-per-tool session=${session.id} tool_choice_policy=${toolChoicePolicy.kind}`
4201
- );
4202
- if (dispatchAbortController.signal.aborted) {
4203
- this.logInfo(
4204
- `[XKZOOM][native-reply-chain] turn skipped: dispatch already aborted session=${session.id}`
4205
- );
4206
- }
4207
- let turnResult;
4208
- try {
4209
- turnResult = await runNativeAnthropicMessagesTurnToDispatcher({
4210
- dispatcher: nativeAnthropicDispatcher,
4211
- chatConfig: nativeAnthropicChatConfig,
4212
- messages: nativeTranscriptMessages,
4213
- systemPrompt: turnSystemPrompt,
4214
- agentId: session.agentId,
4215
- inboundSessionId: session.id,
4216
- ownedToolDeps: buildTurnOwnedToolDeps(session, inboundBodyForAgentDispatch, cfg),
4217
- toolChoicePolicy,
4218
- signal: dispatchAbortController.signal,
4219
- log: (m) => this.logInfo(m),
4220
- reasoningMode: primaryReasoningLevel,
4221
- onToolEvent: onAgentEvent ? (ev) => {
4222
- onAgentEvent({ stream: "tool", data: ev });
4223
- } : void 0,
4224
- providerAccelerationPlan: nativeContext.providerAccelerationPlan,
4225
- providerAccelerationCachePrefix: nativeContext.providerAccelerationCachePrefix
4226
- });
4227
- } catch (err) {
4228
- const message = err instanceof Error ? err.message : String(err);
4229
- const kind = classifyTurnTimeoutKind(err, {
4230
- signalAborted: dispatchAbortController.signal.aborted
4231
- });
4232
- const iteration = extractTurnMetricFromError(err, "iterations");
4233
- const lastToolName = extractLastToolNameFromError(err) ?? lastToolNameForInterruptedTurn;
4234
- const assistantPartialText = textStream.peekFinalAnswerText();
4235
- interruptedTurnFailure = {
4236
- kind,
4237
- error: err,
4238
- elapsedMs: Date.now() - dispatchStartAt,
4239
- ...typeof iteration === "number" ? { iteration } : {},
4240
- ...lastToolName ? { lastToolName } : {},
4241
- assistantPartialText
4242
- };
4243
- this.logWarn(
4244
- `[XKZOOM][native-reply-chain][anthropic-turn] failed session=${session.id} streamId=${streamId} policy=${toolChoicePolicy.kind} turn_timeout_kind=${kind} elapsedMs=${interruptedTurnFailure.elapsedMs} iteration=${iteration ?? -1} lastToolName=${lastToolName ?? "none"} visibleTextLength=${assistantPartialText.length} conversationId=${identity.conversationId ?? "none"} messageId=${userMessage.id} error=${message}`
4245
- );
4246
- nativeAnthropicDispatcher.sendFinalReply({
4247
- text: formatNativeAnthropicTurnUserMessage(err, kind),
4248
- contentType: "final",
4249
- madpVersion: 1
4250
- });
4251
- nativeAnthropicDispatcher.markComplete();
4252
- break;
4253
- }
4254
- if (turnResult.forcedButNoToolCall) {
4255
- this.logInfo(
4256
- `[XKZOOM][native-reply-chain][telemetry] forced_but_no_tool_call=1 session=${session.id} policy=${toolChoicePolicy.kind} model=${nativeAnthropicChatConfig.model} (\u5F3A\u5236\u6863\u672A\u751F\u6548\uFF1Aadapter \u964D\u7EA7 / \u6A21\u578B\u4ECD\u672A\u8C03\u5DE5\u5177 / provider \u4E0D\u652F\u6301)`
4257
- );
4258
- }
4259
- turnReasoningSignatureToPersist = turnResult.reasoningSignature;
4260
- } else {
4261
- await runNativeAnthropicMessagesStreamToDispatcher({
4262
- dispatcher: nativeAnthropicDispatcher,
4263
- chatConfig: nativeAnthropicChatConfig,
4264
- messages: nativeTranscriptMessages,
4265
- systemPrompt: nativeAnthropicSystemPrompt,
4266
- signal: dispatchAbortController.signal,
4267
- log: (m) => this.logInfo(m),
4268
- reasoningMode: primaryReasoningLevel,
4269
- providerAccelerationPlan: nativeContext.providerAccelerationPlan,
4270
- providerAccelerationCachePrefix: nativeContext.providerAccelerationCachePrefix
4271
- });
4272
- }
4273
- await Promise.all(nativeAnthropicDeliverPromises);
4274
- if (turnReasoningSignatureToPersist) {
4275
- this.store.setMessageReasoningSignature(
4276
- session.id,
4277
- streamId,
4278
- turnReasoningSignatureToPersist
4279
- );
3828
+ const nativeTurnResult = await runNativeDispatchTurn({
3829
+ route: nativeReplyRoute,
3830
+ dispatcher,
3831
+ transcriptMessages: nativeTranscriptMessages,
3832
+ ...nativeTranscriptBudget?.maxBytes !== void 0 ? { transcriptBudgetMaxBytes: nativeTranscriptBudget.maxBytes } : {},
3833
+ agentId: session.agentId,
3834
+ sessionId: session.id,
3835
+ streamId,
3836
+ userMessageId: userMessage.id,
3837
+ ...identity.conversationId ? { conversationId: identity.conversationId } : {},
3838
+ userText: inboundBodyForAgentDispatch,
3839
+ priorSessionMessageCount,
3840
+ ownedToolDeps: buildTurnOwnedToolDeps(session, inboundBodyForAgentDispatch, cfg),
3841
+ agentSnapshot: nativeAgentSnapshot,
3842
+ signal: dispatchAbortController.signal,
3843
+ dispatchStartAt,
3844
+ ...lastToolNameForInterruptedTurn ? { lastToolNameForInterruptedTurn } : {},
3845
+ reasoningMode: primaryReasoningLevel,
3846
+ buildRuntimeExtraContext: buildNativeRuntimeExtraContext,
3847
+ peekFinalAnswerText: () => textStream.peekFinalAnswerText(),
3848
+ logInfo: (m) => this.logInfo(m),
3849
+ logWarn: (m) => this.logWarn(m),
3850
+ ...onAgentEvent ? {
3851
+ onToolEvent: (ev) => {
3852
+ onAgentEvent({ stream: "tool", data: ev });
4280
3853
  }
4281
- break;
4282
- }
4283
- default: {
4284
- throw new Error(
4285
- `native-reply-chain: unhandled platform ${String(nativeReplyRoute.platform)}`
4286
- );
4287
- }
3854
+ } : {}
3855
+ });
3856
+ if (nativeTurnResult.interruptedFailure) {
3857
+ interruptedTurnFailure = nativeTurnResult.interruptedFailure;
3858
+ }
3859
+ if (nativeTurnResult.reasoningSignature) {
3860
+ this.store.setMessageReasoningSignature(
3861
+ session.id,
3862
+ streamId,
3863
+ nativeTurnResult.reasoningSignature
3864
+ );
4288
3865
  }
4289
3866
  } else if (!compactHandled) {
4290
3867
  if (process.env.XKZOOM_XRE_CORE === "1" && isMobileInbound && primaryReasoningLevel === "on") {
@@ -4293,7 +3870,8 @@ ${inbound.bodyText}` : inbound.bodyText;
4293
3870
  requestType: request.type,
4294
3871
  content: inboundBodyForAgentDispatch,
4295
3872
  hasInboundMedia: Boolean(inbound.mediaUrls && inbound.mediaUrls.length > 0),
4296
- hasResolvedUpload: Boolean(resolvedHttpUpload)
3873
+ hasResolvedUpload: Boolean(resolvedHttpUpload),
3874
+ allowNativeToolLoopOverride: nativeOwnedTurnOverridesHostToolLoop()
4297
3875
  });
4298
3876
  this.logInfo(
4299
3877
  `[XKZOOM] native-reply-chain missed session=${session.id} reason=${miss.reason} detail=${formatNativeReplyRouteMissMessage(miss)}` + (miss.reason === "gateway_tool_loop" ? " \u2192 dispatchInboundMessage (legacy tool loop)" : "")
@@ -4544,40 +4122,31 @@ ${inbound.bodyText}` : inbound.bodyText;
4544
4122
  response: abortPlaceholder
4545
4123
  };
4546
4124
  }
4547
- const lastAssist = [...replies].reverse().find((m) => !m.isSelf && (m.type === "text" || m.type === "code"));
4548
- const bucketVisible = !!(lastAssist?.answerContent?.trim() || lastAssist?.bodyContent?.trim() || lastAssist?.summaryContent?.trim());
4549
- const bridgeDeliveredThisRound = (this.lastOutboundBridgeDeliverAt.get(session.id) ?? 0) >= dispatchStartAt;
4550
- const hasVisibleAnswer = bucketVisible || bridgeDeliveredThisRound;
4551
- const noUserVisibleReply = primaryDispatchSucceeded && !hasVisibleAnswer;
4125
+ const finalizeState = resolveMobileDispatchFinalizeState({
4126
+ replies,
4127
+ primaryDispatchSucceeded,
4128
+ lastOutboundBridgeDeliverAt: this.lastOutboundBridgeDeliverAt.get(session.id),
4129
+ dispatchStartAt
4130
+ });
4552
4131
  void deliverTextChunks;
4553
- if (noUserVisibleReply) {
4132
+ if (finalizeState.noUserVisibleReply) {
4554
4133
  const liveTarget = this.resolveLiveReplyTarget(replyTarget, identity.conversationId);
4555
4134
  const errorTarget = liveTarget ?? replyTarget;
4556
- const errorDetails = {
4135
+ const errorDetails = buildNoUserVisibleReplyDetails({
4557
4136
  sessionId: session.id,
4558
4137
  clientMessageId: request.clientMessageId,
4559
4138
  serverMessageId: userMessage.id,
4560
4139
  streamId,
4561
- assistantRunId,
4562
- failureKind: "no_user_visible_reply"
4563
- };
4564
- const errorWsPayload = {
4565
- type: "error" /* ERROR */,
4566
- data: {
4567
- message: "\u672C\u8F6E\u6A21\u578B\u672A\u4EA7\u51FA\u5BF9\u7528\u6237\u7684\u56DE\u590D",
4568
- code: "agent_no_user_visible_reply",
4569
- retryable: false,
4570
- details: errorDetails
4571
- },
4572
- timestamp: (/* @__PURE__ */ new Date()).toISOString()
4573
- };
4140
+ assistantRunId
4141
+ });
4142
+ const errorWsPayload = buildNoUserVisibleReplyErrorPayload(errorDetails);
4574
4143
  const wsAny = this.websocket;
4575
4144
  if (errorTarget && typeof wsAny.sendError === "function") {
4576
4145
  try {
4577
4146
  wsAny.sendError(
4578
4147
  errorTarget,
4579
- "\u672C\u8F6E\u6A21\u578B\u672A\u4EA7\u51FA\u5BF9\u7528\u6237\u7684\u56DE\u590D",
4580
- "agent_no_user_visible_reply",
4148
+ NO_USER_VISIBLE_REPLY_MESSAGE,
4149
+ NO_USER_VISIBLE_REPLY_CODE,
4581
4150
  false,
4582
4151
  errorDetails
4583
4152
  );
@@ -4602,19 +4171,12 @@ ${inbound.bodyText}` : inbound.bodyText;
4602
4171
  );
4603
4172
  persistInterruptedTurnSnapshot({
4604
4173
  kind: "stream_empty",
4605
- error: new Error("no_user_visible_reply"),
4174
+ error: new Error(NO_USER_VISIBLE_REPLY_FAILURE_KIND),
4606
4175
  elapsedMs: Date.now() - dispatchStartAt,
4607
4176
  lastToolName: lastToolNameForInterruptedTurn,
4608
- assistantMessage: lastAssist ?? null
4177
+ assistantMessage: finalizeState.lastAssistant ?? null
4609
4178
  });
4610
- const placeholder = {
4611
- ...userMessage,
4612
- id: `${userMessage.id}-no-visible-reply-placeholder`,
4613
- isSelf: false,
4614
- status: "sent",
4615
- content: "",
4616
- type: "text"
4617
- };
4179
+ const placeholder = createNoUserVisibleReplyPlaceholder(userMessage);
4618
4180
  return {
4619
4181
  messageId: userMessage.id,
4620
4182
  response: placeholder
@@ -4622,19 +4184,11 @@ ${inbound.bodyText}` : inbound.bodyText;
4622
4184
  }
4623
4185
  const response = replies.at(-1);
4624
4186
  if (!response) {
4625
- const bridgeDeliveredAt = this.lastOutboundBridgeDeliverAt.get(session.id) ?? 0;
4626
- if (bridgeDeliveredAt >= dispatchStartAt) {
4187
+ if (finalizeState.bridgeDeliveredThisRound) {
4627
4188
  this.logInfo(
4628
4189
  `[XKZOOM] mobile dispatch: no dispatcher reply but outbound bridge delivered during window (session=${session.id})`
4629
4190
  );
4630
- const placeholder = {
4631
- ...userMessage,
4632
- id: `${userMessage.id}-bridge-placeholder`,
4633
- isSelf: false,
4634
- status: "sent",
4635
- content: "",
4636
- type: "text"
4637
- };
4191
+ const placeholder = createOutboundBridgeDeliveredPlaceholder(userMessage);
4638
4192
  return {
4639
4193
  messageId: userMessage.id,
4640
4194
  response: placeholder
@@ -4772,12 +4326,14 @@ ${inbound.bodyText}` : inbound.bodyText;
4772
4326
  const rawContent = typeof request.content === "string" ? request.content.trim() : "";
4773
4327
  const caption = typeof request.caption === "string" && request.caption.trim() ? request.caption.trim() : void 0;
4774
4328
  let persisted = null;
4775
- if ((type === "image" || type === "file") && isInlineUplinkDataBlobContent(rawContent)) {
4776
- throwInlineUplinkDeprecated({
4329
+ assertNoInlineDataBlobUplink({
4330
+ messageType: type,
4331
+ content: rawContent,
4332
+ details: {
4777
4333
  sessionId: request.sessionId,
4778
4334
  clientMessageId: request.clientMessageId
4779
- });
4780
- }
4335
+ }
4336
+ });
4781
4337
  if ((type === "image" || type === "file") && looksLikeXkzoomMediaRefV1(rawContent)) {
4782
4338
  const consumed = consumeInboundMobileUploadRef(rawContent);
4783
4339
  if (!consumed) {