@opencx/widget-react-headless 5.3.0 → 5.4.1

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
@@ -1,13 +1,13 @@
1
- import K, { useSyncExternalStore as Ke, useRef as R, useCallback as U, useEffect as z, useMemo as te, useState as J, createContext as qe, useContext as Ne, memo as ya, useLayoutEffect as ba } from "react";
2
- import { isAgentStreamKeepalive as Ca, isRecord as Sa, genUuid as Et, buildSendMessageBody as Ea, log as ye, resolveClientPresentation as wa, ConnectionRequestExpiredError as Ia, ConnectionAttemptUnavailableError as _a, PrimitiveState as Er, WidgetCtx as Aa, resolveSidebarMode as Ta, resolveSidebarSide as xa, normalizeCompanionLayouts as Ma, resolveCompanionDefaultLayout as Pa } from "@opencx/widget-core";
1
+ import K, { useSyncExternalStore as $e, useRef as O, useCallback as q, useEffect as F, useMemo as te, useState as J, createContext as ze, useContext as Ne, memo as ba, useLayoutEffect as Ca } from "react";
2
+ import { isAgentStreamKeepalive as Sa, isRecord as Er, genUuid as Et, buildSendMessageBody as Ea, log as ye, resolveClientPresentation as wa, ConnectionRequestExpiredError as Ia, ConnectionAttemptUnavailableError as _a, PrimitiveState as wr, WidgetCtx as Aa, resolveSidebarMode as xa, resolveSidebarSide as Ta, normalizeCompanionLayouts as Ma, resolveCompanionDefaultLayout as Pa } from "@opencx/widget-core";
3
3
  import * as Jt from "zod/v4";
4
4
  import { z as o } from "zod/v4";
5
5
  import { ZodFirstPartyTypeKind as P } from "zod/v3";
6
6
  import "react/jsx-runtime";
