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

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 (162) hide show
  1. package/dist/agent-utils/FunctionAgent.d.ts +2 -2
  2. package/dist/agent-utils/LLMAgent.d.ts +2 -2
  3. package/dist/agent-utils/LLMAgent.js +22 -22
  4. package/dist/agent-utils/WorkflowAgent.d.ts +2 -2
  5. package/dist/agent-utils/index.d.ts +99 -0
  6. package/dist/agent-utils/index.js +148 -0
  7. package/dist/agent-utils/middlewares/trace.js +25 -33
  8. package/dist/agent-utils/tools/FunctionTool.d.ts +2 -2
  9. package/dist/agent-utils/types.d.ts +30 -1
  10. package/dist/agent-utils/workflows/ConditionalWorkflow.d.ts +2 -2
  11. package/dist/agent-utils/workflows/LoopWorkflow.d.ts +2 -2
  12. package/dist/agent-utils/workflows/ParallelWorkflow.d.ts +2 -2
  13. package/dist/agent-utils/workflows/RouterWorkflow.d.ts +2 -2
  14. package/dist/agent-utils/workflows/SequentialWorkflow.d.ts +2 -2
  15. package/dist/agent-utils/workflows/SwitchWorkflow.d.ts +2 -2
  16. package/dist/cdn/{V2P4AIGG.js → 24QNMEFG.js} +1 -1
  17. package/dist/cdn/{NAUXSHIE.js → 34SG44C3.js} +2 -2
  18. package/dist/cdn/3JGWGKT6.js +2 -0
  19. package/dist/cdn/3NBDVZ2I.js +2 -0
  20. package/dist/cdn/3VOQD2MR.js +2 -0
  21. package/dist/cdn/434TAA3J.js +2 -0
  22. package/dist/cdn/53NTYC4I.js +2 -0
  23. package/dist/cdn/{4HU7735A.js → 5CV7R5IS.js} +6 -4
  24. package/dist/cdn/{AMP6IALT.js → 5W7S2RS4.js} +1 -1
  25. package/dist/cdn/{FL4W4VYN.js → 6ZW7Z36F.js} +16 -0
  26. package/dist/cdn/7CYGX4F4.js +2 -0
  27. package/dist/cdn/{DHOVCT6R.js → AZGGTNA3.js} +1 -1
  28. package/dist/cdn/B7WJFBOZ.js +2 -0
  29. package/dist/cdn/BX7FSMUU.js +56 -0
  30. package/dist/cdn/CHPQM77M.js +181 -0
  31. package/dist/cdn/DHKUXLU3.js +179 -0
  32. package/dist/cdn/DQSEBKOX.js +2 -0
  33. package/dist/cdn/DXVU45KM.js +2 -0
  34. package/dist/cdn/{P6OPJQMC.js → DZ2QWNUA.js} +1 -1
  35. package/dist/cdn/EBISDZ5H.js +2 -0
  36. package/dist/cdn/{MDVYQQUG.js → ERL2CB2Y.js} +5 -5
  37. package/dist/cdn/F6QHMKF5.js +2 -0
  38. package/dist/cdn/FUIGPHBH.js +2 -0
  39. package/dist/cdn/{AO7BQHKC.js → H2CHHGGH.js} +1 -1
  40. package/dist/cdn/{OH64RMOR.js → HWKDNS4K.js} +2 -2
  41. package/dist/cdn/IMQ4TVHF.js +16 -0
  42. package/dist/cdn/IOD3GDA7.js +2 -0
  43. package/dist/cdn/IR7PTESF.js +2 -0
  44. package/dist/cdn/IRZDTYO2.js +2 -0
  45. package/dist/cdn/JIWK6QK6.js +2 -0
  46. package/dist/cdn/{S6W6HV4T.js → JLKGS6Y5.js} +12 -12
  47. package/dist/cdn/K3JCH4XW.js +2 -0
  48. package/dist/cdn/KHXUWZHB.js +2 -0
  49. package/dist/cdn/LIFK3QSD.js +2 -0
  50. package/dist/cdn/NXKKG5TK.js +2 -0
  51. package/dist/cdn/{FX5JFRDL.js → O3EN27N5.js} +1 -1
  52. package/dist/cdn/O3RFFPU3.js +6 -0
  53. package/dist/cdn/P7DG5T3Z.js +9 -0
  54. package/dist/cdn/PBO6FZN6.js +2 -0
  55. package/dist/cdn/Q3ZW4FYA.js +3 -0
  56. package/dist/cdn/Q6LRANX6.js +2 -0
  57. package/dist/cdn/Q7TL5Q5N.js +2 -0
  58. package/dist/cdn/QCSN44H4.js +2 -0
  59. package/dist/cdn/R56X6ZKR.js +161 -0
  60. package/dist/cdn/{HB5A5R2E.js → RUURNLTP.js} +1 -1
  61. package/dist/cdn/T43LEBBE.js +47 -0
  62. package/dist/cdn/{ZLXN7NMF.js → T537PKP4.js} +9 -7
  63. package/dist/cdn/TR4GFL7X.js +2 -0
  64. package/dist/cdn/{3PKJWIC3.js → UPEEHMSY.js} +1 -1
  65. package/dist/cdn/WAIFKDR3.js +2 -0
  66. package/dist/cdn/WNS5ZUF5.js +2 -0
  67. package/dist/cdn/X4XY5HIE.js +2 -0
  68. package/dist/cdn/XOH56EQ2.js +2 -0
  69. package/dist/cdn/XON27U6U.js +2 -0
  70. package/dist/cdn/{H7422XUG.js → YLN2BZ5J.js} +1 -1
  71. package/dist/cdn/{2AXF774U.js → YUKR4AZW.js} +1 -1
  72. package/dist/cdn/{JY6LLOUJ.js → Z2G7MP5L.js} +3 -3
  73. package/dist/cdn/ZEYIBYSF.js +66 -0
  74. package/dist/cdn/agent-utils/index.js +2 -0
  75. package/dist/cdn/agent-utils/middlewares/humanInTheLoop.js +3 -0
  76. package/dist/cdn/agent-utils/middlewares/middleware.js +2 -0
  77. package/dist/cdn/agent-utils/middlewares/trace.js +2 -0
  78. package/dist/cdn/index.js +1 -1
  79. package/dist/cdn/main.css +1 -1
  80. package/dist/chunks/adapter.js +1390 -1323
  81. package/dist/chunks/arcgisKnowledgeGraph.js +109 -72
  82. package/dist/chunks/dataExplorationGraph.js +108 -96
  83. package/dist/chunks/generateLayerDescriptions.js +206 -168
  84. package/dist/chunks/helpGraph.js +16 -13
  85. package/dist/chunks/index.js +11 -0
  86. package/dist/chunks/intent_prompt.js +16 -0
  87. package/dist/chunks/layerStylingGraph.js +23 -20
  88. package/dist/chunks/navigationGraph.js +34 -30
  89. package/dist/chunks/orchestrator.js +241 -201
  90. package/dist/chunks/slottableRequestUtils.js +3 -7
  91. package/dist/chunks/summarize_query_response_prompt.js +9 -7
  92. package/dist/chunks/toolCallResponse.js +5 -3
  93. package/dist/components/arcgis-assistant/customElement.d.ts +15 -0
  94. package/dist/components/arcgis-assistant/customElement.js +228 -127
  95. package/dist/components/arcgis-assistant/index.js +2 -3
  96. package/dist/components/arcgis-assistant/types.d.ts +14 -1
  97. package/dist/components/arcgis-assistant-chat/customElement.d.ts +8 -2
  98. package/dist/components/arcgis-assistant-chat/customElement.js +7 -7
  99. package/dist/components/arcgis-assistant-chat-entry/customElement.d.ts +4 -1
  100. package/dist/components/arcgis-assistant-chat-entry/customElement.js +25 -18
  101. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +1 -0
  102. package/dist/components/arcgis-assistant-help-agent/customElement.js +1 -0
  103. package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +4 -1
  104. package/dist/components/arcgis-assistant-interrupt/customElement.js +13 -9
  105. package/dist/components/arcgis-assistant-interrupt-preview/customElement.js +20 -0
  106. package/dist/components/arcgis-assistant-interrupt-preview/index.js +2 -0
  107. package/dist/components/arcgis-assistant-knowledge-agent/customElement.d.ts +7 -7
  108. package/dist/components/arcgis-assistant-knowledge-agent/customElement.js +1 -0
  109. package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +1 -0
  110. package/dist/components/arcgis-assistant-message/customElement.d.ts +23 -0
  111. package/dist/components/arcgis-assistant-message/customElement.js +28 -26
  112. package/dist/components/arcgis-assistant-message/index.d.ts +1 -0
  113. package/dist/components/arcgis-assistant-message/index.js +2 -0
  114. package/dist/components/arcgis-assistant-message-block/customElement.d.ts +1 -1
  115. package/dist/components/arcgis-assistant-message-block/customElement.js +18 -11
  116. package/dist/components/arcgis-assistant-message-block/index.js +1 -0
  117. package/dist/components/arcgis-assistant-message-feedback/customElement.d.ts +4 -1
  118. package/dist/components/arcgis-assistant-message-footer/customElement.d.ts +4 -1
  119. package/dist/components/arcgis-assistant-message-loading/customElement.d.ts +8 -1
  120. package/dist/components/arcgis-assistant-message-loading/customElement.js +8 -8
  121. package/dist/components/arcgis-assistant-message-loading/index.js +1 -0
  122. package/dist/components/arcgis-assistant-message-log/customElement.d.ts +4 -1
  123. package/dist/components/arcgis-assistant-message-read-aloud/customElement.d.ts +4 -1
  124. package/dist/components/arcgis-assistant-message-text/customElement.d.ts +4 -1
  125. package/dist/components/arcgis-assistant-navigation-agent/customElement.js +1 -0
  126. package/dist/components/arcgis-assistant-speech-input/customElement.d.ts +6 -1
  127. package/dist/components/arcgis-assistant-suggested-prompts/customElement.d.ts +4 -1
  128. package/dist/components/arcgis-assistant-suggested-prompts/customElement.js +8 -8
  129. package/dist/components/arcgis-assistant-user-message/customElement.d.ts +4 -1
  130. package/dist/components/arcgis-assistant-user-message/customElement.js +1 -1
  131. package/dist/docs/api.json +1 -1
  132. package/dist/docs/docs.json +1 -1
  133. package/dist/docs/vscode.html-custom-data.json +1 -1
  134. package/dist/docs/web-types.json +1 -1
  135. package/dist/index.d.ts +4 -0
  136. package/dist/loader.js +6 -5
  137. package/dist/orchestrator/registry/agentRegistry.d.ts +33 -0
  138. package/dist/types/lumina.d.ts +10 -4
  139. package/dist/types/preact.d.ts +11 -4
  140. package/dist/types/react.d.ts +12 -4
  141. package/dist/types/stencil.d.ts +10 -4
  142. package/dist/utils/index.d.ts +87 -43
  143. package/dist/utils/index.js +54 -49
  144. package/package.json +8 -7
  145. package/dist/cdn/462JBSEV.js +0 -422
  146. package/dist/cdn/7BCR6TUO.js +0 -2
  147. package/dist/cdn/7GH7VSB2.js +0 -2
  148. package/dist/cdn/7PLV4QH6.js +0 -2
  149. package/dist/cdn/DDLZOMUY.js +0 -2
  150. package/dist/cdn/FHVXO2WG.js +0 -166
  151. package/dist/cdn/GSEPHN3A.js +0 -106
  152. package/dist/cdn/MH5RPXHM.js +0 -2
  153. package/dist/cdn/NVI3I46B.js +0 -2
  154. package/dist/cdn/OAVEHGB6.js +0 -2
  155. package/dist/cdn/ON2V5XI2.js +0 -3
  156. package/dist/cdn/QR54T33D.js +0 -2
  157. package/dist/cdn/RVOAPUBN.js +0 -2
  158. package/dist/cdn/SXDLXCIM.js +0 -2
  159. package/dist/cdn/USMDJUFS.js +0 -2
  160. package/dist/cdn/V5YEZSRY.js +0 -16
  161. package/dist/cdn/Y333DGV6.js +0 -2
  162. package/dist/cdn/YY2SBO3V.js +0 -2
