@teodorruskvi/chat-core 0.1.48 → 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
  }
@@ -3609,7 +3609,7 @@ function pt(e, t) {
3609
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;
3610
3610
  }
3611
3611
  function vr(e, t, n) {
3612
- var m, y, I, f, k;
3612
+ var m, y, v, f, I;
3613
3613
  const r = t.messages;
3614
3614
  if (!r.length)
3615
3615
  return console.warn("[messagesReducer] Dropping messages/partial event without messages[]", t), e;
@@ -3648,8 +3648,8 @@ function vr(e, t, n) {
3648
3648
  ...e.messagesStreamMeta ?? {},
3649
3649
  [s]: {
3650
3650
  ...((m = e.messagesStreamMeta) == null ? void 0 : m[s]) ?? {},
3651
- lastSeq: t.seq ?? ((I = (y = e.messagesStreamMeta) == null ? void 0 : y[s]) == null ? void 0 : I.lastSeq) ?? null,
3652
- lastText: u || (((k = (f = e.messagesStreamMeta) == null ? void 0 : f[s]) == null ? void 0 : k.lastText) ?? "")
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) ?? "")
3653
3653
  }
3654
3654
  }
3655
3655
  };
@@ -3819,8 +3819,8 @@ async function Mr(e, t) {
3819
3819
  if (Array.isArray(m))
3820
3820
  for (const y of m) {
3821
3821
  if (!y || typeof y != "object" || y.type !== "image_url" && y.type !== "file") continue;
3822
- const I = y.fileId || y.file_id;
3823
- typeof I == "string" && I.trim() && o.add(I);
3822
+ const v = y.fileId || y.file_id;
3823
+ typeof v == "string" && v.trim() && o.add(v);
3824
3824
  }
3825
3825
  }
3826
3826
  }
@@ -3844,10 +3844,10 @@ async function Mr(e, t) {
3844
3844
  if (Array.isArray(m))
3845
3845
  for (const y of m) {
3846
3846
  if (!y || typeof y != "object" || y.type !== "image_url" && y.type !== "file") continue;
3847
- const I = y.fileId || y.file_id;
3848
- if (!I) continue;
3849
- const f = a.get(I), k = (f == null ? void 0 : f.contentUrl) || (f == null ? void 0 : f.content_url);
3850
- k && (y.type === "image_url" ? (y.imageUrl = y.imageUrl || {}, y.imageUrl.url = k) : y.type === "file" && (y.url = k, !y.name && (f != null && f.filename || f != null && f.name) && (y.name = (f == null ? void 0 : f.filename) || (f == null ? void 0 : f.name))));
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))));
3851
3851
  }
3852
3852
  }
3853
3853
  }
@@ -3863,21 +3863,21 @@ function mt(e) {
3863
3863
  };
3864
3864
  }
