@automattic/agenttic-client 0.1.13 → 0.1.15

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.
Files changed (49) hide show
  1. package/README.md +78 -1
  2. package/dist/client/index.d.ts.map +1 -1
  3. package/dist/client/types/index.d.ts +55 -0
  4. package/dist/client/types/index.d.ts.map +1 -1
  5. package/dist/index.d.ts +5 -8
  6. package/dist/index.d.ts.map +1 -1
  7. package/dist/index.js +1189 -1591
  8. package/dist/message-actions/index.d.ts +0 -2
  9. package/dist/message-actions/index.d.ts.map +1 -1
  10. package/dist/message-actions/useMessageActions.d.ts.map +1 -1
  11. package/dist/mocks/MockSalesGraph.d.ts.map +1 -1
  12. package/dist/mocks.js +672 -50
  13. package/dist/react/agentManager.d.ts +1 -0
  14. package/dist/react/agentManager.d.ts.map +1 -1
  15. package/dist/react/useAgentChat.d.ts +0 -18
  16. package/dist/react/useAgentChat.d.ts.map +1 -1
  17. package/dist/react/useClientTools.d.ts +65 -3
  18. package/dist/react/useClientTools.d.ts.map +1 -1
  19. package/dist/utils/wordpressAbilities.d.ts +37 -0
  20. package/dist/utils/wordpressAbilities.d.ts.map +1 -0
  21. package/package.json +6 -11
  22. package/dist/BarChart-Cid6YH81.js +0 -801
  23. package/dist/BarChart.css +0 -1
  24. package/dist/markdown-extensions/charts/BarChart.d.ts +0 -16
  25. package/dist/markdown-extensions/charts/BarChart.d.ts.map +0 -1
  26. package/dist/markdown-extensions/charts/BaseChart.d.ts +0 -36
  27. package/dist/markdown-extensions/charts/BaseChart.d.ts.map +0 -1
  28. package/dist/markdown-extensions/charts/ChartBlock.d.ts +0 -34
  29. package/dist/markdown-extensions/charts/ChartBlock.d.ts.map +0 -1
  30. package/dist/markdown-extensions/charts/ChartError.d.ts +0 -17
  31. package/dist/markdown-extensions/charts/ChartError.d.ts.map +0 -1
  32. package/dist/markdown-extensions/charts/ChartErrorBoundary.d.ts +0 -30
  33. package/dist/markdown-extensions/charts/ChartErrorBoundary.d.ts.map +0 -1
  34. package/dist/markdown-extensions/charts/LineChart.d.ts +0 -14
  35. package/dist/markdown-extensions/charts/LineChart.d.ts.map +0 -1
  36. package/dist/markdown-extensions/charts/index.d.ts +0 -294
  37. package/dist/markdown-extensions/charts/index.d.ts.map +0 -1
  38. package/dist/markdown-extensions/charts/utils/chartUtils.d.ts +0 -56
  39. package/dist/markdown-extensions/charts/utils/chartUtils.d.ts.map +0 -1
  40. package/dist/markdown-extensions/index.d.ts +0 -34
  41. package/dist/markdown-extensions/index.d.ts.map +0 -1
  42. package/dist/markdown-extensions/types.d.ts +0 -52
  43. package/dist/markdown-extensions/types.d.ts.map +0 -1
  44. package/dist/message-actions/factories.d.ts +0 -16
  45. package/dist/message-actions/factories.d.ts.map +0 -1
  46. package/dist/utils/createMessageRenderer.d.ts +0 -25
  47. package/dist/utils/createMessageRenderer.d.ts.map +0 -1
  48. package/dist/utils/markdownParser.d.ts +0 -25
  49. package/dist/utils/markdownParser.d.ts.map +0 -1
