@arcgis/ai-components 5.1.0-next.115 → 5.1.0-next.117

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.
Files changed (117) hide show
  1. package/dist/agent-utils/BaseAgent.d.ts +90 -0
  2. package/dist/agent-utils/BaseAgent.js +87 -0
  3. package/dist/agent-utils/FunctionAgent.d.ts +64 -0
  4. package/dist/agent-utils/FunctionAgent.js +98 -0
  5. package/dist/agent-utils/LLMAgent.d.ts +65 -0
  6. package/dist/agent-utils/LLMAgent.js +139 -0
  7. package/dist/agent-utils/WorkflowAgent.d.ts +44 -0
  8. package/dist/agent-utils/WorkflowAgent.js +70 -0
  9. package/dist/agent-utils/middlewares/humanInTheLoop.d.ts +152 -0
  10. package/dist/agent-utils/middlewares/humanInTheLoop.js +94 -0
  11. package/dist/agent-utils/middlewares/middleware.d.ts +25 -0
  12. package/dist/agent-utils/middlewares/middleware.js +44 -0
  13. package/dist/agent-utils/middlewares/trace.d.ts +25 -0
  14. package/dist/agent-utils/middlewares/trace.js +50 -0
  15. package/dist/agent-utils/middlewares/types.d.ts +123 -0
  16. package/dist/agent-utils/middlewares/types.js +2 -0
  17. package/dist/agent-utils/tools/FunctionTool.d.ts +127 -0
  18. package/dist/agent-utils/tools/FunctionTool.js +80 -0
  19. package/dist/agent-utils/types.d.ts +152 -0
  20. package/dist/agent-utils/workflows/BaseWorkflow.d.ts +87 -0
  21. package/dist/agent-utils/workflows/ConditionalWorkflow.d.ts +72 -0
  22. package/dist/agent-utils/workflows/ConditionalWorkflow.js +61 -0
  23. package/dist/agent-utils/workflows/LoopWorkflow.d.ts +58 -0
  24. package/dist/agent-utils/workflows/LoopWorkflow.js +56 -0
  25. package/dist/agent-utils/workflows/ParallelWorkflow.d.ts +68 -0
  26. package/dist/agent-utils/workflows/ParallelWorkflow.js +129 -0
  27. package/dist/agent-utils/workflows/RouterWorkflow.d.ts +63 -0
  28. package/dist/agent-utils/workflows/RouterWorkflow.js +75 -0
  29. package/dist/agent-utils/workflows/SequentialWorkflow.d.ts +56 -0
  30. package/dist/agent-utils/workflows/SequentialWorkflow.js +69 -0
  31. package/dist/agent-utils/workflows/SwitchWorkflow.d.ts +74 -0
  32. package/dist/agent-utils/workflows/SwitchWorkflow.js +84 -0
  33. package/dist/assets/embeddings.worker-k9_Ou679.js +1 -0
  34. package/dist/cdn/{RACFQ7G7.js → 7J26XD64.js} +1 -1
  35. package/dist/cdn/{RYEH3CUI.js → B3TOOMRL.js} +48 -49
  36. package/dist/cdn/DQE7BZ7J.js +42 -0
  37. package/dist/cdn/FTK7YZJ2.js +36 -0
  38. package/dist/cdn/IHFTPX4T.js +22 -0
  39. package/dist/cdn/J5NF6FQP.js +14 -0
  40. package/dist/cdn/{EJWQC2SL.js → KLIA4JYQ.js} +1 -1
  41. package/dist/cdn/N5ORE2OA.js +16 -0
  42. package/dist/cdn/UBPQG2VW.js +3 -0
  43. package/dist/cdn/WI7N36W3.js +166 -0
  44. package/dist/cdn/YOFAGUJN.js +2 -0
  45. package/dist/cdn/index.js +1 -1
  46. package/dist/chunks/BaseWorkflow.js +107 -0
  47. package/dist/chunks/adapter.js +2964 -0
  48. package/dist/chunks/arcgisKnowledgeGraph.js +174 -0
  49. package/dist/chunks/arcgis_knowledge_current_lc_context.js +8 -0
  50. package/dist/chunks/arcgis_knowledge_current_map_context.js +8 -0
  51. package/dist/chunks/arcgis_knowledge_lucene_generation_prompt.js +101 -0
  52. package/dist/chunks/arcgis_knowledge_summarize_result_prompt.js +48 -0
  53. package/dist/chunks/arcgis_knowledge_tool_prompt.js +34 -0
  54. package/dist/chunks/dataExplorationGraph.js +289 -0
  55. package/dist/chunks/data_explore_filter_prompt.js +125 -0
  56. package/dist/chunks/data_explore_query_prompt.js +131 -0
  57. package/dist/chunks/embeddings.worker.js +25 -0
  58. package/dist/chunks/field_descriptions_prompt.js +112 -0
  59. package/dist/chunks/generateLayerDescriptions.js +413 -0
  60. package/dist/chunks/graph.js +86 -0
  61. package/dist/chunks/helpGraph.js +123 -0
  62. package/dist/chunks/help_prompt.js +57 -0
  63. package/dist/chunks/intent_prompt.js +124 -0
  64. package/dist/chunks/layerStylingGraph.js +189 -0
  65. package/dist/chunks/layer_descriptions_prompt.js +59 -0
  66. package/dist/chunks/layer_styling_prompt.js +72 -0
  67. package/dist/chunks/navigationGraph.js +266 -0
  68. package/dist/chunks/navigation_intent_prompt.js +46 -0
  69. package/dist/chunks/navigation_tool_prompt.js +39 -0
  70. package/dist/chunks/orchestrator.js +528 -0
  71. package/dist/chunks/state.js +71 -0
  72. package/dist/chunks/summarize_query_response_prompt.js +77 -0
  73. package/dist/chunks/toolCallResponse.js +29 -0
  74. package/dist/chunks/utils.js +46 -40
  75. package/dist/chunks/utils2.js +41 -10
  76. package/dist/chunks/utils3.js +16 -0
  77. package/dist/components/arcgis-assistant/customElement.js +31 -23
  78. package/dist/components/arcgis-assistant/types.d.ts +1 -1
  79. package/dist/components/arcgis-assistant-agent/customElement.d.ts +1 -1
  80. package/dist/components/arcgis-assistant-agent/customElement.js +1 -1
  81. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +24 -8
  82. package/dist/components/arcgis-assistant-help-agent/customElement.js +27 -8
  83. package/dist/components/arcgis-assistant-knowledge-agent/customElement.d.ts +16 -2
  84. package/dist/components/arcgis-assistant-knowledge-agent/customElement.js +36 -19
  85. package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +27 -8
  86. package/dist/components/arcgis-assistant-message-block/customElement.d.ts +1 -1
  87. package/dist/components/arcgis-assistant-navigation-agent/customElement.js +25 -7
  88. package/dist/docs/api.json +1 -1
  89. package/dist/docs/docs.json +1 -1
  90. package/dist/docs/web-types.json +1 -1
  91. package/dist/utils/index.d.ts +203 -9
  92. package/dist/utils/index.js +108 -10
  93. package/package.json +22 -7
  94. package/dist/cdn/F746AXM6.js +0 -2
  95. package/dist/cdn/HKVQQV3Z.js +0 -2
  96. package/dist/cdn/NWLDMNBB.js +0 -283
  97. package/dist/cdn/PGHTDGBE.js +0 -2
  98. package/dist/cdn/R5PFKR6I.js +0 -2
  99. package/dist/cdn/RTYJZ47N.js +0 -2
  100. package/dist/cdn/SHR5YB5Q.js +0 -2
  101. /package/dist/cdn/{YVTKUITE.js → 53Z3R4OY.js} +0 -0
  102. /package/dist/cdn/{CFT5BBC6.js → 77GAVZIK.js} +0 -0
  103. /package/dist/cdn/{Z7GVYVWK.js → BXKPX3C7.js} +0 -0
  104. /package/dist/cdn/{W5CHGOOR.js → G7XK3XOR.js} +0 -0
  105. /package/dist/cdn/{LSGRWCAO.js → GH7EROHP.js} +0 -0
  106. /package/dist/cdn/{DMLSCJAM.js → HJGF7W5O.js} +0 -0
  107. /package/dist/cdn/{5X5GJH2L.js → KWORBODI.js} +0 -0
  108. /package/dist/cdn/{K6LVZHWM.js → MFEAOGTZ.js} +0 -0
  109. /package/dist/cdn/{47QQSSPB.js → MLQKBQSG.js} +0 -0
  110. /package/dist/cdn/{JDL3HFFX.js → MQ7QXIOW.js} +0 -0
  111. /package/dist/cdn/{MZJGADGH.js → NMWLJECU.js} +0 -0
  112. /package/dist/cdn/{ESTSYVJP.js → ORRZDP5H.js} +0 -0
  113. /package/dist/cdn/{JKAITV5Q.js → PTKZXFXB.js} +0 -0
  114. /package/dist/cdn/{5PT7ZFXF.js → RNMI3HNM.js} +0 -0
  115. /package/dist/cdn/{7EXACS27.js → SCT3365V.js} +0 -0
  116. /package/dist/cdn/{24MYCR6F.js → URYKQKFE.js} +0 -0
  117. /package/dist/cdn/{SFREIREB.js → WTEDVMFR.js} +0 -0
