@arcgis/ai-components 5.2.0-next.3 → 5.2.0-next.31

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (207) hide show
  1. package/dist/agent-utils/FunctionAgent.d.ts +2 -2
  2. package/dist/agent-utils/LLMAgent.d.ts +2 -2
  3. package/dist/agent-utils/LLMAgent.js +23 -22
  4. package/dist/agent-utils/WorkflowAgent.d.ts +2 -2
  5. package/dist/agent-utils/index.d.ts +177 -0
  6. package/dist/agent-utils/index.js +167 -0
  7. package/dist/agent-utils/middlewares/trace.d.ts +2 -0
  8. package/dist/agent-utils/middlewares/trace.js +25 -33
  9. package/dist/agent-utils/tools/FunctionTool.d.ts +2 -2
  10. package/dist/agent-utils/types.d.ts +36 -7
  11. package/dist/agent-utils/workflows/ConditionalWorkflow.d.ts +2 -2
  12. package/dist/agent-utils/workflows/LoopWorkflow.d.ts +2 -2
  13. package/dist/agent-utils/workflows/ParallelWorkflow.d.ts +2 -2
  14. package/dist/agent-utils/workflows/RouterWorkflow.d.ts +2 -2
  15. package/dist/agent-utils/workflows/SequentialWorkflow.d.ts +2 -2
  16. package/dist/agent-utils/workflows/SwitchWorkflow.d.ts +2 -2
  17. package/dist/cdn/27NEUQN3.js +2 -0
  18. package/dist/cdn/2NMR43NW.js +2 -0
  19. package/dist/cdn/3AXQTBIA.js +134 -0
  20. package/dist/cdn/434TAA3J.js +2 -0
  21. package/dist/cdn/4I4MCV7V.js +71 -0
  22. package/dist/cdn/4RZPOYZ7.js +9 -0
  23. package/dist/cdn/5SBLS4NW.js +2 -0
  24. package/dist/cdn/{AMP6IALT.js → 5W7S2RS4.js} +1 -1
  25. package/dist/cdn/6LZ6GOHF.js +56 -0
  26. package/dist/cdn/7IFCBXV7.js +2 -0
  27. package/dist/cdn/ADYIXCSG.js +2 -0
  28. package/dist/cdn/AFLQZIKS.js +180 -0
  29. package/dist/cdn/AMVOJNWN.js +2 -0
  30. package/dist/cdn/C7E7MJSR.js +2 -0
  31. package/dist/cdn/CAECQD75.js +2 -0
  32. package/dist/cdn/CIW3QMKV.js +2 -0
  33. package/dist/cdn/CJIV4KJZ.js +179 -0
  34. package/dist/cdn/CVHJMR5X.js +2 -0
  35. package/dist/cdn/DEAYZ3MK.js +2 -0
  36. package/dist/cdn/{H7422XUG.js → E2HENO3T.js} +1 -1
  37. package/dist/cdn/E7TMP4YV.js +3 -0
  38. package/dist/cdn/EBRNMPPO.js +48 -0
  39. package/dist/cdn/FWU6DFIB.js +2 -0
  40. package/dist/cdn/HBYZSLEZ.js +22 -0
  41. package/dist/cdn/HOCTVCHH.js +2 -0
  42. package/dist/cdn/{4HU7735A.js → HXOSLGWU.js} +6 -4
  43. package/dist/cdn/I64KIZG3.js +2 -0
  44. package/dist/cdn/IB4WTK74.js +2 -0
  45. package/dist/cdn/IC5P5NYY.js +2 -0
  46. package/dist/cdn/IGZWQJW7.js +3 -0
  47. package/dist/cdn/IKEF7ZHH.js +181 -0
  48. package/dist/cdn/IXAKT6L3.js +2 -0
  49. package/dist/cdn/JEIMRNYM.js +2 -0
  50. package/dist/cdn/JN744CAW.js +2 -0
  51. package/dist/cdn/KRE4U7V7.js +2 -0
  52. package/dist/cdn/{NE7E52YR.js → KTK4HNL2.js} +8 -2
  53. package/dist/cdn/L77BTGXY.js +2 -0
  54. package/dist/cdn/LEPJUN3X.js +22 -0
  55. package/dist/cdn/LODKJRS4.js +2 -0
  56. package/dist/cdn/M3SWPT3M.js +2 -0
  57. package/dist/cdn/MAV3DW27.js +4 -0
  58. package/dist/cdn/NOJYPREL.js +3 -0
  59. package/dist/cdn/NXKKG5TK.js +2 -0
  60. package/dist/cdn/O3F47IO5.js +2 -0
  61. package/dist/cdn/O7TGCM5P.js +6 -0
  62. package/dist/cdn/PBTINZTK.js +65 -0
  63. package/dist/cdn/PKHQW7QU.js +18 -0
  64. package/dist/cdn/PSWI3MFB.js +2 -0
  65. package/dist/cdn/Q73PK7Q7.js +2 -0
  66. package/dist/cdn/Q7TL5Q5N.js +2 -0
  67. package/dist/cdn/QSA4T3BU.js +2 -0
  68. package/dist/cdn/RMLXVQZ5.js +2 -0
  69. package/dist/cdn/RX45PCYB.js +9 -0
  70. package/dist/cdn/S27EJSLC.js +14 -0
  71. package/dist/cdn/SMADRJ67.js +2 -0
  72. package/dist/cdn/{ZLXN7NMF.js → T537PKP4.js} +9 -7
  73. package/dist/cdn/{X2ZDYHCG.js → TNMXWUXU.js} +9 -4
  74. package/dist/cdn/TSEQVE2H.js +36 -0
  75. package/dist/cdn/VKU4WAQV.js +2 -0
  76. package/dist/cdn/W2IHPJ54.js +34 -0
  77. package/dist/cdn/W2JAKE2M.js +2 -0
  78. package/dist/cdn/WAVKMZA6.js +2 -0
  79. package/dist/cdn/WDE3HN7K.js +2 -0
  80. package/dist/cdn/WH6QQK6N.js +2 -0
  81. package/dist/cdn/WNS5ZUF5.js +2 -0
  82. package/dist/cdn/{FL4W4VYN.js → X7GE26KU.js} +16 -0
  83. package/dist/cdn/XVQJBUMY.js +2 -0
  84. package/dist/cdn/YJ3QQXF6.js +2 -0
  85. package/dist/cdn/YRBANNQ5.js +2 -0
  86. package/dist/cdn/YYY7HKYX.js +2 -0
  87. package/dist/cdn/ZEYIBYSF.js +66 -0
  88. package/dist/cdn/ZMSJQB65.js +99 -0
  89. package/dist/cdn/ZOSUDIJH.js +2 -0
  90. package/dist/cdn/ZPLFFLPF.js +2 -0
  91. package/dist/cdn/agent-utils/index.js +2 -0
  92. package/dist/cdn/agent-utils/middlewares/humanInTheLoop.js +3 -0
  93. package/dist/cdn/agent-utils/middlewares/middleware.js +2 -0
  94. package/dist/cdn/agent-utils/middlewares/trace.js +2 -0
  95. package/dist/cdn/index.js +1 -1
  96. package/dist/cdn/main.css +1 -1
  97. package/dist/chunks/adapter.js +1794 -1597
  98. package/dist/chunks/arcgisKnowledgeGraph.js +126 -71
  99. package/dist/chunks/arcgis_knowledge_current_lc_context.js +19 -2
  100. package/dist/chunks/arcgis_knowledge_current_map_context.js +31 -2
  101. package/dist/chunks/arcgis_knowledge_cypher_query_prompt.js +102 -0
  102. package/dist/chunks/arcgis_knowledge_summarize_result_prompt.js +116 -27
  103. package/dist/chunks/converterUtils.js +39 -32
  104. package/dist/chunks/dataExplorationGraph.js +139 -113
  105. package/dist/chunks/data_explore_query_prompt.js +9 -4
  106. package/dist/chunks/generateLayerDescriptions.js +231 -191
  107. package/dist/chunks/helpGraph.js +17 -13
  108. package/dist/chunks/help_prompt.js +34 -17
  109. package/dist/chunks/index.js +11 -0
  110. package/dist/chunks/intent_prompt.js +16 -0
  111. package/dist/chunks/layerStylingGraph.js +24 -20
  112. package/dist/chunks/navigationGraph.js +33 -28
  113. package/dist/chunks/navigation_intent_prompt.js +8 -2
  114. package/dist/chunks/orchestrator.js +267 -226
  115. package/dist/chunks/slottableRequestUtils.js +3 -7
  116. package/dist/chunks/state.js +1 -1
  117. package/dist/chunks/summarize_query_response_prompt.js +9 -7
  118. package/dist/chunks/toolCallResponse.js +12 -9
  119. package/dist/chunks/utils2.js +8 -8
  120. package/dist/components/arcgis-assistant/customElement.d.ts +27 -0
  121. package/dist/components/arcgis-assistant/customElement.js +385 -152
  122. package/dist/components/arcgis-assistant/index.js +2 -3
  123. package/dist/components/arcgis-assistant/types.d.ts +14 -1
  124. package/dist/components/arcgis-assistant-agent/customElement.js +5 -1
  125. package/dist/components/arcgis-assistant-chat/customElement.d.ts +8 -2
  126. package/dist/components/arcgis-assistant-chat/customElement.js +23 -18
  127. package/dist/components/arcgis-assistant-chat-entry/customElement.d.ts +4 -1
  128. package/dist/components/arcgis-assistant-chat-entry/customElement.js +25 -18
  129. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +11 -5
  130. package/dist/components/arcgis-assistant-help-agent/customElement.js +8 -2
  131. package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +4 -1
  132. package/dist/components/arcgis-assistant-interrupt/customElement.js +12 -8
  133. package/dist/components/arcgis-assistant-interrupt-preview/customElement.js +20 -0
  134. package/dist/components/arcgis-assistant-interrupt-preview/index.js +2 -0
  135. package/dist/components/arcgis-assistant-knowledge-agent/customElement.d.ts +7 -7
  136. package/dist/components/arcgis-assistant-knowledge-agent/customElement.js +17 -11
  137. package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +10 -4
  138. package/dist/components/arcgis-assistant-message/customElement.d.ts +23 -0
  139. package/dist/components/arcgis-assistant-message/customElement.js +28 -26
  140. package/dist/components/arcgis-assistant-message/index.d.ts +1 -0
  141. package/dist/components/arcgis-assistant-message/index.js +2 -0
  142. package/dist/components/arcgis-assistant-message-block/customElement.d.ts +1 -1
  143. package/dist/components/arcgis-assistant-message-block/customElement.js +18 -11
  144. package/dist/components/arcgis-assistant-message-block/index.js +1 -0
  145. package/dist/components/arcgis-assistant-message-feedback/customElement.d.ts +4 -1
  146. package/dist/components/arcgis-assistant-message-footer/customElement.d.ts +4 -1
  147. package/dist/components/arcgis-assistant-message-loading/customElement.d.ts +8 -1
  148. package/dist/components/arcgis-assistant-message-loading/customElement.js +8 -8
  149. package/dist/components/arcgis-assistant-message-loading/index.js +1 -0
  150. package/dist/components/arcgis-assistant-message-log/customElement.d.ts +4 -1
  151. package/dist/components/arcgis-assistant-message-read-aloud/customElement.d.ts +4 -1
  152. package/dist/components/arcgis-assistant-message-text/customElement.d.ts +5 -1
  153. package/dist/components/arcgis-assistant-message-text/customElement.js +12 -12
  154. package/dist/components/arcgis-assistant-navigation-agent/customElement.js +11 -5
  155. package/dist/components/arcgis-assistant-speech-input/customElement.d.ts +6 -1
  156. package/dist/components/arcgis-assistant-suggested-prompts/customElement.d.ts +4 -1
  157. package/dist/components/arcgis-assistant-suggested-prompts/customElement.js +8 -8
  158. package/dist/components/arcgis-assistant-user-message/customElement.d.ts +4 -1
  159. package/dist/components/arcgis-assistant-user-message/customElement.js +10 -8
  160. package/dist/docs/api.json +1 -1
  161. package/dist/docs/docs.json +1 -1
  162. package/dist/docs/vscode.html-custom-data.json +1 -1
  163. package/dist/docs/web-types.json +1 -1
  164. package/dist/index.d.ts +4 -0
  165. package/dist/loader.js +7 -6
  166. package/dist/types/lumina.d.ts +11 -5
  167. package/dist/types/preact.d.ts +12 -5
  168. package/dist/types/react.d.ts +13 -5
  169. package/dist/types/stencil.d.ts +11 -5
  170. package/dist/utils/index.d.ts +85 -42
  171. package/dist/utils/index.js +54 -49
  172. package/package.json +8 -7
  173. package/dist/cdn/2AXF774U.js +0 -2
  174. package/dist/cdn/3PKJWIC3.js +0 -2
  175. package/dist/cdn/462JBSEV.js +0 -422
  176. package/dist/cdn/5QAHYX7Y.js +0 -5
  177. package/dist/cdn/7BCR6TUO.js +0 -2
  178. package/dist/cdn/7GH7VSB2.js +0 -2
  179. package/dist/cdn/7PLV4QH6.js +0 -2
  180. package/dist/cdn/AO7BQHKC.js +0 -2
  181. package/dist/cdn/AXDZBBNL.js +0 -45
  182. package/dist/cdn/DDLZOMUY.js +0 -2
  183. package/dist/cdn/DHOVCT6R.js +0 -2
  184. package/dist/cdn/F2AHA4GB.js +0 -54
  185. package/dist/cdn/FHVXO2WG.js +0 -166
  186. package/dist/cdn/FX5JFRDL.js +0 -2
  187. package/dist/cdn/GSEPHN3A.js +0 -106
  188. package/dist/cdn/HB5A5R2E.js +0 -2
  189. package/dist/cdn/JY6LLOUJ.js +0 -22
  190. package/dist/cdn/KMQ3SP4I.js +0 -5
  191. package/dist/cdn/MDVYQQUG.js +0 -14
  192. package/dist/cdn/MH5RPXHM.js +0 -2
  193. package/dist/cdn/NAUXSHIE.js +0 -72
  194. package/dist/cdn/NVI3I46B.js +0 -2
  195. package/dist/cdn/OAVEHGB6.js +0 -2
  196. package/dist/cdn/OH64RMOR.js +0 -4
  197. package/dist/cdn/ON2V5XI2.js +0 -3
  198. package/dist/cdn/P6OPJQMC.js +0 -3
  199. package/dist/cdn/QR54T33D.js +0 -2
  200. package/dist/cdn/RVOAPUBN.js +0 -2
  201. package/dist/cdn/S6W6HV4T.js +0 -36
  202. package/dist/cdn/SXDLXCIM.js +0 -2
  203. package/dist/cdn/USMDJUFS.js +0 -2
  204. package/dist/cdn/V2P4AIGG.js +0 -2
  205. package/dist/cdn/V5YEZSRY.js +0 -16
  206. package/dist/cdn/Y333DGV6.js +0 -2
  207. package/dist/cdn/YY2SBO3V.js +0 -2
