@mountaya/elements 0.1.0 → 0.2.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 (862) hide show
  1. package/CHANGELOG.md +38 -0
  2. package/README.md +4 -3
  3. package/THIRD-PARTY-NOTICES.txt +1 -1
  4. package/dist/agent/index.cjs +1152 -1905
  5. package/dist/agent/index.cjs.map +1 -1
  6. package/dist/agent/index.d.cts +1152 -1202
  7. package/dist/agent/index.d.ts +1152 -1202
  8. package/dist/agent/index.js +1147 -1903
  9. package/dist/agent/index.js.map +1 -1
  10. package/dist/camera/index.cjs +2470 -3435
  11. package/dist/camera/index.cjs.map +1 -1
  12. package/dist/camera/index.d.cts +716 -744
  13. package/dist/camera/index.d.ts +716 -744
  14. package/dist/camera/index.js +2438 -3323
  15. package/dist/camera/index.js.map +1 -1
  16. package/dist/{units-D9mBrusY.d.cts → chunk-5pTPpv4v.d.cts} +38 -41
  17. package/dist/{units-D9mBrusY.d.ts → chunk-5pTPpv4v.d.ts} +38 -41
  18. package/dist/{order-BLhsGsH8.d.ts → chunk-6JzFMFHh.d.ts} +15 -28
  19. package/dist/chunk-6qyuJVvt.d.ts +513 -0
  20. package/dist/chunk-9fp0lDic.cjs +583 -0
  21. package/dist/chunk-9fp0lDic.cjs.map +1 -0
  22. package/dist/{zones-B05QA8fy.d.ts → chunk-A48H1rDg.d.cts} +2 -4
  23. package/dist/{zones-B05QA8fy.d.cts → chunk-A48H1rDg.d.ts} +2 -4
  24. package/dist/chunk-B-m1AchR.cjs +57 -0
  25. package/dist/chunk-B-m1AchR.cjs.map +1 -0
  26. package/dist/{bundle-xYrrbJTH.d.ts → chunk-B-qFTf04.d.ts} +51 -57
  27. package/dist/chunk-B0YROiZh.d.cts +1475 -0
  28. package/dist/chunk-B14wgOvH.d.cts +68 -0
  29. package/dist/chunk-B19l3j9r.cjs +150 -0
  30. package/dist/chunk-B19l3j9r.cjs.map +1 -0
  31. package/dist/chunk-B2PtjVKg.cjs +86 -0
  32. package/dist/chunk-B2PtjVKg.cjs.map +1 -0
  33. package/dist/chunk-B56Oyb7W.cjs +70 -0
  34. package/dist/chunk-B56Oyb7W.cjs.map +1 -0
  35. package/dist/chunk-B5WGMQwK.cjs +113 -0
  36. package/dist/chunk-B5WGMQwK.cjs.map +1 -0
  37. package/dist/{types-nO2joeRk.d.ts → chunk-B98mKrdu.d.cts} +103 -122
  38. package/dist/{videoOverlay-Dh_D5_Zs.d.ts → chunk-BB0PmqIM.d.cts} +10 -10
  39. package/dist/chunk-BBikve0Z.cjs +269 -0
  40. package/dist/chunk-BBikve0Z.cjs.map +1 -0
  41. package/dist/chunk-BHeXmM0X.js +37 -0
  42. package/dist/chunk-BHeXmM0X.js.map +1 -0
  43. package/dist/chunk-BI8WZLpU.cjs +281 -0
  44. package/dist/chunk-BI8WZLpU.cjs.map +1 -0
  45. package/dist/chunk-BIEc_SkR.cjs +29 -0
  46. package/dist/chunk-BIEc_SkR.cjs.map +1 -0
  47. package/dist/chunk-BJ6L6_W9.cjs +553 -0
  48. package/dist/chunk-BJ6L6_W9.cjs.map +1 -0
  49. package/dist/chunk-BJ91UCbB.js +11 -0
  50. package/dist/chunk-BJ91UCbB.js.map +1 -0
  51. package/dist/chunk-BJEZWTKj.cjs +166 -0
  52. package/dist/chunk-BJEZWTKj.cjs.map +1 -0
  53. package/dist/chunk-BJz54mfg.cjs +10 -0
  54. package/dist/chunk-BJz54mfg.cjs.map +1 -0
  55. package/dist/{sections-CVlc2Inr.d.cts → chunk-BNX5LAfN.d.cts} +289 -330
  56. package/dist/chunk-BP6KgA86.js +35 -0
  57. package/dist/chunk-BP6KgA86.js.map +1 -0
  58. package/dist/{segmentRoute-C5UL_5bp.d.ts → chunk-BRnjQq6K.d.cts} +44 -59
  59. package/dist/chunk-BSiMEwPS.js +46 -0
  60. package/dist/chunk-BSiMEwPS.js.map +1 -0
  61. package/dist/chunk-BTPjDw_y.cjs +16 -0
  62. package/dist/chunk-BTPjDw_y.cjs.map +1 -0
  63. package/dist/chunk-BTUUABGI.js +17 -0
  64. package/dist/chunk-BTUUABGI.js.map +1 -0
  65. package/dist/chunk-BUeL9y7s.cjs +45 -0
  66. package/dist/chunk-BUeL9y7s.cjs.map +1 -0
  67. package/dist/chunk-BWMuCNc9.cjs +172 -0
  68. package/dist/chunk-BWMuCNc9.cjs.map +1 -0
  69. package/dist/chunk-BWjRfhpF.js +126 -0
  70. package/dist/chunk-BWjRfhpF.js.map +1 -0
  71. package/dist/{types-CTQwbSdA.d.cts → chunk-BZ5KyZXI.d.ts} +103 -122
  72. package/dist/chunk-B_4SVmvh.js +94 -0
  73. package/dist/chunk-B_4SVmvh.js.map +1 -0
  74. package/dist/chunk-BcTUuZQ3.js +95 -0
  75. package/dist/chunk-BcTUuZQ3.js.map +1 -0
  76. package/dist/chunk-BdkqSsJe.cjs +140 -0
  77. package/dist/chunk-BdkqSsJe.cjs.map +1 -0
  78. package/dist/chunk-BfktMVmI.js +70 -0
  79. package/dist/chunk-BfktMVmI.js.map +1 -0
  80. package/dist/chunk-BfzQb0EK.cjs +6 -0
  81. package/dist/chunk-BhWfT-22.d.cts +808 -0
  82. package/dist/chunk-BjJcqX5J.cjs +60 -0
  83. package/dist/chunk-BjJcqX5J.cjs.map +1 -0
  84. package/dist/{geodesy-543qXKtI.d.ts → chunk-Bk0L8g5J.d.cts} +3 -4
  85. package/dist/{geodesy-543qXKtI.d.cts → chunk-Bk0L8g5J.d.ts} +3 -4
  86. package/dist/chunk-Bl4_uVa6.cjs +11 -0
  87. package/dist/chunk-Bl4_uVa6.cjs.map +1 -0
  88. package/dist/chunk-BlKF4lrp.js +43 -0
  89. package/dist/chunk-BlKF4lrp.js.map +1 -0
  90. package/dist/chunk-Bm1FieGR.js +4 -0
  91. package/dist/chunk-Bm1FieGR.js.map +1 -0
  92. package/dist/chunk-Bn6ZbxkS.cjs +27 -0
  93. package/dist/chunk-BpN3hr6a.cjs +541 -0
  94. package/dist/chunk-BpN3hr6a.cjs.map +1 -0
  95. package/dist/{order-BZkUwMou.d.cts → chunk-Bq_WHTfd.d.cts} +15 -28
  96. package/dist/chunk-Bqt4LBBz.cjs +648 -0
  97. package/dist/chunk-Bqt4LBBz.cjs.map +1 -0
  98. package/dist/{language-CEWQ5uYw.d.cts → chunk-Bqt97zwf.d.cts} +3 -18
  99. package/dist/{language-CEWQ5uYw.d.ts → chunk-Bqt97zwf.d.ts} +3 -18
  100. package/dist/chunk-BsBiN4w6.d.cts +245 -0
  101. package/dist/chunk-BvTpOUoC.cjs +207 -0
  102. package/dist/chunk-BvTpOUoC.cjs.map +1 -0
  103. package/dist/chunk-BwK6Hl3q.cjs +446 -0
  104. package/dist/chunk-BwK6Hl3q.cjs.map +1 -0
  105. package/dist/{elevationTiles-pmsb9wnU.d.cts → chunk-BxDQZDXR.d.cts} +26 -27
  106. package/dist/{elevationTiles-pmsb9wnU.d.ts → chunk-BxDQZDXR.d.ts} +26 -27
  107. package/dist/chunk-BxUio8kX.js +20 -0
  108. package/dist/chunk-BxUio8kX.js.map +1 -0
  109. package/dist/chunk-BxaocpFi.d.cts +1 -0
  110. package/dist/chunk-Bywi0K1N.js +36 -0
  111. package/dist/chunk-Bywi0K1N.js.map +1 -0
  112. package/dist/chunk-C-IlmkDl.js +59 -0
  113. package/dist/chunk-C-IlmkDl.js.map +1 -0
  114. package/dist/chunk-C5PtVewq.d.ts +389 -0
  115. package/dist/chunk-C5dpC7mQ.js +19 -0
  116. package/dist/chunk-C5dpC7mQ.js.map +1 -0
  117. package/dist/chunk-C5q1sgSa.js +46 -0
  118. package/dist/chunk-C5q1sgSa.js.map +1 -0
  119. package/dist/chunk-C6fU9G5I.cjs +221 -0
  120. package/dist/chunk-C6fU9G5I.cjs.map +1 -0
  121. package/dist/chunk-C71dpWUK.js +5 -0
  122. package/dist/chunk-C71dpWUK.js.map +1 -0
  123. package/dist/chunk-C82N1gQX.d.ts +1831 -0
  124. package/dist/chunk-C8HdaHpu.js +118 -0
  125. package/dist/chunk-C8HdaHpu.js.map +1 -0
  126. package/dist/chunk-C8ZGryck.js +236 -0
  127. package/dist/chunk-C8ZGryck.js.map +1 -0
  128. package/dist/chunk-C95NG0oD.cjs +43 -0
  129. package/dist/chunk-C95NG0oD.cjs.map +1 -0
  130. package/dist/chunk-C9aR8DXb.js +9 -0
  131. package/dist/chunk-C9aR8DXb.js.map +1 -0
  132. package/dist/{camera-C48Ykaxv.d.ts → chunk-CAUZnoCs.d.ts} +135 -159
  133. package/dist/chunk-CBXWWuM9.cjs +82 -0
  134. package/dist/chunk-CBXWWuM9.cjs.map +1 -0
  135. package/dist/chunk-CC_Kquu7.d.cts +125 -0
  136. package/dist/chunk-CC_Kquu7.d.ts +125 -0
  137. package/dist/chunk-CCp85vXg.cjs +60 -0
  138. package/dist/chunk-CCp85vXg.cjs.map +1 -0
  139. package/dist/chunk-CEcB1_uK.js +39 -0
  140. package/dist/chunk-CEcB1_uK.js.map +1 -0
  141. package/dist/{bundle-Je5zsRFg.d.cts → chunk-CFIo021l.d.cts} +51 -57
  142. package/dist/chunk-CH_IZoJE.js +33 -0
  143. package/dist/chunk-CH_IZoJE.js.map +1 -0
  144. package/dist/chunk-CHrasH_g.cjs +25 -0
  145. package/dist/chunk-CHrasH_g.cjs.map +1 -0
  146. package/dist/chunk-CJVoSaAE.cjs +3 -0
  147. package/dist/chunk-CJp8nGcb.js +96 -0
  148. package/dist/chunk-CJp8nGcb.js.map +1 -0
  149. package/dist/chunk-CJwUtkOt.js +112 -0
  150. package/dist/chunk-CJwUtkOt.js.map +1 -0
  151. package/dist/chunk-CKhCOVIf.d.cts +751 -0
  152. package/dist/chunk-CKiVSRYg.js +50 -0
  153. package/dist/chunk-CKiVSRYg.js.map +1 -0
  154. package/dist/chunk-CKtd19eD.cjs +59 -0
  155. package/dist/chunk-CKtd19eD.cjs.map +1 -0
  156. package/dist/chunk-CL92KE3j.d.ts +3188 -0
  157. package/dist/chunk-CLqUlkAe.js +54 -0
  158. package/dist/chunk-CLqUlkAe.js.map +1 -0
  159. package/dist/chunk-CMG5OV0q.cjs +4741 -0
  160. package/dist/chunk-CMG5OV0q.cjs.map +1 -0
  161. package/dist/chunk-CN_TKSgm.js +10 -0
  162. package/dist/chunk-CN_TKSgm.js.map +1 -0
  163. package/dist/chunk-CNe6MtqV.cjs +29 -0
  164. package/dist/chunk-CNe6MtqV.cjs.map +1 -0
  165. package/dist/chunk-COQkDTC5.js +83 -0
  166. package/dist/chunk-COQkDTC5.js.map +1 -0
  167. package/dist/chunk-CPBl6K4M.cjs +168 -0
  168. package/dist/chunk-CPBl6K4M.cjs.map +1 -0
  169. package/dist/chunk-CPx0ZYFB.d.ts +3 -0
  170. package/dist/chunk-CQQhcP_C.d.ts +197 -0
  171. package/dist/chunk-CTNoajFh.d.cts +389 -0
  172. package/dist/chunk-CTd-qgJc.cjs +384 -0
  173. package/dist/chunk-CTd-qgJc.cjs.map +1 -0
  174. package/dist/chunk-CW80YYtU.cjs +1056 -0
  175. package/dist/chunk-CW80YYtU.cjs.map +1 -0
  176. package/dist/{searchLimits-j99-NTXR.d.ts → chunk-CWpqBgkF.d.cts} +2 -2
  177. package/dist/{searchLimits-j99-NTXR.d.cts → chunk-CWpqBgkF.d.ts} +2 -2
  178. package/dist/chunk-CXjRArgy.d.ts +3 -0
  179. package/dist/chunk-CXonfH3-.cjs +14 -0
  180. package/dist/chunk-CXonfH3-.cjs.map +1 -0
  181. package/dist/chunk-CYcouGXN.d.ts +825 -0
  182. package/dist/chunk-CZDAzEBw.cjs +1621 -0
  183. package/dist/chunk-CZDAzEBw.cjs.map +1 -0
  184. package/dist/{amenities-B3-qAjxu.d.cts → chunk-C_fQFr70.d.cts} +40 -41
  185. package/dist/{amenities-B3-qAjxu.d.ts → chunk-C_fQFr70.d.ts} +40 -41
  186. package/dist/chunk-CbOtHnnB.cjs +359 -0
  187. package/dist/chunk-CbOtHnnB.cjs.map +1 -0
  188. package/dist/chunk-CdA6ZMGk.d.cts +825 -0
  189. package/dist/chunk-Ce1_thm7.js +146 -0
  190. package/dist/chunk-Ce1_thm7.js.map +1 -0
  191. package/dist/chunk-CeD8Hw0j.d.cts +3188 -0
  192. package/dist/{camera-BrFLU1DH.d.cts → chunk-CeiTuMyt.d.cts} +135 -159
  193. package/dist/chunk-Ch1OLzLi.js +1 -0
  194. package/dist/chunk-Cizu_j1N.cjs +87 -0
  195. package/dist/chunk-Cizu_j1N.cjs.map +1 -0
  196. package/dist/chunk-CjDe9z6A.d.cts +427 -0
  197. package/dist/chunk-Cl1etdlu.js +63 -0
  198. package/dist/chunk-Cl1etdlu.js.map +1 -0
  199. package/dist/chunk-CmoVJDoz.js +4 -0
  200. package/dist/chunk-CmoVJDoz.js.map +1 -0
  201. package/dist/chunk-CnLucxjG.cjs +197 -0
  202. package/dist/chunk-CnLucxjG.cjs.map +1 -0
  203. package/dist/chunk-CsWjBmdi.cjs +56 -0
  204. package/dist/chunk-CsWjBmdi.cjs.map +1 -0
  205. package/dist/chunk-CuseO5MZ.d.cts +3 -0
  206. package/dist/chunk-CvMHibbA.d.ts +427 -0
  207. package/dist/chunk-CwDeiN5U.js +870 -0
  208. package/dist/chunk-CwDeiN5U.js.map +1 -0
  209. package/dist/chunk-Cwdmx4tG.js +1 -0
  210. package/dist/{geolocation-DDkQdWMN.d.cts → chunk-D-4MxHTt.d.cts} +33 -34
  211. package/dist/{geolocation-DDkQdWMN.d.ts → chunk-D-4MxHTt.d.ts} +33 -34
  212. package/dist/chunk-D0LF-99V.js +1093 -0
  213. package/dist/chunk-D0LF-99V.js.map +1 -0
  214. package/dist/chunk-D1fe-0c_.js +367 -0
  215. package/dist/chunk-D1fe-0c_.js.map +1 -0
  216. package/dist/chunk-D21fEI6A.d.ts +1926 -0
  217. package/dist/chunk-D39gAxya.cjs +89 -0
  218. package/dist/chunk-D39gAxya.cjs.map +1 -0
  219. package/dist/chunk-D6KdIW5e.cjs +228 -0
  220. package/dist/chunk-D6KdIW5e.cjs.map +1 -0
  221. package/dist/chunk-D6qHYbgW.d.cts +36 -0
  222. package/dist/{videoOverlay-Dh_D5_Zs.d.cts → chunk-D89E-w70.d.ts} +10 -10
  223. package/dist/chunk-D8bdTysL.js +552 -0
  224. package/dist/chunk-D8bdTysL.js.map +1 -0
  225. package/dist/chunk-D96QJT24.cjs +109 -0
  226. package/dist/chunk-D96QJT24.cjs.map +1 -0
  227. package/dist/chunk-DAmkQl-i.js +119 -0
  228. package/dist/chunk-DAmkQl-i.js.map +1 -0
  229. package/dist/chunk-DEfsb2lc.cjs +10 -0
  230. package/dist/chunk-DEfsb2lc.cjs.map +1 -0
  231. package/dist/chunk-DIFjT5-V.d.cts +66 -0
  232. package/dist/{sections-CmtaduLc.d.ts → chunk-DJpUw8TN.d.ts} +289 -330
  233. package/dist/chunk-DK6lm2IZ.cjs +11 -0
  234. package/dist/chunk-DK6lm2IZ.cjs.map +1 -0
  235. package/dist/chunk-DKqgr31j.cjs +61 -0
  236. package/dist/chunk-DKqgr31j.cjs.map +1 -0
  237. package/dist/chunk-DLZ0QYm9.js +37 -0
  238. package/dist/chunk-DLZ0QYm9.js.map +1 -0
  239. package/dist/chunk-DLjS0uaC.js +4 -0
  240. package/dist/chunk-DLjS0uaC.js.map +1 -0
  241. package/dist/chunk-DMokwmOV.cjs +49 -0
  242. package/dist/chunk-DMokwmOV.cjs.map +1 -0
  243. package/dist/chunk-DMvWgBZL.d.cts +1831 -0
  244. package/dist/chunk-DNfGfIF3.js +31 -0
  245. package/dist/chunk-DNfGfIF3.js.map +1 -0
  246. package/dist/chunk-DQbSRe8D.d.ts +245 -0
  247. package/dist/chunk-DSGkP8_y.js +45 -0
  248. package/dist/chunk-DSGkP8_y.js.map +1 -0
  249. package/dist/chunk-DTctvfSd.d.cts +197 -0
  250. package/dist/chunk-DWe7igyw.cjs +206 -0
  251. package/dist/chunk-DWe7igyw.cjs.map +1 -0
  252. package/dist/chunk-DWsMP5JR.d.ts +68 -0
  253. package/dist/{provider-DM71XnLX.d.cts → chunk-DWsm3HIW.d.cts} +37 -38
  254. package/dist/{provider-DM71XnLX.d.ts → chunk-DWsm3HIW.d.ts} +37 -38
  255. package/dist/chunk-DXABHjLa.cjs +3 -0
  256. package/dist/chunk-D_BeqSbc.cjs +42 -0
  257. package/dist/chunk-D_BeqSbc.cjs.map +1 -0
  258. package/dist/chunk-D_svQNdW.d.ts +66 -0
  259. package/dist/chunk-Dav4xWrp.js +330 -0
  260. package/dist/chunk-Dav4xWrp.js.map +1 -0
  261. package/dist/chunk-DbCPhepL.js +293 -0
  262. package/dist/chunk-DbCPhepL.js.map +1 -0
  263. package/dist/chunk-DcrTy-y2.cjs +43 -0
  264. package/dist/chunk-DcrTy-y2.cjs.map +1 -0
  265. package/dist/chunk-Ddv484ld.js +487 -0
  266. package/dist/chunk-Ddv484ld.js.map +1 -0
  267. package/dist/chunk-De0bjnhY.cjs +88 -0
  268. package/dist/chunk-De0bjnhY.cjs.map +1 -0
  269. package/dist/chunk-De2FmNPu.cjs +32 -0
  270. package/dist/chunk-De2FmNPu.cjs.map +1 -0
  271. package/dist/{segmentRoute-CIo6dR8Y.d.cts → chunk-DeSjQXiI.d.ts} +44 -59
  272. package/dist/chunk-Den0Ta6C.js +132 -0
  273. package/dist/chunk-Den0Ta6C.js.map +1 -0
  274. package/dist/chunk-DiDKEeEa.js +8 -0
  275. package/dist/chunk-DiDKEeEa.js.map +1 -0
  276. package/dist/chunk-Dj60k5PU.js +197 -0
  277. package/dist/chunk-Dj60k5PU.js.map +1 -0
  278. package/dist/chunk-DjnYQBCN.js +4705 -0
  279. package/dist/chunk-DjnYQBCN.js.map +1 -0
  280. package/dist/chunk-Dk9VKvyq.d.ts +1 -0
  281. package/dist/chunk-Dor1ERI9.cjs +85 -0
  282. package/dist/chunk-Dor1ERI9.cjs.map +1 -0
  283. package/dist/chunk-DpMouOoH.js +451 -0
  284. package/dist/chunk-DpMouOoH.js.map +1 -0
  285. package/dist/chunk-DposgdNL.cjs +52 -0
  286. package/dist/chunk-DposgdNL.cjs.map +1 -0
  287. package/dist/chunk-DqLTG_5Q.d.cts +3 -0
  288. package/dist/{roadAccess-D_rOE4xW.d.cts → chunk-Dr5MCIpS.d.cts} +5 -28
  289. package/dist/{roadAccess-D_rOE4xW.d.ts → chunk-Dr5MCIpS.d.ts} +5 -28
  290. package/dist/chunk-DrudttCC.cjs +4 -0
  291. package/dist/chunk-DsDYVJQC.js +173 -0
  292. package/dist/chunk-DsDYVJQC.js.map +1 -0
  293. package/dist/chunk-Dw8ur6FJ.js +27 -0
  294. package/dist/chunk-Dw8ur6FJ.js.map +1 -0
  295. package/dist/chunk-DwG6M_0v.js +64 -0
  296. package/dist/chunk-DwG6M_0v.js.map +1 -0
  297. package/dist/chunk-Dy9a5ibO.js +284 -0
  298. package/dist/chunk-Dy9a5ibO.js.map +1 -0
  299. package/dist/chunk-DyayZlQJ.js +157 -0
  300. package/dist/chunk-DyayZlQJ.js.map +1 -0
  301. package/dist/chunk-DyhJZC2i.js +126 -0
  302. package/dist/chunk-DyhJZC2i.js.map +1 -0
  303. package/dist/chunk-F9zBzmmG.cjs +45 -0
  304. package/dist/chunk-F9zBzmmG.cjs.map +1 -0
  305. package/dist/chunk-FyCYofv2.js +116 -0
  306. package/dist/chunk-FyCYofv2.js.map +1 -0
  307. package/dist/chunk-GHJRjAk2.js +1 -0
  308. package/dist/chunk-H14isiSf.d.ts +751 -0
  309. package/dist/chunk-HIJzXoN4.js +7 -0
  310. package/dist/chunk-HIJzXoN4.js.map +1 -0
  311. package/dist/chunk-Id_8kRtu.d.ts +36 -0
  312. package/dist/chunk-KN60yxBQ.js +5 -0
  313. package/dist/chunk-KN60yxBQ.js.map +1 -0
  314. package/dist/chunk-NM5yg6bh.cjs +82 -0
  315. package/dist/chunk-NM5yg6bh.cjs.map +1 -0
  316. package/dist/chunk-OXr3zJfM.cjs +119 -0
  317. package/dist/chunk-OXr3zJfM.cjs.map +1 -0
  318. package/dist/chunk-QGqgNC4z.d.ts +928 -0
  319. package/dist/chunk-QJBtJrZ0.js +36 -0
  320. package/dist/chunk-QJBtJrZ0.js.map +1 -0
  321. package/dist/{routeProfile-BsSUABXv.d.cts → chunk-QKWhxfPv.d.cts} +196 -45
  322. package/dist/{routeProfile-BKfSfxx6.d.ts → chunk-QKWhxfPv.d.ts} +196 -45
  323. package/dist/chunk-QXW7b4Ev.d.cts +410 -0
  324. package/dist/chunk-RHZrxUrM.cjs +39 -0
  325. package/dist/chunk-RHZrxUrM.cjs.map +1 -0
  326. package/dist/chunk-RTxe2i66.js +91 -0
  327. package/dist/chunk-RTxe2i66.js.map +1 -0
  328. package/dist/chunk-RrKkJb6P.js +16 -0
  329. package/dist/chunk-RrKkJb6P.js.map +1 -0
  330. package/dist/chunk-VOJqpcnM.cjs +181 -0
  331. package/dist/chunk-VOJqpcnM.cjs.map +1 -0
  332. package/dist/chunk-VljGTrid.js +1 -0
  333. package/dist/chunk-X3UVwUEK.d.cts +513 -0
  334. package/dist/chunk-X9K2WChn.cjs +28 -0
  335. package/dist/chunk-X9K2WChn.cjs.map +1 -0
  336. package/dist/chunk-YrtOx6oy.js +251 -0
  337. package/dist/chunk-YrtOx6oy.js.map +1 -0
  338. package/dist/chunk-bY7ySujI.d.cts +928 -0
  339. package/dist/chunk-bYf1sBz5.d.cts +11 -0
  340. package/dist/chunk-bYf1sBz5.d.ts +11 -0
  341. package/dist/chunk-blfknWoM.d.cts +1926 -0
  342. package/dist/chunk-blqsohAb.js +113 -0
  343. package/dist/chunk-blqsohAb.js.map +1 -0
  344. package/dist/chunk-cDMCjodI.cjs +58 -0
  345. package/dist/chunk-cDMCjodI.cjs.map +1 -0
  346. package/dist/chunk-cWjE3qd6.cjs +10 -0
  347. package/dist/chunk-cWjE3qd6.cjs.map +1 -0
  348. package/dist/chunk-dfOgV3fu.js +26 -0
  349. package/dist/chunk-dfOgV3fu.js.map +1 -0
  350. package/dist/chunk-f9cTwUX1.cjs +125 -0
  351. package/dist/chunk-f9cTwUX1.cjs.map +1 -0
  352. package/dist/chunk-fHVYEZs4.cjs +28 -0
  353. package/dist/chunk-fHVYEZs4.cjs.map +1 -0
  354. package/dist/chunk-fWRUMgRI.js +22 -0
  355. package/dist/chunk-fWRUMgRI.js.map +1 -0
  356. package/dist/{types-BEv8V_8V.d.cts → chunk-fozLXfHY.d.cts} +8 -8
  357. package/dist/{types-BEv8V_8V.d.ts → chunk-fozLXfHY.d.ts} +8 -8
  358. package/dist/chunk-gWmB1l3A.cjs +3122 -0
  359. package/dist/chunk-gWmB1l3A.cjs.map +1 -0
  360. package/dist/chunk-gbj2R-_w.js +58 -0
  361. package/dist/chunk-gbj2R-_w.js.map +1 -0
  362. package/dist/chunk-iIWxsAXd.js +59 -0
  363. package/dist/chunk-iIWxsAXd.js.map +1 -0
  364. package/dist/chunk-lItIuOIS.cjs +137 -0
  365. package/dist/chunk-lItIuOIS.cjs.map +1 -0
  366. package/dist/chunk-m6Rh4PCe.cjs +798 -0
  367. package/dist/chunk-m6Rh4PCe.cjs.map +1 -0
  368. package/dist/chunk-o3IRANDf.cjs +99 -0
  369. package/dist/chunk-o3IRANDf.cjs.map +1 -0
  370. package/dist/chunk-obUcg3Sk.d.ts +808 -0
  371. package/dist/chunk-ohsf-6Rn.js +600 -0
  372. package/dist/chunk-ohsf-6Rn.js.map +1 -0
  373. package/dist/chunk-pBleU6Nv.js +3061 -0
  374. package/dist/chunk-pBleU6Nv.js.map +1 -0
  375. package/dist/chunk-px4e99cy.js +71 -0
  376. package/dist/chunk-px4e99cy.js.map +1 -0
  377. package/dist/chunk-qwYDLeXc.cjs +99 -0
  378. package/dist/chunk-qwYDLeXc.cjs.map +1 -0
  379. package/dist/chunk-rF_859Qk.cjs +101 -0
  380. package/dist/chunk-rF_859Qk.cjs.map +1 -0
  381. package/dist/chunk-rLJkqJ5j.d.ts +1475 -0
  382. package/dist/chunk-twQItIRg.cjs +338 -0
  383. package/dist/chunk-twQItIRg.cjs.map +1 -0
  384. package/dist/chunk-vnPrMVjY.js +10 -0
  385. package/dist/chunk-vnPrMVjY.js.map +1 -0
  386. package/dist/chunk-ws3bVwaS.d.ts +410 -0
  387. package/dist/chunk-xh3UkuVs.cjs +246 -0
  388. package/dist/chunk-xh3UkuVs.cjs.map +1 -0
  389. package/dist/chunk-yMzRr26E.js +153 -0
  390. package/dist/chunk-yMzRr26E.js.map +1 -0
  391. package/dist/collab/index.cjs +802 -1254
  392. package/dist/collab/index.cjs.map +1 -1
  393. package/dist/collab/index.d.cts +518 -544
  394. package/dist/collab/index.d.ts +518 -544
  395. package/dist/collab/index.js +797 -1252
  396. package/dist/collab/index.js.map +1 -1
  397. package/dist/data/index.cjs +39 -132
  398. package/dist/data/index.d.cts +6 -468
  399. package/dist/data/index.d.ts +6 -468
  400. package/dist/data/index.js +7 -15
  401. package/dist/editor/index.cjs +2631 -4424
  402. package/dist/editor/index.cjs.map +1 -1
  403. package/dist/editor/index.d.cts +10 -59
  404. package/dist/editor/index.d.ts +10 -59
  405. package/dist/editor/index.js +2619 -4403
  406. package/dist/editor/index.js.map +1 -1
  407. package/dist/errors/index.cjs +11 -28
  408. package/dist/errors/index.d.cts +2 -125
  409. package/dist/errors/index.d.ts +2 -125
  410. package/dist/errors/index.js +1 -3
  411. package/dist/geo/index.cjs +68 -232
  412. package/dist/geo/index.d.cts +6 -821
  413. package/dist/geo/index.d.ts +6 -821
  414. package/dist/geo/index.js +11 -15
  415. package/dist/i18n/fr/index.cjs +329 -334
  416. package/dist/i18n/fr/index.cjs.map +1 -1
  417. package/dist/i18n/fr/index.d.cts +3 -10
  418. package/dist/i18n/fr/index.d.ts +3 -10
  419. package/dist/i18n/fr/index.js +324 -332
  420. package/dist/i18n/fr/index.js.map +1 -1
  421. package/dist/i18n/index.cjs +434 -447
  422. package/dist/i18n/index.cjs.map +1 -1
  423. package/dist/i18n/index.d.cts +152 -111
  424. package/dist/i18n/index.d.ts +152 -111
  425. package/dist/i18n/index.js +420 -420
  426. package/dist/i18n/index.js.map +1 -1
  427. package/dist/icons/index.cjs +37 -116
  428. package/dist/icons/index.d.cts +4 -457
  429. package/dist/icons/index.d.ts +4 -457
  430. package/dist/icons/index.js +8 -11
  431. package/dist/index.cjs +515 -1867
  432. package/dist/index.cjs.map +1 -1
  433. package/dist/index.d.cts +44 -121
  434. package/dist/index.d.ts +44 -121
  435. package/dist/index.js +52 -65
  436. package/dist/index.js.map +1 -1
  437. package/dist/layers/index.cjs +83 -318
  438. package/dist/layers/index.d.cts +3 -1555
  439. package/dist/layers/index.d.ts +3 -1555
  440. package/dist/layers/index.js +5 -17
  441. package/dist/map-client/index.cjs +5 -4
  442. package/dist/map-client/index.d.cts +6 -1856
  443. package/dist/map-client/index.d.ts +6 -1856
  444. package/dist/map-client/index.js +0 -3
  445. package/dist/maplibre-worker.mjs +4 -4
  446. package/dist/navigation/index.cjs +584 -671
  447. package/dist/navigation/index.cjs.map +1 -1
  448. package/dist/navigation/index.d.cts +191 -272
  449. package/dist/navigation/index.d.ts +191 -272
  450. package/dist/navigation/index.js +579 -669
  451. package/dist/navigation/index.js.map +1 -1
  452. package/dist/profile/index.cjs +177 -675
  453. package/dist/profile/index.d.cts +8 -2086
  454. package/dist/profile/index.d.ts +8 -2086
  455. package/dist/profile/index.js +10 -18
  456. package/dist/seams/index.cjs +15 -39
  457. package/dist/seams/index.d.cts +4 -254
  458. package/dist/seams/index.d.ts +4 -254
  459. package/dist/seams/index.js +4 -6
  460. package/dist/search/index.cjs +39 -147
  461. package/dist/search/index.d.cts +6 -888
  462. package/dist/search/index.d.ts +6 -888
  463. package/dist/search/index.js +3 -14
  464. package/dist/style/index.cjs +34 -116
  465. package/dist/style/index.d.cts +5 -538
  466. package/dist/style/index.d.ts +5 -538
  467. package/dist/style/index.js +5 -11
  468. package/dist/testing/index.cjs +432 -617
  469. package/dist/testing/index.cjs.map +1 -1
  470. package/dist/testing/index.d.cts +61 -109
  471. package/dist/testing/index.d.ts +61 -109
  472. package/dist/testing/index.js +427 -615
  473. package/dist/testing/index.js.map +1 -1
  474. package/dist/timezone/index.cjs +1946 -752
  475. package/dist/timezone/index.cjs.map +1 -1
  476. package/dist/timezone/index.d.cts +4 -29
  477. package/dist/timezone/index.d.ts +4 -29
  478. package/dist/timezone/index.js +1941 -750
  479. package/dist/timezone/index.js.map +1 -1
  480. package/dist/units/index.cjs +29 -99
  481. package/dist/units/index.d.cts +3 -75
  482. package/dist/units/index.d.ts +3 -75
  483. package/dist/units/index.js +3 -6
  484. package/dist/video/index.cjs +1684 -2169
  485. package/dist/video/index.cjs.map +1 -1
  486. package/dist/video/index.d.cts +386 -413
  487. package/dist/video/index.d.ts +386 -413
  488. package/dist/video/index.js +1678 -2162
  489. package/dist/video/index.js.map +1 -1
  490. package/dist/view/index.cjs +6 -42
  491. package/dist/view/index.d.cts +3 -836
  492. package/dist/view/index.d.ts +3 -836
  493. package/dist/view/index.js +1 -34
  494. package/package.json +12 -12
  495. package/src/auth/rules/clientHeader.ts +1 -1
  496. package/src/camera/rules/modes.ts +38 -42
  497. package/src/camera/rules/routeContent.ts +1 -0
  498. package/src/collab/index.ts +1 -5
  499. package/src/compose/engines/mountayaMap.ts +16 -42
  500. package/src/compose/rules/developmentWarnings.ts +4 -3
  501. package/src/compose/rules/fitBox.ts +67 -0
  502. package/src/compose/rules/maplibreWorkerVersion.gen.ts +1 -1
  503. package/src/compose/rules/maxBounds.ts +5 -5
  504. package/src/compose/rules/types.ts +4 -11
  505. package/src/compose/rules/workerUrl.ts +41 -6
  506. package/src/editing/rules/engine.ts +4 -2
  507. package/src/editor/engines/viewClient.ts +8 -0
  508. package/src/editor/rules/contract.ts +1 -6
  509. package/src/errors/rules/errors.ts +1 -0
  510. package/src/geo/index.ts +1 -6
  511. package/src/i18n/index.ts +1 -0
  512. package/src/i18n/rules/dates.ts +165 -0
  513. package/src/index.ts +5 -24
  514. package/src/map-client/rules/mapClient.ts +4 -2
  515. package/src/profile/rules/scale.ts +1 -5
  516. package/src/profile/rules/waypointCard.ts +8 -11
  517. package/src/search/index.ts +3 -18
  518. package/src/video/index.ts +1 -1
  519. package/src/video/profileOverlay/rules/contract.ts +1 -3
  520. package/src/video/rules/videoEncoder.ts +1 -1
  521. package/dist/accentColor-GNKBD2CW.js +0 -4
  522. package/dist/accentColor-GNKBD2CW.js.map +0 -1
  523. package/dist/accentColor-VX2JSMGE.cjs +0 -17
  524. package/dist/accentColor-VX2JSMGE.cjs.map +0 -1
  525. package/dist/chunk-23PFRRB6.js +0 -3
  526. package/dist/chunk-23PFRRB6.js.map +0 -1
  527. package/dist/chunk-2GI5SAH2.js +0 -71
  528. package/dist/chunk-2GI5SAH2.js.map +0 -1
  529. package/dist/chunk-2MQK6A74.js +0 -39
  530. package/dist/chunk-2MQK6A74.js.map +0 -1
  531. package/dist/chunk-2RE7R4LD.js +0 -73
  532. package/dist/chunk-2RE7R4LD.js.map +0 -1
  533. package/dist/chunk-3JZQKN4O.js +0 -6
  534. package/dist/chunk-3JZQKN4O.js.map +0 -1
  535. package/dist/chunk-3NDXVUUI.js +0 -50
  536. package/dist/chunk-3NDXVUUI.js.map +0 -1
  537. package/dist/chunk-3R4GFTUM.cjs +0 -59
  538. package/dist/chunk-3R4GFTUM.cjs.map +0 -1
  539. package/dist/chunk-3RVUQ6JN.cjs +0 -22
  540. package/dist/chunk-3RVUQ6JN.cjs.map +0 -1
  541. package/dist/chunk-4F6BJMJC.cjs +0 -49
  542. package/dist/chunk-4F6BJMJC.cjs.map +0 -1
  543. package/dist/chunk-4NWQD4BX.js +0 -132
  544. package/dist/chunk-4NWQD4BX.js.map +0 -1
  545. package/dist/chunk-5K2MH3R6.js +0 -10
  546. package/dist/chunk-5K2MH3R6.js.map +0 -1
  547. package/dist/chunk-6ACRNQQQ.cjs +0 -8
  548. package/dist/chunk-6ACRNQQQ.cjs.map +0 -1
  549. package/dist/chunk-6D26E3IA.js +0 -66
  550. package/dist/chunk-6D26E3IA.js.map +0 -1
  551. package/dist/chunk-6ESAW35P.cjs +0 -80
  552. package/dist/chunk-6ESAW35P.cjs.map +0 -1
  553. package/dist/chunk-6LIW2A5M.cjs +0 -1176
  554. package/dist/chunk-6LIW2A5M.cjs.map +0 -1
  555. package/dist/chunk-6OTTWVCA.js +0 -57
  556. package/dist/chunk-6OTTWVCA.js.map +0 -1
  557. package/dist/chunk-6VROJ4UG.js +0 -862
  558. package/dist/chunk-6VROJ4UG.js.map +0 -1
  559. package/dist/chunk-6Y7FTGO4.js +0 -23
  560. package/dist/chunk-6Y7FTGO4.js.map +0 -1
  561. package/dist/chunk-75I4CG64.js +0 -104
  562. package/dist/chunk-75I4CG64.js.map +0 -1
  563. package/dist/chunk-7CUBXHAH.cjs +0 -14
  564. package/dist/chunk-7CUBXHAH.cjs.map +0 -1
  565. package/dist/chunk-7GTCURVY.js +0 -52
  566. package/dist/chunk-7GTCURVY.js.map +0 -1
  567. package/dist/chunk-7IWOL6AM.cjs +0 -100
  568. package/dist/chunk-7IWOL6AM.cjs.map +0 -1
  569. package/dist/chunk-7QN7M667.cjs +0 -151
  570. package/dist/chunk-7QN7M667.cjs.map +0 -1
  571. package/dist/chunk-A6KQDKLM.cjs +0 -1197
  572. package/dist/chunk-A6KQDKLM.cjs.map +0 -1
  573. package/dist/chunk-A77EA67G.js +0 -354
  574. package/dist/chunk-A77EA67G.js.map +0 -1
  575. package/dist/chunk-AFKOABJ4.cjs +0 -7194
  576. package/dist/chunk-AFKOABJ4.cjs.map +0 -1
  577. package/dist/chunk-AG6JV5Z2.cjs +0 -183
  578. package/dist/chunk-AG6JV5Z2.cjs.map +0 -1
  579. package/dist/chunk-APBK7NMS.js +0 -30
  580. package/dist/chunk-APBK7NMS.js.map +0 -1
  581. package/dist/chunk-AWO5YA7A.cjs +0 -33
  582. package/dist/chunk-AWO5YA7A.cjs.map +0 -1
  583. package/dist/chunk-AZATU6QW.js +0 -108
  584. package/dist/chunk-AZATU6QW.js.map +0 -1
  585. package/dist/chunk-BD2U3WST.cjs +0 -623
  586. package/dist/chunk-BD2U3WST.cjs.map +0 -1
  587. package/dist/chunk-BHBEOU6L.cjs +0 -65
  588. package/dist/chunk-BHBEOU6L.cjs.map +0 -1
  589. package/dist/chunk-CNOSNYNE.js +0 -8
  590. package/dist/chunk-CNOSNYNE.js.map +0 -1
  591. package/dist/chunk-CW3EFR4O.js +0 -12
  592. package/dist/chunk-CW3EFR4O.js.map +0 -1
  593. package/dist/chunk-DASVRNBK.js +0 -7187
  594. package/dist/chunk-DASVRNBK.js.map +0 -1
  595. package/dist/chunk-DJ6LCKYP.js +0 -42
  596. package/dist/chunk-DJ6LCKYP.js.map +0 -1
  597. package/dist/chunk-E5FHQAIO.cjs +0 -45
  598. package/dist/chunk-E5FHQAIO.cjs.map +0 -1
  599. package/dist/chunk-EOML5OTY.cjs +0 -360
  600. package/dist/chunk-EOML5OTY.cjs.map +0 -1
  601. package/dist/chunk-EP5CASHL.js +0 -613
  602. package/dist/chunk-EP5CASHL.js.map +0 -1
  603. package/dist/chunk-EP5OEEVZ.cjs +0 -14
  604. package/dist/chunk-EP5OEEVZ.cjs.map +0 -1
  605. package/dist/chunk-EUXI3FGQ.js +0 -150
  606. package/dist/chunk-EUXI3FGQ.js.map +0 -1
  607. package/dist/chunk-EWFSHCOS.js +0 -40
  608. package/dist/chunk-EWFSHCOS.js.map +0 -1
  609. package/dist/chunk-EX2C5K2T.cjs +0 -25
  610. package/dist/chunk-EX2C5K2T.cjs.map +0 -1
  611. package/dist/chunk-FEXWDQIZ.cjs +0 -8
  612. package/dist/chunk-FEXWDQIZ.cjs.map +0 -1
  613. package/dist/chunk-FEYBFY7H.cjs +0 -358
  614. package/dist/chunk-FEYBFY7H.cjs.map +0 -1
  615. package/dist/chunk-FRGAV6N6.cjs +0 -34
  616. package/dist/chunk-FRGAV6N6.cjs.map +0 -1
  617. package/dist/chunk-G5DHP5VF.js +0 -6
  618. package/dist/chunk-G5DHP5VF.js.map +0 -1
  619. package/dist/chunk-G5W2UHV2.js +0 -99
  620. package/dist/chunk-G5W2UHV2.js.map +0 -1
  621. package/dist/chunk-G7OP7O2C.cjs +0 -39
  622. package/dist/chunk-G7OP7O2C.cjs.map +0 -1
  623. package/dist/chunk-GE6CFCAM.cjs +0 -25
  624. package/dist/chunk-GE6CFCAM.cjs.map +0 -1
  625. package/dist/chunk-GIFALLHI.cjs +0 -111
  626. package/dist/chunk-GIFALLHI.cjs.map +0 -1
  627. package/dist/chunk-GLFET5GM.js +0 -129
  628. package/dist/chunk-GLFET5GM.js.map +0 -1
  629. package/dist/chunk-GQ6UFPFM.js +0 -22
  630. package/dist/chunk-GQ6UFPFM.js.map +0 -1
  631. package/dist/chunk-GQJWVMXS.js +0 -129
  632. package/dist/chunk-GQJWVMXS.js.map +0 -1
  633. package/dist/chunk-GVVJPUKC.js +0 -80
  634. package/dist/chunk-GVVJPUKC.js.map +0 -1
  635. package/dist/chunk-GZ2HOCQ2.cjs +0 -134
  636. package/dist/chunk-GZ2HOCQ2.cjs.map +0 -1
  637. package/dist/chunk-HCBOHXWP.js +0 -37
  638. package/dist/chunk-HCBOHXWP.js.map +0 -1
  639. package/dist/chunk-IBQJDVHF.cjs +0 -281
  640. package/dist/chunk-IBQJDVHF.cjs.map +0 -1
  641. package/dist/chunk-ISLB6Y5Q.cjs +0 -106
  642. package/dist/chunk-ISLB6Y5Q.cjs.map +0 -1
  643. package/dist/chunk-J55CRR4F.js +0 -105
  644. package/dist/chunk-J55CRR4F.js.map +0 -1
  645. package/dist/chunk-JBG6Z6MQ.cjs +0 -28
  646. package/dist/chunk-JBG6Z6MQ.cjs.map +0 -1
  647. package/dist/chunk-K3RQOZRU.js +0 -61
  648. package/dist/chunk-K3RQOZRU.js.map +0 -1
  649. package/dist/chunk-KDJYS4GB.cjs +0 -703
  650. package/dist/chunk-KDJYS4GB.cjs.map +0 -1
  651. package/dist/chunk-KMCAHUZM.cjs +0 -4
  652. package/dist/chunk-KMCAHUZM.cjs.map +0 -1
  653. package/dist/chunk-KUCBNPC6.js +0 -87
  654. package/dist/chunk-KUCBNPC6.js.map +0 -1
  655. package/dist/chunk-KV6UE5A4.js +0 -50
  656. package/dist/chunk-KV6UE5A4.js.map +0 -1
  657. package/dist/chunk-L6TZ2HQR.cjs +0 -18
  658. package/dist/chunk-L6TZ2HQR.cjs.map +0 -1
  659. package/dist/chunk-L7QHHGG2.cjs +0 -141
  660. package/dist/chunk-L7QHHGG2.cjs.map +0 -1
  661. package/dist/chunk-LHK3Y2AL.js +0 -271
  662. package/dist/chunk-LHK3Y2AL.js.map +0 -1
  663. package/dist/chunk-LO5RYRBH.cjs +0 -6317
  664. package/dist/chunk-LO5RYRBH.cjs.map +0 -1
  665. package/dist/chunk-LS5SJMUO.cjs +0 -194
  666. package/dist/chunk-LS5SJMUO.cjs.map +0 -1
  667. package/dist/chunk-LUGTMZFN.cjs +0 -42
  668. package/dist/chunk-LUGTMZFN.cjs.map +0 -1
  669. package/dist/chunk-LVUQU6D5.js +0 -32
  670. package/dist/chunk-LVUQU6D5.js.map +0 -1
  671. package/dist/chunk-M2QRC2GZ.js +0 -166
  672. package/dist/chunk-M2QRC2GZ.js.map +0 -1
  673. package/dist/chunk-M6QJYQIM.cjs +0 -53
  674. package/dist/chunk-M6QJYQIM.cjs.map +0 -1
  675. package/dist/chunk-MGCPH5EO.js +0 -12
  676. package/dist/chunk-MGCPH5EO.js.map +0 -1
  677. package/dist/chunk-MLVUWEZR.cjs +0 -474
  678. package/dist/chunk-MLVUWEZR.cjs.map +0 -1
  679. package/dist/chunk-MTAMJMZL.cjs +0 -707
  680. package/dist/chunk-MTAMJMZL.cjs.map +0 -1
  681. package/dist/chunk-MXL5AT3N.js +0 -48
  682. package/dist/chunk-MXL5AT3N.js.map +0 -1
  683. package/dist/chunk-MYEQSESM.cjs +0 -75
  684. package/dist/chunk-MYEQSESM.cjs.map +0 -1
  685. package/dist/chunk-N3VPF6ZD.js +0 -427
  686. package/dist/chunk-N3VPF6ZD.js.map +0 -1
  687. package/dist/chunk-N6VUAIGI.js +0 -7
  688. package/dist/chunk-N6VUAIGI.js.map +0 -1
  689. package/dist/chunk-N6XRLUN6.js +0 -6286
  690. package/dist/chunk-N6XRLUN6.js.map +0 -1
  691. package/dist/chunk-NOGDOZIT.cjs +0 -114
  692. package/dist/chunk-NOGDOZIT.cjs.map +0 -1
  693. package/dist/chunk-NUWXEISH.cjs +0 -10
  694. package/dist/chunk-NUWXEISH.cjs.map +0 -1
  695. package/dist/chunk-NZCZHXYN.cjs +0 -161
  696. package/dist/chunk-NZCZHXYN.cjs.map +0 -1
  697. package/dist/chunk-ODROSWQX.cjs +0 -53
  698. package/dist/chunk-ODROSWQX.cjs.map +0 -1
  699. package/dist/chunk-OE36AYKG.cjs +0 -82
  700. package/dist/chunk-OE36AYKG.cjs.map +0 -1
  701. package/dist/chunk-OLON7MO6.cjs +0 -437
  702. package/dist/chunk-OLON7MO6.cjs.map +0 -1
  703. package/dist/chunk-PBUOR2IT.js +0 -277
  704. package/dist/chunk-PBUOR2IT.js.map +0 -1
  705. package/dist/chunk-PC2ELXFF.cjs +0 -225
  706. package/dist/chunk-PC2ELXFF.cjs.map +0 -1
  707. package/dist/chunk-PCSGXLOC.js +0 -71
  708. package/dist/chunk-PCSGXLOC.js.map +0 -1
  709. package/dist/chunk-PFNMP6FQ.js +0 -56
  710. package/dist/chunk-PFNMP6FQ.js.map +0 -1
  711. package/dist/chunk-PIWSZTIP.js +0 -690
  712. package/dist/chunk-PIWSZTIP.js.map +0 -1
  713. package/dist/chunk-PKWHJ2GI.js +0 -136
  714. package/dist/chunk-PKWHJ2GI.js.map +0 -1
  715. package/dist/chunk-PLMVBX2A.cjs +0 -76
  716. package/dist/chunk-PLMVBX2A.cjs.map +0 -1
  717. package/dist/chunk-PM3XCD2G.cjs +0 -113
  718. package/dist/chunk-PM3XCD2G.cjs.map +0 -1
  719. package/dist/chunk-QAL4GZO7.cjs +0 -143
  720. package/dist/chunk-QAL4GZO7.cjs.map +0 -1
  721. package/dist/chunk-QDB2SEA2.js +0 -74
  722. package/dist/chunk-QDB2SEA2.js.map +0 -1
  723. package/dist/chunk-QOV7UNUN.js +0 -25
  724. package/dist/chunk-QOV7UNUN.js.map +0 -1
  725. package/dist/chunk-QQUWYLSF.cjs +0 -50
  726. package/dist/chunk-QQUWYLSF.cjs.map +0 -1
  727. package/dist/chunk-QUMBH3U4.cjs +0 -9
  728. package/dist/chunk-QUMBH3U4.cjs.map +0 -1
  729. package/dist/chunk-R4KA7OFQ.js +0 -12
  730. package/dist/chunk-R4KA7OFQ.js.map +0 -1
  731. package/dist/chunk-RBSGAZQQ.js +0 -17
  732. package/dist/chunk-RBSGAZQQ.js.map +0 -1
  733. package/dist/chunk-RM5YJWZI.js +0 -46
  734. package/dist/chunk-RM5YJWZI.js.map +0 -1
  735. package/dist/chunk-ROKNKXA4.cjs +0 -8
  736. package/dist/chunk-ROKNKXA4.cjs.map +0 -1
  737. package/dist/chunk-RQG6D546.cjs +0 -75
  738. package/dist/chunk-RQG6D546.cjs.map +0 -1
  739. package/dist/chunk-SG4YDD5L.cjs +0 -74
  740. package/dist/chunk-SG4YDD5L.cjs.map +0 -1
  741. package/dist/chunk-SNRCA7EO.js +0 -56
  742. package/dist/chunk-SNRCA7EO.js.map +0 -1
  743. package/dist/chunk-SO75R4WW.cjs +0 -22
  744. package/dist/chunk-SO75R4WW.cjs.map +0 -1
  745. package/dist/chunk-SP34NHFI.js +0 -45
  746. package/dist/chunk-SP34NHFI.js.map +0 -1
  747. package/dist/chunk-SSKSSBWJ.cjs +0 -179
  748. package/dist/chunk-SSKSSBWJ.cjs.map +0 -1
  749. package/dist/chunk-TB5663C2.js +0 -1108
  750. package/dist/chunk-TB5663C2.js.map +0 -1
  751. package/dist/chunk-TGH4NRES.js +0 -220
  752. package/dist/chunk-TGH4NRES.js.map +0 -1
  753. package/dist/chunk-TJ6ZPNID.js +0 -189
  754. package/dist/chunk-TJ6ZPNID.js.map +0 -1
  755. package/dist/chunk-U45T35N2.cjs +0 -90
  756. package/dist/chunk-U45T35N2.cjs.map +0 -1
  757. package/dist/chunk-UKVOPEZ2.js +0 -442
  758. package/dist/chunk-UKVOPEZ2.js.map +0 -1
  759. package/dist/chunk-UTB4NROA.cjs +0 -887
  760. package/dist/chunk-UTB4NROA.cjs.map +0 -1
  761. package/dist/chunk-UTW33B5V.js +0 -6
  762. package/dist/chunk-UTW33B5V.js.map +0 -1
  763. package/dist/chunk-UYUBSD2V.cjs +0 -33
  764. package/dist/chunk-UYUBSD2V.cjs.map +0 -1
  765. package/dist/chunk-V3JEP5AG.cjs +0 -59
  766. package/dist/chunk-V3JEP5AG.cjs.map +0 -1
  767. package/dist/chunk-VFAGJXHR.js +0 -18
  768. package/dist/chunk-VFAGJXHR.js.map +0 -1
  769. package/dist/chunk-VMEE57E5.cjs +0 -58
  770. package/dist/chunk-VMEE57E5.cjs.map +0 -1
  771. package/dist/chunk-VQVBEX3Y.cjs +0 -113
  772. package/dist/chunk-VQVBEX3Y.cjs.map +0 -1
  773. package/dist/chunk-VZDXX7TT.cjs +0 -64
  774. package/dist/chunk-VZDXX7TT.cjs.map +0 -1
  775. package/dist/chunk-WE5ZTI4D.js +0 -346
  776. package/dist/chunk-WE5ZTI4D.js.map +0 -1
  777. package/dist/chunk-WEFUVABP.js +0 -19
  778. package/dist/chunk-WEFUVABP.js.map +0 -1
  779. package/dist/chunk-WMU4LRKC.js +0 -28
  780. package/dist/chunk-WMU4LRKC.js.map +0 -1
  781. package/dist/chunk-WQ24RRHL.cjs +0 -354
  782. package/dist/chunk-WQ24RRHL.cjs.map +0 -1
  783. package/dist/chunk-WW4CGS7G.cjs +0 -26
  784. package/dist/chunk-WW4CGS7G.cjs.map +0 -1
  785. package/dist/chunk-WXE5WCTM.js +0 -1144
  786. package/dist/chunk-WXE5WCTM.js.map +0 -1
  787. package/dist/chunk-X23BGIYA.cjs +0 -37
  788. package/dist/chunk-X23BGIYA.cjs.map +0 -1
  789. package/dist/chunk-XEW4FTR2.js +0 -98
  790. package/dist/chunk-XEW4FTR2.js.map +0 -1
  791. package/dist/chunk-XIOI4IYW.js +0 -167
  792. package/dist/chunk-XIOI4IYW.js.map +0 -1
  793. package/dist/chunk-XLVPJ37V.cjs +0 -44
  794. package/dist/chunk-XLVPJ37V.cjs.map +0 -1
  795. package/dist/chunk-XOHAXXZA.cjs +0 -51
  796. package/dist/chunk-XOHAXXZA.cjs.map +0 -1
  797. package/dist/chunk-Y4NRIHK6.cjs +0 -313
  798. package/dist/chunk-Y4NRIHK6.cjs.map +0 -1
  799. package/dist/chunk-Y4YMMKL3.js +0 -23
  800. package/dist/chunk-Y4YMMKL3.js.map +0 -1
  801. package/dist/chunk-YJNYBVE3.cjs +0 -14
  802. package/dist/chunk-YJNYBVE3.cjs.map +0 -1
  803. package/dist/chunk-Z762QNQP.cjs +0 -60
  804. package/dist/chunk-Z762QNQP.cjs.map +0 -1
  805. package/dist/chunk-ZG5KMBOF.js +0 -669
  806. package/dist/chunk-ZG5KMBOF.js.map +0 -1
  807. package/dist/chunk-ZKONQEFA.js +0 -344
  808. package/dist/chunk-ZKONQEFA.js.map +0 -1
  809. package/dist/chunk-ZR5X7QMH.js +0 -39
  810. package/dist/chunk-ZR5X7QMH.js.map +0 -1
  811. package/dist/chunk-ZW4BJQ26.js +0 -84
  812. package/dist/chunk-ZW4BJQ26.js.map +0 -1
  813. package/dist/climbs-BhlWuu0x.d.ts +0 -70
  814. package/dist/climbs-DgBFwySV.d.cts +0 -70
  815. package/dist/data/index.cjs.map +0 -1
  816. package/dist/data/index.js.map +0 -1
  817. package/dist/errors/index.cjs.map +0 -1
  818. package/dist/errors/index.js.map +0 -1
  819. package/dist/geo/index.cjs.map +0 -1
  820. package/dist/geo/index.js.map +0 -1
  821. package/dist/icons/index.cjs.map +0 -1
  822. package/dist/icons/index.js.map +0 -1
  823. package/dist/itinerary-Dp2ZnqgD.d.cts +0 -178
  824. package/dist/itinerary-Dp2ZnqgD.d.ts +0 -178
  825. package/dist/layers/index.cjs.map +0 -1
  826. package/dist/layers/index.js.map +0 -1
  827. package/dist/map-client/index.cjs.map +0 -1
  828. package/dist/map-client/index.js.map +0 -1
  829. package/dist/markerSprite-DGBQF6PO.cjs +0 -49
  830. package/dist/markerSprite-DGBQF6PO.cjs.map +0 -1
  831. package/dist/markerSprite-DZLTR6F6.js +0 -8
  832. package/dist/markerSprite-DZLTR6F6.js.map +0 -1
  833. package/dist/mountayaMap-C9mxRFib.d.cts +0 -3277
  834. package/dist/mountayaMap-DgnlQ2fE.d.ts +0 -3277
  835. package/dist/paint-BgUcj8l7.d.cts +0 -118
  836. package/dist/paint-Dx_qGNE_.d.ts +0 -118
  837. package/dist/profile/index.cjs.map +0 -1
  838. package/dist/profile/index.js.map +0 -1
  839. package/dist/seams/index.cjs.map +0 -1
  840. package/dist/seams/index.js.map +0 -1
  841. package/dist/search/index.cjs.map +0 -1
  842. package/dist/search/index.js.map +0 -1
  843. package/dist/searchHighlight-DFE7LVIL.cjs +0 -33
  844. package/dist/searchHighlight-DFE7LVIL.cjs.map +0 -1
  845. package/dist/searchHighlight-MHAQZVWG.js +0 -12
  846. package/dist/searchHighlight-MHAQZVWG.js.map +0 -1
  847. package/dist/strings-30RSdIat.d.cts +0 -552
  848. package/dist/strings-DPTIbzT5.d.ts +0 -552
  849. package/dist/stripeImage-CQUXM2YI.js +0 -14
  850. package/dist/stripeImage-CQUXM2YI.js.map +0 -1
  851. package/dist/stripeImage-R43OPA6U.cjs +0 -39
  852. package/dist/stripeImage-R43OPA6U.cjs.map +0 -1
  853. package/dist/style/index.cjs.map +0 -1
  854. package/dist/style/index.js.map +0 -1
  855. package/dist/types-B034JMjl.d.ts +0 -973
  856. package/dist/types-B2NDLxQA.d.cts +0 -21
  857. package/dist/types-B2NDLxQA.d.ts +0 -21
  858. package/dist/types-C8aX5KMU.d.cts +0 -973
  859. package/dist/units/index.cjs.map +0 -1
  860. package/dist/units/index.js.map +0 -1
  861. package/dist/view/index.cjs.map +0 -1
  862. package/dist/view/index.js.map +0 -1