7
- import { z as N } from "zod";
8
- const Ra = "5.3.0";
9
- function G(t) {
10
- return Ke(t.subscribe, t.get, t.get);
7
+ import { z as j } from "zod";
8
+ const Ra = "5.4.1";
9
+ function H(t) {
10
+ return $e(t.subscribe, t.get, t.get);
11
11
  }
12
12
  function Oa({
13
13
  turnSources: t,
@@ -27,7 +27,7 @@ function Na(t) {
27
27
  }
28
28
  return null;
29
29
  }
30
- var wr = "vercel.ai.error", ja = Symbol.for(wr), Kt, Yt, ge = class Ir extends (Yt = Error, Kt = ja, Yt) {
30
+ var Ir = "vercel.ai.error", ja = Symbol.for(Ir), Kt, Yt, ge = class _r extends (Yt = Error, Kt = ja, Yt) {
31
31
  /**
32
32
  * Creates an AI SDK Error.
33
33
  *
@@ -49,40 +49,40 @@ var wr = "vercel.ai.error", ja = Symbol.for(wr), Kt, Yt, ge = class Ir extends (
49
49
  * @returns {boolean} True if the error is an AI SDK Error, false otherwise.
50
50
  */
51
51
  static isInstance(e) {
52
- return Ir.hasMarker(e, wr);
52
+ return _r.hasMarker(e, Ir);
53
53
  }
54
54
  static hasMarker(e, r) {
55
55
  const a = Symbol.for(r);
56
56
  return e != null && typeof e == "object" && a in e && typeof e[a] == "boolean" && e[a] === !0;
57
57
  }
58
58
  };
59
- function _r(t) {
59
+ function Ar(t) {
60
60
  return t == null ? "unknown error" : typeof t == "string" ? t : t instanceof Error ? t.toString() : JSON.stringify(t);
61
61
  }
62
- var Ar = "AI_InvalidArgumentError", Tr = `vercel.ai.error.${Ar}`, Da = Symbol.for(Tr), Ht, Gt, ka = class extends (Gt = ge, Ht = Da, Gt) {
62
+ var xr = "AI_InvalidArgumentError", Tr = `vercel.ai.error.${xr}`, Da = Symbol.for(Tr), Ht, Gt, ka = class extends (Gt = ge, Ht = Da, Gt) {
63
63
  constructor({
64
64
  message: t,
65
65
  cause: e,
66
66
  argument: r
67
67
  }) {
68
- super({ name: Ar, message: t, cause: e }), this[Ht] = !0, this.argument = r;
68
+ super({ name: xr, message: t, cause: e }), this[Ht] = !0, this.argument = r;
69
69
  }
70
70
  static isInstance(t) {
71
71
  return ge.hasMarker(t, Tr);
72
72
  }
73
- }, xr = "AI_JSONParseError", Mr = `vercel.ai.error.${xr}`, La = Symbol.for(Mr), Qt, Xt, er = class extends (Xt = ge, Qt = La, Xt) {
73
+ }, Mr = "AI_JSONParseError", Pr = `vercel.ai.error.${Mr}`, La = Symbol.for(Pr), Qt, Xt, er = class extends (Xt = ge, Qt = La, Xt) {
74
74
  constructor({ text: t, cause: e }) {
75
75
  super({
76
- name: xr,
76
+ name: Mr,
77
77
  message: `JSON parsing failed: Text: ${t}.
78
- Error message: ${_r(e)}`,
78
+ Error message: ${Ar(e)}`,
79
79
  cause: e
80
80
  }), this[Qt] = !0, this.text = t;
81
81
  }
82
82
  static isInstance(t) {
83
- return ge.hasMarker(t, Mr);
83
+ return ge.hasMarker(t, Pr);
84
84
  }
85
- }, Pr = "AI_TypeValidationError", Rr = `vercel.ai.error.${Pr}`, Fa = Symbol.for(Rr), tr, rr, Ue = class Pt extends (rr = ge, tr = Fa, rr) {
85
+ }, Rr = "AI_TypeValidationError", Or = `vercel.ai.error.${Rr}`, Fa = Symbol.for(Or), tr, rr, qe = class Pt extends (rr = ge, tr = Fa, rr) {
86
86
  constructor({
87
87
  value: e,
88
88
  cause: r,
@@ -95,14 +95,14 @@ Error message: ${_r(e)}`,
95
95
  a.entityName && i.push(a.entityName), a.entityId && i.push(`id: "${a.entityId}"`), n += i.join(", "), n += ")";
96
96
  }
97
97
  super({
98
- name: Pr,
98
+ name: Rr,
99
99
  message: `${n}: Value: ${JSON.stringify(e)}.
100
- Error message: ${_r(r)}`,
100
+ Error message: ${Ar(r)}`,
101
101
  cause: r
102
102
  }), this[tr] = !0, this.value = e, this.context = a;
103
103
  }
104
104
  static isInstance(e) {
105
- return ge.hasMarker(e, Rr);
105
+ return ge.hasMarker(e, Or);
106
106
  }
107
107
  /**
108
108
  * Wraps an error into a TypeValidationError.
@@ -129,7 +129,7 @@ class wt extends Error {
129
129
  super(e), this.name = "ParseError", this.type = r.type, this.field = r.field, this.value = r.value, this.line = r.line;
130
130
  }
131
131
  }
132
- const ar = 10, $a = 13, xe = 32;
132
+ const ar = 10, $a = 13, Te = 32;
133
133
  function It(t) {
134
134
  }
135
135
  function Ua(t) {
@@ -138,8 +138,8 @@ function Ua(t) {
138
138
  "`config` must be an object, got a function instead. Did you mean `createParser({onEvent: fn})`?"
139
139
  );
140
140
  const { onEvent: e = It, onError: r = It, onRetry: a = It, onComment: n, maxBufferSize: i } = t, l = [];
141
- let s = 0, f = !0, c, p = "", d = 0, C, v = !1;
142
- function O(g) {
141
+ let s = 0, f = !0, c, p = "", u = 0, C, v = !1;
142
+ function N(g) {
143
143
  if (v)
144
144
  throw new Error(
145
145
  "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
@@ -161,7 +161,7 @@ function Ua(t) {
161
161
  y !== "" && (l.push(y), s = y.length), I();
162
162
  }
163
163
  function I() {
164
- i !== void 0 && (s + p.length <= i || (v = !0, l.length = 0, s = 0, c = void 0, p = "", d = 0, C = void 0, r(
164
+ i !== void 0 && (s + p.length <= i || (v = !0, l.length = 0, s = 0, c = void 0, p = "", u = 0, C = void 0, r(
165
165
  new wt(`Buffered data exceeded max buffer size of ${i} characters`, {
166
166
  type: "max-buffer-size-exceeded"
167
167
  })
@@ -174,22 +174,22 @@ function Ua(t) {
174
174
  `, m);
175
175
  for (; y !== -1; ) {
176
176
  if (m === y) {
177
- d > 0 && e({ id: c, event: C, data: p }), c = void 0, p = "", d = 0, C = void 0, m = y + 1, y = g.indexOf(`
177
+ u > 0 && e({ id: c, event: C, data: p }), c = void 0, p = "", u = 0, C = void 0, m = y + 1, y = g.indexOf(`
178
178
  `, m);
179
179
  continue;
180
180
  }
181
181
  const h = g.charCodeAt(m);
182
182
  if (nr(g, m, h)) {
183
- const w = g.charCodeAt(m + 5) === xe ? m + 6 : m + 5, k = g.slice(w, y);
184
- if (d === 0 && g.charCodeAt(y + 1) === ar) {
183
+ const w = g.charCodeAt(m + 5) === Te ? m + 6 : m + 5, k = g.slice(w, y);
184
+ if (u === 0 && g.charCodeAt(y + 1) === ar) {
185
185
  e({ id: c, event: C, data: k }), c = void 0, p = "", C = void 0, m = y + 2, y = g.indexOf(`
186
186
  `, m);
187
187
  continue;
188
188
  }
189
- p = d === 0 ? k : `${p}
190
- ${k}`, d++;
189
+ p = u === 0 ? k : `${p}
190
+ ${k}`, u++;
191
191
  } else sr(g, m, h) ? C = g.slice(
192
- g.charCodeAt(m + 6) === xe ? m + 7 : m + 6,
192
+ g.charCodeAt(m + 6) === Te ? m + 7 : m + 6,
193
193
  y
194
194
  ) || void 0 : _(g, m, y);
195
195
  m = y + 1, y = g.indexOf(`
@@ -214,24 +214,24 @@ ${k}`, d++;
214
214
  }
215
215
  const h = g.charCodeAt(m);
216
216
  if (nr(g, m, h)) {
217
- const $ = g.charCodeAt(m + 5) === xe ? m + 6 : m + 5, W = g.slice($, y);
218
- p = d === 0 ? W : `${p}
219
- ${W}`, d++;
217
+ const U = g.charCodeAt(m + 5) === Te ? m + 6 : m + 5, W = g.slice(U, y);
218
+ p = u === 0 ? W : `${p}
219
+ ${W}`, u++;
220
220
  return;
221
221
  }
222
222
  if (sr(g, m, h)) {
223
- C = g.slice(g.charCodeAt(m + 6) === xe ? m + 7 : m + 6, y) || void 0;
223
+ C = g.slice(g.charCodeAt(m + 6) === Te ? m + 7 : m + 6, y) || void 0;
224
224
  return;
225
225
  }
226
226
  if (h === 105 && g.charCodeAt(m + 1) === 100 && g.charCodeAt(m + 2) === 58) {
227
- const $ = g.slice(g.charCodeAt(m + 3) === xe ? m + 4 : m + 3, y);
228
- c = $.includes("\0") ? void 0 : $;
227
+ const U = g.slice(g.charCodeAt(m + 3) === Te ? m + 4 : m + 3, y);
228
+ c = U.includes("\0") ? void 0 : U;
229
229
  return;
230
230
  }
231
231
  if (h === 58) {
232
232
  if (n) {
233
- const $ = g.slice(m, y);
234
- n($.slice(g.charCodeAt(m + 1) === xe ? 2 : 1));
233
+ const U = g.slice(m, y);
234
+ n(U.slice(g.charCodeAt(m + 1) === Te ? 2 : 1));
235
235
  }
236
236
  return;
237
237
  }
@@ -240,7 +240,7 @@ ${W}`, d++;
240
240
  S(w, "", w);
241
241
  return;
242
242
  }
243
- const D = w.slice(0, k), V = w.charCodeAt(k + 1) === xe ? 2 : 1, Z = w.slice(k + V);
243
+ const D = w.slice(0, k), B = w.charCodeAt(k + 1) === Te ? 2 : 1, Z = w.slice(k + B);
244
244
  S(D, Z, w);
245
245
  }
246
246
  function S(g, m, y) {
@@ -249,8 +249,8 @@ ${W}`, d++;
249
249
  C = m || void 0;
250
250
  break;
251
251
  case "data":
252
- p = d === 0 ? m : `${p}
253
- ${m}`, d++;
252
+ p = u === 0 ? m : `${p}
253
+ ${m}`, u++;
254
254
  break;
255
255
  case "id":
256
256
  c = m.includes("\0") ? void 0 : m;
@@ -275,20 +275,20 @@ ${m}`, d++;
275
275
  }
276
276
  }
277
277
  function M() {
278
- d > 0 && e({
278
+ u > 0 && e({
279
279
  id: c,
280
280
  event: C,
281
281
  data: p
282
- }), c = void 0, p = "", d = 0, C = void 0;
282
+ }), c = void 0, p = "", u = 0, C = void 0;
283
283
  }
284
- function u(g = {}) {
284
+ function d(g = {}) {
285
285
  if (g.consume && l.length > 0) {
286
286
  const m = l.join("");
287
287
  _(m, 0, m.length);
288
288
  }
289
- f = !0, c = void 0, p = "", d = 0, C = void 0, l.length = 0, s = 0, v = !1;
289
+ f = !0, c = void 0, p = "", u = 0, C = void 0, l.length = 0, s = 0, v = !1;
290
290
  }
291
- return { feed: O, reset: u };
291
+ return { feed: N, reset: d };
292
292
  }
293
293
  function nr(t, e, r) {
294
294
  return r === 100 && t.charCodeAt(e + 1) === 97 && t.charCodeAt(e + 2) === 116 && t.charCodeAt(e + 3) === 97 && t.charCodeAt(e + 4) === 58;
@@ -360,12 +360,12 @@ function Za(t) {
360
360
  var e, r;
361
361
  return (r = (e = globalThis.Buffer) == null ? void 0 : e.isBuffer(t)) != null ? r : !1;
362
362
  }
363
- var Wa = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/, Ba = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
363
+ var Wa = /"(?:_|\\u005[Ff])(?:_|\\u005[Ff])(?:p|\\u0070)(?:r|\\u0072)(?:o|\\u006[Ff])(?:t|\\u0074)(?:o|\\u006[Ff])(?:_|\\u005[Ff])(?:_|\\u005[Ff])"\s*:/, Va = /"(?:c|\\u0063)(?:o|\\u006[Ff])(?:n|\\u006[Ee])(?:s|\\u0073)(?:t|\\u0074)(?:r|\\u0072)(?:u|\\u0075)(?:c|\\u0063)(?:t|\\u0074)(?:o|\\u006[Ff])(?:r|\\u0072)"\s*:/;
364
364
  function ir(t) {
365
365
  const e = JSON.parse(t);
366
- return e === null || typeof e != "object" || Wa.test(t) === !1 && Ba.test(t) === !1 ? e : Va(e);
366
+ return e === null || typeof e != "object" || Wa.test(t) === !1 && Va.test(t) === !1 ? e : Ba(e);
367
367
  }
368
- function Va(t) {
368
+ function Ba(t) {
369
369
  let e = [t];
370
370
  for (; e.length; ) {
371
371
  const r = e;
@@ -443,7 +443,7 @@ var Ka = /* @__PURE__ */ Symbol(
443
443
  ...or,
444
444
  ...t
445
445
  };
446
- function se() {
446
+ function ie() {
447
447
  return {};
448
448
  }
449
449
  function Ha(t, e) {
@@ -451,7 +451,7 @@ function Ha(t, e) {
451
451
  const i = {
452
452
  type: "array"
453
453
  };
454
- return (r = t.type) != null && r._def && ((n = (a = t.type) == null ? void 0 : a._def) == null ? void 0 : n.typeName) !== P.ZodAny && (i.items = F(t.type._def, {
454
+ return (r = t.type) != null && r._def && ((n = (a = t.type) == null ? void 0 : a._def) == null ? void 0 : n.typeName) !== P.ZodAny && (i.items = $(t.type._def, {
455
455
  ...e,
456
456
  currentPath: [...e.currentPath, "items"]
457
457
  })), t.minLength && (i.minItems = t.minLength.value), t.maxLength && (i.maxItems = t.maxLength.value), t.exactLength && (i.minItems = t.exactLength.value, i.maxItems = t.exactLength.value), i;
@@ -479,15 +479,15 @@ function Ga(t) {
479
479
  function Qa() {
480
480
  return { type: "boolean" };
481
481
  }
482
- function Or(t, e) {
483
- return F(t.type._def, e);
482
+ function Nr(t, e) {
483
+ return $(t.type._def, e);
484
484
  }
485
- var Xa = (t, e) => F(t.innerType._def, e);
486
- function Nr(t, e, r) {
485
+ var Xa = (t, e) => $(t.innerType._def, e);
486
+ function jr(t, e, r) {
487
487
  const a = r ?? e.dateStrategy;
488
488
  if (Array.isArray(a))
489
489
  return {
490
- anyOf: a.map((n) => Nr(t, e, n))
490
+ anyOf: a.map((n) => jr(t, e, n))
491
491
  };
492
492
  switch (a) {
493
493
  case "string":
@@ -523,12 +523,12 @@ var en = (t) => {
523
523
  };
524
524
  function tn(t, e) {
525
525
  return {
526
- ...F(t.innerType._def, e),
526
+ ...$(t.innerType._def, e),
527
527
  default: t.defaultValue()
528
528
  };
529
529
  }
530
530
  function rn(t, e) {
531
- return e.effectStrategy === "input" ? F(t.schema._def, e) : se();
531
+ return e.effectStrategy === "input" ? $(t.schema._def, e) : ie();
532
532
  }
533
533
  function an(t) {
534
534
  return {
@@ -539,11 +539,11 @@ function an(t) {
539
539
  var nn = (t) => "type" in t && t.type === "string" ? !1 : "allOf" in t;
540
540
  function sn(t, e) {
541
541
  const r = [
542
- F(t.left._def, {
542
+ $(t.left._def, {
543
543
  ...e,
544
544
  currentPath: [...e.currentPath, "allOf", "0"]
545
545
  }),
546
- F(t.right._def, {
546
+ $(t.right._def, {
547
547
  ...e,
548
548
  currentPath: [...e.currentPath, "allOf", "1"]
549
549
  })
@@ -615,7 +615,7 @@ var _t = void 0, pe = {
615
615
  nanoid: /^[a-zA-Z0-9_-]{21}$/,
616
616
  jwt: /^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/
617
617
  };
618
- function jr(t, e) {
618
+ function Dr(t, e) {
619
619
  const r = {
620
620
  type: "string"
621
621
  };
@@ -828,17 +828,17 @@ function lr(t, e) {
828
828
  }
829
829
  return i;
830
830
  }
831
- function Dr(t, e) {
831
+ function kr(t, e) {
832
832
  var r, a, n, i, l, s;
833
833
  const f = {
834
834
  type: "object",
835
- additionalProperties: (r = F(t.valueType._def, {
835
+ additionalProperties: (r = $(t.valueType._def, {
836
836
  ...e,
837
837
  currentPath: [...e.currentPath, "additionalProperties"]
838
838
  })) != null ? r : e.allowedAdditionalProperties
839
839
  };
840
840
  if (((a = t.keyType) == null ? void 0 : a._def.typeName) === P.ZodString && ((n = t.keyType._def.checks) != null && n.length)) {
841
- const { type: c, ...p } = jr(t.keyType._def, e);
841
+ const { type: c, ...p } = Dr(t.keyType._def, e);
842
842
  return {
843
843
  ...f,
844
844
  propertyNames: p
@@ -852,7 +852,7 @@ function Dr(t, e) {
852
852
  }
853
853
  };
854
854
  if (((l = t.keyType) == null ? void 0 : l._def.typeName) === P.ZodBranded && t.keyType._def.type._def.typeName === P.ZodString && ((s = t.keyType._def.type._def.checks) != null && s.length)) {
855
- const { type: c, ...p } = Or(
855
+ const { type: c, ...p } = Nr(
856
856
  t.keyType._def,
857
857
  e
858
858
  );
@@ -866,14 +866,14 @@ function Dr(t, e) {
866
866
  }
867
867
  function un(t, e) {
868
868
  if (e.mapStrategy === "record")
869
- return Dr(t, e);
870
- const r = F(t.keyType._def, {
869
+ return kr(t, e);
870
+ const r = $(t.keyType._def, {
871
871
  ...e,
872
872
  currentPath: [...e.currentPath, "items", "items", "0"]
873
- }) || se(), a = F(t.valueType._def, {
873
+ }) || ie(), a = $(t.valueType._def, {
874
874
  ...e,
875
875
  currentPath: [...e.currentPath, "items", "items", "1"]
876
- }) || se();
876
+ }) || ie();
877
877
  return {
878
878
  type: "array",
879
879
  maxItems: 125,
@@ -895,7 +895,7 @@ function dn(t) {
895
895
  };
896
896
  }
897
897
  function pn() {
898
- return { not: se() };
898
+ return { not: ie() };
899
899
  }
900
900
  function fn() {
901
901
  return {
@@ -968,7 +968,7 @@ function mn(t, e) {
968
968
  }
969
969
  var gn = (t, e) => {
970
970
  const r = (t.options instanceof Map ? Array.from(t.options.values()) : t.options).map(
971
- (a, n) => F(a._def, {
971
+ (a, n) => $(a._def, {
972
972
  ...e,
973
973
  currentPath: [...e.currentPath, "anyOf", `${n}`]
974
974
  })
@@ -987,7 +987,7 @@ function hn(t, e) {
987
987
  "null"
988
988
  ]
989
989
  };
990
- const r = F(t.innerType._def, {
990
+ const r = $(t.innerType._def, {
991
991
  ...e,
992
992
  currentPath: [...e.currentPath, "anyOf", "0"]
993
993
  });
@@ -1024,7 +1024,7 @@ function yn(t, e) {
1024
1024
  let s = n[l];
1025
1025
  if (s === void 0 || s._def === void 0)
1026
1026
  continue;
1027
- const f = Cn(s), c = F(s._def, {
1027
+ const f = Cn(s), c = $(s._def, {
1028
1028
  ...e,
1029
1029
  currentPath: [...e.currentPath, "properties", l],
1030
1030
  propertyPath: [...e.currentPath, "properties", l]
@@ -1037,7 +1037,7 @@ function yn(t, e) {
1037
1037
  }
1038
1038
  function bn(t, e) {
1039
1039
  if (t.catchall._def.typeName !== "ZodNever")
1040
- return F(t.catchall._def, {
1040
+ return $(t.catchall._def, {
1041
1041
  ...e,
1042
1042
  currentPath: [...e.currentPath, "additionalProperties"]
1043
1043
  });
@@ -1060,21 +1060,21 @@ function Cn(t) {
1060
1060
  var Sn = (t, e) => {
1061
1061
  var r;
1062
1062
  if (e.currentPath.toString() === ((r = e.propertyPath) == null ? void 0 : r.toString()))
1063
- return F(t.innerType._def, e);
1064
- const a = F(t.innerType._def, {
1063
+ return $(t.innerType._def, e);
1064
+ const a = $(t.innerType._def, {
1065
1065
  ...e,
1066
1066
  currentPath: [...e.currentPath, "anyOf", "1"]
1067
1067
  });
1068
- return a ? { anyOf: [{ not: se() }, a] } : se();
1068
+ return a ? { anyOf: [{ not: ie() }, a] } : ie();
1069
1069
  }, En = (t, e) => {
1070
1070
  if (e.pipeStrategy === "input")
1071
- return F(t.in._def, e);
1071
+ return $(t.in._def, e);
1072
1072
  if (e.pipeStrategy === "output")
1073
- return F(t.out._def, e);
1074
- const r = F(t.in._def, {
1073
+ return $(t.out._def, e);
1074
+ const r = $(t.in._def, {
1075
1075
  ...e,
1076
1076
  currentPath: [...e.currentPath, "allOf", "0"]
1077
- }), a = F(t.out._def, {
1077
+ }), a = $(t.out._def, {
1078
1078
  ...e,
1079
1079
  currentPath: [...e.currentPath, "allOf", r ? "1" : "0"]
1080
1080
  });
@@ -1085,13 +1085,13 @@ var Sn = (t, e) => {
1085
1085
  };
1086
1086
  };
1087
1087
  function wn(t, e) {
1088
- return F(t.type._def, e);
1088
+ return $(t.type._def, e);
1089
1089
  }
1090
1090
  function In(t, e) {
1091
1091
  const a = {
1092
1092
  type: "array",
1093
1093
  uniqueItems: !0,
1094
- items: F(t.valueType._def, {
1094
+ items: $(t.valueType._def, {
1095
1095
  ...e,
1096
1096
  currentPath: [...e.currentPath, "items"]
1097
1097
  })
@@ -1103,7 +1103,7 @@ function _n(t, e) {
1103
1103
  type: "array",
1104
1104
  minItems: t.items.length,
1105
1105
  items: t.items.map(
1106
- (r, a) => F(r._def, {
1106
+ (r, a) => $(r._def, {
1107
1107
  ...e,
1108
1108
  currentPath: [...e.currentPath, "items", `${a}`]
1109
1109
  })
@@ -1111,7 +1111,7 @@ function _n(t, e) {
1111
1111
  (r, a) => a === void 0 ? r : [...r, a],
1112
1112
  []
1113
1113
  ),
1114
- additionalItems: F(t.rest._def, {
1114
+ additionalItems: $(t.rest._def, {
1115
1115
  ...e,
1116
1116
  currentPath: [...e.currentPath, "additionalItems"]
1117
1117
  })
@@ -1120,7 +1120,7 @@ function _n(t, e) {
1120
1120
  minItems: t.items.length,
1121
1121
  maxItems: t.items.length,
1122
1122
  items: t.items.map(
1123
- (r, a) => F(r._def, {
1123
+ (r, a) => $(r._def, {
1124
1124
  ...e,
1125
1125
  currentPath: [...e.currentPath, "items", `${a}`]
1126
1126
  })
@@ -1132,16 +1132,16 @@ function _n(t, e) {
1132
1132
  }
1133
1133
  function An() {
1134
1134
  return {
1135
- not: se()
1135
+ not: ie()
1136
1136
  };
1137
1137
  }
1138
- function Tn() {
1139
- return se();
1138
+ function xn() {
1139
+ return ie();
1140
1140
  }
1141
- var xn = (t, e) => F(t.innerType._def, e), Mn = (t, e, r) => {
1141
+ var Tn = (t, e) => $(t.innerType._def, e), Mn = (t, e, r) => {
1142
1142
  switch (e) {
1143
1143
  case P.ZodString:
1144
- return jr(t, r);
1144
+ return Dr(t, r);
1145
1145
  case P.ZodNumber:
1146
1146
  return vn(t);
1147
1147
  case P.ZodObject:
@@ -1151,7 +1151,7 @@ var xn = (t, e) => F(t.innerType._def, e), Mn = (t, e, r) => {
1151
1151
  case P.ZodBoolean:
1152
1152
  return Qa();
1153
1153
  case P.ZodDate:
1154
- return Nr(t, r);
1154
+ return jr(t, r);
1155
1155
  case P.ZodUndefined:
1156
1156
  return An();
1157
1157
  case P.ZodNull:
@@ -1166,7 +1166,7 @@ var xn = (t, e) => F(t.innerType._def, e), Mn = (t, e, r) => {
1166
1166
  case P.ZodTuple:
1167
1167
  return _n(t, r);
1168
1168
  case P.ZodRecord:
1169
- return Dr(t, r);
1169
+ return kr(t, r);
1170
1170
  case P.ZodLiteral:
1171
1171
  return on(t);
1172
1172
  case P.ZodEnum:
@@ -1191,15 +1191,15 @@ var xn = (t, e) => F(t.innerType._def, e), Mn = (t, e, r) => {
1191
1191
  case P.ZodEffects:
1192
1192
  return rn(t, r);
1193
1193
  case P.ZodAny:
1194
- return se();
1194
+ return ie();
1195
1195
  case P.ZodUnknown:
1196
- return Tn();
1196
+ return xn();
1197
1197
  case P.ZodDefault:
1198
1198
  return tn(t, r);
1199
1199
  case P.ZodBranded:
1200
- return Or(t, r);
1200
+ return Nr(t, r);
1201
1201
  case P.ZodReadonly:
1202
- return xn(t, r);
1202
+ return Tn(t, r);
1203
1203
  case P.ZodCatch:
1204
1204
  return Xa(t, r);
1205
1205
  case P.ZodPipeline:
@@ -1218,7 +1218,7 @@ var xn = (t, e) => F(t.innerType._def, e), Mn = (t, e, r) => {
1218
1218
  ;
1219
1219
  return [(t.length - r).toString(), ...e.slice(r)].join("/");
1220
1220
  };
1221
- function F(t, e, r = !1) {
1221
+ function $(t, e, r = !1) {
1222
1222
  var a;
1223
1223
  const n = e.seen.get(t);
1224
1224
  if (e.override) {
@@ -1239,7 +1239,7 @@ function F(t, e, r = !1) {
1239
1239
  }
1240
1240
  const i = { def: t, path: e.currentPath, jsonSchema: void 0 };
1241
1241
  e.seen.set(t, i);
1242
- const l = Mn(t, t.typeName, e), s = typeof l == "function" ? F(l(), e) : l;
1242
+ const l = Mn(t, t.typeName, e), s = typeof l == "function" ? $(l(), e) : l;
1243
1243
  if (s && On(t, e, s), e.postProcess) {
1244
1244
  const f = e.postProcess(s, t, e);
1245
1245
  return i.jsonSchema = s, f;
@@ -1258,7 +1258,7 @@ var Rn = (t, e) => {
1258
1258
  `Recursive reference detected at ${e.currentPath.join(
1259
1259
  "/"
1260
1260
  )}! Defaulting to any`
1261
- ), se()) : e.$refStrategy === "seen" ? se() : void 0;
1261
+ ), ie()) : e.$refStrategy === "seen" ? ie() : void 0;
1262
1262
  }
1263
1263
  }, On = (t, e, r) => (t.description && (r.description = t.description), r), Nn = (t) => {
1264
1264
  const e = Ya(t), r = e.name !== void 0 ? [...e.basePath, e.definitionPath, e.name] : e.basePath;
@@ -1282,30 +1282,30 @@ var Rn = (t, e) => {
1282
1282
  var r;
1283
1283
  const a = Nn(e);
1284
1284
  let n = typeof e == "object" && e.definitions ? Object.entries(e.definitions).reduce(
1285
- (c, [p, d]) => {
1285
+ (c, [p, u]) => {
1286
1286
  var C;
1287
1287
  return {
1288
1288
  ...c,
1289
- [p]: (C = F(
1290
- d._def,
1289
+ [p]: (C = $(
1290
+ u._def,
1291
1291
  {
1292
1292
  ...a,
1293
1293
  currentPath: [...a.basePath, a.definitionPath, p]
1294
1294
  },
1295
1295
  !0
1296
- )) != null ? C : se()
1296
+ )) != null ? C : ie()
1297
1297
  };
1298
1298
  },
1299
1299
  {}
1300
1300
  ) : void 0;
1301
- const i = typeof e == "string" ? e : (e == null ? void 0 : e.nameStrategy) === "title" || e == null ? void 0 : e.name, l = (r = F(
1301
+ const i = typeof e == "string" ? e : (e == null ? void 0 : e.nameStrategy) === "title" || e == null ? void 0 : e.name, l = (r = $(
1302
1302
  t._def,
1303
1303
  i === void 0 ? a : {
1304
1304
  ...a,
1305
1305
  currentPath: [...a.basePath, a.definitionPath, i]
1306
1306
  },
1307
1307
  !1
1308
- )) != null ? r : se(), s = typeof e == "object" && e.name !== void 0 && e.nameStrategy === "title" ? e.name : void 0;
1308
+ )) != null ? r : ie(), s = typeof e == "object" && e.name !== void 0 && e.nameStrategy === "title" ? e.name : void 0;
1309
1309
  s !== void 0 && (l.title = s);
1310
1310
  const f = i === void 0 ? n ? {
1311
1311
  ...l,
@@ -1348,7 +1348,7 @@ function Ft(t) {
1348
1348
  type: "object",
1349
1349
  properties: {},
1350
1350
  additionalProperties: !1
1351
- }) : kn(t) ? t : "~standard" in t ? t["~standard"].vendor === "zod" ? kr(t) : Ln(t) : t();
1351
+ }) : kn(t) ? t : "~standard" in t ? t["~standard"].vendor === "zod" ? Lr(t) : Ln(t) : t();
1352
1352
  }
1353
1353
  function Ln(t) {
1354
1354
  return ct(
@@ -1368,7 +1368,7 @@ function Ln(t) {
1368
1368
  const r = await t["~standard"].validate(e);
1369
1369
  return "value" in r ? { success: !0, value: r.value } : {
1370
1370
  success: !1,
1371
- error: new Ue({
1371
+ error: new qe({
1372
1372
  value: e,
1373
1373
  cause: r.issues
1374
1374
  })
@@ -1419,7 +1419,7 @@ function Un(t, e) {
1419
1419
  function qn(t) {
1420
1420
  return "_zod" in t;
1421
1421
  }
1422
- function kr(t, e) {
1422
+ function Lr(t, e) {
1423
1423
  return qn(t) ? Un(t) : $n(t);
1424
1424
  }
1425
1425
  async function cr({
@@ -1429,7 +1429,7 @@ async function cr({
1429
1429
  }) {
1430
1430
  const a = await He({ value: t, schema: e, context: r });
1431
1431
  if (!a.success)
1432
- throw Ue.wrap({ value: t, cause: a.error, context: r });
1432
+ throw qe.wrap({ value: t, cause: a.error, context: r });
1433
1433
  return a.value;
1434
1434
  }
1435
1435
  async function He({
@@ -1444,13 +1444,13 @@ async function He({
1444
1444
  const n = await a.validate(t);
1445
1445
  return n.success ? { success: !0, value: n.value, rawValue: t } : {
1446
1446
  success: !1,
1447
- error: Ue.wrap({ value: t, cause: n.error, context: r }),
1447
+ error: qe.wrap({ value: t, cause: n.error, context: r }),
1448
1448
  rawValue: t
1449
1449
  };
1450
1450
  } catch (n) {
1451
1451
  return {
1452
1452
  success: !1,
1453
- error: Ue.wrap({ value: t, cause: n, context: r }),
1453
+ error: qe.wrap({ value: t, cause: n, context: r }),
1454
1454
  rawValue: t
1455
1455
  };
1456
1456
  }
@@ -1489,10 +1489,10 @@ new TextDecoder();
1489
1489
  function Zn(t) {
1490
1490
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
1491
1491
  }
1492
- var Wn = Object.defineProperty, Bn = (t, e) => {
1492
+ var Wn = Object.defineProperty, Vn = (t, e) => {
1493
1493
  for (var r in e)
1494
1494
  Wn(t, r, { get: e[r], enumerable: !0 });
1495
- }, Lr = "AI_NoObjectGeneratedError", Fr = `vercel.ai.error.${Lr}`, Vn = Symbol.for(Fr), $r, Ae = class extends ge {
1495
+ }, Fr = "AI_NoObjectGeneratedError", $r = `vercel.ai.error.${Fr}`, Bn = Symbol.for($r), Ur, Ae = class extends ge {
1496
1496
  constructor({
1497
1497
  message: t = "No object generated.",
1498
1498
  cause: e,
@@ -1501,26 +1501,26 @@ var Wn = Object.defineProperty, Bn = (t, e) => {
1501
1501
  usage: n,
1502
1502
  finishReason: i
1503
1503
  }) {
1504
- super({ name: Lr, message: t, cause: e }), this[$r] = !0, this.text = r, this.response = a, this.usage = n, this.finishReason = i;
1504
+ super({ name: Fr, message: t, cause: e }), this[Ur] = !0, this.text = r, this.response = a, this.usage = n, this.finishReason = i;
1505
1505
  }
1506
1506
  static isInstance(t) {
1507
- return ge.hasMarker(t, Fr);
1507
+ return ge.hasMarker(t, $r);
1508
1508
  }
1509
1509
  };
1510
- $r = Vn;
1511
- var Ur = "AI_UIMessageStreamError", qr = `vercel.ai.error.${Ur}`, Jn = Symbol.for(qr), zr, Pe = class extends ge {
1510
+ Ur = Bn;
1511
+ var qr = "AI_UIMessageStreamError", zr = `vercel.ai.error.${qr}`, Jn = Symbol.for(zr), Zr, Pe = class extends ge {
1512
1512
  constructor({
1513
1513
  chunkType: t,
1514
1514
  chunkId: e,
1515
1515
  message: r
1516
1516
  }) {
1517
- super({ name: Ur, message: r }), this[zr] = !0, this.chunkType = t, this.chunkId = e;
1517
+ super({ name: qr, message: r }), this[Zr] = !0, this.chunkType = t, this.chunkId = e;
1518
1518
  }
1519
1519
  static isInstance(t) {
1520
- return ge.hasMarker(t, qr);
1520
+ return ge.hasMarker(t, zr);
1521
1521
  }
1522
1522
  };
1523
- zr = Jn;
1523
+ Zr = Jn;
1524
1524
  var Oe = o.lazy(
1525
1525
  () => o.union([
1526
1526
  o.null(),
@@ -1530,7 +1530,7 @@ var Oe = o.lazy(
1530
1530
  o.record(o.string(), Oe.optional()),
1531
1531
  o.array(Oe)
1532
1532
  ])
1533
- ), x = o.record(
1533
+ ), T = o.record(
1534
1534
  o.string(),
1535
1535
  o.record(o.string(), Oe.optional())
1536
1536
  ), Ge = o.union([
@@ -1538,10 +1538,10 @@ var Oe = o.lazy(
1538
1538
  o.instanceof(Uint8Array),
1539
1539
  o.instanceof(ArrayBuffer),
1540
1540
  o.custom(Za, { message: "Must be a Buffer" })
1541
- ]), $t = o.record(o.string(), o.string()), Zr = o.object({
1541
+ ]), $t = o.record(o.string(), o.string()), Wr = o.object({
1542
1542
  type: o.literal("text"),
1543
1543
  text: o.string(),
1544
- providerOptions: x.optional()
1544
+ providerOptions: T.optional()
1545
1545
  }), Kn = o.object({
1546
1546
  type: o.literal("image"),
1547
1547
  image: o.union([
@@ -1550,8 +1550,8 @@ var Oe = o.lazy(
1550
1550
  $t
1551
1551
  ]),
1552
1552
  mediaType: o.string().optional(),
1553
- providerOptions: x.optional()
1554
- }), Wr = o.discriminatedUnion("type", [
1553
+ providerOptions: T.optional()
1554
+ }), Vr = o.discriminatedUnion("type", [
1555
1555
  o.object({ type: o.literal("data"), data: Ge }),
1556
1556
  o.object({ type: o.literal("url"), url: o.instanceof(URL) }),
1557
1557
  o.object({
@@ -1565,22 +1565,22 @@ var Oe = o.lazy(
1565
1565
  ]), Br = o.object({
1566
1566
  type: o.literal("file"),
1567
1567
  data: o.union([
1568
- Wr,
1568
+ Vr,
1569
1569
  Ge,
1570
1570
  o.instanceof(URL),
1571
1571
  $t
1572
1572
  ]),
1573
1573
  filename: o.string().optional(),
1574
1574
  mediaType: o.string(),
1575
- providerOptions: x.optional()
1575
+ providerOptions: T.optional()
1576
1576
  }), Hn = o.object({
1577
1577
  type: o.literal("reasoning"),
1578
1578
  text: o.string(),
1579
- providerOptions: x.optional()
1579
+ providerOptions: T.optional()
1580
1580
  }), Gn = o.object({
1581
1581
  type: o.literal("custom"),
1582
1582
  kind: o.string().transform((t) => t),
1583
- providerOptions: x.optional()
1583
+ providerOptions: T.optional()
1584
1584
  }), Qn = o.object({
1585
1585
  type: o.literal("reasoning-file"),
1586
1586
  data: o.union([
@@ -1589,13 +1589,13 @@ var Oe = o.lazy(
1589
1589
  o.instanceof(URL)
1590
1590
  ]),
1591
1591
  mediaType: o.string(),
1592
- providerOptions: x.optional()
1592
+ providerOptions: T.optional()
1593
1593
  }), Xn = o.object({
1594
1594
  type: o.literal("tool-call"),
1595
1595
  toolCallId: o.string(),
1596
1596
  toolName: o.string(),
1597
1597
  input: o.unknown(),
1598
- providerOptions: x.optional(),
1598
+ providerOptions: T.optional(),
1599
1599
  providerExecuted: o.boolean().optional()
1600
1600
  }), es = o.discriminatedUnion(
1601
1601
  "type",
@@ -1603,27 +1603,27 @@ var Oe = o.lazy(
1603
1603
  o.object({
1604
1604
  type: o.literal("text"),
1605
1605
  value: o.string(),
1606
- providerOptions: x.optional()
1606
+ providerOptions: T.optional()
1607
1607
  }),
1608
1608
  o.object({
1609
1609
  type: o.literal("json"),
1610
1610
  value: Oe,
1611
- providerOptions: x.optional()
1611
+ providerOptions: T.optional()
1612
1612
  }),
1613
1613
  o.object({
1614
1614
  type: o.literal("execution-denied"),
1615
1615
  reason: o.string().optional(),
1616
- providerOptions: x.optional()
1616
+ providerOptions: T.optional()
1617
1617
  }),
1618
1618
  o.object({
1619
1619
  type: o.literal("error-text"),
1620
1620
  value: o.string(),
1621
- providerOptions: x.optional()
1621
+ providerOptions: T.optional()
1622
1622
  }),
1623
1623
  o.object({
1624
1624
  type: o.literal("error-json"),
1625
1625
  value: Oe,
1626
- providerOptions: x.optional()
1626
+ providerOptions: T.optional()
1627
1627
  }),
1628
1628
  o.object({
1629
1629
  type: o.literal("content"),
@@ -1632,14 +1632,14 @@ var Oe = o.lazy(
1632
1632
  o.object({
1633
1633
  type: o.literal("text"),
1634
1634
  text: o.string(),
1635
- providerOptions: x.optional()
1635
+ providerOptions: T.optional()
1636
1636
  }),
1637
1637
  o.object({
1638
1638
  type: o.literal("file"),
1639
- data: Wr,
1639
+ data: Vr,
1640
1640
  mediaType: o.string(),
1641
1641
  filename: o.string().optional(),
1642
- providerOptions: x.optional()
1642
+ providerOptions: T.optional()
1643
1643
  }),
1644
1644
  o.object({
1645
1645
  // Deprecated.
@@ -1647,66 +1647,66 @@ var Oe = o.lazy(
1647
1647
  data: o.string(),
1648
1648
  mediaType: o.string(),
1649
1649
  filename: o.string().optional(),
1650
- providerOptions: x.optional()
1650
+ providerOptions: T.optional()
1651
1651
  }),
1652
1652
  o.object({
1653
1653
  // Deprecated.
1654
1654
  type: o.literal("file-url"),
1655
1655
  url: o.string(),
1656
1656
  mediaType: o.string().optional(),
1657
- providerOptions: x.optional()
1657
+ providerOptions: T.optional()
1658
1658
  }),
1659
1659
  o.object({
1660
1660
  // Deprecated.
1661
1661
  type: o.literal("file-id"),
1662
1662
  fileId: o.union([o.string(), o.record(o.string(), o.string())]),
1663
- providerOptions: x.optional()
1663
+ providerOptions: T.optional()
1664
1664
  }),
1665
1665
  o.object({
1666
1666
  // Deprecated.
1667
1667
  type: o.literal("file-reference"),
1668
1668
  providerReference: o.record(o.string(), o.string()),
1669
- providerOptions: x.optional()
1669
+ providerOptions: T.optional()
1670
1670
  }),
1671
1671
  o.object({
1672
1672
  // Deprecated.
1673
1673
  type: o.literal("image-data"),
1674
1674
  data: o.string(),
1675
1675
  mediaType: o.string(),
1676
- providerOptions: x.optional()
1676
+ providerOptions: T.optional()
1677
1677
  }),
1678
1678
  o.object({
1679
1679
  // Deprecated.
1680
1680
  type: o.literal("image-url"),
1681
1681
  url: o.string(),
1682
- providerOptions: x.optional()
1682
+ providerOptions: T.optional()
1683
1683
  }),
1684
1684
  o.object({
1685
1685
  // Deprecated.
1686
1686
  type: o.literal("image-file-id"),
1687
1687
  fileId: o.union([o.string(), o.record(o.string(), o.string())]),
1688
- providerOptions: x.optional()
1688
+ providerOptions: T.optional()
1689
1689
  }),
1690
1690
  o.object({
1691
1691
  // Deprecated.
1692
1692
  type: o.literal("image-file-reference"),
1693
1693
  providerReference: o.record(o.string(), o.string()),
1694
- providerOptions: x.optional()
1694
+ providerOptions: T.optional()
1695
1695
  }),
1696
1696
  o.object({
1697
1697
  type: o.literal("custom"),
1698
- providerOptions: x.optional()
1698
+ providerOptions: T.optional()
1699
1699
  })
1700
1700
  ])
1701
1701
  )
1702
1702
  })
1703
1703
  ]
1704
- ), Vr = o.object({
1704
+ ), Jr = o.object({
1705
1705
  type: o.literal("tool-result"),
1706
1706
  toolCallId: o.string(),
1707
1707
  toolName: o.string(),
1708
1708
  output: es,
1709
- providerOptions: x.optional()
1709
+ providerOptions: T.optional()
1710
1710
  }), ts = o.object({
1711
1711
  type: o.literal("tool-approval-request"),
1712
1712
  approvalId: o.string(),
@@ -1720,37 +1720,37 @@ var Oe = o.lazy(
1720
1720
  {
1721
1721
  role: o.literal("system"),
1722
1722
  content: o.string(),
1723
- providerOptions: x.optional()
1723
+ providerOptions: T.optional()
1724
1724
  }
1725
1725
  ), ns = o.object({
1726
1726
  role: o.literal("user"),
1727
1727
  content: o.union([
1728
1728
  o.string(),
1729
- o.array(o.union([Zr, Kn, Br]))
1729
+ o.array(o.union([Wr, Kn, Br]))
1730
1730
  ]),
1731
- providerOptions: x.optional()
1731
+ providerOptions: T.optional()
1732
1732
  }), ss = o.object({
1733
1733
  role: o.literal("assistant"),
1734
1734
  content: o.union([
1735
1735
  o.string(),
1736
1736
  o.array(
1737
1737
  o.union([
1738
- Zr,
1738
+ Wr,
1739
1739
  Gn,
1740
1740
  Br,
1741
1741
  Hn,
1742
1742
  Qn,
1743
1743
  Xn,
1744
- Vr,
1744
+ Jr,
1745
1745
  ts
1746
1746
  ])
1747
1747
  )
1748
1748
  ]),
1749
- providerOptions: x.optional()
1749
+ providerOptions: T.optional()
1750
1750
  }), is = o.object({
1751
1751
  role: o.literal("tool"),
1752
- content: o.array(o.union([Vr, rs])),
1753
- providerOptions: x.optional()
1752
+ content: o.array(o.union([Jr, rs])),
1753
+ providerOptions: T.optional()
1754
1754
  });
1755
1755
  o.union([
1756
1756
  as,
@@ -1758,7 +1758,7 @@ o.union([
1758
1758
  ss,
1759
1759
  is
1760
1760
  ]);
1761
- function Jr(t, e) {
1761
+ function Kr(t, e) {
1762
1762
  if (t === void 0 && e === void 0)
1763
1763
  return;
1764
1764
  if (t === void 0)
@@ -1772,7 +1772,7 @@ function Jr(t, e) {
1772
1772
  if (n === void 0)
1773
1773
  continue;
1774
1774
  const i = a in t ? t[a] : void 0, l = n !== null && typeof n == "object" && !Array.isArray(n) && !(n instanceof Date) && !(n instanceof RegExp), s = i != null && typeof i == "object" && !Array.isArray(i) && !(i instanceof Date) && !(i instanceof RegExp);
1775
- l && s ? r[a] = Jr(
1775
+ l && s ? r[a] = Kr(
1776
1776
  i,
1777
1777
  n
1778
1778
  ) : r[a] = n;
@@ -1780,7 +1780,7 @@ function Jr(t, e) {
1780
1780
  return r;
1781
1781
  }
1782
1782
  var os = {};
1783
- Bn(os, {
1783
+ Vn(os, {
1784
1784
  array: () => ds,
1785
1785
  choice: () => ps,
1786
1786
  json: () => fs,
@@ -1793,16 +1793,16 @@ function ls(t) {
1793
1793
  function i(p) {
1794
1794
  return p >= "0" && p <= "9" || p >= "A" && p <= "F" || p >= "a" && p <= "f";
1795
1795
  }
1796
- function l(p, d, C) {
1796
+ function l(p, u, C) {
1797
1797
  switch (p) {
1798
1798
  case '"': {
1799
- r = d, e.pop(), e.push(C), e.push("INSIDE_STRING");
1799
+ r = u, e.pop(), e.push(C), e.push("INSIDE_STRING");
1800
1800
  break;
1801
1801
  }
1802
1802
  case "f":
1803
1803
  case "t":
1804
1804
  case "n": {
1805
- r = d, a = d, e.pop(), e.push(C), e.push("INSIDE_LITERAL");
1805
+ r = u, a = u, e.pop(), e.push(C), e.push("INSIDE_LITERAL");
1806
1806
  break;
1807
1807
  }
1808
1808
  case "-": {
@@ -1819,51 +1819,51 @@ function ls(t) {
1819
1819
  case "7":
1820
1820
  case "8":
1821
1821
  case "9": {
1822
- r = d, e.pop(), e.push(C), e.push("INSIDE_NUMBER");
1822
+ r = u, e.pop(), e.push(C), e.push("INSIDE_NUMBER");
1823
1823
  break;
1824
1824
  }
1825
1825
  case "{": {
1826
- r = d, e.pop(), e.push(C), e.push("INSIDE_OBJECT_START");
1826
+ r = u, e.pop(), e.push(C), e.push("INSIDE_OBJECT_START");
1827
1827
  break;
1828
1828
  }
1829
1829
  case "[": {
1830
- r = d, e.pop(), e.push(C), e.push("INSIDE_ARRAY_START");
1830
+ r = u, e.pop(), e.push(C), e.push("INSIDE_ARRAY_START");
1831
1831
  break;
1832
1832
  }
1833
1833
  }
1834
1834
  }
1835
- function s(p, d) {
1835
+ function s(p, u) {
1836
1836
  switch (p) {
1837
1837
  case ",": {
1838
1838
  e.pop(), e.push("INSIDE_OBJECT_AFTER_COMMA");
1839
1839
  break;
1840
1840
  }
1841
1841
  case "}": {
1842
- r = d, e.pop();
1842
+ r = u, e.pop();
1843
1843
  break;
1844
1844
  }
1845
1845
  }
1846
1846
  }
1847
- function f(p, d) {
1847
+ function f(p, u) {
1848
1848
  switch (p) {
1849
1849
  case ",": {
1850
1850
  e.pop(), e.push("INSIDE_ARRAY_AFTER_COMMA");
1851
1851
  break;
1852
1852
  }
1853
1853
  case "]": {
1854
- r = d, e.pop();
1854
+ r = u, e.pop();
1855
1855
  break;
1856
1856
  }
1857
1857
  }
1858
1858
  }
1859
1859
  for (let p = 0; p < t.length; p++) {
1860
- const d = t[p];
1860
+ const u = t[p];
1861
1861
  switch (e[e.length - 1]) {
1862
1862
  case "ROOT":
1863
- l(d, p, "FINISH");
1863
+ l(u, p, "FINISH");
1864
1864
  break;
1865
1865
  case "INSIDE_OBJECT_START": {
1866
- switch (d) {
1866
+ switch (u) {
1867
1867
  case '"': {
1868
1868
  e.pop(), e.push("INSIDE_OBJECT_KEY");
1869
1869
  break;
@@ -1876,7 +1876,7 @@ function ls(t) {
1876
1876
  break;
1877
1877
  }
1878
1878
  case "INSIDE_OBJECT_AFTER_COMMA": {
1879
- switch (d) {
1879
+ switch (u) {
1880
1880
  case '"': {
1881
1881
  e.pop(), e.push("INSIDE_OBJECT_KEY");
1882
1882
  break;
@@ -1885,7 +1885,7 @@ function ls(t) {
1885
1885
  break;
1886
1886
  }
1887
1887
  case "INSIDE_OBJECT_KEY": {
1888
- switch (d) {
1888
+ switch (u) {
1889
1889
  case '"': {
1890
1890
  e.pop(), e.push("INSIDE_OBJECT_AFTER_KEY");
1891
1891
  break;
@@ -1894,7 +1894,7 @@ function ls(t) {
1894
1894
  break;
1895
1895
  }
1896
1896
  case "INSIDE_OBJECT_AFTER_KEY": {
1897
- switch (d) {
1897
+ switch (u) {
1898
1898
  case ":": {
1899
1899
  e.pop(), e.push("INSIDE_OBJECT_BEFORE_VALUE");
1900
1900
  break;
@@ -1903,15 +1903,15 @@ function ls(t) {
1903
1903
  break;
1904
1904
  }
1905
1905
  case "INSIDE_OBJECT_BEFORE_VALUE": {
1906
- l(d, p, "INSIDE_OBJECT_AFTER_VALUE");
1906
+ l(u, p, "INSIDE_OBJECT_AFTER_VALUE");
1907
1907
  break;
1908
1908
  }
1909
1909
  case "INSIDE_OBJECT_AFTER_VALUE": {
1910
- s(d, p);
1910
+ s(u, p);
1911
1911
  break;
1912
1912
  }
1913
1913
  case "INSIDE_STRING": {
1914
- switch (d) {
1914
+ switch (u) {
1915
1915
  case '"': {
1916
1916
  e.pop(), r = p;
1917
1917
  break;
@@ -1926,20 +1926,20 @@ function ls(t) {
1926
1926
  break;
1927
1927
  }
1928
1928
  case "INSIDE_ARRAY_START": {
1929
- switch (d) {
1929
+ switch (u) {
1930
1930
  case "]": {
1931
1931
  r = p, e.pop();
1932
1932
  break;
1933
1933
  }
1934
1934
  default: {
1935
- r = p, l(d, p, "INSIDE_ARRAY_AFTER_VALUE");
1935
+ r = p, l(u, p, "INSIDE_ARRAY_AFTER_VALUE");
1936
1936
  break;
1937
1937
  }
1938
1938
  }
1939
1939
  break;
1940
1940
  }
1941
1941
  case "INSIDE_ARRAY_AFTER_VALUE": {
1942
- switch (d) {
1942
+ switch (u) {
1943
1943
  case ",": {
1944
1944
  e.pop(), e.push("INSIDE_ARRAY_AFTER_COMMA");
1945
1945
  break;
@@ -1956,19 +1956,19 @@ function ls(t) {
1956
1956
  break;
1957
1957
  }
1958
1958
  case "INSIDE_ARRAY_AFTER_COMMA": {
1959
- l(d, p, "INSIDE_ARRAY_AFTER_VALUE");
1959
+ l(u, p, "INSIDE_ARRAY_AFTER_VALUE");
1960
1960
  break;
1961
1961
  }
1962
1962
  case "INSIDE_STRING_ESCAPE": {
1963
- e.pop(), d === "u" ? (n = 0, e.push("INSIDE_STRING_UNICODE_ESCAPE")) : r = p;
1963
+ e.pop(), u === "u" ? (n = 0, e.push("INSIDE_STRING_UNICODE_ESCAPE")) : r = p;
1964
1964
  break;
1965
1965
  }
1966
1966
  case "INSIDE_STRING_UNICODE_ESCAPE": {
1967
- i(d) && (n++, n === 4 && (e.pop(), r = p));
1967
+ i(u) && (n++, n === 4 && (e.pop(), r = p));
1968
1968
  break;
1969
1969
  }
1970
1970
  case "INSIDE_NUMBER": {
1971
- switch (d) {
1971
+ switch (u) {
1972
1972
  case "0":
1973
1973
  case "1":
1974
1974
  case "2":
@@ -1988,15 +1988,15 @@ function ls(t) {
1988
1988
  case ".":
1989
1989
  break;
1990
1990
  case ",": {
1991
- e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && f(d, p), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && s(d, p);
1991
+ e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && f(u, p), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && s(u, p);
1992
1992
  break;
1993
1993
  }
1994
1994
  case "}": {
1995
- e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && s(d, p);
1995
+ e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" && s(u, p);
1996
1996
  break;
1997
1997
  }
1998
1998
  case "]": {
1999
- e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && f(d, p);
1999
+ e.pop(), e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && f(u, p);
2000
2000
  break;
2001
2001
  }
2002
2002
  default: {
@@ -2008,7 +2008,7 @@ function ls(t) {
2008
2008
  }
2009
2009
  case "INSIDE_LITERAL": {
2010
2010
  const v = t.substring(a, p + 1);
2011
- !"false".startsWith(v) && !"true".startsWith(v) && !"null".startsWith(v) ? (e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" ? s(d, p) : e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && f(d, p)) : r = p;
2011
+ !"false".startsWith(v) && !"true".startsWith(v) && !"null".startsWith(v) ? (e.pop(), e[e.length - 1] === "INSIDE_OBJECT_AFTER_VALUE" ? s(u, p) : e[e.length - 1] === "INSIDE_ARRAY_AFTER_VALUE" && f(u, p)) : r = p;
2012
2012
  break;
2013
2013
  }
2014
2014
  }
@@ -2157,7 +2157,7 @@ var cs = () => ({
2157
2157
  if (s == null || typeof s != "object" || !("elements" in s) || !Array.isArray(s.elements))
2158
2158
  throw new Ae({
2159
2159
  message: "No object generated: response did not match schema.",
2160
- cause: new Ue({
2160
+ cause: new qe({
2161
2161
  value: s,
2162
2162
  cause: "response must be an object with an elements array"
2163
2163
  }),
@@ -2255,7 +2255,7 @@ var cs = () => ({
2255
2255
  if (l == null || typeof l != "object" || !("result" in l) || typeof l.result != "string" || !t.includes(l.result))
2256
2256
  throw new Ae({
2257
2257
  message: "No object generated: response did not match schema.",
2258
- cause: new Ue({
2258
+ cause: new qe({
2259
2259
  value: l,
2260
2260
  cause: "response must be an object that contains a choice value."
2261
2261
  }),
@@ -2349,27 +2349,27 @@ ce({
2349
2349
  });
2350
2350
  }
2351
2351
  });
2352
- var We = o.record(
2352
+ var Ve = o.record(
2353
2353
  o.string(),
2354
2354
  Oe.optional()
2355
2355
  ), ms = Dn(
2356
- () => kr(
2356
+ () => Lr(
2357
2357
  o.union([
2358
2358
  o.strictObject({
2359
2359
  type: o.literal("text-start"),
2360
2360
  id: o.string(),
2361
- providerMetadata: x.optional()
2361
+ providerMetadata: T.optional()
2362
2362
  }),
2363
2363
  o.strictObject({
2364
2364
  type: o.literal("text-delta"),
2365
2365
  id: o.string(),
2366
2366
  delta: o.string(),
2367
- providerMetadata: x.optional()
2367
+ providerMetadata: T.optional()
2368
2368
  }),
2369
2369
  o.strictObject({
2370
2370
  type: o.literal("text-end"),
2371
2371
  id: o.string(),
2372
- providerMetadata: x.optional()
2372
+ providerMetadata: T.optional()
2373
2373
  }),
2374
2374
  o.strictObject({
2375
2375
  type: o.literal("error"),
@@ -2380,8 +2380,8 @@ var We = o.record(
2380
2380
  toolCallId: o.string(),
2381
2381
  toolName: o.string(),
2382
2382
  providerExecuted: o.boolean().optional(),
2383
- providerMetadata: x.optional(),
2384
- toolMetadata: We.optional(),
2383
+ providerMetadata: T.optional(),
2384
+ toolMetadata: Ve.optional(),
2385
2385
  dynamic: o.boolean().optional(),
2386
2386
  title: o.string().optional()
2387
2387
  }),
@@ -2396,8 +2396,8 @@ var We = o.record(
2396
2396
  toolName: o.string(),
2397
2397
  input: o.unknown(),
2398
2398
  providerExecuted: o.boolean().optional(),
2399
- providerMetadata: x.optional(),
2400
- toolMetadata: We.optional(),
2399
+ providerMetadata: T.optional(),
2400
+ toolMetadata: Ve.optional(),
2401
2401
  dynamic: o.boolean().optional(),
2402
2402
  title: o.string().optional()
2403
2403
  }),
@@ -2407,8 +2407,8 @@ var We = o.record(
2407
2407
  toolName: o.string(),
2408
2408
  input: o.unknown(),
2409
2409
  providerExecuted: o.boolean().optional(),
2410
- providerMetadata: x.optional(),
2411
- toolMetadata: We.optional(),
2410
+ providerMetadata: T.optional(),
2411
+ toolMetadata: Ve.optional(),
2412
2412
  dynamic: o.boolean().optional(),
2413
2413
  errorText: o.string(),
2414
2414
  title: o.string().optional()
@@ -2426,15 +2426,15 @@ var We = o.record(
2426
2426
  approved: o.boolean(),
2427
2427
  reason: o.string().optional(),
2428
2428
  providerExecuted: o.boolean().optional(),
2429
- providerMetadata: x.optional()
2429
+ providerMetadata: T.optional()
2430
2430
  }),
2431
2431
  o.strictObject({
2432
2432
  type: o.literal("tool-output-available"),
2433
2433
  toolCallId: o.string(),
2434
2434
  output: o.unknown(),
2435
2435
  providerExecuted: o.boolean().optional(),
2436
- providerMetadata: x.optional(),
2437
- toolMetadata: We.optional(),
2436
+ providerMetadata: T.optional(),
2437
+ toolMetadata: Ve.optional(),
2438
2438
  dynamic: o.boolean().optional(),
2439
2439
  preliminary: o.boolean().optional()
2440
2440
  }),
@@ -2443,8 +2443,8 @@ var We = o.record(
2443
2443
  toolCallId: o.string(),
2444
2444
  errorText: o.string(),
2445
2445
  providerExecuted: o.boolean().optional(),
2446
- providerMetadata: x.optional(),
2447
- toolMetadata: We.optional(),
2446
+ providerMetadata: T.optional(),
2447
+ toolMetadata: Ve.optional(),
2448
2448
  dynamic: o.boolean().optional()
2449
2449
  }),
2450
2450
  o.strictObject({
@@ -2454,30 +2454,30 @@ var We = o.record(
2454
2454
  o.strictObject({
2455
2455
  type: o.literal("reasoning-start"),
2456
2456
  id: o.string(),
2457
- providerMetadata: x.optional()
2457
+ providerMetadata: T.optional()
2458
2458
  }),
2459
2459
  o.strictObject({
2460
2460
  type: o.literal("reasoning-delta"),
2461
2461
  id: o.string(),
2462
2462
  delta: o.string(),
2463
- providerMetadata: x.optional()
2463
+ providerMetadata: T.optional()
2464
2464
  }),
2465
2465
  o.strictObject({
2466
2466
  type: o.literal("reasoning-end"),
2467
2467
  id: o.string(),
2468
- providerMetadata: x.optional()
2468
+ providerMetadata: T.optional()
2469
2469
  }),
2470
2470
  o.strictObject({
2471
2471
  type: o.literal("custom"),
2472
2472
  kind: o.string().transform((t) => t),
2473
- providerMetadata: x.optional()
2473
+ providerMetadata: T.optional()
2474
2474
  }),
2475
2475
  o.strictObject({
2476
2476
  type: o.literal("source-url"),
2477
2477
  sourceId: o.string(),
2478
2478
  url: o.string(),
2479
2479
  title: o.string().optional(),
2480
- providerMetadata: x.optional()
2480
+ providerMetadata: T.optional()
2481
2481
  }),
2482
2482
  o.strictObject({
2483
2483
  type: o.literal("source-document"),
@@ -2485,19 +2485,19 @@ var We = o.record(
2485
2485
  mediaType: o.string(),
2486
2486
  title: o.string(),
2487
2487
  filename: o.string().optional(),
2488
- providerMetadata: x.optional()
2488
+ providerMetadata: T.optional()
2489
2489
  }),
2490
2490
  o.strictObject({
2491
2491
  type: o.literal("file"),
2492
2492
  url: o.string(),
2493
2493
  mediaType: o.string(),
2494
- providerMetadata: x.optional()
2494
+ providerMetadata: T.optional()
2495
2495
  }),
2496
2496
  o.strictObject({
2497
2497
  type: o.literal("reasoning-file"),
2498
2498
  url: o.string(),
2499
2499
  mediaType: o.string(),
2500
- providerMetadata: x.optional()
2500
+ providerMetadata: T.optional()
2501
2501
  }),
2502
2502
  o.strictObject({
2503
2503
  type: o.custom(
@@ -2551,17 +2551,17 @@ function Ye() {
2551
2551
  function Nt(t) {
2552
2552
  return t.type.startsWith("tool-");
2553
2553
  }
2554
- function Kr(t) {
2554
+ function Yr(t) {
2555
2555
  return t.type === "dynamic-tool";
2556
2556
  }
2557
- function $e(t) {
2558
- return Nt(t) || Kr(t);
2557
+ function Ue(t) {
2558
+ return Nt(t) || Yr(t);
2559
2559
  }
2560
2560
  function jt(t) {
2561
2561
  return t.type.split("-").slice(1).join("-");
2562
2562
  }
2563
2563
  function hs(t) {
2564
- return Kr(t) ? t.toolName : jt(t);
2564
+ return Yr(t) ? t.toolName : jt(t);
2565
2565
  }
2566
2566
  function vs({
2567
2567
  lastMessage: t,
@@ -2592,75 +2592,75 @@ function ys({
2592
2592
  new TransformStream({
2593
2593
  async transform(s, f) {
2594
2594
  await a(async ({ state: c, write: p }) => {
2595
- var d, C, v, O;
2596
- function I(u) {
2597
- const m = c.message.parts.filter($e).find(
2598
- (y) => y.toolCallId === u
2595
+ var u, C, v, N;
2596
+ function I(d) {
2597
+ const m = c.message.parts.filter(Ue).find(
2598
+ (y) => y.toolCallId === d
2599
2599
  );
2600
2600
  if (m == null)
2601
2601
  throw new Pe({
2602
2602
  chunkType: "tool-invocation",
2603
- chunkId: u,
2604
- message: `No tool invocation found for tool call ID "${u}".`
2603
+ chunkId: d,
2604
+ message: `No tool invocation found for tool call ID "${d}".`
2605
2605
  });
2606
2606
  return m;
2607
2607
  }
2608
- function E(u) {
2609
- const m = c.message.parts.filter($e).find(
2608
+ function E(d) {
2609
+ const m = c.message.parts.filter(Ue).find(
2610
2610
  (y) => {
2611
2611
  var h;
2612
- return ((h = y.approval) == null ? void 0 : h.id) === u;
2612
+ return ((h = y.approval) == null ? void 0 : h.id) === d;
2613
2613
  }
2614
2614
  );
2615
2615
  if (m == null)
2616
2616
  throw new Pe({
2617
2617
  chunkType: "tool-approval-response",
2618
- chunkId: u,
2619
- message: `No tool invocation found for approval ID "${u}".`
2618
+ chunkId: d,
2619
+ message: `No tool invocation found for approval ID "${d}".`
2620
2620
  });
2621
2621
  return m;
2622
2622
  }
2623
- function _(u) {
2623
+ function _(d) {
2624
2624
  var g;
2625
2625
  const m = c.message.parts.find(
2626
- (w) => Nt(w) && w.toolCallId === u.toolCallId
2627
- ), y = u, h = m;
2626
+ (w) => Nt(w) && w.toolCallId === d.toolCallId
2627
+ ), y = d, h = m;
2628
2628
  if (m != null) {
2629
- m.state = u.state, h.input = y.input, h.output = y.output, h.errorText = y.errorText, h.rawInput = y.rawInput, h.preliminary = y.preliminary, u.title !== void 0 && (h.title = u.title), u.toolMetadata !== void 0 && (h.toolMetadata = u.toolMetadata), h.providerExecuted = (g = y.providerExecuted) != null ? g : m.providerExecuted;
2629
+ m.state = d.state, h.input = y.input, h.output = y.output, h.errorText = y.errorText, h.rawInput = y.rawInput, h.preliminary = y.preliminary, d.title !== void 0 && (h.title = d.title), d.toolMetadata !== void 0 && (h.toolMetadata = d.toolMetadata), h.providerExecuted = (g = y.providerExecuted) != null ? g : m.providerExecuted;
2630
2630
  const w = y.providerMetadata;
2631
2631
  if (w != null)
2632
- if (u.state === "output-available" || u.state === "output-error") {
2632
+ if (d.state === "output-available" || d.state === "output-error") {
2633
2633
  const k = m;
2634
2634
  k.resultProviderMetadata = w;
2635
2635
  } else
2636
2636
  m.callProviderMetadata = w;
2637
2637
  } else
2638
2638
  c.message.parts.push({
2639
- type: `tool-${u.toolName}`,
2640
- toolCallId: u.toolCallId,
2641
- state: u.state,
2642
- title: u.title,
2643
- ...u.toolMetadata !== void 0 ? { toolMetadata: u.toolMetadata } : {},
2639
+ type: `tool-${d.toolName}`,
2640
+ toolCallId: d.toolCallId,
2641
+ state: d.state,
2642
+ title: d.title,
2643
+ ...d.toolMetadata !== void 0 ? { toolMetadata: d.toolMetadata } : {},
2644
2644
  input: y.input,
2645
2645
  output: y.output,
2646
2646
  rawInput: y.rawInput,
2647
2647
  errorText: y.errorText,
2648
2648
  providerExecuted: y.providerExecuted,
2649
2649
  preliminary: y.preliminary,
2650
- ...y.providerMetadata != null && (u.state === "output-available" || u.state === "output-error") ? { resultProviderMetadata: y.providerMetadata } : {},
2651
- ...y.providerMetadata != null && !(u.state === "output-available" || u.state === "output-error") ? { callProviderMetadata: y.providerMetadata } : {}
2650
+ ...y.providerMetadata != null && (d.state === "output-available" || d.state === "output-error") ? { resultProviderMetadata: y.providerMetadata } : {},
2651
+ ...y.providerMetadata != null && !(d.state === "output-available" || d.state === "output-error") ? { callProviderMetadata: y.providerMetadata } : {}
2652
2652
  });
2653
2653
  }
2654
- function S(u) {
2654
+ function S(d) {
2655
2655
  var g, m;
2656
2656
  const y = c.message.parts.find(
2657
- (k) => k.type === "dynamic-tool" && k.toolCallId === u.toolCallId
2658
- ), h = u, w = y;
2657
+ (k) => k.type === "dynamic-tool" && k.toolCallId === d.toolCallId
2658
+ ), h = d, w = y;
2659
2659
  if (y != null) {
2660
- y.state = u.state, w.toolName = u.toolName, w.input = h.input, w.output = h.output, w.errorText = h.errorText, w.rawInput = (g = h.rawInput) != null ? g : w.rawInput, w.preliminary = h.preliminary, u.title !== void 0 && (w.title = u.title), u.toolMetadata !== void 0 && (w.toolMetadata = u.toolMetadata), w.providerExecuted = (m = h.providerExecuted) != null ? m : y.providerExecuted;
2660
+ y.state = d.state, w.toolName = d.toolName, w.input = h.input, w.output = h.output, w.errorText = h.errorText, w.rawInput = (g = h.rawInput) != null ? g : w.rawInput, w.preliminary = h.preliminary, d.title !== void 0 && (w.title = d.title), d.toolMetadata !== void 0 && (w.toolMetadata = d.toolMetadata), w.providerExecuted = (m = h.providerExecuted) != null ? m : y.providerExecuted;
2661
2661
  const k = h.providerMetadata;
2662
2662
  if (k != null)
2663
- if (u.state === "output-available" || u.state === "output-error") {
2663
+ if (d.state === "output-available" || d.state === "output-error") {
2664
2664
  const D = y;
2665
2665
  D.resultProviderMetadata = k;
2666
2666
  } else
@@ -2668,23 +2668,23 @@ function ys({
2668
2668
  } else
2669
2669
  c.message.parts.push({
2670
2670
  type: "dynamic-tool",
2671
- toolName: u.toolName,
2672
- toolCallId: u.toolCallId,
2673
- state: u.state,
2671
+ toolName: d.toolName,
2672
+ toolCallId: d.toolCallId,
2673
+ state: d.state,
2674
2674
  input: h.input,
2675
2675
  output: h.output,
2676
2676
  errorText: h.errorText,
2677
2677
  preliminary: h.preliminary,
2678
2678
  providerExecuted: h.providerExecuted,
2679
- title: u.title,
2680
- ...u.toolMetadata !== void 0 ? { toolMetadata: u.toolMetadata } : {},
2681
- ...h.providerMetadata != null && (u.state === "output-available" || u.state === "output-error") ? { resultProviderMetadata: h.providerMetadata } : {},
2682
- ...h.providerMetadata != null && !(u.state === "output-available" || u.state === "output-error") ? { callProviderMetadata: h.providerMetadata } : {}
2679
+ title: d.title,
2680
+ ...d.toolMetadata !== void 0 ? { toolMetadata: d.toolMetadata } : {},
2681
+ ...h.providerMetadata != null && (d.state === "output-available" || d.state === "output-error") ? { resultProviderMetadata: h.providerMetadata } : {},
2682
+ ...h.providerMetadata != null && !(d.state === "output-available" || d.state === "output-error") ? { callProviderMetadata: h.providerMetadata } : {}
2683
2683
  });
2684
2684
  }
2685
- async function M(u) {
2686
- if (u != null) {
2687
- const g = c.message.metadata != null ? Jr(c.message.metadata, u) : u;
2685
+ async function M(d) {
2686
+ if (d != null) {
2687
+ const g = c.message.metadata != null ? Kr(c.message.metadata, d) : d;
2688
2688
  e != null && await cr({
2689
2689
  value: g,
2690
2690
  schema: e,
@@ -2697,76 +2697,76 @@ function ys({
2697
2697
  }
2698
2698
  switch (s.type) {
2699
2699
  case "text-start": {
2700
- const u = {
2700
+ const d = {
2701
2701
  type: "text",
2702
2702
  text: "",
2703
2703
  providerMetadata: s.providerMetadata,
2704
2704
  state: "streaming"
2705
2705
  };
2706
- c.activeTextParts[s.id] = u, c.message.parts.push(u), p();
2706
+ c.activeTextParts[s.id] = d, c.message.parts.push(d), p();
2707
2707
  break;
2708
2708
  }
2709
2709
  case "text-delta": {
2710
- const u = c.activeTextParts[s.id];
2711
- if (u == null)
2710
+ const d = c.activeTextParts[s.id];
2711
+ if (d == null)
2712
2712
  throw new Pe({
2713
2713
  chunkType: "text-delta",
2714
2714
  chunkId: s.id,
2715
2715
  message: `Received text-delta for missing text part with ID "${s.id}". Ensure a "text-start" chunk is sent before any "text-delta" chunks.`
2716
2716
  });
2717
- u.text += s.delta, u.providerMetadata = (d = s.providerMetadata) != null ? d : u.providerMetadata, p();
2717
+ d.text += s.delta, d.providerMetadata = (u = s.providerMetadata) != null ? u : d.providerMetadata, p();
2718
2718
  break;
2719
2719
  }
2720
2720
  case "text-end": {
2721
- const u = c.activeTextParts[s.id];
2722
- if (u == null)
2721
+ const d = c.activeTextParts[s.id];
2722
+ if (d == null)
2723
2723
  throw new Pe({
2724
2724
  chunkType: "text-end",
2725
2725
  chunkId: s.id,
2726
2726
  message: `Received text-end for missing text part with ID "${s.id}". Ensure a "text-start" chunk is sent before any "text-end" chunks.`
2727
2727
  });
2728
- u.state = "done", u.providerMetadata = (C = s.providerMetadata) != null ? C : u.providerMetadata, delete c.activeTextParts[s.id], p();
2728
+ d.state = "done", d.providerMetadata = (C = s.providerMetadata) != null ? C : d.providerMetadata, delete c.activeTextParts[s.id], p();
2729
2729
  break;
2730
2730
  }
2731
2731
  case "custom": {
2732
- const u = {
2732
+ const d = {
2733
2733
  type: "custom",
2734
2734
  kind: s.kind,
2735
2735
  providerMetadata: s.providerMetadata
2736
2736
  };
2737
- c.message.parts.push(u), p();
2737
+ c.message.parts.push(d), p();
2738
2738
  break;
2739
2739
  }
2740
2740
  case "reasoning-start": {
2741
- const u = {
2741
+ const d = {
2742
2742
  type: "reasoning",
2743
2743
  text: "",
2744
2744
  providerMetadata: s.providerMetadata,
2745
2745
  state: "streaming"
2746
2746
  };
2747
- c.activeReasoningParts[s.id] = u, c.message.parts.push(u), p();
2747
+ c.activeReasoningParts[s.id] = d, c.message.parts.push(d), p();
2748
2748
  break;
2749
2749
  }
2750
2750
  case "reasoning-delta": {
2751
- const u = c.activeReasoningParts[s.id];
2752
- if (u == null)
2751
+ const d = c.activeReasoningParts[s.id];
2752
+ if (d == null)
2753
2753
  throw new Pe({
2754
2754
  chunkType: "reasoning-delta",
2755
2755
  chunkId: s.id,
2756
2756
  message: `Received reasoning-delta for missing reasoning part with ID "${s.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-delta" chunks.`
2757
2757
  });
2758
- u.text += s.delta, u.providerMetadata = (v = s.providerMetadata) != null ? v : u.providerMetadata, p();
2758
+ d.text += s.delta, d.providerMetadata = (v = s.providerMetadata) != null ? v : d.providerMetadata, p();
2759
2759
  break;
2760
2760
  }
2761
2761
  case "reasoning-end": {
2762
- const u = c.activeReasoningParts[s.id];
2763
- if (u == null)
2762
+ const d = c.activeReasoningParts[s.id];
2763
+ if (d == null)
2764
2764
  throw new Pe({
2765
2765
  chunkType: "reasoning-end",
2766
2766
  chunkId: s.id,
2767
2767
  message: `Received reasoning-end for missing reasoning part with ID "${s.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`
2768
2768
  });
2769
- u.providerMetadata = (O = s.providerMetadata) != null ? O : u.providerMetadata, u.state = "done", delete c.activeReasoningParts[s.id], p();
2769
+ d.providerMetadata = (N = s.providerMetadata) != null ? N : d.providerMetadata, d.state = "done", delete c.activeReasoningParts[s.id], p();
2770
2770
  break;
2771
2771
  }
2772
2772
  case "file":
@@ -2801,11 +2801,11 @@ function ys({
2801
2801
  break;
2802
2802
  }
2803
2803
  case "tool-input-start": {
2804
- const u = c.message.parts.filter(Nt);
2804
+ const d = c.message.parts.filter(Nt);
2805
2805
  c.partialToolCalls[s.toolCallId] = {
2806
2806
  text: "",
2807
2807
  toolName: s.toolName,
2808
- index: u.length,
2808
+ index: d.length,
2809
2809
  dynamic: s.dynamic,
2810
2810
  title: s.title,
2811
2811
  toolMetadata: s.toolMetadata
@@ -2831,31 +2831,31 @@ function ys({
2831
2831
  break;
2832
2832
  }
2833
2833
  case "tool-input-delta": {
2834
- const u = c.partialToolCalls[s.toolCallId];
2835
- if (u == null)
2834
+ const d = c.partialToolCalls[s.toolCallId];
2835
+ if (d == null)
2836
2836
  throw new Pe({
2837
2837
  chunkType: "tool-input-delta",
2838
2838
  chunkId: s.toolCallId,
2839
2839
  message: `Received tool-input-delta for missing tool call with ID "${s.toolCallId}". Ensure a "tool-input-start" chunk is sent before any "tool-input-delta" chunks.`
2840
2840
  });
2841
- u.text += s.inputTextDelta;
2841
+ d.text += s.inputTextDelta;
2842
2842
  const { value: g } = await Qe(
2843
- u.text
2843
+ d.text
2844
2844
  );
2845
- u.dynamic ? S({
2845
+ d.dynamic ? S({
2846
2846
  toolCallId: s.toolCallId,
2847
- toolName: u.toolName,
2847
+ toolName: d.toolName,
2848
2848
  state: "input-streaming",
2849
2849
  input: g,
2850
- title: u.title,
2851
- toolMetadata: u.toolMetadata
2850
+ title: d.title,
2851
+ toolMetadata: d.toolMetadata
2852
2852
  }) : _({
2853
2853
  toolCallId: s.toolCallId,
2854
- toolName: u.toolName,
2854
+ toolName: d.toolName,
2855
2855
  state: "input-streaming",
2856
2856
  input: g,
2857
- title: u.title,
2858
- toolMetadata: u.toolMetadata
2857
+ title: d.title,
2858
+ toolMetadata: d.toolMetadata
2859
2859
  }), p();
2860
2860
  break;
2861
2861
  }
@@ -2884,8 +2884,8 @@ function ys({
2884
2884
  break;
2885
2885
  }
2886
2886
  case "tool-input-error": {
2887
- const u = c.message.parts.filter($e).find((m) => m.toolCallId === s.toolCallId);
2888
- (u != null ? u.type === "dynamic-tool" : !!s.dynamic) ? S({
2887
+ const d = c.message.parts.filter(Ue).find((m) => m.toolCallId === s.toolCallId);
2888
+ (d != null ? d.type === "dynamic-tool" : !!s.dynamic) ? S({
2889
2889
  toolCallId: s.toolCallId,
2890
2890
  toolName: s.toolName,
2891
2891
  state: "output-error",
@@ -2908,8 +2908,8 @@ function ys({
2908
2908
  break;
2909
2909
  }
2910
2910
  case "tool-approval-request": {
2911
- const u = I(s.toolCallId);
2912
- u.state = "approval-requested", u.approval = {
2911
+ const d = I(s.toolCallId);
2912
+ d.state = "approval-requested", d.approval = {
2913
2913
  id: s.approvalId,
2914
2914
  ...s.isAutomatic === !0 ? { isAutomatic: !0 } : {},
2915
2915
  ...s.signature != null ? { signature: s.signature } : {}
@@ -2917,73 +2917,73 @@ function ys({
2917
2917
  break;
2918
2918
  }
2919
2919
  case "tool-approval-response": {
2920
- const u = E(
2920
+ const d = E(
2921
2921
  s.approvalId
2922
- ), g = u.approval == null ? { id: s.approvalId } : u.approval;
2923
- u.state = "approval-responded", u.approval = {
2922
+ ), g = d.approval == null ? { id: s.approvalId } : d.approval;
2923
+ d.state = "approval-responded", d.approval = {
2924
2924
  id: s.approvalId,
2925
2925
  approved: s.approved,
2926
2926
  ...s.reason != null ? { reason: s.reason } : {},
2927
2927
  ...g.isAutomatic === !0 ? { isAutomatic: !0 } : {},
2928
2928
  ...g.signature != null ? { signature: g.signature } : {}
2929
- }, s.providerExecuted != null && (u.providerExecuted = s.providerExecuted), s.providerMetadata != null && (u.callProviderMetadata = s.providerMetadata), p();
2929
+ }, s.providerExecuted != null && (d.providerExecuted = s.providerExecuted), s.providerMetadata != null && (d.callProviderMetadata = s.providerMetadata), p();
2930
2930
  break;
2931
2931
  }
2932
2932
  case "tool-output-denied": {
2933
- const u = I(s.toolCallId);
2934
- u.state = "output-denied", p();
2933
+ const d = I(s.toolCallId);
2934
+ d.state = "output-denied", p();
2935
2935
  break;
2936
2936
  }
2937
2937
  case "tool-output-available": {
2938
- const u = I(s.toolCallId);
2939
- u.type === "dynamic-tool" ? S({
2938
+ const d = I(s.toolCallId);
2939
+ d.type === "dynamic-tool" ? S({
2940
2940
  toolCallId: s.toolCallId,
2941
- toolName: u.toolName,
2941
+ toolName: d.toolName,
2942
2942
  state: "output-available",
2943
- input: u.input,
2943
+ input: d.input,
2944
2944
  output: s.output,
2945
2945
  preliminary: s.preliminary,
2946
2946
  providerExecuted: s.providerExecuted,
2947
2947
  providerMetadata: s.providerMetadata,
2948
- title: u.title,
2949
- toolMetadata: u.toolMetadata
2948
+ title: d.title,
2949
+ toolMetadata: d.toolMetadata
2950
2950
  }) : _({
2951
2951
  toolCallId: s.toolCallId,
2952
- toolName: jt(u),
2952
+ toolName: jt(d),
2953
2953
  state: "output-available",
2954
- input: u.input,
2954
+ input: d.input,
2955
2955
  output: s.output,
2956
2956
  providerExecuted: s.providerExecuted,
2957
2957
  preliminary: s.preliminary,
2958
2958
  providerMetadata: s.providerMetadata,
2959
- title: u.title,
2960
- toolMetadata: u.toolMetadata
2959
+ title: d.title,
2960
+ toolMetadata: d.toolMetadata
2961
2961
  }), p();
2962
2962
  break;
2963
2963
  }
2964
2964
  case "tool-output-error": {
2965
- const u = I(s.toolCallId);
2966
- u.type === "dynamic-tool" ? S({
2965
+ const d = I(s.toolCallId);
2966
+ d.type === "dynamic-tool" ? S({
2967
2967
  toolCallId: s.toolCallId,
2968
- toolName: u.toolName,
2968
+ toolName: d.toolName,
2969
2969
  state: "output-error",
2970
- input: u.input,
2970
+ input: d.input,
2971
2971
  errorText: s.errorText,
2972
2972
  providerExecuted: s.providerExecuted,
2973
2973
  providerMetadata: s.providerMetadata,
2974
- title: u.title,
2975
- toolMetadata: u.toolMetadata
2974
+ title: d.title,
2975
+ toolMetadata: d.toolMetadata
2976
2976
  }) : _({
2977
2977
  toolCallId: s.toolCallId,
2978
- toolName: jt(u),
2978
+ toolName: jt(d),
2979
2979
  state: "output-error",
2980
- input: u.input,
2981
- rawInput: u.rawInput,
2980
+ input: d.input,
2981
+ rawInput: d.rawInput,
2982
2982
  errorText: s.errorText,
2983
2983
  providerExecuted: s.providerExecuted,
2984
2984
  providerMetadata: s.providerMetadata,
2985
- title: u.title,
2986
- toolMetadata: u.toolMetadata
2985
+ title: d.title,
2986
+ toolMetadata: d.toolMetadata
2987
2987
  }), p();
2988
2988
  break;
2989
2989
  }
@@ -3027,15 +3027,15 @@ function ys({
3027
3027
  }
3028
3028
  });
3029
3029
  }
3030
- const u = s;
3031
- if (u.transient) {
3032
- l == null || l(u);
3030
+ const d = s;
3031
+ if (d.transient) {
3032
+ l == null || l(d);
3033
3033
  break;
3034
3034
  }
3035
- const g = u.id != null ? c.message.parts.find(
3036
- (m) => u.type === m.type && u.id === m.id
3035
+ const g = d.id != null ? c.message.parts.find(
3036
+ (m) => d.type === m.type && d.id === m.id
3037
3037
  ) : void 0;
3038
- g != null ? g.data = u.data : c.message.parts.push(u), l == null || l(u), p();
3038
+ g != null ? g.data = d.data : c.message.parts.push(d), l == null || l(d), p();
3039
3039
  }
3040
3040
  }
3041
3041
  f.enqueue(s);
@@ -3162,7 +3162,7 @@ var Es = class {
3162
3162
  const s = await _e(this.body), f = await _e(this.headers), c = await _e(this.credentials), p = {
3163
3163
  ...ke(f),
3164
3164
  ...ke(e.headers)
3165
- }, d = await ((r = this.prepareSendMessagesRequest) == null ? void 0 : r.call(this, {
3165
+ }, u = await ((r = this.prepareSendMessagesRequest) == null ? void 0 : r.call(this, {
3166
3166
  api: this.api,
3167
3167
  id: e.chatId,
3168
3168
  messages: e.messages,
@@ -3172,20 +3172,20 @@ var Es = class {
3172
3172
  requestMetadata: e.metadata,
3173
3173
  trigger: e.trigger,
3174
3174
  messageId: e.messageId
3175
- })), C = (a = d == null ? void 0 : d.api) != null ? a : this.api, v = (d == null ? void 0 : d.headers) !== void 0 ? ke(d.headers) : p, O = (d == null ? void 0 : d.body) !== void 0 ? d.body : {
3175
+ })), C = (a = u == null ? void 0 : u.api) != null ? a : this.api, v = (u == null ? void 0 : u.headers) !== void 0 ? ke(u.headers) : p, N = (u == null ? void 0 : u.body) !== void 0 ? u.body : {
3176
3176
  ...s,
3177
3177
  ...e.body,
3178
3178
  id: e.chatId,
3179
3179
  messages: e.messages,
3180
3180
  trigger: e.trigger,
3181
3181
  messageId: e.messageId
3182
- }, I = (n = d == null ? void 0 : d.credentials) != null ? n : c, _ = await ((i = this.fetch) != null ? i : globalThis.fetch)(C, {
3182
+ }, I = (n = u == null ? void 0 : u.credentials) != null ? n : c, _ = await ((i = this.fetch) != null ? i : globalThis.fetch)(C, {
3183
3183
  method: "POST",
3184
3184
  headers: {
3185
3185
  "Content-Type": "application/json",
3186
3186
  ...v
3187
3187
  },
3188
- body: JSON.stringify(O),
3188
+ body: JSON.stringify(N),
3189
3189
  credentials: I,
3190
3190
  signal: t
3191
3191
  });
@@ -3209,7 +3209,7 @@ var Es = class {
3209
3209
  headers: c,
3210
3210
  credentials: f,
3211
3211
  requestMetadata: t.metadata
3212
- })), d = (r = p == null ? void 0 : p.api) != null ? r : `${this.api}/${t.chatId}/stream`, C = (p == null ? void 0 : p.headers) !== void 0 ? ke(p.headers) : c, v = (a = p == null ? void 0 : p.credentials) != null ? a : f, I = await ((n = this.fetch) != null ? n : globalThis.fetch)(d, {
3212
+ })), u = (r = p == null ? void 0 : p.api) != null ? r : `${this.api}/${t.chatId}/stream`, C = (p == null ? void 0 : p.headers) !== void 0 ? ke(p.headers) : c, v = (a = p == null ? void 0 : p.credentials) != null ? a : f, I = await ((n = this.fetch) != null ? n : globalThis.fetch)(u, {
3213
3213
  method: "GET",
3214
3214
  headers: C,
3215
3215
  credentials: v
@@ -3256,9 +3256,9 @@ var Es = class {
3256
3256
  onData: c,
3257
3257
  sendAutomaticallyWhen: p
3258
3258
  }) {
3259
- this.activeResponse = void 0, this.jobExecutor = new Cs(), this.sendMessage = async (d, C) => {
3260
- var v, O, I, E;
3261
- if (d == null) {
3259
+ this.activeResponse = void 0, this.jobExecutor = new Cs(), this.sendMessage = async (u, C) => {
3260
+ var v, N, I, E;
3261
+ if (u == null) {
3262
3262
  await this.makeRequest({
3263
3263
  trigger: "submit-message",
3264
3264
  messageId: (v = this.lastMessage) == null ? void 0 : v.id,
@@ -3267,69 +3267,69 @@ var Es = class {
3267
3267
  return;
3268
3268
  }
3269
3269
  let _;
3270
- if ("text" in d || "files" in d ? _ = {
3270
+ if ("text" in u || "files" in u ? _ = {
3271
3271
  parts: [
3272
- ...Array.isArray(d.files) ? d.files : await Ss(d.files),
3273
- ..."text" in d && d.text != null ? [{ type: "text", text: d.text }] : []
3272
+ ...Array.isArray(u.files) ? u.files : await Ss(u.files),
3273
+ ..."text" in u && u.text != null ? [{ type: "text", text: u.text }] : []
3274
3274
  ]
3275
- } : _ = d, d.messageId != null) {
3275
+ } : _ = u, u.messageId != null) {
3276
3276
  const S = this.state.messages.findIndex(
3277
- (M) => M.id === d.messageId
3277
+ (M) => M.id === u.messageId
3278
3278
  );
3279
3279
  if (S === -1)
3280
- throw new Error(`message with id ${d.messageId} not found`);
3280
+ throw new Error(`message with id ${u.messageId} not found`);
3281
3281
  if (this.state.messages[S].role !== "user")
3282
3282
  throw new Error(
3283
- `message with id ${d.messageId} is not a user message`
3283
+ `message with id ${u.messageId} is not a user message`
3284
3284
  );
3285
3285
  this.state.messages = this.state.messages.slice(0, S + 1), this.state.replaceMessage(S, {
3286
3286
  ..._,
3287
- id: d.messageId,
3288
- role: (O = _.role) != null ? O : "user",
3289
- metadata: d.metadata
3287
+ id: u.messageId,
3288
+ role: (N = _.role) != null ? N : "user",
3289
+ metadata: u.metadata
3290
3290
  });
3291
3291
  } else
3292
3292
  this.state.pushMessage({
3293
3293
  ..._,
3294
3294
  id: (I = _.id) != null ? I : this.generateId(),
3295
3295
  role: (E = _.role) != null ? E : "user",
3296
- metadata: d.metadata
3296
+ metadata: u.metadata
3297
3297
  });
3298
3298
  await this.makeRequest({
3299
3299
  trigger: "submit-message",
3300
- messageId: d.messageId,
3300
+ messageId: u.messageId,
3301
3301
  ...C
3302
3302
  });
3303
3303
  }, this.regenerate = async ({
3304
- messageId: d,
3304
+ messageId: u,
3305
3305
  ...C
3306
3306
  } = {}) => {
3307
- const v = d == null ? this.state.messages.length - 1 : this.state.messages.findIndex((O) => O.id === d);
3307
+ const v = u == null ? this.state.messages.length - 1 : this.state.messages.findIndex((N) => N.id === u);
3308
3308
  if (v === -1)
3309
- throw new Error(`message ${d} not found`);
3309
+ throw new Error(`message ${u} not found`);
3310
3310
  this.state.messages = this.state.messages.slice(
3311
3311
  0,
3312
3312
  // if the message is a user message, we need to include it in the request:
3313
3313
  this.messages[v].role === "assistant" ? v : v + 1
3314
3314
  ), await this.makeRequest({
3315
3315
  trigger: "regenerate-message",
3316
- messageId: d,
3316
+ messageId: u,
3317
3317
  ...C
3318
3318
  });
3319
- }, this.resumeStream = async (d = {}) => {
3320
- await this.makeRequest({ trigger: "resume-stream", ...d });
3319
+ }, this.resumeStream = async (u = {}) => {
3320
+ await this.makeRequest({ trigger: "resume-stream", ...u });
3321
3321
  }, this.clearError = () => {
3322
3322
  this.status === "error" && (this.state.error = void 0, this.setStatus({ status: "ready" }));
3323
3323
  }, this.addToolApprovalResponse = async ({
3324
- id: d,
3324
+ id: u,
3325
3325
  approved: C,
3326
3326
  reason: v,
3327
- options: O
3327
+ options: N
3328
3328
  }) => this.jobExecutor.run(async () => {
3329
- const I = this.state.messages, E = I[I.length - 1], _ = (S) => $e(S) && S.state === "approval-requested" && S.approval.id === d ? {
3329
+ const I = this.state.messages, E = I[I.length - 1], _ = (S) => Ue(S) && S.state === "approval-requested" && S.approval.id === u ? {
3330
3330
  ...S,
3331
3331
  state: "approval-responded",
3332
- approval: { ...S.approval, id: d, approved: C, reason: v }
3332
+ approval: { ...S.approval, id: u, approved: C, reason: v }
3333
3333
  } : S;
3334
3334
  this.state.replaceMessage(I.length - 1, {
3335
3335
  ...E,
@@ -3339,31 +3339,31 @@ var Es = class {
3339
3339
  S && this.makeRequest({
3340
3340
  trigger: "submit-message",
3341
3341
  messageId: (M = this.lastMessage) == null ? void 0 : M.id,
3342
- ...O
3342
+ ...N
3343
3343
  });
3344
3344
  });
3345
3345
  }), this.addToolOutput = async ({
3346
- state: d = "output-available",
3346
+ state: u = "output-available",
3347
3347
  toolCallId: C,
3348
3348
  output: v,
3349
- errorText: O,
3349
+ errorText: N,
3350
3350
  options: I
3351
3351
  }) => this.jobExecutor.run(async () => {
3352
- const E = this.state.messages, _ = E[E.length - 1], S = (M) => $e(M) && M.toolCallId === C ? { ...M, state: d, output: v, errorText: O } : M;
3352
+ const E = this.state.messages, _ = E[E.length - 1], S = (M) => Ue(M) && M.toolCallId === C ? { ...M, state: u, output: v, errorText: N } : M;
3353
3353
  this.state.replaceMessage(E.length - 1, {
3354
3354
  ..._,
3355
3355
  parts: _.parts.map(S)
3356
3356
  }), this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(S)), this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen && this.shouldSendAutomatically().then((M) => {
3357
- var u;
3357
+ var d;
3358
3358
  M && this.makeRequest({
3359
3359
  trigger: "submit-message",
3360
- messageId: (u = this.lastMessage) == null ? void 0 : u.id,
3360
+ messageId: (d = this.lastMessage) == null ? void 0 : d.id,
3361
3361
  ...I
3362
3362
  });
3363
3363
  });
3364
3364
  }), this.addToolResult = this.addToolOutput, this.stop = async () => {
3365
- var d;
3366
- this.status !== "streaming" && this.status !== "submitted" || (d = this.activeResponse) != null && d.abortController && this.activeResponse.abortController.abort();
3365
+ var u;
3366
+ this.status !== "streaming" && this.status !== "submitted" || (u = this.activeResponse) != null && u.abortController && this.activeResponse.abortController.abort();
3367
3367
  }, this.id = e, this.transport = r, this.generateId = t, this.messageMetadataSchema = a, this.dataPartSchemas = n, this.state = i, this.onError = l, this.onToolCall = s, this.onFinish = f, this.onData = c, this.sendAutomaticallyWhen = p;
3368
3368
  }
3369
3369
  /**
@@ -3429,7 +3429,7 @@ var Es = class {
3429
3429
  }
3430
3430
  this.setStatus({ status: "submitted", error: void 0 });
3431
3431
  const f = this.lastMessage;
3432
- let c = !1, p = !1, d = !1, C;
3432
+ let c = !1, p = !1, u = !1, C;
3433
3433
  try {
3434
3434
  const v = {
3435
3435
  state: vs({
@@ -3441,8 +3441,8 @@ var Es = class {
3441
3441
  C = v, v.abortController.signal.addEventListener("abort", () => {
3442
3442
  c = !0;
3443
3443
  }), this.activeResponse = v;
3444
- let O;
3445
- t === "resume-stream" ? O = s : O = await this.transport.sendMessages({
3444
+ let N;
3445
+ t === "resume-stream" ? N = s : N = await this.transport.sendMessages({
3446
3446
  chatId: this.id,
3447
3447
  messages: this.state.messages,
3448
3448
  abortSignal: v.abortController.signal,
@@ -3469,7 +3469,7 @@ var Es = class {
3469
3469
  );
3470
3470
  await bs({
3471
3471
  stream: ys({
3472
- stream: O,
3472
+ stream: N,
3473
3473
  onToolCall: this.onToolCall,
3474
3474
  onData: this.onData,
3475
3475
  messageMetadataSchema: this.messageMetadataSchema,
@@ -3486,7 +3486,7 @@ var Es = class {
3486
3486
  } catch (v) {
3487
3487
  if (c || v.name === "AbortError")
3488
3488
  return c = !0, this.setStatus({ status: "ready" }), null;
3489
- d = !0, v instanceof TypeError && (v.message.toLowerCase().includes("fetch") || v.message.toLowerCase().includes("network")) && (p = !0), this.onError && v instanceof Error && this.onError(v), this.setStatus({ status: "error", error: v });
3489
+ u = !0, v instanceof TypeError && (v.message.toLowerCase().includes("fetch") || v.message.toLowerCase().includes("network")) && (p = !0), this.onError && v instanceof Error && this.onError(v), this.setStatus({ status: "error", error: v });
3490
3490
  } finally {
3491
3491
  try {
3492
3492
  C && ((i = this.onFinish) == null || i.call(this, {
@@ -3494,7 +3494,7 @@ var Es = class {
3494
3494
  messages: this.state.messages,
3495
3495
  isAbort: c,
3496
3496
  isDisconnect: p,
3497
- isError: d,
3497
+ isError: u,
3498
3498
  finishReason: C.state.finishReason
3499
3499
  }));
3500
3500
  } catch (v) {
@@ -3502,7 +3502,7 @@ var Es = class {
3502
3502
  }
3503
3503
  this.activeResponse === C && (this.activeResponse = void 0);
3504
3504
  }
3505
- !d && await this.shouldSendAutomatically() && await this.makeRequest({
3505
+ !u && await this.shouldSendAutomatically() && await this.makeRequest({
3506
3506
  trigger: "submit-message",
3507
3507
  messageId: (l = this.lastMessage) == null ? void 0 : l.id,
3508
3508
  metadata: e,
@@ -3510,9 +3510,9 @@ var Es = class {
3510
3510
  body: a
3511
3511
  });
3512
3512
  }
3513
- }, Tt, ur;
3513
+ }, xt, ur;
3514
3514
  function Is() {
3515
- if (ur) return Tt;
3515
+ if (ur) return xt;
3516
3516
  ur = 1;
3517
3517
  function t(e, r) {
3518
3518
  if (typeof e != "function")
@@ -3526,83 +3526,83 @@ function Is() {
3526
3526
  }, c);
3527
3527
  };
3528
3528
  }
3529
- return Tt = t, Tt;
3529
+ return xt = t, xt;
3530
3530
  }
3531
3531
  var _s = /* @__PURE__ */ Is();
3532
3532
  const As = /* @__PURE__ */ Zn(_s);
3533
- var Yr = (t, e, r) => {
3533
+ var Hr = (t, e, r) => {
3534
3534
  if (!e.has(t))
3535
3535
  throw TypeError("Cannot " + r);
3536
- }, B = (t, e, r) => (Yr(t, e, "read from private field"), r ? r.call(t) : e.get(t)), me = (t, e, r) => {
3536
+ }, V = (t, e, r) => (Hr(t, e, "read from private field"), r ? r.call(t) : e.get(t)), me = (t, e, r) => {
3537
3537
  if (e.has(t))
3538
3538
  throw TypeError("Cannot add the same private member more than once");
3539
3539
  e instanceof WeakSet ? e.add(t) : e.set(t, r);
3540
- }, Ie = (t, e, r, a) => (Yr(t, e, "write to private field"), e.set(t, r), r);
3541
- function Ts(t, e) {
3540
+ }, Ie = (t, e, r, a) => (Hr(t, e, "write to private field"), e.set(t, r), r);
3541
+ function xs(t, e) {
3542
3542
  return e != null ? As(t, e) : t;
3543
3543
  }
3544
- var le, it, ot, Be, Ve, Je, Le, Dt, kt, xs = class {
3544
+ var le, it, ot, Be, Je, Ke, Le, Dt, kt, Ts = class {
3545
3545
  constructor(t = []) {
3546
- me(this, le, void 0), me(this, it, "ready"), me(this, ot, void 0), me(this, Be, /* @__PURE__ */ new Set()), me(this, Ve, /* @__PURE__ */ new Set()), me(this, Je, /* @__PURE__ */ new Set()), this.pushMessage = (e) => {
3547
- Ie(this, le, B(this, le).concat(e)), B(this, Le).call(this);
3546
+ me(this, le, void 0), me(this, it, "ready"), me(this, ot, void 0), me(this, Be, /* @__PURE__ */ new Set()), me(this, Je, /* @__PURE__ */ new Set()), me(this, Ke, /* @__PURE__ */ new Set()), this.pushMessage = (e) => {
3547
+ Ie(this, le, V(this, le).concat(e)), V(this, Le).call(this);
3548
3548
  }, this.popMessage = () => {
3549
- Ie(this, le, B(this, le).slice(0, -1)), B(this, Le).call(this);
3549
+ Ie(this, le, V(this, le).slice(0, -1)), V(this, Le).call(this);
3550
3550
  }, this.replaceMessage = (e, r) => {
3551
3551
  Ie(this, le, [
3552
- ...B(this, le).slice(0, e),
3552
+ ...V(this, le).slice(0, e),
3553
3553
  // We deep clone the message here to ensure the new React Compiler (currently in RC) detects deeply nested parts/metadata changes:
3554
3554
  this.snapshot(r),
3555
- ...B(this, le).slice(e + 1)
3556
- ]), B(this, Le).call(this);
3555
+ ...V(this, le).slice(e + 1)
3556
+ ]), V(this, Le).call(this);
3557
3557
  }, this.snapshot = (e) => structuredClone(e), this["~registerMessagesCallback"] = (e, r) => {
3558
- const a = r ? Ts(e, r) : e;
3559
- return B(this, Be).add(a), () => {
3560
- B(this, Be).delete(a);
3558
+ const a = r ? xs(e, r) : e;
3559
+ return V(this, Be).add(a), () => {
3560
+ V(this, Be).delete(a);
3561
3561
  };
3562
- }, this["~registerStatusCallback"] = (e) => (B(this, Ve).add(e), () => {
3563
- B(this, Ve).delete(e);
3564
- }), this["~registerErrorCallback"] = (e) => (B(this, Je).add(e), () => {
3565
- B(this, Je).delete(e);
3562
+ }, this["~registerStatusCallback"] = (e) => (V(this, Je).add(e), () => {
3563
+ V(this, Je).delete(e);
3564
+ }), this["~registerErrorCallback"] = (e) => (V(this, Ke).add(e), () => {
3565
+ V(this, Ke).delete(e);
3566
3566
  }), me(this, Le, () => {
3567
- B(this, Be).forEach((e) => e());
3567
+ V(this, Be).forEach((e) => e());
3568
3568
  }), me(this, Dt, () => {
3569
- B(this, Ve).forEach((e) => e());
3569
+ V(this, Je).forEach((e) => e());
3570
3570
  }), me(this, kt, () => {
3571
- B(this, Je).forEach((e) => e());
3571
+ V(this, Ke).forEach((e) => e());
3572
3572
  }), Ie(this, le, t);
3573
3573
  }
3574
3574
  get status() {
3575
- return B(this, it);
3575
+ return V(this, it);
3576
3576
  }
3577
3577
  set status(t) {
3578
- Ie(this, it, t), B(this, Dt).call(this);
3578
+ Ie(this, it, t), V(this, Dt).call(this);
3579
3579
  }
3580
3580
  get error() {
3581
- return B(this, ot);
3581
+ return V(this, ot);
3582
3582
  }
3583
3583
  set error(t) {
3584
- Ie(this, ot, t), B(this, kt).call(this);
3584
+ Ie(this, ot, t), V(this, kt).call(this);
3585
3585
  }
3586
3586
  get messages() {
3587
- return B(this, le);
3587
+ return V(this, le);
3588
3588
  }
3589
3589
  set messages(t) {
3590
- Ie(this, le, [...t]), B(this, Le).call(this);
3590
+ Ie(this, le, [...t]), V(this, Le).call(this);
3591
3591
  }
3592
3592
  };
3593
3593
  le = /* @__PURE__ */ new WeakMap();
3594
3594
  it = /* @__PURE__ */ new WeakMap();
3595
3595
  ot = /* @__PURE__ */ new WeakMap();
3596
3596
  Be = /* @__PURE__ */ new WeakMap();
3597
- Ve = /* @__PURE__ */ new WeakMap();
3598
3597
  Je = /* @__PURE__ */ new WeakMap();
3598
+ Ke = /* @__PURE__ */ new WeakMap();
3599
3599
  Le = /* @__PURE__ */ new WeakMap();
3600
3600
  Dt = /* @__PURE__ */ new WeakMap();
3601
3601
  kt = /* @__PURE__ */ new WeakMap();
3602
3602
  var Fe, dr = class extends ws {
3603
3603
  constructor({ messages: t, ...e }) {
3604
- const r = new xs(t);
3605
- super({ ...e, state: r }), me(this, Fe, void 0), this["~registerMessagesCallback"] = (a, n) => B(this, Fe)["~registerMessagesCallback"](a, n), this["~registerStatusCallback"] = (a) => B(this, Fe)["~registerStatusCallback"](a), this["~registerErrorCallback"] = (a) => B(this, Fe)["~registerErrorCallback"](a), Ie(this, Fe, r);
3604
+ const r = new Ts(t);
3605
+ super({ ...e, state: r }), me(this, Fe, void 0), this["~registerMessagesCallback"] = (a, n) => V(this, Fe)["~registerMessagesCallback"](a, n), this["~registerStatusCallback"] = (a) => V(this, Fe)["~registerStatusCallback"](a), this["~registerErrorCallback"] = (a) => V(this, Fe)["~registerErrorCallback"](a), Ie(this, Fe, r);
3606
3606
  }
3607
3607
  };
3608
3608
  Fe = /* @__PURE__ */ new WeakMap();
@@ -3612,7 +3612,7 @@ function Ms({
3612
3612
  resume: r = !1,
3613
3613
  ...a
3614
3614
  } = {}) {
3615
- const n = t ?? e, i = R({});
3615
+ const n = t ?? e, i = O({});
3616
3616
  "chat" in a || (i.current = {
3617
3617
  onToolCall: a.onToolCall,
3618
3618
  onData: a.onData,
@@ -3651,34 +3651,34 @@ function Ms({
3651
3651
  var _, S, M;
3652
3652
  return (M = (S = (_ = i.current).sendAutomaticallyWhen) == null ? void 0 : S.call(_, E)) != null ? M : !1;
3653
3653
  }
3654
- }, c = R(
3654
+ }, c = O(
3655
3655
  "chat" in a ? a.chat : new dr(f)
3656
3656
  );
3657
3657
  ("chat" in a && a.chat !== c.current || "id" in a && a.id != null && c.current.id !== a.id) && (c.current = "chat" in a ? a.chat : new dr(f));
3658
- const d = U(
3658
+ const u = q(
3659
3659
  (E) => c.current["~registerMessagesCallback"](E, n),
3660
3660
  // `chatRef.current.id` is required to trigger re-subscription when the chat ID changes
3661
3661
  // eslint-disable-next-line react-hooks/exhaustive-deps
3662
3662
  [n, c.current.id]
3663
- ), C = Ke(
3664
- d,
3663
+ ), C = $e(
3664
+ u,
3665
3665
  () => c.current.messages,
3666
3666
  () => c.current.messages
3667
- ), v = Ke(
3667
+ ), v = $e(
3668
3668
  c.current["~registerStatusCallback"],
3669
3669
  () => c.current.status,
3670
3670
  () => c.current.status
3671
- ), O = Ke(
3671
+ ), N = $e(
3672
3672
  c.current["~registerErrorCallback"],
3673
3673
  () => c.current.error,
3674
3674
  () => c.current.error
3675
- ), I = U(
3675
+ ), I = q(
3676
3676
  (E) => {
3677
3677
  typeof E == "function" && (E = E(c.current.messages)), c.current.messages = E;
3678
3678
  },
3679
3679
  [c]
3680
3680
  );
3681
- return z(() => {
3681
+ return F(() => {
3682
3682
  r && c.current.resumeStream();
3683
3683
  }, [r, c]), {
3684
3684
  id: c.current.id,
@@ -3688,7 +3688,7 @@ function Ms({
3688
3688
  regenerate: c.current.regenerate,
3689
3689
  clearError: c.current.clearError,
3690
3690
  stop: c.current.stop,
3691
- error: O,
3691
+ error: N,
3692
3692
  resumeStream: c.current.resumeStream,
3693
3693
  status: v,
3694
3694
  /**
@@ -3744,17 +3744,17 @@ function fr(t, e) {
3744
3744
  });
3745
3745
  return r.length === t.length && r.every((a, n) => a === t[n]) ? t : r;
3746
3746
  }
3747
- const Ps = N.union([
3748
- N.string(),
3749
- N.looseObject({ id: N.string().optional(), label: N.string() })
3750
- ]), Rs = N.looseObject({
3751
- id: N.string().optional(),
3752
- prompt: N.string(),
3753
- selection: N.enum(["single", "multiple"]).default("single"),
3754
- options: N.array(Ps).min(1)
3755
- }), Os = N.looseObject({
3756
- request_id: N.string().optional(),
3757
- questions: N.array(Rs).min(1)
3747
+ const Ps = j.union([
3748
+ j.string(),
3749
+ j.looseObject({ id: j.string().optional(), label: j.string() })
3750
+ ]), Rs = j.looseObject({
3751
+ id: j.string().optional(),
3752
+ prompt: j.string(),
3753
+ selection: j.enum(["single", "multiple"]).default("single"),
3754
+ options: j.array(Ps).min(1)
3755
+ }), Os = j.looseObject({
3756
+ request_id: j.string().optional(),
3757
+ questions: j.array(Rs).min(1)
3758
3758
  });
3759
3759
  function Ns(t) {
3760
3760
  return !!(t != null && t.includes("ask_questions"));
@@ -3783,7 +3783,7 @@ function ks(t, e) {
3783
3783
  }))
3784
3784
  };
3785
3785
  }
3786
- function xt(t) {
3786
+ function Tt(t) {
3787
3787
  try {
3788
3788
  return JSON.parse(t);
3789
3789
  } catch {
@@ -3792,19 +3792,19 @@ function xt(t) {
3792
3792
  }
3793
3793
  function Ls(t) {
3794
3794
  if (t == null) return null;
3795
- if (typeof t == "string") return xt(t);
3795
+ if (typeof t == "string") return Tt(t);
3796
3796
  if (Array.isArray(t)) {
3797
3797
  for (const e of t)
3798
3798
  if (e && typeof e == "object" && "text" in e) {
3799
3799
  const r = e.text;
3800
- if (typeof r == "string") return xt(r);
3800
+ if (typeof r == "string") return Tt(r);
3801
3801
  }
3802
3802
  return null;
3803
3803
  }
3804
3804
  if (typeof t == "object") {
3805
3805
  if ("text" in t) {
3806
3806
  const e = t.text;
3807
- if (typeof e == "string") return xt(e);
3807
+ if (typeof e == "string") return Tt(e);
3808
3808
  }
3809
3809
  return t;
3810
3810
  }
@@ -3816,7 +3816,7 @@ function mr(t, e) {
3816
3816
  const a = Os.safeParse(r);
3817
3817
  return a.success ? ks(a.data, e) : null;
3818
3818
  }
3819
- function Mi(t, e) {
3819
+ function Ni(t, e) {
3820
3820
  const r = [];
3821
3821
  for (const a of t.questions) {
3822
3822
  const n = e.get(a.id);
@@ -3827,17 +3827,17 @@ A: ${n.trim()}`);
3827
3827
 
3828
3828
  `);
3829
3829
  }
3830
- const Fs = N.object({
3831
- request_id: N.string().uuid(),
3832
- server_id: N.string().uuid(),
3833
- name: N.string().min(1).max(120)
3834
- }), $s = N.object({
3830
+ const Fs = j.object({
3831
+ request_id: j.string().uuid(),
3832
+ server_id: j.string().uuid(),
3833
+ name: j.string().min(1).max(120)
3834
+ }), $s = j.object({
3835
3835
  connection_required: Fs
3836
- }), gr = "data-spec", Us = N.object({ label: N.string(), done: N.boolean() }), qs = N.object({
3837
- plan: N.array(
3838
- N.object({
3839
- step: N.string(),
3840
- status: N.enum(["pending", "in_progress", "completed"])
3836
+ }), gr = "data-spec", Us = j.object({ label: j.string(), done: j.boolean() }), qs = j.object({
3837
+ plan: j.array(
3838
+ j.object({
3839
+ step: j.string(),
3840
+ status: j.enum(["pending", "in_progress", "completed"])
3841
3841
  })
3842
3842
  )
3843
3843
  });
@@ -3848,7 +3848,7 @@ function lt(t) {
3848
3848
  }, a = (l) => l === "output-available" || l === "output-error";
3849
3849
  let n = null, i;
3850
3850
  for (const l of t)
3851
- if (!Ca(l) && Hr(l) !== "highlight_element") {
3851
+ if (!Sa(l) && Gr(l) !== "highlight_element") {
3852
3852
  if (l.state === "output-available" && (l.type === "dynamic-tool" || l.type.startsWith("tool-"))) {
3853
3853
  const s = $s.safeParse(l.output);
3854
3854
  if (s.success) {
@@ -3901,11 +3901,11 @@ function lt(t) {
3901
3901
  }
3902
3902
  return e;
3903
3903
  }
3904
- function Hr(t) {
3904
+ function Gr(t) {
3905
3905
  return t.type === "dynamic-tool" ? typeof t.toolName == "string" ? t.toolName : void 0 : t.type.startsWith("tool-") ? t.type.slice(5) : void 0;
3906
3906
  }
3907
3907
  function zs(t) {
3908
- return Ns(Hr(t));
3908
+ return Ns(Gr(t));
3909
3909
  }
3910
3910
  function Zs(t) {
3911
3911
  const e = typeof t.toolCallId == "string" ? t.toolCallId : void 0, r = mr(t.output, e) ?? mr(t.input, e);
@@ -3923,13 +3923,13 @@ function Ws(t, e) {
3923
3923
  `toolActivity=${encodeURIComponent(e.toolActivity)}`
3924
3924
  ), (e == null ? void 0 : e.reasoning) !== void 0 && r.push(`reasoning=${String(e.reasoning)}`), r.length === 0 ? t : `${t}${t.includes("?") ? "&" : "?"}${r.join("&")}`;
3925
3925
  }
3926
- function Bs(t) {
3926
+ function Vs(t) {
3927
3927
  return ({ id: e }) => ({
3928
3928
  api: t.reconnectApi(e),
3929
3929
  headers: t.headers()
3930
3930
  });
3931
3931
  }
3932
- function Vs(t) {
3932
+ function Bs(t) {
3933
3933
  return new Ut({
3934
3934
  api: t.api,
3935
3935
  headers: () => t.headers(),
@@ -3937,7 +3937,7 @@ function Vs(t) {
3937
3937
  // Every send carries its full body; a send without one is a programming
3938
3938
  // error, and an empty body would be rejected server-side just as loudly.
3939
3939
  prepareSendMessagesRequest: ({ body: e }) => ({ body: e ?? {} }),
3940
- prepareReconnectToStreamRequest: Bs(t)
3940
+ prepareReconnectToStreamRequest: Vs(t)
3941
3941
  });
3942
3942
  }
3943
3943
  function Js({
@@ -3975,7 +3975,7 @@ function vr(t) {
3975
3975
  for (const e of t) {
3976
3976
  if (e.type !== "data-turn-settled") continue;
3977
3977
  const r = e.data;
3978
- return !Sa(r) || typeof r.turn_id != "string" || !Ys(r.message_uuids) ? null : { turnId: r.turn_id, rowIds: r.message_uuids };
3978
+ return !Er(r) || typeof r.turn_id != "string" || !Ys(r.message_uuids) ? null : { turnId: r.turn_id, rowIds: r.message_uuids };
3979
3979
  }
3980
3980
  return null;
3981
3981
  }
@@ -4008,15 +4008,15 @@ function ei({
4008
4008
  sessionId: r,
4009
4009
  persistedMessages: a
4010
4010
  }) {
4011
- var Bt, Vt;
4012
- const { api: n, messageCtx: i } = t, l = R(e);
4011
+ var Vt, Bt;
4012
+ const { api: n, messageCtx: i } = t, l = O(e);
4013
4013
  l.current = e;
4014
4014
  const {
4015
4015
  pageContext: s,
4016
4016
  clientTools: f,
4017
4017
  pageActions: c
4018
4018
  } = t.features, p = te(
4019
- () => Vs({
4019
+ () => Bs({
4020
4020
  ...n.getStreamTransportOptions(),
4021
4021
  headers: () => n.getStreamTransportOptions().headers,
4022
4022
  reconnectApi: (b) => Ws(
@@ -4028,16 +4028,16 @@ function ei({
4028
4028
  fetch: (b, A) => (l.current.streamingFetch ?? globalThis.fetch)(b, A)
4029
4029
  }),
4030
4030
  [n]
4031
- ), [d, C] = J(null), v = R(!1), [O] = J(Et), {
4031
+ ), [u, C] = J(null), v = O(!1), [N] = J(Et), {
4032
4032
  status: I,
4033
4033
  messages: E,
4034
4034
  sendMessage: _,
4035
4035
  stop: S,
4036
4036
  error: M,
4037
- clearError: u,
4037
+ clearError: d,
4038
4038
  resumeStream: g
4039
4039
  } = Ms({
4040
- id: r ?? O,
4040
+ id: r ?? N,
4041
4041
  // Reattach to a still-live turn (reload, tab switch) — but only once a
4042
4042
  // session actually exists. A fresh visitor has nothing to resume, and the
4043
4043
  // engine mounts with the shell, so probing unconditionally would fire a
@@ -4050,25 +4050,33 @@ function ei({
4050
4050
  throttle: 50,
4051
4051
  onError: (b) => ye.error("agent chat stream error", b),
4052
4052
  onFinish: C
4053
- }), m = R(E);
4053
+ }), m = O(E);
4054
4054
  m.current = E;
4055
- const y = R(new pr(yr)), h = R("idle"), [w, k] = J(!1), D = R(Promise.resolve()), V = R(0), Z = R(0), [$, W] = J(0), [ae, oe] = J(!1), ue = R(ae);
4056
- ue.current = ae;
4057
- const [be, Q] = J([]), [Te, he] = J([]), [ve, q] = J(null), H = R(null), ne = U((b) => {
4058
- H.current = b, q(b);
4059
- }, []), re = R(null), ze = R(null), je = R(I), ft = R(r), Ze = ft.current === r, mt = R(null), gt = R(null), zt = R(S), Ce = R(I);
4055
+ const y = O(new pr(yr));
4056
+ F(() => {
4057
+ if (!u || u.messages !== E) return;
4058
+ const { isAbort: b, isDisconnect: A, isError: R, message: x } = u;
4059
+ b || A || R || y.current.size > 0 || i.state.setPartial({
4060
+ lastAIResMightSolveUserIssue: Er(x.metadata) && x.metadata.mightSolveUserIssue === !0
4061
+ });
4062
+ }, [u, E, i]);
4063
+ const h = O("idle"), [w, k] = J(!1), D = O(Promise.resolve()), B = O(0), Z = O(0), [U, W] = J(0), [ne, oe] = J(!1), ue = O(ne);
4064
+ ue.current = ne;
4065
+ const [be, Q] = J([]), [xe, he] = J([]), [ve, z] = J(null), G = O(null), se = q((b) => {
4066
+ G.current = b, z(b);
4067
+ }, []), ae = O(null), Ze = O(null), je = O(I), ft = O(r), We = ft.current === r, mt = O(null), gt = O(null), zt = O(S), Ce = O(I);
4060
4068
  Ce.current = I;
4061
- const Xe = U((b, A) => {
4062
- const j = vr(b.parts);
4063
- if (!j || j.rowIds.length === 0) return;
4064
- const T = lt(b.parts);
4065
- T.length !== 0 && Q(
4066
- (L) => L.some((X) => X.turnId === j.turnId) ? L : [
4069
+ const Xe = q((b, A) => {
4070
+ const R = vr(b.parts);
4071
+ if (!R || R.rowIds.length === 0) return;
4072
+ const x = lt(b.parts);
4073
+ x.length !== 0 && Q(
4074
+ (L) => L.some((X) => X.turnId === R.turnId) ? L : [
4067
4075
  ...L,
4068
- { key: A, turnId: j.turnId, rowIds: j.rowIds, items: T }
4076
+ { key: A, turnId: R.turnId, rowIds: R.rowIds, items: x }
4069
4077
  ]
4070
4078
  );
4071
- }, []), Zt = U(
4079
+ }, []), Zt = q(
4072
4080
  (b) => Ea({
4073
4081
  config: l.current,
4074
4082
  input: b.input,
@@ -4080,7 +4088,7 @@ function ei({
4080
4088
  }),
4081
4089
  [t]
4082
4090
  );
4083
- z(() => {
4091
+ F(() => {
4084
4092
  const b = zt.current;
4085
4093
  zt.current = S;
4086
4094
  const A = ft.current;
@@ -4089,11 +4097,11 @@ function ei({
4089
4097
  Q([]);
4090
4098
  return;
4091
4099
  }
4092
- const j = Ce.current === "submitted" || Ce.current === "streaming" || je.current === "submitted" || je.current === "streaming" || h.current === "in-flight";
4093
- Z.current += 1, V.current = 0, D.current = Promise.resolve(), y.current = new pr(yr), h.current = "idle", k(!1), ze.current = null, re.current = null, C(null), v.current = !1, gt.current = null, mt.current = I === "submitted" || I === "streaming" ? I : null, je.current = "ready", Ce.current = "ready", u(), W((T) => T + 1), oe(!1), Q([]), ne(null), j && Promise.resolve().then(() => b()).catch((T) => {
4094
- ye.error("agent chat client stream cancel failed", T);
4100
+ const R = Ce.current === "submitted" || Ce.current === "streaming" || je.current === "submitted" || je.current === "streaming" || h.current === "in-flight";
4101
+ Z.current += 1, B.current = 0, D.current = Promise.resolve(), y.current = new pr(yr), h.current = "idle", k(!1), Ze.current = null, ae.current = null, C(null), v.current = !1, gt.current = null, mt.current = I === "submitted" || I === "streaming" ? I : null, je.current = "ready", Ce.current = "ready", d(), W((x) => x + 1), oe(!1), Q([]), se(null), R && Promise.resolve().then(() => b()).catch((x) => {
4102
+ ye.error("agent chat client stream cancel failed", x);
4095
4103
  });
4096
- }, [r, I, S, u, ne]), z(() => {
4104
+ }, [r, I, S, d, se]), F(() => {
4097
4105
  var L, X;
4098
4106
  const b = mt.current;
4099
4107
  if (b !== null && I === b) {
@@ -4102,18 +4110,18 @@ function ei({
4102
4110
  }
4103
4111
  mt.current = null;
4104
4112
  const A = je.current;
4105
- if (je.current = I, (I === "submitted" || I === "streaming") && (A !== "submitted" && A !== "streaming" && H.current === null && ne(`turn-resumed-${Et()}`), oe(!0)), I === "streaming") {
4106
- const Y = (L = ze.current) == null ? void 0 : L.userMessage.id;
4113
+ if (je.current = I, (I === "submitted" || I === "streaming") && (A !== "submitted" && A !== "streaming" && G.current === null && se(`turn-resumed-${Et()}`), oe(!0)), I === "streaming") {
4114
+ const Y = (L = Ze.current) == null ? void 0 : L.userMessage.id;
4107
4115
  Y && i.markUserMessageDelivered(Y);
4108
4116
  return;
4109
4117
  }
4110
4118
  if (I !== "ready" && I !== "error") return;
4111
4119
  if (A === "streaming" || A === "submitted" || // An empty response can finish before React observes an active status.
4112
- h.current === "in-flight" && (d == null ? void 0 : d.messages) === m.current) {
4120
+ h.current === "in-flight" && (u == null ? void 0 : u.messages) === m.current) {
4113
4121
  oe(!0), h.current === "in-flight" && (h.current = "idle");
4114
- const Y = m.current.at(-1), Ee = H.current;
4115
- if (re.current = Ee, Ee !== null && Y && Y.role === "assistant" && Xe(Y, Ee), I === "ready") {
4116
- const we = (X = ze.current) == null ? void 0 : X.userMessage.id;
4122
+ const Y = m.current.at(-1), Ee = G.current;
4123
+ if (ae.current = Ee, Ee !== null && Y && Y.role === "assistant" && Xe(Y, Ee), I === "ready") {
4124
+ const we = (X = Ze.current) == null ? void 0 : X.userMessage.id;
4117
4125
  we && i.markUserMessageDelivered(we);
4118
4126
  }
4119
4127
  h.current === "stopping" || (r ? (h.current = "reconciling", t.reconcileAfterStream(r).catch((we) => {
@@ -4123,28 +4131,28 @@ function ei({
4123
4131
  })) : oe(!1));
4124
4132
  }
4125
4133
  if (h.current !== "idle" || !r || ue.current && I !== "error") return;
4126
- const T = y.current.dequeueNext();
4127
- T && (h.current = "in-flight", k(!1), ze.current = T, C(null), v.current = !1, ne(`turn-${T.userMessage.id}`), i.appendUserMessageIfAbsent(T.userMessage), W((Y) => Y + 1), _(
4128
- { text: T.userMessage.content },
4129
- { body: Zt(T) }
4134
+ const x = y.current.dequeueNext();
4135
+ x && (h.current = "in-flight", k(!1), Ze.current = x, C(null), v.current = !1, se(`turn-${x.userMessage.id}`), i.appendUserMessageIfAbsent(x.userMessage), W((Y) => Y + 1), _(
4136
+ { text: x.userMessage.content },
4137
+ { body: Zt(x) }
4130
4138
  ));
4131
4139
  }, [
4132
4140
  I,
4133
4141
  r,
4134
- $,
4142
+ U,
4135
4143
  _,
4136
4144
  i,
4137
4145
  t,
4138
4146
  Zt,
4139
4147
  Xe,
4140
- ne,
4141
- d
4148
+ se,
4149
+ u
4142
4150
  ]);
4143
- const Wt = U(
4151
+ const Wt = q(
4144
4152
  (b) => {
4145
4153
  const A = Z.current;
4146
- V.current++;
4147
- const T = D.current.then(
4154
+ B.current++;
4155
+ const x = D.current.then(
4148
4156
  async () => {
4149
4157
  if (A !== Z.current) return;
4150
4158
  const L = h.current, Y = Ce.current === "submitted" || Ce.current === "streaming" || L !== "idle" || ue.current || y.current.size > 0 ? ti(i.buildQueuedUserMessage(b)) : await i.stageUserTurn(b, { pending: !0 });
@@ -4159,18 +4167,18 @@ function ei({
4159
4167
  W((we) => we + 1), i.notifySendAccepted(b);
4160
4168
  }
4161
4169
  ).finally(() => {
4162
- A === Z.current && V.current--;
4170
+ A === Z.current && B.current--;
4163
4171
  });
4164
- return D.current = T.then(
4172
+ return D.current = x.then(
4165
4173
  () => {
4166
4174
  },
4167
4175
  () => {
4168
4176
  }
4169
- ), T;
4177
+ ), x;
4170
4178
  },
4171
4179
  [i]
4172
- ), la = U(() => {
4173
- const b = ze.current;
4180
+ ), ca = q(() => {
4181
+ const b = Ze.current;
4174
4182
  if (!b) return;
4175
4183
  if (!y.current.enqueue({
4176
4184
  ...b,
@@ -4179,12 +4187,12 @@ function ei({
4179
4187
  ye.warn("agent chat queue full; retry not enqueued");
4180
4188
  return;
4181
4189
  }
4182
- u(), W((j) => j + 1);
4183
- }, [u]), ca = U((b) => {
4190
+ d(), W((R) => R + 1);
4191
+ }, [d]), ua = q((b) => {
4184
4192
  y.current.removeWhere(
4185
- (j) => j.userMessage.id === b
4186
- ) && W((j) => j + 1);
4187
- }, []), ua = U(() => {
4193
+ (R) => R.userMessage.id === b
4194
+ ) && W((R) => R + 1);
4195
+ }, []), da = q(() => {
4188
4196
  h.current = "stopping", k(!0), v.current = !1;
4189
4197
  const b = Z.current;
4190
4198
  Gs({ api: n, sessionId: r, chatStop: S }).then(() => {
@@ -4205,52 +4213,52 @@ function ei({
4205
4213
  b === Z.current && (h.current = "idle", W((A) => A + 1));
4206
4214
  });
4207
4215
  }, [n, r, S, t]);
4208
- z(() => {
4216
+ F(() => {
4209
4217
  const b = {
4210
4218
  send: Wt,
4211
- hasPendingWork: () => V.current > 0 || ue.current || y.current.size > 0 || h.current !== "idle" || Ce.current === "submitted" || Ce.current === "streaming"
4219
+ hasPendingWork: () => B.current > 0 || ue.current || y.current.size > 0 || h.current !== "idle" || Ce.current === "submitted" || Ce.current === "streaming"
4212
4220
  };
4213
4221
  return i.registerAgentHandlers(b), () => i.unregisterAgentHandlers(b);
4214
4222
  }, [i, Wt]);
4215
- const et = (Bt = e.presentation) == null ? void 0 : Bt.toolActivity, tt = (Vt = e.presentation) == null ? void 0 : Vt.reasoning;
4216
- z(() => he([]), [r]), z(() => {
4223
+ const et = (Vt = e.presentation) == null ? void 0 : Vt.toolActivity, tt = (Bt = e.presentation) == null ? void 0 : Bt.reasoning;
4224
+ F(() => he([]), [r]), F(() => {
4217
4225
  var L, X;
4218
4226
  if (!r) return;
4219
- const b = et === void 0 && tt === void 0 ? void 0 : { toolActivity: et, reasoning: tt }, A = gt.current, j = (A == null ? void 0 : A.sessionId) === r && (((L = A.presentation) == null ? void 0 : L.toolActivity) !== et || ((X = A.presentation) == null ? void 0 : X.reasoning) !== tt);
4227
+ const b = et === void 0 && tt === void 0 ? void 0 : { toolActivity: et, reasoning: tt }, A = gt.current, R = (A == null ? void 0 : A.sessionId) === r && (((L = A.presentation) == null ? void 0 : L.toolActivity) !== et || ((X = A.presentation) == null ? void 0 : X.reasoning) !== tt);
4220
4228
  gt.current = { sessionId: r, presentation: b };
4221
- let T = !1;
4229
+ let x = !1;
4222
4230
  return (async () => {
4223
4231
  try {
4224
4232
  const Y = b === void 0 ? await n.getAgentTurnMessages(r) : await n.getAgentTurnMessages(r, b);
4225
- if (!Y || T) return;
4233
+ if (!Y || x) return;
4226
4234
  he(Y.handled_connection_request_ids), Q(
4227
- (Ee) => Js({ existing: Ee, fetched: Y, refreshItems: j })
4235
+ (Ee) => Js({ existing: Ee, fetched: Y, refreshItems: R })
4228
4236
  );
4229
4237
  } catch (Y) {
4230
4238
  ye.error("agent chat turn sources fetch failed", Y);
4231
4239
  }
4232
4240
  })(), () => {
4233
- T = !0;
4241
+ x = !0;
4234
4242
  };
4235
4243
  }, [r, n, et, tt]);
4236
- const [ht, da] = J(() => /* @__PURE__ */ new Set()), rt = R(ht), vt = R(/* @__PURE__ */ new Set()), at = te(() => {
4244
+ const [ht, pa] = J(() => /* @__PURE__ */ new Set()), rt = O(ht), vt = O(/* @__PURE__ */ new Set()), at = te(() => {
4237
4245
  if (w || I !== "streaming" && I !== "submitted")
4238
4246
  return [];
4239
4247
  const b = E.at(-1);
4240
4248
  if (!b || b.role !== "assistant") return [];
4241
4249
  const A = [];
4242
- for (const j of b.parts) {
4243
- if (!$e(j)) continue;
4244
- const T = hs(j), L = T === Qs ? "highlight-element" : T === Xs ? "act-on-page" : null;
4245
- L && j.state === "input-available" && A.push({
4246
- key: `${r ?? "pending"}:${j.toolCallId}`,
4250
+ for (const R of b.parts) {
4251
+ if (!Ue(R)) continue;
4252
+ const x = hs(R), L = x === Qs ? "highlight-element" : x === Xs ? "act-on-page" : null;
4253
+ L && R.state === "input-available" && A.push({
4254
+ key: `${r ?? "pending"}:${R.toolCallId}`,
4247
4255
  type: L,
4248
- input: j.input,
4249
- callId: j.toolCallId
4256
+ input: R.input,
4257
+ callId: R.toolCallId
4250
4258
  });
4251
4259
  }
4252
4260
  return A;
4253
- }, [E, r, I, w]), pa = te(
4261
+ }, [E, r, I, w]), fa = te(
4254
4262
  () => at.filter(
4255
4263
  (b) => s && f && (b.type !== "act-on-page" || c) && !ht.has(b.key)
4256
4264
  ),
@@ -4261,8 +4269,8 @@ function ei({
4261
4269
  c,
4262
4270
  ht
4263
4271
  ]
4264
- ), yt = U(
4265
- (b, A, j, T) => {
4272
+ ), yt = q(
4273
+ (b, A, R, x) => {
4266
4274
  if (!r) return;
4267
4275
  const L = `${r}:${b}`;
4268
4276
  if (rt.current.has(L)) return;
@@ -4272,36 +4280,36 @@ function ei({
4272
4280
  const Y = X.values().next().value;
4273
4281
  Y !== void 0 && X.delete(Y);
4274
4282
  }
4275
- rt.current = X, da(X), n.sendPageReply(r, {
4283
+ rt.current = X, pa(X), n.sendPageReply(r, {
4276
4284
  callId: b,
4277
4285
  outcome: A,
4278
- ...j ? { detail: j } : {},
4286
+ ...R ? { detail: R } : {},
4279
4287
  // The page as it is after the action. Without it a flow that
4280
4288
  // crosses screens stops dead: the agent is holding refs to the
4281
4289
  // screen it just left.
4282
- ...t.features.pageContext && T ? { controls: T.controls, truncated: T.truncated } : {}
4290
+ ...t.features.pageContext && x ? { controls: x.controls, truncated: x.truncated } : {}
4283
4291
  });
4284
4292
  },
4285
4293
  [n, r, t]
4286
- ), [fa, bt] = J(null), Se = R(
4294
+ ), [ma, bt] = J(null), Se = O(
4287
4295
  /* @__PURE__ */ new Map()
4288
- ), ma = U(
4296
+ ), ga = q(
4289
4297
  (b) => new Promise((A) => {
4290
- const j = `${r ?? "pending"}:${b.callId}`;
4291
- if (rt.current.has(j)) {
4298
+ const R = `${r ?? "pending"}:${b.callId}`;
4299
+ if (rt.current.has(R)) {
4292
4300
  A(!1);
4293
4301
  return;
4294
4302
  }
4295
- vt.current.add(j), Se.current.forEach((T) => T(!1)), Se.current.clear(), Se.current.set(b.callId, A), bt(b);
4303
+ vt.current.add(R), Se.current.forEach((x) => x(!1)), Se.current.clear(), Se.current.set(b.callId, A), bt(b);
4296
4304
  }),
4297
4305
  [r]
4298
- ), Ct = U((b, A) => {
4299
- const j = Se.current.get(b);
4306
+ ), Ct = q((b, A) => {
4307
+ const R = Se.current.get(b);
4300
4308
  Se.current.delete(b), bt(
4301
- (T) => (T == null ? void 0 : T.callId) === b ? null : T
4302
- ), j == null || j(A);
4309
+ (x) => (x == null ? void 0 : x.callId) === b ? null : x
4310
+ ), R == null || R(A);
4303
4311
  }, []);
4304
- z(() => {
4312
+ F(() => {
4305
4313
  for (const b of at)
4306
4314
  s && f && (b.type !== "act-on-page" || c) || (Ct(b.callId, !1), vt.current.has(b.key) || yt(b.callId, "declined"));
4307
4315
  }, [
@@ -4313,49 +4321,49 @@ function ei({
4313
4321
  yt
4314
4322
  ]);
4315
4323
  const de = I === "submitted" || I === "streaming";
4316
- z(
4324
+ F(
4317
4325
  () => () => {
4318
4326
  Se.current.forEach((b) => b(!1)), Se.current.clear();
4319
4327
  },
4320
4328
  [r]
4321
- ), z(() => {
4329
+ ), F(() => {
4322
4330
  if (de && !w) return;
4323
4331
  const b = Se.current;
4324
4332
  b.size !== 0 && (b.forEach((A) => A(!1)), b.clear(), bt(null));
4325
- }, [de, w]), z(() => {
4333
+ }, [de, w]), F(() => {
4326
4334
  if (de) return;
4327
- const b = re.current;
4335
+ const b = ae.current;
4328
4336
  if (b === null) return;
4329
4337
  const A = E.at(-1);
4330
4338
  A && A.role === "assistant" && Xe(A, b);
4331
4339
  }, [E, de, Xe]);
4332
- const St = U(() => {
4333
- r && (de || M === void 0 && !ae || g());
4334
- }, [r, de, ae, M, g]);
4335
- z(
4340
+ const St = q(() => {
4341
+ r && (de || M === void 0 && !ne || g());
4342
+ }, [r, de, ne, M, g]);
4343
+ F(
4336
4344
  () => Hs(St),
4337
4345
  [St]
4338
- ), z(() => {
4339
- if (de || !ae) return;
4346
+ ), F(() => {
4347
+ if (de || !ne) return;
4340
4348
  const b = () => {
4341
- oe(!1), W((T) => T + 1), H.current === re.current && ne(null), re.current = null;
4349
+ oe(!1), W((x) => x + 1), G.current === ae.current && se(null), ae.current = null;
4342
4350
  };
4343
- if (H.current === re.current && (d == null ? void 0 : d.messages) === E && !d.isError && !d.isDisconnect && (!d.isAbort || v.current) && !lt(d.message.parts).some(
4344
- (T) => T.kind !== "steps"
4351
+ if (G.current === ae.current && (u == null ? void 0 : u.messages) === E && !u.isError && !u.isDisconnect && (!u.isAbort || v.current) && !lt(u.message.parts).some(
4352
+ (x) => x.kind !== "steps"
4345
4353
  )) {
4346
- const T = a.findLast((L) => L.type === "USER");
4347
- T && i.state.setPartial({ settledAgentUserMessageId: T.id }), b();
4354
+ const x = a.findLast((L) => L.type === "USER");
4355
+ x && i.state.setPartial({ settledAgentUserMessageId: x.id }), b();
4348
4356
  return;
4349
4357
  }
4350
- if (d && d.messages !== E) return;
4351
- const A = E.at(-1), j = (A == null ? void 0 : A.role) === "assistant" ? vr(A.parts) : null;
4352
- if (j && j.rowIds.length > 0) {
4353
- const T = new Set(a.map((L) => L.id));
4354
- j.rowIds.every((L) => T.has(L)) && b();
4358
+ if (u && u.messages !== E) return;
4359
+ const A = E.at(-1), R = (A == null ? void 0 : A.role) === "assistant" ? vr(A.parts) : null;
4360
+ if (R && R.rowIds.length > 0) {
4361
+ const x = new Set(a.map((L) => L.id));
4362
+ R.rowIds.every((L) => x.has(L)) && b();
4355
4363
  return;
4356
4364
  }
4357
- for (let T = a.length - 1; T >= 0; T -= 1) {
4358
- const L = a[T];
4365
+ for (let x = a.length - 1; x >= 0; x -= 1) {
4366
+ const L = a[x];
4359
4367
  if (L) {
4360
4368
  if (L.type === "USER") return;
4361
4369
  if (!(L.type !== "AI" && L.type !== "AGENT")) {
@@ -4366,19 +4374,19 @@ function ei({
4366
4374
  }
4367
4375
  }, [
4368
4376
  de,
4369
- ae,
4370
- a,
4371
4377
  ne,
4372
- d,
4378
+ a,
4379
+ se,
4380
+ u,
4373
4381
  E,
4374
4382
  i,
4375
- $
4383
+ U
4376
4384
  ]);
4377
4385
  const De = wa(
4378
4386
  t.agent.presentation,
4379
4387
  e.presentation
4380
- ), nt = De == null ? void 0 : De.toolActivity, st = De == null ? void 0 : De.reasoning, ga = te(() => {
4381
- if (!Ze || ve === null || I === "submitted" || !de && !ae)
4388
+ ), nt = De == null ? void 0 : De.toolActivity, st = De == null ? void 0 : De.reasoning, ha = te(() => {
4389
+ if (!We || ve === null || I === "submitted" || !de && !ne)
4382
4390
  return [];
4383
4391
  const b = E.at(-1);
4384
4392
  return !b || b.role !== "assistant" ? [] : fr(lt(b.parts), {
@@ -4389,52 +4397,52 @@ function ei({
4389
4397
  E,
4390
4398
  I,
4391
4399
  de,
4392
- ae,
4400
+ ne,
4393
4401
  nt,
4394
4402
  st,
4395
- Ze,
4403
+ We,
4396
4404
  ve
4397
- ]), ha = te(
4398
- () => Ze ? be.flatMap((b) => {
4405
+ ]), va = te(
4406
+ () => We ? be.flatMap((b) => {
4399
4407
  const A = fr(b.items, {
4400
4408
  toolActivity: nt,
4401
4409
  reasoning: st
4402
4410
  });
4403
4411
  return A.length === 0 ? [] : [A === b.items ? b : { ...b, items: A }];
4404
4412
  }) : [],
4405
- [be, nt, st, Ze]
4406
- ), va = te(
4413
+ [be, nt, st, We]
4414
+ ), ya = te(
4407
4415
  () => y.current.items.filter((b) => !b.input.background).map((b) => b.userMessage),
4408
4416
  // eslint-disable-next-line react-hooks/exhaustive-deps -- queueRef is mutable; queueVersion is the signal
4409
- [$]
4417
+ [U]
4410
4418
  );
4411
4419
  return {
4412
4420
  isStreaming: de,
4413
- liveItems: ga,
4421
+ liveItems: ha,
4414
4422
  /** Finished turns' render sources — see `TurnRenderSource`. */
4415
- turnSources: ha,
4423
+ turnSources: va,
4416
4424
  /** The live turn's node key (stable through the retained promotion). */
4417
4425
  liveTurnKey: ve,
4418
4426
  /** The last turn failed — the transcript renders a visible error row. */
4419
4427
  turnFailed: M !== void 0,
4420
- retryFailedTurn: la,
4428
+ retryFailedTurn: ca,
4421
4429
  resumeInterruptedTurn: St,
4422
- queuedUserMessages: va,
4423
- removeQueued: ca,
4424
- stop: ua,
4425
- pageEffects: pa,
4430
+ queuedUserMessages: ya,
4431
+ removeQueued: ua,
4432
+ stop: da,
4433
+ pageEffects: fa,
4426
4434
  replyToPageCall: yt,
4427
- pendingPageAction: fa,
4428
- requestPageActionConsent: ma,
4435
+ pendingPageAction: ma,
4436
+ requestPageActionConsent: ga,
4429
4437
  resolvePageAction: Ct,
4430
- handledConnectionRequestIds: Te,
4431
- sourceSessionId: Ze ? r : null
4438
+ handledConnectionRequestIds: xe,
4439
+ sourceSessionId: We ? r : null
4432
4440
  };
4433
4441
  }
4434
4442
  function ti(t) {
4435
4443
  return t ? { ...t, initialMessages: [] } : null;
4436
4444
  }
4437
- const br = 2e3, Cr = 6e5, ri = 1e4, ut = qe(null), ai = (t, e) => e === "dismiss" ? {
4445
+ const br = 2e3, Cr = 6e5, ri = 1e4, ut = ze(null), ai = (t, e) => e === "dismiss" ? {
4438
4446
  content: `Continue without connecting ${t.name}.`,
4439
4447
  connectionRequestId: t.request_id
4440
4448
  } : e === "renew" ? {
@@ -4458,21 +4466,21 @@ function ni({
4458
4466
  }) {
4459
4467
  const [n, i] = J("idle"), [l, s] = J(null), [f, c] = J(
4460
4468
  null
4461
- ), [p, d] = J(null), C = R(new AbortController()), v = R(null), O = R(/* @__PURE__ */ new Set()), I = R(null), E = R(null), _ = R(null), S = R(!0), M = R((e == null ? void 0 : e.request_id) ?? null);
4469
+ ), [p, u] = J(null), C = O(new AbortController()), v = O(null), N = O(/* @__PURE__ */ new Set()), I = O(null), E = O(null), _ = O(null), S = O(!0), M = O((e == null ? void 0 : e.request_id) ?? null);
4462
4470
  M.current = (e == null ? void 0 : e.request_id) ?? null;
4463
- const u = U(() => {
4471
+ const d = q(() => {
4464
4472
  var D;
4465
4473
  C.current.abort(), (D = v.current) == null || D.close(), v.current = null;
4466
4474
  }, []);
4467
- z(() => (u(), _.current = null, E.current = null, I.current = null, i("idle"), s(null), c(null), d(null), u), [u, e == null ? void 0 : e.request_id, e == null ? void 0 : e.server_id, r]), z(() => (S.current = !0, () => {
4468
- S.current = !1, u();
4469
- }), [u]);
4470
- const g = U(
4475
+ F(() => (d(), _.current = null, E.current = null, I.current = null, i("idle"), s(null), c(null), u(null), d), [d, e == null ? void 0 : e.request_id, e == null ? void 0 : e.server_id, r]), F(() => (S.current = !0, () => {
4476
+ S.current = !1, d();
4477
+ }), [d]);
4478
+ const g = q(
4471
4479
  async (D) => {
4472
4480
  if (!e) return;
4473
- const V = e.request_id;
4474
- if (O.current.has(V)) return;
4475
- O.current.add(V), I.current = D, c(D), d(null);
4481
+ const B = e.request_id;
4482
+ if (N.current.has(B)) return;
4483
+ N.current.add(B), I.current = D, c(D), u(null);
4476
4484
  let Z = !1;
4477
4485
  try {
4478
4486
  await r.messageCtx.sendMessage({
@@ -4480,82 +4488,82 @@ function ni({
4480
4488
  onAccepted: () => {
4481
4489
  Z = !0, a(e.request_id);
4482
4490
  }
4483
- }), S.current && M.current === V && !Z && d(
4491
+ }), S.current && M.current === B && !Z && u(
4484
4492
  D === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
4485
4493
  );
4486
4494
  } catch {
4487
- S.current && M.current === V && d(
4495
+ S.current && M.current === B && u(
4488
4496
  D === "renew" ? "Could not request a new connection. Try again." : "Could not continue your request. Try again."
4489
4497
  );
4490
4498
  } finally {
4491
- O.current.delete(V), S.current && M.current === V && c(null);
4499
+ N.current.delete(B), S.current && M.current === B && c(null);
4492
4500
  }
4493
4501
  },
4494
4502
  [a, e, r]
4495
- ), m = U(async () => {
4496
- var V, Z;
4503
+ ), m = q(async () => {
4504
+ var B, Z;
4497
4505
  if (!e) return;
4498
- u(), _.current = e.request_id, C.current = new AbortController();
4506
+ d(), _.current = e.request_id, C.current = new AbortController();
4499
4507
  const { signal: D } = C.current;
4500
- i("loading"), I.current = null, s(null), d(null);
4508
+ i("loading"), I.current = null, s(null), u(null);
4501
4509
  try {
4502
4510
  v.current = window.open("about:blank", "_blank"), v.current && (v.current.opener = null);
4503
- const $ = await r.api.startConnection(
4511
+ const U = await r.api.startConnection(
4504
4512
  e.server_id,
4505
4513
  e.request_id,
4506
4514
  D
4507
4515
  );
4508
4516
  if (D.aborted) return;
4509
- const W = new URL($.authorization_url);
4517
+ const W = new URL(U.authorization_url);
4510
4518
  if (!(W.protocol === "https:" || W.protocol === "http:" && ["localhost", "127.0.0.1", "[::1]"].includes(W.hostname)) || W.username || W.password)
4511
4519
  throw new Error("Invalid connection page");
4512
4520
  s({
4513
4521
  url: W.href,
4514
4522
  host: W.host,
4515
- completion: $.completion,
4516
- ...$.completion === "oauth" ? { attemptId: $.attempt_id } : {}
4517
- }), E.current = Date.now() + Cr, (V = v.current) != null && V.closed ? (v.current = null, i("ready")) : v.current ? (v.current.location.replace(W.href), i("waiting")) : i("ready");
4518
- } catch ($) {
4523
+ completion: U.completion,
4524
+ ...U.completion === "oauth" ? { attemptId: U.attempt_id } : {}
4525
+ }), E.current = Date.now() + Cr, (B = v.current) != null && B.closed ? (v.current = null, i("ready")) : v.current ? (v.current.location.replace(W.href), i("waiting")) : i("ready");
4526
+ } catch (U) {
4519
4527
  if (D.aborted) return;
4520
- if ((Z = v.current) == null || Z.close(), v.current = null, s(null), i("idle"), $ instanceof Ia) {
4528
+ if ((Z = v.current) == null || Z.close(), v.current = null, s(null), i("idle"), U instanceof Ia) {
4521
4529
  await g("renew");
4522
4530
  return;
4523
4531
  }
4524
- d(
4525
- $ instanceof Error ? $.message : "Could not start the connection."
4532
+ u(
4533
+ U instanceof Error ? U.message : "Could not start the connection."
4526
4534
  );
4527
4535
  }
4528
- }, [u, e, g, r]);
4529
- z(() => {
4536
+ }, [d, e, g, r]);
4537
+ F(() => {
4530
4538
  if (n !== "waiting" && n !== "ready" || !l || !e)
4531
4539
  return;
4532
4540
  const D = new AbortController();
4533
- let V;
4541
+ let B;
4534
4542
  const Z = E.current ?? Date.now() + Cr;
4535
4543
  E.current = Z;
4536
- let $ = 0, W = document.hidden || !document.hasFocus(), ae = !1;
4544
+ let U = 0, W = document.hidden || !document.hasFocus(), ne = !1;
4537
4545
  const oe = () => {
4538
4546
  W = !0;
4539
4547
  }, ue = () => {
4540
- W && (ae = !0);
4548
+ W && (ne = !0);
4541
4549
  }, be = () => document.hidden ? oe() : ue();
4542
4550
  window.addEventListener("blur", oe), window.addEventListener("focus", ue), document.addEventListener("visibilitychange", be);
4543
- const Q = (q) => {
4544
- var H;
4545
- D.abort(), (H = v.current) == null || H.close(), v.current = null, d(q), i("idle");
4546
- }, Te = setTimeout(
4551
+ const Q = (z) => {
4552
+ var G;
4553
+ D.abort(), (G = v.current) == null || G.close(), v.current = null, u(z), i("idle");
4554
+ }, xe = setTimeout(
4547
4555
  () => Q("Connection timed out. Try again."),
4548
4556
  Math.max(0, Z - Date.now())
4549
- ), he = (q = br) => {
4550
- V = setTimeout(ve, q);
4557
+ ), he = (z = br) => {
4558
+ B = setTimeout(ve, z);
4551
4559
  }, ve = async () => {
4552
- var q, H, ne;
4560
+ var z, G, se;
4553
4561
  if (Date.now() >= Z) {
4554
4562
  Q("Connection timed out. Try again.");
4555
4563
  return;
4556
4564
  }
4557
4565
  if (l.completion === "external") {
4558
- if (n === "waiting" && ((q = v.current) != null && q.closed || ae)) {
4566
+ if (n === "waiting" && ((z = v.current) != null && z.closed || ne)) {
4559
4567
  i("external");
4560
4568
  return;
4561
4569
  }
@@ -4567,52 +4575,52 @@ function ni({
4567
4575
  return;
4568
4576
  }
4569
4577
  try {
4570
- const re = await r.api.getConnectionAttempt(
4578
+ const ae = await r.api.getConnectionAttempt(
4571
4579
  e.server_id,
4572
4580
  l.attemptId,
4573
4581
  D.signal
4574
4582
  );
4575
4583
  if (D.signal.aborted) return;
4576
- if ($ = 0, re === "connected") {
4577
- (H = v.current) == null || H.close(), v.current = null, i("connected");
4584
+ if (U = 0, ae === "connected") {
4585
+ (G = v.current) == null || G.close(), v.current = null, i("connected");
4578
4586
  return;
4579
4587
  }
4580
- if (re === "canceled") {
4588
+ if (ae === "canceled") {
4581
4589
  Q("Connection was canceled. Try again.");
4582
4590
  return;
4583
4591
  }
4584
- if (re === "failed") {
4592
+ if (ae === "failed") {
4585
4593
  Q("Connection approval failed. Try again.");
4586
4594
  return;
4587
4595
  }
4588
- if (re === "expired") {
4596
+ if (ae === "expired") {
4589
4597
  Q("Connection attempt expired. Try again.");
4590
4598
  return;
4591
4599
  }
4592
- (ne = v.current) != null && ne.closed && (v.current = null, i("ready")), he();
4593
- } catch (re) {
4600
+ (se = v.current) != null && se.closed && (v.current = null, i("ready")), he();
4601
+ } catch (ae) {
4594
4602
  if (D.signal.aborted) return;
4595
- if (re instanceof _a) {
4596
- Q(re.message);
4603
+ if (ae instanceof _a) {
4604
+ Q(ae.message);
4597
4605
  return;
4598
4606
  }
4599
- $ += 1, he(
4607
+ U += 1, he(
4600
4608
  Math.min(
4601
- br * 2 ** ($ - 1),
4609
+ br * 2 ** (U - 1),
4602
4610
  ri
4603
4611
  )
4604
4612
  );
4605
4613
  }
4606
4614
  };
4607
4615
  return ve(), () => {
4608
- D.abort(), V && clearTimeout(V), Te && clearTimeout(Te), window.removeEventListener("blur", oe), window.removeEventListener("focus", ue), document.removeEventListener("visibilitychange", be);
4616
+ D.abort(), B && clearTimeout(B), xe && clearTimeout(xe), window.removeEventListener("blur", oe), window.removeEventListener("focus", ue), document.removeEventListener("visibilitychange", be);
4609
4617
  };
4610
- }, [l, n, e, r]), z(() => {
4618
+ }, [l, n, e, r]), F(() => {
4611
4619
  n !== "connected" && n !== "external" || _.current !== (e == null ? void 0 : e.request_id) || g(n === "external" ? "external" : "resume");
4612
4620
  }, [n, e == null ? void 0 : e.request_id, g]);
4613
- const y = U(() => i("waiting"), []), h = U(async () => {
4614
- u(), s(null), i("idle"), await g("dismiss");
4615
- }, [u, g]), w = U(async () => {
4621
+ const y = q(() => i("waiting"), []), h = q(async () => {
4622
+ d(), s(null), i("idle"), await g("dismiss");
4623
+ }, [d, g]), w = q(async () => {
4616
4624
  const D = I.current;
4617
4625
  if (D) {
4618
4626
  await g(D);
@@ -4664,7 +4672,7 @@ function si({
4664
4672
  function ii() {
4665
4673
  return Ne(ut);
4666
4674
  }
4667
- function Pi(t) {
4675
+ function ji(t) {
4668
4676
  const e = Ne(ut);
4669
4677
  if (!e || e.request.request_id !== t.request_id)
4670
4678
  throw new Error(
@@ -4696,8 +4704,8 @@ const qt = {
4696
4704
  },
4697
4705
  pendingClarification: null,
4698
4706
  pendingConnection: null
4699
- }, dt = qe(null);
4700
- function Gr() {
4707
+ }, dt = ze(null);
4708
+ function Qr() {
4701
4709
  return Ne(dt) ?? qt;
4702
4710
  }
4703
4711
  function oi({
@@ -4705,61 +4713,61 @@ function oi({
4705
4713
  widgetCtx: e,
4706
4714
  config: r
4707
4715
  }) {
4708
- var ue, be, Q, Te, he, ve;
4709
- const a = G(e.sessionCtx.sessionState), n = G(e.messageCtx.state), {
4716
+ var ue, be, Q, xe, he, ve;
4717
+ const a = H(e.sessionCtx.sessionState), n = H(e.messageCtx.state), {
4710
4718
  isStreaming: i,
4711
4719
  liveItems: l,
4712
4720
  turnSources: s,
4713
4721
  liveTurnKey: f,
4714
4722
  turnFailed: c,
4715
4723
  retryFailedTurn: p,
4716
- resumeInterruptedTurn: d,
4724
+ resumeInterruptedTurn: u,
4717
4725
  queuedUserMessages: C,
4718
4726
  removeQueued: v,
4719
- stop: O,
4727
+ stop: N,
4720
4728
  pageEffects: I,
4721
4729
  replyToPageCall: E,
4722
4730
  pendingPageAction: _,
4723
4731
  requestPageActionConsent: S,
4724
4732
  resolvePageAction: M,
4725
- handledConnectionRequestIds: u,
4733
+ handledConnectionRequestIds: d,
4726
4734
  sourceSessionId: g
4727
4735
  } = ei({
4728
4736
  widgetCtx: e,
4729
4737
  config: r,
4730
4738
  sessionId: ((ue = a.session) == null ? void 0 : ue.id) ?? null,
4731
4739
  persistedMessages: n.messages
4732
- }), m = ((be = n.messages.at(-1)) == null ? void 0 : be.type) === "USER", y = R(/* @__PURE__ */ new Set()), h = R(((Q = a.session) == null ? void 0 : Q.id) ?? null), w = ((Te = a.session) == null ? void 0 : Te.id) ?? null;
4733
- h.current !== w && (h.current = w, y.current.clear()), u.forEach(
4734
- (q) => y.current.add(q)
4740
+ }), m = ((be = n.messages.at(-1)) == null ? void 0 : be.type) === "USER", y = O(/* @__PURE__ */ new Set()), h = O(((Q = a.session) == null ? void 0 : Q.id) ?? null), w = ((xe = a.session) == null ? void 0 : xe.id) ?? null;
4741
+ h.current !== w && (h.current = w, y.current.clear()), d.forEach(
4742
+ (z) => y.current.add(z)
4735
4743
  );
4736
4744
  const k = (he = [
4737
- ...s.flatMap((q) => q.items),
4745
+ ...s.flatMap((z) => z.items),
4738
4746
  ...l
4739
4747
  ].findLast(
4740
- (q) => q.kind === "connection" && !y.current.has(q.request.request_id)
4741
- )) == null ? void 0 : he.request, [D, V] = J({ sessionId: w, request: null }), Z = ((ve = r.capabilities) == null ? void 0 : ve.connections) === !0, $ = Z && w !== null && D.sessionId === w ? D.request : null;
4742
- z(() => {
4743
- !Z || w === null || g !== w || V((q) => {
4744
- const H = q.sessionId === w && q.request && !y.current.has(q.request.request_id) ? q.request : k ?? null;
4745
- return q.sessionId === w && q.request === H ? q : { sessionId: w, request: H };
4748
+ (z) => z.kind === "connection" && !y.current.has(z.request.request_id)
4749
+ )) == null ? void 0 : he.request, [D, B] = J({ sessionId: w, request: null }), Z = ((ve = r.capabilities) == null ? void 0 : ve.connections) === !0, U = Z && w !== null && D.sessionId === w ? D.request : null;
4750
+ F(() => {
4751
+ !Z || w === null || g !== w || B((z) => {
4752
+ const G = z.sessionId === w && z.request && !y.current.has(z.request.request_id) ? z.request : k ?? null;
4753
+ return z.sessionId === w && z.request === G ? z : { sessionId: w, request: G };
4746
4754
  });
4747
4755
  }, [
4748
4756
  w,
4749
4757
  g,
4750
4758
  k,
4751
- u,
4759
+ d,
4752
4760
  Z,
4753
- $
4761
+ U
4754
4762
  ]);
4755
- const W = U((q) => {
4756
- y.current.add(q), V(
4757
- (H) => {
4758
- var ne;
4759
- return ((ne = H.request) == null ? void 0 : ne.request_id) === q ? { ...H, request: null } : H;
4763
+ const W = q((z) => {
4764
+ y.current.add(z), B(
4765
+ (G) => {
4766
+ var se;
4767
+ return ((se = G.request) == null ? void 0 : se.request_id) === z ? { ...G, request: null } : G;
4760
4768
  }
4761
4769
  );
4762
- }, []), ae = te(
4770
+ }, []), ne = te(
4763
4771
  () => ({
4764
4772
  isStreaming: i,
4765
4773
  liveItems: l,
@@ -4767,16 +4775,16 @@ function oi({
4767
4775
  liveTurnKey: f,
4768
4776
  turnFailed: c,
4769
4777
  retryFailedTurn: p,
4770
- resumeInterruptedTurn: d,
4778
+ resumeInterruptedTurn: u,
4771
4779
  queuedUserMessages: C,
4772
4780
  removeQueued: v,
4773
- stop: O,
4781
+ stop: N,
4774
4782
  pageEffects: I,
4775
4783
  replyToPageCall: E,
4776
4784
  pendingPageAction: _,
4777
4785
  requestPageActionConsent: S,
4778
4786
  resolvePageAction: M,
4779
- pendingConnection: $,
4787
+ pendingConnection: U,
4780
4788
  pendingClarification: Oa({
4781
4789
  turnSources: s,
4782
4790
  liveItems: l,
@@ -4791,35 +4799,35 @@ function oi({
4791
4799
  f,
4792
4800
  c,
4793
4801
  p,
4794
- d,
4802
+ u,
4795
4803
  C,
4796
4804
  v,
4797
- O,
4805
+ N,
4798
4806
  I,
4799
4807
  E,
4800
4808
  _,
4801
4809
  S,
4802
4810
  M,
4803
4811
  m,
4804
- $
4812
+ U
4805
4813
  ]
4806
- ), oe = /* @__PURE__ */ K.createElement(dt.Provider, { value: ae }, t);
4814
+ ), oe = /* @__PURE__ */ K.createElement(dt.Provider, { value: ne }, t);
4807
4815
  return /* @__PURE__ */ K.createElement(
4808
4816
  ni,
4809
4817
  {
4810
- request: $,
4818
+ request: U,
4811
4819
  widgetCtx: e,
4812
4820
  onHandled: W
4813
4821
  },
4814
4822
  oe
4815
4823
  );
4816
4824
  }
4817
- function Qr({
4825
+ function Xr({
4818
4826
  children: t,
4819
4827
  widgetCtx: e,
4820
4828
  config: r
4821
4829
  }) {
4822
- return G(e.messageCtx.state), e.streaming ? /* @__PURE__ */ K.createElement(oi, { widgetCtx: e, config: r }, t) : /* @__PURE__ */ K.createElement(dt.Provider, { value: qt }, t);
4830
+ return H(e.messageCtx.state), e.streaming ? /* @__PURE__ */ K.createElement(oi, { widgetCtx: e, config: r }, t) : /* @__PURE__ */ K.createElement(dt.Provider, { value: qt }, t);
4823
4831
  }
4824
4832
  class li {
4825
4833
  constructor(e) {
@@ -4852,16 +4860,16 @@ class li {
4852
4860
  }));
4853
4861
  }, this.close = (a) => {
4854
4862
  if (this.disposed) return;
4855
- const { chats: n, activeId: i } = this.state.get(), l = n.findIndex((d) => d.id === a && !d.closed), s = n[l];
4863
+ const { chats: n, activeId: i } = this.state.get(), l = n.findIndex((u) => u.id === a && !u.closed), s = n[l];
4856
4864
  if (!s) return;
4857
- const f = this.isWorking(s), c = f ? n.map((d) => d.id === a ? { ...d, closed: !0 } : d) : n.filter((d) => d.id !== a);
4858
- let p = c.find((d) => d.id === i && !d.closed) ?? c.slice(0, l).reverse().find((d) => !d.closed) ?? c.find((d) => !d.closed);
4865
+ const f = this.isWorking(s), c = f ? n.map((u) => u.id === a ? { ...u, closed: !0 } : u) : n.filter((u) => u.id !== a);
4866
+ let p = c.find((u) => u.id === i && !u.closed) ?? c.slice(0, l).reverse().find((u) => !u.closed) ?? c.find((u) => !u.closed);
4859
4867
  p || (p = this.makeChat(this.root.createConversation()), c.push(p)), p.ctx.routerCtx.navigateConversation = this.open, this.root.sessionCtx.trackActiveSession(p.ctx.sessionCtx), this.state.set({ chats: c, activeId: p.id }), f || this.releaseChat(s);
4860
4868
  }, this.canCreateChat = () => !this.disposed && (!this.root.config.oneOpenSessionAllowed || !this.state.get().chats.some(({ ctx: a }) => {
4861
4869
  const { session: n, isCreatingSession: i } = a.sessionCtx.sessionState.get();
4862
4870
  return (n == null ? void 0 : n.isOpened) || i;
4863
4871
  }) && !this.root.sessionCtx.sessionsState.get().data.some((a) => a.isOpened)), this.open = (a) => {
4864
- var f, c, p, d;
4872
+ var f, c, p, u;
4865
4873
  if (this.disposed) return;
4866
4874
  const { chats: n } = this.state.get();
4867
4875
  if (!a && !this.canCreateChat()) return;
@@ -4878,7 +4886,7 @@ class li {
4878
4886
  const l = a ? this.root.sessionCtx.sessionsState.get().data.find((C) => C.id === a) : void 0;
4879
4887
  if (a && !l) return;
4880
4888
  const s = n.find((C) => this.isEmpty(C)) ?? this.makeChat(this.root.createConversation());
4881
- return l && (n.includes(s) && s.ctx.resetChat(), s.ctx.sessionCtx.sessionState.setPartial({ session: l })), n.includes(s) || this.state.setPartial({ chats: [...n, s] }), this.select(s.id), (d = (p = this.root.config.hooks) == null ? void 0 : p.onNavigateToChat) == null || d.call(p, { session: l }), s.ctx;
4889
+ return l && (n.includes(s) && s.ctx.resetChat(), s.ctx.sessionCtx.sessionState.setPartial({ session: l })), n.includes(s) || this.state.setPartial({ chats: [...n, s] }), this.select(s.id), (u = (p = this.root.config.hooks) == null ? void 0 : p.onNavigateToChat) == null || u.call(p, { session: l }), s.ctx;
4882
4890
  }, this.update = (a, n) => {
4883
4891
  const i = this.state.get().chats.find((s) => s.id === a);
4884
4892
  if (!i) return;
@@ -4894,7 +4902,7 @@ class li {
4894
4902
  });
4895
4903
  };
4896
4904
  const r = this.makeChat(e);
4897
- this.state = new Er({ chats: [r], activeId: r.id });
4905
+ this.state = new wr({ chats: [r], activeId: r.id });
4898
4906
  }
4899
4907
  makeChat(e) {
4900
4908
  return {
@@ -4919,15 +4927,15 @@ class li {
4919
4927
  return !e.closed && !r && !this.isWorking(e) && !e.ctx.messageCtx.state.get().messages.length && !a && !n.length && !e.ctx.uploadCtx.state.get().length;
4920
4928
  }
4921
4929
  }
4922
- const Xr = qe(null), ci = new Er({ chats: [], activeId: 0 });
4923
- function ea() {
4924
- const t = Ne(Xr), e = G((t == null ? void 0 : t.state) ?? ci), r = e.chats.filter((n) => !n.closed), a = r.filter(
4930
+ const ea = ze(null), ci = new wr({ chats: [], activeId: 0 });
4931
+ function ta() {
4932
+ const t = Ne(ea), e = H((t == null ? void 0 : t.state) ?? ci), r = e.chats.filter((n) => !n.closed), a = r.filter(
4925
4933
  (n) => n.hasSession || n.working || n.hasDraft || n.title
4926
4934
  );
4927
4935
  return { workspace: t, chats: r, openChats: a, activeId: e.activeId };
4928
4936
  }
4929
- function Ri() {
4930
- const { workspace: t, ...e } = ea();
4937
+ function Di() {
4938
+ const { workspace: t, ...e } = ta();
4931
4939
  if (!t)
4932
4940
  throw new Error("Companion chats require a conversation workspace");
4933
4941
  return {
@@ -4942,28 +4950,28 @@ function ui({
4942
4950
  ctx: e,
4943
4951
  workspace: r
4944
4952
  }) {
4945
- const a = Gr(), n = ii(), i = G(e.messageCtx.state), l = G(e.sessionCtx.sessionState), s = G(e.messageCtx.draftState), f = G(e.uploadCtx.state), c = i.messages.find(
4946
- (O) => O.type === "USER"
4947
- ), p = (c == null ? void 0 : c.type) === "USER" ? c.content.slice(0, 60) : "", d = a.isStreaming || i.isSendingMessage || l.isCreatingSession, C = !!l.session, v = !!s.text || s.mentions.length > 0 || f.length > 0;
4948
- return z(
4953
+ const a = Qr(), n = ii(), i = H(e.messageCtx.state), l = H(e.sessionCtx.sessionState), s = H(e.messageCtx.draftState), f = H(e.uploadCtx.state), c = i.messages.find(
4954
+ (N) => N.type === "USER"
4955
+ ), p = (c == null ? void 0 : c.type) === "USER" ? c.content.slice(0, 60) : "", u = a.isStreaming || i.isSendingMessage || l.isCreatingSession, C = !!l.session, v = !!s.text || s.mentions.length > 0 || f.length > 0;
4956
+ return F(
4949
4957
  () => r.update(t, {
4950
4958
  title: p,
4951
- working: d,
4959
+ working: u,
4952
4960
  hasSession: C,
4953
4961
  hasDraft: v,
4954
4962
  ui: a,
4955
4963
  connection: n
4956
4964
  }),
4957
- [r, t, p, d, C, v, a, n]
4965
+ [r, t, p, u, C, v, a, n]
4958
4966
  ), null;
4959
4967
  }
4960
- const di = ya(function({
4968
+ const di = ba(function({
4961
4969
  chatId: e,
4962
4970
  ctx: r,
4963
4971
  config: a,
4964
4972
  workspace: n
4965
4973
  }) {
4966
- return /* @__PURE__ */ K.createElement(Qr, { widgetCtx: r, config: a }, /* @__PURE__ */ K.createElement(ui, { chatId: e, ctx: r, workspace: n }));
4974
+ return /* @__PURE__ */ K.createElement(Xr, { widgetCtx: r, config: a }, /* @__PURE__ */ K.createElement(ui, { chatId: e, ctx: r, workspace: n }));
4967
4975
  });
4968
4976
  function pi({
4969
4977
  widgetCtx: t,
@@ -4974,8 +4982,8 @@ function pi({
4974
4982
  () => new li(t),
4975
4983
  [t]
4976
4984
  );
4977
- z(() => a.mount(), [a]);
4978
- const { chats: n, activeId: i } = G(a.state), l = n.find((f) => f.id === i), s = te(
4985
+ F(() => a.mount(), [a]);
4986
+ const { chats: n, activeId: i } = H(a.state), l = n.find((f) => f.id === i), s = te(
4979
4987
  () => n.map((f) => /* @__PURE__ */ K.createElement(
4980
4988
  di,
4981
4989
  {
@@ -4988,7 +4996,7 @@ function pi({
4988
4996
  )),
4989
4997
  [n, e, a]
4990
4998
  );
4991
- return /* @__PURE__ */ K.createElement(Xr.Provider, { value: a }, s, /* @__PURE__ */ K.createElement(si, { connection: l.connection }, /* @__PURE__ */ K.createElement(dt.Provider, { value: l.ui }, r(l.ctx))));
4999
+ return /* @__PURE__ */ K.createElement(ea.Provider, { value: a }, s, /* @__PURE__ */ K.createElement(si, { connection: l.connection }, /* @__PURE__ */ K.createElement(dt.Provider, { value: l.ui }, r(l.ctx))));
4992
5000
  }
4993
5001
  class fi {
4994
5002
  constructor(e) {
@@ -5016,17 +5024,17 @@ class fi {
5016
5024
  return (r = this.get(e)) == null ? void 0 : r.component;
5017
5025
  }
5018
5026
  }
5019
- const Sr = N.object({
5020
- org_id: N.string(),
5021
- contact: N.object({ id: N.string(), verified: N.boolean() }),
5022
- mcp_access: N.object({
5023
- server_ids: N.array(N.string()),
5024
- account_id: N.string().optional()
5027
+ const Sr = j.object({
5028
+ org_id: j.string(),
5029
+ contact: j.object({ id: j.string(), verified: j.boolean() }),
5030
+ mcp_access: j.object({
5031
+ server_ids: j.array(j.string()),
5032
+ account_id: j.string().optional()
5025
5033
  }).optional()
5026
- }), mi = N.union([
5027
- N.object({
5028
- sub: N.object({
5029
- type: N.literal("widget-contact"),
5034
+ }), mi = j.union([
5035
+ j.object({
5036
+ sub: j.object({
5037
+ type: j.literal("widget-contact"),
5030
5038
  payload: Sr
5031
5039
  })
5032
5040
  }).transform(({ sub: t }) => t.payload),
@@ -5071,8 +5079,8 @@ const Sr = N.object({
5071
5079
  externalId: e.externalId ?? null,
5072
5080
  opaqueToken: r
5073
5081
  });
5074
- }, ta = qe(null);
5075
- function Oi({
5082
+ }, ra = ze(null);
5083
+ function ki({
5076
5084
  options: t,
5077
5085
  children: e,
5078
5086
  components: r,
@@ -5081,24 +5089,24 @@ function Oi({
5081
5089
  errorComponent: i
5082
5090
  }) {
5083
5091
  var _;
5084
- const l = R(Promise.resolve()), s = R(t);
5092
+ const l = O(Promise.resolve()), s = O(t);
5085
5093
  s.current = t;
5086
- const f = hi(t), c = R(null), p = R(null), d = R(null), [C, v] = J({ status: "loading" }), O = te(
5094
+ const f = hi(t), c = O(null), p = O(null), u = O(null), [C, v] = J({ status: "loading" }), N = te(
5087
5095
  () => new fi({
5088
5096
  components: r
5089
5097
  }),
5090
5098
  [r]
5091
5099
  );
5092
- if (z(() => {
5093
- var u, g, m;
5094
- if (((u = d.current) == null ? void 0 : u.identity) !== f) {
5095
- const y = (g = d.current) == null ? void 0 : g.widgetCtx.dispose({
5100
+ if (F(() => {
5101
+ var d, g, m;
5102
+ if (((d = u.current) == null ? void 0 : d.identity) !== f) {
5103
+ const y = (g = u.current) == null ? void 0 : g.widgetCtx.dispose({
5096
5104
  clearActiveSession: !0
5097
5105
  });
5098
5106
  l.current = Promise.all([l.current, y]).then(
5099
5107
  () => {
5100
5108
  }
5101
- ), d.current = null;
5109
+ ), u.current = null;
5102
5110
  }
5103
5111
  ((m = p.current) == null ? void 0 : m.identity) !== f && (v({ status: "loading" }), p.current = {
5104
5112
  identity: f,
@@ -5119,7 +5127,7 @@ function Oi({
5119
5127
  y.dispose();
5120
5128
  return;
5121
5129
  }
5122
- d.current = { identity: M, widgetCtx: y }, v({
5130
+ u.current = { identity: M, widgetCtx: y }, v({
5123
5131
  status: "ready",
5124
5132
  identity: M,
5125
5133
  widgetCtx: y
@@ -5136,13 +5144,13 @@ function Oi({
5136
5144
  });
5137
5145
  }
5138
5146
  );
5139
- }, [f, t, a]), z(
5147
+ }, [f, t, a]), F(
5140
5148
  () => () => {
5141
5149
  var S;
5142
- p.current = null, (S = d.current) == null || S.widgetCtx.dispose(), d.current = null;
5150
+ p.current = null, (S = u.current) == null || S.widgetCtx.dispose(), u.current = null;
5143
5151
  },
5144
5152
  []
5145
- ), ba(() => {
5153
+ ), Ca(() => {
5146
5154
  var S;
5147
5155
  C.status !== "ready" || C.identity !== f || (S = t.user) != null && S.token && C.widgetCtx.api.setAuthToken(t.user.token);
5148
5156
  }, [(_ = t.user) == null ? void 0 : _.token, f, C]), C.status === "loading" || "identity" in C && C.identity !== f)
@@ -5150,13 +5158,13 @@ function Oi({
5150
5158
  if (C.status === "error")
5151
5159
  return i ? /* @__PURE__ */ K.createElement(K.Fragment, null, i(C.error)) : null;
5152
5160
  const { widgetCtx: I } = C, E = (S, M) => /* @__PURE__ */ K.createElement(
5153
- ta.Provider,
5161
+ ra.Provider,
5154
5162
  {
5155
5163
  value: {
5156
5164
  widgetCtx: S,
5157
5165
  config: t,
5158
5166
  components: r,
5159
- componentStore: O,
5167
+ componentStore: N,
5160
5168
  version: Ra,
5161
5169
  contentIframeRef: c
5162
5170
  }
@@ -5165,16 +5173,16 @@ function Oi({
5165
5173
  );
5166
5174
  return t.displayMode === "companion" && !t.inline ? /* @__PURE__ */ K.createElement(pi, { widgetCtx: I, config: t }, (S) => E(S, e)) : E(
5167
5175
  I,
5168
- /* @__PURE__ */ K.createElement(Qr, { key: f, widgetCtx: I, config: t }, e)
5176
+ /* @__PURE__ */ K.createElement(Xr, { key: f, widgetCtx: I, config: t }, e)
5169
5177
  );
5170
5178
  }
5171
- function ie() {
5172
- const t = Ne(ta);
5179
+ function re() {
5180
+ const t = Ne(ra);
5173
5181
  if (!t)
5174
5182
  throw new Error("useWidget must be used within a WidgetProvider");
5175
5183
  return t;
5176
5184
  }
5177
- function Ni({
5185
+ function Li({
5178
5186
  liveItems: t,
5179
5187
  turnSources: e
5180
5188
  }) {
@@ -5188,8 +5196,8 @@ function Ni({
5188
5196
  if (i) return i.plan;
5189
5197
  }
5190
5198
  }
5191
- function ji() {
5192
- const { config: t, widgetCtx: e } = ie(), { name: r, avatarUrl: a } = e.agent, n = t.bot;
5199
+ function Fi() {
5200
+ const { config: t, widgetCtx: e } = re(), { name: r, avatarUrl: a } = e.agent, n = t.bot;
5193
5201
  return te(
5194
5202
  () => ({
5195
5203
  isAi: !0,
@@ -5202,23 +5210,23 @@ function ji() {
5202
5210
  );
5203
5211
  }
5204
5212
  function pt() {
5205
- const { config: t } = ie();
5213
+ const { config: t } = re();
5206
5214
  return t;
5207
5215
  }
5208
- function Di() {
5209
- const { config: t } = ie();
5216
+ function $i() {
5217
+ const { config: t } = re();
5210
5218
  return t.displayMode ?? "popover";
5211
5219
  }
5212
- function ki() {
5213
- const { widgetCtx: t } = ie();
5220
+ function Ui() {
5221
+ const { widgetCtx: t } = re();
5214
5222
  return {
5215
- contactState: G(t.contactCtx.state),
5223
+ contactState: H(t.contactCtx.state),
5216
5224
  createUnverifiedContact: t.contactCtx.createUnverifiedContact
5217
5225
  };
5218
5226
  }
5219
5227
  function vi() {
5220
5228
  const [t, e] = J("ltr");
5221
- return z(() => {
5229
+ return F(() => {
5222
5230
  const r = () => {
5223
5231
  typeof document > "u" || e(
5224
5232
  window.getComputedStyle((window.top || window).document.body).direction
@@ -5238,7 +5246,7 @@ function vi() {
5238
5246
  }, []), { dir: t };
5239
5247
  }
5240
5248
  const yi = 500, Mt = "opencx:context-changed";
5241
- function ra() {
5249
+ function aa() {
5242
5250
  if (typeof window > "u") return null;
5243
5251
  try {
5244
5252
  const t = window.top ?? window;
@@ -5248,11 +5256,11 @@ function ra() {
5248
5256
  }
5249
5257
  }
5250
5258
  function bi(t) {
5251
- const e = ra();
5259
+ const e = aa();
5252
5260
  if (!e) return () => {
5253
5261
  };
5254
5262
  const r = (n) => {
5255
- (n == null ? void 0 : n.type) === Mt && (aa += 1), t();
5263
+ (n == null ? void 0 : n.type) === Mt && (na += 1), t();
5256
5264
  };
5257
5265
  e.addEventListener("popstate", r), e.addEventListener("hashchange", r), e.addEventListener(Mt, r);
5258
5266
  const a = e.setInterval(r, yi);
@@ -5260,16 +5268,16 @@ function bi(t) {
5260
5268
  e.removeEventListener("popstate", r), e.removeEventListener("hashchange", r), e.removeEventListener(Mt, r), e.clearInterval(a);
5261
5269
  };
5262
5270
  }
5263
- let aa = 0;
5271
+ let na = 0;
5264
5272
  function Ci() {
5265
5273
  var t;
5266
- return `${aa}|${((t = ra()) == null ? void 0 : t.location.href) ?? ""}`;
5274
+ return `${na}|${((t = aa()) == null ? void 0 : t.location.href) ?? ""}`;
5267
5275
  }
5268
- function Li() {
5269
- return Ke(bi, Ci, () => "");
5276
+ function qi() {
5277
+ return $e(bi, Ci, () => "");
5270
5278
  }
5271
- function na() {
5272
- const { widgetCtx: t } = ie(), e = G(t.messageCtx.state), { isStreaming: r } = Gr();
5279
+ function sa() {
5280
+ const { widgetCtx: t } = re(), e = H(t.messageCtx.state), { isStreaming: r } = Qr();
5273
5281
  return {
5274
5282
  messagesState: r ? { ...e, isSendingMessage: !0, isSendingMessageToAI: !0 } : e,
5275
5283
  sendMessage: t.messageCtx.sendMessage,
@@ -5279,12 +5287,12 @@ function na() {
5279
5287
  getSentTextHistory: t.messageCtx.getSentTextHistory
5280
5288
  };
5281
5289
  }
5282
- function sa() {
5290
+ function ia() {
5283
5291
  var f;
5284
- const { widgetCtx: t } = ie(), { oneOpenSessionAllowed: e } = pt(), r = G(t.sessionCtx.sessionState), a = G(t.sessionCtx.sessionsState), { openSessions: n, closedSessions: i } = te(() => ({
5292
+ const { widgetCtx: t } = re(), { oneOpenSessionAllowed: e } = pt(), r = H(t.sessionCtx.sessionState), a = H(t.sessionCtx.sessionsState), { openSessions: n, closedSessions: i } = te(() => ({
5285
5293
  openSessions: a.data.filter((c) => c.isOpened === !0),
5286
5294
  closedSessions: a.data.filter((c) => c.isOpened === !1)
5287
- }), [a.data]), { workspace: l } = ea(), s = l ? l.canCreateChat() : !e || n.length === 0 && !r.isCreatingSession && !((f = r.session) != null && f.isOpened);
5295
+ }), [a.data]), { workspace: l } = ta(), s = l ? l.canCreateChat() : !e || n.length === 0 && !r.isCreatingSession && !((f = r.session) != null && f.isOpened);
5288
5296
  return {
5289
5297
  sessionState: r,
5290
5298
  sessionsState: a,
@@ -5296,23 +5304,71 @@ function sa() {
5296
5304
  canCreateNewSession: s
5297
5305
  };
5298
5306
  }
5299
- function Fi() {
5307
+ function zi() {
5300
5308
  var l, s;
5301
- const { sessionState: t } = sa(), { messagesState: e } = na(), r = ((l = t.session) == null ? void 0 : l.assignee.kind) === "ai", a = (s = e.messages) == null ? void 0 : s.at(-1), n = (a == null ? void 0 : a.type) === "USER" && a.id !== e.settledAgentUserMessageId;
5309
+ const { sessionState: t } = ia(), { messagesState: e } = sa(), r = ((l = t.session) == null ? void 0 : l.assignee.kind) === "ai", a = (s = e.messages) == null ? void 0 : s.at(-1), n = (a == null ? void 0 : a.type) === "USER" && a.id !== e.settledAgentUserMessageId;
5302
5310
  return { isAwaitingBotReply: !!(e.isSendingMessageToAI || (r || t.isCreatingSession) && (e.isSendingMessage || n)) };
5303
5311
  }
5304
- function $i() {
5305
- const { widgetCtx: t } = ie();
5312
+ function Si() {
5313
+ const { widgetCtx: t } = re();
5306
5314
  return {
5307
- routerState: G(t.routerCtx.state),
5315
+ routerState: H(t.routerCtx.state),
5308
5316
  toSessionsScreen: t.routerCtx.toSessionsScreen,
5309
5317
  toChatScreen: t.routerCtx.toChatScreen
5310
5318
  };
5311
5319
  }
5312
- function Ui() {
5320
+ function Zi() {
5321
+ const { widgetCtx: t } = re(), { unreadSessionIds: e, count: r } = H(
5322
+ t.unreadCtx.state
5323
+ ), a = q(
5324
+ (n) => e.includes(n),
5325
+ [e]
5326
+ );
5327
+ return { count: r, hasUnread: r > 0, unreadSessionIds: e, isUnread: a };
5328
+ }
5329
+ const oa = ze(null);
5330
+ function Wi({ children: t }) {
5331
+ const e = pt(), [r, a] = J(() => e.inline ? !0 : e.isOpen ?? !1);
5332
+ return F(() => {
5333
+ a((n) => e.isOpen ?? n);
5334
+ }, [e.isOpen]), F(() => {
5335
+ const n = e.openAfterNSeconds;
5336
+ if (typeof n != "number" || isNaN(n))
5337
+ return;
5338
+ const i = setTimeout(() => a(!0), n * 1e3);
5339
+ return () => clearTimeout(i);
5340
+ }, [e.openAfterNSeconds]), /* @__PURE__ */ K.createElement(oa.Provider, { value: { isOpen: r, setIsOpen: a } }, t);
5341
+ }
5342
+ function Ei() {
5343
+ const t = Ne(oa);
5344
+ if (!t)
5345
+ throw new Error(
5346
+ "useWidgetTrigger must be used within a WidgetTriggerProvider"
5347
+ );
5348
+ return t;
5349
+ }
5350
+ const wi = (t) => (document.addEventListener("visibilitychange", t), () => document.removeEventListener("visibilitychange", t)), Ii = () => document.visibilityState !== "hidden";
5351
+ function Vi({
5352
+ transcriptVisible: t = !0
5353
+ } = {}) {
5354
+ const { widgetCtx: e } = re(), { isOpen: r } = Ei(), { routerState: a } = Si(), { session: n } = H(e.sessionCtx.sessionState), { isInitialFetchLoading: i } = H(
5355
+ e.messageCtx.state
5356
+ ), l = $e(
5357
+ wi,
5358
+ Ii,
5359
+ () => !0
5360
+ ), s = r && l && t && a.screen === "chat" && !i ? (n == null ? void 0 : n.id) ?? null : null;
5361
+ F(() => {
5362
+ e.unreadCtx.setViewingSessionId(s);
5363
+ }, [e, s]), F(
5364
+ () => () => e.unreadCtx.setViewingSessionId(null),
5365
+ [e]
5366
+ );
5367
+ }
5368
+ function Bi() {
5313
5369
  const {
5314
5370
  widgetCtx: { uploadCtx: t }
5315
- } = ie(), e = G(t.state), r = te(
5371
+ } = re(), e = H(t.state), r = te(
5316
5372
  () => e.filter((a) => a.status === "success" && a.fileUrl),
5317
5373
  [e]
5318
5374
  );
@@ -5335,47 +5391,26 @@ function Ui() {
5335
5391
  isUploading: e.some((a) => a.status === "uploading")
5336
5392
  };
5337
5393
  }
5338
- const ia = qe(null);
5339
- function qi({ children: t }) {
5340
- const e = pt(), [r, a] = J(() => e.inline ? !0 : e.isOpen ?? !1);
5341
- return z(() => {
5342
- a((n) => e.isOpen ?? n);
5343
- }, [e.isOpen]), z(() => {
5344
- const n = e.openAfterNSeconds;
5345
- if (typeof n != "number" || isNaN(n))
5346
- return;
5347
- const i = setTimeout(() => a(!0), n * 1e3);
5348
- return () => clearTimeout(i);
5349
- }, [e.openAfterNSeconds]), /* @__PURE__ */ K.createElement(ia.Provider, { value: { isOpen: r, setIsOpen: a } }, t);
5350
- }
5351
- function zi() {
5352
- const t = Ne(ia);
5353
- if (!t)
5354
- throw new Error(
5355
- "useWidgetTrigger must be used within a WidgetTriggerProvider"
5356
- );
5357
- return t;
5358
- }
5359
- function Si(t) {
5394
+ function _i(t) {
5360
5395
  return t !== "fullscreen";
5361
5396
  }
5362
- const oa = qe(null);
5363
- function Zi({ children: t }) {
5397
+ const la = ze(null);
5398
+ function Ji({ children: t }) {
5364
5399
  var n, i;
5365
- const { companion: e } = pt(), { dir: r } = vi(), { widgetCtx: a } = ie();
5400
+ const { companion: e } = pt(), { dir: r } = vi(), { widgetCtx: a } = re();
5366
5401
  return /* @__PURE__ */ K.createElement(
5367
- Ei,
5402
+ Ai,
5368
5403
  {
5369
5404
  configuredDefaultLayout: e == null ? void 0 : e.defaultLayout,
5370
5405
  configuredLayouts: e == null ? void 0 : e.layouts,
5371
- configuredSidebarSide: xa((n = e == null ? void 0 : e.sidebar) == null ? void 0 : n.side, r),
5372
- configuredSidebarMode: Ta((i = e == null ? void 0 : e.sidebar) == null ? void 0 : i.mode),
5406
+ configuredSidebarSide: Ta((n = e == null ? void 0 : e.sidebar) == null ? void 0 : n.side, r),
5407
+ configuredSidebarMode: xa((i = e == null ? void 0 : e.sidebar) == null ? void 0 : i.mode),
5373
5408
  storage: a.storageCtx
5374
5409
  },
5375
5410
  t
5376
5411
  );
5377
5412
  }
5378
- function Ei({
5413
+ function Ai({
5379
5414
  configuredDefaultLayout: t,
5380
5415
  configuredLayouts: e,
5381
5416
  configuredSidebarSide: r,
@@ -5386,33 +5421,33 @@ function Ei({
5386
5421
  const l = Ma(e), s = Pa(
5387
5422
  t,
5388
5423
  l
5389
- ), f = l.join("|"), [c, p] = J(s), [d, C] = J({
5424
+ ), f = l.join("|"), [c, p] = J(s), [u, C] = J({
5390
5425
  defaultLayout: s,
5391
5426
  allowedLayoutsKey: f
5392
5427
  });
5393
- (d.defaultLayout !== s || d.allowedLayoutsKey !== f) && (C({ defaultLayout: s, allowedLayoutsKey: f }), (d.defaultLayout !== s || !l.includes(c)) && p(s));
5428
+ (u.defaultLayout !== s || u.allowedLayoutsKey !== f) && (C({ defaultLayout: s, allowedLayoutsKey: f }), (u.defaultLayout !== s || !l.includes(c)) && p(s));
5394
5429
  const v = (h) => {
5395
5430
  p((w) => {
5396
5431
  const k = typeof h == "function" ? h(w) : h;
5397
5432
  return l.includes(k) ? k : w;
5398
5433
  });
5399
- }, O = R(l);
5400
- O.current = l;
5434
+ }, N = O(l);
5435
+ N.current = l;
5401
5436
  const I = (h) => {
5402
- v(h), O.current.includes(h) && Si(h) && (n == null || n.setCompanionLayout(h).catch(() => {
5437
+ v(h), N.current.includes(h) && _i(h) && (n == null || n.setCompanionLayout(h).catch(() => {
5403
5438
  }));
5404
- }, [E, _] = J(r), [S, M] = J(a), [u, g] = J({
5439
+ }, [E, _] = J(r), [S, M] = J(a), [d, g] = J({
5405
5440
  side: r,
5406
5441
  mode: a
5407
5442
  });
5408
- (u.side !== r || u.mode !== a) && (g({
5443
+ (d.side !== r || d.mode !== a) && (g({
5409
5444
  side: r,
5410
5445
  mode: a
5411
- }), u.side !== r && _(r), u.mode !== a && M(a)), z(() => {
5446
+ }), d.side !== r && _(r), d.mode !== a && M(a)), F(() => {
5412
5447
  if (!n) return;
5413
5448
  let h = !1;
5414
5449
  return n.getCompanionLayout().then((w) => {
5415
- h || !w || O.current.includes(w) && p(w);
5450
+ h || !w || N.current.includes(w) && p(w);
5416
5451
  }).catch(() => {
5417
5452
  }), n.getCompanionSidebarSide().then((w) => {
5418
5453
  !h && w && _(w);
@@ -5424,13 +5459,13 @@ function Ei({
5424
5459
  h = !0;
5425
5460
  };
5426
5461
  }, [n]);
5427
- const m = U(
5462
+ const m = q(
5428
5463
  (h) => {
5429
5464
  _(h), n == null || n.setCompanionSidebarSide(h).catch(() => {
5430
5465
  });
5431
5466
  },
5432
5467
  [n]
5433
- ), y = U(
5468
+ ), y = q(
5434
5469
  (h) => {
5435
5470
  M(h), n == null || n.setCompanionSidebarMode(h).catch(() => {
5436
5471
  });
@@ -5438,7 +5473,7 @@ function Ei({
5438
5473
  [n]
5439
5474
  );
5440
5475
  return /* @__PURE__ */ K.createElement(
5441
- oa.Provider,
5476
+ la.Provider,
5442
5477
  {
5443
5478
  value: {
5444
5479
  layout: c,
@@ -5455,23 +5490,23 @@ function Ei({
5455
5490
  i
5456
5491
  );
5457
5492
  }
5458
- function Wi() {
5459
- const t = Ne(oa);
5493
+ function Ki() {
5494
+ const t = Ne(la);
5460
5495
  if (!t)
5461
5496
  throw new Error(
5462
5497
  "useWidgetLayout must be used within a WidgetLayoutProvider"
5463
5498
  );
5464
5499
  return t;
5465
5500
  }
5466
- function Bi() {
5501
+ function Yi() {
5467
5502
  var s, f;
5468
- const { widgetCtx: t } = ie(), { modesComponents: e } = pt(), { sessionState: r } = sa(), a = t.modes, n = (s = r.session) == null ? void 0 : s.modeId, i = a.find((c) => c.id === n), l = (f = e == null ? void 0 : e.find(
5503
+ const { widgetCtx: t } = re(), { modesComponents: e } = pt(), { sessionState: r } = ia(), a = t.modes, n = (s = r.session) == null ? void 0 : s.modeId, i = a.find((c) => c.id === n), l = (f = e == null ? void 0 : e.find(
5469
5504
  (c) => {
5470
- var p, d;
5505
+ var p, u;
5471
5506
  return [
5472
5507
  (i == null ? void 0 : i.id) || "",
5473
5508
  ((p = i == null ? void 0 : i.name) == null ? void 0 : p.toLowerCase()) || "",
5474
- ((d = i == null ? void 0 : i.slug) == null ? void 0 : d.toLowerCase()) || ""
5509
+ ((u = i == null ? void 0 : i.slug) == null ? void 0 : u.toLowerCase()) || ""
5475
5510
  ].includes(c.key.toLowerCase());
5476
5511
  }
5477
5512
  )) == null ? void 0 : f.component;
@@ -5483,10 +5518,10 @@ function Bi() {
5483
5518
  Component: l
5484
5519
  };
5485
5520
  }
5486
- function Vi() {
5487
- const { widgetCtx: t } = ie(), {
5521
+ function Hi() {
5522
+ const { widgetCtx: t } = re(), {
5488
5523
  messagesState: { messages: e }
5489
- } = na(), {
5524
+ } = sa(), {
5490
5525
  csatRequestedMessage: r,
5491
5526
  isCsatRequested: a,
5492
5527
  csatSubmittedMessage: n,
@@ -5518,10 +5553,10 @@ function Vi() {
5518
5553
  submittedFeedback: s
5519
5554
  };
5520
5555
  }
5521
- function Ji(t) {
5522
- const { widgetCtx: e } = ie(), r = e.dictationCtx, a = G(r.state), n = R(t);
5556
+ function Gi(t) {
5557
+ const { widgetCtx: e } = re(), r = e.dictationCtx, a = H(r.state), n = O(t);
5523
5558
  n.current = t;
5524
- const i = U(() => {
5559
+ const i = q(() => {
5525
5560
  r.start({
5526
5561
  getValue: () => n.current.getValue(),
5527
5562
  setValue: (s) => n.current.setValue(s),
@@ -5530,10 +5565,10 @@ function Ji(t) {
5530
5565
  return (f = (s = n.current).onSend) == null ? void 0 : f.call(s);
5531
5566
  }
5532
5567
  });
5533
- }, [r]), l = U(() => {
5568
+ }, [r]), l = q(() => {
5534
5569
  r.isActive() ? r.stop() : i();
5535
5570
  }, [r, i]);
5536
- return z(() => () => r.stop({ executeFinalCommand: !1 }), [r]), {
5571
+ return F(() => () => r.stop({ executeFinalCommand: !1 }), [r]), {
5537
5572
  enabled: e.features.dictation,
5538
5573
  status: a.status,
5539
5574
  error: a.error,
@@ -5546,22 +5581,22 @@ function Ji(t) {
5546
5581
  prewarm: r.prewarm
5547
5582
  };
5548
5583
  }
5549
- function Ki() {
5550
- const { widgetCtx: t } = ie(), e = t.messageCtx.draftState, r = G(e), a = U(
5584
+ function Qi() {
5585
+ const { widgetCtx: t } = re(), e = t.messageCtx.draftState, r = H(e), a = q(
5551
5586
  (l) => {
5552
5587
  e.setPartial({
5553
5588
  text: typeof l == "function" ? l(e.get().text) : l
5554
5589
  });
5555
5590
  },
5556
5591
  [e]
5557
- ), n = U(
5592
+ ), n = q(
5558
5593
  (l) => {
5559
5594
  e.setPartial({
5560
5595
  mentions: typeof l == "function" ? l(e.get().mentions) : l
5561
5596
  });
5562
5597
  },
5563
5598
  [e]
5564
- ), i = U(
5599
+ ), i = q(
5565
5600
  (l = r) => e.get() !== l ? !1 : (e.reset(), !0),
5566
5601
  [e, r]
5567
5602
  );
@@ -5569,33 +5604,35 @@ function Ki() {
5569
5604
  }
5570
5605
  export {
5571
5606
  Mt as HOST_CONTEXT_CHANGED_EVENT,
5572
- Zi as WidgetLayoutProvider,
5573
- Oi as WidgetProvider,
5574
- qi as WidgetTriggerProvider,
5607
+ Ji as WidgetLayoutProvider,
5608
+ ki as WidgetProvider,
5609
+ Wi as WidgetTriggerProvider,
5575
5610
  fr as applyPresentation,
5576
- Mi as formatAskQuestionsAnswers,
5577
- Ni as sessionPlan,
5578
- Gr as useAgentChatUi,
5579
- ji as useBot,
5580
- Ri as useCompanionChats,
5581
- Ki as useComposerDraft,
5611
+ Ni as formatAskQuestionsAnswers,
5612
+ Li as sessionPlan,
5613
+ Qr as useAgentChatUi,
5614
+ Fi as useBot,
5615
+ Di as useCompanionChats,
5616
+ Qi as useComposerDraft,
5582
5617
  pt as useConfig,
5583
- Pi as useConnection,
5584
- ki as useContact,
5585
- Vi as useCsat,
5586
- Ji as useDictation,
5587
- Di as useDisplayMode,
5618
+ ji as useConnection,
5619
+ Ui as useContact,
5620
+ Hi as useCsat,
5621
+ Gi as useDictation,
5622
+ $i as useDisplayMode,
5588
5623
  vi as useDocumentDir,
5589
- Li as useHostLocation,
5590
- Fi as useIsAwaitingBotReply,
5591
- na as useMessages,
5592
- Bi as useModes,
5593
- G as usePrimitiveState,
5594
- sa as useSessions,
5595
- Ui as useUploadFiles,
5596
- ie as useWidget,
5597
- Wi as useWidgetLayout,
5598
- $i as useWidgetRouter,
5599
- zi as useWidgetTrigger
5624
+ qi as useHostLocation,
5625
+ zi as useIsAwaitingBotReply,
5626
+ sa as useMessages,
5627
+ Yi as useModes,
5628
+ H as usePrimitiveState,
5629
+ ia as useSessions,
5630
+ Zi as useUnread,
5631
+ Vi as useUnreadViewing,
5632
+ Bi as useUploadFiles,
5633
+ re as useWidget,
5634
+ Ki as useWidgetLayout,
5635
+ Si as useWidgetRouter,
5636
+ Ei as useWidgetTrigger
5600
5637
  };
5601
5638
  //# sourceMappingURL=index.js.map