@automattic/agenttic-client 0.1.69 → 0.1.70

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,49 +1,49 @@
1
- var Qe = Object.defineProperty;
2
- var Ge = (e, s, t) => s in e ? Qe(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
3
- var ce = (e, s, t) => Ge(e, typeof s != "symbol" ? s + "" : s, t);
4
- import Xe, { useMemo as _e, useCallback as D, useState as Ee, useRef as ue, useEffect as ae } from "react";
5
- import { l as v, f as Ne, a as z } from "./logger-aKHbTlwk.js";
6
- import Se from "@wordpress/api-fetch";
7
- import { m as ws, l as Ms, i as Ts, j as As, k as vs, h as Ss, f as Cs, o as xs, q as bs, s as Rs, g as ks, n as Ps, a as _s, d as Es, p as Ns, e as Hs, b as Os, c as Us, r as $s, u as qs } from "./useAgentsApiChat-BK33Zwmv.js";
8
- function ns(e) {
9
- return _e(() => e ? {
1
+ var Ge = Object.defineProperty;
2
+ var Xe = (e, s, t) => s in e ? Ge(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
3
+ var de = (e, s, t) => Xe(e, typeof s != "symbol" ? s + "" : s, t);
4
+ import Ye, { useMemo as Ee, useCallback as j, useState as Ne, useRef as re, useEffect as te } from "react";
5
+ import { l as A, f as Ue, a as V } from "./logger-aKHbTlwk.js";
6
+ import Ce from "@wordpress/api-fetch";
7
+ import { m as Ms, l as Ts, i as As, j as vs, k as Ss, h as Cs, f as xs, o as bs, q as Rs, s as ks, g as Ps, n as _s, a as Es, d as Ns, p as Us, e as Hs, b as Os, c as $s, r as qs, u as Fs } from "./useAgentsApiChat-BK33Zwmv.js";
8
+ function rs(e) {
9
+ return Ee(() => e ? {
10
10
  getClientContext: () => {
11
11
  try {
12
12
  return e() || {};
13
13
  } catch (a) {
14
- return v("Error getting client context: %O", a), {};
14
+ return A("Error getting client context: %O", a), {};
15
15
  }
16
16
  }
17
17
  } : void 0, [e]);
18
18
  }
19
- function he({
19
+ function ye({
20
20
  getClientTools: e,
21
21
  executeTool: s,
22
22
  getAbilities: t
23
23
  }) {
24
- const a = D(async () => {
24
+ const a = j(async () => {
25
25
  const r = [];
26
26
  if (e)
27
27
  try {
28
28
  const l = await e();
29
29
  r.push(...l);
30
30
  } catch (l) {
31
- v("Error getting available tools: %O", l);
31
+ A("Error getting available tools: %O", l);
32
32
  }
33
33
  return r;
34
- }, [e]), n = D(
34
+ }, [e]), n = j(
35
35
  async (r, l) => {
36
36
  if (!s)
37
37
  throw new Error("No executeTool callback provided");
38
38
  try {
39
39
  return await s(r, l);
40
40
  } catch (i) {
41
- throw v("Error executing tool %s: %O", r, i), i;
41
+ throw A("Error executing tool %s: %O", r, i), i;
42
42
  }
43
43
  },
44
44
  [s]
45
45
  );
46
- return _e(() => {
46
+ return Ee(() => {
47
47
  if (!e && !t)
48
48
  return;
49
49
  const r = {};
@@ -56,21 +56,21 @@ function he({
56
56
  t
57
57
  ]);
58
58
  }
59
- function rs(e, s) {
60
- return he({
59
+ function os(e, s) {
60
+ return ye({
61
61
  getClientTools: e,
62
62
  executeTool: s,
63
63
  getAbilities: void 0
64
64
  });
65
65
  }
66
- function os(e) {
67
- return he({
66
+ function is(e) {
67
+ return ye({
68
68
  getClientTools: void 0,
69
69
  executeTool: void 0,
70
70
  getAbilities: e
71
71
  });
72
72
  }
73
- function is(e) {
73
+ function ls(e) {
74
74
  const { getClientTools: s, executeTool: t, getAbilities: a } = e;
75
75
  if (!s && !a)
76
76
  throw new Error(
@@ -80,13 +80,13 @@ function is(e) {
80
80
  throw new Error(
81
81
  "executeTool is required when providing getClientTools."
82
82
  );
83
- return he({
83
+ return ye({
84
84
  getClientTools: s,
85
85
  executeTool: t,
86
86
  getAbilities: a
87
87
  });
88
88
  }
89
- function ye() {
89
+ function Ie() {
90
90
  const e = "abcdefghijklmnopqrstuvwxyz0123456789";
91
91
  let s = "";
92
92
  for (let t = 0; t < 8; t++)
@@ -94,13 +94,13 @@ function ye() {
94
94
  return s;
95
95
  }
96
96
  function q() {
97
- return ye();
98
- }
99
- function Ye() {
100
- return `req-${ye()}`;
97
+ return Ie();
101
98
  }
102
99
  function Ze() {
103
- return `task-${ye()}`;
100
+ return `req-${Ie()}`;
101
+ }
102
+ function et() {
103
+ return `task-${Ie()}`;
104
104
  }
105
105
  function He(e, s) {
106
106
  return {
@@ -109,22 +109,22 @@ function He(e, s) {
109
109
  ...s && { metadata: s }
110
110
  };
111
111
  }
112
- function et(e, s = "message/send", t = !1) {
112
+ function tt(e, s = "message/send", t = !1) {
113
113
  const a = {
114
114
  jsonrpc: "2.0",
115
- id: Ye(),
115
+ id: Ze(),
116
116
  method: s,
117
117
  params: {
118
- id: e.id || Ze(),
118
+ id: e.id || et(),
119
119
  ...e
120
120
  }
121
121
  };
122
122
  return t && s === "message/stream" && (a.tokenStreaming = !0), a;
123
123
  }
124
- function L(e) {
124
+ function J(e) {
125
125
  return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
126
126
  }
127
- function Ce(e) {
127
+ function xe(e) {
128
128
  if (!e || !e.parts || !Array.isArray(e.parts))
129
129
  return;
130
130
  const s = e.parts.find((t) => t.type === "progress" ? !0 : t.type === "data" ? "summary" in t.data && typeof t.data.summary == "string" : !1);
@@ -134,7 +134,7 @@ function Ce(e) {
134
134
  phase: s.data.phase
135
135
  };
136
136
  }
137
- function tt(e) {
137
+ function st(e) {
138
138
  return {
139
139
  type: "data",
140
140
  data: {
@@ -146,7 +146,7 @@ function tt(e) {
146
146
  metadata: {}
147
147
  };
148
148
  }
149
- function st(e) {
149
+ function at(e) {
150
150
  return {
151
151
  type: "data",
152
152
  data: {
@@ -161,12 +161,12 @@ function st(e) {
161
161
  metadata: {}
162
162
  };
163
163
  }
164
- function V(e) {
164
+ function Q(e) {
165
165
  return !e || !e.parts || !Array.isArray(e.parts) ? [] : e.parts.filter(
166
166
  (s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
167
167
  );
168
168
  }
169
- function B(e, s, t, a) {
169
+ function z(e, s, t, a) {
170
170
  return {
171
171
  type: "data",
172
172
  data: {
@@ -177,7 +177,7 @@ function B(e, s, t, a) {
177
177
  metadata: a ? { error: a } : void 0
178
178
  };
179
179
  }
180
- function at(e) {
180
+ function nt(e) {
181
181
  return {
182
182
  type: "data",
183
183
  data: {
@@ -186,7 +186,7 @@ function at(e) {
186
186
  metadata: {}
187
187
  };
188
188
  }
189
- function me(e, s) {
189
+ function pe(e, s) {
190
190
  const { contentType: t, ...a } = s || {};
191
191
  return {
192
192
  role: "user",
@@ -199,7 +199,7 @@ function me(e, s) {
199
199
  }
200
200
  };
201
201
  }
202
- function Y(e) {
202
+ function Z(e) {
203
203
  return {
204
204
  role: "agent",
205
205
  parts: [He(e)],
@@ -210,7 +210,7 @@ function Y(e) {
210
210
  }
211
211
  };
212
212
  }
213
- function Ie(e) {
213
+ function we(e) {
214
214
  return e && typeof e == "object" && "result" in e ? {
215
215
  result: e.result,
216
216
  returnToAgent: e.returnToAgent !== !1,
@@ -222,7 +222,7 @@ function Ie(e) {
222
222
  returnToAgent: !0
223
223
  };
224
224
  }
225
- function re(e, s = []) {
225
+ function ie(e, s = []) {
226
226
  return {
227
227
  role: "user",
228
228
  kind: "message",
@@ -233,10 +233,10 @@ function re(e, s = []) {
233
233
  }
234
234
  };
235
235
  }
236
- function ls() {
236
+ function cs() {
237
237
  return new AbortController();
238
238
  }
239
- async function nt(e, s) {
239
+ async function rt(e, s) {
240
240
  if (!s)
241
241
  return e;
242
242
  try {
@@ -244,14 +244,14 @@ async function nt(e, s) {
244
244
  if (s.getAvailableTools) {
245
245
  const a = await s.getAvailableTools();
246
246
  if (a.length > 0) {
247
- const n = a.map(tt);
247
+ const n = a.map(st);
248
248
  t.push(...n);
249
249
  }
250
250
  }
251
251
  if (s.getAbilities) {
252
252
  const a = await s.getAbilities();
253
253
  if (a.length > 0) {
254
- const n = a.map(st);
254
+ const n = a.map(at);
255
255
  t.push(...n);
256
256
  }
257
257
  }
@@ -260,38 +260,38 @@ async function nt(e, s) {
260
260
  parts: [...e.parts, ...t]
261
261
  };
262
262
  } catch (t) {
263
- return v("Warning: Failed to get tools: %s", t), e;
263
+ return A("Warning: Failed to get tools: %s", t), e;
264
264
  }
265
265
  }
266
- function rt(e, s) {
266
+ function ot(e, s) {
267
267
  if (!s)
268
268
  return e;
269
269
  try {
270
270
  const t = s.getClientContext();
271
271
  if (!t || Object.keys(t).length === 0)
272
272
  return e;
273
- const a = at(t);
273
+ const a = nt(t);
274
274
  return {
275
275
  ...e,
276
276
  parts: [...e.parts, a]
277
277
  };
278
278
  } catch (t) {
279
- return v("Warning: Failed to get context: %s", t), e;
279
+ return A("Warning: Failed to get context: %s", t), e;
280
280
  }
281
281
  }
282
- async function ot(e, s, t) {
283
- let a = await nt(
282
+ async function it(e, s, t) {
283
+ let a = await rt(
284
284
  e,
285
285
  s
286
286
  );
287
- a = rt(
287
+ a = ot(
288
288
  a,
289
289
  t
290
290
  );
291
291
  const { metadata: n, ...o } = a;
292
292
  return o;
293
293
  }
294
- function it(e, s = "") {
294
+ function lt(e, s = "") {
295
295
  const t = [], a = s + e;
296
296
  let n = "", o = 0, r = 0;
297
297
  for (; r < a.length; ) {
@@ -309,7 +309,7 @@ function it(e, s = "") {
309
309
  try {
310
310
  t.push(JSON.parse(n)), o = i === -1 ? a.length : i + 1;
311
311
  } catch (c) {
312
- v("Failed to parse SSE event: %o", c), v("Problematic payload: %s", n);
312
+ A("Failed to parse SSE event: %o", c), A("Problematic payload: %s", n);
313
313
  }
314
314
  n = "";
315
315
  }
@@ -318,34 +318,34 @@ function it(e, s = "") {
318
318
  const l = a.substring(o);
319
319
  return { events: t, nextBuffer: l };
320
320
  }
321
- async function* lt(e, s = {}) {
322
- var u, c, p;
321
+ async function* ct(e, s = {}) {
322
+ var u, c, m;
323
323
  const { supportDeltas: t = !1 } = s, a = e.getReader(), n = new TextDecoder();
324
324
  let o = "";
325
- const r = new ut();
325
+ const r = new dt();
326
326
  let l = null, i = null;
327
327
  try {
328
328
  for (; ; ) {
329
- const { done: g, value: A } = await a.read();
330
- if (g)
329
+ const { done: f, value: M } = await a.read();
330
+ if (f)
331
331
  break;
332
- const f = n.decode(A, { stream: !0 }), { events: h, nextBuffer: I } = it(f, o);
332
+ const g = n.decode(M, { stream: !0 }), { events: h, nextBuffer: I } = lt(g, o);
333
333
  if (h && Array.isArray(h))
334
- for (let S = 0; S < h.length; S++) {
335
- const y = h[S];
336
- if (S > 0 && y.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((C) => {
337
- requestAnimationFrame(() => C(void 0));
334
+ for (let v = 0; v < h.length; v++) {
335
+ const y = h[v];
336
+ if (v > 0 && y.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((x) => {
337
+ requestAnimationFrame(() => x(void 0));
338
338
  }), y.error)
339
339
  throw new Error(
340
340
  `Streaming error: ${y.error.message}`
341
341
  );
342
342
  if (t && y.method === "message/delta" && ((u = y.params) != null && u.delta)) {
343
- const C = y.params.delta;
343
+ const x = y.params.delta;
344
344
  try {
345
- let x = !1;
346
- ct(C) ? (r.processToolCallDelta(C), x = !0) : C.deltaType === "content" && (r.processContentDelta(
347
- C.content
348
- ), x = !0), x && (!l && y.params.id && (l = y.params.id), l && (yield {
345
+ let b = !1;
346
+ ut(x) ? (r.processToolCallDelta(x), b = !0) : x.deltaType === "content" && (r.processContentDelta(
347
+ x.content
348
+ ), b = !0), b && (!l && y.params.id && (l = y.params.id), l && (yield {
349
349
  id: l,
350
350
  status: {
351
351
  state: "working",
@@ -355,38 +355,38 @@ async function* lt(e, s = {}) {
355
355
  text: r.getTextContent(),
356
356
  kind: "delta"
357
357
  }));
358
- } catch (x) {
359
- v("Failed to process delta: %o", x);
358
+ } catch (b) {
359
+ A("Failed to process delta: %o", b);
360
360
  }
361
361
  } else if (y.result && y.result.status) {
362
362
  l = y.result.id, i = y.result.status, (r.getTextContent() || r.getCurrentMessage().parts.length > 0) && r.reset();
363
- const C = ((c = y.result.status) == null ? void 0 : c.message) || {
363
+ const x = ((c = y.result.status) == null ? void 0 : c.message) || {
364
364
  role: "agent",
365
365
  parts: []
366
- }, x = Ce(C);
366
+ }, b = xe(x);
367
367
  yield {
368
368
  id: y.result.id,
369
369
  sessionId: y.result.sessionId,
370
370
  status: y.result.status,
371
371
  final: y.result.status.state === "completed" || y.result.status.state === "failed" || y.result.status.state === "canceled",
372
- text: L(C),
373
- progressMessage: x == null ? void 0 : x.summary,
374
- progressPhase: x == null ? void 0 : x.phase,
372
+ text: J(x),
373
+ progressMessage: b == null ? void 0 : b.summary,
374
+ progressPhase: b == null ? void 0 : b.phase,
375
375
  kind: "status"
376
376
  };
377
377
  } else if (y.id && y.result && (l = y.result.id, y.result.status)) {
378
- const C = ((p = y.result.status) == null ? void 0 : p.message) || {
378
+ const x = ((m = y.result.status) == null ? void 0 : m.message) || {
379
379
  role: "agent",
380
380
  parts: []
381
- }, x = Ce(C);
381
+ }, b = xe(x);
382
382
  yield {
383
383
  id: y.result.id,
384
384
  sessionId: y.result.sessionId,
385
385
  status: y.result.status,
386
386
  final: y.result.status.state === "completed" || y.result.status.state === "failed" || y.result.status.state === "canceled",
387
- text: L(C),
388
- progressMessage: x == null ? void 0 : x.summary,
389
- progressPhase: x == null ? void 0 : x.phase,
387
+ text: J(x),
388
+ progressMessage: b == null ? void 0 : b.summary,
389
+ progressPhase: b == null ? void 0 : b.phase,
390
390
  kind: "status"
391
391
  };
392
392
  }
@@ -397,13 +397,13 @@ async function* lt(e, s = {}) {
397
397
  a.releaseLock();
398
398
  }
399
399
  }
400
- function ct(e) {
400
+ function ut(e) {
401
401
  return e.deltaType === "tool_argument" || e.deltaType === "tool_name";
402
402
  }
403
- class ut {
403
+ class dt {
404
404
  constructor() {
405
- ce(this, "textContent", "");
406
- ce(this, "toolCalls", /* @__PURE__ */ new Map());
405
+ de(this, "textContent", "");
406
+ de(this, "toolCalls", /* @__PURE__ */ new Map());
407
407
  }
408
408
  /**
409
409
  * Process a simple content delta (server's actual format)
@@ -503,13 +503,13 @@ class ut {
503
503
  }
504
504
  }
505
505
  function Oe(e, s, t = "request") {
506
- throw clearTimeout(s), v("%s failed with error: %O", t, e), e instanceof Error && (v("Error message: %s", e.message), v("Error stack: %s", e.stack)), e;
506
+ throw clearTimeout(s), A("%s failed with error: %O", t, e), e instanceof Error && (A("Error message: %s", e.message), A("Error stack: %s", e.stack)), e;
507
507
  }
508
- function Ue(e, s = "request") {
508
+ function $e(e, s = "request") {
509
509
  if (!e.ok)
510
510
  throw new Error(`HTTP error! status: ${e.status}`);
511
511
  }
512
- function dt(e, s = "request") {
512
+ function gt(e, s = "request") {
513
513
  if (e.error)
514
514
  throw new Error(
515
515
  `Protocol ${s} error: ${e.error.message}`
@@ -518,24 +518,24 @@ function dt(e, s = "request") {
518
518
  throw new Error(`No result in ${s} response`);
519
519
  return e.result;
520
520
  }
521
- function gt(e, s = "streaming request") {
522
- if (Ue(e, s), !e.body)
521
+ function ft(e, s = "streaming request") {
522
+ if ($e(e, s), !e.body)
523
523
  throw new Error(`No response body for ${s}`);
524
524
  }
525
- function $e(e, s = "request") {
525
+ function qe(e, s = "request") {
526
526
  const t = new AbortController();
527
527
  return { timeoutId: setTimeout(
528
528
  () => t.abort(),
529
529
  e
530
530
  ), controller: t };
531
531
  }
532
- function ft(e, s) {
532
+ function mt(e, s) {
533
533
  return `${e}/${s}`;
534
534
  }
535
- function mt(e, s, t, a) {
536
- v("Request: %s %s", e, s), v("Headers: %o", t), a && v("Body: %s", Ne(a));
535
+ function pt(e, s, t, a) {
536
+ A("Request: %s %s", e, s), A("Headers: %o", t), a && A("Body: %s", Ue(a));
537
537
  }
538
- async function pt(e, s = !1) {
538
+ async function ht(e, s = !1) {
539
539
  const t = {
540
540
  "Content-Type": "application/json"
541
541
  };
@@ -545,7 +545,7 @@ async function pt(e, s = !1) {
545
545
  }
546
546
  return t;
547
547
  }
548
- function qe(e, s) {
548
+ function Fe(e, s) {
549
549
  if (!s)
550
550
  return e;
551
551
  const t = new AbortController(), a = (n) => {
@@ -557,7 +557,7 @@ function qe(e, s) {
557
557
  once: !0
558
558
  }), t.signal;
559
559
  }
560
- function Fe(e, s, t, a) {
560
+ function De(e, s, t, a) {
561
561
  const n = {
562
562
  method: "POST",
563
563
  headers: e,
@@ -566,90 +566,90 @@ function Fe(e, s, t, a) {
566
566
  };
567
567
  return a !== void 0 && (n.credentials = a), n;
568
568
  }
569
- async function oe(e, s, t, a, n, o) {
570
- const { message: r, sessionId: l, taskId: i, metadata: u } = e, { agentId: c, agentUrl: p, authProvider: g, proxy: A } = s, { isStreaming: f = !1, enableTokenStreaming: h = !1 } = t, I = l || o, S = ft(p, c), y = await ot(
569
+ async function le(e, s, t, a, n, o) {
570
+ const { message: r, sessionId: l, taskId: i, metadata: u } = e, { agentId: c, agentUrl: m, authProvider: f, proxy: M } = s, { isStreaming: g = !1, enableTokenStreaming: h = !1 } = t, I = l || o, v = mt(m, c), y = await it(
571
571
  r,
572
572
  a,
573
573
  n
574
- ), C = {
574
+ ), x = {
575
575
  id: i,
576
576
  message: y,
577
577
  metadata: u
578
578
  };
579
- I && (C.sessionId = I);
580
- const x = et(
581
- C,
582
- f ? "message/stream" : "message/send",
583
- h && f
579
+ I && (x.sessionId = I);
580
+ const b = tt(
581
+ x,
582
+ g ? "message/stream" : "message/send",
583
+ h && g
584
584
  // Only enable token streaming if using SSE
585
- ), m = await pt(g, f);
586
- return mt("POST", S, m, x), {
587
- request: x,
588
- headers: m,
585
+ ), S = await ht(f, g);
586
+ return pt("POST", v, S, b), {
587
+ request: b,
588
+ headers: S,
589
589
  enhancedMessage: y,
590
590
  effectiveSessionId: I,
591
- fullAgentUrl: S
591
+ fullAgentUrl: v
592
592
  };
593
593
  }
594
- async function De(e, s, t = {}) {
595
- const { request: a, headers: n, fullAgentUrl: o } = e, { timeout: r, credentials: l } = s, { abortSignal: i } = t, { timeoutId: u, controller: c } = $e(
594
+ async function je(e, s, t = {}) {
595
+ const { request: a, headers: n, fullAgentUrl: o } = e, { timeout: r, credentials: l } = s, { abortSignal: i } = t, { timeoutId: u, controller: c } = qe(
596
596
  r,
597
597
  "request"
598
- ), p = i ? qe(c.signal, i) : c.signal;
598
+ ), m = i ? Fe(c.signal, i) : c.signal;
599
599
  try {
600
- const g = Fe(
600
+ const f = De(
601
601
  n,
602
602
  JSON.stringify(a),
603
- p,
603
+ m,
604
604
  l
605
605
  );
606
- v("Making request to %s with options: %O", o, {
607
- method: g.method,
608
- headers: g.headers
606
+ A("Making request to %s with options: %O", o, {
607
+ method: f.method,
608
+ headers: f.headers
609
609
  });
610
- const A = await fetch(o, g);
611
- clearTimeout(u), Ue(A, "request");
612
- const f = await A.json();
613
- return v(
610
+ const M = await fetch(o, f);
611
+ clearTimeout(u), $e(M, "request");
612
+ const g = await M.json();
613
+ return A(
614
614
  "Response from %s: %d %O",
615
615
  o,
616
- A.status,
617
- Ne(f)
618
- ), dt(f, "request");
619
- } catch (g) {
620
- Oe(g, u, "request");
616
+ M.status,
617
+ Ue(g)
618
+ ), gt(g, "request");
619
+ } catch (f) {
620
+ Oe(f, u, "request");
621
621
  }
622
622
  }
623
- async function* je(e, s, t) {
623
+ async function* Le(e, s, t) {
624
624
  const { request: a, headers: n, fullAgentUrl: o } = e, { credentials: r } = s, {
625
625
  streamingTimeout: l = 6e4,
626
626
  abortSignal: i,
627
627
  enableTokenStreaming: u = !1
628
- } = t, { timeoutId: c, controller: p } = $e(
628
+ } = t, { timeoutId: c, controller: m } = qe(
629
629
  l,
630
630
  "streaming request"
631
- ), g = i ? qe(p.signal, i) : p.signal;
631
+ ), f = i ? Fe(m.signal, i) : m.signal;
632
632
  try {
633
- const A = JSON.stringify(a), f = Fe(
633
+ const M = JSON.stringify(a), g = De(
634
634
  n,
635
- A,
636
- g,
635
+ M,
636
+ f,
637
637
  r
638
- ), h = await fetch(o, f);
639
- if (clearTimeout(c), gt(h, "streaming request"), !h.body)
638
+ ), h = await fetch(o, g);
639
+ if (clearTimeout(c), ft(h, "streaming request"), !h.body)
640
640
  throw new Error(
641
641
  "Response body is null - server may not support streaming"
642
642
  );
643
643
  const I = u && a.tokenStreaming === !0;
644
- yield* lt(h.body, {
644
+ yield* ct(h.body, {
645
645
  supportDeltas: I
646
646
  });
647
- } catch (A) {
648
- Oe(A, c, "streaming request");
647
+ } catch (M) {
648
+ Oe(M, c, "streaming request");
649
649
  }
650
650
  }
651
- const ht = 12e4;
652
- async function ie(e, s, t, a, n) {
651
+ const yt = 12e4;
652
+ async function ce(e, s, t, a, n) {
653
653
  if (e.getAbilities) {
654
654
  const o = await e.getAbilities();
655
655
  if (o.length > 0)
@@ -672,7 +672,7 @@ async function ie(e, s, t, a, n) {
672
672
  }
673
673
  };
674
674
  } catch (i) {
675
- return v(
675
+ return A(
676
676
  "Error executing ability %s: %O",
677
677
  r.name,
678
678
  i
@@ -691,7 +691,7 @@ async function ie(e, s, t, a, n) {
691
691
  t
692
692
  ), returnToAgent: !0 };
693
693
  } catch (i) {
694
- return v(
694
+ return A(
695
695
  "Error executing ability %s: %O",
696
696
  r.name,
697
697
  i
@@ -720,11 +720,11 @@ async function ie(e, s, t, a, n) {
720
720
  `No handler found for tool: ${s}. Tool provider must implement executeTool for non-ability tools.`
721
721
  );
722
722
  }
723
- const we = /* @__PURE__ */ new Map();
724
- async function yt(e, s) {
723
+ const Me = /* @__PURE__ */ new Map();
724
+ async function It(e, s) {
725
725
  if (!e || !s || !e.getAvailableTools)
726
726
  return !1;
727
- const t = V(s);
727
+ const t = Q(s);
728
728
  if (t.length === 0)
729
729
  return !1;
730
730
  try {
@@ -739,20 +739,20 @@ async function yt(e, s) {
739
739
  }
740
740
  return !1;
741
741
  }
742
- function It() {
743
- we.clear();
742
+ function wt() {
743
+ Me.clear();
744
744
  }
745
- function wt(e) {
745
+ function Mt(e) {
746
746
  return e.map((s) => {
747
- const t = s.data.toolCallId, a = we.get(t);
747
+ const t = s.data.toolCallId, a = Me.get(t);
748
748
  if (a && a.resolvedValue !== null) {
749
749
  const n = a.resolvedValue;
750
- return n.error ? B(
750
+ return n.error ? z(
751
751
  t,
752
752
  s.data.toolId,
753
753
  void 0,
754
754
  n.error
755
- ) : B(
755
+ ) : z(
756
756
  t,
757
757
  s.data.toolId,
758
758
  n
@@ -761,29 +761,29 @@ function wt(e) {
761
761
  return s;
762
762
  });
763
763
  }
764
- async function Le(e, s, t) {
764
+ async function Je(e, s, t) {
765
765
  const a = [], n = [];
766
766
  let o = !1;
767
767
  for (const r of e) {
768
768
  const { toolCallId: l, toolId: i, arguments: u } = r.data;
769
769
  try {
770
- const c = await ie(
770
+ const c = await ce(
771
771
  s,
772
772
  i,
773
773
  u,
774
774
  t,
775
775
  l
776
- ), { result: p, returnToAgent: g, agentMessage: A } = Ie(c);
777
- g && (o = !0), A && n.push(Y(A)), a.push(
778
- B(
776
+ ), { result: m, returnToAgent: f, agentMessage: M } = we(c);
777
+ f && (o = !0), M && n.push(Z(M)), a.push(
778
+ z(
779
779
  l,
780
780
  i,
781
- p
781
+ m
782
782
  )
783
783
  );
784
784
  } catch (c) {
785
785
  o = !0, a.push(
786
- B(
786
+ z(
787
787
  l,
788
788
  i,
789
789
  void 0,
@@ -794,7 +794,7 @@ async function Le(e, s, t) {
794
794
  }
795
795
  return { results: a, shouldReturnToAgent: o, agentMessages: n };
796
796
  }
797
- function xe(e) {
797
+ function be(e) {
798
798
  const s = [];
799
799
  for (const t of e)
800
800
  for (const a of t.parts)
@@ -807,8 +807,8 @@ function xe(e) {
807
807
  }) : (a.type === "data" || a.type === "file") && s.push(a);
808
808
  return s;
809
809
  }
810
- async function de(e, s, t, a, n, o, r) {
811
- const i = await oe(
810
+ async function ge(e, s, t, a, n, o, r) {
811
+ const i = await le(
812
812
  {
813
813
  message: s,
814
814
  taskId: e,
@@ -821,17 +821,17 @@ async function de(e, s, t, a, n, o, r) {
821
821
  n,
822
822
  o
823
823
  );
824
- return await De(i, t, {
824
+ return await je(i, t, {
825
825
  abortSignal: r
826
826
  });
827
827
  }
828
- async function be(e, s, t, a, n, o, r, l, i = []) {
828
+ async function Re(e, s, t, a, n, o, r, l, i = []) {
829
829
  const u = {
830
830
  message: s,
831
831
  taskId: e,
832
832
  sessionId: o
833
833
  // Use the provided sessionId to maintain conversation continuity
834
- }, c = l || { isStreaming: !0 }, p = await oe(
834
+ }, c = l || { isStreaming: !0 }, m = await le(
835
835
  u,
836
836
  t,
837
837
  {
@@ -840,12 +840,12 @@ async function be(e, s, t, a, n, o, r, l, i = []) {
840
840
  a,
841
841
  n,
842
842
  o
843
- ), g = je(p, t, {
843
+ ), f = Le(m, t, {
844
844
  ...c,
845
845
  abortSignal: r
846
846
  });
847
- return Je(
848
- g,
847
+ return Ke(
848
+ f,
849
849
  a,
850
850
  n,
851
851
  t,
@@ -859,36 +859,36 @@ async function be(e, s, t, a, n, o, r, l, i = []) {
859
859
  // Pass through the same request options
860
860
  );
861
861
  }
862
- async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
863
- var u, c, p, g, A, f, h, I, S, y, C, x;
864
- for await (const m of e) {
865
- if (m.sessionId && !n && (n = m.sessionId), yield m, m.status.state === "running" && m.status.message && s && await yt(
862
+ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
863
+ var u, c, m, f, M, g, h, I, v, y, x, b;
864
+ for await (const S of e) {
865
+ if (S.sessionId && !n && (n = S.sessionId), yield S, S.status.state === "running" && S.status.message && s && await It(
866
866
  s,
867
- m.status.message
867
+ S.status.message
868
868
  )) {
869
- const d = V(
870
- m.status.message
869
+ const T = Q(
870
+ S.status.message
871
871
  );
872
- for (const w of d) {
873
- const { toolCallId: O, toolId: R, arguments: M } = w.data;
874
- ie(
872
+ for (const d of T) {
873
+ const { toolCallId: w, toolId: U, arguments: p } = d.data;
874
+ ce(
875
875
  s,
876
- R,
877
- M,
878
- (c = (u = m.status) == null ? void 0 : u.message) == null ? void 0 : c.messageId,
879
- O
880
- ).catch((b) => {
881
- v("Tool execution failed for %s: %O", R, b);
876
+ U,
877
+ p,
878
+ (c = (u = S.status) == null ? void 0 : u.message) == null ? void 0 : c.messageId,
879
+ w
880
+ ).catch((C) => {
881
+ A("Tool execution failed for %s: %O", U, C);
882
882
  });
883
883
  }
884
884
  yield {
885
- id: m.id,
885
+ id: S.id,
886
886
  status: {
887
887
  state: "running",
888
888
  message: {
889
889
  role: "agent",
890
890
  kind: "message",
891
- parts: d,
891
+ parts: T,
892
892
  messageId: q()
893
893
  }
894
894
  },
@@ -896,79 +896,79 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
896
896
  text: ""
897
897
  };
898
898
  }
899
- if (m.status.state === "input-required" && m.status.message && s) {
900
- const d = V(
901
- m.status.message
899
+ if (S.status.state === "input-required" && S.status.message && s) {
900
+ const T = Q(
901
+ S.status.message
902
902
  );
903
- if (d.length > 0) {
904
- const w = [];
905
- let O = !1;
906
- const R = [], M = [];
907
- for (const b of d) {
903
+ if (T.length > 0) {
904
+ const d = [];
905
+ let w = !1;
906
+ const U = [], p = [];
907
+ for (const C of T) {
908
908
  const {
909
909
  toolCallId: k,
910
910
  toolId: P,
911
911
  arguments: F
912
- } = b.data;
912
+ } = C.data;
913
913
  try {
914
- const U = await ie(
914
+ const O = await ce(
915
915
  s,
916
916
  P,
917
917
  F,
918
- (g = (p = m.status) == null ? void 0 : p.message) == null ? void 0 : g.messageId,
918
+ (f = (m = S.status) == null ? void 0 : m.message) == null ? void 0 : f.messageId,
919
919
  k
920
- ), { result: T, returnToAgent: E, agentMessage: _ } = Ie(U);
921
- if (E && (O = !0), _ && M.push(
922
- Y(_)
923
- ), T.result instanceof Promise) {
924
- const W = T.result, H = {
925
- promise: W,
920
+ ), { result: E, returnToAgent: R, agentMessage: H } = we(O);
921
+ if (R && (w = !0), H && p.push(
922
+ Z(H)
923
+ ), E.result instanceof Promise) {
924
+ const L = E.result, B = {
925
+ promise: L,
926
926
  resolvedValue: null
927
927
  };
928
- we.set(
928
+ Me.set(
929
929
  k,
930
- H
931
- ), W.then((N) => {
932
- H.resolvedValue = N;
933
- }).catch((N) => {
934
- v(
930
+ B
931
+ ), L.then((_) => {
932
+ B.resolvedValue = _;
933
+ }).catch((_) => {
934
+ A(
935
935
  "Promise rejected for tool call %s: %O",
936
936
  k,
937
- N
938
- ), H.resolvedValue = {
939
- error: N instanceof Error ? N.message : String(N)
937
+ _
938
+ ), B.resolvedValue = {
939
+ error: _ instanceof Error ? _.message : String(_)
940
940
  };
941
941
  });
942
942
  }
943
- const j = B(
943
+ const N = z(
944
944
  k,
945
945
  P,
946
- T
946
+ E
947
947
  );
948
- w.push(j), R.push(j);
949
- } catch (U) {
950
- const T = B(
948
+ d.push(N), U.push(N);
949
+ } catch (O) {
950
+ const E = z(
951
951
  k,
952
952
  P,
953
953
  void 0,
954
- U instanceof Error ? U.message : String(U)
954
+ O instanceof Error ? O.message : String(O)
955
955
  );
956
- w.push(T), R.push(T);
956
+ d.push(E), U.push(E);
957
957
  }
958
958
  }
959
- if (r.push(m.status.message), w.length > 0 && r.push({
959
+ if (r.push(S.status.message), d.length > 0 && r.push({
960
960
  role: "agent",
961
961
  kind: "message",
962
- parts: w,
962
+ parts: d,
963
963
  messageId: q()
964
- }), O) {
965
- const b = xe(r), k = re(
964
+ }), w) {
965
+ const C = be(r), k = ie(
966
966
  [],
967
967
  // Empty array - tool results are already in historyDataParts
968
- b
968
+ C
969
969
  );
970
970
  yield {
971
- id: m.id,
971
+ id: S.id,
972
972
  status: {
973
973
  state: "working",
974
974
  message: k
@@ -976,20 +976,20 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
976
976
  final: !1,
977
977
  text: ""
978
978
  };
979
- for (const E of M) {
980
- const _ = L(E);
979
+ for (const R of p) {
980
+ const H = J(R);
981
981
  yield {
982
- id: m.id,
982
+ id: S.id,
983
983
  status: {
984
984
  state: "working",
985
- message: Y(_)
985
+ message: Z(H)
986
986
  },
987
987
  final: !1,
988
- text: _
988
+ text: H
989
989
  };
990
990
  }
991
- const P = await be(
992
- m.id,
991
+ const P = await Re(
992
+ S.id,
993
993
  k,
994
994
  a,
995
995
  s,
@@ -1000,60 +1000,60 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
1000
1000
  r
1001
1001
  );
1002
1002
  let F = null;
1003
- for await (const E of P)
1004
- E.final ? F = E : yield E;
1003
+ for await (const R of P)
1004
+ R.final ? F = R : yield R;
1005
1005
  if (!F)
1006
1006
  throw new Error(
1007
1007
  "Continue task stream ended without final result"
1008
1008
  );
1009
- let U = (A = F.status) != null && A.message ? V(
1009
+ let O = (M = F.status) != null && M.message ? Q(
1010
1010
  F.status.message
1011
- ) : [], T = F;
1012
- if (U.length > 0)
1011
+ ) : [], E = F;
1012
+ if (O.length > 0)
1013
1013
  for (yield {
1014
1014
  ...F,
1015
1015
  final: !1,
1016
- text: L(
1017
- ((f = F.status) == null ? void 0 : f.message) || {
1016
+ text: J(
1017
+ ((g = F.status) == null ? void 0 : g.message) || {
1018
1018
  parts: [],
1019
1019
  messageId: q()
1020
1020
  }
1021
1021
  )
1022
- }; U.length > 0; ) {
1023
- (h = T.status) != null && h.message && r.push(
1024
- T.status.message
1022
+ }; O.length > 0; ) {
1023
+ (h = E.status) != null && h.message && r.push(
1024
+ E.status.message
1025
1025
  );
1026
1026
  const {
1027
- results: E,
1028
- shouldReturnToAgent: _
1029
- } = await Le(
1030
- U,
1027
+ results: R,
1028
+ shouldReturnToAgent: H
1029
+ } = await Je(
1030
+ O,
1031
1031
  s,
1032
- (S = (I = T.status) == null ? void 0 : I.message) == null ? void 0 : S.messageId
1032
+ (v = (I = E.status) == null ? void 0 : I.message) == null ? void 0 : v.messageId
1033
1033
  );
1034
- if (E.length > 0 && (yield {
1035
- id: T.id,
1034
+ if (R.length > 0 && (yield {
1035
+ id: E.id,
1036
1036
  status: {
1037
1037
  state: "working",
1038
1038
  message: {
1039
1039
  role: "agent",
1040
1040
  kind: "message",
1041
- parts: E,
1041
+ parts: R,
1042
1042
  messageId: q()
1043
1043
  }
1044
1044
  // Simple message with just the results
1045
1045
  },
1046
1046
  final: !1,
1047
1047
  text: ""
1048
- }), _) {
1049
- const j = o ? xe(
1048
+ }), H) {
1049
+ const N = o ? be(
1050
1050
  r
1051
- ) : [], W = re(
1052
- E,
1053
- j
1054
- ), H = await be(
1055
- T.id,
1056
- W,
1051
+ ) : [], L = ie(
1052
+ R,
1053
+ N
1054
+ ), B = await Re(
1055
+ E.id,
1056
+ L,
1057
1057
  a,
1058
1058
  s,
1059
1059
  t,
@@ -1062,21 +1062,21 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
1062
1062
  i,
1063
1063
  r
1064
1064
  );
1065
- let N = null;
1066
- for await (const $ of H)
1067
- $.final ? N = $ : yield $;
1068
- if (!N)
1065
+ let _ = null;
1066
+ for await (const $ of B)
1067
+ $.final ? _ = $ : yield $;
1068
+ if (!_)
1069
1069
  throw new Error(
1070
1070
  "Continue task stream ended without final result"
1071
1071
  );
1072
- T = N, U = (y = T.status) != null && y.message ? V(
1073
- T.status.message
1074
- ) : [], U.length > 0 && (yield {
1075
- id: T.id,
1076
- status: T.status,
1072
+ E = _, O = (y = E.status) != null && y.message ? Q(
1073
+ E.status.message
1074
+ ) : [], O.length > 0 && (yield {
1075
+ id: E.id,
1076
+ status: E.status,
1077
1077
  final: !1,
1078
- text: L(
1079
- ((C = T.status) == null ? void 0 : C.message) || {
1078
+ text: J(
1079
+ ((x = E.status) == null ? void 0 : x.message) || {
1080
1080
  parts: [],
1081
1081
  messageId: q()
1082
1082
  }
@@ -1086,31 +1086,31 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
1086
1086
  break;
1087
1087
  }
1088
1088
  yield {
1089
- ...T,
1089
+ ...E,
1090
1090
  final: !0,
1091
- text: L(
1092
- ((x = T.status) == null ? void 0 : x.message) || {
1091
+ text: J(
1092
+ ((b = E.status) == null ? void 0 : b.message) || {
1093
1093
  parts: [],
1094
1094
  messageId: q()
1095
1095
  }
1096
1096
  )
1097
1097
  };
1098
1098
  } else {
1099
- const b = {
1100
- ...m.status.message,
1101
- parts: R
1099
+ const C = {
1100
+ ...S.status.message,
1101
+ parts: U
1102
1102
  }, k = {
1103
- ...m,
1103
+ ...S,
1104
1104
  status: {
1105
- ...m.status,
1106
- message: b
1105
+ ...S.status,
1106
+ message: C
1107
1107
  },
1108
- final: M.length === 0,
1108
+ final: p.length === 0,
1109
1109
  // Only final if no agent messages to follow
1110
- text: L(b)
1110
+ text: J(C)
1111
1111
  };
1112
- if (yield k, M.length > 0) {
1113
- const P = M.map((U) => L(U)).join(" "), F = Y(P);
1112
+ if (yield k, p.length > 0) {
1113
+ const P = p.map((O) => J(O)).join(" "), F = Z(P);
1114
1114
  yield {
1115
1115
  id: k.id,
1116
1116
  status: {
@@ -1126,13 +1126,13 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
1126
1126
  }
1127
1127
  }
1128
1128
  }
1129
- function Mt(e) {
1129
+ function Tt(e) {
1130
1130
  const {
1131
1131
  agentId: s,
1132
1132
  agentUrl: t,
1133
1133
  authProvider: a,
1134
1134
  defaultSessionId: n,
1135
- timeout: o = ht,
1135
+ timeout: o = yt,
1136
1136
  toolProvider: r,
1137
1137
  contextProvider: l,
1138
1138
  enableStreaming: i = !1,
@@ -1145,121 +1145,121 @@ function Mt(e) {
1145
1145
  credentials: u
1146
1146
  };
1147
1147
  return {
1148
- async sendMessage(p) {
1149
- var C, x;
1150
- const { abortSignal: g } = p, A = p.sessionId || n || void 0, f = [];
1151
- f.push(p.message);
1152
- const h = await oe(
1153
- p,
1148
+ async sendMessage(m) {
1149
+ var x, b;
1150
+ const { abortSignal: f } = m, M = m.sessionId || n || void 0, g = [];
1151
+ g.push(m.message);
1152
+ const h = await le(
1153
+ m,
1154
1154
  c,
1155
1155
  { isStreaming: !1 },
1156
1156
  r,
1157
1157
  l,
1158
- A
1158
+ M
1159
1159
  );
1160
- let I = await De(
1160
+ let I = await je(
1161
1161
  h,
1162
1162
  c,
1163
- { abortSignal: g }
1163
+ { abortSignal: f }
1164
1164
  );
1165
- const S = [], y = [];
1165
+ const v = [], y = [];
1166
1166
  for (; I.status.message && r; ) {
1167
- const m = V(
1167
+ const S = Q(
1168
1168
  I.status.message
1169
1169
  );
1170
- if (m.length === 0)
1170
+ if (S.length === 0)
1171
1171
  break;
1172
- S.push(...m);
1173
- const d = [];
1174
- let w = !1;
1175
- for (const O of m) {
1172
+ v.push(...S);
1173
+ const T = [];
1174
+ let d = !1;
1175
+ for (const w of S) {
1176
1176
  const {
1177
- toolCallId: R,
1178
- toolId: M,
1179
- arguments: b
1180
- } = O.data;
1177
+ toolCallId: U,
1178
+ toolId: p,
1179
+ arguments: C
1180
+ } = w.data;
1181
1181
  try {
1182
- const k = await ie(
1182
+ const k = await ce(
1183
1183
  r,
1184
- M,
1185
- b
1186
- ), { result: P, returnToAgent: F, agentMessage: U } = Ie(k);
1187
- F && (w = !0), U && y.push(
1188
- Y(U)
1184
+ p,
1185
+ C
1186
+ ), { result: P, returnToAgent: F, agentMessage: O } = we(k);
1187
+ F && (d = !0), O && y.push(
1188
+ Z(O)
1189
1189
  );
1190
- const T = B(
1191
- R,
1192
- M,
1190
+ const E = z(
1191
+ U,
1192
+ p,
1193
1193
  P
1194
1194
  );
1195
- d.push(T), S.push(T);
1195
+ T.push(E), v.push(E);
1196
1196
  } catch (k) {
1197
- const P = B(
1198
- R,
1199
- M,
1197
+ const P = z(
1198
+ U,
1199
+ p,
1200
1200
  void 0,
1201
1201
  k instanceof Error ? k.message : String(k)
1202
1202
  );
1203
- d.push(P), S.push(P);
1203
+ T.push(P), v.push(P);
1204
1204
  }
1205
1205
  }
1206
- if (f.push(I.status.message), w) {
1207
- const O = re(d);
1208
- I = await de(
1206
+ if (g.push(I.status.message), d) {
1207
+ const w = ie(T);
1208
+ I = await ge(
1209
1209
  I.id,
1210
- O,
1210
+ w,
1211
1211
  c,
1212
1212
  r,
1213
1213
  l,
1214
- A,
1215
- g
1214
+ M,
1215
+ f
1216
1216
  );
1217
1217
  } else
1218
1218
  break;
1219
1219
  }
1220
- if (S.length > 0 && (C = I.status) != null && C.message) {
1221
- const m = {
1220
+ if (v.length > 0 && (x = I.status) != null && x.message) {
1221
+ const S = {
1222
1222
  ...I.status.message,
1223
- parts: S
1223
+ parts: v
1224
1224
  };
1225
1225
  I = {
1226
1226
  ...I,
1227
1227
  status: {
1228
1228
  ...I.status,
1229
- message: m
1229
+ message: S
1230
1230
  }
1231
1231
  };
1232
1232
  }
1233
1233
  if (y.length > 0) {
1234
- const m = y.map((w) => L(w)).join(" "), d = Y(m);
1234
+ const S = y.map((d) => J(d)).join(" "), T = Z(S);
1235
1235
  return {
1236
1236
  ...I,
1237
1237
  // Keep the enhanced message with tool results
1238
1238
  // The agent message will be handled separately by the caller
1239
- text: m,
1240
- agentMessage: d
1239
+ text: S,
1240
+ agentMessage: T
1241
1241
  // Add this for the caller to handle
1242
1242
  };
1243
1243
  }
1244
1244
  return {
1245
1245
  ...I,
1246
- text: L(
1247
- ((x = I.status) == null ? void 0 : x.message) || {
1246
+ text: J(
1247
+ ((b = I.status) == null ? void 0 : b.message) || {
1248
1248
  parts: [],
1249
1249
  messageId: q()
1250
1250
  }
1251
1251
  )
1252
1252
  };
1253
1253
  },
1254
- async *sendMessageStream(p) {
1254
+ async *sendMessageStream(m) {
1255
1255
  const {
1256
- withHistory: g = !0,
1257
- abortSignal: A,
1258
- enableStreaming: f
1259
- } = p, h = p.sessionId || n || void 0, I = f ?? i, S = [];
1260
- S.push(p.message);
1261
- const y = await oe(
1262
- p,
1256
+ withHistory: f = !0,
1257
+ abortSignal: M,
1258
+ enableStreaming: g
1259
+ } = m, h = m.sessionId || n || void 0, I = g ?? i, v = [];
1260
+ v.push(m.message);
1261
+ const y = await le(
1262
+ m,
1263
1263
  c,
1264
1264
  {
1265
1265
  isStreaming: !0,
@@ -1269,25 +1269,25 @@ function Mt(e) {
1269
1269
  r,
1270
1270
  l,
1271
1271
  h
1272
- ), C = je(
1272
+ ), x = Le(
1273
1273
  y,
1274
1274
  c,
1275
1275
  {
1276
1276
  enableTokenStreaming: I,
1277
1277
  // Token streaming is optional
1278
1278
  streamingTimeout: o,
1279
- abortSignal: A
1279
+ abortSignal: M
1280
1280
  }
1281
1281
  );
1282
- yield* Je(
1283
- C,
1282
+ yield* Ke(
1283
+ x,
1284
1284
  r,
1285
1285
  l,
1286
1286
  c,
1287
1287
  h,
1288
- g,
1289
- S,
1290
- A,
1288
+ f,
1289
+ v,
1290
+ M,
1291
1291
  {
1292
1292
  isStreaming: !0,
1293
1293
  enableTokenStreaming: I,
@@ -1295,41 +1295,41 @@ function Mt(e) {
1295
1295
  }
1296
1296
  );
1297
1297
  },
1298
- async continueTask(p, g, A) {
1299
- var S;
1300
- const f = me(g);
1301
- let I = await de(
1302
- p,
1303
- f,
1298
+ async continueTask(m, f, M) {
1299
+ var v;
1300
+ const g = pe(f);
1301
+ let I = await ge(
1302
+ m,
1303
+ g,
1304
1304
  c,
1305
1305
  r,
1306
1306
  l,
1307
- A
1307
+ M
1308
1308
  );
1309
1309
  for (; I.status.state === "input-required" && I.status.message && r; ) {
1310
- const y = V(
1310
+ const y = Q(
1311
1311
  I.status.message
1312
1312
  );
1313
1313
  if (y.length === 0)
1314
1314
  break;
1315
- const { results: C, shouldReturnToAgent: x } = await Le(y, r);
1316
- if (x) {
1317
- const m = re(C);
1318
- I = await de(
1315
+ const { results: x, shouldReturnToAgent: b } = await Je(y, r);
1316
+ if (b) {
1317
+ const S = ie(x);
1318
+ I = await ge(
1319
1319
  I.id,
1320
- m,
1320
+ S,
1321
1321
  c,
1322
1322
  r,
1323
1323
  l,
1324
- A
1324
+ M
1325
1325
  );
1326
1326
  } else
1327
1327
  break;
1328
1328
  }
1329
1329
  return {
1330
1330
  ...I,
1331
- text: L(
1332
- ((S = I.status) == null ? void 0 : S.message) || {
1331
+ text: J(
1332
+ ((v = I.status) == null ? void 0 : v.message) || {
1333
1333
  parts: [],
1334
1334
  messageId: q()
1335
1335
  }
@@ -1344,7 +1344,7 @@ function Mt(e) {
1344
1344
  }
1345
1345
  };
1346
1346
  }
1347
- function Tt(e) {
1347
+ function At(e) {
1348
1348
  const s = [], t = e.context, a = !!t && !Array.isArray(t) && !!t.flags && typeof t.flags == "object" && t.flags.context_only === !0;
1349
1349
  if (e.content) {
1350
1350
  const r = {
@@ -1396,7 +1396,7 @@ function Tt(e) {
1396
1396
  }
1397
1397
  };
1398
1398
  }
1399
- function At(e) {
1399
+ function vt(e) {
1400
1400
  if (e.role !== "tool_call" && e.role !== "tool_result")
1401
1401
  return !1;
1402
1402
  try {
@@ -1405,9 +1405,9 @@ function At(e) {
1405
1405
  return !1;
1406
1406
  }
1407
1407
  }
1408
- function vt(e, s = !1) {
1408
+ function St(e, s = !1) {
1409
1409
  var o, r, l, i, u, c;
1410
- const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!s || At(p)) : !0).map(Tt), n = {
1410
+ const a = e.messages.filter((m) => m.role === "tool_call" ? !1 : m.role === "tool_result" ? !(!s || vt(m)) : !0).map(At), n = {
1411
1411
  currentPage: ((o = e.metadata) == null ? void 0 : o.current_page) ?? 1,
1412
1412
  itemsPerPage: ((r = e.metadata) == null ? void 0 : r.items_per_page) ?? 10,
1413
1413
  totalPages: ((l = e.metadata) == null ? void 0 : l.total_pages) ?? 1,
@@ -1421,14 +1421,14 @@ function vt(e, s = !1) {
1421
1421
  sessionId: e.session_id
1422
1422
  };
1423
1423
  }
1424
- class Z extends Error {
1424
+ class ee extends Error {
1425
1425
  constructor(s, t, a) {
1426
1426
  super(s), this.statusCode = t, this.details = a, this.name = "ServerConversationError";
1427
1427
  }
1428
1428
  }
1429
- const Me = "https://public-api.wordpress.com";
1430
- async function pe(e, s, t = 1, a = 50, n = !1) {
1431
- const { botId: o, apiBaseUrl: r = Me, authProvider: l } = s;
1429
+ const Te = "https://public-api.wordpress.com";
1430
+ async function he(e, s, t = 1, a = 50, n = !1) {
1431
+ const { botId: o, apiBaseUrl: r = Te, authProvider: l } = s;
1432
1432
  if (!e || !o)
1433
1433
  throw new Error(
1434
1434
  "chatId and botId are required to load conversation from server"
@@ -1438,58 +1438,58 @@ async function pe(e, s, t = 1, a = 50, n = !1) {
1438
1438
  o
1439
1439
  )}/${encodeURIComponent(e)}`
1440
1440
  );
1441
- c.searchParams.set("page_number", i.toString()), c.searchParams.set("items_per_page", u.toString()), v(
1441
+ c.searchParams.set("page_number", i.toString()), c.searchParams.set("items_per_page", u.toString()), A(
1442
1442
  "Loading conversation from server: %s (page %d)",
1443
1443
  e,
1444
1444
  i
1445
1445
  );
1446
1446
  try {
1447
- const p = {
1447
+ const m = {
1448
1448
  "Content-Type": "application/json"
1449
1449
  };
1450
1450
  if (l) {
1451
1451
  const h = await l();
1452
- Object.assign(p, h);
1452
+ Object.assign(m, h);
1453
1453
  }
1454
- const g = await fetch(c.toString(), {
1454
+ const f = await fetch(c.toString(), {
1455
1455
  method: "GET",
1456
- headers: p
1456
+ headers: m
1457
1457
  });
1458
- if (!g.ok) {
1459
- const h = await g.text();
1460
- let I = `Failed to load conversation from server: ${g.status} ${g.statusText}`;
1458
+ if (!f.ok) {
1459
+ const h = await f.text();
1460
+ let I = `Failed to load conversation from server: ${f.status} ${f.statusText}`;
1461
1461
  try {
1462
1462
  const y = JSON.parse(h);
1463
1463
  y.message && (I = y.message);
1464
1464
  } catch {
1465
1465
  }
1466
- const S = new Z(
1466
+ const v = new ee(
1467
1467
  I,
1468
- g.status,
1468
+ f.status,
1469
1469
  h
1470
1470
  );
1471
- throw v("Failed to load conversation from server: %O", S), S;
1471
+ throw A("Failed to load conversation from server: %O", v), v;
1472
1472
  }
1473
- const A = await g.json(), f = vt(A, n);
1474
- return v(
1473
+ const M = await f.json(), g = St(M, n);
1474
+ return A(
1475
1475
  "Loaded %d messages from server (page %d/%d)",
1476
- f.messages.length,
1477
- f.pagination.currentPage,
1478
- f.pagination.totalPages
1479
- ), f;
1480
- } catch (p) {
1481
- if (p instanceof Z)
1482
- throw p;
1483
- const g = new Z(
1484
- `Network error loading conversation: ${p.message}`,
1476
+ g.messages.length,
1477
+ g.pagination.currentPage,
1478
+ g.pagination.totalPages
1479
+ ), g;
1480
+ } catch (m) {
1481
+ if (m instanceof ee)
1482
+ throw m;
1483
+ const f = new ee(
1484
+ `Network error loading conversation: ${m.message}`,
1485
1485
  void 0,
1486
- p
1486
+ m
1487
1487
  );
1488
- throw v("Network error loading conversation: %O", p), g;
1488
+ throw A("Network error loading conversation: %O", m), f;
1489
1489
  }
1490
1490
  }
1491
- async function cs(e, s, t = !1) {
1492
- const { apiBaseUrl: a = Me, authProvider: n } = s, o = new URL(
1491
+ async function us(e, s, t = !1) {
1492
+ const { apiBaseUrl: a = Te, authProvider: n } = s, o = new URL(
1493
1493
  `${a}/wpcom/v2/odie/conversations/${encodeURIComponent(
1494
1494
  e
1495
1495
  )}`
@@ -1497,7 +1497,7 @@ async function cs(e, s, t = !1) {
1497
1497
  o.searchParams.set(
1498
1498
  "truncation_method",
1499
1499
  t ? "first_message" : "last_message"
1500
- ), v("Listing conversations from server for bot: %s", e);
1500
+ ), A("Listing conversations from server for bot: %s", e);
1501
1501
  try {
1502
1502
  const r = {
1503
1503
  "Content-Type": "application/json"
@@ -1511,28 +1511,28 @@ async function cs(e, s, t = !1) {
1511
1511
  headers: r
1512
1512
  });
1513
1513
  if (!l.ok) {
1514
- const u = await l.text(), c = `Failed to list conversations: ${l.status} ${l.statusText}`, p = new Z(
1514
+ const u = await l.text(), c = `Failed to list conversations: ${l.status} ${l.statusText}`, m = new ee(
1515
1515
  c,
1516
1516
  l.status,
1517
1517
  u
1518
1518
  );
1519
- throw v("Failed to list conversations: %O", p), p;
1519
+ throw A("Failed to list conversations: %O", m), m;
1520
1520
  }
1521
1521
  const i = await l.json();
1522
- return v("Loaded %d conversations from server", i.length), i;
1522
+ return A("Loaded %d conversations from server", i.length), i;
1523
1523
  } catch (r) {
1524
- if (r instanceof Z)
1524
+ if (r instanceof ee)
1525
1525
  throw r;
1526
- const l = new Z(
1526
+ const l = new ee(
1527
1527
  `Network error listing conversations: ${r.message}`,
1528
1528
  void 0,
1529
1529
  r
1530
1530
  );
1531
- throw v("Network error listing conversations: %O", r), l;
1531
+ throw A("Network error listing conversations: %O", r), l;
1532
1532
  }
1533
1533
  }
1534
- async function us(e, s, t = 10, a = !1) {
1535
- const n = await pe(
1534
+ async function ds(e, s, t = 10, a = !1) {
1535
+ const n = await he(
1536
1536
  e,
1537
1537
  s,
1538
1538
  1,
@@ -1547,7 +1547,7 @@ async function us(e, s, t = 10, a = !1) {
1547
1547
  ), r = [...n.messages], l = [];
1548
1548
  for (let i = 2; i <= o; i++)
1549
1549
  l.push(
1550
- pe(e, s, i, 50, a)
1550
+ he(e, s, i, 50, a)
1551
1551
  );
1552
1552
  try {
1553
1553
  const i = await Promise.all(l);
@@ -1563,46 +1563,46 @@ async function us(e, s, t = 10, a = !1) {
1563
1563
  chatId: n.chatId
1564
1564
  };
1565
1565
  } catch (i) {
1566
- return v("Failed to load all pages: %O", i), {
1566
+ return A("Failed to load all pages: %O", i), {
1567
1567
  messages: r,
1568
1568
  pagination: n.pagination,
1569
1569
  chatId: n.chatId
1570
1570
  };
1571
1571
  }
1572
1572
  }
1573
- const Te = "a8c_agenttic_conversation_history";
1574
- function St(e) {
1575
- var g, A;
1573
+ const Ae = "a8c_agenttic_conversation_history";
1574
+ function Ct(e) {
1575
+ var f, M;
1576
1576
  const s = e.parts.filter(
1577
- (f) => f.type === "text"
1578
- ), t = s.map((f) => f.text).join(`
1577
+ (g) => g.type === "text"
1578
+ ), t = s.map((g) => g.text).join(`
1579
1579
  `), a = s.some(
1580
- (f) => {
1580
+ (g) => {
1581
1581
  var h;
1582
- return ((h = f.metadata) == null ? void 0 : h.contentType) === "context";
1582
+ return ((h = g.metadata) == null ? void 0 : h.contentType) === "context";
1583
1583
  }
1584
1584
  ) ? "context" : void 0, n = e.parts.filter(
1585
- (f) => f.type === "data" && "toolCallId" in f.data && "arguments" in f.data
1586
- ).map((f) => ({
1587
- toolCallId: f.data.toolCallId,
1588
- toolId: f.data.toolId,
1589
- arguments: f.data.arguments
1585
+ (g) => g.type === "data" && "toolCallId" in g.data && "arguments" in g.data
1586
+ ).map((g) => ({
1587
+ toolCallId: g.data.toolCallId,
1588
+ toolId: g.data.toolId,
1589
+ arguments: g.data.arguments
1590
1590
  })), o = e.parts.filter(
1591
- (f) => f.type === "data" && "toolCallId" in f.data && "result" in f.data
1592
- ).map((f) => ({
1593
- toolCallId: f.data.toolCallId,
1594
- result: f.data.result,
1595
- error: f.data.error
1596
- })), r = e.parts.filter((f) => f.type === "file").map((f) => ({
1597
- name: f.file.name,
1598
- mimeType: f.file.mimeType,
1599
- uri: f.file.uri
1591
+ (g) => g.type === "data" && "toolCallId" in g.data && "result" in g.data
1592
+ ).map((g) => ({
1593
+ toolCallId: g.data.toolCallId,
1594
+ result: g.data.result,
1595
+ error: g.data.error
1596
+ })), r = e.parts.filter((g) => g.type === "file").map((g) => ({
1597
+ name: g.file.name,
1598
+ mimeType: g.file.mimeType,
1599
+ uri: g.file.uri
1600
1600
  }));
1601
1601
  let l;
1602
- for (const f of e.parts) {
1603
- if (f.type !== "data" || !f.data || typeof f.data != "object" || "toolCallId" in f.data)
1602
+ for (const g of e.parts) {
1603
+ if (g.type !== "data" || !g.data || typeof g.data != "object" || "toolCallId" in g.data)
1604
1604
  continue;
1605
- const h = f.data, I = h.flags;
1605
+ const h = g.data, I = h.flags;
1606
1606
  if (I && typeof I == "object" && I !== null && "forward_to_human_support" in I) {
1607
1607
  l = {
1608
1608
  flags: I,
@@ -1611,12 +1611,12 @@ function St(e) {
1611
1611
  break;
1612
1612
  }
1613
1613
  }
1614
- const u = n.length > 0 || o.length > 0 ? "agent" : e.role, c = ((g = e.metadata) == null ? void 0 : g.timestamp) ?? Date.now(), p = ((A = e.metadata) == null ? void 0 : A.archived) ?? void 0;
1614
+ const u = n.length > 0 || o.length > 0 ? "agent" : e.role, c = ((f = e.metadata) == null ? void 0 : f.timestamp) ?? Date.now(), m = ((M = e.metadata) == null ? void 0 : M.archived) ?? void 0;
1615
1615
  return {
1616
1616
  role: u,
1617
1617
  content: t || "(No text content)",
1618
1618
  timestamp: c,
1619
- ...p !== void 0 && { archived: p },
1619
+ ...m !== void 0 && { archived: m },
1620
1620
  ...a && { contentType: a },
1621
1621
  ...r.length > 0 && { files: r },
1622
1622
  ...n.length > 0 && { toolCalls: n },
@@ -1624,7 +1624,7 @@ function St(e) {
1624
1624
  ...l && { agentMessageData: l }
1625
1625
  };
1626
1626
  }
1627
- function Ct(e) {
1627
+ function xt(e) {
1628
1628
  const s = [];
1629
1629
  if (e.content && e.content !== "(No text content)" && s.push({
1630
1630
  type: "text",
@@ -1682,45 +1682,45 @@ function Ct(e) {
1682
1682
  }
1683
1683
  };
1684
1684
  }
1685
- const Q = /* @__PURE__ */ new Map(), xt = 50;
1686
- async function bt(e, s, t) {
1685
+ const G = /* @__PURE__ */ new Map(), bt = 50;
1686
+ async function Rt(e, s, t) {
1687
1687
  const a = t || e;
1688
- if (Q.set(a, [...s]), Q.size > xt) {
1689
- const n = Q.keys().next().value;
1690
- n && Q.delete(n);
1688
+ if (G.set(a, [...s]), G.size > bt) {
1689
+ const n = G.keys().next().value;
1690
+ n && G.delete(n);
1691
1691
  }
1692
1692
  if (!(typeof sessionStorage > "u"))
1693
1693
  try {
1694
1694
  const n = {
1695
1695
  storageKey: a,
1696
- messages: s.map(St),
1696
+ messages: s.map(Ct),
1697
1697
  lastUpdated: Date.now()
1698
1698
  };
1699
1699
  sessionStorage.setItem(
1700
- `${Te}_${a}`,
1700
+ `${Ae}_${a}`,
1701
1701
  JSON.stringify(n)
1702
1702
  );
1703
1703
  } catch (n) {
1704
- v(
1704
+ A(
1705
1705
  "Failed to store conversation in sessionStorage for key %s: %O",
1706
1706
  a,
1707
1707
  n
1708
1708
  );
1709
1709
  }
1710
1710
  }
1711
- async function Rt(e, s, t) {
1712
- return t != null && t.odieBotId ? kt(e, t) : Pt(
1711
+ async function kt(e, s, t) {
1712
+ return t != null && t.odieBotId ? Pt(e, t) : _t(
1713
1713
  e,
1714
1714
  s
1715
1715
  );
1716
1716
  }
1717
- async function kt(e, s) {
1717
+ async function Pt(e, s) {
1718
1718
  const { odieBotId: t, authProvider: a } = s;
1719
1719
  if (!t)
1720
1720
  throw new Error("odieBotId is required for server storage");
1721
- const n = Me;
1721
+ const n = Te;
1722
1722
  try {
1723
- const r = await pe(
1723
+ const r = await he(
1724
1724
  e,
1725
1725
  {
1726
1726
  botId: t,
@@ -1730,7 +1730,7 @@ async function kt(e, s) {
1730
1730
  1,
1731
1731
  50
1732
1732
  );
1733
- return v(
1733
+ return A(
1734
1734
  "Loaded conversation from server: %s (%d messages, page %d/%d)",
1735
1735
  e,
1736
1736
  r.messages.length,
@@ -1741,27 +1741,27 @@ async function kt(e, s) {
1741
1741
  pagination: r.pagination
1742
1742
  };
1743
1743
  } catch (o) {
1744
- throw v("Failed to load conversation from server: %O", o), o;
1744
+ throw A("Failed to load conversation from server: %O", o), o;
1745
1745
  }
1746
1746
  }
1747
- async function Pt(e, s) {
1747
+ async function _t(e, s) {
1748
1748
  const t = s || e;
1749
- if (Q.has(t))
1749
+ if (G.has(t))
1750
1750
  return {
1751
- messages: [...Q.get(t)]
1751
+ messages: [...G.get(t)]
1752
1752
  };
1753
1753
  if (typeof sessionStorage > "u")
1754
1754
  return { messages: [] };
1755
1755
  try {
1756
1756
  const a = sessionStorage.getItem(
1757
- `${Te}_${t}`
1757
+ `${Ae}_${t}`
1758
1758
  );
1759
1759
  if (a) {
1760
- const o = JSON.parse(a).messages.map(Ct);
1761
- return Q.set(t, o), { messages: [...o] };
1760
+ const o = JSON.parse(a).messages.map(xt);
1761
+ return G.set(t, o), { messages: [...o] };
1762
1762
  }
1763
1763
  } catch (a) {
1764
- v(
1764
+ A(
1765
1765
  "Failed to load conversation from sessionStorage for key %s: %O",
1766
1766
  t,
1767
1767
  a
@@ -1769,20 +1769,20 @@ async function Pt(e, s) {
1769
1769
  }
1770
1770
  return { messages: [] };
1771
1771
  }
1772
- async function _t(e, s) {
1772
+ async function Et(e, s) {
1773
1773
  const t = s || e;
1774
- if (Q.delete(t), !(typeof sessionStorage > "u"))
1774
+ if (G.delete(t), !(typeof sessionStorage > "u"))
1775
1775
  try {
1776
- sessionStorage.removeItem(`${Te}_${t}`);
1776
+ sessionStorage.removeItem(`${Ae}_${t}`);
1777
1777
  } catch (a) {
1778
- v(
1778
+ A(
1779
1779
  "Failed to clear conversation from sessionStorage for key %s: %O",
1780
1780
  t,
1781
1781
  a
1782
1782
  );
1783
1783
  }
1784
1784
  }
1785
- function G(e) {
1785
+ function X(e) {
1786
1786
  const s = e.parts.filter((t) => t.type === "text" ? !0 : t.type === "data" ? "role" in t.data && "text" in t.data ? !1 : !!("toolCallId" in t.data && "arguments" in t.data || "flags" in t.data && t.data.flags && typeof t.data.flags == "object" && "forward_to_human_support" in t.data.flags || "sources" in t.data && Array.isArray(t.data.sources) && t.data.sources.length > 0 || "toolCallId" in t.data && "result" in t.data) : !0);
1787
1787
  return {
1788
1788
  ...e,
@@ -1793,7 +1793,7 @@ function G(e) {
1793
1793
  }
1794
1794
  };
1795
1795
  }
1796
- function Ke(e) {
1796
+ function Be(e) {
1797
1797
  const s = [];
1798
1798
  for (const t of e)
1799
1799
  for (const a of t.parts)
@@ -1821,8 +1821,8 @@ function Ke(e) {
1821
1821
  }
1822
1822
  return s;
1823
1823
  }
1824
- function Re(e, s = [], t = []) {
1825
- const a = Ke(s), n = t.map((o) => {
1824
+ function ke(e, s = [], t = []) {
1825
+ const a = Be(s), n = t.map((o) => {
1826
1826
  const r = typeof o == "string" ? o : o.url, l = typeof o == "object" ? o.metadata : void 0, i = (l == null ? void 0 : l.fileType) || "image/jpeg";
1827
1827
  return {
1828
1828
  type: "file",
@@ -1851,12 +1851,12 @@ function Re(e, s = [], t = []) {
1851
1851
  }
1852
1852
  };
1853
1853
  }
1854
- function Et(e) {
1854
+ function Nt(e) {
1855
1855
  return e != null && e.parts ? e.parts.filter(
1856
1856
  (s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
1857
1857
  ) : [];
1858
1858
  }
1859
- function Nt(e) {
1859
+ function Ut(e) {
1860
1860
  var t, a;
1861
1861
  const s = (a = (t = e == null ? void 0 : e.parts) == null ? void 0 : t.find(
1862
1862
  (n) => n.type === "text"
@@ -1870,16 +1870,16 @@ function Nt(e) {
1870
1870
  return !1;
1871
1871
  }
1872
1872
  }
1873
- function ge(e, s) {
1873
+ function fe(e, s) {
1874
1874
  if (typeof localStorage > "u") {
1875
- z("localStorage not available, cannot update session ID");
1875
+ V("localStorage not available, cannot update session ID");
1876
1876
  return;
1877
1877
  }
1878
1878
  try {
1879
1879
  const t = localStorage.getItem(e);
1880
1880
  if (t) {
1881
1881
  const a = JSON.parse(t), n = a.sessionId;
1882
- a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)), z(
1882
+ a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)), V(
1883
1883
  "Updated localStorage[%s] session ID: %s -> %s",
1884
1884
  e,
1885
1885
  n,
@@ -1890,14 +1890,14 @@ function ge(e, s) {
1890
1890
  sessionId: s,
1891
1891
  timestamp: Date.now()
1892
1892
  };
1893
- localStorage.setItem(e, JSON.stringify(a)), z(
1893
+ localStorage.setItem(e, JSON.stringify(a)), V(
1894
1894
  "Created new session in localStorage[%s]: %s",
1895
1895
  e,
1896
1896
  s
1897
1897
  );
1898
1898
  }
1899
1899
  } catch (t) {
1900
- z(
1900
+ V(
1901
1901
  "Failed to update localStorage sessionId to %s: %O",
1902
1902
  s,
1903
1903
  t
@@ -1911,7 +1911,7 @@ async function Ht(e) {
1911
1911
  if (t.parts.some(
1912
1912
  (n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
1913
1913
  )) {
1914
- const n = wt(
1914
+ const n = Mt(
1915
1915
  t.parts
1916
1916
  );
1917
1917
  s.push({
@@ -1922,7 +1922,7 @@ async function Ht(e) {
1922
1922
  s.push(t);
1923
1923
  else
1924
1924
  s.push(t);
1925
- return It(), s;
1925
+ return wt(), s;
1926
1926
  }
1927
1927
  function Ot() {
1928
1928
  const e = /* @__PURE__ */ new Map();
@@ -1930,13 +1930,13 @@ function Ot() {
1930
1930
  const n = e.get(t);
1931
1931
  if (n != null && n.sessionId)
1932
1932
  try {
1933
- await bt(
1933
+ await Rt(
1934
1934
  n.sessionId,
1935
1935
  a,
1936
1936
  n.conversationStorageKey
1937
1937
  );
1938
1938
  } catch (o) {
1939
- z(
1939
+ V(
1940
1940
  `Failed to persist conversation history for agent ${t}:`,
1941
1941
  o
1942
1942
  );
@@ -1946,22 +1946,22 @@ function Ot() {
1946
1946
  async createAgent(t, a) {
1947
1947
  if (e.has(t))
1948
1948
  return e.get(t).client;
1949
- const n = Mt(a), o = a.sessionId || null, r = a.conversationStorageKey, l = a.sessionIdStorageKey, i = {
1949
+ const n = Tt(a), o = a.sessionId || null, r = a.conversationStorageKey, l = a.sessionIdStorageKey, i = {
1950
1950
  odieBotId: a.odieBotId,
1951
1951
  authProvider: a.authProvider
1952
1952
  };
1953
1953
  let u = [];
1954
1954
  if (o)
1955
1955
  try {
1956
- u = (await Rt(
1956
+ u = (await kt(
1957
1957
  o,
1958
1958
  r,
1959
1959
  i
1960
1960
  )).messages;
1961
- } catch (p) {
1962
- z(
1961
+ } catch (m) {
1962
+ V(
1963
1963
  `Failed to load conversation history for agent ${t} with session ${o}:`,
1964
- p
1964
+ m
1965
1965
  );
1966
1966
  }
1967
1967
  const c = {
@@ -1990,68 +1990,68 @@ function Ot() {
1990
1990
  const o = e.get(t);
1991
1991
  if (!o)
1992
1992
  throw new Error(`Agent with key "${t}" not found`);
1993
- const { withHistory: r = !0, sessionId: l, ...i } = n, { client: u, conversationHistory: c } = o, p = n.message || Re(
1993
+ const { withHistory: r = !0, sessionId: l, ...i } = n, { client: u, conversationHistory: c } = o, m = n.message || ke(
1994
1994
  a,
1995
1995
  c,
1996
1996
  n.imageUrls
1997
- ), g = await u.sendMessage({
1998
- message: p,
1997
+ ), f = await u.sendMessage({
1998
+ message: m,
1999
1999
  withHistory: r,
2000
2000
  sessionId: l || o.sessionId || void 0,
2001
2001
  ...i
2002
2002
  });
2003
- if (g.sessionId) {
2004
- const S = o.sessionId;
2005
- o.sessionId = g.sessionId, S && g.sessionId && S !== g.sessionId && o.sessionIdStorageKey && (z(
2003
+ if (f.sessionId) {
2004
+ const v = o.sessionId;
2005
+ o.sessionId = f.sessionId, v && f.sessionId && v !== f.sessionId && o.sessionIdStorageKey && (V(
2006
2006
  "Session ID changed from %s to %s, updating localStorage",
2007
- S,
2008
- g.sessionId
2009
- ), ge(
2007
+ v,
2008
+ f.sessionId
2009
+ ), fe(
2010
2010
  o.sessionIdStorageKey,
2011
- g.sessionId
2011
+ f.sessionId
2012
2012
  ));
2013
2013
  }
2014
- let A = null;
2015
- if ((I = g.status) != null && I.message) {
2016
- const S = g.status.message.parts.filter(
2017
- (C) => C.type === "data" && "toolCallId" in C.data && ("arguments" in C.data || "result" in C.data)
2018
- ), y = g.status.message.parts.filter(
2019
- (C) => C.type === "text"
2014
+ let M = null;
2015
+ if ((I = f.status) != null && I.message) {
2016
+ const v = f.status.message.parts.filter(
2017
+ (x) => x.type === "data" && "toolCallId" in x.data && ("arguments" in x.data || "result" in x.data)
2018
+ ), y = f.status.message.parts.filter(
2019
+ (x) => x.type === "text"
2020
2020
  );
2021
- A = {
2021
+ M = {
2022
2022
  role: "agent",
2023
2023
  kind: "message",
2024
- parts: [...S, ...y],
2024
+ parts: [...v, ...y],
2025
2025
  messageId: q(),
2026
2026
  metadata: {
2027
2027
  timestamp: Date.now()
2028
2028
  }
2029
2029
  };
2030
2030
  }
2031
- const f = [
2031
+ const g = [
2032
2032
  ...c,
2033
2033
  // Store only the new content from the user message (without history parts)
2034
- me(a),
2034
+ pe(a),
2035
2035
  // Add complete agent response with tool calls/results if present
2036
- ...A ? [G(A)] : []
2036
+ ...M ? [X(M)] : []
2037
2037
  ];
2038
- let h = f;
2039
- if (g.agentMessage) {
2040
- const S = G(
2041
- g.agentMessage
2038
+ let h = g;
2039
+ if (f.agentMessage) {
2040
+ const v = X(
2041
+ f.agentMessage
2042
2042
  );
2043
2043
  h = [
2044
- ...f,
2045
- S
2044
+ ...g,
2045
+ v
2046
2046
  ];
2047
2047
  }
2048
2048
  return o.conversationHistory = h, r && await s(
2049
2049
  t,
2050
2050
  h
2051
- ), g;
2051
+ ), f;
2052
2052
  },
2053
2053
  async *sendMessageStream(t, a, n = {}) {
2054
- var x, m, d, w, O, R;
2054
+ var b, S, T, d, w, U;
2055
2055
  const o = e.get(t);
2056
2056
  if (!o)
2057
2057
  throw new Error(`Agent with key "${t}" not found`);
@@ -2061,56 +2061,56 @@ function Ot() {
2061
2061
  metadata: i,
2062
2062
  sessionId: u,
2063
2063
  message: c,
2064
- ...p
2065
- } = n, { client: g } = o, A = i ? (({ contentType: M, ...b }) => b)(i) : void 0, f = new AbortController();
2066
- o.currentAbortController = f, l && l.addEventListener(
2064
+ ...m
2065
+ } = n, { client: f } = o, M = i ? (({ contentType: p, ...C }) => C)(i) : void 0, g = new AbortController();
2066
+ o.currentAbortController = g, l && l.addEventListener(
2067
2067
  "abort",
2068
- () => f.abort()
2068
+ () => g.abort()
2069
2069
  );
2070
2070
  let h = [
2071
2071
  ...o.conversationHistory
2072
2072
  ], I = [];
2073
- const S = await Ht(
2073
+ const v = await Ht(
2074
2074
  h
2075
2075
  );
2076
- o.conversationHistory = S, h = S, r && await s(
2076
+ o.conversationHistory = v, h = v, r && await s(
2077
2077
  t,
2078
- S
2078
+ v
2079
2079
  );
2080
2080
  let y;
2081
2081
  if (c) {
2082
- const M = Ke(
2083
- S
2082
+ const p = Be(
2083
+ v
2084
2084
  );
2085
2085
  y = {
2086
2086
  ...c,
2087
- parts: [...M, ...c.parts]
2087
+ parts: [...p, ...c.parts]
2088
2088
  };
2089
2089
  } else
2090
- y = Re(
2090
+ y = ke(
2091
2091
  a,
2092
- S,
2092
+ v,
2093
2093
  n.imageUrls
2094
2094
  );
2095
2095
  if (n.metadata && !c) {
2096
- const { contentType: M, ...b } = n.metadata;
2097
- if (M) {
2096
+ const { contentType: p, ...C } = n.metadata;
2097
+ if (p) {
2098
2098
  const k = y.parts[y.parts.length - 1];
2099
2099
  k && k.type === "text" && (k.metadata = {
2100
2100
  ...k.metadata,
2101
- contentType: M
2101
+ contentType: p
2102
2102
  });
2103
2103
  }
2104
- Object.keys(b).length > 0 && (y.metadata = {
2104
+ Object.keys(C).length > 0 && (y.metadata = {
2105
2105
  ...y.metadata,
2106
- ...b
2106
+ ...C
2107
2107
  });
2108
2108
  }
2109
- const C = c || me(a, n.metadata);
2109
+ const x = c || pe(a, n.metadata);
2110
2110
  if (n.imageUrls && n.imageUrls.length > 0) {
2111
- const M = n.imageUrls.map(
2112
- (b) => {
2113
- const k = typeof b == "string" ? b : b.url, P = typeof b == "string" ? void 0 : b.metadata, F = (P == null ? void 0 : P.fileType) || "image/jpeg";
2111
+ const p = n.imageUrls.map(
2112
+ (C) => {
2113
+ const k = typeof C == "string" ? C : C.url, P = typeof C == "string" ? void 0 : C.metadata, F = (P == null ? void 0 : P.fileType) || "image/jpeg";
2114
2114
  return {
2115
2115
  type: "file",
2116
2116
  file: {
@@ -2122,43 +2122,43 @@ function Ot() {
2122
2122
  };
2123
2123
  }
2124
2124
  );
2125
- C.parts.push(...M);
2125
+ x.parts.push(...p);
2126
2126
  }
2127
2127
  h = [
2128
2128
  ...h,
2129
- C
2129
+ x
2130
2130
  ], o.conversationHistory = h, r && await s(
2131
2131
  t,
2132
2132
  h
2133
2133
  );
2134
- for await (const M of g.sendMessageStream({
2134
+ for await (const p of f.sendMessageStream({
2135
2135
  message: y,
2136
2136
  withHistory: r,
2137
2137
  sessionId: u || o.sessionId || void 0,
2138
- abortSignal: f.signal,
2139
- ...p,
2140
- ...A && Object.keys(A).length > 0 && {
2141
- metadata: A
2138
+ abortSignal: g.signal,
2139
+ ...m,
2140
+ ...M && Object.keys(M).length > 0 && {
2141
+ metadata: M
2142
2142
  }
2143
2143
  })) {
2144
- if (M.sessionId) {
2145
- const b = o.sessionId;
2146
- o.sessionId = M.sessionId, M.sessionId && b !== M.sessionId && o.sessionIdStorageKey && (z(
2144
+ if (p.sessionId) {
2145
+ const C = o.sessionId;
2146
+ o.sessionId = p.sessionId, p.sessionId && C !== p.sessionId && o.sessionIdStorageKey && (V(
2147
2147
  "Session ID %s, updating localStorage",
2148
- b ? `changed from ${b} to ${M.sessionId}` : `received: ${M.sessionId}`
2149
- ), ge(
2148
+ C ? `changed from ${C} to ${p.sessionId}` : `received: ${p.sessionId}`
2149
+ ), fe(
2150
2150
  o.sessionIdStorageKey,
2151
- M.sessionId
2151
+ p.sessionId
2152
2152
  ));
2153
2153
  }
2154
- if (((x = M.status) == null ? void 0 : x.state) === "input-required" && ((m = M.status) != null && m.message)) {
2155
- I = V(
2156
- M.status.message
2154
+ if (((b = p.status) == null ? void 0 : b.state) === "input-required" && ((S = p.status) != null && S.message)) {
2155
+ I = Q(
2156
+ p.status.message
2157
2157
  ).map(
2158
2158
  (P) => P.data.toolCallId
2159
2159
  );
2160
- const k = G(
2161
- M.status.message
2160
+ const k = X(
2161
+ p.status.message
2162
2162
  );
2163
2163
  h = [
2164
2164
  ...h,
@@ -2168,9 +2168,9 @@ function Ot() {
2168
2168
  h
2169
2169
  );
2170
2170
  }
2171
- if (((d = M.status) == null ? void 0 : d.state) === "working" && ((w = M.status) != null && w.message) && !M.final) {
2172
- const k = Et(
2173
- M.status.message
2171
+ if (((T = p.status) == null ? void 0 : T.state) === "working" && ((d = p.status) != null && d.message) && !p.final) {
2172
+ const k = Nt(
2173
+ p.status.message
2174
2174
  ).filter(
2175
2175
  (P) => I.includes(
2176
2176
  P.data.toolCallId
@@ -2185,35 +2185,35 @@ function Ot() {
2185
2185
  };
2186
2186
  h = [
2187
2187
  ...h,
2188
- G(P)
2188
+ X(P)
2189
2189
  ], o.conversationHistory = h, r && await s(
2190
2190
  t,
2191
2191
  h
2192
2192
  );
2193
- } else Nt(M.status.message) && (h = [
2193
+ } else Ut(p.status.message) && (h = [
2194
2194
  ...h,
2195
- G(
2196
- M.status.message
2195
+ X(
2196
+ p.status.message
2197
2197
  )
2198
2198
  ], o.conversationHistory = h, r && await s(
2199
2199
  t,
2200
2200
  h
2201
2201
  ));
2202
2202
  }
2203
- if (M.final && ((O = M.status) == null ? void 0 : O.state) !== "input-required") {
2203
+ if (p.final && ((w = p.status) == null ? void 0 : w.state) !== "input-required") {
2204
2204
  I = [];
2205
- let b = null;
2206
- (R = M.status) != null && R.message && (b = G(
2207
- M.status.message
2205
+ let C = null;
2206
+ (U = p.status) != null && U.message && (C = X(
2207
+ p.status.message
2208
2208
  ), h = [
2209
2209
  ...h,
2210
- b
2210
+ C
2211
2211
  ], o.conversationHistory = h, r && await s(
2212
2212
  t,
2213
2213
  h
2214
2214
  ));
2215
2215
  }
2216
- yield M;
2216
+ yield p;
2217
2217
  }
2218
2218
  o.currentAbortController = null;
2219
2219
  },
@@ -2248,7 +2248,7 @@ function Ot() {
2248
2248
  role: "user",
2249
2249
  kind: "message",
2250
2250
  parts: [
2251
- B(a, n, o)
2251
+ z(a, n, o)
2252
2252
  ],
2253
2253
  messageId: q()
2254
2254
  }
@@ -2258,7 +2258,7 @@ function Ot() {
2258
2258
  const a = e.get(t);
2259
2259
  if (!a)
2260
2260
  throw new Error(`Agent with key "${t}" not found`);
2261
- a.conversationHistory = [], a.sessionId && await _t(
2261
+ a.conversationHistory = [], a.sessionId && await Et(
2262
2262
  a.sessionId,
2263
2263
  a.conversationStorageKey
2264
2264
  );
@@ -2279,7 +2279,7 @@ function Ot() {
2279
2279
  const n = e.get(t);
2280
2280
  if (!n)
2281
2281
  throw new Error(`Agent with key "${t}" not found`);
2282
- n.sessionId = a, n.sessionIdStorageKey && ge(
2282
+ n.sessionId = a, n.sessionIdStorageKey && fe(
2283
2283
  n.sessionIdStorageKey,
2284
2284
  a
2285
2285
  );
@@ -2295,12 +2295,12 @@ function Ot() {
2295
2295
  }
2296
2296
  };
2297
2297
  }
2298
- const Ut = Ot();
2299
- function X() {
2300
- return Ut;
2298
+ const $t = Ot();
2299
+ function Y() {
2300
+ return $t;
2301
2301
  }
2302
- function $t() {
2303
- const [e, s] = Ee([]), t = D(
2302
+ function qt() {
2303
+ const [e, s] = Ne([]), t = j(
2304
2304
  (o) => {
2305
2305
  s((r) => {
2306
2306
  const l = r.findIndex(
@@ -2314,9 +2314,9 @@ function $t() {
2314
2314
  });
2315
2315
  },
2316
2316
  []
2317
- ), a = D((o) => {
2317
+ ), a = j((o) => {
2318
2318
  s((r) => r.filter((l) => l.id !== o));
2319
- }, []), n = D(() => {
2319
+ }, []), n = j(() => {
2320
2320
  s([]);
2321
2321
  }, []);
2322
2322
  return {
@@ -2326,7 +2326,7 @@ function $t() {
2326
2326
  registrations: e
2327
2327
  };
2328
2328
  }
2329
- function qt(e, s) {
2329
+ function Ft(e, s) {
2330
2330
  return s.flatMap((n) => typeof n.actions == "function" ? n.actions(e) : n.actions).filter((n) => !(n.condition && !n.condition(e))).map((n) => n.type === "component" ? {
2331
2331
  type: "component",
2332
2332
  id: n.id,
@@ -2346,7 +2346,7 @@ function qt(e, s) {
2346
2346
  order: n.order
2347
2347
  }).sort((n, o) => (n.order ?? 1 / 0) - (o.order ?? 1 / 0));
2348
2348
  }
2349
- const Ft = (e) => e.type === "text" ? {
2349
+ const Dt = (e) => e.type === "text" ? {
2350
2350
  ...e,
2351
2351
  metadata: e.metadata ? { ...e.metadata } : void 0
2352
2352
  } : e.type === "file" ? {
@@ -2357,21 +2357,21 @@ const Ft = (e) => e.type === "text" ? {
2357
2357
  ...e,
2358
2358
  data: { ...e.data },
2359
2359
  metadata: e.metadata ? { ...e.metadata } : void 0
2360
- }, Dt = (e) => e.parts.filter(
2360
+ }, jt = (e) => e.parts.filter(
2361
2361
  (s) => {
2362
2362
  var t;
2363
2363
  return s.type === "text" && ((t = s.metadata) == null ? void 0 : t.contentType) !== "context";
2364
2364
  }
2365
2365
  ).map((s) => s.text).join(`
2366
- `).trim(), jt = (e) => ({
2366
+ `).trim(), Lt = (e) => ({
2367
2367
  ...e,
2368
2368
  messageId: q(),
2369
2369
  metadata: {
2370
2370
  ...e.metadata || {},
2371
2371
  timestamp: Date.now()
2372
2372
  },
2373
- parts: e.parts.map(Ft)
2374
- }), Be = (e, s) => {
2373
+ parts: e.parts.map(Dt)
2374
+ }), We = (e, s) => {
2375
2375
  const t = e.findIndex(
2376
2376
  (r) => r.messageId === s && r.role === "agent"
2377
2377
  );
@@ -2385,27 +2385,27 @@ const Ft = (e) => e.type === "text" ? {
2385
2385
  }
2386
2386
  if (a === -1)
2387
2387
  return null;
2388
- const n = e[a], o = Dt(n);
2388
+ const n = e[a], o = jt(n);
2389
2389
  return o ? {
2390
2390
  baseHistory: e.slice(0, a),
2391
2391
  userMessage: n,
2392
2392
  prompt: o
2393
2393
  } : null;
2394
- }, Lt = (e, s) => {
2395
- const t = Be(e, s);
2394
+ }, Jt = (e, s) => {
2395
+ const t = We(e, s);
2396
2396
  return t ? {
2397
2397
  ...t,
2398
- userMessage: jt(t.userMessage)
2398
+ userMessage: Lt(t.userMessage)
2399
2399
  } : null;
2400
- }, We = (e, s) => !!Be(e, s), ke = (e) => {
2400
+ }, ze = (e, s) => !!We(e, s), Pe = (e) => {
2401
2401
  for (let s = e.length - 1; s >= 0; s--) {
2402
2402
  const t = e[s];
2403
- if (t.role === "agent" && We(e, t.messageId))
2403
+ if (t.role === "agent" && ze(e, t.messageId))
2404
2404
  return t.messageId;
2405
2405
  }
2406
2406
  return null;
2407
2407
  };
2408
- function Jt({
2408
+ function Kt({
2409
2409
  agentId: e,
2410
2410
  isValidConfig: s,
2411
2411
  isSendingRef: t,
@@ -2413,39 +2413,39 @@ function Jt({
2413
2413
  transformMessages: n,
2414
2414
  sendMessage: o
2415
2415
  }) {
2416
- const r = D(
2416
+ const r = j(
2417
2417
  async (i) => {
2418
2418
  if (!s || t.current)
2419
2419
  return;
2420
- const c = X().getConversationHistory(e), p = (i == null ? void 0 : i.id) ?? ke(c);
2421
- if (!p)
2420
+ const c = Y().getConversationHistory(e), m = (i == null ? void 0 : i.id) ?? Pe(c);
2421
+ if (!m)
2422
2422
  return;
2423
- const g = Lt(
2423
+ const f = Jt(
2424
2424
  c,
2425
- p
2425
+ m
2426
2426
  );
2427
- if (!g)
2427
+ if (!f)
2428
2428
  return;
2429
- const A = {
2429
+ const M = {
2430
2430
  clientMessages: c,
2431
2431
  uiMessages: a.current.uiMessages
2432
- }, f = n(
2433
- g.baseHistory
2432
+ }, g = n(
2433
+ f.baseHistory
2434
2434
  );
2435
2435
  try {
2436
- await o(g.prompt, void 0, {
2436
+ await o(f.prompt, void 0, {
2437
2437
  initialClientMessages: [
2438
- ...g.baseHistory,
2439
- g.userMessage
2438
+ ...f.baseHistory,
2439
+ f.userMessage
2440
2440
  ],
2441
- initialUiMessages: f,
2442
- messageOverride: g.userMessage,
2441
+ initialUiMessages: g,
2442
+ messageOverride: f.userMessage,
2443
2443
  preserveUiOnlyMessages: !1,
2444
- truncateHistoryTo: g.baseHistory,
2445
- restoreOnError: A
2444
+ truncateHistoryTo: f.baseHistory,
2445
+ restoreOnError: M
2446
2446
  });
2447
2447
  } catch (h) {
2448
- v("Regenerate failed; conversation restored", h);
2448
+ A("Regenerate failed; conversation restored", h);
2449
2449
  }
2450
2450
  },
2451
2451
  [
@@ -2457,22 +2457,22 @@ function Jt({
2457
2457
  n
2458
2458
  ]
2459
2459
  );
2460
- return { getRegenerateHandler: D(
2460
+ return { getRegenerateHandler: j(
2461
2461
  (i) => {
2462
- const u = a.current, c = X(), p = c.hasAgent(e) ? c.getConversationHistory(e) : u.clientMessages, g = (i == null ? void 0 : i.id) ?? ke(p);
2463
- return !s || i && i.role !== "agent" || !g || !We(
2464
- p,
2465
- g
2462
+ const u = a.current, c = Y(), m = c.hasAgent(e) ? c.getConversationHistory(e) : u.clientMessages, f = (i == null ? void 0 : i.id) ?? Pe(m);
2463
+ return !s || i && i.role !== "agent" || !f || !ze(
2464
+ m,
2465
+ f
2466
2466
  ) ? null : () => r(i);
2467
2467
  },
2468
2468
  [e, r, s, a]
2469
2469
  ) };
2470
2470
  }
2471
- const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s) => e.filter(
2471
+ const me = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Bt = (e, s) => e.filter(
2472
2472
  (t) => !s.has(t.id) && t.role !== "user"
2473
- ), ze = (e, s = "40%") => ({
2473
+ ), Ve = (e, s = "40%") => ({
2474
2474
  type: "component",
2475
- component: () => Xe.createElement("img", {
2475
+ component: () => Ye.createElement("img", {
2476
2476
  src: e,
2477
2477
  alt: "Uploaded image",
2478
2478
  style: {
@@ -2484,7 +2484,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
2484
2484
  display: "inline-block"
2485
2485
  }
2486
2486
  })
2487
- }), ne = (e, s = []) => {
2487
+ }), oe = (e, s = []) => {
2488
2488
  var r, l;
2489
2489
  if (e.parts.some((i) => {
2490
2490
  if (i.type === "data") {
@@ -2504,7 +2504,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
2504
2504
  if (i.type === "file") {
2505
2505
  const c = i.file.uri || (i.file.mimeType && i.file.bytes ? `data:${i.file.mimeType};base64,${i.file.bytes}` : void 0);
2506
2506
  if (c)
2507
- return ze(c);
2507
+ return Ve(c);
2508
2508
  }
2509
2509
  if (i.type === "data") {
2510
2510
  const c = i.data;
@@ -2518,7 +2518,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
2518
2518
  } : Array.isArray(c.sources) && c.sources.length > 0 ? {
2519
2519
  type: "data",
2520
2520
  data: c
2521
- } : (v("Dropping unrecognized data part", c), null);
2521
+ } : (A("Dropping unrecognized data part", c), null);
2522
2522
  }
2523
2523
  return {
2524
2524
  type: "text",
@@ -2539,32 +2539,32 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
2539
2539
  icon: e.role === "agent" ? "assistant" : void 0
2540
2540
  };
2541
2541
  if (e.role === "agent" && s.length > 0) {
2542
- const i = qt(
2542
+ const i = Ft(
2543
2543
  o,
2544
2544
  s
2545
2545
  );
2546
2546
  i.length > 0 && (o.actions = i);
2547
2547
  }
2548
2548
  return o;
2549
- }, Bt = () => ({
2549
+ }, Wt = () => ({
2550
2550
  getClientContext: () => ({})
2551
- }), Wt = () => ({
2551
+ }), zt = () => ({
2552
2552
  getAvailableTools: async () => [],
2553
2553
  executeTool: async () => ({
2554
2554
  success: !0,
2555
2555
  result: "No tools available"
2556
2556
  })
2557
- }), zt = (e) => ["agentId", "agentUrl"].every((t) => {
2557
+ }), Vt = (e) => ["agentId", "agentUrl"].every((t) => {
2558
2558
  const a = e[t];
2559
2559
  return typeof a == "string" && a.trim().length > 0;
2560
2560
  });
2561
- function ds(e) {
2561
+ function gs(e) {
2562
2562
  const s = {
2563
2563
  agentId: e.agentId,
2564
2564
  agentUrl: e.agentUrl,
2565
2565
  sessionId: e.sessionId,
2566
2566
  sessionIdStorageKey: e.sessionIdStorageKey
2567
- }, t = zt(s), [a, n] = Ee({
2567
+ }, t = Vt(s), [a, n] = Ne({
2568
2568
  clientMessages: [],
2569
2569
  uiMessages: [],
2570
2570
  isProcessing: !1,
@@ -2577,33 +2577,37 @@ function ds(e) {
2577
2577
  unregisterMessageActions: r,
2578
2578
  clearAllMessageActions: l,
2579
2579
  registrations: i
2580
- } = $t(), u = ue(!1), c = ue(a);
2581
- ae(() => {
2580
+ } = qt(), u = re(!1), c = re(a);
2581
+ te(() => {
2582
2582
  c.current = a;
2583
2583
  }, [a]);
2584
- const p = ue(i);
2585
- ae(() => {
2586
- p.current = i;
2584
+ const m = re(e.onTaskUpdate);
2585
+ te(() => {
2586
+ m.current = e.onTaskUpdate;
2587
+ }, [e.onTaskUpdate]);
2588
+ const f = re(i);
2589
+ te(() => {
2590
+ f.current = i;
2587
2591
  }, [i]);
2588
- const g = D(
2589
- (m) => m.map(
2590
- (d) => ne(d, p.current)
2592
+ const M = j(
2593
+ (T) => T.map(
2594
+ (d) => oe(d, f.current)
2591
2595
  ).filter((d) => d !== null),
2592
2596
  []
2593
2597
  // registrationsRef is stable, so no deps needed
2594
2598
  );
2595
- ae(() => {
2599
+ te(() => {
2596
2600
  if (!t)
2597
2601
  return;
2598
2602
  (async () => {
2599
- const d = X(), w = s.agentId;
2603
+ const d = Y(), w = s.agentId;
2600
2604
  if (d.hasAgent(w))
2601
- s.sessionId ? (d.updateSessionId(w, s.sessionId), d.getConversationHistory(w).length === 0 && n((M) => ({
2602
- ...M,
2605
+ s.sessionId ? (d.updateSessionId(w, s.sessionId), d.getConversationHistory(w).length === 0 && n((C) => ({
2606
+ ...C,
2603
2607
  clientMessages: [],
2604
2608
  uiMessages: []
2605
- }))) : (d.updateSessionId(w, ""), await d.replaceMessages(w, []), n((R) => ({
2606
- ...R,
2609
+ }))) : (d.updateSessionId(w, ""), await d.replaceMessages(w, []), n((p) => ({
2610
+ ...p,
2607
2611
  clientMessages: [],
2608
2612
  uiMessages: []
2609
2613
  })));
@@ -2613,25 +2617,25 @@ function ds(e) {
2613
2617
  sessionId: s.sessionId,
2614
2618
  // Can be empty for new chats
2615
2619
  sessionIdStorageKey: s.sessionIdStorageKey,
2616
- contextProvider: e.contextProvider || Bt(),
2617
- toolProvider: e.toolProvider || Wt(),
2620
+ contextProvider: e.contextProvider || Wt(),
2621
+ toolProvider: e.toolProvider || zt(),
2618
2622
  authProvider: e.authProvider,
2619
2623
  enableStreaming: e.enableStreaming,
2620
2624
  odieBotId: e.odieBotId,
2621
2625
  credentials: e.credentials
2622
2626
  }), s.sessionId) {
2623
- const R = d.getConversationHistory(w);
2624
- n((M) => {
2625
- const b = g(R);
2627
+ const p = d.getConversationHistory(w);
2628
+ n((C) => {
2629
+ const k = M(p);
2626
2630
  return {
2627
- ...M,
2628
- clientMessages: R,
2629
- uiMessages: b
2631
+ ...C,
2632
+ clientMessages: p,
2633
+ uiMessages: k
2630
2634
  };
2631
2635
  });
2632
2636
  } else
2633
- n((R) => ({
2634
- ...R,
2637
+ n((p) => ({
2638
+ ...p,
2635
2639
  clientMessages: [],
2636
2640
  uiMessages: []
2637
2641
  }));
@@ -2648,228 +2652,237 @@ function ds(e) {
2648
2652
  e.odieBotId,
2649
2653
  e.credentials,
2650
2654
  t,
2651
- g
2655
+ M
2652
2656
  ]);
2653
- const A = D(
2654
- async (m, d, w) => {
2655
- var F, U;
2657
+ const g = j(
2658
+ async (T, d, w) => {
2659
+ var O, E;
2656
2660
  if (!t)
2657
2661
  throw new Error("Invalid agent configuration");
2658
2662
  if (u.current)
2659
2663
  return;
2660
2664
  u.current = !0;
2661
- const O = (d == null ? void 0 : d.type) === "tool_result";
2662
- if (O && (!(d != null && d.toolCallId) || !(d != null && d.toolId)))
2665
+ const U = (d == null ? void 0 : d.type) === "tool_result";
2666
+ if (U && (!(d != null && d.toolCallId) || !(d != null && d.toolId)))
2663
2667
  throw new Error(
2664
2668
  "`toolCallId` and `toolId` are required when type is `tool_result`"
2665
2669
  );
2666
- const R = X(), M = s.agentId, b = (w == null ? void 0 : w.preserveUiOnlyMessages) ?? !0, k = async (T) => {
2667
- const E = w == null ? void 0 : w.restoreOnError;
2668
- if (!E)
2670
+ const p = Y(), C = s.agentId, k = (w == null ? void 0 : w.preserveUiOnlyMessages) ?? !0, P = async (R) => {
2671
+ const H = w == null ? void 0 : w.restoreOnError;
2672
+ if (!H)
2669
2673
  return !1;
2670
2674
  try {
2671
- await R.replaceMessages(
2672
- M,
2673
- E.clientMessages
2675
+ await p.replaceMessages(
2676
+ C,
2677
+ H.clientMessages
2674
2678
  );
2675
- } catch (_) {
2676
- v(
2679
+ } catch (N) {
2680
+ A(
2677
2681
  "Failed to restore conversation history after a failed send",
2678
- _
2682
+ N
2679
2683
  );
2680
2684
  }
2681
- return n((_) => ({
2682
- ..._,
2683
- clientMessages: E.clientMessages,
2684
- uiMessages: E.uiMessages,
2685
+ return n((N) => ({
2686
+ ...N,
2687
+ clientMessages: H.clientMessages,
2688
+ uiMessages: H.uiMessages,
2685
2689
  isProcessing: !1,
2686
2690
  progressMessage: null,
2687
2691
  progressPhase: null,
2688
- error: T
2692
+ error: R
2689
2693
  })), !0;
2690
- }, P = Date.now();
2691
- if (O)
2692
- n((T) => ({
2693
- ...T,
2694
+ }, F = Date.now();
2695
+ if (U)
2696
+ n((R) => ({
2697
+ ...R,
2694
2698
  isProcessing: !0,
2695
2699
  error: null
2696
2700
  }));
2697
2701
  else {
2698
- const T = (d == null ? void 0 : d.type) || "text", E = w != null && w.messageOverride ? ne(
2702
+ const R = (d == null ? void 0 : d.type) || "text", H = w != null && w.messageOverride ? oe(
2699
2703
  w.messageOverride,
2700
2704
  []
2701
2705
  ) : {
2702
- id: `user-${P}`,
2706
+ id: `user-${F}`,
2703
2707
  role: "user",
2704
2708
  content: [
2705
- { type: T, text: m },
2709
+ { type: R, text: T },
2706
2710
  // Map image URLs to component content parts
2707
- ...((F = d == null ? void 0 : d.imageUrls) == null ? void 0 : F.map((_) => {
2708
- const j = typeof _ == "string" ? _ : _.url;
2709
- return ze(j);
2711
+ ...((O = d == null ? void 0 : d.imageUrls) == null ? void 0 : O.map((N) => {
2712
+ const L = typeof N == "string" ? N : N.url;
2713
+ return Ve(L);
2710
2714
  })) ?? []
2711
2715
  ],
2712
- timestamp: P,
2716
+ timestamp: F,
2713
2717
  archived: (d == null ? void 0 : d.archived) ?? !1,
2714
2718
  showIcon: !1
2715
2719
  };
2716
- n((_) => ({
2717
- ..._,
2718
- clientMessages: (w == null ? void 0 : w.initialClientMessages) ?? _.clientMessages,
2719
- uiMessages: E ? [
2720
- ...(w == null ? void 0 : w.initialUiMessages) ?? _.uiMessages,
2721
- E
2722
- ] : (w == null ? void 0 : w.initialUiMessages) ?? _.uiMessages,
2720
+ n((N) => ({
2721
+ ...N,
2722
+ clientMessages: (w == null ? void 0 : w.initialClientMessages) ?? N.clientMessages,
2723
+ uiMessages: H ? [
2724
+ ...(w == null ? void 0 : w.initialUiMessages) ?? N.uiMessages,
2725
+ H
2726
+ ] : (w == null ? void 0 : w.initialUiMessages) ?? N.uiMessages,
2723
2727
  isProcessing: !0,
2724
2728
  error: null
2725
2729
  }));
2726
2730
  }
2727
2731
  try {
2728
- w != null && w.truncateHistoryTo && await R.replaceMessages(
2729
- M,
2732
+ w != null && w.truncateHistoryTo && await p.replaceMessages(
2733
+ C,
2730
2734
  w.truncateHistoryTo
2731
2735
  );
2732
- let T = null, E = !1;
2733
- const _ = {}, j = !!(d != null && d.type) && !O;
2734
- (d != null && d.archived || j) && (_.metadata = {
2736
+ let R = null, H = !1;
2737
+ const N = {}, L = !!(d != null && d.type) && !U;
2738
+ (d != null && d.archived || L) && (N.metadata = {
2735
2739
  ...(d == null ? void 0 : d.archived) && { archived: !0 },
2736
- ...j && { contentType: d.type }
2737
- }), d != null && d.sessionId && (_.sessionId = d.sessionId), d != null && d.imageUrls && (_.imageUrls = d.imageUrls), w != null && w.messageOverride && (_.message = w.messageOverride);
2738
- const W = O ? R.sendToolResult(
2739
- M,
2740
+ ...L && { contentType: d.type }
2741
+ }), d != null && d.sessionId && (N.sessionId = d.sessionId), d != null && d.imageUrls && (N.imageUrls = d.imageUrls), w != null && w.messageOverride && (N.message = w.messageOverride);
2742
+ const B = U ? p.sendToolResult(
2743
+ C,
2740
2744
  d.toolCallId,
2741
2745
  d.toolId,
2742
- { success: !0, message: m },
2743
- _
2744
- ) : R.sendMessageStream(
2745
- M,
2746
- m,
2747
- _
2746
+ { success: !0, message: T },
2747
+ N
2748
+ ) : p.sendMessageStream(
2749
+ C,
2750
+ T,
2751
+ N
2748
2752
  );
2749
- for await (const H of W) {
2750
- if ((H.progressMessage || H.progressPhase) && n((N) => ({
2751
- ...N,
2752
- progressMessage: H.progressMessage || null,
2753
- progressPhase: H.progressPhase || null
2754
- })), !H.final && H.text) {
2755
- if (T)
2756
- n((N) => ({
2757
- ...N,
2758
- uiMessages: N.uiMessages.map(
2759
- ($) => $.id === T ? {
2760
- ...$,
2753
+ for await (const _ of B) {
2754
+ if (m.current)
2755
+ try {
2756
+ await m.current(_);
2757
+ } catch ($) {
2758
+ A(
2759
+ "Error in onTaskUpdate callback: %O",
2760
+ $
2761
+ );
2762
+ }
2763
+ if ((_.progressMessage || _.progressPhase) && n(($) => ({
2764
+ ...$,
2765
+ progressMessage: _.progressMessage || null,
2766
+ progressPhase: _.progressPhase || null
2767
+ })), !_.final && _.text) {
2768
+ if (R)
2769
+ n(($) => ({
2770
+ ...$,
2771
+ uiMessages: $.uiMessages.map(
2772
+ (D) => D.id === R ? {
2773
+ ...D,
2761
2774
  content: [
2762
2775
  {
2763
2776
  type: "text",
2764
- text: H.text
2777
+ text: _.text
2765
2778
  }
2766
2779
  ]
2767
- } : $
2780
+ } : D
2768
2781
  )
2769
2782
  }));
2770
2783
  else {
2771
- T = `agent-streaming-${Date.now()}`;
2772
- const N = {
2773
- id: T,
2784
+ R = `agent-streaming-${Date.now()}`;
2785
+ const $ = {
2786
+ id: R,
2774
2787
  role: "agent",
2775
2788
  content: [
2776
- { type: "text", text: H.text }
2789
+ { type: "text", text: _.text }
2777
2790
  ],
2778
2791
  timestamp: Date.now(),
2779
2792
  archived: !1,
2780
2793
  showIcon: !0,
2781
2794
  icon: "assistant",
2782
- reactKey: T
2795
+ reactKey: R
2783
2796
  // Stable key for React rendering
2784
2797
  };
2785
- n(($) => ({
2786
- ...$,
2798
+ n((D) => ({
2799
+ ...D,
2787
2800
  uiMessages: [
2788
- ...$.uiMessages,
2789
- N
2801
+ ...D.uiMessages,
2802
+ $
2790
2803
  ]
2791
2804
  }));
2792
2805
  }
2793
- H.kind === "status" && (T = null);
2806
+ _.kind === "status" && (R = null);
2794
2807
  }
2795
- if (H.final && ((U = H.status) != null && U.message) && T) {
2796
- E = !0;
2797
- const N = T, $ = ne(
2798
- H.status.message,
2799
- p.current
2808
+ if (_.final && ((E = _.status) != null && E.message) && R) {
2809
+ H = !0;
2810
+ const $ = R, D = oe(
2811
+ _.status.message,
2812
+ f.current
2800
2813
  );
2801
- $ && n((ee) => {
2802
- const te = ee.uiMessages.map(
2803
- (J) => {
2804
- var Ae, ve;
2805
- if (J.id === N) {
2806
- const Ve = $.content.length > 0 && ((Ae = $.content[0]) == null ? void 0 : Ae.text) && ((ve = J.content[0]) == null ? void 0 : ve.text) && $.content[0].text.length > J.content[0].text.length;
2814
+ D && n((se) => {
2815
+ const ae = se.uiMessages.map(
2816
+ (K) => {
2817
+ var ve, Se;
2818
+ if (K.id === $) {
2819
+ const Qe = D.content.length > 0 && ((ve = D.content[0]) == null ? void 0 : ve.text) && ((Se = K.content[0]) == null ? void 0 : Se.text) && D.content[0].text.length > K.content[0].text.length;
2807
2820
  return {
2808
- ...$,
2809
- reactKey: J.reactKey || N,
2821
+ ...D,
2822
+ reactKey: K.reactKey || $,
2810
2823
  // Keep stable reactKey
2811
- content: Ve ? $.content : J.content
2824
+ content: Qe ? D.content : K.content
2812
2825
  };
2813
2826
  }
2814
- return J;
2827
+ return K;
2815
2828
  }
2816
- ), se = R.getConversationHistory(
2817
- M
2818
- ), le = new Set(
2819
- se.map(
2820
- (J) => J.messageId
2829
+ ), ne = p.getConversationHistory(
2830
+ C
2831
+ ), ue = new Set(
2832
+ ne.map(
2833
+ (K) => K.messageId
2821
2834
  )
2822
- ), K = b ? te : te.filter(
2823
- (J) => le.has(J.id)
2835
+ ), W = k ? ae : ae.filter(
2836
+ (K) => ue.has(K.id)
2824
2837
  );
2825
2838
  return {
2826
- ...ee,
2827
- clientMessages: se,
2828
- uiMessages: K,
2839
+ ...se,
2840
+ clientMessages: ne,
2841
+ uiMessages: W,
2829
2842
  isProcessing: !1,
2830
2843
  progressMessage: null,
2831
2844
  progressPhase: null
2832
2845
  };
2833
- }), T = null;
2846
+ }), R = null;
2834
2847
  }
2835
2848
  }
2836
- if (!E) {
2837
- const H = R.getConversationHistory(M);
2838
- n((N) => {
2839
- let $ = N.uiMessages;
2840
- T && ($ = N.uiMessages.filter(
2841
- (K) => K.id !== T
2849
+ if (!H) {
2850
+ const _ = p.getConversationHistory(C);
2851
+ n(($) => {
2852
+ let D = $.uiMessages;
2853
+ R && (D = $.uiMessages.filter(
2854
+ (W) => W.id !== R
2842
2855
  ));
2843
- const ee = H.map(
2844
- (K) => ne(
2845
- K,
2846
- p.current
2856
+ const se = _.map(
2857
+ (W) => oe(
2858
+ W,
2859
+ f.current
2847
2860
  )
2848
2861
  ).filter(
2849
- (K) => K !== null
2850
- ), te = new Set(
2851
- H.map((K) => K.messageId)
2852
- ), se = b ? Kt(
2853
- $,
2854
- te
2855
- ) : [], le = fe([
2856
- ...ee,
2857
- ...se
2862
+ (W) => W !== null
2863
+ ), ae = new Set(
2864
+ _.map((W) => W.messageId)
2865
+ ), ne = k ? Bt(
2866
+ D,
2867
+ ae
2868
+ ) : [], ue = me([
2869
+ ...se,
2870
+ ...ne
2858
2871
  ]);
2859
2872
  return {
2860
- ...N,
2861
- clientMessages: H,
2862
- uiMessages: le,
2873
+ ...$,
2874
+ clientMessages: _,
2875
+ uiMessages: ue,
2863
2876
  isProcessing: !1,
2864
2877
  progressMessage: null,
2865
2878
  progressPhase: null
2866
2879
  };
2867
2880
  });
2868
2881
  }
2869
- } catch (T) {
2870
- if (T instanceof Error && T.name === "AbortError") {
2871
- v("Request was aborted by user"), await k(null) || n((W) => ({
2872
- ...W,
2882
+ } catch (R) {
2883
+ if (R instanceof Error && R.name === "AbortError") {
2884
+ A("Request was aborted by user"), await P(null) || n((B) => ({
2885
+ ...B,
2873
2886
  isProcessing: !1,
2874
2887
  progressMessage: null,
2875
2888
  progressPhase: null,
@@ -2878,123 +2891,123 @@ function ds(e) {
2878
2891
  }));
2879
2892
  return;
2880
2893
  }
2881
- const E = T instanceof Error ? T.message : "Failed to send message";
2882
- throw await k(E) || n((j) => ({
2883
- ...j,
2894
+ const H = R instanceof Error ? R.message : "Failed to send message";
2895
+ throw await P(H) || n((L) => ({
2896
+ ...L,
2884
2897
  isProcessing: !1,
2885
2898
  progressMessage: null,
2886
2899
  progressPhase: null,
2887
- error: E
2888
- })), T;
2900
+ error: H
2901
+ })), R;
2889
2902
  } finally {
2890
2903
  u.current = !1;
2891
2904
  }
2892
2905
  },
2893
2906
  [s.agentId, t]
2894
- ), f = D(
2895
- (m, d) => A(m, d),
2896
- [A]
2897
- ), h = D((m) => {
2907
+ ), h = j(
2908
+ (T, d) => g(T, d),
2909
+ [g]
2910
+ ), I = j((T) => {
2898
2911
  n((d) => ({
2899
2912
  ...d,
2900
- uiMessages: fe([...d.uiMessages, m])
2913
+ uiMessages: me([...d.uiMessages, T])
2901
2914
  }));
2902
- }, []), I = D((m) => {
2915
+ }, []), v = j((T) => {
2903
2916
  n((d) => ({
2904
2917
  ...d,
2905
- suggestions: m
2918
+ suggestions: T
2906
2919
  }));
2907
- }, []), S = D(() => {
2908
- n((m) => ({
2909
- ...m,
2920
+ }, []), y = j(() => {
2921
+ n((T) => ({
2922
+ ...T,
2910
2923
  suggestions: []
2911
2924
  }));
2912
2925
  }, []);
2913
- ae(() => {
2914
- n((m) => {
2915
- if (u.current || m.clientMessages.length === 0)
2916
- return m;
2917
- const d = g(m.clientMessages), w = new Set(
2918
- m.clientMessages.map((R) => R.messageId)
2919
- ), O = m.uiMessages.filter(
2920
- (R) => !w.has(R.id) && R.role !== "user"
2926
+ te(() => {
2927
+ n((T) => {
2928
+ if (u.current || T.clientMessages.length === 0)
2929
+ return T;
2930
+ const d = M(T.clientMessages), w = new Set(
2931
+ T.clientMessages.map((p) => p.messageId)
2932
+ ), U = T.uiMessages.filter(
2933
+ (p) => !w.has(p.id) && p.role !== "user"
2921
2934
  );
2922
2935
  return {
2923
- ...m,
2924
- uiMessages: fe([
2936
+ ...T,
2937
+ uiMessages: me([
2925
2938
  ...d,
2926
- ...O
2939
+ ...U
2927
2940
  ])
2928
2941
  };
2929
2942
  });
2930
- }, [i, g]);
2931
- const y = D(() => {
2943
+ }, [i, M]);
2944
+ const x = j(() => {
2932
2945
  if (!t)
2933
2946
  return;
2934
- const m = X(), d = s.agentId;
2935
- m.abortCurrentRequest(d);
2936
- }, [s.agentId, t]), C = D(
2937
- async (m) => {
2947
+ const T = Y(), d = s.agentId;
2948
+ T.abortCurrentRequest(d);
2949
+ }, [s.agentId, t]), b = j(
2950
+ async (T) => {
2938
2951
  if (!t)
2939
2952
  return;
2940
- const d = X(), w = s.agentId;
2941
- await d.replaceMessages(w, m);
2942
- const O = g(m);
2943
- n((R) => ({
2944
- ...R,
2945
- clientMessages: m,
2946
- uiMessages: O
2953
+ const d = Y(), w = s.agentId;
2954
+ await d.replaceMessages(w, T);
2955
+ const U = M(T);
2956
+ n((p) => ({
2957
+ ...p,
2958
+ clientMessages: T,
2959
+ uiMessages: U
2947
2960
  }));
2948
2961
  },
2949
- [s.agentId, t, g]
2950
- ), { getRegenerateHandler: x } = Jt({
2962
+ [s.agentId, t, M]
2963
+ ), { getRegenerateHandler: S } = Kt({
2951
2964
  agentId: s.agentId,
2952
2965
  isValidConfig: t,
2953
2966
  isSendingRef: u,
2954
2967
  stateRef: c,
2955
- transformMessages: g,
2956
- sendMessage: A
2968
+ transformMessages: M,
2969
+ sendMessage: g
2957
2970
  });
2958
2971
  return {
2959
2972
  // AgentUI props
2960
2973
  messages: a.uiMessages,
2961
2974
  isProcessing: a.isProcessing,
2962
2975
  error: a.error,
2963
- onSubmit: f,
2976
+ onSubmit: h,
2964
2977
  suggestions: a.suggestions,
2965
2978
  progressMessage: a.progressMessage,
2966
2979
  progressPhase: a.progressPhase,
2967
2980
  // UI management methods
2968
- registerSuggestions: I,
2969
- clearSuggestions: S,
2981
+ registerSuggestions: v,
2982
+ clearSuggestions: y,
2970
2983
  // Message actions methods
2971
2984
  registerMessageActions: o,
2972
2985
  unregisterMessageActions: r,
2973
2986
  clearAllMessageActions: l,
2974
- getRegenerateHandler: x,
2987
+ getRegenerateHandler: S,
2975
2988
  // Tool integration
2976
- addMessage: h,
2989
+ addMessage: I,
2977
2990
  // Abort control
2978
- abortCurrentRequest: y,
2991
+ abortCurrentRequest: x,
2979
2992
  // Conversation loading
2980
- loadMessages: C
2993
+ loadMessages: b
2981
2994
  };
2982
2995
  }
2983
- var Vt = /* @__PURE__ */ ((e) => (e[e.PARSE_ERROR = -32700] = "PARSE_ERROR", e[e.INVALID_REQUEST = -32600] = "INVALID_REQUEST", e[e.METHOD_NOT_FOUND = -32601] = "METHOD_NOT_FOUND", e[e.INVALID_PARAMS = -32602] = "INVALID_PARAMS", e[e.INTERNAL_ERROR = -32603] = "INTERNAL_ERROR", e[e.SERVER_ERROR = -32e3] = "SERVER_ERROR", e))(Vt || {});
2984
- const Pe = "jetpack-ai-jwt-token", Qt = 30 * 60 * 1e3;
2985
- function Gt() {
2996
+ var Qt = /* @__PURE__ */ ((e) => (e[e.PARSE_ERROR = -32700] = "PARSE_ERROR", e[e.INVALID_REQUEST = -32600] = "INVALID_REQUEST", e[e.METHOD_NOT_FOUND = -32601] = "METHOD_NOT_FOUND", e[e.INVALID_PARAMS = -32602] = "INVALID_PARAMS", e[e.INTERNAL_ERROR = -32603] = "INTERNAL_ERROR", e[e.SERVER_ERROR = -32e3] = "SERVER_ERROR", e))(Qt || {});
2997
+ const _e = "jetpack-ai-jwt-token", Gt = 30 * 60 * 1e3;
2998
+ function Xt() {
2986
2999
  var t, a, n;
2987
3000
  return ((a = (t = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : t.connectionStatus) == null ? void 0 : a.isRegistered) ? !1 : !!((n = window.Jetpack_Editor_Initial_State) != null && n.wpcomBlogId);
2988
3001
  }
2989
- async function Xt(e, s = !0) {
3002
+ async function Yt(e, s = !0) {
2990
3003
  var i, u;
2991
- const t = localStorage.getItem(Pe);
3004
+ const t = localStorage.getItem(_e);
2992
3005
  let a;
2993
3006
  if (t)
2994
3007
  try {
2995
3008
  a = JSON.parse(t);
2996
3009
  } catch (c) {
2997
- v("Invalid cached Jetpack token: %O", c);
3010
+ A("Invalid cached Jetpack token: %O", c);
2998
3011
  }
2999
3012
  if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && s)
3000
3013
  return a;
@@ -3004,10 +3017,10 @@ async function Xt(e, s = !0) {
3004
3017
  blog_id: ""
3005
3018
  };
3006
3019
  try {
3007
- Gt() ? r = await Se({
3020
+ Xt() ? r = await Ce({
3008
3021
  path: "/wpcom/v2/sites/" + o + "/jetpack-openai-query/jwt",
3009
3022
  method: "POST"
3010
- }) : r = await Se({
3023
+ }) : r = await Ce({
3011
3024
  path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
3012
3025
  credentials: "same-origin",
3013
3026
  headers: {
@@ -3016,7 +3029,7 @@ async function Xt(e, s = !0) {
3016
3029
  method: "POST"
3017
3030
  });
3018
3031
  } catch (c) {
3019
- throw v("Failed to fetch Jetpack token: %O", c), new Error(e(c));
3032
+ throw A("Failed to fetch Jetpack token: %O", c), new Error(e(c));
3020
3033
  }
3021
3034
  if (!(r != null && r.token))
3022
3035
  throw new Error(
@@ -3025,26 +3038,26 @@ async function Xt(e, s = !0) {
3025
3038
  const l = {
3026
3039
  token: r.token,
3027
3040
  blogId: r.blog_id || "",
3028
- expire: Date.now() + Qt
3041
+ expire: Date.now() + Gt
3029
3042
  };
3030
3043
  try {
3031
- localStorage.setItem(Pe, JSON.stringify(l));
3044
+ localStorage.setItem(_e, JSON.stringify(l));
3032
3045
  } catch (c) {
3033
- v("Error storing token in localStorage: %O", c);
3046
+ A("Error storing token in localStorage: %O", c);
3034
3047
  }
3035
3048
  return l;
3036
3049
  }
3037
- const gs = (e) => async () => {
3050
+ const fs = (e) => async () => {
3038
3051
  const s = {};
3039
3052
  try {
3040
- const t = await Xt(e);
3053
+ const t = await Yt(e);
3041
3054
  t != null && t.token && (s.Authorization = `${t.token}`);
3042
3055
  } catch (t) {
3043
- throw v("Failed to get Jetpack token for auth: %O", t), t;
3056
+ throw A("Failed to get Jetpack token for auth: %O", t), t;
3044
3057
  }
3045
3058
  return s;
3046
3059
  };
3047
- function Yt(e) {
3060
+ function Zt(e) {
3048
3061
  const s = {
3049
3062
  type: "object",
3050
3063
  properties: {}
@@ -3059,17 +3072,17 @@ function Yt(e) {
3059
3072
  _originalAbility: e
3060
3073
  };
3061
3074
  }
3062
- function fs(e) {
3063
- return e.map(Yt);
3064
- }
3065
3075
  function ms(e) {
3076
+ return e.map(Zt);
3077
+ }
3078
+ function ps(e) {
3066
3079
  return (e == null ? void 0 : e._source) === "wordpress-ability";
3067
3080
  }
3068
- function ps(e, s = "agent", t = "wpcom") {
3081
+ function hs(e, s = "agent", t = "wpcom") {
3069
3082
  const a = e.replace(/-/g, "_");
3070
3083
  return `${t}-${s}-${a}`;
3071
3084
  }
3072
- function Zt(e) {
3085
+ function es(e) {
3073
3086
  const s = e.split("-");
3074
3087
  if (s.length < 3)
3075
3088
  throw new Error(
@@ -3088,58 +3101,58 @@ function Zt(e) {
3088
3101
  agentId: r
3089
3102
  };
3090
3103
  }
3091
- function hs(e) {
3104
+ function ys(e) {
3092
3105
  try {
3093
- const s = Zt(e);
3106
+ const s = es(e);
3094
3107
  return s.product.length > 0 && ["agent", "workflow", "chain"].includes(s.type) && s.slug.length > 0;
3095
3108
  } catch {
3096
3109
  return !1;
3097
3110
  }
3098
3111
  }
3099
3112
  export {
3100
- Vt as ErrorCodes,
3101
- ws as agentsApiContinueResponse,
3102
- Ms as agentsApiDeleteSession,
3103
- Ts as agentsApiListSessions,
3104
- As as agentsApiLoadSession,
3105
- vs as agentsApiMarkSessionRead,
3106
- Ss as agentsApiSendMessage,
3107
- fs as convertAbilitiesToTools,
3108
- Yt as convertAbilityToTool,
3109
- ls as createAbortController,
3110
- Cs as createAgentsApiChatAdapter,
3111
- xs as createAgentsApiRunControlAdapter,
3112
- Mt as createClient,
3113
- gs as createJetpackAuthProvider,
3114
- ps as createOdieBotId,
3115
- bs as createPresentQuestionRenderer,
3116
- Rs as createPresentQuestionToolRenderers,
3117
- Ye as createRequestId,
3118
- Ze as createTaskId,
3119
- me as createTextMessage,
3120
- L as extractTextFromMessage,
3121
- V as extractToolCallsFromMessage,
3122
- X as getAgentManager,
3123
- ks as groupToolMessages,
3124
- hs as isOdieBotId,
3125
- ms as isWordPressAbility,
3126
- cs as listConversationsFromServer,
3127
- us as loadAllMessagesFromServer,
3128
- pe as loadChatFromServer,
3129
- Ps as normalizeAgentsApiMessage,
3130
- _s as normalizeConversation,
3131
- Es as normalizeLoadedSession,
3132
- Ns as normalizePresentQuestionPrompt,
3113
+ Qt as ErrorCodes,
3114
+ Ms as agentsApiContinueResponse,
3115
+ Ts as agentsApiDeleteSession,
3116
+ As as agentsApiListSessions,
3117
+ vs as agentsApiLoadSession,
3118
+ Ss as agentsApiMarkSessionRead,
3119
+ Cs as agentsApiSendMessage,
3120
+ ms as convertAbilitiesToTools,
3121
+ Zt as convertAbilityToTool,
3122
+ cs as createAbortController,
3123
+ xs as createAgentsApiChatAdapter,
3124
+ bs as createAgentsApiRunControlAdapter,
3125
+ Tt as createClient,
3126
+ fs as createJetpackAuthProvider,
3127
+ hs as createOdieBotId,
3128
+ Rs as createPresentQuestionRenderer,
3129
+ ks as createPresentQuestionToolRenderers,
3130
+ Ze as createRequestId,
3131
+ et as createTaskId,
3132
+ pe as createTextMessage,
3133
+ J as extractTextFromMessage,
3134
+ Q as extractToolCallsFromMessage,
3135
+ Y as getAgentManager,
3136
+ Ps as groupToolMessages,
3137
+ ys as isOdieBotId,
3138
+ ps as isWordPressAbility,
3139
+ us as listConversationsFromServer,
3140
+ ds as loadAllMessagesFromServer,
3141
+ he as loadChatFromServer,
3142
+ _s as normalizeAgentsApiMessage,
3143
+ Es as normalizeConversation,
3144
+ Ns as normalizeLoadedSession,
3145
+ Us as normalizePresentQuestionPrompt,
3133
3146
  Hs as normalizeRunEvent,
3134
3147
  Os as normalizeSendResponse,
3135
- Us as normalizeSessions,
3136
- Zt as parseOdieBotId,
3137
- $s as renderToolGroups,
3138
- ds as useAgentChat,
3139
- qs as useAgentsApiChat,
3140
- os as useClientAbilities,
3141
- ns as useClientContext,
3142
- rs as useClientTools,
3143
- is as useClientToolsWithAbilities,
3144
- $t as useMessageActions
3148
+ $s as normalizeSessions,
3149
+ es as parseOdieBotId,
3150
+ qs as renderToolGroups,
3151
+ gs as useAgentChat,
3152
+ Fs as useAgentsApiChat,
3153
+ is as useClientAbilities,
3154
+ rs as useClientContext,
3155
+ os as useClientTools,
3156
+ ls as useClientToolsWithAbilities,
3157
+ qt as useMessageActions
3145
3158
  };