@arcgis/ai-components 5.2.0-next.9 → 5.2.0-next.91

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 (315) 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 +4 -2
  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 +109 -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 +52 -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 +154 -0
  60. package/dist/agents/tools/query/getTopFeatures/adapter.d.ts +8 -0
  61. package/dist/agents/tools/query/getTopFeatures/adapter.js +141 -0
  62. package/dist/agents/tools/query/queryFeatures/adapter.d.ts +8 -0
  63. package/dist/agents/tools/query/queryFeatures/adapter.js +127 -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/2EY3BQQX.js +2 -0
  69. package/dist/cdn/2PTPBAIN.js +2 -0
  70. package/dist/cdn/34O57OGV.js +2 -0
  71. package/dist/cdn/{AMP6IALT.js → 3UEKINYC.js} +1 -1
  72. package/dist/cdn/434TAA3J.js +2 -0
  73. package/dist/cdn/4EBLRHYE.js +2 -0
  74. package/dist/cdn/4HDDRBIY.js +2 -0
  75. package/dist/cdn/4KOV2NEI.js +9 -0
  76. package/dist/cdn/4NJ2FF7H.js +2 -0
  77. package/dist/cdn/4OGR5QKS.js +2 -0
  78. package/dist/cdn/4WIDLQUH.js +2 -0
  79. package/dist/cdn/5FL5BTTX.js +66 -0
  80. package/dist/cdn/5WYRJMBW.js +2 -0
  81. package/dist/cdn/5X7EG7D2.js +2 -0
  82. package/dist/cdn/5ZFUGNRN.js +2 -0
  83. package/dist/cdn/6HF36IKA.js +2 -0
  84. package/dist/cdn/6KFMRBAA.js +2 -0
  85. package/dist/cdn/6VJXUIXY.js +3 -0
  86. package/dist/cdn/7BCQMK6D.js +2 -0
  87. package/dist/cdn/7DFXYMEA.js +2 -0
  88. package/dist/cdn/7M6VKBTK.js +6 -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/7ZFAFKJT.js +2 -0
  93. package/dist/cdn/ACJTJLZN.js +2 -0
  94. package/dist/cdn/AI6DYOKR.js +181 -0
  95. package/dist/cdn/{ZS2TZ6BF.js → AOVJ34QE.js} +1 -1
  96. package/dist/cdn/APFZY4PI.js +2 -0
  97. package/dist/cdn/AT4XVTJR.js +44 -0
  98. package/dist/cdn/AZCIDPML.js +2 -0
  99. package/dist/cdn/{FL4W4VYN.js → BL273EGZ.js} +17 -1
  100. package/dist/cdn/C5ZL5Z52.js +18 -0
  101. package/dist/cdn/CCC6LBMY.js +2 -0
  102. package/dist/cdn/{5ZZGKP7N.js → CEKOEHB3.js} +1 -1
  103. package/dist/cdn/CJMUJXPL.js +2 -0
  104. package/dist/cdn/COL6QYGQ.js +2 -0
  105. package/dist/cdn/CP5BVGJU.js +2 -0
  106. package/dist/cdn/CZM4URK7.js +2 -0
  107. package/dist/cdn/DP6O6PMH.js +2 -0
  108. package/dist/cdn/{V2P4AIGG.js → EKB7CAMM.js} +1 -1
  109. package/dist/cdn/EWLXNGKH.js +208 -0
  110. package/dist/cdn/EYNEYD34.js +2 -0
  111. package/dist/cdn/FDDQ67BG.js +2 -0
  112. package/dist/cdn/FDOMMK2M.js +2 -0
  113. package/dist/cdn/FQH3HOFH.js +2 -0
  114. package/dist/cdn/{GGSZM7KV.js → FUZ77UGP.js} +6 -4
  115. package/dist/cdn/{ZLXN7NMF.js → FYZATVB3.js} +10 -8
  116. package/dist/cdn/GFEOVHJK.js +2 -0
  117. package/dist/cdn/HHFNQR6Z.js +2 -0
  118. package/dist/cdn/HIPQ3VRW.js +2 -0
  119. package/dist/cdn/HKSFWTWK.js +14 -0
  120. package/dist/cdn/HMUWQCXU.js +2 -0
  121. package/dist/cdn/IBZ2NEAO.js +2 -0
  122. package/dist/cdn/{FX7UOGHP.js → ICBIUFK7.js} +1 -1
  123. package/dist/cdn/IHP25JWI.js +99 -0
  124. package/dist/cdn/J6A4AS7E.js +22 -0
  125. package/dist/cdn/J6SZIQJA.js +2 -0
  126. package/dist/cdn/{NE7E52YR.js → JEBRN3EU.js} +9 -3
  127. package/dist/cdn/JJJZ7FOM.js +2 -0
  128. package/dist/cdn/JKIESH74.js +2 -0
  129. package/dist/cdn/JO5ETMPS.js +2 -0
  130. package/dist/cdn/K2R6XVK3.js +2 -0
  131. package/dist/cdn/KCU4FWF7.js +2 -0
  132. package/dist/cdn/KITIP6J2.js +2 -0
  133. package/dist/cdn/KWD2ECTM.js +2 -0
  134. package/dist/cdn/{7RCQFLPP.js → LK7ZIQW6.js} +1 -1
  135. package/dist/cdn/LLUGJKAQ.js +2 -0
  136. package/dist/cdn/LPR72QZF.js +36 -0
  137. package/dist/cdn/{DHOVCT6R.js → MKOQJXQQ.js} +1 -1
  138. package/dist/cdn/MWYBF3F3.js +66 -0
  139. package/dist/cdn/NEV6OZN3.js +71 -0
  140. package/dist/cdn/OAKRPM7D.js +2 -0
  141. package/dist/cdn/{23EQTPO3.js → OKVLGJAG.js} +1 -1
  142. package/dist/cdn/OL5656NI.js +2 -0
  143. package/dist/cdn/ONQ6JSBJ.js +2 -0
  144. package/dist/cdn/OWTGH34K.js +2 -0
  145. package/dist/cdn/OYSPNIJI.js +156 -0
  146. package/dist/cdn/PEYYWXFE.js +2 -0
  147. package/dist/cdn/PKUDO2RC.js +3 -0
  148. package/dist/cdn/{LQ6R5YRN.js → PQ2DPOFM.js} +1 -1
  149. package/dist/cdn/PSYRZMX2.js +2 -0
  150. package/dist/cdn/PUHRBGKB.js +2 -0
  151. package/dist/cdn/Q57QWN5W.js +2 -0
  152. package/dist/cdn/QCFICJ7U.js +3 -0
  153. package/dist/cdn/QNNGPA3Q.js +2 -0
  154. package/dist/cdn/R74ZHFA6.js +2 -0
  155. package/dist/cdn/RBE55SWR.js +2 -0
  156. package/dist/cdn/RHYNE5OE.js +2 -0
  157. package/dist/cdn/RLEHNAIA.js +2 -0
  158. package/dist/cdn/RSNGZQCQ.js +2 -0
  159. package/dist/cdn/{X2ZDYHCG.js → SDWWUWAF.js} +10 -5
  160. package/dist/cdn/SHD6YFSR.js +2 -0
  161. package/dist/cdn/SUYWKYWI.js +22 -0
  162. package/dist/cdn/SZ2QSSB3.js +2 -0
  163. package/dist/cdn/T4RIGOXB.js +2 -0
  164. package/dist/cdn/{3PKJWIC3.js → TMZ6DF22.js} +1 -1
  165. package/dist/cdn/TPULIO6I.js +34 -0
  166. package/dist/cdn/U2D53TAX.js +14 -0
  167. package/dist/cdn/{6YMR4QSD.js → UHEYPSOR.js} +1 -1
  168. package/dist/cdn/UHZG7SKO.js +2 -0
  169. package/dist/cdn/UZLQALHY.js +2 -0
  170. package/dist/cdn/V52XWEGV.js +11 -0
  171. package/dist/cdn/V6F3HEK7.js +2 -0
  172. package/dist/cdn/V6HOUZPZ.js +2 -0
  173. package/dist/cdn/VAXH6RUQ.js +134 -0
  174. package/dist/cdn/VLLZ2FFU.js +2 -0
  175. package/dist/cdn/VNJMTA6O.js +2 -0
  176. package/dist/cdn/VOKXKU7M.js +56 -0
  177. package/dist/cdn/VXFQANGJ.js +2 -0
  178. package/dist/cdn/W5JPJWMM.js +2 -0
  179. package/dist/cdn/WKTQVBFJ.js +2 -0
  180. package/dist/cdn/WNNMKCKS.js +2 -0
  181. package/dist/cdn/WP7ORLSB.js +6 -0
  182. package/dist/cdn/WR2SQX3J.js +2 -0
  183. package/dist/cdn/X3COUAXY.js +4 -0
  184. package/dist/cdn/Y7XD7ZRD.js +2 -0
  185. package/dist/cdn/YEZ3AMNX.js +2 -0
  186. package/dist/cdn/YLVJA4ZE.js +2 -0
  187. package/dist/cdn/YQSU6IUO.js +2 -0
  188. package/dist/cdn/Z5W4V7RC.js +2 -0
  189. package/dist/cdn/ZLWWWTH4.js +2 -0
  190. package/dist/cdn/ZOEMBHRF.js +2 -0
  191. package/dist/cdn/ZQMBJ6MI.js +2 -0
  192. package/dist/cdn/{ZTBA5PM7.js → ZU2FHVNK.js} +1 -1
  193. package/dist/cdn/ZVGUAOXE.js +2 -0
  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/chunks/adapter.js +1299 -2113
  205. package/dist/chunks/arcgisKnowledgeGraph.js +128 -72
  206. package/dist/chunks/arcgis_knowledge_current_lc_context.js +19 -2
  207. package/dist/chunks/arcgis_knowledge_current_map_context.js +31 -2
  208. package/dist/chunks/arcgis_knowledge_cypher_query_prompt.js +102 -0
  209. package/dist/chunks/arcgis_knowledge_summarize_result_prompt.js +116 -27
  210. package/dist/chunks/baseAgentState.js +56 -0
  211. package/dist/chunks/converterUtils.js +66 -41
  212. package/dist/chunks/dataExplorationGraph.js +133 -177
  213. package/dist/chunks/data_explore_query_prompt.js +9 -4
  214. package/dist/chunks/fetchAgentContext.js +13 -0
  215. package/dist/chunks/fetchService.js +10 -0
  216. package/dist/chunks/fieldStatistics.js +79 -0
  217. package/dist/chunks/formatFeatureAttributes.js +132 -0
  218. package/dist/chunks/generateLayerDescriptions.js +259 -282
  219. package/dist/chunks/helpGraph.js +35 -25
  220. package/dist/chunks/help_prompt.js +34 -17
  221. package/dist/chunks/index.js +11 -0
  222. package/dist/chunks/intent_prompt.js +16 -0
  223. package/dist/chunks/layerStylingGraph.js +37 -31
  224. package/dist/chunks/mergeWhereClauses.js +15 -0
  225. package/dist/chunks/navigationGraph.js +124 -103
  226. package/dist/chunks/navigation_intent_prompt.js +8 -2
  227. package/dist/chunks/orchestrator.js +298 -139
  228. package/dist/chunks/slottableRequestUtils.js +3 -7
  229. package/dist/chunks/state.js +21 -27
  230. package/dist/chunks/summarize_query_response_prompt.js +9 -7
  231. package/dist/chunks/toolCallResponse.js +14 -10
  232. package/dist/chunks/types.js +59 -0
  233. package/dist/chunks/utils2.js +11 -11
  234. package/dist/components/arcgis-assistant/customElement.d.ts +72 -0
  235. package/dist/components/arcgis-assistant/customElement.js +416 -172
  236. package/dist/components/arcgis-assistant/index.js +2 -3
  237. package/dist/components/arcgis-assistant/types.d.ts +14 -1
  238. package/dist/components/arcgis-assistant-agent/customElement.d.ts +13 -1
  239. package/dist/components/arcgis-assistant-agent/customElement.js +614 -10
  240. package/dist/components/arcgis-assistant-chat/customElement.d.ts +2 -1
  241. package/dist/components/arcgis-assistant-chat/customElement.js +23 -18
  242. package/dist/components/arcgis-assistant-chat-entry/customElement.d.ts +2 -0
  243. package/dist/components/arcgis-assistant-chat-entry/customElement.js +25 -18
  244. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +20 -4
  245. package/dist/components/arcgis-assistant-help-agent/customElement.js +29 -7
  246. package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +4 -0
  247. package/dist/components/arcgis-assistant-interrupt/customElement.js +17 -14
  248. package/dist/components/arcgis-assistant-interrupt-preview/customElement.js +24 -0
  249. package/dist/components/arcgis-assistant-interrupt-preview/index.js +2 -0
  250. package/dist/components/arcgis-assistant-knowledge-agent/customElement.d.ts +7 -7
  251. package/dist/components/arcgis-assistant-knowledge-agent/customElement.js +40 -16
  252. package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +30 -7
  253. package/dist/components/arcgis-assistant-message/customElement.d.ts +5 -0
  254. package/dist/components/arcgis-assistant-message/customElement.js +29 -26
  255. package/dist/components/arcgis-assistant-message/index.js +2 -0
  256. package/dist/components/arcgis-assistant-message-block/customElement.js +18 -11
  257. package/dist/components/arcgis-assistant-message-block/index.js +1 -0
  258. package/dist/components/arcgis-assistant-message-loading/customElement.d.ts +7 -0
  259. package/dist/components/arcgis-assistant-message-loading/customElement.js +8 -7
  260. package/dist/components/arcgis-assistant-message-loading/index.js +1 -0
  261. package/dist/components/arcgis-assistant-message-text/customElement.d.ts +1 -0
  262. package/dist/components/arcgis-assistant-message-text/customElement.js +12 -12
  263. package/dist/components/arcgis-assistant-navigation-agent/customElement.js +18 -4
  264. package/dist/components/arcgis-assistant-speech-input/customElement.js +34 -52
  265. package/dist/components/arcgis-assistant-suggested-prompts/customElement.js +8 -8
  266. package/dist/components/arcgis-assistant-user-message/customElement.d.ts +2 -0
  267. package/dist/components/arcgis-assistant-user-message/customElement.js +15 -10
  268. package/dist/docs/api.json +1 -1
  269. package/dist/docs/docs.json +1 -1
  270. package/dist/docs/vscode.html-custom-data.json +1 -1
  271. package/dist/docs/web-types.json +1 -1
  272. package/dist/loader.js +9 -8
  273. package/dist/oauth-callback.html +1 -1
  274. package/dist/orchestrator/orchestrator/orchestratorEvents.d.ts +78 -0
  275. package/dist/types/lumina.d.ts +10 -8
  276. package/dist/types/preact.d.ts +10 -8
  277. package/dist/types/react.d.ts +10 -8
  278. package/dist/types/stencil.d.ts +12 -10
  279. package/dist/utils/index.d.ts +8 -8
  280. package/dist/utils/index.js +56 -55
  281. package/package.json +32 -12
  282. package/dist/cdn/2AXF774U.js +0 -2
  283. package/dist/cdn/462JBSEV.js +0 -422
  284. package/dist/cdn/53ZCUPKK.js +0 -22
  285. package/dist/cdn/5QAHYX7Y.js +0 -5
  286. package/dist/cdn/5XRDJL7R.js +0 -14
  287. package/dist/cdn/7BCR6TUO.js +0 -2
  288. package/dist/cdn/7GH7VSB2.js +0 -2
  289. package/dist/cdn/7PLV4QH6.js +0 -2
  290. package/dist/cdn/AXDZBBNL.js +0 -45
  291. package/dist/cdn/DDLZOMUY.js +0 -2
  292. package/dist/cdn/EECZLT6C.js +0 -166
  293. package/dist/cdn/ETRWZ3MS.js +0 -108
  294. package/dist/cdn/F2AHA4GB.js +0 -54
  295. package/dist/cdn/FX5JFRDL.js +0 -2
  296. package/dist/cdn/H7422XUG.js +0 -2
  297. package/dist/cdn/HB5A5R2E.js +0 -2
  298. package/dist/cdn/I6HNBTWY.js +0 -2
  299. package/dist/cdn/I7SRZPVS.js +0 -72
  300. package/dist/cdn/IG6YKZH3.js +0 -3
  301. package/dist/cdn/JVIKKZND.js +0 -3
  302. package/dist/cdn/KMQ3SP4I.js +0 -5
  303. package/dist/cdn/MH5RPXHM.js +0 -2
  304. package/dist/cdn/NVI3I46B.js +0 -2
  305. package/dist/cdn/OAVEHGB6.js +0 -2
  306. package/dist/cdn/OH64RMOR.js +0 -4
  307. package/dist/cdn/P26NON3Z.js +0 -16
  308. package/dist/cdn/QR54T33D.js +0 -2
  309. package/dist/cdn/RVOAPUBN.js +0 -2
  310. package/dist/cdn/S3VPZFWQ.js +0 -36
  311. package/dist/cdn/SXDLXCIM.js +0 -2
  312. package/dist/cdn/TR7RL3IK.js +0 -2
  313. package/dist/cdn/USMDJUFS.js +0 -2
  314. package/dist/cdn/Y333DGV6.js +0 -2
  315. package/dist/cdn/YIMNOUTF.js +0 -2
