@teodorruskvi/chat-core 0.1.46 → 0.1.48

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,21 +1,21 @@
1
- var Kt = Object.defineProperty;
2
- var Gt = (e, t, n) => t in e ? Kt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
1
+ var Ht = Object.defineProperty;
2
+ var Gt = (e, t, n) => t in e ? Ht(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var at = (e, t, n) => Gt(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import { jsx as ie } from "react/jsx-runtime";
5
5
  import * as it from "react";
6
- import { createContext as Me, useContext as Ue, useState as B, useRef as W, useEffect as X, useCallback as _, useMemo as Y, useReducer as Wt } from "react";
6
+ import { createContext as Ce, useContext as Ue, useState as $, useRef as W, useEffect as X, useCallback as _, useMemo as Y, useReducer as Wt } from "react";
7
7
  import Jt, { isCancel as Xt } from "axios";
8
- function kt(e) {
8
+ function vt(e) {
9
9
  var t, n, r = "";
10
10
  if (typeof e == "string" || typeof e == "number") r += e;
11
11
  else if (typeof e == "object") if (Array.isArray(e)) {
12
12
  var o = e.length;
13
- for (t = 0; t < o; t++) e[t] && (n = kt(e[t])) && (r && (r += " "), r += n);
13
+ for (t = 0; t < o; t++) e[t] && (n = vt(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 Qt() {
18
- for (var e, t, n = 0, r = "", o = arguments.length; n < o; n++) (e = arguments[n]) && (t = kt(e)) && (r && (r += " "), r += t);
18
+ for (var e, t, n = 0, r = "", o = arguments.length; n < o; n++) (e = arguments[n]) && (t = vt(e)) && (r && (r += " "), r += t);
19
19
  return r;
20
20
  }
21
21
  const et = "-", Yt = (e) => {
@@ -29,8 +29,8 @@ const et = "-", Yt = (e) => {
29
29
  return i[0] === "" && i.length !== 1 && i.shift(), It(i, t) || Zt(a);
30
30
  },
31
31
  getConflictingClassGroupIds: (a, i) => {
32
- const d = n[a] || [];
33
- return i && r[a] ? [...d, ...r[a]] : d;
32
+ const u = n[a] || [];
33
+ return i && r[a] ? [...u, ...r[a]] : u;
34
34
  }
35
35
  };
36
36
  }, It = (e, t) => {
@@ -120,33 +120,33 @@ const et = "-", Yt = (e) => {
120
120
  n.has(s) ? n.set(s, a) : o(s, a);
121
121
  }
122
122
  };
123
- }, xt = "!", on = (e) => {
123
+ }, At = "!", on = (e) => {
124
124
  const {
125
125
  separator: t,
126
126
  experimentalParseClassName: n
127
127
  } = e, r = t.length === 1, o = t[0], s = t.length, a = (i) => {
128
- const d = [];
129
- let c = 0, l = 0, f;
130
- for (let w = 0; w < i.length; w++) {
131
- let I = i[w];
128
+ const u = [];
129
+ let c = 0, l = 0, d;
130
+ for (let k = 0; k < i.length; k++) {
131
+ let p = i[k];
132
132
  if (c === 0) {
133
- if (I === o && (r || i.slice(w, w + s) === t)) {
134
- d.push(i.slice(l, w)), l = w + s;
133
+ if (p === o && (r || i.slice(k, k + s) === t)) {
134
+ u.push(i.slice(l, k)), l = k + s;
135
135
  continue;
136
136
  }
137
- if (I === "/") {
138
- f = w;
137
+ if (p === "/") {
138
+ d = k;
139
139
  continue;
140
140
  }
141
141
  }
142
- I === "[" ? c++ : I === "]" && c--;
142
+ p === "[" ? c++ : p === "]" && c--;
143
143
  }
144
- const g = d.length === 0 ? i : i.substring(l), m = g.startsWith(xt), k = m ? g.substring(1) : g, u = f && f > l ? f - l : void 0;
144
+ const m = u.length === 0 ? i : i.substring(l), y = m.startsWith(At), I = y ? m.substring(1) : m, f = d && d > l ? d - l : void 0;
145
145
  return {
146
- modifiers: d,
147
- hasImportantModifier: m,
148
- baseClassName: k,
149
- maybePostfixModifierPosition: u
146
+ modifiers: u,
147
+ hasImportantModifier: y,
148
+ baseClassName: I,
149
+ maybePostfixModifierPosition: f
150
150
  };
151
151
  };
152
152
  return n ? (i) => n({
@@ -172,33 +172,33 @@ const et = "-", Yt = (e) => {
172
172
  getConflictingClassGroupIds: o
173
173
  } = t, s = [], a = e.trim().split(cn);
174
174
  let i = "";
175
- for (let d = a.length - 1; d >= 0; d -= 1) {
176
- const c = a[d], {
175
+ for (let u = a.length - 1; u >= 0; u -= 1) {
176
+ const c = a[u], {
177
177
  modifiers: l,
178
- hasImportantModifier: f,
179
- baseClassName: g,
180
- maybePostfixModifierPosition: m
178
+ hasImportantModifier: d,
179
+ baseClassName: m,
180
+ maybePostfixModifierPosition: y
181
181
  } = n(c);
182
- let k = !!m, u = r(k ? g.substring(0, m) : g);
183
- if (!u) {
184
- if (!k) {
182
+ let I = !!y, f = r(I ? m.substring(0, y) : m);
183
+ if (!f) {
184
+ if (!I) {
185
185
  i = c + (i.length > 0 ? " " + i : i);
186
186
  continue;
187
187
  }
188
- if (u = r(g), !u) {
188
+ if (f = r(m), !f) {
189
189
  i = c + (i.length > 0 ? " " + i : i);
190
190
  continue;
191
191
  }
192
- k = !1;
192
+ I = !1;
193
193
  }
194
- const w = sn(l).join(":"), I = f ? w + xt : w, C = I + u;
195
- if (s.includes(C))
194
+ const k = sn(l).join(":"), p = d ? k + At : k, S = p + f;
195
+ if (s.includes(S))
196
196
  continue;
197
- s.push(C);
198
- const x = o(u, k);
199
- for (let E = 0; E < x.length; ++E) {
200
- const v = x[E];
201
- s.push(I + v);
197
+ s.push(S);
198
+ const A = o(f, I);
199
+ for (let E = 0; E < A.length; ++E) {
200
+ const v = A[E];
201
+ s.push(p + v);
202
202
  }
203
203
  i = c + (i.length > 0 ? " " + i : i);
204
204
  }
@@ -207,29 +207,29 @@ const et = "-", Yt = (e) => {
207
207
  function un() {
208
208
  let e = 0, t, n, r = "";
209
209
  for (; e < arguments.length; )
210
- (t = arguments[e++]) && (n = At(t)) && (r && (r += " "), r += n);
210
+ (t = arguments[e++]) && (n = xt(t)) && (r && (r += " "), r += n);
211
211
  return r;
212
212
  }
213
- const At = (e) => {
213
+ const xt = (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 = At(e[r])) && (n && (n += " "), n += t);
218
+ e[r] && (t = xt(e[r])) && (n && (n += " "), n += t);
219
219
  return n;
220
220
  };
221
221
  function dn(e, ...t) {
222
222
  let n, r, o, s = a;
223
- function a(d) {
224
- const c = t.reduce((l, f) => f(l), e());
225
- return n = an(c), r = n.cache.get, o = n.cache.set, s = i, i(d);
223
+ function a(u) {
224
+ const c = t.reduce((l, d) => d(l), e());
225
+ return n = an(c), r = n.cache.get, o = n.cache.set, s = i, i(u);
226
226
  }
227
- function i(d) {
228
- const c = r(d);
227
+ function i(u) {
228
+ const c = r(u);
229
229
  if (c)
230
230
  return c;
231
- const l = ln(d, n);
232
- return o(d, l), l;
231
+ const l = ln(u, n);
232
+ return o(u, l), l;
233
233
  }
234
234
  return function() {
235
235
  return s(un.apply(null, arguments));
@@ -238,7 +238,7 @@ function dn(e, ...t) {
238
238
  const D = (e) => {
239
239
  const t = (n) => n[e] || [];
240
240
  return t.isThemeGetter = !0, t;
241
- }, Tt = /^\[(?:([a-z-]+):)?(.+)\]$/i, fn = /^\d+\/\d+$/, pn = /* @__PURE__ */ new Set(["px", "full", "screen"]), gn = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, mn = /\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$/, yn = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, hn = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, bn = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, de = (e) => Te(e) || pn.has(e) || fn.test(e), be = (e) => Ee(e, "length", Sn), Te = (e) => !!e && !Number.isNaN(Number(e)), He = (e) => Ee(e, "number", Te), _e = (e) => !!e && Number.isInteger(Number(e)), wn = (e) => e.endsWith("%") && Te(e.slice(0, -1)), R = (e) => Tt.test(e), we = (e) => gn.test(e), vn = /* @__PURE__ */ new Set(["length", "size", "percentage"]), kn = (e) => Ee(e, vn, St), In = (e) => Ee(e, "position", St), xn = /* @__PURE__ */ new Set(["image", "url"]), An = (e) => Ee(e, xn, Mn), Tn = (e) => Ee(e, "", Cn), Ne = () => !0, Ee = (e, t, n) => {
241
+ }, Tt = /^\[(?:([a-z-]+):)?(.+)\]$/i, fn = /^\d+\/\d+$/, pn = /* @__PURE__ */ new Set(["px", "full", "screen"]), gn = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, mn = /\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$/, yn = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, hn = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, bn = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, de = (e) => Te(e) || pn.has(e) || fn.test(e), be = (e) => Ee(e, "length", Sn), Te = (e) => !!e && !Number.isNaN(Number(e)), qe = (e) => Ee(e, "number", Te), _e = (e) => !!e && Number.isInteger(Number(e)), wn = (e) => e.endsWith("%") && Te(e.slice(0, -1)), R = (e) => Tt.test(e), we = (e) => gn.test(e), kn = /* @__PURE__ */ new Set(["length", "size", "percentage"]), vn = (e) => Ee(e, kn, St), In = (e) => Ee(e, "position", St), An = /* @__PURE__ */ new Set(["image", "url"]), xn = (e) => Ee(e, An, Cn), Tn = (e) => Ee(e, "", Mn), Ne = () => !0, Ee = (e, t, n) => {
242
242
  const r = Tt.exec(e);
243
243
  return r ? r[1] ? typeof t == "string" ? r[1] === t : t.has(r[1]) : n(r[2]) : !1;
244
244
  }, Sn = (e) => (
@@ -246,8 +246,8 @@ const D = (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
  mn.test(e) && !yn.test(e)
249
- ), St = () => !1, Cn = (e) => hn.test(e), Mn = (e) => bn.test(e), En = () => {
250
- const e = D("colors"), t = D("spacing"), n = D("blur"), r = D("brightness"), o = D("borderColor"), s = D("borderRadius"), a = D("borderSpacing"), i = D("borderWidth"), d = D("contrast"), c = D("grayscale"), l = D("hueRotate"), f = D("invert"), g = D("gap"), m = D("gradientColorStops"), k = D("gradientColorStopPositions"), u = D("inset"), w = D("margin"), I = D("opacity"), C = D("padding"), x = D("saturate"), E = D("scale"), v = D("sepia"), b = D("skew"), A = D("space"), p = D("translate"), h = () => ["auto", "contain", "none"], P = () => ["auto", "hidden", "clip", "visible", "scroll"], j = () => ["auto", R, t], S = () => [R, t], O = () => ["", de, be], $ = () => ["auto", Te, R], M = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], F = () => ["solid", "dashed", "dotted", "double", "none"], N = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], V = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], z = () => ["", "0", R], L = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], K = () => [Te, R];
249
+ ), St = () => !1, Mn = (e) => hn.test(e), Cn = (e) => bn.test(e), En = () => {
250
+ const e = D("colors"), t = D("spacing"), n = D("blur"), r = D("brightness"), o = D("borderColor"), s = D("borderRadius"), a = D("borderSpacing"), i = D("borderWidth"), u = D("contrast"), c = D("grayscale"), l = D("hueRotate"), d = D("invert"), m = D("gap"), y = D("gradientColorStops"), I = D("gradientColorStopPositions"), f = D("inset"), k = D("margin"), p = D("opacity"), S = D("padding"), A = D("saturate"), E = D("scale"), v = D("sepia"), w = D("skew"), x = D("space"), g = D("translate"), b = () => ["auto", "contain", "none"], P = () => ["auto", "hidden", "clip", "visible", "scroll"], j = () => ["auto", R, t], M = () => [R, t], O = () => ["", de, be], F = () => ["auto", Te, R], C = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], B = () => ["solid", "dashed", "dotted", "double", "none"], N = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], V = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], z = () => ["", "0", R], L = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], H = () => [Te, R];
251
251
  return {
252
252
  cacheSize: 500,
253
253
  separator: ":",
@@ -255,28 +255,28 @@ const D = (e) => {
255
255
  colors: [Ne],
256
256
  spacing: [de, be],
257
257
  blur: ["none", "", we, R],
258
- brightness: K(),
258
+ brightness: H(),
259
259
  borderColor: [e],
260
260
  borderRadius: ["none", "", "full", we, R],
261
- borderSpacing: S(),
261
+ borderSpacing: M(),
262
262
  borderWidth: O(),
263
- contrast: K(),
263
+ contrast: H(),
264
264
  grayscale: z(),
265
- hueRotate: K(),
265
+ hueRotate: H(),
266
266
  invert: z(),
267
- gap: S(),
267
+ gap: M(),
268
268
  gradientColorStops: [e],
269
269
  gradientColorStopPositions: [wn, be],
270
270
  inset: j(),
271
271
  margin: j(),
272
- opacity: K(),
273
- padding: S(),
274
- saturate: K(),
275
- scale: K(),
272
+ opacity: H(),
273
+ padding: M(),
274
+ saturate: H(),
275
+ scale: H(),
276
276
  sepia: z(),
277
- skew: K(),
278
- space: S(),
279
- translate: S()
277
+ skew: H(),
278
+ space: M(),
279
+ translate: M()
280
280
  },
281
281
  classGroups: {
282
282
  // Layout
@@ -370,7 +370,7 @@ const D = (e) => {
370
370
  * @see https://tailwindcss.com/docs/object-position
371
371
  */
372
372
  "object-position": [{
373
- object: [...M(), R]
373
+ object: [...C(), R]
374
374
  }],
375
375
  /**
376
376
  * Overflow
@@ -398,21 +398,21 @@ const D = (e) => {
398
398
  * @see https://tailwindcss.com/docs/overscroll-behavior
399
399
  */
400
400
  overscroll: [{
401
- overscroll: h()
401
+ overscroll: b()
402
402
  }],
403
403
  /**
404
404
  * Overscroll Behavior X
405
405
  * @see https://tailwindcss.com/docs/overscroll-behavior
406
406
  */
407
407
  "overscroll-x": [{
408
- "overscroll-x": h()
408
+ "overscroll-x": b()
409
409
  }],
410
410
  /**
411
411
  * Overscroll Behavior Y
412
412
  * @see https://tailwindcss.com/docs/overscroll-behavior
413
413
  */
414
414
  "overscroll-y": [{
415
- "overscroll-y": h()
415
+ "overscroll-y": b()
416
416
  }],
417
417
  /**
418
418
  * Position
@@ -424,63 +424,63 @@ const D = (e) => {
424
424
  * @see https://tailwindcss.com/docs/top-right-bottom-left
425
425
  */
426
426
  inset: [{
427
- inset: [u]
427
+ inset: [f]
428
428
  }],
429
429
  /**
430
430
  * Right / Left
431
431
  * @see https://tailwindcss.com/docs/top-right-bottom-left
432
432
  */
433
433
  "inset-x": [{
434
- "inset-x": [u]
434
+ "inset-x": [f]
435
435
  }],
436
436
  /**
437
437
  * Top / Bottom
438
438
  * @see https://tailwindcss.com/docs/top-right-bottom-left
439
439
  */
440
440
  "inset-y": [{
441
- "inset-y": [u]
441
+ "inset-y": [f]
442
442
  }],
443
443
  /**
444
444
  * Start
445
445
  * @see https://tailwindcss.com/docs/top-right-bottom-left
446
446
  */
447
447
  start: [{
448
- start: [u]
448
+ start: [f]
449
449
  }],
450
450
  /**
451
451
  * End
452
452
  * @see https://tailwindcss.com/docs/top-right-bottom-left
453
453
  */
454
454
  end: [{
455
- end: [u]
455
+ end: [f]
456
456
  }],
457
457
  /**
458
458
  * Top
459
459
  * @see https://tailwindcss.com/docs/top-right-bottom-left
460
460
  */
461
461
  top: [{
462
- top: [u]
462
+ top: [f]
463
463
  }],
464
464
  /**
465
465
  * Right
466
466
  * @see https://tailwindcss.com/docs/top-right-bottom-left
467
467
  */
468
468
  right: [{
469
- right: [u]
469
+ right: [f]
470
470
  }],
471
471
  /**
472
472
  * Bottom
473
473
  * @see https://tailwindcss.com/docs/top-right-bottom-left
474
474
  */
475
475
  bottom: [{
476
- bottom: [u]
476
+ bottom: [f]
477
477
  }],
478
478
  /**
479
479
  * Left
480
480
  * @see https://tailwindcss.com/docs/top-right-bottom-left
481
481
  */
482
482
  left: [{
483
- left: [u]
483
+ left: [f]
484
484
  }],
485
485
  /**
486
486
  * Visibility
@@ -565,14 +565,14 @@ const D = (e) => {
565
565
  * @see https://tailwindcss.com/docs/grid-column
566
566
  */
567
567
  "col-start": [{
568
- "col-start": $()
568
+ "col-start": F()
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": $()
575
+ "col-end": F()
576
576
  }],
577
577
  /**
578
578
  * Grid Template Rows
@@ -595,14 +595,14 @@ const D = (e) => {
595
595
  * @see https://tailwindcss.com/docs/grid-row
596
596
  */
597
597
  "row-start": [{
598
- "row-start": $()
598
+ "row-start": F()
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": $()
605
+ "row-end": F()
606
606
  }],
607
607
  /**
608
608
  * Grid Auto Flow
@@ -630,21 +630,21 @@ const D = (e) => {
630
630
  * @see https://tailwindcss.com/docs/gap
631
631
  */
632
632
  gap: [{
633
- gap: [g]
633
+ gap: [m]
634
634
  }],
635
635
  /**
636
636
  * Gap X
637
637
  * @see https://tailwindcss.com/docs/gap
638
638
  */
639
639
  "gap-x": [{
640
- "gap-x": [g]
640
+ "gap-x": [m]
641
641
  }],
642
642
  /**
643
643
  * Gap Y
644
644
  * @see https://tailwindcss.com/docs/gap
645
645
  */
646
646
  "gap-y": [{
647
- "gap-y": [g]
647
+ "gap-y": [m]
648
648
  }],
649
649
  /**
650
650
  * Justify Content
@@ -715,133 +715,133 @@ const D = (e) => {
715
715
  * @see https://tailwindcss.com/docs/padding
716
716
  */
717
717
  p: [{
718
- p: [C]
718
+ p: [S]
719
719
  }],
720
720
  /**
721
721
  * Padding X
722
722
  * @see https://tailwindcss.com/docs/padding
723
723
  */
724
724
  px: [{
725
- px: [C]
725
+ px: [S]
726
726
  }],
727
727
  /**
728
728
  * Padding Y
729
729
  * @see https://tailwindcss.com/docs/padding
730
730
  */
731
731
  py: [{
732
- py: [C]
732
+ py: [S]
733
733
  }],
734
734
  /**
735
735
  * Padding Start
736
736
  * @see https://tailwindcss.com/docs/padding
737
737
  */
738
738
  ps: [{
739
- ps: [C]
739
+ ps: [S]
740
740
  }],
741
741
  /**
742
742
  * Padding End
743
743
  * @see https://tailwindcss.com/docs/padding
744
744
  */
745
745
  pe: [{
746
- pe: [C]
746
+ pe: [S]
747
747
  }],
748
748
  /**
749
749
  * Padding Top
750
750
  * @see https://tailwindcss.com/docs/padding
751
751
  */
752
752
  pt: [{
753
- pt: [C]
753
+ pt: [S]
754
754
  }],
755
755
  /**
756
756
  * Padding Right
757
757
  * @see https://tailwindcss.com/docs/padding
758
758
  */
759
759
  pr: [{
760
- pr: [C]
760
+ pr: [S]
761
761
  }],
762
762
  /**
763
763
  * Padding Bottom
764
764
  * @see https://tailwindcss.com/docs/padding
765
765
  */
766
766
  pb: [{
767
- pb: [C]
767
+ pb: [S]
768
768
  }],
769
769
  /**
770
770
  * Padding Left
771
771
  * @see https://tailwindcss.com/docs/padding
772
772
  */
773
773
  pl: [{
774
- pl: [C]
774
+ pl: [S]
775
775
  }],
776
776
  /**
777
777
  * Margin
778
778
  * @see https://tailwindcss.com/docs/margin
779
779
  */
780
780
  m: [{
781
- m: [w]
781
+ m: [k]
782
782
  }],
783
783
  /**
784
784
  * Margin X
785
785
  * @see https://tailwindcss.com/docs/margin
786
786
  */
787
787
  mx: [{
788
- mx: [w]
788
+ mx: [k]
789
789
  }],
790
790
  /**
791
791
  * Margin Y
792
792
  * @see https://tailwindcss.com/docs/margin
793
793
  */
794
794
  my: [{
795
- my: [w]
795
+ my: [k]
796
796
  }],
797
797
  /**
798
798
  * Margin Start
799
799
  * @see https://tailwindcss.com/docs/margin
800
800
  */
801
801
  ms: [{
802
- ms: [w]
802
+ ms: [k]
803
803
  }],
804
804
  /**
805
805
  * Margin End
806
806
  * @see https://tailwindcss.com/docs/margin
807
807
  */
808
808
  me: [{
809
- me: [w]
809
+ me: [k]
810
810
  }],
811
811
  /**
812
812
  * Margin Top
813
813
  * @see https://tailwindcss.com/docs/margin
814
814
  */
815
815
  mt: [{
816
- mt: [w]
816
+ mt: [k]
817
817
  }],
818
818
  /**
819
819
  * Margin Right
820
820
  * @see https://tailwindcss.com/docs/margin
821
821
  */
822
822
  mr: [{
823
- mr: [w]
823
+ mr: [k]
824
824
  }],
825
825
  /**
826
826
  * Margin Bottom
827
827
  * @see https://tailwindcss.com/docs/margin
828
828
  */
829
829
  mb: [{
830
- mb: [w]
830
+ mb: [k]
831
831
  }],
832
832
  /**
833
833
  * Margin Left
834
834
  * @see https://tailwindcss.com/docs/margin
835
835
  */
836
836
  ml: [{
837
- ml: [w]
837
+ ml: [k]
838
838
  }],
839
839
  /**
840
840
  * Space Between X
841
841
  * @see https://tailwindcss.com/docs/space
842
842
  */
843
843
  "space-x": [{
844
- "space-x": [A]
844
+ "space-x": [x]
845
845
  }],
846
846
  /**
847
847
  * Space Between X Reverse
@@ -853,7 +853,7 @@ const D = (e) => {
853
853
  * @see https://tailwindcss.com/docs/space
854
854
  */
855
855
  "space-y": [{
856
- "space-y": [A]
856
+ "space-y": [x]
857
857
  }],
858
858
  /**
859
859
  * Space Between Y Reverse
@@ -935,7 +935,7 @@ const D = (e) => {
935
935
  * @see https://tailwindcss.com/docs/font-weight
936
936
  */
937
937
  "font-weight": [{
938
- font: ["thin", "extralight", "light", "normal", "medium", "semibold", "bold", "extrabold", "black", He]
938
+ font: ["thin", "extralight", "light", "normal", "medium", "semibold", "bold", "extrabold", "black", qe]
939
939
  }],
940
940
  /**
941
941
  * Font Family
@@ -986,7 +986,7 @@ const D = (e) => {
986
986
  * @see https://tailwindcss.com/docs/line-clamp
987
987
  */
988
988
  "line-clamp": [{
989
- "line-clamp": ["none", Te, He]
989
+ "line-clamp": ["none", Te, qe]
990
990
  }],
991
991
  /**
992
992
  * Line Height
@@ -1029,7 +1029,7 @@ const D = (e) => {
1029
1029
  * @see https://tailwindcss.com/docs/placeholder-opacity
1030
1030
  */
1031
1031
  "placeholder-opacity": [{
1032
- "placeholder-opacity": [I]
1032
+ "placeholder-opacity": [p]
1033
1033
  }],
1034
1034
  /**
1035
1035
  * Text Alignment
@@ -1050,7 +1050,7 @@ const D = (e) => {
1050
1050
  * @see https://tailwindcss.com/docs/text-opacity
1051
1051
  */
1052
1052
  "text-opacity": [{
1053
- "text-opacity": [I]
1053
+ "text-opacity": [p]
1054
1054
  }],
1055
1055
  /**
1056
1056
  * Text Decoration
@@ -1062,7 +1062,7 @@ const D = (e) => {
1062
1062
  * @see https://tailwindcss.com/docs/text-decoration-style
1063
1063
  */
1064
1064
  "text-decoration-style": [{
1065
- decoration: [...F(), "wavy"]
1065
+ decoration: [...B(), "wavy"]
1066
1066
  }],
1067
1067
  /**
1068
1068
  * Text Decoration Thickness
@@ -1107,7 +1107,7 @@ const D = (e) => {
1107
1107
  * @see https://tailwindcss.com/docs/text-indent
1108
1108
  */
1109
1109
  indent: [{
1110
- indent: S()
1110
+ indent: M()
1111
1111
  }],
1112
1112
  /**
1113
1113
  * Vertical Alignment
@@ -1165,7 +1165,7 @@ const D = (e) => {
1165
1165
  * @see https://tailwindcss.com/docs/background-opacity
1166
1166
  */
1167
1167
  "bg-opacity": [{
1168
- "bg-opacity": [I]
1168
+ "bg-opacity": [p]
1169
1169
  }],
1170
1170
  /**
1171
1171
  * Background Origin
@@ -1179,7 +1179,7 @@ const D = (e) => {
1179
1179
  * @see https://tailwindcss.com/docs/background-position
1180
1180
  */
1181
1181
  "bg-position": [{
1182
- bg: [...M(), In]
1182
+ bg: [...C(), In]
1183
1183
  }],
1184
1184
  /**
1185
1185
  * Background Repeat
@@ -1195,7 +1195,7 @@ const D = (e) => {
1195
1195
  * @see https://tailwindcss.com/docs/background-size
1196
1196
  */
1197
1197
  "bg-size": [{
1198
- bg: ["auto", "cover", "contain", kn]
1198
+ bg: ["auto", "cover", "contain", vn]
1199
1199
  }],
1200
1200
  /**
1201
1201
  * Background Image
@@ -1204,7 +1204,7 @@ const D = (e) => {
1204
1204
  "bg-image": [{
1205
1205
  bg: ["none", {
1206
1206
  "gradient-to": ["t", "tr", "r", "br", "b", "bl", "l", "tl"]
1207
- }, An]
1207
+ }, xn]
1208
1208
  }],
1209
1209
  /**
1210
1210
  * Background Color
@@ -1218,42 +1218,42 @@ const D = (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
1239
1239
  * @see https://tailwindcss.com/docs/gradient-color-stops
1240
1240
  */
1241
1241
  "gradient-from": [{
1242
- from: [m]
1242
+ from: [y]
1243
1243
  }],
1244
1244
  /**
1245
1245
  * Gradient Color Stops Via
1246
1246
  * @see https://tailwindcss.com/docs/gradient-color-stops
1247
1247
  */
1248
1248
  "gradient-via": [{
1249
- via: [m]
1249
+ via: [y]
1250
1250
  }],
1251
1251
  /**
1252
1252
  * Gradient Color Stops To
1253
1253
  * @see https://tailwindcss.com/docs/gradient-color-stops
1254
1254
  */
1255
1255
  "gradient-to": [{
1256
- to: [m]
1256
+ to: [y]
1257
1257
  }],
1258
1258
  // Borders
1259
1259
  /**
@@ -1429,14 +1429,14 @@ const D = (e) => {
1429
1429
  * @see https://tailwindcss.com/docs/border-opacity
1430
1430
  */
1431
1431
  "border-opacity": [{
1432
- "border-opacity": [I]
1432
+ "border-opacity": [p]
1433
1433
  }],
1434
1434
  /**
1435
1435
  * Border Style
1436
1436
  * @see https://tailwindcss.com/docs/border-style
1437
1437
  */
1438
1438
  "border-style": [{
1439
- border: [...F(), "hidden"]
1439
+ border: [...B(), "hidden"]
1440
1440
  }],
1441
1441
  /**
1442
1442
  * Divide Width X
@@ -1467,14 +1467,14 @@ const D = (e) => {
1467
1467
  * @see https://tailwindcss.com/docs/divide-opacity
1468
1468
  */
1469
1469
  "divide-opacity": [{
1470
- "divide-opacity": [I]
1470
+ "divide-opacity": [p]
1471
1471
  }],
1472
1472
  /**
1473
1473
  * Divide Style
1474
1474
  * @see https://tailwindcss.com/docs/divide-style
1475
1475
  */
1476
1476
  "divide-style": [{
1477
- divide: F()
1477
+ divide: B()
1478
1478
  }],
1479
1479
  /**
1480
1480
  * Border Color
@@ -1551,7 +1551,7 @@ const D = (e) => {
1551
1551
  * @see https://tailwindcss.com/docs/outline-style
1552
1552
  */
1553
1553
  "outline-style": [{
1554
- outline: ["", ...F()]
1554
+ outline: ["", ...B()]
1555
1555
  }],
1556
1556
  /**
1557
1557
  * Outline Offset
@@ -1598,7 +1598,7 @@ const D = (e) => {
1598
1598
  * @see https://tailwindcss.com/docs/ring-opacity
1599
1599
  */
1600
1600
  "ring-opacity": [{
1601
- "ring-opacity": [I]
1601
+ "ring-opacity": [p]
1602
1602
  }],
1603
1603
  /**
1604
1604
  * Ring Offset Width
@@ -1634,7 +1634,7 @@ const D = (e) => {
1634
1634
  * @see https://tailwindcss.com/docs/opacity
1635
1635
  */
1636
1636
  opacity: [{
1637
- opacity: [I]
1637
+ opacity: [p]
1638
1638
  }],
1639
1639
  /**
1640
1640
  * Mix Blend Mode
@@ -1678,7 +1678,7 @@ const D = (e) => {
1678
1678
  * @see https://tailwindcss.com/docs/contrast
1679
1679
  */
1680
1680
  contrast: [{
1681
- contrast: [d]
1681
+ contrast: [u]
1682
1682
  }],
1683
1683
  /**
1684
1684
  * Drop Shadow
@@ -1706,14 +1706,14 @@ const D = (e) => {
1706
1706
  * @see https://tailwindcss.com/docs/invert
1707
1707
  */
1708
1708
  invert: [{
1709
- invert: [f]
1709
+ invert: [d]
1710
1710
  }],
1711
1711
  /**
1712
1712
  * Saturate
1713
1713
  * @see https://tailwindcss.com/docs/saturate
1714
1714
  */
1715
1715
  saturate: [{
1716
- saturate: [x]
1716
+ saturate: [A]
1717
1717
  }],
1718
1718
  /**
1719
1719
  * Sepia
@@ -1749,7 +1749,7 @@ const D = (e) => {
1749
1749
  * @see https://tailwindcss.com/docs/backdrop-contrast
1750
1750
  */
1751
1751
  "backdrop-contrast": [{
1752
- "backdrop-contrast": [d]
1752
+ "backdrop-contrast": [u]
1753
1753
  }],
1754
1754
  /**
1755
1755
  * Backdrop Grayscale
@@ -1770,21 +1770,21 @@ const D = (e) => {
1770
1770
  * @see https://tailwindcss.com/docs/backdrop-invert
1771
1771
  */
1772
1772
  "backdrop-invert": [{
1773
- "backdrop-invert": [f]
1773
+ "backdrop-invert": [d]
1774
1774
  }],
1775
1775
  /**
1776
1776
  * Backdrop Opacity
1777
1777
  * @see https://tailwindcss.com/docs/backdrop-opacity
1778
1778
  */
1779
1779
  "backdrop-opacity": [{
1780
- "backdrop-opacity": [I]
1780
+ "backdrop-opacity": [p]
1781
1781
  }],
1782
1782
  /**
1783
1783
  * Backdrop Saturate
1784
1784
  * @see https://tailwindcss.com/docs/backdrop-saturate
1785
1785
  */
1786
1786
  "backdrop-saturate": [{
1787
- "backdrop-saturate": [x]
1787
+ "backdrop-saturate": [A]
1788
1788
  }],
1789
1789
  /**
1790
1790
  * Backdrop Sepia
@@ -1849,7 +1849,7 @@ const D = (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 D = (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
@@ -1913,28 +1913,28 @@ const D = (e) => {
1913
1913
  * @see https://tailwindcss.com/docs/translate
1914
1914
  */
1915
1915
  "translate-x": [{
1916
- "translate-x": [p]
1916
+ "translate-x": [g]
1917
1917
  }],
1918
1918
  /**
1919
1919
  * Translate Y
1920
1920
  * @see https://tailwindcss.com/docs/translate
1921
1921
  */
1922
1922
  "translate-y": [{
1923
- "translate-y": [p]
1923
+ "translate-y": [g]
1924
1924
  }],
1925
1925
  /**
1926
1926
  * Skew X
1927
1927
  * @see https://tailwindcss.com/docs/skew
1928
1928
  */
1929
1929
  "skew-x": [{
1930
- "skew-x": [b]
1930
+ "skew-x": [w]
1931
1931
  }],
1932
1932
  /**
1933
1933
  * Skew Y
1934
1934
  * @see https://tailwindcss.com/docs/skew
1935
1935
  */
1936
1936
  "skew-y": [{
1937
- "skew-y": [b]
1937
+ "skew-y": [w]
1938
1938
  }],
1939
1939
  /**
1940
1940
  * Transform Origin
@@ -1998,126 +1998,126 @@ const D = (e) => {
1998
1998
  * @see https://tailwindcss.com/docs/scroll-margin
1999
1999
  */
2000
2000
  "scroll-m": [{
2001
- "scroll-m": S()
2001
+ "scroll-m": M()
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": S()
2008
+ "scroll-mx": M()
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": S()
2015
+ "scroll-my": M()
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": S()
2022
+ "scroll-ms": M()
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": S()
2029
+ "scroll-me": M()
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": S()
2036
+ "scroll-mt": M()
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": S()
2043
+ "scroll-mr": M()
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": S()
2050
+ "scroll-mb": M()
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": S()
2057
+ "scroll-ml": M()
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": S()
2064
+ "scroll-p": M()
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": S()
2071
+ "scroll-px": M()
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": S()
2078
+ "scroll-py": M()
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": S()
2085
+ "scroll-ps": M()
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": S()
2092
+ "scroll-pe": M()
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": S()
2099
+ "scroll-pt": M()
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": S()
2106
+ "scroll-pr": M()
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": S()
2113
+ "scroll-pb": M()
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": S()
2120
+ "scroll-pl": M()
2121
2121
  }],
2122
2122
  /**
2123
2123
  * Scroll Snap Align
@@ -2200,7 +2200,7 @@ const D = (e) => {
2200
2200
  * @see https://tailwindcss.com/docs/stroke-width
2201
2201
  */
2202
2202
  "stroke-w": [{
2203
- stroke: [de, be, He]
2203
+ stroke: [de, be, qe]
2204
2204
  }],
2205
2205
  /**
2206
2206
  * Stroke
@@ -2329,10 +2329,10 @@ function Un(e) {
2329
2329
  function jn(e) {
2330
2330
  return e.content.filter(Rn);
2331
2331
  }
2332
- function Ct(e) {
2332
+ function Mt(e) {
2333
2333
  return Array.isArray(e.toolCalls) ? e.toolCalls : [];
2334
2334
  }
2335
- function Fn(e) {
2335
+ function Bn(e) {
2336
2336
  const t = [];
2337
2337
  return e.forEach((n) => {
2338
2338
  n.artifact && t.push(n.artifact), Array.isArray(n.toolCalls) && n.toolCalls.forEach((r) => {
@@ -2340,7 +2340,7 @@ function Fn(e) {
2340
2340
  });
2341
2341
  }), t;
2342
2342
  }
2343
- function Mt(e) {
2343
+ function Ct(e) {
2344
2344
  return !!(e && typeof e == "object" && (e.type === "file" || e.mimeType || e.filename || e.sourceType === "base64"));
2345
2345
  }
2346
2346
  function Ve(e) {
@@ -2355,7 +2355,7 @@ function Ve(e) {
2355
2355
  }
2356
2356
  return n;
2357
2357
  }
2358
- if (Mt(e)) {
2358
+ if (Ct(e)) {
2359
2359
  try {
2360
2360
  console.debug("[message-utils] sanitizeForDisplay - dropping file-like object", {
2361
2361
  sampleFilename: e && (e.filename || e.name) ? e.filename || e.name : void 0,
@@ -2389,7 +2389,7 @@ function Ve(e) {
2389
2389
  }
2390
2390
  function Et(e) {
2391
2391
  if (typeof e == "string") return e;
2392
- if (Mt(e)) return "";
2392
+ if (Ct(e)) return "";
2393
2393
  try {
2394
2394
  const t = Ve(e);
2395
2395
  return t === void 0 ? "" : typeof t == "string" ? t : JSON.stringify(t, null, 2);
@@ -2401,7 +2401,7 @@ function oo(e) {
2401
2401
  const t = Et(e);
2402
2402
  return typeof e == "string" && Nn(e) ? { content: e, isMarkdown: !0 } : { content: t, isMarkdown: !1 };
2403
2403
  }
2404
- function On(e) {
2404
+ function Fn(e) {
2405
2405
  const t = (r) => {
2406
2406
  try {
2407
2407
  const o = Ve(r);
@@ -2436,24 +2436,24 @@ function ce(e) {
2436
2436
  }
2437
2437
  return typeof e == "object" && !Array.isArray(e) && (e.type === "text" && typeof e.text == "string" || typeof e.text == "string") ? e.text : Array.isArray(e) && e.length > 0 ? ce(e[0]) : e;
2438
2438
  }
2439
- function Bn(e) {
2439
+ function On(e) {
2440
2440
  return e.replace(/[_-](\w)/g, (t, n) => n ? n.toUpperCase() : "").replace(/^\w/, (t) => t.toLowerCase());
2441
2441
  }
2442
2442
  function le(e) {
2443
2443
  return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(le) : Object.fromEntries(
2444
2444
  Object.entries(e).map(([t, n]) => [
2445
- Bn(t),
2445
+ On(t),
2446
2446
  le(n)
2447
2447
  ])
2448
2448
  );
2449
2449
  }
2450
2450
  function nt(e) {
2451
- var w, I, C, x, E, v;
2451
+ var k, p, S, A, E, v;
2452
2452
  if (!e || typeof e != "object") return null;
2453
2453
  const t = le(e), n = Vn(t);
2454
2454
  if (!n)
2455
2455
  return null;
2456
- const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(rt) : void 0, o = Dn(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 ?? ((w = t.additionalKwargs) == null ? void 0 : w.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), i = t.name ?? ((I = t.additionalKwargs) == null ? void 0 : I.agentName) ?? void 0, d = t.model ?? ((C = t.additionalKwargs) == null ? void 0 : C.model) ?? void 0, c = t.toolCallId ?? void 0, l = t.additionalKwargs ?? void 0, f = t.responseMetadata ?? void 0, g = t.checkpointId ?? ((x = t.additionalKwargs) == null ? void 0 : x.checkpointId) ?? void 0, m = t.checkpointNs ?? ((E = t.additionalKwargs) == null ? void 0 : E.checkpointNs) ?? void 0, k = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((v = t.additionalKwargs) != null && v.toolStreaming);
2456
+ const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(rt) : void 0, o = Dn(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 ?? ((k = t.additionalKwargs) == null ? void 0 : k.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), i = t.name ?? ((p = t.additionalKwargs) == null ? void 0 : p.agentName) ?? void 0, u = t.model ?? ((S = t.additionalKwargs) == null ? void 0 : S.model) ?? void 0, c = t.toolCallId ?? void 0, l = t.additionalKwargs ?? void 0, d = t.responseMetadata ?? void 0, m = t.checkpointId ?? ((A = t.additionalKwargs) == null ? void 0 : A.checkpointId) ?? void 0, y = t.checkpointNs ?? ((E = t.additionalKwargs) == null ? void 0 : E.checkpointNs) ?? void 0, I = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((v = t.additionalKwargs) != null && v.toolStreaming);
2457
2457
  return {
2458
2458
  ...t,
2459
2459
  id: s,
@@ -2461,14 +2461,14 @@ function nt(e) {
2461
2461
  content: o,
2462
2462
  createdAt: a,
2463
2463
  name: i,
2464
- model: d,
2464
+ model: u,
2465
2465
  toolCallId: c,
2466
2466
  toolCalls: r,
2467
- checkpointId: g,
2468
- checkpointNs: m,
2469
- toolStreaming: k,
2467
+ checkpointId: m,
2468
+ checkpointNs: y,
2469
+ toolStreaming: I,
2470
2470
  additionalKwargs: l,
2471
- responseMetadata: f,
2471
+ responseMetadata: d,
2472
2472
  artifact: t.artifact && typeof t.artifact == "object" && !t.artifact.type ? { ...t.artifact, type: t.name } : t.artifact ?? void 0
2473
2473
  };
2474
2474
  }
@@ -2510,14 +2510,14 @@ function ut(e) {
2510
2510
  return t === "running" || t === "pending" ? "pending" : t === "completed" || t === "success" ? "completed" : t === "error" || t === "failed" || t === "failure" ? "error" : null;
2511
2511
  }
2512
2512
  function dt(e) {
2513
- return (Array.isArray(e.toolCalls) ? e.toolCalls : Ct(e)).map(rt);
2513
+ return (Array.isArray(e.toolCalls) ? e.toolCalls : Mt(e)).map(rt);
2514
2514
  }
2515
- function Ke(e, t) {
2515
+ function He(e, t) {
2516
2516
  return t.find(
2517
2517
  (n) => n.role === "tool" && (n.toolCallId === e || n.id === e)
2518
2518
  );
2519
2519
  }
2520
- function qn(e, t) {
2520
+ function Kn(e, t) {
2521
2521
  const n = t.response ?? t.content;
2522
2522
  if (!n) return;
2523
2523
  const r = typeof n == "string" ? n : Et(n);
@@ -2533,21 +2533,21 @@ function qn(e, t) {
2533
2533
  createdAt: e.createdAt
2534
2534
  };
2535
2535
  }
2536
- function Hn(e, t = []) {
2536
+ function qn(e, t = []) {
2537
2537
  if (Array.isArray(e)) {
2538
2538
  const o = e.filter((a) => a.role === "assistant").flatMap((a) => dt(a)), s = /* @__PURE__ */ new Map();
2539
2539
  return o.forEach((a) => s.set(a.id, a)), Array.from(s.values()).map((a) => {
2540
- var f, g, m;
2541
- const i = Ke(a.id, e) || Ke(a.id, t), d = Array.isArray((f = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : f.toolProgress) ? (g = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : g.toolProgress : void 0, c = (i == null ? void 0 : i.artifact) ?? a.artifact, l = ut(a.status) ?? ((m = i == null ? void 0 : i.additionalKwargs) != null && m.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2540
+ var d, m, y;
2541
+ const i = He(a.id, e) || He(a.id, t), u = Array.isArray((d = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : d.toolProgress) ? (m = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : m.toolProgress : void 0, c = (i == null ? void 0 : i.artifact) ?? a.artifact, l = ut(a.status) ?? ((y = i == null ? void 0 : i.additionalKwargs) != null && y.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2542
2542
  if (i && !a.content && l === "completed") {
2543
- const k = ce(i);
2544
- typeof k == "string" && (a.content = k);
2543
+ const I = ce(i);
2544
+ typeof I == "string" && (a.content = I);
2545
2545
  }
2546
2546
  return {
2547
2547
  call: a,
2548
2548
  result: i,
2549
2549
  state: l,
2550
- progress: d,
2550
+ progress: u,
2551
2551
  artifact: c
2552
2552
  };
2553
2553
  });
@@ -2555,11 +2555,11 @@ function Hn(e, t = []) {
2555
2555
  if (e.role !== "assistant") return [];
2556
2556
  const n = dt(e);
2557
2557
  return n.length === 0 ? [] : n.map((r) => {
2558
- var d, c, l;
2559
- const o = Ke(r.id, t) ?? qn(e, r), s = Array.isArray((d = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : d.toolProgress) ? (c = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : c.toolProgress : void 0, a = (o == null ? void 0 : o.artifact) ?? r.artifact, i = ut(r.status) ?? ((l = o == null ? void 0 : o.additionalKwargs) != null && l.toolStreaming ? "pending" : null) ?? (o ? "completed" : "pending");
2558
+ var u, c, l;
2559
+ const o = He(r.id, t) ?? Kn(e, r), s = Array.isArray((u = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : u.toolProgress) ? (c = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : c.toolProgress : void 0, a = (o == null ? void 0 : o.artifact) ?? r.artifact, i = ut(r.status) ?? ((l = o == null ? void 0 : o.additionalKwargs) != null && l.toolStreaming ? "pending" : null) ?? (o ? "completed" : "pending");
2560
2560
  if (o && !r.content && i === "completed") {
2561
- const f = ce(o);
2562
- typeof f == "string" && (r.content = f);
2561
+ const d = ce(o);
2562
+ typeof d == "string" && (r.content = d);
2563
2563
  }
2564
2564
  return {
2565
2565
  call: r,
@@ -2571,7 +2571,7 @@ function Hn(e, t = []) {
2571
2571
  });
2572
2572
  }
2573
2573
  function ao(e, t = []) {
2574
- return Hn(e, t).map((n) => n.artifact).filter((n) => !!n);
2574
+ return qn(e, t).map((n) => n.artifact).filter((n) => !!n);
2575
2575
  }
2576
2576
  const ze = {
2577
2577
  authToken: "authToken",
@@ -2585,19 +2585,19 @@ const ze = {
2585
2585
  function Ge(e) {
2586
2586
  return `draft:${e}`;
2587
2587
  }
2588
- let qe = null;
2588
+ let Ke = null;
2589
2589
  const Qe = /* @__PURE__ */ new Set();
2590
2590
  function Pt() {
2591
- return qe;
2591
+ return Ke;
2592
2592
  }
2593
- function ke(e) {
2594
- qe = e, Qe.forEach((t) => t(e));
2593
+ function ve(e) {
2594
+ Ke = e, Qe.forEach((t) => t(e));
2595
2595
  }
2596
2596
  function _t(e) {
2597
2597
  return Qe.add(e), () => Qe.delete(e);
2598
2598
  }
2599
- const Kn = 12e4, Gn = 12e4;
2600
- let Ye = Kn, Nt = Gn;
2599
+ const Hn = 12e4, Gn = 12e4;
2600
+ let Ye = Hn, Nt = Gn;
2601
2601
  const ne = Jt.create({
2602
2602
  // BaseURL is set dynamically via ApiProvider -> api.updateConfig
2603
2603
  timeout: Ye,
@@ -2613,13 +2613,13 @@ function Wn(e) {
2613
2613
  function Jn() {
2614
2614
  return Nt;
2615
2615
  }
2616
- ne.interceptors.request.use((e) => (qe && (e.headers.Authorization = `Bearer ${qe}`), e));
2616
+ ne.interceptors.request.use((e) => (Ke && (e.headers.Authorization = `Bearer ${Ke}`), e));
2617
2617
  ne.interceptors.response.use(
2618
2618
  (e) => {
2619
2619
  if (typeof window < "u" && (e != null && e.data))
2620
2620
  try {
2621
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(ze.authToken, r), ke(r)), o && localStorage.setItem(ze.authTokenExpiresAt, o.toString()), (r || o) && window.dispatchEvent(
2622
+ r && (localStorage.setItem(ze.authToken, r), ve(r)), o && localStorage.setItem(ze.authTokenExpiresAt, o.toString()), (r || o) && window.dispatchEvent(
2623
2623
  new CustomEvent("smartorg:chat-token-updated", {
2624
2624
  detail: { token: r, expiresAt: o }
2625
2625
  })
@@ -2660,7 +2660,7 @@ class Yn {
2660
2660
  const n = t.baseUrl.replace(/\/+$/, "");
2661
2661
  ne.defaults.baseURL = n;
2662
2662
  }
2663
- t.apiKey !== void 0 ? ke(t.apiKey) : t.getToken && ke(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Wn({
2663
+ t.apiKey !== void 0 ? ve(t.apiKey) : t.getToken && ve(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Wn({
2664
2664
  requestTimeoutMs: t.requestTimeoutMs,
2665
2665
  historyTimeoutMs: t.historyTimeoutMs
2666
2666
  });
@@ -2670,7 +2670,7 @@ class Yn {
2670
2670
  return Pt();
2671
2671
  }
2672
2672
  setAuthToken(t) {
2673
- ke(t);
2673
+ ve(t);
2674
2674
  }
2675
2675
  onTokenChange(t) {
2676
2676
  return _t(t);
@@ -2820,14 +2820,14 @@ class er {
2820
2820
  const n = t.baseUrl.replace(/\/+$/, "");
2821
2821
  this._authBaseUrl = `${n}/auth`;
2822
2822
  }
2823
- t.apiKey !== void 0 ? ke(t.apiKey) : t.getToken && ke(t.getToken());
2823
+ t.apiKey !== void 0 ? ve(t.apiKey) : t.getToken && ve(t.getToken());
2824
2824
  }
2825
2825
  // ---- Token Management ----
2826
2826
  getAuthToken() {
2827
2827
  return Pt();
2828
2828
  }
2829
2829
  setAuthToken(t) {
2830
- ke(t);
2830
+ ve(t);
2831
2831
  }
2832
2832
  onTokenChange(t) {
2833
2833
  return _t(t);
@@ -2838,12 +2838,12 @@ class er {
2838
2838
  return (t == null ? void 0 : t.users) ?? [];
2839
2839
  }
2840
2840
  }
2841
- const tr = new er(), Lt = Me(null);
2841
+ const tr = new er(), Lt = Ce(null);
2842
2842
  function nr({ children: e, apiConfig: t }) {
2843
2843
  const n = zt, r = tr;
2844
2844
  if (t) {
2845
- const s = n.baseUrl, a = r.baseUrl, i = n.getAuthToken(), d = t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0;
2846
- (t.baseUrl || t.chatBaseUrl || d) && (d || 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 }));
2845
+ const s = n.baseUrl, a = r.baseUrl, i = n.getAuthToken(), u = t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0;
2846
+ (t.baseUrl || t.chatBaseUrl || u) && (u || 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 }));
2847
2847
  }
2848
2848
  const o = {
2849
2849
  token: n.getAuthToken(),
@@ -2865,7 +2865,7 @@ async function rr(e) {
2865
2865
  const o = r.result, s = new Uint8Array(o);
2866
2866
  let a = "";
2867
2867
  const i = s.byteLength;
2868
- for (let d = 0; d < i; d++) a += String.fromCharCode(s[d]);
2868
+ for (let u = 0; u < i; u++) a += String.fromCharCode(s[u]);
2869
2869
  t(btoa(a));
2870
2870
  } catch (o) {
2871
2871
  n(o);
@@ -2930,7 +2930,7 @@ function lo(e) {
2930
2930
  }).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("|");
2931
2931
  return `${e.id}:${t}:${n}${s ? `:${s}` : ""}`;
2932
2932
  }
2933
- function Ce() {
2933
+ function Me() {
2934
2934
  const e = Ue(Lt);
2935
2935
  if (!e) throw new Error("useApi must be used within ApiProvider");
2936
2936
  return e;
@@ -3009,72 +3009,72 @@ function fr(e, t) {
3009
3009
  return "type" in n || (n.type = e), n;
3010
3010
  }
3011
3011
  function pr(e = {}) {
3012
- const t = e.baseUrl || "", n = e.streamPath ?? "/stream", [r, o] = B(e.token ?? null), s = W(e.headers ?? {}), a = e.credentials ?? "include", i = W(e);
3012
+ const t = e.baseUrl || "", n = e.streamPath ?? "/stream", [r, o] = $(e.token ?? null), s = W(e.headers ?? {}), a = e.credentials ?? "include", i = W(e);
3013
3013
  X(() => {
3014
3014
  i.current = e;
3015
3015
  }, [e]);
3016
- const d = _((p) => {
3017
- var j, S, O, $, M, F, N, V, z, L;
3018
- const h = i.current;
3019
- if (!h) return;
3020
- (j = h.onEvent) == null || j.call(h, p), p.type === "thread_info" && ((S = h.onThreadInfo) == null || S.call(h, p)), p.type === "values" && Array.isArray(p.checkpoints) && ((O = h.handleValuesEvent) == null || O.call(h, p)), p.type === "metadata" && (($ = h.onMetadataEvent) == null || $.call(h, p)), typeof p.type == "string" && (p.type === "custom" || p.type.startsWith("custom.")) && ((M = h.onCustomEvent) == null || M.call(h, p)), p.type === "updates" && ((F = h.onUpdateEvent) == null || F.call(h, p)), p.type === "tool.end" ? (N = h.onToolEnd) == null || N.call(h, p) : p.type === "tool.start" && ((V = h.onToolStart) == null || V.call(h, p)), p.type === "heartbeat" && ((z = h.onHeartbeat) == null || z.call(h, p)), p.type === "token" && ((L = h.onToken) == null || L.call(h, p.token));
3021
- }, []), [c, l] = B(!1), [f, g] = B(null), [m, k] = B(!1), [u, w] = B(null), I = W(null), C = W(!0), x = W(null), E = _((p) => {
3022
- o(p);
3016
+ const u = _((g) => {
3017
+ var j, M, O, F, C, B, N, V, z, L;
3018
+ const b = i.current;
3019
+ if (!b) return;
3020
+ (j = b.onEvent) == null || j.call(b, g), g.type === "thread_info" && ((M = b.onThreadInfo) == null || M.call(b, g)), g.type === "values" && Array.isArray(g.checkpoints) && ((O = b.handleValuesEvent) == null || O.call(b, g)), g.type === "metadata" && ((F = b.onMetadataEvent) == null || F.call(b, g)), typeof g.type == "string" && (g.type === "custom" || g.type.startsWith("custom.")) && ((C = b.onCustomEvent) == null || C.call(b, g)), g.type === "updates" && ((B = b.onUpdateEvent) == null || B.call(b, g)), g.type === "tool.end" ? (N = b.onToolEnd) == null || N.call(b, g) : g.type === "tool.start" && ((V = b.onToolStart) == null || V.call(b, g)), g.type === "heartbeat" && ((z = b.onHeartbeat) == null || z.call(b, g)), g.type === "token" && ((L = b.onToken) == null || L.call(b, g.token));
3021
+ }, []), [c, l] = $(!1), [d, m] = $(null), [y, I] = $(!1), [f, k] = $(null), p = W(null), S = W(!0), A = W(null), E = _((g) => {
3022
+ o(g);
3023
3023
  }, []), v = _(() => {
3024
- g(null), w(null);
3025
- }, []), b = _(() => {
3026
- var S, O;
3024
+ m(null), k(null);
3025
+ }, []), w = _(() => {
3026
+ var M, O;
3027
3027
  console.debug("[use-chat] stop() invoked - aborting stream");
3028
- const p = (S = x.current) == null ? void 0 : S.threadId, h = (O = x.current) == null ? void 0 : O.runId, P = () => {
3029
- var $;
3030
- ($ = I.current) == null || $.abort(), I.current = null, x.current = null, l(!1), k(!1);
3028
+ const g = (M = A.current) == null ? void 0 : M.threadId, b = (O = A.current) == null ? void 0 : O.runId, P = () => {
3029
+ var F;
3030
+ (F = p.current) == null || F.abort(), p.current = null, A.current = null, l(!1), I(!1);
3031
3031
  };
3032
- (h || p ? zt.cancelRun(h || p).catch(($) => {
3033
- console.warn("[use-chat] cancel run failed:", $);
3032
+ (b || g ? zt.cancelRun(b || g).catch((F) => {
3033
+ console.warn("[use-chat] cancel run failed:", F);
3034
3034
  }) : Promise.resolve()).finally(P);
3035
- }, []), A = _(
3036
- (p) => {
3037
- I.current && (I.current.abort(), I.current = null);
3038
- const h = {
3039
- text: typeof p.content == "string" ? p.content : p.text,
3040
- threadId: p.threadId,
3041
- attachments: p.attachments,
3042
- payload: p.payload ? {
3043
- ...p.payload,
3044
- creativityLevel: p.payload.creativityLevel ?? "medium"
3035
+ }, []), x = _(
3036
+ (g) => {
3037
+ p.current && (p.current.abort(), p.current = null);
3038
+ const b = {
3039
+ text: typeof g.content == "string" ? g.content : g.text,
3040
+ threadId: g.threadId,
3041
+ attachments: g.attachments,
3042
+ payload: g.payload ? {
3043
+ ...g.payload,
3044
+ creativityLevel: g.payload.creativityLevel ?? "medium"
3045
3045
  } : { creativityLevel: "medium" },
3046
- config: p.config,
3047
- checkpointId: p.checkpointId,
3048
- checkpointNs: p.checkpointNs || void 0,
3049
- edit: p.edit ?? !1,
3050
- command: p.command
3046
+ config: g.config,
3047
+ checkpointId: g.checkpointId,
3048
+ checkpointNs: g.checkpointNs || void 0,
3049
+ edit: g.edit ?? !1,
3050
+ command: g.command
3051
3051
  };
3052
- l(!0), g(null), w(null);
3052
+ l(!0), m(null), k(null);
3053
3053
  const P = new AbortController();
3054
- I.current = P;
3055
- let j = null, S = !1;
3056
- return x.current = {
3057
- threadId: h.threadId ?? void 0,
3054
+ p.current = P;
3055
+ let j = null, M = !1;
3056
+ return A.current = {
3057
+ threadId: b.threadId ?? void 0,
3058
3058
  runId: void 0,
3059
3059
  // Will be updated from headers
3060
3060
  headers: {},
3061
3061
  isStreaming: !0
3062
3062
  }, (async () => {
3063
- var O, $, M, F, N, V;
3063
+ var O, F, C, B, N, V;
3064
3064
  try {
3065
3065
  let z = {};
3066
3066
  try {
3067
3067
  if (r)
3068
3068
  z = { Authorization: `Bearer ${r}` };
3069
3069
  else if (typeof window < "u") {
3070
- const te = window.__AUTH_TOKEN__, ve = ((O = window.localStorage) == null ? void 0 : O.getItem(ze.authToken)) || null;
3070
+ const te = window.__AUTH_TOKEN__, ke = ((O = window.localStorage) == null ? void 0 : O.getItem(ze.authToken)) || null;
3071
3071
  let Q = null;
3072
3072
  try {
3073
- const ge = ($ = window.localStorage) == null ? void 0 : $.getItem(ze.chatSettings);
3074
- ge && (Q = ((M = JSON.parse(ge)) == null ? void 0 : M.apiKey) || null);
3073
+ const ge = (F = window.localStorage) == null ? void 0 : F.getItem(ze.chatSettings);
3074
+ ge && (Q = ((C = JSON.parse(ge)) == null ? void 0 : C.apiKey) || null);
3075
3075
  } catch {
3076
3076
  }
3077
- const Z = te || ve || Q || null;
3077
+ const Z = te || ke || Q || null;
3078
3078
  Z && (z = { Authorization: `Bearer ${Z}` });
3079
3079
  }
3080
3080
  } catch {
@@ -3083,26 +3083,26 @@ function pr(e = {}) {
3083
3083
  let L = {};
3084
3084
  if (typeof window < "u")
3085
3085
  try {
3086
- const G = (F = window.localStorage) == null ? void 0 : F.getItem(ze.authSessionId);
3086
+ const G = (B = window.localStorage) == null ? void 0 : B.getItem(ze.authSessionId);
3087
3087
  G && (L = { "X-Session-Id": G });
3088
3088
  } catch {
3089
3089
  }
3090
- const K = {
3090
+ const H = {
3091
3091
  ...z,
3092
3092
  ...L,
3093
3093
  ...s.current
3094
- }, y = {
3094
+ }, h = {
3095
3095
  "Content-Type": "application/json",
3096
3096
  Accept: "text/event-stream",
3097
- ...K
3097
+ ...H
3098
3098
  }, U = await fetch(t + n, {
3099
3099
  method: "POST",
3100
- headers: y,
3101
- body: JSON.stringify(h),
3100
+ headers: h,
3101
+ body: JSON.stringify(b),
3102
3102
  signal: P.signal,
3103
3103
  credentials: a
3104
3104
  });
3105
- if (x.current && (x.current.headers = K), !U.ok || !U.body) {
3105
+ if (A.current && (A.current.headers = H), !U.ok || !U.body) {
3106
3106
  const G = await U.text().catch(() => "");
3107
3107
  console.debug(
3108
3108
  "[use-chat] non-OK response",
@@ -3110,45 +3110,45 @@ function pr(e = {}) {
3110
3110
  G == null ? void 0 : G.slice(0, 500)
3111
3111
  );
3112
3112
  const te = `stream ${U.status}${G ? ": " + G : ""}`;
3113
- throw te && (g(te), j = "error"), new Error(te);
3113
+ throw te && (m(te), j = "error"), new Error(te);
3114
3114
  }
3115
- k(!0);
3115
+ I(!0);
3116
3116
  const T = U.body.getReader(), J = new TextDecoder();
3117
- let q = "", H = 0, ee = Date.now();
3117
+ let K = "", q = 0, ee = Date.now();
3118
3118
  const re = setInterval(() => {
3119
- Date.now() - ee > 18e5 && (g("Stream idle timeout"), j = "error", P.abort());
3119
+ Date.now() - ee > 18e5 && (m("Stream idle timeout"), j = "error", P.abort());
3120
3120
  }, 5e3), ue = 1024 * 1024;
3121
3121
  try {
3122
3122
  const G = U.headers.get("X-Thread-Id") || U.headers.get("x-thread-id"), te = U.headers.get("X-Run-Id") || U.headers.get("x-run-id");
3123
- for (x.current && (x.current = {
3124
- ...x.current,
3125
- threadId: G ?? x.current.threadId,
3126
- runId: te ?? x.current.runId
3123
+ for (A.current && (A.current = {
3124
+ ...A.current,
3125
+ threadId: G ?? A.current.threadId,
3126
+ runId: te ?? A.current.runId
3127
3127
  }); ; ) {
3128
- const { value: ve, done: Q } = await T.read();
3128
+ const { value: ke, done: Q } = await T.read();
3129
3129
  if (Q) break;
3130
- q += J.decode(ve, { stream: !0 }), q.length > ue && (q = "", console.warn("Stream buffer reset: exceeded 1MB"));
3130
+ K += J.decode(ke, { stream: !0 }), K.length > ue && (K = "", console.warn("Stream buffer reset: exceeded 1MB"));
3131
3131
  let Z;
3132
- for (; (Z = q.indexOf(`
3132
+ for (; (Z = K.indexOf(`
3133
3133
 
3134
3134
  `)) >= 0; ) {
3135
- const ge = q.slice(0, Z);
3136
- q = q.slice(Z + 2);
3137
- const je = ge.split(/\r?\n/), Fe = [];
3135
+ const ge = K.slice(0, Z);
3136
+ K = K.slice(Z + 2);
3137
+ const je = ge.split(/\r?\n/), Be = [];
3138
3138
  let me = null;
3139
3139
  for (const he of je)
3140
3140
  if (!he.startsWith(":") && he) {
3141
3141
  if (he.startsWith("event:")) {
3142
- const Ae = he.slice(6).trim();
3143
- Ae && (me = Ae);
3142
+ const xe = he.slice(6).trim();
3143
+ xe && (me = xe);
3144
3144
  continue;
3145
3145
  }
3146
3146
  if (he.startsWith("data:")) {
3147
- const Ae = he.slice(5);
3148
- Fe.push(Ae.startsWith(" ") ? Ae.slice(1) : Ae);
3147
+ const xe = he.slice(5);
3148
+ Be.push(xe.startsWith(" ") ? xe.slice(1) : xe);
3149
3149
  }
3150
3150
  }
3151
- const Ie = Fe.join(`
3151
+ const Ie = Be.join(`
3152
3152
  `);
3153
3153
  if (!Ie) continue;
3154
3154
  let oe;
@@ -3164,17 +3164,17 @@ function pr(e = {}) {
3164
3164
  console.warn("[use-chat] dropped envelope event without payload", oe);
3165
3165
  continue;
3166
3166
  }
3167
- const xe = $n(Pe);
3167
+ const Ae = $n(Pe);
3168
3168
  ee = Date.now();
3169
- const ye = typeof xe.seq == "number" ? xe.seq : void 0;
3169
+ const ye = typeof Ae.seq == "number" ? Ae.seq : void 0;
3170
3170
  if (ye !== void 0) {
3171
- if (ye <= H) {
3172
- console.debug("[use-chat] drop duplicate/out-of-order event", { seq: ye, lastProcessedSeq: H, type: xe.type });
3171
+ if (ye <= q) {
3172
+ console.debug("[use-chat] drop duplicate/out-of-order event", { seq: ye, lastProcessedSeq: q, type: Ae.type });
3173
3173
  continue;
3174
3174
  }
3175
- H = ye;
3175
+ q = ye;
3176
3176
  }
3177
- d(xe);
3177
+ u(Ae);
3178
3178
  }
3179
3179
  }
3180
3180
  j === null && !P.signal.aborted && (j = "complete");
@@ -3183,7 +3183,7 @@ function pr(e = {}) {
3183
3183
  j = j ?? "aborted";
3184
3184
  else {
3185
3185
  const te = G.message || String(G);
3186
- j = "error", g(te);
3186
+ j = "error", m(te);
3187
3187
  }
3188
3188
  } finally {
3189
3189
  try {
@@ -3199,7 +3199,7 @@ function pr(e = {}) {
3199
3199
  j = j ?? "aborted";
3200
3200
  else {
3201
3201
  const L = z.message || String(z);
3202
- j = "error", g(L), S || (S = !0, (V = e.onConnectionError) == null || V.call(e, L));
3202
+ j = "error", m(L), M || (M = !0, (V = e.onConnectionError) == null || V.call(e, L));
3203
3203
  }
3204
3204
  } finally {
3205
3205
  try {
@@ -3216,29 +3216,29 @@ function pr(e = {}) {
3216
3216
  } catch (z) {
3217
3217
  console.warn("[use-chat] onClosed callback failed", z);
3218
3218
  }
3219
- l(!1), k(!1), I.current = null, x.current = null;
3219
+ l(!1), I(!1), p.current = null, A.current = null;
3220
3220
  }
3221
3221
  })(), Promise.resolve();
3222
3222
  },
3223
- [t, n, r, e, d]
3223
+ [t, n, r, e, u]
3224
3224
  );
3225
3225
  return X(() => () => {
3226
- var p;
3227
- C.current = !1, (p = I.current) == null || p.abort();
3226
+ var g;
3227
+ S.current = !1, (g = p.current) == null || g.abort();
3228
3228
  }, []), {
3229
3229
  isStreaming: c,
3230
- error: f,
3230
+ error: d,
3231
3231
  assistantText: "",
3232
3232
  // Deprecated: use messages from reducer
3233
- activeMessageId: u,
3233
+ activeMessageId: f,
3234
3234
  streamedMessages: {},
3235
3235
  // Deprecated: use messages from reducer
3236
3236
  lastCheckpointId: null,
3237
3237
  // Deprecated: use checkpoint from reducer
3238
3238
  lastSeq: 0,
3239
- connected: m,
3240
- stream: A,
3241
- stop: b,
3239
+ connected: y,
3240
+ stream: x,
3241
+ stop: w,
3242
3242
  clear: v,
3243
3243
  setToken: E,
3244
3244
  values: {},
@@ -3246,10 +3246,10 @@ function pr(e = {}) {
3246
3246
  interrupt: () => Promise.resolve(),
3247
3247
  resume: () => Promise.resolve(),
3248
3248
  goto: () => Promise.resolve(),
3249
- connectionState: f ? "error" : c ? m ? "connected" : "connecting" : "idle",
3249
+ connectionState: d ? "error" : c ? y ? "connected" : "connecting" : "idle",
3250
3250
  messages: [],
3251
3251
  // useStream doesn't maintain messages, use useChatSession instead
3252
- submit: A
3252
+ submit: x
3253
3253
  };
3254
3254
  }
3255
3255
  function gr({
@@ -3259,77 +3259,77 @@ function gr({
3259
3259
  onThreadChange: r,
3260
3260
  onCurrentThreadDeleted: o
3261
3261
  }) {
3262
- const [s, a] = B([]), [i, d] = B(t), [c, l] = B(!1), [f, g] = B(null), m = W(i), k = W(/* @__PURE__ */ new Map());
3262
+ const [s, a] = $([]), [i, u] = $(t), [c, l] = $(!1), [d, m] = $(null), y = W(i), I = W(/* @__PURE__ */ new Map());
3263
3263
  X(() => {
3264
- m.current = i;
3264
+ y.current = i;
3265
3265
  }, [i]), X(() => {
3266
- t !== void 0 && t !== m.current && d(t);
3266
+ t !== void 0 && t !== y.current && u(t);
3267
3267
  }, [t]);
3268
- const u = _(async () => {
3269
- l(!0), g(null);
3268
+ const f = _(async () => {
3269
+ l(!0), m(null);
3270
3270
  try {
3271
3271
  const v = await e.listThreads();
3272
3272
  a(v ?? []);
3273
3273
  } catch (v) {
3274
- const b = String(v);
3275
- g(b), n == null || n(b);
3274
+ const w = String(v);
3275
+ m(w), n == null || n(w);
3276
3276
  } finally {
3277
3277
  l(!1);
3278
3278
  }
3279
3279
  }, [e, n]);
3280
3280
  X(() => {
3281
- u();
3282
- }, [u]), X(() => {
3281
+ f();
3282
+ }, [f]), X(() => {
3283
3283
  r == null || r(i);
3284
3284
  }, [i, r]);
3285
- const w = _(
3286
- async (v, b) => {
3285
+ const k = _(
3286
+ async (v, w) => {
3287
3287
  try {
3288
- const A = b && typeof b == "object" ? { id: b.id, name: b.name ?? "" } : void 0, p = await e.createThread(v, A);
3289
- return d(p.threadId), await u(), p.threadId;
3290
- } catch (A) {
3291
- const p = String(A);
3292
- return n == null || n(p), null;
3288
+ const x = w && typeof w == "object" ? { id: w.id, name: w.name ?? "" } : void 0, g = await e.createThread(v, x);
3289
+ return u(g.threadId), await f(), g.threadId;
3290
+ } catch (x) {
3291
+ const g = String(x);
3292
+ return n == null || n(g), null;
3293
3293
  }
3294
3294
  },
3295
- [e, n, u]
3296
- ), I = _(
3295
+ [e, n, f]
3296
+ ), p = _(
3297
3297
  async (v) => {
3298
- const b = s;
3299
- a((p) => p.filter((h) => h.threadId !== v));
3300
- const A = new AbortController();
3301
- k.current.set(v, A);
3298
+ const w = s;
3299
+ a((g) => g.filter((b) => b.threadId !== v));
3300
+ const x = new AbortController();
3301
+ I.current.set(v, x);
3302
3302
  try {
3303
- await e.deleteThread(v), m.current === v && (d(null), o == null || o());
3304
- } catch (p) {
3305
- a(b);
3306
- const h = String(p);
3307
- n == null || n(h);
3303
+ await e.deleteThread(v), y.current === v && (u(null), o == null || o());
3304
+ } catch (g) {
3305
+ a(w);
3306
+ const b = String(g);
3307
+ n == null || n(b);
3308
3308
  } finally {
3309
- k.current.delete(v);
3309
+ I.current.delete(v);
3310
3310
  }
3311
3311
  },
3312
3312
  [e, o, n, s]
3313
- ), C = _(
3314
- async (v, b) => {
3313
+ ), S = _(
3314
+ async (v, w) => {
3315
3315
  try {
3316
- await e.updateThread(v, b), await u();
3317
- } catch (A) {
3318
- n == null || n(String(A));
3316
+ await e.updateThread(v, w), await f();
3317
+ } catch (x) {
3318
+ n == null || n(String(x));
3319
3319
  }
3320
3320
  },
3321
- [e, n, u]
3322
- ), x = Y(
3321
+ [e, n, f]
3322
+ ), A = Y(
3323
3323
  () => ({
3324
- createThread: w,
3325
- deleteThread: I,
3326
- renameThread: C,
3327
- refreshThreads: u
3324
+ createThread: k,
3325
+ deleteThread: p,
3326
+ renameThread: S,
3327
+ refreshThreads: f
3328
3328
  }),
3329
- [w, I, C, u]
3329
+ [k, p, S, f]
3330
3330
  ), E = _((v) => {
3331
3331
  if (!(v != null && v.threadId)) return;
3332
- const b = {
3332
+ const w = {
3333
3333
  threadId: v.threadId,
3334
3334
  title: v.title || `Thread ${v.threadId.slice(0, 8)}`,
3335
3335
  project: v.project,
@@ -3337,80 +3337,80 @@ function gr({
3337
3337
  updatedAt: v.updatedAt || (/* @__PURE__ */ new Date()).toISOString(),
3338
3338
  messageCount: v.messageCount ?? 1
3339
3339
  };
3340
- a((A) => {
3341
- let p = !1;
3342
- const h = A.map((P) => P.threadId === b.threadId ? (p = !0, console.debug("[useThreadsState] thread_info: updating existing thread", b.threadId), {
3340
+ a((x) => {
3341
+ let g = !1;
3342
+ const b = x.map((P) => P.threadId === w.threadId ? (g = !0, console.debug("[useThreadsState] thread_info: updating existing thread", w.threadId), {
3343
3343
  ...P,
3344
- title: b.title ?? P.title,
3345
- project: b.project ?? P.project,
3346
- updatedAt: b.updatedAt ?? P.updatedAt,
3347
- messageCount: b.messageCount ?? P.messageCount
3344
+ title: w.title ?? P.title,
3345
+ project: w.project ?? P.project,
3346
+ updatedAt: w.updatedAt ?? P.updatedAt,
3347
+ messageCount: w.messageCount ?? P.messageCount
3348
3348
  }) : P);
3349
- return p ? h : (console.debug("[useThreadsState] thread_info: adding thread to list", b.threadId), [b, ...A]);
3349
+ return g ? b : (console.debug("[useThreadsState] thread_info: adding thread to list", w.threadId), [w, ...x]);
3350
3350
  });
3351
3351
  }, []);
3352
3352
  return {
3353
3353
  threads: s,
3354
3354
  currentThreadId: i,
3355
- currentThreadIdRef: m,
3356
- setCurrentThreadId: d,
3355
+ currentThreadIdRef: y,
3356
+ setCurrentThreadId: u,
3357
3357
  isLoadingThreads: c,
3358
- threadsError: f,
3359
- actions: x,
3358
+ threadsError: d,
3359
+ actions: A,
3360
3360
  addThreadFromEvent: E
3361
3361
  };
3362
3362
  }
3363
- const jt = Me(null);
3363
+ const jt = Ce(null);
3364
3364
  function mr({
3365
3365
  children: e,
3366
3366
  initialThreadId: t = null,
3367
3367
  onError: n,
3368
3368
  onThreadChange: r
3369
3369
  }) {
3370
- const { chatApi: o } = Ce(), {
3370
+ const { chatApi: o } = Me(), {
3371
3371
  threads: s,
3372
3372
  currentThreadId: a,
3373
3373
  setCurrentThreadId: i,
3374
- currentThreadIdRef: d,
3374
+ currentThreadIdRef: u,
3375
3375
  isLoadingThreads: c,
3376
3376
  threadsError: l,
3377
- actions: f,
3378
- addThreadFromEvent: g
3377
+ actions: d,
3378
+ addThreadFromEvent: m
3379
3379
  } = gr({
3380
3380
  api: o,
3381
3381
  initialThreadId: t,
3382
3382
  onError: n,
3383
3383
  onThreadChange: r
3384
- }), m = Y(
3384
+ }), y = Y(
3385
3385
  () => ({
3386
3386
  threads: s,
3387
3387
  currentThreadId: a,
3388
3388
  setCurrentThreadId: i,
3389
- currentThreadIdRef: d,
3389
+ currentThreadIdRef: u,
3390
3390
  isLoading: c,
3391
3391
  error: l,
3392
- actions: f,
3393
- addThreadFromEvent: g
3392
+ actions: d,
3393
+ addThreadFromEvent: m
3394
3394
  }),
3395
3395
  [
3396
3396
  s,
3397
3397
  a,
3398
3398
  i,
3399
- d,
3399
+ u,
3400
3400
  c,
3401
3401
  l,
3402
- f,
3403
- g
3402
+ d,
3403
+ m
3404
3404
  ]
3405
3405
  );
3406
- return /* @__PURE__ */ ie(jt.Provider, { value: m, children: e });
3406
+ return /* @__PURE__ */ ie(jt.Provider, { value: y, children: e });
3407
3407
  }
3408
3408
  function ot(e) {
3409
3409
  const t = Ue(jt);
3410
3410
  if (!t && !(e != null && e.optional)) throw new Error("useThreads must be used within a ThreadsProvider");
3411
3411
  return t;
3412
3412
  }
3413
- function Ft(e) {
3413
+ function Bt(e) {
3414
3414
  const t = e.artifact;
3415
3415
  return !t || typeof t != "object" ? null : "metadata" in t && t.metadata ? t.metadata : {
3416
3416
  id: t.id ?? e.id ?? `artifact-${Date.now()}`,
@@ -3421,7 +3421,7 @@ function Ft(e) {
3421
3421
  };
3422
3422
  }
3423
3423
  function yr(e, t) {
3424
- const n = Ft(e);
3424
+ const n = Bt(e);
3425
3425
  if (!n) return e;
3426
3426
  const r = {
3427
3427
  ...n,
@@ -3438,25 +3438,26 @@ function yr(e, t) {
3438
3438
  }
3439
3439
  function hr(e, t, n) {
3440
3440
  return e.find((r) => {
3441
- const o = Ft(r);
3441
+ const o = Bt(r);
3442
3442
  return !!((o == null ? void 0 : o.id) === t || n && r.toolCallId === n);
3443
3443
  }) ?? null;
3444
3444
  }
3445
- function Be(e) {
3446
- return e.map((t) => nt(t)).filter((t) => !!t);
3445
+ function Oe(e) {
3446
+ const t = /* @__PURE__ */ new Set();
3447
+ return e.map((n) => nt(n)).filter((n) => !n || t.has(n.id) ? !1 : (t.add(n.id), !0));
3447
3448
  }
3448
- function Ot(e, t, n) {
3449
+ function Ft(e, t, n) {
3449
3450
  return t < 0 || t >= e.length ? e : [...e.slice(0, t), n, ...e.slice(t + 1)];
3450
3451
  }
3451
3452
  function br(e, t, n) {
3452
3453
  for (let r = e.length - 1; r >= 0; r--)
3453
3454
  if (e[r].role === "assistant") {
3454
3455
  const s = { ...e[r], checkpointId: t, checkpointNs: n ?? void 0 };
3455
- return Ot(e, r, s);
3456
+ return Ft(e, r, s);
3456
3457
  }
3457
3458
  return e;
3458
3459
  }
3459
- const Bt = {
3460
+ const Ot = {
3460
3461
  status: "idle",
3461
3462
  messages: [],
3462
3463
  taskMessagesByScope: {},
@@ -3479,8 +3480,8 @@ function wr(e, t) {
3479
3480
  };
3480
3481
  case "reset":
3481
3482
  return {
3482
- ...Bt,
3483
- messages: Be(((n = t.payload) == null ? void 0 : n.messages) ?? [])
3483
+ ...Ot,
3484
+ messages: Oe(((n = t.payload) == null ? void 0 : n.messages) ?? [])
3484
3485
  };
3485
3486
  case "user_message": {
3486
3487
  const { message: r } = t.payload;
@@ -3494,7 +3495,7 @@ function wr(e, t) {
3494
3495
  };
3495
3496
  }
3496
3497
  case "seed": {
3497
- const r = Be(t.payload.messages), o = {
3498
+ const r = Oe(t.payload.messages), o = {
3498
3499
  ...e,
3499
3500
  status: "idle",
3500
3501
  messages: r,
@@ -3506,7 +3507,7 @@ function wr(e, t) {
3506
3507
  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;
3507
3508
  }
3508
3509
  case "prepend": {
3509
- const r = Be(t.payload.messages);
3510
+ const r = Oe(t.payload.messages);
3510
3511
  if (!r.length) return e;
3511
3512
  const o = new Set(e.messages.map((a) => a.id)), s = r.filter((a) => !o.has(a.id));
3512
3513
  return s.length ? { ...e, messages: [...s, ...e.messages] } : e;
@@ -3521,8 +3522,8 @@ function wr(e, t) {
3521
3522
  return e;
3522
3523
  }
3523
3524
  }
3524
- function vr(e = []) {
3525
- const [t, n] = Wt(wr, { ...Bt, messages: e }), r = W([]), o = W(null), s = _(() => {
3525
+ function kr(e = []) {
3526
+ const [t, n] = Wt(wr, { ...Ot, messages: e }), r = W([]), o = W(null), s = _(() => {
3526
3527
  o.current !== null && typeof window < "u" && window.cancelAnimationFrame(o.current), o.current = null;
3527
3528
  const c = r.current;
3528
3529
  c.length && (r.current = [], n({ type: "batch", payload: { events: c } }));
@@ -3530,14 +3531,14 @@ function vr(e = []) {
3530
3531
  typeof window < "u" && typeof window.requestAnimationFrame == "function" ? o.current === null && (o.current = window.requestAnimationFrame(() => s())) : setTimeout(s, 8);
3531
3532
  }, [s]), i = _((c) => {
3532
3533
  r.current.push(c), a();
3533
- }, [a]), d = Y(() => ({
3534
+ }, [a]), u = Y(() => ({
3534
3535
  setStatus: (c, l) => n({ type: "status", payload: { status: c, error: l } }),
3535
3536
  reset: (c) => n({ type: "reset", payload: { messages: c } }),
3536
3537
  seed: (c, l) => n({ type: "seed", payload: { messages: c, ...l ?? {} } }),
3537
3538
  pushUser: (c, l) => n({ type: "user_message", payload: { message: c, editingMessageId: l } }),
3538
3539
  onEvent: i
3539
3540
  }), [i]);
3540
- return { state: t, dispatch: n, ...d };
3541
+ return { state: t, dispatch: n, ...u };
3541
3542
  }
3542
3543
  function pt(e, t) {
3543
3544
  const n = t.origin, r = t.scope, o = n === "task" || typeof r == "string" && r.startsWith("tools:");
@@ -3570,31 +3571,33 @@ function pt(e, t) {
3570
3571
  return { ...e, status: "error", error: t.message, messages: [...e.messages, s] };
3571
3572
  }
3572
3573
  if (t.type === "values" && "messages" in t && Array.isArray(t.messages)) {
3573
- const s = t, a = Array.isArray(s.messages) ? s.messages : [], i = Be(a), { messages: d, ...c } = s, l = c.__interrupt__ ?? c.interrupts, f = Array.isArray(l) && l.length > 0 ? {
3574
+ const s = t, a = Array.isArray(s.messages) ? s.messages : [], i = Oe(a), { messages: u, ...c } = s, l = c.__interrupt__ ?? c.interrupts, d = Array.isArray(l) && l.length > 0 ? {
3574
3575
  id: l[0].id || "native-interrupt",
3575
3576
  value: l[0].value || l[0],
3576
3577
  alternatives: l[0].alternatives
3577
3578
  } : null;
3578
3579
  if (o) {
3579
- const g = typeof r == "string" && r.length > 0 ? r : "task";
3580
+ const m = typeof r == "string" && r.length > 0 ? r : "task";
3580
3581
  return {
3581
3582
  ...e,
3582
- taskMessagesByScope: { ...e.taskMessagesByScope, [g]: i }
3583
+ taskMessagesByScope: { ...e.taskMessagesByScope, [m]: i },
3584
+ assemblingId: null
3585
+ // Clear streaming state when finalized
3583
3586
  };
3584
3587
  }
3585
3588
  return {
3586
3589
  ...e,
3587
- status: f ? "awaiting_input" : e.status === "streaming" ? "idle" : e.status,
3590
+ status: d ? "awaiting_input" : e.status === "streaming" ? "idle" : e.status,
3588
3591
  messages: i,
3589
3592
  assemblingId: null,
3590
- pendingInterrupt: f,
3593
+ pendingInterrupt: d,
3591
3594
  values: c
3592
3595
  };
3593
3596
  }
3594
3597
  if (t.type === "messages/metadata") {
3595
3598
  const s = { ...e.messagesStreamMeta ?? {} }, a = t.metadata;
3596
- return a && typeof a == "object" && Object.entries(a).forEach(([i, d]) => {
3597
- const c = d == null ? void 0 : d.metadata;
3599
+ return a && typeof a == "object" && Object.entries(a).forEach(([i, u]) => {
3600
+ const c = u == null ? void 0 : u.metadata;
3598
3601
  if (!c || typeof c != "object") return;
3599
3602
  const l = s[i] ?? {};
3600
3603
  s[i] = {
@@ -3603,49 +3606,50 @@ function pt(e, t) {
3603
3606
  };
3604
3607
  }), { ...e, messagesStreamMeta: s };
3605
3608
  }
3606
- return t.type === "messages/partial" ? kr(e, t) : t.type === "tool.start" ? { ...Ir(e, t), status: "streaming" } : t.type === "tool.progress" ? xr(e, t) : t.type === "tool.end" ? Ar(e, t) : t.type === "artifact.update" ? Tr(e, t) : e;
3609
+ return t.type === "messages/partial" ? vr(e, t, o) : t.type === "tool.start" ? { ...Ir(e, t, o), status: "streaming" } : t.type === "tool.progress" ? Ar(e, t, o) : t.type === "tool.end" ? xr(e, t, o) : t.type === "artifact.update" ? Tr(e, t) : e;
3607
3610
  }
3608
- function kr(e, t) {
3609
- var l, f, g, m, k;
3610
- const n = t.messages;
3611
- if (!n.length)
3611
+ function vr(e, t, n) {
3612
+ var m, y, I, f, k;
3613
+ const r = t.messages;
3614
+ if (!r.length)
3612
3615
  return console.warn("[messagesReducer] Dropping messages/partial event without messages[]", t), e;
3613
- const r = n.find((u) => u.type === "ai" || u.type === "assistant" || u.role === "assistant");
3614
- if (!r) return e;
3615
- const o = r.id, s = r.content ?? "", a = typeof s == "string" ? [{ type: "text", text: s }] : Array.isArray(s) ? s.map((u) => typeof u == "string" ? { type: "text", text: u } : (u == null ? void 0 : u.type) === "text" ? { type: "text", text: typeof u.text == "string" ? u.text : u.content ?? "" } : ((u == null ? void 0 : u.type) === "reasoning", u)) : [], i = a.filter((u) => u.type === "text").map((u) => u.text).join(""), d = e.assemblingId !== o;
3616
- let c = [...e.messages];
3617
- if (d) {
3618
- const u = nt({
3619
- ...r,
3616
+ const o = r.find((p) => p.type === "ai" || p.type === "assistant" || p.role === "assistant");
3617
+ if (!o) return e;
3618
+ const s = o.id, a = o.content ?? "", i = typeof a == "string" ? [{ type: "text", text: a }] : Array.isArray(a) ? a.map((p) => typeof p == "string" ? { type: "text", text: p } : (p == null ? void 0 : p.type) === "text" ? { type: "text", text: typeof p.text == "string" ? p.text : p.content ?? "" } : ((p == null ? void 0 : p.type) === "reasoning", p)) : [], u = i.filter((p) => p.type === "text").map((p) => p.text).join(""), c = e.assemblingId !== s, l = typeof t.scope == "string" && t.scope.length > 0 ? t.scope : "task";
3619
+ let d = n ? [...e.taskMessagesByScope[l] || []] : [...e.messages];
3620
+ if (c) {
3621
+ const p = nt({
3622
+ ...o,
3620
3623
  role: "assistant",
3621
- content: a,
3624
+ content: i,
3622
3625
  scope: t.scope,
3623
3626
  origin: t.origin
3624
3627
  });
3625
- u && c.push(u);
3628
+ p && d.push(p);
3626
3629
  } else {
3627
- const u = c.findIndex((w) => w.id === o);
3628
- if (u !== -1) {
3629
- const w = c[u];
3630
- c[u] = {
3631
- ...w,
3632
- content: a,
3633
- scope: t.scope ?? w.scope,
3634
- origin: t.origin ?? w.origin
3630
+ const p = d.findIndex((S) => S.id === s);
3631
+ if (p !== -1) {
3632
+ const S = d[p];
3633
+ d[p] = {
3634
+ ...S,
3635
+ content: i,
3636
+ scope: t.scope ?? S.scope,
3637
+ origin: t.origin ?? S.origin
3635
3638
  };
3636
3639
  }
3637
3640
  }
3638
3641
  return {
3639
3642
  ...e,
3640
3643
  status: "streaming",
3641
- messages: c,
3642
- assemblingId: o,
3644
+ messages: n ? e.messages : d,
3645
+ taskMessagesByScope: n ? { ...e.taskMessagesByScope, [l]: d } : e.taskMessagesByScope,
3646
+ assemblingId: s,
3643
3647
  messagesStreamMeta: {
3644
3648
  ...e.messagesStreamMeta ?? {},
3645
- [o]: {
3646
- ...((l = e.messagesStreamMeta) == null ? void 0 : l[o]) ?? {},
3647
- lastSeq: t.seq ?? ((g = (f = e.messagesStreamMeta) == null ? void 0 : f[o]) == null ? void 0 : g.lastSeq) ?? null,
3648
- lastText: i || (((k = (m = e.messagesStreamMeta) == null ? void 0 : m[o]) == null ? void 0 : k.lastText) ?? "")
3649
+ [s]: {
3650
+ ...((m = e.messagesStreamMeta) == null ? void 0 : m[s]) ?? {},
3651
+ lastSeq: t.seq ?? ((I = (y = e.messagesStreamMeta) == null ? void 0 : y[s]) == null ? void 0 : I.lastSeq) ?? null,
3652
+ lastText: u || (((k = (f = e.messagesStreamMeta) == null ? void 0 : f[s]) == null ? void 0 : k.lastText) ?? "")
3649
3653
  }
3650
3654
  }
3651
3655
  };
@@ -3660,21 +3664,21 @@ function st(e, t) {
3660
3664
  }
3661
3665
  return -1;
3662
3666
  }
3663
- function Ir(e, t) {
3664
- const n = t.id || t.callId;
3665
- if (!n) return e;
3666
- const r = t.name || "tool", o = `Starting ${r}...`;
3667
- let s = [...e.messages], a = st(s, n);
3668
- if (a === -1) {
3669
- for (let i = s.length - 1; i >= 0; i--)
3670
- if (s[i].role === "assistant") {
3671
- a = i;
3667
+ function Ir(e, t, n) {
3668
+ const r = t.id || t.callId;
3669
+ if (!r) return e;
3670
+ const o = t.name || "tool", s = `Starting ${o}...`, a = typeof t.scope == "string" && t.scope.length > 0 ? t.scope : "task";
3671
+ let i = n ? [...e.taskMessagesByScope[a] || []] : [...e.messages], u = st(i, r);
3672
+ if (u === -1) {
3673
+ for (let c = i.length - 1; c >= 0; c--)
3674
+ if (i[c].role === "assistant") {
3675
+ u = c;
3672
3676
  break;
3673
3677
  }
3674
3678
  }
3675
- if (a === -1) {
3676
- const i = {
3677
- id: `assistant-${n}`,
3679
+ if (u === -1) {
3680
+ const c = {
3681
+ id: `assistant-${r}`,
3678
3682
  role: "assistant",
3679
3683
  content: [{ type: "text", text: "" }],
3680
3684
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3682,76 +3686,90 @@ function Ir(e, t) {
3682
3686
  scope: t.scope,
3683
3687
  origin: t.origin
3684
3688
  };
3685
- s.push(i), a = s.length - 1;
3689
+ i.push(c), u = i.length - 1;
3686
3690
  }
3687
- if (a !== -1) {
3688
- const i = s[a], d = [...i.toolCalls || []], c = d.findIndex((l) => l.id === n);
3689
- c >= 0 ? d[c] = { ...d[c], status: "running", content: o } : d.push({
3690
- id: n,
3691
- name: r,
3691
+ if (u !== -1) {
3692
+ const c = i[u], l = [...c.toolCalls || []], d = l.findIndex((m) => m.id === r);
3693
+ d >= 0 ? l[d] = { ...l[d], status: "running", content: s } : l.push({
3694
+ id: r,
3695
+ name: o,
3692
3696
  args: t.args || {},
3693
3697
  status: "running",
3694
- content: o
3695
- }), s[a] = {
3696
- ...i,
3697
- toolCalls: d,
3698
- scope: t.scope ?? i.scope,
3699
- origin: t.origin ?? i.origin
3698
+ content: s
3699
+ }), i[u] = {
3700
+ ...c,
3701
+ toolCalls: l,
3702
+ scope: t.scope ?? c.scope,
3703
+ origin: t.origin ?? c.origin
3700
3704
  };
3701
3705
  }
3702
- return { ...e, messages: s };
3706
+ return {
3707
+ ...e,
3708
+ messages: n ? e.messages : i,
3709
+ taskMessagesByScope: n ? { ...e.taskMessagesByScope, [a]: i } : e.taskMessagesByScope
3710
+ };
3703
3711
  }
3704
- function xr(e, t) {
3705
- const n = t.id;
3706
- if (!n) return e;
3707
- let r = [...e.messages];
3708
- const o = st(r, n);
3709
- if (o !== -1) {
3710
- const s = r[o], a = ce(t.content), i = (s.toolCalls || []).map(
3711
- (d) => d.id === n ? { ...d, content: typeof a == "string" ? a : d.content } : d
3712
+ function Ar(e, t, n) {
3713
+ const r = t.id;
3714
+ if (!r) return e;
3715
+ const o = typeof t.scope == "string" && t.scope.length > 0 ? t.scope : "task";
3716
+ let s = n ? [...e.taskMessagesByScope[o] || []] : [...e.messages];
3717
+ const a = st(s, r);
3718
+ if (a !== -1) {
3719
+ const i = s[a], u = ce(t.content), c = (i.toolCalls || []).map(
3720
+ (l) => l.id === r ? { ...l, content: typeof u == "string" ? u : l.content } : l
3712
3721
  );
3713
- r[o] = {
3714
- ...s,
3715
- toolCalls: i,
3716
- scope: t.scope ?? s.scope,
3717
- origin: t.origin ?? s.origin
3722
+ s[a] = {
3723
+ ...i,
3724
+ toolCalls: c,
3725
+ scope: t.scope ?? i.scope,
3726
+ origin: t.origin ?? i.origin
3718
3727
  };
3719
3728
  }
3720
- return { ...e, messages: r };
3729
+ return {
3730
+ ...e,
3731
+ messages: n ? e.messages : s,
3732
+ taskMessagesByScope: n ? { ...e.taskMessagesByScope, [o]: s } : e.taskMessagesByScope
3733
+ };
3721
3734
  }
3722
- function Ar(e, t) {
3723
- const n = t.id;
3724
- if (!n) return e;
3725
- let r = [...e.messages];
3726
- const o = st(r, n), s = ce(t.content ?? t.error);
3727
- if (o !== -1) {
3728
- const i = r[o], d = (i.toolCalls || []).map(
3729
- (c) => c.id === n ? {
3730
- ...c,
3735
+ function xr(e, t, n) {
3736
+ const r = t.id;
3737
+ if (!r) return e;
3738
+ const o = typeof t.scope == "string" && t.scope.length > 0 ? t.scope : "task";
3739
+ let s = n ? [...e.taskMessagesByScope[o] || []] : [...e.messages];
3740
+ const a = st(s, r), i = ce(t.content ?? t.error);
3741
+ if (a !== -1) {
3742
+ const c = s[a], l = (c.toolCalls || []).map(
3743
+ (d) => d.id === r ? {
3744
+ ...d,
3731
3745
  status: t.error ? "failed" : "completed",
3732
- content: typeof s == "string" ? s : c.content,
3746
+ content: typeof i == "string" ? i : d.content,
3733
3747
  artifact: t.artifact
3734
- } : c
3748
+ } : d
3735
3749
  );
3736
- r[o] = {
3737
- ...i,
3738
- toolCalls: d,
3739
- scope: t.scope ?? i.scope,
3740
- origin: t.origin ?? i.origin
3750
+ s[a] = {
3751
+ ...c,
3752
+ toolCalls: l,
3753
+ scope: t.scope ?? c.scope,
3754
+ origin: t.origin ?? c.origin
3741
3755
  };
3742
3756
  }
3743
- const a = {
3744
- id: `tool-${n}`,
3757
+ const u = {
3758
+ id: `tool-${r}`,
3745
3759
  role: "tool",
3746
3760
  name: t.name,
3747
- content: [{ type: "text", text: typeof s == "string" ? s : "" }],
3761
+ content: [{ type: "text", text: typeof i == "string" ? i : "" }],
3748
3762
  artifact: t.artifact,
3749
- toolCallId: n,
3763
+ toolCallId: r,
3750
3764
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3751
3765
  scope: t.scope,
3752
3766
  origin: t.origin
3753
3767
  };
3754
- return { ...e, messages: [...r, a] };
3768
+ return s.push(u), {
3769
+ ...e,
3770
+ messages: n ? e.messages : s,
3771
+ taskMessagesByScope: n ? { ...e.taskMessagesByScope, [o]: s } : e.taskMessagesByScope
3772
+ };
3755
3773
  }
3756
3774
  function Tr(e, t) {
3757
3775
  const n = t.artifactId, r = hr(e.messages, n, t.callId);
@@ -3761,13 +3779,13 @@ function Tr(e, t) {
3761
3779
  progress: t.progress,
3762
3780
  error: t.error
3763
3781
  });
3764
- return t.partial_data && s.artifact && (s.artifact = { ...s.artifact, ...t.partial_data }), { ...e, messages: Ot(e.messages, o, s) };
3782
+ return t.partial_data && s.artifact && (s.artifact = { ...s.artifact, ...t.partial_data }), { ...e, messages: Ft(e.messages, o, s) };
3765
3783
  }
3766
3784
  function Re(e) {
3767
3785
  if (!(!e || typeof e != "object" || Array.isArray(e)))
3768
3786
  return { ...e };
3769
3787
  }
3770
- function Oe(e, t) {
3788
+ function Fe(e, t) {
3771
3789
  if (e)
3772
3790
  for (const n of t) {
3773
3791
  const r = e[n];
@@ -3789,20 +3807,20 @@ function gt(e) {
3789
3807
  if (t)
3790
3808
  return Re(t.configurable) ?? t;
3791
3809
  }
3792
- async function Cr(e, t) {
3793
- var i, d;
3810
+ async function Mr(e, t) {
3811
+ var i, u;
3794
3812
  if (!e) return e ?? null;
3795
3813
  const n = le(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], o = /* @__PURE__ */ new Set();
3796
3814
  for (const c of r) {
3797
3815
  const l = (i = c == null ? void 0 : c.values) == null ? void 0 : i.messages;
3798
3816
  if (Array.isArray(l))
3799
- for (const f of l) {
3800
- const g = f == null ? void 0 : f.content;
3801
- if (Array.isArray(g))
3802
- for (const m of g) {
3803
- if (!m || typeof m != "object" || m.type !== "image_url" && m.type !== "file") continue;
3804
- const k = m.fileId || m.file_id;
3805
- typeof k == "string" && k.trim() && o.add(k);
3817
+ for (const d of l) {
3818
+ const m = d == null ? void 0 : d.content;
3819
+ if (Array.isArray(m))
3820
+ for (const y of m) {
3821
+ if (!y || typeof y != "object" || y.type !== "image_url" && y.type !== "file") continue;
3822
+ const I = y.fileId || y.file_id;
3823
+ typeof I == "string" && I.trim() && o.add(I);
3806
3824
  }
3807
3825
  }
3808
3826
  }
@@ -3811,32 +3829,32 @@ async function Cr(e, t) {
3811
3829
  const s = await Promise.all(
3812
3830
  Array.from(o).map(async (c) => {
3813
3831
  try {
3814
- const l = await t.getFileInfo(c), f = le(l);
3815
- return [c, f];
3832
+ const l = await t.getFileInfo(c), d = le(l);
3833
+ return [c, d];
3816
3834
  } catch {
3817
3835
  return [c, null];
3818
3836
  }
3819
3837
  })
3820
3838
  ), a = new Map(s);
3821
3839
  for (const c of r) {
3822
- const l = (d = c == null ? void 0 : c.values) == null ? void 0 : d.messages;
3840
+ const l = (u = c == null ? void 0 : c.values) == null ? void 0 : u.messages;
3823
3841
  if (Array.isArray(l))
3824
- for (const f of l) {
3825
- const g = f == null ? void 0 : f.content;
3826
- if (Array.isArray(g))
3827
- for (const m of g) {
3828
- if (!m || typeof m != "object" || m.type !== "image_url" && m.type !== "file") continue;
3829
- const k = m.fileId || m.file_id;
3830
- if (!k) continue;
3831
- const u = a.get(k), w = (u == null ? void 0 : u.contentUrl) || (u == null ? void 0 : u.content_url);
3832
- w && (m.type === "image_url" ? (m.imageUrl = m.imageUrl || {}, m.imageUrl.url = w) : m.type === "file" && (m.url = w, !m.name && (u != null && u.filename || u != null && u.name) && (m.name = (u == null ? void 0 : u.filename) || (u == null ? void 0 : u.name))));
3842
+ for (const d of l) {
3843
+ const m = d == null ? void 0 : d.content;
3844
+ if (Array.isArray(m))
3845
+ for (const y of m) {
3846
+ if (!y || typeof y != "object" || y.type !== "image_url" && y.type !== "file") continue;
3847
+ const I = y.fileId || y.file_id;
3848
+ if (!I) continue;
3849
+ const f = a.get(I), k = (f == null ? void 0 : f.contentUrl) || (f == null ? void 0 : f.content_url);
3850
+ k && (y.type === "image_url" ? (y.imageUrl = y.imageUrl || {}, y.imageUrl.url = k) : y.type === "file" && (y.url = k, !y.name && (f != null && f.filename || f != null && f.name) && (y.name = (f == null ? void 0 : f.filename) || (f == null ? void 0 : f.name))));
3833
3851
  }
3834
3852
  }
3835
3853
  }
3836
3854
  return n;
3837
3855
  }
3838
3856
  function mt(e) {
3839
- 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) => Mr(le(s), a)).filter((s) => !!s)].sort((s, a) => yt(a.createdAt) - yt(s.createdAt)), o = r[0] ?? null;
3857
+ 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) => Cr(le(s), a)).filter((s) => !!s)].sort((s, a) => yt(a.createdAt) - yt(s.createdAt)), o = r[0] ?? null;
3840
3858
  return {
3841
3859
  threadId: (e == null ? void 0 : e.threadId) ?? "",
3842
3860
  latest: o,
@@ -3844,34 +3862,34 @@ function mt(e) {
3844
3862
  interrupt: (o == null ? void 0 : o.interrupt) ?? null
3845
3863
  };
3846
3864
  }
3847
- function Mr(e, t) {
3848
- var v, b;
3865
+ function Cr(e, t) {
3866
+ var v, w;
3849
3867
  if (!e) return null;
3850
- const n = ((v = e.values) == null ? void 0 : v.activeAgent) ?? null, r = (b = e.values) == null ? void 0 : b.messages, s = (Array.isArray(r) ? r : []).map((A) => Er(A, n)).filter((A) => !!A), a = Re(e.metadata) ?? {}, i = gt(e.config), d = Re(e.parentConfig), c = gt(d), l = Oe(i, ["checkpointId"]), f = Oe(i, ["checkpointNs"]), g = Oe(c, ["checkpointId"]), m = Re(e.config), k = Array.isArray(e.tasks) ? e.tasks.map((A) => ({ ...A })) : e.tasks ?? null, u = Array.isArray(e.next) ? [...e.next] : e.next ?? null, w = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), I = {
3868
+ const n = ((v = e.values) == null ? void 0 : v.activeAgent) ?? null, r = (w = e.values) == null ? void 0 : w.messages, s = (Array.isArray(r) ? r : []).map((x) => Er(x, n)).filter((x) => !!x), a = Re(e.metadata) ?? {}, i = gt(e.config), u = Re(e.parentConfig), c = gt(u), l = Fe(i, ["checkpointId"]), d = Fe(i, ["checkpointNs"]), m = Fe(c, ["checkpointId"]), y = Re(e.config), I = Array.isArray(e.tasks) ? e.tasks.map((x) => ({ ...x })) : e.tasks ?? null, f = Array.isArray(e.next) ? [...e.next] : e.next ?? null, k = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), p = {
3851
3869
  ...a,
3852
3870
  step: Sr(a, ["step"]) ?? 0,
3853
- source: Oe(a, ["source"]) ?? null
3854
- }, C = s.map((A) => ({
3855
- ...A,
3856
- checkpointId: A.checkpointId ?? l ?? null,
3857
- checkpointNs: A.checkpointNs ?? f ?? null
3858
- })), x = e.values, E = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(x == null ? void 0 : x.interrupts) ? x.interrupts : [];
3871
+ source: Fe(a, ["source"]) ?? null
3872
+ }, S = s.map((x) => ({
3873
+ ...x,
3874
+ checkpointId: x.checkpointId ?? l ?? null,
3875
+ checkpointNs: x.checkpointNs ?? d ?? null
3876
+ })), A = e.values, E = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(A == null ? void 0 : A.interrupts) ? A.interrupts : [];
3859
3877
  return {
3860
3878
  checkpointId: l ?? null,
3861
- checkpointNs: f ?? null,
3862
- createdAt: w,
3863
- parentId: g ?? null,
3864
- messages: C,
3879
+ checkpointNs: d ?? null,
3880
+ createdAt: k,
3881
+ parentId: m ?? null,
3882
+ messages: S,
3865
3883
  interrupt: Pr(
3866
3884
  E,
3867
3885
  t,
3868
3886
  l ?? null
3869
3887
  ),
3870
- metadata: I,
3871
- config: m ?? null,
3872
- parentConfig: d ?? null,
3873
- next: u,
3874
- tasks: k,
3888
+ metadata: p,
3889
+ config: y ?? null,
3890
+ parentConfig: u ?? null,
3891
+ next: f,
3892
+ tasks: I,
3875
3893
  values: e.values ?? {}
3876
3894
  };
3877
3895
  }
@@ -3916,33 +3934,33 @@ function Nr(e) {
3916
3934
  function zr(e) {
3917
3935
  const t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Map(), o = [];
3918
3936
  for (let c = 0; c < e.length; c++) {
3919
- const l = e[c], f = l.checkpointId, g = f ?? `cp-${c}`, m = l.metadata ?? {}, k = typeof m.step == "number" ? m.step : null, u = typeof m.source == "string" ? m.source : null;
3920
- let w = null, I = null;
3921
- const C = Array.isArray(l.messages) ? l.messages : [];
3922
- for (const b of C)
3923
- b.role === "user" && (I || (I = b), b.id && (w = b.id));
3924
- const x = l.next && l.next.length > 0 ? String(l.next[0]) : null, E = l.parentConfig ?? null, v = {
3925
- id: g,
3926
- step: k,
3927
- source: u,
3937
+ const l = e[c], d = l.checkpointId, m = d ?? `cp-${c}`, y = l.metadata ?? {}, I = typeof y.step == "number" ? y.step : null, f = typeof y.source == "string" ? y.source : null;
3938
+ let k = null, p = null;
3939
+ const S = Array.isArray(l.messages) ? l.messages : [];
3940
+ for (const w of S)
3941
+ w.role === "user" && (p || (p = w), w.id && (k = w.id));
3942
+ const A = l.next && l.next.length > 0 ? String(l.next[0]) : null, E = l.parentConfig ?? null, v = {
3943
+ id: m,
3944
+ step: I,
3945
+ source: f,
3928
3946
  createdAt: l.createdAt ?? null,
3929
3947
  namespace: l.checkpointNs ?? null,
3930
3948
  parentId: l.parentId ?? null,
3931
- next: x,
3949
+ next: A,
3932
3950
  parentConfig: E,
3933
- userMessageId: w
3951
+ userMessageId: k
3934
3952
  };
3935
- if (o.push(v), f && t.set(f, v), f && I) {
3936
- const b = Nr(I);
3937
- b && r.set(f, b);
3953
+ if (o.push(v), d && t.set(d, v), d && p) {
3954
+ const w = Nr(p);
3955
+ w && r.set(d, w);
3938
3956
  }
3939
3957
  n.push({
3940
- id: g,
3941
- messageId: w,
3942
- step: k,
3943
- source: u,
3958
+ id: m,
3959
+ messageId: k,
3960
+ step: I,
3961
+ source: f,
3944
3962
  createdAt: l.createdAt ?? null,
3945
- next: x,
3963
+ next: A,
3946
3964
  parentConfig: E
3947
3965
  });
3948
3966
  }
@@ -3954,14 +3972,14 @@ function zr(e) {
3954
3972
  }
3955
3973
  for (const c of s.values()) {
3956
3974
  if (!c.length) continue;
3957
- c.sort((f, g) => {
3958
- const m = f.createdAt ? Date.parse(f.createdAt) : 0;
3959
- return (g.createdAt ? Date.parse(g.createdAt) : 0) - m;
3975
+ c.sort((d, m) => {
3976
+ const y = d.createdAt ? Date.parse(d.createdAt) : 0;
3977
+ return (m.createdAt ? Date.parse(m.createdAt) : 0) - y;
3960
3978
  });
3961
3979
  const l = c.length;
3962
- for (let f = 0; f < c.length; f++) {
3963
- const g = c[f];
3964
- g.attemptCount = l, g.attemptIndex = f, g.isLatestAttempt = f === 0;
3980
+ for (let d = 0; d < c.length; d++) {
3981
+ const m = c[d];
3982
+ m.attemptCount = l, m.attemptIndex = d, m.isLatestAttempt = d === 0;
3965
3983
  }
3966
3984
  }
3967
3985
  return {
@@ -3977,11 +3995,11 @@ function zr(e) {
3977
3995
  getCheckpoint: (c) => t.get(c),
3978
3996
  getMessageAttempts: (c) => {
3979
3997
  const l = [];
3980
- for (const f of t.values())
3981
- f.userMessageId === c && l.push(f);
3982
- return l.length ? (l.sort((f, g) => {
3983
- const m = typeof f.attemptIndex == "number" ? f.attemptIndex : Number.MAX_SAFE_INTEGER, k = typeof g.attemptIndex == "number" ? g.attemptIndex : Number.MAX_SAFE_INTEGER;
3984
- return m - k;
3998
+ for (const d of t.values())
3999
+ d.userMessageId === c && l.push(d);
4000
+ return l.length ? (l.sort((d, m) => {
4001
+ const y = typeof d.attemptIndex == "number" ? d.attemptIndex : Number.MAX_SAFE_INTEGER, I = typeof m.attemptIndex == "number" ? m.attemptIndex : Number.MAX_SAFE_INTEGER;
4002
+ return y - I;
3985
4003
  }), l) : [];
3986
4004
  }
3987
4005
  };
@@ -4016,43 +4034,43 @@ function $t({
4016
4034
  isStreaming: a,
4017
4035
  getMessages: i
4018
4036
  }) {
4019
- const [d, c] = B(null), f = Y(
4020
- () => mt(d),
4021
- [d]
4022
- ).checkpoints, g = Rr(f), m = g.timeline, [k, u] = B(!1), [w, I] = B(!1), [C, x] = B(!1), [E, v] = B(null), b = W(o), A = W(null), p = W(null);
4037
+ const [u, c] = $(null), d = Y(
4038
+ () => mt(u),
4039
+ [u]
4040
+ ).checkpoints, m = Rr(d), y = m.timeline, [I, f] = $(!1), [k, p] = $(!1), [S, A] = $(!1), [E, v] = $(null), w = W(o), x = W(null), g = W(null);
4023
4041
  X(() => {
4024
- b.current = o;
4042
+ w.current = o;
4025
4043
  }, [o]);
4026
- const h = _(
4027
- async (M) => {
4028
- const F = await e.getState({
4029
- threadId: M.threadId,
4030
- checkpointId: M.checkpointId,
4031
- checkpointNs: M.checkpointNs
4044
+ const b = _(
4045
+ async (C) => {
4046
+ const B = await e.getState({
4047
+ threadId: C.threadId,
4048
+ checkpointId: C.checkpointId,
4049
+ checkpointNs: C.checkpointNs
4032
4050
  }), N = {
4033
4051
  version: "values@1",
4034
- threadId: M.threadId,
4035
- checkpoints: [F]
4036
- }, V = t ? await Cr(N, t) : N, { latest: z } = mt(V);
4052
+ threadId: C.threadId,
4053
+ checkpoints: [B]
4054
+ }, V = t ? await Mr(N, t) : N, { latest: z } = mt(V);
4037
4055
  return z;
4038
4056
  },
4039
4057
  [e, t]
4040
4058
  ), P = _(
4041
- async (M, F) => {
4059
+ async (C, B) => {
4042
4060
  var z;
4043
- if (!M) return;
4044
- const N = `${M}:${F ?? "latest"}`;
4045
- if (A.current === N || k) return;
4046
- (z = p.current) == null || z.abort();
4061
+ if (!C) return;
4062
+ const N = `${C}:${B ?? "latest"}`;
4063
+ if (x.current === N || I) return;
4064
+ (z = g.current) == null || z.abort();
4047
4065
  const V = new AbortController();
4048
- p.current = V, u(!0), v(null);
4066
+ g.current = V, f(!0), v(null);
4049
4067
  try {
4050
- const L = await h({
4051
- threadId: M,
4052
- checkpointId: F ?? void 0
4068
+ const L = await b({
4069
+ threadId: C,
4070
+ checkpointId: B ?? void 0
4053
4071
  });
4054
- if (b.current !== M) {
4055
- u(!1);
4072
+ if (w.current !== C) {
4073
+ f(!1);
4056
4074
  return;
4057
4075
  }
4058
4076
  n((L == null ? void 0 : L.messages) ?? [], {
@@ -4060,59 +4078,59 @@ function $t({
4060
4078
  checkpointNs: (L == null ? void 0 : L.checkpointNs) ?? null,
4061
4079
  pendingInterrupt: (L == null ? void 0 : L.interrupt) ?? null,
4062
4080
  values: L == null ? void 0 : L.values
4063
- }), A.current = N, u(!1), x(!0);
4081
+ }), x.current = N, f(!1), A(!0);
4064
4082
  try {
4065
- const K = await e.getStateHistory({
4066
- threadId: M,
4083
+ const H = await e.getStateHistory({
4084
+ threadId: C,
4067
4085
  limit: 100,
4068
4086
  includeMessages: !1
4069
4087
  });
4070
- b.current === M && c(K);
4088
+ w.current === C && c(H);
4071
4089
  } finally {
4072
- x(!1);
4090
+ A(!1);
4073
4091
  }
4074
4092
  } catch (L) {
4075
- if (u(!1), !Xt(L)) {
4076
- const K = String(L);
4077
- v(K), r == null || r(K);
4093
+ if (f(!1), !Xt(L)) {
4094
+ const H = String(L);
4095
+ v(H), r == null || r(H);
4078
4096
  }
4079
4097
  }
4080
4098
  },
4081
- [e, n, h, r, i]
4099
+ [e, n, b, r, i]
4082
4100
  ), j = _(
4083
- async (M, F) => {
4101
+ async (C, B) => {
4084
4102
  if (o) {
4085
- I(!0);
4103
+ p(!0);
4086
4104
  try {
4087
- const N = await h({
4105
+ const N = await b({
4088
4106
  threadId: o,
4089
- checkpointId: M,
4090
- checkpointNs: F ?? void 0
4107
+ checkpointId: C,
4108
+ checkpointNs: B ?? void 0
4091
4109
  });
4092
4110
  n((N == null ? void 0 : N.messages) ?? [], {
4093
- checkpointId: (N == null ? void 0 : N.checkpointId) ?? M,
4094
- checkpointNs: (N == null ? void 0 : N.checkpointNs) ?? F,
4111
+ checkpointId: (N == null ? void 0 : N.checkpointId) ?? C,
4112
+ checkpointNs: (N == null ? void 0 : N.checkpointNs) ?? B,
4095
4113
  pendingInterrupt: (N == null ? void 0 : N.interrupt) ?? null,
4096
4114
  values: N == null ? void 0 : N.values
4097
4115
  });
4098
4116
  } catch (N) {
4099
4117
  console.error("[useThreadHistoryState] Navigation failed", N);
4100
4118
  } finally {
4101
- I(!1);
4119
+ p(!1);
4102
4120
  }
4103
4121
  }
4104
4122
  },
4105
- [o, h, n]
4106
- ), S = _(async () => {
4123
+ [o, b, n]
4124
+ ), M = _(async () => {
4107
4125
  o && await P(o);
4108
4126
  }, [o, P]), O = _(
4109
- async (M) => {
4127
+ async (C) => {
4110
4128
  var V;
4111
- const F = (M == null ? void 0 : M.threadId) || o;
4112
- if (!F || o !== F) return;
4113
- if (c(M), A.current = `${F}:latest`, (V = M.values) != null && V.messages) {
4114
- const z = await h({
4115
- threadId: F
4129
+ const B = (C == null ? void 0 : C.threadId) || o;
4130
+ if (!B || o !== B) return;
4131
+ if (c(C), x.current = `${B}:latest`, (V = C.values) != null && V.messages) {
4132
+ const z = await b({
4133
+ threadId: B
4116
4134
  });
4117
4135
  z && n(z.messages ?? [], {
4118
4136
  checkpointId: z.checkpointId ?? null,
@@ -4122,41 +4140,41 @@ function $t({
4122
4140
  });
4123
4141
  }
4124
4142
  },
4125
- [o, h, n]
4143
+ [o, b, n]
4126
4144
  );
4127
4145
  X(() => {
4128
- if (!s || !o || k || a) return;
4129
- const M = `${o}:latest`;
4130
- A.current !== M && P(o);
4131
- }, [s, o, k, a, P]);
4132
- const $ = _(() => {
4133
- c(null), u(!1), I(!1), x(!1), v(null), A.current = null;
4146
+ if (!s || !o || I || a) return;
4147
+ const C = `${o}:latest`;
4148
+ x.current !== C && P(o);
4149
+ }, [s, o, I, a, P]);
4150
+ const F = _(() => {
4151
+ c(null), f(!1), p(!1), A(!1), v(null), x.current = null;
4134
4152
  }, []);
4135
4153
  return {
4136
- threadCheckpoints: f,
4137
- threadTimeline: m,
4138
- checkpointIndex: g,
4139
- isLoadingThread: k,
4140
- isLoadingCheckpoint: w,
4141
- isLoadingHistory: C,
4154
+ threadCheckpoints: d,
4155
+ threadTimeline: y,
4156
+ checkpointIndex: m,
4157
+ isLoadingThread: I,
4158
+ isLoadingCheckpoint: k,
4159
+ isLoadingHistory: S,
4142
4160
  threadStateError: E,
4143
4161
  loadThread: P,
4144
4162
  navigateToCheckpoint: j,
4145
- setCurrentCheckpointId: (M, F) => {
4146
- n(i(), { checkpointId: M, checkpointNs: F });
4163
+ setCurrentCheckpointId: (C, B) => {
4164
+ n(i(), { checkpointId: C, checkpointNs: B });
4147
4165
  },
4148
- returnToLatest: S,
4166
+ returnToLatest: M,
4149
4167
  handleValuesEvent: O,
4150
4168
  markSkipNextLoad: () => {
4151
4169
  },
4152
4170
  markStreamPendingThread: () => {
4153
4171
  },
4154
- resetHistoryState: $,
4155
- clearState: $
4172
+ resetHistoryState: F,
4173
+ clearState: F
4156
4174
  };
4157
4175
  }
4158
- const Dt = Me(null), Vt = Me(null);
4159
- function qt(e) {
4176
+ const Dt = Ce(null), Vt = Ce(null);
4177
+ function Kt(e) {
4160
4178
  const t = Ue(Dt);
4161
4179
  if (!t && !(e != null && e.optional)) throw new Error("useThreadState must be used within a ThreadStateProvider");
4162
4180
  return t;
@@ -4176,26 +4194,26 @@ function Ur({
4176
4194
  isStreaming: s,
4177
4195
  onError: a
4178
4196
  }) {
4179
- const { chatApi: i, fileApi: d } = Ce(), { currentThreadId: c } = ot(), { state: l, seed: f, onEvent: g, dispatch: m } = vr(), {
4180
- threadCheckpoints: k,
4181
- threadTimeline: u,
4182
- checkpointIndex: w,
4183
- isLoadingThread: I,
4184
- isLoadingCheckpoint: C,
4185
- isLoadingHistory: x,
4197
+ const { chatApi: i, fileApi: u } = Me(), { currentThreadId: c } = ot(), { state: l, seed: d, onEvent: m, dispatch: y } = kr(), {
4198
+ threadCheckpoints: I,
4199
+ threadTimeline: f,
4200
+ checkpointIndex: k,
4201
+ isLoadingThread: p,
4202
+ isLoadingCheckpoint: S,
4203
+ isLoadingHistory: A,
4186
4204
  threadStateError: E,
4187
4205
  loadThread: v,
4188
- navigateToCheckpoint: b,
4189
- setCurrentCheckpointId: A,
4190
- returnToLatest: p,
4191
- handleValuesEvent: h,
4206
+ navigateToCheckpoint: w,
4207
+ setCurrentCheckpointId: x,
4208
+ returnToLatest: g,
4209
+ handleValuesEvent: b,
4192
4210
  markSkipNextLoad: P,
4193
4211
  markStreamPendingThread: j,
4194
- resetHistoryState: S
4212
+ resetHistoryState: M
4195
4213
  } = $t({
4196
4214
  api: i,
4197
- fileApi: d,
4198
- seed: f,
4215
+ fileApi: u,
4216
+ seed: d,
4199
4217
  onError: a,
4200
4218
  currentThreadId: c,
4201
4219
  initialThreadId: t,
@@ -4204,33 +4222,33 @@ function Ur({
4204
4222
  autoLoadInitial: o,
4205
4223
  isStreaming: s,
4206
4224
  getMessages: _(() => l.messages, [l.messages])
4207
- }), O = W(null), $ = _(
4225
+ }), O = W(null), F = _(
4208
4226
  (T) => {
4209
4227
  O.current = T;
4210
4228
  },
4211
4229
  []
4212
- ), M = W(null), F = _(
4230
+ ), C = W(null), B = _(
4213
4231
  (T) => {
4214
- M.current = T;
4232
+ C.current = T;
4215
4233
  },
4216
4234
  []
4217
4235
  ), N = Y(() => ({ assemblingMessageId: l.assemblingId ?? null }), [l.assemblingId]), V = _(
4218
4236
  (T, J) => {
4219
- const q = Ut(T, "user");
4220
- return m({
4237
+ const K = Ut(T, "user");
4238
+ return y({
4221
4239
  type: "user_message",
4222
4240
  payload: {
4223
- message: q,
4241
+ message: K,
4224
4242
  editingMessageId: J == null ? void 0 : J.editingMessageId
4225
4243
  }
4226
- }), q;
4244
+ }), K;
4227
4245
  },
4228
- [m]
4246
+ [y]
4229
4247
  ), z = _(async () => {
4230
- O.current ? await O.current() : (f([], {}), S());
4231
- }, [f, S]), L = _(async (T, J, q) => {
4248
+ O.current ? await O.current() : (d([], {}), M());
4249
+ }, [d, M]), L = _(async (T, J, K) => {
4232
4250
  await v(T, J, { clearProgress: !1 });
4233
- }, [v]), K = Y(() => Fn(l.messages), [l.messages]), y = Y(
4251
+ }, [v]), H = Y(() => Bn(l.messages), [l.messages]), h = Y(
4234
4252
  () => ({
4235
4253
  status: l.status,
4236
4254
  threadId: c,
@@ -4241,20 +4259,20 @@ function Ur({
4241
4259
  id: l.lastCheckpointId ?? null,
4242
4260
  namespace: l.lastCheckpointNs ?? null
4243
4261
  },
4244
- checkpoints: k,
4245
- checkpointIndex: w,
4246
- timelineCheckpoints: u,
4262
+ checkpoints: I,
4263
+ checkpointIndex: k,
4264
+ timelineCheckpoints: f,
4247
4265
  metadata: N,
4248
4266
  values: l.values ?? {},
4249
- isLoading: I,
4250
- isLoadingCheckpoint: C,
4251
- isLoadingHistory: x,
4267
+ isLoading: p,
4268
+ isLoadingCheckpoint: S,
4269
+ isLoadingHistory: A,
4252
4270
  error: E,
4253
4271
  loadOlder: async () => {
4254
4272
  },
4255
4273
  // Placeholder
4256
4274
  seedFromSnapshot: (T) => {
4257
- f(T.messages, {
4275
+ d(T.messages, {
4258
4276
  checkpointId: T.checkpointId,
4259
4277
  checkpointNs: T.checkpointNs,
4260
4278
  pendingInterrupt: T.interrupt,
@@ -4262,22 +4280,22 @@ function Ur({
4262
4280
  });
4263
4281
  },
4264
4282
  clearState: z,
4265
- navigateToCheckpoint: b,
4266
- setCurrentCheckpointId: A,
4267
- returnToLatest: p,
4283
+ navigateToCheckpoint: w,
4284
+ setCurrentCheckpointId: x,
4285
+ returnToLatest: g,
4268
4286
  loadThread: L,
4269
4287
  clearThread: z,
4270
- respondToInterrupt: async (T, J, q) => {
4271
- M.current && await M.current(T, J, q);
4288
+ respondToInterrupt: async (T, J, K) => {
4289
+ C.current && await C.current(T, J, K);
4272
4290
  },
4273
- messagePreviews: w.messagePreviews,
4274
- handleValuesEvent: h,
4291
+ messagePreviews: k.messagePreviews,
4292
+ handleValuesEvent: b,
4275
4293
  markSkipNextLoad: P,
4276
4294
  markStreamPendingThread: j,
4277
- resetHistoryState: S,
4295
+ resetHistoryState: M,
4278
4296
  pushUser: V,
4279
- onEvent: g,
4280
- artifacts: K
4297
+ onEvent: m,
4298
+ artifacts: H
4281
4299
  }),
4282
4300
  [
4283
4301
  c,
@@ -4287,38 +4305,38 @@ function Ur({
4287
4305
  l.lastCheckpointId,
4288
4306
  l.lastCheckpointNs,
4289
4307
  l.values,
4308
+ I,
4309
+ f,
4290
4310
  k,
4291
- u,
4292
- w,
4293
4311
  N,
4294
- I,
4295
- C,
4296
- x,
4312
+ p,
4313
+ S,
4314
+ A,
4297
4315
  E,
4298
- f,
4316
+ d,
4299
4317
  z,
4300
- b,
4301
- A,
4302
- p,
4318
+ w,
4319
+ x,
4320
+ g,
4303
4321
  L,
4304
- h,
4322
+ b,
4305
4323
  P,
4306
4324
  j,
4307
4325
  V,
4308
- g,
4309
- K
4326
+ m,
4327
+ H
4310
4328
  ]
4311
4329
  ), U = Y(
4312
4330
  () => ({
4313
- registerClearThread: $,
4314
- registerRespondToInterrupt: F
4331
+ registerClearThread: F,
4332
+ registerRespondToInterrupt: B
4315
4333
  }),
4316
- [$, F]
4334
+ [F, B]
4317
4335
  );
4318
- return /* @__PURE__ */ ie(Vt.Provider, { value: U, children: /* @__PURE__ */ ie(Dt.Provider, { value: y, children: e }) });
4336
+ return /* @__PURE__ */ ie(Vt.Provider, { value: U, children: /* @__PURE__ */ ie(Dt.Provider, { value: h, children: e }) });
4319
4337
  }
4320
- const Ht = Me(null), jr = Me(!1);
4321
- function Fr({
4338
+ const qt = Ce(null), jr = Ce(!1);
4339
+ function Br({
4322
4340
  children: e,
4323
4341
  onError: t,
4324
4342
  onAuthError: n,
@@ -4327,71 +4345,71 @@ function Fr({
4327
4345
  onUpdateEvent: s,
4328
4346
  onCustomEvent: a,
4329
4347
  onMetadataEvent: i,
4330
- onFinish: d,
4348
+ onFinish: u,
4331
4349
  onStreamingChange: c
4332
4350
  }) {
4333
- const { chatApi: l, baseUrl: f } = Ce(), g = f, m = fe(t), k = fe(n), u = fe(r), w = fe(o), I = fe(s), C = fe(a), x = fe(i), E = fe(d), v = fe(c), b = Y(
4351
+ const { chatApi: l, baseUrl: d } = Me(), m = d, y = fe(t), I = fe(n), f = fe(r), k = fe(o), p = fe(s), S = fe(a), A = fe(i), E = fe(u), v = fe(c), w = Y(
4334
4352
  () => ({
4335
- onError: m,
4336
- onAuthError: k,
4337
- onConnectionError: u,
4338
- onMetadataEvent: x,
4339
- onCustomEvent: C,
4340
- onUpdateEvent: I,
4341
- onToolEnd: w,
4353
+ onError: y,
4354
+ onAuthError: I,
4355
+ onConnectionError: f,
4356
+ onMetadataEvent: A,
4357
+ onCustomEvent: S,
4358
+ onUpdateEvent: p,
4359
+ onToolEnd: k,
4342
4360
  onFinish: E
4343
4361
  }),
4344
4362
  [
4345
- m,
4346
- k,
4347
- u,
4348
- x,
4349
- C,
4363
+ y,
4350
4364
  I,
4351
- w,
4365
+ f,
4366
+ A,
4367
+ S,
4368
+ p,
4369
+ k,
4352
4370
  E
4353
4371
  ]
4354
4372
  );
4355
4373
  return /* @__PURE__ */ ie(jr.Provider, { value: !0, children: /* @__PURE__ */ ie(
4356
- Or,
4374
+ Fr,
4357
4375
  {
4358
4376
  api: l,
4359
- streamBaseUrl: g,
4360
- handlers: b,
4377
+ streamBaseUrl: m,
4378
+ handlers: w,
4361
4379
  onStreamingChange: v,
4362
4380
  children: e
4363
4381
  }
4364
4382
  ) });
4365
4383
  }
4366
- function Or({
4384
+ function Fr({
4367
4385
  children: e,
4368
4386
  api: t,
4369
4387
  streamBaseUrl: n,
4370
4388
  handlers: r,
4371
4389
  onStreamingChange: o
4372
4390
  }) {
4373
- const { setCurrentThreadId: s, currentThreadIdRef: a, addThreadFromEvent: i, currentThreadId: d } = ot(), {
4391
+ const { setCurrentThreadId: s, currentThreadIdRef: a, addThreadFromEvent: i, currentThreadId: u } = ot(), {
4374
4392
  interrupt: c,
4375
4393
  checkpoint: l,
4376
- timelineCheckpoints: f,
4377
- handleValuesEvent: g,
4378
- markSkipNextLoad: m,
4379
- markStreamPendingThread: k,
4380
- resetHistoryState: u,
4381
- pushUser: w,
4382
- onEvent: I,
4383
- messages: C
4384
- } = qt(), { registerClearThread: x, registerRespondToInterrupt: E } = Lr(), v = _(
4385
- (y) => {
4386
- i(y), k(y.threadId), a.current !== y.threadId && ((y.created ?? !a.current) && m(y.threadId), s(y.threadId));
4394
+ timelineCheckpoints: d,
4395
+ handleValuesEvent: m,
4396
+ markSkipNextLoad: y,
4397
+ markStreamPendingThread: I,
4398
+ resetHistoryState: f,
4399
+ pushUser: k,
4400
+ onEvent: p,
4401
+ messages: S
4402
+ } = Kt(), { registerClearThread: A, registerRespondToInterrupt: E } = Lr(), v = _(
4403
+ (h) => {
4404
+ i(h), I(h.threadId), a.current !== h.threadId && ((h.created ?? !a.current) && y(h.threadId), s(h.threadId));
4387
4405
  },
4388
- [i, m, k, s, a]
4389
- ), b = pr({
4406
+ [i, y, I, s, a]
4407
+ ), w = pr({
4390
4408
  baseUrl: n,
4391
- onEvent: I,
4392
- onError: (y) => {
4409
+ onEvent: p,
4410
+ onError: (h) => {
4393
4411
  var U;
4394
- (U = r.onError) == null || U.call(r, (y == null ? void 0 : y.message) ?? String(y));
4412
+ (U = r.onError) == null || U.call(r, (h == null ? void 0 : h.message) ?? String(h));
4395
4413
  },
4396
4414
  onAuthError: r.onAuthError,
4397
4415
  onConnectionError: r.onConnectionError,
@@ -4401,122 +4419,122 @@ function Or({
4401
4419
  onCustomEvent: r.onCustomEvent,
4402
4420
  onUpdateEvent: r.onUpdateEvent,
4403
4421
  onToolEnd: r.onToolEnd,
4404
- handleValuesEvent: g
4422
+ handleValuesEvent: m
4405
4423
  });
4406
4424
  X(() => {
4407
- o == null || o(b.isStreaming);
4408
- }, [b.isStreaming, o]);
4409
- const { stream: A, stop: p, clear: h, isStreaming: P, error: j, connected: S, streamedMessages: O, activeMessageId: $ } = b;
4425
+ o == null || o(w.isStreaming);
4426
+ }, [w.isStreaming, o]);
4427
+ const { stream: x, stop: g, clear: b, isStreaming: P, error: j, connected: M, streamedMessages: O, activeMessageId: F } = w;
4410
4428
  X(() => {
4411
- d !== void 0 && h();
4412
- }, [d, h]);
4413
- const M = _(
4414
- async (y, U) => {
4415
- await A(y, U);
4429
+ u !== void 0 && b();
4430
+ }, [u, b]);
4431
+ const C = _(
4432
+ async (h, U) => {
4433
+ await x(h, U);
4416
4434
  },
4417
- [A]
4418
- ), F = W(l);
4435
+ [x]
4436
+ ), B = W(l);
4419
4437
  X(() => {
4420
- F.current = l;
4438
+ B.current = l;
4421
4439
  }, [l]);
4422
4440
  const N = _(
4423
- async (y, U, T) => {
4441
+ async (h, U, T) => {
4424
4442
  var G;
4425
4443
  const J = a.current;
4426
4444
  if (!J)
4427
4445
  throw new Error("No active thread to handle interrupt");
4428
- const q = y ? U ?? !0 : !1, H = F.current, ee = (T == null ? void 0 : T.checkpointId) ?? H.id ?? void 0, re = (T == null ? void 0 : T.checkpointNs) ?? H.namespace ?? void 0, ue = {
4446
+ const K = h ? U ?? !0 : !1, q = B.current, ee = (T == null ? void 0 : T.checkpointId) ?? q.id ?? void 0, re = (T == null ? void 0 : T.checkpointNs) ?? q.namespace ?? void 0, ue = {
4429
4447
  threadId: J,
4430
4448
  checkpointId: ee,
4431
4449
  checkpointNs: re,
4432
- command: { kind: "resume", value: q },
4450
+ command: { kind: "resume", value: K },
4433
4451
  payload: {
4434
4452
  ...(T == null ? void 0 : T.payload) ?? {},
4435
4453
  creativityLevel: ((G = T == null ? void 0 : T.payload) == null ? void 0 : G.creativityLevel) ?? "medium"
4436
4454
  },
4437
4455
  edit: !1
4438
4456
  };
4439
- M(ue);
4457
+ C(ue);
4440
4458
  },
4441
- [a, M]
4459
+ [a, C]
4442
4460
  );
4443
4461
  X(() => {
4444
4462
  E(N);
4445
4463
  }, [N, E]);
4446
4464
  const V = _(async () => {
4447
- p(), h(), u(), s(null);
4448
- }, [h, u, s, p]);
4465
+ g(), b(), f(), s(null);
4466
+ }, [b, f, s, g]);
4449
4467
  X(() => {
4450
- x(V);
4451
- }, [V, x]);
4468
+ A(V);
4469
+ }, [V, A]);
4452
4470
  const z = _(
4453
- async (y, U) => {
4454
- P && p();
4471
+ async (h, U) => {
4472
+ P && g();
4455
4473
  let T = a.current;
4456
- const J = (y == null ? void 0 : y.text) ?? "", q = (y == null ? void 0 : y.attachments) ?? [], H = (J == null ? void 0 : J.trim()) ?? "", ee = { ...(y == null ? void 0 : y.payload) ?? {} }, re = Array.isArray(ee.messages) ? ee.messages : void 0;
4474
+ const J = (h == null ? void 0 : h.text) ?? "", K = (h == null ? void 0 : h.attachments) ?? [], q = (J == null ? void 0 : J.trim()) ?? "", ee = { ...(h == null ? void 0 : h.payload) ?? {} }, re = Array.isArray(ee.messages) ? ee.messages : void 0;
4457
4475
  re && delete ee.messages;
4458
- const ue = !!(re && re.length), G = !!(y.contentParts && y.contentParts.length > 0);
4459
- if (!T && !H && q.length === 0 && !ue && !G) return;
4476
+ const ue = !!(re && re.length), G = !!(h.contentParts && h.contentParts.length > 0);
4477
+ if (!T && !q && K.length === 0 && !ue && !G) return;
4460
4478
  if (!T) {
4461
4479
  const ye = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), he = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4462
- T = `${ye}${he}`, m(T), s(T);
4480
+ T = `${ye}${he}`, y(T), s(T);
4463
4481
  }
4464
4482
  let te = null;
4465
- y.contentParts && y.contentParts.length > 0 && (te = y.contentParts);
4466
- const { contentParts: ve, filesInfo: Q } = te ? { contentParts: te, filesInfo: [] } : await or(q), Z = [...ve];
4467
- H && Z.push({ type: "text", text: J });
4468
- const ge = y == null ? void 0 : y.originalMessageId, je = !!(y != null && y.edit && ge), Fe = !ue && Z.length > 0;
4483
+ h.contentParts && h.contentParts.length > 0 && (te = h.contentParts);
4484
+ const { contentParts: ke, filesInfo: Q } = te ? { contentParts: te, filesInfo: [] } : await or(K), Z = [...ke];
4485
+ q && Z.push({ type: "text", text: J });
4486
+ const ge = h == null ? void 0 : h.originalMessageId, je = !!(h != null && h.edit && ge), Be = !ue && Z.length > 0;
4469
4487
  let me = null;
4470
- if (Fe) {
4488
+ if (Be) {
4471
4489
  const ye = je ? ge : `msg-${Date.now()}`;
4472
4490
  me = Ut({
4473
4491
  id: ye,
4474
4492
  role: "user",
4475
4493
  content: Z,
4476
4494
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4477
- }, "user"), je ? w(me, { editingMessageId: ge }) : w(me);
4495
+ }, "user"), je ? k(me, { editingMessageId: ge }) : k(me);
4478
4496
  }
4479
4497
  const Ie = ue ? re : me ? [me] : [], oe = {
4480
4498
  ...ee,
4481
4499
  ...Q.length ? { files_info: Q } : {}
4482
4500
  };
4483
4501
  Ie.length ? oe.messages = Ie : "messages" in oe || (oe.messages = []);
4484
- const Pe = (y == null ? void 0 : y.checkpointId) ?? l.id ?? void 0;
4485
- if (y != null && y.edit && !Pe)
4502
+ const Pe = (h == null ? void 0 : h.checkpointId) ?? l.id ?? void 0;
4503
+ if (h != null && h.edit && !Pe)
4486
4504
  throw new Error(
4487
4505
  `[streaming] Missing checkpointId for edit submit. threadId=${T ?? "null"}`
4488
4506
  );
4489
- const xe = {
4507
+ const Ae = {
4490
4508
  threadId: T,
4491
- content: y == null ? void 0 : y.text,
4509
+ content: h == null ? void 0 : h.text,
4492
4510
  payload: oe,
4493
- config: y == null ? void 0 : y.config,
4511
+ config: h == null ? void 0 : h.config,
4494
4512
  checkpointId: Pe,
4495
- command: y == null ? void 0 : y.command,
4496
- edit: y == null ? void 0 : y.edit
4513
+ command: h == null ? void 0 : h.command,
4514
+ edit: h == null ? void 0 : h.edit
4497
4515
  };
4498
- return M(xe, U);
4516
+ return C(Ae, U);
4499
4517
  },
4500
- [l, a, P, m, w, M, p, f]
4501
- ), L = Y(() => C, [C]), K = Y(
4518
+ [l, a, P, y, k, C, g, d]
4519
+ ), L = Y(() => S, [S]), H = Y(
4502
4520
  () => ({
4503
4521
  isStreaming: P,
4504
4522
  error: j,
4505
- connectionState: j ? "error" : P ? S ? "connected" : "connecting" : "idle",
4523
+ connectionState: j ? "error" : P ? M ? "connected" : "connecting" : "idle",
4506
4524
  messages: L,
4507
- activeMessageId: $,
4525
+ activeMessageId: F,
4508
4526
  submit: z,
4509
- stop: p,
4527
+ stop: g,
4510
4528
  interrupt: c,
4511
4529
  resume: () => Promise.resolve(),
4512
- goto: (y, U) => Promise.resolve(),
4530
+ goto: (h, U) => Promise.resolve(),
4513
4531
  clearError: () => {
4514
4532
  }
4515
4533
  // TODO: Implement error clearing
4516
4534
  }),
4517
- [P, j, z, p, c, S, L]
4535
+ [P, j, z, g, c, M, L]
4518
4536
  );
4519
- return /* @__PURE__ */ ie(Ht.Provider, { value: K, children: e });
4537
+ return /* @__PURE__ */ ie(qt.Provider, { value: H, children: e });
4520
4538
  }
4521
4539
  function fe(e) {
4522
4540
  const t = W(e);
@@ -4528,8 +4546,8 @@ function fe(e) {
4528
4546
  return r(...n);
4529
4547
  }, []);
4530
4548
  }
4531
- function Br(e) {
4532
- return Ue(Ht);
4549
+ function Or(e) {
4550
+ return Ue(qt);
4533
4551
  }
4534
4552
  function bt(e) {
4535
4553
  return typeof e == "object" && e !== null;
@@ -4569,41 +4587,41 @@ function po({
4569
4587
  autoLoadInitial: s = !0,
4570
4588
  onConnectionError: a,
4571
4589
  onError: i,
4572
- onAuthError: d,
4590
+ onAuthError: u,
4573
4591
  onThreadChange: c,
4574
4592
  onToolEnd: l,
4575
- onUpdateEvent: f,
4576
- onCustomEvent: g,
4577
- onMetadataEvent: m,
4578
- onFinish: k
4593
+ onUpdateEvent: d,
4594
+ onCustomEvent: m,
4595
+ onMetadataEvent: y,
4596
+ onFinish: I
4579
4597
  }) {
4580
- const u = Dr(t), [w, I] = B(!1), C = pe(i), x = pe(d), E = pe(a), v = pe(c), b = pe(l), A = pe(f), p = pe(g), h = pe(m), P = pe(k), j = Y(
4598
+ const f = Dr(t), [k, p] = $(!1), S = pe(i), A = pe(u), E = pe(a), v = pe(c), w = pe(l), x = pe(d), g = pe(m), b = pe(y), P = pe(I), j = Y(
4581
4599
  () => ({
4582
- onError: C,
4583
- onAuthError: x,
4600
+ onError: S,
4601
+ onAuthError: A,
4584
4602
  onConnectionError: E,
4585
- onToolEnd: b,
4586
- onUpdateEvent: A,
4587
- onCustomEvent: p,
4588
- onMetadataEvent: h,
4603
+ onToolEnd: w,
4604
+ onUpdateEvent: x,
4605
+ onCustomEvent: g,
4606
+ onMetadataEvent: b,
4589
4607
  onFinish: P
4590
4608
  }),
4591
4609
  [
4592
- C,
4593
- x,
4610
+ S,
4611
+ A,
4594
4612
  E,
4613
+ w,
4614
+ x,
4615
+ g,
4595
4616
  b,
4596
- A,
4597
- p,
4598
- h,
4599
4617
  P
4600
4618
  ]
4601
4619
  );
4602
- return /* @__PURE__ */ ie(nr, { apiConfig: u, children: /* @__PURE__ */ ie(
4620
+ return /* @__PURE__ */ ie(nr, { apiConfig: f, children: /* @__PURE__ */ ie(
4603
4621
  mr,
4604
4622
  {
4605
4623
  initialThreadId: n,
4606
- onError: C,
4624
+ onError: S,
4607
4625
  onThreadChange: v,
4608
4626
  children: /* @__PURE__ */ ie(
4609
4627
  Ur,
@@ -4612,13 +4630,13 @@ function po({
4612
4630
  initialCheckpointId: r,
4613
4631
  initialCheckpointNs: o,
4614
4632
  autoLoadInitial: s,
4615
- onError: C,
4616
- isStreaming: w,
4633
+ onError: S,
4634
+ isStreaming: k,
4617
4635
  children: /* @__PURE__ */ ie(
4618
- Fr,
4636
+ Br,
4619
4637
  {
4620
4638
  ...j,
4621
- onStreamingChange: I,
4639
+ onStreamingChange: p,
4622
4640
  children: e
4623
4641
  }
4624
4642
  )
@@ -4635,9 +4653,9 @@ function pe(e) {
4635
4653
  return r(...n);
4636
4654
  }, []);
4637
4655
  }
4638
- const qr = 1, Hr = 1e6;
4656
+ const Kr = 1, qr = 1e6;
4639
4657
  let We = 0;
4640
- function Kr() {
4658
+ function Hr() {
4641
4659
  return We = (We + 1) % Number.MAX_SAFE_INTEGER, We.toString();
4642
4660
  }
4643
4661
  const Je = /* @__PURE__ */ new Map(), wt = (e) => {
@@ -4648,14 +4666,14 @@ const Je = /* @__PURE__ */ new Map(), wt = (e) => {
4648
4666
  type: "REMOVE_TOAST",
4649
4667
  toastId: e
4650
4668
  });
4651
- }, Hr);
4669
+ }, qr);
4652
4670
  Je.set(e, t);
4653
4671
  }, Gr = (e, t) => {
4654
4672
  switch (t.type) {
4655
4673
  case "ADD_TOAST":
4656
4674
  return {
4657
4675
  ...e,
4658
- toasts: [t.toast, ...e.toasts].slice(0, qr)
4676
+ toasts: [t.toast, ...e.toasts].slice(0, Kr)
4659
4677
  };
4660
4678
  case "UPDATE_TOAST":
4661
4679
  return {
@@ -4695,7 +4713,7 @@ function Le(e) {
4695
4713
  });
4696
4714
  }
4697
4715
  function Wr({ ...e }) {
4698
- const t = Kr(), n = (o) => Le({
4716
+ const t = Hr(), n = (o) => Le({
4699
4717
  type: "UPDATE_TOAST",
4700
4718
  toast: { ...o, id: t }
4701
4719
  }), r = () => Le({ type: "DISMISS_TOAST", toastId: t });
@@ -4727,75 +4745,75 @@ function Jr() {
4727
4745
  };
4728
4746
  }
4729
4747
  function go(e) {
4730
- const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = Ce(), { toast: o } = Jr(), [s, a] = B({}), [i, d] = B(null), [c, l] = B(!1), f = _(() => {
4731
- l(!1), d(null);
4732
- }, []), g = _((k) => {
4733
- d(k), l(!0);
4734
- }, []), m = _(
4735
- async (k, u, w) => {
4736
- var I, C;
4748
+ const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = Me(), { toast: o } = Jr(), [s, a] = $({}), [i, u] = $(null), [c, l] = $(!1), d = _(() => {
4749
+ l(!1), u(null);
4750
+ }, []), m = _((I) => {
4751
+ u(I), l(!0);
4752
+ }, []), y = _(
4753
+ async (I, f, k) => {
4754
+ var p, S;
4737
4755
  if (!t) {
4738
- k.preventDefault();
4756
+ I.preventDefault();
4739
4757
  return;
4740
4758
  }
4741
- if (s[w]) {
4742
- k.preventDefault();
4759
+ if (s[k]) {
4760
+ I.preventDefault();
4743
4761
  return;
4744
4762
  }
4745
4763
  try {
4746
- const x = String(u.url ?? ""), E = x.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
4764
+ const A = String(f.url ?? ""), E = A.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
4747
4765
  if (E) {
4748
- k.preventDefault();
4749
- const v = E[1], b = u.name || `file_${v}`, A = u.mimeType || "application/octet-stream";
4750
- g({ id: v, name: b, mimeType: A });
4766
+ I.preventDefault();
4767
+ const v = E[1], w = f.name || `file_${v}`, x = f.mimeType || "application/octet-stream";
4768
+ m({ id: v, name: w, mimeType: x });
4751
4769
  return;
4752
4770
  }
4753
- if (x.startsWith("data:")) {
4754
- k.preventDefault(), a((b) => ({ ...b, [w]: !0 }));
4771
+ if (A.startsWith("data:")) {
4772
+ I.preventDefault(), a((w) => ({ ...w, [k]: !0 }));
4755
4773
  const v = o({ title: "Fetching file...", description: "", open: !0 });
4756
4774
  try {
4757
- const b = await r.listFiles(n ?? void 0);
4758
- if (!b || !Array.isArray(b))
4775
+ const w = await r.listFiles(n ?? void 0);
4776
+ if (!w || !Array.isArray(w))
4759
4777
  throw new Error("Invalid file list response");
4760
- const A = b.find((p) => !p || typeof p != "object" || !((p.filename ?? "") === (u.name ?? "")) ? !1 : typeof u.size == "number" && typeof p.size == "number" ? p.size === u.size : !0);
4761
- if (!(A != null && A.id))
4762
- throw new Error(`File "${u.name}" is not yet available on the server`);
4763
- if (!A.id || !A.filename)
4778
+ const x = w.find((g) => !g || typeof g != "object" || !((g.filename ?? "") === (f.name ?? "")) ? !1 : typeof f.size == "number" && typeof g.size == "number" ? g.size === f.size : !0);
4779
+ if (!(x != null && x.id))
4780
+ throw new Error(`File "${f.name}" is not yet available on the server`);
4781
+ if (!x.id || !x.filename)
4764
4782
  throw new Error("Invalid file data received from server");
4765
- g({
4766
- id: A.id,
4767
- name: u.name || A.filename || `file_${A.id}`,
4768
- mimeType: u.mimeType || A.mime_type || "application/octet-stream"
4769
- }), (I = v.update) == null || I.call(v, {
4783
+ m({
4784
+ id: x.id,
4785
+ name: f.name || x.filename || `file_${x.id}`,
4786
+ mimeType: f.mimeType || x.mime_type || "application/octet-stream"
4787
+ }), (p = v.update) == null || p.call(v, {
4770
4788
  id: v.id,
4771
4789
  title: "Success",
4772
- description: `Opened ${u.name}`,
4790
+ description: `Opened ${f.name}`,
4773
4791
  open: !0
4774
4792
  });
4775
- } catch (b) {
4776
- console.error("Failed to fetch server file:", b);
4777
- const A = b instanceof Error ? b.message : "Unknown error occurred";
4778
- (C = v.update) == null || C.call(v, { id: v.id, title: "Failed", description: A }), o({
4793
+ } catch (w) {
4794
+ console.error("Failed to fetch server file:", w);
4795
+ const x = w instanceof Error ? w.message : "Unknown error occurred";
4796
+ (S = v.update) == null || S.call(v, { id: v.id, title: "Failed", description: x }), o({
4779
4797
  title: "Failed to fetch file",
4780
- description: A,
4798
+ description: x,
4781
4799
  open: !0
4782
4800
  });
4783
4801
  } finally {
4784
- a((b) => ({ ...b, [w]: !1 }));
4802
+ a((w) => ({ ...w, [k]: !1 }));
4785
4803
  }
4786
4804
  }
4787
- } catch (x) {
4788
- console.error("File click error:", x), a((E) => ({ ...E, [w]: !1 }));
4805
+ } catch (A) {
4806
+ console.error("File click error:", A), a((E) => ({ ...E, [k]: !1 }));
4789
4807
  }
4790
4808
  },
4791
- [t, s, o, n, g]
4809
+ [t, s, o, n, m]
4792
4810
  );
4793
4811
  return {
4794
4812
  uploadingFiles: s,
4795
- handleFileClick: m,
4813
+ handleFileClick: y,
4796
4814
  fileViewerOpen: c,
4797
4815
  currentFileInfo: i,
4798
- closeFileViewer: f
4816
+ closeFileViewer: d
4799
4817
  };
4800
4818
  }
4801
4819
  function mo(e) {
@@ -4808,20 +4826,20 @@ function mo(e) {
4808
4826
  toolMeta: ar(t),
4809
4827
  imageParts: n.filter((r) => r.type === "image_url"),
4810
4828
  fileParts: n.filter((r) => r.type === "file"),
4811
- toolRaw: On(n),
4829
+ toolRaw: Fn(n),
4812
4830
  isToolStreaming: !!t.toolStreaming
4813
4831
  };
4814
4832
  }, [e]);
4815
4833
  }
4816
- const vt = "data:";
4834
+ const kt = "data:";
4817
4835
  function Xr(e) {
4818
4836
  if (!e) return [];
4819
4837
  const t = [], n = e.split(/\r?\n/);
4820
4838
  for (const r of n) {
4821
4839
  const o = r.trim();
4822
- if (!o || !o.startsWith(vt))
4840
+ if (!o || !o.startsWith(kt))
4823
4841
  continue;
4824
- const s = o.slice(vt.length).trim();
4842
+ const s = o.slice(kt.length).trim();
4825
4843
  if (!s || s.toLowerCase() === "[done]")
4826
4844
  continue;
4827
4845
  const a = tt(s);
@@ -4840,16 +4858,16 @@ function Qr(e) {
4840
4858
  function yo(e) {
4841
4859
  return Y(() => {
4842
4860
  const t = e.content.filter(
4843
- (d) => d.type === "text"
4861
+ (u) => u.type === "text"
4844
4862
  );
4845
4863
  if (!t.length)
4846
4864
  return null;
4847
4865
  let r = t.flatMap(
4848
- (d) => Xr(d.text ?? "")
4866
+ (u) => Xr(u.text ?? "")
4849
4867
  );
4850
4868
  if (!r.length) {
4851
- const d = t.map((l) => l.text ?? "").join(`
4852
- `), c = tt(d);
4869
+ const u = t.map((l) => l.text ?? "").join(`
4870
+ `), c = tt(u);
4853
4871
  c && typeof c == "object" && (r = [c]);
4854
4872
  }
4855
4873
  if (!r.length)
@@ -4871,24 +4889,24 @@ function yo(e) {
4871
4889
  }, [e]);
4872
4890
  }
4873
4891
  function Yr(e) {
4874
- var S;
4875
- const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, n = typeof e == "object" ? e.lazy : !1, r = ot({ optional: !0 }), o = qt({ optional: !0 }), s = Br(), { currentThreadId: a, setCurrentThreadId: i, actions: d } = r || {
4892
+ var M, O;
4893
+ const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, n = typeof e == "object" ? e.lazy : !1, r = ot({ optional: !0 }), o = Kt({ optional: !0 }), s = Or(), { currentThreadId: a, setCurrentThreadId: i, actions: u } = r || {
4876
4894
  currentThreadId: null,
4877
4895
  setCurrentThreadId: () => {
4878
4896
  },
4879
4897
  actions: {}
4880
- }, c = !!t && t !== a, [l, f] = B([]), g = _((O) => {
4881
- f(O);
4898
+ }, c = !!t && t !== a, [l, d] = $([]), m = _((F) => {
4899
+ d(F);
4882
4900
  }, []), {
4883
- isLoadingThread: m,
4884
- threadStateError: k,
4885
- threadCheckpoints: u,
4886
- isLoadingHistory: w,
4887
- loadThread: I
4901
+ isLoadingThread: y,
4902
+ threadStateError: I,
4903
+ threadCheckpoints: f,
4904
+ isLoadingHistory: k,
4905
+ loadThread: p
4888
4906
  } = $t({
4889
- api: Ce().chatApi,
4890
- fileApi: Ce().fileApi,
4891
- seed: g,
4907
+ api: Me().chatApi,
4908
+ fileApi: Me().fileApi,
4909
+ seed: m,
4892
4910
  currentThreadId: c ? t : null,
4893
4911
  initialThreadId: c ? t : null,
4894
4912
  isStreaming: !1,
@@ -4898,20 +4916,20 @@ function Yr(e) {
4898
4916
  X(() => {
4899
4917
  !c && !n && a && (o != null && o.loadThread) && o.loadThread(a);
4900
4918
  }, [c, n, a, o == null ? void 0 : o.loadThread]);
4901
- const C = Y(() => {
4902
- var O;
4903
- return ((O = u[0]) == null ? void 0 : O.values) || {};
4904
- }, [u]), x = Y(() => ({ timeline: [], messagePreviews: {} }), []), E = t || a, v = c ? m ? "loading" : "idle" : (o == null ? void 0 : o.status) || "idle", b = c ? l : (s == null ? void 0 : s.messages) || [], A = c ? m : (o == null ? void 0 : o.isLoading) || !1, p = c ? w : (o == null ? void 0 : o.isLoadingHistory) || !1, h = c ? C : (o == null ? void 0 : o.values) || {}, P = c ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, j = c ? k : (s == null ? void 0 : s.error) || (o == null ? void 0 : o.error) || null;
4919
+ const S = Y(() => {
4920
+ var F;
4921
+ return ((F = f[0]) == null ? void 0 : F.values) || {};
4922
+ }, [f]), A = Y(() => ({ timeline: [], messagePreviews: {} }), []), E = t || a, v = c ? y ? "loading" : "idle" : (o == null ? void 0 : o.status) || "idle", w = c ? l : (s == null ? void 0 : s.messages) || [], x = c ? y : (o == null ? void 0 : o.isLoading) || !1, g = c ? k : (o == null ? void 0 : o.isLoadingHistory) || !1, b = c ? S : (o == null ? void 0 : o.values) || {}, P = c ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, j = c ? I : (s == null ? void 0 : s.error) || (o == null ? void 0 : o.error) || null;
4905
4923
  return {
4906
4924
  // UNIFIED: Single thread ID concept
4907
4925
  threadId: E,
4908
4926
  status: v,
4909
- messages: b,
4910
- isLoading: A,
4911
- isHistoryLoading: p,
4927
+ messages: w,
4928
+ isLoading: x,
4929
+ isHistoryLoading: g,
4912
4930
  error: j,
4913
4931
  // Values & Metadata
4914
- values: h,
4932
+ values: b,
4915
4933
  taskMessagesByScope: P,
4916
4934
  metadata: c ? {} : o == null ? void 0 : o.metadata,
4917
4935
  // Actions & State relating to Global/Active Thread only
@@ -4921,9 +4939,9 @@ function Yr(e) {
4921
4939
  returnToLatest: c ? async () => {
4922
4940
  } : (o == null ? void 0 : o.returnToLatest) || (async () => {
4923
4941
  }),
4924
- checkpoint: c ? u[0] ? { id: u[0].checkpointId, namespace: u[0].checkpointNs } : null : (o == null ? void 0 : o.checkpoint) || null,
4925
- checkpoints: c ? u : (o == null ? void 0 : o.checkpoints) || [],
4926
- checkpointIndex: c ? x : (o == null ? void 0 : o.checkpointIndex) || { timeline: [], messagePreviews: {} },
4942
+ checkpoint: c ? f[0] ? { id: f[0].checkpointId, namespace: f[0].checkpointNs } : null : (o == null ? void 0 : o.checkpoint) || null,
4943
+ checkpoints: c ? f : (o == null ? void 0 : o.checkpoints) || [],
4944
+ checkpointIndex: c ? A : (o == null ? void 0 : o.checkpointIndex) || { timeline: [], messagePreviews: {} },
4927
4945
  interrupt: c ? null : (o == null ? void 0 : o.interrupt) || null,
4928
4946
  respondToInterrupt: c ? async () => {
4929
4947
  } : (o == null ? void 0 : o.respondToInterrupt) || (async () => {
@@ -4931,9 +4949,9 @@ function Yr(e) {
4931
4949
  // Streaming Status
4932
4950
  // Even in standalone mode, allow streaming state/stop if a stream context exists.
4933
4951
  isStreaming: (s == null ? void 0 : s.isStreaming) || !1,
4934
- activeMessageId: (s == null ? void 0 : s.activeMessageId) || null,
4952
+ activeMessageId: c ? null : ((M = o == null ? void 0 : o.metadata) == null ? void 0 : M.assemblingMessageId) || (s == null ? void 0 : s.activeMessageId) || null,
4935
4953
  connectionState: (s == null ? void 0 : s.connectionState) || "disconnected",
4936
- streamingAssistantId: !c && (s != null && s.isStreaming) && ((S = o == null ? void 0 : o.metadata) != null && S.assemblingMessageId) ? o.metadata.assemblingMessageId : null,
4954
+ streamingAssistantId: !c && (s != null && s.isStreaming) && ((O = o == null ? void 0 : o.metadata) != null && O.assemblingMessageId) ? o.metadata.assemblingMessageId : null,
4937
4955
  // Actions
4938
4956
  submit: (s == null ? void 0 : s.submit) || (async () => {
4939
4957
  }),
@@ -4944,16 +4962,16 @@ function Yr(e) {
4944
4962
  }),
4945
4963
  setCurrentThreadId: i,
4946
4964
  loadHistory: c ? async () => {
4947
- t && await I(t);
4965
+ t && await p(t);
4948
4966
  } : async () => {
4949
4967
  },
4950
4968
  onEvent: c ? () => {
4951
4969
  } : (o == null ? void 0 : o.onEvent) || (() => {
4952
4970
  }),
4953
4971
  // Thread Management
4954
- createThread: d == null ? void 0 : d.createThread,
4955
- deleteThread: d == null ? void 0 : d.deleteThread,
4956
- renameThread: d == null ? void 0 : d.renameThread,
4972
+ createThread: u == null ? void 0 : u.createThread,
4973
+ deleteThread: u == null ? void 0 : u.deleteThread,
4974
+ renameThread: u == null ? void 0 : u.renameThread,
4957
4975
  threads: (r == null ? void 0 : r.threads) || [],
4958
4976
  isThreadsLoading: (r == null ? void 0 : r.isLoading) || !1
4959
4977
  };
@@ -4967,42 +4985,42 @@ function ho({
4967
4985
  onExcelUploadSuccess: s,
4968
4986
  onError: a,
4969
4987
  enableMessageEditing: i,
4970
- messages: d,
4988
+ messages: u,
4971
4989
  setPendingAssistantResponse: c,
4972
4990
  project: l,
4973
- onEvent: f,
4974
- threadId: g,
4975
- clearComposerOnSend: m = !0
4991
+ onEvent: d,
4992
+ threadId: m,
4993
+ clearComposerOnSend: y = !0
4976
4994
  }) {
4977
- const { messages: k } = Yr(), [u, w] = B(null), [I, C] = B(""), [x, E] = B(null), [v, b] = B(null), [A, p] = B(!1), [h, P] = B(""), j = W(h), S = W(null);
4995
+ const { messages: I } = Yr(), [f, k] = $(null), [p, S] = $(""), [A, E] = $(null), [v, w] = $(null), [x, g] = $(!1), [b, P] = $(""), j = W(b), M = W(null);
4978
4996
  X(() => {
4979
- if (!u)
4980
- if (g) {
4981
- const y = localStorage.getItem(Ge(g));
4982
- P(y || "");
4997
+ if (!f)
4998
+ if (m) {
4999
+ const h = localStorage.getItem(Ge(m));
5000
+ P(h || "");
4983
5001
  } else
4984
5002
  P("");
4985
- }, [g, u]);
4986
- const O = _((y) => {
4987
- P(y), !u && g && localStorage.setItem(Ge(g), y);
4988
- }, [g, u]);
5003
+ }, [m, f]);
5004
+ const O = _((h) => {
5005
+ P(h), !f && m && localStorage.setItem(Ge(m), h);
5006
+ }, [m, f]);
4989
5007
  X(() => {
4990
- j.current = h;
4991
- }, [h]), X(() => {
4992
- if (!u) {
4993
- S.current = null;
5008
+ j.current = b;
5009
+ }, [b]), X(() => {
5010
+ if (!f) {
5011
+ M.current = null;
4994
5012
  return;
4995
5013
  }
4996
- S.current === null && (S.current = j.current), O(I ?? "");
4997
- }, [I, u, O]);
4998
- const $ = _(
4999
- (y) => {
5000
- O(y);
5014
+ M.current === null && (M.current = j.current), O(p ?? "");
5015
+ }, [p, f, O]);
5016
+ const F = _(
5017
+ (h) => {
5018
+ O(h);
5001
5019
  },
5002
5020
  [O]
5003
- ), M = async (y, U) => {
5004
- const T = Array.isArray(U) ? { files: U } : U ?? {}, J = T.files ?? [], q = T.contentParts ?? [], H = y.trim();
5005
- if (!(!H && J.length === 0 && q.length === 0))
5021
+ ), C = async (h, U) => {
5022
+ const T = Array.isArray(U) ? { files: U } : U ?? {}, J = T.files ?? [], K = T.contentParts ?? [], q = h.trim();
5023
+ if (!(!q && J.length === 0 && K.length === 0))
5006
5024
  try {
5007
5025
  const ee = J.map(async (Q) => {
5008
5026
  try {
@@ -5023,73 +5041,73 @@ function ho({
5023
5041
  name: Q.filename,
5024
5042
  size: Q.size
5025
5043
  };
5026
- }), G = [...q, ...ue], te = u ? (x == null ? void 0 : x.checkpointId) ?? n ?? void 0 : n ?? void 0, ve = u ? (x == null ? void 0 : x.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5044
+ }), G = [...K, ...ue], te = f ? (A == null ? void 0 : A.checkpointId) ?? n ?? void 0 : n ?? void 0, ke = f ? (A == null ? void 0 : A.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5027
5045
  await e(
5028
5046
  {
5029
- text: H || "",
5047
+ text: q || "",
5030
5048
  contentParts: G,
5031
5049
  attachments: J,
5032
5050
  payload: t.payload,
5033
- edit: !!u,
5051
+ edit: !!f,
5034
5052
  checkpointId: te,
5035
- checkpointNs: ve,
5053
+ checkpointNs: ke,
5036
5054
  project: l ?? void 0,
5037
- originalMessageId: u ?? void 0,
5055
+ originalMessageId: f ?? void 0,
5038
5056
  config: t.config
5039
5057
  },
5040
- f ? { onEvent: f } : void 0
5041
- ), o == null || o(H), c(!0), m && (g && localStorage.removeItem(Ge(g)), O("")), b(null), w(null), C(""), E(null);
5058
+ d ? { onEvent: d } : void 0
5059
+ ), o == null || o(q), c(!0), y && (m && localStorage.removeItem(Ge(m)), O("")), w(null), k(null), S(""), E(null);
5042
5060
  } catch (ee) {
5043
5061
  const re = (ee == null ? void 0 : ee.message) || "Failed to send message";
5044
- b(re), a == null || a(re), c(!1);
5062
+ w(re), a == null || a(re), c(!1);
5045
5063
  }
5046
- }, F = (y, U) => {
5047
- U || M(y, { files: [] });
5064
+ }, B = (h, U) => {
5065
+ U || C(h, { files: [] });
5048
5066
  }, N = _(
5049
- async (y) => {
5067
+ async (h) => {
5050
5068
  await e(
5051
5069
  {
5052
- attachments: [y],
5070
+ attachments: [h],
5053
5071
  payload: t.payload,
5054
5072
  checkpointId: n ?? void 0,
5055
5073
  checkpointNs: r ?? void 0,
5056
5074
  project: l ?? void 0,
5057
5075
  config: t.config
5058
5076
  },
5059
- f ? { onEvent: f } : void 0
5060
- ), s == null || s({ file: y });
5077
+ d ? { onEvent: d } : void 0
5078
+ ), s == null || s({ file: h });
5061
5079
  },
5062
5080
  [n, r, t, s, e]
5063
5081
  ), V = _(
5064
- (y, U, T) => {
5065
- i && (S.current = h, w(y), C(U), E({
5082
+ (h, U, T) => {
5083
+ i && (M.current = b, k(h), S(U), E({
5066
5084
  checkpointId: (T == null ? void 0 : T.checkpointId) ?? null,
5067
5085
  checkpointNs: (T == null ? void 0 : T.checkpointNs) ?? null
5068
- }), b(null));
5086
+ }), w(null));
5069
5087
  },
5070
- [h, i]
5088
+ [b, i]
5071
5089
  ), z = _(() => {
5072
- w(null), C(""), E(null), b(null);
5073
- const y = S.current;
5074
- y !== null && P(y), S.current = null;
5075
- }, []), L = _((y) => {
5090
+ k(null), S(""), E(null), w(null);
5091
+ const h = M.current;
5092
+ h !== null && P(h), M.current = null;
5093
+ }, []), L = _((h) => {
5076
5094
  let U = null;
5077
- for (let H = y - 1; H >= 0; H--)
5078
- if (d[H].role === "user") {
5079
- U = d[H];
5095
+ for (let q = h - 1; q >= 0; q--)
5096
+ if (u[q].role === "user") {
5097
+ U = u[q];
5080
5098
  break;
5081
5099
  }
5082
5100
  if (!U) return;
5083
- const T = Array.isArray(U.content) ? U.content : [], q = T.filter((H) => (H == null ? void 0 : H.type) === "text").map((H) => H.text).join("") || (() => {
5101
+ const T = Array.isArray(U.content) ? U.content : [], K = T.filter((q) => (q == null ? void 0 : q.type) === "text").map((q) => q.text).join("") || (() => {
5084
5102
  try {
5085
5103
  return JSON.stringify(T, null, 2);
5086
5104
  } catch {
5087
5105
  return String(T);
5088
5106
  }
5089
5107
  })();
5090
- q && e(
5108
+ K && e(
5091
5109
  {
5092
- text: q,
5110
+ text: K,
5093
5111
  payload: t.payload,
5094
5112
  checkpointId: n ?? void 0,
5095
5113
  checkpointNs: r ?? void 0,
@@ -5097,25 +5115,25 @@ function ho({
5097
5115
  originalMessageId: U.id,
5098
5116
  config: t.config
5099
5117
  },
5100
- f ? { onEvent: f } : void 0
5118
+ d ? { onEvent: d } : void 0
5101
5119
  );
5102
- }, [d, e, n, r, t]);
5120
+ }, [u, e, n, r, t]);
5103
5121
  return {
5104
- editingMessageId: u,
5105
- editingInitialValue: I,
5122
+ editingMessageId: f,
5123
+ editingInitialValue: p,
5106
5124
  inputError: v,
5107
- setInputError: b,
5108
- dismissError: A,
5109
- setDismissError: p,
5110
- composerValue: h,
5111
- handleComposerChange: $,
5112
- handleSendMessage: M,
5113
- handleQuickPrompt: F,
5125
+ setInputError: w,
5126
+ dismissError: x,
5127
+ setDismissError: g,
5128
+ composerValue: b,
5129
+ handleComposerChange: F,
5130
+ handleSendMessage: C,
5131
+ handleQuickPrompt: B,
5114
5132
  handleExcelUpload: N,
5115
5133
  startEditing: V,
5116
5134
  cancelEditing: z,
5117
5135
  handleRegenerateCb: L,
5118
- displayMessages: k
5136
+ displayMessages: I
5119
5137
  };
5120
5138
  }
5121
5139
  function bo(e) {
@@ -5123,7 +5141,7 @@ function bo(e) {
5123
5141
  textContent: Ln(e),
5124
5142
  imageParts: Un(e),
5125
5143
  fileParts: jn(e),
5126
- toolCalls: Ct(e),
5144
+ toolCalls: Mt(e),
5127
5145
  contentParts: e.content
5128
5146
  } : {
5129
5147
  textContent: "",
@@ -5134,7 +5152,7 @@ function bo(e) {
5134
5152
  }, [e]);
5135
5153
  }
5136
5154
  function wo(e, t, n) {
5137
- const [r, o] = B(e), s = W(e), a = W(null);
5155
+ const [r, o] = $(e), s = W(e), a = W(null);
5138
5156
  return X(() => {
5139
5157
  s.current = e;
5140
5158
  const i = () => {
@@ -5165,21 +5183,21 @@ export {
5165
5183
  Pt as getChatToken,
5166
5184
  uo as getMessageAttemptInfo,
5167
5185
  ao as getToolCallArtifacts,
5168
- Hn as getToolCalls,
5186
+ qn as getToolCalls,
5169
5187
  so as hasContent,
5170
5188
  mt as hydrateHistorySnapshots,
5171
- Mt as isFileLike,
5189
+ Ct as isFileLike,
5172
5190
  Nn as looksLikeMarkdown,
5173
5191
  lo as messageSignature,
5174
5192
  io as normalizeInterruptId,
5175
5193
  _t as onChatTokenChanged,
5176
5194
  tt as parseJsonSafe,
5177
5195
  Et as pretty,
5178
- Cr as refreshHistoryFileUrls,
5196
+ Mr as refreshHistoryFileUrls,
5179
5197
  Ve as sanitizeForDisplay,
5180
- ke as setChatToken,
5181
- On as stringifyTool,
5182
- Ce as useApi,
5198
+ ve as setChatToken,
5199
+ Fn as stringifyTool,
5200
+ Me as useApi,
5183
5201
  ho as useChatController,
5184
5202
  Yr as useChatSession,
5185
5203
  go as useFilePreview,
@@ -5188,7 +5206,7 @@ export {
5188
5206
  pr as useStream,
5189
5207
  wo as useStreamingMarkdownBuffer,
5190
5208
  $t as useThreadHistoryState,
5191
- qt as useThreadState,
5209
+ Kt as useThreadState,
5192
5210
  Lr as useThreadStateUpdater,
5193
5211
  ot as useThreads,
5194
5212
  gr as useThreadsState,