@arcgis/ai-components 5.2.0-next.10 → 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 (300) 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 +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/{SWOXSJ62.js → 2O4DON37.js} +1 -1
  71. package/dist/cdn/34O57OGV.js +2 -0
  72. package/dist/cdn/{5W7S2RS4.js → 3UEKINYC.js} +1 -1
  73. package/dist/cdn/4OGR5QKS.js +2 -0
  74. package/dist/cdn/5FL5BTTX.js +66 -0
  75. package/dist/cdn/5HBAJ57P.js +2 -0
  76. package/dist/cdn/5K5ZY267.js +2 -0
  77. package/dist/cdn/5MK44FNO.js +2 -0
  78. package/dist/cdn/5WYRJMBW.js +2 -0
  79. package/dist/cdn/5X7EG7D2.js +2 -0
  80. package/dist/cdn/5XZLS7UO.js +2 -0
  81. package/dist/cdn/5ZFUGNRN.js +2 -0
  82. package/dist/cdn/655YIKL3.js +11 -0
  83. package/dist/cdn/6ECRQVHY.js +2 -0
  84. package/dist/cdn/6OOZSZRJ.js +2 -0
  85. package/dist/cdn/{D3TNNRP4.js → 6P44KOKX.js} +1 -1
  86. package/dist/cdn/6YYPVU7H.js +3 -0
  87. package/dist/cdn/7BCQMK6D.js +2 -0
  88. package/dist/cdn/7SRLZQVC.js +5 -0
  89. package/dist/cdn/7V6OSTFC.js +2 -0
  90. package/dist/cdn/7VAQUCBU.js +9 -0
  91. package/dist/cdn/7VUSIGEM.js +2 -0
  92. package/dist/cdn/ACJTJLZN.js +2 -0
  93. package/dist/cdn/AI6DYOKR.js +181 -0
  94. package/dist/cdn/AKD5UOVX.js +2 -0
  95. package/dist/cdn/ANRQWYU2.js +2 -0
  96. package/dist/cdn/{ZS2TZ6BF.js → AOVJ34QE.js} +1 -1
  97. package/dist/cdn/APFZY4PI.js +2 -0
  98. package/dist/cdn/B2JDVLA6.js +2 -0
  99. package/dist/cdn/BE7BRJZD.js +2 -0
  100. package/dist/cdn/{FL4W4VYN.js → BL273EGZ.js} +17 -1
  101. package/dist/cdn/C4FEETBZ.js +2 -0
  102. package/dist/cdn/C4JT4S5E.js +2 -0
  103. package/dist/cdn/CCC6LBMY.js +2 -0
  104. package/dist/cdn/{5ZZGKP7N.js → CEKOEHB3.js} +1 -1
  105. package/dist/cdn/CJMUJXPL.js +2 -0
  106. package/dist/cdn/COH3QXWG.js +4 -0
  107. package/dist/cdn/CP5BVGJU.js +2 -0
  108. package/dist/cdn/D5UFYQHN.js +44 -0
  109. package/dist/cdn/EWLXNGKH.js +208 -0
  110. package/dist/cdn/EYOWRGDP.js +2 -0
  111. package/dist/cdn/F5NIRETW.js +2 -0
  112. package/dist/cdn/FDOMMK2M.js +2 -0
  113. package/dist/cdn/FG647IP6.js +2 -0
  114. package/dist/cdn/FJO4KNOZ.js +2 -0
  115. package/dist/cdn/FUF3NAU7.js +2 -0
  116. package/dist/cdn/FXP5UIQU.js +156 -0
  117. package/dist/cdn/{T537PKP4.js → FYZATVB3.js} +1 -1
  118. package/dist/cdn/G2EGT3CF.js +6 -0
  119. package/dist/cdn/G3SF6U2U.js +2 -0
  120. package/dist/cdn/G7OMHU2B.js +2 -0
  121. package/dist/cdn/HAEFC2SJ.js +2 -0
  122. package/dist/cdn/HDACNIZF.js +2 -0
  123. package/dist/cdn/HHFNQR6Z.js +2 -0
  124. package/dist/cdn/HHUQXL3R.js +2 -0
  125. package/dist/cdn/IBZ2NEAO.js +2 -0
  126. package/dist/cdn/{FX7UOGHP.js → ICBIUFK7.js} +1 -1
  127. package/dist/cdn/ICQCK5D3.js +2 -0
  128. package/dist/cdn/IHP25JWI.js +99 -0
  129. package/dist/cdn/IJVMUS2L.js +14 -0
  130. package/dist/cdn/J6A4AS7E.js +22 -0
  131. package/dist/cdn/J6SZIQJA.js +2 -0
  132. package/dist/cdn/JCOA24UH.js +3 -0
  133. package/dist/cdn/{NE7E52YR.js → JEBRN3EU.js} +9 -3
  134. package/dist/cdn/JO5ETMPS.js +2 -0
  135. package/dist/cdn/K2R6XVK3.js +2 -0
  136. package/dist/cdn/KITIP6J2.js +2 -0
  137. package/dist/cdn/KWD2ECTM.js +2 -0
  138. package/dist/cdn/{MODWHY3R.js → LAYVGCPL.js} +6 -4
  139. package/dist/cdn/{7RCQFLPP.js → LK7ZIQW6.js} +1 -1
  140. package/dist/cdn/LLUGJKAQ.js +2 -0
  141. package/dist/cdn/MWYBF3F3.js +66 -0
  142. package/dist/cdn/{VMXLYWUK.js → MXTXJKFE.js} +1 -1
  143. package/dist/cdn/MY47B3CE.js +3 -0
  144. package/dist/cdn/NEV6OZN3.js +71 -0
  145. package/dist/cdn/NNXISHCA.js +14 -0
  146. package/dist/cdn/NZSOJ726.js +2 -0
  147. package/dist/cdn/O4NVW75A.js +2 -0
  148. package/dist/cdn/OE3GW5LE.js +2 -0
  149. package/dist/cdn/{23EQTPO3.js → OKVLGJAG.js} +1 -1
  150. package/dist/cdn/ONQ6JSBJ.js +2 -0
  151. package/dist/cdn/OX64WOEL.js +22 -0
  152. package/dist/cdn/{LQ6R5YRN.js → PQ2DPOFM.js} +1 -1
  153. package/dist/cdn/PUHRBGKB.js +2 -0
  154. package/dist/cdn/Q57QWN5W.js +2 -0
  155. package/dist/cdn/QUKNPVAF.js +2 -0
  156. package/dist/cdn/R2PQVY4O.js +2 -0
  157. package/dist/cdn/R74ZHFA6.js +2 -0
  158. package/dist/cdn/RBE55SWR.js +2 -0
  159. package/dist/cdn/RHYNE5OE.js +2 -0
  160. package/dist/cdn/RLEHNAIA.js +2 -0
  161. package/dist/cdn/RVSTAUQS.js +2 -0
  162. package/dist/cdn/{X2ZDYHCG.js → SDWWUWAF.js} +10 -5
  163. package/dist/cdn/{GTLS44GI.js → SXM4NUT5.js} +1 -1
  164. package/dist/cdn/SZ2QSSB3.js +2 -0
  165. package/dist/cdn/T4RIGOXB.js +2 -0
  166. package/dist/cdn/TCH5I5LS.js +2 -0
  167. package/dist/cdn/TEPP7YPR.js +2 -0
  168. package/dist/cdn/TMVF2W5N.js +36 -0
  169. package/dist/cdn/TPULIO6I.js +34 -0
  170. package/dist/cdn/UDRKUVZP.js +2 -0
  171. package/dist/cdn/{6YMR4QSD.js → UHEYPSOR.js} +1 -1
  172. package/dist/cdn/UHNVDALX.js +18 -0
  173. package/dist/cdn/UZLQALHY.js +2 -0
  174. package/dist/cdn/V6HOUZPZ.js +2 -0
  175. package/dist/cdn/VAXH6RUQ.js +134 -0
  176. package/dist/cdn/VLLZ2FFU.js +2 -0
  177. package/dist/cdn/VOKXKU7M.js +56 -0
  178. package/dist/cdn/VXFQANGJ.js +2 -0
  179. package/dist/cdn/WGO5SER7.js +6 -0
  180. package/dist/cdn/WJXXOKGA.js +9 -0
  181. package/dist/cdn/WKTQVBFJ.js +2 -0
  182. package/dist/cdn/{2SJAOYZT.js → WSWB3B7B.js} +1 -1
  183. package/dist/cdn/XX6GHMNR.js +2 -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/Z5HWPSZN.js +2 -0
  188. package/dist/cdn/Z5W4V7RC.js +2 -0
  189. package/dist/cdn/ZDV4K4WG.js +2 -0
  190. package/dist/cdn/ZOEMBHRF.js +2 -0
  191. package/dist/cdn/ZRVZMPFN.js +2 -0
  192. package/dist/cdn/{ZTBA5PM7.js → ZU2FHVNK.js} +1 -1
  193. package/dist/cdn/agent-utils/index.js +2 -0
  194. package/dist/cdn/agent-utils/middlewares/humanInTheLoop.js +3 -0
  195. package/dist/cdn/agent-utils/middlewares/middleware.js +2 -0
  196. package/dist/cdn/agent-utils/middlewares/trace.js +2 -0
  197. package/dist/cdn/assets/assistant/t9n/messages.en.json +1 -1
  198. package/dist/cdn/assets/assistant-interrupt/t9n/messages.en.json +1 -1
  199. package/dist/cdn/assets/assistant-interrupt-preview/t9n/messages.en.json +1 -0
  200. package/dist/cdn/assets/assistant-message/t9n/messages.en.json +1 -0
  201. package/dist/cdn/assets/assistant-message-loading/t9n/messages.en.json +1 -0
  202. package/dist/cdn/index.js +1 -1
  203. package/dist/chunks/adapter.js +1295 -2104
  204. package/dist/chunks/arcgisKnowledgeGraph.js +128 -72
  205. package/dist/chunks/arcgis_knowledge_current_lc_context.js +19 -2
  206. package/dist/chunks/arcgis_knowledge_current_map_context.js +31 -2
  207. package/dist/chunks/arcgis_knowledge_cypher_query_prompt.js +102 -0
  208. package/dist/chunks/arcgis_knowledge_summarize_result_prompt.js +116 -27
  209. package/dist/chunks/baseAgentState.js +58 -0
  210. package/dist/chunks/converterUtils.js +66 -41
  211. package/dist/chunks/dataExplorationGraph.js +131 -182
  212. package/dist/chunks/data_explore_query_prompt.js +9 -4
  213. package/dist/chunks/fetchAgentContext.js +13 -0
  214. package/dist/chunks/fetchService.js +10 -0
  215. package/dist/chunks/fieldStatistics.js +79 -0
  216. package/dist/chunks/formatFeatureAttributes.js +132 -0
  217. package/dist/chunks/generateLayerDescriptions.js +259 -282
  218. package/dist/chunks/helpGraph.js +35 -25
  219. package/dist/chunks/help_prompt.js +34 -17
  220. package/dist/chunks/index.js +11 -0
  221. package/dist/chunks/intent_prompt.js +16 -0
  222. package/dist/chunks/layerStylingGraph.js +39 -33
  223. package/dist/chunks/mergeWhereClauses.js +15 -0
  224. package/dist/chunks/navigationGraph.js +140 -116
  225. package/dist/chunks/navigation_intent_prompt.js +8 -2
  226. package/dist/chunks/orchestrator.js +444 -233
  227. package/dist/chunks/resolvePointGeometryFilter.js +92 -0
  228. package/dist/chunks/state.js +21 -27
  229. package/dist/chunks/toolCallResponse.js +14 -10
  230. package/dist/chunks/utils2.js +11 -11
  231. package/dist/components/arcgis-assistant/customElement.d.ts +82 -1
  232. package/dist/components/arcgis-assistant/customElement.js +332 -183
  233. package/dist/components/arcgis-assistant-agent/customElement.d.ts +13 -1
  234. package/dist/components/arcgis-assistant-agent/customElement.js +614 -10
  235. package/dist/components/arcgis-assistant-chat/customElement.js +22 -17
  236. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +20 -4
  237. package/dist/components/arcgis-assistant-help-agent/customElement.js +29 -7
  238. package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +4 -0
  239. package/dist/components/arcgis-assistant-interrupt/customElement.js +11 -12
  240. package/dist/components/arcgis-assistant-interrupt-preview/customElement.js +12 -8
  241. package/dist/components/arcgis-assistant-knowledge-agent/customElement.d.ts +7 -7
  242. package/dist/components/arcgis-assistant-knowledge-agent/customElement.js +40 -16
  243. package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +30 -7
  244. package/dist/components/arcgis-assistant-message/customElement.d.ts +3 -0
  245. package/dist/components/arcgis-assistant-message/customElement.js +9 -8
  246. package/dist/components/arcgis-assistant-message-block/customElement.js +1 -1
  247. package/dist/components/arcgis-assistant-message-loading/customElement.d.ts +3 -0
  248. package/dist/components/arcgis-assistant-message-loading/customElement.js +11 -10
  249. package/dist/components/arcgis-assistant-message-text/customElement.d.ts +1 -0
  250. package/dist/components/arcgis-assistant-message-text/customElement.js +12 -12
  251. package/dist/components/arcgis-assistant-navigation-agent/customElement.js +18 -4
  252. package/dist/components/arcgis-assistant-speech-input/customElement.js +34 -52
  253. package/dist/components/arcgis-assistant-user-message/customElement.d.ts +2 -0
  254. package/dist/components/arcgis-assistant-user-message/customElement.js +15 -10
  255. package/dist/docs/api.json +1 -1
  256. package/dist/docs/docs.json +1 -1
  257. package/dist/docs/vscode.html-custom-data.json +1 -1
  258. package/dist/docs/web-types.json +1 -1
  259. package/dist/loader.js +6 -6
  260. package/dist/oauth-callback.html +1 -1
  261. package/dist/orchestrator/orchestrator/orchestratorEvents.d.ts +78 -0
  262. package/dist/types/lumina.d.ts +5 -4
  263. package/dist/types/preact.d.ts +5 -4
  264. package/dist/types/react.d.ts +5 -4
  265. package/dist/types/stencil.d.ts +7 -6
  266. package/dist/utils/index.d.ts +65 -38
  267. package/dist/utils/index.js +56 -55
  268. package/package.json +32 -12
  269. package/dist/cdn/462JBSEV.js +0 -422
  270. package/dist/cdn/5QAHYX7Y.js +0 -5
  271. package/dist/cdn/64PJB5NU.js +0 -2
  272. package/dist/cdn/6AWNQHCO.js +0 -4
  273. package/dist/cdn/AXDZBBNL.js +0 -45
  274. package/dist/cdn/BIV2IPHH.js +0 -2
  275. package/dist/cdn/CCY4TSBO.js +0 -2
  276. package/dist/cdn/CTSALWEP.js +0 -2
  277. package/dist/cdn/D2N2NSRQ.js +0 -72
  278. package/dist/cdn/DOV5ZJ7M.js +0 -2
  279. package/dist/cdn/EEUCKMU7.js +0 -2
  280. package/dist/cdn/EGHBXLNG.js +0 -2
  281. package/dist/cdn/ETRWZ3MS.js +0 -108
  282. package/dist/cdn/EWI4V3GQ.js +0 -36
  283. package/dist/cdn/F2AHA4GB.js +0 -54
  284. package/dist/cdn/I6HNBTWY.js +0 -2
  285. package/dist/cdn/JBHNHHWO.js +0 -3
  286. package/dist/cdn/JOFUPKIB.js +0 -2
  287. package/dist/cdn/KMQ3SP4I.js +0 -5
  288. package/dist/cdn/KUEOKIQR.js +0 -2
  289. package/dist/cdn/LKRAPK4A.js +0 -165
  290. package/dist/cdn/NXKKG5TK.js +0 -2
  291. package/dist/cdn/OBUZ7HBN.js +0 -2
  292. package/dist/cdn/OIVRK7HT.js +0 -2
  293. package/dist/cdn/RUURNLTP.js +0 -2
  294. package/dist/cdn/RVOAPUBN.js +0 -2
  295. package/dist/cdn/TSZPHE7L.js +0 -22
  296. package/dist/cdn/VAZNJSKA.js +0 -16
  297. package/dist/cdn/VNQN5ZQO.js +0 -14
  298. package/dist/cdn/WIDTPVSU.js +0 -2
  299. package/dist/cdn/XER22VYQ.js +0 -3
  300. package/dist/cdn/YIMNOUTF.js +0 -2
