@arcgis/ai-components 5.2.0-next.93 → 5.2.0-next.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cdn/{HIPQ3VRW.js → 2O4DON37.js} +1 -1
- package/dist/cdn/{7DFXYMEA.js → 2XUL3RTX.js} +1 -1
- package/dist/cdn/{YQSU6IUO.js → 5HBAJ57P.js} +1 -1
- package/dist/cdn/{EYNEYD34.js → 5MK44FNO.js} +1 -1
- package/dist/cdn/{FDDQ67BG.js → 6ECRQVHY.js} +1 -1
- package/dist/cdn/{LPR72QZF.js → 6KN5LUAV.js} +1 -1
- package/dist/cdn/{V6F3HEK7.js → 6OOZSZRJ.js} +1 -1
- package/dist/cdn/{TMZ6DF22.js → 6P44KOKX.js} +1 -1
- package/dist/cdn/{QCFICJ7U.js → 6YYPVU7H.js} +1 -1
- package/dist/cdn/{OWTGH34K.js → 7VUSIGEM.js} +1 -1
- package/dist/cdn/{4EBLRHYE.js → AA4FBYKK.js} +1 -1
- package/dist/cdn/{VNJMTA6O.js → ANRQWYU2.js} +1 -1
- package/dist/cdn/{HKSFWTWK.js → ASR3I43T.js} +1 -1
- package/dist/cdn/{ZVGUAOXE.js → B2JDVLA6.js} +1 -1
- package/dist/cdn/{FQH3HOFH.js → B2T7D57Y.js} +1 -1
- package/dist/cdn/{AZCIDPML.js → C4FEETBZ.js} +1 -1
- package/dist/cdn/{X3COUAXY.js → COH3QXWG.js} +3 -3
- package/dist/cdn/{AT4XVTJR.js → D5UFYQHN.js} +1 -1
- package/dist/cdn/{COL6QYGQ.js → EKWM5K4K.js} +1 -1
- package/dist/cdn/{WNNMKCKS.js → EYOWRGDP.js} +1 -1
- package/dist/cdn/{RSNGZQCQ.js → F5NIRETW.js} +1 -1
- package/dist/cdn/{HMUWQCXU.js → FG647IP6.js} +1 -1
- package/dist/cdn/{6KFMRBAA.js → FUF3NAU7.js} +1 -1
- package/dist/cdn/G2EGT3CF.js +6 -0
- package/dist/cdn/{PEYYWXFE.js → G7OMHU2B.js} +1 -1
- package/dist/cdn/{OL5656NI.js → HAEFC2SJ.js} +1 -1
- package/dist/cdn/{ZQMBJ6MI.js → HDACNIZF.js} +1 -1
- package/dist/cdn/{WR2SQX3J.js → HHUQXL3R.js} +1 -1
- package/dist/cdn/{JJJZ7FOM.js → HNADFHYH.js} +1 -1
- package/dist/cdn/{C5ZL5Z52.js → IC3LG6TH.js} +1 -1
- package/dist/cdn/JCOA24UH.js +3 -0
- package/dist/cdn/{SUYWKYWI.js → LNCT4S4I.js} +1 -1
- package/dist/cdn/{OYSPNIJI.js → MX7OEO5Z.js} +1 -1
- package/dist/cdn/{EKB7CAMM.js → MXTXJKFE.js} +1 -1
- package/dist/cdn/MY47B3CE.js +3 -0
- package/dist/cdn/{KCU4FWF7.js → NEZXHUAL.js} +1 -1
- package/dist/cdn/{DP6O6PMH.js → NSHLOFIY.js} +1 -1
- package/dist/cdn/{PSYRZMX2.js → NZSOJ726.js} +1 -1
- package/dist/cdn/{SHD6YFSR.js → O4NVW75A.js} +1 -1
- package/dist/cdn/{4HDDRBIY.js → OE3GW5LE.js} +1 -1
- package/dist/cdn/{ZLWWWTH4.js → R2PQVY4O.js} +1 -1
- package/dist/cdn/{2PTPBAIN.js → SXM4NUT5.js} +1 -1
- package/dist/cdn/{FUZ77UGP.js → UAANWCMU.js} +1 -1
- package/dist/cdn/{WP7ORLSB.js → WGO5SER7.js} +1 -1
- package/dist/cdn/{4KOV2NEI.js → WJXXOKGA.js} +1 -1
- package/dist/cdn/{MKOQJXQQ.js → WSWB3B7B.js} +1 -1
- package/dist/cdn/{W5JPJWMM.js → YWN57GH4.js} +1 -1
- package/dist/cdn/{4NJ2FF7H.js → ZDV4K4WG.js} +1 -1
- package/dist/cdn/agent-utils/index.js +1 -1
- package/dist/cdn/index.js +1 -1
- package/dist/chunks/baseAgentState.js +32 -30
- package/dist/chunks/dataExplorationGraph.js +2 -2
- package/dist/chunks/orchestrator.js +301 -249
- package/dist/components/arcgis-assistant/customElement.d.ts +24 -0
- package/dist/components/arcgis-assistant/customElement.js +275 -270
- package/dist/docs/api.json +1 -1
- package/dist/docs/docs.json +1 -1
- package/dist/docs/vscode.html-custom-data.json +1 -1
- package/dist/docs/web-types.json +1 -1
- package/dist/loader.js +1 -1
- package/dist/types/lumina.d.ts +1 -1
- package/dist/types/preact.d.ts +1 -1
- package/dist/types/react.d.ts +1 -1
- package/dist/types/stencil.d.ts +1 -1
- package/dist/utils/index.d.ts +57 -30
- package/package.json +5 -5
- package/dist/cdn/6VJXUIXY.js +0 -3
- package/dist/cdn/7M6VKBTK.js +0 -6
- package/dist/cdn/PKUDO2RC.js +0 -3
|
@@ -1,83 +1,127 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import { j as
|
|
5
|
-
import { isGraphInterrupt as
|
|
6
|
-
import { generateGuid as
|
|
7
|
-
import { HumanMessage as
|
|
8
|
-
import { s as
|
|
9
|
-
import { BaseCallbackHandler as
|
|
10
|
-
import * as
|
|
2
|
+
import M from "@arcgis/core/identity/IdentityManager.js";
|
|
3
|
+
import _ from "@arcgis/core/portal/Portal.js";
|
|
4
|
+
import { j as $, k as b, D, n as F, o as L, W } from "./generateLayerDescriptions.js";
|
|
5
|
+
import { isGraphInterrupt as q, StateGraph as T, START as j, END as H, MemorySaver as P } from "@langchain/langgraph/web";
|
|
6
|
+
import { generateGuid as A } from "@arcgis/toolkit/string";
|
|
7
|
+
import { HumanMessage as U, AIMessage as O } from "@langchain/core/messages";
|
|
8
|
+
import { s as p } from "./index.js";
|
|
9
|
+
import { BaseCallbackHandler as G } from "@langchain/core/callbacks/base";
|
|
10
|
+
import * as N from "@arcgis/core/core/reactiveUtils.js";
|
|
11
11
|
import V from "@arcgis/core/layers/FeatureLayer.js";
|
|
12
12
|
import z from "@arcgis/core/request.js";
|
|
13
|
-
const B = async (
|
|
14
|
-
const e = await Q(), r = await
|
|
13
|
+
const B = async (n) => {
|
|
14
|
+
const e = await Q(), r = await $("default"), s = _.getDefault(), a = (await M.getCredential(`${s.url}/sharing`)).token, i = {
|
|
15
15
|
type: "generateEmbeddings",
|
|
16
|
-
webmapEmbeddings:
|
|
16
|
+
webmapEmbeddings: n,
|
|
17
17
|
auth: { apiUrl: r, token: a }
|
|
18
18
|
};
|
|
19
|
-
return e.postMessage(i), await new Promise((
|
|
20
|
-
const
|
|
21
|
-
g.data === "completed" && (e.removeEventListener("message",
|
|
19
|
+
return e.postMessage(i), await new Promise((o, d) => {
|
|
20
|
+
const c = (g) => {
|
|
21
|
+
g.data === "completed" && (e.removeEventListener("message", c), o());
|
|
22
22
|
}, u = (g) => {
|
|
23
|
-
e.removeEventListener("message",
|
|
23
|
+
e.removeEventListener("message", c), d(g instanceof Error ? g : new Error("Embeddings worker error"));
|
|
24
24
|
};
|
|
25
|
-
e.addEventListener("message",
|
|
25
|
+
e.addEventListener("message", c), e.addEventListener("error", u, { once: !0 });
|
|
26
26
|
}), e;
|
|
27
27
|
}, Q = async () => {
|
|
28
28
|
{
|
|
29
|
-
const
|
|
30
|
-
return new
|
|
31
|
-
}
|
|
32
|
-
},
|
|
33
|
-
|
|
34
|
-
},
|
|
35
|
-
const r =
|
|
36
|
-
if (
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
const s = r?.services.agentRegistry.list().map((
|
|
41
|
-
return await
|
|
42
|
-
}, X = async (
|
|
43
|
-
if (!E(
|
|
44
|
-
|
|
29
|
+
const n = (await import("./embeddings.worker.js")).default;
|
|
30
|
+
return new n();
|
|
31
|
+
}
|
|
32
|
+
}, K = (n) => {
|
|
33
|
+
n.currentIntent = "none";
|
|
34
|
+
}, J = async (n, e) => {
|
|
35
|
+
const r = b(e);
|
|
36
|
+
if (n.agentExecutionContext.userRequest) {
|
|
37
|
+
const t = new U(n.agentExecutionContext.userRequest.trim());
|
|
38
|
+
n.agentExecutionContext.messages = [...n.agentExecutionContext.messages, t], K(n);
|
|
39
|
+
}
|
|
40
|
+
const s = r?.services.agentRegistry.list().map((t) => t.agent.id) ?? [];
|
|
41
|
+
return await p({ text: `Available agents: ${[...s].join(", ")}` }, e), await p({ text: "Analyzing user input" }, e), n;
|
|
42
|
+
}, X = async (n, e) => (await p({ text: "Exiting..." }, e), n), E = (n) => typeof n == "object" && n !== null && !Array.isArray(n), Y = (n, e) => {
|
|
43
|
+
if (!E(n)) {
|
|
44
|
+
n !== void 0 && console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`);
|
|
45
45
|
return;
|
|
46
46
|
}
|
|
47
47
|
const r = {};
|
|
48
|
-
for (const [s,
|
|
49
|
-
if (!E(
|
|
48
|
+
for (const [s, t] of Object.entries(n)) {
|
|
49
|
+
if (!E(t) || !("value" in t)) {
|
|
50
50
|
console.warn(
|
|
51
51
|
`Agent "${e}" returned invalid sharedStatePatch entry for key "${s}". Ignoring that entry.`
|
|
52
52
|
);
|
|
53
53
|
continue;
|
|
54
54
|
}
|
|
55
|
-
r[s] = { value:
|
|
55
|
+
r[s] = { value: t.value };
|
|
56
56
|
}
|
|
57
57
|
return r;
|
|
58
|
-
}, Z = (
|
|
59
|
-
const { previousSharedState: e, patch: r, agentId: s } =
|
|
58
|
+
}, Z = (n) => {
|
|
59
|
+
const { previousSharedState: e, patch: r, agentId: s } = n;
|
|
60
60
|
if (!r)
|
|
61
61
|
return e;
|
|
62
|
-
const
|
|
62
|
+
const t = Date.now(), a = {
|
|
63
63
|
...e
|
|
64
64
|
};
|
|
65
|
-
for (const [i,
|
|
66
|
-
|
|
67
|
-
value:
|
|
65
|
+
for (const [i, o] of Object.entries(r))
|
|
66
|
+
o?.value !== void 0 && (a[i] = {
|
|
67
|
+
value: o.value,
|
|
68
68
|
meta: {
|
|
69
69
|
updatedByAgentId: s,
|
|
70
|
-
updatedAt:
|
|
70
|
+
updatedAt: t
|
|
71
71
|
}
|
|
72
72
|
});
|
|
73
73
|
return a;
|
|
74
|
-
},
|
|
75
|
-
if (
|
|
74
|
+
}, ee = 256, te = /* @__PURE__ */ new Set(["point", "polyline", "polygon", "extent", "custom"]), ne = (n) => typeof n == "object" && n !== null && !Array.isArray(n), re = (n, e) => {
|
|
75
|
+
if (n === void 0)
|
|
76
76
|
return;
|
|
77
|
-
|
|
77
|
+
if (!Array.isArray(n)) {
|
|
78
|
+
console.warn(`Agent "${e}" returned invalid sharedResourceAdditions. Ignoring it.`);
|
|
79
|
+
return;
|
|
80
|
+
}
|
|
81
|
+
const r = [];
|
|
82
|
+
for (const [s, t] of n.entries()) {
|
|
83
|
+
if (!ne(t) || typeof t.kind != "string" || !te.has(t.kind) || typeof t.description != "string" || !t.description.trim() || !("payload" in t) || t.payload === void 0) {
|
|
84
|
+
console.warn(
|
|
85
|
+
`Agent "${e}" returned invalid sharedResourceAdditions entry at index ${s}. Ignoring that entry.`
|
|
86
|
+
);
|
|
87
|
+
continue;
|
|
88
|
+
}
|
|
89
|
+
let a;
|
|
90
|
+
try {
|
|
91
|
+
a = structuredClone(t.payload);
|
|
92
|
+
} catch {
|
|
93
|
+
console.warn(
|
|
94
|
+
`Agent "${e}" returned invalid sharedResourceAdditions entry at index ${s}. Ignoring that entry.`
|
|
95
|
+
);
|
|
96
|
+
continue;
|
|
97
|
+
}
|
|
98
|
+
r.push({
|
|
99
|
+
kind: t.kind,
|
|
100
|
+
description: t.description.trim().slice(0, ee),
|
|
101
|
+
payload: a
|
|
102
|
+
});
|
|
103
|
+
}
|
|
104
|
+
return r.length ? r : void 0;
|
|
105
|
+
}, se = (n) => {
|
|
106
|
+
const { previousSharedResources: e, additions: r, agentId: s } = n;
|
|
107
|
+
if (!r?.length)
|
|
108
|
+
return e;
|
|
109
|
+
const t = Date.now(), a = r.map((i) => ({
|
|
110
|
+
...i,
|
|
111
|
+
id: A(),
|
|
112
|
+
meta: {
|
|
113
|
+
createdByAgentId: s,
|
|
114
|
+
createdAt: t
|
|
115
|
+
}
|
|
116
|
+
}));
|
|
117
|
+
return [...e, ...a].slice(-50);
|
|
118
|
+
}, R = (n) => {
|
|
119
|
+
if (typeof n != "string")
|
|
120
|
+
return;
|
|
121
|
+
const e = n.trim();
|
|
78
122
|
return e || void 0;
|
|
79
|
-
},
|
|
80
|
-
switch (
|
|
123
|
+
}, ae = (n) => {
|
|
124
|
+
switch (n) {
|
|
81
125
|
case "failed":
|
|
82
126
|
return "Agent failed without a summary.";
|
|
83
127
|
case "unknown":
|
|
@@ -87,166 +131,173 @@ const B = async (t) => {
|
|
|
87
131
|
default:
|
|
88
132
|
return "Agent completed without a summary.";
|
|
89
133
|
}
|
|
90
|
-
},
|
|
91
|
-
const r =
|
|
92
|
-
a === "unknown" && console.warn(`Agent "${
|
|
93
|
-
const i = Y(e?.sharedStatePatch,
|
|
134
|
+
}, ie = (n, e) => {
|
|
135
|
+
const r = R(e?.outputMessage), s = R(e?.summary), t = e?.status, a = t === "success" || t === "failed" ? t : "unknown";
|
|
136
|
+
a === "unknown" && console.warn(`Agent "${n}" returned missing/invalid status. Defaulting to "unknown".`);
|
|
137
|
+
const i = Y(e?.sharedStatePatch, n), o = re(e?.sharedResourceAdditions, n);
|
|
94
138
|
return {
|
|
95
139
|
outputMessage: r,
|
|
96
|
-
summary: s ?? r ??
|
|
140
|
+
summary: s ?? r ?? ae(a),
|
|
97
141
|
status: a,
|
|
98
|
-
sharedStatePatch: i
|
|
142
|
+
sharedStatePatch: i,
|
|
143
|
+
sharedResourceAdditions: o
|
|
99
144
|
};
|
|
100
|
-
},
|
|
101
|
-
const r =
|
|
145
|
+
}, x = 4e3, oe = async (n, e) => {
|
|
146
|
+
const r = b(e);
|
|
102
147
|
if (e?.signal?.aborted)
|
|
103
|
-
return await
|
|
104
|
-
...
|
|
148
|
+
return await p({ text: "Run cancelled; skipping agent execution" }, e), {
|
|
149
|
+
...n,
|
|
105
150
|
currentIntent: "none",
|
|
106
151
|
requiresFollowUp: !1
|
|
107
152
|
};
|
|
108
|
-
const { agentRegistry: s } = r?.services ?? {},
|
|
109
|
-
if (!
|
|
110
|
-
return console.warn(`No agent found for intent: ${
|
|
111
|
-
await
|
|
153
|
+
const { agentRegistry: s } = r?.services ?? {}, t = s?.get(n.currentIntent);
|
|
154
|
+
if (!t)
|
|
155
|
+
return console.warn(`No agent found for intent: ${n.currentIntent}`), n;
|
|
156
|
+
await p({ text: `Executing registered agent: ${t.agent.name}` }, e);
|
|
112
157
|
const a = {
|
|
113
158
|
...e ?? {},
|
|
114
159
|
metadata: {
|
|
115
160
|
...e?.metadata,
|
|
116
|
-
agentId:
|
|
161
|
+
agentId: t.agent.id
|
|
117
162
|
},
|
|
118
163
|
configurable: {
|
|
119
164
|
...r ?? {},
|
|
120
|
-
agentId:
|
|
121
|
-
context:
|
|
165
|
+
agentId: t.agent.id,
|
|
166
|
+
context: t.getContext ? await t.getContext() : void 0
|
|
122
167
|
}
|
|
123
168
|
};
|
|
124
169
|
let i;
|
|
125
170
|
try {
|
|
126
|
-
const
|
|
171
|
+
const c = await t.agent.createGraph().compile().invoke(
|
|
127
172
|
{
|
|
128
173
|
agentExecutionContext: {
|
|
129
|
-
...
|
|
174
|
+
...n.agentExecutionContext,
|
|
130
175
|
// deep clone on messages did not work in agents, so its a shallow clone here.
|
|
131
|
-
messages: [...
|
|
176
|
+
messages: [...n.agentExecutionContext.messages],
|
|
132
177
|
// deep clone to prevent accidental mutations by agents
|
|
133
|
-
priorSteps: structuredClone(
|
|
134
|
-
sharedState: structuredClone(
|
|
178
|
+
priorSteps: structuredClone(n.agentExecutionContext.priorSteps ?? []),
|
|
179
|
+
sharedState: structuredClone(n.agentExecutionContext.sharedState ?? {}),
|
|
180
|
+
sharedResources: structuredClone(n.agentExecutionContext.sharedResources ?? [])
|
|
135
181
|
}
|
|
136
182
|
},
|
|
137
183
|
a
|
|
138
184
|
);
|
|
139
|
-
i =
|
|
140
|
-
} catch (
|
|
141
|
-
if (
|
|
142
|
-
throw
|
|
143
|
-
const u =
|
|
144
|
-
console.error(`Agent "${
|
|
185
|
+
i = ie(t.agent.name, c), await p({ text: `Finished executing registered agent: ${t.agent.name}` }, e);
|
|
186
|
+
} catch (c) {
|
|
187
|
+
if (q(c) || e?.signal?.aborted || c instanceof Error && c.name === "AbortError")
|
|
188
|
+
throw c;
|
|
189
|
+
const u = c instanceof Error ? c.message : String(c);
|
|
190
|
+
console.error(`Agent "${t.agent.name}" failed:`, c), await p({ text: `Registered agent failed: ${t.agent.name}. ${u}` }, e), i = {
|
|
145
191
|
status: "failed",
|
|
146
192
|
outputMessage: `Agent execution failed: ${u}`,
|
|
147
193
|
summary: `Agent execution failed: ${u}`
|
|
148
194
|
};
|
|
149
195
|
}
|
|
150
|
-
const
|
|
151
|
-
if (
|
|
152
|
-
const
|
|
153
|
-
[truncated]` :
|
|
154
|
-
d.push(new O(
|
|
196
|
+
const o = i.outputMessage, d = [...n.agentExecutionContext.messages];
|
|
197
|
+
if (o) {
|
|
198
|
+
const c = o.length > x ? `${o.slice(0, x - 14)}
|
|
199
|
+
[truncated]` : o;
|
|
200
|
+
d.push(new O(c));
|
|
155
201
|
}
|
|
156
202
|
return {
|
|
157
|
-
...
|
|
158
|
-
stepCount:
|
|
159
|
-
lastExecutedAgent:
|
|
160
|
-
requiresFollowUp: i.status === "failed" ? !0 :
|
|
161
|
-
finalOutputMessage:
|
|
203
|
+
...n,
|
|
204
|
+
stepCount: n.stepCount + 1,
|
|
205
|
+
lastExecutedAgent: t.agent.id,
|
|
206
|
+
requiresFollowUp: i.status === "failed" ? !0 : n.requiresFollowUp,
|
|
207
|
+
finalOutputMessage: o ?? "",
|
|
162
208
|
agentExecutionContext: {
|
|
163
|
-
...
|
|
209
|
+
...n.agentExecutionContext,
|
|
164
210
|
messages: d,
|
|
165
211
|
priorSteps: [
|
|
166
|
-
...
|
|
212
|
+
...n.agentExecutionContext.priorSteps ?? [],
|
|
167
213
|
{
|
|
168
|
-
agentId:
|
|
169
|
-
assignedTask:
|
|
214
|
+
agentId: t.agent.id,
|
|
215
|
+
assignedTask: n.agentExecutionContext.assignedTask,
|
|
170
216
|
summary: i?.summary || "No summary provided.",
|
|
171
217
|
status: i?.status || "unknown"
|
|
172
218
|
}
|
|
173
219
|
],
|
|
174
220
|
sharedState: Z({
|
|
175
|
-
previousSharedState:
|
|
221
|
+
previousSharedState: n.agentExecutionContext.sharedState,
|
|
176
222
|
patch: i.sharedStatePatch,
|
|
177
|
-
agentId:
|
|
223
|
+
agentId: t.agent.id
|
|
224
|
+
}),
|
|
225
|
+
sharedResources: se({
|
|
226
|
+
previousSharedResources: n.agentExecutionContext.sharedResources,
|
|
227
|
+
additions: i.sharedResourceAdditions,
|
|
228
|
+
agentId: t.agent.id
|
|
178
229
|
})
|
|
179
230
|
}
|
|
180
231
|
};
|
|
181
|
-
},
|
|
182
|
-
if (
|
|
232
|
+
}, ce = async (n, e) => {
|
|
233
|
+
if (n.routing.mode !== "direct")
|
|
183
234
|
throw new Error("Direct agent assignment requires direct routing.");
|
|
184
|
-
return await
|
|
185
|
-
...
|
|
186
|
-
currentIntent:
|
|
235
|
+
return await p({ text: `Doing a direct route to agent: ${n.routing.agentId}` }, e), {
|
|
236
|
+
...n,
|
|
237
|
+
currentIntent: n.routing.agentId,
|
|
187
238
|
requiresFollowUp: !1,
|
|
188
239
|
agentExecutionContext: {
|
|
189
|
-
...
|
|
190
|
-
assignedTask:
|
|
240
|
+
...n.agentExecutionContext,
|
|
241
|
+
assignedTask: n.agentExecutionContext.userRequest
|
|
191
242
|
}
|
|
192
243
|
};
|
|
193
|
-
},
|
|
194
|
-
const r =
|
|
195
|
-
if (
|
|
244
|
+
}, de = 3, ue = (n) => n.routing.mode === "direct" ? "assignDirectAgent" : "intentLLM", ge = (n) => n.routing.mode === "direct" || n.stepCount >= de || !n.requiresFollowUp ? "exit" : "intentLLM", le = () => new T(D).addNode("ingestInput", J).addNode("assignDirectAgent", ce).addNode("intentLLM", F).addNode("executeRegisteredAgent", oe).addNode("exit", X).addEdge(j, "ingestInput").addConditionalEdges("ingestInput", ue).addEdge("assignDirectAgent", "executeRegisteredAgent").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges("executeRegisteredAgent", ge).addEdge("exit", H), he = (n, e) => {
|
|
245
|
+
const r = n.output?.usage_metadata ?? e.usage_metadata, s = n.output?.llmOutput?.tokenUsage, t = r?.input_tokens ?? s?.promptTokens, a = r?.output_tokens ?? s?.completionTokens, i = r?.total_tokens ?? s?.totalTokens;
|
|
246
|
+
if (t === void 0 || a === void 0 || i === void 0)
|
|
196
247
|
return;
|
|
197
|
-
const
|
|
248
|
+
const o = r?.input_token_details?.cache_read, d = r?.output_token_details?.reasoning;
|
|
198
249
|
return {
|
|
199
|
-
input:
|
|
250
|
+
input: t,
|
|
200
251
|
output: a,
|
|
201
252
|
total: i,
|
|
202
|
-
...
|
|
253
|
+
...o !== void 0 && { cacheRead: o },
|
|
203
254
|
...d !== void 0 && { reasoning: d }
|
|
204
255
|
};
|
|
205
|
-
},
|
|
206
|
-
switch (
|
|
256
|
+
}, pe = (n, e, r, s) => {
|
|
257
|
+
switch (n) {
|
|
207
258
|
case "chat_model":
|
|
208
259
|
case "llm":
|
|
209
260
|
return "model";
|
|
210
261
|
case "tool":
|
|
211
262
|
case "retriever":
|
|
212
|
-
return
|
|
263
|
+
return n;
|
|
213
264
|
case "chain":
|
|
214
265
|
return !s || e === "LangGraph" ? "workflow" : r === e ? "node" : "chain";
|
|
215
266
|
default:
|
|
216
267
|
return;
|
|
217
268
|
}
|
|
218
|
-
},
|
|
219
|
-
if (
|
|
220
|
-
return { message:
|
|
221
|
-
const e =
|
|
269
|
+
}, me = (n) => {
|
|
270
|
+
if (n instanceof Error)
|
|
271
|
+
return { message: n.message, name: n.name };
|
|
272
|
+
const e = n, r = typeof e?.message == "string" ? e.message : String(n ?? "Unknown runtime error"), s = typeof e?.name == "string" ? e.name : void 0;
|
|
222
273
|
return { message: r, ...s && { name: s } };
|
|
223
|
-
},
|
|
224
|
-
event:
|
|
274
|
+
}, ye = ({
|
|
275
|
+
event: n,
|
|
225
276
|
runId: e,
|
|
226
277
|
parentSpanId: r,
|
|
227
278
|
timestamp: s
|
|
228
279
|
}) => {
|
|
229
|
-
const
|
|
230
|
-
if (!
|
|
280
|
+
const t = /^on_(.+)_(start|end|error)$/u.exec(n.event);
|
|
281
|
+
if (!t)
|
|
231
282
|
return;
|
|
232
|
-
const [, a, i] =
|
|
233
|
-
if (!
|
|
283
|
+
const [, a, i] = t, o = n.metadata ?? {}, d = o.langgraph_node, c = pe(a, n.name, d, r);
|
|
284
|
+
if (!c)
|
|
234
285
|
return;
|
|
235
|
-
const u =
|
|
286
|
+
const u = o.agentId, g = o.model ?? o.ls_model_name, l = n.data, f = i === "end" && c === "model" ? he(l, o) : void 0, h = n.tags?.includes("langsmith:hidden") || d === "__start__", v = {
|
|
236
287
|
...g && { model: g },
|
|
237
|
-
...
|
|
288
|
+
...f && { tokenUsage: f },
|
|
238
289
|
...h && { internal: !0 }
|
|
239
290
|
}, w = {
|
|
240
|
-
id:
|
|
291
|
+
id: n.run_id,
|
|
241
292
|
...r && { parentId: r },
|
|
242
|
-
label:
|
|
243
|
-
type:
|
|
293
|
+
label: n.name,
|
|
294
|
+
type: c,
|
|
244
295
|
...Object.keys(v).length && { metadata: v }
|
|
245
|
-
},
|
|
296
|
+
}, m = { runId: e, timestamp: s, type: "runtime", ...u && { agentId: u } };
|
|
246
297
|
switch (i) {
|
|
247
298
|
case "start":
|
|
248
299
|
return {
|
|
249
|
-
...
|
|
300
|
+
...m,
|
|
250
301
|
phase: "started",
|
|
251
302
|
span: {
|
|
252
303
|
...w,
|
|
@@ -255,7 +306,7 @@ const B = async (t) => {
|
|
|
255
306
|
};
|
|
256
307
|
case "end":
|
|
257
308
|
return {
|
|
258
|
-
...
|
|
309
|
+
...m,
|
|
259
310
|
phase: "completed",
|
|
260
311
|
span: {
|
|
261
312
|
...w,
|
|
@@ -263,12 +314,12 @@ const B = async (t) => {
|
|
|
263
314
|
}
|
|
264
315
|
};
|
|
265
316
|
case "error":
|
|
266
|
-
return { ...
|
|
317
|
+
return { ...m, phase: "failed", span: { ...w, error: me(l?.error) } };
|
|
267
318
|
default:
|
|
268
319
|
return;
|
|
269
320
|
}
|
|
270
321
|
};
|
|
271
|
-
class
|
|
322
|
+
class S {
|
|
272
323
|
constructor() {
|
|
273
324
|
this.agentRegistry = /* @__PURE__ */ new Map();
|
|
274
325
|
}
|
|
@@ -285,7 +336,7 @@ class R {
|
|
|
285
336
|
return [...this.agentRegistry.values()];
|
|
286
337
|
}
|
|
287
338
|
}
|
|
288
|
-
class
|
|
339
|
+
class fe {
|
|
289
340
|
/**
|
|
290
341
|
* Create a new InterruptHandler tied to a specific compiled graph and config.
|
|
291
342
|
*/
|
|
@@ -309,7 +360,7 @@ class le {
|
|
|
309
360
|
agentId: e.agentId,
|
|
310
361
|
id: e.id,
|
|
311
362
|
payload: r
|
|
312
|
-
},
|
|
363
|
+
}, t = this.graph.streamEvents(null, {
|
|
313
364
|
...this.config,
|
|
314
365
|
configurable: {
|
|
315
366
|
...this.config.configurable,
|
|
@@ -318,7 +369,7 @@ class le {
|
|
|
318
369
|
subgraphs: !0,
|
|
319
370
|
version: "v2"
|
|
320
371
|
});
|
|
321
|
-
this.resolveWait?.(
|
|
372
|
+
this.resolveWait?.(t);
|
|
322
373
|
} catch (s) {
|
|
323
374
|
this.rejectWait?.(s);
|
|
324
375
|
} finally {
|
|
@@ -332,157 +383,157 @@ class le {
|
|
|
332
383
|
this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
|
|
333
384
|
}
|
|
334
385
|
}
|
|
335
|
-
const
|
|
386
|
+
const we = async (n) => {
|
|
336
387
|
try {
|
|
337
|
-
return await (await L()).embedDocuments(
|
|
388
|
+
return await (await L()).embedDocuments(n);
|
|
338
389
|
} catch (e) {
|
|
339
390
|
throw console.error("Failed to generate embeddings:", e), e;
|
|
340
391
|
}
|
|
341
|
-
}, C = async (
|
|
342
|
-
const r = e.get(
|
|
392
|
+
}, C = async (n, e) => {
|
|
393
|
+
const r = e.get(n);
|
|
343
394
|
if (r)
|
|
344
395
|
return r;
|
|
345
|
-
const s = await
|
|
346
|
-
return e.set(
|
|
396
|
+
const s = await we([n]);
|
|
397
|
+
return e.set(n, s[0]), s[0];
|
|
347
398
|
};
|
|
348
|
-
async function
|
|
349
|
-
const
|
|
399
|
+
async function ve(n, e, r, s) {
|
|
400
|
+
const t = `req-${Date.now()}`, i = {
|
|
350
401
|
type: "layerSearch",
|
|
351
|
-
precomputedEmbedding: s ? await C(
|
|
352
|
-
requestId:
|
|
402
|
+
precomputedEmbedding: s ? await C(n, s) : void 0,
|
|
403
|
+
requestId: t,
|
|
353
404
|
minScore: r
|
|
354
405
|
};
|
|
355
|
-
return await new Promise((
|
|
356
|
-
const d = (
|
|
357
|
-
|
|
406
|
+
return await new Promise((o) => {
|
|
407
|
+
const d = (c) => {
|
|
408
|
+
c.data.requestId === t && o(c.data.results);
|
|
358
409
|
};
|
|
359
410
|
e.addEventListener("message", d, { once: !0 }), e.postMessage(i);
|
|
360
411
|
});
|
|
361
412
|
}
|
|
362
|
-
function
|
|
363
|
-
const { worker: e } =
|
|
413
|
+
function Ee(n) {
|
|
414
|
+
const { worker: e } = n;
|
|
364
415
|
return {
|
|
365
416
|
async searchLayers({
|
|
366
417
|
text: r,
|
|
367
418
|
minScore: s,
|
|
368
|
-
embeddingCache:
|
|
419
|
+
embeddingCache: t
|
|
369
420
|
}) {
|
|
370
|
-
return await
|
|
421
|
+
return await ve(r, e, s, t);
|
|
371
422
|
}
|
|
372
423
|
};
|
|
373
424
|
}
|
|
374
|
-
const
|
|
375
|
-
combinedQuery:
|
|
425
|
+
const Re = async ({
|
|
426
|
+
combinedQuery: n,
|
|
376
427
|
layerIds: e,
|
|
377
428
|
embeddingsWorker: r,
|
|
378
429
|
minScore: s,
|
|
379
|
-
topResults:
|
|
430
|
+
topResults: t,
|
|
380
431
|
embeddingCache: a
|
|
381
432
|
}) => {
|
|
382
|
-
const i = `req-${Date.now()}`,
|
|
433
|
+
const i = `req-${Date.now()}`, o = a ? await C(n, a) : void 0, d = {
|
|
383
434
|
type: "fieldSearch",
|
|
384
435
|
layerIdForFieldsSearch: e,
|
|
385
|
-
precomputedEmbedding:
|
|
436
|
+
precomputedEmbedding: o,
|
|
386
437
|
requestId: i,
|
|
387
438
|
minScore: s,
|
|
388
|
-
topResults:
|
|
439
|
+
topResults: t
|
|
389
440
|
};
|
|
390
|
-
return await new Promise((
|
|
441
|
+
return await new Promise((c) => {
|
|
391
442
|
const u = (g) => {
|
|
392
443
|
if (g.data.requestId !== i)
|
|
393
444
|
return;
|
|
394
|
-
const l = g.data.results.map(({ layerId:
|
|
395
|
-
layerId:
|
|
445
|
+
const l = g.data.results.map(({ layerId: f, results: h }) => ({
|
|
446
|
+
layerId: f,
|
|
396
447
|
results: h
|
|
397
448
|
}));
|
|
398
|
-
|
|
449
|
+
c(l);
|
|
399
450
|
};
|
|
400
451
|
r.addEventListener("message", u, { once: !0 }), r.postMessage(d);
|
|
401
452
|
});
|
|
402
453
|
};
|
|
403
|
-
function
|
|
404
|
-
const { worker: e } =
|
|
454
|
+
function xe(n) {
|
|
455
|
+
const { worker: e } = n;
|
|
405
456
|
return {
|
|
406
|
-
async searchFields({ text: r, layerIds: s, minScore:
|
|
407
|
-
return await
|
|
457
|
+
async searchFields({ text: r, layerIds: s, minScore: t, topResults: a, embeddingCache: i }) {
|
|
458
|
+
return await Re({
|
|
408
459
|
combinedQuery: r,
|
|
409
460
|
layerIds: s,
|
|
410
461
|
embeddingsWorker: e,
|
|
411
|
-
minScore:
|
|
462
|
+
minScore: t,
|
|
412
463
|
topResults: a,
|
|
413
464
|
embeddingCache: i
|
|
414
465
|
});
|
|
415
466
|
}
|
|
416
467
|
};
|
|
417
468
|
}
|
|
418
|
-
const
|
|
419
|
-
const e =
|
|
469
|
+
const Se = (n) => {
|
|
470
|
+
const e = W.safeParse(n);
|
|
420
471
|
if (!e.success)
|
|
421
472
|
throw new Error("Embeddings response validation failed. Regenerate embeddings.");
|
|
422
473
|
return e.data;
|
|
423
|
-
},
|
|
474
|
+
}, be = (n, e) => {
|
|
424
475
|
const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
|
|
425
|
-
if (e.allLayers.forEach((
|
|
426
|
-
|
|
427
|
-
}),
|
|
476
|
+
if (e.allLayers.forEach((t) => {
|
|
477
|
+
t instanceof V && s.set(t.id, t);
|
|
478
|
+
}), n.length !== s.size)
|
|
428
479
|
throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
|
|
429
|
-
for (const
|
|
430
|
-
const a = s.get(
|
|
480
|
+
for (const t of n) {
|
|
481
|
+
const a = s.get(t.id);
|
|
431
482
|
if (!a)
|
|
432
483
|
throw new Error(
|
|
433
|
-
`Layer with ID ${
|
|
484
|
+
`Layer with ID ${t.id} not found in the original map during registry restoration. Regenerate embeddings.`
|
|
434
485
|
);
|
|
435
|
-
if (
|
|
486
|
+
if (t.fields.length !== a.fields.length)
|
|
436
487
|
throw new Error(
|
|
437
|
-
`Field count mismatch for layer ID ${
|
|
488
|
+
`Field count mismatch for layer ID ${t.id} during registry restoration. Regenerate embeddings.`
|
|
438
489
|
);
|
|
439
490
|
const i = {
|
|
440
|
-
name:
|
|
441
|
-
title:
|
|
442
|
-
description:
|
|
443
|
-
},
|
|
444
|
-
for (const d of
|
|
445
|
-
const
|
|
446
|
-
if (!
|
|
491
|
+
name: t.name,
|
|
492
|
+
title: t.title,
|
|
493
|
+
description: t.description
|
|
494
|
+
}, o = /* @__PURE__ */ new Map();
|
|
495
|
+
for (const d of t.fields) {
|
|
496
|
+
const c = a.fieldsIndex.get(d.name);
|
|
497
|
+
if (!c)
|
|
447
498
|
throw new Error(
|
|
448
|
-
`Field with name ${d.name} not found in the original layer ${
|
|
499
|
+
`Field with name ${d.name} not found in the original layer ${t.id} during registry restoration. Regenerate embeddings.`
|
|
449
500
|
);
|
|
450
|
-
|
|
501
|
+
o.set(d.name, {
|
|
451
502
|
name: d.name,
|
|
452
503
|
alias: a.getFieldAlias(d.name) ?? d.alias,
|
|
453
504
|
description: d.description,
|
|
454
|
-
type:
|
|
455
|
-
valueType:
|
|
505
|
+
type: c.type || "unknown",
|
|
506
|
+
valueType: c.valueType || "unknown",
|
|
456
507
|
domain: a.getFieldDomain(d.name) ?? void 0
|
|
457
508
|
});
|
|
458
509
|
}
|
|
459
|
-
r.set(
|
|
510
|
+
r.set(t.id, {
|
|
460
511
|
layerItem: i,
|
|
461
|
-
fieldRegistry:
|
|
512
|
+
fieldRegistry: o
|
|
462
513
|
});
|
|
463
514
|
}
|
|
464
515
|
return r;
|
|
465
|
-
},
|
|
516
|
+
}, Ae = async (n) => {
|
|
466
517
|
try {
|
|
467
|
-
return (await z(
|
|
518
|
+
return (await z(n, {
|
|
468
519
|
responseType: "json"
|
|
469
520
|
})).data;
|
|
470
521
|
} catch (e) {
|
|
471
|
-
throw new Error(`Failed to fetch data from ${
|
|
522
|
+
throw new Error(`Failed to fetch data from ${n}: ${String(e)}`);
|
|
472
523
|
}
|
|
473
|
-
},
|
|
474
|
-
const e =
|
|
524
|
+
}, Ce = async (n) => {
|
|
525
|
+
const e = n.map;
|
|
475
526
|
if (!e?.portalItem)
|
|
476
527
|
throw new Error("WebMap portal item is missing.");
|
|
477
528
|
const { resources: r } = await e.portalItem.fetchResources(), s = r.find((i) => i.resource.path === "embeddings-v01.json");
|
|
478
529
|
if (!s?.resource.url)
|
|
479
530
|
throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
|
|
480
|
-
const
|
|
481
|
-
return
|
|
531
|
+
const t = await Ae(s.resource.url);
|
|
532
|
+
return Se(t);
|
|
482
533
|
};
|
|
483
534
|
class k {
|
|
484
535
|
constructor() {
|
|
485
|
-
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new
|
|
536
|
+
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.sharedResources = [], this.agentRegistry = new S(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.parentRunIds = /* @__PURE__ */ new Map(), this.activeRuntimeSpans = /* @__PURE__ */ new Map(), this.runtimeEventsEnabled = !1, this.streamEpoch = 0;
|
|
486
537
|
}
|
|
487
538
|
/**
|
|
488
539
|
* Creates and returns an AI-ready Orchestrator instance.
|
|
@@ -494,12 +545,12 @@ class k {
|
|
|
494
545
|
r.runtimeEventsEnabled = e.runtimeEventsEnabled ?? !1;
|
|
495
546
|
try {
|
|
496
547
|
if (e.view?.map) {
|
|
497
|
-
await
|
|
498
|
-
const s = await
|
|
548
|
+
await N.whenOnce(() => e.view.ready);
|
|
549
|
+
const s = await Ce(e.view), t = be(
|
|
499
550
|
s.layers,
|
|
500
551
|
e.view.map
|
|
501
552
|
);
|
|
502
|
-
r.layersAndFieldsRegistry =
|
|
553
|
+
r.layersAndFieldsRegistry = t, r.embeddingsWorker = await B(s);
|
|
503
554
|
}
|
|
504
555
|
return e.agents?.forEach((s) => {
|
|
505
556
|
r.agentRegistry.register(s);
|
|
@@ -528,25 +579,25 @@ class k {
|
|
|
528
579
|
throw new Error("Orchestrator has no agents selected for this request.");
|
|
529
580
|
if (++this.streamEpoch, !e.trim())
|
|
530
581
|
return;
|
|
531
|
-
const
|
|
532
|
-
this.parentRunIds.clear(), this.activeRuntimeSpans.clear(), this.activeRunId =
|
|
533
|
-
const a = this.embeddingsWorker ?
|
|
582
|
+
const t = A();
|
|
583
|
+
this.parentRunIds.clear(), this.activeRuntimeSpans.clear(), this.activeRunId = t, this.activeAbortController = new AbortController(), this.graph || (this.graph = le().compile({ checkpointer: new P() }));
|
|
584
|
+
const a = this.embeddingsWorker ? Ee({ worker: this.embeddingsWorker }) : void 0, i = this.embeddingsWorker ? xe({ worker: this.embeddingsWorker }) : void 0, o = /* @__PURE__ */ new Map(), d = r.routing === "direct" ? { mode: "direct", agentId: r.agentId } : { mode: "auto" }, c = {
|
|
534
585
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
535
|
-
thread_id:
|
|
586
|
+
thread_id: t,
|
|
536
587
|
hitlResponse: null,
|
|
537
588
|
services: {
|
|
538
589
|
layerSearch: a,
|
|
539
590
|
fieldSearch: i,
|
|
540
591
|
layersAndFieldsRegistry: this.layersAndFieldsRegistry,
|
|
541
592
|
agentRegistry: s,
|
|
542
|
-
embeddingCache:
|
|
593
|
+
embeddingCache: o
|
|
543
594
|
}
|
|
544
595
|
}, u = {
|
|
545
596
|
version: "v2",
|
|
546
597
|
streamMode: "custom",
|
|
547
598
|
signal: this.activeAbortController.signal,
|
|
548
599
|
...this.runtimeEventsEnabled && { callbacks: [this.createHierarchyCallback()] },
|
|
549
|
-
configurable:
|
|
600
|
+
configurable: c,
|
|
550
601
|
subgraphs: !0
|
|
551
602
|
}, g = this.graph?.streamEvents(
|
|
552
603
|
{
|
|
@@ -555,54 +606,55 @@ class k {
|
|
|
555
606
|
userRequest: e,
|
|
556
607
|
messages: this.chatHistory,
|
|
557
608
|
priorSteps: this.priorSteps,
|
|
558
|
-
sharedState: this.sharedState
|
|
609
|
+
sharedState: this.sharedState,
|
|
610
|
+
sharedResources: this.sharedResources
|
|
559
611
|
}
|
|
560
612
|
},
|
|
561
613
|
u
|
|
562
614
|
), l = ++this.streamEpoch;
|
|
563
|
-
if (yield* this.pipeStream(g, l,
|
|
564
|
-
yield* this.createCancellationEvents(
|
|
615
|
+
if (yield* this.pipeStream(g, l, t), this.isRunCancelled(t)) {
|
|
616
|
+
yield* this.createCancellationEvents(t);
|
|
565
617
|
return;
|
|
566
618
|
}
|
|
567
619
|
for (; ; ) {
|
|
568
|
-
if (this.isRunCancelled(
|
|
569
|
-
yield* this.createCancellationEvents(
|
|
620
|
+
if (this.isRunCancelled(t)) {
|
|
621
|
+
yield* this.createCancellationEvents(t);
|
|
570
622
|
return;
|
|
571
623
|
}
|
|
572
|
-
const
|
|
573
|
-
if (!
|
|
624
|
+
const m = (await this.graph.getState(u, { subgraphs: !0 })).tasks.find((y) => y.interrupts.length > 0)?.interrupts[0]?.value;
|
|
625
|
+
if (!m)
|
|
574
626
|
break;
|
|
575
|
-
this.currentInterrupt =
|
|
627
|
+
this.currentInterrupt = m, this.interruptHandler = new fe(this.graph, u), yield* this.closeActiveRuntimeSpans(t, "interrupted"), yield { runId: t, timestamp: Date.now(), type: "interrupt", interrupt: m };
|
|
576
628
|
try {
|
|
577
|
-
const
|
|
578
|
-
yield* this.pipeStream(
|
|
579
|
-
} catch (
|
|
580
|
-
if (this.isRunCancelled(
|
|
581
|
-
yield* this.createCancellationEvents(
|
|
629
|
+
const y = await this.interruptHandler.waitForUser(), I = ++this.streamEpoch;
|
|
630
|
+
yield* this.pipeStream(y, I, t);
|
|
631
|
+
} catch (y) {
|
|
632
|
+
if (this.isRunCancelled(t)) {
|
|
633
|
+
yield* this.createCancellationEvents(t);
|
|
582
634
|
return;
|
|
583
635
|
}
|
|
584
|
-
if (
|
|
636
|
+
if (y) {
|
|
585
637
|
yield {
|
|
586
|
-
runId:
|
|
638
|
+
runId: t,
|
|
587
639
|
timestamp: Date.now(),
|
|
588
640
|
type: "error",
|
|
589
|
-
error: { message:
|
|
641
|
+
error: { message: y?.message }
|
|
590
642
|
};
|
|
591
643
|
return;
|
|
592
644
|
}
|
|
593
645
|
}
|
|
594
646
|
}
|
|
595
|
-
if (this.isRunCancelled(
|
|
596
|
-
yield* this.createCancellationEvents(
|
|
647
|
+
if (this.isRunCancelled(t)) {
|
|
648
|
+
yield* this.createCancellationEvents(t);
|
|
597
649
|
return;
|
|
598
650
|
}
|
|
599
651
|
const h = (await this.graph.getState(u, { subgraphs: !0 })).values;
|
|
600
|
-
if (this.isRunCancelled(
|
|
601
|
-
yield* this.createCancellationEvents(
|
|
652
|
+
if (this.isRunCancelled(t)) {
|
|
653
|
+
yield* this.createCancellationEvents(t);
|
|
602
654
|
return;
|
|
603
655
|
}
|
|
604
|
-
this.chatHistory = h.agentExecutionContext.messages.length ? h.agentExecutionContext.messages : this.chatHistory, this.priorSteps = h.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = h.agentExecutionContext.sharedState ?? {}, yield {
|
|
605
|
-
runId:
|
|
656
|
+
this.chatHistory = h.agentExecutionContext.messages.length ? h.agentExecutionContext.messages : this.chatHistory, this.priorSteps = h.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = h.agentExecutionContext.sharedState ?? {}, this.sharedResources = h.agentExecutionContext.sharedResources ?? [], yield {
|
|
657
|
+
runId: t,
|
|
606
658
|
timestamp: Date.now(),
|
|
607
659
|
type: "completed",
|
|
608
660
|
result: { content: h.finalOutputMessage }
|
|
@@ -612,7 +664,7 @@ class k {
|
|
|
612
664
|
* Start a new conversation by clearing chat history, prior steps, and shared state.
|
|
613
665
|
*/
|
|
614
666
|
newConversation() {
|
|
615
|
-
this.chatHistory = [], this.priorSteps = [], this.sharedState = {};
|
|
667
|
+
this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.sharedResources = [];
|
|
616
668
|
}
|
|
617
669
|
/**
|
|
618
670
|
* Generic resume for any HITL interrupt.
|
|
@@ -641,45 +693,45 @@ class k {
|
|
|
641
693
|
}
|
|
642
694
|
async *pipeStream(e, r, s) {
|
|
643
695
|
try {
|
|
644
|
-
for await (const
|
|
696
|
+
for await (const t of e) {
|
|
645
697
|
if (this.isRunCancelled(s) || r !== this.streamEpoch)
|
|
646
698
|
break;
|
|
647
699
|
if (this.runtimeEventsEnabled) {
|
|
648
|
-
const a =
|
|
649
|
-
event:
|
|
700
|
+
const a = ye({
|
|
701
|
+
event: t,
|
|
650
702
|
runId: s,
|
|
651
|
-
parentSpanId: this.parentRunIds.get(
|
|
703
|
+
parentSpanId: this.parentRunIds.get(t.run_id),
|
|
652
704
|
timestamp: Date.now()
|
|
653
705
|
});
|
|
654
706
|
a && (a.phase === "started" ? this.activeRuntimeSpans.set(a.span.id, a) : this.activeRuntimeSpans.delete(a.span.id), yield a);
|
|
655
707
|
}
|
|
656
|
-
|
|
708
|
+
t.event === "on_custom_event" && t.name === "trace_message" ? yield { runId: s, timestamp: Date.now(), type: "trace", data: t.data } : t.name === "graph_ux_suggestion" && (yield {
|
|
657
709
|
runId: s,
|
|
658
710
|
timestamp: Date.now(),
|
|
659
711
|
type: "ux-suggestion",
|
|
660
|
-
suggestion:
|
|
712
|
+
suggestion: t.data
|
|
661
713
|
});
|
|
662
714
|
}
|
|
663
|
-
} catch (
|
|
715
|
+
} catch (t) {
|
|
664
716
|
if (!this.isRunCancelled(s))
|
|
665
|
-
throw
|
|
717
|
+
throw t;
|
|
666
718
|
}
|
|
667
719
|
}
|
|
668
720
|
*createCancellationEvents(e) {
|
|
669
721
|
yield* this.closeActiveRuntimeSpans(e, "cancelled"), yield { runId: e, timestamp: Date.now(), type: "cancelled", reason: "user" };
|
|
670
722
|
}
|
|
671
723
|
*closeActiveRuntimeSpans(e, r) {
|
|
672
|
-
const s = Date.now(),
|
|
724
|
+
const s = Date.now(), t = [...this.activeRuntimeSpans.values()].reverse();
|
|
673
725
|
this.activeRuntimeSpans.clear();
|
|
674
|
-
for (const a of
|
|
675
|
-
const { input: i, ...
|
|
726
|
+
for (const a of t) {
|
|
727
|
+
const { input: i, ...o } = a.span;
|
|
676
728
|
yield {
|
|
677
729
|
type: "runtime",
|
|
678
730
|
phase: r,
|
|
679
731
|
runId: e,
|
|
680
732
|
timestamp: s,
|
|
681
733
|
...a.agentId && { agentId: a.agentId },
|
|
682
|
-
span:
|
|
734
|
+
span: o
|
|
683
735
|
};
|
|
684
736
|
}
|
|
685
737
|
}
|
|
@@ -688,12 +740,12 @@ class k {
|
|
|
688
740
|
const e = (r, s) => {
|
|
689
741
|
s && this.parentRunIds.set(r, s);
|
|
690
742
|
};
|
|
691
|
-
return
|
|
692
|
-
handleLLMStart: (r, s,
|
|
693
|
-
handleChatModelStart: (r, s,
|
|
694
|
-
handleChainStart: (r, s,
|
|
695
|
-
handleToolStart: (r, s,
|
|
696
|
-
handleRetrieverStart: (r, s,
|
|
743
|
+
return G.fromMethods({
|
|
744
|
+
handleLLMStart: (r, s, t, a) => e(t, a),
|
|
745
|
+
handleChatModelStart: (r, s, t, a) => e(t, a),
|
|
746
|
+
handleChainStart: (r, s, t, a) => e(t, a),
|
|
747
|
+
handleToolStart: (r, s, t, a) => e(t, a),
|
|
748
|
+
handleRetrieverStart: (r, s, t, a) => e(t, a)
|
|
697
749
|
});
|
|
698
750
|
}
|
|
699
751
|
isRunCancelled(e) {
|
|
@@ -709,18 +761,18 @@ class k {
|
|
|
709
761
|
if (!i)
|
|
710
762
|
throw new Error(`Agent is not registered: ${a}`);
|
|
711
763
|
return i;
|
|
712
|
-
}) : this.agentRegistry.list(),
|
|
713
|
-
return s.forEach((a) =>
|
|
764
|
+
}) : this.agentRegistry.list(), t = new S();
|
|
765
|
+
return s.forEach((a) => t.register(a)), t;
|
|
714
766
|
}
|
|
715
767
|
/**
|
|
716
768
|
* Disposes this instance by terminating the embeddings worker
|
|
717
769
|
* and cleaning up all related resources.
|
|
718
770
|
*/
|
|
719
771
|
dispose() {
|
|
720
|
-
this.embeddingsWorker && (this.embeddingsWorker.terminate(), this.embeddingsWorker = void 0), this.orchestratorReady = !1;
|
|
772
|
+
this.sharedResources = [], this.embeddingsWorker && (this.embeddingsWorker.terminate(), this.embeddingsWorker = void 0), this.orchestratorReady = !1;
|
|
721
773
|
}
|
|
722
774
|
}
|
|
723
775
|
export {
|
|
724
776
|
k as O,
|
|
725
|
-
|
|
777
|
+
we as g
|
|
726
778
|
};
|