@takeshape/purchase-order-chat 1.60.1 → 1.60.3

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_36c304cac03b430c81e7aad4f679f68b", vt = "__vite_c_css_pos_update_36c304cac03b430c81e7aad4f679f68b", 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_88d35ee618544ae783e618c09bb86b96", vt = "__vite_c_css_pos_update_88d35ee618544ae783e618c09bb86b96", 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();
@@ -36,7 +36,7 @@ const Yr = "__vite_c_css_pos_initial_36c304cac03b430c81e7aad4f679f68b", vt = "__
36
36
  const o = e.get(s);
37
37
  return o ? /* @__PURE__ */ Or("style", { ...o.attributes, key: `${s}-${n}` }, o.css) : null;
38
38
  });
39
- }, He = "bigcommercePurchaseOrderAgent", It = "https://api.takeshape.io", Gt = "https://api-b2b.bigcommerce.com/graphql", Xr = "dl7c39mdpul6hyc489yk0vzxl6jesyx", ot = "[client is providing tool response]", be = "__po_address__", Se = "__po_billing_address__", he = "__checkout_address__", ct = "purchase-order-chat-session", Kt = 3;
39
+ }, He = "bigcommercePurchaseOrderAgent", It = "https://api.takeshape.io", Gt = "https://api-b2b.bigcommerce.com/graphql", Xr = "dl7c39mdpul6hyc489yk0vzxl6jesyx", ot = "[client is providing tool response]", be = "__po_address__", Se = "__po_billing_address__", le = "__checkout_address__", ct = "purchase-order-chat-session", Kt = 3;
40
40
  function Zr() {
41
41
  if (typeof document < "u")
42
42
  try {
@@ -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,22 +1689,22 @@ 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."
1702
1702
  );
1703
1703
  return;
1704
1704
  }
1705
- const N = Wn(v);
1706
- if (!N.valid) {
1707
- s(N.error ?? null);
1705
+ const E = Wn(v);
1706
+ if (!E.valid) {
1707
+ s(E.error ?? null);
1708
1708
  return;
1709
1709
  }
1710
1710
  t(v);
@@ -1930,7 +1930,7 @@ function St(t) {
1930
1930
  defaultAddressFilter: c = (b) => b.isDefaultShipping,
1931
1931
  addressFilter: l = (b) => b.isShipping,
1932
1932
  canShowDefaultAddressWarning: d
1933
- } = t, h = n === he, u = r.find(c);
1933
+ } = t, h = n === le, u = r.find(c);
1934
1934
  let m = d && !!n && !h;
1935
1935
  m && u && (m = u.id !== n);
1936
1936
  const S = r.filter(l);
@@ -1974,7 +1974,7 @@ function St(t) {
1974
1974
  }
1975
1975
  ) }, b.id)),
1976
1976
  S.length > 0 && /* @__PURE__ */ a("option", { disabled: !0, children: "---" }),
1977
- /* @__PURE__ */ a("option", { value: he, children: "Enter an address at checkout" }, he)
1977
+ /* @__PURE__ */ a("option", { value: le, children: "Enter an address at checkout" }, le)
1978
1978
  ]
1979
1979
  }
1980
1980
  ),
@@ -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,22 +2157,22 @@ 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(() => {
2166
2166
  l(String(t));
2167
2167
  }, [t]);
