@teodorruskvi/chat-core 0.1.43 → 0.1.45

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.esm.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var Gt = Object.defineProperty;
2
2
  var Ht = (e, t, n) => t in e ? Gt(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var st = (e, t, n) => Ht(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsx as ie } from "react/jsx-runtime";
4
+ import { jsx as le } from "react/jsx-runtime";
5
5
  import * as at from "react";
6
- import { createContext as Se, useContext as Ue, useState as V, useRef as K, useEffect as q, useCallback as z, useMemo as Q, useReducer as Wt } from "react";
6
+ import { createContext as Se, useContext as Ue, useState as V, useRef as K, useEffect as q, useCallback as z, useMemo as Y, useReducer as Wt } from "react";
7
7
  import qt, { isCancel as Jt } from "axios";
8
8
  function vt(e) {
9
9
  var t, n, r = "";
@@ -238,43 +238,43 @@ function un(e, ...t) {
238
238
  const $ = (e) => {
239
239
  const t = (n) => n[e] || [];
240
240
  return t.isThemeGetter = !0, t;
241
- }, xt = /^\[(?:([a-z-]+):)?(.+)\]$/i, dn = /^\d+\/\d+$/, fn = /* @__PURE__ */ new Set(["px", "full", "screen"]), pn = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, gn = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/, mn = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, hn = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, yn = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, fe = (e) => xe(e) || fn.has(e) || dn.test(e), be = (e) => Ce(e, "length", An), xe = (e) => !!e && !Number.isNaN(Number(e)), Ke = (e) => Ce(e, "number", xe), Pe = (e) => !!e && Number.isInteger(Number(e)), bn = (e) => e.endsWith("%") && xe(e.slice(0, -1)), R = (e) => xt.test(e), we = (e) => pn.test(e), wn = /* @__PURE__ */ new Set(["length", "size", "percentage"]), vn = (e) => Ce(e, wn, At), kn = (e) => Ce(e, "position", At), In = /* @__PURE__ */ new Set(["image", "url"]), Tn = (e) => Ce(e, In, Cn), xn = (e) => Ce(e, "", Sn), Ne = () => !0, Ce = (e, t, n) => {
242
- const r = xt.exec(e);
241
+ }, At = /^\[(?:([a-z-]+):)?(.+)\]$/i, dn = /^\d+\/\d+$/, fn = /* @__PURE__ */ new Set(["px", "full", "screen"]), pn = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, gn = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/, mn = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, hn = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, yn = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, pe = (e) => Ae(e) || fn.has(e) || dn.test(e), be = (e) => Ce(e, "length", xn), Ae = (e) => !!e && !Number.isNaN(Number(e)), Ke = (e) => Ce(e, "number", Ae), Pe = (e) => !!e && Number.isInteger(Number(e)), bn = (e) => e.endsWith("%") && Ae(e.slice(0, -1)), R = (e) => At.test(e), we = (e) => pn.test(e), wn = /* @__PURE__ */ new Set(["length", "size", "percentage"]), vn = (e) => Ce(e, wn, xt), kn = (e) => Ce(e, "position", xt), In = /* @__PURE__ */ new Set(["image", "url"]), Tn = (e) => Ce(e, In, Cn), An = (e) => Ce(e, "", Sn), Ne = () => !0, Ce = (e, t, n) => {
242
+ const r = At.exec(e);
243
243
  return r ? r[1] ? typeof t == "string" ? r[1] === t : t.has(r[1]) : n(r[2]) : !1;
244
- }, An = (e) => (
244
+ }, xn = (e) => (
245
245
  // `colorFunctionRegex` check is necessary because color functions can have percentages in them which which would be incorrectly classified as lengths.
246
246
  // For example, `hsl(0 0% 0%)` would be classified as a length without this check.
247
247
  // I could also use lookbehind assertion in `lengthUnitRegex` but that isn't supported widely enough.
248
248
  gn.test(e) && !mn.test(e)
249
- ), At = () => !1, Sn = (e) => hn.test(e), Cn = (e) => yn.test(e), Mn = () => {
250
- const e = $("colors"), t = $("spacing"), n = $("blur"), r = $("brightness"), o = $("borderColor"), s = $("borderRadius"), a = $("borderSpacing"), i = $("borderWidth"), u = $("contrast"), c = $("grayscale"), l = $("hueRotate"), f = $("invert"), m = $("gap"), h = $("gradientColorStops"), k = $("gradientColorStopPositions"), d = $("inset"), v = $("margin"), I = $("opacity"), C = $("padding"), T = $("saturate"), P = $("scale"), b = $("sepia"), y = $("skew"), x = $("space"), p = $("translate"), w = () => ["auto", "contain", "none"], _ = () => ["auto", "hidden", "clip", "visible", "scroll"], U = () => ["auto", R, t], M = () => [R, t], E = () => ["", fe, be], j = () => ["auto", xe, R], N = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], B = () => ["solid", "dashed", "dotted", "double", "none"], O = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], L = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], F = () => ["", "0", R], W = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], Y = () => [xe, R];
249
+ ), xt = () => !1, Sn = (e) => hn.test(e), Cn = (e) => yn.test(e), Mn = () => {
250
+ const e = $("colors"), t = $("spacing"), n = $("blur"), r = $("brightness"), o = $("borderColor"), s = $("borderRadius"), a = $("borderSpacing"), i = $("borderWidth"), u = $("contrast"), c = $("grayscale"), l = $("hueRotate"), f = $("invert"), m = $("gap"), h = $("gradientColorStops"), k = $("gradientColorStopPositions"), d = $("inset"), v = $("margin"), I = $("opacity"), C = $("padding"), T = $("saturate"), P = $("scale"), b = $("sepia"), y = $("skew"), A = $("space"), p = $("translate"), w = () => ["auto", "contain", "none"], _ = () => ["auto", "hidden", "clip", "visible", "scroll"], U = () => ["auto", R, t], M = () => [R, t], E = () => ["", pe, be], j = () => ["auto", Ae, R], N = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], B = () => ["solid", "dashed", "dotted", "double", "none"], O = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], F = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], L = () => ["", "0", R], W = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], Z = () => [Ae, R];
251
251
  return {
252
252
  cacheSize: 500,
253
253
  separator: ":",
254
254
  theme: {
255
255
  colors: [Ne],
256
- spacing: [fe, be],
256
+ spacing: [pe, be],
257
257
  blur: ["none", "", we, R],
258
- brightness: Y(),
258
+ brightness: Z(),
259
259
  borderColor: [e],
260
260
  borderRadius: ["none", "", "full", we, R],
261
261
  borderSpacing: M(),
262
262
  borderWidth: E(),
263
- contrast: Y(),
264
- grayscale: F(),
265
- hueRotate: Y(),
266
- invert: F(),
263
+ contrast: Z(),
264
+ grayscale: L(),
265
+ hueRotate: Z(),
266
+ invert: L(),
267
267
  gap: M(),
268
268
  gradientColorStops: [e],
269
269
  gradientColorStopPositions: [bn, be],
270
270
  inset: U(),
271
271
  margin: U(),
272
- opacity: Y(),
272
+ opacity: Z(),
273
273
  padding: M(),
274
- saturate: Y(),
275
- scale: Y(),
276
- sepia: F(),
277
- skew: Y(),
274
+ saturate: Z(),
275
+ scale: Z(),
276
+ sepia: L(),
277
+ skew: Z(),
278
278
  space: M(),
279
279
  translate: M()
280
280
  },
@@ -528,14 +528,14 @@ const $ = (e) => {
528
528
  * @see https://tailwindcss.com/docs/flex-grow
529
529
  */
530
530
  grow: [{
531
- grow: F()
531
+ grow: L()
532
532
  }],
533
533
  /**
534
534
  * Flex Shrink
535
535
  * @see https://tailwindcss.com/docs/flex-shrink
536
536
  */
537
537
  shrink: [{
538
- shrink: F()
538
+ shrink: L()
539
539
  }],
540
540
  /**
541
541
  * Order
@@ -651,7 +651,7 @@ const $ = (e) => {
651
651
  * @see https://tailwindcss.com/docs/justify-content
652
652
  */
653
653
  "justify-content": [{
654
- justify: ["normal", ...L()]
654
+ justify: ["normal", ...F()]
655
655
  }],
656
656
  /**
657
657
  * Justify Items
@@ -672,7 +672,7 @@ const $ = (e) => {
672
672
  * @see https://tailwindcss.com/docs/align-content
673
673
  */
674
674
  "align-content": [{
675
- content: ["normal", ...L(), "baseline"]
675
+ content: ["normal", ...F(), "baseline"]
676
676
  }],
677
677
  /**
678
678
  * Align Items
@@ -693,7 +693,7 @@ const $ = (e) => {
693
693
  * @see https://tailwindcss.com/docs/place-content
694
694
  */
695
695
  "place-content": [{
696
- "place-content": [...L(), "baseline"]
696
+ "place-content": [...F(), "baseline"]
697
697
  }],
698
698
  /**
699
699
  * Place Items
@@ -841,7 +841,7 @@ const $ = (e) => {
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 $ = (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
@@ -986,14 +986,14 @@ const $ = (e) => {
986
986
  * @see https://tailwindcss.com/docs/line-clamp
987
987
  */
988
988
  "line-clamp": [{
989
- "line-clamp": ["none", xe, Ke]
989
+ "line-clamp": ["none", Ae, Ke]
990
990
  }],
991
991
  /**
992
992
  * Line Height
993
993
  * @see https://tailwindcss.com/docs/line-height
994
994
  */
995
995
  leading: [{
996
- leading: ["none", "tight", "snug", "normal", "relaxed", "loose", fe, R]
996
+ leading: ["none", "tight", "snug", "normal", "relaxed", "loose", pe, R]
997
997
  }],
998
998
  /**
999
999
  * List Style Image
@@ -1069,14 +1069,14 @@ const $ = (e) => {
1069
1069
  * @see https://tailwindcss.com/docs/text-decoration-thickness
1070
1070
  */
1071
1071
  "text-decoration-thickness": [{
1072
- decoration: ["auto", "from-font", fe, be]
1072
+ decoration: ["auto", "from-font", pe, be]
1073
1073
  }],
1074
1074
  /**
1075
1075
  * Text Underline Offset
1076
1076
  * @see https://tailwindcss.com/docs/text-underline-offset
1077
1077
  */
1078
1078
  "underline-offset": [{
1079
- "underline-offset": ["auto", fe, R]
1079
+ "underline-offset": ["auto", pe, R]
1080
1080
  }],
1081
1081
  /**
1082
1082
  * Text Decoration Color
@@ -1558,14 +1558,14 @@ const $ = (e) => {
1558
1558
  * @see https://tailwindcss.com/docs/outline-offset
1559
1559
  */
1560
1560
  "outline-offset": [{
1561
- "outline-offset": [fe, R]
1561
+ "outline-offset": [pe, R]
1562
1562
  }],
1563
1563
  /**
1564
1564
  * Outline Width
1565
1565
  * @see https://tailwindcss.com/docs/outline-width
1566
1566
  */
1567
1567
  "outline-w": [{
1568
- outline: [fe, be]
1568
+ outline: [pe, be]
1569
1569
  }],
1570
1570
  /**
1571
1571
  * Outline Color
@@ -1605,7 +1605,7 @@ const $ = (e) => {
1605
1605
  * @see https://tailwindcss.com/docs/ring-offset-width
1606
1606
  */
1607
1607
  "ring-offset-w": [{
1608
- "ring-offset": [fe, be]
1608
+ "ring-offset": [pe, be]
1609
1609
  }],
1610
1610
  /**
1611
1611
  * Ring Offset Color
@@ -1620,7 +1620,7 @@ const $ = (e) => {
1620
1620
  * @see https://tailwindcss.com/docs/box-shadow
1621
1621
  */
1622
1622
  shadow: [{
1623
- shadow: ["", "inner", "none", we, xn]
1623
+ shadow: ["", "inner", "none", we, An]
1624
1624
  }],
1625
1625
  /**
1626
1626
  * Box Shadow Color
@@ -1849,7 +1849,7 @@ const $ = (e) => {
1849
1849
  * @see https://tailwindcss.com/docs/transition-duration
1850
1850
  */
1851
1851
  duration: [{
1852
- duration: Y()
1852
+ duration: Z()
1853
1853
  }],
1854
1854
  /**
1855
1855
  * Transition Timing Function
@@ -1863,7 +1863,7 @@ const $ = (e) => {
1863
1863
  * @see https://tailwindcss.com/docs/transition-delay
1864
1864
  */
1865
1865
  delay: [{
1866
- delay: Y()
1866
+ delay: Z()
1867
1867
  }],
1868
1868
  /**
1869
1869
  * Animation
@@ -2200,7 +2200,7 @@ const $ = (e) => {
2200
2200
  * @see https://tailwindcss.com/docs/stroke-width
2201
2201
  */
2202
2202
  "stroke-w": [{
2203
- stroke: [fe, be, Ke]
2203
+ stroke: [pe, be, Ke]
2204
2204
  }],
2205
2205
  /**
2206
2206
  * Stroke
@@ -2332,7 +2332,7 @@ function jn(e) {
2332
2332
  function St(e) {
2333
2333
  return Array.isArray(e.toolCalls) ? e.toolCalls : [];
2334
2334
  }
2335
- function Ln(e) {
2335
+ function Fn(e) {
2336
2336
  const t = [];
2337
2337
  return e.forEach((n) => {
2338
2338
  n.artifact && t.push(n.artifact), Array.isArray(n.toolCalls) && n.toolCalls.forEach((r) => {
@@ -2401,7 +2401,7 @@ function Zr(e) {
2401
2401
  const t = Mt(e);
2402
2402
  return typeof e == "string" && Nn(e) ? { content: e, isMarkdown: !0 } : { content: t, isMarkdown: !1 };
2403
2403
  }
2404
- function Fn(e) {
2404
+ function Ln(e) {
2405
2405
  const t = (r) => {
2406
2406
  try {
2407
2407
  const o = Ve(r);
@@ -2416,41 +2416,41 @@ function Fn(e) {
2416
2416
  function eo(e) {
2417
2417
  return e.content.some((t) => t.type === "text" ? t.text.trim().length > 0 : t.type === "image_url" || t.type === "file");
2418
2418
  }
2419
- function ce(e) {
2419
+ function ue(e) {
2420
2420
  if (e == null) return e;
2421
2421
  if (typeof e == "string") {
2422
2422
  const t = e.trim();
2423
2423
  if (t.startsWith("{") || t.startsWith("[")) {
2424
2424
  const n = et(t);
2425
2425
  if (n !== null)
2426
- return ce(n);
2426
+ return ue(n);
2427
2427
  }
2428
2428
  return e;
2429
2429
  }
2430
2430
  if (typeof e == "object" && !Array.isArray(e)) {
2431
2431
  if (e.content !== void 0)
2432
- return Array.isArray(e.content) ? e.content.map((t) => ce(t)).filter(Boolean).join(`
2433
- `) : ce(e.content);
2432
+ return Array.isArray(e.content) ? e.content.map((t) => ue(t)).filter(Boolean).join(`
2433
+ `) : ue(e.content);
2434
2434
  if (e.value !== void 0)
2435
- return ce(e.value);
2435
+ return ue(e.value);
2436
2436
  }
2437
- return typeof e == "object" && !Array.isArray(e) && (e.type === "text" && typeof e.text == "string" || typeof e.text == "string") ? e.text : Array.isArray(e) && e.length > 0 ? ce(e[0]) : e;
2437
+ return typeof e == "object" && !Array.isArray(e) && (e.type === "text" && typeof e.text == "string" || typeof e.text == "string") ? e.text : Array.isArray(e) && e.length > 0 ? ue(e[0]) : e;
2438
2438
  }
2439
2439
  function On(e) {
2440
2440
  return e.replace(/[_-](\w)/g, (t, n) => n ? n.toUpperCase() : "").replace(/^\w/, (t) => t.toLowerCase());
2441
2441
  }
2442
- function le(e) {
2443
- return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(le) : Object.fromEntries(
2442
+ function de(e) {
2443
+ return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(de) : Object.fromEntries(
2444
2444
  Object.entries(e).map(([t, n]) => [
2445
2445
  On(t),
2446
- le(n)
2446
+ de(n)
2447
2447
  ])
2448
2448
  );
2449
2449
  }
2450
2450
  function tt(e) {
2451
2451
  var v, I, C, T, P, b;
2452
2452
  if (!e || typeof e != "object") return null;
2453
- const t = le(e), n = Vn(t);
2453
+ const t = de(e), n = Vn(t);
2454
2454
  if (!n)
2455
2455
  return null;
2456
2456
  const r = Array.isArray(t.toolCalls) ? t.toolCalls.map(nt) : void 0, o = $n(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 ?? ((v = t.additionalKwargs) == null ? void 0 : v.createdAt) ?? (/* @__PURE__ */ new Date()).toISOString(), i = t.name ?? ((I = t.additionalKwargs) == null ? void 0 : I.agentName) ?? void 0, u = t.model ?? ((C = t.additionalKwargs) == null ? void 0 : C.model) ?? void 0, c = t.toolCallId ?? void 0, l = t.additionalKwargs ?? void 0, f = t.responseMetadata ?? void 0, m = t.checkpointId ?? ((T = t.additionalKwargs) == null ? void 0 : T.checkpointId) ?? void 0, h = t.checkpointNs ?? ((P = t.additionalKwargs) == null ? void 0 : P.checkpointNs) ?? void 0, k = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((b = t.additionalKwargs) != null && b.toolStreaming);
@@ -2474,7 +2474,7 @@ function tt(e) {
2474
2474
  }
2475
2475
  function Bn(e) {
2476
2476
  if (!e || typeof e != "object") return e;
2477
- const t = le(e);
2477
+ const t = de(e);
2478
2478
  if (t.tool && !t.name && (t.name = t.tool), t.type === "artifact.update" && t.artifact && typeof t.artifact == "object") {
2479
2479
  const n = t.artifact;
2480
2480
  !n.id && n.artifactId && (n.id = n.artifactId), !n.type && n.artifactType && (n.type = n.artifactType);
@@ -2482,7 +2482,7 @@ function Bn(e) {
2482
2482
  return t;
2483
2483
  }
2484
2484
  function nt(e) {
2485
- const t = le(e), n = t.content ?? t.output ?? void 0;
2485
+ const t = de(e), n = t.content ?? t.output ?? void 0;
2486
2486
  return {
2487
2487
  ...t,
2488
2488
  type: "tool_call",
@@ -2493,12 +2493,12 @@ function nt(e) {
2493
2493
  };
2494
2494
  }
2495
2495
  function $n(e, t) {
2496
- return typeof e == "string" ? [{ type: "text", text: e }] : Array.isArray(e) ? e.map((n) => typeof n == "string" ? { type: "text", text: n } : n.type === "tool_call" || n.type === "tool" ? t ? null : nt(le(n)) : n).filter(
2496
+ return typeof e == "string" ? [{ type: "text", text: e }] : Array.isArray(e) ? e.map((n) => typeof n == "string" ? { type: "text", text: n } : n.type === "tool_call" || n.type === "tool" ? t ? null : nt(de(n)) : n).filter(
2497
2497
  (n) => !!(n && typeof n == "object" && typeof n.type == "string")
2498
2498
  ) : [];
2499
2499
  }
2500
2500
  function Vn(e) {
2501
- const t = le(e), n = t.role;
2501
+ const t = de(e), n = t.role;
2502
2502
  if (n && (n === "assistant" || n === "user" || n === "system" || n === "tool" || n === "interrupt"))
2503
2503
  return n;
2504
2504
  const r = t.type;
@@ -2540,7 +2540,7 @@ function Kn(e, t = []) {
2540
2540
  var f, m, h;
2541
2541
  const i = Ge(a.id, e) || Ge(a.id, t), u = Array.isArray((f = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : f.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 = lt(a.status) ?? ((h = i == null ? void 0 : i.additionalKwargs) != null && h.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2542
2542
  if (i && !a.content && l === "completed") {
2543
- const k = ce(i);
2543
+ const k = ue(i);
2544
2544
  typeof k == "string" && (a.content = k);
2545
2545
  }
2546
2546
  return {
@@ -2558,7 +2558,7 @@ function Kn(e, t = []) {
2558
2558
  var u, c, l;
2559
2559
  const o = Ge(r.id, t) ?? Dn(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 = lt(r.status) ?? ((l = o == null ? void 0 : o.additionalKwargs) != null && l.toolStreaming ? "pending" : null) ?? (o ? "completed" : "pending");
2560
2560
  if (o && !r.content && i === "completed") {
2561
- const f = ce(o);
2561
+ const f = ue(o);
2562
2562
  typeof f == "string" && (r.content = f);
2563
2563
  }
2564
2564
  return {
@@ -2590,7 +2590,7 @@ const Xe = /* @__PURE__ */ new Set();
2590
2590
  function Et() {
2591
2591
  return De;
2592
2592
  }
2593
- function ke(e) {
2593
+ function Ie(e) {
2594
2594
  De = e, Xe.forEach((t) => t(e));
2595
2595
  }
2596
2596
  function Pt(e) {
@@ -2598,7 +2598,7 @@ function Pt(e) {
2598
2598
  }
2599
2599
  const Gn = 12e4, Hn = 12e4;
2600
2600
  let Qe = Gn, Nt = Hn;
2601
- const re = qt.create({
2601
+ const oe = qt.create({
2602
2602
  // BaseURL is set dynamically via ApiProvider -> api.updateConfig
2603
2603
  timeout: Qe,
2604
2604
  withCredentials: !0
@@ -2608,18 +2608,18 @@ function dt(e) {
2608
2608
  }
2609
2609
  function Wn(e) {
2610
2610
  const t = dt(e.requestTimeoutMs), n = dt(e.historyTimeoutMs);
2611
- t !== null && (Qe = t, re.defaults.timeout = Qe), n !== null && (Nt = n);
2611
+ t !== null && (Qe = t, oe.defaults.timeout = Qe), n !== null && (Nt = n);
2612
2612
  }
2613
2613
  function qn() {
2614
2614
  return Nt;
2615
2615
  }
2616
- re.interceptors.request.use((e) => (De && (e.headers.Authorization = `Bearer ${De}`), e));
2617
- re.interceptors.response.use(
2616
+ oe.interceptors.request.use((e) => (De && (e.headers.Authorization = `Bearer ${De}`), e));
2617
+ oe.interceptors.response.use(
2618
2618
  (e) => {
2619
2619
  if (typeof window < "u" && (e != null && e.data))
2620
2620
  try {
2621
2621
  const t = e.data, n = t.data || {}, r = typeof t.token == "string" && t.token || typeof n.token == "string" && n.token || null, o = typeof t.expires_at == "number" && t.expires_at || typeof n.expires_at == "number" && n.expires_at || typeof t.expiresAt == "number" && t.expiresAt || typeof n.expiresAt == "number" && n.expiresAt || null;
2622
- r && (localStorage.setItem(_e.authToken, r), ke(r)), o && localStorage.setItem(_e.authTokenExpiresAt, o.toString()), (r || o) && window.dispatchEvent(
2622
+ r && (localStorage.setItem(_e.authToken, r), Ie(r)), o && localStorage.setItem(_e.authTokenExpiresAt, o.toString()), (r || o) && window.dispatchEvent(
2623
2623
  new CustomEvent("smartorg:chat-token-updated", {
2624
2624
  detail: { token: r, expiresAt: o }
2625
2625
  })
@@ -2631,19 +2631,19 @@ re.interceptors.response.use(
2631
2631
  },
2632
2632
  (e) => Promise.reject(e)
2633
2633
  );
2634
- async function se(e, t) {
2635
- return re.defaults.baseURL ? (await re.get(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2634
+ async function ae(e, t) {
2635
+ return oe.defaults.baseURL ? (await oe.get(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2636
2636
  }
2637
2637
  async function Ye(e, t, n) {
2638
- return re.defaults.baseURL ? (await re.post(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2638
+ return oe.defaults.baseURL ? (await oe.post(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2639
2639
  }
2640
2640
  async function Jn(e, t, n) {
2641
- return re.defaults.baseURL ? (await re.put(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2641
+ return oe.defaults.baseURL ? (await oe.put(e, t, n)).data : Promise.reject(new Error("API base URL is not configured"));
2642
2642
  }
2643
2643
  async function Xn(e, t) {
2644
- return re.defaults.baseURL ? (await re.delete(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2644
+ return oe.defaults.baseURL ? (await oe.delete(e, t)).data : Promise.reject(new Error("API base URL is not configured"));
2645
2645
  }
2646
- function ae(e) {
2646
+ function ce(e) {
2647
2647
  return e && typeof e == "object" && "data" in e ? e.data : e;
2648
2648
  }
2649
2649
  class Qn {
@@ -2651,16 +2651,16 @@ class Qn {
2651
2651
  // Chat client uses the default httpClient baseURL, no need for internal tracking
2652
2652
  // unless we want to support multiple instances with different URLs in the future.
2653
2653
  get baseUrl() {
2654
- return re.defaults.baseURL || "";
2654
+ return oe.defaults.baseURL || "";
2655
2655
  }
2656
2656
  updateConfig(t) {
2657
2657
  if (t.chatBaseUrl)
2658
- re.defaults.baseURL = t.chatBaseUrl;
2658
+ oe.defaults.baseURL = t.chatBaseUrl;
2659
2659
  else if (t.baseUrl) {
2660
2660
  const n = t.baseUrl.replace(/\/+$/, "");
2661
- re.defaults.baseURL = n;
2661
+ oe.defaults.baseURL = n;
2662
2662
  }
2663
- t.apiKey !== void 0 ? ke(t.apiKey) : t.getToken && ke(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Wn({
2663
+ t.apiKey !== void 0 ? Ie(t.apiKey) : t.getToken && Ie(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Wn({
2664
2664
  requestTimeoutMs: t.requestTimeoutMs,
2665
2665
  historyTimeoutMs: t.historyTimeoutMs
2666
2666
  });
@@ -2670,14 +2670,14 @@ class Qn {
2670
2670
  return Et();
2671
2671
  }
2672
2672
  setAuthToken(t) {
2673
- ke(t);
2673
+ Ie(t);
2674
2674
  }
2675
2675
  onTokenChange(t) {
2676
2676
  return Pt(t);
2677
2677
  }
2678
2678
  // ---- Thread Management ----
2679
2679
  async listThreads() {
2680
- const t = await se("/threads"), n = ae(t);
2680
+ const t = await ae("/threads"), n = ce(t);
2681
2681
  return (n == null ? void 0 : n.items) ?? (t == null ? void 0 : t.items) ?? [];
2682
2682
  }
2683
2683
  // listUsers moved to AuthApi
@@ -2685,44 +2685,44 @@ class Qn {
2685
2685
  const r = {};
2686
2686
  t && (r.title = t), n && (r.project = n);
2687
2687
  const o = await Ye("/threads", Object.keys(r).length ? r : void 0);
2688
- return ae(o);
2688
+ return ce(o);
2689
2689
  }
2690
2690
  async updateThread(t, n) {
2691
2691
  const r = await Jn(`/threads/${t}`, { title: n });
2692
- return ae(r);
2692
+ return ce(r);
2693
2693
  }
2694
2694
  async deleteThread(t) {
2695
2695
  const n = await Xn(`/threads/${t}`);
2696
- return ae(n);
2696
+ return ce(n);
2697
2697
  }
2698
2698
  async threadInfo(t) {
2699
- const n = await se(`/threads/${t}/info`);
2700
- return ae(n);
2699
+ const n = await ae(`/threads/${t}/info`);
2700
+ return ce(n);
2701
2701
  }
2702
2702
  // ---- Agents ----
2703
2703
  async listAgents() {
2704
- const t = await se("/agents"), n = ae(t);
2704
+ const t = await ae("/agents"), n = ce(t);
2705
2705
  return (n == null ? void 0 : n.items) ?? [];
2706
2706
  }
2707
2707
  async getAgent(t) {
2708
- const n = await se(`/agents/${t}`);
2709
- return ae(n);
2708
+ const n = await ae(`/agents/${t}`);
2709
+ return ce(n);
2710
2710
  }
2711
2711
  async getAgentSchema(t) {
2712
- const n = await se(`/agents/${t}/schema`);
2713
- return ae(n);
2712
+ const n = await ae(`/agents/${t}/schema`);
2713
+ return ce(n);
2714
2714
  }
2715
2715
  async getState(t) {
2716
- const n = await se(`/threads/${t.threadId}/state`, {
2716
+ const n = await ae(`/threads/${t.threadId}/state`, {
2717
2717
  params: {
2718
2718
  checkpoint_id: t.checkpointId,
2719
2719
  checkpoint_ns: t.checkpointNs
2720
2720
  }
2721
2721
  });
2722
- return ae(n);
2722
+ return ce(n);
2723
2723
  }
2724
2724
  async getStateHistory(t) {
2725
- const n = await se(`/threads/${t.threadId}/state/history`, {
2725
+ const n = await ae(`/threads/${t.threadId}/state/history`, {
2726
2726
  params: {
2727
2727
  checkpoint_id: t.checkpointId,
2728
2728
  checkpoint_ns: t.checkpointNs,
@@ -2733,12 +2733,12 @@ class Qn {
2733
2733
  timeout: qn(),
2734
2734
  signal: t.signal
2735
2735
  });
2736
- return ae(n);
2736
+ return ce(n);
2737
2737
  }
2738
2738
  // ---- Run Management ----
2739
2739
  async cancelRun(t) {
2740
2740
  const n = await Ye(`/runs/${t}/cancel`);
2741
- return ae(n);
2741
+ return ce(n);
2742
2742
  }
2743
2743
  }
2744
2744
  const _t = new Qn();
@@ -2746,7 +2746,7 @@ class Yn {
2746
2746
  // Config logic could go here if files ever need a distinct base URL from chat
2747
2747
  // For now, it shares the chatBaseUrl via the shared httpClient
2748
2748
  async fetchFileBlob(t, n) {
2749
- return await se(t, {
2749
+ return await ae(t, {
2750
2750
  responseType: "blob",
2751
2751
  onDownloadProgress: (o) => {
2752
2752
  try {
@@ -2775,7 +2775,7 @@ class Yn {
2775
2775
  const r = await this.fetchFileBlob(`/files/${t}/download`, n), o = URL.createObjectURL(r);
2776
2776
  let s = `file_${t}`;
2777
2777
  try {
2778
- const i = await se(`/files/${t}`);
2778
+ const i = await ae(`/files/${t}`);
2779
2779
  s = (i == null ? void 0 : i.filename) ?? s;
2780
2780
  } catch {
2781
2781
  }
@@ -2783,11 +2783,11 @@ class Yn {
2783
2783
  a.href = o, a.download = s, document.body.appendChild(a), a.click(), a.remove(), setTimeout(() => URL.revokeObjectURL(o), 6e4);
2784
2784
  }
2785
2785
  async getFileInfo(t) {
2786
- return await se(`/files/${t}`);
2786
+ return await ae(`/files/${t}`);
2787
2787
  }
2788
2788
  async listFiles(t, n = 50, r = 0) {
2789
2789
  const o = { limit: n, offset: r };
2790
- return t && (o.thread_id = t), await se("/files", { params: o });
2790
+ return t && (o.thread_id = t), await ae("/files", { params: o });
2791
2791
  }
2792
2792
  async uploadFile(t, n, r) {
2793
2793
  const o = new FormData();
@@ -2820,21 +2820,21 @@ class Zn {
2820
2820
  const n = t.baseUrl.replace(/\/+$/, "");
2821
2821
  this._authBaseUrl = `${n}/auth`;
2822
2822
  }
2823
- t.apiKey !== void 0 ? ke(t.apiKey) : t.getToken && ke(t.getToken());
2823
+ t.apiKey !== void 0 ? Ie(t.apiKey) : t.getToken && Ie(t.getToken());
2824
2824
  }
2825
2825
  // ---- Token Management ----
2826
2826
  getAuthToken() {
2827
2827
  return Et();
2828
2828
  }
2829
2829
  setAuthToken(t) {
2830
- ke(t);
2830
+ Ie(t);
2831
2831
  }
2832
2832
  onTokenChange(t) {
2833
2833
  return Pt(t);
2834
2834
  }
2835
2835
  // ---- User Management ----
2836
2836
  async listUsers() {
2837
- const t = await se("/users", { baseURL: this.baseUrl });
2837
+ const t = await ae("/users", { baseURL: this.baseUrl });
2838
2838
  return (t == null ? void 0 : t.users) ?? [];
2839
2839
  }
2840
2840
  }
@@ -2855,7 +2855,7 @@ function tr({ children: e, apiConfig: t }) {
2855
2855
  fileApi: zt,
2856
2856
  baseUrl: n.baseUrl
2857
2857
  };
2858
- return /* @__PURE__ */ ie(Rt.Provider, { value: o, children: e });
2858
+ return /* @__PURE__ */ le(Rt.Provider, { value: o, children: e });
2859
2859
  }
2860
2860
  async function nr(e) {
2861
2861
  return await new Promise((t, n) => {
@@ -2930,7 +2930,7 @@ function oo(e) {
2930
2930
  }).join("|") : "", r = "checkpointId" in e && e.checkpointId ? `cp:${e.checkpointId}` : "", o = "checkpointNs" in e && e.checkpointNs ? `ns:${e.checkpointNs}` : "", s = [r, o].filter(Boolean).join("|");
2931
2931
  return `${e.id}:${t}:${n}${s ? `:${s}` : ""}`;
2932
2932
  }
2933
- function Ae() {
2933
+ function xe() {
2934
2934
  const e = Ue(Rt);
2935
2935
  if (!e) throw new Error("useApi must be used within ApiProvider");
2936
2936
  return e;
@@ -2957,10 +2957,10 @@ function cr(e = {}) {
2957
2957
  i.current = e;
2958
2958
  }, [e]);
2959
2959
  const u = z((p) => {
2960
- var U, M, E, j, N, B, O, L, F, W;
2960
+ var U, M, E, j, N, B, O, F, L, W;
2961
2961
  const w = i.current;
2962
2962
  if (!w) return;
2963
- (U = w.onEvent) == null || U.call(w, p), p.type === "thread_info" && ((M = w.onThreadInfo) == null || M.call(w, p)), p.type === "values" && Array.isArray(p.checkpoints) && ((E = w.handleValuesEvent) == null || E.call(w, p)), p.type === "metadata" && ((j = w.onMetadataEvent) == null || j.call(w, p)), typeof p.type == "string" && (p.type === "custom" || p.type.startsWith("custom.")) && ((N = w.onCustomEvent) == null || N.call(w, p)), p.type === "updates" && ((B = w.onUpdateEvent) == null || B.call(w, p)), p.type === "tool.end" ? (O = w.onToolEnd) == null || O.call(w, p) : p.type === "tool.start" && ((L = w.onToolStart) == null || L.call(w, p)), p.type === "heartbeat" && ((F = w.onHeartbeat) == null || F.call(w, p)), p.type === "token" && ((W = w.onToken) == null || W.call(w, p.token));
2963
+ (U = w.onEvent) == null || U.call(w, p), p.type === "thread_info" && ((M = w.onThreadInfo) == null || M.call(w, p)), p.type === "values" && Array.isArray(p.checkpoints) && ((E = w.handleValuesEvent) == null || E.call(w, p)), p.type === "metadata" && ((j = w.onMetadataEvent) == null || j.call(w, p)), typeof p.type == "string" && (p.type === "custom" || p.type.startsWith("custom.")) && ((N = w.onCustomEvent) == null || N.call(w, p)), p.type === "updates" && ((B = w.onUpdateEvent) == null || B.call(w, p)), p.type === "tool.end" ? (O = w.onToolEnd) == null || O.call(w, p) : p.type === "tool.start" && ((F = w.onToolStart) == null || F.call(w, p)), p.type === "heartbeat" && ((L = w.onHeartbeat) == null || L.call(w, p)), p.type === "token" && ((W = w.onToken) == null || W.call(w, p.token));
2964
2964
  }, []), [c, l] = V(!1), [f, m] = V(null), [h, k] = V(!1), [d, v] = V(null), I = K(null), C = K(!0), T = K(null), P = z((p) => {
2965
2965
  o(p);
2966
2966
  }, []), b = z(() => {
@@ -2975,7 +2975,7 @@ function cr(e = {}) {
2975
2975
  (w || p ? _t.cancelRun(w || p).catch((j) => {
2976
2976
  console.warn("[use-chat] cancel run failed:", j);
2977
2977
  }) : Promise.resolve()).finally(_);
2978
- }, []), x = z(
2978
+ }, []), A = z(
2979
2979
  (p) => {
2980
2980
  I.current && (I.current.abort(), I.current = null);
2981
2981
  const w = {
@@ -3000,22 +3000,22 @@ function cr(e = {}) {
3000
3000
  headers: {},
3001
3001
  isStreaming: !0
3002
3002
  }, (async () => {
3003
- var E, j, N, B, O, L;
3003
+ var E, j, N, B, O, F;
3004
3004
  try {
3005
- let F = {};
3005
+ let L = {};
3006
3006
  try {
3007
3007
  if (r)
3008
- F = { Authorization: `Bearer ${r}` };
3008
+ L = { Authorization: `Bearer ${r}` };
3009
3009
  else if (typeof window < "u") {
3010
- const te = window.__AUTH_TOKEN__, ve = ((E = window.localStorage) == null ? void 0 : E.getItem(_e.authToken)) || null;
3010
+ const re = window.__AUTH_TOKEN__, ve = ((E = window.localStorage) == null ? void 0 : E.getItem(_e.authToken)) || null;
3011
3011
  let X = null;
3012
3012
  try {
3013
- const me = (j = window.localStorage) == null ? void 0 : j.getItem(_e.chatSettings);
3014
- me && (X = ((N = JSON.parse(me)) == null ? void 0 : N.apiKey) || null);
3013
+ const he = (j = window.localStorage) == null ? void 0 : j.getItem(_e.chatSettings);
3014
+ he && (X = ((N = JSON.parse(he)) == null ? void 0 : N.apiKey) || null);
3015
3015
  } catch {
3016
3016
  }
3017
- const Z = te || ve || X || null;
3018
- Z && (F = { Authorization: `Bearer ${Z}` });
3017
+ const ee = re || ve || X || null;
3018
+ ee && (L = { Authorization: `Bearer ${ee}` });
3019
3019
  }
3020
3020
  } catch {
3021
3021
  }
@@ -3027,92 +3027,108 @@ function cr(e = {}) {
3027
3027
  H && (W = { "X-Session-Id": H });
3028
3028
  } catch {
3029
3029
  }
3030
- const Y = {
3031
- ...F,
3030
+ const Z = {
3031
+ ...L,
3032
3032
  ...W,
3033
3033
  ...s.current
3034
3034
  }, g = {
3035
3035
  "Content-Type": "application/json",
3036
3036
  Accept: "text/event-stream",
3037
- ...Y
3038
- }, A = await fetch(t + n, {
3037
+ ...Z
3038
+ }, x = await fetch(t + n, {
3039
3039
  method: "POST",
3040
3040
  headers: g,
3041
3041
  body: JSON.stringify(w),
3042
3042
  signal: _.signal,
3043
3043
  credentials: a
3044
3044
  });
3045
- if (T.current && (T.current.headers = Y), !A.ok || !A.body) {
3046
- const H = await A.text().catch(() => "");
3045
+ if (T.current && (T.current.headers = Z), !x.ok || !x.body) {
3046
+ const H = await x.text().catch(() => "");
3047
3047
  console.debug(
3048
3048
  "[use-chat] non-OK response",
3049
- A.status,
3049
+ x.status,
3050
3050
  H == null ? void 0 : H.slice(0, 500)
3051
3051
  );
3052
- const te = `stream ${A.status}${H ? ": " + H : ""}`;
3053
- throw te && (m(te), U = "error"), new Error(te);
3052
+ const re = `stream ${x.status}${H ? ": " + H : ""}`;
3053
+ throw re && (m(re), U = "error"), new Error(re);
3054
3054
  }
3055
3055
  k(!0);
3056
- const S = A.body.getReader(), G = new TextDecoder();
3057
- let J = "", D = 0, ee = Date.now();
3058
- const oe = setInterval(() => {
3059
- Date.now() - ee > 18e5 && (m("Stream idle timeout"), U = "error", _.abort());
3060
- }, 5e3), ue = 1024 * 1024;
3056
+ const S = x.body.getReader(), G = new TextDecoder();
3057
+ let J = "", D = 0, ne = Date.now();
3058
+ const se = setInterval(() => {
3059
+ Date.now() - ne > 18e5 && (m("Stream idle timeout"), U = "error", _.abort());
3060
+ }, 5e3), fe = 1024 * 1024;
3061
3061
  try {
3062
- const H = A.headers.get("X-Thread-Id") || A.headers.get("x-thread-id"), te = A.headers.get("X-Run-Id") || A.headers.get("x-run-id");
3062
+ const H = x.headers.get("X-Thread-Id") || x.headers.get("x-thread-id"), re = x.headers.get("X-Run-Id") || x.headers.get("x-run-id");
3063
3063
  for (T.current && (T.current = {
3064
3064
  ...T.current,
3065
3065
  threadId: H ?? T.current.threadId,
3066
- runId: te ?? T.current.runId
3066
+ runId: re ?? T.current.runId
3067
3067
  }); ; ) {
3068
3068
  const { value: ve, done: X } = await S.read();
3069
3069
  if (X) break;
3070
- J += G.decode(ve, { stream: !0 }), J.length > ue && (J = "", console.warn("Stream buffer reset: exceeded 1MB"));
3071
- let Z;
3072
- for (; (Z = J.indexOf(`
3070
+ J += G.decode(ve, { stream: !0 }), J.length > fe && (J = "", console.warn("Stream buffer reset: exceeded 1MB"));
3071
+ let ee;
3072
+ for (; (ee = J.indexOf(`
3073
3073
 
3074
3074
  `)) >= 0; ) {
3075
- const me = J.slice(0, Z);
3076
- J = J.slice(Z + 2);
3077
- const je = me.split(/\r?\n/), Le = [];
3078
- let de = null;
3079
- for (const ye of je)
3080
- if (!ye.startsWith(":") && ye) {
3081
- if (ye.startsWith("event:")) {
3082
- const Te = ye.slice(6).trim();
3083
- Te && (de = Te);
3075
+ const he = J.slice(0, ee);
3076
+ J = J.slice(ee + 2);
3077
+ const je = he.split(/\r?\n/), Fe = [];
3078
+ let ie = null;
3079
+ for (const Q of je)
3080
+ if (!Q.startsWith(":") && Q) {
3081
+ if (Q.startsWith("event:")) {
3082
+ const ke = Q.slice(6).trim();
3083
+ ke && (ie = ke);
3084
3084
  continue;
3085
3085
  }
3086
- if (ye.startsWith("data:")) {
3087
- const Te = ye.slice(5);
3088
- Le.push(Te.startsWith(" ") ? Te.slice(1) : Te);
3086
+ if (Q.startsWith("data:")) {
3087
+ const ke = Q.slice(5);
3088
+ Fe.push(ke.startsWith(" ") ? ke.slice(1) : ke);
3089
3089
  }
3090
3090
  }
3091
- const Ie = Le.join(`
3091
+ const Te = Fe.join(`
3092
3092
  `);
3093
- if (!Ie) continue;
3094
- let ne;
3093
+ if (!Te) continue;
3094
+ let te;
3095
3095
  try {
3096
- ne = JSON.parse(Ie);
3096
+ te = JSON.parse(Te);
3097
3097
  } catch {
3098
- console.debug("[use-chat] malformed SSE:", Ie.slice(0, 200));
3098
+ console.debug("[use-chat] malformed SSE:", Te.slice(0, 200));
3099
3099
  continue;
3100
3100
  }
3101
- de && typeof ne == "object" && ne !== null && !("type" in ne) && (ne.type = de);
3102
- const Me = ir(ne) ? ne.data : ne;
3101
+ if (ie && typeof te == "object" && te !== null)
3102
+ if (ie === "messages/partial" && Array.isArray(te))
3103
+ te = {
3104
+ type: "messages/partial",
3105
+ messages: te
3106
+ };
3107
+ else {
3108
+ const Q = te;
3109
+ "type" in Q ? ie === "messages/partial" && (Q.type === "ai" || Q.type === "assistant" || Q.role === "assistant") && (te = {
3110
+ type: "messages/partial",
3111
+ messages: [Q],
3112
+ // Preserve common meta fields if present.
3113
+ seq: Q.seq,
3114
+ scope: Q.scope,
3115
+ origin: Q.origin
3116
+ }) : Q.type = ie;
3117
+ }
3118
+ const Me = ir(te) ? te.data : te;
3103
3119
  if (!Me) {
3104
- console.warn("[use-chat] dropped envelope event without payload", ne);
3120
+ console.warn("[use-chat] dropped envelope event without payload", te);
3105
3121
  continue;
3106
3122
  }
3107
3123
  const Ee = Bn(Me);
3108
- ee = Date.now();
3109
- const he = Ee.seq;
3110
- if (he !== void 0) {
3111
- if (he <= D) {
3112
- console.debug("[use-chat] drop duplicate/out-of-order event", { seq: he, lastProcessedSeq: D, type: Ee.type });
3124
+ ne = Date.now();
3125
+ const ye = Ee.seq;
3126
+ if (ye !== void 0) {
3127
+ if (ye <= D) {
3128
+ console.debug("[use-chat] drop duplicate/out-of-order event", { seq: ye, lastProcessedSeq: D, type: Ee.type });
3113
3129
  continue;
3114
3130
  }
3115
- D = he;
3131
+ D = ye;
3116
3132
  }
3117
3133
  u(Ee);
3118
3134
  }
@@ -3122,8 +3138,8 @@ function cr(e = {}) {
3122
3138
  if (H.name === "AbortError")
3123
3139
  U = U ?? "aborted";
3124
3140
  else {
3125
- const te = H.message || String(H);
3126
- U = "error", m(te);
3141
+ const re = H.message || String(H);
3142
+ U = "error", m(re);
3127
3143
  }
3128
3144
  } finally {
3129
3145
  try {
@@ -3132,29 +3148,29 @@ function cr(e = {}) {
3132
3148
  } finally {
3133
3149
  (O = S.releaseLock) == null || O.call(S);
3134
3150
  }
3135
- clearInterval(oe);
3151
+ clearInterval(se);
3136
3152
  }
3137
- } catch (F) {
3138
- if (F.name === "AbortError")
3153
+ } catch (L) {
3154
+ if (L.name === "AbortError")
3139
3155
  U = U ?? "aborted";
3140
3156
  else {
3141
- const W = F.message || String(F);
3142
- U = "error", m(W), M || (M = !0, (L = e.onConnectionError) == null || L.call(e, W));
3157
+ const W = L.message || String(L);
3158
+ U = "error", m(W), M || (M = !0, (F = e.onConnectionError) == null || F.call(e, W));
3143
3159
  }
3144
3160
  } finally {
3145
3161
  try {
3146
3162
  if (e.onFinish) {
3147
- const F = {
3163
+ const L = {
3148
3164
  lastSeq: 0,
3149
3165
  lastCheckpointId: null,
3150
3166
  lastCheckpointNs: null,
3151
3167
  lastValues: null
3152
3168
  // Let the reducer/history hook provide the final values
3153
3169
  };
3154
- e.onFinish(F);
3170
+ e.onFinish(L);
3155
3171
  }
3156
- } catch (F) {
3157
- console.warn("[use-chat] onClosed callback failed", F);
3172
+ } catch (L) {
3173
+ console.warn("[use-chat] onClosed callback failed", L);
3158
3174
  }
3159
3175
  l(!1), k(!1), I.current = null, T.current = null;
3160
3176
  }
@@ -3177,7 +3193,7 @@ function cr(e = {}) {
3177
3193
  // Deprecated: use checkpoint from reducer
3178
3194
  lastSeq: 0,
3179
3195
  connected: h,
3180
- stream: x,
3196
+ stream: A,
3181
3197
  stop: y,
3182
3198
  clear: b,
3183
3199
  setToken: P,
@@ -3189,7 +3205,7 @@ function cr(e = {}) {
3189
3205
  connectionState: f ? "error" : c ? h ? "connected" : "connecting" : "idle",
3190
3206
  messages: [],
3191
3207
  // useStream doesn't maintain messages, use useChatSession instead
3192
- submit: x
3208
+ submit: A
3193
3209
  };
3194
3210
  }
3195
3211
  function lr({
@@ -3225,10 +3241,10 @@ function lr({
3225
3241
  const v = z(
3226
3242
  async (b, y) => {
3227
3243
  try {
3228
- const x = y && typeof y == "object" ? { id: y.id, name: y.name ?? "" } : void 0, p = await e.createThread(b, x);
3244
+ const A = y && typeof y == "object" ? { id: y.id, name: y.name ?? "" } : void 0, p = await e.createThread(b, A);
3229
3245
  return u(p.threadId), await d(), p.threadId;
3230
- } catch (x) {
3231
- const p = String(x);
3246
+ } catch (A) {
3247
+ const p = String(A);
3232
3248
  return n == null || n(p), null;
3233
3249
  }
3234
3250
  },
@@ -3237,8 +3253,8 @@ function lr({
3237
3253
  async (b) => {
3238
3254
  const y = s;
3239
3255
  a((p) => p.filter((w) => w.threadId !== b));
3240
- const x = new AbortController();
3241
- k.current.set(b, x);
3256
+ const A = new AbortController();
3257
+ k.current.set(b, A);
3242
3258
  try {
3243
3259
  await e.deleteThread(b), h.current === b && (u(null), o == null || o());
3244
3260
  } catch (p) {
@@ -3254,12 +3270,12 @@ function lr({
3254
3270
  async (b, y) => {
3255
3271
  try {
3256
3272
  await e.updateThread(b, y), await d();
3257
- } catch (x) {
3258
- n == null || n(String(x));
3273
+ } catch (A) {
3274
+ n == null || n(String(A));
3259
3275
  }
3260
3276
  },
3261
3277
  [e, n, d]
3262
- ), T = Q(
3278
+ ), T = Y(
3263
3279
  () => ({
3264
3280
  createThread: v,
3265
3281
  deleteThread: I,
@@ -3277,16 +3293,16 @@ function lr({
3277
3293
  updatedAt: b.updatedAt || (/* @__PURE__ */ new Date()).toISOString(),
3278
3294
  messageCount: b.messageCount ?? 1
3279
3295
  };
3280
- a((x) => {
3296
+ a((A) => {
3281
3297
  let p = !1;
3282
- const w = x.map((_) => _.threadId === y.threadId ? (p = !0, console.debug("[useThreadsState] thread_info: updating existing thread", y.threadId), {
3298
+ const w = A.map((_) => _.threadId === y.threadId ? (p = !0, console.debug("[useThreadsState] thread_info: updating existing thread", y.threadId), {
3283
3299
  ..._,
3284
3300
  title: y.title ?? _.title,
3285
3301
  project: y.project ?? _.project,
3286
3302
  updatedAt: y.updatedAt ?? _.updatedAt,
3287
3303
  messageCount: y.messageCount ?? _.messageCount
3288
3304
  }) : _);
3289
- return p ? w : (console.debug("[useThreadsState] thread_info: adding thread to list", y.threadId), [y, ...x]);
3305
+ return p ? w : (console.debug("[useThreadsState] thread_info: adding thread to list", y.threadId), [y, ...A]);
3290
3306
  });
3291
3307
  }, []);
3292
3308
  return {
@@ -3307,7 +3323,7 @@ function ur({
3307
3323
  onError: n,
3308
3324
  onThreadChange: r
3309
3325
  }) {
3310
- const { chatApi: o } = Ae(), {
3326
+ const { chatApi: o } = xe(), {
3311
3327
  threads: s,
3312
3328
  currentThreadId: a,
3313
3329
  setCurrentThreadId: i,
@@ -3321,7 +3337,7 @@ function ur({
3321
3337
  initialThreadId: t,
3322
3338
  onError: n,
3323
3339
  onThreadChange: r
3324
- }), h = Q(
3340
+ }), h = Y(
3325
3341
  () => ({
3326
3342
  threads: s,
3327
3343
  currentThreadId: a,
@@ -3343,14 +3359,14 @@ function ur({
3343
3359
  m
3344
3360
  ]
3345
3361
  );
3346
- return /* @__PURE__ */ ie(jt.Provider, { value: h, children: e });
3362
+ return /* @__PURE__ */ le(jt.Provider, { value: h, children: e });
3347
3363
  }
3348
3364
  function rt(e) {
3349
3365
  const t = Ue(jt);
3350
3366
  if (!t && !(e != null && e.optional)) throw new Error("useThreads must be used within a ThreadsProvider");
3351
3367
  return t;
3352
3368
  }
3353
- function Lt(e) {
3369
+ function Ft(e) {
3354
3370
  const t = e.artifact;
3355
3371
  return !t || typeof t != "object" ? null : "metadata" in t && t.metadata ? t.metadata : {
3356
3372
  id: t.id ?? e.id ?? `artifact-${Date.now()}`,
@@ -3361,7 +3377,7 @@ function Lt(e) {
3361
3377
  };
3362
3378
  }
3363
3379
  function dr(e, t) {
3364
- const n = Lt(e);
3380
+ const n = Ft(e);
3365
3381
  if (!n) return e;
3366
3382
  const r = {
3367
3383
  ...n,
@@ -3378,21 +3394,21 @@ function dr(e, t) {
3378
3394
  }
3379
3395
  function fr(e, t, n) {
3380
3396
  return e.find((r) => {
3381
- const o = Lt(r);
3397
+ const o = Ft(r);
3382
3398
  return !!((o == null ? void 0 : o.id) === t || n && r.toolCallId === n);
3383
3399
  }) ?? null;
3384
3400
  }
3385
3401
  function Oe(e) {
3386
3402
  return e.map((t) => tt(t)).filter((t) => !!t);
3387
3403
  }
3388
- function Ft(e, t, n) {
3404
+ function Lt(e, t, n) {
3389
3405
  return t < 0 || t >= e.length ? e : [...e.slice(0, t), n, ...e.slice(t + 1)];
3390
3406
  }
3391
3407
  function pr(e, t, n) {
3392
3408
  for (let r = e.length - 1; r >= 0; r--)
3393
3409
  if (e[r].role === "assistant") {
3394
3410
  const s = { ...e[r], checkpointId: t, checkpointNs: n ?? void 0 };
3395
- return Ft(e, r, s);
3411
+ return Lt(e, r, s);
3396
3412
  }
3397
3413
  return e;
3398
3414
  }
@@ -3470,7 +3486,7 @@ function mr(e = []) {
3470
3486
  typeof window < "u" && typeof window.requestAnimationFrame == "function" ? o.current === null && (o.current = window.requestAnimationFrame(() => s())) : setTimeout(s, 8);
3471
3487
  }, [s]), i = z((c) => {
3472
3488
  r.current.push(c), a();
3473
- }, [a]), u = Q(() => ({
3489
+ }, [a]), u = Y(() => ({
3474
3490
  setStatus: (c, l) => n({ type: "status", payload: { status: c, error: l } }),
3475
3491
  reset: (c) => n({ type: "reset", payload: { messages: c } }),
3476
3492
  seed: (c, l) => n({ type: "seed", payload: { messages: c, ...l ?? {} } }),
@@ -3588,7 +3604,7 @@ function br(e, t) {
3588
3604
  let r = [...e.messages];
3589
3605
  const o = ot(r, n);
3590
3606
  if (o !== -1) {
3591
- const s = r[o], a = ce(t.content), i = (s.toolCalls || []).map(
3607
+ const s = r[o], a = ue(t.content), i = (s.toolCalls || []).map(
3592
3608
  (u) => u.id === n ? { ...u, content: typeof a == "string" ? a : u.content } : u
3593
3609
  );
3594
3610
  r[o] = { ...s, toolCalls: i };
@@ -3599,7 +3615,7 @@ function wr(e, t) {
3599
3615
  const n = t.id;
3600
3616
  if (!n) return e;
3601
3617
  let r = [...e.messages];
3602
- const o = ot(r, n), s = ce(t.content ?? t.error);
3618
+ const o = ot(r, n), s = ue(t.content ?? t.error);
3603
3619
  if (o !== -1) {
3604
3620
  const i = r[o], u = (i.toolCalls || []).map(
3605
3621
  (c) => c.id === n ? {
@@ -3630,13 +3646,13 @@ function vr(e, t) {
3630
3646
  progress: t.progress,
3631
3647
  error: t.error
3632
3648
  });
3633
- return t.partial_data && s.artifact && (s.artifact = { ...s.artifact, ...t.partial_data }), { ...e, messages: Ft(e.messages, o, s) };
3649
+ return t.partial_data && s.artifact && (s.artifact = { ...s.artifact, ...t.partial_data }), { ...e, messages: Lt(e.messages, o, s) };
3634
3650
  }
3635
3651
  function ze(e) {
3636
3652
  if (!(!e || typeof e != "object" || Array.isArray(e)))
3637
3653
  return { ...e };
3638
3654
  }
3639
- function Fe(e, t) {
3655
+ function Le(e, t) {
3640
3656
  if (e)
3641
3657
  for (const n of t) {
3642
3658
  const r = e[n];
@@ -3661,7 +3677,7 @@ function pt(e) {
3661
3677
  async function Ir(e, t) {
3662
3678
  var i, u;
3663
3679
  if (!e) return e ?? null;
3664
- const n = le(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], o = /* @__PURE__ */ new Set();
3680
+ const n = de(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], o = /* @__PURE__ */ new Set();
3665
3681
  for (const c of r) {
3666
3682
  const l = (i = c == null ? void 0 : c.values) == null ? void 0 : i.messages;
3667
3683
  if (Array.isArray(l))
@@ -3680,7 +3696,7 @@ async function Ir(e, t) {
3680
3696
  const s = await Promise.all(
3681
3697
  Array.from(o).map(async (c) => {
3682
3698
  try {
3683
- const l = await t.getFileInfo(c), f = le(l);
3699
+ const l = await t.getFileInfo(c), f = de(l);
3684
3700
  return [c, f];
3685
3701
  } catch {
3686
3702
  return [c, null];
@@ -3705,7 +3721,7 @@ async function Ir(e, t) {
3705
3721
  return n;
3706
3722
  }
3707
3723
  function gt(e) {
3708
- const r = [...(Array.isArray(e == null ? void 0 : e.checkpoints) ? (e == null ? void 0 : e.checkpoints) ?? [] : e != null && e.checkpoints ? Object.values(e.checkpoints) : []).map((s, a) => Tr(le(s), a)).filter((s) => !!s)].sort((s, a) => mt(a.createdAt) - mt(s.createdAt)), o = r[0] ?? null;
3724
+ const r = [...(Array.isArray(e == null ? void 0 : e.checkpoints) ? (e == null ? void 0 : e.checkpoints) ?? [] : e != null && e.checkpoints ? Object.values(e.checkpoints) : []).map((s, a) => Tr(de(s), a)).filter((s) => !!s)].sort((s, a) => mt(a.createdAt) - mt(s.createdAt)), o = r[0] ?? null;
3709
3725
  return {
3710
3726
  threadId: (e == null ? void 0 : e.threadId) ?? "",
3711
3727
  latest: o,
@@ -3716,14 +3732,14 @@ function gt(e) {
3716
3732
  function Tr(e, t) {
3717
3733
  var b, y;
3718
3734
  if (!e) return null;
3719
- const n = ((b = e.values) == null ? void 0 : b.activeAgent) ?? null, r = (y = e.values) == null ? void 0 : y.messages, s = (Array.isArray(r) ? r : []).map((x) => xr(x, n)).filter((x) => !!x), a = ze(e.metadata) ?? {}, i = pt(e.config), u = ze(e.parentConfig), c = pt(u), l = Fe(i, ["checkpointId"]), f = Fe(i, ["checkpointNs"]), m = Fe(c, ["checkpointId"]), h = ze(e.config), k = Array.isArray(e.tasks) ? e.tasks.map((x) => ({ ...x })) : e.tasks ?? null, d = Array.isArray(e.next) ? [...e.next] : e.next ?? null, v = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), I = {
3735
+ const n = ((b = e.values) == null ? void 0 : b.activeAgent) ?? null, r = (y = e.values) == null ? void 0 : y.messages, s = (Array.isArray(r) ? r : []).map((A) => Ar(A, n)).filter((A) => !!A), a = ze(e.metadata) ?? {}, i = pt(e.config), u = ze(e.parentConfig), c = pt(u), l = Le(i, ["checkpointId"]), f = Le(i, ["checkpointNs"]), m = Le(c, ["checkpointId"]), h = ze(e.config), k = Array.isArray(e.tasks) ? e.tasks.map((A) => ({ ...A })) : e.tasks ?? null, d = Array.isArray(e.next) ? [...e.next] : e.next ?? null, v = typeof e.createdAt == "string" && e.createdAt.trim() ? e.createdAt : new Date(Date.now() - t).toISOString(), I = {
3720
3736
  ...a,
3721
3737
  step: kr(a, ["step"]) ?? 0,
3722
- source: Fe(a, ["source"]) ?? null
3723
- }, C = s.map((x) => ({
3724
- ...x,
3725
- checkpointId: x.checkpointId ?? l ?? null,
3726
- checkpointNs: x.checkpointNs ?? f ?? null
3738
+ source: Le(a, ["source"]) ?? null
3739
+ }, C = s.map((A) => ({
3740
+ ...A,
3741
+ checkpointId: A.checkpointId ?? l ?? null,
3742
+ checkpointNs: A.checkpointNs ?? f ?? null
3727
3743
  })), T = e.values, P = Array.isArray(e.interrupts) ? e.interrupts : Array.isArray(T == null ? void 0 : T.interrupts) ? T.interrupts : [];
3728
3744
  return {
3729
3745
  checkpointId: l ?? null,
@@ -3731,7 +3747,7 @@ function Tr(e, t) {
3731
3747
  createdAt: v,
3732
3748
  parentId: m ?? null,
3733
3749
  messages: C,
3734
- interrupt: Ar(
3750
+ interrupt: xr(
3735
3751
  P,
3736
3752
  t,
3737
3753
  l ?? null
@@ -3744,11 +3760,11 @@ function Tr(e, t) {
3744
3760
  values: e.values ?? {}
3745
3761
  };
3746
3762
  }
3747
- function xr(e, t) {
3763
+ function Ar(e, t) {
3748
3764
  const n = tt(e);
3749
3765
  return n ? (n.role === "assistant" && !n.name && t && (n.name = t), n) : null;
3750
3766
  }
3751
- function Ar(e, t, n) {
3767
+ function xr(e, t, n) {
3752
3768
  const r = e.length;
3753
3769
  for (let o = r - 1; o >= 0; o -= 1) {
3754
3770
  const s = e[o];
@@ -3873,7 +3889,7 @@ function so(e, t, n) {
3873
3889
  };
3874
3890
  }
3875
3891
  function Er(e) {
3876
- return Q(() => Mr(e), [e]);
3892
+ return Y(() => Mr(e), [e]);
3877
3893
  }
3878
3894
  function Bt({
3879
3895
  api: e,
@@ -3885,14 +3901,14 @@ function Bt({
3885
3901
  isStreaming: a,
3886
3902
  getMessages: i
3887
3903
  }) {
3888
- const [u, c] = V(null), f = Q(
3904
+ const [u, c] = V(null), f = Y(
3889
3905
  () => gt(u),
3890
3906
  [u]
3891
3907
  ).checkpoints, m = Er(f), h = m.timeline, [k, d] = V(!1), [v, I] = V(!1), [C, T] = V(null), P = K(o), b = K(null), y = K(null);
3892
3908
  q(() => {
3893
3909
  P.current = o;
3894
3910
  }, [o]);
3895
- const x = z(
3911
+ const A = z(
3896
3912
  async (E) => {
3897
3913
  const j = await e.getState({
3898
3914
  threadId: E.threadId,
@@ -3916,39 +3932,39 @@ function Bt({
3916
3932
  const B = new AbortController();
3917
3933
  y.current = B, d(!0), T(null);
3918
3934
  try {
3919
- const L = await x({
3935
+ const F = await A({
3920
3936
  threadId: E,
3921
3937
  checkpointId: j ?? void 0
3922
3938
  });
3923
3939
  if (P.current !== E) return;
3924
- n((L == null ? void 0 : L.messages) ?? [], {
3925
- checkpointId: (L == null ? void 0 : L.checkpointId) ?? null,
3926
- checkpointNs: (L == null ? void 0 : L.checkpointNs) ?? null,
3927
- pendingInterrupt: (L == null ? void 0 : L.interrupt) ?? null,
3928
- values: L == null ? void 0 : L.values
3940
+ n((F == null ? void 0 : F.messages) ?? [], {
3941
+ checkpointId: (F == null ? void 0 : F.checkpointId) ?? null,
3942
+ checkpointNs: (F == null ? void 0 : F.checkpointNs) ?? null,
3943
+ pendingInterrupt: (F == null ? void 0 : F.interrupt) ?? null,
3944
+ values: F == null ? void 0 : F.values
3929
3945
  }), b.current = N;
3930
- const F = await e.getStateHistory({
3946
+ const L = await e.getStateHistory({
3931
3947
  threadId: E,
3932
3948
  limit: 100,
3933
3949
  includeMessages: !1
3934
3950
  });
3935
- P.current === E && c(F);
3936
- } catch (L) {
3937
- if (!Jt(L)) {
3938
- const F = String(L);
3939
- T(F), r == null || r(F);
3951
+ P.current === E && c(L);
3952
+ } catch (F) {
3953
+ if (!Jt(F)) {
3954
+ const L = String(F);
3955
+ T(L), r == null || r(L);
3940
3956
  }
3941
3957
  } finally {
3942
3958
  d(!1);
3943
3959
  }
3944
3960
  },
3945
- [e, n, x, r, k, i]
3961
+ [e, n, A, r, k, i]
3946
3962
  ), w = z(
3947
3963
  async (E, j) => {
3948
3964
  if (o) {
3949
3965
  I(!0);
3950
3966
  try {
3951
- const N = await x({
3967
+ const N = await A({
3952
3968
  threadId: o,
3953
3969
  checkpointId: E,
3954
3970
  checkpointNs: j ?? void 0
@@ -3966,7 +3982,7 @@ function Bt({
3966
3982
  }
3967
3983
  }
3968
3984
  },
3969
- [o, x, n]
3985
+ [o, A, n]
3970
3986
  ), _ = z(async () => {
3971
3987
  o && await p(o);
3972
3988
  }, [o, p]), U = z(
@@ -3975,7 +3991,7 @@ function Bt({
3975
3991
  const j = (E == null ? void 0 : E.threadId) || o;
3976
3992
  if (!j || o !== j) return;
3977
3993
  if (c(E), b.current = `${j}:latest`, (B = E.values) != null && B.messages) {
3978
- const O = await x({
3994
+ const O = await A({
3979
3995
  threadId: j
3980
3996
  });
3981
3997
  O && n(O.messages ?? [], {
@@ -3986,7 +4002,7 @@ function Bt({
3986
4002
  });
3987
4003
  }
3988
4004
  },
3989
- [o, x, n]
4005
+ [o, A, n]
3990
4006
  );
3991
4007
  q(() => {
3992
4008
  if (!s || !o || k || a) return;
@@ -4039,7 +4055,7 @@ function Nr({
4039
4055
  isStreaming: s,
4040
4056
  onError: a
4041
4057
  }) {
4042
- const { chatApi: i, fileApi: u } = Ae(), { currentThreadId: c } = rt(), { state: l, seed: f, onEvent: m, dispatch: h } = mr(), {
4058
+ const { chatApi: i, fileApi: u } = xe(), { currentThreadId: c } = rt(), { state: l, seed: f, onEvent: m, dispatch: h } = mr(), {
4043
4059
  threadCheckpoints: k,
4044
4060
  threadTimeline: d,
4045
4061
  checkpointIndex: v,
@@ -4049,7 +4065,7 @@ function Nr({
4049
4065
  loadThread: P,
4050
4066
  navigateToCheckpoint: b,
4051
4067
  setCurrentCheckpointId: y,
4052
- returnToLatest: x,
4068
+ returnToLatest: A,
4053
4069
  handleValuesEvent: p,
4054
4070
  markSkipNextLoad: w,
4055
4071
  markStreamPendingThread: _,
@@ -4067,18 +4083,18 @@ function Nr({
4067
4083
  isStreaming: s,
4068
4084
  getMessages: z(() => l.messages, [l.messages])
4069
4085
  }), M = K(null), E = z(
4070
- (A) => {
4071
- M.current = A;
4086
+ (x) => {
4087
+ M.current = x;
4072
4088
  },
4073
4089
  []
4074
4090
  ), j = K(null), N = z(
4075
- (A) => {
4076
- j.current = A;
4091
+ (x) => {
4092
+ j.current = x;
4077
4093
  },
4078
4094
  []
4079
- ), B = Q(() => ({ assemblingMessageId: l.assemblingId ?? null }), [l.assemblingId]), O = z(
4080
- (A, S) => {
4081
- const G = Ut(A, "user");
4095
+ ), B = Y(() => ({ assemblingMessageId: l.assemblingId ?? null }), [l.assemblingId]), O = z(
4096
+ (x, S) => {
4097
+ const G = Ut(x, "user");
4082
4098
  return h({
4083
4099
  type: "user_message",
4084
4100
  payload: {
@@ -4088,11 +4104,11 @@ function Nr({
4088
4104
  }), G;
4089
4105
  },
4090
4106
  [h]
4091
- ), L = z(async () => {
4107
+ ), F = z(async () => {
4092
4108
  M.current ? await M.current() : (f([], {}), U());
4093
- }, [f, U]), F = z(async (A, S, G) => {
4094
- await P(A, S, { clearProgress: !1 });
4095
- }, [P]), W = Q(() => Ln(l.messages), [l.messages]), Y = Q(
4109
+ }, [f, U]), L = z(async (x, S, G) => {
4110
+ await P(x, S, { clearProgress: !1 });
4111
+ }, [P]), W = Y(() => Fn(l.messages), [l.messages]), Z = Y(
4096
4112
  () => ({
4097
4113
  status: l.status,
4098
4114
  threadId: c,
@@ -4114,22 +4130,22 @@ function Nr({
4114
4130
  loadOlder: async () => {
4115
4131
  },
4116
4132
  // Placeholder
4117
- seedFromSnapshot: (A) => {
4118
- f(A.messages, {
4119
- checkpointId: A.checkpointId,
4120
- checkpointNs: A.checkpointNs,
4121
- pendingInterrupt: A.interrupt,
4122
- values: A.values
4133
+ seedFromSnapshot: (x) => {
4134
+ f(x.messages, {
4135
+ checkpointId: x.checkpointId,
4136
+ checkpointNs: x.checkpointNs,
4137
+ pendingInterrupt: x.interrupt,
4138
+ values: x.values
4123
4139
  });
4124
4140
  },
4125
- clearState: L,
4141
+ clearState: F,
4126
4142
  navigateToCheckpoint: b,
4127
4143
  setCurrentCheckpointId: y,
4128
- returnToLatest: x,
4129
- loadThread: F,
4130
- clearThread: L,
4131
- respondToInterrupt: async (A, S, G) => {
4132
- j.current && await j.current(A, S, G);
4144
+ returnToLatest: A,
4145
+ loadThread: L,
4146
+ clearThread: F,
4147
+ respondToInterrupt: async (x, S, G) => {
4148
+ j.current && await j.current(x, S, G);
4133
4149
  },
4134
4150
  messagePreviews: v.messagePreviews,
4135
4151
  handleValuesEvent: p,
@@ -4156,11 +4172,11 @@ function Nr({
4156
4172
  C,
4157
4173
  T,
4158
4174
  f,
4159
- L,
4175
+ F,
4160
4176
  b,
4161
4177
  y,
4162
- x,
4163
- F,
4178
+ A,
4179
+ L,
4164
4180
  p,
4165
4181
  w,
4166
4182
  _,
@@ -4168,14 +4184,14 @@ function Nr({
4168
4184
  m,
4169
4185
  W
4170
4186
  ]
4171
- ), g = Q(
4187
+ ), g = Y(
4172
4188
  () => ({
4173
4189
  registerClearThread: E,
4174
4190
  registerRespondToInterrupt: N
4175
4191
  }),
4176
4192
  [E, N]
4177
4193
  );
4178
- return /* @__PURE__ */ ie(Vt.Provider, { value: g, children: /* @__PURE__ */ ie($t.Provider, { value: Y, children: e }) });
4194
+ return /* @__PURE__ */ le(Vt.Provider, { value: g, children: /* @__PURE__ */ le($t.Provider, { value: Z, children: e }) });
4179
4195
  }
4180
4196
  const Kt = Se(null), _r = Se(!1);
4181
4197
  function zr({
@@ -4190,7 +4206,7 @@ function zr({
4190
4206
  onFinish: u,
4191
4207
  onStreamingChange: c
4192
4208
  }) {
4193
- const { chatApi: l, baseUrl: f } = Ae(), m = f, h = pe(t), k = pe(n), d = pe(r), v = pe(o), I = pe(s), C = pe(a), T = pe(i), P = pe(u), b = pe(c), y = Q(
4209
+ const { chatApi: l, baseUrl: f } = xe(), m = f, h = ge(t), k = ge(n), d = ge(r), v = ge(o), I = ge(s), C = ge(a), T = ge(i), P = ge(u), b = ge(c), y = Y(
4194
4210
  () => ({
4195
4211
  onError: h,
4196
4212
  onAuthError: k,
@@ -4212,7 +4228,7 @@ function zr({
4212
4228
  P
4213
4229
  ]
4214
4230
  );
4215
- return /* @__PURE__ */ ie(_r.Provider, { value: !0, children: /* @__PURE__ */ ie(
4231
+ return /* @__PURE__ */ le(_r.Provider, { value: !0, children: /* @__PURE__ */ le(
4216
4232
  Rr,
4217
4233
  {
4218
4234
  api: l,
@@ -4250,8 +4266,8 @@ function Rr({
4250
4266
  baseUrl: n,
4251
4267
  onEvent: I,
4252
4268
  onError: (g) => {
4253
- var A;
4254
- (A = r.onError) == null || A.call(r, (g == null ? void 0 : g.message) ?? String(g));
4269
+ var x;
4270
+ (x = r.onError) == null || x.call(r, (g == null ? void 0 : g.message) ?? String(g));
4255
4271
  },
4256
4272
  onAuthError: r.onAuthError,
4257
4273
  onConnectionError: r.onConnectionError,
@@ -4266,76 +4282,76 @@ function Rr({
4266
4282
  q(() => {
4267
4283
  o == null || o(y.isStreaming);
4268
4284
  }, [y.isStreaming, o]);
4269
- const { stream: x, stop: p, clear: w, isStreaming: _, error: U, connected: M, streamedMessages: E, activeMessageId: j } = y;
4285
+ const { stream: A, stop: p, clear: w, isStreaming: _, error: U, connected: M, streamedMessages: E, activeMessageId: j } = y;
4270
4286
  q(() => {
4271
4287
  u !== void 0 && w();
4272
4288
  }, [u, w]);
4273
4289
  const N = z(
4274
- async (g, A) => {
4275
- await x(g, A);
4290
+ async (g, x) => {
4291
+ await A(g, x);
4276
4292
  },
4277
- [x]
4293
+ [A]
4278
4294
  ), B = K(l);
4279
4295
  q(() => {
4280
4296
  B.current = l;
4281
4297
  }, [l]);
4282
4298
  const O = z(
4283
- async (g, A, S) => {
4299
+ async (g, x, S) => {
4284
4300
  const G = a.current;
4285
4301
  if (!G)
4286
4302
  throw new Error("No active thread to handle interrupt");
4287
- const J = g ? A ?? !0 : !1, D = B.current, ee = (S == null ? void 0 : S.checkpointId) ?? D.id ?? void 0, oe = (S == null ? void 0 : S.checkpointNs) ?? D.namespace ?? void 0, ue = {
4303
+ const J = g ? x ?? !0 : !1, D = B.current, ne = (S == null ? void 0 : S.checkpointId) ?? D.id ?? void 0, se = (S == null ? void 0 : S.checkpointNs) ?? D.namespace ?? void 0, fe = {
4288
4304
  threadId: G,
4289
- checkpointId: ee,
4290
- checkpointNs: oe,
4305
+ checkpointId: ne,
4306
+ checkpointNs: se,
4291
4307
  command: { kind: "resume", value: J },
4292
4308
  payload: S == null ? void 0 : S.payload
4293
4309
  };
4294
- N(ue);
4310
+ N(fe);
4295
4311
  },
4296
4312
  [a, N]
4297
4313
  );
4298
4314
  q(() => {
4299
4315
  P(O);
4300
4316
  }, [O, P]);
4301
- const L = z(async () => {
4317
+ const F = z(async () => {
4302
4318
  p(), w(), d(), s(null);
4303
4319
  }, [w, d, s, p]);
4304
4320
  q(() => {
4305
- T(L);
4306
- }, [L, T]);
4307
- const F = z(
4308
- async (g, A) => {
4321
+ T(F);
4322
+ }, [F, T]);
4323
+ const L = z(
4324
+ async (g, x) => {
4309
4325
  _ && p();
4310
4326
  let S = a.current;
4311
- const G = (g == null ? void 0 : g.text) ?? "", J = (g == null ? void 0 : g.attachments) ?? [], D = (G == null ? void 0 : G.trim()) ?? "", ee = { ...(g == null ? void 0 : g.payload) ?? {} }, oe = Array.isArray(ee.messages) ? ee.messages : void 0;
4312
- oe && delete ee.messages;
4313
- const ue = !!(oe && oe.length), H = !!(g.contentParts && g.contentParts.length > 0);
4314
- if (!S && !D && J.length === 0 && !ue && !H) return;
4327
+ const G = (g == null ? void 0 : g.text) ?? "", J = (g == null ? void 0 : g.attachments) ?? [], D = (G == null ? void 0 : G.trim()) ?? "", ne = { ...(g == null ? void 0 : g.payload) ?? {} }, se = Array.isArray(ne.messages) ? ne.messages : void 0;
4328
+ se && delete ne.messages;
4329
+ const fe = !!(se && se.length), H = !!(g.contentParts && g.contentParts.length > 0);
4330
+ if (!S && !D && J.length === 0 && !fe && !H) return;
4315
4331
  if (!S) {
4316
- const he = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), ye = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4317
- S = `${he}${ye}`, h(S), s(S);
4332
+ const ye = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), Q = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4333
+ S = `${ye}${Q}`, h(S), s(S);
4318
4334
  }
4319
- let te = null;
4320
- g.contentParts && g.contentParts.length > 0 && (te = g.contentParts);
4321
- const { contentParts: ve, filesInfo: X } = te ? { contentParts: te, filesInfo: [] } : await rr(J), Z = [...ve];
4322
- D && Z.push({ type: "text", text: G });
4323
- const me = g == null ? void 0 : g.originalMessageId, je = !!(g != null && g.edit && me), Le = !ue && Z.length > 0;
4324
- let de = null;
4325
- if (Le) {
4326
- const he = je ? me : `msg-${Date.now()}`;
4327
- de = Ut({
4328
- id: he,
4335
+ let re = null;
4336
+ g.contentParts && g.contentParts.length > 0 && (re = g.contentParts);
4337
+ const { contentParts: ve, filesInfo: X } = re ? { contentParts: re, filesInfo: [] } : await rr(J), ee = [...ve];
4338
+ D && ee.push({ type: "text", text: G });
4339
+ const he = g == null ? void 0 : g.originalMessageId, je = !!(g != null && g.edit && he), Fe = !fe && ee.length > 0;
4340
+ let ie = null;
4341
+ if (Fe) {
4342
+ const ye = je ? he : `msg-${Date.now()}`;
4343
+ ie = Ut({
4344
+ id: ye,
4329
4345
  role: "user",
4330
- content: Z,
4346
+ content: ee,
4331
4347
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4332
- }, "user"), je ? v(de, { editingMessageId: me }) : v(de);
4348
+ }, "user"), je ? v(ie, { editingMessageId: he }) : v(ie);
4333
4349
  }
4334
- const Ie = ue ? oe : de ? [de] : [], ne = {
4335
- ...ee,
4350
+ const Te = fe ? se : ie ? [ie] : [], te = {
4351
+ ...ne,
4336
4352
  ...X.length ? { files_info: X } : {}
4337
4353
  };
4338
- Ie.length ? ne.messages = Ie : "messages" in ne || (ne.messages = []);
4354
+ Te.length ? te.messages = Te : "messages" in te || (te.messages = []);
4339
4355
  const Me = (g == null ? void 0 : g.checkpointId) ?? l.id ?? void 0;
4340
4356
  if (g != null && g.edit && !Me)
4341
4357
  throw new Error(
@@ -4344,44 +4360,44 @@ function Rr({
4344
4360
  const Ee = {
4345
4361
  threadId: S,
4346
4362
  content: g == null ? void 0 : g.text,
4347
- payload: ne,
4363
+ payload: te,
4348
4364
  config: g == null ? void 0 : g.config,
4349
4365
  checkpointId: Me,
4350
4366
  command: g == null ? void 0 : g.command,
4351
4367
  edit: g == null ? void 0 : g.edit
4352
4368
  };
4353
- return N(Ee, A);
4369
+ return N(Ee, x);
4354
4370
  },
4355
4371
  [l, a, _, h, v, N, p, f]
4356
- ), W = Q(() => {
4372
+ ), W = Y(() => {
4357
4373
  const g = Object.keys(E).length > 0;
4358
4374
  if (!_ && !g)
4359
4375
  return C;
4360
- const A = /* @__PURE__ */ new Map();
4361
- return C.forEach((S) => A.set(S.id, S)), Object.values(E).forEach((S) => {
4362
- A.set(S.id, S);
4363
- }), Array.from(A.values());
4364
- }, [_, E, C]), Y = Q(
4376
+ const x = /* @__PURE__ */ new Map();
4377
+ return C.forEach((S) => x.set(S.id, S)), Object.values(E).forEach((S) => {
4378
+ x.set(S.id, S);
4379
+ }), Array.from(x.values());
4380
+ }, [_, E, C]), Z = Y(
4365
4381
  () => ({
4366
4382
  isStreaming: _,
4367
4383
  error: U,
4368
4384
  connectionState: U ? "error" : _ ? M ? "connected" : "connecting" : "idle",
4369
4385
  messages: W,
4370
4386
  activeMessageId: j,
4371
- submit: F,
4387
+ submit: L,
4372
4388
  stop: p,
4373
4389
  interrupt: c,
4374
4390
  resume: () => Promise.resolve(),
4375
- goto: (g, A) => Promise.resolve(),
4391
+ goto: (g, x) => Promise.resolve(),
4376
4392
  clearError: () => {
4377
4393
  }
4378
4394
  // TODO: Implement error clearing
4379
4395
  }),
4380
- [_, U, F, p, c, M, W]
4396
+ [_, U, L, p, c, M, W]
4381
4397
  );
4382
- return /* @__PURE__ */ ie(Kt.Provider, { value: Y, children: e });
4398
+ return /* @__PURE__ */ le(Kt.Provider, { value: Z, children: e });
4383
4399
  }
4384
- function pe(e) {
4400
+ function ge(e) {
4385
4401
  const t = K(e);
4386
4402
  return q(() => {
4387
4403
  t.current = e;
@@ -4408,18 +4424,18 @@ function jr(e, t) {
4408
4424
  return !1;
4409
4425
  return !0;
4410
4426
  }
4411
- function Lr(e) {
4427
+ function Fr(e) {
4412
4428
  const t = K(e), n = K(e);
4413
4429
  return jr(t.current, e) || (t.current = e, n.current = e), n.current;
4414
4430
  }
4415
- function Fr(e) {
4431
+ function Lr(e) {
4416
4432
  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;
4417
4433
  return typeof o == "string" ? o : null;
4418
4434
  }
4419
4435
  function ao(e) {
4420
4436
  const { setCurrentTaskId: t, getCurrentTaskId: n, onToolEnd: r } = e;
4421
4437
  return (o) => {
4422
- const s = Fr(o), a = (n == null ? void 0 : n()) ?? null;
4438
+ const s = Lr(o), a = (n == null ? void 0 : n()) ?? null;
4423
4439
  s && s !== a && t(s), r == null || r(o);
4424
4440
  };
4425
4441
  }
@@ -4440,13 +4456,13 @@ function io({
4440
4456
  onMetadataEvent: h,
4441
4457
  onFinish: k
4442
4458
  }) {
4443
- const d = Lr(t), [v, I] = V(!1), C = ge(i), T = ge(u), P = ge(a), b = ge(c), y = ge(l), x = ge(f), p = ge(m), w = ge(h), _ = ge(k), U = Q(
4459
+ const d = Fr(t), [v, I] = V(!1), C = me(i), T = me(u), P = me(a), b = me(c), y = me(l), A = me(f), p = me(m), w = me(h), _ = me(k), U = Y(
4444
4460
  () => ({
4445
4461
  onError: C,
4446
4462
  onAuthError: T,
4447
4463
  onConnectionError: P,
4448
4464
  onToolEnd: y,
4449
- onUpdateEvent: x,
4465
+ onUpdateEvent: A,
4450
4466
  onCustomEvent: p,
4451
4467
  onMetadataEvent: w,
4452
4468
  onFinish: _
@@ -4456,19 +4472,19 @@ function io({
4456
4472
  T,
4457
4473
  P,
4458
4474
  y,
4459
- x,
4475
+ A,
4460
4476
  p,
4461
4477
  w,
4462
4478
  _
4463
4479
  ]
4464
4480
  );
4465
- return /* @__PURE__ */ ie(tr, { apiConfig: d, children: /* @__PURE__ */ ie(
4481
+ return /* @__PURE__ */ le(tr, { apiConfig: d, children: /* @__PURE__ */ le(
4466
4482
  ur,
4467
4483
  {
4468
4484
  initialThreadId: n,
4469
4485
  onError: C,
4470
4486
  onThreadChange: b,
4471
- children: /* @__PURE__ */ ie(
4487
+ children: /* @__PURE__ */ le(
4472
4488
  Nr,
4473
4489
  {
4474
4490
  initialThreadId: n,
@@ -4477,7 +4493,7 @@ function io({
4477
4493
  autoLoadInitial: s,
4478
4494
  onError: C,
4479
4495
  isStreaming: v,
4480
- children: /* @__PURE__ */ ie(
4496
+ children: /* @__PURE__ */ le(
4481
4497
  zr,
4482
4498
  {
4483
4499
  ...U,
@@ -4490,7 +4506,7 @@ function io({
4490
4506
  }
4491
4507
  ) });
4492
4508
  }
4493
- function ge(e) {
4509
+ function me(e) {
4494
4510
  const t = K(e);
4495
4511
  return t.current = e, z((...n) => {
4496
4512
  const r = t.current;
@@ -4590,7 +4606,7 @@ function Kr() {
4590
4606
  };
4591
4607
  }
4592
4608
  function co(e) {
4593
- const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = Ae(), { toast: o } = Kr(), [s, a] = V({}), [i, u] = V(null), [c, l] = V(!1), f = z(() => {
4609
+ const { allowFileOpen: t, currentThreadId: n } = e, { fileApi: r } = xe(), { toast: o } = Kr(), [s, a] = V({}), [i, u] = V(null), [c, l] = V(!1), f = z(() => {
4594
4610
  l(!1), u(null);
4595
4611
  }, []), m = z((k) => {
4596
4612
  u(k), l(!0);
@@ -4609,8 +4625,8 @@ function co(e) {
4609
4625
  const T = String(d.url ?? ""), P = T.match(/\/chat\/files\/([^/]+)(?:\/(view|download))?/);
4610
4626
  if (P) {
4611
4627
  k.preventDefault();
4612
- const b = P[1], y = d.name || `file_${b}`, x = d.mimeType || "application/octet-stream";
4613
- m({ id: b, name: y, mimeType: x });
4628
+ const b = P[1], y = d.name || `file_${b}`, A = d.mimeType || "application/octet-stream";
4629
+ m({ id: b, name: y, mimeType: A });
4614
4630
  return;
4615
4631
  }
4616
4632
  if (T.startsWith("data:")) {
@@ -4620,15 +4636,15 @@ function co(e) {
4620
4636
  const y = await r.listFiles(n ?? void 0);
4621
4637
  if (!y || !Array.isArray(y))
4622
4638
  throw new Error("Invalid file list response");
4623
- const x = y.find((p) => !p || typeof p != "object" || !((p.filename ?? "") === (d.name ?? "")) ? !1 : typeof d.size == "number" && typeof p.size == "number" ? p.size === d.size : !0);
4624
- if (!(x != null && x.id))
4639
+ const A = y.find((p) => !p || typeof p != "object" || !((p.filename ?? "") === (d.name ?? "")) ? !1 : typeof d.size == "number" && typeof p.size == "number" ? p.size === d.size : !0);
4640
+ if (!(A != null && A.id))
4625
4641
  throw new Error(`File "${d.name}" is not yet available on the server`);
4626
- if (!x.id || !x.filename)
4642
+ if (!A.id || !A.filename)
4627
4643
  throw new Error("Invalid file data received from server");
4628
4644
  m({
4629
- id: x.id,
4630
- name: d.name || x.filename || `file_${x.id}`,
4631
- mimeType: d.mimeType || x.mime_type || "application/octet-stream"
4645
+ id: A.id,
4646
+ name: d.name || A.filename || `file_${A.id}`,
4647
+ mimeType: d.mimeType || A.mime_type || "application/octet-stream"
4632
4648
  }), (I = b.update) == null || I.call(b, {
4633
4649
  id: b.id,
4634
4650
  title: "Success",
@@ -4637,10 +4653,10 @@ function co(e) {
4637
4653
  });
4638
4654
  } catch (y) {
4639
4655
  console.error("Failed to fetch server file:", y);
4640
- const x = y instanceof Error ? y.message : "Unknown error occurred";
4641
- (C = b.update) == null || C.call(b, { id: b.id, title: "Failed", description: x }), o({
4656
+ const A = y instanceof Error ? y.message : "Unknown error occurred";
4657
+ (C = b.update) == null || C.call(b, { id: b.id, title: "Failed", description: A }), o({
4642
4658
  title: "Failed to fetch file",
4643
- description: x,
4659
+ description: A,
4644
4660
  open: !0
4645
4661
  });
4646
4662
  } finally {
@@ -4662,7 +4678,7 @@ function co(e) {
4662
4678
  };
4663
4679
  }
4664
4680
  function lo(e) {
4665
- return Q(() => {
4681
+ return Y(() => {
4666
4682
  const t = e;
4667
4683
  let n = Array.isArray(t.content) ? t.content : [];
4668
4684
  return typeof t.content == "string" && (n = [{ type: "text", text: t.content }]), {
@@ -4671,7 +4687,7 @@ function lo(e) {
4671
4687
  toolMeta: sr(t),
4672
4688
  imageParts: n.filter((r) => r.type === "image_url"),
4673
4689
  fileParts: n.filter((r) => r.type === "file"),
4674
- toolRaw: Fn(n),
4690
+ toolRaw: Ln(n),
4675
4691
  isToolStreaming: !!t.toolStreaming
4676
4692
  };
4677
4693
  }, [e]);
@@ -4701,7 +4717,7 @@ function Hr(e) {
4701
4717
  return null;
4702
4718
  }
4703
4719
  function uo(e) {
4704
- return Q(() => {
4720
+ return Y(() => {
4705
4721
  const t = e.content.filter(
4706
4722
  (u) => u.type === "text"
4707
4723
  );
@@ -4720,7 +4736,7 @@ function uo(e) {
4720
4736
  const s = Hr(r) ?? r[r.length - 1];
4721
4737
  if (!s)
4722
4738
  return null;
4723
- const a = s.output ?? s.payload ?? s, i = ce(a);
4739
+ const a = s.output ?? s.payload ?? s, i = ue(a);
4724
4740
  return i && typeof i == "object" && !Array.isArray(i) ? {
4725
4741
  kind: "dict",
4726
4742
  value: i,
@@ -4748,8 +4764,8 @@ function Wr(e) {
4748
4764
  threadCheckpoints: d,
4749
4765
  loadThread: v
4750
4766
  } = Bt({
4751
- api: Ae().chatApi,
4752
- fileApi: Ae().fileApi,
4767
+ api: xe().chatApi,
4768
+ fileApi: xe().fileApi,
4753
4769
  seed: m,
4754
4770
  currentThreadId: c ? t : null,
4755
4771
  initialThreadId: c ? t : null,
@@ -4760,10 +4776,10 @@ function Wr(e) {
4760
4776
  q(() => {
4761
4777
  !c && !n && a && (o != null && o.loadThread) && o.loadThread(a);
4762
4778
  }, [c, n, a, o == null ? void 0 : o.loadThread]);
4763
- const I = Q(() => {
4779
+ const I = Y(() => {
4764
4780
  var U;
4765
4781
  return ((U = d[0]) == null ? void 0 : U.values) || {};
4766
- }, [d]), C = Q(() => ({ timeline: [], messagePreviews: {} }), []), T = t || a, P = c ? h ? "loading" : "idle" : (o == null ? void 0 : o.status) || "idle", b = c ? l : (s == null ? void 0 : s.messages) || [], y = c ? h : (o == null ? void 0 : o.isLoading) || !1, x = c ? I : (o == null ? void 0 : o.values) || {}, p = c ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, w = c ? k : (s == null ? void 0 : s.error) || (o == null ? void 0 : o.error) || null;
4782
+ }, [d]), C = Y(() => ({ timeline: [], messagePreviews: {} }), []), T = t || a, P = c ? h ? "loading" : "idle" : (o == null ? void 0 : o.status) || "idle", b = c ? l : (s == null ? void 0 : s.messages) || [], y = c ? h : (o == null ? void 0 : o.isLoading) || !1, A = c ? I : (o == null ? void 0 : o.values) || {}, p = c ? {} : (o == null ? void 0 : o.taskMessagesByScope) || {}, w = c ? k : (s == null ? void 0 : s.error) || (o == null ? void 0 : o.error) || null;
4767
4783
  return {
4768
4784
  // UNIFIED: Single thread ID concept
4769
4785
  threadId: T,
@@ -4773,7 +4789,7 @@ function Wr(e) {
4773
4789
  isHistoryLoading: y,
4774
4790
  error: w,
4775
4791
  // Values & Metadata
4776
- values: x,
4792
+ values: A,
4777
4793
  taskMessagesByScope: p,
4778
4794
  metadata: c ? {} : o == null ? void 0 : o.metadata,
4779
4795
  // Actions & State relating to Global/Active Thread only
@@ -4833,7 +4849,7 @@ function fo({
4833
4849
  threadId: m,
4834
4850
  clearComposerOnSend: h = !0
4835
4851
  }) {
4836
- const { messages: k } = Wr(), [d, v] = V(null), [I, C] = V(""), [T, P] = V(null), [b, y] = V(null), [x, p] = V(!1), [w, _] = V(""), U = K(w), M = K(null);
4852
+ const { messages: k } = Wr(), [d, v] = V(null), [I, C] = V(""), [T, P] = V(null), [b, y] = V(null), [A, p] = V(!1), [w, _] = V(""), U = K(w), M = K(null);
4837
4853
  q(() => {
4838
4854
  if (!d)
4839
4855
  if (m) {
@@ -4859,30 +4875,30 @@ function fo({
4859
4875
  E(g);
4860
4876
  },
4861
4877
  [E]
4862
- ), N = async (g, A) => {
4863
- const S = Array.isArray(A) ? { files: A } : A ?? {}, G = S.files ?? [], J = S.contentParts ?? [], D = g.trim();
4878
+ ), N = async (g, x) => {
4879
+ const S = Array.isArray(x) ? { files: x } : x ?? {}, G = S.files ?? [], J = S.contentParts ?? [], D = g.trim();
4864
4880
  if (!(!D && G.length === 0 && J.length === 0))
4865
4881
  try {
4866
- const ee = G.map(async (X) => {
4882
+ const ne = G.map(async (X) => {
4867
4883
  try {
4868
- const Z = await zt.uploadFile(X);
4869
- return { file: X, record: Z };
4870
- } catch (Z) {
4871
- throw console.error("Failed to upload file", X.name, Z), new Error(`Failed to upload ${X.name}`);
4884
+ const ee = await zt.uploadFile(X);
4885
+ return { file: X, record: ee };
4886
+ } catch (ee) {
4887
+ throw console.error("Failed to upload file", X.name, ee), new Error(`Failed to upload ${X.name}`);
4872
4888
  }
4873
- }), ue = (await Promise.all(ee)).map(({ record: X }) => {
4874
- const Z = X.mime_type;
4875
- return Z.startsWith("image/") ? {
4889
+ }), fe = (await Promise.all(ne)).map(({ record: X }) => {
4890
+ const ee = X.mime_type;
4891
+ return ee.startsWith("image/") ? {
4876
4892
  type: "image_url",
4877
4893
  image_url: { url: X.content_url }
4878
4894
  } : {
4879
4895
  type: "file",
4880
4896
  url: X.content_url,
4881
- mimeType: Z,
4897
+ mimeType: ee,
4882
4898
  name: X.filename,
4883
4899
  size: X.size
4884
4900
  };
4885
- }), H = [...J, ...ue], te = d ? (T == null ? void 0 : T.checkpointId) ?? n ?? void 0 : n ?? void 0, ve = d ? (T == null ? void 0 : T.checkpointNs) ?? r ?? void 0 : r ?? void 0;
4901
+ }), H = [...J, ...fe], re = d ? (T == null ? void 0 : T.checkpointId) ?? n ?? void 0 : n ?? void 0, ve = d ? (T == null ? void 0 : T.checkpointNs) ?? r ?? void 0 : r ?? void 0;
4886
4902
  await e(
4887
4903
  {
4888
4904
  text: D || "",
@@ -4890,7 +4906,7 @@ function fo({
4890
4906
  attachments: G,
4891
4907
  payload: t.payload,
4892
4908
  edit: !!d,
4893
- checkpointId: te,
4909
+ checkpointId: re,
4894
4910
  checkpointNs: ve,
4895
4911
  project: l ?? void 0,
4896
4912
  originalMessageId: d ?? void 0,
@@ -4898,12 +4914,12 @@ function fo({
4898
4914
  },
4899
4915
  f ? { onEvent: f } : void 0
4900
4916
  ), o == null || o(D), c(!0), h && (m && localStorage.removeItem(He(m)), E("")), y(null), v(null), C(""), P(null);
4901
- } catch (ee) {
4902
- const oe = (ee == null ? void 0 : ee.message) || "Failed to send message";
4903
- y(oe), a == null || a(oe), c(!1);
4917
+ } catch (ne) {
4918
+ const se = (ne == null ? void 0 : ne.message) || "Failed to send message";
4919
+ y(se), a == null || a(se), c(!1);
4904
4920
  }
4905
- }, B = (g, A) => {
4906
- A || N(g, { files: [] });
4921
+ }, B = (g, x) => {
4922
+ x || N(g, { files: [] });
4907
4923
  }, O = z(
4908
4924
  async (g) => {
4909
4925
  await e(
@@ -4919,27 +4935,27 @@ function fo({
4919
4935
  ), s == null || s({ file: g });
4920
4936
  },
4921
4937
  [n, r, t, s, e]
4922
- ), L = z(
4923
- (g, A, S) => {
4924
- i && (M.current = w, v(g), C(A), P({
4938
+ ), F = z(
4939
+ (g, x, S) => {
4940
+ i && (M.current = w, v(g), C(x), P({
4925
4941
  checkpointId: (S == null ? void 0 : S.checkpointId) ?? null,
4926
4942
  checkpointNs: (S == null ? void 0 : S.checkpointNs) ?? null
4927
4943
  }), y(null));
4928
4944
  },
4929
4945
  [w, i]
4930
- ), F = z(() => {
4946
+ ), L = z(() => {
4931
4947
  v(null), C(""), P(null), y(null);
4932
4948
  const g = M.current;
4933
4949
  g !== null && _(g), M.current = null;
4934
4950
  }, []), W = z((g) => {
4935
- let A = null;
4951
+ let x = null;
4936
4952
  for (let D = g - 1; D >= 0; D--)
4937
4953
  if (u[D].role === "user") {
4938
- A = u[D];
4954
+ x = u[D];
4939
4955
  break;
4940
4956
  }
4941
- if (!A) return;
4942
- const S = Array.isArray(A.content) ? A.content : [], J = S.filter((D) => (D == null ? void 0 : D.type) === "text").map((D) => D.text).join("") || (() => {
4957
+ if (!x) return;
4958
+ const S = Array.isArray(x.content) ? x.content : [], J = S.filter((D) => (D == null ? void 0 : D.type) === "text").map((D) => D.text).join("") || (() => {
4943
4959
  try {
4944
4960
  return JSON.stringify(S, null, 2);
4945
4961
  } catch {
@@ -4953,7 +4969,7 @@ function fo({
4953
4969
  checkpointId: n ?? void 0,
4954
4970
  checkpointNs: r ?? void 0,
4955
4971
  edit: !0,
4956
- originalMessageId: A.id,
4972
+ originalMessageId: x.id,
4957
4973
  config: t.config
4958
4974
  },
4959
4975
  f ? { onEvent: f } : void 0
@@ -4964,21 +4980,21 @@ function fo({
4964
4980
  editingInitialValue: I,
4965
4981
  inputError: b,
4966
4982
  setInputError: y,
4967
- dismissError: x,
4983
+ dismissError: A,
4968
4984
  setDismissError: p,
4969
4985
  composerValue: w,
4970
4986
  handleComposerChange: j,
4971
4987
  handleSendMessage: N,
4972
4988
  handleQuickPrompt: B,
4973
4989
  handleExcelUpload: O,
4974
- startEditing: L,
4975
- cancelEditing: F,
4990
+ startEditing: F,
4991
+ cancelEditing: L,
4976
4992
  handleRegenerateCb: W,
4977
4993
  displayMessages: k
4978
4994
  };
4979
4995
  }
4980
4996
  function po(e) {
4981
- return Q(() => e ? {
4997
+ return Y(() => e ? {
4982
4998
  textContent: Rn(e),
4983
4999
  imageParts: Un(e),
4984
5000
  fileParts: jn(e),
@@ -5017,7 +5033,7 @@ export {
5017
5033
  Yr as cn,
5018
5034
  or as collectText,
5019
5035
  ao as createTaskSyncToolEndHandler,
5020
- Fr as extractTaskIdFromToolEnd,
5036
+ Lr as extractTaskIdFromToolEnd,
5021
5037
  sr as extractToolMeta,
5022
5038
  Zr as formatToolOutput,
5023
5039
  ro as getAgentNameFromMessage,
@@ -5036,9 +5052,9 @@ export {
5036
5052
  Mt as pretty,
5037
5053
  Ir as refreshHistoryFileUrls,
5038
5054
  Ve as sanitizeForDisplay,
5039
- ke as setChatToken,
5040
- Fn as stringifyTool,
5041
- Ae as useApi,
5055
+ Ie as setChatToken,
5056
+ Ln as stringifyTool,
5057
+ xe as useApi,
5042
5058
  fo as useChatController,
5043
5059
  Wr as useChatSession,
5044
5060
  co as useFilePreview,