@arcgis/ai-components 5.2.0-next.4 → 5.2.0-next.6

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 (43) hide show
  1. package/dist/agent-utils/LLMAgent.js +22 -22
  2. package/dist/cdn/{YY2SBO3V.js → 3NI46YCE.js} +1 -1
  3. package/dist/cdn/{V5YEZSRY.js → 47FWPQ2A.js} +1 -1
  4. package/dist/cdn/{FHVXO2WG.js → AEJHYRGT.js} +4 -4
  5. package/dist/cdn/{JY6LLOUJ.js → BFZJNJL6.js} +1 -1
  6. package/dist/cdn/{MDVYQQUG.js → GCQLVNNC.js} +1 -1
  7. package/dist/cdn/{GSEPHN3A.js → JV4SI65E.js} +31 -29
  8. package/dist/cdn/R6HV42YW.js +3 -0
  9. package/dist/cdn/{S6W6HV4T.js → V7OJRG26.js} +1 -1
  10. package/dist/cdn/{4HU7735A.js → VOQX4AVB.js} +1 -1
  11. package/dist/cdn/index.js +1 -1
  12. package/dist/cdn/main.css +1 -1
  13. package/dist/chunks/adapter.js +6 -6
  14. package/dist/chunks/generateLayerDescriptions.js +236 -208
  15. package/dist/chunks/orchestrator.js +240 -201
  16. package/dist/components/arcgis-assistant-chat/customElement.d.ts +6 -1
  17. package/dist/components/arcgis-assistant-chat-entry/customElement.d.ts +2 -1
  18. package/dist/components/arcgis-assistant-interrupt/customElement.d.ts +4 -1
  19. package/dist/components/arcgis-assistant-message/customElement.d.ts +21 -0
  20. package/dist/components/arcgis-assistant-message/index.d.ts +1 -0
  21. package/dist/components/arcgis-assistant-message-block/customElement.d.ts +1 -1
  22. package/dist/components/arcgis-assistant-message-feedback/customElement.d.ts +4 -1
  23. package/dist/components/arcgis-assistant-message-footer/customElement.d.ts +4 -1
  24. package/dist/components/arcgis-assistant-message-loading/customElement.d.ts +4 -1
  25. package/dist/components/arcgis-assistant-message-log/customElement.d.ts +4 -1
  26. package/dist/components/arcgis-assistant-message-read-aloud/customElement.d.ts +4 -1
  27. package/dist/components/arcgis-assistant-message-text/customElement.d.ts +4 -1
  28. package/dist/components/arcgis-assistant-speech-input/customElement.d.ts +6 -1
  29. package/dist/components/arcgis-assistant-suggested-prompts/customElement.d.ts +4 -1
  30. package/dist/components/arcgis-assistant-user-message/customElement.d.ts +4 -1
  31. package/dist/docs/api.json +1 -1
  32. package/dist/docs/docs.json +1 -1
  33. package/dist/docs/vscode.html-custom-data.json +1 -1
  34. package/dist/docs/web-types.json +1 -1
  35. package/dist/index.d.ts +4 -0
  36. package/dist/types/lumina.d.ts +5 -0
  37. package/dist/types/preact.d.ts +6 -0
  38. package/dist/types/react.d.ts +7 -0
  39. package/dist/types/stencil.d.ts +5 -0
  40. package/dist/utils/index.d.ts +10 -14
  41. package/dist/utils/index.js +68 -78
  42. package/package.json +5 -5
  43. package/dist/cdn/ON2V5XI2.js +0 -3
@@ -1,43 +1,43 @@
1
1
  /* COPYRIGHT Esri - https://js.arcgis.com/5.2/LICENSE.txt */
2
2
  import { Annotation as d } from "@langchain/langgraph/web";