2168
2168
  const m = (w) => {
2169
- const E = w.target.value;
2170
- if (E === "") {
2169
+ const k = w.target.value;
2170
+ if (k === "") {
2171
2171
  l("");
2172
2172
  return;
2173
2173
  }
2174
- if (/^\d+$/.test(E) && (l(E), !s)) {
2175
- const g = Number.parseInt(E, 10);
2174
+ if (/^\d+$/.test(k) && (l(k), !s)) {
2175
+ const g = Number.parseInt(k, 10);
2176
2176
  if (!Number.isNaN(g)) {
2177
2177
  const A = Math.max(
2178
2178
  r,
@@ -2185,10 +2185,10 @@ function dr({
2185
2185
  const w = Number.parseInt(c, 10);
2186
2186
  if (s)
2187
2187
  if (!Number.isNaN(w) && w >= r && w !== t) {
2188
- const E = n !== void 0 ? Math.min(w, n) : w;
2188
+ const k = n !== void 0 ? Math.min(w, n) : w;
2189
2189
  h("saving");
2190
2190
  try {
2191
- await e(E), h("success"), u.current = setTimeout(() => {
2191
+ await e(k), h("success"), u.current = setTimeout(() => {
2192
2192
  h((g) => g === "success" ? "idle" : g);
2193
2193
  }, 1500);
2194
2194
  } catch {
@@ -2202,7 +2202,7 @@ function dr({
2202
2202
  }, b = (w) => {
2203
2203
  w.key === "Enter" && w.currentTarget.blur();
2204
2204
  }, x = async (w) => {
2205
- const E = Number.parseInt(c, 10), g = Number.isNaN(E) ? t : E, A = Math.max(
2205
+ const k = Number.parseInt(c, 10), g = Number.isNaN(k) ? t : k, A = Math.max(
2206
2206
  r,
2207
2207
  n !== void 0 ? Math.min(g + w, n) : g + w
2208
2208
  );
@@ -2220,7 +2220,7 @@ function dr({
2220
2220
  }
2221
2221
  } else
2222
2222
  e(A);
2223
- }, v = t <= r, N = n !== void 0 && t >= n, I = d === "saving";
2223
+ }, v = t <= r, E = n !== void 0 && t >= n, I = d === "saving";
2224
2224
  return /* @__PURE__ */ p("span", { className: `inline-flex items-center gap-0.5 ${i}`, children: [
2225
2225
  /* @__PURE__ */ a(
2226
2226
  kt,
@@ -2262,7 +2262,7 @@ function dr({
2262
2262
  kt,
2263
2263
  {
2264
2264
  onClick: () => x(1),
2265
- disabled: N || I,
2265
+ disabled: E || I,
2266
2266
  "aria-label": "Increase quantity",
2267
2267
  children: /* @__PURE__ */ p(
2268
2268
  "svg",
@@ -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
  {
@@ -3264,17 +3285,17 @@ function ms({
3264
3285
  selectedBillingAddressId: b,
3265
3286
  billingAddressUpdateStatus: x,
3266
3287
  onBillingAddressChange: v,
3267
- shipToAddress: N,
3288
+ shipToAddress: E,
3268
3289
  billingAddress: I,
3269
3290
  checkoutTotals: w,
3270
- isLoading: E,
3291
+ isLoading: k,
3271
3292
  poMetadataSet: g = !1,
3272
3293
  isDragging: A,
3273
3294
  onNewOrder: $,
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
  });
@@ -3348,7 +3369,7 @@ function ms({
3348
3369
  selectedBillingAddressId: b,
3349
3370
  billingAddressUpdateStatus: x,
3350
3371
  onBillingAddressChange: v,
3351
- shipToAddress: N,
3372
+ shipToAddress: E,
3352
3373
  billingAddress: I
3353
3374
  }
3354
3375
  )
@@ -3394,7 +3415,7 @@ function ms({
3394
3415
  totalQuantity: te,
3395
3416
  availableItemCount: Y.length,
3396
3417
  onCheckout: i,
3397
- isLoading: E,
3418
+ isLoading: k,
3398
3419
  allowCheckout: !!u
3399
3420
  }
3400
3421
  )
@@ -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,9 +3759,9 @@ 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(
3742
- (W) => W.productEntityId === t.productEntityId && W.variantEntityId === N
3743
- ), 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 ? (
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, E = v?.entityId ?? t.variantEntityId, I = r.find(
3763
+ (W) => W.productEntityId === t.productEntityId && W.variantEntityId === E
3764
+ ), w = !!I, k = 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
3745
3766
  !v.isPurchasable || Q === !1 || Q === void 0 && (v.inventory?.aggregated?.availableToSell ?? 0) === 0
3746
3767
  ) : (
@@ -3846,7 +3867,7 @@ function Mt({
3846
3867
  !x && te,
3847
3868
  w && /* @__PURE__ */ p("p", { className: "text-xs text-text-tertiary m-0 mb-1", children: [
3848
3869
  "In cart (×",
3849
- E,
3870
+ k,
3850
3871
  ")"
3851
3872
  ] }),
3852
3873
  /* @__PURE__ */ p(
@@ -3905,36 +3926,36 @@ function Fs({
3905
3926
  ), h = oe(() => {
3906
3927
  const v = /* @__PURE__ */ new Map();
3907
3928
  if (d)
3908
- for (const N of d)
3909
- N.productOptions.length > 0 && v.set(N.entityId, N);
3929
+ for (const E of d)
3930
+ E.productOptions.length > 0 && v.set(E.entityId, E);
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
- const N = new Map(v);
3935
+ const E = new Map(v);
3915
3936
  for (const I of t) {
3916
- if (I.productEntityId === void 0 || N.has(I.id)) continue;
3937
+ if (I.productEntityId === void 0 || E.has(I.id)) continue;
3917
3938
  const w = d.find(
3918
3939
  (g) => g.entityId === I.productEntityId
3919
3940
  );
3920
3941
  if (!w || w.productOptions.length === 0) continue;
3921
- let E;
3942
+ let k;
3922
3943
  if (I.variantEntityId) {
3923
3944
  const g = w.variants.find(
3924
3945
  (A) => A.entityId === I.variantEntityId
3925
3946
  );
3926
- g ? E = Sr(g) : E = Bt(w);
3947
+ g ? k = Sr(g) : k = Bt(w);
3927
3948
  } else
3928
- E = Bt(w);
3929
- N.set(I.id, E);
3949
+ k = Bt(w);
3950
+ E.set(I.id, k);
3930
3951
  }
3931
- return N;
3952
+ return E;
3932
3953
  });
3933
3954
  }, [d, t]);
3934
- const S = (v, N, I) => {
3955
+ const S = (v, E, I) => {
3935
3956
  m((w) => {
3936
- const E = new Map(w), g = new Map(E.get(v) ?? /* @__PURE__ */ new Map());
3937
- return g.set(N, I), E.set(v, g), E;
3957
+ const k = new Map(w), g = new Map(k.get(v) ?? /* @__PURE__ */ new Map());
3958
+ return g.set(E, I), k.set(v, g), k;
3938
3959
  });
3939
3960
  };
3940
3961
  if (i)
@@ -3947,7 +3968,7 @@ function Fs({
3947
3968
  return null;
3948
3969
  const [x] = b;
3949
3970
  if (b.length === 1 && x) {
3950
- const v = x.productEntityId !== void 0 ? h.get(x.productEntityId) : void 0, N = u.get(x.id);
3971
+ const v = x.productEntityId !== void 0 ? h.get(x.productEntityId) : void 0, E = u.get(x.id);
3951
3972
  return /* @__PURE__ */ a("div", { className: `py-2 ${o}`, children: /* @__PURE__ */ a(
3952
3973
  Mt,
3953
3974
  {
@@ -3957,13 +3978,13 @@ function Fs({
3957
3978
  onViewProduct: r,
3958
3979
  cart: n,
3959
3980
  variantDetails: v,
3960
- selections: N,
3981
+ selections: E,
3961
3982
  onSelectionChange: v ? (I, w) => S(x.id, I, w) : void 0
3962
3983
  }
3963
3984
  ) });
3964
3985
  }
3965
3986
  return /* @__PURE__ */ a("div", { className: `flex flex-wrap gap-3 py-2 ${o}`, children: b.map((v) => {
3966
- const N = v.productEntityId !== void 0 ? h.get(v.productEntityId) : void 0, I = u.get(v.id);
3987
+ const E = v.productEntityId !== void 0 ? h.get(v.productEntityId) : void 0, I = u.get(v.id);
3967
3988
  return /* @__PURE__ */ a(
3968
3989
  Mt,
3969
3990
  {
@@ -3971,9 +3992,9 @@ function Fs({
3971
3992
  onAddToCart: e,
3972
3993
  onViewProduct: r,
3973
3994
  cart: n,
3974
- variantDetails: N,
3995
+ variantDetails: E,
3975
3996
  selections: I,
3976
- onSelectionChange: N ? (w, E) => S(v.id, w, E) : void 0
3997
+ onSelectionChange: E ? (w, k) => S(v.id, w, k) : void 0
3977
3998
  },
3978
3999
  v.id
3979
4000
  );
@@ -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) {
@@ -3999,15 +4020,15 @@ function Os({
3999
4020
  return;
4000
4021
  }
4001
4022
  const b = [
4002
- ...new Set(t.products.map((N) => N.entityId))
4023
+ ...new Set(t.products.map((E) => E.entityId))
4003
4024
  ], x = await s.getProductsForDisplay(b), v = [];
4004
- for (const N of t.products) {
4025
+ for (const E of t.products) {
4005
4026
  const I = x.find(
4006
- (E) => E.entityId === N.entityId
4027
+ (k) => k.entityId === E.entityId
4007
4028
  );
4008
4029
  if (!I) continue;
4009
- const w = N.variantEntityId ? I.variants.find(
4010
- (E) => E.entityId === N.variantEntityId
4030
+ const w = E.variantEntityId ? I.variants.find(
4031
+ (k) => k.entityId === E.variantEntityId
4011
4032
  ) : I.variants[0];
4012
4033
  w && v.push({
4013
4034
  id: `${I.entityId}-${w.entityId}`,
@@ -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,19 +4436,19 @@ 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
4422
- ), N = y(
4443
+ ), E = y(
4423
4444
  (w) => w.batchProcessing.threadIds
4424
4445
  );
4425
4446
  F(() => {
4426
4447
  e && (i(""), o(""), l(""), h("idle"), m(""), S.current?.focus());
4427
4448
  }, [e]), F(() => {
4428
4449
  if (!e) return;
4429
- const w = (E) => {
4430
- E.key === "Escape" && r();
4450
+ const w = (k) => {
4451
+ k.key === "Escape" && r();
4431
4452
  };
4432
4453
  return document.addEventListener("keydown", w), () => document.removeEventListener("keydown", w);
4433
4454
  }, [e, r]);
@@ -4447,8 +4468,8 @@ function Ft({
4447
4468
  projectId: b.projectId,
4448
4469
  ...x && { chatThreadId: x },
4449
4470
  ...v && { parserThreadId: v },
4450
- ...N.length > 0 && {
4451
- batchThreadIds: N.join(",")
4471
+ ...E.length > 0 && {
4472
+ batchThreadIds: E.join(",")
4452
4473
  }
4453
4474
  }
4454
4475
  }
@@ -4458,9 +4479,9 @@ function Ft({
4458
4479
  email: s.trim(),
4459
4480
  text: c.trim()
4460
4481
  }), h("success");
4461
- } catch (E) {
4482
+ } catch (k) {
4462
4483
  h("error"), m(
4463
- E instanceof Error ? E.message : "Failed to send feedback"
4484
+ k instanceof Error ? k.message : "Failed to send feedback"
4464
4485
  );
4465
4486
  }
4466
4487
  }
@@ -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), E = D(!0), [I, w] = R(!1), k = oe(() => {
5012
5033
  for (let g = e.length - 1; g >= 0; g--) {
5013
5034
  const A = e[g];
5014
5035
  if (A?.role === "assistant")
@@ -5022,16 +5043,16 @@ const Ys = Rr(
5022
5043
  g && (g.scrollHeight - g.scrollTop - g.clientHeight > 500 || !g.scrollTo ? g.scrollTop = g.scrollHeight : g.scrollTo({
5023
5044
  top: g.scrollHeight,
5024
5045
  behavior: "smooth"
5025
- })), N.current = !0;
5046
+ })), E.current = !0;
5026
5047
  }
5027
5048
  })), F(() => {
5028
5049
  const g = v.current;
5029
5050
  if (!g) return;
5030
5051
  const A = () => {
5031
5052
  const O = g.scrollHeight - g.scrollTop - g.clientHeight < 50;
5032
- N.current = O;
5053
+ E.current = O;
5033
5054
  }, $ = new MutationObserver(() => {
5034
- N.current && (g.scrollTop = g.scrollHeight);
5055
+ E.current && (g.scrollTop = g.scrollHeight);
5035
5056
  });
5036
5057
  return g.addEventListener("scroll", A), $.observe(g, {
5037
5058
  childList: !0,
@@ -5060,7 +5081,7 @@ const Ys = Rr(
5060
5081
  }
5061
5082
  ),
5062
5083
  e.map((g, A) => {
5063
- const $ = m && g.role !== "assistant" && A === 0, O = g.role === "assistant" && g.id === E;
5084
+ const $ = m && g.role !== "assistant" && A === 0, O = g.role === "assistant" && g.id === k;
5064
5085
  return /* @__PURE__ */ a(
5065
5086
  Hs,
5066
5087
  {
@@ -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,
@@ -5219,10 +5240,10 @@ function Lt({
5219
5240
  onRemove: b,
5220
5241
  onCheckout: x,
5221
5242
  onSuggestAlternatives: v,
5222
- onShowMoreLikeThis: N,
5243
+ onShowMoreLikeThis: E,
5223
5244
  onViewProduct: I,
5224
5245
  onAddToCart: w,
5225
- orderId: E,
5246
+ orderId: k,
5226
5247
  buyerInfo: g,
5227
5248
  customerInfo: A,
5228
5249
  addresses: $,
@@ -5242,16 +5263,16 @@ 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), de = D(t.length), ge = D(J);
5248
5269
  ge.current = J;
5249
- const f = t.length === 0 && u.length === 0 && !!h, k = ir({
5270
+ const f = t.length === 0 && u.length === 0 && !!h, N = ir({
5250
5271
  onFile: h ?? (() => {
5251
5272
  })
5252
5273
  });
5253
5274
  F(() => {
5254
- t.length > le.current && ge.current !== "chat" && me(!0), le.current = t.length;
5275
+ t.length > de.current && ge.current !== "chat" && me(!0), de.current = t.length;
5255
5276
  }, [t.length]), F(() => {
5256
5277
  K.isDesktop && me(!1);
5257
5278
  }, [K.isDesktop]);
@@ -5273,7 +5294,7 @@ function Lt({
5273
5294
  onRetry: o,
5274
5295
  hasProcessedDocument: c,
5275
5296
  uploadedFileName: l,
5276
- fileDrop: h ? k : void 0
5297
+ fileDrop: h ? N : void 0
5277
5298
  }
5278
5299
  ), M = /* @__PURE__ */ a(
5279
5300
  ms,
@@ -5284,9 +5305,9 @@ function Lt({
5284
5305
  onRemove: b,
5285
5306
  onCheckout: x,
5286
5307
  onSuggestAlternatives: v,
5287
- onShowMoreLikeThis: N,
5308
+ onShowMoreLikeThis: E,
5288
5309
  onViewProduct: I,
5289
- orderId: E ?? void 0,
5310
+ orderId: k ?? void 0,
5290
5311
  buyerInfo: g ?? void 0,
5291
5312
  customerInfo: A,
5292
5313
  addresses: $,
@@ -5301,13 +5322,13 @@ function Lt({
5301
5322
  checkoutTotals: te ?? void 0,
5302
5323
  isLoading: W,
5303
5324
  poMetadataSet: V,
5304
- isDragging: f && k.isDragging,
5325
+ isDragging: f && N.isDragging,
5305
5326
  onNewOrder: ie,
5306
5327
  onExpand: Ie,
5307
5328
  onMinimize: _,
5308
5329
  className: K.isDesktop ? "rounded-l-none border-0" : ""
5309
5330
  }
5310
- ), L = f ? k.dragProps : void 0;
5331
+ ), L = f ? N.dragProps : void 0;
5311
5332
  return K.isDesktop ? (
5312
5333
  // biome-ignore lint/a11y/noStaticElementInteractions: dnd is optional
5313
5334
  /* @__PURE__ */ p(
@@ -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(() => {
@@ -5889,7 +5910,7 @@ function Ia({
5889
5910
  }
5890
5911
  );
5891
5912
  }
5892
- function pe(t) {
5913
+ function he(t) {
5893
5914
  return {
5894
5915
  firstName: t.firstName,
5895
5916
  lastName: t.lastName,
@@ -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
@@ -5989,11 +6010,11 @@ function ka(t) {
5989
6010
  (f) => f.cartifact.poItemPrices
5990
6011
  ), b = y((f) => f.setBcCart), x = y((f) => f.setCheckout), v = y(
5991
6012
  (f) => f.setSelectedAddressId
5992
- ), N = y(
6013
+ ), E = y(
5993
6014
  (f) => f.setAddressUpdateStatus
5994
6015
  ), I = y((f) => f.setIsLoading), w = y(
5995
6016
  (f) => f.setProductPaths
5996
- ), E = y(
6017
+ ), k = y(
5997
6018
  (f) => f.cartifact.shipToAddress
5998
6019
  ), g = y(
5999
6020
  (f) => f.cartifact.billingAddress
@@ -6008,7 +6029,7 @@ function ka(t) {
6008
6029
  ), H = y(
6009
6030
  (f) => f.setItemWarnings
6010
6031
  ), z = oe(() => s ? s.lineItems.physicalItems.map((f) => {
6011
- const k = `${f.productEntityId}-${f.variantEntityId}`, T = S[k];
6032
+ const N = `${f.productEntityId}-${f.variantEntityId}`, T = S[N];
6012
6033
  return {
6013
6034
  productEntityId: f.productEntityId,
6014
6035
  variantEntityId: f.variantEntityId ?? void 0,
@@ -6016,8 +6037,8 @@ 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(
6020
- async (f, k) => {
6040
+ }) : [], [s, S]), ae = D(/* @__PURE__ */ new Set()), ee = B(
6041
+ async (f, N) => {
6021
6042
  if (!n.current)
6022
6043
  return;
6023
6044
  const T = f.lineItems.physicalItems.map((P) => ({
@@ -6033,7 +6054,7 @@ function ka(t) {
6033
6054
  try {
6034
6055
  const P = await n.current.setCheckoutShippingAddress(
6035
6056
  f.entityId,
6036
- k,
6057
+ N,
6037
6058
  T
6038
6059
  );
6039
6060
  P && x(P);
@@ -6045,12 +6066,12 @@ function ka(t) {
6045
6066
  },
6046
6067
  [x]
6047
6068
  ), se = B(
6048
- async (f, k) => {
6069
+ async (f, N) => {
6049
6070
  if (n.current)
6050
6071
  try {
6051
6072
  const T = await n.current.setCheckoutBillingAddress(
6052
6073
  f.entityId,
6053
- k
6074
+ N
6054
6075
  );
6055
6076
  T && x(T);
6056
6077
  } catch (T) {
@@ -6063,17 +6084,17 @@ function ka(t) {
6063
6084
  );
6064
6085
  F(() => {
6065
6086
  if (!s || !n.current) return;
6066
- const k = [
6087
+ const N = [
6067
6088
  ...new Set(
6068
6089
  s.lineItems.physicalItems.map((T) => T.productEntityId)
6069
6090
  )
6070
6091
  ].filter(
6071
6092
  (T) => !ae.current.has(T)
6072
6093
  );
6073
- if (k.length !== 0) {
6074
- for (const T of k)
6094
+ if (N.length !== 0) {
6095
+ for (const T of N)
6075
6096
  ae.current.add(T);
6076
- n.current.getProductPaths(k).then((T) => {
6097
+ n.current.getProductPaths(N).then((T) => {
6077
6098
  if (T.size > 0) {
6078
6099
  const P = {};
6079
6100
  for (const [L, U] of T)
@@ -6084,53 +6105,62 @@ 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;
6091
- if (!E) {
6092
- l.length === 0 && v(he);
6112
+ if (!k) {
6113
+ if (l.length === 0)
6114
+ v(le);
6115
+ else {
6116
+ const N = l.find(
6117
+ (P) => P.isDefaultShipping
6118
+ ), T = l.find((P) => P.isShipping);
6119
+ v(
6120
+ N?.id ?? T?.id ?? le
6121
+ );
6122
+ }
6093
6123
  return;
6094
6124
  }
6095
6125
  let f;
6096
6126
  if (l.length > 0) {
6097
- const k = qt(
6098
- E,
6127
+ const N = qt(
6128
+ k,
6099
6129
  l
6100
6130
  );
6101
- f = k ? k.id : be;
6131
+ f = N ? N.id : be;
6102
6132
  } else
6103
6133
  f = be;
6104
6134
  Y.current = !1, v(f);
6105
6135
  }, [
6106
6136
  l,
6107
- E,
6137
+ k,
6108
6138
  v,
6109
6139
  d
6110
6140
  ]), F(() => {
6111
- if (Y.current || !s || !d || d === he)
6141
+ if (Y.current || !s || !d || d === le)
6112
6142
  return;
6113
6143
  let f;
6114
- d === be ? f = E ?? void 0 : f = l.find((k) => k.id === d) ?? void 0, f && (Y.current = !0, ee(
6144
+ d === be ? f = k ?? void 0 : f = l.find((N) => N.id === d) ?? void 0, f && (Y.current = !0, ee(
6115
6145
  s,
6116
- pe(f)
6146
+ he(f)
6117
6147
  ));
6118
6148
  }, [
6119
6149
  s,
6120
6150
  d,
6121
6151
  l,
6122
- E,
6152
+ k,
6123
6153
  ee
6124
6154
  ]), F(() => {
6125
6155
  if (!g || A)
6126
6156
  return;
6127
6157
  let f;
6128
6158
  if (l.length > 0) {
6129
- const k = qt(
6159
+ const N = qt(
6130
6160
  g,
6131
6161
  l
6132
6162
  );
6133
- f = k ? k.id : Se;
6163
+ f = N ? N.id : Se;
6134
6164
  } else
6135
6165
  f = Se;
6136
6166
  te.current = !1, O(f);
@@ -6140,12 +6170,12 @@ function ka(t) {
6140
6170
  O,
6141
6171
  A
6142
6172
  ]), F(() => {
6143
- if (te.current || !s || !A || A === he)
6173
+ if (te.current || !s || !A || A === le)
6144
6174
  return;
6145
6175
  let f;
6146
- A === Se ? f = g ?? void 0 : f = l.find((k) => k.id === A) ?? void 0, f && (te.current = !0, se(
6176
+ A === Se ? f = g ?? void 0 : f = l.find((N) => N.id === A) ?? void 0, f && (te.current = !0, se(
6147
6177
  s,
6148
- pe(f)
6178
+ he(f)
6149
6179
  ));
6150
6180
  }, [
6151
6181
  s,
@@ -6154,10 +6184,10 @@ function ka(t) {
6154
6184
  g,
6155
6185
  se
6156
6186
  ]);
6157
- const W = R(void 0), V = R(void 0), ie = oe(() => s ? s.lineItems.physicalItems.map((f) => {
6158
- const k = z.find(
6187
+ const W = D(void 0), V = D(void 0), ie = oe(() => s ? s.lineItems.physicalItems.map((f) => {
6188
+ const N = z.find(
6159
6189
  (L) => L.productEntityId === f.productEntityId && L.variantEntityId === f.variantEntityId
6160
- ), T = k?.poPriceValue, P = f.listPrice.value, M = $r(T, P);
6190
+ ), T = N?.poPriceValue, P = f.listPrice.value, M = $r(T, P);
6161
6191
  return {
6162
6192
  id: f.entityId,
6163
6193
  sku: f.sku ?? "",
@@ -6170,7 +6200,7 @@ function ka(t) {
6170
6200
  quantity: f.quantity,
6171
6201
  bcLineItemEntityId: f.entityId,
6172
6202
  poPriceValue: T,
6173
- poPriceCurrencyCode: k?.poPriceCurrencyCode,
6203
+ poPriceCurrencyCode: N?.poPriceCurrencyCode,
6174
6204
  catalogPriceCurrencyCode: f.listPrice.currencyCode,
6175
6205
  status: M ? "price-mismatch" : "matched"
6176
6206
  };
@@ -6184,23 +6214,23 @@ function ka(t) {
6184
6214
  [s, o]
6185
6215
  ), _ = B(
6186
6216
  async (f) => {
6187
- if (!n.current || !f || !d || d === he || f.lineItems.physicalItems.length === 0)
6217
+ if (!n.current || !f || !d || d === le || f.lineItems.physicalItems.length === 0)
6188
6218
  return;
6189
- let k = null;
6219
+ let N = null;
6190
6220
  if (d === be)
6191
- E && (k = pe(E));
6221
+ k && (N = he(k));
6192
6222
  else {
6193
6223
  const T = l.find(
6194
6224
  (P) => P.id === d
6195
6225
  );
6196
- T && (k = pe(T));
6226
+ T && (N = he(T));
6197
6227
  }
6198
- k && await ee(f, k);
6228
+ N && await ee(f, N);
6199
6229
  },
6200
6230
  [
6201
6231
  d,
6202
6232
  l,
6203
- E,
6233
+ k,
6204
6234
  ee
6205
6235
  ]
6206
6236
  ), j = B(
@@ -6210,7 +6240,7 @@ function ka(t) {
6210
6240
  return { cart: s, cartItems: [], errors: [] };
6211
6241
  I(!0);
6212
6242
  try {
6213
- const k = wa(z, f), T = await n.current.getCart();
6243
+ const N = wa(z, f), T = await n.current.getCart();
6214
6244
  let P = null;
6215
6245
  const M = [];
6216
6246
  if (T) {
@@ -6219,10 +6249,10 @@ function ka(t) {
6219
6249
  f
6220
6250
  );
6221
6251
  if (P = T, G.length > 0) {
6222
- const X = G.map((de) => ({
6223
- productEntityId: de.productEntityId,
6224
- variantEntityId: de.variantEntityId,
6225
- quantity: de.quantity
6252
+ const X = G.map((ue) => ({
6253
+ productEntityId: ue.productEntityId,
6254
+ variantEntityId: ue.variantEntityId,
6255
+ quantity: ue.quantity
6226
6256
  })), { cart: Z, errors: ye } = await n.current.addCartLineItems(
6227
6257
  T.entityId,
6228
6258
  X
@@ -6257,7 +6287,7 @@ function ka(t) {
6257
6287
  b(P);
6258
6288
  const L = y.getState();
6259
6289
  L.setCartEntityId(P?.entityId ?? null);
6260
- for (const G of k)
6290
+ for (const G of N)
6261
6291
  G.poPriceValue !== void 0 && G.poPriceCurrencyCode !== void 0 && L.setPoItemPrice(
6262
6292
  G.productEntityId,
6263
6293
  G.variantEntityId,
@@ -6272,8 +6302,8 @@ function ka(t) {
6272
6302
  ), ce = Object.keys(L.cartifact.poItemPrices);
6273
6303
  for (const X of ce)
6274
6304
  if (!G.has(X)) {
6275
- const Z = X.split("-"), ye = Number(Z[0]), de = Number(Z[1]);
6276
- !Number.isNaN(ye) && !Number.isNaN(de) && L.removePoItemPrice(ye, de);
6305
+ const Z = X.split("-"), ye = Number(Z[0]), ue = Number(Z[1]);
6306
+ !Number.isNaN(ye) && !Number.isNaN(ue) && L.removePoItemPrice(ye, ue);
6277
6307
  }
6278
6308
  }
6279
6309
  if (P && !T && d) {
@@ -6282,14 +6312,14 @@ function ka(t) {
6282
6312
  );
6283
6313
  G && P.lineItems.physicalItems.length > 0 && (Y.current = !0, await ee(
6284
6314
  P,
6285
- pe(G)
6315
+ he(G)
6286
6316
  ));
6287
6317
  }
6288
6318
  if (!P)
6289
6319
  return { cart: null, cartItems: [], errors: M };
6290
6320
  const { cartItems: U } = Na(
6291
6321
  P,
6292
- k
6322
+ N
6293
6323
  ), je = y.getState().cartifact.itemWarnings, Oe = Ea(
6294
6324
  je,
6295
6325
  U
@@ -6313,19 +6343,19 @@ function ka(t) {
6313
6343
  ), K = B(
6314
6344
  async (f) => {
6315
6345
  if (!n.current) return { errors: [] };
6316
- const k = [];
6346
+ const N = [];
6317
6347
  for (const M of f) {
6318
- const L = k.findIndex(
6348
+ const L = N.findIndex(
6319
6349
  (U) => U.productEntityId === M.productEntityId && U.variantEntityId === M.variantEntityId
6320
6350
  );
6321
6351
  if (L >= 0) {
6322
- const U = k[L];
6352
+ const U = N[L];
6323
6353
  U && (U.quantity += M.quantity, M.poPriceValue !== void 0 && M.poPriceCurrencyCode !== void 0 && (U.poPriceValue = M.poPriceValue, U.poPriceCurrencyCode = M.poPriceCurrencyCode));
6324
6354
  } else
6325
- k.push({ ...M });
6355
+ N.push({ ...M });
6326
6356
  }
6327
6357
  const T = [...z];
6328
- for (const M of k) {
6358
+ for (const M of N) {
6329
6359
  const L = T.findIndex(
6330
6360
  (U) => U.productEntityId === M.productEntityId && U.variantEntityId === M.variantEntityId
6331
6361
  );
@@ -6340,7 +6370,7 @@ function ka(t) {
6340
6370
  },
6341
6371
  [j, z]
6342
6372
  ), J = B(
6343
- async (f, k, T, P) => {
6373
+ async (f, N, T, P) => {
6344
6374
  if (!n.current || !s?.entityId)
6345
6375
  return null;
6346
6376
  I(!0);
@@ -6348,7 +6378,7 @@ function ka(t) {
6348
6378
  const M = await n.current.updateCartLineItem(
6349
6379
  s.entityId,
6350
6380
  f,
6351
- k,
6381
+ N,
6352
6382
  T,
6353
6383
  P
6354
6384
  );
@@ -6373,14 +6403,14 @@ function ka(t) {
6373
6403
  return null;
6374
6404
  I(!0);
6375
6405
  try {
6376
- const k = await n.current.deleteCartLineItem(
6406
+ const N = await n.current.deleteCartLineItem(
6377
6407
  s.entityId,
6378
6408
  f
6379
6409
  );
6380
- b(k);
6410
+ b(N);
6381
6411
  const T = y.getState();
6382
- if (k) {
6383
- const P = k.lineItems.physicalItems, M = z.filter(
6412
+ if (N) {
6413
+ const P = N.lineItems.physicalItems, M = z.filter(
6384
6414
  (L) => !P.some(
6385
6415
  (U) => U.productEntityId === L.productEntityId && U.variantEntityId === L.variantEntityId
6386
6416
  )
@@ -6390,13 +6420,13 @@ function ka(t) {
6390
6420
  L.productEntityId,
6391
6421
  L.variantEntityId
6392
6422
  );
6393
- await _(k);
6423
+ await _(N);
6394
6424
  } else
6395
6425
  T.setCartEntityId(null), T.clearPoItemPrices(), x(null);
6396
- return k;
6397
- } catch (k) {
6426
+ return N;
6427
+ } catch (N) {
6398
6428
  return i.current?.(
6399
- k instanceof Error ? k : new Error("Failed to remove item")
6429
+ N instanceof Error ? N : new Error("Failed to remove item")
6400
6430
  ), null;
6401
6431
  } finally {
6402
6432
  I(!1);
@@ -6417,13 +6447,13 @@ function ka(t) {
6417
6447
  return console.error("initiateCheckout: No cart entity ID", { bcCart: s }), null;
6418
6448
  I(!0);
6419
6449
  try {
6420
- const f = y.getState().chat.threadId, k = y.getState().cartifact.orderId;
6450
+ const f = y.getState().chat.threadId, N = y.getState().cartifact.orderId;
6421
6451
  if (f)
6422
6452
  try {
6423
6453
  await n.current.updateCheckoutCustomerMessage(
6424
6454
  s.entityId,
6425
6455
  {
6426
- purchaseOrderNumber: k,
6456
+ purchaseOrderNumber: N,
6427
6457
  threadId: f
6428
6458
  }
6429
6459
  );
@@ -6437,7 +6467,7 @@ function ka(t) {
6437
6467
  }
6438
6468
  }, [s, I]), me = B(
6439
6469
  async (f) => {
6440
- if (f === he) {
6470
+ if (f === le) {
6441
6471
  v(f);
6442
6472
  return;
6443
6473
  }
@@ -6449,14 +6479,14 @@ function ka(t) {
6449
6479
  console.error("setShippingAddressOnCheckout: No cart entity ID");
6450
6480
  return;
6451
6481
  }
6452
- let k = null;
6482
+ let N = null;
6453
6483
  if (f === be)
6454
- E && (k = pe(E));
6484
+ k && (N = he(k));
6455
6485
  else {
6456
6486
  const P = l.find((M) => M.id === f);
6457
- P && (k = pe(P));
6487
+ P && (N = he(P));
6458
6488
  }
6459
- if (!k) {
6489
+ if (!N) {
6460
6490
  console.error(
6461
6491
  "setShippingAddressOnCheckout: Address not found",
6462
6492
  f
@@ -6471,21 +6501,21 @@ function ka(t) {
6471
6501
  console.error("setShippingAddressOnCheckout: No line items in cart");
6472
6502
  return;
6473
6503
  }
6474
- Y.current = !0, I(!0), N("updating");
6504
+ Y.current = !0, I(!0), E("updating");
6475
6505
  try {
6476
6506
  const P = await n.current.setCheckoutShippingAddress(
6477
6507
  s.entityId,
6478
- k,
6508
+ N,
6479
6509
  T
6480
6510
  );
6481
- P && x(P), v(f), N("success"), W.current !== void 0 && clearTimeout(W.current), W.current = window.setTimeout(() => {
6482
- N("idle"), W.current = void 0;
6511
+ P && x(P), v(f), E("success"), W.current !== void 0 && clearTimeout(W.current), W.current = window.setTimeout(() => {
6512
+ E("idle"), W.current = void 0;
6483
6513
  }, 1500);
6484
6514
  } catch (P) {
6485
- console.error("setShippingAddressOnCheckout: API error", P), N("error"), i.current?.(
6515
+ console.error("setShippingAddressOnCheckout: API error", P), E("error"), i.current?.(
6486
6516
  P instanceof Error ? P : new Error("Failed to set shipping address")
6487
6517
  ), W.current !== void 0 && clearTimeout(W.current), W.current = window.setTimeout(() => {
6488
- N("idle"), W.current = void 0;
6518
+ E("idle"), W.current = void 0;
6489
6519
  }, 3e3);
6490
6520
  } finally {
6491
6521
  I(!1);
@@ -6494,33 +6524,33 @@ function ka(t) {
6494
6524
  [
6495
6525
  s,
6496
6526
  l,
6497
- E,
6527
+ k,
6498
6528
  I,
6499
- N,
6529
+ E,
6500
6530
  x,
6501
6531
  v
6502
6532
  ]
6503
- ), le = B(
6533
+ ), de = B(
6504
6534
  async (f) => {
6505
- if (f === he) {
6535
+ if (f === le) {
6506
6536
  O(f);
6507
6537
  return;
6508
6538
  }
6509
6539
  if (!n.current || !s?.entityId)
6510
6540
  return;
6511
- let k = null;
6541
+ let N = null;
6512
6542
  if (f === Se)
6513
- g && (k = pe(g));
6543
+ g && (N = he(g));
6514
6544
  else {
6515
6545
  const T = l.find((P) => P.id === f);
6516
- T && (k = pe(T));
6546
+ T && (N = he(T));
6517
6547
  }
6518
- if (k) {
6548
+ if (N) {
6519
6549
  te.current = !0, I(!0), Q("updating");
6520
6550
  try {
6521
6551
  const T = await n.current.setCheckoutBillingAddress(
6522
6552
  s.entityId,
6523
- k
6553
+ N
6524
6554
  );
6525
6555
  T && x(T), O(f), Q("success"), V.current !== void 0 && clearTimeout(V.current), V.current = window.setTimeout(() => {
6526
6556
  Q("idle"), V.current = void 0;
@@ -6572,7 +6602,7 @@ function ka(t) {
6572
6602
  removeLineItem: Pe,
6573
6603
  initiateCheckout: fe,
6574
6604
  setShippingAddressOnCheckout: me,
6575
- setBillingAddressOnCheckout: le,
6605
+ setBillingAddressOnCheckout: de,
6576
6606
  clearCart: ge,
6577
6607
  setSelectedAddressId: v,
6578
6608
  setSelectedBillingAddressId: O
@@ -6626,8 +6656,8 @@ function Pa({
6626
6656
  quantity: v
6627
6657
  }
6628
6658
  ]), !0;
6629
- } catch (N) {
6630
- return console.error("Failed to add to cart:", N), !1;
6659
+ } catch (E) {
6660
+ return console.error("Failed to add to cart:", E), !1;
6631
6661
  }
6632
6662
  },
6633
6663
  [t]
@@ -6677,12 +6707,12 @@ async function $a(t, e, r, n, i, s) {
6677
6707
  let m = 0;
6678
6708
  for (; m < u; ) {
6679
6709
  m++;
6680
- const E = await _s(
6710
+ const k = await _s(
6681
6711
  t,
6682
6712
  e,
6683
6713
  r,
6684
6714
  h
6685
- ), g = await Rs(E, {
6715
+ ), g = await Ls(k, {
6686
6716
  onToolCall: s?.onToolCall
6687
6717
  });
6688
6718
  if (c.push(...g.textParts), o.push(...g.toolCalls), g.finalMessage && l.push(g.finalMessage), g.errorMessage?.includes(Ta)) {
@@ -6753,19 +6783,19 @@ async function $a(t, e, r, n, i, s) {
6753
6783
  );
6754
6784
  const S = l.length > 0 ? l.join(`
6755
6785
 
6756
- `) : c.join(""), b = Aa(o), x = S + b, N = d.filter(
6757
- (E) => E.toolName === Fe
6758
- ).reduce((E, g) => {
6786
+ `) : c.join(""), b = Aa(o), x = S + b, E = d.filter(
6787
+ (k) => k.toolName === Fe
6788
+ ).reduce((k, g) => {
6759
6789
  const A = g.input?.value;
6760
- return E + (A?.length ?? 0);
6790
+ return k + (A?.length ?? 0);
6761
6791
  }, 0), w = d.filter(
6762
- (E) => E.toolName === pt
6763
- ).reduce((E, g) => {
6792
+ (k) => k.toolName === pt
6793
+ ).reduce((k, g) => {
6764
6794
  const A = g.input?.processingFailures;
6765
- return E + (A?.length ?? 0);
6795
+ return k + (A?.length ?? 0);
6766
6796
  }, 0);
6767
6797
  return s?.logger?.debug(
6768
- `Batch ${i}: ${m} iteration(s), ${d.length} client tool call(s), ${N} addToCart item(s), ${w} failure(s)`
6798
+ `Batch ${i}: ${m} iteration(s), ${d.length} client tool call(s), ${E} addToCart item(s), ${w} failure(s)`
6769
6799
  ), x && s?.logger?.debug(`Batch ${i} output: ${x}`), {
6770
6800
  batchIndex: i,
6771
6801
  threadId: r,
@@ -6879,7 +6909,7 @@ function Oa(t) {
6879
6909
  return e.join(`
6880
6910
  `);
6881
6911
  }
6882
- async function Da(t, e) {
6912
+ async function Ra(t, e) {
6883
6913
  const r = Ma(t);
6884
6914
  if (r.setPoMetadataArgs) {
6885
6915
  const s = r.setPoMetadataArgs;
@@ -6900,7 +6930,7 @@ ${s}` : s;
6900
6930
  }
6901
6931
  return i;
6902
6932
  }
6903
- async function La(t, e) {
6933
+ async function Da(t, e) {
6904
6934
  if (e.length === 0)
6905
6935
  return { results: [], processingFailuresString: "", hasErrors: !1 };
6906
6936
  const r = await Ba(
@@ -6917,7 +6947,7 @@ async function La(t, e) {
6917
6947
  }
6918
6948
  );
6919
6949
  let n = "";
6920
- return t.bcCart && (n = await Da(
6950
+ return t.bcCart && (n = await Ra(
6921
6951
  r.results,
6922
6952
  t.bcCart
6923
6953
  )), {
@@ -6926,7 +6956,7 @@ async function La(t, e) {
6926
6956
  hasErrors: r.hasErrors
6927
6957
  };
6928
6958
  }
6929
- function Ra(t) {
6959
+ function La(t) {
6930
6960
  const { bcCart: e } = t, r = y(
6931
6961
  (d) => d.takeshapeConfig
6932
6962
  ), n = y(
@@ -6950,7 +6980,7 @@ function Ra(t) {
6950
6980
  bcCart: e
6951
6981
  };
6952
6982
  try {
6953
- const u = await La(h, d);
6983
+ const u = await Da(h, d);
6954
6984
  if (s(
6955
6985
  u.results,
6956
6986
  u.processingFailuresString
@@ -6988,11 +7018,11 @@ function _a({
6988
7018
  chatPanelRef: i,
6989
7019
  bcCart: s
6990
7020
  }) {
6991
- const o = R(!1), c = y(
7021
+ const o = D(!1), c = y(
6992
7022
  (u) => u.parser.hasProcessedDocument
6993
7023
  ), l = y(
6994
7024
  (u) => u.setHasProcessedDocument
6995
- ), { processBatches: d } = Ra({ bcCart: s });
7025
+ ), { processBatches: d } = La({ bcCart: s });
6996
7026
  return F(() => {
6997
7027
  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
7028
  }, [
@@ -7127,7 +7157,7 @@ function Za({
7127
7157
  createParserThread: t,
7128
7158
  sendParserMessage: e
7129
7159
  }) {
7130
- const [r, n] = D(!1), [i, s] = D(null), o = B(
7160
+ const [r, n] = R(!1), [i, s] = R(null), o = B(
7131
7161
  async (c) => {
7132
7162
  const l = y.getState();
7133
7163
  if (l.setParsedContent(null), n(!0), l.setUploadedFileName(c.name), s(null), c.type === "application/pdf") {
@@ -7176,7 +7206,7 @@ function Mr(t) {
7176
7206
  onThreadCreated: s
7177
7207
  } = t, { projectId: o, apiKey: c, origin: l } = y(
7178
7208
  (S) => S.takeshapeConfig
7179
- ), [d, h] = D(!1), u = R(
7209
+ ), [d, h] = R(!1), u = D(
7180
7210
  n ? { id: n } : null
7181
7211
  ), m = B(async () => {
7182
7212
  h(!0);
@@ -7198,11 +7228,11 @@ function Mr(t) {
7198
7228
  );
7199
7229
  return;
7200
7230
  }
7201
- const N = 500 * 2 ** b;
7231
+ const E = 500 * 2 ** b;
7202
7232
  console.warn(
7203
- `Thread creation failed (attempt ${b + 1}/${S + 1}), retrying in ${N}ms...`,
7233
+ `Thread creation failed (attempt ${b + 1}/${S + 1}), retrying in ${E}ms...`,
7204
7234
  x
7205
- ), await new Promise((I) => setTimeout(I, N)), b++;
7235
+ ), await new Promise((I) => setTimeout(I, E)), b++;
7206
7236
  }
7207
7237
  }, [e, c, s, l, i, o]);
7208
7238
  return F(() => {
@@ -7228,7 +7258,7 @@ function ei() {
7228
7258
  (g) => g.parser.parsedContent
7229
7259
  ), c = y(
7230
7260
  (g) => g.parser.uploadedFileName
7231
- ), l = R(
7261
+ ), l = D(
7232
7262
  null
7233
7263
  ), {
7234
7264
  messages: d,
@@ -7270,7 +7300,7 @@ function ei() {
7270
7300
  setIsUploadingFile: b,
7271
7301
  parserError: x,
7272
7302
  setParserError: v,
7273
- handleFileUpload: N
7303
+ handleFileUpload: E
7274
7304
  } = Za({
7275
7305
  createParserThread: s,
7276
7306
  sendParserMessage: h
@@ -7283,8 +7313,8 @@ function ei() {
7283
7313
  "file.type": g.type,
7284
7314
  "file.size": g.size
7285
7315
  }
7286
- }), N(g)),
7287
- [N]
7316
+ }), E(g)),
7317
+ [E]
7288
7318
  );
7289
7319
  F(() => {
7290
7320
  if (d.length > 0) {
@@ -7301,7 +7331,7 @@ function ei() {
7301
7331
  }, [u, o]);
7302
7332
  const w = B(() => {
7303
7333
  l.current?.setStatus({ code: 2, message: "cancelled" }), l.current?.end(), l.current = null, v(null), m([]), y.getState().setParsedContent(null);
7304
- }, [v, m]), E = B(() => {
7334
+ }, [v, m]), k = B(() => {
7305
7335
  l.current?.setStatus({ code: 2, message: "cancelled" }), l.current?.end(), l.current = null, m([]), y.getState().clearParser(), b(!1), v(null);
7306
7336
  }, [m, b, v]);
7307
7337
  return {
@@ -7313,7 +7343,7 @@ function ei() {
7313
7343
  parserMessages: d,
7314
7344
  handleFileUpload: I,
7315
7345
  handleClearError: w,
7316
- reset: E
7346
+ reset: k
7317
7347
  };
7318
7348
  }
7319
7349
  class ti {
@@ -7956,11 +7986,11 @@ function ki({
7956
7986
  createOnMount: !l,
7957
7987
  // Only create if no existing thread
7958
7988
  existingThreadId: l
7959
- }), b = y((C) => C.appState), x = y((C) => C.setAppState), v = R(null), N = R(
7989
+ }), b = y((C) => C.appState), x = y((C) => C.setAppState), v = D(null), E = D(
7960
7990
  null
7961
- ), I = R(
7991
+ ), I = D(
7962
7992
  null
7963
- ), w = Re((C) => C.isExpanded), E = Re((C) => C.setExpanded), g = Re((C) => C.reset), A = ei(), $ = ka({
7993
+ ), w = Le((C) => C.isExpanded), k = Le((C) => C.setExpanded), g = Le((C) => C.reset), A = ei(), $ = ka({
7964
7994
  client: n.client,
7965
7995
  onError: (C) => console.error("BigCommerce error:", C)
7966
7996
  }), O = y((C) => C.cartifact.orderId), Q = y((C) => C.cartifact.buyerInfo), H = y(
@@ -7973,12 +8003,12 @@ function ki({
7973
8003
  (C) => C.cartifact.itemWarnings
7974
8004
  ), se = y((C) => C.clearCartifact), Y = y((C) => C.clearBcSession), te = y(
7975
8005
  (C) => C.clearAddressSelections
7976
- ), W = y((C) => C.clearChat), { cartItems: V } = $, ie = R([]), Ie = B(
8006
+ ), W = y((C) => C.clearChat), { cartItems: V } = $, ie = D([]), Ie = B(
7977
8007
  async ({ toolCall: C }) => {
7978
8008
  ie.current.push(C);
7979
8009
  },
7980
8010
  []
7981
- ), _ = R(/* @__PURE__ */ new Set()), { messages: j, sendMessage: K, status: J, error: Pe, setMessages: fe, addToolOutput: me } = zt({
8011
+ ), _ = D(/* @__PURE__ */ new Set()), { messages: j, sendMessage: K, status: J, error: Pe, setMessages: fe, addToolOutput: me } = zt({
7982
8012
  transport: new Qt({
7983
8013
  api: `${s}/project/${o}/agents/messages`,
7984
8014
  headers: {
@@ -7990,15 +8020,15 @@ function ki({
7990
8020
  throw new Error("No messages to send");
7991
8021
  let we = [re];
7992
8022
  if (re.role === "user" && C.messages.length >= 2) {
7993
- const ue = C.messages[C.messages.length - 2], Xe = _.current;
7994
- if (ue?.role === "assistant" && Xe.size > 0) {
8023
+ const pe = C.messages[C.messages.length - 2], Xe = _.current;
8024
+ if (pe?.role === "assistant" && Xe.size > 0) {
7995
8025
  const gt = Ii(
7996
- ue.parts
8026
+ pe.parts
7997
8027
  ).filter(
7998
8028
  (yt) => Xe.has(yt.toolCallId)
7999
8029
  );
8000
8030
  Xe.clear(), gt.length > 0 && (we = [{
8001
- ...ue,
8031
+ ...pe,
8002
8032
  parts: gt.map((Te) => ({
8003
8033
  type: Te.type,
8004
8034
  toolName: wi(Te),
@@ -8029,14 +8059,14 @@ function ki({
8029
8059
  messages: h,
8030
8060
  onToolCall: Ie,
8031
8061
  onError: (C) => {
8032
- console.error("[useChat onError]", C), N.current?.setStatus({
8062
+ console.error("[useChat onError]", C), E.current?.setStatus({
8033
8063
  code: 2,
8034
8064
  message: "internal_error"
8035
- }), N.current?.end(), N.current = null;
8065
+ }), E.current?.end(), E.current = null;
8036
8066
  }
8037
- }), le = B(
8067
+ }), de = B(
8038
8068
  (C) => {
8039
- N.current?.end(), N.current = nt({
8069
+ E.current?.end(), E.current = nt({
8040
8070
  name: "po-agent-turn",
8041
8071
  op: "ai.agent",
8042
8072
  attributes: {
@@ -8047,33 +8077,33 @@ function ki({
8047
8077
  [K, r]
8048
8078
  );
8049
8079
  F(() => {
8050
- J === "ready" && N.current && (N.current.setStatus({ code: 1, message: "ok" }), N.current.end(), N.current = null);
8080
+ J === "ready" && E.current && (E.current.setStatus({ code: 1, message: "ok" }), E.current.end(), E.current = null);
8051
8081
  }, [J]), F(() => () => {
8052
- N.current?.end(), I.current?.end();
8082
+ E.current?.end(), I.current?.end();
8053
8083
  }, []), F(() => {
8054
8084
  if (J === "ready" && ie.current.length > 0) {
8055
8085
  const C = [...ie.current];
8056
8086
  ie.current = [], mi(C, j, $).then(async (re) => {
8057
8087
  for (const we of re.outputs)
8058
8088
  _.current.add(we.toolCallId), await me(we);
8059
- re.outputs.length > 0 && le({ text: ot });
8089
+ re.outputs.length > 0 && de({ text: ot });
8060
8090
  }).catch((re) => {
8061
8091
  console.error("[executeDeferredToolCalls] Error:", re);
8062
8092
  });
8063
8093
  }
8064
- }, [J, j, $, me, le]), F(() => {
8094
+ }, [J, j, $, me, de]), F(() => {
8065
8095
  y.getState().setMessages(j);
8066
8096
  }, [j]);
8067
8097
  const ge = y(
8068
8098
  (C) => C.ai.pendingMessage
8069
- ), f = y((C) => C.ai.shouldScroll), k = y((C) => C.consumeMessage);
8099
+ ), f = y((C) => C.ai.shouldScroll), N = y((C) => C.consumeMessage);
8070
8100
  F(() => {
8071
- ge && (le({ text: ge }), k(), f && requestAnimationFrame(() => {
8101
+ ge && (de({ text: ge }), N(), f && requestAnimationFrame(() => {
8072
8102
  v.current?.scrollToBottom();
8073
8103
  }));
8074
- }, [ge, f, le, k]), F(() => {
8075
- i && b === "chatting" && E(!0);
8076
- }, [i, b, E]);
8104
+ }, [ge, f, de, N]), F(() => {
8105
+ i && b === "chatting" && k(!0);
8106
+ }, [i, b, k]);
8077
8107
  const T = m || J === "submitted" || J === "streaming", P = oe(() => ma(j, J), [j, J]), M = _a({
8078
8108
  appState: b,
8079
8109
  setAppState: x,
@@ -8111,11 +8141,11 @@ function ki({
8111
8141
  },
8112
8142
  [n.onViewProduct]
8113
8143
  ), ce = B(() => {
8114
- const C = [...j].reverse().find((ue) => ue.role === "user");
8144
+ const C = [...j].reverse().find((pe) => pe.role === "user");
8115
8145
  if (!C) return;
8116
8146
  const re = C.parts?.filter(
8117
- (ue) => ue.type === "text"
8118
- ).map((ue) => ue.text).join(`
8147
+ (pe) => pe.type === "text"
8148
+ ).map((pe) => pe.text).join(`
8119
8149
  `);
8120
8150
  if (!re) return;
8121
8151
  const we = j.lastIndexOf(C);
@@ -8152,7 +8182,7 @@ function ki({
8152
8182
  parserError: A.parserError
8153
8183
  }
8154
8184
  ) });
8155
- const de = {
8185
+ const ue = {
8156
8186
  className: t,
8157
8187
  messages: j,
8158
8188
  input: d,
@@ -8191,11 +8221,11 @@ function ki({
8191
8221
  poMetadataSet: ae,
8192
8222
  onNewOrder: ye
8193
8223
  };
8194
- 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(
8195
- Lt,
8224
+ return i && w ? /* @__PURE__ */ a(An, { children: /* @__PURE__ */ a(Dt, { ...ue, onMinimize: () => k(!1) }) }) : /* @__PURE__ */ a("div", { className: "h-full max-w-[1440px] mx-auto", children: /* @__PURE__ */ a(
8225
+ Dt,
8196
8226
  {
8197
- ...de,
8198
- onExpand: i ? () => E(!0) : void 0
8227
+ ...ue,
8228
+ onExpand: i ? () => k(!0) : void 0
8199
8229
  }
8200
8230
  ) });
8201
8231
  }
@@ -8250,4 +8280,4 @@ export {
8250
8280
  Vi as r,
8251
8281
  Gi as s
8252
8282
  };
8253
- //# sourceMappingURL=purchase-order-chat-wrapper-Ctm9BV2k.js.map
8283
+ //# sourceMappingURL=purchase-order-chat-wrapper-CtCPGHtH.js.map