@arcgis/ai-agents 5.0.0-next.133

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 (234) hide show
  1. package/LICENSE.md +17 -0
  2. package/README.md +11 -0
  3. package/dist/agents/dataExploration/context/dataExplorationContext.d.ts +8 -0
  4. package/dist/agents/dataExploration/context/getDataExplorationContext.d.ts +3 -0
  5. package/dist/agents/dataExploration/graph/dataExplorationGraph.d.ts +8 -0
  6. package/dist/agents/dataExploration/index.d.ts +2 -0
  7. package/dist/agents/dataExploration/nodes/dataExplorationExit.d.ts +3 -0
  8. package/dist/agents/dataExploration/nodes/fieldStatistics.d.ts +3 -0
  9. package/dist/agents/dataExploration/nodes/layerFilterLLM.d.ts +3 -0
  10. package/dist/agents/dataExploration/nodes/layerFilterToolCalling.d.ts +3 -0
  11. package/dist/agents/dataExploration/nodes/layerQueryLLM.d.ts +3 -0
  12. package/dist/agents/dataExploration/nodes/layerQueryToolCalling.d.ts +3 -0
  13. package/dist/agents/dataExploration/nodes/requireDataExplorationServices.d.ts +7 -0
  14. package/dist/agents/dataExploration/nodes/summarizeQueryResponseLLM.d.ts +3 -0
  15. package/dist/agents/dataExploration/nodes/vectorSearchFields.d.ts +3 -0
  16. package/dist/agents/dataExploration/nodes/vectorSearchLayers.d.ts +3 -0
  17. package/dist/agents/dataExploration/state/dataExplorationState.d.ts +12 -0
  18. package/dist/agents/dataExploration/tools/filterTools/setDefinitionExpression/adapter.d.ts +22 -0
  19. package/dist/agents/dataExploration/tools/filterTools/setDefinitionExpression/core.d.ts +1 -0
  20. package/dist/agents/dataExploration/tools/filterTools/setDefinitionExpression/index.d.ts +1 -0
  21. package/dist/agents/dataExploration/tools/filterTools/setFeatureEffect/adapter.d.ts +99 -0
  22. package/dist/agents/dataExploration/tools/filterTools/setFeatureEffect/core.d.ts +5 -0
  23. package/dist/agents/dataExploration/tools/filterTools/setFeatureEffect/index.d.ts +1 -0
  24. package/dist/agents/dataExploration/tools/filterTools/setFeatureFilter/adapter.d.ts +87 -0
  25. package/dist/agents/dataExploration/tools/filterTools/setFeatureFilter/core.d.ts +5 -0
  26. package/dist/agents/dataExploration/tools/filterTools/setFeatureFilter/index.d.ts +1 -0
  27. package/dist/agents/dataExploration/tools/index.d.ts +553 -0
  28. package/dist/agents/dataExploration/tools/queryTools/getAttribute/adapter.d.ts +44 -0
  29. package/dist/agents/dataExploration/tools/queryTools/getAttribute/core.d.ts +4 -0
  30. package/dist/agents/dataExploration/tools/queryTools/getAttribute/index.d.ts +1 -0
  31. package/dist/agents/dataExploration/tools/queryTools/getStatistics/adapter.d.ts +90 -0
  32. package/dist/agents/dataExploration/tools/queryTools/getStatistics/core.d.ts +14 -0
  33. package/dist/agents/dataExploration/tools/queryTools/getStatistics/index.d.ts +1 -0
  34. package/dist/agents/dataExploration/tools/queryTools/getTopFeatures/adapter.d.ts +131 -0
  35. package/dist/agents/dataExploration/tools/queryTools/getTopFeatures/core.d.ts +15 -0
  36. package/dist/agents/dataExploration/tools/queryTools/getTopFeatures/index.d.ts +1 -0
  37. package/dist/agents/dataExploration/tools/queryTools/queryFeatures/adapter.d.ts +175 -0
  38. package/dist/agents/dataExploration/tools/queryTools/queryFeatures/core.d.ts +7 -0
  39. package/dist/agents/dataExploration/tools/queryTools/queryFeatures/index.d.ts +1 -0
  40. package/dist/agents/dataExploration/types/types.d.ts +27 -0
  41. package/dist/agents/dataExploration/utils/getDomainName.d.ts +2 -0
  42. package/dist/agents/dataExploration/utils/getGeometry.d.ts +8 -0
  43. package/dist/agents/dataExploration/utils/zoomToWhereClause.d.ts +4 -0
  44. package/dist/agents/layerFilter/context/getLayerFilterContext.d.ts +3 -0
  45. package/dist/agents/layerFilter/context/layerFilterContext.d.ts +8 -0
  46. package/dist/agents/layerFilter/graph/layerFilterGraph.d.ts +8 -0
  47. package/dist/agents/layerFilter/index.d.ts +2 -0
  48. package/dist/agents/layerFilter/nodes/fieldStatistics.d.ts +3 -0
  49. package/dist/agents/layerFilter/nodes/layerFilterExit.d.ts +3 -0
  50. package/dist/agents/layerFilter/nodes/layerFilterLLM.d.ts +3 -0
  51. package/dist/agents/layerFilter/nodes/layerFilterToolCalling.d.ts +3 -0
  52. package/dist/agents/layerFilter/nodes/requireLayerFilterServices.d.ts +7 -0
  53. package/dist/agents/layerFilter/nodes/vectorSearchFields.d.ts +3 -0
  54. package/dist/agents/layerFilter/nodes/vectorSearchLayers.d.ts +3 -0
  55. package/dist/agents/layerFilter/state/layerFilterState.d.ts +10 -0
  56. package/dist/agents/layerFilter/tools/index.d.ts +168 -0
  57. package/dist/agents/layerFilter/tools/setDefinitionExpression/adapter.d.ts +22 -0
  58. package/dist/agents/layerFilter/tools/setDefinitionExpression/core.d.ts +1 -0
  59. package/dist/agents/layerFilter/tools/setDefinitionExpression/index.d.ts +1 -0
  60. package/dist/agents/layerFilter/tools/setFeatureEffect/adapter.d.ts +99 -0
  61. package/dist/agents/layerFilter/tools/setFeatureEffect/core.d.ts +5 -0
  62. package/dist/agents/layerFilter/tools/setFeatureEffect/index.d.ts +1 -0
  63. package/dist/agents/layerFilter/tools/setFeatureFilter/adapter.d.ts +87 -0
  64. package/dist/agents/layerFilter/tools/setFeatureFilter/core.d.ts +5 -0
  65. package/dist/agents/layerFilter/tools/setFeatureFilter/index.d.ts +1 -0
  66. package/dist/agents/layerFilter/types/types.d.ts +9 -0
  67. package/dist/agents/layerFilter/utils/getGeometryForFilter.d.ts +12 -0
  68. package/dist/agents/layerFilter/utils/zoomToWhereClause.d.ts +1 -0
  69. package/dist/agents/layerQuery/context/getLayerQueryContext.d.ts +3 -0
  70. package/dist/agents/layerQuery/context/layerQueryContext.d.ts +8 -0
  71. package/dist/agents/layerQuery/graph/layerQueryGraph.d.ts +8 -0
  72. package/dist/agents/layerQuery/index.d.ts +2 -0
  73. package/dist/agents/layerQuery/nodes/fieldStatistics.d.ts +3 -0
  74. package/dist/agents/layerQuery/nodes/layerQueryExit.d.ts +3 -0
  75. package/dist/agents/layerQuery/nodes/layerQueryLLM.d.ts +3 -0
  76. package/dist/agents/layerQuery/nodes/layerQueryToolCalling.d.ts +3 -0
  77. package/dist/agents/layerQuery/nodes/requireLayerQueryServices.d.ts +7 -0
  78. package/dist/agents/layerQuery/nodes/summarizeQueryResponseLLM.d.ts +3 -0
  79. package/dist/agents/layerQuery/nodes/vectorSearchFields.d.ts +3 -0
  80. package/dist/agents/layerQuery/nodes/vectorSearchLayers.d.ts +3 -0
  81. package/dist/agents/layerQuery/state/layerQueryState.d.ts +12 -0
  82. package/dist/agents/layerQuery/tools/getAttribute/adapter.d.ts +44 -0
  83. package/dist/agents/layerQuery/tools/getAttribute/core.d.ts +4 -0
  84. package/dist/agents/layerQuery/tools/getAttribute/index.d.ts +1 -0
  85. package/dist/agents/layerQuery/tools/getStatistics/adapter.d.ts +90 -0
  86. package/dist/agents/layerQuery/tools/getStatistics/core.d.ts +14 -0
  87. package/dist/agents/layerQuery/tools/getStatistics/index.d.ts +1 -0
  88. package/dist/agents/layerQuery/tools/getTopFeatures/adapter.d.ts +131 -0
  89. package/dist/agents/layerQuery/tools/getTopFeatures/core.d.ts +14 -0
  90. package/dist/agents/layerQuery/tools/getTopFeatures/index.d.ts +1 -0
  91. package/dist/agents/layerQuery/tools/index.d.ts +304 -0
  92. package/dist/agents/layerQuery/tools/queryFeatures/adapter.d.ts +93 -0
  93. package/dist/agents/layerQuery/tools/queryFeatures/core.d.ts +7 -0
  94. package/dist/agents/layerQuery/tools/queryFeatures/index.d.ts +1 -0
  95. package/dist/agents/layerQuery/types/types.d.ts +15 -0
  96. package/dist/agents/layerQuery/utils/getGeometryForQuery.d.ts +6 -0
  97. package/dist/agents/layerStyling/context/getLayerStylingContext.d.ts +3 -0
  98. package/dist/agents/layerStyling/context/layerStylingContext.d.ts +8 -0
  99. package/dist/agents/layerStyling/graph/layerStylingGraph.d.ts +8 -0
  100. package/dist/agents/layerStyling/index.d.ts +2 -0
  101. package/dist/agents/layerStyling/nodes/layerFieldInfo.d.ts +3 -0
  102. package/dist/agents/layerStyling/nodes/layerSelectionHITL.d.ts +9 -0
  103. package/dist/agents/layerStyling/nodes/layerStylingExit.d.ts +3 -0
  104. package/dist/agents/layerStyling/nodes/layerStylingLLM.d.ts +3 -0
  105. package/dist/agents/layerStyling/nodes/layerStylingToolCalling.d.ts +3 -0
  106. package/dist/agents/layerStyling/nodes/requireLayerStylingServices.d.ts +7 -0
  107. package/dist/agents/layerStyling/nodes/vectorSearchFields.d.ts +3 -0
  108. package/dist/agents/layerStyling/nodes/vectorSearchLayers.d.ts +3 -0
  109. package/dist/agents/layerStyling/state/layerStylingState.d.ts +11 -0
  110. package/dist/agents/layerStyling/tools/applyChartRenderer/adapter.d.ts +34 -0
  111. package/dist/agents/layerStyling/tools/applyChartRenderer/core.d.ts +10 -0
  112. package/dist/agents/layerStyling/tools/applyChartRenderer/index.d.ts +1 -0
  113. package/dist/agents/layerStyling/tools/applyColorAgeRenderer/adapter.d.ts +34 -0
  114. package/dist/agents/layerStyling/tools/applyColorAgeRenderer/core.d.ts +10 -0
  115. package/dist/agents/layerStyling/tools/applyColorAgeRenderer/index.d.ts +1 -0
  116. package/dist/agents/layerStyling/tools/applyColorRenderer/adapter.d.ts +34 -0
  117. package/dist/agents/layerStyling/tools/applyColorRenderer/core.d.ts +10 -0
  118. package/dist/agents/layerStyling/tools/applyColorRenderer/index.d.ts +1 -0
  119. package/dist/agents/layerStyling/tools/applyColorSizeUnivariateRenderer/adapter.d.ts +34 -0
  120. package/dist/agents/layerStyling/tools/applyColorSizeUnivariateRenderer/core.d.ts +10 -0
  121. package/dist/agents/layerStyling/tools/applyColorSizeUnivariateRenderer/index.d.ts +1 -0
  122. package/dist/agents/layerStyling/tools/applyDotDensityRenderer/adapter.d.ts +28 -0
  123. package/dist/agents/layerStyling/tools/applyDotDensityRenderer/core.d.ts +9 -0
  124. package/dist/agents/layerStyling/tools/applyDotDensityRenderer/index.d.ts +1 -0
  125. package/dist/agents/layerStyling/tools/applyHeatmapRenderer/adapter.d.ts +28 -0
  126. package/dist/agents/layerStyling/tools/applyHeatmapRenderer/core.d.ts +9 -0
  127. package/dist/agents/layerStyling/tools/applyHeatmapRenderer/index.d.ts +1 -0
  128. package/dist/agents/layerStyling/tools/applyPredominanceRenderer/adapter.d.ts +34 -0
  129. package/dist/agents/layerStyling/tools/applyPredominanceRenderer/core.d.ts +10 -0
  130. package/dist/agents/layerStyling/tools/applyPredominanceRenderer/index.d.ts +1 -0
  131. package/dist/agents/layerStyling/tools/applyRelationshipRenderer/adapter.d.ts +28 -0
  132. package/dist/agents/layerStyling/tools/applyRelationshipRenderer/core.d.ts +9 -0
  133. package/dist/agents/layerStyling/tools/applyRelationshipRenderer/index.d.ts +1 -0
  134. package/dist/agents/layerStyling/tools/applySizeAgeRenderer/adapter.d.ts +34 -0
  135. package/dist/agents/layerStyling/tools/applySizeAgeRenderer/core.d.ts +10 -0
  136. package/dist/agents/layerStyling/tools/applySizeAgeRenderer/index.d.ts +1 -0
  137. package/dist/agents/layerStyling/tools/applySizeRenderer/adapter.d.ts +34 -0
  138. package/dist/agents/layerStyling/tools/applySizeRenderer/core.d.ts +10 -0
  139. package/dist/agents/layerStyling/tools/applySizeRenderer/index.d.ts +1 -0
  140. package/dist/agents/layerStyling/tools/applyTypeRenderer/adapter.d.ts +34 -0
  141. package/dist/agents/layerStyling/tools/applyTypeRenderer/core.d.ts +10 -0
  142. package/dist/agents/layerStyling/tools/applyTypeRenderer/index.d.ts +1 -0
  143. package/dist/agents/layerStyling/tools/index.d.ts +71 -0
  144. package/dist/agents/layerStyling/types/types.d.ts +23 -0
  145. package/dist/agents/layerStyling/utils/renderers/chart.d.ts +3 -0
  146. package/dist/agents/layerStyling/utils/renderers/color-age.d.ts +3 -0
  147. package/dist/agents/layerStyling/utils/renderers/color-size-univariate.d.ts +3 -0
  148. package/dist/agents/layerStyling/utils/renderers/color.d.ts +3 -0
  149. package/dist/agents/layerStyling/utils/renderers/dot-density.d.ts +3 -0
  150. package/dist/agents/layerStyling/utils/renderers/heatmap.d.ts +3 -0
  151. package/dist/agents/layerStyling/utils/renderers/predominance.d.ts +3 -0
  152. package/dist/agents/layerStyling/utils/renderers/relationship.d.ts +3 -0
  153. package/dist/agents/layerStyling/utils/renderers/size-age.d.ts +3 -0
  154. package/dist/agents/layerStyling/utils/renderers/size.d.ts +3 -0
  155. package/dist/agents/layerStyling/utils/renderers/type.d.ts +3 -0
  156. package/dist/agents/linkChart/context/getLinkChartContext.d.ts +3 -0
  157. package/dist/agents/linkChart/context/linkChartContext.d.ts +8 -0
  158. package/dist/agents/linkChart/graph/linkChartGraph.d.ts +8 -0
  159. package/dist/agents/linkChart/index.d.ts +2 -0
  160. package/dist/agents/linkChart/nodes/linkChartIntentLLM.d.ts +2 -0
  161. package/dist/agents/linkChart/nodes/linkChartLLM.d.ts +3 -0
  162. package/dist/agents/linkChart/nodes/linkChartToolCalling.d.ts +3 -0
  163. package/dist/agents/linkChart/nodes/requireLinkChartServices.d.ts +6 -0
  164. package/dist/agents/linkChart/state/linkChartState.d.ts +7 -0
  165. package/dist/agents/linkChart/tools/applyLayout/adapter.d.ts +16 -0
  166. package/dist/agents/linkChart/tools/applyLayout/core.d.ts +2 -0
  167. package/dist/agents/linkChart/tools/applyLayout/index.d.ts +1 -0
  168. package/dist/agents/linkChart/tools/changeNonspatialVisibility/adapter.d.ts +16 -0
  169. package/dist/agents/linkChart/tools/changeNonspatialVisibility/core.d.ts +1 -0
  170. package/dist/agents/linkChart/tools/changeNonspatialVisibility/index.d.ts +1 -0
  171. package/dist/agents/linkChart/tools/index.d.ts +21 -0
  172. package/dist/agents/navigation/context/getNavigationContext.d.ts +3 -0
  173. package/dist/agents/navigation/context/navigationContext.d.ts +8 -0
  174. package/dist/agents/navigation/graph/navigationGraph.d.ts +8 -0
  175. package/dist/agents/navigation/index.d.ts +2 -0
  176. package/dist/agents/navigation/nodes/navigationIntentLLM.d.ts +2 -0
  177. package/dist/agents/navigation/nodes/navigationLLM.d.ts +3 -0
  178. package/dist/agents/navigation/nodes/navigationToolCalling.d.ts +3 -0
  179. package/dist/agents/navigation/nodes/requireNavigationServices.d.ts +7 -0
  180. package/dist/agents/navigation/nodes/vectorSearchFields.d.ts +3 -0
  181. package/dist/agents/navigation/nodes/vectorSearchLayers.d.ts +3 -0
  182. package/dist/agents/navigation/state/navigationState.d.ts +19 -0
  183. package/dist/agents/navigation/tools/goToAddress/adapter.d.ts +16 -0
  184. package/dist/agents/navigation/tools/goToAddress/core.d.ts +1 -0
  185. package/dist/agents/navigation/tools/goToAddress/index.d.ts +1 -0
  186. package/dist/agents/navigation/tools/goToBookmark/adapter.d.ts +16 -0
  187. package/dist/agents/navigation/tools/goToBookmark/core.d.ts +1 -0
  188. package/dist/agents/navigation/tools/goToBookmark/index.d.ts +1 -0
  189. package/dist/agents/navigation/tools/goToFeatures/adapter.d.ts +22 -0
  190. package/dist/agents/navigation/tools/goToFeatures/core.d.ts +1 -0
  191. package/dist/agents/navigation/tools/goToFeatures/index.d.ts +1 -0
  192. package/dist/agents/navigation/tools/goToFullExtent/adapter.d.ts +4 -0
  193. package/dist/agents/navigation/tools/goToFullExtent/core.d.ts +1 -0
  194. package/dist/agents/navigation/tools/goToFullExtent/index.d.ts +1 -0
  195. package/dist/agents/navigation/tools/goToHomeExtent/adapter.d.ts +4 -0
  196. package/dist/agents/navigation/tools/goToHomeExtent/core.d.ts +1 -0
  197. package/dist/agents/navigation/tools/goToHomeExtent/index.d.ts +1 -0
  198. package/dist/agents/navigation/tools/goToLayer/adapter.d.ts +23 -0
  199. package/dist/agents/navigation/tools/goToLayer/core.d.ts +1 -0
  200. package/dist/agents/navigation/tools/goToLayer/index.d.ts +1 -0
  201. package/dist/agents/navigation/tools/goToScale/adapter.d.ts +16 -0
  202. package/dist/agents/navigation/tools/goToScale/core.d.ts +1 -0
  203. package/dist/agents/navigation/tools/goToScale/index.d.ts +1 -0
  204. package/dist/agents/navigation/tools/goToViewpoint/adapter.d.ts +52 -0
  205. package/dist/agents/navigation/tools/goToViewpoint/core.d.ts +7 -0
  206. package/dist/agents/navigation/tools/goToViewpoint/index.d.ts +1 -0
  207. package/dist/agents/navigation/tools/goToZoom/adapter.d.ts +16 -0
  208. package/dist/agents/navigation/tools/goToZoom/core.d.ts +1 -0
  209. package/dist/agents/navigation/tools/goToZoom/index.d.ts +1 -0
  210. package/dist/agents/navigation/tools/index.d.ts +107 -0
  211. package/dist/agents/navigation/types/types.d.ts +12 -0
  212. package/dist/data_explore_filter_prompt-CpgEu_mo.js +79 -0
  213. package/dist/data_explore_query_prompt-CtSDS9l_.js +90 -0
  214. package/dist/data_query_prompt-N4YzctpM.js +61 -0
  215. package/dist/index.d.ts +6 -0
  216. package/dist/index.js +3345 -0
  217. package/dist/layer_filter_prompt-0ujK87_y.js +4 -0
  218. package/dist/layer_styling_prompt-ybkb5Jgq.js +71 -0
  219. package/dist/link_chart_intent_prompt-C1t8tzl2.js +19 -0
  220. package/dist/link_chart_tool_prompt-IJcTG4Ya.js +16 -0
  221. package/dist/navigation_intent_prompt-DEERQeWD.js +19 -0
  222. package/dist/navigation_tool_prompt-C2jIBkeu.js +27 -0
  223. package/dist/summarize_query_response_prompt-DBJy1AAu.js +30 -0
  224. package/dist/types/types.d.ts +6 -0
  225. package/dist/utils/contextSelectors.d.ts +17 -0
  226. package/dist/utils/fetchService.d.ts +6 -0
  227. package/dist/utils/fieldStatistics.d.ts +3 -0
  228. package/dist/utils/getFieldStatistics.d.ts +3 -0
  229. package/dist/utils/getPrompt.d.ts +1 -0
  230. package/dist/utils/requireAgentServices.d.ts +9 -0
  231. package/dist/utils/timeZone.d.ts +8 -0
  232. package/dist/utils/toolCallResponse.d.ts +3 -0
  233. package/dist/utils/useClientSide.d.ts +6 -0
  234. package/package.json +28 -0
