@opencx/widget-react-headless 5.4.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,11 +1,11 @@
1
- import K, { useSyncExternalStore as $e, useRef as R, useCallback as U, useEffect as q, useMemo as te, useState as J, createContext as ze, 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 xa, resolveSidebarSide as Ta, 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.4.0";
7
+ import { z as j } from "zod";
8
+ const Ra = "5.4.1";
9
9
  function H(t) {
10
10
  return $e(t.subscribe, t.get, t.get);
11
11
  }
@@ -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", xr = `vercel.ai.error.${Ar}`, Da = Symbol.for(xr), 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
- return ge.hasMarker(t, xr);
71
+ return ge.hasMarker(t, Tr);
72
72
  }
73
- }, Tr = "AI_JSONParseError", Mr = `vercel.ai.error.${Tr}`, 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: Tr,
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, qe = 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.
@@ -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,20 +174,20 @@ 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
183
  const w = g.charCodeAt(m + 5) === Te ? m + 6 : m + 5, k = g.slice(w, y);
184
- if (d === 0 && g.charCodeAt(y + 1) === ar) {
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
192
  g.charCodeAt(m + 6) === Te ? m + 7 : m + 6,
193
193
  y
@@ -214,9 +214,9 @@ ${k}`, d++;
214
214
  }
215
215
  const h = g.charCodeAt(m);
216
216
  if (nr(g, m, h)) {
217
- const $ = g.charCodeAt(m + 5) === Te ? 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)) {
@@ -224,14 +224,14 @@ ${W}`, d++;
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) === Te ? 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) === Te ? 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
  }
@@ -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;
@@ -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) : ie();
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,11 +866,11 @@ 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
- }) || ie(), a = F(t.valueType._def, {
873
+ }) || ie(), a = $(t.valueType._def, {
874
874
  ...e,
875
875
  currentPath: [...e.currentPath, "items", "items", "1"]
876
876
  }) || ie();
@@ -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
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
  })
