nolo-cli 0.213.0 → 0.220.0

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 (271) hide show
  1. package/README.md +3 -2
  2. package/{_executeModel-CUJLCFWR.js → _executeModel-BNEMFCAO.js} +125 -96
  3. package/{accountResolver-4LKIHEKL.js → accountResolver-QETKNC7T.js} +4 -4
  4. package/{action-DF5UYSJF.js → action-GDZDXPMB.js} +14 -13
  5. package/{addContentAction-WERAONNY.js → addContentAction-7RO4AMRI.js} +21 -20
  6. package/{addDialogAgentAction-7VI7YRML.js → addDialogAgentAction-EVYBGTXB.js} +26 -25
  7. package/{agentDeleteCommand-XJORXPGU.js → agentDeleteCommand-7QTQNFCO.js} +145 -137
  8. package/{agentEmailCommands-XTYYFR6Z.js → agentEmailCommands-I7SHOSD6.js} +146 -139
  9. package/{agentFavoriteCommands-EDK743YA.js → agentFavoriteCommands-7LOP3HUD.js} +11 -12
  10. package/{agentGrantCommands-RQWK2TEV.js → agentGrantCommands-L6O2HVJI.js} +9 -9
  11. package/{agentListCommands-OBLRBLHS.js → agentListCommands-GUGMORTK.js} +180 -103
  12. package/{agentMachineCommands-5FMT3OT5.js → agentMachineCommands-UMDKILU3.js} +75 -66
  13. package/{agentProviderCommands-Q5O33MED.js → agentProviderCommands-STI3DQ6A.js} +8 -8
  14. package/{agentPullCommand-6EM3URVK.js → agentPullCommand-KHV4EELF.js} +11 -11
  15. package/agentRecordCommands-YTAMTHOY.js +175 -0
  16. package/agentRunCommand-DBM6YNO6.js +207 -0
  17. package/{agentRunControl-TAMHJQSR.js → agentRunControl-MBG4U6SL.js} +40 -19
  18. package/{agentRuntimeLocal-SOO2OPJG.js → agentRuntimeLocal-TU4LA353.js} +55 -48
  19. package/{agentSlice-CHR6KOZN.js → agentSlice-DPG7Q7IA.js} +24 -23
  20. package/{appDeleteCommands-GUP6P5YE.js → appDeleteCommands-JWP3XPUA.js} +67 -58
  21. package/{appDeployCommands-MH2FX4O5.js → appDeployCommands-6E4TQCWI.js} +67 -58
  22. package/{appDeployStatusCommands-SUHN3HPJ.js → appDeployStatusCommands-ALU4SADG.js} +67 -58
  23. package/{appGetCommands-YWDEX6Z4.js → appGetCommands-JEY4L6L4.js} +67 -58
  24. package/{appListCommands-ZQVMLPAY.js → appListCommands-PCAVHU7M.js} +67 -58
  25. package/{authCommand-PWX2ZNUP.js → authCommand-CGRIIOOV.js} +37 -33
  26. package/{authCommands-HV3EAU3V.js → authCommands-55OGQGCR.js} +16 -12
  27. package/{builtinSkillRegistry-2QETTQPM.js → builtinSkillRegistry-BAE2LDXF.js} +11 -13
  28. package/{chromeCommands-REEAH4SX.js → chromeCommands-G5UDKVSV.js} +3 -3
  29. package/{chromeOpsCommands-DIVM2K3T.js → chromeOpsCommands-WAA45NCS.js} +23 -13
  30. package/{chunk-VNYYOX3V.js → chunk-262R3XNN.js} +157 -50
  31. package/chunk-2MCB7CD7.js +98 -0
  32. package/{chunk-CTPXME7U.js → chunk-2NPD3FTX.js} +30 -7
  33. package/{chunk-YB3YZK56.js → chunk-2WZXXAQD.js} +1 -67
  34. package/{chunk-HRMJUN5J.js → chunk-2X7WFDT6.js} +1 -1
  35. package/chunk-2YGBI2XB.js +30 -0
  36. package/{chunk-TY3TIUJK.js → chunk-324FWHUA.js} +85 -3
  37. package/{chunk-KFLT5KAD.js → chunk-3NNXR7EH.js} +20 -20
  38. package/{chunk-ZRSNONOB.js → chunk-3P54D2E4.js} +8 -3
  39. package/{chunk-7OCO4TDT.js → chunk-3U44JB3O.js} +1 -1
  40. package/{chunk-TX5EYMGT.js → chunk-44J7Z5AQ.js} +34 -258
  41. package/chunk-4D4QD7FT.js +201 -0
  42. package/chunk-4I2MXV5Q.js +275 -0
  43. package/{chunk-MYOH447Z.js → chunk-4JVNURX4.js} +1 -1
  44. package/{chunk-COFEN36Z.js → chunk-4ZGPHFLE.js} +3 -3
  45. package/{chunk-ZXOUUDCG.js → chunk-53MFERZ3.js} +3869 -362
  46. package/chunk-547ENH5T.js +226 -0
  47. package/{chunk-YDH3FDFQ.js → chunk-5FUN7EG4.js} +1 -1
  48. package/{chunk-6DWMYIUY.js → chunk-5WKDR7HS.js} +14 -9
  49. package/chunk-5ZUOVCKT.js +32 -0
  50. package/{chunk-T43B7LB2.js → chunk-62HXNQVV.js} +1 -1
  51. package/{chunk-ZC3CMUKU.js → chunk-6OVNSQHN.js} +84 -2
  52. package/{chunk-IXNGOHV5.js → chunk-6QHKRARD.js} +12 -153
  53. package/{chunk-4T2WNOY7.js → chunk-6RDBLXVQ.js} +28 -17
  54. package/{chunk-EYLGAEB4.js → chunk-6XRPBZRS.js} +134 -0
  55. package/{chunk-KIM6CLW5.js → chunk-7JGMNKKG.js} +57 -26
  56. package/{chunk-P5L7CXOC.js → chunk-7Z6EW7AH.js} +3 -2
  57. package/chunk-AGYPUBFW.js +686 -0
  58. package/{chunk-Y63ZSOR6.js → chunk-AL3TYDIF.js} +1 -1
  59. package/{chunk-NOKUNJON.js → chunk-ALAES342.js} +75 -94
  60. package/{chunk-4I7ERB7F.js → chunk-ATEKLSLR.js} +2 -2
  61. package/{chunk-CRHOO2ZR.js → chunk-AUAJTAFM.js} +8 -8
  62. package/{chunk-LLRPJECG.js → chunk-AWIL6EHN.js} +15 -157
  63. package/chunk-BIDSIRTS.js +307 -0
  64. package/chunk-BIWI5M4E.js +62 -0
  65. package/{chunk-4VJAC32I.js → chunk-BNMPUQW6.js} +3 -2
  66. package/{chunk-RLBNLZVC.js → chunk-BP5ZJ6B4.js} +1 -1
  67. package/{chunk-NBTY7YJF.js → chunk-BR3GT6MR.js} +1 -0
  68. package/{chunk-7RFNTILS.js → chunk-BUDVRYES.js} +2 -2
  69. package/{chunk-SVYO6AO7.js → chunk-BV3FLP2L.js} +41 -1
  70. package/{chunk-ZL5RAEEB.js → chunk-CBUZ6DKA.js} +3 -3
  71. package/{chunk-SM3NSZJV.js → chunk-CD3RU7XL.js} +36 -2
  72. package/chunk-CMMI3DAT.js +1621 -0
  73. package/{chunk-J2NHJ7WX.js → chunk-CYWNWA77.js} +6 -6
  74. package/{chunk-MOIJOHA5.js → chunk-D6YNCNM6.js} +35 -21
  75. package/{chunk-H2TJUNCH.js → chunk-DBUR22G5.js} +16 -16
  76. package/chunk-DEA37IUY.js +271 -0
  77. package/{chunk-O2TZF4AI.js → chunk-DGYCDA6W.js} +4 -4
  78. package/{chunk-YWSEPJ7C.js → chunk-DUUDXSLX.js} +21 -7
  79. package/{chunk-KFHREHUQ.js → chunk-DXWGFL2Z.js} +89 -1
  80. package/{chunk-H5HF7TJA.js → chunk-EEOOBRA7.js} +6 -6
  81. package/{chunk-Y6ORVLSS.js → chunk-EVGU5P4U.js} +1 -1
  82. package/chunk-EWQ3HGNZ.js +90 -0
  83. package/{chunk-6VLJ6YA7.js → chunk-F6Z6ZCUV.js} +9 -9
  84. package/{chunk-75XIDFBW.js → chunk-FJ23FZXF.js} +72 -28
  85. package/chunk-FJSNBZXR.js +142 -0
  86. package/{chunk-WRYQ35LQ.js → chunk-G7IUT2V3.js} +860 -57
  87. package/{chunk-PCLE46CE.js → chunk-GBWGPTA7.js} +2 -1
  88. package/{chunk-H7PPIYWP.js → chunk-GPOV42YM.js} +19 -19
  89. package/{chunk-W4S457LU.js → chunk-GUXZK7SE.js} +42 -6
  90. package/{chunk-QHPRUL4O.js → chunk-GV6PRJBU.js} +4 -4
  91. package/{chunk-YUA6OAH5.js → chunk-HBRDSQ3M.js} +2 -2
  92. package/{chunk-G7MLNNEX.js → chunk-HHFGE2WF.js} +7 -7
  93. package/{chunk-OQPKUBPB.js → chunk-HSSBDZLD.js} +19 -7
  94. package/{chunk-EHSZD5OI.js → chunk-HXER7YJF.js} +4 -4
  95. package/{chunk-TAKB25RM.js → chunk-HYLRQDEE.js} +6 -6
  96. package/{chunk-LOEO7LRC.js → chunk-ILHQ2AXT.js} +10 -8
  97. package/{chunk-BBJ22CLB.js → chunk-JJMR2EA3.js} +64 -34
  98. package/{chunk-G2BQWAVT.js → chunk-JLAMNSBC.js} +4 -4
  99. package/{chunk-RSHTSUEG.js → chunk-JUSHVFNF.js} +2133 -622
  100. package/{chunk-YJAFKXMU.js → chunk-KHVFJSVE.js} +54 -49
  101. package/{chunk-X7SDOJUM.js → chunk-KRI6N5QZ.js} +16 -16
  102. package/{chunk-7BT37FK3.js → chunk-L32W3PRP.js} +675 -128
  103. package/chunk-LKA64WH4.js +227 -0
  104. package/{chunk-HUBHAQK2.js → chunk-LMRRCEDE.js} +31 -31
  105. package/chunk-M4SFKP5L.js +675 -0
  106. package/{chunk-MDB67IWP.js → chunk-MSMHU36U.js} +12 -12
  107. package/{chunk-7Y4YTDQF.js → chunk-MXKWTPUM.js} +288 -166
  108. package/{chunk-WYDI6TGM.js → chunk-MXRUXMZ3.js} +94 -135
  109. package/{chunk-AZMYUSVF.js → chunk-N5Z2V73W.js} +1 -1
  110. package/{chunk-QG4AOSON.js → chunk-NHY322ZU.js} +154 -32
  111. package/{chunk-UHJGXRJ4.js → chunk-OBIC6EG7.js} +6 -6
  112. package/{chunk-GOO6G4PY.js → chunk-OBSEKCVK.js} +123 -70
  113. package/{chunk-WMTBPBMP.js → chunk-OG6MQOQG.js} +130 -60
  114. package/{chunk-XJWWBO34.js → chunk-OJKUU3LP.js} +5 -7
  115. package/{chunk-ALQ3657A.js → chunk-OOJNQK6V.js} +21 -1
  116. package/{chunk-NSAPDIN2.js → chunk-OWKNSIXL.js} +679 -74
  117. package/{chunk-6XIE5ZGI.js → chunk-PDCV7P5W.js} +1 -1
  118. package/{chunk-A7TFUNZO.js → chunk-PPJYZRSQ.js} +6 -2
  119. package/{chunk-F6UUQOG6.js → chunk-Q3IVPFVO.js} +4 -4
  120. package/{chunk-VO4WSAVP.js → chunk-QBZCGP34.js} +3 -3
  121. package/chunk-QCB42576.js +13 -0
  122. package/chunk-QHEN7NZ7.js +46 -0
  123. package/{chunk-3UKL3HPD.js → chunk-QJTZ76CP.js} +32 -84
  124. package/{chunk-V5Y3R6BT.js → chunk-QRGDJA4B.js} +215 -212
  125. package/{chunk-4KB6WQUL.js → chunk-QYB23WUH.js} +1 -1
  126. package/{chunk-ZNWI6OVT.js → chunk-R44TU3MZ.js} +85 -11
  127. package/{chunk-PYRUW7XN.js → chunk-R6Z5S5GA.js} +139 -57
  128. package/{chunk-VL5KOY2C.js → chunk-R7XWZDOH.js} +125 -29
  129. package/{chunk-R5O4QAWG.js → chunk-RBPUNSG5.js} +11 -77
  130. package/{chunk-NJLL224W.js → chunk-RG2DGNL6.js} +3 -3
  131. package/{chunk-C6KNNXWU.js → chunk-RGQ4UUWZ.js} +25 -2
  132. package/{chunk-TCZHTTUU.js → chunk-RTHFJZ6M.js} +11 -11
  133. package/{chunk-RZOV7OMV.js → chunk-RYOLWYBK.js} +146 -200
  134. package/{chunk-OWYYDMGJ.js → chunk-S2NTVGA2.js} +4 -2
  135. package/{chunk-XHQC4PXX.js → chunk-S5NA3C52.js} +488 -226
  136. package/{secretCommands-LXDWOLZ6.js → chunk-S6FDXXZV.js} +190 -15
  137. package/chunk-S6K5F3KP.js +99 -0
  138. package/{chunk-INN4LTAJ.js → chunk-SRCCSTIM.js} +8 -8
  139. package/{chunk-JY5NGFFH.js → chunk-SYTHYBMI.js} +5 -5
  140. package/{chunk-UYD5HQ6T.js → chunk-SZVMASJ2.js} +3300 -1396
  141. package/{chunk-FUGMREBO.js → chunk-TGNIKIHR.js} +3 -3
  142. package/{chunk-HPFCI4SK.js → chunk-TI2EPRHE.js} +4 -4
  143. package/chunk-TLE77UJ5.js +230 -0
  144. package/chunk-TSPMLCWI.js +364 -0
  145. package/{chunk-YGILMZ7N.js → chunk-TUSTONB3.js} +1 -1
  146. package/{chunk-4VNS5WPM.js → chunk-U67V476Y.js} +1 -8
  147. package/{chunk-F7CI2ZC5.js → chunk-UAIHKQIA.js} +2 -1
  148. package/{chunk-WPORQFYN.js → chunk-UVLYNWIE.js} +2 -2
  149. package/{chunk-H4UOTUOX.js → chunk-VMJVAJ6W.js} +152 -19
  150. package/{chunk-KC4XDTT3.js → chunk-VS276URX.js} +4 -4
  151. package/{chunk-YTF4WH7J.js → chunk-WWTSEBDF.js} +1 -1
  152. package/{chunk-E2BESSAW.js → chunk-X4O7FJF5.js} +2 -0
  153. package/{chunk-RPQXPZZF.js → chunk-XSW4EXQV.js} +976 -17
  154. package/{chunk-7QTZCMKL.js → chunk-XTETTSKN.js} +3036 -2468
  155. package/{chunk-J5JTMQIA.js → chunk-YFLVRVYK.js} +1 -1
  156. package/chunk-YKY4OVOX.js +1141 -0
  157. package/{chunk-MMA3LZ3W.js → chunk-YNIYE47Z.js} +1 -1
  158. package/chunk-YZMNK53S.js +68 -0
  159. package/{chunk-FY7F4Q6X.js → chunk-Z4PCXPUE.js} +2 -2
  160. package/{chunk-INUFILG6.js → chunk-ZH3KXFHS.js} +11 -3
  161. package/chunk-ZOHO6MOF.js +376 -0
  162. package/{cliAgentConfigHelpers-WJBZQTLW.js → cliAgentConfigHelpers-BTRHMPW2.js} +18 -19
  163. package/{cliAuthorityBrokerClient-PM3U6Q6J.js → cliAuthorityBrokerClient-XHH7MH2P.js} +1 -1
  164. package/{cliAuthorityStoreDriver-TKLXNNTG.js → cliAuthorityStoreDriver-6FE3BJNB.js} +1 -1
  165. package/{cliEnvHelpers-BVYTMUPJ.js → cliEnvHelpers-CNMP3RDX.js} +3 -3
  166. package/{cliExecutor-BWBF2MTI.js → cliExecutor-K6FDZTQ2.js} +4 -2
  167. package/cliLocalAgentRecordReader-M3F76NIP.js +90 -0
  168. package/{commandRegistry-W63CYRZJ.js → commandRegistry-T3UBK6OA.js} +105 -97
  169. package/{contentThunks-U7PL5MQD.js → contentThunks-YEPZAHXU.js} +53 -48
  170. package/{cooldownCommands-TIGUHXTD.js → cooldownCommands-YB5H5BBK.js} +5 -4
  171. package/{createAgentAutomationAction-OLBQDD6R.js → createAgentAutomationAction-TBIIO5WT.js} +51 -48
  172. package/{createDialogAction-SVH6B3SB.js → createDialogAction-KBKMYFTQ.js} +52 -53
  173. package/{createPageAction-F4DIWZ2Z.js → createPageAction-3FGAPLJO.js} +56 -53
  174. package/{cursorProvider-YGGNMVWX.js → cursorProvider-2RACMEMF.js} +1 -1
  175. package/{db-HUCI5R4G.js → db-M7FU2GNK.js} +10 -7
  176. package/{dbSlice-BVH2YZPQ.js → dbSlice-XRUZOGSU.js} +20 -19
  177. package/{deleteFile-5YOEKV4U.js → deleteFile-6URDHYRB.js} +12 -12
  178. package/{desktopFolderProjects-SFY5EZS3.js → desktopFolderProjects-4POAMVJN.js} +2 -2
  179. package/{dialogCommands-KHIEPY3M.js → dialogCommands-NRLCOPJR.js} +71 -64
  180. package/dialogNotifyCommand-SHGPCU22.js +36 -0
  181. package/{dialogSlice-ZCTDV2PZ.js → dialogSlice-DP2WTMNO.js} +48 -45
  182. package/{dialogUsageCommand-7KCPYGHG.js → dialogUsageCommand-W2WCSGKF.js} +11 -10
  183. package/{docCreateCommands-DPMZI7G5.js → docCreateCommands-YJRDA3RX.js} +66 -59
  184. package/{docDeleteCommands-IRQQLUBT.js → docDeleteCommands-A5QIHZNF.js} +69 -62
  185. package/{docReadCommands-LK37XH6L.js → docReadCommands-CF2LTMYH.js} +66 -59
  186. package/{docStore-V2KECILA.js → docStore-NDY3K3PK.js} +25 -24
  187. package/{docUpdateCommands-O6T3HJHH.js → docUpdateCommands-QRKV4ZXE.js} +69 -62
  188. package/{fetchMessages-NR4KNQLO.js → fetchMessages-TQEUZD7H.js} +8 -7
  189. package/{getPricing-2MNMXEVG.js → getPricing-LF5C4XSI.js} +7 -7
  190. package/{handleSendMessageAction-2PE25WM3.js → handleSendMessageAction-IUGVVJ43.js} +206 -314
  191. package/{hostCredentialCreate-S233UMAP.js → hostCredentialCreate-X2ZFRXDR.js} +132 -124
  192. package/index.js +65 -27
  193. package/{keys-BEGDOTRL.js → keys-RWF7UCB4.js} +5 -4
  194. package/legacyMigration-TF4SYJCZ.js +19 -0
  195. package/{lib-5KKIBFIT.js → lib-OT5OTXRU.js} +7087 -6664
  196. package/{localDialogRead-7NNDVVF7.js → localDialogRead-CCOCVGAP.js} +3 -3
  197. package/{localFirstLog-DHNOY2NA.js → localFirstLog-OIETGK66.js} +1 -1
  198. package/localRecall-BDYKXB46.js +17 -0
  199. package/{localRuntimeAdapter-KY6WXNBR.js → localRuntimeAdapter-KAG3T4LF.js} +138 -130
  200. package/{localRuntimeAuthority-OYH4AE4G.js → localRuntimeAuthority-IBJAT62G.js} +1 -1
  201. package/{localRuntimeDb-VBIMCWUC.js → localRuntimeDb-N7KHDXS2.js} +2 -2
  202. package/{machineCommands-Q6HA3IXF.js → machineCommands-6NIQJE2A.js} +143 -135
  203. package/{machineInfo-UKPTZO5Y.js → machineInfo-LWHTEBHJ.js} +1 -1
  204. package/machineWsRunDispatch-RA5NOSGG.js +190 -0
  205. package/{memberThunks-7EDJADWU.js → memberThunks-7Y3OYSJQ.js} +30 -29
  206. package/{memoryCommands-ASCE5STX.js → memoryCommands-BC6REPQB.js} +7 -7
  207. package/models-H5NNZRLH.js +9 -0
  208. package/{oauthTokenStore-OEERZFUC.js → oauthTokenStore-RUYNYALS.js} +1 -1
  209. package/{offlineMarxistsAgentCommand-2QTHJCHV.js → offlineMarxistsAgentCommand-XVXUE6G5.js} +6 -6
  210. package/overlay-BBQZXGYI.js +13 -0
  211. package/package.json +2 -2
  212. package/{pdf-U6KSUEZZ.js → pdf-KE3QI2V7.js} +1 -1
  213. package/{processSpawn-ZU5QFM43.js → processSpawn-6GEO77KV.js} +1 -1
  214. package/{profileConfig-KN3N2BLF.js → profileConfig-KOWK4HOG.js} +1 -1
  215. package/{projectArchive-DRTDIMEV.js → projectArchive-OIUP63MV.js} +59 -56
  216. package/{providerPresetApply-YXGV6NXB.js → providerPresetApply-WHAMP2D5.js} +20 -13
  217. package/{providerRegistry-S6UL6UNA.js → providerRegistry-ZI2KORJ7.js} +11 -11
  218. package/{read-4V2RMG7N.js → read-TYMBGEXO.js} +13 -13
  219. package/{readDocTool-BH6ATGQO.js → readDocTool-SKQVHBLO.js} +2 -2
  220. package/{readlineWorkspace-2W4WRCOU.js → readlineWorkspace-ZGC4KSXG.js} +7760 -6499
  221. package/{removeDialogAgentAction-LYAZGNKW.js → removeDialogAgentAction-F5QE2O2B.js} +29 -28
  222. package/{runAgentClientLoop-J2VQBS2Z.js → runAgentClientLoop-NKUW2DSJ.js} +94 -88
  223. package/{runtimeDoctorCommands-QAI3MBKQ.js → runtimeDoctorCommands-RRKPBGVO.js} +19 -19
  224. package/{runtimeModeArgs-2Y7BALTO.js → runtimeModeArgs-X7DL7PUN.js} +1 -1
  225. package/secretCommands-KZWBZIYS.js +24 -0
  226. package/{setDialogExtraReferencesAction-OCRPGPYH.js → setDialogExtraReferencesAction-72L27ERM.js} +25 -24
  227. package/{setPrimaryDialogAgentAction-HFJDQIBU.js → setPrimaryDialogAgentAction-GJJDUSGJ.js} +29 -28
  228. package/{settingThunks-RAMHMTGM.js → settingThunks-ZRGWVGZD.js} +99 -90
  229. package/{skillDiscovery-XKHROSH2.js → skillDiscovery-I37M5KJC.js} +4 -4
  230. package/{skillSummaryMarker-42HKSXYY.js → skillSummaryMarker-62UW7HI7.js} +1 -1
  231. package/{slateToRenderMarkdown-Y5IYN73U.js → slateToRenderMarkdown-R3X74MCX.js} +1 -1
  232. package/{slateUtils-NGV2NMKM.js → slateUtils-ESQAJ6RN.js} +1 -1
  233. package/{spaceCommands-KVJZVKVO.js → spaceCommands-MEH3HJBC.js} +66 -57
  234. package/store-Z53ICFL3.js +48 -0
  235. package/{streamAgentChatTurn-GHBMJJ6S.js → streamAgentChatTurn-FJTUUXHJ.js} +886 -668
  236. package/{switchDialogAgentAction-EBRMW3RA.js → switchDialogAgentAction-IIJBPND3.js} +26 -25
  237. package/{tableCommands-MP6VFSVT.js → tableCommands-FTAOCBTX.js} +13 -13
  238. package/tombstones-FQQMEDOW.js +32 -0
  239. package/{toolApiClient-HGNO53TC.js → toolApiClient-OGQEBQVX.js} +4 -4
  240. package/{tools-EWKCPKMS.js → tools-ZXHIAOSP.js} +82 -81
  241. package/tuiRestart-2IL37YIB.js +41 -0
  242. package/tuiSummaryLlmCaller-W2QN4VAC.js +44 -0
  243. package/{updateCommands-ZQYU6SCI.js → updateCommands-CPATDG6J.js} +11 -7
  244. package/{updateDialogTitleAction-5GGMBTDF.js → updateDialogTitleAction-JMKLKL4P.js} +54 -51
  245. package/{usageCommand-F4IPVMIZ.js → usageCommand-2BF74MKF.js} +11 -10
  246. package/{usageRebuildCommand-HAW2AD5N.js → usageRebuildCommand-UHB55BQM.js} +12 -11
  247. package/userDataMerge-HT2ZVHBJ.js +13 -0
  248. package/{windowsSelfUpdate-257DV2T6.js → windowsSelfUpdate-ZFD6J5HF.js} +3 -3
  249. package/{workloadLifecycle-4C42SVBD.js → workloadLifecycle-HFJIN5IZ.js} +4 -4
  250. package/agentRecordCommands-ZQ7SVYGG.js +0 -167
  251. package/agentRunCommand-WS7IGO2W.js +0 -196
  252. package/chunk-3CGG2PAL.js +0 -594
  253. package/chunk-5MQRBSMW.js +0 -862
  254. package/chunk-5XBUWM6I.js +0 -89
  255. package/chunk-CJEIOP3E.js +0 -0
  256. package/chunk-EHGEOAHI.js +0 -636
  257. package/chunk-FW6YHHLI.js +0 -842
  258. package/chunk-GPVRUGGY.js +0 -115
  259. package/chunk-HSVBJRF4.js +0 -339
  260. package/chunk-LEC5ALIN.js +0 -91
  261. package/chunk-WACI5I6V.js +0 -147
  262. package/chunk-WJZOQR2J.js +0 -151
  263. package/chunk-ZCWRMUWT.js +0 -89
  264. package/dist-M676ULYG.js +0 -7314
  265. package/machineWsRunDispatch-WWJQ6WR3.js +0 -182
  266. package/models-PJBE6JDV.js +0 -9
  267. package/tuiSummaryLlmCaller-ALQYUUWB.js +0 -189
  268. package/{chunk-AGP3YSEC.js → chunk-4N6G2CKP.js} +3 -3
  269. package/{chunk-BLVSFYQ3.js → chunk-LISC7BD4.js} +3 -3
  270. package/{chunk-2QHFH3DR.js → chunk-USGHJSGO.js} +3 -3
  271. package/{chunk-AETZ7AD6.js → chunk-W6RFEDN4.js} +3 -3
