@opencx/widget-react-headless 5.12.0 → 5.14.0

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/index.js CHANGED
@@ -8,8 +8,8 @@ import { isAgentStreamKeepalive as $r, log as le, isRecord as _n, genUuid as Rt,
8
8
  import { safeParseAsync as Yr, lazy as Kr, unknown as Gr, union as Qr, string as Xr, record as es, object as ts, number as ns, null as rs, never as ss, looseObject as as, literal as is, instanceof as os, enum as ls, discriminatedUnion as cs, custom as us, boolean as ds, array as ps } from "zod/v4";
9
9
  import { toJSONSchema as fs } from "zod/v4/core";
10
10
  import "react/jsx-runtime";
11
- import { z as L } from "zod";
12
- const Pn = "5.12.0";
11
+ import { z as D } from "zod";
12
+ const Pn = "5.14.0";
13
13
  function K(t) {
14
14
  return zt(t.subscribe, t.get, t.get);
15
15
  }
@@ -57,17 +57,17 @@ var ee = class Nn extends Error {
57
57
  return e != null && typeof e == "object" && r in e && typeof e[r] == "boolean" && e[r] === !0;
58
58
  }
59
59
  };
60
- const Dn = "AI_APICallError", Ln = `vercel.ai.error.${Dn}`, ys = Symbol.for(Ln);
60
+ const Ln = "AI_APICallError", Dn = `vercel.ai.error.${Ln}`, ys = Symbol.for(Dn);
61
61
  var kn = class extends ee {
62
- constructor({ message: t, url: e, requestBodyValues: n, statusCode: r, responseHeaders: s, responseBody: o, cause: l, isRetryable: u = r != null && (r === 408 || r === 409 || r === 429 || r >= 500), data: y }) {
62
+ constructor({ message: t, url: e, requestBodyValues: n, statusCode: r, responseHeaders: s, responseBody: o, cause: l, isRetryable: u = r != null && (r === 408 || r === 409 || r === 429 || r >= 500), data: h }) {
63
63
  super({
64
- name: Dn,
64
+ name: Ln,
65
65
  message: t,
66
66
  cause: l
67
- }), this[ys] = !0, this.url = e, this.requestBodyValues = n, this.statusCode = r, this.responseHeaders = s, this.responseBody = o, this.isRetryable = u, this.data = y;
67
+ }), this[ys] = !0, this.url = e, this.requestBodyValues = n, this.statusCode = r, this.responseHeaders = s, this.responseBody = o, this.isRetryable = u, this.data = h;
68
68
  }
69
69
  static isInstance(t) {
70
- return ee.hasMarker(t, Ln);
70
+ return ee.hasMarker(t, Dn);
71
71
  }
72
72
  };
73
73
  const jn = "AI_EmptyResponseBodyError", $n = `vercel.ai.error.${jn}`, vs = Symbol.for($n);
@@ -177,15 +177,15 @@ function xs(t) {
177
177
  "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
178
178
  );
179
179
  const { onEvent: e = Ot, onError: n = Ot, onRetry: r = Ot, onComment: s, maxBufferSize: o } = t, l = [];
