@teodorruskvi/chat-core 0.1.56 → 0.1.57

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 Ht = Object.defineProperty;
2
2
  var Gt = (e, t, n) => t in e ? Ht(e, t, { enumerable: !0, configurable: !0, writable: !0, value: n }) : e[t] = n;
3
3
  var at = (e, t, n) => Gt(e, typeof t != "symbol" ? t + "" : t, n);
4
- import { jsx as ce } from "react/jsx-runtime";
4
+ import { jsx as de } from "react/jsx-runtime";
5
5
  import * as it from "react";
6
- import { createContext as Ce, useContext as je, useState as D, useRef as H, useEffect as Q, useCallback as N, useMemo as Z, useReducer as Wt } from "react";
6
+ import { createContext as Ce, useContext as je, useState as D, useRef as H, useEffect as Y, useCallback as N, useMemo as Z, useReducer as Wt } from "react";
7
7
  import Jt, { isCancel as Xt } from "axios";
8
8
  function It(e) {
9
9
  var t, n, r = "";
@@ -238,7 +238,7 @@ function un(e, ...t) {
238
238
  const q = (e) => {
239
239
  const t = (n) => n[e] || [];
240
240
  return t.isThemeGetter = !0, t;
241
- }, Tt = /^\[(?:([a-z-]+):)?(.+)\]$/i, fn = /^\d+\/\d+$/, pn = /* @__PURE__ */ new Set(["px", "full", "screen"]), gn = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, mn = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/, yn = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, hn = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, bn = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, ue = (e) => Te(e) || pn.has(e) || fn.test(e), ke = (e) => Ee(e, "length", Sn), Te = (e) => !!e && !Number.isNaN(Number(e)), qe = (e) => Ee(e, "number", Te), _e = (e) => !!e && Number.isInteger(Number(e)), wn = (e) => e.endsWith("%") && Te(e.slice(0, -1)), z = (e) => Tt.test(e), Ie = (e) => gn.test(e), kn = /* @__PURE__ */ new Set(["length", "size", "percentage"]), In = (e) => Ee(e, kn, St), vn = (e) => Ee(e, "position", St), xn = /* @__PURE__ */ new Set(["image", "url"]), An = (e) => Ee(e, xn, Cn), Tn = (e) => Ee(e, "", Mn), Ne = () => !0, Ee = (e, t, n) => {
241
+ }, Tt = /^\[(?:([a-z-]+):)?(.+)\]$/i, fn = /^\d+\/\d+$/, pn = /* @__PURE__ */ new Set(["px", "full", "screen"]), gn = /^(\d+(\.\d+)?)?(xs|sm|md|lg|xl)$/, mn = /\d+(%|px|r?em|[sdl]?v([hwib]|min|max)|pt|pc|in|cm|mm|cap|ch|ex|r?lh|cq(w|h|i|b|min|max))|\b(calc|min|max|clamp)\(.+\)|^0$/, yn = /^(rgba?|hsla?|hwb|(ok)?(lab|lch))\(.+\)$/, hn = /^(inset_)?-?((\d+)?\.?(\d+)[a-z]+|0)_-?((\d+)?\.?(\d+)[a-z]+|0)/, bn = /^(url|image|image-set|cross-fade|element|(repeating-)?(linear|radial|conic)-gradient)\(.+\)$/, pe = (e) => Te(e) || pn.has(e) || fn.test(e), Ie = (e) => Ee(e, "length", Sn), Te = (e) => !!e && !Number.isNaN(Number(e)), qe = (e) => Ee(e, "number", Te), _e = (e) => !!e && Number.isInteger(Number(e)), wn = (e) => e.endsWith("%") && Te(e.slice(0, -1)), z = (e) => Tt.test(e), ve = (e) => gn.test(e), kn = /* @__PURE__ */ new Set(["length", "size", "percentage"]), In = (e) => Ee(e, kn, St), vn = (e) => Ee(e, "position", St), xn = /* @__PURE__ */ new Set(["image", "url"]), An = (e) => Ee(e, xn, Cn), Tn = (e) => Ee(e, "", Mn), Ne = () => !0, Ee = (e, t, n) => {
242
242
  const r = Tt.exec(e);
243
243
  return r ? r[1] ? typeof t == "string" ? r[1] === t : t.has(r[1]) : n(r[2]) : !1;
244
244
  }, Sn = (e) => (
@@ -247,17 +247,17 @@ const q = (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 = q("colors"), t = q("spacing"), n = q("blur"), r = q("brightness"), o = q("borderColor"), s = q("borderRadius"), a = q("borderSpacing"), i = q("borderWidth"), d = q("contrast"), c = q("grayscale"), l = q("hueRotate"), f = q("invert"), p = q("gap"), g = q("gradientColorStops"), I = q("gradientColorStopPositions"), u = q("inset"), v = q("margin"), x = q("opacity"), S = q("padding"), A = q("saturate"), w = q("scale"), b = q("sepia"), y = q("skew"), T = q("space"), m = q("translate"), k = () => ["auto", "contain", "none"], E = () => ["auto", "hidden", "clip", "visible", "scroll"], U = () => ["auto", z, t], M = () => [z, t], $ = () => ["", ue, ke], F = () => ["auto", Te, z], _ = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], O = () => ["solid", "dashed", "dotted", "double", "none"], R = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], W = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], B = () => ["", "0", z], L = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], h = () => [Te, z];
250
+ const e = q("colors"), t = q("spacing"), n = q("blur"), r = q("brightness"), o = q("borderColor"), s = q("borderRadius"), a = q("borderSpacing"), i = q("borderWidth"), d = q("contrast"), c = q("grayscale"), l = q("hueRotate"), f = q("invert"), p = q("gap"), g = q("gradientColorStops"), I = q("gradientColorStopPositions"), u = q("inset"), v = q("margin"), x = q("opacity"), S = q("padding"), A = q("saturate"), w = q("scale"), b = q("sepia"), y = q("skew"), T = q("space"), m = q("translate"), k = () => ["auto", "contain", "none"], E = () => ["auto", "hidden", "clip", "visible", "scroll"], U = () => ["auto", z, t], M = () => [z, t], $ = () => ["", pe, Ie], F = () => ["auto", Te, z], _ = () => ["bottom", "center", "left", "left-bottom", "left-top", "right", "right-bottom", "right-top", "top"], O = () => ["solid", "dashed", "dotted", "double", "none"], R = () => ["normal", "multiply", "screen", "overlay", "darken", "lighten", "color-dodge", "color-burn", "hard-light", "soft-light", "difference", "exclusion", "hue", "saturation", "color", "luminosity"], W = () => ["start", "end", "center", "between", "around", "evenly", "stretch"], B = () => ["", "0", z], L = () => ["auto", "avoid", "all", "avoid-page", "page", "left", "right", "column"], h = () => [Te, z];
251
251
  return {
252
252
  cacheSize: 500,
253
253
  separator: ":",
254
254
  theme: {
255
255
  colors: [Ne],
256
- spacing: [ue, ke],
257
- blur: ["none", "", Ie, z],
256
+ spacing: [pe, Ie],
257
+ blur: ["none", "", ve, z],
258
258
  brightness: h(),
259
259
  borderColor: [e],
260
- borderRadius: ["none", "", "full", Ie, z],
260
+ borderRadius: ["none", "", "full", ve, z],
261
261
  borderSpacing: M(),
262
262
  borderWidth: $(),
263
263
  contrast: h(),
@@ -266,7 +266,7 @@ const q = (e) => {
266
266
  invert: B(),
267
267
  gap: M(),
268
268
  gradientColorStops: [e],
269
- gradientColorStopPositions: [wn, ke],
269
+ gradientColorStopPositions: [wn, Ie],
270
270
  inset: U(),
271
271
  margin: U(),
272
272
  opacity: h(),
@@ -297,7 +297,7 @@ const q = (e) => {
297
297
  * @see https://tailwindcss.com/docs/columns
298
298
  */
299
299
  columns: [{
300
- columns: [Ie]
300
+ columns: [ve]
301
301
  }],
302
302
  /**
303
303
  * Break After
@@ -881,8 +881,8 @@ const q = (e) => {
881
881
  */
882
882
  "max-w": [{
883
883
  "max-w": [z, t, "none", "full", "min", "max", "fit", "prose", {
884
- screen: [Ie]
885
- }, Ie]
884
+ screen: [ve]
885
+ }, ve]
886
886
  }],
887
887
  /**
888
888
  * Height
@@ -918,7 +918,7 @@ const q = (e) => {
918
918
  * @see https://tailwindcss.com/docs/font-size
919
919
  */
920
920
  "font-size": [{
921
- text: ["base", Ie, ke]
921
+ text: ["base", ve, Ie]
922
922
  }],
923
923
  /**
924
924
  * Font Smoothing
@@ -993,7 +993,7 @@ const q = (e) => {
993
993
  * @see https://tailwindcss.com/docs/line-height
994
994
  */
995
995
  leading: [{
996
- leading: ["none", "tight", "snug", "normal", "relaxed", "loose", ue, z]
996
+ leading: ["none", "tight", "snug", "normal", "relaxed", "loose", pe, z]
997
997
  }],
998
998
  /**
999
999
  * List Style Image
@@ -1069,14 +1069,14 @@ const q = (e) => {
1069
1069
  * @see https://tailwindcss.com/docs/text-decoration-thickness
1070
1070
  */
1071
1071
  "text-decoration-thickness": [{
1072
- decoration: ["auto", "from-font", ue, ke]
1072
+ decoration: ["auto", "from-font", pe, Ie]
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", ue, z]
1079
+ "underline-offset": ["auto", pe, z]
1080
1080
  }],
1081
1081
  /**
1082
1082
  * Text Decoration Color
@@ -1558,14 +1558,14 @@ const q = (e) => {
1558
1558
  * @see https://tailwindcss.com/docs/outline-offset
1559
1559
  */
1560
1560
  "outline-offset": [{
1561
- "outline-offset": [ue, z]
1561
+ "outline-offset": [pe, z]
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: [ue, ke]
1568
+ outline: [pe, Ie]
1569
1569
  }],
1570
1570
  /**
1571
1571
  * Outline Color
@@ -1605,7 +1605,7 @@ const q = (e) => {
1605
1605
  * @see https://tailwindcss.com/docs/ring-offset-width
1606
1606
  */
1607
1607
  "ring-offset-w": [{
1608
- "ring-offset": [ue, ke]
1608
+ "ring-offset": [pe, Ie]
1609
1609
  }],
1610
1610
  /**
1611
1611
  * Ring Offset Color
@@ -1620,7 +1620,7 @@ const q = (e) => {
1620
1620
  * @see https://tailwindcss.com/docs/box-shadow
1621
1621
  */
1622
1622
  shadow: [{
1623
- shadow: ["", "inner", "none", Ie, Tn]
1623
+ shadow: ["", "inner", "none", ve, Tn]
1624
1624
  }],
1625
1625
  /**
1626
1626
  * Box Shadow Color
@@ -1685,7 +1685,7 @@ const q = (e) => {
1685
1685
  * @see https://tailwindcss.com/docs/drop-shadow
1686
1686
  */
1687
1687
  "drop-shadow": [{
1688
- "drop-shadow": ["", "none", Ie, z]
1688
+ "drop-shadow": ["", "none", ve, z]
1689
1689
  }],
1690
1690
  /**
1691
1691
  * Grayscale
@@ -2200,7 +2200,7 @@ const q = (e) => {
2200
2200
  * @see https://tailwindcss.com/docs/stroke-width
2201
2201
  */
2202
2202
  "stroke-w": [{
2203
- stroke: [ue, ke, qe]
2203
+ stroke: [pe, Ie, qe]
2204
2204
  }],
2205
2205
  /**
2206
2206
  * Stroke
@@ -2416,41 +2416,41 @@ function Fn(e) {
2416
2416
  function so(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 le(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 = tt(t);
2425
2425
  if (n !== null)
2426
- return le(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) => le(t)).filter(Boolean).join(`
2433
- `) : le(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 le(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 ? le(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 de(e) {
2443
- return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(de) : Object.fromEntries(
2442
+ function fe(e) {
2443
+ return !e || typeof e != "object" ? e : Array.isArray(e) ? e.map(fe) : Object.fromEntries(
2444
2444
  Object.entries(e).map(([t, n]) => [
2445
2445
  On(t),
2446
- de(n)
2446
+ fe(n)
2447
2447
  ])
2448
2448
  );
2449
2449
  }
2450
2450
  function nt(e) {
2451
2451
  var x, S, A, w, b, y, T;
2452
2452
  if (!e || typeof e != "object") return null;
2453
- const t = de(e), n = Kn(t);
2453
+ const t = fe(e), n = Kn(t);
2454
2454
  if (!n)
2455
2455
  return null;
2456
2456
  const r = t.toolCalls ?? ((x = t.additionalKwargs) == null ? void 0 : x.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(), d = t.name ?? ((A = t.additionalKwargs) == null ? void 0 : A.agentName) ?? void 0, c = t.model ?? ((w = t.additionalKwargs) == null ? void 0 : w.model) ?? void 0, l = t.toolCallId ?? void 0, f = t.additionalKwargs ?? void 0, p = t.responseMetadata ?? void 0, g = t.checkpointId ?? ((b = t.additionalKwargs) == null ? void 0 : b.checkpointId) ?? void 0, I = t.checkpointNs ?? ((y = t.additionalKwargs) == null ? void 0 : y.checkpointNs) ?? void 0, u = typeof t.toolStreaming == "boolean" ? t.toolStreaming : !!((T = t.additionalKwargs) != null && T.toolStreaming);
@@ -2474,7 +2474,7 @@ function nt(e) {
2474
2474
  }
2475
2475
  function $n(e) {
2476
2476
  if (!e || typeof e != "object") return e;
2477
- const t = de(e);
2477
+ const t = fe(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.type && t.name && (n.type = t.name);
@@ -2482,7 +2482,7 @@ function $n(e) {
2482
2482
  return t;
2483
2483
  }
2484
2484
  function rt(e) {
2485
- const t = de(e), n = t.content ?? t.output ?? void 0;
2485
+ const t = fe(e), n = t.content ?? t.output ?? void 0;
2486
2486
  return {
2487
2487
  ...t,
2488
2488
  type: "tool_call",
@@ -2493,12 +2493,12 @@ function rt(e) {
2493
2493
  };
2494
2494
  }
2495
2495
  function Dn(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 : rt(de(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 : rt(fe(n)) : n).filter(
2497
2497
  (n) => !!(n && typeof n == "object" && typeof n.type == "string")
2498
2498
  ) : [];
2499
2499
  }
2500
2500
  function Kn(e) {
2501
- const t = de(e), n = t.role;
2501
+ const t = fe(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;
@@ -2540,7 +2540,7 @@ function qn(e, t = []) {
2540
2540
  var f, p, g;
2541
2541
  const i = He(a.id, e) || He(a.id, t), d = Array.isArray((f = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : f.toolProgress) ? (p = i == null ? void 0 : i.additionalKwargs) == null ? void 0 : p.toolProgress : void 0, c = (i == null ? void 0 : i.artifact) ?? a.artifact, l = dt(a.status) ?? ((g = i == null ? void 0 : i.additionalKwargs) != null && g.toolStreaming ? "pending" : null) ?? (i ? "completed" : "pending");
2542
2542
  if (i && !a.content && l === "completed") {
2543
- const I = le(i);
2543
+ const I = ue(i);
2544
2544
  typeof I == "string" && (a.content = I);
2545
2545
  }
2546
2546
  return {
@@ -2558,7 +2558,7 @@ function qn(e, t = []) {
2558
2558
  var d, c, l;
2559
2559
  const o = He(r.id, t) ?? Vn(e, r), s = Array.isArray((d = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : d.toolProgress) ? (c = o == null ? void 0 : o.additionalKwargs) == null ? void 0 : c.toolProgress : void 0, a = (o == null ? void 0 : o.artifact) ?? r.artifact, i = dt(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 = le(o);
2561
+ const f = ue(o);
2562
2562
  typeof f == "string" && (r.content = f);
2563
2563
  }
2564
2564
  return {
@@ -2590,7 +2590,7 @@ const Qe = /* @__PURE__ */ new Set();
2590
2590
  function Pt() {
2591
2591
  return Ke;
2592
2592
  }
2593
- function ve(e) {
2593
+ function xe(e) {
2594
2594
  Ke = e, Qe.forEach((t) => t(e));
2595
2595
  }
2596
2596
  function _t(e) {
@@ -2598,7 +2598,7 @@ function _t(e) {
2598
2598
  }
2599
2599
  const Hn = 12e4, Gn = 12e4;
2600
2600
  let Ye = Hn, Nt = Gn;
2601
- const te = Jt.create({
2601
+ const oe = Jt.create({
2602
2602
  // BaseURL is set dynamically via ApiProvider -> api.updateConfig
2603
2603
  timeout: Ye,
2604
2604
  withCredentials: !0
@@ -2608,18 +2608,18 @@ function ft(e) {
2608
2608
  }
2609
2609
  function Wn(e) {
2610
2610
  const t = ft(e.requestTimeoutMs), n = ft(e.historyTimeoutMs);
2611
- t !== null && (Ye = t, te.defaults.timeout = Ye), n !== null && (Nt = n);
2611
+ t !== null && (Ye = t, oe.defaults.timeout = Ye), n !== null && (Nt = n);
2612
2612
  }
2613
2613
  function Jn() {
2614
2614
  return Nt;
2615
2615
  }
2616
- te.interceptors.request.use((e) => (Ke && (e.headers.Authorization = `Bearer ${Ke}`), e));
2617
- te.interceptors.response.use(
2616
+ oe.interceptors.request.use((e) => (Ke && (e.headers.Authorization = `Bearer ${Ke}`), 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(ze.authToken, r), ve(r)), o && localStorage.setItem(ze.authTokenExpiresAt, o.toString()), (r || o) && window.dispatchEvent(
2622
+ r && (localStorage.setItem(ze.authToken, r), xe(r)), o && localStorage.setItem(ze.authTokenExpiresAt, o.toString()), (r || o) && window.dispatchEvent(
2623
2623
  new CustomEvent("smartorg:chat-token-updated", {
2624
2624
  detail: { token: r, expiresAt: o }
2625
2625
  })
@@ -2631,19 +2631,19 @@ te.interceptors.response.use(
2631
2631
  },
2632
2632
  (e) => Promise.reject(e)
2633
2633
  );
2634
- async function se(e, t) {
2635
- return te.defaults.baseURL ? (await te.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 Ze(e, t, n) {
2638
- return te.defaults.baseURL ? (await te.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 Xn(e, t, n) {
2641
- return te.defaults.baseURL ? (await te.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 Qn(e, t) {
2644
- return te.defaults.baseURL ? (await te.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 ie(e) {
2646
+ function le(e) {
2647
2647
  return e && typeof e == "object" && "data" in e ? e.data : e;
2648
2648
  }
2649
2649
  class Yn {
@@ -2651,16 +2651,16 @@ class Yn {
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 te.defaults.baseURL || "";
2654
+ return oe.defaults.baseURL || "";
2655
2655
  }
2656
2656
  updateConfig(t) {
2657
2657
  if (t.chatBaseUrl)
2658
- te.defaults.baseURL = t.chatBaseUrl;
2658
+ oe.defaults.baseURL = t.chatBaseUrl;
2659
2659
  else if (t.baseUrl) {
2660
2660
  const n = t.baseUrl.replace(/\/+$/, "");
2661
- te.defaults.baseURL = n;
2661
+ oe.defaults.baseURL = n;
2662
2662
  }
2663
- t.apiKey !== void 0 ? ve(t.apiKey) : t.getToken && ve(t.getToken()), (t.requestTimeoutMs !== void 0 || t.historyTimeoutMs !== void 0) && Wn({
2663
+ t.apiKey !== void 0 ? xe(t.apiKey) : t.getToken && xe(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 Yn {
2670
2670
  return Pt();
2671
2671
  }
2672
2672
  setAuthToken(t) {
2673
- ve(t);
2673
+ xe(t);
2674
2674
  }
2675
2675
  onTokenChange(t) {
2676
2676
  return _t(t);
2677
2677
  }
2678
2678
  // ---- Thread Management ----
2679
2679
  async listThreads() {
2680
- const t = await se("/threads"), n = ie(t);
2680
+ const t = await ae("/threads"), n = le(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 Yn {
2685
2685
  const r = {};
2686
2686
  t && (r.title = t), n && (r.project = n);
2687
2687
  const o = await Ze("/threads", Object.keys(r).length ? r : void 0);
2688
- return ie(o);
2688
+ return le(o);
2689
2689
  }
2690
2690
  async updateThread(t, n) {
2691
2691
  const r = await Xn(`/threads/${t}`, { title: n });
2692
- return ie(r);
2692
+ return le(r);
2693
2693
  }
2694
2694
  async deleteThread(t) {
2695
2695
  const n = await Qn(`/threads/${t}`);
2696
- return ie(n);
2696
+ return le(n);
2697
2697
  }
2698
2698
  async threadInfo(t) {
2699
- const n = await se(`/threads/${t}/info`);
2700
- return ie(n);
2699
+ const n = await ae(`/threads/${t}/info`);
2700
+ return le(n);
2701
2701
  }
2702
2702
  // ---- Agents ----
2703
2703
  async listAgents() {
2704
- const t = await se("/agents"), n = ie(t);
2704
+ const t = await ae("/agents"), n = le(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 ie(n);
2708
+ const n = await ae(`/agents/${t}`);
2709
+ return le(n);
2710
2710
  }
2711
2711
  async getAgentSchema(t) {
2712
- const n = await se(`/agents/${t}/schema`);
2713
- return ie(n);
2712
+ const n = await ae(`/agents/${t}/schema`);
2713
+ return le(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 ie(n);
2722
+ return le(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 Yn {
2733
2733
  timeout: Jn(),
2734
2734
  signal: t.signal
2735
2735
  });
2736
- return ie(n);
2736
+ return le(n);
2737
2737
  }
2738
2738
  // ---- Run Management ----
2739
2739
  async cancelRun(t) {
2740
2740
  const n = await Ze(`/runs/${t}/cancel`);
2741
- return ie(n);
2741
+ return le(n);
2742
2742
  }
2743
2743
  }
2744
2744
  const zt = new Yn();
@@ -2746,7 +2746,7 @@ class Zn {
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 Zn {
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 Zn {
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 er {
2820
2820
  const n = t.baseUrl.replace(/\/+$/, "");
2821
2821
  this._authBaseUrl = `${n}/auth`;
2822
2822
  }
2823
- t.apiKey !== void 0 ? ve(t.apiKey) : t.getToken && ve(t.getToken());
2823
+ t.apiKey !== void 0 ? xe(t.apiKey) : t.getToken && xe(t.getToken());
2824
2824
  }
2825
2825
  // ---- Token Management ----
2826
2826
  getAuthToken() {
2827
2827
  return Pt();
2828
2828
  }
2829
2829
  setAuthToken(t) {
2830
- ve(t);
2830
+ xe(t);
2831
2831
  }
2832
2832
  onTokenChange(t) {
2833
2833
  return _t(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 nr({ children: e, apiConfig: t }) {
2855
2855
  fileApi: Rt,
2856
2856
  baseUrl: n.baseUrl
2857
2857
  };
2858
- return /* @__PURE__ */ ce(Lt.Provider, { value: o, children: e });
2858
+ return /* @__PURE__ */ de(Lt.Provider, { value: o, children: e });
2859
2859
  }
2860
2860
  async function rr(e) {
2861
2861
  return await new Promise((t, n) => {
@@ -3010,7 +3010,7 @@ function fr(e, t) {
3010
3010
  }
3011
3011
  function pr(e = {}) {
3012
3012
  const t = e.baseUrl || "", n = e.streamPath ?? "/stream", [r, o] = D(e.token ?? null), s = H(e.headers ?? {}), a = e.credentials ?? "include", i = H(e);
3013
- Q(() => {
3013
+ Y(() => {
3014
3014
  i.current = e;
3015
3015
  }, [e]);
3016
3016
  const d = N((m) => {
@@ -3067,15 +3067,15 @@ function pr(e = {}) {
3067
3067
  if (r)
3068
3068
  B = { Authorization: `Bearer ${r}` };
3069
3069
  else if (typeof window < "u") {
3070
- const ne = window.__AUTH_TOKEN__, me = (($ = window.localStorage) == null ? void 0 : $.getItem(ze.authToken)) || null;
3070
+ const se = window.__AUTH_TOKEN__, he = (($ = window.localStorage) == null ? void 0 : $.getItem(ze.authToken)) || null;
3071
3071
  let X = null;
3072
3072
  try {
3073
- const ye = (F = window.localStorage) == null ? void 0 : F.getItem(ze.chatSettings);
3074
- ye && (X = ((_ = JSON.parse(ye)) == null ? void 0 : _.apiKey) || null);
3073
+ const be = (F = window.localStorage) == null ? void 0 : F.getItem(ze.chatSettings);
3074
+ be && (X = ((_ = JSON.parse(be)) == null ? void 0 : _.apiKey) || null);
3075
3075
  } catch {
3076
3076
  }
3077
- const Y = ne || me || X || null;
3078
- Y && (B = { Authorization: `Bearer ${Y}` });
3077
+ const Q = se || he || X || null;
3078
+ Q && (B = { Authorization: `Bearer ${Q}` });
3079
3079
  }
3080
3080
  } catch {
3081
3081
  }
@@ -3109,70 +3109,70 @@ function pr(e = {}) {
3109
3109
  C.status,
3110
3110
  G == null ? void 0 : G.slice(0, 500)
3111
3111
  );
3112
- const ne = `stream ${C.status}${G ? ": " + G : ""}`;
3113
- throw ne && (p(ne), U = "error"), new Error(ne);
3112
+ const se = `stream ${C.status}${G ? ": " + G : ""}`;
3113
+ throw se && (p(se), U = "error"), new Error(se);
3114
3114
  }
3115
3115
  I(!0);
3116
3116
  const P = C.body.getReader(), J = new TextDecoder();
3117
3117
  let K = "", V = 0, ee = Date.now();
3118
- const ae = setInterval(() => {
3118
+ const ie = setInterval(() => {
3119
3119
  Date.now() - ee > 18e5 && (p("Stream idle timeout"), U = "error", E.abort());
3120
- }, 5e3), ge = 1024 * 1024;
3120
+ }, 5e3), ye = 1024 * 1024;
3121
3121
  try {
3122
- const G = C.headers.get("X-Thread-Id") || C.headers.get("x-thread-id"), ne = C.headers.get("X-Run-Id") || C.headers.get("x-run-id");
3122
+ const G = C.headers.get("X-Thread-Id") || C.headers.get("x-thread-id"), se = C.headers.get("X-Run-Id") || C.headers.get("x-run-id");
3123
3123
  for (A.current && (A.current = {
3124
3124
  ...A.current,
3125
3125
  threadId: G ?? A.current.threadId,
3126
- runId: ne ?? A.current.runId
3126
+ runId: se ?? A.current.runId
3127
3127
  }); ; ) {
3128
- const { value: me, done: X } = await P.read();
3128
+ const { value: he, done: X } = await P.read();
3129
3129
  if (X) break;
3130
- K += J.decode(me, { stream: !0 }), K.length > ge && (K = "", console.warn("Stream buffer reset: exceeded 1MB"));
3131
- let Y;
3132
- for (; (Y = K.indexOf(`
3130
+ K += J.decode(he, { stream: !0 }), K.length > ye && (K = "", console.warn("Stream buffer reset: exceeded 1MB"));
3131
+ let Q;
3132
+ for (; (Q = K.indexOf(`
3133
3133
 
3134
3134
  `)) >= 0; ) {
3135
- const ye = K.slice(0, Y);
3136
- K = K.slice(Y + 2);
3137
- const Ve = ye.split(/\r?\n/), he = [];
3135
+ const be = K.slice(0, Q);
3136
+ K = K.slice(Q + 2);
3137
+ const Ve = be.split(/\r?\n/), we = [];
3138
3138
  let Pe = null;
3139
- for (const xe of Ve)
3140
- if (!xe.startsWith(":") && xe) {
3141
- if (xe.startsWith("event:")) {
3142
- const Ae = xe.slice(6).trim();
3139
+ for (const ce of Ve)
3140
+ if (!ce.startsWith(":") && ce) {
3141
+ if (ce.startsWith("event:")) {
3142
+ const Ae = ce.slice(6).trim();
3143
3143
  Ae && (Pe = Ae);
3144
3144
  continue;
3145
3145
  }
3146
- if (xe.startsWith("data:")) {
3147
- const Ae = xe.slice(5);
3148
- he.push(Ae.startsWith(" ") ? Ae.slice(1) : Ae);
3146
+ if (ce.startsWith("data:")) {
3147
+ const Ae = ce.slice(5);
3148
+ we.push(Ae.startsWith(" ") ? Ae.slice(1) : Ae);
3149
3149
  }
3150
3150
  }
3151
- const be = he.join(`
3151
+ const ke = we.join(`
3152
3152
  `);
3153
- if (!be) continue;
3154
- let oe;
3153
+ if (!ke) continue;
3154
+ let ne;
3155
3155
  try {
3156
- oe = JSON.parse(be);
3156
+ ne = JSON.parse(ke);
3157
3157
  } catch {
3158
- console.debug("[use-chat] malformed SSE:", be.slice(0, 200));
3158
+ console.debug("[use-chat] malformed SSE:", ke.slice(0, 200));
3159
3159
  continue;
3160
3160
  }
3161
- oe = fr(Pe, oe);
3162
- const Ue = cr(oe) ? oe.data : oe;
3161
+ ne = fr(Pe, ne);
3162
+ const Ue = cr(ne) ? ne.data : ne;
3163
3163
  if (!Ue) {
3164
- console.warn("[use-chat] dropped envelope event without payload", oe);
3164
+ console.warn("[use-chat] dropped envelope event without payload", ne);
3165
3165
  continue;
3166
3166
  }
3167
3167
  const re = $n(Ue);
3168
3168
  ee = Date.now();
3169
- const we = typeof re.seq == "number" ? re.seq : void 0;
3170
- if (we !== void 0) {
3171
- if (we <= V) {
3172
- console.debug("[use-chat] drop duplicate/out-of-order event", { seq: we, lastProcessedSeq: V, type: re.type });
3169
+ const te = typeof re.seq == "number" ? re.seq : void 0;
3170
+ if (te !== void 0) {
3171
+ if (te <= V) {
3172
+ console.debug("[use-chat] drop duplicate/out-of-order event", { seq: te, lastProcessedSeq: V, type: re.type });
3173
3173
  continue;
3174
3174
  }
3175
- V = we;
3175
+ V = te;
3176
3176
  }
3177
3177
  d(re);
3178
3178
  }
@@ -3182,8 +3182,8 @@ function pr(e = {}) {
3182
3182
  if (G.name === "AbortError")
3183
3183
  U = U ?? "aborted";
3184
3184
  else {
3185
- const ne = G.message || String(G);
3186
- U = "error", p(ne);
3185
+ const se = G.message || String(G);
3186
+ U = "error", p(se);
3187
3187
  }
3188
3188
  } finally {
3189
3189
  try {
@@ -3192,7 +3192,7 @@ function pr(e = {}) {
3192
3192
  } finally {
3193
3193
  (R = P.releaseLock) == null || R.call(P);
3194
3194
  }
3195
- clearInterval(ae);
3195
+ clearInterval(ie);
3196
3196
  }
3197
3197
  } catch (B) {
3198
3198
  if (B.name === "AbortError")
@@ -3222,7 +3222,7 @@ function pr(e = {}) {
3222
3222
  },
3223
3223
  [t, n, r, e, d]
3224
3224
  );
3225
- return Q(() => () => {
3225
+ return Y(() => () => {
3226
3226
  var m;
3227
3227
  S.current = !1, (m = x.current) == null || m.abort();
3228
3228
  }, []), {
@@ -3260,9 +3260,9 @@ function gr({
3260
3260
  onCurrentThreadDeleted: o
3261
3261
  }) {
3262
3262
  const [s, a] = D([]), [i, d] = D(t), [c, l] = D(!1), [f, p] = D(null), g = H(i), I = H(/* @__PURE__ */ new Map());
3263
- Q(() => {
3263
+ Y(() => {
3264
3264
  g.current = i;
3265
- }, [i]), Q(() => {
3265
+ }, [i]), Y(() => {
3266
3266
  t !== void 0 && t !== g.current && d(t);
3267
3267
  }, [t]);
3268
3268
  const u = N(async () => {
@@ -3277,9 +3277,9 @@ function gr({
3277
3277
  l(!1);
3278
3278
  }
3279
3279
  }, [e, n]);
3280
- Q(() => {
3280
+ Y(() => {
3281
3281
  u();
3282
- }, [u]), Q(() => {
3282
+ }, [u]), Y(() => {
3283
3283
  r == null || r(i);
3284
3284
  }, [i, r]);
3285
3285
  const v = N(
@@ -3403,7 +3403,7 @@ function mr({
3403
3403
  p
3404
3404
  ]
3405
3405
  );
3406
- return /* @__PURE__ */ ce(Ut.Provider, { value: g, children: e });
3406
+ return /* @__PURE__ */ de(Ut.Provider, { value: g, children: e });
3407
3407
  }
3408
3408
  function ot(e) {
3409
3409
  const t = je(Ut);
@@ -3763,7 +3763,7 @@ function xr(e, t, n) {
3763
3763
  let s = n ? [...e.taskMessagesByScope[o] || []] : [...e.messages];
3764
3764
  const a = st(s, r);
3765
3765
  if (a !== -1) {
3766
- const i = s[a], d = le(t.content), c = (i.toolCalls || []).map(
3766
+ const i = s[a], d = ue(t.content), c = (i.toolCalls || []).map(
3767
3767
  (l) => l.id === r ? { ...l, content: typeof d == "string" ? d : l.content } : l
3768
3768
  );
3769
3769
  s[a] = {
@@ -3784,7 +3784,7 @@ function Ar(e, t, n) {
3784
3784
  if (!r) return e;
3785
3785
  const o = typeof t.scope == "string" && t.scope.length > 0 ? t.scope : "task";
3786
3786
  let s = n ? [...e.taskMessagesByScope[o] || []] : [...e.messages];
3787
- const a = st(s, r), i = le(t.content ?? t.error);
3787
+ const a = st(s, r), i = ue(t.content ?? t.error);
3788
3788
  if (a !== -1) {
3789
3789
  const c = s[a], l = (c.toolCalls || []).map(
3790
3790
  (f) => f.id === r ? {
@@ -3857,7 +3857,7 @@ function gt(e) {
3857
3857
  async function Mr(e, t) {
3858
3858
  var i, d;
3859
3859
  if (!e) return e ?? null;
3860
- const n = de(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], o = /* @__PURE__ */ new Set();
3860
+ const n = fe(e), r = Array.isArray(n.checkpoints) ? n.checkpoints : n.checkpoints ? Object.values(n.checkpoints) : [], o = /* @__PURE__ */ new Set();
3861
3861
  for (const c of r) {
3862
3862
  const l = (i = c == null ? void 0 : c.values) == null ? void 0 : i.messages;
3863
3863
  if (Array.isArray(l))
@@ -3876,7 +3876,7 @@ async function Mr(e, t) {
3876
3876
  const s = await Promise.all(
3877
3877
  Array.from(o).map(async (c) => {
3878
3878
  try {
3879
- const l = await t.getFileInfo(c), f = de(l);
3879
+ const l = await t.getFileInfo(c), f = fe(l);
3880
3880
  return [c, f];
3881
3881
  } catch {
3882
3882
  return [c, null];
@@ -3901,7 +3901,7 @@ async function Mr(e, t) {
3901
3901
  return n;
3902
3902
  }
3903
3903
  function mt(e) {
3904
- const r = [...(Array.isArray(e == null ? void 0 : e.checkpoints) ? (e == null ? void 0 : e.checkpoints) ?? [] : e != null && e.checkpoints ? Object.values(e.checkpoints) : []).map((s, a) => Cr(de(s), a)).filter((s) => !!s)].sort((s, a) => yt(a.createdAt) - yt(s.createdAt)), o = r[0] ?? null;
3904
+ const r = [...(Array.isArray(e == null ? void 0 : e.checkpoints) ? (e == null ? void 0 : e.checkpoints) ?? [] : e != null && e.checkpoints ? Object.values(e.checkpoints) : []).map((s, a) => Cr(fe(s), a)).filter((s) => !!s)].sort((s, a) => yt(a.createdAt) - yt(s.createdAt)), o = r[0] ?? null;
3905
3905
  return {
3906
3906
  threadId: (e == null ? void 0 : e.threadId) ?? "",
3907
3907
  latest: o,
@@ -4085,7 +4085,7 @@ function $t({
4085
4085
  () => mt(d),
4086
4086
  [d]
4087
4087
  ).checkpoints, p = Rr(f), g = p.timeline, [I, u] = D(!1), [v, x] = D(!1), [S, A] = D(!1), [w, b] = D(null), y = H(o), T = H(null), m = H(null);
4088
- Q(() => {
4088
+ Y(() => {
4089
4089
  y.current = o;
4090
4090
  }, [o]);
4091
4091
  const k = N(
@@ -4177,7 +4177,7 @@ function $t({
4177
4177
  },
4178
4178
  [o]
4179
4179
  );
4180
- Q(() => {
4180
+ Y(() => {
4181
4181
  if (!s || !o || I || a) return;
4182
4182
  const _ = `${o}:latest`;
4183
4183
  T.current !== _ && E(o);
@@ -4368,7 +4368,7 @@ function jr({
4368
4368
  }),
4369
4369
  [F, O]
4370
4370
  );
4371
- return /* @__PURE__ */ ce(Kt.Provider, { value: C, children: /* @__PURE__ */ ce(Dt.Provider, { value: j, children: e }) });
4371
+ return /* @__PURE__ */ de(Kt.Provider, { value: C, children: /* @__PURE__ */ de(Dt.Provider, { value: j, children: e }) });
4372
4372
  }
4373
4373
  const qt = Ce(null), Ur = Ce(!1);
4374
4374
  function Br({
@@ -4383,7 +4383,7 @@ function Br({
4383
4383
  onFinish: d,
4384
4384
  onStreamingChange: c
4385
4385
  }) {
4386
- const { chatApi: l, baseUrl: f } = Me(), p = f, g = fe(t), I = fe(n), u = fe(r), v = fe(o), x = fe(s), S = fe(a), A = fe(i), w = fe(d), b = fe(c), y = Z(
4386
+ const { chatApi: l, baseUrl: f } = Me(), p = f, g = ge(t), I = ge(n), u = ge(r), v = ge(o), x = ge(s), S = ge(a), A = ge(i), w = ge(d), b = ge(c), y = Z(
4387
4387
  () => ({
4388
4388
  onError: g,
4389
4389
  onAuthError: I,
@@ -4405,7 +4405,7 @@ function Br({
4405
4405
  w
4406
4406
  ]
4407
4407
  );
4408
- return /* @__PURE__ */ ce(Ur.Provider, { value: !0, children: /* @__PURE__ */ ce(
4408
+ return /* @__PURE__ */ de(Ur.Provider, { value: !0, children: /* @__PURE__ */ de(
4409
4409
  Fr,
4410
4410
  {
4411
4411
  api: l,
@@ -4456,11 +4456,11 @@ function Fr({
4456
4456
  onToolEnd: r.onToolEnd,
4457
4457
  handleValuesEvent: p
4458
4458
  });
4459
- Q(() => {
4459
+ Y(() => {
4460
4460
  o == null || o(y.isStreaming);
4461
4461
  }, [y.isStreaming, o]);
4462
4462
  const { stream: T, stop: m, clear: k, isStreaming: E, error: U, connected: M, activeMessageId: $ } = y;
4463
- Q(() => {
4463
+ Y(() => {
4464
4464
  d !== void 0 && k();
4465
4465
  }, [d, k]);
4466
4466
  const F = N(
@@ -4469,37 +4469,37 @@ function Fr({
4469
4469
  },
4470
4470
  [T]
4471
4471
  ), _ = H(l);
4472
- Q(() => {
4472
+ Y(() => {
4473
4473
  _.current = l;
4474
4474
  }, [l]);
4475
4475
  const O = N(
4476
4476
  async (h, j, C) => {
4477
- var ge;
4477
+ var ye;
4478
4478
  const P = a.current;
4479
4479
  if (!P)
4480
4480
  throw new Error("No active thread to handle interrupt");
4481
- const J = h ? j ?? !0 : !1, K = _.current, V = (C == null ? void 0 : C.checkpointId) ?? K.id ?? void 0, ee = (C == null ? void 0 : C.checkpointNs) ?? K.namespace ?? void 0, ae = {
4481
+ const J = h ? j ?? !0 : !1, K = _.current, V = (C == null ? void 0 : C.checkpointId) ?? K.id ?? void 0, ee = (C == null ? void 0 : C.checkpointNs) ?? K.namespace ?? void 0, ie = {
4482
4482
  threadId: P,
4483
4483
  checkpointId: V,
4484
4484
  checkpointNs: ee,
4485
4485
  command: { kind: "resume", value: J },
4486
4486
  payload: {
4487
4487
  ...(C == null ? void 0 : C.payload) ?? {},
4488
- creativityLevel: ((ge = C == null ? void 0 : C.payload) == null ? void 0 : ge.creativityLevel) ?? "medium"
4488
+ creativityLevel: ((ye = C == null ? void 0 : C.payload) == null ? void 0 : ye.creativityLevel) ?? "medium"
4489
4489
  },
4490
4490
  edit: !1
4491
4491
  };
4492
- F(ae);
4492
+ F(ie);
4493
4493
  },
4494
4494
  [a, F]
4495
4495
  );
4496
- Q(() => {
4496
+ Y(() => {
4497
4497
  w(O);
4498
4498
  }, [O, w]);
4499
4499
  const R = N(async () => {
4500
4500
  m(), k(), u(), s(null);
4501
4501
  }, [k, u, s, m]);
4502
- Q(() => {
4502
+ Y(() => {
4503
4503
  A(R);
4504
4504
  }, [R, A]);
4505
4505
  const W = N(
@@ -4508,47 +4508,57 @@ function Fr({
4508
4508
  let C = a.current;
4509
4509
  const P = (h == null ? void 0 : h.text) ?? "", J = (h == null ? void 0 : h.attachments) ?? [], K = (P == null ? void 0 : P.trim()) ?? "", V = { ...(h == null ? void 0 : h.payload) ?? {} }, ee = Array.isArray(V.messages) ? V.messages : void 0;
4510
4510
  ee && delete V.messages;
4511
- const ae = !!(ee && ee.length), ge = !!(h.contentParts && h.contentParts.length > 0);
4512
- if (!C && !K && J.length === 0 && !ae && !ge) return;
4511
+ const ie = !!(ee && ee.length), ye = !!(h.contentParts && h.contentParts.length > 0);
4512
+ if (!C && !K && J.length === 0 && !ie && !ye) return;
4513
4513
  if (!C) {
4514
- const re = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), we = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4515
- C = `${re}${we}`, g(C), s(C);
4514
+ const re = Math.floor(Date.now() / 1e3).toString(16).padStart(8, "0"), te = Array.from({ length: 4 }, () => Math.floor(Math.random() * 4294967295).toString(16).padStart(8, "0")).join("").slice(0, 16);
4515
+ C = `${re}${te}`, g(C), s(C);
4516
4516
  }
4517
4517
  let G = null;
4518
4518
  h.contentParts && h.contentParts.length > 0 && (G = h.contentParts);
4519
- const { contentParts: ne, filesInfo: me } = G ? { contentParts: G, filesInfo: [] } : await or(J), X = [...ne];
4519
+ const { contentParts: se, filesInfo: he } = G ? { contentParts: G, filesInfo: [] } : await or(J), X = [...se];
4520
4520
  K && X.push({ type: "text", text: P });
4521
- const Y = h == null ? void 0 : h.originalMessageId, ye = !!(h != null && h.edit && Y), Ve = !ae && X.length > 0;
4522
- let he = null;
4521
+ const Q = h == null ? void 0 : h.originalMessageId, be = !!(h != null && h.edit && Q), Ve = !ie && X.length > 0;
4522
+ let we = null;
4523
4523
  if (Ve) {
4524
- const re = ye ? Y : `msg-${Date.now()}`;
4525
- he = jt({
4524
+ const re = be ? Q : `msg-${Date.now()}`;
4525
+ we = jt({
4526
4526
  id: re,
4527
4527
  role: "user",
4528
4528
  content: X,
4529
4529
  createdAt: (/* @__PURE__ */ new Date()).toISOString()
4530
- }, "user"), ye ? v(he, { editingMessageId: Y }) : v(he);
4530
+ }, "user"), be ? v(we, { editingMessageId: Q }) : v(we);
4531
4531
  }
4532
- const Pe = ae ? ee : he ? [he] : [], be = {
4532
+ const Pe = ie ? ee : we ? [we] : [], ke = {
4533
4533
  ...V,
4534
- ...me.length ? { files_info: me } : {}
4534
+ ...he.length ? { files_info: he } : {}
4535
4535
  };
4536
- Pe.length ? be.messages = Pe : "messages" in be || (be.messages = []);
4537
- let oe = (h == null ? void 0 : h.checkpointId) ?? l.id ?? void 0;
4538
- if (ye && !oe) {
4539
- const re = S.find((we) => we.id === Y);
4540
- re != null && re.checkpointId && (oe = re.checkpointId);
4536
+ Pe.length ? ke.messages = Pe : "messages" in ke || (ke.messages = []);
4537
+ let ne = (h == null ? void 0 : h.checkpointId) ?? l.id ?? void 0;
4538
+ if (be) {
4539
+ const re = S.find((te) => te.id === Q);
4540
+ if (re)
4541
+ if (re.checkpointId)
4542
+ ne = re.checkpointId;
4543
+ else {
4544
+ const te = re.additionalKwargs || re.additional_kwargs || {}, ce = te.checkpoint_id || te.checkpointId;
4545
+ ce && (ne = ce);
4546
+ }
4547
+ if (!ne) {
4548
+ const te = S.findIndex((ce) => ce.id === Q);
4549
+ te > 0 && S[te - 1].checkpointId && (ne = S[te - 1].checkpointId ?? void 0);
4550
+ }
4541
4551
  }
4542
- if (h != null && h.edit && !oe)
4552
+ if (h != null && h.edit && !ne)
4543
4553
  throw new Error(
4544
4554
  `[streaming] Missing checkpointId for edit submit. threadId=${C ?? "null"}. Ensure you are editing a message that has been saved.`
4545
4555
  );
4546
4556
  const Ue = {
4547
4557
  threadId: C,
4548
4558
  content: h == null ? void 0 : h.text,
4549
- payload: be,
4559
+ payload: ke,
4550
4560
  config: h == null ? void 0 : h.config,
4551
- checkpointId: oe,
4561
+ checkpointId: ne,
4552
4562
  command: h == null ? void 0 : h.command,
4553
4563
  edit: h == null ? void 0 : h.edit
4554
4564
  };
@@ -4573,11 +4583,11 @@ function Fr({
4573
4583
  }),
4574
4584
  [E, U, W, m, c, M, B]
4575
4585
  );
4576
- return /* @__PURE__ */ ce(qt.Provider, { value: L, children: e });
4586
+ return /* @__PURE__ */ de(qt.Provider, { value: L, children: e });
4577
4587
  }
4578
- function fe(e) {
4588
+ function ge(e) {
4579
4589
  const t = H(e);
4580
- return Q(() => {
4590
+ return Y(() => {
4581
4591
  t.current = e;
4582
4592
  }, [e]), N((...n) => {
4583
4593
  const r = t.current;
@@ -4634,7 +4644,7 @@ function po({
4634
4644
  onMetadataEvent: g,
4635
4645
  onFinish: I
4636
4646
  }) {
4637
- const u = Dr(t), [v, x] = D(!1), S = pe(i), A = pe(d), w = pe(a), b = pe(c), y = pe(l), T = pe(f), m = pe(p), k = pe(g), E = pe(I), U = Z(
4647
+ const u = Dr(t), [v, x] = D(!1), S = me(i), A = me(d), w = me(a), b = me(c), y = me(l), T = me(f), m = me(p), k = me(g), E = me(I), U = Z(
4638
4648
  () => ({
4639
4649
  onError: S,
4640
4650
  onAuthError: A,
@@ -4656,13 +4666,13 @@ function po({
4656
4666
  E
4657
4667
  ]
4658
4668
  );
4659
- return /* @__PURE__ */ ce(nr, { apiConfig: u, children: /* @__PURE__ */ ce(
4669
+ return /* @__PURE__ */ de(nr, { apiConfig: u, children: /* @__PURE__ */ de(
4660
4670
  mr,
4661
4671
  {
4662
4672
  initialThreadId: n,
4663
4673
  onError: S,
4664
4674
  onThreadChange: b,
4665
- children: /* @__PURE__ */ ce(
4675
+ children: /* @__PURE__ */ de(
4666
4676
  jr,
4667
4677
  {
4668
4678
  initialThreadId: n,
@@ -4671,7 +4681,7 @@ function po({
4671
4681
  autoLoadInitial: s,
4672
4682
  onError: S,
4673
4683
  isStreaming: v,
4674
- children: /* @__PURE__ */ ce(
4684
+ children: /* @__PURE__ */ de(
4675
4685
  Br,
4676
4686
  {
4677
4687
  ...U,
@@ -4684,7 +4694,7 @@ function po({
4684
4694
  }
4685
4695
  ) });
4686
4696
  }
4687
- function pe(e) {
4697
+ function me(e) {
4688
4698
  const t = H(e);
4689
4699
  return t.current = e, N((...n) => {
4690
4700
  const r = t.current;
@@ -4914,7 +4924,7 @@ function yo(e) {
4914
4924
  const s = Qr(r) ?? r[r.length - 1];
4915
4925
  if (!s)
4916
4926
  return null;
4917
- const a = s.output ?? s.payload ?? s, i = le(a);
4927
+ const a = s.output ?? s.payload ?? s, i = ue(a);
4918
4928
  return i && typeof i == "object" && !Array.isArray(i) ? {
4919
4929
  kind: "dict",
4920
4930
  value: i,
@@ -4952,7 +4962,7 @@ function Yr(e) {
4952
4962
  getMessages: () => l,
4953
4963
  autoLoadInitial: c && !n
4954
4964
  });
4955
- Q(() => {
4965
+ Y(() => {
4956
4966
  !c && !n && a && (o != null && o.loadThread) && o.loadThread(a);
4957
4967
  }, [c, n, a, o == null ? void 0 : o.loadThread]);
4958
4968
  const S = Z(() => {
@@ -5032,7 +5042,7 @@ function ho({
5032
5042
  clearComposerOnSend: g = !0
5033
5043
  }) {
5034
5044
  const { messages: I } = Yr(), [u, v] = D(null), [x, S] = D(""), [A, w] = D(null), [b, y] = D(null), [T, m] = D(!1), [k, E] = D(""), U = H(k), M = H(null);
5035
- Q(() => {
5045
+ Y(() => {
5036
5046
  if (!u)
5037
5047
  if (p) {
5038
5048
  const j = localStorage.getItem(Ge(p));
@@ -5043,9 +5053,9 @@ function ho({
5043
5053
  const $ = N((j) => {
5044
5054
  E(j), !u && p && localStorage.setItem(Ge(p), j);
5045
5055
  }, [p, u]);
5046
- Q(() => {
5056
+ Y(() => {
5047
5057
  U.current = k;
5048
- }, [k]), Q(() => {
5058
+ }, [k]), Y(() => {
5049
5059
  if (!u) {
5050
5060
  M.current = null;
5051
5061
  return;
@@ -5063,24 +5073,24 @@ function ho({
5063
5073
  try {
5064
5074
  const ee = J.map(async (X) => {
5065
5075
  try {
5066
- const Y = await Rt.uploadFile(X);
5067
- return { file: X, record: Y };
5068
- } catch (Y) {
5069
- throw console.error("Failed to upload file", X.name, Y), new Error(`Failed to upload ${X.name}`);
5076
+ const Q = await Rt.uploadFile(X);
5077
+ return { file: X, record: Q };
5078
+ } catch (Q) {
5079
+ throw console.error("Failed to upload file", X.name, Q), new Error(`Failed to upload ${X.name}`);
5070
5080
  }
5071
- }), ge = (await Promise.all(ee)).map(({ record: X }) => {
5072
- const Y = X.mime_type;
5073
- return Y.startsWith("image/") ? {
5081
+ }), ye = (await Promise.all(ee)).map(({ record: X }) => {
5082
+ const Q = X.mime_type;
5083
+ return Q.startsWith("image/") ? {
5074
5084
  type: "image_url",
5075
5085
  image_url: { url: X.content_url }
5076
5086
  } : {
5077
5087
  type: "file",
5078
5088
  url: X.content_url,
5079
- mimeType: Y,
5089
+ mimeType: Q,
5080
5090
  name: X.filename,
5081
5091
  size: X.size
5082
5092
  };
5083
- }), G = [...K, ...ge], ne = u ? (A == null ? void 0 : A.checkpointId) ?? n ?? void 0 : n ?? void 0, me = u ? (A == null ? void 0 : A.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5093
+ }), G = [...K, ...ye], se = u ? (A == null ? void 0 : A.checkpointId) ?? n ?? void 0 : n ?? void 0, he = u ? (A == null ? void 0 : A.checkpointNs) ?? r ?? void 0 : r ?? void 0;
5084
5094
  await e(
5085
5095
  {
5086
5096
  text: V || "",
@@ -5088,8 +5098,8 @@ function ho({
5088
5098
  attachments: J,
5089
5099
  payload: t.payload,
5090
5100
  edit: !!u,
5091
- checkpointId: ne,
5092
- checkpointNs: me,
5101
+ checkpointId: se,
5102
+ checkpointNs: he,
5093
5103
  project: l ?? void 0,
5094
5104
  originalMessageId: u ?? void 0,
5095
5105
  config: t.config
@@ -5097,8 +5107,8 @@ function ho({
5097
5107
  f ? { onEvent: f } : void 0
5098
5108
  ), o == null || o(V), c(!0), g && (p && localStorage.removeItem(Ge(p)), $("")), y(null), v(null), S(""), w(null);
5099
5109
  } catch (ee) {
5100
- const ae = (ee == null ? void 0 : ee.message) || "Failed to send message";
5101
- y(ae), a == null || a(ae), c(!1);
5110
+ const ie = (ee == null ? void 0 : ee.message) || "Failed to send message";
5111
+ y(ie), a == null || a(ie), c(!1);
5102
5112
  }
5103
5113
  }, O = (j, C) => {
5104
5114
  C || _(j, { files: [] });
@@ -5192,7 +5202,7 @@ function bo(e) {
5192
5202
  }
5193
5203
  function wo(e, t, n) {
5194
5204
  const [r, o] = D(e), s = H(e), a = H(null);
5195
- return Q(() => {
5205
+ return Y(() => {
5196
5206
  s.current = e;
5197
5207
  const i = () => {
5198
5208
  o(s.current), a.current && (clearTimeout(a.current), a.current = null);
@@ -5234,7 +5244,7 @@ export {
5234
5244
  Et as pretty,
5235
5245
  Mr as refreshHistoryFileUrls,
5236
5246
  De as sanitizeForDisplay,
5237
- ve as setChatToken,
5247
+ xe as setChatToken,
5238
5248
  Fn as stringifyTool,
5239
5249
  Me as useApi,
5240
5250
  ho as useChatController,