@automattic/agenttic-client 0.1.45 → 0.1.47

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,6 +1,6 @@
1
1
  var $e = Object.defineProperty;
2
- var Ue = (e, t, s) => t in e ? $e(e, t, { enumerable: !0, configurable: !0, writable: !0, value: s }) : e[t] = s;
3
- var te = (e, t, s) => Ue(e, typeof t != "symbol" ? t + "" : t, s);
2
+ var Ue = (e, s, t) => s in e ? $e(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
3
+ var te = (e, s, t) => Ue(e, typeof s != "symbol" ? s + "" : s, t);
4
4
  import qe, { useMemo as Se, useCallback as F, useState as ve, useRef as He, useEffect as se } from "react";
5
5
  import { l as M, f as Me, a as K } from "./logger-aKHbTlwk.js";
6
6
  import pe from "@wordpress/api-fetch";
@@ -17,8 +17,8 @@ function Ht(e) {
17
17
  }
18
18
  function ce({
19
19
  getClientTools: e,
20
- executeTool: t,
21
- getAbilities: s
20
+ executeTool: s,
21
+ getAbilities: t
22
22
  }) {
23
23
  const a = F(async () => {
24
24
  const o = [];
@@ -32,33 +32,33 @@ function ce({
32
32
  return o;
33
33
  }, [e]), n = F(
34
34
  async (o, c) => {
35
- if (!t)
35
+ if (!s)
36
36
  throw new Error("No executeTool callback provided");
37
37
  try {
38
- return await t(o, c);
38
+ return await s(o, c);
39
39
  } catch (l) {
40
40
  throw M("Error executing tool %s: %O", o, l), l;
41
41
  }
42
42
  },
43
- [t]
43
+ [s]
44
44
  );
45
45
  return Se(() => {
46
- if (!e && !s)
46
+ if (!e && !t)
47
47
  return;
48
48
  const o = {};
49
- return e && (o.getAvailableTools = a), t && (o.executeTool = n), s && (o.getAbilities = s), o;
49
+ return e && (o.getAvailableTools = a), s && (o.executeTool = n), t && (o.getAbilities = t), o;
50
50
  }, [
51
51
  a,
52
52
  n,
53
53
  e,
54
- t,
55
- s
54
+ s,
55
+ t
56
56
  ]);
57
57
  }
58
- function Ft(e, t) {
58
+ function Ft(e, s) {
59
59
  return ce({
60
60
  getClientTools: e,
61
- executeTool: t,
61
+ executeTool: s,
62
62
  getAbilities: void 0
63
63
  });
64
64
  }
@@ -70,27 +70,27 @@ function jt(e) {
70
70
  });
71
71
  }
72
72
  function Dt(e) {
73
- const { getClientTools: t, executeTool: s, getAbilities: a } = e;
74
- if (!t && !a)
73
+ const { getClientTools: s, executeTool: t, getAbilities: a } = e;
74
+ if (!s && !a)
75
75
  throw new Error(
76
76
  "At least one of getClientTools or getAbilities must be provided to useClientToolsWithAbilities."
77
77
  );
78
- if (t && !s)
78
+ if (s && !t)
79
79
  throw new Error(
80
80
  "executeTool is required when providing getClientTools."
81
81
  );
82
82
  return ce({
83
- getClientTools: t,
84
- executeTool: s,
83
+ getClientTools: s,
84
+ executeTool: t,
85
85
  getAbilities: a
86
86
  });
87
87
  }
88
88
  function ue() {
89
89
  const e = "abcdefghijklmnopqrstuvwxyz0123456789";
90
- let t = "";
91
- for (let s = 0; s < 8; s++)
92
- t += e.charAt(Math.floor(Math.random() * e.length));
93
- return t;
90
+ let s = "";
91
+ for (let t = 0; t < 8; t++)
92
+ s += e.charAt(Math.floor(Math.random() * e.length));
93
+ return s;
94
94
  }
95
95
  function N() {
96
96
  return ue();
@@ -101,33 +101,33 @@ function Fe() {
101
101
  function je() {
102
102
  return `task-${ue()}`;
103
103
  }
104
- function xe(e, t) {
104
+ function xe(e, s) {
105
105
  return {
106
106
  type: "text",
107
107
  text: e,
108
- ...t && { metadata: t }
108
+ ...s && { metadata: s }
109
109
  };
110
110
  }
111
- function De(e, t = "message/send", s = !1) {
111
+ function De(e, s = "message/send", t = !1) {
112
112
  const a = {
113
113
  jsonrpc: "2.0",
114
114
  id: Fe(),
115
- method: t,
115
+ method: s,
116
116
  params: {
117
117
  id: e.id || je(),
118
118
  ...e
119
119
  }
120
120
  };
121
- return s && t === "message/stream" && (a.tokenStreaming = !0), a;
121
+ return t && s === "message/stream" && (a.tokenStreaming = !0), a;
122
122
  }
123
123
  function j(e) {
124
- return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((t) => t.type === "text").map((t) => t.text).join(" ");
124
+ return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
125
125
  }
126
126
  function he(e) {
127
127
  if (!e || !e.parts || !Array.isArray(e.parts))
128
128
  return;
129
- const t = e.parts.find((s) => s.type === "progress" ? !0 : s.type === "data" ? "summary" in s.data && typeof s.data.summary == "string" : !1);
130
- return t ? t.data.summary : void 0;
129
+ const s = e.parts.find((t) => t.type === "progress" ? !0 : t.type === "data" ? "summary" in t.data && typeof t.data.summary == "string" : !1);
130
+ return s ? s.data.summary : void 0;
131
131
  }
132
132
  function Je(e) {
133
133
  return {
@@ -158,16 +158,16 @@ function Ke(e) {
158
158
  }
159
159
  function L(e) {
160
160
  return !e || !e.parts || !Array.isArray(e.parts) ? [] : e.parts.filter(
161
- (t) => t.type === "data" && "toolCallId" in t.data && "toolId" in t.data && "arguments" in t.data
161
+ (s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
162
162
  );
163
163
  }
164
- function W(e, t, s, a) {
164
+ function W(e, s, t, a) {
165
165
  return {
166
166
  type: "data",
167
167
  data: {
168
168
  toolCallId: e,
169
- toolId: t,
170
- result: s
169
+ toolId: s,
170
+ result: t
171
171
  },
172
172
  metadata: a ? { error: a } : void 0
173
173
  };
@@ -181,11 +181,11 @@ function Le(e) {
181
181
  metadata: {}
182
182
  };
183
183
  }
184
- function ie(e, t) {
185
- const { contentType: s, ...a } = t || {};
184
+ function ie(e, s) {
185
+ const { contentType: t, ...a } = s || {};
186
186
  return {
187
187
  role: "user",
188
- parts: [xe(e, s ? { contentType: s } : void 0)],
188
+ parts: [xe(e, t ? { contentType: t } : void 0)],
189
189
  kind: "message",
190
190
  messageId: N(),
191
191
  metadata: {
@@ -217,11 +217,11 @@ function de(e) {
217
217
  returnToAgent: !0
218
218
  };
219
219
  }
220
- function X(e, t = []) {
220
+ function X(e, s = []) {
221
221
  return {
222
222
  role: "user",
223
223
  kind: "message",
224
- parts: [...t, ...e],
224
+ parts: [...s, ...e],
225
225
  messageId: N(),
226
226
  metadata: {
227
227
  timestamp: Date.now()
@@ -231,63 +231,63 @@ function X(e, t = []) {
231
231
  function Jt() {
232
232
  return new AbortController();
233
233
  }
234
- async function Be(e, t) {
235
- if (!t)
234
+ async function Be(e, s) {
235
+ if (!s)
236
236
  return e;
237
237
  try {
238
- const s = [];
239
- if (t.getAvailableTools) {
240
- const a = await t.getAvailableTools();
238
+ const t = [];
239
+ if (s.getAvailableTools) {
240
+ const a = await s.getAvailableTools();
241
241
  if (a.length > 0) {
242
242
  const n = a.map(Je);
243
- s.push(...n);
243
+ t.push(...n);
244
244
  }
245
245
  }
246
- if (t.getAbilities) {
247
- const a = await t.getAbilities();
246
+ if (s.getAbilities) {
247
+ const a = await s.getAbilities();
248
248
  if (a.length > 0) {
249
249
  const n = a.map(Ke);
250
- s.push(...n);
250
+ t.push(...n);
251
251
  }
252
252
  }
253
- return s.length === 0 ? e : {
253
+ return t.length === 0 ? e : {
254
254
  ...e,
255
- parts: [...e.parts, ...s]
255
+ parts: [...e.parts, ...t]
256
256
  };
257
- } catch (s) {
258
- return M("Warning: Failed to get tools: %s", s), e;
257
+ } catch (t) {
258
+ return M("Warning: Failed to get tools: %s", t), e;
259
259
  }
260
260
  }
261
- function We(e, t) {
262
- if (!t)
261
+ function We(e, s) {
262
+ if (!s)
263
263
  return e;
264
264
  try {
265
- const s = t.getClientContext();
266
- if (!s || Object.keys(s).length === 0)
265
+ const t = s.getClientContext();
266
+ if (!t || Object.keys(t).length === 0)
267
267
  return e;
268
- const a = Le(s);
268
+ const a = Le(t);
269
269
  return {
270
270
  ...e,
271
271
  parts: [...e.parts, a]
272
272
  };
273
- } catch (s) {
274
- return M("Warning: Failed to get context: %s", s), e;
273
+ } catch (t) {
274
+ return M("Warning: Failed to get context: %s", t), e;
275
275
  }
276
276
  }
277
- async function Ve(e, t, s) {
277
+ async function Ve(e, s, t) {
278
278
  let a = await Be(
279
279
  e,
280
- t
280
+ s
281
281
  );
282
282
  a = We(
283
283
  a,
284
- s
284
+ t
285
285
  );
286
286
  const { metadata: n, ...r } = a;
287
287
  return r;
288
288
  }
289
- function ze(e, t = "") {
290
- const s = [], a = t + e;
289
+ function ze(e, s = "") {
290
+ const t = [], a = s + e;
291
291
  let n = "", r = 0, o = 0;
292
292
  for (; o < a.length; ) {
293
293
  const l = a.indexOf(
@@ -302,7 +302,7 @@ function ze(e, t = "") {
302
302
  );
303
303
  else if (u.trim() === "" && n) {
304
304
  try {
305
- s.push(JSON.parse(n)), r = l === -1 ? a.length : l + 1;
305
+ t.push(JSON.parse(n)), r = l === -1 ? a.length : l + 1;
306
306
  } catch (d) {
307
307
  M("Failed to parse SSE event: %o", d), M("Problematic payload: %s", n);
308
308
  }
@@ -311,11 +311,11 @@ function ze(e, t = "") {
311
311
  l === -1 ? o = a.length : o = l + 1;
312
312
  }
313
313
  const c = a.substring(r);
314
- return { events: s, nextBuffer: c };
314
+ return { events: t, nextBuffer: c };
315
315
  }
316
- async function* Ge(e, t = {}) {
316
+ async function* Ge(e, s = {}) {
317
317
  var u, d, p;
318
- const { supportDeltas: s = !1 } = t, a = e.getReader(), n = new TextDecoder();
318
+ const { supportDeltas: t = !1 } = s, a = e.getReader(), n = new TextDecoder();
319
319
  let r = "";
320
320
  const o = new Qe();
321
321
  let c = null, l = null;
@@ -334,7 +334,7 @@ async function* Ge(e, t = {}) {
334
334
  throw new Error(
335
335
  `Streaming error: ${i.error.message}`
336
336
  );
337
- if (s && i.method === "message/delta" && ((u = i.params) != null && u.delta)) {
337
+ if (t && i.method === "message/delta" && ((u = i.params) != null && u.delta)) {
338
338
  const T = i.params.delta;
339
339
  try {
340
340
  if (T.deltaType === "content" && (o.processContentDelta(
@@ -398,33 +398,33 @@ class Qe {
398
398
  * Process a simple content delta (server's actual format)
399
399
  * @param content - The text content to append
400
400
  */
401
- processContentDelta(t) {
402
- this.textContent += t;
401
+ processContentDelta(s) {
402
+ this.textContent += s;
403
403
  }
404
404
  /**
405
405
  * Process a delta message and accumulate the content (original format)
406
406
  * @param delta - The delta message to process
407
407
  */
408
- processDelta(t) {
409
- switch (t.type) {
408
+ processDelta(s) {
409
+ switch (s.type) {
410
410
  case "content":
411
- this.textContent += t.content;
411
+ this.textContent += s.content;
412
412
  break;
413
413
  case "tool_name":
414
- this.toolCalls.has(t.toolCallIndex) || this.toolCalls.set(t.toolCallIndex, {
415
- toolCallId: t.toolCallId,
414
+ this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
415
+ toolCallId: s.toolCallId,
416
416
  toolName: "",
417
417
  argumentFragments: []
418
418
  });
419
- const s = this.toolCalls.get(t.toolCallIndex);
420
- s.toolName += t.content;
419
+ const t = this.toolCalls.get(s.toolCallIndex);
420
+ t.toolName += s.content;
421
421
  break;
422
422
  case "tool_argument":
423
- this.toolCalls.has(t.toolCallIndex) || this.toolCalls.set(t.toolCallIndex, {
424
- toolCallId: t.toolCallId,
423
+ this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
424
+ toolCallId: s.toolCallId,
425
425
  toolName: "",
426
426
  argumentFragments: []
427
- }), this.toolCalls.get(t.toolCallIndex).argumentFragments.push(t.content);
427
+ }), this.toolCalls.get(s.toolCallIndex).argumentFragments.push(s.content);
428
428
  break;
429
429
  }
430
430
  }
@@ -438,9 +438,9 @@ class Qe {
438
438
  * Get the current accumulated message
439
439
  * @param role - The role for the message (default: 'agent')
440
440
  */
441
- getCurrentMessage(t = "agent") {
442
- const s = [];
443
- this.textContent && s.push({
441
+ getCurrentMessage(s = "agent") {
442
+ const t = [];
443
+ this.textContent && t.push({
444
444
  type: "text",
445
445
  text: this.textContent
446
446
  });
@@ -454,7 +454,7 @@ class Qe {
454
454
  } catch {
455
455
  o = { _raw: r };
456
456
  }
457
- s.push({
457
+ t.push({
458
458
  type: "data",
459
459
  data: {
460
460
  toolCallId: n.toolCallId,
@@ -464,8 +464,8 @@ class Qe {
464
464
  });
465
465
  }
466
466
  return {
467
- role: t,
468
- parts: s,
467
+ role: s,
468
+ parts: t,
469
469
  kind: "message",
470
470
  messageId: N()
471
471
  };
@@ -477,71 +477,71 @@ class Qe {
477
477
  this.textContent = "", this.toolCalls.clear();
478
478
  }
479
479
  }
480
- function Ae(e, t, s = "request") {
481
- throw clearTimeout(t), M("%s failed with error: %O", s, e), e instanceof Error && (M("Error message: %s", e.message), M("Error stack: %s", e.stack)), e;
480
+ function Ae(e, s, t = "request") {
481
+ throw clearTimeout(s), M("%s failed with error: %O", t, e), e instanceof Error && (M("Error message: %s", e.message), M("Error stack: %s", e.stack)), e;
482
482
  }
483
- function Ce(e, t = "request") {
483
+ function Ce(e, s = "request") {
484
484
  if (!e.ok)
485
485
  throw new Error(`HTTP error! status: ${e.status}`);
486
486
  }
487
- function Xe(e, t = "request") {
487
+ function Xe(e, s = "request") {
488
488
  if (e.error)
489
489
  throw new Error(
490
- `Protocol ${t} error: ${e.error.message}`
490
+ `Protocol ${s} error: ${e.error.message}`
491
491
  );
492
492
  if (!e.result)
493
- throw new Error(`No result in ${t} response`);
493
+ throw new Error(`No result in ${s} response`);
494
494
  return e.result;
495
495
  }
496
- function Ye(e, t = "streaming request") {
497
- if (Ce(e, t), !e.body)
498
- throw new Error(`No response body for ${t}`);
496
+ function Ye(e, s = "streaming request") {
497
+ if (Ce(e, s), !e.body)
498
+ throw new Error(`No response body for ${s}`);
499
499
  }
500
- function be(e, t = "request") {
501
- const s = new AbortController();
500
+ function be(e, s = "request") {
501
+ const t = new AbortController();
502
502
  return { timeoutId: setTimeout(
503
- () => s.abort(),
503
+ () => t.abort(),
504
504
  e
505
- ), controller: s };
505
+ ), controller: t };
506
506
  }
507
- function Ze(e, t) {
508
- return `${e}/${t}`;
507
+ function Ze(e, s) {
508
+ return `${e}/${s}`;
509
509
  }
510
- function et(e, t, s, a) {
511
- M("Request: %s %s", e, t), M("Headers: %o", s), a && M("Body: %s", Me(a));
510
+ function et(e, s, t, a) {
511
+ M("Request: %s %s", e, s), M("Headers: %o", t), a && M("Body: %s", Me(a));
512
512
  }
513
- async function tt(e, t = !1) {
514
- const s = {
513
+ async function tt(e, s = !1) {
514
+ const t = {
515
515
  "Content-Type": "application/json"
516
516
  };
517
- if (t && (s.Accept = "text/event-stream"), e) {
517
+ if (s && (t.Accept = "text/event-stream"), e) {
518
518
  const a = await e();
519
- return { ...s, ...a };
519
+ return { ...t, ...a };
520
520
  }
521
- return s;
521
+ return t;
522
522
  }
523
- function ke(e, t) {
524
- if (!t)
523
+ function ke(e, s) {
524
+ if (!s)
525
525
  return e;
526
- const s = new AbortController(), a = (n) => {
527
- s.signal.aborted || s.abort(n.reason);
526
+ const t = new AbortController(), a = (n) => {
527
+ t.signal.aborted || t.abort(n.reason);
528
528
  };
529
- return e.aborted ? s.abort(e.reason) : e.addEventListener("abort", () => a(e), {
529
+ return e.aborted ? t.abort(e.reason) : e.addEventListener("abort", () => a(e), {
530
530
  once: !0
531
- }), t.aborted ? s.abort(t.reason) : t.addEventListener("abort", () => a(t), {
531
+ }), s.aborted ? t.abort(s.reason) : s.addEventListener("abort", () => a(s), {
532
532
  once: !0
533
- }), s.signal;
533
+ }), t.signal;
534
534
  }
535
- function Re(e, t, s) {
535
+ function Re(e, s, t) {
536
536
  return {
537
537
  method: "POST",
538
538
  headers: e,
539
- body: t,
540
- signal: s
539
+ body: s,
540
+ signal: t
541
541
  };
542
542
  }
543
- async function Y(e, t, s, a, n, r) {
544
- const { message: o, sessionId: c, taskId: l, metadata: u } = e, { agentId: d, agentUrl: p, authProvider: m, proxy: f } = t, { isStreaming: I = !1, enableTokenStreaming: h = !1 } = s, A = c || r, g = Ze(p, d), i = await Ve(
543
+ async function Y(e, s, t, a, n, r) {
544
+ const { message: o, sessionId: c, taskId: l, metadata: u } = e, { agentId: d, agentUrl: p, authProvider: m, proxy: f } = s, { isStreaming: I = !1, enableTokenStreaming: h = !1 } = t, A = c || r, g = Ze(p, d), i = await Ve(
545
545
  o,
546
546
  a,
547
547
  n
@@ -565,8 +565,8 @@ async function Y(e, t, s, a, n, r) {
565
565
  fullAgentUrl: g
566
566
  };
567
567
  }
568
- async function Ee(e, t, s = {}) {
569
- const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o } = t, { abortSignal: c } = s, { timeoutId: l, controller: u } = be(
568
+ async function Ee(e, s, t = {}) {
569
+ const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o } = s, { abortSignal: c } = t, { timeoutId: l, controller: u } = be(
570
570
  o,
571
571
  "request"
572
572
  ), d = c ? ke(u.signal, c) : u.signal;
@@ -593,12 +593,12 @@ async function Ee(e, t, s = {}) {
593
593
  Ae(p, l, "request");
594
594
  }
595
595
  }
596
- async function* Pe(e, t, s) {
596
+ async function* _e(e, s, t) {
597
597
  const { request: a, headers: n, fullAgentUrl: r } = e, {
598
598
  streamingTimeout: o = 6e4,
599
599
  abortSignal: c,
600
600
  enableTokenStreaming: l = !1
601
- } = s, { timeoutId: u, controller: d } = be(
601
+ } = t, { timeoutId: u, controller: d } = be(
602
602
  o,
603
603
  "streaming request"
604
604
  ), p = c ? ke(d.signal, c) : d.signal;
@@ -617,17 +617,17 @@ async function* Pe(e, t, s) {
617
617
  }
618
618
  }
619
619
  const st = 12e4;
620
- async function Z(e, t, s, a, n) {
620
+ async function Z(e, s, t, a, n) {
621
621
  if (e.getAbilities) {
622
622
  const r = await e.getAbilities();
623
623
  if (r.length > 0)
624
624
  for (const o of r) {
625
625
  const c = o.name.replace(/\//g, "__").replace(/-/g, "_");
626
- if (t === c || t === o.name) {
626
+ if (s === c || s === o.name) {
627
627
  if (o.callback)
628
628
  try {
629
629
  const l = {
630
- ...s,
630
+ ...t,
631
631
  ...a && { messageId: a }
632
632
  }, u = await o.callback(l);
633
633
  return {
@@ -654,7 +654,7 @@ async function Z(e, t, s, a, n) {
654
654
  try {
655
655
  return { result: await e.executeAbility(
656
656
  o.name,
657
- s
657
+ t
658
658
  ), returnToAgent: !0 };
659
659
  } catch (l) {
660
660
  return M(
@@ -677,25 +677,25 @@ async function Z(e, t, s, a, n) {
677
677
  }
678
678
  if (e.executeTool)
679
679
  return await e.executeTool(
680
- t,
681
680
  s,
681
+ t,
682
682
  a,
683
683
  n
684
684
  );
685
685
  throw new Error(
686
- `No handler found for tool: ${t}. Tool provider must implement executeTool for non-ability tools.`
686
+ `No handler found for tool: ${s}. Tool provider must implement executeTool for non-ability tools.`
687
687
  );
688
688
  }
689
689
  const ge = /* @__PURE__ */ new Map();
690
- async function at(e, t) {
691
- if (!e || !t || !e.getAvailableTools)
690
+ async function at(e, s) {
691
+ if (!e || !s || !e.getAvailableTools)
692
692
  return !1;
693
- const s = L(t);
694
- if (s.length === 0)
693
+ const t = L(s);
694
+ if (t.length === 0)
695
695
  return !1;
696
696
  try {
697
697
  const a = await e.getAvailableTools();
698
- for (const n of s)
698
+ for (const n of t)
699
699
  if (a.some(
700
700
  (o) => o.id === n.data.toolId
701
701
  ))
@@ -709,35 +709,35 @@ function nt() {
709
709
  ge.clear();
710
710
  }
711
711
  function ot(e) {
712
- return e.map((t) => {
713
- const s = t.data.toolCallId, a = ge.get(s);
712
+ return e.map((s) => {
713
+ const t = s.data.toolCallId, a = ge.get(t);
714
714
  if (a && a.resolvedValue !== null) {
715
715
  const n = a.resolvedValue;
716
716
  return n.error ? W(
717
- s,
718
- t.data.toolId,
717
+ t,
718
+ s.data.toolId,
719
719
  void 0,
720
720
  n.error
721
721
  ) : W(
722
- s,
723
- t.data.toolId,
722
+ t,
723
+ s.data.toolId,
724
724
  n
725
725
  );
726
726
  }
727
- return t;
727
+ return s;
728
728
  });
729
729
  }
730
- async function _e(e, t, s) {
730
+ async function Pe(e, s, t) {
731
731
  const a = [], n = [];
732
732
  let r = !1;
733
733
  for (const o of e) {
734
734
  const { toolCallId: c, toolId: l, arguments: u } = o.data;
735
735
  try {
736
736
  const d = await Z(
737
- t,
737
+ s,
738
738
  l,
739
739
  u,
740
- s,
740
+ t,
741
741
  c
742
742
  ), { result: p, returnToAgent: m, agentMessage: f } = de(d);
743
743
  m && (r = !0), f && n.push(G(f)), a.push(
@@ -761,52 +761,52 @@ async function _e(e, t, s) {
761
761
  return { results: a, shouldReturnToAgent: r, agentMessages: n };
762
762
  }
763
763
  function ye(e) {
764
- const t = [];
765
- for (const s of e)
766
- for (const a of s.parts)
767
- a.type === "text" ? t.push({
764
+ const s = [];
765
+ for (const t of e)
766
+ for (const a of t.parts)
767
+ a.type === "text" ? s.push({
768
768
  type: "data",
769
769
  data: {
770
- role: s.role,
770
+ role: t.role,
771
771
  text: a.text
772
772
  }
773
- }) : (a.type === "data" || a.type === "file") && t.push(a);
774
- return t;
773
+ }) : (a.type === "data" || a.type === "file") && s.push(a);
774
+ return s;
775
775
  }
776
- async function ae(e, t, s, a, n, r, o) {
776
+ async function ae(e, s, t, a, n, r, o) {
777
777
  const l = await Y(
778
778
  {
779
- message: t,
779
+ message: s,
780
780
  taskId: e,
781
781
  sessionId: void 0
782
782
  // Use task's session
783
783
  },
784
- s,
784
+ t,
785
785
  { isStreaming: !1 },
786
786
  a,
787
787
  n,
788
788
  r
789
789
  );
790
- return await Ee(l, s, {
790
+ return await Ee(l, t, {
791
791
  abortSignal: o
792
792
  });
793
793
  }
794
- async function Ie(e, t, s, a, n, r, o, c, l = []) {
794
+ async function Ie(e, s, t, a, n, r, o, c, l = []) {
795
795
  const u = {
796
- message: t,
796
+ message: s,
797
797
  taskId: e,
798
798
  sessionId: r
799
799
  // Use the provided sessionId to maintain conversation continuity
800
800
  }, d = c || { isStreaming: !0 }, p = await Y(
801
801
  u,
802
- s,
802
+ t,
803
803
  {
804
804
  ...d
805
805
  },
806
806
  a,
807
807
  n,
808
808
  r
809
- ), m = Pe(p, s, {
809
+ ), m = _e(p, t, {
810
810
  ...d,
811
811
  abortSignal: o
812
812
  });
@@ -814,7 +814,7 @@ async function Ie(e, t, s, a, n, r, o, c, l = []) {
814
814
  m,
815
815
  a,
816
816
  n,
817
- s,
817
+ t,
818
818
  r,
819
819
  !0,
820
820
  // withHistory
@@ -825,20 +825,20 @@ async function Ie(e, t, s, a, n, r, o, c, l = []) {
825
825
  // Pass through the same request options
826
826
  );
827
827
  }
828
- async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
828
+ async function* Oe(e, s, t, a, n, r = !0, o = [], c, l) {
829
829
  var u, d, p, m, f, I, h, A, g, i, T, x;
830
830
  for await (const w of e) {
831
- if (w.sessionId && !n && (n = w.sessionId), yield w, w.status.state === "running" && w.status.message && t && await at(
832
- t,
831
+ if (w.sessionId && !n && (n = w.sessionId), yield w, w.status.state === "running" && w.status.message && s && await at(
832
+ s,
833
833
  w.status.message
834
834
  )) {
835
- const P = L(
835
+ const _ = L(
836
836
  w.status.message
837
837
  );
838
- for (const O of P) {
838
+ for (const O of _) {
839
839
  const { toolCallId: $, toolId: S, arguments: y } = O.data;
840
840
  Z(
841
- t,
841
+ s,
842
842
  S,
843
843
  y,
844
844
  (d = (u = w.status) == null ? void 0 : u.message) == null ? void 0 : d.messageId,
@@ -854,7 +854,7 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
854
854
  message: {
855
855
  role: "agent",
856
856
  kind: "message",
857
- parts: P,
857
+ parts: _,
858
858
  messageId: N()
859
859
  }
860
860
  },
@@ -862,15 +862,15 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
862
862
  text: ""
863
863
  };
864
864
  }
865
- if (w.status.state === "input-required" && w.status.message && t) {
866
- const P = L(
865
+ if (w.status.state === "input-required" && w.status.message && s) {
866
+ const _ = L(
867
867
  w.status.message
868
868
  );
869
- if (P.length > 0) {
869
+ if (_.length > 0) {
870
870
  const O = [];
871
871
  let $ = !1;
872
872
  const S = [], y = [];
873
- for (const C of P) {
873
+ for (const C of _) {
874
874
  const {
875
875
  toolCallId: v,
876
876
  toolId: R,
@@ -878,7 +878,7 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
878
878
  } = C.data;
879
879
  try {
880
880
  const b = await Z(
881
- t,
881
+ s,
882
882
  R,
883
883
  k,
884
884
  (m = (p = w.status) == null ? void 0 : p.message) == null ? void 0 : m.messageId,
@@ -887,14 +887,14 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
887
887
  if (U && ($ = !0), D && y.push(
888
888
  G(D)
889
889
  ), E.result instanceof Promise) {
890
- const _ = E.result, J = {
891
- promise: _,
890
+ const P = E.result, J = {
891
+ promise: P,
892
892
  resolvedValue: null
893
893
  };
894
894
  ge.set(
895
895
  v,
896
896
  J
897
- ), _.then((H) => {
897
+ ), P.then((H) => {
898
898
  J.resolvedValue = H;
899
899
  }).catch((H) => {
900
900
  M(
@@ -946,8 +946,8 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
946
946
  w.id,
947
947
  v,
948
948
  a,
949
- t,
950
949
  s,
950
+ t,
951
951
  n,
952
952
  c,
953
953
  l,
@@ -980,9 +980,9 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
980
980
  const {
981
981
  results: U,
982
982
  shouldReturnToAgent: D
983
- } = await _e(
983
+ } = await Pe(
984
984
  b,
985
- t,
985
+ s,
986
986
  (g = (A = E.status) == null ? void 0 : A.message) == null ? void 0 : g.messageId
987
987
  );
988
988
  if (U.length > 0 && (yield {
@@ -1002,15 +1002,15 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
1002
1002
  }), D) {
1003
1003
  const q = r ? ye(
1004
1004
  o
1005
- ) : [], _ = X(
1005
+ ) : [], P = X(
1006
1006
  U,
1007
1007
  q
1008
1008
  ), J = await Ie(
1009
1009
  E.id,
1010
- _,
1010
+ P,
1011
1011
  a,
1012
- t,
1013
1012
  s,
1013
+ t,
1014
1014
  n,
1015
1015
  c,
1016
1016
  l,
@@ -1082,8 +1082,8 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
1082
1082
  }
1083
1083
  function rt(e) {
1084
1084
  const {
1085
- agentId: t,
1086
- agentUrl: s,
1085
+ agentId: s,
1086
+ agentUrl: t,
1087
1087
  authProvider: a,
1088
1088
  defaultSessionId: n,
1089
1089
  timeout: r = st,
@@ -1091,8 +1091,8 @@ function rt(e) {
1091
1091
  contextProvider: c,
1092
1092
  enableStreaming: l = !1
1093
1093
  } = e, u = {
1094
- agentId: t,
1095
- agentUrl: s,
1094
+ agentId: s,
1095
+ agentUrl: t,
1096
1096
  authProvider: a,
1097
1097
  timeout: r
1098
1098
  };
@@ -1123,7 +1123,7 @@ function rt(e) {
1123
1123
  break;
1124
1124
  A.push(...x);
1125
1125
  const w = [];
1126
- let P = !1;
1126
+ let _ = !1;
1127
1127
  for (const O of x) {
1128
1128
  const {
1129
1129
  toolCallId: $,
@@ -1136,7 +1136,7 @@ function rt(e) {
1136
1136
  S,
1137
1137
  y
1138
1138
  ), { result: v, returnToAgent: R, agentMessage: k } = de(C);
1139
- R && (P = !0), k && g.push(
1139
+ R && (_ = !0), k && g.push(
1140
1140
  G(k)
1141
1141
  );
1142
1142
  const b = W(
@@ -1155,7 +1155,7 @@ function rt(e) {
1155
1155
  w.push(v), A.push(v);
1156
1156
  }
1157
1157
  }
1158
- if (f.push(h.status.message), P) {
1158
+ if (f.push(h.status.message), _) {
1159
1159
  const O = X(w);
1160
1160
  h = await ae(
1161
1161
  h.id,
@@ -1183,7 +1183,7 @@ function rt(e) {
1183
1183
  };
1184
1184
  }
1185
1185
  if (g.length > 0) {
1186
- const x = g.map((P) => j(P)).join(" "), w = G(x);
1186
+ const x = g.map((_) => j(_)).join(" "), w = G(x);
1187
1187
  return {
1188
1188
  ...h,
1189
1189
  // Keep the enhanced message with tool results
@@ -1221,7 +1221,7 @@ function rt(e) {
1221
1221
  o,
1222
1222
  c,
1223
1223
  I
1224
- ), i = Pe(
1224
+ ), i = _e(
1225
1225
  g,
1226
1226
  u,
1227
1227
  {
@@ -1264,7 +1264,7 @@ function rt(e) {
1264
1264
  );
1265
1265
  if (g.length === 0)
1266
1266
  break;
1267
- const { results: i, shouldReturnToAgent: T } = await _e(g, o);
1267
+ const { results: i, shouldReturnToAgent: T } = await Pe(g, o);
1268
1268
  if (T) {
1269
1269
  const x = X(i);
1270
1270
  h = await ae(
@@ -1297,17 +1297,17 @@ function rt(e) {
1297
1297
  };
1298
1298
  }
1299
1299
  function it(e) {
1300
- const t = [];
1300
+ const s = [];
1301
1301
  if (e.content) {
1302
1302
  const r = {
1303
1303
  type: "text",
1304
1304
  text: e.content
1305
1305
  };
1306
- t.push(r);
1306
+ s.push(r);
1307
1307
  }
1308
- const s = e.context;
1309
- if (s && !Array.isArray(s) && Array.isArray(s.file_parts)) {
1310
- for (const r of s.file_parts)
1308
+ const t = e.context;
1309
+ if (t && !Array.isArray(t) && Array.isArray(t.file_parts)) {
1310
+ for (const r of t.file_parts)
1311
1311
  if (r != null && r.uri) {
1312
1312
  const o = {
1313
1313
  type: "file",
@@ -1318,7 +1318,7 @@ function it(e) {
1318
1318
  // Pass attachment ID in metadata if available
1319
1319
  metadata: r.id ? { id: r.id } : void 0
1320
1320
  };
1321
- t.push(o);
1321
+ s.push(o);
1322
1322
  }
1323
1323
  }
1324
1324
  const a = e.role === "user" ? "user" : "agent", n = e.ts ? e.ts * 1e3 : (/* @__PURE__ */ new Date(
@@ -1327,7 +1327,7 @@ function it(e) {
1327
1327
  return {
1328
1328
  role: a,
1329
1329
  kind: "message",
1330
- parts: t,
1330
+ parts: s,
1331
1331
  messageId: N(),
1332
1332
  metadata: {
1333
1333
  timestamp: n,
@@ -1345,9 +1345,9 @@ function lt(e) {
1345
1345
  return !1;
1346
1346
  }
1347
1347
  }
1348
- function ct(e, t = !1) {
1348
+ function ct(e, s = !1) {
1349
1349
  var r, o, c, l, u, d;
1350
- const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!t || lt(p)) : !0).map(it), n = {
1350
+ const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!s || lt(p)) : !0).map(it), n = {
1351
1351
  currentPage: ((r = e.metadata) == null ? void 0 : r.current_page) ?? 1,
1352
1352
  itemsPerPage: ((o = e.metadata) == null ? void 0 : o.items_per_page) ?? 10,
1353
1353
  totalPages: ((c = e.metadata) == null ? void 0 : c.total_pages) ?? 1,
@@ -1362,18 +1362,18 @@ function ct(e, t = !1) {
1362
1362
  };
1363
1363
  }
1364
1364
  class V extends Error {
1365
- constructor(t, s, a) {
1366
- super(t), this.statusCode = s, this.details = a, this.name = "ServerConversationError";
1365
+ constructor(s, t, a) {
1366
+ super(s), this.statusCode = t, this.details = a, this.name = "ServerConversationError";
1367
1367
  }
1368
1368
  }
1369
1369
  const fe = "https://public-api.wordpress.com";
1370
- async function le(e, t, s = 1, a = 50, n = !1) {
1371
- const { botId: r, apiBaseUrl: o = fe, authProvider: c } = t;
1370
+ async function le(e, s, t = 1, a = 50, n = !1) {
1371
+ const { botId: r, apiBaseUrl: o = fe, authProvider: c } = s;
1372
1372
  if (!e || !r)
1373
1373
  throw new Error(
1374
1374
  "chatId and botId are required to load conversation from server"
1375
1375
  );
1376
- const l = Math.max(1, Math.min(s, 100)), u = Math.max(1, Math.min(a, 100)), d = new URL(
1376
+ const l = Math.max(1, Math.min(t, 100)), u = Math.max(1, Math.min(a, 100)), d = new URL(
1377
1377
  `${o}/wpcom/v2/odie/chat/${encodeURIComponent(
1378
1378
  r
1379
1379
  )}/${encodeURIComponent(e)}`
@@ -1428,15 +1428,15 @@ async function le(e, t, s = 1, a = 50, n = !1) {
1428
1428
  throw M("Network error loading conversation: %O", p), m;
1429
1429
  }
1430
1430
  }
1431
- async function Kt(e, t, s = !1) {
1432
- const { apiBaseUrl: a = fe, authProvider: n } = t, r = new URL(
1431
+ async function Kt(e, s, t = !1) {
1432
+ const { apiBaseUrl: a = fe, authProvider: n } = s, r = new URL(
1433
1433
  `${a}/wpcom/v2/odie/conversations/${encodeURIComponent(
1434
1434
  e
1435
1435
  )}`
1436
1436
  );
1437
1437
  r.searchParams.set(
1438
1438
  "truncation_method",
1439
- s ? "first_message" : "last_message"
1439
+ t ? "first_message" : "last_message"
1440
1440
  ), M("Listing conversations from server for bot: %s", e);
1441
1441
  try {
1442
1442
  const o = {
@@ -1471,10 +1471,10 @@ async function Kt(e, t, s = !1) {
1471
1471
  throw M("Network error listing conversations: %O", o), c;
1472
1472
  }
1473
1473
  }
1474
- async function Lt(e, t, s = 10, a = !1) {
1474
+ async function Lt(e, s, t = 10, a = !1) {
1475
1475
  const n = await le(
1476
1476
  e,
1477
- t,
1477
+ s,
1478
1478
  1,
1479
1479
  50,
1480
1480
  a
@@ -1483,11 +1483,11 @@ async function Lt(e, t, s = 10, a = !1) {
1483
1483
  return n;
1484
1484
  const r = Math.min(
1485
1485
  n.pagination.totalPages,
1486
- s
1486
+ t
1487
1487
  ), o = [...n.messages], c = [];
1488
1488
  for (let l = 2; l <= r; l++)
1489
1489
  c.push(
1490
- le(e, t, l, 50, a)
1490
+ le(e, s, l, 50, a)
1491
1491
  );
1492
1492
  try {
1493
1493
  const l = await Promise.all(c);
@@ -1513,10 +1513,10 @@ async function Lt(e, t, s = 10, a = !1) {
1513
1513
  const me = "a8c_agenttic_conversation_history";
1514
1514
  function ut(e) {
1515
1515
  var p, m;
1516
- const t = e.parts.filter(
1516
+ const s = e.parts.filter(
1517
1517
  (f) => f.type === "text"
1518
- ), s = t.map((f) => f.text).join(`
1519
- `), a = t.some(
1518
+ ), t = s.map((f) => f.text).join(`
1519
+ `), a = s.some(
1520
1520
  (f) => {
1521
1521
  var I;
1522
1522
  return ((I = f.metadata) == null ? void 0 : I.contentType) === "context";
@@ -1540,7 +1540,7 @@ function ut(e) {
1540
1540
  })), l = n.length > 0 || r.length > 0 ? "agent" : e.role, u = ((p = e.metadata) == null ? void 0 : p.timestamp) ?? Date.now(), d = ((m = e.metadata) == null ? void 0 : m.archived) ?? void 0;
1541
1541
  return {
1542
1542
  role: l,
1543
- content: s || "(No text content)",
1543
+ content: t || "(No text content)",
1544
1544
  timestamp: u,
1545
1545
  ...d !== void 0 && { archived: d },
1546
1546
  ...a && { contentType: a },
@@ -1550,8 +1550,8 @@ function ut(e) {
1550
1550
  };
1551
1551
  }
1552
1552
  function dt(e) {
1553
- const t = [];
1554
- if (e.content && e.content !== "(No text content)" && t.push({
1553
+ const s = [];
1554
+ if (e.content && e.content !== "(No text content)" && s.push({
1555
1555
  type: "text",
1556
1556
  text: e.content,
1557
1557
  ...e.contentType && {
@@ -1560,39 +1560,39 @@ function dt(e) {
1560
1560
  }
1561
1561
  }
1562
1562
  }), e.files)
1563
- for (const s of e.files)
1564
- t.push({
1563
+ for (const t of e.files)
1564
+ s.push({
1565
1565
  type: "file",
1566
1566
  file: {
1567
- name: s.name,
1568
- mimeType: s.mimeType,
1569
- uri: s.uri
1567
+ name: t.name,
1568
+ mimeType: t.mimeType,
1569
+ uri: t.uri
1570
1570
  }
1571
1571
  });
1572
1572
  if (e.toolCalls)
1573
- for (const s of e.toolCalls)
1574
- t.push({
1573
+ for (const t of e.toolCalls)
1574
+ s.push({
1575
1575
  type: "data",
1576
1576
  data: {
1577
- toolCallId: s.toolCallId,
1578
- toolId: s.toolId,
1579
- arguments: s.arguments
1577
+ toolCallId: t.toolCallId,
1578
+ toolId: t.toolId,
1579
+ arguments: t.arguments
1580
1580
  }
1581
1581
  });
1582
1582
  if (e.toolResults)
1583
- for (const s of e.toolResults)
1584
- t.push({
1583
+ for (const t of e.toolResults)
1584
+ s.push({
1585
1585
  type: "data",
1586
1586
  data: {
1587
- toolCallId: s.toolCallId,
1588
- result: s.result,
1589
- ...s.error && { error: s.error }
1587
+ toolCallId: t.toolCallId,
1588
+ result: t.result,
1589
+ ...t.error && { error: t.error }
1590
1590
  }
1591
1591
  });
1592
1592
  return {
1593
1593
  role: e.role,
1594
1594
  kind: "message",
1595
- parts: t,
1595
+ parts: s,
1596
1596
  messageId: N(),
1597
1597
  metadata: {
1598
1598
  timestamp: e.timestamp,
@@ -1604,9 +1604,9 @@ function dt(e) {
1604
1604
  };
1605
1605
  }
1606
1606
  const B = /* @__PURE__ */ new Map(), gt = 50;
1607
- async function ft(e, t, s) {
1608
- const a = s || e;
1609
- if (B.set(a, [...t]), B.size > gt) {
1607
+ async function ft(e, s, t) {
1608
+ const a = t || e;
1609
+ if (B.set(a, [...s]), B.size > gt) {
1610
1610
  const n = B.keys().next().value;
1611
1611
  n && B.delete(n);
1612
1612
  }
@@ -1614,7 +1614,7 @@ async function ft(e, t, s) {
1614
1614
  try {
1615
1615
  const n = {
1616
1616
  storageKey: a,
1617
- messages: t.map(ut),
1617
+ messages: s.map(ut),
1618
1618
  lastUpdated: Date.now()
1619
1619
  };
1620
1620
  sessionStorage.setItem(
@@ -1629,22 +1629,22 @@ async function ft(e, t, s) {
1629
1629
  );
1630
1630
  }
1631
1631
  }
1632
- async function mt(e, t, s) {
1633
- return s != null && s.odieBotId ? pt(e, s) : ht(
1632
+ async function mt(e, s, t) {
1633
+ return t != null && t.odieBotId ? pt(e, t) : ht(
1634
1634
  e,
1635
- t
1635
+ s
1636
1636
  );
1637
1637
  }
1638
- async function pt(e, t) {
1639
- const { odieBotId: s, authProvider: a } = t;
1640
- if (!s)
1638
+ async function pt(e, s) {
1639
+ const { odieBotId: t, authProvider: a } = s;
1640
+ if (!t)
1641
1641
  throw new Error("odieBotId is required for server storage");
1642
1642
  const n = fe;
1643
1643
  try {
1644
1644
  const o = await le(
1645
1645
  e,
1646
1646
  {
1647
- botId: s,
1647
+ botId: t,
1648
1648
  apiBaseUrl: n,
1649
1649
  authProvider: a
1650
1650
  },
@@ -1665,49 +1665,49 @@ async function pt(e, t) {
1665
1665
  throw M("Failed to load conversation from server: %O", r), r;
1666
1666
  }
1667
1667
  }
1668
- async function ht(e, t) {
1669
- const s = t || e;
1670
- if (B.has(s))
1668
+ async function ht(e, s) {
1669
+ const t = s || e;
1670
+ if (B.has(t))
1671
1671
  return {
1672
- messages: [...B.get(s)]
1672
+ messages: [...B.get(t)]
1673
1673
  };
1674
1674
  if (typeof sessionStorage > "u")
1675
1675
  return { messages: [] };
1676
1676
  try {
1677
1677
  const a = sessionStorage.getItem(
1678
- `${me}_${s}`
1678
+ `${me}_${t}`
1679
1679
  );
1680
1680
  if (a) {
1681
1681
  const r = JSON.parse(a).messages.map(dt);
1682
- return B.set(s, r), { messages: [...r] };
1682
+ return B.set(t, r), { messages: [...r] };
1683
1683
  }
1684
1684
  } catch (a) {
1685
1685
  M(
1686
1686
  "Failed to load conversation from sessionStorage for key %s: %O",
1687
- s,
1687
+ t,
1688
1688
  a
1689
1689
  );
1690
1690
  }
1691
1691
  return { messages: [] };
1692
1692
  }
1693
- async function yt(e, t) {
1694
- const s = t || e;
1695
- if (B.delete(s), !(typeof sessionStorage > "u"))
1693
+ async function yt(e, s) {
1694
+ const t = s || e;
1695
+ if (B.delete(t), !(typeof sessionStorage > "u"))
1696
1696
  try {
1697
- sessionStorage.removeItem(`${me}_${s}`);
1697
+ sessionStorage.removeItem(`${me}_${t}`);
1698
1698
  } catch (a) {
1699
1699
  M(
1700
1700
  "Failed to clear conversation from sessionStorage for key %s: %O",
1701
- s,
1701
+ t,
1702
1702
  a
1703
1703
  );
1704
1704
  }
1705
1705
  }
1706
1706
  function z(e) {
1707
- const t = e.parts.filter((s) => s.type === "text" ? !0 : s.type === "data" ? "role" in s.data && "text" in s.data ? !1 : "toolCallId" in s.data && "arguments" in s.data || "toolCallId" in s.data && "result" in s.data : !0);
1707
+ 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 || "toolCallId" in t.data && "result" in t.data) : !0);
1708
1708
  return {
1709
1709
  ...e,
1710
- parts: t,
1710
+ parts: s,
1711
1711
  // Preserve metadata if it exists, otherwise add timestamp
1712
1712
  metadata: e.metadata || {
1713
1713
  timestamp: Date.now()
@@ -1715,35 +1715,35 @@ function z(e) {
1715
1715
  };
1716
1716
  }
1717
1717
  function It(e) {
1718
- const t = [];
1719
- for (const s of e)
1720
- for (const a of s.parts)
1718
+ const s = [];
1719
+ for (const t of e)
1720
+ for (const a of t.parts)
1721
1721
  if (a.type === "text")
1722
- t.push({
1722
+ s.push({
1723
1723
  type: "data",
1724
1724
  data: {
1725
- role: s.role,
1725
+ role: t.role,
1726
1726
  text: a.text
1727
1727
  }
1728
1728
  });
1729
1729
  else if (a.type === "file")
1730
- t.push(a);
1730
+ s.push(a);
1731
1731
  else if (a.type === "data") {
1732
1732
  if ("role" in a.data && "text" in a.data)
1733
1733
  continue;
1734
1734
  if ("toolCallId" in a.data && "arguments" in a.data) {
1735
- t.push(a);
1735
+ s.push(a);
1736
1736
  continue;
1737
1737
  }
1738
1738
  if ("toolCallId" in a.data && "result" in a.data) {
1739
- t.push(a);
1739
+ s.push(a);
1740
1740
  continue;
1741
1741
  }
1742
1742
  }
1743
- return t;
1743
+ return s;
1744
1744
  }
1745
- function we(e, t = [], s = []) {
1746
- const a = It(t), n = s.map((r) => {
1745
+ function we(e, s = [], t = []) {
1746
+ const a = It(s), n = t.map((r) => {
1747
1747
  const o = typeof r == "string" ? r : r.url, c = typeof r == "object" ? r.metadata : void 0, l = (c == null ? void 0 : c.fileType) || "image/jpeg";
1748
1748
  return {
1749
1749
  type: "file",
@@ -1774,67 +1774,67 @@ function we(e, t = [], s = []) {
1774
1774
  }
1775
1775
  function wt(e) {
1776
1776
  return e != null && e.parts ? e.parts.filter(
1777
- (t) => t.type === "data" && "toolCallId" in t.data && "result" in t.data
1777
+ (s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
1778
1778
  ) : [];
1779
1779
  }
1780
- function ne(e, t) {
1780
+ function ne(e, s) {
1781
1781
  if (typeof localStorage > "u") {
1782
1782
  K("localStorage not available, cannot update session ID");
1783
1783
  return;
1784
1784
  }
1785
1785
  try {
1786
- const s = localStorage.getItem(e);
1787
- if (s) {
1788
- const a = JSON.parse(s), n = a.sessionId;
1789
- a.sessionId = t, localStorage.setItem(e, JSON.stringify(a)), K(
1786
+ const t = localStorage.getItem(e);
1787
+ if (t) {
1788
+ const a = JSON.parse(t), n = a.sessionId;
1789
+ a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)), K(
1790
1790
  "Updated localStorage[%s] session ID: %s -> %s",
1791
1791
  e,
1792
1792
  n,
1793
- t
1793
+ s
1794
1794
  );
1795
1795
  } else {
1796
1796
  const a = {
1797
- sessionId: t,
1797
+ sessionId: s,
1798
1798
  timestamp: Date.now()
1799
1799
  };
1800
1800
  localStorage.setItem(e, JSON.stringify(a)), K(
1801
1801
  "Created new session in localStorage[%s]: %s",
1802
1802
  e,
1803
- t
1803
+ s
1804
1804
  );
1805
1805
  }
1806
- } catch (s) {
1806
+ } catch (t) {
1807
1807
  K(
1808
1808
  "Failed to update localStorage sessionId to %s: %O",
1809
- t,
1810
- s
1809
+ s,
1810
+ t
1811
1811
  );
1812
1812
  }
1813
1813
  }
1814
1814
  async function Tt(e) {
1815
- const t = [];
1816
- for (const s of e)
1817
- if (s.parts && Array.isArray(s.parts))
1818
- if (s.parts.some(
1815
+ const s = [];
1816
+ for (const t of e)
1817
+ if (t.parts && Array.isArray(t.parts))
1818
+ if (t.parts.some(
1819
1819
  (n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
1820
1820
  )) {
1821
1821
  const n = ot(
1822
- s.parts
1822
+ t.parts
1823
1823
  );
1824
- t.push({
1825
- ...s,
1824
+ s.push({
1825
+ ...t,
1826
1826
  parts: n
1827
1827
  });
1828
1828
  } else
1829
- t.push(s);
1829
+ s.push(t);
1830
1830
  else
1831
- t.push(s);
1832
- return nt(), t;
1831
+ s.push(t);
1832
+ return nt(), s;
1833
1833
  }
1834
1834
  function St() {
1835
1835
  const e = /* @__PURE__ */ new Map();
1836
- async function t(s, a) {
1837
- const n = e.get(s);
1836
+ async function s(t, a) {
1837
+ const n = e.get(t);
1838
1838
  if (n != null && n.sessionId)
1839
1839
  try {
1840
1840
  await ft(
@@ -1844,15 +1844,15 @@ function St() {
1844
1844
  );
1845
1845
  } catch (r) {
1846
1846
  K(
1847
- `Failed to persist conversation history for agent ${s}:`,
1847
+ `Failed to persist conversation history for agent ${t}:`,
1848
1848
  r
1849
1849
  );
1850
1850
  }
1851
1851
  }
1852
1852
  return {
1853
- async createAgent(s, a) {
1854
- if (e.has(s))
1855
- return e.get(s).client;
1853
+ async createAgent(t, a) {
1854
+ if (e.has(t))
1855
+ return e.get(t).client;
1856
1856
  const n = rt(a), r = a.sessionId || null, o = a.conversationStorageKey, c = a.sessionIdStorageKey, l = {
1857
1857
  odieBotId: a.odieBotId,
1858
1858
  authProvider: a.authProvider
@@ -1867,7 +1867,7 @@ function St() {
1867
1867
  )).messages;
1868
1868
  } catch (p) {
1869
1869
  K(
1870
- `Failed to load conversation history for agent ${s} with session ${r}:`,
1870
+ `Failed to load conversation history for agent ${t} with session ${r}:`,
1871
1871
  p
1872
1872
  );
1873
1873
  }
@@ -1880,23 +1880,23 @@ function St() {
1880
1880
  conversationHistory: u,
1881
1881
  currentAbortController: null
1882
1882
  };
1883
- return e.set(s, d), n;
1883
+ return e.set(t, d), n;
1884
1884
  },
1885
- getAgent(s) {
1886
- const a = e.get(s);
1885
+ getAgent(t) {
1886
+ const a = e.get(t);
1887
1887
  return (a == null ? void 0 : a.client) || null;
1888
1888
  },
1889
- hasAgent(s) {
1890
- return e.has(s);
1889
+ hasAgent(t) {
1890
+ return e.has(t);
1891
1891
  },
1892
- removeAgent(s) {
1893
- return e.delete(s);
1892
+ removeAgent(t) {
1893
+ return e.delete(t);
1894
1894
  },
1895
- async sendMessage(s, a, n = {}) {
1895
+ async sendMessage(t, a, n = {}) {
1896
1896
  var A;
1897
- const r = e.get(s);
1897
+ const r = e.get(t);
1898
1898
  if (!r)
1899
- throw new Error(`Agent with key "${s}" not found`);
1899
+ throw new Error(`Agent with key "${t}" not found`);
1900
1900
  const { withHistory: o = !0, sessionId: c, ...l } = n, { client: u, conversationHistory: d } = r, p = n.message || we(
1901
1901
  a,
1902
1902
  d,
@@ -1952,16 +1952,16 @@ function St() {
1952
1952
  g
1953
1953
  ];
1954
1954
  }
1955
- return r.conversationHistory = h, o && await t(
1956
- s,
1955
+ return r.conversationHistory = h, o && await s(
1956
+ t,
1957
1957
  h
1958
1958
  ), m;
1959
1959
  },
1960
- async *sendMessageStream(s, a, n = {}) {
1961
- var T, x, w, P, O, $;
1962
- const r = e.get(s);
1960
+ async *sendMessageStream(t, a, n = {}) {
1961
+ var T, x, w, _, O, $;
1962
+ const r = e.get(t);
1963
1963
  if (!r)
1964
- throw new Error(`Agent with key "${s}" not found`);
1964
+ throw new Error(`Agent with key "${t}" not found`);
1965
1965
  const {
1966
1966
  withHistory: o = !0,
1967
1967
  abortSignal: c,
@@ -1979,8 +1979,8 @@ function St() {
1979
1979
  const A = await Tt(
1980
1980
  I
1981
1981
  );
1982
- r.conversationHistory = A, I = A, o && await t(
1983
- s,
1982
+ r.conversationHistory = A, I = A, o && await s(
1983
+ t,
1984
1984
  A
1985
1985
  );
1986
1986
  const g = n.message || we(
@@ -2023,8 +2023,8 @@ function St() {
2023
2023
  I = [
2024
2024
  ...I,
2025
2025
  i
2026
- ], r.conversationHistory = I, o && await t(
2027
- s,
2026
+ ], r.conversationHistory = I, o && await s(
2027
+ t,
2028
2028
  I
2029
2029
  );
2030
2030
  for await (const S of p.sendMessageStream({
@@ -2059,12 +2059,12 @@ function St() {
2059
2059
  I = [
2060
2060
  ...I,
2061
2061
  C
2062
- ], r.conversationHistory = I, o && await t(
2063
- s,
2062
+ ], r.conversationHistory = I, o && await s(
2063
+ t,
2064
2064
  I
2065
2065
  );
2066
2066
  }
2067
- if (((w = S.status) == null ? void 0 : w.state) === "working" && ((P = S.status) != null && P.message) && !S.final) {
2067
+ if (((w = S.status) == null ? void 0 : w.state) === "working" && ((_ = S.status) != null && _.message) && !S.final) {
2068
2068
  const C = wt(
2069
2069
  S.status.message
2070
2070
  ).filter(
@@ -2082,8 +2082,8 @@ function St() {
2082
2082
  I = [
2083
2083
  ...I,
2084
2084
  z(v)
2085
- ], r.conversationHistory = I, o && await t(
2086
- s,
2085
+ ], r.conversationHistory = I, o && await s(
2086
+ t,
2087
2087
  I
2088
2088
  );
2089
2089
  }
@@ -2096,8 +2096,8 @@ function St() {
2096
2096
  ), I = [
2097
2097
  ...I,
2098
2098
  y
2099
- ], r.conversationHistory = I, o && await t(
2100
- s,
2099
+ ], r.conversationHistory = I, o && await s(
2100
+ t,
2101
2101
  I
2102
2102
  ));
2103
2103
  }
@@ -2105,40 +2105,40 @@ function St() {
2105
2105
  }
2106
2106
  r.currentAbortController = null;
2107
2107
  },
2108
- async resetConversation(s) {
2109
- const a = e.get(s);
2108
+ async resetConversation(t) {
2109
+ const a = e.get(t);
2110
2110
  if (!a)
2111
- throw new Error(`Agent with key "${s}" not found`);
2111
+ throw new Error(`Agent with key "${t}" not found`);
2112
2112
  a.conversationHistory = [], a.sessionId && await yt(
2113
2113
  a.sessionId,
2114
2114
  a.conversationStorageKey
2115
2115
  );
2116
2116
  },
2117
- async replaceMessages(s, a) {
2118
- const n = e.get(s);
2117
+ async replaceMessages(t, a) {
2118
+ const n = e.get(t);
2119
2119
  if (!n)
2120
- throw new Error(`Agent with key "${s}" not found`);
2121
- n.conversationHistory = [...a], n.sessionId && await t(s, a);
2120
+ throw new Error(`Agent with key "${t}" not found`);
2121
+ n.conversationHistory = [...a], n.sessionId && await s(t, a);
2122
2122
  },
2123
- getConversationHistory(s) {
2124
- const a = e.get(s);
2123
+ getConversationHistory(t) {
2124
+ const a = e.get(t);
2125
2125
  if (!a)
2126
- throw new Error(`Agent with key "${s}" not found`);
2126
+ throw new Error(`Agent with key "${t}" not found`);
2127
2127
  return [...a.conversationHistory];
2128
2128
  },
2129
- updateSessionId(s, a) {
2130
- const n = e.get(s);
2129
+ updateSessionId(t, a) {
2130
+ const n = e.get(t);
2131
2131
  if (!n)
2132
- throw new Error(`Agent with key "${s}" not found`);
2132
+ throw new Error(`Agent with key "${t}" not found`);
2133
2133
  n.sessionId = a, n.sessionIdStorageKey && ne(
2134
2134
  n.sessionIdStorageKey,
2135
2135
  a
2136
2136
  );
2137
2137
  },
2138
- abortCurrentRequest(s) {
2139
- const a = e.get(s);
2138
+ abortCurrentRequest(t) {
2139
+ const a = e.get(t);
2140
2140
  if (!a)
2141
- throw new Error(`Agent with key "${s}" not found`);
2141
+ throw new Error(`Agent with key "${t}" not found`);
2142
2142
  a.currentAbortController && (a.currentAbortController.abort(), a.currentAbortController = null);
2143
2143
  },
2144
2144
  clear() {
@@ -2151,9 +2151,9 @@ function Q() {
2151
2151
  return vt;
2152
2152
  }
2153
2153
  function Mt() {
2154
- const [e, t] = ve([]), s = F(
2154
+ const [e, s] = ve([]), t = F(
2155
2155
  (r) => {
2156
- t((o) => {
2156
+ s((o) => {
2157
2157
  const c = o.findIndex(
2158
2158
  (l) => l.id === r.id
2159
2159
  );
@@ -2166,19 +2166,19 @@ function Mt() {
2166
2166
  },
2167
2167
  []
2168
2168
  ), a = F((r) => {
2169
- t((o) => o.filter((c) => c.id !== r));
2169
+ s((o) => o.filter((c) => c.id !== r));
2170
2170
  }, []), n = F(() => {
2171
- t([]);
2171
+ s([]);
2172
2172
  }, []);
2173
2173
  return {
2174
- registerMessageActions: s,
2174
+ registerMessageActions: t,
2175
2175
  unregisterMessageActions: a,
2176
2176
  clearAllMessageActions: n,
2177
2177
  registrations: e
2178
2178
  };
2179
2179
  }
2180
- function xt(e, t) {
2181
- return t.flatMap((n) => typeof n.actions == "function" ? n.actions(e) : n.actions).filter((n) => !(n.condition && !n.condition(e))).map((n) => ({
2180
+ function xt(e, s) {
2181
+ return s.flatMap((n) => typeof n.actions == "function" ? n.actions(e) : n.actions).filter((n) => !(n.condition && !n.condition(e))).map((n) => ({
2182
2182
  id: n.id,
2183
2183
  label: n.label,
2184
2184
  icon: n.icon,
@@ -2189,13 +2189,13 @@ function xt(e, t) {
2189
2189
  showLabel: n.showLabel
2190
2190
  }));
2191
2191
  }
2192
- const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t = "40%") => ({
2192
+ const oe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ne = (e, s = "40%") => ({
2193
2193
  type: "component",
2194
2194
  component: () => qe.createElement("img", {
2195
2195
  src: e,
2196
2196
  alt: "Uploaded image",
2197
2197
  style: {
2198
- maxWidth: t,
2198
+ maxWidth: s,
2199
2199
  height: "auto",
2200
2200
  borderRadius: "8px",
2201
2201
  marginTop: "8px",
@@ -2203,7 +2203,7 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
2203
2203
  display: "inline-block"
2204
2204
  }
2205
2205
  })
2206
- }), re = (e, t = []) => {
2206
+ }), re = (e, s = []) => {
2207
2207
  var o, c;
2208
2208
  if (e.parts.some((l) => {
2209
2209
  if (l.type === "data") {
@@ -2249,10 +2249,10 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
2249
2249
  showIcon: e.role === "agent",
2250
2250
  icon: e.role === "agent" ? "assistant" : void 0
2251
2251
  };
2252
- if (e.role === "agent" && t.length > 0) {
2252
+ if (e.role === "agent" && s.length > 0) {
2253
2253
  const l = xt(
2254
2254
  r,
2255
- t
2255
+ s
2256
2256
  );
2257
2257
  l.length > 0 && (r.actions = l);
2258
2258
  }
@@ -2265,21 +2265,21 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
2265
2265
  success: !0,
2266
2266
  result: "No tools available"
2267
2267
  })
2268
- }), bt = (e) => ["agentId", "agentUrl"].every((s) => {
2269
- const a = e[s];
2268
+ }), bt = (e) => ["agentId", "agentUrl"].every((t) => {
2269
+ const a = e[t];
2270
2270
  return typeof a == "string" && a.trim().length > 0;
2271
2271
  });
2272
2272
  function Bt(e) {
2273
- const t = {
2273
+ const s = {
2274
2274
  agentId: e.agentId,
2275
2275
  agentUrl: e.agentUrl,
2276
2276
  sessionId: e.sessionId,
2277
2277
  sessionIdStorageKey: e.sessionIdStorageKey
2278
- }, s = bt(t), [a, n] = ve({
2278
+ }, t = bt(s), [a, n] = ve({
2279
2279
  clientMessages: [],
2280
2280
  uiMessages: [],
2281
2281
  isProcessing: !1,
2282
- error: s ? null : "Invalid agent configuration",
2282
+ error: t ? null : "Invalid agent configuration",
2283
2283
  suggestions: [],
2284
2284
  progressMessage: null
2285
2285
  }), {
@@ -2299,13 +2299,13 @@ function Bt(e) {
2299
2299
  // registrationsRef is stable, so no deps needed
2300
2300
  );
2301
2301
  se(() => {
2302
- if (!s)
2302
+ if (!t)
2303
2303
  return;
2304
2304
  (async () => {
2305
- const i = Q(), T = t.agentId;
2305
+ const i = Q(), T = s.agentId;
2306
2306
  if (i.hasAgent(T))
2307
- t.sessionId ? (i.updateSessionId(T, t.sessionId), i.getConversationHistory(T).length === 0 && n((P) => ({
2308
- ...P,
2307
+ s.sessionId ? (i.updateSessionId(T, s.sessionId), i.getConversationHistory(T).length === 0 && n((_) => ({
2308
+ ..._,
2309
2309
  clientMessages: [],
2310
2310
  uiMessages: []
2311
2311
  }))) : (i.updateSessionId(T, ""), await i.replaceMessages(T, []), n((w) => ({
@@ -2314,22 +2314,22 @@ function Bt(e) {
2314
2314
  uiMessages: []
2315
2315
  })));
2316
2316
  else if (await i.createAgent(T, {
2317
- agentId: t.agentId,
2318
- agentUrl: t.agentUrl,
2319
- sessionId: t.sessionId,
2317
+ agentId: s.agentId,
2318
+ agentUrl: s.agentUrl,
2319
+ sessionId: s.sessionId,
2320
2320
  // Can be empty for new chats
2321
- sessionIdStorageKey: t.sessionIdStorageKey,
2321
+ sessionIdStorageKey: s.sessionIdStorageKey,
2322
2322
  contextProvider: e.contextProvider || At(),
2323
2323
  toolProvider: e.toolProvider || Ct(),
2324
2324
  authProvider: e.authProvider,
2325
2325
  enableStreaming: e.enableStreaming,
2326
2326
  odieBotId: e.odieBotId
2327
- }), t.sessionId) {
2327
+ }), s.sessionId) {
2328
2328
  const w = i.getConversationHistory(T);
2329
- n((P) => {
2329
+ n((_) => {
2330
2330
  const O = d(w);
2331
2331
  return {
2332
- ...P,
2332
+ ..._,
2333
2333
  clientMessages: w,
2334
2334
  uiMessages: O
2335
2335
  };
@@ -2342,27 +2342,27 @@ function Bt(e) {
2342
2342
  }));
2343
2343
  })();
2344
2344
  }, [
2345
- t.sessionId,
2346
- t.agentId,
2347
- t.agentUrl,
2348
- t.sessionIdStorageKey,
2345
+ s.sessionId,
2346
+ s.agentId,
2347
+ s.agentUrl,
2348
+ s.sessionIdStorageKey,
2349
2349
  e.contextProvider,
2350
2350
  e.toolProvider,
2351
2351
  e.authProvider,
2352
2352
  e.enableStreaming,
2353
2353
  e.odieBotId,
2354
- s
2354
+ t
2355
2355
  ]);
2356
2356
  const p = F(
2357
2357
  async (g, i) => {
2358
2358
  var $, S;
2359
- if (!s)
2359
+ if (!t)
2360
2360
  throw new Error("Invalid agent configuration");
2361
- const T = Q(), x = t.agentId, w = Date.now(), P = (i == null ? void 0 : i.type) || "text", O = {
2361
+ const T = Q(), x = s.agentId, w = Date.now(), _ = (i == null ? void 0 : i.type) || "text", O = {
2362
2362
  id: `user-${w}`,
2363
2363
  role: "user",
2364
2364
  content: [
2365
- { type: P, text: g },
2365
+ { type: _, text: g },
2366
2366
  // Map image URLs to component content parts
2367
2367
  ...(($ = i == null ? void 0 : i.imageUrls) == null ? void 0 : $.map((y) => {
2368
2368
  const C = typeof y == "string" ? y : y.url;
@@ -2442,9 +2442,9 @@ function Bt(e) {
2442
2442
  b && n((E) => {
2443
2443
  const U = E.uiMessages.map(
2444
2444
  (q) => {
2445
- var _, J;
2445
+ var P, J;
2446
2446
  if (q.id === k) {
2447
- const H = b.content.length > 0 && ((_ = b.content[0]) == null ? void 0 : _.text) && ((J = q.content[0]) == null ? void 0 : J.text) && b.content[0].text.length > q.content[0].text.length;
2447
+ const H = b.content.length > 0 && ((P = b.content[0]) == null ? void 0 : P.text) && ((J = q.content[0]) == null ? void 0 : J.text) && b.content[0].text.length > q.content[0].text.length;
2448
2448
  return {
2449
2449
  ...b,
2450
2450
  reactKey: q.reactKey || k,
@@ -2472,19 +2472,19 @@ function Bt(e) {
2472
2472
  n((k) => {
2473
2473
  let b = k.uiMessages;
2474
2474
  y && (b = k.uiMessages.filter(
2475
- (_) => _.id !== y
2475
+ (P) => P.id !== y
2476
2476
  ));
2477
2477
  const E = R.map(
2478
- (_) => re(
2479
- _,
2478
+ (P) => re(
2479
+ P,
2480
2480
  u.current
2481
2481
  )
2482
2482
  ).filter(
2483
- (_) => _ !== null
2483
+ (P) => P !== null
2484
2484
  ), U = new Set(
2485
- R.map((_) => _.messageId)
2485
+ R.map((P) => P.messageId)
2486
2486
  ), D = b.filter(
2487
- (_) => !U.has(_.id) && _.role !== "user"
2487
+ (P) => !U.has(P.id) && P.role !== "user"
2488
2488
  ), q = oe([
2489
2489
  ...E,
2490
2490
  ...D
@@ -2518,7 +2518,7 @@ function Bt(e) {
2518
2518
  })), y;
2519
2519
  }
2520
2520
  },
2521
- [t.agentId, s]
2521
+ [s.agentId, t]
2522
2522
  ), m = F((g) => {
2523
2523
  n((i) => ({
2524
2524
  ...i,
@@ -2554,15 +2554,15 @@ function Bt(e) {
2554
2554
  });
2555
2555
  }, [l]);
2556
2556
  const h = F(() => {
2557
- if (!s)
2557
+ if (!t)
2558
2558
  return;
2559
- const g = Q(), i = t.agentId;
2559
+ const g = Q(), i = s.agentId;
2560
2560
  g.abortCurrentRequest(i);
2561
- }, [t.agentId, s]), A = F(
2561
+ }, [s.agentId, t]), A = F(
2562
2562
  async (g) => {
2563
- if (!s)
2563
+ if (!t)
2564
2564
  return;
2565
- const i = Q(), T = t.agentId;
2565
+ const i = Q(), T = s.agentId;
2566
2566
  await i.replaceMessages(T, g);
2567
2567
  const x = d(g);
2568
2568
  n((w) => ({
@@ -2571,7 +2571,7 @@ function Bt(e) {
2571
2571
  uiMessages: x
2572
2572
  }));
2573
2573
  },
2574
- [t.agentId, s]
2574
+ [s.agentId, t]
2575
2575
  );
2576
2576
  return {
2577
2577
  // AgentUI props
@@ -2599,20 +2599,20 @@ function Bt(e) {
2599
2599
  var kt = /* @__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))(kt || {});
2600
2600
  const Te = "jetpack-ai-jwt-token", Rt = 30 * 60 * 1e3;
2601
2601
  function Et() {
2602
- var s, a, n;
2603
- return ((a = (s = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : s.connectionStatus) == null ? void 0 : a.isRegistered) ? !1 : !!((n = window.Jetpack_Editor_Initial_State) != null && n.wpcomBlogId);
2602
+ var t, a, n;
2603
+ 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);
2604
2604
  }
2605
- async function Pt(e, t = !0) {
2605
+ async function _t(e, s = !0) {
2606
2606
  var l, u;
2607
- const s = localStorage.getItem(Te);
2607
+ const t = localStorage.getItem(Te);
2608
2608
  let a;
2609
- if (s)
2609
+ if (t)
2610
2610
  try {
2611
- a = JSON.parse(s);
2611
+ a = JSON.parse(t);
2612
2612
  } catch (d) {
2613
2613
  M("Invalid cached Jetpack token: %O", d);
2614
2614
  }
2615
- if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && t)
2615
+ if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && s)
2616
2616
  return a;
2617
2617
  const n = (l = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : l.apiNonce, r = (u = window.Jetpack_Editor_Initial_State) == null ? void 0 : u.wpcomBlogId;
2618
2618
  let o = {
@@ -2651,17 +2651,17 @@ async function Pt(e, t = !0) {
2651
2651
  return c;
2652
2652
  }
2653
2653
  const Wt = (e) => async () => {
2654
- const t = {};
2654
+ const s = {};
2655
2655
  try {
2656
- const s = await Pt(e);
2657
- s != null && s.token && (t.Authorization = `${s.token}`);
2658
- } catch (s) {
2659
- throw M("Failed to get Jetpack token for auth: %O", s), s;
2656
+ const t = await _t(e);
2657
+ t != null && t.token && (s.Authorization = `${t.token}`);
2658
+ } catch (t) {
2659
+ throw M("Failed to get Jetpack token for auth: %O", t), t;
2660
2660
  }
2661
- return t;
2661
+ return s;
2662
2662
  };
2663
- function _t(e) {
2664
- const t = {
2663
+ function Pt(e) {
2664
+ const s = {
2665
2665
  type: "object",
2666
2666
  properties: {}
2667
2667
  };
@@ -2669,36 +2669,36 @@ function _t(e) {
2669
2669
  id: e.name.replace(/\//g, "-"),
2670
2670
  name: e.label,
2671
2671
  description: e.description,
2672
- input_schema: e.input_schema || t,
2672
+ input_schema: e.input_schema || s,
2673
2673
  // Store metadata for detection and execution
2674
2674
  _source: "wordpress-ability",
2675
2675
  _originalAbility: e
2676
2676
  };
2677
2677
  }
2678
2678
  function Vt(e) {
2679
- return e.map(_t);
2679
+ return e.map(Pt);
2680
2680
  }
2681
2681
  function zt(e) {
2682
2682
  return (e == null ? void 0 : e._source) === "wordpress-ability";
2683
2683
  }
2684
- function Gt(e, t = "agent", s = "wpcom") {
2684
+ function Gt(e, s = "agent", t = "wpcom") {
2685
2685
  const a = e.replace(/-/g, "_");
2686
- return `${s}-${t}-${a}`;
2686
+ return `${t}-${s}-${a}`;
2687
2687
  }
2688
2688
  function Ot(e) {
2689
- const t = e.split("-");
2690
- if (t.length < 3)
2689
+ const s = e.split("-");
2690
+ if (s.length < 3)
2691
2691
  throw new Error(
2692
2692
  `Invalid Odie bot ID format: ${e}. Expected format: {product}-{type}-{slug}`
2693
2693
  );
2694
- const s = t[0], a = t[1];
2694
+ const t = s[0], a = s[1];
2695
2695
  if (!["agent", "workflow", "chain"].includes(a))
2696
2696
  throw new Error(
2697
2697
  `Invalid Odie bot type: ${a}. Expected one of: agent, workflow, chain`
2698
2698
  );
2699
- const n = a, r = t.slice(2).join("-"), o = r.replace(/_/g, "-");
2699
+ const n = a, r = s.slice(2).join("-"), o = r.replace(/_/g, "-");
2700
2700
  return {
2701
- product: s,
2701
+ product: t,
2702
2702
  type: n,
2703
2703
  slug: r,
2704
2704
  agentId: o
@@ -2706,8 +2706,8 @@ function Ot(e) {
2706
2706
  }
2707
2707
  function Qt(e) {
2708
2708
  try {
2709
- const t = Ot(e);
2710
- return t.product.length > 0 && ["agent", "workflow", "chain"].includes(t.type) && t.slug.length > 0;
2709
+ const s = Ot(e);
2710
+ return s.product.length > 0 && ["agent", "workflow", "chain"].includes(s.type) && s.slug.length > 0;
2711
2711
  } catch {
2712
2712
  return !1;
2713
2713
  }
@@ -2715,7 +2715,7 @@ function Qt(e) {
2715
2715
  export {
2716
2716
  kt as ErrorCodes,
2717
2717
  Vt as convertAbilitiesToTools,
2718
- _t as convertAbilityToTool,
2718
+ Pt as convertAbilityToTool,
2719
2719
  Jt as createAbortController,
2720
2720
  rt as createClient,
2721
2721
  Wt as createJetpackAuthProvider,