@automattic/agenttic-client 0.1.68 → 0.1.69

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,10 +1,10 @@
1
- var Ge = Object.defineProperty;
2
- var Qe = (e, s, t) => s in e ? Ge(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
3
- var ce = (e, s, t) => Qe(e, typeof s != "symbol" ? s + "" : s, t);
1
+ var Qe = Object.defineProperty;
2
+ var Ge = (e, s, t) => s in e ? Qe(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
3
+ var ce = (e, s, t) => Ge(e, typeof s != "symbol" ? s + "" : s, t);
4
4
  import Xe, { useMemo as _e, useCallback as D, useState as Ee, useRef as ue, useEffect as ae } from "react";
5
5
  import { l as v, f as Ne, a as z } from "./logger-aKHbTlwk.js";
6
6
  import Se from "@wordpress/api-fetch";
7
- import { m as ws, l as Ms, i as Ts, j as As, k as vs, h as Ss, f as Cs, o as xs, g as bs, n as Rs, a as ks, d as Ps, e as _s, b as Es, c as Ns, r as Hs, u as Os } from "./useAgentsApiChat-cj7ngIA5.js";
7
+ import { m as ws, l as Ms, i as Ts, j as As, k as vs, h as Ss, f as Cs, o as xs, q as bs, s as Rs, g as ks, n as Ps, a as _s, d as Es, p as Ns, e as Hs, b as Os, c as Us, r as $s, u as qs } from "./useAgentsApiChat-BK33Zwmv.js";
8
8
  function ns(e) {
9
9
  return _e(() => e ? {
10
10
  getClientContext: () => {
@@ -326,8 +326,8 @@ async function* lt(e, s = {}) {
326
326
  let l = null, i = null;
327
327
  try {
328
328
  for (; ; ) {
329
- const { done: d, value: A } = await a.read();
330
- if (d)
329
+ const { done: g, value: A } = await a.read();
330
+ if (g)
331
331
  break;
332
332
  const f = n.decode(A, { stream: !0 }), { events: h, nextBuffer: I } = it(f, o);
333
333
  if (h && Array.isArray(h))
@@ -509,7 +509,7 @@ function Ue(e, s = "request") {
509
509
  if (!e.ok)
510
510
  throw new Error(`HTTP error! status: ${e.status}`);
511
511
  }
512
- function gt(e, s = "request") {
512
+ function dt(e, s = "request") {
513
513
  if (e.error)
514
514
  throw new Error(
515
515
  `Protocol ${s} error: ${e.error.message}`
@@ -518,7 +518,7 @@ function gt(e, s = "request") {
518
518
  throw new Error(`No result in ${s} response`);
519
519
  return e.result;
520
520
  }
521
- function dt(e, s = "streaming request") {
521
+ function gt(e, s = "streaming request") {
522
522
  if (Ue(e, s), !e.body)
523
523
  throw new Error(`No response body for ${s}`);
524
524
  }
@@ -567,7 +567,7 @@ function Fe(e, s, t, a) {
567
567
  return a !== void 0 && (n.credentials = a), n;
568
568
  }
569
569
  async function oe(e, s, t, a, n, o) {
570
- const { message: r, sessionId: l, taskId: i, metadata: u } = e, { agentId: c, agentUrl: p, authProvider: d, proxy: A } = s, { isStreaming: f = !1, enableTokenStreaming: h = !1 } = t, I = l || o, S = ft(p, c), y = await ot(
570
+ const { message: r, sessionId: l, taskId: i, metadata: u } = e, { agentId: c, agentUrl: p, authProvider: g, proxy: A } = s, { isStreaming: f = !1, enableTokenStreaming: h = !1 } = t, I = l || o, S = ft(p, c), y = await ot(
571
571
  r,
572
572
  a,
573
573
  n
@@ -582,7 +582,7 @@ async function oe(e, s, t, a, n, o) {
582
582
  f ? "message/stream" : "message/send",
583
583
  h && f
584
584
  // Only enable token streaming if using SSE
585
- ), m = await pt(d, f);
585
+ ), m = await pt(g, f);
586
586
  return mt("POST", S, m, x), {
587
587
  request: x,
588
588
  headers: m,
@@ -597,17 +597,17 @@ async function De(e, s, t = {}) {
597
597
  "request"
598
598
  ), p = i ? qe(c.signal, i) : c.signal;
599
599
  try {
600
- const d = Fe(
600
+ const g = Fe(
601
601
  n,
602
602
  JSON.stringify(a),
603
603
  p,
604
604
  l
605
605
  );
606
606
  v("Making request to %s with options: %O", o, {
607
- method: d.method,
608
- headers: d.headers
607
+ method: g.method,
608
+ headers: g.headers
609
609
  });
610
- const A = await fetch(o, d);
610
+ const A = await fetch(o, g);
611
611
  clearTimeout(u), Ue(A, "request");
612
612
  const f = await A.json();
613
613
  return v(
@@ -615,9 +615,9 @@ async function De(e, s, t = {}) {
615
615
  o,
616
616
  A.status,
617
617
  Ne(f)
618
- ), gt(f, "request");
619
- } catch (d) {
620
- Oe(d, u, "request");
618
+ ), dt(f, "request");
619
+ } catch (g) {
620
+ Oe(g, u, "request");
621
621
  }
622
622
  }
623
623
  async function* je(e, s, t) {
@@ -628,15 +628,15 @@ async function* je(e, s, t) {
628
628
  } = t, { timeoutId: c, controller: p } = $e(
629
629
  l,
630
630
  "streaming request"
631
- ), d = i ? qe(p.signal, i) : p.signal;
631
+ ), g = i ? qe(p.signal, i) : p.signal;
632
632
  try {
633
633
  const A = JSON.stringify(a), f = Fe(
634
634
  n,
635
635
  A,
636
- d,
636
+ g,
637
637
  r
638
638
  ), h = await fetch(o, f);
639
- if (clearTimeout(c), dt(h, "streaming request"), !h.body)
639
+ if (clearTimeout(c), gt(h, "streaming request"), !h.body)
640
640
  throw new Error(
641
641
  "Response body is null - server may not support streaming"
642
642
  );
@@ -773,8 +773,8 @@ async function Le(e, s, t) {
773
773
  u,
774
774
  t,
775
775
  l
776
- ), { result: p, returnToAgent: d, agentMessage: A } = Ie(c);
777
- d && (o = !0), A && n.push(Y(A)), a.push(
776
+ ), { result: p, returnToAgent: g, agentMessage: A } = Ie(c);
777
+ g && (o = !0), A && n.push(Y(A)), a.push(
778
778
  B(
779
779
  l,
780
780
  i,
@@ -807,7 +807,7 @@ function xe(e) {
807
807
  }) : (a.type === "data" || a.type === "file") && s.push(a);
808
808
  return s;
809
809
  }
810
- async function ge(e, s, t, a, n, o, r) {
810
+ async function de(e, s, t, a, n, o, r) {
811
811
  const i = await oe(
812
812
  {
813
813
  message: s,
@@ -840,12 +840,12 @@ async function be(e, s, t, a, n, o, r, l, i = []) {
840
840
  a,
841
841
  n,
842
842
  o
843
- ), d = je(p, t, {
843
+ ), g = je(p, t, {
844
844
  ...c,
845
845
  abortSignal: r
846
846
  });
847
847
  return Je(
848
- d,
848
+ g,
849
849
  a,
850
850
  n,
851
851
  t,
@@ -860,16 +860,16 @@ async function be(e, s, t, a, n, o, r, l, i = []) {
860
860
  );
861
861
  }
862
862
  async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
863
- var u, c, p, d, A, f, h, I, S, y, C, x;
863
+ var u, c, p, g, A, f, h, I, S, y, C, x;
864
864
  for await (const m of e) {
865
865
  if (m.sessionId && !n && (n = m.sessionId), yield m, m.status.state === "running" && m.status.message && s && await yt(
866
866
  s,
867
867
  m.status.message
868
868
  )) {
869
- const g = V(
869
+ const d = V(
870
870
  m.status.message
871
871
  );
872
- for (const w of g) {
872
+ for (const w of d) {
873
873
  const { toolCallId: O, toolId: R, arguments: M } = w.data;
874
874
  ie(
875
875
  s,
@@ -888,7 +888,7 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
888
888
  message: {
889
889
  role: "agent",
890
890
  kind: "message",
891
- parts: g,
891
+ parts: d,
892
892
  messageId: q()
893
893
  }
894
894
  },
@@ -897,14 +897,14 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
897
897
  };
898
898
  }
899
899
  if (m.status.state === "input-required" && m.status.message && s) {
900
- const g = V(
900
+ const d = V(
901
901
  m.status.message
902
902
  );
903
- if (g.length > 0) {
903
+ if (d.length > 0) {
904
904
  const w = [];
905
905
  let O = !1;
906
906
  const R = [], M = [];
907
- for (const b of g) {
907
+ for (const b of d) {
908
908
  const {
909
909
  toolCallId: k,
910
910
  toolId: P,
@@ -915,7 +915,7 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
915
915
  s,
916
916
  P,
917
917
  F,
918
- (d = (p = m.status) == null ? void 0 : p.message) == null ? void 0 : d.messageId,
918
+ (g = (p = m.status) == null ? void 0 : p.message) == null ? void 0 : g.messageId,
919
919
  k
920
920
  ), { result: T, returnToAgent: E, agentMessage: _ } = Ie(U);
921
921
  if (E && (O = !0), _ && M.push(
@@ -1147,7 +1147,7 @@ function Mt(e) {
1147
1147
  return {
1148
1148
  async sendMessage(p) {
1149
1149
  var C, x;
1150
- const { abortSignal: d } = p, A = p.sessionId || n || void 0, f = [];
1150
+ const { abortSignal: g } = p, A = p.sessionId || n || void 0, f = [];
1151
1151
  f.push(p.message);
1152
1152
  const h = await oe(
1153
1153
  p,
@@ -1160,7 +1160,7 @@ function Mt(e) {
1160
1160
  let I = await De(
1161
1161
  h,
1162
1162
  c,
1163
- { abortSignal: d }
1163
+ { abortSignal: g }
1164
1164
  );
1165
1165
  const S = [], y = [];
1166
1166
  for (; I.status.message && r; ) {
@@ -1170,7 +1170,7 @@ function Mt(e) {
1170
1170
  if (m.length === 0)
1171
1171
  break;
1172
1172
  S.push(...m);
1173
- const g = [];
1173
+ const d = [];
1174
1174
  let w = !1;
1175
1175
  for (const O of m) {
1176
1176
  const {
@@ -1192,7 +1192,7 @@ function Mt(e) {
1192
1192
  M,
1193
1193
  P
1194
1194
  );
1195
- g.push(T), S.push(T);
1195
+ d.push(T), S.push(T);
1196
1196
  } catch (k) {
1197
1197
  const P = B(
1198
1198
  R,
@@ -1200,19 +1200,19 @@ function Mt(e) {
1200
1200
  void 0,
1201
1201
  k instanceof Error ? k.message : String(k)
1202
1202
  );
1203
- g.push(P), S.push(P);
1203
+ d.push(P), S.push(P);
1204
1204
  }
1205
1205
  }
1206
1206
  if (f.push(I.status.message), w) {
1207
- const O = re(g);
1208
- I = await ge(
1207
+ const O = re(d);
1208
+ I = await de(
1209
1209
  I.id,
1210
1210
  O,
1211
1211
  c,
1212
1212
  r,
1213
1213
  l,
1214
1214
  A,
1215
- d
1215
+ g
1216
1216
  );
1217
1217
  } else
1218
1218
  break;
@@ -1231,13 +1231,13 @@ function Mt(e) {
1231
1231
  };
1232
1232
  }
1233
1233
  if (y.length > 0) {
1234
- const m = y.map((w) => L(w)).join(" "), g = Y(m);
1234
+ const m = y.map((w) => L(w)).join(" "), d = Y(m);
1235
1235
  return {
1236
1236
  ...I,
1237
1237
  // Keep the enhanced message with tool results
1238
1238
  // The agent message will be handled separately by the caller
1239
1239
  text: m,
1240
- agentMessage: g
1240
+ agentMessage: d
1241
1241
  // Add this for the caller to handle
1242
1242
  };
1243
1243
  }
@@ -1253,7 +1253,7 @@ function Mt(e) {
1253
1253
  },
1254
1254
  async *sendMessageStream(p) {
1255
1255
  const {
1256
- withHistory: d = !0,
1256
+ withHistory: g = !0,
1257
1257
  abortSignal: A,
1258
1258
  enableStreaming: f
1259
1259
  } = p, h = p.sessionId || n || void 0, I = f ?? i, S = [];
@@ -1285,7 +1285,7 @@ function Mt(e) {
1285
1285
  l,
1286
1286
  c,
1287
1287
  h,
1288
- d,
1288
+ g,
1289
1289
  S,
1290
1290
  A,
1291
1291
  {
@@ -1295,10 +1295,10 @@ function Mt(e) {
1295
1295
  }
1296
1296
  );
1297
1297
  },
1298
- async continueTask(p, d, A) {
1298
+ async continueTask(p, g, A) {
1299
1299
  var S;
1300
- const f = me(d);
1301
- let I = await ge(
1300
+ const f = me(g);
1301
+ let I = await de(
1302
1302
  p,
1303
1303
  f,
1304
1304
  c,
@@ -1315,7 +1315,7 @@ function Mt(e) {
1315
1315
  const { results: C, shouldReturnToAgent: x } = await Le(y, r);
1316
1316
  if (x) {
1317
1317
  const m = re(C);
1318
- I = await ge(
1318
+ I = await de(
1319
1319
  I.id,
1320
1320
  m,
1321
1321
  c,
@@ -1451,13 +1451,13 @@ async function pe(e, s, t = 1, a = 50, n = !1) {
1451
1451
  const h = await l();
1452
1452
  Object.assign(p, h);
1453
1453
  }
1454
- const d = await fetch(c.toString(), {
1454
+ const g = await fetch(c.toString(), {
1455
1455
  method: "GET",
1456
1456
  headers: p
1457
1457
  });
1458
- if (!d.ok) {
1459
- const h = await d.text();
1460
- let I = `Failed to load conversation from server: ${d.status} ${d.statusText}`;
1458
+ if (!g.ok) {
1459
+ const h = await g.text();
1460
+ let I = `Failed to load conversation from server: ${g.status} ${g.statusText}`;
1461
1461
  try {
1462
1462
  const y = JSON.parse(h);
1463
1463
  y.message && (I = y.message);
@@ -1465,12 +1465,12 @@ async function pe(e, s, t = 1, a = 50, n = !1) {
1465
1465
  }
1466
1466
  const S = new Z(
1467
1467
  I,
1468
- d.status,
1468
+ g.status,
1469
1469
  h
1470
1470
  );
1471
1471
  throw v("Failed to load conversation from server: %O", S), S;
1472
1472
  }
1473
- const A = await d.json(), f = vt(A, n);
1473
+ const A = await g.json(), f = vt(A, n);
1474
1474
  return v(
1475
1475
  "Loaded %d messages from server (page %d/%d)",
1476
1476
  f.messages.length,
@@ -1480,12 +1480,12 @@ async function pe(e, s, t = 1, a = 50, n = !1) {
1480
1480
  } catch (p) {
1481
1481
  if (p instanceof Z)
1482
1482
  throw p;
1483
- const d = new Z(
1483
+ const g = new Z(
1484
1484
  `Network error loading conversation: ${p.message}`,
1485
1485
  void 0,
1486
1486
  p
1487
1487
  );
1488
- throw v("Network error loading conversation: %O", p), d;
1488
+ throw v("Network error loading conversation: %O", p), g;
1489
1489
  }
1490
1490
  }
1491
1491
  async function cs(e, s, t = !1) {
@@ -1572,7 +1572,7 @@ async function us(e, s, t = 10, a = !1) {
1572
1572
  }
1573
1573
  const Te = "a8c_agenttic_conversation_history";
1574
1574
  function St(e) {
1575
- var d, A;
1575
+ var g, A;
1576
1576
  const s = e.parts.filter(
1577
1577
  (f) => f.type === "text"
1578
1578
  ), t = s.map((f) => f.text).join(`
@@ -1611,7 +1611,7 @@ function St(e) {
1611
1611
  break;
1612
1612
  }
1613
1613
  }
1614
- const u = n.length > 0 || o.length > 0 ? "agent" : e.role, c = ((d = e.metadata) == null ? void 0 : d.timestamp) ?? Date.now(), p = ((A = e.metadata) == null ? void 0 : A.archived) ?? void 0;
1614
+ const u = n.length > 0 || o.length > 0 ? "agent" : e.role, c = ((g = e.metadata) == null ? void 0 : g.timestamp) ?? Date.now(), p = ((A = e.metadata) == null ? void 0 : A.archived) ?? void 0;
1615
1615
  return {
1616
1616
  role: u,
1617
1617
  content: t || "(No text content)",
@@ -1682,12 +1682,12 @@ function Ct(e) {
1682
1682
  }
1683
1683
  };
1684
1684
  }
1685
- const G = /* @__PURE__ */ new Map(), xt = 50;
1685
+ const Q = /* @__PURE__ */ new Map(), xt = 50;
1686
1686
  async function bt(e, s, t) {
1687
1687
  const a = t || e;
1688
- if (G.set(a, [...s]), G.size > xt) {
1689
- const n = G.keys().next().value;
1690
- n && G.delete(n);
1688
+ if (Q.set(a, [...s]), Q.size > xt) {
1689
+ const n = Q.keys().next().value;
1690
+ n && Q.delete(n);
1691
1691
  }
1692
1692
  if (!(typeof sessionStorage > "u"))
1693
1693
  try {
@@ -1746,9 +1746,9 @@ async function kt(e, s) {
1746
1746
  }
1747
1747
  async function Pt(e, s) {
1748
1748
  const t = s || e;
1749
- if (G.has(t))
1749
+ if (Q.has(t))
1750
1750
  return {
1751
- messages: [...G.get(t)]
1751
+ messages: [...Q.get(t)]
1752
1752
  };
1753
1753
  if (typeof sessionStorage > "u")
1754
1754
  return { messages: [] };
@@ -1758,7 +1758,7 @@ async function Pt(e, s) {
1758
1758
  );
1759
1759
  if (a) {
1760
1760
  const o = JSON.parse(a).messages.map(Ct);
1761
- return G.set(t, o), { messages: [...o] };
1761
+ return Q.set(t, o), { messages: [...o] };
1762
1762
  }
1763
1763
  } catch (a) {
1764
1764
  v(
@@ -1771,7 +1771,7 @@ async function Pt(e, s) {
1771
1771
  }
1772
1772
  async function _t(e, s) {
1773
1773
  const t = s || e;
1774
- if (G.delete(t), !(typeof sessionStorage > "u"))
1774
+ if (Q.delete(t), !(typeof sessionStorage > "u"))
1775
1775
  try {
1776
1776
  sessionStorage.removeItem(`${Te}_${t}`);
1777
1777
  } catch (a) {
@@ -1782,7 +1782,7 @@ async function _t(e, s) {
1782
1782
  );
1783
1783
  }
1784
1784
  }
1785
- function Q(e) {
1785
+ function G(e) {
1786
1786
  const s = e.parts.filter((t) => t.type === "text" ? !0 : t.type === "data" ? "role" in t.data && "text" in t.data ? !1 : !!("toolCallId" in t.data && "arguments" in t.data || "flags" in t.data && t.data.flags && typeof t.data.flags == "object" && "forward_to_human_support" in t.data.flags || "sources" in t.data && Array.isArray(t.data.sources) && t.data.sources.length > 0 || "toolCallId" in t.data && "result" in t.data) : !0);
1787
1787
  return {
1788
1788
  ...e,
@@ -1870,7 +1870,7 @@ function Nt(e) {
1870
1870
  return !1;
1871
1871
  }
1872
1872
  }
1873
- function de(e, s) {
1873
+ function ge(e, s) {
1874
1874
  if (typeof localStorage > "u") {
1875
1875
  z("localStorage not available, cannot update session ID");
1876
1876
  return;
@@ -1994,28 +1994,28 @@ function Ot() {
1994
1994
  a,
1995
1995
  c,
1996
1996
  n.imageUrls
1997
- ), d = await u.sendMessage({
1997
+ ), g = await u.sendMessage({
1998
1998
  message: p,
1999
1999
  withHistory: r,
2000
2000
  sessionId: l || o.sessionId || void 0,
2001
2001
  ...i
2002
2002
  });
2003
- if (d.sessionId) {
2003
+ if (g.sessionId) {
2004
2004
  const S = o.sessionId;
2005
- o.sessionId = d.sessionId, S && d.sessionId && S !== d.sessionId && o.sessionIdStorageKey && (z(
2005
+ o.sessionId = g.sessionId, S && g.sessionId && S !== g.sessionId && o.sessionIdStorageKey && (z(
2006
2006
  "Session ID changed from %s to %s, updating localStorage",
2007
2007
  S,
2008
- d.sessionId
2009
- ), de(
2008
+ g.sessionId
2009
+ ), ge(
2010
2010
  o.sessionIdStorageKey,
2011
- d.sessionId
2011
+ g.sessionId
2012
2012
  ));
2013
2013
  }
2014
2014
  let A = null;
2015
- if ((I = d.status) != null && I.message) {
2016
- const S = d.status.message.parts.filter(
2015
+ if ((I = g.status) != null && I.message) {
2016
+ const S = g.status.message.parts.filter(
2017
2017
  (C) => C.type === "data" && "toolCallId" in C.data && ("arguments" in C.data || "result" in C.data)
2018
- ), y = d.status.message.parts.filter(
2018
+ ), y = g.status.message.parts.filter(
2019
2019
  (C) => C.type === "text"
2020
2020
  );
2021
2021
  A = {
@@ -2033,12 +2033,12 @@ function Ot() {
2033
2033
  // Store only the new content from the user message (without history parts)
2034
2034
  me(a),
2035
2035
  // Add complete agent response with tool calls/results if present
2036
- ...A ? [Q(A)] : []
2036
+ ...A ? [G(A)] : []
2037
2037
  ];
2038
2038
  let h = f;
2039
- if (d.agentMessage) {
2040
- const S = Q(
2041
- d.agentMessage
2039
+ if (g.agentMessage) {
2040
+ const S = G(
2041
+ g.agentMessage
2042
2042
  );
2043
2043
  h = [
2044
2044
  ...f,
@@ -2048,10 +2048,10 @@ function Ot() {
2048
2048
  return o.conversationHistory = h, r && await s(
2049
2049
  t,
2050
2050
  h
2051
- ), d;
2051
+ ), g;
2052
2052
  },
2053
2053
  async *sendMessageStream(t, a, n = {}) {
2054
- var x, m, g, w, O, R;
2054
+ var x, m, d, w, O, R;
2055
2055
  const o = e.get(t);
2056
2056
  if (!o)
2057
2057
  throw new Error(`Agent with key "${t}" not found`);
@@ -2062,7 +2062,7 @@ function Ot() {
2062
2062
  sessionId: u,
2063
2063
  message: c,
2064
2064
  ...p
2065
- } = n, { client: d } = o, A = i ? (({ contentType: M, ...b }) => b)(i) : void 0, f = new AbortController();
2065
+ } = n, { client: g } = o, A = i ? (({ contentType: M, ...b }) => b)(i) : void 0, f = new AbortController();
2066
2066
  o.currentAbortController = f, l && l.addEventListener(
2067
2067
  "abort",
2068
2068
  () => f.abort()
@@ -2131,7 +2131,7 @@ function Ot() {
2131
2131
  t,
2132
2132
  h
2133
2133
  );
2134
- for await (const M of d.sendMessageStream({
2134
+ for await (const M of g.sendMessageStream({
2135
2135
  message: y,
2136
2136
  withHistory: r,
2137
2137
  sessionId: u || o.sessionId || void 0,
@@ -2146,7 +2146,7 @@ function Ot() {
2146
2146
  o.sessionId = M.sessionId, M.sessionId && b !== M.sessionId && o.sessionIdStorageKey && (z(
2147
2147
  "Session ID %s, updating localStorage",
2148
2148
  b ? `changed from ${b} to ${M.sessionId}` : `received: ${M.sessionId}`
2149
- ), de(
2149
+ ), ge(
2150
2150
  o.sessionIdStorageKey,
2151
2151
  M.sessionId
2152
2152
  ));
@@ -2157,7 +2157,7 @@ function Ot() {
2157
2157
  ).map(
2158
2158
  (P) => P.data.toolCallId
2159
2159
  );
2160
- const k = Q(
2160
+ const k = G(
2161
2161
  M.status.message
2162
2162
  );
2163
2163
  h = [
@@ -2168,7 +2168,7 @@ function Ot() {
2168
2168
  h
2169
2169
  );
2170
2170
  }
2171
- if (((g = M.status) == null ? void 0 : g.state) === "working" && ((w = M.status) != null && w.message) && !M.final) {
2171
+ if (((d = M.status) == null ? void 0 : d.state) === "working" && ((w = M.status) != null && w.message) && !M.final) {
2172
2172
  const k = Et(
2173
2173
  M.status.message
2174
2174
  ).filter(
@@ -2185,14 +2185,14 @@ function Ot() {
2185
2185
  };
2186
2186
  h = [
2187
2187
  ...h,
2188
- Q(P)
2188
+ G(P)
2189
2189
  ], o.conversationHistory = h, r && await s(
2190
2190
  t,
2191
2191
  h
2192
2192
  );
2193
2193
  } else Nt(M.status.message) && (h = [
2194
2194
  ...h,
2195
- Q(
2195
+ G(
2196
2196
  M.status.message
2197
2197
  )
2198
2198
  ], o.conversationHistory = h, r && await s(
@@ -2203,7 +2203,7 @@ function Ot() {
2203
2203
  if (M.final && ((O = M.status) == null ? void 0 : O.state) !== "input-required") {
2204
2204
  I = [];
2205
2205
  let b = null;
2206
- (R = M.status) != null && R.message && (b = Q(
2206
+ (R = M.status) != null && R.message && (b = G(
2207
2207
  M.status.message
2208
2208
  ), h = [
2209
2209
  ...h,
@@ -2279,7 +2279,7 @@ function Ot() {
2279
2279
  const n = e.get(t);
2280
2280
  if (!n)
2281
2281
  throw new Error(`Agent with key "${t}" not found`);
2282
- n.sessionId = a, n.sessionIdStorageKey && de(
2282
+ n.sessionId = a, n.sessionIdStorageKey && ge(
2283
2283
  n.sessionIdStorageKey,
2284
2284
  a
2285
2285
  );
@@ -2420,28 +2420,28 @@ function Jt({
2420
2420
  const c = X().getConversationHistory(e), p = (i == null ? void 0 : i.id) ?? ke(c);
2421
2421
  if (!p)
2422
2422
  return;
2423
- const d = Lt(
2423
+ const g = Lt(
2424
2424
  c,
2425
2425
  p
2426
2426
  );
2427
- if (!d)
2427
+ if (!g)
2428
2428
  return;
2429
2429
  const A = {
2430
2430
  clientMessages: c,
2431
2431
  uiMessages: a.current.uiMessages
2432
2432
  }, f = n(
2433
- d.baseHistory
2433
+ g.baseHistory
2434
2434
  );
2435
2435
  try {
2436
- await o(d.prompt, void 0, {
2436
+ await o(g.prompt, void 0, {
2437
2437
  initialClientMessages: [
2438
- ...d.baseHistory,
2439
- d.userMessage
2438
+ ...g.baseHistory,
2439
+ g.userMessage
2440
2440
  ],
2441
2441
  initialUiMessages: f,
2442
- messageOverride: d.userMessage,
2442
+ messageOverride: g.userMessage,
2443
2443
  preserveUiOnlyMessages: !1,
2444
- truncateHistoryTo: d.baseHistory,
2444
+ truncateHistoryTo: g.baseHistory,
2445
2445
  restoreOnError: A
2446
2446
  });
2447
2447
  } catch (h) {
@@ -2459,10 +2459,10 @@ function Jt({
2459
2459
  );
2460
2460
  return { getRegenerateHandler: D(
2461
2461
  (i) => {
2462
- const u = a.current, c = X(), p = c.hasAgent(e) ? c.getConversationHistory(e) : u.clientMessages, d = (i == null ? void 0 : i.id) ?? ke(p);
2463
- return !s || i && i.role !== "agent" || !d || !We(
2462
+ const u = a.current, c = X(), p = c.hasAgent(e) ? c.getConversationHistory(e) : u.clientMessages, g = (i == null ? void 0 : i.id) ?? ke(p);
2463
+ return !s || i && i.role !== "agent" || !g || !We(
2464
2464
  p,
2465
- d
2465
+ g
2466
2466
  ) ? null : () => r(i);
2467
2467
  },
2468
2468
  [e, r, s, a]
@@ -2558,7 +2558,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
2558
2558
  const a = e[t];
2559
2559
  return typeof a == "string" && a.trim().length > 0;
2560
2560
  });
2561
- function gs(e) {
2561
+ function ds(e) {
2562
2562
  const s = {
2563
2563
  agentId: e.agentId,
2564
2564
  agentUrl: e.agentUrl,
@@ -2585,10 +2585,10 @@ function gs(e) {
2585
2585
  ae(() => {
2586
2586
  p.current = i;
2587
2587
  }, [i]);
2588
- const d = D(
2588
+ const g = D(
2589
2589
  (m) => m.map(
2590
- (g) => ne(g, p.current)
2591
- ).filter((g) => g !== null),
2590
+ (d) => ne(d, p.current)
2591
+ ).filter((d) => d !== null),
2592
2592
  []
2593
2593
  // registrationsRef is stable, so no deps needed
2594
2594
  );
@@ -2596,18 +2596,18 @@ function gs(e) {
2596
2596
  if (!t)
2597
2597
  return;
2598
2598
  (async () => {
2599
- const g = X(), w = s.agentId;
2600
- if (g.hasAgent(w))
2601
- s.sessionId ? (g.updateSessionId(w, s.sessionId), g.getConversationHistory(w).length === 0 && n((M) => ({
2599
+ const d = X(), w = s.agentId;
2600
+ if (d.hasAgent(w))
2601
+ s.sessionId ? (d.updateSessionId(w, s.sessionId), d.getConversationHistory(w).length === 0 && n((M) => ({
2602
2602
  ...M,
2603
2603
  clientMessages: [],
2604
2604
  uiMessages: []
2605
- }))) : (g.updateSessionId(w, ""), await g.replaceMessages(w, []), n((R) => ({
2605
+ }))) : (d.updateSessionId(w, ""), await d.replaceMessages(w, []), n((R) => ({
2606
2606
  ...R,
2607
2607
  clientMessages: [],
2608
2608
  uiMessages: []
2609
2609
  })));
2610
- else if (await g.createAgent(w, {
2610
+ else if (await d.createAgent(w, {
2611
2611
  agentId: s.agentId,
2612
2612
  agentUrl: s.agentUrl,
2613
2613
  sessionId: s.sessionId,
@@ -2620,9 +2620,9 @@ function gs(e) {
2620
2620
  odieBotId: e.odieBotId,
2621
2621
  credentials: e.credentials
2622
2622
  }), s.sessionId) {
2623
- const R = g.getConversationHistory(w);
2623
+ const R = d.getConversationHistory(w);
2624
2624
  n((M) => {
2625
- const b = d(R);
2625
+ const b = g(R);
2626
2626
  return {
2627
2627
  ...M,
2628
2628
  clientMessages: R,
@@ -2648,18 +2648,18 @@ function gs(e) {
2648
2648
  e.odieBotId,
2649
2649
  e.credentials,
2650
2650
  t,
2651
- d
2651
+ g
2652
2652
  ]);
2653
2653
  const A = D(
2654
- async (m, g, w) => {
2654
+ async (m, d, w) => {
2655
2655
  var F, U;
2656
2656
  if (!t)
2657
2657
  throw new Error("Invalid agent configuration");
2658
2658
  if (u.current)
2659
2659
  return;
2660
2660
  u.current = !0;
2661
- const O = (g == null ? void 0 : g.type) === "tool_result";
2662
- if (O && (!(g != null && g.toolCallId) || !(g != null && g.toolId)))
2661
+ const O = (d == null ? void 0 : d.type) === "tool_result";
2662
+ if (O && (!(d != null && d.toolCallId) || !(d != null && d.toolId)))
2663
2663
  throw new Error(
2664
2664
  "`toolCallId` and `toolId` are required when type is `tool_result`"
2665
2665
  );
@@ -2695,7 +2695,7 @@ function gs(e) {
2695
2695
  error: null
2696
2696
  }));
2697
2697
  else {
2698
- const T = (g == null ? void 0 : g.type) || "text", E = w != null && w.messageOverride ? ne(
2698
+ const T = (d == null ? void 0 : d.type) || "text", E = w != null && w.messageOverride ? ne(
2699
2699
  w.messageOverride,
2700
2700
  []
2701
2701
  ) : {
@@ -2704,13 +2704,13 @@ function gs(e) {
2704
2704
  content: [
2705
2705
  { type: T, text: m },
2706
2706
  // Map image URLs to component content parts
2707
- ...((F = g == null ? void 0 : g.imageUrls) == null ? void 0 : F.map((_) => {
2707
+ ...((F = d == null ? void 0 : d.imageUrls) == null ? void 0 : F.map((_) => {
2708
2708
  const j = typeof _ == "string" ? _ : _.url;
2709
2709
  return ze(j);
2710
2710
  })) ?? []
2711
2711
  ],
2712
2712
  timestamp: P,
2713
- archived: (g == null ? void 0 : g.archived) ?? !1,
2713
+ archived: (d == null ? void 0 : d.archived) ?? !1,
2714
2714
  showIcon: !1
2715
2715
  };
2716
2716
  n((_) => ({
@@ -2730,15 +2730,15 @@ function gs(e) {
2730
2730
  w.truncateHistoryTo
2731
2731
  );
2732
2732
  let T = null, E = !1;
2733
- const _ = {}, j = !!(g != null && g.type) && !O;
2734
- (g != null && g.archived || j) && (_.metadata = {
2735
- ...(g == null ? void 0 : g.archived) && { archived: !0 },
2736
- ...j && { contentType: g.type }
2737
- }), g != null && g.sessionId && (_.sessionId = g.sessionId), g != null && g.imageUrls && (_.imageUrls = g.imageUrls), w != null && w.messageOverride && (_.message = w.messageOverride);
2733
+ const _ = {}, j = !!(d != null && d.type) && !O;
2734
+ (d != null && d.archived || j) && (_.metadata = {
2735
+ ...(d == null ? void 0 : d.archived) && { archived: !0 },
2736
+ ...j && { contentType: d.type }
2737
+ }), d != null && d.sessionId && (_.sessionId = d.sessionId), d != null && d.imageUrls && (_.imageUrls = d.imageUrls), w != null && w.messageOverride && (_.message = w.messageOverride);
2738
2738
  const W = O ? R.sendToolResult(
2739
2739
  M,
2740
- g.toolCallId,
2741
- g.toolId,
2740
+ d.toolCallId,
2741
+ d.toolId,
2742
2742
  { success: !0, message: m },
2743
2743
  _
2744
2744
  ) : R.sendMessageStream(
@@ -2892,16 +2892,16 @@ function gs(e) {
2892
2892
  },
2893
2893
  [s.agentId, t]
2894
2894
  ), f = D(
2895
- (m, g) => A(m, g),
2895
+ (m, d) => A(m, d),
2896
2896
  [A]
2897
2897
  ), h = D((m) => {
2898
- n((g) => ({
2899
- ...g,
2900
- uiMessages: fe([...g.uiMessages, m])
2898
+ n((d) => ({
2899
+ ...d,
2900
+ uiMessages: fe([...d.uiMessages, m])
2901
2901
  }));
2902
2902
  }, []), I = D((m) => {
2903
- n((g) => ({
2904
- ...g,
2903
+ n((d) => ({
2904
+ ...d,
2905
2905
  suggestions: m
2906
2906
  }));
2907
2907
  }, []), S = D(() => {
@@ -2914,7 +2914,7 @@ function gs(e) {
2914
2914
  n((m) => {
2915
2915
  if (u.current || m.clientMessages.length === 0)
2916
2916
  return m;
2917
- const g = d(m.clientMessages), w = new Set(
2917
+ const d = g(m.clientMessages), w = new Set(
2918
2918
  m.clientMessages.map((R) => R.messageId)
2919
2919
  ), O = m.uiMessages.filter(
2920
2920
  (R) => !w.has(R.id) && R.role !== "user"
@@ -2922,37 +2922,37 @@ function gs(e) {
2922
2922
  return {
2923
2923
  ...m,
2924
2924
  uiMessages: fe([
2925
- ...g,
2925
+ ...d,
2926
2926
  ...O
2927
2927
  ])
2928
2928
  };
2929
2929
  });
2930
- }, [i, d]);
2930
+ }, [i, g]);
2931
2931
  const y = D(() => {
2932
2932
  if (!t)
2933
2933
  return;
2934
- const m = X(), g = s.agentId;
2935
- m.abortCurrentRequest(g);
2934
+ const m = X(), d = s.agentId;
2935
+ m.abortCurrentRequest(d);
2936
2936
  }, [s.agentId, t]), C = D(
2937
2937
  async (m) => {
2938
2938
  if (!t)
2939
2939
  return;
2940
- const g = X(), w = s.agentId;
2941
- await g.replaceMessages(w, m);
2942
- const O = d(m);
2940
+ const d = X(), w = s.agentId;
2941
+ await d.replaceMessages(w, m);
2942
+ const O = g(m);
2943
2943
  n((R) => ({
2944
2944
  ...R,
2945
2945
  clientMessages: m,
2946
2946
  uiMessages: O
2947
2947
  }));
2948
2948
  },
2949
- [s.agentId, t, d]
2949
+ [s.agentId, t, g]
2950
2950
  ), { getRegenerateHandler: x } = Jt({
2951
2951
  agentId: s.agentId,
2952
2952
  isValidConfig: t,
2953
2953
  isSendingRef: u,
2954
2954
  stateRef: c,
2955
- transformMessages: d,
2955
+ transformMessages: g,
2956
2956
  sendMessage: A
2957
2957
  });
2958
2958
  return {
@@ -2981,8 +2981,8 @@ function gs(e) {
2981
2981
  };
2982
2982
  }
2983
2983
  var Vt = /* @__PURE__ */ ((e) => (e[e.PARSE_ERROR = -32700] = "PARSE_ERROR", e[e.INVALID_REQUEST = -32600] = "INVALID_REQUEST", e[e.METHOD_NOT_FOUND = -32601] = "METHOD_NOT_FOUND", e[e.INVALID_PARAMS = -32602] = "INVALID_PARAMS", e[e.INTERNAL_ERROR = -32603] = "INTERNAL_ERROR", e[e.SERVER_ERROR = -32e3] = "SERVER_ERROR", e))(Vt || {});
2984
- const Pe = "jetpack-ai-jwt-token", Gt = 30 * 60 * 1e3;
2985
- function Qt() {
2984
+ const Pe = "jetpack-ai-jwt-token", Qt = 30 * 60 * 1e3;
2985
+ function Gt() {
2986
2986
  var t, a, n;
2987
2987
  return ((a = (t = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : t.connectionStatus) == null ? void 0 : a.isRegistered) ? !1 : !!((n = window.Jetpack_Editor_Initial_State) != null && n.wpcomBlogId);
2988
2988
  }
@@ -3004,7 +3004,7 @@ async function Xt(e, s = !0) {
3004
3004
  blog_id: ""
3005
3005
  };
3006
3006
  try {
3007
- Qt() ? r = await Se({
3007
+ Gt() ? r = await Se({
3008
3008
  path: "/wpcom/v2/sites/" + o + "/jetpack-openai-query/jwt",
3009
3009
  method: "POST"
3010
3010
  }) : r = await Se({
@@ -3025,7 +3025,7 @@ async function Xt(e, s = !0) {
3025
3025
  const l = {
3026
3026
  token: r.token,
3027
3027
  blogId: r.blog_id || "",
3028
- expire: Date.now() + Gt
3028
+ expire: Date.now() + Qt
3029
3029
  };
3030
3030
  try {
3031
3031
  localStorage.setItem(Pe, JSON.stringify(l));
@@ -3034,7 +3034,7 @@ async function Xt(e, s = !0) {
3034
3034
  }
3035
3035
  return l;
3036
3036
  }
3037
- const ds = (e) => async () => {
3037
+ const gs = (e) => async () => {
3038
3038
  const s = {};
3039
3039
  try {
3040
3040
  const t = await Xt(e);
@@ -3110,30 +3110,33 @@ export {
3110
3110
  Cs as createAgentsApiChatAdapter,
3111
3111
  xs as createAgentsApiRunControlAdapter,
3112
3112
  Mt as createClient,
3113
- ds as createJetpackAuthProvider,
3113
+ gs as createJetpackAuthProvider,
3114
3114
  ps as createOdieBotId,
3115
+ bs as createPresentQuestionRenderer,
3116
+ Rs as createPresentQuestionToolRenderers,
3115
3117
  Ye as createRequestId,
3116
3118
  Ze as createTaskId,
3117
3119
  me as createTextMessage,
3118
3120
  L as extractTextFromMessage,
3119
3121
  V as extractToolCallsFromMessage,
3120
3122
  X as getAgentManager,
3121
- bs as groupToolMessages,
3123
+ ks as groupToolMessages,
3122
3124
  hs as isOdieBotId,
3123
3125
  ms as isWordPressAbility,
3124
3126
  cs as listConversationsFromServer,
3125
3127
  us as loadAllMessagesFromServer,
3126
3128
  pe as loadChatFromServer,
3127
- Rs as normalizeAgentsApiMessage,
3128
- ks as normalizeConversation,
3129
- Ps as normalizeLoadedSession,
3130
- _s as normalizeRunEvent,
3131
- Es as normalizeSendResponse,
3132
- Ns as normalizeSessions,
3129
+ Ps as normalizeAgentsApiMessage,
3130
+ _s as normalizeConversation,
3131
+ Es as normalizeLoadedSession,
3132
+ Ns as normalizePresentQuestionPrompt,
3133
+ Hs as normalizeRunEvent,
3134
+ Os as normalizeSendResponse,
3135
+ Us as normalizeSessions,
3133
3136
  Zt as parseOdieBotId,
3134
- Hs as renderToolGroups,
3135
- gs as useAgentChat,
3136
- Os as useAgentsApiChat,
3137
+ $s as renderToolGroups,
3138
+ ds as useAgentChat,
3139
+ qs as useAgentsApiChat,
3137
3140
  os as useClientAbilities,
3138
3141
  ns as useClientContext,
3139
3142
  rs as useClientTools,