@arcgis/ai-orchestrator 5.1.0-next.89 → 5.1.0-next.90
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 +166 -163
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
import
|
|
1
|
+
import R from "@arcgis/core/identity/IdentityManager.js";
|
|
2
2
|
import S from "@arcgis/core/portal/Portal.js";
|
|
3
|
-
import { Annotation as x, isGraphInterrupt as
|
|
4
|
-
import { HumanMessage as
|
|
5
|
-
import { dispatchCustomEvent as
|
|
3
|
+
import { Annotation as x, isGraphInterrupt as se, StateGraph as ie, START as ae, END as oe, MemorySaver as ce } from "@langchain/langgraph/web";
|
|
4
|
+
import { HumanMessage as W, AIMessage as A, isAIMessage as de, isToolMessage as le } from "@langchain/core/messages";
|
|
5
|
+
import { dispatchCustomEvent as N } from "@langchain/core/callbacks/dispatch/web";
|
|
6
6
|
import h, { z as l } from "zod";
|
|
7
|
-
import { ChatPromptTemplate as
|
|
8
|
-
import { createAgent as
|
|
9
|
-
import { ChatOpenAI as
|
|
10
|
-
import * as
|
|
11
|
-
import
|
|
12
|
-
import
|
|
13
|
-
const
|
|
7
|
+
import { ChatPromptTemplate as H, SystemMessagePromptTemplate as ue } from "@langchain/core/prompts";
|
|
8
|
+
import { createAgent as me, summarizationMiddleware as ge, modelCallLimitMiddleware as pe } from "langchain";
|
|
9
|
+
import { ChatOpenAI as he, OpenAIEmbeddings as fe } from "@langchain/openai";
|
|
10
|
+
import * as O from "@arcgis/core/core/reactiveUtils.js";
|
|
11
|
+
import V from "@arcgis/core/layers/FeatureLayer.js";
|
|
12
|
+
import ye from "@arcgis/core/request.js";
|
|
13
|
+
const z = {
|
|
14
14
|
advanced: "gpt-5.2",
|
|
15
15
|
default: "gpt-5-mini",
|
|
16
16
|
fast: "gpt-5.4-nano"
|
|
@@ -18,13 +18,13 @@ const V = {
|
|
|
18
18
|
default: "text-embedding-ada-002"
|
|
19
19
|
}, M = /* @__PURE__ */ new Map();
|
|
20
20
|
let E = null;
|
|
21
|
-
const
|
|
21
|
+
const we = () => {
|
|
22
22
|
const t = S.getDefault().helperServices;
|
|
23
23
|
if (!t?.aiModels?.url)
|
|
24
24
|
throw new Error("AI Models Service URL is not defined in the portal's helper services.");
|
|
25
25
|
return t.aiModels.url;
|
|
26
|
-
},
|
|
27
|
-
const t =
|
|
26
|
+
}, G = async (e) => {
|
|
27
|
+
const t = we();
|
|
28
28
|
M.size === 0 && (E || (E = (async () => {
|
|
29
29
|
try {
|
|
30
30
|
const n = await fetch(`${t}/models`);
|
|
@@ -39,8 +39,8 @@ const fe = () => {
|
|
|
39
39
|
if (!r)
|
|
40
40
|
throw new Error(`Model '${e}' is not available in the discovery service.`);
|
|
41
41
|
return r.endpoint;
|
|
42
|
-
},
|
|
43
|
-
const t = await
|
|
42
|
+
}, ve = async (e = "default") => await G(z[e]), B = async (e = "default") => await G(C[e]), xe = async (e) => {
|
|
43
|
+
const t = await be(), r = await B("default"), n = S.getDefault(), a = (await R.getCredential(`${n.url}/sharing`)).token, i = {
|
|
44
44
|
type: "generateEmbeddings",
|
|
45
45
|
webmapEmbeddings: e,
|
|
46
46
|
auth: { apiUrl: r, token: a }
|
|
@@ -53,15 +53,15 @@ const fe = () => {
|
|
|
53
53
|
};
|
|
54
54
|
t.addEventListener("message", d), t.addEventListener("error", u, { once: !0 });
|
|
55
55
|
}), t;
|
|
56
|
-
},
|
|
56
|
+
}, be = async () => {
|
|
57
57
|
{
|
|
58
58
|
const e = (await import("./embeddings.worker-GH7zdYqF.js")).default;
|
|
59
59
|
return new e();
|
|
60
60
|
}
|
|
61
|
-
}, L = (e, t) => t,
|
|
61
|
+
}, L = (e, t) => t, Ee = (e, t) => ({
|
|
62
62
|
...e,
|
|
63
63
|
...t
|
|
64
|
-
}),
|
|
64
|
+
}), Se = x.Root({
|
|
65
65
|
agentExecutionContext: x({
|
|
66
66
|
default: () => ({
|
|
67
67
|
userRequest: "",
|
|
@@ -70,7 +70,7 @@ const fe = () => {
|
|
|
70
70
|
messages: [],
|
|
71
71
|
sharedState: {}
|
|
72
72
|
}),
|
|
73
|
-
reducer:
|
|
73
|
+
reducer: Ee
|
|
74
74
|
}),
|
|
75
75
|
currentIntent: x({
|
|
76
76
|
default: () => "none",
|
|
@@ -85,24 +85,24 @@ const fe = () => {
|
|
|
85
85
|
reducer: (e, t) => t ?? e + 1
|
|
86
86
|
})
|
|
87
87
|
}), f = async (e, t) => {
|
|
88
|
-
await
|
|
89
|
-
},
|
|
90
|
-
await
|
|
91
|
-
},
|
|
88
|
+
await N("trace_message", e, t);
|
|
89
|
+
}, yt = async (e, t) => {
|
|
90
|
+
await N("graph_ux_suggestion", e, t);
|
|
91
|
+
}, Ie = (e) => {
|
|
92
92
|
e.currentIntent = "none";
|
|
93
|
-
},
|
|
93
|
+
}, Me = async (e, t) => {
|
|
94
94
|
if (e.agentExecutionContext.userRequest) {
|
|
95
|
-
const n = new
|
|
96
|
-
e.agentExecutionContext.messages = [...e.agentExecutionContext.messages, n],
|
|
95
|
+
const n = new W(e.agentExecutionContext.userRequest.trim());
|
|
96
|
+
e.agentExecutionContext.messages = [...e.agentExecutionContext.messages, n], Ie(e);
|
|
97
97
|
}
|
|
98
98
|
const r = t?.configurable?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
|
|
99
99
|
return await f({ text: `Available agents: ${[...r].join(", ")}` }, t), await f({ text: "Analyzing user input" }, t), e;
|
|
100
|
-
},
|
|
100
|
+
}, ke = async (e, t) => (await f({ text: "Exiting..." }, t), e), P = 4e3, q = (e) => {
|
|
101
101
|
if (typeof e != "string")
|
|
102
102
|
return;
|
|
103
103
|
const t = e.trim();
|
|
104
104
|
return t || void 0;
|
|
105
|
-
},
|
|
105
|
+
}, Re = (e) => {
|
|
106
106
|
switch (e) {
|
|
107
107
|
case "failed":
|
|
108
108
|
return "Agent failed without a summary.";
|
|
@@ -113,17 +113,17 @@ const fe = () => {
|
|
|
113
113
|
default:
|
|
114
114
|
return "Agent completed without a summary.";
|
|
115
115
|
}
|
|
116
|
-
},
|
|
117
|
-
const r =
|
|
116
|
+
}, Ae = (e) => typeof e == "object" && e !== null && !Array.isArray(e), Ce = (e, t) => {
|
|
117
|
+
const r = q(t?.outputMessage), n = q(t?.summary), s = t?.status, a = s === "success" || s === "failed" ? s : "unknown";
|
|
118
118
|
a === "unknown" && console.warn(`Agent "${e}" returned missing/invalid status. Defaulting to "unknown".`);
|
|
119
|
-
const i = t?.sharedStatePatch, o =
|
|
119
|
+
const i = t?.sharedStatePatch, o = Ae(i) ? i : void 0;
|
|
120
120
|
return i !== void 0 && o === void 0 && console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`), {
|
|
121
121
|
outputMessage: r,
|
|
122
|
-
summary: n ?? r ??
|
|
122
|
+
summary: n ?? r ?? Re(a),
|
|
123
123
|
status: a,
|
|
124
124
|
sharedStatePatch: o
|
|
125
125
|
};
|
|
126
|
-
},
|
|
126
|
+
}, Te = async (e, t) => {
|
|
127
127
|
const r = t?.configurable, { agentRegistry: n } = r.services, s = n?.get(e.currentIntent);
|
|
128
128
|
if (!s)
|
|
129
129
|
return console.warn(`No agent found for intent: ${e.currentIntent}`), e;
|
|
@@ -151,9 +151,9 @@ const fe = () => {
|
|
|
151
151
|
},
|
|
152
152
|
a
|
|
153
153
|
);
|
|
154
|
-
i =
|
|
154
|
+
i = Ce(s.agent.name, d), await f({ text: `Finished executing registered agent: ${s.agent.name}` }, t);
|
|
155
155
|
} catch (d) {
|
|
156
|
-
if (
|
|
156
|
+
if (se(d))
|
|
157
157
|
throw d;
|
|
158
158
|
const u = d instanceof Error ? d.message : String(d);
|
|
159
159
|
console.error(`Agent "${s.agent.name}" failed:`, d), await f({ text: `Registered agent failed: ${s.agent.name}. ${u}` }, t), i = {
|
|
@@ -164,9 +164,9 @@ const fe = () => {
|
|
|
164
164
|
}
|
|
165
165
|
const o = i.outputMessage, c = [...e.agentExecutionContext.messages];
|
|
166
166
|
if (o) {
|
|
167
|
-
const d = o.length >
|
|
167
|
+
const d = o.length > P ? `${o.slice(0, P - 14)}
|
|
168
168
|
[truncated]` : o;
|
|
169
|
-
c.push(new
|
|
169
|
+
c.push(new A(d));
|
|
170
170
|
}
|
|
171
171
|
return {
|
|
172
172
|
...e,
|
|
@@ -190,12 +190,12 @@ const fe = () => {
|
|
|
190
190
|
}
|
|
191
191
|
}
|
|
192
192
|
};
|
|
193
|
-
},
|
|
193
|
+
}, Fe = (e, t, r) => {
|
|
194
194
|
const n = e[t];
|
|
195
195
|
return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((s, a) => {
|
|
196
196
|
(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." : ""))));
|
|
197
197
|
});
|
|
198
|
-
}, T = async (e) => (await
|
|
198
|
+
}, T = async (e) => (await Fe(/* @__PURE__ */ Object.assign({ "./field_descriptions_prompt.md": () => import("./field_descriptions_prompt-haMV_aoG.js"), "./intent_prompt.md": () => import("./intent_prompt-D6yvMy34.js"), "./layer_descriptions_prompt.md": () => import("./layer_descriptions_prompt-NAaKWdJi.js") }), `./${e}.md`, 2)).default, De = async (e) => {
|
|
199
199
|
const { agent: t, messages: r, config: n } = e;
|
|
200
200
|
return { structuredResponse: (await t.invoke(
|
|
201
201
|
{
|
|
@@ -210,8 +210,8 @@ const fe = () => {
|
|
|
210
210
|
headers: n
|
|
211
211
|
});
|
|
212
212
|
}, b = async (e = "default", t = 0) => {
|
|
213
|
-
const r = S.getDefault(), n = await
|
|
214
|
-
return new
|
|
213
|
+
const r = S.getDefault(), n = await R.getCredential(`${r.url}/sharing`), s = z[e], a = await ve(e);
|
|
214
|
+
return new he({
|
|
215
215
|
modelName: s,
|
|
216
216
|
apiKey: "dummy-key",
|
|
217
217
|
// 5-mini does not support temperature parameter
|
|
@@ -221,9 +221,9 @@ const fe = () => {
|
|
|
221
221
|
fetch: K(n.token)
|
|
222
222
|
}
|
|
223
223
|
});
|
|
224
|
-
},
|
|
225
|
-
const t = S.getDefault(), r = await
|
|
226
|
-
return new
|
|
224
|
+
}, $e = async (e = "default") => {
|
|
225
|
+
const t = S.getDefault(), r = await R.getCredential(`${t.url}/sharing`), n = C[e], s = await B(e);
|
|
226
|
+
return new fe({
|
|
227
227
|
modelName: n,
|
|
228
228
|
apiKey: "dummy-key",
|
|
229
229
|
configuration: {
|
|
@@ -233,20 +233,20 @@ const fe = () => {
|
|
|
233
233
|
batchSize: 2048,
|
|
234
234
|
maxConcurrency: 10
|
|
235
235
|
});
|
|
236
|
-
},
|
|
236
|
+
}, Le = l.object({
|
|
237
237
|
id: l.string().min(1),
|
|
238
238
|
name: l.string().min(1),
|
|
239
239
|
description: l.string().min(1)
|
|
240
240
|
});
|
|
241
|
-
l.array(
|
|
242
|
-
const
|
|
241
|
+
l.array(Le);
|
|
242
|
+
const U = (e) => JSON.stringify(e, null, 2), Pe = (e) => {
|
|
243
243
|
const t = e.map((n) => n.id), r = l.enum(t);
|
|
244
244
|
return l.object({
|
|
245
245
|
intent: r.nullable(),
|
|
246
246
|
assignedTask: l.string().nullable(),
|
|
247
247
|
requiresFollowUp: l.boolean()
|
|
248
248
|
});
|
|
249
|
-
},
|
|
249
|
+
}, qe = async (e, t) => {
|
|
250
250
|
try {
|
|
251
251
|
await f({ text: "Asking LLM to route to an agent" }, t);
|
|
252
252
|
const s = (t?.configurable?.services.agentRegistry?.list() ?? []).map(({ agent: v }) => ({
|
|
@@ -256,11 +256,11 @@ const q = (e) => JSON.stringify(e, null, 2), Le = (e) => {
|
|
|
256
256
|
}));
|
|
257
257
|
if (!s.length)
|
|
258
258
|
return await f({ text: "No agents registered; skipping intent detection" }, t), { ...e, currentIntent: "none" };
|
|
259
|
-
const a = await T("intent_prompt"), i =
|
|
259
|
+
const a = await T("intent_prompt"), i = U(s), o = Pe(s), c = {
|
|
260
260
|
registeredAgents: i,
|
|
261
|
-
priorSteps:
|
|
261
|
+
priorSteps: U(e.agentExecutionContext.priorSteps),
|
|
262
262
|
userRequest: e.agentExecutionContext.userRequest
|
|
263
|
-
}, u = await
|
|
263
|
+
}, u = await H.fromTemplate(a).format(c), m = me({
|
|
264
264
|
model: await b("fast"),
|
|
265
265
|
tools: [],
|
|
266
266
|
systemPrompt: u,
|
|
@@ -270,16 +270,16 @@ const q = (e) => JSON.stringify(e, null, 2), Le = (e) => {
|
|
|
270
270
|
// Preserve recent conversation context while summarizing older messages
|
|
271
271
|
// to control token usage without losing important intent signals.
|
|
272
272
|
// The trigger and keep parameters can be tuned based on token limits and behavior.
|
|
273
|
-
|
|
273
|
+
ge({
|
|
274
274
|
model: await b("fast"),
|
|
275
275
|
trigger: { tokens: 4e3 },
|
|
276
276
|
keep: { messages: 6 }
|
|
277
277
|
}),
|
|
278
278
|
// Enforce no loop/retry.
|
|
279
279
|
// 1 usual LLM call and 1 optional summarization call.
|
|
280
|
-
|
|
280
|
+
pe({ runLimit: 2 })
|
|
281
281
|
]
|
|
282
|
-
}), { structuredResponse: y } = await
|
|
282
|
+
}), { structuredResponse: y } = await De({
|
|
283
283
|
agent: m,
|
|
284
284
|
messages: e.agentExecutionContext.messages,
|
|
285
285
|
config: t
|
|
@@ -303,7 +303,7 @@ const q = (e) => JSON.stringify(e, null, 2), Le = (e) => {
|
|
|
303
303
|
agentExecutionContext: {
|
|
304
304
|
...e.agentExecutionContext,
|
|
305
305
|
assignedTask: "",
|
|
306
|
-
messages: [...e.agentExecutionContext.messages, new
|
|
306
|
+
messages: [...e.agentExecutionContext.messages, new A(v)],
|
|
307
307
|
priorSteps: [
|
|
308
308
|
...e.agentExecutionContext.priorSteps ?? [],
|
|
309
309
|
{
|
|
@@ -327,11 +327,11 @@ Requires Follow-Up: ${p.requiresFollowUp}`
|
|
|
327
327
|
} catch (r) {
|
|
328
328
|
throw await f({ text: "Error during intent detection" }, t), new Error(`Error during intent detection: ${r instanceof Error ? r.message : String(r)}`);
|
|
329
329
|
}
|
|
330
|
-
},
|
|
330
|
+
}, Ue = 3, _e = () => new ie(Se).addNode("ingestInput", Me).addNode("intentLLM", qe).addNode("executeRegisteredAgent", Te).addNode("exit", ke).addEdge(ae, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (t) => t.currentIntent === "none" ? "exit" : "executeRegisteredAgent").addConditionalEdges(
|
|
331
331
|
"executeRegisteredAgent",
|
|
332
|
-
(t) => t.stepCount >=
|
|
333
|
-
).addEdge("exit",
|
|
334
|
-
class
|
|
332
|
+
(t) => t.stepCount >= Ue || !t.requiresFollowUp ? "exit" : "intentLLM"
|
|
333
|
+
).addEdge("exit", oe);
|
|
334
|
+
class je {
|
|
335
335
|
constructor() {
|
|
336
336
|
this.agentRegistry = /* @__PURE__ */ new Map();
|
|
337
337
|
}
|
|
@@ -348,7 +348,7 @@ class Ue {
|
|
|
348
348
|
return [...this.agentRegistry.values()];
|
|
349
349
|
}
|
|
350
350
|
}
|
|
351
|
-
class
|
|
351
|
+
class We {
|
|
352
352
|
/**
|
|
353
353
|
* Create a new InterruptHandler tied to a specific compiled graph and config.
|
|
354
354
|
*/
|
|
@@ -395,32 +395,32 @@ class _e {
|
|
|
395
395
|
this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
|
|
396
396
|
}
|
|
397
397
|
}
|
|
398
|
-
const
|
|
398
|
+
const Ne = (e) => {
|
|
399
399
|
let t = -1;
|
|
400
400
|
for (let r = e.length - 1; r >= 0; r--)
|
|
401
|
-
if (e[r] instanceof
|
|
401
|
+
if (e[r] instanceof W) {
|
|
402
402
|
t = r;
|
|
403
403
|
break;
|
|
404
404
|
}
|
|
405
|
-
return t === -1 ? "" : e.slice(t + 1).filter((r) => r instanceof
|
|
405
|
+
return t === -1 ? "" : e.slice(t + 1).filter((r) => r instanceof A).map((r) => r.content).join(`
|
|
406
406
|
`);
|
|
407
|
-
},
|
|
407
|
+
}, J = async (e) => {
|
|
408
408
|
try {
|
|
409
|
-
return await (await
|
|
409
|
+
return await (await $e()).embedDocuments(e);
|
|
410
410
|
} catch (t) {
|
|
411
411
|
throw console.error("Failed to generate embeddings:", t), t;
|
|
412
412
|
}
|
|
413
|
-
},
|
|
413
|
+
}, X = async (e, t) => {
|
|
414
414
|
const r = t.get(e);
|
|
415
415
|
if (r)
|
|
416
416
|
return r;
|
|
417
|
-
const n = await
|
|
417
|
+
const n = await J([e]);
|
|
418
418
|
return t.set(e, n[0]), n[0];
|
|
419
419
|
};
|
|
420
|
-
async function
|
|
420
|
+
async function He(e, t, r, n) {
|
|
421
421
|
const s = `req-${Date.now()}`, i = {
|
|
422
422
|
type: "layerSearch",
|
|
423
|
-
precomputedEmbedding: n ? await
|
|
423
|
+
precomputedEmbedding: n ? await X(e, n) : void 0,
|
|
424
424
|
requestId: s,
|
|
425
425
|
minScore: r
|
|
426
426
|
};
|
|
@@ -431,7 +431,7 @@ async function We(e, t, r, n) {
|
|
|
431
431
|
t.addEventListener("message", c, { once: !0 }), t.postMessage(i);
|
|
432
432
|
});
|
|
433
433
|
}
|
|
434
|
-
function
|
|
434
|
+
function Oe(e) {
|
|
435
435
|
const { worker: t } = e;
|
|
436
436
|
return {
|
|
437
437
|
async searchLayers({
|
|
@@ -439,11 +439,11 @@ function Ne(e) {
|
|
|
439
439
|
minScore: n,
|
|
440
440
|
embeddingCache: s
|
|
441
441
|
}) {
|
|
442
|
-
return await
|
|
442
|
+
return await He(r, t, n, s);
|
|
443
443
|
}
|
|
444
444
|
};
|
|
445
445
|
}
|
|
446
|
-
const
|
|
446
|
+
const Ve = async ({
|
|
447
447
|
combinedQuery: e,
|
|
448
448
|
layerIds: t,
|
|
449
449
|
embeddingsWorker: r,
|
|
@@ -451,7 +451,7 @@ const He = async ({
|
|
|
451
451
|
topResults: s,
|
|
452
452
|
embeddingCache: a
|
|
453
453
|
}) => {
|
|
454
|
-
const i = `req-${Date.now()}`, o = a ? await
|
|
454
|
+
const i = `req-${Date.now()}`, o = a ? await X(e, a) : void 0, c = {
|
|
455
455
|
type: "fieldSearch",
|
|
456
456
|
layerIdForFieldsSearch: t,
|
|
457
457
|
precomputedEmbedding: o,
|
|
@@ -472,11 +472,11 @@ const He = async ({
|
|
|
472
472
|
r.addEventListener("message", u, { once: !0 }), r.postMessage(c);
|
|
473
473
|
});
|
|
474
474
|
};
|
|
475
|
-
function
|
|
475
|
+
function ze(e) {
|
|
476
476
|
const { worker: t } = e;
|
|
477
477
|
return {
|
|
478
478
|
async searchFields({ text: r, layerIds: n, minScore: s, topResults: a, embeddingCache: i }) {
|
|
479
|
-
return await
|
|
479
|
+
return await Ve({
|
|
480
480
|
combinedQuery: r,
|
|
481
481
|
layerIds: n,
|
|
482
482
|
embeddingsWorker: t,
|
|
@@ -487,20 +487,20 @@ function Oe(e) {
|
|
|
487
487
|
}
|
|
488
488
|
};
|
|
489
489
|
}
|
|
490
|
-
const
|
|
490
|
+
const Q = "0.1", w = 1536, Y = "openai", Z = C.default, F = `Name: {name}
|
|
491
491
|
Title: {title}
|
|
492
|
-
Description: {description}`,
|
|
492
|
+
Description: {description}`, D = `Name: {name}
|
|
493
493
|
Alias: {alias}
|
|
494
|
-
Description: {description}`,
|
|
495
|
-
schemaVersion: l.literal(
|
|
494
|
+
Description: {description}`, ee = l.object({
|
|
495
|
+
schemaVersion: l.literal(Q),
|
|
496
496
|
modified: l.number().int().nonnegative(),
|
|
497
497
|
embeddings: l.object({
|
|
498
|
-
modelProvider: l.literal(
|
|
499
|
-
model: l.literal(
|
|
498
|
+
modelProvider: l.literal(Y),
|
|
499
|
+
model: l.literal(Z),
|
|
500
500
|
dimensions: l.literal(w),
|
|
501
501
|
templates: l.object({
|
|
502
|
-
layer: l.string().default(
|
|
503
|
-
field: l.string().default(
|
|
502
|
+
layer: l.string().default(F),
|
|
503
|
+
field: l.string().default(D)
|
|
504
504
|
})
|
|
505
505
|
}),
|
|
506
506
|
layers: l.array(
|
|
@@ -524,15 +524,15 @@ Description: {description}`, Z = l.object({
|
|
|
524
524
|
)
|
|
525
525
|
})
|
|
526
526
|
).default([])
|
|
527
|
-
}),
|
|
528
|
-
const t =
|
|
527
|
+
}), Ge = (e) => {
|
|
528
|
+
const t = ee.safeParse(e);
|
|
529
529
|
if (!t.success)
|
|
530
530
|
throw new Error("Embeddings response validation failed. Regenerate embeddings.");
|
|
531
531
|
return t.data;
|
|
532
|
-
},
|
|
532
|
+
}, Be = (e, t) => {
|
|
533
533
|
const r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
534
534
|
if (t.allLayers.forEach((s) => {
|
|
535
|
-
s instanceof
|
|
535
|
+
s instanceof V && n.set(s.id, s);
|
|
536
536
|
}), e.length !== n.size)
|
|
537
537
|
throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
|
|
538
538
|
for (const s of e) {
|
|
@@ -558,7 +558,7 @@ Description: {description}`, Z = l.object({
|
|
|
558
558
|
);
|
|
559
559
|
o.set(c.name, {
|
|
560
560
|
name: c.name,
|
|
561
|
-
alias: c.alias,
|
|
561
|
+
alias: a.getFieldAlias(c.name) ?? c.alias,
|
|
562
562
|
description: c.description,
|
|
563
563
|
type: d.type || "unknown",
|
|
564
564
|
valueType: d.valueType || "unknown",
|
|
@@ -571,27 +571,27 @@ Description: {description}`, Z = l.object({
|
|
|
571
571
|
});
|
|
572
572
|
}
|
|
573
573
|
return r;
|
|
574
|
-
},
|
|
574
|
+
}, Ke = async (e) => {
|
|
575
575
|
try {
|
|
576
|
-
return (await
|
|
576
|
+
return (await ye(e, {
|
|
577
577
|
responseType: "json"
|
|
578
578
|
})).data;
|
|
579
579
|
} catch (t) {
|
|
580
580
|
throw new Error(`Failed to fetch data from ${e}: ${String(t)}`);
|
|
581
581
|
}
|
|
582
|
-
},
|
|
582
|
+
}, Je = async (e) => {
|
|
583
583
|
const t = e.map;
|
|
584
584
|
if (!t?.portalItem)
|
|
585
585
|
throw new Error("WebMap portal item is missing.");
|
|
586
586
|
const { resources: r } = await t.portalItem.fetchResources(), n = r.find((i) => i.resource.path === "embeddings-v01.json");
|
|
587
587
|
if (!n?.resource.url)
|
|
588
588
|
throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
|
|
589
|
-
const s = await
|
|
590
|
-
return
|
|
589
|
+
const s = await Ke(n.resource.url);
|
|
590
|
+
return Ge(s);
|
|
591
591
|
};
|
|
592
|
-
class
|
|
592
|
+
class te {
|
|
593
593
|
constructor() {
|
|
594
|
-
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.threadId = "", this.agentRegistry = new
|
|
594
|
+
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.threadId = "", this.agentRegistry = new je(), this.streamEpoch = 0;
|
|
595
595
|
}
|
|
596
596
|
/**
|
|
597
597
|
* Creates and returns an AI-ready Orchestrator instance.
|
|
@@ -599,15 +599,15 @@ class ee {
|
|
|
599
599
|
* @returns Ready Orchestrator.
|
|
600
600
|
*/
|
|
601
601
|
static async init(t) {
|
|
602
|
-
const r = new
|
|
602
|
+
const r = new te();
|
|
603
603
|
try {
|
|
604
604
|
if (t.view?.map) {
|
|
605
|
-
await
|
|
606
|
-
const n = await
|
|
605
|
+
await O.whenOnce(() => t.view.ready);
|
|
606
|
+
const n = await Je(t.view), s = Be(
|
|
607
607
|
n.layers,
|
|
608
608
|
t.view.map
|
|
609
609
|
);
|
|
610
|
-
r.layersAndFieldsRegistry = s, r.embeddingsWorker = await
|
|
610
|
+
r.layersAndFieldsRegistry = s, r.embeddingsWorker = await xe(n);
|
|
611
611
|
}
|
|
612
612
|
return t.agents?.forEach((n) => {
|
|
613
613
|
r.agentRegistry.register(n);
|
|
@@ -631,8 +631,8 @@ class ee {
|
|
|
631
631
|
throw new Error("Orchestrator has no registered agents.");
|
|
632
632
|
if (++this.streamEpoch, !t.trim())
|
|
633
633
|
return;
|
|
634
|
-
this.threadId = String(Date.now()), this.graph || (this.graph =
|
|
635
|
-
const r = this.embeddingsWorker ?
|
|
634
|
+
this.threadId = String(Date.now()), this.graph || (this.graph = _e().compile({ checkpointer: new ce() }));
|
|
635
|
+
const r = this.embeddingsWorker ? Oe({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? ze({ worker: this.embeddingsWorker }) : void 0, s = /* @__PURE__ */ new Map(), i = {
|
|
636
636
|
version: "v2",
|
|
637
637
|
streamMode: "custom",
|
|
638
638
|
configurable: {
|
|
@@ -663,7 +663,7 @@ class ee {
|
|
|
663
663
|
const p = (await this.graph.getState(i, { subgraphs: !0 })).tasks.find((g) => g.interrupts.length > 0)?.interrupts[0]?.value;
|
|
664
664
|
if (!p)
|
|
665
665
|
break;
|
|
666
|
-
this.currentInterrupt = p, this.interruptHandler = new
|
|
666
|
+
this.currentInterrupt = p, this.interruptHandler = new We(this.graph, i), yield { runId: this.threadId, timestamp: Date.now(), type: "interrupt", interrupt: p };
|
|
667
667
|
try {
|
|
668
668
|
const g = await this.interruptHandler.waitForUser(), I = ++this.streamEpoch;
|
|
669
669
|
yield* this.pipeStream(g, I);
|
|
@@ -686,7 +686,7 @@ class ee {
|
|
|
686
686
|
runId: this.threadId,
|
|
687
687
|
timestamp: Date.now(),
|
|
688
688
|
type: "completed",
|
|
689
|
-
result: { content:
|
|
689
|
+
result: { content: Ne(u.agentExecutionContext.messages) }
|
|
690
690
|
};
|
|
691
691
|
}
|
|
692
692
|
/**
|
|
@@ -732,30 +732,30 @@ class ee {
|
|
|
732
732
|
this.embeddingsWorker && (this.embeddingsWorker.terminate(), this.embeddingsWorker = void 0), this.orchestratorReady = !1;
|
|
733
733
|
}
|
|
734
734
|
}
|
|
735
|
-
const
|
|
735
|
+
const Xe = (e) => {
|
|
736
736
|
const t = /* @__PURE__ */ new Set();
|
|
737
737
|
for (const n of e)
|
|
738
|
-
if (
|
|
738
|
+
if (de(n)) {
|
|
739
739
|
const s = n;
|
|
740
740
|
s.tool_calls && s.tool_calls.length > 0 && s.tool_calls.forEach((a) => {
|
|
741
741
|
a.id && t.add(a.id);
|
|
742
742
|
});
|
|
743
743
|
}
|
|
744
744
|
return e.filter((n) => {
|
|
745
|
-
if (
|
|
745
|
+
if (le(n)) {
|
|
746
746
|
const s = n;
|
|
747
747
|
return t.has(s.tool_call_id);
|
|
748
748
|
}
|
|
749
749
|
return !0;
|
|
750
750
|
});
|
|
751
|
-
},
|
|
752
|
-
const r =
|
|
753
|
-
return
|
|
754
|
-
},
|
|
755
|
-
const { promptText: t, modelTier: r, temperature: n, messages: s } = e, a =
|
|
751
|
+
}, $ = (e, t) => {
|
|
752
|
+
const r = ue.fromTemplate(e);
|
|
753
|
+
return H.fromMessages([r, ...t]);
|
|
754
|
+
}, Qe = async (e) => {
|
|
755
|
+
const { promptText: t, modelTier: r, temperature: n, messages: s } = e, a = $(t, s ?? []), i = await b(r, n);
|
|
756
756
|
return a.pipe(i);
|
|
757
|
-
},
|
|
758
|
-
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a } = e, o = await (await
|
|
757
|
+
}, wt = async (e) => {
|
|
758
|
+
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a } = e, o = await (await Qe({
|
|
759
759
|
promptText: t,
|
|
760
760
|
modelTier: r,
|
|
761
761
|
temperature: n,
|
|
@@ -765,60 +765,63 @@ const Be = (e) => {
|
|
|
765
765
|
return o;
|
|
766
766
|
const c = o.content;
|
|
767
767
|
return typeof c == "string" ? c : JSON.stringify(c);
|
|
768
|
-
},
|
|
769
|
-
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a, schema: i } = e, o =
|
|
768
|
+
}, ne = async (e) => {
|
|
769
|
+
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a, schema: i } = e, o = $(t, s ?? []), d = (await b(r, n)).withStructuredOutput(i);
|
|
770
770
|
return await o.pipe(d).invoke(a ?? {});
|
|
771
|
-
},
|
|
772
|
-
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a, tools: i } = e, o = i.length > 0 ?
|
|
771
|
+
}, vt = async (e) => {
|
|
772
|
+
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: a, tools: i } = e, o = i.length > 0 ? Xe(s ?? []) : s ?? [], c = $(t, o), d = await b(r, n);
|
|
773
773
|
return await c.pipe(d.bindTools(i)).invoke(a ?? {});
|
|
774
|
-
},
|
|
774
|
+
}, Ye = h.object({
|
|
775
775
|
name: h.string(),
|
|
776
776
|
description: h.string(),
|
|
777
777
|
valueType: h.string(),
|
|
778
778
|
alias: h.string()
|
|
779
|
-
}),
|
|
780
|
-
fields: h.array(
|
|
781
|
-
})
|
|
782
|
-
|
|
779
|
+
}), Ze = h.object({
|
|
780
|
+
fields: h.array(Ye)
|
|
781
|
+
}), re = (e, t) => e.getFieldAlias(t) ?? void 0, k = (e, t) => re(e, t.name) ?? t.alias ?? "", et = (e, t) => {
|
|
782
|
+
const r = re(e, t.name);
|
|
783
|
+
return !!(r && r !== (t.alias ?? ""));
|
|
784
|
+
};
|
|
785
|
+
function _(e, t) {
|
|
783
786
|
const r = /* @__PURE__ */ new Map();
|
|
784
787
|
for (const n of e.fields) {
|
|
785
|
-
const s = t.fields.find((
|
|
788
|
+
const s = t.fields.find((c) => c.name === n.name), a = k(e, n), i = et(e, n), o = {
|
|
786
789
|
name: n.name,
|
|
787
790
|
type: n.type,
|
|
788
|
-
alias: s?.alias ??
|
|
791
|
+
alias: i ? a : s?.alias ?? a,
|
|
789
792
|
description: s?.description ?? n.description ?? "",
|
|
790
793
|
valueType: s?.valueType ?? n.valueType ?? "",
|
|
791
794
|
domain: e.getFieldDomain(n.name) ?? void 0
|
|
792
795
|
};
|
|
793
|
-
r.set(n.name,
|
|
796
|
+
r.set(n.name, o);
|
|
794
797
|
}
|
|
795
798
|
return r;
|
|
796
799
|
}
|
|
797
|
-
const
|
|
798
|
-
const r = await T("field_descriptions_prompt"), n = e.fields.filter((i) => !(i
|
|
799
|
-
const { name: o, type: c,
|
|
800
|
-
return [`Name: ${o}`, `Type: ${c}`, `Alias: ${
|
|
800
|
+
const tt = async (e) => {
|
|
801
|
+
const r = await T("field_descriptions_prompt"), n = e.fields.filter((i) => !(k(e, i) && i.description)).map((i) => {
|
|
802
|
+
const { name: o, type: c, description: d } = i, u = k(e, i);
|
|
803
|
+
return [`Name: ${o}`, `Type: ${c}`, `Alias: ${u}`, `Description: ${d ?? "N/A"}`].join(", ");
|
|
801
804
|
}).join(`
|
|
802
805
|
`);
|
|
803
806
|
if (n.length === 0)
|
|
804
|
-
return
|
|
807
|
+
return _(e, { fields: [] });
|
|
805
808
|
const s = {
|
|
806
809
|
existingItemTitle: e.portalItem?.title,
|
|
807
810
|
existingItemDescription: e.portalItem?.description,
|
|
808
811
|
existingLayerTitle: e.title,
|
|
809
812
|
existingLayerDescription: e.portalItem?.description,
|
|
810
813
|
fieldInformation: n
|
|
811
|
-
}, a = await
|
|
814
|
+
}, a = await ne({
|
|
812
815
|
promptText: r,
|
|
813
|
-
schema:
|
|
816
|
+
schema: Ze,
|
|
814
817
|
inputVariables: s
|
|
815
818
|
});
|
|
816
|
-
return
|
|
817
|
-
},
|
|
819
|
+
return _(e, a);
|
|
820
|
+
}, nt = h.object({
|
|
818
821
|
title: h.string(),
|
|
819
822
|
description: h.string(),
|
|
820
823
|
name: h.string().nullable()
|
|
821
|
-
}),
|
|
824
|
+
}), rt = async (e, t) => {
|
|
822
825
|
const n = await T("layer_descriptions_prompt"), s = Array.from(t.values()), a = {
|
|
823
826
|
fieldInformation: JSON.stringify(s, null, 2),
|
|
824
827
|
existingLayerTitle: e.title,
|
|
@@ -826,45 +829,45 @@ const Ye = async (e) => {
|
|
|
826
829
|
existingLayerSnippet: e.portalItem?.snippet,
|
|
827
830
|
layerGeometryType: e.geometryType
|
|
828
831
|
};
|
|
829
|
-
return { ...await
|
|
832
|
+
return { ...await ne({
|
|
830
833
|
promptText: n,
|
|
831
|
-
schema:
|
|
834
|
+
schema: nt,
|
|
832
835
|
inputVariables: a
|
|
833
836
|
}), name: e.title ?? null };
|
|
834
|
-
},
|
|
837
|
+
}, st = async (e) => {
|
|
835
838
|
const t = e.allLayers.toArray(), r = [], n = /* @__PURE__ */ new Map();
|
|
836
839
|
for (const s of t)
|
|
837
|
-
if (s instanceof
|
|
840
|
+
if (s instanceof V) {
|
|
838
841
|
const a = (async () => {
|
|
839
|
-
const i = await
|
|
842
|
+
const i = await tt(s), o = await rt(s, i);
|
|
840
843
|
n.set(s.id, { layerItem: o, fieldRegistry: i });
|
|
841
844
|
})();
|
|
842
845
|
r.push(a);
|
|
843
846
|
}
|
|
844
847
|
return await Promise.all(r), n;
|
|
845
|
-
},
|
|
846
|
-
await
|
|
847
|
-
const t = await
|
|
848
|
-
schemaVersion:
|
|
848
|
+
}, xt = async (e) => {
|
|
849
|
+
await O.whenOnce(() => e.ready);
|
|
850
|
+
const t = await st(e.map), { layers: r } = await it(t), n = {
|
|
851
|
+
schemaVersion: Q,
|
|
849
852
|
modified: Date.now(),
|
|
850
853
|
embeddings: {
|
|
851
|
-
modelProvider:
|
|
852
|
-
model:
|
|
854
|
+
modelProvider: Y,
|
|
855
|
+
model: Z,
|
|
853
856
|
dimensions: w,
|
|
854
857
|
templates: {
|
|
855
|
-
layer:
|
|
856
|
-
field:
|
|
858
|
+
layer: F,
|
|
859
|
+
field: D
|
|
857
860
|
}
|
|
858
861
|
},
|
|
859
862
|
layers: r
|
|
860
|
-
}, s =
|
|
863
|
+
}, s = ee.safeParse(n);
|
|
861
864
|
if (!s.success)
|
|
862
865
|
throw console.error("Schema Mismatch:", s.error.format()), new Error("Webmap embedding generation failed validation.");
|
|
863
866
|
return s.data;
|
|
864
|
-
},
|
|
867
|
+
}, it = async (e) => {
|
|
865
868
|
const t = [], r = [];
|
|
866
869
|
for (const [i, { fieldRegistry: o, layerItem: c }] of e.entries()) {
|
|
867
|
-
const d =
|
|
870
|
+
const d = j(F, {
|
|
868
871
|
name: c.name,
|
|
869
872
|
title: c.title,
|
|
870
873
|
description: c.description
|
|
@@ -879,7 +882,7 @@ const Ye = async (e) => {
|
|
|
879
882
|
fields: []
|
|
880
883
|
};
|
|
881
884
|
for (const [, m] of o.entries()) {
|
|
882
|
-
const y =
|
|
885
|
+
const y = j(D, {
|
|
883
886
|
name: m.name,
|
|
884
887
|
alias: m.alias,
|
|
885
888
|
description: m.description
|
|
@@ -893,12 +896,12 @@ const Ye = async (e) => {
|
|
|
893
896
|
}
|
|
894
897
|
r.push(u);
|
|
895
898
|
}
|
|
896
|
-
const n = await
|
|
899
|
+
const n = await J(t);
|
|
897
900
|
let s = 0;
|
|
898
901
|
return { layers: r.map((i) => (i.vector = n[s++], i.fields.forEach((o) => {
|
|
899
902
|
o.vector = n[s++];
|
|
900
903
|
}), i)) };
|
|
901
|
-
},
|
|
904
|
+
}, j = (e, t) => e.replace(/\{(\w+)\}/gu, (r, n) => t[n] ?? ""), bt = (e, t) => {
|
|
902
905
|
if (e.length !== t.length)
|
|
903
906
|
throw new Error("Vectors must be the same length");
|
|
904
907
|
let r = 0, n = 0, s = 0;
|
|
@@ -913,14 +916,14 @@ const Ye = async (e) => {
|
|
|
913
916
|
return Math.max(-1, Math.min(1, i));
|
|
914
917
|
};
|
|
915
918
|
export {
|
|
916
|
-
|
|
917
|
-
|
|
919
|
+
te as Orchestrator,
|
|
920
|
+
bt as cosineSimilarity,
|
|
918
921
|
b as createChatModel,
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
922
|
+
xt as createWebmapEmbeddings,
|
|
923
|
+
J as getEmbeddings,
|
|
924
|
+
ne as invokeStructuredPrompt,
|
|
925
|
+
wt as invokeTextPrompt,
|
|
926
|
+
vt as invokeToolPrompt,
|
|
924
927
|
f as sendTraceMessage,
|
|
925
|
-
|
|
928
|
+
yt as sendUXSuggestion
|
|
926
929
|
};
|