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