@arcgis/ai-components 5.1.0-next.4 → 5.1.0-next.41

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 (95) hide show
  1. package/dist/cdn/24MYCR6F.js +3 -0
  2. package/dist/cdn/2JJGDGMG.js +67 -0
  3. package/dist/cdn/433QN6BZ.js +2 -0
  4. package/dist/cdn/{R3LASMEM.js → 6Z5UQ3RY.js} +106 -107
  5. package/dist/cdn/75CJ2C4L.js +2 -0
  6. package/dist/cdn/7ITNTTBI.js +2 -0
  7. package/dist/cdn/{CN6VFVA2.js → BSIB6MUI.js} +1 -0
  8. package/dist/cdn/COBFCTOX.js +2 -0
  9. package/dist/cdn/CXBXMIVC.js +2 -0
  10. package/dist/cdn/{UY4FI7AP.js → FHXNY4QC.js} +1 -1
  11. package/dist/cdn/HN2XKXPX.js +2 -0
  12. package/dist/cdn/HRAAW2JX.js +2 -0
  13. package/dist/cdn/NCO7XIEC.js +3 -0
  14. package/dist/cdn/OG537NIF.js +2 -0
  15. package/dist/cdn/RNZITNTO.js +2 -0
  16. package/dist/cdn/{62K6RJZZ.js → SA7B3M2J.js} +1 -1
  17. package/dist/cdn/TBEVPWWN.js +2 -0
  18. package/dist/cdn/UIXYUELQ.js +2 -0
  19. package/dist/cdn/UY42NIH7.js +2 -0
  20. package/dist/cdn/VC3I52HI.js +2 -0
  21. package/dist/cdn/{ZYQ6U2YH.js → VDUOWASW.js} +14 -0
  22. package/dist/cdn/{NKNUZCLA.js → W2A22QZU.js} +15 -0
  23. package/dist/cdn/XI5SV3HJ.js +47 -0
  24. package/dist/cdn/XSVSCXUM.js +2 -0
  25. package/dist/cdn/XUUCW7HH.js +2 -0
  26. package/dist/cdn/{M7XUI5KY.js → Z6ZNHTPJ.js} +35 -3
  27. package/dist/cdn/ZF5LIGCC.js +275 -0
  28. package/dist/cdn/ZPGX72R2.js +4 -0
  29. package/dist/cdn/index.js +1 -1
  30. package/dist/cdn/main.css +1 -1
  31. package/dist/chunks/converterUtils.js +117 -0
  32. package/dist/chunks/utils.js +16 -14
  33. package/dist/chunks/utils2.js +8 -3
  34. package/dist/components/arcgis-assistant/customElement.d.ts +286 -23
  35. package/dist/components/arcgis-assistant/customElement.js +172 -142
  36. package/dist/components/arcgis-assistant/index.js +2 -1
  37. package/dist/components/arcgis-assistant/types.d.ts +97 -0
  38. package/dist/components/arcgis-assistant-agent/customElement.d.ts +22 -8
  39. package/dist/components/arcgis-assistant-agent/customElement.js +7 -7
  40. package/dist/components/arcgis-assistant-chat/customElement.d.ts +8 -6
  41. package/dist/components/arcgis-assistant-chat/customElement.js +14 -14
  42. package/dist/components/arcgis-assistant-chat-card/customElement.d.ts +12 -5
  43. package/dist/components/arcgis-assistant-chat-card/customElement.js +59 -25
  44. package/dist/components/arcgis-assistant-chat-card/index.js +2 -0
  45. package/dist/components/arcgis-assistant-chat-card-content/customElement.js +14 -12
  46. package/dist/components/arcgis-assistant-chat-card-content/index.js +1 -0
  47. package/dist/components/arcgis-assistant-chat-entry/customElement.d.ts +5 -2
  48. package/dist/components/arcgis-assistant-chat-entry/customElement.js +42 -20
  49. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.d.ts +73 -6
  50. package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +5 -5
  51. package/dist/components/arcgis-assistant-help-agent/customElement.d.ts +73 -0
  52. package/dist/components/arcgis-assistant-help-agent/customElement.js +26 -0
  53. package/dist/components/arcgis-assistant-help-agent/index.d.ts +1 -0
  54. package/dist/components/arcgis-assistant-help-agent/index.js +1 -0
  55. package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +1 -1
  56. package/dist/components/arcgis-assistant-interrupt/customElement.js +8 -8
  57. package/dist/components/arcgis-assistant-layer-filter-agent/customElement.js +3 -3
  58. package/dist/components/arcgis-assistant-layer-query-agent/customElement.js +10 -10
  59. package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +6 -6
  60. package/dist/components/arcgis-assistant-navigation-agent/customElement.d.ts +53 -6
  61. package/dist/components/arcgis-assistant-navigation-agent/customElement.js +5 -5
  62. package/dist/components/arcgis-assistant-shell/customElement.d.ts +3 -0
  63. package/dist/components/arcgis-assistant-shell/customElement.js +12 -11
  64. package/dist/docs/api.json +1 -1
  65. package/dist/docs/docs.json +1 -1
  66. package/dist/docs/vscode.html-custom-data.json +1 -1
  67. package/dist/docs/web-types.json +1 -1
  68. package/dist/index.d.ts +16 -0
  69. package/dist/loader.js +9 -8
  70. package/dist/types/lumina.d.ts +19 -5
  71. package/dist/types/preact.d.ts +20 -5
  72. package/dist/types/react.d.ts +21 -5
  73. package/dist/types/stencil.d.ts +19 -5
  74. package/dist/utils/index.d.ts +305 -0
  75. package/dist/utils/index.js +13 -0
  76. package/package.json +15 -8
  77. package/dist/cdn/26V7SXDR.js +0 -4
  78. package/dist/cdn/4Y73V2HU.js +0 -2
  79. package/dist/cdn/5DFZMIRZ.js +0 -2
  80. package/dist/cdn/6ULHJSIQ.js +0 -245
  81. package/dist/cdn/AQZDEJJZ.js +0 -2
  82. package/dist/cdn/GCFT45CD.js +0 -2
  83. package/dist/cdn/I22GHLAO.js +0 -2
  84. package/dist/cdn/IFWK7P7O.js +0 -2
  85. package/dist/cdn/KJZARHAM.js +0 -2
  86. package/dist/cdn/M672SFG6.js +0 -2
  87. package/dist/cdn/MLJ7GXKB.js +0 -2
  88. package/dist/cdn/PCBMGVNZ.js +0 -4
  89. package/dist/cdn/Q674OE2M.js +0 -2
  90. package/dist/cdn/QOIX2B5M.js +0 -2
  91. package/dist/cdn/SOWNHB7F.js +0 -30
  92. package/dist/cdn/SW3IAT6V.js +0 -2
  93. package/dist/cdn/VUHDKXFM.js +0 -2
  94. package/dist/cdn/XVUE27HC.js +0 -2
  95. package/dist/cdn/ZFFHP5DI.js +0 -2
