@arcgis/ai-components 5.2.0-next.65 → 5.2.0-next.67

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 (34) hide show
  1. package/dist/cdn/{GLOALVJR.js → 563R6SX5.js} +1 -1
  2. package/dist/cdn/B6CJG5UH.js +66 -0
  3. package/dist/cdn/{3YCSUTGV.js → CXW5URTF.js} +1 -1
  4. package/dist/cdn/{L4SS54EZ.js → DTIVDIDY.js} +1 -1
  5. package/dist/cdn/{AYMUK2MC.js → E5ZKBC24.js} +2 -2
  6. package/dist/cdn/{7NP7WGR5.js → EKZTQFYI.js} +1 -1
  7. package/dist/cdn/{FVDFPK3V.js → GP6NDTUE.js} +1 -1
  8. package/dist/cdn/{LUJCH5V7.js → HTBMJ557.js} +1 -1
  9. package/dist/cdn/{THXUE6R4.js → JMIXLFSZ.js} +1 -1
  10. package/dist/cdn/{BI3LK5D3.js → KJAWV5SK.js} +1 -1
  11. package/dist/cdn/KQHLOYKL.js +3 -0
  12. package/dist/cdn/{QBINZNXI.js → KX43Z26W.js} +1 -1
  13. package/dist/cdn/{QZLE7B6X.js → MBIIANTX.js} +1 -1
  14. package/dist/cdn/{FC45FF2D.js → MW5S2XCB.js} +1 -1
  15. package/dist/cdn/{275NKWUE.js → PUFTYLJ2.js} +1 -1
  16. package/dist/cdn/{AHLLB5QW.js → QXGXNOTJ.js} +1 -1
  17. package/dist/cdn/{OY2P2O47.js → ST5FQYT7.js} +32 -32
  18. package/dist/cdn/{WHOZT5H5.js → SXHH575T.js} +17 -17
  19. package/dist/cdn/{RAAV47KU.js → UAKSN7EQ.js} +1 -1
  20. package/dist/cdn/{NSER3L4A.js → WVPU4QOO.js} +1 -1
  21. package/dist/cdn/{242OOJML.js → Y2JULDNA.js} +1 -1
  22. package/dist/cdn/agent-utils/index.js +1 -1
  23. package/dist/cdn/index.js +1 -1
  24. package/dist/chunks/adapter.js +2 -2
  25. package/dist/chunks/generateLayerDescriptions.js +200 -189
  26. package/dist/chunks/navigationGraph.js +21 -20
  27. package/dist/chunks/orchestrator.js +221 -193
  28. package/dist/docs/api.json +1 -1
  29. package/dist/docs/docs.json +1 -1
  30. package/dist/docs/web-types.json +1 -1
  31. package/dist/utils/index.d.ts +1 -0
  32. package/package.json +6 -6
  33. package/dist/cdn/FNPLHH4E.js +0 -3
  34. package/dist/cdn/NQROZZHC.js +0 -65
@@ -1,81 +1,81 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import R from "@arcgis/core/identity/IdentityManager.js";
2
+ import A from "@arcgis/core/identity/IdentityManager.js";
3
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 { generateGuid as q } from "@arcgis/toolkit/string";
7
- import { HumanMessage as H, AIMessage as P } from "@langchain/core/messages";
4
+ import { n as k, o as b, D as M, p as D, q as F, W as $ } from "./generateLayerDescriptions.js";
5
+ import { isGraphInterrupt as L, StateGraph as W, START as q, END as j, MemorySaver as H } from "@langchain/langgraph/web";
6
+ import { generateGuid as P } from "@arcgis/toolkit/string";
7
+ import { HumanMessage as O, AIMessage as T } from "@langchain/core/messages";
8
8
  import { s as l } from "./index.js";