@@ -0,0 +1,413 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
+ import { Annotation as d } from "@langchain/langgraph/web";
3
+ import p, { z as r } from "zod";
4
+ import { ChatPromptTemplate as C, SystemMessagePromptTemplate as K } from "@langchain/core/prompts";
5
+ import { dispatchCustomEvent as F } from "@langchain/core/callbacks/dispatch/web";
6
+ import { AIMessage as B, isAIMessage as W, isToolMessage as H } from "@langchain/core/messages";
7
+ import { createAgent as J, summarizationMiddleware as X, modelCallLimitMiddleware as G } from "langchain";
8
+ import { ChatOpenAI as Q, OpenAIEmbeddings as Y } from "@langchain/openai";
9
+ import U from "@arcgis/core/identity/IdentityManager.js";
10
+ import S from "@arcgis/core/portal/Portal.js";
11
+ const _ = {
12
+ advanced: "gpt-5.2",
13
+ default: "gpt-5-mini",
14
+ fast: "gpt-5.4-nano"
15
+ }, k = {
16
+ default: "text-embedding-ada-002"
17
+ }, M = /* @__PURE__ */ new Map();
18
+ let T = null;
19
+ const Z = () => {
20
+ const t = S.getDefault().helperServices;
21
+ if (!t?.aiModels?.url)
22
+ throw new Error("AI Models Service URL is not defined in the portal's helper services.");
23
+ return t.aiModels.url;
24
+ }, P = async (e) => {
25
+ const t = Z();
26
+ M.size === 0 && (T || (T = (async () => {
27
+ try {
28
+ const n = await fetch(`${t}/models`);
29
+ if (!n.ok)
30
+ throw new Error("Failed to fetch AI service discovery data.");
31
+ (await n.json()).models.forEach((o) => M.set(o.name, o));
32
+ } catch (n) {
33
+ throw T = null, n;
34
+ }
35
+ })()), await T);
36
+ const s = M.get(e);
37
+ if (!s)
38
+ throw new Error(`Model '${e}' is not available in the discovery service.`);
39
+ return s.endpoint;
40
+ }, ee = async (e = "default") => await P(_[e]), te = async (e = "default") => await P(k[e]), u = (e, t) => t, q = (e, t) => ({
41
+ ...e,
42
+ ...t
43
+ }), $ = (e = "", t) => {
44
+ const s = typeof t == "string" ? t.trim() : "";
45
+ if (!s)
46
+ return e;
47
+ const n = e.trim();
48
+ if (!n)
49
+ return s;
50
+ if (n === s)
51
+ return e;
52
+ const i = n.split(`
53
+
54
+ `);
55
+ return i[i.length - 1]?.trim() === s ? e : `${e}
56
+
57
+ ${s}`;
58
+ }, j = () => ({
59
+ userRequest: "",
60
+ assignedTask: "",
61
+ messages: [],
62
+ priorSteps: [],
63
+ sharedState: {}
64
+ }), ne = () => ({
65
+ agentExecutionContext: d({
66
+ reducer: q,
67
+ default: j
68
+ }),
69
+ outputMessage: d({
70
+ reducer: $,
71
+ default: () => ""
72
+ }),
73
+ summary: d({
74
+ reducer: u,
75
+ default: () => ""
76
+ }),
77
+ status: d({
78
+ reducer: u
79
+ })
80
+ }), Ee = () => ({
81
+ ...ne(),
82
+ sharedStatePatch: d({
83
+ reducer: u
84
+ })
85
+ }), Ie = d.Root({
86
+ agentExecutionContext: d({
87
+ default: j,
88
+ reducer: q
89
+ }),
90
+ currentIntent: d({
91
+ default: () => "none",
92
+ reducer: u
93
+ }),
94
+ lastExecutedAgent: d({
95
+ default: () => "",
96
+ reducer: u
97
+ }),
98
+ requiresFollowUp: d({
99
+ default: () => !0,
100
+ reducer: u
101
+ }),
102
+ stepCount: d({
103
+ default: () => 0,
104
+ reducer: (e, t) => t ?? e + 1
105
+ }),
106
+ finalOutputMessage: d({
107
+ default: () => "",
108
+ reducer: $
109
+ })
110
+ }), y = async (e, t) => {
111
+ await F("trace_message", e, t);
112
+ }, De = async (e, t) => {
113
+ await F("graph_ux_suggestion", e, t);
114
+ }, se = (e, t, s) => {
115
+ const n = e[t];
116
+ return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((i, o) => {
117
+ (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(o.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + t + (t.split("/").length !== s ? ". Note that variables only represent file names one level deep." : ""))));
118
+ });
119
+ }, A = async (e) => (await se(/* @__PURE__ */ Object.assign({ "./field_descriptions_prompt.md": () => import("./field_descriptions_prompt.js"), "./intent_prompt.md": () => import("./intent_prompt.js"), "./layer_descriptions_prompt.md": () => import("./layer_descriptions_prompt.js") }), `./${e}.md`, 2)).default, ie = async (e) => {
120
+ const { agent: t, messages: s, config: n } = e;
121
+ return { structuredResponse: (await t.invoke(
122
+ {
123
+ messages: s
124
+ },
125
+ n
126
+ )).structuredResponse };
127
+ }, N = (e) => async (t, s) => {
128
+ const n = new Headers(s?.headers);
129
+ return n.delete("Authorization"), n.delete("api-key"), e && e.length > 0 && (n.set("X-Esri-Authorization", `Bearer ${e}`), n.set("X-Esri-Request-Source", "MapsSDK")), await fetch(t, {
130
+ ...s,
131
+ headers: n
132
+ });
133
+ }, x = async (e = "default", t = 0) => {
134
+ const s = S.getDefault(), n = await U.getCredential(`${s.url}/sharing`), i = _[e], o = await ee(e);
135
+ return new Q({
136
+ modelName: i,
137
+ apiKey: "dummy-key",
138
+ // 5-mini does not support temperature parameter
139
+ ...e !== "default" && { temperature: t },
140
+ configuration: {
141
+ baseURL: o,
142
+ fetch: N(n.token)
143
+ }
144
+ });
145
+ }, Re = async (e = "default") => {
146
+ const t = S.getDefault(), s = await U.getCredential(`${t.url}/sharing`), n = k[e], i = await te(e);
147
+ return new Y({
148
+ modelName: n,
149
+ apiKey: "dummy-key",
150
+ configuration: {
151
+ baseURL: i,
152
+ fetch: N(s.token)
153
+ },
154
+ batchSize: 2048,
155
+ maxConcurrency: 10
156
+ });
157
+ }, re = r.object({
158
+ id: r.string().min(1),
159
+ name: r.string().min(1),
160
+ description: r.string().min(1)
161
+ });
162
+ r.array(re);
163
+ const D = (e) => JSON.stringify(e, null, 2), oe = (e) => {
164
+ const t = e.map((n) => n.id), s = r.enum(t);
165
+ return r.object({
166
+ intent: s.nullable(),
167
+ assignedTask: r.string().nullable(),
168
+ requiresFollowUp: r.boolean()
169
+ });
170
+ }, Ce = async (e, t) => {
171
+ try {
172
+ await y({ text: "Asking LLM to route to an agent" }, t);
173
+ const i = (t?.configurable?.services.agentRegistry?.list() ?? []).map(({ agent: h }) => ({
174
+ id: h.id,
175
+ name: h.name,
176
+ description: h.description
177
+ }));
178
+ if (!i.length)
179
+ return await y({ text: "No agents registered; skipping intent detection" }, t), { ...e, currentIntent: "none" };
180
+ const o = await A("intent_prompt"), a = D(i), c = oe(i), l = {
181
+ registeredAgents: a,
182
+ priorSteps: D(e.agentExecutionContext.priorSteps),
183
+ userRequest: e.agentExecutionContext.userRequest
184
+ }, g = await C.fromTemplate(o).format(l), I = J({
185
+ model: await x("fast"),
186
+ tools: [],
187
+ systemPrompt: g,
188
+ checkpointer: !0,
189
+ responseFormat: c,
190
+ middleware: [
191
+ // Preserve recent conversation context while summarizing older messages
192
+ // to control token usage without losing important intent signals.
193
+ // The trigger and keep parameters can be tuned based on token limits and behavior.
194
+ X({
195
+ model: await x("fast"),
196
+ trigger: { tokens: 4e3 },
197
+ keep: { messages: 6 }
198
+ }),
199
+ // Enforce no loop/retry.
200
+ // 1 usual LLM call and 1 optional summarization call.
201
+ G({ runLimit: 2 })
202
+ ]
203
+ }), { structuredResponse: z } = await ie({
204
+ agent: I,
205
+ messages: e.agentExecutionContext.messages,
206
+ config: t
207
+ }), f = c.parse(
208
+ z ?? { intent: null, assignedTask: null, requiresFollowUp: !1 }
209
+ ), v = f.intent ?? "none", L = {
210
+ ...e,
211
+ currentIntent: v,
212
+ requiresFollowUp: f.requiresFollowUp,
213
+ agentExecutionContext: {
214
+ ...e.agentExecutionContext,
215
+ assignedTask: f.assignedTask ?? ""
216
+ }
217
+ };
218
+ if (v === "none") {
219
+ const h = "I could not find a matching agent for that request. Please rephrase your question with more detail.";
220
+ return await y({ text: "LLM did not identify a clear intent." }, t), {
221
+ ...e,
222
+ currentIntent: v,
223
+ requiresFollowUp: !1,
224
+ agentExecutionContext: {
225
+ ...e.agentExecutionContext,
226
+ assignedTask: "",
227
+ messages: [...e.agentExecutionContext.messages, new B(h)],
228
+ priorSteps: [
229
+ ...e.agentExecutionContext.priorSteps ?? [],
230
+ {
231
+ agentId: "no-intent-router",
232
+ assignedTask: e.agentExecutionContext.userRequest,
233
+ summary: "No matching agent found; asked user to rephrase.",
234
+ status: "failed"
235
+ }
236
+ ]
237
+ }
238
+ };
239
+ }
240
+ return await y(
241
+ {
242
+ text: `Agent picked: ${v}
243
+ Task Assigned: ${f.assignedTask ?? ""}
244
+ Requires Follow-Up: ${f.requiresFollowUp}`
245
+ },
246
+ t
247
+ ), L;
248
+ } catch (s) {
249
+ throw await y({ text: "Error during intent detection" }, t), new Error(`Error during intent detection: ${s instanceof Error ? s.message : String(s)}`);
250
+ }
251
+ }, ae = "0.1", w = 1536, ce = "openai", le = k.default, de = `Name: {name}
252
+ Title: {title}
253
+ Description: {description}`, pe = `Name: {name}
254
+ Alias: {alias}
255
+ Description: {description}`, Fe = r.object({
256
+ schemaVersion: r.literal(ae),
257
+ modified: r.number().int().nonnegative(),
258
+ embeddings: r.object({
259
+ modelProvider: r.literal(ce),
260
+ model: r.literal(le),
261
+ dimensions: r.literal(w),
262
+ templates: r.object({
263
+ layer: r.string().default(de),
264
+ field: r.string().default(pe)
265
+ })
266
+ }),
267
+ layers: r.array(
268
+ r.object({
269
+ id: r.string().min(1),
270
+ name: r.string().min(1),
271
+ title: r.string().catch(""),
272
+ description: r.string().catch(""),
273
+ vector: r.array(r.number()).length(w, {
274
+ message: `Layer vector must be exactly ${w} dimensions`
275
+ }),
276
+ fields: r.array(
277
+ r.object({
278
+ name: r.string().min(1),
279
+ alias: r.string().catch(""),
280
+ description: r.string().catch(""),
281
+ vector: r.array(r.number()).length(w, {
282
+ message: `Field vector must be exactly ${w} dimensions`
283
+ })
284
+ })
285
+ )
286
+ })
287
+ ).default([])
288
+ }), me = (e) => {
289
+ const t = /* @__PURE__ */ new Set();
290
+ for (const n of e)
291
+ if (W(n)) {
292
+ const i = n;
293
+ i.tool_calls && i.tool_calls.length > 0 && i.tool_calls.forEach((o) => {
294
+ o.id && t.add(o.id);
295
+ });
296
+ }
297
+ return e.filter((n) => {
298
+ if (H(n)) {
299
+ const i = n;
300
+ return t.has(i.tool_call_id);
301
+ }
302
+ return !0;
303
+ });
304
+ }, E = (e, t) => {
305
+ const s = K.fromTemplate(e);
306
+ return C.fromMessages([s, ...t]);
307
+ }, ue = async (e) => {
308
+ const { promptText: t, modelTier: s, temperature: n, messages: i } = e, o = E(t, i ?? []), a = await x(s, n);
309
+ return o.pipe(a);
310
+ }, Ue = async (e) => {
311
+ const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: i, inputVariables: o } = e, c = await (await ue({
312
+ promptText: t,
313
+ modelTier: s,
314
+ temperature: n,
315
+ messages: i
316
+ })).invoke(o ?? {});
317
+ if (typeof c == "string")
318
+ return c;
319
+ const l = c.content;
320
+ return typeof l == "string" ? l : JSON.stringify(l);
321
+ }, O = async (e) => {
322
+ const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: i, inputVariables: o, schema: a } = e, c = E(t, i ?? []), m = (await x(s, n)).withStructuredOutput(a);
323
+ return await c.pipe(m).invoke(o ?? {});
324
+ }, _e = async (e) => {
325
+ const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: i, inputVariables: o, tools: a } = e, c = a.length > 0 ? me(i ?? []) : i ?? [], l = E(t, c), m = await x(s, n);
326
+ return await l.pipe(m.bindTools(a)).invoke(o ?? {});
327
+ }, ge = p.object({
328
+ name: p.string(),
329
+ description: p.string(),
330
+ valueType: p.string(),
331
+ alias: p.string()
332
+ }), fe = p.object({
333
+ fields: p.array(ge)
334
+ }), V = (e, t) => e.getFieldAlias(t) ?? void 0, b = (e, t) => V(e, t.name) ?? t.alias ?? "", he = (e, t) => {
335
+ const s = V(e, t.name);
336
+ return !!(s && s !== (t.alias ?? ""));
337
+ };
338
+ function R(e, t) {
339
+ const s = /* @__PURE__ */ new Map();
340
+ for (const n of e.fields) {
341
+ const i = t.fields.find((l) => l.name === n.name), o = b(e, n), a = he(e, n), c = {
342
+ name: n.name,
343
+ type: n.type,
344
+ alias: a ? o : i?.alias ?? o,
345
+ description: i?.description ?? n.description ?? "",
346
+ valueType: i?.valueType ?? n.valueType ?? "",
347
+ domain: e.getFieldDomain(n.name) ?? void 0
348
+ };
349
+ s.set(n.name, c);
350
+ }
351
+ return s;
352
+ }
353
+ const Pe = async (e) => {
354
+ const s = await A("field_descriptions_prompt"), n = e.fields.filter((a) => !(b(e, a) && a.description)).map((a) => {
355
+ const { name: c, type: l, description: m } = a, g = b(e, a);
356
+ return [`Name: ${c}`, `Type: ${l}`, `Alias: ${g}`, `Description: ${m ?? "N/A"}`].join(", ");
357
+ }).join(`
358
+ `);
359
+ if (n.length === 0)
360
+ return R(e, { fields: [] });
361
+ const i = {
362
+ existingItemTitle: e.portalItem?.title,
363
+ existingItemDescription: e.portalItem?.description,
364
+ existingLayerTitle: e.title,
365
+ existingLayerDescription: e.portalItem?.description,
366
+ fieldInformation: n
367
+ }, o = await O({
368
+ promptText: s,
369
+ schema: fe,
370
+ inputVariables: i
371
+ });
372
+ return R(e, o);
373
+ }, ye = p.object({
374
+ title: p.string(),
375
+ description: p.string(),
376
+ name: p.string().nullable()
377
+ }), qe = async (e, t) => {
378
+ const n = await A("layer_descriptions_prompt"), i = Array.from(t.values()), o = {
379
+ fieldInformation: JSON.stringify(i, null, 2),
380
+ existingLayerTitle: e.title,
381
+ existingLayerDescription: e.portalItem?.description,
382
+ existingLayerSnippet: e.portalItem?.snippet,
383
+ layerGeometryType: e.geometryType
384
+ };
385
+ return { ...await O({
386
+ promptText: n,
387
+ schema: ye,
388
+ inputVariables: o
389
+ }), name: e.title ?? null };
390
+ };
391
+ export {
392
+ Ie as D,
393
+ Fe as W,
394
+ qe as a,
395
+ ce as b,
396
+ x as c,
397
+ w as d,
398
+ ae as e,
399
+ pe as f,
400
+ Pe as g,
401
+ Ue as h,
402
+ O as i,
403
+ _e as j,
404
+ ne as k,
405
+ de as l,
406
+ le as m,
407
+ Ee as n,
408
+ De as o,
409
+ te as p,
410
+ Ce as q,
411
+ Re as r,
412
+ y as s
413
+ };
@@ -0,0 +1,86 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
+ import { StateGraph as G, END as p, START as k } from "@langchain/langgraph/web";
3
+ function b(t, c, o, s = {}) {
4
+ const { agent: h, entryNode: u, middlewares: l = [] } = s;
5
+ let r = new G(o);
6
+ if (Object.keys(t).length === 0)
7
+ throw new Error("Graph requires at least one node.");
8
+ if (c.length === 0)
9
+ throw new Error("Graph requires at least one edge.");
10
+ if (l.length > 0 && !h)
11
+ throw new Error("Graph middleware requires agent metadata.");
12
+ const n = new Set(Object.keys(t)), d = /* @__PURE__ */ new Map(), w = /* @__PURE__ */ new Map();
13
+ for (const e of n)
14
+ d.set(e, 0), w.set(e, 0);
15
+ for (const e of c)
16
+ "to" in e ? (n.has(e.from) && w.set(e.from, (w.get(e.from) ?? 0) + 1), n.has(e.to) && d.set(e.to, (d.get(e.to) ?? 0) + 1)) : n.has(e.from) && w.set(e.from, (w.get(e.from) ?? 0) + 1);
17
+ for (const [e, a] of Object.entries(t)) {
18
+ const f = $(
19
+ h,
20
+ e,
21
+ l,
22
+ async (i, m) => await Promise.resolve(a(i, m))
23
+ ), g = async (i, m) => await f(i, m);
24
+ r = r.addNode(e, g);
25
+ }
26
+ for (const e of c)
27
+ if ("to" in e) {
28
+ const a = e.from, f = e.to;
29
+ if (!n.has(a))
30
+ throw new Error(`Graph edge references unknown from-node: ${a}`);
31
+ if (!n.has(f))
32
+ throw new Error(`Graph edge references unknown to-node: ${f}`);
33
+ r.addEdge(a, f);
34
+ } else {
35
+ const a = e.from;
36
+ if (!n.has(a))
37
+ throw new Error(`Graph conditional edge references unknown from-node: ${a}`);
38
+ r.addConditionalEdges(
39
+ a,
40
+ async (f, g) => {
41
+ const i = await e.decide(f, g);
42
+ if (!i)
43
+ return p;
44
+ if (!n.has(i))
45
+ throw new Error(`Graph conditional edge returned unknown node: ${i}`);
46
+ return i;
47
+ }
48
+ );
49
+ }
50
+ const E = x(n, d, u);
51
+ r.addEdge(k, E);
52
+ const y = [...n].filter((e) => (w.get(e) ?? 0) === 0);
53
+ for (const e of y)
54
+ r.addEdge(e, p);
55
+ return r;
56
+ }
57
+ function $(t, c, o, s) {
58
+ return !o.length || !t ? s : async (h, u) => await o.reduceRight(
59
+ (r, n) => async (d) => await n.handler(d, r),
60
+ async (r) => {
61
+ const n = await s(r.state, r.config);
62
+ return { ...r.state, ...n };
63
+ }
64
+ )({
65
+ agent: t,
66
+ config: u,
67
+ nodeName: c,
68
+ state: h
69
+ });
70
+ }
71
+ function x(t, c, o) {
72
+ if (o) {
73
+ if (!t.has(o))
74
+ throw new Error(`Graph entry node references unknown node: ${o}`);
75
+ return o;
76
+ }
77
+ const s = [...t].filter((h) => (c.get(h) ?? 0) === 0);
78
+ if (s.length !== 1)
79
+ throw new Error(
80
+ `Graph could not infer a single entry node (found ${s.length}). Provide an explicit entryNode or ensure exactly one node has no incoming edges.`
81
+ );
82
+ return s[0];
83
+ }
84
+ export {
85
+ b as c
86
+ };
@@ -0,0 +1,123 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
+ import { StateGraph as d, START as g, END as i } from "@langchain/langgraph/web";
3
+ import { l as h, g as x, f as p, r as f, t as y, H as u } from "./adapter.js";
4
+ import "@arcgis/core/identity/IdentityManager.js";
5
+ import "@arcgis/core/portal/Portal.js";
6
+ import { j as S, s as c } from "./generateLayerDescriptions.js";
7
+ import "@langchain/core/messages";
8
+ import "@langchain/core/callbacks/dispatch/web";
9
+ import "@langchain/openai";
10
+ import "@arcgis/core/core/reactiveUtils.js";
11
+ import "@arcgis/core/layers/FeatureLayer.js";
12
+ import "@arcgis/core/request.js";
13
+ import { ToolNode as E } from "@langchain/langgraph/prebuilt";
14
+ import "@langchain/core/prompts";
15
+ const m = [h], v = (e) => {
16
+ if (!e || e.size === 0)
17
+ return "No layers available in this map.";
18
+ const t = Array.from(e.values()).map(({ layerItem: r, fieldRegistry: s }, l) => {
19
+ const a = Array.from(s.values()).map((n) => n.name).slice(0, 10).join(", "), o = s.size > 10 ? ` (and ${s.size - 10} more)` : "";
20
+ return `${l + 1}. "${r.title}". Description: ${r.description}
21
+ Fields: ${a}${o}`;
22
+ }).join(`
23
+
24
+ `);
25
+ return `This map contains ${e.size} layer(s):
26
+
27
+ ${t}`;
28
+ }, T = (e) => {
29
+ const t = e?.list() ?? [];
30
+ return t.length ? t.map((r) => `- ${r.agent.name}: ${r.agent.description}`).join(`
31
+ `) : "No agents currently available.";
32
+ };
33
+ async function _(e, t) {
34
+ const r = await x("help_prompt"), s = p(t, "layersAndFieldsRegistry"), l = p(t, "agentRegistry");
35
+ try {
36
+ const a = await S({
37
+ promptText: r,
38
+ modelTier: "fast",
39
+ tools: m,
40
+ inputVariables: {
41
+ layerSummary: v(s),
42
+ agents: T(l),
43
+ assignedTask: e.agentExecutionContext.assignedTask,
44
+ userRequest: e.agentExecutionContext.userRequest,
45
+ priorSteps: e.agentExecutionContext.priorSteps
46
+ }
47
+ }), o = (a.tool_calls?.length ?? 0) > 0, n = typeof a.text == "string" ? a.text.trim() : "";
48
+ return {
49
+ ...e,
50
+ helpInternalState: {
51
+ ...e.helpInternalState,
52
+ toolCallMessage: o ? a : void 0
53
+ },
54
+ outputMessage: o ? e.outputMessage : n,
55
+ summary: o ? "Prepared help tool call from assigned task." : "Provided map-related help based on the assigned task.",
56
+ status: o ? e.status : "success"
57
+ };
58
+ } catch (a) {
59
+ const o = a instanceof Error ? a.message : String(a);
60
+ return {
61
+ ...e,
62
+ outputMessage: `Error invoking help agent: ${o}`,
63
+ summary: "Help agent execution failed.",
64
+ status: "failed"
65
+ };
66
+ }
67
+ }
68
+ const C = (e, t) => f(["agentRegistry"], "Help Agent")(e, t);
69
+ async function H(e, t) {
70
+ const r = new E(m);
71
+ try {
72
+ const s = e.helpInternalState.toolCallMessage;
73
+ if (!s)
74
+ throw new Error("helpToolCalling: missing helpInternalState.toolCallMessage");
75
+ const a = (await r.invoke({ messages: [s] }, t)).messages.map((o) => o.text).join(`
76
+ `);
77
+ return await c({ text: `Finished executing help tool: ${a}` }, t), {
78
+ ...e,
79
+ outputMessage: a,
80
+ status: "success",
81
+ summary: a ? y(a) : "Help executed.",
82
+ helpInternalState: {
83
+ ...e.helpInternalState,
84
+ toolCallMessage: void 0
85
+ }
86
+ };
87
+ } catch (s) {
88
+ const l = s instanceof Error ? s.message : String(s);
89
+ return await c({ text: `Help tool execution failed: ${l}` }, t), {
90
+ ...e,
91
+ outputMessage: `Help tool execution failed: ${l}`,
92
+ status: "failed",
93
+ summary: `Help tool execution failed: ${l}`,
94
+ helpInternalState: {
95
+ ...e.helpInternalState,
96
+ toolCallMessage: void 0
97
+ }
98
+ };
99
+ }
100
+ }
101
+ const b = () => new d(u).addNode("requireHelpServices", C).addNode("agent", _).addNode("tools", H).addEdge(g, "requireHelpServices").addEdge("requireHelpServices", "agent").addConditionalEdges("agent", (t) => t.helpInternalState.toolCallMessage ? "tools" : i).addEdge("tools", i), M = String.raw`- **help** — Enables users to ask questions about the map, layers, fields, and it's capabilities.
102
+
103
+ _Example: “Tell me about this map”_
104
+ _Example: “List all layers in this map”_
105
+ _Example: “List fields in protected areas layer”_
106
+ _Example: “What agents are available to me?”_
107
+ _Example: “What can you do?”_
108
+ _Example: “What can I ask”_
109
+
110
+ Even if the user asks unrelated queries like "What are the vowels in English alphabet" or "How to cook", call this agent.
111
+
112
+ IF the user asks map related queries, but those that are not performed by any of the agents, call this agent so we can respond accordingly.
113
+ _Example: "Create a chart"_
114
+ _Example: "Create a table"_`, D = {
115
+ id: "help",
116
+ name: "Help Agent",
117
+ description: M,
118
+ createGraph: b,
119
+ workspace: u
120
+ };
121
+ export {
122
+ D as H
123
+ };
@@ -0,0 +1,57 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
+ const e = `## Map Query Gate
3
+
4
+ ### Input
5
+
6
+ Assigned task:
7
+ {assignedTask}
8
+
9
+ Latest user request:
10
+ {userRequest}
11
+
12
+ Prior steps:
13
+ {priorSteps}
14
+
15
+ Use the assigned task as the primary instruction for the current query. The question will **not** be restated again here.
16
+ Use the latest user request as supporting context when needed.
17
+ Use prior steps only when needed to explain a previous result, failure, or likely next action.
18
+
19
+ ### Map Context
20
+
21
+ {layerSummary}
22
+
23
+ ## Available agents (capabilities)
24
+
25
+ {agents}
26
+
27
+ ### Rules
28
+
29
+ - "What layers are in this map?" → List the layer names
30
+ - "What fields are in this layer?" → Call the tool to list the field names for that layer
31
+ - "What can you do?" / "What can I ask?" → Suggest specific queries using EXACT layer and field names from the context above
32
+ - "Tell me about this map" → Summarize layers and capabilities
33
+ - "Create a chart of all wells ans their depth" → If a question is map related but not supported by available capabilities, say so. Add that support for this might be added in the future.
34
+ - Questions completely unrelated to maps/GIS → Politely explain you only help with the map |
35
+
36
+ ### Response Guidelines
37
+
38
+ When suggesting what users can ask, be SPECIFIC using actual layer names:
39
+
40
+ - "Show me water sources with elevation above 500"
41
+ - "Filter Protected Areas in Panama by protection level"
42
+ - "Zoom to Watershed Boundaries"
43
+
44
+ For "what can I ask" responses, provide 3-5 specific example queries using fields from the context.
45
+
46
+ For off-topic questions:
47
+ "I can only help with this map. Try asking me to filter [LayerName] by [FieldName], or zoom to a location."
48
+
49
+ Rules:
50
+
51
+ - Keep responses concise
52
+ - Use bullet points for lists
53
+ - Use new lines (\\n) and appropriate formatting in your response
54
+ `;
55
+ export {
56
+ e as default
57
+ };