@@ -1,49 +1,52 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import R from "@arcgis/core/identity/IdentityManager.js";
3
- import C from "@arcgis/core/portal/Portal.js";
4
- import { p as I, q as v, s as l, D as k, r as A, t as M, W as F } from "./generateLayerDescriptions.js";
5
- import { isGraphInterrupt as D, StateGraph as L, START as W, END as $, MemorySaver as j } from "@langchain/langgraph/web";
6
- import { HumanMessage as q, AIMessage as H } from "@langchain/core/messages";
7
- import * as P from "@arcgis/core/core/reactiveUtils.js";
8
- import O from "@arcgis/core/layers/FeatureLayer.js";
9
- import T from "@arcgis/core/request.js";
10
- const U = async (t) => {
11
- const e = await N(), r = await I("default"), s = C.getDefault(), a = (await R.getCredential(`${s.url}/sharing`)).token, i = {
2
+ import A from "@arcgis/core/identity/IdentityManager.js";
3
+ import M from "@arcgis/core/portal/Portal.js";
4
+ import { j as _, k as x, D, n as F, o as L, W as $ } from "./generateLayerDescriptions.js";
5
+ import { isGraphInterrupt as W, StateGraph as q, START as T, END as H, MemorySaver as j } from "@langchain/langgraph/web";
6
+ import { generateGuid as U } from "@arcgis/toolkit/string";
7
+ import { HumanMessage as P, AIMessage as O } from "@langchain/core/messages";
8
+ import { s as m } from "./index.js";
9
+ import { BaseCallbackHandler as N } from "@langchain/core/callbacks/base";
10
+ import * as G 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 (t) => {
14
+ const e = await Q(), r = await _("default"), s = M.getDefault(), a = (await A.getCredential(`${s.url}/sharing`)).token, i = {
12
15
  type: "generateEmbeddings",
13
16
  webmapEmbeddings: t,
14
17
  auth: { apiUrl: r, token: a }
15
18
  };
16
19
  return e.postMessage(i), 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"));
20
+ const o = (g) => {
21
+ g.data === "completed" && (e.removeEventListener("message", o), c());
22
+ }, u = (g) => {
23
+ e.removeEventListener("message", o), 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", o), e.addEventListener("error", u, { once: !0 });
23
26
  }), e;
24
- }, N = async () => {
27
+ }, Q = async () => {
25
28
  {
26
29
  const t = (await import("./embeddings.worker.js")).default;
27
30
  return new t();
28
31
  }
29
- }, G = (t) => {
32
+ }, J = (t) => {
30
33
  t.currentIntent = "none";
31
- }, _ = async (t, e) => {
32
- const r = v(e);
34
+ }, K = async (t, e) => {
35
+ const r = x(e);
33
36
  if (t.agentExecutionContext.userRequest) {
34
- const n = new q(t.agentExecutionContext.userRequest.trim());
35
- t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], G(t);
37
+ const n = new P(t.agentExecutionContext.userRequest.trim());
38
+ t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], J(t);
36
39
  }