@@ -1,10 +1,29 @@
1
- import {
2
- applyPublicAgentCatalogOverride
3
- } from "./chunk-H2TJUNCH.js";
4
1
  import {
5
2
  buildCliPrompt
6
3
  } from "./chunk-ATNTHIZI.js";
7
4
  import {
5
+ applyImageConfigRuntimeOverride,
6
+ buildDynamicContexts,
7
+ buildForegroundTurnAdmissionFetchInit,
8
+ buildStaticContexts,
9
+ compressOldToolResults,
10
+ consumeAgentRunStream,
11
+ mergeAgentToolsWithRuntime,
12
+ mergeContexts,
13
+ projectDesktopToolUiContent,
14
+ pushGate,
15
+ resolveImageGenerationStreamingState,
16
+ resolveTurnToolContext,
17
+ targetForRunKind,
18
+ validateAccessAndBalance,
19
+ withRequestContextBlocks
20
+ } from "./chunk-MXRUXMZ3.js";
21
+ import {
22
+ resolveUserSkillRuntime
23
+ } from "./chunk-R44TU3MZ.js";
24
+ import {
25
+ buildEmptyCompletionRepairBody,
26
+ buildFinalCompletionsRequestBody,
8
27
  deliverHtmlArtifactToolResult,
9
28
  filterAndCleanMessages,
10
29
  handleToolCalls,
@@ -12,12 +31,15 @@ import {
12
31
  readStreamChunk,
13
32
  sendOpenAICompletionsRequest,
14
33
  updateTotalUsage
15
- } from "./chunk-YJAFKXMU.js";
34
+ } from "./chunk-KHVFJSVE.js";
16
35
  import "./chunk-JEXVIMYZ.js";
17
36
  import {
18
- prepareTools
19
- } from "./chunk-G2BQWAVT.js";
37
+ inlineImageUrlsForCustomProvider,
38
+ prepareTools,
39
+ shouldInlineImageUrlsForAgent
40
+ } from "./chunk-JLAMNSBC.js";
20
41
  import {
42
+ DirectApiKeyResolutionError,
21
43
  INVALID_TOOL_ARGS_REPLACEMENT,
22
44
  buildInvalidToolCallSelfHealResult,
23
45
  generateRequestBody,
@@ -27,259 +49,249 @@ import {
27
49
  sanitizeOutboundResponsesInput,
28
50
  selectResponsesConversationState,
29
51
  updateResponsesConversationState
30
- } from "./chunk-BBJ22CLB.js";
52
+ } from "./chunk-JJMR2EA3.js";
31
53
  import "./chunk-HS7MLR74.js";
32
- import "./chunk-XHQC4PXX.js";
33
- import "./chunk-KFHREHUQ.js";
34
- import {
35
- isOwnedAgentRecord,
36
- resolveBillingSource
37
- } from "./chunk-QG4AOSON.js";
38
- import "./chunk-PCLE46CE.js";
39
- import "./chunk-IXNGOHV5.js";
40
- import "./chunk-75XIDFBW.js";
41
- import {
42
- applyImageConfigRuntimeOverride,
43
- buildDynamicContexts,
44
- buildForegroundTurnAdmissionFetchInit,
45
- buildStaticContexts,
46
- compressOldToolResults,
47
- consumeAgentRunStream,
48
- mergeAgentToolsWithRuntime,
49
- mergeContexts,
50
- projectDesktopToolUiContent,
51
- resolveImageGenerationStreamingState,
52
- resolveTurnToolContext,
53
- trimMessagesWithSummary,
54
- validateAccessAndBalance,
55
- withRequestContextBlocks
56
- } from "./chunk-WYDI6TGM.js";
54
+ import "./chunk-S5NA3C52.js";
57
55
  import {
58
- resolveUserSkillRuntime
59
- } from "./chunk-ZNWI6OVT.js";
56
+ isGptProModel,
57
+ isPlatformPaidAgentCall,
58
+ shouldBlockForGptPro
59
+ } from "./chunk-NHY322ZU.js";
60
+ import "./chunk-6QHKRARD.js";
60
61
  import {
61
- isContextOverflowText,
62
- parseApiError,
63
62
  performServerProxyFetchWithRetry
64
- } from "./chunk-TX5EYMGT.js";
63
+ } from "./chunk-44J7Z5AQ.js";
65
64
  import {
66
65
  createSSEParser,
67
66
  selectMaxExecutionTime,
68
67
  waitForAbortableDelay
69
- } from "./chunk-HUBHAQK2.js";
68
+ } from "./chunk-LMRRCEDE.js";
70
69
  import "./chunk-NF64D32W.js";