@@ -1138,10 +1138,10 @@ function An() {
1138
1138
  function xn() {
1139
1139
  return ie();
1140
1140
  }
1141
- var Tn = (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 Tn = (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 Tn = (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:
@@ -1197,7 +1197,7 @@ var Tn = (t, e) => F(t.innerType._def, e), Mn = (t, e, r) => {
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
1202
  return Tn(t, r);
1203
1203
  case P.ZodCatch:
@@ -1218,7 +1218,7 @@ var Tn = (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;
@@ -1282,12 +1282,12 @@ 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]
@@ -1298,7 +1298,7 @@ var Rn = (t, e) => {
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,
@@ -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(
@@ -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({
@@ -1492,7 +1492,7 @@ function Zn(t) {
1492
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}`, Bn = 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, Vn = (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 = Bn;
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(),
@@ -1538,7 +1538,7 @@ 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
1544
  providerOptions: T.optional()
@@ -1551,7 +1551,7 @@ var Oe = o.lazy(
1551
1551
  ]),
1552
1552
  mediaType: o.string().optional(),
1553
1553
  providerOptions: T.optional()
1554
- }), Wr = o.discriminatedUnion("type", [
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({
@@ -1562,10 +1562,10 @@ var Oe = o.lazy(
1562
1562
  ]), Yn = o.discriminatedUnion("type", [
1563
1563
  o.object({ type: o.literal("data"), data: Ge }),
1564
1564
  o.object({ type: o.literal("url"), url: o.instanceof(URL) })
1565
- ]), Vr = o.object({
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
@@ -1636,7 +1636,7 @@ var Oe = o.lazy(
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
1642
  providerOptions: T.optional()
@@ -1701,7 +1701,7 @@ var Oe = o.lazy(
1701
1701
  )
1702
1702
  })
1703
1703
  ]
1704
- ), Br = o.object({
1704
+ ), Jr = o.object({
1705
1705
  type: o.literal("tool-result"),
1706
1706
  toolCallId: o.string(),
1707
1707
  toolName: o.string(),
@@ -1726,7 +1726,7 @@ var Oe = o.lazy(
1726
1726
  role: o.literal("user"),
1727
1727
  content: o.union([
1728
1728
  o.string(),
1729
- o.array(o.union([Zr, Kn, Vr]))
1729
+ o.array(o.union([Wr, Kn, Br]))
1730
1730
  ]),
1731
1731
  providerOptions: T.optional()
1732
1732
  }), ss = o.object({
@@ -1735,13 +1735,13 @@ var Oe = o.lazy(
1735
1735
  o.string(),
1736
1736
  o.array(
1737
1737
  o.union([
1738
- Zr,
1738
+ Wr,
1739
1739
  Gn,
1740
- Vr,
1740
+ Br,
1741
1741
  Hn,
1742
1742
  Qn,
1743
1743
  Xn,
1744
- Br,
1744
+ Jr,
1745
1745
  ts
1746
1746
  ])
1747
1747
  )
@@ -1749,7 +1749,7 @@ var Oe = o.lazy(
1749
1749
  providerOptions: T.optional()
1750
1750
  }), is = o.object({
1751
1751
  role: o.literal("tool"),
1752
- content: o.array(o.union([Br, rs])),
1752
+ content: o.array(o.union([Jr, rs])),
1753
1753
  providerOptions: T.optional()
1754
1754
  });
1755
1755
  o.union([
@@ -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;
@@ -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
  }
@@ -2353,7 +2353,7 @@ 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"),
@@ -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
2557
  function Ue(t) {
2558
- return Nt(t) || Kr(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) {
2595
+ var u, C, v, N;
2596
+ function I(d) {
2597
2597
  const m = c.message.parts.filter(Ue).find(
2598
- (y) => y.toolCallId === u
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) {
2608
+ function E(d) {
2609
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(Ue).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) => Ue(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) => Ue(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,
@@ -3530,14 +3530,14 @@ function Is() {
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
- }, V = (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);
3540
+ }, Ie = (t, e, r, a) => (Hr(t, e, "write to private field"), e.set(t, r), r);
3541
3541
  function xs(t, e) {
3542
3542
  return e != null ? As(t, e) : t;
3543
3543
  }
@@ -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
3663
  ), C = $e(
3664
- d,
3664
+ u,
3665
3665
  () => c.current.messages,
3666
3666
  () => c.current.messages
3667
3667
  ), v = $e(
3668
3668
  c.current["~registerStatusCallback"],
3669
3669
  () => c.current.status,
3670
3670
  () => c.current.status
3671
- ), O = $e(
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 q(() => {
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"));
@@ -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);
@@ -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
  }
@@ -4009,7 +4009,7 @@ function ei({
4009
4009
  persistedMessages: a
4010
4010
  }) {
4011
4011
  var Vt, Bt;
4012
- const { api: n, messageCtx: i } = t, l = R(e);
4012
+ const { api: n, messageCtx: i } = t, l = O(e);
4013
4013
  l.current = e;
4014
4014
  const {
4015
4015
  pageContext: s,
@@ -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()), B = R(0), Z = R(0), [$, W] = J(0), [ne, oe] = J(!1), ue = R(ne);
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);
4056
4064
  ue.current = ne;
4057
- const [be, Q] = J([]), [xe, he] = J([]), [ve, z] = J(null), G = R(null), se = U((b) => {
4065
+ const [be, Q] = J([]), [xe, he] = J([]), [ve, z] = J(null), G = O(null), se = q((b) => {
4058
4066
  G.current = b, z(b);
4059
- }, []), ae = R(null), Ze = R(null), je = R(I), ft = R(r), We = ft.current === r, mt = R(null), gt = R(null), zt = R(S), Ce = R(I);
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;
4069
+ const Xe = q((b, A) => {
4070
+ const R = vr(b.parts);
4071
+ if (!R || R.rowIds.length === 0) return;
4064
4072
  const x = lt(b.parts);
4065
4073
  x.length !== 0 && Q(
4066
- (L) => L.some((X) => X.turnId === j.turnId) ? L : [
4074
+ (L) => L.some((X) => X.turnId === R.turnId) ? L : [
4067
4075
  ...L,
4068
- { key: A, turnId: j.turnId, rowIds: j.rowIds, items: x }
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
- q(() => {
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, 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", u(), W((x) => x + 1), oe(!1), Q([]), se(null), j && Promise.resolve().then(() => b()).catch((x) => {
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) => {
4094
4102
  ye.error("agent chat client stream cancel failed", x);
4095
4103
  });
4096
- }, [r, I, S, u, se]), q(() => {
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) {
@@ -4109,7 +4117,7 @@ function ei({
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
4122
  const Y = m.current.at(-1), Ee = G.current;
4115
4123
  if (ae.current = Ee, Ee !== null && Y && Y.role === "assistant" && Xe(Y, Ee), I === "ready") {
@@ -4131,16 +4139,16 @@ function ei({
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
4148
  se,
4141
- d
4149
+ u
4142
4150
  ]);
4143
- const Wt = U(
4151
+ const Wt = q(
4144
4152
  (b) => {
4145
4153
  const A = Z.current;
4146
4154
  B.current++;
@@ -4169,7 +4177,7 @@ function ei({
4169
4177
  ), x;
4170
4178
  },
4171
4179
  [i]
4172
- ), la = U(() => {
4180
+ ), ca = q(() => {
4173
4181
  const b = Ze.current;
4174
4182
  if (!b) return;
4175
4183
  if (!y.current.enqueue({
@@ -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,7 +4213,7 @@ function ei({
4205
4213
  b === Z.current && (h.current = "idle", W((A) => A + 1));
4206
4214
  });
4207
4215
  }, [n, r, S, t]);
4208
- q(() => {
4216
+ F(() => {
4209
4217
  const b = {
4210
4218
  send: Wt,
4211
4219
  hasPendingWork: () => B.current > 0 || ue.current || y.current.size > 0 || h.current !== "idle" || Ce.current === "submitted" || Ce.current === "streaming"
@@ -4213,10 +4221,10 @@ function ei({
4213
4221
  return i.registerAgentHandlers(b), () => i.unregisterAgentHandlers(b);
4214
4222
  }, [i, Wt]);
4215
4223
  const et = (Vt = e.presentation) == null ? void 0 : Vt.toolActivity, tt = (Bt = e.presentation) == null ? void 0 : Bt.reasoning;
4216
- q(() => he([]), [r]), q(() => {
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
4229
  let x = !1;
4222
4230
  return (async () => {
@@ -4224,7 +4232,7 @@ function ei({
4224
4232
  const Y = b === void 0 ? await n.getAgentTurnMessages(r) : await n.getAgentTurnMessages(r, b);
4225
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);
@@ -4233,24 +4241,24 @@ function ei({
4233
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 (!Ue(j)) continue;
4244
- const x = hs(j), L = x === Qs ? "highlight-element" : x === 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, x) => {
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,10 +4280,10 @@ 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.
@@ -4283,25 +4291,25 @@ function ei({
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((x) => x(!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
4309
  (x) => (x == null ? void 0 : x.callId) === b ? null : x
4302
- ), j == null || j(A);
4310
+ ), R == null || R(A);
4303
4311
  }, []);
4304
- q(() => {
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,45 +4321,45 @@ function ei({
4313
4321
  yt
4314
4322
  ]);
4315
4323
  const de = I === "submitted" || I === "streaming";
4316
- q(
4324
+ F(
4317
4325
  () => () => {
4318
4326
  Se.current.forEach((b) => b(!1)), Se.current.clear();
4319
4327
  },
4320
4328
  [r]
4321
- ), q(() => {
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]), q(() => {
4333
+ }, [de, w]), F(() => {
4326
4334
  if (de) return;
4327
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(() => {
4340
+ const St = q(() => {
4333
4341
  r && (de || M === void 0 && !ne || g());
4334
4342
  }, [r, de, ne, M, g]);
4335
- q(
4343
+ F(
4336
4344
  () => Hs(St),
4337
4345
  [St]
4338
- ), q(() => {
4346
+ ), F(() => {
4339
4347
  if (de || !ne) return;
4340
4348
  const b = () => {
4341
4349
  oe(!1), W((x) => x + 1), G.current === ae.current && se(null), ae.current = null;
4342
4350
  };
4343
- if (G.current === ae.current && (d == null ? void 0 : d.messages) === E && !d.isError && !d.isDisconnect && (!d.isAbort || v.current) && !lt(d.message.parts).some(
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(
4344
4352
  (x) => x.kind !== "steps"
4345
4353
  )) {
4346
4354
  const x = a.findLast((L) => L.type === "USER");
4347
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) {
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) {
4353
4361
  const x = new Set(a.map((L) => L.id));
4354
- j.rowIds.every((L) => x.has(L)) && b();
4362
+ R.rowIds.every((L) => x.has(L)) && b();
4355
4363
  return;
4356
4364
  }
4357
4365
  for (let x = a.length - 1; x >= 0; x -= 1) {
@@ -4369,15 +4377,15 @@ function ei({
4369
4377
  ne,
4370
4378
  a,
4371
4379
  se,
4372
- d,
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(() => {
4388
+ ), nt = De == null ? void 0 : De.toolActivity, st = De == null ? void 0 : De.reasoning, ha = te(() => {
4381
4389
  if (!We || ve === null || I === "submitted" || !de && !ne)
4382
4390
  return [];
4383
4391
  const b = E.at(-1);
@@ -4394,7 +4402,7 @@ function ei({
4394
4402
  st,
4395
4403
  We,
4396
4404
  ve
4397
- ]), ha = te(
4405
+ ]), va = te(
4398
4406
  () => We ? be.flatMap((b) => {
4399
4407
  const A = fr(b.items, {
4400
4408
  toolActivity: nt,
@@ -4403,29 +4411,29 @@ function ei({
4403
4411
  return A.length === 0 ? [] : [A === b.items ? b : { ...b, items: A }];
4404
4412
  }) : [],
4405
4413
  [be, nt, st, We]
4406
- ), va = te(
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
4438
  handledConnectionRequestIds: xe,
4431
4439
  sourceSessionId: We ? r : null
@@ -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
- q(() => (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]), q(() => (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
4481
  const B = e.request_id;
4474
- if (O.current.has(B)) return;
4475
- O.current.add(B), I.current = D, c(D), d(null);
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,60 +4488,60 @@ function ni({
4480
4488
  onAccepted: () => {
4481
4489
  Z = !0, a(e.request_id);
4482
4490
  }
4483
- }), S.current && M.current === B && !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 === B && 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(B), S.current && M.current === B && 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 () => {
4503
+ ), m = q(async () => {
4496
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 } : {}
4523
+ completion: U.completion,
4524
+ ...U.completion === "oauth" ? { attemptId: U.attempt_id } : {}
4517
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");
4518
- } catch ($) {
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
- q(() => {
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
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(), ne = !1;
4544
+ let U = 0, W = document.hidden || !document.hasFocus(), ne = !1;
4537
4545
  const oe = () => {
4538
4546
  W = !0;
4539
4547
  }, ue = () => {
@@ -4542,7 +4550,7 @@ function ni({
4542
4550
  window.addEventListener("blur", oe), window.addEventListener("focus", ue), document.addEventListener("visibilitychange", be);
4543
4551
  const Q = (z) => {
4544
4552
  var G;
4545
- D.abort(), (G = v.current) == null || G.close(), v.current = null, d(z), i("idle");
4553
+ D.abort(), (G = v.current) == null || G.close(), v.current = null, u(z), i("idle");
4546
4554
  }, xe = setTimeout(
4547
4555
  () => Q("Connection timed out. Try again."),
4548
4556
  Math.max(0, Z - Date.now())
@@ -4573,7 +4581,7 @@ function ni({
4573
4581
  D.signal
4574
4582
  );
4575
4583
  if (D.signal.aborted) return;
4576
- if ($ = 0, ae === "connected") {
4584
+ if (U = 0, ae === "connected") {
4577
4585
  (G = v.current) == null || G.close(), v.current = null, i("connected");
4578
4586
  return;
4579
4587
  }
@@ -4596,9 +4604,9 @@ function ni({
4596
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
  );
@@ -4607,12 +4615,12 @@ function ni({
4607
4615
  return ve(), () => {
4608
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]), q(() => {
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);
@@ -4697,7 +4705,7 @@ const qt = {
4697
4705
  pendingClarification: null,
4698
4706
  pendingConnection: null
4699
4707
  }, dt = ze(null);
4700
- function Gr() {
4708
+ function Qr() {
4701
4709
  return Ne(dt) ?? qt;
4702
4710
  }
4703
4711
  function oi({
@@ -4713,24 +4721,24 @@ function oi({
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 = ((xe = a.session) == null ? void 0 : xe.id) ?? null;
4733
- h.current !== w && (h.current = w, y.current.clear()), u.forEach(
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(
4734
4742
  (z) => y.current.add(z)
4735
4743
  );
4736
4744
  const k = (he = [
@@ -4738,8 +4746,8 @@ function oi({
4738
4746
  ...l
4739
4747
  ].findLast(
4740
4748
  (z) => z.kind === "connection" && !y.current.has(z.request.request_id)
4741
- )) == null ? void 0 : he.request, [D, B] = 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
- q(() => {
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(() => {
4743
4751
  !Z || w === null || g !== w || B((z) => {
4744
4752
  const G = z.sessionId === w && z.request && !y.current.has(z.request.request_id) ? z.request : k ?? null;
4745
4753
  return z.sessionId === w && z.request === G ? z : { sessionId: w, request: G };
@@ -4748,11 +4756,11 @@ function oi({
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((z) => {
4763
+ const W = q((z) => {
4756
4764
  y.current.add(z), B(
4757
4765
  (G) => {
4758
4766
  var se;
@@ -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,30 +4799,30 @@ 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
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
@@ -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 = ze(null), ci = new Er({ chats: [], activeId: 0 });
4923
- function ea() {
4924
- const t = Ne(Xr), e = H((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
4937
  function Di() {
4930
- const { workspace: t, ...e } = ea();
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 = H(e.messageCtx.state), l = H(e.sessionCtx.sessionState), s = H(e.messageCtx.draftState), f = H(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 q(
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,7 +4982,7 @@ function pi({
4974
4982
  () => new li(t),
4975
4983
  [t]
4976
4984
  );
4977
- q(() => a.mount(), [a]);
4985
+ F(() => a.mount(), [a]);
4978
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,
@@ -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,7 +5079,7 @@ const Sr = N.object({
5071
5079
  externalId: e.externalId ?? null,
5072
5080
  opaqueToken: r
5073
5081
  });
5074
- }, ta = ze(null);
5082
+ }, ra = ze(null);
5075
5083
  function ki({
5076
5084
  options: t,
5077
5085
  children: e,
@@ -5081,24 +5089,24 @@ function ki({
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 (q(() => {
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 ki({
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 ki({
5136
5144
  });
5137
5145
  }
5138
5146
  );
5139
- }, [f, t, a]), q(
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 ki({
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,11 +5173,11 @@ function ki({
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
5179
  function re() {
5172
- const t = Ne(ta);
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;
@@ -5218,7 +5226,7 @@ function Ui() {
5218
5226
  }
5219
5227
  function vi() {
5220
5228
  const [t, e] = J("ltr");
5221
- return q(() => {
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
5276
  function qi() {
5269
5277
  return $e(bi, Ci, () => "");
5270
5278
  }
5271
- function na() {
5272
- const { widgetCtx: t } = re(), e = H(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
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,
@@ -5298,7 +5306,7 @@ function sa() {
5298
5306
  }
5299
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
5312
  function Si() {
@@ -5312,27 +5320,27 @@ function Si() {
5312
5320
  function Zi() {
5313
5321
  const { widgetCtx: t } = re(), { unreadSessionIds: e, count: r } = H(
5314
5322
  t.unreadCtx.state
5315
- ), a = U(
5323
+ ), a = q(
5316
5324
  (n) => e.includes(n),
5317
5325
  [e]
5318
5326
  );
5319
5327
  return { count: r, hasUnread: r > 0, unreadSessionIds: e, isUnread: a };
5320
5328
  }
5321
- const ia = ze(null);
5329
+ const oa = ze(null);
5322
5330
  function Wi({ children: t }) {
5323
5331
  const e = pt(), [r, a] = J(() => e.inline ? !0 : e.isOpen ?? !1);
5324
- return q(() => {
5332
+ return F(() => {
5325
5333
  a((n) => e.isOpen ?? n);
5326
- }, [e.isOpen]), q(() => {
5334
+ }, [e.isOpen]), F(() => {
5327
5335
  const n = e.openAfterNSeconds;
5328
5336
  if (typeof n != "number" || isNaN(n))
5329
5337
  return;
5330
5338
  const i = setTimeout(() => a(!0), n * 1e3);
5331
5339
  return () => clearTimeout(i);
5332
- }, [e.openAfterNSeconds]), /* @__PURE__ */ K.createElement(ia.Provider, { value: { isOpen: r, setIsOpen: a } }, t);
5340
+ }, [e.openAfterNSeconds]), /* @__PURE__ */ K.createElement(oa.Provider, { value: { isOpen: r, setIsOpen: a } }, t);
5333
5341
  }
5334
5342
  function Ei() {
5335
- const t = Ne(ia);
5343
+ const t = Ne(oa);
5336
5344
  if (!t)
5337
5345
  throw new Error(
5338
5346
  "useWidgetTrigger must be used within a WidgetTriggerProvider"
@@ -5350,9 +5358,9 @@ function Vi({
5350
5358
  Ii,
5351
5359
  () => !0
5352
5360
  ), s = r && l && t && a.screen === "chat" && !i ? (n == null ? void 0 : n.id) ?? null : null;
5353
- q(() => {
5361
+ F(() => {
5354
5362
  e.unreadCtx.setViewingSessionId(s);
5355
- }, [e, s]), q(
5363
+ }, [e, s]), F(
5356
5364
  () => () => e.unreadCtx.setViewingSessionId(null),
5357
5365
  [e]
5358
5366
  );
@@ -5386,7 +5394,7 @@ function Bi() {
5386
5394
  function _i(t) {
5387
5395
  return t !== "fullscreen";
5388
5396
  }
5389
- const oa = ze(null);
5397
+ const la = ze(null);
5390
5398
  function Ji({ children: t }) {
5391
5399
  var n, i;
5392
5400
  const { companion: e } = pt(), { dir: r } = vi(), { widgetCtx: a } = re();
@@ -5413,33 +5421,33 @@ function Ai({
5413
5421
  const l = Ma(e), s = Pa(
5414
5422
  t,
5415
5423
  l
5416
- ), f = l.join("|"), [c, p] = J(s), [d, C] = J({
5424
+ ), f = l.join("|"), [c, p] = J(s), [u, C] = J({
5417
5425
  defaultLayout: s,
5418
5426
  allowedLayoutsKey: f
5419
5427
  });
5420
- (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));
5421
5429
  const v = (h) => {
5422
5430
  p((w) => {
5423
5431
  const k = typeof h == "function" ? h(w) : h;
5424
5432
  return l.includes(k) ? k : w;
5425
5433
  });
5426
- }, O = R(l);
5427
- O.current = l;
5434
+ }, N = O(l);
5435
+ N.current = l;
5428
5436
  const I = (h) => {
5429
- v(h), O.current.includes(h) && _i(h) && (n == null || n.setCompanionLayout(h).catch(() => {
5437
+ v(h), N.current.includes(h) && _i(h) && (n == null || n.setCompanionLayout(h).catch(() => {
5430
5438
  }));
5431
- }, [E, _] = J(r), [S, M] = J(a), [u, g] = J({
5439
+ }, [E, _] = J(r), [S, M] = J(a), [d, g] = J({
5432
5440
  side: r,
5433
5441
  mode: a
5434
5442
  });
5435
- (u.side !== r || u.mode !== a) && (g({
5443
+ (d.side !== r || d.mode !== a) && (g({
5436
5444
  side: r,
5437
5445
  mode: a
5438
- }), u.side !== r && _(r), u.mode !== a && M(a)), q(() => {
5446
+ }), d.side !== r && _(r), d.mode !== a && M(a)), F(() => {
5439
5447
  if (!n) return;
5440
5448
  let h = !1;
5441
5449
  return n.getCompanionLayout().then((w) => {
5442
- h || !w || O.current.includes(w) && p(w);
5450
+ h || !w || N.current.includes(w) && p(w);
5443
5451
  }).catch(() => {
5444
5452
  }), n.getCompanionSidebarSide().then((w) => {
5445
5453
  !h && w && _(w);
@@ -5451,13 +5459,13 @@ function Ai({
5451
5459
  h = !0;
5452
5460
  };
5453
5461
  }, [n]);
5454
- const m = U(
5462
+ const m = q(
5455
5463
  (h) => {
5456
5464
  _(h), n == null || n.setCompanionSidebarSide(h).catch(() => {
5457
5465
  });
5458
5466
  },
5459
5467
  [n]
5460
- ), y = U(
5468
+ ), y = q(
5461
5469
  (h) => {
5462
5470
  M(h), n == null || n.setCompanionSidebarMode(h).catch(() => {
5463
5471
  });
@@ -5465,7 +5473,7 @@ function Ai({
5465
5473
  [n]
5466
5474
  );
5467
5475
  return /* @__PURE__ */ K.createElement(
5468
- oa.Provider,
5476
+ la.Provider,
5469
5477
  {
5470
5478
  value: {
5471
5479
  layout: c,
@@ -5483,7 +5491,7 @@ function Ai({
5483
5491
  );
5484
5492
  }
5485
5493
  function Ki() {
5486
- const t = Ne(oa);
5494
+ const t = Ne(la);
5487
5495
  if (!t)
5488
5496
  throw new Error(
5489
5497
  "useWidgetLayout must be used within a WidgetLayoutProvider"
@@ -5492,13 +5500,13 @@ function Ki() {
5492
5500
  }
5493
5501
  function Yi() {
5494
5502
  var s, f;
5495
- const { widgetCtx: t } = re(), { 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(
5496
5504
  (c) => {
5497
- var p, d;
5505
+ var p, u;
5498
5506
  return [
5499
5507
  (i == null ? void 0 : i.id) || "",
5500
5508
  ((p = i == null ? void 0 : i.name) == null ? void 0 : p.toLowerCase()) || "",
5501
- ((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()) || ""
5502
5510
  ].includes(c.key.toLowerCase());
5503
5511
  }
5504
5512
  )) == null ? void 0 : f.component;
@@ -5513,7 +5521,7 @@ function Yi() {
5513
5521
  function Hi() {
5514
5522
  const { widgetCtx: t } = re(), {
5515
5523
  messagesState: { messages: e }
5516
- } = na(), {
5524
+ } = sa(), {
5517
5525
  csatRequestedMessage: r,
5518
5526
  isCsatRequested: a,
5519
5527
  csatSubmittedMessage: n,
@@ -5546,9 +5554,9 @@ function Hi() {
5546
5554
  };
5547
5555
  }
5548
5556
  function Gi(t) {
5549
- const { widgetCtx: e } = re(), r = e.dictationCtx, a = H(r.state), n = R(t);
5557
+ const { widgetCtx: e } = re(), r = e.dictationCtx, a = H(r.state), n = O(t);
5550
5558
  n.current = t;
5551
- const i = U(() => {
5559
+ const i = q(() => {
5552
5560
  r.start({
5553
5561
  getValue: () => n.current.getValue(),
5554
5562
  setValue: (s) => n.current.setValue(s),
@@ -5557,10 +5565,10 @@ function Gi(t) {
5557
5565
  return (f = (s = n.current).onSend) == null ? void 0 : f.call(s);
5558
5566
  }
5559
5567
  });
5560
- }, [r]), l = U(() => {
5568
+ }, [r]), l = q(() => {
5561
5569
  r.isActive() ? r.stop() : i();
5562
5570
  }, [r, i]);
5563
- return q(() => () => r.stop({ executeFinalCommand: !1 }), [r]), {
5571
+ return F(() => () => r.stop({ executeFinalCommand: !1 }), [r]), {
5564
5572
  enabled: e.features.dictation,
5565
5573
  status: a.status,
5566
5574
  error: a.error,
@@ -5574,21 +5582,21 @@ function Gi(t) {
5574
5582
  };
5575
5583
  }
5576
5584
  function Qi() {
5577
- const { widgetCtx: t } = re(), e = t.messageCtx.draftState, r = H(e), a = U(
5585
+ const { widgetCtx: t } = re(), e = t.messageCtx.draftState, r = H(e), a = q(
5578
5586
  (l) => {
5579
5587
  e.setPartial({
5580
5588
  text: typeof l == "function" ? l(e.get().text) : l
5581
5589
  });
5582
5590
  },
5583
5591
  [e]
5584
- ), n = U(
5592
+ ), n = q(
5585
5593
  (l) => {
5586
5594
  e.setPartial({
5587
5595
  mentions: typeof l == "function" ? l(e.get().mentions) : l
5588
5596
  });
5589
5597
  },
5590
5598
  [e]
5591
- ), i = U(
5599
+ ), i = q(
5592
5600
  (l = r) => e.get() !== l ? !1 : (e.reset(), !0),
5593
5601
  [e, r]
5594
5602
  );
@@ -5602,7 +5610,7 @@ export {
5602
5610
  fr as applyPresentation,
5603
5611
  Ni as formatAskQuestionsAnswers,
5604
5612
  Li as sessionPlan,
5605
- Gr as useAgentChatUi,
5613
+ Qr as useAgentChatUi,
5606
5614
  Fi as useBot,
5607
5615
  Di as useCompanionChats,
5608
5616
  Qi as useComposerDraft,
@@ -5615,10 +5623,10 @@ export {
5615
5623
  vi as useDocumentDir,
5616
5624
  qi as useHostLocation,
5617
5625
  zi as useIsAwaitingBotReply,
5618
- na as useMessages,
5626
+ sa as useMessages,
5619
5627
  Yi as useModes,
5620
5628
  H as usePrimitiveState,
5621
- sa as useSessions,
5629
+ ia as useSessions,
5622
5630
  Zi as useUnread,
5623
5631
  Vi as useUnreadViewing,
5624
5632
  Bi as useUploadFiles,