@opencx/widget-react-headless 5.0.0-beta.0 → 5.0.0-beta.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.
package/dist/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import V, { useSyncExternalStore as Oe, useRef as D, useCallback as U, useEffect as $, useMemo as X, useState as Z, createContext as Ue, useContext as qe } from "react";
1
+ import V, { useSyncExternalStore as Oe, useRef as j, useCallback as U, useEffect as $, useMemo as X, useState as Z, createContext as Ue, useContext as qe } from "react";
2
2
  import { isAgentStreamKeepalive as Zt, isRecord as Rr, isTurnSteeredPart as Or, buildSendMessageBody as Pr, log as q, genUuid as yt, WidgetCtx as Nr, resolveSidebarMode as jr, resolveSidebarSide as Dr, normalizeCompanionLayouts as Lr, resolveCompanionDefaultLayout as Fr } from "@opencx/widget-core";
3
3
  import * as bt from "zod/v4";
4
4
  import { z as s } from "zod/v4";
@@ -6,7 +6,7 @@ import { ZodFirstPartyTypeKind as C } from "zod/v3";
6
6
  import "react/jsx-runtime";
7
7
  import { z } from "zod";
8
8
  import { v4 as kr } from "uuid";
9
- const $r = "5.0.0-beta.0";
9
+ const $r = "5.0.0-beta.1";
10
10
  class Ur {
11
11
  constructor(t) {
12
12
  this.components = [];
@@ -16,9 +16,10 @@ class Ur {
16
16
  if (!this.get("fallback"))
17
17
  throw new Error("No fallback component registered");
18
18
  }
19
- // TODO test that this registers or replaces the component
20
19
  register(t) {
21
- const r = this.components.findIndex((a) => a.key === t.key);
20
+ const r = this.components.findIndex(
21
+ (a) => a.key.toUpperCase() === t.key.toUpperCase()
22
+ );
22
23
  return r !== -1 ? this.components[r] = t : this.components.push(t), this;
23
24
  }
24
25
  get(t) {
@@ -165,35 +166,35 @@ function Yr(e) {
165
166
  );
166
167
  const { onEvent: t = Ye, onError: r = Ye, onRetry: a = Ye, onComment: n, maxBufferSize: o } = e, u = [];
167
168
  let i = 0, g = !0, c, l = "", p = 0, v, h = !1;
168
- function T(f) {
169
+ function A(f) {
169
170
  if (h)
170
171
  throw new Error(
171
172
  "Cannot feed parser: it was terminated after exceeding the configured max buffer size. Call `reset()` to resume parsing."
172
173
  );
173
174
  if (g && (g = !1, f.charCodeAt(0) === 239 && f.charCodeAt(1) === 187 && f.charCodeAt(2) === 191 && (f = f.slice(3))), u.length === 0) {
174
- const y = _(f);
175
- y !== "" && (u.push(y), i = y.length), A();
175
+ const y = S(f);
176
+ y !== "" && (u.push(y), i = y.length), M();
176
177
  return;
177
178
  }
178
179
  if (f.indexOf(`
179
180
  `) === -1 && f.indexOf("\r") === -1) {
180
- u.push(f), i += f.length, A();
181
+ u.push(f), i += f.length, M();
181
182
  return;
182
183
  }
183
184
  u.push(f);
184
185
  const m = u.join("");
185
186
  u.length = 0, i = 0;
186
- const b = _(m);
187
- b !== "" && (u.push(b), i = b.length), A();
187
+ const b = S(m);
188
+ b !== "" && (u.push(b), i = b.length), M();
188
189
  }
189
- function A() {
190
+ function M() {
190
191
  o !== void 0 && (i + l.length <= o || (h = !0, u.length = 0, i = 0, c = void 0, l = "", p = 0, v = void 0, r(
191
192
  new Ke(`Buffered data exceeded max buffer size of ${o} characters`, {
192
193
  type: "max-buffer-size-exceeded"
193
194
  })
194
195
  )));
195
196
  }
196
- function _(f) {
197
+ function S(f) {
197
198
  let m = 0;
198
199
  if (f.indexOf("\r") === -1) {
199
200
  let b = f.indexOf(`
@@ -206,18 +207,18 @@ function Yr(e) {
206
207
  }
207
208
  const y = f.charCodeAt(m);
208
209
  if (Rt(f, m, y)) {
209
- const w = f.charCodeAt(m + 5) === fe ? m + 6 : m + 5, j = f.slice(w, b);
210
+ const w = f.charCodeAt(m + 5) === fe ? m + 6 : m + 5, D = f.slice(w, b);
210
211
  if (p === 0 && f.charCodeAt(b + 1) === xt) {
211
- t({ id: c, event: v, data: j }), c = void 0, l = "", v = void 0, m = b + 2, b = f.indexOf(`
212
+ t({ id: c, event: v, data: D }), c = void 0, l = "", v = void 0, m = b + 2, b = f.indexOf(`
212
213
  `, m);
213
214
  continue;
214
215
  }
215
- l = p === 0 ? j : `${l}
216
- ${j}`, p++;
216
+ l = p === 0 ? D : `${l}
217
+ ${D}`, p++;
217
218
  } else Ot(f, m, y) ? v = f.slice(
218
219
  f.charCodeAt(m + 6) === fe ? m + 7 : m + 6,
219
220
  b
220
- ) || void 0 : S(f, m, b);
221
+ ) || void 0 : I(f, m, b);
221
222
  m = b + 1, b = f.indexOf(`
222
223
  `, m);
223
224
  }
@@ -229,11 +230,11 @@ ${j}`, p++;
229
230
  let w = -1;
230
231
  if (b !== -1 && y !== -1 ? w = b < y ? b : y : b !== -1 ? b === f.length - 1 ? w = -1 : w = b : y !== -1 && (w = y), w === -1)
231
232
  break;
232
- S(f, m, w), m = w + 1, f.charCodeAt(m - 1) === Kr && f.charCodeAt(m) === xt && m++;
233
+ I(f, m, w), m = w + 1, f.charCodeAt(m - 1) === Kr && f.charCodeAt(m) === xt && m++;
233
234
  }
234
235
  return f.slice(m);
235
236
  }
236
- function S(f, m, b) {
237
+ function I(f, m, b) {
237
238
  if (m === b) {
238
239
  R();
239
240
  return;
@@ -261,15 +262,15 @@ ${ee}`, p++;
261
262
  }
262
263
  return;
263
264
  }
264
- const w = f.slice(m, b), j = w.indexOf(":");
265
- if (j === -1) {
266
- I(w, "", w);
265
+ const w = f.slice(m, b), D = w.indexOf(":");
266
+ if (D === -1) {
267
+ _(w, "", w);
267
268
  return;
268
269
  }
269
- const se = w.slice(0, j), Be = w.charCodeAt(j + 1) === fe ? 2 : 1, We = w.slice(j + Be);
270
- I(se, We, w);
270
+ const se = w.slice(0, D), Be = w.charCodeAt(D + 1) === fe ? 2 : 1, We = w.slice(D + Be);
271
+ _(se, We, w);
271
272
  }
272
- function I(f, m, b) {
273
+ function _(f, m, b) {
273
274
  switch (f) {
274
275
  case "event":
275
276
  v = m || void 0;
@@ -310,11 +311,11 @@ ${m}`, p++;
310
311
  function d(f = {}) {
311
312
  if (f.consume && u.length > 0) {
312
313
  const m = u.join("");
313
- S(m, 0, m.length);
314
+ I(m, 0, m.length);
314
315
  }
315
316
  g = !0, c = void 0, l = "", p = 0, v = void 0, u.length = 0, i = 0, h = !1;
316
317
  }
317
- return { feed: T, reset: d };
318
+ return { feed: A, reset: d };
318
319
  }
319
320
  function Rt(e, t, r) {
320
321
  return r === 100 && e.charCodeAt(t + 1) === 97 && e.charCodeAt(t + 2) === 116 && e.charCodeAt(t + 3) === 97 && e.charCodeAt(t + 4) === 58;
@@ -1556,7 +1557,7 @@ var he = s.lazy(
1556
1557
  s.record(s.string(), he.optional()),
1557
1558
  s.array(he)
1558
1559
  ])
1559
- ), M = s.record(
1560
+ ), T = s.record(
1560
1561
  s.string(),
1561
1562
  s.record(s.string(), he.optional())
1562
1563
  ), je = s.union([
@@ -1567,7 +1568,7 @@ var he = s.lazy(
1567
1568
  ]), ct = s.record(s.string(), s.string()), ur = s.object({
1568
1569
  type: s.literal("text"),
1569
1570
  text: s.string(),
1570
- providerOptions: M.optional()
1571
+ providerOptions: T.optional()
1571
1572
  }), rs = s.object({
1572
1573
  type: s.literal("image"),
1573
1574
  image: s.union([
@@ -1576,7 +1577,7 @@ var he = s.lazy(
1576
1577
  ct
1577
1578
  ]),
1578
1579
  mediaType: s.string().optional(),
1579
- providerOptions: M.optional()
1580
+ providerOptions: T.optional()
1580
1581
  }), cr = s.discriminatedUnion("type", [
1581
1582
  s.object({ type: s.literal("data"), data: je }),
1582
1583
  s.object({ type: s.literal("url"), url: s.instanceof(URL) }),
@@ -1598,15 +1599,15 @@ var he = s.lazy(
1598
1599
  ]),
1599
1600
  filename: s.string().optional(),
1600
1601
  mediaType: s.string(),
1601
- providerOptions: M.optional()
1602
+ providerOptions: T.optional()
1602
1603
  }), ss = s.object({
1603
1604
  type: s.literal("reasoning"),
1604
1605
  text: s.string(),
1605
- providerOptions: M.optional()
1606
+ providerOptions: T.optional()
1606
1607
  }), ns = s.object({
1607
1608
  type: s.literal("custom"),
1608
1609
  kind: s.string().transform((e) => e),
1609
- providerOptions: M.optional()
1610
+ providerOptions: T.optional()
1610
1611
  }), is = s.object({
1611
1612
  type: s.literal("reasoning-file"),
1612
1613
  data: s.union([
@@ -1615,13 +1616,13 @@ var he = s.lazy(
1615
1616
  s.instanceof(URL)
1616
1617
  ]),
1617
1618
  mediaType: s.string(),
1618
- providerOptions: M.optional()
1619
+ providerOptions: T.optional()
1619
1620
  }), os = s.object({
1620
1621
  type: s.literal("tool-call"),
1621
1622
  toolCallId: s.string(),
1622
1623
  toolName: s.string(),
1623
1624
  input: s.unknown(),
1624
- providerOptions: M.optional(),
1625
+ providerOptions: T.optional(),
1625
1626
  providerExecuted: s.boolean().optional()
1626
1627
  }), ls = s.discriminatedUnion(
1627
1628
  "type",
@@ -1629,27 +1630,27 @@ var he = s.lazy(
1629
1630
  s.object({
1630
1631
  type: s.literal("text"),
1631
1632
  value: s.string(),
1632
- providerOptions: M.optional()
1633
+ providerOptions: T.optional()
1633
1634
  }),
1634
1635
  s.object({
1635
1636
  type: s.literal("json"),
1636
1637
  value: he,
1637
- providerOptions: M.optional()
1638
+ providerOptions: T.optional()
1638
1639
  }),
1639
1640
  s.object({
1640
1641
  type: s.literal("execution-denied"),
1641
1642
  reason: s.string().optional(),
1642
- providerOptions: M.optional()
1643
+ providerOptions: T.optional()
1643
1644
  }),
1644
1645
  s.object({
1645
1646
  type: s.literal("error-text"),
1646
1647
  value: s.string(),
1647
- providerOptions: M.optional()
1648
+ providerOptions: T.optional()
1648
1649
  }),
1649
1650
  s.object({
1650
1651
  type: s.literal("error-json"),
1651
1652
  value: he,
1652
- providerOptions: M.optional()
1653
+ providerOptions: T.optional()
1653
1654
  }),
1654
1655
  s.object({
1655
1656
  type: s.literal("content"),
@@ -1658,14 +1659,14 @@ var he = s.lazy(
1658
1659
  s.object({
1659
1660
  type: s.literal("text"),
1660
1661
  text: s.string(),
1661
- providerOptions: M.optional()
1662
+ providerOptions: T.optional()
1662
1663
  }),
1663
1664
  s.object({
1664
1665
  type: s.literal("file"),
1665
1666
  data: cr,
1666
1667
  mediaType: s.string(),
1667
1668
  filename: s.string().optional(),
1668
- providerOptions: M.optional()
1669
+ providerOptions: T.optional()
1669
1670
  }),
1670
1671
  s.object({
1671
1672
  // Deprecated.
@@ -1673,55 +1674,55 @@ var he = s.lazy(
1673
1674
  data: s.string(),
1674
1675
  mediaType: s.string(),
1675
1676
  filename: s.string().optional(),
1676
- providerOptions: M.optional()
1677
+ providerOptions: T.optional()
1677
1678
  }),
1678
1679
  s.object({
1679
1680
  // Deprecated.
1680
1681
  type: s.literal("file-url"),
1681
1682
  url: s.string(),
1682
1683
  mediaType: s.string().optional(),
1683
- providerOptions: M.optional()
1684
+ providerOptions: T.optional()
1684
1685
  }),
1685
1686
  s.object({
1686
1687
  // Deprecated.
1687
1688
  type: s.literal("file-id"),
1688
1689
  fileId: s.union([s.string(), s.record(s.string(), s.string())]),
1689
- providerOptions: M.optional()
1690
+ providerOptions: T.optional()
1690
1691
  }),
1691
1692
  s.object({
1692
1693
  // Deprecated.
1693
1694
  type: s.literal("file-reference"),
1694
1695
  providerReference: s.record(s.string(), s.string()),
1695
- providerOptions: M.optional()
1696
+ providerOptions: T.optional()
1696
1697
  }),
1697
1698
  s.object({
1698
1699
  // Deprecated.
1699
1700
  type: s.literal("image-data"),
1700
1701
  data: s.string(),
1701
1702
  mediaType: s.string(),
1702
- providerOptions: M.optional()
1703
+ providerOptions: T.optional()
1703
1704
  }),
1704
1705
  s.object({
1705
1706
  // Deprecated.
1706
1707
  type: s.literal("image-url"),
1707
1708
  url: s.string(),
1708
- providerOptions: M.optional()
1709
+ providerOptions: T.optional()
1709
1710
  }),
1710
1711
  s.object({
1711
1712
  // Deprecated.
1712
1713
  type: s.literal("image-file-id"),
1713
1714
  fileId: s.union([s.string(), s.record(s.string(), s.string())]),
1714
- providerOptions: M.optional()
1715
+ providerOptions: T.optional()
1715
1716
  }),
1716
1717
  s.object({
1717
1718
  // Deprecated.
1718
1719
  type: s.literal("image-file-reference"),
1719
1720
  providerReference: s.record(s.string(), s.string()),
1720
- providerOptions: M.optional()
1721
+ providerOptions: T.optional()
1721
1722
  }),
1722
1723
  s.object({
1723
1724
  type: s.literal("custom"),
1724
- providerOptions: M.optional()
1725
+ providerOptions: T.optional()
1725
1726
  })
1726
1727
  ])
1727
1728
  )
@@ -1732,7 +1733,7 @@ var he = s.lazy(
1732
1733
  toolCallId: s.string(),
1733
1734
  toolName: s.string(),
1734
1735
  output: ls,
1735
- providerOptions: M.optional()
1736
+ providerOptions: T.optional()
1736
1737
  }), us = s.object({
1737
1738
  type: s.literal("tool-approval-request"),
1738
1739
  approvalId: s.string(),
@@ -1746,7 +1747,7 @@ var he = s.lazy(
1746
1747
  {
1747
1748
  role: s.literal("system"),
1748
1749
  content: s.string(),
1749
- providerOptions: M.optional()
1750
+ providerOptions: T.optional()
1750
1751
  }
1751
1752
  ), ps = s.object({
1752
1753
  role: s.literal("user"),
@@ -1754,7 +1755,7 @@ var he = s.lazy(
1754
1755
  s.string(),
1755
1756
  s.array(s.union([ur, rs, dr]))
1756
1757
  ]),
1757
- providerOptions: M.optional()
1758
+ providerOptions: T.optional()
1758
1759
  }), fs = s.object({
1759
1760
  role: s.literal("assistant"),
1760
1761
  content: s.union([
@@ -1772,11 +1773,11 @@ var he = s.lazy(
1772
1773
  ])
1773
1774
  )
1774
1775
  ]),
1775
- providerOptions: M.optional()
1776
+ providerOptions: T.optional()
1776
1777
  }), ms = s.object({
1777
1778
  role: s.literal("tool"),
1778
1779
  content: s.array(s.union([pr, cs])),
1779
- providerOptions: M.optional()
1780
+ providerOptions: T.optional()
1780
1781
  });
1781
1782
  s.union([
1782
1783
  ds,
@@ -2384,18 +2385,18 @@ var Ae = s.record(
2384
2385
  s.strictObject({
2385
2386
  type: s.literal("text-start"),
2386
2387
  id: s.string(),
2387
- providerMetadata: M.optional()
2388
+ providerMetadata: T.optional()
2388
2389
  }),
2389
2390
  s.strictObject({
2390
2391
  type: s.literal("text-delta"),
2391
2392
  id: s.string(),
2392
2393
  delta: s.string(),
2393
- providerMetadata: M.optional()
2394
+ providerMetadata: T.optional()
2394
2395
  }),
2395
2396
  s.strictObject({
2396
2397
  type: s.literal("text-end"),
2397
2398
  id: s.string(),
2398
- providerMetadata: M.optional()
2399
+ providerMetadata: T.optional()
2399
2400
  }),
2400
2401
  s.strictObject({
2401
2402
  type: s.literal("error"),
@@ -2406,7 +2407,7 @@ var Ae = s.record(
2406
2407
  toolCallId: s.string(),
2407
2408
  toolName: s.string(),
2408
2409
  providerExecuted: s.boolean().optional(),
2409
- providerMetadata: M.optional(),
2410
+ providerMetadata: T.optional(),
2410
2411
  toolMetadata: Ae.optional(),
2411
2412
  dynamic: s.boolean().optional(),
2412
2413
  title: s.string().optional()
@@ -2422,7 +2423,7 @@ var Ae = s.record(
2422
2423
  toolName: s.string(),
2423
2424
  input: s.unknown(),
2424
2425
  providerExecuted: s.boolean().optional(),
2425
- providerMetadata: M.optional(),
2426
+ providerMetadata: T.optional(),
2426
2427
  toolMetadata: Ae.optional(),
2427
2428
  dynamic: s.boolean().optional(),
2428
2429
  title: s.string().optional()
@@ -2433,7 +2434,7 @@ var Ae = s.record(
2433
2434
  toolName: s.string(),
2434
2435
  input: s.unknown(),
2435
2436
  providerExecuted: s.boolean().optional(),
2436
- providerMetadata: M.optional(),
2437
+ providerMetadata: T.optional(),
2437
2438
  toolMetadata: Ae.optional(),
2438
2439
  dynamic: s.boolean().optional(),
2439
2440
  errorText: s.string(),
@@ -2452,14 +2453,14 @@ var Ae = s.record(
2452
2453
  approved: s.boolean(),
2453
2454
  reason: s.string().optional(),
2454
2455
  providerExecuted: s.boolean().optional(),
2455
- providerMetadata: M.optional()
2456
+ providerMetadata: T.optional()
2456
2457
  }),
2457
2458
  s.strictObject({
2458
2459
  type: s.literal("tool-output-available"),
2459
2460
  toolCallId: s.string(),
2460
2461
  output: s.unknown(),
2461
2462
  providerExecuted: s.boolean().optional(),
2462
- providerMetadata: M.optional(),
2463
+ providerMetadata: T.optional(),
2463
2464
  toolMetadata: Ae.optional(),
2464
2465
  dynamic: s.boolean().optional(),
2465
2466
  preliminary: s.boolean().optional()
@@ -2469,7 +2470,7 @@ var Ae = s.record(
2469
2470
  toolCallId: s.string(),
2470
2471
  errorText: s.string(),
2471
2472
  providerExecuted: s.boolean().optional(),
2472
- providerMetadata: M.optional(),
2473
+ providerMetadata: T.optional(),
2473
2474
  toolMetadata: Ae.optional(),
2474
2475
  dynamic: s.boolean().optional()
2475
2476
  }),
@@ -2480,30 +2481,30 @@ var Ae = s.record(
2480
2481
  s.strictObject({
2481
2482
  type: s.literal("reasoning-start"),
2482
2483
  id: s.string(),
2483
- providerMetadata: M.optional()
2484
+ providerMetadata: T.optional()
2484
2485
  }),
2485
2486
  s.strictObject({
2486
2487
  type: s.literal("reasoning-delta"),
2487
2488
  id: s.string(),
2488
2489
  delta: s.string(),
2489
- providerMetadata: M.optional()
2490
+ providerMetadata: T.optional()
2490
2491
  }),
2491
2492
  s.strictObject({
2492
2493
  type: s.literal("reasoning-end"),
2493
2494
  id: s.string(),
2494
- providerMetadata: M.optional()
2495
+ providerMetadata: T.optional()
2495
2496
  }),
2496
2497
  s.strictObject({
2497
2498
  type: s.literal("custom"),
2498
2499
  kind: s.string().transform((e) => e),
2499
- providerMetadata: M.optional()
2500
+ providerMetadata: T.optional()
2500
2501
  }),
2501
2502
  s.strictObject({
2502
2503
  type: s.literal("source-url"),
2503
2504
  sourceId: s.string(),
2504
2505
  url: s.string(),
2505
2506
  title: s.string().optional(),
2506
- providerMetadata: M.optional()
2507
+ providerMetadata: T.optional()
2507
2508
  }),
2508
2509
  s.strictObject({
2509
2510
  type: s.literal("source-document"),
@@ -2511,19 +2512,19 @@ var Ae = s.record(
2511
2512
  mediaType: s.string(),
2512
2513
  title: s.string(),
2513
2514
  filename: s.string().optional(),
2514
- providerMetadata: M.optional()
2515
+ providerMetadata: T.optional()
2515
2516
  }),
2516
2517
  s.strictObject({
2517
2518
  type: s.literal("file"),
2518
2519
  url: s.string(),
2519
2520
  mediaType: s.string(),
2520
- providerMetadata: M.optional()
2521
+ providerMetadata: T.optional()
2521
2522
  }),
2522
2523
  s.strictObject({
2523
2524
  type: s.literal("reasoning-file"),
2524
2525
  url: s.string(),
2525
2526
  mediaType: s.string(),
2526
- providerMetadata: M.optional()
2527
+ providerMetadata: T.optional()
2527
2528
  }),
2528
2529
  s.strictObject({
2529
2530
  type: s.custom(
@@ -2618,8 +2619,8 @@ function Ts({
2618
2619
  new TransformStream({
2619
2620
  async transform(i, g) {
2620
2621
  await a(async ({ state: c, write: l }) => {
2621
- var p, v, h, T;
2622
- function A(d) {
2622
+ var p, v, h, A;
2623
+ function M(d) {
2623
2624
  const m = c.message.parts.filter(_e).find(
2624
2625
  (b) => b.toolCallId === d
2625
2626
  );
@@ -2631,7 +2632,7 @@ function Ts({
2631
2632
  });
2632
2633
  return m;
2633
2634
  }
2634
- function _(d) {
2635
+ function S(d) {
2635
2636
  const m = c.message.parts.filter(_e).find(
2636
2637
  (b) => {
2637
2638
  var y;
@@ -2646,7 +2647,7 @@ function Ts({
2646
2647
  });
2647
2648
  return m;
2648
2649
  }
2649
- function S(d) {
2650
+ function I(d) {
2650
2651
  var f;
2651
2652
  const m = c.message.parts.find(
2652
2653
  (w) => at(w) && w.toolCallId === d.toolCallId
@@ -2656,8 +2657,8 @@ function Ts({
2656
2657
  const w = b.providerMetadata;
2657
2658
  if (w != null)
2658
2659
  if (d.state === "output-available" || d.state === "output-error") {
2659
- const j = m;
2660
- j.resultProviderMetadata = w;
2660
+ const D = m;
2661
+ D.resultProviderMetadata = w;
2661
2662
  } else
2662
2663
  m.callProviderMetadata = w;
2663
2664
  } else
@@ -2677,20 +2678,20 @@ function Ts({
2677
2678
  ...b.providerMetadata != null && !(d.state === "output-available" || d.state === "output-error") ? { callProviderMetadata: b.providerMetadata } : {}
2678
2679
  });
2679
2680
  }
2680
- function I(d) {
2681
+ function _(d) {
2681
2682
  var f, m;
2682
2683
  const b = c.message.parts.find(
2683
- (j) => j.type === "dynamic-tool" && j.toolCallId === d.toolCallId
2684
+ (D) => D.type === "dynamic-tool" && D.toolCallId === d.toolCallId
2684
2685
  ), y = d, w = b;
2685
2686
  if (b != null) {
2686
2687
  b.state = d.state, w.toolName = d.toolName, w.input = y.input, w.output = y.output, w.errorText = y.errorText, w.rawInput = (f = y.rawInput) != null ? f : w.rawInput, w.preliminary = y.preliminary, d.title !== void 0 && (w.title = d.title), d.toolMetadata !== void 0 && (w.toolMetadata = d.toolMetadata), w.providerExecuted = (m = y.providerExecuted) != null ? m : b.providerExecuted;
2687
- const j = y.providerMetadata;
2688
- if (j != null)
2688
+ const D = y.providerMetadata;
2689
+ if (D != null)
2689
2690
  if (d.state === "output-available" || d.state === "output-error") {
2690
2691
  const se = b;
2691
- se.resultProviderMetadata = j;
2692
+ se.resultProviderMetadata = D;
2692
2693
  } else
2693
- b.callProviderMetadata = j;
2694
+ b.callProviderMetadata = D;
2694
2695
  } else
2695
2696
  c.message.parts.push({
2696
2697
  type: "dynamic-tool",
@@ -2792,7 +2793,7 @@ function Ts({
2792
2793
  chunkId: i.id,
2793
2794
  message: `Received reasoning-end for missing reasoning part with ID "${i.id}". Ensure a "reasoning-start" chunk is sent before any "reasoning-end" chunks.`
2794
2795
  });
2795
- d.providerMetadata = (T = i.providerMetadata) != null ? T : d.providerMetadata, d.state = "done", delete c.activeReasoningParts[i.id], l();
2796
+ d.providerMetadata = (A = i.providerMetadata) != null ? A : d.providerMetadata, d.state = "done", delete c.activeReasoningParts[i.id], l();
2796
2797
  break;
2797
2798
  }
2798
2799
  case "file":
@@ -2835,7 +2836,7 @@ function Ts({
2835
2836
  dynamic: i.dynamic,
2836
2837
  title: i.title,
2837
2838
  toolMetadata: i.toolMetadata
2838
- }, i.dynamic ? I({
2839
+ }, i.dynamic ? _({
2839
2840
  toolCallId: i.toolCallId,
2840
2841
  toolName: i.toolName,
2841
2842
  state: "input-streaming",
@@ -2844,7 +2845,7 @@ function Ts({
2844
2845
  title: i.title,
2845
2846
  toolMetadata: i.toolMetadata,
2846
2847
  providerMetadata: i.providerMetadata
2847
- }) : S({
2848
+ }) : I({
2848
2849
  toolCallId: i.toolCallId,
2849
2850
  toolName: i.toolName,
2850
2851
  state: "input-streaming",
@@ -2868,14 +2869,14 @@ function Ts({
2868
2869
  const { value: f } = await De(
2869
2870
  d.text
2870
2871
  );
2871
- d.dynamic ? I({
2872
+ d.dynamic ? _({
2872
2873
  toolCallId: i.toolCallId,
2873
2874
  toolName: d.toolName,
2874
2875
  state: "input-streaming",
2875
2876
  input: f,
2876
2877
  title: d.title,
2877
2878
  toolMetadata: d.toolMetadata
2878
- }) : S({
2879
+ }) : I({
2879
2880
  toolCallId: i.toolCallId,
2880
2881
  toolName: d.toolName,
2881
2882
  state: "input-streaming",
@@ -2886,7 +2887,7 @@ function Ts({
2886
2887
  break;
2887
2888
  }
2888
2889
  case "tool-input-available": {
2889
- i.dynamic ? I({
2890
+ i.dynamic ? _({
2890
2891
  toolCallId: i.toolCallId,
2891
2892
  toolName: i.toolName,
2892
2893
  state: "input-available",
@@ -2895,7 +2896,7 @@ function Ts({
2895
2896
  providerMetadata: i.providerMetadata,
2896
2897
  title: i.title,
2897
2898
  toolMetadata: i.toolMetadata
2898
- }) : S({
2899
+ }) : I({
2899
2900
  toolCallId: i.toolCallId,
2900
2901
  toolName: i.toolName,
2901
2902
  state: "input-available",
@@ -2911,7 +2912,7 @@ function Ts({
2911
2912
  }
2912
2913
  case "tool-input-error": {
2913
2914
  const d = c.message.parts.filter(_e).find((m) => m.toolCallId === i.toolCallId);
2914
- (d != null ? d.type === "dynamic-tool" : !!i.dynamic) ? I({
2915
+ (d != null ? d.type === "dynamic-tool" : !!i.dynamic) ? _({
2915
2916
  toolCallId: i.toolCallId,
2916
2917
  toolName: i.toolName,
2917
2918
  state: "output-error",
@@ -2920,7 +2921,7 @@ function Ts({
2920
2921
  providerExecuted: i.providerExecuted,
2921
2922
  providerMetadata: i.providerMetadata,
2922
2923
  toolMetadata: i.toolMetadata
2923
- }) : S({
2924
+ }) : I({
2924
2925
  toolCallId: i.toolCallId,
2925
2926
  toolName: i.toolName,
2926
2927
  state: "output-error",
@@ -2934,7 +2935,7 @@ function Ts({
2934
2935
  break;
2935
2936
  }
2936
2937
  case "tool-approval-request": {
2937
- const d = A(i.toolCallId);
2938
+ const d = M(i.toolCallId);
2938
2939
  d.state = "approval-requested", d.approval = {
2939
2940
  id: i.approvalId,
2940
2941
  ...i.isAutomatic === !0 ? { isAutomatic: !0 } : {},
@@ -2943,7 +2944,7 @@ function Ts({
2943
2944
  break;
2944
2945
  }
2945
2946
  case "tool-approval-response": {
2946
- const d = _(
2947
+ const d = S(
2947
2948
  i.approvalId
2948
2949
  ), f = d.approval == null ? { id: i.approvalId } : d.approval;
2949
2950
  d.state = "approval-responded", d.approval = {
@@ -2956,13 +2957,13 @@ function Ts({
2956
2957
  break;
2957
2958
  }
2958
2959
  case "tool-output-denied": {
2959
- const d = A(i.toolCallId);
2960
+ const d = M(i.toolCallId);
2960
2961
  d.state = "output-denied", l();
2961
2962
  break;
2962
2963
  }
2963
2964
  case "tool-output-available": {
2964
- const d = A(i.toolCallId);
2965
- d.type === "dynamic-tool" ? I({
2965
+ const d = M(i.toolCallId);
2966
+ d.type === "dynamic-tool" ? _({
2966
2967
  toolCallId: i.toolCallId,
2967
2968
  toolName: d.toolName,
2968
2969
  state: "output-available",
@@ -2973,7 +2974,7 @@ function Ts({
2973
2974
  providerMetadata: i.providerMetadata,
2974
2975
  title: d.title,
2975
2976
  toolMetadata: d.toolMetadata
2976
- }) : S({
2977
+ }) : I({
2977
2978
  toolCallId: i.toolCallId,
2978
2979
  toolName: st(d),
2979
2980
  state: "output-available",
@@ -2988,8 +2989,8 @@ function Ts({
2988
2989
  break;
2989
2990
  }
2990
2991
  case "tool-output-error": {
2991
- const d = A(i.toolCallId);
2992
- d.type === "dynamic-tool" ? I({
2992
+ const d = M(i.toolCallId);
2993
+ d.type === "dynamic-tool" ? _({
2993
2994
  toolCallId: i.toolCallId,
2994
2995
  toolName: d.toolName,
2995
2996
  state: "output-error",
@@ -2999,7 +3000,7 @@ function Ts({
2999
3000
  providerMetadata: i.providerMetadata,
3000
3001
  title: d.title,
3001
3002
  toolMetadata: d.toolMetadata
3002
- }) : S({
3003
+ }) : I({
3003
3004
  toolCallId: i.toolCallId,
3004
3005
  toolName: st(d),
3005
3006
  state: "output-error",
@@ -3198,30 +3199,30 @@ var Rs = class {
3198
3199
  requestMetadata: t.metadata,
3199
3200
  trigger: t.trigger,
3200
3201
  messageId: t.messageId
3201
- })), v = (a = p == null ? void 0 : p.api) != null ? a : this.api, h = (p == null ? void 0 : p.headers) !== void 0 ? Ee(p.headers) : l, T = (p == null ? void 0 : p.body) !== void 0 ? p.body : {
3202
+ })), v = (a = p == null ? void 0 : p.api) != null ? a : this.api, h = (p == null ? void 0 : p.headers) !== void 0 ? Ee(p.headers) : l, A = (p == null ? void 0 : p.body) !== void 0 ? p.body : {
3202
3203
  ...i,
3203
3204
  ...t.body,
3204
3205
  id: t.chatId,
3205
3206
  messages: t.messages,
3206
3207
  trigger: t.trigger,
3207
3208
  messageId: t.messageId
3208
- }, A = (n = p == null ? void 0 : p.credentials) != null ? n : c, S = await ((o = this.fetch) != null ? o : globalThis.fetch)(v, {
3209
+ }, M = (n = p == null ? void 0 : p.credentials) != null ? n : c, I = await ((o = this.fetch) != null ? o : globalThis.fetch)(v, {
3209
3210
  method: "POST",
3210
3211
  headers: {
3211
3212
  "Content-Type": "application/json",
3212
3213
  ...h
3213
3214
  },
3214
- body: JSON.stringify(T),
3215
- credentials: A,
3215
+ body: JSON.stringify(A),
3216
+ credentials: M,
3216
3217
  signal: e
3217
3218
  });
3218
- if (!S.ok)
3219
+ if (!I.ok)
3219
3220
  throw new Error(
3220
- (u = await S.text()) != null ? u : "Failed to fetch the chat response."
3221
+ (u = await I.text()) != null ? u : "Failed to fetch the chat response."
3221
3222
  );
3222
- if (!S.body)
3223
+ if (!I.body)
3223
3224
  throw new Error("The response body is empty.");
3224
- return this.processResponseStream(S.body);
3225
+ return this.processResponseStream(I.body);
3225
3226
  }
3226
3227
  async reconnectToStream(e) {
3227
3228
  var t, r, a, n, o;
@@ -3235,20 +3236,20 @@ var Rs = class {
3235
3236
  headers: c,
3236
3237
  credentials: g,
3237
3238
  requestMetadata: e.metadata
3238
- })), p = (r = l == null ? void 0 : l.api) != null ? r : `${this.api}/${e.chatId}/stream`, v = (l == null ? void 0 : l.headers) !== void 0 ? Ee(l.headers) : c, h = (a = l == null ? void 0 : l.credentials) != null ? a : g, A = await ((n = this.fetch) != null ? n : globalThis.fetch)(p, {
3239
+ })), p = (r = l == null ? void 0 : l.api) != null ? r : `${this.api}/${e.chatId}/stream`, v = (l == null ? void 0 : l.headers) !== void 0 ? Ee(l.headers) : c, h = (a = l == null ? void 0 : l.credentials) != null ? a : g, M = await ((n = this.fetch) != null ? n : globalThis.fetch)(p, {
3239
3240
  method: "GET",
3240
3241
  headers: v,
3241
3242
  credentials: h
3242
3243
  });
3243
- if (A.status === 204)
3244
+ if (M.status === 204)
3244
3245
  return null;
3245
- if (!A.ok)
3246
+ if (!M.ok)
3246
3247
  throw new Error(
3247
- (o = await A.text()) != null ? o : "Failed to fetch the chat response."
3248
+ (o = await M.text()) != null ? o : "Failed to fetch the chat response."
3248
3249
  );
3249
- if (!A.body)
3250
+ if (!M.body)
3250
3251
  throw new Error("The response body is empty.");
3251
- return this.processResponseStream(A.body);
3252
+ return this.processResponseStream(M.body);
3252
3253
  }
3253
3254
  }, dt = class extends Rs {
3254
3255
  constructor(e = {}) {
@@ -3283,7 +3284,7 @@ var Rs = class {
3283
3284
  sendAutomaticallyWhen: l
3284
3285
  }) {
3285
3286
  this.activeResponse = void 0, this.jobExecutor = new Cs(), this.sendMessage = async (p, v) => {
3286
- var h, T, A, _;
3287
+ var h, A, M, S;
3287
3288
  if (p == null) {
3288
3289
  await this.makeRequest({
3289
3290
  trigger: "submit-message",
@@ -3292,33 +3293,33 @@ var Rs = class {
3292
3293
  });
3293
3294
  return;
3294
3295
  }
3295
- let S;
3296
- if ("text" in p || "files" in p ? S = {
3296
+ let I;
3297
+ if ("text" in p || "files" in p ? I = {
3297
3298
  parts: [
3298
3299
  ...Array.isArray(p.files) ? p.files : await xs(p.files),
3299
3300
  ..."text" in p && p.text != null ? [{ type: "text", text: p.text }] : []
3300
3301
  ]
3301
- } : S = p, p.messageId != null) {
3302
- const I = this.state.messages.findIndex(
3302
+ } : I = p, p.messageId != null) {
3303
+ const _ = this.state.messages.findIndex(
3303
3304
  (R) => R.id === p.messageId
3304
3305
  );
3305
- if (I === -1)
3306
+ if (_ === -1)
3306
3307
  throw new Error(`message with id ${p.messageId} not found`);
3307
- if (this.state.messages[I].role !== "user")
3308
+ if (this.state.messages[_].role !== "user")
3308
3309
  throw new Error(
3309
3310
  `message with id ${p.messageId} is not a user message`
3310
3311
  );
3311
- this.state.messages = this.state.messages.slice(0, I + 1), this.state.replaceMessage(I, {
3312
- ...S,
3312
+ this.state.messages = this.state.messages.slice(0, _ + 1), this.state.replaceMessage(_, {
3313
+ ...I,
3313
3314
  id: p.messageId,
3314
- role: (T = S.role) != null ? T : "user",
3315
+ role: (A = I.role) != null ? A : "user",
3315
3316
  metadata: p.metadata
3316
3317
  });
3317
3318
  } else
3318
3319
  this.state.pushMessage({
3319
- ...S,
3320
- id: (A = S.id) != null ? A : this.generateId(),
3321
- role: (_ = S.role) != null ? _ : "user",
3320
+ ...I,
3321
+ id: (M = I.id) != null ? M : this.generateId(),
3322
+ role: (S = I.role) != null ? S : "user",
3322
3323
  metadata: p.metadata
3323
3324
  });
3324
3325
  await this.makeRequest({
@@ -3330,7 +3331,7 @@ var Rs = class {
3330
3331
  messageId: p,
3331
3332
  ...v
3332
3333
  } = {}) => {
3333
- const h = p == null ? this.state.messages.length - 1 : this.state.messages.findIndex((T) => T.id === p);
3334
+ const h = p == null ? this.state.messages.length - 1 : this.state.messages.findIndex((A) => A.id === p);
3334
3335
  if (h === -1)
3335
3336
  throw new Error(`message ${p} not found`);
3336
3337
  this.state.messages = this.state.messages.slice(
@@ -3350,41 +3351,41 @@ var Rs = class {
3350
3351
  id: p,
3351
3352
  approved: v,
3352
3353
  reason: h,
3353
- options: T
3354
+ options: A
3354
3355
  }) => this.jobExecutor.run(async () => {
3355
- const A = this.state.messages, _ = A[A.length - 1], S = (I) => _e(I) && I.state === "approval-requested" && I.approval.id === p ? {
3356
- ...I,
3357
- state: "approval-responded",
3358
- approval: { ...I.approval, id: p, approved: v, reason: h }
3359
- } : I;
3360
- this.state.replaceMessage(A.length - 1, {
3356
+ const M = this.state.messages, S = M[M.length - 1], I = (_) => _e(_) && _.state === "approval-requested" && _.approval.id === p ? {
3361
3357
  ..._,
3362
- parts: _.parts.map(S)
3363
- }), this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(S)), this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen && this.shouldSendAutomatically().then((I) => {
3358
+ state: "approval-responded",
3359
+ approval: { ..._.approval, id: p, approved: v, reason: h }
3360
+ } : _;
3361
+ this.state.replaceMessage(M.length - 1, {
3362
+ ...S,
3363
+ parts: S.parts.map(I)
3364
+ }), this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(I)), this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen && this.shouldSendAutomatically().then((_) => {
3364
3365
  var R;
3365
- I && this.makeRequest({
3366
+ _ && this.makeRequest({
3366
3367
  trigger: "submit-message",
3367
3368
  messageId: (R = this.lastMessage) == null ? void 0 : R.id,
3368
- ...T
3369
+ ...A
3369
3370
  });
3370
3371
  });
3371
3372
  }), this.addToolOutput = async ({
3372
3373
  state: p = "output-available",
3373
3374
  toolCallId: v,
3374
3375
  output: h,
3375
- errorText: T,
3376
- options: A
3376
+ errorText: A,
3377
+ options: M
3377
3378
  }) => this.jobExecutor.run(async () => {
3378
- const _ = this.state.messages, S = _[_.length - 1], I = (R) => _e(R) && R.toolCallId === v ? { ...R, state: p, output: h, errorText: T } : R;
3379
- this.state.replaceMessage(_.length - 1, {
3380
- ...S,
3381
- parts: S.parts.map(I)
3382
- }), this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(I)), this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen && this.shouldSendAutomatically().then((R) => {
3379
+ const S = this.state.messages, I = S[S.length - 1], _ = (R) => _e(R) && R.toolCallId === v ? { ...R, state: p, output: h, errorText: A } : R;
3380
+ this.state.replaceMessage(S.length - 1, {
3381
+ ...I,
3382
+ parts: I.parts.map(_)
3383
+ }), this.activeResponse && (this.activeResponse.state.message.parts = this.activeResponse.state.message.parts.map(_)), this.status !== "streaming" && this.status !== "submitted" && this.sendAutomaticallyWhen && this.shouldSendAutomatically().then((R) => {
3383
3384
  var d;
3384
3385
  R && this.makeRequest({
3385
3386
  trigger: "submit-message",
3386
3387
  messageId: (d = this.lastMessage) == null ? void 0 : d.id,
3387
- ...A
3388
+ ...M
3388
3389
  });
3389
3390
  });
3390
3391
  }), this.addToolResult = this.addToolOutput, this.stop = async () => {
@@ -3467,8 +3468,8 @@ var Rs = class {
3467
3468
  v = h, h.abortController.signal.addEventListener("abort", () => {
3468
3469
  c = !0;
3469
3470
  }), this.activeResponse = h;
3470
- let T;
3471
- e === "resume-stream" ? T = i : T = await this.transport.sendMessages({
3471
+ let A;
3472
+ e === "resume-stream" ? A = i : A = await this.transport.sendMessages({
3472
3473
  chatId: this.id,
3473
3474
  messages: this.state.messages,
3474
3475
  abortSignal: h.abortController.signal,
@@ -3478,14 +3479,14 @@ var Rs = class {
3478
3479
  trigger: e,
3479
3480
  messageId: n
3480
3481
  });
3481
- const A = (_) => (
3482
+ const M = (S) => (
3482
3483
  // serialize the job execution to avoid race conditions:
3483
3484
  this.jobExecutor.run(
3484
- () => _({
3485
+ () => S({
3485
3486
  state: h.state,
3486
3487
  write: () => {
3487
- var S;
3488
- this.setStatus({ status: "streaming" }), h.state.message.id === ((S = this.lastMessage) == null ? void 0 : S.id) ? this.state.replaceMessage(
3488
+ var I;
3489
+ this.setStatus({ status: "streaming" }), h.state.message.id === ((I = this.lastMessage) == null ? void 0 : I.id) ? this.state.replaceMessage(
3489
3490
  this.state.messages.length - 1,
3490
3491
  h.state.message
3491
3492
  ) : this.state.pushMessage(h.state.message);
@@ -3495,18 +3496,18 @@ var Rs = class {
3495
3496
  );
3496
3497
  await As({
3497
3498
  stream: Ts({
3498
- stream: T,
3499
+ stream: A,
3499
3500
  onToolCall: this.onToolCall,
3500
3501
  onData: this.onData,
3501
3502
  messageMetadataSchema: this.messageMetadataSchema,
3502
3503
  dataPartSchemas: this.dataPartSchemas,
3503
- runUpdateMessageJob: A,
3504
- onError: (_) => {
3505
- throw _;
3504
+ runUpdateMessageJob: M,
3505
+ onError: (S) => {
3506
+ throw S;
3506
3507
  }
3507
3508
  }),
3508
- onError: (_) => {
3509
- throw _;
3509
+ onError: (S) => {
3510
+ throw S;
3510
3511
  }
3511
3512
  }), this.setStatus({ status: "ready" });
3512
3513
  } catch (h) {
@@ -3633,7 +3634,7 @@ function Fs({
3633
3634
  resume: r = !1,
3634
3635
  ...a
3635
3636
  } = {}) {
3636
- const n = e ?? t, o = D({});
3637
+ const n = e ?? t, o = j({});
3637
3638
  "chat" in a || (o.current = {
3638
3639
  onToolCall: a.onToolCall,
3639
3640
  onData: a.onData,
@@ -3644,40 +3645,40 @@ function Fs({
3644
3645
  });
3645
3646
  let u;
3646
3647
  const i = () => {
3647
- var _;
3648
- return (_ = o.current.transport) != null ? _ : u ?? (u = new dt());
3648
+ var S;
3649
+ return (S = o.current.transport) != null ? S : u ?? (u = new dt());
3649
3650
  }, g = {
3650
3651
  ...a,
3651
3652
  transport: {
3652
- sendMessages: (_) => i().sendMessages(_),
3653
- reconnectToStream: (_) => i().reconnectToStream(_)
3653
+ sendMessages: (S) => i().sendMessages(S),
3654
+ reconnectToStream: (S) => i().reconnectToStream(S)
3654
3655
  },
3655
- onToolCall: (_) => {
3656
- var S, I;
3657
- return (I = (S = o.current).onToolCall) == null ? void 0 : I.call(S, _);
3656
+ onToolCall: (S) => {
3657
+ var I, _;
3658
+ return (_ = (I = o.current).onToolCall) == null ? void 0 : _.call(I, S);
3658
3659
  },
3659
- onData: (_) => {
3660
- var S, I;
3661
- return (I = (S = o.current).onData) == null ? void 0 : I.call(S, _);
3660
+ onData: (S) => {
3661
+ var I, _;
3662
+ return (_ = (I = o.current).onData) == null ? void 0 : _.call(I, S);
3662
3663
  },
3663
- onFinish: (_) => {
3664
- var S, I;
3665
- return (I = (S = o.current).onFinish) == null ? void 0 : I.call(S, _);
3664
+ onFinish: (S) => {
3665
+ var I, _;
3666
+ return (_ = (I = o.current).onFinish) == null ? void 0 : _.call(I, S);
3666
3667
  },
3667
- onError: (_) => {
3668
- var S, I;
3669
- return (I = (S = o.current).onError) == null ? void 0 : I.call(S, _);
3668
+ onError: (S) => {
3669
+ var I, _;
3670
+ return (_ = (I = o.current).onError) == null ? void 0 : _.call(I, S);
3670
3671
  },
3671
- sendAutomaticallyWhen: (_) => {
3672
- var S, I, R;
3673
- return (R = (I = (S = o.current).sendAutomaticallyWhen) == null ? void 0 : I.call(S, _)) != null ? R : !1;
3672
+ sendAutomaticallyWhen: (S) => {
3673
+ var I, _, R;
3674
+ return (R = (_ = (I = o.current).sendAutomaticallyWhen) == null ? void 0 : _.call(I, S)) != null ? R : !1;
3674
3675
  }
3675
- }, c = D(
3676
+ }, c = j(
3676
3677
  "chat" in a ? a.chat : new Lt(g)
3677
3678
  );
3678
3679
  ("chat" in a && a.chat !== c.current || "id" in a && a.id != null && c.current.id !== a.id) && (c.current = "chat" in a ? a.chat : new Lt(g));
3679
3680
  const p = U(
3680
- (_) => c.current["~registerMessagesCallback"](_, n),
3681
+ (S) => c.current["~registerMessagesCallback"](S, n),
3681
3682
  // `chatRef.current.id` is required to trigger re-subscription when the chat ID changes
3682
3683
  // eslint-disable-next-line react-hooks/exhaustive-deps
3683
3684
  [n, c.current.id]
@@ -3689,13 +3690,13 @@ function Fs({
3689
3690
  c.current["~registerStatusCallback"],
3690
3691
  () => c.current.status,
3691
3692
  () => c.current.status
3692
- ), T = Oe(
3693
+ ), A = Oe(
3693
3694
  c.current["~registerErrorCallback"],
3694
3695
  () => c.current.error,
3695
3696
  () => c.current.error
3696
- ), A = U(
3697
- (_) => {
3698
- typeof _ == "function" && (_ = _(c.current.messages)), c.current.messages = _;
3697
+ ), M = U(
3698
+ (S) => {
3699
+ typeof S == "function" && (S = S(c.current.messages)), c.current.messages = S;
3699
3700
  },
3700
3701
  [c]
3701
3702
  );
@@ -3704,12 +3705,12 @@ function Fs({
3704
3705
  }, [r, c]), {
3705
3706
  id: c.current.id,
3706
3707
  messages: v,
3707
- setMessages: A,
3708
+ setMessages: M,
3708
3709
  sendMessage: c.current.sendMessage,
3709
3710
  regenerate: c.current.regenerate,
3710
3711
  clearError: c.current.clearError,
3711
3712
  stop: c.current.stop,
3712
- error: T,
3713
+ error: A,
3713
3714
  resumeStream: c.current.resumeStream,
3714
3715
  status: h,
3715
3716
  /**
@@ -3975,7 +3976,7 @@ function sn({
3975
3976
  sessionId: r,
3976
3977
  persistedMessages: a
3977
3978
  }) {
3978
- const { api: n, messageCtx: o } = e, u = D(t);
3979
+ const { api: n, messageCtx: o } = e, u = j(t);
3979
3980
  u.current = t;
3980
3981
  const { pageContext: i, clientTools: g } = e.features, c = X(
3981
3982
  () => Hs({
@@ -3988,9 +3989,9 @@ function sn({
3988
3989
  messages: p,
3989
3990
  sendMessage: v,
3990
3991
  stop: h,
3991
- error: T,
3992
- clearError: A,
3993
- resumeStream: _
3992
+ error: A,
3993
+ clearError: M,
3994
+ resumeStream: S
3994
3995
  } = Fs({
3995
3996
  id: r ?? void 0,
3996
3997
  // Reattach to a still-live turn (reload, tab switch) — but only once a
@@ -4004,11 +4005,11 @@ function sn({
4004
4005
  // replies inside customer pages.
4005
4006
  throttle: 50,
4006
4007
  onError: (E) => q.error("agent chat stream error", E)
4007
- }), S = D(p);
4008
- S.current = p;
4009
- const I = D(new Ft(qt)), R = D("idle"), d = D(Promise.resolve()), f = D(0), [m, b] = Z(0), [y, w] = Z(!1), [j, se] = Z([]), [Be, We] = Z(null), Y = D(null), ee = U((E) => {
4008
+ }), I = j(p);
4009
+ I.current = p;
4010
+ const _ = j(new Ft(qt)), R = j("idle"), d = j(Promise.resolve()), f = j(0), [m, b] = Z(0), [y, w] = Z(!1), [D, se] = Z([]), [Be, We] = Z(null), Y = j(null), ee = U((E) => {
4010
4011
  Y.current = E, We(E);
4011
- }, []), Me = D(null), ye = D(null), be = D(l), ft = D(r), Ve = D(null), Je = D(null), mt = D(h), pe = D(l);
4012
+ }, []), Me = j(null), ye = j(null), be = j(l), ft = j(r), Ve = j(null), Je = j(null), mt = j(h), pe = j(l);
4012
4013
  pe.current = l;
4013
4014
  const Le = U((E, x) => {
4014
4015
  const O = en(E.parts);
@@ -4064,7 +4065,7 @@ function sn({
4064
4065
  q.error("agent chat steer fallback: client stop failed", F);
4065
4066
  }
4066
4067
  if (x !== f.current) return;
4067
- _();
4068
+ S();
4068
4069
  return;
4069
4070
  case "failed":
4070
4071
  q.error("agent chat steer: the turn failed", {
@@ -4080,8 +4081,8 @@ function sn({
4080
4081
  });
4081
4082
  }
4082
4083
  },
4083
- [c, Fe, o, h, _, e]
4084
- ), vt = D(gt);
4084
+ [c, Fe, o, h, S, e]
4085
+ ), vt = j(gt);
4085
4086
  vt.current = gt, $(() => {
4086
4087
  const E = mt.current;
4087
4088
  mt.current = h;
@@ -4092,10 +4093,10 @@ function sn({
4092
4093
  return;
4093
4094
  }
4094
4095
  const O = pe.current === "submitted" || pe.current === "streaming" || be.current === "submitted" || be.current === "streaming" || R.current === "in-flight";
4095
- f.current += 1, d.current = Promise.resolve(), I.current = new Ft(qt), R.current = "idle", ye.current = null, Me.current = null, Je.current = null, Ve.current = l === "submitted" || l === "streaming" ? l : null, be.current = "ready", pe.current = "ready", A(), b((L) => L + 1), w(!1), se([]), ee(null), O && Promise.resolve().then(() => E()).catch((L) => {
4096
+ f.current += 1, d.current = Promise.resolve(), _.current = new Ft(qt), R.current = "idle", ye.current = null, Me.current = null, Je.current = null, Ve.current = l === "submitted" || l === "streaming" ? l : null, be.current = "ready", pe.current = "ready", M(), b((L) => L + 1), w(!1), se([]), ee(null), O && Promise.resolve().then(() => E()).catch((L) => {
4096
4097
  q.error("agent chat client stream cancel failed", L);
4097
4098
  });
4098
- }, [r, l, h, A, ee]), $(() => {
4099
+ }, [r, l, h, M, ee]), $(() => {
4099
4100
  var F, Te;
4100
4101
  const E = Ve.current;
4101
4102
  if (E !== null && l === E) {
@@ -4112,7 +4113,7 @@ function sn({
4112
4113
  if (l !== "ready" && l !== "error") return;
4113
4114
  if (x === "streaming" || x === "submitted") {
4114
4115
  R.current === "in-flight" && (R.current = "idle");
4115
- const H = S.current.at(-1), ne = Y.current;
4116
+ const H = I.current.at(-1), ne = Y.current;
4116
4117
  if (Me.current = ne, ne !== null && H && H.role === "assistant" && Le(H, ne), l === "ready") {
4117
4118
  const ie = (Te = ye.current) == null ? void 0 : Te.userMessage.id;
4118
4119
  ie && o.markUserMessageDelivered(ie);
@@ -4124,7 +4125,7 @@ function sn({
4124
4125
  })) : w(!1));
4125
4126
  }
4126
4127
  if (R.current !== "idle" || !r) return;
4127
- const L = I.current.dequeueNext();
4128
+ const L = _.current.dequeueNext();
4128
4129
  L && (R.current = "in-flight", ye.current = L, ee(`turn-${L.userMessage.id}`), o.appendUserMessageIfAbsent(L.userMessage), b((H) => H + 1), v(
4129
4130
  { text: L.userMessage.content },
4130
4131
  { body: Fe(L) }
@@ -4145,14 +4146,14 @@ function sn({
4145
4146
  const x = f.current, O = d.current.then(
4146
4147
  async () => {
4147
4148
  if (x !== f.current) return;
4148
- const L = R.current, F = pe.current === "streaming" && L !== "stopping" && L !== "reconciling" && I.current.size === 0, H = pe.current === "submitted" || pe.current === "streaming" || L !== "idle" || I.current.size > 0 ? nn(o.buildQueuedUserMessage(E)) : await o.stageUserTurn(E, { pending: !0 });
4149
+ const L = R.current, F = pe.current === "streaming" && L !== "stopping" && L !== "reconciling" && _.current.size === 0, H = pe.current === "submitted" || pe.current === "streaming" || L !== "idle" || _.current.size > 0 ? nn(o.buildQueuedUserMessage(E)) : await o.stageUserTurn(E, { pending: !0 });
4149
4150
  if (!H || x !== f.current) return;
4150
4151
  const ne = { ...H, input: E };
4151
4152
  if (F) {
4152
4153
  o.appendUserMessageIfAbsent(ne.userMessage), o.notifySendAccepted(E), vt.current(ne);
4153
4154
  return;
4154
4155
  }
4155
- if (!I.current.enqueue(ne)) {
4156
+ if (!_.current.enqueue(ne)) {
4156
4157
  q.warn("agent chat queue full; rejecting newest send", {
4157
4158
  rejectedMessageId: ne.userMessage.id
4158
4159
  });
@@ -4172,16 +4173,16 @@ function sn({
4172
4173
  ), wr = U(() => {
4173
4174
  const E = ye.current;
4174
4175
  if (!E) return;
4175
- if (!I.current.enqueue({
4176
+ if (!_.current.enqueue({
4176
4177
  ...E,
4177
4178
  retryUuid: yt()
4178
4179
  })) {
4179
4180
  q.warn("agent chat queue full; retry not enqueued");
4180
4181
  return;
4181
4182
  }
4182
- A(), b((O) => O + 1);
4183
- }, [A]), Mr = U((E) => {
4184
- I.current.removeWhere(
4183
+ M(), b((O) => O + 1);
4184
+ }, [M]), Mr = U((E) => {
4185
+ _.current.removeWhere(
4185
4186
  (O) => O.userMessage.id === E
4186
4187
  ) && b((O) => O + 1);
4187
4188
  }, []), Tr = U(() => {
@@ -4243,12 +4244,12 @@ function sn({
4243
4244
  x && x.role === "assistant" && Le(x, E);
4244
4245
  }, [p, ae, Le]), $(() => {
4245
4246
  const E = () => {
4246
- document.visibilityState === "visible" && r && (ae || T === void 0 && !y || _());
4247
+ document.visibilityState === "visible" && r && (ae || A === void 0 && !y || S());
4247
4248
  };
4248
4249
  return document.addEventListener("visibilitychange", E), window.addEventListener("online", E), () => {
4249
4250
  document.removeEventListener("visibilitychange", E), window.removeEventListener("online", E);
4250
4251
  };
4251
- }, [r, ae, y, T, _]), $(() => {
4252
+ }, [r, ae, y, A, S]), $(() => {
4252
4253
  if (!(ae || !y))
4253
4254
  for (let E = a.length - 1; E >= 0; E -= 1) {
4254
4255
  const x = a[E];
@@ -4266,7 +4267,7 @@ function sn({
4266
4267
  const E = p.at(-1);
4267
4268
  return !E || E.role !== "assistant" ? [] : ot(E.parts);
4268
4269
  }, [p, ae, y]), xr = X(
4269
- () => I.current.items.map((E) => E.userMessage),
4270
+ () => _.current.items.map((E) => E.userMessage),
4270
4271
  // eslint-disable-next-line react-hooks/exhaustive-deps -- queueRef is mutable; queueVersion is the signal
4271
4272
  [m]
4272
4273
  );
@@ -4274,11 +4275,11 @@ function sn({
4274
4275
  isStreaming: ae,
4275
4276
  liveItems: Cr,
4276
4277
  /** Finished turns' render sources — see `TurnRenderSource`. */
4277
- turnSources: j,
4278
+ turnSources: D,
4278
4279
  /** The live turn's node key (stable through the retained promotion). */
4279
4280
  liveTurnKey: Be,
4280
4281
  /** The last turn failed — the transcript renders a visible error row. */
4281
- turnFailed: T !== void 0,
4282
+ turnFailed: A !== void 0,
4282
4283
  retryFailedTurn: wr,
4283
4284
  queuedUserMessages: xr,
4284
4285
  removeQueued: Mr,
@@ -4313,7 +4314,7 @@ function ln({
4313
4314
  widgetCtx: t,
4314
4315
  config: r
4315
4316
  }) {
4316
- var S, I;
4317
+ var I, _;
4317
4318
  const a = de(t.sessionCtx.sessionState), n = de(t.messageCtx.state), {
4318
4319
  isStreaming: o,
4319
4320
  liveItems: u,
@@ -4324,13 +4325,13 @@ function ln({
4324
4325
  queuedUserMessages: p,
4325
4326
  removeQueued: v,
4326
4327
  stop: h,
4327
- pageEffects: T
4328
+ pageEffects: A
4328
4329
  } = sn({
4329
4330
  widgetCtx: t,
4330
4331
  config: r,
4331
- sessionId: ((S = a.session) == null ? void 0 : S.id) ?? null,
4332
+ sessionId: ((I = a.session) == null ? void 0 : I.id) ?? null,
4332
4333
  persistedMessages: n.messages
4333
- }), A = ((I = n.messages.at(-1)) == null ? void 0 : I.type) === "USER", _ = X(
4334
+ }), M = ((_ = n.messages.at(-1)) == null ? void 0 : _.type) === "USER", S = X(
4334
4335
  () => ({
4335
4336
  isStreaming: o,
4336
4337
  liveItems: u,
@@ -4341,12 +4342,12 @@ function ln({
4341
4342
  queuedUserMessages: p,
4342
4343
  removeQueued: v,
4343
4344
  stop: h,
4344
- pageEffects: T,
4345
+ pageEffects: A,
4345
4346
  pendingClarification: qr({
4346
4347
  turnSources: i,
4347
4348
  liveItems: u,
4348
4349
  isStreaming: o,
4349
- lastMessageIsFromUser: A
4350
+ lastMessageIsFromUser: M
4350
4351
  })
4351
4352
  }),
4352
4353
  [
@@ -4359,11 +4360,11 @@ function ln({
4359
4360
  p,
4360
4361
  v,
4361
4362
  h,
4362
- T,
4363
- A
4363
+ A,
4364
+ M
4364
4365
  ]
4365
4366
  );
4366
- return /* @__PURE__ */ V.createElement(pt.Provider, { value: _ }, e);
4367
+ return /* @__PURE__ */ V.createElement(pt.Provider, { value: S }, e);
4367
4368
  }
4368
4369
  function un({
4369
4370
  children: e,
@@ -4381,44 +4382,50 @@ function wn({
4381
4382
  loadingComponent: n,
4382
4383
  errorComponent: o
4383
4384
  }) {
4384
- const u = D(null), i = D(null), [g, c] = Z({ status: "loading" }), l = X(
4385
+ const u = j(e);
4386
+ u.current = e;
4387
+ const i = j(null), g = j(null), [c, l] = Z({ status: "loading" }), p = X(
4385
4388
  () => new Ur({
4386
4389
  components: r
4387
4390
  }),
4388
4391
  [r]
4389
4392
  );
4390
4393
  if ($(() => {
4391
- const v = i.current ?? (i.current = Nr.initialize({ config: e, storage: a }));
4392
- let h = !0;
4393
- return v.then(
4394
- (T) => {
4395
- h && c({ status: "ready", widgetCtx: T });
4394
+ const h = g.current ?? (g.current = Nr.initialize({
4395
+ config: e,
4396
+ storage: a,
4397
+ getClientCapabilities: () => u.current.capabilities
4398
+ }));
4399
+ let A = !0;
4400
+ return h.then(
4401
+ (M) => {
4402
+ A && l({ status: "ready", widgetCtx: M });
4396
4403
  },
4397
- (T) => {
4398
- const A = T instanceof Error ? T : new Error("Widget initialization failed", { cause: T });
4399
- q.error("widget initialization failed", A), h && c({ status: "error", error: A });
4404
+ (M) => {
4405
+ const S = M instanceof Error ? M : new Error("Widget initialization failed", { cause: M });
4406
+ q.error("widget initialization failed", S), A && l({ status: "error", error: S });
4400
4407
  }
4401
4408
  ), () => {
4402
- h = !1;
4409
+ A = !1;
4403
4410
  };
4404
- }, []), g.status === "loading")
4411
+ }, []), c.status === "loading")
4405
4412
  return n ? /* @__PURE__ */ V.createElement(V.Fragment, null, n) : null;
4406
- if (g.status === "error")
4407
- return o ? /* @__PURE__ */ V.createElement(V.Fragment, null, o(g.error)) : null;
4408
- const { widgetCtx: p } = g;
4413
+ if (c.status === "error")
4414
+ return o ? /* @__PURE__ */ V.createElement(V.Fragment, null, o(c.error)) : null;
4415
+ const { widgetCtx: v } = c;
4409
4416
  return /* @__PURE__ */ V.createElement(
4410
4417
  hr.Provider,
4411
4418
  {
4412
4419
  value: {
4413
- widgetCtx: p,
4420
+ widgetCtx: v,
4414
4421
  config: e,
4415
4422
  components: r,
4416
- componentStore: l,
4423
+ componentStore: p,
4417
4424
  version: $r,
4418
- contentIframeRef: u
4425
+ contentIframeRef: i
4419
4426
  }
4420
4427
  },
4421
- /* @__PURE__ */ V.createElement(un, { widgetCtx: p, config: e }, t)
4428
+ /* @__PURE__ */ V.createElement(un, { widgetCtx: v, config: e }, t)
4422
4429
  );
4423
4430
  }
4424
4431
  function K() {
@@ -4575,7 +4582,7 @@ function On() {
4575
4582
  try {
4576
4583
  t(
4577
4584
  (h) => h.map(
4578
- (T) => T.id === l.id ? { ...T, status: "uploading", progress: 0 } : T
4585
+ (A) => A.id === l.id ? { ...A, status: "uploading", progress: 0 } : A
4579
4586
  )
4580
4587
  );
4581
4588
  const v = await r.uploadFile({
@@ -4685,29 +4692,29 @@ function gn({
4685
4692
  (p.defaultLayout !== i || p.allowedLayoutsKey !== g) && (v({ defaultLayout: i, allowedLayoutsKey: g }), (p.defaultLayout !== i || !u.includes(c)) && l(i));
4686
4693
  const h = (y) => {
4687
4694
  l((w) => {
4688
- const j = typeof y == "function" ? y(w) : y;
4689
- return u.includes(j) ? j : w;
4695
+ const D = typeof y == "function" ? y(w) : y;
4696
+ return u.includes(D) ? D : w;
4690
4697
  });
4691
- }, T = D(u);
4692
- T.current = u;
4693
- const A = (y) => {
4694
- h(y), T.current.includes(y) && mn(y) && (n == null || n.setCompanionLayout(y).catch(() => {
4698
+ }, A = j(u);
4699
+ A.current = u;
4700
+ const M = (y) => {
4701
+ h(y), A.current.includes(y) && mn(y) && (n == null || n.setCompanionLayout(y).catch(() => {
4695
4702
  }));
4696
- }, [_, S] = Z(r), [I, R] = Z(a), [d, f] = Z({
4703
+ }, [S, I] = Z(r), [_, R] = Z(a), [d, f] = Z({
4697
4704
  side: r,
4698
4705
  mode: a
4699
4706
  });
4700
4707
  (d.side !== r || d.mode !== a) && (f({
4701
4708
  side: r,
4702
4709
  mode: a
4703
- }), d.side !== r && S(r), d.mode !== a && R(a)), $(() => {
4710
+ }), d.side !== r && I(r), d.mode !== a && R(a)), $(() => {
4704
4711
  if (!n) return;
4705
4712
  let y = !1;
4706
4713
  return n.getCompanionLayout().then((w) => {
4707
- y || !w || T.current.includes(w) && l(w);
4714
+ y || !w || A.current.includes(w) && l(w);
4708
4715
  }).catch(() => {
4709
4716
  }), n.getCompanionSidebarSide().then((w) => {
4710
- !y && w && S(w);
4717
+ !y && w && I(w);
4711
4718
  }).catch(() => {
4712
4719
  }), n.getCompanionSidebarMode().then((w) => {
4713
4720
  !y && w && R(w);
@@ -4718,7 +4725,7 @@ function gn({
4718
4725
  }, [n]);
4719
4726
  const m = U(
4720
4727
  (y) => {
4721
- S(y), n == null || n.setCompanionSidebarSide(y).catch(() => {
4728
+ I(y), n == null || n.setCompanionSidebarSide(y).catch(() => {
4722
4729
  });
4723
4730
  },
4724
4731
  [n]
@@ -4735,12 +4742,12 @@ function gn({
4735
4742
  value: {
4736
4743
  layout: c,
4737
4744
  setLayout: h,
4738
- setLayoutPreference: A,
4745
+ setLayoutPreference: M,
4739
4746
  allowedLayouts: u,
4740
4747
  defaultLayout: i,
4741
- sidebarSide: _,
4748
+ sidebarSide: S,
4742
4749
  setSidebarSide: m,
4743
- sidebarMode: I,
4750
+ sidebarMode: _,
4744
4751
  setSidebarMode: b
4745
4752
  }
4746
4753
  },
@@ -4811,7 +4818,7 @@ function Fn() {
4811
4818
  };
4812
4819
  }
4813
4820
  function kn(e) {
4814
- const { widgetCtx: t } = K(), r = t.dictationCtx, a = de(r.state), n = D(e);
4821
+ const { widgetCtx: t } = K(), r = t.dictationCtx, a = de(r.state), n = j(e);
4815
4822
  n.current = e;
4816
4823
  const o = U(() => {
4817
4824
  r.start({