71
- import "./chunk-3L2WKC3W.js";
72
- import "./chunk-R5O4QAWG.js";
73
- import "./chunk-6DWMYIUY.js";
74
- import "./chunk-MYOH447Z.js";
75
- import "./chunk-VF4K2QE6.js";
76
- import "./chunk-TAKB25RM.js";
77
- import "./chunk-RLBNLZVC.js";
70
+ import "./chunk-RBPUNSG5.js";
71
+ import "./chunk-4JVNURX4.js";
72
+ import "./chunk-HYLRQDEE.js";
73
+ import "./chunk-BP5ZJ6B4.js";
74
+ import "./chunk-FJ23FZXF.js";
78
75
  import "./chunk-AGIM7IMJ.js";
79
- import "./chunk-INN4LTAJ.js";
80
- import {
81
- getPublicImageAgentDefaultProfile,
82
- getPublicImageAgentMode
83
- } from "./chunk-VIDPVFP3.js";
84
76
  import "./chunk-63W5N6P3.js";
85
- import "./chunk-LLRPJECG.js";
86
- import "./chunk-7Y4YTDQF.js";
77
+ import "./chunk-VF4K2QE6.js";
78
+ import "./chunk-5WKDR7HS.js";
79
+ import "./chunk-AWIL6EHN.js";
80
+ import "./chunk-MXKWTPUM.js";
81
+ import {
82
+ getCurrentSpaceId
83
+ } from "./chunk-547ENH5T.js";
87
84
  import {
88
85
  addToolMessage,
89
86
  addUserMessage,
90
- applyBuiltinAgentRuntimeOverride,
87
+ admitPendingUserMessages,
88
+ createUserBatchExecution,
91
89
  estimateMissingUsage,
92
90
  finalizeTransientMessageOnError,
93
91
  messageStreamEnd,
94
92
  messageStreaming,
95
93
  prepareAndPersistUserMessage,
96
94
  removeTransientMessage,
97
- resolveBuiltinPlatformAgentRecord,
95
+ runPendingUserBatchRequest,
96
+ selectAdmittedMessages,
98
97
  selectAllMsgs,
99
98
  selectCurrentDialogConfig,
100
99
  selectDialogConfigByKey,
100
+ snapshotUserBatchInput,
101
101
  toast,
102
+ updateDialogSummaryAction,
102
103
  updateTokens,
103
104
  updateToolMessage
104
- } from "./chunk-ZXOUUDCG.js";
105
+ } from "./chunk-53MFERZ3.js";
105
106
  import "./chunk-TZXPT53C.js";
106
- import "./chunk-7RFNTILS.js";
107
- import "./chunk-LEC5ALIN.js";
107
+ import "./chunk-BUDVRYES.js";
108
108
  import "./chunk-523DITKR.js";
109
- import "./chunk-KFLT5KAD.js";
110
- import {
111
- getCurrentSpaceId
112
- } from "./chunk-5XBUWM6I.js";
109
+ import "./chunk-3NNXR7EH.js";
113
110
  import "./chunk-BYXBJQAS.js";
114
111
  import "./chunk-QYPE3TS3.js";
115
112
  import {
116
113
  createCliChatTurnStream,
117
114
  getCliChatSession,
118
115
  startCliChatSession
119
- } from "./chunk-NJLL224W.js";
120
- import "./chunk-4JH2UMJR.js";
121
- import "./chunk-GPVRUGGY.js";
122
- import "./chunk-UAD2WT54.js";
116
+ } from "./chunk-RG2DGNL6.js";
123
117
  import "./chunk-5RGU3J7P.js";
124
- import "./chunk-WPORQFYN.js";
125
- import "./chunk-MMA3LZ3W.js";
126
118
  import {
127
119
  addActiveController,
128
120
  claimDialogTurnPhase,
129
121
  clearDialogTurnPhase,
130
122
  clearPendingUserInputQueue,
131
123
  dequeueUserInput,
124
+ getDialogRuntimeState,
132
125
  removeActiveController,
133
126
  selectActiveControllers,
134
127
  selectPendingUserInputQueue,
135
128
  setDialogTurnPhase,
129
+ subscribe,
136
130
  tokenUsageLiveUpdate
137
- } from "./chunk-OWYYDMGJ.js";
138
- import "./chunk-YDH3FDFQ.js";
139
- import "./chunk-HPFCI4SK.js";
131
+ } from "./chunk-S2NTVGA2.js";
132
+ import "./chunk-UVLYNWIE.js";
133
+ import "./chunk-YNIYE47Z.js";
134
+ import "./chunk-5FUN7EG4.js";
135
+ import "./chunk-5ZUOVCKT.js";
136
+ import "./chunk-DXWGFL2Z.js";
137
+ import "./chunk-3L2WKC3W.js";
138
+ import "./chunk-TI2EPRHE.js";
140
139
  import {
141
140
  selectCurrentServer
142
- } from "./chunk-4I7ERB7F.js";
141
+ } from "./chunk-ATEKLSLR.js";
142
+ import "./chunk-DEA37IUY.js";
143
+ import "./chunk-UAD2WT54.js";
143
144
  import {
144
145
  patch,
145
146
  read,
146
147
  selectById,
147
148
  write
148
- } from "./chunk-FW6YHHLI.js";
149
+ } from "./chunk-CMMI3DAT.js";
149
150
  import "./chunk-3PVYUPXK.js";
150
- import "./chunk-COFEN36Z.js";
151
- import "./chunk-O2TZF4AI.js";
151
+ import "./chunk-DGYCDA6W.js";
152
+ import "./chunk-4ZGPHFLE.js";
152
153
  import {
153
154
  selectRuntimeCurrentServer
154
- } from "./chunk-PYRUW7XN.js";
155
+ } from "./chunk-R6Z5S5GA.js";
155
156
  import "./chunk-UEILX4EV.js";
156
- import "./chunk-P5L7CXOC.js";
157
+ import "./chunk-7Z6EW7AH.js";
157
158
  import {
158
159
  getIsDesktopApp
159
- } from "./chunk-AGP3YSEC.js";
160
- import "./chunk-QQ56R7KS.js";
161
- import "./chunk-OW765XBU.js";
160
+ } from "./chunk-4N6G2CKP.js";
162
161
  import {
163
162
  selectIdentityToken,
164
163
  selectIdentityUser,
165
164
  selectIdentityUserId
166
165
  } from "./chunk-PXYBUFDB.js";
167
- import "./chunk-EHSZD5OI.js";
168
- import "./chunk-SVYO6AO7.js";
169
- import "./chunk-WRYQ35LQ.js";
170
- import "./chunk-EHGEOAHI.js";
171
- import "./chunk-AETZ7AD6.js";
172
- import "./chunk-Y6ORVLSS.js";
173
- import "./chunk-KHCLMKZZ.js";
166
+ import "./chunk-QQ56R7KS.js";
167
+ import "./chunk-GBWGPTA7.js";
168
+ import "./chunk-OOJNQK6V.js";
169
+ import "./chunk-HXER7YJF.js";
170
+ import "./chunk-BV3FLP2L.js";
171
+ import {
172
+ applyPublicAgentCatalogOverride
173
+ } from "./chunk-DBUR22G5.js";
174
+ import {
175
+ applyBuiltinAgentRuntimeOverride,
176
+ resolveBuiltinPlatformAgentRecord
177
+ } from "./chunk-S6K5F3KP.js";
178
+ import "./chunk-SRCCSTIM.js";
179
+ import {
180
+ getPublicImageAgentDefaultProfile,
181
+ getPublicImageAgentMode
182
+ } from "./chunk-VIDPVFP3.js";
183
+ import "./chunk-4JH2UMJR.js";
174
184
  import {
175
185
  assertDesktopAgentRuntimeTurnBodyHasNoRawSecrets,
176
186
  buildDesktopAgentRuntimeAgentConfigSnapshot,
177
187
  buildDesktopAgentRuntimeDialogHistorySnapshot,
188
+ evaluateRequestBudget,
178
189
  extractImageUrlsFromMessages,
179
190
  stripImagePartsForTextOnlyAgent
180
- } from "./chunk-W4S457LU.js";
191
+ } from "./chunk-GUXZK7SE.js";
192
+ import "./chunk-2WZXXAQD.js";
193
+ import "./chunk-DUUDXSLX.js";
181
194
  import {
182
195
  projectUserPartForModel
183
- } from "./chunk-4KB6WQUL.js";
196
+ } from "./chunk-QYB23WUH.js";
184
197
  import "./chunk-56GBUMO5.js";
185
- import {
186
- isGptProModel,
187
- shouldBlockForGptPro
188
- } from "./chunk-5MQRBSMW.js";
198
+ import "./chunk-AGYPUBFW.js";
189
199
  import {
190
200
  extractImagePartsFromResponseOutput,
191
201
  extractTextFromResponseOutput,
192
202
  toResponsesTools
193
- } from "./chunk-H5HF7TJA.js";
194
- import "./chunk-E2BESSAW.js";
195
- import "./chunk-RZOV7OMV.js";
196
- import "./chunk-3UKL3HPD.js";
203
+ } from "./chunk-EEOOBRA7.js";
204
+ import "./chunk-X4O7FJF5.js";
205
+ import "./chunk-RYOLWYBK.js";
206
+ import "./chunk-QJTZ76CP.js";
197
207
  import {
198
208
  resolveRuntimeToolSurfaceForAgent
199
- } from "./chunk-KC4XDTT3.js";
200
- import "./chunk-YB3YZK56.js";
201
- import "./chunk-YWSEPJ7C.js";
202
- import "./chunk-WJZOQR2J.js";
209
+ } from "./chunk-VS276URX.js";
210
+ import {
211
+ isContextOverflowText,
212
+ parseApiError
213
+ } from "./chunk-TLE77UJ5.js";
203
214
  import {
204
215
  resolveAgentCallPlan,
205
216
  resolveClientWire
206
- } from "./chunk-UHJGXRJ4.js";
217
+ } from "./chunk-OBIC6EG7.js";
218
+ import "./chunk-FJSNBZXR.js";
207
219
  import {
208
220
  resolveAgentContextWindow
209
- } from "./chunk-V5Y3R6BT.js";
221
+ } from "./chunk-QRGDJA4B.js";
222
+ import "./chunk-5ZUL4CUO.js";
210
223
  import {
211
224
  getModelInfo
212
- } from "./chunk-7BT37FK3.js";
225
+ } from "./chunk-L32W3PRP.js";
213
226
  import "./chunk-H57T64RA.js";
214
- import "./chunk-5ZUL4CUO.js";
215
- import {
216
- isOAuthApiKeyRef
217
- } from "./chunk-UKZX3NHN.js";
227
+ import "./chunk-UKZX3NHN.js";
218
228
  import "./chunk-5MMAK75Q.js";
219
- import "./chunk-2QHFH3DR.js";
220
- import "./chunk-OQHIVPG4.js";
229
+ import "./chunk-USGHJSGO.js";
221
230
  import {
222
231
  asRecordOrEmpty
223
232
  } from "./chunk-KX6YBIHG.js";
233
+ import "./chunk-OQHIVPG4.js";
224
234
  import "./chunk-DWLEOOGR.js";
225
235
  import {
226
236
  isAbortError
227
237
  } from "./chunk-7DPNBQSV.js";
228
- import "./chunk-T43B7LB2.js";
229
- import "./chunk-ZRSNONOB.js";
230
- import "./chunk-4VJAC32I.js";
231
- import "./chunk-CJEIOP3E.js";
232
- import "./chunk-ZCWRMUWT.js";
233
- import "./chunk-ZC3CMUKU.js";
238
+ import "./chunk-OW765XBU.js";
239
+ import "./chunk-EWQ3HGNZ.js";
240
+ import {
241
+ estimateTokenCount
242
+ } from "./chunk-PSCNXBYA.js";
243
+ import "./chunk-G7Y4GXTY.js";
244
+ import "./chunk-6UBGXX2W.js";
245
+ import "./chunk-G7IUT2V3.js";
246
+ import "./chunk-6OVNSQHN.js";
247
+ import "./chunk-W6RFEDN4.js";
248
+ import "./chunk-EVGU5P4U.js";
234
249
  import {
235
250
  isSystemBuiltinTrustedAgentKey
236
- } from "./chunk-LOEO7LRC.js";
251
+ } from "./chunk-ILHQ2AXT.js";
237
252
  import {
238
253
  extractCustomId
239
254
  } from "./chunk-M2EJHDJP.js";
255
+ import "./chunk-SYTHYBMI.js";
240
256
  import {
241
- isAntigravityOAuthAgent
242
- } from "./chunk-KIM6CLW5.js";
243
- import "./chunk-ALQ3657A.js";
244
- import {
245
- estimateTokenCount
246
- } from "./chunk-PSCNXBYA.js";
247
- import "./chunk-TCZHTTUU.js";
257
+ createDialogMessageKeyAndId,
258
+ dialogMessageKey
259
+ } from "./chunk-OJKUU3LP.js";
260
+ import "./chunk-YZMNK53S.js";
261
+ import "./chunk-I42VC5KR.js";
262
+ import "./chunk-U6VC4MU4.js";
263
+ import "./chunk-3P54D2E4.js";
264
+ import "./chunk-BNMPUQW6.js";
265
+ import "./chunk-KHCLMKZZ.js";
266
+ import "./chunk-LCBAMY2M.js";
267
+ import "./chunk-62HXNQVV.js";
268
+ import "./chunk-7JGMNKKG.js";
269
+ import "./chunk-RTHFJZ6M.js";
248
270
  import {
249
271
  isOpenAiResponsesModel
250
- } from "./chunk-YUA6OAH5.js";
251
- import {
252
- getApiEndpoint
253
- } from "./chunk-SM3NSZJV.js";
254
- import "./chunk-JRTNUU5Z.js";
272
+ } from "./chunk-HBRDSQ3M.js";
255
273
  import {
256
274
  toErrorMessage
257
275
  } from "./chunk-HNMXYYJR.js";
276
+ import {
277
+ asTrimmedString
278
+ } from "./chunk-3EUW3WEO.js";
279
+ import {
280
+ getApiEndpoint
281
+ } from "./chunk-CD3RU7XL.js";
282
+ import "./chunk-JRTNUU5Z.js";
258
283
  import {
259
284
  isRecord
260
285
  } from "./chunk-KUG52IAP.js";
261
- import "./chunk-GOO6G4PY.js";
262
- import "./chunk-QSJ3HFEF.js";
263
- import "./chunk-LCBAMY2M.js";
264
- import "./chunk-4SN6J65J.js";
265
- import "./chunk-CF7PE763.js";
266
- import "./chunk-G7Y4GXTY.js";
267
- import "./chunk-6UBGXX2W.js";
268
- import "./chunk-JY5NGFFH.js";
269
- import {
270
- createDialogMessageKeyAndId,
271
- dialogMessageKey
272
- } from "./chunk-XJWWBO34.js";
273
- import "./chunk-I42VC5KR.js";
274
- import "./chunk-U6VC4MU4.js";
275
286
  import "./chunk-WWC7I6TA.js";
276
- import {
277
- asTrimmedString
278
- } from "./chunk-3EUW3WEO.js";
279
287
  import {
280
288
  asOptionalTrimmedString
281
289
  } from "./chunk-G3SUCT4W.js";
282
- import "./chunk-4VNS5WPM.js";
290
+ import "./chunk-4SN6J65J.js";
291
+ import "./chunk-CF7PE763.js";
292
+ import "./chunk-OBSEKCVK.js";
293
+ import "./chunk-QSJ3HFEF.js";
294
+ import "./chunk-U67V476Y.js";
283
295
 
284
296
  // packages/ai/agent/isVoiceModel.ts
