@arcgis/ai-components 5.2.0-next.71 → 5.2.0-next.73

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 (167) hide show
  1. package/LICENSE.md +4 -2
  2. package/dist/agent-utils/LLMAgent.d.ts +5 -2
  3. package/dist/agent-utils/LLMAgent.js +1 -1
  4. package/dist/agent-utils/types.d.ts +1 -1
  5. package/dist/agentic-workflow/AgenticWorkflowRuntime.d.ts +24 -0
  6. package/dist/agentic-workflow/Edge.d.ts +16 -0
  7. package/dist/agentic-workflow/WebAgent.d.ts +39 -0
  8. package/dist/agentic-workflow/jsonTypes.d.ts +193 -0
  9. package/dist/agentic-workflow/nodes/AgentNode.d.ts +28 -0
  10. package/dist/agentic-workflow/nodes/BaseNode.d.ts +35 -0
  11. package/dist/agentic-workflow/nodes/EndMessageNode.d.ts +25 -0
  12. package/dist/agentic-workflow/nodes/StartNode.d.ts +21 -0
  13. package/dist/agentic-workflow/nodes/support/Prompt.d.ts +20 -0
  14. package/dist/agentic-workflow/nodes/tools/ArcgisTool.d.ts +21 -0
  15. package/dist/agentic-workflow/types.d.ts +29 -0
  16. package/dist/cdn/2EJROB32.js +2 -0
  17. package/dist/cdn/34O57OGV.js +2 -0
  18. package/dist/cdn/3LXXSMA5.js +2 -0
  19. package/dist/cdn/3MJQA533.js +2 -0
  20. package/dist/cdn/3U476GCP.js +5 -0
  21. package/dist/cdn/3XXZUQMQ.js +2 -0
  22. package/dist/cdn/4YDXYW4J.js +2 -0
  23. package/dist/cdn/4ZUUS4DH.js +2 -0
  24. package/dist/cdn/527C4GD2.js +36 -0
  25. package/dist/cdn/5RZGG4F2.js +2 -0
  26. package/dist/cdn/5SF6DEMO.js +2 -0
  27. package/dist/cdn/5Y6TQAJN.js +2 -0
  28. package/dist/cdn/65IWA2PM.js +2 -0
  29. package/dist/cdn/{MW5S2XCB.js → 67YCNNCN.js} +2 -2
  30. package/dist/cdn/6FKLWNGA.js +2 -0
  31. package/dist/cdn/6QJFOL6M.js +2 -0
  32. package/dist/cdn/6RDKDLSX.js +2 -0
  33. package/dist/cdn/6SGNSDLY.js +2 -0
  34. package/dist/cdn/7747YL7V.js +2 -0
  35. package/dist/cdn/7TO56JHS.js +2 -0
  36. package/dist/cdn/ABXLPDEK.js +2 -0
  37. package/dist/cdn/BBJDW6GC.js +2 -0
  38. package/dist/cdn/{PUFTYLJ2.js → C4FKFOU4.js} +4 -4
  39. package/dist/cdn/CCC6LBMY.js +2 -0
  40. package/dist/cdn/CGVVL52C.js +2 -0
  41. package/dist/cdn/DBHLKLKM.js +2 -0
  42. package/dist/cdn/DKLK4EUE.js +2 -0
  43. package/dist/cdn/E25RINU2.js +2 -0
  44. package/dist/cdn/E62P76TP.js +2 -0
  45. package/dist/cdn/E7JLG2A2.js +2 -0
  46. package/dist/cdn/{TFT6HK3O.js → E7KEOJZG.js} +1 -1
  47. package/dist/cdn/FDOMMK2M.js +2 -0
  48. package/dist/cdn/FSMHR7GK.js +2 -0
  49. package/dist/cdn/GG3AESSV.js +2 -0
  50. package/dist/cdn/H6JSNAT4.js +2 -0
  51. package/dist/cdn/HNMFFLSY.js +2 -0
  52. package/dist/cdn/HO2YDJI2.js +6 -0
  53. package/dist/cdn/{KQHLOYKL.js → I4L45WQS.js} +1 -1
  54. package/dist/cdn/ITBQGOMF.js +11 -0
  55. package/dist/cdn/JH6EAWB2.js +2 -0
  56. package/dist/cdn/JON2JHS2.js +2 -0
  57. package/dist/cdn/JWPB3XZM.js +2 -0
  58. package/dist/cdn/JXB4TNSG.js +2 -0
  59. package/dist/cdn/JYVBCHR6.js +6 -0
  60. package/dist/cdn/KRN6AFNB.js +18 -0
  61. package/dist/cdn/KZACIY2W.js +2 -0
  62. package/dist/cdn/MKJS7QYQ.js +2 -0
  63. package/dist/cdn/N735LT4S.js +2 -0
  64. package/dist/cdn/NP7DG7LQ.js +2 -0
  65. package/dist/cdn/NTZAOJH5.js +2 -0
  66. package/dist/cdn/{CXW5URTF.js → OHMNQ3RU.js} +5 -5
  67. package/dist/cdn/ONQ6JSBJ.js +2 -0
  68. package/dist/cdn/PAUIFUMO.js +2 -0
  69. package/dist/cdn/QNNGPA3Q.js +2 -0
  70. package/dist/cdn/RATZTLNX.js +2 -0
  71. package/dist/cdn/RU5DVLYG.js +156 -0
  72. package/dist/cdn/{YHQJ66WJ.js → S3XUYAUX.js} +1 -1
  73. package/dist/cdn/S6ZAQRC6.js +2 -0
  74. package/dist/cdn/SABZC4D4.js +2 -0
  75. package/dist/cdn/TYL5G7KR.js +2 -0
  76. package/dist/cdn/{XETNZW4D.js → UAZLKUFN.js} +1 -1
  77. package/dist/cdn/UZL6UVE4.js +2 -0
  78. package/dist/cdn/VBZ5XGAM.js +2 -0
  79. package/dist/cdn/VXBUMZYR.js +2 -0
  80. package/dist/cdn/W5FLNFSN.js +2 -0
  81. package/dist/cdn/W5J4Q3RO.js +14 -0
  82. package/dist/cdn/WQKNV6KK.js +2 -0
  83. package/dist/cdn/{ICYUPLZM.js → WZFC5HUX.js} +1 -1
  84. package/dist/cdn/XGBEHER5.js +2 -0
  85. package/dist/cdn/XPTCV6YV.js +2 -0
  86. package/dist/cdn/Y5UFOH54.js +2 -0
  87. package/dist/cdn/YGCTAIBS.js +2 -0
  88. package/dist/cdn/{SXHH575T.js → ZJEWP2ND.js} +20 -24
  89. package/dist/cdn/agent-utils/index.js +1 -1
  90. package/dist/cdn/agent-utils/middlewares/humanInTheLoop.js +1 -1
  91. package/dist/cdn/agent-utils/middlewares/middleware.js +1 -1
  92. package/dist/cdn/agent-utils/middlewares/trace.js +1 -1
  93. package/dist/cdn/index.js +1 -1
  94. package/dist/chunks/adapter.js +939 -1950
  95. package/dist/chunks/adapter10.js +21 -0
  96. package/dist/chunks/adapter11.js +30 -0
  97. package/dist/chunks/adapter12.js +22 -0
  98. package/dist/chunks/adapter13.js +22 -0
  99. package/dist/chunks/adapter14.js +109 -0
  100. package/dist/chunks/adapter15.js +40 -0
  101. package/dist/chunks/adapter16.js +154 -0
  102. package/dist/chunks/adapter17.js +141 -0
  103. package/dist/chunks/adapter18.js +127 -0
  104. package/dist/chunks/adapter2.js +52 -0
  105. package/dist/chunks/adapter3.js +30 -0
  106. package/dist/chunks/adapter4.js +50 -0
  107. package/dist/chunks/adapter5.js +27 -0
  108. package/dist/chunks/adapter6.js +24 -0
  109. package/dist/chunks/adapter7.js +26 -0
  110. package/dist/chunks/adapter8.js +21 -0
  111. package/dist/chunks/adapter9.js +42 -0
  112. package/dist/chunks/arcgisKnowledgeGraph.js +5 -5
  113. package/dist/chunks/baseAgentState.js +56 -0
  114. package/dist/chunks/dataExplorationGraph.js +34 -31
  115. package/dist/chunks/fetchAgentContext.js +13 -0
  116. package/dist/chunks/fetchService.js +10 -0
  117. package/dist/chunks/formatFeatureAttributes.js +132 -0
  118. package/dist/chunks/generateLayerDescriptions.js +189 -235
  119. package/dist/chunks/helpGraph.js +11 -9
  120. package/dist/chunks/layerStylingGraph.js +22 -21
  121. package/dist/chunks/mergeWhereClauses.js +15 -0
  122. package/dist/chunks/navigationGraph.js +81 -70
  123. package/dist/chunks/orchestrator.js +1 -1
  124. package/dist/chunks/state.js +20 -26
  125. package/dist/chunks/types.js +59 -0
  126. package/dist/chunks/utils2.js +3 -3
  127. package/dist/components/arcgis-assistant-agent/customElement.d.ts +13 -1
  128. package/dist/components/arcgis-assistant-agent/customElement.js +636 -10
  129. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +15 -5
  130. package/dist/components/arcgis-assistant-help-agent/customElement.js +21 -5
  131. package/dist/components/arcgis-assistant-knowledge-agent/customElement.js +39 -22
  132. package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +22 -5
  133. package/dist/components/arcgis-assistant-navigation-agent/customElement.js +13 -5
  134. package/dist/docs/api.json +1 -1
  135. package/dist/docs/docs.json +1 -1
  136. package/dist/docs/vscode.html-custom-data.json +1 -1
  137. package/dist/docs/web-types.json +1 -1
  138. package/dist/loader.js +1 -1
  139. package/dist/types/lumina.d.ts +1 -1
  140. package/dist/types/preact.d.ts +1 -1
  141. package/dist/types/react.d.ts +1 -1
  142. package/dist/types/stencil.d.ts +1 -1
  143. package/dist/utils/index.js +26 -25
  144. package/package.json +4 -4
  145. package/dist/cdn/3DJDRAGV.js +0 -2
  146. package/dist/cdn/4CEMUECT.js +0 -2
  147. package/dist/cdn/4PCAK3ET.js +0 -2
  148. package/dist/cdn/57OMVTIU.js +0 -2
  149. package/dist/cdn/6U7TEAAJ.js +0 -2
  150. package/dist/cdn/BE7ZN5FZ.js +0 -2
  151. package/dist/cdn/BNSJO6X2.js +0 -2
  152. package/dist/cdn/CMDRED5H.js +0 -2
  153. package/dist/cdn/DTIVDIDY.js +0 -2
  154. package/dist/cdn/E5ZKBC24.js +0 -36
  155. package/dist/cdn/GP6NDTUE.js +0 -18
  156. package/dist/cdn/HBLRVXEB.js +0 -2
  157. package/dist/cdn/HQXPPYMD.js +0 -2
  158. package/dist/cdn/IEHPNCTL.js +0 -2
  159. package/dist/cdn/LHLO6PTD.js +0 -2
  160. package/dist/cdn/OWXCOUIQ.js +0 -2
  161. package/dist/cdn/PVE7Q43N.js +0 -2
  162. package/dist/cdn/ST5FQYT7.js +0 -180
  163. package/dist/cdn/WUNCZOGU.js +0 -2
  164. package/dist/cdn/WVPU4QOO.js +0 -2
  165. package/dist/cdn/WXWO5D3W.js +0 -2
  166. package/dist/cdn/XCRR2EEG.js +0 -6
  167. package/dist/cdn/ZS6SXJP2.js +0 -2