37
40
  const s = r?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
38
- return await l({ text: `Available agents: ${[...s].join(", ")}` }, e), await l({ text: "Analyzing user input" }, e), t;
39
- }, V = async (t, e) => (await l({ text: "Exiting..." }, e), t), w = (t) => typeof t == "object" && t !== null && !Array.isArray(t), z = (t, e) => {
40
- if (!w(t)) {
41
+ return await m({ text: `Available agents: ${[...s].join(", ")}` }, e), await m({ text: "Analyzing user input" }, e), t;
42
+ }, X = async (t, e) => (await m({ text: "Exiting..." }, e), t), E = (t) => typeof t == "object" && t !== null && !Array.isArray(t), Y = (t, e) => {
43
+ if (!E(t)) {
41
44
  t !== void 0 && console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`);
42
45
  return;
43
46
  }
44
47
  const r = {};
45
48
  for (const [s, n] of Object.entries(t)) {
46
- if (!w(n) || !("value" in n)) {
49
+ if (!E(n) || !("value" in n)) {
47
50
  console.warn(
48
51
  `Agent "${e}" returned invalid sharedStatePatch entry for key "${s}". Ignoring that entry.`
49
52
  );
@@ -52,7 +55,7 @@ const U = async (t) => {
52
55
  r[s] = { value: n.value };
53
56
  }
54
57
  return r;
55
- }, Q = (t) => {
58
+ }, Z = (t) => {
56
59
  const { previousSharedState: e, patch: r, agentId: s } = t;
57
60
  if (!r)
58
61
  return e;
@@ -68,12 +71,12 @@ const U = async (t) => {
68
71
  }
69
72
  });
70
73
  return a;
71
- }, f = (t) => {
74
+ }, S = (t) => {
72
75
  if (typeof t != "string")
73
76
  return;
74
77
  const e = t.trim();
75
78
  return e || void 0;
76
- }, B = (t) => {
79
+ }, ee = (t) => {
77
80
  switch (t) {
78
81
  case "failed":
79
82
  return "Agent failed without a summary.";
@@ -84,20 +87,20 @@ const U = async (t) => {
84
87
  default:
85
88
  return "Agent completed without a summary.";
86
89
  }
87
- }, J = (t, e) => {
88
- const r = f(e?.outputMessage), s = f(e?.summary), n = e?.status, a = n === "success" || n === "failed" ? n : "unknown";
90
+ }, te = (t, e) => {
91
+ const r = S(e?.outputMessage), s = S(e?.summary), n = e?.status, a = n === "success" || n === "failed" ? n : "unknown";
89
92
  a === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
90
- const i = z(e?.sharedStatePatch, t);
93
+ const i = Y(e?.sharedStatePatch, t);
91
94
  return {
92
95
  outputMessage: r,
93
- summary: s ?? r ?? B(a),
96
+ summary: s ?? r ?? ee(a),
94
97
  status: a,
95
98
  sharedStatePatch: i
96
99
  };
97
- }, E = 4e3, K = async (t, e) => {
98
- const r = v(e);
99
- if (r?.abortSignal?.aborted)
100
- return await l({ text: "Run cancelled; skipping agent execution" }, e), {
100
+ }, b = 4e3, ne = async (t, e) => {
101
+ const r = x(e);
102
+ if (e?.signal?.aborted)
103
+ return await m({ text: "Run cancelled; skipping agent execution" }, e), {
101
104
  ...t,
102
105
  currentIntent: "none",
103
106
  requiresFollowUp: !1
@@ -105,9 +108,13 @@ const U = async (t) => {
105
108
  const { agentRegistry: s } = r?.services ?? {}, n = s?.get(t.currentIntent);
106
109
  if (!n)
107
110
  return console.warn(`No agent found for intent: ${t.currentIntent}`), t;
108
- await l({ text: `Executing registered agent: ${n.agent.name}` }, e);
111
+ await m({ text: `Executing registered agent: ${n.agent.name}` }, e);
109
112
  const a = {
110
113
  ...e ?? {},
114
+ metadata: {
115
+ ...e?.metadata,
116
+ agentId: n.agent.id
117
+ },
111
118
  configurable: {
112
119
  ...r ?? {},
113
120
  agentId: n.agent.id,
@@ -129,22 +136,22 @@ const U = async (t) => {
129
136
  },
130
137
  a
131
138
  );
132
- i = J(n.agent.name, o), await l({ text: `Finished executing registered agent: ${n.agent.name}` }, e);
139
+ i = te(n.agent.name, o), await m({ text: `Finished executing registered agent: ${n.agent.name}` }, e);
133
140
  } catch (o) {
134
- if (D(o))
141
+ if (W(o) || e?.signal?.aborted || o instanceof Error && o.name === "AbortError")
135
142
  throw o;
136
- const g = o instanceof Error ? o.message : String(o);
137
- console.error(`Agent "${n.agent.name}" failed:`, o), await l({ text: `Registered agent failed: ${n.agent.name}. ${g}` }, e), i = {
143
+ const u = o instanceof Error ? o.message : String(o);
144
+ console.error(`Agent "${n.agent.name}" failed:`, o), await m({ text: `Registered agent failed: ${n.agent.name}. ${u}` }, e), i = {
138
145
  status: "failed",
139
- outputMessage: `Agent execution failed: ${g}`,
140
- summary: `Agent execution failed: ${g}`
146
+ outputMessage: `Agent execution failed: ${u}`,
147
+ summary: `Agent execution failed: ${u}`
141
148
  };
142
149
  }
143
150
  const c = i.outputMessage, d = [...t.agentExecutionContext.messages];
144
151
  if (c) {
145
- const o = c.length > E ? `${c.slice(0, E - 14)}
152
+ const o = c.length > b ? `${c.slice(0, b - 14)}
146
153
  [truncated]` : c;
147
- d.push(new H(o));
154
+ d.push(new O(o));
148
155
  }
149
156
  return {
150
157
  ...t,
@@ -164,18 +171,104 @@ const U = async (t) => {
164
171
  status: i?.status || "unknown"
165
172
  }
166
173
  ],
167
- sharedState: Q({
174
+ sharedState: Z({
168
175
  previousSharedState: t.agentExecutionContext.sharedState,
169
176
  patch: i.sharedStatePatch,
170
177
  agentId: n.agent.id
171
178
  })
172
179
  }
173
180
  };
174
- }, X = 3, Y = () => new L(k).addNode("ingestInput", _).addNode("intentLLM", A).addNode("executeRegisteredAgent", K).addNode("exit", V).addEdge(W, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges(
175
- "executeRegisteredAgent",
176
- (e) => e.stepCount >= X || !e.requiresFollowUp ? "exit" : "intentLLM"
177
- ).addEdge("exit", $);
178
- class Z {
181
+ }, re = async (t, e) => {
182
+ if (t.routing.mode !== "direct")
183
+ throw new Error("Direct agent assignment requires direct routing.");
184
+ return await m({ text: `Doing a direct route to agent: ${t.routing.agentId}` }, e), {
185
+ ...t,
186
+ currentIntent: t.routing.agentId,
187
+ requiresFollowUp: !1,
188
+ agentExecutionContext: {
189
+ ...t.agentExecutionContext,
190
+ assignedTask: t.agentExecutionContext.userRequest
191
+ }
192
+ };
193
+ }, se = 3, ae = (t) => t.routing.mode === "direct" ? "assignDirectAgent" : "intentLLM", ie = (t) => t.routing.mode === "direct" || t.stepCount >= se || !t.requiresFollowUp ? "exit" : "intentLLM", oe = () => new q(D).addNode("ingestInput", K).addNode("assignDirectAgent", re).addNode("intentLLM", F).addNode("executeRegisteredAgent", ne).addNode("exit", X).addEdge(T, "ingestInput").addConditionalEdges("ingestInput", ae).addEdge("assignDirectAgent", "executeRegisteredAgent").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges("executeRegisteredAgent", ie).addEdge("exit", H), ce = (t, e) => {
194
+ const r = t.output?.usage_metadata ?? e.usage_metadata, s = t.output?.llmOutput?.tokenUsage, n = r?.input_tokens ?? s?.promptTokens, a = r?.output_tokens ?? s?.completionTokens, i = r?.total_tokens ?? s?.totalTokens;
195
+ if (n === void 0 || a === void 0 || i === void 0)
196
+ return;
197
+ const c = r?.input_token_details?.cache_read, d = r?.output_token_details?.reasoning;
198
+ return {
199
+ input: n,
200
+ output: a,
201
+ total: i,
202
+ ...c !== void 0 && { cacheRead: c },
203
+ ...d !== void 0 && { reasoning: d }
204
+ };
205
+ }, de = (t, e, r, s) => {
206
+ switch (t) {
207
+ case "chat_model":
208
+ case "llm":
209
+ return "model";
210
+ case "tool":
211
+ case "retriever":
212
+ return t;
213
+ case "chain":
214
+ return !s || e === "LangGraph" ? "workflow" : r === e ? "node" : "chain";
215
+ default:
216
+ return;
217
+ }
218
+ }, ue = (t) => {
219
+ if (t instanceof Error)
220
+ return { message: t.message, name: t.name };
221
+ const e = t, r = typeof e?.message == "string" ? e.message : String(t ?? "Unknown runtime error"), s = typeof e?.name == "string" ? e.name : void 0;
222
+ return { message: r, ...s && { name: s } };
223
+ }, ge = ({
224
+ event: t,
225
+ runId: e,
226
+ parentSpanId: r,
227
+ timestamp: s
228
+ }) => {
229
+ const n = /^on_(.+)_(start|end|error)$/u.exec(t.event);
230
+ if (!n)
231
+ return;
232
+ const [, a, i] = n, c = t.metadata ?? {}, d = c.langgraph_node, o = de(a, t.name, d, r);
233
+ if (!o)
234
+ return;
235
+ const u = c.agentId, g = c.model ?? c.ls_model_name, l = t.data, y = i === "end" && o === "model" ? ce(l, c) : void 0, h = t.tags?.includes("langsmith:hidden") || d === "__start__", v = {
236
+ ...g && { model: g },
237
+ ...y && { tokenUsage: y },
238
+ ...h && { internal: !0 }
239
+ }, w = {
240
+ id: t.run_id,
241
+ ...r && { parentId: r },
242
+ label: t.name,
243
+ type: o,
244
+ ...Object.keys(v).length && { metadata: v }
245
+ }, p = { runId: e, timestamp: s, type: "runtime", ...u && { agentId: u } };
246
+ switch (i) {
247
+ case "start":
248
+ return {
249
+ ...p,
250
+ phase: "started",
251
+ span: {
252
+ ...w,
253
+ ...l?.input !== void 0 && { input: l.input }
254
+ }
255
+ };
256
+ case "end":
257
+ return {
258
+ ...p,
259
+ phase: "completed",
260
+ span: {
261
+ ...w,
262
+ ...l?.output !== void 0 && { output: l.output }
263
+ }
264
+ };
265
+ case "error":
266
+ return { ...p, phase: "failed", span: { ...w, error: ue(l?.error) } };
267
+ default:
268
+ return;
269
+ }
270
+ };
271
+ class R {
179
272
  constructor() {
180
273
  this.agentRegistry = /* @__PURE__ */ new Map();
181
274
  }
@@ -192,7 +285,7 @@ class Z {
192
285
  return [...this.agentRegistry.values()];
193
286
  }
194
287
  }
195
- class ee {
288
+ class le {
196
289
  /**
197
290
  * Create a new InterruptHandler tied to a specific compiled graph and config.
198
291
  */
@@ -239,23 +332,23 @@ class ee {
239
332
  this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
240
333
  }
241
334
  }
242
- const te = async (t) => {
335
+ const he = async (t) => {
243
336
  try {
244
- return await (await M()).embedDocuments(t);
337
+ return await (await L()).embedDocuments(t);
245
338
  } catch (e) {
246
339
  throw console.error("Failed to generate embeddings:", e), e;
247
340
  }
248
- }, b = async (t, e) => {
341
+ }, C = async (t, e) => {
249
342
  const r = e.get(t);
250
343
  if (r)
251
344
  return r;
252
- const s = await te([t]);
345
+ const s = await he([t]);
253
346
  return e.set(t, s[0]), s[0];
254
347
  };
255
- async function re(t, e, r, s) {
348
+ async function me(t, e, r, s) {
256
349
  const n = `req-${Date.now()}`, i = {
257
350
  type: "layerSearch",
258
- precomputedEmbedding: s ? await b(t, s) : void 0,
351
+ precomputedEmbedding: s ? await C(t, s) : void 0,
259
352
  requestId: n,
260
353
  minScore: r
261
354
  };
@@ -266,7 +359,7 @@ async function re(t, e, r, s) {
266
359
  e.addEventListener("message", d, { once: !0 }), e.postMessage(i);
267
360
  });
268
361
  }
269
- function ne(t) {
362
+ function pe(t) {
270
363
  const { worker: e } = t;
271
364
  return {
272
365
  async searchLayers({
@@ -274,11 +367,11 @@ function ne(t) {
274
367
  minScore: s,
275
368
  embeddingCache: n
276
369
  }) {
277
- return await re(r, e, s, n);
370
+ return await me(r, e, s, n);
278
371
  }
279
372
  };
280
373
  }
281
- const se = async ({
374
+ const fe = async ({
282
375
  combinedQuery: t,
283
376
  layerIds: e,
284
377
  embeddingsWorker: r,
@@ -286,7 +379,7 @@ const se = async ({
286
379
  topResults: n,
287
380
  embeddingCache: a
288
381
  }) => {
289
- const i = `req-${Date.now()}`, c = a ? await b(t, a) : void 0, d = {
382
+ const i = `req-${Date.now()}`, c = a ? await C(t, a) : void 0, d = {
290
383
  type: "fieldSearch",
291
384
  layerIdForFieldsSearch: e,
292
385
  precomputedEmbedding: c,
@@ -295,23 +388,23 @@ const se = async ({
295
388
  topResults: n
296
389
  };
297
390
  return await new Promise((o) => {
298
- const g = (u) => {
299
- if (u.data.requestId !== i)
391
+ const u = (g) => {
392
+ if (g.data.requestId !== i)
300
393
  return;
301
- const p = u.data.results.map(({ layerId: y, results: m }) => ({
394
+ const l = g.data.results.map(({ layerId: y, results: h }) => ({
302
395
  layerId: y,
303
- results: m
396
+ results: h
304
397
  }));
305
- o(p);
398
+ o(l);
306
399
  };
307
- r.addEventListener("message", g, { once: !0 }), r.postMessage(d);
400
+ r.addEventListener("message", u, { once: !0 }), r.postMessage(d);
308
401
  });
309
402
  };
310
- function ae(t) {
403
+ function ye(t) {
311
404
  const { worker: e } = t;
312
405
  return {
313
406
  async searchFields({ text: r, layerIds: s, minScore: n, topResults: a, embeddingCache: i }) {
314
- return await se({
407
+ return await fe({
315
408
  combinedQuery: r,
316
409
  layerIds: s,
317
410
  embeddingsWorker: e,
@@ -322,15 +415,15 @@ function ae(t) {
322
415
  }
323
416
  };
324
417
  }
325
- const ie = (t) => {
326
- const e = F.safeParse(t);
418
+ const we = (t) => {
419
+ const e = $.safeParse(t);
327
420
  if (!e.success)
328
421
  throw new Error("Embeddings response validation failed. Regenerate embeddings.");
329
422
  return e.data;
330
- }, oe = (t, e) => {
423
+ }, ve = (t, e) => {
331
424
  const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
332
425
  if (e.allLayers.forEach((n) => {
333
- n instanceof O && s.set(n.id, n);
426
+ n instanceof V && s.set(n.id, n);
334
427
  }), t.length !== s.size)
335
428
  throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
336
429
  for (const n of t) {
@@ -369,27 +462,27 @@ const ie = (t) => {
369
462
  });
370
463
  }
371
464
  return r;
372
- }, ce = async (t) => {
465
+ }, Ee = async (t) => {
373
466
  try {
374
- return (await T(t, {
467
+ return (await z(t, {
375
468
  responseType: "json"
376
469
  })).data;
377
470
  } catch (e) {
378
471
  throw new Error(`Failed to fetch data from ${t}: ${String(e)}`);
379
472
  }
380
- }, de = async (t) => {
473
+ }, Se = async (t) => {
381
474
  const e = t.map;
382
475
  if (!e?.portalItem)
383
476
  throw new Error("WebMap portal item is missing.");
384
477
  const { resources: r } = await e.portalItem.fetchResources(), s = r.find((i) => i.resource.path === "embeddings-v01.json");
385
478
  if (!s?.resource.url)
386
479
  throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
387
- const n = await ce(s.resource.url);
388
- return ie(n);
480
+ const n = await Ee(s.resource.url);
481
+ return we(n);
389
482
  };
390
- class x {
483
+ class k {
391
484
  constructor() {
392
- this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new Z(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.streamEpoch = 0;
485
+ this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new R(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.parentRunIds = /* @__PURE__ */ new Map(), this.activeRuntimeSpans = /* @__PURE__ */ new Map(), this.runtimeEventsEnabled = !1, this.streamEpoch = 0;
393
486
  }
394
487
  /**
395
488
  * Creates and returns an AI-ready Orchestrator instance.
@@ -397,15 +490,16 @@ class x {
397
490
  * @returns Ready Orchestrator.
398
491
  */
399
492
  static async init(e) {
400
- const r = new x();
493
+ const r = new k();
494
+ r.runtimeEventsEnabled = e.runtimeEventsEnabled ?? !1;
401
495
  try {
402
496
  if (e.view?.map) {
403
- await P.whenOnce(() => e.view.ready);
404
- const s = await de(e.view), n = oe(
497
+ await G.whenOnce(() => e.view.ready);
498
+ const s = await Se(e.view), n = ve(
405
499
  s.layers,
406
500
  e.view.map
407
501
  );
408
- r.layersAndFieldsRegistry = n, r.embeddingsWorker = await U(s);
502
+ r.layersAndFieldsRegistry = n, r.embeddingsWorker = await B(s);
409
503
  }
410
504
  return e.agents?.forEach((s) => {
411
505
  r.agentRegistry.register(s);
@@ -421,35 +515,42 @@ class x {
421
515
  * - `interrupt`: HITL required, wait for `resumeInterrupt()`
422
516
  * - `completed`: final result with chat history + layer styling
423
517
  * - `cancelled`: user aborted the run
518
+ * @param userInput User request to process.
519
+ * @param options Agent selection and routing behavior for this run.
424
520
  */
425
- async *ask(e) {
521
+ async *ask(e, r = {}) {
426
522
  if (!this.orchestratorReady)
427
523
  throw new Error("Orchestrator is not ready yet.");
428
524
  if (!this.agentRegistry.list().length)
429
525
  throw new Error("Orchestrator has no registered agents.");
526
+ const s = this.createRequestAgentRegistry(r);
527
+ if (!s.list().length)
528
+ throw new Error("Orchestrator has no agents selected for this request.");
430
529
  if (++this.streamEpoch, !e.trim())
431
530
  return;
432
- const r = String(Date.now());
433
- this.activeRunId = r, this.activeAbortController = new AbortController(), this.graph || (this.graph = Y().compile({ checkpointer: new j() }));
434
- const s = this.embeddingsWorker ? ne({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? ae({ worker: this.embeddingsWorker }) : void 0, a = /* @__PURE__ */ new Map(), c = {
531
+ const n = U();
532
+ this.parentRunIds.clear(), this.activeRuntimeSpans.clear(), this.activeRunId = n, this.activeAbortController = new AbortController(), this.graph || (this.graph = oe().compile({ checkpointer: new j() }));
533
+ const a = this.embeddingsWorker ? pe({ worker: this.embeddingsWorker }) : void 0, i = this.embeddingsWorker ? ye({ worker: this.embeddingsWorker }) : void 0, c = /* @__PURE__ */ new Map(), d = r.routing === "direct" ? { mode: "direct", agentId: r.agentId } : { mode: "auto" }, o = {
534
+ // eslint-disable-next-line @typescript-eslint/naming-convention
535
+ thread_id: n,
536
+ hitlResponse: null,
537
+ services: {
538
+ layerSearch: a,
539
+ fieldSearch: i,
540
+ layersAndFieldsRegistry: this.layersAndFieldsRegistry,
541
+ agentRegistry: s,
542
+ embeddingCache: c
543
+ }
544
+ }, u = {
435
545
  version: "v2",
436
546
  streamMode: "custom",
437
- configurable: {
438
- // eslint-disable-next-line @typescript-eslint/naming-convention
439
- thread_id: r,
440
- abortSignal: this.activeAbortController.signal,
441
- hitlResponse: null,
442
- services: {
443
- layerSearch: s,
444
- fieldSearch: n,
445
- layersAndFieldsRegistry: this.layersAndFieldsRegistry,
446
- agentRegistry: this.agentRegistry,
447
- embeddingCache: a
448
- }
449
- },
547
+ signal: this.activeAbortController.signal,
548
+ ...this.runtimeEventsEnabled && { callbacks: [this.createHierarchyCallback()] },
549
+ configurable: o,
450
550
  subgraphs: !0
451
- }, d = this.graph?.streamEvents(
551
+ }, g = this.graph?.streamEvents(
452
552
  {
553
+ routing: d,
453
554
  agentExecutionContext: {
454
555
  userRequest: e,
455
556
  messages: this.chatHistory,
@@ -457,54 +558,54 @@ class x {
457
558
  sharedState: this.sharedState
458
559
  }
459
560
  },
460
- c
461
- ), o = ++this.streamEpoch;
462
- if (yield* this.pipeStream(d, o, r), this.isRunCancelled(r)) {
463
- yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
561
+ u
562
+ ), l = ++this.streamEpoch;
563
+ if (yield* this.pipeStream(g, l, n), this.isRunCancelled(n)) {
564
+ yield* this.createCancellationEvents(n);
464
565
  return;
465
566
  }
466
567
  for (; ; ) {
467
- if (this.isRunCancelled(r)) {
468
- yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
568
+ if (this.isRunCancelled(n)) {
569
+ yield* this.createCancellationEvents(n);
469
570
  return;
470
571
  }
471
- const m = (await this.graph.getState(c, { subgraphs: !0 })).tasks.find((h) => h.interrupts.length > 0)?.interrupts[0]?.value;
472
- if (!m)
572
+ const p = (await this.graph.getState(u, { subgraphs: !0 })).tasks.find((f) => f.interrupts.length > 0)?.interrupts[0]?.value;
573
+ if (!p)
473
574
  break;
474
- this.currentInterrupt = m, this.interruptHandler = new ee(this.graph, c), yield { runId: r, timestamp: Date.now(), type: "interrupt", interrupt: m };
575
+ this.currentInterrupt = p, this.interruptHandler = new le(this.graph, u), yield* this.closeActiveRuntimeSpans(n, "interrupted"), yield { runId: n, timestamp: Date.now(), type: "interrupt", interrupt: p };
475
576
  try {
476
- const h = await this.interruptHandler.waitForUser(), S = ++this.streamEpoch;
477
- yield* this.pipeStream(h, S, r);
478
- } catch (h) {
479
- if (this.isRunCancelled(r)) {
480
- yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
577
+ const f = await this.interruptHandler.waitForUser(), I = ++this.streamEpoch;
578
+ yield* this.pipeStream(f, I, n);
579
+ } catch (f) {
580
+ if (this.isRunCancelled(n)) {
581
+ yield* this.createCancellationEvents(n);
481
582
  return;
482
583
  }
483
- if (h) {
584
+ if (f) {
484
585
  yield {
485
- runId: r,
586
+ runId: n,
486
587
  timestamp: Date.now(),
487
588
  type: "error",
488
- error: { message: h?.message }
589
+ error: { message: f?.message }
489
590
  };
490
591
  return;
491
592
  }
492
593
  }
493
594
  }
494
- if (this.isRunCancelled(r)) {
495
- yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
595
+ if (this.isRunCancelled(n)) {
596
+ yield* this.createCancellationEvents(n);
496
597
  return;
497
598
  }
498
- const u = (await this.graph.getState(c, { subgraphs: !0 })).values;
499
- if (this.isRunCancelled(r)) {
500
- yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
599
+ const h = (await this.graph.getState(u, { subgraphs: !0 })).values;
600
+ if (this.isRunCancelled(n)) {
601
+ yield* this.createCancellationEvents(n);
501
602
  return;
502
603
  }
503
- this.chatHistory = u.agentExecutionContext.messages.length ? u.agentExecutionContext.messages : this.chatHistory, this.priorSteps = u.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = u.agentExecutionContext.sharedState ?? {}, yield {
504
- runId: r,
604
+ this.chatHistory = h.agentExecutionContext.messages.length ? h.agentExecutionContext.messages : this.chatHistory, this.priorSteps = h.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = h.agentExecutionContext.sharedState ?? {}, yield {
605
+ runId: n,
505
606
  timestamp: Date.now(),
506
607
  type: "completed",
507
- result: { content: u.finalOutputMessage }
608
+ result: { content: h.finalOutputMessage }
508
609
  };
509
610
  }
510
611
  /**
@@ -539,20 +640,78 @@ class x {
539
640
  this.activeRunId && (this.cancelledRunIds.add(this.activeRunId), this.activeAbortController?.abort(), ++this.streamEpoch, this.interruptHandler?.cancel());
540
641
  }
541
642
  async *pipeStream(e, r, s) {
542
- for await (const n of e) {
543
- if (this.isRunCancelled(s) || r !== this.streamEpoch)
544
- break;
545
- n.event === "on_custom_event" && n.name === "trace_message" ? yield { runId: s, timestamp: Date.now(), type: "trace", data: n.data } : n.name === "graph_ux_suggestion" && (yield {
546
- runId: s,
547
- timestamp: Date.now(),
548
- type: "ux-suggestion",
549
- suggestion: n.data
550
- });
643
+ try {
644
+ for await (const n of e) {
645
+ if (this.isRunCancelled(s) || r !== this.streamEpoch)
646
+ break;
647
+ if (this.runtimeEventsEnabled) {
648
+ const a = ge({
649
+ event: n,
650
+ runId: s,
651
+ parentSpanId: this.parentRunIds.get(n.run_id),
652
+ timestamp: Date.now()
653
+ });
654
+ a && (a.phase === "started" ? this.activeRuntimeSpans.set(a.span.id, a) : this.activeRuntimeSpans.delete(a.span.id), yield a);
655
+ }
656
+ n.event === "on_custom_event" && n.name === "trace_message" ? yield { runId: s, timestamp: Date.now(), type: "trace", data: n.data } : n.name === "graph_ux_suggestion" && (yield {
657
+ runId: s,
658
+ timestamp: Date.now(),
659
+ type: "ux-suggestion",
660
+ suggestion: n.data
661
+ });
662
+ }
663
+ } catch (n) {
664
+ if (!this.isRunCancelled(s))
665
+ throw n;
551
666
  }
552
667
  }
668
+ *createCancellationEvents(e) {
669
+ yield* this.closeActiveRuntimeSpans(e, "cancelled"), yield { runId: e, timestamp: Date.now(), type: "cancelled", reason: "user" };
670
+ }
671
+ *closeActiveRuntimeSpans(e, r) {
672
+ const s = Date.now(), n = [...this.activeRuntimeSpans.values()].reverse();
673
+ this.activeRuntimeSpans.clear();
674
+ for (const a of n) {
675
+ const { input: i, ...c } = a.span;
676
+ yield {
677
+ type: "runtime",
678
+ phase: r,
679
+ runId: e,
680
+ timestamp: s,
681
+ ...a.agentId && { agentId: a.agentId },
682
+ span: c
683
+ };
684
+ }
685
+ }
686
+ // v2 stream events omit parent run IDs, so capture them through callbacks to preserve the normalized span hierarchy.
687
+ createHierarchyCallback() {
688
+ const e = (r, s) => {
689
+ s && this.parentRunIds.set(r, s);
690
+ };
691
+ return N.fromMethods({
692
+ handleLLMStart: (r, s, n, a) => e(n, a),
693
+ handleChatModelStart: (r, s, n, a) => e(n, a),
694
+ handleChainStart: (r, s, n, a) => e(n, a),
695
+ handleToolStart: (r, s, n, a) => e(n, a),
696
+ handleRetrieverStart: (r, s, n, a) => e(n, a)
697
+ });
698
+ }
553
699
  isRunCancelled(e) {
554
700
  return this.cancelledRunIds.has(e);
555
701
  }
702
+ /**
703
+ * Creates a request-scoped registry containing all agents by default,
704
+ * or only the explicitly selected agents when filtering is requested.
705
+ */
706
+ createRequestAgentRegistry(e) {
707
+ const r = e.routing === "direct" ? [e.agentId] : e.agentIds, s = r ? r.map((a) => {
708
+ const i = this.agentRegistry.get(a);
709
+ if (!i)
710
+ throw new Error(`Agent is not registered: ${a}`);
711
+ return i;
712
+ }) : this.agentRegistry.list(), n = new R();
713
+ return s.forEach((a) => n.register(a)), n;
714
+ }
556
715
  /**
557
716
  * Disposes this instance by terminating the embeddings worker
558
717
  * and cleaning up all related resources.
@@ -562,6 +721,6 @@ class x {
562
721
  }
563
722
  }
564
723
  export {
565
- x as O,
566
- te as g
724
+ k as O,
725
+ he as g
567
726
  };