@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.
- package/dist/cdn/{GLOALVJR.js → 563R6SX5.js} +1 -1
- package/dist/cdn/B6CJG5UH.js +66 -0
- package/dist/cdn/{3YCSUTGV.js → CXW5URTF.js} +1 -1
- package/dist/cdn/{L4SS54EZ.js → DTIVDIDY.js} +1 -1
- package/dist/cdn/{AYMUK2MC.js → E5ZKBC24.js} +2 -2
- package/dist/cdn/{7NP7WGR5.js → EKZTQFYI.js} +1 -1
- package/dist/cdn/{FVDFPK3V.js → GP6NDTUE.js} +1 -1
- package/dist/cdn/{LUJCH5V7.js → HTBMJ557.js} +1 -1
- package/dist/cdn/{THXUE6R4.js → JMIXLFSZ.js} +1 -1
- package/dist/cdn/{BI3LK5D3.js → KJAWV5SK.js} +1 -1
- package/dist/cdn/KQHLOYKL.js +3 -0
- package/dist/cdn/{QBINZNXI.js → KX43Z26W.js} +1 -1
- package/dist/cdn/{QZLE7B6X.js → MBIIANTX.js} +1 -1
- package/dist/cdn/{FC45FF2D.js → MW5S2XCB.js} +1 -1
- package/dist/cdn/{275NKWUE.js → PUFTYLJ2.js} +1 -1
- package/dist/cdn/{AHLLB5QW.js → QXGXNOTJ.js} +1 -1
- package/dist/cdn/{OY2P2O47.js → ST5FQYT7.js} +32 -32
- package/dist/cdn/{WHOZT5H5.js → SXHH575T.js} +17 -17
- package/dist/cdn/{RAAV47KU.js → UAKSN7EQ.js} +1 -1
- package/dist/cdn/{NSER3L4A.js → WVPU4QOO.js} +1 -1
- package/dist/cdn/{242OOJML.js → Y2JULDNA.js} +1 -1
- package/dist/cdn/agent-utils/index.js +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/chunks/adapter.js +2 -2
- package/dist/chunks/generateLayerDescriptions.js +200 -189
- package/dist/chunks/navigationGraph.js +21 -20
- package/dist/chunks/orchestrator.js +221 -193
- package/dist/docs/api.json +1 -1
- package/dist/docs/docs.json +1 -1
- package/dist/docs/web-types.json +1 -1
- package/dist/utils/index.d.ts +1 -0
- package/package.json +6 -6
- package/dist/cdn/FNPLHH4E.js +0 -3
- 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
|
|
2
|
+
import A from "@arcgis/core/identity/IdentityManager.js";
|
|
3
3
|
import C from "@arcgis/core/portal/Portal.js";
|
|
4
|
-
import { n as
|
|
5
|
-
import { isGraphInterrupt as
|
|
6
|
-
import { generateGuid as
|
|
7
|
-
import { HumanMessage as
|
|
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
|
|
10
|
-
import
|
|
11
|
-
import
|
|
12
|
-
const
|
|
13
|
-
const e = await
|
|
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:
|
|
16
|
+
auth: { apiUrl: n, token: a }
|
|
17
17
|
};
|
|
18
18
|
return e.postMessage(i), await new Promise((c, d) => {
|
|
19
|
-
const
|
|
20
|
-
u.data === "completed" && (e.removeEventListener("message",
|
|
19
|
+
const o = (u) => {
|
|
20
|
+
u.data === "completed" && (e.removeEventListener("message", o), c());
|
|
21
21
|
}, g = (u) => {
|
|
22
|
-
e.removeEventListener("message",
|
|
22
|
+
e.removeEventListener("message", o), d(u instanceof Error ? u : new Error("Embeddings worker error"));
|
|
23
23
|
};
|
|
24
|
-
e.addEventListener("message",
|
|
24
|
+
e.addEventListener("message", o), e.addEventListener("error", g, { once: !0 });
|
|
25
25
|
}), e;
|
|
26
|
-
},
|
|
26
|
+
}, V = async () => {
|
|
27
27
|
{
|
|
28
28
|
const t = (await import("./embeddings.worker.js")).default;
|
|
29
29
|
return new t();
|
|
30
30
|
}
|
|
31
|
-
},
|
|
31
|
+
}, z = (t) => {
|
|
32
32
|
t.currentIntent = "none";
|
|
33
|
-
},
|
|
34
|
-
const
|
|
33
|
+
}, Q = async (t, e) => {
|
|
34
|
+
const n = b(e);
|
|
35
35
|
if (t.agentExecutionContext.userRequest) {
|
|
36
|
-
const
|
|
37
|
-
t.agentExecutionContext.messages = [...t.agentExecutionContext.messages,
|
|
36
|
+
const r = new O(t.agentExecutionContext.userRequest.trim());
|
|
37
|
+
t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, r], z(t);
|
|
38
38
|
}
|
|
39
|
-
const s =
|
|
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
|
-
},
|
|
42
|
-
if (!
|
|
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
|
|
47
|
-
for (const [s,
|
|
48
|
-
if (!
|
|
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
|
-
|
|
54
|
+
n[s] = { value: r.value };
|
|
55
55
|
}
|
|
56
|
-
return
|
|
57
|
-
},
|
|
58
|
-
const { previousSharedState: e, patch:
|
|
59
|
-
if (!
|
|
56
|
+
return n;
|
|
57
|
+
}, K = (t) => {
|
|
58
|
+
const { previousSharedState: e, patch: n, agentId: s } = t;
|
|
59
|
+
if (!n)
|
|
60
60
|
return e;
|
|
61
|
-
const
|
|
61
|
+
const r = Date.now(), a = {
|
|
62
62
|
...e
|
|
63
63
|
};
|
|
64
|
-
for (const [i, c] of Object.entries(
|
|
65
|
-
c?.value !== void 0 && (
|
|
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:
|
|
69
|
+
updatedAt: r
|
|
70
70
|
}
|
|
71
71
|
});
|
|
72
|
-
return
|
|
73
|
-
},
|
|
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
|
-
},
|
|
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
|
-
},
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const i =
|
|
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:
|
|
95
|
-
summary: s ??
|
|
96
|
-
status:
|
|
94
|
+
outputMessage: n,
|
|
95
|
+
summary: s ?? n ?? X(a),
|
|
96
|
+
status: a,
|
|
97
97
|
sharedStatePatch: i
|
|
98
98
|
};
|
|
99
|
-
},
|
|
100
|
-
const
|
|
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 } =
|
|
108
|
-
if (!
|
|
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: ${
|
|
111
|
-
const
|
|
110
|
+
await l({ text: `Executing registered agent: ${r.agent.name}` }, e);
|
|
111
|
+
const a = {
|
|
112
112
|
...e ?? {},
|
|
113
113
|
configurable: {
|
|
114
|
-
...
|
|
115
|
-
agentId:
|
|
116
|
-
context:
|
|
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
|
|
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
|
-
|
|
132
|
+
a
|
|
133
133
|
);
|
|
134
|
-
i =
|
|
135
|
-
} catch (
|
|
136
|
-
if (
|
|
137
|
-
throw
|
|
138
|
-
const g =
|
|
139
|
-
console.error(`Agent "${
|
|
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
|
|
147
|
+
const o = c.length > x ? `${c.slice(0, x - 14)}
|
|
148
148
|
[truncated]` : c;
|
|
149
|
-
d.push(new
|
|
149
|
+
d.push(new T(o));
|
|
150
150
|
}
|
|
151
151
|
return {
|
|
152
152
|
...t,
|
|
153
153
|
stepCount: t.stepCount + 1,
|
|
154
|
-
lastExecutedAgent:
|
|
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:
|
|
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:
|
|
169
|
+
sharedState: K({
|
|
170
170
|
previousSharedState: t.agentExecutionContext.sharedState,
|
|
171
171
|
patch: i.sharedStatePatch,
|
|
172
|
-
agentId:
|
|
172
|
+
agentId: r.agent.id
|
|
173
173
|
})
|
|
174
174
|
}
|
|
175
175
|
};
|
|
176
|
-
},
|
|
177
|
-
"
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
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:
|
|
186
|
-
if (this.agentRegistry.has(
|
|
187
|
-
throw new Error(`Duplicate agent id: ${
|
|
188
|
-
this.agentRegistry.set(
|
|
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
|
|
206
|
+
class ae {
|
|
198
207
|
/**
|
|
199
208
|
* Create a new InterruptHandler tied to a specific compiled graph and config.
|
|
200
209
|
*/
|
|
201
|
-
constructor(e,
|
|
202
|
-
this.graph = e, this.config = { ...
|
|
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,
|
|
209
|
-
this.resolveWait = e, this.rejectWait =
|
|
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,
|
|
224
|
+
handle(e, n) {
|
|
216
225
|
try {
|
|
217
226
|
const s = {
|
|
218
227
|
agentId: e.agentId,
|
|
219
228
|
id: e.id,
|
|
220
|
-
payload:
|
|
221
|
-
},
|
|
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?.(
|
|
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
|
|
253
|
+
const ie = async (t) => {
|
|
245
254
|
try {
|
|
246
|
-
return await (await
|
|
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
|
-
},
|
|
251
|
-
const
|
|
252
|
-
if (
|
|
253
|
-
return
|
|
254
|
-
const s = await
|
|
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
|
|
258
|
-
const
|
|
266
|
+
async function oe(t, e, n, s) {
|
|
267
|
+
const r = `req-${Date.now()}`, i = {
|
|
259
268
|
type: "layerSearch",
|
|
260
|
-
precomputedEmbedding: s ? await
|
|
261
|
-
requestId:
|
|
262
|
-
minScore:
|
|
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 = (
|
|
266
|
-
|
|
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
|
|
280
|
+
function ce(t) {
|
|
272
281
|
const { worker: e } = t;
|
|
273
282
|
return {
|
|
274
283
|
async searchLayers({
|
|
275
|
-
text:
|
|
284
|
+
text: n,
|
|
276
285
|
minScore: s,
|
|
277
|
-
embeddingCache:
|
|
286
|
+
embeddingCache: r
|
|
278
287
|
}) {
|
|
279
|
-
return await
|
|
288
|
+
return await oe(n, e, s, r);
|
|
280
289
|
}
|
|
281
290
|
};
|
|
282
291
|
}
|
|
283
|
-
const
|
|
292
|
+
const de = async ({
|
|
284
293
|
combinedQuery: t,
|
|
285
294
|
layerIds: e,
|
|
286
|
-
embeddingsWorker:
|
|
295
|
+
embeddingsWorker: n,
|
|
287
296
|
minScore: s,
|
|
288
|
-
topResults:
|
|
289
|
-
embeddingCache:
|
|
297
|
+
topResults: r,
|
|
298
|
+
embeddingCache: a
|
|
290
299
|
}) => {
|
|
291
|
-
const i = `req-${Date.now()}`, c =
|
|
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:
|
|
306
|
+
topResults: r
|
|
298
307
|
};
|
|
299
|
-
return await new Promise((
|
|
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:
|
|
312
|
+
const p = u.data.results.map(({ layerId: y, results: h }) => ({
|
|
304
313
|
layerId: y,
|
|
305
|
-
results:
|
|
314
|
+
results: h
|
|
306
315
|
}));
|
|
307
|
-
|
|
316
|
+
o(p);
|
|
308
317
|
};
|
|
309
|
-
|
|
318
|
+
n.addEventListener("message", g, { once: !0 }), n.postMessage(d);
|
|
310
319
|
});
|
|
311
320
|
};
|
|
312
|
-
function
|
|
321
|
+
function ge(t) {
|
|
313
322
|
const { worker: e } = t;
|
|
314
323
|
return {
|
|
315
|
-
async searchFields({ text:
|
|
316
|
-
return await
|
|
317
|
-
combinedQuery:
|
|
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:
|
|
321
|
-
topResults:
|
|
329
|
+
minScore: r,
|
|
330
|
+
topResults: a,
|
|
322
331
|
embeddingCache: i
|
|
323
332
|
});
|
|
324
333
|
}
|
|
325
334
|
};
|
|
326
335
|
}
|
|
327
|
-
const
|
|
328
|
-
const e =
|
|
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
|
-
},
|
|
333
|
-
const
|
|
334
|
-
if (e.allLayers.forEach((
|
|
335
|
-
|
|
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
|
|
339
|
-
const
|
|
340
|
-
if (!
|
|
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 ${
|
|
351
|
+
`Layer with ID ${r.id} not found in the original map during registry restoration. Regenerate embeddings.`
|
|
343
352
|
);
|
|
344
|
-
if (
|
|
353
|
+
if (r.fields.length !== a.fields.length)
|
|
345
354
|
throw new Error(
|
|
346
|
-
`Field count mismatch for layer ID ${
|
|
355
|
+
`Field count mismatch for layer ID ${r.id} during registry restoration. Regenerate embeddings.`
|
|
347
356
|
);
|
|
348
357
|
const i = {
|
|
349
|
-
name:
|
|
350
|
-
title:
|
|
351
|
-
description:
|
|
358
|
+
name: r.name,
|
|
359
|
+
title: r.title,
|
|
360
|
+
description: r.description
|
|
352
361
|
}, c = /* @__PURE__ */ new Map();
|
|
353
|
-
for (const d of
|
|
354
|
-
const
|
|
355
|
-
if (!
|
|
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 ${
|
|
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:
|
|
370
|
+
alias: a.getFieldAlias(d.name) ?? d.alias,
|
|
362
371
|
description: d.description,
|
|
363
|
-
type:
|
|
364
|
-
valueType:
|
|
365
|
-
domain:
|
|
372
|
+
type: o.type || "unknown",
|
|
373
|
+
valueType: o.valueType || "unknown",
|
|
374
|
+
domain: a.getFieldDomain(d.name) ?? void 0
|
|
366
375
|
});
|
|
367
376
|
}
|
|
368
|
-
|
|
377
|
+
n.set(r.id, {
|
|
369
378
|
layerItem: i,
|
|
370
379
|
fieldRegistry: c
|
|
371
380
|
});
|
|
372
381
|
}
|
|
373
|
-
return
|
|
374
|
-
},
|
|
382
|
+
return n;
|
|
383
|
+
}, he = async (t) => {
|
|
375
384
|
try {
|
|
376
|
-
return (await
|
|
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
|
-
},
|
|
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:
|
|
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
|
|
390
|
-
return
|
|
398
|
+
const r = await he(s.resource.url);
|
|
399
|
+
return ue(r);
|
|
391
400
|
};
|
|
392
|
-
class
|
|
401
|
+
class R {
|
|
393
402
|
constructor() {
|
|
394
|
-
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new
|
|
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
|
|
411
|
+
const n = new R();
|
|
403
412
|
try {
|
|
404
413
|
if (e.view?.map) {
|
|
405
|
-
await
|
|
406
|
-
const s = await
|
|
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
|
-
|
|
419
|
+
n.layersAndFieldsRegistry = r, n.embeddingsWorker = await _(s);
|
|
411
420
|
}
|
|
412
421
|
return e.agents?.forEach((s) => {
|
|
413
|
-
|
|
414
|
-
}),
|
|
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 =
|
|
435
|
-
this.activeRunId = r, this.activeAbortController = new AbortController(), this.graph || (this.graph =
|
|
436
|
-
const
|
|
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:
|
|
442
|
-
fieldSearch:
|
|
455
|
+
layerSearch: a,
|
|
456
|
+
fieldSearch: i,
|
|
443
457
|
layersAndFieldsRegistry: this.layersAndFieldsRegistry,
|
|
444
|
-
agentRegistry:
|
|
445
|
-
embeddingCache:
|
|
458
|
+
agentRegistry: s,
|
|
459
|
+
embeddingCache: c
|
|
446
460
|
}
|
|
447
|
-
},
|
|
461
|
+
}, g = {
|
|
448
462
|
version: "v2",
|
|
449
463
|
streamMode: "custom",
|
|
450
464
|
signal: this.activeAbortController.signal,
|
|
451
|
-
configurable:
|
|
465
|
+
configurable: o,
|
|
452
466
|
subgraphs: !0
|
|
453
|
-
},
|
|
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
|
-
|
|
463
|
-
),
|
|
464
|
-
if (yield* this.pipeStream(
|
|
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
|
|
474
|
-
if (!
|
|
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 =
|
|
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
|
|
479
|
-
yield* this.pipeStream(
|
|
480
|
-
} catch (
|
|
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 (
|
|
500
|
+
if (m) {
|
|
486
501
|
yield {
|
|
487
502
|
runId: r,
|
|
488
503
|
timestamp: Date.now(),
|
|
489
504
|
type: "error",
|
|
490
|
-
error: { 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
|
|
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 =
|
|
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:
|
|
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,
|
|
544
|
-
for await (const
|
|
545
|
-
if (this.isRunCancelled(s) ||
|
|
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
|
-
|
|
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:
|
|
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
|
-
|
|
568
|
-
|
|
595
|
+
R as O,
|
|
596
|
+
ie as g
|
|
569
597
|
};
|