@@ -1,80 +1,127 @@
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 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,
16
+ webmapEmbeddings: n,
14
17
  auth: { apiUrl: r, token: a }
15
18
  };
16
- 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"));
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
- }, N = async () => {
27
+ }, Q = async () => {
25
28
  {
26
- const t = (await import("./embeddings.worker.js")).default;
27
- return new t();
28
- }
29
- }, G = (t) => {
30
- t.currentIntent = "none";
31
- }, _ = async (t, e) => {
32
- const r = v(e);
33
- if (t.agentExecutionContext.userRequest) {
34
- const n = new q(t.agentExecutionContext.userRequest.trim());
35
- t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], G(t);
36
- }
37
- 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
- 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.`);
42
45
  return;
43
46
  }
44
47
  const r = {};
45
- for (const [s, n] of Object.entries(t)) {
46
- if (!w(n) || !("value" in n)) {
48
+ for (const [s, t] of Object.entries(n)) {
49
+ if (!E(t) || !("value" in t)) {
47
50
  console.warn(
48
51
  `Agent "${e}" returned invalid sharedStatePatch entry for key "${s}". Ignoring that entry.`
49
52
  );
50
53
  continue;
51
54
  }
52
- r[s] = { value: n.value };
55
+ r[s] = { value: t.value };
53
56
  }
54
57
  return r;
55
- }, Q = (t) => {
56
- const { previousSharedState: e, patch: r, agentId: s } = t;
58
+ }, Z = (n) => {
59
+ const { previousSharedState: e, patch: r, agentId: s } = n;
57
60
  if (!r)
58
61
  return e;
59
- const n = Date.now(), a = {
62
+ const t = Date.now(), a = {
60
63
  ...e
61
64
  };
62
- for (const [i, c] of Object.entries(r))
63
- c?.value !== void 0 && (a[i] = {
64
- value: c.value,
65
+ for (const [i, o] of Object.entries(r))
66
+ o?.value !== void 0 && (a[i] = {
67
+ value: o.value,
65
68
  meta: {
66
69
  updatedByAgentId: s,
67
- updatedAt: n
70
+ updatedAt: t
68
71
  }
69
72
  });
70
73
  return a;
71
- }, f = (t) => {
72
- if (typeof t != "string")
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)
73
76
  return;
74
- const e = t.trim();
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")
120
+ return;
121
+ const e = n.trim();
75
122
  return e || void 0;
76
- }, B = (t) => {
77
- switch (t) {
123
+ }, ae = (n) => {
124
+ switch (n) {
78
125
  case "failed":
79
126
  return "Agent failed without a summary.";
80
127
  case "unknown":
@@ -84,98 +131,195 @@ const U = async (t) => {
84
131
  default:
85
132
  return "Agent completed without a summary.";
86
133
  }
87
- }, J = (t, e) => {
88
- const r = f(e?.outputMessage), s = f(e?.summary), n = e?.status, a = n === "success" || n === "failed" ? n : "unknown";
89
- a === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
90
- const i = z(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);
91
138
  return {
92
139
  outputMessage: r,
93
- summary: s ?? r ?? B(a),
140
+ summary: s ?? r ?? ae(a),
94
141
  status: a,
95
- sharedStatePatch: i
142
+ sharedStatePatch: i,
143
+ sharedResourceAdditions: o
96
144
  };
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), {
101
- ...t,
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,
102
150
  currentIntent: "none",
103
151
  requiresFollowUp: !1
104
152
  };
105
- const { agentRegistry: s } = r?.services ?? {}, n = s?.get(t.currentIntent);
106
- if (!n)
107
- return console.warn(`No agent found for intent: ${t.currentIntent}`), t;
108
- await l({ text: `Executing registered agent: ${n.agent.name}` }, e);
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);
109
157
  const a = {
110
158
  ...e ?? {},
159
+ metadata: {
160
+ ...e?.metadata,
161
+ agentId: t.agent.id
162
+ },
111
163
  configurable: {
112
164
  ...r ?? {},
113
- agentId: n.agent.id,
114
- context: n.getContext ? await n.getContext() : void 0
165
+ agentId: t.agent.id,
166
+ context: t.getContext ? await t.getContext() : void 0
115
167
  }
116
168
  };
117
169
  let i;
118
170
  try {
119
- const o = await n.agent.createGraph().compile().invoke(
171
+ const c = await t.agent.createGraph().compile().invoke(
120
172
  {
121
173
  agentExecutionContext: {
122
- ...t.agentExecutionContext,
174
+ ...n.agentExecutionContext,
123
175
  // deep clone on messages did not work in agents, so its a shallow clone here.
124
- messages: [...t.agentExecutionContext.messages],
176
+ messages: [...n.agentExecutionContext.messages],
125
177
  // deep clone to prevent accidental mutations by agents
126
- priorSteps: structuredClone(t.agentExecutionContext.priorSteps ?? []),
127
- sharedState: structuredClone(t.agentExecutionContext.sharedState ?? {})
178
+ priorSteps: structuredClone(n.agentExecutionContext.priorSteps ?? []),
179
+ sharedState: structuredClone(n.agentExecutionContext.sharedState ?? {}),
180
+ sharedResources: structuredClone(n.agentExecutionContext.sharedResources ?? [])
128
181
  }
129
182
  },
130
183
  a
131
184
  );
132
- i = J(n.agent.name, o), await l({ text: `Finished executing registered agent: ${n.agent.name}` }, e);
133
- } catch (o) {
134
- if (D(o))
135
- 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 = {
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 = {
138
191
  status: "failed",
139
- outputMessage: `Agent execution failed: ${g}`,
140
- summary: `Agent execution failed: ${g}`
192
+ outputMessage: `Agent execution failed: ${u}`,
193
+ summary: `Agent execution failed: ${u}`
141
194
  };
142
195
  }
143
- const c = i.outputMessage, d = [...t.agentExecutionContext.messages];
144
- if (c) {
145
- const o = c.length > E ? `${c.slice(0, E - 14)}
146
- [truncated]` : c;
147
- d.push(new H(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));
148
201
  }
149
202
  return {
150
- ...t,
151
- stepCount: t.stepCount + 1,
152
- lastExecutedAgent: n.agent.id,
153
- requiresFollowUp: i.status === "failed" ? !0 : t.requiresFollowUp,
154
- 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 ?? "",
155
208
  agentExecutionContext: {
156
- ...t.agentExecutionContext,
209
+ ...n.agentExecutionContext,
157
210
  messages: d,
158
211
  priorSteps: [
159
- ...t.agentExecutionContext.priorSteps ?? [],
212
+ ...n.agentExecutionContext.priorSteps ?? [],
160
213
  {
161
- agentId: n.agent.id,
162
- assignedTask: t.agentExecutionContext.assignedTask,
214
+ agentId: t.agent.id,
215
+ assignedTask: n.agentExecutionContext.assignedTask,
163
216
  summary: i?.summary || "No summary provided.",
164
217
  status: i?.status || "unknown"
165
218
  }
166
219
  ],
167
- sharedState: Q({
168
- previousSharedState: t.agentExecutionContext.sharedState,
220
+ sharedState: Z({
221
+ previousSharedState: n.agentExecutionContext.sharedState,
169
222
  patch: i.sharedStatePatch,
170
- agentId: n.agent.id
223
+ agentId: t.agent.id
224
+ }),
225
+ sharedResources: se({
226
+ previousSharedResources: n.agentExecutionContext.sharedResources,
227
+ additions: i.sharedResourceAdditions,
228
+ agentId: t.agent.id
171
229
  })
172
230
  }
173
231
  };
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 {
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 {
179
323
  constructor() {
180
324
  this.agentRegistry = /* @__PURE__ */ new Map();
181
325
  }
@@ -192,7 +336,7 @@ class Z {
192
336
  return [...this.agentRegistry.values()];
193
337
  }
194
338
  }
195
- class ee {
339
+ class fe {
196
340
  /**
197
341
  * Create a new InterruptHandler tied to a specific compiled graph and config.
198
342
  */
@@ -216,7 +360,7 @@ class ee {
216
360
  agentId: e.agentId,
217
361
  id: e.id,
218
362
  payload: r
219
- }, n = this.graph.streamEvents(null, {
363
+ }, t = this.graph.streamEvents(null, {
220
364
  ...this.config,
221
365
  configurable: {
222
366
  ...this.config.configurable,
@@ -225,7 +369,7 @@ class ee {
225
369
  subgraphs: !0,
226
370
  version: "v2"
227
371
  });
228
- this.resolveWait?.(n);
372
+ this.resolveWait?.(t);
229
373
  } catch (s) {
230
374
  this.rejectWait?.(s);
231
375
  } finally {
@@ -239,157 +383,157 @@ class ee {
239
383
  this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
240
384
  }
241
385
  }
242
- const te = async (t) => {
386
+ const we = async (n) => {
243
387
  try {
244
- return await (await M()).embedDocuments(t);
388
+ return await (await L()).embedDocuments(n);
245
389
  } catch (e) {
246
390
  throw console.error("Failed to generate embeddings:", e), e;
247
391
  }
248
- }, b = async (t, e) => {
249
- const r = e.get(t);
392
+ }, C = async (n, e) => {
393
+ const r = e.get(n);
250
394
  if (r)
251
395
  return r;
252
- const s = await te([t]);
253
- return e.set(t, s[0]), s[0];
396
+ const s = await we([n]);
397
+ return e.set(n, s[0]), s[0];
254
398
  };
255
- async function re(t, e, r, s) {
256
- const n = `req-${Date.now()}`, i = {
399
+ async function ve(n, e, r, s) {
400
+ const t = `req-${Date.now()}`, i = {
257
401
  type: "layerSearch",
258
- precomputedEmbedding: s ? await b(t, s) : void 0,
259
- requestId: n,
402
+ precomputedEmbedding: s ? await C(n, s) : void 0,
403
+ requestId: t,
260
404
  minScore: r
261
405
  };
262
- return await new Promise((c) => {
263
- const d = (o) => {
264
- o.data.requestId === n && c(o.data.results);
406
+ return await new Promise((o) => {
407
+ const d = (c) => {
408
+ c.data.requestId === t && o(c.data.results);
265
409
  };
266
410
  e.addEventListener("message", d, { once: !0 }), e.postMessage(i);
267
411
  });
268
412
  }
269
- function ne(t) {
270
- const { worker: e } = t;
413
+ function Ee(n) {
414
+ const { worker: e } = n;
271
415
  return {
272
416
  async searchLayers({
273
417
  text: r,
274
418
  minScore: s,
275
- embeddingCache: n
419
+ embeddingCache: t
276
420
  }) {
277
- return await re(r, e, s, n);
421
+ return await ve(r, e, s, t);
278
422
  }
279
423
  };
280
424
  }
281
- const se = async ({
282
- combinedQuery: t,
425
+ const Re = async ({
426
+ combinedQuery: n,
283
427
  layerIds: e,
284
428
  embeddingsWorker: r,
285
429
  minScore: s,
286
- topResults: n,
430
+ topResults: t,
287
431
  embeddingCache: a
288
432
  }) => {
289
- const i = `req-${Date.now()}`, c = a ? await b(t, a) : void 0, d = {
433
+ const i = `req-${Date.now()}`, o = a ? await C(n, a) : void 0, d = {
290
434
  type: "fieldSearch",
291
435
  layerIdForFieldsSearch: e,
292
- precomputedEmbedding: c,
436
+ precomputedEmbedding: o,
293
437
  requestId: i,
294
438
  minScore: s,
295
- topResults: n
439
+ topResults: t
296
440
  };
297
- return await new Promise((o) => {
298
- const g = (u) => {
299
- if (u.data.requestId !== i)
441
+ return await new Promise((c) => {
442
+ const u = (g) => {
443
+ if (g.data.requestId !== i)
300
444
  return;
301
- const p = u.data.results.map(({ layerId: y, results: m }) => ({
302
- layerId: y,
303
- results: m
445
+ const l = g.data.results.map(({ layerId: f, results: h }) => ({
446
+ layerId: f,
447
+ results: h
304
448
  }));
305
- o(p);
449
+ c(l);
306
450
  };
307
- r.addEventListener("message", g, { once: !0 }), r.postMessage(d);
451
+ r.addEventListener("message", u, { once: !0 }), r.postMessage(d);
308
452
  });
309
453
  };
310
- function ae(t) {
311
- const { worker: e } = t;
454
+ function xe(n) {
455
+ const { worker: e } = n;
312
456
  return {
313
- async searchFields({ text: r, layerIds: s, minScore: n, topResults: a, embeddingCache: i }) {
314
- return await se({
457
+ async searchFields({ text: r, layerIds: s, minScore: t, topResults: a, embeddingCache: i }) {
458
+ return await Re({
315
459
  combinedQuery: r,
316
460
  layerIds: s,
317
461
  embeddingsWorker: e,
318
- minScore: n,
462
+ minScore: t,
319
463
  topResults: a,
320
464
  embeddingCache: i
321
465
  });
322
466
  }
323
467
  };
324
468
  }
325
- const ie = (t) => {
326
- const e = F.safeParse(t);
469
+ const Se = (n) => {
470
+ const e = W.safeParse(n);
327
471
  if (!e.success)
328
472
  throw new Error("Embeddings response validation failed. Regenerate embeddings.");
329
473
  return e.data;
330
- }, oe = (t, e) => {
474
+ }, be = (n, e) => {
331
475
  const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
332
- if (e.allLayers.forEach((n) => {
333
- n instanceof O && s.set(n.id, n);
334
- }), t.length !== s.size)
476
+ if (e.allLayers.forEach((t) => {
477
+ t instanceof V && s.set(t.id, t);
478
+ }), n.length !== s.size)
335
479
  throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
336
- for (const n of t) {
337
- const a = s.get(n.id);
480
+ for (const t of n) {
481
+ const a = s.get(t.id);
338
482
  if (!a)
339
483
  throw new Error(
340
- `Layer with ID ${n.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.`
341
485
  );
342
- if (n.fields.length !== a.fields.length)
486
+ if (t.fields.length !== a.fields.length)
343
487
  throw new Error(
344
- `Field count mismatch for layer ID ${n.id} during registry restoration. Regenerate embeddings.`
488
+ `Field count mismatch for layer ID ${t.id} during registry restoration. Regenerate embeddings.`
345
489
  );
346
490
  const i = {
347
- name: n.name,
348
- title: n.title,
349
- description: n.description
350
- }, c = /* @__PURE__ */ new Map();
351
- for (const d of n.fields) {
352
- const o = a.fieldsIndex.get(d.name);
353
- if (!o)
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)
354
498
  throw new Error(
355
- `Field with name ${d.name} not found in the original layer ${n.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.`
356
500
  );
357
- c.set(d.name, {
501
+ o.set(d.name, {
358
502
  name: d.name,
359
503
  alias: a.getFieldAlias(d.name) ?? d.alias,
360
504
  description: d.description,
361
- type: o.type || "unknown",
362
- valueType: o.valueType || "unknown",
505
+ type: c.type || "unknown",
506
+ valueType: c.valueType || "unknown",
363
507
  domain: a.getFieldDomain(d.name) ?? void 0
364
508
  });
365
509
  }
366
- r.set(n.id, {
510
+ r.set(t.id, {
367
511
  layerItem: i,
368
- fieldRegistry: c
512
+ fieldRegistry: o
369
513
  });
370
514
  }
371
515
  return r;
372
- }, ce = async (t) => {
516
+ }, Ae = async (n) => {
373
517
  try {
374
- return (await T(t, {
518
+ return (await z(n, {
375
519
  responseType: "json"
376
520
  })).data;
377
521
  } catch (e) {
378
- throw new Error(`Failed to fetch data from ${t}: ${String(e)}`);
522
+ throw new Error(`Failed to fetch data from ${n}: ${String(e)}`);
379
523
  }
380
- }, de = async (t) => {
381
- const e = t.map;
524
+ }, Ce = async (n) => {
525
+ const e = n.map;
382
526
  if (!e?.portalItem)
383
527
  throw new Error("WebMap portal item is missing.");
384
528
  const { resources: r } = await e.portalItem.fetchResources(), s = r.find((i) => i.resource.path === "embeddings-v01.json");
385
529
  if (!s?.resource.url)
386
530
  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);
531
+ const t = await Ae(s.resource.url);
532
+ return Se(t);
389
533
  };
390
- class x {
534
+ class k {
391
535
  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;
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;
393
537
  }
394
538
  /**
395
539
  * Creates and returns an AI-ready Orchestrator instance.
@@ -397,15 +541,16 @@ class x {
397
541
  * @returns Ready Orchestrator.
398
542
  */
399
543
  static async init(e) {
400
- const r = new x();
544
+ const r = new k();
545
+ r.runtimeEventsEnabled = e.runtimeEventsEnabled ?? !1;
401
546
  try {
402
547
  if (e.view?.map) {
403
- await P.whenOnce(() => e.view.ready);
404
- const s = await de(e.view), n = oe(
548
+ await N.whenOnce(() => e.view.ready);
549
+ const s = await Ce(e.view), t = be(
405
550
  s.layers,
406
551
  e.view.map
407
552
  );
408
- r.layersAndFieldsRegistry = n, r.embeddingsWorker = await U(s);
553
+ r.layersAndFieldsRegistry = t, r.embeddingsWorker = await B(s);
409
554
  }
410
555
  return e.agents?.forEach((s) => {
411
556
  r.agentRegistry.register(s);
@@ -421,97 +566,105 @@ class x {
421
566
  * - `interrupt`: HITL required, wait for `resumeInterrupt()`
422
567
  * - `completed`: final result with chat history + layer styling
423
568
  * - `cancelled`: user aborted the run
569
+ * @param userInput User request to process.
570
+ * @param options Agent selection and routing behavior for this run.
424
571
  */
425
- async *ask(e) {
572
+ async *ask(e, r = {}) {
426
573
  if (!this.orchestratorReady)
427
574
  throw new Error("Orchestrator is not ready yet.");
428
575
  if (!this.agentRegistry.list().length)
429
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.");
430
580
  if (++this.streamEpoch, !e.trim())
431
581
  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 = {
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 = {
435
596
  version: "v2",
436
597
  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
- },
598
+ signal: this.activeAbortController.signal,
599
+ ...this.runtimeEventsEnabled && { callbacks: [this.createHierarchyCallback()] },
600
+ configurable: c,
450
601
  subgraphs: !0
451
- }, d = this.graph?.streamEvents(
602
+ }, g = this.graph?.streamEvents(
452
603
  {
604
+ routing: d,
453
605
  agentExecutionContext: {
454
606
  userRequest: e,
455
607
  messages: this.chatHistory,
456
608
  priorSteps: this.priorSteps,
457
- sharedState: this.sharedState
609
+ sharedState: this.sharedState,
610
+ sharedResources: this.sharedResources
458
611
  }
459
612
  },
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" };
613
+ u
614
+ ), l = ++this.streamEpoch;
615
+ if (yield* this.pipeStream(g, l, t), this.isRunCancelled(t)) {
616
+ yield* this.createCancellationEvents(t);
464
617
  return;
465
618
  }
466
619
  for (; ; ) {
467
- if (this.isRunCancelled(r)) {
468
- yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
620
+ if (this.isRunCancelled(t)) {
621
+ yield* this.createCancellationEvents(t);
469
622
  return;
470
623
  }
471
- const m = (await this.graph.getState(c, { subgraphs: !0 })).tasks.find((h) => h.interrupts.length > 0)?.interrupts[0]?.value;
624
+ const m = (await this.graph.getState(u, { subgraphs: !0 })).tasks.find((y) => y.interrupts.length > 0)?.interrupts[0]?.value;
472
625
  if (!m)
473
626
  break;
474
- this.currentInterrupt = m, this.interruptHandler = new ee(this.graph, c), yield { runId: r, 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 };
475
628
  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" };
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);
481
634
  return;
482
635
  }
483
- if (h) {
636
+ if (y) {
484
637
  yield {
485
- runId: r,
638
+ runId: t,
486
639
  timestamp: Date.now(),
487
640
  type: "error",
488
- error: { message: h?.message }
641
+ error: { message: y?.message }
489
642
  };
490
643
  return;
491
644
  }
492
645
  }
493
646
  }
494
- if (this.isRunCancelled(r)) {
495
- yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
647
+ if (this.isRunCancelled(t)) {
648
+ yield* this.createCancellationEvents(t);
496
649
  return;
497
650
  }
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" };
651
+ const h = (await this.graph.getState(u, { subgraphs: !0 })).values;
652
+ if (this.isRunCancelled(t)) {
653
+ yield* this.createCancellationEvents(t);
501
654
  return;
502
655
  }
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,
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,
505
658
  timestamp: Date.now(),
506
659
  type: "completed",
507
- result: { content: u.finalOutputMessage }
660
+ result: { content: h.finalOutputMessage }
508
661
  };
509
662
  }
510
663
  /**
511
664
  * Start a new conversation by clearing chat history, prior steps, and shared state.
512
665
  */
513
666
  newConversation() {
514
- this.chatHistory = [], this.priorSteps = [], this.sharedState = {};
667
+ this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.sharedResources = [];
515
668
  }
516
669
  /**
517
670
  * Generic resume for any HITL interrupt.
@@ -539,29 +692,87 @@ class x {
539
692
  this.activeRunId && (this.cancelledRunIds.add(this.activeRunId), this.activeAbortController?.abort(), ++this.streamEpoch, this.interruptHandler?.cancel());
540
693
  }
541
694
  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
- });
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
+ });
714
+ }
715
+ } catch (t) {
716
+ if (!this.isRunCancelled(s))
717
+ throw t;
718
+ }
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
+ };
551
736
  }
552
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
+ }
553
751
  isRunCancelled(e) {
554
752
  return this.cancelledRunIds.has(e);
555
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
+ }
556
767
  /**
557
768
  * Disposes this instance by terminating the embeddings worker
558
769
  * and cleaning up all related resources.
559
770
  */
560
771
  dispose() {
561
- 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;
562
773
  }
563
774
  }
564
775
  export {
565
- x as O,
566
- te as g
776
+ k as O,
777
+ we as g
567
778
  };