@@ -0,0 +1,2 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import{_ as h,a as E,b as y,ta as k}from"./CJIV4KJZ.js";var j=new Set(["agentExecutionContext","outputMessage","summary","status"]);function x(){return{assignedTask:"",messages:[],priorSteps:[],sharedState:{},userRequest:""}}function O(r){let o=[...new Set([...r].filter(n=>j.has(n)))];if(o.length!==0)throw new Error(`custom state cannot define reserved runtime fields: ${o.join(", ")}.`)}function S(r){let o=Object.entries(r);return Object.fromEntries(o.map(([n,t])=>[n,h({reducer:(i,g)=>g,default:()=>t})]))}function $(r={}){O(Object.keys(r));let o=S(r);return h.Root({...o,agentExecutionContext:h({reducer:(n,t)=>({...n,...t}),default:x}),outputMessage:h({reducer:(n="",t)=>typeof t=="string"&&t.trim()?t:n,default:()=>""}),summary:h({reducer:(n="",t)=>typeof t=="string"?t:n,default:()=>""}),status:h({reducer:(n,t)=>t??n,default:()=>{}})})}function M(r){let o=new Set;for(let t of r)for(let i of Object.keys(t.shape??{}))o.add(i);let n=Object.fromEntries([...o].map(t=>[t,void 0]));return $(n)}function T(r,o,n,t={}){let{agent:i,entryNode:g,middlewares:c=[]}=t,a=new k(n);if(Object.keys(r).length===0)throw new Error("Graph requires at least one node.");if(o.length===0)throw new Error("Graph requires at least one edge.");if(c.length>0&&!i)throw new Error("Graph middleware requires agent metadata.");let s=new Set(Object.keys(r)),l=new Map,w=new Map;for(let e of s)l.set(e,0),w.set(e,0);for(let e of o)"to"in e?(s.has(e.from)&&w.set(e.from,(w.get(e.from)??0)+1),s.has(e.to)&&l.set(e.to,(l.get(e.to)??0)+1)):s.has(e.from)&&w.set(e.from,(w.get(e.from)??0)+1);for(let[e,f]of Object.entries(r)){let u=N(i,e,c,async(d,p)=>await Promise.resolve(f(d,p))),m=async(d,p)=>await u(d,p);a=a.addNode(e,m)}for(let e of o)if("to"in e){let f=e.from,u=e.to;if(!s.has(f))throw new Error(`Graph edge references unknown from-node: ${f}`);if(!s.has(u))throw new Error(`Graph edge references unknown to-node: ${u}`);a.addEdge(f,u)}else{let f=e.from;if(!s.has(f))throw new Error(`Graph conditional edge references unknown from-node: ${f}`);a.addConditionalEdges(f,async(u,m)=>{let d=await e.decide(u,m);if(!d)return y;if(!s.has(d))throw new Error(`Graph conditional edge returned unknown node: ${d}`);return d})}let G=q(s,l,g);a.addEdge(E,G);let b=[...s].filter(e=>(w.get(e)??0)===0);for(let e of b)a.addEdge(e,y);return a}function N(r,o,n,t){return!n.length||!r?t:async(i,g)=>await n.reduceRight((c,a)=>async s=>await a.handler(s,c),async c=>{let a=await t(c.state,c.config);return{...c.state,...a}})({agent:r,config:g,nodeName:o,state:i})}function q(r,o,n){if(n){if(!r.has(n))throw new Error(`Graph entry node references unknown node: ${n}`);return n}let t=[...r].filter(i=>(o.get(i)??0)===0);if(t.length!==1)throw new Error(`Graph could not infer a single entry node (found ${t.length}). Provide an explicit entryNode or ensure exactly one node has no incoming edges.`);return t[0]}export{$ as a,M as b,T as c};
@@ -0,0 +1,2 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import{a as l}from"./E2HENO3T.js";import"./QSA4T3BU.js";import"./NXKKG5TK.js";import{g as a,h as e,k as o,t as i,u as n,v as r,z as c}from"./MAV3DW27.js";import"./ADYIXCSG.js";import"./YIMNOUTF.js";export default $arcgis.t(([{watch:d}])=>{var g=a`.container{display:flex;align-items:center;width:100%;justify-content:space-between;gap:var(--calcite-spacing-xs)}.start,.end{display:flex;align-items:center;gap:var(--calcite-spacing-xs)}`,t=class extends r{constructor(){super(...arguments),this._messages=l({blocking:!0}),this._endRef=i(),this._showLog=!1,this.feedbackEnabled=!1,this.logEnabled=!1,this.copyEnabled=!1,this.readAloudEnabled=!1}static{this.properties={_showLog:16,feedbackEnabled:5,logEnabled:5,copyEnabled:5,readAloudEnabled:5,message:0}}static{this.styles=g}loaded(){this.manager.onLifecycle(()=>[d(()=>this._showLog,()=>this._scrollToEnd())])}_scrollToEnd(){requestAnimationFrame(()=>{this._endRef.value?.scrollIntoView({behavior:"smooth",block:"end"})})}_renderCopyButton(){return!this.message?.error&&this.copyEnabled?e`<calcite-action id=action-copy icon=copy-to-clipboard scale=s @click=${async()=>{try{let s=this.message?.content?.trim();s&&await navigator.clipboard.writeText(s)}catch(s){o("warn","assistant-message-footer","Failed to copy text to clipboard",{once:!0,detail:{error:s}})}}} text></calcite-action><calcite-tooltip reference-element=action-copy overlay-positioning=fixed placement=bottom><span>${this._messages.copyButtonLabel}</span></calcite-tooltip>`:null}_renderLogButton(){return this.message?.log?.length&&this.logEnabled?e`<calcite-action id=action-log icon=access-string-results scale=s @click=${()=>this._showLog=!this._showLog} .text=${this._messages.logButtonLabel} .active=${this._showLog}></calcite-action><calcite-tooltip reference-element=action-log overlay-positioning=fixed placement=bottom><span>${this._messages.logButtonLabel}</span></calcite-tooltip>`:null}_renderReadAloudButton(){return e`<arcgis-assistant-message-read-aloud .message=${this.message} .readAloudEnabled=${this.readAloudEnabled}></arcgis-assistant-message-read-aloud>`}_renderLog(){return e`<arcgis-assistant-message-log .log=${this.message?.log} .showLog=${this._showLog} .logEnabled=${this.logEnabled}></arcgis-assistant-message-log>`}_renderFeedback(){return e`<arcgis-assistant-message-feedback .message=${this.message} .feedbackEnabled=${this.feedbackEnabled}></arcgis-assistant-message-feedback>`}render(){return e`${this._renderLog()}<div class="container"><div class="start">${this._renderCopyButton()}${this._renderLogButton()}${this._renderReadAloudButton()}<slot name=footer-actions-start></slot></div><div class="end"><slot name=footer-actions-end></slot>${this._renderFeedback()}</div></div><div ${n(this._endRef)}></div>`}};c("arcgis-assistant-message-footer",t);return t},"core/reactiveUtils")
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import{b as r}from"./MH5RPXHM.js";import{z as o}from"./OH64RMOR.js";var s=r(o);export{s as a};
2
+ import{b as r}from"./QSA4T3BU.js";import{A as o}from"./MAV3DW27.js";var s=r(o);export{s as a};
@@ -0,0 +1,3 @@
1
+ /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
+ import a from"./EBRNMPPO.js";import{b as f}from"./ADYIXCSG.js";import{a as l}from"./4RZPOYZ7.js";import{U as R,a as v,b as x,ta as S,u as E}from"./CJIV4KJZ.js";import{Z as I,ja as b}from"./IKEF7ZHH.js";export default $arcgis.t(([O,P,q,N,T,{a:C,d:k,e:p,g:A,h:$,o:M}])=>{var U=async t=>{let e=await _(),r=await C("default"),s=P.getDefault(),n=(await O.getCredential(`${s.url}/sharing`)).token,a={type:"generateEmbeddings",webmapEmbeddings:t,auth:{apiUrl:r,token:n}};return e.postMessage(a),await new Promise((i,o)=>{let d=u=>{u.data==="completed"&&(e.removeEventListener("message",d),i())},c=u=>{e.removeEventListener("message",d),o(u instanceof Error?u:new Error("Embeddings worker error"))};e.addEventListener("message",d),e.addEventListener("error",c,{once:!0})}),e},_=async()=>{{let t=(await import("./23EQTPO3.js")).default;return new t}},G=t=>{t.currentIntent="none"},z=async(t,e)=>{let r=p(e);if(t.agentExecutionContext.userRequest){let n=new b(t.agentExecutionContext.userRequest.trim());t.agentExecutionContext.messages=[...t.agentExecutionContext.messages,n],G(t)}let s=r?.services.agentRegistry.list().map(n=>n.agent.id)??[];return await l({text:`Available agents: ${[...s].join(", ")}`},e),await l({text:"Analyzing user input"},e),t},Q=async(t,e)=>(await l({text:"Exiting..."},e),t),D=t=>typeof t=="object"&&t!==null&&!Array.isArray(t),B=(t,e)=>{if(!D(t)){t!==void 0&&console.warn(`Agent "${e}" returned invalid sharedStatePatch. Ignoring it.`);return}let r={};for(let[s,n]of Object.entries(t)){if(!D(n)||!("value"in n)){console.warn(`Agent "${e}" returned invalid sharedStatePatch entry for key "${s}". Ignoring that entry.`);continue}r[s]={value:n.value}}return r},J=t=>{let{previousSharedState:e,patch:r,agentId:s}=t;if(!r)return e;let n=Date.now(),a={...e};for(let[i,o]of Object.entries(r))o?.value!==void 0&&(a[i]={value:o.value,meta:{updatedByAgentId:s,updatedAt:n}});return a},W=t=>typeof t!="string"?void 0:t.trim()||void 0,K=t=>{switch(t){case"failed":return"Agent failed without a summary.";case"unknown":return"Agent returned with unknown status.";case"success":return"Agent completed without a summary.";default:return"Agent completed without a summary."}},V=(t,e)=>{let r=W(e?.outputMessage),s=W(e?.summary),n=e?.status,a=n==="success"||n==="failed"?n:"unknown";a==="unknown"&&console.warn(`Agent "${t}" returned missing/invalid status. Defaulting to "unknown".`);let i=B(e?.sharedStatePatch,t);return{outputMessage:r,summary:s??r??K(a),status:a,sharedStatePatch:i}},F=4e3,X=async(t,e)=>{let r=p(e);if(e?.signal?.aborted)return await l({text:"Run cancelled; skipping agent execution"},e),{...t,currentIntent:"none",requiresFollowUp:!1};let{agentRegistry:s}=r?.services??{},n=s?.get(t.currentIntent);if(!n)return console.warn(`No agent found for intent: ${t.currentIntent}`),t;await l({text:`Executing registered agent: ${n.agent.name}`},e);let a={...e??{},configurable:{...r??{},agentId:n.agent.id,context:n.getContext?await n.getContext():void 0}},i;try{let c=await n.agent.createGraph().compile().invoke({agentExecutionContext:{...t.agentExecutionContext,messages:[...t.agentExecutionContext.messages],priorSteps:structuredClone(t.agentExecutionContext.priorSteps??[]),sharedState:structuredClone(t.agentExecutionContext.sharedState??{})}},a);i=V(n.agent.name,c),await l({text:`Finished executing registered agent: ${n.agent.name}`},e)}catch(c){if(E(c)||e?.signal?.aborted||c instanceof Error&&c.name==="AbortError")throw c;let u=c instanceof Error?c.message:String(c);console.error(`Agent "${n.agent.name}" failed:`,c),await l({text:`Registered agent failed: ${n.agent.name}. ${u}`},e),i={status:"failed",outputMessage:`Agent execution failed: ${u}`,summary:`Agent execution failed: ${u}`}}let o=i.outputMessage,d=[...t.agentExecutionContext.messages];if(o){let c=o.length>F?`${o.slice(0,F-14)}
3
+ [truncated]`:o;d.push(new I(c))}return{...t,stepCount:t.stepCount+1,lastExecutedAgent:n.agent.id,requiresFollowUp:i.status==="failed"?!0:t.requiresFollowUp,finalOutputMessage:o??"",agentExecutionContext:{...t.agentExecutionContext,messages:d,priorSteps:[...t.agentExecutionContext.priorSteps??[],{agentId:n.agent.id,assignedTask:t.agentExecutionContext.assignedTask,summary:i?.summary||"No summary provided.",status:i?.status||"unknown"}],sharedState:J({previousSharedState:t.agentExecutionContext.sharedState,patch:i.sharedStatePatch,agentId:n.agent.id})}}},Y=3,Z=()=>new S(k).addNode("ingestInput",z).addNode("intentLLM",$).addNode("executeRegisteredAgent",X).addNode("exit",Q).addEdge(v,"ingestInput").addEdge("ingestInput","intentLLM").addConditionalEdges("intentLLM",t=>t.currentIntent==="none"||t.currentIntent===t.lastExecutedAgent?"exit":"executeRegisteredAgent").addConditionalEdges("executeRegisteredAgent",t=>t.stepCount>=Y||!t.requiresFollowUp?"exit":"intentLLM").addEdge("exit",x),w=class{constructor(){this.agentRegistry=new Map}register(e){let{agent:r}=e;if(this.agentRegistry.has(r.id))throw new Error(`Duplicate agent id: ${r.id}`);this.agentRegistry.set(r.id,e)}get(e){return this.agentRegistry.get(e)}list(){return[...this.agentRegistry.values()]}},y=class{constructor(e,r){this.graph=e,this.config={...r}}async waitForUser(){return await new Promise((e,r)=>{this.resolveWait=e,this.rejectWait=r})}handle(e,r){try{let s={agentId:e.agentId,id:e.id,payload:r},n=this.graph.streamEvents(null,{...this.config,configurable:{...this.config.configurable,hitlResponse:s},subgraphs:!0,version:"v2"});this.resolveWait?.(n)}catch(s){this.rejectWait?.(s)}finally{this.resolveWait=void 0,this.rejectWait=void 0}}cancel(){this.rejectWait&&(this.rejectWait(new Error("Request cancelled by user.")),this.resolveWait=void 0,this.rejectWait=void 0)}},ee=async t=>{try{return await(await A()).embedDocuments(t)}catch(e){throw console.error("Failed to generate embeddings:",e),e}},j=async(t,e)=>{let r=e.get(t);if(r)return r;let s=await ee([t]);return e.set(t,s[0]),s[0]};async function te(t,e,r,s){let n=`req-${Date.now()}`,a={type:"layerSearch",precomputedEmbedding:s?await j(t,s):void 0,requestId:n,minScore:r};return await new Promise(i=>{let o=d=>{d.data.requestId===n&&i(d.data.results)};e.addEventListener("message",o,{once:!0}),e.postMessage(a)})}function re(t){let{worker:e}=t;return{async searchLayers({text:r,minScore:s,embeddingCache:n}){return await te(r,e,s,n)}}}var ne=async({combinedQuery:t,layerIds:e,embeddingsWorker:r,minScore:s,topResults:n,embeddingCache:a})=>{let i=`req-${Date.now()}`,o=a?await j(t,a):void 0,d={type:"fieldSearch",layerIdForFieldsSearch:e,precomputedEmbedding:o,requestId:i,minScore:s,topResults:n};return await new Promise(c=>{let u=h=>{if(h.data.requestId!==i)return;let g=h.data.results.map(({layerId:m,results:H})=>({layerId:m,results:H}));c(g)};r.addEventListener("message",u,{once:!0}),r.postMessage(d)})};function se(t){let{worker:e}=t;return{async searchFields({text:r,layerIds:s,minScore:n,topResults:a,embeddingCache:i}){return await ne({combinedQuery:r,layerIds:s,embeddingsWorker:e,minScore:n,topResults:a,embeddingCache:i})}}}var ae=t=>{let e=M.safeParse(t);if(!e.success)throw new Error("Embeddings response validation failed. Regenerate embeddings.");return e.data},ie=(t,e)=>{let r=new Map,s=new Map;if(e.allLayers.forEach(n=>{n instanceof N&&s.set(n.id,n)}),t.length!==s.size)throw new Error("Layer count mismatch during registry restoration. Regenerate embeddings.");for(let n of t){let a=s.get(n.id);if(!a)throw new Error(`Layer with ID ${n.id} not found in the original map during registry restoration. Regenerate embeddings.`);if(n.fields.length!==a.fields.length)throw new Error(`Field count mismatch for layer ID ${n.id} during registry restoration. Regenerate embeddings.`);let i={name:n.name,title:n.title,description:n.description},o=new Map;for(let d of n.fields){let c=a.fieldsIndex.get(d.name);if(!c)throw new Error(`Field with name ${d.name} not found in the original layer ${n.id} during registry restoration. Regenerate embeddings.`);o.set(d.name,{name:d.name,alias:a.getFieldAlias(d.name)??d.alias,description:d.description,type:c.type||"unknown",valueType:c.valueType||"unknown",domain:a.getFieldDomain(d.name)??void 0})}r.set(n.id,{layerItem:i,fieldRegistry:o})}return r},oe=async t=>{try{return(await T(t,{responseType:"json"})).data}catch(e){throw new Error(`Failed to fetch data from ${t}: ${String(e)}`)}},de=async t=>{let e=t.map;if(!e?.portalItem)throw new Error("WebMap portal item is missing.");let{resources:r}=await e.portalItem.fetchResources(),s=r.find(a=>a.resource.path==="embeddings-v01.json");if(!s?.resource.url)throw new Error("Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.");let n=await oe(s.resource.url);return ae(n)},L=class t{constructor(){this.orchestratorReady=!1,this.chatHistory=[],this.priorSteps=[],this.sharedState={},this.agentRegistry=new w,this.activeRunId="",this.cancelledRunIds=new Set,this.streamEpoch=0}static async init(e){let r=new t;try{if(e.view?.map){await q.whenOnce(()=>e.view.ready);let s=await de(e.view),n=ie(s.layers,e.view.map);r.layersAndFieldsRegistry=n,r.embeddingsWorker=await U(s)}return e.agents?.forEach(s=>{r.agentRegistry.register(s)}),r.orchestratorReady=!0,r}catch(s){throw console.error("Orchestrator initialization failed:",s),s}}async*ask(e){if(!this.orchestratorReady)throw new Error("Orchestrator is not ready yet.");if(!this.agentRegistry.list().length)throw new Error("Orchestrator has no registered agents.");if(++this.streamEpoch,!e.trim())return;let r=f();this.activeRunId=r,this.activeAbortController=new AbortController,this.graph||(this.graph=Z().compile({checkpointer:new R}));let s=this.embeddingsWorker?re({worker:this.embeddingsWorker}):void 0,n=this.embeddingsWorker?se({worker:this.embeddingsWorker}):void 0,a=new Map,i={thread_id:r,hitlResponse:null,services:{layerSearch:s,fieldSearch:n,layersAndFieldsRegistry:this.layersAndFieldsRegistry,agentRegistry:this.agentRegistry,embeddingCache:a}},o={version:"v2",streamMode:"custom",signal:this.activeAbortController.signal,configurable:i,subgraphs:!0},d=this.graph?.streamEvents({agentExecutionContext:{userRequest:e,messages:this.chatHistory,priorSteps:this.priorSteps,sharedState:this.sharedState}},o),c=++this.streamEpoch;if(yield*this.pipeStream(d,c,r),this.isRunCancelled(r)){yield{runId:r,timestamp:Date.now(),type:"cancelled",reason:"user"};return}for(;;){if(this.isRunCancelled(r)){yield{runId:r,timestamp:Date.now(),type:"cancelled",reason:"user"};return}let h=(await this.graph.getState(o,{subgraphs:!0})).tasks.find(g=>g.interrupts.length>0)?.interrupts[0]?.value;if(!h)break;this.currentInterrupt=h,this.interruptHandler=new y(this.graph,o),yield{runId:r,timestamp:Date.now(),type:"interrupt",interrupt:h};try{let g=await this.interruptHandler.waitForUser(),m=++this.streamEpoch;yield*this.pipeStream(g,m,r)}catch(g){if(this.isRunCancelled(r)){yield{runId:r,timestamp:Date.now(),type:"cancelled",reason:"user"};return}if(g){yield{runId:r,timestamp:Date.now(),type:"error",error:{message:g?.message}};return}}}if(this.isRunCancelled(r)){yield{runId:r,timestamp:Date.now(),type:"cancelled",reason:"user"};return}let u=(await this.graph.getState(o,{subgraphs:!0})).values;if(this.isRunCancelled(r)){yield{runId:r,timestamp:Date.now(),type:"cancelled",reason:"user"};return}this.chatHistory=u.agentExecutionContext.messages.length?u.agentExecutionContext.messages:this.chatHistory,this.priorSteps=u.agentExecutionContext.priorSteps?.slice(-5)??[],this.sharedState=u.agentExecutionContext.sharedState??{},yield{runId:r,timestamp:Date.now(),type:"completed",result:{content:u.finalOutputMessage}}}newConversation(){this.chatHistory=[],this.priorSteps=[],this.sharedState={}}resumeInterrupt(e){if(!this.currentInterrupt||!this.interruptHandler)throw new Error("No pending interrupt to resume.");this.interruptHandler.handle(this.currentInterrupt,e)}cancelInterrupt(){this.interruptHandler&&this.interruptHandler.cancel()}cancel(){this.activeRunId&&(this.cancelledRunIds.add(this.activeRunId),this.activeAbortController?.abort(),++this.streamEpoch,this.interruptHandler?.cancel())}async*pipeStream(e,r,s){for await(let n of e){if(this.isRunCancelled(s)||r!==this.streamEpoch)break;n.event==="on_custom_event"&&n.name==="trace_message"?yield{runId:s,timestamp:Date.now(),type:"trace",data:n.data}:n.name==="graph_ux_suggestion"&&(yield{runId:s,timestamp:Date.now(),type:"ux-suggestion",suggestion:n.data})}}isRunCancelled(e){return this.cancelledRunIds.has(e)}dispose(){this.embeddingsWorker&&(this.embeddingsWorker.terminate(),this.embeddingsWorker=void 0),this.orchestratorReady=!1}};return{a:ee,b:L}},"identity/IdentityManager","portal/Portal","core/reactiveUtils","layers/FeatureLayer","request",a)