@automattic/agenttic-client 0.1.64 → 0.1.66

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