package/dist/index.js ADDED
@@ -0,0 +1,3345 @@
1
+ import { Annotation as g, messagesStateReducer as j, StateGraph as _, START as M, END as x, NodeInterrupt as Oe } from "@langchain/langgraph/web";
2
+ import { invokeToolPrompt as N, sendTraceMessage as m, invokeStructuredPrompt as we, invokeTextPrompt as be, sendUXSuggestion as E } from "@arcgis/ai-orchestrator";
3
+ import { tool as f } from "@langchain/core/tools";
4
+ import Pe from "@arcgis/core/Graphic.js";
5
+ import J from "@arcgis/core/geometry/Point.js";
6
+ import Se from "@arcgis/core/geometry/Extent.js";
7
+ import Be from "@arcgis/core/symbols/SimpleMarkerSymbol.js";
8
+ import { addressToLocations as Ge } from "@arcgis/core/rest/locator.js";
9
+ import i, { z as q } from "zod";
10
+ import { HumanMessage as ve, AIMessage as B } from "@langchain/core/messages";
11
+ import { ToolNode as A } from "@langchain/langgraph/prebuilt";
12
+ import Te from "@arcgis/core/layers/support/FeatureEffect.js";
13
+ import V from "@arcgis/core/layers/support/FeatureFilter.js";
14
+ import * as Y from "@arcgis/core/geometry/operators/unionOperator.js";
15
+ import X from "@arcgis/core/smartMapping/statistics/summaryStatistics.js";
16
+ import ee from "@arcgis/core/smartMapping/statistics/uniqueValues.js";
17
+ import xe from "@arcgis/core/rest/support/TopFeaturesQuery.js";
18
+ import Ee from "@arcgis/core/rest/support/TopFilter.js";
19
+ import te from "@arcgis/core/rest/support/Query.js";
20
+ import * as We from "@arcgis/core/geometry/operators/bufferOperator.js";
21
+ import { createRenderer as Ue } from "@arcgis/core/smartMapping/renderers/pieChart.js";
22
+ import { getSchemesByTag as He, getSchemes as Ze } from "@arcgis/core/smartMapping/symbology/pieChart.js";
23
+ import { getBackgroundColorTheme as de } from "@arcgis/core/views/support/colorUtils.js";
24
+ import { createAgeRenderer as Ke, createContinuousRenderer as Je } from "@arcgis/core/smartMapping/renderers/color.js";
25
+ import { getSchemesByTag as re } from "@arcgis/core/smartMapping/symbology/color.js";
26
+ import { createContinuousRenderer as Ye } from "@arcgis/core/smartMapping/renderers/univariateColorSize.js";
27
+ import { createRenderer as Xe } from "@arcgis/core/smartMapping/renderers/dotDensity.js";
28
+ import { getSchemesByTag as et } from "@arcgis/core/smartMapping/symbology/dotDensity.js";
29
+ import { createRenderer as tt } from "@arcgis/core/smartMapping/renderers/heatmap.js";
30
+ import { getSchemesByTag as rt } from "@arcgis/core/smartMapping/symbology/heatmap.js";
31
+ import { createRenderer as at } from "@arcgis/core/smartMapping/renderers/predominance.js";
32
+ import { getSchemesByTag as ot } from "@arcgis/core/smartMapping/symbology/predominance.js";
33
+ import { createRenderer as st } from "@arcgis/core/smartMapping/renderers/relationship.js";
34
+ import { getSchemesByTag as it } from "@arcgis/core/smartMapping/symbology/relationship.js";
35
+ import { createAgeRenderer as nt, createContinuousRenderer as lt } from "@arcgis/core/smartMapping/renderers/size.js";
36
+ import { createRenderer as ct } from "@arcgis/core/smartMapping/renderers/type.js";
37
+ import { getSchemesByTag as dt } from "@arcgis/core/smartMapping/symbology/type.js";
38
+ const $e = g.Root({
39
+ // messages: comes from global chat history.
40
+ // It is safe to append new messages locally, but existing message objects
41
+ // must be treated as read-only and never mutated.
42
+ messages: g({
43
+ reducer: j,
44
+ default: () => []
45
+ }),
46
+ // Accumulates user-visible output across graph nodes.
47
+ // Uses append semantics, but de-duplicates identical consecutive writes.
48
+ // This avoids duplicate output when tool nodes and final LLM nodes
49
+ // emit the same text during a single agent turn.
50
+ outputMessage: g({
51
+ reducer: (e = "", r) => {
52
+ const t = typeof r == "string" ? r.trim() : "";
53
+ if (!t)
54
+ return e;
55
+ const a = e.trim();
56
+ if (!a)
57
+ return t;
58
+ if (a === t)
59
+ return e;
60
+ const o = a.split(`
61
+
62
+ `);
63
+ return o[o.length - 1]?.trim() === t ? e : `${e}
64
+
65
+ ${t}`;
66
+ },
67
+ default: () => ""
68
+ }),
69
+ intent: g({
70
+ reducer: (e, r) => r
71
+ }),
72
+ vectorSearchLayerResults: g({
73
+ reducer: (e, r) => r,
74
+ default: () => []
75
+ }),
76
+ vectorSearchFieldResults: g({
77
+ reducer: (e, r) => r
78
+ })
79
+ });
80
+ async function ut(e, r) {
81
+ const t = "https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer";
82
+ console.log(`[goToAddress] Geocoding: ${e}`);
83
+ const o = (await Ge(t, {
84
+ address: { SingleLine: e },
85
+ outFields: ["Match_addr"]
86
+ }))?.[0];
87
+ if (!o?.extent)
88
+ throw new Error(`Could not find location for: ${e}`);
89
+ const { xmin: s, ymin: l, xmax: n, ymax: c, spatialReference: d } = o.extent, u = new Se({
90
+ xmin: s,
91
+ ymin: l,
92
+ xmax: n,
93
+ ymax: c,
94
+ spatialReference: d
95
+ }), h = (s + n) / 2, p = (l + c) / 2, y = new J({
96
+ x: h,
97
+ y: p,
98
+ spatialReference: d
99
+ }), w = new Be({
100
+ style: "circle",
101
+ color: "red",
102
+ size: 12
103
+ }), b = new Pe({
104
+ geometry: y,
105
+ symbol: w
106
+ });
107
+ return r.graphics.removeAll(), r.graphics.add(b), await r.goTo(u), `Successfully zoomed to: ${o.address}. Location coordinates: x=${h}, y=${p}, wkid=${d.wkid}`;
108
+ }
109
+ const ht = ["mapView"];
110
+ function R(e) {
111
+ const t = e?.configurable?.context;
112
+ if (!t || typeof t != "object")
113
+ throw new Error("NavigationAgent context missing");
114
+ const a = ht.filter((o) => !(o in t));
115
+ if (a.length)
116
+ throw new Error(`NavigationAgent context missing: ${a.join(", ")}`);
117
+ return t;
118
+ }
119
+ async function mt({ address: e }, r) {
120
+ const { mapView: t } = R(r);
121
+ return await ut(e, t);
122
+ }
123
+ const yt = i.object({
124
+ address: i.string().describe("The full address or place name to locate.")
125
+ }), pt = f(mt, {
126
+ name: "goToAddress",
127
+ description: "Geocodes an address using Esri's World Geocoding Service and zooms the map to that location.",
128
+ schema: yt
129
+ });
130
+ async function gt(e, r) {
131
+ const a = r.map.bookmarks;
132
+ if (!a || a.length === 0)
133
+ throw new Error("No bookmarks found in the map.");
134
+ const o = a.find((l) => l.name === e);
135
+ if (!o)
136
+ throw new Error(`Bookmark with name "${e}" not found.`);
137
+ const s = o.viewpoint;
138
+ if (!s)
139
+ throw new Error(`Bookmark with name "${e}" does not have a valid viewpoint.`);
140
+ return await r.goTo(s), `Navigated to bookmark: ${e}`;
141
+ }
142
+ async function ft({ bookmarkName: e }, r) {
143
+ const { mapView: t } = R(r);
144
+ return await Promise.resolve(gt(e, t));
145
+ }
146
+ const wt = q.object({
147
+ bookmarkName: q.string().describe("The name of the bookmark to navigate to.")
148
+ }), bt = f(ft, {
149
+ name: "goToBookmark",
150
+ description: "Go to the extent of the bookmark with the given name.",
151
+ schema: wt
152
+ });
153
+ async function St(e, r, t) {
154
+ const a = t.map?.allLayers.find((s) => s.id === e);
155
+ if (!a)
156
+ return `Error: Layer with id ${e} not found`;
157
+ const o = a.createQuery();
158
+ o.where = r ?? "1=1";
159
+ try {
160
+ const { extent: s, count: l } = await a.queryExtent(o);
161
+ if (l === 0)
162
+ return `No features found in ${a.title} matching: ${r}`;
163
+ if (s)
164
+ await t.goTo(s);
165
+ else
166
+ return `Error: Unable to determine extent for ${a.title}`;
167
+ return `Successfully zoomed to ${l} feature(s) in ${a.title}`;
168
+ } catch (s) {
169
+ return console.error("Error in goToFeatures:", s), `Error: ${s instanceof Error ? s.message : "Unknown error"}`;
170
+ }
171
+ }
172
+ async function vt({ layerId: e, where: r }, t) {
173
+ const { mapView: a } = R(t);
174
+ return await St(e, r, a);
175
+ }
176
+ const Tt = q.object({
177
+ layerId: q.string().describe("The layerId of the layer to zoom to."),
178
+ where: q.string().describe("The sql-92 where clause used to query features to zoom to")
179
+ }), xt = f(vt, {
180
+ name: "goToFeatures",
181
+ description: "Go to the features that match the given filter related to the given layerId.",
182
+ schema: Tt
183
+ });
184
+ async function Et(e) {
185
+ const t = new Se({
186
+ xmin: -180,
187
+ ymin: -90,
188
+ xmax: 180,
189
+ ymax: 90,
190
+ spatialReference: { wkid: 4326 }
191
+ }).expand(0.7);
192
+ return await e.goTo(t), "Successfully zoomed to world extent";
193
+ }
194
+ async function $t(e, r) {
195
+ const { mapView: t } = R(r);
196
+ return await Et(t);
197
+ }
198
+ const Ft = q.object({}), Rt = f($t, {
199
+ name: "goToFullExtent",
200
+ description: "Zooms the map to the full world extent using Esri's Geocoding Service.",
201
+ schema: Ft
202
+ });
203
+ async function Lt(e) {
204
+ const t = e.map.initialViewProperties?.viewpoint?.targetGeometry;
205
+ if (t)
206
+ await e.goTo(t);
207
+ else
208
+ throw new Error("Initial extent is undefined");
209
+ return "Successfully zoomed to home extent";
210
+ }
211
+ async function It(e, r) {
212
+ const { mapView: t } = R(r);
213
+ return await Lt(t);
214
+ }
215
+ const qt = i.object({}), Ct = f(It, {
216
+ name: "goToHomeExtent",
217
+ description: "Go to the initial web map view extent",
218
+ schema: qt
219
+ });
220
+ async function zt(e, r) {
221
+ await r.when();
222
+ const t = r.map?.allLayers.find((o) => o.id === e);
223
+ if (!t)
224
+ return console.warn(`[goToLayer] No matching FeatureLayer found for: ${e}`), `Could not find layer for: ${e}`;
225
+ console.log(`[goToLayer] Zooming to layer: ${t.title}`);
226
+ const a = t.fullExtent;
227
+ return a ? (await r.goTo(a), t.visible = !0, `Successfully zoomed to: ${t.title ?? ""}`) : "Layer has no defined extent. Cannot zoom to layer.";
228
+ }
229
+ async function Nt({ layerId: e }, r) {
230
+ const { mapView: t } = R(r);
231
+ return await zt(e, t);
232
+ }
233
+ const At = q.object({
234
+ layerId: q.string().describe("The id of the layer to navigate to")
235
+ }), kt = f(Nt, {
236
+ name: "goToLayer",
237
+ description: "Zooms the map view to the full extent of the top matching layer.",
238
+ schema: At
239
+ });
240
+ async function jt(e, r) {
241
+ return await r.goTo({ scale: e }), `Successfully zoomed to: ${e}`;
242
+ }
243
+ async function _t({ scale: e }, r) {
244
+ const { mapView: t } = R(r);
245
+ return await jt(e, t);
246
+ }
247
+ const Mt = i.object({
248
+ scale: i.number().describe("The map scale of the view to go to.")
249
+ }), Vt = f(_t, {
250
+ name: "goToScale",
251
+ description: "Go to the specified view scale.",
252
+ schema: Mt
253
+ });
254
+ async function Dt(e, r, t) {
255
+ const o = {
256
+ target: new J({
257
+ longitude: e.longitude,
258
+ latitude: e.latitude,
259
+ spatialReference: { wkid: 4326 }
260
+ })
261
+ };
262
+ return t?.zoom !== void 0 && (o.zoom = t.zoom), t?.scale !== void 0 && (o.scale = t.scale), await r.goTo(o), `Successfully navigated to: ${[
263
+ `(${e.latitude}°, ${e.longitude}°)`,
264
+ t?.zoom !== void 0 ? `zoom ${t.zoom}` : "",
265
+ t?.scale !== void 0 ? `scale 1:${t.scale}` : ""
266
+ ].filter(Boolean).join(", ")}`;
267
+ }
268
+ async function Qt({
269
+ center: e,
270
+ zoom: r,
271
+ scale: t
272
+ }, a) {
273
+ const { mapView: o } = R(a);
274
+ return await Dt(e, o, { zoom: r, scale: t });
275
+ }
276
+ const Ot = i.object({
277
+ center: i.object({
278
+ longitude: i.number().describe("The longitude (x-coordinate) of the point to navigate to."),
279
+ latitude: i.number().describe("The latitude (y-coordinate) of the point to navigate to.")
280
+ }),
281
+ zoom: i.number().optional().describe("The zoom level. Higher values = more zoomed in."),
282
+ scale: i.number().optional().describe("The map scale. Alternative to zoom. Smaller numbers = more zoomed in.")
283
+ }), Pt = f(Qt, {
284
+ name: "goToViewpoint",
285
+ description: "Go to the specified viewpoint. This can contain a combination of scale, center, zoom, etc.",
286
+ schema: Ot
287
+ });
288
+ async function Bt(e, r) {
289
+ return await r.goTo({ zoom: e }), `Successfully zoomed to: ${e}`;
290
+ }
291
+ async function Gt({ zoom: e }, r) {
292
+ const { mapView: t } = R(r);
293
+ return await Bt(e, t);
294
+ }
295
+ const Wt = i.object({
296
+ zoom: i.number().min(1).max(20).describe("The zoom level of the view to go to.")
297
+ }), Ut = f(Gt, {
298
+ name: "goToZoom",
299
+ 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.).',
300
+ schema: Wt
301
+ }), ae = [
302
+ pt,
303
+ bt,
304
+ xt,
305
+ Rt,
306
+ Ct,
307
+ kt,
308
+ Vt,
309
+ Pt,
310
+ Ut
311
+ ], ue = /* @__PURE__ */ Object.assign({
312
+ "../agents/dataExploration/prompts/data_explore_filter_prompt.md": () => import("./data_explore_filter_prompt-CpgEu_mo.js").then((e) => e.default),
313
+ "../agents/dataExploration/prompts/data_explore_query_prompt.md": () => import("./data_explore_query_prompt-CtSDS9l_.js").then((e) => e.default),
314
+ "../agents/layerFilter/prompts/layer_filter_prompt.md": () => import("./layer_filter_prompt-0ujK87_y.js").then((e) => e.default),
315
+ "../agents/layerQuery/prompts/data_query_prompt.md": () => import("./data_query_prompt-N4YzctpM.js").then((e) => e.default),
316
+ "../agents/layerQuery/prompts/summarize_query_response_prompt.md": () => import("./summarize_query_response_prompt-DBJy1AAu.js").then((e) => e.default),
317
+ "../agents/layerStyling/prompts/layer_styling_prompt.md": () => import("./layer_styling_prompt-ybkb5Jgq.js").then((e) => e.default),
318
+ "../agents/linkChart/prompts/link_chart_intent_prompt.md": () => import("./link_chart_intent_prompt-C1t8tzl2.js").then((e) => e.default),
319
+ "../agents/linkChart/prompts/link_chart_tool_prompt.md": () => import("./link_chart_tool_prompt-IJcTG4Ya.js").then((e) => e.default),
320
+ "../agents/navigation/prompts/navigation_intent_prompt.md": () => import("./navigation_intent_prompt-DEERQeWD.js").then((e) => e.default),
321
+ "../agents/navigation/prompts/navigation_tool_prompt.md": () => import("./navigation_tool_prompt-C2jIBkeu.js").then((e) => e.default)
322
+ });
323
+ async function $(e) {
324
+ const r = Object.entries(ue).find(([t]) => t.endsWith(`/${e}.md`));
325
+ if (console.log(`entry for prompt "${e}":`, r), !r)
326
+ throw new Error(`Prompt not found: ${e}
327
+ Available prompts:
328
+ ${Object.keys(ue).join(`
329
+ `)}`);
330
+ return await r[1]();
331
+ }
332
+ const Ht = (e, r = 3) => e.filter((t) => t instanceof ve).slice(-r), v = (e, r = 3) => {
333
+ const t = e.map((o, s) => o instanceof ve ? s : -1).filter((o) => o !== -1);
334
+ if (t.length === 0)
335
+ return [];
336
+ const a = t.length > r ? t[t.length - r] : t[0];
337
+ return e.slice(a);
338
+ }, L = (e, r = " ") => Ht(e).map((o) => o.content).join(r).trim();
339
+ async function Zt(e, r) {
340
+ const t = await $("navigation_tool_prompt"), { mapView: a } = R(r), o = a.map, s = e.vectorSearchLayerResults?.length > 0 ? e.vectorSearchLayerResults.map(
341
+ (b, T) => `${T + 1}. layerId=${b.id} | title=${b.title ?? ""} | name=${b.name ?? ""} | score=${b.score.toFixed(2)}`
342
+ ).join(`
343
+ `) : "", l = e.vectorSearchFieldResults?.length > 0 ? JSON.stringify(e.vectorSearchFieldResults, null, 2) : "", n = e.intent === "goToBookmark" && o.bookmarks?.length ? `Available bookmarks:
344
+ ${JSON.stringify(o.bookmarks, null, 2)}` : "", c = (e.intent === "goToLayer" || e.intent === "goToFeatures") && e.vectorSearchLayerResults?.length ? `Candidate layers:
345
+ ${s}` : "", d = e.intent === "goToFeatures" && e.vectorSearchFieldResults?.length ? `Candidate fields:
346
+ ${l}` : "", u = {
347
+ intent: e.intent,
348
+ bookmarksSection: n,
349
+ layersSection: c,
350
+ fieldsSection: d,
351
+ currentZoom: a.zoom
352
+ }, h = await N({
353
+ promptText: t,
354
+ messages: v(e.messages),
355
+ inputVariables: u,
356
+ tools: ae
357
+ }), p = [...e.messages, h], w = (h.tool_calls?.length ?? 0) > 0 ? [...p] : [...p, h];
358
+ return { ...e, messages: w };
359
+ }
360
+ async function Kt(e, r) {
361
+ const a = await new A(ae).invoke(
362
+ {
363
+ messages: v(e.messages)
364
+ },
365
+ r
366
+ ), o = a.messages.map((n) => n.text).join(`
367
+ `);
368
+ await m({ text: `Finished executing navigation tool: ${o}` }, r);
369
+ const s = [...e.messages, ...a.messages], l = a.messages.map((n) => n.text).join(`
370
+ `);
371
+ return { ...e, messages: s, outputMessage: l };
372
+ }
373
+ async function Jt(e) {
374
+ const r = await $("navigation_intent_prompt"), a = {
375
+ tools: ae.map((n) => ({
376
+ name: n.name,
377
+ description: n.description,
378
+ schema: n.schema
379
+ })).map(({ name: n, description: c, schema: d }) => `${n}: ${c}, ${JSON.stringify(d)}`).join(`
380
+ `)
381
+ }, o = i.object({
382
+ intent: i.string()
383
+ }), s = await we({
384
+ promptText: r,
385
+ modelTier: "fast",
386
+ messages: v(e.messages),
387
+ inputVariables: a,
388
+ schema: o
389
+ }), l = typeof s.intent == "string" ? s.intent.trim().replace(/^"|"$/gu, "") : "";
390
+ return { ...e, intent: l || "" };
391
+ }
392
+ const S = (e, r) => {
393
+ const a = e?.configurable?.services?.[r];
394
+ if (a == null)
395
+ throw new Error(`${r} missing in config.configurable.services`);
396
+ return a;
397
+ }, Yt = 0.7, Xt = async (e, r) => {
398
+ try {
399
+ const t = L(e.messages);
400
+ await m({ text: `Similarity search to find layers: ${t}` }, r);
401
+ const a = S(r, "layerSearch"), o = S(r, "layersAndFieldsRegistry"), l = (await a.searchLayers({
402
+ text: t,
403
+ minScore: Yt
404
+ })).map(({ id: c, score: d }) => {
405
+ const u = o.get(c)?.layerItem;
406
+ return {
407
+ id: c,
408
+ title: u?.title,
409
+ name: u?.name ?? void 0,
410
+ score: d
411
+ };
412
+ });
413
+ let n;
414
+ return l.length > 0 ? n = `Vector search completed. Matching layers:
415
+ ${l.map((c) => `- layerId=${c.id} | title=${c.title ?? ""} | name=${c.name ?? ""} | score=${c.score.toFixed(2)}`).join(`
416
+ `)}` : n = "Vector search completed. No matching layers found.", await m({ text: n }, r), {
417
+ ...e,
418
+ vectorSearchLayerResults: l
419
+ };
420
+ } catch (t) {
421
+ throw await m(
422
+ { text: `Error during vector search layers: ${t instanceof Error ? t.message : String(t)}` },
423
+ r
424
+ ), t;
425
+ }
426
+ }, he = 0.7, er = 10, tr = async (e, r) => {
427
+ try {
428
+ const t = L(e.messages);
429
+ await m({ text: "Similarity search to find fields" }, r);
430
+ const a = S(r, "fieldSearch"), o = S(r, "layersAndFieldsRegistry"), s = e.vectorSearchLayerResults?.map((d) => d.id) ?? [];
431
+ if (s.length === 0)
432
+ return await m({ text: "No candidate layers for field search" }, r), e;
433
+ const n = (await a.searchFields({
434
+ text: t,
435
+ layerIds: s,
436
+ minScore: he,
437
+ topResults: er
438
+ })).map(({ layerId: d, results: u }) => {
439
+ const h = o.get(d)?.fieldRegistry;
440
+ return {
441
+ layerId: d,
442
+ layerName: o.get(d)?.layerItem.name,
443
+ results: u.map((p) => {
444
+ const y = h?.get(p.name);
445
+ return {
446
+ name: p.name,
447
+ score: p.score,
448
+ type: y?.type,
449
+ alias: y?.alias,
450
+ description: y?.description,
451
+ statistics: y?.statistics
452
+ };
453
+ })
454
+ };
455
+ });
456
+ let c;
457
+ return n.length > 0 ? c = `Vector search completed. Matching layers and fields:
458
+ ${n.map(
459
+ (d) => `${d.layerName ?? d.layerId}:
460
+ ${d.results.map((u) => ` - ${u.name} (${u.score.toFixed(2)})`).join(`
461
+ `)}`
462
+ ).join(`
463
+ `)}` : c = `No vector search field results found for score over ${he}.`, await m({ text: c }, r), {
464
+ ...e,
465
+ vectorSearchFieldResults: n
466
+ };
467
+ } catch (t) {
468
+ throw await m(
469
+ { text: `Error during vector search fields: ${t instanceof Error ? t.message : String(t)}` },
470
+ r
471
+ ), t;
472
+ }
473
+ }, D = (e, r) => (t, a) => {
474
+ const o = a?.configurable?.services;
475
+ for (const s of e)
476
+ if (!o?.[s])
477
+ throw new Error(`${r} requires services.${s} to be available.`);
478
+ return t;
479
+ }, rr = (e, r) => D(["layerSearch", "layersAndFieldsRegistry"], "Navigation Agent")(e, r), ar = () => new _($e).addNode("requireNavigationServices", rr).addNode("intentLLM", Jt).addNode("vectorSearchLayers", Xt).addNode("vectorSearchFields", tr).addNode("agent", Zt).addNode("tools", Kt).addEdge(M, "requireNavigationServices").addEdge("requireNavigationServices", "intentLLM").addConditionalEdges(
480
+ "intentLLM",
481
+ (r) => r.intent === "goToLayer" || r.intent === "goToFeatures" ? "vectorSearchLayers" : "agent",
482
+ {
483
+ vectorSearchLayers: "vectorSearchLayers",
484
+ agent: "agent"
485
+ }
486
+ ).addConditionalEdges(
487
+ "vectorSearchLayers",
488
+ (r) => r.intent === "goToFeatures" ? "vectorSearchFields" : "agent",
489
+ {
490
+ vectorSearchFields: "vectorSearchFields",
491
+ agent: "agent"
492
+ }
493
+ ).addEdge("vectorSearchFields", "agent").addEdge("agent", "tools").addEdge("tools", x), or = String.raw`- **navigation** — Enables users to interact with the map by navigating to specific locations, layers, features, or extents.
494
+ This includes zooming, panning, centering, or geocoding based on user input. The agent is designed to handle explicit map movement requests. NOTE: DO NOT call this agent if the user asks "where is... " or "show me...", that is meant to be handled by another agent.
495
+
496
+ Supported actions:
497
+ - **Zooming**: Adjust the map's zoom level (e.g., "Zoom to level 10", "Zoom in").
498
+ - **Viewpoints**: Navigate to a specific center point with optional zoom or scale (e.g., "Center the map on San Francisco at zoom level 16").
499
+ - **Scales**: Set the map to a specific scale (e.g., "Set the map scale to 1:50,000").
500
+ - **Layers**: Zoom to the full extent of a specific layer (e.g., "Go to the water mains layer").
501
+ - **Features**: Zoom to features in a layer that match a filter (e.g., "Zoom to all schools in the city").
502
+ - **Bookmarks**: Navigate to a predefined bookmark extent (e.g., "Go to the Downtown bookmark").
503
+ - **Extents**: Reset to the initial web map extent or zoom to the full world extent (e.g., "Reset the map", "Zoom to the full world extent").
504
+ - **Addresses**: Zoom to an address or place name (e.g., "Zoom to 1600 Pennsylvania Ave").
505
+
506
+ _Example: “Zoom to Texas”_
507
+ _Example: “Go to the water mains layer”_
508
+ _Example: “Center the map on San Francisco at scale 50000”_
509
+ _Example: “Zoom to the features in the schools layer where city = 'Austin'”_
510
+ _Example: “Go to the Downtown bookmark”_
511
+ _Example: “Zoom to 1600 Pennsylvania Ave”_`, $i = {
512
+ id: "navigation",
513
+ name: "Navigation Agent",
514
+ description: or,
515
+ createGraph: ar,
516
+ workspace: $e
517
+ }, Fe = g.Root({
518
+ // Inputs coming from global context
519
+ messages: g({
520
+ reducer: j,
521
+ default: () => []
522
+ }),
523
+ // Accumulates user-visible output across graph nodes.
524
+ // Uses append semantics, but de-duplicates identical consecutive writes.
525
+ // This avoids duplicate output when tool nodes and final LLM nodes
526
+ // emit the same text during a single agent turn.
527
+ outputMessage: g({
528
+ reducer: (e = "", r) => {
529
+ const t = typeof r == "string" ? r.trim() : "";
530
+ if (!t)
531
+ return e;
532
+ const a = e.trim();
533
+ if (!a)
534
+ return t;
535
+ if (a === t)
536
+ return e;
537
+ const o = a.split(`
538
+
539
+ `);
540
+ return o[o.length - 1]?.trim() === t ? e : `${e}
541
+
542
+ ${t}`;
543
+ },
544
+ default: () => ""
545
+ }),
546
+ vectorSearchLayerIds: g(),
547
+ vectorSearchFieldResults: g(),
548
+ layerFieldInfo: g(),
549
+ queryResponse: g()
550
+ }), sr = async (e, r) => (await m({ text: "Exiting Data Exploration agent" }, r), e), Q = async (e, r) => {
551
+ const t = e.tool_calls ?? [];
552
+ if (t.length === 0) {
553
+ await m({ text: `LLM did not request any tool calls: ${String(e?.content)}` }, r);
554
+ return;
555
+ }
556
+ await Promise.all(
557
+ t.map(
558
+ async (a) => await m(
559
+ { text: `LLM requested tool call with arguments: ${JSON.stringify(a.args, null, 2)}` },
560
+ r
561
+ )
562
+ )
563
+ ), console.log("LLM response:", JSON.stringify(e.tool_calls, null, 2));
564
+ }, oe = async (e, r, t) => {
565
+ const a = e.map?.allLayers.find((s) => s.id === r), o = a.createQuery();
566
+ o.where = t ?? "1=1";
567
+ try {
568
+ const { extent: s, count: l } = await a.queryExtent(o);
569
+ return !s || l === 0 ? {
570
+ success: !1,
571
+ error: `No features found for where clause: ${t}`
572
+ } : (await e.goTo(s), { success: !0 });
573
+ } catch (s) {
574
+ return {
575
+ success: !1,
576
+ error: s instanceof Error ? s.message : String(s)
577
+ };
578
+ }
579
+ }, ir = async (e, r, t) => {
580
+ const a = t.map?.allLayers.find((l) => l.id === e);
581
+ if (!a)
582
+ return `Could not find layer with ID: ${e}`;
583
+ a.definitionExpression = r, a.visible = !0;
584
+ const o = await oe(t, e, r), s = a.title ?? a.layerId;
585
+ return o.success ? `Applied definition expression to layer "${a.title ?? e}": ${r}` : `Applied filter to "${s}" but no features matched. ${o.error}`;
586
+ }, nr = ["mapView"];
587
+ function C(e) {
588
+ const t = e?.configurable?.context;
589
+ if (!t || typeof t != "object")
590
+ throw new Error("DataExplorationAgent context missing");
591
+ const a = nr.filter((o) => !(o in t));
592
+ if (a.length)
593
+ throw new Error(`DataExplorationAgent context missing: ${a.join(", ")}`);
594
+ return t;
595
+ }
596
+ const lr = async ({
597
+ layerId: e,
598
+ definitionExpression: r
599
+ }, t) => {
600
+ const { mapView: a } = C(t);
601
+ return await ir(e, r, a);
602
+ }, cr = i.object({
603
+ layerId: i.string().describe("The layerId of the layer on which to set a definitionExpression."),
604
+ definitionExpression: i.string().describe("The SQL-92 where clause used to set a definition expression on the layer.")
605
+ }), dr = f(lr, {
606
+ name: "setDefinitionExpression",
607
+ description: "Set a SQL-92 where clause to the definition expression of a layer (i.e. a server-side filter). This filters features at the server level, affecting all views of the layer. Do not prioritize this tool unless specifically asked for or implied for server level, affecting all views of the layer.",
608
+ schema: cr
609
+ });
610
+ function H(e) {
611
+ return "point" in e && e.point !== void 0;
612
+ }
613
+ function Z(e) {
614
+ return "layerId" in e && e.layerId !== void 0;
615
+ }
616
+ const O = async (e, r) => {
617
+ if (H(e)) {
618
+ const { point: t } = e;
619
+ return { geometry: new J({
620
+ x: t.x,
621
+ y: t.y,
622
+ spatialReference: t.spatialReference ? { wkid: t.spatialReference.wkid } : r.spatialReference
623
+ }) };
624
+ }
625
+ if (Z(e)) {
626
+ const t = r.map?.allLayers.find(
627
+ (a) => a.id === e.layerId
628
+ );
629
+ if (!t)
630
+ return { error: `Could not find geometry layer with ID: ${e.layerId}` };
631
+ try {
632
+ const a = await t.queryFeatures({
633
+ where: e.where,
634
+ returnGeometry: !0,
635
+ outSpatialReference: r.spatialReference
636
+ });
637
+ if (!a.features.length)
638
+ return {
639
+ error: `No features found in geometry layer with the specified where clause: ${e.where}`
640
+ };
641
+ let o;
642
+ if (a.features.length === 1) {
643
+ const s = a.features[0].geometry;
644
+ if (!s)
645
+ return { error: "The geometry of the first feature is undefined or null." };
646
+ o = s;
647
+ } else {
648
+ const s = a.features.map((n) => n.geometry), l = Y.executeMany(s);
649
+ if (!l)
650
+ return { error: "Failed to create a combined geometry." };
651
+ o = l;
652
+ }
653
+ return o.spatialReference || (o.spatialReference = r.spatialReference), { geometry: o };
654
+ } catch (a) {
655
+ return { error: `Failed to query geometry: ${String(a)}` };
656
+ }
657
+ }
658
+ return { error: "Invalid geometry configuration provided" };
659
+ }, ur = async (e, r, t, a, o) => {
660
+ const s = r.map?.allLayers.find(
661
+ (d) => d.id === e.layerId
662
+ );
663
+ if (!s)
664
+ return `Could not find target layer with ID: ${e.layerId}`;
665
+ let l;
666
+ if (o) {
667
+ const d = await O(o, r);
668
+ if ("error" in d)
669
+ return d.error;
670
+ l = d.geometry;
671
+ }
672
+ s.featureEffect = null, s.featureEffect = new Te({
673
+ filter: new V({
674
+ where: e.where,
675
+ geometry: l,
676
+ spatialRelationship: "intersects",
677
+ distance: o?.distance,
678
+ units: o?.units
679
+ }),
680
+ includedEffect: t,
681
+ excludedEffect: a
682
+ }), s.visible = !0;
683
+ const n = await oe(
684
+ r,
685
+ o ? o.layerId : e.layerId,
686
+ o ? o.where : e.where
687
+ ), c = s.title ?? e.layerId;
688
+ return n.success ? `Applied feature effects to target layer "${s.title ?? e.layerId}"${o ? ` using geometry from layer "${o.layerId}"` : ""}.` : `Applied filter to "${c}" but no features matched. ${n.error}`;
689
+ }, hr = ["feet", "kilometers", "meters", "miles", "nautical-miles", "us-nautical-miles"], z = i.enum(hr), mr = async ({
690
+ targetLayer: e,
691
+ geometryLayer: r,
692
+ includedEffect: t = "drop-shadow(2px, 2px, 2px, gray)",
693
+ excludedEffect: a = "grayscale(100%) opacity(60%) blur(2px)"
694
+ }, o) => {
695
+ const { mapView: s } = C(o);
696
+ return await ur(e, s, t, a, r);
697
+ }, yr = i.object({
698
+ targetLayer: i.object({
699
+ layerId: i.string().describe("The layerId of the layer on which to set a feature effect."),
700
+ where: i.string().describe("The SQL-92 where clause representing the features to emphasize.")
701
+ }),
702
+ geometryLayer: i.object({
703
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
704
+ where: i.string().describe(
705
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
706
+ ),
707
+ distance: i.number().describe("The distance by which to filter the input geometry."),
708
+ units: z.describe("The units used to filter by geometry and distance.")
709
+ }).optional().describe("Optional geometry-based filtering parameters for spatial queries."),
710
+ includedEffect: i.string().optional().default("drop-shadow(2px, 2px, 2px, gray)").describe(
711
+ "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."
712
+ ),
713
+ excludedEffect: i.string().optional().default("grayscale(100%) opacity(60%) blur(2px)").describe(
714
+ "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."
715
+ )
716
+ }), pr = f(mr, {
717
+ name: "setFeatureEffect",
718
+ 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.",
719
+ schema: yr
720
+ }), gr = async (e, r, t) => {
721
+ const a = r.map?.allLayers.find(
722
+ (c) => c.id === e.layerId
723
+ );
724
+ if (!a)
725
+ return `Could not find target layer with ID: ${e.layerId}`;
726
+ let o;
727
+ if (t) {
728
+ const c = await O(t, r);
729
+ if ("error" in c)
730
+ return c.error;
731
+ o = c.geometry;
732
+ }
733
+ const s = await r.whenLayerView(a);
734
+ s.filter = null, s.filter = new V({
735
+ where: e.where,
736
+ geometry: o,
737
+ spatialRelationship: "intersects",
738
+ distance: t?.distance,
739
+ units: t?.units
740
+ }), a.visible = !0;
741
+ const l = await oe(
742
+ r,
743
+ t ? t.layerId : e.layerId,
744
+ t ? t.where : e.where
745
+ ), n = a.title ?? e.layerId;
746
+ return l.success ? `Applied feature filter to layer "${a.title ?? e.layerId}"${t ? ` using geometry from layer "${t.layerId}"` : ""}.` : `Applied filter to "${n}" but no features matched. ${l.error}`;
747
+ }, fr = async ({
748
+ targetLayer: e,
749
+ geometryLayer: r
750
+ }, t) => {
751
+ const { mapView: a } = C(t);
752
+ return await gr(e, a, r);
753
+ }, wr = i.object({
754
+ targetLayer: i.object({
755
+ layerId: i.string().describe("The layerId of the layer on which to set a filter."),
756
+ where: i.string().describe("The SQL-92 where clause representing the features to display.")
757
+ }),
758
+ geometryLayer: i.object({
759
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
760
+ where: i.string().describe(
761
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
762
+ ),
763
+ distance: i.number().describe("The distance by which to filter the input geometry."),
764
+ units: z.describe("The units used to filter by geometry and distance.")
765
+ }).optional().describe("Optional geometry-based filtering parameters for spatial queries.")
766
+ }), br = f(fr, {
767
+ name: "setFeatureFilter",
768
+ description: "Sets a client-side filter using a where clause, geometry filter, or both on a target layer. This filters features at the client level in the view.",
769
+ schema: wr
770
+ }), K = (e, r, t) => {
771
+ if (e && typeof e != "function") {
772
+ const a = "getField" in t && t.getField?.(e), o = a && "getFieldDomain" in t && t.getFieldDomain ? t.getFieldDomain(a.name) : null;
773
+ if (o?.type === "coded-value") {
774
+ const l = o.codedValues.find((n) => n.code === r);
775
+ return l ? l.name : null;
776
+ }
777
+ }
778
+ return null;
779
+ }, Sr = (e, r, t) => {
780
+ const a = e.createQuery();
781
+ return a.outFields = [r], a.where = t || "1=1", a.num = 1, a;
782
+ }, vr = async (e, r, t, a) => {
783
+ const o = a.map?.allLayers.find((h) => h.id === e), s = Sr(o, r, t.where), n = (await o.queryFeatures(s)).features[0], c = n ? n.attributes[r] : null, d = K(r, c, o) || c;
784
+ return {
785
+ tool: "getAttribute",
786
+ layerName: o.title ?? e,
787
+ summary: `${r} = ${d}`,
788
+ details: {
789
+ fieldName: r,
790
+ value: d,
791
+ where: t.where
792
+ }
793
+ };
794
+ };
795
+ async function Tr({ layerId: e, fieldName: r, query: t }, a) {
796
+ const { mapView: o } = C(a), s = await vr(e, r, t, o);
797
+ return JSON.stringify(s, null, 2);
798
+ }
799
+ const xr = i.object({
800
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
801
+ fieldName: i.string().describe("The name of the field/attribute from which to get a field value."),
802
+ query: i.object({
803
+ where: i.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")
804
+ })
805
+ }), Er = f(Tr, {
806
+ name: "getAttribute",
807
+ description: "Returns an attribute value for a given feature.",
808
+ schema: xr
809
+ }), se = (e, r) => r ? e.hasAllFeaturesInView : e.hasAllFeatures, $r = async (e) => {
810
+ const { targetLayer: r, fieldName: t, statisticType: a, mapView: o, layersAndFieldsRegistry: s, geometryLayer: l } = e, n = o.map?.allLayers.find((I) => I.id === r.layerId);
811
+ if (!n)
812
+ throw new Error(`Layer '${r.layerId}' not found.`);
813
+ const c = await o.whenLayerView(n), u = s.get(r.layerId)?.fieldRegistry.get(t);
814
+ if (!u)
815
+ throw new Error(`Field '${t}' not found.`);
816
+ let h, p;
817
+ if (l) {
818
+ const I = await O(l, o);
819
+ if ("error" in I)
820
+ throw new Error(I.error);
821
+ if (!I.geometry)
822
+ throw new Error(`No features found matching: ${l.where}`);
823
+ h = {
824
+ geometryLayerId: l.layerId,
825
+ geometryWhere: l.where,
826
+ distance: l.distance,
827
+ units: l.units,
828
+ applied: !0
829
+ }, p = new V({
830
+ geometry: I.geometry,
831
+ distance: l.distance,
832
+ units: l.units,
833
+ spatialRelationship: "intersects"
834
+ });
835
+ }
836
+ const y = se(c, !1);
837
+ let w = null, b = null;
838
+ const T = 10;
839
+ if (u.type !== "geometry" && u.type !== "oid" && u.type !== "global-id")
840
+ try {
841
+ w = await X({
842
+ layer: n,
843
+ useFeaturesInView: y,
844
+ view: y ? o : void 0,
845
+ field: t,
846
+ sqlWhere: r.where,
847
+ ...p && { filter: p },
848
+ outStatisticTypes: { include: [a] }
849
+ }), ["string", "small-integer", "integer"].includes(u.type) && (b = (await ee({
850
+ layer: n,
851
+ useFeaturesInView: y,
852
+ view: y ? o : void 0,
853
+ field: t,
854
+ sqlWhere: r.where,
855
+ ...p && { filter: p }
856
+ })).uniqueValueInfos.sort((De, Qe) => Qe.count - De.count).slice(0, T));
857
+ } catch (I) {
858
+ console.error("Statistics error:", I);
859
+ }
860
+ return {
861
+ tool: "getStatistics",
862
+ layerName: n.title ?? r.layerId,
863
+ summary: `${a} = ${typeof w?.[a] == "number" ? w[a] : "N/A"}`,
864
+ details: {
865
+ fieldName: t,
866
+ statisticType: a,
867
+ statistic: w?.[a] ?? null,
868
+ summaryStatistics: w,
869
+ uniqueValues: b,
870
+ where: r.where,
871
+ spatialFilterInfo: h
872
+ }
873
+ };
874
+ };
875
+ async function Fr({
876
+ targetLayer: e,
877
+ fieldName: r,
878
+ statisticType: t,
879
+ geometryLayer: a
880
+ }, o) {
881
+ const s = S(o, "layersAndFieldsRegistry"), { mapView: l } = C(o), n = await $r({
882
+ targetLayer: e,
883
+ fieldName: r,
884
+ statisticType: t,
885
+ mapView: l,
886
+ layersAndFieldsRegistry: s,
887
+ geometryLayer: a
888
+ });
889
+ return JSON.stringify(n, null, 2);
890
+ }
891
+ const Rr = i.object({
892
+ targetLayer: i.object({
893
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
894
+ where: i.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")
895
+ }),
896
+ geometryLayer: i.union([
897
+ i.object({
898
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
899
+ where: i.string().describe(
900
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
901
+ ),
902
+ distance: i.number().optional().describe("The distance by which to query from the input geometry."),
903
+ units: z.optional().describe("The units used to query by geometry and distance.")
904
+ }),
905
+ i.object({}).strict()
906
+ ]).optional().describe("Optional geometry-based filtering parameters for spatial queries."),
907
+ fieldName: i.string().describe("The name of the field for which to get statistics. STRICTLY DO NOT use OBJECTID. Use any other field"),
908
+ statisticType: i.enum(["avg", "max", "median", "min", "stddev", "sum", "variance", "nullcount", "count"]).describe("The statistic type to calculate.")
909
+ }), Lr = f(Fr, {
910
+ name: "getStatistics",
911
+ description: 'Returns one or more summary statistics for the given field. Statistic types include: count, maximum, minimum, average, median, standard deviation, variance, mode, sum, nullcount (number of features without a value for a given field), unique values. For "most common/frequent" questions: Use statisticType "count" on a categorical field. The response includes uniqueValues sorted by frequency (most common first). Statistics can be returned for number, date, and string fields. Also returns frequency analysis for string fields - unique values sorted by occurrence count (most frequent first). Use this for "most common", "most frequent", or "how many of each" questions. Only call this tool when the question requires filtering (e.g. a WHERE clause or spatial constraint) that cannot be satisfied by precomputed stats.',
912
+ schema: Rr
913
+ }), Ir = async (e, r, t, a) => {
914
+ const o = t.map?.allLayers.find((u) => u.id === e.layerId), s = await t.whenLayerView(o), l = o.title ?? e.layerId;
915
+ let n;
916
+ if (a) {
917
+ const u = await O(a, t);
918
+ if ("error" in u)
919
+ return {
920
+ tool: "getTopFeatures",
921
+ layerName: l,
922
+ summary: "Geometry lookup failed",
923
+ details: { error: u.error }
924
+ };
925
+ if (!u.geometry)
926
+ return {
927
+ tool: "getTopFeatures",
928
+ layerName: l,
929
+ summary: "No features found for geometry filter",
930
+ details: { error: `No features found matching: ${a.where}` }
931
+ };
932
+ n = u.geometry;
933
+ }
934
+ const c = e.outFields.length > 2 ? e.outFields : ["*"], d = r.groupByFields && r.groupByFields.length > 0;
935
+ try {
936
+ let u;
937
+ if (d) {
938
+ const p = new xe({
939
+ where: e.where || "1=1",
940
+ outFields: c,
941
+ orderByFields: e.orderByFields,
942
+ geometry: n,
943
+ spatialRelationship: n ? "intersects" : void 0,
944
+ distance: a?.distance,
945
+ units: a?.units,
946
+ topFilter: new Ee({
947
+ topCount: r.topCount,
948
+ groupByFields: r.groupByFields,
949
+ orderByFields: r.orderByFields
950
+ })
951
+ });
952
+ u = await o.queryTopFeatures(p);
953
+ } else {
954
+ const p = new te({
955
+ where: e.where || "1=1",
956
+ outFields: c,
957
+ orderByFields: r.orderByFields,
958
+ num: r.topCount,
959
+ geometry: n,
960
+ spatialRelationship: n ? "intersects" : void 0,
961
+ distance: a?.distance,
962
+ units: a?.units,
963
+ outSpatialReference: t.spatialReference
964
+ }), y = se(s, !1);
965
+ try {
966
+ u = y ? await s.queryFeatures(p) : await o.queryFeatures(p);
967
+ } catch (w) {
968
+ console.warn("Client-side query failed, falling back to server:", w), u = await o.queryFeatures(p);
969
+ }
970
+ }
971
+ const h = u.features.map((p) => p.attributes);
972
+ return {
973
+ tool: "getTopFeatures",
974
+ layerName: l,
975
+ summary: `Top ${r.topCount} features extracted`,
976
+ details: {
977
+ topCount: r.topCount,
978
+ attributes: h,
979
+ where: e.where,
980
+ orderByFields: r.orderByFields,
981
+ ...d && { groupByFields: r.groupByFields }
982
+ }
983
+ };
984
+ } catch (u) {
985
+ return {
986
+ tool: "getTopFeatures",
987
+ layerName: l,
988
+ summary: "Query failed",
989
+ details: { error: u instanceof Error ? u.message : String(u) }
990
+ };
991
+ }
992
+ }, qr = async ({
993
+ targetLayer: e,
994
+ topFilter: r,
995
+ geometryLayer: t
996
+ }, a) => {
997
+ const { mapView: o } = C(a), s = await Ir(e, r, o, t);
998
+ return JSON.stringify(s, null, 2);
999
+ }, Cr = i.object({
1000
+ targetLayer: i.object({
1001
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
1002
+ where: i.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),
1003
+ orderByFields: i.array(i.string().describe("The field(s) and order for which to sort the resulting features.")),
1004
+ outFields: i.array(
1005
+ i.string().describe(
1006
+ '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 ("*").'
1007
+ ).default("*")
1008
+ )
1009
+ }),
1010
+ geometryLayer: i.object({
1011
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
1012
+ where: i.string().describe(
1013
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
1014
+ ),
1015
+ distance: i.number().optional().describe("The distance by which to query from the input geometry."),
1016
+ units: z.describe("The units used to query by geometry and distance.").optional()
1017
+ }).optional().describe("Optional geometry-based filtering parameters for spatial queries."),
1018
+ topFilter: i.object({
1019
+ topCount: i.number().describe("Number of top features to return per group."),
1020
+ orderByFields: i.array(
1021
+ i.string().describe("Field(s) to rank by with ASC/DESC. Must be existing field names, not aggregate functions.")
1022
+ ),
1023
+ groupByFields: i.array(i.string().describe("Field(s) to group results by. Returns top N per group."))
1024
+ })
1025
+ }), zr = f(qr, {
1026
+ name: "getTopFeatures",
1027
+ 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.',
1028
+ schema: Cr
1029
+ }), U = 25, Nr = async (e, r, t, a) => {
1030
+ const o = r.map?.allLayers.find((y) => y.id === e.layerId), s = await r.whenLayerView(o), l = o.title ?? e.layerId;
1031
+ let n;
1032
+ if (t) {
1033
+ const y = await O(t, r);
1034
+ if ("error" in y) {
1035
+ const w = { error: y.error };
1036
+ return Z(t) ? (w.geometryLayerId = t.layerId, w.geometryWhere = t.where) : H(t) && (w.point = t.point), {
1037
+ tool: "queryFeatures",
1038
+ layerName: l,
1039
+ summary: "Geometry lookup failed",
1040
+ details: w
1041
+ };
1042
+ }
1043
+ if (!y.geometry) {
1044
+ const w = {};
1045
+ return Z(t) ? (w.error = `No features found matching: ${t.where}`, w.geometryLayerId = t.layerId, w.geometryWhere = t.where) : H(t) && (w.error = "Failed to create point geometry", w.point = t.point), {
1046
+ tool: "queryFeatures",
1047
+ layerName: l,
1048
+ summary: "No features found for geometry filter",
1049
+ details: w
1050
+ };
1051
+ }
1052
+ n = y.geometry;
1053
+ } else a && (n = r.extent.clone());
1054
+ const c = se(s, a ?? !1), d = new te({
1055
+ where: e.where || "1=1",
1056
+ outFields: e.outFields.length ? e.outFields : ["*"],
1057
+ orderByFields: e.orderByFields,
1058
+ ...n && { geometry: n, spatialRelationship: "intersects" },
1059
+ ...t?.distance && { distance: t.distance },
1060
+ ...t?.units && { units: t.units },
1061
+ outSpatialReference: r.spatialReference
1062
+ });
1063
+ let u, h;
1064
+ try {
1065
+ u = c ? await s.queryFeatureCount(d) : await o.queryFeatureCount(d), u > 0 && u <= U && (h = c ? await s.queryFeatures(d) : await o.queryFeatures(d), h && h.features.forEach((y) => {
1066
+ const w = y.attributes;
1067
+ o.fields.forEach((b) => {
1068
+ const T = w[b.name], k = K(b.name, T, o);
1069
+ k && (w[b.name] = k);
1070
+ });
1071
+ }));
1072
+ } catch (y) {
1073
+ console.warn("Client-side query failed, falling back to server:", y), u = await o.queryFeatureCount(d), u > 0 && u <= U && (h = await o.queryFeatures(d), h && h.features.forEach((w) => {
1074
+ o.fields.forEach((b) => {
1075
+ const T = w.attributes[b.name], k = K(b.name, T, o);
1076
+ k && (w.attributes[b.name] = k);
1077
+ });
1078
+ }));
1079
+ }
1080
+ const p = h?.features.map((y) => y.attributes);
1081
+ return {
1082
+ tool: "queryFeatures",
1083
+ layerName: l,
1084
+ summary: `${u} features found`,
1085
+ details: {
1086
+ totalCount: u,
1087
+ where: e.where,
1088
+ ...p && { attributes: p },
1089
+ ...u > U && {
1090
+ note: `${u} features found. Too many to list. Use filters to narrow results.`
1091
+ }
1092
+ }
1093
+ };
1094
+ };
1095
+ async function Ar({
1096
+ targetLayer: e,
1097
+ geometryFilter: r,
1098
+ useCurrentExtent: t
1099
+ }, a) {
1100
+ const { mapView: o } = C(a), s = await Nr(e, o, r, t);
1101
+ return JSON.stringify(s, null, 2);
1102
+ }
1103
+ const kr = i.object({
1104
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
1105
+ where: i.string().describe("The SQL-92 where clause representing the features from which to filter."),
1106
+ distance: i.number().optional().describe("The buffer distance around the geometry."),
1107
+ units: z.optional().describe("The units for the distance buffer.")
1108
+ }), jr = i.object({
1109
+ point: i.object({
1110
+ x: i.number().describe("X coordinate (longitude) from navigation result"),
1111
+ y: i.number().describe("Y coordinate (latitude) from navigation result"),
1112
+ spatialReference: i.object({
1113
+ wkid: i.number().describe("Spatial reference WKID (e.g., 4326 for WGS84)")
1114
+ }).optional().describe("Spatial reference. Defaults to map's spatial reference if not provided.")
1115
+ }).describe("Point coordinates from a previous navigation/geocoding result"),
1116
+ distance: i.number().optional().describe("Optional buffer distance around the point."),
1117
+ units: z.optional().describe("The units for the distance buffer.")
1118
+ }), _r = i.object({
1119
+ targetLayer: i.object({
1120
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
1121
+ where: i.string().describe(
1122
+ "SQL-92 where clause. IMPORTANT: When using geometryFilter.point for point-in-polygon queries, set this to '1=1' to return all features that intersect the point. Only add attribute filters if the user specifically requests them in addition to the spatial query."
1123
+ ),
1124
+ orderByFields: i.array(i.string().describe("The field(s) and order for which to sort the resulting features.")),
1125
+ outFields: i.array(
1126
+ i.string().describe(
1127
+ '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 ("*").'
1128
+ ).default("*")
1129
+ )
1130
+ }),
1131
+ geometryFilter: i.union([kr, jr]).optional().describe(
1132
+ "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."
1133
+ ),
1134
+ useCurrentExtent: i.boolean().optional().describe(
1135
+ "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)."
1136
+ )
1137
+ }), Mr = f(Ar, {
1138
+ name: "queryFeatures",
1139
+ description: "Queries features from a layer. Returns count and attributes (if ≤25 features). Use for listing features, finding features matching conditions, or spatial queries.",
1140
+ schema: _r
1141
+ }), Re = [Er, Lr, zr, Mr], Le = [dr, pr, br], G = () => {
1142
+ const e = (/* @__PURE__ */ new Date()).getTimezoneOffset(), r = e <= 0 ? "+" : "-", t = Math.floor(Math.abs(e) / 60).toString().padStart(2, "0"), a = (Math.abs(e) % 60).toString().padStart(2, "0"), o = `${r}${t}:${a}`;
1143
+ return { userTimezone: Intl.DateTimeFormat().resolvedOptions().timeZone, userTimezoneOffset: o };
1144
+ }, Vr = async (e, r) => {
1145
+ await m({ text: "Requesting LLM for layer filter results" }, r);
1146
+ const a = await $("data_explore_filter_prompt");
1147
+ if (!r?.configurable)
1148
+ throw new Error("config.configurable is required for layer filter tools");
1149
+ const { userTimezone: o, userTimezoneOffset: s } = G(), l = {
1150
+ layerFieldInfo: e.layerFieldInfo,
1151
+ userTimezone: o,
1152
+ userTimezoneOffset: s
1153
+ }, n = await N({
1154
+ promptText: a,
1155
+ messages: v(e.messages),
1156
+ inputVariables: l,
1157
+ tools: Le
1158
+ }), c = [...e.messages, n], u = (n.tool_calls?.length ?? 0) > 0 ? c : [...c, n], h = n.content.toString();
1159
+ return await Q(n, r), { ...e, messages: u, outputMessage: h };
1160
+ }, Dr = async (e, r) => {
1161
+ await m({ text: "Requesting LLM for layer query results" }, r);
1162
+ const a = await $("data_explore_query_prompt");
1163
+ if (!r?.configurable)
1164
+ throw new Error("config.configurable is required for layer query tools");
1165
+ const { userTimezone: o, userTimezoneOffset: s } = G(), l = {
1166
+ layerFieldInfo: e.layerFieldInfo,
1167
+ userTimezone: o,
1168
+ userTimezoneOffset: s
1169
+ }, n = await N({
1170
+ promptText: a,
1171
+ messages: v(e.messages),
1172
+ inputVariables: l,
1173
+ tools: Re
1174
+ }), c = [...e.messages, n], d = n.content.toString();
1175
+ return await Q(n, r), { ...e, messages: c, outputMessage: d };
1176
+ }, Qr = async (e, r) => {
1177
+ try {
1178
+ await m({ text: "Requesting LLM for summary on query results" }, r);
1179
+ const a = await $("summarize_query_response_prompt"), o = {
1180
+ queryResponse: e.queryResponse
1181
+ }, s = await be({
1182
+ promptText: a,
1183
+ messages: v(e.messages),
1184
+ inputVariables: o
1185
+ }), l = typeof s == "string" ? s : s.content, n = new B(l);
1186
+ return await m({ text: `Received response from LLM: ${l}` }, r), {
1187
+ ...e,
1188
+ outputMessage: l,
1189
+ messages: [...e.messages, n]
1190
+ };
1191
+ } catch (t) {
1192
+ throw await m({ text: "Error during filter LLM request" }, r), new Error(`Error during filter LLM request: ${t instanceof Error ? t.message : String(t)}`);
1193
+ }
1194
+ };
1195
+ async function Or(e, r) {
1196
+ const a = await new A(Le).invoke(
1197
+ {
1198
+ messages: v(e.messages)
1199
+ },
1200
+ r
1201
+ ), o = [...e.messages, ...a.messages], s = a.messages.map(
1202
+ (c) => new B({
1203
+ content: c.content,
1204
+ // eslint-disable-next-line @typescript-eslint/naming-convention
1205
+ additional_kwargs: c.additional_kwargs
1206
+ })
1207
+ );
1208
+ await m(
1209
+ { text: `Finished executing layer filter tool: ${a.messages.map((c) => c.content).join(", ")}` },
1210
+ r
1211
+ );
1212
+ const l = [...o, ...s], n = s.map((c) => c.content).join(`
1213
+
1214
+ `);
1215
+ return { ...e, messages: l, outputMessage: n };
1216
+ }
1217
+ const Pr = new A(Re);
1218
+ async function Br(e, r) {
1219
+ const { messages: t } = await Pr.invoke({ messages: v(e.messages) }, r), a = [], o = [];
1220
+ for (const l of t) {
1221
+ const n = l.content;
1222
+ let c;
1223
+ if (typeof n != "string") {
1224
+ c = {
1225
+ tool: l.name ?? "unknown",
1226
+ layerName: "unknown",
1227
+ summary: "Query failed",
1228
+ details: { error: "Skipping non-string tool output:", raw: n }
1229
+ };
1230
+ continue;
1231
+ }
1232
+ try {
1233
+ c = JSON.parse(n);
1234
+ } catch {
1235
+ c = {
1236
+ tool: l.name ?? "unknown",
1237
+ layerName: "unknown",
1238
+ summary: "Query failed",
1239
+ details: { error: n }
1240
+ };
1241
+ }
1242
+ a.push(c), c.details && typeof c.details == "object" && "error" in c.details ? o.push(`- ${c.tool}: Error - ${String(c.details.error)}`) : o.push(`- ${c.layerName}: ${c.summary}`);
1243
+ }
1244
+ const s = [...e.messages, ...t];
1245
+ return await m({ text: `Finished executing layer query tool: ${o.join(", ")}` }, r), {
1246
+ ...e,
1247
+ messages: s,
1248
+ queryResponse: a
1249
+ };
1250
+ }
1251
+ const Gr = 10, Wr = async (e, r) => {
1252
+ let t = null, a = null;
1253
+ try {
1254
+ r.type !== "geometry" && r.type !== "oid" && r.type !== "global-id" && (t = await X({ layer: e, field: r.name }), r.type === "string" && (a = (await ee({ layer: e, field: r.name })).uniqueValueInfos.sort((o, s) => s.count - o.count).slice(0, Gr)));
1255
+ } catch (o) {
1256
+ console.error(`Error fetching statistics for field ${r.name}:`, o);
1257
+ }
1258
+ return {
1259
+ summaryStatistics: t,
1260
+ uniqueValues: a
1261
+ };
1262
+ };
1263
+ async function ie(e, r, t) {
1264
+ const a = [], o = [];
1265
+ for (const s of e) {
1266
+ let l = function(p) {
1267
+ const y = r.get(p)?.layerItem;
1268
+ return y ? [
1269
+ y.name && `Name: ${y.name}`,
1270
+ y.title && `Title: ${y.title}`,
1271
+ y.description && `Description: ${y.description}`
1272
+ ].filter(Boolean).join(" | ") : p;
1273
+ };
1274
+ const { layerId: n, results: c } = s, d = t.map?.allLayers.find((p) => p.id === n), u = r.get(n)?.fieldRegistry;
1275
+ if (!u)
1276
+ continue;
1277
+ let h = a.find((p) => p.layerId === n);
1278
+ h || (h = {
1279
+ layerId: n,
1280
+ layerSummary: l(n),
1281
+ fieldInfos: []
1282
+ }, a.push(h));
1283
+ for (const p of c) {
1284
+ const y = u.get(p.name);
1285
+ if (!y)
1286
+ continue;
1287
+ if (!y.statistics) {
1288
+ const b = Wr(d, y).then((T) => {
1289
+ u.set(y.name, { ...y, statistics: T }), y.statistics = T;
1290
+ });
1291
+ o.push(b);
1292
+ }
1293
+ h.fieldInfos.push(y);
1294
+ }
1295
+ }
1296
+ return await Promise.all(o), a;
1297
+ }
1298
+ const Ur = async (e, r) => {
1299
+ try {
1300
+ await m({ text: "Getting statistics for vector search results" }, r);
1301
+ const t = S(r, "layersAndFieldsRegistry"), { mapView: a } = C(r), o = await ie(e.vectorSearchFieldResults, t, a);
1302
+ return console.log("Field statistics retrieved:", o), await m({ text: "Statistics retrieved" }, r), { ...e, layerFieldInfo: o };
1303
+ } catch (t) {
1304
+ throw await m({ text: "Error during fetching statistics" }, r), new Error(`Error during fetching statistics: ${t instanceof Error ? t.message : String(t)}`);
1305
+ }
1306
+ }, me = 0.7, Hr = 10, Zr = async (e, r) => {
1307
+ try {
1308
+ const t = L(e.messages);
1309
+ await m({ text: "Similarity search to find fields" }, r);
1310
+ const a = S(r, "fieldSearch"), o = S(r, "layersAndFieldsRegistry"), s = await a.searchFields({
1311
+ text: t,
1312
+ layerIds: e.vectorSearchLayerIds,
1313
+ minScore: me,
1314
+ topResults: Hr
1315
+ }), l = s.map(({ layerId: c, results: d }) => {
1316
+ const u = d.map((h) => ` - ${h.name} (${h.score.toFixed(2)})`).join(`
1317
+ `);
1318
+ return `${o.get(c)?.layerItem.name ?? c}:
1319
+ ${u}`;
1320
+ }).join(`
1321
+ `);
1322
+ let n;
1323
+ return s.length > 0 ? n = `Vector search completed. Matching layers and fields with scores:
1324
+ ${l}` : n = `No vector search results found for score over ${me}.`, await m({ text: n }, r), {
1325
+ ...e,
1326
+ vectorSearchFieldResults: s
1327
+ };
1328
+ } catch (t) {
1329
+ throw await m(
1330
+ { text: `Error during vector search: ${t instanceof Error ? t.message : String(t)}` },
1331
+ r
1332
+ ), new Error(`Vector search failed: ${t instanceof Error ? t.message : String(t)}`);
1333
+ }
1334
+ }, Kr = 0.7, Jr = async (e, r) => {
1335
+ try {
1336
+ const t = L(e.messages);
1337
+ await m({ text: `Similarity search to find layers: ${t}` }, r);
1338
+ const a = S(r, "layerSearch"), o = S(r, "layersAndFieldsRegistry"), s = await a.searchLayers({
1339
+ text: t,
1340
+ minScore: Kr
1341
+ }), l = s.map((d) => d.id), n = s.map(({ id: d, score: u }) => `${o.get(d)?.layerItem.name ?? d} (${u.toFixed(2)})`).join(`
1342
+ `);
1343
+ let c;
1344
+ return l.length > 0 ? c = `Vector search completed. Matching layers with scores:
1345
+ ${n}` : c = "Vector search completed. No matching layers found.", await m({ text: c }, r), {
1346
+ ...e,
1347
+ vectorSearchLayerIds: l
1348
+ };
1349
+ } catch (t) {
1350
+ throw await m(
1351
+ { text: `Error during vector search: ${t instanceof Error ? t.message : String(t)}` },
1352
+ r
1353
+ ), new Error(`Vector search failed: ${t instanceof Error ? t.message : String(t)}`);
1354
+ }
1355
+ }, Yr = (e, r) => D(["layerSearch", "fieldSearch", "layersAndFieldsRegistry"], "Data Exploration Agent")(
1356
+ e,
1357
+ r
1358
+ ), Xr = () => new _(Fe).addNode("requireDataExplorationServices", Yr).addNode("vectorSearchLayers", Jr).addNode("vectorSearchFields", Zr).addNode("fieldStatistics", Ur).addNode("queryAgent", Dr).addNode("queryTools", Br).addNode("summarizeQueryResponseLLM", Qr).addNode("filterAgent", Vr).addNode("filterTools", Or).addNode("earlyExit", sr).addEdge(M, "requireDataExplorationServices").addEdge("requireDataExplorationServices", "vectorSearchLayers").addConditionalEdges(
1359
+ "vectorSearchLayers",
1360
+ (r) => r.vectorSearchLayerIds.length ? "vectorSearchFields" : "earlyExit"
1361
+ ).addConditionalEdges(
1362
+ "vectorSearchFields",
1363
+ (r) => r.vectorSearchFieldResults.length ? "fieldStatistics" : "earlyExit"
1364
+ ).addEdge("fieldStatistics", "queryAgent").addConditionalEdges("queryAgent", (r) => (r.messages[r.messages.length - 1]?.tool_calls?.length ?? 0) > 0 ? "queryTools" : "filterAgent").addConditionalEdges(
1365
+ "queryTools",
1366
+ (r) => r.queryResponse.length ? "summarizeQueryResponseLLM" : "filterAgent"
1367
+ ).addEdge("summarizeQueryResponseLLM", "filterAgent").addEdge("filterAgent", "filterTools").addEdge("filterTools", x).addEdge("summarizeQueryResponseLLM", x).addEdge("earlyExit", x), ea = String.raw`- **data exploration** — User is asking about the feature layer’s data (e.g. counts, summaries, statistics, field values), either for all features, a subset based on a condition, or for a subset based on the current view. And/Or user wants to include or exclude features based on field values, or visually style features differently (e.g., highlight or deemphasize them).
1368
+ The Data Exploration Agent will automatically zoom to the affected features for action taken by this agent. In this case, no need to call navigation tool separately.
1369
+ _Example: “Only show stations where Brand is Shell”_
1370
+ _Example: “Make Shell stations stand out on the map”_
1371
+ _Example: “Gray out all stations that aren’t Shell”_
1372
+ This also includes questions that ask which feature meets a given condition or where a particular feature in the data is located (e.g., “Where is the spring with the highest elevation?”).
1373
+ _Example: “How many features are there?”_
1374
+ _Example: “What’s the average population?”_
1375
+ _Example: “Which values are in the status field?”_`, Fi = {
1376
+ id: "dataExploration",
1377
+ name: "Data Exploration Agent",
1378
+ description: ea,
1379
+ createGraph: Xr,
1380
+ workspace: Fe
1381
+ }, ye = 0.7, ta = 10, ra = async (e, r) => {
1382
+ try {
1383
+ const t = L(e.messages);
1384
+ await m({ text: "Similarity search to find fields" }, r);
1385
+ const a = S(r, "fieldSearch"), o = S(r, "layersAndFieldsRegistry"), s = await a.searchFields({
1386
+ text: t,
1387
+ layerIds: e.vectorSearchLayerIds,
1388
+ minScore: ye,
1389
+ topResults: ta
1390
+ }), l = s.map(({ layerId: c, results: d }) => {
1391
+ const u = d.map((h) => ` - ${h.name} (${h.score.toFixed(2)})`).join(`
1392
+ `);
1393
+ return `${o.get(c)?.layerItem.name ?? c}:
1394
+ ${u}`;
1395
+ }).join(`
1396
+ `);
1397
+ let n;
1398
+ return s.length > 0 ? n = `Vector search completed. Matching layers and fields with scores:
1399
+ ${l}` : n = `No vector search results found for score over ${ye}.`, await m({ text: n }, r), {
1400
+ ...e,
1401
+ vectorSearchFieldResults: s
1402
+ };
1403
+ } catch (t) {
1404
+ throw await m(
1405
+ { text: `Error during vector search: ${t instanceof Error ? t.message : String(t)}` },
1406
+ r
1407
+ ), new Error(`Vector search failed: ${t instanceof Error ? t.message : String(t)}`);
1408
+ }
1409
+ }, aa = 0.7, oa = async (e, r) => {
1410
+ try {
1411
+ const t = L(e.messages);
1412
+ await m({ text: `Similarity search to find layers: ${t}` }, r);
1413
+ const a = S(r, "layerSearch"), o = S(r, "layersAndFieldsRegistry"), s = await a.searchLayers({ text: t, minScore: aa }), l = s.map((d) => d.id), n = s.map(({ id: d, score: u }) => `${o.get(d)?.layerItem.name ?? d} (${u.toFixed(2)})`).join(`
1414
+ `);
1415
+ let c;
1416
+ return l.length > 0 ? c = `Vector search completed. Matching layers with scores:
1417
+ ${n}` : c = "Vector search completed. No matching layers found.", await m({ text: c }, r), {
1418
+ ...e,
1419
+ vectorSearchLayerIds: l
1420
+ };
1421
+ } catch (t) {
1422
+ throw await m(
1423
+ { text: `Error during vector search: ${t instanceof Error ? t.message : String(t)}` },
1424
+ r
1425
+ ), new Error(`Vector search failed: ${t instanceof Error ? t.message : String(t)}`);
1426
+ }
1427
+ }, Ie = ["mapView"];
1428
+ function W(e) {
1429
+ const t = e?.configurable?.context;
1430
+ if (!t || typeof t != "object")
1431
+ throw new Error("LayerFilterAgent context missing");
1432
+ const a = Ie.filter((o) => !(o in t));
1433
+ if (a.length)
1434
+ throw new Error(`LayerFilterAgent context missing: ${a.join(", ")}`);
1435
+ return t;
1436
+ }
1437
+ const sa = async (e, r) => {
1438
+ try {
1439
+ await m({ text: "Getting statistics for vector search results" }, r);
1440
+ const t = S(r, "layersAndFieldsRegistry"), { mapView: a } = W(r), o = await ie(e.vectorSearchFieldResults, t, a);
1441
+ return console.log("Field statistics retrieved:", o), await m({ text: "Statistics retrieved" }, r), { ...e, layerFieldInfo: o };
1442
+ } catch (t) {
1443
+ throw await m({ text: "Error during fetching statistics" }, r), new Error(`Error during fetching statistics: ${t instanceof Error ? t.message : String(t)}`);
1444
+ }
1445
+ }, ne = async (e, r, t) => {
1446
+ const a = e.map?.allLayers.find((l) => l.id === r), o = a.createQuery();
1447
+ o.where = t ?? "1=1";
1448
+ const { features: s } = await a.queryFeatures(o);
1449
+ e.goTo(s);
1450
+ }, ia = (e, r, t) => {
1451
+ const a = t.map?.allLayers.find((o) => o.id === e);
1452
+ return a ? (a.definitionExpression = r, a.visible = !0, ne(t, e, r), `Applied definition expression to layer "${a.title ?? e}": ${r}`) : `Could not find layer with ID: ${e}`;
1453
+ }, na = ({
1454
+ layerId: e,
1455
+ definitionExpression: r
1456
+ }, t) => {
1457
+ const { mapView: a } = W(t);
1458
+ return ia(e, r, a);
1459
+ }, la = i.object({
1460
+ layerId: i.string().describe("The layerId of the layer on which to set a definitionExpression."),
1461
+ definitionExpression: i.string().describe("The SQL-92 where clause used to set a definition expression on the layer.")
1462
+ }), ca = f(na, {
1463
+ name: "setDefinitionExpression",
1464
+ description: "Set a SQL-92 where clause to the definition expression of a layer (i.e. a server-side filter). This filters features at the server level, affecting all views of the layer. Do not prioritize this tool unless specifically asked for or implied for server level, affecting all views of the layer.",
1465
+ schema: la
1466
+ }), qe = async (e, r) => {
1467
+ const t = r.map?.allLayers.find(
1468
+ (s) => s.id === e.layerId
1469
+ );
1470
+ if (!t)
1471
+ return { error: `Could not find geometry layer with ID: ${e.layerId}` };
1472
+ const a = await t.queryFeatures({
1473
+ where: e.where,
1474
+ returnGeometry: !0
1475
+ });
1476
+ if (!a.features.length)
1477
+ return { error: `No features found in geometry layer with the specified where clause: ${e.where}` };
1478
+ let o;
1479
+ if (a.features.length === 1) {
1480
+ const s = a.features[0].geometry;
1481
+ if (!s)
1482
+ return { error: "The geometry of the first feature is undefined or null." };
1483
+ o = s;
1484
+ } else {
1485
+ const s = a.features.map((n) => n.geometry), l = Y.executeMany(s);
1486
+ if (!l)
1487
+ return { error: "Failed to create a combined geometry." };
1488
+ o = l;
1489
+ }
1490
+ return { geometry: o };
1491
+ }, da = async (e, r, t, a, o) => {
1492
+ const s = r.map?.allLayers.find(
1493
+ (n) => n.id === e.layerId
1494
+ );
1495
+ if (!s)
1496
+ return `Could not find target layer with ID: ${e.layerId}`;
1497
+ console.log("Layer type:", s.type), console.log("Layer geometryType:", s.geometryType), console.log("Layer renderer:", s.renderer?.type);
1498
+ let l;
1499
+ if (o) {
1500
+ const n = await qe(o, r);
1501
+ if ("error" in n)
1502
+ return n.error;
1503
+ l = n.geometry;
1504
+ }
1505
+ return s.featureEffect = new Te({
1506
+ filter: new V({
1507
+ where: e.where,
1508
+ geometry: l,
1509
+ spatialRelationship: "intersects",
1510
+ distance: o?.distance,
1511
+ units: o?.units
1512
+ }),
1513
+ includedEffect: t,
1514
+ excludedEffect: a
1515
+ }), s.visible = !0, ne(
1516
+ r,
1517
+ o ? o.layerId : e.layerId,
1518
+ o ? o.where : e.where
1519
+ ), `Applied feature effects to target layer "${s.title ?? e.layerId}"${o ? ` using geometry from layer "${o.layerId}"` : ""}.`;
1520
+ }, ua = ["feet", "kilometers", "meters", "miles", "nautical-miles", "us-nautical-miles"], Ce = i.enum(ua), ha = async ({
1521
+ targetLayer: e,
1522
+ geometryLayer: r,
1523
+ includedEffect: t = "drop-shadow(2px, 2px, 2px, gray)",
1524
+ excludedEffect: a = "grayscale(100%) opacity(60%) blur(2px)"
1525
+ }, o) => {
1526
+ const { mapView: s } = W(o);
1527
+ return await da(e, s, t, a, r);
1528
+ }, ma = i.object({
1529
+ targetLayer: i.object({
1530
+ layerId: i.string().describe("The layerId of the layer on which to set a feature effect."),
1531
+ where: i.string().describe("The SQL-92 where clause representing the features to emphasize.")
1532
+ }),
1533
+ geometryLayer: i.object({
1534
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
1535
+ where: i.string().describe(
1536
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
1537
+ ),
1538
+ distance: i.number().describe("The distance by which to filter the input geometry."),
1539
+ units: Ce.describe("The units used to filter by geometry and distance.")
1540
+ }).optional().describe("Optional geometry-based filtering parameters for spatial queries."),
1541
+ includedEffect: i.string().optional().default("drop-shadow(2px, 2px, 2px, gray)").describe(
1542
+ "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."
1543
+ ),
1544
+ excludedEffect: i.string().optional().default("grayscale(100%) opacity(60%) blur(2px)").describe(
1545
+ "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."
1546
+ )
1547
+ }), ya = f(ha, {
1548
+ name: "setFeatureEffect",
1549
+ 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.",
1550
+ schema: ma
1551
+ }), pa = async (e, r, t) => {
1552
+ const a = r.map?.allLayers.find(
1553
+ (l) => l.id === e.layerId
1554
+ );
1555
+ if (!a)
1556
+ return `Could not find target layer with ID: ${e.layerId}`;
1557
+ let o;
1558
+ if (t) {
1559
+ const l = await qe(t, r);
1560
+ if ("error" in l)
1561
+ return l.error;
1562
+ o = l.geometry;
1563
+ }
1564
+ const s = await r.whenLayerView(a);
1565
+ return s.filter = new V({
1566
+ where: e.where,
1567
+ geometry: o,
1568
+ spatialRelationship: "intersects",
1569
+ distance: t?.distance,
1570
+ units: t?.units
1571
+ }), a.visible = !0, ne(
1572
+ r,
1573
+ t ? t.layerId : e.layerId,
1574
+ t ? t.where : e.where
1575
+ ), `Applied feature filter to layer "${a.title ?? e.layerId}"${t ? ` using geometry from layer "${t.layerId}"` : ""}.`;
1576
+ }, ga = async ({
1577
+ targetLayer: e,
1578
+ geometryLayer: r
1579
+ }, t) => {
1580
+ const { mapView: a } = W(t);
1581
+ return await pa(e, a, r);
1582
+ }, fa = i.object({
1583
+ targetLayer: i.object({
1584
+ layerId: i.string().describe("The layerId of the layer on which to set a filter."),
1585
+ where: i.string().describe("The SQL-92 where clause representing the features to display.")
1586
+ }),
1587
+ geometryLayer: i.object({
1588
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
1589
+ where: i.string().describe(
1590
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
1591
+ ),
1592
+ distance: i.number().describe("The distance by which to filter the input geometry."),
1593
+ units: Ce.describe("The units used to filter by geometry and distance.")
1594
+ }).optional().describe("Optional geometry-based filtering parameters for spatial queries.")
1595
+ }), wa = f(ga, {
1596
+ name: "setFeatureFilter",
1597
+ description: "Sets a client-side filter using a where clause, geometry filter, or both on a target layer. This filters features at the client level in the view.",
1598
+ schema: fa
1599
+ }), ze = [ca, ya, wa], ba = async (e, r) => {
1600
+ await m({ text: "Requesting LLM for layer filter results" }, r);
1601
+ const a = await $("layer_filter_prompt");
1602
+ if (!r?.configurable)
1603
+ throw new Error("config.configurable is required for layer filter tools");
1604
+ const { userTimezone: o, userTimezoneOffset: s } = G(), l = {
1605
+ layerFieldInfo: e.layerFieldInfo,
1606
+ userTimezone: o,
1607
+ userTimezoneOffset: s
1608
+ }, n = await N({
1609
+ promptText: a,
1610
+ messages: v(e.messages),
1611
+ inputVariables: l,
1612
+ tools: ze
1613
+ }), c = n.content.toString();
1614
+ return await Q(n, r), { ...e, messages: [...e.messages, n], outputMessage: c };
1615
+ };
1616
+ async function Sa(e, r) {
1617
+ const a = await new A(ze).invoke(
1618
+ {
1619
+ messages: v(e.messages)
1620
+ },
1621
+ r
1622
+ ), o = a.messages.map((n) => n.text).join(`
1623
+ `);
1624
+ await m({ text: `Finished executing layer filter tool: ${o}` }, r);
1625
+ const s = [...e.messages, ...a.messages], l = a.messages.map((n) => n.text).join(`
1626
+ `);
1627
+ return { ...e, outputMessage: l, messages: s };
1628
+ }
1629
+ const Ne = g.Root({
1630
+ // Inputs coming from global context
1631
+ messages: g({
1632
+ reducer: j,
1633
+ default: () => []
1634
+ }),
1635
+ // Accumulates user-visible output across graph nodes.
1636
+ // Uses append semantics, but de-duplicates identical consecutive writes.
1637
+ // This avoids duplicate output when tool nodes and final LLM nodes
1638
+ // emit the same text during a single agent turn.
1639
+ outputMessage: g({
1640
+ reducer: (e = "", r) => {
1641
+ const t = typeof r == "string" ? r.trim() : "";
1642
+ if (!t)
1643
+ return e;
1644
+ const a = e.trim();
1645
+ if (!a)
1646
+ return t;
1647
+ if (a === t)
1648
+ return e;
1649
+ const o = a.split(`
1650
+
1651
+ `);
1652
+ return o[o.length - 1]?.trim() === t ? e : `${e}
1653
+
1654
+ ${t}`;
1655
+ },
1656
+ default: () => ""
1657
+ }),
1658
+ vectorSearchLayerIds: g(),
1659
+ vectorSearchFieldResults: g(),
1660
+ layerFieldInfo: g()
1661
+ }), va = async (e, r) => (await m({ text: "Exiting Layer Filter agent" }, r), e), Ta = (e, r) => D(["layerSearch", "fieldSearch", "layersAndFieldsRegistry"], "Layer Filter Agent")(e, r), xa = () => new _(Ne).addNode("requireLayerFilterServices", Ta).addNode("vectorSearchLayers", oa).addNode("vectorSearchFields", ra).addNode("fieldStatistics", sa).addNode("agent", ba).addNode("tools", Sa).addNode("earlyExit", va).addEdge(M, "requireLayerFilterServices").addEdge("requireLayerFilterServices", "vectorSearchLayers").addConditionalEdges(
1662
+ "vectorSearchLayers",
1663
+ (r) => r.vectorSearchLayerIds.length ? "vectorSearchFields" : "earlyExit"
1664
+ ).addConditionalEdges(
1665
+ "vectorSearchFields",
1666
+ (r) => r.vectorSearchFieldResults.length ? "fieldStatistics" : "earlyExit"
1667
+ ).addEdge("fieldStatistics", "agent").addConditionalEdges("agent", (r) => (r.messages[r.messages.length - 1]?.tool_calls?.length ?? 0) > 0 ? "tools" : "earlyExit").addEdge("tools", "earlyExit").addEdge("earlyExit", x), Ea = String.raw`- **layer filter** — User wants to include or exclude features based on field values, or visually style features differently (e.g., highlight or deemphasize them).
1668
+ The Layer Filter Agent will automatically zoom to the affected features for action taken by this agent. In this case, no need to call navigation tool separately.
1669
+ _Example: “Only show stations where Brand is Shell”_
1670
+ _Example: “Make Shell stations stand out on the map”_
1671
+ _Example: “Gray out all stations that aren’t Shell”_`, Ri = {
1672
+ id: "layerFilter",
1673
+ name: "Layer Filter Agent",
1674
+ description: Ea,
1675
+ createGraph: xa,
1676
+ workspace: Ne
1677
+ }, Ae = g.Root({
1678
+ // Inputs coming from global context
1679
+ messages: g({
1680
+ reducer: j,
1681
+ default: () => []
1682
+ }),
1683
+ // Accumulates user-visible output across graph nodes.
1684
+ // Uses append semantics, but de-duplicates identical consecutive writes.
1685
+ // This avoids duplicate output when tool nodes and final LLM nodes
1686
+ // emit the same text during a single agent turn.
1687
+ outputMessage: g({
1688
+ reducer: (e = "", r) => {
1689
+ const t = typeof r == "string" ? r.trim() : "";
1690
+ if (!t)
1691
+ return e;
1692
+ const a = e.trim();
1693
+ if (!a)
1694
+ return t;
1695
+ if (a === t)
1696
+ return e;
1697
+ const o = a.split(`
1698
+
1699
+ `);
1700
+ return o[o.length - 1]?.trim() === t ? e : `${e}
1701
+
1702
+ ${t}`;
1703
+ },
1704
+ default: () => ""
1705
+ }),
1706
+ vectorSearchLayerIds: g(),
1707
+ vectorSearchFieldResults: g(),
1708
+ layerFieldInfo: g(),
1709
+ queryResponses: g()
1710
+ }), $a = async (e, r) => (await m({ text: "Exiting Layer Query agent" }, r), e);
1711
+ function P(e) {
1712
+ const t = e?.configurable?.context;
1713
+ if (!t || typeof t != "object")
1714
+ throw new Error("LayerQueryAgent context missing");
1715
+ const a = Ie.filter((o) => !(o in t));
1716
+ if (a.length)
1717
+ throw new Error(`LayerQueryAgent context missing: ${a.join(", ")}`);
1718
+ return t;
1719
+ }
1720
+ const Fa = async (e, r) => {
1721
+ try {
1722
+ await m({ text: "Getting statistics for vector search results" }, r);
1723
+ const t = S(r, "layersAndFieldsRegistry"), { mapView: a } = P(r), o = await ie(e.vectorSearchFieldResults, t, a);
1724
+ return console.log("Field statistics retrieved:", o), await m({ text: "Statistics retrieved" }, r), { ...e, layerFieldInfo: o };
1725
+ } catch (t) {
1726
+ throw await m({ text: "Error during fetching statistics" }, r), new Error(`Error during fetching statistics: ${t instanceof Error ? t.message : String(t)}`);
1727
+ }
1728
+ }, pe = 0.7, Ra = 10, La = async (e, r) => {
1729
+ try {
1730
+ const t = L(e.messages);
1731
+ await m({ text: "Similarity search to find fields" }, r);
1732
+ const a = S(r, "fieldSearch"), o = S(r, "layersAndFieldsRegistry"), s = await a.searchFields({
1733
+ text: t,
1734
+ layerIds: e.vectorSearchLayerIds,
1735
+ minScore: pe,
1736
+ topResults: Ra
1737
+ }), l = s.map(({ layerId: c, results: d }) => {
1738
+ const u = d.map((h) => ` - ${h.name} (${h.score.toFixed(2)})`).join(`
1739
+ `);
1740
+ return `${o.get(c)?.layerItem.name ?? c}:
1741
+ ${u}`;
1742
+ }).join(`
1743
+ `);
1744
+ let n;
1745
+ return s.length > 0 ? n = `Vector search completed. Matching layers and fields with scores:
1746
+ ${l}` : n = `No vector search results found for score over ${pe}.`, await m({ text: n }, r), {
1747
+ ...e,
1748
+ vectorSearchFieldResults: s
1749
+ };
1750
+ } catch (t) {
1751
+ throw await m(
1752
+ { text: `Error during vector search: ${t instanceof Error ? t.message : String(t)}` },
1753
+ r
1754
+ ), new Error(`Vector search failed: ${t instanceof Error ? t.message : String(t)}`);
1755
+ }
1756
+ }, Ia = 0.7, qa = async (e, r) => {
1757
+ try {
1758
+ const t = L(e.messages);
1759
+ await m({ text: `Similarity search to find layers: ${t}` }, r);
1760
+ const a = S(r, "layerSearch"), o = S(r, "layersAndFieldsRegistry"), s = await a.searchLayers({
1761
+ text: t,
1762
+ minScore: Ia
1763
+ }), l = s.map((d) => d.id), n = s.map(({ id: d, score: u }) => `${o.get(d)?.layerItem.name ?? d} (${u.toFixed(2)})`).join(`
1764
+ `);
1765
+ let c;
1766
+ return l.length > 0 ? c = `Vector search completed. Matching layers with scores:
1767
+ ${n}` : c = "Vector search completed. No matching layers found.", await m({ text: c }, r), {
1768
+ ...e,
1769
+ vectorSearchLayerIds: l
1770
+ };
1771
+ } catch (t) {
1772
+ throw await m(
1773
+ { text: `Error during vector search: ${t instanceof Error ? t.message : String(t)}` },
1774
+ r
1775
+ ), new Error(`Vector search failed: ${t instanceof Error ? t.message : String(t)}`);
1776
+ }
1777
+ }, Ca = (e, r, t) => {
1778
+ const a = e.createQuery();
1779
+ return a.outFields = [r], a.where = t || "1=1", a.num = 1, a;
1780
+ }, za = async (e, r, t, a) => {
1781
+ const o = a.map?.allLayers.find((u) => u.id === e), s = Ca(o, r, t.where), n = (await o.queryFeatures(s)).features[0], c = n ? n.attributes[r] : null;
1782
+ return {
1783
+ tool: "getAttribute",
1784
+ layerName: o.title ?? e,
1785
+ summary: `${r} = ${c}`,
1786
+ details: {
1787
+ fieldName: r,
1788
+ value: c,
1789
+ where: t.where
1790
+ }
1791
+ };
1792
+ };
1793
+ async function Na({ layerId: e, fieldName: r, query: t }, a) {
1794
+ const { mapView: o } = P(a), s = await za(e, r, t, o);
1795
+ return JSON.stringify(s, null, 2);
1796
+ }
1797
+ const Aa = i.object({
1798
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
1799
+ fieldName: i.string().describe("The name of the field/attribute from which to get a field value."),
1800
+ query: i.object({
1801
+ where: i.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")
1802
+ })
1803
+ }), ka = f(Na, {
1804
+ name: "getAttribute",
1805
+ description: "Returns an attribute value for a given feature.",
1806
+ schema: Aa
1807
+ }), le = async (e, r) => {
1808
+ const t = r.map?.allLayers.find(
1809
+ (s) => s.id === e.layerId
1810
+ );
1811
+ if (!t)
1812
+ return { error: `Could not find geometry layer with ID: ${e.layerId}` };
1813
+ const a = await t.queryFeatures({
1814
+ where: e.where,
1815
+ returnGeometry: !0
1816
+ });
1817
+ if (!a.features.length)
1818
+ return { error: `No features found in geometry layer with the specified where clause: ${e.where}` };
1819
+ let o;
1820
+ if (a.features.length === 1) {
1821
+ const s = a.features[0].geometry;
1822
+ if (!s)
1823
+ return { error: "The geometry of the first feature is undefined or null." };
1824
+ o = s;
1825
+ } else {
1826
+ const s = a.features.map((n) => n.geometry), l = Y.executeMany(s);
1827
+ if (!l)
1828
+ return { error: "Failed to create a combined geometry." };
1829
+ o = l;
1830
+ }
1831
+ return { geometry: o };
1832
+ }, ja = async (e) => {
1833
+ const { targetLayer: r, fieldName: t, statisticType: a, mapView: o, layersAndFieldsRegistry: s, geometryLayer: l } = e, n = o.map?.allLayers.find((b) => b.id === r.layerId);
1834
+ if (!n)
1835
+ throw new Error(`Layer '${r.layerId}' not found.`);
1836
+ const d = s.get(r.layerId)?.fieldRegistry.get(t);
1837
+ if (!d)
1838
+ throw new Error(`Field '${t}' not found.`);
1839
+ let u;
1840
+ if (l) {
1841
+ const b = await le(l, o);
1842
+ if ("error" in b)
1843
+ throw new Error(b.error);
1844
+ if (u = b.geometry, l.distance && l.units) {
1845
+ const T = We.execute(u, l.distance, {
1846
+ unit: l.units === "us-nautical-miles" ? "nautical-miles" : l.units
1847
+ });
1848
+ T && (u = T);
1849
+ }
1850
+ } else
1851
+ u = o.extent.clone();
1852
+ const h = new V({
1853
+ geometry: u,
1854
+ spatialRelationship: "intersects"
1855
+ });
1856
+ let p = null, y = null;
1857
+ try {
1858
+ p = await X({
1859
+ layer: n,
1860
+ field: t,
1861
+ sqlWhere: r.where,
1862
+ filter: h,
1863
+ outStatisticTypes: { include: [a] }
1864
+ }), d.type === "string" && (y = (await ee({
1865
+ layer: n,
1866
+ field: t,
1867
+ sqlWhere: r.where,
1868
+ filter: h
1869
+ })).uniqueValueInfos);
1870
+ } catch (b) {
1871
+ console.error("Statistics error:", b);
1872
+ }
1873
+ return {
1874
+ tool: "getStatistics",
1875
+ layerName: n.title ?? r.layerId,
1876
+ summary: `${a} = ${typeof p?.[a] == "number" ? p[a] : "N/A"}`,
1877
+ details: {
1878
+ fieldName: t,
1879
+ statisticType: a,
1880
+ statistic: p?.[a] ?? null,
1881
+ summaryStatistics: p,
1882
+ uniqueValues: y,
1883
+ where: r.where
1884
+ }
1885
+ };
1886
+ }, _a = ["feet", "kilometers", "meters", "miles", "nautical-miles", "us-nautical-miles"], Ma = i.enum(_a);
1887
+ async function Va({
1888
+ targetLayer: e,
1889
+ fieldName: r,
1890
+ statisticType: t,
1891
+ geometryLayer: a
1892
+ }, o) {
1893
+ const s = S(o, "layersAndFieldsRegistry"), { mapView: l } = P(o), n = await ja({
1894
+ targetLayer: e,
1895
+ fieldName: r,
1896
+ statisticType: t,
1897
+ mapView: l,
1898
+ layersAndFieldsRegistry: s,
1899
+ geometryLayer: a
1900
+ });
1901
+ return console.log(n), JSON.stringify(n, null, 2);
1902
+ }
1903
+ const Da = i.object({
1904
+ targetLayer: i.object({
1905
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
1906
+ where: i.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")
1907
+ }),
1908
+ geometryLayer: i.union([
1909
+ i.object({
1910
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
1911
+ where: i.string().describe(
1912
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
1913
+ ),
1914
+ distance: i.number().optional().describe("The distance by which to query from the input geometry."),
1915
+ units: Ma.optional().describe("The units used to query by geometry and distance.")
1916
+ }),
1917
+ i.object({}).strict()
1918
+ // <-- Allows `{}` without throwing
1919
+ ]).optional().describe("Optional geometry-based filtering parameters for spatial queries."),
1920
+ fieldName: i.string().describe("The name of the field for which to get statistics."),
1921
+ statisticType: i.enum(["avg", "max", "median", "min", "stddev", "sum", "variance", "nullcount", "count"]).describe("The statistic type to calculate.")
1922
+ }), Qa = f(Va, {
1923
+ name: "getStatistics",
1924
+ description: "Returns one or more summary statistics for the given field. Statistic types include: count, maximum, minimum, average, median, standard deviation, variance, mode, sum, nullcount (number of features without a value for a given field), unique values. Statistics can be returned for number, date, and string fields. Only call this tool when the question requires filtering (e.g. a WHERE clause or spatial constraint) that cannot be satisfied by precomputed stats.",
1925
+ schema: Da
1926
+ }), Oa = async (e, r, t, a) => {
1927
+ const o = t.map?.allLayers.find((u) => u.id === e.layerId), s = a ? await le(a, t) : { geometry: void 0 }, l = "geometry" in s ? s.geometry : void 0, n = new xe({
1928
+ where: e.where || "1=1",
1929
+ outFields: e.outFields.length ? e.outFields : ["*"],
1930
+ orderByFields: e.orderByFields,
1931
+ geometry: l,
1932
+ spatialRelationship: l ? "intersects" : void 0,
1933
+ distance: a?.distance,
1934
+ units: a?.units,
1935
+ topFilter: new Ee({
1936
+ topCount: r.topCount,
1937
+ groupByFields: r.groupByFields,
1938
+ orderByFields: r.orderByFields
1939
+ })
1940
+ }), c = await o.queryTopFeatures(n);
1941
+ return {
1942
+ tool: "getTopFeatures",
1943
+ layerName: o.title ?? e.layerId,
1944
+ summary: `Top ${r.topCount} features extracted`,
1945
+ details: {
1946
+ topCount: r.topCount,
1947
+ features: c.features,
1948
+ where: e.where
1949
+ }
1950
+ };
1951
+ }, Pa = async ({
1952
+ targetLayer: e,
1953
+ topFilter: r,
1954
+ geometryLayer: t
1955
+ }, a) => {
1956
+ const { mapView: o } = P(a), s = await Oa(e, r, o, t);
1957
+ return JSON.stringify(s, null, 2);
1958
+ }, Ba = i.object({
1959
+ targetLayer: i.object({
1960
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
1961
+ where: i.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),
1962
+ orderByFields: i.array(i.string().describe("The field(s) and order for which to sort the resulting features.")),
1963
+ outFields: i.array(
1964
+ i.string().describe(
1965
+ "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."
1966
+ )
1967
+ )
1968
+ }),
1969
+ geometryLayer: i.object({
1970
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
1971
+ where: i.string().describe(
1972
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
1973
+ ),
1974
+ distance: i.number().describe("The distance by which to query from the input geometry."),
1975
+ units: z.describe("The units used to query by geometry and distance.")
1976
+ }).optional().describe("Optional geometry-based filtering parameters for spatial queries."),
1977
+ topFilter: i.object({
1978
+ topCount: i.number().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),
1979
+ orderByFields: i.array(i.string().describe("The field(s) and order for which to sort the resulting features.")),
1980
+ groupByFields: i.array(i.string().describe("The field(s) for which to group by the top features."))
1981
+ })
1982
+ }), Ga = f(Pa, {
1983
+ name: "getTopFeatures",
1984
+ description: "Returns the top n features from a layer",
1985
+ schema: Ba
1986
+ }), Wa = async (e, r, t) => {
1987
+ const a = r.map?.allLayers.find((d) => d.id === e.layerId), o = t ? await le(t, r) : { geometry: void 0 }, s = "geometry" in o ? o.geometry : void 0, l = new te({
1988
+ where: e.where || "1=1",
1989
+ outFields: e.outFields.length ? e.outFields : ["*"],
1990
+ orderByFields: e.orderByFields,
1991
+ geometry: s,
1992
+ spatialRelationship: s ? "intersects" : void 0,
1993
+ distance: t?.distance,
1994
+ units: t?.units
1995
+ }), n = await a.queryFeatures(l);
1996
+ return {
1997
+ tool: "queryFeatures",
1998
+ layerName: a.title ?? e.layerId,
1999
+ summary: `${n.features.length} features found`,
2000
+ details: {
2001
+ totalCount: n.features.length,
2002
+ features: n.features.slice(0, 10),
2003
+ where: e.where
2004
+ }
2005
+ };
2006
+ };
2007
+ async function Ua({
2008
+ targetLayer: e,
2009
+ geometryLayer: r
2010
+ }, t) {
2011
+ const { mapView: a } = P(t), o = await Wa(e, a, r);
2012
+ return JSON.stringify(o, null, 2);
2013
+ }
2014
+ const Ha = i.object({
2015
+ targetLayer: i.object({
2016
+ layerId: i.string().describe("The layerId of the layer containing the field from which to get a value."),
2017
+ where: i.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),
2018
+ orderByFields: i.array(i.string().describe("The field(s) and order for which to sort the resulting features.")),
2019
+ outFields: i.array(
2020
+ i.string().describe(
2021
+ "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."
2022
+ )
2023
+ )
2024
+ }),
2025
+ geometryLayer: i.object({
2026
+ layerId: i.string().describe("The layerId of the layer containing the geometry by which to filter."),
2027
+ where: i.string().describe(
2028
+ "The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."
2029
+ ),
2030
+ distance: i.number().describe("The distance by which to query from the input geometry."),
2031
+ units: z.describe("The units used to query by geometry and distance.")
2032
+ }).optional().describe("Optional geometry-based filtering parameters for spatial queries.")
2033
+ }), Za = f(Ua, {
2034
+ name: "queryFeatures",
2035
+ description: "Queries for one or more features from a given layer.",
2036
+ schema: Ha
2037
+ }), ke = [Za, Qa, ka, Ga], Ka = async (e, r) => {
2038
+ await m({ text: "Requesting LLM for layer query results" }, r);
2039
+ const t = await $("data_query_prompt");
2040
+ if (!r?.configurable)
2041
+ throw new Error("config.configurable is required for layer query tools");
2042
+ const { userTimezone: a, userTimezoneOffset: o } = G(), s = {
2043
+ layerFieldInfo: e.layerFieldInfo,
2044
+ userTimezone: a,
2045
+ userTimezoneOffset: o
2046
+ }, l = await N({
2047
+ promptText: t,
2048
+ messages: v(e.messages),
2049
+ inputVariables: s,
2050
+ tools: ke
2051
+ });
2052
+ if (!(l.tool_calls && Array.isArray(l.tool_calls) && l.tool_calls.length > 0))
2053
+ return {
2054
+ ...e,
2055
+ messages: [...e.messages, l]
2056
+ };
2057
+ const c = l.content.toString() || "LLM requested tool calls.";
2058
+ return await Q(l, r), { ...e, outputMessage: c, messages: [...e.messages, l] };
2059
+ }, Ja = new A(ke);
2060
+ async function Ya(e, r) {
2061
+ const { messages: t } = await Ja.invoke(
2062
+ { messages: v(e.messages) },
2063
+ r
2064
+ ), a = [], o = [];
2065
+ for (const n of t) {
2066
+ const c = n.content;
2067
+ if (typeof c != "string") {
2068
+ console.warn("Skipping non-string tool output:", c);
2069
+ continue;
2070
+ }
2071
+ let d;
2072
+ try {
2073
+ d = JSON.parse(c);
2074
+ } catch {
2075
+ console.warn("Skipping invalid JSON from tool:", c);
2076
+ continue;
2077
+ }
2078
+ a.push(d), o.push(`- ${d.layerName}: ${d.summary}`);
2079
+ }
2080
+ if (o.length === 0)
2081
+ return { ...e, queryResponses: a };
2082
+ const s = new B({
2083
+ content: `Query results:
2084
+ ${o.join(`
2085
+ `)}`
2086
+ }), l = `Query results:
2087
+ ${o.join(`
2088
+ `)}`;
2089
+ return {
2090
+ ...e,
2091
+ outputMessage: l,
2092
+ messages: [...e.messages, ...t, s],
2093
+ queryResponses: a
2094
+ };
2095
+ }
2096
+ const Xa = async (e, r) => {
2097
+ try {
2098
+ await m({ text: "Requesting LLM for summary on query results" }, r);
2099
+ const a = await $("summarize_query_response_prompt"), o = {
2100
+ queryResponse: e.queryResponses
2101
+ }, s = await be({
2102
+ promptText: a,
2103
+ messages: v(e.messages),
2104
+ inputVariables: o
2105
+ }), l = typeof s == "string" ? s : s.content;
2106
+ return e.messages = [...e.messages, new B(l)], e.outputMessage = l, await m({ text: `Received response from LLM: ${l}` }, r), e;
2107
+ } catch (t) {
2108
+ throw await m({ text: "Error during filter LLM request" }, r), new Error(`Error during filter LLM request: ${t instanceof Error ? t.message : String(t)}`);
2109
+ }
2110
+ }, eo = (e, r) => D(["layerSearch", "fieldSearch", "layersAndFieldsRegistry"], "Layer Query Agent")(e, r), to = () => new _(Ae).addNode("requireLayerQueryServices", eo).addNode("vectorSearchLayers", qa).addNode("vectorSearchFields", La).addNode("fieldStatistics", Fa).addNode("agent", Ka).addNode("tools", Ya).addNode("summarizeQueryResponseLLM", Xa).addNode("earlyExit", $a).addEdge(M, "requireLayerQueryServices").addEdge("requireLayerQueryServices", "vectorSearchLayers").addConditionalEdges(
2111
+ "vectorSearchLayers",
2112
+ (r) => r.vectorSearchLayerIds.length ? "vectorSearchFields" : "earlyExit"
2113
+ ).addConditionalEdges(
2114
+ "vectorSearchFields",
2115
+ (r) => r.vectorSearchFieldResults.length ? "fieldStatistics" : "earlyExit"
2116
+ ).addEdge("fieldStatistics", "agent").addEdge("agent", "tools").addConditionalEdges("tools", (r) => r.queryResponses.length ? "summarizeQueryResponseLLM" : "earlyExit").addEdge("summarizeQueryResponseLLM", x).addEdge("earlyExit", x), ro = String.raw`- **layerQuery** — User is asking about the feature layer’s data (e.g. counts, summaries, statistics, field values), either for all features, a subset based on a condition, or for a subset based on the current view. CRITICAL: Always call the Layer Filter Agent after this agent.
2117
+ This also includes questions that ask which feature meets a given condition or where a particular feature in the data is located (e.g., “Where is the spring with the highest elevation?”).
2118
+ _Example: “How many features are there?”_
2119
+ _Example: “What’s the average population?”_
2120
+ _Example: “Which values are in the status field?”_`, Li = {
2121
+ id: "layerQuery",
2122
+ name: "Layer Query Agent",
2123
+ description: ro,
2124
+ createGraph: to,
2125
+ workspace: Ae
2126
+ }, ge = 0.7, ao = 10, oo = async (e, r) => {
2127
+ try {
2128
+ const t = L(e.messages);
2129
+ await m({ text: "Similarity search to find fields" }, r);
2130
+ const a = S(r, "fieldSearch"), o = S(r, "layersAndFieldsRegistry"), s = await a.searchFields({
2131
+ text: t,
2132
+ layerIds: e.vectorSearchLayerIds,
2133
+ minScore: ge,
2134
+ topResults: ao
2135
+ }), l = s.map(({ layerId: c, results: d }) => {
2136
+ const u = d.map((h) => ` - ${h.name} (${h.score.toFixed(2)})`).join(`
2137
+ `);
2138
+ return `${o.get(c)?.layerItem.name ?? c}:
2139
+ ${u}`;
2140
+ }).join(`
2141
+ `);
2142
+ let n;
2143
+ return s.length > 0 ? n = `Vector search completed. Matching layers and fields with scores:
2144
+ ${l}` : n = `No vector search results found for score over ${ge}.`, await m({ text: n }, r), {
2145
+ ...e,
2146
+ vectorSearchFieldResults: s
2147
+ };
2148
+ } catch (t) {
2149
+ throw await m(
2150
+ { text: `Error during vector search: ${t instanceof Error ? t.message : String(t)}` },
2151
+ r
2152
+ ), new Error(`Vector search failed: ${t instanceof Error ? t.message : String(t)}`);
2153
+ }
2154
+ }, so = 0.7, io = async (e, r) => {
2155
+ try {
2156
+ const t = L(e.messages);
2157
+ await m({ text: `Similarity search to find layers: ${t}` }, r);
2158
+ const a = S(r, "layerSearch"), o = S(r, "layersAndFieldsRegistry"), s = await a.searchLayers({
2159
+ text: t,
2160
+ minScore: so
2161
+ }), l = s.map((d) => d.id), n = s.map(({ id: d, score: u }) => `${o.get(d)?.layerItem.name ?? d} (${u.toFixed(2)})`).join(`
2162
+ `);
2163
+ let c;
2164
+ return l.length > 0 ? c = `Vector search completed. Matching layers with scores:
2165
+ ${n}` : c = "Vector search completed. No matching layers found.", await m({ text: c }, r), {
2166
+ ...e,
2167
+ vectorSearchLayerIds: l
2168
+ };
2169
+ } catch (t) {
2170
+ throw await m(
2171
+ { text: `Error during vector search: ${t instanceof Error ? t.message : String(t)}` },
2172
+ r
2173
+ ), new Error(`Vector search failed: ${t instanceof Error ? t.message : String(t)}`);
2174
+ }
2175
+ };
2176
+ async function no(e) {
2177
+ const { fields: r, layer: t, view: a, styleName: o, colorSchemeTags: s } = e;
2178
+ let l;
2179
+ return s ? l = He({
2180
+ basemapTheme: await de(a),
2181
+ geometryType: t.geometryType,
2182
+ includedTags: s,
2183
+ numColors: Math.min(r.length, 8)
2184
+ })[0] : l = Ze({
2185
+ basemapTheme: await de(a),
2186
+ geometryType: t.geometryType,
2187
+ numColors: Math.min(r.length, 8)
2188
+ }).primaryScheme, {
2189
+ layer: t,
2190
+ view: a,
2191
+ attributes: r.map((n) => ({
2192
+ field: n,
2193
+ label: t.fields.find((c) => c.name === n)?.alias ?? ""
2194
+ })).slice(0, 8),
2195
+ outlineOptimizationEnabled: !0,
2196
+ sizeOptimizationEnabled: !0,
2197
+ includeSizeVariable: o.includes("Size"),
2198
+ pieChartScheme: l
2199
+ };
2200
+ }
2201
+ async function lo(e) {
2202
+ return await Ue(e);
2203
+ }
2204
+ async function co({
2205
+ arcgisMap: e,
2206
+ arcgisMapView: r,
2207
+ layerId: t,
2208
+ fields: a,
2209
+ colorSchemes: o,
2210
+ includeSize: s
2211
+ }) {
2212
+ const l = r, n = e?.allLayers.find((u) => u.id === t);
2213
+ if (!n)
2214
+ return `Could not find layer for id: ${t}`;
2215
+ const d = {
2216
+ styleName: s ? "chart-size" : "chart",
2217
+ fields: a,
2218
+ layer: n,
2219
+ view: l,
2220
+ colorSchemeTags: o
2221
+ };
2222
+ try {
2223
+ const u = await no(d), h = await lo(u);
2224
+ return n.renderer = h.renderer, n.visible = !0, `Chart renderer applied to layer: ${n.title ?? n.id} using fields ${a.join(", ")}`;
2225
+ } catch (u) {
2226
+ return `Error applying chart renderer: ${u instanceof Error ? u.message : String(u)}`;
2227
+ }
2228
+ }
2229
+ const uo = ["mapView"];
2230
+ function F(e) {
2231
+ const t = e?.configurable?.context;
2232
+ if (!t || typeof t != "object")
2233
+ throw new Error("LayerStylingAgent context missing");
2234
+ const a = uo.filter((o) => !(o in t));
2235
+ if (a.length)
2236
+ throw new Error(`LayerStylingAgent context missing: ${a.join(", ")}`);
2237
+ return t;
2238
+ }
2239
+ async function ho({
2240
+ layerId: e,
2241
+ fields: r,
2242
+ colorSchemes: t,
2243
+ includeSize: a
2244
+ }, o) {
2245
+ const { mapView: s } = F(o);
2246
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, o), await co({
2247
+ arcgisMap: s.map,
2248
+ arcgisMapView: s,
2249
+ layerId: e,
2250
+ fields: r,
2251
+ colorSchemes: t,
2252
+ includeSize: a
2253
+ });
2254
+ }
2255
+ const mo = i.object({
2256
+ layerId: i.string().describe("The id of the layer to apply the chart renderer to"),
2257
+ fields: i.array(i.string()).describe("The fields to use for the chart renderer (multiple numeric fields)"),
2258
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use"),
2259
+ includeSize: i.boolean().optional().describe("Whether to vary the chart size (chart-size)")
2260
+ }), yo = f(ho, {
2261
+ name: "chart",
2262
+ description: `Label: Charts
2263
+ Description: Show the values of two or more categories as a proportion of the total using a pie chart.
2264
+ Keywords: pie, chart, all categories, breakdown, proportion
2265
+ Example: Show the total number of homes built in each decade using a pie chart for each feature.
2266
+ Fields: This style requires 2-8 number fields.
2267
+
2268
+ Label: Charts and Size
2269
+ Description: Show the values of two or more categories as a proportion of the total using a pie chart and use size to capture the total amount or magnitude.
2270
+ Keywords: pie, chart, all categories, breakdown, proportion, total, amount, how much, sum, graduated size, proportional size
2271
+ Example: Show the total number of homes built in each decade using a pie chart for each feature and vary the size of each chart based on the total of all categories.
2272
+ Fields: This style requires 2-8 number fields.`,
2273
+ schema: mo
2274
+ });
2275
+ function po(e) {
2276
+ const { fields: r, layer: t, view: a, theme: o, colorSchemeTags: s } = e, l = r[0];
2277
+ let n;
2278
+ return s && (n = re({
2279
+ geometryType: t.geometryType,
2280
+ includedTags: s,
2281
+ theme: o || "high-to-low"
2282
+ })[0]), {
2283
+ layer: t,
2284
+ view: a,
2285
+ startTime: l,
2286
+ endTime: /* @__PURE__ */ new Date(),
2287
+ theme: o,
2288
+ sizeOptimizationEnabled: !0,
2289
+ outlineOptimizationEnabled: !0,
2290
+ colorScheme: n
2291
+ };
2292
+ }
2293
+ async function go(e) {
2294
+ return await Ke(e);
2295
+ }
2296
+ async function fo({
2297
+ arcgisMap: e,
2298
+ arcgisMapView: r,
2299
+ layerId: t,
2300
+ fields: a,
2301
+ colorSchemes: o,
2302
+ theme: s
2303
+ }) {
2304
+ const l = r, n = e?.allLayers.find((d) => d.id === t);
2305
+ if (!n)
2306
+ return `Could not find layer for id: ${t}`;
2307
+ const c = {
2308
+ styleName: "color-age",
2309
+ fields: a,
2310
+ layer: n,
2311
+ view: l,
2312
+ colorSchemeTags: o,
2313
+ theme: s
2314
+ };
2315
+ try {
2316
+ const d = po(c), u = await go(d);
2317
+ return n.renderer = u.renderer, n.visible = !0, `Color-age renderer applied to layer: ${n.title ?? n.id} using fields ${a.join(", ")}`;
2318
+ } catch (d) {
2319
+ return `Error applying color-age renderer: ${d instanceof Error ? d.message : String(d)}`;
2320
+ }
2321
+ }
2322
+ async function wo({
2323
+ layerId: e,
2324
+ fields: r,
2325
+ colorSchemes: t,
2326
+ theme: a
2327
+ }, o) {
2328
+ const { mapView: s } = F(o);
2329
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, o), await fo({
2330
+ arcgisMap: s.map,
2331
+ arcgisMapView: s,
2332
+ layerId: e,
2333
+ fields: r,
2334
+ colorSchemes: t,
2335
+ theme: a
2336
+ });
2337
+ }
2338
+ const bo = i.object({
2339
+ layerId: i.string().describe("The id of the layer to apply the color-age renderer to"),
2340
+ fields: i.array(i.string()).describe("The field(s) to use for the color-age renderer (temporal/date data)"),
2341
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use"),
2342
+ theme: i.enum(["above-and-below", "above", "below", "centered-on", "extremes", "high-to-low"]).optional().describe("Optional theme for the color ramp")
2343
+ }), So = f(wo, {
2344
+ name: "color-age",
2345
+ description: `Label: Age (color)
2346
+ Description: Use colors along a continuous color ramp to represent the age of features. Age reflects the length of time from a start date to an end date.
2347
+ Keywords: since, age, how old, how long
2348
+ Example: Show the age of each feature based on its reported date.
2349
+ Fields: This style requires at least one field with a date type.`,
2350
+ schema: bo
2351
+ });
2352
+ function vo(e) {
2353
+ const { fields: r, layer: t, view: a, colorSchemeTags: o } = e;
2354
+ let { theme: s } = e, l = r[1];
2355
+ const n = r[0];
2356
+ let c;
2357
+ return o && (c = re({
2358
+ geometryType: t.geometryType,
2359
+ includedTags: o,
2360
+ theme: s || "high-to-low"
2361
+ })[0]), {
2362
+ layer: t,
2363
+ view: a,
2364
+ field: n,
2365
+ normalizationField: l,
2366
+ theme: s,
2367
+ sizeOptimizationEnabled: !0,
2368
+ outlineOptimizationEnabled: !0,
2369
+ colorScheme: c
2370
+ };
2371
+ }
2372
+ async function To(e) {
2373
+ return await Je(e);
2374
+ }
2375
+ async function xo({
2376
+ arcgisMap: e,
2377
+ arcgisMapView: r,
2378
+ layerId: t,
2379
+ fields: a,
2380
+ colorSchemes: o,
2381
+ theme: s
2382
+ }) {
2383
+ const l = r, n = e?.allLayers.find((d) => d.id === t);
2384
+ if (!n)
2385
+ return `Could not find layer for id: ${t}`;
2386
+ const c = {
2387
+ styleName: "color",
2388
+ fields: a,
2389
+ layer: n,
2390
+ view: l,
2391
+ colorSchemeTags: o,
2392
+ theme: s
2393
+ };
2394
+ try {
2395
+ const d = vo(c), u = await To(d);
2396
+ return n.renderer = u.renderer, n.visible = !0, `Color renderer applied to layer: ${n.title ?? n.id} using fields ${a.join(", ")}`;
2397
+ } catch (d) {
2398
+ return `Error applying color renderer: ${d instanceof Error ? d.message : String(d)}`;
2399
+ }
2400
+ }
2401
+ async function Eo({
2402
+ layerId: e,
2403
+ fields: r,
2404
+ colorSchemes: t,
2405
+ theme: a
2406
+ }, o) {
2407
+ const { mapView: s } = F(o);
2408
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, o), await xo({
2409
+ arcgisMap: s.map,
2410
+ arcgisMapView: s,
2411
+ layerId: e,
2412
+ fields: r,
2413
+ colorSchemes: t,
2414
+ theme: a
2415
+ });
2416
+ }
2417
+ const $o = i.object({
2418
+ layerId: i.string().describe("The id of the layer to apply the color renderer to"),
2419
+ fields: i.array(i.string()).describe("The field(s) to use for the color renderer"),
2420
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use"),
2421
+ theme: i.enum(["above-and-below", "above", "below", "centered-on", "extremes", "high-to-low"]).optional().describe("Optional theme for the color ramp")
2422
+ }), Fo = f(Eo, {
2423
+ name: "color",
2424
+ description: `Label: Counts and Amounts (color)
2425
+ Description: Vary color along a continuous color ramp to represent numeric or ranked data.
2426
+ Keywords: graduated color, choropleth, continuous color, hue, color, gradation, saturation, lightness, percent, rate, ratio, index, how much, increase, decrease
2427
+ Example: Color each feature based on the population density.
2428
+ Fields: This style requires a single field with a number type. A second number field may be specified for normalizing the value of the first field.`,
2429
+ schema: $o
2430
+ });
2431
+ function Ro(e) {
2432
+ const { fields: r, layer: t, view: a, colorSchemeTags: o, theme: s } = e;
2433
+ let l, n;
2434
+ const c = r[0];
2435
+ return o && (n = re({
2436
+ geometryType: t.geometryType,
2437
+ includedTags: o,
2438
+ theme: s || "high-to-low"
2439
+ })[0]), {
2440
+ layer: t,
2441
+ view: a,
2442
+ field: c,
2443
+ normalizationField: l,
2444
+ theme: s,
2445
+ colorOptions: {
2446
+ colorScheme: n
2447
+ }
2448
+ };
2449
+ }
2450
+ async function Lo(e) {
2451
+ return await Ye(e);
2452
+ }
2453
+ async function Io({
2454
+ arcgisMap: e,
2455
+ arcgisMapView: r,
2456
+ layerId: t,
2457
+ fields: a,
2458
+ colorSchemes: o,
2459
+ theme: s
2460
+ }) {
2461
+ const l = r, n = e?.allLayers.find((d) => d.id === t);
2462
+ if (!n)
2463
+ return `Could not find layer for id: ${t}`;
2464
+ const c = {
2465
+ styleName: "color-size-univariate",
2466
+ fields: a,
2467
+ layer: n,
2468
+ view: l,
2469
+ colorSchemeTags: o,
2470
+ theme: s
2471
+ };
2472
+ try {
2473
+ const d = Ro(c), u = await Lo(d);
2474
+ return n.renderer = u.renderer, n.visible = !0, `Color-size-univariate renderer applied to layer: ${n.title ?? n.id} using fields ${a.join(", ")}`;
2475
+ } catch (d) {
2476
+ return `Error applying color-size-univariate renderer: ${d instanceof Error ? d.message : String(d)}`;
2477
+ }
2478
+ }
2479
+ async function qo({
2480
+ layerId: e,
2481
+ fields: r,
2482
+ colorSchemes: t,
2483
+ theme: a
2484
+ }, o) {
2485
+ const { mapView: s } = F(o);
2486
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, o), await Io({
2487
+ arcgisMap: s.map,
2488
+ arcgisMapView: s,
2489
+ layerId: e,
2490
+ fields: r,
2491
+ colorSchemes: t,
2492
+ theme: a
2493
+ });
2494
+ }
2495
+ const Co = i.object({
2496
+ layerId: i.string().describe("The id of the layer to apply the color-size univariate renderer to"),
2497
+ fields: i.array(i.string()).describe("The fields to use for the color-size univariate renderer"),
2498
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use"),
2499
+ theme: i.enum(["above-and-below", "above", "below", "centered-on", "extremes", "high-to-low"]).optional().describe("Optional theme for the color and size ramps")
2500
+ }), zo = f(qo, {
2501
+ name: "color-size-univariate",
2502
+ description: `Label: Color and Size (univariate)
2503
+ Description: Vary symbol size and color based on the values of two numeric attributes.
2504
+ Keywords: continuous color, hue, color, size, gradation, saturation, lightness, percent, rate, ratio, index, how much, increase, decrease, amount
2505
+ Example: Color each feature based on the percentage of the population that owns a home and vary the size of each point based on total population.
2506
+ Fields: This style requires at least two fields: one determining the color of each feature, the other determining the size of each feature. Each field may be normalized by an additional normalization field.`,
2507
+ schema: Co
2508
+ });
2509
+ function No(e) {
2510
+ const { fields: r, layer: t, view: a, colorSchemeTags: o } = e;
2511
+ let s;
2512
+ return o && (s = et({
2513
+ includedTags: o,
2514
+ numColors: Math.min(r.length, 8)
2515
+ })[0]), {
2516
+ layer: t,
2517
+ view: a,
2518
+ legendOptions: {
2519
+ unit: "units"
2520
+ },
2521
+ attributes: r.map((l) => ({
2522
+ field: l,
2523
+ label: t.fields.find((n) => n.name === l)?.alias ?? ""
2524
+ })).slice(0, 8),
2525
+ outlineOptimizationEnabled: !0,
2526
+ dotDensityScheme: s
2527
+ };
2528
+ }
2529
+ async function Ao(e) {
2530
+ return await Xe(e);
2531
+ }
2532
+ async function ko({
2533
+ arcgisMap: e,
2534
+ arcgisMapView: r,
2535
+ layerId: t,
2536
+ fields: a,
2537
+ colorSchemes: o
2538
+ }) {
2539
+ const s = r, l = e?.allLayers.find((c) => c.id === t);
2540
+ if (!l)
2541
+ return `Could not find layer for id: ${t}`;
2542
+ const n = {
2543
+ styleName: "dot-density",
2544
+ fields: a,
2545
+ layer: l,
2546
+ view: s,
2547
+ colorSchemeTags: o
2548
+ };
2549
+ try {
2550
+ const c = No(n), d = await Ao(c);
2551
+ return l.renderer = d.renderer, l.visible = !0, `Dot Density renderer applied to layer: ${l.title ?? l.id} using fields ${a.join(", ")}`;
2552
+ } catch (c) {
2553
+ return `Error applying dot density renderer: ${c instanceof Error ? c.message : String(c)}`;
2554
+ }
2555
+ }
2556
+ async function jo({
2557
+ layerId: e,
2558
+ fields: r,
2559
+ colorSchemes: t
2560
+ }, a) {
2561
+ const { mapView: o } = F(a);
2562
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, a), await ko({
2563
+ arcgisMap: o.map,
2564
+ arcgisMapView: o,
2565
+ layerId: e,
2566
+ fields: r,
2567
+ colorSchemes: t
2568
+ });
2569
+ }
2570
+ const _o = i.object({
2571
+ layerId: i.string().describe("The id of the layer to apply the dot density renderer to"),
2572
+ fields: i.array(i.string()).describe("The field(s) to use for the dot density renderer (population or count data)"),
2573
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use")
2574
+ }), Mo = f(jo, {
2575
+ name: "dot-density",
2576
+ description: `Dot Density
2577
+ Use dot density to visualize the distribution of one attribute or compare the density of multiple attributes. This is only valid for polygon layers.
2578
+ **Use cases:**
2579
+ - Population distribution visualization
2580
+ - Comparing multiple categories within areas
2581
+ - Showing spatial distribution patterns
2582
+ **Examples:**
2583
+ - Show the density of the population based on various race/ethnic groups
2584
+ - Visualize distribution of different crops across regions
2585
+ - Display demographic patterns within census tracts
2586
+ **Fields:** Requires 2-8 number fields.
2587
+ **Keywords:** density, how much, how many, total, number, amount`,
2588
+ schema: _o
2589
+ });
2590
+ function Vo(e) {
2591
+ const { fields: r, layer: t, view: a, colorSchemeTags: o } = e;
2592
+ let s;
2593
+ const l = r[0];
2594
+ return o && (s = rt({
2595
+ includedTags: o,
2596
+ basemap: a.map?.basemap || "topo"
2597
+ })[0]), {
2598
+ layer: t,
2599
+ view: a,
2600
+ field: l,
2601
+ heatmapScheme: s
2602
+ };
2603
+ }
2604
+ async function Do(e) {
2605
+ return await tt(e);
2606
+ }
2607
+ async function Qo({
2608
+ arcgisMap: e,
2609
+ arcgisMapView: r,
2610
+ layerId: t,
2611
+ fields: a,
2612
+ colorSchemes: o
2613
+ }) {
2614
+ const s = r, l = e?.allLayers.find((c) => c.id === t);
2615
+ if (!l)
2616
+ return `Could not find layer for id: ${t}`;
2617
+ const n = {
2618
+ styleName: "heatmap",
2619
+ fields: a,
2620
+ layer: l,
2621
+ view: s,
2622
+ colorSchemeTags: o
2623
+ };
2624
+ try {
2625
+ const c = Vo(n), d = await Do(c);
2626
+ return l.renderer = d.renderer, l.visible = !0, `Heatmap renderer applied to layer: ${l.title ?? l.id} using fields ${a.join(", ")}`;
2627
+ } catch (c) {
2628
+ return `Error applying heatmap renderer: ${c instanceof Error ? c.message : String(c)}`;
2629
+ }
2630
+ }
2631
+ async function Oo({
2632
+ layerId: e,
2633
+ fields: r,
2634
+ colorSchemes: t
2635
+ }, a) {
2636
+ const { mapView: o } = F(a);
2637
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, a), await Qo({
2638
+ arcgisMap: o.map,
2639
+ arcgisMapView: o,
2640
+ layerId: e,
2641
+ fields: r,
2642
+ colorSchemes: t
2643
+ });
2644
+ }
2645
+ const Po = i.object({
2646
+ layerId: i.string().describe("The id of the layer to apply the heatmap renderer to"),
2647
+ fields: i.array(i.string()).describe("The field(s) to use for the heatmap renderer (typically point density)"),
2648
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use")
2649
+ }), Bo = f(Oo, {
2650
+ name: "heatmap",
2651
+ description: `Label: Heat Map
2652
+ Description: Show areas of high density with colors that appear to glow hotter. This is only valid for point layers.
2653
+ Keywords: density, heatmap, hot spots, pattern, cluster
2654
+ Example: Create a heatmap
2655
+ Fields: This typically requires zero or one field of type number.`,
2656
+ schema: Po
2657
+ });
2658
+ function Go(e) {
2659
+ const { fields: r, layer: t, view: a, styleName: o, colorSchemeTags: s } = e;
2660
+ let l;
2661
+ return s && (l = ot({
2662
+ geometryType: t.geometryType,
2663
+ includedTags: s,
2664
+ numColors: Math.min(r.length, 10)
2665
+ })[0]), {
2666
+ layer: t,
2667
+ view: a,
2668
+ fields: r.map((n) => ({ name: n })).slice(0, 9),
2669
+ outlineOptimizationEnabled: !0,
2670
+ sizeOptimizationEnabled: !0,
2671
+ includeSizeVariable: o.includes("Size"),
2672
+ predominanceScheme: l
2673
+ };
2674
+ }
2675
+ async function Wo(e) {
2676
+ return await at(e);
2677
+ }
2678
+ async function Uo({
2679
+ arcgisMap: e,
2680
+ arcgisMapView: r,
2681
+ layerId: t,
2682
+ fields: a,
2683
+ colorSchemes: o,
2684
+ includeSize: s
2685
+ }) {
2686
+ const l = r, n = e?.allLayers.find((u) => u.id === t);
2687
+ if (!n)
2688
+ return `Could not find layer for id: ${t}`;
2689
+ const d = {
2690
+ styleName: s ? "predominance-size" : "predominance",
2691
+ fields: a,
2692
+ layer: n,
2693
+ view: l,
2694
+ colorSchemeTags: o
2695
+ };
2696
+ try {
2697
+ const u = Go(d), h = await Wo(u);
2698
+ return n.renderer = h.renderer, n.visible = !0, `Predominance renderer applied to layer: ${n.title ?? n.id} using fields ${a.join(", ")}`;
2699
+ } catch (u) {
2700
+ return `Error applying predominance renderer: ${u instanceof Error ? u.message : String(u)}`;
2701
+ }
2702
+ }
2703
+ async function Ho({
2704
+ layerId: e,
2705
+ fields: r,
2706
+ colorSchemes: t,
2707
+ includeSize: a
2708
+ }, o) {
2709
+ const { mapView: s } = F(o);
2710
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, o), await Uo({
2711
+ arcgisMap: s.map,
2712
+ arcgisMapView: s,
2713
+ layerId: e,
2714
+ fields: r,
2715
+ colorSchemes: t,
2716
+ includeSize: a
2717
+ });
2718
+ }
2719
+ const Zo = i.object({
2720
+ layerId: i.string().describe("The id of the layer to apply the predominance renderer to"),
2721
+ fields: i.array(i.string()).describe("The fields to use for the predominance renderer (competing categories)"),
2722
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use"),
2723
+ includeSize: i.boolean().optional().describe("Whether to include size visualization (predominance-size)")
2724
+ }), Ko = f(Ho, {
2725
+ name: "predominance",
2726
+ description: `Label: Predominant category
2727
+ Description: Compare attributes that share a common subject and unit of measurement to see which has the highest value.
2728
+ Keywords: predominant, winner, won, competing, most, most common, most frequent, dominant, prevalent, top
2729
+ Example: Using fields for Corn Acres, Wheat Acres, and Cotton Acres, show the predominant crop harvested in each area.
2730
+ Fields: This style relies on 2-10 number fields.
2731
+
2732
+ Label: Predominant category and Size
2733
+ Description: Compare attributes that share a common subject and unit of measurement to see which has the highest value. Also varies the size of each symbol based on the total of all categories.
2734
+ Keywords: predominant, winner, won, competing, most, most common, most frequent, dominant, prevalent, top, amount, total, how much, proportional size, graduated size, sum
2735
+ Example: Show the predominant crop in each area and vary the size of each symbol based on the total of all categories.
2736
+ Fields: This style relies on 2-10 number fields.`,
2737
+ schema: Zo
2738
+ });
2739
+ function Jo(e) {
2740
+ const { fields: r, layer: t, view: a, colorSchemeTags: o } = e;
2741
+ let s;
2742
+ const l = {
2743
+ field: r[0]
2744
+ }, n = {
2745
+ field: r[1]
2746
+ };
2747
+ return o && (s = it({
2748
+ geometryType: t.geometryType,
2749
+ includedTags: o
2750
+ })[0]), {
2751
+ layer: t,
2752
+ view: a,
2753
+ field1: l,
2754
+ field2: n,
2755
+ outlineOptimizationEnabled: !0,
2756
+ sizeOptimizationEnabled: !0,
2757
+ relationshipScheme: s
2758
+ };
2759
+ }
2760
+ async function Yo(e) {
2761
+ return await st(e);
2762
+ }
2763
+ async function Xo({
2764
+ arcgisMap: e,
2765
+ arcgisMapView: r,
2766
+ layerId: t,
2767
+ fields: a,
2768
+ colorSchemes: o
2769
+ }) {
2770
+ const s = r, l = e?.allLayers.find((c) => c.id === t);
2771
+ if (!l)
2772
+ return `Could not find layer for id: ${t}`;
2773
+ const n = {
2774
+ styleName: "relationship",
2775
+ fields: a,
2776
+ layer: l,
2777
+ view: s,
2778
+ colorSchemeTags: o
2779
+ };
2780
+ try {
2781
+ const c = Jo(n), d = await Yo(c);
2782
+ return l.renderer = d.renderer, l.visible = !0, `Relationship renderer applied to layer: ${l.title ?? l.id} using fields ${a.join(", ")}`;
2783
+ } catch (c) {
2784
+ return `Error applying relationship renderer: ${c instanceof Error ? c.message : String(c)}`;
2785
+ }
2786
+ }
2787
+ async function es({
2788
+ layerId: e,
2789
+ fields: r,
2790
+ colorSchemes: t
2791
+ }, a) {
2792
+ const { mapView: o } = F(a);
2793
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, a), await Xo({
2794
+ arcgisMap: o.map,
2795
+ arcgisMapView: o,
2796
+ layerId: e,
2797
+ fields: r,
2798
+ colorSchemes: t
2799
+ });
2800
+ }
2801
+ const ts = i.object({
2802
+ layerId: i.string().describe("The id of the layer to apply the relationship renderer to"),
2803
+ fields: i.array(i.string()).describe("The two fields to use for the relationship renderer (bivariate visualization)"),
2804
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use")
2805
+ }), rs = f(es, {
2806
+ name: "relationship",
2807
+ description: `Label: Relationship
2808
+ Description: Overlays two color ramps to represent the relationship between two numeric attributes.
2809
+ Keywords: relationship, correlation, compare, related, bivariate choropleth, bivariate color
2810
+ Example: Show the relationship between tree height and carbon storage
2811
+ Fields: This style requires two number fields.`,
2812
+ schema: ts
2813
+ });
2814
+ function as(e) {
2815
+ const { fields: r, layer: t, view: a, theme: o } = e, s = r[0];
2816
+ return {
2817
+ layer: t,
2818
+ view: a,
2819
+ startTime: s,
2820
+ endTime: /* @__PURE__ */ new Date(),
2821
+ theme: o,
2822
+ sizeOptimizationEnabled: !0,
2823
+ outlineOptimizationEnabled: !0
2824
+ };
2825
+ }
2826
+ async function os(e) {
2827
+ return await nt(e);
2828
+ }
2829
+ async function ss({
2830
+ arcgisMap: e,
2831
+ arcgisMapView: r,
2832
+ layerId: t,
2833
+ fields: a,
2834
+ colorSchemes: o,
2835
+ theme: s
2836
+ }) {
2837
+ const l = r, n = e?.allLayers.find((d) => d.id === t);
2838
+ if (!n)
2839
+ return `Could not find layer for id: ${t}`;
2840
+ const c = {
2841
+ styleName: "size-age",
2842
+ fields: a,
2843
+ layer: n,
2844
+ view: l,
2845
+ colorSchemeTags: o,
2846
+ theme: s
2847
+ };
2848
+ try {
2849
+ const d = as(c), u = await os(d);
2850
+ return n.renderer = u.renderer, n.visible = !0, `Size-age renderer applied to layer: ${n.title ?? n.id} using fields ${a.join(", ")}`;
2851
+ } catch (d) {
2852
+ return `Error applying size-age renderer: ${d instanceof Error ? d.message : String(d)}`;
2853
+ }
2854
+ }
2855
+ async function is({
2856
+ layerId: e,
2857
+ fields: r,
2858
+ colorSchemes: t,
2859
+ theme: a
2860
+ }, o) {
2861
+ const { mapView: s } = F(o);
2862
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, o), await ss({
2863
+ arcgisMap: s.map,
2864
+ arcgisMapView: s,
2865
+ layerId: e,
2866
+ fields: r,
2867
+ colorSchemes: t,
2868
+ theme: a
2869
+ });
2870
+ }
2871
+ const ns = i.object({
2872
+ layerId: i.string().describe("The id of the layer to apply the size-age renderer to"),
2873
+ fields: i.array(i.string()).describe("The field(s) to use for the size-age renderer (temporal data with size)"),
2874
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use"),
2875
+ theme: i.enum(["above-and-below", "above", "below", "centered-on", "extremes", "high-to-low"]).optional().describe("Optional theme for the size ramp")
2876
+ }), ls = f(is, {
2877
+ name: "size-age",
2878
+ description: `Label: Age (size)
2879
+ Description: Vary symbol sizes along a continuous ramp to represent the age of features. Age reflects the length of time from a start date to an end date.
2880
+ Keywords: since, age, how old, how long
2881
+ Example: Change the size of features so older features are larger than new features.
2882
+ Fields: This style requires at least one field with a date type.`,
2883
+ schema: ns
2884
+ });
2885
+ function cs(e) {
2886
+ const { fields: r, layer: t, view: a } = e;
2887
+ let { theme: o } = e, s = r[1];
2888
+ const l = r[0];
2889
+ return {
2890
+ layer: t,
2891
+ view: a,
2892
+ field: l,
2893
+ normalizationField: s,
2894
+ theme: o,
2895
+ sizeOptimizationEnabled: !0,
2896
+ outlineOptimizationEnabled: !0
2897
+ };
2898
+ }
2899
+ async function ds(e) {
2900
+ return await lt(e);
2901
+ }
2902
+ async function us({
2903
+ arcgisMap: e,
2904
+ arcgisMapView: r,
2905
+ layerId: t,
2906
+ fields: a,
2907
+ colorSchemes: o,
2908
+ theme: s
2909
+ }) {
2910
+ const l = r, n = e?.allLayers.find((d) => d.id === t);
2911
+ if (!n)
2912
+ return `Could not find layer for id: ${t}`;
2913
+ const c = {
2914
+ styleName: "size",
2915
+ fields: a,
2916
+ layer: n,
2917
+ view: l,
2918
+ colorSchemeTags: o,
2919
+ theme: s
2920
+ };
2921
+ try {
2922
+ const d = cs(c), u = await ds(d);
2923
+ return n.renderer = u.renderer, n.visible = !0, `Size renderer applied to layer: ${n.title ?? n.id} using fields ${a.join(", ")}`;
2924
+ } catch (d) {
2925
+ return `Error applying size renderer: ${d instanceof Error ? d.message : String(d)}`;
2926
+ }
2927
+ }
2928
+ async function hs({
2929
+ layerId: e,
2930
+ fields: r,
2931
+ colorSchemes: t,
2932
+ theme: a
2933
+ }, o) {
2934
+ const { mapView: s } = F(o);
2935
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, o), await us({
2936
+ arcgisMap: s.map,
2937
+ arcgisMapView: s,
2938
+ layerId: e,
2939
+ fields: r,
2940
+ colorSchemes: t,
2941
+ theme: a
2942
+ });
2943
+ }
2944
+ const ms = i.object({
2945
+ layerId: i.string().describe("The id of the layer to apply the size renderer to"),
2946
+ fields: i.array(i.string()).describe("The field(s) to use for the size renderer (numeric data)"),
2947
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use"),
2948
+ theme: i.enum(["above-and-below", "above", "below", "centered-on", "extremes", "high-to-low"]).optional().describe("Optional theme for the size ramp")
2949
+ }), ys = f(hs, {
2950
+ name: "size",
2951
+ description: `Label: Counts and Amounts (size)
2952
+ Description: Vary symbol sizes along a continuous ramp to represent numeric or ranked data.
2953
+ Keywords: graduated size, proportional size, how much, total, number, amount, size
2954
+ Example: Vary the size of each point based on the total population.
2955
+ Fields: This style requires a single field with a number type. A second number field may be specified for normalizing the value of the first field.
2956
+
2957
+ Label: Continuous Timeline (size)
2958
+ Description: Vary symbol sizes along a continuous ramp to represent dates.
2959
+ Keywords: graduated size, proportional size, classed size, how much, total, number, when
2960
+ Example: Vary the size of each feature based on the date a ticket was completed.
2961
+ Fields: This style requires a single field with a date type.`,
2962
+ schema: ms
2963
+ });
2964
+ function ps(e) {
2965
+ const { fields: r, layer: t, view: a, colorSchemeTags: o } = e;
2966
+ console.log("processTypeRendererParams", e);
2967
+ const s = r[0], l = r[1], n = r[2];
2968
+ let c;
2969
+ return o && (c = dt({
2970
+ geometryType: t.geometryType,
2971
+ includedTags: o
2972
+ })[0]), {
2973
+ layer: t,
2974
+ view: a,
2975
+ field: s,
2976
+ field2: l,
2977
+ field3: n,
2978
+ outlineOptimizationEnabled: !0,
2979
+ sizeOptimizationEnabled: !0,
2980
+ typeScheme: c
2981
+ };
2982
+ }
2983
+ async function gs(e) {
2984
+ return await ct(e);
2985
+ }
2986
+ async function fs({
2987
+ arcgisMap: e,
2988
+ arcgisMapView: r,
2989
+ layerId: t,
2990
+ fields: a,
2991
+ colorSchemes: o,
2992
+ theme: s
2993
+ }) {
2994
+ const l = r, n = e?.allLayers.find((d) => d.id === t);
2995
+ if (!n)
2996
+ return `Could not find layer for id: ${t}`;
2997
+ const c = {
2998
+ styleName: "type",
2999
+ fields: a,
3000
+ layer: n,
3001
+ view: l,
3002
+ colorSchemeTags: o,
3003
+ theme: s
3004
+ };
3005
+ try {
3006
+ const d = ps(c), u = await gs(d);
3007
+ return n.renderer = u.renderer, n.visible = !0, `Type renderer applied to layer: ${n.title ?? n.id} using fields ${a.join(", ")}`;
3008
+ } catch (d) {
3009
+ return `Error applying type renderer: ${d instanceof Error ? d.message : String(d)}`;
3010
+ }
3011
+ }
3012
+ async function ws({
3013
+ layerId: e,
3014
+ fields: r,
3015
+ colorSchemes: t,
3016
+ theme: a
3017
+ }, o) {
3018
+ const { mapView: s } = F(o);
3019
+ return await E({ id: "show-legend", description: "Show Legend", payload: { layerIds: [e] } }, o), await fs({
3020
+ arcgisMap: s.map,
3021
+ arcgisMapView: s,
3022
+ layerId: e,
3023
+ fields: r,
3024
+ colorSchemes: t,
3025
+ theme: a
3026
+ });
3027
+ }
3028
+ const bs = i.object({
3029
+ layerId: i.string().describe("The id of the layer to apply the type renderer to"),
3030
+ fields: i.array(i.string()).describe("The field(s) to use for the type renderer (categorical data)"),
3031
+ colorSchemes: i.array(i.string()).optional().describe("Optional color scheme tags to use"),
3032
+ theme: i.enum(["above-and-below", "above", "below", "centered-on", "extremes", "high-to-low"]).optional().describe("Optional theme for the color scheme")
3033
+ }), Ss = f(ws, {
3034
+ name: "type",
3035
+ description: `Label: Types (unique symbols)
3036
+ Description: Represent features as categories with different symbol colors or shapes. Examples include type of tree, road class, or province name.
3037
+ Keywords: categorical, category, type, unique, discrete, point of interest, region, group
3038
+ Example: Color each feature based on the region it belongs to
3039
+ Fields: This style requires a single field which may be a string, number, or date type. It is usually a string.`,
3040
+ schema: bs
3041
+ }), je = [
3042
+ yo,
3043
+ So,
3044
+ Fo,
3045
+ zo,
3046
+ Mo,
3047
+ Bo,
3048
+ Ko,
3049
+ rs,
3050
+ ls,
3051
+ ys,
3052
+ Ss
3053
+ ], vs = async (e, r) => {
3054
+ await m({ text: "Requesting LLM for layer query results" }, r);
3055
+ const t = await $("navigation_intent_prompt");
3056
+ if (!r?.configurable)
3057
+ throw new Error("config.configurable is required for layer query tools");
3058
+ const a = {
3059
+ layerFieldInfo: e.layerFieldInfo
3060
+ }, o = await N({
3061
+ promptText: t,
3062
+ messages: v(e.messages),
3063
+ inputVariables: a,
3064
+ tools: je
3065
+ });
3066
+ return await Q(o, r), { ...e, messages: [...e.messages, o] };
3067
+ };
3068
+ async function Ts(e, r) {
3069
+ const a = await new A(je).invoke(
3070
+ {
3071
+ messages: v(e.messages)
3072
+ },
3073
+ r
3074
+ ), o = a.messages.map((l) => l.text).join(`
3075
+ `);
3076
+ await m({ text: `Finished executing layer filter tool: ${o}` }, r);
3077
+ const s = a.messages.map((l) => l.text).join(`
3078
+ `);
3079
+ return { ...e, outputMessage: s };
3080
+ }
3081
+ const _e = g.Root({
3082
+ // Inputs coming from global context
3083
+ messages: g({
3084
+ reducer: j,
3085
+ default: () => []
3086
+ }),
3087
+ // Accumulates user-visible output across graph nodes.
3088
+ // Uses append semantics, but de-duplicates identical consecutive writes.
3089
+ // This avoids duplicate output when tool nodes and final LLM nodes
3090
+ // emit the same text during a single agent turn.
3091
+ outputMessage: g({
3092
+ reducer: (e = "", r) => {
3093
+ const t = typeof r == "string" ? r.trim() : "";
3094
+ if (!t)
3095
+ return e;
3096
+ const a = e.trim();
3097
+ if (!a)
3098
+ return t;
3099
+ if (a === t)
3100
+ return e;
3101
+ const o = a.split(`
3102
+
3103
+ `);
3104
+ return o[o.length - 1]?.trim() === t ? e : `${e}
3105
+
3106
+ ${t}`;
3107
+ },
3108
+ default: () => ""
3109
+ }),
3110
+ vectorSearchLayerIds: g(),
3111
+ vectorSearchFieldResults: g(),
3112
+ layerFieldInfo: g(),
3113
+ selectedLayerId: g()
3114
+ }), xs = async (e, r) => (await m({ text: "Exiting Layer Styling agent" }, r), e), Es = async (e, r) => {
3115
+ try {
3116
+ await m({ text: "Populating layer and field info" }, r);
3117
+ const t = [];
3118
+ for (const a of e.vectorSearchFieldResults) {
3119
+ let o = function(u) {
3120
+ const h = n.get(u)?.layerItem;
3121
+ return h ? [
3122
+ h.name && `Name: ${h.name}`,
3123
+ h.title && `Title: ${h.title}`,
3124
+ h.description && `Description: ${h.description}`
3125
+ ].filter(Boolean).join(" | ") : u;
3126
+ };
3127
+ const { layerId: s, results: l } = a, n = S(r, "layersAndFieldsRegistry"), c = n.get(s)?.fieldRegistry;
3128
+ if (!c)
3129
+ continue;
3130
+ let d = t.find((u) => u.layerId === s);
3131
+ d || (d = {
3132
+ layerId: s,
3133
+ layerSummary: o(s),
3134
+ fieldInfos: []
3135
+ }, t.push(d));
3136
+ for (const u of l) {
3137
+ const h = c.get(u.name);
3138
+ h && d.fieldInfos.push(h);
3139
+ }
3140
+ }
3141
+ return console.log("Populated layerFieldInfo:", t), await m({ text: "Populated layerFieldInfo" }, r), { ...e, layerFieldInfo: t };
3142
+ } catch (t) {
3143
+ throw await m({ text: "Error populating layerFieldInfo" }, r), new Error(`Error populating layerFieldInfo: ${t instanceof Error ? t.message : String(t)}`);
3144
+ }
3145
+ }, $s = (e, r) => {
3146
+ const t = e.vectorSearchLayerIds ?? [];
3147
+ if (t.length <= 1)
3148
+ return { ...e, selectedLayerId: e.vectorSearchLayerIds[0] };
3149
+ const { hitlResponse: a } = r.configurable;
3150
+ if (console.log("hitlResponse:", a), !a || a.agentId !== fe.id || a.id !== "reviewLayerSelection") {
3151
+ const s = {
3152
+ agentId: fe.id,
3153
+ id: "reviewLayerSelection",
3154
+ kind: "singleSelection",
3155
+ message: "Choose a layer to apply the styles.",
3156
+ metadata: [...t]
3157
+ };
3158
+ throw new Oe(s);
3159
+ }
3160
+ let o = null;
3161
+ return Array.isArray(a.payload) && a.payload.length > 0 && (o = a.payload[0]), {
3162
+ ...e,
3163
+ selectedLayerId: o ?? e.vectorSearchLayerIds[0]
3164
+ };
3165
+ }, Fs = (e, r) => D(["layerSearch", "fieldSearch", "layersAndFieldsRegistry"], "Layer Styling Agent")(e, r), Rs = () => new _(_e).addNode("requireLayerStylingServices", Fs).addNode("vectorSearchLayers", io).addNode("layerSelectionHITL", $s).addNode("vectorSearchFields", oo).addNode("populateLayerFieldInfo", Es).addNode("agent", vs).addNode("tools", Ts).addNode("earlyExit", xs).addEdge(M, "requireLayerStylingServices").addEdge("requireLayerStylingServices", "vectorSearchLayers").addConditionalEdges(
3166
+ "layerSelectionHITL",
3167
+ (r) => r.vectorSearchLayerIds.length ? "vectorSearchFields" : "earlyExit"
3168
+ ).addConditionalEdges(
3169
+ "vectorSearchFields",
3170
+ (r) => r.vectorSearchFieldResults.length ? "populateLayerFieldInfo" : "earlyExit"
3171
+ ).addEdge("populateLayerFieldInfo", "agent").addEdge("agent", "tools").addEdge("tools", x).addEdge("earlyExit", x), Ls = 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.
3172
+ _Example: “Color points by sales amount”_
3173
+ _Example: “Show population density with a color gradient”_
3174
+ _Example: “Create a relationship map between height and depth”_
3175
+ _Example: “Vary circle sizes according to population”_`, fe = {
3176
+ id: "layerStyling",
3177
+ name: "Layer Styling Agent",
3178
+ description: Ls,
3179
+ createGraph: Rs,
3180
+ workspace: _e
3181
+ }, Me = g.Root({
3182
+ // messages: comes from global chat history.
3183
+ // It is safe to append new messages locally, but existing message objects
3184
+ // must be treated as read-only and never mutated.
3185
+ messages: g({
3186
+ reducer: j,
3187
+ default: () => []
3188
+ }),
3189
+ // Accumulates user-visible output across graph nodes.
3190
+ // Uses append semantics, but de-duplicates identical consecutive writes.
3191
+ // This avoids duplicate output when tool nodes and final LLM nodes
3192
+ // emit the same text during a single agent turn.
3193
+ outputMessage: g({
3194
+ reducer: (e = "", r) => {
3195
+ const t = typeof r == "string" ? r.trim() : "";
3196
+ if (!t)
3197
+ return e;
3198
+ const a = e.trim();
3199
+ if (!a)
3200
+ return t;
3201
+ if (a === t)
3202
+ return e;
3203
+ const o = a.split(`
3204
+
3205
+ `);
3206
+ return o[o.length - 1]?.trim() === t ? e : `${e}
3207
+
3208
+ ${t}`;
3209
+ },
3210
+ default: () => ""
3211
+ }),
3212
+ intent: g({
3213
+ reducer: (e, r) => r
3214
+ })
3215
+ }), Is = ["linkChartView"];
3216
+ function Ve(e) {
3217
+ const t = e?.configurable?.context;
3218
+ if (!t || typeof t != "object")
3219
+ throw new Error("LinkChartAgent context missing");
3220
+ const a = Is.filter((o) => !(o in t));
3221
+ if (a.length)
3222
+ throw new Error(`Link Chart context missing: ${a.join(", ")}`);
3223
+ return t;
3224
+ }
3225
+ async function qs(e, r) {
3226
+ return await r.map.applyLayout(e), `Successfully applied layout: ${e}.`;
3227
+ }
3228
+ async function Cs({ layout: e }, r) {
3229
+ const { linkChartView: t } = Ve(r);
3230
+ return await qs(e, t);
3231
+ }
3232
+ const zs = i.object({
3233
+ layout: i.enum([
3234
+ "organic-standard",
3235
+ "organic-community",
3236
+ "basic-grid",
3237
+ "hierarchical-bottom-to-top",
3238
+ "radial-root-centric",
3239
+ "tree-left-to-right",
3240
+ "geographic-organic-standard",
3241
+ "chronological-mono-timeline",
3242
+ "chronological-multi-timeline"
3243
+ ]).describe(
3244
+ "The layout mode to apply to the link chart. The value must be one of the following: organic-standard, organic-community, basic-grid, hierarchical-bottom-to-top, radial-root-centric, tree-left-to-right, geographic-organic-standard, chronological-mono-timeline, chronological-multi-timeline"
3245
+ )
3246
+ }), Ns = f(Cs, {
3247
+ name: "applyLayout",
3248
+ description: "Apply a diagram layout to the link chart",
3249
+ schema: zs
3250
+ });
3251
+ function As(e, r) {
3252
+ return r.map.changeNonspatialDataDisplay(e), `Successfully applied nonspatial visibility setting: ${e}.`;
3253
+ }
3254
+ function ks({ setting: e }, r) {
3255
+ const { linkChartView: t } = Ve(r);
3256
+ return As(e, t);
3257
+ }
3258
+ const js = i.object({
3259
+ setting: i.enum(["hidden", "visible"]).describe("The setting of nonspatial visibility")
3260
+ }), _s = f(ks, {
3261
+ name: "changeNonspatialVisibility",
3262
+ description: "Change whether or not nonspatial data is visible in the link chart. The value must be either 'hidden' or 'visible'.",
3263
+ schema: js
3264
+ }), ce = [Ns, _s];
3265
+ async function Ms(e, r) {
3266
+ const t = await $("link_chart_tool_prompt"), a = {
3267
+ intent: e.intent
3268
+ }, o = await N({
3269
+ promptText: t,
3270
+ messages: v(e.messages),
3271
+ inputVariables: a,
3272
+ tools: ce
3273
+ }), s = [...e.messages, o], n = (o.tool_calls?.length ?? 0) > 0 ? [...s] : [...s, o];
3274
+ return { ...e, messages: n };
3275
+ }
3276
+ async function Vs(e, r) {
3277
+ const a = await new A(ce).invoke(
3278
+ {
3279
+ messages: v(e.messages)
3280
+ },
3281
+ r
3282
+ ), o = a.messages.map((n) => n.text).join(`
3283
+ `);
3284
+ await m({ text: `Finished executing linkChart tool: ${o}` }, r);
3285
+ const s = [...e.messages, ...a.messages], l = a.messages.map((n) => n.text).join(`
3286
+ `);
3287
+ return { ...e, messages: s, outputMessage: l };
3288
+ }
3289
+ async function Ds(e) {
3290
+ const r = await $("link_chart_intent_prompt"), a = {
3291
+ tools: ce.map((n) => ({
3292
+ name: n.name,
3293
+ description: n.description,
3294
+ schema: n.schema
3295
+ })).map(({ name: n, description: c, schema: d }) => `${n}: ${c}, ${JSON.stringify(d)}`).join(`
3296
+ `)
3297
+ }, o = i.object({
3298
+ intent: i.string()
3299
+ }), s = await we({
3300
+ promptText: r,
3301
+ messages: v(e.messages),
3302
+ inputVariables: a,
3303
+ schema: o
3304
+ }), l = typeof s.intent == "string" ? s.intent.trim().replace(/^"|"$/gu, "") : "";
3305
+ return { ...e, intent: l || "" };
3306
+ }
3307
+ const Qs = (e, r) => (
3308
+ //agent services (ex: embeddingsWorker) would go in the array below, if required.
3309
+ D([], "LinkChart Agent")(e, r)
3310
+ ), Os = () => new _(Me).addNode("requireLinkChartServices", Qs).addNode("intentLLM", Ds).addNode("agent", Ms).addNode("tools", Vs).addEdge(M, "requireLinkChartServices").addEdge("requireLinkChartServices", "intentLLM").addEdge("intentLLM", "agent").addConditionalEdges("agent", (r) => {
3311
+ const t = r.messages[r.messages.length - 1];
3312
+ return t?.getType() === "ai" && "tool_calls" in t && Array.isArray(t.tool_calls) && t.tool_calls.length > 0 ? "tools" : x;
3313
+ }).addEdge("tools", x), Ps = String.raw`Enables users to interact with a link chart by adding new entities (also called nodes) or relationships (also called edges), removing existing entities or relationships,
3314
+ expanding the graph from particular entities, finding relationships between specified entities on the link chart and adding them to the link chart, finding all relationships
3315
+ that exist out from specified entities and adding those to the link chart, changing whether or not nonspatial data is visible, or changing the layout of the link chart.
3316
+ This agent is designed to handle requests that manipulate the specific link chart.
3317
+
3318
+ Supported actions:
3319
+ - **Change or Apply Layout**: Changes the current layout visualization strategy of the link chart (e.g., "Change the layout to basic-grid", "Apply hierarchical layout"). Valid layout types include organic-standard, organic-community, basic-grid, hierarchical-bottom-to-top, radial-root-centric, tree-left-to-right, geographic-organic-standard, chronological-mono-timeline. A best effort should be made to transform the user's request into one of these layout types.
3320
+ - **Change Nonspatial Data Visibility**: Changes whether or not nonspatial data is visible on the link chart (e.g., "Show nonspatial data", "Hide nonspatial data"). Valid settings are "hidden" and "visible". A best effort should be made to transform the user's request into one of these settings.
3321
+ - **Add Records (entities or relationships)**: NYI
3322
+ - **Remove Records (entities or relationships)**: NYI
3323
+ - **Expand from Entities**: NYI
3324
+ - **Find Relationships Between Entities**: NYI
3325
+ - **Find all Relationships Out from Entities**: NYI
3326
+
3327
+ _example: "Change the layout to hierarchical-bottom-to-top"_
3328
+ _example: "Apply radial-root-centric layout"_
3329
+ _example: "Show nonspatial data"_
3330
+ _example: "Hide nonspatial data"_
3331
+ _example: "Turn off nonspatial visibility"_`, Ii = {
3332
+ id: "linkChart",
3333
+ name: "LinkChart Agent",
3334
+ description: Ps,
3335
+ createGraph: Os,
3336
+ workspace: Me
3337
+ };
3338
+ export {
3339
+ Fi as DataExplorationAgent,
3340
+ Ri as LayerFilterAgent,
3341
+ Li as LayerQueryAgent,
3342
+ fe as LayerStylingAgent,
3343
+ Ii as LinkChartAgent,
3344
+ $i as NavigationAgent
3345
+ };