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

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.
@@ -16,10 +16,10 @@ import { convertToLangChainMiddlewares as l } from "./middlewares/middleware.js"
16
16
  import { c as y } from "../chunks/graph.js";
17
17
  import { c as T } from "../chunks/state.js";
18
18
  import { c as d, h as M, g as x } from "../chunks/utils.js";
19
- var P = Object.defineProperty, b = Object.getOwnPropertyDescriptor, n = (t, s, r, e) => {
20
- for (var o = e > 1 ? void 0 : e ? b(s, r) : s, p = t.length - 1, i; p >= 0; p--)
21
- (i = t[p]) && (o = (e ? i(s, r, o) : i(o)) || o);
22
- return e && o && P(s, r, o), o;
19
+ var P = Object.defineProperty, b = Object.getOwnPropertyDescriptor, n = (t, r, s, e) => {
20
+ for (var o = e > 1 ? void 0 : e ? b(r, s) : r, p = t.length - 1, i; p >= 0; p--)
21
+ (i = t[p]) && (o = (e ? i(r, s, o) : i(o)) || o);
22
+ return e && o && P(r, s, o), o;
23
23
  };
24
24
  let a = class extends v {
25
25
  //#region Lifecycle
@@ -53,52 +53,52 @@ let a = class extends v {
53
53
  generate() {
54
54
  const t = T(this.getSchemas());
55
55
  this._set("workspace", t);
56
- const s = this.id, r = { [s]: this._invoke.bind(this) }, e = [{ from: s, decide: () => {
56
+ const r = this.id, s = { [r]: this._invoke.bind(this) }, e = [{ from: r, decide: () => {
57
57
  } }];
58
58
  this._set(
59
59
  "createGraph",
60
- () => y(r, e, t, {
60
+ () => y(s, e, t, {
61
61
  agent: this,
62
- entryNode: s,
62
+ entryNode: r,
63
63
  middlewares: this.middlewares
64
64
  })
65
65
  );
66
66
  }
67
67
  //#endregion
68
68
  //#region Private Methods
69
- async _invoke(t, s) {
69
+ async _invoke(t, r) {
70
70
  try {
71
- return this.outputSchema ? await this._invokeStructured(t, s) : await this._invokeUnstructured(t, s);
72
- } catch (r) {
73
- if (f(r))
74
- throw r;
75
- const e = r instanceof Error ? r.message : String(r);
71
+ return this.outputSchema ? await this._invokeStructured(t, r) : await this._invokeUnstructured(t, r);
72
+ } catch (s) {
73
+ if (f(s))
74
+ throw s;
75
+ const e = s instanceof Error ? s.message : String(s);
76
76
  return d({ outputMessage: e }, "failed", e);
77
77
  }
78
78
  }
79
- async _invokeStructured(t, s) {
79
+ async _invokeStructured(t, r) {
80
80
  if (!this.outputSchema)
81
81
  throw new Error("Output schema is required for structured invocation.");
82
82
  const e = await h({
83
- model: await u(this.modelTier),
83
+ model: await u({ modelTier: this.modelTier }),
84
84
  systemPrompt: await this._getPromptWithInputVariables(t),
85
85
  tools: this._getTools(),
86
86
  checkpointer: !0,
87
87
  middleware: l(this.middlewares),
88
88
  responseFormat: this.outputSchema
89
- }).invoke({ messages: t.agentExecutionContext.messages }, s);
89
+ }).invoke({ messages: t.agentExecutionContext.messages }, r);
90
90
  if (!("structuredResponse" in e) || e.structuredResponse === void 0)
91
91
  throw new Error("LLMAgent did not receive structured output from createAgent.");
92
92
  return M(e.structuredResponse, this.outputSchema, e.messages);
93
93
  }
94
- async _invokeUnstructured(t, s) {
94
+ async _invokeUnstructured(t, r) {
95
95
  const o = (await h({
96
- model: await u(this.modelTier),
96
+ model: await u({ modelTier: this.modelTier }),
97
97
  systemPrompt: await this._getPromptWithInputVariables(t),
98
98
  tools: this._getTools(),
99
99
  checkpointer: !0,
100
100
  middleware: l(this.middlewares)
101
- }).invoke({ messages: t.agentExecutionContext.messages }, s)).messages, i = o.at(-1)?.content ?? "", c = typeof i == "string" ? i : JSON.stringify(i), g = c.trim() || "LLMAgent completed.";
101
+ }).invoke({ messages: t.agentExecutionContext.messages }, r)).messages, i = o.at(-1)?.content ?? "", c = typeof i == "string" ? i : JSON.stringify(i), g = c.trim() || "LLMAgent completed.";
102
102
  return d(
103
103
  { agentExecutionContext: { ...t.agentExecutionContext, messages: o }, outputMessage: c },
104
104
  "success",
@@ -106,10 +106,10 @@ let a = class extends v {
106
106
  );
107
107
  }
108
108
  async _getPromptWithInputVariables(t) {
109
- const s = x(t, this.inputSchema);
109
+ const r = x(t, this.inputSchema);
110
110
  for (const { outputKey: e } of this.middlewares)
111
- e && (s[String(e)] = t[e]);
112
- return await S.fromTemplate(this.prompt).format(s);
111
+ e && (r[String(e)] = t[e]);
112
+ return await S.fromTemplate(this.prompt).format(r);
113
113
  }
114
114
  _getTools() {
115
115
  return this.tools?.map((t) => t.getTool()) ?? [];
@@ -1,5 +1,5 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import b from"./FHVXO2WG.js";import a from"./GSEPHN3A.js";import{Fb as C,a as N,b as T}from"./462JBSEV.js";import{a as L,c as R}from"./HB5A5R2E.js";import"./AMP6IALT.js";import"./OAVEHGB6.js";import{v as E,y as $}from"./OH64RMOR.js";import"./YIMNOUTF.js";export default $arcgis.t(([,,,,,,,,,,,,,,,{a:f,f:d,l:b,m:F},{a:_,b:v,c:x,d:I,e:A,f:M,g:Z,h:q,i:j,j:V,k:O,l:z,m:S,n:G,o:h,p:B}])=>{var w=[I,A,M,Z,q,j,V,O,z];async function H(e,t){let a=await S("navigation_tool_prompt"),{mapView:r}=x(t),l=r.map.bookmarks?.map(p=>p.name).filter(Boolean)??[],i=e.vectorSearchLayerResults?.length>0?e.vectorSearchLayerResults.map((p,W)=>`${W+1}. layerId=${p.id} | title=${p.title??""} | name=${p.name??""} | score=${p.score.toFixed(2)}`).join(`
2
+ import b from"./GJUXVEOF.js";import a from"./DO2P3PWF.js";import{Fb as C,a as N,b as T}from"./462JBSEV.js";import{a as L,c as R}from"./HB5A5R2E.js";import"./AMP6IALT.js";import"./OAVEHGB6.js";import{v as E,y as $}from"./OH64RMOR.js";import"./YIMNOUTF.js";export default $arcgis.t(([,,,,,,,,,,,,,,,{a:f,f:d,m:b,n:F},{a:_,b:v,c:x,d:I,e:A,f:M,g:Z,h:q,i:j,j:V,k:O,l:z,m:S,n:G,o:h,p:B}])=>{var w=[I,A,M,Z,q,j,V,O,z];async function H(e,t){let a=await S("navigation_tool_prompt"),{mapView:r}=x(t),l=r.map.bookmarks?.map(p=>p.name).filter(Boolean)??[],i=e.vectorSearchLayerResults?.length>0?e.vectorSearchLayerResults.map((p,W)=>`${W+1}. layerId=${p.id} | title=${p.title??""} | name=${p.name??""} | score=${p.score.toFixed(2)}`).join(`
3
3
  `):"",c=e.vectorSearchFieldResults?.length>0?JSON.stringify(e.vectorSearchFieldResults,null,2):"",n=e.intent==="goToBookmark"&&l.length?`Available bookmarks:
4
4
  ${l.map(p=>`- ${p}`).join(`
5
5
  `)}`:"",o=(e.intent==="goToLayer"||e.intent==="goToFeatures")&&e.vectorSearchLayerResults?.length?`Candidate layers:
@@ -1,2 +1,2 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import a from"./GSEPHN3A.js";export default $arcgis.t(([,,,,,{f:t}])=>{var y=async(o,r)=>{let i=o.tool_calls??[];if(i.length===0){await t({text:`LLM did not request any tool calls: ${String(o?.content)}`},r);return}await Promise.all(i.map(async a=>await t({text:`LLM invoked ${a.name} tool with arguments: ${JSON.stringify(a.args,null,2)}`},r)))};return y},"identity/IdentityManager","portal/Portal","core/reactiveUtils","layers/FeatureLayer","request",a)
2
+ import a from"./DO2P3PWF.js";export default $arcgis.t(([,,,,,{f:t}])=>{var y=async(o,r)=>{let i=o.tool_calls??[];if(i.length===0){await t({text:`LLM did not request any tool calls: ${String(o?.content)}`},r);return}await Promise.all(i.map(async a=>await t({text:`LLM invoked ${a.name} tool with arguments: ${JSON.stringify(a.args,null,2)}`},r)))};return y},"identity/IdentityManager","portal/Portal","core/reactiveUtils","layers/FeatureLayer","request",a)
@@ -1,5 +1,5 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
- import c from"./FHVXO2WG.js";import a from"./GSEPHN3A.js";import{Fb as k,Q as x,a as y,b as l}from"./462JBSEV.js";import{c as b,d as A}from"./HB5A5R2E.js";import"./AMP6IALT.js";import"./OAVEHGB6.js";import{v as w,y as f}from"./OH64RMOR.js";import"./YIMNOUTF.js";export default $arcgis.t(([,,,,,,,,,,,,,{fetchKnowledgeGraph:J},{f:c,k:v,m:_},{K:u,L:K,M:S,N:M,O:G,P:T,Q:C,R:N,S:R,T:z,U:F,a:q,m:g,n:d,p:E}])=>{var L=[T,C,z,N,G,F,R];async function I(e,a){let i=await g("arcgis_knowledge_tool_prompt"),s=K(a),n={assignedTask:e.agentExecutionContext.assignedTask,userRequest:e.agentExecutionContext.userRequest,priorSteps:e.agentExecutionContext.priorSteps,contextType:s},r=await _({promptText:i,messages:e.arcgisKnowledgeMessages,inputVariables:n,tools:L}),t=(r.tool_calls?.length??0)>0,o=typeof r.text=="string"?r.text.trim():"",h=o.length>0,p=r.content.toString();return!t&&(s==="map"||s==="knowledgeGraph")?{...e,arcgisKnowledgeMessages:[...e.arcgisKnowledgeMessages,r],outputMessage:s==="map"?"No tools were found for the current view and prompt. Maps do not support changing nonspatial visibility, layout changes, or generation from queries.":"No tools were found for the current prompt and knowledge graph service. A knowledge graph service only supports search and query.",status:"success"}:{...e,arcgisKnowledgeMessages:[...e.arcgisKnowledgeMessages,r],outputMessage:t?p:o,status:t?e.status:h?"success":"failed",summary:p?d(p):"ArcGIS Knowledge Agent tool executed."}}async function U(e,a){let i=new q(L);try{let s=await i.invoke({messages:e.arcgisKnowledgeMessages},a),n=[];for(let t of s.messages){let o;if(typeof t.content!="string")throw new Error(`Unexpected tool message content type: ${typeof t.content}. Expected string.`);try{o=JSON.parse(t.content)}catch{throw new Error(`Failed to parse tool message content as JSON. Tool: ${t.name??"unknown"}`)}if(!o||typeof o!="object"||!("toolName"in o))throw new Error(`Parsed tool message content does not have expected structure. Parsed content: ${JSON.stringify(o)}`);n.push(o)}await c({text:`Finished executing ArcGIS Knowledge Agent tools: ${s.messages.filter(t=>t.name).map(t=>t.name).join(", ")}`},a);let r=n.filter(t=>typeof t!="string").map(t=>`- Called Tool: ${t.toolName}, Status: ${t.status}`);return{...e,outputMessage:r.join(`
2
+ import c from"./GJUXVEOF.js";import a from"./DO2P3PWF.js";import{Fb as k,Q as x,a as y,b as l}from"./462JBSEV.js";import{c as b,d as A}from"./HB5A5R2E.js";import"./AMP6IALT.js";import"./OAVEHGB6.js";import{v as w,y as f}from"./OH64RMOR.js";import"./YIMNOUTF.js";export default $arcgis.t(([,,,,,,,,,,,,,{fetchKnowledgeGraph:J},{f:c,l:v,n:_},{K:u,L:K,M:S,N:M,O:G,P:T,Q:C,R:N,S:R,T:z,U:F,a:q,m:g,n:d,p:E}])=>{var L=[T,C,z,N,G,F,R];async function I(e,a){let i=await g("arcgis_knowledge_tool_prompt"),s=K(a),n={assignedTask:e.agentExecutionContext.assignedTask,userRequest:e.agentExecutionContext.userRequest,priorSteps:e.agentExecutionContext.priorSteps,contextType:s},r=await _({promptText:i,messages:e.arcgisKnowledgeMessages,inputVariables:n,tools:L}),t=(r.tool_calls?.length??0)>0,o=typeof r.text=="string"?r.text.trim():"",h=o.length>0,p=r.content.toString();return!t&&(s==="map"||s==="knowledgeGraph")?{...e,arcgisKnowledgeMessages:[...e.arcgisKnowledgeMessages,r],outputMessage:s==="map"?"No tools were found for the current view and prompt. Maps do not support changing nonspatial visibility, layout changes, or generation from queries.":"No tools were found for the current prompt and knowledge graph service. A knowledge graph service only supports search and query.",status:"success"}:{...e,arcgisKnowledgeMessages:[...e.arcgisKnowledgeMessages,r],outputMessage:t?p:o,status:t?e.status:h?"success":"failed",summary:p?d(p):"ArcGIS Knowledge Agent tool executed."}}async function U(e,a){let i=new q(L);try{let s=await i.invoke({messages:e.arcgisKnowledgeMessages},a),n=[];for(let t of s.messages){let o;if(typeof t.content!="string")throw new Error(`Unexpected tool message content type: ${typeof t.content}. Expected string.`);try{o=JSON.parse(t.content)}catch{throw new Error(`Failed to parse tool message content as JSON. Tool: ${t.name??"unknown"}`)}if(!o||typeof o!="object"||!("toolName"in o))throw new Error(`Parsed tool message content does not have expected structure. Parsed content: ${JSON.stringify(o)}`);n.push(o)}await c({text:`Finished executing ArcGIS Knowledge Agent tools: ${s.messages.filter(t=>t.name).map(t=>t.name).join(", ")}`},a);let r=n.filter(t=>typeof t!="string").map(t=>`- Called Tool: ${t.toolName}, Status: ${t.status}`);return{...e,outputMessage:r.join(`
3
3
  `),summary:r.length?d(r.join(`
4
4
  `)):"ArcGIS Knowledge Agent did not execute any tools or return any results.",arcgisKnowledgeMessages:[...e.arcgisKnowledgeMessages,...s.messages],arcgisKnowledgeToolResult:n}}catch(s){let n=s instanceof Error?s.message:String(s);return await c({text:`ArcGIS Knowledge Agent tool execution failed: ${n}`},a),{...e,outputMessage:`ArcGIS Knowledge Agent tool execution failed: ${n}`,status:"failed",summary:`ArcGIS Knowledge Agent tool execution failed: ${n}`,arcgisKnowledgeMessages:[...e.arcgisKnowledgeMessages]}}}var D=(e,a)=>E([],"ArcgisKnowledge Agent")(e,a);async function j(e,a){let i=(e.arcgisKnowledgeToolResult??[]).map(h=>({...h,details:void 0})),{knowledgeGraph:s}=await S(a),n=M.getDataModelTypesSummary(s.dataModel),r={assignedTask:e.agentExecutionContext.assignedTask,userRequest:e.agentExecutionContext.userRequest,toolResult:i,dataModelSummary:n},t=await v({promptText:await g("arcgis_knowledge_summarize_result_prompt"),modelTier:"default",inputVariables:r}),o=typeof t=="string"?t:t.content;return{...e,outputMessage:o,status:"success",summary:d(o),arcgisKnowledgeMessages:[...e.arcgisKnowledgeMessages,new x(o)]}}var O=()=>new k(u).addNode("requireArcgisKnowledgeServices",D).addNode("agent",I).addNode("tools",U).addNode("summarizationLLM",j).addEdge(y,"requireArcgisKnowledgeServices").addEdge("requireArcgisKnowledgeServices","agent").addConditionalEdges("agent",e=>(e.arcgisKnowledgeMessages[e.arcgisKnowledgeMessages.length-1]?.tool_calls?.length??0)>0?"tools":l).addConditionalEdges("tools",e=>e.status==="failed"?l:"summarizationLLM").addEdge("summarizationLLM",l),V=String.raw`The purpose of this agent is to work with Knowledge Graph data, a graph database technology that represents and stores data as interconnected entities (nodes) and relationships (edges).
5
5
  This agent has two categories of skills: those that work with an active link chart visualization of a subset of the data in the knowledge graph, and those that work with the knowledge graph data more generally against the entire dataset in the service and database.