@arcgis/ai-components 5.2.0-next.1 → 5.2.0-next.11
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/agent-utils/FunctionAgent.d.ts +2 -2
- package/dist/agent-utils/LLMAgent.d.ts +2 -2
- package/dist/agent-utils/LLMAgent.js +22 -22
- package/dist/agent-utils/WorkflowAgent.d.ts +2 -2
- package/dist/agent-utils/index.d.ts +99 -0
- package/dist/agent-utils/index.js +148 -0
- package/dist/agent-utils/middlewares/trace.js +25 -33
- package/dist/agent-utils/tools/FunctionTool.d.ts +2 -2
- package/dist/agent-utils/types.d.ts +30 -1
- package/dist/agent-utils/workflows/ConditionalWorkflow.d.ts +2 -2
- package/dist/agent-utils/workflows/LoopWorkflow.d.ts +2 -2
- package/dist/agent-utils/workflows/ParallelWorkflow.d.ts +2 -2
- package/dist/agent-utils/workflows/RouterWorkflow.d.ts +2 -2
- package/dist/agent-utils/workflows/SequentialWorkflow.d.ts +2 -2
- package/dist/agent-utils/workflows/SwitchWorkflow.d.ts +2 -2
- package/dist/cdn/{V2P4AIGG.js → 24QNMEFG.js} +1 -1
- package/dist/cdn/{NAUXSHIE.js → 34SG44C3.js} +2 -2
- package/dist/cdn/3JGWGKT6.js +2 -0
- package/dist/cdn/3NBDVZ2I.js +2 -0
- package/dist/cdn/3VOQD2MR.js +2 -0
- package/dist/cdn/434TAA3J.js +2 -0
- package/dist/cdn/53NTYC4I.js +2 -0
- package/dist/cdn/{4HU7735A.js → 5CV7R5IS.js} +6 -4
- package/dist/cdn/{AMP6IALT.js → 5W7S2RS4.js} +1 -1
- package/dist/cdn/{FL4W4VYN.js → 6ZW7Z36F.js} +16 -0
- package/dist/cdn/7CYGX4F4.js +2 -0
- package/dist/cdn/{DHOVCT6R.js → AZGGTNA3.js} +1 -1
- package/dist/cdn/B7WJFBOZ.js +2 -0
- package/dist/cdn/BX7FSMUU.js +56 -0
- package/dist/cdn/CHPQM77M.js +181 -0
- package/dist/cdn/DHKUXLU3.js +179 -0
- package/dist/cdn/DQSEBKOX.js +2 -0
- package/dist/cdn/DXVU45KM.js +2 -0
- package/dist/cdn/{P6OPJQMC.js → DZ2QWNUA.js} +1 -1
- package/dist/cdn/EBISDZ5H.js +2 -0
- package/dist/cdn/{MDVYQQUG.js → ERL2CB2Y.js} +5 -5
- package/dist/cdn/F6QHMKF5.js +2 -0
- package/dist/cdn/FUIGPHBH.js +2 -0
- package/dist/cdn/{AO7BQHKC.js → H2CHHGGH.js} +1 -1
- package/dist/cdn/{OH64RMOR.js → HWKDNS4K.js} +2 -2
- package/dist/cdn/IMQ4TVHF.js +16 -0
- package/dist/cdn/IOD3GDA7.js +2 -0
- package/dist/cdn/IR7PTESF.js +2 -0
- package/dist/cdn/IRZDTYO2.js +2 -0
- package/dist/cdn/JIWK6QK6.js +2 -0
- package/dist/cdn/{S6W6HV4T.js → JLKGS6Y5.js} +12 -12
- package/dist/cdn/K3JCH4XW.js +2 -0
- package/dist/cdn/KHXUWZHB.js +2 -0
- package/dist/cdn/LIFK3QSD.js +2 -0
- package/dist/cdn/NXKKG5TK.js +2 -0
- package/dist/cdn/{FX5JFRDL.js → O3EN27N5.js} +1 -1
- package/dist/cdn/O3RFFPU3.js +6 -0
- package/dist/cdn/P7DG5T3Z.js +9 -0
- package/dist/cdn/PBO6FZN6.js +2 -0
- package/dist/cdn/Q3ZW4FYA.js +3 -0
- package/dist/cdn/Q6LRANX6.js +2 -0
- package/dist/cdn/Q7TL5Q5N.js +2 -0
- package/dist/cdn/QCSN44H4.js +2 -0
- package/dist/cdn/R56X6ZKR.js +161 -0
- package/dist/cdn/{HB5A5R2E.js → RUURNLTP.js} +1 -1
- package/dist/cdn/T43LEBBE.js +47 -0
- package/dist/cdn/{ZLXN7NMF.js → T537PKP4.js} +9 -7
- package/dist/cdn/TR4GFL7X.js +2 -0
- package/dist/cdn/{3PKJWIC3.js → UPEEHMSY.js} +1 -1
- package/dist/cdn/WAIFKDR3.js +2 -0
- package/dist/cdn/WNS5ZUF5.js +2 -0
- package/dist/cdn/X4XY5HIE.js +2 -0
- package/dist/cdn/XOH56EQ2.js +2 -0
- package/dist/cdn/XON27U6U.js +2 -0
- package/dist/cdn/{H7422XUG.js → YLN2BZ5J.js} +1 -1
- package/dist/cdn/{2AXF774U.js → YUKR4AZW.js} +1 -1
- package/dist/cdn/{JY6LLOUJ.js → Z2G7MP5L.js} +3 -3
- package/dist/cdn/ZEYIBYSF.js +66 -0
- package/dist/cdn/agent-utils/index.js +2 -0
- package/dist/cdn/agent-utils/middlewares/humanInTheLoop.js +3 -0
- package/dist/cdn/agent-utils/middlewares/middleware.js +2 -0
- package/dist/cdn/agent-utils/middlewares/trace.js +2 -0
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/main.css +1 -1
- package/dist/chunks/adapter.js +1390 -1323
- package/dist/chunks/arcgisKnowledgeGraph.js +109 -72
- package/dist/chunks/dataExplorationGraph.js +108 -96
- package/dist/chunks/generateLayerDescriptions.js +206 -168
- package/dist/chunks/helpGraph.js +16 -13
- package/dist/chunks/index.js +11 -0
- package/dist/chunks/intent_prompt.js +16 -0
- package/dist/chunks/layerStylingGraph.js +23 -20
- package/dist/chunks/navigationGraph.js +34 -30
- package/dist/chunks/orchestrator.js +241 -201
- package/dist/chunks/slottableRequestUtils.js +3 -7
- package/dist/chunks/summarize_query_response_prompt.js +9 -7
- package/dist/chunks/toolCallResponse.js +5 -3
- package/dist/components/arcgis-assistant/customElement.d.ts +15 -0
- package/dist/components/arcgis-assistant/customElement.js +228 -127
- package/dist/components/arcgis-assistant/index.js +2 -3
- package/dist/components/arcgis-assistant/types.d.ts +14 -1
- package/dist/components/arcgis-assistant-chat/customElement.d.ts +8 -2
- package/dist/components/arcgis-assistant-chat/customElement.js +7 -7
- package/dist/components/arcgis-assistant-chat-entry/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-chat-entry/customElement.js +25 -18
- package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +1 -0
- package/dist/components/arcgis-assistant-help-agent/customElement.js +1 -0
- package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-interrupt/customElement.js +13 -9
- package/dist/components/arcgis-assistant-interrupt-preview/customElement.js +20 -0
- package/dist/components/arcgis-assistant-interrupt-preview/index.js +2 -0
- package/dist/components/arcgis-assistant-knowledge-agent/customElement.d.ts +7 -7
- package/dist/components/arcgis-assistant-knowledge-agent/customElement.js +1 -0
- package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +1 -0
- package/dist/components/arcgis-assistant-message/customElement.d.ts +23 -0
- package/dist/components/arcgis-assistant-message/customElement.js +28 -26
- package/dist/components/arcgis-assistant-message/index.d.ts +1 -0
- package/dist/components/arcgis-assistant-message/index.js +2 -0
- package/dist/components/arcgis-assistant-message-block/customElement.d.ts +1 -1
- package/dist/components/arcgis-assistant-message-block/customElement.js +18 -11
- package/dist/components/arcgis-assistant-message-block/index.js +1 -0
- package/dist/components/arcgis-assistant-message-feedback/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-message-footer/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-message-loading/customElement.d.ts +8 -1
- package/dist/components/arcgis-assistant-message-loading/customElement.js +8 -8
- package/dist/components/arcgis-assistant-message-loading/index.js +1 -0
- package/dist/components/arcgis-assistant-message-log/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-message-read-aloud/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-message-text/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-navigation-agent/customElement.js +1 -0
- package/dist/components/arcgis-assistant-speech-input/customElement.d.ts +6 -1
- package/dist/components/arcgis-assistant-suggested-prompts/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-suggested-prompts/customElement.js +8 -8
- package/dist/components/arcgis-assistant-user-message/customElement.d.ts +4 -1
- package/dist/components/arcgis-assistant-user-message/customElement.js +1 -1
- 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/index.d.ts +4 -0
- package/dist/loader.js +6 -5
- package/dist/orchestrator/registry/agentRegistry.d.ts +33 -0
- package/dist/types/lumina.d.ts +10 -4
- package/dist/types/preact.d.ts +11 -4
- package/dist/types/react.d.ts +12 -4
- package/dist/types/stencil.d.ts +10 -4
- package/dist/utils/index.d.ts +87 -43
- package/dist/utils/index.js +54 -49
- package/package.json +8 -7
- package/dist/cdn/462JBSEV.js +0 -422
- package/dist/cdn/7BCR6TUO.js +0 -2
- package/dist/cdn/7GH7VSB2.js +0 -2
- package/dist/cdn/7PLV4QH6.js +0 -2
- package/dist/cdn/DDLZOMUY.js +0 -2
- package/dist/cdn/FHVXO2WG.js +0 -166
- package/dist/cdn/GSEPHN3A.js +0 -106
- package/dist/cdn/MH5RPXHM.js +0 -2
- package/dist/cdn/NVI3I46B.js +0 -2
- package/dist/cdn/OAVEHGB6.js +0 -2
- package/dist/cdn/ON2V5XI2.js +0 -3
- package/dist/cdn/QR54T33D.js +0 -2
- package/dist/cdn/RVOAPUBN.js +0 -2
- package/dist/cdn/SXDLXCIM.js +0 -2
- package/dist/cdn/USMDJUFS.js +0 -2
- package/dist/cdn/V5YEZSRY.js +0 -16
- package/dist/cdn/Y333DGV6.js +0 -2
- package/dist/cdn/YY2SBO3V.js +0 -2
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
5
|
-
import { isGraphInterrupt as
|
|
6
|
-
import { HumanMessage as
|
|
2
|
+
import R from "@arcgis/core/identity/IdentityManager.js";
|
|
3
|
+
import C from "@arcgis/core/portal/Portal.js";
|
|
4
|
+
import { n as I, o as v, D as k, p as A, q as M, W as F } from "./generateLayerDescriptions.js";
|
|
5
|
+
import { isGraphInterrupt as D, StateGraph as L, START as W, END as $, MemorySaver as j } from "@langchain/langgraph/web";
|
|
6
|
+
import { HumanMessage as q, AIMessage as H } from "@langchain/core/messages";
|
|
7
|
+
import { s as l } from "./index.js";
|
|
7
8
|
import * as P from "@arcgis/core/core/reactiveUtils.js";
|
|
8
|
-
import
|
|
9
|
-
import
|
|
10
|
-
const
|
|
11
|
-
const e = await
|
|
9
|
+
import U from "@arcgis/core/layers/FeatureLayer.js";
|
|
10
|
+
import O from "@arcgis/core/request.js";
|
|
11
|
+
const T = async (t) => {
|
|
12
|
+
const e = await N(), r = await I("default"), s = C.getDefault(), a = (await R.getCredential(`${s.url}/sharing`)).token, i = {
|
|
12
13
|
type: "generateEmbeddings",
|
|
13
14
|
webmapEmbeddings: t,
|
|
14
|
-
auth: { apiUrl:
|
|
15
|
+
auth: { apiUrl: r, token: a }
|
|
15
16
|
};
|
|
16
|
-
return e.postMessage(
|
|
17
|
+
return e.postMessage(i), await new Promise((c, d) => {
|
|
17
18
|
const o = (u) => {
|
|
18
19
|
u.data === "completed" && (e.removeEventListener("message", o), c());
|
|
19
20
|
}, g = (u) => {
|
|
@@ -21,58 +22,59 @@ const O = async (t) => {
|
|
|
21
22
|
};
|
|
22
23
|
e.addEventListener("message", o), e.addEventListener("error", g, { once: !0 });
|
|
23
24
|
}), e;
|
|
24
|
-
},
|
|
25
|
+
}, N = async () => {
|
|
25
26
|
{
|
|
26
27
|
const t = (await import("./embeddings.worker.js")).default;
|
|
27
28
|
return new t();
|
|
28
29
|
}
|
|
29
|
-
},
|
|
30
|
+
}, G = (t) => {
|
|
30
31
|
t.currentIntent = "none";
|
|
31
|
-
},
|
|
32
|
+
}, _ = async (t, e) => {
|
|
33
|
+
const r = v(e);
|
|
32
34
|
if (t.agentExecutionContext.userRequest) {
|
|
33
|
-
const n = new
|
|
34
|
-
t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n],
|
|
35
|
+
const n = new q(t.agentExecutionContext.userRequest.trim());
|
|
36
|
+
t.agentExecutionContext.messages = [...t.agentExecutionContext.messages, n], G(t);
|
|
35
37
|
}
|
|
36
|
-
const s =
|
|
38
|
+
const s = r?.services.agentRegistry.list().map((n) => n.agent.id) ?? [];
|
|
37
39
|
return await l({ text: `Available agents: ${[...s].join(", ")}` }, e), await l({ text: "Analyzing user input" }, e), t;
|
|
38
|
-
},
|
|
39
|
-
if (!
|
|
40
|
+
}, V = async (t, e) => (await l({ text: "Exiting..." }, e), t), w = (t) => typeof t == "object" && t !== null && !Array.isArray(t), z = (t, e) => {
|
|
41
|
+
if (!w(t)) {
|
|
40
42
|
t !== void 0 && console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`);
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
|
-
const
|
|
44
|
-
for (const [
|
|
45
|
-
if (!
|
|
45
|
+
const r = {};
|
|
46
|
+
for (const [s, n] of Object.entries(t)) {
|
|
47
|
+
if (!w(n) || !("value" in n)) {
|
|
46
48
|
console.warn(
|
|
47
|
-
`Agent "${e}" returned invalid sharedStatePatch entry for key "${
|
|
49
|
+
`Agent "${e}" returned invalid sharedStatePatch entry for key "${s}". Ignoring that entry.`
|
|
48
50
|
);
|
|
49
51
|
continue;
|
|
50
52
|
}
|
|
51
|
-
s
|
|
53
|
+
r[s] = { value: n.value };
|
|
52
54
|
}
|
|
53
|
-
return
|
|
54
|
-
},
|
|
55
|
-
const { previousSharedState: e, patch:
|
|
56
|
-
if (!
|
|
55
|
+
return r;
|
|
56
|
+
}, Q = (t) => {
|
|
57
|
+
const { previousSharedState: e, patch: r, agentId: s } = t;
|
|
58
|
+
if (!r)
|
|
57
59
|
return e;
|
|
58
|
-
const
|
|
60
|
+
const n = Date.now(), a = {
|
|
59
61
|
...e
|
|
60
62
|
};
|
|
61
|
-
for (const [
|
|
62
|
-
c?.value !== void 0 && (i
|
|
63
|
+
for (const [i, c] of Object.entries(r))
|
|
64
|
+
c?.value !== void 0 && (a[i] = {
|
|
63
65
|
value: c.value,
|
|
64
66
|
meta: {
|
|
65
|
-
updatedByAgentId:
|
|
66
|
-
updatedAt:
|
|
67
|
+
updatedByAgentId: s,
|
|
68
|
+
updatedAt: n
|
|
67
69
|
}
|
|
68
70
|
});
|
|
69
|
-
return
|
|
70
|
-
},
|
|
71
|
+
return a;
|
|
72
|
+
}, f = (t) => {
|
|
71
73
|
if (typeof t != "string")
|
|
72
74
|
return;
|
|
73
75
|
const e = t.trim();
|
|
74
76
|
return e || void 0;
|
|
75
|
-
},
|
|
77
|
+
}, B = (t) => {
|
|
76
78
|
switch (t) {
|
|
77
79
|
case "failed":
|
|
78
80
|
return "Agent failed without a summary.";
|
|
@@ -83,32 +85,39 @@ const O = async (t) => {
|
|
|
83
85
|
default:
|
|
84
86
|
return "Agent completed without a summary.";
|
|
85
87
|
}
|
|
86
|
-
},
|
|
87
|
-
const
|
|
88
|
-
|
|
89
|
-
const
|
|
88
|
+
}, J = (t, e) => {
|
|
89
|
+
const r = f(e?.outputMessage), s = f(e?.summary), n = e?.status, a = n === "success" || n === "failed" ? n : "unknown";
|
|
90
|
+
a === "unknown" && console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);
|
|
91
|
+
const i = z(e?.sharedStatePatch, t);
|
|
90
92
|
return {
|
|
91
|
-
outputMessage:
|
|
92
|
-
summary:
|
|
93
|
-
status:
|
|
94
|
-
sharedStatePatch:
|
|
93
|
+
outputMessage: r,
|
|
94
|
+
summary: s ?? r ?? B(a),
|
|
95
|
+
status: a,
|
|
96
|
+
sharedStatePatch: i
|
|
95
97
|
};
|
|
96
|
-
},
|
|
97
|
-
const
|
|
98
|
-
if (
|
|
98
|
+
}, E = 4e3, K = async (t, e) => {
|
|
99
|
+
const r = v(e);
|
|
100
|
+
if (r?.abortSignal?.aborted)
|
|
101
|
+
return await l({ text: "Run cancelled; skipping agent execution" }, e), {
|
|
102
|
+
...t,
|
|
103
|
+
currentIntent: "none",
|
|
104
|
+
requiresFollowUp: !1
|
|
105
|
+
};
|
|
106
|
+
const { agentRegistry: s } = r?.services ?? {}, n = s?.get(t.currentIntent);
|
|
107
|
+
if (!n)
|
|
99
108
|
return console.warn(`No agent found for intent: ${t.currentIntent}`), t;
|
|
100
|
-
await l({ text: `Executing registered agent: ${
|
|
101
|
-
const
|
|
109
|
+
await l({ text: `Executing registered agent: ${n.agent.name}` }, e);
|
|
110
|
+
const a = {
|
|
102
111
|
...e ?? {},
|
|
103
112
|
configurable: {
|
|
104
|
-
...
|
|
105
|
-
agentId:
|
|
106
|
-
context:
|
|
113
|
+
...r ?? {},
|
|
114
|
+
agentId: n.agent.id,
|
|
115
|
+
context: n.getContext ? await n.getContext() : void 0
|
|
107
116
|
}
|
|
108
117
|
};
|
|
109
|
-
let
|
|
118
|
+
let i;
|
|
110
119
|
try {
|
|
111
|
-
const o = await
|
|
120
|
+
const o = await n.agent.createGraph().compile().invoke(
|
|
112
121
|
{
|
|
113
122
|
agentExecutionContext: {
|
|
114
123
|
...t.agentExecutionContext,
|
|
@@ -119,30 +128,30 @@ const O = async (t) => {
|
|
|
119
128
|
sharedState: structuredClone(t.agentExecutionContext.sharedState ?? {})
|
|
120
129
|
}
|
|
121
130
|
},
|
|
122
|
-
|
|
131
|
+
a
|
|
123
132
|
);
|
|
124
|
-
|
|
133
|
+
i = J(n.agent.name, o), await l({ text: `Finished executing registered agent: ${n.agent.name}` }, e);
|
|
125
134
|
} catch (o) {
|
|
126
|
-
if (
|
|
135
|
+
if (D(o))
|
|
127
136
|
throw o;
|
|
128
137
|
const g = o instanceof Error ? o.message : String(o);
|
|
129
|
-
console.error(`Agent "${
|
|
138
|
+
console.error(`Agent "${n.agent.name}" failed:`, o), await l({ text: `Registered agent failed: ${n.agent.name}. ${g}` }, e), i = {
|
|
130
139
|
status: "failed",
|
|
131
140
|
outputMessage: `Agent execution failed: ${g}`,
|
|
132
141
|
summary: `Agent execution failed: ${g}`
|
|
133
142
|
};
|
|
134
143
|
}
|
|
135
|
-
const c =
|
|
144
|
+
const c = i.outputMessage, d = [...t.agentExecutionContext.messages];
|
|
136
145
|
if (c) {
|
|
137
|
-
const o = c.length >
|
|
146
|
+
const o = c.length > E ? `${c.slice(0, E - 14)}
|
|
138
147
|
[truncated]` : c;
|
|
139
|
-
d.push(new
|
|
148
|
+
d.push(new H(o));
|
|
140
149
|
}
|
|
141
150
|
return {
|
|
142
151
|
...t,
|
|
143
152
|
stepCount: t.stepCount + 1,
|
|
144
|
-
lastExecutedAgent:
|
|
145
|
-
requiresFollowUp:
|
|
153
|
+
lastExecutedAgent: n.agent.id,
|
|
154
|
+
requiresFollowUp: i.status === "failed" ? !0 : t.requiresFollowUp,
|
|
146
155
|
finalOutputMessage: c ?? "",
|
|
147
156
|
agentExecutionContext: {
|
|
148
157
|
...t.agentExecutionContext,
|
|
@@ -150,32 +159,32 @@ const O = async (t) => {
|
|
|
150
159
|
priorSteps: [
|
|
151
160
|
...t.agentExecutionContext.priorSteps ?? [],
|
|
152
161
|
{
|
|
153
|
-
agentId:
|
|
162
|
+
agentId: n.agent.id,
|
|
154
163
|
assignedTask: t.agentExecutionContext.assignedTask,
|
|
155
|
-
summary:
|
|
156
|
-
status:
|
|
164
|
+
summary: i?.summary || "No summary provided.",
|
|
165
|
+
status: i?.status || "unknown"
|
|
157
166
|
}
|
|
158
167
|
],
|
|
159
|
-
sharedState:
|
|
168
|
+
sharedState: Q({
|
|
160
169
|
previousSharedState: t.agentExecutionContext.sharedState,
|
|
161
|
-
patch:
|
|
162
|
-
agentId:
|
|
170
|
+
patch: i.sharedStatePatch,
|
|
171
|
+
agentId: n.agent.id
|
|
163
172
|
})
|
|
164
173
|
}
|
|
165
174
|
};
|
|
166
|
-
},
|
|
175
|
+
}, X = 3, Y = () => new L(k).addNode("ingestInput", _).addNode("intentLLM", A).addNode("executeRegisteredAgent", K).addNode("exit", V).addEdge(W, "ingestInput").addEdge("ingestInput", "intentLLM").addConditionalEdges("intentLLM", (e) => e.currentIntent === "none" || e.currentIntent === e.lastExecutedAgent ? "exit" : "executeRegisteredAgent").addConditionalEdges(
|
|
167
176
|
"executeRegisteredAgent",
|
|
168
|
-
(e) => e.stepCount >=
|
|
169
|
-
).addEdge("exit",
|
|
170
|
-
class
|
|
177
|
+
(e) => e.stepCount >= X || !e.requiresFollowUp ? "exit" : "intentLLM"
|
|
178
|
+
).addEdge("exit", $);
|
|
179
|
+
class Z {
|
|
171
180
|
constructor() {
|
|
172
181
|
this.agentRegistry = /* @__PURE__ */ new Map();
|
|
173
182
|
}
|
|
174
183
|
register(e) {
|
|
175
|
-
const { agent:
|
|
176
|
-
if (this.agentRegistry.has(
|
|
177
|
-
throw new Error(`Duplicate agent id: ${
|
|
178
|
-
this.agentRegistry.set(
|
|
184
|
+
const { agent: r } = e;
|
|
185
|
+
if (this.agentRegistry.has(r.id))
|
|
186
|
+
throw new Error(`Duplicate agent id: ${r.id}`);
|
|
187
|
+
this.agentRegistry.set(r.id, e);
|
|
179
188
|
}
|
|
180
189
|
get(e) {
|
|
181
190
|
return this.agentRegistry.get(e);
|
|
@@ -184,42 +193,42 @@ class X {
|
|
|
184
193
|
return [...this.agentRegistry.values()];
|
|
185
194
|
}
|
|
186
195
|
}
|
|
187
|
-
class
|
|
196
|
+
class ee {
|
|
188
197
|
/**
|
|
189
198
|
* Create a new InterruptHandler tied to a specific compiled graph and config.
|
|
190
199
|
*/
|
|
191
|
-
constructor(e,
|
|
192
|
-
this.graph = e, this.config = { ...
|
|
200
|
+
constructor(e, r) {
|
|
201
|
+
this.graph = e, this.config = { ...r };
|
|
193
202
|
}
|
|
194
203
|
/**
|
|
195
204
|
* Returns a promise that resolves when the user provides a HITL response.
|
|
196
205
|
*/
|
|
197
206
|
async waitForUser() {
|
|
198
|
-
return await new Promise((e,
|
|
199
|
-
this.resolveWait = e, this.rejectWait =
|
|
207
|
+
return await new Promise((e, r) => {
|
|
208
|
+
this.resolveWait = e, this.rejectWait = r;
|
|
200
209
|
});
|
|
201
210
|
}
|
|
202
211
|
/**
|
|
203
212
|
* Resume graph execution after the UI responds to an interrupt.
|
|
204
213
|
*/
|
|
205
|
-
handle(e,
|
|
214
|
+
handle(e, r) {
|
|
206
215
|
try {
|
|
207
|
-
const
|
|
216
|
+
const s = {
|
|
208
217
|
agentId: e.agentId,
|
|
209
218
|
id: e.id,
|
|
210
|
-
payload:
|
|
211
|
-
},
|
|
219
|
+
payload: r
|
|
220
|
+
}, n = this.graph.streamEvents(null, {
|
|
212
221
|
...this.config,
|
|
213
222
|
configurable: {
|
|
214
223
|
...this.config.configurable,
|
|
215
|
-
hitlResponse:
|
|
224
|
+
hitlResponse: s
|
|
216
225
|
},
|
|
217
226
|
subgraphs: !0,
|
|
218
227
|
version: "v2"
|
|
219
228
|
});
|
|
220
|
-
this.resolveWait?.(
|
|
221
|
-
} catch (
|
|
222
|
-
this.rejectWait?.(
|
|
229
|
+
this.resolveWait?.(n);
|
|
230
|
+
} catch (s) {
|
|
231
|
+
this.rejectWait?.(s);
|
|
223
232
|
} finally {
|
|
224
233
|
this.resolveWait = void 0, this.rejectWait = void 0;
|
|
225
234
|
}
|
|
@@ -231,157 +240,157 @@ class Y {
|
|
|
231
240
|
this.rejectWait && (this.rejectWait(new Error("Request cancelled by user.")), this.resolveWait = void 0, this.rejectWait = void 0);
|
|
232
241
|
}
|
|
233
242
|
}
|
|
234
|
-
const
|
|
243
|
+
const te = async (t) => {
|
|
235
244
|
try {
|
|
236
245
|
return await (await M()).embedDocuments(t);
|
|
237
246
|
} catch (e) {
|
|
238
247
|
throw console.error("Failed to generate embeddings:", e), e;
|
|
239
248
|
}
|
|
240
|
-
},
|
|
241
|
-
const
|
|
242
|
-
if (
|
|
243
|
-
return
|
|
244
|
-
const
|
|
245
|
-
return e.set(t,
|
|
249
|
+
}, b = async (t, e) => {
|
|
250
|
+
const r = e.get(t);
|
|
251
|
+
if (r)
|
|
252
|
+
return r;
|
|
253
|
+
const s = await te([t]);
|
|
254
|
+
return e.set(t, s[0]), s[0];
|
|
246
255
|
};
|
|
247
|
-
async function
|
|
248
|
-
const
|
|
256
|
+
async function re(t, e, r, s) {
|
|
257
|
+
const n = `req-${Date.now()}`, i = {
|
|
249
258
|
type: "layerSearch",
|
|
250
|
-
precomputedEmbedding:
|
|
251
|
-
requestId:
|
|
252
|
-
minScore:
|
|
259
|
+
precomputedEmbedding: s ? await b(t, s) : void 0,
|
|
260
|
+
requestId: n,
|
|
261
|
+
minScore: r
|
|
253
262
|
};
|
|
254
263
|
return await new Promise((c) => {
|
|
255
264
|
const d = (o) => {
|
|
256
|
-
o.data.requestId ===
|
|
265
|
+
o.data.requestId === n && c(o.data.results);
|
|
257
266
|
};
|
|
258
|
-
e.addEventListener("message", d, { once: !0 }), e.postMessage(
|
|
267
|
+
e.addEventListener("message", d, { once: !0 }), e.postMessage(i);
|
|
259
268
|
});
|
|
260
269
|
}
|
|
261
|
-
function
|
|
270
|
+
function ne(t) {
|
|
262
271
|
const { worker: e } = t;
|
|
263
272
|
return {
|
|
264
273
|
async searchLayers({
|
|
265
|
-
text:
|
|
266
|
-
minScore:
|
|
267
|
-
embeddingCache:
|
|
274
|
+
text: r,
|
|
275
|
+
minScore: s,
|
|
276
|
+
embeddingCache: n
|
|
268
277
|
}) {
|
|
269
|
-
return await
|
|
278
|
+
return await re(r, e, s, n);
|
|
270
279
|
}
|
|
271
280
|
};
|
|
272
281
|
}
|
|
273
|
-
const
|
|
282
|
+
const se = async ({
|
|
274
283
|
combinedQuery: t,
|
|
275
284
|
layerIds: e,
|
|
276
|
-
embeddingsWorker:
|
|
277
|
-
minScore:
|
|
278
|
-
topResults:
|
|
279
|
-
embeddingCache:
|
|
285
|
+
embeddingsWorker: r,
|
|
286
|
+
minScore: s,
|
|
287
|
+
topResults: n,
|
|
288
|
+
embeddingCache: a
|
|
280
289
|
}) => {
|
|
281
|
-
const
|
|
290
|
+
const i = `req-${Date.now()}`, c = a ? await b(t, a) : void 0, d = {
|
|
282
291
|
type: "fieldSearch",
|
|
283
292
|
layerIdForFieldsSearch: e,
|
|
284
293
|
precomputedEmbedding: c,
|
|
285
|
-
requestId:
|
|
286
|
-
minScore:
|
|
287
|
-
topResults:
|
|
294
|
+
requestId: i,
|
|
295
|
+
minScore: s,
|
|
296
|
+
topResults: n
|
|
288
297
|
};
|
|
289
298
|
return await new Promise((o) => {
|
|
290
299
|
const g = (u) => {
|
|
291
|
-
if (u.data.requestId !==
|
|
300
|
+
if (u.data.requestId !== i)
|
|
292
301
|
return;
|
|
293
|
-
const p = u.data.results.map(({ layerId:
|
|
294
|
-
layerId:
|
|
295
|
-
results:
|
|
302
|
+
const p = u.data.results.map(({ layerId: y, results: m }) => ({
|
|
303
|
+
layerId: y,
|
|
304
|
+
results: m
|
|
296
305
|
}));
|
|
297
306
|
o(p);
|
|
298
307
|
};
|
|
299
|
-
|
|
308
|
+
r.addEventListener("message", g, { once: !0 }), r.postMessage(d);
|
|
300
309
|
});
|
|
301
310
|
};
|
|
302
|
-
function
|
|
311
|
+
function ae(t) {
|
|
303
312
|
const { worker: e } = t;
|
|
304
313
|
return {
|
|
305
|
-
async searchFields({ text:
|
|
306
|
-
return await
|
|
307
|
-
combinedQuery:
|
|
308
|
-
layerIds:
|
|
314
|
+
async searchFields({ text: r, layerIds: s, minScore: n, topResults: a, embeddingCache: i }) {
|
|
315
|
+
return await se({
|
|
316
|
+
combinedQuery: r,
|
|
317
|
+
layerIds: s,
|
|
309
318
|
embeddingsWorker: e,
|
|
310
|
-
minScore:
|
|
311
|
-
topResults:
|
|
312
|
-
embeddingCache:
|
|
319
|
+
minScore: n,
|
|
320
|
+
topResults: a,
|
|
321
|
+
embeddingCache: i
|
|
313
322
|
});
|
|
314
323
|
}
|
|
315
324
|
};
|
|
316
325
|
}
|
|
317
|
-
const
|
|
318
|
-
const e =
|
|
326
|
+
const ie = (t) => {
|
|
327
|
+
const e = F.safeParse(t);
|
|
319
328
|
if (!e.success)
|
|
320
329
|
throw new Error("Embeddings response validation failed. Regenerate embeddings.");
|
|
321
330
|
return e.data;
|
|
322
|
-
},
|
|
323
|
-
const
|
|
324
|
-
if (e.allLayers.forEach((
|
|
325
|
-
|
|
326
|
-
}), t.length !==
|
|
331
|
+
}, oe = (t, e) => {
|
|
332
|
+
const r = /* @__PURE__ */ new Map(), s = /* @__PURE__ */ new Map();
|
|
333
|
+
if (e.allLayers.forEach((n) => {
|
|
334
|
+
n instanceof U && s.set(n.id, n);
|
|
335
|
+
}), t.length !== s.size)
|
|
327
336
|
throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");
|
|
328
|
-
for (const
|
|
329
|
-
const
|
|
330
|
-
if (!
|
|
337
|
+
for (const n of t) {
|
|
338
|
+
const a = s.get(n.id);
|
|
339
|
+
if (!a)
|
|
331
340
|
throw new Error(
|
|
332
|
-
`Layer with ID ${
|
|
341
|
+
`Layer with ID ${n.id} not found in the original map during registry restoration. Regenerate embeddings.`
|
|
333
342
|
);
|
|
334
|
-
if (
|
|
343
|
+
if (n.fields.length !== a.fields.length)
|
|
335
344
|
throw new Error(
|
|
336
|
-
`Field count mismatch for layer ID ${
|
|
345
|
+
`Field count mismatch for layer ID ${n.id} during registry restoration. Regenerate embeddings.`
|
|
337
346
|
);
|
|
338
|
-
const
|
|
339
|
-
name:
|
|
340
|
-
title:
|
|
341
|
-
description:
|
|
347
|
+
const i = {
|
|
348
|
+
name: n.name,
|
|
349
|
+
title: n.title,
|
|
350
|
+
description: n.description
|
|
342
351
|
}, c = /* @__PURE__ */ new Map();
|
|
343
|
-
for (const d of
|
|
344
|
-
const o =
|
|
352
|
+
for (const d of n.fields) {
|
|
353
|
+
const o = a.fieldsIndex.get(d.name);
|
|
345
354
|
if (!o)
|
|
346
355
|
throw new Error(
|
|
347
|
-
`Field with name ${d.name} not found in the original layer ${
|
|
356
|
+
`Field with name ${d.name} not found in the original layer ${n.id} during registry restoration. Regenerate embeddings.`
|
|
348
357
|
);
|
|
349
358
|
c.set(d.name, {
|
|
350
359
|
name: d.name,
|
|
351
|
-
alias:
|
|
360
|
+
alias: a.getFieldAlias(d.name) ?? d.alias,
|
|
352
361
|
description: d.description,
|
|
353
362
|
type: o.type || "unknown",
|
|
354
363
|
valueType: o.valueType || "unknown",
|
|
355
|
-
domain:
|
|
364
|
+
domain: a.getFieldDomain(d.name) ?? void 0
|
|
356
365
|
});
|
|
357
366
|
}
|
|
358
|
-
|
|
359
|
-
layerItem:
|
|
367
|
+
r.set(n.id, {
|
|
368
|
+
layerItem: i,
|
|
360
369
|
fieldRegistry: c
|
|
361
370
|
});
|
|
362
371
|
}
|
|
363
|
-
return
|
|
364
|
-
},
|
|
372
|
+
return r;
|
|
373
|
+
}, ce = async (t) => {
|
|
365
374
|
try {
|
|
366
|
-
return (await
|
|
375
|
+
return (await O(t, {
|
|
367
376
|
responseType: "json"
|
|
368
377
|
})).data;
|
|
369
378
|
} catch (e) {
|
|
370
379
|
throw new Error(`Failed to fetch data from ${t}: ${String(e)}`);
|
|
371
380
|
}
|
|
372
|
-
},
|
|
381
|
+
}, de = async (t) => {
|
|
373
382
|
const e = t.map;
|
|
374
383
|
if (!e?.portalItem)
|
|
375
384
|
throw new Error("WebMap portal item is missing.");
|
|
376
|
-
const { resources:
|
|
377
|
-
if (!
|
|
385
|
+
const { resources: r } = await e.portalItem.fetchResources(), s = r.find((i) => i.resource.path === "embeddings-v01.json");
|
|
386
|
+
if (!s?.resource.url)
|
|
378
387
|
throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");
|
|
379
|
-
const
|
|
380
|
-
return
|
|
388
|
+
const n = await ce(s.resource.url);
|
|
389
|
+
return ie(n);
|
|
381
390
|
};
|
|
382
|
-
class
|
|
391
|
+
class x {
|
|
383
392
|
constructor() {
|
|
384
|
-
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.
|
|
393
|
+
this.orchestratorReady = !1, this.chatHistory = [], this.priorSteps = [], this.sharedState = {}, this.agentRegistry = new Z(), this.activeRunId = "", this.cancelledRunIds = /* @__PURE__ */ new Set(), this.streamEpoch = 0;
|
|
385
394
|
}
|
|
386
395
|
/**
|
|
387
396
|
* Creates and returns an AI-ready Orchestrator instance.
|
|
@@ -389,21 +398,21 @@ class v {
|
|
|
389
398
|
* @returns Ready Orchestrator.
|
|
390
399
|
*/
|
|
391
400
|
static async init(e) {
|
|
392
|
-
const
|
|
401
|
+
const r = new x();
|
|
393
402
|
try {
|
|
394
403
|
if (e.view?.map) {
|
|
395
404
|
await P.whenOnce(() => e.view.ready);
|
|
396
|
-
const
|
|
397
|
-
|
|
405
|
+
const s = await de(e.view), n = oe(
|
|
406
|
+
s.layers,
|
|
398
407
|
e.view.map
|
|
399
408
|
);
|
|
400
|
-
|
|
409
|
+
r.layersAndFieldsRegistry = n, r.embeddingsWorker = await T(s);
|
|
401
410
|
}
|
|
402
|
-
return e.agents?.forEach((
|
|
403
|
-
|
|
404
|
-
}),
|
|
405
|
-
} catch (
|
|
406
|
-
throw console.error("Orchestrator initialization failed:",
|
|
411
|
+
return e.agents?.forEach((s) => {
|
|
412
|
+
r.agentRegistry.register(s);
|
|
413
|
+
}), r.orchestratorReady = !0, r;
|
|
414
|
+
} catch (s) {
|
|
415
|
+
throw console.error("Orchestrator initialization failed:", s), s;
|
|
407
416
|
}
|
|
408
417
|
}
|
|
409
418
|
/**
|
|
@@ -421,24 +430,26 @@ class v {
|
|
|
421
430
|
throw new Error("Orchestrator has no registered agents.");
|
|
422
431
|
if (++this.streamEpoch, !e.trim())
|
|
423
432
|
return;
|
|
424
|
-
|
|
425
|
-
|
|
433
|
+
const r = crypto.randomUUID();
|
|
434
|
+
this.activeRunId = r, this.activeAbortController = new AbortController(), this.graph || (this.graph = Y().compile({ checkpointer: new j() }));
|
|
435
|
+
const s = this.embeddingsWorker ? ne({ worker: this.embeddingsWorker }) : void 0, n = this.embeddingsWorker ? ae({ worker: this.embeddingsWorker }) : void 0, a = /* @__PURE__ */ new Map(), c = {
|
|
426
436
|
version: "v2",
|
|
427
437
|
streamMode: "custom",
|
|
428
438
|
configurable: {
|
|
429
439
|
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
430
|
-
thread_id:
|
|
440
|
+
thread_id: r,
|
|
441
|
+
abortSignal: this.activeAbortController.signal,
|
|
431
442
|
hitlResponse: null,
|
|
432
443
|
services: {
|
|
433
444
|
layerSearch: s,
|
|
434
445
|
fieldSearch: n,
|
|
435
446
|
layersAndFieldsRegistry: this.layersAndFieldsRegistry,
|
|
436
447
|
agentRegistry: this.agentRegistry,
|
|
437
|
-
embeddingCache:
|
|
448
|
+
embeddingCache: a
|
|
438
449
|
}
|
|
439
450
|
},
|
|
440
451
|
subgraphs: !0
|
|
441
|
-
},
|
|
452
|
+
}, d = this.graph?.streamEvents(
|
|
442
453
|
{
|
|
443
454
|
agentExecutionContext: {
|
|
444
455
|
userRequest: e,
|
|
@@ -447,36 +458,54 @@ class v {
|
|
|
447
458
|
sharedState: this.sharedState
|
|
448
459
|
}
|
|
449
460
|
},
|
|
450
|
-
|
|
451
|
-
),
|
|
452
|
-
|
|
453
|
-
|
|
461
|
+
c
|
|
462
|
+
), o = ++this.streamEpoch;
|
|
463
|
+
if (yield* this.pipeStream(d, o, r), this.isRunCancelled(r)) {
|
|
464
|
+
yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
for (; ; ) {
|
|
468
|
+
if (this.isRunCancelled(r)) {
|
|
469
|
+
yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
472
|
+
const m = (await this.graph.getState(c, { subgraphs: !0 })).tasks.find((h) => h.interrupts.length > 0)?.interrupts[0]?.value;
|
|
454
473
|
if (!m)
|
|
455
474
|
break;
|
|
456
|
-
this.currentInterrupt = m, this.interruptHandler = new
|
|
475
|
+
this.currentInterrupt = m, this.interruptHandler = new ee(this.graph, c), yield { runId: r, timestamp: Date.now(), type: "interrupt", interrupt: m };
|
|
457
476
|
try {
|
|
458
|
-
const h = await this.interruptHandler.waitForUser(),
|
|
459
|
-
yield* this.pipeStream(h,
|
|
477
|
+
const h = await this.interruptHandler.waitForUser(), S = ++this.streamEpoch;
|
|
478
|
+
yield* this.pipeStream(h, S, r);
|
|
460
479
|
} catch (h) {
|
|
480
|
+
if (this.isRunCancelled(r)) {
|
|
481
|
+
yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
461
484
|
if (h) {
|
|
462
485
|
yield {
|
|
463
|
-
runId:
|
|
486
|
+
runId: r,
|
|
464
487
|
timestamp: Date.now(),
|
|
465
488
|
type: "error",
|
|
466
489
|
error: { message: h?.message }
|
|
467
490
|
};
|
|
468
491
|
return;
|
|
469
492
|
}
|
|
470
|
-
yield { runId: this.threadId, timestamp: Date.now(), type: "cancelled" };
|
|
471
|
-
return;
|
|
472
493
|
}
|
|
473
494
|
}
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
495
|
+
if (this.isRunCancelled(r)) {
|
|
496
|
+
yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
|
|
497
|
+
return;
|
|
498
|
+
}
|
|
499
|
+
const u = (await this.graph.getState(c, { subgraphs: !0 })).values;
|
|
500
|
+
if (this.isRunCancelled(r)) {
|
|
501
|
+
yield { runId: r, timestamp: Date.now(), type: "cancelled", reason: "user" };
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
this.chatHistory = u.agentExecutionContext.messages.length ? u.agentExecutionContext.messages : this.chatHistory, this.priorSteps = u.agentExecutionContext.priorSteps?.slice(-5) ?? [], this.sharedState = u.agentExecutionContext.sharedState ?? {}, yield {
|
|
505
|
+
runId: r,
|
|
477
506
|
timestamp: Date.now(),
|
|
478
507
|
type: "completed",
|
|
479
|
-
result: { content:
|
|
508
|
+
result: { content: u.finalOutputMessage }
|
|
480
509
|
};
|
|
481
510
|
}
|
|
482
511
|
/**
|
|
@@ -500,20 +529,31 @@ class v {
|
|
|
500
529
|
cancelInterrupt() {
|
|
501
530
|
this.interruptHandler && this.interruptHandler.cancel();
|
|
502
531
|
}
|
|
503
|
-
|
|
532
|
+
/**
|
|
533
|
+
* Cancels the active run.
|
|
534
|
+
*
|
|
535
|
+
* - Aborts in-flight work for consumers that honor AbortSignal.
|
|
536
|
+
* - Invalidates active stream iterators via epoch bump.
|
|
537
|
+
* - Unblocks any pending HITL wait.
|
|
538
|
+
*/
|
|
539
|
+
cancel() {
|
|
540
|
+
this.activeRunId && (this.cancelledRunIds.add(this.activeRunId), this.activeAbortController?.abort(), ++this.streamEpoch, this.interruptHandler?.cancel());
|
|
541
|
+
}
|
|
542
|
+
async *pipeStream(e, r, s) {
|
|
504
543
|
for await (const n of e) {
|
|
505
|
-
if (s !== this.streamEpoch)
|
|
506
|
-
console.log("Stale stream detected, aborting.");
|
|
544
|
+
if (this.isRunCancelled(s) || r !== this.streamEpoch)
|
|
507
545
|
break;
|
|
508
|
-
}
|
|
509
|
-
|
|
510
|
-
runId: this.threadId,
|
|
546
|
+
n.event === "on_custom_event" && n.name === "trace_message" ? yield { runId: s, timestamp: Date.now(), type: "trace", data: n.data } : n.name === "graph_ux_suggestion" && (yield {
|
|
547
|
+
runId: s,
|
|
511
548
|
timestamp: Date.now(),
|
|
512
549
|
type: "ux-suggestion",
|
|
513
550
|
suggestion: n.data
|
|
514
551
|
});
|
|
515
552
|
}
|
|
516
553
|
}
|
|
554
|
+
isRunCancelled(e) {
|
|
555
|
+
return this.cancelledRunIds.has(e);
|
|
556
|
+
}
|
|
517
557
|
/**
|
|
518
558
|
* Disposes this instance by terminating the embeddings worker
|
|
519
559
|
* and cleaning up all related resources.
|
|
@@ -523,6 +563,6 @@ class v {
|
|
|
523
563
|
}
|
|
524
564
|
}
|
|
525
565
|
export {
|
|
526
|
-
|
|
527
|
-
|
|
566
|
+
x as O,
|
|
567
|
+
te as g
|
|
528
568
|
};
|