@teodorruskvi/chat-core 0.1.29 → 0.1.30

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.esm.js CHANGED
@@ -1,43 +1,43 @@
1
- var Un = Object.defineProperty;
2
- var Fn = (e, t, n) => t in e ? Un(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var Bt = (e, t, n) => Fn(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsx as Me } from "react/jsx-runtime";
1
+ var zn = Object.defineProperty;
2
+ var Un = (e, t, n) => t in e ? zn(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
+ var Bt = (e, t, n) => Un(e, typeof t != "symbol" ? t + "" : t, n);
4
+ import { jsx as Ce } from "react/jsx-runtime";
5
5
  import * as Dt from "react";
6
- import { createContext as Ge, useContext as at, useState as H, useRef as K, useEffect as oe, useCallback as E, useMemo as pe, useReducer as jn } from "react";
7
- import On, { isCancel as Vt } from "axios";
8
- function sn(e) {
6
+ import { createContext as Ge, useContext as at, useState as H, useRef as K, useEffect as ae, useCallback as E, useMemo as fe, useReducer as Fn } from "react";
7
+ import jn, { isCancel as Vt } from "axios";
8
+ function rn(e) {
9
9
  var t, n, r = "";
10
10
  if (typeof e == "string" || typeof e == "number") r += e;
11
11
  else if (typeof e == "object") if (Array.isArray(e)) {
12
12
  var s = e.length;
13
- for (t = 0; t < s; t++) e[t] && (n = sn(e[t])) && (r && (r += " "), r += n);
13
+ for (t = 0; t < s; t++) e[t] && (n = rn(e[t])) && (r && (r += " "), r += n);
14
14
  } else for (n in e) e[n] && (r && (r += " "), r += n);
15
15
  return r;
16
16
  }
17
- function $n() {
18
- for (var e, t, n = 0, r = "", s = arguments.length; n < s; n++) (e = arguments[n]) && (t = sn(e)) && (r && (r += " "), r += t);
17
+ function On() {
18
+ for (var e, t, n = 0, r = "", s = arguments.length; n < s; n++) (e = arguments[n]) && (t = rn(e)) && (r && (r += " "), r += t);
19
19
  return r;
20
20
  }
21
- const zt = "-", Bn = (e) => {
22
- const t = Vn(e), {
21
+ const zt = "-", $n = (e) => {
22
+ const t = Dn(e), {
23
23
  conflictingClassGroups: n,
24
24
  conflictingClassGroupModifiers: r
25
25
  } = e;
26
26
  return {
27
27
  getClassGroupId: (a) => {
28
28
  const i = a.split(zt);
29
- return i[0] === "" && i.length !== 1 && i.shift(), on(i, t) || Dn(a);
29
+ return i[0] === "" && i.length !== 1 && i.shift(), sn(i, t) || Bn(a);
30
30
  },
31
31
  getConflictingClassGroupIds: (a, i) => {
32
32
  const f = n[a] || [];
33
33
  return i && r[a] ? [...f, ...r[a]] : f;
34
34
  }
35
35
  };
36
- }, on = (e, t) => {
36
+ }, sn = (e, t) => {
37
37
  var a;
38
38
  if (e.length === 0)
39
39
  return t.classGroupId;
40
- const n = e[0], r = t.nextPart.get(n), s = r ? on(e.slice(1), r) : void 0;
40
+ const n = e[0], r = t.nextPart.get(n), s = r ? sn(e.slice(1), r) : void 0;
41
41
  if (s)
42
42
  return s;
43
43
  if (t.validators.length === 0)
@@ -46,13 +46,13 @@ const zt = "-", Bn = (e) => {
46
46
  return (a = t.validators.find(({
47
47
  validator: i
48
48
  }) => i(o))) == null ? void 0 : a.classGroupId;
49
- }, Kt = /^\[(.+)\]$/, Dn = (e) => {
49
+ }, Kt = /^\[(.+)\]$/, Bn = (e) => {
50
50
  if (Kt.test(e)) {
51
51
  const t = Kt.exec(e)[1], n = t == null ? void 0 : t.substring(0, t.indexOf(":"));
52
52
  if (n)
53
53
  return "arbitrary.." + n;
54
54
  }
55
- }, Vn = (e) => {
55
+ }, Dn = (e) => {
56
56
  const {
57
57
  theme: t,
58
58
  prefix: n
@@ -60,7 +60,7 @@ const zt = "-", Bn = (e) => {
60
60
  nextPart: /* @__PURE__ */ new Map(),
61
61
  validators: []
62
62
  };
63
- return Hn(Object.entries(e.classGroups), n).forEach(([o, a]) => {
63
+ return Kn(Object.entries(e.classGroups), n).forEach(([o, a]) => {
64
64
  Nt(a, r, o, t);
65
65
  }), r;
66
66
  }, Nt = (e, t, n, r) => {
@@ -71,7 +71,7 @@ const zt = "-", Bn = (e) => {
71
71
  return;
72
72
  }
73
73
  if (typeof s == "function") {
74
- if (Kn(s)) {
74
+ if (Vn(s)) {
75
75
  Nt(s(r), t, n, r);
76
76
  return;
77
77
  }
@@ -93,10 +93,10 @@ const zt = "-", Bn = (e) => {
93
93
  validators: []
94
94
  }), n = n.nextPart.get(r);
95
95
  }), n;
96
- }, Kn = (e) => e.isThemeGetter, Hn = (e, t) => t ? e.map(([n, r]) => {
96
+ }, Vn = (e) => e.isThemeGetter, Kn = (e, t) => t ? e.map(([n, r]) => {
97
97
  const s = r.map((o) => typeof o == "string" ? t + o : typeof o == "object" ? Object.fromEntries(Object.entries(o).map(([a, i]) => [t + a, i])) : o);
98
98
  return [n, s];
99
- }) : e, qn = (e) => {
99
+ }) : e, Hn = (e) => {
100
100
  if (e < 1)
101
101
  return {
102
102
  get: () => {
@@ -120,7 +120,7 @@ const zt = "-", Bn = (e) => {
120
120
  n.has(o) ? n.set(o, a) : s(o, a);
121
121
  }
122
122
  };
123
- }, an = "!", Wn = (e) => {
123
+ }, on = "!", qn = (e) => {
124
124
  const {
125
125
  separator: t,
126
126
  experimentalParseClassName: n
@@ -141,7 +141,7 @@ const zt = "-", Bn = (e) => {
141
141
  }
142
142
  I === "[" ? l++ : I === "]" && l--;
143
143
  }
144
- const g = f.length === 0 ? i : i.substring(c), h = g.startsWith(an), v = h ? g.substring(1) : g, m = d && d > c ? d - c : void 0;
144
+ const g = f.length === 0 ? i : i.substring(c), h = g.startsWith(on), v = h ? g.substring(1) : g, m = d && d > c ? d - c : void 0;
145
145
  return {
146
146
  modifiers: f,
147
147
  hasImportantModifier: h,
@@ -153,7 +153,7 @@ const zt = "-", Bn = (e) => {
153
153
  className: i,
154
154
  parseClassName: a
155
155
  }) : a;
156
- }, Gn = (e) => {
156
+ }, Wn = (e) => {
157
157
  if (e.length <= 1)
158
158
  return e;
159
159
  const t = [];
@@ -161,16 +161,16 @@ const zt = "-", Bn = (e) => {
161
161
  return e.forEach((r) => {
162
162
  r[0] === "[" ? (t.push(...n.sort(), r), n = []) : n.push(r);
163
163
  }), t.push(...n.sort()), t;
164
- }, Jn = (e) => ({
165
- cache: qn(e.cacheSize),
166
- parseClassName: Wn(e),
167
- ...Bn(e)
168
- }), Xn = /\s+/, Qn = (e, t) => {
164
+ }, Gn = (e) => ({
165
+ cache: Hn(e.cacheSize),
166
+ parseClassName: qn(e),
167
+ ...$n(e)
168
+ }), Jn = /\s+/, Xn = (e, t) => {
169
169
  const {
170
170
  parseClassName: n,
171
171
  getClassGroupId: r,
172
172
  getConflictingClassGroupIds: s
173
- } = t, o = [], a = e.trim().split(Xn);
173
+ } = t, o = [], a = e.trim().split(Jn);
174
174
  let i = "";
175
175
  for (let f = a.length - 1; f >= 0; f -= 1) {
176
176
  const l = a[f], {
@@ -191,7 +191,7 @@ const zt = "-", Bn = (e) => {
191
191
  }
192
192
  v = !1;
193
193
  }
194
- const y = Gn(c).join(":"), I = d ? y + an : y, A = I + m;
194
+ const y = Wn(c).join(":"), I = d ? y + on : y, A = I + m;
195
195
  if (o.includes(A))
196
196
  continue;
197
197
  o.push(A);
@@ -204,60 +204,60 @@ const zt = "-", Bn = (e) => {
204
204
  }
205
205
  return i;
206
206
  };
207
- function Yn() {
207
+ function Qn() {
208
208
  let e = 0, t, n, r = "";
209
209
  for (; e < arguments.length; )
210
- (t = arguments[e++]) && (n = cn(t)) && (r && (r += " "), r += n);
210
+ (t = arguments[e++]) && (n = an(t)) && (r && (r += " "), r += n);
211
211
  return r;
212
212
  }
213
- const cn = (e) => {
213
+ const an = (e) => {
214
214
  if (typeof e == "string")
215
215
  return e;
216
216
  let t, n = "";
217
217
  for (let r = 0; r < e.length; r++)
218
- e[r] && (t = cn(e[r])) && (n && (n += " "), n += t);
218
+ e[r] && (t = an(e[r])) && (n && (n += " "), n += t);
219
219
  return n;
220
220
  };
221
- function Zn(e, ...t) {
221
+ function Yn(e, ...t) {
222
222
  let n, r, s, o = a;
223
223
  function a(f) {
224
224
  const l = t.reduce((c, d) => d(c), e());
225
- return n = Jn(l), r = n.cache.get, s = n.cache.set, o = i, i(f);
225
+ return n = Gn(l), r = n.cache.get, s = n.cache.set, o = i, i(f);
226
226
  }
227
227
  function i(f) {
228
228
  const l = r(f);
229
229
  if (l)
230
230
  return l;
231
- const c = Qn(f, n);
231
+ const c = Xn(f, n);
232
232
  return s(f, c), c;
233
233
  }
234
234
  return function() {
235
- return o(Yn.apply(null, arguments));
235
+ return o(Qn.apply(null, arguments));
236
236
  };
237
237
  }
238
238
  const Z = (e) => {
239
239
  const t = (n) => n[e] || [];
240
240
  return t.isThemeGetter = !0, t;
241
- }, ln = /^\[(?:([a-z-]+):)?(.+)\]$/i, er = /^\d+\/\d+$/, tr = /* @__PURE__ */ new Set(["px", "full", "screen"]), nr = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, rr = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/, sr = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, or = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, ar = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, _e = (e) => qe(e) || tr.has(e) || er.test(e), Ue = (e) => Je(e, "length", gr), qe = (e) => !!e && !Number.isNaN(Number(e)), xt = (e) => Je(e, "number", qe), Ze = (e) => !!e && Number.isInteger(Number(e)), ir = (e) => e.endsWith("%") && qe(e.slice(0, -1)), F = (e) => ln.test(e), Fe = (e) => nr.test(e), cr = /* @__PURE__ */ new Set(["length", "size", "percentage"]), lr = (e) => Je(e, cr, un), ur = (e) => Je(e, "position", un), dr = /* @__PURE__ */ new Set(["image", "url"]), fr = (e) => Je(e, dr, hr), pr = (e) => Je(e, "", mr), et = () => !0, Je = (e, t, n) => {
242
- const r = ln.exec(e);
241
+ }, cn = /^\[(?:([a-z-]+):)?(.+)\]$/i, Zn = /^\d+\/\d+$/, er = /* @__PURE__ */ new Set(["px", "full", "screen"]), tr = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, nr = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/, rr = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, sr = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, or = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, Ne = (e) => qe(e) || er.has(e) || Zn.test(e), ze = (e) => Je(e, "length", pr), qe = (e) => !!e && !Number.isNaN(Number(e)), xt = (e) => Je(e, "number", qe), Ze = (e) => !!e && Number.isInteger(Number(e)), ar = (e) => e.endsWith("%") && qe(e.slice(0, -1)), F = (e) => cn.test(e), Ue = (e) => tr.test(e), ir = /* @__PURE__ */ new Set(["length", "size", "percentage"]), cr = (e) => Je(e, ir, ln), lr = (e) => Je(e, "position", ln), ur = /* @__PURE__ */ new Set(["image", "url"]), dr = (e) => Je(e, ur, mr), fr = (e) => Je(e, "", gr), et = () => !0, Je = (e, t, n) => {
242
+ const r = cn.exec(e);
243
243
  return r ? r[1] ? typeof t == "string" ? r[1] === t : t.has(r[1]) : n(r[2]) : !1;
244
- }, gr = (e) => (
244
+ }, pr = (e) => (
245
245
  // `colorFunctionRegex` check is necessary because color functions can have percentages in them which which would be incorrectly classified as lengths.
246
246
  // For example, `hsl(0 0% 0%)` would be classified as a length without this check.
247
247
  // I could also use lookbehind assertion in `lengthUnitRegex` but that isn't supported widely enough.
248
- rr.test(e) && !sr.test(e)
249
- ), un = () => !1, mr = (e) => or.test(e), hr = (e) => ar.test(e), yr = () => {
250
- const e = Z("colors"), t = Z("spacing"), n = Z("blur"), r = Z("brightness"), s = Z("borderColor"), o = Z("borderRadius"), a = Z("borderSpacing"), i = Z("borderWidth"), f = Z("contrast"), l = Z("grayscale"), c = Z("hueRotate"), d = Z("invert"), g = Z("gap"), h = Z("gradientColorStops"), v = Z("gradientColorStopPositions"), m = Z("inset"), y = Z("margin"), I = Z("opacity"), A = Z("padding"), x = Z("saturate"), N = Z("scale"), _ = Z("sepia"), k = Z("skew"), T = Z("space"), L = Z("translate"), j = () => ["auto", "contain", "none"], O = () => ["auto", "hidden", "clip", "visible", "scroll"], $ = () => ["auto", F, t], C = () => [F, t], J = () => ["", _e, Ue], G = () => ["auto", qe, F], X = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], te = () => ["solid", "dashed", "dotted", "double", "none"], ne = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], S = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], P = () => ["", "0", F], D = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], V = () => [qe, F];
248
+ nr.test(e) && !rr.test(e)
249
+ ), ln = () => !1, gr = (e) => sr.test(e), mr = (e) => or.test(e), hr = () => {
250
+ const e = Z("colors"), t = Z("spacing"), n = Z("blur"), r = Z("brightness"), s = Z("borderColor"), o = Z("borderRadius"), a = Z("borderSpacing"), i = Z("borderWidth"), f = Z("contrast"), l = Z("grayscale"), c = Z("hueRotate"), d = Z("invert"), g = Z("gap"), h = Z("gradientColorStops"), v = Z("gradientColorStopPositions"), m = Z("inset"), y = Z("margin"), I = Z("opacity"), A = Z("padding"), x = Z("saturate"), N = Z("scale"), _ = Z("sepia"), k = Z("skew"), T = Z("space"), L = Z("translate"), j = () => ["auto", "contain", "none"], O = () => ["auto", "hidden", "clip", "visible", "scroll"], $ = () => ["auto", F, t], C = () => [F, t], J = () => ["", Ne, ze], W = () => ["auto", qe, F], Q = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], te = () => ["solid", "dashed", "dotted", "double", "none"], ne = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], S = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], P = () => ["", "0", F], D = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], V = () => [qe, F];
251
251
  return {
252
252
  cacheSize: 500,
253
253
  separator: ":",
254
254
  theme: {
255
255
  colors: [et],
256
- spacing: [_e, Ue],
257
- blur: ["none", "", Fe, F],
256
+ spacing: [Ne, ze],
257
+ blur: ["none", "", Ue, F],
258
258
  brightness: V(),
259
259
  borderColor: [e],
260
- borderRadius: ["none", "", "full", Fe, F],
260
+ borderRadius: ["none", "", "full", Ue, F],
261
261
  borderSpacing: C(),
262
262
  borderWidth: J(),
263
263
  contrast: V(),
@@ -266,7 +266,7 @@ const Z = (e) => {
266
266
  invert: P(),
267
267
  gap: C(),
268
268
  gradientColorStops: [e],
269
- gradientColorStopPositions: [ir, Ue],
269
+ gradientColorStopPositions: [ar, ze],
270
270
  inset: $(),
271
271
  margin: $(),
272
272
  opacity: V(),
@@ -297,7 +297,7 @@ const Z = (e) => {
297
297
  * @see https://tailwindcss.com/docs/columns
298
298
  */
299
299
  columns: [{
300
- columns: [Fe]
300
+ columns: [Ue]
301
301
  }],
302
302
  /**
303
303
  * Break After
@@ -370,7 +370,7 @@ const Z = (e) => {
370
370
  * @see https://tailwindcss.com/docs/object-position
371
371
  */
372
372
  "object-position": [{
373
- object: [...X(), F]
373
+ object: [...Q(), F]
374
374
  }],
375
375
  /**
376
376
  * Overflow
@@ -565,14 +565,14 @@ const Z = (e) => {
565
565
  * @see https://tailwindcss.com/docs/grid-column
566
566
  */
567
567
  "col-start": [{
568
- "col-start": G()
568
+ "col-start": W()
569
569
  }],
570
570
  /**
571
571
  * Grid Column End
572
572
  * @see https://tailwindcss.com/docs/grid-column
573
573
  */
574
574
  "col-end": [{
575
- "col-end": G()
575
+ "col-end": W()
576
576
  }],
577
577
  /**
578
578
  * Grid Template Rows
@@ -595,14 +595,14 @@ const Z = (e) => {
595
595
  * @see https://tailwindcss.com/docs/grid-row
596
596
  */
597
597
  "row-start": [{
598
- "row-start": G()
598
+ "row-start": W()
599
599
  }],
600
600
  /**
601
601
  * Grid Row End
602
602
  * @see https://tailwindcss.com/docs/grid-row
603
603
  */
604
604
  "row-end": [{
605
- "row-end": G()
605
+ "row-end": W()
606
606
  }],
607
607
  /**
608
608
  * Grid Auto Flow
@@ -881,8 +881,8 @@ const Z = (e) => {
881
881
  */
882
882
  "max-w": [{
883
883
  "max-w": [F, t, "none", "full", "min", "max", "fit", "prose", {
884
- screen: [Fe]
885
- }, Fe]
884
+ screen: [Ue]
885
+ }, Ue]
886
886
  }],
887
887
  /**
888
888
  * Height
@@ -918,7 +918,7 @@ const Z = (e) => {
918
918
  * @see https://tailwindcss.com/docs/font-size
919
919
  */
920
920
  "font-size": [{
921
- text: ["base", Fe, Ue]
921
+ text: ["base", Ue, ze]
922
922
  }],
923
923
  /**
924
924
  * Font Smoothing
@@ -993,7 +993,7 @@ const Z = (e) => {
993
993
  * @see https://tailwindcss.com/docs/line-height
994
994
  */
995
995
  leading: [{
996
- leading: ["none", "tight", "snug", "normal", "relaxed", "loose", _e, F]
996
+ leading: ["none", "tight", "snug", "normal", "relaxed", "loose", Ne, F]
997
997
  }],
998
998
  /**
999
999
  * List Style Image
@@ -1069,14 +1069,14 @@ const Z = (e) => {
1069
1069
  * @see https://tailwindcss.com/docs/text-decoration-thickness
1070
1070
  */
1071
1071
  "text-decoration-thickness": [{
1072
- decoration: ["auto", "from-font", _e, Ue]
1072
+ decoration: ["auto", "from-font", Ne, ze]
1073
1073
  }],
1074
1074
  /**
1075
1075
  * Text Underline Offset
1076
1076
  * @see https://tailwindcss.com/docs/text-underline-offset
1077
1077
  */
1078
1078
  "underline-offset": [{
1079
- "underline-offset": ["auto", _e, F]
1079
+ "underline-offset": ["auto", Ne, F]
1080
1080
  }],
1081
1081
  /**
1082
1082
  * Text Decoration Color
@@ -1179,7 +1179,7 @@ const Z = (e) => {
1179
1179
  * @see https://tailwindcss.com/docs/background-position
1180
1180
  */
1181
1181
  "bg-position": [{
1182
- bg: [...X(), ur]
1182
+ bg: [...Q(), lr]
1183
1183
  }],
1184
1184
  /**
1185
1185
  * Background Repeat
@@ -1195,7 +1195,7 @@ const Z = (e) => {
1195
1195
  * @see https://tailwindcss.com/docs/background-size
1196
1196
  */
1197
1197
  "bg-size": [{
1198
- bg: ["auto", "cover", "contain", lr]
1198
+ bg: ["auto", "cover", "contain", cr]
1199
1199
  }],
1200
1200
  /**
1201
1201
  * Background Image
@@ -1204,7 +1204,7 @@ const Z = (e) => {
1204
1204
  "bg-image": [{
1205
1205
  bg: ["none", {
1206
1206
  "gradient-to": ["t", "tr", "r", "br", "b", "bl", "l", "tl"]
1207
- }, fr]
1207
+ }, dr]
1208
1208
  }],
1209
1209
  /**
1210
1210
  * Background Color
@@ -1558,14 +1558,14 @@ const Z = (e) => {
1558
1558
  * @see https://tailwindcss.com/docs/outline-offset
1559
1559
  */
1560
1560
  "outline-offset": [{
1561
- "outline-offset": [_e, F]
1561
+ "outline-offset": [Ne, F]
1562
1562
  }],
1563
1563
  /**
1564
1564
  * Outline Width
1565
1565
  * @see https://tailwindcss.com/docs/outline-width
1566
1566
  */
1567
1567
  "outline-w": [{
1568
- outline: [_e, Ue]
1568
+ outline: [Ne, ze]
1569
1569
  }],
1570
1570
  /**
1571
1571
  * Outline Color
@@ -1605,7 +1605,7 @@ const Z = (e) => {
1605
1605
  * @see https://tailwindcss.com/docs/ring-offset-width
1606
1606
  */
1607
1607
  "ring-offset-w": [{
1608
- "ring-offset": [_e, Ue]
1608
+ "ring-offset": [Ne, ze]
1609
1609
  }],
1610
1610
  /**
1611
1611
  * Ring Offset Color
@@ -1620,7 +1620,7 @@ const Z = (e) => {
1620
1620
  * @see https://tailwindcss.com/docs/box-shadow
1621
1621
  */
1622
1622
  shadow: [{
1623
- shadow: ["", "inner", "none", Fe, pr]
1623
+ shadow: ["", "inner", "none", Ue, fr]
1624
1624
  }],
1625
1625
  /**
1626
1626
  * Box Shadow Color
@@ -1685,7 +1685,7 @@ const Z = (e) => {
1685
1685
  * @see https://tailwindcss.com/docs/drop-shadow
1686
1686
  */
1687
1687
  "drop-shadow": [{
1688
- "drop-shadow": ["", "none", Fe, F]
1688
+ "drop-shadow": ["", "none", Ue, F]
1689
1689
  }],
1690
1690
  /**
1691
1691
  * Grayscale
@@ -2200,7 +2200,7 @@ const Z = (e) => {
2200
2200
  * @see https://tailwindcss.com/docs/stroke-width
2201
2201
  */
2202
2202
  "stroke-w": [{
2203
- stroke: [_e, Ue, xt]
2203
+ stroke: [Ne, ze, xt]
2204
2204
  }],
2205
2205
  /**
2206
2206
  * Stroke
@@ -2275,11 +2275,11 @@ const Z = (e) => {
2275
2275
  "font-size": ["leading"]
2276
2276
  }
2277
2277
  };
2278
- }, br = /* @__PURE__ */ Zn(yr);
2279
- function Ks(...e) {
2280
- return br($n(e));
2278
+ }, yr = /* @__PURE__ */ Yn(hr);
2279
+ function Vs(...e) {
2280
+ return yr(On(e));
2281
2281
  }
2282
- function wr(e) {
2282
+ function br(e) {
2283
2283
  let t = !1, n = "";
2284
2284
  for (const s of e) {
2285
2285
  if (s === "\\") {
@@ -2300,7 +2300,7 @@ function Ut(e) {
2300
2300
  try {
2301
2301
  return JSON.parse(t);
2302
2302
  } catch {
2303
- const n = wr(t);
2303
+ const n = br(t);
2304
2304
  if (n)
2305
2305
  try {
2306
2306
  return JSON.parse(n);
@@ -2310,29 +2310,29 @@ function Ut(e) {
2310
2310
  return null;
2311
2311
  }
2312
2312
  }
2313
- function kr(e) {
2313
+ function wr(e) {
2314
2314
  return typeof e != "string" ? !1 : /^[\s\n]*[-*]\s|^[\s\n]*#+\s|```|^\s*\[.*\]\(|^>\s/.test(e);
2315
2315
  }
2316
- function vr(e) {
2316
+ function kr(e) {
2317
2317
  return e.type === "image_url";
2318
2318
  }
2319
- function Ir(e) {
2319
+ function vr(e) {
2320
2320
  return e.type === "file";
2321
2321
  }
2322
- function Tr(e) {
2322
+ function Ir(e) {
2323
2323
  return Array.isArray(e.content) ? e.content.filter((t) => t.type === "text").map((t) => t.text).join(`
2324
2324
  `).trim() : typeof e.content == "string" ? e.content : "";
2325
2325
  }
2326
+ function Tr(e) {
2327
+ return e.content.filter(kr);
2328
+ }
2326
2329
  function Ar(e) {
2327
2330
  return e.content.filter(vr);
2328
2331
  }
2329
- function Sr(e) {
2330
- return e.content.filter(Ir);
2331
- }
2332
- function dn(e) {
2332
+ function un(e) {
2333
2333
  return Array.isArray(e.toolCalls) ? e.toolCalls : [];
2334
2334
  }
2335
- function xr(e) {
2335
+ function Sr(e) {
2336
2336
  const t = [];
2337
2337
  return e.forEach((n) => {
2338
2338
  n.artifact && t.push(n.artifact), Array.isArray(n.toolCalls) && n.toolCalls.forEach((r) => {
@@ -2340,7 +2340,7 @@ function xr(e) {
2340
2340
  });
2341
2341
  }), t;
2342
2342
  }
2343
- function fn(e) {
2343
+ function dn(e) {
2344
2344
  return !!(e && typeof e == "object" && (e.type === "file" || e.mimeType || e.filename || e.sourceType === "base64"));
2345
2345
  }
2346
2346
  function yt(e) {
@@ -2355,7 +2355,7 @@ function yt(e) {
2355
2355
  }
2356
2356
  return n;
2357
2357
  }
2358
- if (fn(e)) {
2358
+ if (dn(e)) {
2359
2359
  try {
2360
2360
  console.debug("[message-utils] sanitizeForDisplay - dropping file-like object", {
2361
2361
  sampleFilename: e && (e.filename || e.name) ? e.filename || e.name : void 0,
@@ -2387,9 +2387,9 @@ function yt(e) {
2387
2387
  }
2388
2388
  return e;
2389
2389
  }
2390
- function pn(e) {
2390
+ function fn(e) {
2391
2391
  if (typeof e == "string") return e;
2392
- if (fn(e)) return "";
2392
+ if (dn(e)) return "";
2393
2393
  try {
2394
2394
  const t = yt(e);
2395
2395
  return t === void 0 ? "" : typeof t == "string" ? t : JSON.stringify(t, null, 2);
@@ -2397,11 +2397,11 @@ function pn(e) {
2397
2397
  return "";
2398
2398
  }
2399
2399
  }
2400
- function Hs(e) {
2401
- const t = pn(e);
2402
- return typeof e == "string" && kr(e) ? { content: e, isMarkdown: !0 } : { content: t, isMarkdown: !1 };
2400
+ function Ks(e) {
2401
+ const t = fn(e);
2402
+ return typeof e == "string" && wr(e) ? { content: e, isMarkdown: !0 } : { content: t, isMarkdown: !1 };
2403
2403
  }
2404
- function Cr(e) {
2404
+ function xr(e) {
2405
2405
  const t = (r) => {
2406
2406
  try {
2407
2407
  const s = yt(r);
@@ -2413,47 +2413,47 @@ function Cr(e) {
2413
2413
  return n.length ? t(n.map((r) => r.text).join(`
2414
2414
  `)) : t(e);
2415
2415
  }
2416
- function qs(e) {
2416
+ function Hs(e) {
2417
2417
  return e.content.some((t) => t.type === "text" ? t.text.trim().length > 0 : t.type === "image_url" || t.type === "file");
2418
2418
  }
2419
- function Ee(e) {
2419
+ function Me(e) {
2420
2420
  if (e == null) return e;
2421
2421
  if (typeof e == "string") {
2422
2422
  const t = e.trim();
2423
2423
  if (t.startsWith("{") || t.startsWith("[")) {
2424
2424
  const n = Ut(t);
2425
2425
  if (n !== null)
2426
- return Ee(n);
2426
+ return Me(n);
2427
2427
  }
2428
2428
  return e;
2429
2429
  }
2430
2430
  if (typeof e == "object" && !Array.isArray(e)) {
2431
2431
  if (e.content !== void 0)
2432
- return Array.isArray(e.content) ? e.content.map((t) => Ee(t)).filter(Boolean).join(`
2433
- `) : Ee(e.content);
2432
+ return Array.isArray(e.content) ? e.content.map((t) => Me(t)).filter(Boolean).join(`
2433
+ `) : Me(e.content);
2434
2434
  if (e.value !== void 0)
2435
- return Ee(e.value);
2435
+ return Me(e.value);
2436
2436
  }
2437
- return typeof e == "object" && !Array.isArray(e) && (e.type === "text" && typeof e.text == "string" || typeof e.text == "string") ? e.text : Array.isArray(e) && e.length > 0 ? Ee(e[0]) : e;
2437
+ return typeof e == "object" && !Array.isArray(e) && (e.type === "text" && typeof e.text == "string" || typeof e.text == "string") ? e.text : Array.isArray(e) && e.length > 0 ? Me(e[0]) : e;
2438
2438
  }
2439
- function Mr(e) {
2439
+ function Cr(e) {
2440
2440
  return e.replace(/[_-](\w)/g, (t, n) => n ? n.toUpperCase() : "").replace(/^\w/, (t) => t.toLowerCase());
2441
2441
  }
2442
- function Pe(e) {
2443
- return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(Pe) : Object.fromEntries(
2442
+ function Ee(e) {
2443
+ return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(Ee) : Object.fromEntries(
2444
2444
  Object.entries(e).map(([t, n]) => [
2445
- Mr(t),
2446
- Pe(n)
2445
+ Cr(t),
2446
+ Ee(n)
2447
2447
  ])
2448
2448
  );
2449
2449
  }
2450
2450
  function bt(e) {
2451
2451
  var y, I, A, x, N, _;
2452
2452
  if (!e || typeof e != "object") return null;
2453
- const t = Pe(e), n = Rr(t);
2453
+ const t = Ee(e), n = Pr(t);
2454
2454
  if (!n)
2455
2455
  return null;
2456
- const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(Ft) : void 0, s = Pr(t.content ?? t.parts, !!(r != null && r.length)), o = t.id ?? `msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`, a = t.createdAt ?? ((y = t.additionalKwargs) == null ? void 0 : y.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), i = t.name ?? ((I = t.additionalKwargs) == null ? void 0 : I.agentName) ?? void 0, f = t.model ?? ((A = t.additionalKwargs) == null ? void 0 : A.model) ?? void 0, l = t.toolCallId ?? void 0, c = t.additionalKwargs ?? void 0, d = t.responseMetadata ?? void 0, g = t.checkpointId ?? ((x = t.additionalKwargs) == null ? void 0 : x.checkpointId) ?? void 0, h = t.checkpointNs ?? ((N = t.additionalKwargs) == null ? void 0 : N.checkpointNs) ?? void 0, v = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((_ = t.additionalKwargs) != null && _.toolStreaming);
2456
+ const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(Ft) : void 0, s = Er(t.content ?? t.parts, !!(r != null && r.length)), o = t.id ?? `msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`, a = t.createdAt ?? ((y = t.additionalKwargs) == null ? void 0 : y.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), i = t.name ?? ((I = t.additionalKwargs) == null ? void 0 : I.agentName) ?? void 0, f = t.model ?? ((A = t.additionalKwargs) == null ? void 0 : A.model) ?? void 0, l = t.toolCallId ?? void 0, c = t.additionalKwargs ?? void 0, d = t.responseMetadata ?? void 0, g = t.checkpointId ?? ((x = t.additionalKwargs) == null ? void 0 : x.checkpointId) ?? void 0, h = t.checkpointNs ?? ((N = t.additionalKwargs) == null ? void 0 : N.checkpointNs) ?? void 0, v = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((_ = t.additionalKwargs) != null && _.toolStreaming);
2457
2457
  return {
2458
2458
  ...t,
2459
2459
  id: o,
@@ -2472,9 +2472,9 @@ function bt(e) {
2472
2472
  artifact: t.artifact ?? void 0
2473
2473
  };
2474
2474
  }
2475
- function Er(e) {
2475
+ function Mr(e) {
2476
2476
  if (!e || typeof e != "object") return e;
2477
- const t = Pe(e);
2477
+ const t = Ee(e);
2478
2478
  if (t.tool && !t.name && (t.name = t.tool), t.type === "artifact.update" && t.artifact && typeof t.artifact == "object") {
2479
2479
  const n = t.artifact;
2480
2480
  !n.id && n.artifactId && (n.id = n.artifactId), !n.type && n.artifactType && (n.type = n.artifactType);
@@ -2482,7 +2482,7 @@ function Er(e) {
2482
2482
  return t;
2483
2483
  }
2484
2484
  function Ft(e) {
2485
- const t = Pe(e), n = t.content ?? t.output ?? void 0;
2485
+ const t = Ee(e), n = t.content ?? t.output ?? void 0;
2486
2486
  return {
2487
2487
  ...t,
2488
2488
  type: "tool_call",
@@ -2492,13 +2492,13 @@ function Ft(e) {
2492
2492
  content: typeof n == "string" ? n : n ? JSON.stringify(n) : void 0
2493
2493
  };
2494
2494
  }
2495
- function Pr(e, t) {
2496
- return Array.isArray(e) ? e.map((n) => n.type === "tool_call" || n.type === "tool" ? t ? null : Ft(Pe(n)) : n).filter(
2495
+ function Er(e, t) {
2496
+ return Array.isArray(e) ? e.map((n) => n.type === "tool_call" || n.type === "tool" ? t ? null : Ft(Ee(n)) : n).filter(
2497
2497
  (n) => !!(n && typeof n == "object" && typeof n.type == "string")
2498
2498
  ) : [];
2499
2499
  }
2500
- function Rr(e) {
2501
- const t = Pe(e), n = t.role;
2500
+ function Pr(e) {
2501
+ const t = Ee(e), n = t.role;
2502
2502
  if (n && (n === "assistant" || n === "user" || n === "system" || n === "tool" || n === "interrupt"))
2503
2503
  return n;
2504
2504
  const r = t.type;
@@ -2510,17 +2510,17 @@ function qt(e) {
2510
2510
  return t === "running" || t === "pending" ? "pending" : t === "completed" || t === "success" ? "completed" : t === "error" || t === "failed" || t === "failure" ? "error" : null;
2511
2511
  }
2512
2512
  function Wt(e) {
2513
- return (Array.isArray(e.toolCalls) ? e.toolCalls : dn(e)).map(Ft);
2513
+ return (Array.isArray(e.toolCalls) ? e.toolCalls : un(e)).map(Ft);
2514
2514
  }
2515
2515
  function Ct(e, t) {
2516
2516
  return t.find(
2517
2517
  (n) => n.role === "tool" && (n.toolCallId === e || n.id === e)
2518
2518
  );
2519
2519
  }
2520
- function Nr(e, t) {
2520
+ function Rr(e, t) {
2521
2521
  const n = t.response ?? t.content;
2522
2522
  if (!n) return;
2523
- const r = typeof n == "string" ? n : pn(n);
2523
+ const r = typeof n == "string" ? n : fn(n);
2524
2524
  if (!r.trim()) return;
2525
2525
  const s = [{ type: "text", text: r }];
2526
2526
  return {
@@ -2533,14 +2533,14 @@ function Nr(e, t) {
2533
2533
  createdAt: e.createdAt
2534
2534
  };
2535
2535
  }
2536
- function _r(e, t = []) {
2536
+ function Nr(e, t = []) {
2537
2537
  if (Array.isArray(e)) {
2538
2538
  const s = e.filter((a) => a.role === "assistant").flatMap((a) => Wt(a)), o = /* @__PURE__ */ new Map();
2539
2539
  return s.forEach((a) => o.set(a.id, a)), Array.from(o.values()).map((a) => {
2540
2540
  var d, g, h;
2541
2541
  const i = Ct(a.id, e) || Ct(a.id, t), f = Array.isArray((d = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : d.toolProgress) ? (g = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : g.toolProgress : void 0, l = (i == null ? void 0 : i.artifact) ?? a.artifact, c = qt(a.status) ?? ((h = i == null ? void 0 : i.additionalKwargs) != null && h.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2542
2542
  if (i && !a.content && c === "completed") {
2543
- const v = Ee(i);
2543
+ const v = Me(i);
2544
2544
  typeof v == "string" && (a.content = v);
2545
2545
  }
2546
2546
  return {
@@ -2556,9 +2556,9 @@ function _r(e, t = []) {
2556
2556
  const n = Wt(e);
2557
2557
  return n.length === 0 ? [] : n.map((r) => {
2558
2558
  var f, l, c;
2559
- const s = Ct(r.id, t) ?? Nr(e, r), o = Array.isArray((f = s == null ? void 0 : s.additionalKwargs) == null ? void 0 : f.toolProgress) ? (l = s == null ? void 0 : s.additionalKwargs) == null ? void 0 : l.toolProgress : void 0, a = (s == null ? void 0 : s.artifact) ?? r.artifact, i = qt(r.status) ?? ((c = s == null ? void 0 : s.additionalKwargs) != null && c.toolStreaming ? "pending" : null) ?? (s ? "completed" : "pending");
2559
+ const s = Ct(r.id, t) ?? Rr(e, r), o = Array.isArray((f = s == null ? void 0 : s.additionalKwargs) == null ? void 0 : f.toolProgress) ? (l = s == null ? void 0 : s.additionalKwargs) == null ? void 0 : l.toolProgress : void 0, a = (s == null ? void 0 : s.artifact) ?? r.artifact, i = qt(r.status) ?? ((c = s == null ? void 0 : s.additionalKwargs) != null && c.toolStreaming ? "pending" : null) ?? (s ? "completed" : "pending");
2560
2560
  if (s && !r.content && i === "completed") {
2561
- const d = Ee(s);
2561
+ const d = Me(s);
2562
2562
  typeof d == "string" && (r.content = d);
2563
2563
  }
2564
2564
  return {
@@ -2570,8 +2570,8 @@ function _r(e, t = []) {
2570
2570
  };
2571
2571
  });
2572
2572
  }
2573
- function Ws(e, t = []) {
2574
- return _r(e, t).map((n) => n.artifact).filter((n) => !!n);
2573
+ function qs(e, t = []) {
2574
+ return Nr(e, t).map((n) => n.artifact).filter((n) => !!n);
2575
2575
  }
2576
2576
  const nt = {
2577
2577
  authToken: "authToken",
@@ -2587,18 +2587,18 @@ function Mt(e) {
2587
2587
  }
2588
2588
  let wt = null;
2589
2589
  const _t = /* @__PURE__ */ new Set();
2590
- function gn() {
2590
+ function pn() {
2591
2591
  return wt;
2592
2592
  }
2593
2593
  function Ve(e) {
2594
2594
  wt = e, _t.forEach((t) => t(e));
2595
2595
  }
2596
- function mn(e) {
2596
+ function gn(e) {
2597
2597
  return _t.add(e), () => _t.delete(e);
2598
2598
  }
2599
- const Lr = 12e4, zr = 12e4;
2600
- let Lt = Lr, hn = zr;
2601
- const ye = On.create({
2599
+ const _r = 12e4, Lr = 12e4;
2600
+ let Lt = _r, mn = Lr;
2601
+ const ye = jn.create({
2602
2602
  // BaseURL is set dynamically via ApiProvider -> api.updateConfig
2603
2603
  timeout: Lt,
2604
2604
  withCredentials: !0
@@ -2606,12 +2606,12 @@ const ye = On.create({
2606
2606
  function Gt(e) {
2607
2607
  return typeof e != "number" || !Number.isFinite(e) || e <= 0 ? null : Math.floor(e);
2608
2608
  }
2609
- function Ur(e) {
2609
+ function zr(e) {
2610
2610
  const t = Gt(e.requestTimeoutMs), n = Gt(e.historyTimeoutMs);
2611
- t !== null && (Lt = t, ye.defaults.timeout = Lt), n !== null && (hn = n);
2611
+ t !== null && (Lt = t, ye.defaults.timeout = Lt), n !== null && (mn = n);
2612
2612
  }
2613
- function Fr() {
2614
- return hn;
2613
+ function Ur() {
2614
+ return mn;
2615
2615
  }
2616
2616
  ye.interceptors.request.use((e) => (wt && (e.headers.Authorization = `Bearer ${wt}`), e));
2617
2617
  ye.interceptors.response.use(
@@ -2631,22 +2631,22 @@ ye.interceptors.response.use(
2631
2631
  },
2632
2632
  (e) => Promise.reject(e)
2633
2633
  );
2634
- async function Ie(e, t) {
2634
+ async function ve(e, t) {
2635
2635
  return ye.defaults.baseURL ? (await ye.get(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2636
2636
  }
2637
2637
  async function ft(e, t, n) {
2638
2638
  return ye.defaults.baseURL ? (await ye.post(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2639
2639
  }
2640
- async function jr(e, t, n) {
2640
+ async function Fr(e, t, n) {
2641
2641
  return ye.defaults.baseURL ? (await ye.put(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2642
2642
  }
2643
2643
  async function Jt(e, t) {
2644
2644
  return ye.defaults.baseURL ? (await ye.delete(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2645
2645
  }
2646
- function ke(e) {
2646
+ function we(e) {
2647
2647
  return e && typeof e == "object" && "data" in e ? e.data : e;
2648
2648
  }
2649
- class Or {
2649
+ class jr {
2650
2650
  // ---- Configuration ----
2651
2651
  // Chat client uses the default httpClient baseURL, no need for internal tracking
2652
2652
  // unless we want to support multiple instances with different URLs in the future.
@@ -2660,28 +2660,28 @@ class Or {
2660
2660
  const n = t.baseUrl.replace(/\/+$/, "");
2661
2661
  n.endsWith("/chat") ? ye.defaults.baseURL = n : ye.defaults.baseURL = `${n}/chat`;
2662
2662
  }
2663
- t.apiKey !== void 0 ? Ve(t.apiKey) : t.getToken && Ve(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Ur({
2663
+ t.apiKey !== void 0 ? Ve(t.apiKey) : t.getToken && Ve(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && zr({
2664
2664
  requestTimeoutMs: t.requestTimeoutMs,
2665
2665
  historyTimeoutMs: t.historyTimeoutMs
2666
2666
  });
2667
2667
  }
2668
2668
  // ---- Token Management ----
2669
2669
  getAuthToken() {
2670
- return gn();
2670
+ return pn();
2671
2671
  }
2672
2672
  setAuthToken(t) {
2673
2673
  Ve(t);
2674
2674
  }
2675
2675
  onTokenChange(t) {
2676
- return mn(t);
2676
+ return gn(t);
2677
2677
  }
2678
2678
  // ---- Thread Management ----
2679
2679
  async listThreads() {
2680
- const t = await Ie("/threads"), n = ke(t);
2680
+ const t = await ve("/threads"), n = we(t);
2681
2681
  return (n == null ? void 0 : n.items) ?? (t == null ? void 0 : t.items) ?? [];
2682
2682
  }
2683
2683
  async listSharedThreads() {
2684
- const t = await Ie("/threads/shared"), n = ke(t);
2684
+ const t = await ve("/threads/shared"), n = we(t);
2685
2685
  return (n == null ? void 0 : n.items) ?? (t == null ? void 0 : t.items) ?? [];
2686
2686
  }
2687
2687
  // listUsers moved to AuthApi
@@ -2689,79 +2689,78 @@ class Or {
2689
2689
  const r = {};
2690
2690
  t && (r.title = t), n && (r.project = n);
2691
2691
  const s = await ft("/threads", Object.keys(r).length ? r : void 0);
2692
- return ke(s);
2692
+ return we(s);
2693
2693
  }
2694
2694
  async updateThread(t, n) {
2695
- const r = await jr(`/threads/${t}`, { title: n });
2696
- return ke(r);
2695
+ const r = await Fr(`/threads/${t}`, { title: n });
2696
+ return we(r);
2697
2697
  }
2698
2698
  async deleteThread(t) {
2699
2699
  const n = await Jt(`/threads/${t}`);
2700
- return ke(n);
2700
+ return we(n);
2701
2701
  }
2702
2702
  async shareThread(t, n) {
2703
2703
  const r = await ft(`/threads/${t}/share`, {
2704
2704
  shared_with_user_id: n
2705
2705
  });
2706
- return ke(r);
2706
+ return we(r);
2707
2707
  }
2708
2708
  async threadInfo(t) {
2709
- const n = await Ie(`/threads/${t}/info`);
2710
- return ke(n);
2709
+ const n = await ve(`/threads/${t}/info`);
2710
+ return we(n);
2711
2711
  }
2712
2712
  // ---- Agents ----
2713
2713
  async listAgents() {
2714
- const t = await Ie("/agents"), n = ke(t);
2714
+ const t = await ve("/agents"), n = we(t);
2715
2715
  return (n == null ? void 0 : n.items) ?? [];
2716
2716
  }
2717
2717
  async getAgent(t) {
2718
- const n = await Ie(`/agents/${t}`);
2719
- return ke(n);
2718
+ const n = await ve(`/agents/${t}`);
2719
+ return we(n);
2720
2720
  }
2721
2721
  async getAgentSchema(t) {
2722
- const n = await Ie(`/agents/${t}/schema`);
2723
- return ke(n);
2722
+ const n = await ve(`/agents/${t}/schema`);
2723
+ return we(n);
2724
2724
  }
2725
2725
  async getState(t) {
2726
- const n = await Ie(`/threads/${t.threadId}/state`, {
2726
+ const n = await ve(`/threads/${t.threadId}/state`, {
2727
2727
  params: {
2728
2728
  checkpoint_id: t.checkpointId,
2729
2729
  checkpoint_ns: t.checkpointNs
2730
2730
  }
2731
2731
  });
2732
- return ke(n);
2732
+ return we(n);
2733
2733
  }
2734
2734
  async getStateHistory(t) {
2735
- const n = await Ie(`/threads/${t.threadId}/state`, {
2735
+ const n = await ve(`/threads/${t.threadId}/state/history`, {
2736
2736
  params: {
2737
2737
  checkpoint_id: t.checkpointId,
2738
- checkpoint_ns: t.checkpointNs
2738
+ checkpoint_ns: t.checkpointNs,
2739
+ limit: t.limit ?? 100,
2740
+ offset: t.offset ?? 0,
2741
+ include_messages: t.includeMessages ?? !0
2739
2742
  },
2740
- timeout: Fr(),
2743
+ timeout: Ur(),
2741
2744
  signal: t.signal
2742
- }), r = ke(n);
2743
- return r && "checkpoints" in r ? r : {
2744
- version: "values@1",
2745
- threadId: t.threadId,
2746
- checkpoints: r ? [r] : []
2747
- };
2745
+ });
2746
+ return we(n);
2748
2747
  }
2749
2748
  // ---- Run Management ----
2750
2749
  async cancelRun(t) {
2751
2750
  const n = await ft("/stream/cancel", { threadId: t });
2752
- return ke(n);
2751
+ return we(n);
2753
2752
  }
2754
2753
  async unshareThread(t, n) {
2755
2754
  const r = await Jt(`/threads/${t}/share/${n}`);
2756
- return ke(r);
2755
+ return we(r);
2757
2756
  }
2758
2757
  }
2759
- const yn = new Or();
2760
- class $r {
2758
+ const hn = new jr();
2759
+ class Or {
2761
2760
  // Config logic could go here if files ever need a distinct base URL from chat
2762
2761
  // For now, it shares the chatBaseUrl via the shared httpClient
2763
2762
  async fetchFileBlob(t, n) {
2764
- return await Ie(t, {
2763
+ return await ve(t, {
2765
2764
  responseType: "blob",
2766
2765
  onDownloadProgress: (s) => {
2767
2766
  try {
@@ -2790,7 +2789,7 @@ class $r {
2790
2789
  const r = await this.fetchFileBlob(`/files/${t}/download`, n), s = URL.createObjectURL(r);
2791
2790
  let o = `file_${t}`;
2792
2791
  try {
2793
- const i = await Ie(`/files/${t}`);
2792
+ const i = await ve(`/files/${t}`);
2794
2793
  o = (i == null ? void 0 : i.filename) ?? o;
2795
2794
  } catch {
2796
2795
  }
@@ -2798,11 +2797,11 @@ class $r {
2798
2797
  a.href = s, a.download = o, document.body.appendChild(a), a.click(), a.remove(), setTimeout(() => URL.revokeObjectURL(s), 6e4);
2799
2798
  }
2800
2799
  async getFileInfo(t) {
2801
- return await Ie(`/files/${t}`);
2800
+ return await ve(`/files/${t}`);
2802
2801
  }
2803
2802
  async listFiles(t, n = 50, r = 0) {
2804
2803
  const s = { limit: n, offset: r };
2805
- return t && (s.thread_id = t), await Ie("/files", { params: s });
2804
+ return t && (s.thread_id = t), await ve("/files", { params: s });
2806
2805
  }
2807
2806
  async uploadFile(t, n, r) {
2808
2807
  const s = new FormData();
@@ -2819,8 +2818,8 @@ class $r {
2819
2818
  });
2820
2819
  }
2821
2820
  }
2822
- const bn = new $r();
2823
- class Br {
2821
+ const yn = new Or();
2822
+ class $r {
2824
2823
  constructor() {
2825
2824
  // ---- Configuration ----
2826
2825
  Bt(this, "_authBaseUrl", "");
@@ -2839,23 +2838,23 @@ class Br {
2839
2838
  }
2840
2839
  // ---- Token Management ----
2841
2840
  getAuthToken() {
2842
- return gn();
2841
+ return pn();
2843
2842
  }
2844
2843
  setAuthToken(t) {
2845
2844
  Ve(t);
2846
2845
  }
2847
2846
  onTokenChange(t) {
2848
- return mn(t);
2847
+ return gn(t);
2849
2848
  }
2850
2849
  // ---- User Management ----
2851
2850
  async listUsers() {
2852
- const t = await Ie("/users", { baseURL: this.baseUrl });
2851
+ const t = await ve("/users", { baseURL: this.baseUrl });
2853
2852
  return (t == null ? void 0 : t.users) ?? [];
2854
2853
  }
2855
2854
  }
2856
- const Dr = new Br(), wn = Ge(null);
2857
- function Vr({ children: e, apiConfig: t }) {
2858
- const n = yn, r = Dr;
2855
+ const Br = new $r(), bn = Ge(null);
2856
+ function Dr({ children: e, apiConfig: t }) {
2857
+ const n = hn, r = Br;
2859
2858
  if (t) {
2860
2859
  const o = n.baseUrl, a = r.baseUrl, i = n.getAuthToken(), f = t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0;
2861
2860
  (t.baseUrl || t.chatBaseUrl || f) && (f || t.chatBaseUrl && t.chatBaseUrl !== o || t.baseUrl && !o.startsWith(t.baseUrl)) && n.updateConfig(t), (t.baseUrl || t.authBaseUrl) && (t.authBaseUrl && t.authBaseUrl !== a || t.baseUrl && !a.startsWith(t.baseUrl)) && r.updateConfig(t), t.apiKey !== void 0 && t.apiKey !== i && (n.updateConfig({ apiKey: t.apiKey }), r.updateConfig({ apiKey: t.apiKey }));
@@ -2867,12 +2866,12 @@ function Vr({ children: e, apiConfig: t }) {
2867
2866
  },
2868
2867
  chatApi: n,
2869
2868
  authApi: r,
2870
- fileApi: bn,
2869
+ fileApi: yn,
2871
2870
  baseUrl: n.baseUrl
2872
2871
  };
2873
- return /* @__PURE__ */ Me(wn.Provider, { value: s, children: e });
2872
+ return /* @__PURE__ */ Ce(bn.Provider, { value: s, children: e });
2874
2873
  }
2875
- async function Kr(e) {
2874
+ async function Vr(e) {
2876
2875
  return await new Promise((t, n) => {
2877
2876
  const r = new FileReader();
2878
2877
  r.onload = () => {
@@ -2888,11 +2887,11 @@ async function Kr(e) {
2888
2887
  }, r.onerror = (s) => n(s), r.readAsArrayBuffer(e);
2889
2888
  });
2890
2889
  }
2891
- async function Hr(e = []) {
2890
+ async function Kr(e = []) {
2892
2891
  const t = [], n = [];
2893
2892
  for (const r of e)
2894
2893
  try {
2895
- const s = await Kr(r), o = r.type || "application/octet-stream";
2894
+ const s = await Vr(r), o = r.type || "application/octet-stream";
2896
2895
  n.push({
2897
2896
  filename: r.name,
2898
2897
  data: s,
@@ -2911,28 +2910,28 @@ async function Hr(e = []) {
2911
2910
  }
2912
2911
  return { contentParts: t, filesInfo: n };
2913
2912
  }
2914
- function qr(e) {
2913
+ function Hr(e) {
2915
2914
  return e.filter((t) => t.type === "text").map((t) => t.text).join("");
2916
2915
  }
2917
- function Gs(e) {
2916
+ function Ws(e) {
2918
2917
  if (e == null) return null;
2919
2918
  const t = String(e).trim();
2920
2919
  return t.length > 0 ? t : null;
2921
2920
  }
2922
- function Wr(e) {
2921
+ function qr(e) {
2923
2922
  const t = e.toolCallId ?? (e.role === "tool" ? e.id : void 0);
2924
2923
  return e.role === "tool" && !t && console.error("[meta-utils] CRITICAL: Tool message missing toolCallId!", e), {
2925
2924
  toolCallId: t ?? void 0,
2926
2925
  name: e.name ?? void 0
2927
2926
  };
2928
2927
  }
2929
- function Js(e) {
2928
+ function Gs(e) {
2930
2929
  var n;
2931
2930
  if (e.name && e.name.trim()) return e.name;
2932
2931
  const t = (n = e.additionalKwargs) == null ? void 0 : n.agentName;
2933
2932
  return typeof t == "string" && t.trim() ? t : e.model && e.model.includes("/") ? e.model.split("/").pop() || null : e.model || null;
2934
2933
  }
2935
- function Xs(e) {
2934
+ function Js(e) {
2936
2935
  const t = e.updatedAt ?? e.createdAt ?? "", n = Array.isArray(e.content) ? e.content.map((a) => {
2937
2936
  switch (a.type) {
2938
2937
  case "text":
@@ -2946,11 +2945,11 @@ function Xs(e) {
2946
2945
  return `${e.id}:${t}:${n}${o ? `:${o}` : ""}`;
2947
2946
  }
2948
2947
  function We() {
2949
- const e = at(wn);
2948
+ const e = at(bn);
2950
2949
  if (!e) throw new Error("useApi must be used within ApiProvider");
2951
2950
  return e;
2952
2951
  }
2953
- function Gr(e, t, n) {
2952
+ function Wr(e, t, n) {
2954
2953
  const r = typeof t == "string" ? [{ type: "text", text: t }] : t;
2955
2954
  return {
2956
2955
  id: `msg-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`,
@@ -2960,8 +2959,8 @@ function Gr(e, t, n) {
2960
2959
  ...n
2961
2960
  };
2962
2961
  }
2963
- function kn(e, t = "user") {
2964
- return typeof e == "string" ? Gr(t, e) : e;
2962
+ function wn(e, t = "user") {
2963
+ return typeof e == "string" ? Wr(t, e) : e;
2965
2964
  }
2966
2965
  function rt(e) {
2967
2966
  if (!(!e || typeof e != "object" || Array.isArray(e)))
@@ -2975,7 +2974,7 @@ function dt(e, t) {
2975
2974
  return r.trim();
2976
2975
  }
2977
2976
  }
2978
- function Jr(e, t) {
2977
+ function Gr(e, t) {
2979
2978
  if (!e) return null;
2980
2979
  for (const n of t) {
2981
2980
  const r = e[n];
@@ -2992,7 +2991,7 @@ function Xt(e) {
2992
2991
  async function Et(e, t) {
2993
2992
  var i, f;
2994
2993
  if (!e) return e ?? null;
2995
- const n = Pe(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], s = /* @__PURE__ */ new Set();
2994
+ const n = Ee(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], s = /* @__PURE__ */ new Set();
2996
2995
  for (const l of r) {
2997
2996
  const c = (i = l == null ? void 0 : l.values) == null ? void 0 : i.messages;
2998
2997
  if (Array.isArray(c))
@@ -3011,7 +3010,7 @@ async function Et(e, t) {
3011
3010
  const o = await Promise.all(
3012
3011
  Array.from(s).map(async (l) => {
3013
3012
  try {
3014
- const c = await t.getFileInfo(l), d = Pe(c);
3013
+ const c = await t.getFileInfo(l), d = Ee(c);
3015
3014
  return [l, d];
3016
3015
  } catch {
3017
3016
  return [l, null];
@@ -3036,7 +3035,7 @@ async function Et(e, t) {
3036
3035
  return n;
3037
3036
  }
3038
3037
  function tt(e) {
3039
- const r = [...(Array.isArray(e == null ? void 0 : e.checkpoints) ? (e == null ? void 0 : e.checkpoints) ?? [] : e != null && e.checkpoints ? Object.values(e.checkpoints) : []).map((o, a) => Xr(Pe(o), a)).filter((o) => !!o)].sort((o, a) => Qt(a.createdAt) - Qt(o.createdAt)), s = r[0] ?? null;
3038
+ const r = [...(Array.isArray(e == null ? void 0 : e.checkpoints) ? (e == null ? void 0 : e.checkpoints) ?? [] : e != null && e.checkpoints ? Object.values(e.checkpoints) : []).map((o, a) => Jr(Ee(o), a)).filter((o) => !!o)].sort((o, a) => Qt(a.createdAt) - Qt(o.createdAt)), s = r[0] ?? null;
3040
3039
  return {
3041
3040
  threadId: (e == null ? void 0 : e.threadId) ?? "",
3042
3041
  latest: s,
@@ -3044,12 +3043,12 @@ function tt(e) {
3044
3043
  interrupt: (s == null ? void 0 : s.interrupt) ?? null
3045
3044
  };
3046
3045
  }
3047
- function Xr(e, t) {
3046
+ function Jr(e, t) {
3048
3047
  var _, k;
3049
3048
  if (!e) return null;
3050
- const n = ((_ = e.values) == null ? void 0 : _.activeAgent) ?? null, r = (k = e.values) == null ? void 0 : k.messages, o = (Array.isArray(r) ? r : []).map((T) => Qr(T, n)).filter((T) => !!T), a = rt(e.metadata) ?? {}, i = Xt(e.config), f = rt(e.parentConfig), l = Xt(f), c = dt(i, ["checkpointId"]), d = dt(i, ["checkpointNs"]), g = dt(l, ["checkpointId"]), h = rt(e.config), v = Array.isArray(e.tasks) ? e.tasks.map((T) => ({ ...T })) : e.tasks ?? null, m = Array.isArray(e.next) ? [...e.next] : e.next ?? null, y = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), I = {
3049
+ const n = ((_ = e.values) == null ? void 0 : _.activeAgent) ?? null, r = (k = e.values) == null ? void 0 : k.messages, o = (Array.isArray(r) ? r : []).map((T) => Xr(T, n)).filter((T) => !!T), a = rt(e.metadata) ?? {}, i = Xt(e.config), f = rt(e.parentConfig), l = Xt(f), c = dt(i, ["checkpointId"]), d = dt(i, ["checkpointNs"]), g = dt(l, ["checkpointId"]), h = rt(e.config), v = Array.isArray(e.tasks) ? e.tasks.map((T) => ({ ...T })) : e.tasks ?? null, m = Array.isArray(e.next) ? [...e.next] : e.next ?? null, y = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), I = {
3051
3050
  ...a,
3052
- step: Jr(a, ["step"]) ?? 0,
3051
+ step: Gr(a, ["step"]) ?? 0,
3053
3052
  source: dt(a, ["source"]) ?? null
3054
3053
  }, A = o.map((T) => ({
3055
3054
  ...T,
@@ -3062,7 +3061,7 @@ function Xr(e, t) {
3062
3061
  createdAt: y,
3063
3062
  parentId: g ?? null,
3064
3063
  messages: A,
3065
- interrupt: Yr(
3064
+ interrupt: Qr(
3066
3065
  N,
3067
3066
  t,
3068
3067
  c ?? null
@@ -3075,11 +3074,11 @@ function Xr(e, t) {
3075
3074
  values: e.values ?? {}
3076
3075
  };
3077
3076
  }
3078
- function Qr(e, t) {
3077
+ function Xr(e, t) {
3079
3078
  const n = bt(e);
3080
3079
  return n ? (n.role === "assistant" && !n.name && t && (n.name = t), n) : null;
3081
3080
  }
3082
- function Yr(e, t, n) {
3081
+ function Qr(e, t, n) {
3083
3082
  const r = e.length;
3084
3083
  for (let s = r - 1; s >= 0; s -= 1) {
3085
3084
  const o = e[s];
@@ -3100,16 +3099,16 @@ function Qt(e) {
3100
3099
  const t = Date.parse(e);
3101
3100
  return Number.isFinite(t) ? t : 0;
3102
3101
  }
3103
- function Zr(e) {
3102
+ function Yr(e) {
3104
3103
  return !!e && typeof e == "object" && "data" in e;
3105
3104
  }
3106
- function es(e = {}) {
3105
+ function Zr(e = {}) {
3107
3106
  const t = e.baseUrl || "", n = e.streamPath ?? "/stream", [r, s] = H(e.token ?? null), o = K(e.headers ?? {}), a = e.credentials ?? "include", i = K(e);
3108
- oe(() => {
3107
+ ae(() => {
3109
3108
  i.current = e;
3110
3109
  }, [e]);
3111
3110
  const f = E((p) => {
3112
- var U, q, B, ee, Q, re, W, se, ge, be;
3111
+ var U, q, B, re, X, se, G, oe, pe, ee;
3113
3112
  const b = i.current;
3114
3113
  if (!b) return;
3115
3114
  if (p.type === "thread_info") {
@@ -3125,18 +3124,18 @@ function es(e = {}) {
3125
3124
  return;
3126
3125
  }
3127
3126
  if (typeof p.type == "string" && (p.type === "custom" || p.type.startsWith("custom."))) {
3128
- (ee = b.onCustomEvent) == null || ee.call(b, p);
3127
+ (re = b.onCustomEvent) == null || re.call(b, p);
3129
3128
  return;
3130
3129
  }
3131
- (Q = b.onEvent) == null || Q.call(b, p), p.type === "updates" && ((re = b.onUpdateEvent) == null || re.call(b, p)), p.type === "tool.end" ? (W = b.onToolEnd) == null || W.call(b, p) : p.type === "tool.start" && ((se = b.onToolStart) == null || se.call(b, p)), p.type === "heartbeat" && ((ge = b.onHeartbeat) == null || ge.call(b, p)), p.type === "token" && ((be = b.onToken) == null || be.call(b, p.token));
3132
- }, []), [l, c] = H(!1), [d, g] = H(null), [h, v] = H(""), [m, y] = H(null), [I, A] = H(0), [x, N] = H(!1), [_, k] = H({}), [T, L] = H(null), [j, O] = H({}), $ = K(null), C = K(!0), J = K(0), G = K(null), X = K(null), te = K(null), ne = K(null), S = K([]), P = K(/* @__PURE__ */ new Set()), D = K({
3130
+ (X = b.onEvent) == null || X.call(b, p), p.type === "updates" && ((se = b.onUpdateEvent) == null || se.call(b, p)), p.type === "tool.end" ? (G = b.onToolEnd) == null || G.call(b, p) : p.type === "tool.start" && ((oe = b.onToolStart) == null || oe.call(b, p)), p.type === "heartbeat" && ((pe = b.onHeartbeat) == null || pe.call(b, p)), p.type === "token" && ((ee = b.onToken) == null || ee.call(b, p.token));
3131
+ }, []), [l, c] = H(!1), [d, g] = H(null), [h, v] = H(""), [m, y] = H(null), [I, A] = H(0), [x, N] = H(!1), [_, k] = H({}), [T, L] = H(null), [j, O] = H({}), $ = K(null), C = K(!0), J = K(0), W = K(null), Q = K(null), te = K(null), ne = K(null), S = K([]), P = K(/* @__PURE__ */ new Set()), D = K({
3133
3132
  messageId: null,
3134
3133
  lastSeq: null,
3135
3134
  lastText: ""
3136
3135
  }), V = E((p) => {
3137
3136
  s(p);
3138
3137
  }, []), u = E(() => {
3139
- v(""), y(null), g(null), X.current = null, te.current = null, ne.current = null, S.current = [], P.current = /* @__PURE__ */ new Set(), k({}), L(null), O({}), D.current = {
3138
+ v(""), y(null), g(null), Q.current = null, te.current = null, ne.current = null, S.current = [], P.current = /* @__PURE__ */ new Set(), k({}), L(null), O({}), D.current = {
3140
3139
  messageId: null,
3141
3140
  lastSeq: null,
3142
3141
  lastText: ""
@@ -3144,11 +3143,11 @@ function es(e = {}) {
3144
3143
  }, []), R = E(() => {
3145
3144
  var U;
3146
3145
  console.debug("[use-chat] stop() invoked - aborting stream");
3147
- const p = (U = G.current) == null ? void 0 : U.threadId, b = () => {
3146
+ const p = (U = W.current) == null ? void 0 : U.threadId, b = () => {
3148
3147
  var q;
3149
- (q = $.current) == null || q.abort(), $.current = null, G.current = null, c(!1), N(!1), J.current = 0, A(0);
3148
+ (q = $.current) == null || q.abort(), $.current = null, W.current = null, c(!1), N(!1), J.current = 0, A(0);
3150
3149
  };
3151
- (p ? yn.cancelRun(p).catch((q) => {
3150
+ (p ? hn.cancelRun(p).catch((q) => {
3152
3151
  console.warn("[use-chat] cancel run failed:", q);
3153
3152
  }) : Promise.resolve()).finally(b);
3154
3153
  }, []), M = E(
@@ -3165,7 +3164,7 @@ function es(e = {}) {
3165
3164
  edit: p.edit,
3166
3165
  command: p.command
3167
3166
  };
3168
- c(!0), g(null), v(""), y(null), X.current = null, te.current = null, ne.current = null, S.current = [], P.current = /* @__PURE__ */ new Set(), k({}), L(null), O({}), D.current = {
3167
+ c(!0), g(null), v(""), y(null), Q.current = null, te.current = null, ne.current = null, S.current = [], P.current = /* @__PURE__ */ new Set(), k({}), L(null), O({}), D.current = {
3169
3168
  messageId: null,
3170
3169
  lastSeq: null,
3171
3170
  lastText: ""
@@ -3173,312 +3172,312 @@ function es(e = {}) {
3173
3172
  const z = new AbortController();
3174
3173
  $.current = z;
3175
3174
  let U = null, q = !1;
3176
- const B = (ee) => {
3177
- if (P.current.has(ee)) return;
3178
- const Q = S.current[0];
3179
- Q && k((re) => {
3180
- let W = T;
3181
- if (!W) {
3182
- const de = Object.values(re).filter((je) => je.role === "assistant");
3183
- de.length > 0 && (W = de[de.length - 1].id);
3175
+ const B = (re) => {
3176
+ if (P.current.has(re)) return;
3177
+ const X = S.current[0];
3178
+ X && k((se) => {
3179
+ let G = T;
3180
+ if (!G) {
3181
+ const ge = Object.values(se).filter((je) => je.role === "assistant");
3182
+ ge.length > 0 && (G = ge[ge.length - 1].id);
3184
3183
  }
3185
- if (!W || !re[W]) return re;
3186
- const se = re[W], ge = [...se.toolCalls || []], be = Q.id ?? `task-${ee}`;
3187
- return ge.some((de) => de.id === be && de.name === "task" && de.scope === ee) || ge.push({
3188
- id: be,
3184
+ if (!G || !se[G]) return se;
3185
+ const oe = se[G], pe = [...oe.toolCalls || []], ee = X.id ?? `task-${re}`;
3186
+ return pe.some((ge) => ge.id === ee && ge.name === "task" && ge.scope === re) || pe.push({
3187
+ id: ee,
3189
3188
  name: "task",
3190
3189
  args: {
3191
- description: Q.description,
3192
- subagentType: Q.subagentType
3190
+ description: X.description,
3191
+ subagentType: X.subagentType
3193
3192
  },
3194
3193
  status: "running",
3195
- content: Q.description,
3196
- scope: ee
3197
- }), P.current.add(ee), S.current.shift(), { ...re, [W]: { ...se, toolCalls: ge } };
3194
+ content: X.description,
3195
+ scope: re
3196
+ }), P.current.add(re), S.current.shift(), { ...se, [G]: { ...oe, toolCalls: pe } };
3198
3197
  });
3199
3198
  };
3200
- return G.current = {
3199
+ return W.current = {
3201
3200
  threadId: b.threadId ?? null,
3202
3201
  headers: {},
3203
3202
  isStreaming: !0
3204
3203
  }, (async () => {
3205
- var ee, Q, re, W, se, ge, be, ue, de, je, Oe, Xe;
3204
+ var re, X, se, G, oe, pe, ee, Fe, ge, je, Oe, Xe;
3206
3205
  try {
3207
- let Ae = {};
3206
+ let Te = {};
3208
3207
  try {
3209
3208
  if (r)
3210
- Ae = { Authorization: `Bearer ${r}` };
3209
+ Te = { Authorization: `Bearer ${r}` };
3211
3210
  else if (typeof window < "u") {
3212
- const xe = window.__AUTH_TOKEN__, Tt = ((ee = window.localStorage) == null ? void 0 : ee.getItem(nt.authToken)) || null;
3211
+ const Se = window.__AUTH_TOKEN__, Tt = ((re = window.localStorage) == null ? void 0 : re.getItem(nt.authToken)) || null;
3213
3212
  let lt = null;
3214
3213
  try {
3215
- const ut = (Q = window.localStorage) == null ? void 0 : Q.getItem(nt.chatSettings);
3216
- ut && (lt = ((re = JSON.parse(ut)) == null ? void 0 : re.apiKey) || null);
3214
+ const ut = (X = window.localStorage) == null ? void 0 : X.getItem(nt.chatSettings);
3215
+ ut && (lt = ((se = JSON.parse(ut)) == null ? void 0 : se.apiKey) || null);
3217
3216
  } catch {
3218
3217
  }
3219
- const He = xe || Tt || lt || null;
3220
- He && (Ae = { Authorization: `Bearer ${He}` });
3218
+ const He = Se || Tt || lt || null;
3219
+ He && (Te = { Authorization: `Bearer ${He}` });
3221
3220
  }
3222
3221
  } catch {
3223
3222
  }
3224
3223
  console.debug("[use-chat] POST", t + n);
3225
- let Se = {};
3224
+ let Ae = {};
3226
3225
  if (typeof window < "u")
3227
3226
  try {
3228
- const fe = (W = window.localStorage) == null ? void 0 : W.getItem(nt.authSessionId);
3229
- fe && (Se = { "X-Session-Id": fe });
3227
+ const de = (G = window.localStorage) == null ? void 0 : G.getItem(nt.authSessionId);
3228
+ de && (Ae = { "X-Session-Id": de });
3230
3229
  } catch {
3231
3230
  }
3232
3231
  const Ke = {
3232
+ ...Te,
3233
3233
  ...Ae,
3234
- ...Se,
3235
3234
  ...o.current
3236
3235
  }, vt = {
3237
3236
  "Content-Type": "application/json",
3238
3237
  Accept: "text/event-stream",
3239
3238
  ...Ke
3240
- }, Te = await fetch(t + n, {
3239
+ }, Ie = await fetch(t + n, {
3241
3240
  method: "POST",
3242
3241
  headers: vt,
3243
3242
  body: JSON.stringify(b),
3244
3243
  signal: z.signal,
3245
3244
  credentials: a
3246
3245
  });
3247
- if (G.current && (G.current.headers = Ke), !Te.ok || !Te.body) {
3248
- const fe = await Te.text().catch(() => "");
3246
+ if (W.current && (W.current.headers = Ke), !Ie.ok || !Ie.body) {
3247
+ const de = await Ie.text().catch(() => "");
3249
3248
  console.debug(
3250
3249
  "[use-chat] non-OK response",
3251
- Te.status,
3252
- fe == null ? void 0 : fe.slice(0, 500)
3250
+ Ie.status,
3251
+ de == null ? void 0 : de.slice(0, 500)
3253
3252
  );
3254
- const xe = `stream ${Te.status}${fe ? ": " + fe : ""}`;
3255
- throw xe && (g(xe), U = "error"), new Error(xe);
3253
+ const Se = `stream ${Ie.status}${de ? ": " + de : ""}`;
3254
+ throw Se && (g(Se), U = "error"), new Error(Se);
3256
3255
  }
3257
3256
  N(!0);
3258
- const Qe = Te.body.getReader(), En = new TextDecoder();
3257
+ const Qe = Ie.body.getReader(), Mn = new TextDecoder();
3259
3258
  let $e = "", ct = [];
3260
3259
  J.current = 0, A(0);
3261
3260
  let Ye = 0, Be = null;
3262
3261
  const It = () => {
3263
3262
  if (ct.length) {
3264
- const fe = ct.join("");
3265
- ct = [], C.current && v((xe) => xe + fe);
3263
+ const de = ct.join("");
3264
+ ct = [], C.current && v((Se) => Se + de);
3266
3265
  }
3267
3266
  Be = null;
3268
- }, Pn = () => {
3267
+ }, En = () => {
3269
3268
  typeof window < "u" && Be == null && (Be = requestAnimationFrame(It));
3270
3269
  };
3271
3270
  let jt = Date.now();
3272
- const Rn = setInterval(() => {
3271
+ const Pn = setInterval(() => {
3273
3272
  Date.now() - jt > 18e5 && (g("Stream idle timeout"), U = "error", z.abort());
3274
- }, 5e3), Nn = 1024 * 1024;
3273
+ }, 5e3), Rn = 1024 * 1024;
3275
3274
  try {
3276
- const xe = (Te.headers.get("X-Thread-Id") || Te.headers.get("x-thread-id")) ?? null;
3277
- for (G.current && !G.current.threadId && (G.current = {
3278
- ...G.current,
3279
- threadId: xe
3275
+ const Se = (Ie.headers.get("X-Thread-Id") || Ie.headers.get("x-thread-id")) ?? null;
3276
+ for (W.current && !W.current.threadId && (W.current = {
3277
+ ...W.current,
3278
+ threadId: Se
3280
3279
  }); ; ) {
3281
3280
  const { value: Tt, done: lt } = await Qe.read();
3282
3281
  if (lt) break;
3283
- $e += En.decode(Tt, { stream: !0 }), $e.length > Nn && ($e = "", console.warn("Stream buffer reset: exceeded 1MB"));
3282
+ $e += Mn.decode(Tt, { stream: !0 }), $e.length > Rn && ($e = "", console.warn("Stream buffer reset: exceeded 1MB"));
3284
3283
  let He;
3285
3284
  for (; (He = $e.indexOf(`
3286
3285
 
3287
3286
  `)) >= 0; ) {
3288
3287
  const ut = $e.slice(0, He);
3289
3288
  $e = $e.slice(He + 2);
3290
- const _n = ut.split(/\r?\n/), Ot = [];
3289
+ const Nn = ut.split(/\r?\n/), Ot = [];
3291
3290
  let At = null;
3292
- for (const w of _n) {
3291
+ for (const w of Nn) {
3293
3292
  if (w.startsWith(":")) {
3294
3293
  w.startsWith(": heartbeat") && console.debug("[use-chat] SSE heartbeat comment received");
3295
3294
  continue;
3296
3295
  }
3297
3296
  if (w) {
3298
3297
  if (w.startsWith("event:")) {
3299
- const ce = w.slice(6).trim();
3300
- ce && (At = ce);
3298
+ const le = w.slice(6).trim();
3299
+ le && (At = le);
3301
3300
  continue;
3302
3301
  }
3303
3302
  if (w.startsWith("data:")) {
3304
- const ce = w.slice(5);
3305
- Ot.push(ce.startsWith(" ") ? ce.slice(1) : ce);
3303
+ const le = w.slice(5);
3304
+ Ot.push(le.startsWith(" ") ? le.slice(1) : le);
3306
3305
  }
3307
3306
  }
3308
3307
  }
3309
3308
  const St = Ot.join(`
3310
3309
  `);
3311
3310
  if (!St) continue;
3312
- let Re;
3311
+ let Pe;
3313
3312
  try {
3314
- Re = JSON.parse(St);
3313
+ Pe = JSON.parse(St);
3315
3314
  } catch {
3316
3315
  console.debug("[use-chat] malformed SSE:", St.slice(0, 200));
3317
3316
  continue;
3318
3317
  }
3319
- At && typeof Re == "object" && Re !== null && !("type" in Re) && (Re.type = At);
3320
- const $t = Zr(Re) ? Re.data : Re;
3318
+ At && typeof Pe == "object" && Pe !== null && !("type" in Pe) && (Pe.type = At);
3319
+ const $t = Yr(Pe) ? Pe.data : Pe;
3321
3320
  if (!$t) {
3322
- console.warn("[use-chat] dropped envelope event without payload", Re);
3321
+ console.warn("[use-chat] dropped envelope event without payload", Pe);
3323
3322
  continue;
3324
3323
  }
3325
- const ae = Er($t);
3324
+ const ie = Mr($t);
3326
3325
  jt = Date.now();
3327
- const De = ae.seq;
3326
+ const De = ie.seq;
3328
3327
  if (De !== void 0) {
3329
3328
  if (De <= Ye) {
3330
- console.debug("[use-chat] drop duplicate/out-of-order event", { seq: De, lastProcessedSeq: Ye, type: ae.type });
3329
+ console.debug("[use-chat] drop duplicate/out-of-order event", { seq: De, lastProcessedSeq: Ye, type: ie.type });
3331
3330
  continue;
3332
3331
  }
3333
3332
  Ye > 0 && De > Ye + 1, Ye = De, J.current = De, A(De);
3334
3333
  }
3335
- const Ln = ["messages/partial", "metadata", "checkpoint", "values", "heartbeat", "token", "status", "error", "interrupt", "tool.start", "tool.progress", "tool.end", "task.start"];
3336
- let ve = ae.type || "unknown";
3337
- if (Ln.includes(ve) || (ae.messages || ae.content !== void 0 && ae.id) && (ve = "messages/partial"), ve === "checkpoint") {
3338
- const w = ae;
3339
- X.current = w.checkpointId ?? null, te.current = w.checkpointNs ?? null, y(w.checkpointId ?? null);
3340
- } else if (ve === "values") {
3341
- const w = ae, ce = w == null ? void 0 : w.origin, ie = w == null ? void 0 : w.scope;
3342
- ce === "task" && typeof ie == "string" && ie.startsWith("tools:") && B(ie);
3343
- const me = ce === "task" || typeof ie == "string" && ie.startsWith("tools:");
3334
+ const _n = ["messages/partial", "metadata", "checkpoint", "values", "heartbeat", "token", "status", "error", "interrupt", "tool.start", "tool.progress", "tool.end", "task.start"];
3335
+ let ke = ie.type || "unknown";
3336
+ if (_n.includes(ke) || (ie.messages || ie.content !== void 0 && ie.id) && (ke = "messages/partial"), ke === "checkpoint") {
3337
+ const w = ie;
3338
+ Q.current = w.checkpointId ?? null, te.current = w.checkpointNs ?? null, y(w.checkpointId ?? null);
3339
+ } else if (ke === "values") {
3340
+ const w = ie, le = w == null ? void 0 : w.origin, ce = w == null ? void 0 : w.scope;
3341
+ le === "task" && typeof ce == "string" && ce.startsWith("tools:") && B(ce);
3342
+ const me = le === "task" || typeof ce == "string" && ce.startsWith("tools:");
3344
3343
  if (Array.isArray(w.checkpoints)) {
3345
3344
  ne.current = w;
3346
3345
  try {
3347
- const le = tt(w).latest;
3348
- le && (X.current = le.checkpointId ?? null, te.current = le.checkpointNs ?? null, y(le.checkpointId ?? null), me || O(le.values ?? {})), me || (k({}), L(null));
3346
+ const ue = tt(w).latest;
3347
+ ue && (Q.current = ue.checkpointId ?? null, te.current = ue.checkpointNs ?? null, y(ue.checkpointId ?? null), me || O(ue.values ?? {})), me || (k({}), L(null));
3349
3348
  } catch (Y) {
3350
3349
  console.warn("[use-chat] Failed to hydrate values payload", Y);
3351
3350
  }
3352
- } else if ((se = w.values) != null && se.messages)
3351
+ } else if ((oe = w.values) != null && oe.messages)
3353
3352
  me || (k({}), L(null)), me || O(w.values ?? {});
3354
3353
  else {
3355
3354
  const Y = w.values && typeof w.values == "object" ? w.values : w;
3356
3355
  me || O(Y ?? {});
3357
3356
  }
3358
3357
  }
3359
- if (ve === "task.start") {
3360
- const w = ae;
3358
+ if (ke === "task.start") {
3359
+ const w = ie;
3361
3360
  S.current.push({
3362
3361
  id: w.id ?? w.callId,
3363
3362
  description: w.description,
3364
3363
  subagentType: w.subagentType ?? w.subagent_type
3365
3364
  });
3366
3365
  }
3367
- if (ve === "tool.start" || ve === "tool.progress" || ve === "tool.end") {
3368
- const w = ae, ce = w.id || w.callId, ie = w.scope;
3369
- w.origin === "task" && typeof ie == "string" && ie.startsWith("tools:") && B(ie), ce && k((me) => {
3366
+ if (ke === "tool.start" || ke === "tool.progress" || ke === "tool.end") {
3367
+ const w = ie, le = w.id || w.callId, ce = w.scope;
3368
+ w.origin === "task" && typeof ce == "string" && ce.startsWith("tools:") && B(ce), le && k((me) => {
3370
3369
  let Y = T;
3371
3370
  if (!Y) {
3372
- const le = Object.values(me).filter((he) => he.role === "assistant");
3373
- le.length > 0 && (Y = le[le.length - 1].id);
3371
+ const ue = Object.values(me).filter((he) => he.role === "assistant");
3372
+ ue.length > 0 && (Y = ue[ue.length - 1].id);
3374
3373
  }
3375
3374
  if (Y && me[Y]) {
3376
- const le = me[Y], he = [...le.toolCalls || []], Ce = he.findIndex((Ne) => Ne.id === ce);
3377
- let we = w.content || w.status || "Processing...";
3378
- return ae.type === "tool.start" ? we = `Starting ${w.name || w.tool || "tool"}...` : ae.type === "tool.end" && w.error && (we = `Error: ${w.error}`), Ce >= 0 ? he[Ce] = {
3379
- ...he[Ce],
3380
- content: we,
3381
- status: ae.type === "tool.start" ? "running" : ae.type === "tool.end" ? w.error ? "failed" : "completed" : he[Ce].status,
3382
- artifact: w.artifact || he[Ce].artifact,
3383
- scope: ie ?? he[Ce].scope
3375
+ const ue = me[Y], he = [...ue.toolCalls || []], xe = he.findIndex((Re) => Re.id === le);
3376
+ let be = w.content || w.status || "Processing...";
3377
+ return ie.type === "tool.start" ? be = `Starting ${w.name || w.tool || "tool"}...` : ie.type === "tool.end" && w.error && (be = `Error: ${w.error}`), xe >= 0 ? he[xe] = {
3378
+ ...he[xe],
3379
+ content: be,
3380
+ status: ie.type === "tool.start" ? "running" : ie.type === "tool.end" ? w.error ? "failed" : "completed" : he[xe].status,
3381
+ artifact: w.artifact || he[xe].artifact,
3382
+ scope: ce ?? he[xe].scope
3384
3383
  } : he.push({
3385
- id: ce,
3384
+ id: le,
3386
3385
  name: w.name || w.tool || "tool",
3387
3386
  args: w.args || {},
3388
- status: ae.type === "tool.end" ? w.error ? "failed" : "completed" : "running",
3389
- content: we,
3387
+ status: ie.type === "tool.end" ? w.error ? "failed" : "completed" : "running",
3388
+ content: be,
3390
3389
  artifact: w.artifact,
3391
- scope: ie
3392
- }), { ...me, [Y]: { ...le, toolCalls: he } };
3390
+ scope: ce
3391
+ }), { ...me, [Y]: { ...ue, toolCalls: he } };
3393
3392
  }
3394
3393
  return me;
3395
3394
  });
3396
- } else if (ve === "messages/partial") {
3397
- const w = ae, ce = w.messages || [w];
3398
- if (Array.isArray(ce) && ce.length > 0) {
3399
- const ie = ce.find((Y) => Y.type === "ai"), me = ce.find((Y) => Y.type === "tool");
3400
- if (ie) {
3401
- const Y = ie.id, le = ie.content ?? "", he = !1, Ce = he ? (D.current.lastText || "") + le : le;
3395
+ } else if (ke === "messages/partial") {
3396
+ const w = ie, le = w.messages || [w];
3397
+ if (Array.isArray(le) && le.length > 0) {
3398
+ const ce = le.find((Y) => Y.type === "ai"), me = le.find((Y) => Y.type === "tool");
3399
+ if (ce) {
3400
+ const Y = ce.id, ue = ce.content ?? "", he = !1, xe = he ? (D.current.lastText || "") + ue : ue;
3402
3401
  if (D.current.messageId !== Y) {
3403
- const we = ie.name ?? ie.agentName ?? "assistant";
3402
+ const be = ce.name ?? ce.agentName ?? "assistant";
3404
3403
  D.current = {
3405
3404
  messageId: Y,
3406
3405
  lastSeq: null,
3407
3406
  lastText: ""
3408
3407
  };
3409
- const Ne = bt({
3408
+ const Re = bt({
3410
3409
  id: Y,
3411
3410
  role: "assistant",
3412
- name: we,
3413
- model: we,
3411
+ name: be,
3412
+ model: be,
3414
3413
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3415
- content: [{ type: "text", text: Ce }]
3414
+ content: [{ type: "text", text: xe }]
3416
3415
  });
3417
- k((zn) => ({ ...zn, [Y]: Ne })), L(Y), D.current.lastText = Ce;
3416
+ k((Ln) => ({ ...Ln, [Y]: Re })), L(Y), D.current.lastText = xe;
3418
3417
  } else
3419
- k((we) => {
3420
- const Ne = we[Y];
3421
- return Ne ? {
3422
- ...we,
3418
+ k((be) => {
3419
+ const Re = be[Y];
3420
+ return Re ? {
3421
+ ...be,
3423
3422
  [Y]: {
3424
- ...Ne,
3425
- content: [{ type: "text", text: Ce }],
3423
+ ...Re,
3424
+ content: [{ type: "text", text: xe }],
3426
3425
  // Preserve existing metadata if the chunk doesn't have it
3427
- responseMetadata: ie.responseMetadata ?? Ne.responseMetadata
3426
+ responseMetadata: ce.responseMetadata ?? Re.responseMetadata
3428
3427
  }
3429
- } : we;
3430
- }), D.current.lastText = Ce;
3428
+ } : be;
3429
+ }), D.current.lastText = xe;
3431
3430
  if (!he) {
3432
- const we = D.current.lastText || "";
3433
- if (le.length > we.length) {
3434
- const Ne = le.slice(we.length);
3435
- ct.push(Ne), Pn();
3431
+ const be = D.current.lastText || "";
3432
+ if (ue.length > be.length) {
3433
+ const Re = ue.slice(be.length);
3434
+ ct.push(Re), En();
3436
3435
  }
3437
3436
  }
3438
3437
  }
3439
3438
  if (me) {
3440
- const Y = me.id || `tool-${Date.now()}`, le = bt({
3439
+ const Y = me.id || `tool-${Date.now()}`, ue = bt({
3441
3440
  ...me,
3442
3441
  id: Y,
3443
3442
  role: "tool",
3444
3443
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
3445
3444
  });
3446
- k((he) => ({ ...he, [Y]: le }));
3445
+ k((he) => ({ ...he, [Y]: ue }));
3447
3446
  }
3448
3447
  }
3449
- } else if (ve === "heartbeat") {
3448
+ } else if (ke === "heartbeat") {
3450
3449
  console.debug("[use-chat] heartbeat received");
3451
3450
  try {
3452
3451
  } catch (w) {
3453
3452
  console.warn("[use-chat] heartbeat callback failed", w);
3454
3453
  }
3455
- } else if (Be !== null && cancelAnimationFrame(Be), It(), ve === "checkpoint")
3456
- y(ae.checkpointId ?? null);
3457
- else if (ve === "error") {
3458
- const w = ae;
3459
- if (g(w.message), U = "error", w.error_type === "auth_error" || w.code === "TOKEN_EXPIRED" || ((ge = w.message) == null ? void 0 : ge.includes("token")) || ((be = w.message) == null ? void 0 : be.includes("401")) || ((ue = w.message) == null ? void 0 : ue.includes("unauthorized")) || ((de = w.message) == null ? void 0 : de.includes("Unauthorized"))) {
3454
+ } else if (Be !== null && cancelAnimationFrame(Be), It(), ke === "checkpoint")
3455
+ y(ie.checkpointId ?? null);
3456
+ else if (ke === "error") {
3457
+ const w = ie;
3458
+ if (g(w.message), U = "error", w.error_type === "auth_error" || w.code === "TOKEN_EXPIRED" || ((pe = w.message) == null ? void 0 : pe.includes("token")) || ((ee = w.message) == null ? void 0 : ee.includes("401")) || ((Fe = w.message) == null ? void 0 : Fe.includes("unauthorized")) || ((ge = w.message) == null ? void 0 : ge.includes("Unauthorized"))) {
3460
3459
  console.error("[use-chat] Auth error detected:", w.message);
3461
3460
  try {
3462
3461
  (je = e.onAuthError) == null || je.call(e, w.message);
3463
- } catch (ie) {
3464
- console.warn("[use-chat] onAuthError handler failed", ie);
3462
+ } catch (ce) {
3463
+ console.warn("[use-chat] onAuthError handler failed", ce);
3465
3464
  }
3466
3465
  z.abort();
3467
3466
  }
3468
- } else if (ve === "status") {
3469
- const w = ae;
3467
+ } else if (ke === "status") {
3468
+ const w = ie;
3470
3469
  (w.status === "completed" || w.status === "interrupted" || w.status === "error") && (c(!1), console.log("[use-chat] Status event received:", w));
3471
3470
  }
3472
- f(ae);
3471
+ f(ie);
3473
3472
  }
3474
3473
  }
3475
3474
  It(), U === null && !z.signal.aborted && (U = "complete");
3476
- } catch (fe) {
3477
- if (fe.name === "AbortError")
3475
+ } catch (de) {
3476
+ if (de.name === "AbortError")
3478
3477
  U = U ?? "aborted";
3479
3478
  else {
3480
- const xe = fe.message || String(fe);
3481
- U = "error", g(xe);
3479
+ const Se = de.message || String(de);
3480
+ U = "error", g(Se);
3482
3481
  }
3483
3482
  } finally {
3484
3483
  try {
@@ -3487,37 +3486,37 @@ function es(e = {}) {
3487
3486
  } finally {
3488
3487
  (Oe = Qe.releaseLock) == null || Oe.call(Qe);
3489
3488
  }
3490
- Be !== null && typeof window < "u" && window.cancelAnimationFrame(Be), clearInterval(Rn);
3489
+ Be !== null && typeof window < "u" && window.cancelAnimationFrame(Be), clearInterval(Pn);
3491
3490
  }
3492
- } catch (Ae) {
3493
- if (Ae.name === "AbortError")
3491
+ } catch (Te) {
3492
+ if (Te.name === "AbortError")
3494
3493
  U = U ?? "aborted";
3495
3494
  else {
3496
- const Se = Ae.message || String(Ae);
3497
- U = "error", g(Se), q || (q = !0, (Xe = e.onConnectionError) == null || Xe.call(e, Se));
3495
+ const Ae = Te.message || String(Te);
3496
+ U = "error", g(Ae), q || (q = !0, (Xe = e.onConnectionError) == null || Xe.call(e, Ae));
3498
3497
  }
3499
3498
  } finally {
3500
- const Ae = J.current, Se = X.current, Ke = te.current, vt = ne.current;
3499
+ const Te = J.current, Ae = Q.current, Ke = te.current, vt = ne.current;
3501
3500
  try {
3502
3501
  if (e.onFinish) {
3503
- const Te = {
3504
- lastSeq: Ae,
3505
- lastCheckpointId: Se,
3502
+ const Ie = {
3503
+ lastSeq: Te,
3504
+ lastCheckpointId: Ae,
3506
3505
  lastCheckpointNs: Ke,
3507
3506
  lastValues: vt
3508
3507
  };
3509
- e.onFinish(Te);
3508
+ e.onFinish(Ie);
3510
3509
  }
3511
- } catch (Te) {
3512
- console.warn("[use-chat] onClosed callback failed", Te);
3510
+ } catch (Ie) {
3511
+ console.warn("[use-chat] onClosed callback failed", Ie);
3513
3512
  }
3514
- c(!1), N(!1), $.current = null, J.current = 0, A(0), G.current = null;
3513
+ c(!1), N(!1), $.current = null, J.current = 0, A(0), W.current = null;
3515
3514
  }
3516
3515
  })(), Promise.resolve();
3517
3516
  },
3518
3517
  [t, n, r, e]
3519
3518
  );
3520
- return oe(() => () => {
3519
+ return ae(() => () => {
3521
3520
  var p;
3522
3521
  C.current = !1, (p = $.current) == null || p.abort();
3523
3522
  }, []), {
@@ -3543,7 +3542,7 @@ function es(e = {}) {
3543
3542
  submit: M
3544
3543
  };
3545
3544
  }
3546
- const ts = ["detail", "message", "error", "description", "title"];
3545
+ const es = ["detail", "message", "error", "description", "title"];
3547
3546
  function pt(e) {
3548
3547
  if (!e) return null;
3549
3548
  if (typeof e == "string") {
@@ -3560,7 +3559,7 @@ function pt(e) {
3560
3559
  }
3561
3560
  if (typeof e == "object") {
3562
3561
  const t = e;
3563
- for (const n of ts) {
3562
+ for (const n of es) {
3564
3563
  const r = pt(t[n]);
3565
3564
  if (r)
3566
3565
  return r;
@@ -3572,7 +3571,7 @@ function pt(e) {
3572
3571
  }
3573
3572
  return null;
3574
3573
  }
3575
- function ns(e) {
3574
+ function ts(e) {
3576
3575
  if (!e) return "Request failed";
3577
3576
  const t = e.response, n = pt(t == null ? void 0 : t.data);
3578
3577
  if (n) return n;
@@ -3586,7 +3585,7 @@ function ns(e) {
3586
3585
  }
3587
3586
  return t != null && t.status ? `Request failed with status code ${t.status}` : "Request failed";
3588
3587
  }
3589
- function rs({
3588
+ function ns({
3590
3589
  api: e,
3591
3590
  initialThreadId: t = null,
3592
3591
  onError: n,
@@ -3594,9 +3593,9 @@ function rs({
3594
3593
  onCurrentThreadDeleted: s
3595
3594
  }) {
3596
3595
  const [o, a] = H([]), [i, f] = H(t), [l, c] = H(!1), [d, g] = H(null), [h, v] = H([]), [m, y] = H(!1), [, I] = H(null), [A, x] = H(null), [N, _] = H(!1), k = K(i), T = K(/* @__PURE__ */ new Map());
3597
- oe(() => {
3596
+ ae(() => {
3598
3597
  k.current = i;
3599
- }, [i]), oe(() => {
3598
+ }, [i]), ae(() => {
3600
3599
  t !== void 0 && t !== k.current && f(t);
3601
3600
  }, [t]);
3602
3601
  const L = E(async () => {
@@ -3622,11 +3621,11 @@ function rs({
3622
3621
  y(!1);
3623
3622
  }
3624
3623
  }, [e, n]);
3625
- oe(() => {
3624
+ ae(() => {
3626
3625
  L();
3627
- }, [L]), oe(() => {
3626
+ }, [L]), ae(() => {
3628
3627
  j();
3629
- }, [j]), oe(() => {
3628
+ }, [j]), ae(() => {
3630
3629
  r == null || r(i);
3631
3630
  }, [i, r]);
3632
3631
  const O = E(
@@ -3672,14 +3671,14 @@ function rs({
3672
3671
  try {
3673
3672
  await e.shareThread(S, P), await j(), x("Shared successfully");
3674
3673
  } catch (D) {
3675
- const V = ns(D);
3674
+ const V = ts(D);
3676
3675
  throw n == null || n(V), x(`Failed to share: ${V}`), new Error(V);
3677
3676
  } finally {
3678
3677
  _(!1);
3679
3678
  }
3680
3679
  },
3681
3680
  [e, n, j]
3682
- ), G = E(
3681
+ ), W = E(
3683
3682
  async (S, P) => {
3684
3683
  try {
3685
3684
  await e.unshareThread(S, P), await j();
@@ -3689,7 +3688,7 @@ function rs({
3689
3688
  }
3690
3689
  },
3691
3690
  [e, n, j]
3692
- ), X = pe(
3691
+ ), Q = fe(
3693
3692
  () => ({
3694
3693
  createThread: O,
3695
3694
  deleteThread: $,
@@ -3697,9 +3696,9 @@ function rs({
3697
3696
  refreshThreads: L,
3698
3697
  refreshSharedThreads: j,
3699
3698
  shareThread: J,
3700
- unshareThread: G
3699
+ unshareThread: W
3701
3700
  }),
3702
- [O, $, C, L, j, J, G]
3701
+ [O, $, C, L, j, J, W]
3703
3702
  ), te = E((S) => {
3704
3703
  if (!(S != null && S.threadId)) return;
3705
3704
  const P = {
@@ -3731,15 +3730,15 @@ function rs({
3731
3730
  threadsError: d,
3732
3731
  sharedThreads: h,
3733
3732
  isLoadingSharedThreads: m,
3734
- actions: X,
3733
+ actions: Q,
3735
3734
  addThreadFromEvent: te,
3736
3735
  shareInFlight: N,
3737
3736
  shareStatus: A,
3738
3737
  clearShareStatus: ne
3739
3738
  };
3740
3739
  }
3741
- const vn = Ge(null);
3742
- function ss({
3740
+ const kn = Ge(null);
3741
+ function rs({
3743
3742
  children: e,
3744
3743
  initialThreadId: t = null,
3745
3744
  onError: n,
@@ -3759,12 +3758,12 @@ function ss({
3759
3758
  shareInFlight: m,
3760
3759
  shareStatus: y,
3761
3760
  clearShareStatus: I
3762
- } = rs({
3761
+ } = ns({
3763
3762
  api: s,
3764
3763
  initialThreadId: t,
3765
3764
  onError: n,
3766
3765
  onThreadChange: r
3767
- }), A = pe(
3766
+ }), A = fe(
3768
3767
  () => ({
3769
3768
  threads: o,
3770
3769
  currentThreadId: a,
@@ -3796,14 +3795,14 @@ function ss({
3796
3795
  v
3797
3796
  ]
3798
3797
  );
3799
- return /* @__PURE__ */ Me(vn.Provider, { value: A, children: e });
3798
+ return /* @__PURE__ */ Ce(kn.Provider, { value: A, children: e });
3800
3799
  }
3801
3800
  function st() {
3802
- const e = at(vn);
3801
+ const e = at(kn);
3803
3802
  if (!e) throw new Error("useThreads must be used within a ThreadsProvider");
3804
3803
  return e;
3805
3804
  }
3806
- function In(e) {
3805
+ function vn(e) {
3807
3806
  const t = e.artifact;
3808
3807
  return !t || typeof t != "object" ? null : "metadata" in t && t.metadata ? t.metadata : {
3809
3808
  id: t.id ?? e.id ?? `artifact-${Date.now()}`,
@@ -3813,8 +3812,8 @@ function In(e) {
3813
3812
  progress: t.progress ?? void 0
3814
3813
  };
3815
3814
  }
3816
- function os(e, t) {
3817
- const n = In(e);
3815
+ function ss(e, t) {
3816
+ const n = vn(e);
3818
3817
  if (!n) return e;
3819
3818
  const r = {
3820
3819
  ...n,
@@ -3829,9 +3828,9 @@ function os(e, t) {
3829
3828
  }
3830
3829
  };
3831
3830
  }
3832
- function as(e, t, n) {
3831
+ function os(e, t, n) {
3833
3832
  return e.find((r) => {
3834
- const s = In(r);
3833
+ const s = vn(r);
3835
3834
  return !!((s == null ? void 0 : s.id) === t || n && r.toolCallId === n);
3836
3835
  }) ?? null;
3837
3836
  }
@@ -3841,7 +3840,7 @@ function gt(e) {
3841
3840
  function it(e, t, n) {
3842
3841
  return t < 0 || t >= e.length ? e : [...e.slice(0, t), n, ...e.slice(t + 1)];
3843
3842
  }
3844
- function is(e, t, n) {
3843
+ function as(e, t, n) {
3845
3844
  for (let r = e.length - 1; r >= 0; r--)
3846
3845
  if (e[r].role === "assistant") {
3847
3846
  const o = { ...e[r], checkpointId: t, checkpointNs: n ?? void 0 };
@@ -3849,7 +3848,7 @@ function is(e, t, n) {
3849
3848
  }
3850
3849
  return e;
3851
3850
  }
3852
- function cs(e) {
3851
+ function is(e) {
3853
3852
  const t = /* @__PURE__ */ new Set();
3854
3853
  return e.map((n) => {
3855
3854
  var o;
@@ -3865,7 +3864,7 @@ function cs(e) {
3865
3864
  return s ? t.has(s) ? !1 : (t.add(s), !0) : !0;
3866
3865
  });
3867
3866
  }
3868
- const ls = {
3867
+ const cs = {
3869
3868
  messages: [],
3870
3869
  taskMessagesByScope: {},
3871
3870
  assemblingId: null,
@@ -3875,7 +3874,7 @@ const ls = {
3875
3874
  pendingInterrupt: null,
3876
3875
  values: {}
3877
3876
  };
3878
- function us(e, t) {
3877
+ function ls(e, t) {
3879
3878
  var n;
3880
3879
  switch (t.type) {
3881
3880
  case "reset":
@@ -3925,8 +3924,8 @@ function us(e, t) {
3925
3924
  return e;
3926
3925
  }
3927
3926
  }
3928
- function ds(e = []) {
3929
- const [t, n] = jn(us, { ...ls, messages: e }), r = K([]), s = K(null), o = K(null), a = E(() => {
3927
+ function us(e = []) {
3928
+ const [t, n] = Fn(ls, { ...cs, messages: e }), r = K([]), s = K(null), o = K(null), a = E(() => {
3930
3929
  s.current !== null && typeof window < "u" && window.cancelAnimationFrame(s.current), o.current !== null && clearTimeout(o.current), s.current = null, o.current = null;
3931
3930
  const c = r.current;
3932
3931
  c.length && (r.current = [], n({ type: "batch", payload: { events: c } }));
@@ -3935,10 +3934,10 @@ function ds(e = []) {
3935
3934
  }, [a]), f = E((c) => {
3936
3935
  r.current.push(c), i();
3937
3936
  }, [i]);
3938
- oe(() => () => {
3937
+ ae(() => () => {
3939
3938
  s.current !== null && typeof window < "u" && window.cancelAnimationFrame(s.current), o.current !== null && clearTimeout(o.current), r.current = [];
3940
3939
  }, []);
3941
- const l = pe(() => ({
3940
+ const l = fe(() => ({
3942
3941
  reset: (c) => n({ type: "reset", payload: { messages: c } }),
3943
3942
  seed: (c, d) => n({ type: "seed", payload: { messages: c, ...d ?? {} } }),
3944
3943
  prepend: (c) => n({ type: "prepend", payload: { messages: c } }),
@@ -3951,15 +3950,15 @@ function Yt(e, t) {
3951
3950
  var a;
3952
3951
  const n = t, r = n == null ? void 0 : n.origin, s = n == null ? void 0 : n.scope, o = r === "task" || typeof s == "string" && s.startsWith("tools:");
3953
3952
  if (t.type === "tool.start")
3954
- return o ? e : gs(e, t);
3953
+ return o ? e : ps(e, t);
3955
3954
  if (t.type === "tool.progress")
3956
- return o ? e : ms(e, t);
3955
+ return o ? e : gs(e, t);
3957
3956
  if (t.type === "tool.end")
3958
- return o ? e : hs(e, t);
3957
+ return o ? e : ms(e, t);
3959
3958
  if (t.type === "artifact.update")
3960
- return ys(e, t);
3959
+ return hs(e, t);
3961
3960
  if (t.type === "checkpoint") {
3962
- const i = t.checkpointNs ?? e.lastCheckpointNs ?? null, f = is(e.messages, t.checkpointId, i);
3961
+ const i = t.checkpointNs ?? e.lastCheckpointNs ?? null, f = as(e.messages, t.checkpointId, i);
3963
3962
  return { ...e, lastCheckpointId: t.checkpointId, lastCheckpointNs: i, messages: f };
3964
3963
  }
3965
3964
  if (t.type === "error") {
@@ -3972,7 +3971,7 @@ function Yt(e, t) {
3972
3971
  return { ...e, messages: [...e.messages, i] };
3973
3972
  }
3974
3973
  if (t.type === "values" && ((a = t.values) != null && a.messages)) {
3975
- const i = t.values, f = Array.isArray(i.messages) ? i.messages : [], l = cs(gt(f)), { messages: c, ...d } = i;
3974
+ const i = t.values, f = Array.isArray(i.messages) ? i.messages : [], l = is(gt(f)), { messages: c, ...d } = i;
3976
3975
  if (o) {
3977
3976
  const g = typeof s == "string" && s.length > 0 ? s : "task";
3978
3977
  return {
@@ -3994,7 +3993,7 @@ function Yt(e, t) {
3994
3993
  }
3995
3994
  return t.type === "thread_info", e;
3996
3995
  }
3997
- function Tn(e) {
3996
+ function In(e) {
3998
3997
  return e.id ?? void 0;
3999
3998
  }
4000
3999
  function kt(e, t) {
@@ -4007,12 +4006,12 @@ function kt(e, t) {
4007
4006
  }
4008
4007
  return -1;
4009
4008
  }
4010
- function fs(e) {
4009
+ function ds(e) {
4011
4010
  for (let t = e.length - 1; t >= 0; t--)
4012
4011
  if (e[t].role === "user") return t;
4013
4012
  return -1;
4014
4013
  }
4015
- function ps(e, t, n) {
4014
+ function fs(e, t, n) {
4016
4015
  const r = kt(e, t);
4017
4016
  if (r === -1) return e;
4018
4017
  const s = e[r], o = (s.toolCalls ?? []).map(
@@ -4020,13 +4019,13 @@ function ps(e, t, n) {
4020
4019
  );
4021
4020
  return it(e, r, { ...s, toolCalls: o });
4022
4021
  }
4023
- function gs(e, t) {
4022
+ function ps(e, t) {
4024
4023
  const n = t, r = n.id || n.callId, s = n.name ?? void 0, o = n.scope ?? void 0, a = `Starting ${s ?? "tool"}...`;
4025
4024
  let i = e.messages;
4026
4025
  if (r) {
4027
4026
  let f = kt(i, r);
4028
4027
  if (f === -1) {
4029
- const l = fs(i);
4028
+ const l = ds(i);
4030
4029
  for (let c = i.length - 1; c > l; c--)
4031
4030
  if (i[c].role === "assistant") {
4032
4031
  f = c;
@@ -4064,27 +4063,27 @@ function gs(e, t) {
4064
4063
  }
4065
4064
  return { ...e, messages: i };
4066
4065
  }
4067
- function ms(e, t) {
4068
- const n = t.id ?? Tn(t);
4066
+ function gs(e, t) {
4067
+ const n = t.id ?? In(t);
4069
4068
  if (!n) return e;
4070
4069
  const r = t.content ?? void 0, s = t.scope ?? void 0;
4071
4070
  let o = e.messages;
4072
4071
  const a = kt(o, n);
4073
4072
  if (a !== -1) {
4074
- const i = o[a], f = r ?? null, l = typeof f == "string" ? f : JSON.stringify(f), c = Ee(f), d = typeof c == "string" ? c : l, g = (i.toolCalls ?? []).map(
4073
+ const i = o[a], f = r ?? null, l = typeof f == "string" ? f : JSON.stringify(f), c = Me(f), d = typeof c == "string" ? c : l, g = (i.toolCalls ?? []).map(
4075
4074
  (h) => h.id === n ? { ...h, content: d, scope: s ?? h.scope } : h
4076
4075
  );
4077
4076
  o = it(o, a, { ...i, toolCalls: g });
4078
4077
  }
4079
4078
  return { ...e, messages: o };
4080
4079
  }
4081
- function hs(e, t) {
4082
- const n = Tn(t);
4080
+ function ms(e, t) {
4081
+ const n = In(t);
4083
4082
  let r = e.messages;
4084
- const s = t.scope ?? void 0, o = t.content ?? t.error ?? null, a = typeof o == "string" ? o : JSON.stringify(o), i = Ee(o), f = typeof i == "string" ? i : a;
4083
+ const s = t.scope ?? void 0, o = t.content ?? t.error ?? null, a = typeof o == "string" ? o : JSON.stringify(o), i = Me(o), f = typeof i == "string" ? i : a;
4085
4084
  if (n)
4086
4085
  if (kt(r, n) !== -1)
4087
- r = ps(r, n, {
4086
+ r = fs(r, n, {
4088
4087
  status: "completed",
4089
4088
  content: f,
4090
4089
  artifact: t.artifact,
@@ -4120,8 +4119,8 @@ function hs(e, t) {
4120
4119
  };
4121
4120
  return { ...e, messages: [...r, l] };
4122
4121
  }
4123
- function ys(e, t) {
4124
- const n = t.artifactId, r = t.callId, s = as(e.messages, n, r);
4122
+ function hs(e, t) {
4123
+ const n = t.artifactId, r = t.callId, s = os(e.messages, n, r);
4125
4124
  if (!s) {
4126
4125
  const i = {
4127
4126
  id: `artifact-${n}`,
@@ -4146,7 +4145,7 @@ function ys(e, t) {
4146
4145
  messages: [...e.messages, i]
4147
4146
  };
4148
4147
  }
4149
- const o = e.messages.indexOf(s), a = os(s, {
4148
+ const o = e.messages.indexOf(s), a = ss(s, {
4150
4149
  status: t.status,
4151
4150
  progress: t.progress,
4152
4151
  error: t.error
@@ -4160,7 +4159,7 @@ function ys(e, t) {
4160
4159
  };
4161
4160
  }
4162
4161
  const Zt = 120;
4163
- function bs(e) {
4162
+ function ys(e) {
4164
4163
  if (!Array.isArray(e))
4165
4164
  return "";
4166
4165
  const t = e.filter((r) => !!(r && r.type === "text")).map((r) => (r.text ?? "").trim()).filter(Boolean);
@@ -4169,10 +4168,10 @@ function bs(e) {
4169
4168
  const n = t.join(" ").replace(/\s+/g, " ").trim();
4170
4169
  return n ? n.length > Zt ? `${n.slice(0, Zt - 3)}…` : n : "";
4171
4170
  }
4172
- function ws(e) {
4173
- return bs(e.content) || "";
4171
+ function bs(e) {
4172
+ return ys(e.content) || "";
4174
4173
  }
4175
- function ks(e) {
4174
+ function ws(e) {
4176
4175
  const t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Map(), s = [];
4177
4176
  for (let l = 0; l < e.length; l++) {
4178
4177
  const c = e[l], d = c.checkpointId, g = d ?? `cp-${l}`, h = c.metadata ?? {}, v = typeof h.step == "number" ? h.step : null, m = typeof h.source == "string" ? h.source : null;
@@ -4192,7 +4191,7 @@ function ks(e) {
4192
4191
  userMessageId: y
4193
4192
  };
4194
4193
  if (s.push(_), d && t.set(d, _), d && I) {
4195
- const k = ws(I);
4194
+ const k = bs(I);
4196
4195
  k && r.set(d, k);
4197
4196
  }
4198
4197
  n.push({
@@ -4245,7 +4244,7 @@ function ks(e) {
4245
4244
  }
4246
4245
  };
4247
4246
  }
4248
- function Qs(e, t, n) {
4247
+ function Xs(e, t, n) {
4249
4248
  if (!e)
4250
4249
  return { attemptCount: 1, attemptIndex: 0, attempts: [] };
4251
4250
  const r = n.getMessageAttempts(e);
@@ -4262,17 +4261,10 @@ function Qs(e, t, n) {
4262
4261
  attempts: r
4263
4262
  };
4264
4263
  }
4265
- function vs(e) {
4266
- return pe(() => ks(e), [e]);
4267
- }
4268
- function en(e, t) {
4269
- return {
4270
- version: "values@1",
4271
- threadId: e,
4272
- checkpoints: t ? [t] : []
4273
- };
4264
+ function ks(e) {
4265
+ return fe(() => ws(e), [e]);
4274
4266
  }
4275
- function An({
4267
+ function Tn({
4276
4268
  api: e,
4277
4269
  fileApi: t,
4278
4270
  seed: n,
@@ -4285,14 +4277,14 @@ function An({
4285
4277
  isStreaming: l,
4286
4278
  getMessages: c
4287
4279
  }) {
4288
- const [d, g] = H(null), v = pe(
4280
+ const [d, g] = H(null), v = fe(
4289
4281
  () => tt(d),
4290
4282
  [d]
4291
- ).checkpoints, m = vs(v), y = m.timeline, [I, A] = H(!1), [x, N] = H(!1), [_, k] = H(null), T = K(s), L = K(null), j = K(null), O = K(null), $ = K(null), C = K(null), J = K(/* @__PURE__ */ new Map()), G = K(null);
4292
- oe(() => {
4283
+ ).checkpoints, m = ks(v), y = m.timeline, [I, A] = H(!1), [x, N] = H(!1), [_, k] = H(null), T = K(s), L = K(null), j = K(null), O = K(null), $ = K(null), C = K(null), J = K(/* @__PURE__ */ new Map()), W = K(null);
4284
+ ae(() => {
4293
4285
  T.current = s;
4294
4286
  }, [s]);
4295
- const X = E(
4287
+ const Q = E(
4296
4288
  async (p) => {
4297
4289
  var z, U;
4298
4290
  if (!p.threadId) return;
@@ -4302,8 +4294,8 @@ function An({
4302
4294
  await p.action(b);
4303
4295
  } catch (q) {
4304
4296
  if (!Vt(q) && T.current === b) {
4305
- const ee = String(q);
4306
- (U = p.handleError) == null || U.call(p, ee), r == null || r(ee);
4297
+ const re = String(q);
4298
+ (U = p.handleError) == null || U.call(p, re), r == null || r(re);
4307
4299
  }
4308
4300
  throw q;
4309
4301
  } finally {
@@ -4313,47 +4305,50 @@ function An({
4313
4305
  [r]
4314
4306
  ), te = E(
4315
4307
  async (p, b) => {
4316
- var ee;
4308
+ var re;
4317
4309
  if (!p) return;
4318
4310
  const z = `${p}:${b ?? "latest"}`, U = J.current.get(z);
4319
4311
  if (U)
4320
4312
  return U;
4321
- (ee = G.current) == null || ee.abort();
4313
+ (re = W.current) == null || re.abort();
4322
4314
  const q = new AbortController();
4323
- G.current = q;
4324
- const B = X({
4315
+ W.current = q;
4316
+ const B = Q({
4325
4317
  threadId: p,
4326
4318
  setLoading: A,
4327
4319
  onStart: () => k(null),
4328
- handleError: (Q) => k(Q),
4329
- action: async (Q) => {
4330
- const re = await e.getState({
4331
- threadId: Q,
4332
- checkpointId: b ?? void 0
4333
- }), W = en(Q, re), se = t ? await Et(W, t) : W;
4334
- if (T.current !== Q) {
4320
+ handleError: (X) => k(X),
4321
+ action: async (X) => {
4322
+ const se = await e.getStateHistory({
4323
+ threadId: X,
4324
+ checkpointId: b ?? void 0,
4325
+ signal: q.signal,
4326
+ limit: 100,
4327
+ includeMessages: !0
4328
+ }), G = t ? await Et(se, t) : se;
4329
+ if (T.current !== X) {
4335
4330
  console.log(
4336
- `[useThreadHistoryState] Thread changed during load (was ${Q}, now ${T.current}), discarding stale data`
4331
+ `[useThreadHistoryState] Thread changed during load (was ${X}, now ${T.current}), discarding stale data`
4337
4332
  );
4338
4333
  return;
4339
4334
  }
4340
- const { checkpoints: ge, latest: be } = tt(se), ue = b ? ge.find((de) => de.checkpointId === b) ?? be : be;
4341
- n((ue == null ? void 0 : ue.messages) ?? [], {
4342
- checkpointId: (ue == null ? void 0 : ue.checkpointId) ?? null,
4343
- checkpointNs: (ue == null ? void 0 : ue.checkpointNs) ?? null,
4344
- pendingInterrupt: (ue == null ? void 0 : ue.interrupt) ?? null
4345
- }), g(se);
4335
+ const { checkpoints: oe, latest: pe } = tt(G), ee = b ? oe.find((Fe) => Fe.checkpointId === b) ?? pe : pe;
4336
+ n((ee == null ? void 0 : ee.messages) ?? [], {
4337
+ checkpointId: (ee == null ? void 0 : ee.checkpointId) ?? null,
4338
+ checkpointNs: (ee == null ? void 0 : ee.checkpointNs) ?? null,
4339
+ pendingInterrupt: (ee == null ? void 0 : ee.interrupt) ?? null
4340
+ }), g(G);
4346
4341
  }
4347
4342
  });
4348
4343
  J.current.set(z, B);
4349
4344
  try {
4350
4345
  await B;
4351
4346
  } finally {
4352
- J.current.delete(z), G.current === q && (G.current = null);
4347
+ J.current.delete(z), W.current === q && (W.current = null);
4353
4348
  }
4354
4349
  return T.current === p && (C.current = z), B;
4355
4350
  },
4356
- [e, n, X, t]
4351
+ [e, n, Q, t]
4357
4352
  ), ne = E(
4358
4353
  async (p, b) => {
4359
4354
  $.current = p;
@@ -4391,33 +4386,35 @@ function An({
4391
4386
  ), V = E(
4392
4387
  async (p, b) => {
4393
4388
  const z = T.current;
4394
- await X({
4389
+ await Q({
4395
4390
  threadId: z,
4396
4391
  setLoading: N,
4397
4392
  action: async (U) => {
4398
- const q = await e.getState({
4393
+ const q = await e.getStateHistory({
4399
4394
  threadId: U,
4400
4395
  checkpointId: p,
4401
- checkpointNs: b ?? void 0
4402
- }), B = en(U, q), ee = t ? await Et(B, t) : B;
4396
+ checkpointNs: b ?? void 0,
4397
+ limit: 100,
4398
+ includeMessages: !0
4399
+ }), B = t ? await Et(q, t) : q;
4403
4400
  if (T.current !== U)
4404
4401
  return;
4405
- const { checkpoints: Q } = tt(ee), re = Q.find(
4406
- (W) => W.checkpointId === p && (b ? W.checkpointNs === b : !0)
4402
+ const { checkpoints: re } = tt(B), X = re.find(
4403
+ (se) => se.checkpointId === p && (b ? se.checkpointNs === b : !0)
4407
4404
  );
4408
- if (!re) {
4405
+ if (!X) {
4409
4406
  console.warn("[useThreadHistoryState] Requested checkpoint not found:", { checkpointId: p, checkpointNs: b });
4410
4407
  return;
4411
4408
  }
4412
- g(ee), n(re.messages ?? [], {
4413
- checkpointId: re.checkpointId ?? null,
4414
- checkpointNs: re.checkpointNs ?? null
4409
+ g(B), n(X.messages ?? [], {
4410
+ checkpointId: X.checkpointId ?? null,
4411
+ checkpointNs: X.checkpointNs ?? null
4415
4412
  });
4416
4413
  }
4417
4414
  }).catch(() => {
4418
4415
  });
4419
4416
  },
4420
- [e, n, X, t]
4417
+ [e, n, Q, t]
4421
4418
  ), u = E(
4422
4419
  (p, b) => {
4423
4420
  n(c(), {
@@ -4429,7 +4426,7 @@ function An({
4429
4426
  ), R = E(async () => {
4430
4427
  T.current && await ne(T.current);
4431
4428
  }, [ne]);
4432
- oe(() => {
4429
+ ae(() => {
4433
4430
  if (!f || !s || I || l)
4434
4431
  return;
4435
4432
  if (j.current === s) {
@@ -4481,19 +4478,19 @@ function An({
4481
4478
  clearState: M
4482
4479
  };
4483
4480
  }
4484
- const Sn = Ge(null), xn = Ge(null);
4485
- function Cn(e) {
4486
- const t = at(Sn);
4481
+ const An = Ge(null), Sn = Ge(null);
4482
+ function xn(e) {
4483
+ const t = at(An);
4487
4484
  if (!t && !(e != null && e.optional)) throw new Error("useThreadState must be used within a ThreadStateProvider");
4488
4485
  return t;
4489
4486
  }
4490
- function Is() {
4491
- const e = at(xn);
4487
+ function vs() {
4488
+ const e = at(Sn);
4492
4489
  if (!e)
4493
4490
  throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");
4494
4491
  return e;
4495
4492
  }
4496
- function Ts({
4493
+ function Is({
4497
4494
  children: e,
4498
4495
  initialThreadId: t = null,
4499
4496
  initialCheckpointId: n = null,
@@ -4502,7 +4499,7 @@ function Ts({
4502
4499
  isStreaming: o,
4503
4500
  onError: a
4504
4501
  }) {
4505
- const { chatApi: i, fileApi: f } = We(), { currentThreadId: l } = st(), { state: c, seed: d, onEvent: g, dispatch: h } = ds(), {
4502
+ const { chatApi: i, fileApi: f } = We(), { currentThreadId: l } = st(), { state: c, seed: d, onEvent: g, dispatch: h } = us(), {
4506
4503
  threadCheckpoints: v,
4507
4504
  threadTimeline: m,
4508
4505
  checkpointIndex: y,
@@ -4517,7 +4514,7 @@ function Ts({
4517
4514
  markSkipNextLoad: j,
4518
4515
  markStreamPendingThread: O,
4519
4516
  resetHistoryState: $
4520
- } = An({
4517
+ } = Tn({
4521
4518
  api: i,
4522
4519
  fileApi: f,
4523
4520
  seed: d,
@@ -4530,7 +4527,7 @@ function Ts({
4530
4527
  isStreaming: o,
4531
4528
  getMessages: E(() => c.messages, [c.messages])
4532
4529
  });
4533
- oe(() => {
4530
+ ae(() => {
4534
4531
  l || (d([], {}), $());
4535
4532
  }, [l, d, $]);
4536
4533
  const C = K(null), J = E(
@@ -4538,14 +4535,14 @@ function Ts({
4538
4535
  C.current = u;
4539
4536
  },
4540
4537
  []
4541
- ), G = K(null), X = E(
4538
+ ), W = K(null), Q = E(
4542
4539
  (u) => {
4543
- G.current = u;
4540
+ W.current = u;
4544
4541
  },
4545
4542
  []
4546
- ), te = pe(() => ({ assemblingMessageId: c.assemblingId ?? null }), [c.assemblingId]), ne = E(
4543
+ ), te = fe(() => ({ assemblingMessageId: c.assemblingId ?? null }), [c.assemblingId]), ne = E(
4547
4544
  (u, R) => {
4548
- const M = kn(u, "user");
4545
+ const M = wn(u, "user");
4549
4546
  return h({
4550
4547
  type: "user_message",
4551
4548
  payload: {
@@ -4557,7 +4554,7 @@ function Ts({
4557
4554
  [h]
4558
4555
  ), S = E(async () => {
4559
4556
  C.current ? await C.current() : (d([], {}), $());
4560
- }, [d, $]), P = pe(() => xr(c.messages), [c.messages]), D = pe(
4557
+ }, [d, $]), P = fe(() => Sr(c.messages), [c.messages]), D = fe(
4561
4558
  () => ({
4562
4559
  threadId: l,
4563
4560
  messages: c.messages,
@@ -4595,7 +4592,7 @@ function Ts({
4595
4592
  },
4596
4593
  clearThread: S,
4597
4594
  respondToInterrupt: async (u, R, M) => {
4598
- G.current && await G.current(u, R, M);
4595
+ W.current && await W.current(u, R, M);
4599
4596
  },
4600
4597
  messagePreviews: y.messagePreviews,
4601
4598
  handleValuesEvent: L,
@@ -4634,17 +4631,17 @@ function Ts({
4634
4631
  g,
4635
4632
  P
4636
4633
  ]
4637
- ), V = pe(
4634
+ ), V = fe(
4638
4635
  () => ({
4639
4636
  registerClearThread: J,
4640
- registerRespondToInterrupt: X
4637
+ registerRespondToInterrupt: Q
4641
4638
  }),
4642
- [J, X]
4639
+ [J, Q]
4643
4640
  );
4644
- return /* @__PURE__ */ Me(xn.Provider, { value: V, children: /* @__PURE__ */ Me(Sn.Provider, { value: D, children: e }) });
4641
+ return /* @__PURE__ */ Ce(Sn.Provider, { value: V, children: /* @__PURE__ */ Ce(An.Provider, { value: D, children: e }) });
4645
4642
  }
4646
- const Mn = Ge(null), As = Ge(!1);
4647
- function Ss({
4643
+ const Cn = Ge(null), Ts = Ge(!1);
4644
+ function As({
4648
4645
  children: e,
4649
4646
  onError: t,
4650
4647
  onAuthError: n,
@@ -4656,7 +4653,7 @@ function Ss({
4656
4653
  onFinish: f,
4657
4654
  onStreamingChange: l
4658
4655
  }) {
4659
- const { chatApi: c, baseUrl: d } = We(), g = d, h = Le(t), v = Le(n), m = Le(r), y = Le(s), I = Le(o), A = Le(a), x = Le(i), N = Le(f), _ = Le(l), k = pe(
4656
+ const { chatApi: c, baseUrl: d } = We(), g = d, h = _e(t), v = _e(n), m = _e(r), y = _e(s), I = _e(o), A = _e(a), x = _e(i), N = _e(f), _ = _e(l), k = fe(
4660
4657
  () => ({
4661
4658
  onError: h,
4662
4659
  onAuthError: v,
@@ -4678,8 +4675,8 @@ function Ss({
4678
4675
  N
4679
4676
  ]
4680
4677
  );
4681
- return /* @__PURE__ */ Me(As.Provider, { value: !0, children: /* @__PURE__ */ Me(
4682
- xs,
4678
+ return /* @__PURE__ */ Ce(Ts.Provider, { value: !0, children: /* @__PURE__ */ Ce(
4679
+ Ss,
4683
4680
  {
4684
4681
  api: c,
4685
4682
  streamBaseUrl: g,
@@ -4689,7 +4686,7 @@ function Ss({
4689
4686
  }
4690
4687
  ) });
4691
4688
  }
4692
- function xs({
4689
+ function Ss({
4693
4690
  children: e,
4694
4691
  api: t,
4695
4692
  streamBaseUrl: n,
@@ -4707,12 +4704,12 @@ function xs({
4707
4704
  pushUser: y,
4708
4705
  onEvent: I,
4709
4706
  messages: A
4710
- } = Cn(), { registerClearThread: x, registerRespondToInterrupt: N } = Is(), _ = E(
4707
+ } = xn(), { registerClearThread: x, registerRespondToInterrupt: N } = vs(), _ = E(
4711
4708
  (u) => {
4712
4709
  i(u), v(u.threadId), a.current !== u.threadId && ((u.created ?? !a.current) && h(u.threadId), o(u.threadId));
4713
4710
  },
4714
4711
  [i, h, v, o, a]
4715
- ), k = es({
4712
+ ), k = Zr({
4716
4713
  baseUrl: n,
4717
4714
  onEvent: I,
4718
4715
  onError: (u) => {
@@ -4729,20 +4726,20 @@ function xs({
4729
4726
  onToolEnd: r.onToolEnd,
4730
4727
  handleValuesEvent: g
4731
4728
  });
4732
- oe(() => {
4729
+ ae(() => {
4733
4730
  s == null || s(k.isStreaming);
4734
4731
  }, [k.isStreaming, s]);
4735
- const { stream: T, stop: L, clear: j, isStreaming: O, error: $, connected: C, streamedMessages: J, activeMessageId: G } = k;
4736
- oe(() => {
4732
+ const { stream: T, stop: L, clear: j, isStreaming: O, error: $, connected: C, streamedMessages: J, activeMessageId: W } = k;
4733
+ ae(() => {
4737
4734
  f !== void 0 && j();
4738
4735
  }, [f, j]);
4739
- const X = E(
4736
+ const Q = E(
4740
4737
  async (u, R) => {
4741
4738
  await T(u, R);
4742
4739
  },
4743
4740
  [T]
4744
4741
  ), te = K(c);
4745
- oe(() => {
4742
+ ae(() => {
4746
4743
  te.current = c;
4747
4744
  }, [c]);
4748
4745
  const ne = E(
@@ -4757,17 +4754,17 @@ function xs({
4757
4754
  command: { kind: "resume", value: b },
4758
4755
  payload: M == null ? void 0 : M.payload
4759
4756
  };
4760
- X(B);
4757
+ Q(B);
4761
4758
  },
4762
- [a, X]
4759
+ [a, Q]
4763
4760
  );
4764
- oe(() => {
4761
+ ae(() => {
4765
4762
  N(ne);
4766
4763
  }, [ne, N]);
4767
4764
  const S = E(async () => {
4768
4765
  L(), j(), m(), o(null);
4769
4766
  }, [j, m, o, L]);
4770
- oe(() => {
4767
+ ae(() => {
4771
4768
  x(S);
4772
4769
  }, [S, x]);
4773
4770
  const P = E(
@@ -4776,30 +4773,30 @@ function xs({
4776
4773
  let M = a.current;
4777
4774
  const p = (u == null ? void 0 : u.text) ?? "", b = (u == null ? void 0 : u.attachments) ?? [], z = (p == null ? void 0 : p.trim()) ?? "", U = { ...(u == null ? void 0 : u.payload) ?? {} }, q = Array.isArray(U.messages) ? U.messages : void 0;
4778
4775
  q && delete U.messages;
4779
- const B = !!(q && q.length), ee = !!(u.contentParts && u.contentParts.length > 0);
4780
- if (!M && !z && b.length === 0 && !B && !ee) return;
4776
+ const B = !!(q && q.length), re = !!(u.contentParts && u.contentParts.length > 0);
4777
+ if (!M && !z && b.length === 0 && !B && !re) return;
4781
4778
  if (!M) {
4782
- const Se = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), Ke = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4783
- M = `${Se}${Ke}`, h(M), o(M);
4779
+ const Ae = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), Ke = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4780
+ M = `${Ae}${Ke}`, h(M), o(M);
4784
4781
  }
4785
- let Q = null;
4786
- u.contentParts && u.contentParts.length > 0 && (Q = u.contentParts);
4787
- const { contentParts: re, filesInfo: W } = Q ? { contentParts: Q, filesInfo: [] } : await Hr(b), se = [...re];
4788
- z && se.push({ type: "text", text: p });
4789
- const ge = u == null ? void 0 : u.originalMessageId, be = !!(u != null && u.edit && ge), ue = !B && se.length > 0;
4790
- let de = null;
4791
- if (ue) {
4792
- const Se = be ? ge : `msg-${Date.now()}`;
4793
- de = kn({
4794
- id: Se,
4782
+ let X = null;
4783
+ u.contentParts && u.contentParts.length > 0 && (X = u.contentParts);
4784
+ const { contentParts: se, filesInfo: G } = X ? { contentParts: X, filesInfo: [] } : await Kr(b), oe = [...se];
4785
+ z && oe.push({ type: "text", text: p });
4786
+ const pe = u == null ? void 0 : u.originalMessageId, ee = !!(u != null && u.edit && pe), Fe = !B && oe.length > 0;
4787
+ let ge = null;
4788
+ if (Fe) {
4789
+ const Ae = ee ? pe : `msg-${Date.now()}`;
4790
+ ge = wn({
4791
+ id: Ae,
4795
4792
  role: "user",
4796
- content: se,
4793
+ content: oe,
4797
4794
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4798
- }, "user"), be ? y(de, { editingMessageId: ge }) : y(de);
4795
+ }, "user"), ee ? y(ge, { editingMessageId: pe }) : y(ge);
4799
4796
  }
4800
- const je = B ? q : de ? [de] : [], Oe = {
4797
+ const je = B ? q : ge ? [ge] : [], Oe = {
4801
4798
  ...U,
4802
- ...W.length ? { files_info: W } : {}
4799
+ ...G.length ? { files_info: G } : {}
4803
4800
  };
4804
4801
  je.length ? Oe.messages = je : "messages" in Oe || (Oe.messages = []);
4805
4802
  const Xe = (u == null ? void 0 : u.checkpointId) ?? c.id ?? void 0;
@@ -4807,7 +4804,7 @@ function xs({
4807
4804
  throw new Error(
4808
4805
  `[streaming] Missing checkpointId for edit submit. threadId=${M ?? "null"}`
4809
4806
  );
4810
- const Ae = {
4807
+ const Te = {
4811
4808
  threadId: M,
4812
4809
  content: u == null ? void 0 : u.text,
4813
4810
  payload: Oe,
@@ -4816,10 +4813,10 @@ function xs({
4816
4813
  command: u == null ? void 0 : u.command,
4817
4814
  edit: u == null ? void 0 : u.edit
4818
4815
  };
4819
- return X(Ae, R);
4816
+ return Q(Te, R);
4820
4817
  },
4821
- [c, a, O, h, y, X, L, d]
4822
- ), D = pe(() => {
4818
+ [c, a, O, h, y, Q, L, d]
4819
+ ), D = fe(() => {
4823
4820
  const u = Object.keys(J).length > 0;
4824
4821
  if (!O && !u)
4825
4822
  return A;
@@ -4827,13 +4824,13 @@ function xs({
4827
4824
  return A.forEach((M) => R.set(M.id, M)), Object.values(J).forEach((M) => {
4828
4825
  R.set(M.id, M);
4829
4826
  }), Array.from(R.values());
4830
- }, [O, J, A]), V = pe(
4827
+ }, [O, J, A]), V = fe(
4831
4828
  () => ({
4832
4829
  isStreaming: O,
4833
4830
  error: $,
4834
4831
  connectionState: $ ? "error" : O ? C ? "connected" : "connecting" : "idle",
4835
4832
  messages: D,
4836
- activeMessageId: G,
4833
+ activeMessageId: W,
4837
4834
  submit: P,
4838
4835
  stop: L,
4839
4836
  interrupt: l,
@@ -4845,11 +4842,11 @@ function xs({
4845
4842
  }),
4846
4843
  [O, $, P, L, l, C, D]
4847
4844
  );
4848
- return /* @__PURE__ */ Me(Mn.Provider, { value: V, children: e });
4845
+ return /* @__PURE__ */ Ce(Cn.Provider, { value: V, children: e });
4849
4846
  }
4850
- function Le(e) {
4847
+ function _e(e) {
4851
4848
  const t = K(e);
4852
- return oe(() => {
4849
+ return ae(() => {
4853
4850
  t.current = e;
4854
4851
  }, [e]), E((...n) => {
4855
4852
  const r = t.current;
@@ -4857,17 +4854,17 @@ function Le(e) {
4857
4854
  return r(...n);
4858
4855
  }, []);
4859
4856
  }
4860
- function Cs() {
4861
- const e = at(Mn);
4857
+ function xs() {
4858
+ const e = at(Cn);
4862
4859
  if (!e) throw new Error("useStream must be used within StreamingProvider");
4863
4860
  return e;
4864
4861
  }
4865
- function tn(e) {
4862
+ function en(e) {
4866
4863
  return typeof e == "object" && e !== null;
4867
4864
  }
4868
- function Ms(e, t) {
4865
+ function Cs(e, t) {
4869
4866
  if (Object.is(e, t)) return !0;
4870
- if (!tn(e) || !tn(t)) return !1;
4867
+ if (!en(e) || !en(t)) return !1;
4871
4868
  const n = Object.keys(e), r = Object.keys(t);
4872
4869
  if (n.length !== r.length)
4873
4870
  return !1;
@@ -4876,22 +4873,22 @@ function Ms(e, t) {
4876
4873
  return !1;
4877
4874
  return !0;
4878
4875
  }
4879
- function Es(e) {
4876
+ function Ms(e) {
4880
4877
  const t = K(e), n = K(e);
4881
- return Ms(t.current, e) || (t.current = e, n.current = e), n.current;
4878
+ return Cs(t.current, e) || (t.current = e, n.current = e), n.current;
4882
4879
  }
4883
- function Ps(e) {
4880
+ function Es(e) {
4884
4881
  const t = e.artifact && typeof e.artifact == "object" ? e.artifact : null, n = !t && e.content && typeof e.content == "object" ? e.content : null, r = t ?? n, s = (r == null ? void 0 : r.task_id) ?? (r == null ? void 0 : r.taskId) ?? null;
4885
4882
  return typeof s == "string" ? s : null;
4886
4883
  }
4887
- function Ys(e) {
4884
+ function Qs(e) {
4888
4885
  const { setCurrentTaskId: t, getCurrentTaskId: n, onToolEnd: r } = e;
4889
4886
  return (s) => {
4890
- const o = Ps(s), a = (n == null ? void 0 : n()) ?? null;
4887
+ const o = Es(s), a = (n == null ? void 0 : n()) ?? null;
4891
4888
  o && o !== a && t(o), r == null || r(s);
4892
4889
  };
4893
4890
  }
4894
- function Zs({
4891
+ function Ys({
4895
4892
  children: e,
4896
4893
  apiConfig: t,
4897
4894
  initialThreadId: n = null,
@@ -4908,7 +4905,7 @@ function Zs({
4908
4905
  onMetadataEvent: h,
4909
4906
  onFinish: v
4910
4907
  }) {
4911
- const m = Es(t), [y, I] = H(!1), A = ze(i), x = ze(f), N = ze(a), _ = ze(l), k = ze(c), T = ze(d), L = ze(g), j = ze(h), O = ze(v), $ = pe(
4908
+ const m = Ms(t), [y, I] = H(!1), A = Le(i), x = Le(f), N = Le(a), _ = Le(l), k = Le(c), T = Le(d), L = Le(g), j = Le(h), O = Le(v), $ = fe(
4912
4909
  () => ({
4913
4910
  onError: A,
4914
4911
  onAuthError: x,
@@ -4930,14 +4927,14 @@ function Zs({
4930
4927
  O
4931
4928
  ]
4932
4929
  );
4933
- return /* @__PURE__ */ Me(Vr, { apiConfig: m, children: /* @__PURE__ */ Me(
4934
- ss,
4930
+ return /* @__PURE__ */ Ce(Dr, { apiConfig: m, children: /* @__PURE__ */ Ce(
4931
+ rs,
4935
4932
  {
4936
4933
  initialThreadId: n,
4937
4934
  onError: A,
4938
4935
  onThreadChange: _,
4939
- children: /* @__PURE__ */ Me(
4940
- Ts,
4936
+ children: /* @__PURE__ */ Ce(
4937
+ Is,
4941
4938
  {
4942
4939
  initialThreadId: n,
4943
4940
  initialCheckpointId: r,
@@ -4945,8 +4942,8 @@ function Zs({
4945
4942
  autoLoadInitial: o,
4946
4943
  onError: A,
4947
4944
  isStreaming: y,
4948
- children: /* @__PURE__ */ Me(
4949
- Ss,
4945
+ children: /* @__PURE__ */ Ce(
4946
+ As,
4950
4947
  {
4951
4948
  ...$,
4952
4949
  onStreamingChange: I,
@@ -4958,7 +4955,7 @@ function Zs({
4958
4955
  }
4959
4956
  ) });
4960
4957
  }
4961
- function ze(e) {
4958
+ function Le(e) {
4962
4959
  const t = K(e);
4963
4960
  return t.current = e, E((...n) => {
4964
4961
  const r = t.current;
@@ -4966,12 +4963,12 @@ function ze(e) {
4966
4963
  return r(...n);
4967
4964
  }, []);
4968
4965
  }
4969
- const Rs = 1, Ns = 1e6;
4966
+ const Ps = 1, Rs = 1e6;
4970
4967
  let Pt = 0;
4971
- function _s() {
4968
+ function Ns() {
4972
4969
  return Pt = (Pt + 1) % Number.MAX_SAFE_INTEGER, Pt.toString();
4973
4970
  }
4974
- const Rt = /* @__PURE__ */ new Map(), nn = (e) => {
4971
+ const Rt = /* @__PURE__ */ new Map(), tn = (e) => {
4975
4972
  if (Rt.has(e))
4976
4973
  return;
4977
4974
  const t = setTimeout(() => {
@@ -4979,14 +4976,14 @@ const Rt = /* @__PURE__ */ new Map(), nn = (e) => {
4979
4976
  type: "REMOVE_TOAST",
4980
4977
  toastId: e
4981
4978
  });
4982
- }, Ns);
4979
+ }, Rs);
4983
4980
  Rt.set(e, t);
4984
- }, Ls = (e, t) => {
4981
+ }, _s = (e, t) => {
4985
4982
  switch (t.type) {
4986
4983
  case "ADD_TOAST":
4987
4984
  return {
4988
4985
  ...e,
4989
- toasts: [t.toast, ...e.toasts].slice(0, Rs)
4986
+ toasts: [t.toast, ...e.toasts].slice(0, Ps)
4990
4987
  };
4991
4988
  case "UPDATE_TOAST":
4992
4989
  return {
@@ -4997,8 +4994,8 @@ const Rt = /* @__PURE__ */ new Map(), nn = (e) => {
4997
4994
  };
4998
4995
  case "DISMISS_TOAST": {
4999
4996
  const { toastId: n } = t;
5000
- return n ? nn(n) : e.toasts.forEach((r) => {
5001
- nn(r.id);
4997
+ return n ? tn(n) : e.toasts.forEach((r) => {
4998
+ tn(r.id);
5002
4999
  }), {
5003
5000
  ...e,
5004
5001
  toasts: e.toasts.map(
@@ -5021,12 +5018,12 @@ const Rt = /* @__PURE__ */ new Map(), nn = (e) => {
5021
5018
  }, mt = [];
5022
5019
  let ht = { toasts: [] };
5023
5020
  function ot(e) {
5024
- ht = Ls(ht, e), mt.forEach((t) => {
5021
+ ht = _s(ht, e), mt.forEach((t) => {
5025
5022
  t(ht);
5026
5023
  });
5027
5024
  }
5028
- function zs({ ...e }) {
5029
- const t = _s(), n = (s) => ot({
5025
+ function Ls({ ...e }) {
5026
+ const t = Ns(), n = (s) => ot({
5030
5027
  type: "UPDATE_TOAST",
5031
5028
  toast: { ...s, id: t }
5032
5029
  }), r = () => ot({ type: "DISMISS_TOAST", toastId: t });
@@ -5046,19 +5043,19 @@ function zs({ ...e }) {
5046
5043
  update: n
5047
5044
  };
5048
5045
  }
5049
- function Us() {
5046
+ function zs() {
5050
5047
  const [e, t] = Dt.useState(ht);
5051
5048
  return Dt.useEffect(() => (mt.push(t), () => {
5052
5049
  const n = mt.indexOf(t);
5053
5050
  n > -1 && mt.splice(n, 1);
5054
5051
  }), [e]), {
5055
5052
  ...e,
5056
- toast: zs,
5053
+ toast: Ls,
5057
5054
  dismiss: (n) => ot({ type: "DISMISS_TOAST", toastId: n })
5058
5055
  };
5059
5056
  }
5060
- function eo(e) {
5061
- const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = We(), { toast: s } = Us(), [o, a] = H({}), [i, f] = H(null), [l, c] = H(!1), d = E(() => {
5057
+ function Zs(e) {
5058
+ const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = We(), { toast: s } = zs(), [o, a] = H({}), [i, f] = H(null), [l, c] = H(!1), d = E(() => {
5062
5059
  c(!1), f(null);
5063
5060
  }, []), g = E((v) => {
5064
5061
  f(v), c(!0);
@@ -5129,30 +5126,30 @@ function eo(e) {
5129
5126
  closeFileViewer: d
5130
5127
  };
5131
5128
  }
5132
- function to(e) {
5133
- return pe(() => {
5129
+ function eo(e) {
5130
+ return fe(() => {
5134
5131
  const t = e;
5135
5132
  let n = Array.isArray(t.content) ? t.content : [];
5136
5133
  return typeof t.content == "string" && (n = [{ type: "text", text: t.content }]), {
5137
5134
  contentParts: n,
5138
- textContent: qr(n),
5139
- toolMeta: Wr(t),
5135
+ textContent: Hr(n),
5136
+ toolMeta: qr(t),
5140
5137
  imageParts: n.filter((r) => r.type === "image_url"),
5141
5138
  fileParts: n.filter((r) => r.type === "file"),
5142
- toolRaw: Cr(n),
5139
+ toolRaw: xr(n),
5143
5140
  isToolStreaming: !!t.toolStreaming
5144
5141
  };
5145
5142
  }, [e]);
5146
5143
  }
5147
- const rn = "data:";
5148
- function Fs(e) {
5144
+ const nn = "data:";
5145
+ function Us(e) {
5149
5146
  if (!e) return [];
5150
5147
  const t = [], n = e.split(/\r?\n/);
5151
5148
  for (const r of n) {
5152
5149
  const s = r.trim();
5153
- if (!s || !s.startsWith(rn))
5150
+ if (!s || !s.startsWith(nn))
5154
5151
  continue;
5155
- const o = s.slice(rn.length).trim();
5152
+ const o = s.slice(nn.length).trim();
5156
5153
  if (!o || o.toLowerCase() === "[done]")
5157
5154
  continue;
5158
5155
  const a = Ut(o);
@@ -5160,7 +5157,7 @@ function Fs(e) {
5160
5157
  }
5161
5158
  return t;
5162
5159
  }
5163
- function js(e) {
5160
+ function Fs(e) {
5164
5161
  for (let t = e.length - 1; t >= 0; t -= 1) {
5165
5162
  const n = e[t];
5166
5163
  if (n && typeof n == "object" && n.type === "tool.end")
@@ -5168,15 +5165,15 @@ function js(e) {
5168
5165
  }
5169
5166
  return null;
5170
5167
  }
5171
- function no(e) {
5172
- return pe(() => {
5168
+ function to(e) {
5169
+ return fe(() => {
5173
5170
  const t = e.content.filter(
5174
5171
  (f) => f.type === "text"
5175
5172
  );
5176
5173
  if (!t.length)
5177
5174
  return null;
5178
5175
  let r = t.flatMap(
5179
- (f) => Fs(f.text ?? "")
5176
+ (f) => Us(f.text ?? "")
5180
5177
  );
5181
5178
  if (!r.length) {
5182
5179
  const f = t.map((c) => c.text ?? "").join(`
@@ -5185,10 +5182,10 @@ function no(e) {
5185
5182
  }
5186
5183
  if (!r.length)
5187
5184
  return null;
5188
- const o = js(r) ?? r[r.length - 1];
5185
+ const o = Fs(r) ?? r[r.length - 1];
5189
5186
  if (!o)
5190
5187
  return null;
5191
- const a = o.output ?? o.payload ?? o, i = Ee(a);
5188
+ const a = o.output ?? o.payload ?? o, i = Me(a);
5192
5189
  return i && typeof i == "object" && !Array.isArray(i) ? {
5193
5190
  kind: "dict",
5194
5191
  value: i,
@@ -5201,15 +5198,15 @@ function no(e) {
5201
5198
  };
5202
5199
  }, [e]);
5203
5200
  }
5204
- function Os(e) {
5201
+ function js(e) {
5205
5202
  var _;
5206
- const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, { currentThreadId: n, setCurrentThreadId: r, actions: s } = st(), o = Cn({ optional: !0 }), a = Cs(), i = !!t && t !== n, [f, l] = H([]), c = E((k) => {
5203
+ const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, { currentThreadId: n, setCurrentThreadId: r, actions: s } = st(), o = xn({ optional: !0 }), a = xs(), i = !!t && t !== n, [f, l] = H([]), c = E((k) => {
5207
5204
  l(k);
5208
5205
  }, []), {
5209
5206
  isLoadingThread: d,
5210
5207
  threadStateError: g,
5211
5208
  threadCheckpoints: h
5212
- } = An({
5209
+ } = Tn({
5213
5210
  api: We().chatApi,
5214
5211
  fileApi: We().fileApi,
5215
5212
  seed: c,
@@ -5218,7 +5215,7 @@ function Os(e) {
5218
5215
  isStreaming: !1,
5219
5216
  getMessages: () => f,
5220
5217
  autoLoadInitial: !0
5221
- }), v = pe(() => {
5218
+ }), v = fe(() => {
5222
5219
  var k;
5223
5220
  return ((k = h[0]) == null ? void 0 : k.values) || {};
5224
5221
  }, [h]), m = t || n, y = i ? f : (a == null ? void 0 : a.messages) || [], I = i ? d : (o == null ? void 0 : o.isLoading) || !1, A = i ? v : (o == null ? void 0 : o.values) || {}, x = i ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, N = i ? g : (a == null ? void 0 : a.error) || (o == null ? void 0 : o.error) || null;
@@ -5267,7 +5264,7 @@ function Os(e) {
5267
5264
  isThreadsLoading: st().isLoading
5268
5265
  };
5269
5266
  }
5270
- function ro({
5267
+ function no({
5271
5268
  submit: e,
5272
5269
  chatRequest: t,
5273
5270
  lastCheckpointId: n,
@@ -5283,8 +5280,8 @@ function ro({
5283
5280
  threadId: g,
5284
5281
  clearComposerOnSend: h = !0
5285
5282
  }) {
5286
- const { messages: v } = Os(), [m, y] = H(null), [I, A] = H(""), [x, N] = H(null), [_, k] = H(null), [T, L] = H(!1), [j, O] = H(""), $ = K(j), C = K(null);
5287
- oe(() => {
5283
+ const { messages: v } = js(), [m, y] = H(null), [I, A] = H(""), [x, N] = H(null), [_, k] = H(null), [T, L] = H(!1), [j, O] = H(""), $ = K(j), C = K(null);
5284
+ ae(() => {
5288
5285
  if (!m)
5289
5286
  if (g) {
5290
5287
  const u = localStorage.getItem(Mt(g));
@@ -5295,53 +5292,53 @@ function ro({
5295
5292
  const J = E((u) => {
5296
5293
  O(u), !m && g && localStorage.setItem(Mt(g), u);
5297
5294
  }, [g, m]);
5298
- oe(() => {
5295
+ ae(() => {
5299
5296
  $.current = j;
5300
- }, [j]), oe(() => {
5297
+ }, [j]), ae(() => {
5301
5298
  if (!m) {
5302
5299
  C.current = null;
5303
5300
  return;
5304
5301
  }
5305
5302
  C.current === null && (C.current = $.current), J(I ?? "");
5306
5303
  }, [I, m, J]);
5307
- const G = E(
5304
+ const W = E(
5308
5305
  (u) => {
5309
5306
  J(u);
5310
5307
  },
5311
5308
  [J]
5312
- ), X = async (u, R) => {
5309
+ ), Q = async (u, R) => {
5313
5310
  const M = Array.isArray(R) ? { files: R } : R ?? {}, p = M.files ?? [], b = M.contentParts ?? [], z = u.trim();
5314
5311
  if (!(!z && p.length === 0 && b.length === 0))
5315
5312
  try {
5316
- const U = p.map(async (W) => {
5313
+ const U = p.map(async (G) => {
5317
5314
  try {
5318
- const se = await bn.uploadFile(W);
5319
- return { file: W, record: se };
5320
- } catch (se) {
5321
- throw console.error("Failed to upload file", W.name, se), new Error(`Failed to upload ${W.name}`);
5315
+ const oe = await yn.uploadFile(G);
5316
+ return { file: G, record: oe };
5317
+ } catch (oe) {
5318
+ throw console.error("Failed to upload file", G.name, oe), new Error(`Failed to upload ${G.name}`);
5322
5319
  }
5323
- }), B = (await Promise.all(U)).map(({ record: W }) => {
5324
- const se = W.mime_type;
5325
- return se.startsWith("image/") ? {
5320
+ }), B = (await Promise.all(U)).map(({ record: G }) => {
5321
+ const oe = G.mime_type;
5322
+ return oe.startsWith("image/") ? {
5326
5323
  type: "image_url",
5327
- image_url: { url: W.content_url }
5324
+ image_url: { url: G.content_url }
5328
5325
  } : {
5329
5326
  type: "file",
5330
- url: W.content_url,
5331
- mimeType: se,
5332
- name: W.filename,
5333
- size: W.size
5327
+ url: G.content_url,
5328
+ mimeType: oe,
5329
+ name: G.filename,
5330
+ size: G.size
5334
5331
  };
5335
- }), ee = [...b, ...B], Q = m ? (x == null ? void 0 : x.checkpointId) ?? n ?? void 0 : n ?? void 0, re = m ? (x == null ? void 0 : x.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5332
+ }), re = [...b, ...B], X = m ? (x == null ? void 0 : x.checkpointId) ?? n ?? void 0 : n ?? void 0, se = m ? (x == null ? void 0 : x.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5336
5333
  await e(
5337
5334
  {
5338
5335
  text: z || "",
5339
- contentParts: ee,
5336
+ contentParts: re,
5340
5337
  attachments: p,
5341
5338
  payload: t.payload,
5342
5339
  edit: !!m,
5343
- checkpointId: Q,
5344
- checkpointNs: re,
5340
+ checkpointId: X,
5341
+ checkpointNs: se,
5345
5342
  project: c ?? void 0,
5346
5343
  originalMessageId: m ?? void 0,
5347
5344
  config: t.config
@@ -5353,7 +5350,7 @@ function ro({
5353
5350
  k(q), a == null || a(q), l(!1);
5354
5351
  }
5355
5352
  }, te = (u, R) => {
5356
- R || X(u, { files: [] });
5353
+ R || Q(u, { files: [] });
5357
5354
  }, ne = E(
5358
5355
  async (u) => {
5359
5356
  await e(
@@ -5417,8 +5414,8 @@ function ro({
5417
5414
  dismissError: T,
5418
5415
  setDismissError: L,
5419
5416
  composerValue: j,
5420
- handleComposerChange: G,
5421
- handleSendMessage: X,
5417
+ handleComposerChange: W,
5418
+ handleSendMessage: Q,
5422
5419
  handleQuickPrompt: te,
5423
5420
  handleExcelUpload: ne,
5424
5421
  startEditing: S,
@@ -5427,12 +5424,12 @@ function ro({
5427
5424
  displayMessages: v
5428
5425
  };
5429
5426
  }
5430
- function so(e) {
5431
- return pe(() => e ? {
5432
- textContent: Tr(e),
5433
- imageParts: Ar(e),
5434
- fileParts: Sr(e),
5435
- toolCalls: dn(e),
5427
+ function ro(e) {
5428
+ return fe(() => e ? {
5429
+ textContent: Ir(e),
5430
+ imageParts: Tr(e),
5431
+ fileParts: Ar(e),
5432
+ toolCalls: un(e),
5436
5433
  contentParts: e.content
5437
5434
  } : {
5438
5435
  textContent: "",
@@ -5442,9 +5439,9 @@ function so(e) {
5442
5439
  contentParts: []
5443
5440
  }, [e]);
5444
5441
  }
5445
- function oo(e, t, n) {
5442
+ function so(e, t, n) {
5446
5443
  const [r, s] = H(e), o = K(e), a = K(null);
5447
- return oe(() => {
5444
+ return ae(() => {
5448
5445
  o.current = e;
5449
5446
  const i = () => {
5450
5447
  s(o.current), a.current && (clearTimeout(a.current), a.current = null);
@@ -5461,46 +5458,46 @@ function oo(e, t, n) {
5461
5458
  }, [e, t, n]), r;
5462
5459
  }
5463
5460
  export {
5464
- Zs as ChatProviders,
5465
- Ts as ThreadStateProvider,
5466
- ss as ThreadsProvider,
5467
- Ks as cn,
5468
- qr as collectText,
5469
- Ys as createTaskSyncToolEndHandler,
5470
- Ps as extractTaskIdFromToolEnd,
5471
- Wr as extractToolMeta,
5472
- Hs as formatToolOutput,
5473
- Js as getAgentNameFromMessage,
5474
- gn as getChatToken,
5475
- Qs as getMessageAttemptInfo,
5476
- Ws as getToolCallArtifacts,
5477
- _r as getToolCalls,
5478
- qs as hasContent,
5461
+ Ys as ChatProviders,
5462
+ Is as ThreadStateProvider,
5463
+ rs as ThreadsProvider,
5464
+ Vs as cn,
5465
+ Hr as collectText,
5466
+ Qs as createTaskSyncToolEndHandler,
5467
+ Es as extractTaskIdFromToolEnd,
5468
+ qr as extractToolMeta,
5469
+ Ks as formatToolOutput,
5470
+ Gs as getAgentNameFromMessage,
5471
+ pn as getChatToken,
5472
+ Xs as getMessageAttemptInfo,
5473
+ qs as getToolCallArtifacts,
5474
+ Nr as getToolCalls,
5475
+ Hs as hasContent,
5479
5476
  tt as hydrateHistorySnapshots,
5480
- fn as isFileLike,
5481
- kr as looksLikeMarkdown,
5482
- Xs as messageSignature,
5483
- Gs as normalizeInterruptId,
5484
- mn as onChatTokenChanged,
5477
+ dn as isFileLike,
5478
+ wr as looksLikeMarkdown,
5479
+ Js as messageSignature,
5480
+ Ws as normalizeInterruptId,
5481
+ gn as onChatTokenChanged,
5485
5482
  Ut as parseJsonSafe,
5486
- pn as pretty,
5483
+ fn as pretty,
5487
5484
  Et as refreshHistoryFileUrls,
5488
5485
  yt as sanitizeForDisplay,
5489
5486
  Ve as setChatToken,
5490
- Cr as stringifyTool,
5487
+ xr as stringifyTool,
5491
5488
  We as useApi,
5492
- ro as useChatController,
5493
- Os as useChatSession,
5494
- eo as useFilePreview,
5495
- so as useMessageContent,
5496
- to as useParsedMessageContent,
5497
- es as useStream,
5498
- oo as useStreamingMarkdownBuffer,
5499
- An as useThreadHistoryState,
5500
- Cn as useThreadState,
5501
- Is as useThreadStateUpdater,
5489
+ no as useChatController,
5490
+ js as useChatSession,
5491
+ Zs as useFilePreview,
5492
+ ro as useMessageContent,
5493
+ eo as useParsedMessageContent,
5494
+ Zr as useStream,
5495
+ so as useStreamingMarkdownBuffer,
5496
+ Tn as useThreadHistoryState,
5497
+ xn as useThreadState,
5498
+ vs as useThreadStateUpdater,
5502
5499
  st as useThreads,
5503
- rs as useThreadsState,
5504
- no as useToolPayload
5500
+ ns as useThreadsState,
5501
+ to as useToolPayload
5505
5502
  };
5506
5503
  //# sourceMappingURL=index.esm.js.map