@arcgis/ai-components 5.2.0-next.1 → 5.2.0-next.100

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 (325) hide show
  1. package/LICENSE.md +4 -2
  2. package/README.md +2 -2
  3. package/dist/agent-utils/FunctionAgent.d.ts +2 -2
  4. package/dist/agent-utils/LLMAgent.d.ts +7 -4
  5. package/dist/agent-utils/LLMAgent.js +26 -24
  6. package/dist/agent-utils/WorkflowAgent.d.ts +2 -2
  7. package/dist/agent-utils/WorkflowAgent.js +14 -15
  8. package/dist/agent-utils/index.d.ts +177 -0
  9. package/dist/agent-utils/index.js +167 -0
  10. package/dist/agent-utils/middlewares/trace.d.ts +2 -0
  11. package/dist/agent-utils/middlewares/trace.js +25 -33
  12. package/dist/agent-utils/tools/FunctionTool.d.ts +2 -2
  13. package/dist/agent-utils/types.d.ts +37 -8
  14. package/dist/agent-utils/workflows/ConditionalWorkflow.d.ts +2 -2
  15. package/dist/agent-utils/workflows/LoopWorkflow.d.ts +2 -2
  16. package/dist/agent-utils/workflows/ParallelWorkflow.d.ts +2 -2
  17. package/dist/agent-utils/workflows/RouterWorkflow.d.ts +2 -2
  18. package/dist/agent-utils/workflows/SequentialWorkflow.d.ts +2 -2
  19. package/dist/agent-utils/workflows/SwitchWorkflow.d.ts +2 -2
  20. package/dist/agentic-workflow/AgenticWorkflowRuntime.d.ts +24 -0
  21. package/dist/agentic-workflow/Edge.d.ts +16 -0
  22. package/dist/agentic-workflow/WebAgent.d.ts +39 -0
  23. package/dist/agentic-workflow/jsonTypes.d.ts +189 -0
  24. package/dist/agentic-workflow/nodes/AgentNode.d.ts +28 -0
  25. package/dist/agentic-workflow/nodes/BaseNode.d.ts +35 -0
  26. package/dist/agentic-workflow/nodes/EndMessageNode.d.ts +25 -0
  27. package/dist/agentic-workflow/nodes/StartNode.d.ts +21 -0
  28. package/dist/agentic-workflow/nodes/tools/ArcgisTool.d.ts +21 -0
  29. package/dist/agentic-workflow/types.d.ts +29 -0
  30. package/dist/agents/tools/filter/clearFilters/adapter.d.ts +8 -0
  31. package/dist/agents/tools/filter/clearFilters/adapter.js +22 -0
  32. package/dist/agents/tools/filter/resetMap/adapter.d.ts +8 -0
  33. package/dist/agents/tools/filter/resetMap/adapter.js +22 -0
  34. package/dist/agents/tools/filter/setFeatureEffect/adapter.d.ts +8 -0
  35. package/dist/agents/tools/filter/setFeatureEffect/adapter.js +121 -0
  36. package/dist/agents/tools/help/listFields/adapter.d.ts +11 -0
  37. package/dist/agents/tools/help/listFields/adapter.js +30 -0
  38. package/dist/agents/tools/navigation/goToAddress/adapter.d.ts +10 -0
  39. package/dist/agents/tools/navigation/goToAddress/adapter.js +60 -0
  40. package/dist/agents/tools/navigation/goToBookmark/adapter.d.ts +8 -0
  41. package/dist/agents/tools/navigation/goToBookmark/adapter.js +30 -0
  42. package/dist/agents/tools/navigation/goToFeatures/adapter.d.ts +8 -0
  43. package/dist/agents/tools/navigation/goToFeatures/adapter.js +50 -0
  44. package/dist/agents/tools/navigation/goToFullExtent/adapter.d.ts +8 -0
  45. package/dist/agents/tools/navigation/goToFullExtent/adapter.js +27 -0
  46. package/dist/agents/tools/navigation/goToHomeExtent/adapter.d.ts +8 -0
  47. package/dist/agents/tools/navigation/goToHomeExtent/adapter.js +24 -0
  48. package/dist/agents/tools/navigation/goToLayer/adapter.d.ts +8 -0
  49. package/dist/agents/tools/navigation/goToLayer/adapter.js +26 -0
  50. package/dist/agents/tools/navigation/goToScale/adapter.d.ts +8 -0
  51. package/dist/agents/tools/navigation/goToScale/adapter.js +21 -0
  52. package/dist/agents/tools/navigation/goToViewpoint/adapter.d.ts +8 -0
  53. package/dist/agents/tools/navigation/goToViewpoint/adapter.js +42 -0
  54. package/dist/agents/tools/navigation/goToZoom/adapter.d.ts +8 -0
  55. package/dist/agents/tools/navigation/goToZoom/adapter.js +21 -0
  56. package/dist/agents/tools/query/getAttribute/adapter.d.ts +8 -0
  57. package/dist/agents/tools/query/getAttribute/adapter.js +40 -0
  58. package/dist/agents/tools/query/getStatistics/adapter.d.ts +8 -0
  59. package/dist/agents/tools/query/getStatistics/adapter.js +157 -0
  60. package/dist/agents/tools/query/getTopFeatures/adapter.d.ts +8 -0
  61. package/dist/agents/tools/query/getTopFeatures/adapter.js +144 -0
  62. package/dist/agents/tools/query/queryFeatures/adapter.d.ts +8 -0
  63. package/dist/agents/tools/query/queryFeatures/adapter.js +130 -0
  64. package/dist/agents/tools/search/findRelevantFields/adapter.d.ts +8 -0
  65. package/dist/agents/tools/search/findRelevantFields/adapter.js +57 -0
  66. package/dist/agents/tools/search/findRelevantLayers/adapter.d.ts +8 -0
  67. package/dist/agents/tools/search/findRelevantLayers/adapter.js +38 -0
  68. package/dist/cdn/22KHSDJI.js +2 -0
  69. package/dist/cdn/2EY3BQQX.js +2 -0
  70. package/dist/cdn/2O4DON37.js +2 -0
  71. package/dist/cdn/34O57OGV.js +2 -0
  72. package/dist/cdn/{AMP6IALT.js → 3UEKINYC.js} +1 -1
  73. package/dist/cdn/434TAA3J.js +2 -0
  74. package/dist/cdn/4OGR5QKS.js +2 -0
  75. package/dist/cdn/5FL5BTTX.js +66 -0
  76. package/dist/cdn/5HBAJ57P.js +2 -0
  77. package/dist/cdn/5K5ZY267.js +2 -0
  78. package/dist/cdn/5MK44FNO.js +2 -0
  79. package/dist/cdn/5WYRJMBW.js +2 -0
  80. package/dist/cdn/5X7EG7D2.js +2 -0
  81. package/dist/cdn/5XZLS7UO.js +2 -0
  82. package/dist/cdn/5ZFUGNRN.js +2 -0
  83. package/dist/cdn/655YIKL3.js +11 -0
  84. package/dist/cdn/6ECRQVHY.js +2 -0
  85. package/dist/cdn/6OOZSZRJ.js +2 -0
  86. package/dist/cdn/{3PKJWIC3.js → 6P44KOKX.js} +1 -1
  87. package/dist/cdn/6YYPVU7H.js +3 -0
  88. package/dist/cdn/7BCQMK6D.js +2 -0
  89. package/dist/cdn/7SRLZQVC.js +5 -0
  90. package/dist/cdn/7V6OSTFC.js +2 -0
  91. package/dist/cdn/7VAQUCBU.js +9 -0
  92. package/dist/cdn/7VUSIGEM.js +2 -0
  93. package/dist/cdn/ACJTJLZN.js +2 -0
  94. package/dist/cdn/AI6DYOKR.js +181 -0
  95. package/dist/cdn/AKD5UOVX.js +2 -0
  96. package/dist/cdn/ANRQWYU2.js +2 -0
  97. package/dist/cdn/{ZS2TZ6BF.js → AOVJ34QE.js} +1 -1
  98. package/dist/cdn/APFZY4PI.js +2 -0
  99. package/dist/cdn/B2JDVLA6.js +2 -0
  100. package/dist/cdn/BE7BRJZD.js +2 -0
  101. package/dist/cdn/{FL4W4VYN.js → BL273EGZ.js} +17 -1
  102. package/dist/cdn/C4FEETBZ.js +2 -0
  103. package/dist/cdn/C4JT4S5E.js +2 -0
  104. package/dist/cdn/CCC6LBMY.js +2 -0
  105. package/dist/cdn/{5ZZGKP7N.js → CEKOEHB3.js} +1 -1
  106. package/dist/cdn/CJMUJXPL.js +2 -0
  107. package/dist/cdn/COH3QXWG.js +4 -0
  108. package/dist/cdn/CP5BVGJU.js +2 -0
  109. package/dist/cdn/D5UFYQHN.js +44 -0
  110. package/dist/cdn/EWLXNGKH.js +208 -0
  111. package/dist/cdn/EYOWRGDP.js +2 -0
  112. package/dist/cdn/F5NIRETW.js +2 -0
  113. package/dist/cdn/FDOMMK2M.js +2 -0
  114. package/dist/cdn/FG647IP6.js +2 -0
  115. package/dist/cdn/FJO4KNOZ.js +2 -0
  116. package/dist/cdn/FUF3NAU7.js +2 -0
  117. package/dist/cdn/FXP5UIQU.js +156 -0
  118. package/dist/cdn/{ZLXN7NMF.js → FYZATVB3.js} +10 -8
  119. package/dist/cdn/G2EGT3CF.js +6 -0
  120. package/dist/cdn/G3SF6U2U.js +2 -0
  121. package/dist/cdn/G7OMHU2B.js +2 -0
  122. package/dist/cdn/HAEFC2SJ.js +2 -0
  123. package/dist/cdn/HDACNIZF.js +2 -0
  124. package/dist/cdn/HHFNQR6Z.js +2 -0
  125. package/dist/cdn/HHUQXL3R.js +2 -0
  126. package/dist/cdn/IBZ2NEAO.js +2 -0
  127. package/dist/cdn/{FX7UOGHP.js → ICBIUFK7.js} +1 -1
  128. package/dist/cdn/ICQCK5D3.js +2 -0
  129. package/dist/cdn/IHP25JWI.js +99 -0
  130. package/dist/cdn/IJVMUS2L.js +14 -0
  131. package/dist/cdn/J6A4AS7E.js +22 -0
  132. package/dist/cdn/J6SZIQJA.js +2 -0
  133. package/dist/cdn/JCOA24UH.js +3 -0
  134. package/dist/cdn/{NE7E52YR.js → JEBRN3EU.js} +9 -3
  135. package/dist/cdn/JO5ETMPS.js +2 -0
  136. package/dist/cdn/K2R6XVK3.js +2 -0
  137. package/dist/cdn/KITIP6J2.js +2 -0
  138. package/dist/cdn/KWD2ECTM.js +2 -0
  139. package/dist/cdn/{4HU7735A.js → LAYVGCPL.js} +6 -4
  140. package/dist/cdn/{7RCQFLPP.js → LK7ZIQW6.js} +1 -1
  141. package/dist/cdn/LLUGJKAQ.js +2 -0
  142. package/dist/cdn/MWYBF3F3.js +66 -0
  143. package/dist/cdn/{V2P4AIGG.js → MXTXJKFE.js} +1 -1
  144. package/dist/cdn/MY47B3CE.js +3 -0
  145. package/dist/cdn/NEV6OZN3.js +71 -0
  146. package/dist/cdn/NNXISHCA.js +14 -0
  147. package/dist/cdn/NZSOJ726.js +2 -0
  148. package/dist/cdn/O4NVW75A.js +2 -0
  149. package/dist/cdn/OE3GW5LE.js +2 -0
  150. package/dist/cdn/{23EQTPO3.js → OKVLGJAG.js} +1 -1
  151. package/dist/cdn/ONQ6JSBJ.js +2 -0
  152. package/dist/cdn/OX64WOEL.js +22 -0
  153. package/dist/cdn/{LQ6R5YRN.js → PQ2DPOFM.js} +1 -1
  154. package/dist/cdn/PUHRBGKB.js +2 -0
  155. package/dist/cdn/Q57QWN5W.js +2 -0
  156. package/dist/cdn/QUKNPVAF.js +2 -0
  157. package/dist/cdn/R2PQVY4O.js +2 -0
  158. package/dist/cdn/R74ZHFA6.js +2 -0
  159. package/dist/cdn/RBE55SWR.js +2 -0
  160. package/dist/cdn/RHYNE5OE.js +2 -0
  161. package/dist/cdn/RLEHNAIA.js +2 -0
  162. package/dist/cdn/RVSTAUQS.js +2 -0
  163. package/dist/cdn/{X2ZDYHCG.js → SDWWUWAF.js} +10 -5
  164. package/dist/cdn/SXM4NUT5.js +2 -0
  165. package/dist/cdn/SZ2QSSB3.js +2 -0
  166. package/dist/cdn/T4RIGOXB.js +2 -0
  167. package/dist/cdn/TCH5I5LS.js +2 -0
  168. package/dist/cdn/TEPP7YPR.js +2 -0
  169. package/dist/cdn/TMVF2W5N.js +36 -0
  170. package/dist/cdn/TPULIO6I.js +34 -0
  171. package/dist/cdn/UDRKUVZP.js +2 -0
  172. package/dist/cdn/{6YMR4QSD.js → UHEYPSOR.js} +1 -1
  173. package/dist/cdn/UHNVDALX.js +18 -0
  174. package/dist/cdn/UZLQALHY.js +2 -0
  175. package/dist/cdn/V6HOUZPZ.js +2 -0
  176. package/dist/cdn/VAXH6RUQ.js +134 -0
  177. package/dist/cdn/VLLZ2FFU.js +2 -0
  178. package/dist/cdn/VOKXKU7M.js +56 -0
  179. package/dist/cdn/VXFQANGJ.js +2 -0
  180. package/dist/cdn/WGO5SER7.js +6 -0
  181. package/dist/cdn/WJXXOKGA.js +9 -0
  182. package/dist/cdn/WKTQVBFJ.js +2 -0
  183. package/dist/cdn/{DHOVCT6R.js → WSWB3B7B.js} +1 -1
  184. package/dist/cdn/XX6GHMNR.js +2 -0
  185. package/dist/cdn/Y7XD7ZRD.js +2 -0
  186. package/dist/cdn/YEZ3AMNX.js +2 -0
  187. package/dist/cdn/YLVJA4ZE.js +2 -0
  188. package/dist/cdn/Z5HWPSZN.js +2 -0
  189. package/dist/cdn/Z5W4V7RC.js +2 -0
  190. package/dist/cdn/ZDV4K4WG.js +2 -0
  191. package/dist/cdn/ZOEMBHRF.js +2 -0
  192. package/dist/cdn/ZRVZMPFN.js +2 -0
  193. package/dist/cdn/{ZTBA5PM7.js → ZU2FHVNK.js} +1 -1
  194. package/dist/cdn/agent-utils/index.js +2 -0
  195. package/dist/cdn/agent-utils/middlewares/humanInTheLoop.js +3 -0
  196. package/dist/cdn/agent-utils/middlewares/middleware.js +2 -0
  197. package/dist/cdn/agent-utils/middlewares/trace.js +2 -0
  198. package/dist/cdn/assets/assistant/t9n/messages.en.json +1 -1
  199. package/dist/cdn/assets/assistant-interrupt/t9n/messages.en.json +1 -1
  200. package/dist/cdn/assets/assistant-interrupt-preview/t9n/messages.en.json +1 -0
  201. package/dist/cdn/assets/assistant-message/t9n/messages.en.json +1 -0
  202. package/dist/cdn/assets/assistant-message-loading/t9n/messages.en.json +1 -0
  203. package/dist/cdn/index.js +1 -1
  204. package/dist/cdn/main.css +1 -1
  205. package/dist/chunks/adapter.js +1299 -2113
  206. package/dist/chunks/arcgisKnowledgeGraph.js +128 -72
  207. package/dist/chunks/arcgis_knowledge_current_lc_context.js +19 -2
  208. package/dist/chunks/arcgis_knowledge_current_map_context.js +31 -2
  209. package/dist/chunks/arcgis_knowledge_cypher_query_prompt.js +102 -0
  210. package/dist/chunks/arcgis_knowledge_summarize_result_prompt.js +116 -27
  211. package/dist/chunks/baseAgentState.js +58 -0
  212. package/dist/chunks/converterUtils.js +66 -41
  213. package/dist/chunks/dataExplorationGraph.js +135 -179
  214. package/dist/chunks/data_explore_query_prompt.js +9 -4
  215. package/dist/chunks/fetchAgentContext.js +13 -0
  216. package/dist/chunks/fetchService.js +10 -0
  217. package/dist/chunks/fieldStatistics.js +79 -0
  218. package/dist/chunks/formatFeatureAttributes.js +132 -0
  219. package/dist/chunks/generateLayerDescriptions.js +250 -246
  220. package/dist/chunks/helpGraph.js +35 -25
  221. package/dist/chunks/help_prompt.js +34 -17
  222. package/dist/chunks/index.js +11 -0
  223. package/dist/chunks/intent_prompt.js +16 -0
  224. package/dist/chunks/layerStylingGraph.js +37 -31
  225. package/dist/chunks/mergeWhereClauses.js +15 -0
  226. package/dist/chunks/navigationGraph.js +135 -111
  227. package/dist/chunks/navigation_intent_prompt.js +8 -2
  228. package/dist/chunks/orchestrator.js +530 -280
  229. package/dist/chunks/resolvePointGeometryFilter.js +92 -0
  230. package/dist/chunks/slottableRequestUtils.js +3 -7
  231. package/dist/chunks/state.js +21 -27
  232. package/dist/chunks/summarize_query_response_prompt.js +9 -7
  233. package/dist/chunks/toolCallResponse.js +14 -10
  234. package/dist/chunks/utils2.js +11 -11
  235. package/dist/components/arcgis-assistant/customElement.d.ts +96 -0
  236. package/dist/components/arcgis-assistant/customElement.js +398 -149
  237. package/dist/components/arcgis-assistant/index.js +2 -3
  238. package/dist/components/arcgis-assistant/types.d.ts +14 -1
  239. package/dist/components/arcgis-assistant-agent/customElement.d.ts +13 -1
  240. package/dist/components/arcgis-assistant-agent/customElement.js +614 -10
  241. package/dist/components/arcgis-assistant-chat/customElement.d.ts +8 -2
  242. package/dist/components/arcgis-assistant-chat/customElement.js +23 -18
  243. package/dist/components/arcgis-assistant-chat-entry/customElement.d.ts +4 -1
  244. package/dist/components/arcgis-assistant-chat-entry/customElement.js +25 -18
  245. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +20 -4
  246. package/dist/components/arcgis-assistant-help-agent/customElement.js +29 -7
  247. package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +8 -1
  248. package/dist/components/arcgis-assistant-interrupt/customElement.js +17 -14
  249. package/dist/components/arcgis-assistant-interrupt-preview/customElement.js +24 -0
  250. package/dist/components/arcgis-assistant-interrupt-preview/index.js +2 -0
  251. package/dist/components/arcgis-assistant-knowledge-agent/customElement.d.ts +7 -7
  252. package/dist/components/arcgis-assistant-knowledge-agent/customElement.js +40 -16
  253. package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +30 -7
  254. package/dist/components/arcgis-assistant-message/customElement.d.ts +26 -0
  255. package/dist/components/arcgis-assistant-message/customElement.js +29 -26
  256. package/dist/components/arcgis-assistant-message/index.d.ts +1 -0
  257. package/dist/components/arcgis-assistant-message/index.js +2 -0
  258. package/dist/components/arcgis-assistant-message-block/customElement.d.ts +1 -1
  259. package/dist/components/arcgis-assistant-message-block/customElement.js +18 -11
  260. package/dist/components/arcgis-assistant-message-block/index.js +1 -0
  261. package/dist/components/arcgis-assistant-message-feedback/customElement.d.ts +4 -1
  262. package/dist/components/arcgis-assistant-message-footer/customElement.d.ts +4 -1
  263. package/dist/components/arcgis-assistant-message-loading/customElement.d.ts +11 -1
  264. package/dist/components/arcgis-assistant-message-loading/customElement.js +8 -7
  265. package/dist/components/arcgis-assistant-message-loading/index.js +1 -0
  266. package/dist/components/arcgis-assistant-message-log/customElement.d.ts +4 -1
  267. package/dist/components/arcgis-assistant-message-read-aloud/customElement.d.ts +4 -1
  268. package/dist/components/arcgis-assistant-message-text/customElement.d.ts +5 -1
  269. package/dist/components/arcgis-assistant-message-text/customElement.js +12 -12
  270. package/dist/components/arcgis-assistant-navigation-agent/customElement.js +18 -4
  271. package/dist/components/arcgis-assistant-speech-input/customElement.d.ts +6 -1
  272. package/dist/components/arcgis-assistant-speech-input/customElement.js +34 -52
  273. package/dist/components/arcgis-assistant-suggested-prompts/customElement.d.ts +4 -1
  274. package/dist/components/arcgis-assistant-suggested-prompts/customElement.js +8 -8
  275. package/dist/components/arcgis-assistant-user-message/customElement.d.ts +6 -1
  276. package/dist/components/arcgis-assistant-user-message/customElement.js +15 -10
  277. package/dist/docs/api.json +1 -1
  278. package/dist/docs/docs.json +1 -1
  279. package/dist/docs/vscode.html-custom-data.json +1 -1
  280. package/dist/docs/web-types.json +1 -1
  281. package/dist/index.d.ts +4 -0
  282. package/dist/loader.js +9 -8
  283. package/dist/oauth-callback.html +1 -1
  284. package/dist/orchestrator/orchestrator/orchestratorEvents.d.ts +78 -0
  285. package/dist/types/lumina.d.ts +14 -7
  286. package/dist/types/preact.d.ts +15 -7
  287. package/dist/types/react.d.ts +16 -7
  288. package/dist/types/stencil.d.ts +16 -9
  289. package/dist/utils/index.d.ts +135 -65
  290. package/dist/utils/index.js +55 -50
  291. package/package.json +32 -12
  292. package/dist/cdn/2AXF774U.js +0 -2
  293. package/dist/cdn/462JBSEV.js +0 -422
  294. package/dist/cdn/5QAHYX7Y.js +0 -5
  295. package/dist/cdn/7BCR6TUO.js +0 -2
  296. package/dist/cdn/7GH7VSB2.js +0 -2
  297. package/dist/cdn/7PLV4QH6.js +0 -2
  298. package/dist/cdn/AO7BQHKC.js +0 -2
  299. package/dist/cdn/AXDZBBNL.js +0 -45
  300. package/dist/cdn/DDLZOMUY.js +0 -2
  301. package/dist/cdn/F2AHA4GB.js +0 -54
  302. package/dist/cdn/FHVXO2WG.js +0 -166
  303. package/dist/cdn/FX5JFRDL.js +0 -2
  304. package/dist/cdn/GSEPHN3A.js +0 -106
  305. package/dist/cdn/H7422XUG.js +0 -2
  306. package/dist/cdn/HB5A5R2E.js +0 -2
  307. package/dist/cdn/JY6LLOUJ.js +0 -22
  308. package/dist/cdn/KMQ3SP4I.js +0 -5
  309. package/dist/cdn/MDVYQQUG.js +0 -14
  310. package/dist/cdn/MH5RPXHM.js +0 -2
  311. package/dist/cdn/NAUXSHIE.js +0 -72
  312. package/dist/cdn/NVI3I46B.js +0 -2
  313. package/dist/cdn/OAVEHGB6.js +0 -2
  314. package/dist/cdn/OH64RMOR.js +0 -4
  315. package/dist/cdn/ON2V5XI2.js +0 -3
  316. package/dist/cdn/P6OPJQMC.js +0 -3
  317. package/dist/cdn/QR54T33D.js +0 -2
  318. package/dist/cdn/RVOAPUBN.js +0 -2
  319. package/dist/cdn/S6W6HV4T.js +0 -36
  320. package/dist/cdn/SXDLXCIM.js +0 -2
  321. package/dist/cdn/USMDJUFS.js +0 -2
  322. package/dist/cdn/V5YEZSRY.js +0 -16
  323. package/dist/cdn/Y333DGV6.js +0 -2
  324. package/dist/cdn/YIMNOUTF.js +0 -2
  325. package/dist/cdn/YY2SBO3V.js +0 -2