@@ -0,0 +1,21 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import t from "zod";
3
+ import { tool as m } from "@langchain/core/tools";
4
+ import { f as i } from "./fetchAgentContext.js";
5
+ async function r(o, e) {
6
+ return await e.goTo({ zoom: o }), { text: `Successfully zoomed to: ${o}` };
7
+ }
8
+ async function a({ zoom: o }, e) {
9
+ const { mapView: n } = i(e, ["mapView"]);
10
+ return await r(o, n);
11
+ }
12
+ const c = t.object({
13
+ zoom: t.number().min(1).max(20).describe("The zoom level of the view to go to.")
14
+ }), l = m(a, {
15
+ name: "goToZoom",
16
+ description: 'Go to the specified zoom level. If input is generic (e.g. "zoom in", then only zoom to the next appropriate level - increase level for zooming in and decrease for zooming out.).',
17
+ schema: c
18
+ });
19
+ export {
20
+ l as goToZoomTool
21
+ };
@@ -0,0 +1,30 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import { tool as n } from "@langchain/core/tools";
3
+ import s from "zod";
4
+ import { f as c } from "./fetchService.js";
5
+ const y = (i, r) => {
6
+ const t = Array.from(i.values()).find(
7
+ ({ layerItem: e }) => e.title?.toLowerCase().includes(r.toLowerCase())
8
+ );
9
+ if (!t) {
10
+ const e = Array.from(i.values()).map((o) => o.layerItem.title).join(", ");
11
+ return `Could not find a layer matching "${r}". Available layers: ${e}`;
12
+ }
13
+ const l = Array.from(t.fieldRegistry.values()), a = l.map((e) => `- **${e.alias || e.name}** (\`${e.name}\`, ${e.type})${e.description ? `: ${e.description}` : ""}`).join(`
14
+ `);
15
+ return `**${t.layerItem.title}** has ${l.length} field(s):
16
+
17
+ ${a}`;
18
+ }, d = ({ layerTitle: i }, r) => {
19
+ const t = c(r, "layersAndFieldsRegistry");
20
+ return y(t, i);
21
+ }, u = n(d, {
22
+ name: "listLayerFields",
23
+ description: "Lists all fields for a given layer by title. Use ONLY when the user explicitly asks to see fields, columns, or attributes of a specific named layer. Do NOT call this tool for general help questions, capability overviews, or layer listing.",
24
+ schema: s.object({
25
+ layerTitle: s.string().describe("The title or partial title of the layer to list fields for.")
26
+ })
27
+ });
28
+ export {
29
+ u as listLayerFieldsTool
30
+ };
@@ -0,0 +1,22 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import { tool as l } from "@langchain/core/tools";
3
+ import o from "zod";
4
+ import { f } from "./fetchAgentContext.js";
5
+ const i = (a) => {
6
+ const r = a.map?.allLayers.filter((t) => t.type === "feature");
7
+ let e = 0;
8
+ return r?.forEach((t) => {
9
+ const s = t;
10
+ s.featureEffect && (s.featureEffect = null, e++);
11
+ }), e > 0 ? `Cleared filters from ${e} layer(s). View unchanged.` : "No active filters to clear. View unchanged.";
12
+ }, n = async (a, r) => {
13
+ const { mapView: e } = f(r, ["mapView"]);
14
+ return i(e);
15
+ }, p = l(n, {
16
+ name: "clearFilters",
17
+ description: "Clears all feature effects/filters from the map but does NOT change the current view. Use when user says 'clear filters', 'reset filters', 'remove filters', 'show all features', or wants to remove emphasis without navigating anywhere.",
18
+ schema: o.object({})
19
+ });
20
+ export {
21
+ p as clearFiltersTool
22
+ };
@@ -0,0 +1,22 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import { tool as n } from "@langchain/core/tools";
3
+ import i from "zod";
4
+ import { f as l } from "./fetchAgentContext.js";
5
+ const f = async (e) => {
6
+ e.map?.allLayers.filter((t) => t.type === "feature")?.forEach((t) => {
7
+ const s = t;
8
+ s.featureEffect && (s.featureEffect = null);
9
+ });
10
+ const o = e.map.initialViewProperties?.viewpoint?.targetGeometry;
11
+ return o ? (await e.goTo(o), "Cleared all filters and returned to home extent.") : "Cleared all filters. Could not determine home extent.";
12
+ }, p = async (e, r) => {
13
+ const { mapView: a } = l(r, ["mapView"]);
14
+ return await f(a);
15
+ }, h = n(p, {
16
+ name: "resetMap",
17
+ description: "Clears all feature effects/filters from the map AND zooms to the home extent (initial map view). Use when user says 'reset map', 'reset the map', 'start over', or wants to both clear filters and return to the initial view.",
18
+ schema: i.object({})
19
+ });
20
+ export {
21
+ h as resetMapTool
22
+ };
@@ -0,0 +1,109 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import e from "zod";
3
+ import { tool as h } from "@langchain/core/tools";
4
+ import m from "@arcgis/core/layers/support/FeatureEffect.js";
5
+ import b from "@arcgis/core/layers/support/FeatureFilter.js";
6
+ import { g as y, d } from "./types.js";
7
+ import { f as w } from "./fetchAgentContext.js";
8
+ const g = async (t, o, u, n, r, c) => {
9
+ const a = t.map?.allLayers.find((i) => i.id === o);
10
+ if (!a)
11
+ return { success: !1, error: `Layer '${o}' not found.` };
12
+ const s = a.createQuery();
13
+ s.where = u ?? "1=1", n && (s.geometry = n, s.spatialRelationship = "intersects", r && (s.distance = r), c && (s.units = c));
14
+ try {
15
+ const { extent: i, count: l } = await a.queryExtent(s);
16
+ return !i || l === 0 ? {
17
+ success: !1,
18
+ error: `No features found for filter (where: ${s.where}${n ? ", spatial filter used" : ""})`
19
+ } : (await t.goTo(i), { success: !0 });
20
+ } catch (i) {
21
+ return {
22
+ success: !1,
23
+ error: i instanceof Error ? i.message : String(i)
24
+ };
25
+ }
26
+ }, I = async (t, o, u, n, r, c) => {
27
+ const a = o.map?.allLayers.find(
28
+ (f) => f.id === t.layerId
29
+ );
30
+ if (!a)
31
+ return `Could not find target layer with ID: ${t.layerId}`;
32
+ let s;
33
+ if (r) {
34
+ const f = await y(r, o);
35
+ if ("error" in f)
36
+ return f.error;
37
+ s = f.geometry;
38
+ }
39
+ if (a.featureEffect = null, a.featureEffect = new m({
40
+ filter: new b({
41
+ ...t.objectIds?.length ? { objectIds: t.objectIds } : { where: t.where },
42
+ geometry: s,
43
+ spatialRelationship: "intersects",
44
+ distance: r?.distance,
45
+ units: r?.units
46
+ }),
47
+ includedEffect: u,
48
+ excludedEffect: n
49
+ }), a.visible = !0, c)
50
+ return `Applied feature effects to "${a.title ?? t.layerId}" within current map extent.`;
51
+ const i = t.objectIds?.length ? `${a.objectIdField} IN (${t.objectIds.join(",")})` : t.where, l = await g(
52
+ o,
53
+ t.layerId,
54
+ i,
55
+ s,
56
+ r?.distance,
57
+ r?.units
58
+ ), p = a.title ?? t.layerId;
59
+ return l.success ? `Applied feature effects to target layer "${a.title ?? t.layerId}"${r && "layerId" in r ? ` using geometry from layer "${r.layerId}"` : ""}.` : `Applied filter to "${p}" but no features matched. ${l.error}`;
60
+ }, v = async ({
61
+ targetLayer: t,
62
+ geometryFilter: o,
63
+ useCurrentExtent: u,
64
+ includedEffect: n = "drop-shadow(2px, 2px, 2px, gray)",
65
+ excludedEffect: r = "grayscale(100%) opacity(60%) blur(2px)"
66
+ }, c) => {
67
+ const { mapView: a } = w(c, ["mapView"]);
68
+ return await I(t, a, n, r, o, u);
69
+ }, x = e.object({
70
+ layerId: e.string().describe("The layerId of the layer containing the geometry by which to filter."),
71
+ where: e.string().describe("The SQL-92 where clause representing the features from which to filter."),
72
+ distance: e.number().optional().describe("The buffer distance around the geometry."),
73
+ units: d.optional().describe("The units for the distance buffer.")
74
+ }), j = e.object({
75
+ point: e.object({
76
+ x: e.number().describe("X coordinate (longitude) from navigation result"),
77
+ y: e.number().describe("Y coordinate (latitude) from navigation result"),
78
+ spatialReference: e.object({
79
+ wkid: e.number().describe("Spatial reference WKID (e.g., 4326 for WGS84)")
80
+ }).optional().describe("Spatial reference. Defaults to map's spatial reference if not provided.")
81
+ }).describe("Point coordinates from a previous navigation/geocoding result"),
82
+ distance: e.number().optional().describe("Optional buffer distance around the point."),
83
+ units: d.optional().describe("The units for the distance buffer.")
84
+ }), E = e.object({
85
+ targetLayer: e.object({
86
+ layerId: e.string().describe("The layerId of the layer on which to set a feature effect."),
87
+ where: e.string().describe("The SQL-92 where clause representing the features to emphasize."),
88
+ objectIds: e.array(e.number()).optional().describe(
89
+ "Array of objectIds from a previous query result. Use this instead of a where clause when the query returned objectIds (e.g. top N results). If provided, takes precedence over where clause."
90
+ )
91
+ }),
92
+ geometryFilter: e.union([x, j]).optional().describe("Optional geometry-based filtering parameters for spatial queries."),
93
+ useCurrentExtent: e.boolean().optional().describe(
94
+ "Set to true when the previous query used the current map extent as a spatial filter. This ensures the feature effect applies only to features visible in the current view. Default is false."
95
+ ),
96
+ includedEffect: e.string().default("drop-shadow(2px, 2px, 2px, gray)").describe(
97
+ "The effect applied to features that meet the filter requirements. Valid effects include: bloom, blur, brightness, contrast, drop-shadow, grayscale, hue-rotate, invert, opacity, saturate, and sepia. Prefer default unless specified."
98
+ ),
99
+ excludedEffect: e.string().default("grayscale(100%) opacity(60%) blur(2px)").describe(
100
+ "The effect applied to features that do not meet the filter requirements. Valid effects include: bloom, blur, brightness, contrast, drop-shadow, grayscale, hue-rotate, invert, opacity, saturate, and sepia. Prefer default unless specified."
101
+ )
102
+ }), A = h(v, {
103
+ name: "setFeatureEffect",
104
+ description: "Sets a feature effect on a given layer with given filter parameters and feature effects to emphasize certain features that meet a filter requirement. If no feature effect information is provided, then use the default effect provided.",
105
+ schema: E
106
+ });
107
+ export {
108
+ A as setFeatureEffectTool
109
+ };
@@ -0,0 +1,40 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import { tool as f } from "@langchain/core/tools";
3
+ import i from "zod";
4
+ import { f as h, g } from "./formatFeatureAttributes.js";
5
+ import { f as y } from "./fetchAgentContext.js";
6
+ const b = (a, e, o) => {
7
+ const t = a.createQuery();
8
+ return t.outFields = [e], t.where = o || "1=1", t.num = 1, t;
9
+ }, d = async (a, e, o, t) => {
10
+ const r = t.map?.allLayers.find((m) => m.id === a), n = b(r, e, o.where), u = (await r.queryFeatures(n)).features[0], c = u ? u.attributes[e] : null, l = h(r, e, c, t.timeZone), s = g(r, e);
11
+ return {
12
+ tool: "getAttribute",
13
+ layerName: r.title ?? a,
14
+ summary: `${s} = ${l}`,
15
+ details: {
16
+ fieldName: e,
17
+ fieldAlias: s !== e ? s : void 0,
18
+ value: l,
19
+ where: o.where
20
+ }
21
+ };
22
+ };
23
+ async function p({ layerId: a, fieldName: e, query: o }, t) {
24
+ const { mapView: r } = y(t, ["mapView"]), n = await d(a, e, o, r);
25
+ return JSON.stringify(n, null, 2);
26
+ }
27
+ const w = i.object({
28
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
29
+ fieldName: i.string().describe("The name of the field/attribute from which to get a field value."),
30
+ query: i.object({
31
+ where: i.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")
32
+ })
33
+ }), Q = f(p, {
34
+ name: "getAttribute",
35
+ description: "Returns an attribute value for a given feature.",
36
+ schema: w
37
+ });
38
+ export {
39
+ Q as getAttributeTool
40
+ };
@@ -0,0 +1,154 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import { tool as L } from "@langchain/core/tools";
3
+ import t from "zod";
4
+ import V from "@arcgis/core/smartMapping/statistics/summaryStatistics.js";
5
+ import E from "@arcgis/core/smartMapping/statistics/uniqueValues.js";
6
+ import O from "@arcgis/core/layers/support/FeatureFilter.js";
7
+ import { c as x, m as b } from "./mergeWhereClauses.js";
8
+ import { g as N, i as v, a as C, d as S } from "./types.js";
9
+ import { f as R } from "./fetchAgentContext.js";
10
+ import { f as U } from "./fetchService.js";
11
+ const W = async (h) => {
12
+ const { targetLayer: r, fieldName: n, statisticType: l, mapView: a, layersAndFieldsRegistry: p, geometryFilter: e } = h, s = a.map?.allLayers.find((i) => i.id === r.layerId);
13
+ if (!s)
14
+ throw new Error(`Layer '${r.layerId}' not found.`);
15
+ const T = await a.whenLayerView(s), o = p.get(r.layerId)?.fieldRegistry.get(n), I = o?.alias;
16
+ if (!o)
17
+ throw new Error(`Field '${n}' not found.`);
18
+ let w, u;
19
+ if (e) {
20
+ const i = await N(e, a);
21
+ if ("error" in i)
22
+ throw new Error(i.error);
23
+ if (!i.geometry)
24
+ throw v(e) ? new Error(`No features found matching: ${e.where}`) : new Error("Failed to create geometry");
25
+ if (v(e)) {
26
+ const g = a.map?.allLayers.find((f) => f.id === e.layerId);
27
+ w = {
28
+ geometryLayerName: g?.title ?? g?.id,
29
+ geometryLayerId: e.layerId,
30
+ geometryWhere: e.where,
31
+ distance: e.distance,
32
+ units: e.units,
33
+ applied: !0
34
+ };
35
+ } else C(e) && (w = {
36
+ point: e.point,
37
+ distance: e.distance,
38
+ units: e.units,
39
+ applied: !0
40
+ });
41
+ u = new O({
42
+ geometry: i.geometry,
43
+ distance: e.distance,
44
+ units: e.units,
45
+ spatialRelationship: "intersects"
46
+ });
47
+ }
48
+ const y = x(T, [n], !1);
49
+ let d = null, m = null;
50
+ const F = 10;
51
+ if (o.type !== "geometry" && o.type !== "oid" && o.type !== "global-id")
52
+ try {
53
+ const i = {
54
+ layer: s,
55
+ useFeaturesInView: y,
56
+ view: y ? a : void 0,
57
+ field: n,
58
+ sqlWhere: b(s.definitionExpression, r.where),
59
+ ...u && { filter: u },
60
+ outStatisticTypes: { include: [l] }
61
+ };
62
+ d = await V(i);
63
+ const g = ["string", "small-integer", "integer"], f = o.domain?.type === "coded-value" ? o.domain : null;
64
+ (g.includes(o.type) || f) && (m = (await E({
65
+ layer: s,
66
+ useFeaturesInView: y,
67
+ view: y ? a : void 0,
68
+ field: n,
69
+ sqlWhere: b(s.definitionExpression, r.where),
70
+ ...u && { filter: u }
71
+ })).uniqueValueInfos.sort((c, q) => q.count - c.count).slice(0, F)), m && o.domain?.type === "coded-value" && (m = m.map((c) => ({
72
+ ...c,
73
+ value: f ? f.getName(c.value) ?? c.value : c.value
74
+ })));
75
+ } catch (i) {
76
+ console.error("Statistics error:", i);
77
+ }
78
+ return {
79
+ tool: "getStatistics",
80
+ layerName: s.title ?? r.layerId,
81
+ summary: `${l} = ${typeof d?.[l] == "number" ? d[l] : "N/A"}`,
82
+ details: {
83
+ fieldName: n,
84
+ fieldAlias: I,
85
+ statisticType: l,
86
+ statistic: d?.[l] ?? null,
87
+ summaryStatistics: d,
88
+ uniqueValues: m,
89
+ where: r.where,
90
+ spatialFilterInfo: w
91
+ }
92
+ };
93
+ };
94
+ async function j({
95
+ targetLayer: h,
96
+ fieldName: r,
97
+ statisticType: n,
98
+ geometryFilter: l
99
+ }, a) {
100
+ const p = U(a, "layersAndFieldsRegistry"), { mapView: e } = R(a, ["mapView"]), s = await W({
101
+ targetLayer: h,
102
+ fieldName: r,
103
+ statisticType: n,
104
+ mapView: e,
105
+ layersAndFieldsRegistry: p,
106
+ geometryFilter: l
107
+ });
108
+ return JSON.stringify(s, null, 2);
109
+ }
110
+ const A = t.object({
111
+ layerId: t.string().describe("The layerId of the layer containing the geometry by which to filter."),
112
+ where: t.string().describe("The SQL-92 where clause representing the features from which to filter."),
113
+ distance: t.number().optional().describe("The buffer distance around the geometry."),
114
+ units: S.optional().describe("The units for the distance buffer.")
115
+ }), G = t.object({
116
+ point: t.object({
117
+ x: t.number().describe("X coordinate (longitude) from navigation result"),
118
+ y: t.number().describe("Y coordinate (latitude) from navigation result"),
119
+ spatialReference: t.object({
120
+ wkid: t.number().describe("Spatial reference WKID (e.g., 4326 for WGS84)")
121
+ }).optional().describe("Spatial reference. Defaults to map's spatial reference if not provided.")
122
+ }).describe("Point coordinates from a previous navigation/geocoding result"),
123
+ distance: t.number().optional().describe("Optional buffer distance around the point."),
124
+ units: S.optional().describe("The units for the distance buffer.")
125
+ }), D = t.object({
126
+ targetLayer: t.object({
127
+ layerId: t.string().describe("The layerId of the layer containing the field from which to get a value."),
128
+ where: t.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")
129
+ }),
130
+ geometryFilter: t.union([A, G]).optional().describe(
131
+ "Geometry filter for spatial queries. Use 'point' option with x/y coordinates from navigation results to find features at that location (point-in-polygon). Use 'layerId/where' option to filter by features from another layer."
132
+ ),
133
+ fieldName: t.string().describe("The name of the field for which to get statistics. STRICTLY DO NOT use OBJECTID. Use any other field"),
134
+ statisticType: t.enum(["avg", "max", "median", "min", "stddev", "sum", "variance", "nullcount", "count"]).describe("The statistic type to calculate.")
135
+ }), M = L(j, {
136
+ name: "getStatistics",
137
+ description: `Computes a single aggregate statistic (max, min, avg, sum, median, stddev, variance) for a numeric field across matching features. Also returns frequency analysis for categorical fields.
138
+
139
+ USE THIS TOOL FOR:
140
+ - "What is the average/maximum/minimum/total [field]?" — aggregate computations
141
+ - "Most common/frequent value of [field]?" — frequency analysis
142
+ - Questions requiring a mathematical aggregation across many features
143
+
144
+ DO NOT USE FOR:
145
+ - "How many features match X?" — use queryFeatures instead (it returns totalCount)
146
+ - "Show / list / find features" — use queryFeatures instead
147
+ - Simple counts of features matching a condition — use queryFeatures instead
148
+
149
+ Only call this tool when the answer requires computing an aggregate (avg, max, min, sum, median, stddev) over a field's values, not just counting or listing features.`,
150
+ schema: D
151
+ });
152
+ export {
153
+ M as getStatisticsTool
154
+ };
@@ -0,0 +1,141 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import { tool as T } from "@langchain/core/tools";
3
+ import e from "zod";
4
+ import S from "@arcgis/core/rest/support/TopFeaturesQuery.js";
5
+ import B from "@arcgis/core/rest/support/TopFilter.js";
6
+ import { m as C, c as v } from "./mergeWhereClauses.js";
7
+ import { a as I } from "./formatFeatureAttributes.js";
8
+ import { g as q, d as y } from "./types.js";
9
+ import { f as N } from "./fetchAgentContext.js";
10
+ const k = (i) => i.flatMap((t) => t.split(",")).map((t) => t.trim()).map((t) => t.split(/\s+/u)[0]?.replace(/^"|"$/gu, "")).filter((t) => !!t), x = async (i, t, a, s, l) => {
11
+ const n = a.map?.allLayers.find((o) => o.id === i.layerId), d = await a.whenLayerView(n), c = n.title ?? i.layerId;
12
+ let u;
13
+ if (s) {
14
+ const o = await q(s, a);
15
+ if ("error" in o)
16
+ return {
17
+ tool: "getTopFeatures",
18
+ layerName: c,
19
+ summary: "Geometry lookup failed",
20
+ details: { error: o.error }
21
+ };
22
+ if (!o.geometry)
23
+ return {
24
+ tool: "getTopFeatures",
25
+ layerName: c,
26
+ summary: "No features found for geometry filter",
27
+ details: {
28
+ error: `No features found matching: ${"where" in s ? s.where : "unknown criteria"}`
29
+ }
30
+ };
31
+ u = o.geometry;
32
+ } else l && (u = a.extent.clone());
33
+ const h = t.groupByFields && t.groupByFields.length > 0, f = n.objectIdField, p = i.outFields.includes("*") ? ["*"] : [.../* @__PURE__ */ new Set([...i.outFields, f])];
34
+ try {
35
+ let o;
36
+ if (h) {
37
+ const r = new S({
38
+ where: i.where || "1=1",
39
+ outFields: p,
40
+ orderByFields: i.orderByFields,
41
+ geometry: u,
42
+ spatialRelationship: u ? "intersects" : void 0,
43
+ distance: s?.distance,
44
+ units: s?.units,
45
+ topFilter: new B({
46
+ topCount: t.topCount,
47
+ groupByFields: t.groupByFields,
48
+ orderByFields: t.orderByFields
49
+ })
50
+ });
51
+ o = await n.queryTopFeatures(r);
52
+ } else {
53
+ const r = n.createQuery();
54
+ r.where = C(n.definitionExpression, i.where || "1=1"), r.outFields = p.length ? p : ["*"], r.orderByFields = t.orderByFields, r.returnGeometry = !1, r.num = t.topCount, u && (r.geometry = u, r.spatialRelationship = "intersects"), s?.distance && (r.distance = s.distance), s?.units && (r.units = s.units), r.outSpatialReference = a.spatialReference;
55
+ const m = [
56
+ .../* @__PURE__ */ new Set([...i.outFields, ...k(t.orderByFields)])
57
+ ], w = v(d, m, l ?? !1);
58
+ try {
59
+ o = w ? await d.queryFeatures(r) : await n.queryFeatures(r);
60
+ } catch (F) {
61
+ console.warn("Client-side query failed, falling back to server:", F), o = await n.queryFeatures(r);
62
+ }
63
+ }
64
+ const g = o.features.map((r) => r.attributes[f]), { attributes: b } = I(n, o, a.timeZone);
65
+ return {
66
+ tool: "getTopFeatures",
67
+ layerName: c,
68
+ summary: `Top ${t.topCount} features extracted`,
69
+ details: {
70
+ topCount: t.topCount,
71
+ attributes: b,
72
+ objectIds: g,
73
+ objectIdField: f,
74
+ where: i.where,
75
+ orderByFields: t.orderByFields,
76
+ ...h && { groupByFields: t.groupByFields }
77
+ }
78
+ };
79
+ } catch (o) {
80
+ return {
81
+ tool: "getTopFeatures",
82
+ layerName: c,
83
+ summary: "Query failed",
84
+ details: { error: o instanceof Error ? o.message : String(o) }
85
+ };
86
+ }
87
+ }, j = async ({
88
+ targetLayer: i,
89
+ topFilter: t,
90
+ geometryFilter: a,
91
+ useCurrentExtent: s
92
+ }, l) => {
93
+ const { mapView: n } = N(l, ["mapView"]), d = await x(i, t, n, a, s);
94
+ return JSON.stringify(d, null, 2);
95
+ }, G = e.object({
96
+ layerId: e.string().describe("The layerId of the layer containing the geometry by which to filter."),
97
+ where: e.string().describe("The SQL-92 where clause representing the features from which to filter."),
98
+ distance: e.number().optional().describe("The buffer distance around the geometry."),
99
+ units: y.optional().describe("The units for the distance buffer.")
100
+ }), R = e.object({
101
+ point: e.object({
102
+ x: e.number().describe("X coordinate (longitude) from navigation result"),
103
+ y: e.number().describe("Y coordinate (latitude) from navigation result"),
104
+ spatialReference: e.object({
105
+ wkid: e.number().describe("Spatial reference WKID (e.g., 4326 for WGS84)")
106
+ }).optional().describe("Spatial reference. Defaults to map's spatial reference if not provided.")
107
+ }).describe("Point coordinates from a previous navigation/geocoding result"),
108
+ distance: e.number().optional().describe("Optional buffer distance around the point."),
109
+ units: y.optional().describe("The units for the distance buffer.")
110
+ }), Q = e.object({
111
+ targetLayer: e.object({
112
+ layerId: e.string().describe("The layerId of the layer containing the field from which to get a value."),
113
+ where: e.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),
114
+ orderByFields: e.array(e.string().describe("The field(s) and order for which to sort the resulting features.")),
115
+ outFields: e.array(
116
+ e.string().describe(
117
+ 'The fields to include in the output that will be presented to the user. This should include identifying information about the resulting features, like a name or id, along with the values desired in the output. If unsure, choose all fields ("*").'
118
+ ).default("*")
119
+ )
120
+ }),
121
+ geometryFilter: e.union([G, R]).optional().describe(
122
+ "Geometry filter for spatial queries. Use 'point' option with x/y coordinates from navigation results to find features at that location (point-in-polygon). Use 'layerId/where' option to filter by features from another layer."
123
+ ),
124
+ topFilter: e.object({
125
+ topCount: e.number().describe("Number of top features to return per group."),
126
+ orderByFields: e.array(
127
+ e.string().describe("Field(s) to rank by with ASC/DESC. Must be existing field names, not aggregate functions.")
128
+ ),
129
+ groupByFields: e.array(e.string().describe("Field(s) to group results by. Returns top N per group."))
130
+ }).required(),
131
+ useCurrentExtent: e.boolean().optional().describe(
132
+ "Set to true ONLY when user explicitly asks about features 'in my view', 'on my map', 'I am looking at'. Default is false (queries entire layer)."
133
+ )
134
+ }), z = T(j, {
135
+ name: "getTopFeatures",
136
+ description: 'Returns top N features ranked by an existing field value. Use for "highest", "lowest", "top N" questions where ranking is based on a field that already exists in the data (e.g., population, value, date, depth). orderByFields must be actual field names with ASC/DESC. Do NOT use aggregate functions like COUNT(), SUM(), AVG() - those require getStatistics.',
137
+ schema: Q
138
+ });
139
+ export {
140
+ z as getTopFeaturesTool
141
+ };