package/dist/index.js CHANGED
@@ -1,104 +1,192 @@
1
- var Nt = Object.defineProperty;
2
- var $t = (t, e, s) => e in t ? Nt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
3
- var at = (t, e, s) => $t(t, typeof e != "symbol" ? e + "" : e, s);
4
- import gt, { useMemo as it, useCallback as j, Component as Dt, useState as X, useRef as xt, useEffect as Y } from "react";
5
- import { j as $, C as tt, g as _t, a as jt, B as Ft, b as Ht } from "./BarChart-Cid6YH81.js";
6
- import qt from "streamdown";
7
- import Ut from "remark-gfm";
8
- import { __ as H, sprintf as ft } from "@wordpress/i18n";
9
- import { LineChart as Bt } from "@automattic/charts";
10
- import mt from "@wordpress/api-fetch";
11
- const N = (t, ...e) => {
12
- Jt() && console.log(`[agenttic-client] ${t}`, ...e);
1
+ var Rt = Object.defineProperty;
2
+ var kt = (t, s, e) => s in t ? Rt(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
3
+ var Z = (t, s, e) => kt(t, typeof s != "symbol" ? s + "" : s, e);
4
+ import { useMemo as G, useCallback as H, useState as ht, useRef as Et, useEffect as tt } from "react";
5
+ import ut from "@wordpress/api-fetch";
6
+ const k = (t, ...s) => {
7
+ Pt() && console.log(`[agenttic-client] ${t}`, ...s);
13
8
  };
14
- function Jt() {
9
+ function Pt() {
15
10
  var t;
16
11
  return typeof globalThis < "u" && "window" in globalThis && ((t = globalThis.window) == null ? void 0 : t.DEBUG) === "agenttic-client";
17
12
  }
18
- function Mt(t) {
13
+ function yt(t) {
19
14
  return JSON.stringify(t, null, 2);
20
15
  }
21
- function ht(t, ...e) {
22
- console.log(`[agenttic-client] ${t}`, ...e);
16
+ function dt(t, ...s) {
17
+ console.log(`[agenttic-client] ${t}`, ...s);
23
18
  }
24
- function Ve(t) {
25
- return it(() => t ? {
19
+ function Se(t) {
20
+ return G(() => t ? {
26
21
  getClientContext: () => {
27
22
  try {
28
23
  return t() || {};
29
24
  } catch (n) {
30
- return N("Error getting client context: %O", n), {};
25
+ return k("Error getting client context: %O", n), {};
31
26
  }
32
27
  }
33
28
  } : void 0, [t]);
34
29
  }
35
- function ze(t, e) {
36
- const s = j(async () => {
37
- if (!t)
38
- return [];
39
- try {
40
- return await t();
41
- } catch (r) {
42
- return N("Error getting available tools: %O", r), [];
43
- }
44
- }, [t]), n = j(
45
- async (r, o) => {
46
- if (!e)
30
+ function Ot(t) {
31
+ const s = {
32
+ type: "object",
33
+ properties: {}
34
+ };
35
+ return {
36
+ id: t.name.replace(/\//g, "-"),
37
+ name: t.label,
38
+ description: t.description,
39
+ input_schema: t.input_schema || s,
40
+ // Store metadata for detection and execution
41
+ _source: "wordpress-ability",
42
+ _originalAbility: t
43
+ };
44
+ }
45
+ function _t(t) {
46
+ return t.map(Ot);
47
+ }
48
+ function be(t) {
49
+ return (t == null ? void 0 : t._source) === "wordpress-ability";
50
+ }
51
+ function at({
52
+ getClientTools: t,
53
+ executeTool: s,
54
+ abilities: e,
55
+ executeAbility: n
56
+ }) {
57
+ const o = G(() => !e || e.length === 0 ? [] : _t(e), [e]), r = G(() => !e || e.length === 0 ? /* @__PURE__ */ new Map() : new Map(
58
+ e.map((d) => [d.name.replace(/\//g, "-"), d])
59
+ ), [e]), a = H(async () => {
60
+ const d = [];
61
+ if (t)
62
+ try {
63
+ const c = await t();
64
+ d.push(...c);
65
+ } catch (c) {
66
+ k("Error getting available tools: %O", c);
67
+ }
68
+ return o.length > 0 && d.push(...o), d;
69
+ }, [t, o]), l = H(
70
+ async (d, c) => {
71
+ const g = r.get(d);
72
+ if (g)
73
+ try {
74
+ const h = await n(g.name, c);
75
+ return k(`Executed Ability: ${g.name}`), {
76
+ result: h,
77
+ returnToAgent: !0
78
+ };
79
+ } catch (h) {
80
+ return k(
81
+ "Error executing ability %s: %O",
82
+ g.name,
83
+ h
84
+ ), {
85
+ result: {
86
+ error: h instanceof Error ? h.message : String(h),
87
+ success: !1
88
+ },
89
+ returnToAgent: !0
90
+ };
91
+ }
92
+ if (!s)
47
93
  throw new Error("No executeTool callback provided");
48
94
  try {
49
- return await e(r, o);
50
- } catch (i) {
51
- throw N("Error executing tool %s: %O", r, i), i;
95
+ return await s(d, c);
96
+ } catch (h) {
97
+ throw k("Error executing tool %s: %O", d, h), h;
52
98
  }
53
99
  },
54
- [e]
100
+ [s, r, n]
55
101
  );
56
- return it(() => {
57
- if (t)
102
+ return G(() => {
103
+ if (!(!t && (!e || e.length === 0)))
58
104
  return {
59
- getAvailableTools: s,
60
- executeTool: n
105
+ getAvailableTools: a,
106
+ executeTool: l,
107
+ abilities: e
61
108
  };
62
- }, [s, n, t]);
109
+ }, [a, l, t, e]);
110
+ }
111
+ function Ae(t, s) {
112
+ return at({
113
+ getClientTools: t,
114
+ executeTool: s,
115
+ abilities: void 0,
116
+ executeAbility: void 0
117
+ });
118
+ }
119
+ function ve(t, s) {
120
+ if (t.length > 0 && !s)
121
+ throw new Error(
122
+ "executeAbility is required when providing abilities. Please provide the executeAbility function from @wordpress/abilities."
123
+ );
124
+ return at({
125
+ getClientTools: void 0,
126
+ executeTool: void 0,
127
+ abilities: t,
128
+ executeAbility: s
129
+ });
130
+ }
131
+ function Re(t) {
132
+ const { getClientTools: s, executeTool: e, abilities: n, executeAbility: o } = t;
133
+ if (!s && (!n || n.length === 0))
134
+ throw new Error(
135
+ "At least one of getClientTools or abilities must be provided to useClientToolsWithAbilities."
136
+ );
137
+ if (s && !e)
138
+ throw new Error(
139
+ "executeTool is required when providing getClientTools."
140
+ );
141
+ if (n && n.length > 0 && !o)
142
+ throw new Error(
143
+ "executeAbility is required when providing abilities. Please provide the executeAbility function from @wordpress/abilities."
144
+ );
145
+ return at({
146
+ getClientTools: s,
147
+ executeTool: e,
148
+ abilities: n,
149
+ executeAbility: o
150
+ });
63
151
  }
64
- function lt() {
152
+ function rt() {
65
153
  const t = "abcdefghijklmnopqrstuvwxyz0123456789";
66
- let e = "";
67
- for (let s = 0; s < 8; s++)
68
- e += t.charAt(Math.floor(Math.random() * t.length));
69
- return e;
154
+ let s = "";
155
+ for (let e = 0; e < 8; e++)
156
+ s += t.charAt(Math.floor(Math.random() * t.length));
157
+ return s;
70
158
  }
71
- function D() {
72
- return lt();
159
+ function O() {
160
+ return rt();
73
161
  }
74
- function Lt() {
75
- return `req-${lt()}`;
162
+ function Nt() {
163
+ return `req-${rt()}`;
76
164
  }
77
- function Wt() {
78
- return `task-${lt()}`;
165
+ function qt() {
166
+ return `task-${rt()}`;
79
167
  }
80
- function Tt(t) {
168
+ function wt(t) {
81
169
  return {
82
170
  type: "text",
83
171
  text: t
84
172
  };
85
173
  }
86
- function Kt(t, e = "message/send", s = !1) {
174
+ function Ht(t, s = "message/send", e = !1) {
87
175
  const n = {
88
176
  jsonrpc: "2.0",
89
- id: Lt(),
90
- method: e,
177
+ id: Nt(),
178
+ method: s,
91
179
  params: {
92
- id: t.id || Wt(),
180
+ id: t.id || qt(),
93
181
  ...t
94
182
  }
95
183
  };
96
- return s && e === "message/stream" && (n.tokenStreaming = !0), n;
184
+ return e && s === "message/stream" && (n.tokenStreaming = !0), n;
97
185
  }
98
- function U(t) {
99
- return !t || !t.parts || !Array.isArray(t.parts) ? "" : t.parts.filter((e) => e.type === "text").map((e) => e.text).join(" ");
186
+ function $(t) {
187
+ return !t || !t.parts || !Array.isArray(t.parts) ? "" : t.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
100
188
  }
101
- function Vt(t) {
189
+ function $t(t) {
102
190
  return {
103
191
  type: "data",
104
192
  data: {
@@ -110,23 +198,23 @@ function Vt(t) {
110
198
  metadata: {}
111
199
  };
112
200
  }
113
- function J(t) {
201
+ function F(t) {
114
202
  return !t || !t.parts || !Array.isArray(t.parts) ? [] : t.parts.filter(
115
- (e) => e.type === "data" && "toolCallId" in e.data && "toolId" in e.data && "arguments" in e.data
203
+ (s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
116
204
  );
117
205
  }
118
- function W(t, e, s, n) {
206
+ function J(t, s, e, n) {
119
207
  return {
120
208
  type: "data",
121
209
  data: {
122
210
  toolCallId: t,
123
- toolId: e,
124
- result: s
211
+ toolId: s,
212
+ result: e
125
213
  },
126
214
  metadata: n ? { error: n } : void 0
127
215
  };
128
216
  }
129
- function zt(t) {
217
+ function Dt(t) {
130
218
  return {
131
219
  type: "data",
132
220
  data: {
@@ -135,29 +223,29 @@ function zt(t) {
135
223
  metadata: {}
136
224
  };
137
225
  }
138
- function rt(t) {
226
+ function ot(t) {
139
227
  return {
140
228
  role: "user",
141
- parts: [Tt(t)],
229
+ parts: [wt(t)],
142
230
  kind: "message",
143
- messageId: D(),
231
+ messageId: O(),
144
232
  metadata: {
145
233
  timestamp: Date.now()
146
234
  }
147
235
  };
148
236
  }
149
- function Z(t) {
237
+ function L(t) {
150
238
  return {
151
239
  role: "agent",
152
- parts: [Tt(t)],
240
+ parts: [wt(t)],
153
241
  kind: "message",
154
- messageId: D(),
242
+ messageId: O(),
155
243
  metadata: {
156
244
  timestamp: Date.now()
157
245
  }
158
246
  };
159
247
  }
160
- function ct(t) {
248
+ function it(t) {
161
249
  return t && typeof t == "object" && "result" in t ? {
162
250
  result: t.result,
163
251
  returnToAgent: t.returnToAgent !== !1,
@@ -169,196 +257,196 @@ function ct(t) {
169
257
  returnToAgent: !0
170
258
  };
171
259
  }
172
- function et(t, e = []) {
260
+ function Q(t, s = []) {
173
261
  return {
174
262
  role: "user",
175
263
  kind: "message",
176
- parts: [...e, ...t],
177
- messageId: D(),
264
+ parts: [...s, ...t],
265
+ messageId: O(),
178
266
  metadata: {
179
267
  timestamp: Date.now()
180
268
  }
181
269
  };
182
270
  }
183
- function Ge() {
271
+ function ke() {
184
272
  return new AbortController();
185
273
  }
186
- async function Gt(t, e) {
187
- if (!e)
274
+ async function Ft(t, s) {
275
+ if (!s)
188
276
  return t;
189
277
  try {
190
- const s = await e.getAvailableTools();
191
- if (s.length === 0)
278
+ const e = await s.getAvailableTools();
279
+ if (e.length === 0)
192
280
  return t;
193
- const n = s.map(Vt);
281
+ const n = e.map($t);
194
282
  return {
195
283
  ...t,
196
284
  parts: [...t.parts, ...n]
197
285
  };
198
- } catch (s) {
199
- return N("Warning: Failed to get tools: %s", s), t;
286
+ } catch (e) {
287
+ return k("Warning: Failed to get tools: %s", e), t;
200
288
  }
201
289
  }
202
- function Qt(t, e) {
203
- if (!e)
290
+ function Ut(t, s) {
291
+ if (!s)
204
292
  return t;
205
293
  try {
206
- const s = e.getClientContext();
207
- if (!s || Object.keys(s).length === 0)
294
+ const e = s.getClientContext();
295
+ if (!e || Object.keys(e).length === 0)
208
296
  return t;
209
- const n = zt(s);
297
+ const n = Dt(e);
210
298
  return {
211
299
  ...t,
212
300
  parts: [...t.parts, n]
213
301
  };
214
- } catch (s) {
215
- return N("Warning: Failed to get context: %s", s), t;
302
+ } catch (e) {
303
+ return k("Warning: Failed to get context: %s", e), t;
216
304
  }
217
305
  }
218
- async function Xt(t, e, s) {
219
- let n = await Gt(
306
+ async function Jt(t, s, e) {
307
+ let n = await Ft(
220
308
  t,
221
- e
309
+ s
222
310
  );
223
- n = Qt(
311
+ n = Ut(
224
312
  n,
225
- s
313
+ e
226
314
  );
227
- const { metadata: a, ...r } = n;
315
+ const { metadata: o, ...r } = n;
228
316
  return r;
229
317
  }
230
- function Yt(t, e = "") {
231
- const s = [], n = e + t;
232
- let a = "", r = 0, o = 0;
233
- for (; o < n.length; ) {
234
- const l = n.indexOf(
318
+ function jt(t, s = "") {
319
+ const e = [], n = s + t;
320
+ let o = "", r = 0, a = 0;
321
+ for (; a < n.length; ) {
322
+ const i = n.indexOf(
235
323
  `
236
324
  `,
237
- o
238
- ), c = l === -1 ? n.substring(o) : n.substring(o, l);
239
- if (c.startsWith("data:"))
240
- a !== "" && (a += `
241
- `), a += c.substring(
242
- c.startsWith("data: ") ? 6 : 5
325
+ a
326
+ ), d = i === -1 ? n.substring(a) : n.substring(a, i);
327
+ if (d.startsWith("data:"))
328
+ o !== "" && (o += `
329
+ `), o += d.substring(
330
+ d.startsWith("data: ") ? 6 : 5
243
331
  );
244
- else if (c.trim() === "" && a) {
332
+ else if (d.trim() === "" && o) {
245
333
  try {
246
- s.push(JSON.parse(a)), r = l === -1 ? n.length : l + 1;
247
- } catch (g) {
248
- N("Failed to parse SSE event: %o", g), N("Problematic payload: %s", a);
334
+ e.push(JSON.parse(o)), r = i === -1 ? n.length : i + 1;
335
+ } catch (c) {
336
+ k("Failed to parse SSE event: %o", c), k("Problematic payload: %s", o);
249
337
  }
250
- a = "";
338
+ o = "";
251
339
  }
252
- l === -1 ? o = n.length : o = l + 1;
340
+ i === -1 ? a = n.length : a = i + 1;
253
341
  }
254
- const i = n.substring(r);
255
- return { events: s, nextBuffer: i };
342
+ const l = n.substring(r);
343
+ return { events: e, nextBuffer: l };
256
344
  }
257
- async function* Zt(t, e = {}) {
258
- var c, g, y;
259
- const { supportDeltas: s = !1 } = e, n = t.getReader(), a = new TextDecoder();
345
+ async function* Kt(t, s = {}) {
346
+ var d, c, g;
347
+ const { supportDeltas: e = !1 } = s, n = t.getReader(), o = new TextDecoder();
260
348
  let r = "";
261
- const o = new te();
262
- let i = null, l = null;
349
+ const a = new Lt();
350
+ let l = null, i = null;
263
351
  try {
264
352
  for (; ; ) {
265
- const { done: b, value: A } = await n.read();
266
- if (b)
353
+ const { done: h, value: T } = await n.read();
354
+ if (h)
267
355
  break;
268
- const S = a.decode(A, { stream: !0 }), { events: M, nextBuffer: x } = Yt(S, r);
269
- if (M && Array.isArray(M))
270
- for (let p = 0; p < M.length; p++) {
271
- const u = M[p];
272
- if (p > 0 && u.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((h) => {
273
- requestAnimationFrame(() => h(void 0));
356
+ const M = o.decode(T, { stream: !0 }), { events: p, nextBuffer: m } = jt(M, r);
357
+ if (p && Array.isArray(p))
358
+ for (let y = 0; y < p.length; y++) {
359
+ const u = p[y];
360
+ if (y > 0 && u.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((w) => {
361
+ requestAnimationFrame(() => w(void 0));
274
362
  }), u.error)
275
363
  throw new Error(
276
364
  `Streaming error: ${u.error.message}`
277
365
  );
278
- if (s && u.method === "message/delta" && ((c = u.params) != null && c.delta)) {
279
- const h = u.params.delta;
366
+ if (e && u.method === "message/delta" && ((d = u.params) != null && d.delta)) {
367
+ const w = u.params.delta;
280
368
  try {
281
- if (h.deltaType === "content" && (o.processContentDelta(
282
- h.content
283
- ), !i && u.params.id && (i = u.params.id), i)) {
284
- const d = o.getCurrentMessage();
369
+ if (w.deltaType === "content" && (a.processContentDelta(
370
+ w.content
371
+ ), !l && u.params.id && (l = u.params.id), l)) {
372
+ const S = a.getCurrentMessage();
285
373
  yield {
286
- id: i,
374
+ id: l,
287
375
  status: {
288
376
  state: "working",
289
- message: d
377
+ message: S
290
378
  },
291
379
  final: !1,
292
- text: o.getTextContent()
380
+ text: a.getTextContent()
293
381
  };
294
382
  }
295
- } catch (d) {
296
- N("Failed to process delta: %o", d);
383
+ } catch (S) {
384
+ k("Failed to process delta: %o", S);
297
385
  }
298
- } else u.result && u.result.status ? (i = u.result.id, l = u.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset(), yield {
386
+ } else u.result && u.result.status ? (l = u.result.id, i = u.result.status, (a.getTextContent() || a.getCurrentMessage().parts.length > 0) && a.reset(), yield {
299
387
  id: u.result.id,
300
388
  status: u.result.status,
301
389
  final: u.result.status.state === "completed" || u.result.status.state === "failed" || u.result.status.state === "canceled",
302
- text: U(
303
- ((g = u.result.status) == null ? void 0 : g.message) || {
390
+ text: $(
391
+ ((c = u.result.status) == null ? void 0 : c.message) || {
304
392
  role: "agent",
305
393
  parts: []
306
394
  }
307
395
  )
308
- }) : u.id && u.result && (i = u.result.id, u.result.status && (yield {
396
+ }) : u.id && u.result && (l = u.result.id, u.result.status && (yield {
309
397
  id: u.result.id,
310
398
  status: u.result.status,
311
399
  final: u.result.status.state === "completed" || u.result.status.state === "failed" || u.result.status.state === "canceled",
312
- text: U(
313
- ((y = u.result.status) == null ? void 0 : y.message) || {
400
+ text: $(
401
+ ((g = u.result.status) == null ? void 0 : g.message) || {
314
402
  role: "agent",
315
403
  parts: []
316
404
  }
317
405
  )
318
406
  }));
319
407
  }
320
- r = x;
408
+ r = m;
321
409
  }
322
410
  } finally {
323
411
  n.releaseLock();
324
412
  }
325
413
  }
326
- class te {
414
+ class Lt {
327
415
  constructor() {
328
- at(this, "textContent", "");
329
- at(this, "toolCalls", /* @__PURE__ */ new Map());
416
+ Z(this, "textContent", "");
417
+ Z(this, "toolCalls", /* @__PURE__ */ new Map());
330
418
  }
331
419
  /**
332
420
  * Process a simple content delta (server's actual format)
333
421
  * @param content - The text content to append
334
422
  */
335
- processContentDelta(e) {
336
- this.textContent += e;
423
+ processContentDelta(s) {
424
+ this.textContent += s;
337
425
  }
338
426
  /**
339
427
  * Process a delta message and accumulate the content (original format)
340
428
  * @param delta - The delta message to process
341
429
  */
342
- processDelta(e) {
343
- switch (e.type) {
430
+ processDelta(s) {
431
+ switch (s.type) {
344
432
  case "content":
345
- this.textContent += e.content;
433
+ this.textContent += s.content;
346
434
  break;
347
435
  case "tool_name":
348
- this.toolCalls.has(e.toolCallIndex) || this.toolCalls.set(e.toolCallIndex, {
349
- toolCallId: e.toolCallId,
436
+ this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
437
+ toolCallId: s.toolCallId,
350
438
  toolName: "",
351
439
  argumentFragments: []
352
440
  });
353
- const s = this.toolCalls.get(e.toolCallIndex);
354
- s.toolName += e.content;
441
+ const e = this.toolCalls.get(s.toolCallIndex);
442
+ e.toolName += s.content;
355
443
  break;
356
444
  case "tool_argument":
357
- this.toolCalls.has(e.toolCallIndex) || this.toolCalls.set(e.toolCallIndex, {
358
- toolCallId: e.toolCallId,
445
+ this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
446
+ toolCallId: s.toolCallId,
359
447
  toolName: "",
360
448
  argumentFragments: []
361
- }), this.toolCalls.get(e.toolCallIndex).argumentFragments.push(e.content);
449
+ }), this.toolCalls.get(s.toolCallIndex).argumentFragments.push(s.content);
362
450
  break;
363
451
  }
364
452
  }
@@ -372,36 +460,36 @@ class te {
372
460
  * Get the current accumulated message
373
461
  * @param role - The role for the message (default: 'agent')
374
462
  */
375
- getCurrentMessage(e = "agent") {
376
- const s = [];
377
- this.textContent && s.push({
463
+ getCurrentMessage(s = "agent") {
464
+ const e = [];
465
+ this.textContent && e.push({
378
466
  type: "text",
379
467
  text: this.textContent
380
468
  });
381
- for (const [n, a] of this.toolCalls)
382
- if (a.toolName) {
383
- const r = a.argumentFragments.join("");
384
- let o = {};
469
+ for (const [n, o] of this.toolCalls)
470
+ if (o.toolName) {
471
+ const r = o.argumentFragments.join("");
472
+ let a = {};
385
473
  if (r)
386
474
  try {
387
- o = JSON.parse(r);
475
+ a = JSON.parse(r);
388
476
  } catch {
389
- o = { _raw: r };
477
+ a = { _raw: r };
390
478
  }
391
- s.push({
479
+ e.push({
392
480
  type: "data",
393
481
  data: {
394
- toolCallId: a.toolCallId,
395
- toolId: a.toolName,
396
- arguments: o
482
+ toolCallId: o.toolCallId,
483
+ toolId: o.toolName,
484
+ arguments: a
397
485
  }
398
486
  });
399
487
  }
400
488
  return {
401
- role: e,
402
- parts: s,
489
+ role: s,
490
+ parts: e,
403
491
  kind: "message",
404
- messageId: D()
492
+ messageId: O()
405
493
  };
406
494
  }
407
495
  /**
@@ -411,154 +499,154 @@ class te {
411
499
  this.textContent = "", this.toolCalls.clear();
412
500
  }
413
501
  }
414
- function bt(t, e, s = "request") {
415
- throw clearTimeout(e), N("%s failed with error: %O", s, t), t instanceof Error && (N("Error message: %s", t.message), N("Error stack: %s", t.stack)), t;
502
+ function It(t, s, e = "request") {
503
+ throw clearTimeout(s), k("%s failed with error: %O", e, t), t instanceof Error && (k("Error message: %s", t.message), k("Error stack: %s", t.stack)), t;
416
504
  }
417
- function St(t, e = "request") {
505
+ function Tt(t, s = "request") {
418
506
  if (!t.ok)
419
507
  throw new Error(`HTTP error! status: ${t.status}`);
420
508
  }
421
- function ee(t, e = "request") {
509
+ function Wt(t, s = "request") {
422
510
  if (t.error)
423
- throw new Error(`A2A ${e} error: ${t.error.message}`);
511
+ throw new Error(`A2A ${s} error: ${t.error.message}`);
424
512
  if (!t.result)
425
- throw new Error(`No result in ${e} response`);
513
+ throw new Error(`No result in ${s} response`);
426
514
  return t.result;
427
515
  }
428
- function se(t, e = "streaming request") {
429
- if (St(t, e), !t.body)
430
- throw new Error(`No response body for ${e}`);
516
+ function Vt(t, s = "streaming request") {
517
+ if (Tt(t, s), !t.body)
518
+ throw new Error(`No response body for ${s}`);
431
519
  }
432
- function kt(t, e = "request") {
433
- const s = new AbortController();
520
+ function Ct(t, s = "request") {
521
+ const e = new AbortController();
434
522
  return { timeoutId: setTimeout(
435
- () => s.abort(),
523
+ () => e.abort(),
436
524
  t
437
- ), controller: s };
525
+ ), controller: e };
438
526
  }
439
- function ne(t, e) {
440
- return `${t}/${e}`;
527
+ function Bt(t, s) {
528
+ return `${t}/${s}`;
441
529
  }
442
- function ae(t, e, s, n) {
443
- N("Request: %s %s", t, e), N("Headers: %o", s), n && N("Body: %s", Mt(n));
530
+ function zt(t, s, e, n) {
531
+ k("Request: %s %s", t, s), k("Headers: %o", e), n && k("Body: %s", yt(n));
444
532
  }
445
- async function oe(t, e = !1) {
446
- const s = {
533
+ async function Gt(t, s = !1) {
534
+ const e = {
447
535
  "Content-Type": "application/json"
448
536
  };
449
- if (e && (s.Accept = "text/event-stream"), t) {
537
+ if (s && (e.Accept = "text/event-stream"), t) {
450
538
  const n = await t();
451
- return { ...s, ...n };
539
+ return { ...e, ...n };
452
540
  }
453
- return s;
541
+ return e;
454
542
  }
455
- function At(t, e) {
456
- if (!e)
543
+ function xt(t, s) {
544
+ if (!s)
457
545
  return t;
458
- const s = new AbortController(), n = (a) => {
459
- s.signal.aborted || s.abort(a.reason);
546
+ const e = new AbortController(), n = (o) => {
547
+ e.signal.aborted || e.abort(o.reason);
460
548
  };
461
- return t.aborted ? s.abort(t.reason) : t.addEventListener("abort", () => n(t), {
549
+ return t.aborted ? e.abort(t.reason) : t.addEventListener("abort", () => n(t), {
462
550
  once: !0
463
- }), e.aborted ? s.abort(e.reason) : e.addEventListener("abort", () => n(e), {
551
+ }), s.aborted ? e.abort(s.reason) : s.addEventListener("abort", () => n(s), {
464
552
  once: !0
465
- }), s.signal;
553
+ }), e.signal;
466
554
  }
467
- function vt(t, e, s) {
555
+ function Mt(t, s, e) {
468
556
  return {
469
557
  method: "POST",
470
558
  headers: t,
471
- body: e,
472
- signal: s
559
+ body: s,
560
+ signal: e
473
561
  };
474
562
  }
475
- async function st(t, e, s, n, a, r) {
476
- const { message: o, sessionId: i, taskId: l, metadata: c } = t, { agentId: g, agentUrl: y, authProvider: b, proxy: A } = e, { isStreaming: S = !1, enableTokenStreaming: M = !1 } = s, x = i || r, p = ne(y, g), u = await Xt(
477
- o,
563
+ async function X(t, s, e, n, o, r) {
564
+ const { message: a, sessionId: l, taskId: i, metadata: d } = t, { agentId: c, agentUrl: g, authProvider: h, proxy: T } = s, { isStreaming: M = !1, enableTokenStreaming: p = !1 } = e, m = l || r, y = Bt(g, c), u = await Jt(
565
+ a,
478
566
  n,
479
- a
480
- ), h = Kt(
567
+ o
568
+ ), w = Ht(
481
569
  {
482
- id: l,
483
- sessionId: x,
570
+ id: i,
571
+ sessionId: m,
484
572
  message: u,
485
- metadata: c
573
+ metadata: d
486
574
  },
487
- S ? "message/stream" : "message/send",
488
- M && S
575
+ M ? "message/stream" : "message/send",
576
+ p && M
489
577
  // Only enable token streaming if using SSE
490
- ), d = await oe(b, S);
491
- return ae("POST", p, d, h), {
492
- request: h,
493
- headers: d,
578
+ ), S = await Gt(h, M);
579
+ return zt("POST", y, S, w), {
580
+ request: w,
581
+ headers: S,
494
582
  enhancedMessage: u,
495
- effectiveSessionId: x,
496
- fullAgentUrl: p
583
+ effectiveSessionId: m,
584
+ fullAgentUrl: y
497
585
  };
498
586
  }
499
- async function Rt(t, e, s = {}) {
500
- const { request: n, headers: a, fullAgentUrl: r } = t, { timeout: o } = e, { abortSignal: i } = s, { timeoutId: l, controller: c } = kt(
501
- o,
587
+ async function St(t, s, e = {}) {
588
+ const { request: n, headers: o, fullAgentUrl: r } = t, { timeout: a } = s, { abortSignal: l } = e, { timeoutId: i, controller: d } = Ct(
589
+ a,
502
590
  "request"
503
- ), g = i ? At(c.signal, i) : c.signal;
591
+ ), c = l ? xt(d.signal, l) : d.signal;
504
592
  try {
505
- const y = vt(
506
- a,
593
+ const g = Mt(
594
+ o,
507
595
  JSON.stringify(n),
508
- g
596
+ c
509
597
  );
510
- N("Making request to %s with options: %O", r, {
511
- method: y.method,
512
- headers: y.headers
598
+ k("Making request to %s with options: %O", r, {
599
+ method: g.method,
600
+ headers: g.headers
513
601
  });
514
- const b = await fetch(r, y);
515
- clearTimeout(l), St(b, "request");
516
- const A = await b.json();
517
- return N(
602
+ const h = await fetch(r, g);
603
+ clearTimeout(i), Tt(h, "request");
604
+ const T = await h.json();
605
+ return k(
518
606
  "Response from %s: %d %O",
519
607
  r,
520
- b.status,
521
- Mt(A)
522
- ), ee(A, "request");
523
- } catch (y) {
524
- bt(y, l, "request");
608
+ h.status,
609
+ yt(T)
610
+ ), Wt(T, "request");
611
+ } catch (g) {
612
+ It(g, i, "request");
525
613
  }
526
614
  }
527
- async function* Et(t, e, s) {
528
- const { request: n, headers: a, fullAgentUrl: r } = t, {
529
- streamingTimeout: o = 6e4,
530
- abortSignal: i,
531
- enableTokenStreaming: l = !1
532
- } = s, { timeoutId: c, controller: g } = kt(
533
- o,
615
+ async function* bt(t, s, e) {
616
+ const { request: n, headers: o, fullAgentUrl: r } = t, {
617
+ streamingTimeout: a = 6e4,
618
+ abortSignal: l,
619
+ enableTokenStreaming: i = !1
620
+ } = e, { timeoutId: d, controller: c } = Ct(
621
+ a,
534
622
  "streaming request"
535
- ), y = i ? At(g.signal, i) : g.signal;
623
+ ), g = l ? xt(c.signal, l) : c.signal;
536
624
  try {
537
- const b = JSON.stringify(n), A = vt(a, b, y), S = await fetch(r, A);
538
- if (clearTimeout(c), se(S, "streaming request"), !S.body)
625
+ const h = JSON.stringify(n), T = Mt(o, h, g), M = await fetch(r, T);
626
+ if (clearTimeout(d), Vt(M, "streaming request"), !M.body)
539
627
  throw new Error(
540
628
  "Response body is null - server may not support streaming"
541
629
  );
542
- const M = l && n.tokenStreaming === !0;
543
- yield* Zt(S.body, {
544
- supportDeltas: M
630
+ const p = i && n.tokenStreaming === !0;
631
+ yield* Kt(M.body, {
632
+ supportDeltas: p
545
633
  });
546
- } catch (b) {
547
- bt(b, c, "streaming request");
634
+ } catch (h) {
635
+ It(h, d, "streaming request");
548
636
  }
549
637
  }
550
- const re = 12e4, ut = /* @__PURE__ */ new Map();
551
- async function ie(t, e) {
552
- if (!t || !e || !t.getAvailableTools)
638
+ const Qt = 12e4, lt = /* @__PURE__ */ new Map();
639
+ async function Xt(t, s) {
640
+ if (!t || !s || !t.getAvailableTools)
553
641
  return !1;
554
- const s = J(e);
555
- if (s.length === 0)
642
+ const e = F(s);
643
+ if (e.length === 0)
556
644
  return !1;
557
645
  try {
558
646
  const n = await t.getAvailableTools();
559
- for (const a of s)
647
+ for (const o of e)
560
648
  if (n.some(
561
- (o) => o.id === a.data.toolId
649
+ (a) => a.id === o.data.toolId
562
650
  ))
563
651
  return !0;
564
652
  } catch {
@@ -566,146 +654,146 @@ async function ie(t, e) {
566
654
  }
567
655
  return !1;
568
656
  }
569
- function le() {
570
- ut.clear();
657
+ function Yt() {
658
+ lt.clear();
571
659
  }
572
- function ce(t) {
573
- return t.map((e) => {
574
- const s = e.data.toolCallId, n = ut.get(s);
660
+ function Zt(t) {
661
+ return t.map((s) => {
662
+ const e = s.data.toolCallId, n = lt.get(e);
575
663
  if (n && n.resolvedValue !== null) {
576
- const a = n.resolvedValue;
577
- return a.error ? W(
578
- s,
579
- e.data.toolId,
664
+ const o = n.resolvedValue;
665
+ return o.error ? J(
666
+ e,
667
+ s.data.toolId,
580
668
  void 0,
581
- a.error
582
- ) : W(
583
- s,
584
- e.data.toolId,
585
- a
669
+ o.error
670
+ ) : J(
671
+ e,
672
+ s.data.toolId,
673
+ o
586
674
  );
587
675
  }
588
- return e;
676
+ return s;
589
677
  });
590
678
  }
591
- async function Pt(t, e, s) {
592
- const n = [], a = [];
679
+ async function At(t, s, e) {
680
+ const n = [], o = [];
593
681
  let r = !1;
594
- for (const o of t) {
595
- const { toolCallId: i, toolId: l, arguments: c } = o.data;
682
+ for (const a of t) {
683
+ const { toolCallId: l, toolId: i, arguments: d } = a.data;
596
684
  try {
597
- const g = await e.executeTool(
598
- l,
599
- c,
600
- s,
601
- i
602
- ), { result: y, returnToAgent: b, agentMessage: A } = ct(g);
603
- b && (r = !0), A && a.push(Z(A)), n.push(
604
- W(
605
- i,
685
+ const c = await s.executeTool(
686
+ i,
687
+ d,
688
+ e,
689
+ l
690
+ ), { result: g, returnToAgent: h, agentMessage: T } = it(c);
691
+ h && (r = !0), T && o.push(L(T)), n.push(
692
+ J(
606
693
  l,
607
- y
694
+ i,
695
+ g
608
696
  )
609
697
  );
610
- } catch (g) {
698
+ } catch (c) {
611
699
  r = !0, n.push(
612
- W(
613
- i,
700
+ J(
614
701
  l,
702
+ i,
615
703
  void 0,
616
- g instanceof Error ? g.message : String(g)
704
+ c instanceof Error ? c.message : String(c)
617
705
  )
618
706
  );
619
707
  }
620
708
  }
621
- return { results: n, shouldReturnToAgent: r, agentMessages: a };
709
+ return { results: n, shouldReturnToAgent: r, agentMessages: o };
622
710
  }
623
- function pt(t) {
624
- const e = [];
625
- for (const s of t)
626
- for (const n of s.parts)
627
- n.type === "text" ? e.push({
711
+ function gt(t) {
712
+ const s = [];
713
+ for (const e of t)
714
+ for (const n of e.parts)
715
+ n.type === "text" ? s.push({
628
716
  type: "data",
629
717
  data: {
630
- role: s.role,
718
+ role: e.role,
631
719
  text: n.text
632
720
  }
633
- }) : n.type === "data" && e.push(n);
634
- return e;
721
+ }) : n.type === "data" && s.push(n);
722
+ return s;
635
723
  }
636
- async function ot(t, e, s, n, a, r, o) {
637
- const l = await st(
724
+ async function et(t, s, e, n, o, r, a) {
725
+ const i = await X(
638
726
  {
639
- message: e,
727
+ message: s,
640
728
  taskId: t,
641
729
  sessionId: void 0
642
730
  // Use task's session
643
731
  },
644
- s,
732
+ e,
645
733
  { isStreaming: !1 },
646
734
  n,
647
- a,
735
+ o,
648
736
  r
649
737
  );
650
- return await Rt(l, s, {
651
- abortSignal: o
738
+ return await St(i, e, {
739
+ abortSignal: a
652
740
  });
653
741
  }
654
- async function yt(t, e, s, n, a, r, o, i) {
655
- const l = {
656
- message: e,
742
+ async function ft(t, s, e, n, o, r, a, l, i = []) {
743
+ const d = {
744
+ message: s,
657
745
  taskId: t,
658
746
  sessionId: void 0
659
747
  // Use task's session
660
- }, c = i || { isStreaming: !0 }, g = await st(
661
- l,
662
- s,
748
+ }, c = l || { isStreaming: !0 }, g = await X(
749
+ d,
750
+ e,
663
751
  {
664
752
  ...c
665
753
  },
666
754
  n,
667
- a,
755
+ o,
668
756
  r
669
- ), y = Et(g, s, {
757
+ ), h = bt(g, e, {
670
758
  ...c,
671
- abortSignal: o
759
+ abortSignal: a
672
760
  });
673
- return Ot(
674
- y,
761
+ return vt(
762
+ h,
675
763
  n,
676
- a,
677
- s,
764
+ o,
765
+ e,
678
766
  r,
679
767
  !0,
680
768
  // withHistory
681
- [],
682
- // newConversationParts - empty for continueTask
683
- o,
769
+ i,
770
+ // preserve conversation parts across continuation
771
+ a,
684
772
  c
685
773
  // Pass through the same request options
686
774
  );
687
775
  }
688
- async function* Ot(t, e, s, n, a, r = !0, o = [], i, l) {
689
- var c, g, y, b, A, S, M, x, p, u, h, d;
776
+ async function* vt(t, s, e, n, o, r = !0, a = [], l, i) {
777
+ var d, c, g, h, T, M, p, m, y, u, w, S;
690
778
  for await (const f of t) {
691
- if (yield f, f.status.state === "running" && f.status.message && e && await ie(
692
- e,
779
+ if (yield f, f.status.state === "running" && f.status.message && s && await Xt(
780
+ s,
693
781
  f.status.message
694
782
  )) {
695
- const T = J(
783
+ const C = F(
696
784
  f.status.message
697
785
  );
698
- for (const I of T) {
699
- const { toolCallId: P, toolId: w, arguments: m } = I.data;
700
- e.executeTool(
701
- w,
702
- m,
703
- (g = (c = f.status) == null ? void 0 : c.message) == null ? void 0 : g.messageId,
704
- P
705
- ).catch((k) => {
786
+ for (const I of C) {
787
+ const { toolCallId: b, toolId: x, arguments: _ } = I.data;
788
+ s.executeTool(
789
+ x,
790
+ _,
791
+ (c = (d = f.status) == null ? void 0 : d.message) == null ? void 0 : c.messageId,
792
+ b
793
+ ).catch((N) => {
706
794
  console.error(
707
- `Tool execution failed for ${w}:`,
708
- k
795
+ `Tool execution failed for ${x}:`,
796
+ N
709
797
  );
710
798
  });
711
799
  }
@@ -716,182 +804,183 @@ async function* Ot(t, e, s, n, a, r = !0, o = [], i, l) {
716
804
  message: {
717
805
  role: "agent",
718
806
  kind: "message",
719
- parts: T,
720
- messageId: D()
807
+ parts: C,
808
+ messageId: O()
721
809
  }
722
810
  },
723
811
  final: !1,
724
812
  text: ""
725
813
  };
726
814
  }
727
- if (f.status.state === "input-required" && f.status.message && e) {
728
- const T = J(
815
+ if (f.status.state === "input-required" && f.status.message && s) {
816
+ const C = F(
729
817
  f.status.message
730
818
  );
731
- if (T.length > 0) {
819
+ if (C.length > 0) {
732
820
  const I = [];
733
- let P = !1;
734
- const w = [], m = [];
735
- for (const k of T) {
821
+ let b = !1;
822
+ const x = [], _ = [];
823
+ for (const N of C) {
736
824
  const {
737
- toolCallId: C,
738
- toolId: E,
739
- arguments: R
740
- } = k.data;
825
+ toolCallId: R,
826
+ toolId: P,
827
+ arguments: A
828
+ } = N.data;
741
829
  try {
742
- const O = await e.executeTool(
743
- E,
744
- R,
745
- (b = (y = f.status) == null ? void 0 : y.message) == null ? void 0 : b.messageId,
746
- C
747
- ), { result: v, returnToAgent: F, agentMessage: B } = ct(O);
748
- if (F && (P = !0), B && m.push(
749
- Z(B)
830
+ const E = await s.executeTool(
831
+ P,
832
+ A,
833
+ (h = (g = f.status) == null ? void 0 : g.message) == null ? void 0 : h.messageId,
834
+ R
835
+ ), { result: v, returnToAgent: D, agentMessage: W } = it(E);
836
+ if (D && (b = !0), W && _.push(
837
+ L(W)
750
838
  ), v.result instanceof Promise) {
751
- const K = v.result, z = {
752
- promise: K,
839
+ const B = v.result, j = {
840
+ promise: B,
753
841
  resolvedValue: null
754
842
  };
755
- ut.set(
756
- C,
757
- z
758
- ), K.then((q) => {
759
- z.resolvedValue = q;
843
+ lt.set(
844
+ R,
845
+ j
846
+ ), B.then((q) => {
847
+ j.resolvedValue = q;
760
848
  }).catch((q) => {
761
849
  console.error(
762
- `Promise rejected for tool call ${C}:`,
850
+ `Promise rejected for tool call ${R}:`,
763
851
  q
764
- ), z.resolvedValue = {
852
+ ), j.resolvedValue = {
765
853
  error: q instanceof Error ? q.message : String(q)
766
854
  };
767
855
  });
768
856
  }
769
- const _ = W(
770
- C,
771
- E,
857
+ const V = J(
858
+ R,
859
+ P,
772
860
  v
773
861
  );
774
- I.push(_), w.push(_);
775
- } catch (O) {
776
- const v = W(
777
- C,
778
- E,
862
+ I.push(V), x.push(V);
863
+ } catch (E) {
864
+ const v = J(
865
+ R,
866
+ P,
779
867
  void 0,
780
- O instanceof Error ? O.message : String(O)
868
+ E instanceof Error ? E.message : String(E)
781
869
  );
782
- I.push(v), w.push(v);
870
+ I.push(v), x.push(v);
783
871
  }
784
872
  }
785
- if (o.push(f.status.message), P) {
786
- const k = pt(o), C = et(
787
- I,
788
- k
873
+ if (a.push(f.status.message), I.length > 0 && a.push({
874
+ role: "agent",
875
+ kind: "message",
876
+ parts: I,
877
+ messageId: O()
878
+ }), b) {
879
+ const N = gt(a), R = Q(
880
+ [],
881
+ // Empty array - tool results are already in historyDataParts
882
+ N
789
883
  );
790
884
  yield {
791
885
  id: f.id,
792
886
  status: {
793
887
  state: "working",
794
- message: C
888
+ message: R
795
889
  },
796
890
  final: !1,
797
891
  text: ""
798
892
  };
799
- const E = await yt(
893
+ const P = await ft(
800
894
  f.id,
801
- C,
895
+ R,
802
896
  n,
803
- e,
804
897
  s,
805
- a,
898
+ e,
899
+ o,
900
+ l,
806
901
  i,
807
- l
902
+ a
808
903
  );
809
- let R = null;
810
- for await (const F of E)
811
- F.final ? R = F : yield F;
812
- if (!R)
904
+ let A = null;
905
+ for await (const D of P)
906
+ D.final ? A = D : yield D;
907
+ if (!A)
813
908
  throw new Error(
814
909
  "Continue task stream ended without final result"
815
910
  );
816
- let O = (A = R.status) != null && A.message ? J(
817
- R.status.message
818
- ) : [];
819
- I.length > 0 && o.push({
820
- role: "agent",
821
- kind: "message",
822
- parts: I,
823
- messageId: D()
824
- });
825
- let v = R;
826
- if (O.length > 0)
911
+ let E = (T = A.status) != null && T.message ? F(
912
+ A.status.message
913
+ ) : [], v = A;
914
+ if (E.length > 0)
827
915
  for (yield {
828
- ...R,
916
+ ...A,
829
917
  final: !1,
830
- text: U(
831
- ((S = R.status) == null ? void 0 : S.message) || {
918
+ text: $(
919
+ ((M = A.status) == null ? void 0 : M.message) || {
832
920
  parts: [],
833
- messageId: D()
921
+ messageId: O()
834
922
  }
835
923
  )
836
- }; O.length > 0; ) {
837
- (M = v.status) != null && M.message && o.push(
924
+ }; E.length > 0; ) {
925
+ (p = v.status) != null && p.message && a.push(
838
926
  v.status.message
839
927
  );
840
928
  const {
841
- results: F,
842
- shouldReturnToAgent: B
843
- } = await Pt(
844
- O,
845
- e,
846
- (p = (x = v.status) == null ? void 0 : x.message) == null ? void 0 : p.messageId
929
+ results: D,
930
+ shouldReturnToAgent: W
931
+ } = await At(
932
+ E,
933
+ s,
934
+ (y = (m = v.status) == null ? void 0 : m.message) == null ? void 0 : y.messageId
847
935
  );
848
- if (F.length > 0 && (yield {
936
+ if (D.length > 0 && (yield {
849
937
  id: v.id,
850
938
  status: {
851
939
  state: "working",
852
940
  message: {
853
941
  role: "agent",
854
942
  kind: "message",
855
- parts: F,
856
- messageId: D()
943
+ parts: D,
944
+ messageId: O()
857
945
  }
858
946
  // Simple message with just the results
859
947
  },
860
948
  final: !1,
861
949
  text: ""
862
- }), B) {
863
- const _ = r ? pt(
864
- o
865
- ) : [], K = et(
866
- F,
867
- _
868
- ), z = await yt(
950
+ }), W) {
951
+ const V = r ? gt(
952
+ a
953
+ ) : [], B = Q(
954
+ D,
955
+ V
956
+ ), j = await ft(
869
957
  v.id,
870
- K,
958
+ B,
871
959
  n,
872
- e,
873
960
  s,
874
- a,
961
+ e,
962
+ o,
963
+ l,
875
964
  i,
876
- l
965
+ a
877
966
  );
878
967
  let q = null;
879
- for await (const nt of z)
880
- nt.final ? q = nt : yield nt;
968
+ for await (const Y of j)
969
+ Y.final ? q = Y : yield Y;
881
970
  if (!q)
882
971
  throw new Error(
883
972
  "Continue task stream ended without final result"
884
973
  );
885
- v = q, O = (u = v.status) != null && u.message ? J(
974
+ v = q, E = (u = v.status) != null && u.message ? F(
886
975
  v.status.message
887
- ) : [], O.length > 0 && (yield {
976
+ ) : [], E.length > 0 && (yield {
888
977
  id: v.id,
889
978
  status: v.status,
890
979
  final: !1,
891
- text: U(
892
- ((h = v.status) == null ? void 0 : h.message) || {
980
+ text: $(
981
+ ((w = v.status) == null ? void 0 : w.message) || {
893
982
  parts: [],
894
- messageId: D()
983
+ messageId: O()
895
984
  }
896
985
  )
897
986
  });
@@ -901,37 +990,37 @@ async function* Ot(t, e, s, n, a, r = !0, o = [], i, l) {
901
990
  yield {
902
991
  ...v,
903
992
  final: !0,
904
- text: U(
905
- ((d = v.status) == null ? void 0 : d.message) || {
993
+ text: $(
994
+ ((S = v.status) == null ? void 0 : S.message) || {
906
995
  parts: [],
907
- messageId: D()
996
+ messageId: O()
908
997
  }
909
998
  )
910
999
  };
911
1000
  } else {
912
- const k = {
1001
+ const N = {
913
1002
  ...f.status.message,
914
- parts: w
915
- }, C = {
1003
+ parts: x
1004
+ }, R = {
916
1005
  ...f,
917
1006
  status: {
918
1007
  ...f.status,
919
- message: k
1008
+ message: N
920
1009
  },
921
- final: m.length === 0,
1010
+ final: _.length === 0,
922
1011
  // Only final if no agent messages to follow
923
- text: U(k)
1012
+ text: $(N)
924
1013
  };
925
- if (yield C, m.length > 0) {
926
- const E = m.map((O) => U(O)).join(" "), R = Z(E);
1014
+ if (yield R, _.length > 0) {
1015
+ const P = _.map((E) => $(E)).join(" "), A = L(P);
927
1016
  yield {
928
- id: C.id,
1017
+ id: R.id,
929
1018
  status: {
930
1019
  state: "completed",
931
- message: R
1020
+ message: A
932
1021
  },
933
1022
  final: !0,
934
- text: E
1023
+ text: P
935
1024
  };
936
1025
  }
937
1026
  }
@@ -939,363 +1028,363 @@ async function* Ot(t, e, s, n, a, r = !0, o = [], i, l) {
939
1028
  }
940
1029
  }
941
1030
  }
942
- function ue(t) {
1031
+ function te(t) {
943
1032
  const {
944
- agentId: e,
945
- agentUrl: s,
1033
+ agentId: s,
1034
+ agentUrl: e,
946
1035
  authProvider: n,
947
- defaultSessionId: a,
948
- timeout: r = re,
949
- toolProvider: o,
950
- contextProvider: i,
951
- enableStreaming: l = !1
952
- } = t, c = {
953
- agentId: e,
954
- agentUrl: s,
1036
+ defaultSessionId: o,
1037
+ timeout: r = Qt,
1038
+ toolProvider: a,
1039
+ contextProvider: l,
1040
+ enableStreaming: i = !1
1041
+ } = t, d = {
1042
+ agentId: s,
1043
+ agentUrl: e,
955
1044
  authProvider: n,
956
1045
  timeout: r
957
1046
  };
958
1047
  return {
959
- async sendMessage(g) {
960
- var h, d;
961
- const { withHistory: y = !0, abortSignal: b } = g, A = g.sessionId || a || void 0, S = [];
962
- S.push(g.message);
963
- const M = await st(
964
- g,
1048
+ async sendMessage(c) {
1049
+ var w, S;
1050
+ const { withHistory: g = !0, abortSignal: h } = c, T = c.sessionId || o || void 0, M = [];
1051
+ M.push(c.message);
1052
+ const p = await X(
965
1053
  c,
1054
+ d,
966
1055
  { isStreaming: !1 },
967
- o,
968
- i,
969
- A
1056
+ a,
1057
+ l,
1058
+ T
970
1059
  );
971
- let x = await Rt(
972
- M,
973
- c,
974
- { abortSignal: b }
1060
+ let m = await St(
1061
+ p,
1062
+ d,
1063
+ { abortSignal: h }
975
1064
  );
976
- const p = [], u = [];
977
- for (; x.status.message && o; ) {
978
- const f = J(
979
- x.status.message
1065
+ const y = [], u = [];
1066
+ for (; m.status.message && a; ) {
1067
+ const f = F(
1068
+ m.status.message
980
1069
  );
981
1070
  if (f.length === 0)
982
1071
  break;
983
- p.push(...f);
984
- const T = [];
1072
+ y.push(...f);
1073
+ const C = [];
985
1074
  let I = !1;
986
- for (const P of f) {
1075
+ for (const b of f) {
987
1076
  const {
988
- toolCallId: w,
989
- toolId: m,
990
- arguments: k
991
- } = P.data;
1077
+ toolCallId: x,
1078
+ toolId: _,
1079
+ arguments: N
1080
+ } = b.data;
992
1081
  try {
993
- const C = await o.executeTool(
994
- m,
995
- k
996
- ), { result: E, returnToAgent: R, agentMessage: O } = ct(C);
997
- R && (I = !0), O && u.push(
998
- Z(O)
1082
+ const R = await a.executeTool(
1083
+ _,
1084
+ N
1085
+ ), { result: P, returnToAgent: A, agentMessage: E } = it(R);
1086
+ A && (I = !0), E && u.push(
1087
+ L(E)
999
1088
  );
1000
- const v = W(
1001
- w,
1002
- m,
1003
- E
1089
+ const v = J(
1090
+ x,
1091
+ _,
1092
+ P
1004
1093
  );
1005
- T.push(v), p.push(v);
1006
- } catch (C) {
1007
- const E = W(
1008
- w,
1009
- m,
1094
+ C.push(v), y.push(v);
1095
+ } catch (R) {
1096
+ const P = J(
1097
+ x,
1098
+ _,
1010
1099
  void 0,
1011
- C instanceof Error ? C.message : String(C)
1100
+ R instanceof Error ? R.message : String(R)
1012
1101
  );
1013
- T.push(E), p.push(E);
1102
+ C.push(P), y.push(P);
1014
1103
  }
1015
1104
  }
1016
- if (S.push(x.status.message), I) {
1017
- const P = et(T);
1018
- x = await ot(
1019
- x.id,
1020
- P,
1021
- c,
1022
- o,
1023
- i,
1024
- A,
1025
- b
1105
+ if (M.push(m.status.message), I) {
1106
+ const b = Q(C);
1107
+ m = await et(
1108
+ m.id,
1109
+ b,
1110
+ d,
1111
+ a,
1112
+ l,
1113
+ T,
1114
+ h
1026
1115
  );
1027
1116
  } else
1028
1117
  break;
1029
1118
  }
1030
- if (p.length > 0 && (h = x.status) != null && h.message) {
1119
+ if (y.length > 0 && (w = m.status) != null && w.message) {
1031
1120
  const f = {
1032
- ...x.status.message,
1033
- parts: p
1121
+ ...m.status.message,
1122
+ parts: y
1034
1123
  };
1035
- x = {
1036
- ...x,
1124
+ m = {
1125
+ ...m,
1037
1126
  status: {
1038
- ...x.status,
1127
+ ...m.status,
1039
1128
  message: f
1040
1129
  }
1041
1130
  };
1042
1131
  }
1043
1132
  if (u.length > 0) {
1044
- const f = u.map((I) => U(I)).join(" "), T = Z(f);
1133
+ const f = u.map((I) => $(I)).join(" "), C = L(f);
1045
1134
  return {
1046
- ...x,
1135
+ ...m,
1047
1136
  // Keep the enhanced message with tool results
1048
1137
  // The agent message will be handled separately by the caller
1049
1138
  text: f,
1050
- agentMessage: T
1139
+ agentMessage: C
1051
1140
  // Add this for the caller to handle
1052
1141
  };
1053
1142
  }
1054
1143
  return {
1055
- ...x,
1056
- text: U(
1057
- ((d = x.status) == null ? void 0 : d.message) || {
1144
+ ...m,
1145
+ text: $(
1146
+ ((S = m.status) == null ? void 0 : S.message) || {
1058
1147
  parts: [],
1059
- messageId: D()
1148
+ messageId: O()
1060
1149
  }
1061
1150
  )
1062
1151
  };
1063
1152
  },
1064
- async *sendMessageStream(g) {
1153
+ async *sendMessageStream(c) {
1065
1154
  const {
1066
- withHistory: y = !0,
1067
- abortSignal: b,
1068
- enableStreaming: A
1069
- } = g, S = g.sessionId || a || void 0, M = A ?? l, x = [];
1070
- x.push(g.message);
1071
- const p = await st(
1072
- g,
1155
+ withHistory: g = !0,
1156
+ abortSignal: h,
1157
+ enableStreaming: T
1158
+ } = c, M = c.sessionId || o || void 0, p = T ?? i, m = [];
1159
+ m.push(c.message);
1160
+ const y = await X(
1073
1161
  c,
1162
+ d,
1074
1163
  {
1075
1164
  isStreaming: !0,
1076
1165
  // Always use message/stream endpoint for SSE
1077
- enableTokenStreaming: M
1166
+ enableTokenStreaming: p
1078
1167
  },
1079
- o,
1080
- i,
1081
- S
1082
- ), u = Et(
1083
- p,
1084
- c,
1168
+ a,
1169
+ l,
1170
+ M
1171
+ ), u = bt(
1172
+ y,
1173
+ d,
1085
1174
  {
1086
- enableTokenStreaming: M,
1175
+ enableTokenStreaming: p,
1087
1176
  // Token streaming is optional
1088
1177
  streamingTimeout: r,
1089
- abortSignal: b
1178
+ abortSignal: h
1090
1179
  }
1091
1180
  );
1092
- yield* Ot(
1181
+ yield* vt(
1093
1182
  u,
1094
- o,
1095
- i,
1096
- c,
1097
- S,
1098
- y,
1099
- x,
1100
- b,
1183
+ a,
1184
+ l,
1185
+ d,
1186
+ M,
1187
+ g,
1188
+ m,
1189
+ h,
1101
1190
  {
1102
1191
  isStreaming: !0,
1103
- enableTokenStreaming: M,
1192
+ enableTokenStreaming: p,
1104
1193
  streamingTimeout: r
1105
1194
  }
1106
1195
  );
1107
1196
  },
1108
- async continueTask(g, y, b) {
1109
- var x;
1110
- const A = rt(y);
1111
- let M = await ot(
1112
- g,
1113
- A,
1197
+ async continueTask(c, g, h) {
1198
+ var m;
1199
+ const T = ot(g);
1200
+ let p = await et(
1114
1201
  c,
1115
- o,
1116
- i,
1117
- b
1202
+ T,
1203
+ d,
1204
+ a,
1205
+ l,
1206
+ h
1118
1207
  );
1119
- for (; M.status.state === "input-required" && M.status.message && o; ) {
1120
- const p = J(
1121
- M.status.message
1208
+ for (; p.status.state === "input-required" && p.status.message && a; ) {
1209
+ const y = F(
1210
+ p.status.message
1122
1211
  );
1123
- if (p.length === 0)
1212
+ if (y.length === 0)
1124
1213
  break;
1125
- const { results: u, shouldReturnToAgent: h } = await Pt(p, o);
1126
- if (h) {
1127
- const d = et(u);
1128
- M = await ot(
1129
- M.id,
1214
+ const { results: u, shouldReturnToAgent: w } = await At(y, a);
1215
+ if (w) {
1216
+ const S = Q(u);
1217
+ p = await et(
1218
+ p.id,
1219
+ S,
1130
1220
  d,
1131
- c,
1132
- o,
1133
- i,
1134
- b
1221
+ a,
1222
+ l,
1223
+ h
1135
1224
  );
1136
1225
  } else
1137
1226
  break;
1138
1227
  }
1139
1228
  return {
1140
- ...M,
1141
- text: U(
1142
- ((x = M.status) == null ? void 0 : x.message) || {
1229
+ ...p,
1230
+ text: $(
1231
+ ((m = p.status) == null ? void 0 : m.message) || {
1143
1232
  parts: [],
1144
- messageId: D()
1233
+ messageId: O()
1145
1234
  }
1146
1235
  )
1147
1236
  };
1148
1237
  },
1149
- async getTask(g) {
1238
+ async getTask(c) {
1150
1239
  throw new Error("getTask not implemented yet");
1151
1240
  },
1152
- async cancelTask(g) {
1241
+ async cancelTask(c) {
1153
1242
  throw new Error("cancelTask not implemented yet");
1154
1243
  }
1155
1244
  };
1156
1245
  }
1157
- const dt = "a8c_agenttic_conversation_history";
1158
- function de(t) {
1159
- var i;
1160
- const e = t.parts.filter((l) => l.type === "text").map((l) => l.text).join(`
1161
- `), s = t.parts.filter(
1162
- (l) => l.type === "data" && "toolCallId" in l.data && "arguments" in l.data
1163
- ).map((l) => ({
1164
- toolCallId: l.data.toolCallId,
1165
- toolId: l.data.toolId,
1166
- arguments: l.data.arguments
1246
+ const ct = "a8c_agenttic_conversation_history";
1247
+ function ee(t) {
1248
+ var l;
1249
+ const s = t.parts.filter((i) => i.type === "text").map((i) => i.text).join(`
1250
+ `), e = t.parts.filter(
1251
+ (i) => i.type === "data" && "toolCallId" in i.data && "arguments" in i.data
1252
+ ).map((i) => ({
1253
+ toolCallId: i.data.toolCallId,
1254
+ toolId: i.data.toolId,
1255
+ arguments: i.data.arguments
1167
1256
  })), n = t.parts.filter(
1168
- (l) => l.type === "data" && "toolCallId" in l.data && "result" in l.data
1169
- ).map((l) => ({
1170
- toolCallId: l.data.toolCallId,
1171
- result: l.data.result,
1172
- error: l.data.error
1173
- })), r = s.length > 0 || n.length > 0 ? "agent" : t.role, o = ((i = t.metadata) == null ? void 0 : i.timestamp) ?? Date.now();
1257
+ (i) => i.type === "data" && "toolCallId" in i.data && "result" in i.data
1258
+ ).map((i) => ({
1259
+ toolCallId: i.data.toolCallId,
1260
+ result: i.data.result,
1261
+ error: i.data.error
1262
+ })), r = e.length > 0 || n.length > 0 ? "agent" : t.role, a = ((l = t.metadata) == null ? void 0 : l.timestamp) ?? Date.now();
1174
1263
  return {
1175
1264
  role: r,
1176
- content: e || "(No text content)",
1177
- timestamp: o,
1178
- ...s.length > 0 && { toolCalls: s },
1265
+ content: s || "(No text content)",
1266
+ timestamp: a,
1267
+ ...e.length > 0 && { toolCalls: e },
1179
1268
  ...n.length > 0 && { toolResults: n }
1180
1269
  };
1181
1270
  }
1182
- function ge(t) {
1183
- const e = [];
1184
- if (t.content && t.content !== "(No text content)" && e.push({
1271
+ function se(t) {
1272
+ const s = [];
1273
+ if (t.content && t.content !== "(No text content)" && s.push({
1185
1274
  type: "text",
1186
1275
  text: t.content
1187
1276
  }), t.toolCalls)
1188
- for (const s of t.toolCalls)
1189
- e.push({
1277
+ for (const e of t.toolCalls)
1278
+ s.push({
1190
1279
  type: "data",
1191
1280
  data: {
1192
- toolCallId: s.toolCallId,
1193
- toolId: s.toolId,
1194
- arguments: s.arguments
1281
+ toolCallId: e.toolCallId,
1282
+ toolId: e.toolId,
1283
+ arguments: e.arguments
1195
1284
  }
1196
1285
  });
1197
1286
  if (t.toolResults)
1198
- for (const s of t.toolResults)
1199
- e.push({
1287
+ for (const e of t.toolResults)
1288
+ s.push({
1200
1289
  type: "data",
1201
1290
  data: {
1202
- toolCallId: s.toolCallId,
1203
- result: s.result,
1204
- ...s.error && { error: s.error }
1291
+ toolCallId: e.toolCallId,
1292
+ result: e.result,
1293
+ ...e.error && { error: e.error }
1205
1294
  }
1206
1295
  });
1207
1296
  return {
1208
1297
  role: t.role,
1209
1298
  kind: "message",
1210
- parts: e,
1211
- messageId: D(),
1299
+ parts: s,
1300
+ messageId: O(),
1212
1301
  metadata: {
1213
1302
  timestamp: t.timestamp
1214
1303
  }
1215
1304
  };
1216
1305
  }
1217
- const L = /* @__PURE__ */ new Map(), fe = 50;
1218
- async function me(t, e, s) {
1219
- const n = s || t;
1220
- if (L.set(n, [...e]), L.size > fe) {
1221
- const a = L.keys().next().value;
1222
- a && L.delete(a);
1306
+ const U = /* @__PURE__ */ new Map(), ne = 50;
1307
+ async function oe(t, s, e) {
1308
+ const n = e || t;
1309
+ if (U.set(n, [...s]), U.size > ne) {
1310
+ const o = U.keys().next().value;
1311
+ o && U.delete(o);
1223
1312
  }
1224
1313
  if (!(typeof sessionStorage > "u"))
1225
1314
  try {
1226
- const a = {
1315
+ const o = {
1227
1316
  storageKey: n,
1228
- messages: e.map(de),
1317
+ messages: s.map(ee),
1229
1318
  lastUpdated: Date.now()
1230
1319
  };
1231
1320
  sessionStorage.setItem(
1232
- `${dt}_${n}`,
1233
- JSON.stringify(a)
1321
+ `${ct}_${n}`,
1322
+ JSON.stringify(o)
1234
1323
  );
1235
- } catch (a) {
1236
- N(
1324
+ } catch (o) {
1325
+ k(
1237
1326
  "Failed to store conversation in sessionStorage for key %s: %O",
1238
1327
  n,
1239
- a
1328
+ o
1240
1329
  );
1241
1330
  }
1242
1331
  }
1243
- async function he(t, e) {
1244
- const s = e || t;
1245
- if (L.has(s))
1246
- return [...L.get(s)];
1332
+ async function ae(t, s) {
1333
+ const e = s || t;
1334
+ if (U.has(e))
1335
+ return [...U.get(e)];
1247
1336
  if (typeof sessionStorage > "u")
1248
1337
  return [];
1249
1338
  try {
1250
1339
  const n = sessionStorage.getItem(
1251
- `${dt}_${s}`
1340
+ `${ct}_${e}`
1252
1341
  );
1253
1342
  if (n) {
1254
- const r = JSON.parse(n).messages.map(ge);
1255
- return L.set(s, r), [...r];
1343
+ const r = JSON.parse(n).messages.map(se);
1344
+ return U.set(e, r), [...r];
1256
1345
  }
1257
1346
  } catch (n) {
1258
- N(
1347
+ k(
1259
1348
  "Failed to load conversation from sessionStorage for key %s: %O",
1260
- s,
1349
+ e,
1261
1350
  n
1262
1351
  );
1263
1352
  }
1264
1353
  return [];
1265
1354
  }
1266
- async function pe(t, e) {
1267
- const s = e || t;
1268
- if (L.delete(s), !(typeof sessionStorage > "u"))
1355
+ async function re(t, s) {
1356
+ const e = s || t;
1357
+ if (U.delete(e), !(typeof sessionStorage > "u"))
1269
1358
  try {
1270
- sessionStorage.removeItem(`${dt}_${s}`);
1359
+ sessionStorage.removeItem(`${ct}_${e}`);
1271
1360
  } catch (n) {
1272
- N(
1361
+ k(
1273
1362
  "Failed to clear conversation from sessionStorage for key %s: %O",
1274
- s,
1363
+ e,
1275
1364
  n
1276
1365
  );
1277
1366
  }
1278
1367
  }
1279
- function G(t) {
1280
- const e = t.parts.filter((s) => s.type === "text" ? !0 : s.type === "data" ? "role" in s.data && "text" in s.data ? !1 : "toolCallId" in s.data && "arguments" in s.data || "toolCallId" in s.data && "result" in s.data : !0);
1368
+ function K(t) {
1369
+ const s = t.parts.filter((e) => e.type === "text" ? !0 : e.type === "data" ? "role" in e.data && "text" in e.data ? !1 : "toolCallId" in e.data && "arguments" in e.data || "toolCallId" in e.data && "result" in e.data : !0);
1281
1370
  return {
1282
1371
  ...t,
1283
- parts: e,
1372
+ parts: s,
1284
1373
  // Preserve metadata if it exists, otherwise add timestamp
1285
1374
  metadata: t.metadata || {
1286
1375
  timestamp: Date.now()
1287
1376
  }
1288
1377
  };
1289
1378
  }
1290
- function ye(t) {
1291
- const e = [];
1292
- for (const s of t)
1293
- for (const n of s.parts)
1379
+ function ie(t) {
1380
+ const s = [];
1381
+ for (const e of t)
1382
+ for (const n of e.parts)
1294
1383
  if (n.type === "text")
1295
- e.push({
1384
+ s.push({
1296
1385
  type: "data",
1297
1386
  data: {
1298
- role: s.role,
1387
+ role: e.role,
1299
1388
  text: n.text
1300
1389
  }
1301
1390
  });
@@ -1303,1232 +1392,741 @@ function ye(t) {
1303
1392
  if ("role" in n.data && "text" in n.data)
1304
1393
  continue;
1305
1394
  if ("toolCallId" in n.data && "arguments" in n.data) {
1306
- e.push(n);
1395
+ s.push(n);
1307
1396
  continue;
1308
1397
  }
1309
1398
  if ("toolCallId" in n.data && "result" in n.data) {
1310
- e.push(n);
1399
+ s.push(n);
1311
1400
  continue;
1312
1401
  }
1313
1402
  }
1314
- return e;
1403
+ return s;
1315
1404
  }
1316
- function wt(t, e = []) {
1405
+ function mt(t, s = []) {
1317
1406
  return {
1318
1407
  role: "user",
1319
1408
  parts: [
1320
- ...ye(e),
1409
+ ...ie(s),
1321
1410
  {
1322
1411
  type: "text",
1323
1412
  text: t
1324
1413
  }
1325
1414
  ],
1326
1415
  kind: "message",
1327
- messageId: D(),
1416
+ messageId: O(),
1328
1417
  metadata: {
1329
1418
  timestamp: Date.now()
1330
1419
  }
1331
1420
  };
1332
1421
  }
1333
- function we(t) {
1422
+ function le(t) {
1334
1423
  return t != null && t.parts ? t.parts.filter(
1335
- (e) => e.type === "data" && "toolCallId" in e.data && "result" in e.data
1424
+ (s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
1336
1425
  ) : [];
1337
1426
  }
1338
- async function Ie(t) {
1339
- const e = [];
1340
- for (const s of t)
1341
- if (s.parts && Array.isArray(s.parts))
1342
- if (s.parts.some(
1343
- (a) => a.type === "data" && "toolCallId" in a.data && "result" in a.data
1427
+ async function ce(t) {
1428
+ const s = [];
1429
+ for (const e of t)
1430
+ if (e.parts && Array.isArray(e.parts))
1431
+ if (e.parts.some(
1432
+ (o) => o.type === "data" && "toolCallId" in o.data && "result" in o.data
1344
1433
  )) {
1345
- const a = ce(
1346
- s.parts
1434
+ const o = Zt(
1435
+ e.parts
1347
1436
  );
1348
- e.push({
1349
- ...s,
1350
- parts: a
1437
+ s.push({
1438
+ ...e,
1439
+ parts: o
1351
1440
  });
1352
1441
  } else
1353
- e.push(s);
1442
+ s.push(e);
1354
1443
  else
1355
- e.push(s);
1356
- return le(), e;
1444
+ s.push(e);
1445
+ return Yt(), s;
1357
1446
  }
1358
- function Ce() {
1447
+ function ue() {
1359
1448
  const t = /* @__PURE__ */ new Map();
1360
- async function e(s, n) {
1361
- const a = t.get(s);
1362
- if (a != null && a.sessionId)
1449
+ async function s(e, n) {
1450
+ const o = t.get(e);
1451
+ if (o != null && o.sessionId)
1363
1452
  try {
1364
- await me(
1365
- a.sessionId,
1453
+ await oe(
1454
+ o.sessionId,
1366
1455
  n,
1367
- a.conversationStorageKey
1456
+ o.conversationStorageKey
1368
1457
  );
1369
1458
  } catch (r) {
1370
- ht(
1371
- `Failed to persist conversation history for agent ${s}:`,
1459
+ dt(
1460
+ `Failed to persist conversation history for agent ${e}:`,
1372
1461
  r
1373
1462
  );
1374
1463
  }
1375
1464
  }
1376
1465
  return {
1377
- async createAgent(s, n) {
1378
- if (t.has(s))
1379
- return t.get(s).client;
1380
- const a = ue(n), r = n.sessionId || null, o = n.conversationStorageKey;
1381
- let i = [];
1466
+ async createAgent(e, n) {
1467
+ if (t.has(e))
1468
+ return t.get(e).client;
1469
+ const o = te(n), r = n.sessionId || null, a = n.conversationStorageKey;
1470
+ let l = [];
1382
1471
  if (r)
1383
1472
  try {
1384
- i = await he(
1473
+ l = await ae(
1385
1474
  r,
1386
- o
1475
+ a
1387
1476
  );
1388
- } catch (c) {
1389
- ht(
1390
- `Failed to load conversation history for agent ${s} with session ${r}:`,
1391
- c
1477
+ } catch (d) {
1478
+ dt(
1479
+ `Failed to load conversation history for agent ${e} with session ${r}:`,
1480
+ d
1392
1481
  );
1393
1482
  }
1394
- const l = {
1395
- client: a,
1483
+ const i = {
1484
+ client: o,
1396
1485
  sessionId: r,
1397
- conversationStorageKey: o,
1398
- conversationHistory: i
1486
+ conversationStorageKey: a,
1487
+ conversationHistory: l,
1488
+ currentAbortController: null
1399
1489
  };
1400
- return t.set(s, l), a;
1490
+ return t.set(e, i), o;
1401
1491
  },
1402
- getAgent(s) {
1403
- const n = t.get(s);
1492
+ getAgent(e) {
1493
+ const n = t.get(e);
1404
1494
  return (n == null ? void 0 : n.client) || null;
1405
1495
  },
1406
- hasAgent(s) {
1407
- return t.has(s);
1496
+ hasAgent(e) {
1497
+ return t.has(e);
1408
1498
  },
1409
- removeAgent(s) {
1410
- return t.delete(s);
1499
+ removeAgent(e) {
1500
+ return t.delete(e);
1411
1501
  },
1412
- async sendMessage(s, n, a = {}) {
1413
- var M;
1414
- const r = t.get(s);
1502
+ async sendMessage(e, n, o = {}) {
1503
+ var p;
1504
+ const r = t.get(e);
1415
1505
  if (!r)
1416
- throw new Error(`Agent with key "${s}" not found`);
1417
- const { withHistory: o = !0, ...i } = a, { client: l, conversationHistory: c } = r, g = a.message || wt(n, c), y = await l.sendMessage({
1418
- message: g,
1419
- withHistory: o,
1420
- ...i
1506
+ throw new Error(`Agent with key "${e}" not found`);
1507
+ const { withHistory: a = !0, ...l } = o, { client: i, conversationHistory: d } = r, c = o.message || mt(n, d), g = await i.sendMessage({
1508
+ message: c,
1509
+ withHistory: a,
1510
+ ...l
1421
1511
  });
1422
- let b = null;
1423
- if ((M = y.status) != null && M.message) {
1424
- const x = y.status.message.parts.filter(
1512
+ let h = null;
1513
+ if ((p = g.status) != null && p.message) {
1514
+ const m = g.status.message.parts.filter(
1425
1515
  (u) => u.type === "data" && "toolCallId" in u.data && ("arguments" in u.data || "result" in u.data)
1426
- ), p = y.status.message.parts.filter(
1516
+ ), y = g.status.message.parts.filter(
1427
1517
  (u) => u.type === "text"
1428
1518
  );
1429
- b = {
1519
+ h = {
1430
1520
  role: "agent",
1431
1521
  kind: "message",
1432
- parts: [...x, ...p],
1433
- messageId: D(),
1522
+ parts: [...m, ...y],
1523
+ messageId: O(),
1434
1524
  metadata: {
1435
1525
  timestamp: Date.now()
1436
1526
  }
1437
1527
  };
1438
1528
  }
1439
- const A = [
1440
- ...c,
1529
+ const T = [
1530
+ ...d,
1441
1531
  // Store only the new content from the user message (without history parts)
1442
- rt(n),
1532
+ ot(n),
1443
1533
  // Add complete agent response with tool calls/results if present
1444
- ...b ? [G(b)] : []
1534
+ ...h ? [K(h)] : []
1445
1535
  ];
1446
- let S = A;
1447
- if (y.agentMessage) {
1448
- const x = G(
1449
- y.agentMessage
1536
+ let M = T;
1537
+ if (g.agentMessage) {
1538
+ const m = K(
1539
+ g.agentMessage
1450
1540
  );
1451
- S = [
1452
- ...A,
1453
- x
1541
+ M = [
1542
+ ...T,
1543
+ m
1454
1544
  ];
1455
1545
  }
1456
- return r.conversationHistory = S, o && await e(
1457
- s,
1458
- S
1459
- ), y;
1546
+ return r.conversationHistory = M, a && await s(
1547
+ e,
1548
+ M
1549
+ ), g;
1460
1550
  },
1461
- async *sendMessageStream(s, n, a = {}) {
1462
- var S, M, x, p, u, h;
1463
- const r = t.get(s);
1551
+ async *sendMessageStream(e, n, o = {}) {
1552
+ var m, y, u, w, S, f;
1553
+ const r = t.get(e);
1464
1554
  if (!r)
1465
- throw new Error(`Agent with key "${s}" not found`);
1466
- const { withHistory: o = !0, ...i } = a, { client: l } = r;
1467
- let c = [
1555
+ throw new Error(`Agent with key "${e}" not found`);
1556
+ const {
1557
+ withHistory: a = !0,
1558
+ abortSignal: l,
1559
+ ...i
1560
+ } = o, { client: d } = r, c = new AbortController();
1561
+ r.currentAbortController = c, l && l.addEventListener(
1562
+ "abort",
1563
+ () => c.abort()
1564
+ );
1565
+ let g = [
1468
1566
  ...r.conversationHistory
1469
- ], g = [];
1470
- const y = await Ie(
1471
- c
1567
+ ], h = [];
1568
+ const T = await ce(
1569
+ g
1472
1570
  );
1473
- r.conversationHistory = y, c = y, o && await e(
1474
- s,
1475
- y
1571
+ r.conversationHistory = T, g = T, a && await s(
1572
+ e,
1573
+ T
1476
1574
  );
1477
- const b = a.message || wt(
1575
+ const M = o.message || mt(
1478
1576
  n,
1479
- y
1480
- ), A = rt(n);
1481
- c = [
1482
- ...c,
1483
- A
1484
- ], r.conversationHistory = c, o && await e(
1485
- s,
1486
- c
1577
+ T
1578
+ ), p = ot(n);
1579
+ g = [
1580
+ ...g,
1581
+ p
1582
+ ], r.conversationHistory = g, a && await s(
1583
+ e,
1584
+ g
1487
1585
  );
1488
- for await (const d of l.sendMessageStream({
1489
- message: b,
1490
- withHistory: o,
1586
+ for await (const C of d.sendMessageStream({
1587
+ message: M,
1588
+ withHistory: a,
1589
+ abortSignal: c.signal,
1491
1590
  ...i
1492
1591
  })) {
1493
- if (((S = d.status) == null ? void 0 : S.state) === "input-required" && ((M = d.status) != null && M.message)) {
1494
- g = J(
1495
- d.status.message
1592
+ if (((m = C.status) == null ? void 0 : m.state) === "input-required" && ((y = C.status) != null && y.message)) {
1593
+ h = F(
1594
+ C.status.message
1496
1595
  ).map(
1497
- (I) => I.data.toolCallId
1596
+ (x) => x.data.toolCallId
1498
1597
  );
1499
- const T = G(
1500
- d.status.message
1598
+ const b = K(
1599
+ C.status.message
1501
1600
  );
1502
- c = [
1503
- ...c,
1504
- T
1505
- ], r.conversationHistory = c, o && await e(
1506
- s,
1507
- c
1601
+ g = [
1602
+ ...g,
1603
+ b
1604
+ ], r.conversationHistory = g, a && await s(
1605
+ e,
1606
+ g
1508
1607
  );
1509
1608
  }
1510
- if (((x = d.status) == null ? void 0 : x.state) === "working" && ((p = d.status) != null && p.message) && !d.final) {
1511
- const T = we(
1512
- d.status.message
1609
+ if (((u = C.status) == null ? void 0 : u.state) === "working" && ((w = C.status) != null && w.message) && !C.final) {
1610
+ const b = le(
1611
+ C.status.message
1513
1612
  ).filter(
1514
- (I) => g.includes(
1515
- I.data.toolCallId
1613
+ (x) => h.includes(
1614
+ x.data.toolCallId
1516
1615
  )
1517
1616
  );
1518
- if (T.length > 0) {
1519
- const I = {
1617
+ if (b.length > 0) {
1618
+ const x = {
1520
1619
  role: "agent",
1521
1620
  kind: "message",
1522
- parts: T,
1523
- messageId: D()
1621
+ parts: b,
1622
+ messageId: O()
1524
1623
  };
1525
- c = [
1526
- ...c,
1527
- G(I)
1528
- ], r.conversationHistory = c, o && await e(
1529
- s,
1530
- c
1624
+ g = [
1625
+ ...g,
1626
+ K(x)
1627
+ ], r.conversationHistory = g, a && await s(
1628
+ e,
1629
+ g
1531
1630
  );
1532
1631
  }
1533
1632
  }
1534
- if (d.final && ((u = d.status) == null ? void 0 : u.state) !== "input-required") {
1535
- g = [];
1536
- let f = null;
1537
- (h = d.status) != null && h.message && (f = G(
1538
- d.status.message
1539
- ), c = [
1540
- ...c,
1541
- f
1542
- ], r.conversationHistory = c, o && await e(
1543
- s,
1544
- c
1633
+ if (C.final && ((S = C.status) == null ? void 0 : S.state) !== "input-required") {
1634
+ h = [];
1635
+ let I = null;
1636
+ (f = C.status) != null && f.message && (I = K(
1637
+ C.status.message
1638
+ ), g = [
1639
+ ...g,
1640
+ I
1641
+ ], r.conversationHistory = g, a && await s(
1642
+ e,
1643
+ g
1545
1644
  ));
1546
1645
  }
1547
- yield d;
1646
+ yield C;
1548
1647
  }
1648
+ r.currentAbortController = null;
1549
1649
  },
1550
- async resetConversation(s) {
1551
- const n = t.get(s);
1650
+ async resetConversation(e) {
1651
+ const n = t.get(e);
1552
1652
  if (!n)
1553
- throw new Error(`Agent with key "${s}" not found`);
1554
- n.conversationHistory = [], n.sessionId && await pe(
1653
+ throw new Error(`Agent with key "${e}" not found`);
1654
+ n.conversationHistory = [], n.sessionId && await re(
1555
1655
  n.sessionId,
1556
1656
  n.conversationStorageKey
1557
1657
  );
1558
1658
  },
1559
- getConversationHistory(s) {
1560
- const n = t.get(s);
1659
+ getConversationHistory(e) {
1660
+ const n = t.get(e);
1561
1661
  if (!n)
1562
- throw new Error(`Agent with key "${s}" not found`);
1662
+ throw new Error(`Agent with key "${e}" not found`);
1563
1663
  return [...n.conversationHistory];
1564
1664
  },
1665
+ abortCurrentRequest(e) {
1666
+ const n = t.get(e);
1667
+ if (!n)
1668
+ throw new Error(`Agent with key "${e}" not found`);
1669
+ n.currentAbortController && (n.currentAbortController.abort(), n.currentAbortController = null);
1670
+ },
1565
1671
  clear() {
1566
1672
  t.clear();
1567
1673
  }
1568
1674
  };
1569
1675
  }
1570
- const xe = Ce();
1571
- function It() {
1572
- return xe;
1573
- }
1574
- class Me extends Dt {
1575
- constructor(e) {
1576
- super(e), this.state = {
1577
- hasError: !1,
1578
- error: null,
1579
- errorInfo: null
1580
- };
1581
- }
1582
- static getDerivedStateFromError(e) {
1583
- return {
1584
- hasError: !0,
1585
- error: e,
1586
- errorInfo: null
1587
- };
1588
- }
1589
- componentDidCatch(e, s) {
1590
- if (console.error("Chart rendering error:", e), console.error("Error info:", s), this.props.chartData) {
1591
- console.error(
1592
- "Chart data that caused the error:",
1593
- this.props.chartData
1594
- );
1595
- try {
1596
- const n = JSON.parse(this.props.chartData);
1597
- console.error("Parsed chart data:", n);
1598
- } catch {
1599
- console.error("Could not parse chart data as JSON");
1600
- }
1601
- }
1602
- this.setState({
1603
- errorInfo: s
1604
- });
1605
- }
1606
- render() {
1607
- var e;
1608
- if (this.state.hasError) {
1609
- const s = ((e = this.state.error) == null ? void 0 : e.message) || "An error occurred while rendering the chart", n = [
1610
- "The chart could not be rendered due to an error.",
1611
- "The error has been logged to the console."
1612
- ];
1613
- return /* @__PURE__ */ $.jsx(
1614
- tt,
1615
- {
1616
- message: s,
1617
- details: n.join(`
1618
- `)
1619
- }
1620
- );
1621
- }
1622
- return this.props.children;
1623
- }
1676
+ const de = ue();
1677
+ function st() {
1678
+ return de;
1624
1679
  }
1625
- const Te = (t) => {
1626
- const {
1627
- data: e,
1628
- currency: s,
1629
- showLegend: n = !0,
1630
- withTooltips: a = !0,
1631
- renderTooltip: r,
1632
- margin: o,
1633
- withGradientFill: i = !0,
1634
- error: l,
1635
- ...c
1636
- } = t, g = {
1637
- ..._t(),
1638
- bottom: 80
1639
- }, y = {
1640
- data: e,
1641
- withTooltips: a,
1642
- renderTooltip: r,
1643
- showLegend: n,
1644
- withGradientFill: i,
1645
- withLegendGlyph: !1,
1646
- legendOrientation: "horizontal",
1647
- legendAlignmentHorizontal: "center",
1648
- legendAlignmentVertical: "bottom",
1649
- margin: g,
1650
- options: {
1651
- xScale: {
1652
- type: "time"
1653
- },
1654
- axis: {
1655
- x: {
1656
- ...jt(e)
1657
- }
1658
- }
1659
- },
1660
- ...s && { currency: s },
1661
- ...c
1662
- };
1663
- return /* @__PURE__ */ $.jsx(Ft, { error: l, children: /* @__PURE__ */ $.jsx(Bt, { ...y }) });
1664
- }, be = ({
1665
- data: t,
1666
- className: e = "",
1667
- config: s
1668
- }) => {
1669
- const [n, a] = X(null), [r, o] = X(
1670
- null
1671
- ), [i, l] = X(300), c = xt(null), g = j(
1672
- (p) => {
1673
- var P;
1674
- const { tooltipData: u } = p, h = (P = u == null ? void 0 : u.nearestDatum) == null ? void 0 : P.datum;
1675
- if (!h)
1676
- return null;
1677
- const d = (w) => {
1678
- if (r != null && r.currency) {
1679
- const { symbol: m, symbolPosition: k } = r.currency;
1680
- let C;
1681
- return w >= 1e6 ? C = `${(w / 1e6).toFixed(
1682
- 1
1683
- )}M` : w >= 1e3 ? C = `${(w / 1e3).toFixed(1)}K` : C = w.toLocaleString(), k === "right" ? `${C}${m}` : `${m}${C}`;
1684
- }
1685
- return w >= 1e6 ? `${(w / 1e6).toFixed(1)}M` : w >= 1e3 ? `${(w / 1e3).toFixed(1)}K` : w.toLocaleString();
1686
- }, f = (w) => {
1687
- const k = Math.floor(
1688
- ((/* @__PURE__ */ new Date()).getTime() - w.getTime()) / (1e3 * 60 * 60 * 24)
1689
- );
1690
- return k === 0 ? H("Today", "a8c-agenttic") : k === 1 ? H("Yesterday", "a8c-agenttic") : k < 7 ? ft(
1691
- /* translators: %d: number of days */
1692
- H("%d days ago", "a8c-agenttic"),
1693
- k
1694
- ) : w.toLocaleDateString("en-US", {
1695
- year: "numeric",
1696
- month: "short",
1697
- day: "numeric"
1698
- });
1699
- }, T = h.label, I = Object.entries(
1700
- (u == null ? void 0 : u.datumByKey) || {}
1701
- ).map(([w, m]) => {
1702
- const k = m.datum;
1703
- return {
1704
- key: w,
1705
- value: k.value
1706
- };
1707
- }).sort((w, m) => m.value - w.value);
1708
- return /* @__PURE__ */ $.jsxs("div", { children: [
1709
- T && /* @__PURE__ */ $.jsx(
1710
- "div",
1711
- {
1712
- style: {
1713
- fontSize: "12px",
1714
- fontWeight: "bold",
1715
- marginBottom: "4px",
1716
- color: "#1e1e1e",
1717
- borderBottom: "1px solid #eee",
1718
- paddingBottom: "2px"
1719
- },
1720
- children: T
1721
- }
1722
- ),
1723
- h.date && /* @__PURE__ */ $.jsx(
1724
- "div",
1725
- {
1726
- style: {
1727
- fontSize: "10px",
1728
- opacity: 0.8,
1729
- marginBottom: "4px"
1730
- },
1731
- children: f(h.date)
1732
- }
1733
- ),
1734
- I.map((w) => /* @__PURE__ */ $.jsxs(
1735
- "div",
1736
- {
1737
- style: { marginBottom: "2px" },
1738
- children: [
1739
- /* @__PURE__ */ $.jsxs("strong", { children: [
1740
- w.key,
1741
- ":"
1742
- ] }),
1743
- " ",
1744
- d(w.value)
1745
- ]
1746
- },
1747
- w.key
1748
- ))
1749
- ] });
1750
- },
1751
- [r == null ? void 0 : r.currency]
1752
- );
1753
- Y(() => {
1754
- if (a(null), o(null), !t || typeof t != "string") {
1755
- a({
1756
- message: H("Invalid chart data provided", "a8c-agenttic"),
1757
- details: `Input data: ${t}`
1758
- });
1759
- return;
1760
- }
1761
- try {
1762
- const p = JSON.parse(t.trim());
1763
- if (!p.chartType) {
1764
- a({
1765
- message: H(
1766
- "Chart data must include chartType",
1767
- "a8c-agenttic"
1768
- ),
1769
- details: H("Available types: line, bar", "a8c-agenttic")
1770
- });
1771
- return;
1772
- }
1773
- if (!p.data || !Array.isArray(p.data)) {
1774
- a({
1775
- message: H(
1776
- "Chart data must include a data array",
1777
- "a8c-agenttic"
1778
- ),
1779
- details: `Input data: ${t}`
1780
- });
1781
- return;
1782
- }
1783
- if (p.data.length === 0) {
1784
- a({
1785
- message: H(
1786
- "No data points found for chart",
1787
- "a8c-agenttic"
1788
- ),
1789
- details: `Input data: ${t}`
1790
- });
1791
- return;
1792
- }
1793
- const u = p.data.map((d) => ({
1794
- ...d,
1795
- data: d.data.map((f) => {
1796
- if (f.date) {
1797
- const T = new Date(f.date);
1798
- return isNaN(T.getTime()) ? (console.warn(
1799
- `Invalid date string: "${f.date}" in series "${d.label}"`
1800
- ), {
1801
- label: f.label,
1802
- value: f.value,
1803
- date: void 0
1804
- }) : {
1805
- label: f.label,
1806
- value: f.value,
1807
- date: T
1808
- };
1809
- }
1810
- return {
1811
- label: f.label,
1812
- value: f.value,
1813
- date: void 0
1814
- };
1815
- })
1816
- })), h = {
1817
- chartType: p.chartType,
1818
- title: p.title,
1819
- data: u,
1820
- currency: p.currency,
1821
- mode: p.mode || "time-comparison"
1822
- };
1823
- o(h);
1824
- } catch {
1825
- a({
1826
- message: H(
1827
- "Failed to parse chart data as JSON",
1828
- "a8c-agenttic"
1829
- ),
1830
- details: `Input data: ${t}`
1831
- });
1832
- }
1833
- }, [t]);
1834
- const y = j((p) => {
1835
- if (c.current && c.current.disconnect(), p) {
1836
- const { width: u } = p.getBoundingClientRect(), h = Math.max(280, u - 4);
1837
- l(h), c.current = new ResizeObserver((d) => {
1838
- for (const f of d) {
1839
- const T = f.contentRect.width, I = Math.max(
1840
- 280,
1841
- T - 4
1842
- );
1843
- l(I);
1844
- }
1845
- }), c.current.observe(p);
1846
- }
1847
- }, []);
1848
- if (Y(() => () => {
1849
- c.current && (c.current.disconnect(), c.current = null);
1850
- }, []), n)
1851
- return /* @__PURE__ */ $.jsx(tt, { message: n.message, details: n.details });
1852
- if (!r)
1853
- return /* @__PURE__ */ $.jsx(
1854
- tt,
1855
- {
1856
- message: H("No chart data available", "a8c-agenttic")
1857
- }
1858
- );
1859
- const A = r.data.length > 1, S = i, M = {
1860
- data: r.data,
1861
- currency: r.currency,
1862
- showLegend: A,
1863
- withTooltips: !0,
1864
- renderTooltip: g,
1865
- error: null,
1866
- maxWidth: S,
1867
- aspectRatio: 1.2,
1868
- resizeDebounceTime: 300
1869
- }, x = () => {
1870
- switch (r.chartType) {
1871
- case "line":
1872
- return /* @__PURE__ */ $.jsx(Te, { ...M });
1873
- case "bar":
1874
- return /* @__PURE__ */ $.jsx(
1875
- Ht,
1876
- {
1877
- ...M,
1878
- mode: r.mode
1879
- }
1880
- );
1881
- default:
1882
- return /* @__PURE__ */ $.jsx(
1883
- tt,
1884
- {
1885
- message: ft(
1886
- /* translators: %s: chart type name */
1887
- H("Unsupported chart type: %s", "a8c-agenttic"),
1888
- r.chartType
1889
- )
1890
- }
1891
- );
1892
- }
1893
- };
1894
- return /* @__PURE__ */ $.jsx(Me, { chartData: t, children: /* @__PURE__ */ $.jsxs(
1895
- "div",
1896
- {
1897
- ref: y,
1898
- className: `chart-block ${e}`,
1899
- children: [
1900
- r.title && /* @__PURE__ */ $.jsx("h3", { className: "chart-block-title", children: r.title }),
1901
- /* @__PURE__ */ $.jsx("div", { className: "chart-container", children: x() })
1902
- ]
1903
- }
1904
- ) });
1905
- };
1906
- function Se(t) {
1907
- return function(s) {
1908
- const { children: n, className: a, ...r } = s;
1909
- if (!(a == null ? void 0 : a.includes("language-chart")))
1910
- return gt.createElement(
1911
- "code",
1912
- { className: a, ...r },
1913
- n
1914
- );
1915
- const i = typeof n == "string" ? n : "";
1916
- return gt.createElement(be, {
1917
- data: i,
1918
- className: "markdown-chart",
1919
- config: t
1920
- });
1921
- };
1922
- }
1923
- function ke(t) {
1924
- var n, a;
1925
- const e = {}, s = [];
1926
- return (n = t == null ? void 0 : t.charts) != null && n.enabled && (e.code = Se(t.charts.config)), (a = t == null ? void 0 : t.gfm) != null && a.enabled && s.push(Ut), { components: e, remarkPlugins: s };
1927
- }
1928
- function Ae(t, e = {}) {
1929
- return {
1930
- ...t,
1931
- ...e
1932
- };
1933
- }
1934
- function ve(t = {}) {
1935
- const { components: e = {}, extensions: s = {}, remarkPlugins: n = [] } = t, a = ke(s), r = Ae(
1936
- a.components,
1937
- e
1938
- ), o = [...a.remarkPlugins, ...n];
1939
- return function({ children: l }) {
1940
- return /* @__PURE__ */ $.jsx(
1941
- qt,
1942
- {
1943
- components: r,
1944
- remarkPlugins: o,
1945
- children: l
1946
- }
1947
- );
1948
- };
1949
- }
1950
- const Re = (t) => {
1951
- const e = t.condition || (() => !0), s = {}, n = [], a = () => {
1952
- n.forEach((o) => o());
1953
- }, r = async (o, i) => {
1954
- s[o] = i, await t.onFeedback(o, i), a();
1955
- };
1956
- return {
1957
- getActionsForMessage: (o) => {
1958
- if (!e(o))
1959
- return [];
1960
- const i = s[o.id], l = [];
1961
- return l.push({
1962
- id: "feedback-up",
1963
- icon: t.icons.up,
1964
- label: "Good response",
1965
- onClick: async () => {
1966
- i === "up" ? delete s[o.id] : await r(o.id, "up"), a();
1967
- },
1968
- tooltip: "This response was helpful",
1969
- pressed: i === "up",
1970
- disabled: i === "down"
1971
- // Disable if other is selected
1972
- }), l.push({
1973
- id: "feedback-down",
1974
- icon: t.icons.down,
1975
- label: "Bad response",
1976
- onClick: async () => {
1977
- i === "down" ? delete s[o.id] : await r(o.id, "down"), a();
1978
- },
1979
- tooltip: "This response was not helpful",
1980
- pressed: i === "down",
1981
- disabled: i === "up"
1982
- // Disable if other is selected
1983
- }), l;
1984
- },
1985
- clearFeedback: (o) => {
1986
- delete s[o], a();
1987
- },
1988
- clearAllFeedback: () => {
1989
- Object.keys(s).forEach((o) => {
1990
- delete s[o];
1991
- }), a();
1992
- },
1993
- onChange: (o) => {
1994
- n.push(o);
1995
- },
1996
- offChange: (o) => {
1997
- const i = n.indexOf(o);
1998
- i > -1 && n.splice(i, 1);
1999
- }
2000
- };
2001
- };
2002
- function Ee() {
2003
- const [t, e] = X([]), s = j(
1680
+ function ge() {
1681
+ const [t, s] = ht([]), e = H(
2004
1682
  (r) => {
2005
- e((o) => {
2006
- const i = o.findIndex(
2007
- (l) => l.id === r.id
1683
+ s((a) => {
1684
+ const l = a.findIndex(
1685
+ (i) => i.id === r.id
2008
1686
  );
2009
- if (i >= 0) {
2010
- const l = [...o];
2011
- return l[i] = r, l;
1687
+ if (l >= 0) {
1688
+ const i = [...a];
1689
+ return i[l] = r, i;
2012
1690
  }
2013
- return [...o, r];
1691
+ return [...a, r];
2014
1692
  });
2015
1693
  },
2016
1694
  []
2017
- ), n = j((r) => {
2018
- e((o) => o.filter((i) => i.id !== r));
2019
- }, []), a = j(() => {
2020
- e([]);
1695
+ ), n = H((r) => {
1696
+ s((a) => a.filter((l) => l.id !== r));
1697
+ }, []), o = H(() => {
1698
+ s([]);
2021
1699
  }, []);
2022
1700
  return {
2023
- registerMessageActions: s,
1701
+ registerMessageActions: e,
2024
1702
  unregisterMessageActions: n,
2025
- clearAllMessageActions: a,
2026
- createFeedbackActions: Re,
1703
+ clearAllMessageActions: o,
2027
1704
  registrations: t
2028
1705
  };
2029
1706
  }
2030
- function Pe(t, e) {
2031
- return e.flatMap((a) => typeof a.actions == "function" ? a.actions(t) : a.actions).filter((a) => !(a.condition && !a.condition(t))).map((a) => ({
2032
- id: a.id,
2033
- label: a.label,
2034
- icon: a.icon,
2035
- onClick: a.onClick,
2036
- tooltip: a.tooltip,
2037
- disabled: a.disabled || !1,
2038
- pressed: a.pressed,
2039
- showLabel: a.showLabel
1707
+ function fe(t, s) {
1708
+ return s.flatMap((o) => typeof o.actions == "function" ? o.actions(t) : o.actions).filter((o) => !(o.condition && !o.condition(t))).map((o) => ({
1709
+ id: o.id,
1710
+ label: o.label,
1711
+ icon: o.icon,
1712
+ onClick: o.onClick,
1713
+ tooltip: o.tooltip,
1714
+ disabled: o.disabled || !1,
1715
+ pressed: o.pressed,
1716
+ showLabel: o.showLabel
2040
1717
  }));
2041
1718
  }
2042
- const Q = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), V = (t, e = []) => {
2043
- var o;
2044
- if (t.parts.some((i) => {
2045
- if (i.type === "data") {
2046
- const l = i.data;
2047
- return l.toolCallId || l.toolId || l.result;
1719
+ const nt = (t) => [...t].sort((s, e) => s.timestamp - e.timestamp), z = (t, s = []) => {
1720
+ var a;
1721
+ if (t.parts.some((l) => {
1722
+ if (l.type === "data") {
1723
+ const i = l.data;
1724
+ return i.toolCallId || i.toolId || i.result;
2048
1725
  }
2049
1726
  return !1;
2050
1727
  }))
2051
1728
  return null;
2052
- const n = t.parts.map((i) => {
2053
- if (i.type === "text")
1729
+ const n = t.parts.map((l) => {
1730
+ if (l.type === "text")
2054
1731
  return {
2055
1732
  type: "text",
2056
- text: i.text
1733
+ text: l.text
2057
1734
  };
2058
- if (i.type === "file")
1735
+ if (l.type === "file")
2059
1736
  return {
2060
1737
  type: "image_url",
2061
- image_url: i.file.uri || `data:${i.file.mimeType};base64,${i.file.bytes}`
1738
+ image_url: l.file.uri || `data:${l.file.mimeType};base64,${l.file.bytes}`
2062
1739
  };
2063
- if (i.type === "data") {
2064
- const l = i.data;
2065
- return l.component && l.componentProps ? {
1740
+ if (l.type === "data") {
1741
+ const i = l.data;
1742
+ return i.component && i.componentProps ? {
2066
1743
  type: "component",
2067
- component: l.component,
2068
- componentProps: l.componentProps
1744
+ component: i.component,
1745
+ componentProps: i.componentProps
2069
1746
  } : {
2070
1747
  type: "text",
2071
- text: JSON.stringify(l)
1748
+ text: JSON.stringify(i)
2072
1749
  };
2073
1750
  }
2074
1751
  return {
2075
1752
  type: "text",
2076
1753
  text: "[Unsupported content]"
2077
1754
  };
2078
- }), a = ((o = t.metadata) == null ? void 0 : o.timestamp) ?? Date.now(), r = {
1755
+ }), o = ((a = t.metadata) == null ? void 0 : a.timestamp) ?? Date.now(), r = {
2079
1756
  id: t.messageId,
2080
1757
  role: t.role === "agent" ? "agent" : "user",
2081
1758
  content: n,
2082
- timestamp: a,
1759
+ timestamp: o,
2083
1760
  archived: !1,
2084
1761
  showIcon: t.role === "agent",
2085
1762
  icon: t.role === "agent" ? "assistant" : void 0
2086
1763
  };
2087
- if (t.role === "agent" && e.length > 0) {
2088
- const i = Pe(
1764
+ if (t.role === "agent" && s.length > 0) {
1765
+ const l = fe(
2089
1766
  r,
2090
- e
1767
+ s
2091
1768
  );
2092
- i.length > 0 && (r.actions = i);
1769
+ l.length > 0 && (r.actions = l);
2093
1770
  }
2094
1771
  return r;
2095
- }, Oe = () => ({
1772
+ }, me = () => ({
2096
1773
  getClientContext: () => ({})
2097
- }), Ne = () => ({
1774
+ }), pe = () => ({
2098
1775
  getAvailableTools: async () => [],
2099
1776
  executeTool: async () => ({
2100
1777
  success: !0,
2101
1778
  result: "No tools available"
2102
1779
  })
2103
- }), $e = (t) => ["agentId", "agentUrl", "sessionId"].every((s) => {
2104
- const n = t[s];
1780
+ }), he = (t) => ["agentId", "agentUrl", "sessionId"].every((e) => {
1781
+ const n = t[e];
2105
1782
  return typeof n == "string" && n.trim().length > 0;
2106
1783
  });
2107
- function Qe(t) {
2108
- const e = {
1784
+ function Ee(t) {
1785
+ const s = {
2109
1786
  agentId: t.agentId,
2110
1787
  agentUrl: t.agentUrl,
2111
1788
  sessionId: t.sessionId
2112
- }, s = $e(e), [n, a] = X({
1789
+ }, e = he(s), [n, o] = ht({
2113
1790
  clientMessages: [],
2114
1791
  uiMessages: [],
2115
1792
  isProcessing: !1,
2116
- error: s ? null : "Invalid agent configuration",
2117
- suggestions: [],
2118
- markdownComponents: {},
2119
- markdownExtensions: {},
2120
- currentAbortController: null
1793
+ error: e ? null : "Invalid agent configuration",
1794
+ suggestions: []
2121
1795
  }), {
2122
1796
  registerMessageActions: r,
2123
- unregisterMessageActions: o,
2124
- clearAllMessageActions: i,
2125
- createFeedbackActions: l,
2126
- registrations: c
2127
- } = Ee(), g = xt(c);
2128
- Y(() => {
2129
- g.current = c;
2130
- }, [c]), Y(() => {
2131
- if (!s)
1797
+ unregisterMessageActions: a,
1798
+ clearAllMessageActions: l,
1799
+ registrations: i
1800
+ } = ge(), d = Et(i);
1801
+ tt(() => {
1802
+ d.current = i;
1803
+ }, [i]), tt(() => {
1804
+ if (!e)
2132
1805
  return;
2133
1806
  (async () => {
2134
- if (e.sessionId) {
2135
- const d = It(), f = `${e.agentId}-${e.sessionId}`;
2136
- if (!d.hasAgent(f)) {
2137
- await d.createAgent(f, {
2138
- agentId: e.agentId,
2139
- agentUrl: e.agentUrl,
2140
- sessionId: e.sessionId,
2141
- contextProvider: t.contextProvider || Oe(),
2142
- toolProvider: t.toolProvider || Ne(),
1807
+ if (s.sessionId) {
1808
+ const m = st(), y = `${s.agentId}-${s.sessionId}`;
1809
+ if (!m.hasAgent(y)) {
1810
+ await m.createAgent(y, {
1811
+ agentId: s.agentId,
1812
+ agentUrl: s.agentUrl,
1813
+ sessionId: s.sessionId,
1814
+ contextProvider: t.contextProvider || me(),
1815
+ toolProvider: t.toolProvider || pe(),
2143
1816
  authProvider: t.authProvider,
2144
1817
  enableStreaming: t.enableStreaming
2145
1818
  });
2146
- const T = d.getConversationHistory(f);
2147
- a((I) => {
2148
- const P = T.map(
2149
- (w) => V(
2150
- w,
2151
- g.current
1819
+ const u = m.getConversationHistory(y);
1820
+ o((w) => {
1821
+ const S = u.map(
1822
+ (f) => z(
1823
+ f,
1824
+ d.current
2152
1825
  )
2153
1826
  ).filter(
2154
- (w) => w !== null
1827
+ (f) => f !== null
2155
1828
  );
2156
1829
  return {
2157
- ...I,
2158
- clientMessages: T,
2159
- uiMessages: P
1830
+ ...w,
1831
+ clientMessages: u,
1832
+ uiMessages: S
2160
1833
  };
2161
1834
  });
2162
1835
  }
2163
1836
  }
2164
1837
  })();
2165
1838
  }, [
2166
- e.sessionId,
2167
- e.agentId,
2168
- e.agentUrl,
1839
+ s.sessionId,
1840
+ s.agentId,
1841
+ s.agentUrl,
2169
1842
  t.contextProvider,
2170
1843
  t.toolProvider,
2171
1844
  t.authProvider,
2172
1845
  t.enableStreaming,
2173
- s
1846
+ e
2174
1847
  ]);
2175
- const y = j(
2176
- async (h) => {
2177
- var w;
2178
- if (!s)
1848
+ const c = H(
1849
+ async (p) => {
1850
+ var S;
1851
+ if (!e)
2179
1852
  throw new Error("Invalid agent configuration");
2180
- const d = It(), f = `${e.agentId}-${e.sessionId}`, T = Date.now(), I = {
2181
- id: `user-${T}`,
1853
+ const m = st(), y = `${s.agentId}-${s.sessionId}`, u = Date.now(), w = {
1854
+ id: `user-${u}`,
2182
1855
  role: "user",
2183
- content: [{ type: "text", text: h }],
2184
- timestamp: T,
1856
+ content: [{ type: "text", text: p }],
1857
+ timestamp: u,
2185
1858
  archived: !1,
2186
1859
  showIcon: !1
2187
- }, P = new AbortController();
2188
- a((m) => ({
2189
- ...m,
2190
- uiMessages: [...m.uiMessages, I],
1860
+ };
1861
+ o((f) => ({
1862
+ ...f,
1863
+ uiMessages: [...f.uiMessages, w],
2191
1864
  isProcessing: !0,
2192
- error: null,
2193
- currentAbortController: P
1865
+ error: null
2194
1866
  }));
2195
1867
  try {
2196
- let m = null, k = !1;
2197
- for await (const C of d.sendMessageStream(
2198
- f,
2199
- h,
2200
- {
2201
- abortSignal: P.signal
2202
- }
1868
+ let f = null, C = !1;
1869
+ for await (const I of m.sendMessageStream(
1870
+ y,
1871
+ p
2203
1872
  )) {
2204
- if (!C.final && C.text)
2205
- if (m)
2206
- a((E) => ({
2207
- ...E,
2208
- uiMessages: E.uiMessages.map(
2209
- (R) => R.id === m ? {
2210
- ...R,
1873
+ if (!I.final && I.text)
1874
+ if (f)
1875
+ o((b) => ({
1876
+ ...b,
1877
+ uiMessages: b.uiMessages.map(
1878
+ (x) => x.id === f ? {
1879
+ ...x,
2211
1880
  content: [
2212
1881
  {
2213
1882
  type: "text",
2214
- text: C.text
1883
+ text: I.text
2215
1884
  }
2216
1885
  ]
2217
- } : R
1886
+ } : x
2218
1887
  )
2219
1888
  }));
2220
1889
  else {
2221
- m = `agent-streaming-${Date.now()}`;
2222
- const E = {
2223
- id: m,
1890
+ f = `agent-streaming-${Date.now()}`;
1891
+ const b = {
1892
+ id: f,
2224
1893
  role: "agent",
2225
1894
  content: [
2226
- { type: "text", text: C.text }
1895
+ { type: "text", text: I.text }
2227
1896
  ],
2228
1897
  timestamp: Date.now(),
2229
1898
  archived: !1,
2230
1899
  showIcon: !0,
2231
1900
  icon: "assistant"
2232
1901
  };
2233
- a((R) => ({
2234
- ...R,
1902
+ o((x) => ({
1903
+ ...x,
2235
1904
  uiMessages: [
2236
- ...R.uiMessages,
2237
- E
1905
+ ...x.uiMessages,
1906
+ b
2238
1907
  ]
2239
1908
  }));
2240
1909
  }
2241
- if (C.final && ((w = C.status) != null && w.message) && m) {
2242
- k = !0;
2243
- const E = m, R = V(
2244
- C.status.message,
2245
- g.current
1910
+ if (I.final && ((S = I.status) != null && S.message) && f) {
1911
+ C = !0;
1912
+ const b = f, x = z(
1913
+ I.status.message,
1914
+ d.current
2246
1915
  );
2247
- R && a((O) => {
2248
- const v = O.uiMessages.map(
2249
- (B) => B.id === E ? R : B
2250
- ), F = d.getConversationHistory(
2251
- f
1916
+ x && o((_) => {
1917
+ const N = _.uiMessages.map(
1918
+ (P) => P.id === b ? x : P
1919
+ ), R = m.getConversationHistory(
1920
+ y
2252
1921
  );
2253
1922
  return {
2254
- ...O,
2255
- clientMessages: F,
2256
- uiMessages: v,
2257
- isProcessing: !1,
2258
- currentAbortController: null
1923
+ ..._,
1924
+ clientMessages: R,
1925
+ uiMessages: N,
1926
+ isProcessing: !1
2259
1927
  };
2260
- }), m = null;
1928
+ }), f = null;
2261
1929
  }
2262
1930
  }
2263
- if (!k) {
2264
- const C = d.getConversationHistory(f);
2265
- a((E) => {
2266
- let R = E.uiMessages;
2267
- m && (R = E.uiMessages.filter(
2268
- (_) => _.id !== m
1931
+ if (!C) {
1932
+ const I = m.getConversationHistory(y);
1933
+ o((b) => {
1934
+ let x = b.uiMessages;
1935
+ f && (x = b.uiMessages.filter(
1936
+ (A) => A.id !== f
2269
1937
  ));
2270
- const O = C.map(
2271
- (_) => V(
2272
- _,
2273
- g.current
1938
+ const _ = I.map(
1939
+ (A) => z(
1940
+ A,
1941
+ d.current
2274
1942
  )
2275
1943
  ).filter(
2276
- (_) => _ !== null
2277
- ), v = new Set(
2278
- C.map((_) => _.messageId)
2279
- ), F = R.filter(
2280
- (_) => {
2281
- var K;
2282
- return !v.has(_.id) && ((K = _.content[0]) == null ? void 0 : K.type) === "component";
1944
+ (A) => A !== null
1945
+ ), N = new Set(
1946
+ I.map((A) => A.messageId)
1947
+ ), R = x.filter(
1948
+ (A) => {
1949
+ var E;
1950
+ return !N.has(A.id) && ((E = A.content[0]) == null ? void 0 : E.type) === "component";
2283
1951
  }
2284
- ), B = Q([
2285
- ...O,
2286
- ...F
1952
+ ), P = nt([
1953
+ ..._,
1954
+ ...R
2287
1955
  ]);
2288
1956
  return {
2289
- ...E,
2290
- clientMessages: C,
2291
- uiMessages: B,
2292
- isProcessing: !1,
2293
- currentAbortController: null
1957
+ ...b,
1958
+ clientMessages: I,
1959
+ uiMessages: P,
1960
+ isProcessing: !1
2294
1961
  };
2295
1962
  });
2296
1963
  }
2297
- } catch (m) {
2298
- if (m instanceof Error && m.name === "AbortError") {
2299
- console.log("Request was aborted by user"), a((C) => ({
2300
- ...C,
1964
+ } catch (f) {
1965
+ if (f instanceof Error && f.name === "AbortError") {
1966
+ console.log("Request was aborted by user"), o((I) => ({
1967
+ ...I,
2301
1968
  isProcessing: !1,
2302
- error: null,
1969
+ error: null
2303
1970
  // Don't show error for user-initiated abort
2304
- currentAbortController: null
2305
1971
  }));
2306
1972
  return;
2307
1973
  }
2308
- const k = m instanceof Error ? m.message : "Failed to send message";
2309
- throw a((C) => ({
2310
- ...C,
1974
+ const C = f instanceof Error ? f.message : "Failed to send message";
1975
+ throw o((I) => ({
1976
+ ...I,
2311
1977
  isProcessing: !1,
2312
- error: k,
2313
- currentAbortController: null
2314
- })), m;
1978
+ error: C
1979
+ })), f;
2315
1980
  }
2316
1981
  },
2317
- [e.agentId, e.sessionId, s]
2318
- ), b = j((h) => {
2319
- a((d) => ({
2320
- ...d,
2321
- uiMessages: Q([...d.uiMessages, h])
1982
+ [s.agentId, s.sessionId, e]
1983
+ ), g = H((p) => {
1984
+ o((m) => ({
1985
+ ...m,
1986
+ uiMessages: nt([...m.uiMessages, p])
2322
1987
  }));
2323
- }, []), A = j((h) => {
2324
- a((d) => ({
2325
- ...d,
2326
- suggestions: h
1988
+ }, []), h = H((p) => {
1989
+ o((m) => ({
1990
+ ...m,
1991
+ suggestions: p
2327
1992
  }));
2328
- }, []), S = j(() => {
2329
- a((h) => ({
2330
- ...h,
1993
+ }, []), T = H(() => {
1994
+ o((p) => ({
1995
+ ...p,
2331
1996
  suggestions: []
2332
1997
  }));
2333
- }, []), M = j(
2334
- (h) => {
2335
- a((d) => {
2336
- const f = {
2337
- ...d.markdownComponents,
2338
- ...h
2339
- }, T = d.clientMessages.map(
2340
- (m) => V(
2341
- m,
2342
- g.current
2343
- )
2344
- ).filter((m) => m !== null), I = new Set(
2345
- d.clientMessages.map((m) => m.messageId)
2346
- ), P = d.uiMessages.filter(
2347
- (m) => {
2348
- var k;
2349
- return !I.has(m.id) && ((k = m.content[0]) == null ? void 0 : k.type) === "component";
2350
- }
2351
- ), w = Q([
2352
- ...T,
2353
- ...P
2354
- ]);
2355
- return {
2356
- ...d,
2357
- markdownComponents: f,
2358
- uiMessages: w
2359
- };
2360
- });
2361
- },
2362
- []
2363
- ), x = j(
2364
- (h) => {
2365
- a((d) => {
2366
- const f = {
2367
- ...d.markdownExtensions,
2368
- ...h
2369
- }, T = d.clientMessages.map(
2370
- (m) => V(
2371
- m,
2372
- g.current
2373
- )
2374
- ).filter((m) => m !== null), I = new Set(
2375
- d.clientMessages.map((m) => m.messageId)
2376
- ), P = d.uiMessages.filter(
2377
- (m) => {
2378
- var k;
2379
- return !I.has(m.id) && ((k = m.content[0]) == null ? void 0 : k.type) === "component";
2380
- }
2381
- ), w = Q([
2382
- ...T,
2383
- ...P
2384
- ]);
2385
- return {
2386
- ...d,
2387
- markdownExtensions: f,
2388
- uiMessages: w
2389
- };
2390
- });
2391
- },
2392
- []
2393
- );
2394
- Y(() => {
2395
- a((h) => {
2396
- if (h.clientMessages.length === 0)
2397
- return h;
2398
- const d = h.clientMessages.map(
2399
- (I) => V(I, g.current)
2400
- ).filter((I) => I !== null), f = new Set(
2401
- h.clientMessages.map((I) => I.messageId)
2402
- ), T = h.uiMessages.filter(
2403
- (I) => {
2404
- var P;
2405
- return !f.has(I.id) && ((P = I.content[0]) == null ? void 0 : P.type) === "component";
1998
+ }, []);
1999
+ tt(() => {
2000
+ o((p) => {
2001
+ if (p.clientMessages.length === 0)
2002
+ return p;
2003
+ const m = p.clientMessages.map(
2004
+ (w) => z(w, d.current)
2005
+ ).filter((w) => w !== null), y = new Set(
2006
+ p.clientMessages.map((w) => w.messageId)
2007
+ ), u = p.uiMessages.filter(
2008
+ (w) => {
2009
+ var S;
2010
+ return !y.has(w.id) && ((S = w.content[0]) == null ? void 0 : S.type) === "component";
2406
2011
  }
2407
2012
  );
2408
2013
  return {
2409
- ...h,
2410
- uiMessages: Q([
2411
- ...d,
2412
- ...T
2014
+ ...p,
2015
+ uiMessages: nt([
2016
+ ...m,
2017
+ ...u
2413
2018
  ])
2414
2019
  };
2415
2020
  });
2416
- }, [c]);
2417
- const p = it(
2418
- () => ve({
2419
- components: n.markdownComponents,
2420
- extensions: n.markdownExtensions
2421
- }),
2422
- [n.markdownComponents, n.markdownExtensions]
2423
- ), u = j(() => {
2424
- a((h) => (h.currentAbortController && h.currentAbortController.abort(), h));
2425
- }, []);
2021
+ }, [i]);
2022
+ const M = H(() => {
2023
+ if (!e)
2024
+ return;
2025
+ const p = st(), m = `${s.agentId}-${s.sessionId}`;
2026
+ p.abortCurrentRequest(m);
2027
+ }, [s.agentId, s.sessionId, e]);
2426
2028
  return {
2427
2029
  // AgentUI props
2428
2030
  messages: n.uiMessages,
2429
2031
  isProcessing: n.isProcessing,
2430
2032
  error: n.error,
2431
- onSubmit: y,
2033
+ onSubmit: c,
2432
2034
  suggestions: n.suggestions,
2433
- messageRenderer: p,
2434
2035
  // UI management methods
2435
- registerSuggestions: A,
2436
- clearSuggestions: S,
2437
- registerMarkdownComponents: M,
2438
- registerMarkdownExtensions: x,
2036
+ registerSuggestions: h,
2037
+ clearSuggestions: T,
2439
2038
  // Message actions methods
2440
2039
  registerMessageActions: r,
2441
- unregisterMessageActions: o,
2442
- clearAllMessageActions: i,
2443
- createFeedbackActions: l,
2040
+ unregisterMessageActions: a,
2041
+ clearAllMessageActions: l,
2444
2042
  // Tool integration
2445
- addMessage: b,
2043
+ addMessage: g,
2446
2044
  // Abort control
2447
- abortCurrentRequest: u
2045
+ abortCurrentRequest: M
2448
2046
  };
2449
2047
  }
2450
- var De = /* @__PURE__ */ ((t) => (t[t.PARSE_ERROR = -32700] = "PARSE_ERROR", t[t.INVALID_REQUEST = -32600] = "INVALID_REQUEST", t[t.METHOD_NOT_FOUND = -32601] = "METHOD_NOT_FOUND", t[t.INVALID_PARAMS = -32602] = "INVALID_PARAMS", t[t.INTERNAL_ERROR = -32603] = "INTERNAL_ERROR", t[t.SERVER_ERROR = -32e3] = "SERVER_ERROR", t))(De || {});
2451
- const Ct = "jetpack-ai-jwt-token", _e = 30 * 60 * 1e3;
2452
- function je() {
2453
- var s;
2454
- return window.JP_CONNECTION_INITIAL_STATE ? !1 : !!((s = window.Jetpack_Editor_Initial_State) != null && s.wpcomBlogId);
2048
+ var ye = /* @__PURE__ */ ((t) => (t[t.PARSE_ERROR = -32700] = "PARSE_ERROR", t[t.INVALID_REQUEST = -32600] = "INVALID_REQUEST", t[t.METHOD_NOT_FOUND = -32601] = "METHOD_NOT_FOUND", t[t.INVALID_PARAMS = -32602] = "INVALID_PARAMS", t[t.INTERNAL_ERROR = -32603] = "INTERNAL_ERROR", t[t.SERVER_ERROR = -32e3] = "SERVER_ERROR", t))(ye || {});
2049
+ const pt = "jetpack-ai-jwt-token", we = 30 * 60 * 1e3;
2050
+ function Ie() {
2051
+ var e;
2052
+ return window.JP_CONNECTION_INITIAL_STATE ? !1 : !!((e = window.Jetpack_Editor_Initial_State) != null && e.wpcomBlogId);
2455
2053
  }
2456
- async function Fe(t, e = !0) {
2457
- var l, c;
2458
- const s = localStorage.getItem(Ct);
2054
+ async function Te(t, s = !0) {
2055
+ var i, d;
2056
+ const e = localStorage.getItem(pt);
2459
2057
  let n;
2460
- if (s)
2058
+ if (e)
2461
2059
  try {
2462
- n = JSON.parse(s);
2463
- } catch (g) {
2464
- console.warn("Invalid cached Jetpack token:", g);
2060
+ n = JSON.parse(e);
2061
+ } catch (c) {
2062
+ console.warn("Invalid cached Jetpack token:", c);
2465
2063
  }
2466
- if (n && (n != null && n.token) && (n != null && n.expire) && (n == null ? void 0 : n.expire) > Date.now() && e)
2064
+ if (n && (n != null && n.token) && (n != null && n.expire) && (n == null ? void 0 : n.expire) > Date.now() && s)
2467
2065
  return n;
2468
- const a = (l = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : l.apiNonce, r = (c = window.Jetpack_Editor_Initial_State) == null ? void 0 : c.wpcomBlogId;
2469
- let o = {
2066
+ const o = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (d = window.Jetpack_Editor_Initial_State) == null ? void 0 : d.wpcomBlogId;
2067
+ let a = {
2470
2068
  token: "",
2471
2069
  blog_id: ""
2472
2070
  };
2473
2071
  try {
2474
- je() ? o = await mt({
2072
+ Ie() ? a = await ut({
2475
2073
  path: "/wpcom/v2/sites/" + r + "/jetpack-openai-query/jwt",
2476
2074
  method: "POST"
2477
- }) : o = await mt({
2075
+ }) : a = await ut({
2478
2076
  path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
2479
2077
  credentials: "same-origin",
2480
2078
  headers: {
2481
- "X-WP-Nonce": a || ""
2079
+ "X-WP-Nonce": o || ""
2482
2080
  },
2483
2081
  method: "POST"
2484
2082
  });
2485
- } catch (g) {
2486
- throw console.log("Failed to fetch Jetpack token:", g), new Error(t(g));
2083
+ } catch (c) {
2084
+ throw console.log("Failed to fetch Jetpack token:", c), new Error(t(c));
2487
2085
  }
2488
- if (!(o != null && o.token))
2086
+ if (!(a != null && a.token))
2489
2087
  throw new Error(
2490
2088
  "Authentication failed. Please ensure Jetpack is properly connected and try again."
2491
2089
  );
2492
- const i = {
2493
- token: o.token,
2494
- blogId: o.blog_id || "",
2495
- expire: Date.now() + _e
2090
+ const l = {
2091
+ token: a.token,
2092
+ blogId: a.blog_id || "",
2093
+ expire: Date.now() + we
2496
2094
  };
2497
2095
  try {
2498
- localStorage.setItem(Ct, JSON.stringify(i));
2499
- } catch (g) {
2500
- console.log("Error storing token in localStorage:", g);
2096
+ localStorage.setItem(pt, JSON.stringify(l));
2097
+ } catch (c) {
2098
+ console.log("Error storing token in localStorage:", c);
2501
2099
  }
2502
- return i;
2100
+ return l;
2503
2101
  }
2504
- const Xe = (t) => async () => {
2505
- const e = {};
2102
+ const Pe = (t) => async () => {
2103
+ const s = {};
2506
2104
  try {
2507
- const s = await Fe(t);
2508
- s != null && s.token && (e.Authorization = `${s.token}`);
2509
- } catch (s) {
2510
- throw console.error("Failed to get Jetpack token for auth:", s), s;
2105
+ const e = await Te(t);
2106
+ e != null && e.token && (s.Authorization = `${e.token}`);
2107
+ } catch (e) {
2108
+ throw console.error("Failed to get Jetpack token for auth:", e), e;
2511
2109
  }
2512
- return e;
2110
+ return s;
2513
2111
  };
2514
2112
  export {
2515
- De as A2AErrorCodes,
2516
- Ht as BarChart,
2517
- be as ChartBlock,
2518
- Te as LineChart,
2519
- Ge as createAbortController,
2520
- ue as createClient,
2521
- Re as createFeedbackActions,
2522
- Xe as createJetpackAuthProvider,
2523
- ve as createMessageRenderer,
2524
- Lt as createRequestId,
2525
- Wt as createTaskId,
2526
- rt as createTextMessage,
2527
- U as extractTextFromMessage,
2528
- J as extractToolCallsFromMessage,
2529
- It as getAgentManager,
2530
- Qe as useAgentChat,
2531
- Ve as useClientContext,
2532
- ze as useClientTools,
2533
- Ee as useMessageActions
2113
+ ye as A2AErrorCodes,
2114
+ _t as convertAbilitiesToTools,
2115
+ Ot as convertAbilityToTool,
2116
+ ke as createAbortController,
2117
+ te as createClient,
2118
+ Pe as createJetpackAuthProvider,
2119
+ Nt as createRequestId,
2120
+ qt as createTaskId,
2121
+ ot as createTextMessage,
2122
+ $ as extractTextFromMessage,
2123
+ F as extractToolCallsFromMessage,
2124
+ st as getAgentManager,
2125
+ be as isWordPressAbility,
2126
+ Ee as useAgentChat,
2127
+ ve as useClientAbilities,
2128
+ Se as useClientContext,
2129
+ Ae as useClientTools,
2130
+ Re as useClientToolsWithAbilities,
2131
+ ge as useMessageActions
2534
2132
  };