@arcgis/ai-components 5.1.0-next.129 → 5.1.0-next.130
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/{PW4XPFSA.js → 72HM6DTZ.js} +2 -2
- package/dist/cdn/AZTWZFVA.js +16 -0
- package/dist/cdn/{EX6NWXUF.js → FKSLZTUY.js} +2 -2
- package/dist/cdn/{E4TOTVRI.js → RBMBKUY6.js} +2 -2
- package/dist/cdn/{7UAGCI6W.js → RJ6XMESZ.js} +35 -36
- package/dist/cdn/{EC62ZHZL.js → VWMJ7HIK.js} +9 -7
- package/dist/cdn/{MEM7FGVU.js → Y2L6M2RG.js} +10 -10
- package/dist/cdn/index.js +1 -1
- package/dist/chunks/adapter.js +479 -484
- package/dist/chunks/arcgisKnowledgeGraph.js +1 -1
- package/dist/chunks/dataExplorationGraph.js +101 -94
- package/dist/chunks/helpGraph.js +4 -4
- package/dist/chunks/layerStylingGraph.js +10 -10
- package/dist/chunks/navigationGraph.js +27 -27
- package/dist/chunks/summarize_query_response_prompt.js +9 -7
- package/dist/docs/api.json +1 -1
- package/dist/docs/docs.json +1 -1
- package/dist/docs/web-types.json +1 -1
- package/package.json +4 -4
- package/dist/cdn/32S235WW.js +0 -16
|
@@ -1,174 +1,181 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import { StateGraph as
|
|
3
|
-
import { g as T, O as R, P as C, t as N, Q as
|
|
2
|
+
import { StateGraph as I, START as k, END as v } from "@langchain/langgraph/web";
|
|
3
|
+
import { g as T, O as R, P as C, t as N, Q as V, f as h, R as D, r as z, S as b, T as P } from "./adapter.js";
|
|
4
4
|
import "@arcgis/core/identity/IdentityManager.js";
|
|
5
5
|
import "@arcgis/core/portal/Portal.js";
|
|
6
|
-
import { s as
|
|
6
|
+
import { s as n, j as _, h as Q } from "./generateLayerDescriptions.js";
|
|
7
7
|
import { AIMessage as j } from "@langchain/core/messages";
|
|
8
8
|
import "@langchain/openai";
|
|
9
9
|
import "@arcgis/core/core/reactiveUtils.js";
|
|
10
10
|
import "@arcgis/core/layers/FeatureLayer.js";
|
|
11
11
|
import "@arcgis/core/request.js";
|
|
12
12
|
import "@langchain/core/prompts";
|
|
13
|
-
import { h as
|
|
13
|
+
import { h as $ } from "./toolCallResponse.js";
|
|
14
14
|
import { ToolNode as O } from "@langchain/langgraph/prebuilt";
|
|
15
15
|
import G from "@arcgis/core/smartMapping/statistics/summaryStatistics.js";
|
|
16
16
|
import U from "@arcgis/core/smartMapping/statistics/uniqueValues.js";
|
|
17
|
-
const W = async (t, e) => (await
|
|
18
|
-
await
|
|
17
|
+
const W = async (t, e) => (await n({ text: "Exiting Data Exploration agent" }, e), t), B = async (t, e) => {
|
|
18
|
+
await n({ text: "Requesting LLM for layer filter results" }, e);
|
|
19
19
|
const d = await T("data_explore_filter_prompt");
|
|
20
20
|
if (!e?.configurable)
|
|
21
21
|
throw new Error("config.configurable is required for layer filter tools");
|
|
22
|
-
const { userTimezone:
|
|
22
|
+
const { userTimezone: l, userTimezoneOffset: s } = R(), o = {
|
|
23
23
|
layerFieldInfo: t.layerFieldInfo,
|
|
24
|
-
userTimezone:
|
|
25
|
-
userTimezoneOffset:
|
|
24
|
+
userTimezone: l,
|
|
25
|
+
userTimezoneOffset: s,
|
|
26
26
|
queryResponse: t.queryResponse,
|
|
27
27
|
assignedTask: t.agentExecutionContext.assignedTask,
|
|
28
28
|
userRequest: t.agentExecutionContext.userRequest,
|
|
29
29
|
priorSteps: t.agentExecutionContext.priorSteps
|
|
30
|
-
},
|
|
30
|
+
}, r = await _({
|
|
31
31
|
promptText: d,
|
|
32
32
|
modelTier: "advanced",
|
|
33
33
|
messages: t.dataExplorationMessages,
|
|
34
34
|
inputVariables: o,
|
|
35
35
|
tools: C
|
|
36
|
-
}), i = [...t.dataExplorationMessages,
|
|
37
|
-
if (!((
|
|
38
|
-
return await
|
|
36
|
+
}), i = [...t.dataExplorationMessages, r];
|
|
37
|
+
if (!((r.tool_calls?.length ?? 0) > 0))
|
|
38
|
+
return await n({ text: "LLM determined no filter changes needed" }, e), {
|
|
39
39
|
...t,
|
|
40
40
|
dataExplorationMessages: i
|
|
41
41
|
// Don't overwrite outputMessage if query already set it
|
|
42
42
|
};
|
|
43
|
-
const m =
|
|
44
|
-
return await
|
|
43
|
+
const m = i, p = r.content.toString();
|
|
44
|
+
return await $(r, e), { ...t, dataExplorationMessages: m, outputMessage: p };
|
|
45
45
|
}, H = async (t, e) => {
|
|
46
|
-
await
|
|
46
|
+
await n({ text: "Requesting LLM for layer query results" }, e);
|
|
47
47
|
const d = await T("data_explore_query_prompt");
|
|
48
48
|
if (!e?.configurable)
|
|
49
49
|
throw new Error("config.configurable is required for layer query tools");
|
|
50
|
-
const { userTimezone:
|
|
51
|
-
let
|
|
50
|
+
const { userTimezone: l, userTimezoneOffset: s } = R(), r = t.agentExecutionContext.sharedState.lastNavigatedFeatures, i = r && typeof r == "object" && "value" in r ? r.value : r;
|
|
51
|
+
let c = "none";
|
|
52
52
|
if (i != null)
|
|
53
53
|
try {
|
|
54
|
-
|
|
54
|
+
c = JSON.stringify(i);
|
|
55
55
|
} catch {
|
|
56
|
-
|
|
56
|
+
c = "none";
|
|
57
57
|
}
|
|
58
58
|
const m = {
|
|
59
59
|
layerFieldInfo: t.layerFieldInfo,
|
|
60
|
-
userTimezone:
|
|
61
|
-
userTimezoneOffset:
|
|
60
|
+
userTimezone: l,
|
|
61
|
+
userTimezoneOffset: s,
|
|
62
62
|
assignedTask: t.agentExecutionContext.assignedTask,
|
|
63
63
|
userRequest: t.agentExecutionContext.userRequest,
|
|
64
64
|
priorSteps: t.agentExecutionContext.priorSteps,
|
|
65
|
-
lastNavigatedFeatures:
|
|
66
|
-
}, p = await
|
|
65
|
+
lastNavigatedFeatures: c
|
|
66
|
+
}, p = await _({
|
|
67
67
|
promptText: d,
|
|
68
68
|
modelTier: "advanced",
|
|
69
69
|
messages: t.dataExplorationMessages,
|
|
70
70
|
inputVariables: m,
|
|
71
|
-
tools:
|
|
72
|
-
}),
|
|
73
|
-
return await
|
|
71
|
+
tools: V
|
|
72
|
+
}), f = (p.tool_calls?.length ?? 0) > 0, g = p.content.toString();
|
|
73
|
+
return await $(p, e), {
|
|
74
74
|
...t,
|
|
75
75
|
dataExplorationMessages: [...t.dataExplorationMessages, p],
|
|
76
|
-
|
|
76
|
+
// Only emit output here when no tools are being called.
|
|
77
|
+
// For tool-calling flows, downstream summarizer nodes provide the final user-facing message.
|
|
78
|
+
...f ? {} : { outputMessage: g },
|
|
77
79
|
status: "success",
|
|
78
|
-
summary:
|
|
80
|
+
summary: g && !f ? N(g) : "Query planning completed."
|
|
79
81
|
};
|
|
80
82
|
}, J = async (t, e) => {
|
|
81
83
|
try {
|
|
82
|
-
await
|
|
83
|
-
const d = await T("summarize_query_response_prompt"),
|
|
84
|
+
await n({ text: "Requesting LLM for summary on query results" }, e);
|
|
85
|
+
const d = await T("summarize_query_response_prompt"), l = {
|
|
84
86
|
queryResponse: t.queryResponse,
|
|
85
87
|
assignedTask: t.agentExecutionContext.assignedTask,
|
|
86
88
|
userRequest: t.agentExecutionContext.userRequest,
|
|
87
89
|
priorSteps: t.agentExecutionContext.priorSteps
|
|
88
|
-
},
|
|
90
|
+
}, s = await Q({
|
|
89
91
|
promptText: d,
|
|
90
92
|
modelTier: "fast",
|
|
91
93
|
messages: t.dataExplorationMessages,
|
|
92
|
-
inputVariables:
|
|
93
|
-
}), o = typeof
|
|
94
|
-
await
|
|
94
|
+
inputVariables: l
|
|
95
|
+
}), o = typeof s == "string" ? s : s.content, r = new j(o);
|
|
96
|
+
await n({ text: `Received response from LLM: ${o}` }, e);
|
|
95
97
|
const i = o;
|
|
96
98
|
return {
|
|
97
99
|
...t,
|
|
98
100
|
outputMessage: i,
|
|
99
101
|
status: "success",
|
|
100
102
|
summary: i ? N(i) : "Summary generated.",
|
|
101
|
-
dataExplorationMessages: [...t.dataExplorationMessages,
|
|
103
|
+
dataExplorationMessages: [...t.dataExplorationMessages, r]
|
|
102
104
|
};
|
|
103
105
|
} catch (a) {
|
|
104
|
-
throw await
|
|
106
|
+
throw await n({ text: "Error during filter LLM request" }, e), new Error(`Error during filter LLM request: ${a instanceof Error ? a.message : String(a)}`);
|
|
105
107
|
}
|
|
106
108
|
};
|
|
107
109
|
async function K(t, e) {
|
|
108
|
-
|
|
110
|
+
if ((t.queryResponse ?? []).some((s) => {
|
|
111
|
+
const o = s.details;
|
|
112
|
+
return typeof o == "object" && o !== null && "error" in o;
|
|
113
|
+
}))
|
|
114
|
+
return await n({ text: "Skipping layer filter tool because query response contains an error." }, e), { ...t };
|
|
115
|
+
const l = await new O(C, { handleToolErrors: !1 }).invoke(
|
|
109
116
|
{
|
|
110
117
|
messages: t.dataExplorationMessages
|
|
111
118
|
},
|
|
112
119
|
e
|
|
113
120
|
);
|
|
114
|
-
return await
|
|
115
|
-
{ text: `Finished executing layer filter tool: ${
|
|
121
|
+
return await n(
|
|
122
|
+
{ text: `Finished executing layer filter tool: ${l.messages.map((s) => s.content).join(", ")}` },
|
|
116
123
|
e
|
|
117
124
|
), { ...t };
|
|
118
125
|
}
|
|
119
126
|
const X = 10, Y = ["string", "small-integer", "integer"], Z = async (t, e, { includeSummaryStatistics: a = !0, includeUniqueValues: d = !0 } = {}) => {
|
|
120
|
-
let
|
|
127
|
+
let l = null, s = null;
|
|
121
128
|
try {
|
|
122
129
|
if (e.type !== "geometry" && e.type !== "oid" && e.type !== "global-id") {
|
|
123
|
-
a && (
|
|
130
|
+
a && (l = await G({ layer: t, field: e.name }));
|
|
124
131
|
const o = e.domain?.type === "coded-value" ? e.domain : null;
|
|
125
|
-
d && (Y.includes(e.type) || o) && (
|
|
126
|
-
...
|
|
127
|
-
value: o.getName(
|
|
132
|
+
d && (Y.includes(e.type) || o) && (s = (await U({ layer: t, field: e.name })).uniqueValueInfos.sort((r, i) => i.count - r.count).slice(0, X), o && (s = s.map((r) => ({
|
|
133
|
+
...r,
|
|
134
|
+
value: o.getName(r.value) ?? r.value
|
|
128
135
|
}))));
|
|
129
136
|
}
|
|
130
137
|
} catch (o) {
|
|
131
138
|
console.error(`Error fetching statistics for field ${e.name}:`, o);
|
|
132
139
|
}
|
|
133
140
|
return {
|
|
134
|
-
summaryStatistics:
|
|
135
|
-
uniqueValues:
|
|
141
|
+
summaryStatistics: l,
|
|
142
|
+
uniqueValues: s
|
|
136
143
|
};
|
|
137
144
|
};
|
|
138
145
|
function ee(t, e) {
|
|
139
146
|
return ["string", "small-integer", "integer"].includes(t) || e === "coded-value";
|
|
140
147
|
}
|
|
141
148
|
async function te(t, e, a, d = !0) {
|
|
142
|
-
const
|
|
143
|
-
for (const
|
|
144
|
-
let i = function(
|
|
145
|
-
const u = e.get(
|
|
149
|
+
const l = [], s = [], o = [];
|
|
150
|
+
for (const r of t) {
|
|
151
|
+
let i = function(y) {
|
|
152
|
+
const u = e.get(y)?.layerItem;
|
|
146
153
|
return u ? [
|
|
147
154
|
u.name && `Name: ${u.name}`,
|
|
148
155
|
u.title && `Title: ${u.title}`,
|
|
149
156
|
u.description && `Description: ${u.description}`
|
|
150
|
-
].filter(Boolean).join(" | ") :
|
|
157
|
+
].filter(Boolean).join(" | ") : y;
|
|
151
158
|
};
|
|
152
|
-
const { layerId:
|
|
153
|
-
if (!
|
|
159
|
+
const { layerId: c, results: m } = r, p = a.map?.allLayers.find((y) => y.id === c), f = e.get(c)?.fieldRegistry;
|
|
160
|
+
if (!f)
|
|
154
161
|
continue;
|
|
155
|
-
let
|
|
156
|
-
|
|
157
|
-
layerId:
|
|
158
|
-
layerSummary: i(
|
|
162
|
+
let g = l.find((y) => y.layerId === c);
|
|
163
|
+
g || (g = {
|
|
164
|
+
layerId: c,
|
|
165
|
+
layerSummary: i(c),
|
|
159
166
|
fieldInfos: []
|
|
160
|
-
},
|
|
161
|
-
for (const
|
|
162
|
-
const u =
|
|
167
|
+
}, l.push(g));
|
|
168
|
+
for (const y of m) {
|
|
169
|
+
const u = f.get(y.name);
|
|
163
170
|
if (!u)
|
|
164
171
|
continue;
|
|
165
172
|
const x = u.statistics, E = d && !x?.summaryStatistics, w = ee(u.type, u.domain?.type) && !x?.uniqueValues, q = E || w;
|
|
166
173
|
if (o.push({
|
|
167
|
-
layerId:
|
|
174
|
+
layerId: c,
|
|
168
175
|
fieldName: u.name,
|
|
169
176
|
didFetchStatistics: q
|
|
170
177
|
}), q) {
|
|
171
|
-
const
|
|
178
|
+
const A = Z(p, u, {
|
|
172
179
|
includeSummaryStatistics: E,
|
|
173
180
|
includeUniqueValues: w
|
|
174
181
|
}).then((F) => {
|
|
@@ -176,16 +183,16 @@ async function te(t, e, a, d = !0) {
|
|
|
176
183
|
summaryStatistics: x?.summaryStatistics ?? null,
|
|
177
184
|
uniqueValues: x?.uniqueValues ?? null
|
|
178
185
|
};
|
|
179
|
-
E && (S.summaryStatistics = F.summaryStatistics), w && (S.uniqueValues = F.uniqueValues),
|
|
186
|
+
E && (S.summaryStatistics = F.summaryStatistics), w && (S.uniqueValues = F.uniqueValues), f.set(u.name, { ...u, statistics: S }), u.statistics = S;
|
|
180
187
|
});
|
|
181
|
-
|
|
188
|
+
s.push(A);
|
|
182
189
|
}
|
|
183
|
-
|
|
190
|
+
g.fieldInfos.push(u);
|
|
184
191
|
}
|
|
185
192
|
}
|
|
186
|
-
return await Promise.all(
|
|
187
|
-
layerFieldInfo:
|
|
188
|
-
didFetchStatistics:
|
|
193
|
+
return await Promise.all(s), {
|
|
194
|
+
layerFieldInfo: l,
|
|
195
|
+
didFetchStatistics: s.length > 0,
|
|
189
196
|
fieldStatisticsFetchStatus: o
|
|
190
197
|
};
|
|
191
198
|
}
|
|
@@ -195,73 +202,73 @@ function ae(t, e) {
|
|
|
195
202
|
}
|
|
196
203
|
const se = async (t, e) => {
|
|
197
204
|
try {
|
|
198
|
-
await
|
|
199
|
-
const a = h(e, "layersAndFieldsRegistry"), { mapView: d } = D(e), { assignedTask:
|
|
205
|
+
await n({ text: "Preparing field information for vector search results" }, e);
|
|
206
|
+
const a = h(e, "layersAndFieldsRegistry"), { mapView: d } = D(e), { assignedTask: l, userRequest: s } = t.agentExecutionContext, o = ae(l, s), { layerFieldInfo: r, didFetchStatistics: i, fieldStatisticsFetchStatus: c } = await te(
|
|
200
207
|
t.vectorSearchFieldResults,
|
|
201
208
|
a,
|
|
202
209
|
d,
|
|
203
210
|
o
|
|
204
211
|
);
|
|
205
|
-
i ? await
|
|
206
|
-
for (const m of
|
|
207
|
-
await
|
|
212
|
+
i ? await n({ text: "Statistics fetched" }, e) : await n({ text: "Statistics skipped" }, e);
|
|
213
|
+
for (const m of c)
|
|
214
|
+
await n(
|
|
208
215
|
{
|
|
209
216
|
text: ` - ${m.fieldName} - stats ${m.didFetchStatistics ? "fetched" : "skipped"}`
|
|
210
217
|
},
|
|
211
218
|
e
|
|
212
219
|
);
|
|
213
|
-
return await
|
|
220
|
+
return await n({ text: "Field information prepared" }, e), { ...t, layerFieldInfo: r };
|
|
214
221
|
} catch (a) {
|
|
215
|
-
throw await
|
|
222
|
+
throw await n({ text: "Error during fetching statistics" }, e), new Error(`Error during fetching statistics: ${a instanceof Error ? a.message : String(a)}`);
|
|
216
223
|
}
|
|
217
224
|
}, L = 0.7, re = 10, oe = async (t, e) => {
|
|
218
225
|
try {
|
|
219
|
-
await
|
|
220
|
-
const a = h(e, "fieldSearch"), d = h(e, "layersAndFieldsRegistry"),
|
|
226
|
+
await n({ text: "Similarity search to find fields" }, e);
|
|
227
|
+
const a = h(e, "fieldSearch"), d = h(e, "layersAndFieldsRegistry"), l = h(e, "embeddingCache"), s = await a.searchFields({
|
|
221
228
|
text: t.agentExecutionContext.assignedTask,
|
|
222
229
|
layerIds: t.vectorSearchLayerIds,
|
|
223
230
|
minScore: L,
|
|
224
231
|
topResults: re,
|
|
225
|
-
embeddingCache:
|
|
226
|
-
}), o =
|
|
227
|
-
const m =
|
|
232
|
+
embeddingCache: l
|
|
233
|
+
}), o = s.map(({ layerId: i, results: c }) => {
|
|
234
|
+
const m = c.map((p) => ` - ${p.name} (${p.score.toFixed(2)})`).join(`
|
|
228
235
|
`);
|
|
229
236
|
return `${d.get(i)?.layerItem.name ?? i}:
|
|
230
237
|
${m}`;
|
|
231
238
|
}).join(`
|
|
232
239
|
`);
|
|
233
|
-
let
|
|
234
|
-
return
|
|
235
|
-
${o}` :
|
|
240
|
+
let r;
|
|
241
|
+
return s.length > 0 ? r = `Vector search completed. Matching layers and fields with scores:
|
|
242
|
+
${o}` : r = `No vector search results found for score over ${L}.`, await n({ text: r }, e), {
|
|
236
243
|
...t,
|
|
237
|
-
vectorSearchFieldResults:
|
|
244
|
+
vectorSearchFieldResults: s
|
|
238
245
|
};
|
|
239
246
|
} catch (a) {
|
|
240
|
-
throw await
|
|
247
|
+
throw await n(
|
|
241
248
|
{ text: `Error during vector search: ${a instanceof Error ? a.message : String(a)}` },
|
|
242
249
|
e
|
|
243
250
|
), new Error(`Vector search failed: ${a instanceof Error ? a.message : String(a)}`);
|
|
244
251
|
}
|
|
245
252
|
}, ie = 0.7, ne = async (t, e) => {
|
|
246
253
|
try {
|
|
247
|
-
await
|
|
254
|
+
await n(
|
|
248
255
|
{ text: `Similarity search to find layers: ${t.agentExecutionContext.assignedTask}` },
|
|
249
256
|
e
|
|
250
257
|
);
|
|
251
|
-
const a = h(e, "layerSearch"), d = h(e, "layersAndFieldsRegistry"),
|
|
258
|
+
const a = h(e, "layerSearch"), d = h(e, "layersAndFieldsRegistry"), l = h(e, "embeddingCache"), s = await a.searchLayers({
|
|
252
259
|
text: t.agentExecutionContext.assignedTask,
|
|
253
260
|
minScore: ie,
|
|
254
|
-
embeddingCache:
|
|
255
|
-
}), o =
|
|
261
|
+
embeddingCache: l
|
|
262
|
+
}), o = s.map((c) => c.id), r = s.map(({ id: c, score: m }) => `${d.get(c)?.layerItem.name ?? c} (${m.toFixed(2)})`).join(`
|
|
256
263
|
`);
|
|
257
264
|
let i;
|
|
258
265
|
return o.length > 0 ? i = `Vector search completed. Matching layers with scores:
|
|
259
|
-
${
|
|
266
|
+
${r}` : i = "Vector search completed. No matching layers found.", await n({ text: i }, e), {
|
|
260
267
|
...t,
|
|
261
268
|
vectorSearchLayerIds: o
|
|
262
269
|
};
|
|
263
270
|
} catch (a) {
|
|
264
|
-
throw await
|
|
271
|
+
throw await n(
|
|
265
272
|
{ text: `Error during vector search: ${a instanceof Error ? a.message : String(a)}` },
|
|
266
273
|
e
|
|
267
274
|
), new Error(`Vector search failed: ${a instanceof Error ? a.message : String(a)}`);
|
|
@@ -269,7 +276,7 @@ ${s}` : i = "Vector search completed. No matching layers found.", await c({ text
|
|
|
269
276
|
}, le = (t, e) => z(["layerSearch", "fieldSearch", "layersAndFieldsRegistry"], "Data Exploration Agent")(
|
|
270
277
|
t,
|
|
271
278
|
e
|
|
272
|
-
), ce = () => new b
|
|
279
|
+
), ce = () => new I(b).addNode("requireDataExplorationServices", le).addNode("vectorSearchLayers", ne).addNode("vectorSearchFields", oe).addNode("fieldStatistics", se).addNode("queryAgent", H).addNode("queryTools", P).addNode("summarizeQueryResponseLLM", J).addNode("filterAgent", B).addNode("filterTools", K).addNode("earlyExit", W).addEdge(k, "requireDataExplorationServices").addEdge("requireDataExplorationServices", "vectorSearchLayers").addConditionalEdges(
|
|
273
280
|
"vectorSearchLayers",
|
|
274
281
|
(e) => e.vectorSearchLayerIds.length ? "vectorSearchFields" : "earlyExit"
|
|
275
282
|
).addConditionalEdges(
|
|
@@ -291,7 +298,7 @@ ${s}` : i = "Vector search completed. No matching layers found.", await c({ text
|
|
|
291
298
|
name: "Data Exploration Agent",
|
|
292
299
|
description: de,
|
|
293
300
|
createGraph: ce,
|
|
294
|
-
workspace:
|
|
301
|
+
workspace: b
|
|
295
302
|
};
|
|
296
303
|
export {
|
|
297
304
|
Me as D
|
package/dist/chunks/helpGraph.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
2
|
import { StateGraph as d, START as g, END as i } from "@langchain/langgraph/web";
|
|
3
|
-
import { l as h, g as
|
|
3
|
+
import { l as h, g as f, f as p, r as x, t as y, H as u } from "./adapter.js";
|
|
4
4
|
import "@arcgis/core/identity/IdentityManager.js";
|
|
5
5
|
import "@arcgis/core/portal/Portal.js";
|
|
6
6
|
import { j as S, s as c } from "./generateLayerDescriptions.js";
|
|
@@ -31,7 +31,7 @@ ${t}`;
|
|
|
31
31
|
`) : "No agents currently available.";
|
|
32
32
|
};
|
|
33
33
|
async function _(e, t) {
|
|
34
|
-
const r = await
|
|
34
|
+
const r = await f("help_prompt"), s = p(t, "layersAndFieldsRegistry"), l = p(t, "agentRegistry");
|
|
35
35
|
try {
|
|
36
36
|
const a = await S({
|
|
37
37
|
promptText: r,
|
|
@@ -65,9 +65,9 @@ async function _(e, t) {
|
|
|
65
65
|
};
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
const C = (e, t) =>
|
|
68
|
+
const C = (e, t) => x(["agentRegistry"], "Help Agent")(e, t);
|
|
69
69
|
async function H(e, t) {
|
|
70
|
-
const r = new E(m);
|
|
70
|
+
const r = new E(m, { handleToolErrors: !1 });
|
|
71
71
|
try {
|
|
72
72
|
const s = e.helpInternalState.toolCallMessage;
|
|
73
73
|
if (!s)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import { NodeInterrupt as
|
|
2
|
+
import { NodeInterrupt as E, StateGraph as L, START as w, END as h } from "@langchain/langgraph/web";
|
|
3
3
|
import "@arcgis/core/identity/IdentityManager.js";
|
|
4
4
|
import "@arcgis/core/portal/Portal.js";
|
|
5
5
|
import { s as i, j as I } from "./generateLayerDescriptions.js";
|
|
@@ -9,16 +9,16 @@ import "@arcgis/core/core/reactiveUtils.js";
|
|
|
9
9
|
import "@arcgis/core/layers/FeatureLayer.js";
|
|
10
10
|
import "@arcgis/core/request.js";
|
|
11
11
|
import "@langchain/core/prompts";
|
|
12
|
-
import { f as p, z as v, A as
|
|
12
|
+
import { f as p, z as v, A as T, B as R, C as F, D as C, E as A, F as $, I as N, J as b, K as q, L as M, g as _, r as j, M as S } from "./adapter.js";
|
|
13
13
|
import { h as k } from "./toolCallResponse.js";
|
|
14
14
|
import { ToolNode as V } from "@langchain/langgraph/prebuilt";
|
|
15
|
-
const
|
|
15
|
+
const m = 0.7, z = 10, D = async (t, e) => {
|
|
16
16
|
try {
|
|
17
17
|
await i({ text: "Similarity search to find fields" }, e);
|
|
18
18
|
const r = p(e, "fieldSearch"), a = p(e, "layersAndFieldsRegistry"), o = p(e, "embeddingCache"), n = await r.searchFields({
|
|
19
19
|
text: t.agentExecutionContext.assignedTask,
|
|
20
20
|
layerIds: t.vectorSearchLayerIds,
|
|
21
|
-
minScore:
|
|
21
|
+
minScore: m,
|
|
22
22
|
topResults: z,
|
|
23
23
|
embeddingCache: o
|
|
24
24
|
}), c = n.map(({ layerId: d, results: g }) => {
|
|
@@ -30,7 +30,7 @@ ${y}`;
|
|
|
30
30
|
`);
|
|
31
31
|
let l;
|
|
32
32
|
return n.length > 0 ? l = `Vector search completed. Matching layers and fields with scores:
|
|
33
|
-
${c}` : l = `No vector search results found for score over ${
|
|
33
|
+
${c}` : l = `No vector search results found for score over ${m}.`, await i({ text: l }, e), {
|
|
34
34
|
...t,
|
|
35
35
|
vectorSearchFieldResults: n
|
|
36
36
|
};
|
|
@@ -65,8 +65,8 @@ ${c}` : l = "Vector search completed. No matching layers found.", await i({ text
|
|
|
65
65
|
}
|
|
66
66
|
}, f = [
|
|
67
67
|
v,
|
|
68
|
-
R,
|
|
69
68
|
T,
|
|
69
|
+
R,
|
|
70
70
|
F,
|
|
71
71
|
C,
|
|
72
72
|
A,
|
|
@@ -104,7 +104,7 @@ ${c}` : l = "Vector search completed. No matching layers found.", await i({ text
|
|
|
104
104
|
};
|
|
105
105
|
};
|
|
106
106
|
async function B(t, e) {
|
|
107
|
-
const a = await new V(f).invoke(
|
|
107
|
+
const a = await new V(f, { handleToolErrors: !1 }).invoke(
|
|
108
108
|
{
|
|
109
109
|
messages: x(t.agentExecutionContext.messages)
|
|
110
110
|
},
|
|
@@ -160,20 +160,20 @@ const U = async (t, e) => (await i({ text: "Exiting Layer Styling agent" }, e),
|
|
|
160
160
|
message: "Choose a layer to apply the styles.",
|
|
161
161
|
metadata: [...r]
|
|
162
162
|
};
|
|
163
|
-
throw new
|
|
163
|
+
throw new E(n);
|
|
164
164
|
}
|
|
165
165
|
let o = null;
|
|
166
166
|
return Array.isArray(a.payload) && a.payload.length > 0 && (o = a.payload[0]), {
|
|
167
167
|
...t,
|
|
168
168
|
selectedLayerId: o ?? t.vectorSearchLayerIds[0]
|
|
169
169
|
};
|
|
170
|
-
}, O = (t, e) => j(["layerSearch", "fieldSearch", "layersAndFieldsRegistry"], "Layer Styling Agent")(t, e), Q = () => new
|
|
170
|
+
}, O = (t, e) => j(["layerSearch", "fieldSearch", "layersAndFieldsRegistry"], "Layer Styling Agent")(t, e), Q = () => new L(S).addNode("requireLayerStylingServices", O).addNode("vectorSearchLayers", H).addNode("layerSelectionHITL", K).addNode("vectorSearchFields", D).addNode("populateLayerFieldInfo", J).addNode("agent", G).addNode("tools", B).addNode("earlyExit", U).addEdge(w, "requireLayerStylingServices").addEdge("requireLayerStylingServices", "vectorSearchLayers").addConditionalEdges(
|
|
171
171
|
"layerSelectionHITL",
|
|
172
172
|
(e) => e.vectorSearchLayerIds.length ? "vectorSearchFields" : "earlyExit"
|
|
173
173
|
).addConditionalEdges(
|
|
174
174
|
"vectorSearchFields",
|
|
175
175
|
(e) => e.vectorSearchFieldResults.length ? "populateLayerFieldInfo" : "earlyExit"
|
|
176
|
-
).addEdge("populateLayerFieldInfo", "agent").addEdge("agent", "tools").addEdge("tools",
|
|
176
|
+
).addEdge("populateLayerFieldInfo", "agent").addEdge("agent", "tools").addEdge("tools", h).addEdge("earlyExit", h), W = String.raw`- **layerStyling** — User wants to change how features are drawn or styled on the map based on their data, such as applying color, size, transparency, symbols, or charts according to field values.
|
|
177
177
|
_Example: “Color points by sales amount”_
|
|
178
178
|
_Example: “Show population density with a color gradient”_
|
|
179
179
|
_Example: “Create a relationship map between height and depth”_
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
|
|
2
|
-
import { StateGraph as
|
|
2
|
+
import { StateGraph as b, START as $, END as C } from "@langchain/langgraph/web";
|
|
3
3
|
import { k as F, m as R, n as L, o as M, p as A, u as _, v as I, w as q, x as Z, g as T, y as k, t as j, f as u, r as P, N as w } from "./adapter.js";
|
|
4
4
|
import "@arcgis/core/identity/IdentityManager.js";
|
|
5
5
|
import "@arcgis/core/portal/Portal.js";
|
|
@@ -25,14 +25,14 @@ const S = [
|
|
|
25
25
|
Z
|
|
26
26
|
];
|
|
27
27
|
async function O(e, t) {
|
|
28
|
-
const o = await T("navigation_tool_prompt"), { mapView: s } = k(t), i = s.map.bookmarks?.map((p) => p.name).filter(Boolean) ?? [],
|
|
29
|
-
(p,
|
|
28
|
+
const o = await T("navigation_tool_prompt"), { mapView: s } = k(t), i = s.map.bookmarks?.map((p) => p.name).filter(Boolean) ?? [], l = e.vectorSearchLayerResults?.length > 0 ? e.vectorSearchLayerResults.map(
|
|
29
|
+
(p, E) => `${E + 1}. layerId=${p.id} | title=${p.title ?? ""} | name=${p.name ?? ""} | score=${p.score.toFixed(2)}`
|
|
30
30
|
).join(`
|
|
31
|
-
`) : "",
|
|
31
|
+
`) : "", c = e.vectorSearchFieldResults?.length > 0 ? JSON.stringify(e.vectorSearchFieldResults, null, 2) : "", a = e.intent === "goToBookmark" && i.length ? `Available bookmarks:
|
|
32
32
|
${i.map((p) => `- ${p}`).join(`
|
|
33
33
|
`)}` : "", r = (e.intent === "goToLayer" || e.intent === "goToFeatures") && e.vectorSearchLayerResults?.length ? `Candidate layers:
|
|
34
|
-
${
|
|
35
|
-
${
|
|
34
|
+
${l}` : "", d = e.intent === "goToFeatures" && e.vectorSearchFieldResults?.length ? `Candidate fields:
|
|
35
|
+
${c}` : "", y = {
|
|
36
36
|
intent: e.intent,
|
|
37
37
|
bookmarksSection: a,
|
|
38
38
|
layersSection: r,
|
|
@@ -70,7 +70,7 @@ const B = (e) => {
|
|
|
70
70
|
return { text: t };
|
|
71
71
|
};
|
|
72
72
|
async function D(e, t) {
|
|
73
|
-
const o = new G(S);
|
|
73
|
+
const o = new G(S, { handleToolErrors: !1 });
|
|
74
74
|
try {
|
|
75
75
|
const s = e.navigationInternalState.toolCallMessage;
|
|
76
76
|
if (!s)
|
|
@@ -81,19 +81,19 @@ async function D(e, t) {
|
|
|
81
81
|
},
|
|
82
82
|
t
|
|
83
83
|
);
|
|
84
|
-
let i = "",
|
|
85
|
-
for (const
|
|
86
|
-
const a = B(
|
|
84
|
+
let i = "", l;
|
|
85
|
+
for (const c of g) {
|
|
86
|
+
const a = B(c.content);
|
|
87
87
|
a.text && (i += `${a.text}
|
|
88
|
-
`), a.sharedStatePatch && (
|
|
89
|
-
...
|
|
88
|
+
`), a.sharedStatePatch && (l = {
|
|
89
|
+
...l,
|
|
90
90
|
...a.sharedStatePatch
|
|
91
91
|
});
|
|
92
92
|
}
|
|
93
93
|
return await h({ text: `Finished executing navigation tool: ${i}` }, t), {
|
|
94
94
|
...e,
|
|
95
95
|
outputMessage: i,
|
|
96
|
-
sharedStatePatch:
|
|
96
|
+
sharedStatePatch: l,
|
|
97
97
|
status: "success",
|
|
98
98
|
summary: i ? j(i) : "Navigation executed.",
|
|
99
99
|
navigationInternalState: {
|
|
@@ -120,12 +120,12 @@ async function J(e, t) {
|
|
|
120
120
|
name: n.name,
|
|
121
121
|
description: n.description,
|
|
122
122
|
schema: n.schema
|
|
123
|
-
})),
|
|
124
|
-
${
|
|
123
|
+
})), l = s.map.bookmarks?.map((n) => n.name).filter(Boolean) ?? [], c = l.length ? `Available bookmarks:
|
|
124
|
+
${l.map((n) => `- ${n}`).join(`
|
|
125
125
|
`)}` : "", a = {
|
|
126
126
|
tools: g.map(({ name: n, description: m, schema: v }) => `${n}: ${m}, ${JSON.stringify(v)}`).join(`
|
|
127
127
|
`),
|
|
128
|
-
bookmarks:
|
|
128
|
+
bookmarks: c,
|
|
129
129
|
assignedTask: e.agentExecutionContext.assignedTask,
|
|
130
130
|
userRequest: e.agentExecutionContext.userRequest,
|
|
131
131
|
priorSteps: e.agentExecutionContext.priorSteps
|
|
@@ -145,7 +145,7 @@ const H = 0.7, U = async (e, t) => {
|
|
|
145
145
|
{ text: `Similarity search to find layers: ${e.agentExecutionContext.assignedTask}` },
|
|
146
146
|
t
|
|
147
147
|
);
|
|
148
|
-
const o = u(t, "layerSearch"), s = u(t, "layersAndFieldsRegistry"), g = u(t, "embeddingCache"),
|
|
148
|
+
const o = u(t, "layerSearch"), s = u(t, "layersAndFieldsRegistry"), g = u(t, "embeddingCache"), l = (await o.searchLayers({
|
|
149
149
|
text: e.agentExecutionContext.assignedTask,
|
|
150
150
|
minScore: H,
|
|
151
151
|
embeddingCache: g
|
|
@@ -158,12 +158,12 @@ const H = 0.7, U = async (e, t) => {
|
|
|
158
158
|
score: r
|
|
159
159
|
};
|
|
160
160
|
});
|
|
161
|
-
let
|
|
162
|
-
return
|
|
163
|
-
${
|
|
164
|
-
`)}` :
|
|
161
|
+
let c;
|
|
162
|
+
return l.length > 0 ? c = `Vector search completed. Matching layers:
|
|
163
|
+
${l.map((a) => `- layerId=${a.id} | title=${a.title ?? ""} | name=${a.name ?? ""} | score=${a.score.toFixed(2)}`).join(`
|
|
164
|
+
`)}` : c = "Vector search completed. No matching layers found.", await h({ text: c }, t), {
|
|
165
165
|
...e,
|
|
166
|
-
vectorSearchLayerResults:
|
|
166
|
+
vectorSearchLayerResults: l
|
|
167
167
|
};
|
|
168
168
|
} catch (o) {
|
|
169
169
|
throw await h(
|
|
@@ -180,7 +180,7 @@ ${c.map((a) => `- layerId=${a.id} | title=${a.title ?? ""} | name=${a.name ?? ""
|
|
|
180
180
|
const o = u(t, "fieldSearch"), s = u(t, "layersAndFieldsRegistry"), g = u(t, "embeddingCache"), i = e.vectorSearchLayerResults?.map((r) => r.id) ?? [];
|
|
181
181
|
if (i.length === 0)
|
|
182
182
|
return await h({ text: "No candidate layers for field search" }, t), e;
|
|
183
|
-
const
|
|
183
|
+
const c = (await o.searchFields({
|
|
184
184
|
text: e.agentExecutionContext.assignedTask,
|
|
185
185
|
layerIds: i,
|
|
186
186
|
minScore: f,
|
|
@@ -205,15 +205,15 @@ ${c.map((a) => `- layerId=${a.id} | title=${a.title ?? ""} | name=${a.name ?? ""
|
|
|
205
205
|
};
|
|
206
206
|
});
|
|
207
207
|
let a;
|
|
208
|
-
return
|
|
209
|
-
${
|
|
208
|
+
return c.length > 0 ? a = `Vector search completed. Matching layers and fields:
|
|
209
|
+
${c.map(
|
|
210
210
|
(r) => `${r.layerName ?? r.layerId}:
|
|
211
211
|
${r.results.map((d) => ` - ${d.name} (${d.score.toFixed(2)})`).join(`
|
|
212
212
|
`)}`
|
|
213
213
|
).join(`
|
|
214
214
|
`)}` : a = `No vector search field results found for score over ${f}.`, await h({ text: a }, t), {
|
|
215
215
|
...e,
|
|
216
|
-
vectorSearchFieldResults:
|
|
216
|
+
vectorSearchFieldResults: c
|
|
217
217
|
};
|
|
218
218
|
} catch (o) {
|
|
219
219
|
throw await h(
|
|
@@ -221,7 +221,7 @@ ${r.results.map((d) => ` - ${d.name} (${d.score.toFixed(2)})`).join(`
|
|
|
221
221
|
t
|
|
222
222
|
), o;
|
|
223
223
|
}
|
|
224
|
-
}, Q = (e, t) => P(["layerSearch", "layersAndFieldsRegistry"], "Navigation Agent")(e, t), X = () => new
|
|
224
|
+
}, Q = (e, t) => P(["layerSearch", "layersAndFieldsRegistry"], "Navigation Agent")(e, t), X = () => new b(w).addNode("requireNavigationServices", Q).addNode("intentLLM", J).addNode("vectorSearchLayers", U).addNode("vectorSearchFields", K).addNode("agent", O).addNode("tools", D).addEdge($, "requireNavigationServices").addEdge("requireNavigationServices", "intentLLM").addConditionalEdges(
|
|
225
225
|
"intentLLM",
|
|
226
226
|
(t) => t.intent === "goToLayer" || t.intent === "goToFeatures" ? "vectorSearchLayers" : "agent",
|
|
227
227
|
{
|