@takeshape/purchase-order-chat 1.64.0 → 1.64.1

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.
@@ -12,16 +12,16 @@ import { devtools as zr, persist as zt } from "zustand/middleware";
12
12
  import { Streamdown as He } from "streamdown";
13
13
  import { z as yt } from "zod";
14
14
  import Hr from "p-map";
15
- function ke(...t) {
15
+ function Pe(...t) {
16
16
  return Vr(Wr(t));
17
17
  }
18
- function qi(t, e) {
18
+ function Wi(t, e) {
19
19
  return t.replace(/:(\w+)/g, (r, n) => {
20
20
  const i = e[n];
21
21
  return i != null ? String(i) : "";
22
22
  });
23
23
  }
24
- const Qr = "__vite_c_css_pos_initial_05f37d663790485ea5a6ff7e3c2189b4", xt = "__vite_c_css_pos_update_05f37d663790485ea5a6ff7e3c2189b4", bt = () => typeof window < "u" ? window[Qr] : void 0, ji = (t) => {
24
+ const Qr = "__vite_c_css_pos_initial_2d6e636c35f8408d82e22d360c298aeb", xt = "__vite_c_css_pos_update_2d6e636c35f8408d82e22d360c298aeb", bt = () => typeof window < "u" ? window[Qr] : void 0, Vi = (t) => {
25
25
  const [e, r] = R(() => bt() || /* @__PURE__ */ new Map()), [n, i] = R(0);
26
26
  return F(() => {
27
27
  const s = (o) => {
@@ -139,7 +139,7 @@ const Xr = ve(
139
139
  }
140
140
  }
141
141
  `
142
- ), V = jt(), Be = V(`
142
+ ), V = jt(), $e = V(`
143
143
  fragment CartFields on Cart {
144
144
  id
145
145
  entityId
@@ -224,7 +224,7 @@ const Xr = ve(
224
224
  }
225
225
  }
226
226
  `,
227
- [Be]
227
+ [$e]
228
228
  ), tn = V(
229
229
  `
230
230
  mutation CreateCart($input: CreateCartInput!) {
@@ -237,7 +237,7 @@ const Xr = ve(
237
237
  }
238
238
  }
239
239
  `,
240
- [Be]
240
+ [$e]
241
241
  ), rn = V(
242
242
  `
243
243
  mutation AddCartLineItems($input: AddCartLineItemsInput!) {
@@ -250,7 +250,7 @@ const Xr = ve(
250
250
  }
251
251
  }
252
252
  `,
253
- [Be]
253
+ [$e]
254
254
  ), nn = V(
255
255
  `
256
256
  mutation UpdateCartLineItem($input: UpdateCartLineItemInput!) {
@@ -263,7 +263,7 @@ const Xr = ve(
263
263
  }
264
264
  }
265
265
  `,
266
- [Be]
266
+ [$e]
267
267
  ), sn = V(
268
268
  `
269
269
  mutation DeleteCartLineItem($input: DeleteCartLineItemInput!) {
@@ -276,7 +276,7 @@ const Xr = ve(
276
276
  }
277
277
  }
278
278
  `,
279
- [Be]
279
+ [$e]
280
280
  ), an = V(`
281
281
  mutation DeleteCart($input: DeleteCartInput!) {
282
282
  cart {
@@ -306,7 +306,7 @@ const Xr = ve(
306
306
  }
307
307
  }
308
308
  }
309
- `), $e = V(`
309
+ `), Me = V(`
310
310
  fragment CheckoutFields on Checkout {
311
311
  entityId
312
312
  subtotal {
@@ -392,7 +392,7 @@ const Xr = ve(
392
392
  }
393
393
  }
394
394
  `,
395
- [$e]
395
+ [Me]
396
396
  ), dn = V(
397
397
  `
398
398
  mutation AddCheckoutShippingConsignments($input: AddCheckoutShippingConsignmentsInput!) {
@@ -405,7 +405,7 @@ const Xr = ve(
405
405
  }
406
406
  }
407
407
  `,
408
- [$e]
408
+ [Me]
409
409
  ), un = V(
410
410
  `
411
411
  mutation AddCheckoutBillingAddressMutation($input: AddCheckoutBillingAddressInput!) {
@@ -418,7 +418,7 @@ const Xr = ve(
418
418
  }
419
419
  }
420
420
  `,
421
- [$e]
421
+ [Me]
422
422
  );
423
423
  V(
424
424
  `
@@ -432,7 +432,7 @@ V(
432
432
  }
433
433
  }
434
434
  `,
435
- [$e]
435
+ [Me]
436
436
  );
437
437
  const pn = V(
438
438
  `
@@ -446,7 +446,7 @@ const pn = V(
446
446
  }
447
447
  }
448
448
  `,
449
- [$e]
449
+ [Me]
450
450
  ), vt = V(`
451
451
  query GetProductDisplayData($entityIds: [Int!], $variantEntityIds: [Int!], $first: Int = 50) {
452
452
  site {
@@ -922,11 +922,11 @@ async function We(t, e, r, n) {
922
922
  return i;
923
923
  }
924
924
  const xe = 20;
925
- function De(t) {
926
- return Ee(Be, t);
925
+ function Re(t) {
926
+ return Ee($e, t);
927
927
  }
928
928
  function Ve(t) {
929
- return Ee($e, t);
929
+ return Ee(Me, t);
930
930
  }
931
931
  function vn(t) {
932
932
  return t.startsWith("http://") || t.startsWith("https://") ? t : typeof window < "u" && window.location?.origin ? `${window.location.origin}${t.startsWith("/") ? "" : "/"}${t}` : t;
@@ -1026,7 +1026,7 @@ class In {
1026
1026
  cartEntityId: e
1027
1027
  }
1028
1028
  })).site.cart;
1029
- return n ? De(n) : null;
1029
+ return n ? Re(n) : null;
1030
1030
  }
1031
1031
  /**
1032
1032
  * Create a new cart with line items
@@ -1113,7 +1113,7 @@ class In {
1113
1113
  },
1114
1114
  { retry: n }
1115
1115
  )).cart.addCartLineItems?.cart;
1116
- return s ? De(s) : null;
1116
+ return s ? Re(s) : null;
1117
1117
  }
1118
1118
  /**
1119
1119
  * Try to add a batch to cart, isolating failures if needed.
@@ -1167,7 +1167,7 @@ class In {
1167
1167
  },
1168
1168
  { retry: r }
1169
1169
  )).cart.createCart?.cart;
1170
- return i ? De(i) : null;
1170
+ return i ? Re(i) : null;
1171
1171
  }
1172
1172
  /**
1173
1173
  * Try to create a cart with a batch, isolating failures if needed.
@@ -1255,7 +1255,7 @@ class In {
1255
1255
  }
1256
1256
  }
1257
1257
  })).cart.updateCartLineItem?.cart;
1258
- return c ? De(c) : null;
1258
+ return c ? Re(c) : null;
1259
1259
  }
1260
1260
  /**
1261
1261
  * Remove a line item from the cart
@@ -1270,7 +1270,7 @@ class In {
1270
1270
  }
1271
1271
  }
1272
1272
  })).cart.deleteCartLineItem?.cart;
1273
- return i ? De(i) : null;
1273
+ return i ? Re(i) : null;
1274
1274
  }
1275
1275
  /**
1276
1276
  * Delete an entire cart
@@ -1659,20 +1659,20 @@ class In {
1659
1659
  };
1660
1660
  }
1661
1661
  }
1662
- function Wi(t) {
1662
+ function zi(t) {
1663
1663
  return `https://store-${t}.mybigcommerce.com/graphql`;
1664
1664
  }
1665
1665
  function wn(t) {
1666
1666
  return new In(t);
1667
1667
  }
1668
- const Re = at((t) => ({
1668
+ const _e = at((t) => ({
1669
1669
  isExpanded: !1,
1670
1670
  setExpanded: (e) => t({ isExpanded: e }),
1671
1671
  toggleExpanded: () => t((e) => ({ isExpanded: !e.isExpanded })),
1672
1672
  reset: () => t({ isExpanded: !1 })
1673
1673
  }));
1674
1674
  function Sn({ children: t }) {
1675
- const e = Re((i) => i.isExpanded), r = Re((i) => i.setExpanded), n = D(null);
1675
+ const e = _e((i) => i.isExpanded), r = _e((i) => i.setExpanded), n = D(null);
1676
1676
  return F(() => {
1677
1677
  if (!e) return;
1678
1678
  const i = (s) => {
@@ -1743,9 +1743,9 @@ async function Pn(t, e) {
1743
1743
  }
1744
1744
  }
1745
1745
  async function Tn(t, e) {
1746
- const { HeifDecoder: r } = await import("libheif-js/wasm-bundle"), n = await new Promise((v, b) => {
1746
+ const { HeifDecoder: r } = await import("libheif-js/wasm-bundle"), n = await new Promise((C, b) => {
1747
1747
  const x = new FileReader();
1748
- x.onload = () => v(new Uint8Array(x.result)), x.onerror = () => b(new Error("Failed to read file")), x.readAsArrayBuffer(t);
1748
+ x.onload = () => C(new Uint8Array(x.result)), x.onerror = () => b(new Error("Failed to read file")), x.readAsArrayBuffer(t);
1749
1749
  }), o = new r().decode(n)[0];
1750
1750
  if (!o)
1751
1751
  throw new Error("HEIF processing error");
@@ -1753,10 +1753,10 @@ async function Tn(t, e) {
1753
1753
  if (!p)
1754
1754
  throw new Error("Failed to get canvas context");
1755
1755
  const u = p.createImageData(c, l);
1756
- await new Promise((v, b) => {
1756
+ await new Promise((C, b) => {
1757
1757
  o.display(u, (x) => {
1758
1758
  if (!x) return b(new Error("HEIF processing error"));
1759
- v();
1759
+ C();
1760
1760
  });
1761
1761
  }), p.putImageData(u, 0, 0);
1762
1762
  const m = await d.convertToBlob({ type: "image/jpeg", quality: e });
@@ -1854,7 +1854,7 @@ function sr({ onFile: t, onBeforeValidate: e }) {
1854
1854
  I && l(I), x.target && (x.target.value = "");
1855
1855
  },
1856
1856
  [l]
1857
- ), v = M(() => {
1857
+ ), C = M(() => {
1858
1858
  o.current?.click();
1859
1859
  }, []), b = M(() => {
1860
1860
  c.current?.click();
@@ -1870,7 +1870,7 @@ function sr({ onFile: t, onBeforeValidate: e }) {
1870
1870
  onDrop: u
1871
1871
  },
1872
1872
  handleFileChange: m,
1873
- openFilePicker: v,
1873
+ openFilePicker: C,
1874
1874
  openCamera: b
1875
1875
  };
1876
1876
  }
@@ -1978,7 +1978,7 @@ const _n = () => /* @__PURE__ */ h(
1978
1978
  /* @__PURE__ */ a("line", { x1: "12", y1: "16", x2: "12.01", y2: "16" })
1979
1979
  ]
1980
1980
  }
1981
- ), Me = ({ size: t = 12 }) => /* @__PURE__ */ h(
1981
+ ), Oe = ({ size: t = 12 }) => /* @__PURE__ */ h(
1982
1982
  "svg",
1983
1983
  {
1984
1984
  width: t,
@@ -2009,7 +2009,7 @@ function Un({
2009
2009
  return /* @__PURE__ */ h(
2010
2010
  "div",
2011
2011
  {
2012
- className: ke(
2012
+ className: Pe(
2013
2013
  "grid gap-2",
2014
2014
  s ? "grid-cols-2" : "grid-cols-1"
2015
2015
  ),
@@ -2060,7 +2060,7 @@ function wt(t) {
2060
2060
  } = t, p = n === le, u = r.find(c);
2061
2061
  let m = d && !!n && !p;
2062
2062
  m && u && (m = u.id !== n);
2063
- const v = r.filter(l);
2063
+ const C = r.filter(l);
2064
2064
  return /* @__PURE__ */ h(
2065
2065
  "div",
2066
2066
  {
@@ -2069,7 +2069,7 @@ function wt(t) {
2069
2069
  /* @__PURE__ */ h("div", { className: "flex justify-between items-center mb-0.5", children: [
2070
2070
  /* @__PURE__ */ a("span", { className: "text-2xs text-text-tertiary uppercase tracking-[0.05em]", children: e }),
2071
2071
  i === "updating" && /* @__PURE__ */ h("span", { className: "flex items-center gap-1 text-2xs font-medium text-text-tertiary uppercase tracking-[0.025em]", children: [
2072
- /* @__PURE__ */ a(Me, { size: 10 }),
2072
+ /* @__PURE__ */ a(Oe, { size: 10 }),
2073
2073
  "Updating..."
2074
2074
  ] }),
2075
2075
  i === "success" && /* @__PURE__ */ h("span", { className: "flex items-center gap-0.5 text-2xs font-semibold text-success-text uppercase tracking-[0.025em]", children: [
@@ -2093,14 +2093,14 @@ function wt(t) {
2093
2093
  /* @__PURE__ */ a("option", { value: o.id, children: /* @__PURE__ */ a(St, { address: o }) }, o.id),
2094
2094
  /* @__PURE__ */ a("option", { disabled: !0, children: "---" })
2095
2095
  ] }),
2096
- v.map((b) => /* @__PURE__ */ a("option", { value: b.id, children: /* @__PURE__ */ a(
2096
+ C.map((b) => /* @__PURE__ */ a("option", { value: b.id, children: /* @__PURE__ */ a(
2097
2097
  St,
2098
2098
  {
2099
2099
  address: b,
2100
2100
  isDefault: c
2101
2101
  }
2102
2102
  ) }, b.id)),
2103
- v.length > 0 && /* @__PURE__ */ a("option", { disabled: !0, children: "---" }),
2103
+ C.length > 0 && /* @__PURE__ */ a("option", { disabled: !0, children: "---" }),
2104
2104
  /* @__PURE__ */ a("option", { value: le, children: "Enter an address at checkout" }, le)
2105
2105
  ]
2106
2106
  }
@@ -2165,7 +2165,7 @@ function jn({ address: t }) {
2165
2165
  }
2166
2166
  );
2167
2167
  }
2168
- const Ae = (t, e = "USD") => new Intl.NumberFormat("en-US", {
2168
+ const Be = (t, e = "USD") => new Intl.NumberFormat("en-US", {
2169
2169
  style: "currency",
2170
2170
  currency: e
2171
2171
  }).format(t);
@@ -2176,7 +2176,7 @@ function Xe({ label: t, value: e }) {
2176
2176
  ] });
2177
2177
  }
2178
2178
  function et(t, e) {
2179
- return t != null ? Ae(t, e) : "...";
2179
+ return t != null ? Be(t, e) : "...";
2180
2180
  }
2181
2181
  function Wn({
2182
2182
  subtotal: t,
@@ -2195,7 +2195,7 @@ function Wn({
2195
2195
  Xe,
2196
2196
  {
2197
2197
  label: "Subtotal",
2198
- value: Ae(t, i)
2198
+ value: Be(t, i)
2199
2199
  }
2200
2200
  ),
2201
2201
  /* @__PURE__ */ a(Xe, { label: "Tax", value: et(e, i) }),
@@ -2269,7 +2269,7 @@ function Nt({
2269
2269
  "button",
2270
2270
  {
2271
2271
  type: "button",
2272
- className: e ? ke(Et, e) : Et,
2272
+ className: e ? Pe(Et, e) : Et,
2273
2273
  ...r,
2274
2274
  children: t
2275
2275
  }
@@ -2308,7 +2308,7 @@ function cr({
2308
2308
  e(A);
2309
2309
  }
2310
2310
  }
2311
- }, v = async () => {
2311
+ }, C = async () => {
2312
2312
  const N = Number.parseInt(c, 10);
2313
2313
  if (s)
2314
2314
  if (!Number.isNaN(N) && N >= r && N !== t) {
@@ -2379,7 +2379,7 @@ function cr({
2379
2379
  value: c,
2380
2380
  disabled: k,
2381
2381
  onChange: m,
2382
- onBlur: v,
2382
+ onBlur: C,
2383
2383
  onKeyDown: b,
2384
2384
  "data-testid": o,
2385
2385
  className: `w-8 h-8 px-0.5 py-0.5 text-xs text-center focus:outline-none focus:border-border-focus text-text border border-solid ${k ? "border-border bg-surface-tertiary opacity-60" : "border-border"}`
@@ -2409,7 +2409,7 @@ function cr({
2409
2409
  )
2410
2410
  }
2411
2411
  ),
2412
- k && /* @__PURE__ */ a("span", { className: "text-text-tertiary ml-0.5", children: /* @__PURE__ */ a(Me, {}) }),
2412
+ k && /* @__PURE__ */ a("span", { className: "text-text-tertiary ml-0.5", children: /* @__PURE__ */ a(Oe, {}) }),
2413
2413
  d === "success" && /* @__PURE__ */ a("span", { className: "text-success ml-0.5", children: /* @__PURE__ */ a(Ue, {}) }),
2414
2414
  d === "error" && /* @__PURE__ */ a("span", { className: "text-error text-xs ml-0.5", children: "Failed" })
2415
2415
  ] });
@@ -2479,10 +2479,10 @@ function Vn(t) {
2479
2479
  d ? "Catalog price lower" : "Catalog price higher",
2480
2480
  " · ",
2481
2481
  "PO: ",
2482
- Ae(o, e.poPriceCurrencyCode),
2482
+ Be(o, e.poPriceCurrencyCode),
2483
2483
  " → Catalog:",
2484
2484
  " ",
2485
- Ae(e.price ?? 0, e.catalogPriceCurrencyCode)
2485
+ Be(e.price ?? 0, e.catalogPriceCurrencyCode)
2486
2486
  ] })
2487
2487
  }
2488
2488
  ),
@@ -2495,7 +2495,7 @@ function Vn(t) {
2495
2495
  onClick: () => i(e.name, e.sku)
2496
2496
  }
2497
2497
  ) }),
2498
- e.price !== void 0 && /* @__PURE__ */ a("span", { className: "text-sm font-semibold text-text", children: Ae(
2498
+ e.price !== void 0 && /* @__PURE__ */ a("span", { className: "text-sm font-semibold text-text", children: Be(
2499
2499
  e.price * e.quantity,
2500
2500
  e.catalogPriceCurrencyCode
2501
2501
  ) })
@@ -2515,7 +2515,7 @@ function zn(t) {
2515
2515
  );
2516
2516
  }
2517
2517
  const kt = "flex items-center gap-1 min-h-11 px-3 py-1 text-xs font-medium text-text bg-surface-secondary border border-border-focus/20 rounded-md hover:bg-surface-tertiary hover:border-border-focus/35 transition-all whitespace-nowrap";
2518
- function _e({
2518
+ function Le({
2519
2519
  children: t,
2520
2520
  className: e,
2521
2521
  ...r
@@ -2524,7 +2524,7 @@ function _e({
2524
2524
  "button",
2525
2525
  {
2526
2526
  type: "button",
2527
- className: e ? ke(kt, e) : kt,
2527
+ className: e ? Pe(kt, e) : kt,
2528
2528
  ...r,
2529
2529
  children: t
2530
2530
  }
@@ -2583,7 +2583,7 @@ function lr({ onNewOrder: t }) {
2583
2583
  children: "No"
2584
2584
  }
2585
2585
  )
2586
- ] }) : /* @__PURE__ */ h(_e, { onClick: c, title: "Start a new order", children: [
2586
+ ] }) : /* @__PURE__ */ h(Le, { onClick: c, title: "Start a new order", children: [
2587
2587
  /* @__PURE__ */ a(
2588
2588
  "svg",
2589
2589
  {
@@ -2631,7 +2631,7 @@ function Qn({
2631
2631
  return /* @__PURE__ */ h(
2632
2632
  "div",
2633
2633
  {
2634
- className: ke(
2634
+ className: Pe(
2635
2635
  "rounded-lg flex flex-col h-full bg-surface-secondary relative transition-colors duration-200",
2636
2636
  e && "bg-surface-tertiary",
2637
2637
  t
@@ -2639,11 +2639,11 @@ function Qn({
2639
2639
  children: [
2640
2640
  s && /* @__PURE__ */ h("div", { className: "absolute top-0 right-0 px-4 py-3 z-10 flex items-center gap-2", children: [
2641
2641
  r && /* @__PURE__ */ a(lr, { onNewOrder: r }),
2642
- n && /* @__PURE__ */ h(_e, { onClick: n, "aria-label": "Expand", children: [
2642
+ n && /* @__PURE__ */ h(Le, { onClick: n, "aria-label": "Expand", children: [
2643
2643
  /* @__PURE__ */ a(ir, { size: 14 }),
2644
2644
  "Expand"
2645
2645
  ] }),
2646
- i && /* @__PURE__ */ h(_e, { onClick: i, "aria-label": "Minimize", children: [
2646
+ i && /* @__PURE__ */ h(Le, { onClick: i, "aria-label": "Minimize", children: [
2647
2647
  /* @__PURE__ */ a(or, { size: 14 }),
2648
2648
  "Minimize"
2649
2649
  ] })
@@ -3442,7 +3442,7 @@ function ls({
3442
3442
  addresses: p = [],
3443
3443
  selectedAddressId: u,
3444
3444
  addressUpdateStatus: m,
3445
- onAddressChange: v,
3445
+ onAddressChange: C,
3446
3446
  selectedBillingAddressId: b,
3447
3447
  billingAddressUpdateStatus: x,
3448
3448
  onBillingAddressChange: I,
@@ -3488,11 +3488,11 @@ function ls({
3488
3488
  /* @__PURE__ */ a("h2", { className: "text-lg font-normal text-text m-0", children: "Cart" }),
3489
3489
  /* @__PURE__ */ h("div", { className: "flex items-center gap-2", children: [
3490
3490
  $ && /* @__PURE__ */ a(lr, { onNewOrder: $ }),
3491
- B && /* @__PURE__ */ h(_e, { onClick: B, "aria-label": "Expand", children: [
3491
+ B && /* @__PURE__ */ h(Le, { onClick: B, "aria-label": "Expand", children: [
3492
3492
  /* @__PURE__ */ a(ir, { size: 14 }),
3493
3493
  "Expand"
3494
3494
  ] }),
3495
- Q && /* @__PURE__ */ h(_e, { onClick: Q, "aria-label": "Minimize", children: [
3495
+ Q && /* @__PURE__ */ h(Le, { onClick: Q, "aria-label": "Minimize", children: [
3496
3496
  /* @__PURE__ */ a(or, { size: 14 }),
3497
3497
  "Minimize"
3498
3498
  ] })
@@ -3526,7 +3526,7 @@ function ls({
3526
3526
  addresses: p,
3527
3527
  selectedAddressId: u,
3528
3528
  addressUpdateStatus: m,
3529
- onAddressChange: v,
3529
+ onAddressChange: C,
3530
3530
  selectedBillingAddressId: b,
3531
3531
  billingAddressUpdateStatus: x,
3532
3532
  onBillingAddressChange: I,
@@ -3676,7 +3676,7 @@ function fs({
3676
3676
  }
3677
3677
  ) });
3678
3678
  }
3679
- const hr = "showProducts", ms = "searchProducts", gs = "searchProductsFromChat", ys = "searchProductsBySku", Oe = "addToCart", fr = "updateCart", mr = "removeFromCart", gr = "clearCart", yr = "getCart", dt = "getPurchaseOrderData", Ye = "setPoMetadata", xr = "setItemWarnings", br = "removeItemWarnings", ut = "addProcessingFailures", xs = /* @__PURE__ */ new Set([hr]);
3679
+ const hr = "showProducts", ms = "searchProducts", gs = "searchProductsFromChat", ys = "searchProductsBySku", Fe = "addToCart", fr = "updateCart", mr = "removeFromCart", gr = "clearCart", yr = "getCart", dt = "getPurchaseOrderData", Ye = "setPoMetadata", xr = "setItemWarnings", br = "removeItemWarnings", ut = "addProcessingFailures", xs = /* @__PURE__ */ new Set([hr]);
3680
3680
  function bs(t) {
3681
3681
  return t.type === "tool" && !xs.has(t.toolName);
3682
3682
  }
@@ -3954,7 +3954,7 @@ function Bt({
3954
3954
  selections: c,
3955
3955
  onSelectionChange: l
3956
3956
  }) {
3957
- const [d, p] = R(1), [u, m] = R(!1), [v, b] = R(!1), x = i === "horizontal", I = g(
3957
+ const [d, p] = R(1), [u, m] = R(!1), [C, b] = R(!1), x = i === "horizontal", I = g(
3958
3958
  (q) => t.productEntityId !== void 0 ? q.bcSession.variantCache[t.productEntityId] : void 0
3959
3959
  ), w = ee(() => !o || !c || c.size === 0 ? o?.defaultVariant ?? null : ks(
3960
3960
  t.productEntityId,
@@ -4045,7 +4045,7 @@ function Bt({
4045
4045
  }
4046
4046
  ),
4047
4047
  /* @__PURE__ */ a("p", { className: "text-xs text-text-quaternary m-0 mt-0.5", children: A }),
4048
- $ !== void 0 && /* @__PURE__ */ a("p", { className: "text-sm font-semibold text-text m-0 mt-1", children: Ae($) }),
4048
+ $ !== void 0 && /* @__PURE__ */ a("p", { className: "text-sm font-semibold text-text m-0 mt-1", children: Be($) }),
4049
4049
  j && /* @__PURE__ */ a("p", { className: "text-xs text-error m-0 mt-1 font-medium", children: "Out of Stock" }),
4050
4050
  !x && !j && B !== void 0 && B > 0 && /* @__PURE__ */ h("p", { className: "text-2xs text-success font-medium m-0 mt-0.5", children: [
4051
4051
  B,
@@ -4093,9 +4093,9 @@ function Bt({
4093
4093
  {
4094
4094
  type: "button",
4095
4095
  onClick: re,
4096
- disabled: u || v || !!Y || j,
4097
- className: `py-1.5 px-3 text-xs font-medium rounded border-none ${x ? "" : "w-full"} ${Bs(u, v, !!Y || j)}`,
4098
- children: u ? "Adding..." : v ? "✓ Added" : "Add to cart"
4096
+ disabled: u || C || !!Y || j,
4097
+ className: `py-1.5 px-3 text-xs font-medium rounded border-none ${x ? "" : "w-full"} ${Bs(u, C, !!Y || j)}`,
4098
+ children: u ? "Adding..." : C ? "✓ Added" : "Add to cart"
4099
4099
  }
4100
4100
  )
4101
4101
  ]
@@ -4141,7 +4141,7 @@ function $s({
4141
4141
  return w;
4142
4142
  });
4143
4143
  }, [i, d, t]);
4144
- const v = (I, w, k) => {
4144
+ const C = (I, w, k) => {
4145
4145
  const N = m.current.get(I) ?? /* @__PURE__ */ new Map(), T = new Map(N);
4146
4146
  T.set(w, k), u((A) => {
4147
4147
  const $ = new Map(A);
@@ -4186,7 +4186,7 @@ function $s({
4186
4186
  cart: n,
4187
4187
  cachedProduct: I,
4188
4188
  selections: w,
4189
- onSelectionChange: I && I.productOptions.length > 0 ? (k, N) => v(x.id, k, N) : void 0
4189
+ onSelectionChange: I && I.productOptions.length > 0 ? (k, N) => C(x.id, k, N) : void 0
4190
4190
  }
4191
4191
  ) });
4192
4192
  }
@@ -4201,7 +4201,7 @@ function $s({
4201
4201
  cart: n,
4202
4202
  cachedProduct: w,
4203
4203
  selections: k,
4204
- onSelectionChange: w && w.productOptions.length > 0 ? (N, T) => v(I.id, N, T) : void 0
4204
+ onSelectionChange: w && w.productOptions.length > 0 ? (N, T) => C(I.id, N, T) : void 0
4205
4205
  },
4206
4206
  I.id
4207
4207
  );
@@ -4217,27 +4217,27 @@ function Ms({
4217
4217
  const s = e !== "output-available", { productEntityIds: o, variantEntityIds: c } = ee(() => {
4218
4218
  if (!t?.products?.length)
4219
4219
  return { productEntityIds: [], variantEntityIds: [] };
4220
- const u = [...new Set(t.products.map((v) => v.entityId))], m = t.products.map((v) => v.variantEntityId).filter((v) => v !== void 0);
4220
+ const u = [...new Set(t.products.map((C) => C.entityId))], m = t.products.map((C) => C.variantEntityId).filter((C) => C !== void 0);
4221
4221
  return { productEntityIds: u, variantEntityIds: m };
4222
4222
  }, [t]), { products: l, isLoading: d } = Es(o, c), p = ee(() => {
4223
4223
  if (!t?.products?.length) return [];
4224
4224
  const u = [];
4225
4225
  for (const m of t.products) {
4226
- const v = l.find(
4226
+ const C = l.find(
4227
4227
  (x) => x.entityId === m.entityId
4228
4228
  );
4229
- if (!v) continue;
4230
- const b = v.defaultVariant;
4229
+ if (!C) continue;
4230
+ const b = C.defaultVariant;
4231
4231
  b && u.push({
4232
- id: `${v.entityId}-${b.entityId}`,
4232
+ id: `${C.entityId}-${b.entityId}`,
4233
4233
  sku: b.sku,
4234
- name: v.name,
4235
- path: v.path,
4234
+ name: C.name,
4235
+ path: C.path,
4236
4236
  price: b.price,
4237
- imageUrl: b.defaultImage?.replace("{:size}", "200w") ?? v.defaultImage?.replace("{:size}", "200w"),
4237
+ imageUrl: b.defaultImage?.replace("{:size}", "200w") ?? C.defaultImage?.replace("{:size}", "200w"),
4238
4238
  availableQuantity: b.availableToSell,
4239
4239
  isInStock: b.isInStock,
4240
- productEntityId: v.entityId,
4240
+ productEntityId: C.entityId,
4241
4241
  variantEntityId: b.entityId
4242
4242
  });
4243
4243
  }
@@ -4292,7 +4292,7 @@ function Ir({
4292
4292
  toolOutput: n,
4293
4293
  toolState: i ?? ""
4294
4294
  }
4295
- ) : e === Oe ? /* @__PURE__ */ a(
4295
+ ) : e === Fe ? /* @__PURE__ */ a(
4296
4296
  ae,
4297
4297
  {
4298
4298
  toolCallId: t,
@@ -4465,7 +4465,7 @@ async function Ds(t, e) {
4465
4465
  case "tool-output-available": {
4466
4466
  n.add(u.toolCallId);
4467
4467
  const m = r.find(
4468
- (v) => v.toolCallId === u.toolCallId
4468
+ (C) => C.toolCallId === u.toolCallId
4469
4469
  );
4470
4470
  m && (m.output = u.output, e?.onToolOutput?.(m));
4471
4471
  break;
@@ -4604,15 +4604,21 @@ const Us = {
4604
4604
  setAttribute: () => {
4605
4605
  }
4606
4606
  };
4607
- let Le = null;
4608
- function Vi(t) {
4609
- Le = t;
4607
+ let ke = null;
4608
+ function Hi(t) {
4609
+ ke = t;
4610
4610
  }
4611
4611
  function rt(t) {
4612
- return Le ? Le.startInactiveSpan(t) : Us;
4612
+ return ke ? ke.startInactiveSpan(t) : Us;
4613
4613
  }
4614
4614
  function qs(t, e) {
4615
- Le && Le.captureFeedback(
4615
+ ke && ke.captureException(t, {
4616
+ tags: e?.tags,
4617
+ extra: e?.extra
4618
+ });
4619
+ }
4620
+ function js(t, e) {
4621
+ ke && ke.captureFeedback(
4616
4622
  t,
4617
4623
  e?.tags ? {
4618
4624
  captureContext: {
@@ -4626,7 +4632,7 @@ function $t({
4626
4632
  isOpen: e,
4627
4633
  onClose: r
4628
4634
  }) {
4629
- const [n, i] = R(""), [s, o] = R(""), [c, l] = R(""), [d, p] = R("idle"), [u, m] = R(""), v = D(null), b = g(
4635
+ const [n, i] = R(""), [s, o] = R(""), [c, l] = R(""), [d, p] = R("idle"), [u, m] = R(""), C = D(null), b = g(
4630
4636
  (N) => N.takeshapeConfig
4631
4637
  ), x = g((N) => N.chat.threadId), I = g(
4632
4638
  (N) => N.parser.threadId
@@ -4634,7 +4640,7 @@ function $t({
4634
4640
  (N) => N.batchProcessing.threadIds
4635
4641
  );
4636
4642
  F(() => {
4637
- e && (i(""), o(""), l(""), p("idle"), m(""), v.current?.focus());
4643
+ e && (i(""), o(""), l(""), p("idle"), m(""), C.current?.focus());
4638
4644
  }, [e]), F(() => {
4639
4645
  if (!e) return;
4640
4646
  const N = (T) => {
@@ -4646,7 +4652,7 @@ function $t({
4646
4652
  if (N.preventDefault(), !(!n.trim() || !c.trim())) {
4647
4653
  p("submitting"), m("");
4648
4654
  try {
4649
- qs(
4655
+ js(
4650
4656
  {
4651
4657
  name: n.trim(),
4652
4658
  email: s.trim() || void 0,
@@ -4729,7 +4735,7 @@ function $t({
4729
4735
  /* @__PURE__ */ a(
4730
4736
  "input",
4731
4737
  {
4732
- ref: v,
4738
+ ref: C,
4733
4739
  id: "feedback-name",
4734
4740
  type: "text",
4735
4741
  value: n,
@@ -4798,7 +4804,7 @@ function $t({
4798
4804
  disabled: !n.trim() || !c.trim() || d === "submitting" || d === "success",
4799
4805
  className: "w-full flex items-center justify-center gap-2 px-4 py-2 text-sm font-medium text-text-invert bg-surface-invert rounded-md hover:bg-surface-invert-hover transition-colors disabled:opacity-50 disabled:cursor-not-allowed",
4800
4806
  children: d === "submitting" ? /* @__PURE__ */ h(Ce, { children: [
4801
- /* @__PURE__ */ a(Me, { size: 16 }),
4807
+ /* @__PURE__ */ a(Oe, { size: 16 }),
4802
4808
  "Sending..."
4803
4809
  ] }) : d === "success" ? "Sent!" : "Send Feedback"
4804
4810
  }
@@ -4829,7 +4835,7 @@ const Mt = ({ size: t = 12 }) => /* @__PURE__ */ h(
4829
4835
  ]
4830
4836
  }
4831
4837
  );
4832
- function js({
4838
+ function Ws({
4833
4839
  messagePartId: t,
4834
4840
  messageId: e,
4835
4841
  isLatestAssistantMessage: r,
@@ -4924,7 +4930,7 @@ function js({
4924
4930
  )
4925
4931
  ] });
4926
4932
  }
4927
- function Ws(t) {
4933
+ function Vs(t) {
4928
4934
  if (!t.parts)
4929
4935
  return [];
4930
4936
  const e = [];
@@ -4947,11 +4953,11 @@ function Ws(t) {
4947
4953
  }
4948
4954
  return e;
4949
4955
  }
4950
- function Vs(t) {
4956
+ function zs(t) {
4951
4957
  const e = t?.find((r) => r.type === "file");
4952
4958
  return e && "filename" in e && typeof e.filename == "string" ? e.filename : "Attachment";
4953
4959
  }
4954
- function zs({
4960
+ function Hs({
4955
4961
  message: t,
4956
4962
  isFirstUserMessage: e,
4957
4963
  isLatestAssistantMessage: r,
@@ -4962,7 +4968,7 @@ function zs({
4962
4968
  onAddToCart: c,
4963
4969
  onViewProduct: l
4964
4970
  }) {
4965
- const d = t.role === "assistant", p = Ws(t);
4971
+ const d = t.role === "assistant", p = Vs(t);
4966
4972
  return p.length === 0 ? null : /* @__PURE__ */ a(
4967
4973
  "div",
4968
4974
  {
@@ -5017,7 +5023,7 @@ function zs({
5017
5023
  },
5018
5024
  `group-${t.id}-${m}`
5019
5025
  ) : u.type === "text" ? d ? /* @__PURE__ */ a(
5020
- js,
5026
+ Ws,
5021
5027
  {
5022
5028
  messagePartId: `${t.id}-${m}`,
5023
5029
  messageId: t.id,
@@ -5054,7 +5060,7 @@ function zs({
5054
5060
  ) }, u.toolCallId) : null),
5055
5061
  !d && t.parts?.some((u) => u.type === "file") && /* @__PURE__ */ h("div", { className: "flex items-center gap-1.5 mt-2 text-xs text-text-tertiary", children: [
5056
5062
  /* @__PURE__ */ a(At, {}),
5057
- /* @__PURE__ */ a("span", { children: Vs(t.parts) })
5063
+ /* @__PURE__ */ a("span", { children: zs(t.parts) })
5058
5064
  ] })
5059
5065
  ] }) })
5060
5066
  }
@@ -5092,7 +5098,7 @@ const Er = () => /* @__PURE__ */ h(
5092
5098
  /* @__PURE__ */ a("polyline", { points: "9 15 12 12 15 15" })
5093
5099
  ]
5094
5100
  }
5095
- ), Hs = () => /* @__PURE__ */ h(
5101
+ ), Qs = () => /* @__PURE__ */ h(
5096
5102
  "svg",
5097
5103
  {
5098
5104
  width: "16",
@@ -5118,13 +5124,13 @@ function Nr({ onClick: t }) {
5118
5124
  className: "flex items-center gap-2 min-h-11 py-2.5 px-5 bg-surface border border-border-strong rounded-full text-sm font-medium text-text cursor-pointer transition-colors hover:bg-surface-secondary focus-visible:outline-2 focus-visible:outline-border-focus focus-visible:outline-offset-2",
5119
5125
  onClick: t,
5120
5126
  children: [
5121
- /* @__PURE__ */ a(Hs, {}),
5127
+ /* @__PURE__ */ a(Qs, {}),
5122
5128
  "Take a photo"
5123
5129
  ]
5124
5130
  }
5125
5131
  );
5126
5132
  }
5127
- function Qs({
5133
+ function Gs({
5128
5134
  isDragging: t = !1,
5129
5135
  fileInputRef: e,
5130
5136
  cameraInputRef: r,
@@ -5166,7 +5172,7 @@ function Qs({
5166
5172
  /* @__PURE__ */ a(
5167
5173
  "div",
5168
5174
  {
5169
- className: ke(
5175
+ className: Pe(
5170
5176
  "flex items-center justify-center w-16 h-16 rounded-2xl p-1 border-2 border-dashed border-border-focus text-text transition-transform duration-200",
5171
5177
  t && "animate-icon-bounce"
5172
5178
  ),
@@ -5190,7 +5196,7 @@ function Qs({
5190
5196
  n && /* @__PURE__ */ a("div", { className: "flex items-center gap-2 py-3 px-4 bg-error-bg border border-error/30 rounded-lg text-error-text text-sm max-w-[400px] text-center", children: n })
5191
5197
  ] }) });
5192
5198
  }
5193
- function Gs() {
5199
+ function Ks() {
5194
5200
  return /* @__PURE__ */ a("div", { className: "flex justify-start px-5 py-2", children: /* @__PURE__ */ h("div", { className: "flex flex-col gap-2 w-3/4", children: [
5195
5201
  /* @__PURE__ */ a("div", { className: "h-3 rounded-full animate-shimmer" }),
5196
5202
  /* @__PURE__ */ a(
@@ -5202,7 +5208,7 @@ function Gs() {
5202
5208
  )
5203
5209
  ] }) });
5204
5210
  }
5205
- const Ks = Fr(
5211
+ const Js = Fr(
5206
5212
  function({
5207
5213
  messages: e,
5208
5214
  input: r,
@@ -5216,7 +5222,7 @@ const Ks = Fr(
5216
5222
  error: p = null,
5217
5223
  onRetry: u,
5218
5224
  hasProcessedDocument: m = !1,
5219
- uploadedFileName: v = null,
5225
+ uploadedFileName: C = null,
5220
5226
  fileDrop: b
5221
5227
  }, x) {
5222
5228
  const I = D(null), w = D(!0), [k, N] = R(!1), T = ee(() => {
@@ -5259,7 +5265,7 @@ const Ks = Fr(
5259
5265
  className: "flex-1 min-h-0 overflow-y-auto py-3 flex flex-col",
5260
5266
  children: [
5261
5267
  e.length === 0 && !s && b && /* @__PURE__ */ a(
5262
- Qs,
5268
+ Gs,
5263
5269
  {
5264
5270
  isDragging: b.isDragging,
5265
5271
  fileInputRef: b.fileInputRef,
@@ -5273,14 +5279,14 @@ const Ks = Fr(
5273
5279
  e.map((y, A) => {
5274
5280
  const $ = m && y.role !== "assistant" && A === 0, B = y.role === "assistant" && y.id === T;
5275
5281
  return /* @__PURE__ */ a(
5276
- zs,
5282
+ Hs,
5277
5283
  {
5278
5284
  message: y,
5279
5285
  isFirstUserMessage: $,
5280
5286
  isLatestAssistantMessage: B,
5281
5287
  isDocumentExpanded: k,
5282
5288
  onToggleDocument: () => N(!k),
5283
- uploadedFileName: v,
5289
+ uploadedFileName: C,
5284
5290
  cart: o,
5285
5291
  onAddToCart: c,
5286
5292
  onViewProduct: l
@@ -5288,7 +5294,7 @@ const Ks = Fr(
5288
5294
  y.id
5289
5295
  );
5290
5296
  }),
5291
- s && /* @__PURE__ */ a(Gs, {}),
5297
+ s && /* @__PURE__ */ a(Ks, {}),
5292
5298
  /* @__PURE__ */ a(ps, { error: p, onRetry: u })
5293
5299
  ]
5294
5300
  }
@@ -5304,18 +5310,18 @@ const Ks = Fr(
5304
5310
  )
5305
5311
  ] });
5306
5312
  }
5307
- ), Js = "purchase-order-chat-user-settings", Ys = 25, Ot = at()(
5313
+ ), Ys = "purchase-order-chat-user-settings", Zs = 25, Ot = at()(
5308
5314
  zt(
5309
5315
  (t) => ({
5310
- panelWidth: Ys,
5316
+ panelWidth: Zs,
5311
5317
  setPanelWidth: (e) => t({ panelWidth: e })
5312
5318
  }),
5313
5319
  {
5314
- name: Js
5320
+ name: Ys
5315
5321
  }
5316
5322
  )
5317
5323
  );
5318
- function Zs() {
5324
+ function Xs() {
5319
5325
  const t = Ot((m) => m.panelWidth), e = Ot((m) => m.setPanelWidth), [r, n] = R(
5320
5326
  typeof window < "u" && window.innerWidth >= 1024
5321
5327
  ), i = D(null), s = D(!1), o = D(t);
@@ -5332,7 +5338,7 @@ function Zs() {
5332
5338
  const c = M(
5333
5339
  (m) => {
5334
5340
  if (!s.current || !i.current) return;
5335
- const v = i.current.getBoundingClientRect(), b = (m.clientX - v.left) / v.width * 100, x = Math.min(80, Math.max(20, b));
5341
+ const C = i.current.getBoundingClientRect(), b = (m.clientX - C.left) / C.width * 100, x = Math.min(80, Math.max(20, b));
5336
5342
  o.current = x, e(x);
5337
5343
  },
5338
5344
  [e]
@@ -5369,7 +5375,7 @@ function Zs() {
5369
5375
  handleBlur: u
5370
5376
  };
5371
5377
  }
5372
- function Xs({ activeTab: t, onTabChange: e, hasUnread: r }) {
5378
+ function ea({ activeTab: t, onTabChange: e, hasUnread: r }) {
5373
5379
  const n = r && t !== "chat";
5374
5380
  return /* @__PURE__ */ h("div", { className: "flex border-b border-border-strong shrink-0", role: "tablist", children: [
5375
5381
  /* @__PURE__ */ a(
@@ -5426,7 +5432,7 @@ function Ft({
5426
5432
  // Cart panel props
5427
5433
  cartItems: u,
5428
5434
  itemWarnings: m,
5429
- onUpdateQuantity: v,
5435
+ onUpdateQuantity: C,
5430
5436
  onRemove: b,
5431
5437
  onCheckout: x,
5432
5438
  onSuggestAlternatives: I,
@@ -5453,7 +5459,7 @@ function Ft({
5453
5459
  onMinimize: L,
5454
5460
  className: W = ""
5455
5461
  }) {
5456
- const G = Zs(), [K, Pe] = R(
5462
+ const G = Xs(), [K, Te] = R(
5457
5463
  u.length > 0 ? "cart" : "chat"
5458
5464
  ), [fe, me] = R(!1), de = D(t.length), ge = D(K);
5459
5465
  ge.current = K;
@@ -5467,9 +5473,9 @@ function Ft({
5467
5473
  G.isDesktop && me(!1);
5468
5474
  }, [G.isDesktop]);
5469
5475
  const E = M((_) => {
5470
- Pe(_), _ === "chat" && me(!1);
5476
+ Te(_), _ === "chat" && me(!1);
5471
5477
  }, []), P = /* @__PURE__ */ a(
5472
- Ks,
5478
+ Js,
5473
5479
  {
5474
5480
  ref: d,
5475
5481
  messages: t,
@@ -5491,7 +5497,7 @@ function Ft({
5491
5497
  {
5492
5498
  items: u,
5493
5499
  itemWarnings: m,
5494
- onUpdateQuantity: v,
5500
+ onUpdateQuantity: C,
5495
5501
  onRemove: b,
5496
5502
  onCheckout: x,
5497
5503
  onSuggestAlternatives: I,
@@ -5574,7 +5580,7 @@ function Ft({
5574
5580
  ...U,
5575
5581
  children: [
5576
5582
  /* @__PURE__ */ a(
5577
- Xs,
5583
+ ea,
5578
5584
  {
5579
5585
  activeTab: K,
5580
5586
  onTabChange: E,
@@ -5596,7 +5602,7 @@ function Ft({
5596
5602
  )
5597
5603
  );
5598
5604
  }
5599
- function ea() {
5605
+ function ta() {
5600
5606
  const t = ht(), e = g((c) => c.ui.existingCart), r = g(
5601
5607
  (c) => c.confirmClearExistingCart
5602
5608
  ), [n, i] = R(!1), s = ee(
@@ -5625,14 +5631,14 @@ function ea() {
5625
5631
  disabled: n,
5626
5632
  className: "bg-surface-invert shadow-button transition-all duration-200 ease-in-out hover:bg-surface-invert-hover hover:shadow-button-hover hover:-translate-y-px px-4 py-2 text-text-invert rounded-full font-medium cursor-pointer disabled:opacity-50 disabled:pointer-events-none",
5627
5633
  children: n ? /* @__PURE__ */ h("span", { className: "flex items-center gap-2", children: [
5628
- /* @__PURE__ */ a(Me, { size: 14 }),
5634
+ /* @__PURE__ */ a(Oe, { size: 14 }),
5629
5635
  "Clearing cart…"
5630
5636
  ] }) : "Clear Cart & Continue"
5631
5637
  }
5632
5638
  )
5633
5639
  ] }) });
5634
5640
  }
5635
- function ta({ message: t }) {
5641
+ function ra({ message: t }) {
5636
5642
  return /* @__PURE__ */ a("div", { className: "flex items-center justify-center h-full w-full bg-surface-secondary", children: /* @__PURE__ */ h("div", { className: "text-center max-w-md px-4", children: [
5637
5643
  /* @__PURE__ */ a("p", { className: "text-lg text-text-secondary mb-2", children: "Something went wrong" }),
5638
5644
  /* @__PURE__ */ a("p", { className: "text-sm text-text-tertiary mb-6", children: t || "An unexpected error occurred. Please refresh the page to try again." }),
@@ -5657,19 +5663,19 @@ function kr() {
5657
5663
  );
5658
5664
  return ee(() => t !== "processing" ? null : e ? r === "idle" || r === "processing" ? "matching" : "building" : "reading", [t, e, r]);
5659
5665
  }
5660
- const ra = [
5666
+ const na = [
5661
5667
  { label: "Upload", number: 1 },
5662
5668
  { label: "Match", number: 2 },
5663
5669
  { label: "Checkout", number: 3 }
5664
5670
  ];
5665
- function na(t = {}) {
5666
- return /* @__PURE__ */ a("div", { className: "flex items-center justify-center gap-0 p-4 md:py-1 md:px-0", children: ra.map((e, r) => /* @__PURE__ */ h("div", { className: "flex items-center gap-2", children: [
5671
+ function sa(t = {}) {
5672
+ return /* @__PURE__ */ a("div", { className: "flex items-center justify-center gap-0 p-4 md:py-1 md:px-0", children: na.map((e, r) => /* @__PURE__ */ h("div", { className: "flex items-center gap-2", children: [
5667
5673
  r > 0 && /* @__PURE__ */ a("div", { className: "w-6 md:w-10 h-px mx-2 md:mx-3 rounded-[1px] bg-border" }),
5668
5674
  /* @__PURE__ */ a("div", { className: "flex items-center justify-center w-5 h-5 rounded-full shrink-0 bg-transparent border-[1.5px] border-border-strong text-text-quaternary", children: /* @__PURE__ */ a("span", { className: "text-xs font-medium", children: e.number }) }),
5669
5675
  /* @__PURE__ */ a("span", { className: "text-s font-normal whitespace-nowrap text-text-quaternary", children: e.label })
5670
5676
  ] }, e.label)) });
5671
5677
  }
5672
- function sa({
5678
+ function aa({
5673
5679
  isDragging: t,
5674
5680
  fileInputRef: e,
5675
5681
  cameraInputRef: r,
@@ -5708,7 +5714,7 @@ function sa({
5708
5714
  /* @__PURE__ */ a(
5709
5715
  "div",
5710
5716
  {
5711
- className: ke(
5717
+ className: Pe(
5712
5718
  "flex items-center justify-center w-16 h-16 rounded-2xl p-1 border-2 border-dashed border-border-focus text-text transition-transform duration-200",
5713
5719
  t && "animate-icon-bounce"
5714
5720
  ),
@@ -5729,7 +5735,7 @@ function sa({
5729
5735
  }
5730
5736
  );
5731
5737
  }
5732
- function aa({
5738
+ function ia({
5733
5739
  isDragging: t,
5734
5740
  fileInputRef: e,
5735
5741
  acceptedExtensions: r,
@@ -5744,14 +5750,14 @@ function aa({
5744
5750
  return /* @__PURE__ */ h(
5745
5751
  "div",
5746
5752
  {
5747
- className: ke(
5753
+ className: Pe(
5748
5754
  "flex flex-col items-center gap-6 border-border border-solid bg-surface border rounded-2xl transition-all duration-[250ms] ease-[cubic-bezier(0.34,1.56,0.64,1)] hover:border-border-strong",
5749
5755
  t && "ring-2 ring-border-focus border-border-focus bg-surface-tertiary shadow-upload-active"
5750
5756
  ),
5751
5757
  children: [
5752
- /* @__PURE__ */ a("div", { className: "upload-zone-steps mb-3 py-4 px-8 border-b border-solid border-border-strong", children: /* @__PURE__ */ a(na, {}) }),
5758
+ /* @__PURE__ */ a("div", { className: "upload-zone-steps mb-3 py-4 px-8 border-b border-solid border-border-strong", children: /* @__PURE__ */ a(sa, {}) }),
5753
5759
  /* @__PURE__ */ a(
5754
- sa,
5760
+ aa,
5755
5761
  {
5756
5762
  isDragging: t,
5757
5763
  fileInputRef: e,
@@ -5777,7 +5783,7 @@ function aa({
5777
5783
  }
5778
5784
  );
5779
5785
  }
5780
- function ia({
5786
+ function oa({
5781
5787
  items: t,
5782
5788
  orderId: e,
5783
5789
  parsedContent: r,
@@ -5869,23 +5875,23 @@ function ia({
5869
5875
  ] })
5870
5876
  ] });
5871
5877
  }
5872
- const oa = 3e3, Dt = 200;
5873
- function ca(t) {
5874
- return t <= 0 ? Dt : Math.max(Dt, Math.round(oa / t));
5878
+ const ca = 3e3, Dt = 200;
5879
+ function la(t) {
5880
+ return t <= 0 ? Dt : Math.max(Dt, Math.round(ca / t));
5875
5881
  }
5876
- function la() {
5882
+ function da() {
5877
5883
  const t = g(
5878
5884
  (o) => o.batchProcessing.toolCalls
5879
5885
  ), r = g(
5880
5886
  (o) => o.batchProcessing.status
5881
5887
  ) === "complete", n = t.reduce((o, c) => {
5882
- if (c.toolName !== Oe) return o;
5888
+ if (c.toolName !== Fe) return o;
5883
5889
  const l = c.input;
5884
5890
  return l && typeof l == "object" && "value" in l && Array.isArray(l.value) ? o + l.value.length : o;
5885
5891
  }, 0), [i, s] = R(0);
5886
5892
  return F(() => {
5887
5893
  if (!r || n === 0 || i >= n) return;
5888
- const o = ca(n), c = setTimeout(() => {
5894
+ const o = la(n), c = setTimeout(() => {
5889
5895
  s((l) => Math.min(l + 1, n));
5890
5896
  }, o);
5891
5897
  return () => clearTimeout(c);
@@ -5895,8 +5901,8 @@ function la() {
5895
5901
  isRevealing: n > 0 && i < n
5896
5902
  };
5897
5903
  }
5898
- const da = 1e3;
5899
- function ua() {
5904
+ const ua = 1e3;
5905
+ function pa() {
5900
5906
  const t = g(
5901
5907
  (s) => s.batchProcessing.toolCalls
5902
5908
  ), e = g(
@@ -5907,7 +5913,7 @@ function ua() {
5907
5913
  F(() => {
5908
5914
  if (e >= t.length)
5909
5915
  return;
5910
- const s = setTimeout(r, da);
5916
+ const s = setTimeout(r, ua);
5911
5917
  return () => clearTimeout(s);
5912
5918
  }, [t.length, e, r]);
5913
5919
  const n = t.slice(0, e);
@@ -5918,15 +5924,15 @@ function ua() {
5918
5924
  };
5919
5925
  }
5920
5926
  const Rt = ["reading", "matching", "building"];
5921
- function pa(t, e) {
5927
+ function ha(t, e) {
5922
5928
  if (!e) return "pending";
5923
5929
  const r = Rt.indexOf(e), n = Rt.indexOf(t);
5924
5930
  return n < r ? "complete" : n === r ? "active" : "pending";
5925
5931
  }
5926
- function ha(t, e) {
5932
+ function fa(t, e) {
5927
5933
  return t.length >= 2 && e !== "submitted" && e !== "streaming";
5928
5934
  }
5929
- function fa(t) {
5935
+ function ma(t) {
5930
5936
  if (t == null) return null;
5931
5937
  const e = pt(t, [
5932
5938
  "searchProductsBySku",
@@ -5934,7 +5940,7 @@ function fa(t) {
5934
5940
  ]);
5935
5941
  return e === void 0 ? null : e.total ?? 0;
5936
5942
  }
5937
- const ma = {
5943
+ const ga = {
5938
5944
  searchProductsBySku: (t, { resultCount: e }) => {
5939
5945
  const r = t.sku ?? "";
5940
5946
  return e === null ? `Looking up SKU ${r}` : /* @__PURE__ */ h(Ce, { children: [
@@ -5963,14 +5969,14 @@ const ma = {
5963
5969
  ] });
5964
5970
  }
5965
5971
  };
5966
- function ga(t, e) {
5967
- const r = ma[t.toolName];
5972
+ function ya(t, e) {
5973
+ const r = ga[t.toolName];
5968
5974
  return r ? r(t.input, {
5969
5975
  visibleToolCalls: e,
5970
- resultCount: fa(t.output)
5976
+ resultCount: ma(t.output)
5971
5977
  }) : null;
5972
5978
  }
5973
- const ya = [
5979
+ const xa = [
5974
5980
  { id: "reading", label: "Reading document..." },
5975
5981
  { id: "matching", label: "Matching products..." },
5976
5982
  { id: "building", label: "Building cart..." }
@@ -5988,14 +5994,14 @@ const ya = [
5988
5994
  icon: "bg-surface border-2 border-success text-success"
5989
5995
  }
5990
5996
  };
5991
- function xa({
5997
+ function ba({
5992
5998
  currentStep: t
5993
5999
  }) {
5994
- const { currentToolCall: e, visibleToolCalls: r } = ua(), { revealedCount: n, totalItems: i } = la(), s = g(
6000
+ const { currentToolCall: e, visibleToolCalls: r } = pa(), { revealedCount: n, totalItems: i } = da(), s = g(
5995
6001
  (o) => o.parser.uploadedFileName
5996
6002
  );
5997
- return /* @__PURE__ */ a("div", { className: "flex flex-col gap-6 w-64", children: /* @__PURE__ */ a("div", { className: "flex flex-col gap-6", children: ya.map((o) => {
5998
- const c = pa(o.id, t), l = o.id === "reading" && (c === "active" || c === "complete") && s ? s : null, d = o.id === "matching" && c === "active" && e ? ga(e, r) : null, p = o.id === "building" && c === "active" && i > 0 ? n >= i ? `Added ${i} item${i !== 1 ? "s" : ""}` : `Adding item ${n + 1} of ${i}...` : null;
6003
+ return /* @__PURE__ */ a("div", { className: "flex flex-col gap-6 w-64", children: /* @__PURE__ */ a("div", { className: "flex flex-col gap-6", children: xa.map((o) => {
6004
+ const c = ha(o.id, t), l = o.id === "reading" && (c === "active" || c === "complete") && s ? s : null, d = o.id === "matching" && c === "active" && e ? ya(e, r) : null, p = o.id === "building" && c === "active" && i > 0 ? n >= i ? `Added ${i} item${i !== 1 ? "s" : ""}` : `Adding item ${n + 1} of ${i}...` : null;
5999
6005
  return /* @__PURE__ */ h(
6000
6006
  "div",
6001
6007
  {
@@ -6009,7 +6015,7 @@ function xa({
6009
6015
  className: `flex items-center justify-center w-8 h-8 rounded-full shrink-0 transition-all duration-300 ${_t[c].icon}${c === "complete" ? " animate-step-pulse" : ""}${c === "active" ? " bg-surface-invert shadow-step" : ""}`,
6010
6016
  children: [
6011
6017
  c === "complete" && /* @__PURE__ */ a(Ue, { size: 16, title: "Complete" }),
6012
- c === "active" && /* @__PURE__ */ a(Me, { size: 16 }),
6018
+ c === "active" && /* @__PURE__ */ a(Oe, { size: 16 }),
6013
6019
  c === "pending" && /* @__PURE__ */ a("div", { className: "w-2 h-2 rounded-full bg-border-strong" })
6014
6020
  ]
6015
6021
  }
@@ -6046,7 +6052,7 @@ function xa({
6046
6052
  );
6047
6053
  }) }) });
6048
6054
  }
6049
- function ba({
6055
+ function Ca({
6050
6056
  cartItems: t,
6051
6057
  isUploading: e = !1
6052
6058
  }) {
@@ -6054,9 +6060,9 @@ function ba({
6054
6060
  (s) => s.parser.parsedContent
6055
6061
  );
6056
6062
  return /* @__PURE__ */ a("div", { className: "animate-fade-in-scale flex flex-col w-full max-w-[900px] gap-10 bg-surface rounded-2xl p-10 max-md:p-6 border border-border-strong border-solid", children: /* @__PURE__ */ h("div", { className: "flex w-full justify-center gap-32 max-md:flex-col max-md:gap-8", children: [
6057
- /* @__PURE__ */ a("div", { className: "shrink-0 flex items-center justify-center", children: /* @__PURE__ */ a(xa, { currentStep: r }) }),
6063
+ /* @__PURE__ */ a("div", { className: "shrink-0 flex items-center justify-center", children: /* @__PURE__ */ a(ba, { currentStep: r }) }),
6058
6064
  /* @__PURE__ */ a("div", { className: "shrink-0 flex items-center justify-center min-w-80", children: /* @__PURE__ */ a(
6059
- ia,
6065
+ oa,
6060
6066
  {
6061
6067
  items: t,
6062
6068
  orderId: n,
@@ -6067,7 +6073,7 @@ function ba({
6067
6073
  ) })
6068
6074
  ] }) });
6069
6075
  }
6070
- function Ca({
6076
+ function va({
6071
6077
  onFileUpload: t,
6072
6078
  onSkip: e,
6073
6079
  onClearError: r,
@@ -6086,8 +6092,8 @@ function Ca({
6086
6092
  {
6087
6093
  className: `upload-step flex flex-col w-full flex-1 min-h-0 ${l.isDragging ? "upload-step-dragging" : ""} ${c ? "upload-step-processing" : ""}`,
6088
6094
  ...l.dragProps,
6089
- children: /* @__PURE__ */ a("div", { className: "upload-step-content animate-fade-in-up flex-1 flex items-center justify-center min-h-0 relative", children: c ? /* @__PURE__ */ a(ba, { cartItems: n, isUploading: i }) : /* @__PURE__ */ a(
6090
- aa,
6095
+ children: /* @__PURE__ */ a("div", { className: "upload-step-content animate-fade-in-up flex-1 flex items-center justify-center min-h-0 relative", children: c ? /* @__PURE__ */ a(Ca, { cartItems: n, isUploading: i }) : /* @__PURE__ */ a(
6096
+ ia,
6091
6097
  {
6092
6098
  isDragging: l.isDragging,
6093
6099
  fileInputRef: l.fileInputRef,
@@ -6123,7 +6129,7 @@ function Lt(t, e) {
6123
6129
  function Pr(t, e) {
6124
6130
  return t !== void 0 && Math.abs(t - e) > 0.01;
6125
6131
  }
6126
- function va(t, e) {
6132
+ function Ia(t, e) {
6127
6133
  const r = [...t];
6128
6134
  for (const n of e) {
6129
6135
  const i = r.findIndex(
@@ -6133,7 +6139,7 @@ function va(t, e) {
6133
6139
  }
6134
6140
  return r;
6135
6141
  }
6136
- function Ia(t, e) {
6142
+ function wa(t, e) {
6137
6143
  const r = [], n = [];
6138
6144
  for (const i of e) {
6139
6145
  const s = t.find(
@@ -6148,7 +6154,7 @@ function Ia(t, e) {
6148
6154
  }
6149
6155
  return { toAdd: r, toUpdate: n };
6150
6156
  }
6151
- function wa(t, e) {
6157
+ function Sa(t, e) {
6152
6158
  const r = [];
6153
6159
  for (const n of t.lineItems.physicalItems) {
6154
6160
  const i = e.find(
@@ -6177,14 +6183,14 @@ function Ke(t) {
6177
6183
  function Je(t) {
6178
6184
  return t.toLowerCase();
6179
6185
  }
6180
- function Sa(t, e) {
6186
+ function Ea(t, e) {
6181
6187
  return t.filter(
6182
6188
  (r) => !e.some(
6183
6189
  (n) => r.productSku && n.sku && Ke(r.productSku) === Ke(n.sku) || r.productName && n.name && Je(r.productName) === Je(n.name)
6184
6190
  )
6185
6191
  );
6186
6192
  }
6187
- function Ea(t) {
6193
+ function Na(t) {
6188
6194
  const { client: e, onError: r } = t, n = D(e), i = D(r);
6189
6195
  i.current = r;
6190
6196
  const s = g((f) => f.bcSession.bcCart), o = g((f) => f.bcSession.checkout), c = g(
@@ -6197,7 +6203,7 @@ function Ea(t) {
6197
6203
  (f) => f.ui.addressUpdateStatus
6198
6204
  ), u = g((f) => f.bcSession.isLoading), m = g(
6199
6205
  (f) => f.bcSession.productCache
6200
- ), v = g(
6206
+ ), C = g(
6201
6207
  (f) => f.cartifact.poItemPrices
6202
6208
  ), b = g((f) => f.setBcCart), x = g((f) => f.setCheckout), I = g(
6203
6209
  (f) => f.setSelectedAddressId
@@ -6218,7 +6224,7 @@ function Ea(t) {
6218
6224
  ), te = g(
6219
6225
  (f) => f.setItemWarnings
6220
6226
  ), j = ee(() => s ? s.lineItems.physicalItems.map((f) => {
6221
- const S = `${f.productEntityId}-${f.variantEntityId}`, E = v[S];
6227
+ const S = `${f.productEntityId}-${f.variantEntityId}`, E = C[S];
6222
6228
  return {
6223
6229
  productEntityId: f.productEntityId,
6224
6230
  variantEntityId: f.variantEntityId ?? void 0,
@@ -6226,7 +6232,7 @@ function Ea(t) {
6226
6232
  poPriceValue: E?.poPrice,
6227
6233
  poPriceCurrencyCode: E?.poCurrency
6228
6234
  };
6229
- }) : [], [s, v]), Y = D(/* @__PURE__ */ new Set()), re = M(
6235
+ }) : [], [s, C]), Y = D(/* @__PURE__ */ new Set()), re = M(
6230
6236
  async (f, S) => {
6231
6237
  if (!n.current)
6232
6238
  return;
@@ -6431,11 +6437,11 @@ function Ea(t) {
6431
6437
  return { cart: s, cartItems: [], errors: [] };
6432
6438
  k(!0);
6433
6439
  try {
6434
- const S = va(j, f), E = await n.current.getCart();
6440
+ const S = Ia(j, f), E = await n.current.getCart();
6435
6441
  let P = null;
6436
6442
  const O = [];
6437
6443
  if (E) {
6438
- const { toAdd: H, toUpdate: ce } = Ia(
6444
+ const { toAdd: H, toUpdate: ce } = wa(
6439
6445
  E.lineItems.physicalItems,
6440
6446
  f
6441
6447
  );
@@ -6508,14 +6514,14 @@ function Ea(t) {
6508
6514
  }
6509
6515
  if (!P)
6510
6516
  return { cart: null, cartItems: [], errors: O };
6511
- const { cartItems: _ } = wa(
6517
+ const { cartItems: _ } = Sa(
6512
6518
  P,
6513
6519
  S
6514
- ), qe = g.getState().cartifact.itemWarnings, Fe = Sa(
6520
+ ), qe = g.getState().cartifact.itemWarnings, De = Ea(
6515
6521
  qe,
6516
6522
  _
6517
6523
  );
6518
- return Fe.length !== qe.length && te(Fe), { cart: P, cartItems: _, errors: O };
6524
+ return De.length !== qe.length && te(De), { cart: P, cartItems: _, errors: O };
6519
6525
  } finally {
6520
6526
  k(!1);
6521
6527
  }
@@ -6588,7 +6594,7 @@ function Ea(t) {
6588
6594
  b,
6589
6595
  k
6590
6596
  ]
6591
- ), Pe = M(
6597
+ ), Te = M(
6592
6598
  async (f) => {
6593
6599
  if (!n.current || !s?.entityId)
6594
6600
  return null;
@@ -6790,7 +6796,7 @@ function Ea(t) {
6790
6796
  cartItems: oe,
6791
6797
  addToCart: G,
6792
6798
  updateLineItemQuantity: K,
6793
- removeLineItem: Pe,
6799
+ removeLineItem: Te,
6794
6800
  initiateCheckout: fe,
6795
6801
  setShippingAddressOnCheckout: me,
6796
6802
  setBillingAddressOnCheckout: de,
@@ -6799,7 +6805,7 @@ function Ea(t) {
6799
6805
  setSelectedBillingAddressId: B
6800
6806
  };
6801
6807
  }
6802
- function Na({
6808
+ function ka({
6803
6809
  bcCart: t,
6804
6810
  cartItems: e,
6805
6811
  onCheckoutInitiated: r,
@@ -6819,12 +6825,12 @@ function Na({
6819
6825
  }
6820
6826
  }, [t, r, n]), o = M(
6821
6827
  async (u, m) => {
6822
- const v = e.find((b) => b.id === u);
6823
- !v?.productEntityId || !v?.variantEntityId || await t.updateLineItemQuantity(
6828
+ const C = e.find((b) => b.id === u);
6829
+ !C?.productEntityId || !C?.variantEntityId || await t.updateLineItemQuantity(
6824
6830
  u,
6825
6831
  m,
6826
- v.productEntityId,
6827
- v.variantEntityId
6832
+ C.productEntityId,
6833
+ C.variantEntityId
6828
6834
  );
6829
6835
  },
6830
6836
  [e, t]
@@ -6834,8 +6840,8 @@ function Na({
6834
6840
  },
6835
6841
  [t]
6836
6842
  ), l = M(
6837
- async (u, m, v) => {
6838
- const { productEntityId: b } = u, x = v ?? u.variantEntityId;
6843
+ async (u, m, C) => {
6844
+ const { productEntityId: b } = u, x = C ?? u.variantEntityId;
6839
6845
  if (!b || !x)
6840
6846
  return console.error("Cannot add to cart: missing entity IDs", u), !1;
6841
6847
  const I = u.availableQuantity !== void 0 && u.availableQuantity > 0 ? Math.min(m, u.availableQuantity) : m;
@@ -6854,14 +6860,14 @@ function Na({
6854
6860
  [t]
6855
6861
  ), d = M(
6856
6862
  (u, m) => {
6857
- const v = m ? `Suggest alternatives for "${u}" (SKU: ${m})` : `Suggest alternatives for "${u}"`;
6858
- i(v);
6863
+ const C = m ? `Suggest alternatives for "${u}" (SKU: ${m})` : `Suggest alternatives for "${u}"`;
6864
+ i(C);
6859
6865
  },
6860
6866
  [i]
6861
6867
  ), p = M(
6862
6868
  (u, m) => {
6863
- const v = m ? `Show more products like "${u}" (SKU: ${m})` : `Show more products like "${u}"`;
6864
- i(v);
6869
+ const C = m ? `Show more products like "${u}" (SKU: ${m})` : `Show more products like "${u}"`;
6870
+ i(C);
6865
6871
  },
6866
6872
  [i]
6867
6873
  );
@@ -6875,18 +6881,18 @@ function Na({
6875
6881
  };
6876
6882
  }
6877
6883
  const nt = /* @__PURE__ */ new Set([
6878
- Oe,
6884
+ Fe,
6879
6885
  dt,
6880
6886
  Ye,
6881
6887
  ut
6882
- ]), ka = "did not produce any output";
6883
- function Pa(t) {
6888
+ ]), Pa = "did not produce any output";
6889
+ function Ta(t) {
6884
6890
  const e = t.filter((n) => nt.has(n.toolName)).map((n) => n.toolName);
6885
6891
  return e.length === 0 ? "" : `
6886
6892
 
6887
6893
  Tools called: ${[...new Set(e)].join(", ")}`;
6888
6894
  }
6889
- async function Ta(t, e, r, n, i, s) {
6895
+ async function Aa(t, e, r, n, i, s) {
6890
6896
  const o = [], c = [], l = [], d = [];
6891
6897
  let p = [
6892
6898
  {
@@ -6907,7 +6913,7 @@ async function Ta(t, e, r, n, i, s) {
6907
6913
  onToolCall: s?.onToolCall,
6908
6914
  onToolOutput: s?.onToolOutput
6909
6915
  });
6910
- if (c.push(...y.textParts), o.push(...y.toolCalls), y.finalMessage && l.push(y.finalMessage), y.errorMessage?.includes(ka)) {
6916
+ if (c.push(...y.textParts), o.push(...y.toolCalls), y.finalMessage && l.push(y.finalMessage), y.errorMessage?.includes(Pa)) {
6911
6917
  s?.logger?.debug(
6912
6918
  `Batch ${i}: Exiting loop - no output error`
6913
6919
  );
@@ -6973,10 +6979,10 @@ async function Ta(t, e, r, n, i, s) {
6973
6979
  m >= u && s?.logger?.debug(
6974
6980
  `Batch ${i}: WARNING - Hit max iterations limit (${u})`
6975
6981
  );
6976
- const v = l.length > 0 ? l.join(`
6982
+ const C = l.length > 0 ? l.join(`
6977
6983
 
6978
- `) : c.join(""), b = Pa(o), x = v + b, w = d.filter(
6979
- (T) => T.toolName === Oe
6984
+ `) : c.join(""), b = Ta(o), x = C + b, w = d.filter(
6985
+ (T) => T.toolName === Fe
6980
6986
  ).reduce((T, y) => {
6981
6987
  const A = y.input?.value;
6982
6988
  return T + (A?.length ?? 0);
@@ -6996,7 +7002,7 @@ async function Ta(t, e, r, n, i, s) {
6996
7002
  pendingClientToolCalls: d
6997
7003
  };
6998
7004
  }
6999
- async function Aa(t, e, r, n) {
7005
+ async function Ba(t, e, r, n) {
7000
7006
  if (r.length === 0)
7001
7007
  return { results: [], hasErrors: !1 };
7002
7008
  const s = (await Promise.allSettled(
@@ -7023,7 +7029,7 @@ async function Aa(t, e, r, n) {
7023
7029
  error: "Failed to create thread"
7024
7030
  };
7025
7031
  try {
7026
- const u = await Ta(
7032
+ const u = await Aa(
7027
7033
  t,
7028
7034
  e,
7029
7035
  p,
@@ -7048,28 +7054,38 @@ async function Aa(t, e, r, n) {
7048
7054
  ), c = o.some((l) => l.error !== void 0);
7049
7055
  return { results: o, hasErrors: c };
7050
7056
  }
7051
- function Ba(t) {
7057
+ function $a(t) {
7052
7058
  const e = [];
7053
7059
  let r = null;
7054
- const n = [];
7055
- for (const i of t) {
7056
- if (i.error)
7060
+ const n = [], i = [];
7061
+ for (const s of t) {
7062
+ if (s.error) {
7063
+ i.push({
7064
+ batchIndex: s.batchIndex,
7065
+ error: s.error
7066
+ });
7057
7067
  continue;
7058
- let s = 0, o = 0;
7059
- for (const c of i.pendingClientToolCalls)
7060
- if (c.toolName === Oe) {
7061
- const l = c.input;
7062
- l.value && (s += l.value.length, e.push(...l.value));
7063
- } else if (c.toolName === Ye)
7064
- r = c.input;
7065
- else if (c.toolName === ut) {
7066
- const l = c.input;
7067
- l.processingFailures && (o += l.processingFailures.length, n.push(...l.processingFailures));
7068
+ }
7069
+ let o = 0, c = 0;
7070
+ for (const l of s.pendingClientToolCalls)
7071
+ if (l.toolName === Fe) {
7072
+ const d = l.input;
7073
+ d.value && (o += d.value.length, e.push(...d.value));
7074
+ } else if (l.toolName === Ye)
7075
+ r = l.input;
7076
+ else if (l.toolName === ut) {
7077
+ const d = l.input;
7078
+ d.processingFailures && (c += d.processingFailures.length, n.push(...d.processingFailures));
7068
7079
  }
7069
7080
  }
7070
- return { addToCartItems: e, setPoMetadataArgs: r, processingFailures: n };
7081
+ return {
7082
+ addToCartItems: e,
7083
+ setPoMetadataArgs: r,
7084
+ processingFailures: n,
7085
+ batchFailures: i
7086
+ };
7071
7087
  }
7072
- function $a(t) {
7088
+ function Ma(t) {
7073
7089
  if (t.length === 0)
7074
7090
  return "";
7075
7091
  const e = [
@@ -7085,7 +7101,23 @@ function $a(t) {
7085
7101
  return e.join(`
7086
7102
  `);
7087
7103
  }
7088
- function Ma(t) {
7104
+ function Oa(t) {
7105
+ if (t.length === 0)
7106
+ return "";
7107
+ const e = [
7108
+ "",
7109
+ "---",
7110
+ "## Batch Processing Failures",
7111
+ "",
7112
+ `${t.length} batch${t.length > 1 ? "es" : ""} could not be processed. Items from these batches were not added to the cart:`,
7113
+ ""
7114
+ ];
7115
+ for (const r of t)
7116
+ e.push(`- Batch ${r.batchIndex + 1}: ${r.error}`);
7117
+ return e.push(""), e.join(`
7118
+ `);
7119
+ }
7120
+ function Fa(t) {
7089
7121
  if (t.length === 0) return "";
7090
7122
  const e = ["---", "## Failed Tool Calls", ""];
7091
7123
  for (const r of t) {
@@ -7101,8 +7133,8 @@ function Ma(t) {
7101
7133
  return e.join(`
7102
7134
  `);
7103
7135
  }
7104
- async function Oa(t, e) {
7105
- const r = Ba(t);
7136
+ async function Da(t, e) {
7137
+ const r = $a(t);
7106
7138
  if (r.setPoMetadataArgs) {
7107
7139
  const s = r.setPoMetadataArgs;
7108
7140
  g.getState().applyPoMetadata(s.poMetadata);
@@ -7112,20 +7144,17 @@ async function Oa(t, e) {
7112
7144
  const { errors: s } = await e.addToCart(r.addToCartItems);
7113
7145
  n = s, s.length > 0 && console.error("Failed to add some items to cart:", s);
7114
7146
  }
7115
- const i = $a(
7116
- r.processingFailures
7117
- );
7118
- if (n.length > 0) {
7119
- const s = Ma(n);
7120
- return i ? `${i}
7121
- ${s}` : s;
7122
- }
7123
- return i;
7147
+ return [
7148
+ Oa(r.batchFailures),
7149
+ Ma(r.processingFailures),
7150
+ n.length > 0 ? Fa(n) : ""
7151
+ ].filter(Boolean).join(`
7152
+ `);
7124
7153
  }
7125
- async function Fa(t, e) {
7154
+ async function Ra(t, e) {
7126
7155
  if (e.length === 0)
7127
7156
  return { results: [], processingFailuresString: "", hasErrors: !1 };
7128
- const r = await Aa(
7157
+ const r = await Ba(
7129
7158
  t.takeshapeConfig,
7130
7159
  t.agentName,
7131
7160
  e,
@@ -7135,11 +7164,20 @@ async function Fa(t, e) {
7135
7164
  },
7136
7165
  onThreadCreated: (i, s) => {
7137
7166
  g.getState().addBatchThreadId(s);
7167
+ },
7168
+ onError: (i, s) => {
7169
+ qs(
7170
+ new Error(`Batch ${i} failed: ${s}`),
7171
+ {
7172
+ tags: { component: "batch-processor" },
7173
+ extra: { batchIndex: i, errorMessage: s }
7174
+ }
7175
+ );
7138
7176
  }
7139
7177
  }
7140
7178
  );
7141
7179
  let n = "";
7142
- return t.bcCart && (n = await Oa(
7180
+ return t.bcCart && (n = await Da(
7143
7181
  r.results,
7144
7182
  t.bcCart
7145
7183
  )), {
@@ -7148,7 +7186,7 @@ async function Fa(t, e) {
7148
7186
  hasErrors: r.hasErrors
7149
7187
  };
7150
7188
  }
7151
- function Da(t) {
7189
+ function _a(t) {
7152
7190
  const { bcCart: e } = t, r = g(
7153
7191
  (d) => d.takeshapeConfig
7154
7192
  ), n = g(
@@ -7172,19 +7210,28 @@ function Da(t) {
7172
7210
  bcCart: e
7173
7211
  };
7174
7212
  try {
7175
- const u = await Fa(p, d);
7213
+ const u = await Ra(p, d);
7176
7214
  if (s(
7177
7215
  u.results,
7178
7216
  u.processingFailuresString
7179
7217
  ), u.hasErrors) {
7180
7218
  n("error");
7181
- const m = u.results.filter((v) => v.error).length;
7219
+ const m = u.results.filter((C) => C.error).length;
7182
7220
  i(
7183
7221
  `${m} of ${d.length} batches failed to process`
7184
7222
  );
7185
7223
  } else
7186
7224
  n("complete");
7187
- return u.processingFailuresString ? c(u.processingFailuresString) : c("No failures detected."), u;
7225
+ if (u.processingFailuresString)
7226
+ c(u.processingFailuresString);
7227
+ else if (u.hasErrors) {
7228
+ const m = u.results.filter((C) => C.error).length;
7229
+ c(
7230
+ `${m} of ${d.length} batches failed to process. No items were added to the cart.`
7231
+ );
7232
+ } else
7233
+ c("No failures detected.");
7234
+ return u;
7188
7235
  } catch (u) {
7189
7236
  const m = u instanceof Error ? u.message : "Unknown error";
7190
7237
  throw i(m), n("error"), u;
@@ -7202,7 +7249,7 @@ function Da(t) {
7202
7249
  reset: o
7203
7250
  };
7204
7251
  }
7205
- function Ra({
7252
+ function La({
7206
7253
  appState: t,
7207
7254
  setAppState: e,
7208
7255
  parser: r,
@@ -7214,7 +7261,7 @@ function Ra({
7214
7261
  (u) => u.parser.hasProcessedDocument
7215
7262
  ), l = g(
7216
7263
  (u) => u.setHasProcessedDocument
7217
- ), { processBatches: d } = Da({ bcCart: s });
7264
+ ), { processBatches: d } = _a({ bcCart: s });
7218
7265
  return F(() => {
7219
7266
  t === "processing" && r.parserStatus !== "streaming" && r.parserStatus !== "submitted" && r.parsedContent && r.parserMessages.length > 0 && !o.current && (o.current = !0, l(!0), d(r.parsedContent));
7220
7267
  }, [
@@ -7240,30 +7287,30 @@ function Ra({
7240
7287
  }
7241
7288
  };
7242
7289
  }
7243
- const _a = "<!-- BATCH -->";
7244
- function La(t) {
7245
- return t.split(_a).map((e) => e.trim()).filter(Boolean);
7290
+ const Ua = "<!-- BATCH -->";
7291
+ function qa(t) {
7292
+ return t.split(Ua).map((e) => e.trim()).filter(Boolean);
7246
7293
  }
7247
- function Ua(t) {
7294
+ function ja(t) {
7248
7295
  return new Promise((e, r) => {
7249
7296
  const n = new FileReader();
7250
7297
  n.onload = () => e(n.result), n.onerror = () => r(new Error("Failed to read file")), n.readAsText(t);
7251
7298
  });
7252
7299
  }
7253
- function qa(t) {
7300
+ function Wa(t) {
7254
7301
  return new Promise((e, r) => {
7255
7302
  const n = new FileReader();
7256
7303
  n.onload = () => e(n.result), n.onerror = () => r(new Error("Failed to read file")), n.readAsDataURL(t);
7257
7304
  });
7258
7305
  }
7259
- const ja = /* @__PURE__ */ new Set([
7306
+ const Va = /* @__PURE__ */ new Set([
7260
7307
  "application/vnd.ms-excel",
7261
7308
  "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
7262
7309
  ]);
7263
7310
  function Ut(t) {
7264
- return ja.has(t);
7311
+ return Va.has(t);
7265
7312
  }
7266
- async function Wa(t) {
7313
+ async function za(t) {
7267
7314
  const e = await import("xlsx"), r = await t.arrayBuffer(), n = e.read(r, { type: "array" });
7268
7315
  if (n.SheetNames.length === 0)
7269
7316
  throw new Error("Workbook contains no sheets");
@@ -7275,27 +7322,27 @@ async function Wa(t) {
7275
7322
  const s = e.utils.json_to_sheet(i);
7276
7323
  return e.utils.sheet_to_csv(s);
7277
7324
  }
7278
- const Va = "%PDF-", za = "%%EOF", Ha = 256;
7279
- function Qa(t) {
7325
+ const Ha = "%PDF-", Qa = "%%EOF", Ga = 256;
7326
+ function Ka(t) {
7280
7327
  return new Promise((e, r) => {
7281
7328
  const n = new FileReader();
7282
7329
  n.onload = () => e(n.result), n.onerror = () => r(n.error), n.readAsArrayBuffer(t);
7283
7330
  });
7284
7331
  }
7285
- async function Ga(t) {
7286
- if (t.size < Ha) return { valid: !1, reason: "invalid" };
7332
+ async function Ja(t) {
7333
+ if (t.size < Ga) return { valid: !1, reason: "invalid" };
7287
7334
  let e;
7288
7335
  try {
7289
- e = new Uint8Array(await Qa(t));
7336
+ e = new Uint8Array(await Ka(t));
7290
7337
  } catch {
7291
7338
  return { valid: !1, reason: "invalid" };
7292
7339
  }
7293
- if (!String.fromCharCode(...e.slice(0, 5)).startsWith(Va))
7340
+ if (!String.fromCharCode(...e.slice(0, 5)).startsWith(Ha))
7294
7341
  return { valid: !1, reason: "invalid" };
7295
7342
  const n = Math.min(1024, e.length);
7296
7343
  if (!String.fromCharCode(
7297
7344
  ...e.slice(e.length - n)
7298
- ).includes(za))
7345
+ ).includes(Qa))
7299
7346
  return { valid: !1, reason: "invalid" };
7300
7347
  const s = Math.max(0, e.length - 8192), o = new TextDecoder().decode(e.slice(s)), c = o.lastIndexOf("<<"), l = o.lastIndexOf(">>");
7301
7348
  if (c !== -1 && l !== -1 && c < l && o.substring(c, l).includes("/Encrypt"))
@@ -7319,7 +7366,7 @@ async function Ga(t) {
7319
7366
  }
7320
7367
  return { valid: !0 };
7321
7368
  }
7322
- const Ka = /* @__PURE__ */ new Set([
7369
+ const Ya = /* @__PURE__ */ new Set([
7323
7370
  "text/csv",
7324
7371
  "text/plain",
7325
7372
  "application/json"
@@ -7334,7 +7381,7 @@ ${e}`
7334
7381
  }
7335
7382
  ];
7336
7383
  }
7337
- function Ja(t, e, r) {
7384
+ function Za(t, e, r) {
7338
7385
  return [
7339
7386
  { type: "text", text: Tr },
7340
7387
  {
@@ -7345,7 +7392,7 @@ function Ja(t, e, r) {
7345
7392
  }
7346
7393
  ];
7347
7394
  }
7348
- function Ya({
7395
+ function Xa({
7349
7396
  createParserThread: t,
7350
7397
  sendParserMessage: e
7351
7398
  }) {
@@ -7353,7 +7400,7 @@ function Ya({
7353
7400
  async (c) => {
7354
7401
  const l = g.getState();
7355
7402
  if (l.setParsedContent(null), n(!0), l.setUploadedFileName(c.name), s(null), c.type === "application/pdf") {
7356
- const d = await Ga(c);
7403
+ const d = await Ja(c);
7357
7404
  if (!d.valid)
7358
7405
  return s(
7359
7406
  d.reason === "password-protected" ? "The PDF appears to be password protected." : "The file does not appear to be a valid PDF."
@@ -7362,15 +7409,15 @@ function Ya({
7362
7409
  await t();
7363
7410
  try {
7364
7411
  if (Ut(c.type)) {
7365
- const d = await Wa(c);
7412
+ const d = await za(c);
7366
7413
  e({ parts: qt(c.name, d) });
7367
- } else if (Ka.has(c.type)) {
7368
- const d = await Ua(c);
7414
+ } else if (Ya.has(c.type)) {
7415
+ const d = await ja(c);
7369
7416
  e({ parts: qt(c.name, d) });
7370
7417
  } else {
7371
- const d = await qa(c);
7418
+ const d = await Wa(c);
7372
7419
  e({
7373
- parts: Ja(d, c.type, c.name)
7420
+ parts: Za(d, c.type, c.name)
7374
7421
  });
7375
7422
  }
7376
7423
  } catch (d) {
@@ -7397,14 +7444,14 @@ function Ar(t) {
7397
7444
  persist: i = !0,
7398
7445
  onThreadCreated: s
7399
7446
  } = t, { projectId: o, apiKey: c, origin: l } = g(
7400
- (v) => v.takeshapeConfig
7447
+ (C) => C.takeshapeConfig
7401
7448
  ), [d, p] = R(!1), u = D(
7402
7449
  n ? { id: n } : null
7403
7450
  ), m = M(async () => {
7404
7451
  p(!0);
7405
- const v = 2;
7452
+ const C = 2;
7406
7453
  let b = 0;
7407
- for (; b <= v; )
7454
+ for (; b <= C; )
7408
7455
  try {
7409
7456
  const x = await wr(
7410
7457
  { origin: l, projectId: o, apiKey: c },
@@ -7413,16 +7460,16 @@ function Ar(t) {
7413
7460
  p(!1), u.current = { id: x }, i && g.getState().setThreadId(x), s?.(x);
7414
7461
  return;
7415
7462
  } catch (x) {
7416
- if (b === v) {
7463
+ if (b === C) {
7417
7464
  p(!1), console.error(
7418
- `Failed to create thread after ${v + 1} attempts:`,
7465
+ `Failed to create thread after ${C + 1} attempts:`,
7419
7466
  x
7420
7467
  );
7421
7468
  return;
7422
7469
  }
7423
7470
  const w = 500 * 2 ** b;
7424
7471
  console.warn(
7425
- `Thread creation failed (attempt ${b + 1}/${v + 1}), retrying in ${w}ms...`,
7472
+ `Thread creation failed (attempt ${b + 1}/${C + 1}), retrying in ${w}ms...`,
7426
7473
  x
7427
7474
  ), await new Promise((k) => setTimeout(k, w)), b++;
7428
7475
  }
@@ -7435,7 +7482,7 @@ function Ar(t) {
7435
7482
  createThread: m
7436
7483
  };
7437
7484
  }
7438
- function Za() {
7485
+ function ei() {
7439
7486
  const { sseOrigin: t, projectId: e, apiKey: r } = g(
7440
7487
  (y) => y.takeshapeConfig
7441
7488
  ), n = g(
@@ -7488,12 +7535,12 @@ function Za() {
7488
7535
  ), l.current?.setStatus({ code: 2, message: "internal_error" }), l.current?.end(), l.current = null, b(!1);
7489
7536
  }
7490
7537
  }), {
7491
- isUploadingFile: v,
7538
+ isUploadingFile: C,
7492
7539
  setIsUploadingFile: b,
7493
7540
  parserError: x,
7494
7541
  setParserError: I,
7495
7542
  handleFileUpload: w
7496
- } = Ya({
7543
+ } = Xa({
7497
7544
  createParserThread: s,
7498
7545
  sendParserMessage: p
7499
7546
  }), k = M(
@@ -7512,7 +7559,7 @@ function Za() {
7512
7559
  if (d.length > 0) {
7513
7560
  const y = d[d.length - 1];
7514
7561
  if (y?.role === "assistant" && Array.isArray(y.parts)) {
7515
- const A = y.parts.filter((B) => B.type === "text").map((B) => B.text).filter(Boolean), $ = La(A.join(""));
7562
+ const A = y.parts.filter((B) => B.type === "text").map((B) => B.text).filter(Boolean), $ = qa(A.join(""));
7516
7563
  g.getState().setParsedContent($), $ && b(!1);
7517
7564
  }
7518
7565
  }
@@ -7528,7 +7575,7 @@ function Za() {
7528
7575
  }, [m, b, I]);
7529
7576
  return {
7530
7577
  parsedContent: o,
7531
- isUploadingFile: v,
7578
+ isUploadingFile: C,
7532
7579
  uploadedFileName: c,
7533
7580
  parserError: x,
7534
7581
  parserStatus: u,
@@ -7538,7 +7585,7 @@ function Za() {
7538
7585
  reset: T
7539
7586
  };
7540
7587
  }
7541
- class Xa {
7588
+ class ti {
7542
7589
  b2bToken = null;
7543
7590
  companyId = null;
7544
7591
  channelId;
@@ -7684,12 +7731,12 @@ class Xa {
7684
7731
  }
7685
7732
  }
7686
7733
  }
7687
- function ei(t) {
7734
+ function ri(t) {
7688
7735
  return console.debug(
7689
7736
  `[createB2BClient] Initializing B2B client for channelId=${t.channelId}`
7690
- ), new Xa(t);
7737
+ ), new ti(t);
7691
7738
  }
7692
- async function zi(t) {
7739
+ async function Qi(t) {
7693
7740
  let e = null;
7694
7741
  try {
7695
7742
  const r = await Ne(
@@ -7738,7 +7785,7 @@ async function zi(t) {
7738
7785
  return null;
7739
7786
  }
7740
7787
  }
7741
- async function ti(t, e) {
7788
+ async function ni(t, e) {
7742
7789
  const { setToolCallError: r } = g.getState(), n = t.input;
7743
7790
  let i = "No items provided to add to cart.";
7744
7791
  if (n.value && n.value.length > 0) {
@@ -7750,12 +7797,12 @@ async function ti(t, e) {
7750
7797
  i = `Successfully added ${n.value.length} item(s) to cart.`;
7751
7798
  }
7752
7799
  return {
7753
- tool: Oe,
7800
+ tool: Fe,
7754
7801
  toolCallId: t.toolCallId,
7755
7802
  output: i
7756
7803
  };
7757
7804
  }
7758
- async function ri(t, e) {
7805
+ async function si(t, e) {
7759
7806
  const { setToolCallError: r } = g.getState();
7760
7807
  let n = "Cart cleared successfully.";
7761
7808
  try {
@@ -7770,7 +7817,7 @@ async function ri(t, e) {
7770
7817
  output: n
7771
7818
  };
7772
7819
  }
7773
- function ni(t, e) {
7820
+ function ai(t, e) {
7774
7821
  const r = {
7775
7822
  items: e.cartItems.map((n) => ({
7776
7823
  productEntityId: n.productEntityId,
@@ -7790,7 +7837,7 @@ function ni(t, e) {
7790
7837
  output: JSON.stringify(r)
7791
7838
  };
7792
7839
  }
7793
- function si(t) {
7840
+ function ii(t) {
7794
7841
  const { parser: e } = g.getState(), r = {
7795
7842
  uploadedFileName: e.uploadedFileName,
7796
7843
  parsedContent: e.parsedContent
@@ -7801,7 +7848,7 @@ function si(t) {
7801
7848
  output: JSON.stringify(r)
7802
7849
  };
7803
7850
  }
7804
- async function ai(t, e) {
7851
+ async function oi(t, e) {
7805
7852
  const { setToolCallError: r } = g.getState(), n = t.input;
7806
7853
  let i = "Item removed from cart successfully.";
7807
7854
  try {
@@ -7826,7 +7873,7 @@ async function ai(t, e) {
7826
7873
  output: i
7827
7874
  };
7828
7875
  }
7829
- function ii(t) {
7876
+ function ci(t) {
7830
7877
  const {
7831
7878
  cartifact: { itemWarnings: e },
7832
7879
  setItemWarnings: r
@@ -7839,7 +7886,7 @@ function ii(t) {
7839
7886
  output: "Item warnings removed successfully."
7840
7887
  };
7841
7888
  }
7842
- function oi(t) {
7889
+ function li(t) {
7843
7890
  const { setItemWarnings: e } = g.getState(), r = t.input;
7844
7891
  return r.itemWarnings && e(r.itemWarnings), {
7845
7892
  tool: xr,
@@ -7847,7 +7894,7 @@ function oi(t) {
7847
7894
  output: "Item warnings set successfully."
7848
7895
  };
7849
7896
  }
7850
- function ci(t) {
7897
+ function di(t) {
7851
7898
  const e = t.input;
7852
7899
  return g.getState().applyPoMetadata(e.poMetadata), {
7853
7900
  tool: Ye,
@@ -7855,7 +7902,7 @@ function ci(t) {
7855
7902
  output: "PO metadata set successfully."
7856
7903
  };
7857
7904
  }
7858
- async function li(t, e) {
7905
+ async function ui(t, e) {
7859
7906
  const { setToolCallError: r, setPoItemPrice: n } = g.getState(), i = t.input;
7860
7907
  let s = 0;
7861
7908
  try {
@@ -7888,21 +7935,21 @@ async function li(t, e) {
7888
7935
  };
7889
7936
  }
7890
7937
  const Br = {
7891
- addToCart: ti,
7892
- updateCart: li,
7893
- removeFromCart: ai,
7894
- clearCart: ri,
7895
- getCart: ni,
7896
- getPurchaseOrderData: si,
7897
- setPoMetadata: ci,
7898
- setItemWarnings: oi,
7899
- removeItemWarnings: ii
7900
- }, di = new Set(Object.keys(Br));
7901
- async function ui(t, e) {
7938
+ addToCart: ni,
7939
+ updateCart: ui,
7940
+ removeFromCart: oi,
7941
+ clearCart: si,
7942
+ getCart: ai,
7943
+ getPurchaseOrderData: ii,
7944
+ setPoMetadata: di,
7945
+ setItemWarnings: li,
7946
+ removeItemWarnings: ci
7947
+ }, pi = new Set(Object.keys(Br));
7948
+ async function hi(t, e) {
7902
7949
  const r = Br[t.toolName];
7903
7950
  return r?.(t, e);
7904
7951
  }
7905
- function pi(t, e) {
7952
+ function fi(t, e) {
7906
7953
  const n = [...t].reverse().find((i) => i.role === "assistant")?.parts?.find(
7907
7954
  (i) => "toolCallId" in i && i.toolCallId === e && "state" in i && (i.state === "output-available" || i.state === "output-error")
7908
7955
  );
@@ -7912,12 +7959,12 @@ function pi(t, e) {
7912
7959
  errorText: "errorText" in n ? String(n.errorText) : void 0
7913
7960
  };
7914
7961
  }
7915
- async function hi(t, e, r) {
7962
+ async function mi(t, e, r) {
7916
7963
  const n = [], i = [];
7917
7964
  for (const s of t) {
7918
- if (!di.has(s.toolName))
7965
+ if (!pi.has(s.toolName))
7919
7966
  continue;
7920
- const o = pi(
7967
+ const o = fi(
7921
7968
  e,
7922
7969
  s.toolCallId
7923
7970
  );
@@ -7936,7 +7983,7 @@ async function hi(t, e, r) {
7936
7983
  continue;
7937
7984
  }
7938
7985
  try {
7939
- const c = await ui(s, r);
7986
+ const c = await hi(s, r);
7940
7987
  c && (n.push(c.toolCallId), i.push(c));
7941
7988
  } catch (c) {
7942
7989
  console.error("[handleToolCall] Error:", { toolCall: s, error: c });
@@ -7946,7 +7993,7 @@ async function hi(t, e, r) {
7946
7993
  }
7947
7994
  return { completedToolCallIds: n, outputs: i };
7948
7995
  }
7949
- function fi() {
7996
+ function gi() {
7950
7997
  try {
7951
7998
  const t = localStorage.getItem(ot);
7952
7999
  if (!t)
@@ -8002,7 +8049,7 @@ function ze() {
8002
8049
  console.error("Failed to clear persisted session:", t);
8003
8050
  }
8004
8051
  }
8005
- function mi(t, e) {
8052
+ function yi(t, e) {
8006
8053
  return !t && !e ? { valid: !0 } : t && !e ? {
8007
8054
  valid: !1,
8008
8055
  error: "Your previous session was reset because you signed out."
@@ -8014,20 +8061,20 @@ function mi(t, e) {
8014
8061
  error: "Your previous session was reset because you signed in as a different user."
8015
8062
  } : { valid: !0 };
8016
8063
  }
8017
- async function gi(t, e) {
8064
+ async function xi(t, e) {
8018
8065
  return { valid: !0 };
8019
8066
  }
8020
- function yi(t) {
8067
+ function bi(t) {
8021
8068
  return t ? { valid: !0 } : {
8022
8069
  valid: !1,
8023
8070
  error: "The cart from your previous session is no longer available."
8024
8071
  };
8025
8072
  }
8026
- async function xi(t) {
8073
+ async function Ci(t) {
8027
8074
  const e = g.getState();
8028
8075
  if (e.ui.initStatus !== "pending")
8029
8076
  return;
8030
- const r = fi();
8077
+ const r = gi();
8031
8078
  if (e.setTakeShapeConfig(t.takeShapeConfig), !r.valid) {
8032
8079
  ze(), e.failValidation(r.error ?? "Session validation failed");
8033
8080
  return;
@@ -8037,8 +8084,8 @@ async function xi(t) {
8037
8084
  const m = await t.storefrontClient.getCustomerAddresses();
8038
8085
  if (i = m.customerInfo, n = m.addresses, await t.b2bClient.initPromise, t.b2bClient.isAvailable) {
8039
8086
  console.debug("[BigCommerceClient] Fetching B2B company addresses");
8040
- const v = await t.b2bClient.getCompanyAddresses();
8041
- v.length > 0 && (n = [...v]);
8087
+ const C = await t.b2bClient.getCompanyAddresses();
8088
+ C.length > 0 && (n = [...C]);
8042
8089
  }
8043
8090
  } catch (m) {
8044
8091
  if (console.error("Failed to fetch customer addresses:", m), r.data) {
@@ -8075,12 +8122,12 @@ async function xi(t) {
8075
8122
  const d = [];
8076
8123
  d.push(
8077
8124
  Promise.resolve(
8078
- mi(
8125
+ yi(
8079
8126
  c.customerEntityId ?? null,
8080
8127
  i
8081
8128
  )
8082
8129
  )
8083
- ), s && d.push(gi()), o && d.push(Promise.resolve(yi(l)));
8130
+ ), s && d.push(xi()), o && d.push(Promise.resolve(bi(l)));
8084
8131
  const u = (await Promise.all(d)).find((m) => !m.valid);
8085
8132
  if (u) {
8086
8133
  ze(), e.failValidation(u.error ?? "Session validation failed");
@@ -8088,16 +8135,16 @@ async function xi(t) {
8088
8135
  }
8089
8136
  c && e.restoreSession(c), l && e.setBcCart(l), i && e.setCustomerInfo(i), n.length > 0 && e.setCustomerAddresses(n), e.completeValidation();
8090
8137
  }
8091
- function bi(t) {
8138
+ function vi(t) {
8092
8139
  return jr(t) && "toolCallId" in t && typeof t.toolCallId == "string" && "output" in t && t.output !== void 0 && "state" in t && t.state === "output-available";
8093
8140
  }
8094
- function Ci(t) {
8095
- return t ? t.filter(bi) : [];
8141
+ function Ii(t) {
8142
+ return t ? t.filter(vi) : [];
8096
8143
  }
8097
- function vi(t) {
8144
+ function wi(t) {
8098
8145
  return t.type === "dynamic-tool" ? t.toolName ?? "unknown" : t.type.slice(5);
8099
8146
  }
8100
- const Ii = new Lr({
8147
+ const Si = new Lr({
8101
8148
  defaultOptions: {
8102
8149
  queries: {
8103
8150
  staleTime: 300 * 1e3
@@ -8105,15 +8152,15 @@ const Ii = new Lr({
8105
8152
  }
8106
8153
  }
8107
8154
  });
8108
- function wi(t) {
8109
- return /* @__PURE__ */ a(_r, { client: Ii, children: /* @__PURE__ */ a(Ss, { client: t.bigcommerce.client, children: /* @__PURE__ */ a(Si, { ...t }) }) });
8155
+ function Ei(t) {
8156
+ return /* @__PURE__ */ a(_r, { client: Si, children: /* @__PURE__ */ a(Ss, { client: t.bigcommerce.client, children: /* @__PURE__ */ a(Ni, { ...t }) }) });
8110
8157
  }
8111
- function Si(t) {
8158
+ function Ni(t) {
8112
8159
  const e = g((s) => s.ui.initStatus), r = g((s) => s.ui.initError), n = g((s) => s.fatalError), i = g((s) => s.clearInitError);
8113
8160
  return F(() => {
8114
- e === "pending" && xi({
8161
+ e === "pending" && Ci({
8115
8162
  storefrontClient: t.bigcommerce.client,
8116
- b2bClient: ei({
8163
+ b2bClient: ri({
8117
8164
  channelId: t.bigcommerce.client.channelId,
8118
8165
  getB2BJwt: t.bigcommerce.getB2BJwt
8119
8166
  }),
@@ -8123,19 +8170,19 @@ function Si(t) {
8123
8170
  "div",
8124
8171
  {
8125
8172
  className: `flex h-full items-center justify-center ${t.className ?? ""}`,
8126
- children: /* @__PURE__ */ a(ta, { message: n })
8173
+ children: /* @__PURE__ */ a(ra, { message: n })
8127
8174
  }
8128
8175
  ) : e === "pending" ? /* @__PURE__ */ a(
8129
8176
  "div",
8130
8177
  {
8131
8178
  className: `flex h-full items-center justify-center ${t.className ?? ""}`,
8132
- children: /* @__PURE__ */ a("div", { className: "flex items-center", children: /* @__PURE__ */ a(Me, { size: 16 }) })
8179
+ children: /* @__PURE__ */ a("div", { className: "flex items-center", children: /* @__PURE__ */ a(Oe, { size: 16 }) })
8133
8180
  }
8134
8181
  ) : e === "existing-cart" ? /* @__PURE__ */ a(
8135
8182
  "div",
8136
8183
  {
8137
8184
  className: `flex h-full items-center justify-center ${t.className ?? ""}`,
8138
- children: /* @__PURE__ */ a(ea, {})
8185
+ children: /* @__PURE__ */ a(ta, {})
8139
8186
  }
8140
8187
  ) : r ? /* @__PURE__ */ h(
8141
8188
  "div",
@@ -8154,9 +8201,9 @@ function Si(t) {
8154
8201
  )
8155
8202
  ]
8156
8203
  }
8157
- ) : /* @__PURE__ */ a(Ei, { ...t });
8204
+ ) : /* @__PURE__ */ a(ki, { ...t });
8158
8205
  }
8159
- function Ei({
8206
+ function ki({
8160
8207
  className: t = "",
8161
8208
  agentName: e = Qe,
8162
8209
  inputName: r = Qe,
@@ -8164,70 +8211,70 @@ function Ei({
8164
8211
  expandOnReady: i
8165
8212
  }) {
8166
8213
  const { sseOrigin: s, projectId: o, apiKey: c } = g(
8167
- (C) => C.takeshapeConfig
8214
+ (v) => v.takeshapeConfig
8168
8215
  ), l = g(
8169
- (C) => C.chat.threadId
8170
- ), d = g((C) => C.chat.input), p = g(
8171
- (C) => C.chat.messages
8216
+ (v) => v.chat.threadId
8217
+ ), d = g((v) => v.chat.input), p = g(
8218
+ (v) => v.chat.messages
8172
8219
  ), {
8173
8220
  thread: u,
8174
8221
  isCreating: m,
8175
- createThread: v
8222
+ createThread: C
8176
8223
  } = Ar({
8177
8224
  agentName: e,
8178
8225
  createOnMount: !l,
8179
8226
  // Only create if no existing thread
8180
8227
  existingThreadId: l
8181
- }), b = g((C) => C.appState), x = g((C) => C.setAppState), I = D(null), w = D(
8228
+ }), b = g((v) => v.appState), x = g((v) => v.setAppState), I = D(null), w = D(
8182
8229
  null
8183
8230
  ), k = D(
8184
8231
  null
8185
- ), N = Re((C) => C.isExpanded), T = Re((C) => C.setExpanded), y = Re((C) => C.reset), A = Za(), $ = Ea({
8232
+ ), N = _e((v) => v.isExpanded), T = _e((v) => v.setExpanded), y = _e((v) => v.reset), A = ei(), $ = Na({
8186
8233
  client: n.client,
8187
- onError: (C) => console.error("BigCommerce error:", C)
8188
- }), B = g((C) => C.cartifact.orderId), Q = g((C) => C.cartifact.buyerInfo), te = g(
8189
- (C) => C.cartifact.shipToAddress
8234
+ onError: (v) => console.error("BigCommerce error:", v)
8235
+ }), B = g((v) => v.cartifact.orderId), Q = g((v) => v.cartifact.buyerInfo), te = g(
8236
+ (v) => v.cartifact.shipToAddress
8190
8237
  ), j = g(
8191
- (C) => C.cartifact.billingAddress
8238
+ (v) => v.cartifact.billingAddress
8192
8239
  ), Y = g(
8193
- (C) => C.cartifact.poMetadataSet
8240
+ (v) => v.cartifact.poMetadataSet
8194
8241
  ), re = g(
8195
- (C) => C.cartifact.itemWarnings
8196
- ), ie = g((C) => C.clearCartifact), Z = g((C) => C.clearBcSession), ne = g(
8197
- (C) => C.clearAddressSelections
8198
- ), z = g((C) => C.clearChat), { cartItems: q } = $, oe = D([]), Ie = M(
8199
- async ({ toolCall: C }) => {
8200
- oe.current.push(C);
8242
+ (v) => v.cartifact.itemWarnings
8243
+ ), ie = g((v) => v.clearCartifact), Z = g((v) => v.clearBcSession), ne = g(
8244
+ (v) => v.clearAddressSelections
8245
+ ), z = g((v) => v.clearChat), { cartItems: q } = $, oe = D([]), Ie = M(
8246
+ async ({ toolCall: v }) => {
8247
+ oe.current.push(v);
8201
8248
  },
8202
8249
  []
8203
- ), L = D(/* @__PURE__ */ new Set()), { messages: W, sendMessage: G, status: K, error: Pe, setMessages: fe, addToolOutput: me } = Wt({
8250
+ ), L = D(/* @__PURE__ */ new Set()), { messages: W, sendMessage: G, status: K, error: Te, setMessages: fe, addToolOutput: me } = Wt({
8204
8251
  transport: new Vt({
8205
8252
  api: `${s}/project/${o}/agents/messages`,
8206
8253
  headers: {
8207
8254
  Authorization: `Bearer ${c}`
8208
8255
  },
8209
- prepareSendMessagesRequest: async (C) => {
8210
- const se = C.messages[C.messages.length - 1];
8256
+ prepareSendMessagesRequest: async (v) => {
8257
+ const se = v.messages[v.messages.length - 1];
8211
8258
  if (!se)
8212
8259
  throw new Error("No messages to send");
8213
8260
  let we = [se];
8214
- if (se.role === "user" && C.messages.length >= 2) {
8215
- const pe = C.messages[C.messages.length - 2], Ze = L.current;
8261
+ if (se.role === "user" && v.messages.length >= 2) {
8262
+ const pe = v.messages[v.messages.length - 2], Ze = L.current;
8216
8263
  if (pe?.role === "assistant" && Ze.size > 0) {
8217
- const ft = Ci(
8264
+ const ft = Ii(
8218
8265
  pe.parts
8219
8266
  ).filter(
8220
8267
  (mt) => Ze.has(mt.toolCallId)
8221
8268
  );
8222
8269
  Ze.clear(), ft.length > 0 && (we = [{
8223
8270
  ...pe,
8224
- parts: ft.map((Te) => ({
8225
- type: Te.type,
8226
- toolName: vi(Te),
8227
- toolCallId: Te.toolCallId,
8228
- state: Te.state,
8229
- input: Te.input,
8230
- output: Te.output
8271
+ parts: ft.map((Ae) => ({
8272
+ type: Ae.type,
8273
+ toolName: wi(Ae),
8274
+ toolCallId: Ae.toolCallId,
8275
+ state: Ae.state,
8276
+ input: Ae.input,
8277
+ output: Ae.output
8231
8278
  }))
8232
8279
  }, se]);
8233
8280
  }
@@ -8236,10 +8283,10 @@ function Ei({
8236
8283
  body: {
8237
8284
  id: u.current?.id ?? "",
8238
8285
  messages: we,
8239
- trigger: C.trigger,
8240
- messageId: C.messageId,
8286
+ trigger: v.trigger,
8287
+ messageId: v.messageId,
8241
8288
  metadata: {
8242
- ...C.requestMetadata,
8289
+ ...v.requestMetadata,
8243
8290
  custom: {
8244
8291
  inputName: r
8245
8292
  }
@@ -8250,21 +8297,21 @@ function Ei({
8250
8297
  }),
8251
8298
  messages: p,
8252
8299
  onToolCall: Ie,
8253
- onError: (C) => {
8254
- console.error("[useChat onError]", C), w.current?.setStatus({
8300
+ onError: (v) => {
8301
+ console.error("[useChat onError]", v), w.current?.setStatus({
8255
8302
  code: 2,
8256
8303
  message: "internal_error"
8257
8304
  }), w.current?.end(), w.current = null;
8258
8305
  }
8259
8306
  }), de = M(
8260
- (C) => {
8307
+ (v) => {
8261
8308
  w.current?.end(), w.current = rt({
8262
8309
  name: "po-agent-turn",
8263
8310
  op: "ai.agent",
8264
8311
  attributes: {
8265
8312
  "agent.name": r
8266
8313
  }
8267
- }), G(C);
8314
+ }), G(v);
8268
8315
  },
8269
8316
  [G, r]
8270
8317
  );
@@ -8274,8 +8321,8 @@ function Ei({
8274
8321
  w.current?.end(), k.current?.end();
8275
8322
  }, []), F(() => {
8276
8323
  if (K === "ready" && oe.current.length > 0) {
8277
- const C = [...oe.current];
8278
- oe.current = [], hi(C, W, $).then(async (se) => {
8324
+ const v = [...oe.current];
8325
+ oe.current = [], mi(v, W, $).then(async (se) => {
8279
8326
  for (const we of se.outputs)
8280
8327
  L.current.add(we.toolCallId), await me(we);
8281
8328
  se.outputs.length > 0 && de({ text: it });
@@ -8287,8 +8334,8 @@ function Ei({
8287
8334
  g.getState().setMessages(W);
8288
8335
  }, [W]);
8289
8336
  const ge = g(
8290
- (C) => C.ai.pendingMessage
8291
- ), f = g((C) => C.ai.shouldScroll), S = g((C) => C.consumeMessage);
8337
+ (v) => v.ai.pendingMessage
8338
+ ), f = g((v) => v.ai.shouldScroll), S = g((v) => v.consumeMessage);
8292
8339
  F(() => {
8293
8340
  ge && (de({ text: ge }), S(), f && requestAnimationFrame(() => {
8294
8341
  I.current?.scrollToBottom();
@@ -8296,58 +8343,58 @@ function Ei({
8296
8343
  }, [ge, f, de, S]), F(() => {
8297
8344
  i && b === "chatting" && T(!0);
8298
8345
  }, [i, b, T]);
8299
- const E = m || K === "submitted" || K === "streaming", P = ee(() => ha(W, K), [W, K]), O = Ra({
8346
+ const E = m || K === "submitted" || K === "streaming", P = ee(() => fa(W, K), [W, K]), O = La({
8300
8347
  appState: b,
8301
8348
  setAppState: x,
8302
8349
  parser: A,
8303
8350
  firstResponseComplete: P,
8304
8351
  chatPanelRef: I,
8305
8352
  bcCart: $
8306
- }), U = Na({
8353
+ }), U = ka({
8307
8354
  bcCart: $,
8308
8355
  cartItems: q,
8309
- onCheckoutInitiated: (C) => {
8310
- C ? k.current?.setStatus({ code: 2, message: C.message }) : k.current?.setStatus({ code: 1, message: "ok" }), k.current?.end(), k.current = null;
8356
+ onCheckoutInitiated: (v) => {
8357
+ v ? k.current?.setStatus({ code: 2, message: v.message }) : k.current?.setStatus({ code: 1, message: "ok" }), k.current?.end(), k.current = null;
8311
8358
  },
8312
8359
  onCheckout: n.onCheckout
8313
- }), _ = (C) => {
8314
- g.getState().setInput(C.target.value);
8315
- }, qe = (C) => {
8316
- C.preventDefault(), d.trim() && (g.getState().sendMessage(d), g.getState().setInput(""));
8317
- }, Fe = async (C) => {
8360
+ }), _ = (v) => {
8361
+ g.getState().setInput(v.target.value);
8362
+ }, qe = (v) => {
8363
+ v.preventDefault(), d.trim() && (g.getState().sendMessage(d), g.getState().setInput(""));
8364
+ }, De = async (v) => {
8318
8365
  k.current?.end(), k.current = rt({
8319
8366
  name: "upload-to-checkout",
8320
8367
  op: "purchase-order.session",
8321
8368
  attributes: {
8322
- "file.name": C.name
8369
+ "file.name": v.name
8323
8370
  }
8324
- }), x("processing"), O.reset(), await A.handleFileUpload(C) === !1 && x("upload");
8371
+ }), x("processing"), O.reset(), await A.handleFileUpload(v) === !1 && x("upload");
8325
8372
  }, H = M(
8326
- (C) => {
8373
+ (v) => {
8327
8374
  n.onViewProduct && n.onViewProduct({
8328
- productEntityId: C.productEntityId,
8329
- sku: C.sku,
8330
- name: C.name,
8331
- path: C.path
8375
+ productEntityId: v.productEntityId,
8376
+ sku: v.sku,
8377
+ name: v.name,
8378
+ path: v.path
8332
8379
  });
8333
8380
  },
8334
8381
  [n.onViewProduct]
8335
8382
  ), ce = M(() => {
8336
- const C = [...W].reverse().find((pe) => pe.role === "user");
8337
- if (!C) return;
8338
- const se = C.parts?.filter(
8383
+ const v = [...W].reverse().find((pe) => pe.role === "user");
8384
+ if (!v) return;
8385
+ const se = v.parts?.filter(
8339
8386
  (pe) => pe.type === "text"
8340
8387
  ).map((pe) => pe.text).join(`
8341
8388
  `);
8342
8389
  if (!se) return;
8343
- const we = W.lastIndexOf(C);
8390
+ const we = W.lastIndexOf(v);
8344
8391
  fe(W.slice(0, we)), g.getState().sendMessage(se);
8345
8392
  }, [W, fe]), J = M(() => {
8346
8393
  x("chatting");
8347
8394
  }, [x]), X = g(
8348
- (C) => C.resetBatchProcessing
8395
+ (v) => v.resetBatchProcessing
8349
8396
  ), ye = M(async () => {
8350
- k.current?.setStatus({ code: 2, message: "cancelled" }), k.current?.end(), k.current = null, await $.clearCart(), ie(), Z(), ne(), z(), fe([]), X(), y(), A.reset(), O.reset(), x("upload"), v();
8397
+ k.current?.setStatus({ code: 2, message: "cancelled" }), k.current?.end(), k.current = null, await $.clearCart(), ie(), Z(), ne(), z(), fe([]), X(), y(), A.reset(), O.reset(), x("upload"), C();
8351
8398
  }, [
8352
8399
  $.clearCart,
8353
8400
  ie,
@@ -8359,14 +8406,14 @@ function Ei({
8359
8406
  y,
8360
8407
  A.reset,
8361
8408
  O.reset,
8362
- v,
8409
+ C,
8363
8410
  x
8364
8411
  ]);
8365
8412
  if (b === "upload" || b === "processing")
8366
8413
  return /* @__PURE__ */ a("div", { className: `flex h-full ${t}`, children: /* @__PURE__ */ a(
8367
- Ca,
8414
+ va,
8368
8415
  {
8369
- onFileUpload: Fe,
8416
+ onFileUpload: De,
8370
8417
  onSkip: J,
8371
8418
  onClearError: A.handleClearError,
8372
8419
  cartItems: q,
@@ -8381,12 +8428,12 @@ function Ei({
8381
8428
  onInputChange: _,
8382
8429
  onSubmit: qe,
8383
8430
  isLoading: E,
8384
- error: Pe,
8385
- onRetry: Pe ? ce : void 0,
8431
+ error: Te,
8432
+ onRetry: Te ? ce : void 0,
8386
8433
  hasProcessedDocument: O.hasProcessedDocument,
8387
8434
  uploadedFileName: A.uploadedFileName,
8388
8435
  chatPanelRef: I,
8389
- onFileUpload: Fe,
8436
+ onFileUpload: De,
8390
8437
  cartItems: q,
8391
8438
  itemWarnings: re,
8392
8439
  onUpdateQuantity: U.handleUpdateQuantity,
@@ -8421,7 +8468,7 @@ function Ei({
8421
8468
  }
8422
8469
  ) });
8423
8470
  }
8424
- function Hi({
8471
+ function Gi({
8425
8472
  takeshape: t,
8426
8473
  bigcommerce: e,
8427
8474
  agentName: r = Qe,
@@ -8440,7 +8487,7 @@ function Hi({
8440
8487
  [e.endpoint, e.storefrontToken, e.channelId]
8441
8488
  );
8442
8489
  return /* @__PURE__ */ a(
8443
- wi,
8490
+ Ei,
8444
8491
  {
8445
8492
  agentName: r,
8446
8493
  inputName: n,
@@ -8462,14 +8509,14 @@ function Hi({
8462
8509
  );
8463
8510
  }
8464
8511
  export {
8465
- Hi as P,
8466
- ji as S,
8512
+ Gi as P,
8513
+ Vi as S,
8467
8514
  wn as a,
8468
- Wi as b,
8469
- ei as c,
8470
- wi as d,
8471
- Vi as i,
8472
- qi as r,
8473
- zi as s
8515
+ zi as b,
8516
+ ri as c,
8517
+ Ei as d,
8518
+ Hi as i,
8519
+ Wi as r,
8520
+ Qi as s
8474
8521
  };
8475
- //# sourceMappingURL=purchase-order-chat-wrapper-BVV3Wy6e.js.map
8522
+ //# sourceMappingURL=purchase-order-chat-wrapper-66JrwtTs.js.map