@@ -1,1937 +1,1181 @@
1
- import { statusOf, retryAfterMsOf, reconnectDelayMs, retryAfterDelayMs } from '../chunk-WMU4LRKC.js';
2
- import '../chunk-3JZQKN4O.js';
3
- import { randomUuid, localId } from '../chunk-RM5YJWZI.js';
4
- import { surfaceFault } from '../chunk-Y4YMMKL3.js';
5
- import { MountayaElementsError } from '../chunk-G5W2UHV2.js';
6
-
7
- // src/agent/rules/errorCodes.ts
8
- var agentToolErrorCodes = {
9
- canceled: "canceled",
10
- "capability-denied": "capability-denied",
11
- "collab-locked": "collab-locked",
12
- "confirmation-denied": "confirmation-denied",
13
- "confirmation-timeout": "confirmation-timeout",
14
- conflict: "conflict",
15
- "draft-open": "draft-open",
16
- "edit-in-progress": "edit-in-progress",
17
- forbidden: "forbidden",
18
- internal: "internal",
19
- "invalid-input": "invalid-input",
20
- "limit-reached": "limit-reached",
21
- "not-found": "not-found",
22
- "rate-limited": "rate-limited",
23
- timeout: "timeout",
24
- unavailable: "unavailable",
25
- "unknown-tool": "unknown-tool",
26
- "upgrade-required": "upgrade-required"
1
+ import { t as MountayaElementsError } from "../chunk-Cl1etdlu.js";
2
+ import { n as surfaceFault } from "../chunk-BTUUABGI.js";
3
+ import { n as randomUuid, t as localId } from "../chunk-DNfGfIF3.js";
4
+ import { i as retryAfterDelayMs, n as statusOf, r as reconnectDelayMs, t as retryAfterMsOf } from "../chunk-C5dpC7mQ.js";
5
+ const agentToolErrorCodes = {
6
+ canceled: "canceled",
7
+ "capability-denied": "capability-denied",
8
+ "collab-locked": "collab-locked",
9
+ "confirmation-denied": "confirmation-denied",
10
+ "confirmation-timeout": "confirmation-timeout",
11
+ conflict: "conflict",
12
+ "draft-open": "draft-open",
13
+ "edit-in-progress": "edit-in-progress",
14
+ forbidden: "forbidden",
15
+ internal: "internal",
16
+ "invalid-input": "invalid-input",
17
+ "limit-reached": "limit-reached",
18
+ "not-found": "not-found",
19
+ "rate-limited": "rate-limited",
20
+ timeout: "timeout",
21
+ unavailable: "unavailable",
22
+ "unknown-tool": "unknown-tool",
23
+ "upgrade-required": "upgrade-required"
27
24
  };
28
- var isWireErrorCode = (code) => Object.hasOwn(agentToolErrorCodes, code);
29
- var toWireErrorCode = (code) => {
30
- if (code === void 0) {
31
- return void 0;
32
- }
33
- return isWireErrorCode(code) ? agentToolErrorCodes[code] : "internal";
25
+ const isWireErrorCode = (code) => Object.hasOwn(agentToolErrorCodes, code);
26
+ const toWireErrorCode = (code) => {
27
+ if (code === void 0) return;
28
+ return isWireErrorCode(code) ? agentToolErrorCodes[code] : "internal";
34
29
  };
35
-
36
- // src/agent/rules/toolResultPayload.ts
37
- var MAX_TOOL_RESULT_DATA_BYTES = 4096;
38
- var byteLength = (value) => {
39
- let json;
40
- try {
41
- json = JSON.stringify(value);
42
- } catch {
43
- return null;
44
- }
45
- return json === void 0 ? 0 : new TextEncoder().encode(json).length;
30
+ const MAX_TOOL_RESULT_DATA_BYTES = 4096;
31
+ const byteLength = (value) => {
32
+ let json;
33
+ try {
34
+ json = JSON.stringify(value);
35
+ } catch {
36
+ return null;
37
+ }
38
+ return json === void 0 ? 0 : new TextEncoder().encode(json).length;
46
39
  };
47
- var longestCollection = (data) => {
48
- let longest = null;
49
- for (const [key, value] of Object.entries(data)) {
50
- if (Array.isArray(value) && value.length > (longest?.items.length ?? -1)) {
51
- longest = { items: value, key };
52
- }
53
- }
54
- return longest;
40
+ const longestCollection = (data) => {
41
+ let longest = null;
42
+ for (const [key, value] of Object.entries(data)) if (Array.isArray(value) && value.length > (longest?.items.length ?? -1)) longest = {
43
+ items: value,
44
+ key
45
+ };
46
+ return longest;
55
47
  };
56
- var largestFittingSlice = (items, budget, render) => {
57
- let low = 0;
58
- let high = items.length;
59
- while (low < high) {
60
- const mid = Math.ceil((low + high) / 2);
61
- const size = byteLength(render(mid));
62
- if (size !== null && size <= budget) {
63
- low = mid;
64
- } else {
65
- high = mid - 1;
66
- }
67
- }
68
- return low;
48
+ const largestFittingSlice = (items, budget, render) => {
49
+ let low = 0;
50
+ let high = items.length;
51
+ while (low < high) {
52
+ const mid = Math.ceil((low + high) / 2);
53
+ const size = byteLength(render(mid));
54
+ if (size !== null && size <= budget) low = mid;
55
+ else high = mid - 1;
56
+ }
57
+ return low;
69
58
  };
70
- var buildToolResultPayload = (summary, data, state) => {
71
- const base = { summary, ...state ? { state } : {} };
72
- if (data === void 0 || data === null) {
73
- return base;
74
- }
75
- const size = byteLength(data);
76
- if (size === null) {
77
- return { ...base, truncated: true };
78
- }
79
- if (size === 0) {
80
- return base;
81
- }
82
- if (size <= MAX_TOOL_RESULT_DATA_BYTES) {
83
- return { ...base, data };
84
- }
85
- if (Array.isArray(data)) {
86
- const items = data;
87
- const returned = largestFittingSlice(
88
- items,
89
- MAX_TOOL_RESULT_DATA_BYTES,
90
- (count) => items.slice(0, count)
91
- );
92
- return {
93
- ...base,
94
- data: items.slice(0, returned),
95
- returned,
96
- total: items.length,
97
- truncated: true
98
- };
99
- }
100
- if (typeof data === "object") {
101
- const collection = longestCollection(data);
102
- if (collection !== null) {
103
- const { items, key } = collection;
104
- const returned = largestFittingSlice(items, MAX_TOOL_RESULT_DATA_BYTES, (count) => ({
105
- ...data,
106
- [key]: items.slice(0, count)
107
- }));
108
- if (returned > 0) {
109
- return {
110
- ...base,
111
- data: { ...data, [key]: items.slice(0, returned) },
112
- returned,
113
- total: items.length,
114
- truncated: true,
115
- truncatedField: key
116
- };
117
- }
118
- }
119
- }
120
- return { ...base, truncated: true };
59
+ const buildToolResultPayload = (summary, data, state) => {
60
+ const base = {
61
+ summary,
62
+ ...state ? { state } : {}
63
+ };
64
+ if (data === void 0 || data === null) return base;
65
+ const size = byteLength(data);
66
+ if (size === null) return {
67
+ ...base,
68
+ truncated: true
69
+ };
70
+ if (size === 0) return base;
71
+ if (size <= 4096) return {
72
+ ...base,
73
+ data
74
+ };
75
+ if (Array.isArray(data)) {
76
+ const items = data;
77
+ const returned = largestFittingSlice(items, MAX_TOOL_RESULT_DATA_BYTES, (count) => items.slice(0, count));
78
+ return {
79
+ ...base,
80
+ data: items.slice(0, returned),
81
+ returned,
82
+ total: items.length,
83
+ truncated: true
84
+ };
85
+ }
86
+ if (typeof data === "object") {
87
+ const collection = longestCollection(data);
88
+ if (collection !== null) {
89
+ const { items, key } = collection;
90
+ const returned = largestFittingSlice(items, MAX_TOOL_RESULT_DATA_BYTES, (count) => ({
91
+ ...data,
92
+ [key]: items.slice(0, count)
93
+ }));
94
+ if (returned > 0) return {
95
+ ...base,
96
+ data: {
97
+ ...data,
98
+ [key]: items.slice(0, returned)
99
+ },
100
+ returned,
101
+ total: items.length,
102
+ truncated: true,
103
+ truncatedField: key
104
+ };
105
+ }
106
+ }
107
+ return {
108
+ ...base,
109
+ truncated: true
110
+ };
121
111
  };
122
-
123
- // src/agent/engines/session.ts
124
- var toClientToolManifest = (entries) => entries.map((entry) => ({
125
- ...entry.requiresConfirmation ? { confirms: true } : {},
126
- ...entry.readOnly ? { read_only: true } : {},
127
- description: entry.description,
128
- name: entry.name,
129
- parameters: entry.inputSchema
112
+ const toClientToolManifest = (entries) => entries.map((entry) => ({
113
+ ...entry.requiresConfirmation ? { confirms: true } : {},
114
+ ...entry.readOnly ? { read_only: true } : {},
115
+ description: entry.description,
116
+ name: entry.name,
117
+ parameters: entry.inputSchema
130
118
  }));
131
- var manifestKey = (manifest) => manifest.map((entry) => entry.name).sort().join("\n");
132
- var routedKey = (manifest, serverTools) => `${manifestKey(manifest)}\0${serverTools?.join(",") ?? ""}`;
133
- var AGENT_RECONNECT_BASE_MS = 500;
134
- var RECONNECT_MAX_MS = 8e3;
135
- var reconnectSchedule = {
136
- baseMs: AGENT_RECONNECT_BASE_MS,
137
- maxMs: RECONNECT_MAX_MS
119
+ const manifestKey = (manifest) => manifest.map((entry) => entry.name).sort().join("\n");
120
+ const routedKey = (manifest, serverTools) => `${manifestKey(manifest)}\0${serverTools?.join(",") ?? ""}`;
121
+ const reconnectSchedule = {
122
+ baseMs: 500,
123
+ maxMs: 8e3
138
124
  };
139
- var RECONNECT_MAX_ATTEMPTS = 6;
140
- var RECONNECT_UNAVAILABLE_MAX_MS = 12e4;
141
- var UNAVAILABLE_STATUS = 503;
142
- var PRODUCTIVE_FRAME_COUNT = 1;
143
- var REOPEN_STATUSES = [429, 503, 504];
144
- var isConnectionFault = (error) => {
145
- if (typeof error !== "object" || error === null || !("name" in error)) {
146
- return false;
147
- }
148
- return error.name === "TypeError" || error.name === "MountayaConnectionError";
125
+ const RECONNECT_MAX_ATTEMPTS = 6;
126
+ const RECONNECT_UNAVAILABLE_MAX_MS = 12e4;
127
+ const UNAVAILABLE_STATUS = 503;
128
+ const PRODUCTIVE_FRAME_COUNT = 1;
129
+ const REOPEN_STATUSES = [
130
+ 429,
131
+ 503,
132
+ 504
133
+ ];
134
+ const isConnectionFault = (error) => {
135
+ if (typeof error !== "object" || error === null || !("name" in error)) return false;
136
+ return error.name === "TypeError" || error.name === "MountayaConnectionError";
149
137
  };
150
- var isTransientStreamFault = (error) => {
151
- const status = statusOf(error);
152
- return status === void 0 ? isConnectionFault(error) : REOPEN_STATUSES.includes(status);
138
+ const isTransientStreamFault = (error) => {
139
+ const status = statusOf(error);
140
+ return status === void 0 ? isConnectionFault(error) : REOPEN_STATUSES.includes(status);
153
141
  };
154
- var createPendingStart = () => {
155
- let settle = () => {
156
- };
157
- const opened = new Promise((resolve) => {
158
- settle = resolve;
159
- });
160
- return { opened, settle, withdrawal: new AbortController() };
142
+ const createPendingStart = () => {
143
+ let settle = () => {};
144
+ return {
145
+ opened: new Promise((resolve) => {
146
+ settle = resolve;
147
+ }),
148
+ settle,
149
+ withdrawal: new AbortController()
150
+ };
161
151
  };
162
152
  var AgentEngine = class {
163
- constructor(config) {
164
- this.config = config;
165
- }
166
- config;
167
- currentRunId = null;
168
- // The run this engine adopted and has neither read to its `done` nor closed: the one run it
169
- // still owes a close. It outlives the read when the engine stops reading on its own (the
170
- // reconnect ceiling, two minutes of opens answered 503, an open refused for good), because
171
- // the gateway holds that run open until its own timeout and nobody else was reading it.
172
- // leaveRun and close pay it.
173
- unfinishedRunId = null;
174
- state = "awaiting_input";
175
- /**
176
- * The state the observer was told last. It is {@link state} but from the moment a start
177
- * readies its run until that start reports: the engine rests for those statements, and the
178
- * observer is told the state the start leaves it in, never the rest between two turns.
179
- */
180
- reported = "awaiting_input";
181
- // The claim the sends still being posted have on `running`, or null when the state is not
182
- // theirs alone; see SendHold.
183
- sendHold = null;
184
- // True while the `running` report of a send is on the stack. A send made from inside it lets
185
- // the one that reports make its post first; see send.
186
- sendReporting = false;
187
- // The last position the stream named, by a frame that reached the engine or by a record that
188
- // carries none, sent back as Last-Event-ID so a reconnect resumes after it rather than
189
- // replaying the whole durable history. A frame whose handling threw gives its position back.
190
- lastEventId;
191
- // Aborts the open events stream when the host tears the run down or it ends, so
192
- // a parked consumer and its fetch are released rather than leaked. Replaced each
193
- // time a new stream is opened (a reconnect), and tripped by close(), dispose(), and
194
- // a start() or resume() that replaces the run.
195
- streamAbort = null;
196
- // Unsubscribes from the open events stream. The abort tears the live fetch down;
197
- // this stops the callback delivery (and the scripted drain, which has no fetch).
198
- // Whatever trips the abort trips both; a settle inside consume clears it while it is
199
- // still that read's.
200
- unsubscribe = null;
201
- // Counts the reads beginRun readied, so a read can tell whether a start or a resume made
202
- // from one of the observer's callbacks replaced it while it handled a frame.
203
- readGeneration = 0;
204
- // The tool names the run was last offered, so routeTools can skip a no-op
205
- // update rather than busting the provider's cached prompt prefix for nothing.
206
- routedNames = "";
207
- // Counts the routing updates sent, so each one is numbered in the order the run was sent it.
208
- routingUpdates = 0;
209
- // The number of the update whose selection is recorded, so an answer can tell whether the
210
- // run accepted a later one.
211
- routedUpdate = 0;
212
- // The shutdown latch. dispose() sets it, and from then on start() and resume() open
213
- // nothing: a torn-down engine that started a run would start one nobody reads.
214
- disposed = false;
215
- // The start still waiting on its run id, if one is; see PendingStart.
216
- pendingStart = null;
217
- // The tool_call_ids of the client tool calls the engine ran, of the confirmations it
218
- // answered and of the calls the stream marked settled, in the run named by handledRunId, so
219
- // a frame the stream sends again runs nothing twice and asks nothing twice. A reopen that
220
- // sends no cursor is answered with the run's whole history, the calls already handled
221
- // included.
222
- handledCalls = /* @__PURE__ */ new Set();
223
- handledRunId = null;
224
- // The tool_call_ids of the client tool calls the engine ran and reported itself in the run
225
- // named by handledRunId. Each is reported from the bus result, so what the stream says about
226
- // one afterwards (the gateway's echo of the answer, an abandonment that crossed it) is
227
- // dropped. A call whose handling threw before its report is not among them: what the stream
228
- // says about it is the one report it gets.
229
- dispatchedCalls = /* @__PURE__ */ new Set();
230
- // The client tool calls the engine is running in the run named by handledRunId: claimed, and
231
- // not reported yet. Each maps to the first thing the stream said of the call meanwhile, held
232
- // as the report it would have made, or to null while the stream has said nothing. A read a
233
- // resume opened beside the handling is the one that can say something. The entry goes at
234
- // the engine's own report, which drops the held word, and when the handling throws before
235
- // it, which releases the word.
236
- runningCalls = /* @__PURE__ */ new Map();
237
- /**
238
- * start opens a fresh run with the user's first message, then consumes the
239
- * run's single event stream to completion. The returned promise settles only
240
- * when the engine stops reading the run, so the caller fire-and-forgets it and
241
- * reacts to turns through the observer instead. It resolves on the terminal
242
- * `done`, on {@link close} or {@link dispose}, when a later start or
243
- * {@link resume} replaces the run, and when its reconnects stop being productive.
244
- *
245
- * It rejects when the start or the stream fails for good: a start whose post is
246
- * refused, at once for most answers and, for a 429, a 502, a 503, a 504 or a dropped
247
- * connection, once the transport has repeated it under the start's idempotency key
248
- * as far as its retry policy goes, a stream open answered with anything but a 429,
249
- * 503 or 504, a fault in one of the host's own seams, and a stream that is still
250
- * failing when the reconnect ceiling is reached, whether its connection stays down
251
- * or every open is answered 429 or 504; that one rejects with the last
252
- * failure. A stream that fails leaves the state `ended`, reported through
253
- * `onStateChange("ended")`, before the promise rejects; a start that fails leaves
254
- * it `awaiting_input`.
255
- *
256
- * A stream open answered 503 is not counted against the reconnect ceiling. It says the
257
- * run's events cannot be reached for a moment while the run goes on, so the engine opens
258
- * the stream again, after the wait the answer names, for as long as two minutes of such
259
- * answers with no turn read in between, and then rejects with the last of them.
260
- *
261
- * The state is `running` from the call, reported through `onStateChange("running")` before
262
- * the run has an id, so a host shows the turn as under way from the message. A start that
263
- * fails reports `awaiting_input` again before its promise rejects. The report is the last
264
- * step ahead of the post: a start that fails before it, on a fault in the tool surface,
265
- * never reports `running`.
266
- *
267
- * A start that replaces a run reports that one change and no rest ahead of it: `running`
268
- * from an engine at rest or whose last run ended, and nothing from an engine whose run is
269
- * under way, which reads `running` through the replacement. Where such a start fails, the
270
- * one report is `awaiting_input`.
271
- *
272
- * One engine reads one run. A start while the engine still reads a run tears that
273
- * run's stream down and posts a close for it before it opens its own, so none of
274
- * that run's frames, its resume cursor or its `done` reach the run that replaces
275
- * it. A start while another start still waits on its run id withdraws that start,
276
- * as {@link close} does. A start on an engine whose last run ended opens the next
277
- * run and reads it from its beginning, and posts a close for that last run first when
278
- * the engine stopped reading it short of its `done` (see {@link close}). A start after
279
- * {@link dispose} opens nothing and resolves at once.
280
- *
281
- * Every start carries an `Idempotency-Key` of its own, drawn once per call where the runtime
282
- * has a cryptographic random source, and is posted once: the transport repeats a start whose
283
- * answer was lost under that same key, and the API answers the repeat with the run the key
284
- * already started, so a lost answer never opens a second run. A start the transport gives up
285
- * on rejects with the transport's failure, which carries the key. A custom
286
- * {@link AgentTransport} receives the key as the `idempotencyKey` of the options its `startRun`
287
- * is handed, and none where the runtime offers no source to draw it from.
288
- *
289
- * A {@link close}, a {@link dispose} or a later start or {@link resume} while the start
290
- * still waits on its run id withdraws it: no stream is opened, no run id and no frame of
291
- * the run reaches the observer, and the returned promise resolves even when the start
292
- * itself fails. The run it opens is closed as soon as its id arrives. A withdrawal made from
293
- * inside a state report of the start itself, or from inside the tool surface it reads (the
294
- * bus's `manifest`), comes ahead of the post: nothing is posted, no run is opened and no
295
- * `running` follows the `ended` the withdrawal reported.
296
- *
297
- * @param message The user's first message, which opens the run's first turn.
298
- * @param organizationId The organization that owns the resource the co-pilot is opened on
299
- * (the itinerary or zone being edited). The run is scoped and access-gated to it, and the
300
- * API resolves the AI provider credential through it. It is captured per start because it
301
- * reflects the resource open at the moment the run opens, and the API requires it.
302
- * @param context The caller's point-in-time studio snapshot, forwarded verbatim to the
303
- * gateway's create body so the run starts knowing the current UI state. It is captured per
304
- * start (not held on the session config) because it is a snapshot of the moment the run
305
- * opens. It stays an opaque `Record<string, unknown>` here because its typed shape is the
306
- * host's, which this package does not import: the host builds it and passes it through.
307
- */
308
- async start(message, organizationId, context) {
309
- if (this.disposed) {
310
- return;
311
- }
312
- this.leaveRun();
313
- const pending = createPendingStart();
314
- this.pendingStart = pending;
315
- let runId;
316
- try {
317
- this.beginRun();
318
- const manifest = this.routedManifest();
319
- const serverTools = this.routedServerTools();
320
- if (pending.withdrawal.signal.aborted) {
321
- return;
322
- }
323
- const params = {
324
- client_tools: manifest,
325
- context,
326
- message,
327
- organization_id: organizationId,
328
- profile: this.config.profile,
329
- // Left out rather than sent empty where the session routes no server tool: a key's run
330
- // calls none, and the API refuses a start that names any.
331
- ...serverTools === void 0 ? {} : { server_tools: serverTools }
332
- };
333
- const idempotencyKey = randomUuid();
334
- this.setState("running");
335
- if (pending.withdrawal.signal.aborted) {
336
- return;
337
- }
338
- this.routedNames = routedKey(manifest, serverTools);
339
- ({ runId } = await this.config.transport.startRun(params, { idempotencyKey }));
340
- } catch (error) {
341
- pending.settle(false);
342
- if (!pending.withdrawal.signal.aborted) {
343
- this.setState("awaiting_input");
344
- throw error;
345
- }
346
- return;
347
- } finally {
348
- if (this.pendingStart === pending) {
349
- this.pendingStart = null;
350
- }
351
- }
352
- if (pending.withdrawal.signal.aborted) {
353
- await this.closeQuietly(runId);
354
- return;
355
- }
356
- this.adoptRun(runId);
357
- pending.settle(true);
358
- this.tell((observer) => observer.onRunId?.(runId));
359
- await this.run(runId);
360
- }
361
- /**
362
- * resume re-attaches to an already-started run (e.g. after a page reload) and consumes the
363
- * run's single event stream to completion. It lets a reload reconnect to an
364
- * in-flight conversation rather than starting over. Its promise settles as the
365
- * read of a {@link start} does: it resolves when the engine stops reading the run,
366
- * and rejects when the stream fails for good, the state already `ended`.
367
- *
368
- * `lastEventId` is the stream position to read on from: the gateway replays what follows
369
- * it, then the live feed. Without one the read starts where the engine left the run when
370
- * `runId` is the run it holds (the one it read last, still open or not), so a host that
371
- * kept its transcript re-attaches and is handed nothing a second time. That place is after
372
- * the last frame that reached the engine, the one an observer callback is being handed
373
- * included: a resume made from inside the callback reads on after that frame. A frame whose
374
- * handling threw (a seam that answers: the tool layer, the confirm gate, the tool surface or
375
- * the state delta) is the exception. It is read again, and
376
- * a call the run already claimed is dropped. For any other run the engine holds no position,
377
- * and the gateway answers with the run's whole history: that is the read an engine built
378
- * after a reload makes, and its host starts from an empty transcript. To read the held run
379
- * from its first event again, resume it on a new engine.
380
- *
381
- * Like {@link start}, it reads the run on an engine whose last run ended, opens
382
- * nothing after {@link dispose}, and replaces what the engine reads when it is
383
- * called: another run is torn down and closed, and a start still waiting on its run
384
- * id is withdrawn. A resume of the run the engine is reading tears that read down
385
- * and reads the run again from `lastEventId`, or from where that read was when none is
386
- * passed, and posts no close for it.
387
- *
388
- * The engine is at rest as the read begins, reported through `onStateChange("awaiting_input")`
389
- * from an engine that was `running` or `ended`, and the stream says the rest. A call made
390
- * from inside that report is read before the run is adopted, as one made from a report of a
391
- * {@link start} is: a {@link dispose} ends the resume with no stream opened and no run to
392
- * close, and a start or another resume is the one read the engine makes, so this resume
393
- * resolves at once. A {@link close} made there finds no run held and posts nothing, and the
394
- * resume reads its run.
395
- */
396
- async resume(runId, lastEventId) {
397
- if (this.disposed) {
398
- return;
399
- }
400
- const held = this.currentRunId === runId ? this.lastEventId : void 0;
401
- this.leaveRun(runId);
402
- const generation = this.beginRun();
403
- this.setState("awaiting_input");
404
- if (this.disposed || generation !== this.readGeneration) {
405
- return;
406
- }
407
- this.adoptRun(runId);
408
- this.lastEventId = lastEventId ?? held;
409
- await this.run(runId);
410
- }
411
- /**
412
- * streamPosition reads where the engine stands in the run it read last, for a host that
413
- * replaces the engine and has the next one read the run on.
414
- *
415
- * It is the position a {@link resume} of that run on this engine reads on from: after the last
416
- * frame that reached the engine, or the position a resume was handed while no frame has
417
- * followed it. It is kept through {@link dispose}, which is when a host reads it.
418
- *
419
- * @returns The run and the position, or `null` while the engine has read no run or the run's
420
- * stream has named no position, which is the whole of a run whose frames carry no id.
421
- *
422
- * @example
423
- * ```ts
424
- * import type { AgentEngine } from "@mountaya/elements/agent";
425
- *
426
- * declare const parked: AgentEngine;
427
- * declare const next: AgentEngine;
428
- *
429
- * const position = parked.streamPosition();
430
- * parked.dispose();
431
- * if (position !== null) {
432
- * next.resume(position.runId, position.lastEventId).catch((error: unknown) => {
433
- * console.error(error);
434
- * });
435
- * }
436
- * ```
437
- */
438
- streamPosition() {
439
- return this.currentRunId === null || this.lastEventId === void 0 ? null : { lastEventId: this.lastEventId, runId: this.currentRunId };
440
- }
441
- /**
442
- * runId reads the id of the run the engine holds: the one a {@link start} opened, from the
443
- * moment its post answers, or the one a {@link resume} reads, from the moment it begins. It is
444
- * kept once the engine stops reading that run, whether the run ended, its stream failed, or the
445
- * engine was disposed.
446
- *
447
- * It is what tells the two failures a start rejects with apart. A start whose post the gateway
448
- * refused opened no run, and this reads null; a start whose run opened and whose stream was
449
- * then refused reads that run. The same status says different things on each: a 404 on the post
450
- * is an organization the reader does not reach, and a 404 on the stream is a run the gateway no
451
- * longer holds.
452
- *
453
- * @returns The run's id, or null while the engine holds none: before its first run, and from
454
- * the moment a start replaces a run until the post of that start answers, which a start that
455
- * fails never does.
456
- *
457
- * @example
458
- * ```ts
459
- * import type { AgentEngine } from "@mountaya/elements/agent";
460
- *
461
- * declare const engine: AgentEngine;
462
- * declare const report: (failure: unknown, openedRun: string | null) => void;
463
- *
464
- * engine.start("Plan a loop", "organization-id").catch((failure: unknown) => {
465
- * report(failure, engine.runId());
466
- * });
467
- * ```
468
- */
469
- runId() {
470
- return this.currentRunId;
471
- }
472
- /**
473
- * send delivers a follow-up user message into the open run. It only posts the
474
- * input (the persistent consumer opened by start/resume carries this turn's
475
- * events), so it does NOT open a second stream.
476
- *
477
- * A message sent while a {@link start} still waits on its run id is held until the id
478
- * arrives, then posted into that run, behind the opening of its stream and in the order the
479
- * messages were sent. A start settles only when its run is over, so a caller has no promise
480
- * to wait on before the next message. When that start opens no run (it fails, or a
481
- * {@link close}, a {@link dispose} or a later start or {@link resume} withdraws it), the
482
- * held message is dropped and the promise resolves: the start's rejection, or the call that
483
- * withdrew it, already says the conversation did not open, and a second report of one
484
- * failure is one too many.
485
- *
486
- * The state is `running` from the call the engine takes, reported through
487
- * `onStateChange("running")` when the run was at rest, so the turn's settle is a change the
488
- * observer hears even when the turn sends no frame of its own. A message the engine refuses
489
- * changes nothing. When the post fails, the engine reports `awaiting_input` again before the
490
- * promise rejects, unless another message is still being posted, one of them landed, or the
491
- * stream has reported a state since: the turn is then the stream's to settle.
492
- *
493
- * The report is made ahead of the post, and the message goes into the run it found at the
494
- * call. A {@link close}, a {@link dispose}, a {@link start} or a {@link resume} of another run
495
- * made from inside that report takes the run from the message: nothing is posted and the
496
- * promise resolves, as it does for a message held behind a start that opens no run. A
497
- * {@link resume} of the same run keeps the message, and its turn is the stream's to settle.
498
- * A send made from inside that report is posted after the message that reported, so two
499
- * messages reach the run in the order they were sent.
500
- *
501
- * @throws {MountayaElementsError} when no run is being read and none is on its way: on an
502
- * engine that never opened one, and once the run has ended, been closed or been disposed.
503
- * A run that ended takes no more messages, and one the engine has stopped reading would
504
- * answer to nobody, so the refusal is local rather than a request the gateway refuses. It
505
- * is the package's own error and no stream fault, because it is a misuse of this package,
506
- * which is what a consumer catching {@link MountayaElementsError} is catching. The next
507
- * message goes into a run a new {@link start} opens, except on a disposed engine, which
508
- * opens no more runs: the conversation continues on a new engine.
509
- */
510
- async send(message) {
511
- if (this.sendReporting) {
512
- await Promise.resolve();
513
- }
514
- const pending = this.pendingStart;
515
- if (pending !== null && !await pending.opened) {
516
- return;
517
- }
518
- if (this.disposed) {
519
- throw new MountayaElementsError(
520
- "send: the engine is disposed and opens no more runs. Build a new engine to continue the conversation."
521
- );
522
- }
523
- if (this.state === "ended") {
524
- throw new MountayaElementsError(
525
- "send: the run has ended, and a run that ended takes no more messages. Open the next run with start()."
526
- );
527
- }
528
- const runId = this.currentRunId;
529
- if (runId === null) {
530
- throw new MountayaElementsError(
531
- "send: no run is open. Open one with start(), or re-attach to one with resume(), before sending into it."
532
- );
533
- }
534
- const hold = this.sendHold ?? { found: this.state, posting: 0 };
535
- hold.posting += 1;
536
- this.sendHold = hold;
537
- try {
538
- this.sendReporting = true;
539
- try {
540
- this.reportState("running");
541
- } finally {
542
- this.sendReporting = false;
543
- }
544
- if (!this.reads(runId)) {
545
- return;
546
- }
547
- await this.config.transport.sendInput(runId, { content: message, type: "user-message" });
548
- hold.found = null;
549
- } catch (error) {
550
- if (this.sendHold === hold && hold.posting === 1 && hold.found === "awaiting_input") {
551
- this.setState("awaiting_input");
552
- }
553
- throw error;
554
- } finally {
555
- hold.posting -= 1;
556
- if (this.sendHold === hold && hold.posting === 0) {
557
- this.sendHold = null;
558
- }
559
- }
560
- }
561
- /**
562
- * reads reports whether `runId` is still the run this engine reads: the engine is neither
563
- * disposed nor ended, and no start or resume has put another run in its place.
564
- */
565
- reads(runId) {
566
- return !this.disposed && this.state !== "ended" && this.currentRunId === runId;
567
- }
568
- /**
569
- * routedManifest renders the wire manifest for whatever the toolSurface seam
570
- * currently selects, or the whole permitted set when no router is wired.
571
- */
572
- routedManifest() {
573
- const { bus, ctx, toolSurface } = this.config;
574
- return toClientToolManifest(bus.manifest(ctx.capabilities, toolSurface?.()));
575
- }
576
- /**
577
- * routedServerTools renders the server-tool allowlist for whatever the
578
- * toolSurface seam currently selects: the routed name set verbatim, sorted so
579
- * the wire body and the change key are stable across identical selections.
580
- * The gateway ignores the client-tool names in it, so no registry knowledge
581
- * is needed here. Undefined when no router is wired: the run then keeps
582
- * every server tool. Undefined as well unless the session routes server tools
583
- * ({@link AgentEngineConfig.routesServerTools}): under a publishable key a run
584
- * calls none, and a list naming any is refused, so none is sent.
585
- */
586
- routedServerTools() {
587
- if (this.config.routesServerTools !== true) {
588
- return void 0;
589
- }
590
- const surface = this.config.toolSurface?.();
591
- return surface ? [...surface].sort() : void 0;
592
- }
593
- /**
594
- * routeTools re-reads the toolSurface seam and, when it has moved, replaces the
595
- * tool set the run offers the model from its next turn on. The model then
596
- * chooses among a coherent handful for the task at hand instead of the whole
597
- * registry.
598
- *
599
- * It narrows only what the model can SEE. Every tool stays registered on the
600
- * bus and dispatchable by a human click or an internal tool chain, and the
601
- * capability gate remains the sole authorization boundary, exactly as
602
- * `agentHidden` behaves.
603
- *
604
- * An unchanged selection sends nothing. That is not just a saved request: the
605
- * tool array is the outermost part of the provider's cached prompt prefix, so a
606
- * manifest re-sent on every turn would invalidate the cache every turn and cost
607
- * far more than routing saves. "Unchanged" means changed since the run last
608
- * ACCEPTED a set, so a selection whose POST failed is retried on the next call
609
- * rather than treated as delivered.
610
- *
611
- * It is a no-op before a run exists, rather than a throw: routing is advisory,
612
- * and a surface change while the panel is idle should cost nothing, since the
613
- * next start() sends the current selection as the run's seed anyway.
614
- *
615
- * While a {@link start} still waits on its run id, the seed is already on its way, so the
616
- * call waits for the run as {@link send} does and then routes it with the selection the
617
- * surface holds by then. A routing update and a message held behind one start are released
618
- * in the order they were called, neither waiting on the other's answer, so a caller that
619
- * needs the selection in the run ahead of its message awaits routeTools() before it calls
620
- * {@link send}. When that start opens no run, nothing is sent.
621
- */
622
- async routeTools() {
623
- const pending = this.pendingStart;
624
- if (pending !== null && !await pending.opened) {
625
- return;
626
- }
627
- if (!this.currentRunId || this.state === "ended") {
628
- return;
629
- }
630
- const manifest = this.routedManifest();
631
- const serverTools = this.routedServerTools();
632
- const key = routedKey(manifest, serverTools);
633
- if (key === this.routedNames) {
634
- return;
635
- }
636
- const runId = this.currentRunId;
637
- this.routingUpdates += 1;
638
- const update = this.routingUpdates;
639
- await this.config.transport.sendInput(runId, {
640
- client_tools: manifest,
641
- ...serverTools === void 0 ? {} : { server_tools: serverTools },
642
- type: "manifest-update"
643
- });
644
- if (this.currentRunId === runId && update > this.routedUpdate) {
645
- this.routedNames = key;
646
- this.routedUpdate = update;
647
- }
648
- }
649
- /**
650
- * close asks the run to finish. It POSTs a close so the gateway finishes the
651
- * run successfully (a terminal `done` event), AND aborts the open stream so a
652
- * consumer parked between turns unwinds promptly rather than waiting on the
653
- * gateway to close the connection. The terminal `done`, when it arrives first,
654
- * ends the session.
655
- *
656
- * It closes a run the engine stopped reading on its own just the same: one it gave
657
- * up on at the reconnect ceiling, after two minutes of opens answered 503 or on an
658
- * open refused for good, which the gateway would otherwise hold open until its own
659
- * timeout. A run is closed at most once, and a run that read its `done` is closed
660
- * never: a second call, and a call after `done`, post nothing. So does a call after
661
- * {@link dispose}, which leaves the run it was reading to the host.
662
- *
663
- * During a start that still waits on its run id, close withdraws the start and
664
- * resolves at once, and the start finishes the run it opens (see {@link start}).
665
- */
666
- async close() {
667
- if (this.pendingStart !== null) {
668
- this.withdrawStart();
669
- this.setState("ended");
670
- return;
671
- }
672
- const runId = this.unfinishedRunId;
673
- if (runId === null) {
674
- return;
675
- }
676
- this.unfinishedRunId = null;
677
- this.setState("ended");
678
- this.teardownStream();
679
- await this.config.transport.sendInput(runId, { type: "close" });
680
- }
681
- /**
682
- * dispose tears the session down without signalling the gateway: it aborts the
683
- * open stream and marks the run ended, releasing the parked consumer. The host
684
- * calls it on unmount AFTER close() has POSTed (a closed tab finishes the run),
685
- * with the abort as the backstop when the consumer would otherwise leak.
686
- *
687
- * It is the engine's shutdown latch: {@link start} and {@link resume} open nothing
688
- * afterwards. What it can still cause is what a start sends to finish the run whose id the
689
- * host never received, when it was withdrawn or gave up at its ceiling: that run's close,
690
- * and, when the start's answer was lost, the one last post of the start that names the run
691
- * (see {@link start}).
692
- *
693
- * The run the engine was reading, or stopped reading on its own, is the host's from here:
694
- * the host holds its id, so it can resume it or close it, and a later {@link close} on
695
- * this engine posts nothing for it.
696
- */
697
- dispose() {
698
- this.disposed = true;
699
- this.unfinishedRunId = null;
700
- this.withdrawStart();
701
- this.setState("ended");
702
- this.teardownStream();
703
- }
704
- /**
705
- * leaveRun stops the engine reading what it reads, before a {@link start} or a
706
- * {@link resume} reads a run: one engine reads one run. A start still waiting on its run
707
- * id is withdrawn. A run still being read has its stream torn down, so none of its frames,
708
- * its resume cursor or its `done` reach the run read next. A close is posted for the run the
709
- * engine still owes one (see `unfinishedRunId`): the run it was reading, and the run it
710
- * stopped reading on its own, because in both cases the engine was the one party reading
711
- * it. `next` names the run about to be read, and that run is spared the close when it is
712
- * the one owed it: a resume of it reads it again.
713
- */
714
- leaveRun(next) {
715
- this.withdrawStart();
716
- if (this.currentRunId !== null && this.state !== "ended") {
717
- this.teardownStream();
718
- }
719
- const owed = this.unfinishedRunId;
720
- this.unfinishedRunId = null;
721
- if (owed !== null && owed !== next) {
722
- void this.closeQuietly(owed);
723
- }
724
- }
725
- /**
726
- * withdrawStart withdraws the start still waiting on its run id, if one is: that start then
727
- * finishes the run it opens instead of reading it (see {@link start}), and every message
728
- * and routing update held behind it is dropped (see {@link send}).
729
- */
730
- withdrawStart() {
731
- const pending = this.pendingStart;
732
- this.pendingStart = null;
733
- pending?.settle(false);
734
- pending?.withdrawal.abort();
735
- }
736
- /**
737
- * beginRun readies the engine to read a new run once {@link leaveRun} has stopped it
738
- * reading the last one. The run id, the resume cursor and the stream handle belong to that
739
- * run, so all three go, and the state returns to `awaiting_input`: `ended` would stop the
740
- * read loop before it opened anything.
741
- *
742
- * The rest is the engine's own and is reported to nobody here. A {@link resume} reports it,
743
- * since its run may rest for good. A {@link start} reports `running` next, or the rest once
744
- * it fails, so a start that replaces a run under way is one turn after another to the
745
- * observer and no rest between them ({@link reportState}).
746
- *
747
- * @returns The generation of the read being readied, which a later start or resume replaces.
748
- */
749
- beginRun() {
750
- this.readGeneration += 1;
751
- this.currentRunId = null;
752
- this.lastEventId = void 0;
753
- this.streamAbort = null;
754
- this.sendHold = null;
755
- this.state = "awaiting_input";
756
- return this.readGeneration;
757
- }
758
- /**
759
- * adoptRun makes `runId` the run this engine reads, and the run it owes a close until the
760
- * run's `done` arrives or a close is posted. The memory of handled calls, and of the calls
761
- * the engine reported among them, belongs to one run, because call ids are the run's own: it
762
- * is kept when the run is the one already read (a resume of it) and emptied for any other.
763
- */
764
- adoptRun(runId) {
765
- this.currentRunId = runId;
766
- this.unfinishedRunId = runId;
767
- if (this.handledRunId !== runId) {
768
- this.handledRunId = runId;
769
- this.handledCalls.clear();
770
- this.dispatchedCalls.clear();
771
- this.runningCalls.clear();
772
- }
773
- }
774
- /**
775
- * claimCall records a call id as handled and reports whether the frame that names it is
776
- * the engine's to act on. Two frames are not, and each is dropped whole:
777
- *
778
- * - one whose id the run already sighted, a replay of a call the engine ran or answered
779
- * itself, whose result is already posted;
780
- * - one the stream marks `settled`, a replay of a call whose outcome the stream already
781
- * holds. An engine built after a page reload has no memory of the run, so the marker is
782
- * all that tells it the call was answered.
783
- *
784
- * A settled id is recorded like any other, so a later frame that names it without the
785
- * marker runs nothing either. A replayed frame with no marker and an id never sighted is
786
- * one the stream holds no outcome for, and is the engine's.
787
- */
788
- claimCall(toolCallId, settled) {
789
- const sighted = this.handledCalls.has(toolCallId);
790
- this.handledCalls.add(toolCallId);
791
- return !sighted && settled !== true;
792
- }
793
- /**
794
- * closeQuietly posts a close for a live run the engine leaves behind: one a withdrawn start
795
- * opened and never read, whose id the host never received, and one a later start or resume
796
- * replaced. A failed post is dropped: nobody is
797
- * left to tell, and the gateway completes a run that goes quiet on its own.
798
- */
799
- async closeQuietly(runId) {
800
- try {
801
- await this.config.transport.sendInput(runId, { type: "close" });
802
- } catch {
803
- }
804
- }
805
- /**
806
- * releaseSubscription stops callback delivery from the open stream, exactly
807
- * once. It reads the handle out and clears it BEFORE invoking it, so a
808
- * re-entrant settle (the abort listener firing synchronously inside
809
- * teardownStream, or a transport calling back into onClose) finds nothing
810
- * left to release rather than calling the same handle twice.
811
- */
812
- releaseSubscription() {
813
- const unsubscribe = this.unsubscribe;
814
- this.unsubscribe = null;
815
- unsubscribe?.();
816
- }
817
- /**
818
- * teardownStream releases the open events stream from both sides: the
819
- * unsubscribe stops callback delivery (covering the scripted drain, which has
820
- * no fetch to abort), and the abort closes the live fetch (and trips the resume
821
- * detection in run()). Idempotent, so close() followed by dispose() is harmless.
822
- *
823
- * The unsubscribe runs FIRST because abort() dispatches its listener
824
- * synchronously: that listener settles the read and clears the handle, so
825
- * aborting first would leave nothing to unsubscribe and the scripted drain
826
- * would stay parked for the life of the process.
827
- */
828
- teardownStream() {
829
- this.releaseSubscription();
830
- this.streamAbort?.abort();
831
- }
832
- /**
833
- * run consumes the run's event stream to completion, reconnecting when the
834
- * stream closes before a terminal event. The gateway may close an SSE
835
- * connection between turns (e.g. after `awaiting-input`); rather than leave the
836
- * run silently stuck, run re-opens the stream from the tracked Last-Event-ID so
837
- * the conversation continues. It returns once a terminal event ends the run, an
838
- * abort tears the stream down, or the reconnects stop being productive: an open that
839
- * closes having said nothing or one frame waits on the reconnect schedule, and the
840
- * attempt ceiling below bounds how many of them in a row the run is given.
841
- *
842
- * A read that FAILS is judged by {@link isTransientStreamFault}. A transient one (a
843
- * dropped connection, a 429, 503 or 504 at open) reopens from the last id on the same
844
- * schedule and under the same ceiling as a hangup, and when the ceiling is reached on a
845
- * read that failed, that failure (the drop, or the 429 or 504) is what the caller
846
- * receives. The client's own reader reports an open that never answers and a stream gone
847
- * silent as dropped connections, so both reopen. Any other failure ends the read at once and
848
- * rejects with it. Either way the state is `ended` before the rejection, because the engine
849
- * has stopped reading the run, and the run is owed a close (see {@link close}).
850
- *
851
- * An open answered 503 reopens on that schedule and outside that ceiling: it is left out of
852
- * the count, neither adding to it nor clearing it, and such opens are bounded by
853
- * {@link RECONNECT_UNAVAILABLE_MAX_MS} from the first of them, past which the caller receives
854
- * the 503. A turn that moves starts the count and that time again.
855
- *
856
- * A stream that ends with the credential it was opened with, or that the API could not keep
857
- * delivering (`interrupted`), reopens at once from the last id, and clears the count of
858
- * fruitless opens: the transport closes either as `reconnect`, and the reopen carries the
859
- * session token the client holds by then. A 401 on that reopen is a failure like any other
860
- * refusal, and ends the read.
861
- *
862
- * A teardown ends the read wherever it finds it, the backoff between two opens included:
863
- * a close or a dispose, and a start or a resume that replaced this run (see
864
- * {@link leaveRun}).
865
- */
866
- async run(runId) {
867
- let attempts = 0;
868
- let unavailable = null;
869
- while (this.state !== "ended") {
870
- const abort = new AbortController();
871
- this.streamAbort = abort;
872
- const result = await this.consume(runId, abort.signal);
873
- if (result.ended || abort.signal.aborted) {
874
- return;
875
- }
876
- const { failure } = result;
877
- if (failure !== void 0 && !failure.transient) {
878
- this.setState("ended");
879
- throw failure.error;
880
- }
881
- if (result.reconnect === true) {
882
- attempts = 0;
883
- unavailable = null;
884
- continue;
885
- }
886
- if (result.frames > PRODUCTIVE_FRAME_COUNT) {
887
- attempts = 0;
888
- unavailable = null;
889
- continue;
890
- }
891
- attempts += 1;
892
- if (failure !== void 0 && statusOf(failure.error) === UNAVAILABLE_STATUS) {
893
- unavailable ??= { count: 0, since: Date.now() };
894
- unavailable.count += 1;
895
- if (Date.now() - unavailable.since >= RECONNECT_UNAVAILABLE_MAX_MS) {
896
- this.setState("ended");
897
- throw failure.error;
898
- }
899
- } else if (attempts - (unavailable?.count ?? 0) > RECONNECT_MAX_ATTEMPTS) {
900
- this.setState("ended");
901
- if (failure !== void 0) {
902
- throw failure.error;
903
- }
904
- return;
905
- }
906
- await this.backoff(attempts, abort.signal, retryAfterMsOf(failure?.error));
907
- if (abort.signal.aborted) {
908
- return;
909
- }
910
- }
911
- }
912
- /**
913
- * backoff waits out one reconnect delay, drawn by {@link reconnectDelayMs} on the run's
914
- * {@link reconnectSchedule}: below a ceiling that doubles from AGENT_RECONNECT_BASE_MS to
915
- * RECONNECT_MAX_MS, so the wait stays inside a person's patience and runs dropped together
916
- * do not reopen together. Where the failure was a 429 or a 503 that named its wait (`namedMs`),
917
- * that wait replaces the draw, with up to a second drawn above it and the timer's ceiling over
918
- * it ({@link retryAfterDelayMs}), as SPEC §2 has `Retry-After` replace the schedule. It settles
919
- * on whichever comes first, the timer or the stream teardown's abort, and drops both hooks
920
- * either way: a run that reconnects many times must not accumulate listeners on the signal, nor
921
- * leave a timer holding the loop after the session is gone.
922
- */
923
- backoff(attempts, signal, namedMs) {
924
- const delay = namedMs === void 0 ? reconnectDelayMs(attempts, reconnectSchedule) : retryAfterDelayMs(namedMs);
925
- return new Promise((resolve) => {
926
- const settle = () => {
927
- clearTimeout(timer);
928
- signal.removeEventListener("abort", settle);
929
- resolve();
930
- };
931
- const timer = setTimeout(settle, delay);
932
- signal.addEventListener("abort", settle, { once: true });
933
- });
934
- }
935
- /**
936
- * consume opens one read of the run's events stream and settles when it
937
- * finishes, bridging the transport's AgentStreamHandlers callbacks to a single
938
- * promise run() can await. It reacts to each decoded frame and records its id as
939
- * the resume position when the frame arrives, taking it back when the frame's handling
940
- * throws; the transport has already validated every frame, so it trusts the typed
941
- * event. Unlike a per-turn drive it does NOT stop on
942
- * `awaiting-input` (the stream stays open for the next message). It resolves
943
- * with whether a terminal event ended the run and how many frames the stream
944
- * delivered, so the caller can decide between reconnecting and settling and
945
- * tell a productive open from a fruitless one, and with the failure when the
946
- * read failed. It never rejects, a transport that throws from the open included:
947
- * whether a failure ends the run is run()'s call.
948
- * A terminal the SESSION decides (handle returning true on `done`) tears the
949
- * subscription down here so no further frame is processed after the run is
950
- * over. A teardown's abort (a close, a dispose, or a start or resume that replaced
951
- * the run) settles the promise on its own (the transport fires no callback on a
952
- * deliberate abort), so run() unwinds without waiting on a dead stream.
953
- *
954
- * It is one closure on purpose. Every handler reads and writes this read's own settle
955
- * latch and frame count, and held as fields they would be the next read's to reach.
956
- */
957
- consume(runId, signal) {
958
- return new Promise((resolve) => {
959
- let frames = 0;
960
- let settled = false;
961
- let unsubscribe;
962
- let released = false;
963
- const release = () => {
964
- if (released) {
965
- return;
966
- }
967
- released = true;
968
- unsubscribe?.();
969
- };
970
- const settle = () => {
971
- if (settled) {
972
- return false;
973
- }
974
- settled = true;
975
- signal.removeEventListener("abort", onAbort);
976
- if (this.unsubscribe === release) {
977
- this.unsubscribe = null;
978
- }
979
- release();
980
- return true;
981
- };
982
- const finish = (ended, reconnect = false) => {
983
- if (!settle()) {
984
- return;
985
- }
986
- resolve({ ended, frames, reconnect });
987
- };
988
- const fail = (error, transient) => {
989
- if (!settle()) {
990
- return;
991
- }
992
- resolve({ ended: false, failure: { error, transient }, frames });
993
- };
994
- const onAbort = () => finish(false);
995
- if (signal.aborted) {
996
- finish(false);
997
- return;
998
- }
999
- signal.addEventListener("abort", onAbort, { once: true });
1000
- const handlers = {
1001
- onClose: (reason) => finish(reason === "terminal", reason === "reconnect"),
1002
- onError: (error) => fail(error, isTransientStreamFault(error)),
1003
- onFrame: async (frame) => {
1004
- if (settled) {
1005
- return;
1006
- }
1007
- frames += 1;
1008
- const before = this.lastEventId;
1009
- if (frame.id !== void 0) {
1010
- this.lastEventId = frame.id;
1011
- }
1012
- let ended;
1013
- try {
1014
- ended = await this.handle(runId, frame.event);
1015
- } catch (error) {
1016
- if (frame.id !== void 0 && !settled && this.lastEventId === frame.id) {
1017
- this.lastEventId = before;
1018
- }
1019
- fail(error, false);
1020
- return;
1021
- }
1022
- if (ended) {
1023
- finish(true);
1024
- if (this.streamAbort?.signal === signal) {
1025
- this.teardownStream();
1026
- }
1027
- }
1028
- },
1029
- // A record that names a position and carries no frame moves the cursor too, so a
1030
- // reopen resumes from the last position the stream named. A settled read's report is
1031
- // stale, like its frames.
1032
- onLastEventId: (lastEventId) => {
1033
- if (!settled) {
1034
- this.lastEventId = lastEventId;
1035
- }
1036
- },
1037
- // A frame the transport skips, an event this build does not know or data it cannot read,
1038
- // hands the run nothing and moves no position, and it is still a frame the stream
1039
- // delivered: a stream saying one thing and then one this build skips has said two.
1040
- onSkippedFrame: () => {
1041
- if (!settled) {
1042
- frames += 1;
1043
- }
1044
- }
1045
- };
1046
- try {
1047
- unsubscribe = this.config.transport.subscribe(runId, handlers, {
1048
- lastEventId: this.lastEventId,
1049
- signal
1050
- });
1051
- } catch (error) {
1052
- fail(error, false);
1053
- return;
1054
- }
1055
- if (released) {
1056
- unsubscribe();
1057
- } else {
1058
- this.unsubscribe = release;
1059
- }
1060
- });
1061
- }
1062
- /**
1063
- * handle reacts to one event of the run `runId` names and reports whether the run
1064
- * ended (so consume can stop). An active-turn event (streamed text, a tool call, a
1065
- * confirm request) flips the lifecycle to `running`; a client tool-call is dispatched
1066
- * through the bus and its result posted back; a confirm-required is routed through
1067
- * the host gate and the decision posted back. Both answers go to `runId`, the run that
1068
- * asked, even when a later start or resume replaced it while the tool ran or the host
1069
- * decided. A tool-call or a confirm-required that {@link claimCall} refuses, one the
1070
- * stream marks `settled` or one the run already handled, is dropped whole: it reaches
1071
- * neither the bus, the gate nor the observer, and leaves the lifecycle as it is. An
1072
- * `awaiting-input` event settles the turn to the `awaiting_input` state but
1073
- * keeps the stream open (returns false); only a terminal `done` ends the run (returns
1074
- * true).
1075
- */
1076
- async handle(runId, event) {
1077
- switch (event.type) {
1078
- case "message-delta":
1079
- this.setState("running");
1080
- this.tell((observer) => observer.onMessageDelta?.(event.text));
1081
- return false;
1082
- case "message":
1083
- this.setState("running");
1084
- this.tell((observer) => observer.onMessage?.(event.content, event.message_index));
1085
- return false;
1086
- case "tool-call":
1087
- return this.handleToolCall(runId, event);
1088
- case "confirm-required":
1089
- return this.handleConfirmRequired(runId, event);
1090
- case "budget-exhausted":
1091
- this.tell((observer) => observer.onError?.(event.reason, "budget-exhausted"));
1092
- return false;
1093
- case "error":
1094
- this.tell((observer) => observer.onError?.(event.message, event.code));
1095
- return false;
1096
- case "checks-unmet":
1097
- this.tell((observer) => observer.onChecksUnmet?.(event.unmet));
1098
- return false;
1099
- case "awaiting-input":
1100
- this.setState("awaiting_input");
1101
- return false;
1102
- case "done":
1103
- return this.handleDone(runId, event);
1104
- case "tool-result":
1105
- return this.handleToolResult(event);
1106
- case "tool-abandoned":
1107
- return this.handleToolAbandoned(event);
1108
- case "reconnect":
1109
- return false;
1110
- }
1111
- }
1112
- /**
1113
- * handleToolCall runs one client tool call through the bus, reports it to the observer and
1114
- * posts its result back into the run that asked. It answers false: a tool call never ends
1115
- * the run.
1116
- *
1117
- * The call is running from its claim to its report. What the stream says of it meanwhile is
1118
- * held ({@link holdWhileRunning}), and released when the handling throws before the report:
1119
- * the engine has no report of its own then, and the stream's word settles the host's row.
1120
- */
1121
- async handleToolCall(runId, event) {
1122
- if (!this.claimCall(event.tool_call_id, event.settled)) {
1123
- return false;
1124
- }
1125
- this.runningCalls.set(event.tool_call_id, null);
1126
- try {
1127
- return await this.runToolCall(runId, event);
1128
- } catch (error) {
1129
- this.releaseHeldWord(runId, event.tool_call_id);
1130
- throw error;
1131
- }
1132
- }
1133
- /**
1134
- * releaseHeldWord takes a call out of the running set and delivers what the stream said of it
1135
- * while it ran, when it said anything. A call the engine reported is out of the set already,
1136
- * and so is every call of a run the engine no longer holds the memory of: both release
1137
- * nothing.
1138
- */
1139
- releaseHeldWord(runId, toolCallId) {
1140
- if (this.handledRunId !== runId) {
1141
- return;
1142
- }
1143
- const held = this.runningCalls.get(toolCallId);
1144
- this.runningCalls.delete(toolCallId);
1145
- held?.();
1146
- }
1147
- /**
1148
- * holdWhileRunning keeps what the stream says of a call the engine is still running, as the
1149
- * report it would have made, and answers whether it did. The first word is the one kept: a
1150
- * failed `tool-result` follows the `tool-abandoned` of a call the run gave up on.
1151
- */
1152
- holdWhileRunning(toolCallId, report) {
1153
- if (!this.runningCalls.has(toolCallId)) {
1154
- return false;
1155
- }
1156
- if (this.runningCalls.get(toolCallId) === null) {
1157
- this.runningCalls.set(toolCallId, report);
1158
- }
1159
- return true;
1160
- }
1161
- /** runToolCall is the handling of a claimed client tool call: see {@link handleToolCall}. */
1162
- async runToolCall(runId, event) {
1163
- const { bus, ctx, recoveryFor, stateDelta } = this.config;
1164
- this.setState("running");
1165
- this.tell((observer) => observer.onToolActivity?.(event.name));
1166
- this.tell((observer) => observer.onToolCall?.(event.name, event.input, event.tool_call_id));
1167
- const before = stateDelta?.capture(ctx);
1168
- const result = await bus.dispatchFromModel(ctx, event.name, event.input);
1169
- const moved = stateDelta && before !== void 0 ? stateDelta.diff(before, stateDelta.capture(ctx)) : void 0;
1170
- if (result.ok && result.summary) {
1171
- this.tell((observer) => observer.onToolActivity?.(result.summary));
1172
- }
1173
- const recovery = result.ok ? void 0 : recoveryFor?.(event.name, result.code);
1174
- if (this.handledRunId === runId) {
1175
- this.dispatchedCalls.add(event.tool_call_id);
1176
- this.runningCalls.delete(event.tool_call_id);
1177
- }
1178
- this.tell(
1179
- (observer) => observer.onToolResult?.(
1180
- event.tool_call_id,
1181
- result.ok ? { status: "ok", summary: result.summary } : result.code === "confirmation-denied" ? { status: "abandoned" } : { error: result.error, recovery, status: "error" }
1182
- )
1183
- );
1184
- await this.postInput(runId, {
1185
- ok: result.ok,
1186
- tool_call_id: event.tool_call_id,
1187
- type: "tool-result",
1188
- ...result.ok ? { result: buildToolResultPayload(result.summary, result.data, moved) } : {
1189
- code: toWireErrorCode(result.code),
1190
- error: result.error,
1191
- // What to do about THIS failure of THIS tool, when the playbook
1192
- // says. It rides the failing result rather than the prompt so it
1193
- // costs nothing for the codes that never fire.
1194
- ...recovery ? { recovery } : {}
1195
- }
1196
- });
1197
- return false;
1198
- }
1199
- /**
1200
- * handleConfirmRequired puts a server tool's confirmation to the host gate and posts the
1201
- * decision back into the run that asked. It answers false: a confirmation never ends the
1202
- * run.
1203
- */
1204
- async handleConfirmRequired(runId, event) {
1205
- if (!this.claimCall(event.tool_call_id, event.settled)) {
1206
- return false;
1207
- }
1208
- this.setState("running");
1209
- const approved = await this.config.confirmServerTool({ name: event.name });
1210
- await this.postInput(runId, {
1211
- approved,
1212
- tool_call_id: event.tool_call_id,
1213
- type: "confirm"
1214
- });
1215
- return false;
1216
- }
1217
- /**
1218
- * handleDone reports how the run ended and ends the read, unless a start or a resume made
1219
- * from the callback has already replaced it. It answers true: `done` is the one terminal.
1220
- */
1221
- handleDone(runId, event) {
1222
- if (this.unfinishedRunId === runId) {
1223
- this.unfinishedRunId = null;
1224
- }
1225
- const generation = this.readGeneration;
1226
- this.tell((observer) => observer.onRunEnd?.(event.reason));
1227
- if (generation === this.readGeneration) {
1228
- this.setState("ended");
1229
- }
1230
- return true;
1231
- }
1232
- /**
1233
- * handleToolResult reports a call's outcome as the stream states it, unless the call is one
1234
- * the engine ran and reported itself. It answers false.
1235
- */
1236
- handleToolResult(event) {
1237
- if (this.dispatchedCalls.has(event.tool_call_id)) {
1238
- return false;
1239
- }
1240
- const report = () => {
1241
- const { summary } = event;
1242
- if (summary) {
1243
- this.tell((observer) => observer.onToolActivity?.(summary));
1244
- }
1245
- this.tell(
1246
- (observer) => observer.onToolResult?.(
1247
- event.tool_call_id,
1248
- event.ok ? { status: "ok", summary: event.summary } : { error: event.error, status: "error" }
1249
- )
1250
- );
1251
- };
1252
- if (!this.holdWhileRunning(event.tool_call_id, report)) {
1253
- report();
1254
- }
1255
- return false;
1256
- }
1257
- /**
1258
- * handleToolAbandoned reports a call the run gave up on, unless the call is one the engine
1259
- * ran and reported itself. It answers false.
1260
- */
1261
- handleToolAbandoned(event) {
1262
- if (this.dispatchedCalls.has(event.tool_call_id)) {
1263
- return false;
1264
- }
1265
- const report = () => {
1266
- this.tell(
1267
- (observer) => observer.onToolResult?.(event.tool_call_id, {
1268
- abandonedReason: event.reason,
1269
- status: "abandoned"
1270
- })
1271
- );
1272
- };
1273
- if (!this.holdWhileRunning(event.tool_call_id, report)) {
1274
- report();
1275
- }
1276
- return false;
1277
- }
1278
- /**
1279
- * setState records the lifecycle transition and notifies the observer only on
1280
- * an actual change, so the host does not re-render on a no-op.
1281
- *
1282
- * Every report, a no-op included, drops the hold the sends being posted have on `running`:
1283
- * whatever speaks here (a frame, a close, a new run) owns the state from then on. A send
1284
- * reports its own `running` through {@link reportState}, which keeps the hold.
1285
- */
1286
- setState(next) {
1287
- this.sendHold = null;
1288
- this.reportState(next);
1289
- }
1290
- /**
1291
- * reportState is {@link setState} without the drop of the hold, for the one report that is
1292
- * the hold's own: the `running` of a send.
1293
- *
1294
- * The observer is told a state that differs from the one it was told last, which is the
1295
- * engine's own state but while a start readies its run ({@link beginRun}).
1296
- */
1297
- reportState(next) {
1298
- this.state = next;
1299
- if (this.reported === next) {
1300
- return;
1301
- }
1302
- this.reported = next;
1303
- this.tell((observer) => observer.onStateChange?.(next));
1304
- }
1305
- /**
1306
- * tell hands the observer one report. The observer answers nothing the run waits on, so a
1307
- * callback that throws is a defect of the host's own rendering and never the run's: its fault
1308
- * reaches the program through {@link surfaceFault}, and the read goes on.
1309
- */
1310
- tell(report) {
1311
- try {
1312
- report(this.config.observer);
1313
- } catch (fault) {
1314
- surfaceFault(fault);
1315
- }
1316
- }
1317
- /**
1318
- * postInput sends one input frame back into the run `runId` names, the run that asked
1319
- * for it, and reports a failure as a fault in the conversation instead of throwing.
1320
- *
1321
- * The catch is the point. `start()` ends with `await this.run(runId)`, so the whole
1322
- * consume loop lives inside the start promise, and an unguarded rejection here would
1323
- * leave `handle()` as a fault of the engine's own: the read would end for good, and
1324
- * `start()` would reject into the host's START error path. A network blip on turn
1325
- * twelve would then render "could not start", clear the started guard and drop the run
1326
- * id, so the still-alive gateway run could never be resumed and the model's call would
1327
- * expire as `tool-abandoned` with the user told nothing true about why.
1328
- *
1329
- * Reporting and continuing is the right shape: the run is still open, the stream is
1330
- * still readable, and the gateway abandons the unanswered call on its own timeout so
1331
- * the model can replan. What is lost is one tool result, which is a turn-level fault,
1332
- * not a session-level one. A run a later start or resume replaced has nobody reading
1333
- * it, so a failure to answer it is dropped rather than reported into the run that
1334
- * replaced it. So is a failure to answer a run the engine has stopped reading, after a
1335
- * {@link close} or a {@link dispose}: the host ended that conversation, and an error line
1336
- * under it would report a fault in a run nobody is in.
1337
- *
1338
- * The message is deliberately empty. A fetch rejection carries an English,
1339
- * internal string, and the host resolves an empty message to its own localized
1340
- * generic line, the same rule the run's other self-raised terminals follow.
1341
- */
1342
- async postInput(runId, input) {
1343
- try {
1344
- await this.config.transport.sendInput(runId, input);
1345
- } catch {
1346
- if (this.currentRunId === runId && this.state !== "ended") {
1347
- this.tell((observer) => observer.onError?.(""));
1348
- }
1349
- }
1350
- }
153
+ config;
154
+ currentRunId = null;
155
+ unfinishedRunId = null;
156
+ state = "awaiting_input";
157
+ reported = "awaiting_input";
158
+ sendHold = null;
159
+ sendReporting = false;
160
+ lastEventId;
161
+ streamAbort = null;
162
+ unsubscribe = null;
163
+ readGeneration = 0;
164
+ routedNames = "";
165
+ routingUpdates = 0;
166
+ routedUpdate = 0;
167
+ disposed = false;
168
+ pendingStart = null;
169
+ handledCalls = /* @__PURE__ */ new Set();
170
+ handledRunId = null;
171
+ dispatchedCalls = /* @__PURE__ */ new Set();
172
+ runningCalls = /* @__PURE__ */ new Map();
173
+ constructor(config) {
174
+ this.config = config;
175
+ }
176
+ async start(message, organizationId, context) {
177
+ if (this.disposed) return;
178
+ this.leaveRun();
179
+ const pending = createPendingStart();
180
+ this.pendingStart = pending;
181
+ let runId;
182
+ try {
183
+ this.beginRun();
184
+ const manifest = this.routedManifest();
185
+ const serverTools = this.routedServerTools();
186
+ if (pending.withdrawal.signal.aborted) return;
187
+ const params = {
188
+ client_tools: manifest,
189
+ context,
190
+ message,
191
+ organization_id: organizationId,
192
+ profile: this.config.profile,
193
+ ...serverTools === void 0 ? {} : { server_tools: serverTools }
194
+ };
195
+ const idempotencyKey = randomUuid();
196
+ this.setState("running");
197
+ if (pending.withdrawal.signal.aborted) return;
198
+ this.routedNames = routedKey(manifest, serverTools);
199
+ ({runId} = await this.config.transport.startRun(params, { idempotencyKey }));
200
+ } catch (error) {
201
+ pending.settle(false);
202
+ if (!pending.withdrawal.signal.aborted) {
203
+ this.setState("awaiting_input");
204
+ throw error;
205
+ }
206
+ return;
207
+ } finally {
208
+ if (this.pendingStart === pending) this.pendingStart = null;
209
+ }
210
+ if (pending.withdrawal.signal.aborted) {
211
+ await this.closeQuietly(runId);
212
+ return;
213
+ }
214
+ this.adoptRun(runId);
215
+ pending.settle(true);
216
+ this.tell((observer) => observer.onRunId?.(runId));
217
+ await this.run(runId);
218
+ }
219
+ async resume(runId, lastEventId) {
220
+ if (this.disposed) return;
221
+ const held = this.currentRunId === runId ? this.lastEventId : void 0;
222
+ this.leaveRun(runId);
223
+ const generation = this.beginRun();
224
+ this.setState("awaiting_input");
225
+ if (this.disposed || generation !== this.readGeneration) return;
226
+ this.adoptRun(runId);
227
+ this.lastEventId = lastEventId ?? held;
228
+ await this.run(runId);
229
+ }
230
+ streamPosition() {
231
+ return this.currentRunId === null || this.lastEventId === void 0 ? null : {
232
+ lastEventId: this.lastEventId,
233
+ runId: this.currentRunId
234
+ };
235
+ }
236
+ runId() {
237
+ return this.currentRunId;
238
+ }
239
+ async send(message) {
240
+ if (this.sendReporting) await Promise.resolve();
241
+ const pending = this.pendingStart;
242
+ if (pending !== null && !await pending.opened) return;
243
+ if (this.disposed) throw new MountayaElementsError("send: the engine is disposed and opens no more runs. Build a new engine to continue the conversation.");
244
+ if (this.state === "ended") throw new MountayaElementsError("send: the run has ended, and a run that ended takes no more messages. Open the next run with start().");
245
+ const runId = this.currentRunId;
246
+ if (runId === null) throw new MountayaElementsError("send: no run is open. Open one with start(), or re-attach to one with resume(), before sending into it.");
247
+ const hold = this.sendHold ?? {
248
+ found: this.state,
249
+ posting: 0
250
+ };
251
+ hold.posting += 1;
252
+ this.sendHold = hold;
253
+ try {
254
+ this.sendReporting = true;
255
+ try {
256
+ this.reportState("running");
257
+ } finally {
258
+ this.sendReporting = false;
259
+ }
260
+ if (!this.reads(runId)) return;
261
+ await this.config.transport.sendInput(runId, {
262
+ content: message,
263
+ type: "user-message"
264
+ });
265
+ hold.found = null;
266
+ } catch (error) {
267
+ if (this.sendHold === hold && hold.posting === 1 && hold.found === "awaiting_input") this.setState("awaiting_input");
268
+ throw error;
269
+ } finally {
270
+ hold.posting -= 1;
271
+ if (this.sendHold === hold && hold.posting === 0) this.sendHold = null;
272
+ }
273
+ }
274
+ reads(runId) {
275
+ return !this.disposed && this.state !== "ended" && this.currentRunId === runId;
276
+ }
277
+ routedManifest() {
278
+ const { bus, ctx, toolSurface } = this.config;
279
+ return toClientToolManifest(bus.manifest(ctx.capabilities, toolSurface?.()));
280
+ }
281
+ routedServerTools() {
282
+ if (this.config.routesServerTools !== true) return;
283
+ const surface = this.config.toolSurface?.();
284
+ return surface ? [...surface].sort() : void 0;
285
+ }
286
+ async routeTools() {
287
+ const pending = this.pendingStart;
288
+ if (pending !== null && !await pending.opened) return;
289
+ if (!this.currentRunId || this.state === "ended") return;
290
+ const manifest = this.routedManifest();
291
+ const serverTools = this.routedServerTools();
292
+ const key = routedKey(manifest, serverTools);
293
+ if (key === this.routedNames) return;
294
+ const runId = this.currentRunId;
295
+ this.routingUpdates += 1;
296
+ const update = this.routingUpdates;
297
+ await this.config.transport.sendInput(runId, {
298
+ client_tools: manifest,
299
+ ...serverTools === void 0 ? {} : { server_tools: serverTools },
300
+ type: "manifest-update"
301
+ });
302
+ if (this.currentRunId === runId && update > this.routedUpdate) {
303
+ this.routedNames = key;
304
+ this.routedUpdate = update;
305
+ }
306
+ }
307
+ async close() {
308
+ if (this.pendingStart !== null) {
309
+ this.withdrawStart();
310
+ this.setState("ended");
311
+ return;
312
+ }
313
+ const runId = this.unfinishedRunId;
314
+ if (runId === null) return;
315
+ this.unfinishedRunId = null;
316
+ this.setState("ended");
317
+ this.teardownStream();
318
+ await this.config.transport.sendInput(runId, { type: "close" });
319
+ }
320
+ dispose() {
321
+ this.disposed = true;
322
+ this.unfinishedRunId = null;
323
+ this.withdrawStart();
324
+ this.setState("ended");
325
+ this.teardownStream();
326
+ }
327
+ leaveRun(next) {
328
+ this.withdrawStart();
329
+ if (this.currentRunId !== null && this.state !== "ended") this.teardownStream();
330
+ const owed = this.unfinishedRunId;
331
+ this.unfinishedRunId = null;
332
+ if (owed !== null && owed !== next) this.closeQuietly(owed);
333
+ }
334
+ withdrawStart() {
335
+ const pending = this.pendingStart;
336
+ this.pendingStart = null;
337
+ pending?.settle(false);
338
+ pending?.withdrawal.abort();
339
+ }
340
+ beginRun() {
341
+ this.readGeneration += 1;
342
+ this.currentRunId = null;
343
+ this.lastEventId = void 0;
344
+ this.streamAbort = null;
345
+ this.sendHold = null;
346
+ this.state = "awaiting_input";
347
+ return this.readGeneration;
348
+ }
349
+ adoptRun(runId) {
350
+ this.currentRunId = runId;
351
+ this.unfinishedRunId = runId;
352
+ if (this.handledRunId !== runId) {
353
+ this.handledRunId = runId;
354
+ this.handledCalls.clear();
355
+ this.dispatchedCalls.clear();
356
+ this.runningCalls.clear();
357
+ }
358
+ }
359
+ claimCall(toolCallId, settled) {
360
+ const sighted = this.handledCalls.has(toolCallId);
361
+ this.handledCalls.add(toolCallId);
362
+ return !sighted && settled !== true;
363
+ }
364
+ async closeQuietly(runId) {
365
+ try {
366
+ await this.config.transport.sendInput(runId, { type: "close" });
367
+ } catch {}
368
+ }
369
+ releaseSubscription() {
370
+ const unsubscribe = this.unsubscribe;
371
+ this.unsubscribe = null;
372
+ unsubscribe?.();
373
+ }
374
+ teardownStream() {
375
+ this.releaseSubscription();
376
+ this.streamAbort?.abort();
377
+ }
378
+ async run(runId) {
379
+ let attempts = 0;
380
+ let unavailable = null;
381
+ while (this.state !== "ended") {
382
+ const abort = new AbortController();
383
+ this.streamAbort = abort;
384
+ const result = await this.consume(runId, abort.signal);
385
+ if (result.ended || abort.signal.aborted) return;
386
+ const { failure } = result;
387
+ if (failure !== void 0 && !failure.transient) {
388
+ this.setState("ended");
389
+ throw failure.error;
390
+ }
391
+ if (result.reconnect === true) {
392
+ attempts = 0;
393
+ unavailable = null;
394
+ continue;
395
+ }
396
+ if (result.frames > PRODUCTIVE_FRAME_COUNT) {
397
+ attempts = 0;
398
+ unavailable = null;
399
+ continue;
400
+ }
401
+ attempts += 1;
402
+ if (failure !== void 0 && statusOf(failure.error) === UNAVAILABLE_STATUS) {
403
+ unavailable ??= {
404
+ count: 0,
405
+ since: Date.now()
406
+ };
407
+ unavailable.count += 1;
408
+ if (Date.now() - unavailable.since >= RECONNECT_UNAVAILABLE_MAX_MS) {
409
+ this.setState("ended");
410
+ throw failure.error;
411
+ }
412
+ } else if (attempts - (unavailable?.count ?? 0) > RECONNECT_MAX_ATTEMPTS) {
413
+ this.setState("ended");
414
+ if (failure !== void 0) throw failure.error;
415
+ return;
416
+ }
417
+ await this.backoff(attempts, abort.signal, retryAfterMsOf(failure?.error));
418
+ if (abort.signal.aborted) return;
419
+ }
420
+ }
421
+ backoff(attempts, signal, namedMs) {
422
+ const delay = namedMs === void 0 ? reconnectDelayMs(attempts, reconnectSchedule) : retryAfterDelayMs(namedMs);
423
+ return new Promise((resolve) => {
424
+ const settle = () => {
425
+ clearTimeout(timer);
426
+ signal.removeEventListener("abort", settle);
427
+ resolve();
428
+ };
429
+ const timer = setTimeout(settle, delay);
430
+ signal.addEventListener("abort", settle, { once: true });
431
+ });
432
+ }
433
+ consume(runId, signal) {
434
+ return new Promise((resolve) => {
435
+ let frames = 0;
436
+ let settled = false;
437
+ let unsubscribe;
438
+ let released = false;
439
+ const release = () => {
440
+ if (released) return;
441
+ released = true;
442
+ unsubscribe?.();
443
+ };
444
+ const settle = () => {
445
+ if (settled) return false;
446
+ settled = true;
447
+ signal.removeEventListener("abort", onAbort);
448
+ if (this.unsubscribe === release) this.unsubscribe = null;
449
+ release();
450
+ return true;
451
+ };
452
+ const finish = (ended, reconnect = false) => {
453
+ if (!settle()) return;
454
+ resolve({
455
+ ended,
456
+ frames,
457
+ reconnect
458
+ });
459
+ };
460
+ const fail = (error, transient) => {
461
+ if (!settle()) return;
462
+ resolve({
463
+ ended: false,
464
+ failure: {
465
+ error,
466
+ transient
467
+ },
468
+ frames
469
+ });
470
+ };
471
+ const onAbort = () => finish(false);
472
+ if (signal.aborted) {
473
+ finish(false);
474
+ return;
475
+ }
476
+ signal.addEventListener("abort", onAbort, { once: true });
477
+ const handlers = {
478
+ onClose: (reason) => finish(reason === "terminal", reason === "reconnect"),
479
+ onError: (error) => fail(error, isTransientStreamFault(error)),
480
+ onFrame: async (frame) => {
481
+ if (settled) return;
482
+ frames += 1;
483
+ const before = this.lastEventId;
484
+ if (frame.id !== void 0) this.lastEventId = frame.id;
485
+ let ended;
486
+ try {
487
+ ended = await this.handle(runId, frame.event);
488
+ } catch (error) {
489
+ if (frame.id !== void 0 && !settled && this.lastEventId === frame.id) this.lastEventId = before;
490
+ fail(error, false);
491
+ return;
492
+ }
493
+ if (ended) {
494
+ finish(true);
495
+ if (this.streamAbort?.signal === signal) this.teardownStream();
496
+ }
497
+ },
498
+ onLastEventId: (lastEventId) => {
499
+ if (!settled) this.lastEventId = lastEventId;
500
+ },
501
+ onSkippedFrame: () => {
502
+ if (!settled) frames += 1;
503
+ }
504
+ };
505
+ try {
506
+ unsubscribe = this.config.transport.subscribe(runId, handlers, {
507
+ lastEventId: this.lastEventId,
508
+ signal
509
+ });
510
+ } catch (error) {
511
+ fail(error, false);
512
+ return;
513
+ }
514
+ if (released) unsubscribe();
515
+ else this.unsubscribe = release;
516
+ });
517
+ }
518
+ async handle(runId, event) {
519
+ switch (event.type) {
520
+ case "message-delta":
521
+ this.setState("running");
522
+ this.tell((observer) => observer.onMessageDelta?.(event.text));
523
+ return false;
524
+ case "message":
525
+ this.setState("running");
526
+ this.tell((observer) => observer.onMessage?.(event.content, event.message_index));
527
+ return false;
528
+ case "tool-call": return this.handleToolCall(runId, event);
529
+ case "confirm-required": return this.handleConfirmRequired(runId, event);
530
+ case "budget-exhausted":
531
+ this.tell((observer) => observer.onError?.(event.reason, "budget-exhausted"));
532
+ return false;
533
+ case "error":
534
+ this.tell((observer) => observer.onError?.(event.message, event.code));
535
+ return false;
536
+ case "checks-unmet":
537
+ this.tell((observer) => observer.onChecksUnmet?.(event.unmet));
538
+ return false;
539
+ case "awaiting-input":
540
+ this.setState("awaiting_input");
541
+ return false;
542
+ case "done": return this.handleDone(runId, event);
543
+ case "tool-result": return this.handleToolResult(event);
544
+ case "tool-abandoned": return this.handleToolAbandoned(event);
545
+ case "reconnect": return false;
546
+ }
547
+ }
548
+ async handleToolCall(runId, event) {
549
+ if (!this.claimCall(event.tool_call_id, event.settled)) return false;
550
+ this.runningCalls.set(event.tool_call_id, null);
551
+ try {
552
+ return await this.runToolCall(runId, event);
553
+ } catch (error) {
554
+ this.releaseHeldWord(runId, event.tool_call_id);
555
+ throw error;
556
+ }
557
+ }
558
+ releaseHeldWord(runId, toolCallId) {
559
+ if (this.handledRunId !== runId) return;
560
+ const held = this.runningCalls.get(toolCallId);
561
+ this.runningCalls.delete(toolCallId);
562
+ held?.();
563
+ }
564
+ holdWhileRunning(toolCallId, report) {
565
+ if (!this.runningCalls.has(toolCallId)) return false;
566
+ if (this.runningCalls.get(toolCallId) === null) this.runningCalls.set(toolCallId, report);
567
+ return true;
568
+ }
569
+ async runToolCall(runId, event) {
570
+ const { bus, ctx, recoveryFor, stateDelta } = this.config;
571
+ this.setState("running");
572
+ this.tell((observer) => observer.onToolActivity?.(event.name));
573
+ this.tell((observer) => observer.onToolCall?.(event.name, event.input, event.tool_call_id));
574
+ const before = stateDelta?.capture(ctx);
575
+ const result = await bus.dispatchFromModel(ctx, event.name, event.input);
576
+ const moved = stateDelta && before !== void 0 ? stateDelta.diff(before, stateDelta.capture(ctx)) : void 0;
577
+ if (result.ok && result.summary) this.tell((observer) => observer.onToolActivity?.(result.summary));
578
+ const recovery = result.ok ? void 0 : recoveryFor?.(event.name, result.code);
579
+ if (this.handledRunId === runId) {
580
+ this.dispatchedCalls.add(event.tool_call_id);
581
+ this.runningCalls.delete(event.tool_call_id);
582
+ }
583
+ this.tell((observer) => observer.onToolResult?.(event.tool_call_id, result.ok ? {
584
+ status: "ok",
585
+ summary: result.summary
586
+ } : result.code === "confirmation-denied" ? { status: "abandoned" } : {
587
+ error: result.error,
588
+ recovery,
589
+ status: "error"
590
+ }));
591
+ await this.postInput(runId, {
592
+ ok: result.ok,
593
+ tool_call_id: event.tool_call_id,
594
+ type: "tool-result",
595
+ ...result.ok ? { result: buildToolResultPayload(result.summary, result.data, moved) } : {
596
+ code: toWireErrorCode(result.code),
597
+ error: result.error,
598
+ ...recovery ? { recovery } : {}
599
+ }
600
+ });
601
+ return false;
602
+ }
603
+ async handleConfirmRequired(runId, event) {
604
+ if (!this.claimCall(event.tool_call_id, event.settled)) return false;
605
+ this.setState("running");
606
+ const approved = await this.config.confirmServerTool({ name: event.name });
607
+ await this.postInput(runId, {
608
+ approved,
609
+ tool_call_id: event.tool_call_id,
610
+ type: "confirm"
611
+ });
612
+ return false;
613
+ }
614
+ handleDone(runId, event) {
615
+ if (this.unfinishedRunId === runId) this.unfinishedRunId = null;
616
+ const generation = this.readGeneration;
617
+ this.tell((observer) => observer.onRunEnd?.(event.reason));
618
+ if (generation === this.readGeneration) this.setState("ended");
619
+ return true;
620
+ }
621
+ handleToolResult(event) {
622
+ if (this.dispatchedCalls.has(event.tool_call_id)) return false;
623
+ const report = () => {
624
+ const { summary } = event;
625
+ if (summary) this.tell((observer) => observer.onToolActivity?.(summary));
626
+ this.tell((observer) => observer.onToolResult?.(event.tool_call_id, event.ok ? {
627
+ status: "ok",
628
+ summary: event.summary
629
+ } : {
630
+ error: event.error,
631
+ status: "error"
632
+ }));
633
+ };
634
+ if (!this.holdWhileRunning(event.tool_call_id, report)) report();
635
+ return false;
636
+ }
637
+ handleToolAbandoned(event) {
638
+ if (this.dispatchedCalls.has(event.tool_call_id)) return false;
639
+ const report = () => {
640
+ this.tell((observer) => observer.onToolResult?.(event.tool_call_id, {
641
+ abandonedReason: event.reason,
642
+ status: "abandoned"
643
+ }));
644
+ };
645
+ if (!this.holdWhileRunning(event.tool_call_id, report)) report();
646
+ return false;
647
+ }
648
+ setState(next) {
649
+ this.sendHold = null;
650
+ this.reportState(next);
651
+ }
652
+ reportState(next) {
653
+ this.state = next;
654
+ if (this.reported === next) return;
655
+ this.reported = next;
656
+ this.tell((observer) => observer.onStateChange?.(next));
657
+ }
658
+ tell(report) {
659
+ try {
660
+ report(this.config.observer);
661
+ } catch (fault) {
662
+ surfaceFault(fault);
663
+ }
664
+ }
665
+ async postInput(runId, input) {
666
+ try {
667
+ await this.config.transport.sendInput(runId, input);
668
+ } catch {
669
+ if (this.currentRunId === runId && this.state !== "ended") this.tell((observer) => observer.onError?.(""));
670
+ }
671
+ }
1351
672
  };
1352
-
1353
- // src/agent/rules/agentError.ts
1354
- var resolveAgentError = (message, code, copy, draft) => {
1355
- if (code === "rate-limited") {
1356
- return copy.rateLimited;
1357
- }
1358
- if (code === "ai-provider-not-configured") {
1359
- return copy.notConfigured;
1360
- }
1361
- if (code === "looping") {
1362
- return copy.looping;
1363
- }
1364
- if (code === "access-revoked") {
1365
- return copy.accessRevoked;
1366
- }
1367
- if (code === "budget-exhausted") {
1368
- const line = (() => {
1369
- switch (message.trim()) {
1370
- case "turns":
1371
- return copy.budget.turns;
1372
- case "cost":
1373
- return copy.budget.cost;
1374
- default:
1375
- return copy.budget.generic;
1376
- }
1377
- })();
1378
- return draft?.open ? `${line} ${draft.note}` : line;
1379
- }
1380
- const trimmed = message.trim();
1381
- return trimmed.length > 0 ? trimmed : copy.generic;
673
+ const resolveAgentError = (message, code, copy, draft) => {
674
+ if (code === "rate-limited") return copy.rateLimited;
675
+ if (code === "ai-provider-not-configured") return copy.notConfigured;
676
+ if (code === "looping") return copy.looping;
677
+ if (code === "access-revoked") return copy.accessRevoked;
678
+ if (code === "budget-exhausted") {
679
+ const line = (() => {
680
+ switch (message.trim()) {
681
+ case "turns": return copy.budget.turns;
682
+ case "cost": return copy.budget.cost;
683
+ default: return copy.budget.generic;
684
+ }
685
+ })();
686
+ return draft?.open ? `${line} ${draft.note}` : line;
687
+ }
688
+ const trimmed = message.trim();
689
+ return trimmed.length > 0 ? trimmed : copy.generic;
1382
690
  };
1383
-
1384
- // src/agent/rules/boundedInputJson.ts
1385
- var MAX_TOOL_INPUT_CHARS = 2e3;
1386
- var HIGH_SURROGATE_FIRST = 55296;
1387
- var HIGH_SURROGATE_LAST = 56319;
1388
- var boundedInputJson = (input) => {
1389
- let json;
1390
- try {
1391
- json = JSON.stringify(input, null, 2);
1392
- } catch {
1393
- return null;
1394
- }
1395
- if (json === void 0) {
1396
- return null;
1397
- }
1398
- if (json.length <= MAX_TOOL_INPUT_CHARS) {
1399
- return json;
1400
- }
1401
- const last = json.charCodeAt(MAX_TOOL_INPUT_CHARS - 1);
1402
- const splitsPair = last >= HIGH_SURROGATE_FIRST && last <= HIGH_SURROGATE_LAST;
1403
- return `${json.slice(0, splitsPair ? MAX_TOOL_INPUT_CHARS - 1 : MAX_TOOL_INPUT_CHARS)}\u2026`;
691
+ const MAX_TOOL_INPUT_CHARS = 2e3;
692
+ const HIGH_SURROGATE_FIRST = 55296;
693
+ const HIGH_SURROGATE_LAST = 56319;
694
+ const boundedInputJson = (input) => {
695
+ let json;
696
+ try {
697
+ json = JSON.stringify(input, null, 2);
698
+ } catch {
699
+ return null;
700
+ }
701
+ if (json === void 0) return null;
702
+ if (json.length <= 2e3) return json;
703
+ const last = json.charCodeAt(1999);
704
+ const splitsPair = last >= HIGH_SURROGATE_FIRST && last <= HIGH_SURROGATE_LAST;
705
+ return `${json.slice(0, splitsPair ? 1999 : MAX_TOOL_INPUT_CHARS)}…`;
1404
706
  };
1405
-
1406
- // src/agent/rules/conversation.ts
1407
- var appendQuestionEntry = (transcript, question) => {
1408
- if (question.options.length === 0) {
1409
- return transcript;
1410
- }
1411
- if (transcript.some((entry) => entry.id === question.toolCallId)) {
1412
- return transcript;
1413
- }
1414
- return [
1415
- ...transcript,
1416
- {
1417
- id: question.toolCallId,
1418
- options: question.options,
1419
- question: question.question,
1420
- role: "question",
1421
- selected: null,
1422
- settled: false
1423
- }
1424
- ];
707
+ const appendQuestionEntry = (transcript, question) => {
708
+ if (question.options.length === 0) return transcript;
709
+ if (transcript.some((entry) => entry.id === question.toolCallId)) return transcript;
710
+ return [...transcript, {
711
+ id: question.toolCallId,
712
+ options: question.options,
713
+ question: question.question,
714
+ role: "question",
715
+ selected: null,
716
+ settled: false
717
+ }];
1425
718
  };
1426
- var answerQuestionEntry = (transcript, entryId, label) => transcript.map(
1427
- (entry) => entry.role === "question" && entry.id === entryId && !entry.settled ? { ...entry, selected: label, settled: true } : entry
1428
- );
1429
- var settleOpenQuestionEntries = (transcript) => {
1430
- if (!transcript.some((entry) => entry.role === "question" && !entry.settled)) {
1431
- return transcript;
1432
- }
1433
- return transcript.map(
1434
- (entry) => entry.role === "question" && !entry.settled ? { ...entry, settled: true } : entry
1435
- );
719
+ const answerQuestionEntry = (transcript, entryId, label) => transcript.map((entry) => entry.role === "question" && entry.id === entryId && !entry.settled ? {
720
+ ...entry,
721
+ selected: label,
722
+ settled: true
723
+ } : entry);
724
+ const settleOpenQuestionEntries = (transcript) => {
725
+ if (!transcript.some((entry) => entry.role === "question" && !entry.settled)) return transcript;
726
+ return transcript.map((entry) => entry.role === "question" && !entry.settled ? {
727
+ ...entry,
728
+ settled: true
729
+ } : entry);
1436
730
  };
1437
- var appendSuggestionsEntry = (transcript, suggestions) => {
1438
- if (suggestions.candidates.length === 0) {
1439
- return transcript;
1440
- }
1441
- if (transcript.some((entry) => entry.id === suggestions.entryId)) {
1442
- return transcript;
1443
- }
1444
- return [
1445
- ...settleOpenSuggestionEntries(transcript),
1446
- {
1447
- candidates: suggestions.candidates,
1448
- chosenSeed: null,
1449
- id: suggestions.entryId,
1450
- role: "suggestions",
1451
- settled: false
1452
- }
1453
- ];
731
+ const appendSuggestionsEntry = (transcript, suggestions) => {
732
+ if (suggestions.candidates.length === 0) return transcript;
733
+ if (transcript.some((entry) => entry.id === suggestions.entryId)) return transcript;
734
+ return [...settleOpenSuggestionEntries(transcript), {
735
+ candidates: suggestions.candidates,
736
+ chosenSeed: null,
737
+ id: suggestions.entryId,
738
+ role: "suggestions",
739
+ settled: false
740
+ }];
1454
741
  };
1455
- var chooseSuggestionEntry = (transcript, entryId, seed) => transcript.map(
1456
- (entry) => entry.role === "suggestions" && entry.id === entryId && !entry.settled ? { ...entry, chosenSeed: seed, settled: true } : entry
1457
- );
1458
- var settleOpenSuggestionEntries = (transcript) => {
1459
- if (!transcript.some((entry) => entry.role === "suggestions" && !entry.settled)) {
1460
- return transcript;
1461
- }
1462
- return transcript.map(
1463
- (entry) => entry.role === "suggestions" && !entry.settled ? { ...entry, settled: true } : entry
1464
- );
742
+ const chooseSuggestionEntry = (transcript, entryId, seed) => transcript.map((entry) => entry.role === "suggestions" && entry.id === entryId && !entry.settled ? {
743
+ ...entry,
744
+ chosenSeed: seed,
745
+ settled: true
746
+ } : entry);
747
+ const settleOpenSuggestionEntries = (transcript) => {
748
+ if (!transcript.some((entry) => entry.role === "suggestions" && !entry.settled)) return transcript;
749
+ return transcript.map((entry) => entry.role === "suggestions" && !entry.settled ? {
750
+ ...entry,
751
+ settled: true
752
+ } : entry);
1465
753
  };
1466
- var appendWarningEntry = (transcript, lines) => {
1467
- if (lines.length === 0) {
1468
- return transcript;
1469
- }
1470
- return [...transcript, { id: mintEntryId(), lines, role: "warning" }];
754
+ const appendWarningEntry = (transcript, lines) => {
755
+ if (lines.length === 0) return transcript;
756
+ return [...transcript, {
757
+ id: mintEntryId(),
758
+ lines,
759
+ role: "warning"
760
+ }];
1471
761
  };
1472
- var appendErrorEntry = (transcript, message) => [
1473
- ...transcript,
1474
- { content: message, id: mintEntryId(), role: "error" }
1475
- ];
1476
- var appendUserEntry = (transcript, content) => [
1477
- ...transcript,
1478
- { content, id: mintEntryId(), role: "user" }
1479
- ];
1480
- var appendActivityEntry = (transcript, activity) => {
1481
- if (transcript.some((entry) => entry.id === activity.toolCallId)) {
1482
- return transcript;
1483
- }
1484
- return [
1485
- ...transcript,
1486
- {
1487
- abandonedReason: null,
1488
- error: null,
1489
- id: activity.toolCallId,
1490
- input: activity.input,
1491
- label: null,
1492
- name: activity.name,
1493
- recovery: null,
1494
- role: "activity",
1495
- status: "running"
1496
- }
1497
- ];
762
+ const appendErrorEntry = (transcript, message) => [...transcript, {
763
+ content: message,
764
+ id: mintEntryId(),
765
+ role: "error"
766
+ }];
767
+ const appendUserEntry = (transcript, content) => [...transcript, {
768
+ content,
769
+ id: mintEntryId(),
770
+ role: "user"
771
+ }];
772
+ const appendActivityEntry = (transcript, activity) => {
773
+ if (transcript.some((entry) => entry.id === activity.toolCallId)) return transcript;
774
+ return [...transcript, {
775
+ abandonedReason: null,
776
+ error: null,
777
+ id: activity.toolCallId,
778
+ input: activity.input,
779
+ label: null,
780
+ name: activity.name,
781
+ recovery: null,
782
+ role: "activity",
783
+ status: "running"
784
+ }];
1498
785
  };
1499
- var settleActivityEntry = (transcript, toolCallId, outcome) => {
1500
- if (transcript.some((entry) => entry.role === "question" && entry.id === toolCallId)) {
1501
- return transcript;
1502
- }
1503
- const index = transcript.findLastIndex(
1504
- (entry) => entry.role === "activity" && entry.id === toolCallId
1505
- );
1506
- if (index === -1) {
1507
- return [
1508
- ...transcript,
1509
- {
1510
- abandonedReason: outcome.abandonedReason ?? null,
1511
- error: outcome.error ?? null,
1512
- id: toolCallId,
1513
- input: null,
1514
- label: outcome.summary ?? null,
1515
- name: null,
1516
- recovery: outcome.recovery ?? null,
1517
- role: "activity",
1518
- status: outcome.status
1519
- }
1520
- ];
1521
- }
1522
- const found = transcript[index];
1523
- if (found?.role === "activity" && found.status !== "running") {
1524
- return transcript;
1525
- }
1526
- return transcript.map(
1527
- (entry, i) => i === index && entry.role === "activity" ? {
1528
- ...entry,
1529
- abandonedReason: outcome.abandonedReason ?? null,
1530
- error: outcome.error ?? null,
1531
- label: outcome.summary ?? null,
1532
- recovery: outcome.recovery ?? null,
1533
- status: outcome.status
1534
- } : entry
1535
- );
786
+ const settleActivityEntry = (transcript, toolCallId, outcome) => {
787
+ if (transcript.some((entry) => entry.role === "question" && entry.id === toolCallId)) return transcript;
788
+ const index = transcript.findLastIndex((entry) => entry.role === "activity" && entry.id === toolCallId);
789
+ if (index === -1) return [...transcript, {
790
+ abandonedReason: outcome.abandonedReason ?? null,
791
+ error: outcome.error ?? null,
792
+ id: toolCallId,
793
+ input: null,
794
+ label: outcome.summary ?? null,
795
+ name: null,
796
+ recovery: outcome.recovery ?? null,
797
+ role: "activity",
798
+ status: outcome.status
799
+ }];
800
+ const found = transcript[index];
801
+ if (found?.role === "activity" && found.status !== "running") return transcript;
802
+ return transcript.map((entry, i) => i === index && entry.role === "activity" ? {
803
+ ...entry,
804
+ abandonedReason: outcome.abandonedReason ?? null,
805
+ error: outcome.error ?? null,
806
+ label: outcome.summary ?? null,
807
+ recovery: outcome.recovery ?? null,
808
+ status: outcome.status
809
+ } : entry);
1536
810
  };
1537
- var mintEntryId = () => localId();
1538
- var isAssistantTurn = (entry) => entry.role === "assistant";
1539
- var accumulateAssistant = (transcript, delta) => {
1540
- const last = transcript.at(-1);
1541
- if (last && isAssistantTurn(last) && last.messageIndex === void 0) {
1542
- return [...transcript.slice(0, -1), { ...last, content: last.content + delta }];
1543
- }
1544
- return [...transcript, { content: delta, id: mintEntryId(), role: "assistant" }];
811
+ const mintEntryId = () => localId();
812
+ const isAssistantTurn = (entry) => entry.role === "assistant";
813
+ const accumulateAssistant = (transcript, delta) => {
814
+ const last = transcript.at(-1);
815
+ if (last && isAssistantTurn(last) && last.messageIndex === void 0) return [...transcript.slice(0, -1), {
816
+ ...last,
817
+ content: last.content + delta
818
+ }];
819
+ return [...transcript, {
820
+ content: delta,
821
+ id: mintEntryId(),
822
+ role: "assistant"
823
+ }];
1545
824
  };
1546
- var settlesLastTurn = (last, messageIndex) => messageIndex === void 0 || last.messageIndex === void 0 || last.messageIndex === messageIndex;
1547
- var replaceAssistant = (transcript, content, messageIndex) => {
1548
- const last = transcript.at(-1);
1549
- if (last && isAssistantTurn(last) && settlesLastTurn(last, messageIndex)) {
1550
- return [...transcript.slice(0, -1), { ...last, content, messageIndex }];
1551
- }
1552
- return [...transcript, { content, id: mintEntryId(), messageIndex, role: "assistant" }];
825
+ const settlesLastTurn = (last, messageIndex) => messageIndex === void 0 || last.messageIndex === void 0 || last.messageIndex === messageIndex;
826
+ const replaceAssistant = (transcript, content, messageIndex) => {
827
+ const last = transcript.at(-1);
828
+ if (last && isAssistantTurn(last) && settlesLastTurn(last, messageIndex)) return [...transcript.slice(0, -1), {
829
+ ...last,
830
+ content,
831
+ messageIndex
832
+ }];
833
+ return [...transcript, {
834
+ content,
835
+ id: mintEntryId(),
836
+ messageIndex,
837
+ role: "assistant"
838
+ }];
1553
839
  };
1554
-
1555
- // src/agent/rules/conversationFaults.ts
1556
- var startRefusal = (error) => {
1557
- const status = statusOf(error);
1558
- if (status === void 0 || typeof error !== "object" || error === null) {
1559
- return null;
1560
- }
1561
- const code = "code" in error && typeof error.code === "string" ? error.code : void 0;
1562
- return { code, status };
840
+ const startRefusal = (error) => {
841
+ const status = statusOf(error);
842
+ if (status === void 0 || typeof error !== "object" || error === null) return null;
843
+ return {
844
+ code: "code" in error && typeof error.code === "string" ? error.code : void 0,
845
+ status
846
+ };
1563
847
  };
1564
- var TOO_LARGE_STATUS = 413;
1565
- var RATE_LIMITED_STATUS = 429;
1566
- var refusedAsSent = (status, copy) => {
1567
- if (status === TOO_LARGE_STATUS) {
1568
- return copy.tooLarge;
1569
- }
1570
- if (status === RATE_LIMITED_STATUS) {
1571
- return copy.rateLimited;
1572
- }
1573
- return void 0;
848
+ const TOO_LARGE_STATUS = 413;
849
+ const RATE_LIMITED_STATUS = 429;
850
+ const refusedAsSent = (status, copy) => {
851
+ if (status === TOO_LARGE_STATUS) return copy.tooLarge;
852
+ if (status === RATE_LIMITED_STATUS) return copy.rateLimited;
1574
853
  };
1575
- var ACCESS_STATUSES = [402, 403, 404];
1576
- var SIGN_IN_REFUSED_STATUS = 401;
1577
- var createConversationFaults = (config) => {
1578
- const { copy, invalidateAiConfig, invalidateMemberships, onSettled, onSignInRefused, writer } = config;
1579
- const tellHost = (tell) => {
1580
- try {
1581
- tell();
1582
- } catch (fault) {
1583
- surfaceFault(fault);
1584
- }
1585
- };
1586
- const tellSignInRefused = (status) => {
1587
- if (status === SIGN_IN_REFUSED_STATUS) {
1588
- tellHost(() => onSignInRefused?.());
1589
- }
1590
- };
1591
- return {
1592
- handleStartError: (organizationId, error, runId) => {
1593
- writer.setRunId(null);
1594
- writer.setSessionState("awaiting_input");
1595
- const refusal = startRefusal(error);
1596
- const credentialGone = refusal?.status === 409 && refusal.code === "AI_PROVIDER_NOT_CONFIGURED";
1597
- const startNotReached = refusal?.status === 404 && runId === void 0;
1598
- if (refusal?.status === 402) {
1599
- writer.appendError(copy.notEntitled);
1600
- } else if (refusal?.status === 403 || startNotReached) {
1601
- writer.appendError(copy.noAccess);
1602
- } else if (credentialGone) {
1603
- writer.appendError(copy.notConfigured);
1604
- } else {
1605
- writer.appendError(refusedAsSent(refusal?.status, copy) ?? copy.generic);
1606
- }
1607
- onSettled?.();
1608
- if (credentialGone) {
1609
- tellHost(() => invalidateAiConfig?.(organizationId));
1610
- }
1611
- if (refusal !== null && ACCESS_STATUSES.includes(refusal.status)) {
1612
- tellHost(() => invalidateMemberships?.());
1613
- }
1614
- tellSignInRefused(refusal?.status);
1615
- },
1616
- // No onSettled here: no run opened, so there is no run id for a surface to
1617
- // mirror anywhere, only the hint and the re-enabled input.
1618
- missingOrganization: () => {
1619
- writer.appendError(copy.missingOrganization);
1620
- writer.setSessionState("awaiting_input");
1621
- },
1622
- recover: (runGone, error) => {
1623
- if (runGone) {
1624
- writer.setRunId(null);
1625
- }
1626
- writer.appendError(refusedAsSent(statusOf(error), copy) ?? copy.generic);
1627
- writer.setSessionState("awaiting_input");
1628
- onSettled?.();
1629
- if (runGone && statusOf(error) === 404) {
1630
- tellHost(() => invalidateMemberships?.());
1631
- }
1632
- tellSignInRefused(statusOf(error));
1633
- },
1634
- resumeFailed: (error) => {
1635
- writer.setRunId(null);
1636
- writer.setSessionState("awaiting_input");
1637
- onSettled?.();
1638
- tellSignInRefused(statusOf(error));
1639
- }
1640
- };
854
+ const ACCESS_STATUSES = [
855
+ 402,
856
+ 403,
857
+ 404
858
+ ];
859
+ const SIGN_IN_REFUSED_STATUS = 401;
860
+ const createConversationFaults = (config) => {
861
+ const { copy, invalidateAiConfig, invalidateMemberships, onSettled, onSignInRefused, writer } = config;
862
+ const tellHost = (tell) => {
863
+ try {
864
+ tell();
865
+ } catch (fault) {
866
+ surfaceFault(fault);
867
+ }
868
+ };
869
+ const tellSignInRefused = (status) => {
870
+ if (status === SIGN_IN_REFUSED_STATUS) tellHost(() => onSignInRefused?.());
871
+ };
872
+ return {
873
+ handleStartError: (organizationId, error, runId) => {
874
+ writer.setRunId(null);
875
+ writer.setSessionState("awaiting_input");
876
+ const refusal = startRefusal(error);
877
+ const credentialGone = refusal?.status === 409 && refusal.code === "AI_PROVIDER_NOT_CONFIGURED";
878
+ const startNotReached = refusal?.status === 404 && runId === void 0;
879
+ if (refusal?.status === 402) writer.appendError(copy.notEntitled);
880
+ else if (refusal?.status === 403 || startNotReached) writer.appendError(copy.noAccess);
881
+ else if (credentialGone) writer.appendError(copy.notConfigured);
882
+ else writer.appendError(refusedAsSent(refusal?.status, copy) ?? copy.generic);
883
+ onSettled?.();
884
+ if (credentialGone) tellHost(() => invalidateAiConfig?.(organizationId));
885
+ if (refusal !== null && ACCESS_STATUSES.includes(refusal.status)) tellHost(() => invalidateMemberships?.());
886
+ tellSignInRefused(refusal?.status);
887
+ },
888
+ missingOrganization: () => {
889
+ writer.appendError(copy.missingOrganization);
890
+ writer.setSessionState("awaiting_input");
891
+ },
892
+ recover: (runGone, error) => {
893
+ if (runGone) writer.setRunId(null);
894
+ writer.appendError(refusedAsSent(statusOf(error), copy) ?? copy.generic);
895
+ writer.setSessionState("awaiting_input");
896
+ onSettled?.();
897
+ if (runGone && statusOf(error) === 404) tellHost(() => invalidateMemberships?.());
898
+ tellSignInRefused(statusOf(error));
899
+ },
900
+ resumeFailed: (error) => {
901
+ writer.setRunId(null);
902
+ writer.setSessionState("awaiting_input");
903
+ onSettled?.();
904
+ tellSignInRefused(statusOf(error));
905
+ }
906
+ };
1641
907
  };
1642
-
1643
- // src/agent/rules/conversationHost.ts
1644
- var isRunGone = (error) => error instanceof MountayaElementsError || statusOf(error) === 404;
1645
- var createConversationHost = (config) => {
1646
- let session = null;
1647
- let started = false;
1648
- let latestCall = null;
1649
- let callMade = Promise.resolve();
1650
- let parkedAt = null;
1651
- const ensureSession = () => {
1652
- if (!session) {
1653
- session = config.buildSession();
1654
- }
1655
- return session;
1656
- };
1657
- const dispose = () => {
1658
- parkedAt = session?.streamPosition?.() ?? parkedAt;
1659
- session?.dispose();
1660
- session = null;
1661
- started = false;
1662
- latestCall = null;
1663
- };
1664
- const beginCall = () => {
1665
- const call = /* @__PURE__ */ Symbol("run");
1666
- latestCall = call;
1667
- return call;
1668
- };
1669
- const callSettled = (call) => {
1670
- if (latestCall !== call) {
1671
- return false;
1672
- }
1673
- latestCall = null;
1674
- started = false;
1675
- return true;
1676
- };
1677
- const closeRun = () => {
1678
- void session?.close().catch(() => void 0);
1679
- };
1680
- const finish = () => {
1681
- closeRun();
1682
- dispose();
1683
- parkedAt = null;
1684
- };
1685
- const reroute = () => {
1686
- if (!started || !session) {
1687
- return;
1688
- }
1689
- config.routeForState?.();
1690
- void session.routeTools().catch(() => void 0);
1691
- };
1692
- const restart = () => {
1693
- closeRun();
1694
- session?.dispose();
1695
- session = config.buildSession();
1696
- started = false;
1697
- latestCall = null;
1698
- parkedAt = null;
1699
- };
1700
- const resume = (runId, onFault) => {
1701
- const active = ensureSession();
1702
- if (!runId || started) {
1703
- return;
1704
- }
1705
- started = true;
1706
- const call = beginCall();
1707
- callMade = Promise.resolve();
1708
- const position = parkedAt?.runId === runId ? parkedAt.lastEventId : void 0;
1709
- parkedAt = null;
1710
- const reading = position === void 0 ? active.resume(runId) : active.resume(runId, position);
1711
- reading.then(
1712
- () => {
1713
- callSettled(call);
1714
- },
1715
- (error) => {
1716
- if (callSettled(call)) {
1717
- onFault(error);
1718
- }
1719
- }
1720
- );
1721
- };
1722
- const submit = (message) => {
1723
- const active = ensureSession();
1724
- config.appendUserMessage(message);
1725
- config.routeForMessage?.(message);
1726
- if (started) {
1727
- const call2 = latestCall;
1728
- void callMade.then(() => active.routeTools()).catch(() => void 0).then(() => active.send(message)).catch((error) => {
1729
- if (session !== active || latestCall !== call2) {
1730
- return;
1731
- }
1732
- const runGone = isRunGone(error);
1733
- if (runGone) {
1734
- latestCall = null;
1735
- started = false;
1736
- }
1737
- config.onSendFault(error, runGone);
1738
- });
1739
- return;
1740
- }
1741
- const organizationId = config.resolveOrganizationId();
1742
- if (!organizationId) {
1743
- config.onMissingOrganization();
1744
- return;
1745
- }
1746
- started = true;
1747
- parkedAt = null;
1748
- const call = beginCall();
1749
- const context = config.buildContext();
1750
- const running = context.then((captured) => active.start(message, organizationId, captured));
1751
- callMade = context.then(
1752
- () => void 0,
1753
- () => void 0
1754
- );
1755
- running.then(
1756
- () => {
1757
- callSettled(call);
1758
- },
1759
- (error) => {
1760
- if (!callSettled(call)) {
1761
- return;
1762
- }
1763
- const openedRun = active.runId?.() ?? null;
1764
- if (openedRun === null) {
1765
- config.onStartError(organizationId, error);
1766
- } else {
1767
- config.onStartError(organizationId, error, openedRun);
1768
- }
1769
- }
1770
- );
1771
- };
1772
- return { dispose, finish, reroute, restart, resume, submit };
908
+ const isRunGone = (error) => error instanceof MountayaElementsError || statusOf(error) === 404;
909
+ const createConversationHost = (config) => {
910
+ let session = null;
911
+ let started = false;
912
+ let latestCall = null;
913
+ let callMade = Promise.resolve();
914
+ let parkedAt = null;
915
+ const ensureSession = () => {
916
+ if (!session) session = config.buildSession();
917
+ return session;
918
+ };
919
+ const dispose = () => {
920
+ parkedAt = session?.streamPosition?.() ?? parkedAt;
921
+ session?.dispose();
922
+ session = null;
923
+ started = false;
924
+ latestCall = null;
925
+ };
926
+ const beginCall = () => {
927
+ const call = Symbol("run");
928
+ latestCall = call;
929
+ return call;
930
+ };
931
+ const callSettled = (call) => {
932
+ if (latestCall !== call) return false;
933
+ latestCall = null;
934
+ started = false;
935
+ return true;
936
+ };
937
+ const closeRun = () => {
938
+ session?.close().catch(() => void 0);
939
+ };
940
+ const finish = () => {
941
+ closeRun();
942
+ dispose();
943
+ parkedAt = null;
944
+ };
945
+ const reroute = () => {
946
+ if (!started || !session) return;
947
+ config.routeForState?.();
948
+ session.routeTools().catch(() => void 0);
949
+ };
950
+ const restart = () => {
951
+ closeRun();
952
+ session?.dispose();
953
+ session = config.buildSession();
954
+ started = false;
955
+ latestCall = null;
956
+ parkedAt = null;
957
+ };
958
+ const resume = (runId, onFault) => {
959
+ const active = ensureSession();
960
+ if (!runId || started) return;
961
+ started = true;
962
+ const call = beginCall();
963
+ callMade = Promise.resolve();
964
+ const position = parkedAt?.runId === runId ? parkedAt.lastEventId : void 0;
965
+ parkedAt = null;
966
+ (position === void 0 ? active.resume(runId) : active.resume(runId, position)).then(() => {
967
+ callSettled(call);
968
+ }, (error) => {
969
+ if (callSettled(call)) onFault(error);
970
+ });
971
+ };
972
+ const submit = (message) => {
973
+ const active = ensureSession();
974
+ config.appendUserMessage(message);
975
+ config.routeForMessage?.(message);
976
+ if (started) {
977
+ const call = latestCall;
978
+ callMade.then(() => active.routeTools()).catch(() => void 0).then(() => active.send(message)).catch((error) => {
979
+ if (session !== active || latestCall !== call) return;
980
+ const runGone = isRunGone(error);
981
+ if (runGone) {
982
+ latestCall = null;
983
+ started = false;
984
+ }
985
+ config.onSendFault(error, runGone);
986
+ });
987
+ return;
988
+ }
989
+ const organizationId = config.resolveOrganizationId();
990
+ if (!organizationId) {
991
+ config.onMissingOrganization();
992
+ return;
993
+ }
994
+ started = true;
995
+ parkedAt = null;
996
+ const call = beginCall();
997
+ const context = config.buildContext();
998
+ const running = context.then((captured) => active.start(message, organizationId, captured));
999
+ callMade = context.then(() => void 0, () => void 0);
1000
+ running.then(() => {
1001
+ callSettled(call);
1002
+ }, (error) => {
1003
+ if (!callSettled(call)) return;
1004
+ const openedRun = active.runId?.() ?? null;
1005
+ if (openedRun === null) config.onStartError(organizationId, error);
1006
+ else config.onStartError(organizationId, error, openedRun);
1007
+ });
1008
+ };
1009
+ return {
1010
+ dispose,
1011
+ finish,
1012
+ reroute,
1013
+ restart,
1014
+ resume,
1015
+ submit
1016
+ };
1773
1017
  };
1774
-
1775
- // src/agent/rules/scriptedTransport.ts
1776
- var terminalTypes = /* @__PURE__ */ new Set(["done"]);
1777
- var readRun = (run, handlers, options) => {
1778
- const signal = options?.signal;
1779
- if (signal?.aborted) {
1780
- return () => {
1781
- };
1782
- }
1783
- let active = true;
1784
- const named = options?.lastEventId;
1785
- let position = named === void 0 ? 0 : run.history.findIndex((entry) => entry.id === named) + 1;
1786
- const beginsPastTheEnd = run.history.slice(0, position).some(({ event }) => terminalTypes.has(event.type));
1787
- let wake = null;
1788
- const release = () => {
1789
- signal?.removeEventListener("abort", teardown);
1790
- };
1791
- const teardown = () => {
1792
- active = false;
1793
- release();
1794
- const resume = wake;
1795
- wake = null;
1796
- if (resume !== null) {
1797
- run.waiting.delete(resume);
1798
- resume();
1799
- }
1800
- };
1801
- signal?.addEventListener("abort", teardown, { once: true });
1802
- void (async () => {
1803
- if (beginsPastTheEnd) {
1804
- await Promise.resolve();
1805
- if (active) {
1806
- active = false;
1807
- release();
1808
- handlers.onClose("ended");
1809
- }
1810
- return;
1811
- }
1812
- while (active) {
1813
- const entry = run.history[position];
1814
- if (entry === void 0) {
1815
- await new Promise((resolve) => {
1816
- wake = resolve;
1817
- run.waiting.add(resolve);
1818
- });
1819
- wake = null;
1820
- continue;
1821
- }
1822
- position += 1;
1823
- try {
1824
- await handlers.onFrame({ event: run.delivered(entry.event), id: entry.id });
1825
- } catch (error) {
1826
- if (active) {
1827
- active = false;
1828
- release();
1829
- handlers.onError(error);
1830
- }
1831
- return;
1832
- }
1833
- if (active && terminalTypes.has(entry.event.type)) {
1834
- active = false;
1835
- release();
1836
- handlers.onClose("terminal");
1837
- return;
1838
- }
1839
- }
1840
- })();
1841
- return teardown;
1018
+ const terminalTypes = /* @__PURE__ */ new Set(["done"]);
1019
+ const readRun = (run, handlers, options) => {
1020
+ const signal = options?.signal;
1021
+ if (signal?.aborted) return () => {};
1022
+ let active = true;
1023
+ const named = options?.lastEventId;
1024
+ let position = named === void 0 ? 0 : run.history.findIndex((entry) => entry.id === named) + 1;
1025
+ const beginsPastTheEnd = run.history.slice(0, position).some(({ event }) => terminalTypes.has(event.type));
1026
+ let wake = null;
1027
+ const release = () => {
1028
+ signal?.removeEventListener("abort", teardown);
1029
+ };
1030
+ const teardown = () => {
1031
+ active = false;
1032
+ release();
1033
+ const resume = wake;
1034
+ wake = null;
1035
+ if (resume !== null) {
1036
+ run.waiting.delete(resume);
1037
+ resume();
1038
+ }
1039
+ };
1040
+ signal?.addEventListener("abort", teardown, { once: true });
1041
+ (async () => {
1042
+ if (beginsPastTheEnd) {
1043
+ await Promise.resolve();
1044
+ if (active) {
1045
+ active = false;
1046
+ release();
1047
+ handlers.onClose("ended");
1048
+ }
1049
+ return;
1050
+ }
1051
+ while (active) {
1052
+ const entry = run.history[position];
1053
+ if (entry === void 0) {
1054
+ await new Promise((resolve) => {
1055
+ wake = resolve;
1056
+ run.waiting.add(resolve);
1057
+ });
1058
+ wake = null;
1059
+ continue;
1060
+ }
1061
+ position += 1;
1062
+ try {
1063
+ await handlers.onFrame({
1064
+ event: run.delivered(entry.event),
1065
+ id: entry.id
1066
+ });
1067
+ } catch (error) {
1068
+ if (active) {
1069
+ active = false;
1070
+ release();
1071
+ handlers.onError(error);
1072
+ }
1073
+ return;
1074
+ }
1075
+ if (active && terminalTypes.has(entry.event.type)) {
1076
+ active = false;
1077
+ release();
1078
+ handlers.onClose("terminal");
1079
+ return;
1080
+ }
1081
+ }
1082
+ })();
1083
+ return teardown;
1842
1084
  };
1843
- var createRunStream = () => {
1844
- const history = [];
1845
- let recorded = 0;
1846
- const record = (event) => {
1847
- recorded += 1;
1848
- return { event, id: String(recorded) };
1849
- };
1850
- const answered = /* @__PURE__ */ new Set();
1851
- const waiting = /* @__PURE__ */ new Set();
1852
- const delivered = (event) => (event.type === "tool-call" || event.type === "confirm-required") && answered.has(event.tool_call_id) ? { ...event, settled: true } : event;
1853
- const stream = {
1854
- answer: (toolCallId, outcome) => {
1855
- answered.add(toolCallId);
1856
- const isSettled = history.some(
1857
- ({ event }) => (event.type === "tool-result" || event.type === "tool-abandoned") && event.tool_call_id === toolCallId
1858
- );
1859
- if (outcome === void 0 || isSettled) {
1860
- return;
1861
- }
1862
- const terminal = history.findIndex(({ event }) => terminalTypes.has(event.type));
1863
- if (terminal === -1) {
1864
- stream.push([outcome]);
1865
- } else {
1866
- history.splice(terminal, 0, record(outcome));
1867
- }
1868
- },
1869
- push: (events) => {
1870
- history.push(...events.map(record));
1871
- const resumes = [...waiting];
1872
- waiting.clear();
1873
- for (const resume of resumes) {
1874
- resume();
1875
- }
1876
- },
1877
- subscribe: (handlers, options) => readRun({ delivered, history, waiting }, handlers, options)
1878
- };
1879
- return stream;
1085
+ const createRunStream = () => {
1086
+ const history = [];
1087
+ let recorded = 0;
1088
+ const record = (event) => {
1089
+ recorded += 1;
1090
+ return {
1091
+ event,
1092
+ id: String(recorded)
1093
+ };
1094
+ };
1095
+ const answered = /* @__PURE__ */ new Set();
1096
+ const waiting = /* @__PURE__ */ new Set();
1097
+ const delivered = (event) => (event.type === "tool-call" || event.type === "confirm-required") && answered.has(event.tool_call_id) ? {
1098
+ ...event,
1099
+ settled: true
1100
+ } : event;
1101
+ const stream = {
1102
+ answer: (toolCallId, outcome) => {
1103
+ answered.add(toolCallId);
1104
+ const isSettled = history.some(({ event }) => (event.type === "tool-result" || event.type === "tool-abandoned") && event.tool_call_id === toolCallId);
1105
+ if (outcome === void 0 || isSettled) return;
1106
+ const terminal = history.findIndex(({ event }) => terminalTypes.has(event.type));
1107
+ if (terminal === -1) stream.push([outcome]);
1108
+ else history.splice(terminal, 0, record(outcome));
1109
+ },
1110
+ push: (events) => {
1111
+ history.push(...events.map(record));
1112
+ const resumes = [...waiting];
1113
+ waiting.clear();
1114
+ for (const resume of resumes) resume();
1115
+ },
1116
+ subscribe: (handlers, options) => readRun({
1117
+ delivered,
1118
+ history,
1119
+ waiting
1120
+ }, handlers, options)
1121
+ };
1122
+ return stream;
1880
1123
  };
1881
- var echoOf = (answer) => ({
1882
- ok: answer.ok,
1883
- tool_call_id: answer.tool_call_id,
1884
- type: "tool-result",
1885
- ...answer.result === void 0 ? {} : { data: answer.result },
1886
- ...answer.error === void 0 ? {} : { error: answer.error }
1124
+ const echoOf = (answer) => ({
1125
+ ok: answer.ok,
1126
+ tool_call_id: answer.tool_call_id,
1127
+ type: "tool-result",
1128
+ ...answer.result === void 0 ? {} : { data: answer.result },
1129
+ ...answer.error === void 0 ? {} : { error: answer.error }
1887
1130
  });
1888
- var createAgentScriptedTransport = (resolve) => {
1889
- const streams = /* @__PURE__ */ new Map();
1890
- const streamFor = (runId) => streams.get(runId);
1891
- const startRun = async (params) => {
1892
- const runId = localId();
1893
- const stream = createRunStream();
1894
- streams.set(runId, stream);
1895
- stream.push(resolve(params.message));
1896
- return { runId };
1897
- };
1898
- const sendInput = async (runId, input) => {
1899
- const stream = streamFor(runId);
1900
- if (!stream) {
1901
- return;
1902
- }
1903
- if (input.type === "user-message") {
1904
- stream.push(resolve(input.content));
1905
- } else if (input.type === "close") {
1906
- stream.push([{ reason: "completed", type: "done" }]);
1907
- } else if (input.type === "tool-result") {
1908
- stream.answer(input.tool_call_id, echoOf(input));
1909
- } else if (input.type === "confirm") {
1910
- stream.answer(input.tool_call_id);
1911
- }
1912
- };
1913
- const subscribe = (runId, handlers, options) => {
1914
- const stream = streamFor(runId);
1915
- if (!stream) {
1916
- queueMicrotask(() => handlers.onClose("ended"));
1917
- return () => {
1918
- };
1919
- }
1920
- return stream.subscribe(handlers, options);
1921
- };
1922
- const pushEvents = (runId, turnEvents) => {
1923
- streamFor(runId)?.push(turnEvents);
1924
- };
1925
- const endRun = (runId) => {
1926
- streamFor(runId)?.push([{ reason: "completed", type: "done" }]);
1927
- };
1928
- return { endRun, pushEvents, sendInput, startRun, subscribe };
1131
+ const createAgentScriptedTransport = (resolve) => {
1132
+ const streams = /* @__PURE__ */ new Map();
1133
+ const streamFor = (runId) => streams.get(runId);
1134
+ const startRun = async (params) => {
1135
+ const runId = localId();
1136
+ const stream = createRunStream();
1137
+ streams.set(runId, stream);
1138
+ stream.push(resolve(params.message));
1139
+ return { runId };
1140
+ };
1141
+ const sendInput = async (runId, input) => {
1142
+ const stream = streamFor(runId);
1143
+ if (!stream) return;
1144
+ if (input.type === "user-message") stream.push(resolve(input.content));
1145
+ else if (input.type === "close") stream.push([{
1146
+ reason: "completed",
1147
+ type: "done"
1148
+ }]);
1149
+ else if (input.type === "tool-result") stream.answer(input.tool_call_id, echoOf(input));
1150
+ else if (input.type === "confirm") stream.answer(input.tool_call_id);
1151
+ };
1152
+ const subscribe = (runId, handlers, options) => {
1153
+ const stream = streamFor(runId);
1154
+ if (!stream) {
1155
+ queueMicrotask(() => handlers.onClose("ended"));
1156
+ return () => {};
1157
+ }
1158
+ return stream.subscribe(handlers, options);
1159
+ };
1160
+ const pushEvents = (runId, turnEvents) => {
1161
+ streamFor(runId)?.push(turnEvents);
1162
+ };
1163
+ const endRun = (runId) => {
1164
+ streamFor(runId)?.push([{
1165
+ reason: "completed",
1166
+ type: "done"
1167
+ }]);
1168
+ };
1169
+ return {
1170
+ endRun,
1171
+ pushEvents,
1172
+ sendInput,
1173
+ startRun,
1174
+ subscribe
1175
+ };
1929
1176
  };
1930
-
1931
- // src/agent/rules/stickToBottom.ts
1932
- var STICK_TO_BOTTOM_THRESHOLD_PX = 24;
1933
- var isPinnedToBottom = (viewport, threshold = STICK_TO_BOTTOM_THRESHOLD_PX) => viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight <= threshold;
1934
-
1177
+ const STICK_TO_BOTTOM_THRESHOLD_PX = 24;
1178
+ const isPinnedToBottom = (viewport, threshold = 24) => viewport.scrollHeight - viewport.scrollTop - viewport.clientHeight <= threshold;
1935
1179
  export { AgentEngine, MAX_TOOL_INPUT_CHARS, MAX_TOOL_RESULT_DATA_BYTES, STICK_TO_BOTTOM_THRESHOLD_PX, accumulateAssistant, answerQuestionEntry, appendActivityEntry, appendErrorEntry, appendQuestionEntry, appendSuggestionsEntry, appendUserEntry, appendWarningEntry, boundedInputJson, buildToolResultPayload, chooseSuggestionEntry, createAgentScriptedTransport, createConversationFaults, createConversationHost, isPinnedToBottom, mintEntryId, replaceAssistant, resolveAgentError, settleActivityEntry, settleOpenQuestionEntries, settleOpenSuggestionEntries, toWireErrorCode };
1936
- //# sourceMappingURL=index.js.map
1180
+
1937
1181
  //# sourceMappingURL=index.js.map