@teodorruskvi/chat-core 0.1.46 → 0.1.47

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,25 @@ 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) {
3445
+ function Oe(e) {
3446
3446
  return e.map((t) => nt(t)).filter((t) => !!t);
3447
3447
  }
3448
- function Ot(e, t, n) {
3448
+ function Ft(e, t, n) {
3449
3449
  return t < 0 || t >= e.length ? e : [...e.slice(0, t), n, ...e.slice(t + 1)];
3450
3450
  }
3451
3451
  function br(e, t, n) {
3452
3452
  for (let r = e.length - 1; r >= 0; r--)
3453
3453
  if (e[r].role === "assistant") {
3454
3454
  const s = { ...e[r], checkpointId: t, checkpointNs: n ?? void 0 };
3455
- return Ot(e, r, s);
3455
+ return Ft(e, r, s);
3456
3456
  }
3457
3457
  return e;
3458
3458
  }
3459
- const Bt = {
3459
+ const Ot = {
3460
3460
  status: "idle",
3461
3461
  messages: [],
3462
3462
  taskMessagesByScope: {},
@@ -3479,8 +3479,8 @@ function wr(e, t) {
3479
3479
  };
3480
3480
  case "reset":
3481
3481
  return {
3482
- ...Bt,
3483
- messages: Be(((n = t.payload) == null ? void 0 : n.messages) ?? [])
3482
+ ...Ot,
3483
+ messages: Oe(((n = t.payload) == null ? void 0 : n.messages) ?? [])
3484
3484
  };
3485
3485
  case "user_message": {
3486
3486
  const { message: r } = t.payload;
@@ -3494,7 +3494,7 @@ function wr(e, t) {
3494
3494
  };
3495
3495
  }
3496
3496
  case "seed": {
3497
- const r = Be(t.payload.messages), o = {
3497
+ const r = Oe(t.payload.messages), o = {
3498
3498
  ...e,
3499
3499
  status: "idle",
3500
3500
  messages: r,
@@ -3506,7 +3506,7 @@ function wr(e, t) {
3506
3506
  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
3507
  }
3508
3508
  case "prepend": {
3509
- const r = Be(t.payload.messages);
3509
+ const r = Oe(t.payload.messages);
3510
3510
  if (!r.length) return e;
3511
3511
  const o = new Set(e.messages.map((a) => a.id)), s = r.filter((a) => !o.has(a.id));
3512
3512
  return s.length ? { ...e, messages: [...s, ...e.messages] } : e;
@@ -3521,8 +3521,8 @@ function wr(e, t) {
3521
3521
  return e;
3522
3522
  }
3523
3523
  }
3524
- function vr(e = []) {
3525
- const [t, n] = Wt(wr, { ...Bt, messages: e }), r = W([]), o = W(null), s = _(() => {
3524
+ function kr(e = []) {
3525
+ const [t, n] = Wt(wr, { ...Ot, messages: e }), r = W([]), o = W(null), s = _(() => {
3526
3526
  o.current !== null && typeof window < "u" && window.cancelAnimationFrame(o.current), o.current = null;
3527
3527
  const c = r.current;
3528
3528
  c.length && (r.current = [], n({ type: "batch", payload: { events: c } }));
@@ -3530,14 +3530,14 @@ function vr(e = []) {
3530
3530
  typeof window < "u" && typeof window.requestAnimationFrame == "function" ? o.current === null && (o.current = window.requestAnimationFrame(() => s())) : setTimeout(s, 8);
3531
3531
  }, [s]), i = _((c) => {
3532
3532
  r.current.push(c), a();
3533
- }, [a]), d = Y(() => ({
3533
+ }, [a]), u = Y(() => ({
3534
3534
  setStatus: (c, l) => n({ type: "status", payload: { status: c, error: l } }),
3535
3535
  reset: (c) => n({ type: "reset", payload: { messages: c } }),
3536
3536
  seed: (c, l) => n({ type: "seed", payload: { messages: c, ...l ?? {} } }),
3537
3537
  pushUser: (c, l) => n({ type: "user_message", payload: { message: c, editingMessageId: l } }),
3538
3538
  onEvent: i
3539
3539
  }), [i]);
3540
- return { state: t, dispatch: n, ...d };
3540
+ return { state: t, dispatch: n, ...u };
3541
3541
  }
3542
3542
  function pt(e, t) {
3543
3543
  const n = t.origin, r = t.scope, o = n === "task" || typeof r == "string" && r.startsWith("tools:");
@@ -3570,31 +3570,33 @@ function pt(e, t) {
3570
3570
  return { ...e, status: "error", error: t.message, messages: [...e.messages, s] };
3571
3571
  }
3572
3572
  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 ? {
3573
+ 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
3574
  id: l[0].id || "native-interrupt",
3575
3575
  value: l[0].value || l[0],
3576
3576
  alternatives: l[0].alternatives
3577
3577
  } : null;
3578
3578
  if (o) {
3579
- const g = typeof r == "string" && r.length > 0 ? r : "task";
3579
+ const m = typeof r == "string" && r.length > 0 ? r : "task";
3580
3580
  return {
3581
3581
  ...e,
3582
- taskMessagesByScope: { ...e.taskMessagesByScope, [g]: i }
3582
+ taskMessagesByScope: { ...e.taskMessagesByScope, [m]: i },
3583
+ assemblingId: null
3584
+ // Clear streaming state when finalized
3583
3585
  };
3584
3586
  }
3585
3587
  return {
3586
3588
  ...e,
3587
- status: f ? "awaiting_input" : e.status === "streaming" ? "idle" : e.status,
3589
+ status: d ? "awaiting_input" : e.status === "streaming" ? "idle" : e.status,
3588
3590
  messages: i,
3589
3591
  assemblingId: null,
3590
- pendingInterrupt: f,
3592
+ pendingInterrupt: d,
3591
3593
  values: c
3592
3594
  };
3593
3595
  }
3594
3596
  if (t.type === "messages/metadata") {
3595
3597
  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;
3598
+ return a && typeof a == "object" && Object.entries(a).forEach(([i, u]) => {
3599
+ const c = u == null ? void 0 : u.metadata;
3598
3600
  if (!c || typeof c != "object") return;
3599
3601
  const l = s[i] ?? {};
3600
3602
  s[i] = {
@@ -3603,49 +3605,50 @@ function pt(e, t) {
3603
3605
  };
3604
3606
  }), { ...e, messagesStreamMeta: s };
3605
3607
  }
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;
3608
+ 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
3609
  }
3608
- function kr(e, t) {
3609
- var l, f, g, m, k;
3610
- const n = t.messages;
3611
- if (!n.length)
3610
+ function vr(e, t, n) {
3611
+ var m, y, I, f, k;
3612
+ const r = t.messages;
3613
+ if (!r.length)
3612
3614
  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,
3615
+ const o = r.find((p) => p.type === "ai" || p.type === "assistant" || p.role === "assistant");
3616
+ if (!o) return e;
3617
+ 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";
3618
+ let d = n ? [...e.taskMessagesByScope[l] || []] : [...e.messages];
3619
+ if (c) {
3620
+ const p = nt({
3621
+ ...o,
3620
3622
  role: "assistant",
3621
- content: a,
3623
+ content: i,
3622
3624
  scope: t.scope,
3623
3625
  origin: t.origin
3624
3626
  });
3625
- u && c.push(u);
3627
+ p && d.push(p);
3626
3628
  } 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
3629
+ const p = d.findIndex((S) => S.id === s);
3630
+ if (p !== -1) {
3631
+ const S = d[p];
3632
+ d[p] = {
3633
+ ...S,
3634
+ content: i,
3635
+ scope: t.scope ?? S.scope,
3636
+ origin: t.origin ?? S.origin
3635
3637
  };
3636
3638
  }
3637
3639
  }
3638
3640
  return {
3639
3641
  ...e,
3640
3642
  status: "streaming",
3641
- messages: c,
3642
- assemblingId: o,
3643
+ messages: n ? e.messages : d,
3644
+ taskMessagesByScope: n ? { ...e.taskMessagesByScope, [l]: d } : e.taskMessagesByScope,
3645
+ assemblingId: s,
3643
3646
  messagesStreamMeta: {
3644
3647
  ...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) ?? "")
3648
+ [s]: {
3649
+ ...((m = e.messagesStreamMeta) == null ? void 0 : m[s]) ?? {},
3650
+ lastSeq: t.seq ?? ((I = (y = e.messagesStreamMeta) == null ? void 0 : y[s]) == null ? void 0 : I.lastSeq) ?? null,
3651
+ lastText: u || (((k = (f = e.messagesStreamMeta) == null ? void 0 : f[s]) == null ? void 0 : k.lastText) ?? "")
3649
3652
  }
3650
3653
  }
3651
3654
  };
@@ -3660,21 +3663,21 @@ function st(e, t) {
3660
3663
  }
3661
3664
  return -1;
3662
3665
  }
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;
3666
+ function Ir(e, t, n) {
3667
+ const r = t.id || t.callId;
3668
+ if (!r) return e;
3669
+ const o = t.name || "tool", s = `Starting ${o}...`, a = typeof t.scope == "string" && t.scope.length > 0 ? t.scope : "task";
3670
+ let i = n ? [...e.taskMessagesByScope[a] || []] : [...e.messages], u = st(i, r);
3671
+ if (u === -1) {
3672
+ for (let c = i.length - 1; c >= 0; c--)
3673
+ if (i[c].role === "assistant") {
3674
+ u = c;
3672
3675
  break;
3673
3676
  }
3674
3677
  }
3675
- if (a === -1) {
3676
- const i = {
3677
- id: `assistant-${n}`,
3678
+ if (u === -1) {
3679
+ const c = {
3680
+ id: `assistant-${r}`,
3678
3681
  role: "assistant",
3679
3682
  content: [{ type: "text", text: "" }],
3680
3683
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
@@ -3682,76 +3685,90 @@ function Ir(e, t) {
3682
3685
  scope: t.scope,
3683
3686
  origin: t.origin
3684
3687
  };
3685
- s.push(i), a = s.length - 1;
3688
+ i.push(c), u = i.length - 1;
3686
3689
  }
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,
3690
+ if (u !== -1) {
3691
+ const c = i[u], l = [...c.toolCalls || []], d = l.findIndex((m) => m.id === r);
3692
+ d >= 0 ? l[d] = { ...l[d], status: "running", content: s } : l.push({
3693
+ id: r,
3694
+ name: o,
3692
3695
  args: t.args || {},
3693
3696
  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
3697
+ content: s
3698
+ }), i[u] = {
3699
+ ...c,
3700
+ toolCalls: l,
3701
+ scope: t.scope ?? c.scope,
3702
+ origin: t.origin ?? c.origin
3700
3703
  };
3701
3704
  }
3702
- return { ...e, messages: s };
3705
+ return {
3706
+ ...e,
3707
+ messages: n ? e.messages : i,
3708
+ taskMessagesByScope: n ? { ...e.taskMessagesByScope, [a]: i } : e.taskMessagesByScope
3709
+ };
3703
3710
  }
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
3711
+ function Ar(e, t, n) {
3712
+ const r = t.id;
3713
+ if (!r) return e;
3714
+ const o = typeof t.scope == "string" && t.scope.length > 0 ? t.scope : "task";
3715
+ let s = n ? [...e.taskMessagesByScope[o] || []] : [...e.messages];
3716
+ const a = st(s, r);
3717
+ if (a !== -1) {
3718
+ const i = s[a], u = ce(t.content), c = (i.toolCalls || []).map(
3719
+ (l) => l.id === r ? { ...l, content: typeof u == "string" ? u : l.content } : l
3712
3720
  );
3713
- r[o] = {
3714
- ...s,
3715
- toolCalls: i,
3716
- scope: t.scope ?? s.scope,
3717
- origin: t.origin ?? s.origin
3721
+ s[a] = {
3722
+ ...i,
3723
+ toolCalls: c,
3724
+ scope: t.scope ?? i.scope,
3725
+ origin: t.origin ?? i.origin
3718
3726
  };
3719
3727
  }
3720
- return { ...e, messages: r };
3728
+ return {
3729
+ ...e,
3730
+ messages: n ? e.messages : s,
3731
+ taskMessagesByScope: n ? { ...e.taskMessagesByScope, [o]: s } : e.taskMessagesByScope
3732
+ };
3721
3733
  }
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,
3734
+ function xr(e, t, n) {
3735
+ const r = t.id;
3736
+ if (!r) return e;
3737
+ const o = typeof t.scope == "string" && t.scope.length > 0 ? t.scope : "task";
3738
+ let s = n ? [...e.taskMessagesByScope[o] || []] : [...e.messages];
3739
+ const a = st(s, r), i = ce(t.content ?? t.error);
3740
+ if (a !== -1) {
3741
+ const c = s[a], l = (c.toolCalls || []).map(
3742
+ (d) => d.id === r ? {
3743
+ ...d,
3731
3744
  status: t.error ? "failed" : "completed",
3732
- content: typeof s == "string" ? s : c.content,
3745
+ content: typeof i == "string" ? i : d.content,
3733
3746
  artifact: t.artifact
3734
- } : c
3747
+ } : d
3735
3748
  );
3736
- r[o] = {
3737
- ...i,
3738
- toolCalls: d,
3739
- scope: t.scope ?? i.scope,
3740
- origin: t.origin ?? i.origin
3749
+ s[a] = {
3750
+ ...c,
3751
+ toolCalls: l,
3752
+ scope: t.scope ?? c.scope,
3753
+ origin: t.origin ?? c.origin
3741
3754
  };
3742
3755
  }
3743
- const a = {
3744
- id: `tool-${n}`,
3756
+ const u = {
3757
+ id: `tool-${r}`,
3745
3758
  role: "tool",
3746
3759
  name: t.name,
3747
- content: [{ type: "text", text: typeof s == "string" ? s : "" }],
3760
+ content: [{ type: "text", text: typeof i == "string" ? i : "" }],
3748
3761
  artifact: t.artifact,
3749
- toolCallId: n,
3762
+ toolCallId: r,
3750
3763
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3751
3764
  scope: t.scope,
3752
3765
  origin: t.origin
3753
3766
  };
3754
- return { ...e, messages: [...r, a] };
3767
+ return s.push(u), {
3768
+ ...e,
3769
+ messages: n ? e.messages : s,
3770
+ taskMessagesByScope: n ? { ...e.taskMessagesByScope, [o]: s } : e.taskMessagesByScope
3771
+ };
3755
3772
  }
3756
3773
  function Tr(e, t) {
3757
3774
  const n = t.artifactId, r = hr(e.messages, n, t.callId);
@@ -3761,13 +3778,13 @@ function Tr(e, t) {
3761
3778
  progress: t.progress,
3762
3779
  error: t.error
3763
3780
  });
3764
- return t.partial_data && s.artifact && (s.artifact = { ...s.artifact, ...t.partial_data }), { ...e, messages: Ot(e.messages, o, s) };
3781
+ return t.partial_data && s.artifact && (s.artifact = { ...s.artifact, ...t.partial_data }), { ...e, messages: Ft(e.messages, o, s) };
3765
3782
  }
3766
3783
  function Re(e) {
3767
3784
  if (!(!e || typeof e != "object" || Array.isArray(e)))
3768
3785
  return { ...e };
3769
3786
  }
3770
- function Oe(e, t) {
3787
+ function Fe(e, t) {
3771
3788
  if (e)
3772
3789
  for (const n of t) {
3773
3790
  const r = e[n];
@@ -3789,20 +3806,20 @@ function gt(e) {
3789
3806
  if (t)
3790
3807
  return Re(t.configurable) ?? t;
3791
3808
  }
3792
- async function Cr(e, t) {
3793
- var i, d;
3809
+ async function Mr(e, t) {
3810
+ var i, u;
3794
3811
  if (!e) return e ?? null;
3795
3812
  const n = le(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], o = /* @__PURE__ */ new Set();
3796
3813
  for (const c of r) {
3797
3814
  const l = (i = c == null ? void 0 : c.values) == null ? void 0 : i.messages;
3798
3815
  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);
3816
+ for (const d of l) {
3817
+ const m = d == null ? void 0 : d.content;
3818
+ if (Array.isArray(m))
3819
+ for (const y of m) {
3820
+ if (!y || typeof y != "object" || y.type !== "image_url" && y.type !== "file") continue;
3821
+ const I = y.fileId || y.file_id;
3822
+ typeof I == "string" && I.trim() && o.add(I);
3806
3823
  }
3807
3824
  }
3808
3825
  }
@@ -3811,32 +3828,32 @@ async function Cr(e, t) {
3811
3828
  const s = await Promise.all(
3812
3829
  Array.from(o).map(async (c) => {
3813
3830
  try {
3814
- const l = await t.getFileInfo(c), f = le(l);
3815
- return [c, f];
3831
+ const l = await t.getFileInfo(c), d = le(l);
3832
+ return [c, d];
3816
3833
  } catch {
3817
3834
  return [c, null];
3818
3835
  }
3819
3836
  })
3820
3837
  ), a = new Map(s);
3821
3838
  for (const c of r) {
3822
- const l = (d = c == null ? void 0 : c.values) == null ? void 0 : d.messages;
3839
+ const l = (u = c == null ? void 0 : c.values) == null ? void 0 : u.messages;
3823
3840
  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))));
3841
+ for (const d of l) {
3842
+ const m = d == null ? void 0 : d.content;
3843
+ if (Array.isArray(m))
3844
+ for (const y of m) {
3845
+ if (!y || typeof y != "object" || y.type !== "image_url" && y.type !== "file") continue;
3846
+ const I = y.fileId || y.file_id;
3847
+ if (!I) continue;
3848
+ const f = a.get(I), k = (f == null ? void 0 : f.contentUrl) || (f == null ? void 0 : f.content_url);
3849
+ 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
3850
  }
3834
3851
  }
3835
3852
  }
3836
3853
  return n;
3837
3854
  }
3838
3855
  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;
3856
+ 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
3857
  return {
3841
3858
  threadId: (e == null ? void 0 : e.threadId) ?? "",
3842
3859
  latest: o,
@@ -3844,34 +3861,34 @@ function mt(e) {
3844
3861
  interrupt: (o == null ? void 0 : o.interrupt) ?? null
3845
3862
  };
3846
3863
  }
3847
- function Mr(e, t) {
3848
- var v, b;
3864
+ function Cr(e, t) {
3865
+ var v, w;
3849
3866
  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 = {
3867
+ 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
3868
  ...a,
3852
3869
  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 : [];
3870
+ source: Fe(a, ["source"]) ?? null
3871
+ }, S = s.map((x) => ({
3872
+ ...x,
3873
+ checkpointId: x.checkpointId ?? l ?? null,
3874
+ checkpointNs: x.checkpointNs ?? d ?? null
3875
+ })), A = e.values, E = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(A == null ? void 0 : A.interrupts) ? A.interrupts : [];
3859
3876
  return {
3860
3877
  checkpointId: l ?? null,
3861
- checkpointNs: f ?? null,
3862
- createdAt: w,
3863
- parentId: g ?? null,
3864
- messages: C,
3878
+ checkpointNs: d ?? null,
3879
+ createdAt: k,
3880
+ parentId: m ?? null,
3881
+ messages: S,
3865
3882
  interrupt: Pr(
3866
3883
  E,
3867
3884
  t,
3868
3885
  l ?? null
3869
3886
  ),
3870
- metadata: I,
3871
- config: m ?? null,
3872
- parentConfig: d ?? null,
3873
- next: u,
3874
- tasks: k,
3887
+ metadata: p,
3888
+ config: y ?? null,
3889
+ parentConfig: u ?? null,
3890
+ next: f,
3891
+ tasks: I,
3875
3892
  values: e.values ?? {}
3876
3893
  };
3877
3894
  }
@@ -3916,33 +3933,33 @@ function Nr(e) {
3916
3933
  function zr(e) {
3917
3934
  const t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Map(), o = [];
3918
3935
  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,
3936
+ 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;
3937
+ let k = null, p = null;
3938
+ const S = Array.isArray(l.messages) ? l.messages : [];
3939
+ for (const w of S)
3940
+ w.role === "user" && (p || (p = w), w.id && (k = w.id));
3941
+ const A = l.next && l.next.length > 0 ? String(l.next[0]) : null, E = l.parentConfig ?? null, v = {
3942
+ id: m,
3943
+ step: I,
3944
+ source: f,
3928
3945
  createdAt: l.createdAt ?? null,
3929
3946
  namespace: l.checkpointNs ?? null,
3930
3947
  parentId: l.parentId ?? null,
3931
- next: x,
3948
+ next: A,
3932
3949
  parentConfig: E,
3933
- userMessageId: w
3950
+ userMessageId: k
3934
3951
  };
3935
- if (o.push(v), f && t.set(f, v), f && I) {
3936
- const b = Nr(I);
3937
- b && r.set(f, b);
3952
+ if (o.push(v), d && t.set(d, v), d && p) {
3953
+ const w = Nr(p);
3954
+ w && r.set(d, w);
3938
3955
  }
3939
3956
  n.push({
3940
- id: g,
3941
- messageId: w,
3942
- step: k,
3943
- source: u,
3957
+ id: m,
3958
+ messageId: k,
3959
+ step: I,
3960
+ source: f,
3944
3961
  createdAt: l.createdAt ?? null,
3945
- next: x,
3962
+ next: A,
3946
3963
  parentConfig: E
3947
3964
  });
3948
3965
  }
@@ -3954,14 +3971,14 @@ function zr(e) {
3954
3971
  }
3955
3972
  for (const c of s.values()) {
3956
3973
  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;
3974
+ c.sort((d, m) => {
3975
+ const y = d.createdAt ? Date.parse(d.createdAt) : 0;
3976
+ return (m.createdAt ? Date.parse(m.createdAt) : 0) - y;
3960
3977
  });
3961
3978
  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;
3979
+ for (let d = 0; d < c.length; d++) {
3980
+ const m = c[d];
3981
+ m.attemptCount = l, m.attemptIndex = d, m.isLatestAttempt = d === 0;
3965
3982
  }
3966
3983
  }
3967
3984
  return {
@@ -3977,11 +3994,11 @@ function zr(e) {
3977
3994
  getCheckpoint: (c) => t.get(c),
3978
3995
  getMessageAttempts: (c) => {
3979
3996
  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;
3997
+ for (const d of t.values())
3998
+ d.userMessageId === c && l.push(d);
3999
+ return l.length ? (l.sort((d, m) => {
4000
+ const y = typeof d.attemptIndex == "number" ? d.attemptIndex : Number.MAX_SAFE_INTEGER, I = typeof m.attemptIndex == "number" ? m.attemptIndex : Number.MAX_SAFE_INTEGER;
4001
+ return y - I;
3985
4002
  }), l) : [];
3986
4003
  }
3987
4004
  };
@@ -4016,43 +4033,43 @@ function $t({
4016
4033
  isStreaming: a,
4017
4034
  getMessages: i
4018
4035
  }) {
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);
4036
+ const [u, c] = $(null), d = Y(
4037
+ () => mt(u),
4038
+ [u]
4039
+ ).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
4040
  X(() => {
4024
- b.current = o;
4041
+ w.current = o;
4025
4042
  }, [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
4043
+ const b = _(
4044
+ async (C) => {
4045
+ const B = await e.getState({
4046
+ threadId: C.threadId,
4047
+ checkpointId: C.checkpointId,
4048
+ checkpointNs: C.checkpointNs
4032
4049
  }), N = {
4033
4050
  version: "values@1",
4034
- threadId: M.threadId,
4035
- checkpoints: [F]
4036
- }, V = t ? await Cr(N, t) : N, { latest: z } = mt(V);
4051
+ threadId: C.threadId,
4052
+ checkpoints: [B]
4053
+ }, V = t ? await Mr(N, t) : N, { latest: z } = mt(V);
4037
4054
  return z;
4038
4055
  },
4039
4056
  [e, t]
4040
4057
  ), P = _(
4041
- async (M, F) => {
4058
+ async (C, B) => {
4042
4059
  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();
4060
+ if (!C) return;
4061
+ const N = `${C}:${B ?? "latest"}`;
4062
+ if (x.current === N || I) return;
4063
+ (z = g.current) == null || z.abort();
4047
4064
  const V = new AbortController();
4048
- p.current = V, u(!0), v(null);
4065
+ g.current = V, f(!0), v(null);
4049
4066
  try {
4050
- const L = await h({
4051
- threadId: M,
4052
- checkpointId: F ?? void 0
4067
+ const L = await b({
4068
+ threadId: C,
4069
+ checkpointId: B ?? void 0
4053
4070
  });
4054
- if (b.current !== M) {
4055
- u(!1);
4071
+ if (w.current !== C) {
4072
+ f(!1);
4056
4073
  return;
4057
4074
  }
4058
4075
  n((L == null ? void 0 : L.messages) ?? [], {
@@ -4060,59 +4077,59 @@ function $t({
4060
4077
  checkpointNs: (L == null ? void 0 : L.checkpointNs) ?? null,
4061
4078
  pendingInterrupt: (L == null ? void 0 : L.interrupt) ?? null,
4062
4079
  values: L == null ? void 0 : L.values
4063
- }), A.current = N, u(!1), x(!0);
4080
+ }), x.current = N, f(!1), A(!0);
4064
4081
  try {
4065
- const K = await e.getStateHistory({
4066
- threadId: M,
4082
+ const H = await e.getStateHistory({
4083
+ threadId: C,
4067
4084
  limit: 100,
4068
4085
  includeMessages: !1
4069
4086
  });
4070
- b.current === M && c(K);
4087
+ w.current === C && c(H);
4071
4088
  } finally {
4072
- x(!1);
4089
+ A(!1);
4073
4090
  }
4074
4091
  } catch (L) {
4075
- if (u(!1), !Xt(L)) {
4076
- const K = String(L);
4077
- v(K), r == null || r(K);
4092
+ if (f(!1), !Xt(L)) {
4093
+ const H = String(L);
4094
+ v(H), r == null || r(H);
4078
4095
  }
4079
4096
  }
4080
4097
  },
4081
- [e, n, h, r, i]
4098
+ [e, n, b, r, i]
4082
4099
  ), j = _(
4083
- async (M, F) => {
4100
+ async (C, B) => {
4084
4101
  if (o) {
4085
- I(!0);
4102
+ p(!0);
4086
4103
  try {
4087
- const N = await h({
4104
+ const N = await b({
4088
4105
  threadId: o,
4089
- checkpointId: M,
4090
- checkpointNs: F ?? void 0
4106
+ checkpointId: C,
4107
+ checkpointNs: B ?? void 0
4091
4108
  });
4092
4109
  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,
4110
+ checkpointId: (N == null ? void 0 : N.checkpointId) ?? C,
4111
+ checkpointNs: (N == null ? void 0 : N.checkpointNs) ?? B,
4095
4112
  pendingInterrupt: (N == null ? void 0 : N.interrupt) ?? null,
4096
4113
  values: N == null ? void 0 : N.values
4097
4114
  });
4098
4115
  } catch (N) {
4099
4116
  console.error("[useThreadHistoryState] Navigation failed", N);
4100
4117
  } finally {
4101
- I(!1);
4118
+ p(!1);
4102
4119
  }
4103
4120
  }
4104
4121
  },
4105
- [o, h, n]
4106
- ), S = _(async () => {
4122
+ [o, b, n]
4123
+ ), M = _(async () => {
4107
4124
  o && await P(o);
4108
4125
  }, [o, P]), O = _(
4109
- async (M) => {
4126
+ async (C) => {
4110
4127
  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
4128
+ const B = (C == null ? void 0 : C.threadId) || o;
4129
+ if (!B || o !== B) return;
4130
+ if (c(C), x.current = `${B}:latest`, (V = C.values) != null && V.messages) {
4131
+ const z = await b({
4132
+ threadId: B
4116
4133
  });
4117
4134
  z && n(z.messages ?? [], {
4118
4135
  checkpointId: z.checkpointId ?? null,
@@ -4122,41 +4139,41 @@ function $t({
4122
4139
  });
4123
4140
  }
4124
4141
  },
4125
- [o, h, n]
4142
+ [o, b, n]
4126
4143
  );
4127
4144
  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;
4145
+ if (!s || !o || I || a) return;
4146
+ const C = `${o}:latest`;
4147
+ x.current !== C && P(o);
4148
+ }, [s, o, I, a, P]);
4149
+ const F = _(() => {
4150
+ c(null), f(!1), p(!1), A(!1), v(null), x.current = null;
4134
4151
  }, []);
4135
4152
  return {
4136
- threadCheckpoints: f,
4137
- threadTimeline: m,
4138
- checkpointIndex: g,
4139
- isLoadingThread: k,
4140
- isLoadingCheckpoint: w,
4141
- isLoadingHistory: C,
4153
+ threadCheckpoints: d,
4154
+ threadTimeline: y,
4155
+ checkpointIndex: m,
4156
+ isLoadingThread: I,
4157
+ isLoadingCheckpoint: k,
4158
+ isLoadingHistory: S,
4142
4159
  threadStateError: E,
4143
4160
  loadThread: P,
4144
4161
  navigateToCheckpoint: j,
4145
- setCurrentCheckpointId: (M, F) => {
4146
- n(i(), { checkpointId: M, checkpointNs: F });
4162
+ setCurrentCheckpointId: (C, B) => {
4163
+ n(i(), { checkpointId: C, checkpointNs: B });
4147
4164
  },
4148
- returnToLatest: S,
4165
+ returnToLatest: M,
4149
4166
  handleValuesEvent: O,
4150
4167
  markSkipNextLoad: () => {
4151
4168
  },
4152
4169
  markStreamPendingThread: () => {
4153
4170
  },
4154
- resetHistoryState: $,
4155
- clearState: $
4171
+ resetHistoryState: F,
4172
+ clearState: F
4156
4173
  };
4157
4174
  }
4158
- const Dt = Me(null), Vt = Me(null);
4159
- function qt(e) {
4175
+ const Dt = Ce(null), Vt = Ce(null);
4176
+ function Kt(e) {
4160
4177
  const t = Ue(Dt);
4161
4178
  if (!t && !(e != null && e.optional)) throw new Error("useThreadState must be used within a ThreadStateProvider");
4162
4179
  return t;
@@ -4176,26 +4193,26 @@ function Ur({
4176
4193
  isStreaming: s,
4177
4194
  onError: a
4178
4195
  }) {
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,
4196
+ const { chatApi: i, fileApi: u } = Me(), { currentThreadId: c } = ot(), { state: l, seed: d, onEvent: m, dispatch: y } = kr(), {
4197
+ threadCheckpoints: I,
4198
+ threadTimeline: f,
4199
+ checkpointIndex: k,
4200
+ isLoadingThread: p,
4201
+ isLoadingCheckpoint: S,
4202
+ isLoadingHistory: A,
4186
4203
  threadStateError: E,
4187
4204
  loadThread: v,
4188
- navigateToCheckpoint: b,
4189
- setCurrentCheckpointId: A,
4190
- returnToLatest: p,
4191
- handleValuesEvent: h,
4205
+ navigateToCheckpoint: w,
4206
+ setCurrentCheckpointId: x,
4207
+ returnToLatest: g,
4208
+ handleValuesEvent: b,
4192
4209
  markSkipNextLoad: P,
4193
4210
  markStreamPendingThread: j,
4194
- resetHistoryState: S
4211
+ resetHistoryState: M
4195
4212
  } = $t({
4196
4213
  api: i,
4197
- fileApi: d,
4198
- seed: f,
4214
+ fileApi: u,
4215
+ seed: d,
4199
4216
  onError: a,
4200
4217
  currentThreadId: c,
4201
4218
  initialThreadId: t,
@@ -4204,33 +4221,33 @@ function Ur({
4204
4221
  autoLoadInitial: o,
4205
4222
  isStreaming: s,
4206
4223
  getMessages: _(() => l.messages, [l.messages])
4207
- }), O = W(null), $ = _(
4224
+ }), O = W(null), F = _(
4208
4225
  (T) => {
4209
4226
  O.current = T;
4210
4227
  },
4211
4228
  []
4212
- ), M = W(null), F = _(
4229
+ ), C = W(null), B = _(
4213
4230
  (T) => {
4214
- M.current = T;
4231
+ C.current = T;
4215
4232
  },
4216
4233
  []
4217
4234
  ), N = Y(() => ({ assemblingMessageId: l.assemblingId ?? null }), [l.assemblingId]), V = _(
4218
4235
  (T, J) => {
4219
- const q = Ut(T, "user");
4220
- return m({
4236
+ const K = Ut(T, "user");
4237
+ return y({
4221
4238
  type: "user_message",
4222
4239
  payload: {
4223
- message: q,
4240
+ message: K,
4224
4241
  editingMessageId: J == null ? void 0 : J.editingMessageId
4225
4242
  }
4226
- }), q;
4243
+ }), K;
4227
4244
  },
4228
- [m]
4245
+ [y]
4229
4246
  ), z = _(async () => {
4230
- O.current ? await O.current() : (f([], {}), S());
4231
- }, [f, S]), L = _(async (T, J, q) => {
4247
+ O.current ? await O.current() : (d([], {}), M());
4248
+ }, [d, M]), L = _(async (T, J, K) => {
4232
4249
  await v(T, J, { clearProgress: !1 });
4233
- }, [v]), K = Y(() => Fn(l.messages), [l.messages]), y = Y(
4250
+ }, [v]), H = Y(() => Bn(l.messages), [l.messages]), h = Y(
4234
4251
  () => ({
4235
4252
  status: l.status,
4236
4253
  threadId: c,
@@ -4241,20 +4258,20 @@ function Ur({
4241
4258
  id: l.lastCheckpointId ?? null,
4242
4259
  namespace: l.lastCheckpointNs ?? null
4243
4260
  },
4244
- checkpoints: k,
4245
- checkpointIndex: w,
4246
- timelineCheckpoints: u,
4261
+ checkpoints: I,
4262
+ checkpointIndex: k,
4263
+ timelineCheckpoints: f,
4247
4264
  metadata: N,
4248
4265
  values: l.values ?? {},
4249
- isLoading: I,
4250
- isLoadingCheckpoint: C,
4251
- isLoadingHistory: x,
4266
+ isLoading: p,
4267
+ isLoadingCheckpoint: S,
4268
+ isLoadingHistory: A,
4252
4269
  error: E,
4253
4270
  loadOlder: async () => {
4254
4271
  },
4255
4272
  // Placeholder
4256
4273
  seedFromSnapshot: (T) => {
4257
- f(T.messages, {
4274
+ d(T.messages, {
4258
4275
  checkpointId: T.checkpointId,
4259
4276
  checkpointNs: T.checkpointNs,
4260
4277
  pendingInterrupt: T.interrupt,
@@ -4262,22 +4279,22 @@ function Ur({
4262
4279
  });
4263
4280
  },
4264
4281
  clearState: z,
4265
- navigateToCheckpoint: b,
4266
- setCurrentCheckpointId: A,
4267
- returnToLatest: p,
4282
+ navigateToCheckpoint: w,
4283
+ setCurrentCheckpointId: x,
4284
+ returnToLatest: g,
4268
4285
  loadThread: L,
4269
4286
  clearThread: z,
4270
- respondToInterrupt: async (T, J, q) => {
4271
- M.current && await M.current(T, J, q);
4287
+ respondToInterrupt: async (T, J, K) => {
4288
+ C.current && await C.current(T, J, K);
4272
4289
  },
4273
- messagePreviews: w.messagePreviews,
4274
- handleValuesEvent: h,
4290
+ messagePreviews: k.messagePreviews,
4291
+ handleValuesEvent: b,
4275
4292
  markSkipNextLoad: P,
4276
4293
  markStreamPendingThread: j,
4277
- resetHistoryState: S,
4294
+ resetHistoryState: M,
4278
4295
  pushUser: V,
4279
- onEvent: g,
4280
- artifacts: K
4296
+ onEvent: m,
4297
+ artifacts: H
4281
4298
  }),
4282
4299
  [
4283
4300
  c,
@@ -4287,38 +4304,38 @@ function Ur({
4287
4304
  l.lastCheckpointId,
4288
4305
  l.lastCheckpointNs,
4289
4306
  l.values,
4307
+ I,
4308
+ f,
4290
4309
  k,
4291
- u,
4292
- w,
4293
4310
  N,
4294
- I,
4295
- C,
4296
- x,
4311
+ p,
4312
+ S,
4313
+ A,
4297
4314
  E,
4298
- f,
4315
+ d,
4299
4316
  z,
4300
- b,
4301
- A,
4302
- p,
4317
+ w,
4318
+ x,
4319
+ g,
4303
4320
  L,
4304
- h,
4321
+ b,
4305
4322
  P,
4306
4323
  j,
4307
4324
  V,
4308
- g,
4309
- K
4325
+ m,
4326
+ H
4310
4327
  ]
4311
4328
  ), U = Y(
4312
4329
  () => ({
4313
- registerClearThread: $,
4314
- registerRespondToInterrupt: F
4330
+ registerClearThread: F,
4331
+ registerRespondToInterrupt: B
4315
4332
  }),
4316
- [$, F]
4333
+ [F, B]
4317
4334
  );
4318
- return /* @__PURE__ */ ie(Vt.Provider, { value: U, children: /* @__PURE__ */ ie(Dt.Provider, { value: y, children: e }) });
4335
+ return /* @__PURE__ */ ie(Vt.Provider, { value: U, children: /* @__PURE__ */ ie(Dt.Provider, { value: h, children: e }) });
4319
4336
  }
4320
- const Ht = Me(null), jr = Me(!1);
4321
- function Fr({
4337
+ const qt = Ce(null), jr = Ce(!1);
4338
+ function Br({
4322
4339
  children: e,
4323
4340
  onError: t,
4324
4341
  onAuthError: n,
@@ -4327,71 +4344,71 @@ function Fr({
4327
4344
  onUpdateEvent: s,
4328
4345
  onCustomEvent: a,
4329
4346
  onMetadataEvent: i,
4330
- onFinish: d,
4347
+ onFinish: u,
4331
4348
  onStreamingChange: c
4332
4349
  }) {
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(
4350
+ 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
4351
  () => ({
4335
- onError: m,
4336
- onAuthError: k,
4337
- onConnectionError: u,
4338
- onMetadataEvent: x,
4339
- onCustomEvent: C,
4340
- onUpdateEvent: I,
4341
- onToolEnd: w,
4352
+ onError: y,
4353
+ onAuthError: I,
4354
+ onConnectionError: f,
4355
+ onMetadataEvent: A,
4356
+ onCustomEvent: S,
4357
+ onUpdateEvent: p,
4358
+ onToolEnd: k,
4342
4359
  onFinish: E
4343
4360
  }),
4344
4361
  [
4345
- m,
4346
- k,
4347
- u,
4348
- x,
4349
- C,
4362
+ y,
4350
4363
  I,
4351
- w,
4364
+ f,
4365
+ A,
4366
+ S,
4367
+ p,
4368
+ k,
4352
4369
  E
4353
4370
  ]
4354
4371
  );
4355
4372
  return /* @__PURE__ */ ie(jr.Provider, { value: !0, children: /* @__PURE__ */ ie(
4356
- Or,
4373
+ Fr,
4357
4374
  {
4358
4375
  api: l,
4359
- streamBaseUrl: g,
4360
- handlers: b,
4376
+ streamBaseUrl: m,
4377
+ handlers: w,
4361
4378
  onStreamingChange: v,
4362
4379
  children: e
4363
4380
  }
4364
4381
  ) });
4365
4382
  }
4366
- function Or({
4383
+ function Fr({
4367
4384
  children: e,
4368
4385
  api: t,
4369
4386
  streamBaseUrl: n,
4370
4387
  handlers: r,
4371
4388
  onStreamingChange: o
4372
4389
  }) {
4373
- const { setCurrentThreadId: s, currentThreadIdRef: a, addThreadFromEvent: i, currentThreadId: d } = ot(), {
4390
+ const { setCurrentThreadId: s, currentThreadIdRef: a, addThreadFromEvent: i, currentThreadId: u } = ot(), {
4374
4391
  interrupt: c,
4375
4392
  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));
4393
+ timelineCheckpoints: d,
4394
+ handleValuesEvent: m,
4395
+ markSkipNextLoad: y,
4396
+ markStreamPendingThread: I,
4397
+ resetHistoryState: f,
4398
+ pushUser: k,
4399
+ onEvent: p,
4400
+ messages: S
4401
+ } = Kt(), { registerClearThread: A, registerRespondToInterrupt: E } = Lr(), v = _(
4402
+ (h) => {
4403
+ i(h), I(h.threadId), a.current !== h.threadId && ((h.created ?? !a.current) && y(h.threadId), s(h.threadId));
4387
4404
  },
4388
- [i, m, k, s, a]
4389
- ), b = pr({
4405
+ [i, y, I, s, a]
4406
+ ), w = pr({
4390
4407
  baseUrl: n,
4391
- onEvent: I,
4392
- onError: (y) => {
4408
+ onEvent: p,
4409
+ onError: (h) => {
4393
4410
  var U;
4394
- (U = r.onError) == null || U.call(r, (y == null ? void 0 : y.message) ?? String(y));
4411
+ (U = r.onError) == null || U.call(r, (h == null ? void 0 : h.message) ?? String(h));
4395
4412
  },
4396
4413
  onAuthError: r.onAuthError,
4397
4414
  onConnectionError: r.onConnectionError,
@@ -4401,122 +4418,122 @@ function Or({
4401
4418
  onCustomEvent: r.onCustomEvent,
4402
4419
  onUpdateEvent: r.onUpdateEvent,
4403
4420
  onToolEnd: r.onToolEnd,
4404
- handleValuesEvent: g
4421
+ handleValuesEvent: m
4405
4422
  });
4406
4423
  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;
4424
+ o == null || o(w.isStreaming);
4425
+ }, [w.isStreaming, o]);
4426
+ const { stream: x, stop: g, clear: b, isStreaming: P, error: j, connected: M, streamedMessages: O, activeMessageId: F } = w;
4410
4427
  X(() => {
4411
- d !== void 0 && h();
4412
- }, [d, h]);
4413
- const M = _(
4414
- async (y, U) => {
4415
- await A(y, U);
4428
+ u !== void 0 && b();
4429
+ }, [u, b]);
4430
+ const C = _(
4431
+ async (h, U) => {
4432
+ await x(h, U);
4416
4433
  },
4417
- [A]
4418
- ), F = W(l);
4434
+ [x]
4435
+ ), B = W(l);
4419
4436
  X(() => {
4420
- F.current = l;
4437
+ B.current = l;
4421
4438
  }, [l]);
4422
4439
  const N = _(
4423
- async (y, U, T) => {
4440
+ async (h, U, T) => {
4424
4441
  var G;
4425
4442
  const J = a.current;
4426
4443
  if (!J)
4427
4444
  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 = {
4445
+ 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
4446
  threadId: J,
4430
4447
  checkpointId: ee,
4431
4448
  checkpointNs: re,
4432
- command: { kind: "resume", value: q },
4449
+ command: { kind: "resume", value: K },
4433
4450
  payload: {
4434
4451
  ...(T == null ? void 0 : T.payload) ?? {},
4435
4452
  creativityLevel: ((G = T == null ? void 0 : T.payload) == null ? void 0 : G.creativityLevel) ?? "medium"
4436
4453
  },
4437
4454
  edit: !1
4438
4455
  };
4439
- M(ue);
4456
+ C(ue);
4440
4457
  },
4441
- [a, M]
4458
+ [a, C]
4442
4459
  );
4443
4460
  X(() => {
4444
4461
  E(N);
4445
4462
  }, [N, E]);
4446
4463
  const V = _(async () => {
4447
- p(), h(), u(), s(null);
4448
- }, [h, u, s, p]);
4464
+ g(), b(), f(), s(null);
4465
+ }, [b, f, s, g]);
4449
4466
  X(() => {
4450
- x(V);
4451
- }, [V, x]);
4467
+ A(V);
4468
+ }, [V, A]);
4452
4469
  const z = _(
4453
- async (y, U) => {
4454
- P && p();
4470
+ async (h, U) => {
4471
+ P && g();
4455
4472
  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;
4473
+ 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
4474
  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;
4475
+ const ue = !!(re && re.length), G = !!(h.contentParts && h.contentParts.length > 0);
4476
+ if (!T && !q && K.length === 0 && !ue && !G) return;
4460
4477
  if (!T) {
4461
4478
  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);
4479
+ T = `${ye}${he}`, y(T), s(T);
4463
4480
  }
4464
4481
  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;
4482
+ h.contentParts && h.contentParts.length > 0 && (te = h.contentParts);
4483
+ const { contentParts: ke, filesInfo: Q } = te ? { contentParts: te, filesInfo: [] } : await or(K), Z = [...ke];
4484
+ q && Z.push({ type: "text", text: J });
4485
+ const ge = h == null ? void 0 : h.originalMessageId, je = !!(h != null && h.edit && ge), Be = !ue && Z.length > 0;
4469
4486
  let me = null;
4470
- if (Fe) {
4487
+ if (Be) {
4471
4488
  const ye = je ? ge : `msg-${Date.now()}`;
4472
4489
  me = Ut({
4473
4490
  id: ye,
4474
4491
  role: "user",
4475
4492
  content: Z,
4476
4493
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4477
- }, "user"), je ? w(me, { editingMessageId: ge }) : w(me);
4494
+ }, "user"), je ? k(me, { editingMessageId: ge }) : k(me);
4478
4495
  }
4479
4496
  const Ie = ue ? re : me ? [me] : [], oe = {
4480
4497
  ...ee,
4481
4498
  ...Q.length ? { files_info: Q } : {}
4482
4499
  };
4483
4500
  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)
4501
+ const Pe = (h == null ? void 0 : h.checkpointId) ?? l.id ?? void 0;
4502
+ if (h != null && h.edit && !Pe)
4486
4503
  throw new Error(
4487
4504
  `[streaming] Missing checkpointId for edit submit. threadId=${T ?? "null"}`
4488
4505
  );
4489
- const xe = {
4506
+ const Ae = {
4490
4507
  threadId: T,
4491
- content: y == null ? void 0 : y.text,
4508
+ content: h == null ? void 0 : h.text,
4492
4509
  payload: oe,
4493
- config: y == null ? void 0 : y.config,
4510
+ config: h == null ? void 0 : h.config,
4494
4511
  checkpointId: Pe,
4495
- command: y == null ? void 0 : y.command,
4496
- edit: y == null ? void 0 : y.edit
4512
+ command: h == null ? void 0 : h.command,
4513
+ edit: h == null ? void 0 : h.edit
4497
4514
  };
4498
- return M(xe, U);
4515
+ return C(Ae, U);
4499
4516
  },
4500
- [l, a, P, m, w, M, p, f]
4501
- ), L = Y(() => C, [C]), K = Y(
4517
+ [l, a, P, y, k, C, g, d]
4518
+ ), L = Y(() => S, [S]), H = Y(
4502
4519
  () => ({
4503
4520
  isStreaming: P,
4504
4521
  error: j,
4505
- connectionState: j ? "error" : P ? S ? "connected" : "connecting" : "idle",
4522
+ connectionState: j ? "error" : P ? M ? "connected" : "connecting" : "idle",
4506
4523
  messages: L,
4507
- activeMessageId: $,
4524
+ activeMessageId: F,
4508
4525
  submit: z,
4509
- stop: p,
4526
+ stop: g,
4510
4527
  interrupt: c,
4511
4528
  resume: () => Promise.resolve(),
4512
- goto: (y, U) => Promise.resolve(),
4529
+ goto: (h, U) => Promise.resolve(),
4513
4530
  clearError: () => {
4514
4531
  }
4515
4532
  // TODO: Implement error clearing
4516
4533
  }),
4517
- [P, j, z, p, c, S, L]
4534
+ [P, j, z, g, c, M, L]
4518
4535
  );
4519
- return /* @__PURE__ */ ie(Ht.Provider, { value: K, children: e });
4536
+ return /* @__PURE__ */ ie(qt.Provider, { value: H, children: e });
4520
4537
  }
4521
4538
  function fe(e) {
4522
4539
  const t = W(e);
@@ -4528,8 +4545,8 @@ function fe(e) {
4528
4545
  return r(...n);
4529
4546
  }, []);
4530
4547
  }
4531
- function Br(e) {
4532
- return Ue(Ht);
4548
+ function Or(e) {
4549
+ return Ue(qt);
4533
4550
  }
4534
4551
  function bt(e) {
4535
4552
  return typeof e == "object" && e !== null;
@@ -4569,41 +4586,41 @@ function po({
4569
4586
  autoLoadInitial: s = !0,
4570
4587
  onConnectionError: a,
4571
4588
  onError: i,
4572
- onAuthError: d,
4589
+ onAuthError: u,
4573
4590
  onThreadChange: c,
4574
4591
  onToolEnd: l,
4575
- onUpdateEvent: f,
4576
- onCustomEvent: g,
4577
- onMetadataEvent: m,
4578
- onFinish: k
4592
+ onUpdateEvent: d,
4593
+ onCustomEvent: m,
4594
+ onMetadataEvent: y,
4595
+ onFinish: I
4579
4596
  }) {
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(
4597
+ 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
4598
  () => ({
4582
- onError: C,
4583
- onAuthError: x,
4599
+ onError: S,
4600
+ onAuthError: A,
4584
4601
  onConnectionError: E,
4585
- onToolEnd: b,
4586
- onUpdateEvent: A,
4587
- onCustomEvent: p,
4588
- onMetadataEvent: h,
4602
+ onToolEnd: w,
4603
+ onUpdateEvent: x,
4604
+ onCustomEvent: g,
4605
+ onMetadataEvent: b,
4589
4606
  onFinish: P
4590
4607
  }),
4591
4608
  [
4592
- C,
4593
- x,
4609
+ S,
4610
+ A,
4594
4611
  E,
4612
+ w,
4613
+ x,
4614
+ g,
4595
4615
  b,
4596
- A,
4597
- p,
4598
- h,
4599
4616
  P
4600
4617
  ]
4601
4618
  );
4602
- return /* @__PURE__ */ ie(nr, { apiConfig: u, children: /* @__PURE__ */ ie(
4619
+ return /* @__PURE__ */ ie(nr, { apiConfig: f, children: /* @__PURE__ */ ie(
4603
4620
  mr,
4604
4621
  {
4605
4622
  initialThreadId: n,
4606
- onError: C,
4623
+ onError: S,
4607
4624
  onThreadChange: v,
4608
4625
  children: /* @__PURE__ */ ie(
4609
4626
  Ur,
@@ -4612,13 +4629,13 @@ function po({
4612
4629
  initialCheckpointId: r,
4613
4630
  initialCheckpointNs: o,
4614
4631
  autoLoadInitial: s,
4615
- onError: C,
4616
- isStreaming: w,
4632
+ onError: S,
4633
+ isStreaming: k,
4617
4634
  children: /* @__PURE__ */ ie(
4618
- Fr,
4635
+ Br,
4619
4636
  {
4620
4637
  ...j,
4621
- onStreamingChange: I,
4638
+ onStreamingChange: p,
4622
4639
  children: e
4623
4640
  }
4624
4641
  )
@@ -4635,9 +4652,9 @@ function pe(e) {
4635
4652
  return r(...n);
4636
4653
  }, []);
4637
4654
  }
4638
- const qr = 1, Hr = 1e6;
4655
+ const Kr = 1, qr = 1e6;
4639
4656
  let We = 0;
4640
- function Kr() {
4657
+ function Hr() {
4641
4658
  return We = (We + 1) % Number.MAX_SAFE_INTEGER, We.toString();
4642
4659
  }
4643
4660
  const Je = /* @__PURE__ */ new Map(), wt = (e) => {
@@ -4648,14 +4665,14 @@ const Je = /* @__PURE__ */ new Map(), wt = (e) => {
4648
4665
  type: "REMOVE_TOAST",
4649
4666
  toastId: e
4650
4667
  });
4651
- }, Hr);
4668
+ }, qr);
4652
4669
  Je.set(e, t);
4653
4670
  }, Gr = (e, t) => {
4654
4671
  switch (t.type) {
4655
4672
  case "ADD_TOAST":
4656
4673
  return {
4657
4674
  ...e,
4658
- toasts: [t.toast, ...e.toasts].slice(0, qr)
4675
+ toasts: [t.toast, ...e.toasts].slice(0, Kr)
4659
4676
  };
4660
4677
  case "UPDATE_TOAST":
4661
4678
  return {
@@ -4695,7 +4712,7 @@ function Le(e) {
4695
4712
  });
4696
4713
  }
4697
4714
  function Wr({ ...e }) {
4698
- const t = Kr(), n = (o) => Le({
4715
+ const t = Hr(), n = (o) => Le({
4699
4716
  type: "UPDATE_TOAST",
4700
4717
  toast: { ...o, id: t }
4701
4718
  }), r = () => Le({ type: "DISMISS_TOAST", toastId: t });
@@ -4727,75 +4744,75 @@ function Jr() {
4727
4744
  };
4728
4745
  }
4729
4746
  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;
4747
+ const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = Me(), { toast: o } = Jr(), [s, a] = $({}), [i, u] = $(null), [c, l] = $(!1), d = _(() => {
4748
+ l(!1), u(null);
4749
+ }, []), m = _((I) => {
4750
+ u(I), l(!0);
4751
+ }, []), y = _(
4752
+ async (I, f, k) => {
4753
+ var p, S;
4737
4754
  if (!t) {
4738
- k.preventDefault();
4755
+ I.preventDefault();
4739
4756
  return;
4740
4757
  }
4741
- if (s[w]) {
4742
- k.preventDefault();
4758
+ if (s[k]) {
4759
+ I.preventDefault();
4743
4760
  return;
4744
4761
  }
4745
4762
  try {
4746
- const x = String(u.url ?? ""), E = x.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
4763
+ const A = String(f.url ?? ""), E = A.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
4747
4764
  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 });
4765
+ I.preventDefault();
4766
+ const v = E[1], w = f.name || `file_${v}`, x = f.mimeType || "application/octet-stream";
4767
+ m({ id: v, name: w, mimeType: x });
4751
4768
  return;
4752
4769
  }
4753
- if (x.startsWith("data:")) {
4754
- k.preventDefault(), a((b) => ({ ...b, [w]: !0 }));
4770
+ if (A.startsWith("data:")) {
4771
+ I.preventDefault(), a((w) => ({ ...w, [k]: !0 }));
4755
4772
  const v = o({ title: "Fetching file...", description: "", open: !0 });
4756
4773
  try {
4757
- const b = await r.listFiles(n ?? void 0);
4758
- if (!b || !Array.isArray(b))
4774
+ const w = await r.listFiles(n ?? void 0);
4775
+ if (!w || !Array.isArray(w))
4759
4776
  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)
4777
+ 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);
4778
+ if (!(x != null && x.id))
4779
+ throw new Error(`File "${f.name}" is not yet available on the server`);
4780
+ if (!x.id || !x.filename)
4764
4781
  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, {
4782
+ m({
4783
+ id: x.id,
4784
+ name: f.name || x.filename || `file_${x.id}`,
4785
+ mimeType: f.mimeType || x.mime_type || "application/octet-stream"
4786
+ }), (p = v.update) == null || p.call(v, {
4770
4787
  id: v.id,
4771
4788
  title: "Success",
4772
- description: `Opened ${u.name}`,
4789
+ description: `Opened ${f.name}`,
4773
4790
  open: !0
4774
4791
  });
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({
4792
+ } catch (w) {
4793
+ console.error("Failed to fetch server file:", w);
4794
+ const x = w instanceof Error ? w.message : "Unknown error occurred";
4795
+ (S = v.update) == null || S.call(v, { id: v.id, title: "Failed", description: x }), o({
4779
4796
  title: "Failed to fetch file",
4780
- description: A,
4797
+ description: x,
4781
4798
  open: !0
4782
4799
  });
4783
4800
  } finally {
4784
- a((b) => ({ ...b, [w]: !1 }));
4801
+ a((w) => ({ ...w, [k]: !1 }));
4785
4802
  }
4786
4803
  }
4787
- } catch (x) {
4788
- console.error("File click error:", x), a((E) => ({ ...E, [w]: !1 }));
4804
+ } catch (A) {
4805
+ console.error("File click error:", A), a((E) => ({ ...E, [k]: !1 }));
4789
4806
  }
4790
4807
  },
4791
- [t, s, o, n, g]
4808
+ [t, s, o, n, m]
4792
4809
  );
4793
4810
  return {
4794
4811
  uploadingFiles: s,
4795
- handleFileClick: m,
4812
+ handleFileClick: y,
4796
4813
  fileViewerOpen: c,
4797
4814
  currentFileInfo: i,
4798
- closeFileViewer: f
4815
+ closeFileViewer: d
4799
4816
  };
4800
4817
  }
4801
4818
  function mo(e) {
@@ -4808,20 +4825,20 @@ function mo(e) {
4808
4825
  toolMeta: ar(t),
4809
4826
  imageParts: n.filter((r) => r.type === "image_url"),
4810
4827
  fileParts: n.filter((r) => r.type === "file"),
4811
- toolRaw: On(n),
4828
+ toolRaw: Fn(n),
4812
4829
  isToolStreaming: !!t.toolStreaming
4813
4830
  };
4814
4831
  }, [e]);
4815
4832
  }
4816
- const vt = "data:";
4833
+ const kt = "data:";
4817
4834
  function Xr(e) {
4818
4835
  if (!e) return [];
4819
4836
  const t = [], n = e.split(/\r?\n/);
4820
4837
  for (const r of n) {
4821
4838
  const o = r.trim();
4822
- if (!o || !o.startsWith(vt))
4839
+ if (!o || !o.startsWith(kt))
4823
4840
  continue;
4824
- const s = o.slice(vt.length).trim();
4841
+ const s = o.slice(kt.length).trim();
4825
4842
  if (!s || s.toLowerCase() === "[done]")
4826
4843
  continue;
4827
4844
  const a = tt(s);
@@ -4840,16 +4857,16 @@ function Qr(e) {
4840
4857
  function yo(e) {
4841
4858
  return Y(() => {
4842
4859
  const t = e.content.filter(
4843
- (d) => d.type === "text"
4860
+ (u) => u.type === "text"
4844
4861
  );
4845
4862
  if (!t.length)
4846
4863
  return null;
4847
4864
  let r = t.flatMap(
4848
- (d) => Xr(d.text ?? "")
4865
+ (u) => Xr(u.text ?? "")
4849
4866
  );
4850
4867
  if (!r.length) {
4851
- const d = t.map((l) => l.text ?? "").join(`
4852
- `), c = tt(d);
4868
+ const u = t.map((l) => l.text ?? "").join(`
4869
+ `), c = tt(u);
4853
4870
  c && typeof c == "object" && (r = [c]);
4854
4871
  }
4855
4872
  if (!r.length)
@@ -4871,24 +4888,24 @@ function yo(e) {
4871
4888
  }, [e]);
4872
4889
  }
4873
4890
  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 || {
4891
+ var M, O;
4892
+ 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
4893
  currentThreadId: null,
4877
4894
  setCurrentThreadId: () => {
4878
4895
  },
4879
4896
  actions: {}
4880
- }, c = !!t && t !== a, [l, f] = B([]), g = _((O) => {
4881
- f(O);
4897
+ }, c = !!t && t !== a, [l, d] = $([]), m = _((F) => {
4898
+ d(F);
4882
4899
  }, []), {
4883
- isLoadingThread: m,
4884
- threadStateError: k,
4885
- threadCheckpoints: u,
4886
- isLoadingHistory: w,
4887
- loadThread: I
4900
+ isLoadingThread: y,
4901
+ threadStateError: I,
4902
+ threadCheckpoints: f,
4903
+ isLoadingHistory: k,
4904
+ loadThread: p
4888
4905
  } = $t({
4889
- api: Ce().chatApi,
4890
- fileApi: Ce().fileApi,
4891
- seed: g,
4906
+ api: Me().chatApi,
4907
+ fileApi: Me().fileApi,
4908
+ seed: m,
4892
4909
  currentThreadId: c ? t : null,
4893
4910
  initialThreadId: c ? t : null,
4894
4911
  isStreaming: !1,
@@ -4898,20 +4915,20 @@ function Yr(e) {
4898
4915
  X(() => {
4899
4916
  !c && !n && a && (o != null && o.loadThread) && o.loadThread(a);
4900
4917
  }, [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;
4918
+ const S = Y(() => {
4919
+ var F;
4920
+ return ((F = f[0]) == null ? void 0 : F.values) || {};
4921
+ }, [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
4922
  return {
4906
4923
  // UNIFIED: Single thread ID concept
4907
4924
  threadId: E,
4908
4925
  status: v,
4909
- messages: b,
4910
- isLoading: A,
4911
- isHistoryLoading: p,
4926
+ messages: w,
4927
+ isLoading: x,
4928
+ isHistoryLoading: g,
4912
4929
  error: j,
4913
4930
  // Values & Metadata
4914
- values: h,
4931
+ values: b,
4915
4932
  taskMessagesByScope: P,
4916
4933
  metadata: c ? {} : o == null ? void 0 : o.metadata,
4917
4934
  // Actions & State relating to Global/Active Thread only
@@ -4921,9 +4938,9 @@ function Yr(e) {
4921
4938
  returnToLatest: c ? async () => {
4922
4939
  } : (o == null ? void 0 : o.returnToLatest) || (async () => {
4923
4940
  }),
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: {} },
4941
+ checkpoint: c ? f[0] ? { id: f[0].checkpointId, namespace: f[0].checkpointNs } : null : (o == null ? void 0 : o.checkpoint) || null,
4942
+ checkpoints: c ? f : (o == null ? void 0 : o.checkpoints) || [],
4943
+ checkpointIndex: c ? A : (o == null ? void 0 : o.checkpointIndex) || { timeline: [], messagePreviews: {} },
4927
4944
  interrupt: c ? null : (o == null ? void 0 : o.interrupt) || null,
4928
4945
  respondToInterrupt: c ? async () => {
4929
4946
  } : (o == null ? void 0 : o.respondToInterrupt) || (async () => {
@@ -4931,9 +4948,9 @@ function Yr(e) {
4931
4948
  // Streaming Status
4932
4949
  // Even in standalone mode, allow streaming state/stop if a stream context exists.
4933
4950
  isStreaming: (s == null ? void 0 : s.isStreaming) || !1,
4934
- activeMessageId: (s == null ? void 0 : s.activeMessageId) || null,
4951
+ activeMessageId: c ? null : ((M = o == null ? void 0 : o.metadata) == null ? void 0 : M.assemblingMessageId) || (s == null ? void 0 : s.activeMessageId) || null,
4935
4952
  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,
4953
+ streamingAssistantId: !c && (s != null && s.isStreaming) && ((O = o == null ? void 0 : o.metadata) != null && O.assemblingMessageId) ? o.metadata.assemblingMessageId : null,
4937
4954
  // Actions
4938
4955
  submit: (s == null ? void 0 : s.submit) || (async () => {
4939
4956
  }),
@@ -4944,16 +4961,16 @@ function Yr(e) {
4944
4961
  }),
4945
4962
  setCurrentThreadId: i,
4946
4963
  loadHistory: c ? async () => {
4947
- t && await I(t);
4964
+ t && await p(t);
4948
4965
  } : async () => {
4949
4966
  },
4950
4967
  onEvent: c ? () => {
4951
4968
  } : (o == null ? void 0 : o.onEvent) || (() => {
4952
4969
  }),
4953
4970
  // 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,
4971
+ createThread: u == null ? void 0 : u.createThread,
4972
+ deleteThread: u == null ? void 0 : u.deleteThread,
4973
+ renameThread: u == null ? void 0 : u.renameThread,
4957
4974
  threads: (r == null ? void 0 : r.threads) || [],
4958
4975
  isThreadsLoading: (r == null ? void 0 : r.isLoading) || !1
4959
4976
  };
@@ -4967,42 +4984,42 @@ function ho({
4967
4984
  onExcelUploadSuccess: s,
4968
4985
  onError: a,
4969
4986
  enableMessageEditing: i,
4970
- messages: d,
4987
+ messages: u,
4971
4988
  setPendingAssistantResponse: c,
4972
4989
  project: l,
4973
- onEvent: f,
4974
- threadId: g,
4975
- clearComposerOnSend: m = !0
4990
+ onEvent: d,
4991
+ threadId: m,
4992
+ clearComposerOnSend: y = !0
4976
4993
  }) {
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);
4994
+ 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
4995
  X(() => {
4979
- if (!u)
4980
- if (g) {
4981
- const y = localStorage.getItem(Ge(g));
4982
- P(y || "");
4996
+ if (!f)
4997
+ if (m) {
4998
+ const h = localStorage.getItem(Ge(m));
4999
+ P(h || "");
4983
5000
  } else
4984
5001
  P("");
4985
- }, [g, u]);
4986
- const O = _((y) => {
4987
- P(y), !u && g && localStorage.setItem(Ge(g), y);
4988
- }, [g, u]);
5002
+ }, [m, f]);
5003
+ const O = _((h) => {
5004
+ P(h), !f && m && localStorage.setItem(Ge(m), h);
5005
+ }, [m, f]);
4989
5006
  X(() => {
4990
- j.current = h;
4991
- }, [h]), X(() => {
4992
- if (!u) {
4993
- S.current = null;
5007
+ j.current = b;
5008
+ }, [b]), X(() => {
5009
+ if (!f) {
5010
+ M.current = null;
4994
5011
  return;
4995
5012
  }
4996
- S.current === null && (S.current = j.current), O(I ?? "");
4997
- }, [I, u, O]);
4998
- const $ = _(
4999
- (y) => {
5000
- O(y);
5013
+ M.current === null && (M.current = j.current), O(p ?? "");
5014
+ }, [p, f, O]);
5015
+ const F = _(
5016
+ (h) => {
5017
+ O(h);
5001
5018
  },
5002
5019
  [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))
5020
+ ), C = async (h, U) => {
5021
+ const T = Array.isArray(U) ? { files: U } : U ?? {}, J = T.files ?? [], K = T.contentParts ?? [], q = h.trim();
5022
+ if (!(!q && J.length === 0 && K.length === 0))
5006
5023
  try {
5007
5024
  const ee = J.map(async (Q) => {
5008
5025
  try {
@@ -5023,73 +5040,73 @@ function ho({
5023
5040
  name: Q.filename,
5024
5041
  size: Q.size
5025
5042
  };
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;
5043
+ }), 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
5044
  await e(
5028
5045
  {
5029
- text: H || "",
5046
+ text: q || "",
5030
5047
  contentParts: G,
5031
5048
  attachments: J,
5032
5049
  payload: t.payload,
5033
- edit: !!u,
5050
+ edit: !!f,
5034
5051
  checkpointId: te,
5035
- checkpointNs: ve,
5052
+ checkpointNs: ke,
5036
5053
  project: l ?? void 0,
5037
- originalMessageId: u ?? void 0,
5054
+ originalMessageId: f ?? void 0,
5038
5055
  config: t.config
5039
5056
  },
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);
5057
+ d ? { onEvent: d } : void 0
5058
+ ), o == null || o(q), c(!0), y && (m && localStorage.removeItem(Ge(m)), O("")), w(null), k(null), S(""), E(null);
5042
5059
  } catch (ee) {
5043
5060
  const re = (ee == null ? void 0 : ee.message) || "Failed to send message";
5044
- b(re), a == null || a(re), c(!1);
5061
+ w(re), a == null || a(re), c(!1);
5045
5062
  }
5046
- }, F = (y, U) => {
5047
- U || M(y, { files: [] });
5063
+ }, B = (h, U) => {
5064
+ U || C(h, { files: [] });
5048
5065
  }, N = _(
5049
- async (y) => {
5066
+ async (h) => {
5050
5067
  await e(
5051
5068
  {
5052
- attachments: [y],
5069
+ attachments: [h],
5053
5070
  payload: t.payload,
5054
5071
  checkpointId: n ?? void 0,
5055
5072
  checkpointNs: r ?? void 0,
5056
5073
  project: l ?? void 0,
5057
5074
  config: t.config
5058
5075
  },
5059
- f ? { onEvent: f } : void 0
5060
- ), s == null || s({ file: y });
5076
+ d ? { onEvent: d } : void 0
5077
+ ), s == null || s({ file: h });
5061
5078
  },
5062
5079
  [n, r, t, s, e]
5063
5080
  ), V = _(
5064
- (y, U, T) => {
5065
- i && (S.current = h, w(y), C(U), E({
5081
+ (h, U, T) => {
5082
+ i && (M.current = b, k(h), S(U), E({
5066
5083
  checkpointId: (T == null ? void 0 : T.checkpointId) ?? null,
5067
5084
  checkpointNs: (T == null ? void 0 : T.checkpointNs) ?? null
5068
- }), b(null));
5085
+ }), w(null));
5069
5086
  },
5070
- [h, i]
5087
+ [b, i]
5071
5088
  ), 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) => {
5089
+ k(null), S(""), E(null), w(null);
5090
+ const h = M.current;
5091
+ h !== null && P(h), M.current = null;
5092
+ }, []), L = _((h) => {
5076
5093
  let U = null;
5077
- for (let H = y - 1; H >= 0; H--)
5078
- if (d[H].role === "user") {
5079
- U = d[H];
5094
+ for (let q = h - 1; q >= 0; q--)
5095
+ if (u[q].role === "user") {
5096
+ U = u[q];
5080
5097
  break;
5081
5098
  }
5082
5099
  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("") || (() => {
5100
+ 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
5101
  try {
5085
5102
  return JSON.stringify(T, null, 2);
5086
5103
  } catch {
5087
5104
  return String(T);
5088
5105
  }
5089
5106
  })();
5090
- q && e(
5107
+ K && e(
5091
5108
  {
5092
- text: q,
5109
+ text: K,
5093
5110
  payload: t.payload,
5094
5111
  checkpointId: n ?? void 0,
5095
5112
  checkpointNs: r ?? void 0,
@@ -5097,25 +5114,25 @@ function ho({
5097
5114
  originalMessageId: U.id,
5098
5115
  config: t.config
5099
5116
  },
5100
- f ? { onEvent: f } : void 0
5117
+ d ? { onEvent: d } : void 0
5101
5118
  );
5102
- }, [d, e, n, r, t]);
5119
+ }, [u, e, n, r, t]);
5103
5120
  return {
5104
- editingMessageId: u,
5105
- editingInitialValue: I,
5121
+ editingMessageId: f,
5122
+ editingInitialValue: p,
5106
5123
  inputError: v,
5107
- setInputError: b,
5108
- dismissError: A,
5109
- setDismissError: p,
5110
- composerValue: h,
5111
- handleComposerChange: $,
5112
- handleSendMessage: M,
5113
- handleQuickPrompt: F,
5124
+ setInputError: w,
5125
+ dismissError: x,
5126
+ setDismissError: g,
5127
+ composerValue: b,
5128
+ handleComposerChange: F,
5129
+ handleSendMessage: C,
5130
+ handleQuickPrompt: B,
5114
5131
  handleExcelUpload: N,
5115
5132
  startEditing: V,
5116
5133
  cancelEditing: z,
5117
5134
  handleRegenerateCb: L,
5118
- displayMessages: k
5135
+ displayMessages: I
5119
5136
  };
5120
5137
  }
5121
5138
  function bo(e) {
@@ -5123,7 +5140,7 @@ function bo(e) {
5123
5140
  textContent: Ln(e),
5124
5141
  imageParts: Un(e),
5125
5142
  fileParts: jn(e),
5126
- toolCalls: Ct(e),
5143
+ toolCalls: Mt(e),
5127
5144
  contentParts: e.content
5128
5145
  } : {
5129
5146
  textContent: "",
@@ -5134,7 +5151,7 @@ function bo(e) {
5134
5151
  }, [e]);
5135
5152
  }
5136
5153
  function wo(e, t, n) {
5137
- const [r, o] = B(e), s = W(e), a = W(null);
5154
+ const [r, o] = $(e), s = W(e), a = W(null);
5138
5155
  return X(() => {
5139
5156
  s.current = e;
5140
5157
  const i = () => {
@@ -5165,21 +5182,21 @@ export {
5165
5182
  Pt as getChatToken,
5166
5183
  uo as getMessageAttemptInfo,
5167
5184
  ao as getToolCallArtifacts,
5168
- Hn as getToolCalls,
5185
+ qn as getToolCalls,
5169
5186
  so as hasContent,
5170
5187
  mt as hydrateHistorySnapshots,
5171
- Mt as isFileLike,
5188
+ Ct as isFileLike,
5172
5189
  Nn as looksLikeMarkdown,
5173
5190
  lo as messageSignature,
5174
5191
  io as normalizeInterruptId,
5175
5192
  _t as onChatTokenChanged,
5176
5193
  tt as parseJsonSafe,
5177
5194
  Et as pretty,
5178
- Cr as refreshHistoryFileUrls,
5195
+ Mr as refreshHistoryFileUrls,
5179
5196
  Ve as sanitizeForDisplay,
5180
- ke as setChatToken,
5181
- On as stringifyTool,
5182
- Ce as useApi,
5197
+ ve as setChatToken,
5198
+ Fn as stringifyTool,
5199
+ Me as useApi,
5183
5200
  ho as useChatController,
5184
5201
  Yr as useChatSession,
5185
5202
  go as useFilePreview,
@@ -5188,7 +5205,7 @@ export {
5188
5205
  pr as useStream,
5189
5206
  wo as useStreamingMarkdownBuffer,
5190
5207
  $t as useThreadHistoryState,
5191
- qt as useThreadState,
5208
+ Kt as useThreadState,
5192
5209
  Lr as useThreadStateUpdater,
5193
5210
  ot as useThreads,
5194
5211
  gr as useThreadsState,