@automattic/agenttic-client 0.1.14 → 0.1.16

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