@teodorruskvi/chat-core 0.1.31 → 0.1.33

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,10 +1,10 @@
1
1
  var Ln = Object.defineProperty;
2
2
  var zn = (e, t, n) => t in e ? Ln(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
- var $t = (e, t, n) => zn(e, typeof t != "symbol" ? t + "" : t, n);
3
+ var Bt = (e, t, n) => zn(e, typeof t != "symbol" ? t + "" : t, n);
4
4
  import { jsx as Ce } from "react/jsx-runtime";
5
- import * as Bt from "react";
6
- import { createContext as We, useContext as ot, useState as W, useRef as H, useEffect as se, useCallback as E, useMemo as de, useReducer as Un } from "react";
7
- import Fn, { isCancel as Dt } from "axios";
5
+ import * as Dt from "react";
6
+ import { createContext as Ge, useContext as ot, useState as q, useRef as V, useEffect as oe, useCallback as C, useMemo as pe, useReducer as Fn } from "react";
7
+ import Un, { isCancel as St } from "axios";
8
8
  function nn(e) {
9
9
  var t, n, r = "";
10
10
  if (typeof e == "string" || typeof e == "number") r += e;
@@ -18,14 +18,14 @@ function jn() {
18
18
  for (var e, t, n = 0, r = "", s = arguments.length; n < s; n++) (e = arguments[n]) && (t = nn(e)) && (r && (r += " "), r += t);
19
19
  return r;
20
20
  }
21
- const Lt = "-", On = (e) => {
21
+ const zt = "-", On = (e) => {
22
22
  const t = Bn(e), {
23
23
  conflictingClassGroups: n,
24
24
  conflictingClassGroupModifiers: r
25
25
  } = e;
26
26
  return {
27
27
  getClassGroupId: (a) => {
28
- const i = a.split(Lt);
28
+ const i = a.split(zt);
29
29
  return i[0] === "" && i.length !== 1 && i.shift(), rn(i, t) || $n(a);
30
30
  },
31
31
  getConflictingClassGroupIds: (a, i) => {
@@ -42,7 +42,7 @@ const Lt = "-", On = (e) => {
42
42
  return s;
43
43
  if (t.validators.length === 0)
44
44
  return;
45
- const o = e.join(Lt);
45
+ const o = e.join(zt);
46
46
  return (a = t.validators.find(({
47
47
  validator: i
48
48
  }) => i(o))) == null ? void 0 : a.classGroupId;
@@ -61,9 +61,9 @@ const Lt = "-", On = (e) => {
61
61
  validators: []
62
62
  };
63
63
  return Vn(Object.entries(e.classGroups), n).forEach(([o, a]) => {
64
- Rt(a, r, o, t);
64
+ Nt(a, r, o, t);
65
65
  }), r;
66
- }, Rt = (e, t, n, r) => {
66
+ }, Nt = (e, t, n, r) => {
67
67
  e.forEach((s) => {
68
68
  if (typeof s == "string") {
69
69
  const o = s === "" ? t : Kt(t, s);
@@ -72,7 +72,7 @@ const Lt = "-", On = (e) => {
72
72
  }
73
73
  if (typeof s == "function") {
74
74
  if (Dn(s)) {
75
- Rt(s(r), t, n, r);
75
+ Nt(s(r), t, n, r);
76
76
  return;
77
77
  }
78
78
  t.validators.push({
@@ -82,12 +82,12 @@ const Lt = "-", On = (e) => {
82
82
  return;
83
83
  }
84
84
  Object.entries(s).forEach(([o, a]) => {
85
- Rt(a, Kt(t, o), n, r);
85
+ Nt(a, Kt(t, o), n, r);
86
86
  });
87
87
  });
88
88
  }, Kt = (e, t) => {
89
89
  let n = e;
90
- return t.split(Lt).forEach((r) => {
90
+ return t.split(zt).forEach((r) => {
91
91
  n.nextPart.has(r) || n.nextPart.set(r, {
92
92
  nextPart: /* @__PURE__ */ new Map(),
93
93
  validators: []
@@ -126,27 +126,27 @@ const Lt = "-", On = (e) => {
126
126
  experimentalParseClassName: n
127
127
  } = e, r = t.length === 1, s = t[0], o = t.length, a = (i) => {
128
128
  const f = [];
129
- let l = 0, c = 0, d;
129
+ let l = 0, c = 0, u;
130
130
  for (let y = 0; y < i.length; y++) {
131
- let I = i[y];
131
+ let v = i[y];
132
132
  if (l === 0) {
133
- if (I === s && (r || i.slice(y, y + o) === t)) {
133
+ if (v === s && (r || i.slice(y, y + o) === t)) {
134
134
  f.push(i.slice(c, y)), c = y + o;
135
135
  continue;
136
136
  }
137
- if (I === "/") {
138
- d = y;
137
+ if (v === "/") {
138
+ u = y;
139
139
  continue;
140
140
  }
141
141
  }
142
- I === "[" ? l++ : I === "]" && l--;
142
+ v === "[" ? l++ : v === "]" && l--;
143
143
  }
144
- const g = f.length === 0 ? i : i.substring(c), h = g.startsWith(sn), k = h ? g.substring(1) : g, m = d && d > c ? d - c : void 0;
144
+ const g = f.length === 0 ? i : i.substring(c), m = g.startsWith(sn), k = m ? g.substring(1) : g, p = u && u > c ? u - c : void 0;
145
145
  return {
146
146
  modifiers: f,
147
- hasImportantModifier: h,
147
+ hasImportantModifier: m,
148
148
  baseClassName: k,
149
- maybePostfixModifierPosition: m
149
+ maybePostfixModifierPosition: p
150
150
  };
151
151
  };
152
152
  return n ? (i) => n({
@@ -175,30 +175,30 @@ const Lt = "-", On = (e) => {
175
175
  for (let f = a.length - 1; f >= 0; f -= 1) {
176
176
  const l = a[f], {
177
177
  modifiers: c,
178
- hasImportantModifier: d,
178
+ hasImportantModifier: u,
179
179
  baseClassName: g,
180
- maybePostfixModifierPosition: h
180
+ maybePostfixModifierPosition: m
181
181
  } = n(l);
182
- let k = !!h, m = r(k ? g.substring(0, h) : g);
183
- if (!m) {
182
+ let k = !!m, p = r(k ? g.substring(0, m) : g);
183
+ if (!p) {
184
184
  if (!k) {
185
185
  i = l + (i.length > 0 ? " " + i : i);
186
186
  continue;
187
187
  }
188
- if (m = r(g), !m) {
188
+ if (p = r(g), !p) {
189
189
  i = l + (i.length > 0 ? " " + i : i);
190
190
  continue;
191
191
  }
192
192
  k = !1;
193
193
  }
194
- const y = qn(c).join(":"), I = d ? y + sn : y, S = I + m;
195
- if (o.includes(S))
194
+ const y = qn(c).join(":"), v = u ? y + sn : y, A = v + p;
195
+ if (o.includes(A))
196
196
  continue;
197
- o.push(S);
198
- const C = s(m, k);
199
- for (let L = 0; L < C.length; ++L) {
200
- const z = C[L];
201
- o.push(I + z);
197
+ o.push(A);
198
+ const x = s(p, k);
199
+ for (let L = 0; L < x.length; ++L) {
200
+ const z = x[L];
201
+ o.push(v + z);
202
202
  }
203
203
  i = l + (i.length > 0 ? " " + i : i);
204
204
  }
@@ -221,7 +221,7 @@ const on = (e) => {
221
221
  function Qn(e, ...t) {
222
222
  let n, r, s, o = a;
223
223
  function a(f) {
224
- const l = t.reduce((c, d) => d(c), e());
224
+ const l = t.reduce((c, u) => u(c), e());
225
225
  return n = Wn(l), r = n.cache.get, s = n.cache.set, o = i, i(f);
226
226
  }
227
227
  function i(f) {
@@ -235,10 +235,10 @@ function Qn(e, ...t) {
235
235
  return o(Xn.apply(null, arguments));
236
236
  };
237
237
  }
238
- const te = (e) => {
238
+ const ne = (e) => {
239
239
  const t = (n) => n[e] || [];
240
240
  return t.isThemeGetter = !0, t;
241
- }, an = /^\[(?:([a-z-]+):)?(.+)\]$/i, Yn = /^\d+\/\d+$/, Zn = /* @__PURE__ */ new Set(["px", "full", "screen"]), er = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, tr = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/, nr = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, rr = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, sr = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, Ne = (e) => He(e) || Zn.has(e) || Yn.test(e), ze = (e) => Ge(e, "length", fr), He = (e) => !!e && !Number.isNaN(Number(e)), xt = (e) => Ge(e, "number", He), Ze = (e) => !!e && Number.isInteger(Number(e)), or = (e) => e.endsWith("%") && He(e.slice(0, -1)), O = (e) => an.test(e), Ue = (e) => er.test(e), ar = /* @__PURE__ */ new Set(["length", "size", "percentage"]), ir = (e) => Ge(e, ar, cn), cr = (e) => Ge(e, "position", cn), lr = /* @__PURE__ */ new Set(["image", "url"]), ur = (e) => Ge(e, lr, gr), dr = (e) => Ge(e, "", pr), et = () => !0, Ge = (e, t, n) => {
241
+ }, an = /^\[(?:([a-z-]+):)?(.+)\]$/i, Yn = /^\d+\/\d+$/, Zn = /* @__PURE__ */ new Set(["px", "full", "screen"]), er = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, tr = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/, nr = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, rr = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, sr = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, _e = (e) => qe(e) || Zn.has(e) || Yn.test(e), Ue = (e) => Je(e, "length", fr), qe = (e) => !!e && !Number.isNaN(Number(e)), xt = (e) => Je(e, "number", qe), Ze = (e) => !!e && Number.isInteger(Number(e)), or = (e) => e.endsWith("%") && qe(e.slice(0, -1)), j = (e) => an.test(e), je = (e) => er.test(e), ar = /* @__PURE__ */ new Set(["length", "size", "percentage"]), ir = (e) => Je(e, ar, cn), cr = (e) => Je(e, "position", cn), lr = /* @__PURE__ */ new Set(["image", "url"]), ur = (e) => Je(e, lr, gr), dr = (e) => Je(e, "", pr), et = () => !0, Je = (e, t, n) => {
242
242
  const r = an.exec(e);
243
243
  return r ? r[1] ? typeof t == "string" ? r[1] === t : t.has(r[1]) : n(r[2]) : !1;
244
244
  }, fr = (e) => (
@@ -247,36 +247,36 @@ const te = (e) => {
247
247
  // I could also use lookbehind assertion in `lengthUnitRegex` but that isn't supported widely enough.
248
248
  tr.test(e) && !nr.test(e)
249
249
  ), cn = () => !1, pr = (e) => rr.test(e), gr = (e) => sr.test(e), mr = () => {
250
- const e = te("colors"), t = te("spacing"), n = te("blur"), r = te("brightness"), s = te("borderColor"), o = te("borderRadius"), a = te("borderSpacing"), i = te("borderWidth"), f = te("contrast"), l = te("grayscale"), c = te("hueRotate"), d = te("invert"), g = te("gap"), h = te("gradientColorStops"), k = te("gradientColorStopPositions"), m = te("inset"), y = te("margin"), I = te("opacity"), S = te("padding"), C = te("saturate"), L = te("scale"), z = te("sepia"), w = te("skew"), v = te("space"), F = te("translate"), $ = () => ["auto", "contain", "none"], B = () => ["auto", "hidden", "clip", "visible", "scroll"], D = () => ["auto", O, t], P = () => [O, t], J = () => ["", Ne, ze], G = () => ["auto", He, O], Q = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], X = () => ["solid", "dashed", "dotted", "double", "none"], oe = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], A = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], R = () => ["", "0", O], V = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], K = () => [He, O];
250
+ const e = ne("colors"), t = ne("spacing"), n = ne("blur"), r = ne("brightness"), s = ne("borderColor"), o = ne("borderRadius"), a = ne("borderSpacing"), i = ne("borderWidth"), f = ne("contrast"), l = ne("grayscale"), c = ne("hueRotate"), u = ne("invert"), g = ne("gap"), m = ne("gradientColorStops"), k = ne("gradientColorStopPositions"), p = ne("inset"), y = ne("margin"), v = ne("opacity"), A = ne("padding"), x = ne("saturate"), L = ne("scale"), z = ne("sepia"), w = ne("skew"), I = ne("space"), F = ne("translate"), $ = () => ["auto", "contain", "none"], B = () => ["auto", "hidden", "clip", "visible", "scroll"], D = () => ["auto", j, t], M = () => [j, t], Q = () => ["", _e, Ue], G = () => ["auto", qe, j], re = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], te = () => ["solid", "dashed", "dotted", "double", "none"], se = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], S = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], E = () => ["", "0", j], O = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], K = () => [qe, j];
251
251
  return {
252
252
  cacheSize: 500,
253
253
  separator: ":",
254
254
  theme: {
255
255
  colors: [et],
256
- spacing: [Ne, ze],
257
- blur: ["none", "", Ue, O],
256
+ spacing: [_e, Ue],
257
+ blur: ["none", "", je, j],
258
258
  brightness: K(),
259
259
  borderColor: [e],
260
- borderRadius: ["none", "", "full", Ue, O],
261
- borderSpacing: P(),
262
- borderWidth: J(),
260
+ borderRadius: ["none", "", "full", je, j],
261
+ borderSpacing: M(),
262
+ borderWidth: Q(),
263
263
  contrast: K(),
264
- grayscale: R(),
264
+ grayscale: E(),
265
265
  hueRotate: K(),
266
- invert: R(),
267
- gap: P(),
266
+ invert: E(),
267
+ gap: M(),
268
268
  gradientColorStops: [e],
269
- gradientColorStopPositions: [or, ze],
269
+ gradientColorStopPositions: [or, Ue],
270
270
  inset: D(),
271
271
  margin: D(),
272
272
  opacity: K(),
273
- padding: P(),
273
+ padding: M(),
274
274
  saturate: K(),
275
275
  scale: K(),
276
- sepia: R(),
276
+ sepia: E(),
277
277
  skew: K(),
278
- space: P(),
279
- translate: P()
278
+ space: M(),
279
+ translate: M()
280
280
  },
281
281
  classGroups: {
282
282
  // Layout
@@ -285,7 +285,7 @@ const te = (e) => {
285
285
  * @see https://tailwindcss.com/docs/aspect-ratio
286
286
  */
287
287
  aspect: [{
288
- aspect: ["auto", "square", "video", O]
288
+ aspect: ["auto", "square", "video", j]
289
289
  }],
290
290
  /**
291
291
  * Container
@@ -297,21 +297,21 @@ const te = (e) => {
297
297
  * @see https://tailwindcss.com/docs/columns
298
298
  */
299
299
  columns: [{
300
- columns: [Ue]
300
+ columns: [je]
301
301
  }],
302
302
  /**
303
303
  * Break After
304
304
  * @see https://tailwindcss.com/docs/break-after
305
305
  */
306
306
  "break-after": [{
307
- "break-after": V()
307
+ "break-after": O()
308
308
  }],
309
309
  /**
310
310
  * Break Before
311
311
  * @see https://tailwindcss.com/docs/break-before
312
312
  */
313
313
  "break-before": [{
314
- "break-before": V()
314
+ "break-before": O()
315
315
  }],
316
316
  /**
317
317
  * Break Inside
@@ -370,7 +370,7 @@ const te = (e) => {
370
370
  * @see https://tailwindcss.com/docs/object-position
371
371
  */
372
372
  "object-position": [{
373
- object: [...Q(), O]
373
+ object: [...re(), j]
374
374
  }],
375
375
  /**
376
376
  * Overflow
@@ -424,63 +424,63 @@ const te = (e) => {
424
424
  * @see https://tailwindcss.com/docs/top-right-bottom-left
425
425
  */
426
426
  inset: [{
427
- inset: [m]
427
+ inset: [p]
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": [m]
434
+ "inset-x": [p]
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": [m]
441
+ "inset-y": [p]
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: [m]
448
+ start: [p]
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: [m]
455
+ end: [p]
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: [m]
462
+ top: [p]
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: [m]
469
+ right: [p]
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: [m]
476
+ bottom: [p]
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: [m]
483
+ left: [p]
484
484
  }],
485
485
  /**
486
486
  * Visibility
@@ -492,7 +492,7 @@ const te = (e) => {
492
492
  * @see https://tailwindcss.com/docs/z-index
493
493
  */
494
494
  z: [{
495
- z: ["auto", Ze, O]
495
+ z: ["auto", Ze, j]
496
496
  }],
497
497
  // Flexbox and Grid
498
498
  /**
@@ -521,28 +521,28 @@ const te = (e) => {
521
521
  * @see https://tailwindcss.com/docs/flex
522
522
  */
523
523
  flex: [{
524
- flex: ["1", "auto", "initial", "none", O]
524
+ flex: ["1", "auto", "initial", "none", j]
525
525
  }],
526
526
  /**
527
527
  * Flex Grow
528
528
  * @see https://tailwindcss.com/docs/flex-grow
529
529
  */
530
530
  grow: [{
531
- grow: R()
531
+ grow: E()
532
532
  }],
533
533
  /**
534
534
  * Flex Shrink
535
535
  * @see https://tailwindcss.com/docs/flex-shrink
536
536
  */
537
537
  shrink: [{
538
- shrink: R()
538
+ shrink: E()
539
539
  }],
540
540
  /**
541
541
  * Order
542
542
  * @see https://tailwindcss.com/docs/order
543
543
  */
544
544
  order: [{
545
- order: ["first", "last", "none", Ze, O]
545
+ order: ["first", "last", "none", Ze, j]
546
546
  }],
547
547
  /**
548
548
  * Grid Template Columns
@@ -557,8 +557,8 @@ const te = (e) => {
557
557
  */
558
558
  "col-start-end": [{
559
559
  col: ["auto", {
560
- span: ["full", Ze, O]
561
- }, O]
560
+ span: ["full", Ze, j]
561
+ }, j]
562
562
  }],
563
563
  /**
564
564
  * Grid Column Start
@@ -587,8 +587,8 @@ const te = (e) => {
587
587
  */
588
588
  "row-start-end": [{
589
589
  row: ["auto", {
590
- span: [Ze, O]
591
- }, O]
590
+ span: [Ze, j]
591
+ }, j]
592
592
  }],
593
593
  /**
594
594
  * Grid Row Start
@@ -616,14 +616,14 @@ const te = (e) => {
616
616
  * @see https://tailwindcss.com/docs/grid-auto-columns
617
617
  */
618
618
  "auto-cols": [{
619
- "auto-cols": ["auto", "min", "max", "fr", O]
619
+ "auto-cols": ["auto", "min", "max", "fr", j]
620
620
  }],
621
621
  /**
622
622
  * Grid Auto Rows
623
623
  * @see https://tailwindcss.com/docs/grid-auto-rows
624
624
  */
625
625
  "auto-rows": [{
626
- "auto-rows": ["auto", "min", "max", "fr", O]
626
+ "auto-rows": ["auto", "min", "max", "fr", j]
627
627
  }],
628
628
  /**
629
629
  * Gap
@@ -651,7 +651,7 @@ const te = (e) => {
651
651
  * @see https://tailwindcss.com/docs/justify-content
652
652
  */
653
653
  "justify-content": [{
654
- justify: ["normal", ...A()]
654
+ justify: ["normal", ...S()]
655
655
  }],
656
656
  /**
657
657
  * Justify Items
@@ -672,7 +672,7 @@ const te = (e) => {
672
672
  * @see https://tailwindcss.com/docs/align-content
673
673
  */
674
674
  "align-content": [{
675
- content: ["normal", ...A(), "baseline"]
675
+ content: ["normal", ...S(), "baseline"]
676
676
  }],
677
677
  /**
678
678
  * Align Items
@@ -693,7 +693,7 @@ const te = (e) => {
693
693
  * @see https://tailwindcss.com/docs/place-content
694
694
  */
695
695
  "place-content": [{
696
- "place-content": [...A(), "baseline"]
696
+ "place-content": [...S(), "baseline"]
697
697
  }],
698
698
  /**
699
699
  * Place Items
@@ -715,63 +715,63 @@ const te = (e) => {
715
715
  * @see https://tailwindcss.com/docs/padding
716
716
  */
717
717
  p: [{
718
- p: [S]
718
+ p: [A]
719
719
  }],
720
720
  /**
721
721
  * Padding X
722
722
  * @see https://tailwindcss.com/docs/padding
723
723
  */
724
724
  px: [{
725
- px: [S]
725
+ px: [A]
726
726
  }],
727
727
  /**
728
728
  * Padding Y
729
729
  * @see https://tailwindcss.com/docs/padding
730
730
  */
731
731
  py: [{
732
- py: [S]
732
+ py: [A]
733
733
  }],
734
734
  /**
735
735
  * Padding Start
736
736
  * @see https://tailwindcss.com/docs/padding
737
737
  */
738
738
  ps: [{
739
- ps: [S]
739
+ ps: [A]
740
740
  }],
741
741
  /**
742
742
  * Padding End
743
743
  * @see https://tailwindcss.com/docs/padding
744
744
  */
745
745
  pe: [{
746
- pe: [S]
746
+ pe: [A]
747
747
  }],
748
748
  /**
749
749
  * Padding Top
750
750
  * @see https://tailwindcss.com/docs/padding
751
751
  */
752
752
  pt: [{
753
- pt: [S]
753
+ pt: [A]
754
754
  }],
755
755
  /**
756
756
  * Padding Right
757
757
  * @see https://tailwindcss.com/docs/padding
758
758
  */
759
759
  pr: [{
760
- pr: [S]
760
+ pr: [A]
761
761
  }],
762
762
  /**
763
763
  * Padding Bottom
764
764
  * @see https://tailwindcss.com/docs/padding
765
765
  */
766
766
  pb: [{
767
- pb: [S]
767
+ pb: [A]
768
768
  }],
769
769
  /**
770
770
  * Padding Left
771
771
  * @see https://tailwindcss.com/docs/padding
772
772
  */
773
773
  pl: [{
774
- pl: [S]
774
+ pl: [A]
775
775
  }],
776
776
  /**
777
777
  * Margin
@@ -841,7 +841,7 @@ const te = (e) => {
841
841
  * @see https://tailwindcss.com/docs/space
842
842
  */
843
843
  "space-x": [{
844
- "space-x": [v]
844
+ "space-x": [I]
845
845
  }],
846
846
  /**
847
847
  * Space Between X Reverse
@@ -853,7 +853,7 @@ const te = (e) => {
853
853
  * @see https://tailwindcss.com/docs/space
854
854
  */
855
855
  "space-y": [{
856
- "space-y": [v]
856
+ "space-y": [I]
857
857
  }],
858
858
  /**
859
859
  * Space Between Y Reverse
@@ -866,51 +866,51 @@ const te = (e) => {
866
866
  * @see https://tailwindcss.com/docs/width
867
867
  */
868
868
  w: [{
869
- w: ["auto", "min", "max", "fit", "svw", "lvw", "dvw", O, t]
869
+ w: ["auto", "min", "max", "fit", "svw", "lvw", "dvw", j, t]
870
870
  }],
871
871
  /**
872
872
  * Min-Width
873
873
  * @see https://tailwindcss.com/docs/min-width
874
874
  */
875
875
  "min-w": [{
876
- "min-w": [O, t, "min", "max", "fit"]
876
+ "min-w": [j, t, "min", "max", "fit"]
877
877
  }],
878
878
  /**
879
879
  * Max-Width
880
880
  * @see https://tailwindcss.com/docs/max-width
881
881
  */
882
882
  "max-w": [{
883
- "max-w": [O, t, "none", "full", "min", "max", "fit", "prose", {
884
- screen: [Ue]
885
- }, Ue]
883
+ "max-w": [j, t, "none", "full", "min", "max", "fit", "prose", {
884
+ screen: [je]
885
+ }, je]
886
886
  }],
887
887
  /**
888
888
  * Height
889
889
  * @see https://tailwindcss.com/docs/height
890
890
  */
891
891
  h: [{
892
- h: [O, t, "auto", "min", "max", "fit", "svh", "lvh", "dvh"]
892
+ h: [j, t, "auto", "min", "max", "fit", "svh", "lvh", "dvh"]
893
893
  }],
894
894
  /**
895
895
  * Min-Height
896
896
  * @see https://tailwindcss.com/docs/min-height
897
897
  */
898
898
  "min-h": [{
899
- "min-h": [O, t, "min", "max", "fit", "svh", "lvh", "dvh"]
899
+ "min-h": [j, t, "min", "max", "fit", "svh", "lvh", "dvh"]
900
900
  }],
901
901
  /**
902
902
  * Max-Height
903
903
  * @see https://tailwindcss.com/docs/max-height
904
904
  */
905
905
  "max-h": [{
906
- "max-h": [O, t, "min", "max", "fit", "svh", "lvh", "dvh"]
906
+ "max-h": [j, t, "min", "max", "fit", "svh", "lvh", "dvh"]
907
907
  }],
908
908
  /**
909
909
  * Size
910
910
  * @see https://tailwindcss.com/docs/size
911
911
  */
912
912
  size: [{
913
- size: [O, t, "auto", "min", "max", "fit"]
913
+ size: [j, t, "auto", "min", "max", "fit"]
914
914
  }],
915
915
  // Typography
916
916
  /**
@@ -918,7 +918,7 @@ const te = (e) => {
918
918
  * @see https://tailwindcss.com/docs/font-size
919
919
  */
920
920
  "font-size": [{
921
- text: ["base", Ue, ze]
921
+ text: ["base", je, Ue]
922
922
  }],
923
923
  /**
924
924
  * Font Smoothing
@@ -979,35 +979,35 @@ const te = (e) => {
979
979
  * @see https://tailwindcss.com/docs/letter-spacing
980
980
  */
981
981
  tracking: [{
982
- tracking: ["tighter", "tight", "normal", "wide", "wider", "widest", O]
982
+ tracking: ["tighter", "tight", "normal", "wide", "wider", "widest", j]
983
983
  }],
984
984
  /**
985
985
  * Line Clamp
986
986
  * @see https://tailwindcss.com/docs/line-clamp
987
987
  */
988
988
  "line-clamp": [{
989
- "line-clamp": ["none", He, xt]
989
+ "line-clamp": ["none", qe, xt]
990
990
  }],
991
991
  /**
992
992
  * Line Height
993
993
  * @see https://tailwindcss.com/docs/line-height
994
994
  */
995
995
  leading: [{
996
- leading: ["none", "tight", "snug", "normal", "relaxed", "loose", Ne, O]
996
+ leading: ["none", "tight", "snug", "normal", "relaxed", "loose", _e, j]
997
997
  }],
998
998
  /**
999
999
  * List Style Image
1000
1000
  * @see https://tailwindcss.com/docs/list-style-image
1001
1001
  */
1002
1002
  "list-image": [{
1003
- "list-image": ["none", O]
1003
+ "list-image": ["none", j]
1004
1004
  }],
1005
1005
  /**
1006
1006
  * List Style Type
1007
1007
  * @see https://tailwindcss.com/docs/list-style-type
1008
1008
  */
1009
1009
  "list-style-type": [{
1010
- list: ["none", "disc", "decimal", O]
1010
+ list: ["none", "disc", "decimal", j]
1011
1011
  }],
1012
1012
  /**
1013
1013
  * List Style Position
@@ -1029,7 +1029,7 @@ const te = (e) => {
1029
1029
  * @see https://tailwindcss.com/docs/placeholder-opacity
1030
1030
  */
1031
1031
  "placeholder-opacity": [{
1032
- "placeholder-opacity": [I]
1032
+ "placeholder-opacity": [v]
1033
1033
  }],
1034
1034
  /**
1035
1035
  * Text Alignment
@@ -1050,7 +1050,7 @@ const te = (e) => {
1050
1050
  * @see https://tailwindcss.com/docs/text-opacity
1051
1051
  */
1052
1052
  "text-opacity": [{
1053
- "text-opacity": [I]
1053
+ "text-opacity": [v]
1054
1054
  }],
1055
1055
  /**
1056
1056
  * Text Decoration
@@ -1062,21 +1062,21 @@ const te = (e) => {
1062
1062
  * @see https://tailwindcss.com/docs/text-decoration-style
1063
1063
  */
1064
1064
  "text-decoration-style": [{
1065
- decoration: [...X(), "wavy"]
1065
+ decoration: [...te(), "wavy"]
1066
1066
  }],
1067
1067
  /**
1068
1068
  * Text Decoration Thickness
1069
1069
  * @see https://tailwindcss.com/docs/text-decoration-thickness
1070
1070
  */
1071
1071
  "text-decoration-thickness": [{
1072
- decoration: ["auto", "from-font", Ne, ze]
1072
+ decoration: ["auto", "from-font", _e, Ue]
1073
1073
  }],
1074
1074
  /**
1075
1075
  * Text Underline Offset
1076
1076
  * @see https://tailwindcss.com/docs/text-underline-offset
1077
1077
  */
1078
1078
  "underline-offset": [{
1079
- "underline-offset": ["auto", Ne, O]
1079
+ "underline-offset": ["auto", _e, j]
1080
1080
  }],
1081
1081
  /**
1082
1082
  * Text Decoration Color
@@ -1107,14 +1107,14 @@ const te = (e) => {
1107
1107
  * @see https://tailwindcss.com/docs/text-indent
1108
1108
  */
1109
1109
  indent: [{
1110
- indent: P()
1110
+ indent: M()
1111
1111
  }],
1112
1112
  /**
1113
1113
  * Vertical Alignment
1114
1114
  * @see https://tailwindcss.com/docs/vertical-align
1115
1115
  */
1116
1116
  "vertical-align": [{
1117
- align: ["baseline", "top", "middle", "bottom", "text-top", "text-bottom", "sub", "super", O]
1117
+ align: ["baseline", "top", "middle", "bottom", "text-top", "text-bottom", "sub", "super", j]
1118
1118
  }],
1119
1119
  /**
1120
1120
  * Whitespace
@@ -1142,7 +1142,7 @@ const te = (e) => {
1142
1142
  * @see https://tailwindcss.com/docs/content
1143
1143
  */
1144
1144
  content: [{
1145
- content: ["none", O]
1145
+ content: ["none", j]
1146
1146
  }],
1147
1147
  // Backgrounds
1148
1148
  /**
@@ -1165,7 +1165,7 @@ const te = (e) => {
1165
1165
  * @see https://tailwindcss.com/docs/background-opacity
1166
1166
  */
1167
1167
  "bg-opacity": [{
1168
- "bg-opacity": [I]
1168
+ "bg-opacity": [v]
1169
1169
  }],
1170
1170
  /**
1171
1171
  * Background Origin
@@ -1179,7 +1179,7 @@ const te = (e) => {
1179
1179
  * @see https://tailwindcss.com/docs/background-position
1180
1180
  */
1181
1181
  "bg-position": [{
1182
- bg: [...Q(), cr]
1182
+ bg: [...re(), cr]
1183
1183
  }],
1184
1184
  /**
1185
1185
  * Background Repeat
@@ -1239,21 +1239,21 @@ const te = (e) => {
1239
1239
  * @see https://tailwindcss.com/docs/gradient-color-stops
1240
1240
  */
1241
1241
  "gradient-from": [{
1242
- from: [h]
1242
+ from: [m]
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: [h]
1249
+ via: [m]
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: [h]
1256
+ to: [m]
1257
1257
  }],
1258
1258
  // Borders
1259
1259
  /**
@@ -1429,14 +1429,14 @@ const te = (e) => {
1429
1429
  * @see https://tailwindcss.com/docs/border-opacity
1430
1430
  */
1431
1431
  "border-opacity": [{
1432
- "border-opacity": [I]
1432
+ "border-opacity": [v]
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: [...X(), "hidden"]
1439
+ border: [...te(), "hidden"]
1440
1440
  }],
1441
1441
  /**
1442
1442
  * Divide Width X
@@ -1467,14 +1467,14 @@ const te = (e) => {
1467
1467
  * @see https://tailwindcss.com/docs/divide-opacity
1468
1468
  */
1469
1469
  "divide-opacity": [{
1470
- "divide-opacity": [I]
1470
+ "divide-opacity": [v]
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: X()
1477
+ divide: te()
1478
1478
  }],
1479
1479
  /**
1480
1480
  * Border Color
@@ -1551,21 +1551,21 @@ const te = (e) => {
1551
1551
  * @see https://tailwindcss.com/docs/outline-style
1552
1552
  */
1553
1553
  "outline-style": [{
1554
- outline: ["", ...X()]
1554
+ outline: ["", ...te()]
1555
1555
  }],
1556
1556
  /**
1557
1557
  * Outline Offset
1558
1558
  * @see https://tailwindcss.com/docs/outline-offset
1559
1559
  */
1560
1560
  "outline-offset": [{
1561
- "outline-offset": [Ne, O]
1561
+ "outline-offset": [_e, j]
1562
1562
  }],
1563
1563
  /**
1564
1564
  * Outline Width
1565
1565
  * @see https://tailwindcss.com/docs/outline-width
1566
1566
  */
1567
1567
  "outline-w": [{
1568
- outline: [Ne, ze]
1568
+ outline: [_e, Ue]
1569
1569
  }],
1570
1570
  /**
1571
1571
  * Outline Color
@@ -1579,7 +1579,7 @@ const te = (e) => {
1579
1579
  * @see https://tailwindcss.com/docs/ring-width
1580
1580
  */
1581
1581
  "ring-w": [{
1582
- ring: J()
1582
+ ring: Q()
1583
1583
  }],
1584
1584
  /**
1585
1585
  * Ring Width Inset
@@ -1598,14 +1598,14 @@ const te = (e) => {
1598
1598
  * @see https://tailwindcss.com/docs/ring-opacity
1599
1599
  */
1600
1600
  "ring-opacity": [{
1601
- "ring-opacity": [I]
1601
+ "ring-opacity": [v]
1602
1602
  }],
1603
1603
  /**
1604
1604
  * Ring Offset Width
1605
1605
  * @see https://tailwindcss.com/docs/ring-offset-width
1606
1606
  */
1607
1607
  "ring-offset-w": [{
1608
- "ring-offset": [Ne, ze]
1608
+ "ring-offset": [_e, Ue]
1609
1609
  }],
1610
1610
  /**
1611
1611
  * Ring Offset Color
@@ -1620,7 +1620,7 @@ const te = (e) => {
1620
1620
  * @see https://tailwindcss.com/docs/box-shadow
1621
1621
  */
1622
1622
  shadow: [{
1623
- shadow: ["", "inner", "none", Ue, dr]
1623
+ shadow: ["", "inner", "none", je, dr]
1624
1624
  }],
1625
1625
  /**
1626
1626
  * Box Shadow Color
@@ -1634,21 +1634,21 @@ const te = (e) => {
1634
1634
  * @see https://tailwindcss.com/docs/opacity
1635
1635
  */
1636
1636
  opacity: [{
1637
- opacity: [I]
1637
+ opacity: [v]
1638
1638
  }],
1639
1639
  /**
1640
1640
  * Mix Blend Mode
1641
1641
  * @see https://tailwindcss.com/docs/mix-blend-mode
1642
1642
  */
1643
1643
  "mix-blend": [{
1644
- "mix-blend": [...oe(), "plus-lighter", "plus-darker"]
1644
+ "mix-blend": [...se(), "plus-lighter", "plus-darker"]
1645
1645
  }],
1646
1646
  /**
1647
1647
  * Background Blend Mode
1648
1648
  * @see https://tailwindcss.com/docs/background-blend-mode
1649
1649
  */
1650
1650
  "bg-blend": [{
1651
- "bg-blend": oe()
1651
+ "bg-blend": se()
1652
1652
  }],
1653
1653
  // Filters
1654
1654
  /**
@@ -1685,7 +1685,7 @@ const te = (e) => {
1685
1685
  * @see https://tailwindcss.com/docs/drop-shadow
1686
1686
  */
1687
1687
  "drop-shadow": [{
1688
- "drop-shadow": ["", "none", Ue, O]
1688
+ "drop-shadow": ["", "none", je, j]
1689
1689
  }],
1690
1690
  /**
1691
1691
  * Grayscale
@@ -1706,14 +1706,14 @@ const te = (e) => {
1706
1706
  * @see https://tailwindcss.com/docs/invert
1707
1707
  */
1708
1708
  invert: [{
1709
- invert: [d]
1709
+ invert: [u]
1710
1710
  }],
1711
1711
  /**
1712
1712
  * Saturate
1713
1713
  * @see https://tailwindcss.com/docs/saturate
1714
1714
  */
1715
1715
  saturate: [{
1716
- saturate: [C]
1716
+ saturate: [x]
1717
1717
  }],
1718
1718
  /**
1719
1719
  * Sepia
@@ -1770,21 +1770,21 @@ const te = (e) => {
1770
1770
  * @see https://tailwindcss.com/docs/backdrop-invert
1771
1771
  */
1772
1772
  "backdrop-invert": [{
1773
- "backdrop-invert": [d]
1773
+ "backdrop-invert": [u]
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": [v]
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": [C]
1787
+ "backdrop-saturate": [x]
1788
1788
  }],
1789
1789
  /**
1790
1790
  * Backdrop Sepia
@@ -1842,7 +1842,7 @@ const te = (e) => {
1842
1842
  * @see https://tailwindcss.com/docs/transition-property
1843
1843
  */
1844
1844
  transition: [{
1845
- transition: ["none", "all", "", "colors", "opacity", "shadow", "transform", O]
1845
+ transition: ["none", "all", "", "colors", "opacity", "shadow", "transform", j]
1846
1846
  }],
1847
1847
  /**
1848
1848
  * Transition Duration
@@ -1856,7 +1856,7 @@ const te = (e) => {
1856
1856
  * @see https://tailwindcss.com/docs/transition-timing-function
1857
1857
  */
1858
1858
  ease: [{
1859
- ease: ["linear", "in", "out", "in-out", O]
1859
+ ease: ["linear", "in", "out", "in-out", j]
1860
1860
  }],
1861
1861
  /**
1862
1862
  * Transition Delay
@@ -1870,7 +1870,7 @@ const te = (e) => {
1870
1870
  * @see https://tailwindcss.com/docs/animation
1871
1871
  */
1872
1872
  animate: [{
1873
- animate: ["none", "spin", "ping", "pulse", "bounce", O]
1873
+ animate: ["none", "spin", "ping", "pulse", "bounce", j]
1874
1874
  }],
1875
1875
  // Transforms
1876
1876
  /**
@@ -1906,7 +1906,7 @@ const te = (e) => {
1906
1906
  * @see https://tailwindcss.com/docs/rotate
1907
1907
  */
1908
1908
  rotate: [{
1909
- rotate: [Ze, O]
1909
+ rotate: [Ze, j]
1910
1910
  }],
1911
1911
  /**
1912
1912
  * Translate X
@@ -1941,7 +1941,7 @@ const te = (e) => {
1941
1941
  * @see https://tailwindcss.com/docs/transform-origin
1942
1942
  */
1943
1943
  "transform-origin": [{
1944
- origin: ["center", "top", "top-right", "right", "bottom-right", "bottom", "bottom-left", "left", "top-left", O]
1944
+ origin: ["center", "top", "top-right", "right", "bottom-right", "bottom", "bottom-left", "left", "top-left", j]
1945
1945
  }],
1946
1946
  // Interactivity
1947
1947
  /**
@@ -1963,7 +1963,7 @@ const te = (e) => {
1963
1963
  * @see https://tailwindcss.com/docs/cursor
1964
1964
  */
1965
1965
  cursor: [{
1966
- cursor: ["auto", "default", "pointer", "wait", "text", "move", "help", "not-allowed", "none", "context-menu", "progress", "cell", "crosshair", "vertical-text", "alias", "copy", "no-drop", "grab", "grabbing", "all-scroll", "col-resize", "row-resize", "n-resize", "e-resize", "s-resize", "w-resize", "ne-resize", "nw-resize", "se-resize", "sw-resize", "ew-resize", "ns-resize", "nesw-resize", "nwse-resize", "zoom-in", "zoom-out", O]
1966
+ cursor: ["auto", "default", "pointer", "wait", "text", "move", "help", "not-allowed", "none", "context-menu", "progress", "cell", "crosshair", "vertical-text", "alias", "copy", "no-drop", "grab", "grabbing", "all-scroll", "col-resize", "row-resize", "n-resize", "e-resize", "s-resize", "w-resize", "ne-resize", "nw-resize", "se-resize", "sw-resize", "ew-resize", "ns-resize", "nesw-resize", "nwse-resize", "zoom-in", "zoom-out", j]
1967
1967
  }],
1968
1968
  /**
1969
1969
  * Caret Color
@@ -1998,126 +1998,126 @@ const te = (e) => {
1998
1998
  * @see https://tailwindcss.com/docs/scroll-margin
1999
1999
  */
2000
2000
  "scroll-m": [{
2001
- "scroll-m": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
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": P()
2120
+ "scroll-pl": M()
2121
2121
  }],
2122
2122
  /**
2123
2123
  * Scroll Snap Align
@@ -2185,7 +2185,7 @@ const te = (e) => {
2185
2185
  * @see https://tailwindcss.com/docs/will-change
2186
2186
  */
2187
2187
  "will-change": [{
2188
- "will-change": ["auto", "scroll", "contents", "transform", O]
2188
+ "will-change": ["auto", "scroll", "contents", "transform", j]
2189
2189
  }],
2190
2190
  // SVG
2191
2191
  /**
@@ -2200,7 +2200,7 @@ const te = (e) => {
2200
2200
  * @see https://tailwindcss.com/docs/stroke-width
2201
2201
  */
2202
2202
  "stroke-w": [{
2203
- stroke: [Ne, ze, xt]
2203
+ stroke: [_e, Ue, xt]
2204
2204
  }],
2205
2205
  /**
2206
2206
  * Stroke
@@ -2294,7 +2294,7 @@ function yr(e) {
2294
2294
  }
2295
2295
  return n.replace(/\bTrue\b/g, "true").replace(/\bFalse\b/g, "false").replace(/\bNone\b/g, "null");
2296
2296
  }
2297
- function zt(e) {
2297
+ function Ft(e) {
2298
2298
  const t = e == null ? void 0 : e.trim();
2299
2299
  if (!t || !(t.startsWith("{") || t.startsWith("["))) return null;
2300
2300
  try {
@@ -2343,12 +2343,12 @@ function Ar(e) {
2343
2343
  function un(e) {
2344
2344
  return !!(e && typeof e == "object" && (e.type === "file" || e.mimeType || e.filename || e.sourceType === "base64"));
2345
2345
  }
2346
- function yt(e) {
2346
+ function ht(e) {
2347
2347
  if (typeof e == "string")
2348
2348
  return e;
2349
2349
  if (e && typeof e == "object") {
2350
2350
  if (Array.isArray(e)) {
2351
- const n = e.map(yt).filter((r) => r !== void 0);
2351
+ const n = e.map(ht).filter((r) => r !== void 0);
2352
2352
  if (!n.length) {
2353
2353
  console.debug("[message-utils] sanitizeForDisplay - array emptied -> returning undefined", { originalLength: e.length });
2354
2354
  return;
@@ -2372,7 +2372,7 @@ function yt(e) {
2372
2372
  if (n === "data" && typeof r == "string" && r.length > 100)
2373
2373
  t[n] = `[base64 ${r.length} chars omitted]`;
2374
2374
  else {
2375
- const s = yt(r);
2375
+ const s = ht(r);
2376
2376
  s !== void 0 && (t[n] = s);
2377
2377
  }
2378
2378
  }
@@ -2391,7 +2391,7 @@ function dn(e) {
2391
2391
  if (typeof e == "string") return e;
2392
2392
  if (un(e)) return "";
2393
2393
  try {
2394
- const t = yt(e);
2394
+ const t = ht(e);
2395
2395
  return t === void 0 ? "" : typeof t == "string" ? t : JSON.stringify(t, null, 2);
2396
2396
  } catch {
2397
2397
  return "";
@@ -2404,7 +2404,7 @@ function Ks(e) {
2404
2404
  function Sr(e) {
2405
2405
  const t = (r) => {
2406
2406
  try {
2407
- const s = yt(r);
2407
+ const s = ht(r);
2408
2408
  return typeof s == "string" ? s : JSON.stringify(s ?? "");
2409
2409
  } catch {
2410
2410
  return "";
@@ -2416,44 +2416,44 @@ function Sr(e) {
2416
2416
  function Hs(e) {
2417
2417
  return e.content.some((t) => t.type === "text" ? t.text.trim().length > 0 : t.type === "image_url" || t.type === "file");
2418
2418
  }
2419
- function Me(e) {
2419
+ function Ee(e) {
2420
2420
  if (e == null) return e;
2421
2421
  if (typeof e == "string") {
2422
2422
  const t = e.trim();
2423
2423
  if (t.startsWith("{") || t.startsWith("[")) {
2424
- const n = zt(t);
2424
+ const n = Ft(t);
2425
2425
  if (n !== null)
2426
- return Me(n);
2426
+ return Ee(n);
2427
2427
  }
2428
2428
  return e;
2429
2429
  }
2430
2430
  if (typeof e == "object" && !Array.isArray(e)) {
2431
2431
  if (e.content !== void 0)
2432
- return Array.isArray(e.content) ? e.content.map((t) => Me(t)).filter(Boolean).join(`
2433
- `) : Me(e.content);
2432
+ return Array.isArray(e.content) ? e.content.map((t) => Ee(t)).filter(Boolean).join(`
2433
+ `) : Ee(e.content);
2434
2434
  if (e.value !== void 0)
2435
- return Me(e.value);
2435
+ return Ee(e.value);
2436
2436
  }
2437
- return typeof e == "object" && !Array.isArray(e) && (e.type === "text" && typeof e.text == "string" || typeof e.text == "string") ? e.text : Array.isArray(e) && e.length > 0 ? Me(e[0]) : e;
2437
+ return typeof e == "object" && !Array.isArray(e) && (e.type === "text" && typeof e.text == "string" || typeof e.text == "string") ? e.text : Array.isArray(e) && e.length > 0 ? Ee(e[0]) : e;
2438
2438
  }
2439
2439
  function xr(e) {
2440
2440
  return e.replace(/[_-](\w)/g, (t, n) => n ? n.toUpperCase() : "").replace(/^\w/, (t) => t.toLowerCase());
2441
2441
  }
2442
- function Ee(e) {
2443
- return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(Ee) : Object.fromEntries(
2442
+ function Pe(e) {
2443
+ return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(Pe) : Object.fromEntries(
2444
2444
  Object.entries(e).map(([t, n]) => [
2445
2445
  xr(t),
2446
- Ee(n)
2446
+ Pe(n)
2447
2447
  ])
2448
2448
  );
2449
2449
  }
2450
- function bt(e) {
2451
- var y, I, S, C, L, z;
2450
+ function yt(e) {
2451
+ var y, v, A, x, L, z;
2452
2452
  if (!e || typeof e != "object") return null;
2453
- const t = Ee(e), n = Er(t);
2453
+ const t = Pe(e), n = Er(t);
2454
2454
  if (!n)
2455
2455
  return null;
2456
- const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(Ut) : void 0, s = Mr(t.content ?? t.parts, !!(r != null && r.length)), o = t.id ?? `msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`, a = t.createdAt ?? ((y = t.additionalKwargs) == null ? void 0 : y.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), i = t.name ?? ((I = t.additionalKwargs) == null ? void 0 : I.agentName) ?? void 0, f = t.model ?? ((S = t.additionalKwargs) == null ? void 0 : S.model) ?? void 0, l = t.toolCallId ?? void 0, c = t.additionalKwargs ?? void 0, d = t.responseMetadata ?? void 0, g = t.checkpointId ?? ((C = t.additionalKwargs) == null ? void 0 : C.checkpointId) ?? void 0, h = t.checkpointNs ?? ((L = t.additionalKwargs) == null ? void 0 : L.checkpointNs) ?? void 0, k = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((z = t.additionalKwargs) != null && z.toolStreaming);
2456
+ const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(Ut) : void 0, s = Mr(t.content ?? t.parts, !!(r != null && r.length)), o = t.id ?? `msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`, a = t.createdAt ?? ((y = t.additionalKwargs) == null ? void 0 : y.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), i = t.name ?? ((v = t.additionalKwargs) == null ? void 0 : v.agentName) ?? void 0, f = t.model ?? ((A = t.additionalKwargs) == null ? void 0 : A.model) ?? void 0, l = t.toolCallId ?? void 0, c = t.additionalKwargs ?? void 0, u = t.responseMetadata ?? void 0, g = t.checkpointId ?? ((x = t.additionalKwargs) == null ? void 0 : x.checkpointId) ?? void 0, m = t.checkpointNs ?? ((L = t.additionalKwargs) == null ? void 0 : L.checkpointNs) ?? void 0, k = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((z = t.additionalKwargs) != null && z.toolStreaming);
2457
2457
  return {
2458
2458
  ...t,
2459
2459
  id: o,
@@ -2465,16 +2465,16 @@ function bt(e) {
2465
2465
  toolCallId: l,
2466
2466
  toolCalls: r,
2467
2467
  checkpointId: g,
2468
- checkpointNs: h,
2468
+ checkpointNs: m,
2469
2469
  toolStreaming: k,
2470
2470
  additionalKwargs: c,
2471
- responseMetadata: d,
2471
+ responseMetadata: u,
2472
2472
  artifact: t.artifact ?? void 0
2473
2473
  };
2474
2474
  }
2475
2475
  function Cr(e) {
2476
2476
  if (!e || typeof e != "object") return e;
2477
- const t = Ee(e);
2477
+ const t = Pe(e);
2478
2478
  if (t.tool && !t.name && (t.name = t.tool), t.type === "artifact.update" && t.artifact && typeof t.artifact == "object") {
2479
2479
  const n = t.artifact;
2480
2480
  !n.id && n.artifactId && (n.id = n.artifactId), !n.type && n.artifactType && (n.type = n.artifactType);
@@ -2482,7 +2482,7 @@ function Cr(e) {
2482
2482
  return t;
2483
2483
  }
2484
2484
  function Ut(e) {
2485
- const t = Ee(e), n = t.content ?? t.output ?? void 0;
2485
+ const t = Pe(e), n = t.content ?? t.output ?? void 0;
2486
2486
  return {
2487
2487
  ...t,
2488
2488
  type: "tool_call",
@@ -2493,12 +2493,12 @@ function Ut(e) {
2493
2493
  };
2494
2494
  }
2495
2495
  function Mr(e, t) {
2496
- return Array.isArray(e) ? e.map((n) => n.type === "tool_call" || n.type === "tool" ? t ? null : Ut(Ee(n)) : n).filter(
2496
+ return Array.isArray(e) ? e.map((n) => n.type === "tool_call" || n.type === "tool" ? t ? null : Ut(Pe(n)) : n).filter(
2497
2497
  (n) => !!(n && typeof n == "object" && typeof n.type == "string")
2498
2498
  ) : [];
2499
2499
  }
2500
2500
  function Er(e) {
2501
- const t = Ee(e), n = t.role;
2501
+ const t = Pe(e), n = t.role;
2502
2502
  if (n && (n === "assistant" || n === "user" || n === "system" || n === "tool" || n === "interrupt"))
2503
2503
  return n;
2504
2504
  const r = t.type;
@@ -2533,14 +2533,14 @@ function Pr(e, t) {
2533
2533
  createdAt: e.createdAt
2534
2534
  };
2535
2535
  }
2536
- function Rr(e, t = []) {
2536
+ function Nr(e, t = []) {
2537
2537
  if (Array.isArray(e)) {
2538
2538
  const s = e.filter((a) => a.role === "assistant").flatMap((a) => qt(a)), o = /* @__PURE__ */ new Map();
2539
2539
  return s.forEach((a) => o.set(a.id, a)), Array.from(o.values()).map((a) => {
2540
- var d, g, h;
2541
- const i = Ct(a.id, e) || Ct(a.id, t), f = Array.isArray((d = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : d.toolProgress) ? (g = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : g.toolProgress : void 0, l = (i == null ? void 0 : i.artifact) ?? a.artifact, c = Ht(a.status) ?? ((h = i == null ? void 0 : i.additionalKwargs) != null && h.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2540
+ var u, g, m;
2541
+ const i = Ct(a.id, e) || Ct(a.id, t), f = Array.isArray((u = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : u.toolProgress) ? (g = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : g.toolProgress : void 0, l = (i == null ? void 0 : i.artifact) ?? a.artifact, c = Ht(a.status) ?? ((m = i == null ? void 0 : i.additionalKwargs) != null && m.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2542
2542
  if (i && !a.content && c === "completed") {
2543
- const k = Me(i);
2543
+ const k = Ee(i);
2544
2544
  typeof k == "string" && (a.content = k);
2545
2545
  }
2546
2546
  return {
@@ -2558,8 +2558,8 @@ function Rr(e, t = []) {
2558
2558
  var f, l, c;
2559
2559
  const s = Ct(r.id, t) ?? Pr(e, r), o = Array.isArray((f = s == null ? void 0 : s.additionalKwargs) == null ? void 0 : f.toolProgress) ? (l = s == null ? void 0 : s.additionalKwargs) == null ? void 0 : l.toolProgress : void 0, a = (s == null ? void 0 : s.artifact) ?? r.artifact, i = Ht(r.status) ?? ((c = s == null ? void 0 : s.additionalKwargs) != null && c.toolStreaming ? "pending" : null) ?? (s ? "completed" : "pending");
2560
2560
  if (s && !r.content && i === "completed") {
2561
- const d = Me(s);
2562
- typeof d == "string" && (r.content = d);
2561
+ const u = Ee(s);
2562
+ typeof u == "string" && (r.content = u);
2563
2563
  }
2564
2564
  return {
2565
2565
  call: r,
@@ -2571,7 +2571,7 @@ function Rr(e, t = []) {
2571
2571
  });
2572
2572
  }
2573
2573
  function qs(e, t = []) {
2574
- return Rr(e, t).map((n) => n.artifact).filter((n) => !!n);
2574
+ return Nr(e, t).map((n) => n.artifact).filter((n) => !!n);
2575
2575
  }
2576
2576
  const tt = {
2577
2577
  authToken: "authToken",
@@ -2585,20 +2585,20 @@ const tt = {
2585
2585
  function Mt(e) {
2586
2586
  return `draft:${e}`;
2587
2587
  }
2588
- let wt = null;
2589
- const Nt = /* @__PURE__ */ new Set();
2588
+ let bt = null;
2589
+ const Rt = /* @__PURE__ */ new Set();
2590
2590
  function fn() {
2591
- return wt;
2591
+ return bt;
2592
2592
  }
2593
- function De(e) {
2594
- wt = e, Nt.forEach((t) => t(e));
2593
+ function Ve(e) {
2594
+ bt = e, Rt.forEach((t) => t(e));
2595
2595
  }
2596
2596
  function pn(e) {
2597
- return Nt.add(e), () => Nt.delete(e);
2597
+ return Rt.add(e), () => Rt.delete(e);
2598
2598
  }
2599
- const Nr = 12e4, _r = 12e4;
2600
- let _t = Nr, gn = _r;
2601
- const me = Fn.create({
2599
+ const Rr = 12e4, _r = 12e4;
2600
+ let _t = Rr, gn = _r;
2601
+ const he = Un.create({
2602
2602
  // BaseURL is set dynamically via ApiProvider -> api.updateConfig
2603
2603
  timeout: _t,
2604
2604
  withCredentials: !0
@@ -2608,18 +2608,18 @@ function Wt(e) {
2608
2608
  }
2609
2609
  function Lr(e) {
2610
2610
  const t = Wt(e.requestTimeoutMs), n = Wt(e.historyTimeoutMs);
2611
- t !== null && (_t = t, me.defaults.timeout = _t), n !== null && (gn = n);
2611
+ t !== null && (_t = t, he.defaults.timeout = _t), n !== null && (gn = n);
2612
2612
  }
2613
2613
  function zr() {
2614
2614
  return gn;
2615
2615
  }
2616
- me.interceptors.request.use((e) => (wt && (e.headers.Authorization = `Bearer ${wt}`), e));
2617
- me.interceptors.response.use(
2616
+ he.interceptors.request.use((e) => (bt && (e.headers.Authorization = `Bearer ${bt}`), e));
2617
+ he.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, s = typeof t.expires_at == "number" && t.expires_at || typeof n.expires_at == "number" && n.expires_at || typeof t.expiresAt == "number" && t.expiresAt || typeof n.expiresAt == "number" && n.expiresAt || null;
2622
- r && (localStorage.setItem(tt.authToken, r), De(r)), s && localStorage.setItem(tt.authTokenExpiresAt, s.toString()), (r || s) && window.dispatchEvent(
2622
+ r && (localStorage.setItem(tt.authToken, r), Ve(r)), s && localStorage.setItem(tt.authTokenExpiresAt, s.toString()), (r || s) && window.dispatchEvent(
2623
2623
  new CustomEvent("smartorg:chat-token-updated", {
2624
2624
  detail: { token: r, expiresAt: s }
2625
2625
  })
@@ -2632,35 +2632,35 @@ me.interceptors.response.use(
2632
2632
  (e) => Promise.reject(e)
2633
2633
  );
2634
2634
  async function ke(e, t) {
2635
- return me.defaults.baseURL ? (await me.get(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2635
+ return he.defaults.baseURL ? (await he.get(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2636
2636
  }
2637
2637
  async function dt(e, t, n) {
2638
- return me.defaults.baseURL ? (await me.post(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2638
+ return he.defaults.baseURL ? (await he.post(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2639
2639
  }
2640
- async function Ur(e, t, n) {
2641
- return me.defaults.baseURL ? (await me.put(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2640
+ async function Fr(e, t, n) {
2641
+ return he.defaults.baseURL ? (await he.put(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2642
2642
  }
2643
2643
  async function Gt(e, t) {
2644
- return me.defaults.baseURL ? (await me.delete(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2644
+ return he.defaults.baseURL ? (await he.delete(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2645
2645
  }
2646
- function ye(e) {
2646
+ function be(e) {
2647
2647
  return e && typeof e == "object" && "data" in e ? e.data : e;
2648
2648
  }
2649
- class Fr {
2649
+ class Ur {
2650
2650
  // ---- Configuration ----
2651
2651
  // Chat client uses the default httpClient baseURL, no need for internal tracking
2652
2652
  // unless we want to support multiple instances with different URLs in the future.
2653
2653
  get baseUrl() {
2654
- return me.defaults.baseURL || "";
2654
+ return he.defaults.baseURL || "";
2655
2655
  }
2656
2656
  updateConfig(t) {
2657
2657
  if (t.chatBaseUrl)
2658
- me.defaults.baseURL = t.chatBaseUrl;
2658
+ he.defaults.baseURL = t.chatBaseUrl;
2659
2659
  else if (t.baseUrl) {
2660
2660
  const n = t.baseUrl.replace(/\/+$/, "");
2661
- n.endsWith("/chat") ? me.defaults.baseURL = n : me.defaults.baseURL = `${n}/chat`;
2661
+ n.endsWith("/chat") ? he.defaults.baseURL = n : he.defaults.baseURL = `${n}/chat`;
2662
2662
  }
2663
- t.apiKey !== void 0 ? De(t.apiKey) : t.getToken && De(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Lr({
2663
+ t.apiKey !== void 0 ? Ve(t.apiKey) : t.getToken && Ve(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Lr({
2664
2664
  requestTimeoutMs: t.requestTimeoutMs,
2665
2665
  historyTimeoutMs: t.historyTimeoutMs
2666
2666
  });
@@ -2670,18 +2670,18 @@ class Fr {
2670
2670
  return fn();
2671
2671
  }
2672
2672
  setAuthToken(t) {
2673
- De(t);
2673
+ Ve(t);
2674
2674
  }
2675
2675
  onTokenChange(t) {
2676
2676
  return pn(t);
2677
2677
  }
2678
2678
  // ---- Thread Management ----
2679
2679
  async listThreads() {
2680
- const t = await ke("/threads"), n = ye(t);
2680
+ const t = await ke("/threads"), n = be(t);
2681
2681
  return (n == null ? void 0 : n.items) ?? (t == null ? void 0 : t.items) ?? [];
2682
2682
  }
2683
2683
  async listSharedThreads() {
2684
- const t = await ke("/threads/shared"), n = ye(t);
2684
+ const t = await ke("/threads/shared"), n = be(t);
2685
2685
  return (n == null ? void 0 : n.items) ?? (t == null ? void 0 : t.items) ?? [];
2686
2686
  }
2687
2687
  // listUsers moved to AuthApi
@@ -2689,38 +2689,38 @@ class Fr {
2689
2689
  const r = {};
2690
2690
  t && (r.title = t), n && (r.project = n);
2691
2691
  const s = await dt("/threads", Object.keys(r).length ? r : void 0);
2692
- return ye(s);
2692
+ return be(s);
2693
2693
  }
2694
2694
  async updateThread(t, n) {
2695
- const r = await Ur(`/threads/${t}`, { title: n });
2696
- return ye(r);
2695
+ const r = await Fr(`/threads/${t}`, { title: n });
2696
+ return be(r);
2697
2697
  }
2698
2698
  async deleteThread(t) {
2699
2699
  const n = await Gt(`/threads/${t}`);
2700
- return ye(n);
2700
+ return be(n);
2701
2701
  }
2702
2702
  async shareThread(t, n) {
2703
2703
  const r = await dt(`/threads/${t}/share`, {
2704
2704
  shared_with_user_id: n
2705
2705
  });
2706
- return ye(r);
2706
+ return be(r);
2707
2707
  }
2708
2708
  async threadInfo(t) {
2709
2709
  const n = await ke(`/threads/${t}/info`);
2710
- return ye(n);
2710
+ return be(n);
2711
2711
  }
2712
2712
  // ---- Agents ----
2713
2713
  async listAgents() {
2714
- const t = await ke("/agents"), n = ye(t);
2714
+ const t = await ke("/agents"), n = be(t);
2715
2715
  return (n == null ? void 0 : n.items) ?? [];
2716
2716
  }
2717
2717
  async getAgent(t) {
2718
2718
  const n = await ke(`/agents/${t}`);
2719
- return ye(n);
2719
+ return be(n);
2720
2720
  }
2721
2721
  async getAgentSchema(t) {
2722
2722
  const n = await ke(`/agents/${t}/schema`);
2723
- return ye(n);
2723
+ return be(n);
2724
2724
  }
2725
2725
  async getState(t) {
2726
2726
  const n = await ke(`/threads/${t.threadId}/state`, {
@@ -2729,7 +2729,7 @@ class Fr {
2729
2729
  checkpoint_ns: t.checkpointNs
2730
2730
  }
2731
2731
  });
2732
- return ye(n);
2732
+ return be(n);
2733
2733
  }
2734
2734
  async getStateHistory(t) {
2735
2735
  const n = await ke(`/threads/${t.threadId}/state/history`, {
@@ -2743,19 +2743,19 @@ class Fr {
2743
2743
  timeout: zr(),
2744
2744
  signal: t.signal
2745
2745
  });
2746
- return ye(n);
2746
+ return be(n);
2747
2747
  }
2748
2748
  // ---- Run Management ----
2749
2749
  async cancelRun(t) {
2750
2750
  const n = await dt("/stream/cancel", { threadId: t });
2751
- return ye(n);
2751
+ return be(n);
2752
2752
  }
2753
2753
  async unshareThread(t, n) {
2754
2754
  const r = await Gt(`/threads/${t}/share/${n}`);
2755
- return ye(r);
2755
+ return be(r);
2756
2756
  }
2757
2757
  }
2758
- const mn = new Fr();
2758
+ const mn = new Ur();
2759
2759
  class jr {
2760
2760
  // Config logic could go here if files ever need a distinct base URL from chat
2761
2761
  // For now, it shares the chatBaseUrl via the shared httpClient
@@ -2822,7 +2822,7 @@ const hn = new jr();
2822
2822
  class Or {
2823
2823
  constructor() {
2824
2824
  // ---- Configuration ----
2825
- $t(this, "_authBaseUrl", "");
2825
+ Bt(this, "_authBaseUrl", "");
2826
2826
  }
2827
2827
  get baseUrl() {
2828
2828
  return this._authBaseUrl;
@@ -2834,14 +2834,14 @@ class Or {
2834
2834
  const n = t.baseUrl.replace(/\/+$/, "");
2835
2835
  this._authBaseUrl = `${n}/auth`;
2836
2836
  }
2837
- t.apiKey !== void 0 ? De(t.apiKey) : t.getToken && De(t.getToken());
2837
+ t.apiKey !== void 0 ? Ve(t.apiKey) : t.getToken && Ve(t.getToken());
2838
2838
  }
2839
2839
  // ---- Token Management ----
2840
2840
  getAuthToken() {
2841
2841
  return fn();
2842
2842
  }
2843
2843
  setAuthToken(t) {
2844
- De(t);
2844
+ Ve(t);
2845
2845
  }
2846
2846
  onTokenChange(t) {
2847
2847
  return pn(t);
@@ -2852,7 +2852,7 @@ class Or {
2852
2852
  return (t == null ? void 0 : t.users) ?? [];
2853
2853
  }
2854
2854
  }
2855
- const $r = new Or(), yn = We(null);
2855
+ const $r = new Or(), yn = Ge(null);
2856
2856
  function Br({ children: e, apiConfig: t }) {
2857
2857
  const n = mn, r = $r;
2858
2858
  if (t) {
@@ -2944,7 +2944,7 @@ function Js(e) {
2944
2944
  }).join("|") : "", r = "checkpointId" in e && e.checkpointId ? `cp:${e.checkpointId}` : "", s = "checkpointNs" in e && e.checkpointNs ? `ns:${e.checkpointNs}` : "", o = [r, s].filter(Boolean).join("|");
2945
2945
  return `${e.id}:${t}:${n}${o ? `:${o}` : ""}`;
2946
2946
  }
2947
- function qe() {
2947
+ function We() {
2948
2948
  const e = ot(yn);
2949
2949
  if (!e) throw new Error("useApi must be used within ApiProvider");
2950
2950
  return e;
@@ -2991,16 +2991,16 @@ function Jt(e) {
2991
2991
  async function Gr(e, t) {
2992
2992
  var i, f;
2993
2993
  if (!e) return e ?? null;
2994
- const n = Ee(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], s = /* @__PURE__ */ new Set();
2994
+ const n = Pe(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], s = /* @__PURE__ */ new Set();
2995
2995
  for (const l of r) {
2996
2996
  const c = (i = l == null ? void 0 : l.values) == null ? void 0 : i.messages;
2997
2997
  if (Array.isArray(c))
2998
- for (const d of c) {
2999
- const g = d == null ? void 0 : d.content;
2998
+ for (const u of c) {
2999
+ const g = u == null ? void 0 : u.content;
3000
3000
  if (Array.isArray(g))
3001
- for (const h of g) {
3002
- if (!h || typeof h != "object" || h.type !== "image_url" && h.type !== "file") continue;
3003
- const k = h.fileId || h.file_id;
3001
+ for (const m of g) {
3002
+ if (!m || typeof m != "object" || m.type !== "image_url" && m.type !== "file") continue;
3003
+ const k = m.fileId || m.file_id;
3004
3004
  typeof k == "string" && k.trim() && s.add(k);
3005
3005
  }
3006
3006
  }
@@ -3010,8 +3010,8 @@ async function Gr(e, t) {
3010
3010
  const o = await Promise.all(
3011
3011
  Array.from(s).map(async (l) => {
3012
3012
  try {
3013
- const c = await t.getFileInfo(l), d = Ee(c);
3014
- return [l, d];
3013
+ const c = await t.getFileInfo(l), u = Pe(c);
3014
+ return [l, u];
3015
3015
  } catch {
3016
3016
  return [l, null];
3017
3017
  }
@@ -3020,22 +3020,22 @@ async function Gr(e, t) {
3020
3020
  for (const l of r) {
3021
3021
  const c = (f = l == null ? void 0 : l.values) == null ? void 0 : f.messages;
3022
3022
  if (Array.isArray(c))
3023
- for (const d of c) {
3024
- const g = d == null ? void 0 : d.content;
3023
+ for (const u of c) {
3024
+ const g = u == null ? void 0 : u.content;
3025
3025
  if (Array.isArray(g))
3026
- for (const h of g) {
3027
- if (!h || typeof h != "object" || h.type !== "image_url" && h.type !== "file") continue;
3028
- const k = h.fileId || h.file_id;
3026
+ for (const m of g) {
3027
+ if (!m || typeof m != "object" || m.type !== "image_url" && m.type !== "file") continue;
3028
+ const k = m.fileId || m.file_id;
3029
3029
  if (!k) continue;
3030
- const m = a.get(k), y = (m == null ? void 0 : m.contentUrl) || (m == null ? void 0 : m.content_url);
3031
- y && (h.type === "image_url" ? (h.imageUrl = h.imageUrl || {}, h.imageUrl.url = y) : h.type === "file" && (h.url = y, !h.name && (m != null && m.filename || m != null && m.name) && (h.name = (m == null ? void 0 : m.filename) || (m == null ? void 0 : m.name))));
3030
+ const p = a.get(k), y = (p == null ? void 0 : p.contentUrl) || (p == null ? void 0 : p.content_url);
3031
+ y && (m.type === "image_url" ? (m.imageUrl = m.imageUrl || {}, m.imageUrl.url = y) : m.type === "file" && (m.url = y, !m.name && (p != null && p.filename || p != null && p.name) && (m.name = (p == null ? void 0 : p.filename) || (p == null ? void 0 : p.name))));
3032
3032
  }
3033
3033
  }
3034
3034
  }
3035
3035
  return n;
3036
3036
  }
3037
- function ft(e) {
3038
- const r = [...(Array.isArray(e == null ? void 0 : e.checkpoints) ? (e == null ? void 0 : e.checkpoints) ?? [] : e != null && e.checkpoints ? Object.values(e.checkpoints) : []).map((o, a) => Jr(Ee(o), a)).filter((o) => !!o)].sort((o, a) => Xt(a.createdAt) - Xt(o.createdAt)), s = r[0] ?? null;
3037
+ function Lt(e) {
3038
+ const r = [...(Array.isArray(e == null ? void 0 : e.checkpoints) ? (e == null ? void 0 : e.checkpoints) ?? [] : e != null && e.checkpoints ? Object.values(e.checkpoints) : []).map((o, a) => Jr(Pe(o), a)).filter((o) => !!o)].sort((o, a) => Xt(a.createdAt) - Xt(o.createdAt)), s = r[0] ?? null;
3039
3039
  return {
3040
3040
  threadId: (e == null ? void 0 : e.threadId) ?? "",
3041
3041
  latest: s,
@@ -3046,36 +3046,36 @@ function ft(e) {
3046
3046
  function Jr(e, t) {
3047
3047
  var z, w;
3048
3048
  if (!e) return null;
3049
- const n = ((z = e.values) == null ? void 0 : z.activeAgent) ?? null, r = (w = e.values) == null ? void 0 : w.messages, o = (Array.isArray(r) ? r : []).map((v) => Xr(v, n)).filter((v) => !!v), a = nt(e.metadata) ?? {}, i = Jt(e.config), f = nt(e.parentConfig), l = Jt(f), c = ut(i, ["checkpointId"]), d = ut(i, ["checkpointNs"]), g = ut(l, ["checkpointId"]), h = nt(e.config), k = Array.isArray(e.tasks) ? e.tasks.map((v) => ({ ...v })) : e.tasks ?? null, m = Array.isArray(e.next) ? [...e.next] : e.next ?? null, y = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), I = {
3049
+ const n = ((z = e.values) == null ? void 0 : z.activeAgent) ?? null, r = (w = e.values) == null ? void 0 : w.messages, o = (Array.isArray(r) ? r : []).map((I) => Xr(I, n)).filter((I) => !!I), a = nt(e.metadata) ?? {}, i = Jt(e.config), f = nt(e.parentConfig), l = Jt(f), c = ut(i, ["checkpointId"]), u = ut(i, ["checkpointNs"]), g = ut(l, ["checkpointId"]), m = nt(e.config), k = Array.isArray(e.tasks) ? e.tasks.map((I) => ({ ...I })) : e.tasks ?? null, p = Array.isArray(e.next) ? [...e.next] : e.next ?? null, y = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), v = {
3050
3050
  ...a,
3051
3051
  step: Wr(a, ["step"]) ?? 0,
3052
3052
  source: ut(a, ["source"]) ?? null
3053
- }, S = o.map((v) => ({
3054
- ...v,
3055
- checkpointId: v.checkpointId ?? c ?? null,
3056
- checkpointNs: v.checkpointNs ?? d ?? null
3057
- })), C = e.values, L = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(C == null ? void 0 : C.interrupts) ? C.interrupts : [];
3053
+ }, A = o.map((I) => ({
3054
+ ...I,
3055
+ checkpointId: I.checkpointId ?? c ?? null,
3056
+ checkpointNs: I.checkpointNs ?? u ?? null
3057
+ })), x = e.values, L = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(x == null ? void 0 : x.interrupts) ? x.interrupts : [];
3058
3058
  return {
3059
3059
  checkpointId: c ?? null,
3060
- checkpointNs: d ?? null,
3060
+ checkpointNs: u ?? null,
3061
3061
  createdAt: y,
3062
3062
  parentId: g ?? null,
3063
- messages: S,
3063
+ messages: A,
3064
3064
  interrupt: Qr(
3065
3065
  L,
3066
3066
  t,
3067
3067
  c ?? null
3068
3068
  ),
3069
- metadata: I,
3070
- config: h ?? null,
3069
+ metadata: v,
3070
+ config: m ?? null,
3071
3071
  parentConfig: f ?? null,
3072
- next: m,
3072
+ next: p,
3073
3073
  tasks: k,
3074
3074
  values: e.values ?? {}
3075
3075
  };
3076
3076
  }
3077
3077
  function Xr(e, t) {
3078
- const n = bt(e);
3078
+ const n = yt(e);
3079
3079
  return n ? (n.role === "assistant" && !n.name && t && (n.name = t), n) : null;
3080
3080
  }
3081
3081
  function Qr(e, t, n) {
@@ -3103,57 +3103,57 @@ function Yr(e) {
3103
3103
  return !!e && typeof e == "object" && "data" in e;
3104
3104
  }
3105
3105
  function Zr(e = {}) {
3106
- const t = e.baseUrl || "", n = e.streamPath ?? "/stream", [r, s] = W(e.token ?? null), o = H(e.headers ?? {}), a = e.credentials ?? "include", i = H(e);
3107
- se(() => {
3106
+ const t = e.baseUrl || "", n = e.streamPath ?? "/stream", [r, s] = q(e.token ?? null), o = V(e.headers ?? {}), a = e.credentials ?? "include", i = V(e);
3107
+ oe(() => {
3108
3108
  i.current = e;
3109
3109
  }, [e]);
3110
- const f = E((T) => {
3111
- var x, q, U, ne, ee, Y, j, re, be, ve;
3112
- const p = i.current;
3113
- if (!p) return;
3110
+ const f = C((T) => {
3111
+ var h, U, H, Y, N, ae, W, Z, X, Ie;
3112
+ const P = i.current;
3113
+ if (!P) return;
3114
3114
  if (T.type === "thread_info") {
3115
- (x = p.onThreadInfo) == null || x.call(p, T);
3115
+ (h = P.onThreadInfo) == null || h.call(P, T);
3116
3116
  return;
3117
3117
  }
3118
3118
  if (T.type === "values" && Array.isArray(T.checkpoints)) {
3119
- (q = p.handleValuesEvent) == null || q.call(p, T);
3119
+ (U = P.handleValuesEvent) == null || U.call(P, T);
3120
3120
  return;
3121
3121
  }
3122
3122
  if (T.type === "metadata") {
3123
- (U = p.onMetadataEvent) == null || U.call(p, T);
3123
+ (H = P.onMetadataEvent) == null || H.call(P, T);
3124
3124
  return;
3125
3125
  }
3126
3126
  if (typeof T.type == "string" && (T.type === "custom" || T.type.startsWith("custom."))) {
3127
- (ne = p.onCustomEvent) == null || ne.call(p, T);
3127
+ (Y = P.onCustomEvent) == null || Y.call(P, T);
3128
3128
  return;
3129
3129
  }
3130
- (ee = p.onEvent) == null || ee.call(p, T), T.type === "updates" && ((Y = p.onUpdateEvent) == null || Y.call(p, T)), T.type === "tool.end" ? (j = p.onToolEnd) == null || j.call(p, T) : T.type === "tool.start" && ((re = p.onToolStart) == null || re.call(p, T)), T.type === "heartbeat" && ((be = p.onHeartbeat) == null || be.call(p, T)), T.type === "token" && ((ve = p.onToken) == null || ve.call(p, T.token));
3131
- }, []), [l, c] = W(!1), [d, g] = W(null), [h, k] = W(""), [m, y] = W(null), [I, S] = W(0), [C, L] = W(!1), [z, w] = W({}), [v, F] = W(null), [$, B] = W({}), D = H(null), P = H(!0), J = H(0), G = H(null), Q = H(null), X = H(null), oe = H(null), A = H([]), R = H(/* @__PURE__ */ new Set()), V = H({
3130
+ (N = P.onEvent) == null || N.call(P, T), T.type === "updates" && ((ae = P.onUpdateEvent) == null || ae.call(P, T)), T.type === "tool.end" ? (W = P.onToolEnd) == null || W.call(P, T) : T.type === "tool.start" && ((Z = P.onToolStart) == null || Z.call(P, T)), T.type === "heartbeat" && ((X = P.onHeartbeat) == null || X.call(P, T)), T.type === "token" && ((Ie = P.onToken) == null || Ie.call(P, T.token));
3131
+ }, []), [l, c] = q(!1), [u, g] = q(null), [m, k] = q(""), [p, y] = q(null), [v, A] = q(0), [x, L] = q(!1), [z, w] = q({}), [I, F] = q(null), [$, B] = q({}), D = V(null), M = V(!0), Q = V(0), G = V(null), re = V(null), te = V(null), se = V(null), S = V([]), E = V(/* @__PURE__ */ new Set()), O = V({
3132
3132
  messageId: null,
3133
3133
  lastSeq: null,
3134
3134
  lastText: ""
3135
- }), K = E((T) => {
3135
+ }), K = C((T) => {
3136
3136
  s(T);
3137
- }, []), u = E(() => {
3138
- k(""), y(null), g(null), Q.current = null, X.current = null, oe.current = null, A.current = [], R.current = /* @__PURE__ */ new Set(), w({}), F(null), B({}), V.current = {
3137
+ }, []), d = C(() => {
3138
+ k(""), y(null), g(null), re.current = null, te.current = null, se.current = null, S.current = [], E.current = /* @__PURE__ */ new Set(), w({}), F(null), B({}), O.current = {
3139
3139
  messageId: null,
3140
3140
  lastSeq: null,
3141
3141
  lastText: ""
3142
3142
  };
3143
- }, []), N = E(() => {
3144
- var x;
3143
+ }, []), R = C(() => {
3144
+ var h;
3145
3145
  console.debug("[use-chat] stop() invoked - aborting stream");
3146
- const T = (x = G.current) == null ? void 0 : x.threadId, p = () => {
3147
- var q;
3148
- (q = D.current) == null || q.abort(), D.current = null, G.current = null, c(!1), L(!1), J.current = 0, S(0);
3146
+ const T = (h = G.current) == null ? void 0 : h.threadId, P = () => {
3147
+ var U;
3148
+ (U = D.current) == null || U.abort(), D.current = null, G.current = null, c(!1), L(!1), Q.current = 0, A(0);
3149
3149
  };
3150
- (T ? mn.cancelRun(T).catch((q) => {
3151
- console.warn("[use-chat] cancel run failed:", q);
3152
- }) : Promise.resolve()).finally(p);
3153
- }, []), _ = E(
3150
+ (T ? mn.cancelRun(T).catch((U) => {
3151
+ console.warn("[use-chat] cancel run failed:", U);
3152
+ }) : Promise.resolve()).finally(P);
3153
+ }, []), _ = C(
3154
3154
  (T) => {
3155
3155
  D.current && (D.current.abort(), D.current = null);
3156
- const p = {
3156
+ const P = {
3157
3157
  text: typeof T.content == "string" ? T.content : T.text,
3158
3158
  threadId: T.threadId,
3159
3159
  attachments: T.attachments,
@@ -3164,59 +3164,59 @@ function Zr(e = {}) {
3164
3164
  edit: T.edit,
3165
3165
  command: T.command
3166
3166
  };
3167
- c(!0), g(null), k(""), y(null), Q.current = null, X.current = null, oe.current = null, A.current = [], R.current = /* @__PURE__ */ new Set(), w({}), F(null), B({}), V.current = {
3167
+ c(!0), g(null), k(""), y(null), re.current = null, te.current = null, se.current = null, S.current = [], E.current = /* @__PURE__ */ new Set(), w({}), F(null), B({}), O.current = {
3168
3168
  messageId: null,
3169
3169
  lastSeq: null,
3170
3170
  lastText: ""
3171
3171
  };
3172
- const M = new AbortController();
3173
- D.current = M;
3174
- let x = null, q = !1;
3175
- const U = (ne) => {
3176
- if (R.current.has(ne)) return;
3177
- const ee = A.current[0];
3178
- ee && w((Y) => {
3179
- let j = v;
3180
- if (!j) {
3181
- const fe = Object.values(Y).filter((Fe) => Fe.role === "assistant");
3182
- fe.length > 0 && (j = fe[fe.length - 1].id);
3172
+ const J = new AbortController();
3173
+ D.current = J;
3174
+ let h = null, U = !1;
3175
+ const H = (Y) => {
3176
+ if (E.current.has(Y)) return;
3177
+ const N = S.current[0];
3178
+ N && w((ae) => {
3179
+ let W = I;
3180
+ if (!W) {
3181
+ const le = Object.values(ae).filter((Me) => Me.role === "assistant");
3182
+ le.length > 0 && (W = le[le.length - 1].id);
3183
3183
  }
3184
- if (!j || !Y[j]) return Y;
3185
- const re = Y[j], be = [...re.toolCalls || []], ve = ee.id ?? `task-${ne}`;
3186
- return be.some((fe) => fe.id === ve && fe.name === "task" && fe.scope === ne) || be.push({
3187
- id: ve,
3184
+ if (!W || !ae[W]) return ae;
3185
+ const Z = ae[W], X = [...Z.toolCalls || []], Ie = N.id ?? `task-${Y}`;
3186
+ return X.some((le) => le.id === Ie && le.name === "task" && le.scope === Y) || X.push({
3187
+ id: Ie,
3188
3188
  name: "task",
3189
3189
  args: {
3190
- description: ee.description,
3191
- subagentType: ee.subagentType
3190
+ description: N.description,
3191
+ subagentType: N.subagentType
3192
3192
  },
3193
3193
  status: "running",
3194
- content: ee.description,
3195
- scope: ne
3196
- }), R.current.add(ne), A.current.shift(), { ...Y, [j]: { ...re, toolCalls: be } };
3194
+ content: N.description,
3195
+ scope: Y
3196
+ }), E.current.add(Y), S.current.shift(), { ...ae, [W]: { ...Z, toolCalls: X } };
3197
3197
  });
3198
3198
  };
3199
3199
  return G.current = {
3200
- threadId: p.threadId ?? null,
3200
+ threadId: P.threadId ?? null,
3201
3201
  headers: {},
3202
3202
  isStreaming: !0
3203
3203
  }, (async () => {
3204
- var ne, ee, Y, j, re, be, ve, Je, fe, Fe, je, Xe;
3204
+ var Y, N, ae, W, Z, X, Ie, Fe, le, Me, Oe, Xe;
3205
3205
  try {
3206
3206
  let Te = {};
3207
3207
  try {
3208
3208
  if (r)
3209
3209
  Te = { Authorization: `Bearer ${r}` };
3210
3210
  else if (typeof window < "u") {
3211
- const Se = window.__AUTH_TOKEN__, Tt = ((ne = window.localStorage) == null ? void 0 : ne.getItem(tt.authToken)) || null;
3211
+ const Se = window.__AUTH_TOKEN__, vt = ((Y = window.localStorage) == null ? void 0 : Y.getItem(tt.authToken)) || null;
3212
3212
  let ct = null;
3213
3213
  try {
3214
- const lt = (ee = window.localStorage) == null ? void 0 : ee.getItem(tt.chatSettings);
3215
- lt && (ct = ((Y = JSON.parse(lt)) == null ? void 0 : Y.apiKey) || null);
3214
+ const lt = (N = window.localStorage) == null ? void 0 : N.getItem(tt.chatSettings);
3215
+ lt && (ct = ((ae = JSON.parse(lt)) == null ? void 0 : ae.apiKey) || null);
3216
3216
  } catch {
3217
3217
  }
3218
- const Ke = Se || Tt || ct || null;
3219
- Ke && (Te = { Authorization: `Bearer ${Ke}` });
3218
+ const He = Se || vt || ct || null;
3219
+ He && (Te = { Authorization: `Bearer ${He}` });
3220
3220
  }
3221
3221
  } catch {
3222
3222
  }
@@ -3224,225 +3224,225 @@ function Zr(e = {}) {
3224
3224
  let Ae = {};
3225
3225
  if (typeof window < "u")
3226
3226
  try {
3227
- const ue = (j = window.localStorage) == null ? void 0 : j.getItem(tt.authSessionId);
3228
- ue && (Ae = { "X-Session-Id": ue });
3227
+ const fe = (W = window.localStorage) == null ? void 0 : W.getItem(tt.authSessionId);
3228
+ fe && (Ae = { "X-Session-Id": fe });
3229
3229
  } catch {
3230
3230
  }
3231
- const Ve = {
3231
+ const Ke = {
3232
3232
  ...Te,
3233
3233
  ...Ae,
3234
3234
  ...o.current
3235
- }, It = {
3235
+ }, kt = {
3236
3236
  "Content-Type": "application/json",
3237
3237
  Accept: "text/event-stream",
3238
- ...Ve
3239
- }, Ie = await fetch(t + n, {
3238
+ ...Ke
3239
+ }, ve = await fetch(t + n, {
3240
3240
  method: "POST",
3241
- headers: It,
3242
- body: JSON.stringify(p),
3243
- signal: M.signal,
3241
+ headers: kt,
3242
+ body: JSON.stringify(P),
3243
+ signal: J.signal,
3244
3244
  credentials: a
3245
3245
  });
3246
- if (G.current && (G.current.headers = Ve), !Ie.ok || !Ie.body) {
3247
- const ue = await Ie.text().catch(() => "");
3246
+ if (G.current && (G.current.headers = Ke), !ve.ok || !ve.body) {
3247
+ const fe = await ve.text().catch(() => "");
3248
3248
  console.debug(
3249
3249
  "[use-chat] non-OK response",
3250
- Ie.status,
3251
- ue == null ? void 0 : ue.slice(0, 500)
3250
+ ve.status,
3251
+ fe == null ? void 0 : fe.slice(0, 500)
3252
3252
  );
3253
- const Se = `stream ${Ie.status}${ue ? ": " + ue : ""}`;
3254
- throw Se && (g(Se), x = "error"), new Error(Se);
3253
+ const Se = `stream ${ve.status}${fe ? ": " + fe : ""}`;
3254
+ throw Se && (g(Se), h = "error"), new Error(Se);
3255
3255
  }
3256
3256
  L(!0);
3257
- const Qe = Ie.body.getReader(), Cn = new TextDecoder();
3258
- let Oe = "", it = [];
3259
- J.current = 0, S(0);
3260
- let Ye = 0, $e = null;
3261
- const vt = () => {
3257
+ const Qe = ve.body.getReader(), Cn = new TextDecoder();
3258
+ let $e = "", it = [];
3259
+ Q.current = 0, A(0);
3260
+ let Ye = 0, Be = null;
3261
+ const It = () => {
3262
3262
  if (it.length) {
3263
- const ue = it.join("");
3264
- it = [], P.current && k((Se) => Se + ue);
3263
+ const fe = it.join("");
3264
+ it = [], M.current && k((Se) => Se + fe);
3265
3265
  }
3266
- $e = null;
3266
+ Be = null;
3267
3267
  }, Mn = () => {
3268
- typeof window < "u" && $e == null && ($e = requestAnimationFrame(vt));
3268
+ typeof window < "u" && Be == null && (Be = requestAnimationFrame(It));
3269
3269
  };
3270
- let Ft = Date.now();
3270
+ let jt = Date.now();
3271
3271
  const En = setInterval(() => {
3272
- Date.now() - Ft > 18e5 && (g("Stream idle timeout"), x = "error", M.abort());
3272
+ Date.now() - jt > 18e5 && (g("Stream idle timeout"), h = "error", J.abort());
3273
3273
  }, 5e3), Pn = 1024 * 1024;
3274
3274
  try {
3275
- const Se = (Ie.headers.get("X-Thread-Id") || Ie.headers.get("x-thread-id")) ?? null;
3275
+ const Se = (ve.headers.get("X-Thread-Id") || ve.headers.get("x-thread-id")) ?? null;
3276
3276
  for (G.current && !G.current.threadId && (G.current = {
3277
3277
  ...G.current,
3278
3278
  threadId: Se
3279
3279
  }); ; ) {
3280
- const { value: Tt, done: ct } = await Qe.read();
3280
+ const { value: vt, done: ct } = await Qe.read();
3281
3281
  if (ct) break;
3282
- Oe += Cn.decode(Tt, { stream: !0 }), Oe.length > Pn && (Oe = "", console.warn("Stream buffer reset: exceeded 1MB"));
3283
- let Ke;
3284
- for (; (Ke = Oe.indexOf(`
3282
+ $e += Cn.decode(vt, { stream: !0 }), $e.length > Pn && ($e = "", console.warn("Stream buffer reset: exceeded 1MB"));
3283
+ let He;
3284
+ for (; (He = $e.indexOf(`
3285
3285
 
3286
3286
  `)) >= 0; ) {
3287
- const lt = Oe.slice(0, Ke);
3288
- Oe = Oe.slice(Ke + 2);
3289
- const Rn = lt.split(/\r?\n/), jt = [];
3290
- let At = null;
3291
- for (const b of Rn) {
3287
+ const lt = $e.slice(0, He);
3288
+ $e = $e.slice(He + 2);
3289
+ const Nn = lt.split(/\r?\n/), Ot = [];
3290
+ let Tt = null;
3291
+ for (const b of Nn) {
3292
3292
  if (b.startsWith(":")) {
3293
3293
  b.startsWith(": heartbeat") && console.debug("[use-chat] SSE heartbeat comment received");
3294
3294
  continue;
3295
3295
  }
3296
3296
  if (b) {
3297
3297
  if (b.startsWith("event:")) {
3298
- const ce = b.slice(6).trim();
3299
- ce && (At = ce);
3298
+ const ue = b.slice(6).trim();
3299
+ ue && (Tt = ue);
3300
3300
  continue;
3301
3301
  }
3302
3302
  if (b.startsWith("data:")) {
3303
- const ce = b.slice(5);
3304
- jt.push(ce.startsWith(" ") ? ce.slice(1) : ce);
3303
+ const ue = b.slice(5);
3304
+ Ot.push(ue.startsWith(" ") ? ue.slice(1) : ue);
3305
3305
  }
3306
3306
  }
3307
3307
  }
3308
- const St = jt.join(`
3308
+ const At = Ot.join(`
3309
3309
  `);
3310
- if (!St) continue;
3311
- let Pe;
3310
+ if (!At) continue;
3311
+ let Ne;
3312
3312
  try {
3313
- Pe = JSON.parse(St);
3313
+ Ne = JSON.parse(At);
3314
3314
  } catch {
3315
- console.debug("[use-chat] malformed SSE:", St.slice(0, 200));
3315
+ console.debug("[use-chat] malformed SSE:", At.slice(0, 200));
3316
3316
  continue;
3317
3317
  }
3318
- At && typeof Pe == "object" && Pe !== null && !("type" in Pe) && (Pe.type = At);
3319
- const Ot = Yr(Pe) ? Pe.data : Pe;
3320
- if (!Ot) {
3321
- console.warn("[use-chat] dropped envelope event without payload", Pe);
3318
+ Tt && typeof Ne == "object" && Ne !== null && !("type" in Ne) && (Ne.type = Tt);
3319
+ const $t = Yr(Ne) ? Ne.data : Ne;
3320
+ if (!$t) {
3321
+ console.warn("[use-chat] dropped envelope event without payload", Ne);
3322
3322
  continue;
3323
3323
  }
3324
- const ae = Cr(Ot);
3325
- Ft = Date.now();
3326
- const Be = ae.seq;
3327
- if (Be !== void 0) {
3328
- if (Be <= Ye) {
3329
- console.debug("[use-chat] drop duplicate/out-of-order event", { seq: Be, lastProcessedSeq: Ye, type: ae.type });
3324
+ const ie = Cr($t);
3325
+ jt = Date.now();
3326
+ const De = ie.seq;
3327
+ if (De !== void 0) {
3328
+ if (De <= Ye) {
3329
+ console.debug("[use-chat] drop duplicate/out-of-order event", { seq: De, lastProcessedSeq: Ye, type: ie.type });
3330
3330
  continue;
3331
3331
  }
3332
- Ye > 0 && Be > Ye + 1, Ye = Be, J.current = Be, S(Be);
3332
+ Ye > 0 && De > Ye + 1, Ye = De, Q.current = De, A(De);
3333
3333
  }
3334
- const Nn = ["messages/partial", "metadata", "checkpoint", "values", "heartbeat", "token", "status", "error", "interrupt", "tool.start", "tool.progress", "tool.end", "task.start"];
3335
- let we = ae.type || "unknown";
3336
- if (Nn.includes(we) || (ae.messages || ae.content !== void 0 && ae.id) && (we = "messages/partial"), we === "checkpoint") {
3337
- const b = ae;
3338
- Q.current = b.checkpointId ?? null, X.current = b.checkpointNs ?? null, y(b.checkpointId ?? null);
3334
+ const Rn = ["messages/partial", "metadata", "checkpoint", "values", "heartbeat", "token", "status", "error", "interrupt", "tool.start", "tool.progress", "tool.end", "task.start"];
3335
+ let we = ie.type || "unknown";
3336
+ if (Rn.includes(we) || (ie.messages || ie.content !== void 0 && ie.id) && (we = "messages/partial"), we === "checkpoint") {
3337
+ const b = ie;
3338
+ re.current = b.checkpointId ?? null, te.current = b.checkpointNs ?? null, y(b.checkpointId ?? null);
3339
3339
  } else if (we === "values") {
3340
- const b = ae, ce = b == null ? void 0 : b.origin, ie = b == null ? void 0 : b.scope;
3341
- ce === "task" && typeof ie == "string" && ie.startsWith("tools:") && U(ie);
3342
- const pe = ce === "task" || typeof ie == "string" && ie.startsWith("tools:");
3340
+ const b = ie, ue = b == null ? void 0 : b.origin, ce = b == null ? void 0 : b.scope;
3341
+ ue === "task" && typeof ce == "string" && ce.startsWith("tools:") && H(ce);
3342
+ const ge = ue === "task" || typeof ce == "string" && ce.startsWith("tools:");
3343
3343
  if (Array.isArray(b.checkpoints)) {
3344
- oe.current = b;
3344
+ se.current = b;
3345
3345
  try {
3346
- const le = ft(b).latest;
3347
- le && (Q.current = le.checkpointId ?? null, X.current = le.checkpointNs ?? null, y(le.checkpointId ?? null), pe || B(le.values ?? {})), pe || (w({}), F(null));
3348
- } catch (Z) {
3349
- console.warn("[use-chat] Failed to hydrate values payload", Z);
3346
+ const de = Lt(b).latest;
3347
+ de && (re.current = de.checkpointId ?? null, te.current = de.checkpointNs ?? null, y(de.checkpointId ?? null), ge || B(de.values ?? {})), ge || (w({}), F(null));
3348
+ } catch (ee) {
3349
+ console.warn("[use-chat] Failed to hydrate values payload", ee);
3350
3350
  }
3351
- } else if ((re = b.values) != null && re.messages)
3352
- pe || (w({}), F(null)), pe || B(b.values ?? {});
3351
+ } else if ((Z = b.values) != null && Z.messages)
3352
+ ge || (w({}), F(null)), ge || B(b.values ?? {});
3353
3353
  else {
3354
- const Z = b.values && typeof b.values == "object" ? b.values : b;
3355
- pe || B(Z ?? {});
3354
+ const ee = b.values && typeof b.values == "object" ? b.values : b;
3355
+ ge || B(ee ?? {});
3356
3356
  }
3357
3357
  }
3358
3358
  if (we === "task.start") {
3359
- const b = ae;
3360
- A.current.push({
3359
+ const b = ie;
3360
+ S.current.push({
3361
3361
  id: b.id ?? b.callId,
3362
3362
  description: b.description,
3363
3363
  subagentType: b.subagentType ?? b.subagent_type
3364
3364
  });
3365
3365
  }
3366
3366
  if (we === "tool.start" || we === "tool.progress" || we === "tool.end") {
3367
- const b = ae, ce = b.id || b.callId, ie = b.scope;
3368
- b.origin === "task" && typeof ie == "string" && ie.startsWith("tools:") && U(ie), ce && w((pe) => {
3369
- let Z = v;
3370
- if (!Z) {
3371
- const le = Object.values(pe).filter((ge) => ge.role === "assistant");
3372
- le.length > 0 && (Z = le[le.length - 1].id);
3367
+ const b = ie, ue = b.id || b.callId, ce = b.scope;
3368
+ b.origin === "task" && typeof ce == "string" && ce.startsWith("tools:") && H(ce), ue && w((ge) => {
3369
+ let ee = I;
3370
+ if (!ee) {
3371
+ const de = Object.values(ge).filter((me) => me.role === "assistant");
3372
+ de.length > 0 && (ee = de[de.length - 1].id);
3373
3373
  }
3374
- if (Z && pe[Z]) {
3375
- const le = pe[Z], ge = [...le.toolCalls || []], xe = ge.findIndex((Re) => Re.id === ce);
3376
- let he = b.content || b.status || "Processing...";
3377
- return ae.type === "tool.start" ? he = `Starting ${b.name || b.tool || "tool"}...` : ae.type === "tool.end" && b.error && (he = `Error: ${b.error}`), xe >= 0 ? ge[xe] = {
3378
- ...ge[xe],
3379
- content: he,
3380
- status: ae.type === "tool.start" ? "running" : ae.type === "tool.end" ? b.error ? "failed" : "completed" : ge[xe].status,
3381
- artifact: b.artifact || ge[xe].artifact,
3382
- scope: ie ?? ge[xe].scope
3383
- } : ge.push({
3384
- id: ce,
3374
+ if (ee && ge[ee]) {
3375
+ const de = ge[ee], me = [...de.toolCalls || []], xe = me.findIndex((Re) => Re.id === ue);
3376
+ let ye = b.content || b.status || "Processing...";
3377
+ return ie.type === "tool.start" ? ye = `Starting ${b.name || b.tool || "tool"}...` : ie.type === "tool.end" && b.error && (ye = `Error: ${b.error}`), xe >= 0 ? me[xe] = {
3378
+ ...me[xe],
3379
+ content: ye,
3380
+ status: ie.type === "tool.start" ? "running" : ie.type === "tool.end" ? b.error ? "failed" : "completed" : me[xe].status,
3381
+ artifact: b.artifact || me[xe].artifact,
3382
+ scope: ce ?? me[xe].scope
3383
+ } : me.push({
3384
+ id: ue,
3385
3385
  name: b.name || b.tool || "tool",
3386
3386
  args: b.args || {},
3387
- status: ae.type === "tool.end" ? b.error ? "failed" : "completed" : "running",
3388
- content: he,
3387
+ status: ie.type === "tool.end" ? b.error ? "failed" : "completed" : "running",
3388
+ content: ye,
3389
3389
  artifact: b.artifact,
3390
- scope: ie
3391
- }), { ...pe, [Z]: { ...le, toolCalls: ge } };
3390
+ scope: ce
3391
+ }), { ...ge, [ee]: { ...de, toolCalls: me } };
3392
3392
  }
3393
- return pe;
3393
+ return ge;
3394
3394
  });
3395
3395
  } else if (we === "messages/partial") {
3396
- const b = ae, ce = b.messages || [b];
3397
- if (Array.isArray(ce) && ce.length > 0) {
3398
- const ie = ce.find((Z) => Z.type === "ai"), pe = ce.find((Z) => Z.type === "tool");
3399
- if (ie) {
3400
- const Z = ie.id, le = ie.content ?? "", ge = !1, xe = ge ? (V.current.lastText || "") + le : le;
3401
- if (V.current.messageId !== Z) {
3402
- const he = ie.name ?? ie.agentName ?? "assistant";
3403
- V.current = {
3404
- messageId: Z,
3396
+ const b = ie, ue = b.messages || [b];
3397
+ if (Array.isArray(ue) && ue.length > 0) {
3398
+ const ce = ue.find((ee) => ee.type === "ai"), ge = ue.find((ee) => ee.type === "tool");
3399
+ if (ce) {
3400
+ const ee = ce.id, de = ce.content ?? "", me = !1, xe = me ? (O.current.lastText || "") + de : de;
3401
+ if (O.current.messageId !== ee) {
3402
+ const ye = ce.name ?? ce.agentName ?? "assistant";
3403
+ O.current = {
3404
+ messageId: ee,
3405
3405
  lastSeq: null,
3406
3406
  lastText: ""
3407
3407
  };
3408
- const Re = bt({
3409
- id: Z,
3408
+ const Re = yt({
3409
+ id: ee,
3410
3410
  role: "assistant",
3411
- name: he,
3412
- model: he,
3411
+ name: ye,
3412
+ model: ye,
3413
3413
  createdAt: (/* @__PURE__ */ new Date()).toISOString(),
3414
3414
  content: [{ type: "text", text: xe }]
3415
3415
  });
3416
- w((_n) => ({ ..._n, [Z]: Re })), F(Z), V.current.lastText = xe;
3416
+ w((_n) => ({ ..._n, [ee]: Re })), F(ee), O.current.lastText = xe;
3417
3417
  } else
3418
- w((he) => {
3419
- const Re = he[Z];
3418
+ w((ye) => {
3419
+ const Re = ye[ee];
3420
3420
  return Re ? {
3421
- ...he,
3422
- [Z]: {
3421
+ ...ye,
3422
+ [ee]: {
3423
3423
  ...Re,
3424
3424
  content: [{ type: "text", text: xe }],
3425
3425
  // Preserve existing metadata if the chunk doesn't have it
3426
- responseMetadata: ie.responseMetadata ?? Re.responseMetadata
3426
+ responseMetadata: ce.responseMetadata ?? Re.responseMetadata
3427
3427
  }
3428
- } : he;
3429
- }), V.current.lastText = xe;
3430
- if (!ge) {
3431
- const he = V.current.lastText || "";
3432
- if (le.length > he.length) {
3433
- const Re = le.slice(he.length);
3428
+ } : ye;
3429
+ }), O.current.lastText = xe;
3430
+ if (!me) {
3431
+ const ye = O.current.lastText || "";
3432
+ if (de.length > ye.length) {
3433
+ const Re = de.slice(ye.length);
3434
3434
  it.push(Re), Mn();
3435
3435
  }
3436
3436
  }
3437
3437
  }
3438
- if (pe) {
3439
- const Z = pe.id || `tool-${Date.now()}`, le = bt({
3440
- ...pe,
3441
- id: Z,
3438
+ if (ge) {
3439
+ const ee = ge.id || `tool-${Date.now()}`, de = yt({
3440
+ ...ge,
3441
+ id: ee,
3442
3442
  role: "tool",
3443
3443
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
3444
3444
  });
3445
- w((ge) => ({ ...ge, [Z]: le }));
3445
+ w((me) => ({ ...me, [ee]: de }));
3446
3446
  }
3447
3447
  }
3448
3448
  } else if (we === "heartbeat") {
@@ -3451,99 +3451,99 @@ function Zr(e = {}) {
3451
3451
  } catch (b) {
3452
3452
  console.warn("[use-chat] heartbeat callback failed", b);
3453
3453
  }
3454
- } else if ($e !== null && cancelAnimationFrame($e), vt(), we === "checkpoint")
3455
- y(ae.checkpointId ?? null);
3454
+ } else if (Be !== null && cancelAnimationFrame(Be), It(), we === "checkpoint")
3455
+ y(ie.checkpointId ?? null);
3456
3456
  else if (we === "error") {
3457
- const b = ae;
3458
- if (g(b.message), x = "error", b.error_type === "auth_error" || b.code === "TOKEN_EXPIRED" || ((be = b.message) == null ? void 0 : be.includes("token")) || ((ve = b.message) == null ? void 0 : ve.includes("401")) || ((Je = b.message) == null ? void 0 : Je.includes("unauthorized")) || ((fe = b.message) == null ? void 0 : fe.includes("Unauthorized"))) {
3457
+ const b = ie;
3458
+ if (g(b.message), h = "error", b.error_type === "auth_error" || b.code === "TOKEN_EXPIRED" || ((X = b.message) == null ? void 0 : X.includes("token")) || ((Ie = b.message) == null ? void 0 : Ie.includes("401")) || ((Fe = b.message) == null ? void 0 : Fe.includes("unauthorized")) || ((le = b.message) == null ? void 0 : le.includes("Unauthorized"))) {
3459
3459
  console.error("[use-chat] Auth error detected:", b.message);
3460
3460
  try {
3461
- (Fe = e.onAuthError) == null || Fe.call(e, b.message);
3462
- } catch (ie) {
3463
- console.warn("[use-chat] onAuthError handler failed", ie);
3461
+ (Me = e.onAuthError) == null || Me.call(e, b.message);
3462
+ } catch (ce) {
3463
+ console.warn("[use-chat] onAuthError handler failed", ce);
3464
3464
  }
3465
- M.abort();
3465
+ J.abort();
3466
3466
  }
3467
3467
  } else if (we === "status") {
3468
- const b = ae;
3468
+ const b = ie;
3469
3469
  (b.status === "completed" || b.status === "interrupted" || b.status === "error") && (c(!1), console.log("[use-chat] Status event received:", b));
3470
3470
  }
3471
- f(ae);
3471
+ f(ie);
3472
3472
  }
3473
3473
  }
3474
- vt(), x === null && !M.signal.aborted && (x = "complete");
3475
- } catch (ue) {
3476
- if (ue.name === "AbortError")
3477
- x = x ?? "aborted";
3474
+ It(), h === null && !J.signal.aborted && (h = "complete");
3475
+ } catch (fe) {
3476
+ if (fe.name === "AbortError")
3477
+ h = h ?? "aborted";
3478
3478
  else {
3479
- const Se = ue.message || String(ue);
3480
- x = "error", g(Se);
3479
+ const Se = fe.message || String(fe);
3480
+ h = "error", g(Se);
3481
3481
  }
3482
3482
  } finally {
3483
3483
  try {
3484
3484
  await Qe.cancel();
3485
3485
  } catch {
3486
3486
  } finally {
3487
- (je = Qe.releaseLock) == null || je.call(Qe);
3487
+ (Oe = Qe.releaseLock) == null || Oe.call(Qe);
3488
3488
  }
3489
- $e !== null && typeof window < "u" && window.cancelAnimationFrame($e), clearInterval(En);
3489
+ Be !== null && typeof window < "u" && window.cancelAnimationFrame(Be), clearInterval(En);
3490
3490
  }
3491
3491
  } catch (Te) {
3492
3492
  if (Te.name === "AbortError")
3493
- x = x ?? "aborted";
3493
+ h = h ?? "aborted";
3494
3494
  else {
3495
3495
  const Ae = Te.message || String(Te);
3496
- x = "error", g(Ae), q || (q = !0, (Xe = e.onConnectionError) == null || Xe.call(e, Ae));
3496
+ h = "error", g(Ae), U || (U = !0, (Xe = e.onConnectionError) == null || Xe.call(e, Ae));
3497
3497
  }
3498
3498
  } finally {
3499
- const Te = J.current, Ae = Q.current, Ve = X.current, It = oe.current;
3499
+ const Te = Q.current, Ae = re.current, Ke = te.current, kt = se.current;
3500
3500
  try {
3501
3501
  if (e.onFinish) {
3502
- const Ie = {
3502
+ const ve = {
3503
3503
  lastSeq: Te,
3504
3504
  lastCheckpointId: Ae,
3505
- lastCheckpointNs: Ve,
3506
- lastValues: It
3505
+ lastCheckpointNs: Ke,
3506
+ lastValues: kt
3507
3507
  };
3508
- e.onFinish(Ie);
3508
+ e.onFinish(ve);
3509
3509
  }
3510
- } catch (Ie) {
3511
- console.warn("[use-chat] onClosed callback failed", Ie);
3510
+ } catch (ve) {
3511
+ console.warn("[use-chat] onClosed callback failed", ve);
3512
3512
  }
3513
- c(!1), L(!1), D.current = null, J.current = 0, S(0), G.current = null;
3513
+ c(!1), L(!1), D.current = null, Q.current = 0, A(0), G.current = null;
3514
3514
  }
3515
3515
  })(), Promise.resolve();
3516
3516
  },
3517
3517
  [t, n, r, e]
3518
3518
  );
3519
- return se(() => () => {
3519
+ return oe(() => () => {
3520
3520
  var T;
3521
- P.current = !1, (T = D.current) == null || T.abort();
3521
+ M.current = !1, (T = D.current) == null || T.abort();
3522
3522
  }, []), {
3523
3523
  isStreaming: l,
3524
- error: d,
3525
- assistantText: h,
3526
- activeMessageId: v,
3524
+ error: u,
3525
+ assistantText: m,
3526
+ activeMessageId: I,
3527
3527
  streamedMessages: z,
3528
- lastCheckpointId: m,
3529
- lastSeq: I,
3530
- connected: C,
3528
+ lastCheckpointId: p,
3529
+ lastSeq: v,
3530
+ connected: x,
3531
3531
  stream: _,
3532
- stop: N,
3533
- clear: u,
3532
+ stop: R,
3533
+ clear: d,
3534
3534
  setToken: K,
3535
3535
  values: $,
3536
3536
  interrupt: () => Promise.resolve(),
3537
3537
  resume: () => Promise.resolve(),
3538
3538
  goto: () => Promise.resolve(),
3539
- connectionState: d ? "error" : l ? C ? "connected" : "connecting" : "idle",
3539
+ connectionState: u ? "error" : l ? x ? "connected" : "connecting" : "idle",
3540
3540
  messages: [],
3541
3541
  // useStream doesn't maintain messages, use useChatSession instead
3542
3542
  submit: _
3543
3543
  };
3544
3544
  }
3545
3545
  const es = ["detail", "message", "error", "description", "title"];
3546
- function pt(e) {
3546
+ function ft(e) {
3547
3547
  if (!e) return null;
3548
3548
  if (typeof e == "string") {
3549
3549
  const t = e.trim();
@@ -3551,7 +3551,7 @@ function pt(e) {
3551
3551
  }
3552
3552
  if (Array.isArray(e)) {
3553
3553
  for (const t of e) {
3554
- const n = pt(t);
3554
+ const n = ft(t);
3555
3555
  if (n)
3556
3556
  return n;
3557
3557
  }
@@ -3560,12 +3560,12 @@ function pt(e) {
3560
3560
  if (typeof e == "object") {
3561
3561
  const t = e;
3562
3562
  for (const n of es) {
3563
- const r = pt(t[n]);
3563
+ const r = ft(t[n]);
3564
3564
  if (r)
3565
3565
  return r;
3566
3566
  }
3567
3567
  if ("errors" in t) {
3568
- const n = pt(t.errors);
3568
+ const n = ft(t.errors);
3569
3569
  if (n) return n;
3570
3570
  }
3571
3571
  }
@@ -3573,7 +3573,7 @@ function pt(e) {
3573
3573
  }
3574
3574
  function ts(e) {
3575
3575
  if (!e) return "Request failed";
3576
- const t = e.response, n = pt(t == null ? void 0 : t.data);
3576
+ const t = e.response, n = ft(t == null ? void 0 : t.data);
3577
3577
  if (n) return n;
3578
3578
  if (t != null && t.statusText)
3579
3579
  return t.statusText;
@@ -3592,178 +3592,178 @@ function ns({
3592
3592
  onThreadChange: r,
3593
3593
  onCurrentThreadDeleted: s
3594
3594
  }) {
3595
- const [o, a] = W([]), [i, f] = W(t), [l, c] = W(!1), [d, g] = W(null), [h, k] = W([]), [m, y] = W(!1), [, I] = W(null), [S, C] = W(null), [L, z] = W(!1), w = H(i), v = H(/* @__PURE__ */ new Map());
3596
- se(() => {
3595
+ const [o, a] = q([]), [i, f] = q(t), [l, c] = q(!1), [u, g] = q(null), [m, k] = q([]), [p, y] = q(!1), [, v] = q(null), [A, x] = q(null), [L, z] = q(!1), w = V(i), I = V(/* @__PURE__ */ new Map());
3596
+ oe(() => {
3597
3597
  w.current = i;
3598
- }, [i]), se(() => {
3598
+ }, [i]), oe(() => {
3599
3599
  t !== void 0 && t !== w.current && f(t);
3600
3600
  }, [t]);
3601
- const F = E(async () => {
3601
+ const F = C(async () => {
3602
3602
  c(!0), g(null);
3603
3603
  try {
3604
- const A = await e.listThreads();
3605
- a(A ?? []);
3606
- } catch (A) {
3607
- const R = String(A);
3608
- g(R), n == null || n(R);
3604
+ const S = await e.listThreads();
3605
+ a(S ?? []);
3606
+ } catch (S) {
3607
+ const E = String(S);
3608
+ g(E), n == null || n(E);
3609
3609
  } finally {
3610
3610
  c(!1);
3611
3611
  }
3612
- }, [e, n]), $ = E(async () => {
3613
- y(!0), I(null);
3612
+ }, [e, n]), $ = C(async () => {
3613
+ y(!0), v(null);
3614
3614
  try {
3615
- const A = await e.listSharedThreads();
3616
- k(A ?? []);
3617
- } catch (A) {
3618
- const R = String(A);
3619
- I(R), n == null || n(R);
3615
+ const S = await e.listSharedThreads();
3616
+ k(S ?? []);
3617
+ } catch (S) {
3618
+ const E = String(S);
3619
+ v(E), n == null || n(E);
3620
3620
  } finally {
3621
3621
  y(!1);
3622
3622
  }
3623
3623
  }, [e, n]);
3624
- se(() => {
3624
+ oe(() => {
3625
3625
  F();
3626
- }, [F]), se(() => {
3626
+ }, [F]), oe(() => {
3627
3627
  $();
3628
- }, [$]), se(() => {
3628
+ }, [$]), oe(() => {
3629
3629
  r == null || r(i);
3630
3630
  }, [i, r]);
3631
- const B = E(
3632
- async (A, R) => {
3631
+ const B = C(
3632
+ async (S, E) => {
3633
3633
  try {
3634
- const V = R && typeof R == "object" ? { id: R.id, name: R.name ?? "" } : void 0, K = await e.createThread(A, V);
3634
+ const O = E && typeof E == "object" ? { id: E.id, name: E.name ?? "" } : void 0, K = await e.createThread(S, O);
3635
3635
  return f(K.threadId), await F(), K.threadId;
3636
- } catch (V) {
3637
- const K = String(V);
3636
+ } catch (O) {
3637
+ const K = String(O);
3638
3638
  return n == null || n(K), null;
3639
3639
  }
3640
3640
  },
3641
3641
  [e, n, F]
3642
- ), D = E(
3643
- async (A) => {
3644
- const R = o;
3645
- a((K) => K.filter((u) => u.threadId !== A));
3646
- const V = new AbortController();
3647
- v.current.set(A, V);
3642
+ ), D = C(
3643
+ async (S) => {
3644
+ const E = o;
3645
+ a((K) => K.filter((d) => d.threadId !== S));
3646
+ const O = new AbortController();
3647
+ I.current.set(S, O);
3648
3648
  try {
3649
- await e.deleteThread(A), w.current === A && (f(null), s == null || s());
3649
+ await e.deleteThread(S), w.current === S && (f(null), s == null || s());
3650
3650
  } catch (K) {
3651
- a(R);
3652
- const u = String(K);
3653
- n == null || n(u);
3651
+ a(E);
3652
+ const d = String(K);
3653
+ n == null || n(d);
3654
3654
  } finally {
3655
- v.current.delete(A);
3655
+ I.current.delete(S);
3656
3656
  }
3657
3657
  },
3658
3658
  [e, s, n, o]
3659
- ), P = E(
3660
- async (A, R) => {
3659
+ ), M = C(
3660
+ async (S, E) => {
3661
3661
  try {
3662
- await e.updateThread(A, R), await F();
3663
- } catch (V) {
3664
- n == null || n(String(V));
3662
+ await e.updateThread(S, E), await F();
3663
+ } catch (O) {
3664
+ n == null || n(String(O));
3665
3665
  }
3666
3666
  },
3667
3667
  [e, n, F]
3668
- ), J = E(
3669
- async (A, R) => {
3670
- z(!0), C("Sharing thread…");
3668
+ ), Q = C(
3669
+ async (S, E) => {
3670
+ z(!0), x("Sharing thread…");
3671
3671
  try {
3672
- await e.shareThread(A, R), await $(), C("Shared successfully");
3673
- } catch (V) {
3674
- const K = ts(V);
3675
- throw n == null || n(K), C(`Failed to share: ${K}`), new Error(K);
3672
+ await e.shareThread(S, E), await $(), x("Shared successfully");
3673
+ } catch (O) {
3674
+ const K = ts(O);
3675
+ throw n == null || n(K), x(`Failed to share: ${K}`), new Error(K);
3676
3676
  } finally {
3677
3677
  z(!1);
3678
3678
  }
3679
3679
  },
3680
3680
  [e, n, $]
3681
- ), G = E(
3682
- async (A, R) => {
3681
+ ), G = C(
3682
+ async (S, E) => {
3683
3683
  try {
3684
- await e.unshareThread(A, R), await $();
3685
- } catch (V) {
3686
- const K = String(V);
3687
- throw n == null || n(K), V;
3684
+ await e.unshareThread(S, E), await $();
3685
+ } catch (O) {
3686
+ const K = String(O);
3687
+ throw n == null || n(K), O;
3688
3688
  }
3689
3689
  },
3690
3690
  [e, n, $]
3691
- ), Q = de(
3691
+ ), re = pe(
3692
3692
  () => ({
3693
3693
  createThread: B,
3694
3694
  deleteThread: D,
3695
- renameThread: P,
3695
+ renameThread: M,
3696
3696
  refreshThreads: F,
3697
3697
  refreshSharedThreads: $,
3698
- shareThread: J,
3698
+ shareThread: Q,
3699
3699
  unshareThread: G
3700
3700
  }),
3701
- [B, D, P, F, $, J, G]
3702
- ), X = E((A) => {
3703
- if (!(A != null && A.threadId)) return;
3704
- const R = {
3705
- threadId: A.threadId,
3706
- title: A.title || `Thread ${A.threadId.slice(0, 8)}`,
3707
- project: A.project,
3708
- createdAt: A.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
3709
- updatedAt: A.updatedAt || (/* @__PURE__ */ new Date()).toISOString(),
3710
- messageCount: A.messageCount ?? 1
3701
+ [B, D, M, F, $, Q, G]
3702
+ ), te = C((S) => {
3703
+ if (!(S != null && S.threadId)) return;
3704
+ const E = {
3705
+ threadId: S.threadId,
3706
+ title: S.title || `Thread ${S.threadId.slice(0, 8)}`,
3707
+ project: S.project,
3708
+ createdAt: S.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
3709
+ updatedAt: S.updatedAt || (/* @__PURE__ */ new Date()).toISOString(),
3710
+ messageCount: S.messageCount ?? 1
3711
3711
  };
3712
- a((V) => {
3712
+ a((O) => {
3713
3713
  let K = !1;
3714
- const u = V.map((N) => N.threadId === R.threadId ? (K = !0, console.debug("[useThreadsState] thread_info: updating existing thread", R.threadId), {
3715
- ...N,
3716
- title: R.title ?? N.title,
3717
- project: R.project ?? N.project,
3718
- updatedAt: R.updatedAt ?? N.updatedAt,
3719
- messageCount: R.messageCount ?? N.messageCount
3720
- }) : N);
3721
- return K ? u : (console.debug("[useThreadsState] thread_info: adding thread to list", R.threadId), [R, ...V]);
3714
+ const d = O.map((R) => R.threadId === E.threadId ? (K = !0, console.debug("[useThreadsState] thread_info: updating existing thread", E.threadId), {
3715
+ ...R,
3716
+ title: E.title ?? R.title,
3717
+ project: E.project ?? R.project,
3718
+ updatedAt: E.updatedAt ?? R.updatedAt,
3719
+ messageCount: E.messageCount ?? R.messageCount
3720
+ }) : R);
3721
+ return K ? d : (console.debug("[useThreadsState] thread_info: adding thread to list", E.threadId), [E, ...O]);
3722
3722
  });
3723
- }, []), oe = E(() => C(null), []);
3723
+ }, []), se = C(() => x(null), []);
3724
3724
  return {
3725
3725
  threads: o,
3726
3726
  currentThreadId: i,
3727
3727
  currentThreadIdRef: w,
3728
3728
  setCurrentThreadId: f,
3729
3729
  isLoadingThreads: l,
3730
- threadsError: d,
3731
- sharedThreads: h,
3732
- isLoadingSharedThreads: m,
3733
- actions: Q,
3734
- addThreadFromEvent: X,
3730
+ threadsError: u,
3731
+ sharedThreads: m,
3732
+ isLoadingSharedThreads: p,
3733
+ actions: re,
3734
+ addThreadFromEvent: te,
3735
3735
  shareInFlight: L,
3736
- shareStatus: S,
3737
- clearShareStatus: oe
3736
+ shareStatus: A,
3737
+ clearShareStatus: se
3738
3738
  };
3739
3739
  }
3740
- const wn = We(null);
3740
+ const wn = Ge(null);
3741
3741
  function rs({
3742
3742
  children: e,
3743
3743
  initialThreadId: t = null,
3744
3744
  onError: n,
3745
3745
  onThreadChange: r
3746
3746
  }) {
3747
- const { chatApi: s } = qe(), {
3747
+ const { chatApi: s } = We(), {
3748
3748
  threads: o,
3749
3749
  currentThreadId: a,
3750
3750
  setCurrentThreadId: i,
3751
3751
  currentThreadIdRef: f,
3752
3752
  isLoadingThreads: l,
3753
3753
  threadsError: c,
3754
- sharedThreads: d,
3754
+ sharedThreads: u,
3755
3755
  isLoadingSharedThreads: g,
3756
- actions: h,
3756
+ actions: m,
3757
3757
  addThreadFromEvent: k,
3758
- shareInFlight: m,
3758
+ shareInFlight: p,
3759
3759
  shareStatus: y,
3760
- clearShareStatus: I
3760
+ clearShareStatus: v
3761
3761
  } = ns({
3762
3762
  api: s,
3763
3763
  initialThreadId: t,
3764
3764
  onError: n,
3765
3765
  onThreadChange: r
3766
- }), S = de(
3766
+ }), A = pe(
3767
3767
  () => ({
3768
3768
  threads: o,
3769
3769
  currentThreadId: a,
@@ -3771,12 +3771,12 @@ function rs({
3771
3771
  currentThreadIdRef: f,
3772
3772
  isLoading: l,
3773
3773
  error: c,
3774
- sharedThreads: d,
3774
+ sharedThreads: u,
3775
3775
  isLoadingSharedThreads: g,
3776
- actions: h,
3777
- shareInFlight: m,
3776
+ actions: m,
3777
+ shareInFlight: p,
3778
3778
  shareStatus: y,
3779
- clearShareStatus: I,
3779
+ clearShareStatus: v,
3780
3780
  addThreadFromEvent: k
3781
3781
  }),
3782
3782
  [
@@ -3786,16 +3786,16 @@ function rs({
3786
3786
  f,
3787
3787
  l,
3788
3788
  c,
3789
- d,
3789
+ u,
3790
3790
  g,
3791
- h,
3792
3791
  m,
3792
+ p,
3793
3793
  y,
3794
- I,
3794
+ v,
3795
3795
  k
3796
3796
  ]
3797
3797
  );
3798
- return /* @__PURE__ */ Ce(wn.Provider, { value: S, children: e });
3798
+ return /* @__PURE__ */ Ce(wn.Provider, { value: A, children: e });
3799
3799
  }
3800
3800
  function rt() {
3801
3801
  const e = ot(wn);
@@ -3834,8 +3834,8 @@ function os(e, t, n) {
3834
3834
  return !!((s == null ? void 0 : s.id) === t || n && r.toolCallId === n);
3835
3835
  }) ?? null;
3836
3836
  }
3837
- function gt(e) {
3838
- return e.map((t) => bt(t)).filter((t) => !!t);
3837
+ function pt(e) {
3838
+ return e.map((t) => yt(t)).filter((t) => !!t);
3839
3839
  }
3840
3840
  function at(e, t, n) {
3841
3841
  return t < 0 || t >= e.length ? e : [...e.slice(0, t), n, ...e.slice(t + 1)];
@@ -3879,7 +3879,7 @@ function ls(e, t) {
3879
3879
  switch (t.type) {
3880
3880
  case "reset":
3881
3881
  return {
3882
- messages: gt(((n = t.payload) == null ? void 0 : n.messages) ?? []),
3882
+ messages: pt(((n = t.payload) == null ? void 0 : n.messages) ?? []),
3883
3883
  taskMessagesByScope: {},
3884
3884
  assemblingId: null,
3885
3885
  lastCheckpointId: null,
@@ -3893,7 +3893,7 @@ function ls(e, t) {
3893
3893
  return s ? { ...e, messages: [...e.messages, r], assemblingId: null } : { ...e, messages: [...e.messages, r], assemblingId: null };
3894
3894
  }
3895
3895
  case "seed": {
3896
- const r = gt(t.payload.messages), s = {
3896
+ const r = pt(t.payload.messages), s = {
3897
3897
  ...e,
3898
3898
  messages: r,
3899
3899
  // REPLACE with incoming messages (don't merge with existing)
@@ -3905,7 +3905,7 @@ function ls(e, t) {
3905
3905
  return Object.prototype.hasOwnProperty.call(t.payload, "checkpointId") && (s.lastCheckpointId = t.payload.checkpointId ?? null), Object.prototype.hasOwnProperty.call(t.payload, "checkpointNs") && (s.lastCheckpointNs = t.payload.checkpointNs ?? null), Object.prototype.hasOwnProperty.call(t.payload, "values") && (s.values = t.payload.values ?? {}), s;
3906
3906
  }
3907
3907
  case "prepend": {
3908
- const r = gt(t.payload.messages);
3908
+ const r = pt(t.payload.messages);
3909
3909
  if (!r.length)
3910
3910
  return e;
3911
3911
  const s = new Set(e.messages.map((i) => i.id)), o = r.filter((i) => !s.has(i.id));
@@ -3925,23 +3925,23 @@ function ls(e, t) {
3925
3925
  }
3926
3926
  }
3927
3927
  function us(e = []) {
3928
- const [t, n] = Un(ls, { ...cs, messages: e }), r = H([]), s = H(null), o = H(null), a = E(() => {
3928
+ const [t, n] = Fn(ls, { ...cs, messages: e }), r = V([]), s = V(null), o = V(null), a = C(() => {
3929
3929
  s.current !== null && typeof window < "u" && window.cancelAnimationFrame(s.current), o.current !== null && clearTimeout(o.current), s.current = null, o.current = null;
3930
3930
  const c = r.current;
3931
3931
  c.length && (r.current = [], n({ type: "batch", payload: { events: c } }));
3932
- }, []), i = E(() => {
3932
+ }, []), i = C(() => {
3933
3933
  typeof window < "u" && typeof window.requestAnimationFrame == "function" ? s.current === null && (s.current = window.requestAnimationFrame(() => a())) : o.current === null && (o.current = setTimeout(a, 8));
3934
- }, [a]), f = E((c) => {
3934
+ }, [a]), f = C((c) => {
3935
3935
  r.current.push(c), i();
3936
3936
  }, [i]);
3937
- se(() => () => {
3937
+ oe(() => () => {
3938
3938
  s.current !== null && typeof window < "u" && window.cancelAnimationFrame(s.current), o.current !== null && clearTimeout(o.current), r.current = [];
3939
3939
  }, []);
3940
- const l = de(() => ({
3940
+ const l = pe(() => ({
3941
3941
  reset: (c) => n({ type: "reset", payload: { messages: c } }),
3942
- seed: (c, d) => n({ type: "seed", payload: { messages: c, ...d ?? {} } }),
3942
+ seed: (c, u) => n({ type: "seed", payload: { messages: c, ...u ?? {} } }),
3943
3943
  prepend: (c) => n({ type: "prepend", payload: { messages: c } }),
3944
- pushUser: (c, d) => n({ type: "user_message", payload: { message: c, editingMessageId: d } }),
3944
+ pushUser: (c, u) => n({ type: "user_message", payload: { message: c, editingMessageId: u } }),
3945
3945
  onEvent: f
3946
3946
  }), [f]);
3947
3947
  return { state: t, dispatch: n, ...l };
@@ -3971,7 +3971,7 @@ function Qt(e, t) {
3971
3971
  return { ...e, messages: [...e.messages, i] };
3972
3972
  }
3973
3973
  if (t.type === "values" && ((a = t.values) != null && a.messages)) {
3974
- const i = t.values, f = Array.isArray(i.messages) ? i.messages : [], l = is(gt(f)), { messages: c, ...d } = i;
3974
+ const i = t.values, f = Array.isArray(i.messages) ? i.messages : [], l = is(pt(f)), { messages: c, ...u } = i;
3975
3975
  if (o) {
3976
3976
  const g = typeof s == "string" && s.length > 0 ? s : "task";
3977
3977
  return {
@@ -3988,7 +3988,7 @@ function Qt(e, t) {
3988
3988
  assemblingId: null,
3989
3989
  messagesStreamMeta: {},
3990
3990
  pendingInterrupt: null,
3991
- values: d
3991
+ values: u
3992
3992
  };
3993
3993
  }
3994
3994
  return t.type === "thread_info", e;
@@ -3996,7 +3996,7 @@ function Qt(e, t) {
3996
3996
  function In(e) {
3997
3997
  return e.id ?? void 0;
3998
3998
  }
3999
- function kt(e, t) {
3999
+ function wt(e, t) {
4000
4000
  var n;
4001
4001
  if (!t) return -1;
4002
4002
  for (let r = e.length - 1; r >= 0; r--) {
@@ -4012,7 +4012,7 @@ function ds(e) {
4012
4012
  return -1;
4013
4013
  }
4014
4014
  function fs(e, t, n) {
4015
- const r = kt(e, t);
4015
+ const r = wt(e, t);
4016
4016
  if (r === -1) return e;
4017
4017
  const s = e[r], o = (s.toolCalls ?? []).map(
4018
4018
  (a) => a.id === t ? { ...a, ...n } : a
@@ -4023,7 +4023,7 @@ function ps(e, t) {
4023
4023
  const n = t, r = n.id || n.callId, s = n.name ?? void 0, o = n.scope ?? void 0, a = `Starting ${s ?? "tool"}...`;
4024
4024
  let i = e.messages;
4025
4025
  if (r) {
4026
- let f = kt(i, r);
4026
+ let f = wt(i, r);
4027
4027
  if (f === -1) {
4028
4028
  const l = ds(i);
4029
4029
  for (let c = i.length - 1; c > l; c--)
@@ -4033,8 +4033,8 @@ function ps(e, t) {
4033
4033
  }
4034
4034
  }
4035
4035
  if (f !== -1) {
4036
- const l = i[f], c = [...l.toolCalls ?? []], d = c.findIndex((g) => g.id === r);
4037
- d >= 0 ? c[d] = { ...c[d], status: "running", content: a, scope: o ?? c[d].scope } : c.push({
4036
+ const l = i[f], c = [...l.toolCalls ?? []], u = c.findIndex((g) => g.id === r);
4037
+ u >= 0 ? c[u] = { ...c[u], status: "running", content: a, scope: o ?? c[u].scope } : c.push({
4038
4038
  id: r,
4039
4039
  name: s || "tool",
4040
4040
  args: n.args || {},
@@ -4068,10 +4068,10 @@ function gs(e, t) {
4068
4068
  if (!n) return e;
4069
4069
  const r = t.content ?? void 0, s = t.scope ?? void 0;
4070
4070
  let o = e.messages;
4071
- const a = kt(o, n);
4071
+ const a = wt(o, n);
4072
4072
  if (a !== -1) {
4073
- const i = o[a], f = r ?? null, l = typeof f == "string" ? f : JSON.stringify(f), c = Me(f), d = typeof c == "string" ? c : l, g = (i.toolCalls ?? []).map(
4074
- (h) => h.id === n ? { ...h, content: d, scope: s ?? h.scope } : h
4073
+ const i = o[a], f = r ?? null, l = typeof f == "string" ? f : JSON.stringify(f), c = Ee(f), u = typeof c == "string" ? c : l, g = (i.toolCalls ?? []).map(
4074
+ (m) => m.id === n ? { ...m, content: u, scope: s ?? m.scope } : m
4075
4075
  );
4076
4076
  o = at(o, a, { ...i, toolCalls: g });
4077
4077
  }
@@ -4080,9 +4080,9 @@ function gs(e, t) {
4080
4080
  function ms(e, t) {
4081
4081
  const n = In(t);
4082
4082
  let r = e.messages;
4083
- const s = t.scope ?? void 0, o = t.content ?? t.error ?? null, a = typeof o == "string" ? o : JSON.stringify(o), i = Me(o), f = typeof i == "string" ? i : a;
4083
+ const s = t.scope ?? void 0, o = t.content ?? t.error ?? null, a = typeof o == "string" ? o : JSON.stringify(o), i = Ee(o), f = typeof i == "string" ? i : a;
4084
4084
  if (n)
4085
- if (kt(r, n) !== -1)
4085
+ if (wt(r, n) !== -1)
4086
4086
  r = fs(r, n, {
4087
4087
  status: "completed",
4088
4088
  content: f,
@@ -4090,10 +4090,10 @@ function ms(e, t) {
4090
4090
  scope: s
4091
4091
  });
4092
4092
  else {
4093
- const d = t.name ?? "assistant", g = {
4093
+ const u = t.name ?? "assistant", g = {
4094
4094
  id: `ai-${Date.now()}`,
4095
4095
  role: "assistant",
4096
- name: d,
4096
+ name: u,
4097
4097
  content: [],
4098
4098
  toolCalls: [{
4099
4099
  id: n,
@@ -4174,33 +4174,33 @@ function bs(e) {
4174
4174
  function ws(e) {
4175
4175
  const t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Map(), s = [];
4176
4176
  for (let l = 0; l < e.length; l++) {
4177
- const c = e[l], d = c.checkpointId, g = d ?? `cp-${l}`, h = c.metadata ?? {}, k = typeof h.step == "number" ? h.step : null, m = typeof h.source == "string" ? h.source : null;
4178
- let y = null, I = null;
4179
- const S = Array.isArray(c.messages) ? c.messages : [];
4180
- for (const w of S)
4181
- w.role === "user" && (I || (I = w), w.id && (y = w.id));
4182
- const C = c.next && c.next.length > 0 ? String(c.next[0]) : null, L = c.parentConfig ?? null, z = {
4177
+ const c = e[l], u = c.checkpointId, g = u ?? `cp-${l}`, m = c.metadata ?? {}, k = typeof m.step == "number" ? m.step : null, p = typeof m.source == "string" ? m.source : null;
4178
+ let y = null, v = null;
4179
+ const A = Array.isArray(c.messages) ? c.messages : [];
4180
+ for (const w of A)
4181
+ w.role === "user" && (v || (v = w), w.id && (y = w.id));
4182
+ const x = c.next && c.next.length > 0 ? String(c.next[0]) : null, L = c.parentConfig ?? null, z = {
4183
4183
  id: g,
4184
4184
  step: k,
4185
- source: m,
4185
+ source: p,
4186
4186
  createdAt: c.createdAt ?? null,
4187
4187
  namespace: c.checkpointNs ?? null,
4188
4188
  parentId: c.parentId ?? null,
4189
- next: C,
4189
+ next: x,
4190
4190
  parentConfig: L,
4191
4191
  userMessageId: y
4192
4192
  };
4193
- if (s.push(z), d && t.set(d, z), d && I) {
4194
- const w = bs(I);
4195
- w && r.set(d, w);
4193
+ if (s.push(z), u && t.set(u, z), u && v) {
4194
+ const w = bs(v);
4195
+ w && r.set(u, w);
4196
4196
  }
4197
4197
  n.push({
4198
4198
  id: g,
4199
4199
  messageId: y,
4200
4200
  step: k,
4201
- source: m,
4201
+ source: p,
4202
4202
  createdAt: c.createdAt ?? null,
4203
- next: C,
4203
+ next: x,
4204
4204
  parentConfig: L
4205
4205
  });
4206
4206
  }
@@ -4212,14 +4212,14 @@ function ws(e) {
4212
4212
  }
4213
4213
  for (const l of o.values()) {
4214
4214
  if (!l.length) continue;
4215
- l.sort((d, g) => {
4216
- const h = d.createdAt ? Date.parse(d.createdAt) : 0;
4217
- return (g.createdAt ? Date.parse(g.createdAt) : 0) - h;
4215
+ l.sort((u, g) => {
4216
+ const m = u.createdAt ? Date.parse(u.createdAt) : 0;
4217
+ return (g.createdAt ? Date.parse(g.createdAt) : 0) - m;
4218
4218
  });
4219
4219
  const c = l.length;
4220
- for (let d = 0; d < l.length; d++) {
4221
- const g = l[d];
4222
- g.attemptCount = c, g.attemptIndex = d, g.isLatestAttempt = d === 0;
4220
+ for (let u = 0; u < l.length; u++) {
4221
+ const g = l[u];
4222
+ g.attemptCount = c, g.attemptIndex = u, g.isLatestAttempt = u === 0;
4223
4223
  }
4224
4224
  }
4225
4225
  return {
@@ -4235,11 +4235,11 @@ function ws(e) {
4235
4235
  getCheckpoint: (l) => t.get(l),
4236
4236
  getMessageAttempts: (l) => {
4237
4237
  const c = [];
4238
- for (const d of t.values())
4239
- d.userMessageId === l && c.push(d);
4240
- return c.length ? (c.sort((d, g) => {
4241
- const h = typeof d.attemptIndex == "number" ? d.attemptIndex : Number.MAX_SAFE_INTEGER, k = typeof g.attemptIndex == "number" ? g.attemptIndex : Number.MAX_SAFE_INTEGER;
4242
- return h - k;
4238
+ for (const u of t.values())
4239
+ u.userMessageId === l && c.push(u);
4240
+ return c.length ? (c.sort((u, g) => {
4241
+ const m = typeof u.attemptIndex == "number" ? u.attemptIndex : Number.MAX_SAFE_INTEGER, k = typeof g.attemptIndex == "number" ? g.attemptIndex : Number.MAX_SAFE_INTEGER;
4242
+ return m - k;
4243
4243
  }), c) : [];
4244
4244
  }
4245
4245
  };
@@ -4262,7 +4262,7 @@ function Xs(e, t, n) {
4262
4262
  };
4263
4263
  }
4264
4264
  function ks(e) {
4265
- return de(() => ws(e), [e]);
4265
+ return pe(() => ws(e), [e]);
4266
4266
  }
4267
4267
  function vn({
4268
4268
  api: e,
@@ -4277,179 +4277,182 @@ function vn({
4277
4277
  isStreaming: l,
4278
4278
  getMessages: c
4279
4279
  }) {
4280
- const [d, g] = W(null), k = de(
4281
- () => ft(d),
4282
- [d]
4283
- ).checkpoints, m = ks(k), y = m.timeline, [I, S] = W(!1), [C, L] = W(!1), [z, w] = W(null), v = H(s), F = H(null), $ = H(null), B = H(null), D = H(null), P = H(null), J = H(/* @__PURE__ */ new Map()), G = H(null);
4284
- se(() => {
4285
- v.current = s;
4280
+ const [u, g] = q(null), k = pe(
4281
+ () => Lt(u),
4282
+ [u]
4283
+ ).checkpoints, p = ks(k), y = p.timeline, [v, A] = q(!1), [x, L] = q(!1), [z, w] = q(null), I = V(s), F = V(null), $ = V(null), B = V(null), D = V(null), M = V(null), Q = V(/* @__PURE__ */ new Map()), G = V(null), re = V(null);
4284
+ oe(() => {
4285
+ I.current = s;
4286
4286
  }, [s]);
4287
- const Q = E(
4288
- async (p) => {
4289
- var x, q;
4290
- if (!p.threadId) return;
4291
- const M = p.threadId;
4292
- (x = p.onStart) == null || x.call(p), p.setLoading(!0);
4287
+ const te = C(
4288
+ async (h) => {
4289
+ var H, Y;
4290
+ if (!h.threadId) return;
4291
+ const U = h.threadId;
4292
+ (H = h.onStart) == null || H.call(h), h.setLoading(!0);
4293
4293
  try {
4294
- await p.action(M);
4295
- } catch (U) {
4296
- if (!Dt(U) && v.current === M) {
4297
- const ee = String(U);
4298
- (q = p.handleError) == null || q.call(p, ee), r == null || r(ee);
4294
+ await h.action(U);
4295
+ } catch (N) {
4296
+ if (!St(N) && I.current === U) {
4297
+ const W = String(N);
4298
+ (Y = h.handleError) == null || Y.call(h, W), r == null || r(W);
4299
4299
  }
4300
- throw U;
4300
+ throw N;
4301
4301
  } finally {
4302
- p.setLoading(!1);
4302
+ h.setLoading(!1);
4303
4303
  }
4304
4304
  },
4305
4305
  [r]
4306
- ), X = E(
4307
- async (p) => {
4308
- const M = await e.getState({
4309
- threadId: p.threadId,
4310
- checkpointId: p.checkpointId,
4311
- checkpointNs: p.checkpointNs
4312
- }), x = p.forTimelineHistory ?? {
4306
+ ), se = C(
4307
+ async (h) => {
4308
+ const U = await e.getState({
4309
+ threadId: h.threadId,
4310
+ checkpointId: h.checkpointId,
4311
+ checkpointNs: h.checkpointNs
4312
+ }), H = h.forTimelineHistory ?? {
4313
4313
  version: "values@1",
4314
- threadId: p.threadId,
4315
- checkpoints: [M]
4316
- }, q = t ? await Gr(x, t) : x, { latest: U } = ft(q);
4317
- return U;
4314
+ threadId: h.threadId,
4315
+ checkpoints: [U]
4316
+ }, Y = t ? await Gr(H, t) : H, { latest: N } = Lt(Y);
4317
+ return N;
4318
4318
  },
4319
4319
  [e, t]
4320
- ), oe = E(
4321
- async (p, M) => {
4322
- var ee;
4323
- if (!p) return;
4324
- const x = `${p}:${M ?? "latest"}`, q = J.current.get(x);
4325
- if (q)
4326
- return q;
4327
- (ee = G.current) == null || ee.abort();
4328
- const U = new AbortController();
4329
- G.current = U;
4330
- const ne = Q({
4331
- threadId: p,
4332
- setLoading: S,
4320
+ ), S = C(
4321
+ async (h) => {
4322
+ const U = await e.getStateHistory({
4323
+ threadId: h.threadId,
4324
+ checkpointId: h.checkpointId,
4325
+ checkpointNs: h.checkpointNs,
4326
+ limit: 100,
4327
+ includeMessages: !1,
4328
+ signal: h.signal
4329
+ });
4330
+ I.current === h.threadId && g(U);
4331
+ },
4332
+ [e]
4333
+ ), E = C(
4334
+ async (h, U) => {
4335
+ var W;
4336
+ if (!h) return;
4337
+ const H = `${h}:${U ?? "latest"}`, Y = Q.current.get(H);
4338
+ if (Y)
4339
+ return Y;
4340
+ (W = G.current) == null || W.abort();
4341
+ const N = new AbortController();
4342
+ G.current = N;
4343
+ const ae = te({
4344
+ threadId: h,
4345
+ setLoading: A,
4333
4346
  onStart: () => w(null),
4334
- handleError: (Y) => w(Y),
4335
- action: async (Y) => {
4336
- const j = await X({
4337
- threadId: Y,
4338
- checkpointId: M ?? void 0
4339
- }), re = await e.getStateHistory({
4340
- threadId: Y,
4341
- checkpointId: M ?? void 0,
4342
- signal: U.signal,
4343
- limit: 100,
4344
- includeMessages: !1
4347
+ handleError: (Z) => w(Z),
4348
+ action: async (Z) => {
4349
+ var Fe;
4350
+ const X = await se({
4351
+ threadId: Z,
4352
+ checkpointId: U ?? void 0
4345
4353
  });
4346
- if (v.current !== Y) {
4354
+ if (I.current !== Z) {
4347
4355
  console.log(
4348
- `[useThreadHistoryState] Thread changed during load (was ${Y}, now ${v.current}), discarding stale data`
4356
+ `[useThreadHistoryState] Thread changed during load (was ${Z}, now ${I.current}), discarding stale data`
4349
4357
  );
4350
4358
  return;
4351
4359
  }
4352
- n((j == null ? void 0 : j.messages) ?? [], {
4353
- checkpointId: (j == null ? void 0 : j.checkpointId) ?? null,
4354
- checkpointNs: (j == null ? void 0 : j.checkpointNs) ?? null,
4355
- pendingInterrupt: (j == null ? void 0 : j.interrupt) ?? null,
4356
- values: j == null ? void 0 : j.values
4357
- }), g(re);
4360
+ if (n((X == null ? void 0 : X.messages) ?? [], {
4361
+ checkpointId: (X == null ? void 0 : X.checkpointId) ?? null,
4362
+ checkpointNs: (X == null ? void 0 : X.checkpointNs) ?? null,
4363
+ pendingInterrupt: (X == null ? void 0 : X.interrupt) ?? null,
4364
+ values: X == null ? void 0 : X.values
4365
+ }), !(!!u && (u == null ? void 0 : u.threadId) === Z)) {
4366
+ (Fe = re.current) == null || Fe.abort();
4367
+ const le = new AbortController();
4368
+ re.current = le, S({
4369
+ threadId: Z,
4370
+ checkpointId: U ?? void 0,
4371
+ signal: le.signal
4372
+ }).catch((Me) => {
4373
+ St(Me) || console.warn("[useThreadHistoryState] Background timeline load failed", Me);
4374
+ });
4375
+ }
4358
4376
  }
4359
4377
  });
4360
- J.current.set(x, ne);
4378
+ Q.current.set(H, ae);
4361
4379
  try {
4362
- await ne;
4380
+ await ae;
4363
4381
  } finally {
4364
- J.current.delete(x), G.current === U && (G.current = null);
4382
+ Q.current.delete(H), G.current === N && (G.current = null);
4365
4383
  }
4366
- return v.current === p && (P.current = x), ne;
4384
+ return I.current === h && (M.current = H), ae;
4367
4385
  },
4368
- [e, n, Q, X]
4369
- ), A = E(
4370
- async (p, M) => {
4371
- D.current = p;
4386
+ [n, te, se, S, u]
4387
+ ), O = C(
4388
+ async (h, U) => {
4389
+ D.current = h;
4372
4390
  try {
4373
- await oe(p, M);
4374
- } catch (x) {
4375
- if (!Dt(x))
4376
- throw x;
4391
+ await E(h, U);
4392
+ } catch (H) {
4393
+ if (!St(H))
4394
+ throw H;
4377
4395
  } finally {
4378
- D.current === p && (D.current = null);
4396
+ D.current === h && (D.current = null);
4379
4397
  }
4380
4398
  },
4381
- [oe]
4382
- ), R = E((p) => {
4383
- $.current = p;
4384
- }, []), V = E((p) => {
4385
- B.current = p;
4386
- }, []), K = E(
4387
- async (p) => {
4388
- const M = p == null ? void 0 : p.threadId, x = typeof M == "string" ? M : v.current;
4389
- if (!x || v.current && v.current !== x && B.current !== x)
4399
+ [E]
4400
+ ), K = C((h) => {
4401
+ $.current = h;
4402
+ }, []), d = C((h) => {
4403
+ B.current = h;
4404
+ }, []), R = C(
4405
+ async (h) => {
4406
+ const U = h == null ? void 0 : h.threadId, H = typeof U == "string" ? U : I.current;
4407
+ if (!H || I.current && I.current !== H && B.current !== H)
4390
4408
  return;
4391
- const q = p, U = await X({
4392
- threadId: x
4409
+ const Y = h, N = await se({
4410
+ threadId: H
4393
4411
  });
4394
- U && (n(U.messages ?? [], {
4395
- checkpointId: U.checkpointId ?? null,
4396
- checkpointNs: U.checkpointNs ?? null,
4397
- pendingInterrupt: U.interrupt ?? null,
4398
- values: U.values
4399
- }), g(q), P.current = `${x}:latest`, $.current = null, B.current === x && (B.current = null));
4412
+ N && (n(N.messages ?? [], {
4413
+ checkpointId: N.checkpointId ?? null,
4414
+ checkpointNs: N.checkpointNs ?? null,
4415
+ pendingInterrupt: N.interrupt ?? null,
4416
+ values: N.values
4417
+ }), g(Y), M.current = `${H}:latest`, $.current = null, B.current === H && (B.current = null));
4400
4418
  },
4401
- [n, l, X]
4402
- ), u = E(
4403
- async (p, M) => {
4404
- const x = v.current;
4405
- await Q({
4406
- threadId: x,
4419
+ [n, l, se]
4420
+ ), _ = C(
4421
+ async (h, U) => {
4422
+ const H = I.current;
4423
+ await te({
4424
+ threadId: H,
4407
4425
  setLoading: L,
4408
- action: async (q) => {
4409
- const U = await X({
4410
- threadId: q,
4411
- checkpointId: p,
4412
- checkpointNs: M ?? void 0
4413
- }), ne = await e.getStateHistory({
4414
- threadId: q,
4415
- checkpointId: p,
4416
- checkpointNs: M ?? void 0,
4417
- limit: 100,
4418
- includeMessages: !1
4426
+ action: async (Y) => {
4427
+ const N = await se({
4428
+ threadId: Y,
4429
+ checkpointId: h,
4430
+ checkpointNs: U ?? void 0
4419
4431
  });
4420
- if (v.current !== q)
4421
- return;
4422
- const { checkpoints: ee } = ft(ne), Y = ee.find(
4423
- (j) => j.checkpointId === p && (M ? j.checkpointNs === M : !0)
4424
- );
4425
- if (!Y) {
4426
- console.warn("[useThreadHistoryState] Requested checkpoint not found:", { checkpointId: p, checkpointNs: M });
4427
- return;
4428
- }
4429
- g(ne), n((U == null ? void 0 : U.messages) ?? [], {
4430
- checkpointId: (U == null ? void 0 : U.checkpointId) ?? Y.checkpointId ?? null,
4431
- checkpointNs: (U == null ? void 0 : U.checkpointNs) ?? Y.checkpointNs ?? null,
4432
- pendingInterrupt: (U == null ? void 0 : U.interrupt) ?? null,
4433
- values: U == null ? void 0 : U.values
4432
+ I.current === Y && n((N == null ? void 0 : N.messages) ?? [], {
4433
+ checkpointId: (N == null ? void 0 : N.checkpointId) ?? h ?? null,
4434
+ checkpointNs: (N == null ? void 0 : N.checkpointNs) ?? U ?? null,
4435
+ pendingInterrupt: (N == null ? void 0 : N.interrupt) ?? null,
4436
+ values: N == null ? void 0 : N.values
4434
4437
  });
4435
4438
  }
4436
4439
  }).catch(() => {
4437
4440
  });
4438
4441
  },
4439
- [e, n, Q, X]
4440
- ), N = E(
4441
- (p, M) => {
4442
+ [n, te, se]
4443
+ ), T = C(
4444
+ (h, U) => {
4442
4445
  n(c(), {
4443
- checkpointId: p ?? null,
4444
- checkpointNs: M ?? null
4446
+ checkpointId: h ?? null,
4447
+ checkpointNs: U ?? null
4445
4448
  });
4446
4449
  },
4447
4450
  [c, n]
4448
- ), _ = E(async () => {
4449
- v.current && await A(v.current);
4450
- }, [A]);
4451
- se(() => {
4452
- if (!f || !s || I || l)
4451
+ ), P = C(async () => {
4452
+ I.current && await O(I.current);
4453
+ }, [O]);
4454
+ oe(() => {
4455
+ if (!f || !s || v || l)
4453
4456
  return;
4454
4457
  if ($.current === s) {
4455
4458
  $.current = null, F.current = s;
@@ -4466,41 +4469,41 @@ function vn({
4466
4469
  if (F.current === s)
4467
4470
  return;
4468
4471
  F.current = s;
4469
- let p;
4470
- const M = `${s}:latest`;
4471
- P.current !== M && A(s, p);
4472
+ let h;
4473
+ const U = `${s}:latest`;
4474
+ M.current !== U && O(s, h);
4472
4475
  }, [
4473
4476
  f,
4474
4477
  s,
4475
4478
  a,
4476
4479
  i,
4477
4480
  o,
4478
- I,
4481
+ v,
4479
4482
  l,
4480
- A
4483
+ O
4481
4484
  ]);
4482
- const T = E(() => {
4483
- g(null), S(!1), L(!1), w(null), $.current = null, B.current = null, F.current = null, P.current = null, D.current = null;
4485
+ const J = C(() => {
4486
+ g(null), A(!1), L(!1), w(null), $.current = null, B.current = null, F.current = null, M.current = null, D.current = null;
4484
4487
  }, []);
4485
4488
  return {
4486
4489
  threadCheckpoints: k,
4487
4490
  threadTimeline: y,
4488
- checkpointIndex: m,
4489
- isLoadingThread: I,
4490
- isLoadingCheckpoint: C,
4491
+ checkpointIndex: p,
4492
+ isLoadingThread: v,
4493
+ isLoadingCheckpoint: x,
4491
4494
  threadStateError: z,
4492
- loadThread: A,
4493
- navigateToCheckpoint: u,
4494
- setCurrentCheckpointId: N,
4495
- returnToLatest: _,
4496
- handleValuesEvent: K,
4497
- markSkipNextLoad: R,
4498
- markStreamPendingThread: V,
4499
- resetHistoryState: T,
4500
- clearState: T
4495
+ loadThread: O,
4496
+ navigateToCheckpoint: _,
4497
+ setCurrentCheckpointId: T,
4498
+ returnToLatest: P,
4499
+ handleValuesEvent: R,
4500
+ markSkipNextLoad: K,
4501
+ markStreamPendingThread: d,
4502
+ resetHistoryState: J,
4503
+ clearState: J
4501
4504
  };
4502
4505
  }
4503
- const Tn = We(null), An = We(null);
4506
+ const Tn = Ge(null), An = Ge(null);
4504
4507
  function Sn(e) {
4505
4508
  const t = ot(Tn);
4506
4509
  if (!t && !(e != null && e.optional)) throw new Error("useThreadState must be used within a ThreadStateProvider");
@@ -4521,17 +4524,17 @@ function vs({
4521
4524
  isStreaming: o,
4522
4525
  onError: a
4523
4526
  }) {
4524
- const { chatApi: i, fileApi: f } = qe(), { currentThreadId: l } = rt(), { state: c, seed: d, onEvent: g, dispatch: h } = us(), {
4527
+ const { chatApi: i, fileApi: f } = We(), { currentThreadId: l } = rt(), { state: c, seed: u, onEvent: g, dispatch: m } = us(), {
4525
4528
  threadCheckpoints: k,
4526
- threadTimeline: m,
4529
+ threadTimeline: p,
4527
4530
  checkpointIndex: y,
4528
- isLoadingThread: I,
4529
- isLoadingCheckpoint: S,
4530
- threadStateError: C,
4531
+ isLoadingThread: v,
4532
+ isLoadingCheckpoint: A,
4533
+ threadStateError: x,
4531
4534
  loadThread: L,
4532
4535
  navigateToCheckpoint: z,
4533
4536
  setCurrentCheckpointId: w,
4534
- returnToLatest: v,
4537
+ returnToLatest: I,
4535
4538
  handleValuesEvent: F,
4536
4539
  markSkipNextLoad: $,
4537
4540
  markStreamPendingThread: B,
@@ -4539,7 +4542,7 @@ function vs({
4539
4542
  } = vn({
4540
4543
  api: i,
4541
4544
  fileApi: f,
4542
- seed: d,
4545
+ seed: u,
4543
4546
  onError: a,
4544
4547
  currentThreadId: l,
4545
4548
  initialThreadId: t,
@@ -4547,36 +4550,36 @@ function vs({
4547
4550
  initialCheckpointNs: r,
4548
4551
  autoLoadInitial: s,
4549
4552
  isStreaming: o,
4550
- getMessages: E(() => c.messages, [c.messages])
4553
+ getMessages: C(() => c.messages, [c.messages])
4551
4554
  });
4552
- se(() => {
4553
- l || (d([], {}), D());
4554
- }, [l, d, D]);
4555
- const P = H(null), J = E(
4556
- (u) => {
4557
- P.current = u;
4555
+ oe(() => {
4556
+ l || (u([], {}), D());
4557
+ }, [l, u, D]);
4558
+ const M = V(null), Q = C(
4559
+ (d) => {
4560
+ M.current = d;
4558
4561
  },
4559
4562
  []
4560
- ), G = H(null), Q = E(
4561
- (u) => {
4562
- G.current = u;
4563
+ ), G = V(null), re = C(
4564
+ (d) => {
4565
+ G.current = d;
4563
4566
  },
4564
4567
  []
4565
- ), X = de(() => ({ assemblingMessageId: c.assemblingId ?? null }), [c.assemblingId]), oe = E(
4566
- (u, N) => {
4567
- const _ = bn(u, "user");
4568
- return h({
4568
+ ), te = pe(() => ({ assemblingMessageId: c.assemblingId ?? null }), [c.assemblingId]), se = C(
4569
+ (d, R) => {
4570
+ const _ = bn(d, "user");
4571
+ return m({
4569
4572
  type: "user_message",
4570
4573
  payload: {
4571
4574
  message: _,
4572
- editingMessageId: N == null ? void 0 : N.editingMessageId
4575
+ editingMessageId: R == null ? void 0 : R.editingMessageId
4573
4576
  }
4574
4577
  }), _;
4575
4578
  },
4576
- [h]
4577
- ), A = E(async () => {
4578
- P.current ? await P.current() : (d([], {}), D());
4579
- }, [d, D]), R = de(() => Ar(c.messages), [c.messages]), V = de(
4579
+ [m]
4580
+ ), S = C(async () => {
4581
+ M.current ? await M.current() : (u([], {}), D());
4582
+ }, [u, D]), E = pe(() => Ar(c.messages), [c.messages]), O = pe(
4580
4583
  () => ({
4581
4584
  threadId: l,
4582
4585
  messages: c.messages,
@@ -4588,42 +4591,42 @@ function vs({
4588
4591
  },
4589
4592
  checkpoints: k,
4590
4593
  checkpointIndex: y,
4591
- timelineCheckpoints: m,
4592
- metadata: X,
4594
+ timelineCheckpoints: p,
4595
+ metadata: te,
4593
4596
  values: c.values ?? {},
4594
- isLoading: I,
4595
- isLoadingCheckpoint: S,
4596
- error: C,
4597
+ isLoading: v,
4598
+ isLoadingCheckpoint: A,
4599
+ error: x,
4597
4600
  loadOlder: async () => {
4598
4601
  },
4599
4602
  // Placeholder
4600
- seedFromSnapshot: (u) => {
4601
- d(u.messages, {
4602
- checkpointId: u.checkpointId,
4603
- checkpointNs: u.checkpointNs,
4604
- pendingInterrupt: u.interrupt,
4605
- values: u.values
4603
+ seedFromSnapshot: (d) => {
4604
+ u(d.messages, {
4605
+ checkpointId: d.checkpointId,
4606
+ checkpointNs: d.checkpointNs,
4607
+ pendingInterrupt: d.interrupt,
4608
+ values: d.values
4606
4609
  });
4607
4610
  },
4608
- clearState: A,
4611
+ clearState: S,
4609
4612
  navigateToCheckpoint: z,
4610
4613
  setCurrentCheckpointId: w,
4611
- returnToLatest: v,
4612
- loadThread: async (u, N, _) => {
4613
- await L(u, N, { clearProgress: !1 });
4614
+ returnToLatest: I,
4615
+ loadThread: async (d, R, _) => {
4616
+ await L(d, R, { clearProgress: !1 });
4614
4617
  },
4615
- clearThread: A,
4616
- respondToInterrupt: async (u, N, _) => {
4617
- G.current && await G.current(u, N, _);
4618
+ clearThread: S,
4619
+ respondToInterrupt: async (d, R, _) => {
4620
+ G.current && await G.current(d, R, _);
4618
4621
  },
4619
4622
  messagePreviews: y.messagePreviews,
4620
4623
  handleValuesEvent: F,
4621
4624
  markSkipNextLoad: $,
4622
4625
  markStreamPendingThread: B,
4623
4626
  resetHistoryState: D,
4624
- pushUser: oe,
4627
+ pushUser: se,
4625
4628
  onEvent: g,
4626
- artifacts: R
4629
+ artifacts: E
4627
4630
  }),
4628
4631
  [
4629
4632
  l,
@@ -4634,35 +4637,35 @@ function vs({
4634
4637
  c.lastCheckpointNs,
4635
4638
  c.values,
4636
4639
  k,
4637
- m,
4640
+ p,
4638
4641
  y,
4639
- X,
4640
- I,
4641
- S,
4642
- C,
4643
- d,
4642
+ te,
4643
+ v,
4644
4644
  A,
4645
+ x,
4646
+ u,
4647
+ S,
4645
4648
  z,
4646
4649
  w,
4647
- v,
4650
+ I,
4648
4651
  L,
4649
4652
  F,
4650
4653
  $,
4651
4654
  B,
4652
- oe,
4655
+ se,
4653
4656
  g,
4654
- R
4657
+ E
4655
4658
  ]
4656
- ), K = de(
4659
+ ), K = pe(
4657
4660
  () => ({
4658
- registerClearThread: J,
4659
- registerRespondToInterrupt: Q
4661
+ registerClearThread: Q,
4662
+ registerRespondToInterrupt: re
4660
4663
  }),
4661
- [J, Q]
4664
+ [Q, re]
4662
4665
  );
4663
- return /* @__PURE__ */ Ce(An.Provider, { value: K, children: /* @__PURE__ */ Ce(Tn.Provider, { value: V, children: e }) });
4666
+ return /* @__PURE__ */ Ce(An.Provider, { value: K, children: /* @__PURE__ */ Ce(Tn.Provider, { value: O, children: e }) });
4664
4667
  }
4665
- const xn = We(null), Ts = We(!1);
4668
+ const xn = Ge(null), Ts = Ge(!1);
4666
4669
  function As({
4667
4670
  children: e,
4668
4671
  onError: t,
@@ -4675,24 +4678,24 @@ function As({
4675
4678
  onFinish: f,
4676
4679
  onStreamingChange: l
4677
4680
  }) {
4678
- const { chatApi: c, baseUrl: d } = qe(), g = d, h = _e(t), k = _e(n), m = _e(r), y = _e(s), I = _e(o), S = _e(a), C = _e(i), L = _e(f), z = _e(l), w = de(
4681
+ const { chatApi: c, baseUrl: u } = We(), g = u, m = Le(t), k = Le(n), p = Le(r), y = Le(s), v = Le(o), A = Le(a), x = Le(i), L = Le(f), z = Le(l), w = pe(
4679
4682
  () => ({
4680
- onError: h,
4683
+ onError: m,
4681
4684
  onAuthError: k,
4682
- onConnectionError: m,
4683
- onMetadataEvent: C,
4684
- onCustomEvent: S,
4685
- onUpdateEvent: I,
4685
+ onConnectionError: p,
4686
+ onMetadataEvent: x,
4687
+ onCustomEvent: A,
4688
+ onUpdateEvent: v,
4686
4689
  onToolEnd: y,
4687
4690
  onFinish: L
4688
4691
  }),
4689
4692
  [
4690
- h,
4691
- k,
4692
4693
  m,
4693
- C,
4694
- S,
4695
- I,
4694
+ k,
4695
+ p,
4696
+ x,
4697
+ A,
4698
+ v,
4696
4699
  y,
4697
4700
  L
4698
4701
  ]
@@ -4718,25 +4721,25 @@ function Ss({
4718
4721
  const { setCurrentThreadId: o, currentThreadIdRef: a, addThreadFromEvent: i, currentThreadId: f } = rt(), {
4719
4722
  interrupt: l,
4720
4723
  checkpoint: c,
4721
- timelineCheckpoints: d,
4724
+ timelineCheckpoints: u,
4722
4725
  handleValuesEvent: g,
4723
- markSkipNextLoad: h,
4726
+ markSkipNextLoad: m,
4724
4727
  markStreamPendingThread: k,
4725
- resetHistoryState: m,
4728
+ resetHistoryState: p,
4726
4729
  pushUser: y,
4727
- onEvent: I,
4728
- messages: S
4729
- } = Sn(), { registerClearThread: C, registerRespondToInterrupt: L } = Is(), z = E(
4730
- (u) => {
4731
- i(u), k(u.threadId), a.current !== u.threadId && ((u.created ?? !a.current) && h(u.threadId), o(u.threadId));
4730
+ onEvent: v,
4731
+ messages: A
4732
+ } = Sn(), { registerClearThread: x, registerRespondToInterrupt: L } = Is(), z = C(
4733
+ (d) => {
4734
+ i(d), k(d.threadId), a.current !== d.threadId && ((d.created ?? !a.current) && m(d.threadId), o(d.threadId));
4732
4735
  },
4733
- [i, h, k, o, a]
4736
+ [i, m, k, o, a]
4734
4737
  ), w = Zr({
4735
4738
  baseUrl: n,
4736
- onEvent: I,
4737
- onError: (u) => {
4738
- var N;
4739
- (N = r.onError) == null || N.call(r, (u == null ? void 0 : u.message) ?? String(u));
4739
+ onEvent: v,
4740
+ onError: (d) => {
4741
+ var R;
4742
+ (R = r.onError) == null || R.call(r, (d == null ? void 0 : d.message) ?? String(d));
4740
4743
  },
4741
4744
  onAuthError: r.onAuthError,
4742
4745
  onConnectionError: r.onConnectionError,
@@ -4748,129 +4751,129 @@ function Ss({
4748
4751
  onToolEnd: r.onToolEnd,
4749
4752
  handleValuesEvent: g
4750
4753
  });
4751
- se(() => {
4754
+ oe(() => {
4752
4755
  s == null || s(w.isStreaming);
4753
4756
  }, [w.isStreaming, s]);
4754
- const { stream: v, stop: F, clear: $, isStreaming: B, error: D, connected: P, streamedMessages: J, activeMessageId: G } = w;
4755
- se(() => {
4757
+ const { stream: I, stop: F, clear: $, isStreaming: B, error: D, connected: M, streamedMessages: Q, activeMessageId: G } = w;
4758
+ oe(() => {
4756
4759
  f !== void 0 && $();
4757
4760
  }, [f, $]);
4758
- const Q = E(
4759
- async (u, N) => {
4760
- await v(u, N);
4761
+ const re = C(
4762
+ async (d, R) => {
4763
+ await I(d, R);
4761
4764
  },
4762
- [v]
4763
- ), X = H(c);
4764
- se(() => {
4765
- X.current = c;
4765
+ [I]
4766
+ ), te = V(c);
4767
+ oe(() => {
4768
+ te.current = c;
4766
4769
  }, [c]);
4767
- const oe = E(
4768
- async (u, N, _) => {
4770
+ const se = C(
4771
+ async (d, R, _) => {
4769
4772
  const T = a.current;
4770
4773
  if (!T)
4771
4774
  throw new Error("No active thread to handle interrupt");
4772
- const p = u ? N ?? !0 : !1, M = X.current, x = (_ == null ? void 0 : _.checkpointId) ?? M.id ?? void 0, q = (_ == null ? void 0 : _.checkpointNs) ?? M.namespace ?? void 0, U = {
4775
+ const P = d ? R ?? !0 : !1, J = te.current, h = (_ == null ? void 0 : _.checkpointId) ?? J.id ?? void 0, U = (_ == null ? void 0 : _.checkpointNs) ?? J.namespace ?? void 0, H = {
4773
4776
  threadId: T,
4774
- checkpointId: x,
4775
- checkpointNs: q,
4776
- command: { kind: "resume", value: p },
4777
+ checkpointId: h,
4778
+ checkpointNs: U,
4779
+ command: { kind: "resume", value: P },
4777
4780
  payload: _ == null ? void 0 : _.payload
4778
4781
  };
4779
- Q(U);
4782
+ re(H);
4780
4783
  },
4781
- [a, Q]
4784
+ [a, re]
4782
4785
  );
4783
- se(() => {
4784
- L(oe);
4785
- }, [oe, L]);
4786
- const A = E(async () => {
4787
- F(), $(), m(), o(null);
4788
- }, [$, m, o, F]);
4789
- se(() => {
4790
- C(A);
4791
- }, [A, C]);
4792
- const R = E(
4793
- async (u, N) => {
4786
+ oe(() => {
4787
+ L(se);
4788
+ }, [se, L]);
4789
+ const S = C(async () => {
4790
+ F(), $(), p(), o(null);
4791
+ }, [$, p, o, F]);
4792
+ oe(() => {
4793
+ x(S);
4794
+ }, [S, x]);
4795
+ const E = C(
4796
+ async (d, R) => {
4794
4797
  B && F();
4795
4798
  let _ = a.current;
4796
- const T = (u == null ? void 0 : u.text) ?? "", p = (u == null ? void 0 : u.attachments) ?? [], M = (T == null ? void 0 : T.trim()) ?? "", x = { ...(u == null ? void 0 : u.payload) ?? {} }, q = Array.isArray(x.messages) ? x.messages : void 0;
4797
- q && delete x.messages;
4798
- const U = !!(q && q.length), ne = !!(u.contentParts && u.contentParts.length > 0);
4799
- if (!_ && !M && p.length === 0 && !U && !ne) return;
4799
+ const T = (d == null ? void 0 : d.text) ?? "", P = (d == null ? void 0 : d.attachments) ?? [], J = (T == null ? void 0 : T.trim()) ?? "", h = { ...(d == null ? void 0 : d.payload) ?? {} }, U = Array.isArray(h.messages) ? h.messages : void 0;
4800
+ U && delete h.messages;
4801
+ const H = !!(U && U.length), Y = !!(d.contentParts && d.contentParts.length > 0);
4802
+ if (!_ && !J && P.length === 0 && !H && !Y) return;
4800
4803
  if (!_) {
4801
- const Ae = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), Ve = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4802
- _ = `${Ae}${Ve}`, h(_), o(_);
4804
+ const Ae = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), Ke = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4805
+ _ = `${Ae}${Ke}`, m(_), o(_);
4803
4806
  }
4804
- let ee = null;
4805
- u.contentParts && u.contentParts.length > 0 && (ee = u.contentParts);
4806
- const { contentParts: Y, filesInfo: j } = ee ? { contentParts: ee, filesInfo: [] } : await Vr(p), re = [...Y];
4807
- M && re.push({ type: "text", text: T });
4808
- const be = u == null ? void 0 : u.originalMessageId, ve = !!(u != null && u.edit && be), Je = !U && re.length > 0;
4809
- let fe = null;
4810
- if (Je) {
4811
- const Ae = ve ? be : `msg-${Date.now()}`;
4812
- fe = bn({
4807
+ let N = null;
4808
+ d.contentParts && d.contentParts.length > 0 && (N = d.contentParts);
4809
+ const { contentParts: ae, filesInfo: W } = N ? { contentParts: N, filesInfo: [] } : await Vr(P), Z = [...ae];
4810
+ J && Z.push({ type: "text", text: T });
4811
+ const X = d == null ? void 0 : d.originalMessageId, Ie = !!(d != null && d.edit && X), Fe = !H && Z.length > 0;
4812
+ let le = null;
4813
+ if (Fe) {
4814
+ const Ae = Ie ? X : `msg-${Date.now()}`;
4815
+ le = bn({
4813
4816
  id: Ae,
4814
4817
  role: "user",
4815
- content: re,
4818
+ content: Z,
4816
4819
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4817
- }, "user"), ve ? y(fe, { editingMessageId: be }) : y(fe);
4820
+ }, "user"), Ie ? y(le, { editingMessageId: X }) : y(le);
4818
4821
  }
4819
- const Fe = U ? q : fe ? [fe] : [], je = {
4820
- ...x,
4821
- ...j.length ? { files_info: j } : {}
4822
+ const Me = H ? U : le ? [le] : [], Oe = {
4823
+ ...h,
4824
+ ...W.length ? { files_info: W } : {}
4822
4825
  };
4823
- Fe.length ? je.messages = Fe : "messages" in je || (je.messages = []);
4824
- const Xe = (u == null ? void 0 : u.checkpointId) ?? c.id ?? void 0;
4825
- if (u != null && u.edit && !Xe)
4826
+ Me.length ? Oe.messages = Me : "messages" in Oe || (Oe.messages = []);
4827
+ const Xe = (d == null ? void 0 : d.checkpointId) ?? c.id ?? void 0;
4828
+ if (d != null && d.edit && !Xe)
4826
4829
  throw new Error(
4827
4830
  `[streaming] Missing checkpointId for edit submit. threadId=${_ ?? "null"}`
4828
4831
  );
4829
4832
  const Te = {
4830
4833
  threadId: _,
4831
- content: u == null ? void 0 : u.text,
4832
- payload: je,
4833
- config: u == null ? void 0 : u.config,
4834
+ content: d == null ? void 0 : d.text,
4835
+ payload: Oe,
4836
+ config: d == null ? void 0 : d.config,
4834
4837
  checkpointId: Xe,
4835
- command: u == null ? void 0 : u.command,
4836
- edit: u == null ? void 0 : u.edit
4838
+ command: d == null ? void 0 : d.command,
4839
+ edit: d == null ? void 0 : d.edit
4837
4840
  };
4838
- return Q(Te, N);
4841
+ return re(Te, R);
4839
4842
  },
4840
- [c, a, B, h, y, Q, F, d]
4841
- ), V = de(() => {
4842
- const u = Object.keys(J).length > 0;
4843
- if (!B && !u)
4844
- return S;
4845
- const N = /* @__PURE__ */ new Map();
4846
- return S.forEach((_) => N.set(_.id, _)), Object.values(J).forEach((_) => {
4847
- N.set(_.id, _);
4848
- }), Array.from(N.values());
4849
- }, [B, J, S]), K = de(
4843
+ [c, a, B, m, y, re, F, u]
4844
+ ), O = pe(() => {
4845
+ const d = Object.keys(Q).length > 0;
4846
+ if (!B && !d)
4847
+ return A;
4848
+ const R = /* @__PURE__ */ new Map();
4849
+ return A.forEach((_) => R.set(_.id, _)), Object.values(Q).forEach((_) => {
4850
+ R.set(_.id, _);
4851
+ }), Array.from(R.values());
4852
+ }, [B, Q, A]), K = pe(
4850
4853
  () => ({
4851
4854
  isStreaming: B,
4852
4855
  error: D,
4853
- connectionState: D ? "error" : B ? P ? "connected" : "connecting" : "idle",
4854
- messages: V,
4856
+ connectionState: D ? "error" : B ? M ? "connected" : "connecting" : "idle",
4857
+ messages: O,
4855
4858
  activeMessageId: G,
4856
- submit: R,
4859
+ submit: E,
4857
4860
  stop: F,
4858
4861
  interrupt: l,
4859
4862
  resume: () => Promise.resolve(),
4860
- goto: (u, N) => Promise.resolve(),
4863
+ goto: (d, R) => Promise.resolve(),
4861
4864
  clearError: () => {
4862
4865
  }
4863
4866
  // TODO: Implement error clearing
4864
4867
  }),
4865
- [B, D, R, F, l, P, V]
4868
+ [B, D, E, F, l, M, O]
4866
4869
  );
4867
4870
  return /* @__PURE__ */ Ce(xn.Provider, { value: K, children: e });
4868
4871
  }
4869
- function _e(e) {
4870
- const t = H(e);
4871
- return se(() => {
4872
+ function Le(e) {
4873
+ const t = V(e);
4874
+ return oe(() => {
4872
4875
  t.current = e;
4873
- }, [e]), E((...n) => {
4876
+ }, [e]), C((...n) => {
4874
4877
  const r = t.current;
4875
4878
  if (r)
4876
4879
  return r(...n);
@@ -4896,7 +4899,7 @@ function Cs(e, t) {
4896
4899
  return !0;
4897
4900
  }
4898
4901
  function Ms(e) {
4899
- const t = H(e), n = H(e);
4902
+ const t = V(e), n = V(e);
4900
4903
  return Cs(t.current, e) || (t.current = e, n.current = e), n.current;
4901
4904
  }
4902
4905
  function Es(e) {
@@ -4922,38 +4925,38 @@ function Ys({
4922
4925
  onAuthError: f,
4923
4926
  onThreadChange: l,
4924
4927
  onToolEnd: c,
4925
- onUpdateEvent: d,
4928
+ onUpdateEvent: u,
4926
4929
  onCustomEvent: g,
4927
- onMetadataEvent: h,
4930
+ onMetadataEvent: m,
4928
4931
  onFinish: k
4929
4932
  }) {
4930
- const m = Ms(t), [y, I] = W(!1), S = Le(i), C = Le(f), L = Le(a), z = Le(l), w = Le(c), v = Le(d), F = Le(g), $ = Le(h), B = Le(k), D = de(
4933
+ const p = Ms(t), [y, v] = q(!1), A = ze(i), x = ze(f), L = ze(a), z = ze(l), w = ze(c), I = ze(u), F = ze(g), $ = ze(m), B = ze(k), D = pe(
4931
4934
  () => ({
4932
- onError: S,
4933
- onAuthError: C,
4935
+ onError: A,
4936
+ onAuthError: x,
4934
4937
  onConnectionError: L,
4935
4938
  onToolEnd: w,
4936
- onUpdateEvent: v,
4939
+ onUpdateEvent: I,
4937
4940
  onCustomEvent: F,
4938
4941
  onMetadataEvent: $,
4939
4942
  onFinish: B
4940
4943
  }),
4941
4944
  [
4942
- S,
4943
- C,
4945
+ A,
4946
+ x,
4944
4947
  L,
4945
4948
  w,
4946
- v,
4949
+ I,
4947
4950
  F,
4948
4951
  $,
4949
4952
  B
4950
4953
  ]
4951
4954
  );
4952
- return /* @__PURE__ */ Ce(Br, { apiConfig: m, children: /* @__PURE__ */ Ce(
4955
+ return /* @__PURE__ */ Ce(Br, { apiConfig: p, children: /* @__PURE__ */ Ce(
4953
4956
  rs,
4954
4957
  {
4955
4958
  initialThreadId: n,
4956
- onError: S,
4959
+ onError: A,
4957
4960
  onThreadChange: z,
4958
4961
  children: /* @__PURE__ */ Ce(
4959
4962
  vs,
@@ -4962,13 +4965,13 @@ function Ys({
4962
4965
  initialCheckpointId: r,
4963
4966
  initialCheckpointNs: s,
4964
4967
  autoLoadInitial: o,
4965
- onError: S,
4968
+ onError: A,
4966
4969
  isStreaming: y,
4967
4970
  children: /* @__PURE__ */ Ce(
4968
4971
  As,
4969
4972
  {
4970
4973
  ...D,
4971
- onStreamingChange: I,
4974
+ onStreamingChange: v,
4972
4975
  children: e
4973
4976
  }
4974
4977
  )
@@ -4977,17 +4980,17 @@ function Ys({
4977
4980
  }
4978
4981
  ) });
4979
4982
  }
4980
- function Le(e) {
4981
- const t = H(e);
4982
- return t.current = e, E((...n) => {
4983
+ function ze(e) {
4984
+ const t = V(e);
4985
+ return t.current = e, C((...n) => {
4983
4986
  const r = t.current;
4984
4987
  if (r)
4985
4988
  return r(...n);
4986
4989
  }, []);
4987
4990
  }
4988
- const Ps = 1, Rs = 1e6;
4991
+ const Ps = 1, Ns = 1e6;
4989
4992
  let Et = 0;
4990
- function Ns() {
4993
+ function Rs() {
4991
4994
  return Et = (Et + 1) % Number.MAX_SAFE_INTEGER, Et.toString();
4992
4995
  }
4993
4996
  const Pt = /* @__PURE__ */ new Map(), en = (e) => {
@@ -4998,7 +5001,7 @@ const Pt = /* @__PURE__ */ new Map(), en = (e) => {
4998
5001
  type: "REMOVE_TOAST",
4999
5002
  toastId: e
5000
5003
  });
5001
- }, Rs);
5004
+ }, Ns);
5002
5005
  Pt.set(e, t);
5003
5006
  }, _s = (e, t) => {
5004
5007
  switch (t.type) {
@@ -5037,15 +5040,15 @@ const Pt = /* @__PURE__ */ new Map(), en = (e) => {
5037
5040
  toasts: e.toasts.filter((n) => n.id !== t.toastId)
5038
5041
  };
5039
5042
  }
5040
- }, mt = [];
5041
- let ht = { toasts: [] };
5043
+ }, gt = [];
5044
+ let mt = { toasts: [] };
5042
5045
  function st(e) {
5043
- ht = _s(ht, e), mt.forEach((t) => {
5044
- t(ht);
5046
+ mt = _s(mt, e), gt.forEach((t) => {
5047
+ t(mt);
5045
5048
  });
5046
5049
  }
5047
5050
  function Ls({ ...e }) {
5048
- const t = Ns(), n = (s) => st({
5051
+ const t = Rs(), n = (s) => st({
5049
5052
  type: "UPDATE_TOAST",
5050
5053
  toast: { ...s, id: t }
5051
5054
  }), r = () => st({ type: "DISMISS_TOAST", toastId: t });
@@ -5066,10 +5069,10 @@ function Ls({ ...e }) {
5066
5069
  };
5067
5070
  }
5068
5071
  function zs() {
5069
- const [e, t] = Bt.useState(ht);
5070
- return Bt.useEffect(() => (mt.push(t), () => {
5071
- const n = mt.indexOf(t);
5072
- n > -1 && mt.splice(n, 1);
5072
+ const [e, t] = Dt.useState(mt);
5073
+ return Dt.useEffect(() => (gt.push(t), () => {
5074
+ const n = gt.indexOf(t);
5075
+ n > -1 && gt.splice(n, 1);
5073
5076
  }), [e]), {
5074
5077
  ...e,
5075
5078
  toast: Ls,
@@ -5077,13 +5080,13 @@ function zs() {
5077
5080
  };
5078
5081
  }
5079
5082
  function Zs(e) {
5080
- const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = qe(), { toast: s } = zs(), [o, a] = W({}), [i, f] = W(null), [l, c] = W(!1), d = E(() => {
5083
+ const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = We(), { toast: s } = zs(), [o, a] = q({}), [i, f] = q(null), [l, c] = q(!1), u = C(() => {
5081
5084
  c(!1), f(null);
5082
- }, []), g = E((k) => {
5085
+ }, []), g = C((k) => {
5083
5086
  f(k), c(!0);
5084
- }, []), h = E(
5085
- async (k, m, y) => {
5086
- var I, S;
5087
+ }, []), m = C(
5088
+ async (k, p, y) => {
5089
+ var v, A;
5087
5090
  if (!t) {
5088
5091
  k.preventDefault();
5089
5092
  return;
@@ -5093,63 +5096,63 @@ function Zs(e) {
5093
5096
  return;
5094
5097
  }
5095
5098
  try {
5096
- const C = String(m.url ?? ""), L = C.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
5099
+ const x = String(p.url ?? ""), L = x.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
5097
5100
  if (L) {
5098
5101
  k.preventDefault();
5099
- const z = L[1], w = m.name || `file_${z}`, v = m.mimeType || "application/octet-stream";
5100
- g({ id: z, name: w, mimeType: v });
5102
+ const z = L[1], w = p.name || `file_${z}`, I = p.mimeType || "application/octet-stream";
5103
+ g({ id: z, name: w, mimeType: I });
5101
5104
  return;
5102
5105
  }
5103
- if (C.startsWith("data:")) {
5106
+ if (x.startsWith("data:")) {
5104
5107
  k.preventDefault(), a((w) => ({ ...w, [y]: !0 }));
5105
5108
  const z = s({ title: "Fetching file...", description: "", open: !0 });
5106
5109
  try {
5107
5110
  const w = await r.listFiles(n ?? void 0);
5108
5111
  if (!w || !Array.isArray(w))
5109
5112
  throw new Error("Invalid file list response");
5110
- const v = w.find((F) => !F || typeof F != "object" || !((F.filename ?? "") === (m.name ?? "")) ? !1 : typeof m.size == "number" && typeof F.size == "number" ? F.size === m.size : !0);
5111
- if (!(v != null && v.id))
5112
- throw new Error(`File "${m.name}" is not yet available on the server`);
5113
- if (!v.id || !v.filename)
5113
+ const I = w.find((F) => !F || typeof F != "object" || !((F.filename ?? "") === (p.name ?? "")) ? !1 : typeof p.size == "number" && typeof F.size == "number" ? F.size === p.size : !0);
5114
+ if (!(I != null && I.id))
5115
+ throw new Error(`File "${p.name}" is not yet available on the server`);
5116
+ if (!I.id || !I.filename)
5114
5117
  throw new Error("Invalid file data received from server");
5115
5118
  g({
5116
- id: v.id,
5117
- name: m.name || v.filename || `file_${v.id}`,
5118
- mimeType: m.mimeType || v.mime_type || "application/octet-stream"
5119
- }), (I = z.update) == null || I.call(z, {
5119
+ id: I.id,
5120
+ name: p.name || I.filename || `file_${I.id}`,
5121
+ mimeType: p.mimeType || I.mime_type || "application/octet-stream"
5122
+ }), (v = z.update) == null || v.call(z, {
5120
5123
  id: z.id,
5121
5124
  title: "Success",
5122
- description: `Opened ${m.name}`,
5125
+ description: `Opened ${p.name}`,
5123
5126
  open: !0
5124
5127
  });
5125
5128
  } catch (w) {
5126
5129
  console.error("Failed to fetch server file:", w);
5127
- const v = w instanceof Error ? w.message : "Unknown error occurred";
5128
- (S = z.update) == null || S.call(z, { id: z.id, title: "Failed", description: v }), s({
5130
+ const I = w instanceof Error ? w.message : "Unknown error occurred";
5131
+ (A = z.update) == null || A.call(z, { id: z.id, title: "Failed", description: I }), s({
5129
5132
  title: "Failed to fetch file",
5130
- description: v,
5133
+ description: I,
5131
5134
  open: !0
5132
5135
  });
5133
5136
  } finally {
5134
5137
  a((w) => ({ ...w, [y]: !1 }));
5135
5138
  }
5136
5139
  }
5137
- } catch (C) {
5138
- console.error("File click error:", C), a((L) => ({ ...L, [y]: !1 }));
5140
+ } catch (x) {
5141
+ console.error("File click error:", x), a((L) => ({ ...L, [y]: !1 }));
5139
5142
  }
5140
5143
  },
5141
5144
  [t, o, s, n, g]
5142
5145
  );
5143
5146
  return {
5144
5147
  uploadingFiles: o,
5145
- handleFileClick: h,
5148
+ handleFileClick: m,
5146
5149
  fileViewerOpen: l,
5147
5150
  currentFileInfo: i,
5148
- closeFileViewer: d
5151
+ closeFileViewer: u
5149
5152
  };
5150
5153
  }
5151
5154
  function eo(e) {
5152
- return de(() => {
5155
+ return pe(() => {
5153
5156
  const t = e;
5154
5157
  let n = Array.isArray(t.content) ? t.content : [];
5155
5158
  return typeof t.content == "string" && (n = [{ type: "text", text: t.content }]), {
@@ -5164,7 +5167,7 @@ function eo(e) {
5164
5167
  }, [e]);
5165
5168
  }
5166
5169
  const tn = "data:";
5167
- function Us(e) {
5170
+ function Fs(e) {
5168
5171
  if (!e) return [];
5169
5172
  const t = [], n = e.split(/\r?\n/);
5170
5173
  for (const r of n) {
@@ -5174,12 +5177,12 @@ function Us(e) {
5174
5177
  const o = s.slice(tn.length).trim();
5175
5178
  if (!o || o.toLowerCase() === "[done]")
5176
5179
  continue;
5177
- const a = zt(o);
5180
+ const a = Ft(o);
5178
5181
  a && typeof a == "object" && t.push(a);
5179
5182
  }
5180
5183
  return t;
5181
5184
  }
5182
- function Fs(e) {
5185
+ function Us(e) {
5183
5186
  for (let t = e.length - 1; t >= 0; t -= 1) {
5184
5187
  const n = e[t];
5185
5188
  if (n && typeof n == "object" && n.type === "tool.end")
@@ -5188,26 +5191,26 @@ function Fs(e) {
5188
5191
  return null;
5189
5192
  }
5190
5193
  function to(e) {
5191
- return de(() => {
5194
+ return pe(() => {
5192
5195
  const t = e.content.filter(
5193
5196
  (f) => f.type === "text"
5194
5197
  );
5195
5198
  if (!t.length)
5196
5199
  return null;
5197
5200
  let r = t.flatMap(
5198
- (f) => Us(f.text ?? "")
5201
+ (f) => Fs(f.text ?? "")
5199
5202
  );
5200
5203
  if (!r.length) {
5201
5204
  const f = t.map((c) => c.text ?? "").join(`
5202
- `), l = zt(f);
5205
+ `), l = Ft(f);
5203
5206
  l && typeof l == "object" && (r = [l]);
5204
5207
  }
5205
5208
  if (!r.length)
5206
5209
  return null;
5207
- const o = Fs(r) ?? r[r.length - 1];
5210
+ const o = Us(r) ?? r[r.length - 1];
5208
5211
  if (!o)
5209
5212
  return null;
5210
- const a = o.output ?? o.payload ?? o, i = Me(a);
5213
+ const a = o.output ?? o.payload ?? o, i = Ee(a);
5211
5214
  return i && typeof i == "object" && !Array.isArray(i) ? {
5212
5215
  kind: "dict",
5213
5216
  value: i,
@@ -5222,35 +5225,35 @@ function to(e) {
5222
5225
  }
5223
5226
  function js(e) {
5224
5227
  var z;
5225
- const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, { currentThreadId: n, setCurrentThreadId: r, actions: s } = rt(), o = Sn({ optional: !0 }), a = xs(), i = !!t && t !== n, [f, l] = W([]), c = E((w) => {
5228
+ const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, { currentThreadId: n, setCurrentThreadId: r, actions: s } = rt(), o = Sn({ optional: !0 }), a = xs(), i = !!t && t !== n, [f, l] = q([]), c = C((w) => {
5226
5229
  l(w);
5227
5230
  }, []), {
5228
- isLoadingThread: d,
5231
+ isLoadingThread: u,
5229
5232
  threadStateError: g,
5230
- threadCheckpoints: h
5233
+ threadCheckpoints: m
5231
5234
  } = vn({
5232
- api: qe().chatApi,
5233
- fileApi: qe().fileApi,
5235
+ api: We().chatApi,
5236
+ fileApi: We().fileApi,
5234
5237
  seed: c,
5235
5238
  currentThreadId: i ? t : null,
5236
5239
  initialThreadId: i ? t : null,
5237
5240
  isStreaming: !1,
5238
5241
  getMessages: () => f,
5239
5242
  autoLoadInitial: !0
5240
- }), k = de(() => {
5243
+ }), k = pe(() => {
5241
5244
  var w;
5242
- return ((w = h[0]) == null ? void 0 : w.values) || {};
5243
- }, [h]), m = t || n, y = i ? f : (a == null ? void 0 : a.messages) || [], I = i ? d : (o == null ? void 0 : o.isLoading) || !1, S = i ? k : (o == null ? void 0 : o.values) || {}, C = i ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, L = i ? g : (a == null ? void 0 : a.error) || (o == null ? void 0 : o.error) || null;
5245
+ return ((w = m[0]) == null ? void 0 : w.values) || {};
5246
+ }, [m]), p = t || n, y = i ? f : (a == null ? void 0 : a.messages) || [], v = i ? u : (o == null ? void 0 : o.isLoading) || !1, A = i ? k : (o == null ? void 0 : o.values) || {}, x = i ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, L = i ? g : (a == null ? void 0 : a.error) || (o == null ? void 0 : o.error) || null;
5244
5247
  return {
5245
5248
  // UNIFIED: Single thread ID concept
5246
- threadId: m,
5249
+ threadId: p,
5247
5250
  messages: y,
5248
- isLoading: I,
5249
- isHistoryLoading: I,
5251
+ isLoading: v,
5252
+ isHistoryLoading: v,
5250
5253
  error: L,
5251
5254
  // Values & Metadata
5252
- values: S,
5253
- taskMessagesByScope: C,
5255
+ values: A,
5256
+ taskMessagesByScope: x,
5254
5257
  metadata: o == null ? void 0 : o.metadata,
5255
5258
  // Actions & State relating to Global/Active Thread only
5256
5259
  navigateToCheckpoint: (o == null ? void 0 : o.navigateToCheckpoint) || (async () => {
@@ -5298,156 +5301,156 @@ function no({
5298
5301
  messages: f,
5299
5302
  setPendingAssistantResponse: l,
5300
5303
  project: c,
5301
- onEvent: d,
5304
+ onEvent: u,
5302
5305
  threadId: g,
5303
- clearComposerOnSend: h = !0
5306
+ clearComposerOnSend: m = !0
5304
5307
  }) {
5305
- const { messages: k } = js(), [m, y] = W(null), [I, S] = W(""), [C, L] = W(null), [z, w] = W(null), [v, F] = W(!1), [$, B] = W(""), D = H($), P = H(null);
5306
- se(() => {
5307
- if (!m)
5308
+ const { messages: k } = js(), [p, y] = q(null), [v, A] = q(""), [x, L] = q(null), [z, w] = q(null), [I, F] = q(!1), [$, B] = q(""), D = V($), M = V(null);
5309
+ oe(() => {
5310
+ if (!p)
5308
5311
  if (g) {
5309
- const u = localStorage.getItem(Mt(g));
5310
- B(u || "");
5312
+ const d = localStorage.getItem(Mt(g));
5313
+ B(d || "");
5311
5314
  } else
5312
5315
  B("");
5313
- }, [g, m]);
5314
- const J = E((u) => {
5315
- B(u), !m && g && localStorage.setItem(Mt(g), u);
5316
- }, [g, m]);
5317
- se(() => {
5316
+ }, [g, p]);
5317
+ const Q = C((d) => {
5318
+ B(d), !p && g && localStorage.setItem(Mt(g), d);
5319
+ }, [g, p]);
5320
+ oe(() => {
5318
5321
  D.current = $;
5319
- }, [$]), se(() => {
5320
- if (!m) {
5321
- P.current = null;
5322
+ }, [$]), oe(() => {
5323
+ if (!p) {
5324
+ M.current = null;
5322
5325
  return;
5323
5326
  }
5324
- P.current === null && (P.current = D.current), J(I ?? "");
5325
- }, [I, m, J]);
5326
- const G = E(
5327
- (u) => {
5328
- J(u);
5327
+ M.current === null && (M.current = D.current), Q(v ?? "");
5328
+ }, [v, p, Q]);
5329
+ const G = C(
5330
+ (d) => {
5331
+ Q(d);
5329
5332
  },
5330
- [J]
5331
- ), Q = async (u, N) => {
5332
- const _ = Array.isArray(N) ? { files: N } : N ?? {}, T = _.files ?? [], p = _.contentParts ?? [], M = u.trim();
5333
- if (!(!M && T.length === 0 && p.length === 0))
5333
+ [Q]
5334
+ ), re = async (d, R) => {
5335
+ const _ = Array.isArray(R) ? { files: R } : R ?? {}, T = _.files ?? [], P = _.contentParts ?? [], J = d.trim();
5336
+ if (!(!J && T.length === 0 && P.length === 0))
5334
5337
  try {
5335
- const x = T.map(async (j) => {
5338
+ const h = T.map(async (W) => {
5336
5339
  try {
5337
- const re = await hn.uploadFile(j);
5338
- return { file: j, record: re };
5339
- } catch (re) {
5340
- throw console.error("Failed to upload file", j.name, re), new Error(`Failed to upload ${j.name}`);
5340
+ const Z = await hn.uploadFile(W);
5341
+ return { file: W, record: Z };
5342
+ } catch (Z) {
5343
+ throw console.error("Failed to upload file", W.name, Z), new Error(`Failed to upload ${W.name}`);
5341
5344
  }
5342
- }), U = (await Promise.all(x)).map(({ record: j }) => {
5343
- const re = j.mime_type;
5344
- return re.startsWith("image/") ? {
5345
+ }), H = (await Promise.all(h)).map(({ record: W }) => {
5346
+ const Z = W.mime_type;
5347
+ return Z.startsWith("image/") ? {
5345
5348
  type: "image_url",
5346
- image_url: { url: j.content_url }
5349
+ image_url: { url: W.content_url }
5347
5350
  } : {
5348
5351
  type: "file",
5349
- url: j.content_url,
5350
- mimeType: re,
5351
- name: j.filename,
5352
- size: j.size
5352
+ url: W.content_url,
5353
+ mimeType: Z,
5354
+ name: W.filename,
5355
+ size: W.size
5353
5356
  };
5354
- }), ne = [...p, ...U], ee = m ? (C == null ? void 0 : C.checkpointId) ?? n ?? void 0 : n ?? void 0, Y = m ? (C == null ? void 0 : C.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5357
+ }), Y = [...P, ...H], N = p ? (x == null ? void 0 : x.checkpointId) ?? n ?? void 0 : n ?? void 0, ae = p ? (x == null ? void 0 : x.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5355
5358
  await e(
5356
5359
  {
5357
- text: M || "",
5358
- contentParts: ne,
5360
+ text: J || "",
5361
+ contentParts: Y,
5359
5362
  attachments: T,
5360
5363
  payload: t.payload,
5361
- edit: !!m,
5362
- checkpointId: ee,
5363
- checkpointNs: Y,
5364
+ edit: !!p,
5365
+ checkpointId: N,
5366
+ checkpointNs: ae,
5364
5367
  project: c ?? void 0,
5365
- originalMessageId: m ?? void 0,
5368
+ originalMessageId: p ?? void 0,
5366
5369
  config: t.config
5367
5370
  },
5368
- d ? { onEvent: d } : void 0
5369
- ), s == null || s(M), l(!0), h && (g && localStorage.removeItem(Mt(g)), J("")), w(null), y(null), S(""), L(null);
5370
- } catch (x) {
5371
- const q = (x == null ? void 0 : x.message) || "Failed to send message";
5372
- w(q), a == null || a(q), l(!1);
5371
+ u ? { onEvent: u } : void 0
5372
+ ), s == null || s(J), l(!0), m && (g && localStorage.removeItem(Mt(g)), Q("")), w(null), y(null), A(""), L(null);
5373
+ } catch (h) {
5374
+ const U = (h == null ? void 0 : h.message) || "Failed to send message";
5375
+ w(U), a == null || a(U), l(!1);
5373
5376
  }
5374
- }, X = (u, N) => {
5375
- N || Q(u, { files: [] });
5376
- }, oe = E(
5377
- async (u) => {
5377
+ }, te = (d, R) => {
5378
+ R || re(d, { files: [] });
5379
+ }, se = C(
5380
+ async (d) => {
5378
5381
  await e(
5379
5382
  {
5380
- attachments: [u],
5383
+ attachments: [d],
5381
5384
  payload: t.payload,
5382
5385
  checkpointId: n ?? void 0,
5383
5386
  checkpointNs: r ?? void 0,
5384
5387
  project: c ?? void 0,
5385
5388
  config: t.config
5386
5389
  },
5387
- d ? { onEvent: d } : void 0
5388
- ), o == null || o({ file: u });
5390
+ u ? { onEvent: u } : void 0
5391
+ ), o == null || o({ file: d });
5389
5392
  },
5390
5393
  [n, r, t, o, e]
5391
- ), A = E(
5392
- (u, N, _) => {
5393
- i && (P.current = $, y(u), S(N), L({
5394
+ ), S = C(
5395
+ (d, R, _) => {
5396
+ i && (M.current = $, y(d), A(R), L({
5394
5397
  checkpointId: (_ == null ? void 0 : _.checkpointId) ?? null,
5395
5398
  checkpointNs: (_ == null ? void 0 : _.checkpointNs) ?? null
5396
5399
  }), w(null));
5397
5400
  },
5398
5401
  [$, i]
5399
- ), R = E(() => {
5400
- y(null), S(""), L(null), w(null);
5401
- const u = P.current;
5402
- u !== null && B(u), P.current = null;
5403
- }, []), V = E((u) => {
5404
- let N = null;
5405
- for (let M = u - 1; M >= 0; M--)
5406
- if (f[M].role === "user") {
5407
- N = f[M];
5402
+ ), E = C(() => {
5403
+ y(null), A(""), L(null), w(null);
5404
+ const d = M.current;
5405
+ d !== null && B(d), M.current = null;
5406
+ }, []), O = C((d) => {
5407
+ let R = null;
5408
+ for (let J = d - 1; J >= 0; J--)
5409
+ if (f[J].role === "user") {
5410
+ R = f[J];
5408
5411
  break;
5409
5412
  }
5410
- if (!N) return;
5411
- const _ = Array.isArray(N.content) ? N.content : [], p = _.filter((M) => (M == null ? void 0 : M.type) === "text").map((M) => M.text).join("") || (() => {
5413
+ if (!R) return;
5414
+ const _ = Array.isArray(R.content) ? R.content : [], P = _.filter((J) => (J == null ? void 0 : J.type) === "text").map((J) => J.text).join("") || (() => {
5412
5415
  try {
5413
5416
  return JSON.stringify(_, null, 2);
5414
5417
  } catch {
5415
5418
  return String(_);
5416
5419
  }
5417
5420
  })();
5418
- p && e(
5421
+ P && e(
5419
5422
  {
5420
- text: p,
5423
+ text: P,
5421
5424
  payload: t.payload,
5422
5425
  checkpointId: n ?? void 0,
5423
5426
  checkpointNs: r ?? void 0,
5424
5427
  edit: !0,
5425
- originalMessageId: N.id,
5428
+ originalMessageId: R.id,
5426
5429
  config: t.config
5427
5430
  },
5428
- d ? { onEvent: d } : void 0
5431
+ u ? { onEvent: u } : void 0
5429
5432
  );
5430
5433
  }, [f, e, n, r, t]);
5431
5434
  return {
5432
- editingMessageId: m,
5433
- editingInitialValue: I,
5435
+ editingMessageId: p,
5436
+ editingInitialValue: v,
5434
5437
  inputError: z,
5435
5438
  setInputError: w,
5436
- dismissError: v,
5439
+ dismissError: I,
5437
5440
  setDismissError: F,
5438
5441
  composerValue: $,
5439
5442
  handleComposerChange: G,
5440
- handleSendMessage: Q,
5441
- handleQuickPrompt: X,
5442
- handleExcelUpload: oe,
5443
- startEditing: A,
5444
- cancelEditing: R,
5445
- handleRegenerateCb: V,
5443
+ handleSendMessage: re,
5444
+ handleQuickPrompt: te,
5445
+ handleExcelUpload: se,
5446
+ startEditing: S,
5447
+ cancelEditing: E,
5448
+ handleRegenerateCb: O,
5446
5449
  displayMessages: k
5447
5450
  };
5448
5451
  }
5449
5452
  function ro(e) {
5450
- return de(() => e ? {
5453
+ return pe(() => e ? {
5451
5454
  textContent: Ir(e),
5452
5455
  imageParts: vr(e),
5453
5456
  fileParts: Tr(e),
@@ -5462,8 +5465,8 @@ function ro(e) {
5462
5465
  }, [e]);
5463
5466
  }
5464
5467
  function so(e, t, n) {
5465
- const [r, s] = W(e), o = H(e), a = H(null);
5466
- return se(() => {
5468
+ const [r, s] = q(e), o = V(e), a = V(null);
5469
+ return oe(() => {
5467
5470
  o.current = e;
5468
5471
  const i = () => {
5469
5472
  s(o.current), a.current && (clearTimeout(a.current), a.current = null);
@@ -5493,21 +5496,21 @@ export {
5493
5496
  fn as getChatToken,
5494
5497
  Xs as getMessageAttemptInfo,
5495
5498
  qs as getToolCallArtifacts,
5496
- Rr as getToolCalls,
5499
+ Nr as getToolCalls,
5497
5500
  Hs as hasContent,
5498
- ft as hydrateHistorySnapshots,
5501
+ Lt as hydrateHistorySnapshots,
5499
5502
  un as isFileLike,
5500
5503
  br as looksLikeMarkdown,
5501
5504
  Js as messageSignature,
5502
5505
  Ws as normalizeInterruptId,
5503
5506
  pn as onChatTokenChanged,
5504
- zt as parseJsonSafe,
5507
+ Ft as parseJsonSafe,
5505
5508
  dn as pretty,
5506
5509
  Gr as refreshHistoryFileUrls,
5507
- yt as sanitizeForDisplay,
5508
- De as setChatToken,
5510
+ ht as sanitizeForDisplay,
5511
+ Ve as setChatToken,
5509
5512
  Sr as stringifyTool,
5510
- qe as useApi,
5513
+ We as useApi,
5511
5514
  no as useChatController,
5512
5515
  js as useChatSession,
5513
5516
  Zs as useFilePreview,