@teodorruskvi/chat-core 0.1.47 → 0.1.49

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
@@ -127,25 +127,25 @@ const et = "-", Yt = (e) => {
127
127
  } = e, r = t.length === 1, o = t[0], s = t.length, a = (i) => {
128
128
  const u = [];
129
129
  let c = 0, l = 0, d;
130
- for (let k = 0; k < i.length; k++) {
131
- let p = i[k];
130
+ for (let I = 0; I < i.length; I++) {
131
+ let p = i[I];
132
132
  if (c === 0) {
133
- if (p === o && (r || i.slice(k, k + s) === t)) {
134
- u.push(i.slice(l, k)), l = k + s;
133
+ if (p === o && (r || i.slice(I, I + s) === t)) {
134
+ u.push(i.slice(l, I)), l = I + s;
135
135
  continue;
136
136
  }
137
137
  if (p === "/") {
138
- d = k;
138
+ d = I;
139
139
  continue;
140
140
  }
141
141
  }
142
142
  p === "[" ? c++ : p === "]" && c--;
143
143
  }
144
- const m = u.length === 0 ? i : i.substring(l), y = m.startsWith(At), I = y ? m.substring(1) : m, f = d && d > l ? d - l : void 0;
144
+ const m = u.length === 0 ? i : i.substring(l), y = m.startsWith(At), v = y ? m.substring(1) : m, f = d && d > l ? d - l : void 0;
145
145
  return {
146
146
  modifiers: u,
147
147
  hasImportantModifier: y,
148
- baseClassName: I,
148
+ baseClassName: v,
149
149
  maybePostfixModifierPosition: f
150
150
  };
151
151
  };
@@ -179,9 +179,9 @@ const et = "-", Yt = (e) => {
179
179
  baseClassName: m,
180
180
  maybePostfixModifierPosition: y
181
181
  } = n(c);
182
- let I = !!y, f = r(I ? m.substring(0, y) : m);
182
+ let v = !!y, f = r(v ? m.substring(0, y) : m);
183
183
  if (!f) {
184
- if (!I) {
184
+ if (!v) {
185
185
  i = c + (i.length > 0 ? " " + i : i);
186
186
  continue;
187
187
  }
@@ -189,16 +189,16 @@ const et = "-", Yt = (e) => {
189
189
  i = c + (i.length > 0 ? " " + i : i);
190
190
  continue;
191
191
  }
192
- I = !1;
192
+ v = !1;
193
193
  }
194
- const k = sn(l).join(":"), p = d ? k + At : k, S = p + f;
194
+ const I = sn(l).join(":"), p = d ? I + At : I, S = p + f;
195
195
  if (s.includes(S))
196
196
  continue;
197
197
  s.push(S);
198
- const A = o(f, I);
199
- for (let E = 0; E < A.length; ++E) {
200
- const v = A[E];
201
- s.push(p + v);
198
+ const x = o(f, v);
199
+ for (let E = 0; E < x.length; ++E) {
200
+ const k = x[E];
201
+ s.push(p + k);
202
202
  }
203
203
  i = c + (i.length > 0 ? " " + i : i);
204
204
  }
@@ -247,7 +247,7 @@ const D = (e) => {
247
247
  // I could also use lookbehind assertion in `lengthUnitRegex` but that isn't supported widely enough.
248
248
  mn.test(e) && !yn.test(e)
249
249
  ), St = () => !1, Mn = (e) => hn.test(e), Cn = (e) => bn.test(e), En = () => {
250
- const e = D("colors"), t = D("spacing"), n = D("blur"), r = D("brightness"), o = D("borderColor"), s = D("borderRadius"), a = D("borderSpacing"), i = D("borderWidth"), u = D("contrast"), c = D("grayscale"), l = D("hueRotate"), d = D("invert"), m = D("gap"), y = D("gradientColorStops"), I = D("gradientColorStopPositions"), f = D("inset"), k = D("margin"), p = D("opacity"), S = D("padding"), A = D("saturate"), E = D("scale"), v = D("sepia"), w = D("skew"), x = D("space"), g = D("translate"), b = () => ["auto", "contain", "none"], P = () => ["auto", "hidden", "clip", "visible", "scroll"], j = () => ["auto", R, t], M = () => [R, t], O = () => ["", de, be], F = () => ["auto", Te, R], C = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], B = () => ["solid", "dashed", "dotted", "double", "none"], N = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], V = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], z = () => ["", "0", R], L = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], H = () => [Te, R];
250
+ const e = D("colors"), t = D("spacing"), n = D("blur"), r = D("brightness"), o = D("borderColor"), s = D("borderRadius"), a = D("borderSpacing"), i = D("borderWidth"), u = D("contrast"), c = D("grayscale"), l = D("hueRotate"), d = D("invert"), m = D("gap"), y = D("gradientColorStops"), v = D("gradientColorStopPositions"), f = D("inset"), I = D("margin"), p = D("opacity"), S = D("padding"), x = D("saturate"), E = D("scale"), k = D("sepia"), b = D("skew"), A = D("space"), g = D("translate"), w = () => ["auto", "contain", "none"], P = () => ["auto", "hidden", "clip", "visible", "scroll"], j = () => ["auto", R, t], M = () => [R, t], O = () => ["", de, be], F = () => ["auto", Te, R], C = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], B = () => ["solid", "dashed", "dotted", "double", "none"], N = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], K = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], z = () => ["", "0", R], L = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], H = () => [Te, R];
251
251
  return {
252
252
  cacheSize: 500,
253
253
  separator: ":",
@@ -398,21 +398,21 @@ const D = (e) => {
398
398
  * @see https://tailwindcss.com/docs/overscroll-behavior
399
399
  */
400
400
  overscroll: [{
401
- overscroll: b()
401
+ overscroll: w()
402
402
  }],
403
403
  /**
404
404
  * Overscroll Behavior X
405
405
  * @see https://tailwindcss.com/docs/overscroll-behavior
406
406
  */
407
407
  "overscroll-x": [{
408
- "overscroll-x": b()
408
+ "overscroll-x": w()
409
409
  }],
410
410
  /**
411
411
  * Overscroll Behavior Y
412
412
  * @see https://tailwindcss.com/docs/overscroll-behavior
413
413
  */
414
414
  "overscroll-y": [{
415
- "overscroll-y": b()
415
+ "overscroll-y": w()
416
416
  }],
417
417
  /**
418
418
  * Position
@@ -651,7 +651,7 @@ const D = (e) => {
651
651
  * @see https://tailwindcss.com/docs/justify-content
652
652
  */
653
653
  "justify-content": [{
654
- justify: ["normal", ...V()]
654
+ justify: ["normal", ...K()]
655
655
  }],
656
656
  /**
657
657
  * Justify Items
@@ -672,7 +672,7 @@ const D = (e) => {
672
672
  * @see https://tailwindcss.com/docs/align-content
673
673
  */
674
674
  "align-content": [{
675
- content: ["normal", ...V(), "baseline"]
675
+ content: ["normal", ...K(), "baseline"]
676
676
  }],
677
677
  /**
678
678
  * Align Items
@@ -693,7 +693,7 @@ const D = (e) => {
693
693
  * @see https://tailwindcss.com/docs/place-content
694
694
  */
695
695
  "place-content": [{
696
- "place-content": [...V(), "baseline"]
696
+ "place-content": [...K(), "baseline"]
697
697
  }],
698
698
  /**
699
699
  * Place Items
@@ -778,70 +778,70 @@ const D = (e) => {
778
778
  * @see https://tailwindcss.com/docs/margin
779
779
  */
780
780
  m: [{
781
- m: [k]
781
+ m: [I]
782
782
  }],
783
783
  /**
784
784
  * Margin X
785
785
  * @see https://tailwindcss.com/docs/margin
786
786
  */
787
787
  mx: [{
788
- mx: [k]
788
+ mx: [I]
789
789
  }],
790
790
  /**
791
791
  * Margin Y
792
792
  * @see https://tailwindcss.com/docs/margin
793
793
  */
794
794
  my: [{
795
- my: [k]
795
+ my: [I]
796
796
  }],
797
797
  /**
798
798
  * Margin Start
799
799
  * @see https://tailwindcss.com/docs/margin
800
800
  */
801
801
  ms: [{
802
- ms: [k]
802
+ ms: [I]
803
803
  }],
804
804
  /**
805
805
  * Margin End
806
806
  * @see https://tailwindcss.com/docs/margin
807
807
  */
808
808
  me: [{
809
- me: [k]
809
+ me: [I]
810
810
  }],
811
811
  /**
812
812
  * Margin Top
813
813
  * @see https://tailwindcss.com/docs/margin
814
814
  */
815
815
  mt: [{
816
- mt: [k]
816
+ mt: [I]
817
817
  }],
818
818
  /**
819
819
  * Margin Right
820
820
  * @see https://tailwindcss.com/docs/margin
821
821
  */
822
822
  mr: [{
823
- mr: [k]
823
+ mr: [I]
824
824
  }],
825
825
  /**
826
826
  * Margin Bottom
827
827
  * @see https://tailwindcss.com/docs/margin
828
828
  */
829
829
  mb: [{
830
- mb: [k]
830
+ mb: [I]
831
831
  }],
832
832
  /**
833
833
  * Margin Left
834
834
  * @see https://tailwindcss.com/docs/margin
835
835
  */
836
836
  ml: [{
837
- ml: [k]
837
+ ml: [I]
838
838
  }],
839
839
  /**
840
840
  * Space Between X
841
841
  * @see https://tailwindcss.com/docs/space
842
842
  */
843
843
  "space-x": [{
844
- "space-x": [x]
844
+ "space-x": [A]
845
845
  }],
846
846
  /**
847
847
  * Space Between X Reverse
@@ -853,7 +853,7 @@ const D = (e) => {
853
853
  * @see https://tailwindcss.com/docs/space
854
854
  */
855
855
  "space-y": [{
856
- "space-y": [x]
856
+ "space-y": [A]
857
857
  }],
858
858
  /**
859
859
  * Space Between Y Reverse
@@ -1218,21 +1218,21 @@ const D = (e) => {
1218
1218
  * @see https://tailwindcss.com/docs/gradient-color-stops
1219
1219
  */
1220
1220
  "gradient-from-pos": [{
1221
- from: [I]
1221
+ from: [v]
1222
1222
  }],
1223
1223
  /**
1224
1224
  * Gradient Color Stops Via Position
1225
1225
  * @see https://tailwindcss.com/docs/gradient-color-stops
1226
1226
  */
1227
1227
  "gradient-via-pos": [{
1228
- via: [I]
1228
+ via: [v]
1229
1229
  }],
1230
1230
  /**
1231
1231
  * Gradient Color Stops To Position
1232
1232
  * @see https://tailwindcss.com/docs/gradient-color-stops
1233
1233
  */
1234
1234
  "gradient-to-pos": [{
1235
- to: [I]
1235
+ to: [v]
1236
1236
  }],
1237
1237
  /**
1238
1238
  * Gradient Color Stops From
@@ -1713,14 +1713,14 @@ const D = (e) => {
1713
1713
  * @see https://tailwindcss.com/docs/saturate
1714
1714
  */
1715
1715
  saturate: [{
1716
- saturate: [A]
1716
+ saturate: [x]
1717
1717
  }],
1718
1718
  /**
1719
1719
  * Sepia
1720
1720
  * @see https://tailwindcss.com/docs/sepia
1721
1721
  */
1722
1722
  sepia: [{
1723
- sepia: [v]
1723
+ sepia: [k]
1724
1724
  }],
1725
1725
  /**
1726
1726
  * Backdrop Filter
@@ -1784,14 +1784,14 @@ const D = (e) => {
1784
1784
  * @see https://tailwindcss.com/docs/backdrop-saturate
1785
1785
  */
1786
1786
  "backdrop-saturate": [{
1787
- "backdrop-saturate": [A]
1787
+ "backdrop-saturate": [x]
1788
1788
  }],
1789
1789
  /**
1790
1790
  * Backdrop Sepia
1791
1791
  * @see https://tailwindcss.com/docs/backdrop-sepia
1792
1792
  */
1793
1793
  "backdrop-sepia": [{
1794
- "backdrop-sepia": [v]
1794
+ "backdrop-sepia": [k]
1795
1795
  }],
1796
1796
  // Tables
1797
1797
  /**
@@ -1927,14 +1927,14 @@ const D = (e) => {
1927
1927
  * @see https://tailwindcss.com/docs/skew
1928
1928
  */
1929
1929
  "skew-x": [{
1930
- "skew-x": [w]
1930
+ "skew-x": [b]
1931
1931
  }],
1932
1932
  /**
1933
1933
  * Skew Y
1934
1934
  * @see https://tailwindcss.com/docs/skew
1935
1935
  */
1936
1936
  "skew-y": [{
1937
- "skew-y": [w]
1937
+ "skew-y": [b]
1938
1938
  }],
1939
1939
  /**
1940
1940
  * Transform Origin
@@ -2343,12 +2343,12 @@ function Bn(e) {
2343
2343
  function Ct(e) {
2344
2344
  return !!(e && typeof e == "object" && (e.type === "file" || e.mimeType || e.filename || e.sourceType === "base64"));
2345
2345
  }
2346
- function Ve(e) {
2346
+ function Ke(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(Ve).filter((r) => r !== void 0);
2351
+ const n = e.map(Ke).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 Ve(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 o = Ve(r);
2375
+ const o = Ke(r);
2376
2376
  o !== void 0 && (t[n] = o);
2377
2377
  }
2378
2378
  }
@@ -2391,7 +2391,7 @@ function Et(e) {
2391
2391
  if (typeof e == "string") return e;
2392
2392
  if (Ct(e)) return "";
2393
2393
  try {
2394
- const t = Ve(e);
2394
+ const t = Ke(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 oo(e) {
2404
2404
  function Fn(e) {
2405
2405
  const t = (r) => {
2406
2406
  try {
2407
- const o = Ve(r);
2407
+ const o = Ke(r);
2408
2408
  return typeof o == "string" ? o : JSON.stringify(o ?? "");
2409
2409
  } catch {
2410
2410
  return "";
@@ -2448,27 +2448,27 @@ function le(e) {
2448
2448
  );
2449
2449
  }
2450
2450
  function nt(e) {
2451
- var k, p, S, A, E, v;
2451
+ var p, S, x, E, k, b, A;
2452
2452
  if (!e || typeof e != "object") return null;
2453
- const t = le(e), n = Vn(t);
2453
+ const t = le(e), n = Kn(t);
2454
2454
  if (!n)
2455
2455
  return null;
2456
- const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(rt) : void 0, o = Dn(t.content ?? t.parts, !!(r != null && r.length)), s = t.id ?? `msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`, a = t.createdAt ?? ((k = t.additionalKwargs) == null ? void 0 : k.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), i = t.name ?? ((p = t.additionalKwargs) == null ? void 0 : p.agentName) ?? void 0, u = t.model ?? ((S = t.additionalKwargs) == null ? void 0 : S.model) ?? void 0, c = t.toolCallId ?? void 0, l = t.additionalKwargs ?? void 0, d = t.responseMetadata ?? void 0, m = t.checkpointId ?? ((A = t.additionalKwargs) == null ? void 0 : A.checkpointId) ?? void 0, y = t.checkpointNs ?? ((E = t.additionalKwargs) == null ? void 0 : E.checkpointNs) ?? void 0, I = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((v = t.additionalKwargs) != null && v.toolStreaming);
2456
+ const r = t.toolCalls ?? ((p = t.additionalKwargs) == null ? void 0 : p.toolCalls), o = Array.isArray(r) ? r.map(rt) : void 0, s = Dn(t.content ?? t.parts, !!(o != null && o.length)), a = t.id ?? `msg-${Date.now().toString(16)}-${Math.random().toString(16).slice(2)}`, i = t.createdAt ?? ((S = t.additionalKwargs) == null ? void 0 : S.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), u = t.name ?? ((x = t.additionalKwargs) == null ? void 0 : x.agentName) ?? void 0, c = t.model ?? ((E = t.additionalKwargs) == null ? void 0 : E.model) ?? void 0, l = t.toolCallId ?? void 0, d = t.additionalKwargs ?? void 0, m = t.responseMetadata ?? void 0, y = t.checkpointId ?? ((k = t.additionalKwargs) == null ? void 0 : k.checkpointId) ?? void 0, v = t.checkpointNs ?? ((b = t.additionalKwargs) == null ? void 0 : b.checkpointNs) ?? void 0, f = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((A = t.additionalKwargs) != null && A.toolStreaming);
2457
2457
  return {
2458
2458
  ...t,
2459
- id: s,
2459
+ id: a,
2460
2460
  role: n,
2461
- content: o,
2462
- createdAt: a,
2463
- name: i,
2464
- model: u,
2465
- toolCallId: c,
2466
- toolCalls: r,
2467
- checkpointId: m,
2468
- checkpointNs: y,
2469
- toolStreaming: I,
2470
- additionalKwargs: l,
2471
- responseMetadata: d,
2461
+ content: s,
2462
+ createdAt: i,
2463
+ name: u,
2464
+ model: c,
2465
+ toolCallId: l,
2466
+ toolCalls: o,
2467
+ checkpointId: y,
2468
+ checkpointNs: v,
2469
+ toolStreaming: f,
2470
+ additionalKwargs: d,
2471
+ responseMetadata: m,
2472
2472
  artifact: t.artifact && typeof t.artifact == "object" && !t.artifact.type ? { ...t.artifact, type: t.name } : t.artifact ?? void 0
2473
2473
  };
2474
2474
  }
@@ -2497,12 +2497,12 @@ function Dn(e, t) {
2497
2497
  (n) => !!(n && typeof n == "object" && typeof n.type == "string")
2498
2498
  ) : [];
2499
2499
  }
2500
- function Vn(e) {
2500
+ function Kn(e) {
2501
2501
  const t = le(e), n = t.role;
2502
2502
  if (n && (n === "assistant" || n === "user" || n === "system" || n === "tool"))
2503
2503
  return n;
2504
2504
  const r = t.type;
2505
- return r === "human" ? "user" : r === "ai" ? "assistant" : r === "tool" ? "tool" : r === "system" ? "system" : null;
2505
+ return r ? r === "user" || r === "assistant" || r === "system" || r === "tool" ? r : r === "human" ? "user" : r === "ai" ? "assistant" : null : null;
2506
2506
  }
2507
2507
  function ut(e) {
2508
2508
  if (!e) return null;
@@ -2517,7 +2517,7 @@ function He(e, t) {
2517
2517
  (n) => n.role === "tool" && (n.toolCallId === e || n.id === e)
2518
2518
  );
2519
2519
  }
2520
- function Kn(e, t) {
2520
+ function Vn(e, t) {
2521
2521
  const n = t.response ?? t.content;
2522
2522
  if (!n) return;
2523
2523
  const r = typeof n == "string" ? n : Et(n);
@@ -2540,8 +2540,8 @@ function qn(e, t = []) {
2540
2540
  var d, m, y;
2541
2541
  const i = He(a.id, e) || He(a.id, t), u = Array.isArray((d = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : d.toolProgress) ? (m = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : m.toolProgress : void 0, c = (i == null ? void 0 : i.artifact) ?? a.artifact, l = ut(a.status) ?? ((y = i == null ? void 0 : i.additionalKwargs) != null && y.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2542
2542
  if (i && !a.content && l === "completed") {
2543
- const I = ce(i);
2544
- typeof I == "string" && (a.content = I);
2543
+ const v = ce(i);
2544
+ typeof v == "string" && (a.content = v);
2545
2545
  }
2546
2546
  return {
2547
2547
  call: a,
@@ -2556,7 +2556,7 @@ function qn(e, t = []) {
2556
2556
  const n = dt(e);
2557
2557
  return n.length === 0 ? [] : n.map((r) => {
2558
2558
  var u, c, l;
2559
- const o = He(r.id, t) ?? Kn(e, r), s = Array.isArray((u = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : u.toolProgress) ? (c = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : c.toolProgress : void 0, a = (o == null ? void 0 : o.artifact) ?? r.artifact, i = ut(r.status) ?? ((l = o == null ? void 0 : o.additionalKwargs) != null && l.toolStreaming ? "pending" : null) ?? (o ? "completed" : "pending");
2559
+ const o = He(r.id, t) ?? Vn(e, r), s = Array.isArray((u = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : u.toolProgress) ? (c = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : c.toolProgress : void 0, a = (o == null ? void 0 : o.artifact) ?? r.artifact, i = ut(r.status) ?? ((l = o == null ? void 0 : o.additionalKwargs) != null && l.toolStreaming ? "pending" : null) ?? (o ? "completed" : "pending");
2560
2560
  if (o && !r.content && i === "completed") {
2561
2561
  const d = ce(o);
2562
2562
  typeof d == "string" && (r.content = d);
@@ -2585,13 +2585,13 @@ const ze = {
2585
2585
  function Ge(e) {
2586
2586
  return `draft:${e}`;
2587
2587
  }
2588
- let Ke = null;
2588
+ let Ve = null;
2589
2589
  const Qe = /* @__PURE__ */ new Set();
2590
2590
  function Pt() {
2591
- return Ke;
2591
+ return Ve;
2592
2592
  }
2593
2593
  function ve(e) {
2594
- Ke = e, Qe.forEach((t) => t(e));
2594
+ Ve = e, Qe.forEach((t) => t(e));
2595
2595
  }
2596
2596
  function _t(e) {
2597
2597
  return Qe.add(e), () => Qe.delete(e);
@@ -2613,7 +2613,7 @@ function Wn(e) {
2613
2613
  function Jn() {
2614
2614
  return Nt;
2615
2615
  }
2616
- ne.interceptors.request.use((e) => (Ke && (e.headers.Authorization = `Bearer ${Ke}`), e));
2616
+ ne.interceptors.request.use((e) => (Ve && (e.headers.Authorization = `Bearer ${Ve}`), e));
2617
2617
  ne.interceptors.response.use(
2618
2618
  (e) => {
2619
2619
  if (typeof window < "u" && (e != null && e.data))
@@ -3014,28 +3014,28 @@ function pr(e = {}) {
3014
3014
  i.current = e;
3015
3015
  }, [e]);
3016
3016
  const u = _((g) => {
3017
- var j, M, O, F, C, B, N, V, z, L;
3018
- const b = i.current;
3019
- if (!b) return;
3020
- (j = b.onEvent) == null || j.call(b, g), g.type === "thread_info" && ((M = b.onThreadInfo) == null || M.call(b, g)), g.type === "values" && Array.isArray(g.checkpoints) && ((O = b.handleValuesEvent) == null || O.call(b, g)), g.type === "metadata" && ((F = b.onMetadataEvent) == null || F.call(b, g)), typeof g.type == "string" && (g.type === "custom" || g.type.startsWith("custom.")) && ((C = b.onCustomEvent) == null || C.call(b, g)), g.type === "updates" && ((B = b.onUpdateEvent) == null || B.call(b, g)), g.type === "tool.end" ? (N = b.onToolEnd) == null || N.call(b, g) : g.type === "tool.start" && ((V = b.onToolStart) == null || V.call(b, g)), g.type === "heartbeat" && ((z = b.onHeartbeat) == null || z.call(b, g)), g.type === "token" && ((L = b.onToken) == null || L.call(b, g.token));
3021
- }, []), [c, l] = $(!1), [d, m] = $(null), [y, I] = $(!1), [f, k] = $(null), p = W(null), S = W(!0), A = W(null), E = _((g) => {
3017
+ var j, M, O, F, C, B, N, K, z, L;
3018
+ const w = i.current;
3019
+ if (!w) return;
3020
+ (j = w.onEvent) == null || j.call(w, g), g.type === "thread_info" && ((M = w.onThreadInfo) == null || M.call(w, g)), g.type === "values" && Array.isArray(g.checkpoints) && ((O = w.handleValuesEvent) == null || O.call(w, g)), g.type === "metadata" && ((F = w.onMetadataEvent) == null || F.call(w, g)), typeof g.type == "string" && (g.type === "custom" || g.type.startsWith("custom.")) && ((C = w.onCustomEvent) == null || C.call(w, g)), g.type === "updates" && ((B = w.onUpdateEvent) == null || B.call(w, g)), g.type === "tool.end" ? (N = w.onToolEnd) == null || N.call(w, g) : g.type === "tool.start" && ((K = w.onToolStart) == null || K.call(w, g)), g.type === "heartbeat" && ((z = w.onHeartbeat) == null || z.call(w, g)), g.type === "token" && ((L = w.onToken) == null || L.call(w, g.token));
3021
+ }, []), [c, l] = $(!1), [d, m] = $(null), [y, v] = $(!1), [f, I] = $(null), p = W(null), S = W(!0), x = W(null), E = _((g) => {
3022
3022
  o(g);
3023
- }, []), v = _(() => {
3024
- m(null), k(null);
3025
- }, []), w = _(() => {
3023
+ }, []), k = _(() => {
3024
+ m(null), I(null);
3025
+ }, []), b = _(() => {
3026
3026
  var M, O;
3027
3027
  console.debug("[use-chat] stop() invoked - aborting stream");
3028
- const g = (M = A.current) == null ? void 0 : M.threadId, b = (O = A.current) == null ? void 0 : O.runId, P = () => {
3028
+ const g = (M = x.current) == null ? void 0 : M.threadId, w = (O = x.current) == null ? void 0 : O.runId, P = () => {
3029
3029
  var F;
3030
- (F = p.current) == null || F.abort(), p.current = null, A.current = null, l(!1), I(!1);
3030
+ (F = p.current) == null || F.abort(), p.current = null, x.current = null, l(!1), v(!1);
3031
3031
  };
3032
- (b || g ? zt.cancelRun(b || g).catch((F) => {
3032
+ (w || g ? zt.cancelRun(w || g).catch((F) => {
3033
3033
  console.warn("[use-chat] cancel run failed:", F);
3034
3034
  }) : Promise.resolve()).finally(P);
3035
- }, []), x = _(
3035
+ }, []), A = _(
3036
3036
  (g) => {
3037
3037
  p.current && (p.current.abort(), p.current = null);
3038
- const b = {
3038
+ const w = {
3039
3039
  text: typeof g.content == "string" ? g.content : g.text,
3040
3040
  threadId: g.threadId,
3041
3041
  attachments: g.attachments,
@@ -3049,18 +3049,18 @@ function pr(e = {}) {
3049
3049
  edit: g.edit ?? !1,
3050
3050
  command: g.command
3051
3051
  };
3052
- l(!0), m(null), k(null);
3052
+ l(!0), m(null), I(null);
3053
3053
  const P = new AbortController();
3054
3054
  p.current = P;
3055
3055
  let j = null, M = !1;
3056
- return A.current = {
3057
- threadId: b.threadId ?? void 0,
3056
+ return x.current = {
3057
+ threadId: w.threadId ?? void 0,
3058
3058
  runId: void 0,
3059
3059
  // Will be updated from headers
3060
3060
  headers: {},
3061
3061
  isStreaming: !0
3062
3062
  }, (async () => {
3063
- var O, F, C, B, N, V;
3063
+ var O, F, C, B, N, K;
3064
3064
  try {
3065
3065
  let z = {};
3066
3066
  try {
@@ -3098,11 +3098,11 @@ function pr(e = {}) {
3098
3098
  }, U = await fetch(t + n, {
3099
3099
  method: "POST",
3100
3100
  headers: h,
3101
- body: JSON.stringify(b),
3101
+ body: JSON.stringify(w),
3102
3102
  signal: P.signal,
3103
3103
  credentials: a
3104
3104
  });
3105
- if (A.current && (A.current.headers = H), !U.ok || !U.body) {
3105
+ if (x.current && (x.current.headers = H), !U.ok || !U.body) {
3106
3106
  const G = await U.text().catch(() => "");
3107
3107
  console.debug(
3108
3108
  "[use-chat] non-OK response",
@@ -3112,28 +3112,28 @@ function pr(e = {}) {
3112
3112
  const te = `stream ${U.status}${G ? ": " + G : ""}`;
3113
3113
  throw te && (m(te), j = "error"), new Error(te);
3114
3114
  }
3115
- I(!0);
3115
+ v(!0);
3116
3116
  const T = U.body.getReader(), J = new TextDecoder();
3117
- let K = "", q = 0, ee = Date.now();
3117
+ let V = "", q = 0, ee = Date.now();
3118
3118
  const re = setInterval(() => {
3119
3119
  Date.now() - ee > 18e5 && (m("Stream idle timeout"), j = "error", P.abort());
3120
3120
  }, 5e3), ue = 1024 * 1024;
3121
3121
  try {
3122
3122
  const G = U.headers.get("X-Thread-Id") || U.headers.get("x-thread-id"), te = U.headers.get("X-Run-Id") || U.headers.get("x-run-id");
3123
- for (A.current && (A.current = {
3124
- ...A.current,
3125
- threadId: G ?? A.current.threadId,
3126
- runId: te ?? A.current.runId
3123
+ for (x.current && (x.current = {
3124
+ ...x.current,
3125
+ threadId: G ?? x.current.threadId,
3126
+ runId: te ?? x.current.runId
3127
3127
  }); ; ) {
3128
3128
  const { value: ke, done: Q } = await T.read();
3129
3129
  if (Q) break;
3130
- K += J.decode(ke, { stream: !0 }), K.length > ue && (K = "", console.warn("Stream buffer reset: exceeded 1MB"));
3130
+ V += J.decode(ke, { stream: !0 }), V.length > ue && (V = "", console.warn("Stream buffer reset: exceeded 1MB"));
3131
3131
  let Z;
3132
- for (; (Z = K.indexOf(`
3132
+ for (; (Z = V.indexOf(`
3133
3133
 
3134
3134
  `)) >= 0; ) {
3135
- const ge = K.slice(0, Z);
3136
- K = K.slice(Z + 2);
3135
+ const ge = V.slice(0, Z);
3136
+ V = V.slice(Z + 2);
3137
3137
  const je = ge.split(/\r?\n/), Be = [];
3138
3138
  let me = null;
3139
3139
  for (const he of je)
@@ -3199,7 +3199,7 @@ function pr(e = {}) {
3199
3199
  j = j ?? "aborted";
3200
3200
  else {
3201
3201
  const L = z.message || String(z);
3202
- j = "error", m(L), M || (M = !0, (V = e.onConnectionError) == null || V.call(e, L));
3202
+ j = "error", m(L), M || (M = !0, (K = e.onConnectionError) == null || K.call(e, L));
3203
3203
  }
3204
3204
  } finally {
3205
3205
  try {
@@ -3216,7 +3216,7 @@ function pr(e = {}) {
3216
3216
  } catch (z) {
3217
3217
  console.warn("[use-chat] onClosed callback failed", z);
3218
3218
  }
3219
- l(!1), I(!1), p.current = null, A.current = null;
3219
+ l(!1), v(!1), p.current = null, x.current = null;
3220
3220
  }
3221
3221
  })(), Promise.resolve();
3222
3222
  },
@@ -3237,9 +3237,9 @@ function pr(e = {}) {
3237
3237
  // Deprecated: use checkpoint from reducer
3238
3238
  lastSeq: 0,
3239
3239
  connected: y,
3240
- stream: x,
3241
- stop: w,
3242
- clear: v,
3240
+ stream: A,
3241
+ stop: b,
3242
+ clear: k,
3243
3243
  setToken: E,
3244
3244
  values: {},
3245
3245
  // Provide empty object for backward compatibility
@@ -3249,7 +3249,7 @@ function pr(e = {}) {
3249
3249
  connectionState: d ? "error" : c ? y ? "connected" : "connecting" : "idle",
3250
3250
  messages: [],
3251
3251
  // useStream doesn't maintain messages, use useChatSession instead
3252
- submit: x
3252
+ submit: A
3253
3253
  };
3254
3254
  }
3255
3255
  function gr({
@@ -3259,7 +3259,7 @@ function gr({
3259
3259
  onThreadChange: r,
3260
3260
  onCurrentThreadDeleted: o
3261
3261
  }) {
3262
- const [s, a] = $([]), [i, u] = $(t), [c, l] = $(!1), [d, m] = $(null), y = W(i), I = W(/* @__PURE__ */ new Map());
3262
+ const [s, a] = $([]), [i, u] = $(t), [c, l] = $(!1), [d, m] = $(null), y = W(i), v = W(/* @__PURE__ */ new Map());
3263
3263
  X(() => {
3264
3264
  y.current = i;
3265
3265
  }, [i]), X(() => {
@@ -3268,11 +3268,11 @@ function gr({
3268
3268
  const f = _(async () => {
3269
3269
  l(!0), m(null);
3270
3270
  try {
3271
- const v = await e.listThreads();
3272
- a(v ?? []);
3273
- } catch (v) {
3274
- const w = String(v);
3275
- m(w), n == null || n(w);
3271
+ const k = await e.listThreads();
3272
+ a(k ?? []);
3273
+ } catch (k) {
3274
+ const b = String(k);
3275
+ m(b), n == null || n(b);
3276
3276
  } finally {
3277
3277
  l(!1);
3278
3278
  }
@@ -3282,71 +3282,71 @@ function gr({
3282
3282
  }, [f]), X(() => {
3283
3283
  r == null || r(i);
3284
3284
  }, [i, r]);
3285
- const k = _(
3286
- async (v, w) => {
3285
+ const I = _(
3286
+ async (k, b) => {
3287
3287
  try {
3288
- const x = w && typeof w == "object" ? { id: w.id, name: w.name ?? "" } : void 0, g = await e.createThread(v, x);
3288
+ const A = b && typeof b == "object" ? { id: b.id, name: b.name ?? "" } : void 0, g = await e.createThread(k, A);
3289
3289
  return u(g.threadId), await f(), g.threadId;
3290
- } catch (x) {
3291
- const g = String(x);
3290
+ } catch (A) {
3291
+ const g = String(A);
3292
3292
  return n == null || n(g), null;
3293
3293
  }
3294
3294
  },
3295
3295
  [e, n, f]
3296
3296
  ), p = _(
3297
- async (v) => {
3298
- const w = s;
3299
- a((g) => g.filter((b) => b.threadId !== v));
3300
- const x = new AbortController();
3301
- I.current.set(v, x);
3297
+ async (k) => {
3298
+ const b = s;
3299
+ a((g) => g.filter((w) => w.threadId !== k));
3300
+ const A = new AbortController();
3301
+ v.current.set(k, A);
3302
3302
  try {
3303
- await e.deleteThread(v), y.current === v && (u(null), o == null || o());
3303
+ await e.deleteThread(k), y.current === k && (u(null), o == null || o());
3304
3304
  } catch (g) {
3305
- a(w);
3306
- const b = String(g);
3307
- n == null || n(b);
3305
+ a(b);
3306
+ const w = String(g);
3307
+ n == null || n(w);
3308
3308
  } finally {
3309
- I.current.delete(v);
3309
+ v.current.delete(k);
3310
3310
  }
3311
3311
  },
3312
3312
  [e, o, n, s]
3313
3313
  ), S = _(
3314
- async (v, w) => {
3314
+ async (k, b) => {
3315
3315
  try {
3316
- await e.updateThread(v, w), await f();
3317
- } catch (x) {
3318
- n == null || n(String(x));
3316
+ await e.updateThread(k, b), await f();
3317
+ } catch (A) {
3318
+ n == null || n(String(A));
3319
3319
  }
3320
3320
  },
3321
3321
  [e, n, f]
3322
- ), A = Y(
3322
+ ), x = Y(
3323
3323
  () => ({
3324
- createThread: k,
3324
+ createThread: I,
3325
3325
  deleteThread: p,
3326
3326
  renameThread: S,
3327
3327
  refreshThreads: f
3328
3328
  }),
3329
- [k, p, S, f]
3330
- ), E = _((v) => {
3331
- if (!(v != null && v.threadId)) return;
3332
- const w = {
3333
- threadId: v.threadId,
3334
- title: v.title || `Thread ${v.threadId.slice(0, 8)}`,
3335
- project: v.project,
3336
- createdAt: v.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
3337
- updatedAt: v.updatedAt || (/* @__PURE__ */ new Date()).toISOString(),
3338
- messageCount: v.messageCount ?? 1
3329
+ [I, p, S, f]
3330
+ ), E = _((k) => {
3331
+ if (!(k != null && k.threadId)) return;
3332
+ const b = {
3333
+ threadId: k.threadId,
3334
+ title: k.title || `Thread ${k.threadId.slice(0, 8)}`,
3335
+ project: k.project,
3336
+ createdAt: k.createdAt || (/* @__PURE__ */ new Date()).toISOString(),
3337
+ updatedAt: k.updatedAt || (/* @__PURE__ */ new Date()).toISOString(),
3338
+ messageCount: k.messageCount ?? 1
3339
3339
  };
3340
- a((x) => {
3340
+ a((A) => {
3341
3341
  let g = !1;
3342
- const b = x.map((P) => P.threadId === w.threadId ? (g = !0, console.debug("[useThreadsState] thread_info: updating existing thread", w.threadId), {
3342
+ const w = A.map((P) => P.threadId === b.threadId ? (g = !0, console.debug("[useThreadsState] thread_info: updating existing thread", b.threadId), {
3343
3343
  ...P,
3344
- title: w.title ?? P.title,
3345
- project: w.project ?? P.project,
3346
- updatedAt: w.updatedAt ?? P.updatedAt,
3347
- messageCount: w.messageCount ?? P.messageCount
3344
+ title: b.title ?? P.title,
3345
+ project: b.project ?? P.project,
3346
+ updatedAt: b.updatedAt ?? P.updatedAt,
3347
+ messageCount: b.messageCount ?? P.messageCount
3348
3348
  }) : P);
3349
- return g ? b : (console.debug("[useThreadsState] thread_info: adding thread to list", w.threadId), [w, ...x]);
3349
+ return g ? w : (console.debug("[useThreadsState] thread_info: adding thread to list", b.threadId), [b, ...A]);
3350
3350
  });
3351
3351
  }, []);
3352
3352
  return {
@@ -3356,7 +3356,7 @@ function gr({
3356
3356
  setCurrentThreadId: u,
3357
3357
  isLoadingThreads: c,
3358
3358
  threadsError: d,
3359
- actions: A,
3359
+ actions: x,
3360
3360
  addThreadFromEvent: E
3361
3361
  };
3362
3362
  }
@@ -3443,7 +3443,8 @@ function hr(e, t, n) {
3443
3443
  }) ?? null;
3444
3444
  }
3445
3445
  function Oe(e) {
3446
- return e.map((t) => nt(t)).filter((t) => !!t);
3446
+ const t = /* @__PURE__ */ new Set();
3447
+ return e.map((n) => nt(n)).filter((n) => !n || t.has(n.id) ? !1 : (t.add(n.id), !0));
3447
3448
  }
3448
3449
  function Ft(e, t, n) {
3449
3450
  return t < 0 || t >= e.length ? e : [...e.slice(0, t), n, ...e.slice(t + 1)];
@@ -3608,7 +3609,7 @@ function pt(e, t) {
3608
3609
  return t.type === "messages/partial" ? vr(e, t, o) : t.type === "tool.start" ? { ...Ir(e, t, o), status: "streaming" } : t.type === "tool.progress" ? Ar(e, t, o) : t.type === "tool.end" ? xr(e, t, o) : t.type === "artifact.update" ? Tr(e, t) : e;
3609
3610
  }
3610
3611
  function vr(e, t, n) {
3611
- var m, y, I, f, k;
3612
+ var m, y, v, f, I;
3612
3613
  const r = t.messages;
3613
3614
  if (!r.length)
3614
3615
  return console.warn("[messagesReducer] Dropping messages/partial event without messages[]", t), e;
@@ -3647,8 +3648,8 @@ function vr(e, t, n) {
3647
3648
  ...e.messagesStreamMeta ?? {},
3648
3649
  [s]: {
3649
3650
  ...((m = e.messagesStreamMeta) == null ? void 0 : m[s]) ?? {},
3650
- lastSeq: t.seq ?? ((I = (y = e.messagesStreamMeta) == null ? void 0 : y[s]) == null ? void 0 : I.lastSeq) ?? null,
3651
- lastText: u || (((k = (f = e.messagesStreamMeta) == null ? void 0 : f[s]) == null ? void 0 : k.lastText) ?? "")
3651
+ lastSeq: t.seq ?? ((v = (y = e.messagesStreamMeta) == null ? void 0 : y[s]) == null ? void 0 : v.lastSeq) ?? null,
3652
+ lastText: u || (((I = (f = e.messagesStreamMeta) == null ? void 0 : f[s]) == null ? void 0 : I.lastText) ?? "")
3652
3653
  }
3653
3654
  }
3654
3655
  };
@@ -3818,8 +3819,8 @@ async function Mr(e, t) {
3818
3819
  if (Array.isArray(m))
3819
3820
  for (const y of m) {
3820
3821
  if (!y || typeof y != "object" || y.type !== "image_url" && y.type !== "file") continue;
3821
- const I = y.fileId || y.file_id;
3822
- typeof I == "string" && I.trim() && o.add(I);
3822
+ const v = y.fileId || y.file_id;
3823
+ typeof v == "string" && v.trim() && o.add(v);
3823
3824
  }
3824
3825
  }
3825
3826
  }
@@ -3843,10 +3844,10 @@ async function Mr(e, t) {
3843
3844
  if (Array.isArray(m))
3844
3845
  for (const y of m) {
3845
3846
  if (!y || typeof y != "object" || y.type !== "image_url" && y.type !== "file") continue;
3846
- const I = y.fileId || y.file_id;
3847
- if (!I) continue;
3848
- const f = a.get(I), k = (f == null ? void 0 : f.contentUrl) || (f == null ? void 0 : f.content_url);
3849
- k && (y.type === "image_url" ? (y.imageUrl = y.imageUrl || {}, y.imageUrl.url = k) : y.type === "file" && (y.url = k, !y.name && (f != null && f.filename || f != null && f.name) && (y.name = (f == null ? void 0 : f.filename) || (f == null ? void 0 : f.name))));
3847
+ const v = y.fileId || y.file_id;
3848
+ if (!v) continue;
3849
+ const f = a.get(v), I = (f == null ? void 0 : f.contentUrl) || (f == null ? void 0 : f.content_url);
3850
+ I && (y.type === "image_url" ? (y.imageUrl = y.imageUrl || {}, y.imageUrl.url = I) : y.type === "file" && (y.url = I, !y.name && (f != null && f.filename || f != null && f.name) && (y.name = (f == null ? void 0 : f.filename) || (f == null ? void 0 : f.name))));
3850
3851
  }
3851
3852
  }
3852
3853
  }
@@ -3862,21 +3863,21 @@ function mt(e) {
3862
3863
  };
3863
3864
  }
3864
3865
  function Cr(e, t) {
3865
- var v, w;
3866
+ var k, b;
3866
3867
  if (!e) return null;
3867
- const n = ((v = e.values) == null ? void 0 : v.activeAgent) ?? null, r = (w = e.values) == null ? void 0 : w.messages, s = (Array.isArray(r) ? r : []).map((x) => Er(x, n)).filter((x) => !!x), a = Re(e.metadata) ?? {}, i = gt(e.config), u = Re(e.parentConfig), c = gt(u), l = Fe(i, ["checkpointId"]), d = Fe(i, ["checkpointNs"]), m = Fe(c, ["checkpointId"]), y = Re(e.config), I = Array.isArray(e.tasks) ? e.tasks.map((x) => ({ ...x })) : e.tasks ?? null, f = Array.isArray(e.next) ? [...e.next] : e.next ?? null, k = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), p = {
3868
+ const n = ((k = e.values) == null ? void 0 : k.activeAgent) ?? null, r = (b = e.values) == null ? void 0 : b.messages, s = (Array.isArray(r) ? r : []).map((A) => Er(A, n)).filter((A) => !!A), a = Re(e.metadata) ?? {}, i = gt(e.config), u = Re(e.parentConfig), c = gt(u), l = Fe(i, ["checkpointId"]), d = Fe(i, ["checkpointNs"]), m = Fe(c, ["checkpointId"]), y = Re(e.config), v = Array.isArray(e.tasks) ? e.tasks.map((A) => ({ ...A })) : e.tasks ?? null, f = Array.isArray(e.next) ? [...e.next] : e.next ?? null, I = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), p = {
3868
3869
  ...a,
3869
3870
  step: Sr(a, ["step"]) ?? 0,
3870
3871
  source: Fe(a, ["source"]) ?? null
3871
- }, S = s.map((x) => ({
3872
- ...x,
3873
- checkpointId: x.checkpointId ?? l ?? null,
3874
- checkpointNs: x.checkpointNs ?? d ?? null
3875
- })), A = e.values, E = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(A == null ? void 0 : A.interrupts) ? A.interrupts : [];
3872
+ }, S = s.map((A) => ({
3873
+ ...A,
3874
+ checkpointId: A.checkpointId ?? l ?? null,
3875
+ checkpointNs: A.checkpointNs ?? d ?? null
3876
+ })), x = e.values, E = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(x == null ? void 0 : x.interrupts) ? x.interrupts : [];
3876
3877
  return {
3877
3878
  checkpointId: l ?? null,
3878
3879
  checkpointNs: d ?? null,
3879
- createdAt: k,
3880
+ createdAt: I,
3880
3881
  parentId: m ?? null,
3881
3882
  messages: S,
3882
3883
  interrupt: Pr(
@@ -3888,7 +3889,7 @@ function Cr(e, t) {
3888
3889
  config: y ?? null,
3889
3890
  parentConfig: u ?? null,
3890
3891
  next: f,
3891
- tasks: I,
3892
+ tasks: v,
3892
3893
  values: e.values ?? {}
3893
3894
  };
3894
3895
  }
@@ -3933,33 +3934,33 @@ function Nr(e) {
3933
3934
  function zr(e) {
3934
3935
  const t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Map(), o = [];
3935
3936
  for (let c = 0; c < e.length; c++) {
3936
- const l = e[c], d = l.checkpointId, m = d ?? `cp-${c}`, y = l.metadata ?? {}, I = typeof y.step == "number" ? y.step : null, f = typeof y.source == "string" ? y.source : null;
3937
- let k = null, p = null;
3937
+ const l = e[c], d = l.checkpointId, m = d ?? `cp-${c}`, y = l.metadata ?? {}, v = typeof y.step == "number" ? y.step : null, f = typeof y.source == "string" ? y.source : null;
3938
+ let I = null, p = null;
3938
3939
  const S = Array.isArray(l.messages) ? l.messages : [];
3939
- for (const w of S)
3940
- w.role === "user" && (p || (p = w), w.id && (k = w.id));
3941
- const A = l.next && l.next.length > 0 ? String(l.next[0]) : null, E = l.parentConfig ?? null, v = {
3940
+ for (const b of S)
3941
+ b.role === "user" && (p || (p = b), b.id && (I = b.id));
3942
+ const x = l.next && l.next.length > 0 ? String(l.next[0]) : null, E = l.parentConfig ?? null, k = {
3942
3943
  id: m,
3943
- step: I,
3944
+ step: v,
3944
3945
  source: f,
3945
3946
  createdAt: l.createdAt ?? null,
3946
3947
  namespace: l.checkpointNs ?? null,
3947
3948
  parentId: l.parentId ?? null,
3948
- next: A,
3949
+ next: x,
3949
3950
  parentConfig: E,
3950
- userMessageId: k
3951
+ userMessageId: I
3951
3952
  };
3952
- if (o.push(v), d && t.set(d, v), d && p) {
3953
- const w = Nr(p);
3954
- w && r.set(d, w);
3953
+ if (o.push(k), d && t.set(d, k), d && p) {
3954
+ const b = Nr(p);
3955
+ b && r.set(d, b);
3955
3956
  }
3956
3957
  n.push({
3957
3958
  id: m,
3958
- messageId: k,
3959
- step: I,
3959
+ messageId: I,
3960
+ step: v,
3960
3961
  source: f,
3961
3962
  createdAt: l.createdAt ?? null,
3962
- next: A,
3963
+ next: x,
3963
3964
  parentConfig: E
3964
3965
  });
3965
3966
  }
@@ -3997,8 +3998,8 @@ function zr(e) {
3997
3998
  for (const d of t.values())
3998
3999
  d.userMessageId === c && l.push(d);
3999
4000
  return l.length ? (l.sort((d, m) => {
4000
- const y = typeof d.attemptIndex == "number" ? d.attemptIndex : Number.MAX_SAFE_INTEGER, I = typeof m.attemptIndex == "number" ? m.attemptIndex : Number.MAX_SAFE_INTEGER;
4001
- return y - I;
4001
+ const y = typeof d.attemptIndex == "number" ? d.attemptIndex : Number.MAX_SAFE_INTEGER, v = typeof m.attemptIndex == "number" ? m.attemptIndex : Number.MAX_SAFE_INTEGER;
4002
+ return y - v;
4002
4003
  }), l) : [];
4003
4004
  }
4004
4005
  };
@@ -4036,11 +4037,11 @@ function $t({
4036
4037
  const [u, c] = $(null), d = Y(
4037
4038
  () => mt(u),
4038
4039
  [u]
4039
- ).checkpoints, m = Rr(d), y = m.timeline, [I, f] = $(!1), [k, p] = $(!1), [S, A] = $(!1), [E, v] = $(null), w = W(o), x = W(null), g = W(null);
4040
+ ).checkpoints, m = Rr(d), y = m.timeline, [v, f] = $(!1), [I, p] = $(!1), [S, x] = $(!1), [E, k] = $(null), b = W(o), A = W(null), g = W(null);
4040
4041
  X(() => {
4041
- w.current = o;
4042
+ b.current = o;
4042
4043
  }, [o]);
4043
- const b = _(
4044
+ const w = _(
4044
4045
  async (C) => {
4045
4046
  const B = await e.getState({
4046
4047
  threadId: C.threadId,
@@ -4050,7 +4051,7 @@ function $t({
4050
4051
  version: "values@1",
4051
4052
  threadId: C.threadId,
4052
4053
  checkpoints: [B]
4053
- }, V = t ? await Mr(N, t) : N, { latest: z } = mt(V);
4054
+ }, K = t ? await Mr(N, t) : N, { latest: z } = mt(K);
4054
4055
  return z;
4055
4056
  },
4056
4057
  [e, t]
@@ -4059,16 +4060,16 @@ function $t({
4059
4060
  var z;
4060
4061
  if (!C) return;
4061
4062
  const N = `${C}:${B ?? "latest"}`;
4062
- if (x.current === N || I) return;
4063
+ if (A.current === N || v) return;
4063
4064
  (z = g.current) == null || z.abort();
4064
- const V = new AbortController();
4065
- g.current = V, f(!0), v(null);
4065
+ const K = new AbortController();
4066
+ g.current = K, f(!0), k(null);
4066
4067
  try {
4067
- const L = await b({
4068
+ const L = await w({
4068
4069
  threadId: C,
4069
4070
  checkpointId: B ?? void 0
4070
4071
  });
4071
- if (w.current !== C) {
4072
+ if (b.current !== C) {
4072
4073
  f(!1);
4073
4074
  return;
4074
4075
  }
@@ -4077,31 +4078,31 @@ function $t({
4077
4078
  checkpointNs: (L == null ? void 0 : L.checkpointNs) ?? null,
4078
4079
  pendingInterrupt: (L == null ? void 0 : L.interrupt) ?? null,
4079
4080
  values: L == null ? void 0 : L.values
4080
- }), x.current = N, f(!1), A(!0);
4081
+ }), A.current = N, f(!1), x(!0);
4081
4082
  try {
4082
4083
  const H = await e.getStateHistory({
4083
4084
  threadId: C,
4084
4085
  limit: 100,
4085
4086
  includeMessages: !1
4086
4087
  });
4087
- w.current === C && c(H);
4088
+ b.current === C && c(H);
4088
4089
  } finally {
4089
- A(!1);
4090
+ x(!1);
4090
4091
  }
4091
4092
  } catch (L) {
4092
4093
  if (f(!1), !Xt(L)) {
4093
4094
  const H = String(L);
4094
- v(H), r == null || r(H);
4095
+ k(H), r == null || r(H);
4095
4096
  }
4096
4097
  }
4097
4098
  },
4098
- [e, n, b, r, i]
4099
+ [e, n, w, r, i]
4099
4100
  ), j = _(
4100
4101
  async (C, B) => {
4101
4102
  if (o) {
4102
4103
  p(!0);
4103
4104
  try {
4104
- const N = await b({
4105
+ const N = await w({
4105
4106
  threadId: o,
4106
4107
  checkpointId: C,
4107
4108
  checkpointNs: B ?? void 0
@@ -4119,16 +4120,16 @@ function $t({
4119
4120
  }
4120
4121
  }
4121
4122
  },
4122
- [o, b, n]
4123
+ [o, w, n]
4123
4124
  ), M = _(async () => {
4124
4125
  o && await P(o);
4125
4126
  }, [o, P]), O = _(
4126
4127
  async (C) => {
4127
- var V;
4128
+ var K;
4128
4129
  const B = (C == null ? void 0 : C.threadId) || o;
4129
4130
  if (!B || o !== B) return;
4130
- if (c(C), x.current = `${B}:latest`, (V = C.values) != null && V.messages) {
4131
- const z = await b({
4131
+ if (c(C), A.current = `${B}:latest`, (K = C.values) != null && K.messages) {
4132
+ const z = await w({
4132
4133
  threadId: B
4133
4134
  });
4134
4135
  z && n(z.messages ?? [], {
@@ -4139,22 +4140,22 @@ function $t({
4139
4140
  });
4140
4141
  }
4141
4142
  },
4142
- [o, b, n]
4143
+ [o, w, n]
4143
4144
  );
4144
4145
  X(() => {
4145
- if (!s || !o || I || a) return;
4146
+ if (!s || !o || v || a) return;
4146
4147
  const C = `${o}:latest`;
4147
- x.current !== C && P(o);
4148
- }, [s, o, I, a, P]);
4148
+ A.current !== C && P(o);
4149
+ }, [s, o, v, a, P]);
4149
4150
  const F = _(() => {
4150
- c(null), f(!1), p(!1), A(!1), v(null), x.current = null;
4151
+ c(null), f(!1), p(!1), x(!1), k(null), A.current = null;
4151
4152
  }, []);
4152
4153
  return {
4153
4154
  threadCheckpoints: d,
4154
4155
  threadTimeline: y,
4155
4156
  checkpointIndex: m,
4156
- isLoadingThread: I,
4157
- isLoadingCheckpoint: k,
4157
+ isLoadingThread: v,
4158
+ isLoadingCheckpoint: I,
4158
4159
  isLoadingHistory: S,
4159
4160
  threadStateError: E,
4160
4161
  loadThread: P,
@@ -4172,14 +4173,14 @@ function $t({
4172
4173
  clearState: F
4173
4174
  };
4174
4175
  }
4175
- const Dt = Ce(null), Vt = Ce(null);
4176
- function Kt(e) {
4176
+ const Dt = Ce(null), Kt = Ce(null);
4177
+ function Vt(e) {
4177
4178
  const t = Ue(Dt);
4178
4179
  if (!t && !(e != null && e.optional)) throw new Error("useThreadState must be used within a ThreadStateProvider");
4179
4180
  return t;
4180
4181
  }
4181
4182
  function Lr() {
4182
- const e = Ue(Vt);
4183
+ const e = Ue(Kt);
4183
4184
  if (!e)
4184
4185
  throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");
4185
4186
  return e;
@@ -4194,18 +4195,18 @@ function Ur({
4194
4195
  onError: a
4195
4196
  }) {
4196
4197
  const { chatApi: i, fileApi: u } = Me(), { currentThreadId: c } = ot(), { state: l, seed: d, onEvent: m, dispatch: y } = kr(), {
4197
- threadCheckpoints: I,
4198
+ threadCheckpoints: v,
4198
4199
  threadTimeline: f,
4199
- checkpointIndex: k,
4200
+ checkpointIndex: I,
4200
4201
  isLoadingThread: p,
4201
4202
  isLoadingCheckpoint: S,
4202
- isLoadingHistory: A,
4203
+ isLoadingHistory: x,
4203
4204
  threadStateError: E,
4204
- loadThread: v,
4205
- navigateToCheckpoint: w,
4206
- setCurrentCheckpointId: x,
4205
+ loadThread: k,
4206
+ navigateToCheckpoint: b,
4207
+ setCurrentCheckpointId: A,
4207
4208
  returnToLatest: g,
4208
- handleValuesEvent: b,
4209
+ handleValuesEvent: w,
4209
4210
  markSkipNextLoad: P,
4210
4211
  markStreamPendingThread: j,
4211
4212
  resetHistoryState: M
@@ -4231,23 +4232,23 @@ function Ur({
4231
4232
  C.current = T;
4232
4233
  },
4233
4234
  []
4234
- ), N = Y(() => ({ assemblingMessageId: l.assemblingId ?? null }), [l.assemblingId]), V = _(
4235
+ ), N = Y(() => ({ assemblingMessageId: l.assemblingId ?? null }), [l.assemblingId]), K = _(
4235
4236
  (T, J) => {
4236
- const K = Ut(T, "user");
4237
+ const V = Ut(T, "user");
4237
4238
  return y({
4238
4239
  type: "user_message",
4239
4240
  payload: {
4240
- message: K,
4241
+ message: V,
4241
4242
  editingMessageId: J == null ? void 0 : J.editingMessageId
4242
4243
  }
4243
- }), K;
4244
+ }), V;
4244
4245
  },
4245
4246
  [y]
4246
4247
  ), z = _(async () => {
4247
4248
  O.current ? await O.current() : (d([], {}), M());
4248
- }, [d, M]), L = _(async (T, J, K) => {
4249
- await v(T, J, { clearProgress: !1 });
4250
- }, [v]), H = Y(() => Bn(l.messages), [l.messages]), h = Y(
4249
+ }, [d, M]), L = _(async (T, J, V) => {
4250
+ await k(T, J, { clearProgress: !1 });
4251
+ }, [k]), H = Y(() => Bn(l.messages), [l.messages]), h = Y(
4251
4252
  () => ({
4252
4253
  status: l.status,
4253
4254
  threadId: c,
@@ -4258,14 +4259,14 @@ function Ur({
4258
4259
  id: l.lastCheckpointId ?? null,
4259
4260
  namespace: l.lastCheckpointNs ?? null
4260
4261
  },
4261
- checkpoints: I,
4262
- checkpointIndex: k,
4262
+ checkpoints: v,
4263
+ checkpointIndex: I,
4263
4264
  timelineCheckpoints: f,
4264
4265
  metadata: N,
4265
4266
  values: l.values ?? {},
4266
4267
  isLoading: p,
4267
4268
  isLoadingCheckpoint: S,
4268
- isLoadingHistory: A,
4269
+ isLoadingHistory: x,
4269
4270
  error: E,
4270
4271
  loadOlder: async () => {
4271
4272
  },
@@ -4279,20 +4280,20 @@ function Ur({
4279
4280
  });
4280
4281
  },
4281
4282
  clearState: z,
4282
- navigateToCheckpoint: w,
4283
- setCurrentCheckpointId: x,
4283
+ navigateToCheckpoint: b,
4284
+ setCurrentCheckpointId: A,
4284
4285
  returnToLatest: g,
4285
4286
  loadThread: L,
4286
4287
  clearThread: z,
4287
- respondToInterrupt: async (T, J, K) => {
4288
- C.current && await C.current(T, J, K);
4288
+ respondToInterrupt: async (T, J, V) => {
4289
+ C.current && await C.current(T, J, V);
4289
4290
  },
4290
- messagePreviews: k.messagePreviews,
4291
- handleValuesEvent: b,
4291
+ messagePreviews: I.messagePreviews,
4292
+ handleValuesEvent: w,
4292
4293
  markSkipNextLoad: P,
4293
4294
  markStreamPendingThread: j,
4294
4295
  resetHistoryState: M,
4295
- pushUser: V,
4296
+ pushUser: K,
4296
4297
  onEvent: m,
4297
4298
  artifacts: H
4298
4299
  }),
@@ -4304,24 +4305,24 @@ function Ur({
4304
4305
  l.lastCheckpointId,
4305
4306
  l.lastCheckpointNs,
4306
4307
  l.values,
4307
- I,
4308
+ v,
4308
4309
  f,
4309
- k,
4310
+ I,
4310
4311
  N,
4311
4312
  p,
4312
4313
  S,
4313
- A,
4314
+ x,
4314
4315
  E,
4315
4316
  d,
4316
4317
  z,
4317
- w,
4318
- x,
4318
+ b,
4319
+ A,
4319
4320
  g,
4320
4321
  L,
4321
- b,
4322
+ w,
4322
4323
  P,
4323
4324
  j,
4324
- V,
4325
+ K,
4325
4326
  m,
4326
4327
  H
4327
4328
  ]
@@ -4332,7 +4333,7 @@ function Ur({
4332
4333
  }),
4333
4334
  [F, B]
4334
4335
  );
4335
- return /* @__PURE__ */ ie(Vt.Provider, { value: U, children: /* @__PURE__ */ ie(Dt.Provider, { value: h, children: e }) });
4336
+ return /* @__PURE__ */ ie(Kt.Provider, { value: U, children: /* @__PURE__ */ ie(Dt.Provider, { value: h, children: e }) });
4336
4337
  }
4337
4338
  const qt = Ce(null), jr = Ce(!1);
4338
4339
  function Br({
@@ -4347,25 +4348,25 @@ function Br({
4347
4348
  onFinish: u,
4348
4349
  onStreamingChange: c
4349
4350
  }) {
4350
- const { chatApi: l, baseUrl: d } = Me(), m = d, y = fe(t), I = fe(n), f = fe(r), k = fe(o), p = fe(s), S = fe(a), A = fe(i), E = fe(u), v = fe(c), w = Y(
4351
+ const { chatApi: l, baseUrl: d } = Me(), m = d, y = fe(t), v = fe(n), f = fe(r), I = fe(o), p = fe(s), S = fe(a), x = fe(i), E = fe(u), k = fe(c), b = Y(
4351
4352
  () => ({
4352
4353
  onError: y,
4353
- onAuthError: I,
4354
+ onAuthError: v,
4354
4355
  onConnectionError: f,
4355
- onMetadataEvent: A,
4356
+ onMetadataEvent: x,
4356
4357
  onCustomEvent: S,
4357
4358
  onUpdateEvent: p,
4358
- onToolEnd: k,
4359
+ onToolEnd: I,
4359
4360
  onFinish: E
4360
4361
  }),
4361
4362
  [
4362
4363
  y,
4363
- I,
4364
+ v,
4364
4365
  f,
4365
- A,
4366
+ x,
4366
4367
  S,
4367
4368
  p,
4368
- k,
4369
+ I,
4369
4370
  E
4370
4371
  ]
4371
4372
  );
@@ -4374,8 +4375,8 @@ function Br({
4374
4375
  {
4375
4376
  api: l,
4376
4377
  streamBaseUrl: m,
4377
- handlers: w,
4378
- onStreamingChange: v,
4378
+ handlers: b,
4379
+ onStreamingChange: k,
4379
4380
  children: e
4380
4381
  }
4381
4382
  ) });
@@ -4393,17 +4394,17 @@ function Fr({
4393
4394
  timelineCheckpoints: d,
4394
4395
  handleValuesEvent: m,
4395
4396
  markSkipNextLoad: y,
4396
- markStreamPendingThread: I,
4397
+ markStreamPendingThread: v,
4397
4398
  resetHistoryState: f,
4398
- pushUser: k,
4399
+ pushUser: I,
4399
4400
  onEvent: p,
4400
4401
  messages: S
4401
- } = Kt(), { registerClearThread: A, registerRespondToInterrupt: E } = Lr(), v = _(
4402
+ } = Vt(), { registerClearThread: x, registerRespondToInterrupt: E } = Lr(), k = _(
4402
4403
  (h) => {
4403
- i(h), I(h.threadId), a.current !== h.threadId && ((h.created ?? !a.current) && y(h.threadId), s(h.threadId));
4404
+ i(h), v(h.threadId), a.current !== h.threadId && ((h.created ?? !a.current) && y(h.threadId), s(h.threadId));
4404
4405
  },
4405
- [i, y, I, s, a]
4406
- ), w = pr({
4406
+ [i, y, v, s, a]
4407
+ ), b = pr({
4407
4408
  baseUrl: n,
4408
4409
  onEvent: p,
4409
4410
  onError: (h) => {
@@ -4413,7 +4414,7 @@ function Fr({
4413
4414
  onAuthError: r.onAuthError,
4414
4415
  onConnectionError: r.onConnectionError,
4415
4416
  onFinish: r.onFinish,
4416
- onThreadInfo: v,
4417
+ onThreadInfo: k,
4417
4418
  onMetadataEvent: r.onMetadataEvent,
4418
4419
  onCustomEvent: r.onCustomEvent,
4419
4420
  onUpdateEvent: r.onUpdateEvent,
@@ -4421,17 +4422,17 @@ function Fr({
4421
4422
  handleValuesEvent: m
4422
4423
  });
4423
4424
  X(() => {
4424
- o == null || o(w.isStreaming);
4425
- }, [w.isStreaming, o]);
4426
- const { stream: x, stop: g, clear: b, isStreaming: P, error: j, connected: M, streamedMessages: O, activeMessageId: F } = w;
4425
+ o == null || o(b.isStreaming);
4426
+ }, [b.isStreaming, o]);
4427
+ const { stream: A, stop: g, clear: w, isStreaming: P, error: j, connected: M, streamedMessages: O, activeMessageId: F } = b;
4427
4428
  X(() => {
4428
- u !== void 0 && b();
4429
- }, [u, b]);
4429
+ u !== void 0 && w();
4430
+ }, [u, w]);
4430
4431
  const C = _(
4431
4432
  async (h, U) => {
4432
- await x(h, U);
4433
+ await A(h, U);
4433
4434
  },
4434
- [x]
4435
+ [A]
4435
4436
  ), B = W(l);
4436
4437
  X(() => {
4437
4438
  B.current = l;
@@ -4442,11 +4443,11 @@ function Fr({
4442
4443
  const J = a.current;
4443
4444
  if (!J)
4444
4445
  throw new Error("No active thread to handle interrupt");
4445
- const K = h ? U ?? !0 : !1, q = B.current, ee = (T == null ? void 0 : T.checkpointId) ?? q.id ?? void 0, re = (T == null ? void 0 : T.checkpointNs) ?? q.namespace ?? void 0, ue = {
4446
+ const V = h ? U ?? !0 : !1, q = B.current, ee = (T == null ? void 0 : T.checkpointId) ?? q.id ?? void 0, re = (T == null ? void 0 : T.checkpointNs) ?? q.namespace ?? void 0, ue = {
4446
4447
  threadId: J,
4447
4448
  checkpointId: ee,
4448
4449
  checkpointNs: re,
4449
- command: { kind: "resume", value: K },
4450
+ command: { kind: "resume", value: V },
4450
4451
  payload: {
4451
4452
  ...(T == null ? void 0 : T.payload) ?? {},
4452
4453
  creativityLevel: ((G = T == null ? void 0 : T.payload) == null ? void 0 : G.creativityLevel) ?? "medium"
@@ -4460,27 +4461,27 @@ function Fr({
4460
4461
  X(() => {
4461
4462
  E(N);
4462
4463
  }, [N, E]);
4463
- const V = _(async () => {
4464
- g(), b(), f(), s(null);
4465
- }, [b, f, s, g]);
4464
+ const K = _(async () => {
4465
+ g(), w(), f(), s(null);
4466
+ }, [w, f, s, g]);
4466
4467
  X(() => {
4467
- A(V);
4468
- }, [V, A]);
4468
+ x(K);
4469
+ }, [K, x]);
4469
4470
  const z = _(
4470
4471
  async (h, U) => {
4471
4472
  P && g();
4472
4473
  let T = a.current;
4473
- const J = (h == null ? void 0 : h.text) ?? "", K = (h == null ? void 0 : h.attachments) ?? [], q = (J == null ? void 0 : J.trim()) ?? "", ee = { ...(h == null ? void 0 : h.payload) ?? {} }, re = Array.isArray(ee.messages) ? ee.messages : void 0;
4474
+ const J = (h == null ? void 0 : h.text) ?? "", V = (h == null ? void 0 : h.attachments) ?? [], q = (J == null ? void 0 : J.trim()) ?? "", ee = { ...(h == null ? void 0 : h.payload) ?? {} }, re = Array.isArray(ee.messages) ? ee.messages : void 0;
4474
4475
  re && delete ee.messages;
4475
4476
  const ue = !!(re && re.length), G = !!(h.contentParts && h.contentParts.length > 0);
4476
- if (!T && !q && K.length === 0 && !ue && !G) return;
4477
+ if (!T && !q && V.length === 0 && !ue && !G) return;
4477
4478
  if (!T) {
4478
4479
  const ye = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), he = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4479
4480
  T = `${ye}${he}`, y(T), s(T);
4480
4481
  }
4481
4482
  let te = null;
4482
4483
  h.contentParts && h.contentParts.length > 0 && (te = h.contentParts);
4483
- const { contentParts: ke, filesInfo: Q } = te ? { contentParts: te, filesInfo: [] } : await or(K), Z = [...ke];
4484
+ const { contentParts: ke, filesInfo: Q } = te ? { contentParts: te, filesInfo: [] } : await or(V), Z = [...ke];
4484
4485
  q && Z.push({ type: "text", text: J });
4485
4486
  const ge = h == null ? void 0 : h.originalMessageId, je = !!(h != null && h.edit && ge), Be = !ue && Z.length > 0;
4486
4487
  let me = null;
@@ -4491,7 +4492,7 @@ function Fr({
4491
4492
  role: "user",
4492
4493
  content: Z,
4493
4494
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4494
- }, "user"), je ? k(me, { editingMessageId: ge }) : k(me);
4495
+ }, "user"), je ? I(me, { editingMessageId: ge }) : I(me);
4495
4496
  }
4496
4497
  const Ie = ue ? re : me ? [me] : [], oe = {
4497
4498
  ...ee,
@@ -4514,7 +4515,7 @@ function Fr({
4514
4515
  };
4515
4516
  return C(Ae, U);
4516
4517
  },
4517
- [l, a, P, y, k, C, g, d]
4518
+ [l, a, P, y, I, C, g, d]
4518
4519
  ), L = Y(() => S, [S]), H = Y(
4519
4520
  () => ({
4520
4521
  isStreaming: P,
@@ -4566,14 +4567,14 @@ function Dr(e) {
4566
4567
  const t = W(e), n = W(e);
4567
4568
  return $r(t.current, e) || (t.current = e, n.current = e), n.current;
4568
4569
  }
4569
- function Vr(e) {
4570
+ function Kr(e) {
4570
4571
  const t = e.artifact && typeof e.artifact == "object" ? e.artifact : null, n = !t && e.content && typeof e.content == "object" ? e.content : null, r = t ?? n, o = (r == null ? void 0 : r.task_id) ?? (r == null ? void 0 : r.taskId) ?? null;
4571
4572
  return typeof o == "string" ? o : null;
4572
4573
  }
4573
4574
  function fo(e) {
4574
4575
  const { setCurrentTaskId: t, getCurrentTaskId: n, onToolEnd: r } = e;
4575
4576
  return (o) => {
4576
- const s = Vr(o), a = (n == null ? void 0 : n()) ?? null;
4577
+ const s = Kr(o), a = (n == null ? void 0 : n()) ?? null;
4577
4578
  s && s !== a && t(s), r == null || r(o);
4578
4579
  };
4579
4580
  }
@@ -4592,27 +4593,27 @@ function po({
4592
4593
  onUpdateEvent: d,
4593
4594
  onCustomEvent: m,
4594
4595
  onMetadataEvent: y,
4595
- onFinish: I
4596
+ onFinish: v
4596
4597
  }) {
4597
- const f = Dr(t), [k, p] = $(!1), S = pe(i), A = pe(u), E = pe(a), v = pe(c), w = pe(l), x = pe(d), g = pe(m), b = pe(y), P = pe(I), j = Y(
4598
+ const f = Dr(t), [I, p] = $(!1), S = pe(i), x = pe(u), E = pe(a), k = pe(c), b = pe(l), A = pe(d), g = pe(m), w = pe(y), P = pe(v), j = Y(
4598
4599
  () => ({
4599
4600
  onError: S,
4600
- onAuthError: A,
4601
+ onAuthError: x,
4601
4602
  onConnectionError: E,
4602
- onToolEnd: w,
4603
- onUpdateEvent: x,
4603
+ onToolEnd: b,
4604
+ onUpdateEvent: A,
4604
4605
  onCustomEvent: g,
4605
- onMetadataEvent: b,
4606
+ onMetadataEvent: w,
4606
4607
  onFinish: P
4607
4608
  }),
4608
4609
  [
4609
4610
  S,
4610
- A,
4611
- E,
4612
- w,
4613
4611
  x,
4614
- g,
4612
+ E,
4615
4613
  b,
4614
+ A,
4615
+ g,
4616
+ w,
4616
4617
  P
4617
4618
  ]
4618
4619
  );
@@ -4621,7 +4622,7 @@ function po({
4621
4622
  {
4622
4623
  initialThreadId: n,
4623
4624
  onError: S,
4624
- onThreadChange: v,
4625
+ onThreadChange: k,
4625
4626
  children: /* @__PURE__ */ ie(
4626
4627
  Ur,
4627
4628
  {
@@ -4630,7 +4631,7 @@ function po({
4630
4631
  initialCheckpointNs: o,
4631
4632
  autoLoadInitial: s,
4632
4633
  onError: S,
4633
- isStreaming: k,
4634
+ isStreaming: I,
4634
4635
  children: /* @__PURE__ */ ie(
4635
4636
  Br,
4636
4637
  {
@@ -4652,7 +4653,7 @@ function pe(e) {
4652
4653
  return r(...n);
4653
4654
  }, []);
4654
4655
  }
4655
- const Kr = 1, qr = 1e6;
4656
+ const Vr = 1, qr = 1e6;
4656
4657
  let We = 0;
4657
4658
  function Hr() {
4658
4659
  return We = (We + 1) % Number.MAX_SAFE_INTEGER, We.toString();
@@ -4672,7 +4673,7 @@ const Je = /* @__PURE__ */ new Map(), wt = (e) => {
4672
4673
  case "ADD_TOAST":
4673
4674
  return {
4674
4675
  ...e,
4675
- toasts: [t.toast, ...e.toasts].slice(0, Kr)
4676
+ toasts: [t.toast, ...e.toasts].slice(0, Vr)
4676
4677
  };
4677
4678
  case "UPDATE_TOAST":
4678
4679
  return {
@@ -4746,63 +4747,63 @@ function Jr() {
4746
4747
  function go(e) {
4747
4748
  const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = Me(), { toast: o } = Jr(), [s, a] = $({}), [i, u] = $(null), [c, l] = $(!1), d = _(() => {
4748
4749
  l(!1), u(null);
4749
- }, []), m = _((I) => {
4750
- u(I), l(!0);
4750
+ }, []), m = _((v) => {
4751
+ u(v), l(!0);
4751
4752
  }, []), y = _(
4752
- async (I, f, k) => {
4753
+ async (v, f, I) => {
4753
4754
  var p, S;
4754
4755
  if (!t) {
4755
- I.preventDefault();
4756
+ v.preventDefault();
4756
4757
  return;
4757
4758
  }
4758
- if (s[k]) {
4759
- I.preventDefault();
4759
+ if (s[I]) {
4760
+ v.preventDefault();
4760
4761
  return;
4761
4762
  }
4762
4763
  try {
4763
- const A = String(f.url ?? ""), E = A.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
4764
+ const x = String(f.url ?? ""), E = x.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
4764
4765
  if (E) {
4765
- I.preventDefault();
4766
- const v = E[1], w = f.name || `file_${v}`, x = f.mimeType || "application/octet-stream";
4767
- m({ id: v, name: w, mimeType: x });
4766
+ v.preventDefault();
4767
+ const k = E[1], b = f.name || `file_${k}`, A = f.mimeType || "application/octet-stream";
4768
+ m({ id: k, name: b, mimeType: A });
4768
4769
  return;
4769
4770
  }
4770
- if (A.startsWith("data:")) {
4771
- I.preventDefault(), a((w) => ({ ...w, [k]: !0 }));
4772
- const v = o({ title: "Fetching file...", description: "", open: !0 });
4771
+ if (x.startsWith("data:")) {
4772
+ v.preventDefault(), a((b) => ({ ...b, [I]: !0 }));
4773
+ const k = o({ title: "Fetching file...", description: "", open: !0 });
4773
4774
  try {
4774
- const w = await r.listFiles(n ?? void 0);
4775
- if (!w || !Array.isArray(w))
4775
+ const b = await r.listFiles(n ?? void 0);
4776
+ if (!b || !Array.isArray(b))
4776
4777
  throw new Error("Invalid file list response");
4777
- const x = w.find((g) => !g || typeof g != "object" || !((g.filename ?? "") === (f.name ?? "")) ? !1 : typeof f.size == "number" && typeof g.size == "number" ? g.size === f.size : !0);
4778
- if (!(x != null && x.id))
4778
+ const A = b.find((g) => !g || typeof g != "object" || !((g.filename ?? "") === (f.name ?? "")) ? !1 : typeof f.size == "number" && typeof g.size == "number" ? g.size === f.size : !0);
4779
+ if (!(A != null && A.id))
4779
4780
  throw new Error(`File "${f.name}" is not yet available on the server`);
4780
- if (!x.id || !x.filename)
4781
+ if (!A.id || !A.filename)
4781
4782
  throw new Error("Invalid file data received from server");
4782
4783
  m({
4783
- id: x.id,
4784
- name: f.name || x.filename || `file_${x.id}`,
4785
- mimeType: f.mimeType || x.mime_type || "application/octet-stream"
4786
- }), (p = v.update) == null || p.call(v, {
4787
- id: v.id,
4784
+ id: A.id,
4785
+ name: f.name || A.filename || `file_${A.id}`,
4786
+ mimeType: f.mimeType || A.mime_type || "application/octet-stream"
4787
+ }), (p = k.update) == null || p.call(k, {
4788
+ id: k.id,
4788
4789
  title: "Success",
4789
4790
  description: `Opened ${f.name}`,
4790
4791
  open: !0
4791
4792
  });
4792
- } catch (w) {
4793
- console.error("Failed to fetch server file:", w);
4794
- const x = w instanceof Error ? w.message : "Unknown error occurred";
4795
- (S = v.update) == null || S.call(v, { id: v.id, title: "Failed", description: x }), o({
4793
+ } catch (b) {
4794
+ console.error("Failed to fetch server file:", b);
4795
+ const A = b instanceof Error ? b.message : "Unknown error occurred";
4796
+ (S = k.update) == null || S.call(k, { id: k.id, title: "Failed", description: A }), o({
4796
4797
  title: "Failed to fetch file",
4797
- description: x,
4798
+ description: A,
4798
4799
  open: !0
4799
4800
  });
4800
4801
  } finally {
4801
- a((w) => ({ ...w, [k]: !1 }));
4802
+ a((b) => ({ ...b, [I]: !1 }));
4802
4803
  }
4803
4804
  }
4804
- } catch (A) {
4805
- console.error("File click error:", A), a((E) => ({ ...E, [k]: !1 }));
4805
+ } catch (x) {
4806
+ console.error("File click error:", x), a((E) => ({ ...E, [I]: !1 }));
4806
4807
  }
4807
4808
  },
4808
4809
  [t, s, o, n, m]
@@ -4889,7 +4890,7 @@ function yo(e) {
4889
4890
  }
4890
4891
  function Yr(e) {
4891
4892
  var M, O;
4892
- const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, n = typeof e == "object" ? e.lazy : !1, r = ot({ optional: !0 }), o = Kt({ optional: !0 }), s = Or(), { currentThreadId: a, setCurrentThreadId: i, actions: u } = r || {
4893
+ const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, n = typeof e == "object" ? e.lazy : !1, r = ot({ optional: !0 }), o = Vt({ optional: !0 }), s = Or(), { currentThreadId: a, setCurrentThreadId: i, actions: u } = r || {
4893
4894
  currentThreadId: null,
4894
4895
  setCurrentThreadId: () => {
4895
4896
  },
@@ -4898,9 +4899,9 @@ function Yr(e) {
4898
4899
  d(F);
4899
4900
  }, []), {
4900
4901
  isLoadingThread: y,
4901
- threadStateError: I,
4902
+ threadStateError: v,
4902
4903
  threadCheckpoints: f,
4903
- isLoadingHistory: k,
4904
+ isLoadingHistory: I,
4904
4905
  loadThread: p
4905
4906
  } = $t({
4906
4907
  api: Me().chatApi,
@@ -4918,17 +4919,17 @@ function Yr(e) {
4918
4919
  const S = Y(() => {
4919
4920
  var F;
4920
4921
  return ((F = f[0]) == null ? void 0 : F.values) || {};
4921
- }, [f]), A = Y(() => ({ timeline: [], messagePreviews: {} }), []), E = t || a, v = c ? y ? "loading" : "idle" : (o == null ? void 0 : o.status) || "idle", w = c ? l : (s == null ? void 0 : s.messages) || [], x = c ? y : (o == null ? void 0 : o.isLoading) || !1, g = c ? k : (o == null ? void 0 : o.isLoadingHistory) || !1, b = c ? S : (o == null ? void 0 : o.values) || {}, P = c ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, j = c ? I : (s == null ? void 0 : s.error) || (o == null ? void 0 : o.error) || null;
4922
+ }, [f]), x = Y(() => ({ timeline: [], messagePreviews: {} }), []), E = t || a, k = c ? y ? "loading" : "idle" : (o == null ? void 0 : o.status) || "idle", b = c ? l : (s == null ? void 0 : s.messages) || [], A = c ? y : (o == null ? void 0 : o.isLoading) || !1, g = c ? I : (o == null ? void 0 : o.isLoadingHistory) || !1, w = c ? S : (o == null ? void 0 : o.values) || {}, P = c ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, j = c ? v : (s == null ? void 0 : s.error) || (o == null ? void 0 : o.error) || null;
4922
4923
  return {
4923
4924
  // UNIFIED: Single thread ID concept
4924
4925
  threadId: E,
4925
- status: v,
4926
- messages: w,
4927
- isLoading: x,
4926
+ status: k,
4927
+ messages: b,
4928
+ isLoading: A,
4928
4929
  isHistoryLoading: g,
4929
4930
  error: j,
4930
4931
  // Values & Metadata
4931
- values: b,
4932
+ values: w,
4932
4933
  taskMessagesByScope: P,
4933
4934
  metadata: c ? {} : o == null ? void 0 : o.metadata,
4934
4935
  // Actions & State relating to Global/Active Thread only
@@ -4940,7 +4941,7 @@ function Yr(e) {
4940
4941
  }),
4941
4942
  checkpoint: c ? f[0] ? { id: f[0].checkpointId, namespace: f[0].checkpointNs } : null : (o == null ? void 0 : o.checkpoint) || null,
4942
4943
  checkpoints: c ? f : (o == null ? void 0 : o.checkpoints) || [],
4943
- checkpointIndex: c ? A : (o == null ? void 0 : o.checkpointIndex) || { timeline: [], messagePreviews: {} },
4944
+ checkpointIndex: c ? x : (o == null ? void 0 : o.checkpointIndex) || { timeline: [], messagePreviews: {} },
4944
4945
  interrupt: c ? null : (o == null ? void 0 : o.interrupt) || null,
4945
4946
  respondToInterrupt: c ? async () => {
4946
4947
  } : (o == null ? void 0 : o.respondToInterrupt) || (async () => {
@@ -4991,7 +4992,7 @@ function ho({
4991
4992
  threadId: m,
4992
4993
  clearComposerOnSend: y = !0
4993
4994
  }) {
4994
- const { messages: I } = Yr(), [f, k] = $(null), [p, S] = $(""), [A, E] = $(null), [v, w] = $(null), [x, g] = $(!1), [b, P] = $(""), j = W(b), M = W(null);
4995
+ const { messages: v } = Yr(), [f, I] = $(null), [p, S] = $(""), [x, E] = $(null), [k, b] = $(null), [A, g] = $(!1), [w, P] = $(""), j = W(w), M = W(null);
4995
4996
  X(() => {
4996
4997
  if (!f)
4997
4998
  if (m) {
@@ -5004,8 +5005,8 @@ function ho({
5004
5005
  P(h), !f && m && localStorage.setItem(Ge(m), h);
5005
5006
  }, [m, f]);
5006
5007
  X(() => {
5007
- j.current = b;
5008
- }, [b]), X(() => {
5008
+ j.current = w;
5009
+ }, [w]), X(() => {
5009
5010
  if (!f) {
5010
5011
  M.current = null;
5011
5012
  return;
@@ -5018,8 +5019,8 @@ function ho({
5018
5019
  },
5019
5020
  [O]
5020
5021
  ), C = async (h, U) => {
5021
- const T = Array.isArray(U) ? { files: U } : U ?? {}, J = T.files ?? [], K = T.contentParts ?? [], q = h.trim();
5022
- if (!(!q && J.length === 0 && K.length === 0))
5022
+ const T = Array.isArray(U) ? { files: U } : U ?? {}, J = T.files ?? [], V = T.contentParts ?? [], q = h.trim();
5023
+ if (!(!q && J.length === 0 && V.length === 0))
5023
5024
  try {
5024
5025
  const ee = J.map(async (Q) => {
5025
5026
  try {
@@ -5040,7 +5041,7 @@ function ho({
5040
5041
  name: Q.filename,
5041
5042
  size: Q.size
5042
5043
  };
5043
- }), G = [...K, ...ue], te = f ? (A == null ? void 0 : A.checkpointId) ?? n ?? void 0 : n ?? void 0, ke = f ? (A == null ? void 0 : A.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5044
+ }), G = [...V, ...ue], te = f ? (x == null ? void 0 : x.checkpointId) ?? n ?? void 0 : n ?? void 0, ke = f ? (x == null ? void 0 : x.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5044
5045
  await e(
5045
5046
  {
5046
5047
  text: q || "",
@@ -5055,10 +5056,10 @@ function ho({
5055
5056
  config: t.config
5056
5057
  },
5057
5058
  d ? { onEvent: d } : void 0
5058
- ), o == null || o(q), c(!0), y && (m && localStorage.removeItem(Ge(m)), O("")), w(null), k(null), S(""), E(null);
5059
+ ), o == null || o(q), c(!0), y && (m && localStorage.removeItem(Ge(m)), O("")), b(null), I(null), S(""), E(null);
5059
5060
  } catch (ee) {
5060
5061
  const re = (ee == null ? void 0 : ee.message) || "Failed to send message";
5061
- w(re), a == null || a(re), c(!1);
5062
+ b(re), a == null || a(re), c(!1);
5062
5063
  }
5063
5064
  }, B = (h, U) => {
5064
5065
  U || C(h, { files: [] });
@@ -5077,16 +5078,16 @@ function ho({
5077
5078
  ), s == null || s({ file: h });
5078
5079
  },
5079
5080
  [n, r, t, s, e]
5080
- ), V = _(
5081
+ ), K = _(
5081
5082
  (h, U, T) => {
5082
- i && (M.current = b, k(h), S(U), E({
5083
+ i && (M.current = w, I(h), S(U), E({
5083
5084
  checkpointId: (T == null ? void 0 : T.checkpointId) ?? null,
5084
5085
  checkpointNs: (T == null ? void 0 : T.checkpointNs) ?? null
5085
- }), w(null));
5086
+ }), b(null));
5086
5087
  },
5087
- [b, i]
5088
+ [w, i]
5088
5089
  ), z = _(() => {
5089
- k(null), S(""), E(null), w(null);
5090
+ I(null), S(""), E(null), b(null);
5090
5091
  const h = M.current;
5091
5092
  h !== null && P(h), M.current = null;
5092
5093
  }, []), L = _((h) => {
@@ -5097,16 +5098,16 @@ function ho({
5097
5098
  break;
5098
5099
  }
5099
5100
  if (!U) return;
5100
- const T = Array.isArray(U.content) ? U.content : [], K = T.filter((q) => (q == null ? void 0 : q.type) === "text").map((q) => q.text).join("") || (() => {
5101
+ const T = Array.isArray(U.content) ? U.content : [], V = T.filter((q) => (q == null ? void 0 : q.type) === "text").map((q) => q.text).join("") || (() => {
5101
5102
  try {
5102
5103
  return JSON.stringify(T, null, 2);
5103
5104
  } catch {
5104
5105
  return String(T);
5105
5106
  }
5106
5107
  })();
5107
- K && e(
5108
+ V && e(
5108
5109
  {
5109
- text: K,
5110
+ text: V,
5110
5111
  payload: t.payload,
5111
5112
  checkpointId: n ?? void 0,
5112
5113
  checkpointNs: r ?? void 0,
@@ -5120,19 +5121,19 @@ function ho({
5120
5121
  return {
5121
5122
  editingMessageId: f,
5122
5123
  editingInitialValue: p,
5123
- inputError: v,
5124
- setInputError: w,
5125
- dismissError: x,
5124
+ inputError: k,
5125
+ setInputError: b,
5126
+ dismissError: A,
5126
5127
  setDismissError: g,
5127
- composerValue: b,
5128
+ composerValue: w,
5128
5129
  handleComposerChange: F,
5129
5130
  handleSendMessage: C,
5130
5131
  handleQuickPrompt: B,
5131
5132
  handleExcelUpload: N,
5132
- startEditing: V,
5133
+ startEditing: K,
5133
5134
  cancelEditing: z,
5134
5135
  handleRegenerateCb: L,
5135
- displayMessages: I
5136
+ displayMessages: v
5136
5137
  };
5137
5138
  }
5138
5139
  function bo(e) {
@@ -5175,7 +5176,7 @@ export {
5175
5176
  ro as cn,
5176
5177
  sr as collectText,
5177
5178
  fo as createTaskSyncToolEndHandler,
5178
- Vr as extractTaskIdFromToolEnd,
5179
+ Kr as extractTaskIdFromToolEnd,
5179
5180
  ar as extractToolMeta,
5180
5181
  oo as formatToolOutput,
5181
5182
  co as getAgentNameFromMessage,
@@ -5193,7 +5194,7 @@ export {
5193
5194
  tt as parseJsonSafe,
5194
5195
  Et as pretty,
5195
5196
  Mr as refreshHistoryFileUrls,
5196
- Ve as sanitizeForDisplay,
5197
+ Ke as sanitizeForDisplay,
5197
5198
  ve as setChatToken,
5198
5199
  Fn as stringifyTool,
5199
5200
  Me as useApi,
@@ -5205,7 +5206,7 @@ export {
5205
5206
  pr as useStream,
5206
5207
  wo as useStreamingMarkdownBuffer,
5207
5208
  $t as useThreadHistoryState,
5208
- Kt as useThreadState,
5209
+ Vt as useThreadState,
5209
5210
  Lr as useThreadStateUpdater,
5210
5211
  ot as useThreads,
5211
5212
  gr as useThreadsState,