285
297
  function isVoiceModel(model, provider) {
@@ -476,6 +488,40 @@ var hasReportedTokenOrCostUsage = (usage) => {
476
488
  var shouldSkipBillingForUserAbort = (error, usage) => {
477
489
  return isAbortError(error) && !hasReportedTokenOrCostUsage(usage);
478
490
  };
491
+ function buildResponsesRequestBodyWithTools(bodyData, agentConfig) {
492
+ const functionTools = getModelInfo(agentConfig.model)?.hasImageOutput ? [] : prepareTools(agentConfig.tools ?? [], { provider: agentConfig.provider });
493
+ const imageMode = getPublicImageAgentMode(agentConfig);
494
+ const imageProfile = imageMode === "continuous" ? getPublicImageAgentDefaultProfile("continuous") : null;
495
+ const imageGenerationModel = asOptionalTrimmedString(
496
+ agentConfig?.imageModel
497
+ );
498
+ const tools = [
499
+ ...toResponsesTools(functionTools) ?? [],
500
+ ...shouldEnableBuiltInImageGeneration(agentConfig) ? [
501
+ {
502
+ type: "image_generation",
503
+ ...imageGenerationModel ? { model: imageGenerationModel } : {}
504
+ }
505
+ ] : [],
506
+ ...imageMode === "continuous" ? [
507
+ {
508
+ type: "image_generation",
509
+ action: "auto",
510
+ ...imageGenerationModel ? { model: imageGenerationModel } : {},
511
+ quality: imageProfile?.quality,
512
+ output_format: imageProfile?.outputFormat
513
+ }
514
+ ] : []
515
+ ];
516
+ const sourceBodyData = bodyData;
517
+ const sanitizedInput = Array.isArray(sourceBodyData?.input) ? sanitizeOutboundResponsesInput(sourceBodyData.input) : sourceBodyData?.input;
518
+ const baseBodyData = sanitizedInput !== sourceBodyData?.input ? { ...sourceBodyData, input: sanitizedInput } : sourceBodyData;
519
+ return {
520
+ ...baseBodyData,
521
+ ...tools.length ? { tools, tool_choice: baseBodyData.tool_choice ?? "auto" } : {},
522
+ stream: true
523
+ };
524
+ }
479
525
  var sendOpenAIResponseRequest = async ({
480
526
  bodyData,
481
527
  agentConfig,
@@ -744,39 +790,7 @@ var sendOpenAIResponseRequest = async ({
744
790
  })
745
791
  );
746
792
  }
747
- const functionTools = getModelInfo(agentConfig.model)?.hasImageOutput ? [] : prepareTools(agentConfig.tools ?? [], { provider: agentConfig.provider });
748
- const imageMode = getPublicImageAgentMode(agentConfig);
749
- const imageProfile = imageMode === "continuous" ? getPublicImageAgentDefaultProfile("continuous") : null;
750
- const imageGenerationModel = asOptionalTrimmedString(
751
- agentConfig?.imageModel
752
- );
753
- const tools = [
754
- ...toResponsesTools(functionTools) ?? [],
755
- ...shouldEnableBuiltInImageGeneration(agentConfig) ? [
756
- {
757
- type: "image_generation",
758
- ...imageGenerationModel ? { model: imageGenerationModel } : {}
759
- }
760
- ] : [],
761
- ...imageMode === "continuous" ? [
762
- {
763
- type: "image_generation",
764
- action: "auto",
765
- ...imageGenerationModel ? { model: imageGenerationModel } : {},
766
- quality: imageProfile?.quality,
767
- output_format: imageProfile?.outputFormat
768
- }
769
- ] : []
770
- ];
771
- const buildRequestBody = (sourceBodyData) => {
772
- const sanitizedInput = Array.isArray(sourceBodyData?.input) ? sanitizeOutboundResponsesInput(sourceBodyData.input) : sourceBodyData?.input;
773
- const baseBodyData = sanitizedInput !== sourceBodyData?.input ? { ...sourceBodyData, input: sanitizedInput } : sourceBodyData;
774
- return {
775
- ...baseBodyData,
776
- ...tools.length ? { tools, tool_choice: baseBodyData.tool_choice ?? "auto" } : {},
777
- stream: true
778
- };
779
- };
793
+ const buildRequestBody = (body) => buildResponsesRequestBodyWithTools(body, agentConfig);
780
794
  let requestBody = buildRequestBody(bodyData);
781
795
  const fallbackRequestBody = fallbackBodyData ? buildRequestBody(fallbackBodyData) : null;
782
796
  const api = getApiEndpoint(agentConfig);
@@ -1146,37 +1160,79 @@ var buildAgentViewMessages = (allMessages, currentAgentKey) => {
1146
1160
  return result;
1147
1161
  };
1148
1162
 
1149
- // packages/ai/agent/platformPaidCall.ts
1150
- var asTrimmed = (value) => typeof value === "string" ? value.trim() : "";
1151
- var hasOAuthCredentialShape = (agentConfig) => isOAuthApiKeyRef(agentConfig?.apiKeyRef) || isAntigravityOAuthAgent({
1152
- key: "platform-paid-call-probe",
1153
- apiKeyRef: agentConfig?.apiKeyRef ?? void 0,
1154
- provider: agentConfig?.provider ?? void 0,
1155
- customProviderUrl: agentConfig?.customProviderUrl ?? void 0
1156
- });
1157
- function isPlatformPaidAgentCall(probe) {
1158
- const agentConfig = probe?.agentConfig ?? {};
1159
- const authKind = asTrimmed(probe?.authKind);
1160
- if (authKind) return authKind === "platform-key";
1161
- if (asTrimmed(agentConfig.apiSource) === "cli") return false;
1162
- return resolveBillingSource({
1163
- local: agentConfig.local,
1164
- isLocal: agentConfig.isLocal,
1165
- cliProvider: agentConfig.cliProvider,
1166
- apiSource: agentConfig.apiSource,
1167
- provider: agentConfig.provider,
1168
- billingSource: agentConfig.billingSource,
1169
- // 形态证明而非记录自声明(见文件头):自声明 isOAuth 不足以证明 OAuth 通道归属。
1170
- isOAuth: hasOAuthCredentialShape(agentConfig),
1171
- apiKeyRef: agentConfig.apiKeyRef,
1172
- customProviderUrl: agentConfig.customProviderUrl,
1173
- isOwned: isOwnedAgentRecord(
1174
- agentConfig,
1175
- asTrimmed(probe?.callerUserId) || void 0
1176
- ),
1177
- userId: agentConfig.userId,
1178
- ownerId: agentConfig.ownerId
1179
- }) === "platform_credits";
1163
+ // packages/ai/agent/requestAdmission.ts
1164
+ function projectSummaryHistory(messages, summary, anchor) {
1165
+ if (!summary || !anchor) return messages;
1166
+ const covered = messages.findIndex((message) => message.id === anchor);
1167
+ if (covered < 0) return messages;
1168
+ let start = covered + 1;
1169
+ while (start > 0 && messages[start]?.role === "tool") start--;
1170
+ const latestUser = messages.map((message) => message.role).lastIndexOf("user");
1171
+ const suffix = messages.slice(start);
1172
+ return latestUser >= 0 && latestUser < start ? [messages[latestUser], ...suffix] : suffix;
1173
+ }
1174
+ var UNKNOWN_IMAGE_RESERVE_TOKENS = 4096;
1175
+ function projectWireImageCosts(items) {
1176
+ let imageCount = 0;
1177
+ if (!Array.isArray(items)) return { projected: items, imageCount };
1178
+ const projected = items.map((message) => {
1179
+ if (!message || !Array.isArray(message.content)) return message;
1180
+ return { ...message, content: message.content.map((part) => {
1181
+ if (part?.type === "image_url" && typeof part.image_url?.url === "string") {
1182
+ imageCount++;
1183
+ return { type: "image_url", image_url: { detail: part.image_url.detail } };
1184
+ }
1185
+ if (part?.type === "input_image" && (typeof part.image_url === "string" || typeof part.file_id === "string")) {
1186
+ imageCount++;
1187
+ return { type: "input_image", detail: part.detail };
1188
+ }
1189
+ return part;
1190
+ }) };
1191
+ });
1192
+ return { projected, imageCount };
1193
+ }
1194
+ function estimateWebRequestBudget(body, contextWindow) {
1195
+ const { messages, input, instructions, tools, ...other } = body;
1196
+ const count = (value) => value == null ? 0 : estimateTokenCount(JSON.stringify(value));
1197
+ const projectedMessages = projectWireImageCosts(messages);
1198
+ const projectedInput = projectWireImageCosts(input);
1199
+ const unknownImageCount = projectedMessages.imageCount + projectedInput.imageCount;
1200
+ const heuristicImageReserveTokens = unknownImageCount * UNKNOWN_IMAGE_RESERVE_TOKENS;
1201
+ const cap = body.max_output_tokens ?? body.max_completion_tokens ?? body.max_tokens;
1202
+ const decision = evaluateRequestBudget({
1203
+ contextWindow,
1204
+ messageTokens: count(projectedMessages.projected) + count(projectedInput.projected) + count(instructions),
1205
+ toolSchemaTokens: count(tools),
1206
+ otherInputTokens: count(other) + heuristicImageReserveTokens,
1207
+ protocolReserveTokens: 1024,
1208
+ output: { semantics: "unknown", fallbackReserveTokens: cap === void 0 ? 8192 : Number(cap) }
1209
+ });
1210
+ return { ...decision, unknownImageCount, heuristicImageReserveTokens, imageCostBasis: "unknown-provider-heuristic" };
1211
+ }
1212
+ async function admitWebRequest(options) {
1213
+ for (let attempt = 0; attempt < 2; attempt++) {
1214
+ if (options.signal.aborted) {
1215
+ const error = new Error("Request admission aborted");
1216
+ error.name = "AbortError";
1217
+ throw options.signal.reason ?? error;
1218
+ }
1219
+ const request = await options.build();
1220
+ if (options.signal.aborted) {
1221
+ const error = new Error("Request admission aborted");
1222
+ error.name = "AbortError";
1223
+ throw options.signal.reason ?? error;
1224
+ }
1225
+ const decisions = request.wireBodies.map((body) => estimateWebRequestBudget(body, options.contextWindow));
1226
+ if (decisions.length && decisions.every((decision) => decision.fitsEstimate)) return request.value;
1227
+ if (attempt) throw new Error("Context budget exceeded after budget_rescue; request not sent (heuristic estimate)");
1228
+ const allowances = request.wireBodies.map((body) => {
1229
+ const systemOnly = (items) => Array.isArray(items) ? items.filter((item) => item.role === "system" || item.role === "developer") : items;
1230
+ const external = estimateWebRequestBudget({ ...body, messages: systemOnly(body.messages), input: systemOnly(body.input) }, options.contextWindow);
1231
+ return Math.max(0, external.availableInputTokens - external.estimatedInputTokens);
1232
+ });
1233
+ await options.rescue(Math.min(...allowances));
1234
+ }
1235
+ throw new Error("Context budget admission failed");
1180
1236
  }
1181
1237
 
1182
1238
  // packages/ai/agent/persistMessageWithFixedId.ts
@@ -1236,13 +1292,14 @@ function buildDesktopAgentRuntimeTurnBody(args) {
1236
1292
  } else if (Array.isArray(args.dialogMessages) && continueDialogId) {
1237
1293
  dialogHistorySnapshot = buildDesktopAgentRuntimeDialogHistorySnapshot({
1238
1294
  dialogId: continueDialogId,
1239
- messages: args.dialogMessages,
1240
- currentInput: args.input
1295
+ messages: args.userMessages?.length ? args.dialogMessages.filter((message) => !args.userMessages.some((user) => user.cliMessageId === message.id)) : args.dialogMessages,
1296
+ currentInput: args.userMessages?.length ? void 0 : args.input
1241
1297
  }) ?? void 0;
1242
1298
  }
1243
1299
  const body = {
1244
1300
  agentRef: args.agentRef,
1245
1301
  input: args.input,
1302
+ ...args.userMessages?.length ? { userMessages: args.userMessages } : {},
1246
1303
  ...Array.isArray(args.contextBlocks) && args.contextBlocks.length > 0 ? { contextBlocks: args.contextBlocks } : {},
1247
1304
  ...args.runtimeContext ? { runtimeContext: args.runtimeContext } : {},
1248
1305
  ...continueDialogId ? { continueDialogId } : {},
@@ -1988,6 +2045,7 @@ var streamAgentChatTurnHandler = async (args, thunkApi) => {
1988
2045
  let loopKey = null;
1989
2046
  let runtimeDialogKey = explicitDialogKey ?? null;
1990
2047
  let turnPhaseTurnId = null;
2048
+ const batchExecution = createUserBatchExecution(loopController.signal, () => !thunkApi.signal.aborted && (!turnPhaseTurnId || !runtimeDialogKey || getDialogRuntimeState(runtimeDialogKey).turnPhaseTurnId === turnPhaseTurnId));
1991
2049
  let remoteTransientMessageId = null;
1992
2050
  let remoteTransientMessageFinalized = false;
1993
2051
  let modelRequestStarted = false;
@@ -2123,7 +2181,7 @@ var streamAgentChatTurnHandler = async (args, thunkApi) => {
2123
2181
  if (boundMachineId) {
2124
2182
  const token = selectIdentityToken(currentState);
2125
2183
  const authHeader = token ? `Bearer ${token}` : "";
2126
- const rawMessages = selectAllMsgs(currentState, dialogId2);
2184
+ const rawMessages = selectAdmittedMessages(selectAllMsgs(currentState, dialogId2));
2127
2185
  const visibleMessages = buildAgentViewMessages(
2128
2186
  rawMessages,
2129
2187
  agentConfig.dbKey
@@ -2184,15 +2242,16 @@ var streamAgentChatTurnHandler = async (args, thunkApi) => {
2184
2242
  ...Array.isArray(contextBlocks) && contextBlocks.length > 0 ? { contextBlocks } : {},
2185
2243
  messages: cleanedMessages,
2186
2244
  stream: true,
2187
- persistDialog: false,
2188
- clientDialogId: dialogId2,
2245
+ persistDialog: true,
2246
+ continueDialogId: dialogId2,
2189
2247
  ...explicitTarget ? { runtimeTarget: explicitTarget } : {},
2190
2248
  runtimeContext: {
2191
2249
  surface: "web",
2192
2250
  host: "browser",
2193
2251
  runtime: "react",
2194
2252
  entrypoint: "chat-dialog",
2195
- capabilities: ["streaming", "dialog-ui", "machine-bound-cli"]
2253
+ capabilities: ["streaming", "dialog-ui", "machine-bound-cli", "durable-user-batch", "client-user-prepersisted"],
2254
+ userMessageId: selectAdmittedMessages(selectAllMsgs(getState(), dialogId2)).filter((message) => message.role === "user").at(-1)?.id
2196
2255
  },
2197
2256
  ...dialogConfig?.spaceId ? { spaceId: dialogConfig.spaceId } : {}
2198
2257
  }),
@@ -2239,6 +2298,15 @@ var streamAgentChatTurnHandler = async (args, thunkApi) => {
2239
2298
  if (payload.type === "error") {
2240
2299
  return { reject: payload.message || "\u7535\u8111\u7AEF Agent \u6267\u884C\u5931\u8D25" };
2241
2300
  }
2301
+ if (payload.type === "action_gate" && payload.gate) {
2302
+ pushGate(
2303
+ payload.gate,
2304
+ targetForRunKind("server-run", {
2305
+ server: currentServer2,
2306
+ token
2307
+ })
2308
+ );
2309
+ }
2242
2310
  remoteToolHandlers.handleToolPayload(payload);
2243
2311
  if (payload.type === "text" && typeof payload.content === "string") {
2244
2312
  accumulated2 += payload.content;
@@ -2547,6 +2615,8 @@ var streamAgentChatTurnHandler = async (args, thunkApi) => {
2547
2615
  dialogKey,
2548
2616
  dialogId
2549
2617
  });
2618
+ turnPhaseTurnId = `turn-phase:${dialogId}:${crypto.randomUUID()}`;
2619
+ claimDialogTurnPhase({ dialogKey, turnId: turnPhaseTurnId });
2550
2620
  if (shouldUseDesktopLocalRuntime(agentConfig, explicitTarget)) {
2551
2621
  const desktopMessageMetadata = buildMessageMetadata(agentConfig);
2552
2622
  const w2 = typeof globalThis !== "undefined" && globalThis.window ? globalThis.window : null;
@@ -2554,428 +2624,489 @@ var streamAgentChatTurnHandler = async (args, thunkApi) => {
2554
2624
  dispatch(addActiveController({ messageId: loopKey, controller: loopController, dialogKey }));
2555
2625
  turnPhaseTurnId = `turn-phase:${dialogId}:${Date.now().toString(36)}:${Math.random().toString(36).slice(2, 8)}`;
2556
2626
  claimDialogTurnPhase({ dialogKey, turnId: turnPhaseTurnId });
2557
- let currentContent = "";
2558
- const assistantSegments = [];
2559
- let assistantMessageKeys = null;
2560
- let streamResult = null;
2561
- let streamError = null;
2562
- let reasoningBuffer = "";
2563
- const activeToolMessages = /* @__PURE__ */ new Map();
2564
- let desktopToolExecutionLocation = void 0;
2565
- const ensureAssistantMessageKeys = () => {
2566
- if (!assistantMessageKeys) {
2567
- assistantMessageKeys = createDialogMessageKeyAndId(dialogId);
2568
- assistantSegments.push({
2569
- key: assistantMessageKeys.key,
2570
- messageId: assistantMessageKeys.messageId,
2571
- content: "",
2572
- finalized: false,
2573
- toolCallIds: []
2574
- });
2575
- remoteTransientMessageId = assistantMessageKeys.messageId;
2627
+ const ownsDesktopTurn = () => !loopController.signal.aborted && !thunkApi.signal.aborted && getDialogRuntimeState(dialogKey).turnPhaseTurnId === turnPhaseTurnId;
2628
+ const admitDesktopBatch = async () => {
2629
+ const admission = new AbortController();
2630
+ const checkOwner = () => {
2631
+ if (!ownsDesktopTurn()) admission.abort();
2632
+ };
2633
+ const unsubscribe = subscribe(checkOwner);
2634
+ loopController.signal.addEventListener("abort", checkOwner);
2635
+ thunkApi.signal.addEventListener("abort", checkOwner);
2636
+ checkOwner();
2637
+ try {
2638
+ return await dispatch(admitPendingUserMessages({ dialogKey, signal: admission.signal })).unwrap();
2639
+ } finally {
2640
+ unsubscribe();
2641
+ loopController.signal.removeEventListener("abort", checkOwner);
2642
+ thunkApi.signal.removeEventListener("abort", checkOwner);
2576
2643
  }
2577
- return assistantMessageKeys;
2578
- };
2579
- const streamDesktopAssistantUpsert = () => {
2580
- const { key: msgKey2, messageId: messageId2 } = ensureAssistantMessageKeys();
2581
- const segment2 = assistantSegments[assistantSegments.length - 1];
2582
- segment2.content = currentContent;
2583
- dispatch(messageStreaming({
2584
- id: messageId2,
2585
- dialogId,
2586
- dbKey: msgKey2,
2587
- content: currentContent,
2588
- role: "assistant",
2589
- isStreaming: true,
2590
- thinkContent: reasoningBuffer,
2591
- ...desktopMessageMetadata
2592
- }));
2593
- };
2594
- const streamDesktopAssistantText = (text) => {
2595
- currentContent += text;
2596
- streamDesktopAssistantUpsert();
2597
2644
  };
2598
- const finalizeCurrentAssistantSegmentForTool = () => {
2599
- const segment2 = assistantSegments[assistantSegments.length - 1];
2600
- if (segment2) {
2645
+ const sameInput = (content) => JSON.stringify(content) === JSON.stringify(userInput);
2646
+ const initialMessages = selectAllMsgs(getState(), dialogId);
2647
+ const initialUser = initialMessages.filter((message) => message.role === "user" && sameInput(message.content)).at(-1);
2648
+ const isUserTurn = !!initialUser && sameInput(initialUser.content);
2649
+ let desktopBatch = isUserTurn && initialUser.metadata?.queueState === "pending" ? await admitDesktopBatch() : isUserTurn ? [...initialMessages.filter((message) => message.role === "user" && message.id !== initialUser.id && message.metadata?.userBatchPhase === "admitted"), initialUser] : [];
2650
+ if (!ownsDesktopTurn()) return { aborted: true };
2651
+ while (ownsDesktopTurn()) {
2652
+ const desktopRequestUserInput = snapshotUserBatchInput(desktopBatch.length ? desktopBatch : selectAllMsgs(getState(), dialogId));
2653
+ const desktopInput = desktopBatch.length ? desktopBatch[desktopBatch.length - 1].content : userInput;
2654
+ let currentContent = "";
2655
+ const assistantSegments = [];
2656
+ let assistantMessageKeys = null;
2657
+ let streamResult = null;
2658
+ let streamError = null;
2659
+ let reasoningBuffer = "";
2660
+ const activeToolMessages = /* @__PURE__ */ new Map();
2661
+ let desktopToolExecutionLocation = void 0;
2662
+ const ensureAssistantMessageKeys = () => {
2663
+ if (!assistantMessageKeys) {
2664
+ assistantMessageKeys = createDialogMessageKeyAndId(dialogId);
2665
+ assistantSegments.push({
2666
+ key: assistantMessageKeys.key,
2667
+ messageId: assistantMessageKeys.messageId,
2668
+ content: "",
2669
+ finalized: false,
2670
+ toolCallIds: []
2671
+ });
2672
+ remoteTransientMessageId = assistantMessageKeys.messageId;
2673
+ }
2674
+ return assistantMessageKeys;
2675
+ };
2676
+ const streamDesktopAssistantUpsert = () => {
2677
+ const { key: msgKey2, messageId: messageId2 } = ensureAssistantMessageKeys();
2678
+ const segment2 = assistantSegments[assistantSegments.length - 1];
2601
2679
  segment2.content = currentContent;
2602
- segment2.finalized = true;
2603
- }
2604
- if (assistantMessageKeys && (currentContent.length > 0 || reasoningBuffer.length > 0)) {
2605
- dispatch(updateToolMessage({
2606
- id: assistantMessageKeys.messageId,
2680
+ dispatch(messageStreaming({
2681
+ id: messageId2,
2607
2682
  dialogId,
2608
- changes: {
2609
- content: currentContent,
2610
- thinkContent: reasoningBuffer,
2611
- isStreaming: false
2612
- }
2683
+ dbKey: msgKey2,
2684
+ content: currentContent,
2685
+ role: "assistant",
2686
+ isStreaming: true,
2687
+ thinkContent: reasoningBuffer,
2688
+ ...desktopMessageMetadata
2613
2689
  }));
2614
- }
2615
- assistantMessageKeys = null;
2616
- currentContent = "";
2617
- };
2618
- try {
2619
- const desktopAgentRef = agentConfig.dbKey || agentKey;
2620
- const eventStream = runDesktopAgentRuntimeTurnStream({
2621
- agentRef: desktopAgentRef,
2622
- input: userInput,
2623
- ...Array.isArray(contextBlocks) && contextBlocks.length > 0 ? { contextBlocks } : {},
2624
- continueDialogId: dialogId,
2625
- dialogKey,
2626
- cwd: runtimeOptions?.cwd,
2627
- restrictShellToWorkspace: runtimeOptions?.restrictShellToWorkspace === true,
2628
- workspaceToolsHint: runtimeOptions?.workspaceToolsHint === true,
2629
- agentConfigSnapshot: agentConfig,
2630
- dialogMessages: selectAllMsgs(getState(), dialogId),
2631
- signal: loopController.signal,
2632
- // SSE 传输层兜底(review 修复 4):此前本调用方从不传
2633
- // noEventWatchdogMs,watchdog 永远关闭——「已有安全网」只是
2634
- // 错觉,挂起点若在 provider.complete 之外(resolveProvider /
2635
- // adapter 内部,runtime 没有任何 deadline)就会无限静默。
2636
- // 量级必须大于 runtime 自己的 idle 窗(默认 10 分钟无新输出
2637
- // 才放弃,见 localLoop.DEFAULT_LLM_REQUEST_TIMEOUT_MS),
2638
- // 否则一个健康的慢思考轮次会被客户端提前判死,用户拿到的是
2639
- // 未分类的 "stream stalled" 而不是 runtime 的
2640
- // LLM_REQUEST_TIMEOUT 可操作文案。取 2× = 20 分钟:
2641
- // 只兜「runtime 完全没 deadline」的真悬挂。
2642
- noEventWatchdogMs: DESKTOP_SSE_NO_EVENT_WATCHDOG_MS
2643
- });
2644
- for await (const event of eventStream) {
2645
- if (loopController.signal.aborted || thunkApi.signal.aborted) {
2646
- if (w2) w2.__LOOP_STOP_REASON__ = "aborted";
2647
- break;
2690
+ };
2691
+ const streamDesktopAssistantText = (text) => {
2692
+ currentContent += text;
2693
+ streamDesktopAssistantUpsert();
2694
+ };
2695
+ const finalizeCurrentAssistantSegmentForTool = () => {
2696
+ const segment2 = assistantSegments[assistantSegments.length - 1];
2697
+ if (segment2) {
2698
+ segment2.content = currentContent;
2699
+ segment2.finalized = true;
2700
+ }
2701
+ if (assistantMessageKeys && (currentContent.length > 0 || reasoningBuffer.length > 0)) {
2702
+ dispatch(updateToolMessage({
2703
+ id: assistantMessageKeys.messageId,
2704
+ dialogId,
2705
+ changes: {
2706
+ content: currentContent,
2707
+ thinkContent: reasoningBuffer,
2708
+ isStreaming: false
2709
+ }
2710
+ }));
2648
2711
  }
2649
- if (event.type === "delta") {
2650
- streamDesktopAssistantText(event.text);
2651
- } else if (event.type === "thinking") {
2652
- if (typeof event.content === "string") {
2653
- reasoningBuffer += event.content;
2654
- streamDesktopAssistantUpsert();
2712
+ assistantMessageKeys = null;
2713
+ currentContent = "";
2714
+ };
2715
+ try {
2716
+ const desktopAgentRef = agentConfig.dbKey || agentKey;
2717
+ const eventStream = await dispatch(runPendingUserBatchRequest({
2718
+ dialogKey,
2719
+ signal: loopController.signal,
2720
+ execution: batchExecution,
2721
+ requestUserInput: desktopRequestUserInput,
2722
+ owns: ownsDesktopTurn,
2723
+ start: () => {
2724
+ const iterator = runDesktopAgentRuntimeTurnStream({
2725
+ agentRef: desktopAgentRef,
2726
+ input: desktopInput,
2727
+ ...desktopBatch.length ? {
2728
+ userMessages: desktopBatch.map((message) => ({
2729
+ role: "user",
2730
+ content: message.content,
2731
+ cliMessageId: message.id
2732
+ })),
2733
+ runtimeContext: { userMessageId: desktopBatch[desktopBatch.length - 1].id }
2734
+ } : {},
2735
+ ...Array.isArray(contextBlocks) && contextBlocks.length > 0 ? { contextBlocks } : {},
2736
+ continueDialogId: dialogId,
2737
+ dialogKey,
2738
+ cwd: runtimeOptions?.cwd,
2739
+ restrictShellToWorkspace: runtimeOptions?.restrictShellToWorkspace === true,
2740
+ workspaceToolsHint: runtimeOptions?.workspaceToolsHint === true,
2741
+ agentConfigSnapshot: agentConfig,
2742
+ dialogMessages: selectAdmittedMessages(selectAllMsgs(getState(), dialogId)),
2743
+ signal: loopController.signal,
2744
+ // SSE 传输层兜底(review 修复 4):此前本调用方从不传
2745
+ // noEventWatchdogMs,watchdog 永远关闭——「已有安全网」只是
2746
+ // 错觉,挂起点若在 provider.complete 之外(resolveProvider /
2747
+ // adapter 内部,runtime 没有任何 deadline)就会无限静默。
2748
+ // 量级必须大于 runtime 自己的 idle 窗(默认 10 分钟无新输出
2749
+ // 才放弃,见 localLoop.DEFAULT_LLM_REQUEST_TIMEOUT_MS),
2750
+ // 否则一个健康的慢思考轮次会被客户端提前判死,用户拿到的是
2751
+ // 未分类的 "stream stalled" 而不是 runtime 的
2752
+ // LLM_REQUEST_TIMEOUT 可操作文案。取 2× = 20 分钟:
2753
+ // 只兜「runtime 完全没 deadline」的真悬挂。
2754
+ noEventWatchdogMs: DESKTOP_SSE_NO_EVENT_WATCHDOG_MS
2755
+ });
2756
+ const first = iterator.next();
2757
+ return async function* () {
2758
+ const event = await first;
2759
+ if (!event.done) yield event.value;
2760
+ yield* iterator;
2761
+ }();
2655
2762
  }
2656
- } else if (event.type === "tool") {
2657
- const toolEvent = event.event;
2658
- const callId = toolEvent.toolCallId;
2659
- if (!callId) continue;
2660
- if (toolEvent.type === "tool-call") {
2661
- attachToolCallIdToSegment(assistantSegments, callId);
2662
- finalizeCurrentAssistantSegmentForTool();
2663
- const { key: dbKey, messageId: toolMsgId } = createDialogMessageKeyAndId(dialogId);
2664
- const toolMsg = {
2665
- id: toolMsgId,
2666
- dialogId,
2667
- dbKey,
2668
- role: "tool",
2669
- content: "",
2670
- isStreaming: true,
2671
- toolName: toolEvent.toolName,
2672
- toolCallId: callId,
2673
- // F2: 实际执行位置(服务端/runtime 投影)挂到 tool
2674
- // 卡片 metadata。优先事件自带 metadata(runtime
2675
- // 投影层直接注入的同名字段),兜底用 turn 级
2676
- // execution_location 帧。缺失/不合法时渲染层
2677
- // projectToolExecutionLocation 收敛为 unknown。
2678
- metadata: {
2679
- ...isRecord(toolEvent.metadata) ? toolEvent.metadata : {},
2680
- ...desktopToolExecutionLocation !== void 0 && !(isRecord(toolEvent.metadata) && toolEvent.metadata.executionLocation !== void 0) ? { executionLocation: desktopToolExecutionLocation } : {},
2681
- ...toolEvent.argumentsPreview ? { argumentsPreview: toolEvent.argumentsPreview } : {}
2682
- },
2683
- ...toolEvent.argumentsPreview ? {
2684
- toolPayload: {
2685
- input: {
2686
- command: toolEvent.argumentsPreview,
2687
- cmd: toolEvent.argumentsPreview
2763
+ })).unwrap();
2764
+ if (!eventStream || !ownsDesktopTurn()) break;
2765
+ for await (const event of eventStream) {
2766
+ if (loopController.signal.aborted || thunkApi.signal.aborted) {
2767
+ if (w2) w2.__LOOP_STOP_REASON__ = "aborted";
2768
+ break;
2769
+ }
2770
+ if (event.type === "delta") {
2771
+ streamDesktopAssistantText(event.text);
2772
+ } else if (event.type === "thinking") {
2773
+ if (typeof event.content === "string") {
2774
+ reasoningBuffer += event.content;
2775
+ streamDesktopAssistantUpsert();
2776
+ }
2777
+ } else if (event.type === "tool") {
2778
+ const toolEvent = event.event;
2779
+ const callId = toolEvent.toolCallId;
2780
+ if (!callId) continue;
2781
+ if (toolEvent.type === "tool-call") {
2782
+ attachToolCallIdToSegment(assistantSegments, callId);
2783
+ finalizeCurrentAssistantSegmentForTool();
2784
+ const { key: dbKey, messageId: toolMsgId } = createDialogMessageKeyAndId(dialogId);
2785
+ const toolMsg = {
2786
+ id: toolMsgId,
2787
+ dialogId,
2788
+ dbKey,
2789
+ role: "tool",
2790
+ content: "",
2791
+ isStreaming: true,
2792
+ toolName: toolEvent.toolName,
2793
+ toolCallId: callId,
2794
+ // F2: 实际执行位置(服务端/runtime 投影)挂到 tool
2795
+ // 卡片 metadata。优先事件自带 metadata(runtime
2796
+ // 投影层直接注入的同名字段),兜底用 turn 级
2797
+ // execution_location 帧。缺失/不合法时渲染层
2798
+ // projectToolExecutionLocation 收敛为 unknown。
2799
+ metadata: {
2800
+ ...isRecord(toolEvent.metadata) ? toolEvent.metadata : {},
2801
+ ...desktopToolExecutionLocation !== void 0 && !(isRecord(toolEvent.metadata) && toolEvent.metadata.executionLocation !== void 0) ? { executionLocation: desktopToolExecutionLocation } : {},
2802
+ ...toolEvent.argumentsPreview ? { argumentsPreview: toolEvent.argumentsPreview } : {}
2803
+ },
2804
+ ...toolEvent.argumentsPreview ? {
2805
+ toolPayload: {
2806
+ input: {
2807
+ command: toolEvent.argumentsPreview,
2808
+ cmd: toolEvent.argumentsPreview
2809
+ }
2688
2810
  }
2689
- }
2690
- } : {}
2691
- };
2692
- activeToolMessages.set(callId, toolMsg);
2693
- dispatch(messageStreaming(toolMsg));
2694
- } else if (toolEvent.type === "tool-result" || toolEvent.type === "tool-error") {
2695
- const existing = activeToolMessages.get(callId);
2696
- if (existing) {
2697
- const isError = toolEvent.type === "tool-error";
2698
- const existingMeta = asRecordOrEmpty(existing.metadata);
2699
- const existingInput = isRecord(existing.toolPayload?.input) ? existing.toolPayload.input : {};
2700
- const mergedMeta = {
2701
- ...existingMeta,
2702
- ...toolEvent.metadata,
2703
- ...isError ? { error: true, message: toolEvent.message } : {},
2704
- // 服务端/runtime 已在事件 metadata 带
2705
- // executionLocation 时尊重之;tool-call 阶段
2706
- // 已写入的值由 existingMeta 保留;仅当两边都
2707
- // 没有且 turn 级 execution_location 帧存在时
2708
- // 兜底补上,绝不覆盖已有值。
2709
- ...existingMeta.executionLocation === void 0 && (!isRecord(toolEvent.metadata) || toolEvent.metadata.executionLocation === void 0) && desktopToolExecutionLocation !== void 0 ? { executionLocation: desktopToolExecutionLocation } : {}
2710
- };
2711
- const toolResultMsg = {
2712
- ...existing,
2713
- isStreaming: false,
2714
- content: projectDesktopToolUiContent({
2715
- toolName: toolEvent.toolName || existing.toolName,
2716
- content: toolEvent.content,
2717
- summary: toolEvent.summary,
2718
- message: toolEvent.message,
2719
- metadata: mergedMeta,
2720
- argumentsPreview: asOptionalTrimmedString(mergedMeta.argumentsPreview) || asOptionalTrimmedString(existingInput.command) || asOptionalTrimmedString(existingInput.cmd) || void 0
2721
- }),
2722
- metadata: mergedMeta
2811
+ } : {}
2723
2812
  };
2724
- activeToolMessages.set(callId, toolResultMsg);
2725
- dispatch(messageStreaming(toolResultMsg));
2726
- const resultToolName = toolEvent.toolName || existing.toolName;
2727
- if (!isError) {
2728
- deliverHtmlArtifactToolResult(resultToolName, toolEvent.content, dialogKey);
2813
+ activeToolMessages.set(callId, toolMsg);
2814
+ dispatch(messageStreaming(toolMsg));
2815
+ } else if (toolEvent.type === "tool-result" || toolEvent.type === "tool-error") {
2816
+ const existing = activeToolMessages.get(callId);
2817
+ if (existing) {
2818
+ const isError = toolEvent.type === "tool-error";
2819
+ const existingMeta = asRecordOrEmpty(existing.metadata);
2820
+ const existingInput = isRecord(existing.toolPayload?.input) ? existing.toolPayload.input : {};
2821
+ const mergedMeta = {
2822
+ ...existingMeta,
2823
+ ...toolEvent.metadata,
2824
+ ...isError ? { error: true, message: toolEvent.message } : {},
2825
+ // 服务端/runtime 已在事件 metadata 带
2826
+ // executionLocation 时尊重之;tool-call 阶段
2827
+ // 已写入的值由 existingMeta 保留;仅当两边都
2828
+ // 没有且 turn 级 execution_location 帧存在时
2829
+ // 兜底补上,绝不覆盖已有值。
2830
+ ...existingMeta.executionLocation === void 0 && (!isRecord(toolEvent.metadata) || toolEvent.metadata.executionLocation === void 0) && desktopToolExecutionLocation !== void 0 ? { executionLocation: desktopToolExecutionLocation } : {}
2831
+ };
2832
+ const toolResultMsg = {
2833
+ ...existing,
2834
+ isStreaming: false,
2835
+ content: projectDesktopToolUiContent({
2836
+ toolName: toolEvent.toolName || existing.toolName,
2837
+ content: toolEvent.content,
2838
+ summary: toolEvent.summary,
2839
+ message: toolEvent.message,
2840
+ metadata: mergedMeta,
2841
+ argumentsPreview: asOptionalTrimmedString(mergedMeta.argumentsPreview) || asOptionalTrimmedString(existingInput.command) || asOptionalTrimmedString(existingInput.cmd) || void 0
2842
+ }),
2843
+ metadata: mergedMeta
2844
+ };
2845
+ activeToolMessages.set(callId, toolResultMsg);
2846
+ dispatch(messageStreaming(toolResultMsg));
2847
+ const resultToolName = toolEvent.toolName || existing.toolName;
2848
+ if (!isError) {
2849
+ deliverHtmlArtifactToolResult(resultToolName, toolEvent.content, dialogKey);
2850
+ }
2729
2851
  }
2730
2852
  }
2853
+ } else if (event.type === "status") {
2854
+ const phase = event.phase === "validating-context" ? "validating" : event.phase;
2855
+ setDialogTurnPhase({ phase, dialogKey, turnId: turnPhaseTurnId ?? void 0 });
2856
+ } else if (event.type === "execution_location") {
2857
+ desktopToolExecutionLocation = event.location;
2858
+ } else if (event.type === "action_gate") {
2859
+ pushGate(
2860
+ event.gate,
2861
+ targetForRunKind("desktop-local")
2862
+ );
2863
+ } else if (event.type === "done") {
2864
+ streamResult = event.result;
2865
+ } else if (event.type === "error") {
2866
+ streamError = event.error;
2731
2867
  }
2732
- } else if (event.type === "status") {
2733
- const phase = event.phase === "validating-context" ? "validating" : event.phase;
2734
- setDialogTurnPhase({ phase, dialogKey, turnId: turnPhaseTurnId ?? void 0 });
2735
- } else if (event.type === "execution_location") {
2736
- desktopToolExecutionLocation = event.location;
2737
- } else if (event.type === "done") {
2738
- streamResult = event.result;
2739
- } else if (event.type === "error") {
2740
- streamError = event.error;
2868
+ }
2869
+ } catch (err) {
2870
+ if (isAbortError(err) || loopController.signal.aborted || thunkApi.signal.aborted) {
2871
+ if (w2) w2.__LOOP_STOP_REASON__ = "aborted";
2872
+ } else {
2873
+ streamError = err?.message || "Local turn read stream error";
2741
2874
  }
2742
2875
  }
2743
- } catch (err) {
2744
- if (isAbortError(err) || loopController.signal.aborted || thunkApi.signal.aborted) {
2876
+ if (loopController.signal.aborted || thunkApi.signal.aborted || typeof streamError === "string" && /operation was aborted/i.test(streamError)) {
2745
2877
  if (w2) w2.__LOOP_STOP_REASON__ = "aborted";
2746
- } else {
2747
- streamError = err?.message || "Local turn read stream error";
2748
- }
2749
- }
2750
- if (loopController.signal.aborted || thunkApi.signal.aborted || typeof streamError === "string" && /operation was aborted/i.test(streamError)) {
2751
- if (w2) w2.__LOOP_STOP_REASON__ = "aborted";
2752
- const stopKeys = assistantMessageKeys;
2753
- if (stopKeys) {
2754
- const last = assistantSegments[assistantSegments.length - 1];
2755
- if (last && last.messageId === stopKeys.messageId) {
2756
- last.content = currentContent;
2878
+ const stopKeys = assistantMessageKeys;
2879
+ if (stopKeys) {
2880
+ const last = assistantSegments[assistantSegments.length - 1];
2881
+ if (last && last.messageId === stopKeys.messageId) {
2882
+ last.content = currentContent;
2883
+ }
2757
2884
  }
2758
- }
2759
- const stopToolNameById = /* @__PURE__ */ new Map();
2760
- for (const [callId, toolMsg] of activeToolMessages) {
2761
- if (!toolMessageWillPersist(toolMsg)) continue;
2762
- const toolName = toolMsg?.toolName;
2763
- stopToolNameById.set(
2764
- callId,
2765
- typeof toolName === "string" && toolName ? toolName : "tool"
2766
- );
2767
- }
2768
- for (const segment2 of assistantSegments) {
2769
- const hasContent = segment2.content.trim().length > 0;
2770
- const hasToolCalls = segment2.toolCallIds && segment2.toolCallIds.length > 0;
2771
- if (hasContent || hasToolCalls) {
2772
- const stopToolCalls = buildMinimalToolCallsFromIds(
2773
- segment2.toolCallIds,
2774
- stopToolNameById
2885
+ const stopToolNameById = /* @__PURE__ */ new Map();
2886
+ for (const [callId, toolMsg] of activeToolMessages) {
2887
+ if (!toolMessageWillPersist(toolMsg)) continue;
2888
+ const toolName = toolMsg?.toolName;
2889
+ stopToolNameById.set(
2890
+ callId,
2891
+ typeof toolName === "string" && toolName ? toolName : "tool"
2775
2892
  );
2776
- await persistMessageWithFixedId(dispatch, {
2777
- dialogId,
2778
- id: segment2.messageId,
2779
- dbKey: segment2.key,
2780
- role: "assistant",
2781
- content: segment2.content,
2782
- ...stopToolCalls.length > 0 ? { tool_calls: stopToolCalls } : {},
2783
- ...desktopMessageMetadata,
2784
- userId: selectIdentityUserId(getState())
2785
- });
2786
- } else {
2787
- dispatch(removeTransientMessage(segment2.messageId));
2788
2893
  }
2789
- }
2790
- const durableTools = [];
2791
- for (const toolMsg of activeToolMessages.values()) {
2792
- const content = toolMsg?.content;
2793
- const hasContent = typeof content === "string" ? content.trim().length > 0 : Array.isArray(content) && content.length > 0;
2794
- if (!hasContent) {
2795
- dispatch(removeTransientMessage(toolMsg.id));
2796
- continue;
2894
+ for (const segment2 of assistantSegments) {
2895
+ const hasContent = segment2.content.trim().length > 0;
2896
+ const hasToolCalls = segment2.toolCallIds && segment2.toolCallIds.length > 0;
2897
+ if (hasContent || hasToolCalls) {
2898
+ const stopToolCalls = buildMinimalToolCallsFromIds(
2899
+ segment2.toolCallIds,
2900
+ stopToolNameById
2901
+ );
2902
+ await persistMessageWithFixedId(dispatch, {
2903
+ dialogId,
2904
+ id: segment2.messageId,
2905
+ dbKey: segment2.key,
2906
+ role: "assistant",
2907
+ content: segment2.content,
2908
+ ...stopToolCalls.length > 0 ? { tool_calls: stopToolCalls } : {},
2909
+ ...desktopMessageMetadata,
2910
+ userId: selectIdentityUserId(getState())
2911
+ });
2912
+ } else {
2913
+ dispatch(removeTransientMessage(segment2.messageId));
2914
+ }
2797
2915
  }
2798
- const stopped = { ...toolMsg, isStreaming: false };
2799
- dispatch(messageStreaming(stopped));
2800
- durableTools.push(stopped);
2801
- }
2802
- await persistToolMessages(dispatch, durableTools, {
2803
- isStreaming: false,
2804
- soft: true
2805
- });
2806
- remoteTransientMessageFinalized = true;
2807
- return { aborted: true };
2808
- }
2809
- const finalizeDesktopTurnOnError = async (errorText) => {
2810
- const errorToolNameById = /* @__PURE__ */ new Map();
2811
- for (const [callId, toolMsg] of activeToolMessages) {
2812
- if (!toolMessageWillPersist(toolMsg)) continue;
2813
- const toolName = toolMsg?.toolName;
2814
- errorToolNameById.set(
2815
- callId,
2816
- typeof toolName === "string" && toolName ? toolName : "tool"
2817
- );
2916
+ const durableTools = [];
2917
+ for (const toolMsg of activeToolMessages.values()) {
2918
+ const content = toolMsg?.content;
2919
+ const hasContent = typeof content === "string" ? content.trim().length > 0 : Array.isArray(content) && content.length > 0;
2920
+ if (!hasContent) {
2921
+ dispatch(removeTransientMessage(toolMsg.id));
2922
+ continue;
2923
+ }
2924
+ const stopped = { ...toolMsg, isStreaming: false };
2925
+ dispatch(messageStreaming(stopped));
2926
+ durableTools.push(stopped);
2927
+ }
2928
+ await persistToolMessages(dispatch, durableTools, {
2929
+ isStreaming: false,
2930
+ soft: true
2931
+ });
2932
+ remoteTransientMessageFinalized = true;
2933
+ return { aborted: true };
2818
2934
  }
2819
- for (const segment2 of assistantSegments) {
2820
- const hasContent = segment2.content.trim().length > 0;
2821
- const hasToolCalls = segment2.toolCallIds && segment2.toolCallIds.length > 0;
2822
- if (hasContent || hasToolCalls) {
2823
- const errorToolCalls = buildMinimalToolCallsFromIds(
2824
- segment2.toolCallIds,
2825
- errorToolNameById
2935
+ const finalizeDesktopTurnOnError = async (errorText) => {
2936
+ const errorToolNameById = /* @__PURE__ */ new Map();
2937
+ for (const [callId, toolMsg] of activeToolMessages) {
2938
+ if (!toolMessageWillPersist(toolMsg)) continue;
2939
+ const toolName = toolMsg?.toolName;
2940
+ errorToolNameById.set(
2941
+ callId,
2942
+ typeof toolName === "string" && toolName ? toolName : "tool"
2826
2943
  );
2827
- await persistMessageWithFixedId(dispatch, {
2828
- dialogId,
2829
- id: segment2.messageId,
2830
- dbKey: segment2.key,
2831
- role: "assistant",
2832
- content: segment2.content,
2833
- ...errorToolCalls.length > 0 ? { tool_calls: errorToolCalls } : {},
2834
- ...desktopMessageMetadata,
2835
- userId: selectIdentityUserId(getState())
2836
- });
2837
- if (hasContent) {
2944
+ }
2945
+ for (const segment2 of assistantSegments) {
2946
+ const hasContent = segment2.content.trim().length > 0;
2947
+ const hasToolCalls = segment2.toolCallIds && segment2.toolCallIds.length > 0;
2948
+ if (hasContent || hasToolCalls) {
2949
+ const errorToolCalls = buildMinimalToolCallsFromIds(
2950
+ segment2.toolCallIds,
2951
+ errorToolNameById
2952
+ );
2953
+ await persistMessageWithFixedId(dispatch, {
2954
+ dialogId,
2955
+ id: segment2.messageId,
2956
+ dbKey: segment2.key,
2957
+ role: "assistant",
2958
+ content: segment2.content,
2959
+ ...errorToolCalls.length > 0 ? { tool_calls: errorToolCalls } : {},
2960
+ ...desktopMessageMetadata,
2961
+ userId: selectIdentityUserId(getState())
2962
+ });
2963
+ if (hasContent) {
2964
+ dispatch(finalizeTransientMessageOnError({
2965
+ id: segment2.messageId,
2966
+ error: errorText
2967
+ }));
2968
+ }
2969
+ } else {
2838
2970
  dispatch(finalizeTransientMessageOnError({
2839
2971
  id: segment2.messageId,
2840
2972
  error: errorText
2841
2973
  }));
2842
2974
  }
2843
- } else {
2844
- dispatch(finalizeTransientMessageOnError({
2845
- id: segment2.messageId,
2846
- error: errorText
2847
- }));
2848
2975
  }
2849
- }
2850
- const durableTools = [];
2851
- for (const toolMsg of activeToolMessages.values()) {
2852
- const content = toolMsg?.content;
2853
- const hasContent = typeof content === "string" ? content.trim().length > 0 : Array.isArray(content) && content.length > 0;
2854
- if (!hasContent) {
2855
- dispatch(removeTransientMessage(toolMsg.id));
2856
- continue;
2976
+ const durableTools = [];
2977
+ for (const toolMsg of activeToolMessages.values()) {
2978
+ const content = toolMsg?.content;
2979
+ const hasContent = typeof content === "string" ? content.trim().length > 0 : Array.isArray(content) && content.length > 0;
2980
+ if (!hasContent) {
2981
+ dispatch(removeTransientMessage(toolMsg.id));
2982
+ continue;
2983
+ }
2984
+ const stopped = { ...toolMsg, isStreaming: false };
2985
+ dispatch(messageStreaming(stopped));
2986
+ durableTools.push(stopped);
2857
2987
  }
2858
- const stopped = { ...toolMsg, isStreaming: false };
2859
- dispatch(messageStreaming(stopped));
2860
- durableTools.push(stopped);
2861
- }
2862
- await persistToolMessages(dispatch, durableTools, {
2863
- isStreaming: false,
2864
- soft: true
2865
- });
2866
- remoteTransientMessageFinalized = true;
2867
- setLoopStopReason("error");
2868
- };
2869
- if (streamError) {
2870
- const info = classifyLocalTurnStreamError(streamError);
2871
- const finalError = info.actionHint ? `${streamError}
2988
+ await persistToolMessages(dispatch, durableTools, {
2989
+ isStreaming: false,
2990
+ soft: true
2991
+ });
2992
+ remoteTransientMessageFinalized = true;
2993
+ setLoopStopReason("error");
2994
+ };
2995
+ if (streamError) {
2996
+ const info = classifyLocalTurnStreamError(streamError);
2997
+ const finalError = info.actionHint ? `${streamError}
2872
2998
 
2873
2999
  ${info.actionHint}` : streamError;
2874
- await finalizeDesktopTurnOnError(finalError);
2875
- return rejectWithValue(finalError);
2876
- }
2877
- if (!streamResult) {
2878
- const message = "Local turn stream closed unexpectedly without result";
2879
- await finalizeDesktopTurnOnError(message);
2880
- return rejectWithValue(message);
2881
- }
2882
- const desktopTurnMessages = streamResult.turnMessages || [];
2883
- const hasSegmentWithCallIds = assistantSegments.some(
2884
- (s) => s.toolCallIds.length > 0
2885
- );
2886
- if (!hasSegmentWithCallIds) {
2887
- const doneOnlyAssistantCalls = desktopTurnMessages.filter(
2888
- (m) => m?.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0
2889
- ).flatMap((m) => m.tool_calls.map((tc) => tc?.id)).filter((id) => typeof id === "string");
2890
- if (doneOnlyAssistantCalls.length > 0) {
2891
- ensureAssistantMessageKeys();
2892
- for (const callId of doneOnlyAssistantCalls) {
2893
- attachToolCallIdToSegment(assistantSegments, callId);
3000
+ await finalizeDesktopTurnOnError(finalError);
3001
+ return rejectWithValue(finalError);
3002
+ }
3003
+ if (!streamResult) {
3004
+ const message = "Local turn stream closed unexpectedly without result";
3005
+ await finalizeDesktopTurnOnError(message);
3006
+ return rejectWithValue(message);
3007
+ }
3008
+ const desktopTurnMessages = streamResult.turnMessages || [];
3009
+ const hasSegmentWithCallIds = assistantSegments.some(
3010
+ (s) => s.toolCallIds.length > 0
3011
+ );
3012
+ if (!hasSegmentWithCallIds) {
3013
+ const doneOnlyAssistantCalls = desktopTurnMessages.filter(
3014
+ (m) => m?.role === "assistant" && Array.isArray(m.tool_calls) && m.tool_calls.length > 0
3015
+ ).flatMap((m) => m.tool_calls.map((tc) => tc?.id)).filter((id) => typeof id === "string");
3016
+ if (doneOnlyAssistantCalls.length > 0) {
3017
+ ensureAssistantMessageKeys();
3018
+ for (const callId of doneOnlyAssistantCalls) {
3019
+ attachToolCallIdToSegment(assistantSegments, callId);
3020
+ }
3021
+ if (currentContent.length === 0) {
3022
+ finalizeCurrentAssistantSegmentForTool();
3023
+ }
2894
3024
  }
2895
- if (currentContent.length === 0) {
2896
- finalizeCurrentAssistantSegmentForTool();
3025
+ }
3026
+ if (activeToolMessages.size === 0) {
3027
+ for (const toolMessage of buildDesktopRuntimeToolMessagesForUi({
3028
+ dialogId,
3029
+ turnMessages: desktopTurnMessages
3030
+ })) {
3031
+ dispatch(messageStreaming(toolMessage));
3032
+ activeToolMessages.set(
3033
+ asTrimmedString(toolMessage.toolCallId) || toolMessage.id,
3034
+ toolMessage
3035
+ );
2897
3036
  }
2898
3037
  }
2899
- }
2900
- if (activeToolMessages.size === 0) {
2901
- for (const toolMessage of buildDesktopRuntimeToolMessagesForUi({
2902
- dialogId,
2903
- turnMessages: desktopTurnMessages
2904
- })) {
2905
- dispatch(messageStreaming(toolMessage));
2906
- activeToolMessages.set(
2907
- asTrimmedString(toolMessage.toolCallId) || toolMessage.id,
2908
- toolMessage
3038
+ await persistToolMessages(
3039
+ dispatch,
3040
+ activeToolMessages.values(),
3041
+ { isStreaming: false, soft: true }
3042
+ );
3043
+ const earlierFinalizedSegments = selectPersistableFinalizedSegments(assistantSegments);
3044
+ for (const segment2 of earlierFinalizedSegments) {
3045
+ const segmentToolCalls = resolveSegmentToolCalls(
3046
+ segment2.toolCallIds,
3047
+ desktopTurnMessages
2909
3048
  );
3049
+ dispatch(write({
3050
+ data: {
3051
+ id: segment2.messageId,
3052
+ dbKey: segment2.key,
3053
+ dialogId,
3054
+ content: segment2.content,
3055
+ role: "assistant",
3056
+ isStreaming: false,
3057
+ type: "msg" /* MSG */,
3058
+ ...segmentToolCalls.length > 0 ? { tool_calls: segmentToolCalls } : {},
3059
+ ...desktopMessageMetadata
3060
+ },
3061
+ customKey: segment2.key
3062
+ }));
2910
3063
  }
2911
- }
2912
- await persistToolMessages(
2913
- dispatch,
2914
- activeToolMessages.values(),
2915
- { isStreaming: false, soft: true }
2916
- );
2917
- const earlierFinalizedSegments = selectPersistableFinalizedSegments(assistantSegments);
2918
- for (const segment2 of earlierFinalizedSegments) {
2919
- const segmentToolCalls = resolveSegmentToolCalls(
2920
- segment2.toolCallIds,
2921
- desktopTurnMessages
2922
- );
2923
- dispatch(write({
2924
- data: {
2925
- id: segment2.messageId,
2926
- dbKey: segment2.key,
2927
- dialogId,
2928
- content: segment2.content,
2929
- role: "assistant",
2930
- isStreaming: false,
2931
- type: "msg" /* MSG */,
2932
- ...segmentToolCalls.length > 0 ? { tool_calls: segmentToolCalls } : {},
2933
- ...desktopMessageMetadata
2934
- },
2935
- customKey: segment2.key
3064
+ const { key: msgKey, messageId } = ensureAssistantMessageKeys();
3065
+ const lastSegmentContent = hasInlineExecutedToolCalls(streamResult) ? currentContent || "" : streamResult.content || currentContent || "";
3066
+ const segment = assistantSegments[assistantSegments.length - 1];
3067
+ segment.content = lastSegmentContent;
3068
+ dispatch(messageStreaming({
3069
+ id: messageId,
3070
+ dialogId,
3071
+ dbKey: msgKey,
3072
+ content: lastSegmentContent,
3073
+ role: "assistant",
3074
+ isStreaming: false,
3075
+ ...desktopMessageMetadata
2936
3076
  }));
3077
+ const lastSegmentToolCalls = segment ? resolveSegmentToolCalls(segment.toolCallIds, desktopTurnMessages) : [];
3078
+ await dispatch(messageStreamEnd({
3079
+ finalContentBuffer: [
3080
+ {
3081
+ type: "text",
3082
+ text: lastSegmentContent
3083
+ }
3084
+ ],
3085
+ totalUsage: streamResult.usage ?? void 0,
3086
+ billingUsageRecords: streamResult.usageRecords,
3087
+ messageId,
3088
+ msgKey,
3089
+ agentConfig,
3090
+ dialogId,
3091
+ dialogKey,
3092
+ // 优先用本 turn 累计的 thinking SSE;为空时兜底 streamResult.reasoning_content
3093
+ // (provider 在 SSE 流内累计返回的 reasoning_content)。
3094
+ reasoningBuffer: reasoningBuffer || (typeof streamResult?.reasoning_content === "string" ? streamResult.reasoning_content : ""),
3095
+ toolCalls: lastSegmentToolCalls,
3096
+ // 把 provider 报告的 finish_reason 透传给 messageStreamEnd,
3097
+ // 由 assembleFinalAssistantMessage 决定是否写进最终 Message。
3098
+ finishReason: streamResult.finish_reason ?? void 0,
3099
+ messageMetadata: desktopMessageMetadata
3100
+ })).unwrap();
3101
+ remoteTransientMessageFinalized = true;
3102
+ if (!isUserTurn || !ownsDesktopTurn() || streamResult.finish_reason !== "stop" || streamResult.stopReason && streamResult.stopReason !== "done" || streamResult.pendingInteraction || streamResult.hasPendingInteraction || streamResult.error || streamResult.emptyAssistantFallbackReason) {
3103
+ return { usage: streamResult.usage ?? void 0 };
3104
+ }
3105
+ desktopBatch = await admitDesktopBatch();
3106
+ if (!ownsDesktopTurn()) return { aborted: true };
3107
+ if (!desktopBatch.length) return { usage: streamResult.usage ?? void 0 };
2937
3108
  }
2938
- const { key: msgKey, messageId } = ensureAssistantMessageKeys();
2939
- const lastSegmentContent = hasInlineExecutedToolCalls(streamResult) ? currentContent || "" : streamResult.content || currentContent || "";
2940
- const segment = assistantSegments[assistantSegments.length - 1];
2941
- segment.content = lastSegmentContent;
2942
- dispatch(messageStreaming({
2943
- id: messageId,
2944
- dialogId,
2945
- dbKey: msgKey,
2946
- content: lastSegmentContent,
2947
- role: "assistant",
2948
- isStreaming: false,
2949
- ...desktopMessageMetadata
2950
- }));
2951
- const lastSegmentToolCalls = segment ? resolveSegmentToolCalls(segment.toolCallIds, desktopTurnMessages) : [];
2952
- await dispatch(messageStreamEnd({
2953
- finalContentBuffer: [
2954
- {
2955
- type: "text",
2956
- text: lastSegmentContent
2957
- }
2958
- ],
2959
- totalUsage: streamResult.usage ?? void 0,
2960
- billingUsageRecords: streamResult.usageRecords,
2961
- messageId,
2962
- msgKey,
2963
- agentConfig,
2964
- dialogId,
2965
- dialogKey,
2966
- // 优先用本 turn 累计的 thinking SSE;为空时兜底 streamResult.reasoning_content
2967
- // (provider 在 SSE 流内累计返回的 reasoning_content)。
2968
- reasoningBuffer: reasoningBuffer || (typeof streamResult?.reasoning_content === "string" ? streamResult.reasoning_content : ""),
2969
- toolCalls: lastSegmentToolCalls,
2970
- // 把 provider 报告的 finish_reason 透传给 messageStreamEnd,
2971
- // 由 assembleFinalAssistantMessage 决定是否写进最终 Message。
2972
- finishReason: streamResult.finish_reason ?? void 0,
2973
- messageMetadata: desktopMessageMetadata
2974
- })).unwrap();
2975
- remoteTransientMessageFinalized = true;
2976
- return {
2977
- usage: streamResult.usage ?? void 0
2978
- };
3109
+ return { aborted: true };
2979
3110
  }
2980
3111
  const userInputText = extractAgentRunUserText(userInput);
2981
3112
  const explicitServerBase = asOptionalTrimmedString(args.serverBase) ?? null;
@@ -2990,7 +3121,7 @@ ${info.actionHint}` : streamError;
2990
3121
  } else {
2991
3122
  const token = selectIdentityToken(state);
2992
3123
  const authHeader = token ? `Bearer ${token}` : "";
2993
- const rawMessages = selectAllMsgs(state, dialogId);
3124
+ const rawMessages = selectAdmittedMessages(selectAllMsgs(state, dialogId));
2994
3125
  const visibleMessages = buildAgentViewMessages(
2995
3126
  rawMessages,
2996
3127
  agentConfig.dbKey
@@ -3124,6 +3255,15 @@ ${info.actionHint}` : streamError;
3124
3255
  if (payload.type === "error") {
3125
3256
  return { reject: payload.message || "\u8FDC\u7AEF Agent \u6267\u884C\u5931\u8D25" };
3126
3257
  }
3258
+ if (payload.type === "action_gate" && payload.gate) {
3259
+ pushGate(
3260
+ payload.gate,
3261
+ targetForRunKind("server-run", {
3262
+ server: explicitServerBase,
3263
+ token
3264
+ })
3265
+ );
3266
+ }
3127
3267
  if (payload.type === "agent_handoff") {
3128
3268
  await patchDialogThreadMetadata(
3129
3269
  dispatch,
@@ -3229,7 +3369,7 @@ ${info.actionHint}` : streamError;
3229
3369
  recommendedSkillHints: turnToolContext.recommendedSkillHints,
3230
3370
  skillPromptPatches: turnToolContext.skillPromptPatches
3231
3371
  };
3232
- const initialRawMsgs = selectAllMsgs(state, dialogId);
3372
+ const initialRawMsgs = selectAdmittedMessages(selectAllMsgs(state, dialogId));
3233
3373
  const initialHistoryIds = new Set(initialRawMsgs.map((m) => m.id));
3234
3374
  const accountSkillRuntime = agentConfigWithReferences.runtimePromptAlreadyInMessages ? null : await resolveUserSkillRuntime(agentConfigWithReferences, state.settings);
3235
3375
  const agentConfigWithTools = resolveWebAgentRuntimeToolSurface(
@@ -3391,7 +3531,7 @@ ${info.actionHint}` : streamError;
3391
3531
  mergeContexts(staticContexts2, dynamicContexts),
3392
3532
  contextBlocks
3393
3533
  );
3394
- const rawMessages = selectAllMsgs(loopState, dialogId);
3534
+ const rawMessages = selectAdmittedMessages(selectAllMsgs(loopState, dialogId));
3395
3535
  let visibleMessages = buildAgentViewMessages(
3396
3536
  rawMessages,
3397
3537
  agentConfigForCall.dbKey
@@ -3419,9 +3559,9 @@ ${info.actionHint}` : streamError;
3419
3559
  }
3420
3560
  }
3421
3561
  }
3562
+ const requestUserInput = snapshotUserBatchInput(selectAllMsgs(loopState, dialogId));
3422
3563
  const cleanedMessages = filterAndCleanMessages(visibleMessages);
3423
3564
  const ctxWindow = resolveAgentContextWindow(agentConfigForCall);
3424
- const summaryTokenCount = contexts.dialogSummary ? estimateTokenCount(contexts.dialogSummary) : 0;
3425
3565
  const messagesBeforeStrip = compressOldToolResults(cleanedMessages);
3426
3566
  const preprocessedResult = await stripImagePartsForTextOnlyAgent(
3427
3567
  messagesBeforeStrip,
@@ -3432,49 +3572,69 @@ ${info.actionHint}` : streamError;
3432
3572
  messagesBeforeStrip,
3433
3573
  targetUserMessageId: activeTurnUserMessageId2
3434
3574
  });
3435
- let processedMessages = trimMessagesWithSummary(
3436
- preprocessedResult.messages,
3437
- ctxWindow,
3438
- summaryTokenCount
3439
- );
3440
- let firstDynamicIdx = processedMessages.findIndex(
3441
- (m) => m.id && !initialHistoryIds.has(m.id)
3442
- );
3443
- if (firstDynamicIdx === -1) firstDynamicIdx = processedMessages.length;
3444
- let stableMessages = processedMessages.slice(0, firstDynamicIdx);
3445
- let dynamicMessages = processedMessages.slice(firstDynamicIdx);
3446
- const bodyData = generateRequestBody({
3447
- agentConfig: effectiveAgentConfig,
3448
- messages: dynamicMessages,
3449
- stableMessages,
3450
- userInput: userInputText,
3451
- contexts,
3452
- responsesState
3575
+ const { bodyData, fallbackBodyData, dynamicMessages, stableMessages } = await admitWebRequest({
3576
+ contextWindow: ctxWindow,
3577
+ signal: loopController.signal,
3578
+ rescue: (availableHistoryTokens) => updateDialogSummaryAction({
3579
+ dialogKey,
3580
+ force: true,
3581
+ reason: "budget_rescue",
3582
+ availableHistoryTokens,
3583
+ contextWindow: ctxWindow,
3584
+ preserveLatestUserByProjection: true
3585
+ }, { ...thunkApi, signal: loopController.signal }),
3586
+ build: async () => {
3587
+ const summaryConfig = selectById(getState(), dialogKey);
3588
+ const refreshedContexts = { ...contexts, dialogSummary: summaryConfig?.summary || null };
3589
+ const processedMessages = projectSummaryHistory(preprocessedResult.messages, summaryConfig?.summary, summaryConfig?.summarizedBeforeId);
3590
+ let firstDynamicIdx = processedMessages.findIndex(
3591
+ (m) => m.id && !initialHistoryIds.has(m.id)
3592
+ );
3593
+ if (firstDynamicIdx === -1) firstDynamicIdx = processedMessages.length;
3594
+ let stableMessages2 = processedMessages.slice(0, firstDynamicIdx);
3595
+ let dynamicMessages2 = processedMessages.slice(firstDynamicIdx);
3596
+ const bodyData2 = generateRequestBody({
3597
+ agentConfig: effectiveAgentConfig,
3598
+ messages: dynamicMessages2,
3599
+ stableMessages: stableMessages2,
3600
+ userInput: userInputText,
3601
+ contexts: refreshedContexts,
3602
+ responsesState
3603
+ });
3604
+ const fallbackBodyData2 = responsesState ? generateRequestBody({
3605
+ agentConfig: effectiveAgentConfig,
3606
+ messages: dynamicMessages2,
3607
+ stableMessages: stableMessages2,
3608
+ userInput: userInputText,
3609
+ contexts: refreshedContexts,
3610
+ responsesState: null
3611
+ }) : void 0;
3612
+ return { value: { bodyData: bodyData2, fallbackBodyData: fallbackBodyData2, dynamicMessages: dynamicMessages2, stableMessages: stableMessages2 }, wireBodies: [buildResponsesRequestBodyWithTools(bodyData2, agentConfigForCall), ...fallbackBodyData2 ? [buildResponsesRequestBodyWithTools(fallbackBodyData2, agentConfigForCall)] : []] };
3613
+ }
3453
3614
  });
3454
- const fallbackBodyData = responsesState ? generateRequestBody({
3455
- agentConfig: effectiveAgentConfig,
3456
- messages: dynamicMessages,
3457
- stableMessages,
3458
- userInput: userInputText,
3459
- contexts,
3460
- responsesState: null
3461
- }) : void 0;
3462
3615
  logQuickChatPerfStage2(quickChatPerfStartedAt, "stream-agent-model-request-starting", {
3463
3616
  responseApi: true,
3464
3617
  dynamicMessageCount: dynamicMessages.length,
3465
3618
  stableMessageCount: stableMessages.length
3466
3619
  });
3467
3620
  modelRequestStarted = true;
3468
- const meta = await sendOpenAIResponseRequest({
3469
- bodyData,
3470
- agentConfig: agentConfigForCall,
3471
- thunkApi,
3621
+ const meta = await dispatch(runPendingUserBatchRequest({
3472
3622
  dialogKey,
3473
- parentMessageId: currentParentMessageId2,
3474
- messageMetadata: streamingMessageMetadata,
3475
- quickChatPerfStartedAt,
3476
- fallbackBodyData
3477
- });
3623
+ signal: loopController.signal,
3624
+ execution: batchExecution,
3625
+ requestUserInput,
3626
+ start: () => sendOpenAIResponseRequest({
3627
+ bodyData,
3628
+ agentConfig: agentConfigForCall,
3629
+ thunkApi,
3630
+ dialogKey,
3631
+ parentMessageId: currentParentMessageId2,
3632
+ messageMetadata: streamingMessageMetadata,
3633
+ quickChatPerfStartedAt,
3634
+ fallbackBodyData
3635
+ })
3636
+ })).unwrap();
3637
+ if (!meta || loopController.signal.aborted || thunkApi.signal.aborted) break;
3478
3638
  logQuickChatPerfStage2(quickChatPerfStartedAt, "stream-agent-model-request-finished", {
3479
3639
  responseApi: true,
3480
3640
  hasToolCalls: meta.hasToolCalls,
@@ -3524,6 +3684,17 @@ ${info.actionHint}` : streamError;
3524
3684
  if (w2) w2.__LOOP_STOP_REASON__ = "pending";
3525
3685
  break;
3526
3686
  }
3687
+ if (!loopController.signal.aborted && !thunkApi.signal.aborted) {
3688
+ const admitted = await dispatch(admitPendingUserMessages({
3689
+ dialogKey,
3690
+ signal: loopController.signal
3691
+ })).unwrap();
3692
+ if (loopController.signal.aborted || thunkApi.signal.aborted) break;
3693
+ if (admitted.length) {
3694
+ activeTurnUserMessageId2 = admitted[admitted.length - 1].id;
3695
+ continue;
3696
+ }
3697
+ }
3527
3698
  const afterTurnState = getState();
3528
3699
  const queuedMessages = selectPendingUserInputQueue(afterTurnState, dialogKey);
3529
3700
  if (queuedMessages.length > 0) {
@@ -3673,7 +3844,7 @@ ${info.actionHint}` : streamError;
3673
3844
  mergeContexts(staticContexts, dynamicContexts),
3674
3845
  contextBlocks
3675
3846
  );
3676
- const rawMessages = selectAllMsgs(loopState, dialogId);
3847
+ const rawMessages = selectAdmittedMessages(selectAllMsgs(loopState, dialogId));
3677
3848
  let visibleMessages = buildAgentViewMessages(
3678
3849
  rawMessages,
3679
3850
  agentConfigForCall.dbKey
@@ -3701,9 +3872,9 @@ ${info.actionHint}` : streamError;
3701
3872
  }
3702
3873
  }
3703
3874
  }
3875
+ const requestUserInput = snapshotUserBatchInput(selectAllMsgs(loopState, dialogId));
3704
3876
  const cleanedMessages = filterAndCleanMessages(visibleMessages);
3705
3877
  const ctxWindow = resolveAgentContextWindow(agentConfigForCall);
3706
- const summaryTokenCount = contexts.dialogSummary ? estimateTokenCount(contexts.dialogSummary) : 0;
3707
3878
  const messagesBeforeStrip = compressOldToolResults(cleanedMessages);
3708
3879
  const preprocessedResult = await stripImagePartsForTextOnlyAgent(
3709
3880
  messagesBeforeStrip,
@@ -3714,23 +3885,44 @@ ${info.actionHint}` : streamError;
3714
3885
  messagesBeforeStrip,
3715
3886
  targetUserMessageId: activeTurnUserMessageId
3716
3887
  });
3717
- let processedMessages = trimMessagesWithSummary(
3718
- preprocessedResult.messages,
3719
- ctxWindow,
3720
- summaryTokenCount
3721
- );
3722
- let firstDynamicIdx = processedMessages.findIndex(
3723
- (m) => m.id && !initialHistoryIds.has(m.id)
3724
- );
3725
- if (firstDynamicIdx === -1) firstDynamicIdx = processedMessages.length;
3726
- let stableMessages = processedMessages.slice(0, firstDynamicIdx);
3727
- let dynamicMessages = processedMessages.slice(firstDynamicIdx);
3728
- const bodyData = generateRequestBody({
3729
- agentConfig: effectiveAgentConfig,
3730
- messages: dynamicMessages,
3731
- stableMessages,
3732
- userInput: userInputText,
3733
- contexts
3888
+ const { bodyData, dynamicMessages, stableMessages } = await admitWebRequest({
3889
+ contextWindow: ctxWindow,
3890
+ signal: loopController.signal,
3891
+ rescue: (availableHistoryTokens) => updateDialogSummaryAction({
3892
+ dialogKey,
3893
+ force: true,
3894
+ reason: "budget_rescue",
3895
+ availableHistoryTokens,
3896
+ contextWindow: ctxWindow,
3897
+ preserveLatestUserByProjection: true
3898
+ }, { ...thunkApi, signal: loopController.signal }),
3899
+ build: async () => {
3900
+ const summaryConfig = selectById(getState(), dialogKey);
3901
+ const refreshedContexts = { ...contexts, dialogSummary: summaryConfig?.summary || null };
3902
+ const processedMessages = projectSummaryHistory(preprocessedResult.messages, summaryConfig?.summary, summaryConfig?.summarizedBeforeId);
3903
+ let firstDynamicIdx = processedMessages.findIndex(
3904
+ (m) => m.id && !initialHistoryIds.has(m.id)
3905
+ );
3906
+ if (firstDynamicIdx === -1) firstDynamicIdx = processedMessages.length;
3907
+ let stableMessages2 = processedMessages.slice(0, firstDynamicIdx);
3908
+ let dynamicMessages2 = processedMessages.slice(firstDynamicIdx);
3909
+ const bodyData2 = generateRequestBody({
3910
+ agentConfig: effectiveAgentConfig,
3911
+ messages: dynamicMessages2,
3912
+ stableMessages: stableMessages2,
3913
+ userInput: userInputText,
3914
+ contexts: refreshedContexts
3915
+ });
3916
+ const finalBody = await inlineImageUrlsForCustomProvider(
3917
+ buildFinalCompletionsRequestBody(
3918
+ bodyData2,
3919
+ agentConfigForCall,
3920
+ shouldDisableQuickChatToolsForDirectAnswer(quickChatPerfStartedAt, userInput, runtimeOptions, currentDialog)
3921
+ ),
3922
+ { shouldInline: shouldInlineImageUrlsForAgent(agentConfigForCall), signal: loopController.signal }
3923
+ );
3924
+ return { value: { bodyData: finalBody, dynamicMessages: dynamicMessages2, stableMessages: stableMessages2 }, wireBodies: [buildEmptyCompletionRepairBody(finalBody)] };
3925
+ }
3734
3926
  });
3735
3927
  logQuickChatPerfStage2(quickChatPerfStartedAt, "stream-agent-model-request-starting", {
3736
3928
  responseApi: false,
@@ -3754,16 +3946,23 @@ ${info.actionHint}` : streamError;
3754
3946
  }
3755
3947
  );
3756
3948
  }
3757
- const meta = await sendOpenAICompletionsRequest({
3758
- bodyData,
3759
- agentConfig: agentConfigForCall,
3760
- thunkApi,
3949
+ const meta = await dispatch(runPendingUserBatchRequest({
3761
3950
  dialogKey,
3762
- parentMessageId: currentParentMessageId,
3763
- messageMetadata: streamingMessageMetadata,
3764
- disableToolsForThisRequest,
3765
- quickChatPerfStartedAt
3766
- });
3951
+ signal: loopController.signal,
3952
+ execution: batchExecution,
3953
+ requestUserInput,
3954
+ start: () => sendOpenAICompletionsRequest({
3955
+ bodyData,
3956
+ agentConfig: agentConfigForCall,
3957
+ thunkApi,
3958
+ dialogKey,
3959
+ parentMessageId: currentParentMessageId,
3960
+ messageMetadata: streamingMessageMetadata,
3961
+ disableToolsForThisRequest,
3962
+ quickChatPerfStartedAt
3963
+ })
3964
+ })).unwrap();
3965
+ if (!meta || loopController.signal.aborted || thunkApi.signal.aborted) break;
3767
3966
  logQuickChatPerfStage2(quickChatPerfStartedAt, "stream-agent-model-request-finished", {
3768
3967
  responseApi: false,
3769
3968
  hasToolCalls: meta.hasToolCalls,
@@ -3784,6 +3983,17 @@ ${info.actionHint}` : streamError;
3784
3983
  if (w) w.__LOOP_STOP_REASON__ = "pending";
3785
3984
  break;
3786
3985
  }
3986
+ if (!loopController.signal.aborted && !thunkApi.signal.aborted) {
3987
+ const admitted = await dispatch(admitPendingUserMessages({
3988
+ dialogKey,
3989
+ signal: loopController.signal
3990
+ })).unwrap();
3991
+ if (loopController.signal.aborted || thunkApi.signal.aborted) break;
3992
+ if (admitted.length) {
3993
+ activeTurnUserMessageId = admitted[admitted.length - 1].id;
3994
+ continue;
3995
+ }
3996
+ }
3787
3997
  const afterTurnState = getState();
3788
3998
  const queuedMessages = selectPendingUserInputQueue(afterTurnState, dialogKey);
3789
3999
  if (queuedMessages.length > 0) {
@@ -3844,10 +4054,18 @@ ${info.actionHint}` : streamError;
3844
4054
  } else if (!isTurnAborted(error)) {
3845
4055
  setLoopStopReason("error");
3846
4056
  }
4057
+ if (error instanceof DirectApiKeyResolutionError || error?.kind === "credential_missing") {
4058
+ return rejectWithValue({
4059
+ kind: "credential_missing",
4060
+ credentialRef: error.credentialRef,
4061
+ message: error.message
4062
+ });
4063
+ }
3847
4064
  return rejectWithValue(
3848
4065
  error?.message || "An unexpected error occurred in streamAgentChatTurn."
3849
4066
  );
3850
4067
  } finally {
4068
+ batchExecution.dispose();
3851
4069
  clearDialogTurnPhase({ dialogKey: runtimeDialogKey ?? void 0, turnId: turnPhaseTurnId ?? void 0 });
3852
4070
  if (loopKey && runtimeDialogKey) {
3853
4071
  dispatch(removeActiveController({ messageId: loopKey, dialogKey: runtimeDialogKey }));