@takeshape/purchase-order-chat 1.60.0 → 1.60.2

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.
@@ -1,4 +1,4 @@
1
- import { useState as D, useEffect as F, createElement as Or, useRef as R, useLayoutEffect as xt, useCallback as B, createContext as Dr, useContext as Lr, useMemo as oe, forwardRef as Rr, useImperativeHandle as _r } from "react";
1
+ import { useState as R, useEffect as F, createElement as Or, useRef as D, useLayoutEffect as xt, useCallback as B, createContext as Rr, useContext as Dr, useMemo as oe, forwardRef as Lr, useImperativeHandle as _r } from "react";
2
2
  import { jsxs as p, jsx as a, Fragment as ve } from "react/jsx-runtime";
3
3
  import { GraphQLClient as at, ClientError as Ur } from "graphql-request";
4
4
  import { initGraphQLTada as Vt, readFragment as Ne } from "gql.tada";
@@ -22,8 +22,8 @@ function Vi(t, e) {
22
22
  return i != null ? String(i) : "";
23
23
  });
24
24
  }
25
- const Yr = "__vite_c_css_pos_initial_648f0c526ee84f978742d80f0489cbe8", vt = "__vite_c_css_pos_update_648f0c526ee84f978742d80f0489cbe8", Ct = () => typeof window < "u" ? window[Yr] : void 0, zi = (t) => {
26
- const [e, r] = D(() => Ct() || /* @__PURE__ */ new Map()), [n, i] = D(0);
25
+ const Yr = "__vite_c_css_pos_initial_01a5a5f6a7504c91b86d80b970afaddc", vt = "__vite_c_css_pos_update_01a5a5f6a7504c91b86d80b970afaddc", Ct = () => typeof window < "u" ? window[Yr] : void 0, zi = (t) => {
26
+ const [e, r] = R(() => Ct() || /* @__PURE__ */ new Map()), [n, i] = R(0);
27
27
  return F(() => {
28
28
  const s = (o) => {
29
29
  const c = Ct() || /* @__PURE__ */ new Map();
@@ -864,7 +864,7 @@ function We(t, e) {
864
864
  };
865
865
  }
866
866
  const En = 20;
867
- async function De(t, e, r, n) {
867
+ async function Re(t, e, r, n) {
868
868
  const i = [];
869
869
  let s, o = 0;
870
870
  for (; o < En; ) {
@@ -879,7 +879,7 @@ async function De(t, e, r, n) {
879
879
  return i;
880
880
  }
881
881
  const xe = 20;
882
- function Le(t) {
882
+ function De(t) {
883
883
  return Ne($e, t);
884
884
  }
885
885
  function Ve(t) {
@@ -983,7 +983,7 @@ class Pn {
983
983
  cartEntityId: e
984
984
  }
985
985
  })).site.cart;
986
- return n ? Le(n) : null;
986
+ return n ? De(n) : null;
987
987
  }
988
988
  /**
989
989
  * Create a new cart with line items
@@ -1058,7 +1058,7 @@ class Pn {
1058
1058
  },
1059
1059
  { retry: n }
1060
1060
  )).cart.addCartLineItems?.cart;
1061
- return s ? Le(s) : null;
1061
+ return s ? De(s) : null;
1062
1062
  }
1063
1063
  /**
1064
1064
  * Try to add a batch to cart, isolating failures if needed.
@@ -1109,7 +1109,7 @@ class Pn {
1109
1109
  },
1110
1110
  { retry: r }
1111
1111
  )).cart.createCart?.cart;
1112
- return i ? Le(i) : null;
1112
+ return i ? De(i) : null;
1113
1113
  }
1114
1114
  /**
1115
1115
  * Try to create a cart with a batch, isolating failures if needed.
@@ -1191,7 +1191,7 @@ class Pn {
1191
1191
  }
1192
1192
  }
1193
1193
  })).cart.updateCartLineItem?.cart;
1194
- return c ? Le(c) : null;
1194
+ return c ? De(c) : null;
1195
1195
  }
1196
1196
  /**
1197
1197
  * Remove a line item from the cart
@@ -1206,7 +1206,7 @@ class Pn {
1206
1206
  }
1207
1207
  }
1208
1208
  })).cart.deleteCartLineItem?.cart;
1209
- return i ? Le(i) : null;
1209
+ return i ? De(i) : null;
1210
1210
  }
1211
1211
  /**
1212
1212
  * Delete an entire cart
@@ -1335,7 +1335,7 @@ class Pn {
1335
1335
  email: e.customer.email
1336
1336
  }, n = [...e.customer.addresses.edges ?? []];
1337
1337
  if (e.customer.addresses.pageInfo.hasNextPage) {
1338
- const s = await De(
1338
+ const s = await Re(
1339
1339
  this,
1340
1340
  wt,
1341
1341
  { after: e.customer.addresses.pageInfo.endCursor },
@@ -1387,7 +1387,7 @@ class Pn {
1387
1387
  for (const i of r.site.products.edges ?? []) {
1388
1388
  const s = i.node, o = [...s.variants.edges ?? []];
1389
1389
  if (s.variants.pageInfo.hasNextPage) {
1390
- const d = await De(
1390
+ const d = await Re(
1391
1391
  this,
1392
1392
  vn,
1393
1393
  {
@@ -1400,7 +1400,7 @@ class Pn {
1400
1400
  }
1401
1401
  const c = [...s.productOptions.edges ?? []];
1402
1402
  if (s.productOptions.pageInfo.hasNextPage) {
1403
- const d = await De(
1403
+ const d = await Re(
1404
1404
  this,
1405
1405
  Cn,
1406
1406
  {
@@ -1415,7 +1415,7 @@ class Pn {
1415
1415
  for (const d of c) {
1416
1416
  const h = d.node;
1417
1417
  if (h.values?.pageInfo.hasNextPage && h.values.pageInfo.endCursor) {
1418
- const u = await De(
1418
+ const u = await Re(
1419
1419
  this,
1420
1420
  wn,
1421
1421
  {
@@ -1502,7 +1502,7 @@ class Pn {
1502
1502
  for (const i of r.site.products.edges ?? []) {
1503
1503
  const s = i.node, o = [...s.variants.edges ?? []];
1504
1504
  if (s.variants.pageInfo.hasNextPage) {
1505
- const c = await De(
1505
+ const c = await Re(
1506
1506
  this,
1507
1507
  bn,
1508
1508
  {
@@ -1538,14 +1538,14 @@ function Qi(t) {
1538
1538
  function Tn(t) {
1539
1539
  return new Pn(t);
1540
1540
  }
1541
- const Re = it((t) => ({
1541
+ const Le = it((t) => ({
1542
1542
  isExpanded: !1,
1543
1543
  setExpanded: (e) => t({ isExpanded: e }),
1544
1544
  toggleExpanded: () => t((e) => ({ isExpanded: !e.isExpanded })),
1545
1545
  reset: () => t({ isExpanded: !1 })
1546
1546
  }));
1547
1547
  function An({ children: t }) {
1548
- const e = Re((i) => i.isExpanded), r = Re((i) => i.setExpanded), n = R(null);
1548
+ const e = Le((i) => i.isExpanded), r = Le((i) => i.setExpanded), n = D(null);
1549
1549
  return F(() => {
1550
1550
  if (!e) return;
1551
1551
  const i = (s) => {
@@ -1635,7 +1635,7 @@ async function On(t, e) {
1635
1635
  const m = await d.convertToBlob({ type: "image/jpeg", quality: e });
1636
1636
  return new File([m], tr(t.name), { type: "image/jpeg" });
1637
1637
  }
1638
- async function Dn(t) {
1638
+ async function Rn(t) {
1639
1639
  if (!er(t)) return t;
1640
1640
  console.debug("heic file detected, attempting to convert");
1641
1641
  const e = 0.9, r = await Fn(t, e);
@@ -1654,7 +1654,7 @@ const rr = {
1654
1654
  "image/webp": ".webp",
1655
1655
  "image/heic": ".heic",
1656
1656
  "image/heif": ".heif"
1657
- }, Ln = Object.keys(rr), Rn = Object.values(rr).flatMap(
1657
+ }, Dn = Object.keys(rr), Ln = Object.values(rr).flatMap(
1658
1658
  (t) => t.split(",")
1659
1659
  ), _n = [
1660
1660
  ".png",
@@ -1669,14 +1669,14 @@ const rr = {
1669
1669
  ".tif",
1670
1670
  ".svg",
1671
1671
  ".avif"
1672
- ], nr = Rn.join(","), sr = "image/png,image/jpeg,image/gif,image/webp", Un = "PDF, Excel, CSV, text, or image files", qn = "PNG, JPEG, GIF, or WebP", ar = ["PDF", "Excel", "CSV", "Images"], jn = 10 * 1024 * 1024;
1672
+ ], nr = Ln.join(","), sr = "image/png,image/jpeg,image/gif,image/webp", Un = "PDF, Excel, CSV, text, or image files", qn = "PNG, JPEG, GIF, or WebP", ar = ["PDF", "Excel", "CSV", "Images"], jn = 10 * 1024 * 1024;
1673
1673
  function Wn(t) {
1674
1674
  if (t.size > jn)
1675
1675
  return {
1676
1676
  valid: !1,
1677
1677
  error: "File size exceeds 10MB limit. Please choose a smaller file."
1678
1678
  };
1679
- if (!Ln.includes(t.type)) {
1679
+ if (!Dn.includes(t.type)) {
1680
1680
  const e = t.name.includes(".") ? `.${t.name.split(".").pop()?.toLowerCase()}` : void 0;
1681
1681
  return t.type.startsWith("image/") || e && _n.includes(e) ? {
1682
1682
  valid: !1,
@@ -1689,13 +1689,13 @@ function Wn(t) {
1689
1689
  return { valid: !0 };
1690
1690
  }
1691
1691
  function ir({ onFile: t, onBeforeValidate: e }) {
1692
- const [r, n] = D(!1), [i, s] = D(null), o = R(null), c = R(null), l = B(
1692
+ const [r, n] = R(!1), [i, s] = R(null), o = D(null), c = D(null), l = B(
1693
1693
  async (x) => {
1694
1694
  e?.(), s(null);
1695
1695
  let v = x;
1696
1696
  if (er(x))
1697
1697
  try {
1698
- v = await Dn(x);
1698
+ v = await Rn(x);
1699
1699
  } catch {
1700
1700
  s(
1701
1701
  "Failed to convert HEIC image. Please convert to JPEG and try again."
@@ -2010,7 +2010,7 @@ function Hn(t) {
2010
2010
  return t.postalCode ? e.push(`${r} ${t.postalCode}`) : r && e.push(r), e.join(", ");
2011
2011
  }
2012
2012
  function Gn({ address: t }) {
2013
- const [e, r] = D(!1), n = R(void 0);
2013
+ const [e, r] = R(!1), n = D(void 0);
2014
2014
  F(() => () => {
2015
2015
  n.current && clearTimeout(n.current);
2016
2016
  }, []);
@@ -2157,9 +2157,9 @@ function dr({
2157
2157
  asyncMode: s = !1,
2158
2158
  testId: o
2159
2159
  }) {
2160
- const [c, l] = D(String(t)), [d, h] = D(
2160
+ const [c, l] = R(String(t)), [d, h] = R(
2161
2161
  "idle"
2162
- ), u = R(null);
2162
+ ), u = D(null);
2163
2163
  F(() => () => {
2164
2164
  u.current && clearTimeout(u.current);
2165
2165
  }, []), F(() => {
@@ -2404,24 +2404,45 @@ function _e({
2404
2404
  );
2405
2405
  }
2406
2406
  function ur({ onNewOrder: t }) {
2407
- const [e, r] = D(!1), n = R(
2407
+ const [e, r] = R(!1), [n, i] = R(!1), s = D(!0), o = D(
2408
2408
  void 0
2409
- ), i = () => {
2410
- e || (r(!0), n.current = setTimeout(() => r(!1), 3e3));
2411
- }, s = () => {
2412
- n.current && clearTimeout(n.current), r(!1), t();
2413
- }, o = () => {
2414
- n.current && clearTimeout(n.current), r(!1);
2409
+ ), c = () => {
2410
+ e || (r(!0), o.current = setTimeout(() => r(!1), 3e3));
2411
+ }, l = async () => {
2412
+ o.current && clearTimeout(o.current), r(!1), i(!0);
2413
+ try {
2414
+ await t();
2415
+ } finally {
2416
+ s.current && i(!1);
2417
+ }
2418
+ }, d = () => {
2419
+ o.current && clearTimeout(o.current), r(!1);
2415
2420
  };
2416
2421
  return F(() => () => {
2417
- n.current && clearTimeout(n.current);
2418
- }, []), e ? /* @__PURE__ */ p("span", { className: "flex items-center gap-1.5 text-xs animate-[fadeIn_0.15s_ease]", children: [
2422
+ s.current = !1, o.current && clearTimeout(o.current);
2423
+ }, []), n ? /* @__PURE__ */ p("span", { className: "flex items-center gap-1.5 text-xs animate-[fadeIn_0.15s_ease]", children: [
2424
+ /* @__PURE__ */ a(
2425
+ "svg",
2426
+ {
2427
+ width: "14",
2428
+ height: "14",
2429
+ viewBox: "0 0 24 24",
2430
+ fill: "none",
2431
+ stroke: "currentColor",
2432
+ strokeWidth: "2",
2433
+ className: "animate-spin",
2434
+ "aria-hidden": "true",
2435
+ children: /* @__PURE__ */ a("path", { d: "M21 12a9 9 0 1 1-6.219-8.56" })
2436
+ }
2437
+ ),
2438
+ /* @__PURE__ */ a("span", { className: "text-text-tertiary font-medium", children: "Resetting…" })
2439
+ ] }) : e ? /* @__PURE__ */ p("span", { className: "flex items-center gap-1.5 text-xs animate-[fadeIn_0.15s_ease]", children: [
2419
2440
  /* @__PURE__ */ a("span", { className: "text-text-tertiary font-medium", children: "Reset?" }),
2420
2441
  /* @__PURE__ */ a(
2421
2442
  "button",
2422
2443
  {
2423
2444
  type: "button",
2424
- onClick: s,
2445
+ onClick: l,
2425
2446
  className: "min-h-11 min-w-11 px-3 py-1 text-xs font-semibold text-error-text bg-error-bg border border-error/30 rounded hover:bg-error/20 transition-all",
2426
2447
  children: "Yes"
2427
2448
  }
@@ -2430,12 +2451,12 @@ function ur({ onNewOrder: t }) {
2430
2451
  "button",
2431
2452
  {
2432
2453
  type: "button",
2433
- onClick: o,
2454
+ onClick: d,
2434
2455
  className: "min-h-11 min-w-11 px-3 py-1 text-xs font-semibold text-text-tertiary bg-surface-secondary border border-border rounded hover:bg-surface-tertiary transition-all",
2435
2456
  children: "No"
2436
2457
  }
2437
2458
  )
2438
- ] }) : /* @__PURE__ */ p(_e, { onClick: i, title: "Start a new order", children: [
2459
+ ] }) : /* @__PURE__ */ p(_e, { onClick: c, title: "Start a new order", children: [
2439
2460
  /* @__PURE__ */ a(
2440
2461
  "svg",
2441
2462
  {
@@ -3274,7 +3295,7 @@ function ms({
3274
3295
  onExpand: O,
3275
3296
  onMinimize: Q
3276
3297
  }) {
3277
- const [H, z] = D(!1), ae = R(void 0), ee = B(() => {
3298
+ const [H, z] = R(!1), ae = D(void 0), ee = B(() => {
3278
3299
  d && navigator.clipboard.writeText(d).then(() => {
3279
3300
  z(!0), clearTimeout(ae.current), ae.current = setTimeout(() => z(!1), 2e3);
3280
3301
  });
@@ -3617,7 +3638,7 @@ function ks({
3617
3638
  }
3618
3639
  );
3619
3640
  }
3620
- const wr = Dr(
3641
+ const wr = Rr(
3621
3642
  null
3622
3643
  );
3623
3644
  function Ps({
@@ -3627,7 +3648,7 @@ function Ps({
3627
3648
  return /* @__PURE__ */ a(wr.Provider, { value: t, children: e });
3628
3649
  }
3629
3650
  function ft() {
3630
- return Lr(wr);
3651
+ return Dr(wr);
3631
3652
  }
3632
3653
  function Ts(t, e) {
3633
3654
  return qr({
@@ -3738,7 +3759,7 @@ function Mt({
3738
3759
  selections: c,
3739
3760
  onSelectionChange: l
3740
3761
  }) {
3741
- const [d, h] = D(1), [u, m] = D(!1), [S, b] = D(!1), x = i === "horizontal", v = o && c ? mt(o.variants, c) : null, N = v?.entityId ?? t.variantEntityId, I = r.find(
3762
+ const [d, h] = R(1), [u, m] = R(!1), [S, b] = R(!1), x = i === "horizontal", v = o && c ? mt(o.variants, c) : null, N = v?.entityId ?? t.variantEntityId, I = r.find(
3742
3763
  (W) => W.productEntityId === t.productEntityId && W.variantEntityId === N
3743
3764
  ), w = !!I, E = I?.quantity ?? 0, g = v?.sku ?? t.sku, A = v?.prices?.price?.value ?? t.price, $ = v?.inventory?.aggregated?.availableToSell ?? t.availableQuantity, O = $ !== void 0 && $ > 0 && $ < Bs, Q = v?.inventory?.isInStock ?? t.isInStock, H = v !== null ? (
3744
3765
  // Have variant details: check variant stock
@@ -3908,7 +3929,7 @@ function Fs({
3908
3929
  for (const N of d)
3909
3930
  N.productOptions.length > 0 && v.set(N.entityId, N);
3910
3931
  return v;
3911
- }, [d]), [u, m] = D(/* @__PURE__ */ new Map());
3932
+ }, [d]), [u, m] = R(/* @__PURE__ */ new Map());
3912
3933
  F(() => {
3913
3934
  d && m((v) => {
3914
3935
  const N = new Map(v);
@@ -3986,7 +4007,7 @@ function Os({
3986
4007
  onAddToCart: n,
3987
4008
  onViewProduct: i
3988
4009
  }) {
3989
- const s = ft(), [o, c] = D([]), [l, d] = D(!0), [h, u] = D(null), m = e !== "output-available";
4010
+ const s = ft(), [o, c] = R([]), [l, d] = R(!0), [h, u] = R(null), m = e !== "output-available";
3990
4011
  return F(() => {
3991
4012
  async function S() {
3992
4013
  if (!s) {
@@ -4159,14 +4180,14 @@ function Nr({
4159
4180
  }
4160
4181
  ) : null;
4161
4182
  }
4162
- function Ds({
4183
+ function Rs({
4163
4184
  tools: t,
4164
4185
  messageId: e,
4165
4186
  cart: r,
4166
4187
  onAddToCart: n,
4167
4188
  onViewProduct: i
4168
4189
  }) {
4169
- const [s, o] = D(!1);
4190
+ const [s, o] = R(!1);
4170
4191
  return t.length === 0 ? null : /* @__PURE__ */ p("div", { children: [
4171
4192
  /* @__PURE__ */ p(
4172
4193
  "button",
@@ -4217,10 +4238,10 @@ function Ds({
4217
4238
  )
4218
4239
  ] });
4219
4240
  }
4220
- const Ls = bt.object({
4241
+ const Ds = bt.object({
4221
4242
  id: bt.string()
4222
4243
  });
4223
- async function Rs(t, e) {
4244
+ async function Ls(t, e) {
4224
4245
  if (!t.body)
4225
4246
  throw new Error("No response body");
4226
4247
  const r = [], n = /* @__PURE__ */ new Set(), i = [];
@@ -4298,7 +4319,7 @@ async function Er(t, e) {
4298
4319
  );
4299
4320
  }
4300
4321
  const o = await s.json();
4301
- return Ls.parse(o).id;
4322
+ return Ds.parse(o).id;
4302
4323
  }
4303
4324
  async function _s(t, e, r, n) {
4304
4325
  const { sseOrigin: i, projectId: s, apiKey: o } = t, c = await Ee(
@@ -4415,7 +4436,7 @@ function Ft({
4415
4436
  isOpen: e,
4416
4437
  onClose: r
4417
4438
  }) {
4418
- const [n, i] = D(""), [s, o] = D(""), [c, l] = D(""), [d, h] = D("idle"), [u, m] = D(""), S = R(null), b = y(
4439
+ const [n, i] = R(""), [s, o] = R(""), [c, l] = R(""), [d, h] = R("idle"), [u, m] = R(""), S = D(null), b = y(
4419
4440
  (w) => w.takeshapeConfig
4420
4441
  ), x = y((w) => w.chat.threadId), v = y(
4421
4442
  (w) => w.parser.threadId
@@ -4628,7 +4649,7 @@ function Vs({
4628
4649
  (h) => h.ui.expandedMessageIds
4629
4650
  ), o = y(
4630
4651
  (h) => h.toggleMessageExpanded
4631
- ), c = r || s.includes(t), [l, d] = D(!1);
4652
+ ), c = r || s.includes(t), [l, d] = R(!1);
4632
4653
  return r ? /* @__PURE__ */ p("div", { className: "my-2 flex items-center gap-2", children: [
4633
4654
  /* @__PURE__ */ a("div", { className: "flex-1 min-w-0", children: /* @__PURE__ */ a(Qe, { className: "leading-relaxed text-text", plugins: {}, children: n }) }),
4634
4655
  /* @__PURE__ */ a(
@@ -4796,7 +4817,7 @@ function Hs({
4796
4817
  ) : null) })
4797
4818
  ] }) : /* @__PURE__ */ p(ve, { children: [
4798
4819
  Ns(h).map((u, m) => u.type === "tool-group" ? /* @__PURE__ */ a(
4799
- Ds,
4820
+ Rs,
4800
4821
  {
4801
4822
  tools: u.tools,
4802
4823
  messageId: `${t.id}-${m}`,
@@ -4850,7 +4871,7 @@ function Hs({
4850
4871
  );
4851
4872
  }
4852
4873
  function kr() {
4853
- const [t, e] = D(!1);
4874
+ const [t, e] = R(!1);
4854
4875
  return F(() => {
4855
4876
  if (typeof window.matchMedia != "function") {
4856
4877
  e(
@@ -4991,7 +5012,7 @@ function Js() {
4991
5012
  )
4992
5013
  ] }) });
4993
5014
  }
4994
- const Ys = Rr(
5015
+ const Ys = Lr(
4995
5016
  function({
4996
5017
  messages: e,
4997
5018
  input: r,
@@ -5008,7 +5029,7 @@ const Ys = Rr(
5008
5029
  uploadedFileName: S = null,
5009
5030
  fileDrop: b
5010
5031
  }, x) {
5011
- const v = R(null), N = R(!0), [I, w] = D(!1), E = oe(() => {
5032
+ const v = D(null), N = D(!0), [I, w] = R(!1), E = oe(() => {
5012
5033
  for (let g = e.length - 1; g >= 0; g--) {
5013
5034
  const A = e[g];
5014
5035
  if (A?.role === "assistant")
@@ -5093,7 +5114,7 @@ const Ys = Rr(
5093
5114
  )
5094
5115
  ] });
5095
5116
  }
5096
- ), Xs = "purchase-order-chat-user-settings", Zs = 25, Dt = it()(
5117
+ ), Xs = "purchase-order-chat-user-settings", Zs = 25, Rt = it()(
5097
5118
  Ht(
5098
5119
  (t) => ({
5099
5120
  panelWidth: Zs,
@@ -5105,9 +5126,9 @@ const Ys = Rr(
5105
5126
  )
5106
5127
  );
5107
5128
  function ea() {
5108
- const t = Dt((m) => m.panelWidth), e = Dt((m) => m.setPanelWidth), [r, n] = D(
5129
+ const t = Rt((m) => m.panelWidth), e = Rt((m) => m.setPanelWidth), [r, n] = R(
5109
5130
  typeof window < "u" && window.innerWidth >= 1024
5110
- ), i = R(null), s = R(!1), o = R(t);
5131
+ ), i = D(null), s = D(!1), o = D(t);
5111
5132
  F(() => {
5112
5133
  o.current = t;
5113
5134
  }, [t]), F(() => {
@@ -5199,7 +5220,7 @@ function ta({ activeTab: t, onTabChange: e, hasUnread: r }) {
5199
5220
  )
5200
5221
  ] });
5201
5222
  }
5202
- function Lt({
5223
+ function Dt({
5203
5224
  // Chat panel props
5204
5225
  messages: t,
5205
5226
  input: e,
@@ -5242,9 +5263,9 @@ function Lt({
5242
5263
  onMinimize: _,
5243
5264
  className: j = ""
5244
5265
  }) {
5245
- const K = ea(), [J, Pe] = D(
5266
+ const K = ea(), [J, Pe] = R(
5246
5267
  u.length > 0 ? "cart" : "chat"
5247
- ), [fe, me] = D(!1), le = R(t.length), ge = R(J);
5268
+ ), [fe, me] = R(!1), le = D(t.length), ge = D(J);
5248
5269
  ge.current = J;
5249
5270
  const f = t.length === 0 && u.length === 0 && !!h, k = ir({
5250
5271
  onFile: h ?? (() => {
@@ -5388,7 +5409,7 @@ function Lt({
5388
5409
  function ra() {
5389
5410
  const t = ft(), e = y((c) => c.ui.existingCart), r = y(
5390
5411
  (c) => c.confirmClearExistingCart
5391
- ), [n, i] = D(!1), s = oe(
5412
+ ), [n, i] = R(!1), s = oe(
5392
5413
  () => e?.lineItems.physicalItems.reduce(
5393
5414
  (c, l) => c + l.quantity,
5394
5415
  0
@@ -5527,7 +5548,7 @@ function oa({
5527
5548
  onFileChange: s,
5528
5549
  onSkip: o
5529
5550
  }) {
5530
- const c = kr(), l = R(null), d = B(() => {
5551
+ const c = kr(), l = D(null), d = B(() => {
5531
5552
  l.current?.click();
5532
5553
  }, []);
5533
5554
  return /* @__PURE__ */ p(
@@ -5658,9 +5679,9 @@ function ca({
5658
5679
  ] })
5659
5680
  ] });
5660
5681
  }
5661
- const la = 3e3, Rt = 200;
5682
+ const la = 3e3, Lt = 200;
5662
5683
  function da(t) {
5663
- return t <= 0 ? Rt : Math.max(Rt, Math.round(la / t));
5684
+ return t <= 0 ? Lt : Math.max(Lt, Math.round(la / t));
5664
5685
  }
5665
5686
  function ua() {
5666
5687
  const t = y(
@@ -5671,7 +5692,7 @@ function ua() {
5671
5692
  if (c.toolName !== Fe) return o;
5672
5693
  const l = c.input;
5673
5694
  return l && typeof l == "object" && "value" in l && Array.isArray(l.value) ? o + l.value.length : o;
5674
- }, 0), [i, s] = D(0);
5695
+ }, 0), [i, s] = R(0);
5675
5696
  return F(() => {
5676
5697
  if (!r || n === 0 || i >= n) return;
5677
5698
  const o = da(n), c = setTimeout(() => {
@@ -5973,7 +5994,7 @@ function Ea(t, e) {
5973
5994
  );
5974
5995
  }
5975
5996
  function ka(t) {
5976
- const { client: e, onError: r } = t, n = R(e), i = R(r);
5997
+ const { client: e, onError: r } = t, n = D(e), i = D(r);
5977
5998
  i.current = r;
5978
5999
  const s = y((f) => f.bcSession.bcCart), o = y((f) => f.bcSession.checkout), c = y(
5979
6000
  (f) => f.customer.customerInfo
@@ -6016,7 +6037,7 @@ function ka(t) {
6016
6037
  poPriceValue: T?.poPrice,
6017
6038
  poPriceCurrencyCode: T?.poCurrency
6018
6039
  };
6019
- }) : [], [s, S]), ae = R(/* @__PURE__ */ new Set()), ee = B(
6040
+ }) : [], [s, S]), ae = D(/* @__PURE__ */ new Set()), ee = B(
6020
6041
  async (f, k) => {
6021
6042
  if (!n.current)
6022
6043
  return;
@@ -6084,7 +6105,7 @@ function ka(t) {
6084
6105
  });
6085
6106
  }
6086
6107
  }, [s, w]);
6087
- const Y = R(!1), te = R(!1);
6108
+ const Y = D(!1), te = D(!1);
6088
6109
  F(() => {
6089
6110
  if (d)
6090
6111
  return;
@@ -6154,7 +6175,7 @@ function ka(t) {
6154
6175
  g,
6155
6176
  se
6156
6177
  ]);
6157
- const W = R(void 0), V = R(void 0), ie = oe(() => s ? s.lineItems.physicalItems.map((f) => {
6178
+ const W = D(void 0), V = D(void 0), ie = oe(() => s ? s.lineItems.physicalItems.map((f) => {
6158
6179
  const k = z.find(
6159
6180
  (L) => L.productEntityId === f.productEntityId && L.variantEntityId === f.variantEntityId
6160
6181
  ), T = k?.poPriceValue, P = f.listPrice.value, M = $r(T, P);
@@ -6682,7 +6703,7 @@ async function $a(t, e, r, n, i, s) {
6682
6703
  e,
6683
6704
  r,
6684
6705
  h
6685
- ), g = await Rs(E, {
6706
+ ), g = await Ls(E, {
6686
6707
  onToolCall: s?.onToolCall
6687
6708
  });
6688
6709
  if (c.push(...g.textParts), o.push(...g.toolCalls), g.finalMessage && l.push(g.finalMessage), g.errorMessage?.includes(Ta)) {
@@ -6879,7 +6900,7 @@ function Oa(t) {
6879
6900
  return e.join(`
6880
6901
  `);
6881
6902
  }
6882
- async function Da(t, e) {
6903
+ async function Ra(t, e) {
6883
6904
  const r = Ma(t);
6884
6905
  if (r.setPoMetadataArgs) {
6885
6906
  const s = r.setPoMetadataArgs;
@@ -6900,7 +6921,7 @@ ${s}` : s;
6900
6921
  }
6901
6922
  return i;
6902
6923
  }
6903
- async function La(t, e) {
6924
+ async function Da(t, e) {
6904
6925
  if (e.length === 0)
6905
6926
  return { results: [], processingFailuresString: "", hasErrors: !1 };
6906
6927
  const r = await Ba(
@@ -6917,7 +6938,7 @@ async function La(t, e) {
6917
6938
  }
6918
6939
  );
6919
6940
  let n = "";
6920
- return t.bcCart && (n = await Da(
6941
+ return t.bcCart && (n = await Ra(
6921
6942
  r.results,
6922
6943
  t.bcCart
6923
6944
  )), {
@@ -6926,7 +6947,7 @@ async function La(t, e) {
6926
6947
  hasErrors: r.hasErrors
6927
6948
  };
6928
6949
  }
6929
- function Ra(t) {
6950
+ function La(t) {
6930
6951
  const { bcCart: e } = t, r = y(
6931
6952
  (d) => d.takeshapeConfig
6932
6953
  ), n = y(
@@ -6950,7 +6971,7 @@ function Ra(t) {
6950
6971
  bcCart: e
6951
6972
  };
6952
6973
  try {
6953
- const u = await La(h, d);
6974
+ const u = await Da(h, d);
6954
6975
  if (s(
6955
6976
  u.results,
6956
6977
  u.processingFailuresString
@@ -6988,11 +7009,11 @@ function _a({
6988
7009
  chatPanelRef: i,
6989
7010
  bcCart: s
6990
7011
  }) {
6991
- const o = R(!1), c = y(
7012
+ const o = D(!1), c = y(
6992
7013
  (u) => u.parser.hasProcessedDocument
6993
7014
  ), l = y(
6994
7015
  (u) => u.setHasProcessedDocument
6995
- ), { processBatches: d } = Ra({ bcCart: s });
7016
+ ), { processBatches: d } = La({ bcCart: s });
6996
7017
  return F(() => {
6997
7018
  t === "processing" && r.parserStatus !== "streaming" && r.parserStatus !== "submitted" && r.parsedContent && r.parserMessages.length > 0 && !o.current && (o.current = !0, l(!0), d(r.parsedContent));
6998
7019
  }, [
@@ -7127,7 +7148,7 @@ function Za({
7127
7148
  createParserThread: t,
7128
7149
  sendParserMessage: e
7129
7150
  }) {
7130
- const [r, n] = D(!1), [i, s] = D(null), o = B(
7151
+ const [r, n] = R(!1), [i, s] = R(null), o = B(
7131
7152
  async (c) => {
7132
7153
  const l = y.getState();
7133
7154
  if (l.setParsedContent(null), n(!0), l.setUploadedFileName(c.name), s(null), c.type === "application/pdf") {
@@ -7176,7 +7197,7 @@ function Mr(t) {
7176
7197
  onThreadCreated: s
7177
7198
  } = t, { projectId: o, apiKey: c, origin: l } = y(
7178
7199
  (S) => S.takeshapeConfig
7179
- ), [d, h] = D(!1), u = R(
7200
+ ), [d, h] = R(!1), u = D(
7180
7201
  n ? { id: n } : null
7181
7202
  ), m = B(async () => {
7182
7203
  h(!0);
@@ -7220,7 +7241,7 @@ function ei() {
7220
7241
  (g) => g.setParserThreadId
7221
7242
  ), { thread: i, createThread: s } = Mr({
7222
7243
  agentName: "documentParser",
7223
- createOnMount: !0,
7244
+ createOnMount: !1,
7224
7245
  persist: !1,
7225
7246
  // Document parser is ephemeral, don't overwrite main chat thread
7226
7247
  onThreadCreated: n
@@ -7228,7 +7249,7 @@ function ei() {
7228
7249
  (g) => g.parser.parsedContent
7229
7250
  ), c = y(
7230
7251
  (g) => g.parser.uploadedFileName
7231
- ), l = R(
7252
+ ), l = D(
7232
7253
  null
7233
7254
  ), {
7234
7255
  messages: d,
@@ -7300,15 +7321,10 @@ function ei() {
7300
7321
  u === "ready" && l.current && o !== null && (l.current.setStatus({ code: 1, message: "ok" }), l.current.end(), l.current = null);
7301
7322
  }, [u, o]);
7302
7323
  const w = B(() => {
7303
- l.current?.setStatus({ code: 2, message: "cancelled" }), l.current?.end(), l.current = null, v(null), m([]), y.getState().setParsedContent(null), s();
7304
- }, [v, m, s]), E = B(() => {
7305
- l.current?.setStatus({ code: 2, message: "cancelled" }), l.current?.end(), l.current = null, m([]), y.getState().clearParser(), b(!1), v(null), s();
7306
- }, [
7307
- m,
7308
- b,
7309
- v,
7310
- s
7311
- ]);
7324
+ l.current?.setStatus({ code: 2, message: "cancelled" }), l.current?.end(), l.current = null, v(null), m([]), y.getState().setParsedContent(null);
7325
+ }, [v, m]), E = B(() => {
7326
+ l.current?.setStatus({ code: 2, message: "cancelled" }), l.current?.end(), l.current = null, m([]), y.getState().clearParser(), b(!1), v(null);
7327
+ }, [m, b, v]);
7312
7328
  return {
7313
7329
  parsedContent: o,
7314
7330
  isUploadingFile: S,
@@ -7588,17 +7604,17 @@ async function oi(t, e) {
7588
7604
  const { setToolCallError: r } = y.getState(), n = t.input;
7589
7605
  let i = "Item removed from cart successfully.";
7590
7606
  try {
7591
- const s = e.bcCart?.lineItems.physicalItems.find(
7607
+ const s = e.bcCart?.lineItems.physicalItems.filter(
7592
7608
  (o) => o.productEntityId === n.productEntityId && o.variantEntityId === n.variantEntityId
7593
- );
7594
- if (s)
7595
- await e.removeLineItem(s.entityId);
7596
- else
7609
+ ) ?? [];
7610
+ if (s.length === 0)
7597
7611
  return {
7598
7612
  tool: yr,
7599
7613
  toolCallId: t.toolCallId,
7600
7614
  output: "Cart item not found."
7601
7615
  };
7616
+ for (const o of s)
7617
+ await e.removeLineItem(o.entityId);
7602
7618
  } catch (s) {
7603
7619
  const o = s instanceof Error ? s.message : "Unknown error";
7604
7620
  i = `Failed to remove item from cart: ${o}`, r(t.toolCallId, o);
@@ -7961,11 +7977,11 @@ function ki({
7961
7977
  createOnMount: !l,
7962
7978
  // Only create if no existing thread
7963
7979
  existingThreadId: l
7964
- }), b = y((C) => C.appState), x = y((C) => C.setAppState), v = R(null), N = R(
7980
+ }), b = y((C) => C.appState), x = y((C) => C.setAppState), v = D(null), N = D(
7965
7981
  null
7966
- ), I = R(
7982
+ ), I = D(
7967
7983
  null
7968
- ), w = Re((C) => C.isExpanded), E = Re((C) => C.setExpanded), g = Re((C) => C.reset), A = ei(), $ = ka({
7984
+ ), w = Le((C) => C.isExpanded), E = Le((C) => C.setExpanded), g = Le((C) => C.reset), A = ei(), $ = ka({
7969
7985
  client: n.client,
7970
7986
  onError: (C) => console.error("BigCommerce error:", C)
7971
7987
  }), O = y((C) => C.cartifact.orderId), Q = y((C) => C.cartifact.buyerInfo), H = y(
@@ -7978,12 +7994,12 @@ function ki({
7978
7994
  (C) => C.cartifact.itemWarnings
7979
7995
  ), se = y((C) => C.clearCartifact), Y = y((C) => C.clearBcSession), te = y(
7980
7996
  (C) => C.clearAddressSelections
7981
- ), W = y((C) => C.clearChat), { cartItems: V } = $, ie = R([]), Ie = B(
7997
+ ), W = y((C) => C.clearChat), { cartItems: V } = $, ie = D([]), Ie = B(
7982
7998
  async ({ toolCall: C }) => {
7983
7999
  ie.current.push(C);
7984
8000
  },
7985
8001
  []
7986
- ), _ = R(/* @__PURE__ */ new Set()), { messages: j, sendMessage: K, status: J, error: Pe, setMessages: fe, addToolOutput: me } = zt({
8002
+ ), _ = D(/* @__PURE__ */ new Set()), { messages: j, sendMessage: K, status: J, error: Pe, setMessages: fe, addToolOutput: me } = zt({
7987
8003
  transport: new Qt({
7988
8004
  api: `${s}/project/${o}/agents/messages`,
7989
8005
  headers: {
@@ -8196,8 +8212,8 @@ function ki({
8196
8212
  poMetadataSet: ae,
8197
8213
  onNewOrder: ye
8198
8214
  };
8199
- return i && w ? /* @__PURE__ */ a(An, { children: /* @__PURE__ */ a(Lt, { ...de, onMinimize: () => E(!1) }) }) : /* @__PURE__ */ a("div", { className: "h-full max-w-[1440px] mx-auto", children: /* @__PURE__ */ a(
8200
- Lt,
8215
+ return i && w ? /* @__PURE__ */ a(An, { children: /* @__PURE__ */ a(Dt, { ...de, onMinimize: () => E(!1) }) }) : /* @__PURE__ */ a("div", { className: "h-full max-w-[1440px] mx-auto", children: /* @__PURE__ */ a(
8216
+ Dt,
8201
8217
  {
8202
8218
  ...de,
8203
8219
  onExpand: i ? () => E(!0) : void 0
@@ -8255,4 +8271,4 @@ export {
8255
8271
  Vi as r,
8256
8272
  Gi as s
8257
8273
  };
8258
- //# sourceMappingURL=purchase-order-chat-wrapper-CGoWg1CH.js.map
8274
+ //# sourceMappingURL=purchase-order-chat-wrapper-D6twvEIU.js.map