@arcgis/ai-orchestrator 5.1.0-next.85 → 5.1.0-next.86

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.
package/dist/index.js CHANGED
@@ -1,68 +1,68 @@
1
1
  import R from "@arcgis/core/identity/IdentityManager.js";
2
- import E from "@arcgis/core/portal/Portal.js";
3
- import { Annotation as v, isGraphInterrupt as re, StateGraph as se, START as ie, END as ae, MemorySaver as oe } from "@langchain/langgraph/web";
4
- import { HumanMessage as P, AIMessage as q, isAIMessage as ce, isToolMessage as de } from "@langchain/core/messages";
5
- import { dispatchCustomEvent as N } from "@langchain/core/callbacks/dispatch/web";
6
- import p, { z as l } from "zod";
7
- import { ChatPromptTemplate as H, SystemMessagePromptTemplate as le } from "@langchain/core/prompts";
8
- import { createAgent as me, summarizationMiddleware as ue, modelCallLimitMiddleware as ge } from "langchain";
9
- import { ChatOpenAI as pe, OpenAIEmbeddings as he } from "@langchain/openai";
10
- import * as O from "@arcgis/core/core/reactiveUtils.js";
11
- import V from "@arcgis/core/layers/FeatureLayer.js";
12
- import fe from "@arcgis/core/request.js";
13
- const z = {
2
+ import I from "@arcgis/core/portal/Portal.js";
3
+ import { Annotation as x, isGraphInterrupt as ne, StateGraph as re, START as se, END as ie, MemorySaver as ae } from "@langchain/langgraph/web";
4
+ import { HumanMessage as W, AIMessage as k, isAIMessage as oe, isToolMessage as ce } from "@langchain/core/messages";
5
+ import { dispatchCustomEvent as j } from "@langchain/core/callbacks/dispatch/web";
6
+ import h, { z as l } from "zod";
7
+ import { ChatPromptTemplate as N, SystemMessagePromptTemplate as de } from "@langchain/core/prompts";
8
+ import { createAgent as le, summarizationMiddleware as ue, modelCallLimitMiddleware as me } from "langchain";
9
+ import { ChatOpenAI as ge, OpenAIEmbeddings as pe } from "@langchain/openai";
10
+ import * as H from "@arcgis/core/core/reactiveUtils.js";
11
+ import O from "@arcgis/core/layers/FeatureLayer.js";
12
+ import he from "@arcgis/core/request.js";
13
+ const V = {
14
14
  advanced: "gpt-5.2",
15
15
  default: "gpt-5-mini",
16
16
  fast: "gpt-5.4-nano"
17
- }, k = {
17
+ }, T = {
18
18
  default: "text-embedding-ada-002"
19
19
  }, M = /* @__PURE__ */ new Map();
20
- let x = null;
21
- const ye = () => {
22
- const e = E.getDefault().helperServices;
23
- if (!e?.aiModels?.url)
20
+ let E = null;
21
+ const fe = () => {
22
+ const t = I.getDefault().helperServices;
23
+ if (!t?.aiModels?.url)
24
24
  throw new Error("AI Models Service URL is not defined in the portal's helper services.");
25
- return e.aiModels.url;
26
- }, G = async (t) => {
27
- const e = ye();
28
- M.size === 0 && (x || (x = (async () => {
25
+ return t.aiModels.url;
26
+ }, z = async (e) => {
27
+ const t = fe();
28
+ M.size === 0 && (E || (E = (async () => {
29
29
  try {
30
- const n = await fetch(`${e}/models`);
30
+ const n = await fetch(`${t}/models`);
31
31
  if (!n.ok)
32
32
  throw new Error("Failed to fetch AI service discovery data.");
33
33
  (await n.json()).models.forEach((a) => M.set(a.name, a));
34
34
  } catch (n) {
35
- throw x = null, n;
35
+ throw E = null, n;
36
36
  }
37
- })()), await x);
38
- const r = M.get(t);
37
+ })()), await E);
38
+ const r = M.get(e);
39
39
  if (!r)
40
- throw new Error(`Model '${t}' is not available in the discovery service.`);
40
+ throw new Error(`Model '${e}' is not available in the discovery service.`);
41
41
  return r.endpoint;
42
- }, we = async (t = "default") => await G(z[t]), K = async (t = "default") => await G(k[t]), ve = async (t) => {
43
- const e = await be(), r = await K("default"), n = E.getDefault(), a = (await R.getCredential(`${n.url}/sharing`)).token, i = {
42
+ }, ye = async (e = "default") => await z(V[e]), G = async (e = "default") => await z(T[e]), we = async (e) => {
43
+ const t = await ve(), r = await G("default"), n = I.getDefault(), a = (await R.getCredential(`${n.url}/sharing`)).token, i = {
44
44
  type: "generateEmbeddings",
45
- webmapEmbeddings: t,
45
+ webmapEmbeddings: e,
46
46
  auth: { apiUrl: r, token: a }
47
47
  };
48
- return e.postMessage(i), await new Promise((c, o) => {
49
- const d = (u) => {
50
- u.data === "completed" && (e.removeEventListener("message", d), c());
51
- }, m = (u) => {
52
- e.removeEventListener("message", d), o(u instanceof Error ? u : new Error("Embeddings worker error"));
48
+ return t.postMessage(i), await new Promise((c, o) => {
49
+ const d = (m) => {
50
+ m.data === "completed" && (t.removeEventListener("message", d), c());
51
+ }, u = (m) => {
52
+ t.removeEventListener("message", d), o(m instanceof Error ? m : new Error("Embeddings worker error"));
53
53
  };
54
- e.addEventListener("message", d), e.addEventListener("error", m, { once: !0 });
55
- }), e;
56
- }, be = async () => {
54
+ t.addEventListener("message", d), t.addEventListener("error", u, { once: !0 });
55
+ }), t;
56
+ }, ve = async () => {
57
57
  {
58
- const t = (await import("./embeddings.worker-GH7zdYqF.js")).default;
59
- return new t();
58
+ const e = (await import("./embeddings.worker-GH7zdYqF.js")).default;
59
+ return new e();
60
60
  }
61
- }, F = (t, e) => e, xe = (t, e) => ({
62
- ...t,
63
- ...e
64
- }), Ee = v.Root({
65
- agentExecutionContext: v({
61
+ }, L = (e, t) => t, xe = (e, t) => ({
62
+ ...e,
63
+ ...t
64
+ }), be = x.Root({
65
+ agentExecutionContext: x({
66
66
  default: () => ({
67
67
  userRequest: "",
68
68
  assignedTask: "",
@@ -71,42 +71,40 @@ const ye = () => {
71
71
  }),
72
72
  reducer: xe
73
73
  }),
74
- currentIntent: v({
74
+ currentIntent: x({
75
75
  default: () => "none",
76
- reducer: F
76
+ reducer: L
77
77
  }),
78
- requiresFollowUp: v({
78
+ requiresFollowUp: x({
79
79
  default: () => !0,
80
- reducer: F
80
+ reducer: L
81
81
  }),
82
- stepCount: v({
82
+ stepCount: x({
83
83
  default: () => 0,
84
- reducer: (t, e) => e ?? t + 1
84
+ reducer: (e, t) => t ?? e + 1
85
85
  })
86
- }), h = async (t, e) => {
87
- await N("trace_message", t, e);
88
- }, gt = async (t, e) => {
89
- await N("graph_ux_suggestion", t, e);
90
- }, Ie = (t) => {
91
- t.currentIntent = "none";
92
- }, Se = async (t, e) => {
93
- if (t.agentExecutionContext.userRequest) {
94
- const n = new P(t.agentExecutionContext.userRequest.trim());
95
- t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], Ie(t);
86
+ }), f = async (e, t) => {
87
+ await j("trace_message", e, t);
88
+ }, gt = async (e, t) => {
89
+ await j("graph_ux_suggestion", e, t);
90
+ }, Ee = (e) => {
91
+ e.currentIntent = "none";
92
+ }, Ie = async (e, t) => {
93
+ if (e.agentExecutionContext.userRequest) {
94
+ const n = new W(e.agentExecutionContext.userRequest.trim());
95
+ e.agentExecutionContext.messages = [...e.agentExecutionContext.messages, n], Ee(e);
96
96
  }
97
- const r = e?.configurable?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
98
- return await h({ text: `Available agents: ${[...r].join(", ")}` }, e), await h({ text: "Analyzing user input" }, e), t;
99
- }, Me = async (t, e) => (await h({ text: "Exiting..." }, e), t), L = 4e3, $ = (t) => {
100
- if (typeof t != "string")
97
+ const r = t?.configurable?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
98
+ return await f({ text: `Available agents: ${[...r].join(", ")}` }, t), await f({ text: "Analyzing user input" }, t), e;
99
+ }, Se = async (e, t) => (await f({ text: "Exiting..." }, t), e), $ = 4e3, q = (e) => {
100
+ if (typeof e != "string")
101
101
  return;
102
- const e = t.trim();
103
- return e || void 0;
104
- }, Re = (t) => {
105
- switch (t) {
102
+ const t = e.trim();
103
+ return t || void 0;
104
+ }, Me = (e) => {
105
+ switch (e) {
106
106
  case "failed":
107
107
  return "Agent failed without a summary.";
108
- case "partial":
109
- return "Agent partially completed without a summary.";
110
108
  case "unknown":
111
109
  return "Agent returned with unknown status.";
112
110
  case "success":
@@ -114,20 +112,20 @@ const ye = () => {
114
112
  default:
115
113
  return "Agent completed without a summary.";
116
114
  }
117
- }, ke = (t, e) => {
118
- const r = $(e?.outputMessage), n = $(e?.summary), s = e?.status ?? "unknown";
119
- return s === "unknown" && console.warn(`Registered agent "${t}" returned an invalid or missing status.`), {
115
+ }, Re = (e, t) => {
116
+ const r = q(t?.outputMessage), n = q(t?.summary), s = t?.status ?? "unknown";
117
+ return s === "unknown" && console.warn(`Registered agent "${e}" returned an invalid or missing status.`), {
120
118
  outputMessage: r,
121
- summary: n ?? r ?? Re(s),
119
+ summary: n ?? r ?? Me(s),
122
120
  status: s
123
121
  };
124
- }, Te = async (t, e) => {
125
- const r = e?.configurable, { agentRegistry: n } = r.services, s = n?.get(t.currentIntent);
122
+ }, ke = async (e, t) => {
123
+ const r = t?.configurable, { agentRegistry: n } = r.services, s = n?.get(e.currentIntent);
126
124
  if (!s)
127
- return console.warn(`No agent found for intent: ${t.currentIntent}`), t;
128
- await h({ text: `Executing registered agent: ${s.agent.name}` }, e);
125
+ return console.warn(`No agent found for intent: ${e.currentIntent}`), e;
126
+ await f({ text: `Executing registered agent: ${s.agent.name}` }, t);
129
127
  const a = {
130
- ...e ?? {},
128
+ ...t ?? {},
131
129
  configurable: {
132
130
  ...r ?? {},
133
131
  agentId: s.agent.id,
@@ -139,86 +137,87 @@ const ye = () => {
139
137
  const d = await s.agent.createGraph().compile().invoke(
140
138
  {
141
139
  agentExecutionContext: {
142
- ...t.agentExecutionContext,
143
- messages: [...t.agentExecutionContext.messages],
144
- priorSteps: [...t.agentExecutionContext.priorSteps ?? []]
140
+ ...e.agentExecutionContext,
141
+ messages: [...e.agentExecutionContext.messages],
142
+ priorSteps: [...e.agentExecutionContext.priorSteps ?? []]
145
143
  }
146
144
  },
147
145
  a
148
146
  );
149
- i = ke(s.agent.name, d), await h({ text: `Finished executing registered agent: ${s.agent.name}` }, e);
147
+ i = Re(s.agent.name, d), await f({ text: `Finished executing registered agent: ${s.agent.name}` }, t);
150
148
  } catch (d) {
151
- if (re(d))
149
+ if (ne(d))
152
150
  throw d;
153
- const m = d instanceof Error ? d.message : String(d);
154
- console.error(`Agent "${s.agent.name}" failed:`, d), await h({ text: `Registered agent failed: ${s.agent.name}. ${m}` }, e), i = {
151
+ const u = d instanceof Error ? d.message : String(d);
152
+ console.error(`Agent "${s.agent.name}" failed:`, d), await f({ text: `Registered agent failed: ${s.agent.name}. ${u}` }, t), i = {
155
153
  status: "failed",
156
- outputMessage: `Agent execution failed: ${m}`,
157
- summary: `Agent execution failed: ${m}`
154
+ outputMessage: `Agent execution failed: ${u}`,
155
+ summary: `Agent execution failed: ${u}`
158
156
  };
159
157
  }
160
- const c = i.outputMessage, o = [...t.agentExecutionContext.messages];
158
+ const c = i.outputMessage, o = [...e.agentExecutionContext.messages];
161
159
  if (c) {
162
- const d = c.length > L ? `${c.slice(0, L - 14)}
160
+ const d = c.length > $ ? `${c.slice(0, $ - 14)}
163
161
  [truncated]` : c;
164
- o.push(new q(d));
162
+ o.push(new k(d));
165
163
  }
166
164
  return {
167
- ...t,
168
- stepCount: t.stepCount + 1,
165
+ ...e,
166
+ stepCount: e.stepCount + 1,
167
+ requiresFollowUp: i.status === "failed" ? !0 : e.requiresFollowUp,
169
168
  agentExecutionContext: {
170
- ...t.agentExecutionContext,
169
+ ...e.agentExecutionContext,
171
170
  messages: o,
172
171
  priorSteps: [
173
- ...t.agentExecutionContext.priorSteps ?? [],
172
+ ...e.agentExecutionContext.priorSteps ?? [],
174
173
  {
175
174
  agentId: s.agent.id,
176
- assignedTask: t.agentExecutionContext.assignedTask,
177
- summary: i.summary,
175
+ assignedTask: e.agentExecutionContext.assignedTask,
176
+ summary: i?.summary || "No summary provided.",
178
177
  status: i.status
179
178
  }
180
179
  ]
181
180
  }
182
181
  };
183
- }, Ae = (t, e, r) => {
184
- const n = t[e];
182
+ }, Te = (e, t, r) => {
183
+ const n = e[t];
185
184
  return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((s, a) => {
186
- (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(a.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + e + (e.split("/").length !== r ? ". Note that variables only represent file names one level deep." : ""))));
185
+ (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(a.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + t + (t.split("/").length !== r ? ". Note that variables only represent file names one level deep." : ""))));
187
186
  });
188
- }, T = async (t) => (await Ae(/* @__PURE__ */ Object.assign({ "./field_descriptions_prompt.md": () => import("./field_descriptions_prompt-haMV_aoG.js"), "./intent_prompt.md": () => import("./intent_prompt-DpOkH79K.js"), "./layer_descriptions_prompt.md": () => import("./layer_descriptions_prompt-NAaKWdJi.js") }), `./${t}.md`, 2)).default, Ce = async (t) => {
189
- const { agent: e, messages: r, config: n } = t;
190
- return { structuredResponse: (await e.invoke(
187
+ }, C = async (e) => (await Te(/* @__PURE__ */ Object.assign({ "./field_descriptions_prompt.md": () => import("./field_descriptions_prompt-haMV_aoG.js"), "./intent_prompt.md": () => import("./intent_prompt-BSRo2YLj.js"), "./layer_descriptions_prompt.md": () => import("./layer_descriptions_prompt-NAaKWdJi.js") }), `./${e}.md`, 2)).default, Ce = async (e) => {
188
+ const { agent: t, messages: r, config: n } = e;
189
+ return { structuredResponse: (await t.invoke(
191
190
  {
192
191
  messages: r
193
192
  },
194
193
  n
195
194
  )).structuredResponse };
196
- }, B = (t) => async (e, r) => {
195
+ }, K = (e) => async (t, r) => {
197
196
  const n = new Headers(r?.headers);
198
- return n.delete("Authorization"), n.delete("api-key"), t && t.length > 0 && (n.set("X-Esri-Authorization", `Bearer ${t}`), n.set("X-Esri-Request-Source", "MapsSDK")), await fetch(e, {
197
+ return n.delete("Authorization"), n.delete("api-key"), e && e.length > 0 && (n.set("X-Esri-Authorization", `Bearer ${e}`), n.set("X-Esri-Request-Source", "MapsSDK")), await fetch(t, {
199
198
  ...r,
200
199
  headers: n
201
200
  });
202
- }, b = async (t = "default", e = 0) => {
203
- const r = E.getDefault(), n = await R.getCredential(`${r.url}/sharing`), s = z[t], a = await we(t);
204
- return new pe({
201
+ }, b = async (e = "default", t = 0) => {
202
+ const r = I.getDefault(), n = await R.getCredential(`${r.url}/sharing`), s = V[e], a = await ye(e);
203
+ return new ge({
205
204
  modelName: s,
206
205
  apiKey: "dummy-key",
207
206
  // 5-mini does not support temperature parameter
208
- ...t !== "default" && { temperature: e },
207
+ ...e !== "default" && { temperature: t },
209
208
  configuration: {
210
209
  baseURL: a,
211
- fetch: B(n.token)
210
+ fetch: K(n.token)
212
211
  }
213
212
  });
214
- }, De = async (t = "default") => {
215
- const e = E.getDefault(), r = await R.getCredential(`${e.url}/sharing`), n = k[t], s = await K(t);
216
- return new he({
213
+ }, Ae = async (e = "default") => {
214
+ const t = I.getDefault(), r = await R.getCredential(`${t.url}/sharing`), n = T[e], s = await G(e);
215
+ return new pe({
217
216
  modelName: n,
218
217
  apiKey: "dummy-key",
219
218
  configuration: {
220
219
  baseURL: s,
221
- fetch: B(r.token)
220
+ fetch: K(r.token)
222
221
  },
223
222
  batchSize: 2048,
224
223
  maxConcurrency: 10
@@ -229,31 +228,31 @@ const ye = () => {
229
228
  description: l.string().min(1)
230
229
  });
231
230
  l.array(Fe);
232
- const _ = (t) => JSON.stringify(t, null, 2), Le = (t) => {
233
- const e = t.map((n) => n.id), r = l.enum(e);
231
+ const U = (e) => JSON.stringify(e, null, 2), De = (e) => {
232
+ const t = e.map((n) => n.id), r = l.enum(t);
234
233
  return l.object({
235
234
  intent: r.nullable(),
236
235
  assignedTask: l.string().nullable(),
237
236
  requiresFollowUp: l.boolean()
238
237
  });
239
- }, $e = async (t, e) => {
238
+ }, Le = async (e, t) => {
240
239
  try {
241
- await h({ text: "Asking LLM to route to an agent" }, e);
242
- const s = (e?.configurable?.services.agentRegistry?.list() ?? []).map(({ agent: S }) => ({
243
- id: S.id,
244
- name: S.name,
245
- description: S.description
240
+ await f({ text: "Asking LLM to route to an agent" }, t);
241
+ const s = (t?.configurable?.services.agentRegistry?.list() ?? []).map(({ agent: v }) => ({
242
+ id: v.id,
243
+ name: v.name,
244
+ description: v.description
246
245
  }));
247
246
  if (!s.length)
248
- return await h({ text: "No agents registered; skipping intent detection" }, e), { ...t, currentIntent: "none" };
249
- const a = await T("intent_prompt"), i = _(s), c = Le(s), o = {
247
+ return await f({ text: "No agents registered; skipping intent detection" }, t), { ...e, currentIntent: "none" };
248
+ const a = await C("intent_prompt"), i = U(s), c = De(s), o = {
250
249
  registeredAgents: i,
251
- priorSteps: _(t.agentExecutionContext.priorSteps),
252
- userRequest: t.agentExecutionContext.userRequest
253
- }, m = await H.fromTemplate(a).format(o), u = me({
254
- model: await b("default"),
250
+ priorSteps: U(e.agentExecutionContext.priorSteps),
251
+ userRequest: e.agentExecutionContext.userRequest
252
+ }, u = await N.fromTemplate(a).format(o), m = le({
253
+ model: await b("fast"),
255
254
  tools: [],
256
- systemPrompt: m,
255
+ systemPrompt: u,
257
256
  checkpointer: !0,
258
257
  responseFormat: c,
259
258
  middleware: [
@@ -267,77 +266,100 @@ const _ = (t) => JSON.stringify(t, null, 2), Le = (t) => {
267
266
  }),
268
267
  // Enforce no loop/retry.
269
268
  // 1 usual LLM call and 1 optional summarization call.
270
- ge({ runLimit: 2 })
269
+ me({ runLimit: 2 })
271
270
  ]
272
271
  }), { structuredResponse: y } = await Ce({
273
- agent: u,
274
- messages: t.agentExecutionContext.messages,
275
- config: e
276
- }), f = c.parse(
272
+ agent: m,
273
+ messages: e.agentExecutionContext.messages,
274
+ config: t
275
+ }), p = c.parse(
277
276
  y ?? { intent: null, assignedTask: null, requiresFollowUp: !1 }
278
- ), g = f.intent ?? "none", I = {
279
- ...t,
277
+ ), g = p.intent ?? "none", S = {
278
+ ...e,
280
279
  currentIntent: g,
281
- requiresFollowUp: f.requiresFollowUp,
280
+ requiresFollowUp: p.requiresFollowUp,
282
281
  agentExecutionContext: {
283
- ...t.agentExecutionContext,
284
- assignedTask: f.assignedTask ?? ""
282
+ ...e.agentExecutionContext,
283
+ assignedTask: p.assignedTask ?? ""
285
284
  }
286
285
  };
287
- return await h({ text: `Intent came back as: ${g}` }, e), await h(
288
- { text: `Agent picked: ${g}
289
- Task Assigned: ${f.assignedTask ?? ""}` },
290
- e
291
- ), I;
286
+ if (g === "none") {
287
+ const v = "I could not find a matching agent for that request. Please rephrase your question with more detail.";
288
+ return await f({ text: "LLM did not identify a clear intent." }, t), {
289
+ ...e,
290
+ currentIntent: g,
291
+ requiresFollowUp: !1,
292
+ agentExecutionContext: {
293
+ ...e.agentExecutionContext,
294
+ assignedTask: "",
295
+ messages: [...e.agentExecutionContext.messages, new k(v)],
296
+ priorSteps: [
297
+ ...e.agentExecutionContext.priorSteps ?? [],
298
+ {
299
+ agentId: "no-intent-router",
300
+ assignedTask: e.agentExecutionContext.userRequest,
301
+ summary: "No matching agent found; asked user to rephrase.",
302
+ status: "success"
303
+ }
304
+ ]
305
+ }
306
+ };
307
+ }
308
+ return await f(
309
+ {
310
+ text: `Agent picked: ${g}
311
+ Task Assigned: ${p.assignedTask ?? ""}
312
+ Requires Follow-Up: ${p.requiresFollowUp}`
313
+ },
314
+ t
315
+ ), S;
292
316
  } catch (r) {
293
- throw await h({ text: "Error during intent detection" }, e), new Error(`Error during intent detection: ${r instanceof Error ? r.message : String(r)}`);
317
+ throw await f({ text: "Error during intent detection" }, t), new Error(`Error during intent detection: ${r instanceof Error ? r.message : String(r)}`);
294
318
  }
295
- }, U = 3, _e = () => new se(Ee).addNode("ingestInput", Se).addNode("intentLLM", $e).addNode("executeRegisteredAgent", Te).addNode("exit", Me).addEdge(ie, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" ? "exit" : "executeRegisteredAgent").addConditionalEdges("executeRegisteredAgent", (e) => (console.log("[Dispatcher][executeRegisteredAgent]", {
296
- intent: e.currentIntent,
297
- followUp: e.requiresFollowUp,
298
- step: e.stepCount,
299
- maxSteps: U
300
- }), !e.requiresFollowUp || e.stepCount >= U ? "exit" : "intentLLM")).addEdge("exit", ae);
319
+ }, $e = 3, qe = () => new re(be).addNode("ingestInput", Ie).addNode("intentLLM", Le).addNode("executeRegisteredAgent", ke).addNode("exit", Se).addEdge(se, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (t) => t.currentIntent === "none" ? "exit" : "executeRegisteredAgent").addConditionalEdges(
320
+ "executeRegisteredAgent",
321
+ (t) => t.stepCount >= $e || !t.requiresFollowUp ? "exit" : "intentLLM"
322
+ ).addEdge("exit", ie);
301
323
  class Ue {
302
324
  constructor() {
303
325
  this.agentRegistry = /* @__PURE__ */ new Map();
304
326
  }
305
- register(e) {
306
- const { agent: r } = e;
327
+ register(t) {
328
+ const { agent: r } = t;
307
329
  if (this.agentRegistry.has(r.id))
308
330
  throw new Error(`Duplicate agent id: ${r.id}`);
309
- this.agentRegistry.set(r.id, e);
331
+ this.agentRegistry.set(r.id, t);
310
332
  }
311
- get(e) {
312
- return this.agentRegistry.get(e);
333
+ get(t) {
334
+ return this.agentRegistry.get(t);
313
335
  }
314
336
  list() {
315
337
  return [...this.agentRegistry.values()];
316
338
  }
317
339
  }
318
- class We {
340
+ class _e {
319
341
  /**
320
342
  * Create a new InterruptHandler tied to a specific compiled graph and config.
321
343
  */
322
- constructor(e, r) {
323
- this.graph = e, this.config = { ...r };
344
+ constructor(t, r) {
345
+ this.graph = t, this.config = { ...r };
324
346
  }
325
347
  /**
326
348
  * Returns a promise that resolves when the user provides a HITL response.
327
349
  */
328
350
  async waitForUser() {
329
- return await new Promise((e, r) => {
330
- this.resolveWait = e, this.rejectWait = r;
351
+ return await new Promise((t, r) => {
352
+ this.resolveWait = t, this.rejectWait = r;
331
353
  });
332
354
  }
333
355
  /**
334
356
  * Resume graph execution after the UI responds to an interrupt.
335
357
  */
336
- handle(e, r) {
358
+ handle(t, r) {
337
359
  try {
338
360
  const n = {
339
- agentId: e.agentId,
340
- id: e.id,
361
+ agentId: t.agentId,
362
+ id: t.id,
341
363
  payload: r
342
364
  }, s = this.graph.streamEvents(null, {
343
365
  ...this.config,
@@ -362,32 +384,32 @@ class We {
362
384
  this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
363
385
  }
364
386
  }
365
- const je = (t) => {
366
- let e = -1;
367
- for (let r = t.length - 1; r >= 0; r--)
368
- if (t[r] instanceof P) {
369
- e = r;
387
+ const Pe = (e) => {
388
+ let t = -1;
389
+ for (let r = e.length - 1; r >= 0; r--)
390
+ if (e[r] instanceof W) {
391
+ t = r;
370
392
  break;
371
393
  }
372
- return e === -1 ? "" : t.slice(e + 1).filter((r) => r instanceof q).map((r) => r.content).join(`
394
+ return t === -1 ? "" : e.slice(t + 1).filter((r) => r instanceof k).map((r) => r.content).join(`
373
395
  `);
374
- }, J = async (t) => {
396
+ }, B = async (e) => {
375
397
  try {
376
- return await (await De()).embedDocuments(t);
377
- } catch (e) {
378
- throw console.error("Failed to generate embeddings:", e), e;
398
+ return await (await Ae()).embedDocuments(e);
399
+ } catch (t) {
400
+ throw console.error("Failed to generate embeddings:", t), t;
379
401
  }
380
- }, X = async (t, e) => {
381
- const r = e.get(t);
402
+ }, J = async (e, t) => {
403
+ const r = t.get(e);
382
404
  if (r)
383
405
  return r;
384
- const n = await J([t]);
385
- return e.set(t, n[0]), n[0];
406
+ const n = await B([e]);
407
+ return t.set(e, n[0]), n[0];
386
408
  };
387
- async function Pe(t, e, r, n) {
409
+ async function We(e, t, r, n) {
388
410
  const s = `req-${Date.now()}`, i = {
389
411
  type: "layerSearch",
390
- precomputedEmbedding: n ? await X(t, n) : void 0,
412
+ precomputedEmbedding: n ? await J(e, n) : void 0,
391
413
  requestId: s,
392
414
  minScore: r
393
415
  };
@@ -395,58 +417,58 @@ async function Pe(t, e, r, n) {
395
417
  const o = (d) => {
396
418
  d.data.requestId === s && c(d.data.results);
397
419
  };
398
- e.addEventListener("message", o, { once: !0 }), e.postMessage(i);
420
+ t.addEventListener("message", o, { once: !0 }), t.postMessage(i);
399
421
  });
400
422
  }
401
- function qe(t) {
402
- const { worker: e } = t;
423
+ function je(e) {
424
+ const { worker: t } = e;
403
425
  return {
404
426
  async searchLayers({
405
427
  text: r,
406
428
  minScore: n,
407
429
  embeddingCache: s
408
430
  }) {
409
- return await Pe(r, e, n, s);
431
+ return await We(r, t, n, s);
410
432
  }
411
433
  };
412
434
  }
413
435
  const Ne = async ({
414
- combinedQuery: t,
415
- layerIds: e,
436
+ combinedQuery: e,
437
+ layerIds: t,
416
438
  embeddingsWorker: r,
417
439
  minScore: n,
418
440
  topResults: s,
419
441
  embeddingCache: a
420
442
  }) => {
421
- const i = `req-${Date.now()}`, c = a ? await X(t, a) : void 0, o = {
443
+ const i = `req-${Date.now()}`, c = a ? await J(e, a) : void 0, o = {
422
444
  type: "fieldSearch",
423
- layerIdForFieldsSearch: e,
445
+ layerIdForFieldsSearch: t,
424
446
  precomputedEmbedding: c,
425
447
  requestId: i,
426
448
  minScore: n,
427
449
  topResults: s
428
450
  };
429
451
  return await new Promise((d) => {
430
- const m = (u) => {
431
- if (u.data.requestId !== i)
452
+ const u = (m) => {
453
+ if (m.data.requestId !== i)
432
454
  return;
433
- const y = u.data.results.map(({ layerId: f, results: g }) => ({
434
- layerId: f,
455
+ const y = m.data.results.map(({ layerId: p, results: g }) => ({
456
+ layerId: p,
435
457
  results: g
436
458
  }));
437
459
  d(y);
438
460
  };
439
- r.addEventListener("message", m, { once: !0 }), r.postMessage(o);
461
+ r.addEventListener("message", u, { once: !0 }), r.postMessage(o);
440
462
  });
441
463
  };
442
- function He(t) {
443
- const { worker: e } = t;
464
+ function He(e) {
465
+ const { worker: t } = e;
444
466
  return {
445
467
  async searchFields({ text: r, layerIds: n, minScore: s, topResults: a, embeddingCache: i }) {
446
468
  return await Ne({
447
469
  combinedQuery: r,
448
470
  layerIds: n,
449
- embeddingsWorker: e,
471
+ embeddingsWorker: t,
450
472
  minScore: s,
451
473
  topResults: a,
452
474
  embeddingCache: i
@@ -454,20 +476,20 @@ function He(t) {
454
476
  }
455
477
  };
456
478
  }
457
- const Q = "0.1", w = 1536, Y = "openai", Z = k.default, A = `Name: {name}
479
+ const X = "0.1", w = 1536, Q = "openai", Y = T.default, A = `Name: {name}
458
480
  Title: {title}
459
- Description: {description}`, C = `Name: {name}
481
+ Description: {description}`, F = `Name: {name}
460
482
  Alias: {alias}
461
- Description: {description}`, ee = l.object({
462
- schemaVersion: l.literal(Q),
483
+ Description: {description}`, Z = l.object({
484
+ schemaVersion: l.literal(X),
463
485
  modified: l.number().int().nonnegative(),
464
486
  embeddings: l.object({
465
- modelProvider: l.literal(Y),
466
- model: l.literal(Z),
487
+ modelProvider: l.literal(Q),
488
+ model: l.literal(Y),
467
489
  dimensions: l.literal(w),
468
490
  templates: l.object({
469
491
  layer: l.string().default(A),
470
- field: l.string().default(C)
492
+ field: l.string().default(F)
471
493
  })
472
494
  }),
473
495
  layers: l.array(
@@ -491,18 +513,18 @@ Description: {description}`, ee = l.object({
491
513
  )
492
514
  })
493
515
  ).default([])
494
- }), Oe = (t) => {
495
- const e = ee.safeParse(t);
496
- if (!e.success)
516
+ }), Oe = (e) => {
517
+ const t = Z.safeParse(e);
518
+ if (!t.success)
497
519
  throw new Error("Embeddings response validation failed. Regenerate embeddings.");
498
- return e.data;
499
- }, Ve = (t, e) => {
520
+ return t.data;
521
+ }, Ve = (e, t) => {
500
522
  const r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
501
- if (e.allLayers.forEach((s) => {
502
- s instanceof V && n.set(s.id, s);
503
- }), t.length !== n.size)
523
+ if (t.allLayers.forEach((s) => {
524
+ s instanceof O && n.set(s.id, s);
525
+ }), e.length !== n.size)
504
526
  throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
505
- for (const s of t) {
527
+ for (const s of e) {
506
528
  const a = n.get(s.id);
507
529
  if (!a)
508
530
  throw new Error(
@@ -538,25 +560,25 @@ Description: {description}`, ee = l.object({
538
560
  });
539
561
  }
540
562
  return r;
541
- }, ze = async (t) => {
563
+ }, ze = async (e) => {
542
564
  try {
543
- return (await fe(t, {
565
+ return (await he(e, {
544
566
  responseType: "json"
545
567
  })).data;
546
- } catch (e) {
547
- throw new Error(`Failed to fetch data from ${t}: ${String(e)}`);
568
+ } catch (t) {
569
+ throw new Error(`Failed to fetch data from ${e}: ${String(t)}`);
548
570
  }
549
- }, Ge = async (t) => {
550
- const e = t.map;
551
- if (!e?.portalItem)
571
+ }, Ge = async (e) => {
572
+ const t = e.map;
573
+ if (!t?.portalItem)
552
574
  throw new Error("WebMap portal item is missing.");
553
- const { resources: r } = await e.portalItem.fetchResources(), n = r.find((i) => i.resource.path === "embeddings-v01.json");
575
+ const { resources: r } = await t.portalItem.fetchResources(), n = r.find((i) => i.resource.path === "embeddings-v01.json");
554
576
  if (!n?.resource.url)
555
577
  throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
556
578
  const s = await ze(n.resource.url);
557
579
  return Oe(s);
558
580
  };
559
- class te {
581
+ class ee {
560
582
  constructor() {
561
583
  this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.threadId = "", this.agentRegistry = new Ue(), this.streamEpoch = 0;
562
584
  }
@@ -565,18 +587,18 @@ class te {
565
587
  * @param deps Core dependencies (layer/field registry plus optional map views).
566
588
  * @returns Ready Orchestrator.
567
589
  */
568
- static async init(e) {
569
- const r = new te();
590
+ static async init(t) {
591
+ const r = new ee();
570
592
  try {
571
- if (e.view?.map) {
572
- await O.whenOnce(() => e.view.ready);
573
- const n = await Ge(e.view), s = Ve(
593
+ if (t.view?.map) {
594
+ await H.whenOnce(() => t.view.ready);
595
+ const n = await Ge(t.view), s = Ve(
574
596
  n.layers,
575
- e.view.map
597
+ t.view.map
576
598
  );
577
- r.layersAndFieldsRegistry = s, r.embeddingsWorker = await ve(n);
599
+ r.layersAndFieldsRegistry = s, r.embeddingsWorker = await we(n);
578
600
  }
579
- return e.agents?.forEach((n) => {
601
+ return t.agents?.forEach((n) => {
580
602
  r.agentRegistry.register(n);
581
603
  }), r.orchestratorReady = !0, r;
582
604
  } catch (n) {
@@ -591,15 +613,15 @@ class te {
591
613
  * - `completed`: final result with chat history + layer styling
592
614
  * - `cancelled`: user aborted the run
593
615
  */
594
- async *ask(e) {
616
+ async *ask(t) {
595
617
  if (!this.orchestratorReady)
596
618
  throw new Error("Orchestrator is not ready yet.");
597
619
  if (!this.agentRegistry.list().length)
598
620
  throw new Error("Orchestrator has no registered agents.");
599
- if (++this.streamEpoch, !e.trim())
621
+ if (++this.streamEpoch, !t.trim())
600
622
  return;
601
- this.threadId = String(Date.now()), this.graph || (this.graph = _e().compile({ checkpointer: new oe() }));
602
- const r = this.embeddingsWorker ? qe({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? He({ worker: this.embeddingsWorker }) : void 0, s = /* @__PURE__ */ new Map(), i = {
623
+ this.threadId = String(Date.now()), this.graph || (this.graph = qe().compile({ checkpointer: new ae() }));
624
+ const r = this.embeddingsWorker ? je({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? He({ worker: this.embeddingsWorker }) : void 0, s = /* @__PURE__ */ new Map(), i = {
603
625
  version: "v2",
604
626
  streamMode: "custom",
605
627
  configurable: {
@@ -616,17 +638,17 @@ class te {
616
638
  },
617
639
  subgraphs: !0
618
640
  }, c = this.graph?.streamEvents(
619
- { agentExecutionContext: { userRequest: e, messages: this.chatHistory, priorSteps: this.priorSteps } },
641
+ { agentExecutionContext: { userRequest: t, messages: this.chatHistory, priorSteps: this.priorSteps } },
620
642
  i
621
643
  ), o = ++this.streamEpoch;
622
644
  for (yield* this.pipeStream(c, o); ; ) {
623
- const f = (await this.graph.getState(i, { subgraphs: !0 })).tasks.find((g) => g.interrupts.length > 0)?.interrupts[0]?.value;
624
- if (!f)
645
+ const p = (await this.graph.getState(i, { subgraphs: !0 })).tasks.find((g) => g.interrupts.length > 0)?.interrupts[0]?.value;
646
+ if (!p)
625
647
  break;
626
- this.currentInterrupt = f, this.interruptHandler = new We(this.graph, i), yield { runId: this.threadId, timestamp: Date.now(), type: "interrupt", interrupt: f };
648
+ this.currentInterrupt = p, this.interruptHandler = new _e(this.graph, i), yield { runId: this.threadId, timestamp: Date.now(), type: "interrupt", interrupt: p };
627
649
  try {
628
- const g = await this.interruptHandler.waitForUser(), I = ++this.streamEpoch;
629
- yield* this.pipeStream(g, I);
650
+ const g = await this.interruptHandler.waitForUser(), S = ++this.streamEpoch;
651
+ yield* this.pipeStream(g, S);
630
652
  } catch (g) {
631
653
  if (g) {
632
654
  yield {
@@ -641,12 +663,12 @@ class te {
641
663
  return;
642
664
  }
643
665
  }
644
- const m = (await this.graph.getState(i, { subgraphs: !0 })).values;
645
- this.chatHistory = m.agentExecutionContext.messages.length ? m.agentExecutionContext.messages : this.chatHistory, this.priorSteps = m.agentExecutionContext.priorSteps?.slice(-5) ?? [], yield {
666
+ const u = (await this.graph.getState(i, { subgraphs: !0 })).values;
667
+ this.chatHistory = u.agentExecutionContext.messages.length ? u.agentExecutionContext.messages : this.chatHistory, this.priorSteps = u.agentExecutionContext.priorSteps?.slice(-5) ?? [], yield {
646
668
  runId: this.threadId,
647
669
  timestamp: Date.now(),
648
670
  type: "completed",
649
- result: { content: je(m.agentExecutionContext.messages) }
671
+ result: { content: Pe(u.agentExecutionContext.messages) }
650
672
  };
651
673
  }
652
674
  /**
@@ -659,10 +681,10 @@ class te {
659
681
  * Generic resume for any HITL interrupt.
660
682
  * The payload is whatever the UI collected (e.g. "yes", "no", layerId, etc).
661
683
  */
662
- resumeInterrupt(e) {
684
+ resumeInterrupt(t) {
663
685
  if (!this.currentInterrupt || !this.interruptHandler)
664
686
  throw new Error("No pending interrupt to resume.");
665
- this.interruptHandler.handle(this.currentInterrupt, e);
687
+ this.interruptHandler.handle(this.currentInterrupt, t);
666
688
  }
667
689
  /**
668
690
  * Optional: allow UI to cancel the current HITL.
@@ -670,8 +692,8 @@ class te {
670
692
  cancelInterrupt() {
671
693
  this.interruptHandler && this.interruptHandler.cancel();
672
694
  }
673
- async *pipeStream(e, r) {
674
- for await (const n of e) {
695
+ async *pipeStream(t, r) {
696
+ for await (const n of t) {
675
697
  if (r !== this.streamEpoch) {
676
698
  console.log("Stale stream detected, aborting.");
677
699
  break;
@@ -692,31 +714,31 @@ class te {
692
714
  this.embeddingsWorker && (this.embeddingsWorker.terminate(), this.embeddingsWorker = void 0), this.orchestratorReady = !1;
693
715
  }
694
716
  }
695
- const Ke = (t) => {
696
- const e = /* @__PURE__ */ new Set();
697
- for (const n of t)
698
- if (ce(n)) {
717
+ const Ke = (e) => {
718
+ const t = /* @__PURE__ */ new Set();
719
+ for (const n of e)
720
+ if (oe(n)) {
699
721
  const s = n;
700
722
  s.tool_calls && s.tool_calls.length > 0 && s.tool_calls.forEach((a) => {
701
- a.id && e.add(a.id);
723
+ a.id && t.add(a.id);
702
724
  });
703
725
  }
704
- return t.filter((n) => {
705
- if (de(n)) {
726
+ return e.filter((n) => {
727
+ if (ce(n)) {
706
728
  const s = n;
707
- return e.has(s.tool_call_id);
729
+ return t.has(s.tool_call_id);
708
730
  }
709
731
  return !0;
710
732
  });
711
- }, D = (t, e) => {
712
- const r = le.fromTemplate(t);
713
- return H.fromMessages([r, ...e]);
714
- }, Be = async (t) => {
715
- const { promptText: e, modelTier: r, temperature: n, messages: s } = t, a = D(e, s ?? []), i = await b(r, n);
733
+ }, D = (e, t) => {
734
+ const r = de.fromTemplate(e);
735
+ return N.fromMessages([r, ...t]);
736
+ }, Be = async (e) => {
737
+ const { promptText: t, modelTier: r, temperature: n, messages: s } = e, a = D(t, s ?? []), i = await b(r, n);
716
738
  return a.pipe(i);
717
- }, pt = async (t) => {
718
- const { promptText: e, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a } = t, c = await (await Be({
719
- promptText: e,
739
+ }, pt = async (e) => {
740
+ const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a } = e, c = await (await Be({
741
+ promptText: t,
720
742
  modelTier: r,
721
743
  temperature: n,
722
744
  messages: s
@@ -725,76 +747,76 @@ const Ke = (t) => {
725
747
  return c;
726
748
  const o = c.content;
727
749
  return typeof o == "string" ? o : JSON.stringify(o);
728
- }, ne = async (t) => {
729
- const { promptText: e, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a, schema: i } = t, c = D(e, s ?? []), d = (await b(r, n)).withStructuredOutput(i);
750
+ }, te = async (e) => {
751
+ const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a, schema: i } = e, c = D(t, s ?? []), d = (await b(r, n)).withStructuredOutput(i);
730
752
  return await c.pipe(d).invoke(a ?? {});
731
- }, ht = async (t) => {
732
- const { promptText: e, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a, tools: i } = t, c = i.length > 0 ? Ke(s ?? []) : s ?? [], o = D(e, c), d = await b(r, n);
753
+ }, ht = async (e) => {
754
+ const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a, tools: i } = e, c = i.length > 0 ? Ke(s ?? []) : s ?? [], o = D(t, c), d = await b(r, n);
733
755
  return await o.pipe(d.bindTools(i)).invoke(a ?? {});
734
- }, Je = p.object({
735
- name: p.string(),
736
- description: p.string(),
737
- valueType: p.string(),
738
- alias: p.string()
739
- }), Xe = p.object({
740
- fields: p.array(Je)
756
+ }, Je = h.object({
757
+ name: h.string(),
758
+ description: h.string(),
759
+ valueType: h.string(),
760
+ alias: h.string()
761
+ }), Xe = h.object({
762
+ fields: h.array(Je)
741
763
  });
742
- function W(t, e) {
764
+ function _(e, t) {
743
765
  const r = /* @__PURE__ */ new Map();
744
- for (const n of t.fields) {
745
- const s = e.fields.find((i) => i.name === n.name), a = {
766
+ for (const n of e.fields) {
767
+ const s = t.fields.find((i) => i.name === n.name), a = {
746
768
  name: n.name,
747
769
  type: n.type,
748
770
  alias: s?.alias ?? n.alias ?? "",
749
771
  description: s?.description ?? n.description ?? "",
750
772
  valueType: s?.valueType ?? n.valueType ?? "",
751
- domain: t.getFieldDomain(n.name) ?? void 0
773
+ domain: e.getFieldDomain(n.name) ?? void 0
752
774
  };
753
775
  r.set(n.name, a);
754
776
  }
755
777
  return r;
756
778
  }
757
- const Qe = async (t) => {
758
- const r = await T("field_descriptions_prompt"), n = t.fields.filter((i) => !(i.alias && i.description)).map((i) => {
759
- const { name: c, type: o, alias: d, description: m } = i;
760
- return [`Name: ${c}`, `Type: ${o}`, `Alias: ${d}`, `Description: ${m ?? "N/A"}`].join(", ");
779
+ const Qe = async (e) => {
780
+ const r = await C("field_descriptions_prompt"), n = e.fields.filter((i) => !(i.alias && i.description)).map((i) => {
781
+ const { name: c, type: o, alias: d, description: u } = i;
782
+ return [`Name: ${c}`, `Type: ${o}`, `Alias: ${d}`, `Description: ${u ?? "N/A"}`].join(", ");
761
783
  }).join(`
762
784
  `);
763
785
  if (n.length === 0)
764
- return W(t, { fields: [] });
786
+ return _(e, { fields: [] });
765
787
  const s = {
766
- existingItemTitle: t.portalItem?.title,
767
- existingItemDescription: t.portalItem?.description,
768
- existingLayerTitle: t.title,
769
- existingLayerDescription: t.portalItem?.description,
788
+ existingItemTitle: e.portalItem?.title,
789
+ existingItemDescription: e.portalItem?.description,
790
+ existingLayerTitle: e.title,
791
+ existingLayerDescription: e.portalItem?.description,
770
792
  fieldInformation: n
771
- }, a = await ne({
793
+ }, a = await te({
772
794
  promptText: r,
773
795
  schema: Xe,
774
796
  inputVariables: s
775
797
  });
776
- return W(t, a);
777
- }, Ye = p.object({
778
- title: p.string(),
779
- description: p.string(),
780
- name: p.string().nullable()
781
- }), Ze = async (t, e) => {
782
- const n = await T("layer_descriptions_prompt"), s = Array.from(e.values()), a = {
798
+ return _(e, a);
799
+ }, Ye = h.object({
800
+ title: h.string(),
801
+ description: h.string(),
802
+ name: h.string().nullable()
803
+ }), Ze = async (e, t) => {
804
+ const n = await C("layer_descriptions_prompt"), s = Array.from(t.values()), a = {
783
805
  fieldInformation: JSON.stringify(s, null, 2),
784
- existingLayerTitle: t.title,
785
- existingLayerDescription: t.portalItem?.description,
786
- existingLayerSnippet: t.portalItem?.snippet,
787
- layerGeometryType: t.geometryType
806
+ existingLayerTitle: e.title,
807
+ existingLayerDescription: e.portalItem?.description,
808
+ existingLayerSnippet: e.portalItem?.snippet,
809
+ layerGeometryType: e.geometryType
788
810
  };
789
- return { ...await ne({
811
+ return { ...await te({
790
812
  promptText: n,
791
813
  schema: Ye,
792
814
  inputVariables: a
793
- }), name: t.title ?? null };
794
- }, et = async (t) => {
795
- const e = t.allLayers.toArray(), r = [], n = /* @__PURE__ */ new Map();
796
- for (const s of e)
797
- if (s instanceof V) {
815
+ }), name: e.title ?? null };
816
+ }, et = async (e) => {
817
+ const t = e.allLayers.toArray(), r = [], n = /* @__PURE__ */ new Map();
818
+ for (const s of t)
819
+ if (s instanceof O) {
798
820
  const a = (async () => {
799
821
  const i = await Qe(s), c = await Ze(s, i);
800
822
  n.set(s.id, { layerItem: c, fieldRegistry: i });
@@ -802,35 +824,35 @@ const Qe = async (t) => {
802
824
  r.push(a);
803
825
  }
804
826
  return await Promise.all(r), n;
805
- }, ft = async (t) => {
806
- await O.whenOnce(() => t.ready);
807
- const e = await et(t.map), { layers: r } = await tt(e), n = {
808
- schemaVersion: Q,
827
+ }, ft = async (e) => {
828
+ await H.whenOnce(() => e.ready);
829
+ const t = await et(e.map), { layers: r } = await tt(t), n = {
830
+ schemaVersion: X,
809
831
  modified: Date.now(),
810
832
  embeddings: {
811
- modelProvider: Y,
812
- model: Z,
833
+ modelProvider: Q,
834
+ model: Y,
813
835
  dimensions: w,
814
836
  templates: {
815
837
  layer: A,
816
- field: C
838
+ field: F
817
839
  }
818
840
  },
819
841
  layers: r
820
- }, s = ee.safeParse(n);
842
+ }, s = Z.safeParse(n);
821
843
  if (!s.success)
822
844
  throw console.error("Schema Mismatch:", s.error.format()), new Error("Webmap embedding generation failed validation.");
823
845
  return s.data;
824
- }, tt = async (t) => {
825
- const e = [], r = [];
826
- for (const [i, { fieldRegistry: c, layerItem: o }] of t.entries()) {
827
- const d = j(A, {
846
+ }, tt = async (e) => {
847
+ const t = [], r = [];
848
+ for (const [i, { fieldRegistry: c, layerItem: o }] of e.entries()) {
849
+ const d = P(A, {
828
850
  name: o.name,
829
851
  title: o.title,
830
852
  description: o.description
831
853
  });
832
- e.push(d);
833
- const m = {
854
+ t.push(d);
855
+ const u = {
834
856
  id: i,
835
857
  name: o.name ?? "",
836
858
  title: o.title,
@@ -838,32 +860,32 @@ const Qe = async (t) => {
838
860
  vector: [],
839
861
  fields: []
840
862
  };
841
- for (const [, u] of c.entries()) {
842
- const y = j(C, {
843
- name: u.name,
844
- alias: u.alias,
845
- description: u.description
863
+ for (const [, m] of c.entries()) {
864
+ const y = P(F, {
865
+ name: m.name,
866
+ alias: m.alias,
867
+ description: m.description
846
868
  });
847
- e.push(y), m.fields.push({
848
- name: u.name,
849
- alias: u.alias,
850
- description: u.description,
869
+ t.push(y), u.fields.push({
870
+ name: m.name,
871
+ alias: m.alias,
872
+ description: m.description,
851
873
  vector: []
852
874
  });
853
875
  }
854
- r.push(m);
876
+ r.push(u);
855
877
  }
856
- const n = await J(e);
878
+ const n = await B(t);
857
879
  let s = 0;
858
880
  return { layers: r.map((i) => (i.vector = n[s++], i.fields.forEach((c) => {
859
881
  c.vector = n[s++];
860
882
  }), i)) };
861
- }, j = (t, e) => t.replace(/\{(\w+)\}/gu, (r, n) => e[n] ?? ""), yt = (t, e) => {
862
- if (t.length !== e.length)
883
+ }, P = (e, t) => e.replace(/\{(\w+)\}/gu, (r, n) => t[n] ?? ""), yt = (e, t) => {
884
+ if (e.length !== t.length)
863
885
  throw new Error("Vectors must be the same length");
864
886
  let r = 0, n = 0, s = 0;
865
- for (let c = 0; c < t.length; ++c) {
866
- const o = t[c], d = e[c];
887
+ for (let c = 0; c < e.length; ++c) {
888
+ const o = e[c], d = t[c];
867
889
  r += o * d, n += o * o, s += d * d;
868
890
  }
869
891
  const a = Math.sqrt(n * s);
@@ -873,14 +895,14 @@ const Qe = async (t) => {
873
895
  return Math.max(-1, Math.min(1, i));
874
896
  };
875
897
  export {
876
- te as Orchestrator,
898
+ ee as Orchestrator,
877
899
  yt as cosineSimilarity,
878
900
  b as createChatModel,
879
901
  ft as createWebmapEmbeddings,
880
- J as getEmbeddings,
881
- ne as invokeStructuredPrompt,
902
+ B as getEmbeddings,
903
+ te as invokeStructuredPrompt,
882
904
  pt as invokeTextPrompt,
883
905
  ht as invokeToolPrompt,
884
- h as sendTraceMessage,
906
+ f as sendTraceMessage,
885
907
  gt as sendUXSuggestion
886
908
  };
@@ -39,12 +39,11 @@ Each step has:
39
39
  - agentId: string
40
40
  - assignedTask: string
41
41
  - summary: string
42
- - status: "success" | "failed" | "partial"
42
+ - status: "success" | "failed" | "unknown"
43
43
 
44
44
  Use prior steps to:
45
45
 
46
46
  - Avoid repeating work that has already succeeded
47
- - Continue or refine steps that were partial
48
47
  - Retry or adjust steps that failed when appropriate
49
48
 
50
49
  {priorSteps}
@@ -62,7 +62,7 @@ export interface AgentExecutionContext {
62
62
  userRequest: string;
63
63
  assignedTask: string;
64
64
  messages: ChatHistory;
65
- priorSteps?: PriorStep[];
65
+ priorSteps: PriorStep[];
66
66
  }
67
67
  export interface PriorStep {
68
68
  agentId: string;
@@ -71,8 +71,8 @@ export interface PriorStep {
71
71
  status: AgentStatus;
72
72
  }
73
73
  export interface AgentResult {
74
- outputMessage?: string;
75
- summary: string;
76
74
  status: AgentStatus;
75
+ outputMessage?: string;
76
+ summary?: string;
77
77
  }
78
- export type AgentStatus = "failed" | "partial" | "success" | "unknown";
78
+ export type AgentStatus = "failed" | "success" | "unknown";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@arcgis/ai-orchestrator",
3
- "version": "5.1.0-next.85",
3
+ "version": "5.1.0-next.86",
4
4
  "description": "ArcGIS AI Orchestrator Package",
5
5
  "homepage": "https://developers.arcgis.com/javascript/latest/",
6
6
  "type": "module",