@arcgis/ai-orchestrator 5.1.0-next.90 → 5.1.0-next.91
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/dispatcherAgent/utils/agentResultUtils.d.ts +7 -0
- package/dist/dispatcherAgent/utils/sharedStateUtils.d.ts +7 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +247 -214
- package/dist/orchestrator/orchestratorEvents.d.ts +3 -3
- package/dist/registry/agentRegistry.d.ts +2 -1
- package/dist/types/types.d.ts +16 -3
- package/package.json +1 -1
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { SharedStatePatch, SharedState } from '../../types/types';
|
|
2
|
+
export declare const toSharedStatePatch: (value: unknown, agentName: string) => SharedStatePatch | undefined;
|
|
3
|
+
export declare const applySharedStatePatch: (params: {
|
|
4
|
+
previousSharedState: SharedState;
|
|
5
|
+
patch?: SharedStatePatch;
|
|
6
|
+
agentId: string;
|
|
7
|
+
}) => SharedState;
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,7 @@ export { createChatModel } from './providers/arcgis/aiFactory';
|
|
|
5
5
|
export { createWebmapEmbeddings } from './embeddings/webmapEmbeddings';
|
|
6
6
|
export { getEmbeddings } from './embeddings/embeddingsUtil';
|
|
7
7
|
export { cosineSimilarity } from './embeddings/cosineSimilarity';
|
|
8
|
-
export type { CustomConfigurableType, VectorSearchFieldResults, LayersAndFieldsRegistry, Services, FieldInfo, FieldStatistics, ChatHistory, AgentExecutionContext, AgentStatus, PriorStep, } from './types/types';
|
|
8
|
+
export type { CustomConfigurableType, VectorSearchFieldResults, LayersAndFieldsRegistry, Services, FieldInfo, FieldStatistics, ChatHistory, AgentExecutionContext, AgentStatus, PriorStep, SharedState, SharedStatePatch, } from './types/types';
|
|
9
9
|
export type { UXSuggestion } from './orchestrator/orchestratorEvents';
|
|
10
10
|
export type { UiInterrupt } from './hitl/types';
|
|
11
11
|
export type { AgentRegistration, AgentWithContext } from './registry/agentRegistry';
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
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 ie, StateGraph as ae, START as oe, END as ce, MemorySaver as de } from "@langchain/langgraph/web";
|
|
4
|
+
import { HumanMessage as N, AIMessage as A, isAIMessage as le, isToolMessage as ue } from "@langchain/core/messages";
|
|
5
|
+
import { dispatchCustomEvent as O } from "@langchain/core/callbacks/dispatch/web";
|
|
6
6
|
import h, { z as l } from "zod";
|
|
7
|
-
import { ChatPromptTemplate as H, SystemMessagePromptTemplate 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 me } from "@langchain/core/prompts";
|
|
8
|
+
import { createAgent as ge, summarizationMiddleware as pe, modelCallLimitMiddleware as he } from "langchain";
|
|
9
|
+
import { ChatOpenAI as fe, OpenAIEmbeddings as ye } from "@langchain/openai";
|
|
10
|
+
import * as V from "@arcgis/core/core/reactiveUtils.js";
|
|
11
|
+
import z from "@arcgis/core/layers/FeatureLayer.js";
|
|
12
|
+
import we from "@arcgis/core/request.js";
|
|
13
|
+
const B = {
|
|
14
14
|
advanced: "gpt-5.2",
|
|
15
15
|
default: "gpt-5-mini",
|
|
16
16
|
fast: "gpt-5.4-nano"
|
|
@@ -18,19 +18,19 @@ const z = {
|
|
|
18
18
|
default: "text-embedding-ada-002"
|
|
19
19
|
}, M = /* @__PURE__ */ new Map();
|
|
20
20
|
let E = null;
|
|
21
|
-
const
|
|
21
|
+
const ve = () => {
|
|
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
26
|
}, G = async (e) => {
|
|
27
|
-
const t =
|
|
27
|
+
const t = ve();
|
|
28
28
|
M.size === 0 && (E || (E = (async () => {
|
|
29
29
|
try {
|
|
30
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
|
-
(await n.json()).models.forEach((
|
|
33
|
+
(await n.json()).models.forEach((i) => M.set(i.name, i));
|
|
34
34
|
} catch (n) {
|
|
35
35
|
throw E = null, n;
|
|
36
36
|
}
|
|
@@ -39,13 +39,13 @@ const we = () => {
|
|
|
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
|
+
}, xe = async (e = "default") => await G(B[e]), K = async (e = "default") => await G(C[e]), be = async (e) => {
|
|
43
|
+
const t = await Ee(), r = await K("default"), n = S.getDefault(), i = (await R.getCredential(`${n.url}/sharing`)).token, a = {
|
|
44
44
|
type: "generateEmbeddings",
|
|
45
45
|
webmapEmbeddings: e,
|
|
46
|
-
auth: { apiUrl: r, token:
|
|
46
|
+
auth: { apiUrl: r, token: i }
|
|
47
47
|
};
|
|
48
|
-
return t.postMessage(
|
|
48
|
+
return t.postMessage(a), await new Promise((o, c) => {
|
|
49
49
|
const d = (m) => {
|
|
50
50
|
m.data === "completed" && (t.removeEventListener("message", d), o());
|
|
51
51
|
}, u = (m) => {
|
|
@@ -53,15 +53,15 @@ const we = () => {
|
|
|
53
53
|
};
|
|
54
54
|
t.addEventListener("message", d), t.addEventListener("error", u, { once: !0 });
|
|
55
55
|
}), t;
|
|
56
|
-
},
|
|
56
|
+
}, Ee = async () => {
|
|
57
57
|
{
|
|
58
58
|
const e = (await import("./embeddings.worker-GH7zdYqF.js")).default;
|
|
59
59
|
return new e();
|
|
60
60
|
}
|
|
61
|
-
},
|
|
61
|
+
}, P = (e, t) => t, Se = (e, t) => ({
|
|
62
62
|
...e,
|
|
63
63
|
...t
|
|
64
|
-
}),
|
|
64
|
+
}), Ie = x.Root({
|
|
65
65
|
agentExecutionContext: x({
|
|
66
66
|
default: () => ({
|
|
67
67
|
userRequest: "",
|
|
@@ -70,39 +70,71 @@ const we = () => {
|
|
|
70
70
|
messages: [],
|
|
71
71
|
sharedState: {}
|
|
72
72
|
}),
|
|
73
|
-
reducer:
|
|
73
|
+
reducer: Se
|
|
74
74
|
}),
|
|
75
75
|
currentIntent: x({
|
|
76
76
|
default: () => "none",
|
|
77
|
-
reducer:
|
|
77
|
+
reducer: P
|
|
78
78
|
}),
|
|
79
79
|
requiresFollowUp: x({
|
|
80
80
|
default: () => !0,
|
|
81
|
-
reducer:
|
|
81
|
+
reducer: P
|
|
82
82
|
}),
|
|
83
83
|
stepCount: x({
|
|
84
84
|
default: () => 0,
|
|
85
85
|
reducer: (e, t) => t ?? e + 1
|
|
86
86
|
})
|
|
87
87
|
}), f = async (e, t) => {
|
|
88
|
-
await
|
|
89
|
-
},
|
|
90
|
-
await
|
|
91
|
-
},
|
|
88
|
+
await O("trace_message", e, t);
|
|
89
|
+
}, vt = async (e, t) => {
|
|
90
|
+
await O("graph_ux_suggestion", e, t);
|
|
91
|
+
}, Me = (e) => {
|
|
92
92
|
e.currentIntent = "none";
|
|
93
|
-
},
|
|
93
|
+
}, ke = 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 N(e.agentExecutionContext.userRequest.trim());
|
|
96
|
+
e.agentExecutionContext.messages = [...e.agentExecutionContext.messages, n], Me(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
|
+
}, Re = async (e, t) => (await f({ text: "Exiting..." }, t), e), L = (e) => typeof e == "object" && e !== null && !Array.isArray(e), Ae = (e, t) => {
|
|
101
|
+
if (!L(e)) {
|
|
102
|
+
e !== void 0 && console.warn(`Agent "${t}" returned invalid sharedStatePatch. Ignoring it.`);
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
const r = {};
|
|
106
|
+
for (const [n, s] of Object.entries(e)) {
|
|
107
|
+
if (!L(s) || !("value" in s)) {
|
|
108
|
+
console.warn(
|
|
109
|
+
`Agent "${t}" returned invalid sharedStatePatch entry for key "${n}". Ignoring that entry.`
|
|
110
|
+
);
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
r[n] = { value: s.value };
|
|
114
|
+
}
|
|
115
|
+
return r;
|
|
116
|
+
}, Ce = (e) => {
|
|
117
|
+
const { previousSharedState: t, patch: r, agentId: n } = e;
|
|
118
|
+
if (!r)
|
|
119
|
+
return t;
|
|
120
|
+
const s = Date.now(), i = {
|
|
121
|
+
...t
|
|
122
|
+
};
|
|
123
|
+
for (const [a, o] of Object.entries(r))
|
|
124
|
+
o.value !== void 0 && (i[a] = {
|
|
125
|
+
value: o.value,
|
|
126
|
+
meta: {
|
|
127
|
+
updatedByAgentId: n,
|
|
128
|
+
updatedAt: s
|
|
129
|
+
}
|
|
130
|
+
});
|
|
131
|
+
return i;
|
|
132
|
+
}, q = (e) => {
|
|
101
133
|
if (typeof e != "string")
|
|
102
134
|
return;
|
|
103
135
|
const t = e.trim();
|
|
104
136
|
return t || void 0;
|
|
105
|
-
},
|
|
137
|
+
}, Te = (e) => {
|
|
106
138
|
switch (e) {
|
|
107
139
|
case "failed":
|
|
108
140
|
return "Agent failed without a summary.";
|
|
@@ -113,22 +145,22 @@ const we = () => {
|
|
|
113
145
|
default:
|
|
114
146
|
return "Agent completed without a summary.";
|
|
115
147
|
}
|
|
116
|
-
},
|
|
117
|
-
const r = q(t?.outputMessage), n = q(t?.summary), s = t?.status,
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
return
|
|
148
|
+
}, Fe = (e, t) => {
|
|
149
|
+
const r = q(t?.outputMessage), n = q(t?.summary), s = t?.status, i = s === "success" || s === "failed" ? s : "unknown";
|
|
150
|
+
i === "unknown" && console.warn(`Agent "${e}" returned missing/invalid status. Defaulting to "unknown".`);
|
|
151
|
+
const a = Ae(t?.sharedStatePatch, e);
|
|
152
|
+
return {
|
|
121
153
|
outputMessage: r,
|
|
122
|
-
summary: n ?? r ??
|
|
123
|
-
status:
|
|
124
|
-
sharedStatePatch:
|
|
154
|
+
summary: n ?? r ?? Te(i),
|
|
155
|
+
status: i,
|
|
156
|
+
sharedStatePatch: a
|
|
125
157
|
};
|
|
126
|
-
},
|
|
158
|
+
}, j = 4e3, De = async (e, t) => {
|
|
127
159
|
const r = t?.configurable, { agentRegistry: n } = r.services, s = n?.get(e.currentIntent);
|
|
128
160
|
if (!s)
|
|
129
161
|
return console.warn(`No agent found for intent: ${e.currentIntent}`), e;
|
|
130
162
|
await f({ text: `Executing registered agent: ${s.agent.name}` }, t);
|
|
131
|
-
const
|
|
163
|
+
const i = {
|
|
132
164
|
...t ?? {},
|
|
133
165
|
configurable: {
|
|
134
166
|
...r ?? {},
|
|
@@ -136,7 +168,7 @@ const we = () => {
|
|
|
136
168
|
context: s.getContext ? await s.getContext() : void 0
|
|
137
169
|
}
|
|
138
170
|
};
|
|
139
|
-
let
|
|
171
|
+
let a;
|
|
140
172
|
try {
|
|
141
173
|
const d = await s.agent.createGraph().compile().invoke(
|
|
142
174
|
{
|
|
@@ -149,29 +181,29 @@ const we = () => {
|
|
|
149
181
|
sharedState: structuredClone(e.agentExecutionContext.sharedState ?? {})
|
|
150
182
|
}
|
|
151
183
|
},
|
|
152
|
-
|
|
184
|
+
i
|
|
153
185
|
);
|
|
154
|
-
|
|
186
|
+
a = Fe(s.agent.name, d), await f({ text: `Finished executing registered agent: ${s.agent.name}` }, t);
|
|
155
187
|
} catch (d) {
|
|
156
|
-
if (
|
|
188
|
+
if (ie(d))
|
|
157
189
|
throw d;
|
|
158
190
|
const u = d instanceof Error ? d.message : String(d);
|
|
159
|
-
console.error(`Agent "${s.agent.name}" failed:`, d), await f({ text: `Registered agent failed: ${s.agent.name}. ${u}` }, t),
|
|
191
|
+
console.error(`Agent "${s.agent.name}" failed:`, d), await f({ text: `Registered agent failed: ${s.agent.name}. ${u}` }, t), a = {
|
|
160
192
|
status: "failed",
|
|
161
193
|
outputMessage: `Agent execution failed: ${u}`,
|
|
162
194
|
summary: `Agent execution failed: ${u}`
|
|
163
195
|
};
|
|
164
196
|
}
|
|
165
|
-
const o =
|
|
197
|
+
const o = a.outputMessage, c = [...e.agentExecutionContext.messages];
|
|
166
198
|
if (o) {
|
|
167
|
-
const d = o.length >
|
|
199
|
+
const d = o.length > j ? `${o.slice(0, j - 14)}
|
|
168
200
|
[truncated]` : o;
|
|
169
201
|
c.push(new A(d));
|
|
170
202
|
}
|
|
171
203
|
return {
|
|
172
204
|
...e,
|
|
173
205
|
stepCount: e.stepCount + 1,
|
|
174
|
-
requiresFollowUp:
|
|
206
|
+
requiresFollowUp: a.status === "failed" ? !0 : e.requiresFollowUp,
|
|
175
207
|
agentExecutionContext: {
|
|
176
208
|
...e.agentExecutionContext,
|
|
177
209
|
messages: c,
|
|
@@ -180,22 +212,23 @@ const we = () => {
|
|
|
180
212
|
{
|
|
181
213
|
agentId: s.agent.id,
|
|
182
214
|
assignedTask: e.agentExecutionContext.assignedTask,
|
|
183
|
-
summary:
|
|
184
|
-
status:
|
|
215
|
+
summary: a?.summary || "No summary provided.",
|
|
216
|
+
status: a?.status || "unknown"
|
|
185
217
|
}
|
|
186
218
|
],
|
|
187
|
-
sharedState: {
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
219
|
+
sharedState: Ce({
|
|
220
|
+
previousSharedState: e.agentExecutionContext.sharedState,
|
|
221
|
+
patch: a.sharedStatePatch,
|
|
222
|
+
agentId: s.agent.id
|
|
223
|
+
})
|
|
191
224
|
}
|
|
192
225
|
};
|
|
193
|
-
},
|
|
226
|
+
}, $e = (e, t, r) => {
|
|
194
227
|
const n = e[t];
|
|
195
|
-
return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((s,
|
|
196
|
-
(typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(
|
|
228
|
+
return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((s, i) => {
|
|
229
|
+
(typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(i.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
230
|
});
|
|
198
|
-
}, T = async (e) => (await
|
|
231
|
+
}, T = async (e) => (await $e(/* @__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, Pe = async (e) => {
|
|
199
232
|
const { agent: t, messages: r, config: n } = e;
|
|
200
233
|
return { structuredResponse: (await t.invoke(
|
|
201
234
|
{
|
|
@@ -203,50 +236,50 @@ const we = () => {
|
|
|
203
236
|
},
|
|
204
237
|
n
|
|
205
238
|
)).structuredResponse };
|
|
206
|
-
},
|
|
239
|
+
}, J = (e) => async (t, r) => {
|
|
207
240
|
const n = new Headers(r?.headers);
|
|
208
241
|
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, {
|
|
209
242
|
...r,
|
|
210
243
|
headers: n
|
|
211
244
|
});
|
|
212
245
|
}, b = async (e = "default", t = 0) => {
|
|
213
|
-
const r = S.getDefault(), n = await R.getCredential(`${r.url}/sharing`), s =
|
|
214
|
-
return new
|
|
246
|
+
const r = S.getDefault(), n = await R.getCredential(`${r.url}/sharing`), s = B[e], i = await xe(e);
|
|
247
|
+
return new fe({
|
|
215
248
|
modelName: s,
|
|
216
249
|
apiKey: "dummy-key",
|
|
217
250
|
// 5-mini does not support temperature parameter
|
|
218
251
|
...e !== "default" && { temperature: t },
|
|
219
252
|
configuration: {
|
|
220
|
-
baseURL:
|
|
221
|
-
fetch:
|
|
253
|
+
baseURL: i,
|
|
254
|
+
fetch: J(n.token)
|
|
222
255
|
}
|
|
223
256
|
});
|
|
224
|
-
},
|
|
225
|
-
const t = S.getDefault(), r = await R.getCredential(`${t.url}/sharing`), n = C[e], s = await
|
|
226
|
-
return new
|
|
257
|
+
}, Le = async (e = "default") => {
|
|
258
|
+
const t = S.getDefault(), r = await R.getCredential(`${t.url}/sharing`), n = C[e], s = await K(e);
|
|
259
|
+
return new ye({
|
|
227
260
|
modelName: n,
|
|
228
261
|
apiKey: "dummy-key",
|
|
229
262
|
configuration: {
|
|
230
263
|
baseURL: s,
|
|
231
|
-
fetch:
|
|
264
|
+
fetch: J(r.token)
|
|
232
265
|
},
|
|
233
266
|
batchSize: 2048,
|
|
234
267
|
maxConcurrency: 10
|
|
235
268
|
});
|
|
236
|
-
},
|
|
269
|
+
}, qe = l.object({
|
|
237
270
|
id: l.string().min(1),
|
|
238
271
|
name: l.string().min(1),
|
|
239
272
|
description: l.string().min(1)
|
|
240
273
|
});
|
|
241
|
-
l.array(
|
|
242
|
-
const U = (e) => JSON.stringify(e, null, 2),
|
|
274
|
+
l.array(qe);
|
|
275
|
+
const U = (e) => JSON.stringify(e, null, 2), je = (e) => {
|
|
243
276
|
const t = e.map((n) => n.id), r = l.enum(t);
|
|
244
277
|
return l.object({
|
|
245
278
|
intent: r.nullable(),
|
|
246
279
|
assignedTask: l.string().nullable(),
|
|
247
280
|
requiresFollowUp: l.boolean()
|
|
248
281
|
});
|
|
249
|
-
},
|
|
282
|
+
}, Ue = async (e, t) => {
|
|
250
283
|
try {
|
|
251
284
|
await f({ text: "Asking LLM to route to an agent" }, t);
|
|
252
285
|
const s = (t?.configurable?.services.agentRegistry?.list() ?? []).map(({ agent: v }) => ({
|
|
@@ -256,11 +289,11 @@ const U = (e) => JSON.stringify(e, null, 2), Pe = (e) => {
|
|
|
256
289
|
}));
|
|
257
290
|
if (!s.length)
|
|
258
291
|
return await f({ text: "No agents registered; skipping intent detection" }, t), { ...e, currentIntent: "none" };
|
|
259
|
-
const
|
|
260
|
-
registeredAgents:
|
|
292
|
+
const i = await T("intent_prompt"), a = U(s), o = je(s), c = {
|
|
293
|
+
registeredAgents: a,
|
|
261
294
|
priorSteps: U(e.agentExecutionContext.priorSteps),
|
|
262
295
|
userRequest: e.agentExecutionContext.userRequest
|
|
263
|
-
}, u = await H.fromTemplate(
|
|
296
|
+
}, u = await H.fromTemplate(i).format(c), m = ge({
|
|
264
297
|
model: await b("fast"),
|
|
265
298
|
tools: [],
|
|
266
299
|
systemPrompt: u,
|
|
@@ -270,16 +303,16 @@ const U = (e) => JSON.stringify(e, null, 2), Pe = (e) => {
|
|
|
270
303
|
// Preserve recent conversation context while summarizing older messages
|
|
271
304
|
// to control token usage without losing important intent signals.
|
|
272
305
|
// The trigger and keep parameters can be tuned based on token limits and behavior.
|
|
273
|
-
|
|
306
|
+
pe({
|
|
274
307
|
model: await b("fast"),
|
|
275
308
|
trigger: { tokens: 4e3 },
|
|
276
309
|
keep: { messages: 6 }
|
|
277
310
|
}),
|
|
278
311
|
// Enforce no loop/retry.
|
|
279
312
|
// 1 usual LLM call and 1 optional summarization call.
|
|
280
|
-
|
|
313
|
+
he({ runLimit: 2 })
|
|
281
314
|
]
|
|
282
|
-
}), { structuredResponse: y } = await
|
|
315
|
+
}), { structuredResponse: y } = await Pe({
|
|
283
316
|
agent: m,
|
|
284
317
|
messages: e.agentExecutionContext.messages,
|
|
285
318
|
config: t
|
|
@@ -327,11 +360,11 @@ Requires Follow-Up: ${p.requiresFollowUp}`
|
|
|
327
360
|
} catch (r) {
|
|
328
361
|
throw await f({ text: "Error during intent detection" }, t), new Error(`Error during intent detection: ${r instanceof Error ? r.message : String(r)}`);
|
|
329
362
|
}
|
|
330
|
-
},
|
|
363
|
+
}, _e = 3, We = () => new ae(Ie).addNode("ingestInput", ke).addNode("intentLLM", Ue).addNode("executeRegisteredAgent", De).addNode("exit", Re).addEdge(oe, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (t) => t.currentIntent === "none" ? "exit" : "executeRegisteredAgent").addConditionalEdges(
|
|
331
364
|
"executeRegisteredAgent",
|
|
332
|
-
(t) => t.stepCount >=
|
|
333
|
-
).addEdge("exit",
|
|
334
|
-
class
|
|
365
|
+
(t) => t.stepCount >= _e || !t.requiresFollowUp ? "exit" : "intentLLM"
|
|
366
|
+
).addEdge("exit", ce);
|
|
367
|
+
class Ne {
|
|
335
368
|
constructor() {
|
|
336
369
|
this.agentRegistry = /* @__PURE__ */ new Map();
|
|
337
370
|
}
|
|
@@ -348,7 +381,7 @@ class je {
|
|
|
348
381
|
return [...this.agentRegistry.values()];
|
|
349
382
|
}
|
|
350
383
|
}
|
|
351
|
-
class
|
|
384
|
+
class Oe {
|
|
352
385
|
/**
|
|
353
386
|
* Create a new InterruptHandler tied to a specific compiled graph and config.
|
|
354
387
|
*/
|
|
@@ -395,32 +428,32 @@ class We {
|
|
|
395
428
|
this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
|
|
396
429
|
}
|
|
397
430
|
}
|
|
398
|
-
const
|
|
431
|
+
const He = (e) => {
|
|
399
432
|
let t = -1;
|
|
400
433
|
for (let r = e.length - 1; r >= 0; r--)
|
|
401
|
-
if (e[r] instanceof
|
|
434
|
+
if (e[r] instanceof N) {
|
|
402
435
|
t = r;
|
|
403
436
|
break;
|
|
404
437
|
}
|
|
405
438
|
return t === -1 ? "" : e.slice(t + 1).filter((r) => r instanceof A).map((r) => r.content).join(`
|
|
406
439
|
`);
|
|
407
|
-
},
|
|
440
|
+
}, X = async (e) => {
|
|
408
441
|
try {
|
|
409
|
-
return await (await
|
|
442
|
+
return await (await Le()).embedDocuments(e);
|
|
410
443
|
} catch (t) {
|
|
411
444
|
throw console.error("Failed to generate embeddings:", t), t;
|
|
412
445
|
}
|
|
413
|
-
},
|
|
446
|
+
}, Q = async (e, t) => {
|
|
414
447
|
const r = t.get(e);
|
|
415
448
|
if (r)
|
|
416
449
|
return r;
|
|
417
|
-
const n = await
|
|
450
|
+
const n = await X([e]);
|
|
418
451
|
return t.set(e, n[0]), n[0];
|
|
419
452
|
};
|
|
420
|
-
async function
|
|
421
|
-
const s = `req-${Date.now()}`,
|
|
453
|
+
async function Ve(e, t, r, n) {
|
|
454
|
+
const s = `req-${Date.now()}`, a = {
|
|
422
455
|
type: "layerSearch",
|
|
423
|
-
precomputedEmbedding: n ? await
|
|
456
|
+
precomputedEmbedding: n ? await Q(e, n) : void 0,
|
|
424
457
|
requestId: s,
|
|
425
458
|
minScore: r
|
|
426
459
|
};
|
|
@@ -428,10 +461,10 @@ async function He(e, t, r, n) {
|
|
|
428
461
|
const c = (d) => {
|
|
429
462
|
d.data.requestId === s && o(d.data.results);
|
|
430
463
|
};
|
|
431
|
-
t.addEventListener("message", c, { once: !0 }), t.postMessage(
|
|
464
|
+
t.addEventListener("message", c, { once: !0 }), t.postMessage(a);
|
|
432
465
|
});
|
|
433
466
|
}
|
|
434
|
-
function
|
|
467
|
+
function ze(e) {
|
|
435
468
|
const { worker: t } = e;
|
|
436
469
|
return {
|
|
437
470
|
async searchLayers({
|
|
@@ -439,29 +472,29 @@ function Oe(e) {
|
|
|
439
472
|
minScore: n,
|
|
440
473
|
embeddingCache: s
|
|
441
474
|
}) {
|
|
442
|
-
return await
|
|
475
|
+
return await Ve(r, t, n, s);
|
|
443
476
|
}
|
|
444
477
|
};
|
|
445
478
|
}
|
|
446
|
-
const
|
|
479
|
+
const Be = async ({
|
|
447
480
|
combinedQuery: e,
|
|
448
481
|
layerIds: t,
|
|
449
482
|
embeddingsWorker: r,
|
|
450
483
|
minScore: n,
|
|
451
484
|
topResults: s,
|
|
452
|
-
embeddingCache:
|
|
485
|
+
embeddingCache: i
|
|
453
486
|
}) => {
|
|
454
|
-
const
|
|
487
|
+
const a = `req-${Date.now()}`, o = i ? await Q(e, i) : void 0, c = {
|
|
455
488
|
type: "fieldSearch",
|
|
456
489
|
layerIdForFieldsSearch: t,
|
|
457
490
|
precomputedEmbedding: o,
|
|
458
|
-
requestId:
|
|
491
|
+
requestId: a,
|
|
459
492
|
minScore: n,
|
|
460
493
|
topResults: s
|
|
461
494
|
};
|
|
462
495
|
return await new Promise((d) => {
|
|
463
496
|
const u = (m) => {
|
|
464
|
-
if (m.data.requestId !==
|
|
497
|
+
if (m.data.requestId !== a)
|
|
465
498
|
return;
|
|
466
499
|
const y = m.data.results.map(({ layerId: p, results: g }) => ({
|
|
467
500
|
layerId: p,
|
|
@@ -472,31 +505,31 @@ const Ve = async ({
|
|
|
472
505
|
r.addEventListener("message", u, { once: !0 }), r.postMessage(c);
|
|
473
506
|
});
|
|
474
507
|
};
|
|
475
|
-
function
|
|
508
|
+
function Ge(e) {
|
|
476
509
|
const { worker: t } = e;
|
|
477
510
|
return {
|
|
478
|
-
async searchFields({ text: r, layerIds: n, minScore: s, topResults:
|
|
479
|
-
return await
|
|
511
|
+
async searchFields({ text: r, layerIds: n, minScore: s, topResults: i, embeddingCache: a }) {
|
|
512
|
+
return await Be({
|
|
480
513
|
combinedQuery: r,
|
|
481
514
|
layerIds: n,
|
|
482
515
|
embeddingsWorker: t,
|
|
483
516
|
minScore: s,
|
|
484
|
-
topResults:
|
|
485
|
-
embeddingCache:
|
|
517
|
+
topResults: i,
|
|
518
|
+
embeddingCache: a
|
|
486
519
|
});
|
|
487
520
|
}
|
|
488
521
|
};
|
|
489
522
|
}
|
|
490
|
-
const
|
|
523
|
+
const Y = "0.1", w = 1536, Z = "openai", ee = C.default, F = `Name: {name}
|
|
491
524
|
Title: {title}
|
|
492
525
|
Description: {description}`, D = `Name: {name}
|
|
493
526
|
Alias: {alias}
|
|
494
|
-
Description: {description}`,
|
|
495
|
-
schemaVersion: l.literal(
|
|
527
|
+
Description: {description}`, te = l.object({
|
|
528
|
+
schemaVersion: l.literal(Y),
|
|
496
529
|
modified: l.number().int().nonnegative(),
|
|
497
530
|
embeddings: l.object({
|
|
498
|
-
modelProvider: l.literal(
|
|
499
|
-
model: l.literal(
|
|
531
|
+
modelProvider: l.literal(Z),
|
|
532
|
+
model: l.literal(ee),
|
|
500
533
|
dimensions: l.literal(w),
|
|
501
534
|
templates: l.object({
|
|
502
535
|
layer: l.string().default(F),
|
|
@@ -524,74 +557,74 @@ Description: {description}`, ee = l.object({
|
|
|
524
557
|
)
|
|
525
558
|
})
|
|
526
559
|
).default([])
|
|
527
|
-
}),
|
|
528
|
-
const t =
|
|
560
|
+
}), Ke = (e) => {
|
|
561
|
+
const t = te.safeParse(e);
|
|
529
562
|
if (!t.success)
|
|
530
563
|
throw new Error("Embeddings response validation failed. Regenerate embeddings.");
|
|
531
564
|
return t.data;
|
|
532
|
-
},
|
|
565
|
+
}, Je = (e, t) => {
|
|
533
566
|
const r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Map();
|
|
534
567
|
if (t.allLayers.forEach((s) => {
|
|
535
|
-
s instanceof
|
|
568
|
+
s instanceof z && n.set(s.id, s);
|
|
536
569
|
}), e.length !== n.size)
|
|
537
570
|
throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
|
|
538
571
|
for (const s of e) {
|
|
539
|
-
const
|
|
540
|
-
if (!
|
|
572
|
+
const i = n.get(s.id);
|
|
573
|
+
if (!i)
|
|
541
574
|
throw new Error(
|
|
542
575
|
`Layer with ID ${s.id} not found in the original map during registry restoration. Regenerate embeddings.`
|
|
543
576
|
);
|
|
544
|
-
if (s.fields.length !==
|
|
577
|
+
if (s.fields.length !== i.fields.length)
|
|
545
578
|
throw new Error(
|
|
546
579
|
`Field count mismatch for layer ID ${s.id} during registry restoration. Regenerate embeddings.`
|
|
547
580
|
);
|
|
548
|
-
const
|
|
581
|
+
const a = {
|
|
549
582
|
name: s.name,
|
|
550
583
|
title: s.title,
|
|
551
584
|
description: s.description
|
|
552
585
|
}, o = /* @__PURE__ */ new Map();
|
|
553
586
|
for (const c of s.fields) {
|
|
554
|
-
const d =
|
|
587
|
+
const d = i.fieldsIndex.get(c.name);
|
|
555
588
|
if (!d)
|
|
556
589
|
throw new Error(
|
|
557
590
|
`Field with name ${c.name} not found in the original layer ${s.id} during registry restoration. Regenerate embeddings.`
|
|
558
591
|
);
|
|
559
592
|
o.set(c.name, {
|
|
560
593
|
name: c.name,
|
|
561
|
-
alias:
|
|
594
|
+
alias: i.getFieldAlias(c.name) ?? c.alias,
|
|
562
595
|
description: c.description,
|
|
563
596
|
type: d.type || "unknown",
|
|
564
597
|
valueType: d.valueType || "unknown",
|
|
565
|
-
domain:
|
|
598
|
+
domain: i.getFieldDomain(c.name) ?? void 0
|
|
566
599
|
});
|
|
567
600
|
}
|
|
568
601
|
r.set(s.id, {
|
|
569
|
-
layerItem:
|
|
602
|
+
layerItem: a,
|
|
570
603
|
fieldRegistry: o
|
|
571
604
|
});
|
|
572
605
|
}
|
|
573
606
|
return r;
|
|
574
|
-
},
|
|
607
|
+
}, Xe = async (e) => {
|
|
575
608
|
try {
|
|
576
|
-
return (await
|
|
609
|
+
return (await we(e, {
|
|
577
610
|
responseType: "json"
|
|
578
611
|
})).data;
|
|
579
612
|
} catch (t) {
|
|
580
613
|
throw new Error(`Failed to fetch data from ${e}: ${String(t)}`);
|
|
581
614
|
}
|
|
582
|
-
},
|
|
615
|
+
}, Qe = async (e) => {
|
|
583
616
|
const t = e.map;
|
|
584
617
|
if (!t?.portalItem)
|
|
585
618
|
throw new Error("WebMap portal item is missing.");
|
|
586
|
-
const { resources: r } = await t.portalItem.fetchResources(), n = r.find((
|
|
619
|
+
const { resources: r } = await t.portalItem.fetchResources(), n = r.find((a) => a.resource.path === "embeddings-v01.json");
|
|
587
620
|
if (!n?.resource.url)
|
|
588
621
|
throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
|
|
589
|
-
const s = await
|
|
590
|
-
return
|
|
622
|
+
const s = await Xe(n.resource.url);
|
|
623
|
+
return Ke(s);
|
|
591
624
|
};
|
|
592
|
-
class
|
|
625
|
+
class ne {
|
|
593
626
|
constructor() {
|
|
594
|
-
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.threadId = "", this.agentRegistry = new
|
|
627
|
+
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.threadId = "", this.agentRegistry = new Ne(), this.streamEpoch = 0;
|
|
595
628
|
}
|
|
596
629
|
/**
|
|
597
630
|
* Creates and returns an AI-ready Orchestrator instance.
|
|
@@ -599,15 +632,15 @@ class te {
|
|
|
599
632
|
* @returns Ready Orchestrator.
|
|
600
633
|
*/
|
|
601
634
|
static async init(t) {
|
|
602
|
-
const r = new
|
|
635
|
+
const r = new ne();
|
|
603
636
|
try {
|
|
604
637
|
if (t.view?.map) {
|
|
605
|
-
await
|
|
606
|
-
const n = await
|
|
638
|
+
await V.whenOnce(() => t.view.ready);
|
|
639
|
+
const n = await Qe(t.view), s = Je(
|
|
607
640
|
n.layers,
|
|
608
641
|
t.view.map
|
|
609
642
|
);
|
|
610
|
-
r.layersAndFieldsRegistry = s, r.embeddingsWorker = await
|
|
643
|
+
r.layersAndFieldsRegistry = s, r.embeddingsWorker = await be(n);
|
|
611
644
|
}
|
|
612
645
|
return t.agents?.forEach((n) => {
|
|
613
646
|
r.agentRegistry.register(n);
|
|
@@ -631,8 +664,8 @@ class te {
|
|
|
631
664
|
throw new Error("Orchestrator has no registered agents.");
|
|
632
665
|
if (++this.streamEpoch, !t.trim())
|
|
633
666
|
return;
|
|
634
|
-
this.threadId = String(Date.now()), this.graph || (this.graph =
|
|
635
|
-
const r = this.embeddingsWorker ?
|
|
667
|
+
this.threadId = String(Date.now()), this.graph || (this.graph = We().compile({ checkpointer: new de() }));
|
|
668
|
+
const r = this.embeddingsWorker ? ze({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? Ge({ worker: this.embeddingsWorker }) : void 0, s = /* @__PURE__ */ new Map(), a = {
|
|
636
669
|
version: "v2",
|
|
637
670
|
streamMode: "custom",
|
|
638
671
|
configurable: {
|
|
@@ -657,13 +690,13 @@ class te {
|
|
|
657
690
|
sharedState: this.sharedState
|
|
658
691
|
}
|
|
659
692
|
},
|
|
660
|
-
|
|
693
|
+
a
|
|
661
694
|
), c = ++this.streamEpoch;
|
|
662
695
|
for (yield* this.pipeStream(o, c); ; ) {
|
|
663
|
-
const p = (await this.graph.getState(
|
|
696
|
+
const p = (await this.graph.getState(a, { subgraphs: !0 })).tasks.find((g) => g.interrupts.length > 0)?.interrupts[0]?.value;
|
|
664
697
|
if (!p)
|
|
665
698
|
break;
|
|
666
|
-
this.currentInterrupt = p, this.interruptHandler = new
|
|
699
|
+
this.currentInterrupt = p, this.interruptHandler = new Oe(this.graph, a), yield { runId: this.threadId, timestamp: Date.now(), type: "interrupt", interrupt: p };
|
|
667
700
|
try {
|
|
668
701
|
const g = await this.interruptHandler.waitForUser(), I = ++this.streamEpoch;
|
|
669
702
|
yield* this.pipeStream(g, I);
|
|
@@ -681,12 +714,12 @@ class te {
|
|
|
681
714
|
return;
|
|
682
715
|
}
|
|
683
716
|
}
|
|
684
|
-
const u = (await this.graph.getState(
|
|
685
|
-
this.chatHistory = u.agentExecutionContext.messages.length ? u.agentExecutionContext.messages : this.chatHistory, this.priorSteps = u.agentExecutionContext.priorSteps?.slice(-5) ?? [], yield {
|
|
717
|
+
const u = (await this.graph.getState(a, { subgraphs: !0 })).values;
|
|
718
|
+
this.chatHistory = u.agentExecutionContext.messages.length ? u.agentExecutionContext.messages : this.chatHistory, this.priorSteps = u.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = u.agentExecutionContext.sharedState ?? {}, yield {
|
|
686
719
|
runId: this.threadId,
|
|
687
720
|
timestamp: Date.now(),
|
|
688
721
|
type: "completed",
|
|
689
|
-
result: { content:
|
|
722
|
+
result: { content: He(u.agentExecutionContext.messages) }
|
|
690
723
|
};
|
|
691
724
|
}
|
|
692
725
|
/**
|
|
@@ -732,63 +765,63 @@ class te {
|
|
|
732
765
|
this.embeddingsWorker && (this.embeddingsWorker.terminate(), this.embeddingsWorker = void 0), this.orchestratorReady = !1;
|
|
733
766
|
}
|
|
734
767
|
}
|
|
735
|
-
const
|
|
768
|
+
const Ye = (e) => {
|
|
736
769
|
const t = /* @__PURE__ */ new Set();
|
|
737
770
|
for (const n of e)
|
|
738
|
-
if (
|
|
771
|
+
if (le(n)) {
|
|
739
772
|
const s = n;
|
|
740
|
-
s.tool_calls && s.tool_calls.length > 0 && s.tool_calls.forEach((
|
|
741
|
-
|
|
773
|
+
s.tool_calls && s.tool_calls.length > 0 && s.tool_calls.forEach((i) => {
|
|
774
|
+
i.id && t.add(i.id);
|
|
742
775
|
});
|
|
743
776
|
}
|
|
744
777
|
return e.filter((n) => {
|
|
745
|
-
if (
|
|
778
|
+
if (ue(n)) {
|
|
746
779
|
const s = n;
|
|
747
780
|
return t.has(s.tool_call_id);
|
|
748
781
|
}
|
|
749
782
|
return !0;
|
|
750
783
|
});
|
|
751
784
|
}, $ = (e, t) => {
|
|
752
|
-
const r =
|
|
785
|
+
const r = me.fromTemplate(e);
|
|
753
786
|
return H.fromMessages([r, ...t]);
|
|
754
|
-
},
|
|
755
|
-
const { promptText: t, modelTier: r, temperature: n, messages: s } = e,
|
|
756
|
-
return
|
|
757
|
-
},
|
|
758
|
-
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables:
|
|
787
|
+
}, Ze = async (e) => {
|
|
788
|
+
const { promptText: t, modelTier: r, temperature: n, messages: s } = e, i = $(t, s ?? []), a = await b(r, n);
|
|
789
|
+
return i.pipe(a);
|
|
790
|
+
}, xt = async (e) => {
|
|
791
|
+
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: i } = e, o = await (await Ze({
|
|
759
792
|
promptText: t,
|
|
760
793
|
modelTier: r,
|
|
761
794
|
temperature: n,
|
|
762
795
|
messages: s
|
|
763
|
-
})).invoke(
|
|
796
|
+
})).invoke(i ?? {});
|
|
764
797
|
if (typeof o == "string")
|
|
765
798
|
return o;
|
|
766
799
|
const c = o.content;
|
|
767
800
|
return typeof c == "string" ? c : JSON.stringify(c);
|
|
768
|
-
},
|
|
769
|
-
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables:
|
|
770
|
-
return await o.pipe(d).invoke(
|
|
771
|
-
},
|
|
772
|
-
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables:
|
|
773
|
-
return await c.pipe(d.bindTools(
|
|
774
|
-
},
|
|
801
|
+
}, re = async (e) => {
|
|
802
|
+
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: i, schema: a } = e, o = $(t, s ?? []), d = (await b(r, n)).withStructuredOutput(a);
|
|
803
|
+
return await o.pipe(d).invoke(i ?? {});
|
|
804
|
+
}, bt = async (e) => {
|
|
805
|
+
const { promptText: t, modelTier: r = "default", temperature: n = 0, messages: s, inputVariables: i, tools: a } = e, o = a.length > 0 ? Ye(s ?? []) : s ?? [], c = $(t, o), d = await b(r, n);
|
|
806
|
+
return await c.pipe(d.bindTools(a)).invoke(i ?? {});
|
|
807
|
+
}, et = h.object({
|
|
775
808
|
name: h.string(),
|
|
776
809
|
description: h.string(),
|
|
777
810
|
valueType: h.string(),
|
|
778
811
|
alias: h.string()
|
|
779
|
-
}),
|
|
780
|
-
fields: h.array(
|
|
781
|
-
}),
|
|
782
|
-
const r =
|
|
812
|
+
}), tt = h.object({
|
|
813
|
+
fields: h.array(et)
|
|
814
|
+
}), se = (e, t) => e.getFieldAlias(t) ?? void 0, k = (e, t) => se(e, t.name) ?? t.alias ?? "", nt = (e, t) => {
|
|
815
|
+
const r = se(e, t.name);
|
|
783
816
|
return !!(r && r !== (t.alias ?? ""));
|
|
784
817
|
};
|
|
785
818
|
function _(e, t) {
|
|
786
819
|
const r = /* @__PURE__ */ new Map();
|
|
787
820
|
for (const n of e.fields) {
|
|
788
|
-
const s = t.fields.find((c) => c.name === n.name),
|
|
821
|
+
const s = t.fields.find((c) => c.name === n.name), i = k(e, n), a = nt(e, n), o = {
|
|
789
822
|
name: n.name,
|
|
790
823
|
type: n.type,
|
|
791
|
-
alias:
|
|
824
|
+
alias: a ? i : s?.alias ?? i,
|
|
792
825
|
description: s?.description ?? n.description ?? "",
|
|
793
826
|
valueType: s?.valueType ?? n.valueType ?? "",
|
|
794
827
|
domain: e.getFieldDomain(n.name) ?? void 0
|
|
@@ -797,9 +830,9 @@ function _(e, t) {
|
|
|
797
830
|
}
|
|
798
831
|
return r;
|
|
799
832
|
}
|
|
800
|
-
const
|
|
801
|
-
const r = await T("field_descriptions_prompt"), n = e.fields.filter((
|
|
802
|
-
const { name: o, type: c, description: d } =
|
|
833
|
+
const rt = async (e) => {
|
|
834
|
+
const r = await T("field_descriptions_prompt"), n = e.fields.filter((a) => !(k(e, a) && a.description)).map((a) => {
|
|
835
|
+
const { name: o, type: c, description: d } = a, u = k(e, a);
|
|
803
836
|
return [`Name: ${o}`, `Type: ${c}`, `Alias: ${u}`, `Description: ${d ?? "N/A"}`].join(", ");
|
|
804
837
|
}).join(`
|
|
805
838
|
`);
|
|
@@ -811,48 +844,48 @@ const tt = async (e) => {
|
|
|
811
844
|
existingLayerTitle: e.title,
|
|
812
845
|
existingLayerDescription: e.portalItem?.description,
|
|
813
846
|
fieldInformation: n
|
|
814
|
-
},
|
|
847
|
+
}, i = await re({
|
|
815
848
|
promptText: r,
|
|
816
|
-
schema:
|
|
849
|
+
schema: tt,
|
|
817
850
|
inputVariables: s
|
|
818
851
|
});
|
|
819
|
-
return _(e,
|
|
820
|
-
},
|
|
852
|
+
return _(e, i);
|
|
853
|
+
}, st = h.object({
|
|
821
854
|
title: h.string(),
|
|
822
855
|
description: h.string(),
|
|
823
856
|
name: h.string().nullable()
|
|
824
|
-
}),
|
|
825
|
-
const n = await T("layer_descriptions_prompt"), s = Array.from(t.values()),
|
|
857
|
+
}), it = async (e, t) => {
|
|
858
|
+
const n = await T("layer_descriptions_prompt"), s = Array.from(t.values()), i = {
|
|
826
859
|
fieldInformation: JSON.stringify(s, null, 2),
|
|
827
860
|
existingLayerTitle: e.title,
|
|
828
861
|
existingLayerDescription: e.portalItem?.description,
|
|
829
862
|
existingLayerSnippet: e.portalItem?.snippet,
|
|
830
863
|
layerGeometryType: e.geometryType
|
|
831
864
|
};
|
|
832
|
-
return { ...await
|
|
865
|
+
return { ...await re({
|
|
833
866
|
promptText: n,
|
|
834
|
-
schema:
|
|
835
|
-
inputVariables:
|
|
867
|
+
schema: st,
|
|
868
|
+
inputVariables: i
|
|
836
869
|
}), name: e.title ?? null };
|
|
837
|
-
},
|
|
870
|
+
}, at = async (e) => {
|
|
838
871
|
const t = e.allLayers.toArray(), r = [], n = /* @__PURE__ */ new Map();
|
|
839
872
|
for (const s of t)
|
|
840
|
-
if (s instanceof
|
|
841
|
-
const
|
|
842
|
-
const
|
|
843
|
-
n.set(s.id, { layerItem: o, fieldRegistry:
|
|
873
|
+
if (s instanceof z) {
|
|
874
|
+
const i = (async () => {
|
|
875
|
+
const a = await rt(s), o = await it(s, a);
|
|
876
|
+
n.set(s.id, { layerItem: o, fieldRegistry: a });
|
|
844
877
|
})();
|
|
845
|
-
r.push(
|
|
878
|
+
r.push(i);
|
|
846
879
|
}
|
|
847
880
|
return await Promise.all(r), n;
|
|
848
|
-
},
|
|
849
|
-
await
|
|
850
|
-
const t = await
|
|
851
|
-
schemaVersion:
|
|
881
|
+
}, Et = async (e) => {
|
|
882
|
+
await V.whenOnce(() => e.ready);
|
|
883
|
+
const t = await at(e.map), { layers: r } = await ot(t), n = {
|
|
884
|
+
schemaVersion: Y,
|
|
852
885
|
modified: Date.now(),
|
|
853
886
|
embeddings: {
|
|
854
|
-
modelProvider:
|
|
855
|
-
model:
|
|
887
|
+
modelProvider: Z,
|
|
888
|
+
model: ee,
|
|
856
889
|
dimensions: w,
|
|
857
890
|
templates: {
|
|
858
891
|
layer: F,
|
|
@@ -860,21 +893,21 @@ const tt = async (e) => {
|
|
|
860
893
|
}
|
|
861
894
|
},
|
|
862
895
|
layers: r
|
|
863
|
-
}, s =
|
|
896
|
+
}, s = te.safeParse(n);
|
|
864
897
|
if (!s.success)
|
|
865
898
|
throw console.error("Schema Mismatch:", s.error.format()), new Error("Webmap embedding generation failed validation.");
|
|
866
899
|
return s.data;
|
|
867
|
-
},
|
|
900
|
+
}, ot = async (e) => {
|
|
868
901
|
const t = [], r = [];
|
|
869
|
-
for (const [
|
|
870
|
-
const d =
|
|
902
|
+
for (const [a, { fieldRegistry: o, layerItem: c }] of e.entries()) {
|
|
903
|
+
const d = W(F, {
|
|
871
904
|
name: c.name,
|
|
872
905
|
title: c.title,
|
|
873
906
|
description: c.description
|
|
874
907
|
});
|
|
875
908
|
t.push(d);
|
|
876
909
|
const u = {
|
|
877
|
-
id:
|
|
910
|
+
id: a,
|
|
878
911
|
name: c.name ?? "",
|
|
879
912
|
title: c.title,
|
|
880
913
|
description: c.description,
|
|
@@ -882,7 +915,7 @@ const tt = async (e) => {
|
|
|
882
915
|
fields: []
|
|
883
916
|
};
|
|
884
917
|
for (const [, m] of o.entries()) {
|
|
885
|
-
const y =
|
|
918
|
+
const y = W(D, {
|
|
886
919
|
name: m.name,
|
|
887
920
|
alias: m.alias,
|
|
888
921
|
description: m.description
|
|
@@ -896,12 +929,12 @@ const tt = async (e) => {
|
|
|
896
929
|
}
|
|
897
930
|
r.push(u);
|
|
898
931
|
}
|
|
899
|
-
const n = await
|
|
932
|
+
const n = await X(t);
|
|
900
933
|
let s = 0;
|
|
901
|
-
return { layers: r.map((
|
|
934
|
+
return { layers: r.map((a) => (a.vector = n[s++], a.fields.forEach((o) => {
|
|
902
935
|
o.vector = n[s++];
|
|
903
|
-
}),
|
|
904
|
-
},
|
|
936
|
+
}), a)) };
|
|
937
|
+
}, W = (e, t) => e.replace(/\{(\w+)\}/gu, (r, n) => t[n] ?? ""), St = (e, t) => {
|
|
905
938
|
if (e.length !== t.length)
|
|
906
939
|
throw new Error("Vectors must be the same length");
|
|
907
940
|
let r = 0, n = 0, s = 0;
|
|
@@ -909,21 +942,21 @@ const tt = async (e) => {
|
|
|
909
942
|
const c = e[o], d = t[o];
|
|
910
943
|
r += c * d, n += c * c, s += d * d;
|
|
911
944
|
}
|
|
912
|
-
const
|
|
913
|
-
if (
|
|
945
|
+
const i = Math.sqrt(n * s);
|
|
946
|
+
if (i === 0)
|
|
914
947
|
return 0;
|
|
915
|
-
const
|
|
916
|
-
return Math.max(-1, Math.min(1,
|
|
948
|
+
const a = r / i;
|
|
949
|
+
return Math.max(-1, Math.min(1, a));
|
|
917
950
|
};
|
|
918
951
|
export {
|
|
919
|
-
|
|
920
|
-
|
|
952
|
+
ne as Orchestrator,
|
|
953
|
+
St as cosineSimilarity,
|
|
921
954
|
b as createChatModel,
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
955
|
+
Et as createWebmapEmbeddings,
|
|
956
|
+
X as getEmbeddings,
|
|
957
|
+
re as invokeStructuredPrompt,
|
|
958
|
+
xt as invokeTextPrompt,
|
|
959
|
+
bt as invokeToolPrompt,
|
|
927
960
|
f as sendTraceMessage,
|
|
928
|
-
|
|
961
|
+
vt as sendUXSuggestion
|
|
929
962
|
};
|
|
@@ -34,7 +34,7 @@ type OrchestratorEventBase = {
|
|
|
34
34
|
runId: string;
|
|
35
35
|
timestamp: number;
|
|
36
36
|
};
|
|
37
|
-
|
|
37
|
+
interface CompletedEventResult {
|
|
38
38
|
content: string;
|
|
39
39
|
}
|
|
40
40
|
/** Data for a trace event emitted during graph execution */
|
|
@@ -51,9 +51,9 @@ export type UXSuggestion = {
|
|
|
51
51
|
/** Cancel reasons for orchestrator events:
|
|
52
52
|
* - "user": the user explicitly cancelled the run.
|
|
53
53
|
*/
|
|
54
|
-
|
|
54
|
+
type CancelReason = "user";
|
|
55
55
|
/** Error information for orchestrator events */
|
|
56
|
-
|
|
56
|
+
type OrchestratorError = {
|
|
57
57
|
message: string;
|
|
58
58
|
};
|
|
59
59
|
export {};
|
|
@@ -36,7 +36,7 @@ export interface AgentRegistration {
|
|
|
36
36
|
*/
|
|
37
37
|
workspace: AnnotationRoot<any>;
|
|
38
38
|
}
|
|
39
|
-
|
|
39
|
+
type GetContext<TContext extends Record<string, unknown>> = () => Promise<TContext> | TContext;
|
|
40
40
|
export interface AgentWithContext<TContext extends Record<string, unknown> = Record<string, unknown>> {
|
|
41
41
|
agent: AgentRegistration;
|
|
42
42
|
/**
|
|
@@ -51,3 +51,4 @@ export declare class AgentRegistry {
|
|
|
51
51
|
get(id: string): AgentWithContext | undefined;
|
|
52
52
|
list(): AgentWithContext[];
|
|
53
53
|
}
|
|
54
|
+
export {};
|
package/dist/types/types.d.ts
CHANGED
|
@@ -25,7 +25,7 @@ export type LayersAndFieldsRegistry = Map<string, {
|
|
|
25
25
|
layerItem: LayerDescriptionWrapper;
|
|
26
26
|
fieldRegistry: FieldsRegistry;
|
|
27
27
|
}>;
|
|
28
|
-
|
|
28
|
+
type FieldVectors = {
|
|
29
29
|
layerId: string;
|
|
30
30
|
results: {
|
|
31
31
|
name: string;
|
|
@@ -58,12 +58,24 @@ export type CustomConfigurableType = Record<string, unknown> & {
|
|
|
58
58
|
};
|
|
59
59
|
/** Cache for query embeddings to avoid duplicate API calls within a request */
|
|
60
60
|
export type QueryEmbeddingCache = Map<string, number[]>;
|
|
61
|
+
type SharedStateEntry = {
|
|
62
|
+
value: unknown;
|
|
63
|
+
meta: {
|
|
64
|
+
updatedByAgentId: string;
|
|
65
|
+
updatedAt: number;
|
|
66
|
+
};
|
|
67
|
+
};
|
|
68
|
+
type SharedStatePatchEntry<T = unknown> = {
|
|
69
|
+
value: T;
|
|
70
|
+
};
|
|
71
|
+
export type SharedState = Record<string, SharedStateEntry>;
|
|
72
|
+
export type SharedStatePatch = Record<string, SharedStatePatchEntry>;
|
|
61
73
|
export interface AgentExecutionContext {
|
|
62
74
|
userRequest: string;
|
|
63
75
|
assignedTask: string;
|
|
64
76
|
messages: ChatHistory;
|
|
65
77
|
priorSteps: PriorStep[];
|
|
66
|
-
sharedState:
|
|
78
|
+
sharedState: SharedState;
|
|
67
79
|
}
|
|
68
80
|
export interface PriorStep {
|
|
69
81
|
agentId: string;
|
|
@@ -75,6 +87,7 @@ export interface AgentResult {
|
|
|
75
87
|
status?: AgentStatus;
|
|
76
88
|
outputMessage?: string;
|
|
77
89
|
summary?: string;
|
|
78
|
-
sharedStatePatch?:
|
|
90
|
+
sharedStatePatch?: SharedStatePatch;
|
|
79
91
|
}
|
|
80
92
|
export type AgentStatus = "failed" | "success" | "unknown";
|
|
93
|
+
export {};
|