@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.
- package/dist/cdn/24MYCR6F.js +3 -0
- package/dist/cdn/2JJGDGMG.js +67 -0
- package/dist/cdn/433QN6BZ.js +2 -0
- package/dist/cdn/{R3LASMEM.js → 6Z5UQ3RY.js} +106 -107
- package/dist/cdn/75CJ2C4L.js +2 -0
- package/dist/cdn/7ITNTTBI.js +2 -0
- package/dist/cdn/{CN6VFVA2.js → BSIB6MUI.js} +1 -0
- package/dist/cdn/COBFCTOX.js +2 -0
- package/dist/cdn/CXBXMIVC.js +2 -0
- package/dist/cdn/{UY4FI7AP.js → FHXNY4QC.js} +1 -1
- package/dist/cdn/HN2XKXPX.js +2 -0
- package/dist/cdn/HRAAW2JX.js +2 -0
- package/dist/cdn/NCO7XIEC.js +3 -0
- package/dist/cdn/OG537NIF.js +2 -0
- package/dist/cdn/RNZITNTO.js +2 -0
- package/dist/cdn/{62K6RJZZ.js → SA7B3M2J.js} +1 -1
- package/dist/cdn/TBEVPWWN.js +2 -0
- package/dist/cdn/UIXYUELQ.js +2 -0
- package/dist/cdn/UY42NIH7.js +2 -0
- package/dist/cdn/VC3I52HI.js +2 -0
- package/dist/cdn/{ZYQ6U2YH.js → VDUOWASW.js} +14 -0
- package/dist/cdn/{NKNUZCLA.js → W2A22QZU.js} +15 -0
- package/dist/cdn/XI5SV3HJ.js +47 -0
- package/dist/cdn/XSVSCXUM.js +2 -0
- package/dist/cdn/XUUCW7HH.js +2 -0
- package/dist/cdn/{M7XUI5KY.js → Z6ZNHTPJ.js} +35 -3
- package/dist/cdn/ZF5LIGCC.js +275 -0
- package/dist/cdn/ZPGX72R2.js +4 -0
- package/dist/cdn/index.js +1 -1
- package/dist/cdn/main.css +1 -1
- package/dist/chunks/converterUtils.js +117 -0
- package/dist/chunks/utils.js +16 -14
- package/dist/chunks/utils2.js +8 -3
- package/dist/components/arcgis-assistant/customElement.d.ts +286 -23
- package/dist/components/arcgis-assistant/customElement.js +172 -142
- package/dist/components/arcgis-assistant/index.js +2 -1
- package/dist/components/arcgis-assistant/types.d.ts +97 -0
- package/dist/components/arcgis-assistant-agent/customElement.d.ts +22 -8
- package/dist/components/arcgis-assistant-agent/customElement.js +7 -7
- package/dist/components/arcgis-assistant-chat/customElement.d.ts +8 -6
- package/dist/components/arcgis-assistant-chat/customElement.js +14 -14
- package/dist/components/arcgis-assistant-chat-card/customElement.d.ts +12 -5
- package/dist/components/arcgis-assistant-chat-card/customElement.js +59 -25
- package/dist/components/arcgis-assistant-chat-card/index.js +2 -0
- package/dist/components/arcgis-assistant-chat-card-content/customElement.js +14 -12
- package/dist/components/arcgis-assistant-chat-card-content/index.js +1 -0
- package/dist/components/arcgis-assistant-chat-entry/customElement.d.ts +5 -2
- package/dist/components/arcgis-assistant-chat-entry/customElement.js +42 -20
- package/dist/components/arcgis-assistant-data-exploration-agent/customElement.d.ts +73 -6
- package/dist/components/arcgis-assistant-data-exploration-agent/customElement.js +5 -5
- package/dist/components/arcgis-assistant-help-agent/customElement.d.ts +73 -0
- package/dist/components/arcgis-assistant-help-agent/customElement.js +26 -0
- package/dist/components/arcgis-assistant-help-agent/index.d.ts +1 -0
- package/dist/components/arcgis-assistant-help-agent/index.js +1 -0
- package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +1 -1
- package/dist/components/arcgis-assistant-interrupt/customElement.js +8 -8
- package/dist/components/arcgis-assistant-layer-filter-agent/customElement.js +3 -3
- package/dist/components/arcgis-assistant-layer-query-agent/customElement.js +10 -10
- package/dist/components/arcgis-assistant-layer-styling-agent/customElement.js +6 -6
- package/dist/components/arcgis-assistant-navigation-agent/customElement.d.ts +53 -6
- package/dist/components/arcgis-assistant-navigation-agent/customElement.js +5 -5
- package/dist/components/arcgis-assistant-shell/customElement.d.ts +3 -0
- package/dist/components/arcgis-assistant-shell/customElement.js +12 -11
- package/dist/docs/api.json +1 -1
- package/dist/docs/docs.json +1 -1
- package/dist/docs/vscode.html-custom-data.json +1 -1
- package/dist/docs/web-types.json +1 -1
- package/dist/index.d.ts +16 -0
- package/dist/loader.js +9 -8
- package/dist/types/lumina.d.ts +19 -5
- package/dist/types/preact.d.ts +20 -5
- package/dist/types/react.d.ts +21 -5
- package/dist/types/stencil.d.ts +19 -5
- package/dist/utils/index.d.ts +305 -0
- package/dist/utils/index.js +13 -0
- package/package.json +15 -8
- package/dist/cdn/26V7SXDR.js +0 -4
- package/dist/cdn/4Y73V2HU.js +0 -2
- package/dist/cdn/5DFZMIRZ.js +0 -2
- package/dist/cdn/6ULHJSIQ.js +0 -245
- package/dist/cdn/AQZDEJJZ.js +0 -2
- package/dist/cdn/GCFT45CD.js +0 -2
- package/dist/cdn/I22GHLAO.js +0 -2
- package/dist/cdn/IFWK7P7O.js +0 -2
- package/dist/cdn/KJZARHAM.js +0 -2
- package/dist/cdn/M672SFG6.js +0 -2
- package/dist/cdn/MLJ7GXKB.js +0 -2
- package/dist/cdn/PCBMGVNZ.js +0 -4
- package/dist/cdn/Q674OE2M.js +0 -2
- package/dist/cdn/QOIX2B5M.js +0 -2
- package/dist/cdn/SOWNHB7F.js +0 -30
- package/dist/cdn/SW3IAT6V.js +0 -2
- package/dist/cdn/VUHDKXFM.js +0 -2
- package/dist/cdn/XVUE27HC.js +0 -2
- 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
|
|
3
|
-
import { css as
|
|
4
|
-
import
|
|
5
|
-
import { whenOnce as
|
|
6
|
-
import
|
|
7
|
-
import { LitElement as
|
|
8
|
-
import { createRef as
|
|
9
|
-
import { Orchestrator as
|
|
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
|
|
12
|
-
import { g as
|
|
13
|
-
import { u as
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
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
|
|
21
|
-
constructor(
|
|
22
|
-
super(
|
|
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
|
|
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
|
|
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
|
-
|
|
44
|
+
E(
|
|
45
45
|
() => [this.view, this.agents],
|
|
46
46
|
() => void this._initialize()
|
|
47
47
|
)
|
|
48
48
|
]);
|
|
49
49
|
}
|
|
50
|
-
|
|
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
|
-
|
|
57
|
+
const t = [];
|
|
55
58
|
try {
|
|
56
|
-
const
|
|
57
|
-
for await (const s of
|
|
58
|
-
|
|
59
|
-
|
|
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),
|
|
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:
|
|
73
|
+
yield { type: "completed", error: "Could not process the request.", log: t, runId: r };
|
|
72
74
|
return;
|
|
73
75
|
}
|
|
74
|
-
const
|
|
75
|
-
this._set("processingStep", ""), yield { type: "completed", response:
|
|
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
|
-
|
|
80
|
-
|
|
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:
|
|
84
|
+
return { type: "boolean-choice", message: g, options: u };
|
|
84
85
|
case "singleSelection":
|
|
85
|
-
return { type: "single-select", message:
|
|
86
|
+
return { type: "single-select", message: g, options: u };
|
|
86
87
|
case "multipleSelection":
|
|
87
|
-
return { type: "multi-select", message:
|
|
88
|
+
return { type: "multi-select", message: g, options: u };
|
|
88
89
|
case "textInput":
|
|
89
|
-
return { type: "text-input", message:
|
|
90
|
+
return { type: "text-input", message: g };
|
|
90
91
|
default:
|
|
91
|
-
return { type:
|
|
92
|
+
return { type: o, message: g, options: u };
|
|
92
93
|
}
|
|
93
94
|
})();
|
|
94
|
-
this._set("processingStep", "Waiting for user input..."), yield { type: "interrupt", payload:
|
|
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 (
|
|
108
|
-
console.warn("Error during message processing:",
|
|
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
|
-
|
|
116
|
-
|
|
117
|
-
],
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
],
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
],
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
],
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
],
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
],
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
],
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
],
|
|
139
|
-
|
|
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 =
|
|
142
|
-
|
|
143
|
-
}, this.#
|
|
144
|
-
|
|
145
|
-
const
|
|
146
|
-
this.orchestrator?.resumeInterrupt(
|
|
147
|
-
}, this.#
|
|
148
|
-
|
|
149
|
-
const
|
|
150
|
-
this
|
|
151
|
-
}, this.#l = (
|
|
152
|
-
if (
|
|
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.#
|
|
157
|
-
}, this
|
|
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 = {
|
|
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 =
|
|
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
|
-
|
|
175
|
-
|
|
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
|
-
|
|
178
|
-
this.#
|
|
199
|
+
get _user() {
|
|
200
|
+
return this.#r?.user?.fullName || this.#r?.user?.username;
|
|
179
201
|
}
|
|
180
|
-
|
|
181
|
-
this.
|
|
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
|
-
|
|
186
|
-
this.
|
|
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
|
-
|
|
198
|
-
|
|
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
|
|
212
|
-
const
|
|
213
|
-
if (!
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
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.
|
|
224
|
-
|
|
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.
|
|
235
|
-
|
|
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
|
|
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
|
-
|
|
275
|
+
_("arcgis-assistant", D);
|
|
246
276
|
export {
|
|
247
|
-
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
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
|
-
* //
|
|
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
|
|
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
|
-
|
|
13
|
+
i(this);
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
|
-
t("arcgis-assistant-agent",
|
|
16
|
+
t("arcgis-assistant-agent", n);
|
|
17
17
|
export {
|
|
18
|
-
|
|
18
|
+
n as ArcgisAssistantAgent
|
|
19
19
|
};
|