@arcgis/ai-components 5.0.0-next.139 → 5.0.0-next.141
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +2 -2
- package/dist/cdn/{HBQRKPCT.js → 2IKIZBUH.js} +2 -2
- package/dist/cdn/{D532Z7XU.js → 5HRRKEE4.js} +2 -2
- package/dist/cdn/{LZRFQZSB.js → 5UOB4H2A.js} +1 -1
- package/dist/cdn/{HA4E5AC2.js → 7MRF4WET.js} +2 -2
- package/dist/cdn/{5BR5YVZ6.js → 7YKK77E7.js} +2 -2
- package/dist/cdn/{LWPYJABR.js → AVZUVYVX.js} +2 -2
- package/dist/cdn/{72JQRHOG.js → BU5VWLVE.js} +2 -2
- package/dist/cdn/{Z5SVRVZN.js → CB2PODD7.js} +2 -2
- package/dist/cdn/{RYLC4RYQ.js → DD4BMSWI.js} +2 -2
- package/dist/cdn/{CLP7HMEW.js → EPU4I3W4.js} +2 -2
- package/dist/cdn/{GNIBW6BM.js → F6UDKJ6F.js} +2 -2
- package/dist/cdn/FKEUC44C.js +4 -0
- package/dist/cdn/{UJTPKXBP.js → G3K3GRB2.js} +33 -33
- package/dist/cdn/{6UMV2K64.js → G6BVI2XX.js} +2 -2
- package/dist/cdn/GERMHSWI.js +4 -0
- package/dist/cdn/{NSMIL2SL.js → H3CVMHP7.js} +1 -1
- package/dist/cdn/{RHI6IEK3.js → I2UQJD5X.js} +2 -2
- package/dist/cdn/IJ45EDHD.js +43 -0
- package/dist/cdn/IOV4MOIL.js +32 -0
- package/dist/cdn/{3FXMITU4.js → IPYRSZ5V.js} +2 -2
- package/dist/cdn/{E3XZJC24.js → JPTOZPR4.js} +2 -2
- package/dist/cdn/{YKVAJ4AV.js → JRPAEWR6.js} +2 -2
- package/dist/cdn/{JLY2B5AJ.js → K7MLZAMJ.js} +2 -2
- package/dist/cdn/{QS6457MX.js → KIXLFZXK.js} +2 -2
- package/dist/cdn/{42IBUNOA.js → LLYWEDKO.js} +2 -2
- package/dist/cdn/{UPQ7HXXV.js → MPRS2EHZ.js} +2 -2
- package/dist/cdn/{CFFB4JKG.js → QO5G3EUA.js} +2 -2
- package/dist/cdn/{WCFPWMZ6.js → SB67G4Q4.js} +2 -2
- package/dist/cdn/SCG7VRZ4.js +6 -0
- package/dist/cdn/{TFW2C2V3.js → SCXQGMCX.js} +2 -2
- package/dist/cdn/{B4GME3XE.js → SEVNR22P.js} +2 -2
- package/dist/cdn/{6JDNCSC3.js → T2J3AABV.js} +2 -2
- package/dist/cdn/{RQY4555K.js → TJDDZDQ4.js} +2 -2
- package/dist/cdn/VV7LNFJC.js +134 -0
- package/dist/cdn/{TJJX6UKQ.js → W4CBQGNN.js} +2 -2
- package/dist/cdn/{DBKCPK5I.js → WMC3UR5F.js} +49 -32
- package/dist/cdn/{3QTHBF2F.js → XBO2KI27.js} +2 -2
- package/dist/cdn/{IXKVVRW7.js → XIQFWAFC.js} +1 -1
- package/dist/cdn/{IB7MSLQX.js → XOTBUNPJ.js} +2 -2
- package/dist/cdn/{RKR7CXWK.js → XQLOMET4.js} +2 -2
- package/dist/cdn/{GVW52DIA.js → YCG6EVNI.js} +2 -2
- package/dist/cdn/index.js +2 -2
- package/dist/chunks/runtime.js +1 -1
- package/dist/chunks/useT9n.js +1 -1
- package/dist/chunks/utils.js +1 -1
- package/dist/chunks/utils2.js +1 -1
- package/dist/components/arcgis-assistant/customElement.js +1 -1
- package/dist/components/arcgis-assistant-agent/customElement.js +1 -1
- package/dist/components/arcgis-assistant-chat/customElement.js +1 -1
- package/dist/components/arcgis-assistant-chat-card/customElement.js +1 -1
- package/dist/components/arcgis-assistant-chat-card-content/customElement.js +1 -1
- package/dist/components/arcgis-assistant-chat-entry/customElement.js +1 -1
- package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +1 -1
- package/dist/components/arcgis-assistant-interrupt/customElement.js +1 -1
- package/dist/components/arcgis-assistant-layer-filter-agent/customElement.js +1 -1
- package/dist/components/arcgis-assistant-layer-query-agent/customElement.js +1 -1
- package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +1 -1
- package/dist/components/arcgis-assistant-navigation-agent/customElement.js +1 -1
- package/dist/components/arcgis-assistant-shell/customElement.js +1 -1
- package/dist/docs/api.json +1 -1
- package/dist/docs/docs.json +1 -1
- package/dist/docs/web-types.json +1 -1
- package/dist/index.js +1 -1
- package/dist/loader.js +1 -1
- package/package.json +7 -7
- package/dist/cdn/BN3XKJOK.js +0 -6
- package/dist/cdn/ILSPDWE2.js +0 -4
- package/dist/cdn/X5OTOFCC.js +0 -134
- package/dist/cdn/YQJWHNVD.js +0 -4
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
2
2
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
3
|
-
v5.0.0-next.
|
|
4
|
-
import"./
|
|
3
|
+
v5.0.0-next.141 */
|
|
4
|
+
import"./H3CVMHP7.js";var e=`# ArcGIS JavaScript SDK FeatureLayerView Query Assistant
|
|
5
5
|
|
|
6
6
|
You are a GIS assistant that generates query parameters for the ArcGIS JavaScript SDK FeatureLayerView \`queryFeatures()\` method.
|
|
7
7
|
|
|
@@ -1,28 +1,28 @@
|
|
|
1
1
|
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
2
2
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
3
|
-
v5.0.0-next.
|
|
4
|
-
import a from"./
|
|
5
|
-
Please fix your mistakes.`,name:r.name,tool_call_id:r.id??""})}}async run(r,t){let a;if(Ke(r))a=[await this.runTool(r.lg_tool_call,t)];else{let s;if(ve(r))s=r;else if(
|
|
3
|
+
v5.0.0-next.141 */
|
|
4
|
+
import a from"./VV7LNFJC.js";import{Fa as N,J as O,M as Z,Q as j,aa as K}from"./G3K3GRB2.js";export default $arcgis.t(([tt,oe,Ne,rt,{addressToLocations:at},Re,V,U,ie,ne,Ae,qe,se,ke,{createRenderer:ot},{getSchemesByTag:it,getSchemes:nt},{getBackgroundColorTheme:Te},{createAgeRenderer:st,createContinuousRenderer:lt},{getSchemesByTag:le},{createContinuousRenderer:ct},{createRenderer:dt},{getSchemesByTag:ut},{createRenderer:mt},{getSchemesByTag:ht},{createRenderer:ft},{getSchemesByTag:gt},{createRenderer:yt},{getSchemesByTag:pt},{createAgeRenderer:wt,createContinuousRenderer:bt},{createRenderer:St},{getSchemesByTag:vt},{a:ge,b:ye,c:p,d:g,e:n,f:R,g:x,h:pe,i:G,j:W,k:we,l:A,m:$,n:m,o:E,p:Y,q:be,r:C}])=>{var ve=e=>Array.isArray(e)&&e.every(O),Ze=e=>typeof e=="object"&&e!=null&&"messages"in e&&ve(e.messages),Ke=e=>typeof e=="object"&&e!=null&&"lg_tool_call"in e,L=class extends we{constructor(r,t){let{name:a,tags:o,handleToolErrors:i}=t??{};super({name:a,tags:o,func:(s,l)=>this.run(s,l)}),Object.defineProperty(this,"tools",{enumerable:!0,configurable:!0,writable:!0,value:void 0}),Object.defineProperty(this,"handleToolErrors",{enumerable:!0,configurable:!0,writable:!0,value:!0}),Object.defineProperty(this,"trace",{enumerable:!0,configurable:!0,writable:!0,value:!1}),this.tools=r,this.handleToolErrors=i??this.handleToolErrors}async runTool(r,t){let a=this.tools.find(o=>o.name===r.name);try{if(a===void 0)throw new Error(`Tool "${r.name}" not found.`);let o=await a.invoke({...r,type:"tool_call"},t);return O(o)&&o.getType()==="tool"||W(o)?o:new Z({status:"success",name:a.name,content:typeof o=="string"?o:JSON.stringify(o),tool_call_id:r.id})}catch(o){if(!this.handleToolErrors||ye(o))throw o;return new Z({status:"error",content:`Error: ${o.message}
|
|
5
|
+
Please fix your mistakes.`,name:r.name,tool_call_id:r.id??""})}}async run(r,t){let a;if(Ke(r))a=[await this.runTool(r.lg_tool_call,t)];else{let s;if(ve(r))s=r;else if(Ze(r))s=r.messages;else throw new Error("ToolNode only accepts BaseMessage[] or { messages: BaseMessage[] } as input.");let l=new Set(s.filter(c=>c.getType()==="tool").map(c=>c.tool_call_id)),d;for(let c=s.length-1;c>=0;c-=1){let u=s[c];if(u.getType()==="ai"){d=u;break}}if(d?.getType()!=="ai")throw new Error("ToolNode only accepts AIMessages as input.");a=await Promise.all(d.tool_calls?.filter(c=>c.id==null||!l.has(c.id)).map(c=>this.runTool(c,t))??[])}if(!a.some(W))return Array.isArray(r)?a:{messages:a};let o=[],i=null;for(let s of a)W(s)?s.graph===G.PARENT&&Array.isArray(s.goto)&&s.goto.every(l=>pe(l))?i?i.goto.push(...s.goto):i=new G({graph:G.PARENT,goto:s.goto}):o.push(s):o.push(Array.isArray(r)?[s]:{messages:[s]});return i&&o.push(i),o}};var Rn=g.Root({llmInputMessages:g({reducer:(e,r)=>$([],r),default:()=>[]})});var ze=g.Root({messages:g({reducer:$,default:()=>[]}),outputMessage:g({reducer:(e="",r)=>{let t=typeof r=="string"?r.trim():"";if(!t)return e;let a=e.trim();if(!a)return t;if(a===t)return e;let o=a.split(`
|
|
6
6
|
|
|
7
7
|
`);return o[o.length-1]?.trim()===t?e:`${e}
|
|
8
8
|
|
|
9
|
-
${t}`},default:()=>""}),intent:g({reducer:(e,r)=>r}),vectorSearchLayerResults:g({reducer:(e,r)=>r,default:()=>[]}),vectorSearchFieldResults:g({reducer:(e,r)=>r})});async function Tt(e,r){let t="https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer";console.log(`[goToAddress] Geocoding: ${e}`);let a=(await at(t,{address:{SingleLine:e},outFields:["Match_addr"]}))?.[0];if(!a?.extent)throw new Error(`Could not find location for: ${e}`);let{xmin:o,ymin:i,xmax:s,ymax:l,spatialReference:d}=a.extent,c=new Ne({xmin:o,ymin:i,xmax:s,ymax:l,spatialReference:d}),u=(o+s)/2,h=(i+l)/2,y=new oe({x:u,y:h,spatialReference:d}),f=new rt({style:"circle",color:"red",size:12}),w=new tt({geometry:y,symbol:f});return r.graphics.removeAll(),r.graphics.add(w),await r.goTo(c),`Successfully zoomed to: ${a.address}. Location coordinates: x=${u}, y=${h}, wkid=${d.wkid}`}var xt=["mapView"];function
|
|
9
|
+
${t}`},default:()=>""}),intent:g({reducer:(e,r)=>r}),vectorSearchLayerResults:g({reducer:(e,r)=>r,default:()=>[]}),vectorSearchFieldResults:g({reducer:(e,r)=>r})});async function Tt(e,r){let t="https://geocode.arcgis.com/arcgis/rest/services/World/GeocodeServer";console.log(`[goToAddress] Geocoding: ${e}`);let a=(await at(t,{address:{SingleLine:e},outFields:["Match_addr"]}))?.[0];if(!a?.extent)throw new Error(`Could not find location for: ${e}`);let{xmin:o,ymin:i,xmax:s,ymax:l,spatialReference:d}=a.extent,c=new Ne({xmin:o,ymin:i,xmax:s,ymax:l,spatialReference:d}),u=(o+s)/2,h=(i+l)/2,y=new oe({x:u,y:h,spatialReference:d}),f=new rt({style:"circle",color:"red",size:12}),w=new tt({geometry:y,symbol:f});return r.graphics.removeAll(),r.graphics.add(w),await r.goTo(c),`Successfully zoomed to: ${a.address}. Location coordinates: x=${u}, y=${h}, wkid=${d.wkid}`}var xt=["mapView"];function F(e){let r=e?.configurable?.context;if(!r||typeof r!="object")throw new Error("NavigationAgent context missing");let t=xt.filter(a=>!(a in r));if(t.length)throw new Error(`NavigationAgent context missing: ${t.join(", ")}`);return r}async function Et({address:e},r){let{mapView:t}=F(r);return await Tt(e,t)}var Lt=n.object({address:n.string().describe("The full address or place name to locate.")}),It=p(Et,{name:"goToAddress",description:"Geocodes an address using Esri's World Geocoding Service and zooms the map to that location.",schema:Lt});async function $t(e,r){let t=r.map.bookmarks;if(!t||t.length===0)throw new Error("No bookmarks found in the map.");let a=t.find(i=>i.name===e);if(!a)throw new Error(`Bookmark with name "${e}" not found.`);let o=a.viewpoint;if(!o)throw new Error(`Bookmark with name "${e}" does not have a valid viewpoint.`);return await r.goTo(o),`Navigated to bookmark: ${e}`}async function Ft({bookmarkName:e},r){let{mapView:t}=F(r);return await Promise.resolve($t(e,t))}var _t=N.object({bookmarkName:N.string().describe("The name of the bookmark to navigate to.")}),Nt=p(Ft,{name:"goToBookmark",description:"Go to the extent of the bookmark with the given name.",schema:_t});async function Rt(e,r,t){let a=t.map?.allLayers.find(i=>i.id===e);if(!a)return`Error: Layer with id ${e} not found`;let o=a.createQuery();o.where=r??"1=1";try{let{extent:i,count:s}=await a.queryExtent(o);if(s===0)return`No features found in ${a.title} matching: ${r}`;if(i)await t.goTo(i);else return`Error: Unable to determine extent for ${a.title}`;return`Successfully zoomed to ${s} feature(s) in ${a.title}`}catch(i){return console.error("Error in goToFeatures:",i),`Error: ${i instanceof Error?i.message:"Unknown error"}`}}async function At({layerId:e,where:r},t){let{mapView:a}=F(t);return await Rt(e,r,a)}var qt=N.object({layerId:N.string().describe("The layerId of the layer to zoom to."),where:N.string().describe("The sql-92 where clause used to query features to zoom to")}),kt=p(At,{name:"goToFeatures",description:"Go to the features that match the given filter related to the given layerId.",schema:qt});async function zt(e){let r=new Ne({xmin:-180,ymin:-90,xmax:180,ymax:90,spatialReference:{wkid:4326}}).expand(.7);return await e.goTo(r),"Successfully zoomed to world extent"}async function Mt(e,r){let{mapView:t}=F(r);return await zt(t)}var Ct=N.object({}),jt=p(Mt,{name:"goToFullExtent",description:"Zooms the map to the full world extent using Esri's Geocoding Service.",schema:Ct});async function Vt(e){let r=e.map.initialViewProperties?.viewpoint?.targetGeometry;if(r)await e.goTo(r);else throw new Error("Initial extent is undefined");return"Successfully zoomed to home extent"}async function Ot(e,r){let{mapView:t}=F(r);return await Vt(t)}var Dt=n.object({}),Bt=p(Ot,{name:"goToHomeExtent",description:"Go to the initial web map view extent",schema:Dt});async function Qt(e,r){await r.when();let t=r.map?.allLayers.find(o=>o.id===e);if(!t)return console.warn(`[goToLayer] No matching FeatureLayer found for: ${e}`),`Could not find layer for: ${e}`;console.log(`[goToLayer] Zooming to layer: ${t.title}`);let a=t.fullExtent;return a?(await r.goTo(a),t.visible=!0,`Successfully zoomed to: ${t.title??""}`):"Layer has no defined extent. Cannot zoom to layer."}async function Pt({layerId:e},r){let{mapView:t}=F(r);return await Qt(e,t)}var Gt=N.object({layerId:N.string().describe("The id of the layer to navigate to")}),Wt=p(Pt,{name:"goToLayer",description:"Zooms the map view to the full extent of the top matching layer.",schema:Gt});async function Ut(e,r){return await r.goTo({scale:e}),`Successfully zoomed to: ${e}`}async function Ht({scale:e},r){let{mapView:t}=F(r);return await Ut(e,t)}var Jt=n.object({scale:n.number().describe("The map scale of the view to go to.")}),Zt=p(Ht,{name:"goToScale",description:"Go to the specified view scale.",schema:Jt});async function Kt(e,r,t){let a={target:new oe({longitude:e.longitude,latitude:e.latitude,spatialReference:{wkid:4326}})};return t?.zoom!==void 0&&(a.zoom=t.zoom),t?.scale!==void 0&&(a.scale=t.scale),await r.goTo(a),`Successfully navigated to: ${[`(${e.latitude}\xB0, ${e.longitude}\xB0)`,t?.zoom!==void 0?`zoom ${t.zoom}`:"",t?.scale!==void 0?`scale 1:${t.scale}`:""].filter(Boolean).join(", ")}`}async function Yt({center:e,zoom:r,scale:t},a){let{mapView:o}=F(a);return await Kt(e,o,{zoom:r,scale:t})}var Xt=n.object({center:n.object({longitude:n.number().describe("The longitude (x-coordinate) of the point to navigate to."),latitude:n.number().describe("The latitude (y-coordinate) of the point to navigate to.")}),zoom:n.number().optional().describe("The zoom level. Higher values = more zoomed in."),scale:n.number().optional().describe("The map scale. Alternative to zoom. Smaller numbers = more zoomed in.")}),er=p(Yt,{name:"goToViewpoint",description:"Go to the specified viewpoint. This can contain a combination of scale, center, zoom, etc.",schema:Xt});async function tr(e,r){return await r.goTo({zoom:e}),`Successfully zoomed to: ${e}`}async function rr({zoom:e},r){let{mapView:t}=F(r);return await tr(e,t)}var ar=n.object({zoom:n.number().min(1).max(20).describe("The zoom level of the view to go to.")}),or=p(rr,{name:"goToZoom",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.).',schema:ar}),ce=[It,Nt,kt,jt,Bt,Wt,Zt,er,or],xe=Object.assign({"../agents/dataExploration/prompts/data_explore_filter_prompt.md":()=>import("./G6BVI2XX.js").then(e=>e.default),"../agents/dataExploration/prompts/data_explore_query_prompt.md":()=>import("./W4CBQGNN.js").then(e=>e.default),"../agents/dataExploration/prompts/summarize_query_response_prompt.md":()=>import("./IOV4MOIL.js").then(e=>e.default),"../agents/help/prompts/help_prompt.md":()=>import("./IJ45EDHD.js").then(e=>e.default),"../agents/layerFilter/prompts/layer_filter_prompt.md":()=>import("./F6UDKJ6F.js").then(e=>e.default),"../agents/layerQuery/prompts/data_query_prompt.md":()=>import("./EPU4I3W4.js").then(e=>e.default),"../agents/layerQuery/prompts/summarize_query_response_prompt.md":()=>import("./XQLOMET4.js").then(e=>e.default),"../agents/layerStyling/prompts/layer_styling_prompt.md":()=>import("./JPTOZPR4.js").then(e=>e.default),"../agents/linkChart/prompts/link_chart_intent_prompt.md":()=>import("./XBO2KI27.js").then(e=>e.default),"../agents/linkChart/prompts/link_chart_tool_prompt.md":()=>import("./DD4BMSWI.js").then(e=>e.default),"../agents/navigation/prompts/navigation_intent_prompt.md":()=>import("./IPYRSZ5V.js").then(e=>e.default),"../agents/navigation/prompts/navigation_tool_prompt.md":()=>import("./SEVNR22P.js").then(e=>e.default)});async function q(e){let r=Object.entries(xe).find(([t])=>t.endsWith(`/${e}.md`));if(console.log(`entry for prompt "${e}":`,r),!r)throw new Error(`Prompt not found: ${e}
|
|
10
10
|
Available prompts:
|
|
11
11
|
${Object.keys(xe).join(`
|
|
12
|
-
`)}`);return await r[1]()}var ir=(e,r=3)=>e.filter(t=>t instanceof K).slice(-r),S=(e,r=3)=>{let t=e.map((o,i)=>o instanceof K?i:-1).filter(o=>o!==-1);if(t.length===0)return[];let a=t.length>r?t[t.length-r]:t[0];return e.slice(a)},
|
|
12
|
+
`)}`);return await r[1]()}var ir=(e,r=3)=>e.filter(t=>t instanceof K).slice(-r),S=(e,r=3)=>{let t=e.map((o,i)=>o instanceof K?i:-1).filter(o=>o!==-1);if(t.length===0)return[];let a=t.length>r?t[t.length-r]:t[0];return e.slice(a)},_=(e,r=" ")=>ir(e).map(t=>t.content).join(r).trim();async function nr(e,r){let t=await q("navigation_tool_prompt"),{mapView:a}=F(r),o=a.map,i=e.vectorSearchLayerResults?.length>0?e.vectorSearchLayerResults.map((w,v)=>`${v+1}. layerId=${w.id} | title=${w.title??""} | name=${w.name??""} | score=${w.score.toFixed(2)}`).join(`
|
|
13
13
|
`):"",s=e.vectorSearchFieldResults?.length>0?JSON.stringify(e.vectorSearchFieldResults,null,2):"",l=e.intent==="goToBookmark"&&o.bookmarks?.length?`Available bookmarks:
|
|
14
14
|
${JSON.stringify(o.bookmarks,null,2)}`:"",d=(e.intent==="goToLayer"||e.intent==="goToFeatures")&&e.vectorSearchLayerResults?.length?`Candidate layers:
|
|
15
15
|
${i}`:"",c=e.intent==="goToFeatures"&&e.vectorSearchFieldResults?.length?`Candidate fields:
|
|
16
16
|
${s}`:"",u={intent:e.intent,bookmarksSection:l,layersSection:d,fieldsSection:c,currentZoom:a.zoom},h=await C({promptText:t,messages:S(e.messages),inputVariables:u,tools:ce}),y=[...e.messages,h],f=(h.tool_calls?.length??0)>0?[...y]:[...y,h];return{...e,messages:f}}async function sr(e,r){let t=await new L(ce).invoke({messages:S(e.messages)},r),a=t.messages.map(s=>s.text).join(`
|
|
17
17
|
`);await m({text:`Finished executing navigation tool: ${a}`},r);let o=[...e.messages,...t.messages],i=t.messages.map(s=>s.text).join(`
|
|
18
18
|
`);return{...e,messages:o,outputMessage:i}}async function lr(e){let r=await q("navigation_intent_prompt"),t={tools:ce.map(s=>({name:s.name,description:s.description,schema:s.schema})).map(({name:s,description:l,schema:d})=>`${s}: ${l}, ${JSON.stringify(d)}`).join(`
|
|
19
|
-
`)},a=n.object({intent:n.string()}),o=await be({promptText:r,modelTier:"fast",messages:S(e.messages),inputVariables:t,schema:a}),i=typeof o.intent=="string"?o.intent.trim().replace(/^"|"$/gu,""):"";return{...e,intent:i||""}}var b=(e,r)=>{let t=e?.configurable?.services?.[r];if(t==null)throw new Error(`${r} missing in config.configurable.services`);return t},cr=.7,dr=async(e,r)=>{try{let t=
|
|
19
|
+
`)},a=n.object({intent:n.string()}),o=await be({promptText:r,modelTier:"fast",messages:S(e.messages),inputVariables:t,schema:a}),i=typeof o.intent=="string"?o.intent.trim().replace(/^"|"$/gu,""):"";return{...e,intent:i||""}}var b=(e,r)=>{let t=e?.configurable?.services?.[r];if(t==null)throw new Error(`${r} missing in config.configurable.services`);return t},cr=.7,dr=async(e,r)=>{try{let t=_(e.messages);await m({text:`Similarity search to find layers: ${t}`},r);let a=b(r,"layerSearch"),o=b(r,"layersAndFieldsRegistry"),i=(await a.searchLayers({text:t,minScore:cr})).map(({id:l,score:d})=>{let c=o.get(l)?.layerItem;return{id:l,title:c?.title,name:c?.name??void 0,score:d}}),s;return i.length>0?s=`Vector search completed. Matching layers:
|
|
20
20
|
${i.map(l=>`- layerId=${l.id} | title=${l.title??""} | name=${l.name??""} | score=${l.score.toFixed(2)}`).join(`
|
|
21
|
-
`)}`:s="Vector search completed. No matching layers found.",await m({text:s},r),{...e,vectorSearchLayerResults:i}}catch(t){throw await m({text:`Error during vector search layers: ${t instanceof Error?t.message:String(t)}`},r),t}},Ee=.7,ur=10,mr=async(e,r)=>{try{let t=
|
|
21
|
+
`)}`:s="Vector search completed. No matching layers found.",await m({text:s},r),{...e,vectorSearchLayerResults:i}}catch(t){throw await m({text:`Error during vector search layers: ${t instanceof Error?t.message:String(t)}`},r),t}},Ee=.7,ur=10,mr=async(e,r)=>{try{let t=_(e.messages);await m({text:"Similarity search to find fields"},r);let a=b(r,"fieldSearch"),o=b(r,"layersAndFieldsRegistry"),i=e.vectorSearchLayerResults?.map(d=>d.id)??[];if(i.length===0)return await m({text:"No candidate layers for field search"},r),e;let s=(await a.searchFields({text:t,layerIds:i,minScore:Ee,topResults:ur})).map(({layerId:d,results:c})=>{let u=o.get(d)?.fieldRegistry;return{layerId:d,layerName:o.get(d)?.layerItem.name,results:c.map(h=>{let y=u?.get(h.name);return{name:h.name,score:h.score,type:y?.type,alias:y?.alias,description:y?.description,statistics:y?.statistics}})}}),l;return s.length>0?l=`Vector search completed. Matching layers and fields:
|
|
22
22
|
${s.map(d=>`${d.layerName??d.layerId}:
|
|
23
23
|
${d.results.map(c=>` - ${c.name} (${c.score.toFixed(2)})`).join(`
|
|
24
24
|
`)}`).join(`
|
|
25
|
-
`)}`:l=`No vector search field results found for score over ${Ee}.`,await m({text:l},r),{...e,vectorSearchFieldResults:s}}catch(t){throw await m({text:`Error during vector search fields: ${t instanceof Error?t.message:String(t)}`},r),t}},D=(e,r)=>(t,a)=>{let o=a?.configurable?.services;for(let i of e)if(!o?.[i])throw new Error(`${r} requires services.${i} to be available.`);return t},hr=(e,r)=>D(["layerSearch","layersAndFieldsRegistry"],"Navigation Agent")(e,r),fr=()=>new
|
|
25
|
+
`)}`:l=`No vector search field results found for score over ${Ee}.`,await m({text:l},r),{...e,vectorSearchFieldResults:s}}catch(t){throw await m({text:`Error during vector search fields: ${t instanceof Error?t.message:String(t)}`},r),t}},D=(e,r)=>(t,a)=>{let o=a?.configurable?.services;for(let i of e)if(!o?.[i])throw new Error(`${r} requires services.${i} to be available.`);return t},hr=(e,r)=>D(["layerSearch","layersAndFieldsRegistry"],"Navigation Agent")(e,r),fr=()=>new A(ze).addNode("requireNavigationServices",hr).addNode("intentLLM",lr).addNode("vectorSearchLayers",dr).addNode("vectorSearchFields",mr).addNode("agent",nr).addNode("tools",sr).addEdge(R,"requireNavigationServices").addEdge("requireNavigationServices","intentLLM").addConditionalEdges("intentLLM",e=>e.intent==="goToLayer"||e.intent==="goToFeatures"?"vectorSearchLayers":"agent",{vectorSearchLayers:"vectorSearchLayers",agent:"agent"}).addConditionalEdges("vectorSearchLayers",e=>e.intent==="goToFeatures"?"vectorSearchFields":"agent",{vectorSearchFields:"vectorSearchFields",agent:"agent"}).addEdge("vectorSearchFields","agent").addEdge("agent","tools").addEdge("tools",x),gr=String.raw`- **navigation** — Enables users to interact with the map by navigating to specific locations, layers, features, or extents.
|
|
26
26
|
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.
|
|
27
27
|
|
|
28
28
|
Supported actions:
|
|
@@ -40,19 +40,19 @@ ${d.results.map(c=>` - ${c.name} (${c.score.toFixed(2)})`).join(`
|
|
|
40
40
|
_Example: “Center the map on San Francisco at scale 50000”_
|
|
41
41
|
_Example: “Zoom to the features in the schools layer where city = 'Austin'”_
|
|
42
42
|
_Example: “Go to the Downtown bookmark”_
|
|
43
|
-
_Example: “Zoom to 1600 Pennsylvania Ave”_`,Fs={id:"navigation",name:"Navigation Agent",description:gr,createGraph:fr,workspace:ze},Me=g.Root({messages:g({reducer
|
|
43
|
+
_Example: “Zoom to 1600 Pennsylvania Ave”_`,Fs={id:"navigation",name:"Navigation Agent",description:gr,createGraph:fr,workspace:ze},Me=g.Root({messages:g({reducer:$,default:()=>[]}),outputMessage:g({reducer:(e="",r)=>{let t=typeof r=="string"?r.trim():"";if(!t)return e;let a=e.trim();if(!a)return t;if(a===t)return e;let o=a.split(`
|
|
44
44
|
|
|
45
45
|
`);return o[o.length-1]?.trim()===t?e:`${e}
|
|
46
46
|
|
|
47
|
-
${t}`},default:()=>""}),vectorSearchLayerIds:g(),vectorSearchFieldResults:g(),layerFieldInfo:g(),queryResponse:g()}),yr=async(e,r)=>(await m({text:"Exiting Data Exploration agent"},r),e),B=async(e,r)=>{let t=e.tool_calls??[];if(t.length===0){await m({text:`LLM did not request any tool calls: ${String(e?.content)}`},r);return}await Promise.all(t.map(async a=>await m({text:`LLM requested tool call with arguments: ${JSON.stringify(a.args,null,2)}`},r))),console.log("LLM response:",JSON.stringify(e.tool_calls,null,2))},de=async(e,r,t)=>{let a=e.map?.allLayers.find(i=>i.id===r),o=a.createQuery();o.where=t??"1=1";try{let{extent:i,count:s}=await a.queryExtent(o);return!i||s===0?{success:!1,error:`No features found for where clause: ${t}`}:(await e.goTo(i),{success:!0})}catch(i){return{success:!1,error:i instanceof Error?i.message:String(i)}}},pr=async(e,r,t)=>{let a=t.map?.allLayers.find(s=>s.id===e);if(!a)return`Could not find layer with ID: ${e}`;a.definitionExpression=r,a.visible=!0;let o=await de(t,e,r),i=a.title??a.layerId;return o.success?`Applied definition expression to layer "${a.title??e}": ${r}`:`Applied filter to "${i}" but no features matched. ${o.error}`},wr=["mapView"];function k(e){let r=e?.configurable?.context;if(!r||typeof r!="object")throw new Error("DataExplorationAgent context missing");let t=wr.filter(a=>!(a in r));if(t.length)throw new Error(`DataExplorationAgent context missing: ${t.join(", ")}`);return r}var br=async({layerId:e,definitionExpression:r},t)=>{let{mapView:a}=k(t);return await pr(e,r,a)},Sr=n.object({layerId:n.string().describe("The layerId of the layer on which to set a definitionExpression."),definitionExpression:n.string().describe("The SQL-92 where clause used to set a definition expression on the layer.")}),vr=p(br,{name:"setDefinitionExpression",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.",schema:Sr});function te(e){return"point"in e&&e.point!==void 0}function re(e){return"layerId"in e&&e.layerId!==void 0}var Q=async(e,r)=>{if(te(e)){let{point:t}=e;return{geometry:new oe({x:t.x,y:t.y,spatialReference:t.spatialReference?{wkid:t.spatialReference.wkid}:r.spatialReference})}}if(re(e)){let t=r.map?.allLayers.find(a=>a.id===e.layerId);if(!t)return{error:`Could not find geometry layer with ID: ${e.layerId}`};try{let a=await t.queryFeatures({where:e.where,returnGeometry:!0,outSpatialReference:r.spatialReference});if(!a.features.length)return{error:`No features found in geometry layer with the specified where clause: ${e.where}`};let o;if(a.features.length===1){let i=a.features[0].geometry;if(!i)return{error:"The geometry of the first feature is undefined or null."};o=i}else{let i=a.features.map(l=>l.geometry),s=U.executeMany(i);if(!s)return{error:"Failed to create a combined geometry."};o=s}return o.spatialReference||(o.spatialReference=r.spatialReference),{geometry:o}}catch(a){return{error:`Failed to query geometry: ${String(a)}`}}}return{error:"Invalid geometry configuration provided"}},Tr=async(e,r,t,a,o)=>{let i=r.map?.allLayers.find(c=>c.id===e.layerId);if(!i)return`Could not find target layer with ID: ${e.layerId}`;let s;if(o){let c=await Q(o,r);if("error"in c)return c.error;s=c.geometry}i.featureEffect=null,i.featureEffect=new Re({filter:new V({where:e.where,geometry:s,spatialRelationship:"intersects",distance:o?.distance,units:o?.units}),includedEffect:t,excludedEffect:a}),i.visible=!0;let l=await de(r,o?o.layerId:e.layerId,o?o.where:e.where),d=i.title??e.layerId;return l.success?`Applied feature effects to target layer "${i.title??e.layerId}"${o?` using geometry from layer "${o.layerId}"`:""}.`:`Applied filter to "${d}" but no features matched. ${l.error}`},xr=["feet","kilometers","meters","miles","nautical-miles","us-nautical-miles"],z=n.enum(xr),Er=async({targetLayer:e,geometryLayer:r,includedEffect:t="drop-shadow(2px, 2px, 2px, gray)",excludedEffect:a="grayscale(100%) opacity(60%) blur(2px)"},o)=>{let{mapView:i}=k(o);return await Tr(e,i,t,a,r)},Lr=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer on which to set a feature effect."),where:n.string().describe("The SQL-92 where clause representing the features to emphasize.")}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to filter the input geometry."),units:z.describe("The units used to filter by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries."),includedEffect:n.string().optional().default("drop-shadow(2px, 2px, 2px, gray)").describe("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."),excludedEffect:n.string().optional().default("grayscale(100%) opacity(60%) blur(2px)").describe("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.")}),Ir=p(Er,{name:"setFeatureEffect",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.",schema:Lr}),$r=async(e,r,t)=>{let a=r.map?.allLayers.find(d=>d.id===e.layerId);if(!a)return`Could not find target layer with ID: ${e.layerId}`;let o;if(t){let d=await Q(t,r);if("error"in d)return d.error;o=d.geometry}let i=await r.whenLayerView(a);i.filter=null,i.filter=new V({where:e.where,geometry:o,spatialRelationship:"intersects",distance:t?.distance,units:t?.units}),a.visible=!0;let s=await de(r,t?t.layerId:e.layerId,t?t.where:e.where),l=a.title??e.layerId;return s.success?`Applied feature filter to layer "${a.title??e.layerId}"${t?` using geometry from layer "${t.layerId}"`:""}.`:`Applied filter to "${l}" but no features matched. ${s.error}`},Fr=async({targetLayer:e,geometryLayer:r},t)=>{let{mapView:a}=k(t);return await $r(e,a,r)},_r=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer on which to set a filter."),where:n.string().describe("The SQL-92 where clause representing the features to display.")}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to filter the input geometry."),units:z.describe("The units used to filter by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries.")}),Nr=p(Fr,{name:"setFeatureFilter",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.",schema:_r}),ae=(e,r,t)=>{if(e&&typeof e!="function"){let a="getField"in t&&t.getField?.(e),o=a&&"getFieldDomain"in t&&t.getFieldDomain?t.getFieldDomain(a.name):null;if(o?.type==="coded-value"){let i=o.codedValues.find(s=>s.code===r);return i?i.name:null}}return null},Rr=(e,r,t)=>{let a=e.createQuery();return a.outFields=[r],a.where=t||"1=1",a.num=1,a},Ar=async(e,r,t,a)=>{let o=a.map?.allLayers.find(c=>c.id===e),i=Rr(o,r,t.where),s=(await o.queryFeatures(i)).features[0],l=s?s.attributes[r]:null,d=ae(r,l,o)||l;return{tool:"getAttribute",layerName:o.title??e,summary:`${r} = ${d}`,details:{fieldName:r,value:d,where:t.where}}};async function qr({layerId:e,fieldName:r,query:t},a){let{mapView:o}=k(a),i=await Ar(e,r,t,o);return JSON.stringify(i,null,2)}var kr=n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),fieldName:n.string().describe("The name of the field/attribute from which to get a field value."),query:n.object({where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")})}),zr=p(qr,{name:"getAttribute",description:"Returns an attribute value for a given feature.",schema:kr}),ue=(e,r)=>r?e.hasAllFeaturesInView:e.hasAllFeatures,Mr=async e=>{let{targetLayer:r,fieldName:t,statisticType:a,mapView:o,layersAndFieldsRegistry:i,geometryLayer:s}=e,l=o.map?.allLayers.find(T=>T.id===r.layerId);if(!l)throw new Error(`Layer '${r.layerId}' not found.`);let d=await o.whenLayerView(l),c=i.get(r.layerId)?.fieldRegistry.get(t);if(!c)throw new Error(`Field '${t}' not found.`);let u,h;if(s){let T=await Q(s,o);if("error"in T)throw new Error(T.error);if(!T.geometry)throw new Error(`No features found matching: ${s.where}`);u={geometryLayerId:s.layerId,geometryWhere:s.where,distance:s.distance,units:s.units,applied:!0},h=new V({geometry:T.geometry,distance:s.distance,units:s.units,spatialRelationship:"intersects"})}let y=ue(d,!1),f=null,w=null,v=10;if(c.type!=="geometry"&&c.type!=="oid"&&c.type!=="global-id")try{f=await ie({layer:l,useFeaturesInView:y,view:y?o:void 0,field:t,sqlWhere:r.where,...h&&{filter:h},outStatisticTypes:{include:[a]}}),["string","small-integer","integer"].includes(c.type)&&(w=(await ne({layer:l,useFeaturesInView:y,view:y?o:void 0,field:t,sqlWhere:r.where,...h&&{filter:h}})).uniqueValueInfos.sort((T,M)=>M.count-T.count).slice(0,v))}catch(T){console.error("Statistics error:",T)}return{tool:"getStatistics",layerName:l.title??r.layerId,summary:`${a} = ${typeof f?.[a]=="number"?f[a]:"N/A"}`,details:{fieldName:t,statisticType:a,statistic:f?.[a]??null,summaryStatistics:f,uniqueValues:w,where:r.where,spatialFilterInfo:u}}};async function Cr({targetLayer:e,fieldName:r,statisticType:t,geometryLayer:a},o){let i=b(o,"layersAndFieldsRegistry"),{mapView:s}=k(o),l=await Mr({targetLayer:e,fieldName:r,statisticType:t,mapView:s,layersAndFieldsRegistry:i,geometryLayer:a});return JSON.stringify(l,null,2)}var jr=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")}),geometryLayer:n.union([n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().optional().describe("The distance by which to query from the input geometry."),units:z.optional().describe("The units used to query by geometry and distance.")}),n.object({}).strict()]).optional().describe("Optional geometry-based filtering parameters for spatial queries."),fieldName:n.string().describe("The name of the field for which to get statistics. STRICTLY DO NOT use OBJECTID. Use any other field"),statisticType:n.enum(["avg","max","median","min","stddev","sum","variance","nullcount","count"]).describe("The statistic type to calculate.")}),Vr=p(Cr,{name:"getStatistics",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.',schema:jr}),Or=async(e,r,t,a)=>{let o=t.map?.allLayers.find(u=>u.id===e.layerId),i=await t.whenLayerView(o),s=o.title??e.layerId,l;if(a){let u=await Q(a,t);if("error"in u)return{tool:"getTopFeatures",layerName:s,summary:"Geometry lookup failed",details:{error:u.error}};if(!u.geometry)return{tool:"getTopFeatures",layerName:s,summary:"No features found for geometry filter",details:{error:`No features found matching: ${a.where}`}};l=u.geometry}let d=e.outFields.length>2?e.outFields:["*"],c=r.groupByFields&&r.groupByFields.length>0;try{let u;if(c){let y=new Ae({where:e.where||"1=1",outFields:d,orderByFields:e.orderByFields,geometry:l,spatialRelationship:l?"intersects":void 0,distance:a?.distance,units:a?.units,topFilter:new qe({topCount:r.topCount,groupByFields:r.groupByFields,orderByFields:r.orderByFields})});u=await o.queryTopFeatures(y)}else{let y=new se({where:e.where||"1=1",outFields:d,orderByFields:r.orderByFields,num:r.topCount,geometry:l,spatialRelationship:l?"intersects":void 0,distance:a?.distance,units:a?.units,outSpatialReference:t.spatialReference}),f=ue(i,!1);try{u=f?await i.queryFeatures(y):await o.queryFeatures(y)}catch(w){console.warn("Client-side query failed, falling back to server:",w),u=await o.queryFeatures(y)}}let h=u.features.map(y=>y.attributes);return{tool:"getTopFeatures",layerName:s,summary:`Top ${r.topCount} features extracted`,details:{topCount:r.topCount,attributes:h,where:e.where,orderByFields:r.orderByFields,...c&&{groupByFields:r.groupByFields}}}}catch(u){return{tool:"getTopFeatures",layerName:s,summary:"Query failed",details:{error:u instanceof Error?u.message:String(u)}}}},Dr=async({targetLayer:e,topFilter:r,geometryLayer:t},a)=>{let{mapView:o}=k(a),i=await Or(e,r,o,t);return JSON.stringify(i,null,2)},Br=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),outFields:n.array(n.string().describe('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 ("*").').default("*"))}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().optional().describe("The distance by which to query from the input geometry."),units:z.describe("The units used to query by geometry and distance.").optional()}).optional().describe("Optional geometry-based filtering parameters for spatial queries."),topFilter:n.object({topCount:n.number().describe("Number of top features to return per group."),orderByFields:n.array(n.string().describe("Field(s) to rank by with ASC/DESC. Must be existing field names, not aggregate functions.")),groupByFields:n.array(n.string().describe("Field(s) to group results by. Returns top N per group."))})}),Qr=p(Dr,{name:"getTopFeatures",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.',schema:Br}),ee=25,Pr=async(e,r,t,a)=>{let o=r.map?.allLayers.find(f=>f.id===e.layerId),i=await r.whenLayerView(o),s=o.title??e.layerId,l;if(t){let f=await Q(t,r);if("error"in f){let w={error:f.error};return re(t)?(w.geometryLayerId=t.layerId,w.geometryWhere=t.where):te(t)&&(w.point=t.point),{tool:"queryFeatures",layerName:s,summary:"Geometry lookup failed",details:w}}if(!f.geometry){let w={};return re(t)?(w.error=`No features found matching: ${t.where}`,w.geometryLayerId=t.layerId,w.geometryWhere=t.where):te(t)&&(w.error="Failed to create point geometry",w.point=t.point),{tool:"queryFeatures",layerName:s,summary:"No features found for geometry filter",details:w}}l=f.geometry}else a&&(l=r.extent.clone());let d=ue(i,a??!1),c=new se({where:e.where||"1=1",outFields:e.outFields.length?e.outFields:["*"],orderByFields:e.orderByFields,...l&&{geometry:l,spatialRelationship:"intersects"},...t?.distance&&{distance:t.distance},...t?.units&&{units:t.units},outSpatialReference:r.spatialReference}),u,h;try{u=d?await i.queryFeatureCount(c):await o.queryFeatureCount(c),u>0&&u<=ee&&(h=d?await i.queryFeatures(c):await o.queryFeatures(c),h&&h.features.forEach(f=>{let w=f.attributes;o.fields.forEach(v=>{let T=w[v.name],M=ae(v.name,T,o);M&&(w[v.name]=M)})}))}catch(f){console.warn("Client-side query failed, falling back to server:",f),u=await o.queryFeatureCount(c),u>0&&u<=ee&&(h=await o.queryFeatures(c),h&&h.features.forEach(w=>{o.fields.forEach(v=>{let T=w.attributes[v.name],M=ae(v.name,T,o);M&&(w.attributes[v.name]=M)})}))}let y=h?.features.map(f=>f.attributes);return{tool:"queryFeatures",layerName:s,summary:`${u} features found`,details:{totalCount:u,where:e.where,...y&&{attributes:y},...u>ee&&{note:`${u} features found. Too many to list. Use filters to narrow results.`}}}};async function Gr({targetLayer:e,geometryFilter:r,useCurrentExtent:t},a){let{mapView:o}=k(a),i=await Pr(e,o,r,t);return JSON.stringify(i,null,2)}var Wr=n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter."),distance:n.number().optional().describe("The buffer distance around the geometry."),units:z.optional().describe("The units for the distance buffer.")}),Ur=n.object({point:n.object({x:n.number().describe("X coordinate (longitude) from navigation result"),y:n.number().describe("Y coordinate (latitude) from navigation result"),spatialReference:n.object({wkid:n.number().describe("Spatial reference WKID (e.g., 4326 for WGS84)")}).optional().describe("Spatial reference. Defaults to map's spatial reference if not provided.")}).describe("Point coordinates from a previous navigation/geocoding result"),distance:n.number().optional().describe("Optional buffer distance around the point."),units:z.optional().describe("The units for the distance buffer.")}),Jr=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("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."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),outFields:n.array(n.string().describe('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 ("*").').default("*"))}),geometryFilter:n.union([Wr,Ur]).optional().describe("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."),useCurrentExtent:n.boolean().optional().describe("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).")}),Zr=p(Gr,{name:"queryFeatures",description:"Queries features from a layer. Returns count and attributes (if \u226425 features). Use for listing features, finding features matching conditions, or spatial queries.",schema:Jr}),Ce=[zr,Vr,Qr,Zr],je=[vr,Ir,Nr],J=()=>{let e=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}`;return{userTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone,userTimezoneOffset:o}},Hr=async(e,r)=>{await m({text:"Requesting LLM for layer filter results"},r);let t=await q("data_explore_filter_prompt");if(!r?.configurable)throw new Error("config.configurable is required for layer filter tools");let{userTimezone:a,userTimezoneOffset:o}=J(),i={layerFieldInfo:e.layerFieldInfo,userTimezone:a,userTimezoneOffset:o},s=await C({promptText:t,messages:S(e.messages),inputVariables:i,tools:je}),l=[...e.messages,s],d=(s.tool_calls?.length??0)>0?l:[...l,s],c=s.content.toString();return await B(s,r),{...e,messages:d,outputMessage:c}},Kr=async(e,r)=>{await m({text:"Requesting LLM for layer query results"},r);let t=await q("data_explore_query_prompt");if(!r?.configurable)throw new Error("config.configurable is required for layer query tools");let{userTimezone:a,userTimezoneOffset:o}=J(),i={layerFieldInfo:e.layerFieldInfo,userTimezone:a,userTimezoneOffset:o},s=await C({promptText:t,messages:S(e.messages),inputVariables:i,tools:Ce}),l=[...e.messages,s],d=s.content.toString();return await B(s,r),{...e,messages:l,outputMessage:d}},Yr=async(e,r)=>{try{await m({text:"Requesting LLM for summary on query results"},r);let t=await q("summarize_query_response_prompt"),a={queryResponse:e.queryResponse},o=await Y({promptText:t,messages:S(e.messages),inputVariables:a}),i=typeof o=="string"?o:o.content,s=new j(i);return await m({text:`Received response from LLM: ${i}`},r),{...e,outputMessage:i,messages:[...e.messages,s]}}catch(t){throw await m({text:"Error during filter LLM request"},r),new Error(`Error during filter LLM request: ${t instanceof Error?t.message:String(t)}`)}};async function Xr(e,r){let t=await new L(je).invoke({messages:S(e.messages)},r),a=[...e.messages,...t.messages],o=t.messages.map(l=>new j({content:l.content,additional_kwargs:l.additional_kwargs}));await m({text:`Finished executing layer filter tool: ${t.messages.map(l=>l.content).join(", ")}`},r);let i=[...a,...o],s=o.map(l=>l.content).join(`
|
|
47
|
+
${t}`},default:()=>""}),vectorSearchLayerIds:g(),vectorSearchFieldResults:g(),layerFieldInfo:g(),queryResponse:g()}),yr=async(e,r)=>(await m({text:"Exiting Data Exploration agent"},r),e),B=async(e,r)=>{let t=e.tool_calls??[];if(t.length===0){await m({text:`LLM did not request any tool calls: ${String(e?.content)}`},r);return}await Promise.all(t.map(async a=>await m({text:`LLM requested tool call with arguments: ${JSON.stringify(a.args,null,2)}`},r))),console.log("LLM response:",JSON.stringify(e.tool_calls,null,2))},de=async(e,r,t)=>{let a=e.map?.allLayers.find(i=>i.id===r),o=a.createQuery();o.where=t??"1=1";try{let{extent:i,count:s}=await a.queryExtent(o);return!i||s===0?{success:!1,error:`No features found for where clause: ${t}`}:(await e.goTo(i),{success:!0})}catch(i){return{success:!1,error:i instanceof Error?i.message:String(i)}}},pr=async(e,r,t)=>{let a=t.map?.allLayers.find(s=>s.id===e);if(!a)return`Could not find layer with ID: ${e}`;a.definitionExpression=r,a.visible=!0;let o=await de(t,e,r),i=a.title??a.layerId;return o.success?`Applied definition expression to layer "${a.title??e}": ${r}`:`Applied filter to "${i}" but no features matched. ${o.error}`},wr=["mapView"];function k(e){let r=e?.configurable?.context;if(!r||typeof r!="object")throw new Error("DataExplorationAgent context missing");let t=wr.filter(a=>!(a in r));if(t.length)throw new Error(`DataExplorationAgent context missing: ${t.join(", ")}`);return r}var br=async({layerId:e,definitionExpression:r},t)=>{let{mapView:a}=k(t);return await pr(e,r,a)},Sr=n.object({layerId:n.string().describe("The layerId of the layer on which to set a definitionExpression."),definitionExpression:n.string().describe("The SQL-92 where clause used to set a definition expression on the layer.")}),vr=p(br,{name:"setDefinitionExpression",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.",schema:Sr});function te(e){return"point"in e&&e.point!==void 0}function re(e){return"layerId"in e&&e.layerId!==void 0}var Q=async(e,r)=>{if(te(e)){let{point:t}=e;return{geometry:new oe({x:t.x,y:t.y,spatialReference:t.spatialReference?{wkid:t.spatialReference.wkid}:r.spatialReference})}}if(re(e)){let t=r.map?.allLayers.find(a=>a.id===e.layerId);if(!t)return{error:`Could not find geometry layer with ID: ${e.layerId}`};try{let a=await t.queryFeatures({where:e.where,returnGeometry:!0,outSpatialReference:r.spatialReference});if(!a.features.length)return{error:`No features found in geometry layer with the specified where clause: ${e.where}`};let o;if(a.features.length===1){let i=a.features[0].geometry;if(!i)return{error:"The geometry of the first feature is undefined or null."};o=i}else{let i=a.features.map(l=>l.geometry),s=U.executeMany(i);if(!s)return{error:"Failed to create a combined geometry."};o=s}return o.spatialReference||(o.spatialReference=r.spatialReference),{geometry:o}}catch(a){return{error:`Failed to query geometry: ${String(a)}`}}}return{error:"Invalid geometry configuration provided"}},Tr=async(e,r,t,a,o)=>{let i=r.map?.allLayers.find(c=>c.id===e.layerId);if(!i)return`Could not find target layer with ID: ${e.layerId}`;let s;if(o){let c=await Q(o,r);if("error"in c)return c.error;s=c.geometry}i.featureEffect=null,i.featureEffect=new Re({filter:new V({where:e.where,geometry:s,spatialRelationship:"intersects",distance:o?.distance,units:o?.units}),includedEffect:t,excludedEffect:a}),i.visible=!0;let l=await de(r,o?o.layerId:e.layerId,o?o.where:e.where),d=i.title??e.layerId;return l.success?`Applied feature effects to target layer "${i.title??e.layerId}"${o?` using geometry from layer "${o.layerId}"`:""}.`:`Applied filter to "${d}" but no features matched. ${l.error}`},xr=["feet","kilometers","meters","miles","nautical-miles","us-nautical-miles"],z=n.enum(xr),Er=async({targetLayer:e,geometryLayer:r,includedEffect:t="drop-shadow(2px, 2px, 2px, gray)",excludedEffect:a="grayscale(100%) opacity(60%) blur(2px)"},o)=>{let{mapView:i}=k(o);return await Tr(e,i,t,a,r)},Lr=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer on which to set a feature effect."),where:n.string().describe("The SQL-92 where clause representing the features to emphasize.")}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to filter the input geometry."),units:z.describe("The units used to filter by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries."),includedEffect:n.string().optional().default("drop-shadow(2px, 2px, 2px, gray)").describe("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."),excludedEffect:n.string().optional().default("grayscale(100%) opacity(60%) blur(2px)").describe("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.")}),Ir=p(Er,{name:"setFeatureEffect",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.",schema:Lr}),$r=async(e,r,t)=>{let a=r.map?.allLayers.find(d=>d.id===e.layerId);if(!a)return`Could not find target layer with ID: ${e.layerId}`;let o;if(t){let d=await Q(t,r);if("error"in d)return d.error;o=d.geometry}let i=await r.whenLayerView(a);i.filter=null,i.filter=new V({where:e.where,geometry:o,spatialRelationship:"intersects",distance:t?.distance,units:t?.units}),a.visible=!0;let s=await de(r,t?t.layerId:e.layerId,t?t.where:e.where),l=a.title??e.layerId;return s.success?`Applied feature filter to layer "${a.title??e.layerId}"${t?` using geometry from layer "${t.layerId}"`:""}.`:`Applied filter to "${l}" but no features matched. ${s.error}`},Fr=async({targetLayer:e,geometryLayer:r},t)=>{let{mapView:a}=k(t);return await $r(e,a,r)},_r=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer on which to set a filter."),where:n.string().describe("The SQL-92 where clause representing the features to display.")}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to filter the input geometry."),units:z.describe("The units used to filter by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries.")}),Nr=p(Fr,{name:"setFeatureFilter",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.",schema:_r}),ae=(e,r,t)=>{if(e&&typeof e!="function"){let a="getField"in t&&t.getField?.(e),o=a&&"getFieldDomain"in t&&t.getFieldDomain?t.getFieldDomain(a.name):null;if(o?.type==="coded-value"){let i=o.codedValues.find(s=>s.code===r);return i?i.name:null}}return null},Rr=(e,r,t)=>{let a=e.createQuery();return a.outFields=[r],a.where=t||"1=1",a.num=1,a},Ar=async(e,r,t,a)=>{let o=a.map?.allLayers.find(c=>c.id===e),i=Rr(o,r,t.where),s=(await o.queryFeatures(i)).features[0],l=s?s.attributes[r]:null,d=ae(r,l,o)||l;return{tool:"getAttribute",layerName:o.title??e,summary:`${r} = ${d}`,details:{fieldName:r,value:d,where:t.where}}};async function qr({layerId:e,fieldName:r,query:t},a){let{mapView:o}=k(a),i=await Ar(e,r,t,o);return JSON.stringify(i,null,2)}var kr=n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),fieldName:n.string().describe("The name of the field/attribute from which to get a field value."),query:n.object({where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")})}),zr=p(qr,{name:"getAttribute",description:"Returns an attribute value for a given feature.",schema:kr}),ue=(e,r)=>r?e.hasAllFeaturesInView:e.hasAllFeatures,Mr=async e=>{let{targetLayer:r,fieldName:t,statisticType:a,mapView:o,layersAndFieldsRegistry:i,geometryLayer:s}=e,l=o.map?.allLayers.find(T=>T.id===r.layerId);if(!l)throw new Error(`Layer '${r.layerId}' not found.`);let d=await o.whenLayerView(l),c=i.get(r.layerId)?.fieldRegistry.get(t);if(!c)throw new Error(`Field '${t}' not found.`);let u,h;if(s){let T=await Q(s,o);if("error"in T)throw new Error(T.error);if(!T.geometry)throw new Error(`No features found matching: ${s.where}`);u={geometryLayerId:s.layerId,geometryWhere:s.where,distance:s.distance,units:s.units,applied:!0},h=new V({geometry:T.geometry,distance:s.distance,units:s.units,spatialRelationship:"intersects"})}let y=ue(d,!1),f=null,w=null,v=10;if(c.type!=="geometry"&&c.type!=="oid"&&c.type!=="global-id")try{f=await ie({layer:l,useFeaturesInView:y,view:y?o:void 0,field:t,sqlWhere:r.where,...h&&{filter:h},outStatisticTypes:{include:[a]}}),["string","small-integer","integer"].includes(c.type)&&(w=(await ne({layer:l,useFeaturesInView:y,view:y?o:void 0,field:t,sqlWhere:r.where,...h&&{filter:h}})).uniqueValueInfos.sort((T,M)=>M.count-T.count).slice(0,v))}catch(T){console.error("Statistics error:",T)}return{tool:"getStatistics",layerName:l.title??r.layerId,summary:`${a} = ${typeof f?.[a]=="number"?f[a]:"N/A"}`,details:{fieldName:t,statisticType:a,statistic:f?.[a]??null,summaryStatistics:f,uniqueValues:w,where:r.where,spatialFilterInfo:u}}};async function Cr({targetLayer:e,fieldName:r,statisticType:t,geometryLayer:a},o){let i=b(o,"layersAndFieldsRegistry"),{mapView:s}=k(o),l=await Mr({targetLayer:e,fieldName:r,statisticType:t,mapView:s,layersAndFieldsRegistry:i,geometryLayer:a});return JSON.stringify(l,null,2)}var jr=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")}),geometryLayer:n.union([n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().optional().describe("The distance by which to query from the input geometry."),units:z.optional().describe("The units used to query by geometry and distance.")}),n.object({}).strict()]).optional().describe("Optional geometry-based filtering parameters for spatial queries."),fieldName:n.string().describe("The name of the field for which to get statistics. STRICTLY DO NOT use OBJECTID. Use any other field"),statisticType:n.enum(["avg","max","median","min","stddev","sum","variance","nullcount","count"]).describe("The statistic type to calculate.")}),Vr=p(Cr,{name:"getStatistics",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.',schema:jr}),Or=async(e,r,t,a)=>{let o=t.map?.allLayers.find(u=>u.id===e.layerId),i=await t.whenLayerView(o),s=o.title??e.layerId,l;if(a){let u=await Q(a,t);if("error"in u)return{tool:"getTopFeatures",layerName:s,summary:"Geometry lookup failed",details:{error:u.error}};if(!u.geometry)return{tool:"getTopFeatures",layerName:s,summary:"No features found for geometry filter",details:{error:`No features found matching: ${a.where}`}};l=u.geometry}let d=e.outFields.length>2?e.outFields:["*"],c=r.groupByFields&&r.groupByFields.length>0;try{let u;if(c){let y=new Ae({where:e.where||"1=1",outFields:d,orderByFields:e.orderByFields,geometry:l,spatialRelationship:l?"intersects":void 0,distance:a?.distance,units:a?.units,topFilter:new qe({topCount:r.topCount,groupByFields:r.groupByFields,orderByFields:r.orderByFields})});u=await o.queryTopFeatures(y)}else{let y=new se({where:e.where||"1=1",outFields:d,orderByFields:r.orderByFields,num:r.topCount,geometry:l,spatialRelationship:l?"intersects":void 0,distance:a?.distance,units:a?.units,outSpatialReference:t.spatialReference}),f=ue(i,!1);try{u=f?await i.queryFeatures(y):await o.queryFeatures(y)}catch(w){console.warn("Client-side query failed, falling back to server:",w),u=await o.queryFeatures(y)}}let h=u.features.map(y=>y.attributes);return{tool:"getTopFeatures",layerName:s,summary:`Top ${r.topCount} features extracted`,details:{topCount:r.topCount,attributes:h,where:e.where,orderByFields:r.orderByFields,...c&&{groupByFields:r.groupByFields}}}}catch(u){return{tool:"getTopFeatures",layerName:s,summary:"Query failed",details:{error:u instanceof Error?u.message:String(u)}}}},Dr=async({targetLayer:e,topFilter:r,geometryLayer:t},a)=>{let{mapView:o}=k(a),i=await Or(e,r,o,t);return JSON.stringify(i,null,2)},Br=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),outFields:n.array(n.string().describe('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 ("*").').default("*"))}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().optional().describe("The distance by which to query from the input geometry."),units:z.describe("The units used to query by geometry and distance.").optional()}).optional().describe("Optional geometry-based filtering parameters for spatial queries."),topFilter:n.object({topCount:n.number().describe("Number of top features to return per group."),orderByFields:n.array(n.string().describe("Field(s) to rank by with ASC/DESC. Must be existing field names, not aggregate functions.")),groupByFields:n.array(n.string().describe("Field(s) to group results by. Returns top N per group."))})}),Qr=p(Dr,{name:"getTopFeatures",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.',schema:Br}),ee=25,Pr=async(e,r,t,a)=>{let o=r.map?.allLayers.find(f=>f.id===e.layerId),i=await r.whenLayerView(o),s=o.title??e.layerId,l;if(t){let f=await Q(t,r);if("error"in f){let w={error:f.error};return re(t)?(w.geometryLayerId=t.layerId,w.geometryWhere=t.where):te(t)&&(w.point=t.point),{tool:"queryFeatures",layerName:s,summary:"Geometry lookup failed",details:w}}if(!f.geometry){let w={};return re(t)?(w.error=`No features found matching: ${t.where}`,w.geometryLayerId=t.layerId,w.geometryWhere=t.where):te(t)&&(w.error="Failed to create point geometry",w.point=t.point),{tool:"queryFeatures",layerName:s,summary:"No features found for geometry filter",details:w}}l=f.geometry}else a&&(l=r.extent.clone());let d=ue(i,a??!1),c=new se({where:e.where||"1=1",outFields:e.outFields.length?e.outFields:["*"],orderByFields:e.orderByFields,...l&&{geometry:l,spatialRelationship:"intersects"},...t?.distance&&{distance:t.distance},...t?.units&&{units:t.units},outSpatialReference:r.spatialReference}),u,h;try{u=d?await i.queryFeatureCount(c):await o.queryFeatureCount(c),u>0&&u<=ee&&(h=d?await i.queryFeatures(c):await o.queryFeatures(c),h&&h.features.forEach(f=>{let w=f.attributes;o.fields.forEach(v=>{let T=w[v.name],M=ae(v.name,T,o);M&&(w[v.name]=M)})}))}catch(f){console.warn("Client-side query failed, falling back to server:",f),u=await o.queryFeatureCount(c),u>0&&u<=ee&&(h=await o.queryFeatures(c),h&&h.features.forEach(w=>{o.fields.forEach(v=>{let T=w.attributes[v.name],M=ae(v.name,T,o);M&&(w.attributes[v.name]=M)})}))}let y=h?.features.map(f=>f.attributes);return{tool:"queryFeatures",layerName:s,summary:`${u} features found`,details:{totalCount:u,where:e.where,...y&&{attributes:y},...u>ee&&{note:`${u} features found. Too many to list. Use filters to narrow results.`}}}};async function Gr({targetLayer:e,geometryFilter:r,useCurrentExtent:t},a){let{mapView:o}=k(a),i=await Pr(e,o,r,t);return JSON.stringify(i,null,2)}var Wr=n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter."),distance:n.number().optional().describe("The buffer distance around the geometry."),units:z.optional().describe("The units for the distance buffer.")}),Ur=n.object({point:n.object({x:n.number().describe("X coordinate (longitude) from navigation result"),y:n.number().describe("Y coordinate (latitude) from navigation result"),spatialReference:n.object({wkid:n.number().describe("Spatial reference WKID (e.g., 4326 for WGS84)")}).optional().describe("Spatial reference. Defaults to map's spatial reference if not provided.")}).describe("Point coordinates from a previous navigation/geocoding result"),distance:n.number().optional().describe("Optional buffer distance around the point."),units:z.optional().describe("The units for the distance buffer.")}),Hr=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("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."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),outFields:n.array(n.string().describe('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 ("*").').default("*"))}),geometryFilter:n.union([Wr,Ur]).optional().describe("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."),useCurrentExtent:n.boolean().optional().describe("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).")}),Jr=p(Gr,{name:"queryFeatures",description:"Queries features from a layer. Returns count and attributes (if \u226425 features). Use for listing features, finding features matching conditions, or spatial queries.",schema:Hr}),Ce=[zr,Vr,Qr,Jr],je=[vr,Ir,Nr],H=()=>{let e=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}`;return{userTimezone:Intl.DateTimeFormat().resolvedOptions().timeZone,userTimezoneOffset:o}},Zr=async(e,r)=>{await m({text:"Requesting LLM for layer filter results"},r);let t=await q("data_explore_filter_prompt");if(!r?.configurable)throw new Error("config.configurable is required for layer filter tools");let{userTimezone:a,userTimezoneOffset:o}=H(),i={layerFieldInfo:e.layerFieldInfo,userTimezone:a,userTimezoneOffset:o},s=await C({promptText:t,messages:S(e.messages),inputVariables:i,tools:je}),l=[...e.messages,s],d=(s.tool_calls?.length??0)>0?l:[...l,s],c=s.content.toString();return await B(s,r),{...e,messages:d,outputMessage:c}},Kr=async(e,r)=>{await m({text:"Requesting LLM for layer query results"},r);let t=await q("data_explore_query_prompt");if(!r?.configurable)throw new Error("config.configurable is required for layer query tools");let{userTimezone:a,userTimezoneOffset:o}=H(),i={layerFieldInfo:e.layerFieldInfo,userTimezone:a,userTimezoneOffset:o},s=await C({promptText:t,messages:S(e.messages),inputVariables:i,tools:Ce}),l=[...e.messages,s],d=s.content.toString();return await B(s,r),{...e,messages:l,outputMessage:d}},Yr=async(e,r)=>{try{await m({text:"Requesting LLM for summary on query results"},r);let t=await q("summarize_query_response_prompt"),a={queryResponse:e.queryResponse},o=await Y({promptText:t,messages:S(e.messages),inputVariables:a}),i=typeof o=="string"?o:o.content,s=new j(i);return await m({text:`Received response from LLM: ${i}`},r),{...e,outputMessage:i,messages:[...e.messages,s]}}catch(t){throw await m({text:"Error during filter LLM request"},r),new Error(`Error during filter LLM request: ${t instanceof Error?t.message:String(t)}`)}};async function Xr(e,r){let t=await new L(je).invoke({messages:S(e.messages)},r),a=[...e.messages,...t.messages],o=t.messages.map(l=>new j({content:l.content,additional_kwargs:l.additional_kwargs}));await m({text:`Finished executing layer filter tool: ${t.messages.map(l=>l.content).join(", ")}`},r);let i=[...a,...o],s=o.map(l=>l.content).join(`
|
|
48
48
|
|
|
49
|
-
`);return{...e,messages:i,outputMessage:s}}var ea=new L(Ce);async function ta(e,r){let{messages:t}=await ea.invoke({messages:S(e.messages)},r),a=[],o=[];for(let s of t){let l=s.content,d;if(typeof l!="string"){d={tool:s.name??"unknown",layerName:"unknown",summary:"Query failed",details:{error:"Skipping non-string tool output:",raw:l}};continue}try{d=JSON.parse(l)}catch{d={tool:s.name??"unknown",layerName:"unknown",summary:"Query failed",details:{error:l}}}a.push(d),d.details&&typeof d.details=="object"&&"error"in d.details?o.push(`- ${d.tool}: Error - ${String(d.details.error)}`):o.push(`- ${d.layerName}: ${d.summary}`)}let i=[...e.messages,...t];return await m({text:`Finished executing layer query tool: ${o.join(", ")}`},r),{...e,messages:i,queryResponse:a}}var ra=10,aa=async(e,r)=>{let t=null,a=null;try{r.type!=="geometry"&&r.type!=="oid"&&r.type!=="global-id"&&(t=await ie({layer:e,field:r.name}),r.type==="string"&&(a=(await ne({layer:e,field:r.name})).uniqueValueInfos.sort((o,i)=>i.count-o.count).slice(0,ra)))}catch(o){console.error(`Error fetching statistics for field ${r.name}:`,o)}return{summaryStatistics:t,uniqueValues:a}};async function me(e,r,t){let a=[],o=[];for(let i of e){let s=function(y){let f=r.get(y)?.layerItem;return f?[f.name&&`Name: ${f.name}`,f.title&&`Title: ${f.title}`,f.description&&`Description: ${f.description}`].filter(Boolean).join(" | "):y},{layerId:l,results:d}=i,c=t.map?.allLayers.find(y=>y.id===l),u=r.get(l)?.fieldRegistry;if(!u)continue;let h=a.find(y=>y.layerId===l);h||(h={layerId:l,layerSummary:s(l),fieldInfos:[]},a.push(h));for(let y of d){let f=u.get(y.name);if(f){if(!f.statistics){let w=aa(c,f).then(v=>{u.set(f.name,{...f,statistics:v}),f.statistics=v});o.push(w)}h.fieldInfos.push(f)}}}return await Promise.all(o),a}var oa=async(e,r)=>{try{await m({text:"Getting statistics for vector search results"},r);let t=b(r,"layersAndFieldsRegistry"),{mapView:a}=k(r),o=await me(e.vectorSearchFieldResults,t,a);return console.log("Field statistics retrieved:",o),await m({text:"Statistics retrieved"},r),{...e,layerFieldInfo:o}}catch(t){throw await m({text:"Error during fetching statistics"},r),new Error(`Error during fetching statistics: ${t instanceof Error?t.message:String(t)}`)}},Le=.7,ia=10,na=async(e,r)=>{try{let t=
|
|
49
|
+
`);return{...e,messages:i,outputMessage:s}}var ea=new L(Ce);async function ta(e,r){let{messages:t}=await ea.invoke({messages:S(e.messages)},r),a=[],o=[];for(let s of t){let l=s.content,d;if(typeof l!="string"){d={tool:s.name??"unknown",layerName:"unknown",summary:"Query failed",details:{error:"Skipping non-string tool output:",raw:l}};continue}try{d=JSON.parse(l)}catch{d={tool:s.name??"unknown",layerName:"unknown",summary:"Query failed",details:{error:l}}}a.push(d),d.details&&typeof d.details=="object"&&"error"in d.details?o.push(`- ${d.tool}: Error - ${String(d.details.error)}`):o.push(`- ${d.layerName}: ${d.summary}`)}let i=[...e.messages,...t];return await m({text:`Finished executing layer query tool: ${o.join(", ")}`},r),{...e,messages:i,queryResponse:a}}var ra=10,aa=async(e,r)=>{let t=null,a=null;try{r.type!=="geometry"&&r.type!=="oid"&&r.type!=="global-id"&&(t=await ie({layer:e,field:r.name}),r.type==="string"&&(a=(await ne({layer:e,field:r.name})).uniqueValueInfos.sort((o,i)=>i.count-o.count).slice(0,ra)))}catch(o){console.error(`Error fetching statistics for field ${r.name}:`,o)}return{summaryStatistics:t,uniqueValues:a}};async function me(e,r,t){let a=[],o=[];for(let i of e){let s=function(y){let f=r.get(y)?.layerItem;return f?[f.name&&`Name: ${f.name}`,f.title&&`Title: ${f.title}`,f.description&&`Description: ${f.description}`].filter(Boolean).join(" | "):y},{layerId:l,results:d}=i,c=t.map?.allLayers.find(y=>y.id===l),u=r.get(l)?.fieldRegistry;if(!u)continue;let h=a.find(y=>y.layerId===l);h||(h={layerId:l,layerSummary:s(l),fieldInfos:[]},a.push(h));for(let y of d){let f=u.get(y.name);if(f){if(!f.statistics){let w=aa(c,f).then(v=>{u.set(f.name,{...f,statistics:v}),f.statistics=v});o.push(w)}h.fieldInfos.push(f)}}}return await Promise.all(o),a}var oa=async(e,r)=>{try{await m({text:"Getting statistics for vector search results"},r);let t=b(r,"layersAndFieldsRegistry"),{mapView:a}=k(r),o=await me(e.vectorSearchFieldResults,t,a);return console.log("Field statistics retrieved:",o),await m({text:"Statistics retrieved"},r),{...e,layerFieldInfo:o}}catch(t){throw await m({text:"Error during fetching statistics"},r),new Error(`Error during fetching statistics: ${t instanceof Error?t.message:String(t)}`)}},Le=.7,ia=10,na=async(e,r)=>{try{let t=_(e.messages);await m({text:"Similarity search to find fields"},r);let a=b(r,"fieldSearch"),o=b(r,"layersAndFieldsRegistry"),i=await a.searchFields({text:t,layerIds:e.vectorSearchLayerIds,minScore:Le,topResults:ia}),s=i.map(({layerId:d,results:c})=>{let u=c.map(h=>` - ${h.name} (${h.score.toFixed(2)})`).join(`
|
|
50
50
|
`);return`${o.get(d)?.layerItem.name??d}:
|
|
51
51
|
${u}`}).join(`
|
|
52
52
|
`),l;return i.length>0?l=`Vector search completed. Matching layers and fields with scores:
|
|
53
|
-
${s}`:l=`No vector search results found for score over ${Le}.`,await m({text:l},r),{...e,vectorSearchFieldResults:i}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},sa=.7,la=async(e,r)=>{try{let t=
|
|
53
|
+
${s}`:l=`No vector search results found for score over ${Le}.`,await m({text:l},r),{...e,vectorSearchFieldResults:i}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},sa=.7,la=async(e,r)=>{try{let t=_(e.messages);await m({text:`Similarity search to find layers: ${t}`},r);let a=b(r,"layerSearch"),o=b(r,"layersAndFieldsRegistry"),i=await a.searchLayers({text:t,minScore:sa}),s=i.map(c=>c.id),l=i.map(({id:c,score:u})=>`${o.get(c)?.layerItem.name??c} (${u.toFixed(2)})`).join(`
|
|
54
54
|
`),d;return s.length>0?d=`Vector search completed. Matching layers with scores:
|
|
55
|
-
${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r),{...e,vectorSearchLayerIds:s}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},ca=(e,r)=>D(["layerSearch","fieldSearch","layersAndFieldsRegistry"],"Data Exploration Agent")(e,r),da=()=>new
|
|
55
|
+
${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r),{...e,vectorSearchLayerIds:s}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},ca=(e,r)=>D(["layerSearch","fieldSearch","layersAndFieldsRegistry"],"Data Exploration Agent")(e,r),da=()=>new A(Me).addNode("requireDataExplorationServices",ca).addNode("vectorSearchLayers",la).addNode("vectorSearchFields",na).addNode("fieldStatistics",oa).addNode("queryAgent",Kr).addNode("queryTools",ta).addNode("summarizeQueryResponseLLM",Yr).addNode("filterAgent",Zr).addNode("filterTools",Xr).addNode("earlyExit",yr).addEdge(R,"requireDataExplorationServices").addEdge("requireDataExplorationServices","vectorSearchLayers").addConditionalEdges("vectorSearchLayers",e=>e.vectorSearchLayerIds.length?"vectorSearchFields":"earlyExit").addConditionalEdges("vectorSearchFields",e=>e.vectorSearchFieldResults.length?"fieldStatistics":"earlyExit").addEdge("fieldStatistics","queryAgent").addConditionalEdges("queryAgent",e=>(e.messages[e.messages.length-1]?.tool_calls?.length??0)>0?"queryTools":"filterAgent").addConditionalEdges("queryTools",e=>e.queryResponse.length?"summarizeQueryResponseLLM":"filterAgent").addEdge("summarizeQueryResponseLLM","filterAgent").addEdge("filterAgent","filterTools").addEdge("filterTools",x).addEdge("summarizeQueryResponseLLM",x).addEdge("earlyExit",x),ua=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).
|
|
56
56
|
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.
|
|
57
57
|
_Example: “Only show stations where Brand is Shell”_
|
|
58
58
|
_Example: “Make Shell stations stand out on the map”_
|
|
@@ -60,45 +60,45 @@ ${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r)
|
|
|
60
60
|
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?”).
|
|
61
61
|
_Example: “How many features are there?”_
|
|
62
62
|
_Example: “What’s the average population?”_
|
|
63
|
-
_Example: “Which values are in the status field?”_`,_s={id:"dataExploration",name:"Data Exploration Agent",description:ua,createGraph:da,workspace:Me},Ie=.7,ma=10,ha=async(e,r)=>{try{let t=
|
|
63
|
+
_Example: “Which values are in the status field?”_`,_s={id:"dataExploration",name:"Data Exploration Agent",description:ua,createGraph:da,workspace:Me},Ie=.7,ma=10,ha=async(e,r)=>{try{let t=_(e.messages);await m({text:"Similarity search to find fields"},r);let a=b(r,"fieldSearch"),o=b(r,"layersAndFieldsRegistry"),i=await a.searchFields({text:t,layerIds:e.vectorSearchLayerIds,minScore:Ie,topResults:ma}),s=i.map(({layerId:d,results:c})=>{let u=c.map(h=>` - ${h.name} (${h.score.toFixed(2)})`).join(`
|
|
64
64
|
`);return`${o.get(d)?.layerItem.name??d}:
|
|
65
65
|
${u}`}).join(`
|
|
66
66
|
`),l;return i.length>0?l=`Vector search completed. Matching layers and fields with scores:
|
|
67
|
-
${s}`:l=`No vector search results found for score over ${Ie}.`,await m({text:l},r),{...e,vectorSearchFieldResults:i}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},fa=.7,ga=async(e,r)=>{try{let t=
|
|
67
|
+
${s}`:l=`No vector search results found for score over ${Ie}.`,await m({text:l},r),{...e,vectorSearchFieldResults:i}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},fa=.7,ga=async(e,r)=>{try{let t=_(e.messages);await m({text:`Similarity search to find layers: ${t}`},r);let a=b(r,"layerSearch"),o=b(r,"layersAndFieldsRegistry"),i=await a.searchLayers({text:t,minScore:fa}),s=i.map(c=>c.id),l=i.map(({id:c,score:u})=>`${o.get(c)?.layerItem.name??c} (${u.toFixed(2)})`).join(`
|
|
68
68
|
`),d;return s.length>0?d=`Vector search completed. Matching layers with scores:
|
|
69
|
-
${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r),{...e,vectorSearchLayerIds:s}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},Ve=["mapView"];function
|
|
69
|
+
${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r),{...e,vectorSearchLayerIds:s}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},Ve=["mapView"];function J(e){let r=e?.configurable?.context;if(!r||typeof r!="object")throw new Error("LayerFilterAgent context missing");let t=Ve.filter(a=>!(a in r));if(t.length)throw new Error(`LayerFilterAgent context missing: ${t.join(", ")}`);return r}var ya=async(e,r)=>{try{await m({text:"Getting statistics for vector search results"},r);let t=b(r,"layersAndFieldsRegistry"),{mapView:a}=J(r),o=await me(e.vectorSearchFieldResults,t,a);return console.log("Field statistics retrieved:",o),await m({text:"Statistics retrieved"},r),{...e,layerFieldInfo:o}}catch(t){throw await m({text:"Error during fetching statistics"},r),new Error(`Error during fetching statistics: ${t instanceof Error?t.message:String(t)}`)}},he=async(e,r,t)=>{let a=e.map?.allLayers.find(s=>s.id===r),o=a.createQuery();o.where=t??"1=1";let{features:i}=await a.queryFeatures(o);e.goTo(i)},pa=(e,r,t)=>{let a=t.map?.allLayers.find(o=>o.id===e);return a?(a.definitionExpression=r,a.visible=!0,he(t,e,r),`Applied definition expression to layer "${a.title??e}": ${r}`):`Could not find layer with ID: ${e}`},wa=({layerId:e,definitionExpression:r},t)=>{let{mapView:a}=J(t);return pa(e,r,a)},ba=n.object({layerId:n.string().describe("The layerId of the layer on which to set a definitionExpression."),definitionExpression:n.string().describe("The SQL-92 where clause used to set a definition expression on the layer.")}),Sa=p(wa,{name:"setDefinitionExpression",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.",schema:ba}),Oe=async(e,r)=>{let t=r.map?.allLayers.find(i=>i.id===e.layerId);if(!t)return{error:`Could not find geometry layer with ID: ${e.layerId}`};let a=await t.queryFeatures({where:e.where,returnGeometry:!0});if(!a.features.length)return{error:`No features found in geometry layer with the specified where clause: ${e.where}`};let o;if(a.features.length===1){let i=a.features[0].geometry;if(!i)return{error:"The geometry of the first feature is undefined or null."};o=i}else{let i=a.features.map(l=>l.geometry),s=U.executeMany(i);if(!s)return{error:"Failed to create a combined geometry."};o=s}return{geometry:o}},va=async(e,r,t,a,o)=>{let i=r.map?.allLayers.find(l=>l.id===e.layerId);if(!i)return`Could not find target layer with ID: ${e.layerId}`;console.log("Layer type:",i.type),console.log("Layer geometryType:",i.geometryType),console.log("Layer renderer:",i.renderer?.type);let s;if(o){let l=await Oe(o,r);if("error"in l)return l.error;s=l.geometry}return i.featureEffect=new Re({filter:new V({where:e.where,geometry:s,spatialRelationship:"intersects",distance:o?.distance,units:o?.units}),includedEffect:t,excludedEffect:a}),i.visible=!0,he(r,o?o.layerId:e.layerId,o?o.where:e.where),`Applied feature effects to target layer "${i.title??e.layerId}"${o?` using geometry from layer "${o.layerId}"`:""}.`},Ta=["feet","kilometers","meters","miles","nautical-miles","us-nautical-miles"],De=n.enum(Ta),xa=async({targetLayer:e,geometryLayer:r,includedEffect:t="drop-shadow(2px, 2px, 2px, gray)",excludedEffect:a="grayscale(100%) opacity(60%) blur(2px)"},o)=>{let{mapView:i}=J(o);return await va(e,i,t,a,r)},Ea=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer on which to set a feature effect."),where:n.string().describe("The SQL-92 where clause representing the features to emphasize.")}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to filter the input geometry."),units:De.describe("The units used to filter by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries."),includedEffect:n.string().optional().default("drop-shadow(2px, 2px, 2px, gray)").describe("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."),excludedEffect:n.string().optional().default("grayscale(100%) opacity(60%) blur(2px)").describe("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.")}),La=p(xa,{name:"setFeatureEffect",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.",schema:Ea}),Ia=async(e,r,t)=>{let a=r.map?.allLayers.find(s=>s.id===e.layerId);if(!a)return`Could not find target layer with ID: ${e.layerId}`;let o;if(t){let s=await Oe(t,r);if("error"in s)return s.error;o=s.geometry}let i=await r.whenLayerView(a);return i.filter=new V({where:e.where,geometry:o,spatialRelationship:"intersects",distance:t?.distance,units:t?.units}),a.visible=!0,he(r,t?t.layerId:e.layerId,t?t.where:e.where),`Applied feature filter to layer "${a.title??e.layerId}"${t?` using geometry from layer "${t.layerId}"`:""}.`},$a=async({targetLayer:e,geometryLayer:r},t)=>{let{mapView:a}=J(t);return await Ia(e,a,r)},Fa=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer on which to set a filter."),where:n.string().describe("The SQL-92 where clause representing the features to display.")}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to filter the input geometry."),units:De.describe("The units used to filter by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries.")}),_a=p($a,{name:"setFeatureFilter",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.",schema:Fa}),Be=[Sa,La,_a],Na=async(e,r)=>{await m({text:"Requesting LLM for layer filter results"},r);let t=await q("layer_filter_prompt");if(!r?.configurable)throw new Error("config.configurable is required for layer filter tools");let{userTimezone:a,userTimezoneOffset:o}=H(),i={layerFieldInfo:e.layerFieldInfo,userTimezone:a,userTimezoneOffset:o},s=await C({promptText:t,messages:S(e.messages),inputVariables:i,tools:Be}),l=s.content.toString();return await B(s,r),{...e,messages:[...e.messages,s],outputMessage:l}};async function Ra(e,r){let t=await new L(Be).invoke({messages:S(e.messages)},r),a=t.messages.map(s=>s.text).join(`
|
|
70
70
|
`);await m({text:`Finished executing layer filter tool: ${a}`},r);let o=[...e.messages,...t.messages],i=t.messages.map(s=>s.text).join(`
|
|
71
|
-
`);return{...e,outputMessage:i,messages:o}}var Qe=g.Root({messages:g({reducer
|
|
71
|
+
`);return{...e,outputMessage:i,messages:o}}var Qe=g.Root({messages:g({reducer:$,default:()=>[]}),outputMessage:g({reducer:(e="",r)=>{let t=typeof r=="string"?r.trim():"";if(!t)return e;let a=e.trim();if(!a)return t;if(a===t)return e;let o=a.split(`
|
|
72
72
|
|
|
73
73
|
`);return o[o.length-1]?.trim()===t?e:`${e}
|
|
74
74
|
|
|
75
|
-
${t}`},default:()=>""}),vectorSearchLayerIds:g(),vectorSearchFieldResults:g(),layerFieldInfo:g()}),Aa=async(e,r)=>(await m({text:"Exiting Layer Filter agent"},r),e),qa=(e,r)=>D(["layerSearch","fieldSearch","layersAndFieldsRegistry"],"Layer Filter Agent")(e,r),ka=()=>new
|
|
75
|
+
${t}`},default:()=>""}),vectorSearchLayerIds:g(),vectorSearchFieldResults:g(),layerFieldInfo:g()}),Aa=async(e,r)=>(await m({text:"Exiting Layer Filter agent"},r),e),qa=(e,r)=>D(["layerSearch","fieldSearch","layersAndFieldsRegistry"],"Layer Filter Agent")(e,r),ka=()=>new A(Qe).addNode("requireLayerFilterServices",qa).addNode("vectorSearchLayers",ga).addNode("vectorSearchFields",ha).addNode("fieldStatistics",ya).addNode("agent",Na).addNode("tools",Ra).addNode("earlyExit",Aa).addEdge(R,"requireLayerFilterServices").addEdge("requireLayerFilterServices","vectorSearchLayers").addConditionalEdges("vectorSearchLayers",e=>e.vectorSearchLayerIds.length?"vectorSearchFields":"earlyExit").addConditionalEdges("vectorSearchFields",e=>e.vectorSearchFieldResults.length?"fieldStatistics":"earlyExit").addEdge("fieldStatistics","agent").addConditionalEdges("agent",e=>(e.messages[e.messages.length-1]?.tool_calls?.length??0)>0?"tools":"earlyExit").addEdge("tools","earlyExit").addEdge("earlyExit",x),za=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).
|
|
76
76
|
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.
|
|
77
77
|
_Example: “Only show stations where Brand is Shell”_
|
|
78
78
|
_Example: “Make Shell stations stand out on the map”_
|
|
79
|
-
_Example: “Gray out all stations that aren’t Shell”_`,Ns={id:"layerFilter",name:"Layer Filter Agent",description:za,createGraph:ka,workspace:Qe},Pe=g.Root({messages:g({reducer
|
|
79
|
+
_Example: “Gray out all stations that aren’t Shell”_`,Ns={id:"layerFilter",name:"Layer Filter Agent",description:za,createGraph:ka,workspace:Qe},Pe=g.Root({messages:g({reducer:$,default:()=>[]}),outputMessage:g({reducer:(e="",r)=>{let t=typeof r=="string"?r.trim():"";if(!t)return e;let a=e.trim();if(!a)return t;if(a===t)return e;let o=a.split(`
|
|
80
80
|
|
|
81
81
|
`);return o[o.length-1]?.trim()===t?e:`${e}
|
|
82
82
|
|
|
83
|
-
${t}`},default:()=>""}),vectorSearchLayerIds:g(),vectorSearchFieldResults:g(),layerFieldInfo:g(),queryResponses:g()}),Ma=async(e,r)=>(await m({text:"Exiting Layer Query agent"},r),e);function P(e){let r=e?.configurable?.context;if(!r||typeof r!="object")throw new Error("LayerQueryAgent context missing");let t=Ve.filter(a=>!(a in r));if(t.length)throw new Error(`LayerQueryAgent context missing: ${t.join(", ")}`);return r}var Ca=async(e,r)=>{try{await m({text:"Getting statistics for vector search results"},r);let t=b(r,"layersAndFieldsRegistry"),{mapView:a}=P(r),o=await me(e.vectorSearchFieldResults,t,a);return console.log("Field statistics retrieved:",o),await m({text:"Statistics retrieved"},r),{...e,layerFieldInfo:o}}catch(t){throw await m({text:"Error during fetching statistics"},r),new Error(`Error during fetching statistics: ${t instanceof Error?t.message:String(t)}`)}},$e=.7,ja=10,Va=async(e,r)=>{try{let t=
|
|
83
|
+
${t}`},default:()=>""}),vectorSearchLayerIds:g(),vectorSearchFieldResults:g(),layerFieldInfo:g(),queryResponses:g()}),Ma=async(e,r)=>(await m({text:"Exiting Layer Query agent"},r),e);function P(e){let r=e?.configurable?.context;if(!r||typeof r!="object")throw new Error("LayerQueryAgent context missing");let t=Ve.filter(a=>!(a in r));if(t.length)throw new Error(`LayerQueryAgent context missing: ${t.join(", ")}`);return r}var Ca=async(e,r)=>{try{await m({text:"Getting statistics for vector search results"},r);let t=b(r,"layersAndFieldsRegistry"),{mapView:a}=P(r),o=await me(e.vectorSearchFieldResults,t,a);return console.log("Field statistics retrieved:",o),await m({text:"Statistics retrieved"},r),{...e,layerFieldInfo:o}}catch(t){throw await m({text:"Error during fetching statistics"},r),new Error(`Error during fetching statistics: ${t instanceof Error?t.message:String(t)}`)}},$e=.7,ja=10,Va=async(e,r)=>{try{let t=_(e.messages);await m({text:"Similarity search to find fields"},r);let a=b(r,"fieldSearch"),o=b(r,"layersAndFieldsRegistry"),i=await a.searchFields({text:t,layerIds:e.vectorSearchLayerIds,minScore:$e,topResults:ja}),s=i.map(({layerId:d,results:c})=>{let u=c.map(h=>` - ${h.name} (${h.score.toFixed(2)})`).join(`
|
|
84
84
|
`);return`${o.get(d)?.layerItem.name??d}:
|
|
85
85
|
${u}`}).join(`
|
|
86
86
|
`),l;return i.length>0?l=`Vector search completed. Matching layers and fields with scores:
|
|
87
|
-
${s}`:l=`No vector search results found for score over ${$e}.`,await m({text:l},r),{...e,vectorSearchFieldResults:i}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},Oa=.7,Da=async(e,r)=>{try{let t=
|
|
87
|
+
${s}`:l=`No vector search results found for score over ${$e}.`,await m({text:l},r),{...e,vectorSearchFieldResults:i}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},Oa=.7,Da=async(e,r)=>{try{let t=_(e.messages);await m({text:`Similarity search to find layers: ${t}`},r);let a=b(r,"layerSearch"),o=b(r,"layersAndFieldsRegistry"),i=await a.searchLayers({text:t,minScore:Oa}),s=i.map(c=>c.id),l=i.map(({id:c,score:u})=>`${o.get(c)?.layerItem.name??c} (${u.toFixed(2)})`).join(`
|
|
88
88
|
`),d;return s.length>0?d=`Vector search completed. Matching layers with scores:
|
|
89
|
-
${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r),{...e,vectorSearchLayerIds:s}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},Ba=(e,r,t)=>{let a=e.createQuery();return a.outFields=[r],a.where=t||"1=1",a.num=1,a},Qa=async(e,r,t,a)=>{let o=a.map?.allLayers.find(d=>d.id===e),i=Ba(o,r,t.where),s=(await o.queryFeatures(i)).features[0],l=s?s.attributes[r]:null;return{tool:"getAttribute",layerName:o.title??e,summary:`${r} = ${l}`,details:{fieldName:r,value:l,where:t.where}}};async function Pa({layerId:e,fieldName:r,query:t},a){let{mapView:o}=P(a),i=await Qa(e,r,t,o);return JSON.stringify(i,null,2)}var Ga=n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),fieldName:n.string().describe("The name of the field/attribute from which to get a field value."),query:n.object({where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")})}),Wa=p(Pa,{name:"getAttribute",description:"Returns an attribute value for a given feature.",schema:Ga}),fe=async(e,r)=>{let t=r.map?.allLayers.find(i=>i.id===e.layerId);if(!t)return{error:`Could not find geometry layer with ID: ${e.layerId}`};let a=await t.queryFeatures({where:e.where,returnGeometry:!0});if(!a.features.length)return{error:`No features found in geometry layer with the specified where clause: ${e.where}`};let o;if(a.features.length===1){let i=a.features[0].geometry;if(!i)return{error:"The geometry of the first feature is undefined or null."};o=i}else{let i=a.features.map(l=>l.geometry),s=U.executeMany(i);if(!s)return{error:"Failed to create a combined geometry."};o=s}return{geometry:o}},Ua=async e=>{let{targetLayer:r,fieldName:t,statisticType:a,mapView:o,layersAndFieldsRegistry:i,geometryLayer:s}=e,l=o.map?.allLayers.find(f=>f.id===r.layerId);if(!l)throw new Error(`Layer '${r.layerId}' not found.`);let d=i.get(r.layerId)?.fieldRegistry.get(t);if(!d)throw new Error(`Field '${t}' not found.`);let c;if(s){let f=await fe(s,o);if("error"in f)throw new Error(f.error);if(c=f.geometry,s.distance&&s.units){let w=ke.execute(c,s.distance,{unit:s.units==="us-nautical-miles"?"nautical-miles":s.units});w&&(c=w)}}else c=o.extent.clone();let u=new V({geometry:c,spatialRelationship:"intersects"}),h=null,y=null;try{h=await ie({layer:l,field:t,sqlWhere:r.where,filter:u,outStatisticTypes:{include:[a]}}),d.type==="string"&&(y=(await ne({layer:l,field:t,sqlWhere:r.where,filter:u})).uniqueValueInfos)}catch(f){console.error("Statistics error:",f)}return{tool:"getStatistics",layerName:l.title??r.layerId,summary:`${a} = ${typeof h?.[a]=="number"?h[a]:"N/A"}`,details:{fieldName:t,statisticType:a,statistic:h?.[a]??null,summaryStatistics:h,uniqueValues:y,where:r.where}}},Ja=["feet","kilometers","meters","miles","nautical-miles","us-nautical-miles"],Za=n.enum(Ja);async function Ha({targetLayer:e,fieldName:r,statisticType:t,geometryLayer:a},o){let i=b(o,"layersAndFieldsRegistry"),{mapView:s}=P(o),l=await Ua({targetLayer:e,fieldName:r,statisticType:t,mapView:s,layersAndFieldsRegistry:i,geometryLayer:a});return console.log(l),JSON.stringify(l,null,2)}var Ka=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")}),geometryLayer:n.union([n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().optional().describe("The distance by which to query from the input geometry."),units:Za.optional().describe("The units used to query by geometry and distance.")}),n.object({}).strict()]).optional().describe("Optional geometry-based filtering parameters for spatial queries."),fieldName:n.string().describe("The name of the field for which to get statistics."),statisticType:n.enum(["avg","max","median","min","stddev","sum","variance","nullcount","count"]).describe("The statistic type to calculate.")}),Ya=p(Ha,{name:"getStatistics",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.",schema:Ka}),Xa=async(e,r,t,a)=>{let o=t.map?.allLayers.find(c=>c.id===e.layerId),i=a?await fe(a,t):{geometry:void 0},s="geometry"in i?i.geometry:void 0,l=new Ae({where:e.where||"1=1",outFields:e.outFields.length?e.outFields:["*"],orderByFields:e.orderByFields,geometry:s,spatialRelationship:s?"intersects":void 0,distance:a?.distance,units:a?.units,topFilter:new qe({topCount:r.topCount,groupByFields:r.groupByFields,orderByFields:r.orderByFields})}),d=await o.queryTopFeatures(l);return{tool:"getTopFeatures",layerName:o.title??e.layerId,summary:`Top ${r.topCount} features extracted`,details:{topCount:r.topCount,features:d.features,where:e.where}}},eo=async({targetLayer:e,topFilter:r,geometryLayer:t},a)=>{let{mapView:o}=P(a),i=await Xa(e,r,o,t);return JSON.stringify(i,null,2)},to=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),outFields:n.array(n.string().describe("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."))}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to query from the input geometry."),units:z.describe("The units used to query by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries."),topFilter:n.object({topCount:n.number().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),groupByFields:n.array(n.string().describe("The field(s) for which to group by the top features."))})}),ro=p(eo,{name:"getTopFeatures",description:"Returns the top n features from a layer",schema:to}),ao=async(e,r,t)=>{let a=r.map?.allLayers.find(d=>d.id===e.layerId),o=t?await fe(t,r):{geometry:void 0},i="geometry"in o?o.geometry:void 0,s=new se({where:e.where||"1=1",outFields:e.outFields.length?e.outFields:["*"],orderByFields:e.orderByFields,geometry:i,spatialRelationship:i?"intersects":void 0,distance:t?.distance,units:t?.units}),l=await a.queryFeatures(s);return{tool:"queryFeatures",layerName:a.title??e.layerId,summary:`${l.features.length} features found`,details:{totalCount:l.features.length,features:l.features.slice(0,10),where:e.where}}};async function oo({targetLayer:e,geometryLayer:r},t){let{mapView:a}=P(t),o=await ao(e,a,r);return JSON.stringify(o,null,2)}var io=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),outFields:n.array(n.string().describe("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."))}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to query from the input geometry."),units:z.describe("The units used to query by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries.")}),no=p(oo,{name:"queryFeatures",description:"Queries for one or more features from a given layer.",schema:io}),Ge=[no,Ya,Wa,ro],so=async(e,r)=>{await m({text:"Requesting LLM for layer query results"},r);let t=await q("data_query_prompt");if(!r?.configurable)throw new Error("config.configurable is required for layer query tools");let{userTimezone:a,userTimezoneOffset:o}=J(),i={layerFieldInfo:e.layerFieldInfo,userTimezone:a,userTimezoneOffset:o},s=await C({promptText:t,messages:S(e.messages),inputVariables:i,tools:Ge});if(!(s.tool_calls&&Array.isArray(s.tool_calls)&&s.tool_calls.length>0))return{...e,messages:[...e.messages,s]};let l=s.content.toString()||"LLM requested tool calls.";return await B(s,r),{...e,outputMessage:l,messages:[...e.messages,s]}},lo=new L(Ge);async function co(e,r){let{messages:t}=await lo.invoke({messages:S(e.messages)},r),a=[],o=[];for(let l of t){let d=l.content;if(typeof d!="string"){console.warn("Skipping non-string tool output:",d);continue}let c;try{c=JSON.parse(d)}catch{console.warn("Skipping invalid JSON from tool:",d);continue}a.push(c),o.push(`- ${c.layerName}: ${c.summary}`)}if(o.length===0)return{...e,queryResponses:a};let i=new j({content:`Query results:
|
|
89
|
+
${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r),{...e,vectorSearchLayerIds:s}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},Ba=(e,r,t)=>{let a=e.createQuery();return a.outFields=[r],a.where=t||"1=1",a.num=1,a},Qa=async(e,r,t,a)=>{let o=a.map?.allLayers.find(d=>d.id===e),i=Ba(o,r,t.where),s=(await o.queryFeatures(i)).features[0],l=s?s.attributes[r]:null;return{tool:"getAttribute",layerName:o.title??e,summary:`${r} = ${l}`,details:{fieldName:r,value:l,where:t.where}}};async function Pa({layerId:e,fieldName:r,query:t},a){let{mapView:o}=P(a),i=await Qa(e,r,t,o);return JSON.stringify(i,null,2)}var Ga=n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),fieldName:n.string().describe("The name of the field/attribute from which to get a field value."),query:n.object({where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")})}),Wa=p(Pa,{name:"getAttribute",description:"Returns an attribute value for a given feature.",schema:Ga}),fe=async(e,r)=>{let t=r.map?.allLayers.find(i=>i.id===e.layerId);if(!t)return{error:`Could not find geometry layer with ID: ${e.layerId}`};let a=await t.queryFeatures({where:e.where,returnGeometry:!0});if(!a.features.length)return{error:`No features found in geometry layer with the specified where clause: ${e.where}`};let o;if(a.features.length===1){let i=a.features[0].geometry;if(!i)return{error:"The geometry of the first feature is undefined or null."};o=i}else{let i=a.features.map(l=>l.geometry),s=U.executeMany(i);if(!s)return{error:"Failed to create a combined geometry."};o=s}return{geometry:o}},Ua=async e=>{let{targetLayer:r,fieldName:t,statisticType:a,mapView:o,layersAndFieldsRegistry:i,geometryLayer:s}=e,l=o.map?.allLayers.find(f=>f.id===r.layerId);if(!l)throw new Error(`Layer '${r.layerId}' not found.`);let d=i.get(r.layerId)?.fieldRegistry.get(t);if(!d)throw new Error(`Field '${t}' not found.`);let c;if(s){let f=await fe(s,o);if("error"in f)throw new Error(f.error);if(c=f.geometry,s.distance&&s.units){let w=ke.execute(c,s.distance,{unit:s.units==="us-nautical-miles"?"nautical-miles":s.units});w&&(c=w)}}else c=o.extent.clone();let u=new V({geometry:c,spatialRelationship:"intersects"}),h=null,y=null;try{h=await ie({layer:l,field:t,sqlWhere:r.where,filter:u,outStatisticTypes:{include:[a]}}),d.type==="string"&&(y=(await ne({layer:l,field:t,sqlWhere:r.where,filter:u})).uniqueValueInfos)}catch(f){console.error("Statistics error:",f)}return{tool:"getStatistics",layerName:l.title??r.layerId,summary:`${a} = ${typeof h?.[a]=="number"?h[a]:"N/A"}`,details:{fieldName:t,statisticType:a,statistic:h?.[a]??null,summaryStatistics:h,uniqueValues:y,where:r.where}}},Ha=["feet","kilometers","meters","miles","nautical-miles","us-nautical-miles"],Ja=n.enum(Ha);async function Za({targetLayer:e,fieldName:r,statisticType:t,geometryLayer:a},o){let i=b(o,"layersAndFieldsRegistry"),{mapView:s}=P(o),l=await Ua({targetLayer:e,fieldName:r,statisticType:t,mapView:s,layersAndFieldsRegistry:i,geometryLayer:a});return console.log(l),JSON.stringify(l,null,2)}var Ka=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value.")}),geometryLayer:n.union([n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().optional().describe("The distance by which to query from the input geometry."),units:Ja.optional().describe("The units used to query by geometry and distance.")}),n.object({}).strict()]).optional().describe("Optional geometry-based filtering parameters for spatial queries."),fieldName:n.string().describe("The name of the field for which to get statistics."),statisticType:n.enum(["avg","max","median","min","stddev","sum","variance","nullcount","count"]).describe("The statistic type to calculate.")}),Ya=p(Za,{name:"getStatistics",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.",schema:Ka}),Xa=async(e,r,t,a)=>{let o=t.map?.allLayers.find(c=>c.id===e.layerId),i=a?await fe(a,t):{geometry:void 0},s="geometry"in i?i.geometry:void 0,l=new Ae({where:e.where||"1=1",outFields:e.outFields.length?e.outFields:["*"],orderByFields:e.orderByFields,geometry:s,spatialRelationship:s?"intersects":void 0,distance:a?.distance,units:a?.units,topFilter:new qe({topCount:r.topCount,groupByFields:r.groupByFields,orderByFields:r.orderByFields})}),d=await o.queryTopFeatures(l);return{tool:"getTopFeatures",layerName:o.title??e.layerId,summary:`Top ${r.topCount} features extracted`,details:{topCount:r.topCount,features:d.features,where:e.where}}},eo=async({targetLayer:e,topFilter:r,geometryLayer:t},a)=>{let{mapView:o}=P(a),i=await Xa(e,r,o,t);return JSON.stringify(i,null,2)},to=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),outFields:n.array(n.string().describe("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."))}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to query from the input geometry."),units:z.describe("The units used to query by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries."),topFilter:n.object({topCount:n.number().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),groupByFields:n.array(n.string().describe("The field(s) for which to group by the top features."))})}),ro=p(eo,{name:"getTopFeatures",description:"Returns the top n features from a layer",schema:to}),ao=async(e,r,t)=>{let a=r.map?.allLayers.find(d=>d.id===e.layerId),o=t?await fe(t,r):{geometry:void 0},i="geometry"in o?o.geometry:void 0,s=new se({where:e.where||"1=1",outFields:e.outFields.length?e.outFields:["*"],orderByFields:e.orderByFields,geometry:i,spatialRelationship:i?"intersects":void 0,distance:t?.distance,units:t?.units}),l=await a.queryFeatures(s);return{tool:"queryFeatures",layerName:a.title??e.layerId,summary:`${l.features.length} features found`,details:{totalCount:l.features.length,features:l.features.slice(0,10),where:e.where}}};async function oo({targetLayer:e,geometryLayer:r},t){let{mapView:a}=P(t),o=await ao(e,a,r);return JSON.stringify(o,null,2)}var io=n.object({targetLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the field from which to get a value."),where:n.string().describe("The SQL-92 where clause representing the feature from which to get an attribute value."),orderByFields:n.array(n.string().describe("The field(s) and order for which to sort the resulting features.")),outFields:n.array(n.string().describe("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."))}),geometryLayer:n.object({layerId:n.string().describe("The layerId of the layer containing the geometry by which to filter."),where:n.string().describe("The SQL-92 where clause representing the features from which to filter features from the targetLayer by geometry."),distance:n.number().describe("The distance by which to query from the input geometry."),units:z.describe("The units used to query by geometry and distance.")}).optional().describe("Optional geometry-based filtering parameters for spatial queries.")}),no=p(oo,{name:"queryFeatures",description:"Queries for one or more features from a given layer.",schema:io}),Ge=[no,Ya,Wa,ro],so=async(e,r)=>{await m({text:"Requesting LLM for layer query results"},r);let t=await q("data_query_prompt");if(!r?.configurable)throw new Error("config.configurable is required for layer query tools");let{userTimezone:a,userTimezoneOffset:o}=H(),i={layerFieldInfo:e.layerFieldInfo,userTimezone:a,userTimezoneOffset:o},s=await C({promptText:t,messages:S(e.messages),inputVariables:i,tools:Ge});if(!(s.tool_calls&&Array.isArray(s.tool_calls)&&s.tool_calls.length>0))return{...e,messages:[...e.messages,s]};let l=s.content.toString()||"LLM requested tool calls.";return await B(s,r),{...e,outputMessage:l,messages:[...e.messages,s]}},lo=new L(Ge);async function co(e,r){let{messages:t}=await lo.invoke({messages:S(e.messages)},r),a=[],o=[];for(let l of t){let d=l.content;if(typeof d!="string"){console.warn("Skipping non-string tool output:",d);continue}let c;try{c=JSON.parse(d)}catch{console.warn("Skipping invalid JSON from tool:",d);continue}a.push(c),o.push(`- ${c.layerName}: ${c.summary}`)}if(o.length===0)return{...e,queryResponses:a};let i=new j({content:`Query results:
|
|
90
90
|
${o.join(`
|
|
91
91
|
`)}`}),s=`Query results:
|
|
92
92
|
${o.join(`
|
|
93
|
-
`)}`;return{...e,outputMessage:s,messages:[...e.messages,...t,i],queryResponses:a}}var uo=async(e,r)=>{try{await m({text:"Requesting LLM for summary on query results"},r);let t=await q("summarize_query_response_prompt"),a={queryResponse:e.queryResponses},o=await Y({promptText:t,messages:S(e.messages),inputVariables:a}),i=typeof o=="string"?o:o.content;return e.messages=[...e.messages,new j(i)],e.outputMessage=i,await m({text:`Received response from LLM: ${i}`},r),e}catch(t){throw await m({text:"Error during filter LLM request"},r),new Error(`Error during filter LLM request: ${t instanceof Error?t.message:String(t)}`)}},mo=(e,r)=>D(["layerSearch","fieldSearch","layersAndFieldsRegistry"],"Layer Query Agent")(e,r),ho=()=>new
|
|
93
|
+
`)}`;return{...e,outputMessage:s,messages:[...e.messages,...t,i],queryResponses:a}}var uo=async(e,r)=>{try{await m({text:"Requesting LLM for summary on query results"},r);let t=await q("summarize_query_response_prompt"),a={queryResponse:e.queryResponses},o=await Y({promptText:t,messages:S(e.messages),inputVariables:a}),i=typeof o=="string"?o:o.content;return e.messages=[...e.messages,new j(i)],e.outputMessage=i,await m({text:`Received response from LLM: ${i}`},r),e}catch(t){throw await m({text:"Error during filter LLM request"},r),new Error(`Error during filter LLM request: ${t instanceof Error?t.message:String(t)}`)}},mo=(e,r)=>D(["layerSearch","fieldSearch","layersAndFieldsRegistry"],"Layer Query Agent")(e,r),ho=()=>new A(Pe).addNode("requireLayerQueryServices",mo).addNode("vectorSearchLayers",Da).addNode("vectorSearchFields",Va).addNode("fieldStatistics",Ca).addNode("agent",so).addNode("tools",co).addNode("summarizeQueryResponseLLM",uo).addNode("earlyExit",Ma).addEdge(R,"requireLayerQueryServices").addEdge("requireLayerQueryServices","vectorSearchLayers").addConditionalEdges("vectorSearchLayers",e=>e.vectorSearchLayerIds.length?"vectorSearchFields":"earlyExit").addConditionalEdges("vectorSearchFields",e=>e.vectorSearchFieldResults.length?"fieldStatistics":"earlyExit").addEdge("fieldStatistics","agent").addEdge("agent","tools").addConditionalEdges("tools",e=>e.queryResponses.length?"summarizeQueryResponseLLM":"earlyExit").addEdge("summarizeQueryResponseLLM",x).addEdge("earlyExit",x),fo=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.
|
|
94
94
|
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?”).
|
|
95
95
|
_Example: “How many features are there?”_
|
|
96
96
|
_Example: “What’s the average population?”_
|
|
97
|
-
_Example: “Which values are in the status field?”_`,Rs={id:"layerQuery",name:"Layer Query Agent",description:fo,createGraph:ho,workspace:Pe},Fe=.7,go=10,yo=async(e,r)=>{try{let t=
|
|
97
|
+
_Example: “Which values are in the status field?”_`,Rs={id:"layerQuery",name:"Layer Query Agent",description:fo,createGraph:ho,workspace:Pe},Fe=.7,go=10,yo=async(e,r)=>{try{let t=_(e.messages);await m({text:"Similarity search to find fields"},r);let a=b(r,"fieldSearch"),o=b(r,"layersAndFieldsRegistry"),i=await a.searchFields({text:t,layerIds:e.vectorSearchLayerIds,minScore:Fe,topResults:go}),s=i.map(({layerId:d,results:c})=>{let u=c.map(h=>` - ${h.name} (${h.score.toFixed(2)})`).join(`
|
|
98
98
|
`);return`${o.get(d)?.layerItem.name??d}:
|
|
99
99
|
${u}`}).join(`
|
|
100
100
|
`),l;return i.length>0?l=`Vector search completed. Matching layers and fields with scores:
|
|
101
|
-
${s}`:l=`No vector search results found for score over ${Fe}.`,await m({text:l},r),{...e,vectorSearchFieldResults:i}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},po=.7,wo=async(e,r)=>{try{let t=
|
|
101
|
+
${s}`:l=`No vector search results found for score over ${Fe}.`,await m({text:l},r),{...e,vectorSearchFieldResults:i}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}},po=.7,wo=async(e,r)=>{try{let t=_(e.messages);await m({text:`Similarity search to find layers: ${t}`},r);let a=b(r,"layerSearch"),o=b(r,"layersAndFieldsRegistry"),i=await a.searchLayers({text:t,minScore:po}),s=i.map(c=>c.id),l=i.map(({id:c,score:u})=>`${o.get(c)?.layerItem.name??c} (${u.toFixed(2)})`).join(`
|
|
102
102
|
`),d;return s.length>0?d=`Vector search completed. Matching layers with scores:
|
|
103
103
|
${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r),{...e,vectorSearchLayerIds:s}}catch(t){throw await m({text:`Error during vector search: ${t instanceof Error?t.message:String(t)}`},r),new Error(`Vector search failed: ${t instanceof Error?t.message:String(t)}`)}};async function bo(e){let{fields:r,layer:t,view:a,styleName:o,colorSchemeTags:i}=e,s;return i?s=it({basemapTheme:await Te(a),geometryType:t.geometryType,includedTags:i,numColors:Math.min(r.length,8)})[0]:s=nt({basemapTheme:await Te(a),geometryType:t.geometryType,numColors:Math.min(r.length,8)}).primaryScheme,{layer:t,view:a,attributes:r.map(l=>({field:l,label:t.fields.find(d=>d.name===l)?.alias??""})).slice(0,8),outlineOptimizationEnabled:!0,sizeOptimizationEnabled:!0,includeSizeVariable:o.includes("Size"),pieChartScheme:s}}async function So(e){return await ot(e)}async function vo({arcgisMap:e,arcgisMapView:r,layerId:t,fields:a,colorSchemes:o,includeSize:i}){let s=r,l=e?.allLayers.find(c=>c.id===t);if(!l)return`Could not find layer for id: ${t}`;let d={styleName:i?"chart-size":"chart",fields:a,layer:l,view:s,colorSchemeTags:o};try{let c=await bo(d),u=await So(c);return l.renderer=u.renderer,l.visible=!0,`Chart renderer applied to layer: ${l.title??l.id} using fields ${a.join(", ")}`}catch(c){return`Error applying chart renderer: ${c instanceof Error?c.message:String(c)}`}}var To=["mapView"];function I(e){let r=e?.configurable?.context;if(!r||typeof r!="object")throw new Error("LayerStylingAgent context missing");let t=To.filter(a=>!(a in r));if(t.length)throw new Error(`LayerStylingAgent context missing: ${t.join(", ")}`);return r}async function xo({layerId:e,fields:r,colorSchemes:t,includeSize:a},o){let{mapView:i}=I(o);return await E({id:"show-legend",description:"Show Legend",payload:{layerIds:[e]}},o),await vo({arcgisMap:i.map,arcgisMapView:i,layerId:e,fields:r,colorSchemes:t,includeSize:a})}var Eo=n.object({layerId:n.string().describe("The id of the layer to apply the chart renderer to"),fields:n.array(n.string()).describe("The fields to use for the chart renderer (multiple numeric fields)"),colorSchemes:n.array(n.string()).optional().describe("Optional color scheme tags to use"),includeSize:n.boolean().optional().describe("Whether to vary the chart size (chart-size)")}),Lo=p(xo,{name:"chart",description:`Label: Charts
|
|
104
104
|
Description: Show the values of two or more categories as a proportion of the total using a pie chart.
|
|
@@ -122,7 +122,7 @@ ${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r)
|
|
|
122
122
|
Description: Vary symbol size and color based on the values of two numeric attributes.
|
|
123
123
|
Keywords: continuous color, hue, color, size, gradation, saturation, lightness, percent, rate, ratio, index, how much, increase, decrease, amount
|
|
124
124
|
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.
|
|
125
|
-
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.`,schema:Bo});function Po(e){let{fields:r,layer:t,view:a,colorSchemeTags:o}=e,i;return o&&(i=ut({includedTags:o,numColors:Math.min(r.length,8)})[0]),{layer:t,view:a,legendOptions:{unit:"units"},attributes:r.map(s=>({field:s,label:t.fields.find(l=>l.name===s)?.alias??""})).slice(0,8),outlineOptimizationEnabled:!0,dotDensityScheme:i}}async function Go(e){return await dt(e)}async function Wo({arcgisMap:e,arcgisMapView:r,layerId:t,fields:a,colorSchemes:o}){let i=r,s=e?.allLayers.find(d=>d.id===t);if(!s)return`Could not find layer for id: ${t}`;let l={styleName:"dot-density",fields:a,layer:s,view:i,colorSchemeTags:o};try{let d=Po(l),c=await Go(d);return s.renderer=c.renderer,s.visible=!0,`Dot Density renderer applied to layer: ${s.title??s.id} using fields ${a.join(", ")}`}catch(d){return`Error applying dot density renderer: ${d instanceof Error?d.message:String(d)}`}}async function Uo({layerId:e,fields:r,colorSchemes:t},a){let{mapView:o}=I(a);return await E({id:"show-legend",description:"Show Legend",payload:{layerIds:[e]}},a),await Wo({arcgisMap:o.map,arcgisMapView:o,layerId:e,fields:r,colorSchemes:t})}var
|
|
125
|
+
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.`,schema:Bo});function Po(e){let{fields:r,layer:t,view:a,colorSchemeTags:o}=e,i;return o&&(i=ut({includedTags:o,numColors:Math.min(r.length,8)})[0]),{layer:t,view:a,legendOptions:{unit:"units"},attributes:r.map(s=>({field:s,label:t.fields.find(l=>l.name===s)?.alias??""})).slice(0,8),outlineOptimizationEnabled:!0,dotDensityScheme:i}}async function Go(e){return await dt(e)}async function Wo({arcgisMap:e,arcgisMapView:r,layerId:t,fields:a,colorSchemes:o}){let i=r,s=e?.allLayers.find(d=>d.id===t);if(!s)return`Could not find layer for id: ${t}`;let l={styleName:"dot-density",fields:a,layer:s,view:i,colorSchemeTags:o};try{let d=Po(l),c=await Go(d);return s.renderer=c.renderer,s.visible=!0,`Dot Density renderer applied to layer: ${s.title??s.id} using fields ${a.join(", ")}`}catch(d){return`Error applying dot density renderer: ${d instanceof Error?d.message:String(d)}`}}async function Uo({layerId:e,fields:r,colorSchemes:t},a){let{mapView:o}=I(a);return await E({id:"show-legend",description:"Show Legend",payload:{layerIds:[e]}},a),await Wo({arcgisMap:o.map,arcgisMapView:o,layerId:e,fields:r,colorSchemes:t})}var Ho=n.object({layerId:n.string().describe("The id of the layer to apply the dot density renderer to"),fields:n.array(n.string()).describe("The field(s) to use for the dot density renderer (population or count data)"),colorSchemes:n.array(n.string()).optional().describe("Optional color scheme tags to use")}),Jo=p(Uo,{name:"dot-density",description:`Dot Density
|
|
126
126
|
Use dot density to visualize the distribution of one attribute or compare the density of multiple attributes. This is only valid for polygon layers.
|
|
127
127
|
**Use cases:**
|
|
128
128
|
- Population distribution visualization
|
|
@@ -133,7 +133,7 @@ ${l}`:d="Vector search completed. No matching layers found.",await m({text:d},r)
|
|
|
133
133
|
- Visualize distribution of different crops across regions
|
|
134
134
|
- Display demographic patterns within census tracts
|
|
135
135
|
**Fields:** Requires 2-8 number fields.
|
|
136
|
-
**Keywords:** density, how much, how many, total, number, amount`,schema:
|
|
136
|
+
**Keywords:** density, how much, how many, total, number, amount`,schema:Ho});function Zo(e){let{fields:r,layer:t,view:a,colorSchemeTags:o}=e,i,s=r[0];return o&&(i=ht({includedTags:o,basemap:a.map?.basemap||"topo"})[0]),{layer:t,view:a,field:s,heatmapScheme:i}}async function Ko(e){return await mt(e)}async function Yo({arcgisMap:e,arcgisMapView:r,layerId:t,fields:a,colorSchemes:o}){let i=r,s=e?.allLayers.find(d=>d.id===t);if(!s)return`Could not find layer for id: ${t}`;let l={styleName:"heatmap",fields:a,layer:s,view:i,colorSchemeTags:o};try{let d=Zo(l),c=await Ko(d);return s.renderer=c.renderer,s.visible=!0,`Heatmap renderer applied to layer: ${s.title??s.id} using fields ${a.join(", ")}`}catch(d){return`Error applying heatmap renderer: ${d instanceof Error?d.message:String(d)}`}}async function Xo({layerId:e,fields:r,colorSchemes:t},a){let{mapView:o}=I(a);return await E({id:"show-legend",description:"Show Legend",payload:{layerIds:[e]}},a),await Yo({arcgisMap:o.map,arcgisMapView:o,layerId:e,fields:r,colorSchemes:t})}var ei=n.object({layerId:n.string().describe("The id of the layer to apply the heatmap renderer to"),fields:n.array(n.string()).describe("The field(s) to use for the heatmap renderer (typically point density)"),colorSchemes:n.array(n.string()).optional().describe("Optional color scheme tags to use")}),ti=p(Xo,{name:"heatmap",description:`Label: Heat Map
|
|
137
137
|
Description: Show areas of high density with colors that appear to glow hotter. This is only valid for point layers.
|
|
138
138
|
Keywords: density, heatmap, hot spots, pattern, cluster
|
|
139
139
|
Example: Create a heatmap
|
|
@@ -169,21 +169,38 @@ Fields: This typically requires zero or one field of type number.`,schema:ei});f
|
|
|
169
169
|
Description: Represent features as categories with different symbol colors or shapes. Examples include type of tree, road class, or province name.
|
|
170
170
|
Keywords: categorical, category, type, unique, discrete, point of interest, region, group
|
|
171
171
|
Example: Color each feature based on the region it belongs to
|
|
172
|
-
Fields: This style requires a single field which may be a string, number, or date type. It is usually a string.`,schema:Ni}),We=[Lo,Ro,Co,Qo,
|
|
172
|
+
Fields: This style requires a single field which may be a string, number, or date type. It is usually a string.`,schema:Ni}),We=[Lo,Ro,Co,Qo,Jo,ti,si,hi,bi,Li,Ri],Ai=async(e,r)=>{await m({text:"Requesting LLM for layer query results"},r);let t=await q("navigation_intent_prompt");if(!r?.configurable)throw new Error("config.configurable is required for layer query tools");let a={layerFieldInfo:e.layerFieldInfo},o=await C({promptText:t,messages:S(e.messages),inputVariables:a,tools:We});return await B(o,r),{...e,messages:[...e.messages,o]}};async function qi(e,r){let t=await new L(We).invoke({messages:S(e.messages)},r),a=t.messages.map(i=>i.text).join(`
|
|
173
173
|
`);await m({text:`Finished executing layer filter tool: ${a}`},r);let o=t.messages.map(i=>i.text).join(`
|
|
174
|
-
`);return{...e,outputMessage:o}}var Ue=g.Root({messages:g({reducer
|
|
174
|
+
`);return{...e,outputMessage:o}}var Ue=g.Root({messages:g({reducer:$,default:()=>[]}),outputMessage:g({reducer:(e="",r)=>{let t=typeof r=="string"?r.trim():"";if(!t)return e;let a=e.trim();if(!a)return t;if(a===t)return e;let o=a.split(`
|
|
175
175
|
|
|
176
176
|
`);return o[o.length-1]?.trim()===t?e:`${e}
|
|
177
177
|
|
|
178
|
-
${t}`},default:()=>""}),vectorSearchLayerIds:g(),vectorSearchFieldResults:g(),layerFieldInfo:g(),selectedLayerId:g()}),ki=async(e,r)=>(await m({text:"Exiting Layer Styling agent"},r),e),zi=async(e,r)=>{try{await m({text:"Populating layer and field info"},r);let t=[];for(let a of e.vectorSearchFieldResults){let o=function(u){let h=l.get(u)?.layerItem;return h?[h.name&&`Name: ${h.name}`,h.title&&`Title: ${h.title}`,h.description&&`Description: ${h.description}`].filter(Boolean).join(" | "):u},{layerId:i,results:s}=a,l=b(r,"layersAndFieldsRegistry"),d=l.get(i)?.fieldRegistry;if(!d)continue;let c=t.find(u=>u.layerId===i);c||(c={layerId:i,layerSummary:o(i),fieldInfos:[]},t.push(c));for(let u of s){let h=d.get(u.name);h&&c.fieldInfos.push(h)}}return console.log("Populated layerFieldInfo:",t),await m({text:"Populated layerFieldInfo"},r),{...e,layerFieldInfo:t}}catch(t){throw await m({text:"Error populating layerFieldInfo"},r),new Error(`Error populating layerFieldInfo: ${t instanceof Error?t.message:String(t)}`)}},Mi=(e,r)=>{let t=e.vectorSearchLayerIds??[];if(t.length<=1)return{...e,selectedLayerId:e.vectorSearchLayerIds[0]};let{hitlResponse:a}=r.configurable;if(console.log("hitlResponse:",a),!a||a.agentId!==_e.id||a.id!=="reviewLayerSelection"){let i={agentId:_e.id,id:"reviewLayerSelection",kind:"singleSelection",message:"Choose a layer to apply the styles.",metadata:[...t]};throw new ge(i)}let o=null;return Array.isArray(a.payload)&&a.payload.length>0&&(o=a.payload[0]),{...e,selectedLayerId:o??e.vectorSearchLayerIds[0]}},Ci=(e,r)=>D(["layerSearch","fieldSearch","layersAndFieldsRegistry"],"Layer Styling Agent")(e,r),ji=()=>new
|
|
178
|
+
${t}`},default:()=>""}),vectorSearchLayerIds:g(),vectorSearchFieldResults:g(),layerFieldInfo:g(),selectedLayerId:g()}),ki=async(e,r)=>(await m({text:"Exiting Layer Styling agent"},r),e),zi=async(e,r)=>{try{await m({text:"Populating layer and field info"},r);let t=[];for(let a of e.vectorSearchFieldResults){let o=function(u){let h=l.get(u)?.layerItem;return h?[h.name&&`Name: ${h.name}`,h.title&&`Title: ${h.title}`,h.description&&`Description: ${h.description}`].filter(Boolean).join(" | "):u},{layerId:i,results:s}=a,l=b(r,"layersAndFieldsRegistry"),d=l.get(i)?.fieldRegistry;if(!d)continue;let c=t.find(u=>u.layerId===i);c||(c={layerId:i,layerSummary:o(i),fieldInfos:[]},t.push(c));for(let u of s){let h=d.get(u.name);h&&c.fieldInfos.push(h)}}return console.log("Populated layerFieldInfo:",t),await m({text:"Populated layerFieldInfo"},r),{...e,layerFieldInfo:t}}catch(t){throw await m({text:"Error populating layerFieldInfo"},r),new Error(`Error populating layerFieldInfo: ${t instanceof Error?t.message:String(t)}`)}},Mi=(e,r)=>{let t=e.vectorSearchLayerIds??[];if(t.length<=1)return{...e,selectedLayerId:e.vectorSearchLayerIds[0]};let{hitlResponse:a}=r.configurable;if(console.log("hitlResponse:",a),!a||a.agentId!==_e.id||a.id!=="reviewLayerSelection"){let i={agentId:_e.id,id:"reviewLayerSelection",kind:"singleSelection",message:"Choose a layer to apply the styles.",metadata:[...t]};throw new ge(i)}let o=null;return Array.isArray(a.payload)&&a.payload.length>0&&(o=a.payload[0]),{...e,selectedLayerId:o??e.vectorSearchLayerIds[0]}},Ci=(e,r)=>D(["layerSearch","fieldSearch","layersAndFieldsRegistry"],"Layer Styling Agent")(e,r),ji=()=>new A(Ue).addNode("requireLayerStylingServices",Ci).addNode("vectorSearchLayers",wo).addNode("layerSelectionHITL",Mi).addNode("vectorSearchFields",yo).addNode("populateLayerFieldInfo",zi).addNode("agent",Ai).addNode("tools",qi).addNode("earlyExit",ki).addEdge(R,"requireLayerStylingServices").addEdge("requireLayerStylingServices","vectorSearchLayers").addConditionalEdges("layerSelectionHITL",e=>e.vectorSearchLayerIds.length?"vectorSearchFields":"earlyExit").addConditionalEdges("vectorSearchFields",e=>e.vectorSearchFieldResults.length?"populateLayerFieldInfo":"earlyExit").addEdge("populateLayerFieldInfo","agent").addEdge("agent","tools").addEdge("tools",x).addEdge("earlyExit",x),Vi=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.
|
|
179
179
|
_Example: “Color points by sales amount”_
|
|
180
180
|
_Example: “Show population density with a color gradient”_
|
|
181
181
|
_Example: “Create a relationship map between height and depth”_
|
|
182
|
-
_Example: “Vary circle sizes according to population”_`,_e={id:"layerStyling",name:"Layer Styling Agent",description:Vi,createGraph:ji,workspace:Ue},As=g.Root({messages:g({reducer
|
|
182
|
+
_Example: “Vary circle sizes according to population”_`,_e={id:"layerStyling",name:"Layer Styling Agent",description:Vi,createGraph:ji,workspace:Ue},As=g.Root({messages:g({reducer:$,default:()=>[]}),outputMessage:g({reducer:(e="",r)=>{let t=typeof r=="string"?r.trim():"";if(!t)return e;let a=e.trim();if(!a)return t;if(a===t)return e;let o=a.split(`
|
|
183
183
|
|
|
184
184
|
`);return o[o.length-1]?.trim()===t?e:`${e}
|
|
185
185
|
|
|
186
|
-
${t}`},default:()=>""})
|
|
186
|
+
${t}`},default:()=>""})});var qs=String.raw`- **help** — Enables users to ask questions about the map, layers, fields, and it's capabilities.
|
|
187
|
+
|
|
188
|
+
_Example: “Tell me about this map”_
|
|
189
|
+
_Example: “List all layers in this map”_
|
|
190
|
+
_Example: “List fields in protected areas layer”_
|
|
191
|
+
_Example: “What agents are available to me?”_
|
|
192
|
+
_Example: “What can you do?”_
|
|
193
|
+
_Example: “What can I ask”_
|
|
194
|
+
|
|
195
|
+
Even if the user asks unrelated queries like "What are the vowels in English alphabet" or "How to cook", call this agent.
|
|
196
|
+
|
|
197
|
+
IF the user asks map related queries, but those that are not performed by any of the agents, call this agent so we can respond accordingly.
|
|
198
|
+
_Example: "Create a chart"_
|
|
199
|
+
_Example: "Create a table"_`;var ks=g.Root({messages:g({reducer:$,default:()=>[]}),outputMessage:g({reducer:(e="",r)=>{let t=typeof r=="string"?r.trim():"";if(!t)return e;let a=e.trim();if(!a)return t;if(a===t)return e;let o=a.split(`
|
|
200
|
+
|
|
201
|
+
`);return o[o.length-1]?.trim()===t?e:`${e}
|
|
202
|
+
|
|
203
|
+
${t}`},default:()=>""}),intent:g({reducer:(e,r)=>r})}),Oi=["linkChartView"];function He(e){let r=e?.configurable?.context;if(!r||typeof r!="object")throw new Error("LinkChartAgent context missing");let t=Oi.filter(a=>!(a in r));if(t.length)throw new Error(`Link Chart context missing: ${t.join(", ")}`);return r}async function Di(e,r){return await r.map.applyLayout(e),`Successfully applied layout: ${e}.`}async function Bi({layout:e},r){let{linkChartView:t}=He(r);return await Di(e,t)}var Qi=n.object({layout:n.enum(["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"]).describe("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")}),zs=p(Bi,{name:"applyLayout",description:"Apply a diagram layout to the link chart",schema:Qi});function Pi(e,r){return r.map.changeNonspatialDataDisplay(e),`Successfully applied nonspatial visibility setting: ${e}.`}function Gi({setting:e},r){let{linkChartView:t}=He(r);return Pi(e,t)}var Wi=n.object({setting:n.enum(["hidden","visible"]).describe("The setting of nonspatial visibility")}),Ms=p(Gi,{name:"changeNonspatialVisibility",description:"Change whether or not nonspatial data is visible in the link chart. The value must be either 'hidden' or 'visible'.",schema:Wi});var Cs=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,
|
|
187
204
|
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
|
|
188
205
|
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.
|
|
189
206
|
This agent is designed to handle requests that manipulate the specific link chart.
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
2
2
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
3
|
-
v5.0.0-next.
|
|
4
|
-
import"./
|
|
3
|
+
v5.0.0-next.141 */
|
|
4
|
+
import"./H3CVMHP7.js";var e=`## LinkChart Agent - Tool Intent Classifier
|
|
5
5
|
|
|
6
6
|
You are an assistant that classifies user intent for linkChart agent.
|
|
7
7
|
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/*! All material copyright Esri, All Rights Reserved, unless otherwise specified.
|
|
2
2
|
See https://js.arcgis.com/5.0/esri/copyright.txt for details.
|
|
3
|
-
v5.0.0-next.
|
|
3
|
+
v5.0.0-next.141 */
|
|
4
4
|
var a=(n,t)=>{let e=n;for(;e;){if(e===t)return!0;if(!e.parentNode)return!1;e.parentNode instanceof ShadowRoot?e=e.parentNode.host:e=e.parentNode}return!1},f=(n,t,e)=>{let s=l(t).subscribe;return s(o=>{o.some(r=>a(n,r.target))&&e()})},c={},l=n=>{let t=n.join(","),e=c[t];if(e!==void 0)return e;let s=new Set,o=new MutationObserver(r=>s.forEach(u=>u(r)));globalThis.document&&o.observe(document.documentElement,{attributes:!0,attributeFilter:n,subtree:!0});let i={subscribe:r=>(s.add(r),()=>{s.delete(r),s.size===0&&(o.disconnect(),c[t]=void 0)})};return c[t]=i,i},d=(n,t)=>{let e=n;for(;e;){let s=e.closest?.(t);if(s)return s;let o=e.getRootNode?.();if(o===globalThis.document)return;e=o.host}};var h=(n,t,e)=>d(n,`[${t}]`)?.getAttribute(t)??e;export{f as a,d as b,h as c};
|