@teodorruskvi/chat-core 0.1.33 → 0.1.34

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
@@ -3,19 +3,19 @@ var zn = (e, t, n) => t in e ? Ln(e, t, { enumerable: !0, configurable: !0, writ
3
3
  var Bt = (e, t, n) => zn(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import { jsx as Ce } from "react/jsx-runtime";
5
5
  import * as Dt from "react";
6
- import { createContext as Ge, useContext as ot, useState as q, useRef as V, useEffect as oe, useCallback as C, useMemo as pe, useReducer as Fn } from "react";
6
+ import { createContext as Ge, useContext as st, useState as q, useRef as K, useEffect as se, useCallback as C, useMemo as pe, useReducer as Fn } from "react";
7
7
  import Un, { isCancel as St } from "axios";
8
8
  function nn(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
- var s = e.length;
13
- for (t = 0; t < s; t++) e[t] && (n = nn(e[t])) && (r && (r += " "), r += n);
12
+ var o = e.length;
13
+ for (t = 0; t < o; t++) e[t] && (n = nn(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
17
  function jn() {
18
- for (var e, t, n = 0, r = "", s = arguments.length; n < s; n++) (e = arguments[n]) && (t = nn(e)) && (r && (r += " "), r += t);
18
+ for (var e, t, n = 0, r = "", o = arguments.length; n < o; n++) (e = arguments[n]) && (t = nn(e)) && (r && (r += " "), r += t);
19
19
  return r;
20
20
  }
21
21
  const zt = "-", On = (e) => {
@@ -37,15 +37,15 @@ const zt = "-", On = (e) => {
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 ? rn(e.slice(1), r) : void 0;
41
- if (s)
42
- return s;
40
+ const n = e[0], r = t.nextPart.get(n), o = r ? rn(e.slice(1), r) : void 0;
41
+ if (o)
42
+ return o;
43
43
  if (t.validators.length === 0)
44
44
  return;
45
- const o = e.join(zt);
45
+ const s = e.join(zt);
46
46
  return (a = t.validators.find(({
47
47
  validator: i
48
- }) => i(o))) == null ? void 0 : a.classGroupId;
48
+ }) => i(s))) == null ? void 0 : a.classGroupId;
49
49
  }, Vt = /^\[(.+)\]$/, $n = (e) => {
50
50
  if (Vt.test(e)) {
51
51
  const t = Vt.exec(e)[1], n = t == null ? void 0 : t.substring(0, t.indexOf(":"));
@@ -60,29 +60,29 @@ const zt = "-", On = (e) => {
60
60
  nextPart: /* @__PURE__ */ new Map(),
61
61
  validators: []
62
62
  };
63
- return Vn(Object.entries(e.classGroups), n).forEach(([o, a]) => {
64
- Nt(a, r, o, t);
63
+ return Vn(Object.entries(e.classGroups), n).forEach(([s, a]) => {
64
+ Nt(a, r, s, t);
65
65
  }), r;
66
66
  }, Nt = (e, t, n, r) => {
67
- e.forEach((s) => {
68
- if (typeof s == "string") {
69
- const o = s === "" ? t : Kt(t, s);
70
- o.classGroupId = n;
67
+ e.forEach((o) => {
68
+ if (typeof o == "string") {
69
+ const s = o === "" ? t : Kt(t, o);
70
+ s.classGroupId = n;
71
71
  return;
72
72
  }
73
- if (typeof s == "function") {
74
- if (Dn(s)) {
75
- Nt(s(r), t, n, r);
73
+ if (typeof o == "function") {
74
+ if (Dn(o)) {
75
+ Nt(o(r), t, n, r);
76
76
  return;
77
77
  }
78
78
  t.validators.push({
79
- validator: s,
79
+ validator: o,
80
80
  classGroupId: n
81
81
  });
82
82
  return;
83
83
  }
84
- Object.entries(s).forEach(([o, a]) => {
85
- Nt(a, Kt(t, o), n, r);
84
+ Object.entries(o).forEach(([s, a]) => {
85
+ Nt(a, Kt(t, s), n, r);
86
86
  });
87
87
  });
88
88
  }, Kt = (e, t) => {
@@ -94,8 +94,8 @@ const zt = "-", On = (e) => {
94
94
  }), n = n.nextPart.get(r);
95
95
  }), n;
96
96
  }, Dn = (e) => e.isThemeGetter, Vn = (e, t) => t ? e.map(([n, r]) => {
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
- return [n, s];
97
+ const o = r.map((s) => typeof s == "string" ? t + s : typeof s == "object" ? Object.fromEntries(Object.entries(s).map(([a, i]) => [t + a, i])) : s);
98
+ return [n, o];
99
99
  }) : e, Kn = (e) => {
100
100
  if (e < 1)
101
101
  return {
@@ -105,33 +105,33 @@ const zt = "-", On = (e) => {
105
105
  }
106
106
  };
107
107
  let t = 0, n = /* @__PURE__ */ new Map(), r = /* @__PURE__ */ new Map();
108
- const s = (o, a) => {
109
- n.set(o, a), t++, t > e && (t = 0, r = n, n = /* @__PURE__ */ new Map());
108
+ const o = (s, a) => {
109
+ n.set(s, a), t++, t > e && (t = 0, r = n, n = /* @__PURE__ */ new Map());
110
110
  };
111
111
  return {
112
- get(o) {
113
- let a = n.get(o);
112
+ get(s) {
113
+ let a = n.get(s);
114
114
  if (a !== void 0)
115
115
  return a;
116
- if ((a = r.get(o)) !== void 0)
117
- return s(o, a), a;
116
+ if ((a = r.get(s)) !== void 0)
117
+ return o(s, a), a;
118
118
  },
119
- set(o, a) {
120
- n.has(o) ? n.set(o, a) : s(o, a);
119
+ set(s, a) {
120
+ n.has(s) ? n.set(s, a) : o(s, a);
121
121
  }
122
122
  };
123
- }, sn = "!", Hn = (e) => {
123
+ }, on = "!", Hn = (e) => {
124
124
  const {
125
125
  separator: t,
126
126
  experimentalParseClassName: n
127
- } = e, r = t.length === 1, s = t[0], o = t.length, a = (i) => {
127
+ } = e, r = t.length === 1, o = t[0], s = t.length, a = (i) => {
128
128
  const f = [];
129
129
  let l = 0, c = 0, u;
130
130
  for (let y = 0; y < i.length; y++) {
131
131
  let v = i[y];
132
132
  if (l === 0) {
133
- if (v === s && (r || i.slice(y, y + o) === t)) {
134
- f.push(i.slice(c, y)), c = y + o;
133
+ if (v === o && (r || i.slice(y, y + s) === t)) {
134
+ f.push(i.slice(c, y)), c = y + s;
135
135
  continue;
136
136
  }
137
137
  if (v === "/") {
@@ -141,11 +141,11 @@ const zt = "-", On = (e) => {
141
141
  }
142
142
  v === "[" ? l++ : v === "]" && l--;
143
143
  }
144
- const g = f.length === 0 ? i : i.substring(c), m = g.startsWith(sn), k = m ? g.substring(1) : g, p = u && u > c ? u - c : void 0;
144
+ const g = f.length === 0 ? i : i.substring(c), m = g.startsWith(on), I = m ? g.substring(1) : g, p = u && u > c ? u - c : void 0;
145
145
  return {
146
146
  modifiers: f,
147
147
  hasImportantModifier: m,
148
- baseClassName: k,
148
+ baseClassName: I,
149
149
  maybePostfixModifierPosition: p
150
150
  };
151
151
  };
@@ -169,8 +169,8 @@ const zt = "-", On = (e) => {
169
169
  const {
170
170
  parseClassName: n,
171
171
  getClassGroupId: r,
172
- getConflictingClassGroupIds: s
173
- } = t, o = [], a = e.trim().split(Gn);
172
+ getConflictingClassGroupIds: o
173
+ } = t, s = [], a = e.trim().split(Gn);
174
174
  let i = "";
175
175
  for (let f = a.length - 1; f >= 0; f -= 1) {
176
176
  const l = a[f], {
@@ -179,9 +179,9 @@ const zt = "-", On = (e) => {
179
179
  baseClassName: g,
180
180
  maybePostfixModifierPosition: m
181
181
  } = n(l);
182
- let k = !!m, p = r(k ? g.substring(0, m) : g);
182
+ let I = !!m, p = r(I ? g.substring(0, m) : g);
183
183
  if (!p) {
184
- if (!k) {
184
+ if (!I) {
185
185
  i = l + (i.length > 0 ? " " + i : i);
186
186
  continue;
187
187
  }
@@ -189,16 +189,16 @@ const zt = "-", On = (e) => {
189
189
  i = l + (i.length > 0 ? " " + i : i);
190
190
  continue;
191
191
  }
192
- k = !1;
192
+ I = !1;
193
193
  }
194
- const y = qn(c).join(":"), v = u ? y + sn : y, A = v + p;
195
- if (o.includes(A))
194
+ const y = qn(c).join(":"), v = u ? y + on : y, A = v + p;
195
+ if (s.includes(A))
196
196
  continue;
197
- o.push(A);
198
- const x = s(p, k);
197
+ s.push(A);
198
+ const x = o(p, I);
199
199
  for (let L = 0; L < x.length; ++L) {
200
200
  const z = x[L];
201
- o.push(v + z);
201
+ s.push(v + z);
202
202
  }
203
203
  i = l + (i.length > 0 ? " " + i : i);
204
204
  }
@@ -207,38 +207,38 @@ const zt = "-", On = (e) => {
207
207
  function Xn() {
208
208
  let e = 0, t, n, r = "";
209
209
  for (; e < arguments.length; )
210
- (t = arguments[e++]) && (n = on(t)) && (r && (r += " "), r += n);
210
+ (t = arguments[e++]) && (n = sn(t)) && (r && (r += " "), r += n);
211
211
  return r;
212
212
  }
213
- const on = (e) => {
213
+ const sn = (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 = on(e[r])) && (n && (n += " "), n += t);
218
+ e[r] && (t = sn(e[r])) && (n && (n += " "), n += t);
219
219
  return n;
220
220
  };
221
221
  function Qn(e, ...t) {
222
- let n, r, s, o = a;
222
+ let n, r, o, s = a;
223
223
  function a(f) {
224
224
  const l = t.reduce((c, u) => u(c), e());
225
- return n = Wn(l), r = n.cache.get, s = n.cache.set, o = i, i(f);
225
+ return n = Wn(l), r = n.cache.get, o = n.cache.set, s = 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
231
  const c = Jn(f, n);
232
- return s(f, c), c;
232
+ return o(f, c), c;
233
233
  }
234
234
  return function() {
235
- return o(Xn.apply(null, arguments));
235
+ return s(Xn.apply(null, arguments));
236
236
  };
237
237
  }
238
238
  const ne = (e) => {
239
239
  const t = (n) => n[e] || [];
240
240
  return t.isThemeGetter = !0, t;
241
- }, an = /^\[(?:([a-z-]+):)?(.+)\]$/i, Yn = /^\d+\/\d+$/, Zn = /* @__PURE__ */ new Set(["px", "full", "screen"]), er = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, tr = /\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$/, nr = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, rr = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, sr = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, _e = (e) => qe(e) || Zn.has(e) || Yn.test(e), Ue = (e) => Je(e, "length", fr), qe = (e) => !!e && !Number.isNaN(Number(e)), xt = (e) => Je(e, "number", qe), Ze = (e) => !!e && Number.isInteger(Number(e)), or = (e) => e.endsWith("%") && qe(e.slice(0, -1)), j = (e) => an.test(e), je = (e) => er.test(e), ar = /* @__PURE__ */ new Set(["length", "size", "percentage"]), ir = (e) => Je(e, ar, cn), cr = (e) => Je(e, "position", cn), lr = /* @__PURE__ */ new Set(["image", "url"]), ur = (e) => Je(e, lr, gr), dr = (e) => Je(e, "", pr), et = () => !0, Je = (e, t, n) => {
241
+ }, an = /^\[(?:([a-z-]+):)?(.+)\]$/i, Yn = /^\d+\/\d+$/, Zn = /* @__PURE__ */ new Set(["px", "full", "screen"]), er = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, tr = /\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$/, nr = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, rr = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, or = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, _e = (e) => qe(e) || Zn.has(e) || Yn.test(e), Ue = (e) => Je(e, "length", fr), qe = (e) => !!e && !Number.isNaN(Number(e)), xt = (e) => Je(e, "number", qe), Ze = (e) => !!e && Number.isInteger(Number(e)), sr = (e) => e.endsWith("%") && qe(e.slice(0, -1)), j = (e) => an.test(e), je = (e) => er.test(e), ar = /* @__PURE__ */ new Set(["length", "size", "percentage"]), ir = (e) => Je(e, ar, cn), cr = (e) => Je(e, "position", cn), lr = /* @__PURE__ */ new Set(["image", "url"]), ur = (e) => Je(e, lr, gr), dr = (e) => Je(e, "", pr), et = () => !0, Je = (e, t, n) => {
242
242
  const r = an.exec(e);
243
243
  return r ? r[1] ? typeof t == "string" ? r[1] === t : t.has(r[1]) : n(r[2]) : !1;
244
244
  }, fr = (e) => (
@@ -246,8 +246,8 @@ const ne = (e) => {
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
248
  tr.test(e) && !nr.test(e)
249
- ), cn = () => !1, pr = (e) => rr.test(e), gr = (e) => sr.test(e), mr = () => {
250
- const e = ne("colors"), t = ne("spacing"), n = ne("blur"), r = ne("brightness"), s = ne("borderColor"), o = ne("borderRadius"), a = ne("borderSpacing"), i = ne("borderWidth"), f = ne("contrast"), l = ne("grayscale"), c = ne("hueRotate"), u = ne("invert"), g = ne("gap"), m = ne("gradientColorStops"), k = ne("gradientColorStopPositions"), p = ne("inset"), y = ne("margin"), v = ne("opacity"), A = ne("padding"), x = ne("saturate"), L = ne("scale"), z = ne("sepia"), w = ne("skew"), I = ne("space"), F = ne("translate"), $ = () => ["auto", "contain", "none"], B = () => ["auto", "hidden", "clip", "visible", "scroll"], D = () => ["auto", j, t], M = () => [j, t], Q = () => ["", _e, Ue], G = () => ["auto", qe, j], re = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], te = () => ["solid", "dashed", "dotted", "double", "none"], se = () => ["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"], E = () => ["", "0", j], O = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], K = () => [qe, j];
249
+ ), cn = () => !1, pr = (e) => rr.test(e), gr = (e) => or.test(e), mr = () => {
250
+ const e = ne("colors"), t = ne("spacing"), n = ne("blur"), r = ne("brightness"), o = ne("borderColor"), s = ne("borderRadius"), a = ne("borderSpacing"), i = ne("borderWidth"), f = ne("contrast"), l = ne("grayscale"), c = ne("hueRotate"), u = ne("invert"), g = ne("gap"), m = ne("gradientColorStops"), I = ne("gradientColorStopPositions"), p = ne("inset"), y = ne("margin"), v = ne("opacity"), A = ne("padding"), x = ne("saturate"), L = ne("scale"), z = ne("sepia"), w = ne("skew"), k = ne("space"), F = ne("translate"), $ = () => ["auto", "contain", "none"], D = () => ["auto", "hidden", "clip", "visible", "scroll"], V = () => ["auto", j, t], E = () => [j, t], Y = () => ["", _e, Ue], W = () => ["auto", qe, j], re = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], te = () => ["solid", "dashed", "dotted", "double", "none"], oe = () => ["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", j], O = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], H = () => [qe, j];
251
251
  return {
252
252
  cacheSize: 500,
253
253
  separator: ":",
@@ -255,28 +255,28 @@ const ne = (e) => {
255
255
  colors: [et],
256
256
  spacing: [_e, Ue],
257
257
  blur: ["none", "", je, j],
258
- brightness: K(),
258
+ brightness: H(),
259
259
  borderColor: [e],
260
260
  borderRadius: ["none", "", "full", je, j],
261
- borderSpacing: M(),
262
- borderWidth: Q(),
263
- contrast: K(),
264
- grayscale: E(),
265
- hueRotate: K(),
266
- invert: E(),
267
- gap: M(),
261
+ borderSpacing: E(),
262
+ borderWidth: Y(),
263
+ contrast: H(),
264
+ grayscale: P(),
265
+ hueRotate: H(),
266
+ invert: P(),
267
+ gap: E(),
268
268
  gradientColorStops: [e],
269
- gradientColorStopPositions: [or, Ue],
270
- inset: D(),
271
- margin: D(),
272
- opacity: K(),
273
- padding: M(),
274
- saturate: K(),
275
- scale: K(),
276
- sepia: E(),
277
- skew: K(),
278
- space: M(),
279
- translate: M()
269
+ gradientColorStopPositions: [sr, Ue],
270
+ inset: V(),
271
+ margin: V(),
272
+ opacity: H(),
273
+ padding: E(),
274
+ saturate: H(),
275
+ scale: H(),
276
+ sepia: P(),
277
+ skew: H(),
278
+ space: E(),
279
+ translate: E()
280
280
  },
281
281
  classGroups: {
282
282
  // Layout
@@ -377,21 +377,21 @@ const ne = (e) => {
377
377
  * @see https://tailwindcss.com/docs/overflow
378
378
  */
379
379
  overflow: [{
380
- overflow: B()
380
+ overflow: D()
381
381
  }],
382
382
  /**
383
383
  * Overflow X
384
384
  * @see https://tailwindcss.com/docs/overflow
385
385
  */
386
386
  "overflow-x": [{
387
- "overflow-x": B()
387
+ "overflow-x": D()
388
388
  }],
389
389
  /**
390
390
  * Overflow Y
391
391
  * @see https://tailwindcss.com/docs/overflow
392
392
  */
393
393
  "overflow-y": [{
394
- "overflow-y": B()
394
+ "overflow-y": D()
395
395
  }],
396
396
  /**
397
397
  * Overscroll Behavior
@@ -500,7 +500,7 @@ const ne = (e) => {
500
500
  * @see https://tailwindcss.com/docs/flex-basis
501
501
  */
502
502
  basis: [{
503
- basis: D()
503
+ basis: V()
504
504
  }],
505
505
  /**
506
506
  * Flex Direction
@@ -528,14 +528,14 @@ const ne = (e) => {
528
528
  * @see https://tailwindcss.com/docs/flex-grow
529
529
  */
530
530
  grow: [{
531
- grow: E()
531
+ grow: P()
532
532
  }],
533
533
  /**
534
534
  * Flex Shrink
535
535
  * @see https://tailwindcss.com/docs/flex-shrink
536
536
  */
537
537
  shrink: [{
538
- shrink: E()
538
+ shrink: P()
539
539
  }],
540
540
  /**
541
541
  * Order
@@ -565,14 +565,14 @@ const ne = (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 ne = (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
@@ -841,7 +841,7 @@ const ne = (e) => {
841
841
  * @see https://tailwindcss.com/docs/space
842
842
  */
843
843
  "space-x": [{
844
- "space-x": [I]
844
+ "space-x": [k]
845
845
  }],
846
846
  /**
847
847
  * Space Between X Reverse
@@ -853,7 +853,7 @@ const ne = (e) => {
853
853
  * @see https://tailwindcss.com/docs/space
854
854
  */
855
855
  "space-y": [{
856
- "space-y": [I]
856
+ "space-y": [k]
857
857
  }],
858
858
  /**
859
859
  * Space Between Y Reverse
@@ -1107,7 +1107,7 @@ const ne = (e) => {
1107
1107
  * @see https://tailwindcss.com/docs/text-indent
1108
1108
  */
1109
1109
  indent: [{
1110
- indent: M()
1110
+ indent: E()
1111
1111
  }],
1112
1112
  /**
1113
1113
  * Vertical Alignment
@@ -1218,21 +1218,21 @@ const ne = (e) => {
1218
1218
  * @see https://tailwindcss.com/docs/gradient-color-stops
1219
1219
  */
1220
1220
  "gradient-from-pos": [{
1221
- from: [k]
1221
+ from: [I]
1222
1222
  }],
1223
1223
  /**
1224
1224
  * Gradient Color Stops Via Position
1225
1225
  * @see https://tailwindcss.com/docs/gradient-color-stops
1226
1226
  */
1227
1227
  "gradient-via-pos": [{
1228
- via: [k]
1228
+ via: [I]
1229
1229
  }],
1230
1230
  /**
1231
1231
  * Gradient Color Stops To Position
1232
1232
  * @see https://tailwindcss.com/docs/gradient-color-stops
1233
1233
  */
1234
1234
  "gradient-to-pos": [{
1235
- to: [k]
1235
+ to: [I]
1236
1236
  }],
1237
1237
  /**
1238
1238
  * Gradient Color Stops From
@@ -1261,105 +1261,105 @@ const ne = (e) => {
1261
1261
  * @see https://tailwindcss.com/docs/border-radius
1262
1262
  */
1263
1263
  rounded: [{
1264
- rounded: [o]
1264
+ rounded: [s]
1265
1265
  }],
1266
1266
  /**
1267
1267
  * Border Radius Start
1268
1268
  * @see https://tailwindcss.com/docs/border-radius
1269
1269
  */
1270
1270
  "rounded-s": [{
1271
- "rounded-s": [o]
1271
+ "rounded-s": [s]
1272
1272
  }],
1273
1273
  /**
1274
1274
  * Border Radius End
1275
1275
  * @see https://tailwindcss.com/docs/border-radius
1276
1276
  */
1277
1277
  "rounded-e": [{
1278
- "rounded-e": [o]
1278
+ "rounded-e": [s]
1279
1279
  }],
1280
1280
  /**
1281
1281
  * Border Radius Top
1282
1282
  * @see https://tailwindcss.com/docs/border-radius
1283
1283
  */
1284
1284
  "rounded-t": [{
1285
- "rounded-t": [o]
1285
+ "rounded-t": [s]
1286
1286
  }],
1287
1287
  /**
1288
1288
  * Border Radius Right
1289
1289
  * @see https://tailwindcss.com/docs/border-radius
1290
1290
  */
1291
1291
  "rounded-r": [{
1292
- "rounded-r": [o]
1292
+ "rounded-r": [s]
1293
1293
  }],
1294
1294
  /**
1295
1295
  * Border Radius Bottom
1296
1296
  * @see https://tailwindcss.com/docs/border-radius
1297
1297
  */
1298
1298
  "rounded-b": [{
1299
- "rounded-b": [o]
1299
+ "rounded-b": [s]
1300
1300
  }],
1301
1301
  /**
1302
1302
  * Border Radius Left
1303
1303
  * @see https://tailwindcss.com/docs/border-radius
1304
1304
  */
1305
1305
  "rounded-l": [{
1306
- "rounded-l": [o]
1306
+ "rounded-l": [s]
1307
1307
  }],
1308
1308
  /**
1309
1309
  * Border Radius Start Start
1310
1310
  * @see https://tailwindcss.com/docs/border-radius
1311
1311
  */
1312
1312
  "rounded-ss": [{
1313
- "rounded-ss": [o]
1313
+ "rounded-ss": [s]
1314
1314
  }],
1315
1315
  /**
1316
1316
  * Border Radius Start End
1317
1317
  * @see https://tailwindcss.com/docs/border-radius
1318
1318
  */
1319
1319
  "rounded-se": [{
1320
- "rounded-se": [o]
1320
+ "rounded-se": [s]
1321
1321
  }],
1322
1322
  /**
1323
1323
  * Border Radius End End
1324
1324
  * @see https://tailwindcss.com/docs/border-radius
1325
1325
  */
1326
1326
  "rounded-ee": [{
1327
- "rounded-ee": [o]
1327
+ "rounded-ee": [s]
1328
1328
  }],
1329
1329
  /**
1330
1330
  * Border Radius End Start
1331
1331
  * @see https://tailwindcss.com/docs/border-radius
1332
1332
  */
1333
1333
  "rounded-es": [{
1334
- "rounded-es": [o]
1334
+ "rounded-es": [s]
1335
1335
  }],
1336
1336
  /**
1337
1337
  * Border Radius Top Left
1338
1338
  * @see https://tailwindcss.com/docs/border-radius
1339
1339
  */
1340
1340
  "rounded-tl": [{
1341
- "rounded-tl": [o]
1341
+ "rounded-tl": [s]
1342
1342
  }],
1343
1343
  /**
1344
1344
  * Border Radius Top Right
1345
1345
  * @see https://tailwindcss.com/docs/border-radius
1346
1346
  */
1347
1347
  "rounded-tr": [{
1348
- "rounded-tr": [o]
1348
+ "rounded-tr": [s]
1349
1349
  }],
1350
1350
  /**
1351
1351
  * Border Radius Bottom Right
1352
1352
  * @see https://tailwindcss.com/docs/border-radius
1353
1353
  */
1354
1354
  "rounded-br": [{
1355
- "rounded-br": [o]
1355
+ "rounded-br": [s]
1356
1356
  }],
1357
1357
  /**
1358
1358
  * Border Radius Bottom Left
1359
1359
  * @see https://tailwindcss.com/docs/border-radius
1360
1360
  */
1361
1361
  "rounded-bl": [{
1362
- "rounded-bl": [o]
1362
+ "rounded-bl": [s]
1363
1363
  }],
1364
1364
  /**
1365
1365
  * Border Width
@@ -1481,70 +1481,70 @@ const ne = (e) => {
1481
1481
  * @see https://tailwindcss.com/docs/border-color
1482
1482
  */
1483
1483
  "border-color": [{
1484
- border: [s]
1484
+ border: [o]
1485
1485
  }],
1486
1486
  /**
1487
1487
  * Border Color X
1488
1488
  * @see https://tailwindcss.com/docs/border-color
1489
1489
  */
1490
1490
  "border-color-x": [{
1491
- "border-x": [s]
1491
+ "border-x": [o]
1492
1492
  }],
1493
1493
  /**
1494
1494
  * Border Color Y
1495
1495
  * @see https://tailwindcss.com/docs/border-color
1496
1496
  */
1497
1497
  "border-color-y": [{
1498
- "border-y": [s]
1498
+ "border-y": [o]
1499
1499
  }],
1500
1500
  /**
1501
1501
  * Border Color S
1502
1502
  * @see https://tailwindcss.com/docs/border-color
1503
1503
  */
1504
1504
  "border-color-s": [{
1505
- "border-s": [s]
1505
+ "border-s": [o]
1506
1506
  }],
1507
1507
  /**
1508
1508
  * Border Color E
1509
1509
  * @see https://tailwindcss.com/docs/border-color
1510
1510
  */
1511
1511
  "border-color-e": [{
1512
- "border-e": [s]
1512
+ "border-e": [o]
1513
1513
  }],
1514
1514
  /**
1515
1515
  * Border Color Top
1516
1516
  * @see https://tailwindcss.com/docs/border-color
1517
1517
  */
1518
1518
  "border-color-t": [{
1519
- "border-t": [s]
1519
+ "border-t": [o]
1520
1520
  }],
1521
1521
  /**
1522
1522
  * Border Color Right
1523
1523
  * @see https://tailwindcss.com/docs/border-color
1524
1524
  */
1525
1525
  "border-color-r": [{
1526
- "border-r": [s]
1526
+ "border-r": [o]
1527
1527
  }],
1528
1528
  /**
1529
1529
  * Border Color Bottom
1530
1530
  * @see https://tailwindcss.com/docs/border-color
1531
1531
  */
1532
1532
  "border-color-b": [{
1533
- "border-b": [s]
1533
+ "border-b": [o]
1534
1534
  }],
1535
1535
  /**
1536
1536
  * Border Color Left
1537
1537
  * @see https://tailwindcss.com/docs/border-color
1538
1538
  */
1539
1539
  "border-color-l": [{
1540
- "border-l": [s]
1540
+ "border-l": [o]
1541
1541
  }],
1542
1542
  /**
1543
1543
  * Divide Color
1544
1544
  * @see https://tailwindcss.com/docs/divide-color
1545
1545
  */
1546
1546
  "divide-color": [{
1547
- divide: [s]
1547
+ divide: [o]
1548
1548
  }],
1549
1549
  /**
1550
1550
  * Outline Style
@@ -1579,7 +1579,7 @@ const ne = (e) => {
1579
1579
  * @see https://tailwindcss.com/docs/ring-width
1580
1580
  */
1581
1581
  "ring-w": [{
1582
- ring: Q()
1582
+ ring: Y()
1583
1583
  }],
1584
1584
  /**
1585
1585
  * Ring Width Inset
@@ -1641,14 +1641,14 @@ const ne = (e) => {
1641
1641
  * @see https://tailwindcss.com/docs/mix-blend-mode
1642
1642
  */
1643
1643
  "mix-blend": [{
1644
- "mix-blend": [...se(), "plus-lighter", "plus-darker"]
1644
+ "mix-blend": [...oe(), "plus-lighter", "plus-darker"]
1645
1645
  }],
1646
1646
  /**
1647
1647
  * Background Blend Mode
1648
1648
  * @see https://tailwindcss.com/docs/background-blend-mode
1649
1649
  */
1650
1650
  "bg-blend": [{
1651
- "bg-blend": se()
1651
+ "bg-blend": oe()
1652
1652
  }],
1653
1653
  // Filters
1654
1654
  /**
@@ -1849,7 +1849,7 @@ const ne = (e) => {
1849
1849
  * @see https://tailwindcss.com/docs/transition-duration
1850
1850
  */
1851
1851
  duration: [{
1852
- duration: K()
1852
+ duration: H()
1853
1853
  }],
1854
1854
  /**
1855
1855
  * Transition Timing Function
@@ -1863,7 +1863,7 @@ const ne = (e) => {
1863
1863
  * @see https://tailwindcss.com/docs/transition-delay
1864
1864
  */
1865
1865
  delay: [{
1866
- delay: K()
1866
+ delay: H()
1867
1867
  }],
1868
1868
  /**
1869
1869
  * Animation
@@ -1998,126 +1998,126 @@ const ne = (e) => {
1998
1998
  * @see https://tailwindcss.com/docs/scroll-margin
1999
1999
  */
2000
2000
  "scroll-m": [{
2001
- "scroll-m": M()
2001
+ "scroll-m": E()
2002
2002
  }],
2003
2003
  /**
2004
2004
  * Scroll Margin X
2005
2005
  * @see https://tailwindcss.com/docs/scroll-margin
2006
2006
  */
2007
2007
  "scroll-mx": [{
2008
- "scroll-mx": M()
2008
+ "scroll-mx": E()
2009
2009
  }],
2010
2010
  /**
2011
2011
  * Scroll Margin Y
2012
2012
  * @see https://tailwindcss.com/docs/scroll-margin
2013
2013
  */
2014
2014
  "scroll-my": [{
2015
- "scroll-my": M()
2015
+ "scroll-my": E()
2016
2016
  }],
2017
2017
  /**
2018
2018
  * Scroll Margin Start
2019
2019
  * @see https://tailwindcss.com/docs/scroll-margin
2020
2020
  */
2021
2021
  "scroll-ms": [{
2022
- "scroll-ms": M()
2022
+ "scroll-ms": E()
2023
2023
  }],
2024
2024
  /**
2025
2025
  * Scroll Margin End
2026
2026
  * @see https://tailwindcss.com/docs/scroll-margin
2027
2027
  */
2028
2028
  "scroll-me": [{
2029
- "scroll-me": M()
2029
+ "scroll-me": E()
2030
2030
  }],
2031
2031
  /**
2032
2032
  * Scroll Margin Top
2033
2033
  * @see https://tailwindcss.com/docs/scroll-margin
2034
2034
  */
2035
2035
  "scroll-mt": [{
2036
- "scroll-mt": M()
2036
+ "scroll-mt": E()
2037
2037
  }],
2038
2038
  /**
2039
2039
  * Scroll Margin Right
2040
2040
  * @see https://tailwindcss.com/docs/scroll-margin
2041
2041
  */
2042
2042
  "scroll-mr": [{
2043
- "scroll-mr": M()
2043
+ "scroll-mr": E()
2044
2044
  }],
2045
2045
  /**
2046
2046
  * Scroll Margin Bottom
2047
2047
  * @see https://tailwindcss.com/docs/scroll-margin
2048
2048
  */
2049
2049
  "scroll-mb": [{
2050
- "scroll-mb": M()
2050
+ "scroll-mb": E()
2051
2051
  }],
2052
2052
  /**
2053
2053
  * Scroll Margin Left
2054
2054
  * @see https://tailwindcss.com/docs/scroll-margin
2055
2055
  */
2056
2056
  "scroll-ml": [{
2057
- "scroll-ml": M()
2057
+ "scroll-ml": E()
2058
2058
  }],
2059
2059
  /**
2060
2060
  * Scroll Padding
2061
2061
  * @see https://tailwindcss.com/docs/scroll-padding
2062
2062
  */
2063
2063
  "scroll-p": [{
2064
- "scroll-p": M()
2064
+ "scroll-p": E()
2065
2065
  }],
2066
2066
  /**
2067
2067
  * Scroll Padding X
2068
2068
  * @see https://tailwindcss.com/docs/scroll-padding
2069
2069
  */
2070
2070
  "scroll-px": [{
2071
- "scroll-px": M()
2071
+ "scroll-px": E()
2072
2072
  }],
2073
2073
  /**
2074
2074
  * Scroll Padding Y
2075
2075
  * @see https://tailwindcss.com/docs/scroll-padding
2076
2076
  */
2077
2077
  "scroll-py": [{
2078
- "scroll-py": M()
2078
+ "scroll-py": E()
2079
2079
  }],
2080
2080
  /**
2081
2081
  * Scroll Padding Start
2082
2082
  * @see https://tailwindcss.com/docs/scroll-padding
2083
2083
  */
2084
2084
  "scroll-ps": [{
2085
- "scroll-ps": M()
2085
+ "scroll-ps": E()
2086
2086
  }],
2087
2087
  /**
2088
2088
  * Scroll Padding End
2089
2089
  * @see https://tailwindcss.com/docs/scroll-padding
2090
2090
  */
2091
2091
  "scroll-pe": [{
2092
- "scroll-pe": M()
2092
+ "scroll-pe": E()
2093
2093
  }],
2094
2094
  /**
2095
2095
  * Scroll Padding Top
2096
2096
  * @see https://tailwindcss.com/docs/scroll-padding
2097
2097
  */
2098
2098
  "scroll-pt": [{
2099
- "scroll-pt": M()
2099
+ "scroll-pt": E()
2100
2100
  }],
2101
2101
  /**
2102
2102
  * Scroll Padding Right
2103
2103
  * @see https://tailwindcss.com/docs/scroll-padding
2104
2104
  */
2105
2105
  "scroll-pr": [{
2106
- "scroll-pr": M()
2106
+ "scroll-pr": E()
2107
2107
  }],
2108
2108
  /**
2109
2109
  * Scroll Padding Bottom
2110
2110
  * @see https://tailwindcss.com/docs/scroll-padding
2111
2111
  */
2112
2112
  "scroll-pb": [{
2113
- "scroll-pb": M()
2113
+ "scroll-pb": E()
2114
2114
  }],
2115
2115
  /**
2116
2116
  * Scroll Padding Left
2117
2117
  * @see https://tailwindcss.com/docs/scroll-padding
2118
2118
  */
2119
2119
  "scroll-pl": [{
2120
- "scroll-pl": M()
2120
+ "scroll-pl": E()
2121
2121
  }],
2122
2122
  /**
2123
2123
  * Scroll Snap Align
@@ -2276,21 +2276,21 @@ const ne = (e) => {
2276
2276
  }
2277
2277
  };
2278
2278
  }, hr = /* @__PURE__ */ Qn(mr);
2279
- function Vs(...e) {
2279
+ function Ko(...e) {
2280
2280
  return hr(jn(e));
2281
2281
  }
2282
2282
  function yr(e) {
2283
2283
  let t = !1, n = "";
2284
- for (const s of e) {
2285
- if (s === "\\") {
2286
- n += s, t = !t;
2284
+ for (const o of e) {
2285
+ if (o === "\\") {
2286
+ n += o, t = !t;
2287
2287
  continue;
2288
2288
  }
2289
- if (s === "'" && !t) {
2289
+ if (o === "'" && !t) {
2290
2290
  n += '"';
2291
2291
  continue;
2292
2292
  }
2293
- n += s, t = !1;
2293
+ n += o, t = !1;
2294
2294
  }
2295
2295
  return n.replace(/\bTrue\b/g, "true").replace(/\bFalse\b/g, "false").replace(/\bNone\b/g, "null");
2296
2296
  }
@@ -2316,10 +2316,10 @@ function br(e) {
2316
2316
  function wr(e) {
2317
2317
  return e.type === "image_url";
2318
2318
  }
2319
- function kr(e) {
2319
+ function Ir(e) {
2320
2320
  return e.type === "file";
2321
2321
  }
2322
- function Ir(e) {
2322
+ function kr(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
  }
@@ -2327,7 +2327,7 @@ function vr(e) {
2327
2327
  return e.content.filter(wr);
2328
2328
  }
2329
2329
  function Tr(e) {
2330
- return e.content.filter(kr);
2330
+ return e.content.filter(Ir);
2331
2331
  }
2332
2332
  function ln(e) {
2333
2333
  return Array.isArray(e.toolCalls) ? e.toolCalls : [];
@@ -2372,8 +2372,8 @@ function ht(e) {
2372
2372
  if (n === "data" && typeof r == "string" && r.length > 100)
2373
2373
  t[n] = `[base64 ${r.length} chars omitted]`;
2374
2374
  else {
2375
- const s = ht(r);
2376
- s !== void 0 && (t[n] = s);
2375
+ const o = ht(r);
2376
+ o !== void 0 && (t[n] = o);
2377
2377
  }
2378
2378
  }
2379
2379
  if (Object.keys(t).length)
@@ -2397,15 +2397,15 @@ function dn(e) {
2397
2397
  return "";
2398
2398
  }
2399
2399
  }
2400
- function Ks(e) {
2400
+ function Ho(e) {
2401
2401
  const t = dn(e);
2402
2402
  return typeof e == "string" && br(e) ? { content: e, isMarkdown: !0 } : { content: t, isMarkdown: !1 };
2403
2403
  }
2404
2404
  function Sr(e) {
2405
2405
  const t = (r) => {
2406
2406
  try {
2407
- const s = ht(r);
2408
- return typeof s == "string" ? s : JSON.stringify(s ?? "");
2407
+ const o = ht(r);
2408
+ return typeof o == "string" ? o : JSON.stringify(o ?? "");
2409
2409
  } catch {
2410
2410
  return "";
2411
2411
  }
@@ -2413,7 +2413,7 @@ function Sr(e) {
2413
2413
  return n.length ? t(n.map((r) => r.text).join(`
2414
2414
  `)) : t(e);
2415
2415
  }
2416
- function Hs(e) {
2416
+ function qo(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
2419
  function Ee(e) {
@@ -2453,12 +2453,12 @@ function yt(e) {
2453
2453
  const t = Pe(e), n = Er(t);
2454
2454
  if (!n)
2455
2455
  return null;
2456
- const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(Ut) : void 0, s = Mr(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 ?? ((v = t.additionalKwargs) == null ? void 0 : v.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, u = t.responseMetadata ?? void 0, g = t.checkpointId ?? ((x = t.additionalKwargs) == null ? void 0 : x.checkpointId) ?? void 0, m = t.checkpointNs ?? ((L = t.additionalKwargs) == null ? void 0 : L.checkpointNs) ?? void 0, k = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((z = t.additionalKwargs) != null && z.toolStreaming);
2456
+ const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(Ut) : void 0, o = Mr(t.content ?? t.parts, !!(r != null && r.length)), s = 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 ?? ((v = t.additionalKwargs) == null ? void 0 : v.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, u = t.responseMetadata ?? void 0, g = t.checkpointId ?? ((x = t.additionalKwargs) == null ? void 0 : x.checkpointId) ?? void 0, m = t.checkpointNs ?? ((L = t.additionalKwargs) == null ? void 0 : L.checkpointNs) ?? void 0, I = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((z = t.additionalKwargs) != null && z.toolStreaming);
2457
2457
  return {
2458
2458
  ...t,
2459
- id: o,
2459
+ id: s,
2460
2460
  role: n,
2461
- content: s,
2461
+ content: o,
2462
2462
  createdAt: a,
2463
2463
  name: i,
2464
2464
  model: f,
@@ -2466,7 +2466,7 @@ function yt(e) {
2466
2466
  toolCalls: r,
2467
2467
  checkpointId: g,
2468
2468
  checkpointNs: m,
2469
- toolStreaming: k,
2469
+ toolStreaming: I,
2470
2470
  additionalKwargs: c,
2471
2471
  responseMetadata: u,
2472
2472
  artifact: t.artifact ?? void 0
@@ -2522,11 +2522,11 @@ function Pr(e, t) {
2522
2522
  if (!n) return;
2523
2523
  const r = typeof n == "string" ? n : dn(n);
2524
2524
  if (!r.trim()) return;
2525
- const s = [{ type: "text", text: r }];
2525
+ const o = [{ type: "text", text: r }];
2526
2526
  return {
2527
2527
  id: `tool-${t.id}`,
2528
2528
  role: "tool",
2529
- content: s,
2529
+ content: o,
2530
2530
  name: t.name,
2531
2531
  toolCallId: t.id,
2532
2532
  artifact: t.artifact,
@@ -2535,13 +2535,13 @@ function Pr(e, t) {
2535
2535
  }
2536
2536
  function Nr(e, t = []) {
2537
2537
  if (Array.isArray(e)) {
2538
- const s = e.filter((a) => a.role === "assistant").flatMap((a) => qt(a)), o = /* @__PURE__ */ new Map();
2539
- return s.forEach((a) => o.set(a.id, a)), Array.from(o.values()).map((a) => {
2538
+ const o = e.filter((a) => a.role === "assistant").flatMap((a) => qt(a)), s = /* @__PURE__ */ new Map();
2539
+ return o.forEach((a) => s.set(a.id, a)), Array.from(s.values()).map((a) => {
2540
2540
  var u, g, m;
2541
2541
  const i = Ct(a.id, e) || Ct(a.id, t), f = Array.isArray((u = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : u.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 = Ht(a.status) ?? ((m = i == null ? void 0 : i.additionalKwargs) != null && m.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2542
2542
  if (i && !a.content && c === "completed") {
2543
- const k = Ee(i);
2544
- typeof k == "string" && (a.content = k);
2543
+ const I = Ee(i);
2544
+ typeof I == "string" && (a.content = I);
2545
2545
  }
2546
2546
  return {
2547
2547
  call: a,
@@ -2556,21 +2556,21 @@ function Nr(e, t = []) {
2556
2556
  const n = qt(e);
2557
2557
  return n.length === 0 ? [] : n.map((r) => {
2558
2558
  var f, l, c;
2559
- const s = Ct(r.id, t) ?? Pr(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 = Ht(r.status) ?? ((c = s == null ? void 0 : s.additionalKwargs) != null && c.toolStreaming ? "pending" : null) ?? (s ? "completed" : "pending");
2560
- if (s && !r.content && i === "completed") {
2561
- const u = Ee(s);
2559
+ const o = Ct(r.id, t) ?? Pr(e, r), s = Array.isArray((f = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : f.toolProgress) ? (l = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : l.toolProgress : void 0, a = (o == null ? void 0 : o.artifact) ?? r.artifact, i = Ht(r.status) ?? ((c = o == null ? void 0 : o.additionalKwargs) != null && c.toolStreaming ? "pending" : null) ?? (o ? "completed" : "pending");
2560
+ if (o && !r.content && i === "completed") {
2561
+ const u = Ee(o);
2562
2562
  typeof u == "string" && (r.content = u);
2563
2563
  }
2564
2564
  return {
2565
2565
  call: r,
2566
- result: s,
2566
+ result: o,
2567
2567
  state: i,
2568
- progress: o,
2568
+ progress: s,
2569
2569
  artifact: a
2570
2570
  };
2571
2571
  });
2572
2572
  }
2573
- function qs(e, t = []) {
2573
+ function Wo(e, t = []) {
2574
2574
  return Nr(e, t).map((n) => n.artifact).filter((n) => !!n);
2575
2575
  }
2576
2576
  const tt = {
@@ -2598,7 +2598,7 @@ function pn(e) {
2598
2598
  }
2599
2599
  const Rr = 12e4, _r = 12e4;
2600
2600
  let _t = Rr, gn = _r;
2601
- const he = Un.create({
2601
+ const we = Un.create({
2602
2602
  // BaseURL is set dynamically via ApiProvider -> api.updateConfig
2603
2603
  timeout: _t,
2604
2604
  withCredentials: !0
@@ -2608,20 +2608,20 @@ function Wt(e) {
2608
2608
  }
2609
2609
  function Lr(e) {
2610
2610
  const t = Wt(e.requestTimeoutMs), n = Wt(e.historyTimeoutMs);
2611
- t !== null && (_t = t, he.defaults.timeout = _t), n !== null && (gn = n);
2611
+ t !== null && (_t = t, we.defaults.timeout = _t), n !== null && (gn = n);
2612
2612
  }
2613
2613
  function zr() {
2614
2614
  return gn;
2615
2615
  }
2616
- he.interceptors.request.use((e) => (bt && (e.headers.Authorization = `Bearer ${bt}`), e));
2617
- he.interceptors.response.use(
2616
+ we.interceptors.request.use((e) => (bt && (e.headers.Authorization = `Bearer ${bt}`), e));
2617
+ we.interceptors.response.use(
2618
2618
  (e) => {
2619
2619
  if (typeof window < "u" && (e != null && e.data))
2620
2620
  try {
2621
- const t = e.data, n = t.data || {}, r = typeof t.token == "string" && t.token || typeof n.token == "string" && n.token || null, s = typeof t.expires_at == "number" && t.expires_at || typeof n.expires_at == "number" && n.expires_at || typeof t.expiresAt == "number" && t.expiresAt || typeof n.expiresAt == "number" && n.expiresAt || null;
2622
- r && (localStorage.setItem(tt.authToken, r), Ve(r)), s && localStorage.setItem(tt.authTokenExpiresAt, s.toString()), (r || s) && window.dispatchEvent(
2621
+ const t = e.data, n = t.data || {}, r = typeof t.token == "string" && t.token || typeof n.token == "string" && n.token || null, o = typeof t.expires_at == "number" && t.expires_at || typeof n.expires_at == "number" && n.expires_at || typeof t.expiresAt == "number" && t.expiresAt || typeof n.expiresAt == "number" && n.expiresAt || null;
2622
+ r && (localStorage.setItem(tt.authToken, r), Ve(r)), o && localStorage.setItem(tt.authTokenExpiresAt, o.toString()), (r || o) && window.dispatchEvent(
2623
2623
  new CustomEvent("smartorg:chat-token-updated", {
2624
- detail: { token: r, expiresAt: s }
2624
+ detail: { token: r, expiresAt: o }
2625
2625
  })
2626
2626
  );
2627
2627
  } catch (t) {
@@ -2632,16 +2632,16 @@ he.interceptors.response.use(
2632
2632
  (e) => Promise.reject(e)
2633
2633
  );
2634
2634
  async function ke(e, t) {
2635
- return he.defaults.baseURL ? (await he.get(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2635
+ return we.defaults.baseURL ? (await we.get(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2636
2636
  }
2637
2637
  async function dt(e, t, n) {
2638
- return he.defaults.baseURL ? (await he.post(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2638
+ return we.defaults.baseURL ? (await we.post(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2639
2639
  }
2640
2640
  async function Fr(e, t, n) {
2641
- return he.defaults.baseURL ? (await he.put(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2641
+ return we.defaults.baseURL ? (await we.put(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2642
2642
  }
2643
2643
  async function Gt(e, t) {
2644
- return he.defaults.baseURL ? (await he.delete(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2644
+ return we.defaults.baseURL ? (await we.delete(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2645
2645
  }
2646
2646
  function be(e) {
2647
2647
  return e && typeof e == "object" && "data" in e ? e.data : e;
@@ -2651,14 +2651,14 @@ class Ur {
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.
2653
2653
  get baseUrl() {
2654
- return he.defaults.baseURL || "";
2654
+ return we.defaults.baseURL || "";
2655
2655
  }
2656
2656
  updateConfig(t) {
2657
2657
  if (t.chatBaseUrl)
2658
- he.defaults.baseURL = t.chatBaseUrl;
2658
+ we.defaults.baseURL = t.chatBaseUrl;
2659
2659
  else if (t.baseUrl) {
2660
2660
  const n = t.baseUrl.replace(/\/+$/, "");
2661
- n.endsWith("/chat") ? he.defaults.baseURL = n : he.defaults.baseURL = `${n}/chat`;
2661
+ we.defaults.baseURL = n;
2662
2662
  }
2663
2663
  t.apiKey !== void 0 ? Ve(t.apiKey) : t.getToken && Ve(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Lr({
2664
2664
  requestTimeoutMs: t.requestTimeoutMs,
@@ -2688,8 +2688,8 @@ class Ur {
2688
2688
  async createThread(t, n) {
2689
2689
  const r = {};
2690
2690
  t && (r.title = t), n && (r.project = n);
2691
- const s = await dt("/threads", Object.keys(r).length ? r : void 0);
2692
- return be(s);
2691
+ const o = await dt("/threads", Object.keys(r).length ? r : void 0);
2692
+ return be(o);
2693
2693
  }
2694
2694
  async updateThread(t, n) {
2695
2695
  const r = await Fr(`/threads/${t}`, { title: n });
@@ -2747,7 +2747,7 @@ class Ur {
2747
2747
  }
2748
2748
  // ---- Run Management ----
2749
2749
  async cancelRun(t) {
2750
- const n = await dt("/stream/cancel", { threadId: t });
2750
+ const n = await dt(`/runs/${t}/cancel`);
2751
2751
  return be(n);
2752
2752
  }
2753
2753
  async unshareThread(t, n) {
@@ -2762,11 +2762,11 @@ class jr {
2762
2762
  async fetchFileBlob(t, n) {
2763
2763
  return await ke(t, {
2764
2764
  responseType: "blob",
2765
- onDownloadProgress: (s) => {
2765
+ onDownloadProgress: (o) => {
2766
2766
  try {
2767
- if (n && s.lengthComputable) {
2768
- const o = s.loaded / s.total;
2769
- n(o);
2767
+ if (n && o.lengthComputable) {
2768
+ const s = o.loaded / o.total;
2769
+ n(s);
2770
2770
  }
2771
2771
  } catch {
2772
2772
  }
@@ -2776,8 +2776,8 @@ class jr {
2776
2776
  });
2777
2777
  }
2778
2778
  async viewFileById(t, n) {
2779
- const r = await this.fetchFileBlob(`/files/${t}/view`, n), s = URL.createObjectURL(r);
2780
- window.open(s, "_blank"), setTimeout(() => URL.revokeObjectURL(s), 6e4);
2779
+ const r = await this.fetchFileBlob(`/files/${t}/view`, n), o = URL.createObjectURL(r);
2780
+ window.open(o, "_blank"), setTimeout(() => URL.revokeObjectURL(o), 6e4);
2781
2781
  }
2782
2782
  async getFileBlob(t, n) {
2783
2783
  return await this.fetchFileBlob(`/files/${t}/view`, n);
@@ -2786,30 +2786,30 @@ class jr {
2786
2786
  return await (await this.fetchFileBlob(`/files/${t}/view`, n)).text();
2787
2787
  }
2788
2788
  async downloadFileById(t, n) {
2789
- const r = await this.fetchFileBlob(`/files/${t}/download`, n), s = URL.createObjectURL(r);
2790
- let o = `file_${t}`;
2789
+ const r = await this.fetchFileBlob(`/files/${t}/download`, n), o = URL.createObjectURL(r);
2790
+ let s = `file_${t}`;
2791
2791
  try {
2792
2792
  const i = await ke(`/files/${t}`);
2793
- o = (i == null ? void 0 : i.filename) ?? o;
2793
+ s = (i == null ? void 0 : i.filename) ?? s;
2794
2794
  } catch {
2795
2795
  }
2796
2796
  const a = document.createElement("a");
2797
- a.href = s, a.download = o, document.body.appendChild(a), a.click(), a.remove(), setTimeout(() => URL.revokeObjectURL(s), 6e4);
2797
+ a.href = o, a.download = s, document.body.appendChild(a), a.click(), a.remove(), setTimeout(() => URL.revokeObjectURL(o), 6e4);
2798
2798
  }
2799
2799
  async getFileInfo(t) {
2800
2800
  return await ke(`/files/${t}`);
2801
2801
  }
2802
2802
  async listFiles(t, n = 50, r = 0) {
2803
- const s = { limit: n, offset: r };
2804
- return t && (s.thread_id = t), await ke("/files", { params: s });
2803
+ const o = { limit: n, offset: r };
2804
+ return t && (o.thread_id = t), await ke("/files", { params: o });
2805
2805
  }
2806
2806
  async uploadFile(t, n, r) {
2807
- const s = new FormData();
2808
- return s.append("file", t), n && s.append("thread_id", n), await dt("/files/upload-form", s, {
2809
- onUploadProgress: (o) => {
2807
+ const o = new FormData();
2808
+ return o.append("file", t), n && o.append("thread_id", n), await dt("/files/upload-form", o, {
2809
+ onUploadProgress: (s) => {
2810
2810
  try {
2811
- if (r && o.lengthComputable) {
2812
- const a = o.loaded / o.total;
2811
+ if (r && s.lengthComputable) {
2812
+ const a = s.loaded / s.total;
2813
2813
  r(a);
2814
2814
  }
2815
2815
  } catch {
@@ -2856,53 +2856,53 @@ const $r = new Or(), yn = Ge(null);
2856
2856
  function Br({ children: e, apiConfig: t }) {
2857
2857
  const n = mn, r = $r;
2858
2858
  if (t) {
2859
- const o = n.baseUrl, a = r.baseUrl, i = n.getAuthToken(), f = t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0;
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 }));
2859
+ const s = n.baseUrl, a = r.baseUrl, i = n.getAuthToken(), f = t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0;
2860
+ (t.baseUrl || t.chatBaseUrl || f) && (f || t.chatBaseUrl && t.chatBaseUrl !== s || t.baseUrl && !s.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 }));
2861
2861
  }
2862
- const s = {
2862
+ const o = {
2863
2863
  token: n.getAuthToken(),
2864
- setToken: (o) => {
2865
- n.setAuthToken(o), r.setAuthToken(o);
2864
+ setToken: (s) => {
2865
+ n.setAuthToken(s), r.setAuthToken(s);
2866
2866
  },
2867
2867
  chatApi: n,
2868
2868
  authApi: r,
2869
2869
  fileApi: hn,
2870
2870
  baseUrl: n.baseUrl
2871
2871
  };
2872
- return /* @__PURE__ */ Ce(yn.Provider, { value: s, children: e });
2872
+ return /* @__PURE__ */ Ce(yn.Provider, { value: o, children: e });
2873
2873
  }
2874
2874
  async function Dr(e) {
2875
2875
  return await new Promise((t, n) => {
2876
2876
  const r = new FileReader();
2877
2877
  r.onload = () => {
2878
2878
  try {
2879
- const s = r.result, o = new Uint8Array(s);
2879
+ const o = r.result, s = new Uint8Array(o);
2880
2880
  let a = "";
2881
- const i = o.byteLength;
2882
- for (let f = 0; f < i; f++) a += String.fromCharCode(o[f]);
2881
+ const i = s.byteLength;
2882
+ for (let f = 0; f < i; f++) a += String.fromCharCode(s[f]);
2883
2883
  t(btoa(a));
2884
- } catch (s) {
2885
- n(s);
2884
+ } catch (o) {
2885
+ n(o);
2886
2886
  }
2887
- }, r.onerror = (s) => n(s), r.readAsArrayBuffer(e);
2887
+ }, r.onerror = (o) => n(o), r.readAsArrayBuffer(e);
2888
2888
  });
2889
2889
  }
2890
2890
  async function Vr(e = []) {
2891
2891
  const t = [], n = [];
2892
2892
  for (const r of e)
2893
2893
  try {
2894
- const s = await Dr(r), o = r.type || "application/octet-stream";
2894
+ const o = await Dr(r), s = r.type || "application/octet-stream";
2895
2895
  n.push({
2896
2896
  filename: r.name,
2897
- data: s,
2898
- mime_type: o
2899
- }), o.startsWith("image/") ? t.push({
2897
+ data: o,
2898
+ mime_type: s
2899
+ }), s.startsWith("image/") ? t.push({
2900
2900
  type: "image_url",
2901
- image_url: { url: `data:${o};base64,${s}` }
2901
+ image_url: { url: `data:${s};base64,${o}` }
2902
2902
  }) : t.push({
2903
2903
  type: "file",
2904
- url: `data:${o};base64,${s}`,
2905
- mimeType: o,
2904
+ url: `data:${s};base64,${o}`,
2905
+ mimeType: s,
2906
2906
  name: r.name,
2907
2907
  size: r.size
2908
2908
  });
@@ -2913,7 +2913,7 @@ async function Vr(e = []) {
2913
2913
  function Kr(e) {
2914
2914
  return e.filter((t) => t.type === "text").map((t) => t.text).join("");
2915
2915
  }
2916
- function Ws(e) {
2916
+ function Go(e) {
2917
2917
  if (e == null) return null;
2918
2918
  const t = String(e).trim();
2919
2919
  return t.length > 0 ? t : null;
@@ -2925,13 +2925,13 @@ function Hr(e) {
2925
2925
  name: e.name ?? void 0
2926
2926
  };
2927
2927
  }
2928
- function Gs(e) {
2928
+ function Jo(e) {
2929
2929
  var n;
2930
2930
  if (e.name && e.name.trim()) return e.name;
2931
2931
  const t = (n = e.additionalKwargs) == null ? void 0 : n.agentName;
2932
2932
  return typeof t == "string" && t.trim() ? t : e.model && e.model.includes("/") ? e.model.split("/").pop() || null : e.model || null;
2933
2933
  }
2934
- function Js(e) {
2934
+ function Xo(e) {
2935
2935
  const t = e.updatedAt ?? e.createdAt ?? "", n = Array.isArray(e.content) ? e.content.map((a) => {
2936
2936
  switch (a.type) {
2937
2937
  case "text":
@@ -2941,11 +2941,11 @@ function Js(e) {
2941
2941
  default:
2942
2942
  return a.type === "interrupt" ? "interrupt" : "unknown";
2943
2943
  }
2944
- }).join("|") : "", r = "checkpointId" in e && e.checkpointId ? `cp:${e.checkpointId}` : "", s = "checkpointNs" in e && e.checkpointNs ? `ns:${e.checkpointNs}` : "", o = [r, s].filter(Boolean).join("|");
2945
- return `${e.id}:${t}:${n}${o ? `:${o}` : ""}`;
2944
+ }).join("|") : "", r = "checkpointId" in e && e.checkpointId ? `cp:${e.checkpointId}` : "", o = "checkpointNs" in e && e.checkpointNs ? `ns:${e.checkpointNs}` : "", s = [r, o].filter(Boolean).join("|");
2945
+ return `${e.id}:${t}:${n}${s ? `:${s}` : ""}`;
2946
2946
  }
2947
2947
  function We() {
2948
- const e = ot(yn);
2948
+ const e = st(yn);
2949
2949
  if (!e) throw new Error("useApi must be used within ApiProvider");
2950
2950
  return e;
2951
2951
  }
@@ -2991,7 +2991,7 @@ function Jt(e) {
2991
2991
  async function Gr(e, t) {
2992
2992
  var i, f;
2993
2993
  if (!e) return e ?? null;
2994
- const n = Pe(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], s = /* @__PURE__ */ new Set();
2994
+ const n = Pe(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], o = /* @__PURE__ */ new Set();
2995
2995
  for (const l of r) {
2996
2996
  const c = (i = l == null ? void 0 : l.values) == null ? void 0 : i.messages;
2997
2997
  if (Array.isArray(c))
@@ -3000,15 +3000,15 @@ async function Gr(e, t) {
3000
3000
  if (Array.isArray(g))
3001
3001
  for (const m of g) {
3002
3002
  if (!m || typeof m != "object" || m.type !== "image_url" && m.type !== "file") continue;
3003
- const k = m.fileId || m.file_id;
3004
- typeof k == "string" && k.trim() && s.add(k);
3003
+ const I = m.fileId || m.file_id;
3004
+ typeof I == "string" && I.trim() && o.add(I);
3005
3005
  }
3006
3006
  }
3007
3007
  }
3008
- if (s.size === 0)
3008
+ if (o.size === 0)
3009
3009
  return n;
3010
- const o = await Promise.all(
3011
- Array.from(s).map(async (l) => {
3010
+ const s = await Promise.all(
3011
+ Array.from(o).map(async (l) => {
3012
3012
  try {
3013
3013
  const c = await t.getFileInfo(l), u = Pe(c);
3014
3014
  return [l, u];
@@ -3016,7 +3016,7 @@ async function Gr(e, t) {
3016
3016
  return [l, null];
3017
3017
  }
3018
3018
  })
3019
- ), a = new Map(o);
3019
+ ), a = new Map(s);
3020
3020
  for (const l of r) {
3021
3021
  const c = (f = l == null ? void 0 : l.values) == null ? void 0 : f.messages;
3022
3022
  if (Array.isArray(c))
@@ -3025,9 +3025,9 @@ async function Gr(e, t) {
3025
3025
  if (Array.isArray(g))
3026
3026
  for (const m of g) {
3027
3027
  if (!m || typeof m != "object" || m.type !== "image_url" && m.type !== "file") continue;
3028
- const k = m.fileId || m.file_id;
3029
- if (!k) continue;
3030
- const p = a.get(k), y = (p == null ? void 0 : p.contentUrl) || (p == null ? void 0 : p.content_url);
3028
+ const I = m.fileId || m.file_id;
3029
+ if (!I) continue;
3030
+ const p = a.get(I), y = (p == null ? void 0 : p.contentUrl) || (p == null ? void 0 : p.content_url);
3031
3031
  y && (m.type === "image_url" ? (m.imageUrl = m.imageUrl || {}, m.imageUrl.url = y) : m.type === "file" && (m.url = y, !m.name && (p != null && p.filename || p != null && p.name) && (m.name = (p == null ? void 0 : p.filename) || (p == null ? void 0 : p.name))));
3032
3032
  }
3033
3033
  }
@@ -3035,25 +3035,25 @@ async function Gr(e, t) {
3035
3035
  return n;
3036
3036
  }
3037
3037
  function Lt(e) {
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(Pe(o), a)).filter((o) => !!o)].sort((o, a) => Xt(a.createdAt) - Xt(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((s, a) => Jr(Pe(s), a)).filter((s) => !!s)].sort((s, a) => Xt(a.createdAt) - Xt(s.createdAt)), o = r[0] ?? null;
3039
3039
  return {
3040
3040
  threadId: (e == null ? void 0 : e.threadId) ?? "",
3041
- latest: s,
3041
+ latest: o,
3042
3042
  checkpoints: r,
3043
- interrupt: (s == null ? void 0 : s.interrupt) ?? null
3043
+ interrupt: (o == null ? void 0 : o.interrupt) ?? null
3044
3044
  };
3045
3045
  }
3046
3046
  function Jr(e, t) {
3047
3047
  var z, w;
3048
3048
  if (!e) return null;
3049
- const n = ((z = e.values) == null ? void 0 : z.activeAgent) ?? null, r = (w = e.values) == null ? void 0 : w.messages, o = (Array.isArray(r) ? r : []).map((I) => Xr(I, n)).filter((I) => !!I), a = nt(e.metadata) ?? {}, i = Jt(e.config), f = nt(e.parentConfig), l = Jt(f), c = ut(i, ["checkpointId"]), u = ut(i, ["checkpointNs"]), g = ut(l, ["checkpointId"]), m = nt(e.config), k = Array.isArray(e.tasks) ? e.tasks.map((I) => ({ ...I })) : e.tasks ?? null, p = 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(), v = {
3049
+ const n = ((z = e.values) == null ? void 0 : z.activeAgent) ?? null, r = (w = e.values) == null ? void 0 : w.messages, s = (Array.isArray(r) ? r : []).map((k) => Xr(k, n)).filter((k) => !!k), a = nt(e.metadata) ?? {}, i = Jt(e.config), f = nt(e.parentConfig), l = Jt(f), c = ut(i, ["checkpointId"]), u = ut(i, ["checkpointNs"]), g = ut(l, ["checkpointId"]), m = nt(e.config), I = Array.isArray(e.tasks) ? e.tasks.map((k) => ({ ...k })) : e.tasks ?? null, p = 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(), v = {
3050
3050
  ...a,
3051
3051
  step: Wr(a, ["step"]) ?? 0,
3052
3052
  source: ut(a, ["source"]) ?? null
3053
- }, A = o.map((I) => ({
3054
- ...I,
3055
- checkpointId: I.checkpointId ?? c ?? null,
3056
- checkpointNs: I.checkpointNs ?? u ?? null
3053
+ }, A = s.map((k) => ({
3054
+ ...k,
3055
+ checkpointId: k.checkpointId ?? c ?? null,
3056
+ checkpointNs: k.checkpointNs ?? u ?? null
3057
3057
  })), x = e.values, L = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(x == null ? void 0 : x.interrupts) ? x.interrupts : [];
3058
3058
  return {
3059
3059
  checkpointId: c ?? null,
@@ -3070,7 +3070,7 @@ function Jr(e, t) {
3070
3070
  config: m ?? null,
3071
3071
  parentConfig: f ?? null,
3072
3072
  next: p,
3073
- tasks: k,
3073
+ tasks: I,
3074
3074
  values: e.values ?? {}
3075
3075
  };
3076
3076
  }
@@ -3080,15 +3080,15 @@ function Xr(e, t) {
3080
3080
  }
3081
3081
  function Qr(e, t, n) {
3082
3082
  const r = e.length;
3083
- for (let s = r - 1; s >= 0; s -= 1) {
3084
- const o = e[s];
3085
- if (!o || typeof o != "object")
3083
+ for (let o = r - 1; o >= 0; o -= 1) {
3084
+ const s = e[o];
3085
+ if (!s || typeof s != "object")
3086
3086
  continue;
3087
- const a = o, i = a.value ?? o;
3087
+ const a = s, i = a.value ?? s;
3088
3088
  if (i == null)
3089
3089
  continue;
3090
3090
  return {
3091
- id: typeof a.id == "string" && a.id.trim() ? a.id : `interrupt-${n ?? t}-${s}`,
3091
+ id: typeof a.id == "string" && a.id.trim() ? a.id : `interrupt-${n ?? t}-${o}`,
3092
3092
  value: i
3093
3093
  };
3094
3094
  }
@@ -3103,57 +3103,57 @@ function Yr(e) {
3103
3103
  return !!e && typeof e == "object" && "data" in e;
3104
3104
  }
3105
3105
  function Zr(e = {}) {
3106
- const t = e.baseUrl || "", n = e.streamPath ?? "/stream", [r, s] = q(e.token ?? null), o = V(e.headers ?? {}), a = e.credentials ?? "include", i = V(e);
3107
- oe(() => {
3106
+ const t = e.baseUrl || "", n = e.streamPath ?? "/runs/stream", [r, o] = q(e.token ?? null), s = K(e.headers ?? {}), a = e.credentials ?? "include", i = K(e);
3107
+ se(() => {
3108
3108
  i.current = e;
3109
3109
  }, [e]);
3110
3110
  const f = C((T) => {
3111
- var h, U, H, Y, N, ae, W, Z, X, Ie;
3112
- const P = i.current;
3113
- if (!P) return;
3111
+ var h, U, B, G, N, ae, X, Z, Q, ve;
3112
+ const M = i.current;
3113
+ if (!M) return;
3114
3114
  if (T.type === "thread_info") {
3115
- (h = P.onThreadInfo) == null || h.call(P, T);
3115
+ (h = M.onThreadInfo) == null || h.call(M, T);
3116
3116
  return;
3117
3117
  }
3118
3118
  if (T.type === "values" && Array.isArray(T.checkpoints)) {
3119
- (U = P.handleValuesEvent) == null || U.call(P, T);
3119
+ (U = M.handleValuesEvent) == null || U.call(M, T);
3120
3120
  return;
3121
3121
  }
3122
3122
  if (T.type === "metadata") {
3123
- (H = P.onMetadataEvent) == null || H.call(P, T);
3123
+ (B = M.onMetadataEvent) == null || B.call(M, T);
3124
3124
  return;
3125
3125
  }
3126
3126
  if (typeof T.type == "string" && (T.type === "custom" || T.type.startsWith("custom."))) {
3127
- (Y = P.onCustomEvent) == null || Y.call(P, T);
3127
+ (G = M.onCustomEvent) == null || G.call(M, T);
3128
3128
  return;
3129
3129
  }
3130
- (N = P.onEvent) == null || N.call(P, T), T.type === "updates" && ((ae = P.onUpdateEvent) == null || ae.call(P, T)), T.type === "tool.end" ? (W = P.onToolEnd) == null || W.call(P, T) : T.type === "tool.start" && ((Z = P.onToolStart) == null || Z.call(P, T)), T.type === "heartbeat" && ((X = P.onHeartbeat) == null || X.call(P, T)), T.type === "token" && ((Ie = P.onToken) == null || Ie.call(P, T.token));
3131
- }, []), [l, c] = q(!1), [u, g] = q(null), [m, k] = q(""), [p, y] = q(null), [v, A] = q(0), [x, L] = q(!1), [z, w] = q({}), [I, F] = q(null), [$, B] = q({}), D = V(null), M = V(!0), Q = V(0), G = V(null), re = V(null), te = V(null), se = V(null), S = V([]), E = V(/* @__PURE__ */ new Set()), O = V({
3130
+ (N = M.onEvent) == null || N.call(M, T), T.type === "updates" && ((ae = M.onUpdateEvent) == null || ae.call(M, T)), T.type === "tool.end" ? (X = M.onToolEnd) == null || X.call(M, T) : T.type === "tool.start" && ((Z = M.onToolStart) == null || Z.call(M, T)), T.type === "heartbeat" && ((Q = M.onHeartbeat) == null || Q.call(M, T)), T.type === "token" && ((ve = M.onToken) == null || ve.call(M, T.token));
3131
+ }, []), [l, c] = q(!1), [u, g] = q(null), [m, I] = q(""), [p, y] = q(null), [v, A] = q(0), [x, L] = q(!1), [z, w] = q({}), [k, F] = q(null), [$, D] = q({}), V = K(null), E = K(!0), Y = K(0), W = K(null), re = K(null), te = K(null), oe = K(null), S = K([]), P = K(/* @__PURE__ */ new Set()), O = K({
3132
3132
  messageId: null,
3133
3133
  lastSeq: null,
3134
3134
  lastText: ""
3135
- }), K = C((T) => {
3136
- s(T);
3135
+ }), H = C((T) => {
3136
+ o(T);
3137
3137
  }, []), d = C(() => {
3138
- k(""), y(null), g(null), re.current = null, te.current = null, se.current = null, S.current = [], E.current = /* @__PURE__ */ new Set(), w({}), F(null), B({}), O.current = {
3138
+ I(""), y(null), g(null), re.current = null, te.current = null, oe.current = null, S.current = [], P.current = /* @__PURE__ */ new Set(), w({}), F(null), D({}), O.current = {
3139
3139
  messageId: null,
3140
3140
  lastSeq: null,
3141
3141
  lastText: ""
3142
3142
  };
3143
3143
  }, []), R = C(() => {
3144
- var h;
3144
+ var U, B;
3145
3145
  console.debug("[use-chat] stop() invoked - aborting stream");
3146
- const T = (h = G.current) == null ? void 0 : h.threadId, P = () => {
3147
- var U;
3148
- (U = D.current) == null || U.abort(), D.current = null, G.current = null, c(!1), L(!1), Q.current = 0, A(0);
3146
+ const T = (U = W.current) == null ? void 0 : U.threadId, M = (B = W.current) == null ? void 0 : B.runId, J = () => {
3147
+ var G;
3148
+ (G = V.current) == null || G.abort(), V.current = null, W.current = null, c(!1), L(!1), Y.current = 0, A(0);
3149
3149
  };
3150
- (T ? mn.cancelRun(T).catch((U) => {
3151
- console.warn("[use-chat] cancel run failed:", U);
3152
- }) : Promise.resolve()).finally(P);
3150
+ (M || T ? mn.cancelRun(M || T).catch((G) => {
3151
+ console.warn("[use-chat] cancel run failed:", G);
3152
+ }) : Promise.resolve()).finally(J);
3153
3153
  }, []), _ = C(
3154
3154
  (T) => {
3155
- D.current && (D.current.abort(), D.current = null);
3156
- const P = {
3155
+ V.current && (V.current.abort(), V.current = null);
3156
+ const M = {
3157
3157
  text: typeof T.content == "string" ? T.content : T.text,
3158
3158
  threadId: T.threadId,
3159
3159
  attachments: T.attachments,
@@ -3164,27 +3164,27 @@ function Zr(e = {}) {
3164
3164
  edit: T.edit,
3165
3165
  command: T.command
3166
3166
  };
3167
- c(!0), g(null), k(""), y(null), re.current = null, te.current = null, se.current = null, S.current = [], E.current = /* @__PURE__ */ new Set(), w({}), F(null), B({}), O.current = {
3167
+ c(!0), g(null), I(""), y(null), re.current = null, te.current = null, oe.current = null, S.current = [], P.current = /* @__PURE__ */ new Set(), w({}), F(null), D({}), O.current = {
3168
3168
  messageId: null,
3169
3169
  lastSeq: null,
3170
3170
  lastText: ""
3171
3171
  };
3172
3172
  const J = new AbortController();
3173
- D.current = J;
3173
+ V.current = J;
3174
3174
  let h = null, U = !1;
3175
- const H = (Y) => {
3176
- if (E.current.has(Y)) return;
3175
+ const B = (G) => {
3176
+ if (P.current.has(G)) return;
3177
3177
  const N = S.current[0];
3178
3178
  N && w((ae) => {
3179
- let W = I;
3180
- if (!W) {
3179
+ let X = k;
3180
+ if (!X) {
3181
3181
  const le = Object.values(ae).filter((Me) => Me.role === "assistant");
3182
- le.length > 0 && (W = le[le.length - 1].id);
3182
+ le.length > 0 && (X = le[le.length - 1].id);
3183
3183
  }
3184
- if (!W || !ae[W]) return ae;
3185
- const Z = ae[W], X = [...Z.toolCalls || []], Ie = N.id ?? `task-${Y}`;
3186
- return X.some((le) => le.id === Ie && le.name === "task" && le.scope === Y) || X.push({
3187
- id: Ie,
3184
+ if (!X || !ae[X]) return ae;
3185
+ const Z = ae[X], Q = [...Z.toolCalls || []], ve = N.id ?? `task-${G}`;
3186
+ return Q.some((le) => le.id === ve && le.name === "task" && le.scope === G) || Q.push({
3187
+ id: ve,
3188
3188
  name: "task",
3189
3189
  args: {
3190
3190
  description: N.description,
@@ -3192,23 +3192,25 @@ function Zr(e = {}) {
3192
3192
  },
3193
3193
  status: "running",
3194
3194
  content: N.description,
3195
- scope: Y
3196
- }), E.current.add(Y), S.current.shift(), { ...ae, [W]: { ...Z, toolCalls: X } };
3195
+ scope: G
3196
+ }), P.current.add(G), S.current.shift(), { ...ae, [X]: { ...Z, toolCalls: Q } };
3197
3197
  });
3198
3198
  };
3199
- return G.current = {
3200
- threadId: P.threadId ?? null,
3199
+ return W.current = {
3200
+ threadId: M.threadId ?? void 0,
3201
+ runId: void 0,
3202
+ // Will be updated from headers
3201
3203
  headers: {},
3202
3204
  isStreaming: !0
3203
3205
  }, (async () => {
3204
- var Y, N, ae, W, Z, X, Ie, Fe, le, Me, Oe, Xe;
3206
+ var G, N, ae, X, Z, Q, ve, Fe, le, Me, Oe, Xe;
3205
3207
  try {
3206
3208
  let Te = {};
3207
3209
  try {
3208
3210
  if (r)
3209
3211
  Te = { Authorization: `Bearer ${r}` };
3210
3212
  else if (typeof window < "u") {
3211
- const Se = window.__AUTH_TOKEN__, vt = ((Y = window.localStorage) == null ? void 0 : Y.getItem(tt.authToken)) || null;
3213
+ const Se = window.__AUTH_TOKEN__, vt = ((G = window.localStorage) == null ? void 0 : G.getItem(tt.authToken)) || null;
3212
3214
  let ct = null;
3213
3215
  try {
3214
3216
  const lt = (N = window.localStorage) == null ? void 0 : N.getItem(tt.chatSettings);
@@ -3224,58 +3226,59 @@ function Zr(e = {}) {
3224
3226
  let Ae = {};
3225
3227
  if (typeof window < "u")
3226
3228
  try {
3227
- const fe = (W = window.localStorage) == null ? void 0 : W.getItem(tt.authSessionId);
3229
+ const fe = (X = window.localStorage) == null ? void 0 : X.getItem(tt.authSessionId);
3228
3230
  fe && (Ae = { "X-Session-Id": fe });
3229
3231
  } catch {
3230
3232
  }
3231
3233
  const Ke = {
3232
3234
  ...Te,
3233
3235
  ...Ae,
3234
- ...o.current
3235
- }, kt = {
3236
+ ...s.current
3237
+ }, It = {
3236
3238
  "Content-Type": "application/json",
3237
3239
  Accept: "text/event-stream",
3238
3240
  ...Ke
3239
- }, ve = await fetch(t + n, {
3241
+ }, he = await fetch(t + n, {
3240
3242
  method: "POST",
3241
- headers: kt,
3242
- body: JSON.stringify(P),
3243
+ headers: It,
3244
+ body: JSON.stringify(M),
3243
3245
  signal: J.signal,
3244
3246
  credentials: a
3245
3247
  });
3246
- if (G.current && (G.current.headers = Ke), !ve.ok || !ve.body) {
3247
- const fe = await ve.text().catch(() => "");
3248
+ if (W.current && (W.current.headers = Ke), !he.ok || !he.body) {
3249
+ const fe = await he.text().catch(() => "");
3248
3250
  console.debug(
3249
3251
  "[use-chat] non-OK response",
3250
- ve.status,
3252
+ he.status,
3251
3253
  fe == null ? void 0 : fe.slice(0, 500)
3252
3254
  );
3253
- const Se = `stream ${ve.status}${fe ? ": " + fe : ""}`;
3255
+ const Se = `stream ${he.status}${fe ? ": " + fe : ""}`;
3254
3256
  throw Se && (g(Se), h = "error"), new Error(Se);
3255
3257
  }
3256
3258
  L(!0);
3257
- const Qe = ve.body.getReader(), Cn = new TextDecoder();
3259
+ const Qe = he.body.getReader(), Cn = new TextDecoder();
3258
3260
  let $e = "", it = [];
3259
- Q.current = 0, A(0);
3261
+ Y.current = 0, A(0);
3260
3262
  let Ye = 0, Be = null;
3261
- const It = () => {
3263
+ const kt = () => {
3262
3264
  if (it.length) {
3263
3265
  const fe = it.join("");
3264
- it = [], M.current && k((Se) => Se + fe);
3266
+ it = [], E.current && I((Se) => Se + fe);
3265
3267
  }
3266
3268
  Be = null;
3267
3269
  }, Mn = () => {
3268
- typeof window < "u" && Be == null && (Be = requestAnimationFrame(It));
3270
+ typeof window < "u" && Be == null && (Be = requestAnimationFrame(kt));
3269
3271
  };
3270
3272
  let jt = Date.now();
3271
3273
  const En = setInterval(() => {
3272
3274
  Date.now() - jt > 18e5 && (g("Stream idle timeout"), h = "error", J.abort());
3273
3275
  }, 5e3), Pn = 1024 * 1024;
3274
3276
  try {
3275
- const Se = (ve.headers.get("X-Thread-Id") || ve.headers.get("x-thread-id")) ?? null;
3276
- for (G.current && !G.current.threadId && (G.current = {
3277
- ...G.current,
3278
- threadId: Se
3277
+ const fe = he.headers.get("X-Thread-Id") || he.headers.get("x-thread-id"), Se = he.headers.get("X-Run-Id") || he.headers.get("x-run-id");
3278
+ for (W.current && (W.current = {
3279
+ ...W.current,
3280
+ threadId: fe ?? W.current.threadId,
3281
+ runId: Se ?? W.current.runId
3279
3282
  }); ; ) {
3280
3283
  const { value: vt, done: ct } = await Qe.read();
3281
3284
  if (ct) break;
@@ -3329,33 +3332,33 @@ function Zr(e = {}) {
3329
3332
  console.debug("[use-chat] drop duplicate/out-of-order event", { seq: De, lastProcessedSeq: Ye, type: ie.type });
3330
3333
  continue;
3331
3334
  }
3332
- Ye > 0 && De > Ye + 1, Ye = De, Q.current = De, A(De);
3335
+ Ye > 0 && De > Ye + 1, Ye = De, Y.current = De, A(De);
3333
3336
  }
3334
3337
  const Rn = ["messages/partial", "metadata", "checkpoint", "values", "heartbeat", "token", "status", "error", "interrupt", "tool.start", "tool.progress", "tool.end", "task.start"];
3335
- let we = ie.type || "unknown";
3336
- if (Rn.includes(we) || (ie.messages || ie.content !== void 0 && ie.id) && (we = "messages/partial"), we === "checkpoint") {
3338
+ let Ie = ie.type || "unknown";
3339
+ if (Rn.includes(Ie) || (ie.messages || ie.content !== void 0 && ie.id) && (Ie = "messages/partial"), Ie === "checkpoint") {
3337
3340
  const b = ie;
3338
3341
  re.current = b.checkpointId ?? null, te.current = b.checkpointNs ?? null, y(b.checkpointId ?? null);
3339
- } else if (we === "values") {
3342
+ } else if (Ie === "values") {
3340
3343
  const b = ie, ue = b == null ? void 0 : b.origin, ce = b == null ? void 0 : b.scope;
3341
- ue === "task" && typeof ce == "string" && ce.startsWith("tools:") && H(ce);
3344
+ ue === "task" && typeof ce == "string" && ce.startsWith("tools:") && B(ce);
3342
3345
  const ge = ue === "task" || typeof ce == "string" && ce.startsWith("tools:");
3343
3346
  if (Array.isArray(b.checkpoints)) {
3344
- se.current = b;
3347
+ oe.current = b;
3345
3348
  try {
3346
3349
  const de = Lt(b).latest;
3347
- de && (re.current = de.checkpointId ?? null, te.current = de.checkpointNs ?? null, y(de.checkpointId ?? null), ge || B(de.values ?? {})), ge || (w({}), F(null));
3350
+ de && (re.current = de.checkpointId ?? null, te.current = de.checkpointNs ?? null, y(de.checkpointId ?? null), ge || D(de.values ?? {})), ge || (w({}), F(null));
3348
3351
  } catch (ee) {
3349
3352
  console.warn("[use-chat] Failed to hydrate values payload", ee);
3350
3353
  }
3351
3354
  } else if ((Z = b.values) != null && Z.messages)
3352
- ge || (w({}), F(null)), ge || B(b.values ?? {});
3355
+ ge || (w({}), F(null)), ge || D(b.values ?? {});
3353
3356
  else {
3354
3357
  const ee = b.values && typeof b.values == "object" ? b.values : b;
3355
- ge || B(ee ?? {});
3358
+ ge || D(ee ?? {});
3356
3359
  }
3357
3360
  }
3358
- if (we === "task.start") {
3361
+ if (Ie === "task.start") {
3359
3362
  const b = ie;
3360
3363
  S.current.push({
3361
3364
  id: b.id ?? b.callId,
@@ -3363,10 +3366,10 @@ function Zr(e = {}) {
3363
3366
  subagentType: b.subagentType ?? b.subagent_type
3364
3367
  });
3365
3368
  }
3366
- if (we === "tool.start" || we === "tool.progress" || we === "tool.end") {
3369
+ if (Ie === "tool.start" || Ie === "tool.progress" || Ie === "tool.end") {
3367
3370
  const b = ie, ue = b.id || b.callId, ce = b.scope;
3368
- b.origin === "task" && typeof ce == "string" && ce.startsWith("tools:") && H(ce), ue && w((ge) => {
3369
- let ee = I;
3371
+ b.origin === "task" && typeof ce == "string" && ce.startsWith("tools:") && B(ce), ue && w((ge) => {
3372
+ let ee = k;
3370
3373
  if (!ee) {
3371
3374
  const de = Object.values(ge).filter((me) => me.role === "assistant");
3372
3375
  de.length > 0 && (ee = de[de.length - 1].id);
@@ -3392,7 +3395,7 @@ function Zr(e = {}) {
3392
3395
  }
3393
3396
  return ge;
3394
3397
  });
3395
- } else if (we === "messages/partial") {
3398
+ } else if (Ie === "messages/partial") {
3396
3399
  const b = ie, ue = b.messages || [b];
3397
3400
  if (Array.isArray(ue) && ue.length > 0) {
3398
3401
  const ce = ue.find((ee) => ee.type === "ai"), ge = ue.find((ee) => ee.type === "tool");
@@ -3445,17 +3448,17 @@ function Zr(e = {}) {
3445
3448
  w((me) => ({ ...me, [ee]: de }));
3446
3449
  }
3447
3450
  }
3448
- } else if (we === "heartbeat") {
3451
+ } else if (Ie === "heartbeat") {
3449
3452
  console.debug("[use-chat] heartbeat received");
3450
3453
  try {
3451
3454
  } catch (b) {
3452
3455
  console.warn("[use-chat] heartbeat callback failed", b);
3453
3456
  }
3454
- } else if (Be !== null && cancelAnimationFrame(Be), It(), we === "checkpoint")
3457
+ } else if (Be !== null && cancelAnimationFrame(Be), kt(), Ie === "checkpoint")
3455
3458
  y(ie.checkpointId ?? null);
3456
- else if (we === "error") {
3459
+ else if (Ie === "error") {
3457
3460
  const b = ie;
3458
- if (g(b.message), h = "error", b.error_type === "auth_error" || b.code === "TOKEN_EXPIRED" || ((X = b.message) == null ? void 0 : X.includes("token")) || ((Ie = b.message) == null ? void 0 : Ie.includes("401")) || ((Fe = b.message) == null ? void 0 : Fe.includes("unauthorized")) || ((le = b.message) == null ? void 0 : le.includes("Unauthorized"))) {
3461
+ if (g(b.message), h = "error", b.error_type === "auth_error" || b.code === "TOKEN_EXPIRED" || ((Q = b.message) == null ? void 0 : Q.includes("token")) || ((ve = b.message) == null ? void 0 : ve.includes("401")) || ((Fe = b.message) == null ? void 0 : Fe.includes("unauthorized")) || ((le = b.message) == null ? void 0 : le.includes("Unauthorized"))) {
3459
3462
  console.error("[use-chat] Auth error detected:", b.message);
3460
3463
  try {
3461
3464
  (Me = e.onAuthError) == null || Me.call(e, b.message);
@@ -3464,14 +3467,14 @@ function Zr(e = {}) {
3464
3467
  }
3465
3468
  J.abort();
3466
3469
  }
3467
- } else if (we === "status") {
3470
+ } else if (Ie === "status") {
3468
3471
  const b = ie;
3469
3472
  (b.status === "completed" || b.status === "interrupted" || b.status === "error") && (c(!1), console.log("[use-chat] Status event received:", b));
3470
3473
  }
3471
3474
  f(ie);
3472
3475
  }
3473
3476
  }
3474
- It(), h === null && !J.signal.aborted && (h = "complete");
3477
+ kt(), h === null && !J.signal.aborted && (h = "complete");
3475
3478
  } catch (fe) {
3476
3479
  if (fe.name === "AbortError")
3477
3480
  h = h ?? "aborted";
@@ -3496,34 +3499,34 @@ function Zr(e = {}) {
3496
3499
  h = "error", g(Ae), U || (U = !0, (Xe = e.onConnectionError) == null || Xe.call(e, Ae));
3497
3500
  }
3498
3501
  } finally {
3499
- const Te = Q.current, Ae = re.current, Ke = te.current, kt = se.current;
3502
+ const Te = Y.current, Ae = re.current, Ke = te.current, It = oe.current;
3500
3503
  try {
3501
3504
  if (e.onFinish) {
3502
- const ve = {
3505
+ const he = {
3503
3506
  lastSeq: Te,
3504
3507
  lastCheckpointId: Ae,
3505
3508
  lastCheckpointNs: Ke,
3506
- lastValues: kt
3509
+ lastValues: It
3507
3510
  };
3508
- e.onFinish(ve);
3511
+ e.onFinish(he);
3509
3512
  }
3510
- } catch (ve) {
3511
- console.warn("[use-chat] onClosed callback failed", ve);
3513
+ } catch (he) {
3514
+ console.warn("[use-chat] onClosed callback failed", he);
3512
3515
  }
3513
- c(!1), L(!1), D.current = null, Q.current = 0, A(0), G.current = null;
3516
+ c(!1), L(!1), V.current = null, Y.current = 0, A(0), W.current = null;
3514
3517
  }
3515
3518
  })(), Promise.resolve();
3516
3519
  },
3517
3520
  [t, n, r, e]
3518
3521
  );
3519
- return oe(() => () => {
3522
+ return se(() => () => {
3520
3523
  var T;
3521
- M.current = !1, (T = D.current) == null || T.abort();
3524
+ E.current = !1, (T = V.current) == null || T.abort();
3522
3525
  }, []), {
3523
3526
  isStreaming: l,
3524
3527
  error: u,
3525
3528
  assistantText: m,
3526
- activeMessageId: I,
3529
+ activeMessageId: k,
3527
3530
  streamedMessages: z,
3528
3531
  lastCheckpointId: p,
3529
3532
  lastSeq: v,
@@ -3531,7 +3534,7 @@ function Zr(e = {}) {
3531
3534
  stream: _,
3532
3535
  stop: R,
3533
3536
  clear: d,
3534
- setToken: K,
3537
+ setToken: H,
3535
3538
  values: $,
3536
3539
  interrupt: () => Promise.resolve(),
3537
3540
  resume: () => Promise.resolve(),
@@ -3542,7 +3545,7 @@ function Zr(e = {}) {
3542
3545
  submit: _
3543
3546
  };
3544
3547
  }
3545
- const es = ["detail", "message", "error", "description", "title"];
3548
+ const eo = ["detail", "message", "error", "description", "title"];
3546
3549
  function ft(e) {
3547
3550
  if (!e) return null;
3548
3551
  if (typeof e == "string") {
@@ -3559,7 +3562,7 @@ function ft(e) {
3559
3562
  }
3560
3563
  if (typeof e == "object") {
3561
3564
  const t = e;
3562
- for (const n of es) {
3565
+ for (const n of eo) {
3563
3566
  const r = ft(t[n]);
3564
3567
  if (r)
3565
3568
  return r;
@@ -3571,7 +3574,7 @@ function ft(e) {
3571
3574
  }
3572
3575
  return null;
3573
3576
  }
3574
- function ts(e) {
3577
+ function to(e) {
3575
3578
  if (!e) return "Request failed";
3576
3579
  const t = e.response, n = ft(t == null ? void 0 : t.data);
3577
3580
  if (n) return n;
@@ -3585,17 +3588,17 @@ function ts(e) {
3585
3588
  }
3586
3589
  return t != null && t.status ? `Request failed with status code ${t.status}` : "Request failed";
3587
3590
  }
3588
- function ns({
3591
+ function no({
3589
3592
  api: e,
3590
3593
  initialThreadId: t = null,
3591
3594
  onError: n,
3592
3595
  onThreadChange: r,
3593
- onCurrentThreadDeleted: s
3596
+ onCurrentThreadDeleted: o
3594
3597
  }) {
3595
- const [o, a] = q([]), [i, f] = q(t), [l, c] = q(!1), [u, g] = q(null), [m, k] = q([]), [p, y] = q(!1), [, v] = q(null), [A, x] = q(null), [L, z] = q(!1), w = V(i), I = V(/* @__PURE__ */ new Map());
3596
- oe(() => {
3598
+ const [s, a] = q([]), [i, f] = q(t), [l, c] = q(!1), [u, g] = q(null), [m, I] = q([]), [p, y] = q(!1), [, v] = q(null), [A, x] = q(null), [L, z] = q(!1), w = K(i), k = K(/* @__PURE__ */ new Map());
3599
+ se(() => {
3597
3600
  w.current = i;
3598
- }, [i]), oe(() => {
3601
+ }, [i]), se(() => {
3599
3602
  t !== void 0 && t !== w.current && f(t);
3600
3603
  }, [t]);
3601
3604
  const F = C(async () => {
@@ -3604,8 +3607,8 @@ function ns({
3604
3607
  const S = await e.listThreads();
3605
3608
  a(S ?? []);
3606
3609
  } catch (S) {
3607
- const E = String(S);
3608
- g(E), n == null || n(E);
3610
+ const P = String(S);
3611
+ g(P), n == null || n(P);
3609
3612
  } finally {
3610
3613
  c(!1);
3611
3614
  }
@@ -3613,95 +3616,95 @@ function ns({
3613
3616
  y(!0), v(null);
3614
3617
  try {
3615
3618
  const S = await e.listSharedThreads();
3616
- k(S ?? []);
3619
+ I(S ?? []);
3617
3620
  } catch (S) {
3618
- const E = String(S);
3619
- v(E), n == null || n(E);
3621
+ const P = String(S);
3622
+ v(P), n == null || n(P);
3620
3623
  } finally {
3621
3624
  y(!1);
3622
3625
  }
3623
3626
  }, [e, n]);
3624
- oe(() => {
3627
+ se(() => {
3625
3628
  F();
3626
- }, [F]), oe(() => {
3629
+ }, [F]), se(() => {
3627
3630
  $();
3628
- }, [$]), oe(() => {
3631
+ }, [$]), se(() => {
3629
3632
  r == null || r(i);
3630
3633
  }, [i, r]);
3631
- const B = C(
3632
- async (S, E) => {
3634
+ const D = C(
3635
+ async (S, P) => {
3633
3636
  try {
3634
- const O = E && typeof E == "object" ? { id: E.id, name: E.name ?? "" } : void 0, K = await e.createThread(S, O);
3635
- return f(K.threadId), await F(), K.threadId;
3637
+ const O = P && typeof P == "object" ? { id: P.id, name: P.name ?? "" } : void 0, H = await e.createThread(S, O);
3638
+ return f(H.threadId), await F(), H.threadId;
3636
3639
  } catch (O) {
3637
- const K = String(O);
3638
- return n == null || n(K), null;
3640
+ const H = String(O);
3641
+ return n == null || n(H), null;
3639
3642
  }
3640
3643
  },
3641
3644
  [e, n, F]
3642
- ), D = C(
3645
+ ), V = C(
3643
3646
  async (S) => {
3644
- const E = o;
3645
- a((K) => K.filter((d) => d.threadId !== S));
3647
+ const P = s;
3648
+ a((H) => H.filter((d) => d.threadId !== S));
3646
3649
  const O = new AbortController();
3647
- I.current.set(S, O);
3650
+ k.current.set(S, O);
3648
3651
  try {
3649
- await e.deleteThread(S), w.current === S && (f(null), s == null || s());
3650
- } catch (K) {
3651
- a(E);
3652
- const d = String(K);
3652
+ await e.deleteThread(S), w.current === S && (f(null), o == null || o());
3653
+ } catch (H) {
3654
+ a(P);
3655
+ const d = String(H);
3653
3656
  n == null || n(d);
3654
3657
  } finally {
3655
- I.current.delete(S);
3658
+ k.current.delete(S);
3656
3659
  }
3657
3660
  },
3658
- [e, s, n, o]
3659
- ), M = C(
3660
- async (S, E) => {
3661
+ [e, o, n, s]
3662
+ ), E = C(
3663
+ async (S, P) => {
3661
3664
  try {
3662
- await e.updateThread(S, E), await F();
3665
+ await e.updateThread(S, P), await F();
3663
3666
  } catch (O) {
3664
3667
  n == null || n(String(O));
3665
3668
  }
3666
3669
  },
3667
3670
  [e, n, F]
3668
- ), Q = C(
3669
- async (S, E) => {
3671
+ ), Y = C(
3672
+ async (S, P) => {
3670
3673
  z(!0), x("Sharing thread…");
3671
3674
  try {
3672
- await e.shareThread(S, E), await $(), x("Shared successfully");
3675
+ await e.shareThread(S, P), await $(), x("Shared successfully");
3673
3676
  } catch (O) {
3674
- const K = ts(O);
3675
- throw n == null || n(K), x(`Failed to share: ${K}`), new Error(K);
3677
+ const H = to(O);
3678
+ throw n == null || n(H), x(`Failed to share: ${H}`), new Error(H);
3676
3679
  } finally {
3677
3680
  z(!1);
3678
3681
  }
3679
3682
  },
3680
3683
  [e, n, $]
3681
- ), G = C(
3682
- async (S, E) => {
3684
+ ), W = C(
3685
+ async (S, P) => {
3683
3686
  try {
3684
- await e.unshareThread(S, E), await $();
3687
+ await e.unshareThread(S, P), await $();
3685
3688
  } catch (O) {
3686
- const K = String(O);
3687
- throw n == null || n(K), O;
3689
+ const H = String(O);
3690
+ throw n == null || n(H), O;
3688
3691
  }
3689
3692
  },
3690
3693
  [e, n, $]
3691
3694
  ), re = pe(
3692
3695
  () => ({
3693
- createThread: B,
3694
- deleteThread: D,
3695
- renameThread: M,
3696
+ createThread: D,
3697
+ deleteThread: V,
3698
+ renameThread: E,
3696
3699
  refreshThreads: F,
3697
3700
  refreshSharedThreads: $,
3698
- shareThread: Q,
3699
- unshareThread: G
3701
+ shareThread: Y,
3702
+ unshareThread: W
3700
3703
  }),
3701
- [B, D, M, F, $, Q, G]
3704
+ [D, V, E, F, $, Y, W]
3702
3705
  ), te = C((S) => {
3703
3706
  if (!(S != null && S.threadId)) return;
3704
- const E = {
3707
+ const P = {
3705
3708
  threadId: S.threadId,
3706
3709
  title: S.title || `Thread ${S.threadId.slice(0, 8)}`,
3707
3710
  project: S.project,
@@ -3710,19 +3713,19 @@ function ns({
3710
3713
  messageCount: S.messageCount ?? 1
3711
3714
  };
3712
3715
  a((O) => {
3713
- let K = !1;
3714
- const d = O.map((R) => R.threadId === E.threadId ? (K = !0, console.debug("[useThreadsState] thread_info: updating existing thread", E.threadId), {
3716
+ let H = !1;
3717
+ const d = O.map((R) => R.threadId === P.threadId ? (H = !0, console.debug("[useThreadsState] thread_info: updating existing thread", P.threadId), {
3715
3718
  ...R,
3716
- title: E.title ?? R.title,
3717
- project: E.project ?? R.project,
3718
- updatedAt: E.updatedAt ?? R.updatedAt,
3719
- messageCount: E.messageCount ?? R.messageCount
3719
+ title: P.title ?? R.title,
3720
+ project: P.project ?? R.project,
3721
+ updatedAt: P.updatedAt ?? R.updatedAt,
3722
+ messageCount: P.messageCount ?? R.messageCount
3720
3723
  }) : R);
3721
- return K ? d : (console.debug("[useThreadsState] thread_info: adding thread to list", E.threadId), [E, ...O]);
3724
+ return H ? d : (console.debug("[useThreadsState] thread_info: adding thread to list", P.threadId), [P, ...O]);
3722
3725
  });
3723
- }, []), se = C(() => x(null), []);
3726
+ }, []), oe = C(() => x(null), []);
3724
3727
  return {
3725
- threads: o,
3728
+ threads: s,
3726
3729
  currentThreadId: i,
3727
3730
  currentThreadIdRef: w,
3728
3731
  setCurrentThreadId: f,
@@ -3734,18 +3737,18 @@ function ns({
3734
3737
  addThreadFromEvent: te,
3735
3738
  shareInFlight: L,
3736
3739
  shareStatus: A,
3737
- clearShareStatus: se
3740
+ clearShareStatus: oe
3738
3741
  };
3739
3742
  }
3740
3743
  const wn = Ge(null);
3741
- function rs({
3744
+ function ro({
3742
3745
  children: e,
3743
3746
  initialThreadId: t = null,
3744
3747
  onError: n,
3745
3748
  onThreadChange: r
3746
3749
  }) {
3747
- const { chatApi: s } = We(), {
3748
- threads: o,
3750
+ const { chatApi: o } = We(), {
3751
+ threads: s,
3749
3752
  currentThreadId: a,
3750
3753
  setCurrentThreadId: i,
3751
3754
  currentThreadIdRef: f,
@@ -3754,18 +3757,18 @@ function rs({
3754
3757
  sharedThreads: u,
3755
3758
  isLoadingSharedThreads: g,
3756
3759
  actions: m,
3757
- addThreadFromEvent: k,
3760
+ addThreadFromEvent: I,
3758
3761
  shareInFlight: p,
3759
3762
  shareStatus: y,
3760
3763
  clearShareStatus: v
3761
- } = ns({
3762
- api: s,
3764
+ } = no({
3765
+ api: o,
3763
3766
  initialThreadId: t,
3764
3767
  onError: n,
3765
3768
  onThreadChange: r
3766
3769
  }), A = pe(
3767
3770
  () => ({
3768
- threads: o,
3771
+ threads: s,
3769
3772
  currentThreadId: a,
3770
3773
  setCurrentThreadId: i,
3771
3774
  currentThreadIdRef: f,
@@ -3777,10 +3780,10 @@ function rs({
3777
3780
  shareInFlight: p,
3778
3781
  shareStatus: y,
3779
3782
  clearShareStatus: v,
3780
- addThreadFromEvent: k
3783
+ addThreadFromEvent: I
3781
3784
  }),
3782
3785
  [
3783
- o,
3786
+ s,
3784
3787
  a,
3785
3788
  i,
3786
3789
  f,
@@ -3792,17 +3795,17 @@ function rs({
3792
3795
  p,
3793
3796
  y,
3794
3797
  v,
3795
- k
3798
+ I
3796
3799
  ]
3797
3800
  );
3798
3801
  return /* @__PURE__ */ Ce(wn.Provider, { value: A, children: e });
3799
3802
  }
3800
3803
  function rt() {
3801
- const e = ot(wn);
3804
+ const e = st(wn);
3802
3805
  if (!e) throw new Error("useThreads must be used within a ThreadsProvider");
3803
3806
  return e;
3804
3807
  }
3805
- function kn(e) {
3808
+ function In(e) {
3806
3809
  const t = e.artifact;
3807
3810
  return !t || typeof t != "object" ? null : "metadata" in t && t.metadata ? t.metadata : {
3808
3811
  id: t.id ?? e.id ?? `artifact-${Date.now()}`,
@@ -3812,8 +3815,8 @@ function kn(e) {
3812
3815
  progress: t.progress ?? void 0
3813
3816
  };
3814
3817
  }
3815
- function ss(e, t) {
3816
- const n = kn(e);
3818
+ function oo(e, t) {
3819
+ const n = In(e);
3817
3820
  if (!n) return e;
3818
3821
  const r = {
3819
3822
  ...n,
@@ -3828,10 +3831,10 @@ function ss(e, t) {
3828
3831
  }
3829
3832
  };
3830
3833
  }
3831
- function os(e, t, n) {
3834
+ function so(e, t, n) {
3832
3835
  return e.find((r) => {
3833
- const s = kn(r);
3834
- return !!((s == null ? void 0 : s.id) === t || n && r.toolCallId === n);
3836
+ const o = In(r);
3837
+ return !!((o == null ? void 0 : o.id) === t || n && r.toolCallId === n);
3835
3838
  }) ?? null;
3836
3839
  }
3837
3840
  function pt(e) {
@@ -3840,31 +3843,31 @@ function pt(e) {
3840
3843
  function at(e, t, n) {
3841
3844
  return t < 0 || t >= e.length ? e : [...e.slice(0, t), n, ...e.slice(t + 1)];
3842
3845
  }
3843
- function as(e, t, n) {
3846
+ function ao(e, t, n) {
3844
3847
  for (let r = e.length - 1; r >= 0; r--)
3845
3848
  if (e[r].role === "assistant") {
3846
- const o = { ...e[r], checkpointId: t, checkpointNs: n ?? void 0 };
3847
- return at(e, r, o);
3849
+ const s = { ...e[r], checkpointId: t, checkpointNs: n ?? void 0 };
3850
+ return at(e, r, s);
3848
3851
  }
3849
3852
  return e;
3850
3853
  }
3851
- function is(e) {
3854
+ function io(e) {
3852
3855
  const t = /* @__PURE__ */ new Set();
3853
3856
  return e.map((n) => {
3854
- var o;
3855
- if (n.role !== "assistant" || !((o = n.toolCalls) != null && o.length)) return n;
3856
- const r = /* @__PURE__ */ new Set(), s = n.toolCalls.filter((a) => {
3857
+ var s;
3858
+ if (n.role !== "assistant" || !((s = n.toolCalls) != null && s.length)) return n;
3859
+ const r = /* @__PURE__ */ new Set(), o = n.toolCalls.filter((a) => {
3857
3860
  const i = a == null ? void 0 : a.id;
3858
3861
  return i ? r.has(i) ? !1 : (r.add(i), !0) : !0;
3859
3862
  });
3860
- return s.length === n.toolCalls.length ? n : { ...n, toolCalls: s };
3863
+ return o.length === n.toolCalls.length ? n : { ...n, toolCalls: o };
3861
3864
  }).filter((n) => {
3862
3865
  if (n.role !== "tool") return !0;
3863
- const r = n, s = n.toolCallId || r.toolCallId || r.callId;
3864
- return s ? t.has(s) ? !1 : (t.add(s), !0) : !0;
3866
+ const r = n, o = n.toolCallId || r.toolCallId || r.callId;
3867
+ return o ? t.has(o) ? !1 : (t.add(o), !0) : !0;
3865
3868
  });
3866
3869
  }
3867
- const cs = {
3870
+ const co = {
3868
3871
  messages: [],
3869
3872
  taskMessagesByScope: {},
3870
3873
  assemblingId: null,
@@ -3874,7 +3877,7 @@ const cs = {
3874
3877
  pendingInterrupt: null,
3875
3878
  values: {}
3876
3879
  };
3877
- function ls(e, t) {
3880
+ function lo(e, t) {
3878
3881
  var n;
3879
3882
  switch (t.type) {
3880
3883
  case "reset":
@@ -3889,11 +3892,11 @@ function ls(e, t) {
3889
3892
  values: {}
3890
3893
  };
3891
3894
  case "user_message": {
3892
- const { message: r, editingMessageId: s } = t.payload;
3893
- return s ? { ...e, messages: [...e.messages, r], assemblingId: null } : { ...e, messages: [...e.messages, r], assemblingId: null };
3895
+ const { message: r, editingMessageId: o } = t.payload;
3896
+ return o ? { ...e, messages: [...e.messages, r], assemblingId: null } : { ...e, messages: [...e.messages, r], assemblingId: null };
3894
3897
  }
3895
3898
  case "seed": {
3896
- const r = pt(t.payload.messages), s = {
3899
+ const r = pt(t.payload.messages), o = {
3897
3900
  ...e,
3898
3901
  messages: r,
3899
3902
  // REPLACE with incoming messages (don't merge with existing)
@@ -3902,40 +3905,40 @@ function ls(e, t) {
3902
3905
  pendingInterrupt: t.payload.pendingInterrupt ?? null,
3903
3906
  taskMessagesByScope: {}
3904
3907
  };
3905
- return Object.prototype.hasOwnProperty.call(t.payload, "checkpointId") && (s.lastCheckpointId = t.payload.checkpointId ?? null), Object.prototype.hasOwnProperty.call(t.payload, "checkpointNs") && (s.lastCheckpointNs = t.payload.checkpointNs ?? null), Object.prototype.hasOwnProperty.call(t.payload, "values") && (s.values = t.payload.values ?? {}), s;
3908
+ return Object.prototype.hasOwnProperty.call(t.payload, "checkpointId") && (o.lastCheckpointId = t.payload.checkpointId ?? null), Object.prototype.hasOwnProperty.call(t.payload, "checkpointNs") && (o.lastCheckpointNs = t.payload.checkpointNs ?? null), Object.prototype.hasOwnProperty.call(t.payload, "values") && (o.values = t.payload.values ?? {}), o;
3906
3909
  }
3907
3910
  case "prepend": {
3908
3911
  const r = pt(t.payload.messages);
3909
3912
  if (!r.length)
3910
3913
  return e;
3911
- const s = new Set(e.messages.map((i) => i.id)), o = r.filter((i) => !s.has(i.id));
3912
- if (!o.length)
3914
+ const o = new Set(e.messages.map((i) => i.id)), s = r.filter((i) => !o.has(i.id));
3915
+ if (!s.length)
3913
3916
  return e;
3914
- const a = [...o, ...e.messages];
3917
+ const a = [...s, ...e.messages];
3915
3918
  return { ...e, messages: a };
3916
3919
  }
3917
3920
  case "event":
3918
3921
  return Qt(e, t.payload.ev);
3919
3922
  case "batch": {
3920
3923
  const { events: r } = t.payload;
3921
- return r.length ? r.reduce((s, o) => Qt(s, o), e) : e;
3924
+ return r.length ? r.reduce((o, s) => Qt(o, s), e) : e;
3922
3925
  }
3923
3926
  default:
3924
3927
  return e;
3925
3928
  }
3926
3929
  }
3927
- function us(e = []) {
3928
- const [t, n] = Fn(ls, { ...cs, messages: e }), r = V([]), s = V(null), o = V(null), a = C(() => {
3929
- s.current !== null && typeof window < "u" && window.cancelAnimationFrame(s.current), o.current !== null && clearTimeout(o.current), s.current = null, o.current = null;
3930
+ function uo(e = []) {
3931
+ const [t, n] = Fn(lo, { ...co, messages: e }), r = K([]), o = K(null), s = K(null), a = C(() => {
3932
+ o.current !== null && typeof window < "u" && window.cancelAnimationFrame(o.current), s.current !== null && clearTimeout(s.current), o.current = null, s.current = null;
3930
3933
  const c = r.current;
3931
3934
  c.length && (r.current = [], n({ type: "batch", payload: { events: c } }));
3932
3935
  }, []), i = C(() => {
3933
- typeof window < "u" && typeof window.requestAnimationFrame == "function" ? s.current === null && (s.current = window.requestAnimationFrame(() => a())) : o.current === null && (o.current = setTimeout(a, 8));
3936
+ typeof window < "u" && typeof window.requestAnimationFrame == "function" ? o.current === null && (o.current = window.requestAnimationFrame(() => a())) : s.current === null && (s.current = setTimeout(a, 8));
3934
3937
  }, [a]), f = C((c) => {
3935
3938
  r.current.push(c), i();
3936
3939
  }, [i]);
3937
- oe(() => () => {
3938
- s.current !== null && typeof window < "u" && window.cancelAnimationFrame(s.current), o.current !== null && clearTimeout(o.current), r.current = [];
3940
+ se(() => () => {
3941
+ o.current !== null && typeof window < "u" && window.cancelAnimationFrame(o.current), s.current !== null && clearTimeout(s.current), r.current = [];
3939
3942
  }, []);
3940
3943
  const l = pe(() => ({
3941
3944
  reset: (c) => n({ type: "reset", payload: { messages: c } }),
@@ -3948,17 +3951,17 @@ function us(e = []) {
3948
3951
  }
3949
3952
  function Qt(e, t) {
3950
3953
  var a;
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:");
3954
+ const n = t, r = n == null ? void 0 : n.origin, o = n == null ? void 0 : n.scope, s = r === "task" || typeof o == "string" && o.startsWith("tools:");
3952
3955
  if (t.type === "tool.start")
3953
- return o ? e : ps(e, t);
3956
+ return s ? e : go(e, t);
3954
3957
  if (t.type === "tool.progress")
3955
- return o ? e : gs(e, t);
3958
+ return s ? e : mo(e, t);
3956
3959
  if (t.type === "tool.end")
3957
- return o ? e : ms(e, t);
3960
+ return s ? e : ho(e, t);
3958
3961
  if (t.type === "artifact.update")
3959
- return hs(e, t);
3962
+ return yo(e, t);
3960
3963
  if (t.type === "checkpoint") {
3961
- const i = t.checkpointNs ?? e.lastCheckpointNs ?? null, f = as(e.messages, t.checkpointId, i);
3964
+ const i = t.checkpointNs ?? e.lastCheckpointNs ?? null, f = ao(e.messages, t.checkpointId, i);
3962
3965
  return { ...e, lastCheckpointId: t.checkpointId, lastCheckpointNs: i, messages: f };
3963
3966
  }
3964
3967
  if (t.type === "error") {
@@ -3971,9 +3974,9 @@ function Qt(e, t) {
3971
3974
  return { ...e, messages: [...e.messages, i] };
3972
3975
  }
3973
3976
  if (t.type === "values" && ((a = t.values) != null && a.messages)) {
3974
- const i = t.values, f = Array.isArray(i.messages) ? i.messages : [], l = is(pt(f)), { messages: c, ...u } = i;
3975
- if (o) {
3976
- const g = typeof s == "string" && s.length > 0 ? s : "task";
3977
+ const i = t.values, f = Array.isArray(i.messages) ? i.messages : [], l = io(pt(f)), { messages: c, ...u } = i;
3978
+ if (s) {
3979
+ const g = typeof o == "string" && o.length > 0 ? o : "task";
3977
3980
  return {
3978
3981
  ...e,
3979
3982
  taskMessagesByScope: {
@@ -3993,39 +3996,39 @@ function Qt(e, t) {
3993
3996
  }
3994
3997
  return t.type === "thread_info", e;
3995
3998
  }
3996
- function In(e) {
3999
+ function kn(e) {
3997
4000
  return e.id ?? void 0;
3998
4001
  }
3999
4002
  function wt(e, t) {
4000
4003
  var n;
4001
4004
  if (!t) return -1;
4002
4005
  for (let r = e.length - 1; r >= 0; r--) {
4003
- const s = e[r];
4004
- if (s.role === "assistant" && ((n = s.toolCalls) != null && n.some((o) => o.id === t)))
4006
+ const o = e[r];
4007
+ if (o.role === "assistant" && ((n = o.toolCalls) != null && n.some((s) => s.id === t)))
4005
4008
  return r;
4006
4009
  }
4007
4010
  return -1;
4008
4011
  }
4009
- function ds(e) {
4012
+ function fo(e) {
4010
4013
  for (let t = e.length - 1; t >= 0; t--)
4011
4014
  if (e[t].role === "user") return t;
4012
4015
  return -1;
4013
4016
  }
4014
- function fs(e, t, n) {
4017
+ function po(e, t, n) {
4015
4018
  const r = wt(e, t);
4016
4019
  if (r === -1) return e;
4017
- const s = e[r], o = (s.toolCalls ?? []).map(
4020
+ const o = e[r], s = (o.toolCalls ?? []).map(
4018
4021
  (a) => a.id === t ? { ...a, ...n } : a
4019
4022
  );
4020
- return at(e, r, { ...s, toolCalls: o });
4023
+ return at(e, r, { ...o, toolCalls: s });
4021
4024
  }
4022
- function ps(e, t) {
4023
- const n = t, r = n.id || n.callId, s = n.name ?? void 0, o = n.scope ?? void 0, a = `Starting ${s ?? "tool"}...`;
4025
+ function go(e, t) {
4026
+ const n = t, r = n.id || n.callId, o = n.name ?? void 0, s = n.scope ?? void 0, a = `Starting ${o ?? "tool"}...`;
4024
4027
  let i = e.messages;
4025
4028
  if (r) {
4026
4029
  let f = wt(i, r);
4027
4030
  if (f === -1) {
4028
- const l = ds(i);
4031
+ const l = fo(i);
4029
4032
  for (let c = i.length - 1; c > l; c--)
4030
4033
  if (i[c].role === "assistant") {
4031
4034
  f = c;
@@ -4034,13 +4037,13 @@ function ps(e, t) {
4034
4037
  }
4035
4038
  if (f !== -1) {
4036
4039
  const l = i[f], c = [...l.toolCalls ?? []], u = c.findIndex((g) => g.id === r);
4037
- u >= 0 ? c[u] = { ...c[u], status: "running", content: a, scope: o ?? c[u].scope } : c.push({
4040
+ u >= 0 ? c[u] = { ...c[u], status: "running", content: a, scope: s ?? c[u].scope } : c.push({
4038
4041
  id: r,
4039
- name: s || "tool",
4042
+ name: o || "tool",
4040
4043
  args: n.args || {},
4041
4044
  status: "running",
4042
4045
  content: a,
4043
- scope: o
4046
+ scope: s
4044
4047
  }), i = at(i, f, { ...l, toolCalls: c });
4045
4048
  } else {
4046
4049
  const l = n.agentName ?? "assistant", c = {
@@ -4050,11 +4053,11 @@ function ps(e, t) {
4050
4053
  content: [],
4051
4054
  toolCalls: [{
4052
4055
  id: r,
4053
- name: s || "tool",
4056
+ name: o || "tool",
4054
4057
  args: n.args || {},
4055
4058
  status: "running",
4056
4059
  content: a,
4057
- scope: o
4060
+ scope: s
4058
4061
  }],
4059
4062
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4060
4063
  };
@@ -4063,31 +4066,31 @@ function ps(e, t) {
4063
4066
  }
4064
4067
  return { ...e, messages: i };
4065
4068
  }
4066
- function gs(e, t) {
4067
- const n = t.id ?? In(t);
4069
+ function mo(e, t) {
4070
+ const n = t.id ?? kn(t);
4068
4071
  if (!n) return e;
4069
- const r = t.content ?? void 0, s = t.scope ?? void 0;
4070
- let o = e.messages;
4071
- const a = wt(o, n);
4072
+ const r = t.content ?? void 0, o = t.scope ?? void 0;
4073
+ let s = e.messages;
4074
+ const a = wt(s, n);
4072
4075
  if (a !== -1) {
4073
- const i = o[a], f = r ?? null, l = typeof f == "string" ? f : JSON.stringify(f), c = Ee(f), u = typeof c == "string" ? c : l, g = (i.toolCalls ?? []).map(
4074
- (m) => m.id === n ? { ...m, content: u, scope: s ?? m.scope } : m
4076
+ const i = s[a], f = r ?? null, l = typeof f == "string" ? f : JSON.stringify(f), c = Ee(f), u = typeof c == "string" ? c : l, g = (i.toolCalls ?? []).map(
4077
+ (m) => m.id === n ? { ...m, content: u, scope: o ?? m.scope } : m
4075
4078
  );
4076
- o = at(o, a, { ...i, toolCalls: g });
4079
+ s = at(s, a, { ...i, toolCalls: g });
4077
4080
  }
4078
- return { ...e, messages: o };
4081
+ return { ...e, messages: s };
4079
4082
  }
4080
- function ms(e, t) {
4081
- const n = In(t);
4083
+ function ho(e, t) {
4084
+ const n = kn(t);
4082
4085
  let r = e.messages;
4083
- 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;
4086
+ const o = t.scope ?? void 0, s = t.content ?? t.error ?? null, a = typeof s == "string" ? s : JSON.stringify(s), i = Ee(s), f = typeof i == "string" ? i : a;
4084
4087
  if (n)
4085
4088
  if (wt(r, n) !== -1)
4086
- r = fs(r, n, {
4089
+ r = po(r, n, {
4087
4090
  status: "completed",
4088
4091
  content: f,
4089
4092
  artifact: t.artifact,
4090
- scope: s
4093
+ scope: o
4091
4094
  });
4092
4095
  else {
4093
4096
  const u = t.name ?? "assistant", g = {
@@ -4102,7 +4105,7 @@ function ms(e, t) {
4102
4105
  status: "completed",
4103
4106
  content: f,
4104
4107
  artifact: t.artifact,
4105
- scope: s
4108
+ scope: o
4106
4109
  }],
4107
4110
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4108
4111
  };
@@ -4119,9 +4122,9 @@ function ms(e, t) {
4119
4122
  };
4120
4123
  return { ...e, messages: [...r, l] };
4121
4124
  }
4122
- function hs(e, t) {
4123
- const n = t.artifactId, r = t.callId, s = os(e.messages, n, r);
4124
- if (!s) {
4125
+ function yo(e, t) {
4126
+ const n = t.artifactId, r = t.callId, o = so(e.messages, n, r);
4127
+ if (!o) {
4125
4128
  const i = {
4126
4129
  id: `artifact-${n}`,
4127
4130
  role: "tool",
@@ -4145,7 +4148,7 @@ function hs(e, t) {
4145
4148
  messages: [...e.messages, i]
4146
4149
  };
4147
4150
  }
4148
- const o = e.messages.indexOf(s), a = ss(s, {
4151
+ const s = e.messages.indexOf(o), a = oo(o, {
4149
4152
  status: t.status,
4150
4153
  progress: t.progress,
4151
4154
  error: t.error
@@ -4155,11 +4158,11 @@ function hs(e, t) {
4155
4158
  ...t.partial_data
4156
4159
  }), {
4157
4160
  ...e,
4158
- messages: at(e.messages, o, a)
4161
+ messages: at(e.messages, s, a)
4159
4162
  };
4160
4163
  }
4161
4164
  const Yt = 120;
4162
- function ys(e) {
4165
+ function bo(e) {
4163
4166
  if (!Array.isArray(e))
4164
4167
  return "";
4165
4168
  const t = e.filter((r) => !!(r && r.type === "text")).map((r) => (r.text ?? "").trim()).filter(Boolean);
@@ -4168,20 +4171,20 @@ function ys(e) {
4168
4171
  const n = t.join(" ").replace(/\s+/g, " ").trim();
4169
4172
  return n ? n.length > Yt ? `${n.slice(0, Yt - 3)}…` : n : "";
4170
4173
  }
4171
- function bs(e) {
4172
- return ys(e.content) || "";
4174
+ function wo(e) {
4175
+ return bo(e.content) || "";
4173
4176
  }
4174
- function ws(e) {
4175
- const t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Map(), s = [];
4177
+ function Io(e) {
4178
+ const t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Map(), o = [];
4176
4179
  for (let l = 0; l < e.length; l++) {
4177
- const c = e[l], u = c.checkpointId, g = u ?? `cp-${l}`, m = c.metadata ?? {}, k = typeof m.step == "number" ? m.step : null, p = typeof m.source == "string" ? m.source : null;
4180
+ const c = e[l], u = c.checkpointId, g = u ?? `cp-${l}`, m = c.metadata ?? {}, I = typeof m.step == "number" ? m.step : null, p = typeof m.source == "string" ? m.source : null;
4178
4181
  let y = null, v = null;
4179
4182
  const A = Array.isArray(c.messages) ? c.messages : [];
4180
4183
  for (const w of A)
4181
4184
  w.role === "user" && (v || (v = w), w.id && (y = w.id));
4182
4185
  const x = c.next && c.next.length > 0 ? String(c.next[0]) : null, L = c.parentConfig ?? null, z = {
4183
4186
  id: g,
4184
- step: k,
4187
+ step: I,
4185
4188
  source: p,
4186
4189
  createdAt: c.createdAt ?? null,
4187
4190
  namespace: c.checkpointNs ?? null,
@@ -4190,27 +4193,27 @@ function ws(e) {
4190
4193
  parentConfig: L,
4191
4194
  userMessageId: y
4192
4195
  };
4193
- if (s.push(z), u && t.set(u, z), u && v) {
4194
- const w = bs(v);
4196
+ if (o.push(z), u && t.set(u, z), u && v) {
4197
+ const w = wo(v);
4195
4198
  w && r.set(u, w);
4196
4199
  }
4197
4200
  n.push({
4198
4201
  id: g,
4199
4202
  messageId: y,
4200
- step: k,
4203
+ step: I,
4201
4204
  source: p,
4202
4205
  createdAt: c.createdAt ?? null,
4203
4206
  next: x,
4204
4207
  parentConfig: L
4205
4208
  });
4206
4209
  }
4207
- const o = /* @__PURE__ */ new Map();
4208
- for (const l of s) {
4210
+ const s = /* @__PURE__ */ new Map();
4211
+ for (const l of o) {
4209
4212
  if (!l.userMessageId) continue;
4210
- const c = o.get(l.userMessageId) ?? [];
4211
- c.push(l), o.set(l.userMessageId, c);
4213
+ const c = s.get(l.userMessageId) ?? [];
4214
+ c.push(l), s.set(l.userMessageId, c);
4212
4215
  }
4213
- for (const l of o.values()) {
4216
+ for (const l of s.values()) {
4214
4217
  if (!l.length) continue;
4215
4218
  l.sort((u, g) => {
4216
4219
  const m = u.createdAt ? Date.parse(u.createdAt) : 0;
@@ -4238,64 +4241,64 @@ function ws(e) {
4238
4241
  for (const u of t.values())
4239
4242
  u.userMessageId === l && c.push(u);
4240
4243
  return c.length ? (c.sort((u, g) => {
4241
- const m = typeof u.attemptIndex == "number" ? u.attemptIndex : Number.MAX_SAFE_INTEGER, k = typeof g.attemptIndex == "number" ? g.attemptIndex : Number.MAX_SAFE_INTEGER;
4242
- return m - k;
4244
+ const m = typeof u.attemptIndex == "number" ? u.attemptIndex : Number.MAX_SAFE_INTEGER, I = typeof g.attemptIndex == "number" ? g.attemptIndex : Number.MAX_SAFE_INTEGER;
4245
+ return m - I;
4243
4246
  }), c) : [];
4244
4247
  }
4245
4248
  };
4246
4249
  }
4247
- function Xs(e, t, n) {
4250
+ function Qo(e, t, n) {
4248
4251
  if (!e)
4249
4252
  return { attemptCount: 1, attemptIndex: 0, attempts: [] };
4250
4253
  const r = n.getMessageAttempts(e);
4251
4254
  if (!r.length)
4252
4255
  return { attemptCount: 1, attemptIndex: 0, attempts: [] };
4253
- let s = 0;
4256
+ let o = 0;
4254
4257
  if (t) {
4255
- const o = r.findIndex((a) => a.id === t);
4256
- o >= 0 && (s = o);
4258
+ const s = r.findIndex((a) => a.id === t);
4259
+ s >= 0 && (o = s);
4257
4260
  }
4258
4261
  return {
4259
4262
  attemptCount: r.length,
4260
- attemptIndex: s,
4263
+ attemptIndex: o,
4261
4264
  attempts: r
4262
4265
  };
4263
4266
  }
4264
- function ks(e) {
4265
- return pe(() => ws(e), [e]);
4267
+ function ko(e) {
4268
+ return pe(() => Io(e), [e]);
4266
4269
  }
4267
4270
  function vn({
4268
4271
  api: e,
4269
4272
  fileApi: t,
4270
4273
  seed: n,
4271
4274
  onError: r,
4272
- currentThreadId: s,
4273
- initialThreadId: o = null,
4275
+ currentThreadId: o,
4276
+ initialThreadId: s = null,
4274
4277
  initialCheckpointId: a = null,
4275
4278
  initialCheckpointNs: i = null,
4276
4279
  autoLoadInitial: f = !0,
4277
4280
  isStreaming: l,
4278
4281
  getMessages: c
4279
4282
  }) {
4280
- const [u, g] = q(null), k = pe(
4283
+ const [u, g] = q(null), I = pe(
4281
4284
  () => Lt(u),
4282
4285
  [u]
4283
- ).checkpoints, p = ks(k), y = p.timeline, [v, A] = q(!1), [x, L] = q(!1), [z, w] = q(null), I = V(s), F = V(null), $ = V(null), B = V(null), D = V(null), M = V(null), Q = V(/* @__PURE__ */ new Map()), G = V(null), re = V(null);
4284
- oe(() => {
4285
- I.current = s;
4286
- }, [s]);
4286
+ ).checkpoints, p = ko(I), y = p.timeline, [v, A] = q(!1), [x, L] = q(!1), [z, w] = q(null), k = K(o), F = K(null), $ = K(null), D = K(null), V = K(null), E = K(null), Y = K(/* @__PURE__ */ new Map()), W = K(null), re = K(null);
4287
+ se(() => {
4288
+ k.current = o;
4289
+ }, [o]);
4287
4290
  const te = C(
4288
4291
  async (h) => {
4289
- var H, Y;
4292
+ var B, G;
4290
4293
  if (!h.threadId) return;
4291
4294
  const U = h.threadId;
4292
- (H = h.onStart) == null || H.call(h), h.setLoading(!0);
4295
+ (B = h.onStart) == null || B.call(h), h.setLoading(!0);
4293
4296
  try {
4294
4297
  await h.action(U);
4295
4298
  } catch (N) {
4296
- if (!St(N) && I.current === U) {
4297
- const W = String(N);
4298
- (Y = h.handleError) == null || Y.call(h, W), r == null || r(W);
4299
+ if (!St(N) && k.current === U) {
4300
+ const X = String(N);
4301
+ (G = h.handleError) == null || G.call(h, X), r == null || r(X);
4299
4302
  }
4300
4303
  throw N;
4301
4304
  } finally {
@@ -4303,17 +4306,17 @@ function vn({
4303
4306
  }
4304
4307
  },
4305
4308
  [r]
4306
- ), se = C(
4309
+ ), oe = C(
4307
4310
  async (h) => {
4308
4311
  const U = await e.getState({
4309
4312
  threadId: h.threadId,
4310
4313
  checkpointId: h.checkpointId,
4311
4314
  checkpointNs: h.checkpointNs
4312
- }), H = h.forTimelineHistory ?? {
4315
+ }), B = h.forTimelineHistory ?? {
4313
4316
  version: "values@1",
4314
4317
  threadId: h.threadId,
4315
4318
  checkpoints: [U]
4316
- }, Y = t ? await Gr(H, t) : H, { latest: N } = Lt(Y);
4319
+ }, G = t ? await Gr(B, t) : B, { latest: N } = Lt(G);
4317
4320
  return N;
4318
4321
  },
4319
4322
  [e, t]
@@ -4327,19 +4330,19 @@ function vn({
4327
4330
  includeMessages: !1,
4328
4331
  signal: h.signal
4329
4332
  });
4330
- I.current === h.threadId && g(U);
4333
+ k.current === h.threadId && g(U);
4331
4334
  },
4332
4335
  [e]
4333
- ), E = C(
4336
+ ), P = C(
4334
4337
  async (h, U) => {
4335
- var W;
4338
+ var X;
4336
4339
  if (!h) return;
4337
- const H = `${h}:${U ?? "latest"}`, Y = Q.current.get(H);
4338
- if (Y)
4339
- return Y;
4340
- (W = G.current) == null || W.abort();
4340
+ const B = `${h}:${U ?? "latest"}`, G = Y.current.get(B);
4341
+ if (G)
4342
+ return G;
4343
+ (X = W.current) == null || X.abort();
4341
4344
  const N = new AbortController();
4342
- G.current = N;
4345
+ W.current = N;
4343
4346
  const ae = te({
4344
4347
  threadId: h,
4345
4348
  setLoading: A,
@@ -4347,21 +4350,21 @@ function vn({
4347
4350
  handleError: (Z) => w(Z),
4348
4351
  action: async (Z) => {
4349
4352
  var Fe;
4350
- const X = await se({
4353
+ const Q = await oe({
4351
4354
  threadId: Z,
4352
4355
  checkpointId: U ?? void 0
4353
4356
  });
4354
- if (I.current !== Z) {
4357
+ if (k.current !== Z) {
4355
4358
  console.log(
4356
- `[useThreadHistoryState] Thread changed during load (was ${Z}, now ${I.current}), discarding stale data`
4359
+ `[useThreadHistoryState] Thread changed during load (was ${Z}, now ${k.current}), discarding stale data`
4357
4360
  );
4358
4361
  return;
4359
4362
  }
4360
- if (n((X == null ? void 0 : X.messages) ?? [], {
4361
- checkpointId: (X == null ? void 0 : X.checkpointId) ?? null,
4362
- checkpointNs: (X == null ? void 0 : X.checkpointNs) ?? null,
4363
- pendingInterrupt: (X == null ? void 0 : X.interrupt) ?? null,
4364
- values: X == null ? void 0 : X.values
4363
+ if (n((Q == null ? void 0 : Q.messages) ?? [], {
4364
+ checkpointId: (Q == null ? void 0 : Q.checkpointId) ?? null,
4365
+ checkpointNs: (Q == null ? void 0 : Q.checkpointNs) ?? null,
4366
+ pendingInterrupt: (Q == null ? void 0 : Q.interrupt) ?? null,
4367
+ values: Q == null ? void 0 : Q.values
4365
4368
  }), !(!!u && (u == null ? void 0 : u.threadId) === Z)) {
4366
4369
  (Fe = re.current) == null || Fe.abort();
4367
4370
  const le = new AbortController();
@@ -4375,61 +4378,61 @@ function vn({
4375
4378
  }
4376
4379
  }
4377
4380
  });
4378
- Q.current.set(H, ae);
4381
+ Y.current.set(B, ae);
4379
4382
  try {
4380
4383
  await ae;
4381
4384
  } finally {
4382
- Q.current.delete(H), G.current === N && (G.current = null);
4385
+ Y.current.delete(B), W.current === N && (W.current = null);
4383
4386
  }
4384
- return I.current === h && (M.current = H), ae;
4387
+ return k.current === h && (E.current = B), ae;
4385
4388
  },
4386
- [n, te, se, S, u]
4389
+ [n, te, oe, S, u]
4387
4390
  ), O = C(
4388
4391
  async (h, U) => {
4389
- D.current = h;
4392
+ V.current = h;
4390
4393
  try {
4391
- await E(h, U);
4392
- } catch (H) {
4393
- if (!St(H))
4394
- throw H;
4394
+ await P(h, U);
4395
+ } catch (B) {
4396
+ if (!St(B))
4397
+ throw B;
4395
4398
  } finally {
4396
- D.current === h && (D.current = null);
4399
+ V.current === h && (V.current = null);
4397
4400
  }
4398
4401
  },
4399
- [E]
4400
- ), K = C((h) => {
4402
+ [P]
4403
+ ), H = C((h) => {
4401
4404
  $.current = h;
4402
4405
  }, []), d = C((h) => {
4403
- B.current = h;
4406
+ D.current = h;
4404
4407
  }, []), R = C(
4405
4408
  async (h) => {
4406
- const U = h == null ? void 0 : h.threadId, H = typeof U == "string" ? U : I.current;
4407
- if (!H || I.current && I.current !== H && B.current !== H)
4409
+ const U = h == null ? void 0 : h.threadId, B = typeof U == "string" ? U : k.current;
4410
+ if (!B || k.current && k.current !== B && D.current !== B)
4408
4411
  return;
4409
- const Y = h, N = await se({
4410
- threadId: H
4412
+ const G = h, N = await oe({
4413
+ threadId: B
4411
4414
  });
4412
4415
  N && (n(N.messages ?? [], {
4413
4416
  checkpointId: N.checkpointId ?? null,
4414
4417
  checkpointNs: N.checkpointNs ?? null,
4415
4418
  pendingInterrupt: N.interrupt ?? null,
4416
4419
  values: N.values
4417
- }), g(Y), M.current = `${H}:latest`, $.current = null, B.current === H && (B.current = null));
4420
+ }), g(G), E.current = `${B}:latest`, $.current = null, D.current === B && (D.current = null));
4418
4421
  },
4419
- [n, l, se]
4422
+ [n, l, oe]
4420
4423
  ), _ = C(
4421
4424
  async (h, U) => {
4422
- const H = I.current;
4425
+ const B = k.current;
4423
4426
  await te({
4424
- threadId: H,
4427
+ threadId: B,
4425
4428
  setLoading: L,
4426
- action: async (Y) => {
4427
- const N = await se({
4428
- threadId: Y,
4429
+ action: async (G) => {
4430
+ const N = await oe({
4431
+ threadId: G,
4429
4432
  checkpointId: h,
4430
4433
  checkpointNs: U ?? void 0
4431
4434
  });
4432
- I.current === Y && n((N == null ? void 0 : N.messages) ?? [], {
4435
+ k.current === G && n((N == null ? void 0 : N.messages) ?? [], {
4433
4436
  checkpointId: (N == null ? void 0 : N.checkpointId) ?? h ?? null,
4434
4437
  checkpointNs: (N == null ? void 0 : N.checkpointNs) ?? U ?? null,
4435
4438
  pendingInterrupt: (N == null ? void 0 : N.interrupt) ?? null,
@@ -4439,7 +4442,7 @@ function vn({
4439
4442
  }).catch(() => {
4440
4443
  });
4441
4444
  },
4442
- [n, te, se]
4445
+ [n, te, oe]
4443
4446
  ), T = C(
4444
4447
  (h, U) => {
4445
4448
  n(c(), {
@@ -4448,45 +4451,45 @@ function vn({
4448
4451
  });
4449
4452
  },
4450
4453
  [c, n]
4451
- ), P = C(async () => {
4452
- I.current && await O(I.current);
4454
+ ), M = C(async () => {
4455
+ k.current && await O(k.current);
4453
4456
  }, [O]);
4454
- oe(() => {
4455
- if (!f || !s || v || l)
4457
+ se(() => {
4458
+ if (!f || !o || v || l)
4456
4459
  return;
4457
- if ($.current === s) {
4458
- $.current = null, F.current = s;
4460
+ if ($.current === o) {
4461
+ $.current = null, F.current = o;
4459
4462
  return;
4460
4463
  }
4461
- if (B.current === s) {
4462
- F.current = s;
4464
+ if (D.current === o) {
4465
+ F.current = o;
4463
4466
  return;
4464
4467
  }
4465
- if (D.current === s) {
4466
- D.current = null, F.current = s;
4468
+ if (V.current === o) {
4469
+ V.current = null, F.current = o;
4467
4470
  return;
4468
4471
  }
4469
- if (F.current === s)
4472
+ if (F.current === o)
4470
4473
  return;
4471
- F.current = s;
4474
+ F.current = o;
4472
4475
  let h;
4473
- const U = `${s}:latest`;
4474
- M.current !== U && O(s, h);
4476
+ const U = `${o}:latest`;
4477
+ E.current !== U && O(o, h);
4475
4478
  }, [
4476
4479
  f,
4477
- s,
4480
+ o,
4478
4481
  a,
4479
4482
  i,
4480
- o,
4483
+ s,
4481
4484
  v,
4482
4485
  l,
4483
4486
  O
4484
4487
  ]);
4485
4488
  const J = C(() => {
4486
- g(null), A(!1), L(!1), w(null), $.current = null, B.current = null, F.current = null, M.current = null, D.current = null;
4489
+ g(null), A(!1), L(!1), w(null), $.current = null, D.current = null, F.current = null, E.current = null, V.current = null;
4487
4490
  }, []);
4488
4491
  return {
4489
- threadCheckpoints: k,
4492
+ threadCheckpoints: I,
4490
4493
  threadTimeline: y,
4491
4494
  checkpointIndex: p,
4492
4495
  isLoadingThread: v,
@@ -4495,9 +4498,9 @@ function vn({
4495
4498
  loadThread: O,
4496
4499
  navigateToCheckpoint: _,
4497
4500
  setCurrentCheckpointId: T,
4498
- returnToLatest: P,
4501
+ returnToLatest: M,
4499
4502
  handleValuesEvent: R,
4500
- markSkipNextLoad: K,
4503
+ markSkipNextLoad: H,
4501
4504
  markStreamPendingThread: d,
4502
4505
  resetHistoryState: J,
4503
4506
  clearState: J
@@ -4505,27 +4508,27 @@ function vn({
4505
4508
  }
4506
4509
  const Tn = Ge(null), An = Ge(null);
4507
4510
  function Sn(e) {
4508
- const t = ot(Tn);
4511
+ const t = st(Tn);
4509
4512
  if (!t && !(e != null && e.optional)) throw new Error("useThreadState must be used within a ThreadStateProvider");
4510
4513
  return t;
4511
4514
  }
4512
- function Is() {
4513
- const e = ot(An);
4515
+ function vo() {
4516
+ const e = st(An);
4514
4517
  if (!e)
4515
4518
  throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");
4516
4519
  return e;
4517
4520
  }
4518
- function vs({
4521
+ function To({
4519
4522
  children: e,
4520
4523
  initialThreadId: t = null,
4521
4524
  initialCheckpointId: n = null,
4522
4525
  initialCheckpointNs: r = null,
4523
- autoLoadInitial: s = !0,
4524
- isStreaming: o,
4526
+ autoLoadInitial: o = !0,
4527
+ isStreaming: s,
4525
4528
  onError: a
4526
4529
  }) {
4527
- const { chatApi: i, fileApi: f } = We(), { currentThreadId: l } = rt(), { state: c, seed: u, onEvent: g, dispatch: m } = us(), {
4528
- threadCheckpoints: k,
4530
+ const { chatApi: i, fileApi: f } = We(), { currentThreadId: l } = rt(), { state: c, seed: u, onEvent: g, dispatch: m } = uo(), {
4531
+ threadCheckpoints: I,
4529
4532
  threadTimeline: p,
4530
4533
  checkpointIndex: y,
4531
4534
  isLoadingThread: v,
@@ -4534,11 +4537,11 @@ function vs({
4534
4537
  loadThread: L,
4535
4538
  navigateToCheckpoint: z,
4536
4539
  setCurrentCheckpointId: w,
4537
- returnToLatest: I,
4540
+ returnToLatest: k,
4538
4541
  handleValuesEvent: F,
4539
4542
  markSkipNextLoad: $,
4540
- markStreamPendingThread: B,
4541
- resetHistoryState: D
4543
+ markStreamPendingThread: D,
4544
+ resetHistoryState: V
4542
4545
  } = vn({
4543
4546
  api: i,
4544
4547
  fileApi: f,
@@ -4548,24 +4551,24 @@ function vs({
4548
4551
  initialThreadId: t,
4549
4552
  initialCheckpointId: n,
4550
4553
  initialCheckpointNs: r,
4551
- autoLoadInitial: s,
4552
- isStreaming: o,
4554
+ autoLoadInitial: o,
4555
+ isStreaming: s,
4553
4556
  getMessages: C(() => c.messages, [c.messages])
4554
4557
  });
4555
- oe(() => {
4556
- l || (u([], {}), D());
4557
- }, [l, u, D]);
4558
- const M = V(null), Q = C(
4558
+ se(() => {
4559
+ l || (u([], {}), V());
4560
+ }, [l, u, V]);
4561
+ const E = K(null), Y = C(
4559
4562
  (d) => {
4560
- M.current = d;
4563
+ E.current = d;
4561
4564
  },
4562
4565
  []
4563
- ), G = V(null), re = C(
4566
+ ), W = K(null), re = C(
4564
4567
  (d) => {
4565
- G.current = d;
4568
+ W.current = d;
4566
4569
  },
4567
4570
  []
4568
- ), te = pe(() => ({ assemblingMessageId: c.assemblingId ?? null }), [c.assemblingId]), se = C(
4571
+ ), te = pe(() => ({ assemblingMessageId: c.assemblingId ?? null }), [c.assemblingId]), oe = C(
4569
4572
  (d, R) => {
4570
4573
  const _ = bn(d, "user");
4571
4574
  return m({
@@ -4578,8 +4581,8 @@ function vs({
4578
4581
  },
4579
4582
  [m]
4580
4583
  ), S = C(async () => {
4581
- M.current ? await M.current() : (u([], {}), D());
4582
- }, [u, D]), E = pe(() => Ar(c.messages), [c.messages]), O = pe(
4584
+ E.current ? await E.current() : (u([], {}), V());
4585
+ }, [u, V]), P = pe(() => Ar(c.messages), [c.messages]), O = pe(
4583
4586
  () => ({
4584
4587
  threadId: l,
4585
4588
  messages: c.messages,
@@ -4589,7 +4592,7 @@ function vs({
4589
4592
  id: c.lastCheckpointId ?? null,
4590
4593
  namespace: c.lastCheckpointNs ?? null
4591
4594
  },
4592
- checkpoints: k,
4595
+ checkpoints: I,
4593
4596
  checkpointIndex: y,
4594
4597
  timelineCheckpoints: p,
4595
4598
  metadata: te,
@@ -4611,22 +4614,22 @@ function vs({
4611
4614
  clearState: S,
4612
4615
  navigateToCheckpoint: z,
4613
4616
  setCurrentCheckpointId: w,
4614
- returnToLatest: I,
4617
+ returnToLatest: k,
4615
4618
  loadThread: async (d, R, _) => {
4616
4619
  await L(d, R, { clearProgress: !1 });
4617
4620
  },
4618
4621
  clearThread: S,
4619
4622
  respondToInterrupt: async (d, R, _) => {
4620
- G.current && await G.current(d, R, _);
4623
+ W.current && await W.current(d, R, _);
4621
4624
  },
4622
4625
  messagePreviews: y.messagePreviews,
4623
4626
  handleValuesEvent: F,
4624
4627
  markSkipNextLoad: $,
4625
- markStreamPendingThread: B,
4626
- resetHistoryState: D,
4627
- pushUser: se,
4628
+ markStreamPendingThread: D,
4629
+ resetHistoryState: V,
4630
+ pushUser: oe,
4628
4631
  onEvent: g,
4629
- artifacts: E
4632
+ artifacts: P
4630
4633
  }),
4631
4634
  [
4632
4635
  l,
@@ -4636,7 +4639,7 @@ function vs({
4636
4639
  c.lastCheckpointId,
4637
4640
  c.lastCheckpointNs,
4638
4641
  c.values,
4639
- k,
4642
+ I,
4640
4643
  p,
4641
4644
  y,
4642
4645
  te,
@@ -4647,41 +4650,41 @@ function vs({
4647
4650
  S,
4648
4651
  z,
4649
4652
  w,
4650
- I,
4653
+ k,
4651
4654
  L,
4652
4655
  F,
4653
4656
  $,
4654
- B,
4655
- se,
4657
+ D,
4658
+ oe,
4656
4659
  g,
4657
- E
4660
+ P
4658
4661
  ]
4659
- ), K = pe(
4662
+ ), H = pe(
4660
4663
  () => ({
4661
- registerClearThread: Q,
4664
+ registerClearThread: Y,
4662
4665
  registerRespondToInterrupt: re
4663
4666
  }),
4664
- [Q, re]
4667
+ [Y, re]
4665
4668
  );
4666
- return /* @__PURE__ */ Ce(An.Provider, { value: K, children: /* @__PURE__ */ Ce(Tn.Provider, { value: O, children: e }) });
4669
+ return /* @__PURE__ */ Ce(An.Provider, { value: H, children: /* @__PURE__ */ Ce(Tn.Provider, { value: O, children: e }) });
4667
4670
  }
4668
- const xn = Ge(null), Ts = Ge(!1);
4669
- function As({
4671
+ const xn = Ge(null), Ao = Ge(!1);
4672
+ function So({
4670
4673
  children: e,
4671
4674
  onError: t,
4672
4675
  onAuthError: n,
4673
4676
  onConnectionError: r,
4674
- onToolEnd: s,
4675
- onUpdateEvent: o,
4677
+ onToolEnd: o,
4678
+ onUpdateEvent: s,
4676
4679
  onCustomEvent: a,
4677
4680
  onMetadataEvent: i,
4678
4681
  onFinish: f,
4679
4682
  onStreamingChange: l
4680
4683
  }) {
4681
- const { chatApi: c, baseUrl: u } = We(), g = u, m = Le(t), k = Le(n), p = Le(r), y = Le(s), v = Le(o), A = Le(a), x = Le(i), L = Le(f), z = Le(l), w = pe(
4684
+ const { chatApi: c, baseUrl: u } = We(), g = u, m = Le(t), I = Le(n), p = Le(r), y = Le(o), v = Le(s), A = Le(a), x = Le(i), L = Le(f), z = Le(l), w = pe(
4682
4685
  () => ({
4683
4686
  onError: m,
4684
- onAuthError: k,
4687
+ onAuthError: I,
4685
4688
  onConnectionError: p,
4686
4689
  onMetadataEvent: x,
4687
4690
  onCustomEvent: A,
@@ -4691,7 +4694,7 @@ function As({
4691
4694
  }),
4692
4695
  [
4693
4696
  m,
4694
- k,
4697
+ I,
4695
4698
  p,
4696
4699
  x,
4697
4700
  A,
@@ -4700,8 +4703,8 @@ function As({
4700
4703
  L
4701
4704
  ]
4702
4705
  );
4703
- return /* @__PURE__ */ Ce(Ts.Provider, { value: !0, children: /* @__PURE__ */ Ce(
4704
- Ss,
4706
+ return /* @__PURE__ */ Ce(Ao.Provider, { value: !0, children: /* @__PURE__ */ Ce(
4707
+ xo,
4705
4708
  {
4706
4709
  api: c,
4707
4710
  streamBaseUrl: g,
@@ -4711,29 +4714,29 @@ function As({
4711
4714
  }
4712
4715
  ) });
4713
4716
  }
4714
- function Ss({
4717
+ function xo({
4715
4718
  children: e,
4716
4719
  api: t,
4717
4720
  streamBaseUrl: n,
4718
4721
  handlers: r,
4719
- onStreamingChange: s
4722
+ onStreamingChange: o
4720
4723
  }) {
4721
- const { setCurrentThreadId: o, currentThreadIdRef: a, addThreadFromEvent: i, currentThreadId: f } = rt(), {
4724
+ const { setCurrentThreadId: s, currentThreadIdRef: a, addThreadFromEvent: i, currentThreadId: f } = rt(), {
4722
4725
  interrupt: l,
4723
4726
  checkpoint: c,
4724
4727
  timelineCheckpoints: u,
4725
4728
  handleValuesEvent: g,
4726
4729
  markSkipNextLoad: m,
4727
- markStreamPendingThread: k,
4730
+ markStreamPendingThread: I,
4728
4731
  resetHistoryState: p,
4729
4732
  pushUser: y,
4730
4733
  onEvent: v,
4731
4734
  messages: A
4732
- } = Sn(), { registerClearThread: x, registerRespondToInterrupt: L } = Is(), z = C(
4735
+ } = Sn(), { registerClearThread: x, registerRespondToInterrupt: L } = vo(), z = C(
4733
4736
  (d) => {
4734
- i(d), k(d.threadId), a.current !== d.threadId && ((d.created ?? !a.current) && m(d.threadId), o(d.threadId));
4737
+ i(d), I(d.threadId), a.current !== d.threadId && ((d.created ?? !a.current) && m(d.threadId), s(d.threadId));
4735
4738
  },
4736
- [i, m, k, o, a]
4739
+ [i, m, I, s, a]
4737
4740
  ), w = Zr({
4738
4741
  baseUrl: n,
4739
4742
  onEvent: v,
@@ -4751,77 +4754,77 @@ function Ss({
4751
4754
  onToolEnd: r.onToolEnd,
4752
4755
  handleValuesEvent: g
4753
4756
  });
4754
- oe(() => {
4755
- s == null || s(w.isStreaming);
4756
- }, [w.isStreaming, s]);
4757
- const { stream: I, stop: F, clear: $, isStreaming: B, error: D, connected: M, streamedMessages: Q, activeMessageId: G } = w;
4758
- oe(() => {
4757
+ se(() => {
4758
+ o == null || o(w.isStreaming);
4759
+ }, [w.isStreaming, o]);
4760
+ const { stream: k, stop: F, clear: $, isStreaming: D, error: V, connected: E, streamedMessages: Y, activeMessageId: W } = w;
4761
+ se(() => {
4759
4762
  f !== void 0 && $();
4760
4763
  }, [f, $]);
4761
4764
  const re = C(
4762
4765
  async (d, R) => {
4763
- await I(d, R);
4766
+ await k(d, R);
4764
4767
  },
4765
- [I]
4766
- ), te = V(c);
4767
- oe(() => {
4768
+ [k]
4769
+ ), te = K(c);
4770
+ se(() => {
4768
4771
  te.current = c;
4769
4772
  }, [c]);
4770
- const se = C(
4773
+ const oe = C(
4771
4774
  async (d, R, _) => {
4772
4775
  const T = a.current;
4773
4776
  if (!T)
4774
4777
  throw new Error("No active thread to handle interrupt");
4775
- const P = d ? R ?? !0 : !1, J = te.current, h = (_ == null ? void 0 : _.checkpointId) ?? J.id ?? void 0, U = (_ == null ? void 0 : _.checkpointNs) ?? J.namespace ?? void 0, H = {
4778
+ const M = d ? R ?? !0 : !1, J = te.current, h = (_ == null ? void 0 : _.checkpointId) ?? J.id ?? void 0, U = (_ == null ? void 0 : _.checkpointNs) ?? J.namespace ?? void 0, B = {
4776
4779
  threadId: T,
4777
4780
  checkpointId: h,
4778
4781
  checkpointNs: U,
4779
- command: { kind: "resume", value: P },
4782
+ command: { kind: "resume", value: M },
4780
4783
  payload: _ == null ? void 0 : _.payload
4781
4784
  };
4782
- re(H);
4785
+ re(B);
4783
4786
  },
4784
4787
  [a, re]
4785
4788
  );
4786
- oe(() => {
4787
- L(se);
4788
- }, [se, L]);
4789
+ se(() => {
4790
+ L(oe);
4791
+ }, [oe, L]);
4789
4792
  const S = C(async () => {
4790
- F(), $(), p(), o(null);
4791
- }, [$, p, o, F]);
4792
- oe(() => {
4793
+ F(), $(), p(), s(null);
4794
+ }, [$, p, s, F]);
4795
+ se(() => {
4793
4796
  x(S);
4794
4797
  }, [S, x]);
4795
- const E = C(
4798
+ const P = C(
4796
4799
  async (d, R) => {
4797
- B && F();
4800
+ D && F();
4798
4801
  let _ = a.current;
4799
- const T = (d == null ? void 0 : d.text) ?? "", P = (d == null ? void 0 : d.attachments) ?? [], J = (T == null ? void 0 : T.trim()) ?? "", h = { ...(d == null ? void 0 : d.payload) ?? {} }, U = Array.isArray(h.messages) ? h.messages : void 0;
4802
+ const T = (d == null ? void 0 : d.text) ?? "", M = (d == null ? void 0 : d.attachments) ?? [], J = (T == null ? void 0 : T.trim()) ?? "", h = { ...(d == null ? void 0 : d.payload) ?? {} }, U = Array.isArray(h.messages) ? h.messages : void 0;
4800
4803
  U && delete h.messages;
4801
- const H = !!(U && U.length), Y = !!(d.contentParts && d.contentParts.length > 0);
4802
- if (!_ && !J && P.length === 0 && !H && !Y) return;
4804
+ const B = !!(U && U.length), G = !!(d.contentParts && d.contentParts.length > 0);
4805
+ if (!_ && !J && M.length === 0 && !B && !G) return;
4803
4806
  if (!_) {
4804
4807
  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);
4805
- _ = `${Ae}${Ke}`, m(_), o(_);
4808
+ _ = `${Ae}${Ke}`, m(_), s(_);
4806
4809
  }
4807
4810
  let N = null;
4808
4811
  d.contentParts && d.contentParts.length > 0 && (N = d.contentParts);
4809
- const { contentParts: ae, filesInfo: W } = N ? { contentParts: N, filesInfo: [] } : await Vr(P), Z = [...ae];
4812
+ const { contentParts: ae, filesInfo: X } = N ? { contentParts: N, filesInfo: [] } : await Vr(M), Z = [...ae];
4810
4813
  J && Z.push({ type: "text", text: T });
4811
- const X = d == null ? void 0 : d.originalMessageId, Ie = !!(d != null && d.edit && X), Fe = !H && Z.length > 0;
4814
+ const Q = d == null ? void 0 : d.originalMessageId, ve = !!(d != null && d.edit && Q), Fe = !B && Z.length > 0;
4812
4815
  let le = null;
4813
4816
  if (Fe) {
4814
- const Ae = Ie ? X : `msg-${Date.now()}`;
4817
+ const Ae = ve ? Q : `msg-${Date.now()}`;
4815
4818
  le = bn({
4816
4819
  id: Ae,
4817
4820
  role: "user",
4818
4821
  content: Z,
4819
4822
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4820
- }, "user"), Ie ? y(le, { editingMessageId: X }) : y(le);
4823
+ }, "user"), ve ? y(le, { editingMessageId: Q }) : y(le);
4821
4824
  }
4822
- const Me = H ? U : le ? [le] : [], Oe = {
4825
+ const Me = B ? U : le ? [le] : [], Oe = {
4823
4826
  ...h,
4824
- ...W.length ? { files_info: W } : {}
4827
+ ...X.length ? { files_info: X } : {}
4825
4828
  };
4826
4829
  Me.length ? Oe.messages = Me : "messages" in Oe || (Oe.messages = []);
4827
4830
  const Xe = (d == null ? void 0 : d.checkpointId) ?? c.id ?? void 0;
@@ -4840,23 +4843,23 @@ function Ss({
4840
4843
  };
4841
4844
  return re(Te, R);
4842
4845
  },
4843
- [c, a, B, m, y, re, F, u]
4846
+ [c, a, D, m, y, re, F, u]
4844
4847
  ), O = pe(() => {
4845
- const d = Object.keys(Q).length > 0;
4846
- if (!B && !d)
4848
+ const d = Object.keys(Y).length > 0;
4849
+ if (!D && !d)
4847
4850
  return A;
4848
4851
  const R = /* @__PURE__ */ new Map();
4849
- return A.forEach((_) => R.set(_.id, _)), Object.values(Q).forEach((_) => {
4852
+ return A.forEach((_) => R.set(_.id, _)), Object.values(Y).forEach((_) => {
4850
4853
  R.set(_.id, _);
4851
4854
  }), Array.from(R.values());
4852
- }, [B, Q, A]), K = pe(
4855
+ }, [D, Y, A]), H = pe(
4853
4856
  () => ({
4854
- isStreaming: B,
4855
- error: D,
4856
- connectionState: D ? "error" : B ? M ? "connected" : "connecting" : "idle",
4857
+ isStreaming: D,
4858
+ error: V,
4859
+ connectionState: V ? "error" : D ? E ? "connected" : "connecting" : "idle",
4857
4860
  messages: O,
4858
- activeMessageId: G,
4859
- submit: E,
4861
+ activeMessageId: W,
4862
+ submit: P,
4860
4863
  stop: F,
4861
4864
  interrupt: l,
4862
4865
  resume: () => Promise.resolve(),
@@ -4865,13 +4868,13 @@ function Ss({
4865
4868
  }
4866
4869
  // TODO: Implement error clearing
4867
4870
  }),
4868
- [B, D, E, F, l, M, O]
4871
+ [D, V, P, F, l, E, O]
4869
4872
  );
4870
- return /* @__PURE__ */ Ce(xn.Provider, { value: K, children: e });
4873
+ return /* @__PURE__ */ Ce(xn.Provider, { value: H, children: e });
4871
4874
  }
4872
4875
  function Le(e) {
4873
- const t = V(e);
4874
- return oe(() => {
4876
+ const t = K(e);
4877
+ return se(() => {
4875
4878
  t.current = e;
4876
4879
  }, [e]), C((...n) => {
4877
4880
  const r = t.current;
@@ -4879,47 +4882,47 @@ function Le(e) {
4879
4882
  return r(...n);
4880
4883
  }, []);
4881
4884
  }
4882
- function xs() {
4883
- const e = ot(xn);
4885
+ function Co() {
4886
+ const e = st(xn);
4884
4887
  if (!e) throw new Error("useStream must be used within StreamingProvider");
4885
4888
  return e;
4886
4889
  }
4887
4890
  function Zt(e) {
4888
4891
  return typeof e == "object" && e !== null;
4889
4892
  }
4890
- function Cs(e, t) {
4893
+ function Mo(e, t) {
4891
4894
  if (Object.is(e, t)) return !0;
4892
4895
  if (!Zt(e) || !Zt(t)) return !1;
4893
4896
  const n = Object.keys(e), r = Object.keys(t);
4894
4897
  if (n.length !== r.length)
4895
4898
  return !1;
4896
- for (const s of n)
4897
- if (!Object.prototype.hasOwnProperty.call(t, s) || !Object.is(e[s], t[s]))
4899
+ for (const o of n)
4900
+ if (!Object.prototype.hasOwnProperty.call(t, o) || !Object.is(e[o], t[o]))
4898
4901
  return !1;
4899
4902
  return !0;
4900
4903
  }
4901
- function Ms(e) {
4902
- const t = V(e), n = V(e);
4903
- return Cs(t.current, e) || (t.current = e, n.current = e), n.current;
4904
+ function Eo(e) {
4905
+ const t = K(e), n = K(e);
4906
+ return Mo(t.current, e) || (t.current = e, n.current = e), n.current;
4904
4907
  }
4905
- function Es(e) {
4906
- 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;
4907
- return typeof s == "string" ? s : null;
4908
+ function Po(e) {
4909
+ 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, o = (r == null ? void 0 : r.task_id) ?? (r == null ? void 0 : r.taskId) ?? null;
4910
+ return typeof o == "string" ? o : null;
4908
4911
  }
4909
- function Qs(e) {
4912
+ function Yo(e) {
4910
4913
  const { setCurrentTaskId: t, getCurrentTaskId: n, onToolEnd: r } = e;
4911
- return (s) => {
4912
- const o = Es(s), a = (n == null ? void 0 : n()) ?? null;
4913
- o && o !== a && t(o), r == null || r(s);
4914
+ return (o) => {
4915
+ const s = Po(o), a = (n == null ? void 0 : n()) ?? null;
4916
+ s && s !== a && t(s), r == null || r(o);
4914
4917
  };
4915
4918
  }
4916
- function Ys({
4919
+ function Zo({
4917
4920
  children: e,
4918
4921
  apiConfig: t,
4919
4922
  initialThreadId: n = null,
4920
4923
  initialCheckpointId: r = null,
4921
- initialCheckpointNs: s = null,
4922
- autoLoadInitial: o = !0,
4924
+ initialCheckpointNs: o = null,
4925
+ autoLoadInitial: s = !0,
4923
4926
  onConnectionError: a,
4924
4927
  onError: i,
4925
4928
  onAuthError: f,
@@ -4928,49 +4931,49 @@ function Ys({
4928
4931
  onUpdateEvent: u,
4929
4932
  onCustomEvent: g,
4930
4933
  onMetadataEvent: m,
4931
- onFinish: k
4934
+ onFinish: I
4932
4935
  }) {
4933
- const p = Ms(t), [y, v] = q(!1), A = ze(i), x = ze(f), L = ze(a), z = ze(l), w = ze(c), I = ze(u), F = ze(g), $ = ze(m), B = ze(k), D = pe(
4936
+ const p = Eo(t), [y, v] = q(!1), A = ze(i), x = ze(f), L = ze(a), z = ze(l), w = ze(c), k = ze(u), F = ze(g), $ = ze(m), D = ze(I), V = pe(
4934
4937
  () => ({
4935
4938
  onError: A,
4936
4939
  onAuthError: x,
4937
4940
  onConnectionError: L,
4938
4941
  onToolEnd: w,
4939
- onUpdateEvent: I,
4942
+ onUpdateEvent: k,
4940
4943
  onCustomEvent: F,
4941
4944
  onMetadataEvent: $,
4942
- onFinish: B
4945
+ onFinish: D
4943
4946
  }),
4944
4947
  [
4945
4948
  A,
4946
4949
  x,
4947
4950
  L,
4948
4951
  w,
4949
- I,
4952
+ k,
4950
4953
  F,
4951
4954
  $,
4952
- B
4955
+ D
4953
4956
  ]
4954
4957
  );
4955
4958
  return /* @__PURE__ */ Ce(Br, { apiConfig: p, children: /* @__PURE__ */ Ce(
4956
- rs,
4959
+ ro,
4957
4960
  {
4958
4961
  initialThreadId: n,
4959
4962
  onError: A,
4960
4963
  onThreadChange: z,
4961
4964
  children: /* @__PURE__ */ Ce(
4962
- vs,
4965
+ To,
4963
4966
  {
4964
4967
  initialThreadId: n,
4965
4968
  initialCheckpointId: r,
4966
- initialCheckpointNs: s,
4967
- autoLoadInitial: o,
4969
+ initialCheckpointNs: o,
4970
+ autoLoadInitial: s,
4968
4971
  onError: A,
4969
4972
  isStreaming: y,
4970
4973
  children: /* @__PURE__ */ Ce(
4971
- As,
4974
+ So,
4972
4975
  {
4973
- ...D,
4976
+ ...V,
4974
4977
  onStreamingChange: v,
4975
4978
  children: e
4976
4979
  }
@@ -4981,34 +4984,34 @@ function Ys({
4981
4984
  ) });
4982
4985
  }
4983
4986
  function ze(e) {
4984
- const t = V(e);
4987
+ const t = K(e);
4985
4988
  return t.current = e, C((...n) => {
4986
4989
  const r = t.current;
4987
4990
  if (r)
4988
4991
  return r(...n);
4989
4992
  }, []);
4990
4993
  }
4991
- const Ps = 1, Ns = 1e6;
4994
+ const No = 1, Ro = 1e6;
4992
4995
  let Et = 0;
4993
- function Rs() {
4996
+ function _o() {
4994
4997
  return Et = (Et + 1) % Number.MAX_SAFE_INTEGER, Et.toString();
4995
4998
  }
4996
4999
  const Pt = /* @__PURE__ */ new Map(), en = (e) => {
4997
5000
  if (Pt.has(e))
4998
5001
  return;
4999
5002
  const t = setTimeout(() => {
5000
- Pt.delete(e), st({
5003
+ Pt.delete(e), ot({
5001
5004
  type: "REMOVE_TOAST",
5002
5005
  toastId: e
5003
5006
  });
5004
- }, Ns);
5007
+ }, Ro);
5005
5008
  Pt.set(e, t);
5006
- }, _s = (e, t) => {
5009
+ }, Lo = (e, t) => {
5007
5010
  switch (t.type) {
5008
5011
  case "ADD_TOAST":
5009
5012
  return {
5010
5013
  ...e,
5011
- toasts: [t.toast, ...e.toasts].slice(0, Ps)
5014
+ toasts: [t.toast, ...e.toasts].slice(0, No)
5012
5015
  };
5013
5016
  case "UPDATE_TOAST":
5014
5017
  return {
@@ -5042,24 +5045,24 @@ const Pt = /* @__PURE__ */ new Map(), en = (e) => {
5042
5045
  }
5043
5046
  }, gt = [];
5044
5047
  let mt = { toasts: [] };
5045
- function st(e) {
5046
- mt = _s(mt, e), gt.forEach((t) => {
5048
+ function ot(e) {
5049
+ mt = Lo(mt, e), gt.forEach((t) => {
5047
5050
  t(mt);
5048
5051
  });
5049
5052
  }
5050
- function Ls({ ...e }) {
5051
- const t = Rs(), n = (s) => st({
5053
+ function zo({ ...e }) {
5054
+ const t = _o(), n = (o) => ot({
5052
5055
  type: "UPDATE_TOAST",
5053
- toast: { ...s, id: t }
5054
- }), r = () => st({ type: "DISMISS_TOAST", toastId: t });
5055
- return st({
5056
+ toast: { ...o, id: t }
5057
+ }), r = () => ot({ type: "DISMISS_TOAST", toastId: t });
5058
+ return ot({
5056
5059
  type: "ADD_TOAST",
5057
5060
  toast: {
5058
5061
  ...e,
5059
5062
  id: t,
5060
5063
  open: !0,
5061
- onOpenChange: (s) => {
5062
- s || r();
5064
+ onOpenChange: (o) => {
5065
+ o || r();
5063
5066
  }
5064
5067
  }
5065
5068
  }), {
@@ -5068,57 +5071,57 @@ function Ls({ ...e }) {
5068
5071
  update: n
5069
5072
  };
5070
5073
  }
5071
- function zs() {
5074
+ function Fo() {
5072
5075
  const [e, t] = Dt.useState(mt);
5073
5076
  return Dt.useEffect(() => (gt.push(t), () => {
5074
5077
  const n = gt.indexOf(t);
5075
5078
  n > -1 && gt.splice(n, 1);
5076
5079
  }), [e]), {
5077
5080
  ...e,
5078
- toast: Ls,
5079
- dismiss: (n) => st({ type: "DISMISS_TOAST", toastId: n })
5081
+ toast: zo,
5082
+ dismiss: (n) => ot({ type: "DISMISS_TOAST", toastId: n })
5080
5083
  };
5081
5084
  }
5082
- function Zs(e) {
5083
- const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = We(), { toast: s } = zs(), [o, a] = q({}), [i, f] = q(null), [l, c] = q(!1), u = C(() => {
5085
+ function es(e) {
5086
+ const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = We(), { toast: o } = Fo(), [s, a] = q({}), [i, f] = q(null), [l, c] = q(!1), u = C(() => {
5084
5087
  c(!1), f(null);
5085
- }, []), g = C((k) => {
5086
- f(k), c(!0);
5088
+ }, []), g = C((I) => {
5089
+ f(I), c(!0);
5087
5090
  }, []), m = C(
5088
- async (k, p, y) => {
5091
+ async (I, p, y) => {
5089
5092
  var v, A;
5090
5093
  if (!t) {
5091
- k.preventDefault();
5094
+ I.preventDefault();
5092
5095
  return;
5093
5096
  }
5094
- if (o[y]) {
5095
- k.preventDefault();
5097
+ if (s[y]) {
5098
+ I.preventDefault();
5096
5099
  return;
5097
5100
  }
5098
5101
  try {
5099
5102
  const x = String(p.url ?? ""), L = x.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
5100
5103
  if (L) {
5101
- k.preventDefault();
5102
- const z = L[1], w = p.name || `file_${z}`, I = p.mimeType || "application/octet-stream";
5103
- g({ id: z, name: w, mimeType: I });
5104
+ I.preventDefault();
5105
+ const z = L[1], w = p.name || `file_${z}`, k = p.mimeType || "application/octet-stream";
5106
+ g({ id: z, name: w, mimeType: k });
5104
5107
  return;
5105
5108
  }
5106
5109
  if (x.startsWith("data:")) {
5107
- k.preventDefault(), a((w) => ({ ...w, [y]: !0 }));
5108
- const z = s({ title: "Fetching file...", description: "", open: !0 });
5110
+ I.preventDefault(), a((w) => ({ ...w, [y]: !0 }));
5111
+ const z = o({ title: "Fetching file...", description: "", open: !0 });
5109
5112
  try {
5110
5113
  const w = await r.listFiles(n ?? void 0);
5111
5114
  if (!w || !Array.isArray(w))
5112
5115
  throw new Error("Invalid file list response");
5113
- const I = w.find((F) => !F || typeof F != "object" || !((F.filename ?? "") === (p.name ?? "")) ? !1 : typeof p.size == "number" && typeof F.size == "number" ? F.size === p.size : !0);
5114
- if (!(I != null && I.id))
5116
+ const k = w.find((F) => !F || typeof F != "object" || !((F.filename ?? "") === (p.name ?? "")) ? !1 : typeof p.size == "number" && typeof F.size == "number" ? F.size === p.size : !0);
5117
+ if (!(k != null && k.id))
5115
5118
  throw new Error(`File "${p.name}" is not yet available on the server`);
5116
- if (!I.id || !I.filename)
5119
+ if (!k.id || !k.filename)
5117
5120
  throw new Error("Invalid file data received from server");
5118
5121
  g({
5119
- id: I.id,
5120
- name: p.name || I.filename || `file_${I.id}`,
5121
- mimeType: p.mimeType || I.mime_type || "application/octet-stream"
5122
+ id: k.id,
5123
+ name: p.name || k.filename || `file_${k.id}`,
5124
+ mimeType: p.mimeType || k.mime_type || "application/octet-stream"
5122
5125
  }), (v = z.update) == null || v.call(z, {
5123
5126
  id: z.id,
5124
5127
  title: "Success",
@@ -5127,10 +5130,10 @@ function Zs(e) {
5127
5130
  });
5128
5131
  } catch (w) {
5129
5132
  console.error("Failed to fetch server file:", w);
5130
- const I = w instanceof Error ? w.message : "Unknown error occurred";
5131
- (A = z.update) == null || A.call(z, { id: z.id, title: "Failed", description: I }), s({
5133
+ const k = w instanceof Error ? w.message : "Unknown error occurred";
5134
+ (A = z.update) == null || A.call(z, { id: z.id, title: "Failed", description: k }), o({
5132
5135
  title: "Failed to fetch file",
5133
- description: I,
5136
+ description: k,
5134
5137
  open: !0
5135
5138
  });
5136
5139
  } finally {
@@ -5141,17 +5144,17 @@ function Zs(e) {
5141
5144
  console.error("File click error:", x), a((L) => ({ ...L, [y]: !1 }));
5142
5145
  }
5143
5146
  },
5144
- [t, o, s, n, g]
5147
+ [t, s, o, n, g]
5145
5148
  );
5146
5149
  return {
5147
- uploadingFiles: o,
5150
+ uploadingFiles: s,
5148
5151
  handleFileClick: m,
5149
5152
  fileViewerOpen: l,
5150
5153
  currentFileInfo: i,
5151
5154
  closeFileViewer: u
5152
5155
  };
5153
5156
  }
5154
- function eo(e) {
5157
+ function ts(e) {
5155
5158
  return pe(() => {
5156
5159
  const t = e;
5157
5160
  let n = Array.isArray(t.content) ? t.content : [];
@@ -5167,22 +5170,22 @@ function eo(e) {
5167
5170
  }, [e]);
5168
5171
  }
5169
5172
  const tn = "data:";
5170
- function Fs(e) {
5173
+ function Uo(e) {
5171
5174
  if (!e) return [];
5172
5175
  const t = [], n = e.split(/\r?\n/);
5173
5176
  for (const r of n) {
5174
- const s = r.trim();
5175
- if (!s || !s.startsWith(tn))
5177
+ const o = r.trim();
5178
+ if (!o || !o.startsWith(tn))
5176
5179
  continue;
5177
- const o = s.slice(tn.length).trim();
5178
- if (!o || o.toLowerCase() === "[done]")
5180
+ const s = o.slice(tn.length).trim();
5181
+ if (!s || s.toLowerCase() === "[done]")
5179
5182
  continue;
5180
- const a = Ft(o);
5183
+ const a = Ft(s);
5181
5184
  a && typeof a == "object" && t.push(a);
5182
5185
  }
5183
5186
  return t;
5184
5187
  }
5185
- function Us(e) {
5188
+ function jo(e) {
5186
5189
  for (let t = e.length - 1; t >= 0; t -= 1) {
5187
5190
  const n = e[t];
5188
5191
  if (n && typeof n == "object" && n.type === "tool.end")
@@ -5190,7 +5193,7 @@ function Us(e) {
5190
5193
  }
5191
5194
  return null;
5192
5195
  }
5193
- function to(e) {
5196
+ function ns(e) {
5194
5197
  return pe(() => {
5195
5198
  const t = e.content.filter(
5196
5199
  (f) => f.type === "text"
@@ -5198,7 +5201,7 @@ function to(e) {
5198
5201
  if (!t.length)
5199
5202
  return null;
5200
5203
  let r = t.flatMap(
5201
- (f) => Fs(f.text ?? "")
5204
+ (f) => Uo(f.text ?? "")
5202
5205
  );
5203
5206
  if (!r.length) {
5204
5207
  const f = t.map((c) => c.text ?? "").join(`
@@ -5207,25 +5210,25 @@ function to(e) {
5207
5210
  }
5208
5211
  if (!r.length)
5209
5212
  return null;
5210
- const o = Us(r) ?? r[r.length - 1];
5211
- if (!o)
5213
+ const s = jo(r) ?? r[r.length - 1];
5214
+ if (!s)
5212
5215
  return null;
5213
- const a = o.output ?? o.payload ?? o, i = Ee(a);
5216
+ const a = s.output ?? s.payload ?? s, i = Ee(a);
5214
5217
  return i && typeof i == "object" && !Array.isArray(i) ? {
5215
5218
  kind: "dict",
5216
5219
  value: i,
5217
5220
  data: i,
5218
- event: o
5221
+ event: s
5219
5222
  } : {
5220
5223
  kind: "generic",
5221
5224
  value: i,
5222
- event: o
5225
+ event: s
5223
5226
  };
5224
5227
  }, [e]);
5225
5228
  }
5226
- function js(e) {
5229
+ function Oo(e) {
5227
5230
  var z;
5228
- const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, { currentThreadId: n, setCurrentThreadId: r, actions: s } = rt(), o = Sn({ optional: !0 }), a = xs(), i = !!t && t !== n, [f, l] = q([]), c = C((w) => {
5231
+ const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, { currentThreadId: n, setCurrentThreadId: r, actions: o } = rt(), s = Sn({ optional: !0 }), a = Co(), i = !!t && t !== n, [f, l] = q([]), c = C((w) => {
5229
5232
  l(w);
5230
5233
  }, []), {
5231
5234
  isLoadingThread: u,
@@ -5240,10 +5243,10 @@ function js(e) {
5240
5243
  isStreaming: !1,
5241
5244
  getMessages: () => f,
5242
5245
  autoLoadInitial: !0
5243
- }), k = pe(() => {
5246
+ }), I = pe(() => {
5244
5247
  var w;
5245
5248
  return ((w = m[0]) == null ? void 0 : w.values) || {};
5246
- }, [m]), p = t || n, y = i ? f : (a == null ? void 0 : a.messages) || [], v = i ? u : (o == null ? void 0 : o.isLoading) || !1, A = i ? k : (o == null ? void 0 : o.values) || {}, x = i ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, L = i ? g : (a == null ? void 0 : a.error) || (o == null ? void 0 : o.error) || null;
5249
+ }, [m]), p = t || n, y = i ? f : (a == null ? void 0 : a.messages) || [], v = i ? u : (s == null ? void 0 : s.isLoading) || !1, A = i ? I : (s == null ? void 0 : s.values) || {}, x = i ? {} : (s == null ? void 0 : s.taskMessagesByScope) || {}, L = i ? g : (a == null ? void 0 : a.error) || (s == null ? void 0 : s.error) || null;
5247
5250
  return {
5248
5251
  // UNIFIED: Single thread ID concept
5249
5252
  threadId: p,
@@ -5254,48 +5257,48 @@ function js(e) {
5254
5257
  // Values & Metadata
5255
5258
  values: A,
5256
5259
  taskMessagesByScope: x,
5257
- metadata: o == null ? void 0 : o.metadata,
5260
+ metadata: s == null ? void 0 : s.metadata,
5258
5261
  // Actions & State relating to Global/Active Thread only
5259
- navigateToCheckpoint: (o == null ? void 0 : o.navigateToCheckpoint) || (async () => {
5262
+ navigateToCheckpoint: (s == null ? void 0 : s.navigateToCheckpoint) || (async () => {
5260
5263
  }),
5261
- returnToLatest: (o == null ? void 0 : o.returnToLatest) || (async () => {
5264
+ returnToLatest: (s == null ? void 0 : s.returnToLatest) || (async () => {
5262
5265
  }),
5263
- checkpoint: (o == null ? void 0 : o.checkpoint) || null,
5264
- checkpoints: (o == null ? void 0 : o.checkpoints) || [],
5265
- checkpointIndex: (o == null ? void 0 : o.checkpointIndex) || { timeline: [], messagePreviews: {} },
5266
- interrupt: (o == null ? void 0 : o.interrupt) || null,
5267
- respondToInterrupt: (o == null ? void 0 : o.respondToInterrupt) || (async () => {
5266
+ checkpoint: (s == null ? void 0 : s.checkpoint) || null,
5267
+ checkpoints: (s == null ? void 0 : s.checkpoints) || [],
5268
+ checkpointIndex: (s == null ? void 0 : s.checkpointIndex) || { timeline: [], messagePreviews: {} },
5269
+ interrupt: (s == null ? void 0 : s.interrupt) || null,
5270
+ respondToInterrupt: (s == null ? void 0 : s.respondToInterrupt) || (async () => {
5268
5271
  }),
5269
5272
  // Streaming Status
5270
5273
  // Even in standalone mode, allow streaming state/stop if a stream context exists.
5271
5274
  isStreaming: (a == null ? void 0 : a.isStreaming) || !1,
5272
5275
  activeMessageId: (a == null ? void 0 : a.activeMessageId) || null,
5273
5276
  connectionState: (a == null ? void 0 : a.connectionState) || "disconnected",
5274
- streamingAssistantId: a != null && a.isStreaming && ((z = o == null ? void 0 : o.metadata) != null && z.assemblingMessageId) ? o.metadata.assemblingMessageId : null,
5277
+ streamingAssistantId: a != null && a.isStreaming && ((z = s == null ? void 0 : s.metadata) != null && z.assemblingMessageId) ? s.metadata.assemblingMessageId : null,
5275
5278
  // Actions
5276
5279
  submit: (a == null ? void 0 : a.submit) || (async () => {
5277
5280
  }),
5278
5281
  stop: (a == null ? void 0 : a.stop) || (() => {
5279
5282
  }),
5280
- clearThread: (o == null ? void 0 : o.clearThread) || (async () => {
5283
+ clearThread: (s == null ? void 0 : s.clearThread) || (async () => {
5281
5284
  }),
5282
5285
  setCurrentThreadId: r,
5283
5286
  // Thread Management
5284
- createThread: s.createThread,
5285
- deleteThread: s.deleteThread,
5286
- renameThread: s.renameThread,
5287
- shareThread: s.shareThread,
5287
+ createThread: o.createThread,
5288
+ deleteThread: o.deleteThread,
5289
+ renameThread: o.renameThread,
5290
+ shareThread: o.shareThread,
5288
5291
  threads: rt().threads,
5289
5292
  isThreadsLoading: rt().isLoading
5290
5293
  };
5291
5294
  }
5292
- function no({
5295
+ function rs({
5293
5296
  submit: e,
5294
5297
  chatRequest: t,
5295
5298
  lastCheckpointId: n,
5296
5299
  lastCheckpointNs: r,
5297
- onMessageSent: s,
5298
- onExcelUploadSuccess: o,
5300
+ onMessageSent: o,
5301
+ onExcelUploadSuccess: s,
5299
5302
  onError: a,
5300
5303
  enableMessageEditing: i,
5301
5304
  messages: f,
@@ -5305,60 +5308,60 @@ function no({
5305
5308
  threadId: g,
5306
5309
  clearComposerOnSend: m = !0
5307
5310
  }) {
5308
- const { messages: k } = js(), [p, y] = q(null), [v, A] = q(""), [x, L] = q(null), [z, w] = q(null), [I, F] = q(!1), [$, B] = q(""), D = V($), M = V(null);
5309
- oe(() => {
5311
+ const { messages: I } = Oo(), [p, y] = q(null), [v, A] = q(""), [x, L] = q(null), [z, w] = q(null), [k, F] = q(!1), [$, D] = q(""), V = K($), E = K(null);
5312
+ se(() => {
5310
5313
  if (!p)
5311
5314
  if (g) {
5312
5315
  const d = localStorage.getItem(Mt(g));
5313
- B(d || "");
5316
+ D(d || "");
5314
5317
  } else
5315
- B("");
5318
+ D("");
5316
5319
  }, [g, p]);
5317
- const Q = C((d) => {
5318
- B(d), !p && g && localStorage.setItem(Mt(g), d);
5320
+ const Y = C((d) => {
5321
+ D(d), !p && g && localStorage.setItem(Mt(g), d);
5319
5322
  }, [g, p]);
5320
- oe(() => {
5321
- D.current = $;
5322
- }, [$]), oe(() => {
5323
+ se(() => {
5324
+ V.current = $;
5325
+ }, [$]), se(() => {
5323
5326
  if (!p) {
5324
- M.current = null;
5327
+ E.current = null;
5325
5328
  return;
5326
5329
  }
5327
- M.current === null && (M.current = D.current), Q(v ?? "");
5328
- }, [v, p, Q]);
5329
- const G = C(
5330
+ E.current === null && (E.current = V.current), Y(v ?? "");
5331
+ }, [v, p, Y]);
5332
+ const W = C(
5330
5333
  (d) => {
5331
- Q(d);
5334
+ Y(d);
5332
5335
  },
5333
- [Q]
5336
+ [Y]
5334
5337
  ), re = async (d, R) => {
5335
- const _ = Array.isArray(R) ? { files: R } : R ?? {}, T = _.files ?? [], P = _.contentParts ?? [], J = d.trim();
5336
- if (!(!J && T.length === 0 && P.length === 0))
5338
+ const _ = Array.isArray(R) ? { files: R } : R ?? {}, T = _.files ?? [], M = _.contentParts ?? [], J = d.trim();
5339
+ if (!(!J && T.length === 0 && M.length === 0))
5337
5340
  try {
5338
- const h = T.map(async (W) => {
5341
+ const h = T.map(async (X) => {
5339
5342
  try {
5340
- const Z = await hn.uploadFile(W);
5341
- return { file: W, record: Z };
5343
+ const Z = await hn.uploadFile(X);
5344
+ return { file: X, record: Z };
5342
5345
  } catch (Z) {
5343
- throw console.error("Failed to upload file", W.name, Z), new Error(`Failed to upload ${W.name}`);
5346
+ throw console.error("Failed to upload file", X.name, Z), new Error(`Failed to upload ${X.name}`);
5344
5347
  }
5345
- }), H = (await Promise.all(h)).map(({ record: W }) => {
5346
- const Z = W.mime_type;
5348
+ }), B = (await Promise.all(h)).map(({ record: X }) => {
5349
+ const Z = X.mime_type;
5347
5350
  return Z.startsWith("image/") ? {
5348
5351
  type: "image_url",
5349
- image_url: { url: W.content_url }
5352
+ image_url: { url: X.content_url }
5350
5353
  } : {
5351
5354
  type: "file",
5352
- url: W.content_url,
5355
+ url: X.content_url,
5353
5356
  mimeType: Z,
5354
- name: W.filename,
5355
- size: W.size
5357
+ name: X.filename,
5358
+ size: X.size
5356
5359
  };
5357
- }), Y = [...P, ...H], N = p ? (x == null ? void 0 : x.checkpointId) ?? n ?? void 0 : n ?? void 0, ae = p ? (x == null ? void 0 : x.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5360
+ }), G = [...M, ...B], N = p ? (x == null ? void 0 : x.checkpointId) ?? n ?? void 0 : n ?? void 0, ae = p ? (x == null ? void 0 : x.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5358
5361
  await e(
5359
5362
  {
5360
5363
  text: J || "",
5361
- contentParts: Y,
5364
+ contentParts: G,
5362
5365
  attachments: T,
5363
5366
  payload: t.payload,
5364
5367
  edit: !!p,
@@ -5369,14 +5372,14 @@ function no({
5369
5372
  config: t.config
5370
5373
  },
5371
5374
  u ? { onEvent: u } : void 0
5372
- ), s == null || s(J), l(!0), m && (g && localStorage.removeItem(Mt(g)), Q("")), w(null), y(null), A(""), L(null);
5375
+ ), o == null || o(J), l(!0), m && (g && localStorage.removeItem(Mt(g)), Y("")), w(null), y(null), A(""), L(null);
5373
5376
  } catch (h) {
5374
5377
  const U = (h == null ? void 0 : h.message) || "Failed to send message";
5375
5378
  w(U), a == null || a(U), l(!1);
5376
5379
  }
5377
5380
  }, te = (d, R) => {
5378
5381
  R || re(d, { files: [] });
5379
- }, se = C(
5382
+ }, oe = C(
5380
5383
  async (d) => {
5381
5384
  await e(
5382
5385
  {
@@ -5388,21 +5391,21 @@ function no({
5388
5391
  config: t.config
5389
5392
  },
5390
5393
  u ? { onEvent: u } : void 0
5391
- ), o == null || o({ file: d });
5394
+ ), s == null || s({ file: d });
5392
5395
  },
5393
- [n, r, t, o, e]
5396
+ [n, r, t, s, e]
5394
5397
  ), S = C(
5395
5398
  (d, R, _) => {
5396
- i && (M.current = $, y(d), A(R), L({
5399
+ i && (E.current = $, y(d), A(R), L({
5397
5400
  checkpointId: (_ == null ? void 0 : _.checkpointId) ?? null,
5398
5401
  checkpointNs: (_ == null ? void 0 : _.checkpointNs) ?? null
5399
5402
  }), w(null));
5400
5403
  },
5401
5404
  [$, i]
5402
- ), E = C(() => {
5405
+ ), P = C(() => {
5403
5406
  y(null), A(""), L(null), w(null);
5404
- const d = M.current;
5405
- d !== null && B(d), M.current = null;
5407
+ const d = E.current;
5408
+ d !== null && D(d), E.current = null;
5406
5409
  }, []), O = C((d) => {
5407
5410
  let R = null;
5408
5411
  for (let J = d - 1; J >= 0; J--)
@@ -5411,16 +5414,16 @@ function no({
5411
5414
  break;
5412
5415
  }
5413
5416
  if (!R) return;
5414
- const _ = Array.isArray(R.content) ? R.content : [], P = _.filter((J) => (J == null ? void 0 : J.type) === "text").map((J) => J.text).join("") || (() => {
5417
+ const _ = Array.isArray(R.content) ? R.content : [], M = _.filter((J) => (J == null ? void 0 : J.type) === "text").map((J) => J.text).join("") || (() => {
5415
5418
  try {
5416
5419
  return JSON.stringify(_, null, 2);
5417
5420
  } catch {
5418
5421
  return String(_);
5419
5422
  }
5420
5423
  })();
5421
- P && e(
5424
+ M && e(
5422
5425
  {
5423
- text: P,
5426
+ text: M,
5424
5427
  payload: t.payload,
5425
5428
  checkpointId: n ?? void 0,
5426
5429
  checkpointNs: r ?? void 0,
@@ -5436,22 +5439,22 @@ function no({
5436
5439
  editingInitialValue: v,
5437
5440
  inputError: z,
5438
5441
  setInputError: w,
5439
- dismissError: I,
5442
+ dismissError: k,
5440
5443
  setDismissError: F,
5441
5444
  composerValue: $,
5442
- handleComposerChange: G,
5445
+ handleComposerChange: W,
5443
5446
  handleSendMessage: re,
5444
5447
  handleQuickPrompt: te,
5445
- handleExcelUpload: se,
5448
+ handleExcelUpload: oe,
5446
5449
  startEditing: S,
5447
- cancelEditing: E,
5450
+ cancelEditing: P,
5448
5451
  handleRegenerateCb: O,
5449
- displayMessages: k
5452
+ displayMessages: I
5450
5453
  };
5451
5454
  }
5452
- function ro(e) {
5455
+ function os(e) {
5453
5456
  return pe(() => e ? {
5454
- textContent: Ir(e),
5457
+ textContent: kr(e),
5455
5458
  imageParts: vr(e),
5456
5459
  fileParts: Tr(e),
5457
5460
  toolCalls: ln(e),
@@ -5464,12 +5467,12 @@ function ro(e) {
5464
5467
  contentParts: []
5465
5468
  }, [e]);
5466
5469
  }
5467
- function so(e, t, n) {
5468
- const [r, s] = q(e), o = V(e), a = V(null);
5469
- return oe(() => {
5470
- o.current = e;
5470
+ function ss(e, t, n) {
5471
+ const [r, o] = q(e), s = K(e), a = K(null);
5472
+ return se(() => {
5473
+ s.current = e;
5471
5474
  const i = () => {
5472
- s(o.current), a.current && (clearTimeout(a.current), a.current = null);
5475
+ o(s.current), a.current && (clearTimeout(a.current), a.current = null);
5473
5476
  };
5474
5477
  if (!t || n <= 0) {
5475
5478
  i();
@@ -5483,26 +5486,26 @@ function so(e, t, n) {
5483
5486
  }, [e, t, n]), r;
5484
5487
  }
5485
5488
  export {
5486
- Ys as ChatProviders,
5487
- vs as ThreadStateProvider,
5488
- rs as ThreadsProvider,
5489
- Vs as cn,
5489
+ Zo as ChatProviders,
5490
+ To as ThreadStateProvider,
5491
+ ro as ThreadsProvider,
5492
+ Ko as cn,
5490
5493
  Kr as collectText,
5491
- Qs as createTaskSyncToolEndHandler,
5492
- Es as extractTaskIdFromToolEnd,
5494
+ Yo as createTaskSyncToolEndHandler,
5495
+ Po as extractTaskIdFromToolEnd,
5493
5496
  Hr as extractToolMeta,
5494
- Ks as formatToolOutput,
5495
- Gs as getAgentNameFromMessage,
5497
+ Ho as formatToolOutput,
5498
+ Jo as getAgentNameFromMessage,
5496
5499
  fn as getChatToken,
5497
- Xs as getMessageAttemptInfo,
5498
- qs as getToolCallArtifacts,
5500
+ Qo as getMessageAttemptInfo,
5501
+ Wo as getToolCallArtifacts,
5499
5502
  Nr as getToolCalls,
5500
- Hs as hasContent,
5503
+ qo as hasContent,
5501
5504
  Lt as hydrateHistorySnapshots,
5502
5505
  un as isFileLike,
5503
5506
  br as looksLikeMarkdown,
5504
- Js as messageSignature,
5505
- Ws as normalizeInterruptId,
5507
+ Xo as messageSignature,
5508
+ Go as normalizeInterruptId,
5506
5509
  pn as onChatTokenChanged,
5507
5510
  Ft as parseJsonSafe,
5508
5511
  dn as pretty,
@@ -5511,18 +5514,18 @@ export {
5511
5514
  Ve as setChatToken,
5512
5515
  Sr as stringifyTool,
5513
5516
  We as useApi,
5514
- no as useChatController,
5515
- js as useChatSession,
5516
- Zs as useFilePreview,
5517
- ro as useMessageContent,
5518
- eo as useParsedMessageContent,
5517
+ rs as useChatController,
5518
+ Oo as useChatSession,
5519
+ es as useFilePreview,
5520
+ os as useMessageContent,
5521
+ ts as useParsedMessageContent,
5519
5522
  Zr as useStream,
5520
- so as useStreamingMarkdownBuffer,
5523
+ ss as useStreamingMarkdownBuffer,
5521
5524
  vn as useThreadHistoryState,
5522
5525
  Sn as useThreadState,
5523
- Is as useThreadStateUpdater,
5526
+ vo as useThreadStateUpdater,
5524
5527
  rt as useThreads,
5525
- ns as useThreadsState,
5526
- to as useToolPayload
5528
+ no as useThreadsState,
5529
+ ns as useToolPayload
5527
5530
  };
5528
5531
  //# sourceMappingURL=index.esm.js.map