3
- import p, { z as r } from "zod";
4
- import { ChatPromptTemplate as C, SystemMessagePromptTemplate as K } from "@langchain/core/prompts";
5
- import { dispatchCustomEvent as F } from "@langchain/core/callbacks/dispatch/web";
6
- import { AIMessage as B, isAIMessage as W, isToolMessage as H } from "@langchain/core/messages";
7
- import { createAgent as J, summarizationMiddleware as X, modelCallLimitMiddleware as G } from "langchain";
8
- import { ChatOpenAI as Q, OpenAIEmbeddings as Y } from "@langchain/openai";
9
- import U from "@arcgis/core/identity/IdentityManager.js";
10
- import S from "@arcgis/core/portal/Portal.js";
11
- const _ = {
3
+ import p, { z as o } from "zod";
4
+ import { ChatPromptTemplate as F, SystemMessagePromptTemplate as W } from "@langchain/core/prompts";
5
+ import { dispatchCustomEvent as U } from "@langchain/core/callbacks/dispatch/web";
6
+ import { AIMessage as H, isAIMessage as J, isToolMessage as X } from "@langchain/core/messages";
7
+ import { createAgent as G, summarizationMiddleware as Q, modelCallLimitMiddleware as Y } from "langchain";
8
+ import { ChatOpenAI as Z, OpenAIEmbeddings as ee } from "@langchain/openai";
9
+ import _ from "@arcgis/core/identity/IdentityManager.js";
10
+ import k from "@arcgis/core/portal/Portal.js";
11
+ const P = {
12
12
  advanced: "gpt-5.2",
13
13
  default: "gpt-5-mini",
14
14
  fast: "gpt-5.4-nano"
15
- }, k = {
15
+ }, A = {
16
16
  default: "text-embedding-ada-002"
17
17
  }, M = /* @__PURE__ */ new Map();
18
- let T = null;
19
- const Z = () => {
20
- const t = S.getDefault().helperServices;
18
+ let v = null;
19
+ const te = () => {
20
+ const t = k.getDefault().helperServices;
21
21
  if (!t?.aiModels?.url)
22
22
  throw new Error("AI Models Service URL is not defined in the portal's helper services.");
23
23
  return t.aiModels.url;
24
- }, P = async (e) => {
25
- const t = Z();
26
- M.size === 0 && (T || (T = (async () => {
24
+ }, q = async (e) => {
25
+ const t = te();
26
+ M.size === 0 && (v || (v = (async () => {
27
27
  try {
28
28
  const n = await fetch(`${t}/models`);
29
29
  if (!n.ok)
30
30
  throw new Error("Failed to fetch AI service discovery data.");
31
- (await n.json()).models.forEach((o) => M.set(o.name, o));
31
+ (await n.json()).models.forEach((i) => M.set(i.name, i));
32
32
  } catch (n) {
33
- throw T = null, n;
33
+ throw v = null, n;
34
34
  }
35
- })()), await T);
35
+ })()), await v);
36
36
  const s = M.get(e);
37
37
  if (!s)
38
38
  throw new Error(`Model '${e}' is not available in the discovery service.`);
39
39
  return s.endpoint;
40
- }, ee = async (e = "default") => await P(_[e]), te = async (e = "default") => await P(k[e]), u = (e, t) => t, q = (e, t) => ({
40
+ }, ne = async (e = "default") => await q(P[e]), se = async (e = "default") => await q(A[e]), h = (e, t) => t, j = (e, t) => ({
41
41
  ...e,
42
42
  ...t
43
43
  }), $ = (e = "", t) => {
@@ -49,55 +49,55 @@ const Z = () => {
49
49
  return s;
50
50
  if (n === s)
51
51
  return e;
52
- const i = n.split(`
52
+ const a = n.split(`
53
53
 
54
54
  `);
55
- return i[i.length - 1]?.trim() === s ? e : `${e}
55
+ return a[a.length - 1]?.trim() === s ? e : `${e}
56
56
 
57
57
  ${s}`;
58
- }, j = () => ({
58
+ }, N = () => ({
59
59
  userRequest: "",
60
60
  assignedTask: "",
61
61
  messages: [],
62
62
  priorSteps: [],
63
63
  sharedState: {}
64
- }), ne = () => ({
64
+ }), ae = () => ({
65
65
  agentExecutionContext: d({
66
- reducer: q,
67
- default: j
66
+ reducer: j,
67
+ default: N
68
68
  }),
69
69
  outputMessage: d({
70
70
  reducer: $,
71
71
  default: () => ""
72
72
  }),
73
73
  summary: d({
74
- reducer: u,
74
+ reducer: h,
75
75
  default: () => ""
76
76
  }),
77
77
  status: d({
78
- reducer: u
78
+ reducer: h
79
79
  })
80
- }), Ee = () => ({
81
- ...ne(),
80
+ }), De = () => ({
81
+ ...ae(),
82
82
  sharedStatePatch: d({
83
- reducer: u
83
+ reducer: h
84
84
  })
85
- }), Ie = d.Root({
85
+ }), Fe = d.Root({
86
86
  agentExecutionContext: d({
87
- default: j,
88
- reducer: q
87
+ default: N,
88
+ reducer: j
89
89
  }),
90
90
  currentIntent: d({
91
91
  default: () => "none",
92
- reducer: u
92
+ reducer: h
93
93
  }),
94
94
  lastExecutedAgent: d({
95
95
  default: () => "",
96
- reducer: u
96
+ reducer: h
97
97
  }),
98
98
  requiresFollowUp: d({
99
99
  default: () => !0,
100
- reducer: u
100
+ reducer: h
101
101
  }),
102
102
  stepCount: d({
103
103
  default: () => 0,
@@ -107,16 +107,24 @@ ${s}`;
107
107
  default: () => "",
108
108
  reducer: $
109
109
  })
110
- }), y = async (e, t) => {
111
- await F("trace_message", e, t);
112
- }, De = async (e, t) => {
113
- await F("graph_ux_suggestion", e, t);
114
- }, se = (e, t, s) => {
110
+ }), f = async (e, t) => {
111
+ await U("trace_message", e, t);
112
+ }, Ue = async (e, t) => {
113
+ await U("graph_ux_suggestion", e, t);
114
+ }, ie = (e) => {
115
+ if (!e || typeof e != "object" || !("services" in e))
116
+ return !1;
117
+ const t = e.services;
118
+ return !!t && typeof t == "object" && "agentRegistry" in t;
119
+ }, oe = (e) => {
120
+ const t = e?.configurable;
121
+ return ie(t) ? t : void 0;
122
+ }, re = (e, t, s) => {
115
123
  const n = e[t];
116
- return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((i, o) => {
117
- (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(o.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + t + (t.split("/").length !== s ? ". Note that variables only represent file names one level deep." : ""))));
124
+ return n ? typeof n == "function" ? n() : Promise.resolve(n) : new Promise((a, i) => {
125
+ (typeof queueMicrotask == "function" ? queueMicrotask : setTimeout)(i.bind(null, /* @__PURE__ */ new Error("Unknown variable dynamic import: " + t + (t.split("/").length !== s ? ". Note that variables only represent file names one level deep." : ""))));
118
126
  });
119
- }, A = async (e) => (await se(/* @__PURE__ */ Object.assign({ "./field_descriptions_prompt.md": () => import("./field_descriptions_prompt.js"), "./intent_prompt.md": () => import("./intent_prompt.js"), "./layer_descriptions_prompt.md": () => import("./layer_descriptions_prompt.js") }), `./${e}.md`, 2)).default, ie = async (e) => {
127
+ }, I = async (e) => (await re(/* @__PURE__ */ Object.assign({ "./field_descriptions_prompt.md": () => import("./field_descriptions_prompt.js"), "./intent_prompt.md": () => import("./intent_prompt.js"), "./layer_descriptions_prompt.md": () => import("./layer_descriptions_prompt.js") }), `./${e}.md`, 2)).default, ce = async (e) => {
120
128
  const { agent: t, messages: s, config: n } = e;
121
129
  return { structuredResponse: (await t.invoke(
122
130
  {
@@ -124,107 +132,125 @@ ${s}`;
124
132
  },
125
133
  n
126
134
  )).structuredResponse };
127
- }, N = (e) => async (t, s) => {
128
- const n = new Headers(s?.headers);
129
- return n.delete("Authorization"), n.delete("api-key"), e && e.length > 0 && (n.set("X-Esri-Authorization", `Bearer ${e}`), n.set("X-Esri-Request-Source", "MapsSDK")), await fetch(t, {
130
- ...s,
131
- headers: n
135
+ }, O = (e, t) => async (s, n) => {
136
+ const a = new Headers(n?.headers);
137
+ a.delete("Authorization"), a.delete("api-key"), e && e.length > 0 && (a.set("X-Esri-Authorization", `Bearer ${e}`), a.set("X-Esri-Request-Source", "MapsSDK"));
138
+ const i = t && n?.signal ? AbortSignal.any([t, n.signal]) : n?.signal ?? t;
139
+ return await fetch(s, {
140
+ ...n,
141
+ headers: a,
142
+ signal: i
132
143
  });
133
- }, x = async (e = "default", t = 0) => {
134
- const s = S.getDefault(), n = await U.getCredential(`${s.url}/sharing`), i = _[e], o = await ee(e);
135
- return new Q({
136
- modelName: i,
144
+ }, b = async (e = {}) => {
145
+ const { modelTier: t = "default", temperature: s = 0, abortSignal: n } = e, a = k.getDefault(), i = await _.getCredential(`${a.url}/sharing`), r = P[t], c = await ne(t);
146
+ return new Z({
147
+ modelName: r,
137
148
  apiKey: "dummy-key",
138
149
  // 5-mini does not support temperature parameter
139
- ...e !== "default" && { temperature: t },
150
+ ...t !== "default" && { temperature: s },
140
151
  configuration: {
141
- baseURL: o,
142
- fetch: N(n.token)
152
+ baseURL: c,
153
+ fetch: O(i.token, n)
143
154
  }
144
155
  });
145
- }, Re = async (e = "default") => {
146
- const t = S.getDefault(), s = await U.getCredential(`${t.url}/sharing`), n = k[e], i = await te(e);
147
- return new Y({
148
- modelName: n,
156
+ }, _e = async (e = "default", t) => {
157
+ const s = k.getDefault(), n = await _.getCredential(`${s.url}/sharing`), a = A[e], i = await se(e);
158
+ return new ee({
159
+ modelName: a,
149
160
  apiKey: "dummy-key",
150
161
  configuration: {
151
162
  baseURL: i,
152
- fetch: N(s.token)
163
+ fetch: O(n.token, t)
153
164
  },
154
165
  batchSize: 2048,
155
166
  maxConcurrency: 10
156
167
  });
157
- }, re = r.object({
158
- id: r.string().min(1),
159
- name: r.string().min(1),
160
- description: r.string().min(1)
168
+ }, le = o.object({
169
+ id: o.string().min(1),
170
+ name: o.string().min(1),
171
+ description: o.string().min(1)
161
172
  });
162
- r.array(re);
163
- const D = (e) => JSON.stringify(e, null, 2), oe = (e) => {
164
- const t = e.map((n) => n.id), s = r.enum(t);
165
- return r.object({
173
+ o.array(le);
174
+ const R = (e) => JSON.stringify(e, null, 2), de = (e) => {
175
+ const t = e.map((n) => n.id), s = o.enum(t);
176
+ return o.object({
166
177
  intent: s.nullable(),
167
- assignedTask: r.string().nullable(),
168
- requiresFollowUp: r.boolean()
178
+ assignedTask: o.string().nullable(),
179
+ requiresFollowUp: o.boolean()
169
180
  });
170
- }, Ce = async (e, t) => {
181
+ }, Pe = async (e, t) => {
182
+ const s = oe(t);
183
+ if (s.abortSignal?.aborted)
184
+ return await f({ text: "Run cancelled; skipping intent routing" }, t), {
185
+ ...e,
186
+ currentIntent: "none",
187
+ finalOutputMessage: "Operation cancelled.",
188
+ requiresFollowUp: !1
189
+ };
171
190
  try {
172
- await y({ text: "Asking LLM to route to an agent" }, t);
173
- const i = (t?.configurable?.services.agentRegistry?.list() ?? []).map(({ agent: h }) => ({
174
- id: h.id,
175
- name: h.name,
176
- description: h.description
191
+ await f({ text: "Asking LLM to route to an agent" }, t);
192
+ const a = s.services.agentRegistry?.list() ?? [], i = a.map(({ agent: g }) => ({
193
+ id: g.id,
194
+ name: g.name,
195
+ description: g.description
177
196
  }));
178
197
  if (!i.length)
179
- return await y({ text: "No agents registered; skipping intent detection" }, t), { ...e, currentIntent: "none" };
180
- const o = await A("intent_prompt"), a = D(i), c = oe(i), l = {
181
- registeredAgents: a,
182
- priorSteps: D(e.agentExecutionContext.priorSteps),
198
+ return await f({ text: "No agents registered; skipping intent detection" }, t), {
199
+ ...e,
200
+ currentIntent: "none",
201
+ finalOutputMessage: "No agents registered; skipping intent detection."
202
+ };
203
+ const r = await I("intent_prompt"), c = R(i), l = de(i), m = {
204
+ registeredAgents: c,
205
+ priorSteps: R(e.agentExecutionContext.priorSteps),
183
206
  userRequest: e.agentExecutionContext.userRequest
184
- }, g = await C.fromTemplate(o).format(l), I = J({
185
- model: await x("fast"),
207
+ }, T = await F.fromTemplate(r).format(m), C = G({
208
+ model: await b({ modelTier: "fast", abortSignal: s.abortSignal }),
186
209
  tools: [],
187
- systemPrompt: g,
210
+ systemPrompt: T,
188
211
  checkpointer: !0,
189
- responseFormat: c,
212
+ responseFormat: l,
190
213
  middleware: [
191
214
  // Preserve recent conversation context while summarizing older messages
192
215
  // to control token usage without losing important intent signals.
193
216
  // The trigger and keep parameters can be tuned based on token limits and behavior.
194
- X({
195
- model: await x("fast"),
217
+ Q({
218
+ model: await b({ modelTier: "fast", abortSignal: s.abortSignal }),
196
219
  trigger: { tokens: 4e3 },
197
220
  keep: { messages: 6 }
198
221
  }),
199
222
  // Enforce no loop/retry.
200
223
  // 1 usual LLM call and 1 optional summarization call.
201
- G({ runLimit: 2 })
224
+ Y({ runLimit: 2 })
202
225
  ]
203
- }), { structuredResponse: z } = await ie({
204
- agent: I,
226
+ }), { structuredResponse: L } = await ce({
227
+ agent: C,
205
228
  messages: e.agentExecutionContext.messages,
206
229
  config: t
207
- }), f = c.parse(
208
- z ?? { intent: null, assignedTask: null, requiresFollowUp: !1 }
209
- ), v = f.intent ?? "none", L = {
230
+ }), y = l.parse(
231
+ L ?? { intent: null, assignedTask: null, requiresFollowUp: !1 }
232
+ ), x = y.intent ?? "none", K = {
210
233
  ...e,
211
- currentIntent: v,
212
- requiresFollowUp: f.requiresFollowUp,
234
+ currentIntent: x,
235
+ requiresFollowUp: y.requiresFollowUp,
213
236
  agentExecutionContext: {
214
237
  ...e.agentExecutionContext,
215
- assignedTask: f.assignedTask ?? ""
238
+ assignedTask: y.assignedTask ?? ""
216
239
  }
217
240
  };
218
- if (v === "none") {
219
- const h = "I could not find a matching agent for that request. Please rephrase your question with more detail.";
220
- return await y({ text: "LLM did not identify a clear intent." }, t), {
241
+ if (x === "none") {
242
+ const g = `I could not find an agent that can handle that request. I have access to the following agents: ${a.map(({ agent: B }) => B.name).join(", ")}.
243
+
244
+ Please ask a question that can be answered by one of these agents.`;
245
+ return await f({ text: "LLM did not identify a clear intent." }, t), {
221
246
  ...e,
222
- currentIntent: v,
247
+ currentIntent: x,
223
248
  requiresFollowUp: !1,
249
+ finalOutputMessage: g,
224
250
  agentExecutionContext: {
225
251
  ...e.agentExecutionContext,
226
252
  assignedTask: "",
227
- messages: [...e.agentExecutionContext.messages, new B(h)],
253
+ messages: [...e.agentExecutionContext.messages, new H(g)],
228
254
  priorSteps: [
229
255
  ...e.agentExecutionContext.priorSteps ?? [],
230
256
  {
@@ -237,177 +263,179 @@ const D = (e) => JSON.stringify(e, null, 2), oe = (e) => {
237
263
  }
238
264
  };
239
265
  }
240
- return await y(
266
+ return await f(
241
267
  {
242
- text: `Agent picked: ${v}
243
- Task Assigned: ${f.assignedTask ?? ""}
244
- Requires Follow-Up: ${f.requiresFollowUp}`
268
+ text: `Agent picked: ${x}
269
+ Task Assigned: ${y.assignedTask ?? ""}
270
+ Requires Follow-Up: ${y.requiresFollowUp}`
245
271
  },
246
272
  t
247
- ), L;
248
- } catch (s) {
249
- throw await y({ text: "Error during intent detection" }, t), new Error(`Error during intent detection: ${s instanceof Error ? s.message : String(s)}`);
273
+ ), K;
274
+ } catch (n) {
275
+ throw await f({ text: "Error during intent detection" }, t), new Error(`Error during intent detection: ${n instanceof Error ? n.message : String(n)}`);
250
276
  }
251
- }, ae = "0.1", w = 1536, ce = "openai", le = k.default, de = `Name: {name}
277
+ }, pe = "0.1", w = 1536, me = "openai", ue = A.default, ge = `Name: {name}
252
278
  Title: {title}
253
- Description: {description}`, pe = `Name: {name}
279
+ Description: {description}`, fe = `Name: {name}
254
280
  Alias: {alias}
255
- Description: {description}`, Fe = r.object({
256
- schemaVersion: r.literal(ae),
257
- modified: r.number().int().nonnegative(),
258
- embeddings: r.object({
259
- modelProvider: r.literal(ce),
260
- model: r.literal(le),
261
- dimensions: r.literal(w),
262
- templates: r.object({
263
- layer: r.string().default(de),
264
- field: r.string().default(pe)
281
+ Description: {description}`, qe = o.object({
282
+ schemaVersion: o.literal(pe),
283
+ modified: o.number().int().nonnegative(),
284
+ embeddings: o.object({
285
+ modelProvider: o.literal(me),
286
+ model: o.literal(ue),
287
+ dimensions: o.literal(w),
288
+ templates: o.object({
289
+ layer: o.string().default(ge),
290
+ field: o.string().default(fe)
265
291
  })
266
292
  }),
267
- layers: r.array(
268
- r.object({
269
- id: r.string().min(1),
270
- name: r.string().min(1),
271
- title: r.string().catch(""),
272
- description: r.string().catch(""),
273
- vector: r.array(r.number()).length(w, {
293
+ layers: o.array(
294
+ o.object({
295
+ id: o.string().min(1),
296
+ name: o.string().min(1),
297
+ title: o.string().catch(""),
298
+ description: o.string().catch(""),
299
+ vector: o.array(o.number()).length(w, {
274
300
  message: `Layer vector must be exactly ${w} dimensions`
275
301
  }),
276
- fields: r.array(
277
- r.object({
278
- name: r.string().min(1),
279
- alias: r.string().catch(""),
280
- description: r.string().catch(""),
281
- vector: r.array(r.number()).length(w, {
302
+ fields: o.array(
303
+ o.object({
304
+ name: o.string().min(1),
305
+ alias: o.string().catch(""),
306
+ description: o.string().catch(""),
307
+ vector: o.array(o.number()).length(w, {
282
308
  message: `Field vector must be exactly ${w} dimensions`
283
309
  })
284
310
  })
285
311
  )
286
312
  })
287
313
  ).default([])
288
- }), me = (e) => {
314
+ }), he = (e) => {
289
315
  const t = /* @__PURE__ */ new Set();
290
316
  for (const n of e)
291
- if (W(n)) {
292
- const i = n;
293
- i.tool_calls && i.tool_calls.length > 0 && i.tool_calls.forEach((o) => {
294
- o.id && t.add(o.id);
317
+ if (J(n)) {
318
+ const a = n;
319
+ a.tool_calls && a.tool_calls.length > 0 && a.tool_calls.forEach((i) => {
320
+ i.id && t.add(i.id);
295
321
  });
296
322
  }
297
323
  return e.filter((n) => {
298
- if (H(n)) {
299
- const i = n;
300
- return t.has(i.tool_call_id);
324
+ if (X(n)) {
325
+ const a = n;
326
+ return t.has(a.tool_call_id);
301
327
  }
302
328
  return !0;
303
329
  });
304
330
  }, E = (e, t) => {
305
- const s = K.fromTemplate(e);
306
- return C.fromMessages([s, ...t]);
307
- }, ue = async (e) => {
308
- const { promptText: t, modelTier: s, temperature: n, messages: i } = e, o = E(t, i ?? []), a = await x(s, n);
309
- return o.pipe(a);
310
- }, Ue = async (e) => {
311
- const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: i, inputVariables: o } = e, c = await (await ue({
331
+ const s = W.fromTemplate(e);
332
+ return F.fromMessages([s, ...t]);
333
+ }, ye = async (e) => {
334
+ const { promptText: t, modelTier: s, temperature: n, messages: a, abortSignal: i } = e, r = E(t, a ?? []), c = await b({ modelTier: s, temperature: n, abortSignal: i });
335
+ return r.pipe(c);
336
+ }, je = async (e) => {
337
+ const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: a, inputVariables: i, abortSignal: r } = e, l = await (await ye({
312
338
  promptText: t,
313
339
  modelTier: s,
314
340
  temperature: n,
315
- messages: i
316
- })).invoke(o ?? {});
317
- if (typeof c == "string")
318
- return c;
319
- const l = c.content;
320
- return typeof l == "string" ? l : JSON.stringify(l);
321
- }, O = async (e) => {
322
- const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: i, inputVariables: o, schema: a } = e, c = E(t, i ?? []), m = (await x(s, n)).withStructuredOutput(a);
323
- return await c.pipe(m).invoke(o ?? {});
324
- }, _e = async (e) => {
325
- const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: i, inputVariables: o, tools: a } = e, c = a.length > 0 ? me(i ?? []) : i ?? [], l = E(t, c), m = await x(s, n);
326
- return await l.pipe(m.bindTools(a)).invoke(o ?? {});
327
- }, ge = p.object({
341
+ messages: a,
342
+ abortSignal: r
343
+ })).invoke(i ?? {});
344
+ if (typeof l == "string")
345
+ return l;
346
+ const m = l.content;
347
+ return typeof m == "string" ? m : JSON.stringify(m);
348
+ }, V = async (e) => {
349
+ const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: a, inputVariables: i, schema: r, abortSignal: c } = e, l = E(t, a ?? []), u = (await b({ modelTier: s, temperature: n, abortSignal: c })).withStructuredOutput(r);
350
+ return await l.pipe(u).invoke(i ?? {});
351
+ }, $e = async (e) => {
352
+ const { promptText: t, modelTier: s = "default", temperature: n = 0, messages: a, inputVariables: i, tools: r, abortSignal: c } = e, l = r.length > 0 ? he(a ?? []) : a ?? [], m = E(t, l), u = await b({ modelTier: s, temperature: n, abortSignal: c });
353
+ return await m.pipe(u.bindTools(r)).invoke(i ?? {});
354
+ }, we = p.object({
328
355
  name: p.string(),
329
356
  description: p.string(),
330
357
  valueType: p.string(),
331
358
  alias: p.string()
332
- }), fe = p.object({
333
- fields: p.array(ge)
334
- }), V = (e, t) => e.getFieldAlias(t) ?? void 0, b = (e, t) => V(e, t.name) ?? t.alias ?? "", he = (e, t) => {
335
- const s = V(e, t.name);
359
+ }), be = p.object({
360
+ fields: p.array(we)
361
+ }), z = (e, t) => e.getFieldAlias(t) ?? void 0, S = (e, t) => z(e, t.name) ?? t.alias ?? "", xe = (e, t) => {
362
+ const s = z(e, t.name);
336
363
  return !!(s && s !== (t.alias ?? ""));
337
364
  };
338
- function R(e, t) {
365
+ function D(e, t) {
339
366
  const s = /* @__PURE__ */ new Map();
340
367
  for (const n of e.fields) {
341
- const i = t.fields.find((l) => l.name === n.name), o = b(e, n), a = he(e, n), c = {
368
+ const a = t.fields.find((l) => l.name === n.name), i = S(e, n), r = xe(e, n), c = {
342
369
  name: n.name,
343
370
  type: n.type,
344
- alias: a ? o : i?.alias ?? o,
345
- description: i?.description ?? n.description ?? "",
346
- valueType: i?.valueType ?? n.valueType ?? "",
371
+ alias: r ? i : a?.alias ?? i,
372
+ description: a?.description ?? n.description ?? "",
373
+ valueType: a?.valueType ?? n.valueType ?? "",
347
374
  domain: e.getFieldDomain(n.name) ?? void 0
348
375
  };
349
376
  s.set(n.name, c);
350
377
  }
351
378
  return s;
352
379
  }
353
- const Pe = async (e) => {
354
- const s = await A("field_descriptions_prompt"), n = e.fields.filter((a) => !(b(e, a) && a.description)).map((a) => {
355
- const { name: c, type: l, description: m } = a, g = b(e, a);
356
- return [`Name: ${c}`, `Type: ${l}`, `Alias: ${g}`, `Description: ${m ?? "N/A"}`].join(", ");
380
+ const Ne = async (e) => {
381
+ const s = await I("field_descriptions_prompt"), n = e.fields.filter((r) => !(S(e, r) && r.description)).map((r) => {
382
+ const { name: c, type: l, description: m } = r, u = S(e, r);
383
+ return [`Name: ${c}`, `Type: ${l}`, `Alias: ${u}`, `Description: ${m ?? "N/A"}`].join(", ");
357
384
  }).join(`
358
385
  `);
359
386
  if (n.length === 0)
360
- return R(e, { fields: [] });
361
- const i = {
387
+ return D(e, { fields: [] });
388
+ const a = {
362
389
  existingItemTitle: e.portalItem?.title,
363
390
  existingItemDescription: e.portalItem?.description,
364
391
  existingLayerTitle: e.title,
365
392
  existingLayerDescription: e.portalItem?.description,
366
393
  fieldInformation: n
367
- }, o = await O({
394
+ }, i = await V({
368
395
  promptText: s,
369
- schema: fe,
370
- inputVariables: i
396
+ schema: be,
397
+ inputVariables: a
371
398
  });
372
- return R(e, o);
373
- }, ye = p.object({
399
+ return D(e, i);
400
+ }, ve = p.object({
374
401
  title: p.string(),
375
402
  description: p.string(),
376
403
  name: p.string().nullable()
377
- }), qe = async (e, t) => {
378
- const n = await A("layer_descriptions_prompt"), i = Array.from(t.values()), o = {
379
- fieldInformation: JSON.stringify(i, null, 2),
404
+ }), Oe = async (e, t) => {
405
+ const n = await I("layer_descriptions_prompt"), a = Array.from(t.values()), i = {
406
+ fieldInformation: JSON.stringify(a, null, 2),
380
407
  existingLayerTitle: e.title,
381
408
  existingLayerDescription: e.portalItem?.description,
382
409
  existingLayerSnippet: e.portalItem?.snippet,
383
410
  layerGeometryType: e.geometryType
384
411
  };
385
- return { ...await O({
412
+ return { ...await V({
386
413
  promptText: n,
387
- schema: ye,
388
- inputVariables: o
414
+ schema: ve,
415
+ inputVariables: i
389
416
  }), name: e.title ?? null };
390
417
  };
391
418
  export {
392
- Ie as D,
393
- Fe as W,
394
- qe as a,
395
- ce as b,
396
- x as c,
419
+ Fe as D,
420
+ qe as W,
421
+ Oe as a,
422
+ me as b,
423
+ b as c,
397
424
  w as d,
398
- ae as e,
399
- pe as f,
400
- Pe as g,
401
- Ue as h,
402
- O as i,
403
- _e as j,
404
- ne as k,
405
- de as l,
406
- le as m,
407
- Ee as n,
408
- De as o,
409
- te as p,
410
- Ce as q,
411
- Re as r,
412
- y as s
425
+ pe as e,
426
+ fe as f,
427
+ Ne as g,
428
+ je as h,
429
+ V as i,
430
+ $e as j,
431
+ ae as k,
432
+ ge as l,
433
+ ue as m,
434
+ De as n,
435
+ Ue as o,
436
+ se as p,
437
+ oe as q,
438
+ Pe as r,
439
+ f as s,
440
+ _e as t
413
441
  };