@@ -1,79 +1,127 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import S from "@arcgis/core/identity/IdentityManager.js";
3
- import b from "@arcgis/core/portal/Portal.js";
4
- import { p as I, s as l, D as R, q as k, r as M, W as C } from "./generateLayerDescriptions.js";
5
- import { isGraphInterrupt as A, StateGraph as F, START as L, END as W, MemorySaver as $ } from "@langchain/langgraph/web";
6
- import { HumanMessage as D, AIMessage as j } from "@langchain/core/messages";
7
- import * as P from "@arcgis/core/core/reactiveUtils.js";
8
- import q from "@arcgis/core/layers/FeatureLayer.js";
9
- import H from "@arcgis/core/request.js";
10
- const O = async (t) => {
11
- const e = await T(), s = await I("default"), n = b.getDefault(), i = (await S.getCredential(`${n.url}/sharing`)).token, a = {
2
+ import M from "@arcgis/core/identity/IdentityManager.js";
3
+ import _ from "@arcgis/core/portal/Portal.js";
4
+ import { j as $, k as b, D, n as F, o as L, W } from "./generateLayerDescriptions.js";
5
+ import { isGraphInterrupt as q, StateGraph as T, START as j, END as H, MemorySaver as P } from "@langchain/langgraph/web";
6
+ import { generateGuid as A } from "@arcgis/toolkit/string";
7
+ import { HumanMessage as U, AIMessage as O } from "@langchain/core/messages";
8
+ import { s as p } from "./index.js";
9
+ import { BaseCallbackHandler as G } from "@langchain/core/callbacks/base";
10
+ import * as N from "@arcgis/core/core/reactiveUtils.js";
11
+ import V from "@arcgis/core/layers/FeatureLayer.js";
12
+ import z from "@arcgis/core/request.js";
13
+ const B = async (n) => {
14
+ const e = await Q(), r = await $("default"), s = _.getDefault(), a = (await M.getCredential(`${s.url}/sharing`)).token, i = {
12
15
  type: "generateEmbeddings",
13
- webmapEmbeddings: t,
14
- auth: { apiUrl: s, token: i }
16
+ webmapEmbeddings: n,
17
+ auth: { apiUrl: r, token: a }
15
18
  };
16
- return e.postMessage(a), await new Promise((c, d) => {
17
- const o = (u) => {
18
- u.data === "completed" && (e.removeEventListener("message", o), c());
19
- }, g = (u) => {
20
- e.removeEventListener("message", o), d(u instanceof Error ? u : new Error("Embeddings worker error"));
19
+ return e.postMessage(i), await new Promise((o, d) => {
20
+ const c = (g) => {
21
+ g.data === "completed" && (e.removeEventListener("message", c), o());
22
+ }, u = (g) => {
23
+ e.removeEventListener("message", c), d(g instanceof Error ? g : new Error("Embeddings worker error"));
21
24
  };
22
- e.addEventListener("message", o), e.addEventListener("error", g, { once: !0 });
25
+ e.addEventListener("message", c), e.addEventListener("error", u, { once: !0 });
23
26
  }), e;
24
- }, T = async () => {
27
+ }, Q = async () => {
25
28
  {
26
- const t = (await import("./embeddings.worker.js")).default;
27
- return new t();
28
- }
29
- }, U = (t) => {
30
- t.currentIntent = "none";
31
- }, N = async (t, e) => {
32
- if (t.agentExecutionContext.userRequest) {
33
- const n = new D(t.agentExecutionContext.userRequest.trim());
34
- t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], U(t);
35
- }
36
- const s = e?.configurable?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
37
- return await l({ text: `Available agents: ${[...s].join(", ")}` }, e), await l({ text: "Analyzing user input" }, e), t;
38
- }, G = async (t, e) => (await l({ text: "Exiting..." }, e), t), y = (t) => typeof t == "object" && t !== null && !Array.isArray(t), _ = (t, e) => {
39
- if (!y(t)) {
40
- t !== void 0 && console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`);
29
+ const n = (await import("./embeddings.worker.js")).default;
30
+ return new n();
31
+ }
32
+ }, K = (n) => {
33
+ n.currentIntent = "none";
34
+ }, J = async (n, e) => {
35
+ const r = b(e);
36
+ if (n.agentExecutionContext.userRequest) {
37
+ const t = new U(n.agentExecutionContext.userRequest.trim());
38
+ n.agentExecutionContext.messages = [...n.agentExecutionContext.messages, t], K(n);
39
+ }
40
+ const s = r?.services.agentRegistry.list().map((t) => t.agent.id) ?? [];
41
+ return await p({ text: `Available agents: ${[...s].join(", ")}` }, e), await p({ text: "Analyzing user input" }, e), n;
42
+ }, X = async (n, e) => (await p({ text: "Exiting..." }, e), n), E = (n) => typeof n == "object" && n !== null && !Array.isArray(n), Y = (n, e) => {
43
+ if (!E(n)) {
44
+ n !== void 0 && console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`);
41
45
  return;
42
46
  }
43
- const s = {};
44
- for (const [n, r] of Object.entries(t)) {
45
- if (!y(r) || !("value" in r)) {
47
+ const r = {};
48
+ for (const [s, t] of Object.entries(n)) {
49
+ if (!E(t) || !("value" in t)) {
46
50
  console.warn(
47
- `Agent "${e}" returned invalid sharedStatePatch entry for key "${n}". Ignoring that entry.`
51
+ `Agent "${e}" returned invalid sharedStatePatch entry for key "${s}". Ignoring that entry.`
48
52
  );
49
53
  continue;
50
54
  }
51
- s[n] = { value: r.value };
55
+ r[s] = { value: t.value };
52
56
  }
53
- return s;
54
- }, V = (t) => {
55
- const { previousSharedState: e, patch: s, agentId: n } = t;
56
- if (!s)
57
+ return r;
58
+ }, Z = (n) => {
59
+ const { previousSharedState: e, patch: r, agentId: s } = n;
60
+ if (!r)
57
61
  return e;
58
- const r = Date.now(), i = {
62
+ const t = Date.now(), a = {
59
63
  ...e
60
64
  };
61
- for (const [a, c] of Object.entries(s))
62
- c?.value !== void 0 && (i[a] = {
63
- value: c.value,
65
+ for (const [i, o] of Object.entries(r))
66
+ o?.value !== void 0 && (a[i] = {
67
+ value: o.value,
64
68
  meta: {
65
- updatedByAgentId: n,
66
- updatedAt: r
69
+ updatedByAgentId: s,
70
+ updatedAt: t
67
71
  }
68
72
  });
69
- return i;
70
- }, w = (t) => {
71
- if (typeof t != "string")
73
+ return a;
74
+ }, ee = 256, te = /* @__PURE__ */ new Set(["point", "polyline", "polygon", "extent", "custom"]), ne = (n) => typeof n == "object" && n !== null && !Array.isArray(n), re = (n, e) => {
75
+ if (n === void 0)
76
+ return;
77
+ if (!Array.isArray(n)) {
78
+ console.warn(`Agent "${e}" returned invalid sharedResourceAdditions. Ignoring it.`);
79
+ return;
80
+ }
81
+ const r = [];
82
+ for (const [s, t] of n.entries()) {
83
+ if (!ne(t) || typeof t.kind != "string" || !te.has(t.kind) || typeof t.description != "string" || !t.description.trim() || !("payload" in t) || t.payload === void 0) {
84
+ console.warn(
85
+ `Agent "${e}" returned invalid sharedResourceAdditions entry at index ${s}. Ignoring that entry.`
86
+ );
87
+ continue;
88
+ }
89
+ let a;
90
+ try {
91
+ a = structuredClone(t.payload);
92
+ } catch {
93
+ console.warn(
94
+ `Agent "${e}" returned invalid sharedResourceAdditions entry at index ${s}. Ignoring that entry.`
95
+ );
96
+ continue;
97
+ }
98
+ r.push({
99
+ kind: t.kind,
100
+ description: t.description.trim().slice(0, ee),
101
+ payload: a
102
+ });
103
+ }
104
+ return r.length ? r : void 0;
105
+ }, se = (n) => {
106
+ const { previousSharedResources: e, additions: r, agentId: s } = n;
107
+ if (!r?.length)
108
+ return e;
109
+ const t = Date.now(), a = r.map((i) => ({
110
+ ...i,
111
+ id: A(),
112
+ meta: {
113
+ createdByAgentId: s,
114
+ createdAt: t
115
+ }
116
+ }));
117
+ return [...e, ...a].slice(-50);
118
+ }, R = (n) => {
119
+ if (typeof n != "string")
72
120
  return;
73
- const e = t.trim();
121
+ const e = n.trim();
74
122
  return e || void 0;
75
- }, z = (t) => {
76
- switch (t) {
123
+ }, ae = (n) => {
124
+ switch (n) {
77
125
  case "failed":
78
126
  return "Agent failed without a summary.";
79
127
  case "unknown":
@@ -83,99 +131,203 @@ const O = async (t) => {
83
131
  default:
84
132
  return "Agent completed without a summary.";
85
133
  }
86
- }, Q = (t, e) => {
87
- const s = w(e?.outputMessage), n = w(e?.summary), r = e?.status, i = r === "success" || r === "failed" ? r : "unknown";
88
- i === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
89
- const a = _(e?.sharedStatePatch, t);
134
+ }, ie = (n, e) => {
135
+ const r = R(e?.outputMessage), s = R(e?.summary), t = e?.status, a = t === "success" || t === "failed" ? t : "unknown";
136
+ a === "unknown" && console.warn(`Agent "${n}" returned missing/invalid status. Defaulting to "unknown".`);
137
+ const i = Y(e?.sharedStatePatch, n), o = re(e?.sharedResourceAdditions, n);
90
138
  return {
91
- outputMessage: s,
92
- summary: n ?? s ?? z(i),
93
- status: i,
94
- sharedStatePatch: a
139
+ outputMessage: r,
140
+ summary: s ?? r ?? ae(a),
141
+ status: a,
142
+ sharedStatePatch: i,
143
+ sharedResourceAdditions: o
95
144
  };
96
- }, f = 4e3, B = async (t, e) => {
97
- const s = e?.configurable, { agentRegistry: n } = s.services, r = n?.get(t.currentIntent);
98
- if (!r)
99
- return console.warn(`No agent found for intent: ${t.currentIntent}`), t;
100
- await l({ text: `Executing registered agent: ${r.agent.name}` }, e);
101
- const i = {
145
+ }, x = 4e3, oe = async (n, e) => {
146
+ const r = b(e);
147
+ if (e?.signal?.aborted)
148
+ return await p({ text: "Run cancelled; skipping agent execution" }, e), {
149
+ ...n,
150
+ currentIntent: "none",
151
+ requiresFollowUp: !1
152
+ };
153
+ const { agentRegistry: s } = r?.services ?? {}, t = s?.get(n.currentIntent);
154
+ if (!t)
155
+ return console.warn(`No agent found for intent: ${n.currentIntent}`), n;
156
+ await p({ text: `Executing registered agent: ${t.agent.name}` }, e);
157
+ const a = {
102
158
  ...e ?? {},
159
+ metadata: {
160
+ ...e?.metadata,
161
+ agentId: t.agent.id
162
+ },
103
163
  configurable: {
104
- ...s ?? {},
105
- agentId: r.agent.id,
106
- context: r.getContext ? await r.getContext() : void 0
164
+ ...r ?? {},
165
+ agentId: t.agent.id,
166
+ context: t.getContext ? await t.getContext() : void 0
107
167
  }
108
168
  };
109
- let a;
169
+ let i;
110
170
  try {
111
- const o = await r.agent.createGraph().compile().invoke(
171
+ const c = await t.agent.createGraph().compile().invoke(
112
172
  {
113
173
  agentExecutionContext: {
114
- ...t.agentExecutionContext,
174
+ ...n.agentExecutionContext,
115
175
  // deep clone on messages did not work in agents, so its a shallow clone here.
116
- messages: [...t.agentExecutionContext.messages],
176
+ messages: [...n.agentExecutionContext.messages],
117
177
  // deep clone to prevent accidental mutations by agents
118
- priorSteps: structuredClone(t.agentExecutionContext.priorSteps ?? []),
119
- sharedState: structuredClone(t.agentExecutionContext.sharedState ?? {})
178
+ priorSteps: structuredClone(n.agentExecutionContext.priorSteps ?? []),
179
+ sharedState: structuredClone(n.agentExecutionContext.sharedState ?? {}),
180
+ sharedResources: structuredClone(n.agentExecutionContext.sharedResources ?? [])
120
181
  }
121
182
  },
122
- i
183
+ a
123
184
  );
124
- a = Q(r.agent.name, o), await l({ text: `Finished executing registered agent: ${r.agent.name}` }, e);
125
- } catch (o) {
126
- if (A(o))
127
- throw o;
128
- const g = o instanceof Error ? o.message : String(o);
129
- console.error(`Agent "${r.agent.name}" failed:`, o), await l({ text: `Registered agent failed: ${r.agent.name}. ${g}` }, e), a = {
185
+ i = ie(t.agent.name, c), await p({ text: `Finished executing registered agent: ${t.agent.name}` }, e);
186
+ } catch (c) {
187
+ if (q(c) || e?.signal?.aborted || c instanceof Error && c.name === "AbortError")
188
+ throw c;
189
+ const u = c instanceof Error ? c.message : String(c);
190
+ console.error(`Agent "${t.agent.name}" failed:`, c), await p({ text: `Registered agent failed: ${t.agent.name}. ${u}` }, e), i = {
130
191
  status: "failed",
131
- outputMessage: `Agent execution failed: ${g}`,
132
- summary: `Agent execution failed: ${g}`
192
+ outputMessage: `Agent execution failed: ${u}`,
193
+ summary: `Agent execution failed: ${u}`
133
194
  };
134
195
  }
135
- const c = a.outputMessage, d = [...t.agentExecutionContext.messages];
136
- if (c) {
137
- const o = c.length > f ? `${c.slice(0, f - 14)}
138
- [truncated]` : c;
139
- d.push(new j(o));
196
+ const o = i.outputMessage, d = [...n.agentExecutionContext.messages];
197
+ if (o) {
198
+ const c = o.length > x ? `${o.slice(0, x - 14)}
199
+ [truncated]` : o;
200
+ d.push(new O(c));
140
201
  }
141
202
  return {
142
- ...t,
143
- stepCount: t.stepCount + 1,
144
- lastExecutedAgent: r.agent.id,
145
- requiresFollowUp: a.status === "failed" ? !0 : t.requiresFollowUp,
146
- finalOutputMessage: c ?? "",
203
+ ...n,
204
+ stepCount: n.stepCount + 1,
205
+ lastExecutedAgent: t.agent.id,
206
+ requiresFollowUp: i.status === "failed" ? !0 : n.requiresFollowUp,
207
+ finalOutputMessage: o ?? "",
147
208
  agentExecutionContext: {
148
- ...t.agentExecutionContext,
209
+ ...n.agentExecutionContext,
149
210
  messages: d,
150
211
  priorSteps: [
151
- ...t.agentExecutionContext.priorSteps ?? [],
212
+ ...n.agentExecutionContext.priorSteps ?? [],
152
213
  {
153
- agentId: r.agent.id,
154
- assignedTask: t.agentExecutionContext.assignedTask,
155
- summary: a?.summary || "No summary provided.",
156
- status: a?.status || "unknown"
214
+ agentId: t.agent.id,
215
+ assignedTask: n.agentExecutionContext.assignedTask,
216
+ summary: i?.summary || "No summary provided.",
217
+ status: i?.status || "unknown"
157
218
  }
158
219
  ],
159
- sharedState: V({
160
- previousSharedState: t.agentExecutionContext.sharedState,
161
- patch: a.sharedStatePatch,
162
- agentId: r.agent.id
220
+ sharedState: Z({
221
+ previousSharedState: n.agentExecutionContext.sharedState,
222
+ patch: i.sharedStatePatch,
223
+ agentId: t.agent.id
224
+ }),
225
+ sharedResources: se({
226
+ previousSharedResources: n.agentExecutionContext.sharedResources,
227
+ additions: i.sharedResourceAdditions,
228
+ agentId: t.agent.id
163
229
  })
164
230
  }
165
231
  };
166
- }, J = 3, K = () => new F(R).addNode("ingestInput", N).addNode("intentLLM", k).addNode("executeRegisteredAgent", B).addNode("exit", G).addEdge(L, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges(
167
- "executeRegisteredAgent",
168
- (e) => e.stepCount >= J || !e.requiresFollowUp ? "exit" : "intentLLM"
169
- ).addEdge("exit", W);
170
- class X {
232
+ }, ce = async (n, e) => {
233
+ if (n.routing.mode !== "direct")
234
+ throw new Error("Direct agent assignment requires direct routing.");
235
+ return await p({ text: `Doing a direct route to agent: ${n.routing.agentId}` }, e), {
236
+ ...n,
237
+ currentIntent: n.routing.agentId,
238
+ requiresFollowUp: !1,
239
+ agentExecutionContext: {
240
+ ...n.agentExecutionContext,
241
+ assignedTask: n.agentExecutionContext.userRequest
242
+ }
243
+ };
244
+ }, de = 3, ue = (n) => n.routing.mode === "direct" ? "assignDirectAgent" : "intentLLM", ge = (n) => n.routing.mode === "direct" || n.stepCount >= de || !n.requiresFollowUp ? "exit" : "intentLLM", le = () => new T(D).addNode("ingestInput", J).addNode("assignDirectAgent", ce).addNode("intentLLM", F).addNode("executeRegisteredAgent", oe).addNode("exit", X).addEdge(j, "ingestInput").addConditionalEdges("ingestInput", ue).addEdge("assignDirectAgent", "executeRegisteredAgent").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges("executeRegisteredAgent", ge).addEdge("exit", H), he = (n, e) => {
245
+ const r = n.output?.usage_metadata ?? e.usage_metadata, s = n.output?.llmOutput?.tokenUsage, t = r?.input_tokens ?? s?.promptTokens, a = r?.output_tokens ?? s?.completionTokens, i = r?.total_tokens ?? s?.totalTokens;
246
+ if (t === void 0 || a === void 0 || i === void 0)
247
+ return;
248
+ const o = r?.input_token_details?.cache_read, d = r?.output_token_details?.reasoning;
249
+ return {
250
+ input: t,
251
+ output: a,
252
+ total: i,
253
+ ...o !== void 0 && { cacheRead: o },
254
+ ...d !== void 0 && { reasoning: d }
255
+ };
256
+ }, pe = (n, e, r, s) => {
257
+ switch (n) {
258
+ case "chat_model":
259
+ case "llm":
260
+ return "model";
261
+ case "tool":
262
+ case "retriever":
263
+ return n;
264
+ case "chain":
265
+ return !s || e === "LangGraph" ? "workflow" : r === e ? "node" : "chain";
266
+ default:
267
+ return;
268
+ }
269
+ }, me = (n) => {
270
+ if (n instanceof Error)
271
+ return { message: n.message, name: n.name };
272
+ const e = n, r = typeof e?.message == "string" ? e.message : String(n ?? "Unknown runtime error"), s = typeof e?.name == "string" ? e.name : void 0;
273
+ return { message: r, ...s && { name: s } };
274
+ }, ye = ({
275
+ event: n,
276
+ runId: e,
277
+ parentSpanId: r,
278
+ timestamp: s
279
+ }) => {
280
+ const t = /^on_(.+)_(start|end|error)$/u.exec(n.event);
281
+ if (!t)
282
+ return;
283
+ const [, a, i] = t, o = n.metadata ?? {}, d = o.langgraph_node, c = pe(a, n.name, d, r);
284
+ if (!c)
285
+ return;
286
+ const u = o.agentId, g = o.model ?? o.ls_model_name, l = n.data, f = i === "end" && c === "model" ? he(l, o) : void 0, h = n.tags?.includes("langsmith:hidden") || d === "__start__", v = {
287
+ ...g && { model: g },
288
+ ...f && { tokenUsage: f },
289
+ ...h && { internal: !0 }
290
+ }, w = {
291
+ id: n.run_id,
292
+ ...r && { parentId: r },
293
+ label: n.name,
294
+ type: c,
295
+ ...Object.keys(v).length && { metadata: v }
296
+ }, m = { runId: e, timestamp: s, type: "runtime", ...u && { agentId: u } };
297
+ switch (i) {
298
+ case "start":
299
+ return {
300
+ ...m,
301
+ phase: "started",
302
+ span: {
303
+ ...w,
304
+ ...l?.input !== void 0 && { input: l.input }
305
+ }
306
+ };
307
+ case "end":
308
+ return {
309
+ ...m,
310
+ phase: "completed",
311
+ span: {
312
+ ...w,
313
+ ...l?.output !== void 0 && { output: l.output }
314
+ }
315
+ };
316
+ case "error":
317
+ return { ...m, phase: "failed", span: { ...w, error: me(l?.error) } };
318
+ default:
319
+ return;
320
+ }
321
+ };
322
+ class S {
171
323
  constructor() {
172
324
  this.agentRegistry = /* @__PURE__ */ new Map();
173
325
  }
174
326
  register(e) {
175
- const { agent: s } = e;
176
- if (this.agentRegistry.has(s.id))
177
- throw new Error(`Duplicate agent id: ${s.id}`);
178
- this.agentRegistry.set(s.id, e);
327
+ const { agent: r } = e;
328
+ if (this.agentRegistry.has(r.id))
329
+ throw new Error(`Duplicate agent id: ${r.id}`);
330
+ this.agentRegistry.set(r.id, e);
179
331
  }
180
332
  get(e) {
181
333
  return this.agentRegistry.get(e);
@@ -184,42 +336,42 @@ class X {
184
336
  return [...this.agentRegistry.values()];
185
337
  }
186
338
  }
187
- class Y {
339
+ class fe {
188
340
  /**
189
341
  * Create a new InterruptHandler tied to a specific compiled graph and config.
190
342
  */
191
- constructor(e, s) {
192
- this.graph = e, this.config = { ...s };
343
+ constructor(e, r) {
344
+ this.graph = e, this.config = { ...r };
193
345
  }
194
346
  /**
195
347
  * Returns a promise that resolves when the user provides a HITL response.
196
348
  */
197
349
  async waitForUser() {
198
- return await new Promise((e, s) => {
199
- this.resolveWait = e, this.rejectWait = s;
350
+ return await new Promise((e, r) => {
351
+ this.resolveWait = e, this.rejectWait = r;
200
352
  });
201
353
  }
202
354
  /**
203
355
  * Resume graph execution after the UI responds to an interrupt.
204
356
  */
205
- handle(e, s) {
357
+ handle(e, r) {
206
358
  try {
207
- const n = {
359
+ const s = {
208
360
  agentId: e.agentId,
209
361
  id: e.id,
210
- payload: s
211
- }, r = this.graph.streamEvents(null, {
362
+ payload: r
363
+ }, t = this.graph.streamEvents(null, {
212
364
  ...this.config,
213
365
  configurable: {
214
366
  ...this.config.configurable,
215
- hitlResponse: n
367
+ hitlResponse: s
216
368
  },
217
369
  subgraphs: !0,
218
370
  version: "v2"
219
371
  });
220
- this.resolveWait?.(r);
221
- } catch (n) {
222
- this.rejectWait?.(n);
372
+ this.resolveWait?.(t);
373
+ } catch (s) {
374
+ this.rejectWait?.(s);
223
375
  } finally {
224
376
  this.resolveWait = void 0, this.rejectWait = void 0;
225
377
  }
@@ -231,157 +383,157 @@ class Y {
231
383
  this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
232
384
  }
233
385
  }
234
- const Z = async (t) => {
386
+ const we = async (n) => {
235
387
  try {
236
- return await (await M()).embedDocuments(t);
388
+ return await (await L()).embedDocuments(n);
237
389
  } catch (e) {
238
390
  throw console.error("Failed to generate embeddings:", e), e;
239
391
  }
240
- }, E = async (t, e) => {
241
- const s = e.get(t);
242
- if (s)
243
- return s;
244
- const n = await Z([t]);
245
- return e.set(t, n[0]), n[0];
392
+ }, C = async (n, e) => {
393
+ const r = e.get(n);
394
+ if (r)
395
+ return r;
396
+ const s = await we([n]);
397
+ return e.set(n, s[0]), s[0];
246
398
  };
247
- async function ee(t, e, s, n) {
248
- const r = `req-${Date.now()}`, a = {
399
+ async function ve(n, e, r, s) {
400
+ const t = `req-${Date.now()}`, i = {
249
401
  type: "layerSearch",
250
- precomputedEmbedding: n ? await E(t, n) : void 0,
251
- requestId: r,
252
- minScore: s
402
+ precomputedEmbedding: s ? await C(n, s) : void 0,
403
+ requestId: t,
404
+ minScore: r
253
405
  };
254
- return await new Promise((c) => {
255
- const d = (o) => {
256
- o.data.requestId === r && c(o.data.results);
406
+ return await new Promise((o) => {
407
+ const d = (c) => {
408
+ c.data.requestId === t && o(c.data.results);
257
409
  };
258
- e.addEventListener("message", d, { once: !0 }), e.postMessage(a);
410
+ e.addEventListener("message", d, { once: !0 }), e.postMessage(i);
259
411
  });
260
412
  }
261
- function te(t) {
262
- const { worker: e } = t;
413
+ function Ee(n) {
414
+ const { worker: e } = n;
263
415
  return {
264
416
  async searchLayers({
265
- text: s,
266
- minScore: n,
267
- embeddingCache: r
417
+ text: r,
418
+ minScore: s,
419
+ embeddingCache: t
268
420
  }) {
269
- return await ee(s, e, n, r);
421
+ return await ve(r, e, s, t);
270
422
  }
271
423
  };
272
424
  }
273
- const re = async ({
274
- combinedQuery: t,
425
+ const Re = async ({
426
+ combinedQuery: n,
275
427
  layerIds: e,
276
- embeddingsWorker: s,
277
- minScore: n,
278
- topResults: r,
279
- embeddingCache: i
428
+ embeddingsWorker: r,
429
+ minScore: s,
430
+ topResults: t,
431
+ embeddingCache: a
280
432
  }) => {
281
- const a = `req-${Date.now()}`, c = i ? await E(t, i) : void 0, d = {
433
+ const i = `req-${Date.now()}`, o = a ? await C(n, a) : void 0, d = {
282
434
  type: "fieldSearch",
283
435
  layerIdForFieldsSearch: e,
284
- precomputedEmbedding: c,
285
- requestId: a,
286
- minScore: n,
287
- topResults: r
436
+ precomputedEmbedding: o,
437
+ requestId: i,
438
+ minScore: s,
439
+ topResults: t
288
440
  };
289
- return await new Promise((o) => {
290
- const g = (u) => {
291
- if (u.data.requestId !== a)
441
+ return await new Promise((c) => {
442
+ const u = (g) => {
443
+ if (g.data.requestId !== i)
292
444
  return;
293
- const p = u.data.results.map(({ layerId: m, results: h }) => ({
294
- layerId: m,
445
+ const l = g.data.results.map(({ layerId: f, results: h }) => ({
446
+ layerId: f,
295
447
  results: h
296
448
  }));
297
- o(p);
449
+ c(l);
298
450
  };
299
- s.addEventListener("message", g, { once: !0 }), s.postMessage(d);
451
+ r.addEventListener("message", u, { once: !0 }), r.postMessage(d);
300
452
  });
301
453
  };
302
- function ne(t) {
303
- const { worker: e } = t;
454
+ function xe(n) {
455
+ const { worker: e } = n;
304
456
  return {
305
- async searchFields({ text: s, layerIds: n, minScore: r, topResults: i, embeddingCache: a }) {
306
- return await re({
307
- combinedQuery: s,
308
- layerIds: n,
457
+ async searchFields({ text: r, layerIds: s, minScore: t, topResults: a, embeddingCache: i }) {
458
+ return await Re({
459
+ combinedQuery: r,
460
+ layerIds: s,
309
461
  embeddingsWorker: e,
310
- minScore: r,
311
- topResults: i,
312
- embeddingCache: a
462
+ minScore: t,
463
+ topResults: a,
464
+ embeddingCache: i
313
465
  });
314
466
  }
315
467
  };
316
468
  }
317
- const se = (t) => {
318
- const e = C.safeParse(t);
469
+ const Se = (n) => {
470
+ const e = W.safeParse(n);
319
471
  if (!e.success)
320
472
  throw new Error("Embeddings response validation failed. Regenerate embeddings.");
321
473
  return e.data;
322
- }, ae = (t, e) => {
323
- const s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
324
- if (e.allLayers.forEach((r) => {
325
- r instanceof q && n.set(r.id, r);
326
- }), t.length !== n.size)
474
+ }, be = (n, e) => {
475
+ const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
476
+ if (e.allLayers.forEach((t) => {
477
+ t instanceof V && s.set(t.id, t);
478
+ }), n.length !== s.size)
327
479
  throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
328
- for (const r of t) {
329
- const i = n.get(r.id);
330
- if (!i)
480
+ for (const t of n) {
481
+ const a = s.get(t.id);
482
+ if (!a)
331
483
  throw new Error(
332
- `Layer with ID ${r.id} not found in the original map during registry restoration. Regenerate embeddings.`
484
+ `Layer with ID ${t.id} not found in the original map during registry restoration. Regenerate embeddings.`
333
485
  );
334
- if (r.fields.length !== i.fields.length)
486
+ if (t.fields.length !== a.fields.length)
335
487
  throw new Error(
336
- `Field count mismatch for layer ID ${r.id} during registry restoration. Regenerate embeddings.`
488
+ `Field count mismatch for layer ID ${t.id} during registry restoration. Regenerate embeddings.`
337
489
  );
338
- const a = {
339
- name: r.name,
340
- title: r.title,
341
- description: r.description
342
- }, c = /* @__PURE__ */ new Map();
343
- for (const d of r.fields) {
344
- const o = i.fieldsIndex.get(d.name);
345
- if (!o)
490
+ const i = {
491
+ name: t.name,
492
+ title: t.title,
493
+ description: t.description
494
+ }, o = /* @__PURE__ */ new Map();
495
+ for (const d of t.fields) {
496
+ const c = a.fieldsIndex.get(d.name);
497
+ if (!c)
346
498
  throw new Error(
347
- `Field with name ${d.name} not found in the original layer ${r.id} during registry restoration. Regenerate embeddings.`
499
+ `Field with name ${d.name} not found in the original layer ${t.id} during registry restoration. Regenerate embeddings.`
348
500
  );
349
- c.set(d.name, {
501
+ o.set(d.name, {
350
502
  name: d.name,
351
- alias: i.getFieldAlias(d.name) ?? d.alias,
503
+ alias: a.getFieldAlias(d.name) ?? d.alias,
352
504
  description: d.description,
353
- type: o.type || "unknown",
354
- valueType: o.valueType || "unknown",
355
- domain: i.getFieldDomain(d.name) ?? void 0
505
+ type: c.type || "unknown",
506
+ valueType: c.valueType || "unknown",
507
+ domain: a.getFieldDomain(d.name) ?? void 0
356
508
  });
357
509
  }
358
- s.set(r.id, {
359
- layerItem: a,
360
- fieldRegistry: c
510
+ r.set(t.id, {
511
+ layerItem: i,
512
+ fieldRegistry: o
361
513
  });
362
514
  }
363
- return s;
364
- }, ie = async (t) => {
515
+ return r;
516
+ }, Ae = async (n) => {
365
517
  try {
366
- return (await H(t, {
518
+ return (await z(n, {
367
519
  responseType: "json"
368
520
  })).data;
369
521
  } catch (e) {
370
- throw new Error(`Failed to fetch data from ${t}: ${String(e)}`);
522
+ throw new Error(`Failed to fetch data from ${n}: ${String(e)}`);
371
523
  }
372
- }, oe = async (t) => {
373
- const e = t.map;
524
+ }, Ce = async (n) => {
525
+ const e = n.map;
374
526
  if (!e?.portalItem)
375
527
  throw new Error("WebMap portal item is missing.");
376
- const { resources: s } = await e.portalItem.fetchResources(), n = s.find((a) => a.resource.path === "embeddings-v01.json");
377
- if (!n?.resource.url)
528
+ const { resources: r } = await e.portalItem.fetchResources(), s = r.find((i) => i.resource.path === "embeddings-v01.json");
529
+ if (!s?.resource.url)
378
530
  throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
379
- const r = await ie(n.resource.url);
380
- return se(r);
531
+ const t = await Ae(s.resource.url);
532
+ return Se(t);
381
533
  };
382
- class v {
534
+ class k {
383
535
  constructor() {
384
- this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.threadId = "", this.agentRegistry = new X(), this.streamEpoch = 0;
536
+ this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.sharedResources = [], this.agentRegistry = new S(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.parentRunIds = /* @__PURE__ */ new Map(), this.activeRuntimeSpans = /* @__PURE__ */ new Map(), this.runtimeEventsEnabled = !1, this.streamEpoch = 0;
385
537
  }
386
538
  /**
387
539
  * Creates and returns an AI-ready Orchestrator instance.
@@ -389,21 +541,22 @@ class v {
389
541
  * @returns Ready Orchestrator.
390
542
  */
391
543
  static async init(e) {
392
- const s = new v();
544
+ const r = new k();
545
+ r.runtimeEventsEnabled = e.runtimeEventsEnabled ?? !1;
393
546
  try {
394
547
  if (e.view?.map) {
395
- await P.whenOnce(() => e.view.ready);
396
- const n = await oe(e.view), r = ae(
397
- n.layers,
548
+ await N.whenOnce(() => e.view.ready);
549
+ const s = await Ce(e.view), t = be(
550
+ s.layers,
398
551
  e.view.map
399
552
  );
400
- s.layersAndFieldsRegistry = r, s.embeddingsWorker = await O(n);
553
+ r.layersAndFieldsRegistry = t, r.embeddingsWorker = await B(s);
401
554
  }
402
- return e.agents?.forEach((n) => {
403
- s.agentRegistry.register(n);
404
- }), s.orchestratorReady = !0, s;
405
- } catch (n) {
406
- throw console.error("Orchestrator initialization failed:", n), n;
555
+ return e.agents?.forEach((s) => {
556
+ r.agentRegistry.register(s);
557
+ }), r.orchestratorReady = !0, r;
558
+ } catch (s) {
559
+ throw console.error("Orchestrator initialization failed:", s), s;
407
560
  }
408
561
  }
409
562
  /**
@@ -413,77 +566,105 @@ class v {
413
566
  * - `interrupt`: HITL required, wait for `resumeInterrupt()`
414
567
  * - `completed`: final result with chat history + layer styling
415
568
  * - `cancelled`: user aborted the run
569
+ * @param userInput User request to process.
570
+ * @param options Agent selection and routing behavior for this run.
416
571
  */
417
- async *ask(e) {
572
+ async *ask(e, r = {}) {
418
573
  if (!this.orchestratorReady)
419
574
  throw new Error("Orchestrator is not ready yet.");
420
575
  if (!this.agentRegistry.list().length)
421
576
  throw new Error("Orchestrator has no registered agents.");
577
+ const s = this.createRequestAgentRegistry(r);
578
+ if (!s.list().length)
579
+ throw new Error("Orchestrator has no agents selected for this request.");
422
580
  if (++this.streamEpoch, !e.trim())
423
581
  return;
424
- this.threadId = String(Date.now()), this.graph || (this.graph = K().compile({ checkpointer: new $() }));
425
- const s = this.embeddingsWorker ? te({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? ne({ worker: this.embeddingsWorker }) : void 0, r = /* @__PURE__ */ new Map(), a = {
582
+ const t = A();
583
+ this.parentRunIds.clear(), this.activeRuntimeSpans.clear(), this.activeRunId = t, this.activeAbortController = new AbortController(), this.graph || (this.graph = le().compile({ checkpointer: new P() }));
584
+ const a = this.embeddingsWorker ? Ee({ worker: this.embeddingsWorker }) : void 0, i = this.embeddingsWorker ? xe({ worker: this.embeddingsWorker }) : void 0, o = /* @__PURE__ */ new Map(), d = r.routing === "direct" ? { mode: "direct", agentId: r.agentId } : { mode: "auto" }, c = {
585
+ // eslint-disable-next-line @typescript-eslint/naming-convention
586
+ thread_id: t,
587
+ hitlResponse: null,
588
+ services: {
589
+ layerSearch: a,
590
+ fieldSearch: i,
591
+ layersAndFieldsRegistry: this.layersAndFieldsRegistry,
592
+ agentRegistry: s,
593
+ embeddingCache: o
594
+ }
595
+ }, u = {
426
596
  version: "v2",
427
597
  streamMode: "custom",
428
- configurable: {
429
- // eslint-disable-next-line @typescript-eslint/naming-convention
430
- thread_id: this.threadId,
431
- hitlResponse: null,
432
- services: {
433
- layerSearch: s,
434
- fieldSearch: n,
435
- layersAndFieldsRegistry: this.layersAndFieldsRegistry,
436
- agentRegistry: this.agentRegistry,
437
- embeddingCache: r
438
- }
439
- },
598
+ signal: this.activeAbortController.signal,
599
+ ...this.runtimeEventsEnabled && { callbacks: [this.createHierarchyCallback()] },
600
+ configurable: c,
440
601
  subgraphs: !0
441
- }, c = this.graph?.streamEvents(
602
+ }, g = this.graph?.streamEvents(
442
603
  {
604
+ routing: d,
443
605
  agentExecutionContext: {
444
606
  userRequest: e,
445
607
  messages: this.chatHistory,
446
608
  priorSteps: this.priorSteps,
447
- sharedState: this.sharedState
609
+ sharedState: this.sharedState,
610
+ sharedResources: this.sharedResources
448
611
  }
449
612
  },
450
- a
451
- ), d = ++this.streamEpoch;
452
- for (yield* this.pipeStream(c, d); ; ) {
453
- const m = (await this.graph.getState(a, { subgraphs: !0 })).tasks.find((h) => h.interrupts.length > 0)?.interrupts[0]?.value;
613
+ u
614
+ ), l = ++this.streamEpoch;
615
+ if (yield* this.pipeStream(g, l, t), this.isRunCancelled(t)) {
616
+ yield* this.createCancellationEvents(t);
617
+ return;
618
+ }
619
+ for (; ; ) {
620
+ if (this.isRunCancelled(t)) {
621
+ yield* this.createCancellationEvents(t);
622
+ return;
623
+ }
624
+ const m = (await this.graph.getState(u, { subgraphs: !0 })).tasks.find((y) => y.interrupts.length > 0)?.interrupts[0]?.value;
454
625
  if (!m)
455
626
  break;
456
- this.currentInterrupt = m, this.interruptHandler = new Y(this.graph, a), yield { runId: this.threadId, timestamp: Date.now(), type: "interrupt", interrupt: m };
627
+ this.currentInterrupt = m, this.interruptHandler = new fe(this.graph, u), yield* this.closeActiveRuntimeSpans(t, "interrupted"), yield { runId: t, timestamp: Date.now(), type: "interrupt", interrupt: m };
457
628
  try {
458
- const h = await this.interruptHandler.waitForUser(), x = ++this.streamEpoch;
459
- yield* this.pipeStream(h, x);
460
- } catch (h) {
461
- if (h) {
629
+ const y = await this.interruptHandler.waitForUser(), I = ++this.streamEpoch;
630
+ yield* this.pipeStream(y, I, t);
631
+ } catch (y) {
632
+ if (this.isRunCancelled(t)) {
633
+ yield* this.createCancellationEvents(t);
634
+ return;
635
+ }
636
+ if (y) {
462
637
  yield {
463
- runId: this.threadId,
638
+ runId: t,
464
639
  timestamp: Date.now(),
465
640
  type: "error",
466
- error: { message: h?.message }
641
+ error: { message: y?.message }
467
642
  };
468
643
  return;
469
644
  }
470
- yield { runId: this.threadId, timestamp: Date.now(), type: "cancelled" };
471
- return;
472
645
  }
473
646
  }
474
- const g = (await this.graph.getState(a, { subgraphs: !0 })).values;
475
- this.chatHistory = g.agentExecutionContext.messages.length ? g.agentExecutionContext.messages : this.chatHistory, this.priorSteps = g.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = g.agentExecutionContext.sharedState ?? {}, yield {
476
- runId: this.threadId,
647
+ if (this.isRunCancelled(t)) {
648
+ yield* this.createCancellationEvents(t);
649
+ return;
650
+ }
651
+ const h = (await this.graph.getState(u, { subgraphs: !0 })).values;
652
+ if (this.isRunCancelled(t)) {
653
+ yield* this.createCancellationEvents(t);
654
+ return;
655
+ }
656
+ this.chatHistory = h.agentExecutionContext.messages.length ? h.agentExecutionContext.messages : this.chatHistory, this.priorSteps = h.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = h.agentExecutionContext.sharedState ?? {}, this.sharedResources = h.agentExecutionContext.sharedResources ?? [], yield {
657
+ runId: t,
477
658
  timestamp: Date.now(),
478
659
  type: "completed",
479
- result: { content: g.finalOutputMessage }
660
+ result: { content: h.finalOutputMessage }
480
661
  };
481
662
  }
482
663
  /**
483
664
  * Start a new conversation by clearing chat history, prior steps, and shared state.
484
665
  */
485
666
  newConversation() {
486
- this.chatHistory = [], this.priorSteps = [], this.sharedState = {};
667
+ this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.sharedResources = [];
487
668
  }
488
669
  /**
489
670
  * Generic resume for any HITL interrupt.
@@ -500,29 +681,98 @@ class v {
500
681
  cancelInterrupt() {
501
682
  this.interruptHandler && this.interruptHandler.cancel();
502
683
  }
503
- async *pipeStream(e, s) {
504
- for await (const n of e) {
505
- if (s !== this.streamEpoch) {
506
- console.log("Stale stream detected, aborting.");
507
- break;
684
+ /**
685
+ * Cancels the active run.
686
+ *
687
+ * - Aborts in-flight work for consumers that honor AbortSignal.
688
+ * - Invalidates active stream iterators via epoch bump.
689
+ * - Unblocks any pending HITL wait.
690
+ */
691
+ cancel() {
692
+ this.activeRunId && (this.cancelledRunIds.add(this.activeRunId), this.activeAbortController?.abort(), ++this.streamEpoch, this.interruptHandler?.cancel());
693
+ }
694
+ async *pipeStream(e, r, s) {
695
+ try {
696
+ for await (const t of e) {
697
+ if (this.isRunCancelled(s) || r !== this.streamEpoch)
698
+ break;
699
+ if (this.runtimeEventsEnabled) {
700
+ const a = ye({
701
+ event: t,
702
+ runId: s,
703
+ parentSpanId: this.parentRunIds.get(t.run_id),
704
+ timestamp: Date.now()
705
+ });
706
+ a && (a.phase === "started" ? this.activeRuntimeSpans.set(a.span.id, a) : this.activeRuntimeSpans.delete(a.span.id), yield a);
707
+ }
708
+ t.event === "on_custom_event" && t.name === "trace_message" ? yield { runId: s, timestamp: Date.now(), type: "trace", data: t.data } : t.name === "graph_ux_suggestion" && (yield {
709
+ runId: s,
710
+ timestamp: Date.now(),
711
+ type: "ux-suggestion",
712
+ suggestion: t.data
713
+ });
508
714
  }
509
- n.event === "on_custom_event" && n.name === "trace_message" ? yield { runId: this.threadId, timestamp: Date.now(), type: "trace", data: n.data } : n.name === "graph_ux_suggestion" && (yield {
510
- runId: this.threadId,
511
- timestamp: Date.now(),
512
- type: "ux-suggestion",
513
- suggestion: n.data
514
- });
715
+ } catch (t) {
716
+ if (!this.isRunCancelled(s))
717
+ throw t;
515
718
  }
516
719
  }
720
+ *createCancellationEvents(e) {
721
+ yield* this.closeActiveRuntimeSpans(e, "cancelled"), yield { runId: e, timestamp: Date.now(), type: "cancelled", reason: "user" };
722
+ }
723
+ *closeActiveRuntimeSpans(e, r) {
724
+ const s = Date.now(), t = [...this.activeRuntimeSpans.values()].reverse();
725
+ this.activeRuntimeSpans.clear();
726
+ for (const a of t) {
727
+ const { input: i, ...o } = a.span;
728
+ yield {
729
+ type: "runtime",
730
+ phase: r,
731
+ runId: e,
732
+ timestamp: s,
733
+ ...a.agentId && { agentId: a.agentId },
734
+ span: o
735
+ };
736
+ }
737
+ }
738
+ // v2 stream events omit parent run IDs, so capture them through callbacks to preserve the normalized span hierarchy.
739
+ createHierarchyCallback() {
740
+ const e = (r, s) => {
741
+ s && this.parentRunIds.set(r, s);
742
+ };
743
+ return G.fromMethods({
744
+ handleLLMStart: (r, s, t, a) => e(t, a),
745
+ handleChatModelStart: (r, s, t, a) => e(t, a),
746
+ handleChainStart: (r, s, t, a) => e(t, a),
747
+ handleToolStart: (r, s, t, a) => e(t, a),
748
+ handleRetrieverStart: (r, s, t, a) => e(t, a)
749
+ });
750
+ }
751
+ isRunCancelled(e) {
752
+ return this.cancelledRunIds.has(e);
753
+ }
754
+ /**
755
+ * Creates a request-scoped registry containing all agents by default,
756
+ * or only the explicitly selected agents when filtering is requested.
757
+ */
758
+ createRequestAgentRegistry(e) {
759
+ const r = e.routing === "direct" ? [e.agentId] : e.agentIds, s = r ? r.map((a) => {
760
+ const i = this.agentRegistry.get(a);
761
+ if (!i)
762
+ throw new Error(`Agent is not registered: ${a}`);
763
+ return i;
764
+ }) : this.agentRegistry.list(), t = new S();
765
+ return s.forEach((a) => t.register(a)), t;
766
+ }
517
767
  /**
518
768
  * Disposes this instance by terminating the embeddings worker
519
769
  * and cleaning up all related resources.
520
770
  */
521
771
  dispose() {
522
- this.embeddingsWorker && (this.embeddingsWorker.terminate(), this.embeddingsWorker = void 0), this.orchestratorReady = !1;
772
+ this.sharedResources = [], this.embeddingsWorker && (this.embeddingsWorker.terminate(), this.embeddingsWorker = void 0), this.orchestratorReady = !1;
523
773
  }
524
774
  }
525
775
  export {
526
- v as O,
527
- Z as g
776
+ k as O,
777
+ we as g
528
778
  };