@arcgis/ai-orchestrator 5.1.0-next.85 → 5.1.0-next.87
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
|
|
3
|
-
import { Annotation as
|
|
4
|
-
import { HumanMessage as
|
|
5
|
-
import { dispatchCustomEvent as
|
|
6
|
-
import
|
|
7
|
-
import { ChatPromptTemplate as
|
|
8
|
-
import { createAgent as
|
|
9
|
-
import { ChatOpenAI as
|
|
10
|
-
import * as
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
const
|
|
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
|
-
},
|
|
17
|
+
}, T = {
|
|
18
18
|
default: "text-embedding-ada-002"
|
|
19
19
|
}, M = /* @__PURE__ */ new Map();
|
|
20
|
-
let
|
|
21
|
-
const
|
|
22
|
-
const
|
|
23
|
-
if (!
|
|
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
|
|
26
|
-
},
|
|
27
|
-
const
|
|
28
|
-
M.size === 0 && (
|
|
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(`${
|
|
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
|
|
35
|
+
throw E = null, n;
|
|
36
36
|
}
|
|
37
|
-
})()), await
|
|
38
|
-
const r = M.get(
|
|
37
|
+
})()), await E);
|
|
38
|
+
const r = M.get(e);
|
|
39
39
|
if (!r)
|
|
40
|
-
throw new Error(`Model '${
|
|
40
|
+
throw new Error(`Model '${e}' is not available in the discovery service.`);
|
|
41
41
|
return r.endpoint;
|
|
42
|
-
},
|
|
43
|
-
const
|
|
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:
|
|
45
|
+
webmapEmbeddings: e,
|
|
46
46
|
auth: { apiUrl: r, token: a }
|
|
47
47
|
};
|
|
48
|
-
return
|
|
49
|
-
const d = (
|
|
50
|
-
|
|
51
|
-
},
|
|
52
|
-
|
|
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
|
-
|
|
55
|
-
}),
|
|
56
|
-
},
|
|
54
|
+
t.addEventListener("message", d), t.addEventListener("error", u, { once: !0 });
|
|
55
|
+
}), t;
|
|
56
|
+
}, ve = async () => {
|
|
57
57
|
{
|
|
58
|
-
const
|
|
59
|
-
return new
|
|
58
|
+
const e = (await import("./embeddings.worker-GH7zdYqF.js")).default;
|
|
59
|
+
return new e();
|
|
60
60
|
}
|
|
61
|
-
},
|
|
62
|
-
...
|
|
63
|
-
...
|
|
64
|
-
}),
|
|
65
|
-
agentExecutionContext:
|
|
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:
|
|
74
|
+
currentIntent: x({
|
|
75
75
|
default: () => "none",
|
|
76
|
-
reducer:
|
|
76
|
+
reducer: L
|
|
77
77
|
}),
|
|
78
|
-
requiresFollowUp:
|
|
78
|
+
requiresFollowUp: x({
|
|
79
79
|
default: () => !0,
|
|
80
|
-
reducer:
|
|
80
|
+
reducer: L
|
|
81
81
|
}),
|
|
82
|
-
stepCount:
|
|
82
|
+
stepCount: x({
|
|
83
83
|
default: () => 0,
|
|
84
|
-
reducer: (
|
|
84
|
+
reducer: (e, t) => t ?? e + 1
|
|
85
85
|
})
|
|
86
|
-
}),
|
|
87
|
-
await
|
|
88
|
-
}, gt = async (
|
|
89
|
-
await
|
|
90
|
-
},
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
if (
|
|
94
|
-
const n = new
|
|
95
|
-
|
|
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 =
|
|
98
|
-
return await
|
|
99
|
-
},
|
|
100
|
-
if (typeof
|
|
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
|
|
103
|
-
return
|
|
104
|
-
},
|
|
105
|
-
switch (
|
|
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
|
-
},
|
|
118
|
-
const r =
|
|
119
|
-
return s === "unknown" && console.warn(`Registered agent "${
|
|
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 ??
|
|
119
|
+
summary: n ?? r ?? Me(s),
|
|
122
120
|
status: s
|
|
123
121
|
};
|
|
124
|
-
},
|
|
125
|
-
const r =
|
|
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: ${
|
|
128
|
-
await
|
|
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
|
-
...
|
|
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
|
-
...
|
|
143
|
-
messages: [...
|
|
144
|
-
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 =
|
|
147
|
+
i = Re(s.agent.name, d), await f({ text: `Finished executing registered agent: ${s.agent.name}` }, t);
|
|
150
148
|
} catch (d) {
|
|
151
|
-
if (
|
|
149
|
+
if (ne(d))
|
|
152
150
|
throw d;
|
|
153
|
-
const
|
|
154
|
-
console.error(`Agent "${s.agent.name}" failed:`, d), await
|
|
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: ${
|
|
157
|
-
summary: `Agent execution failed: ${
|
|
154
|
+
outputMessage: `Agent execution failed: ${u}`,
|
|
155
|
+
summary: `Agent execution failed: ${u}`
|
|
158
156
|
};
|
|
159
157
|
}
|
|
160
|
-
const c = i.outputMessage, o = [...
|
|
158
|
+
const c = i.outputMessage, o = [...e.agentExecutionContext.messages];
|
|
161
159
|
if (c) {
|
|
162
|
-
const d = c.length >
|
|
160
|
+
const d = c.length > $ ? `${c.slice(0, $ - 14)}
|
|
163
161
|
[truncated]` : c;
|
|
164
|
-
o.push(new
|
|
162
|
+
o.push(new k(d));
|
|
165
163
|
}
|
|
166
164
|
return {
|
|
167
|
-
...
|
|
168
|
-
stepCount:
|
|
165
|
+
...e,
|
|
166
|
+
stepCount: e.stepCount + 1,
|
|
167
|
+
requiresFollowUp: i.status === "failed" ? !0 : e.requiresFollowUp,
|
|
169
168
|
agentExecutionContext: {
|
|
170
|
-
...
|
|
169
|
+
...e.agentExecutionContext,
|
|
171
170
|
messages: o,
|
|
172
171
|
priorSteps: [
|
|
173
|
-
...
|
|
172
|
+
...e.agentExecutionContext.priorSteps ?? [],
|
|
174
173
|
{
|
|
175
174
|
agentId: s.agent.id,
|
|
176
|
-
assignedTask:
|
|
177
|
-
summary: i.
|
|
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
|
-
},
|
|
184
|
-
const n = t
|
|
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: " +
|
|
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
|
-
},
|
|
189
|
-
const { agent:
|
|
190
|
-
return { structuredResponse: (await
|
|
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
|
-
},
|
|
195
|
+
}, K = (e) => async (t, r) => {
|
|
197
196
|
const n = new Headers(r?.headers);
|
|
198
|
-
return n.delete("Authorization"), n.delete("api-key"),
|
|
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 (
|
|
203
|
-
const r =
|
|
204
|
-
return new
|
|
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
|
-
...
|
|
207
|
+
...e !== "default" && { temperature: t },
|
|
209
208
|
configuration: {
|
|
210
209
|
baseURL: a,
|
|
211
|
-
fetch:
|
|
210
|
+
fetch: K(n.token)
|
|
212
211
|
}
|
|
213
212
|
});
|
|
214
|
-
},
|
|
215
|
-
const
|
|
216
|
-
return new
|
|
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:
|
|
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
|
|
233
|
-
const
|
|
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
|
-
},
|
|
238
|
+
}, Le = async (e, t) => {
|
|
240
239
|
try {
|
|
241
|
-
await
|
|
242
|
-
const s = (
|
|
243
|
-
id:
|
|
244
|
-
name:
|
|
245
|
-
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
|
|
249
|
-
const a = await
|
|
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:
|
|
252
|
-
userRequest:
|
|
253
|
-
},
|
|
254
|
-
model: await b("
|
|
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:
|
|
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
|
-
|
|
269
|
+
me({ runLimit: 2 })
|
|
271
270
|
]
|
|
272
271
|
}), { structuredResponse: y } = await Ce({
|
|
273
|
-
agent:
|
|
274
|
-
messages:
|
|
275
|
-
config:
|
|
276
|
-
}),
|
|
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 =
|
|
279
|
-
...
|
|
277
|
+
), g = p.intent ?? "none", S = {
|
|
278
|
+
...e,
|
|
280
279
|
currentIntent: g,
|
|
281
|
-
requiresFollowUp:
|
|
280
|
+
requiresFollowUp: p.requiresFollowUp,
|
|
282
281
|
agentExecutionContext: {
|
|
283
|
-
...
|
|
284
|
-
assignedTask:
|
|
282
|
+
...e.agentExecutionContext,
|
|
283
|
+
assignedTask: p.assignedTask ?? ""
|
|
285
284
|
}
|
|
286
285
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
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
|
|
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
|
-
},
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
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(
|
|
306
|
-
const { agent: r } =
|
|
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,
|
|
331
|
+
this.agentRegistry.set(r.id, t);
|
|
310
332
|
}
|
|
311
|
-
get(
|
|
312
|
-
return this.agentRegistry.get(
|
|
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
|
|
340
|
+
class _e {
|
|
319
341
|
/**
|
|
320
342
|
* Create a new InterruptHandler tied to a specific compiled graph and config.
|
|
321
343
|
*/
|
|
322
|
-
constructor(
|
|
323
|
-
this.graph =
|
|
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((
|
|
330
|
-
this.resolveWait =
|
|
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(
|
|
358
|
+
handle(t, r) {
|
|
337
359
|
try {
|
|
338
360
|
const n = {
|
|
339
|
-
agentId:
|
|
340
|
-
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
|
|
366
|
-
let
|
|
367
|
-
for (let r =
|
|
368
|
-
if (
|
|
369
|
-
|
|
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
|
|
394
|
+
return t === -1 ? "" : e.slice(t + 1).filter((r) => r instanceof k).map((r) => r.content).join(`
|
|
373
395
|
`);
|
|
374
|
-
},
|
|
396
|
+
}, B = async (e) => {
|
|
375
397
|
try {
|
|
376
|
-
return await (await
|
|
377
|
-
} catch (
|
|
378
|
-
throw console.error("Failed to generate embeddings:",
|
|
398
|
+
return await (await Ae()).embedDocuments(e);
|
|
399
|
+
} catch (t) {
|
|
400
|
+
throw console.error("Failed to generate embeddings:", t), t;
|
|
379
401
|
}
|
|
380
|
-
},
|
|
381
|
-
const r =
|
|
402
|
+
}, J = async (e, t) => {
|
|
403
|
+
const r = t.get(e);
|
|
382
404
|
if (r)
|
|
383
405
|
return r;
|
|
384
|
-
const n = await
|
|
385
|
-
return
|
|
406
|
+
const n = await B([e]);
|
|
407
|
+
return t.set(e, n[0]), n[0];
|
|
386
408
|
};
|
|
387
|
-
async function
|
|
409
|
+
async function We(e, t, r, n) {
|
|
388
410
|
const s = `req-${Date.now()}`, i = {
|
|
389
411
|
type: "layerSearch",
|
|
390
|
-
precomputedEmbedding: n ? await
|
|
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
|
-
|
|
420
|
+
t.addEventListener("message", o, { once: !0 }), t.postMessage(i);
|
|
399
421
|
});
|
|
400
422
|
}
|
|
401
|
-
function
|
|
402
|
-
const { worker:
|
|
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
|
|
431
|
+
return await We(r, t, n, s);
|
|
410
432
|
}
|
|
411
433
|
};
|
|
412
434
|
}
|
|
413
435
|
const Ne = async ({
|
|
414
|
-
combinedQuery:
|
|
415
|
-
layerIds:
|
|
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
|
|
443
|
+
const i = `req-${Date.now()}`, c = a ? await J(e, a) : void 0, o = {
|
|
422
444
|
type: "fieldSearch",
|
|
423
|
-
layerIdForFieldsSearch:
|
|
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
|
|
431
|
-
if (
|
|
452
|
+
const u = (m) => {
|
|
453
|
+
if (m.data.requestId !== i)
|
|
432
454
|
return;
|
|
433
|
-
const y =
|
|
434
|
-
layerId:
|
|
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",
|
|
461
|
+
r.addEventListener("message", u, { once: !0 }), r.postMessage(o);
|
|
440
462
|
});
|
|
441
463
|
};
|
|
442
|
-
function He(
|
|
443
|
-
const { worker:
|
|
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:
|
|
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
|
|
479
|
+
const X = "0.1", w = 1536, Q = "openai", Y = T.default, A = `Name: {name}
|
|
458
480
|
Title: {title}
|
|
459
|
-
Description: {description}`,
|
|
481
|
+
Description: {description}`, F = `Name: {name}
|
|
460
482
|
Alias: {alias}
|
|
461
|
-
Description: {description}`,
|
|
462
|
-
schemaVersion: l.literal(
|
|
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(
|
|
466
|
-
model: l.literal(
|
|
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(
|
|
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 = (
|
|
495
|
-
const
|
|
496
|
-
if (!
|
|
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
|
|
499
|
-
}, Ve = (
|
|
520
|
+
return t.data;
|
|
521
|
+
}, Ve = (e, t) => {
|
|
500
522
|
const r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
501
|
-
if (
|
|
502
|
-
s instanceof
|
|
503
|
-
}),
|
|
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
|
|
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 (
|
|
563
|
+
}, ze = async (e) => {
|
|
542
564
|
try {
|
|
543
|
-
return (await
|
|
565
|
+
return (await he(e, {
|
|
544
566
|
responseType: "json"
|
|
545
567
|
})).data;
|
|
546
|
-
} catch (
|
|
547
|
-
throw new Error(`Failed to fetch data from ${
|
|
568
|
+
} catch (t) {
|
|
569
|
+
throw new Error(`Failed to fetch data from ${e}: ${String(t)}`);
|
|
548
570
|
}
|
|
549
|
-
}, Ge = async (
|
|
550
|
-
const
|
|
551
|
-
if (!
|
|
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
|
|
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
|
|
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(
|
|
569
|
-
const r = new
|
|
590
|
+
static async init(t) {
|
|
591
|
+
const r = new ee();
|
|
570
592
|
try {
|
|
571
|
-
if (
|
|
572
|
-
await
|
|
573
|
-
const n = await Ge(
|
|
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
|
-
|
|
597
|
+
t.view.map
|
|
576
598
|
);
|
|
577
|
-
r.layersAndFieldsRegistry = s, r.embeddingsWorker = await
|
|
599
|
+
r.layersAndFieldsRegistry = s, r.embeddingsWorker = await we(n);
|
|
578
600
|
}
|
|
579
|
-
return
|
|
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(
|
|
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, !
|
|
621
|
+
if (++this.streamEpoch, !t.trim())
|
|
600
622
|
return;
|
|
601
|
-
this.threadId = String(Date.now()), this.graph || (this.graph =
|
|
602
|
-
const r = this.embeddingsWorker ?
|
|
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:
|
|
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
|
|
624
|
-
if (!
|
|
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 =
|
|
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(),
|
|
629
|
-
yield* this.pipeStream(g,
|
|
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
|
|
645
|
-
this.chatHistory =
|
|
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:
|
|
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(
|
|
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,
|
|
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(
|
|
674
|
-
for await (const n of
|
|
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 = (
|
|
696
|
-
const
|
|
697
|
-
for (const n of
|
|
698
|
-
if (
|
|
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 &&
|
|
723
|
+
a.id && t.add(a.id);
|
|
702
724
|
});
|
|
703
725
|
}
|
|
704
|
-
return
|
|
705
|
-
if (
|
|
726
|
+
return e.filter((n) => {
|
|
727
|
+
if (ce(n)) {
|
|
706
728
|
const s = n;
|
|
707
|
-
return
|
|
729
|
+
return t.has(s.tool_call_id);
|
|
708
730
|
}
|
|
709
731
|
return !0;
|
|
710
732
|
});
|
|
711
|
-
}, D = (
|
|
712
|
-
const r =
|
|
713
|
-
return
|
|
714
|
-
}, Be = async (
|
|
715
|
-
const { promptText:
|
|
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 (
|
|
718
|
-
const { promptText:
|
|
719
|
-
promptText:
|
|
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
|
-
},
|
|
729
|
-
const { promptText:
|
|
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 (
|
|
732
|
-
const { promptText:
|
|
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 =
|
|
735
|
-
name:
|
|
736
|
-
description:
|
|
737
|
-
valueType:
|
|
738
|
-
alias:
|
|
739
|
-
}), Xe =
|
|
740
|
-
fields:
|
|
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
|
|
764
|
+
function _(e, t) {
|
|
743
765
|
const r = /* @__PURE__ */ new Map();
|
|
744
|
-
for (const n of
|
|
745
|
-
const s =
|
|
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:
|
|
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 (
|
|
758
|
-
const r = await
|
|
759
|
-
const { name: c, type: o, alias: d, description:
|
|
760
|
-
return [`Name: ${c}`, `Type: ${o}`, `Alias: ${d}`, `Description: ${
|
|
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
|
|
786
|
+
return _(e, { fields: [] });
|
|
765
787
|
const s = {
|
|
766
|
-
existingItemTitle:
|
|
767
|
-
existingItemDescription:
|
|
768
|
-
existingLayerTitle:
|
|
769
|
-
existingLayerDescription:
|
|
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
|
|
793
|
+
}, a = await te({
|
|
772
794
|
promptText: r,
|
|
773
795
|
schema: Xe,
|
|
774
796
|
inputVariables: s
|
|
775
797
|
});
|
|
776
|
-
return
|
|
777
|
-
}, Ye =
|
|
778
|
-
title:
|
|
779
|
-
description:
|
|
780
|
-
name:
|
|
781
|
-
}), Ze = async (
|
|
782
|
-
const n = await
|
|
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:
|
|
785
|
-
existingLayerDescription:
|
|
786
|
-
existingLayerSnippet:
|
|
787
|
-
layerGeometryType:
|
|
806
|
+
existingLayerTitle: e.title,
|
|
807
|
+
existingLayerDescription: e.portalItem?.description,
|
|
808
|
+
existingLayerSnippet: e.portalItem?.snippet,
|
|
809
|
+
layerGeometryType: e.geometryType
|
|
788
810
|
};
|
|
789
|
-
return { ...await
|
|
811
|
+
return { ...await te({
|
|
790
812
|
promptText: n,
|
|
791
813
|
schema: Ye,
|
|
792
814
|
inputVariables: a
|
|
793
|
-
}), name:
|
|
794
|
-
}, et = async (
|
|
795
|
-
const
|
|
796
|
-
for (const s of
|
|
797
|
-
if (s instanceof
|
|
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 (
|
|
806
|
-
await
|
|
807
|
-
const
|
|
808
|
-
schemaVersion:
|
|
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:
|
|
812
|
-
model:
|
|
833
|
+
modelProvider: Q,
|
|
834
|
+
model: Y,
|
|
813
835
|
dimensions: w,
|
|
814
836
|
templates: {
|
|
815
837
|
layer: A,
|
|
816
|
-
field:
|
|
838
|
+
field: F
|
|
817
839
|
}
|
|
818
840
|
},
|
|
819
841
|
layers: r
|
|
820
|
-
}, s =
|
|
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 (
|
|
825
|
-
const
|
|
826
|
-
for (const [i, { fieldRegistry: c, layerItem: o }] of
|
|
827
|
-
const d =
|
|
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
|
-
|
|
833
|
-
const
|
|
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 [,
|
|
842
|
-
const y =
|
|
843
|
-
name:
|
|
844
|
-
alias:
|
|
845
|
-
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
|
-
|
|
848
|
-
name:
|
|
849
|
-
alias:
|
|
850
|
-
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(
|
|
876
|
+
r.push(u);
|
|
855
877
|
}
|
|
856
|
-
const n = await
|
|
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
|
-
},
|
|
862
|
-
if (
|
|
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 <
|
|
866
|
-
const o =
|
|
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
|
-
|
|
898
|
+
ee as Orchestrator,
|
|
877
899
|
yt as cosineSimilarity,
|
|
878
900
|
b as createChatModel,
|
|
879
901
|
ft as createWebmapEmbeddings,
|
|
880
|
-
|
|
881
|
-
|
|
902
|
+
B as getEmbeddings,
|
|
903
|
+
te as invokeStructuredPrompt,
|
|
882
904
|
pt as invokeTextPrompt,
|
|
883
905
|
ht as invokeToolPrompt,
|
|
884
|
-
|
|
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" | "
|
|
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}
|
package/dist/types/types.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export interface AgentExecutionContext {
|
|
|
62
62
|
userRequest: string;
|
|
63
63
|
assignedTask: string;
|
|
64
64
|
messages: ChatHistory;
|
|
65
|
-
priorSteps
|
|
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" | "
|
|
78
|
+
export type AgentStatus = "failed" | "success" | "unknown";
|