180
- let u = 0, y = !0, g, i = "", d = 0, p, b = !1;
180
+ let u = 0, h = !0, g, i = "", d = 0, p, b = !1;
181
181
  function P(c) {
182
182
  if (b)
183
183
  throw new Error(
184
184
  "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
185
185
  );
186
- if (y && (y = !1, c.charCodeAt(0) === 239 && c.charCodeAt(1) === 187 && c.charCodeAt(2) === 191 && (c = c.slice(3))), l.length === 0) {
187
- const h = O(c);
188
- h !== "" && (l.push(h), u = h.length), M();
186
+ if (h && (h = !1, c.charCodeAt(0) === 239 && c.charCodeAt(1) === 187 && c.charCodeAt(2) === 191 && (c = c.slice(3))), l.length === 0) {
187
+ const y = O(c);
188
+ y !== "" && (l.push(y), u = y.length), M();
189
189
  return;
190
190
  }
191
191
  if (c.indexOf(`
@@ -217,8 +217,8 @@ function xs(t) {
217
217
  `, m);
218
218
  continue;
219
219
  }
220
- const h = c.charCodeAt(m);
221
- if (an(c, m, h)) {
220
+ const y = c.charCodeAt(m);
221
+ if (an(c, m, y)) {
222
222
  const S = c.charCodeAt(m + 5) === Oe ? m + 6 : m + 5, N = c.slice(S, f);
223
223
  if (d === 0 && c.charCodeAt(f + 1) === sn) {
224
224
  e({ id: g, event: p, data: N }), g = void 0, i = "", p = void 0, m = f + 2, f = c.indexOf(`
@@ -227,7 +227,7 @@ function xs(t) {
227
227
  }
228
228
  i = d === 0 ? N : `${i}
229
229
  ${N}`, d++;
230
- } else on(c, m, h) ? p = c.slice(
230
+ } else on(c, m, y) ? p = c.slice(
231
231
  c.charCodeAt(m + 6) === Oe ? m + 7 : m + 6,
232
232
  f
233
233
  ) || void 0 : x(c, m, f);
@@ -237,10 +237,10 @@ ${N}`, d++;
237
237
  return c.slice(m);
238
238
  }
239
239
  for (; m < c.length; ) {
240
- const f = c.indexOf("\r", m), h = c.indexOf(`
240
+ const f = c.indexOf("\r", m), y = c.indexOf(`
241
241
  `, m);
242
242
  let S = -1;
243
- if (f !== -1 && h !== -1 ? S = f < h ? f : h : f !== -1 ? f === c.length - 1 ? S = -1 : S = f : h !== -1 && (S = h), S === -1)
243
+ if (f !== -1 && y !== -1 ? S = f < y ? f : y : f !== -1 ? f === c.length - 1 ? S = -1 : S = f : y !== -1 && (S = y), S === -1)
244
244
  break;
245
245
  x(c, m, S), m = S + 1, c.charCodeAt(m - 1) === As && c.charCodeAt(m) === sn && m++;
246
246
  }
@@ -251,23 +251,23 @@ ${N}`, d++;
251
251
  I();
252
252
  return;
253
253
  }
254
- const h = c.charCodeAt(m);
255
- if (an(c, m, h)) {
254
+ const y = c.charCodeAt(m);
255
+ if (an(c, m, y)) {
256
256
  const k = c.charCodeAt(m + 5) === Oe ? m + 6 : m + 5, $ = c.slice(k, f);
257
257
  i = d === 0 ? $ : `${i}
258
258
  ${$}`, d++;
259
259
  return;
260
260
  }
261
- if (on(c, m, h)) {
261
+ if (on(c, m, y)) {
262
262
  p = c.slice(c.charCodeAt(m + 6) === Oe ? m + 7 : m + 6, f) || void 0;
263
263
  return;
264
264
  }
265
- if (h === 105 && c.charCodeAt(m + 1) === 100 && c.charCodeAt(m + 2) === 58) {
265
+ if (y === 105 && c.charCodeAt(m + 1) === 100 && c.charCodeAt(m + 2) === 58) {
266
266
  const k = c.slice(c.charCodeAt(m + 3) === Oe ? m + 4 : m + 3, f);
267
267
  g = k.includes("\0") ? void 0 : k;
268
268
  return;
269
269
  }
270
- if (h === 58) {
270
+ if (y === 58) {
271
271
  if (s) {
272
272
  const k = c.slice(m, f);
273
273
  s(k.slice(c.charCodeAt(m + 1) === Oe ? 2 : 1));
@@ -279,8 +279,8 @@ ${$}`, d++;
279
279
  C(S, "", S);
280
280
  return;
281
281
  }
282
- const D = S.slice(0, N), B = S.charCodeAt(N + 1) === Oe ? 2 : 1, W = S.slice(N + B);
283
- C(D, W, S);
282
+ const L = S.slice(0, N), B = S.charCodeAt(N + 1) === Oe ? 2 : 1, W = S.slice(N + B);
283
+ C(L, W, S);
284
284
  }
285
285
  function C(c, m, f) {
286
286
  switch (c) {
@@ -325,7 +325,7 @@ ${m}`, d++;
325
325
  const m = l.join("");
326
326
  x(m, 0, m.length);
327
327
  }
328
- y = !0, g = void 0, i = "", d = 0, p = void 0, l.length = 0, u = 0, b = !1;
328
+ h = !0, g = void 0, i = "", d = 0, p = void 0, l.length = 0, u = 0, b = !1;
329
329
  }
330
330
  return { feed: P, reset: w };
331
331
  }
@@ -437,7 +437,7 @@ function Zt(t) {
437
437
  function Me(t) {
438
438
  return typeof t == "boolean" ? t : Zt(t);
439
439
  }
440
- const Ds = Symbol("Let zodToJsonSchema decide on which parser to use"), cn = {
440
+ const Ls = Symbol("Let zodToJsonSchema decide on which parser to use"), cn = {
441
441
  name: void 0,
442
442
  $refStrategy: "root",
443
443
  basePath: ["#"],
@@ -457,7 +457,7 @@ const Ds = Symbol("Let zodToJsonSchema decide on which parser to use"), cn = {
457
457
  emailStrategy: "format:email",
458
458
  base64Strategy: "contentEncoding:base64",
459
459
  nameStrategy: "ref"
460
- }, Ls = (t) => typeof t == "string" ? {
460
+ }, Ds = (t) => typeof t == "string" ? {
461
461
  ...cn,
462
462
  name: t
463
463
  } : {
@@ -664,10 +664,10 @@ function Kn(t, e) {
664
664
  se(n, he.cuid2, r.message, e);
665
665
  break;
666
666
  case "startsWith":
667
- se(n, RegExp(`^${Dt(r.value, e)}`), r.message, e);
667
+ se(n, RegExp(`^${Lt(r.value, e)}`), r.message, e);
668
668
  break;
669
669
  case "endsWith":
670
- se(n, RegExp(`${Dt(r.value, e)}$`), r.message, e);
670
+ se(n, RegExp(`${Lt(r.value, e)}$`), r.message, e);
671
671
  break;
672
672
  case "datetime":
673
673
  ye(n, "date-time", r.message, e);
@@ -685,7 +685,7 @@ function Kn(t, e) {
685
685
  n.minLength = typeof n.minLength == "number" ? Math.max(n.minLength, r.value) : r.value, n.maxLength = typeof n.maxLength == "number" ? Math.min(n.maxLength, r.value) : r.value;
686
686
  break;
687
687
  case "includes":
688
- se(n, RegExp(Dt(r.value, e)), r.message, e);
688
+ se(n, RegExp(Lt(r.value, e)), r.message, e);
689
689
  break;
690
690
  case "ip":
691
691
  r.version !== "v6" && ye(n, "ipv4", r.message, e), r.version !== "v4" && ye(n, "ipv6", r.message, e);
@@ -722,7 +722,7 @@ function Kn(t, e) {
722
722
  }
723
723
  return n;
724
724
  }
725
- function Dt(t, e) {
725
+ function Lt(t, e) {
726
726
  return e.patternStrategy === "escape" ? Hs(t) : t;
727
727
  }
728
728
  const Js = /* @__PURE__ */ new Set("ABCDEFGHIJKLMNOPQRSTUVXYZabcdefghijklmnopqrstuvxyz0123456789");
@@ -747,7 +747,7 @@ function se(t, e, n, r) {
747
747
  })) : t.pattern = un(e, r);
748
748
  }
749
749
  function un(t, e) {
750
- var y;
750
+ var h;
751
751
  if (!e.applyRegexFlags || !t.flags) return t.source;
752
752
  const n = {
753
753
  i: t.flags.includes("i"),
@@ -763,7 +763,7 @@ function un(t, e) {
763
763
  if (n.i) {
764
764
  if (l) {
765
765
  if (r[g].match(/[a-z]/)) {
766
- u ? (s += r[g], s += `${r[g - 2]}-${r[g]}`.toUpperCase(), u = !1) : r[g + 1] === "-" && ((y = r[g + 2]) != null && y.match(/[a-z]/)) ? (s += r[g], u = !0) : s += `${r[g]}${r[g].toUpperCase()}`;
766
+ u ? (s += r[g], s += `${r[g - 2]}-${r[g]}`.toUpperCase(), u = !1) : r[g + 1] === "-" && ((h = r[g + 2]) != null && h.match(/[a-z]/)) ? (s += r[g], u = !0) : s += `${r[g]}${r[g].toUpperCase()}`;
767
767
  continue;
768
768
  }
769
769
  } else if (r[g].match(/[a-z]/)) {
@@ -807,7 +807,7 @@ function Gn(t, e) {
807
807
  }) ?? e.allowedAdditionalProperties
808
808
  };
809
809
  if (((r = t.keyType) == null ? void 0 : r._def.typeName) === "ZodString" && ((s = t.keyType._def.checks) != null && s.length)) {
810
- const { type: y, ...g } = Kn(t.keyType._def, e);
810
+ const { type: h, ...g } = Kn(t.keyType._def, e);
811
811
  return {
812
812
  ...n,
813
813
  propertyNames: g
@@ -818,7 +818,7 @@ function Gn(t, e) {
818
818
  propertyNames: { enum: t.keyType._def.values }
819
819
  };
820
820
  if (((l = t.keyType) == null ? void 0 : l._def.typeName) === "ZodBranded" && t.keyType._def.type._def.typeName === "ZodString" && ((u = t.keyType._def.type._def.checks) != null && u.length)) {
821
- const { type: y, ...g } = Hn(t.keyType._def, e);
821
+ const { type: h, ...g } = Hn(t.keyType._def, e);
822
822
  return {
823
823
  ...n,
824
824
  propertyNames: g
@@ -967,7 +967,7 @@ function ra(t, e) {
967
967
  for (const l in s) {
968
968
  let u = s[l];
969
969
  if (u === void 0 || u._def === void 0) continue;
970
- const y = aa(u), g = q(u._def, {
970
+ const h = aa(u), g = q(u._def, {
971
971
  ...e,
972
972
  currentPath: [
973
973
  ...e.currentPath,
@@ -980,7 +980,7 @@ function ra(t, e) {
980
980
  l
981
981
  ]
982
982
  });
983
- g !== void 0 && (n.properties[l] = g, y || r.push(l));
983
+ g !== void 0 && (n.properties[l] = g, h || r.push(l));
984
984
  }
985
985
  r.length && (n.required = r);
986
986
  const o = sa(t, e);
@@ -1172,12 +1172,12 @@ function q(t, e, n = !1) {
1172
1172
  var u;
1173
1173
  const r = e.seen.get(t);
1174
1174
  if (e.override) {
1175
- const y = (u = e.override) == null ? void 0 : u.call(e, t, e, r, n);
1176
- if (y !== Ds) return y;
1175
+ const h = (u = e.override) == null ? void 0 : u.call(e, t, e, r, n);
1176
+ if (h !== Ls) return h;
1177
1177
  }
1178
1178
  if (r && !n) {
1179
- const y = ha(r, e);
1180
- if (y !== void 0) return y;
1179
+ const h = ha(r, e);
1180
+ if (h !== void 0) return h;
1181
1181
  }
1182
1182
  const s = {
1183
1183
  def: t,
@@ -1187,8 +1187,8 @@ function q(t, e, n = !1) {
1187
1187
  e.seen.set(t, s);
1188
1188
  const o = ma(t, t.typeName, e), l = typeof o == "function" ? q(o(), e) : o;
1189
1189
  if (l && ya(t, e, l), e.postProcess) {
1190
- const y = e.postProcess(l, t, e);
1191
- return s.jsonSchema = l, y;
1190
+ const h = e.postProcess(l, t, e);
1191
+ return s.jsonSchema = l, h;
1192
1192
  }
1193
1193
  return s.jsonSchema = l, l;
1194
1194
  }
@@ -1203,7 +1203,7 @@ const ha = (t, e) => {
1203
1203
  return t.path.length < e.currentPath.length && t.path.every((n, r) => e.currentPath[r] === n) ? (console.warn(`Recursive reference detected at ${e.currentPath.join("/")}! Defaulting to any`), ue()) : e.$refStrategy === "seen" ? ue() : void 0;
1204
1204
  }
1205
1205
  }, ya = (t, e, n) => (t.description && (n.description = t.description), n), va = (t) => {
1206
- const e = Ls(t), n = e.name !== void 0 ? [
1206
+ const e = Ds(t), n = e.name !== void 0 ? [
1207
1207
  ...e.basePath,
1208
1208
  e.definitionPath,
1209
1209
  e.name
@@ -1224,8 +1224,8 @@ const ha = (t, e) => {
1224
1224
  };
1225
1225
  }, ba = (t, e) => {
1226
1226
  const n = va(e);
1227
- let r = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((y, [g, i]) => ({
1228
- ...y,
1227
+ let r = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce((h, [g, i]) => ({
1228
+ ...h,
1229
1229
  [g]: q(i._def, {
1230
1230
  ...n,
1231
1231
  currentPath: [
@@ -1538,11 +1538,11 @@ const a = {
1538
1538
  filename: a.string().optional(),
1539
1539
  mediaType: a.string(),
1540
1540
  providerOptions: _.optional()
1541
- }), Da = a.object({
1541
+ }), La = a.object({
1542
1542
  type: a.literal("reasoning"),
1543
1543
  text: a.string(),
1544
1544
  providerOptions: _.optional()
1545
- }), La = a.object({
1545
+ }), Da = a.object({
1546
1546
  type: a.literal("custom"),
1547
1547
  kind: a.string().transform((t) => t),
1548
1548
  providerOptions: _.optional()
@@ -1688,9 +1688,9 @@ const a = {
1688
1688
  role: a.literal("assistant"),
1689
1689
  content: a.union([a.string(), a.array(a.union([
1690
1690
  ar,
1691
- La,
1692
- or,
1693
1691
  Da,
1692
+ or,
1693
+ La,
1694
1694
  ka,
1695
1695
  ja,
1696
1696
  lr,
@@ -1755,7 +1755,7 @@ function Ba(t) {
1755
1755
  n = d, e.pop();
1756
1756
  }
1757
1757
  }
1758
- function y(i, d) {
1758
+ function h(i, d) {
1759
1759
  switch (i) {
1760
1760
  case ",":
1761
1761
  e.pop(), e.push("INSIDE_ARRAY_AFTER_COMMA");
@@ -1865,13 +1865,13 @@ function Ba(t) {
1865
1865
  case ".":
1866
1866
  break;
1867
1867
  case ",":
1868
- e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && y(d, i), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && u(d, i);
1868
+ e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && h(d, i), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && u(d, i);
1869
1869
  break;
1870
1870
  case "}":
1871
1871
  e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && u(d, i);
1872
1872
  break;
1873
1873
  case "]":
1874
- e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && y(d, i);
1874
+ e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && h(d, i);
1875
1875
  break;
1876
1876
  default:
1877
1877
  e.pop();
@@ -1879,7 +1879,7 @@ function Ba(t) {
1879
1879
  break;
1880
1880
  case "INSIDE_LITERAL": {
1881
1881
  const p = t.substring(r, i + 1);
1882
- !"false".startsWith(p) && !"true".startsWith(p) && !"null".startsWith(p) ? (e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" ? u(d, i) : e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && y(d, i)) : n = i;
1882
+ !"false".startsWith(p) && !"true".startsWith(p) && !"null".startsWith(p) ? (e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" ? u(d, i) : e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && h(d, i)) : n = i;
1883
1883
  break;
1884
1884
  }
1885
1885
  }
@@ -2207,7 +2207,7 @@ function ur({ lastMessage: t, messageId: e }) {
2207
2207
  partialToolCalls: r
2208
2208
  };
2209
2209
  }
2210
- function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdateMessageJob: r, onError: s, onToolCall: o, onData: l, resetStateOnMessageIdChange: u = !1, resetStateOnFirstMessageStart: y = !1 }) {
2210
+ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdateMessageJob: r, onError: s, onToolCall: o, onData: l, resetStateOnMessageIdChange: u = !1, resetStateOnFirstMessageStart: h = !1 }) {
2211
2211
  let g = !0;
2212
2212
  return t.pipeThrough(new TransformStream({ async transform(i, d) {
2213
2213
  await r(async ({ state: p, write: b }) => {
@@ -2224,8 +2224,8 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
2224
2224
  let m = M().find((f) => f.toolCallId === c);
2225
2225
  if (m == null) {
2226
2226
  const f = p.message.parts;
2227
- for (let h = f.length - 1; h >= 0; h--) {
2228
- const S = f[h];
2227
+ for (let y = f.length - 1; y >= 0; y--) {
2228
+ const S = f[y];
2229
2229
  if (pe(S) && S.toolCallId === c) {
2230
2230
  m = S;
2231
2231
  break;
@@ -2241,8 +2241,8 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
2241
2241
  }
2242
2242
  function x(c) {
2243
2243
  const m = p.message.parts.filter(pe).find((f) => {
2244
- var h;
2245
- return ((h = f.approval) == null ? void 0 : h.id) === c;
2244
+ var y;
2245
+ return ((y = f.approval) == null ? void 0 : y.id) === c;
2246
2246
  });
2247
2247
  if (m == null) throw new Ne({
2248
2248
  chunkType: "tool-approval-response",
@@ -2252,14 +2252,14 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
2252
2252
  return m;
2253
2253
  }
2254
2254
  function C(c, m) {
2255
- const f = m ?? P().find((N) => gt(N) && N.toolCallId === c.toolCallId), h = c, S = f;
2255
+ const f = m ?? P().find((N) => gt(N) && N.toolCallId === c.toolCallId), y = c, S = f;
2256
2256
  if (f != null) {
2257
- f.state = c.state, S.type = `tool-${c.toolName}`, S.input = h.input, S.output = h.output, S.errorText = h.errorText, S.rawInput = h.rawInput, h.inputEncoding != null ? S.inputEncoding = h.inputEncoding : delete S.inputEncoding, S.preliminary = h.preliminary, c.title !== void 0 && (S.title = c.title), c.toolMetadata !== void 0 && (S.toolMetadata = c.toolMetadata), S.providerExecuted = h.providerExecuted ?? f.providerExecuted;
2258
- const N = h.providerMetadata;
2257
+ f.state = c.state, S.type = `tool-${c.toolName}`, S.input = y.input, S.output = y.output, S.errorText = y.errorText, S.rawInput = y.rawInput, y.inputEncoding != null ? S.inputEncoding = y.inputEncoding : delete S.inputEncoding, S.preliminary = y.preliminary, c.title !== void 0 && (S.title = c.title), c.toolMetadata !== void 0 && (S.toolMetadata = c.toolMetadata), S.providerExecuted = y.providerExecuted ?? f.providerExecuted;
2258
+ const N = y.providerMetadata;
2259
2259
  if (N != null)
2260
2260
  if (c.state === "output-available" || c.state === "output-error") {
2261
- const D = f;
2262
- D.resultProviderMetadata = N;
2261
+ const L = f;
2262
+ L.resultProviderMetadata = N;
2263
2263
  } else f.callProviderMetadata = N;
2264
2264
  } else p.message.parts.push({
2265
2265
  type: `tool-${c.toolName}`,
@@ -2267,42 +2267,42 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
2267
2267
  state: c.state,
2268
2268
  title: c.title,
2269
2269
  ...c.toolMetadata !== void 0 ? { toolMetadata: c.toolMetadata } : {},
2270
- input: h.input,
2271
- ...h.inputEncoding != null ? { inputEncoding: h.inputEncoding } : {},
2272
- output: h.output,
2273
- rawInput: h.rawInput,
2274
- errorText: h.errorText,
2275
- providerExecuted: h.providerExecuted,
2276
- preliminary: h.preliminary,
2277
- ...h.providerMetadata != null && (c.state === "output-available" || c.state === "output-error") ? { resultProviderMetadata: h.providerMetadata } : {},
2278
- ...h.providerMetadata != null && !(c.state === "output-available" || c.state === "output-error") ? { callProviderMetadata: h.providerMetadata } : {}
2270
+ input: y.input,
2271
+ ...y.inputEncoding != null ? { inputEncoding: y.inputEncoding } : {},
2272
+ output: y.output,
2273
+ rawInput: y.rawInput,
2274
+ errorText: y.errorText,
2275
+ providerExecuted: y.providerExecuted,
2276
+ preliminary: y.preliminary,
2277
+ ...y.providerMetadata != null && (c.state === "output-available" || c.state === "output-error") ? { resultProviderMetadata: y.providerMetadata } : {},
2278
+ ...y.providerMetadata != null && !(c.state === "output-available" || c.state === "output-error") ? { callProviderMetadata: y.providerMetadata } : {}
2279
2279
  });
2280
2280
  }
2281
2281
  function I(c, m) {
2282
- const f = m ?? P().find((N) => N.type === "dynamic-tool" && N.toolCallId === c.toolCallId), h = c, S = f;
2282
+ const f = m ?? P().find((N) => N.type === "dynamic-tool" && N.toolCallId === c.toolCallId), y = c, S = f;
2283
2283
  if (f != null) {
2284
- f.state = c.state, S.toolName = c.toolName, S.input = h.input, S.output = h.output, S.errorText = h.errorText, S.rawInput = h.rawInput, h.inputEncoding != null ? S.inputEncoding = h.inputEncoding : delete S.inputEncoding, S.preliminary = h.preliminary, c.title !== void 0 && (S.title = c.title), c.toolMetadata !== void 0 && (S.toolMetadata = c.toolMetadata), S.providerExecuted = h.providerExecuted ?? f.providerExecuted;
2285
- const N = h.providerMetadata;
2284
+ f.state = c.state, S.toolName = c.toolName, S.input = y.input, S.output = y.output, S.errorText = y.errorText, S.rawInput = y.rawInput, y.inputEncoding != null ? S.inputEncoding = y.inputEncoding : delete S.inputEncoding, S.preliminary = y.preliminary, c.title !== void 0 && (S.title = c.title), c.toolMetadata !== void 0 && (S.toolMetadata = c.toolMetadata), S.providerExecuted = y.providerExecuted ?? f.providerExecuted;
2285
+ const N = y.providerMetadata;
2286
2286
  if (N != null)
2287
2287
  if (c.state === "output-available" || c.state === "output-error") {
2288
- const D = f;
2289
- D.resultProviderMetadata = N;
2288
+ const L = f;
2289
+ L.resultProviderMetadata = N;
2290
2290
  } else f.callProviderMetadata = N;
2291
2291
  } else p.message.parts.push({
2292
2292
  type: "dynamic-tool",
2293
2293
  toolName: c.toolName,
2294
2294
  toolCallId: c.toolCallId,
2295
2295
  state: c.state,
2296
- input: h.input,
2297
- ...h.inputEncoding != null ? { inputEncoding: h.inputEncoding } : {},
2298
- output: h.output,
2299
- errorText: h.errorText,
2300
- preliminary: h.preliminary,
2301
- providerExecuted: h.providerExecuted,
2296
+ input: y.input,
2297
+ ...y.inputEncoding != null ? { inputEncoding: y.inputEncoding } : {},
2298
+ output: y.output,
2299
+ errorText: y.errorText,
2300
+ preliminary: y.preliminary,
2301
+ providerExecuted: y.providerExecuted,
2302
2302
  title: c.title,
2303
2303
  ...c.toolMetadata !== void 0 ? { toolMetadata: c.toolMetadata } : {},
2304
- ...h.providerMetadata != null && (c.state === "output-available" || c.state === "output-error") ? { resultProviderMetadata: h.providerMetadata } : {},
2305
- ...h.providerMetadata != null && !(c.state === "output-available" || c.state === "output-error") ? { callProviderMetadata: h.providerMetadata } : {}
2304
+ ...y.providerMetadata != null && (c.state === "output-available" || c.state === "output-error") ? { resultProviderMetadata: y.providerMetadata } : {},
2305
+ ...y.providerMetadata != null && !(c.state === "output-available" || c.state === "output-error") ? { callProviderMetadata: y.providerMetadata } : {}
2306
2306
  });
2307
2307
  }
2308
2308
  async function w(c) {
@@ -2615,7 +2615,7 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
2615
2615
  break;
2616
2616
  }
2617
2617
  case "start": {
2618
- const c = y && g || u && i.messageId != null && i.messageId !== p.message.id;
2618
+ const c = h && g || u && i.messageId != null && i.messageId !== p.message.id;
2619
2619
  g = !1, c && Object.assign(p, ur({
2620
2620
  lastMessage: void 0,
2621
2621
  messageId: i.messageId ?? p.message.id
@@ -2634,12 +2634,12 @@ function Ga({ stream: t, messageMetadataSchema: e, dataPartSchemas: n, runUpdate
2634
2634
  default:
2635
2635
  if (Ya(i)) {
2636
2636
  if ((n == null ? void 0 : n[i.type]) != null) {
2637
- const f = p.message.parts.findIndex((S) => "id" in S && "data" in S && S.id === i.id && S.type === i.type), h = f >= 0 ? f : p.message.parts.length;
2637
+ const f = p.message.parts.findIndex((S) => "id" in S && "data" in S && S.id === i.id && S.type === i.type), y = f >= 0 ? f : p.message.parts.length;
2638
2638
  await dn({
2639
2639
  value: i.data,
2640
2640
  schema: n[i.type],
2641
2641
  context: {
2642
- field: `message.parts[${h}].data`,
2642
+ field: `message.parts[${y}].data`,
2643
2643
  entityName: i.type,
2644
2644
  entityId: i.id
2645
2645
  }
@@ -2816,8 +2816,8 @@ async function ti(t) {
2816
2816
  url: await new Promise((s, o) => {
2817
2817
  const l = new FileReader();
2818
2818
  l.onload = (u) => {
2819
- var y;
2820
- s((y = u.target) == null ? void 0 : y.result);
2819
+ var h;
2820
+ s((h = u.target) == null ? void 0 : h.result);
2821
2821
  }, l.onerror = (u) => o(u), l.readAsDataURL(e);
2822
2822
  })
2823
2823
  };
@@ -2849,7 +2849,7 @@ var ri = class {
2849
2849
  requestMetadata: e.metadata,
2850
2850
  trigger: e.trigger,
2851
2851
  messageId: e.messageId
2852
- })), u = (l == null ? void 0 : l.api) ?? this.api, y = (l == null ? void 0 : l.headers) !== void 0 ? Ze(l.headers) : o, g = (l == null ? void 0 : l.body) !== void 0 ? l.body : {
2852
+ })), u = (l == null ? void 0 : l.api) ?? this.api, h = (l == null ? void 0 : l.headers) !== void 0 ? Ze(l.headers) : o, g = (l == null ? void 0 : l.body) !== void 0 ? l.body : {
2853
2853
  ...n,
2854
2854
  ...e.body,
2855
2855
  id: e.chatId,
@@ -2860,7 +2860,7 @@ var ri = class {
2860
2860
  method: "POST",
2861
2861
  headers: {
2862
2862
  "content-type": "application/json",
2863
- ...y
2863
+ ...h
2864
2864
  },
2865
2865
  body: JSON.stringify(g),
2866
2866
  credentials: i,
@@ -2899,10 +2899,10 @@ var ri = class {
2899
2899
  });
2900
2900
  l = ni(this.api, `/${encodeURIComponent(t.chatId)}/stream`);
2901
2901
  }
2902
- const u = (o == null ? void 0 : o.headers) !== void 0 ? Ze(o.headers) : s, y = (o == null ? void 0 : o.credentials) ?? r, g = await (this.fetch ?? globalThis.fetch)(l, {
2902
+ const u = (o == null ? void 0 : o.headers) !== void 0 ? Ze(o.headers) : s, h = (o == null ? void 0 : o.credentials) ?? r, g = await (this.fetch ?? globalThis.fetch)(l, {
2903
2903
  method: "GET",
2904
2904
  headers: u,
2905
- credentials: y,
2905
+ credentials: h,
2906
2906
  signal: t.abortSignal
2907
2907
  });
2908
2908
  if (g.status === 204) return null;
@@ -2931,7 +2931,7 @@ var ri = class {
2931
2931
  get id() {
2932
2932
  return this._id ?? (this._id = this.generateId());
2933
2933
  }
2934
- constructor({ generateId: t = Ms, id: e, transport: n = new yt(), messageMetadataSchema: r, dataPartSchemas: s, state: o, onError: l, onToolCall: u, onFinish: y, onData: g, sendAutomaticallyWhen: i }) {
2934
+ constructor({ generateId: t = Ms, id: e, transport: n = new yt(), messageMetadataSchema: r, dataPartSchemas: s, state: o, onError: l, onToolCall: u, onFinish: h, onData: g, sendAutomaticallyWhen: i }) {
2935
2935
  this.pendingMessagePreparations = /* @__PURE__ */ new Set(), this.interruptedMessageIds = /* @__PURE__ */ new Set(), this.activeResponse = void 0, this.activeResumeRequest = void 0, this.resumableStreamState = void 0, this.jobExecutor = new ei(), this.activeStopCount = 0, this.stopGeneration = 0, this.sendMessage = async (d, p) => {
2936
2936
  var P;
2937
2937
  if (d == null) {
@@ -3101,7 +3101,7 @@ var ri = class {
3101
3101
  }, this.dispose = async () => {
3102
3102
  var d, p;
3103
3103
  await this.stop(), (p = (d = this.transport).close) == null || p.call(d);
3104
- }, this._id = e, this.transport = n, this.generateId = t, this.messageMetadataSchema = r, this.dataPartSchemas = s, this.state = o, this.onError = l, this.onToolCall = u, this.onFinish = y, this.onData = g, this.sendAutomaticallyWhen = i;
3104
+ }, this._id = e, this.transport = n, this.generateId = t, this.messageMetadataSchema = r, this.dataPartSchemas = s, this.state = o, this.onError = l, this.onToolCall = u, this.onFinish = h, this.onData = g, this.sendAutomaticallyWhen = i;
3105
3105
  }
3106
3106
  /**
3107
3107
  * Hook status:
@@ -3170,7 +3170,7 @@ var ri = class {
3170
3170
  completionPromise: o
3171
3171
  } : void 0;
3172
3172
  u && ((c = this.activeResumeRequest) == null || c.abortController.abort(), this.activeResumeRequest = u);
3173
- const y = () => u == null || this.activeResumeRequest === u, g = () => {
3173
+ const h = () => u == null || this.activeResumeRequest === u, g = () => {
3174
3174
  this.activeResumeRequest === u && (this.activeResumeRequest = void 0);
3175
3175
  };
3176
3176
  let i;
@@ -3182,9 +3182,9 @@ var ri = class {
3182
3182
  headers: n,
3183
3183
  body: r
3184
3184
  });
3185
- if (l.signal.aborted || !y()) {
3185
+ if (l.signal.aborted || !h()) {
3186
3186
  await (f == null ? void 0 : f.cancel().catch(() => {
3187
- })), y() && (this.setStatus({ status: "ready" }), this.resumableStreamState = void 0), g();
3187
+ })), h() && (this.setStatus({ status: "ready" }), this.resumableStreamState = void 0), g();
3188
3188
  return;
3189
3189
  }
3190
3190
  if (f == null) {
@@ -3194,10 +3194,10 @@ var ri = class {
3194
3194
  i = f;
3195
3195
  } catch (f) {
3196
3196
  if (l.signal.aborted || f.name === "AbortError") {
3197
- y() && (this.setStatus({ status: "ready" }), this.resumableStreamState = void 0), g();
3197
+ h() && (this.setStatus({ status: "ready" }), this.resumableStreamState = void 0), g();
3198
3198
  return;
3199
3199
  }
3200
- if (!y()) return;
3200
+ if (!h()) return;
3201
3201
  this.onError && f instanceof Error && this.onError(f), this.setStatus({
3202
3202
  status: "error",
3203
3203
  error: f
@@ -3222,8 +3222,8 @@ var ri = class {
3222
3222
  w = f, f.abortController.signal.addEventListener("abort", () => {
3223
3223
  x = !0;
3224
3224
  }), this.activeResponse = f;
3225
- let h;
3226
- t === "resume-stream" ? h = i : h = await this.transport.sendMessages({
3225
+ let y;
3226
+ t === "resume-stream" ? y = i : y = await this.transport.sendMessages({
3227
3227
  chatId: this.id,
3228
3228
  messages: this.state.messages,
3229
3229
  abortSignal: f.abortController.signal,
@@ -3235,9 +3235,9 @@ var ri = class {
3235
3235
  });
3236
3236
  const S = (N) => this.jobExecutor.run(() => f.abortController.signal.aborted ? Promise.resolve() : N({
3237
3237
  state: f.state,
3238
- write: ({ updateStatus: D = !0 } = {}) => {
3238
+ write: ({ updateStatus: L = !0 } = {}) => {
3239
3239
  if (f.abortController.signal.aborted) return;
3240
- D && this.setStatus({ status: "streaming" });
3240
+ L && this.setStatus({ status: "streaming" });
3241
3241
  const B = this.state.messages.findLastIndex((W) => W.id === f.state.message.id);
3242
3242
  if (B !== -1) this.state.replaceMessage(B, f.state.message);
3243
3243
  else if (O) {
@@ -3248,7 +3248,7 @@ var ri = class {
3248
3248
  }));
3249
3249
  if (await Qa({
3250
3250
  stream: Ga({
3251
- stream: h,
3251
+ stream: y,
3252
3252
  resetStateOnMessageIdChange: t === "resume-stream",
3253
3253
  resetStateOnFirstMessageStart: t === "resume-stream" && this.transport.resumeStreamIsReplay,
3254
3254
  onToolCall: this.onToolCall,
@@ -3265,15 +3265,15 @@ var ri = class {
3265
3265
  throw N;
3266
3266
  }
3267
3267
  }), x)
3268
- return y() && (this.setStatus({ status: "ready" }), this.resumableStreamState === f.state && (this.resumableStreamState = void 0)), null;
3269
- y() && (this.setStatus({ status: "ready" }), this.resumableStreamState === f.state && (this.resumableStreamState = void 0));
3268
+ return h() && (this.setStatus({ status: "ready" }), this.resumableStreamState === f.state && (this.resumableStreamState = void 0)), null;
3269
+ h() && (this.setStatus({ status: "ready" }), this.resumableStreamState === f.state && (this.resumableStreamState = void 0));
3270
3270
  } catch (f) {
3271
3271
  if (x || f.name === "AbortError")
3272
- return x = !0, y() && (this.setStatus({ status: "ready" }), this.resumableStreamState === (w == null ? void 0 : w.state) && (this.resumableStreamState = void 0)), null;
3273
- if (!y()) return null;
3272
+ return x = !0, h() && (this.setStatus({ status: "ready" }), this.resumableStreamState === (w == null ? void 0 : w.state) && (this.resumableStreamState = void 0)), null;
3273
+ if (!h()) return null;
3274
3274
  if (I = !0, f instanceof TypeError) {
3275
- const h = f.message.toLowerCase();
3276
- C = h.includes("fetch") || h.includes("network") || h === "load failed";
3275
+ const y = f.message.toLowerCase();
3276
+ C = y.includes("fetch") || y.includes("network") || y === "load failed";
3277
3277
  }
3278
3278
  C ? this.resumableStreamState = w == null ? void 0 : w.state : this.resumableStreamState === (w == null ? void 0 : w.state) && (this.resumableStreamState = void 0), this.onError && f instanceof Error && this.onError(f), this.setStatus({
3279
3279
  status: "error",
@@ -3282,8 +3282,8 @@ var ri = class {
3282
3282
  } finally {
3283
3283
  try {
3284
3284
  if (w) {
3285
- const { message: f, finishReason: h } = w.state;
3286
- h === "interrupted" ? this.interruptedMessageIds.add(f.id) : !x && !I && this.interruptedMessageIds.delete(f.id), (m = this.onFinish) == null || m.call(this, {
3285
+ const { message: f, finishReason: y } = w.state;
3286
+ y === "interrupted" ? this.interruptedMessageIds.add(f.id) : !x && !I && this.interruptedMessageIds.delete(f.id), (m = this.onFinish) == null || m.call(this, {
3287
3287
  message: w.state.message,
3288
3288
  messages: this.state.messages,
3289
3289
  isAbort: x,
@@ -3307,9 +3307,9 @@ var ri = class {
3307
3307
  });
3308
3308
  });
3309
3309
  }
3310
- }, Lt, fn;
3310
+ }, Dt, fn;
3311
3311
  function ai() {
3312
- if (fn) return Lt;
3312
+ if (fn) return Dt;
3313
3313
  fn = 1;
3314
3314
  function t(e, n) {
3315
3315
  if (typeof e != "function")
@@ -3317,13 +3317,13 @@ function ai() {
3317
3317
  let r, s = 0;
3318
3318
  return function(...l) {
3319
3319
  clearTimeout(r);
3320
- const u = Date.now(), y = u - s, g = n - y;
3320
+ const u = Date.now(), h = u - s, g = n - h;
3321
3321
  g <= 0 ? (s = u, e.apply(this, l)) : r = setTimeout(() => {
3322
3322
  s = Date.now(), e.apply(this, l);
3323
3323
  }, g);
3324
3324
  };
3325
3325
  }
3326
- return Lt = t, Lt;
3326
+ return Dt = t, Dt;
3327
3327
  }
3328
3328
  var ii = /* @__PURE__ */ ai();
3329
3329
  const oi = /* @__PURE__ */ _a(ii);
@@ -3333,18 +3333,18 @@ function li(t, e) {
3333
3333
  function ci(t) {
3334
3334
  return Array.isArray(t) ? [...t] : t != null && typeof t == "object" && (Object.getPrototypeOf(t) === Object.prototype || Object.getPrototypeOf(t) === null) ? { ...t } : t;
3335
3335
  }
3336
- var ce, We, Je, De, Le, ke, _e, Qe, Xe, Tn, ui = (Tn = class {
3336
+ var ce, We, Je, Le, De, ke, _e, Qe, Xe, Tn, ui = (Tn = class {
3337
3337
  constructor(t = []) {
3338
3338
  ge(this, ce);
3339
3339
  ge(this, We);
3340
3340
  ge(this, Je);
3341
- ge(this, De);
3342
3341
  ge(this, Le);
3342
+ ge(this, De);
3343
3343
  ge(this, ke);
3344
3344
  ge(this, _e);
3345
3345
  ge(this, Qe);
3346
3346
  ge(this, Xe);
3347
- Q(this, We, "ready"), Q(this, Je, void 0), Q(this, De, /* @__PURE__ */ new Set()), Q(this, Le, /* @__PURE__ */ new Set()), Q(this, ke, /* @__PURE__ */ new Set()), this.pushMessage = (e) => {
3347
+ Q(this, We, "ready"), Q(this, Je, void 0), Q(this, Le, /* @__PURE__ */ new Set()), Q(this, De, /* @__PURE__ */ new Set()), Q(this, ke, /* @__PURE__ */ new Set()), this.pushMessage = (e) => {
3348
3348
  Q(this, ce, V(this, ce).concat(e)), V(this, _e).call(this);
3349
3349
  }, this.popMessage = () => {
3350
3350
  Q(this, ce, V(this, ce).slice(0, -1)), V(this, _e).call(this);
@@ -3363,17 +3363,17 @@ var ce, We, Je, De, Le, ke, _e, Qe, Xe, Tn, ui = (Tn = class {
3363
3363
  return "metadata" in n && (r.metadata = ci(n.metadata)), r;
3364
3364
  }, this["~registerMessagesCallback"] = (e, n) => {
3365
3365
  const r = n ? li(e, n) : e;
3366
- return V(this, De).add(r), () => {
3367
- V(this, De).delete(r);
3366
+ return V(this, Le).add(r), () => {
3367
+ V(this, Le).delete(r);
3368
3368
  };
3369
- }, this["~registerStatusCallback"] = (e) => (V(this, Le).add(e), () => {
3370
- V(this, Le).delete(e);
3369
+ }, this["~registerStatusCallback"] = (e) => (V(this, De).add(e), () => {
3370
+ V(this, De).delete(e);
3371
3371
  }), this["~registerErrorCallback"] = (e) => (V(this, ke).add(e), () => {
3372
3372
  V(this, ke).delete(e);
3373
3373
  }), Q(this, _e, () => {
3374
- V(this, De).forEach((e) => e());
3375
- }), Q(this, Qe, () => {
3376
3374
  V(this, Le).forEach((e) => e());
3375
+ }), Q(this, Qe, () => {
3376
+ V(this, De).forEach((e) => e());
3377
3377
  }), Q(this, Xe, () => {
3378
3378
  V(this, ke).forEach((e) => e());
3379
3379
  }), Q(this, ce, t);
@@ -3396,7 +3396,7 @@ var ce, We, Je, De, Le, ke, _e, Qe, Xe, Tn, ui = (Tn = class {
3396
3396
  set messages(t) {
3397
3397
  Q(this, ce, [...t]), V(this, _e).call(this);
3398
3398
  }
3399
- }, ce = new WeakMap(), We = new WeakMap(), Je = new WeakMap(), De = new WeakMap(), Le = new WeakMap(), ke = new WeakMap(), _e = new WeakMap(), Qe = new WeakMap(), Xe = new WeakMap(), Tn), je, Mn, di = (Mn = class extends si {
3399
+ }, ce = new WeakMap(), We = new WeakMap(), Je = new WeakMap(), Le = new WeakMap(), De = new WeakMap(), ke = new WeakMap(), _e = new WeakMap(), Qe = new WeakMap(), Xe = new WeakMap(), Tn), je, Mn, di = (Mn = class extends si {
3400
3400
  constructor({ messages: e, ...n }) {
3401
3401
  const r = new ui(e);
3402
3402
  super({
@@ -3457,14 +3457,14 @@ function mi({ throttle: t, experimental_throttle: e, resume: n = !1, ...r } = {}
3457
3457
  transport: r.transport
3458
3458
  });
3459
3459
  let u;
3460
- const y = () => l.current.transport ?? u ?? (u = new yt()), g = {
3460
+ const h = () => l.current.transport ?? u ?? (u = new yt()), g = {
3461
3461
  ...r,
3462
3462
  transport: {
3463
3463
  get resumeStreamIsReplay() {
3464
- return y().resumeStreamIsReplay;
3464
+ return h().resumeStreamIsReplay;
3465
3465
  },
3466
- sendMessages: (I) => y().sendMessages(I),
3467
- reconnectToStream: (I) => y().reconnectToStream(I)
3466
+ sendMessages: (I) => h().sendMessages(I),
3467
+ reconnectToStream: (I) => h().reconnectToStream(I)
3468
3468
  },
3469
3469
  onToolCall: (I) => {
3470
3470
  var w, c;
@@ -3502,7 +3502,7 @@ function mi({ throttle: t, experimental_throttle: e, resume: n = !1, ...r } = {}
3502
3502
  const w = () => {
3503
3503
  if (!I) return;
3504
3504
  const f = ct(d);
3505
- P((h) => h.chat !== d || mn(h, f) ? h : f);
3505
+ P((y) => y.chat !== d || mn(y, f) ? y : f);
3506
3506
  }, c = [
3507
3507
  d["~registerMessagesCallback"](w, s),
3508
3508
  d["~registerStatusCallback"](w),
@@ -3586,17 +3586,17 @@ function hn(t, e) {
3586
3586
  });
3587
3587
  return n.length === t.length && n.every((r, s) => r === t[s]) ? t : n;
3588
3588
  }
3589
- const gi = L.union([
3590
- L.string(),
3591
- L.looseObject({ id: L.string().optional(), label: L.string() })
3592
- ]), hi = L.looseObject({
3593
- id: L.string().optional(),
3594
- prompt: L.string(),
3595
- selection: L.enum(["single", "multiple"]).default("single"),
3596
- options: L.array(gi).min(1)
3597
- }), yi = L.looseObject({
3598
- request_id: L.string().optional(),
3599
- questions: L.array(hi).min(1)
3589
+ const gi = D.union([
3590
+ D.string(),
3591
+ D.looseObject({ id: D.string().optional(), label: D.string() })
3592
+ ]), hi = D.looseObject({
3593
+ id: D.string().optional(),
3594
+ prompt: D.string(),
3595
+ selection: D.enum(["single", "multiple"]).default("single"),
3596
+ options: D.array(gi).min(1)
3597
+ }), yi = D.looseObject({
3598
+ request_id: D.string().optional(),
3599
+ questions: D.array(hi).min(1)
3600
3600
  });
3601
3601
  function vi(t) {
3602
3602
  return !!(t != null && t.includes("ask_questions"));
@@ -3669,17 +3669,17 @@ A: ${s.trim()}`);
3669
3669
 
3670
3670
  `);
3671
3671
  }
3672
- const Ci = L.object({
3673
- request_id: L.string().uuid(),
3674
- server_id: L.string().uuid(),
3675
- name: L.string().min(1).max(120)
3676
- }), wi = L.object({
3672
+ const Ci = D.object({
3673
+ request_id: D.string().uuid(),
3674
+ server_id: D.string().uuid(),
3675
+ name: D.string().min(1).max(120)
3676
+ }), wi = D.object({
3677
3677
  connection_required: Ci
3678
- }), vn = "data-spec", Ai = L.object({ label: L.string(), done: L.boolean() }), xi = L.object({
3679
- plan: L.array(
3680
- L.object({
3681
- step: L.string(),
3682
- status: L.enum(["pending", "in_progress", "completed"])
3678
+ }), vn = "data-spec", Ai = D.object({ label: D.string(), done: D.boolean() }), xi = D.object({
3679
+ plan: D.array(
3680
+ D.object({
3681
+ step: D.string(),
3682
+ status: D.enum(["pending", "in_progress", "completed"])
3683
3683
  })
3684
3684
  )
3685
3685
  });
@@ -3822,7 +3822,7 @@ class Ni extends yt {
3822
3822
  }
3823
3823
  /** The recovered stream; otherwise the original error is rethrown. */
3824
3824
  async readThroughRecoveryFetch(e, n, r) {
3825
- var l, u, y, g, i;
3825
+ var l, u, h, g, i;
3826
3826
  if (!ft.isInstance(e)) throw e;
3827
3827
  const s = (u = (l = this.agentOptions).recoveryFetch) == null ? void 0 : u.call(l);
3828
3828
  if (!s) throw e;
@@ -3835,7 +3835,7 @@ class Ni extends yt {
3835
3835
  )
3836
3836
  });
3837
3837
  for (const d of Ri) {
3838
- if (await Pi(d, r.abortSignal), (y = r.abortSignal) != null && y.aborted) throw e;
3838
+ if (await Pi(d, r.abortSignal), (h = r.abortSignal) != null && h.aborted) throw e;
3839
3839
  let p;
3840
3840
  try {
3841
3841
  p = await o.reconnectToStream(r);
@@ -3848,10 +3848,10 @@ class Ni extends yt {
3848
3848
  throw e;
3849
3849
  }
3850
3850
  }
3851
- function Di(t) {
3851
+ function Li(t) {
3852
3852
  return new Ni(t);
3853
3853
  }
3854
- function Li({
3854
+ function Di({
3855
3855
  existing: t,
3856
3856
  fetched: e,
3857
3857
  refreshItems: n = !1
@@ -3861,16 +3861,16 @@ function Li({
3861
3861
  ), s = /* @__PURE__ */ new Set(), o = [];
3862
3862
  for (const u of e.turns) {
3863
3863
  if (s.add(u.turn_id), u.message_uuids.length === 0) continue;
3864
- const y = r.get(u.turn_id);
3865
- if (y && !n) {
3866
- ki(y.rowIds, u.message_uuids) ? o.push(y) : o.push({ ...y, rowIds: u.message_uuids });
3864
+ const h = r.get(u.turn_id);
3865
+ if (h && !n) {
3866
+ ki(h.rowIds, u.message_uuids) ? o.push(h) : o.push({ ...h, rowIds: u.message_uuids });
3867
3867
  continue;
3868
3868
  }
3869
3869
  if (u.ui_parts !== null) {
3870
3870
  const g = pt(u.ui_parts);
3871
3871
  if (g.length === 0) continue;
3872
3872
  o.push({
3873
- key: (y == null ? void 0 : y.key) ?? `turn-${u.turn_id}`,
3873
+ key: (h == null ? void 0 : h.key) ?? `turn-${u.turn_id}`,
3874
3874
  turnId: u.turn_id,
3875
3875
  rowIds: u.message_uuids,
3876
3876
  items: g
@@ -3879,7 +3879,7 @@ function Li({
3879
3879
  }
3880
3880
  for (const u of t)
3881
3881
  s.has(u.turnId) || o.push(u);
3882
- return o.length === t.length && o.every((u, y) => u === t[y]) ? t : o;
3882
+ return o.length === t.length && o.every((u, h) => u === t[h]) ? t : o;
3883
3883
  }
3884
3884
  const ki = (t, e) => t.length === e.length && t.every((n, r) => n === e[r]), ji = (t) => Array.isArray(t) && t.every((e) => typeof e == "string");
3885
3885
  function In(t) {
@@ -3940,11 +3940,11 @@ function Vi({
3940
3940
  l.current = e;
3941
3941
  const {
3942
3942
  pageContext: u,
3943
- clientTools: y,
3943
+ clientTools: h,
3944
3944
  pageActions: g
3945
3945
  } = t.features, i = R(() => {
3946
3946
  }), d = X(
3947
- () => Di({
3947
+ () => Li({
3948
3948
  ...s.getStreamTransportOptions(),
3949
3949
  headers: () => s.getStreamTransportOptions().headers,
3950
3950
  reconnectApi: (v) => _i(
@@ -3975,10 +3975,10 @@ function Vi({
3975
3975
  }), {
3976
3976
  status: m,
3977
3977
  messages: f,
3978
- sendMessage: h,
3978
+ sendMessage: y,
3979
3979
  stop: S,
3980
3980
  error: N,
3981
- clearError: D,
3981
+ clearError: L,
3982
3982
  resumeStream: B
3983
3983
  } = mi({
3984
3984
  id: n ?? M,
@@ -4067,10 +4067,10 @@ function Vi({
4067
4067
  return;
4068
4068
  }
4069
4069
  const T = xe.current === "submitted" || xe.current === "streaming" || qe.current === "submitted" || qe.current === "streaming" || $.current === "in-flight";
4070
- C.current += 1, x.current = 0, O.current = Promise.resolve(), k.current = new gn(Cn), $.current = "idle", Ie(!1), we.current = null, Ae.current = null, Ue.current = null, b(null), P.current = !1, Ct.current = null, Et.current = m === "submitted" || m === "streaming" ? m : null, qe.current = "ready", xe.current = "ready", D(), ae((A) => A + 1), de(!1), U([]), Re(null), T && Promise.resolve().then(() => v()).catch((A) => {
4070
+ C.current += 1, x.current = 0, O.current = Promise.resolve(), k.current = new gn(Cn), $.current = "idle", Ie(!1), we.current = null, Ae.current = null, Ue.current = null, b(null), P.current = !1, Ct.current = null, Et.current = m === "submitted" || m === "streaming" ? m : null, qe.current = "ready", xe.current = "ready", L(), ae((A) => A + 1), de(!1), U([]), Re(null), T && Promise.resolve().then(() => v()).catch((A) => {
4071
4071
  le.error("agent chat client stream cancel failed", A);
4072
4072
  });
4073
- }, [n, m, S, D, Re]), F(() => {
4073
+ }, [n, m, S, L, Re]), F(() => {
4074
4074
  var j, Y;
4075
4075
  const v = Et.current;
4076
4076
  if (v !== null && m === v) {
@@ -4103,7 +4103,7 @@ function Vi({
4103
4103
  }
4104
4104
  if ($.current !== "idle" || !n || fe.current && m !== "error") return;
4105
4105
  const A = k.current.dequeueNext();
4106
- A && ($.current = "in-flight", Ie(!1), we.current = A, Ae.current = null, b(null), P.current = !1, Re(`turn-${A.userMessage.id}`), o.appendUserMessageIfAbsent(A.userMessage), ae((Z) => Z + 1), h(
4106
+ A && ($.current = "in-flight", Ie(!1), we.current = A, Ae.current = null, b(null), P.current = !1, Re(`turn-${A.userMessage.id}`), o.appendUserMessageIfAbsent(A.userMessage), ae((Z) => Z + 1), y(
4107
4107
  { text: A.userMessage.content },
4108
4108
  { body: Kt(A) }
4109
4109
  ));
@@ -4111,7 +4111,7 @@ function Vi({
4111
4111
  m,
4112
4112
  n,
4113
4113
  ve,
4114
- h,
4114
+ y,
4115
4115
  o,
4116
4116
  t,
4117
4117
  Kt,
@@ -4161,8 +4161,8 @@ function Vi({
4161
4161
  le.warn("agent chat queue full; retry not enqueued");
4162
4162
  return;
4163
4163
  }
4164
- E && o.setMessageOptionPick(E.messageId, E.optionId), D(), ae((Z) => Z + 1);
4165
- }, [D, o, r]), Ar = z(
4164
+ E && o.setMessageOptionPick(E.messageId, E.optionId), L(), ae((Z) => Z + 1);
4165
+ }, [L, o, r]), Ar = z(
4166
4166
  (v) => {
4167
4167
  const E = k.current.removeWhere(
4168
4168
  (T) => T.userMessage.id === v
@@ -4210,7 +4210,7 @@ function Vi({
4210
4210
  const Z = v === void 0 ? await s.getAgentTurnMessages(n) : await s.getAgentTurnMessages(n, v);
4211
4211
  if (!Z || A) return;
4212
4212
  Ce(Z.handled_connection_request_ids), U(
4213
- (re) => Li({ existing: re, fetched: Z, refreshItems: T })
4213
+ (re) => Di({ existing: re, fetched: Z, refreshItems: T })
4214
4214
  );
4215
4215
  } catch (Z) {
4216
4216
  le.error("agent chat turn sources fetch failed", Z);
@@ -4238,12 +4238,12 @@ function Vi({
4238
4238
  return E;
4239
4239
  }, [f, n, m, Se]), Mr = X(
4240
4240
  () => at.filter(
4241
- (v) => u && y && (v.type !== "act-on-page" || g) && !wt.has(v.key)
4241
+ (v) => u && h && (v.type !== "act-on-page" || g) && !wt.has(v.key)
4242
4242
  ),
4243
4243
  [
4244
4244
  at,
4245
4245
  u,
4246
- y,
4246
+ h,
4247
4247
  g,
4248
4248
  wt
4249
4249
  ]
@@ -4289,11 +4289,11 @@ function Vi({
4289
4289
  }, []);
4290
4290
  F(() => {
4291
4291
  for (const v of at)
4292
- u && y && (v.type !== "act-on-page" || g) || (Mt(v.callId, !1), At.current.has(v.key) || xt(v.callId, "declined"));
4292
+ u && h && (v.type !== "act-on-page" || g) || (Mt(v.callId, !1), At.current.has(v.key) || xt(v.callId, "declined"));
4293
4293
  }, [
4294
4294
  at,
4295
4295
  u,
4296
- y,
4296
+ h,
4297
4297
  g,
4298
4298
  Mt,
4299
4299
  xt
@@ -4319,13 +4319,13 @@ function Vi({
4319
4319
  }
4320
4320
  if (A || Ae.current !== v) return;
4321
4321
  if (be == null ? void 0 : be.turns.some(
4322
- (lt) => (lt.input_message_uuids ?? []).includes(E) && lt.message_uuids.some((Lr) => T.has(Lr))
4322
+ (lt) => (lt.input_message_uuids ?? []).includes(E) && lt.message_uuids.some((Dr) => T.has(Dr))
4323
4323
  )) {
4324
- Ae.current = null, v.kind === "send" && o.markUserMessageDelivered(v.bubbleId), D();
4324
+ Ae.current = null, v.kind === "send" && o.markUserMessageDelivered(v.bubbleId), L();
4325
4325
  return;
4326
4326
  }
4327
- const [en, ...Dr] = re;
4328
- en !== void 0 && (j = setTimeout(() => void Y(Dr), en));
4327
+ const [en, ...Lr] = re;
4328
+ en !== void 0 && (j = setTimeout(() => void Y(Lr), en));
4329
4329
  };
4330
4330
  return Y(qi), () => {
4331
4331
  A = !0, j !== void 0 && clearTimeout(j);
@@ -4337,7 +4337,7 @@ function Vi({
4337
4337
  n,
4338
4338
  s,
4339
4339
  o,
4340
- D
4340
+ L
4341
4341
  ]), F(
4342
4342
  () => () => {
4343
4343
  Te.current.forEach((v) => v(!1)), Te.current.clear();
@@ -4481,36 +4481,36 @@ function Hi({
4481
4481
  widgetCtx: n,
4482
4482
  onHandled: r
4483
4483
  }) {
4484
- const [s, o] = J("idle"), [l, u] = J(null), [y, g] = J(
4484
+ const [s, o] = J("idle"), [l, u] = J(null), [h, g] = J(
4485
4485
  null
4486
4486
  ), [i, d] = J(null), p = R(new AbortController()), b = R(null), P = R(/* @__PURE__ */ new Set()), M = R(null), O = R(null), x = R(null), C = R(!0), I = R((e == null ? void 0 : e.request_id) ?? null);
4487
4487
  I.current = (e == null ? void 0 : e.request_id) ?? null;
4488
4488
  const w = z(() => {
4489
- var D;
4490
- p.current.abort(), (D = b.current) == null || D.close(), b.current = null;
4489
+ var L;
4490
+ p.current.abort(), (L = b.current) == null || L.close(), b.current = null;
4491
4491
  }, []);
4492
4492
  F(() => (w(), x.current = null, O.current = null, M.current = null, o("idle"), u(null), g(null), d(null), w), [w, e == null ? void 0 : e.request_id, e == null ? void 0 : e.server_id, n]), F(() => (C.current = !0, () => {
4493
4493
  C.current = !1, w();
4494
4494
  }), [w]);
4495
4495
  const c = z(
4496
- async (D) => {
4496
+ async (L) => {
4497
4497
  if (!e) return;
4498
4498
  const B = e.request_id;
4499
4499
  if (P.current.has(B)) return;
4500
- P.current.add(B), M.current = D, g(D), d(null);
4500
+ P.current.add(B), M.current = L, g(L), d(null);
4501
4501
  let W = !1;
4502
4502
  try {
4503
4503
  await n.messageCtx.sendMessage({
4504
- ...Ji(e, D),
4504
+ ...Ji(e, L),
4505
4505
  onAccepted: () => {
4506
4506
  W = !0, r(e.request_id);
4507
4507
  }
4508
4508
  }), C.current && I.current === B && !W && d(
4509
- D === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
4509
+ L === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
4510
4510
  );
4511
4511
  } catch {
4512
4512
  C.current && I.current === B && d(
4513
- D === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
4513
+ L === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
4514
4514
  );
4515
4515
  } finally {
4516
4516
  P.current.delete(B), C.current && I.current === B && g(null);
@@ -4521,16 +4521,16 @@ function Hi({
4521
4521
  var B, W;
4522
4522
  if (!e) return;
4523
4523
  w(), x.current = e.request_id, p.current = new AbortController();
4524
- const { signal: D } = p.current;
4524
+ const { signal: L } = p.current;
4525
4525
  o("loading"), M.current = null, u(null), d(null);
4526
4526
  try {
4527
4527
  b.current = window.open("about:blank", "_blank"), b.current && (b.current.opener = null);
4528
4528
  const k = await n.api.startConnection(
4529
4529
  e.server_id,
4530
4530
  e.request_id,
4531
- D
4531
+ L
4532
4532
  );
4533
- if (D.aborted) return;
4533
+ if (L.aborted) return;
4534
4534
  const $ = new URL(k.authorization_url);
4535
4535
  if (!($.protocol === "https:" || $.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes($.hostname)) || $.username || $.password)
4536
4536
  throw new Error("Invalid connection page");
@@ -4541,7 +4541,7 @@ function Hi({
4541
4541
  ...k.completion === "oauth" ? { attemptId: k.attempt_id } : {}
4542
4542
  }), O.current = Date.now() + An, (B = b.current) != null && B.closed ? (b.current = null, o("ready")) : b.current ? (b.current.location.replace($.href), o("waiting")) : o("ready");
4543
4543
  } catch (k) {
4544
- if (D.aborted) return;
4544
+ if (L.aborted) return;
4545
4545
  if ((W = b.current) == null || W.close(), b.current = null, u(null), o("idle"), k instanceof zr) {
4546
4546
  await c("renew");
4547
4547
  return;
@@ -4554,7 +4554,7 @@ function Hi({
4554
4554
  F(() => {
4555
4555
  if (s !== "waiting" && s !== "ready" || !l || !e)
4556
4556
  return;
4557
- const D = new AbortController();
4557
+ const L = new AbortController();
4558
4558
  let B;
4559
4559
  const W = O.current ?? Date.now() + An;
4560
4560
  O.current = W;
@@ -4567,7 +4567,7 @@ function Hi({
4567
4567
  window.addEventListener("blur", Ie), window.addEventListener("focus", ve), document.addEventListener("visibilitychange", ae);
4568
4568
  const G = (U) => {
4569
4569
  var ie;
4570
- D.abort(), (ie = b.current) == null || ie.close(), b.current = null, d(U), o("idle");
4570
+ L.abort(), (ie = b.current) == null || ie.close(), b.current = null, d(U), o("idle");
4571
4571
  }, de = setTimeout(
4572
4572
  () => G("Connection timed out. Try again."),
4573
4573
  Math.max(0, W - Date.now())
@@ -4595,9 +4595,9 @@ function Hi({
4595
4595
  const me = await n.api.getConnectionAttempt(
4596
4596
  e.server_id,
4597
4597
  l.attemptId,
4598
- D.signal
4598
+ L.signal
4599
4599
  );
4600
- if (D.signal.aborted) return;
4600
+ if (L.signal.aborted) return;
4601
4601
  if (k = 0, me === "connected") {
4602
4602
  (ie = b.current) == null || ie.close(), b.current = null, o("connected");
4603
4603
  return;
@@ -4616,7 +4616,7 @@ function Hi({
4616
4616
  }
4617
4617
  (Ce = b.current) != null && Ce.closed && (b.current = null, o("ready")), fe();
4618
4618
  } catch (me) {
4619
- if (D.signal.aborted) return;
4619
+ if (L.signal.aborted) return;
4620
4620
  if (me instanceof Zr) {
4621
4621
  G(me.message);
4622
4622
  return;
@@ -4630,17 +4630,17 @@ function Hi({
4630
4630
  }
4631
4631
  };
4632
4632
  return Ee(), () => {
4633
- D.abort(), B && clearTimeout(B), de && clearTimeout(de), window.removeEventListener("blur", Ie), window.removeEventListener("focus", ve), document.removeEventListener("visibilitychange", ae);
4633
+ L.abort(), B && clearTimeout(B), de && clearTimeout(de), window.removeEventListener("blur", Ie), window.removeEventListener("focus", ve), document.removeEventListener("visibilitychange", ae);
4634
4634
  };
4635
4635
  }, [l, s, e, n]), F(() => {
4636
4636
  s !== "connected" && s !== "external" || x.current !== (e == null ? void 0 : e.request_id) || c(s === "external" ? "external" : "resume");
4637
4637
  }, [s, e == null ? void 0 : e.request_id, c]);
4638
- const f = z(() => o("waiting"), []), h = z(async () => {
4638
+ const f = z(() => o("waiting"), []), y = z(async () => {
4639
4639
  w(), u(null), o("idle"), await c("dismiss");
4640
4640
  }, [w, c]), S = z(async () => {
4641
- const D = M.current;
4642
- if (D) {
4643
- await c(D);
4641
+ const L = M.current;
4642
+ if (L) {
4643
+ await c(L);
4644
4644
  return;
4645
4645
  }
4646
4646
  await m();
@@ -4649,17 +4649,17 @@ function Hi({
4649
4649
  request: e,
4650
4650
  phase: s,
4651
4651
  authorization: l,
4652
- continuation: y,
4652
+ continuation: h,
4653
4653
  error: i,
4654
4654
  start: m,
4655
4655
  opened: f,
4656
- cancel: h,
4656
+ cancel: y,
4657
4657
  retryContinuation: S
4658
4658
  } : null,
4659
4659
  [
4660
4660
  l,
4661
- h,
4662
4661
  y,
4662
+ h,
4663
4663
  i,
4664
4664
  f,
4665
4665
  s,
@@ -4735,7 +4735,7 @@ function Gi({
4735
4735
  isStreaming: o,
4736
4736
  liveItems: l,
4737
4737
  turnSources: u,
4738
- liveTurnKey: y,
4738
+ liveTurnKey: h,
4739
4739
  turnFailed: g,
4740
4740
  retryFailedTurn: i,
4741
4741
  resumeInterruptedTurn: d,
@@ -4754,8 +4754,8 @@ function Gi({
4754
4754
  config: n,
4755
4755
  sessionId: ((ve = r.session) == null ? void 0 : ve.id) ?? null,
4756
4756
  persistedMessages: s.messages
4757
- }), m = ((ae = s.messages.at(-1)) == null ? void 0 : ae.type) === "USER", f = R(/* @__PURE__ */ new Set()), h = R(((G = r.session) == null ? void 0 : G.id) ?? null), S = ((de = r.session) == null ? void 0 : de.id) ?? null;
4758
- h.current !== S && (h.current = S, f.current.clear()), w.forEach(
4757
+ }), m = ((ae = s.messages.at(-1)) == null ? void 0 : ae.type) === "USER", f = R(/* @__PURE__ */ new Set()), y = R(((G = r.session) == null ? void 0 : G.id) ?? null), S = ((de = r.session) == null ? void 0 : de.id) ?? null;
4758
+ y.current !== S && (y.current = S, f.current.clear()), w.forEach(
4759
4759
  (U) => f.current.add(U)
4760
4760
  );
4761
4761
  const N = (fe = [
@@ -4763,7 +4763,7 @@ function Gi({
4763
4763
  ...l
4764
4764
  ].findLast(
4765
4765
  (U) => U.kind === "connection" && !f.current.has(U.request.request_id)
4766
- )) == null ? void 0 : fe.request, [D, B] = J({ sessionId: S, request: null }), W = ((Ee = n.capabilities) == null ? void 0 : Ee.connections) === !0, k = W && S !== null && D.sessionId === S ? D.request : null;
4766
+ )) == null ? void 0 : fe.request, [L, B] = J({ sessionId: S, request: null }), W = ((Ee = n.capabilities) == null ? void 0 : Ee.connections) === !0, k = W && S !== null && L.sessionId === S ? L.request : null;
4767
4767
  F(() => {
4768
4768
  !W || S === null || c !== S || B((U) => {
4769
4769
  const ie = U.sessionId === S && U.request && !f.current.has(U.request.request_id) ? U.request : N ?? null;
@@ -4789,7 +4789,7 @@ function Gi({
4789
4789
  isStreaming: o,
4790
4790
  liveItems: l,
4791
4791
  turnSources: u,
4792
- liveTurnKey: y,
4792
+ liveTurnKey: h,
4793
4793
  turnFailed: g,
4794
4794
  retryFailedTurn: i,
4795
4795
  resumeInterruptedTurn: d,
@@ -4813,7 +4813,7 @@ function Gi({
4813
4813
  o,
4814
4814
  l,
4815
4815
  u,
4816
- y,
4816
+ h,
4817
4817
  g,
4818
4818
  i,
4819
4819
  d,
@@ -4879,14 +4879,14 @@ class Qi {
4879
4879
  if (this.disposed) return;
4880
4880
  const { chats: s, activeId: o } = this.state.get(), l = s.findIndex((d) => d.id === r && !d.closed), u = s[l];
4881
4881
  if (!u) return;
4882
- const y = this.isWorking(u), g = y ? s.map((d) => d.id === r ? { ...d, closed: !0 } : d) : s.filter((d) => d.id !== r);
4882
+ const h = this.isWorking(u), g = h ? s.map((d) => d.id === r ? { ...d, closed: !0 } : d) : s.filter((d) => d.id !== r);
4883
4883
  let i = g.find((d) => d.id === o && !d.closed) ?? g.slice(0, l).reverse().find((d) => !d.closed) ?? g.find((d) => !d.closed);
4884
- i || (i = this.makeChat(this.root.createConversation()), g.push(i)), i.ctx.routerCtx.navigateConversation = this.open, this.root.sessionCtx.trackActiveSession(i.ctx.sessionCtx), this.state.set({ chats: g, activeId: i.id }), y || this.releaseChat(u);
4884
+ i || (i = this.makeChat(this.root.createConversation()), g.push(i)), i.ctx.routerCtx.navigateConversation = this.open, this.root.sessionCtx.trackActiveSession(i.ctx.sessionCtx), this.state.set({ chats: g, activeId: i.id }), h || this.releaseChat(u);
4885
4885
  }, this.canCreateChat = () => !this.disposed && (!this.root.config.oneOpenSessionAllowed || !this.state.get().chats.some(({ ctx: r }) => {
4886
4886
  const { session: s, isCreatingSession: o } = r.sessionCtx.sessionState.get();
4887
4887
  return (s == null ? void 0 : s.isOpened) || o;
4888
4888
  }) && !this.root.sessionCtx.sessionsState.get().data.some((r) => r.isOpened)), this.open = (r) => {
4889
- var y, g, i, d;
4889
+ var h, g, i, d;
4890
4890
  if (this.disposed) return;
4891
4891
  const { chats: s } = this.state.get();
4892
4892
  if (!r && !this.canCreateChat()) return;
@@ -4897,7 +4897,7 @@ class Qi {
4897
4897
  }
4898
4898
  ) : s.find((p) => this.isEmpty(p));
4899
4899
  if (o)
4900
- return this.select(o.id), (g = (y = this.root.config.hooks) == null ? void 0 : y.onNavigateToChat) == null || g.call(y, {
4900
+ return this.select(o.id), (g = (h = this.root.config.hooks) == null ? void 0 : h.onNavigateToChat) == null || g.call(h, {
4901
4901
  session: o.ctx.sessionCtx.sessionState.get().session ?? void 0
4902
4902
  }), o.ctx;
4903
4903
  const l = r ? this.root.sessionCtx.sessionsState.get().data.find((p) => p.id === r) : void 0;
@@ -4967,9 +4967,9 @@ function eo({
4967
4967
  ctx: e,
4968
4968
  workspace: n
4969
4969
  }) {
4970
- const r = pr(), s = Ki(), o = K(e.messageCtx.state), l = K(e.sessionCtx.sessionState), u = K(e.messageCtx.draftState), y = K(e.uploadCtx.state), g = o.messages.find(
4970
+ const r = pr(), s = Ki(), o = K(e.messageCtx.state), l = K(e.sessionCtx.sessionState), u = K(e.messageCtx.draftState), h = K(e.uploadCtx.state), g = o.messages.find(
4971
4971
  (P) => P.type === "USER"
4972
- ), i = (g == null ? void 0 : g.type) === "USER" ? g.content.slice(0, 60) : "", d = r.isStreaming || o.isSendingMessage || l.isCreatingSession, p = !!l.session, b = !!u.text || u.mentions.length > 0 || y.length > 0;
4972
+ ), i = (g == null ? void 0 : g.type) === "USER" ? g.content.slice(0, 60) : "", d = r.isStreaming || o.isSendingMessage || l.isCreatingSession, p = !!l.session, b = !!u.text || u.mentions.length > 0 || h.length > 0;
4973
4973
  return F(
4974
4974
  () => n.update(t, {
4975
4975
  title: i,
@@ -5000,13 +5000,13 @@ function no({
5000
5000
  [t]
5001
5001
  );
5002
5002
  F(() => r.mount(), [r]);
5003
- const { chats: s, activeId: o } = K(r.state), l = s.find((y) => y.id === o), u = X(
5004
- () => s.map((y) => /* @__PURE__ */ H.createElement(
5003
+ const { chats: s, activeId: o } = K(r.state), l = s.find((h) => h.id === o), u = X(
5004
+ () => s.map((h) => /* @__PURE__ */ H.createElement(
5005
5005
  to,
5006
5006
  {
5007
- key: y.id,
5008
- chatId: y.id,
5009
- ctx: y.ctx,
5007
+ key: h.id,
5008
+ chatId: h.id,
5009
+ ctx: h.ctx,
5010
5010
  config: e,
5011
5011
  workspace: r
5012
5012
  }
@@ -5041,17 +5041,17 @@ class ro {
5041
5041
  return (n = this.get(e)) == null ? void 0 : n.component;
5042
5042
  }
5043
5043
  }
5044
- const xn = L.object({
5045
- org_id: L.string(),
5046
- contact: L.object({ id: L.string(), verified: L.boolean() }),
5047
- mcp_access: L.object({
5048
- server_ids: L.array(L.string()),
5049
- account_id: L.string().optional()
5044
+ const xn = D.object({
5045
+ org_id: D.string(),
5046
+ contact: D.object({ id: D.string(), verified: D.boolean() }),
5047
+ mcp_access: D.object({
5048
+ server_ids: D.array(D.string()),
5049
+ account_id: D.string().optional()
5050
5050
  }).optional()
5051
- }), so = L.union([
5052
- L.object({
5053
- sub: L.object({
5054
- type: L.literal("widget-contact"),
5051
+ }), so = D.union([
5052
+ D.object({
5053
+ sub: D.object({
5054
+ type: D.literal("widget-contact"),
5055
5055
  payload: xn
5056
5056
  })
5057
5057
  }).transform(({ sub: t }) => t.payload),
@@ -5108,7 +5108,7 @@ function _o({
5108
5108
  var x;
5109
5109
  const l = R(Promise.resolve()), u = R(t);
5110
5110
  u.current = t;
5111
- const y = io(t), g = R(null), i = R(null), d = R(null), [p, b] = J({ status: "loading" }), P = X(
5111
+ const h = io(t), g = R(null), i = R(null), d = R(null), [p, b] = J({ status: "loading" }), P = X(
5112
5112
  () => new ro({
5113
5113
  components: n
5114
5114
  }),
@@ -5116,7 +5116,7 @@ function _o({
5116
5116
  );
5117
5117
  if (F(() => {
5118
5118
  var w, c, m;
5119
- if (((w = d.current) == null ? void 0 : w.identity) !== y) {
5119
+ if (((w = d.current) == null ? void 0 : w.identity) !== h) {
5120
5120
  const f = (c = d.current) == null ? void 0 : c.widgetCtx.dispose({
5121
5121
  clearActiveSession: !0
5122
5122
  });
@@ -5125,8 +5125,8 @@ function _o({
5125
5125
  }
5126
5126
  ), d.current = null;
5127
5127
  }
5128
- ((m = i.current) == null ? void 0 : m.identity) !== y && (b({ status: "loading" }), i.current = {
5129
- identity: y,
5128
+ ((m = i.current) == null ? void 0 : m.identity) !== h && (b({ status: "loading" }), i.current = {
5129
+ identity: h,
5130
5130
  request: l.current.then(
5131
5131
  () => Vr.initialize({
5132
5132
  config: t,
@@ -5139,8 +5139,8 @@ function _o({
5139
5139
  const C = i.current.request, I = i.current.identity;
5140
5140
  C.then(
5141
5141
  (f) => {
5142
- var h;
5143
- if (((h = i.current) == null ? void 0 : h.request) !== C) {
5142
+ var y;
5143
+ if (((y = i.current) == null ? void 0 : y.request) !== C) {
5144
5144
  f.dispose();
5145
5145
  return;
5146
5146
  }
@@ -5153,15 +5153,15 @@ function _o({
5153
5153
  (f) => {
5154
5154
  var S;
5155
5155
  if (((S = i.current) == null ? void 0 : S.request) !== C) return;
5156
- const h = f instanceof Error ? f : new Error("Widget initialization failed", { cause: f });
5157
- le.error("widget initialization failed", h), b({
5156
+ const y = f instanceof Error ? f : new Error("Widget initialization failed", { cause: f });
5157
+ le.error("widget initialization failed", y), b({
5158
5158
  status: "error",
5159
5159
  identity: I,
5160
- error: h
5160
+ error: y
5161
5161
  });
5162
5162
  }
5163
5163
  );
5164
- }, [y, t, r]), F(
5164
+ }, [h, t, r]), F(
5165
5165
  () => () => {
5166
5166
  var C;
5167
5167
  i.current = null, (C = d.current) == null || C.widgetCtx.dispose(), d.current = null;
@@ -5169,15 +5169,15 @@ function _o({
5169
5169
  []
5170
5170
  ), jr(() => {
5171
5171
  var C;
5172
- p.status !== "ready" || p.identity !== y || (C = t.user) != null && C.token && (p.widgetCtx.api.setAuthToken(t.user.token), p.widgetCtx.tokenRenewalCtx.track(t.user.token));
5173
- }, [(x = t.user) == null ? void 0 : x.token, y, p]), F(() => {
5172
+ p.status !== "ready" || p.identity !== h || (C = t.user) != null && C.token && (p.widgetCtx.api.setAuthToken(t.user.token), p.widgetCtx.tokenRenewalCtx.track(t.user.token));
5173
+ }, [(x = t.user) == null ? void 0 : x.token, h, p]), F(() => {
5174
5174
  if (p.status !== "ready" || typeof document > "u")
5175
5175
  return;
5176
5176
  const C = p.widgetCtx.tokenRenewalCtx, I = () => {
5177
5177
  document.visibilityState === "visible" && C.onVisible();
5178
5178
  };
5179
5179
  return document.addEventListener("visibilitychange", I), () => document.removeEventListener("visibilitychange", I);
5180
- }, [p]), p.status === "loading" || "identity" in p && p.identity !== y)
5180
+ }, [p]), p.status === "loading" || "identity" in p && p.identity !== h)
5181
5181
  return s ? /* @__PURE__ */ H.createElement(H.Fragment, null, s) : null;
5182
5182
  if (p.status === "error")
5183
5183
  return o ? /* @__PURE__ */ H.createElement(H.Fragment, null, o(p.error)) : null;
@@ -5197,7 +5197,7 @@ function _o({
5197
5197
  );
5198
5198
  return t.displayMode === "companion" && !t.inline ? /* @__PURE__ */ H.createElement(no, { widgetCtx: M, config: t }, (C) => O(C, e)) : O(
5199
5199
  M,
5200
- /* @__PURE__ */ H.createElement(fr, { key: y, widgetCtx: M, config: t }, e)
5200
+ /* @__PURE__ */ H.createElement(fr, { key: h, widgetCtx: M, config: t }, e)
5201
5201
  );
5202
5202
  }
5203
5203
  function ne() {
@@ -5248,7 +5248,7 @@ function No() {
5248
5248
  createUnverifiedContact: t.contactCtx.createUnverifiedContact
5249
5249
  };
5250
5250
  }
5251
- function Do() {
5251
+ function Lo() {
5252
5252
  const { widgetCtx: t } = ne(), { ended: e } = K(t.tokenRenewalCtx.state);
5253
5253
  return { sessionEnded: e };
5254
5254
  }
@@ -5301,7 +5301,7 @@ function uo() {
5301
5301
  var t;
5302
5302
  return `${vr}|${((t = yr()) == null ? void 0 : t.location.href) ?? ""}`;
5303
5303
  }
5304
- function Lo() {
5304
+ function Do() {
5305
5305
  return zt(co, uo, () => "");
5306
5306
  }
5307
5307
  function br() {
@@ -5316,11 +5316,11 @@ function br() {
5316
5316
  };
5317
5317
  }
5318
5318
  function Sr() {
5319
- var y;
5319
+ var h;
5320
5320
  const { widgetCtx: t } = ne(), { oneOpenSessionAllowed: e } = It(), n = K(t.sessionCtx.sessionState), r = K(t.sessionCtx.sessionsState), { openSessions: s, closedSessions: o } = X(() => ({
5321
5321
  openSessions: r.data.filter((g) => g.isOpened === !0),
5322
5322
  closedSessions: r.data.filter((g) => g.isOpened === !1)
5323
- }), [r.data]), { workspace: l } = gr(), u = l ? l.canCreateChat() : !e || s.length === 0 && !n.isCreatingSession && !((y = n.session) != null && y.isOpened);
5323
+ }), [r.data]), { workspace: l } = gr(), u = l ? l.canCreateChat() : !e || s.length === 0 && !n.isCreatingSession && !((h = n.session) != null && h.isOpened);
5324
5324
  return {
5325
5325
  sessionState: n,
5326
5326
  sessionsState: r,
@@ -5451,20 +5451,20 @@ function yo({
5451
5451
  const l = Jr(e), u = Hr(
5452
5452
  t,
5453
5453
  l
5454
- ), y = l.join("|"), [g, i] = J(u), [d, p] = J({
5454
+ ), h = l.join("|"), [g, i] = J(u), [d, p] = J({
5455
5455
  defaultLayout: u,
5456
- allowedLayoutsKey: y
5456
+ allowedLayoutsKey: h
5457
5457
  });
5458
- (d.defaultLayout !== u || d.allowedLayoutsKey !== y) && (p({ defaultLayout: u, allowedLayoutsKey: y }), (d.defaultLayout !== u || !l.includes(g)) && i(u));
5459
- const b = (h) => {
5458
+ (d.defaultLayout !== u || d.allowedLayoutsKey !== h) && (p({ defaultLayout: u, allowedLayoutsKey: h }), (d.defaultLayout !== u || !l.includes(g)) && i(u));
5459
+ const b = (y) => {
5460
5460
  i((S) => {
5461
- const N = typeof h == "function" ? h(S) : h;
5461
+ const N = typeof y == "function" ? y(S) : y;
5462
5462
  return l.includes(N) ? N : S;
5463
5463
  });
5464
5464
  }, P = R(l);
5465
5465
  P.current = l;
5466
- const M = (h) => {
5467
- b(h), P.current.includes(h) && ho(h) && (s == null || s.setCompanionLayout(h).catch(() => {
5466
+ const M = (y) => {
5467
+ b(y), P.current.includes(y) && ho(y) && (s == null || s.setCompanionLayout(y).catch(() => {
5468
5468
  }));
5469
5469
  }, [O, x] = J(n), [C, I] = J(r), [w, c] = J({
5470
5470
  side: n,
@@ -5475,29 +5475,29 @@ function yo({
5475
5475
  mode: r
5476
5476
  }), w.side !== n && x(n), w.mode !== r && I(r)), F(() => {
5477
5477
  if (!s) return;
5478
- let h = !1;
5478
+ let y = !1;
5479
5479
  return s.getCompanionLayout().then((S) => {
5480
- h || !S || P.current.includes(S) && i(S);
5480
+ y || !S || P.current.includes(S) && i(S);
5481
5481
  }).catch(() => {
5482
5482
  }), s.getCompanionSidebarSide().then((S) => {
5483
- !h && S && x(S);
5483
+ !y && S && x(S);
5484
5484
  }).catch(() => {
5485
5485
  }), s.getCompanionSidebarMode().then((S) => {
5486
- !h && S && I(S);
5486
+ !y && S && I(S);
5487
5487
  }).catch(() => {
5488
5488
  }), () => {
5489
- h = !0;
5489
+ y = !0;
5490
5490
  };
5491
5491
  }, [s]);
5492
5492
  const m = z(
5493
- (h) => {
5494
- x(h), s == null || s.setCompanionSidebarSide(h).catch(() => {
5493
+ (y) => {
5494
+ x(y), s == null || s.setCompanionSidebarSide(y).catch(() => {
5495
5495
  });
5496
5496
  },
5497
5497
  [s]
5498
5498
  ), f = z(
5499
- (h) => {
5500
- I(h), s == null || s.setCompanionSidebarMode(h).catch(() => {
5499
+ (y) => {
5500
+ I(y), s == null || s.setCompanionSidebarMode(y).catch(() => {
5501
5501
  });
5502
5502
  },
5503
5503
  [s]
@@ -5529,8 +5529,8 @@ function zo() {
5529
5529
  return t;
5530
5530
  }
5531
5531
  function Zo() {
5532
- var u, y;
5533
- const { widgetCtx: t } = ne(), { modesComponents: e } = It(), { sessionState: n } = Sr(), r = t.modes, s = (u = n.session) == null ? void 0 : u.modeId, o = r.find((g) => g.id === s), l = (y = e == null ? void 0 : e.find(
5532
+ var u, h;
5533
+ const { widgetCtx: t } = ne(), { modesComponents: e } = It(), { sessionState: n } = Sr(), r = t.modes, s = (u = n.session) == null ? void 0 : u.modeId, o = r.find((g) => g.id === s), l = (h = e == null ? void 0 : e.find(
5534
5534
  (g) => {
5535
5535
  var i, d;
5536
5536
  return [
@@ -5539,7 +5539,7 @@ function Zo() {
5539
5539
  ((d = o == null ? void 0 : o.slug) == null ? void 0 : d.toLowerCase()) || ""
5540
5540
  ].includes(g.key.toLowerCase());
5541
5541
  }
5542
- )) == null ? void 0 : y.component;
5542
+ )) == null ? void 0 : h.component;
5543
5543
  return {
5544
5544
  modes: r,
5545
5545
  modesComponents: e,
@@ -5548,39 +5548,29 @@ function Zo() {
5548
5548
  Component: l
5549
5549
  };
5550
5550
  }
5551
- function Vo() {
5552
- const { widgetCtx: t } = ne(), {
5553
- messagesState: { messages: e }
5554
- } = br(), {
5555
- csatRequestedMessage: n,
5556
- isCsatRequested: r,
5557
- csatSubmittedMessage: s,
5558
- isCsatSubmitted: o,
5559
- submittedScore: l,
5560
- submittedFeedback: u
5561
- } = X(() => {
5562
- const y = e.find(
5563
- (i) => i.type === "SYSTEM" && i.subtype === "csat_requested"
5564
- ), g = e.findLast(
5565
- (i) => i.type === "SYSTEM" && i.subtype === "csat_submitted"
5566
- );
5567
- return {
5568
- csatRequestedMessage: y,
5569
- isCsatRequested: !!y && !g,
5570
- csatSubmittedMessage: g,
5571
- isCsatSubmitted: !!g,
5572
- submittedScore: g == null ? void 0 : g.data.payload.score,
5573
- submittedFeedback: g == null ? void 0 : g.data.payload.feedback
5574
- };
5575
- }, [e]);
5551
+ function Vo(t = "csat") {
5552
+ const { widgetCtx: e } = ne(), {
5553
+ messagesState: { messages: n }
5554
+ } = br();
5576
5555
  return {
5577
- submitCsat: t.csatCtx.submitCsat,
5578
- csatRequestedMessage: n,
5579
- isCsatRequested: r,
5580
- csatSubmittedMessage: s,
5581
- isCsatSubmitted: o,
5582
- submittedScore: l,
5583
- submittedFeedback: u
5556
+ ...X(() => {
5557
+ var u;
5558
+ const s = n.findLast(
5559
+ (h) => h.type === "SYSTEM" && h.subtype === `${t}_requested`
5560
+ ), o = n.findLast(
5561
+ (h) => h.type === "SYSTEM" && h.subtype === `${t}_submitted`
5562
+ ), l = !!s && (!o || n.indexOf(s) > n.indexOf(o));
5563
+ return {
5564
+ csatRequestedMessage: s,
5565
+ csatSubmittedMessage: o,
5566
+ isCsatRequested: l,
5567
+ isCsatSubmitted: !!o && !l,
5568
+ submittedScore: o == null ? void 0 : o.data.payload.score,
5569
+ submittedFeedback: o == null ? void 0 : o.data.payload.feedback,
5570
+ question: (u = s == null ? void 0 : s.data.payload) == null ? void 0 : u.question
5571
+ };
5572
+ }, [n, t]),
5573
+ submitCsat: (s) => e.csatCtx.submitCsat({ ...s, survey_type: t })
5584
5574
  };
5585
5575
  }
5586
5576
  function Bo(t) {
@@ -5591,8 +5581,8 @@ function Bo(t) {
5591
5581
  getValue: () => s.current.getValue(),
5592
5582
  setValue: (u) => s.current.setValue(u),
5593
5583
  onSend: () => {
5594
- var u, y;
5595
- return (y = (u = s.current).onSend) == null ? void 0 : y.call(u);
5584
+ var u, h;
5585
+ return (h = (u = s.current).onSend) == null ? void 0 : h.call(u);
5596
5586
  }
5597
5587
  });
5598
5588
  }, [n]), l = z(() => {
@@ -5651,13 +5641,13 @@ export {
5651
5641
  Bo as useDictation,
5652
5642
  Oo as useDisplayMode,
5653
5643
  oo as useDocumentDir,
5654
- Lo as useHostLocation,
5644
+ Do as useHostLocation,
5655
5645
  ko as useIsAwaitingBotReply,
5656
5646
  br as useMessages,
5657
5647
  Zo as useModes,
5658
5648
  K as usePrimitiveState,
5659
5649
  Sr as useSessions,
5660
- Do as useTokenRenewal,
5650
+ Lo as useTokenRenewal,
5661
5651
  jo as useUnread,
5662
5652
  Fo as useUnreadViewing,
5663
5653
  Uo as useUploadFiles,