3865
3865
  function Cr(e, t) {
3866
- var v, w;
3866
+ var k, b;
3867
3867
  if (!e) return null;
3868
- const n = ((v = e.values) == null ? void 0 : v.activeAgent) ?? null, r = (w = e.values) == null ? void 0 : w.messages, s = (Array.isArray(r) ? r : []).map((x) => Er(x, n)).filter((x) => !!x), a = Re(e.metadata) ?? {}, i = gt(e.config), u = Re(e.parentConfig), c = gt(u), l = Fe(i, ["checkpointId"]), d = Fe(i, ["checkpointNs"]), m = Fe(c, ["checkpointId"]), y = Re(e.config), I = Array.isArray(e.tasks) ? e.tasks.map((x) => ({ ...x })) : e.tasks ?? null, f = Array.isArray(e.next) ? [...e.next] : e.next ?? null, k = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), p = {
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 = {
3869
3869
  ...a,
3870
3870
  step: Sr(a, ["step"]) ?? 0,
3871
3871
  source: Fe(a, ["source"]) ?? null
3872
- }, S = s.map((x) => ({
3873
- ...x,
3874
- checkpointId: x.checkpointId ?? l ?? null,
3875
- checkpointNs: x.checkpointNs ?? d ?? null
3876
- })), A = e.values, E = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(A == null ? void 0 : A.interrupts) ? A.interrupts : [];
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 : [];
3877
3877
  return {
3878
3878
  checkpointId: l ?? null,
3879
3879
  checkpointNs: d ?? null,
3880
- createdAt: k,
3880
+ createdAt: I,
3881
3881
  parentId: m ?? null,
3882
3882
  messages: S,
3883
3883
  interrupt: Pr(
@@ -3889,7 +3889,7 @@ function Cr(e, t) {
3889
3889
  config: y ?? null,
3890
3890
  parentConfig: u ?? null,
3891
3891
  next: f,
3892
- tasks: I,
3892
+ tasks: v,
3893
3893
  values: e.values ?? {}
3894
3894
  };
3895
3895
  }
@@ -3934,33 +3934,33 @@ function Nr(e) {
3934
3934
  function zr(e) {
3935
3935
  const t = /* @__PURE__ */ new Map(), n = [], r = /* @__PURE__ */ new Map(), o = [];
3936
3936
  for (let c = 0; c < e.length; c++) {
3937
- const l = e[c], d = l.checkpointId, m = d ?? `cp-${c}`, y = l.metadata ?? {}, I = typeof y.step == "number" ? y.step : null, f = typeof y.source == "string" ? y.source : null;
3938
- let k = null, p = null;
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;
3939
3939
  const S = Array.isArray(l.messages) ? l.messages : [];
3940
- for (const w of S)
3941
- w.role === "user" && (p || (p = w), w.id && (k = w.id));
3942
- const A = l.next && l.next.length > 0 ? String(l.next[0]) : null, E = l.parentConfig ?? null, v = {
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 = {
3943
3943
  id: m,
3944
- step: I,
3944
+ step: v,
3945
3945
  source: f,
3946
3946
  createdAt: l.createdAt ?? null,
3947
3947
  namespace: l.checkpointNs ?? null,
3948
3948
  parentId: l.parentId ?? null,
3949
- next: A,
3949
+ next: x,
3950
3950
  parentConfig: E,
3951
- userMessageId: k
3951
+ userMessageId: I
3952
3952
  };
3953
- if (o.push(v), d && t.set(d, v), d && p) {
3954
- const w = Nr(p);
3955
- 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);
3956
3956
  }
3957
3957
  n.push({
3958
3958
  id: m,
3959
- messageId: k,
3960
- step: I,
3959
+ messageId: I,
3960
+ step: v,
3961
3961
  source: f,
3962
3962
  createdAt: l.createdAt ?? null,
3963
- next: A,
3963
+ next: x,
3964
3964
  parentConfig: E
3965
3965
  });
3966
3966
  }
@@ -3998,8 +3998,8 @@ function zr(e) {
3998
3998
  for (const d of t.values())
3999
3999
  d.userMessageId === c && l.push(d);
4000
4000
  return l.length ? (l.sort((d, m) => {
4001
- const y = typeof d.attemptIndex == "number" ? d.attemptIndex : Number.MAX_SAFE_INTEGER, I = typeof m.attemptIndex == "number" ? m.attemptIndex : Number.MAX_SAFE_INTEGER;
4002
- return y - I;
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;
4003
4003
  }), l) : [];
4004
4004
  }
4005
4005
  };
@@ -4037,11 +4037,11 @@ function $t({
4037
4037
  const [u, c] = $(null), d = Y(
4038
4038
  () => mt(u),
4039
4039
  [u]
4040
- ).checkpoints, m = Rr(d), y = m.timeline, [I, f] = $(!1), [k, p] = $(!1), [S, A] = $(!1), [E, v] = $(null), w = W(o), x = W(null), g = W(null);
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);
4041
4041
  X(() => {
4042
- w.current = o;
4042
+ b.current = o;
4043
4043
  }, [o]);
4044
- const b = _(
4044
+ const w = _(
4045
4045
  async (C) => {
4046
4046
  const B = await e.getState({
4047
4047
  threadId: C.threadId,
@@ -4051,7 +4051,7 @@ function $t({
4051
4051
  version: "values@1",
4052
4052
  threadId: C.threadId,
4053
4053
  checkpoints: [B]
4054
- }, V = t ? await Mr(N, t) : N, { latest: z } = mt(V);
4054
+ }, K = t ? await Mr(N, t) : N, { latest: z } = mt(K);
4055
4055
  return z;
4056
4056
  },
4057
4057
  [e, t]
@@ -4060,16 +4060,16 @@ function $t({
4060
4060
  var z;
4061
4061
  if (!C) return;
4062
4062
  const N = `${C}:${B ?? "latest"}`;
4063
- if (x.current === N || I) return;
4063
+ if (A.current === N || v) return;
4064
4064
  (z = g.current) == null || z.abort();
4065
- const V = new AbortController();
4066
- g.current = V, f(!0), v(null);
4065
+ const K = new AbortController();
4066
+ g.current = K, f(!0), k(null);
4067
4067
  try {
4068
- const L = await b({
4068
+ const L = await w({
4069
4069
  threadId: C,
4070
4070
  checkpointId: B ?? void 0
4071
4071
  });
4072
- if (w.current !== C) {
4072
+ if (b.current !== C) {
4073
4073
  f(!1);
4074
4074
  return;
4075
4075
  }
@@ -4078,31 +4078,31 @@ function $t({
4078
4078
  checkpointNs: (L == null ? void 0 : L.checkpointNs) ?? null,
4079
4079
  pendingInterrupt: (L == null ? void 0 : L.interrupt) ?? null,
4080
4080
  values: L == null ? void 0 : L.values
4081
- }), x.current = N, f(!1), A(!0);
4081
+ }), A.current = N, f(!1), x(!0);
4082
4082
  try {
4083
4083
  const H = await e.getStateHistory({
4084
4084
  threadId: C,
4085
4085
  limit: 100,
4086
4086
  includeMessages: !1
4087
4087
  });
4088
- w.current === C && c(H);
4088
+ b.current === C && c(H);
4089
4089
  } finally {
4090
- A(!1);
4090
+ x(!1);
4091
4091
  }
4092
4092
  } catch (L) {
4093
4093
  if (f(!1), !Xt(L)) {
4094
4094
  const H = String(L);
4095
- v(H), r == null || r(H);
4095
+ k(H), r == null || r(H);
4096
4096
  }
4097
4097
  }
4098
4098
  },
4099
- [e, n, b, r, i]
4099
+ [e, n, w, r, i]
4100
4100
  ), j = _(
4101
4101
  async (C, B) => {
4102
4102
  if (o) {
4103
4103
  p(!0);
4104
4104
  try {
4105
- const N = await b({
4105
+ const N = await w({
4106
4106
  threadId: o,
4107
4107
  checkpointId: C,
4108
4108
  checkpointNs: B ?? void 0
@@ -4120,16 +4120,16 @@ function $t({
4120
4120
  }
4121
4121
  }
4122
4122
  },
4123
- [o, b, n]
4123
+ [o, w, n]
4124
4124
  ), M = _(async () => {
4125
4125
  o && await P(o);
4126
4126
  }, [o, P]), O = _(
4127
4127
  async (C) => {
4128
- var V;
4128
+ var K;
4129
4129
  const B = (C == null ? void 0 : C.threadId) || o;
4130
4130
  if (!B || o !== B) return;
4131
- if (c(C), x.current = `${B}:latest`, (V = C.values) != null && V.messages) {
4132
- const z = await b({
4131
+ if (c(C), A.current = `${B}:latest`, (K = C.values) != null && K.messages) {
4132
+ const z = await w({
4133
4133
  threadId: B
4134
4134
  });
4135
4135
  z && n(z.messages ?? [], {
@@ -4140,22 +4140,22 @@ function $t({
4140
4140
  });
4141
4141
  }
4142
4142
  },
4143
- [o, b, n]
4143
+ [o, w, n]
4144
4144
  );
4145
4145
  X(() => {
4146
- if (!s || !o || I || a) return;
4146
+ if (!s || !o || v || a) return;
4147
4147
  const C = `${o}:latest`;
4148
- x.current !== C && P(o);
4149
- }, [s, o, I, a, P]);
4148
+ A.current !== C && P(o);
4149
+ }, [s, o, v, a, P]);
4150
4150
  const F = _(() => {
4151
- 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;
4152
4152
  }, []);
4153
4153
  return {
4154
4154
  threadCheckpoints: d,
4155
4155
  threadTimeline: y,
4156
4156
  checkpointIndex: m,
4157
- isLoadingThread: I,
4158
- isLoadingCheckpoint: k,
4157
+ isLoadingThread: v,
4158
+ isLoadingCheckpoint: I,
4159
4159
  isLoadingHistory: S,
4160
4160
  threadStateError: E,
4161
4161
  loadThread: P,
@@ -4173,14 +4173,14 @@ function $t({
4173
4173
  clearState: F
4174
4174
  };
4175
4175
  }
4176
- const Dt = Ce(null), Vt = Ce(null);
4177
- function Kt(e) {
4176
+ const Dt = Ce(null), Kt = Ce(null);
4177
+ function Vt(e) {
4178
4178
  const t = Ue(Dt);
4179
4179
  if (!t && !(e != null && e.optional)) throw new Error("useThreadState must be used within a ThreadStateProvider");
4180
4180
  return t;
4181
4181
  }
4182
4182
  function Lr() {
4183
- const e = Ue(Vt);
4183
+ const e = Ue(Kt);
4184
4184
  if (!e)
4185
4185
  throw new Error("useThreadStateUpdater must be used within a ThreadStateProvider");
4186
4186
  return e;
@@ -4195,18 +4195,18 @@ function Ur({
4195
4195
  onError: a
4196
4196
  }) {
4197
4197
  const { chatApi: i, fileApi: u } = Me(), { currentThreadId: c } = ot(), { state: l, seed: d, onEvent: m, dispatch: y } = kr(), {
4198
- threadCheckpoints: I,
4198
+ threadCheckpoints: v,
4199
4199
  threadTimeline: f,
4200
- checkpointIndex: k,
4200
+ checkpointIndex: I,
4201
4201
  isLoadingThread: p,
4202
4202
  isLoadingCheckpoint: S,
4203
- isLoadingHistory: A,
4203
+ isLoadingHistory: x,
4204
4204
  threadStateError: E,
4205
- loadThread: v,
4206
- navigateToCheckpoint: w,
4207
- setCurrentCheckpointId: x,
4205
+ loadThread: k,
4206
+ navigateToCheckpoint: b,
4207
+ setCurrentCheckpointId: A,
4208
4208
  returnToLatest: g,
4209
- handleValuesEvent: b,
4209
+ handleValuesEvent: w,
4210
4210
  markSkipNextLoad: P,
4211
4211
  markStreamPendingThread: j,
4212
4212
  resetHistoryState: M
@@ -4232,23 +4232,23 @@ function Ur({
4232
4232
  C.current = T;
4233
4233
  },
4234
4234
  []
4235
- ), N = Y(() => ({ assemblingMessageId: l.assemblingId ?? null }), [l.assemblingId]), V = _(
4235
+ ), N = Y(() => ({ assemblingMessageId: l.assemblingId ?? null }), [l.assemblingId]), K = _(
4236
4236
  (T, J) => {
4237
- const K = Ut(T, "user");
4237
+ const V = Ut(T, "user");
4238
4238
  return y({
4239
4239
  type: "user_message",
4240
4240
  payload: {
4241
- message: K,
4241
+ message: V,
4242
4242
  editingMessageId: J == null ? void 0 : J.editingMessageId
4243
4243
  }
4244
- }), K;
4244
+ }), V;
4245
4245
  },
4246
4246
  [y]
4247
4247
  ), z = _(async () => {
4248
4248
  O.current ? await O.current() : (d([], {}), M());
4249
- }, [d, M]), L = _(async (T, J, K) => {
4250
- await v(T, J, { clearProgress: !1 });
4251
- }, [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(
4252
4252
  () => ({
4253
4253
  status: l.status,
4254
4254
  threadId: c,
@@ -4259,14 +4259,14 @@ function Ur({
4259
4259
  id: l.lastCheckpointId ?? null,
4260
4260
  namespace: l.lastCheckpointNs ?? null
4261
4261
  },
4262
- checkpoints: I,
4263
- checkpointIndex: k,
4262
+ checkpoints: v,
4263
+ checkpointIndex: I,
4264
4264
  timelineCheckpoints: f,
4265
4265
  metadata: N,
4266
4266
  values: l.values ?? {},
4267
4267
  isLoading: p,
4268
4268
  isLoadingCheckpoint: S,
4269
- isLoadingHistory: A,
4269
+ isLoadingHistory: x,
4270
4270
  error: E,
4271
4271
  loadOlder: async () => {
4272
4272
  },
@@ -4280,20 +4280,20 @@ function Ur({
4280
4280
  });
4281
4281
  },
4282
4282
  clearState: z,
4283
- navigateToCheckpoint: w,
4284
- setCurrentCheckpointId: x,
4283
+ navigateToCheckpoint: b,
4284
+ setCurrentCheckpointId: A,
4285
4285
  returnToLatest: g,
4286
4286
  loadThread: L,
4287
4287
  clearThread: z,
4288
- respondToInterrupt: async (T, J, K) => {
4289
- C.current && await C.current(T, J, K);
4288
+ respondToInterrupt: async (T, J, V) => {
4289
+ C.current && await C.current(T, J, V);
4290
4290
  },
4291
- messagePreviews: k.messagePreviews,
4292
- handleValuesEvent: b,
4291
+ messagePreviews: I.messagePreviews,
4292
+ handleValuesEvent: w,
4293
4293
  markSkipNextLoad: P,
4294
4294
  markStreamPendingThread: j,
4295
4295
  resetHistoryState: M,
4296
- pushUser: V,
4296
+ pushUser: K,
4297
4297
  onEvent: m,
4298
4298
  artifacts: H
4299
4299
  }),
@@ -4305,24 +4305,24 @@ function Ur({
4305
4305
  l.lastCheckpointId,
4306
4306
  l.lastCheckpointNs,
4307
4307
  l.values,
4308
- I,
4308
+ v,
4309
4309
  f,
4310
- k,
4310
+ I,
4311
4311
  N,
4312
4312
  p,
4313
4313
  S,
4314
- A,
4314
+ x,
4315
4315
  E,
4316
4316
  d,
4317
4317
  z,
4318
- w,
4319
- x,
4318
+ b,
4319
+ A,
4320
4320
  g,
4321
4321
  L,
4322
- b,
4322
+ w,
4323
4323
  P,
4324
4324
  j,
4325
- V,
4325
+ K,
4326
4326
  m,
4327
4327
  H
4328
4328
  ]
@@ -4333,7 +4333,7 @@ function Ur({
4333
4333
  }),
4334
4334
  [F, B]
4335
4335
  );
4336
- 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 }) });
4337
4337
  }
4338
4338
  const qt = Ce(null), jr = Ce(!1);
4339
4339
  function Br({
@@ -4348,25 +4348,25 @@ function Br({
4348
4348
  onFinish: u,
4349
4349
  onStreamingChange: c
4350
4350
  }) {
4351
- const { chatApi: l, baseUrl: d } = Me(), m = d, y = fe(t), I = fe(n), f = fe(r), k = fe(o), p = fe(s), S = fe(a), A = fe(i), E = fe(u), v = fe(c), w = Y(
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(
4352
4352
  () => ({
4353
4353
  onError: y,
4354
- onAuthError: I,
4354
+ onAuthError: v,
4355
4355
  onConnectionError: f,
4356
- onMetadataEvent: A,
4356
+ onMetadataEvent: x,
4357
4357
  onCustomEvent: S,
4358
4358
  onUpdateEvent: p,
4359
- onToolEnd: k,
4359
+ onToolEnd: I,
4360
4360
  onFinish: E
4361
4361
  }),
4362
4362
  [
4363
4363
  y,
4364
- I,
4364
+ v,
4365
4365
  f,
4366
- A,
4366
+ x,
4367
4367
  S,
4368
4368
  p,
4369
- k,
4369
+ I,
4370
4370
  E
4371
4371
  ]
4372
4372
  );
@@ -4375,8 +4375,8 @@ function Br({
4375
4375
  {
4376
4376
  api: l,
4377
4377
  streamBaseUrl: m,
4378
- handlers: w,
4379
- onStreamingChange: v,
4378
+ handlers: b,
4379
+ onStreamingChange: k,
4380
4380
  children: e
4381
4381
  }
4382
4382
  ) });
@@ -4394,17 +4394,17 @@ function Fr({
4394
4394
  timelineCheckpoints: d,
4395
4395
  handleValuesEvent: m,
4396
4396
  markSkipNextLoad: y,
4397
- markStreamPendingThread: I,
4397
+ markStreamPendingThread: v,
4398
4398
  resetHistoryState: f,
4399
- pushUser: k,
4399
+ pushUser: I,
4400
4400
  onEvent: p,
4401
4401
  messages: S
4402
- } = Kt(), { registerClearThread: A, registerRespondToInterrupt: E } = Lr(), v = _(
4402
+ } = Vt(), { registerClearThread: x, registerRespondToInterrupt: E } = Lr(), k = _(
4403
4403
  (h) => {
4404
- 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));
4405
4405
  },
4406
- [i, y, I, s, a]
4407
- ), w = pr({
4406
+ [i, y, v, s, a]
4407
+ ), b = pr({
4408
4408
  baseUrl: n,
4409
4409
  onEvent: p,
4410
4410
  onError: (h) => {
@@ -4414,7 +4414,7 @@ function Fr({
4414
4414
  onAuthError: r.onAuthError,
4415
4415
  onConnectionError: r.onConnectionError,
4416
4416
  onFinish: r.onFinish,
4417
- onThreadInfo: v,
4417
+ onThreadInfo: k,
4418
4418
  onMetadataEvent: r.onMetadataEvent,
4419
4419
  onCustomEvent: r.onCustomEvent,
4420
4420
  onUpdateEvent: r.onUpdateEvent,
@@ -4422,17 +4422,17 @@ function Fr({
4422
4422
  handleValuesEvent: m
4423
4423
  });
4424
4424
  X(() => {
4425
- o == null || o(w.isStreaming);
4426
- }, [w.isStreaming, o]);
4427
- const { stream: x, stop: g, clear: b, isStreaming: P, error: j, connected: M, streamedMessages: O, activeMessageId: F } = w;
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;
4428
4428
  X(() => {
4429
- u !== void 0 && b();
4430
- }, [u, b]);
4429
+ u !== void 0 && w();
4430
+ }, [u, w]);
4431
4431
  const C = _(
4432
4432
  async (h, U) => {
4433
- await x(h, U);
4433
+ await A(h, U);
4434
4434
  },
4435
- [x]
4435
+ [A]
4436
4436
  ), B = W(l);
4437
4437
  X(() => {
4438
4438
  B.current = l;
@@ -4443,11 +4443,11 @@ function Fr({
4443
4443
  const J = a.current;
4444
4444
  if (!J)
4445
4445
  throw new Error("No active thread to handle interrupt");
4446
- const K = h ? U ?? !0 : !1, q = B.current, ee = (T == null ? void 0 : T.checkpointId) ?? q.id ?? void 0, re = (T == null ? void 0 : T.checkpointNs) ?? q.namespace ?? void 0, ue = {
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 = {
4447
4447
  threadId: J,
4448
4448
  checkpointId: ee,
4449
4449
  checkpointNs: re,
4450
- command: { kind: "resume", value: K },
4450
+ command: { kind: "resume", value: V },
4451
4451
  payload: {
4452
4452
  ...(T == null ? void 0 : T.payload) ?? {},
4453
4453
  creativityLevel: ((G = T == null ? void 0 : T.payload) == null ? void 0 : G.creativityLevel) ?? "medium"
@@ -4461,27 +4461,27 @@ function Fr({
4461
4461
  X(() => {
4462
4462
  E(N);
4463
4463
  }, [N, E]);
4464
- const V = _(async () => {
4465
- g(), b(), f(), s(null);
4466
- }, [b, f, s, g]);
4464
+ const K = _(async () => {
4465
+ g(), w(), f(), s(null);
4466
+ }, [w, f, s, g]);
4467
4467
  X(() => {
4468
- A(V);
4469
- }, [V, A]);
4468
+ x(K);
4469
+ }, [K, x]);
4470
4470
  const z = _(
4471
4471
  async (h, U) => {
4472
4472
  P && g();
4473
4473
  let T = a.current;
4474
- const J = (h == null ? void 0 : h.text) ?? "", K = (h == null ? void 0 : h.attachments) ?? [], q = (J == null ? void 0 : J.trim()) ?? "", ee = { ...(h == null ? void 0 : h.payload) ?? {} }, re = Array.isArray(ee.messages) ? ee.messages : void 0;
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;
4475
4475
  re && delete ee.messages;
4476
4476
  const ue = !!(re && re.length), G = !!(h.contentParts && h.contentParts.length > 0);
4477
- if (!T && !q && K.length === 0 && !ue && !G) return;
4477
+ if (!T && !q && V.length === 0 && !ue && !G) return;
4478
4478
  if (!T) {
4479
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);
4480
4480
  T = `${ye}${he}`, y(T), s(T);
4481
4481
  }
4482
4482
  let te = null;
4483
4483
  h.contentParts && h.contentParts.length > 0 && (te = h.contentParts);
4484
- const { contentParts: ke, filesInfo: Q } = te ? { contentParts: te, filesInfo: [] } : await or(K), Z = [...ke];
4484
+ const { contentParts: ke, filesInfo: Q } = te ? { contentParts: te, filesInfo: [] } : await or(V), Z = [...ke];
4485
4485
  q && Z.push({ type: "text", text: J });
4486
4486
  const ge = h == null ? void 0 : h.originalMessageId, je = !!(h != null && h.edit && ge), Be = !ue && Z.length > 0;
4487
4487
  let me = null;
@@ -4492,7 +4492,7 @@ function Fr({
4492
4492
  role: "user",
4493
4493
  content: Z,
4494
4494
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4495
- }, "user"), je ? k(me, { editingMessageId: ge }) : k(me);
4495
+ }, "user"), je ? I(me, { editingMessageId: ge }) : I(me);
4496
4496
  }
4497
4497
  const Ie = ue ? re : me ? [me] : [], oe = {
4498
4498
  ...ee,
@@ -4515,7 +4515,7 @@ function Fr({
4515
4515
  };
4516
4516
  return C(Ae, U);
4517
4517
  },
4518
- [l, a, P, y, k, C, g, d]
4518
+ [l, a, P, y, I, C, g, d]
4519
4519
  ), L = Y(() => S, [S]), H = Y(
4520
4520
  () => ({
4521
4521
  isStreaming: P,
@@ -4567,14 +4567,14 @@ function Dr(e) {
4567
4567
  const t = W(e), n = W(e);
4568
4568
  return $r(t.current, e) || (t.current = e, n.current = e), n.current;
4569
4569
  }
4570
- function Vr(e) {
4570
+ function Kr(e) {
4571
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;
4572
4572
  return typeof o == "string" ? o : null;
4573
4573
  }
4574
4574
  function fo(e) {
4575
4575
  const { setCurrentTaskId: t, getCurrentTaskId: n, onToolEnd: r } = e;
4576
4576
  return (o) => {
4577
- const s = Vr(o), a = (n == null ? void 0 : n()) ?? null;
4577
+ const s = Kr(o), a = (n == null ? void 0 : n()) ?? null;
4578
4578
  s && s !== a && t(s), r == null || r(o);
4579
4579
  };
4580
4580
  }
@@ -4593,27 +4593,27 @@ function po({
4593
4593
  onUpdateEvent: d,
4594
4594
  onCustomEvent: m,
4595
4595
  onMetadataEvent: y,
4596
- onFinish: I
4596
+ onFinish: v
4597
4597
  }) {
4598
- const f = Dr(t), [k, p] = $(!1), S = pe(i), A = pe(u), E = pe(a), v = pe(c), w = pe(l), x = pe(d), g = pe(m), b = pe(y), P = pe(I), j = Y(
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(
4599
4599
  () => ({
4600
4600
  onError: S,
4601
- onAuthError: A,
4601
+ onAuthError: x,
4602
4602
  onConnectionError: E,
4603
- onToolEnd: w,
4604
- onUpdateEvent: x,
4603
+ onToolEnd: b,
4604
+ onUpdateEvent: A,
4605
4605
  onCustomEvent: g,
4606
- onMetadataEvent: b,
4606
+ onMetadataEvent: w,
4607
4607
  onFinish: P
4608
4608
  }),
4609
4609
  [
4610
4610
  S,
4611
- A,
4612
- E,
4613
- w,
4614
4611
  x,
4615
- g,
4612
+ E,
4616
4613
  b,
4614
+ A,
4615
+ g,
4616
+ w,
4617
4617
  P
4618
4618
  ]
4619
4619
  );
@@ -4622,7 +4622,7 @@ function po({
4622
4622
  {
4623
4623
  initialThreadId: n,
4624
4624
  onError: S,
4625
- onThreadChange: v,
4625
+ onThreadChange: k,
4626
4626
  children: /* @__PURE__ */ ie(
4627
4627
  Ur,
4628
4628
  {
@@ -4631,7 +4631,7 @@ function po({
4631
4631
  initialCheckpointNs: o,
4632
4632
  autoLoadInitial: s,
4633
4633
  onError: S,
4634
- isStreaming: k,
4634
+ isStreaming: I,
4635
4635
  children: /* @__PURE__ */ ie(
4636
4636
  Br,
4637
4637
  {
@@ -4653,7 +4653,7 @@ function pe(e) {
4653
4653
  return r(...n);
4654
4654
  }, []);
4655
4655
  }
4656
- const Kr = 1, qr = 1e6;
4656
+ const Vr = 1, qr = 1e6;
4657
4657
  let We = 0;
4658
4658
  function Hr() {
4659
4659
  return We = (We + 1) % Number.MAX_SAFE_INTEGER, We.toString();
@@ -4673,7 +4673,7 @@ const Je = /* @__PURE__ */ new Map(), wt = (e) => {
4673
4673
  case "ADD_TOAST":
4674
4674
  return {
4675
4675
  ...e,
4676
- toasts: [t.toast, ...e.toasts].slice(0, Kr)
4676
+ toasts: [t.toast, ...e.toasts].slice(0, Vr)
4677
4677
  };
4678
4678
  case "UPDATE_TOAST":
4679
4679
  return {
@@ -4747,63 +4747,63 @@ function Jr() {
4747
4747
  function go(e) {
4748
4748
  const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = Me(), { toast: o } = Jr(), [s, a] = $({}), [i, u] = $(null), [c, l] = $(!1), d = _(() => {
4749
4749
  l(!1), u(null);
4750
- }, []), m = _((I) => {
4751
- u(I), l(!0);
4750
+ }, []), m = _((v) => {
4751
+ u(v), l(!0);
4752
4752
  }, []), y = _(
4753
- async (I, f, k) => {
4753
+ async (v, f, I) => {
4754
4754
  var p, S;
4755
4755
  if (!t) {
4756
- I.preventDefault();
4756
+ v.preventDefault();
4757
4757
  return;
4758
4758
  }
4759
- if (s[k]) {
4760
- I.preventDefault();
4759
+ if (s[I]) {
4760
+ v.preventDefault();
4761
4761
  return;
4762
4762
  }
4763
4763
  try {
4764
- 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))?/);
4765
4765
  if (E) {
4766
- I.preventDefault();
4767
- const v = E[1], w = f.name || `file_${v}`, x = f.mimeType || "application/octet-stream";
4768
- m({ id: v, name: w, mimeType: x });
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 });
4769
4769
  return;
4770
4770
  }
4771
- if (A.startsWith("data:")) {
4772
- I.preventDefault(), a((w) => ({ ...w, [k]: !0 }));
4773
- 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 });
4774
4774
  try {
4775
- const w = await r.listFiles(n ?? void 0);
4776
- if (!w || !Array.isArray(w))
4775
+ const b = await r.listFiles(n ?? void 0);
4776
+ if (!b || !Array.isArray(b))
4777
4777
  throw new Error("Invalid file list response");
4778
- const x = w.find((g) => !g || typeof g != "object" || !((g.filename ?? "") === (f.name ?? "")) ? !1 : typeof f.size == "number" && typeof g.size == "number" ? g.size === f.size : !0);
4779
- if (!(x != null && x.id))
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))
4780
4780
  throw new Error(`File "${f.name}" is not yet available on the server`);
4781
- if (!x.id || !x.filename)
4781
+ if (!A.id || !A.filename)
4782
4782
  throw new Error("Invalid file data received from server");
4783
4783
  m({
4784
- id: x.id,
4785
- name: f.name || x.filename || `file_${x.id}`,
4786
- mimeType: f.mimeType || x.mime_type || "application/octet-stream"
4787
- }), (p = v.update) == null || p.call(v, {
4788
- 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,
4789
4789
  title: "Success",
4790
4790
  description: `Opened ${f.name}`,
4791
4791
  open: !0
4792
4792
  });
4793
- } catch (w) {
4794
- console.error("Failed to fetch server file:", w);
4795
- const x = w instanceof Error ? w.message : "Unknown error occurred";
4796
- (S = v.update) == null || S.call(v, { id: v.id, title: "Failed", description: x }), o({
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({
4797
4797
  title: "Failed to fetch file",
4798
- description: x,
4798
+ description: A,
4799
4799
  open: !0
4800
4800
  });
4801
4801
  } finally {
4802
- a((w) => ({ ...w, [k]: !1 }));
4802
+ a((b) => ({ ...b, [I]: !1 }));
4803
4803
  }
4804
4804
  }
4805
- } catch (A) {
4806
- 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 }));
4807
4807
  }
4808
4808
  },
4809
4809
  [t, s, o, n, m]
@@ -4890,7 +4890,7 @@ function yo(e) {
4890
4890
  }
4891
4891
  function Yr(e) {
4892
4892
  var M, O;
4893
- const t = typeof e == "string" ? e : e == null ? void 0 : e.threadId, n = typeof e == "object" ? e.lazy : !1, r = ot({ optional: !0 }), o = Kt({ optional: !0 }), s = Or(), { currentThreadId: a, setCurrentThreadId: i, actions: u } = r || {
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 || {
4894
4894
  currentThreadId: null,
4895
4895
  setCurrentThreadId: () => {
4896
4896
  },
@@ -4899,9 +4899,9 @@ function Yr(e) {
4899
4899
  d(F);
4900
4900
  }, []), {
4901
4901
  isLoadingThread: y,
4902
- threadStateError: I,
4902
+ threadStateError: v,
4903
4903
  threadCheckpoints: f,
4904
- isLoadingHistory: k,
4904
+ isLoadingHistory: I,
4905
4905
  loadThread: p
4906
4906
  } = $t({
4907
4907
  api: Me().chatApi,
@@ -4919,17 +4919,17 @@ function Yr(e) {
4919
4919
  const S = Y(() => {
4920
4920
  var F;
4921
4921
  return ((F = f[0]) == null ? void 0 : F.values) || {};
4922
- }, [f]), A = Y(() => ({ timeline: [], messagePreviews: {} }), []), E = t || a, v = c ? y ? "loading" : "idle" : (o == null ? void 0 : o.status) || "idle", w = c ? l : (s == null ? void 0 : s.messages) || [], x = c ? y : (o == null ? void 0 : o.isLoading) || !1, g = c ? k : (o == null ? void 0 : o.isLoadingHistory) || !1, b = c ? S : (o == null ? void 0 : o.values) || {}, P = c ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, j = c ? I : (s == null ? void 0 : s.error) || (o == null ? void 0 : o.error) || null;
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;
4923
4923
  return {
4924
4924
  // UNIFIED: Single thread ID concept
4925
4925
  threadId: E,
4926
- status: v,
4927
- messages: w,
4928
- isLoading: x,
4926
+ status: k,
4927
+ messages: b,
4928
+ isLoading: A,
4929
4929
  isHistoryLoading: g,
4930
4930
  error: j,
4931
4931
  // Values & Metadata
4932
- values: b,
4932
+ values: w,
4933
4933
  taskMessagesByScope: P,
4934
4934
  metadata: c ? {} : o == null ? void 0 : o.metadata,
4935
4935
  // Actions & State relating to Global/Active Thread only
@@ -4941,7 +4941,7 @@ function Yr(e) {
4941
4941
  }),
4942
4942
  checkpoint: c ? f[0] ? { id: f[0].checkpointId, namespace: f[0].checkpointNs } : null : (o == null ? void 0 : o.checkpoint) || null,
4943
4943
  checkpoints: c ? f : (o == null ? void 0 : o.checkpoints) || [],
4944
- checkpointIndex: c ? A : (o == null ? void 0 : o.checkpointIndex) || { timeline: [], messagePreviews: {} },
4944
+ checkpointIndex: c ? x : (o == null ? void 0 : o.checkpointIndex) || { timeline: [], messagePreviews: {} },
4945
4945
  interrupt: c ? null : (o == null ? void 0 : o.interrupt) || null,
4946
4946
  respondToInterrupt: c ? async () => {
4947
4947
  } : (o == null ? void 0 : o.respondToInterrupt) || (async () => {
@@ -4992,7 +4992,7 @@ function ho({
4992
4992
  threadId: m,
4993
4993
  clearComposerOnSend: y = !0
4994
4994
  }) {
4995
- const { messages: I } = Yr(), [f, k] = $(null), [p, S] = $(""), [A, E] = $(null), [v, w] = $(null), [x, g] = $(!1), [b, P] = $(""), j = W(b), M = W(null);
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);
4996
4996
  X(() => {
4997
4997
  if (!f)
4998
4998
  if (m) {
@@ -5005,8 +5005,8 @@ function ho({
5005
5005
  P(h), !f && m && localStorage.setItem(Ge(m), h);
5006
5006
  }, [m, f]);
5007
5007
  X(() => {
5008
- j.current = b;
5009
- }, [b]), X(() => {
5008
+ j.current = w;
5009
+ }, [w]), X(() => {
5010
5010
  if (!f) {
5011
5011
  M.current = null;
5012
5012
  return;
@@ -5019,8 +5019,8 @@ function ho({
5019
5019
  },
5020
5020
  [O]
5021
5021
  ), C = async (h, U) => {
5022
- const T = Array.isArray(U) ? { files: U } : U ?? {}, J = T.files ?? [], K = T.contentParts ?? [], q = h.trim();
5023
- if (!(!q && J.length === 0 && K.length === 0))
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))
5024
5024
  try {
5025
5025
  const ee = J.map(async (Q) => {
5026
5026
  try {
@@ -5041,7 +5041,7 @@ function ho({
5041
5041
  name: Q.filename,
5042
5042
  size: Q.size
5043
5043
  };
5044
- }), G = [...K, ...ue], te = f ? (A == null ? void 0 : A.checkpointId) ?? n ?? void 0 : n ?? void 0, ke = f ? (A == null ? void 0 : A.checkpointNs) ?? r ?? void 0 : r ?? void 0;
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;
5045
5045
  await e(
5046
5046
  {
5047
5047
  text: q || "",
@@ -5056,10 +5056,10 @@ function ho({
5056
5056
  config: t.config
5057
5057
  },
5058
5058
  d ? { onEvent: d } : void 0
5059
- ), o == null || o(q), c(!0), y && (m && localStorage.removeItem(Ge(m)), O("")), w(null), k(null), S(""), E(null);
5059
+ ), o == null || o(q), c(!0), y && (m && localStorage.removeItem(Ge(m)), O("")), b(null), I(null), S(""), E(null);
5060
5060
  } catch (ee) {
5061
5061
  const re = (ee == null ? void 0 : ee.message) || "Failed to send message";
5062
- w(re), a == null || a(re), c(!1);
5062
+ b(re), a == null || a(re), c(!1);
5063
5063
  }
5064
5064
  }, B = (h, U) => {
5065
5065
  U || C(h, { files: [] });
@@ -5078,16 +5078,16 @@ function ho({
5078
5078
  ), s == null || s({ file: h });
5079
5079
  },
5080
5080
  [n, r, t, s, e]
5081
- ), V = _(
5081
+ ), K = _(
5082
5082
  (h, U, T) => {
5083
- i && (M.current = b, k(h), S(U), E({
5083
+ i && (M.current = w, I(h), S(U), E({
5084
5084
  checkpointId: (T == null ? void 0 : T.checkpointId) ?? null,
5085
5085
  checkpointNs: (T == null ? void 0 : T.checkpointNs) ?? null
5086
- }), w(null));
5086
+ }), b(null));
5087
5087
  },
5088
- [b, i]
5088
+ [w, i]
5089
5089
  ), z = _(() => {
5090
- k(null), S(""), E(null), w(null);
5090
+ I(null), S(""), E(null), b(null);
5091
5091
  const h = M.current;
5092
5092
  h !== null && P(h), M.current = null;
5093
5093
  }, []), L = _((h) => {
@@ -5098,16 +5098,16 @@ function ho({
5098
5098
  break;
5099
5099
  }
5100
5100
  if (!U) return;
5101
- const T = Array.isArray(U.content) ? U.content : [], K = T.filter((q) => (q == null ? void 0 : q.type) === "text").map((q) => q.text).join("") || (() => {
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("") || (() => {
5102
5102
  try {
5103
5103
  return JSON.stringify(T, null, 2);
5104
5104
  } catch {
5105
5105
  return String(T);
5106
5106
  }
5107
5107
  })();
5108
- K && e(
5108
+ V && e(
5109
5109
  {
5110
- text: K,
5110
+ text: V,
5111
5111
  payload: t.payload,
5112
5112
  checkpointId: n ?? void 0,
5113
5113
  checkpointNs: r ?? void 0,
@@ -5121,19 +5121,19 @@ function ho({
5121
5121
  return {
5122
5122
  editingMessageId: f,
5123
5123
  editingInitialValue: p,
5124
- inputError: v,
5125
- setInputError: w,
5126
- dismissError: x,
5124
+ inputError: k,
5125
+ setInputError: b,
5126
+ dismissError: A,
5127
5127
  setDismissError: g,
5128
- composerValue: b,
5128
+ composerValue: w,
5129
5129
  handleComposerChange: F,
5130
5130
  handleSendMessage: C,
5131
5131
  handleQuickPrompt: B,
5132
5132
  handleExcelUpload: N,
5133
- startEditing: V,
5133
+ startEditing: K,
5134
5134
  cancelEditing: z,
5135
5135
  handleRegenerateCb: L,
5136
- displayMessages: I
5136
+ displayMessages: v
5137
5137
  };
5138
5138
  }
5139
5139
  function bo(e) {
@@ -5176,7 +5176,7 @@ export {
5176
5176
  ro as cn,
5177
5177
  sr as collectText,
5178
5178
  fo as createTaskSyncToolEndHandler,
5179
- Vr as extractTaskIdFromToolEnd,
5179
+ Kr as extractTaskIdFromToolEnd,
5180
5180
  ar as extractToolMeta,
5181
5181
  oo as formatToolOutput,
5182
5182
  co as getAgentNameFromMessage,
@@ -5194,7 +5194,7 @@ export {
5194
5194
  tt as parseJsonSafe,
5195
5195
  Et as pretty,
5196
5196
  Mr as refreshHistoryFileUrls,
5197
- Ve as sanitizeForDisplay,
5197
+ Ke as sanitizeForDisplay,
5198
5198
  ve as setChatToken,
5199
5199
  Fn as stringifyTool,
5200
5200
  Me as useApi,
@@ -5206,7 +5206,7 @@ export {
5206
5206
  pr as useStream,
5207
5207
  wo as useStreamingMarkdownBuffer,
5208
5208
  $t as useThreadHistoryState,
5209
- Kt as useThreadState,
5209
+ Vt as useThreadState,
5210
5210
  Lr as useThreadStateUpdater,
5211
5211
  ot as useThreads,
5212
5212
  gr as useThreadsState,