9
- import * as O from "@arcgis/core/core/reactiveUtils.js";
10
- import T from "@arcgis/core/layers/FeatureLayer.js";
11
- import U from "@arcgis/core/request.js";
12
- const G = async (t) => {
13
- const e = await N(), r = await I("default"), s = C.getDefault(), o = (await R.getCredential(`${s.url}/sharing`)).token, i = {
9
+ import * as U from "@arcgis/core/core/reactiveUtils.js";
10
+ import N from "@arcgis/core/layers/FeatureLayer.js";
11
+ import G from "@arcgis/core/request.js";
12
+ const _ = async (t) => {
13
+ const e = await V(), n = await k("default"), s = C.getDefault(), a = (await A.getCredential(`${s.url}/sharing`)).token, i = {
14
14
  type: "generateEmbeddings",
15
15
  webmapEmbeddings: t,
16
- auth: { apiUrl: r, token: o }
16
+ auth: { apiUrl: n, token: a }
17
17
  };
18
18
  return e.postMessage(i), await new Promise((c, d) => {
19
- const a = (u) => {
20
- u.data === "completed" && (e.removeEventListener("message", a), c());
19
+ const o = (u) => {
20
+ u.data === "completed" && (e.removeEventListener("message", o), c());
21
21
  }, g = (u) => {
22
- e.removeEventListener("message", a), d(u instanceof Error ? u : new Error("Embeddings worker error"));
22
+ e.removeEventListener("message", o), d(u instanceof Error ? u : new Error("Embeddings worker error"));
23
23
  };
24
- e.addEventListener("message", a), e.addEventListener("error", g, { once: !0 });
24
+ e.addEventListener("message", o), e.addEventListener("error", g, { once: !0 });
25
25
  }), e;
26
- }, N = async () => {
26
+ }, V = async () => {
27
27
  {
28
28
  const t = (await import("./embeddings.worker.js")).default;
29
29
  return new t();
30
30
  }
31
- }, _ = (t) => {
31
+ }, z = (t) => {
32
32
  t.currentIntent = "none";
33
- }, V = async (t, e) => {
34
- const r = v(e);
33
+ }, Q = async (t, e) => {
34
+ const n = b(e);
35
35
  if (t.agentExecutionContext.userRequest) {
36
- const n = new H(t.agentExecutionContext.userRequest.trim());
37
- t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], _(t);
36
+ const r = new O(t.agentExecutionContext.userRequest.trim());
37
+ t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, r], z(t);
38
38
  }
39
- const s = r?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
39
+ const s = n?.services.agentRegistry.list().map((r) => r.agent.id) ?? [];
40
40
  return await l({ text: `Available agents: ${[...s].join(", ")}` }, e), await l({ text: "Analyzing user input" }, e), t;
41
- }, z = async (t, e) => (await l({ text: "Exiting..." }, e), t), w = (t) => typeof t == "object" && t !== null && !Array.isArray(t), Q = (t, e) => {
42
- if (!w(t)) {
41
+ }, B = async (t, e) => (await l({ text: "Exiting..." }, e), t), f = (t) => typeof t == "object" && t !== null && !Array.isArray(t), J = (t, e) => {
42
+ if (!f(t)) {
43
43
  t !== void 0 && console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`);
44
44
  return;
45
45
  }
46
- const r = {};
47
- for (const [s, n] of Object.entries(t)) {
48
- if (!w(n) || !("value" in n)) {
46
+ const n = {};
47
+ for (const [s, r] of Object.entries(t)) {
48
+ if (!f(r) || !("value" in r)) {
49
49
  console.warn(
50
50
  `Agent "${e}" returned invalid sharedStatePatch entry for key "${s}". Ignoring that entry.`
51
51
  );
52
52
  continue;
53
53
  }
54
- r[s] = { value: n.value };
54
+ n[s] = { value: r.value };
55
55
  }
56
- return r;
57
- }, B = (t) => {
58
- const { previousSharedState: e, patch: r, agentId: s } = t;
59
- if (!r)
56
+ return n;
57
+ }, K = (t) => {
58
+ const { previousSharedState: e, patch: n, agentId: s } = t;
59
+ if (!n)
60
60
  return e;
61
- const n = Date.now(), o = {
61
+ const r = Date.now(), a = {
62
62
  ...e
63
63
  };
64
- for (const [i, c] of Object.entries(r))
65
- c?.value !== void 0 && (o[i] = {
64
+ for (const [i, c] of Object.entries(n))
65
+ c?.value !== void 0 && (a[i] = {
66
66
  value: c.value,
67
67
  meta: {
68
68
  updatedByAgentId: s,
69
- updatedAt: n
69
+ updatedAt: r
70
70
  }
71
71
  });
72
- return o;
73
- }, f = (t) => {
72
+ return a;
73
+ }, E = (t) => {
74
74
  if (typeof t != "string")
75
75
  return;
76
76
  const e = t.trim();
77
77
  return e || void 0;
78
- }, J = (t) => {
78
+ }, X = (t) => {
79
79
  switch (t) {
80
80
  case "failed":
81
81
  return "Agent failed without a summary.";
@@ -86,39 +86,39 @@ const G = async (t) => {
86
86
  default:
87
87
  return "Agent completed without a summary.";
88
88
  }
89
- }, K = (t, e) => {
90
- const r = f(e?.outputMessage), s = f(e?.summary), n = e?.status, o = n === "success" || n === "failed" ? n : "unknown";
91
- o === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
92
- const i = Q(e?.sharedStatePatch, t);
89
+ }, Y = (t, e) => {
90
+ const n = E(e?.outputMessage), s = E(e?.summary), r = e?.status, a = r === "success" || r === "failed" ? r : "unknown";
91
+ a === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
92
+ const i = J(e?.sharedStatePatch, t);
93
93
  return {
94
- outputMessage: r,
95
- summary: s ?? r ?? J(o),
96
- status: o,
94
+ outputMessage: n,
95
+ summary: s ?? n ?? X(a),
96
+ status: a,
97
97
  sharedStatePatch: i
98
98
  };
99
- }, E = 4e3, X = async (t, e) => {
100
- const r = v(e);
99
+ }, x = 4e3, Z = async (t, e) => {
100
+ const n = b(e);
101
101
  if (e?.signal?.aborted)
102
102
  return await l({ text: "Run cancelled; skipping agent execution" }, e), {
103
103
  ...t,
104
104
  currentIntent: "none",
105
105
  requiresFollowUp: !1
106
106
  };
107
- const { agentRegistry: s } = r?.services ?? {}, n = s?.get(t.currentIntent);
108
- if (!n)
107
+ const { agentRegistry: s } = n?.services ?? {}, r = s?.get(t.currentIntent);
108
+ if (!r)
109
109
  return console.warn(`No agent found for intent: ${t.currentIntent}`), t;
110
- await l({ text: `Executing registered agent: ${n.agent.name}` }, e);
111
- const o = {
110
+ await l({ text: `Executing registered agent: ${r.agent.name}` }, e);
111
+ const a = {
112
112
  ...e ?? {},
113
113
  configurable: {
114
- ...r ?? {},
115
- agentId: n.agent.id,
116
- context: n.getContext ? await n.getContext() : void 0
114
+ ...n ?? {},
115
+ agentId: r.agent.id,
116
+ context: r.getContext ? await r.getContext() : void 0
117
117
  }
118
118
  };
119
119
  let i;
120
120
  try {
121
- const a = await n.agent.createGraph().compile().invoke(
121
+ const o = await r.agent.createGraph().compile().invoke(
122
122
  {
123
123
  agentExecutionContext: {
124
124
  ...t.agentExecutionContext,
@@ -129,14 +129,14 @@ const G = async (t) => {
129
129
  sharedState: structuredClone(t.agentExecutionContext.sharedState ?? {})
130
130
  }
131
131
  },
132
- o
132
+ a
133
133
  );
134
- i = K(n.agent.name, a), await l({ text: `Finished executing registered agent: ${n.agent.name}` }, e);
135
- } catch (a) {
136
- if (D(a) || e?.signal?.aborted || a instanceof Error && a.name === "AbortError")
137
- throw a;
138
- const g = a instanceof Error ? a.message : String(a);
139
- console.error(`Agent "${n.agent.name}" failed:`, a), await l({ text: `Registered agent failed: ${n.agent.name}. ${g}` }, e), i = {
134
+ i = Y(r.agent.name, o), await l({ text: `Finished executing registered agent: ${r.agent.name}` }, e);
135
+ } catch (o) {
136
+ if (L(o) || e?.signal?.aborted || o instanceof Error && o.name === "AbortError")
137
+ throw o;
138
+ const g = o instanceof Error ? o.message : String(o);
139
+ console.error(`Agent "${r.agent.name}" failed:`, o), await l({ text: `Registered agent failed: ${r.agent.name}. ${g}` }, e), i = {
140
140
  status: "failed",
141
141
  outputMessage: `Agent execution failed: ${g}`,
142
142
  summary: `Agent execution failed: ${g}`
@@ -144,14 +144,14 @@ const G = async (t) => {
144
144
  }
145
145
  const c = i.outputMessage, d = [...t.agentExecutionContext.messages];
146
146
  if (c) {
147
- const a = c.length > E ? `${c.slice(0, E - 14)}
147
+ const o = c.length > x ? `${c.slice(0, x - 14)}
148
148
  [truncated]` : c;
149
- d.push(new P(a));
149
+ d.push(new T(o));
150
150
  }
151
151
  return {
152
152
  ...t,
153
153
  stepCount: t.stepCount + 1,
154
- lastExecutedAgent: n.agent.id,
154
+ lastExecutedAgent: r.agent.id,
155
155
  requiresFollowUp: i.status === "failed" ? !0 : t.requiresFollowUp,
156
156
  finalOutputMessage: c ?? "",
157
157
  agentExecutionContext: {
@@ -160,32 +160,41 @@ const G = async (t) => {
160
160
  priorSteps: [
161
161
  ...t.agentExecutionContext.priorSteps ?? [],
162
162
  {
163
- agentId: n.agent.id,
163
+ agentId: r.agent.id,
164
164
  assignedTask: t.agentExecutionContext.assignedTask,
165
165
  summary: i?.summary || "No summary provided.",
166
166
  status: i?.status || "unknown"
167
167
  }
168
168
  ],
169
- sharedState: B({
169
+ sharedState: K({
170
170
  previousSharedState: t.agentExecutionContext.sharedState,
171
171
  patch: i.sharedStatePatch,
172
- agentId: n.agent.id
172
+ agentId: r.agent.id
173
173
  })
174
174
  }
175
175
  };
176
- }, Y = 3, Z = () => new L(k).addNode("ingestInput", V).addNode("intentLLM", A).addNode("executeRegisteredAgent", X).addNode("exit", z).addEdge(W, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges(
177
- "executeRegisteredAgent",
178
- (e) => e.stepCount >= Y || !e.requiresFollowUp ? "exit" : "intentLLM"
179
- ).addEdge("exit", $);
180
- class ee {
176
+ }, ee = async (t, e) => {
177
+ if (t.routing.mode !== "direct")
178
+ throw new Error("Direct agent assignment requires direct routing.");
179
+ return await l({ text: `Doing a direct route to agent: ${t.routing.agentId}` }, e), {
180
+ ...t,
181
+ currentIntent: t.routing.agentId,
182
+ requiresFollowUp: !1,
183
+ agentExecutionContext: {
184
+ ...t.agentExecutionContext,
185
+ assignedTask: t.agentExecutionContext.userRequest
186
+ }
187
+ };
188
+ }, te = 3, re = (t) => t.routing.mode === "direct" ? "assignDirectAgent" : "intentLLM", ne = (t) => t.routing.mode === "direct" || t.stepCount >= te || !t.requiresFollowUp ? "exit" : "intentLLM", se = () => new W(M).addNode("ingestInput", Q).addNode("assignDirectAgent", ee).addNode("intentLLM", D).addNode("executeRegisteredAgent", Z).addNode("exit", B).addEdge(q, "ingestInput").addConditionalEdges("ingestInput", re).addEdge("assignDirectAgent", "executeRegisteredAgent").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges("executeRegisteredAgent", ne).addEdge("exit", j);
189
+ class v {
181
190
  constructor() {
182
191
  this.agentRegistry = /* @__PURE__ */ new Map();
183
192
  }
184
193
  register(e) {
185
- const { agent: r } = e;
186
- if (this.agentRegistry.has(r.id))
187
- throw new Error(`Duplicate agent id: ${r.id}`);
188
- this.agentRegistry.set(r.id, e);
194
+ const { agent: n } = e;
195
+ if (this.agentRegistry.has(n.id))
196
+ throw new Error(`Duplicate agent id: ${n.id}`);
197
+ this.agentRegistry.set(n.id, e);
189
198
  }
190
199
  get(e) {
191
200
  return this.agentRegistry.get(e);
@@ -194,31 +203,31 @@ class ee {
194
203
  return [...this.agentRegistry.values()];
195
204
  }
196
205
  }
197
- class te {
206
+ class ae {
198
207
  /**
199
208
  * Create a new InterruptHandler tied to a specific compiled graph and config.
200
209
  */
201
- constructor(e, r) {
202
- this.graph = e, this.config = { ...r };
210
+ constructor(e, n) {
211
+ this.graph = e, this.config = { ...n };
203
212
  }
204
213
  /**
205
214
  * Returns a promise that resolves when the user provides a HITL response.
206
215
  */
207
216
  async waitForUser() {
208
- return await new Promise((e, r) => {
209
- this.resolveWait = e, this.rejectWait = r;
217
+ return await new Promise((e, n) => {
218
+ this.resolveWait = e, this.rejectWait = n;
210
219
  });
211
220
  }
212
221
  /**
213
222
  * Resume graph execution after the UI responds to an interrupt.
214
223
  */
215
- handle(e, r) {
224
+ handle(e, n) {
216
225
  try {
217
226
  const s = {
218
227
  agentId: e.agentId,
219
228
  id: e.id,
220
- payload: r
221
- }, n = this.graph.streamEvents(null, {
229
+ payload: n
230
+ }, r = this.graph.streamEvents(null, {
222
231
  ...this.config,
223
232
  configurable: {
224
233
  ...this.config.configurable,
@@ -227,7 +236,7 @@ class te {
227
236
  subgraphs: !0,
228
237
  version: "v2"
229
238
  });
230
- this.resolveWait?.(n);
239
+ this.resolveWait?.(r);
231
240
  } catch (s) {
232
241
  this.rejectWait?.(s);
233
242
  } finally {
@@ -241,157 +250,157 @@ class te {
241
250
  this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
242
251
  }
243
252
  }
244
- const re = async (t) => {
253
+ const ie = async (t) => {
245
254
  try {
246
- return await (await M()).embedDocuments(t);
255
+ return await (await F()).embedDocuments(t);
247
256
  } catch (e) {
248
257
  throw console.error("Failed to generate embeddings:", e), e;
249
258
  }
250
- }, x = async (t, e) => {
251
- const r = e.get(t);
252
- if (r)
253
- return r;
254
- const s = await re([t]);
259
+ }, S = async (t, e) => {
260
+ const n = e.get(t);
261
+ if (n)
262
+ return n;
263
+ const s = await ie([t]);
255
264
  return e.set(t, s[0]), s[0];
256
265
  };
257
- async function ne(t, e, r, s) {
258
- const n = `req-${Date.now()}`, i = {
266
+ async function oe(t, e, n, s) {
267
+ const r = `req-${Date.now()}`, i = {
259
268
  type: "layerSearch",
260
- precomputedEmbedding: s ? await x(t, s) : void 0,
261
- requestId: n,
262
- minScore: r
269
+ precomputedEmbedding: s ? await S(t, s) : void 0,
270
+ requestId: r,
271
+ minScore: n
263
272
  };
264
273
  return await new Promise((c) => {
265
- const d = (a) => {
266
- a.data.requestId === n && c(a.data.results);
274
+ const d = (o) => {
275
+ o.data.requestId === r && c(o.data.results);
267
276
  };
268
277
  e.addEventListener("message", d, { once: !0 }), e.postMessage(i);
269
278
  });
270
279
  }
271
- function se(t) {
280
+ function ce(t) {
272
281
  const { worker: e } = t;
273
282
  return {
274
283
  async searchLayers({
275
- text: r,
284
+ text: n,
276
285
  minScore: s,
277
- embeddingCache: n
286
+ embeddingCache: r
278
287
  }) {
279
- return await ne(r, e, s, n);
288
+ return await oe(n, e, s, r);
280
289
  }
281
290
  };
282
291
  }
283
- const ae = async ({
292
+ const de = async ({
284
293
  combinedQuery: t,
285
294
  layerIds: e,
286
- embeddingsWorker: r,
295
+ embeddingsWorker: n,
287
296
  minScore: s,
288
- topResults: n,
289
- embeddingCache: o
297
+ topResults: r,
298
+ embeddingCache: a
290
299
  }) => {
291
- const i = `req-${Date.now()}`, c = o ? await x(t, o) : void 0, d = {
300
+ const i = `req-${Date.now()}`, c = a ? await S(t, a) : void 0, d = {
292
301
  type: "fieldSearch",
293
302
  layerIdForFieldsSearch: e,
294
303
  precomputedEmbedding: c,
295
304
  requestId: i,
296
305
  minScore: s,
297
- topResults: n
306
+ topResults: r
298
307
  };
299
- return await new Promise((a) => {
308
+ return await new Promise((o) => {
300
309
  const g = (u) => {
301
310
  if (u.data.requestId !== i)
302
311
  return;
303
- const p = u.data.results.map(({ layerId: y, results: m }) => ({
312
+ const p = u.data.results.map(({ layerId: y, results: h }) => ({
304
313
  layerId: y,
305
- results: m
314
+ results: h
306
315
  }));
307
- a(p);
316
+ o(p);
308
317
  };
309
- r.addEventListener("message", g, { once: !0 }), r.postMessage(d);
318
+ n.addEventListener("message", g, { once: !0 }), n.postMessage(d);
310
319
  });
311
320
  };
312
- function ie(t) {
321
+ function ge(t) {
313
322
  const { worker: e } = t;
314
323
  return {
315
- async searchFields({ text: r, layerIds: s, minScore: n, topResults: o, embeddingCache: i }) {
316
- return await ae({
317
- combinedQuery: r,
324
+ async searchFields({ text: n, layerIds: s, minScore: r, topResults: a, embeddingCache: i }) {
325
+ return await de({
326
+ combinedQuery: n,
318
327
  layerIds: s,
319
328
  embeddingsWorker: e,
320
- minScore: n,
321
- topResults: o,
329
+ minScore: r,
330
+ topResults: a,
322
331
  embeddingCache: i
323
332
  });
324
333
  }
325
334
  };
326
335
  }
327
- const oe = (t) => {
328
- const e = F.safeParse(t);
336
+ const ue = (t) => {
337
+ const e = $.safeParse(t);
329
338
  if (!e.success)
330
339
  throw new Error("Embeddings response validation failed. Regenerate embeddings.");
331
340
  return e.data;
332
- }, ce = (t, e) => {
333
- const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
334
- if (e.allLayers.forEach((n) => {
335
- n instanceof T && s.set(n.id, n);
341
+ }, le = (t, e) => {
342
+ const n = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
343
+ if (e.allLayers.forEach((r) => {
344
+ r instanceof N && s.set(r.id, r);
336
345
  }), t.length !== s.size)
337
346
  throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
338
- for (const n of t) {
339
- const o = s.get(n.id);
340
- if (!o)
347
+ for (const r of t) {
348
+ const a = s.get(r.id);
349
+ if (!a)
341
350
  throw new Error(
342
- `Layer with ID ${n.id} not found in the original map during registry restoration. Regenerate embeddings.`
351
+ `Layer with ID ${r.id} not found in the original map during registry restoration. Regenerate embeddings.`
343
352
  );
344
- if (n.fields.length !== o.fields.length)
353
+ if (r.fields.length !== a.fields.length)
345
354
  throw new Error(
346
- `Field count mismatch for layer ID ${n.id} during registry restoration. Regenerate embeddings.`
355
+ `Field count mismatch for layer ID ${r.id} during registry restoration. Regenerate embeddings.`
347
356
  );
348
357
  const i = {
349
- name: n.name,
350
- title: n.title,
351
- description: n.description
358
+ name: r.name,
359
+ title: r.title,
360
+ description: r.description
352
361
  }, c = /* @__PURE__ */ new Map();
353
- for (const d of n.fields) {
354
- const a = o.fieldsIndex.get(d.name);
355
- if (!a)
362
+ for (const d of r.fields) {
363
+ const o = a.fieldsIndex.get(d.name);
364
+ if (!o)
356
365
  throw new Error(
357
- `Field with name ${d.name} not found in the original layer ${n.id} during registry restoration. Regenerate embeddings.`
366
+ `Field with name ${d.name} not found in the original layer ${r.id} during registry restoration. Regenerate embeddings.`
358
367
  );
359
368
  c.set(d.name, {
360
369
  name: d.name,
361
- alias: o.getFieldAlias(d.name) ?? d.alias,
370
+ alias: a.getFieldAlias(d.name) ?? d.alias,
362
371
  description: d.description,
363
- type: a.type || "unknown",
364
- valueType: a.valueType || "unknown",
365
- domain: o.getFieldDomain(d.name) ?? void 0
372
+ type: o.type || "unknown",
373
+ valueType: o.valueType || "unknown",
374
+ domain: a.getFieldDomain(d.name) ?? void 0
366
375
  });
367
376
  }
368
- r.set(n.id, {
377
+ n.set(r.id, {
369
378
  layerItem: i,
370
379
  fieldRegistry: c
371
380
  });
372
381
  }
373
- return r;
374
- }, de = async (t) => {
382
+ return n;
383
+ }, he = async (t) => {
375
384
  try {
376
- return (await U(t, {
385
+ return (await G(t, {
377
386
  responseType: "json"
378
387
  })).data;
379
388
  } catch (e) {
380
389
  throw new Error(`Failed to fetch data from ${t}: ${String(e)}`);
381
390
  }
382
- }, ue = async (t) => {
391
+ }, me = async (t) => {
383
392
  const e = t.map;
384
393
  if (!e?.portalItem)
385
394
  throw new Error("WebMap portal item is missing.");
386
- const { resources: r } = await e.portalItem.fetchResources(), s = r.find((i) => i.resource.path === "embeddings-v01.json");
395
+ const { resources: n } = await e.portalItem.fetchResources(), s = n.find((i) => i.resource.path === "embeddings-v01.json");
387
396
  if (!s?.resource.url)
388
397
  throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
389
- const n = await de(s.resource.url);
390
- return oe(n);
398
+ const r = await he(s.resource.url);
399
+ return ue(r);
391
400
  };
392
- class b {
401
+ class R {
393
402
  constructor() {
394
- this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new ee(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.streamEpoch = 0;
403
+ this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new v(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.streamEpoch = 0;
395
404
  }
396
405
  /**
397
406
  * Creates and returns an AI-ready Orchestrator instance.
@@ -399,19 +408,19 @@ class b {
399
408
  * @returns Ready Orchestrator.
400
409
  */
401
410
  static async init(e) {
402
- const r = new b();
411
+ const n = new R();
403
412
  try {
404
413
  if (e.view?.map) {
405
- await O.whenOnce(() => e.view.ready);
406
- const s = await ue(e.view), n = ce(
414
+ await U.whenOnce(() => e.view.ready);
415
+ const s = await me(e.view), r = le(
407
416
  s.layers,
408
417
  e.view.map
409
418
  );
410
- r.layersAndFieldsRegistry = n, r.embeddingsWorker = await G(s);
419
+ n.layersAndFieldsRegistry = r, n.embeddingsWorker = await _(s);
411
420
  }
412
421
  return e.agents?.forEach((s) => {
413
- r.agentRegistry.register(s);
414
- }), r.orchestratorReady = !0, r;
422
+ n.agentRegistry.register(s);
423
+ }), n.orchestratorReady = !0, n;
415
424
  } catch (s) {
416
425
  throw console.error("Orchestrator initialization failed:", s), s;
417
426
  }
@@ -423,35 +432,41 @@ class b {
423
432
  * - `interrupt`: HITL required, wait for `resumeInterrupt()`
424
433
  * - `completed`: final result with chat history + layer styling
425
434
  * - `cancelled`: user aborted the run
435
+ * @param userInput User request to process.
436
+ * @param options Agent selection and routing behavior for this run.
426
437
  */
427
- async *ask(e) {
438
+ async *ask(e, n = {}) {
428
439
  if (!this.orchestratorReady)
429
440
  throw new Error("Orchestrator is not ready yet.");
430
441
  if (!this.agentRegistry.list().length)
431
442
  throw new Error("Orchestrator has no registered agents.");
443
+ const s = this.createRequestAgentRegistry(n);
444
+ if (!s.list().length)
445
+ throw new Error("Orchestrator has no agents selected for this request.");
432
446
  if (++this.streamEpoch, !e.trim())
433
447
  return;
434
- const r = q();
435
- this.activeRunId = r, this.activeAbortController = new AbortController(), this.graph || (this.graph = Z().compile({ checkpointer: new j() }));
436
- const s = this.embeddingsWorker ? se({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? ie({ worker: this.embeddingsWorker }) : void 0, o = /* @__PURE__ */ new Map(), i = {
448
+ const r = P();
449
+ this.activeRunId = r, this.activeAbortController = new AbortController(), this.graph || (this.graph = se().compile({ checkpointer: new H() }));
450
+ const a = this.embeddingsWorker ? ce({ worker: this.embeddingsWorker }) : void 0, i = this.embeddingsWorker ? ge({ worker: this.embeddingsWorker }) : void 0, c = /* @__PURE__ */ new Map(), d = n.routing === "direct" ? { mode: "direct", agentId: n.agentId } : { mode: "auto" }, o = {
437
451
  // eslint-disable-next-line @typescript-eslint/naming-convention
438
452
  thread_id: r,
439
453
  hitlResponse: null,
440
454
  services: {
441
- layerSearch: s,
442
- fieldSearch: n,
455
+ layerSearch: a,
456
+ fieldSearch: i,
443
457
  layersAndFieldsRegistry: this.layersAndFieldsRegistry,
444
- agentRegistry: this.agentRegistry,
445
- embeddingCache: o
458
+ agentRegistry: s,
459
+ embeddingCache: c
446
460
  }
447
- }, c = {
461
+ }, g = {
448
462
  version: "v2",
449
463
  streamMode: "custom",
450
464
  signal: this.activeAbortController.signal,
451
- configurable: i,
465
+ configurable: o,
452
466
  subgraphs: !0
453
- }, d = this.graph?.streamEvents(
467
+ }, u = this.graph?.streamEvents(
454
468
  {
469
+ routing: d,
455
470
  agentExecutionContext: {
456
471
  userRequest: e,
457
472
  messages: this.chatHistory,
@@ -459,9 +474,9 @@ class b {
459
474
  sharedState: this.sharedState
460
475
  }
461
476
  },
462
- c
463
- ), a = ++this.streamEpoch;
464
- if (yield* this.pipeStream(d, a, r), this.isRunCancelled(r)) {
477
+ g
478
+ ), p = ++this.streamEpoch;
479
+ if (yield* this.pipeStream(u, p, r), this.isRunCancelled(r)) {
465
480
  yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
466
481
  return;
467
482
  }
@@ -470,24 +485,24 @@ class b {
470
485
  yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
471
486
  return;
472
487
  }
473
- const m = (await this.graph.getState(c, { subgraphs: !0 })).tasks.find((h) => h.interrupts.length > 0)?.interrupts[0]?.value;
474
- if (!m)
488
+ const w = (await this.graph.getState(g, { subgraphs: !0 })).tasks.find((m) => m.interrupts.length > 0)?.interrupts[0]?.value;
489
+ if (!w)
475
490
  break;
476
- this.currentInterrupt = m, this.interruptHandler = new te(this.graph, c), yield { runId: r, timestamp: Date.now(), type: "interrupt", interrupt: m };
491
+ this.currentInterrupt = w, this.interruptHandler = new ae(this.graph, g), yield { runId: r, timestamp: Date.now(), type: "interrupt", interrupt: w };
477
492
  try {
478
- const h = await this.interruptHandler.waitForUser(), S = ++this.streamEpoch;
479
- yield* this.pipeStream(h, S, r);
480
- } catch (h) {
493
+ const m = await this.interruptHandler.waitForUser(), I = ++this.streamEpoch;
494
+ yield* this.pipeStream(m, I, r);
495
+ } catch (m) {
481
496
  if (this.isRunCancelled(r)) {
482
497
  yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
483
498
  return;
484
499
  }
485
- if (h) {
500
+ if (m) {
486
501
  yield {
487
502
  runId: r,
488
503
  timestamp: Date.now(),
489
504
  type: "error",
490
- error: { message: h?.message }
505
+ error: { message: m?.message }
491
506
  };
492
507
  return;
493
508
  }
@@ -497,16 +512,16 @@ class b {
497
512
  yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
498
513
  return;
499
514
  }
500
- const u = (await this.graph.getState(c, { subgraphs: !0 })).values;
515
+ const h = (await this.graph.getState(g, { subgraphs: !0 })).values;
501
516
  if (this.isRunCancelled(r)) {
502
517
  yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
503
518
  return;
504
519
  }
505
- this.chatHistory = u.agentExecutionContext.messages.length ? u.agentExecutionContext.messages : this.chatHistory, this.priorSteps = u.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = u.agentExecutionContext.sharedState ?? {}, yield {
520
+ this.chatHistory = h.agentExecutionContext.messages.length ? h.agentExecutionContext.messages : this.chatHistory, this.priorSteps = h.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = h.agentExecutionContext.sharedState ?? {}, yield {
506
521
  runId: r,
507
522
  timestamp: Date.now(),
508
523
  type: "completed",
509
- result: { content: u.finalOutputMessage }
524
+ result: { content: h.finalOutputMessage }
510
525
  };
511
526
  }
512
527
  /**
@@ -540,21 +555,34 @@ class b {
540
555
  cancel() {
541
556
  this.activeRunId && (this.cancelledRunIds.add(this.activeRunId), this.activeAbortController?.abort(), ++this.streamEpoch, this.interruptHandler?.cancel());
542
557
  }
543
- async *pipeStream(e, r, s) {
544
- for await (const n of e) {
545
- if (this.isRunCancelled(s) || r !== this.streamEpoch)
558
+ async *pipeStream(e, n, s) {
559
+ for await (const r of e) {
560
+ if (this.isRunCancelled(s) || n !== this.streamEpoch)
546
561
  break;
547
- 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 {
562
+ r.event === "on_custom_event" && r.name === "trace_message" ? yield { runId: s, timestamp: Date.now(), type: "trace", data: r.data } : r.name === "graph_ux_suggestion" && (yield {
548
563
  runId: s,
549
564
  timestamp: Date.now(),
550
565
  type: "ux-suggestion",
551
- suggestion: n.data
566
+ suggestion: r.data
552
567
  });
553
568
  }
554
569
  }
555
570
  isRunCancelled(e) {
556
571
  return this.cancelledRunIds.has(e);
557
572
  }
573
+ /**
574
+ * Creates a request-scoped registry containing all agents by default,
575
+ * or only the explicitly selected agents when filtering is requested.
576
+ */
577
+ createRequestAgentRegistry(e) {
578
+ const n = e.routing === "direct" ? [e.agentId] : e.agentIds, s = n ? n.map((a) => {
579
+ const i = this.agentRegistry.get(a);
580
+ if (!i)
581
+ throw new Error(`Agent is not registered: ${a}`);
582
+ return i;
583
+ }) : this.agentRegistry.list(), r = new v();
584
+ return s.forEach((a) => r.register(a)), r;
585
+ }
558
586
  /**
559
587
  * Disposes this instance by terminating the embeddings worker
560
588
  * and cleaning up all related resources.
@@ -564,6 +592,6 @@ class b {
564
592
  }
565
593
  }
566
594
  export {
567
- b as O,
568
- re as g
595
+ R as O,
596
+ ie as g
569
597
  };