@automattic/agenttic-client 0.1.13 → 0.1.14

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