@@ -1,25 +1,26 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
- import { c as y } from "../../chunks/runtime.js";
3
- import { css as v, html as p } from "lit";
4
- import f from "@arcgis/core/core/Collection.js";
5
- import { whenOnce as _, watch as w, when as b } from "@arcgis/core/core/reactiveUtils.js";
6
- import $ from "@arcgis/core/portal/Portal.js";
7
- import { LitElement as E } from "@arcgis/lumina";
8
- import { createRef as g, ref as m } from "lit/directives/ref.js";
9
- import { Orchestrator as C } from "@arcgis/ai-orchestrator";
2
+ import { c as _ } from "../../chunks/runtime.js";
3
+ import { css as b, html as p } from "lit";
4
+ import v from "@arcgis/core/core/Collection.js";
5
+ import { whenOnce as w, watch as E, when as C } from "@arcgis/core/core/reactiveUtils.js";
6
+ import k from "@arcgis/core/portal/Portal.js";
7
+ import { LitElement as $, createEvent as n } from "@arcgis/lumina";
8
+ import { createRef as m, ref as y } from "lit/directives/ref.js";
9
+ import { Orchestrator as S } from "@arcgis/ai-orchestrator";
10
10
  import L from "@arcgis/core/core/Accessor.js";
11
- import { property as c, subclass as O } from "@arcgis/core/core/accessorSupport/decorators.js";
12
- import { g as P } from "../../chunks/utils2.js";
13
- import { u as S } from "../../chunks/useT9n.js";
14
- const k = v`:host{height:100%}`;
15
- var H = Object.defineProperty, M = Object.getOwnPropertyDescriptor, a = (l, t, e, r) => {
16
- for (var s = r > 1 ? void 0 : r ? M(t, e) : t, n = l.length - 1, o; n >= 0; n--)
17
- (o = l[n]) && (s = (r ? o(t, e, s) : o(s)) || s);
18
- return r && s && H(t, e, s), s;
11
+ import { property as h, subclass as P } from "@arcgis/core/core/accessorSupport/decorators.js";
12
+ import { g as I } from "../../chunks/utils2.js";
13
+ import { u as M } from "../../chunks/useT9n.js";
14
+ import { rethrowError as O } from "@arcgis/toolkit/log";
15
+ const R = b`:host{display:block;width:var(--arcgis-internal-panel-width, 100%);height:var(--arcgis-internal-expand-max-height, 100%)}`;
16
+ var x = Object.defineProperty, A = Object.getOwnPropertyDescriptor, l = (c, e, t, i) => {
17
+ for (var s = i > 1 ? void 0 : i ? A(e, t) : e, r = c.length - 1, o; r >= 0; r--)
18
+ (o = c[r]) && (s = (i ? o(e, t, s) : o(s)) || s);
19
+ return i && s && x(e, t, s), s;
19
20
  };
20
- let i = class extends L {
21
- constructor(l) {
22
- super(l), this.view = null, this.loading = !1, this.processing = !1, this.processingStep = "";
21
+ let a = class extends L {
22
+ constructor(c) {
23
+ super(c), this.view = null, this.loading = !1, this.processing = !1, this.processingStep = "";
23
24
  }
24
25
  async load() {
25
26
  this._set("loading", !0);
@@ -33,69 +34,73 @@ let i = class extends L {
33
34
  this.orchestrator?.dispose(), super.destroy();
34
35
  }
35
36
  async _initialize() {
36
- this.removeHandles(), await Promise.all([this.portal.load(), this.view?.when()]), this.view && await _(() => !this.view.updating), this._set(
37
+ this.removeHandles(), await Promise.all([this.portal.load(), this.view?.when()]), this.view && await w(() => !this.view.updating), this._set(
37
38
  "orchestrator",
38
- await C.init({
39
+ await S.init({
39
40
  agents: [...this.agents],
40
- portal: this.portal,
41
41
  view: this.view ?? void 0
42
42
  })
43
43
  ), this.addHandles([
44
- w(
44
+ E(
45
45
  () => [this.view, this.agents],
46
46
  () => void this._initialize()
47
47
  )
48
48
  ]);
49
49
  }
50
- async *ask(l, t) {
50
+ clearChatHistory() {
51
+ this.orchestrator?.newConversation();
52
+ }
53
+ async *ask(c, e) {
51
54
  if (!this.orchestrator)
52
55
  throw new Error("Orchestrator not initialized yet.");
53
56
  this._set("processing", !0), this._set("processingStep", "");
54
- let e = "";
57
+ const t = [];
55
58
  try {
56
- const r = this.orchestrator.ask(l);
57
- for await (const s of r) {
58
- if (t?.aborted) {
59
- yield { type: "cancelled" };
59
+ const i = this.orchestrator.ask(c);
60
+ for await (const s of i) {
61
+ const r = s.runId;
62
+ if (e?.aborted) {
63
+ yield { type: "cancelled", runId: r };
60
64
  break;
61
65
  }
62
66
  switch (s.type) {
63
67
  case "trace": {
64
- this._set("processingStep", s.data.text), e += `${s.data.text}
65
-
66
- `;
68
+ this._set("processingStep", s.data.text), t.push(s.data.text);
67
69
  break;
68
70
  }
69
71
  case "completed": {
70
72
  if (!s.result.content.length) {
71
- yield { type: "completed", error: "Could not process the request.", log: e };
73
+ yield { type: "completed", error: "Could not process the request.", log: t, runId: r };
72
74
  return;
73
75
  }
74
- const n = s.result.content;
75
- this._set("processingStep", ""), yield { type: "completed", response: n, log: e };
76
+ const o = s.result.content;
77
+ this._set("processingStep", ""), yield { type: "completed", response: o, log: t, runId: r };
76
78
  return;
77
79
  }
78
80
  case "interrupt": {
79
- console.log("Orchestrator interrupt:", s);
80
- const { kind: n, message: o, metadata: u } = s.interrupt, h = Array.isArray(u) ? [...u] : [], d = (() => {
81
- switch (n) {
81
+ const { kind: o, message: g, metadata: d } = s.interrupt, u = Array.isArray(d) ? [...d] : [], f = (() => {
82
+ switch (o) {
82
83
  case "booleanChoice":
83
- return { type: "boolean-choice", message: o, options: h };
84
+ return { type: "boolean-choice", message: g, options: u };
84
85
  case "singleSelection":
85
- return { type: "single-select", message: o, options: h };
86
+ return { type: "single-select", message: g, options: u };
86
87
  case "multipleSelection":
87
- return { type: "multi-select", message: o, options: h };
88
+ return { type: "multi-select", message: g, options: u };
88
89
  case "textInput":
89
- return { type: "text-input", message: o };
90
+ return { type: "text-input", message: g };
90
91
  default:
91
- return { type: n, message: o, options: h };
92
+ return { type: o, message: g, options: u };
92
93
  }
93
94
  })();
94
- this._set("processingStep", "Waiting for user input..."), yield { type: "interrupt", payload: d };
95
+ this._set("processingStep", "Waiting for user input..."), yield { type: "interrupt", payload: f, runId: r };
95
96
  break;
96
97
  }
97
98
  case "cancelled": {
98
- yield { type: "cancelled" };
99
+ yield { type: "cancelled", runId: r };
100
+ return;
101
+ }
102
+ case "error": {
103
+ yield { type: "completed", error: s.error.message, log: t, runId: r };
99
104
  return;
100
105
  }
101
106
  default: {
@@ -104,145 +109,170 @@ let i = class extends L {
104
109
  }
105
110
  }
106
111
  }
107
- } catch (r) {
108
- console.warn("Error during message processing:", r), yield { type: "completed", error: "An error occurred during message processing.", log: e };
112
+ } catch (i) {
113
+ console.warn("Error during message processing:", i), yield { type: "completed", error: "An error occurred during message processing.", log: t, runId: "error" };
109
114
  return;
110
115
  } finally {
111
116
  this._set("processing", !1);
112
117
  }
113
118
  }
114
119
  };
115
- a([
116
- c({ readOnly: !0 })
117
- ], i.prototype, "orchestrator", 2);
118
- a([
119
- c()
120
- ], i.prototype, "agents", 2);
121
- a([
122
- c()
123
- ], i.prototype, "portal", 2);
124
- a([
125
- c()
126
- ], i.prototype, "view", 2);
127
- a([
128
- c({ readOnly: !0 })
129
- ], i.prototype, "loading", 2);
130
- a([
131
- c({ readOnly: !0 })
132
- ], i.prototype, "processing", 2);
133
- a([
134
- c({ readOnly: !0 })
135
- ], i.prototype, "processingStep", 2);
136
- i = a([
137
- O("OrchestratorController")
138
- ], i);
139
- class A extends E {
120
+ l([
121
+ h({ readOnly: !0 })
122
+ ], a.prototype, "orchestrator", 2);
123
+ l([
124
+ h()
125
+ ], a.prototype, "agents", 2);
126
+ l([
127
+ h()
128
+ ], a.prototype, "portal", 2);
129
+ l([
130
+ h()
131
+ ], a.prototype, "view", 2);
132
+ l([
133
+ h({ readOnly: !0 })
134
+ ], a.prototype, "loading", 2);
135
+ l([
136
+ h({ readOnly: !0 })
137
+ ], a.prototype, "processing", 2);
138
+ l([
139
+ h({ readOnly: !0 })
140
+ ], a.prototype, "processingStep", 2);
141
+ a = l([
142
+ P("OrchestratorController")
143
+ ], a);
144
+ const z = "Embeddings resource 'embeddings-v01.json' not found in the webmap portal item.", H = "Embeddings not found for this web map.", j = "https://developers.arcgis.com/javascript/latest/agentic-apps/ai-webmap-setup/#embeddings";
145
+ class D extends $ {
140
146
  constructor() {
141
- super(...arguments), this._messages = S({ blocking: !0 }), this.#e = g(), this.#s = g(), this.#t = null, this.#r = null, this.#n = /* @__PURE__ */ new Map(), this.#i = (t) => {
142
- t.stopPropagation(), this.orchestrator?.cancelInterrupt(), this._interrupt = null;
143
- }, this.#o = (t) => {
144
- t.stopPropagation();
145
- const e = t.detail;
146
- this.orchestrator?.resumeInterrupt(e), this._interrupt = null;
147
- }, this.#a = (t) => {
148
- t.stopPropagation(), this.suggestedPrompts = [];
149
- const e = t.detail;
150
- this.#h(e);
151
- }, this.#l = (t) => {
152
- if (t.stopPropagation(), this._interrupt) {
147
+ super(...arguments), this._messages = M({ blocking: !0 }), this.#e = m(), this.#t = m(), this.#s = null, this.#o = /* @__PURE__ */ new Map(), this.#r = k.getDefault(), this.#i = (e) => {
148
+ e.stopPropagation(), this.arcgisInterruptCancel.emit(), this.orchestrator?.cancelInterrupt(), this._interrupt = null;
149
+ }, this.#a = (e) => {
150
+ e.stopPropagation();
151
+ const t = e.detail;
152
+ this.arcgisInterruptSubmit.emit(t), this.orchestrator?.resumeInterrupt(t), this._interrupt = null;
153
+ }, this.#n = (e) => {
154
+ e.stopPropagation(), this.keepSuggestedPrompts || (this.suggestedPrompts = []);
155
+ const t = e.detail;
156
+ this.arcgisSubmit.emit(t), this.submitMessage(t);
157
+ }, this.#l = (e) => {
158
+ if (e.stopPropagation(), this.arcgisCancel.emit(), this._interrupt) {
153
159
  this.orchestrator?.cancelInterrupt(), this._interrupt = null;
154
160
  return;
155
161
  }
156
- this.#r?.abort();
157
- }, this._interrupt = null, this._chatHistory = new f([]), this._error = null, this.referenceElement = null, this.portal = new $(), this.suggestedPrompts = [];
162
+ this.#s?.abort();
163
+ }, this.#c = (e) => {
164
+ e.stopPropagation();
165
+ const t = e.detail;
166
+ this.arcgisFeedback.emit(t);
167
+ }, this._orchestratorController = null, this._interrupt = null, this._error = null, this.messages = new v([]), this.referenceElement = null, this.suggestedPrompts = [], this.feedbackEnabled = !1, this.keepSuggestedPrompts = !1, this.logEnabled = !1, this.copyEnabled = !1, this.arcgisCancel = n(), this.arcgisError = n(), this.arcgisFeedback = n(), this.arcgisInterrupt = n(), this.arcgisInterruptCancel = n(), this.arcgisInterruptSubmit = n(), this.arcgisReady = n(), this.arcgisSubmit = n();
158
168
  }
159
169
  static {
160
- this.properties = { _interrupt: 16, _chatHistory: 16, _error: 16, orchestrator: 32, entryMessage: 1, heading: 1, description: 1, referenceElement: 1, portal: 0, suggestedPrompts: 0 };
170
+ this.properties = { _orchestratorController: 16, _interrupt: 16, _error: 16, _user: 16, messages: 0, orchestrator: 32, entryMessage: 1, heading: 1, description: 1, referenceElement: 1, suggestedPrompts: 0, feedbackEnabled: 5, keepSuggestedPrompts: 5, logEnabled: 5, copyEnabled: 5 };
161
171
  }
162
172
  static {
163
- this.styles = k;
173
+ this.styles = R;
164
174
  }
165
175
  #e;
166
- #s;
167
176
  #t;
177
+ #s;
178
+ #o;
168
179
  #r;
169
- #n;
170
180
  #i;
171
- #o;
172
181
  #a;
182
+ #n;
173
183
  #l;
174
- get orchestrator() {
175
- return this.#t?.orchestrator;
184
+ #c;
185
+ async #h() {
186
+ try {
187
+ const e = I(this.el, this.referenceElement);
188
+ await e?.componentOnReady();
189
+ const t = [...this.#o.values()];
190
+ return t.length ? (this._orchestratorController = new a({
191
+ agents: t,
192
+ portal: this.#r,
193
+ view: e?.view
194
+ }), await this._orchestratorController.load(), !0) : (this._error = "No agents found.", !1);
195
+ } catch (e) {
196
+ return this._error = e?.message ?? "Error initializing orchestrator.", O(this)(e), !1;
197
+ }
176
198
  }
177
- register(t) {
178
- this.#n.set(t.agent.id, t);
199
+ get _user() {
200
+ return this.#r?.user?.fullName || this.#r?.user?.username;
179
201
  }
180
- load() {
181
- this.manager.onLifecycle(() => () => {
182
- this.#r?.abort(), this._interrupt = null, this._chatHistory.removeAll(), this._error = null;
183
- });
202
+ get orchestrator() {
203
+ return this._orchestratorController?.orchestrator;
184
204
  }
185
- loaded() {
186
- this.manager.onLifecycle(() => {
187
- this.#e.value?.addEventListener("arcgisSubmit", this.#a), this.#e.value?.addEventListener("arcgisCancel", this.#l);
188
- const t = b(() => !!this._interrupt && !!this.#s.value, () => {
189
- const e = this.#s.value;
190
- e.removeEventListener("arcgisSubmit", this.#o), e.removeEventListener("arcgisCancel", this.#i), e.addEventListener("arcgisSubmit", this.#o, { once: !0 }), e.addEventListener("arcgisCancel", this.#i, { once: !0 });
191
- });
192
- return queueMicrotask(() => void this.#c()), () => {
193
- t.remove(), this.#s.value?.removeEventListener("arcgisSubmit", this.#o), this.#s.value?.removeEventListener("arcgisCancel", this.#i), this.#e.value?.removeEventListener("arcgisSubmit", this.#a), this.#e.value?.removeEventListener("arcgisCancel", this.#l), this.#t?.destroy(), this.#t = null;
194
- };
195
- });
205
+ async clearChatHistory() {
206
+ this._reset(), this._orchestratorController?.clearChatHistory();
196
207
  }
197
- async #c() {
198
- try {
199
- const t = P(this.referenceElement);
200
- await t?.componentOnReady();
201
- const e = [...this.#n.values()];
202
- this.#t = new i({
203
- agents: e,
204
- portal: this.portal,
205
- view: t?.view
206
- }), await this.#t.load();
207
- } catch (t) {
208
- console.warn(t), this._error = "Error initializing orchestrator.";
209
- }
208
+ register(e) {
209
+ this.#o.set(e.agent.id, e);
210
210
  }
211
- async #h(t) {
212
- const e = t.trim();
213
- if (!e || (this._chatHistory.push({
214
- type: "prompt",
215
- content: e
216
- }), !this.#t))
211
+ async submitMessage(e) {
212
+ const t = e.trim();
213
+ if (!t || (this.messages.push({
214
+ id: Date.now().toString(),
215
+ // TODO: Replace with a more robust ID generation method or get from orchestrator
216
+ role: "user",
217
+ content: t
218
+ }), !this._orchestratorController))
217
219
  return;
218
- this.#r = new AbortController();
219
- const r = this.#t.ask(e, this.#r.signal);
220
- for await (const s of r)
220
+ const i = this._orchestratorController.ask(t, this.#s?.signal);
221
+ for await (const s of i) {
222
+ const r = s.runId;
221
223
  switch (s.type) {
222
224
  case "completed":
223
- this._chatHistory.push({
224
- type: "response",
225
+ this.messages.push({
226
+ role: "assistant",
225
227
  content: s.response,
226
228
  log: s.log,
227
- error: s.error
229
+ error: s.error,
230
+ id: r
228
231
  });
229
232
  break;
230
233
  case "interrupt":
231
- this._interrupt = s.payload;
234
+ this._interrupt = { ...s.payload, id: r };
232
235
  break;
233
236
  case "cancelled":
234
- this._chatHistory.push({
235
- type: "response",
236
- error: "Request cancelled."
237
+ this.messages.push({
238
+ role: "assistant",
239
+ error: "Request cancelled.",
240
+ id: r
237
241
  });
238
242
  break;
239
243
  }
244
+ }
245
+ }
246
+ load() {
247
+ this.manager.onLifecycle(this._reset.bind(this));
248
+ }
249
+ loaded() {
250
+ this.manager.onLifecycle(() => {
251
+ this.#e.value?.addEventListener("arcgisSubmit", this.#n), this.#e.value?.addEventListener("arcgisCancel", this.#l), this.#e.value?.addEventListener("arcgisFeedback", this.#c);
252
+ const e = C(() => !!this._interrupt && !!this.#t.value, () => {
253
+ const t = this.#t.value;
254
+ t.removeEventListener("arcgisSubmit", this.#a), t.removeEventListener("arcgisCancel", this.#i), t.addEventListener("arcgisSubmit", this.#a, { once: !0 }), t.addEventListener("arcgisCancel", this.#i, { once: !0 }), this._interrupt && this.arcgisInterrupt.emit(this._interrupt);
255
+ });
256
+ return queueMicrotask(() => {
257
+ this.#h().then((t) => {
258
+ t ? this.arcgisReady.emit() : this._error && this.arcgisError.emit(new Error(this._error));
259
+ });
260
+ }), () => {
261
+ e.remove(), this.#t.value?.removeEventListener("arcgisSubmit", this.#a), this.#t.value?.removeEventListener("arcgisCancel", this.#i), this.#e.value?.removeEventListener("arcgisSubmit", this.#n), this.#e.value?.removeEventListener("arcgisCancel", this.#l), this.#e.value?.removeEventListener("arcgisFeedback", this.#c), this._orchestratorController?.destroy(), this._orchestratorController = null;
262
+ };
263
+ });
264
+ }
265
+ _reset() {
266
+ this.#s?.abort(), this._interrupt = null, this.messages.removeAll(), this._error = null;
267
+ }
268
+ _renderErrorNotice() {
269
+ return this._error ? p`<calcite-notice closable slot=entry-message open kind=danger icon width=full>${this._error === z ? p`<div slot=message>${H}</div><calcite-link slot=link .href=${j} target=_blank title="Learn about web map embeddings">Read more</calcite-link>` : p`<div slot=message>${this._error}</div>`}</calcite-notice>` : null;
240
270
  }
241
271
  render() {
242
- return p`<arcgis-assistant-shell .loading=${this.#t?.loading} .heading=${this.heading ?? this._messages.assistantLabel} .description=${this.description} .entryMessage=${this.entryMessage} .entryMessageClosed=${this._chatHistory.length > 0} .awaitingResponse=${this.#t?.processing} .suggestedPrompts=${this.suggestedPrompts} .status=${this.#t?.processing ? "working" : this._error ? "error" : "ready"} ${m(this.#e)}>${this._error ? p`<calcite-notice slot=entry-message open kind=danger icon width=full><div slot=message>${this._error}</div></calcite-notice>` : null}${this._interrupt ? p`<arcgis-assistant-interrupt slot=entry-message .type=${this._interrupt.type} .message=${this._interrupt.message} .options=${this._interrupt.options} ${m(this.#s)}></arcgis-assistant-interrupt>` : null}<arcgis-assistant-chat .loading=${this.#t?.processing} .loadingMessage=${this.#t?.processingStep || ""} .messages=${this._chatHistory} .user=${this.portal?.user?.fullName || this.portal?.user?.username}><slot></slot></arcgis-assistant-chat><slot name=header-actions-end slot=header-actions-end></slot>${this.entryMessage ? null : p`<slot name=entry-message slot=entry-message></slot>`}<slot name=entry-actions-start slot=entry-actions-start></slot><slot name=footer-content slot=footer-content></slot></arcgis-assistant-shell>`;
272
+ return p`<arcgis-assistant-shell .loading=${!this._orchestratorController && !this._error || this._orchestratorController?.loading} .heading=${this.heading ?? this._messages.assistantLabel} .description=${this.description} .entryMessage=${this.entryMessage} .entryMessageClosed=${this.messages.length > 0} .awaitingResponse=${this._orchestratorController?.processing} .suggestedPrompts=${this.suggestedPrompts} .messages=${this.messages} ${y(this.#e)}>${this._renderErrorNotice()}${this._interrupt ? p`<arcgis-assistant-interrupt slot=entry-message .type=${this._interrupt.type} .message=${this._interrupt.message} .options=${this._interrupt.options} ${y(this.#t)}></arcgis-assistant-interrupt>` : null}<arcgis-assistant-chat .loading=${this._orchestratorController?.processing} .loadingMessage=${this._orchestratorController?.processingStep || ""} .messages=${this.messages} .user=${this._user} .feedbackEnabled=${this.feedbackEnabled} .logEnabled=${this.logEnabled} .copyEnabled=${this.copyEnabled}><slot></slot></arcgis-assistant-chat><slot name=header-actions-end slot=header-actions-end></slot>${this.entryMessage ? null : p`<slot name=entry-message slot=entry-message></slot>`}<slot name=entry-actions-start slot=entry-actions-start></slot><slot name=footer-content slot=footer-content></slot></arcgis-assistant-shell>`;
243
273
  }
244
274
  }
245
- y("arcgis-assistant", A);
275
+ _("arcgis-assistant", D);
246
276
  export {
247
- A as ArcgisAssistant
277
+ D as ArcgisAssistant
248
278
  };
@@ -1,5 +1,6 @@
1
- import "../arcgis-assistant-shell/index.js";
2
1
  import "@esri/calcite-components/components/calcite-notice";
2
+ import "@esri/calcite-components/components/calcite-link";
3
+ import "../arcgis-assistant-shell/index.js";
3
4
  import "../arcgis-assistant-interrupt/index.js";
4
5
  import "../arcgis-assistant-chat/index.js";
5
6
  export * from "./customElement.js";
@@ -0,0 +1,97 @@
1
+ /** An interrupt is a UI mechanism used by an agent to prompt the user for additional input or clarification. */
2
+ export interface Interrupt {
3
+ /**
4
+ * The unique identifier of the message associated with the interrupt. This is used to associate the interrupt
5
+ * with specific messages.
6
+ */
7
+ id?: string;
8
+ /**
9
+ * The type of interrupt, which determines how the assistant will prompt the user for input. The available types are:
10
+ *
11
+ * - `boolean-choice`: Presents the user with a yes/no question.
12
+ * - `multi-select`: Allows the user to select multiple options from a list using a checkbox interface.
13
+ * - `single-select`: Allows the user to select a single option from a list using a radio button interface.
14
+ * - `text-input`: Prompts the user to enter free-form text input.
15
+ *
16
+ * The assistant will use the specified type to determine how to display the prompt and collect the user's response.
17
+ * For example, a `boolean-choice` interrupt might be used to confirm an action, while a `text-input`
18
+ * interrupt could be used to ask for more details about a request.
19
+ */
20
+ type: "boolean-choice" | "multi-select" | "single-select" | "text-input";
21
+ /**
22
+ * The message to display to the user when prompting for input. This should provide clear instructions or questions
23
+ * related to the interrupt, guiding the user on what information is needed or what action they should take in response
24
+ * to the prompt.
25
+ *
26
+ * For example, if the interrupt type is `boolean-choice`, the message might be "Do you want to proceed with this
27
+ * action?" If the type is `text-input`, the message could be "Please provide more details about your request."
28
+ */
29
+ message?: string;
30
+ /**
31
+ * The options to present to the user for selection when the interrupt type is `multi-select` or `single-select`.
32
+ * This should be an array of strings representing the available choices. For `boolean-choice`,
33
+ * the options are implicitly "Yes" and "No" and do not need to be provided.
34
+ * For `text-input`, options are not applicable and should be omitted.
35
+ *
36
+ * For example, if the interrupt type is `multi-select`, the options might be ["Option 1", "Option 2", "Option 3"].
37
+ * If the type is `single-select`, the options could be ["Choice A", "Choice B", "Choice C"].
38
+ */
39
+ options?: string[];
40
+ }
41
+
42
+ /** A chat message sent by the assistant. */
43
+ export interface AssistantMessage extends ChatMessageBase {
44
+ role: "assistant";
45
+ /** The content of the assistant's message. This can include text generated by the assistant in response to the user's message. The content is displayed in the chat interface for the user to read and interact with. */
46
+ content?: string;
47
+ /**
48
+ * Log messages related to the assistant's processing of the user's request. This can include information about
49
+ * the agents or tools it invoked, the parameters generated by the LLM, and any relevant details about how it
50
+ * arrived at its response. Log messages are primarily intended for debugging and transparency purposes, allowing
51
+ * developers and users to understand the assistant's behavior and decision-making process.
52
+ */
53
+ log?: string[];
54
+ /**
55
+ * An error message indicating any issues that occurred while the assistant was processing the user's request.
56
+ * The error message may be displayed in the chat interface to inform the user of the issue and can also be used for
57
+ * debugging and improving the assistant's performance.
58
+ */
59
+ error?: string;
60
+ /**
61
+ * Feedback provided by the user for this specific assistant message. This allows users to indicate whether the
62
+ * assistant's response was helpful or not, which the app developer can capture and use to improve the assistant's
63
+ * performance over time.
64
+ */
65
+ feedback?: Feedback;
66
+ }
67
+
68
+ /**
69
+ * A chat message from the user or the assistant. Messages include all relevant information such as content,
70
+ * logs, errors, and feedback.
71
+ */
72
+ export type ChatMessage = AssistantMessage | UserMessage;
73
+
74
+ /** The base interface for chat messages exchanged between the user and the assistant. */
75
+ export interface ChatMessageBase {
76
+ /**
77
+ * The unique identifier for the message. This is used to associate messages with interrupts and feedback.
78
+ * If not provided, a unique ID will be generated automatically.
79
+ */
80
+ id: string;
81
+ }
82
+
83
+ /** A chat message sent by the user. */
84
+ export interface UserMessage extends ChatMessageBase {
85
+ role: "user";
86
+ /**
87
+ * The content of the user's message. This is the text input provided by the user in the chat interface.
88
+ * This content is sent to the assistant and its agents for processing and generating responses.
89
+ */
90
+ content: string;
91
+ }
92
+
93
+ /** Feedback provided by the user for a specific message. */
94
+ export interface Feedback {
95
+ /** Indicates whether the feedback is positive or negative. */
96
+ positive: boolean;
97
+ }
@@ -3,13 +3,19 @@ import type { AgentRegistration } from "@arcgis/ai-orchestrator";
3
3
  import type { PublicLitElement as LitElement } from "@arcgis/lumina";
4
4
 
5
5
  /**
6
- * The Assistant Agent component is a generic wrapper for adding custom AI agents into the ArcGIS Assistant component. To define
6
+ * The Assistant Agent component is a generic wrapper for registering custom agents to the [arcgis-assistant](https://developers.arcgis.com/javascript/latest/references/ai-components/components/arcgis-assistant/) component. To define
7
7
  * a custom agent, you must be familiar with [LangGraph](https://docs.langchain.com/oss/javascript/langgraph/overview). Custom agents must
8
8
  * include a StateGraph that defines the agent's graph and subgraphs.
9
9
  *
10
- * > Building custom agents can only be done using modern JavaScript/TypeScript tooling and cannot be done directly in HTML using
10
+ * Building custom agents can only be done using modern JavaScript/TypeScript tooling and cannot be done directly in HTML using
11
11
  * CDN imports. Therefore, you must use a package manager like npm or yarn to install the required dependencies. Please refer to the
12
- * Creating Custom Agents guide for more instructions.
12
+ * [Custom Agents guide](https://developers.arcgis.com/javascript/latest/agentic-apps/ai-custom-agents/) for more instructions on how to create a custom agent.
13
+ *
14
+ * Use the [utils](https://developers.arcgis.com/javascript/latest/references/ai-components/utils/index/) module for helper functions and types related to building custom agents, including the `AgentRegistration`
15
+ * type and functions for making LLM calls, managing agent state, and setting up human-in-the-loop workflows.
16
+ *
17
+ * > We recommend that developers building custom agents have experience working with LLMs and generative AI, and have a good
18
+ * understanding of the limitations of these technologies when building applications for end users.
13
19
  *
14
20
  * This is an unrendered component that must be added as a child of the `arcgis-assistant` component in either HTML or JavaScript.
15
21
  *
@@ -42,6 +48,12 @@ import type { PublicLitElement as LitElement } from "@arcgis/lumina";
42
48
  * @beta
43
49
  * @see [arcgis-assistant](https://developers.arcgis.com/javascript/latest/references/ai-components/components/arcgis-assistant/)
44
50
  * @see [LangGraph documentation](https://docs.langchain.com/oss/javascript/langgraph/overview)
51
+ * @see [Custom agents guide](https://developers.arcgis.com/javascript/latest/agentic-apps/ai-custom-agents/)
52
+ * @see [AI Assistant component sample](https://developers.arcgis.com/javascript/latest/sample-code/ai-assistant/)
53
+ * @see [AgentRegistration](https://developers.arcgis.com/javascript/latest/references/ai-components/utils/index/#AgentRegistration)
54
+ * @see [invokeStructuredPrompt](https://developers.arcgis.com/javascript/latest/references/ai-components/utils/index/#invokeStructuredPrompt)
55
+ * @see [invokeToolPrompt](https://developers.arcgis.com/javascript/latest/references/ai-components/utils/index/#invokeToolPrompt)
56
+ * @see [invokeTextPrompt](https://developers.arcgis.com/javascript/latest/references/ai-components/utils/index/#invokeTextPrompt)
45
57
  */
46
58
  export abstract class ArcgisAssistantAgent<TContext = Record<string, unknown>> extends LitElement {
47
59
  /**
@@ -49,13 +61,15 @@ export abstract class ArcgisAssistantAgent<TContext = Record<string, unknown>> e
49
61
  * This must include a StateGraph definition (defined using
50
62
  * [LangGraph](https://docs.langchain.com/oss/javascript/langgraph/overview)).
51
63
  *
52
- * This is an agent defined in the client and can be invoked by the assistant within the browser to perform specific tasks
64
+ * This is an agent defined in the client and can be invoked by the assistant from the browser to perform specific tasks
53
65
  * using functions defined in the client.
54
66
  *
55
- * See the Creating Custom Agents guide for more instructions.
67
+ * See the [Custom Agents guide](https://developers.arcgis.com/javascript/latest/agentic-apps/ai-custom-agents/) for more instructions
68
+ * and links to samples demonstrating how to create custom agents.
56
69
  *
57
70
  * @required
58
71
  * @see [LangGraph documentation](https://docs.langchain.com/oss/javascript/langgraph/overview)
72
+ * @see [Custom agents guide](https://developers.arcgis.com/javascript/latest/agentic-apps/ai-custom-agents/)
59
73
  * @example
60
74
  * ```js
61
75
  * // An example graph that updates a component property and replies with a confirmation message
@@ -111,17 +125,17 @@ export abstract class ArcgisAssistantAgent<TContext = Record<string, unknown>> e
111
125
  */
112
126
  accessor agent: AgentRegistration;
113
127
  /**
114
- * If the agent requires context, it can be provided via this property and accessed in the
128
+ * If the agent requires context provided by the application or user, it can be provided via this property and accessed in the
115
129
  * agent's graph nodes.
116
130
  *
117
131
  * @example
118
132
  * ```js
119
133
  * assistantAgent.context = {
120
134
  * myData: {
121
- * // custom context data for the agent
135
+ * // data required for the custom agent
122
136
  * },
123
137
  * };
124
138
  * ```
125
139
  */
126
- accessor context: TContext | undefined;
140
+ accessor context: TContext | (() => Promise<TContext | undefined> | TContext | undefined) | undefined;
127
141
  }
@@ -1,19 +1,19 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.1/LICENSE.txt */
2
2
  import { c as t } from "../../chunks/runtime.js";
3
3
  import { LitElement as s } from "@arcgis/lumina";
4
- import { i as e } from "../../chunks/utils.js";
5
- class i extends s {
4
+ import { i as e, a as i } from "../../chunks/utils.js";
5
+ class n extends s {
6
6
  static {
7
7
  this.properties = { agent: 0, context: 0 };
8
8
  }
9
- getContext() {
10
- return this.context;
9
+ async getContext() {
10
+ return e(this.context) ? await this.context() : this.context;
11
11
  }
12
12
  load() {
13
- e(this);
13
+ i(this);
14
14
  }
15
15
  }
16
- t("arcgis-assistant-agent", i);
16
+ t("arcgis-assistant-agent", n);
17
17
  export {
18
- i as ArcgisAssistantAgent
18
+ n as ArcgisAssistantAgent
19
19
  };