@arcgis/ai-components 5.2.0-next.13 → 5.2.0-next.15

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.
@@ -10,18 +10,18 @@ import * as O from "@arcgis/core/core/reactiveUtils.js";
10
10
  import T from "@arcgis/core/layers/FeatureLayer.js";
11
11
  import U from "@arcgis/core/request.js";
12
12
  const G = async (t) => {
13
- const e = await N(), r = await I("default"), s = C.getDefault(), a = (await R.getCredential(`${s.url}/sharing`)).token, i = {
13
+ const e = await N(), r = await I("default"), s = C.getDefault(), o = (await R.getCredential(`${s.url}/sharing`)).token, i = {
14
14
  type: "generateEmbeddings",
15
15
  webmapEmbeddings: t,
16
- auth: { apiUrl: r, token: a }
16
+ auth: { apiUrl: r, token: o }
17
17
  };
18
18
  return e.postMessage(i), await new Promise((c, d) => {
19
- const o = (u) => {
20
- u.data === "completed" && (e.removeEventListener("message", o), c());
19
+ const a = (u) => {
20
+ u.data === "completed" && (e.removeEventListener("message", a), c());
21
21
  }, g = (u) => {
22
- e.removeEventListener("message", o), d(u instanceof Error ? u : new Error("Embeddings worker error"));
22
+ e.removeEventListener("message", a), d(u instanceof Error ? u : new Error("Embeddings worker error"));
23
23
  };
24
- e.addEventListener("message", o), e.addEventListener("error", g, { once: !0 });
24
+ e.addEventListener("message", a), e.addEventListener("error", g, { once: !0 });
25
25
  }), e;
26
26
  }, N = async () => {
27
27
  {
@@ -58,18 +58,18 @@ const G = async (t) => {
58
58
  const { previousSharedState: e, patch: r, agentId: s } = t;
59
59
  if (!r)
60
60
  return e;
61
- const n = Date.now(), a = {
61
+ const n = Date.now(), o = {
62
62
  ...e
63
63
  };
64
64
  for (const [i, c] of Object.entries(r))
65
- c?.value !== void 0 && (a[i] = {
65
+ c?.value !== void 0 && (o[i] = {
66
66
  value: c.value,
67
67
  meta: {
68
68
  updatedByAgentId: s,
69
69
  updatedAt: n
70
70
  }
71
71
  });
72
- return a;
72
+ return o;
73
73
  }, f = (t) => {
74
74
  if (typeof t != "string")
75
75
  return;
@@ -87,18 +87,18 @@ const G = async (t) => {
87
87
  return "Agent completed without a summary.";
88
88
  }
89
89
  }, K = (t, e) => {
90
- const r = f(e?.outputMessage), s = f(e?.summary), n = e?.status, a = n === "success" || n === "failed" ? n : "unknown";
91
- a === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
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
92
  const i = Q(e?.sharedStatePatch, t);
93
93
  return {
94
94
  outputMessage: r,
95
- summary: s ?? r ?? J(a),
96
- status: a,
95
+ summary: s ?? r ?? J(o),
96
+ status: o,
97
97
  sharedStatePatch: i
98
98
  };
99
99
  }, E = 4e3, X = async (t, e) => {
100
100
  const r = v(e);
101
- if (r?.abortSignal?.aborted)
101
+ if (e?.signal?.aborted)
102
102
  return await l({ text: "Run cancelled; skipping agent execution" }, e), {
103
103
  ...t,
104
104
  currentIntent: "none",
@@ -108,7 +108,7 @@ const G = async (t) => {
108
108
  if (!n)
109
109
  return console.warn(`No agent found for intent: ${t.currentIntent}`), t;
110
110
  await l({ text: `Executing registered agent: ${n.agent.name}` }, e);
111
- const a = {
111
+ const o = {
112
112
  ...e ?? {},
113
113
  configurable: {
114
114
  ...r ?? {},
@@ -118,7 +118,7 @@ const G = async (t) => {
118
118
  };
119
119
  let i;
120
120
  try {
121
- const o = await n.agent.createGraph().compile().invoke(
121
+ const a = await n.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
- a
132
+ o
133
133
  );
134
- i = K(n.agent.name, o), await l({ text: `Finished executing registered agent: ${n.agent.name}` }, e);
135
- } catch (o) {
136
- if (D(o))
137
- throw o;
138
- const g = o instanceof Error ? o.message : String(o);
139
- console.error(`Agent "${n.agent.name}" failed:`, o), await l({ text: `Registered agent failed: ${n.agent.name}. ${g}` }, e), i = {
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 = {
140
140
  status: "failed",
141
141
  outputMessage: `Agent execution failed: ${g}`,
142
142
  summary: `Agent execution failed: ${g}`
@@ -144,9 +144,9 @@ const G = async (t) => {
144
144
  }
145
145
  const c = i.outputMessage, d = [...t.agentExecutionContext.messages];
146
146
  if (c) {
147
- const o = c.length > E ? `${c.slice(0, E - 14)}
147
+ const a = c.length > E ? `${c.slice(0, E - 14)}
148
148
  [truncated]` : c;
149
- d.push(new P(o));
149
+ d.push(new P(a));
150
150
  }
151
151
  return {
152
152
  ...t,
@@ -247,7 +247,7 @@ const re = async (t) => {
247
247
  } catch (e) {
248
248
  throw console.error("Failed to generate embeddings:", e), e;
249
249
  }
250
- }, b = async (t, e) => {
250
+ }, x = async (t, e) => {
251
251
  const r = e.get(t);
252
252
  if (r)
253
253
  return r;
@@ -257,13 +257,13 @@ const re = async (t) => {
257
257
  async function ne(t, e, r, s) {
258
258
  const n = `req-${Date.now()}`, i = {
259
259
  type: "layerSearch",
260
- precomputedEmbedding: s ? await b(t, s) : void 0,
260
+ precomputedEmbedding: s ? await x(t, s) : void 0,
261
261
  requestId: n,
262
262
  minScore: r
263
263
  };
264
264
  return await new Promise((c) => {
265
- const d = (o) => {
266
- o.data.requestId === n && c(o.data.results);
265
+ const d = (a) => {
266
+ a.data.requestId === n && c(a.data.results);
267
267
  };
268
268
  e.addEventListener("message", d, { once: !0 }), e.postMessage(i);
269
269
  });
@@ -286,9 +286,9 @@ const ae = async ({
286
286
  embeddingsWorker: r,
287
287
  minScore: s,
288
288
  topResults: n,
289
- embeddingCache: a
289
+ embeddingCache: o
290
290
  }) => {
291
- const i = `req-${Date.now()}`, c = a ? await b(t, a) : void 0, d = {
291
+ const i = `req-${Date.now()}`, c = o ? await x(t, o) : void 0, d = {
292
292
  type: "fieldSearch",
293
293
  layerIdForFieldsSearch: e,
294
294
  precomputedEmbedding: c,
@@ -296,7 +296,7 @@ const ae = async ({
296
296
  minScore: s,
297
297
  topResults: n
298
298
  };
299
- return await new Promise((o) => {
299
+ return await new Promise((a) => {
300
300
  const g = (u) => {
301
301
  if (u.data.requestId !== i)
302
302
  return;
@@ -304,7 +304,7 @@ const ae = async ({
304
304
  layerId: y,
305
305
  results: m
306
306
  }));
307
- o(p);
307
+ a(p);
308
308
  };
309
309
  r.addEventListener("message", g, { once: !0 }), r.postMessage(d);
310
310
  });
@@ -312,13 +312,13 @@ const ae = async ({
312
312
  function ie(t) {
313
313
  const { worker: e } = t;
314
314
  return {
315
- async searchFields({ text: r, layerIds: s, minScore: n, topResults: a, embeddingCache: i }) {
315
+ async searchFields({ text: r, layerIds: s, minScore: n, topResults: o, embeddingCache: i }) {
316
316
  return await ae({
317
317
  combinedQuery: r,
318
318
  layerIds: s,
319
319
  embeddingsWorker: e,
320
320
  minScore: n,
321
- topResults: a,
321
+ topResults: o,
322
322
  embeddingCache: i
323
323
  });
324
324
  }
@@ -336,12 +336,12 @@ const oe = (t) => {
336
336
  }), t.length !== s.size)
337
337
  throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
338
338
  for (const n of t) {
339
- const a = s.get(n.id);
340
- if (!a)
339
+ const o = s.get(n.id);
340
+ if (!o)
341
341
  throw new Error(
342
342
  `Layer with ID ${n.id} not found in the original map during registry restoration. Regenerate embeddings.`
343
343
  );
344
- if (n.fields.length !== a.fields.length)
344
+ if (n.fields.length !== o.fields.length)
345
345
  throw new Error(
346
346
  `Field count mismatch for layer ID ${n.id} during registry restoration. Regenerate embeddings.`
347
347
  );
@@ -351,18 +351,18 @@ const oe = (t) => {
351
351
  description: n.description
352
352
  }, c = /* @__PURE__ */ new Map();
353
353
  for (const d of n.fields) {
354
- const o = a.fieldsIndex.get(d.name);
355
- if (!o)
354
+ const a = o.fieldsIndex.get(d.name);
355
+ if (!a)
356
356
  throw new Error(
357
357
  `Field with name ${d.name} not found in the original layer ${n.id} during registry restoration. Regenerate embeddings.`
358
358
  );
359
359
  c.set(d.name, {
360
360
  name: d.name,
361
- alias: a.getFieldAlias(d.name) ?? d.alias,
361
+ alias: o.getFieldAlias(d.name) ?? d.alias,
362
362
  description: d.description,
363
- type: o.type || "unknown",
364
- valueType: o.valueType || "unknown",
365
- domain: a.getFieldDomain(d.name) ?? void 0
363
+ type: a.type || "unknown",
364
+ valueType: a.valueType || "unknown",
365
+ domain: o.getFieldDomain(d.name) ?? void 0
366
366
  });
367
367
  }
368
368
  r.set(n.id, {
@@ -389,7 +389,7 @@ const oe = (t) => {
389
389
  const n = await de(s.resource.url);
390
390
  return oe(n);
391
391
  };
392
- class x {
392
+ class b {
393
393
  constructor() {
394
394
  this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new ee(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.streamEpoch = 0;
395
395
  }
@@ -399,7 +399,7 @@ class x {
399
399
  * @returns Ready Orchestrator.
400
400
  */
401
401
  static async init(e) {
402
- const r = new x();
402
+ const r = new b();
403
403
  try {
404
404
  if (e.view?.map) {
405
405
  await O.whenOnce(() => e.view.ready);
@@ -433,22 +433,22 @@ class x {
433
433
  return;
434
434
  const r = q();
435
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, a = /* @__PURE__ */ new Map(), c = {
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 = {
437
+ // eslint-disable-next-line @typescript-eslint/naming-convention
438
+ thread_id: r,
439
+ hitlResponse: null,
440
+ services: {
441
+ layerSearch: s,
442
+ fieldSearch: n,
443
+ layersAndFieldsRegistry: this.layersAndFieldsRegistry,
444
+ agentRegistry: this.agentRegistry,
445
+ embeddingCache: o
446
+ }
447
+ }, c = {
437
448
  version: "v2",
438
449
  streamMode: "custom",
439
- configurable: {
440
- // eslint-disable-next-line @typescript-eslint/naming-convention
441
- thread_id: r,
442
- abortSignal: this.activeAbortController.signal,
443
- hitlResponse: null,
444
- services: {
445
- layerSearch: s,
446
- fieldSearch: n,
447
- layersAndFieldsRegistry: this.layersAndFieldsRegistry,
448
- agentRegistry: this.agentRegistry,
449
- embeddingCache: a
450
- }
451
- },
450
+ signal: this.activeAbortController.signal,
451
+ configurable: i,
452
452
  subgraphs: !0
453
453
  }, d = this.graph?.streamEvents(
454
454
  {
@@ -460,8 +460,8 @@ class x {
460
460
  }
461
461
  },
462
462
  c
463
- ), o = ++this.streamEpoch;
464
- if (yield* this.pipeStream(d, o, r), this.isRunCancelled(r)) {
463
+ ), a = ++this.streamEpoch;
464
+ if (yield* this.pipeStream(d, a, r), this.isRunCancelled(r)) {
465
465
  yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
466
466
  return;
467
467
  }
@@ -564,6 +564,6 @@ class x {
564
564
  }
565
565
  }
566
566
  export {
567
- x as O,
567
+ b as O,
568
568
  re as g
569
569
  };