@@ -1,19 +1,20 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import S from "@arcgis/core/identity/IdentityManager.js";
3
- import b from "@arcgis/core/portal/Portal.js";
4
- import { p as I, s as l, D as R, q as k, r as M, W as C } from "./generateLayerDescriptions.js";
5
- import { isGraphInterrupt as A, StateGraph as F, START as L, END as W, MemorySaver as $ } from "@langchain/langgraph/web";
6
- import { HumanMessage as D, AIMessage as j } from "@langchain/core/messages";
2
+ import R from "@arcgis/core/identity/IdentityManager.js";
3
+ import C from "@arcgis/core/portal/Portal.js";
4
+ import { n as I, o as v, D as k, p as A, q 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 { s as l } from "./index.js";
7
8
  import * as P from "@arcgis/core/core/reactiveUtils.js";
8
- import q from "@arcgis/core/layers/FeatureLayer.js";
9
- import H from "@arcgis/core/request.js";
10
- const O = async (t) => {
11
- const e = await T(), s = await I("default"), n = b.getDefault(), i = (await S.getCredential(`${n.url}/sharing`)).token, a = {
9
+ import U from "@arcgis/core/layers/FeatureLayer.js";
10
+ import O from "@arcgis/core/request.js";
11
+ const T = async (t) => {
12
+ const e = await N(), r = await I("default"), s = C.getDefault(), a = (await R.getCredential(`${s.url}/sharing`)).token, i = {
12
13
  type: "generateEmbeddings",
13
14
  webmapEmbeddings: t,
14
- auth: { apiUrl: s, token: i }
15
+ auth: { apiUrl: r, token: a }
15
16
  };
16
- return e.postMessage(a), await new Promise((c, d) => {
17
+ return e.postMessage(i), await new Promise((c, d) => {
17
18
  const o = (u) => {
18
19
  u.data === "completed" && (e.removeEventListener("message", o), c());
19
20
  }, g = (u) => {
@@ -21,58 +22,59 @@ const O = async (t) => {
21
22
  };
22
23
  e.addEventListener("message", o), e.addEventListener("error", g, { once: !0 });
23
24
  }), e;
24
- }, T = async () => {
25
+ }, N = async () => {
25
26
  {
26
27
  const t = (await import("./embeddings.worker.js")).default;
27
28
  return new t();
28
29
  }
29
- }, U = (t) => {
30
+ }, G = (t) => {
30
31
  t.currentIntent = "none";
31
- }, N = async (t, e) => {
32
+ }, _ = async (t, e) => {
33
+ const r = v(e);
32
34
  if (t.agentExecutionContext.userRequest) {
33
- const n = new D(t.agentExecutionContext.userRequest.trim());
34
- t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], U(t);
35
+ const n = new q(t.agentExecutionContext.userRequest.trim());
36
+ t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], G(t);
35
37
  }
36
- const s = e?.configurable?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
38
+ const s = r?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
37
39
  return await l({ text: `Available agents: ${[...s].join(", ")}` }, e), await l({ text: "Analyzing user input" }, e), t;
38
- }, G = async (t, e) => (await l({ text: "Exiting..." }, e), t), y = (t) => typeof t == "object" && t !== null && !Array.isArray(t), _ = (t, e) => {
39
- if (!y(t)) {
40
+ }, V = async (t, e) => (await l({ text: "Exiting..." }, e), t), w = (t) => typeof t == "object" && t !== null && !Array.isArray(t), z = (t, e) => {
41
+ if (!w(t)) {
40
42
  t !== void 0 && console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`);
41
43
  return;
42
44
  }
43
- const s = {};
44
- for (const [n, r] of Object.entries(t)) {
45
- if (!y(r) || !("value" in r)) {
45
+ const r = {};
46
+ for (const [s, n] of Object.entries(t)) {
47
+ if (!w(n) || !("value" in n)) {
46
48
  console.warn(
47
- `Agent "${e}" returned invalid sharedStatePatch entry for key "${n}". Ignoring that entry.`
49
+ `Agent "${e}" returned invalid sharedStatePatch entry for key "${s}". Ignoring that entry.`
48
50
  );
49
51
  continue;
50
52
  }
51
- s[n] = { value: r.value };
53
+ r[s] = { value: n.value };
52
54
  }
53
- return s;
54
- }, V = (t) => {
55
- const { previousSharedState: e, patch: s, agentId: n } = t;
56
- if (!s)
55
+ return r;
56
+ }, Q = (t) => {
57
+ const { previousSharedState: e, patch: r, agentId: s } = t;
58
+ if (!r)
57
59
  return e;
58
- const r = Date.now(), i = {
60
+ const n = Date.now(), a = {
59
61
  ...e
60
62
  };
61
- for (const [a, c] of Object.entries(s))
62
- c?.value !== void 0 && (i[a] = {
63
+ for (const [i, c] of Object.entries(r))
64
+ c?.value !== void 0 && (a[i] = {
63
65
  value: c.value,
64
66
  meta: {
65
- updatedByAgentId: n,
66
- updatedAt: r
67
+ updatedByAgentId: s,
68
+ updatedAt: n
67
69
  }
68
70
  });
69
- return i;
70
- }, w = (t) => {
71
+ return a;
72
+ }, f = (t) => {
71
73
  if (typeof t != "string")
72
74
  return;
73
75
  const e = t.trim();
74
76
  return e || void 0;
75
- }, z = (t) => {
77
+ }, B = (t) => {
76
78
  switch (t) {
77
79
  case "failed":
78
80
  return "Agent failed without a summary.";
@@ -83,32 +85,39 @@ const O = async (t) => {
83
85
  default:
84
86
  return "Agent completed without a summary.";
85
87
  }
86
- }, Q = (t, e) => {
87
- const s = w(e?.outputMessage), n = w(e?.summary), r = e?.status, i = r === "success" || r === "failed" ? r : "unknown";
88
- i === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
89
- const a = _(e?.sharedStatePatch, t);
88
+ }, J = (t, e) => {
89
+ const r = f(e?.outputMessage), s = f(e?.summary), n = e?.status, a = n === "success" || n === "failed" ? n : "unknown";
90
+ a === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
91
+ const i = z(e?.sharedStatePatch, t);
90
92
  return {
91
- outputMessage: s,
92
- summary: n ?? s ?? z(i),
93
- status: i,
94
- sharedStatePatch: a
93
+ outputMessage: r,
94
+ summary: s ?? r ?? B(a),
95
+ status: a,
96
+ sharedStatePatch: i
95
97
  };
96
- }, f = 4e3, B = async (t, e) => {
97
- const s = e?.configurable, { agentRegistry: n } = s.services, r = n?.get(t.currentIntent);
98
- if (!r)
98
+ }, E = 4e3, K = async (t, e) => {
99
+ const r = v(e);
100
+ if (r?.abortSignal?.aborted)
101
+ return await l({ text: "Run cancelled; skipping agent execution" }, e), {
102
+ ...t,
103
+ currentIntent: "none",
104
+ requiresFollowUp: !1
105
+ };
106
+ const { agentRegistry: s } = r?.services ?? {}, n = s?.get(t.currentIntent);
107
+ if (!n)
99
108
  return console.warn(`No agent found for intent: ${t.currentIntent}`), t;
100
- await l({ text: `Executing registered agent: ${r.agent.name}` }, e);
101
- const i = {
109
+ await l({ text: `Executing registered agent: ${n.agent.name}` }, e);
110
+ const a = {
102
111
  ...e ?? {},
103
112
  configurable: {
104
- ...s ?? {},
105
- agentId: r.agent.id,
106
- context: r.getContext ? await r.getContext() : void 0
113
+ ...r ?? {},
114
+ agentId: n.agent.id,
115
+ context: n.getContext ? await n.getContext() : void 0
107
116
  }
108
117
  };
109
- let a;
118
+ let i;
110
119
  try {
111
- const o = await r.agent.createGraph().compile().invoke(
120
+ const o = await n.agent.createGraph().compile().invoke(
112
121
  {
113
122
  agentExecutionContext: {
114
123
  ...t.agentExecutionContext,
@@ -119,30 +128,30 @@ const O = async (t) => {
119
128
  sharedState: structuredClone(t.agentExecutionContext.sharedState ?? {})
120
129
  }
121
130
  },
122
- i
131
+ a
123
132
  );
124
- a = Q(r.agent.name, o), await l({ text: `Finished executing registered agent: ${r.agent.name}` }, e);
133
+ i = J(n.agent.name, o), await l({ text: `Finished executing registered agent: ${n.agent.name}` }, e);
125
134
  } catch (o) {
126
- if (A(o))
135
+ if (D(o))
127
136
  throw o;
128
137
  const g = o instanceof Error ? o.message : String(o);
129
- console.error(`Agent "${r.agent.name}" failed:`, o), await l({ text: `Registered agent failed: ${r.agent.name}. ${g}` }, e), a = {
138
+ console.error(`Agent "${n.agent.name}" failed:`, o), await l({ text: `Registered agent failed: ${n.agent.name}. ${g}` }, e), i = {
130
139
  status: "failed",
131
140
  outputMessage: `Agent execution failed: ${g}`,
132
141
  summary: `Agent execution failed: ${g}`
133
142
  };
134
143
  }
135
- const c = a.outputMessage, d = [...t.agentExecutionContext.messages];
144
+ const c = i.outputMessage, d = [...t.agentExecutionContext.messages];
136
145
  if (c) {
137
- const o = c.length > f ? `${c.slice(0, f - 14)}
146
+ const o = c.length > E ? `${c.slice(0, E - 14)}
138
147
  [truncated]` : c;
139
- d.push(new j(o));
148
+ d.push(new H(o));
140
149
  }
141
150
  return {
142
151
  ...t,
143
152
  stepCount: t.stepCount + 1,
144
- lastExecutedAgent: r.agent.id,
145
- requiresFollowUp: a.status === "failed" ? !0 : t.requiresFollowUp,
153
+ lastExecutedAgent: n.agent.id,
154
+ requiresFollowUp: i.status === "failed" ? !0 : t.requiresFollowUp,
146
155
  finalOutputMessage: c ?? "",
147
156
  agentExecutionContext: {
148
157
  ...t.agentExecutionContext,
@@ -150,32 +159,32 @@ const O = async (t) => {
150
159
  priorSteps: [
151
160
  ...t.agentExecutionContext.priorSteps ?? [],
152
161
  {
153
- agentId: r.agent.id,
162
+ agentId: n.agent.id,
154
163
  assignedTask: t.agentExecutionContext.assignedTask,
155
- summary: a?.summary || "No summary provided.",
156
- status: a?.status || "unknown"
164
+ summary: i?.summary || "No summary provided.",
165
+ status: i?.status || "unknown"
157
166
  }
158
167
  ],
159
- sharedState: V({
168
+ sharedState: Q({
160
169
  previousSharedState: t.agentExecutionContext.sharedState,
161
- patch: a.sharedStatePatch,
162
- agentId: r.agent.id
170
+ patch: i.sharedStatePatch,
171
+ agentId: n.agent.id
163
172
  })
164
173
  }
165
174
  };
166
- }, J = 3, K = () => new F(R).addNode("ingestInput", N).addNode("intentLLM", k).addNode("executeRegisteredAgent", B).addNode("exit", G).addEdge(L, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges(
175
+ }, 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(
167
176
  "executeRegisteredAgent",
168
- (e) => e.stepCount >= J || !e.requiresFollowUp ? "exit" : "intentLLM"
169
- ).addEdge("exit", W);
170
- class X {
177
+ (e) => e.stepCount >= X || !e.requiresFollowUp ? "exit" : "intentLLM"
178
+ ).addEdge("exit", $);
179
+ class Z {
171
180
  constructor() {
172
181
  this.agentRegistry = /* @__PURE__ */ new Map();
173
182
  }
174
183
  register(e) {
175
- const { agent: s } = e;
176
- if (this.agentRegistry.has(s.id))
177
- throw new Error(`Duplicate agent id: ${s.id}`);
178
- this.agentRegistry.set(s.id, e);
184
+ const { agent: r } = e;
185
+ if (this.agentRegistry.has(r.id))
186
+ throw new Error(`Duplicate agent id: ${r.id}`);
187
+ this.agentRegistry.set(r.id, e);
179
188
  }
180
189
  get(e) {
181
190
  return this.agentRegistry.get(e);
@@ -184,42 +193,42 @@ class X {
184
193
  return [...this.agentRegistry.values()];
185
194
  }
186
195
  }
187
- class Y {
196
+ class ee {
188
197
  /**
189
198
  * Create a new InterruptHandler tied to a specific compiled graph and config.
190
199
  */
191
- constructor(e, s) {
192
- this.graph = e, this.config = { ...s };
200
+ constructor(e, r) {
201
+ this.graph = e, this.config = { ...r };
193
202
  }
194
203
  /**
195
204
  * Returns a promise that resolves when the user provides a HITL response.
196
205
  */
197
206
  async waitForUser() {
198
- return await new Promise((e, s) => {
199
- this.resolveWait = e, this.rejectWait = s;
207
+ return await new Promise((e, r) => {
208
+ this.resolveWait = e, this.rejectWait = r;
200
209
  });
201
210
  }
202
211
  /**
203
212
  * Resume graph execution after the UI responds to an interrupt.
204
213
  */
205
- handle(e, s) {
214
+ handle(e, r) {
206
215
  try {
207
- const n = {
216
+ const s = {
208
217
  agentId: e.agentId,
209
218
  id: e.id,
210
- payload: s
211
- }, r = this.graph.streamEvents(null, {
219
+ payload: r
220
+ }, n = this.graph.streamEvents(null, {
212
221
  ...this.config,
213
222
  configurable: {
214
223
  ...this.config.configurable,
215
- hitlResponse: n
224
+ hitlResponse: s
216
225
  },
217
226
  subgraphs: !0,
218
227
  version: "v2"
219
228
  });
220
- this.resolveWait?.(r);
221
- } catch (n) {
222
- this.rejectWait?.(n);
229
+ this.resolveWait?.(n);
230
+ } catch (s) {
231
+ this.rejectWait?.(s);
223
232
  } finally {
224
233
  this.resolveWait = void 0, this.rejectWait = void 0;
225
234
  }
@@ -231,157 +240,157 @@ class Y {
231
240
  this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
232
241
  }
233
242
  }
234
- const Z = async (t) => {
243
+ const te = async (t) => {
235
244
  try {
236
245
  return await (await M()).embedDocuments(t);
237
246
  } catch (e) {
238
247
  throw console.error("Failed to generate embeddings:", e), e;
239
248
  }
240
- }, E = async (t, e) => {
241
- const s = e.get(t);
242
- if (s)
243
- return s;
244
- const n = await Z([t]);
245
- return e.set(t, n[0]), n[0];
249
+ }, b = async (t, e) => {
250
+ const r = e.get(t);
251
+ if (r)
252
+ return r;
253
+ const s = await te([t]);
254
+ return e.set(t, s[0]), s[0];
246
255
  };
247
- async function ee(t, e, s, n) {
248
- const r = `req-${Date.now()}`, a = {
256
+ async function re(t, e, r, s) {
257
+ const n = `req-${Date.now()}`, i = {
249
258
  type: "layerSearch",
250
- precomputedEmbedding: n ? await E(t, n) : void 0,
251
- requestId: r,
252
- minScore: s
259
+ precomputedEmbedding: s ? await b(t, s) : void 0,
260
+ requestId: n,
261
+ minScore: r
253
262
  };
254
263
  return await new Promise((c) => {
255
264
  const d = (o) => {
256
- o.data.requestId === r && c(o.data.results);
265
+ o.data.requestId === n && c(o.data.results);
257
266
  };
258
- e.addEventListener("message", d, { once: !0 }), e.postMessage(a);
267
+ e.addEventListener("message", d, { once: !0 }), e.postMessage(i);
259
268
  });
260
269
  }
261
- function te(t) {
270
+ function ne(t) {
262
271
  const { worker: e } = t;
263
272
  return {
264
273
  async searchLayers({
265
- text: s,
266
- minScore: n,
267
- embeddingCache: r
274
+ text: r,
275
+ minScore: s,
276
+ embeddingCache: n
268
277
  }) {
269
- return await ee(s, e, n, r);
278
+ return await re(r, e, s, n);
270
279
  }
271
280
  };
272
281
  }
273
- const re = async ({
282
+ const se = async ({
274
283
  combinedQuery: t,
275
284
  layerIds: e,
276
- embeddingsWorker: s,
277
- minScore: n,
278
- topResults: r,
279
- embeddingCache: i
285
+ embeddingsWorker: r,
286
+ minScore: s,
287
+ topResults: n,
288
+ embeddingCache: a
280
289
  }) => {
281
- const a = `req-${Date.now()}`, c = i ? await E(t, i) : void 0, d = {
290
+ const i = `req-${Date.now()}`, c = a ? await b(t, a) : void 0, d = {
282
291
  type: "fieldSearch",
283
292
  layerIdForFieldsSearch: e,
284
293
  precomputedEmbedding: c,
285
- requestId: a,
286
- minScore: n,
287
- topResults: r
294
+ requestId: i,
295
+ minScore: s,
296
+ topResults: n
288
297
  };
289
298
  return await new Promise((o) => {
290
299
  const g = (u) => {
291
- if (u.data.requestId !== a)
300
+ if (u.data.requestId !== i)
292
301
  return;
293
- const p = u.data.results.map(({ layerId: m, results: h }) => ({
294
- layerId: m,
295
- results: h
302
+ const p = u.data.results.map(({ layerId: y, results: m }) => ({
303
+ layerId: y,
304
+ results: m
296
305
  }));
297
306
  o(p);
298
307
  };
299
- s.addEventListener("message", g, { once: !0 }), s.postMessage(d);
308
+ r.addEventListener("message", g, { once: !0 }), r.postMessage(d);
300
309
  });
301
310
  };
302
- function ne(t) {
311
+ function ae(t) {
303
312
  const { worker: e } = t;
304
313
  return {
305
- async searchFields({ text: s, layerIds: n, minScore: r, topResults: i, embeddingCache: a }) {
306
- return await re({
307
- combinedQuery: s,
308
- layerIds: n,
314
+ async searchFields({ text: r, layerIds: s, minScore: n, topResults: a, embeddingCache: i }) {
315
+ return await se({
316
+ combinedQuery: r,
317
+ layerIds: s,
309
318
  embeddingsWorker: e,
310
- minScore: r,
311
- topResults: i,
312
- embeddingCache: a
319
+ minScore: n,
320
+ topResults: a,
321
+ embeddingCache: i
313
322
  });
314
323
  }
315
324
  };
316
325
  }
317
- const se = (t) => {
318
- const e = C.safeParse(t);
326
+ const ie = (t) => {
327
+ const e = F.safeParse(t);
319
328
  if (!e.success)
320
329
  throw new Error("Embeddings response validation failed. Regenerate embeddings.");
321
330
  return e.data;
322
- }, ae = (t, e) => {
323
- const s = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
324
- if (e.allLayers.forEach((r) => {
325
- r instanceof q && n.set(r.id, r);
326
- }), t.length !== n.size)
331
+ }, oe = (t, e) => {
332
+ const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
333
+ if (e.allLayers.forEach((n) => {
334
+ n instanceof U && s.set(n.id, n);
335
+ }), t.length !== s.size)
327
336
  throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
328
- for (const r of t) {
329
- const i = n.get(r.id);
330
- if (!i)
337
+ for (const n of t) {
338
+ const a = s.get(n.id);
339
+ if (!a)
331
340
  throw new Error(
332
- `Layer with ID ${r.id} not found in the original map during registry restoration. Regenerate embeddings.`
341
+ `Layer with ID ${n.id} not found in the original map during registry restoration. Regenerate embeddings.`
333
342
  );
334
- if (r.fields.length !== i.fields.length)
343
+ if (n.fields.length !== a.fields.length)
335
344
  throw new Error(
336
- `Field count mismatch for layer ID ${r.id} during registry restoration. Regenerate embeddings.`
345
+ `Field count mismatch for layer ID ${n.id} during registry restoration. Regenerate embeddings.`
337
346
  );
338
- const a = {
339
- name: r.name,
340
- title: r.title,
341
- description: r.description
347
+ const i = {
348
+ name: n.name,
349
+ title: n.title,
350
+ description: n.description
342
351
  }, c = /* @__PURE__ */ new Map();
343
- for (const d of r.fields) {
344
- const o = i.fieldsIndex.get(d.name);
352
+ for (const d of n.fields) {
353
+ const o = a.fieldsIndex.get(d.name);
345
354
  if (!o)
346
355
  throw new Error(
347
- `Field with name ${d.name} not found in the original layer ${r.id} during registry restoration. Regenerate embeddings.`
356
+ `Field with name ${d.name} not found in the original layer ${n.id} during registry restoration. Regenerate embeddings.`
348
357
  );
349
358
  c.set(d.name, {
350
359
  name: d.name,
351
- alias: i.getFieldAlias(d.name) ?? d.alias,
360
+ alias: a.getFieldAlias(d.name) ?? d.alias,
352
361
  description: d.description,
353
362
  type: o.type || "unknown",
354
363
  valueType: o.valueType || "unknown",
355
- domain: i.getFieldDomain(d.name) ?? void 0
364
+ domain: a.getFieldDomain(d.name) ?? void 0
356
365
  });
357
366
  }
358
- s.set(r.id, {
359
- layerItem: a,
367
+ r.set(n.id, {
368
+ layerItem: i,
360
369
  fieldRegistry: c
361
370
  });
362
371
  }
363
- return s;
364
- }, ie = async (t) => {
372
+ return r;
373
+ }, ce = async (t) => {
365
374
  try {
366
- return (await H(t, {
375
+ return (await O(t, {
367
376
  responseType: "json"
368
377
  })).data;
369
378
  } catch (e) {
370
379
  throw new Error(`Failed to fetch data from ${t}: ${String(e)}`);
371
380
  }
372
- }, oe = async (t) => {
381
+ }, de = async (t) => {
373
382
  const e = t.map;
374
383
  if (!e?.portalItem)
375
384
  throw new Error("WebMap portal item is missing.");
376
- const { resources: s } = await e.portalItem.fetchResources(), n = s.find((a) => a.resource.path === "embeddings-v01.json");
377
- if (!n?.resource.url)
385
+ const { resources: r } = await e.portalItem.fetchResources(), s = r.find((i) => i.resource.path === "embeddings-v01.json");
386
+ if (!s?.resource.url)
378
387
  throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
379
- const r = await ie(n.resource.url);
380
- return se(r);
388
+ const n = await ce(s.resource.url);
389
+ return ie(n);
381
390
  };
382
- class v {
391
+ class x {
383
392
  constructor() {
384
- this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.threadId = "", this.agentRegistry = new X(), this.streamEpoch = 0;
393
+ this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new Z(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.streamEpoch = 0;
385
394
  }
386
395
  /**
387
396
  * Creates and returns an AI-ready Orchestrator instance.
@@ -389,21 +398,21 @@ class v {
389
398
  * @returns Ready Orchestrator.
390
399
  */
391
400
  static async init(e) {
392
- const s = new v();
401
+ const r = new x();
393
402
  try {
394
403
  if (e.view?.map) {
395
404
  await P.whenOnce(() => e.view.ready);
396
- const n = await oe(e.view), r = ae(
397
- n.layers,
405
+ const s = await de(e.view), n = oe(
406
+ s.layers,
398
407
  e.view.map
399
408
  );
400
- s.layersAndFieldsRegistry = r, s.embeddingsWorker = await O(n);
409
+ r.layersAndFieldsRegistry = n, r.embeddingsWorker = await T(s);
401
410
  }
402
- return e.agents?.forEach((n) => {
403
- s.agentRegistry.register(n);
404
- }), s.orchestratorReady = !0, s;
405
- } catch (n) {
406
- throw console.error("Orchestrator initialization failed:", n), n;
411
+ return e.agents?.forEach((s) => {
412
+ r.agentRegistry.register(s);
413
+ }), r.orchestratorReady = !0, r;
414
+ } catch (s) {
415
+ throw console.error("Orchestrator initialization failed:", s), s;
407
416
  }
408
417
  }
409
418
  /**
@@ -421,24 +430,26 @@ class v {
421
430
  throw new Error("Orchestrator has no registered agents.");
422
431
  if (++this.streamEpoch, !e.trim())
423
432
  return;
424
- this.threadId = String(Date.now()), this.graph || (this.graph = K().compile({ checkpointer: new $() }));
425
- const s = this.embeddingsWorker ? te({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? ne({ worker: this.embeddingsWorker }) : void 0, r = /* @__PURE__ */ new Map(), a = {
433
+ const r = crypto.randomUUID();
434
+ this.activeRunId = r, this.activeAbortController = new AbortController(), this.graph || (this.graph = Y().compile({ checkpointer: new j() }));
435
+ const s = this.embeddingsWorker ? ne({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? ae({ worker: this.embeddingsWorker }) : void 0, a = /* @__PURE__ */ new Map(), c = {
426
436
  version: "v2",
427
437
  streamMode: "custom",
428
438
  configurable: {
429
439
  // eslint-disable-next-line @typescript-eslint/naming-convention
430
- thread_id: this.threadId,
440
+ thread_id: r,
441
+ abortSignal: this.activeAbortController.signal,
431
442
  hitlResponse: null,
432
443
  services: {
433
444
  layerSearch: s,
434
445
  fieldSearch: n,
435
446
  layersAndFieldsRegistry: this.layersAndFieldsRegistry,
436
447
  agentRegistry: this.agentRegistry,
437
- embeddingCache: r
448
+ embeddingCache: a
438
449
  }
439
450
  },
440
451
  subgraphs: !0
441
- }, c = this.graph?.streamEvents(
452
+ }, d = this.graph?.streamEvents(
442
453
  {
443
454
  agentExecutionContext: {
444
455
  userRequest: e,
@@ -447,36 +458,54 @@ class v {
447
458
  sharedState: this.sharedState
448
459
  }
449
460
  },
450
- a
451
- ), d = ++this.streamEpoch;
452
- for (yield* this.pipeStream(c, d); ; ) {
453
- const m = (await this.graph.getState(a, { subgraphs: !0 })).tasks.find((h) => h.interrupts.length > 0)?.interrupts[0]?.value;
461
+ c
462
+ ), o = ++this.streamEpoch;
463
+ if (yield* this.pipeStream(d, o, r), this.isRunCancelled(r)) {
464
+ yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
465
+ return;
466
+ }
467
+ for (; ; ) {
468
+ if (this.isRunCancelled(r)) {
469
+ yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
470
+ return;
471
+ }
472
+ const m = (await this.graph.getState(c, { subgraphs: !0 })).tasks.find((h) => h.interrupts.length > 0)?.interrupts[0]?.value;
454
473
  if (!m)
455
474
  break;
456
- this.currentInterrupt = m, this.interruptHandler = new Y(this.graph, a), yield { runId: this.threadId, timestamp: Date.now(), type: "interrupt", interrupt: m };
475
+ this.currentInterrupt = m, this.interruptHandler = new ee(this.graph, c), yield { runId: r, timestamp: Date.now(), type: "interrupt", interrupt: m };
457
476
  try {
458
- const h = await this.interruptHandler.waitForUser(), x = ++this.streamEpoch;
459
- yield* this.pipeStream(h, x);
477
+ const h = await this.interruptHandler.waitForUser(), S = ++this.streamEpoch;
478
+ yield* this.pipeStream(h, S, r);
460
479
  } catch (h) {
480
+ if (this.isRunCancelled(r)) {
481
+ yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
482
+ return;
483
+ }
461
484
  if (h) {
462
485
  yield {
463
- runId: this.threadId,
486
+ runId: r,
464
487
  timestamp: Date.now(),
465
488
  type: "error",
466
489
  error: { message: h?.message }
467
490
  };
468
491
  return;
469
492
  }
470
- yield { runId: this.threadId, timestamp: Date.now(), type: "cancelled" };
471
- return;
472
493
  }
473
494
  }
474
- const g = (await this.graph.getState(a, { subgraphs: !0 })).values;
475
- this.chatHistory = g.agentExecutionContext.messages.length ? g.agentExecutionContext.messages : this.chatHistory, this.priorSteps = g.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = g.agentExecutionContext.sharedState ?? {}, yield {
476
- runId: this.threadId,
495
+ if (this.isRunCancelled(r)) {
496
+ yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
497
+ return;
498
+ }
499
+ const u = (await this.graph.getState(c, { subgraphs: !0 })).values;
500
+ if (this.isRunCancelled(r)) {
501
+ yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
502
+ return;
503
+ }
504
+ this.chatHistory = u.agentExecutionContext.messages.length ? u.agentExecutionContext.messages : this.chatHistory, this.priorSteps = u.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = u.agentExecutionContext.sharedState ?? {}, yield {
505
+ runId: r,
477
506
  timestamp: Date.now(),
478
507
  type: "completed",
479
- result: { content: g.finalOutputMessage }
508
+ result: { content: u.finalOutputMessage }
480
509
  };
481
510
  }
482
511
  /**
@@ -500,20 +529,31 @@ class v {
500
529
  cancelInterrupt() {
501
530
  this.interruptHandler && this.interruptHandler.cancel();
502
531
  }
503
- async *pipeStream(e, s) {
532
+ /**
533
+ * Cancels the active run.
534
+ *
535
+ * - Aborts in-flight work for consumers that honor AbortSignal.
536
+ * - Invalidates active stream iterators via epoch bump.
537
+ * - Unblocks any pending HITL wait.
538
+ */
539
+ cancel() {
540
+ this.activeRunId && (this.cancelledRunIds.add(this.activeRunId), this.activeAbortController?.abort(), ++this.streamEpoch, this.interruptHandler?.cancel());
541
+ }
542
+ async *pipeStream(e, r, s) {
504
543
  for await (const n of e) {
505
- if (s !== this.streamEpoch) {
506
- console.log("Stale stream detected, aborting.");
544
+ if (this.isRunCancelled(s) || r !== this.streamEpoch)
507
545
  break;
508
- }
509
- n.event === "on_custom_event" && n.name === "trace_message" ? yield { runId: this.threadId, timestamp: Date.now(), type: "trace", data: n.data } : n.name === "graph_ux_suggestion" && (yield {
510
- runId: this.threadId,
546
+ 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 {
547
+ runId: s,
511
548
  timestamp: Date.now(),
512
549
  type: "ux-suggestion",
513
550
  suggestion: n.data
514
551
  });
515
552
  }
516
553
  }
554
+ isRunCancelled(e) {
555
+ return this.cancelledRunIds.has(e);
556
+ }
517
557
  /**
518
558
  * Disposes this instance by terminating the embeddings worker
519
559
  * and cleaning up all related resources.
@@ -523,6 +563,6 @@ class v {
523
563
  }
524
564
  }
525
565
  export {
526
- v as O,
527
- Z as g
566
+ x as O,
567
+ te as g
528
568
  };