@automattic/agenttic-client 0.1.44 → 0.1.45
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 +329 -335
- package/dist/react/useAgentChat.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -9,8 +9,8 @@ function Ht(e) {
|
|
|
9
9
|
getClientContext: () => {
|
|
10
10
|
try {
|
|
11
11
|
return e() || {};
|
|
12
|
-
} catch (
|
|
13
|
-
return M("Error getting client context: %O",
|
|
12
|
+
} catch (a) {
|
|
13
|
+
return M("Error getting client context: %O", a), {};
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
} : void 0, [e]);
|
|
@@ -20,7 +20,7 @@ function ce({
|
|
|
20
20
|
executeTool: t,
|
|
21
21
|
getAbilities: s
|
|
22
22
|
}) {
|
|
23
|
-
const
|
|
23
|
+
const a = F(async () => {
|
|
24
24
|
const o = [];
|
|
25
25
|
if (e)
|
|
26
26
|
try {
|
|
@@ -30,7 +30,7 @@ function ce({
|
|
|
30
30
|
M("Error getting available tools: %O", c);
|
|
31
31
|
}
|
|
32
32
|
return o;
|
|
33
|
-
}, [e]),
|
|
33
|
+
}, [e]), n = F(
|
|
34
34
|
async (o, c) => {
|
|
35
35
|
if (!t)
|
|
36
36
|
throw new Error("No executeTool callback provided");
|
|
@@ -46,10 +46,10 @@ function ce({
|
|
|
46
46
|
if (!e && !s)
|
|
47
47
|
return;
|
|
48
48
|
const o = {};
|
|
49
|
-
return e && (o.getAvailableTools =
|
|
49
|
+
return e && (o.getAvailableTools = a), t && (o.executeTool = n), s && (o.getAbilities = s), o;
|
|
50
50
|
}, [
|
|
51
|
-
n,
|
|
52
51
|
a,
|
|
52
|
+
n,
|
|
53
53
|
e,
|
|
54
54
|
t,
|
|
55
55
|
s
|
|
@@ -70,8 +70,8 @@ function jt(e) {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
function Dt(e) {
|
|
73
|
-
const { getClientTools: t, executeTool: s, getAbilities:
|
|
74
|
-
if (!t && !
|
|
73
|
+
const { getClientTools: t, executeTool: s, getAbilities: a } = e;
|
|
74
|
+
if (!t && !a)
|
|
75
75
|
throw new Error(
|
|
76
76
|
"At least one of getClientTools or getAbilities must be provided to useClientToolsWithAbilities."
|
|
77
77
|
);
|
|
@@ -82,7 +82,7 @@ function Dt(e) {
|
|
|
82
82
|
return ce({
|
|
83
83
|
getClientTools: t,
|
|
84
84
|
executeTool: s,
|
|
85
|
-
getAbilities:
|
|
85
|
+
getAbilities: a
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
function ue() {
|
|
@@ -109,7 +109,7 @@ function xe(e, t) {
|
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
111
|
function De(e, t = "message/send", s = !1) {
|
|
112
|
-
const
|
|
112
|
+
const a = {
|
|
113
113
|
jsonrpc: "2.0",
|
|
114
114
|
id: Fe(),
|
|
115
115
|
method: t,
|
|
@@ -118,9 +118,9 @@ function De(e, t = "message/send", s = !1) {
|
|
|
118
118
|
...e
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
|
-
return s && t === "message/stream" && (
|
|
121
|
+
return s && t === "message/stream" && (a.tokenStreaming = !0), a;
|
|
122
122
|
}
|
|
123
|
-
function
|
|
123
|
+
function j(e) {
|
|
124
124
|
return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((t) => t.type === "text").map((t) => t.text).join(" ");
|
|
125
125
|
}
|
|
126
126
|
function he(e) {
|
|
@@ -161,7 +161,7 @@ function L(e) {
|
|
|
161
161
|
(t) => t.type === "data" && "toolCallId" in t.data && "toolId" in t.data && "arguments" in t.data
|
|
162
162
|
);
|
|
163
163
|
}
|
|
164
|
-
function W(e, t, s,
|
|
164
|
+
function W(e, t, s, a) {
|
|
165
165
|
return {
|
|
166
166
|
type: "data",
|
|
167
167
|
data: {
|
|
@@ -169,7 +169,7 @@ function W(e, t, s, n) {
|
|
|
169
169
|
toolId: t,
|
|
170
170
|
result: s
|
|
171
171
|
},
|
|
172
|
-
metadata:
|
|
172
|
+
metadata: a ? { error: a } : void 0
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
175
|
function Le(e) {
|
|
@@ -182,7 +182,7 @@ function Le(e) {
|
|
|
182
182
|
};
|
|
183
183
|
}
|
|
184
184
|
function ie(e, t) {
|
|
185
|
-
const { contentType: s, ...
|
|
185
|
+
const { contentType: s, ...a } = t || {};
|
|
186
186
|
return {
|
|
187
187
|
role: "user",
|
|
188
188
|
parts: [xe(e, s ? { contentType: s } : void 0)],
|
|
@@ -190,7 +190,7 @@ function ie(e, t) {
|
|
|
190
190
|
messageId: N(),
|
|
191
191
|
metadata: {
|
|
192
192
|
timestamp: Date.now(),
|
|
193
|
-
...
|
|
193
|
+
...a
|
|
194
194
|
}
|
|
195
195
|
};
|
|
196
196
|
}
|
|
@@ -237,17 +237,17 @@ async function Be(e, t) {
|
|
|
237
237
|
try {
|
|
238
238
|
const s = [];
|
|
239
239
|
if (t.getAvailableTools) {
|
|
240
|
-
const
|
|
241
|
-
if (
|
|
242
|
-
const
|
|
243
|
-
s.push(...
|
|
240
|
+
const a = await t.getAvailableTools();
|
|
241
|
+
if (a.length > 0) {
|
|
242
|
+
const n = a.map(Je);
|
|
243
|
+
s.push(...n);
|
|
244
244
|
}
|
|
245
245
|
}
|
|
246
246
|
if (t.getAbilities) {
|
|
247
|
-
const
|
|
248
|
-
if (
|
|
249
|
-
const
|
|
250
|
-
s.push(...
|
|
247
|
+
const a = await t.getAbilities();
|
|
248
|
+
if (a.length > 0) {
|
|
249
|
+
const n = a.map(Ke);
|
|
250
|
+
s.push(...n);
|
|
251
251
|
}
|
|
252
252
|
}
|
|
253
253
|
return s.length === 0 ? e : {
|
|
@@ -265,66 +265,66 @@ function We(e, t) {
|
|
|
265
265
|
const s = t.getClientContext();
|
|
266
266
|
if (!s || Object.keys(s).length === 0)
|
|
267
267
|
return e;
|
|
268
|
-
const
|
|
268
|
+
const a = Le(s);
|
|
269
269
|
return {
|
|
270
270
|
...e,
|
|
271
|
-
parts: [...e.parts,
|
|
271
|
+
parts: [...e.parts, a]
|
|
272
272
|
};
|
|
273
273
|
} catch (s) {
|
|
274
274
|
return M("Warning: Failed to get context: %s", s), e;
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
async function Ve(e, t, s) {
|
|
278
|
-
let
|
|
278
|
+
let a = await Be(
|
|
279
279
|
e,
|
|
280
280
|
t
|
|
281
281
|
);
|
|
282
|
-
|
|
283
|
-
|
|
282
|
+
a = We(
|
|
283
|
+
a,
|
|
284
284
|
s
|
|
285
285
|
);
|
|
286
|
-
const { metadata:
|
|
286
|
+
const { metadata: n, ...r } = a;
|
|
287
287
|
return r;
|
|
288
288
|
}
|
|
289
289
|
function ze(e, t = "") {
|
|
290
|
-
const s = [],
|
|
291
|
-
let
|
|
292
|
-
for (; o <
|
|
293
|
-
const l =
|
|
290
|
+
const s = [], a = t + e;
|
|
291
|
+
let n = "", r = 0, o = 0;
|
|
292
|
+
for (; o < a.length; ) {
|
|
293
|
+
const l = a.indexOf(
|
|
294
294
|
`
|
|
295
295
|
`,
|
|
296
296
|
o
|
|
297
|
-
), u = l === -1 ?
|
|
297
|
+
), u = l === -1 ? a.substring(o) : a.substring(o, l);
|
|
298
298
|
if (u.startsWith("data:"))
|
|
299
|
-
|
|
300
|
-
`),
|
|
299
|
+
n !== "" && (n += `
|
|
300
|
+
`), n += u.substring(
|
|
301
301
|
u.startsWith("data: ") ? 6 : 5
|
|
302
302
|
);
|
|
303
|
-
else if (u.trim() === "" &&
|
|
303
|
+
else if (u.trim() === "" && n) {
|
|
304
304
|
try {
|
|
305
|
-
s.push(JSON.parse(
|
|
305
|
+
s.push(JSON.parse(n)), r = l === -1 ? a.length : l + 1;
|
|
306
306
|
} catch (d) {
|
|
307
|
-
M("Failed to parse SSE event: %o", d), M("Problematic payload: %s",
|
|
307
|
+
M("Failed to parse SSE event: %o", d), M("Problematic payload: %s", n);
|
|
308
308
|
}
|
|
309
|
-
|
|
309
|
+
n = "";
|
|
310
310
|
}
|
|
311
|
-
l === -1 ? o =
|
|
311
|
+
l === -1 ? o = a.length : o = l + 1;
|
|
312
312
|
}
|
|
313
|
-
const c =
|
|
313
|
+
const c = a.substring(r);
|
|
314
314
|
return { events: s, nextBuffer: c };
|
|
315
315
|
}
|
|
316
316
|
async function* Ge(e, t = {}) {
|
|
317
317
|
var u, d, p;
|
|
318
|
-
const { supportDeltas: s = !1 } = t,
|
|
318
|
+
const { supportDeltas: s = !1 } = t, a = e.getReader(), n = new TextDecoder();
|
|
319
319
|
let r = "";
|
|
320
320
|
const o = new Qe();
|
|
321
321
|
let c = null, l = null;
|
|
322
322
|
try {
|
|
323
323
|
for (; ; ) {
|
|
324
|
-
const { done: m, value: f } = await
|
|
324
|
+
const { done: m, value: f } = await a.read();
|
|
325
325
|
if (m)
|
|
326
326
|
break;
|
|
327
|
-
const I =
|
|
327
|
+
const I = n.decode(f, { stream: !0 }), { events: h, nextBuffer: A } = ze(I, r);
|
|
328
328
|
if (h && Array.isArray(h))
|
|
329
329
|
for (let g = 0; g < h.length; g++) {
|
|
330
330
|
const i = h[g];
|
|
@@ -365,7 +365,7 @@ async function* Ge(e, t = {}) {
|
|
|
365
365
|
sessionId: i.result.sessionId,
|
|
366
366
|
status: i.result.status,
|
|
367
367
|
final: i.result.status.state === "completed" || i.result.status.state === "failed" || i.result.status.state === "canceled",
|
|
368
|
-
text:
|
|
368
|
+
text: j(T),
|
|
369
369
|
progressMessage: he(T)
|
|
370
370
|
};
|
|
371
371
|
} else if (i.id && i.result && (c = i.result.id, i.result.status)) {
|
|
@@ -378,7 +378,7 @@ async function* Ge(e, t = {}) {
|
|
|
378
378
|
sessionId: i.result.sessionId,
|
|
379
379
|
status: i.result.status,
|
|
380
380
|
final: i.result.status.state === "completed" || i.result.status.state === "failed" || i.result.status.state === "canceled",
|
|
381
|
-
text:
|
|
381
|
+
text: j(T),
|
|
382
382
|
progressMessage: he(T)
|
|
383
383
|
};
|
|
384
384
|
}
|
|
@@ -386,7 +386,7 @@ async function* Ge(e, t = {}) {
|
|
|
386
386
|
r = A;
|
|
387
387
|
}
|
|
388
388
|
} finally {
|
|
389
|
-
|
|
389
|
+
a.releaseLock();
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
392
|
class Qe {
|
|
@@ -444,9 +444,9 @@ class Qe {
|
|
|
444
444
|
type: "text",
|
|
445
445
|
text: this.textContent
|
|
446
446
|
});
|
|
447
|
-
for (const [
|
|
448
|
-
if (
|
|
449
|
-
const r =
|
|
447
|
+
for (const [a, n] of this.toolCalls)
|
|
448
|
+
if (n.toolName) {
|
|
449
|
+
const r = n.argumentFragments.join("");
|
|
450
450
|
let o = {};
|
|
451
451
|
if (r)
|
|
452
452
|
try {
|
|
@@ -457,8 +457,8 @@ class Qe {
|
|
|
457
457
|
s.push({
|
|
458
458
|
type: "data",
|
|
459
459
|
data: {
|
|
460
|
-
toolCallId:
|
|
461
|
-
toolId:
|
|
460
|
+
toolCallId: n.toolCallId,
|
|
461
|
+
toolId: n.toolName,
|
|
462
462
|
arguments: o
|
|
463
463
|
}
|
|
464
464
|
});
|
|
@@ -507,28 +507,28 @@ function be(e, t = "request") {
|
|
|
507
507
|
function Ze(e, t) {
|
|
508
508
|
return `${e}/${t}`;
|
|
509
509
|
}
|
|
510
|
-
function et(e, t, s,
|
|
511
|
-
M("Request: %s %s", e, t), M("Headers: %o", s),
|
|
510
|
+
function et(e, t, s, a) {
|
|
511
|
+
M("Request: %s %s", e, t), M("Headers: %o", s), a && M("Body: %s", Me(a));
|
|
512
512
|
}
|
|
513
513
|
async function tt(e, t = !1) {
|
|
514
514
|
const s = {
|
|
515
515
|
"Content-Type": "application/json"
|
|
516
516
|
};
|
|
517
517
|
if (t && (s.Accept = "text/event-stream"), e) {
|
|
518
|
-
const
|
|
519
|
-
return { ...s, ...
|
|
518
|
+
const a = await e();
|
|
519
|
+
return { ...s, ...a };
|
|
520
520
|
}
|
|
521
521
|
return s;
|
|
522
522
|
}
|
|
523
523
|
function ke(e, t) {
|
|
524
524
|
if (!t)
|
|
525
525
|
return e;
|
|
526
|
-
const s = new AbortController(),
|
|
527
|
-
s.signal.aborted || s.abort(
|
|
526
|
+
const s = new AbortController(), a = (n) => {
|
|
527
|
+
s.signal.aborted || s.abort(n.reason);
|
|
528
528
|
};
|
|
529
|
-
return e.aborted ? s.abort(e.reason) : e.addEventListener("abort", () =>
|
|
529
|
+
return e.aborted ? s.abort(e.reason) : e.addEventListener("abort", () => a(e), {
|
|
530
530
|
once: !0
|
|
531
|
-
}), t.aborted ? s.abort(t.reason) : t.addEventListener("abort", () =>
|
|
531
|
+
}), t.aborted ? s.abort(t.reason) : t.addEventListener("abort", () => a(t), {
|
|
532
532
|
once: !0
|
|
533
533
|
}), s.signal;
|
|
534
534
|
}
|
|
@@ -540,11 +540,11 @@ function Re(e, t, s) {
|
|
|
540
540
|
signal: s
|
|
541
541
|
};
|
|
542
542
|
}
|
|
543
|
-
async function Y(e, t, s,
|
|
543
|
+
async function Y(e, t, s, a, n, r) {
|
|
544
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(
|
|
545
545
|
o,
|
|
546
|
-
|
|
547
|
-
|
|
546
|
+
a,
|
|
547
|
+
n
|
|
548
548
|
), T = {
|
|
549
549
|
id: l,
|
|
550
550
|
message: i,
|
|
@@ -566,14 +566,14 @@ async function Y(e, t, s, n, a, r) {
|
|
|
566
566
|
};
|
|
567
567
|
}
|
|
568
568
|
async function Ee(e, t, s = {}) {
|
|
569
|
-
const { request:
|
|
569
|
+
const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o } = t, { abortSignal: c } = s, { timeoutId: l, controller: u } = be(
|
|
570
570
|
o,
|
|
571
571
|
"request"
|
|
572
572
|
), d = c ? ke(u.signal, c) : u.signal;
|
|
573
573
|
try {
|
|
574
574
|
const p = Re(
|
|
575
|
-
|
|
576
|
-
JSON.stringify(
|
|
575
|
+
n,
|
|
576
|
+
JSON.stringify(a),
|
|
577
577
|
d
|
|
578
578
|
);
|
|
579
579
|
M("Making request to %s with options: %O", r, {
|
|
@@ -594,7 +594,7 @@ async function Ee(e, t, s = {}) {
|
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
596
|
async function* Pe(e, t, s) {
|
|
597
|
-
const { request:
|
|
597
|
+
const { request: a, headers: n, fullAgentUrl: r } = e, {
|
|
598
598
|
streamingTimeout: o = 6e4,
|
|
599
599
|
abortSignal: c,
|
|
600
600
|
enableTokenStreaming: l = !1
|
|
@@ -603,12 +603,12 @@ async function* Pe(e, t, s) {
|
|
|
603
603
|
"streaming request"
|
|
604
604
|
), p = c ? ke(d.signal, c) : d.signal;
|
|
605
605
|
try {
|
|
606
|
-
const m = JSON.stringify(
|
|
606
|
+
const m = JSON.stringify(a), f = Re(n, m, p), I = await fetch(r, f);
|
|
607
607
|
if (clearTimeout(u), Ye(I, "streaming request"), !I.body)
|
|
608
608
|
throw new Error(
|
|
609
609
|
"Response body is null - server may not support streaming"
|
|
610
610
|
);
|
|
611
|
-
const h = l &&
|
|
611
|
+
const h = l && a.tokenStreaming === !0;
|
|
612
612
|
yield* Ge(I.body, {
|
|
613
613
|
supportDeltas: h
|
|
614
614
|
});
|
|
@@ -617,7 +617,7 @@ async function* Pe(e, t, s) {
|
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
const st = 12e4;
|
|
620
|
-
async function Z(e, t, s,
|
|
620
|
+
async function Z(e, t, s, a, n) {
|
|
621
621
|
if (e.getAbilities) {
|
|
622
622
|
const r = await e.getAbilities();
|
|
623
623
|
if (r.length > 0)
|
|
@@ -628,7 +628,7 @@ async function Z(e, t, s, n, a) {
|
|
|
628
628
|
try {
|
|
629
629
|
const l = {
|
|
630
630
|
...s,
|
|
631
|
-
...
|
|
631
|
+
...a && { messageId: a }
|
|
632
632
|
}, u = await o.callback(l);
|
|
633
633
|
return {
|
|
634
634
|
result: u,
|
|
@@ -679,25 +679,25 @@ async function Z(e, t, s, n, a) {
|
|
|
679
679
|
return await e.executeTool(
|
|
680
680
|
t,
|
|
681
681
|
s,
|
|
682
|
-
|
|
683
|
-
|
|
682
|
+
a,
|
|
683
|
+
n
|
|
684
684
|
);
|
|
685
685
|
throw new Error(
|
|
686
686
|
`No handler found for tool: ${t}. Tool provider must implement executeTool for non-ability tools.`
|
|
687
687
|
);
|
|
688
688
|
}
|
|
689
689
|
const ge = /* @__PURE__ */ new Map();
|
|
690
|
-
async function
|
|
690
|
+
async function at(e, t) {
|
|
691
691
|
if (!e || !t || !e.getAvailableTools)
|
|
692
692
|
return !1;
|
|
693
693
|
const s = L(t);
|
|
694
694
|
if (s.length === 0)
|
|
695
695
|
return !1;
|
|
696
696
|
try {
|
|
697
|
-
const
|
|
698
|
-
for (const
|
|
699
|
-
if (
|
|
700
|
-
(o) => o.id ===
|
|
697
|
+
const a = await e.getAvailableTools();
|
|
698
|
+
for (const n of s)
|
|
699
|
+
if (a.some(
|
|
700
|
+
(o) => o.id === n.data.toolId
|
|
701
701
|
))
|
|
702
702
|
return !0;
|
|
703
703
|
} catch {
|
|
@@ -705,30 +705,30 @@ async function nt(e, t) {
|
|
|
705
705
|
}
|
|
706
706
|
return !1;
|
|
707
707
|
}
|
|
708
|
-
function
|
|
708
|
+
function nt() {
|
|
709
709
|
ge.clear();
|
|
710
710
|
}
|
|
711
711
|
function ot(e) {
|
|
712
712
|
return e.map((t) => {
|
|
713
|
-
const s = t.data.toolCallId,
|
|
714
|
-
if (
|
|
715
|
-
const
|
|
716
|
-
return
|
|
713
|
+
const s = t.data.toolCallId, a = ge.get(s);
|
|
714
|
+
if (a && a.resolvedValue !== null) {
|
|
715
|
+
const n = a.resolvedValue;
|
|
716
|
+
return n.error ? W(
|
|
717
717
|
s,
|
|
718
718
|
t.data.toolId,
|
|
719
719
|
void 0,
|
|
720
|
-
|
|
720
|
+
n.error
|
|
721
721
|
) : W(
|
|
722
722
|
s,
|
|
723
723
|
t.data.toolId,
|
|
724
|
-
|
|
724
|
+
n
|
|
725
725
|
);
|
|
726
726
|
}
|
|
727
727
|
return t;
|
|
728
728
|
});
|
|
729
729
|
}
|
|
730
730
|
async function _e(e, t, s) {
|
|
731
|
-
const
|
|
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;
|
|
@@ -740,7 +740,7 @@ async function _e(e, t, s) {
|
|
|
740
740
|
s,
|
|
741
741
|
c
|
|
742
742
|
), { result: p, returnToAgent: m, agentMessage: f } = de(d);
|
|
743
|
-
m && (r = !0), f &&
|
|
743
|
+
m && (r = !0), f && n.push(G(f)), a.push(
|
|
744
744
|
W(
|
|
745
745
|
c,
|
|
746
746
|
l,
|
|
@@ -748,7 +748,7 @@ async function _e(e, t, s) {
|
|
|
748
748
|
)
|
|
749
749
|
);
|
|
750
750
|
} catch (d) {
|
|
751
|
-
r = !0,
|
|
751
|
+
r = !0, a.push(
|
|
752
752
|
W(
|
|
753
753
|
c,
|
|
754
754
|
l,
|
|
@@ -758,22 +758,22 @@ async function _e(e, t, s) {
|
|
|
758
758
|
);
|
|
759
759
|
}
|
|
760
760
|
}
|
|
761
|
-
return { results:
|
|
761
|
+
return { results: a, shouldReturnToAgent: r, agentMessages: n };
|
|
762
762
|
}
|
|
763
763
|
function ye(e) {
|
|
764
764
|
const t = [];
|
|
765
765
|
for (const s of e)
|
|
766
|
-
for (const
|
|
767
|
-
|
|
766
|
+
for (const a of s.parts)
|
|
767
|
+
a.type === "text" ? t.push({
|
|
768
768
|
type: "data",
|
|
769
769
|
data: {
|
|
770
770
|
role: s.role,
|
|
771
|
-
text:
|
|
771
|
+
text: a.text
|
|
772
772
|
}
|
|
773
|
-
}) : (
|
|
773
|
+
}) : (a.type === "data" || a.type === "file") && t.push(a);
|
|
774
774
|
return t;
|
|
775
775
|
}
|
|
776
|
-
async function
|
|
776
|
+
async function ae(e, t, s, a, n, r, o) {
|
|
777
777
|
const l = await Y(
|
|
778
778
|
{
|
|
779
779
|
message: t,
|
|
@@ -783,15 +783,15 @@ async function ne(e, t, s, n, a, r, o) {
|
|
|
783
783
|
},
|
|
784
784
|
s,
|
|
785
785
|
{ isStreaming: !1 },
|
|
786
|
-
n,
|
|
787
786
|
a,
|
|
787
|
+
n,
|
|
788
788
|
r
|
|
789
789
|
);
|
|
790
790
|
return await Ee(l, s, {
|
|
791
791
|
abortSignal: o
|
|
792
792
|
});
|
|
793
793
|
}
|
|
794
|
-
async function Ie(e, t, s,
|
|
794
|
+
async function Ie(e, t, s, a, n, r, o, c, l = []) {
|
|
795
795
|
const u = {
|
|
796
796
|
message: t,
|
|
797
797
|
taskId: e,
|
|
@@ -803,8 +803,8 @@ async function Ie(e, t, s, n, a, r, o, c, l = []) {
|
|
|
803
803
|
{
|
|
804
804
|
...d
|
|
805
805
|
},
|
|
806
|
-
n,
|
|
807
806
|
a,
|
|
807
|
+
n,
|
|
808
808
|
r
|
|
809
809
|
), m = Pe(p, s, {
|
|
810
810
|
...d,
|
|
@@ -812,8 +812,8 @@ async function Ie(e, t, s, n, a, r, o, c, l = []) {
|
|
|
812
812
|
});
|
|
813
813
|
return Oe(
|
|
814
814
|
m,
|
|
815
|
-
n,
|
|
816
815
|
a,
|
|
816
|
+
n,
|
|
817
817
|
s,
|
|
818
818
|
r,
|
|
819
819
|
!0,
|
|
@@ -825,10 +825,10 @@ async function Ie(e, t, s, n, a, r, o, c, l = []) {
|
|
|
825
825
|
// Pass through the same request options
|
|
826
826
|
);
|
|
827
827
|
}
|
|
828
|
-
async function* Oe(e, t, s,
|
|
828
|
+
async function* Oe(e, t, s, 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 && !
|
|
831
|
+
if (w.sessionId && !n && (n = w.sessionId), yield w, w.status.state === "running" && w.status.message && t && await at(
|
|
832
832
|
t,
|
|
833
833
|
w.status.message
|
|
834
834
|
)) {
|
|
@@ -883,25 +883,25 @@ async function* Oe(e, t, s, n, a, r = !0, o = [], c, l) {
|
|
|
883
883
|
k,
|
|
884
884
|
(m = (p = w.status) == null ? void 0 : p.message) == null ? void 0 : m.messageId,
|
|
885
885
|
v
|
|
886
|
-
), { result: E, returnToAgent: U, agentMessage:
|
|
887
|
-
if (U && ($ = !0),
|
|
888
|
-
G(
|
|
886
|
+
), { result: E, returnToAgent: U, agentMessage: D } = de(b);
|
|
887
|
+
if (U && ($ = !0), D && y.push(
|
|
888
|
+
G(D)
|
|
889
889
|
), E.result instanceof Promise) {
|
|
890
|
-
const _ = E.result,
|
|
890
|
+
const _ = E.result, J = {
|
|
891
891
|
promise: _,
|
|
892
892
|
resolvedValue: null
|
|
893
893
|
};
|
|
894
894
|
ge.set(
|
|
895
895
|
v,
|
|
896
|
-
|
|
896
|
+
J
|
|
897
897
|
), _.then((H) => {
|
|
898
|
-
|
|
898
|
+
J.resolvedValue = H;
|
|
899
899
|
}).catch((H) => {
|
|
900
900
|
M(
|
|
901
901
|
"Promise rejected for tool call %s: %O",
|
|
902
902
|
v,
|
|
903
903
|
H
|
|
904
|
-
),
|
|
904
|
+
), J.resolvedValue = {
|
|
905
905
|
error: H instanceof Error ? H.message : String(H)
|
|
906
906
|
};
|
|
907
907
|
});
|
|
@@ -945,10 +945,10 @@ async function* Oe(e, t, s, n, a, r = !0, o = [], c, l) {
|
|
|
945
945
|
const R = await Ie(
|
|
946
946
|
w.id,
|
|
947
947
|
v,
|
|
948
|
-
|
|
948
|
+
a,
|
|
949
949
|
t,
|
|
950
950
|
s,
|
|
951
|
-
|
|
951
|
+
n,
|
|
952
952
|
c,
|
|
953
953
|
l,
|
|
954
954
|
o
|
|
@@ -967,7 +967,7 @@ async function* Oe(e, t, s, n, a, r = !0, o = [], c, l) {
|
|
|
967
967
|
for (yield {
|
|
968
968
|
...k,
|
|
969
969
|
final: !1,
|
|
970
|
-
text:
|
|
970
|
+
text: j(
|
|
971
971
|
((I = k.status) == null ? void 0 : I.message) || {
|
|
972
972
|
parts: [],
|
|
973
973
|
messageId: N()
|
|
@@ -979,7 +979,7 @@ async function* Oe(e, t, s, n, a, r = !0, o = [], c, l) {
|
|
|
979
979
|
);
|
|
980
980
|
const {
|
|
981
981
|
results: U,
|
|
982
|
-
shouldReturnToAgent:
|
|
982
|
+
shouldReturnToAgent: D
|
|
983
983
|
} = await _e(
|
|
984
984
|
b,
|
|
985
985
|
t,
|
|
@@ -999,25 +999,25 @@ async function* Oe(e, t, s, n, a, r = !0, o = [], c, l) {
|
|
|
999
999
|
},
|
|
1000
1000
|
final: !1,
|
|
1001
1001
|
text: ""
|
|
1002
|
-
}),
|
|
1002
|
+
}), D) {
|
|
1003
1003
|
const q = r ? ye(
|
|
1004
1004
|
o
|
|
1005
1005
|
) : [], _ = X(
|
|
1006
1006
|
U,
|
|
1007
1007
|
q
|
|
1008
|
-
),
|
|
1008
|
+
), J = await Ie(
|
|
1009
1009
|
E.id,
|
|
1010
1010
|
_,
|
|
1011
|
-
|
|
1011
|
+
a,
|
|
1012
1012
|
t,
|
|
1013
1013
|
s,
|
|
1014
|
-
|
|
1014
|
+
n,
|
|
1015
1015
|
c,
|
|
1016
1016
|
l,
|
|
1017
1017
|
o
|
|
1018
1018
|
);
|
|
1019
1019
|
let H = null;
|
|
1020
|
-
for await (const ee of
|
|
1020
|
+
for await (const ee of J)
|
|
1021
1021
|
ee.final ? H = ee : yield ee;
|
|
1022
1022
|
if (!H)
|
|
1023
1023
|
throw new Error(
|
|
@@ -1029,7 +1029,7 @@ async function* Oe(e, t, s, n, a, r = !0, o = [], c, l) {
|
|
|
1029
1029
|
id: E.id,
|
|
1030
1030
|
status: E.status,
|
|
1031
1031
|
final: !1,
|
|
1032
|
-
text:
|
|
1032
|
+
text: j(
|
|
1033
1033
|
((T = E.status) == null ? void 0 : T.message) || {
|
|
1034
1034
|
parts: [],
|
|
1035
1035
|
messageId: N()
|
|
@@ -1042,7 +1042,7 @@ async function* Oe(e, t, s, n, a, r = !0, o = [], c, l) {
|
|
|
1042
1042
|
yield {
|
|
1043
1043
|
...E,
|
|
1044
1044
|
final: !0,
|
|
1045
|
-
text:
|
|
1045
|
+
text: j(
|
|
1046
1046
|
((x = E.status) == null ? void 0 : x.message) || {
|
|
1047
1047
|
parts: [],
|
|
1048
1048
|
messageId: N()
|
|
@@ -1061,10 +1061,10 @@ async function* Oe(e, t, s, n, a, r = !0, o = [], c, l) {
|
|
|
1061
1061
|
},
|
|
1062
1062
|
final: y.length === 0,
|
|
1063
1063
|
// Only final if no agent messages to follow
|
|
1064
|
-
text:
|
|
1064
|
+
text: j(C)
|
|
1065
1065
|
};
|
|
1066
1066
|
if (yield v, y.length > 0) {
|
|
1067
|
-
const R = y.map((b) =>
|
|
1067
|
+
const R = y.map((b) => j(b)).join(" "), k = G(R);
|
|
1068
1068
|
yield {
|
|
1069
1069
|
id: v.id,
|
|
1070
1070
|
status: {
|
|
@@ -1084,8 +1084,8 @@ function rt(e) {
|
|
|
1084
1084
|
const {
|
|
1085
1085
|
agentId: t,
|
|
1086
1086
|
agentUrl: s,
|
|
1087
|
-
authProvider:
|
|
1088
|
-
defaultSessionId:
|
|
1087
|
+
authProvider: a,
|
|
1088
|
+
defaultSessionId: n,
|
|
1089
1089
|
timeout: r = st,
|
|
1090
1090
|
toolProvider: o,
|
|
1091
1091
|
contextProvider: c,
|
|
@@ -1093,13 +1093,13 @@ function rt(e) {
|
|
|
1093
1093
|
} = e, u = {
|
|
1094
1094
|
agentId: t,
|
|
1095
1095
|
agentUrl: s,
|
|
1096
|
-
authProvider:
|
|
1096
|
+
authProvider: a,
|
|
1097
1097
|
timeout: r
|
|
1098
1098
|
};
|
|
1099
1099
|
return {
|
|
1100
1100
|
async sendMessage(d) {
|
|
1101
1101
|
var i, T;
|
|
1102
|
-
const { abortSignal: p } = d, m = d.sessionId ||
|
|
1102
|
+
const { abortSignal: p } = d, m = d.sessionId || n || void 0, f = [];
|
|
1103
1103
|
f.push(d.message);
|
|
1104
1104
|
const I = await Y(
|
|
1105
1105
|
d,
|
|
@@ -1157,7 +1157,7 @@ function rt(e) {
|
|
|
1157
1157
|
}
|
|
1158
1158
|
if (f.push(h.status.message), P) {
|
|
1159
1159
|
const O = X(w);
|
|
1160
|
-
h = await
|
|
1160
|
+
h = await ae(
|
|
1161
1161
|
h.id,
|
|
1162
1162
|
O,
|
|
1163
1163
|
u,
|
|
@@ -1183,7 +1183,7 @@ function rt(e) {
|
|
|
1183
1183
|
};
|
|
1184
1184
|
}
|
|
1185
1185
|
if (g.length > 0) {
|
|
1186
|
-
const x = g.map((P) =>
|
|
1186
|
+
const x = g.map((P) => j(P)).join(" "), w = G(x);
|
|
1187
1187
|
return {
|
|
1188
1188
|
...h,
|
|
1189
1189
|
// Keep the enhanced message with tool results
|
|
@@ -1195,7 +1195,7 @@ function rt(e) {
|
|
|
1195
1195
|
}
|
|
1196
1196
|
return {
|
|
1197
1197
|
...h,
|
|
1198
|
-
text:
|
|
1198
|
+
text: j(
|
|
1199
1199
|
((T = h.status) == null ? void 0 : T.message) || {
|
|
1200
1200
|
parts: [],
|
|
1201
1201
|
messageId: N()
|
|
@@ -1208,7 +1208,7 @@ function rt(e) {
|
|
|
1208
1208
|
withHistory: p = !0,
|
|
1209
1209
|
abortSignal: m,
|
|
1210
1210
|
enableStreaming: f
|
|
1211
|
-
} = d, I = d.sessionId ||
|
|
1211
|
+
} = d, I = d.sessionId || n || void 0, h = f ?? l, A = [];
|
|
1212
1212
|
A.push(d.message);
|
|
1213
1213
|
const g = await Y(
|
|
1214
1214
|
d,
|
|
@@ -1250,7 +1250,7 @@ function rt(e) {
|
|
|
1250
1250
|
async continueTask(d, p, m) {
|
|
1251
1251
|
var A;
|
|
1252
1252
|
const f = ie(p);
|
|
1253
|
-
let h = await
|
|
1253
|
+
let h = await ae(
|
|
1254
1254
|
d,
|
|
1255
1255
|
f,
|
|
1256
1256
|
u,
|
|
@@ -1267,7 +1267,7 @@ function rt(e) {
|
|
|
1267
1267
|
const { results: i, shouldReturnToAgent: T } = await _e(g, o);
|
|
1268
1268
|
if (T) {
|
|
1269
1269
|
const x = X(i);
|
|
1270
|
-
h = await
|
|
1270
|
+
h = await ae(
|
|
1271
1271
|
h.id,
|
|
1272
1272
|
x,
|
|
1273
1273
|
u,
|
|
@@ -1280,7 +1280,7 @@ function rt(e) {
|
|
|
1280
1280
|
}
|
|
1281
1281
|
return {
|
|
1282
1282
|
...h,
|
|
1283
|
-
text:
|
|
1283
|
+
text: j(
|
|
1284
1284
|
((A = h.status) == null ? void 0 : A.message) || {
|
|
1285
1285
|
parts: [],
|
|
1286
1286
|
messageId: N()
|
|
@@ -1321,16 +1321,16 @@ function it(e) {
|
|
|
1321
1321
|
t.push(o);
|
|
1322
1322
|
}
|
|
1323
1323
|
}
|
|
1324
|
-
const
|
|
1324
|
+
const a = e.role === "user" ? "user" : "agent", n = e.ts ? e.ts * 1e3 : (/* @__PURE__ */ new Date(
|
|
1325
1325
|
e.created_at.replace(" ", "T") + "Z"
|
|
1326
1326
|
)).getTime();
|
|
1327
1327
|
return {
|
|
1328
|
-
role:
|
|
1328
|
+
role: a,
|
|
1329
1329
|
kind: "message",
|
|
1330
1330
|
parts: t,
|
|
1331
1331
|
messageId: N(),
|
|
1332
1332
|
metadata: {
|
|
1333
|
-
timestamp:
|
|
1333
|
+
timestamp: n,
|
|
1334
1334
|
serverId: e.message_id,
|
|
1335
1335
|
chatId: e.chat_id
|
|
1336
1336
|
}
|
|
@@ -1347,33 +1347,33 @@ function lt(e) {
|
|
|
1347
1347
|
}
|
|
1348
1348
|
function ct(e, t = !1) {
|
|
1349
1349
|
var r, o, c, l, u, d;
|
|
1350
|
-
const
|
|
1350
|
+
const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!t || 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,
|
|
1354
|
-
totalMessages: ((l = e.metadata) == null ? void 0 : l.total_messages) ??
|
|
1354
|
+
totalMessages: ((l = e.metadata) == null ? void 0 : l.total_messages) ?? a.length,
|
|
1355
1355
|
hasMore: (((u = e.metadata) == null ? void 0 : u.current_page) ?? 1) < (((d = e.metadata) == null ? void 0 : d.total_pages) ?? 1)
|
|
1356
1356
|
};
|
|
1357
1357
|
return {
|
|
1358
|
-
messages:
|
|
1359
|
-
pagination:
|
|
1358
|
+
messages: a,
|
|
1359
|
+
pagination: n,
|
|
1360
1360
|
chatId: e.chat_id,
|
|
1361
1361
|
sessionId: e.session_id
|
|
1362
1362
|
};
|
|
1363
1363
|
}
|
|
1364
1364
|
class V extends Error {
|
|
1365
|
-
constructor(t, s,
|
|
1366
|
-
super(t), this.statusCode = s, this.details =
|
|
1365
|
+
constructor(t, s, a) {
|
|
1366
|
+
super(t), this.statusCode = s, 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,
|
|
1370
|
+
async function le(e, t, s = 1, a = 50, n = !1) {
|
|
1371
1371
|
const { botId: r, apiBaseUrl: o = fe, authProvider: c } = t;
|
|
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(
|
|
1376
|
+
const l = Math.max(1, Math.min(s, 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)}`
|
|
@@ -1410,7 +1410,7 @@ async function le(e, t, s = 1, n = 50, a = !1) {
|
|
|
1410
1410
|
);
|
|
1411
1411
|
throw M("Failed to load conversation from server: %O", g), g;
|
|
1412
1412
|
}
|
|
1413
|
-
const f = await m.json(), I = ct(f,
|
|
1413
|
+
const f = await m.json(), I = ct(f, n);
|
|
1414
1414
|
return M(
|
|
1415
1415
|
"Loaded %d messages from server (page %d/%d)",
|
|
1416
1416
|
I.messages.length,
|
|
@@ -1429,8 +1429,8 @@ async function le(e, t, s = 1, n = 50, a = !1) {
|
|
|
1429
1429
|
}
|
|
1430
1430
|
}
|
|
1431
1431
|
async function Kt(e, t, s = !1) {
|
|
1432
|
-
const { apiBaseUrl:
|
|
1433
|
-
`${
|
|
1432
|
+
const { apiBaseUrl: a = fe, authProvider: n } = t, r = new URL(
|
|
1433
|
+
`${a}/wpcom/v2/odie/conversations/${encodeURIComponent(
|
|
1434
1434
|
e
|
|
1435
1435
|
)}`
|
|
1436
1436
|
);
|
|
@@ -1442,8 +1442,8 @@ async function Kt(e, t, s = !1) {
|
|
|
1442
1442
|
const o = {
|
|
1443
1443
|
"Content-Type": "application/json"
|
|
1444
1444
|
};
|
|
1445
|
-
if (
|
|
1446
|
-
const u = await
|
|
1445
|
+
if (n) {
|
|
1446
|
+
const u = await n();
|
|
1447
1447
|
Object.assign(o, u);
|
|
1448
1448
|
}
|
|
1449
1449
|
const c = await fetch(r.toString(), {
|
|
@@ -1471,23 +1471,23 @@ 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,
|
|
1475
|
-
const
|
|
1474
|
+
async function Lt(e, t, s = 10, a = !1) {
|
|
1475
|
+
const n = await le(
|
|
1476
1476
|
e,
|
|
1477
1477
|
t,
|
|
1478
1478
|
1,
|
|
1479
1479
|
50,
|
|
1480
|
-
|
|
1480
|
+
a
|
|
1481
1481
|
);
|
|
1482
|
-
if (!
|
|
1483
|
-
return
|
|
1482
|
+
if (!n.pagination.hasMore)
|
|
1483
|
+
return n;
|
|
1484
1484
|
const r = Math.min(
|
|
1485
|
-
|
|
1485
|
+
n.pagination.totalPages,
|
|
1486
1486
|
s
|
|
1487
|
-
), o = [...
|
|
1487
|
+
), o = [...n.messages], c = [];
|
|
1488
1488
|
for (let l = 2; l <= r; l++)
|
|
1489
1489
|
c.push(
|
|
1490
|
-
le(e, t, l, 50,
|
|
1490
|
+
le(e, t, l, 50, a)
|
|
1491
1491
|
);
|
|
1492
1492
|
try {
|
|
1493
1493
|
const l = await Promise.all(c);
|
|
@@ -1496,17 +1496,17 @@ async function Lt(e, t, s = 10, n = !1) {
|
|
|
1496
1496
|
return {
|
|
1497
1497
|
messages: o,
|
|
1498
1498
|
pagination: {
|
|
1499
|
-
...
|
|
1499
|
+
...n.pagination,
|
|
1500
1500
|
currentPage: r,
|
|
1501
|
-
hasMore: r <
|
|
1501
|
+
hasMore: r < n.pagination.totalPages
|
|
1502
1502
|
},
|
|
1503
|
-
chatId:
|
|
1503
|
+
chatId: n.chatId
|
|
1504
1504
|
};
|
|
1505
1505
|
} catch (l) {
|
|
1506
1506
|
return M("Failed to load all pages: %O", l), {
|
|
1507
1507
|
messages: o,
|
|
1508
|
-
pagination:
|
|
1509
|
-
chatId:
|
|
1508
|
+
pagination: n.pagination,
|
|
1509
|
+
chatId: n.chatId
|
|
1510
1510
|
};
|
|
1511
1511
|
}
|
|
1512
1512
|
}
|
|
@@ -1516,12 +1516,12 @@ function ut(e) {
|
|
|
1516
1516
|
const t = e.parts.filter(
|
|
1517
1517
|
(f) => f.type === "text"
|
|
1518
1518
|
), s = t.map((f) => f.text).join(`
|
|
1519
|
-
`),
|
|
1519
|
+
`), a = t.some(
|
|
1520
1520
|
(f) => {
|
|
1521
1521
|
var I;
|
|
1522
1522
|
return ((I = f.metadata) == null ? void 0 : I.contentType) === "context";
|
|
1523
1523
|
}
|
|
1524
|
-
) ? "context" : void 0,
|
|
1524
|
+
) ? "context" : void 0, n = e.parts.filter(
|
|
1525
1525
|
(f) => f.type === "data" && "toolCallId" in f.data && "arguments" in f.data
|
|
1526
1526
|
).map((f) => ({
|
|
1527
1527
|
toolCallId: f.data.toolCallId,
|
|
@@ -1537,15 +1537,15 @@ function ut(e) {
|
|
|
1537
1537
|
name: f.file.name,
|
|
1538
1538
|
mimeType: f.file.mimeType,
|
|
1539
1539
|
uri: f.file.uri
|
|
1540
|
-
})), l =
|
|
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
1543
|
content: s || "(No text content)",
|
|
1544
1544
|
timestamp: u,
|
|
1545
1545
|
...d !== void 0 && { archived: d },
|
|
1546
|
-
...
|
|
1546
|
+
...a && { contentType: a },
|
|
1547
1547
|
...o.length > 0 && { files: o },
|
|
1548
|
-
...
|
|
1548
|
+
...n.length > 0 && { toolCalls: n },
|
|
1549
1549
|
...r.length > 0 && { toolResults: r }
|
|
1550
1550
|
};
|
|
1551
1551
|
}
|
|
@@ -1605,27 +1605,27 @@ function dt(e) {
|
|
|
1605
1605
|
}
|
|
1606
1606
|
const B = /* @__PURE__ */ new Map(), gt = 50;
|
|
1607
1607
|
async function ft(e, t, s) {
|
|
1608
|
-
const
|
|
1609
|
-
if (B.set(
|
|
1610
|
-
const
|
|
1611
|
-
|
|
1608
|
+
const a = s || e;
|
|
1609
|
+
if (B.set(a, [...t]), B.size > gt) {
|
|
1610
|
+
const n = B.keys().next().value;
|
|
1611
|
+
n && B.delete(n);
|
|
1612
1612
|
}
|
|
1613
1613
|
if (!(typeof sessionStorage > "u"))
|
|
1614
1614
|
try {
|
|
1615
|
-
const
|
|
1616
|
-
storageKey:
|
|
1615
|
+
const n = {
|
|
1616
|
+
storageKey: a,
|
|
1617
1617
|
messages: t.map(ut),
|
|
1618
1618
|
lastUpdated: Date.now()
|
|
1619
1619
|
};
|
|
1620
1620
|
sessionStorage.setItem(
|
|
1621
|
-
`${me}_${
|
|
1622
|
-
JSON.stringify(
|
|
1621
|
+
`${me}_${a}`,
|
|
1622
|
+
JSON.stringify(n)
|
|
1623
1623
|
);
|
|
1624
|
-
} catch (
|
|
1624
|
+
} catch (n) {
|
|
1625
1625
|
M(
|
|
1626
1626
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1627
|
-
|
|
1628
|
-
|
|
1627
|
+
a,
|
|
1628
|
+
n
|
|
1629
1629
|
);
|
|
1630
1630
|
}
|
|
1631
1631
|
}
|
|
@@ -1636,17 +1636,17 @@ async function mt(e, t, s) {
|
|
|
1636
1636
|
);
|
|
1637
1637
|
}
|
|
1638
1638
|
async function pt(e, t) {
|
|
1639
|
-
const { odieBotId: s, authProvider:
|
|
1639
|
+
const { odieBotId: s, authProvider: a } = t;
|
|
1640
1640
|
if (!s)
|
|
1641
1641
|
throw new Error("odieBotId is required for server storage");
|
|
1642
|
-
const
|
|
1642
|
+
const n = fe;
|
|
1643
1643
|
try {
|
|
1644
1644
|
const o = await le(
|
|
1645
1645
|
e,
|
|
1646
1646
|
{
|
|
1647
1647
|
botId: s,
|
|
1648
|
-
apiBaseUrl:
|
|
1649
|
-
authProvider:
|
|
1648
|
+
apiBaseUrl: n,
|
|
1649
|
+
authProvider: a
|
|
1650
1650
|
},
|
|
1651
1651
|
1,
|
|
1652
1652
|
50
|
|
@@ -1674,18 +1674,18 @@ async function ht(e, t) {
|
|
|
1674
1674
|
if (typeof sessionStorage > "u")
|
|
1675
1675
|
return { messages: [] };
|
|
1676
1676
|
try {
|
|
1677
|
-
const
|
|
1677
|
+
const a = sessionStorage.getItem(
|
|
1678
1678
|
`${me}_${s}`
|
|
1679
1679
|
);
|
|
1680
|
-
if (
|
|
1681
|
-
const r = JSON.parse(
|
|
1680
|
+
if (a) {
|
|
1681
|
+
const r = JSON.parse(a).messages.map(dt);
|
|
1682
1682
|
return B.set(s, r), { messages: [...r] };
|
|
1683
1683
|
}
|
|
1684
|
-
} catch (
|
|
1684
|
+
} catch (a) {
|
|
1685
1685
|
M(
|
|
1686
1686
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1687
1687
|
s,
|
|
1688
|
-
|
|
1688
|
+
a
|
|
1689
1689
|
);
|
|
1690
1690
|
}
|
|
1691
1691
|
return { messages: [] };
|
|
@@ -1695,11 +1695,11 @@ async function yt(e, t) {
|
|
|
1695
1695
|
if (B.delete(s), !(typeof sessionStorage > "u"))
|
|
1696
1696
|
try {
|
|
1697
1697
|
sessionStorage.removeItem(`${me}_${s}`);
|
|
1698
|
-
} catch (
|
|
1698
|
+
} catch (a) {
|
|
1699
1699
|
M(
|
|
1700
1700
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1701
1701
|
s,
|
|
1702
|
-
|
|
1702
|
+
a
|
|
1703
1703
|
);
|
|
1704
1704
|
}
|
|
1705
1705
|
}
|
|
@@ -1717,33 +1717,33 @@ function z(e) {
|
|
|
1717
1717
|
function It(e) {
|
|
1718
1718
|
const t = [];
|
|
1719
1719
|
for (const s of e)
|
|
1720
|
-
for (const
|
|
1721
|
-
if (
|
|
1720
|
+
for (const a of s.parts)
|
|
1721
|
+
if (a.type === "text")
|
|
1722
1722
|
t.push({
|
|
1723
1723
|
type: "data",
|
|
1724
1724
|
data: {
|
|
1725
1725
|
role: s.role,
|
|
1726
|
-
text:
|
|
1726
|
+
text: a.text
|
|
1727
1727
|
}
|
|
1728
1728
|
});
|
|
1729
|
-
else if (
|
|
1730
|
-
t.push(
|
|
1731
|
-
else if (
|
|
1732
|
-
if ("role" in
|
|
1729
|
+
else if (a.type === "file")
|
|
1730
|
+
t.push(a);
|
|
1731
|
+
else if (a.type === "data") {
|
|
1732
|
+
if ("role" in a.data && "text" in a.data)
|
|
1733
1733
|
continue;
|
|
1734
|
-
if ("toolCallId" in
|
|
1735
|
-
t.push(
|
|
1734
|
+
if ("toolCallId" in a.data && "arguments" in a.data) {
|
|
1735
|
+
t.push(a);
|
|
1736
1736
|
continue;
|
|
1737
1737
|
}
|
|
1738
|
-
if ("toolCallId" in
|
|
1739
|
-
t.push(
|
|
1738
|
+
if ("toolCallId" in a.data && "result" in a.data) {
|
|
1739
|
+
t.push(a);
|
|
1740
1740
|
continue;
|
|
1741
1741
|
}
|
|
1742
1742
|
}
|
|
1743
1743
|
return t;
|
|
1744
1744
|
}
|
|
1745
1745
|
function we(e, t = [], s = []) {
|
|
1746
|
-
const
|
|
1746
|
+
const a = It(t), n = s.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",
|
|
@@ -1758,12 +1758,12 @@ function we(e, t = [], s = []) {
|
|
|
1758
1758
|
return {
|
|
1759
1759
|
role: "user",
|
|
1760
1760
|
parts: [
|
|
1761
|
-
...
|
|
1761
|
+
...a,
|
|
1762
1762
|
{
|
|
1763
1763
|
type: "text",
|
|
1764
1764
|
text: e
|
|
1765
1765
|
},
|
|
1766
|
-
...
|
|
1766
|
+
...n
|
|
1767
1767
|
],
|
|
1768
1768
|
kind: "message",
|
|
1769
1769
|
messageId: N(),
|
|
@@ -1777,7 +1777,7 @@ function wt(e) {
|
|
|
1777
1777
|
(t) => t.type === "data" && "toolCallId" in t.data && "result" in t.data
|
|
1778
1778
|
) : [];
|
|
1779
1779
|
}
|
|
1780
|
-
function
|
|
1780
|
+
function ne(e, t) {
|
|
1781
1781
|
if (typeof localStorage > "u") {
|
|
1782
1782
|
K("localStorage not available, cannot update session ID");
|
|
1783
1783
|
return;
|
|
@@ -1785,19 +1785,19 @@ function ae(e, t) {
|
|
|
1785
1785
|
try {
|
|
1786
1786
|
const s = localStorage.getItem(e);
|
|
1787
1787
|
if (s) {
|
|
1788
|
-
const
|
|
1789
|
-
|
|
1788
|
+
const a = JSON.parse(s), n = a.sessionId;
|
|
1789
|
+
a.sessionId = t, localStorage.setItem(e, JSON.stringify(a)), K(
|
|
1790
1790
|
"Updated localStorage[%s] session ID: %s -> %s",
|
|
1791
1791
|
e,
|
|
1792
|
-
|
|
1792
|
+
n,
|
|
1793
1793
|
t
|
|
1794
1794
|
);
|
|
1795
1795
|
} else {
|
|
1796
|
-
const
|
|
1796
|
+
const a = {
|
|
1797
1797
|
sessionId: t,
|
|
1798
1798
|
timestamp: Date.now()
|
|
1799
1799
|
};
|
|
1800
|
-
localStorage.setItem(e, JSON.stringify(
|
|
1800
|
+
localStorage.setItem(e, JSON.stringify(a)), K(
|
|
1801
1801
|
"Created new session in localStorage[%s]: %s",
|
|
1802
1802
|
e,
|
|
1803
1803
|
t
|
|
@@ -1816,31 +1816,31 @@ async function Tt(e) {
|
|
|
1816
1816
|
for (const s of e)
|
|
1817
1817
|
if (s.parts && Array.isArray(s.parts))
|
|
1818
1818
|
if (s.parts.some(
|
|
1819
|
-
(
|
|
1819
|
+
(n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
|
|
1820
1820
|
)) {
|
|
1821
|
-
const
|
|
1821
|
+
const n = ot(
|
|
1822
1822
|
s.parts
|
|
1823
1823
|
);
|
|
1824
1824
|
t.push({
|
|
1825
1825
|
...s,
|
|
1826
|
-
parts:
|
|
1826
|
+
parts: n
|
|
1827
1827
|
});
|
|
1828
1828
|
} else
|
|
1829
1829
|
t.push(s);
|
|
1830
1830
|
else
|
|
1831
1831
|
t.push(s);
|
|
1832
|
-
return
|
|
1832
|
+
return nt(), t;
|
|
1833
1833
|
}
|
|
1834
1834
|
function St() {
|
|
1835
1835
|
const e = /* @__PURE__ */ new Map();
|
|
1836
|
-
async function t(s,
|
|
1837
|
-
const
|
|
1838
|
-
if (
|
|
1836
|
+
async function t(s, a) {
|
|
1837
|
+
const n = e.get(s);
|
|
1838
|
+
if (n != null && n.sessionId)
|
|
1839
1839
|
try {
|
|
1840
1840
|
await ft(
|
|
1841
|
-
|
|
1842
|
-
|
|
1843
|
-
|
|
1841
|
+
n.sessionId,
|
|
1842
|
+
a,
|
|
1843
|
+
n.conversationStorageKey
|
|
1844
1844
|
);
|
|
1845
1845
|
} catch (r) {
|
|
1846
1846
|
K(
|
|
@@ -1850,12 +1850,12 @@ function St() {
|
|
|
1850
1850
|
}
|
|
1851
1851
|
}
|
|
1852
1852
|
return {
|
|
1853
|
-
async createAgent(s,
|
|
1853
|
+
async createAgent(s, a) {
|
|
1854
1854
|
if (e.has(s))
|
|
1855
1855
|
return e.get(s).client;
|
|
1856
|
-
const
|
|
1857
|
-
odieBotId:
|
|
1858
|
-
authProvider:
|
|
1856
|
+
const n = rt(a), r = a.sessionId || null, o = a.conversationStorageKey, c = a.sessionIdStorageKey, l = {
|
|
1857
|
+
odieBotId: a.odieBotId,
|
|
1858
|
+
authProvider: a.authProvider
|
|
1859
1859
|
};
|
|
1860
1860
|
let u = [];
|
|
1861
1861
|
if (r)
|
|
@@ -1872,7 +1872,7 @@ function St() {
|
|
|
1872
1872
|
);
|
|
1873
1873
|
}
|
|
1874
1874
|
const d = {
|
|
1875
|
-
client:
|
|
1875
|
+
client: n,
|
|
1876
1876
|
sessionId: r,
|
|
1877
1877
|
conversationStorageKey: o,
|
|
1878
1878
|
sessionIdStorageKey: c,
|
|
@@ -1880,11 +1880,11 @@ function St() {
|
|
|
1880
1880
|
conversationHistory: u,
|
|
1881
1881
|
currentAbortController: null
|
|
1882
1882
|
};
|
|
1883
|
-
return e.set(s, d),
|
|
1883
|
+
return e.set(s, d), n;
|
|
1884
1884
|
},
|
|
1885
1885
|
getAgent(s) {
|
|
1886
|
-
const
|
|
1887
|
-
return (
|
|
1886
|
+
const a = e.get(s);
|
|
1887
|
+
return (a == null ? void 0 : a.client) || null;
|
|
1888
1888
|
},
|
|
1889
1889
|
hasAgent(s) {
|
|
1890
1890
|
return e.has(s);
|
|
@@ -1892,15 +1892,15 @@ function St() {
|
|
|
1892
1892
|
removeAgent(s) {
|
|
1893
1893
|
return e.delete(s);
|
|
1894
1894
|
},
|
|
1895
|
-
async sendMessage(s,
|
|
1895
|
+
async sendMessage(s, a, n = {}) {
|
|
1896
1896
|
var A;
|
|
1897
1897
|
const r = e.get(s);
|
|
1898
1898
|
if (!r)
|
|
1899
1899
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1900
|
-
const { withHistory: o = !0, sessionId: c, ...l } =
|
|
1901
|
-
|
|
1900
|
+
const { withHistory: o = !0, sessionId: c, ...l } = n, { client: u, conversationHistory: d } = r, p = n.message || we(
|
|
1901
|
+
a,
|
|
1902
1902
|
d,
|
|
1903
|
-
|
|
1903
|
+
n.imageUrls
|
|
1904
1904
|
), m = await u.sendMessage({
|
|
1905
1905
|
message: p,
|
|
1906
1906
|
withHistory: o,
|
|
@@ -1913,7 +1913,7 @@ function St() {
|
|
|
1913
1913
|
"Session ID changed from %s to %s, updating localStorage",
|
|
1914
1914
|
g,
|
|
1915
1915
|
m.sessionId
|
|
1916
|
-
),
|
|
1916
|
+
), ne(
|
|
1917
1917
|
r.sessionIdStorageKey,
|
|
1918
1918
|
m.sessionId
|
|
1919
1919
|
));
|
|
@@ -1938,7 +1938,7 @@ function St() {
|
|
|
1938
1938
|
const I = [
|
|
1939
1939
|
...d,
|
|
1940
1940
|
// Store only the new content from the user message (without history parts)
|
|
1941
|
-
ie(
|
|
1941
|
+
ie(a),
|
|
1942
1942
|
// Add complete agent response with tool calls/results if present
|
|
1943
1943
|
...f ? [z(f)] : []
|
|
1944
1944
|
];
|
|
@@ -1957,7 +1957,7 @@ function St() {
|
|
|
1957
1957
|
h
|
|
1958
1958
|
), m;
|
|
1959
1959
|
},
|
|
1960
|
-
async *sendMessageStream(s,
|
|
1960
|
+
async *sendMessageStream(s, a, n = {}) {
|
|
1961
1961
|
var T, x, w, P, O, $;
|
|
1962
1962
|
const r = e.get(s);
|
|
1963
1963
|
if (!r)
|
|
@@ -1968,7 +1968,7 @@ function St() {
|
|
|
1968
1968
|
metadata: l,
|
|
1969
1969
|
sessionId: u,
|
|
1970
1970
|
...d
|
|
1971
|
-
} =
|
|
1971
|
+
} = n, { client: p } = r, m = l ? (({ contentType: S, ...y }) => y)(l) : void 0, f = new AbortController();
|
|
1972
1972
|
r.currentAbortController = f, c && c.addEventListener(
|
|
1973
1973
|
"abort",
|
|
1974
1974
|
() => f.abort()
|
|
@@ -1983,13 +1983,13 @@ function St() {
|
|
|
1983
1983
|
s,
|
|
1984
1984
|
A
|
|
1985
1985
|
);
|
|
1986
|
-
const g =
|
|
1987
|
-
|
|
1986
|
+
const g = n.message || we(
|
|
1987
|
+
a,
|
|
1988
1988
|
A,
|
|
1989
|
-
|
|
1989
|
+
n.imageUrls
|
|
1990
1990
|
);
|
|
1991
|
-
if (
|
|
1992
|
-
const { contentType: S, ...y } =
|
|
1991
|
+
if (n.metadata && !n.message) {
|
|
1992
|
+
const { contentType: S, ...y } = n.metadata;
|
|
1993
1993
|
if (S) {
|
|
1994
1994
|
const C = g.parts[g.parts.length - 1];
|
|
1995
1995
|
C && C.type === "text" && (C.metadata = {
|
|
@@ -2002,9 +2002,9 @@ function St() {
|
|
|
2002
2002
|
...y
|
|
2003
2003
|
});
|
|
2004
2004
|
}
|
|
2005
|
-
const i = ie(
|
|
2006
|
-
if (
|
|
2007
|
-
const S =
|
|
2005
|
+
const i = ie(a, n.metadata);
|
|
2006
|
+
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
2007
|
+
const S = n.imageUrls.map(
|
|
2008
2008
|
(y) => {
|
|
2009
2009
|
const C = typeof y == "string" ? y : y.url, v = typeof y == "string" ? void 0 : y.metadata, R = (v == null ? void 0 : v.fileType) || "image/jpeg";
|
|
2010
2010
|
return {
|
|
@@ -2042,7 +2042,7 @@ function St() {
|
|
|
2042
2042
|
r.sessionId = S.sessionId, S.sessionId && y !== S.sessionId && r.sessionIdStorageKey && (K(
|
|
2043
2043
|
"Session ID %s, updating localStorage",
|
|
2044
2044
|
y ? `changed from ${y} to ${S.sessionId}` : `received: ${S.sessionId}`
|
|
2045
|
-
),
|
|
2045
|
+
), ne(
|
|
2046
2046
|
r.sessionIdStorageKey,
|
|
2047
2047
|
S.sessionId
|
|
2048
2048
|
));
|
|
@@ -2106,40 +2106,40 @@ function St() {
|
|
|
2106
2106
|
r.currentAbortController = null;
|
|
2107
2107
|
},
|
|
2108
2108
|
async resetConversation(s) {
|
|
2109
|
-
const n = e.get(s);
|
|
2110
|
-
if (!n)
|
|
2111
|
-
throw new Error(`Agent with key "${s}" not found`);
|
|
2112
|
-
n.conversationHistory = [], n.sessionId && await yt(
|
|
2113
|
-
n.sessionId,
|
|
2114
|
-
n.conversationStorageKey
|
|
2115
|
-
);
|
|
2116
|
-
},
|
|
2117
|
-
async replaceMessages(s, n) {
|
|
2118
2109
|
const a = e.get(s);
|
|
2119
2110
|
if (!a)
|
|
2120
2111
|
throw new Error(`Agent with key "${s}" not found`);
|
|
2121
|
-
a.conversationHistory = [
|
|
2112
|
+
a.conversationHistory = [], a.sessionId && await yt(
|
|
2113
|
+
a.sessionId,
|
|
2114
|
+
a.conversationStorageKey
|
|
2115
|
+
);
|
|
2122
2116
|
},
|
|
2123
|
-
|
|
2117
|
+
async replaceMessages(s, a) {
|
|
2124
2118
|
const n = e.get(s);
|
|
2125
2119
|
if (!n)
|
|
2126
2120
|
throw new Error(`Agent with key "${s}" not found`);
|
|
2127
|
-
|
|
2121
|
+
n.conversationHistory = [...a], n.sessionId && await t(s, a);
|
|
2128
2122
|
},
|
|
2129
|
-
|
|
2123
|
+
getConversationHistory(s) {
|
|
2130
2124
|
const a = e.get(s);
|
|
2131
2125
|
if (!a)
|
|
2132
2126
|
throw new Error(`Agent with key "${s}" not found`);
|
|
2133
|
-
|
|
2134
|
-
a.sessionIdStorageKey,
|
|
2135
|
-
n
|
|
2136
|
-
);
|
|
2127
|
+
return [...a.conversationHistory];
|
|
2137
2128
|
},
|
|
2138
|
-
|
|
2129
|
+
updateSessionId(s, a) {
|
|
2139
2130
|
const n = e.get(s);
|
|
2140
2131
|
if (!n)
|
|
2141
2132
|
throw new Error(`Agent with key "${s}" not found`);
|
|
2142
|
-
n.
|
|
2133
|
+
n.sessionId = a, n.sessionIdStorageKey && ne(
|
|
2134
|
+
n.sessionIdStorageKey,
|
|
2135
|
+
a
|
|
2136
|
+
);
|
|
2137
|
+
},
|
|
2138
|
+
abortCurrentRequest(s) {
|
|
2139
|
+
const a = e.get(s);
|
|
2140
|
+
if (!a)
|
|
2141
|
+
throw new Error(`Agent with key "${s}" not found`);
|
|
2142
|
+
a.currentAbortController && (a.currentAbortController.abort(), a.currentAbortController = null);
|
|
2143
2143
|
},
|
|
2144
2144
|
clear() {
|
|
2145
2145
|
e.clear();
|
|
@@ -2165,28 +2165,28 @@ function Mt() {
|
|
|
2165
2165
|
});
|
|
2166
2166
|
},
|
|
2167
2167
|
[]
|
|
2168
|
-
),
|
|
2168
|
+
), a = F((r) => {
|
|
2169
2169
|
t((o) => o.filter((c) => c.id !== r));
|
|
2170
|
-
}, []),
|
|
2170
|
+
}, []), n = F(() => {
|
|
2171
2171
|
t([]);
|
|
2172
2172
|
}, []);
|
|
2173
2173
|
return {
|
|
2174
2174
|
registerMessageActions: s,
|
|
2175
|
-
unregisterMessageActions:
|
|
2176
|
-
clearAllMessageActions:
|
|
2175
|
+
unregisterMessageActions: a,
|
|
2176
|
+
clearAllMessageActions: n,
|
|
2177
2177
|
registrations: e
|
|
2178
2178
|
};
|
|
2179
2179
|
}
|
|
2180
2180
|
function xt(e, t) {
|
|
2181
|
-
return t.flatMap((
|
|
2182
|
-
id:
|
|
2183
|
-
label:
|
|
2184
|
-
icon:
|
|
2185
|
-
onClick:
|
|
2186
|
-
tooltip:
|
|
2187
|
-
disabled:
|
|
2188
|
-
pressed:
|
|
2189
|
-
showLabel:
|
|
2181
|
+
return t.flatMap((n) => typeof n.actions == "function" ? n.actions(e) : n.actions).filter((n) => !(n.condition && !n.condition(e))).map((n) => ({
|
|
2182
|
+
id: n.id,
|
|
2183
|
+
label: n.label,
|
|
2184
|
+
icon: n.icon,
|
|
2185
|
+
onClick: n.onClick,
|
|
2186
|
+
tooltip: n.tooltip,
|
|
2187
|
+
disabled: n.disabled || !1,
|
|
2188
|
+
pressed: n.pressed,
|
|
2189
|
+
showLabel: n.showLabel
|
|
2190
2190
|
}));
|
|
2191
2191
|
}
|
|
2192
2192
|
const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t = "40%") => ({
|
|
@@ -2213,7 +2213,7 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
|
|
|
2213
2213
|
return !1;
|
|
2214
2214
|
}))
|
|
2215
2215
|
return null;
|
|
2216
|
-
const
|
|
2216
|
+
const a = e.parts.map((l) => {
|
|
2217
2217
|
var u;
|
|
2218
2218
|
if (l.type === "text")
|
|
2219
2219
|
return {
|
|
@@ -2240,11 +2240,11 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
|
|
|
2240
2240
|
type: "text",
|
|
2241
2241
|
text: "[Unsupported content]"
|
|
2242
2242
|
};
|
|
2243
|
-
}),
|
|
2243
|
+
}), n = ((o = e.metadata) == null ? void 0 : o.timestamp) ?? Date.now(), r = {
|
|
2244
2244
|
id: e.messageId,
|
|
2245
2245
|
role: e.role === "agent" ? "agent" : "user",
|
|
2246
|
-
content:
|
|
2247
|
-
timestamp:
|
|
2246
|
+
content: a,
|
|
2247
|
+
timestamp: n,
|
|
2248
2248
|
archived: !!((c = e.metadata) != null && c.archived),
|
|
2249
2249
|
showIcon: e.role === "agent",
|
|
2250
2250
|
icon: e.role === "agent" ? "assistant" : void 0
|
|
@@ -2266,8 +2266,8 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
|
|
|
2266
2266
|
result: "No tools available"
|
|
2267
2267
|
})
|
|
2268
2268
|
}), bt = (e) => ["agentId", "agentUrl"].every((s) => {
|
|
2269
|
-
const
|
|
2270
|
-
return typeof
|
|
2269
|
+
const a = e[s];
|
|
2270
|
+
return typeof a == "string" && a.trim().length > 0;
|
|
2271
2271
|
});
|
|
2272
2272
|
function Bt(e) {
|
|
2273
2273
|
const t = {
|
|
@@ -2275,7 +2275,7 @@ function Bt(e) {
|
|
|
2275
2275
|
agentUrl: e.agentUrl,
|
|
2276
2276
|
sessionId: e.sessionId,
|
|
2277
2277
|
sessionIdStorageKey: e.sessionIdStorageKey
|
|
2278
|
-
}, s = bt(t), [
|
|
2278
|
+
}, s = bt(t), [a, n] = ve({
|
|
2279
2279
|
clientMessages: [],
|
|
2280
2280
|
uiMessages: [],
|
|
2281
2281
|
isProcessing: !1,
|
|
@@ -2304,11 +2304,11 @@ function Bt(e) {
|
|
|
2304
2304
|
(async () => {
|
|
2305
2305
|
const i = Q(), T = t.agentId;
|
|
2306
2306
|
if (i.hasAgent(T))
|
|
2307
|
-
t.sessionId ? (i.updateSessionId(T, t.sessionId), i.getConversationHistory(T).length === 0 &&
|
|
2307
|
+
t.sessionId ? (i.updateSessionId(T, t.sessionId), i.getConversationHistory(T).length === 0 && n((P) => ({
|
|
2308
2308
|
...P,
|
|
2309
2309
|
clientMessages: [],
|
|
2310
2310
|
uiMessages: []
|
|
2311
|
-
}))) : (i.updateSessionId(T, ""), await i.replaceMessages(T, []),
|
|
2311
|
+
}))) : (i.updateSessionId(T, ""), await i.replaceMessages(T, []), n((w) => ({
|
|
2312
2312
|
...w,
|
|
2313
2313
|
clientMessages: [],
|
|
2314
2314
|
uiMessages: []
|
|
@@ -2326,7 +2326,7 @@ function Bt(e) {
|
|
|
2326
2326
|
odieBotId: e.odieBotId
|
|
2327
2327
|
}), t.sessionId) {
|
|
2328
2328
|
const w = i.getConversationHistory(T);
|
|
2329
|
-
|
|
2329
|
+
n((P) => {
|
|
2330
2330
|
const O = d(w);
|
|
2331
2331
|
return {
|
|
2332
2332
|
...P,
|
|
@@ -2335,7 +2335,7 @@ function Bt(e) {
|
|
|
2335
2335
|
};
|
|
2336
2336
|
});
|
|
2337
2337
|
} else
|
|
2338
|
-
|
|
2338
|
+
n((w) => ({
|
|
2339
2339
|
...w,
|
|
2340
2340
|
clientMessages: [],
|
|
2341
2341
|
uiMessages: []
|
|
@@ -2373,7 +2373,7 @@ function Bt(e) {
|
|
|
2373
2373
|
archived: (i == null ? void 0 : i.archived) ?? !1,
|
|
2374
2374
|
showIcon: !1
|
|
2375
2375
|
};
|
|
2376
|
-
|
|
2376
|
+
n((y) => ({
|
|
2377
2377
|
...y,
|
|
2378
2378
|
uiMessages: [...y.uiMessages, O],
|
|
2379
2379
|
isProcessing: !0,
|
|
@@ -2391,12 +2391,12 @@ function Bt(e) {
|
|
|
2391
2391
|
g,
|
|
2392
2392
|
v
|
|
2393
2393
|
)) {
|
|
2394
|
-
if (R.progressMessage &&
|
|
2394
|
+
if (R.progressMessage && n((k) => ({
|
|
2395
2395
|
...k,
|
|
2396
2396
|
progressMessage: R.progressMessage || null
|
|
2397
2397
|
})), !R.final && R.text)
|
|
2398
2398
|
if (y)
|
|
2399
|
-
|
|
2399
|
+
n((k) => ({
|
|
2400
2400
|
...k,
|
|
2401
2401
|
uiMessages: k.uiMessages.map(
|
|
2402
2402
|
(b) => b.id === y ? {
|
|
@@ -2425,7 +2425,7 @@ function Bt(e) {
|
|
|
2425
2425
|
reactKey: y
|
|
2426
2426
|
// Stable key for React rendering
|
|
2427
2427
|
};
|
|
2428
|
-
|
|
2428
|
+
n((b) => ({
|
|
2429
2429
|
...b,
|
|
2430
2430
|
uiMessages: [
|
|
2431
2431
|
...b.uiMessages,
|
|
@@ -2439,12 +2439,12 @@ function Bt(e) {
|
|
|
2439
2439
|
R.status.message,
|
|
2440
2440
|
u.current
|
|
2441
2441
|
);
|
|
2442
|
-
b &&
|
|
2442
|
+
b && n((E) => {
|
|
2443
2443
|
const U = E.uiMessages.map(
|
|
2444
2444
|
(q) => {
|
|
2445
|
-
var _,
|
|
2445
|
+
var _, J;
|
|
2446
2446
|
if (q.id === k) {
|
|
2447
|
-
const H = b.content.length > 0 && ((_ = b.content[0]) == null ? void 0 : _.text) && ((
|
|
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;
|
|
2448
2448
|
return {
|
|
2449
2449
|
...b,
|
|
2450
2450
|
reactKey: q.reactKey || k,
|
|
@@ -2454,12 +2454,12 @@ function Bt(e) {
|
|
|
2454
2454
|
}
|
|
2455
2455
|
return q;
|
|
2456
2456
|
}
|
|
2457
|
-
),
|
|
2457
|
+
), D = T.getConversationHistory(
|
|
2458
2458
|
x
|
|
2459
2459
|
);
|
|
2460
2460
|
return {
|
|
2461
2461
|
...E,
|
|
2462
|
-
clientMessages:
|
|
2462
|
+
clientMessages: D,
|
|
2463
2463
|
uiMessages: U,
|
|
2464
2464
|
isProcessing: !1,
|
|
2465
2465
|
progressMessage: null
|
|
@@ -2469,7 +2469,7 @@ function Bt(e) {
|
|
|
2469
2469
|
}
|
|
2470
2470
|
if (!C) {
|
|
2471
2471
|
const R = T.getConversationHistory(x);
|
|
2472
|
-
|
|
2472
|
+
n((k) => {
|
|
2473
2473
|
let b = k.uiMessages;
|
|
2474
2474
|
y && (b = k.uiMessages.filter(
|
|
2475
2475
|
(_) => _.id !== y
|
|
@@ -2483,14 +2483,11 @@ function Bt(e) {
|
|
|
2483
2483
|
(_) => _ !== null
|
|
2484
2484
|
), U = new Set(
|
|
2485
2485
|
R.map((_) => _.messageId)
|
|
2486
|
-
),
|
|
2487
|
-
(_) =>
|
|
2488
|
-
var j;
|
|
2489
|
-
return !U.has(_.id) && ((j = _.content[0]) == null ? void 0 : j.type) === "component";
|
|
2490
|
-
}
|
|
2486
|
+
), D = b.filter(
|
|
2487
|
+
(_) => !U.has(_.id) && _.role !== "user"
|
|
2491
2488
|
), q = oe([
|
|
2492
2489
|
...E,
|
|
2493
|
-
...
|
|
2490
|
+
...D
|
|
2494
2491
|
]);
|
|
2495
2492
|
return {
|
|
2496
2493
|
...k,
|
|
@@ -2503,7 +2500,7 @@ function Bt(e) {
|
|
|
2503
2500
|
}
|
|
2504
2501
|
} catch (y) {
|
|
2505
2502
|
if (y instanceof Error && y.name === "AbortError") {
|
|
2506
|
-
M("Request was aborted by user"),
|
|
2503
|
+
M("Request was aborted by user"), n((v) => ({
|
|
2507
2504
|
...v,
|
|
2508
2505
|
isProcessing: !1,
|
|
2509
2506
|
progressMessage: null,
|
|
@@ -2513,7 +2510,7 @@ function Bt(e) {
|
|
|
2513
2510
|
return;
|
|
2514
2511
|
}
|
|
2515
2512
|
const C = y instanceof Error ? y.message : "Failed to send message";
|
|
2516
|
-
throw
|
|
2513
|
+
throw n((v) => ({
|
|
2517
2514
|
...v,
|
|
2518
2515
|
isProcessing: !1,
|
|
2519
2516
|
progressMessage: null,
|
|
@@ -2523,32 +2520,29 @@ function Bt(e) {
|
|
|
2523
2520
|
},
|
|
2524
2521
|
[t.agentId, s]
|
|
2525
2522
|
), m = F((g) => {
|
|
2526
|
-
|
|
2523
|
+
n((i) => ({
|
|
2527
2524
|
...i,
|
|
2528
2525
|
uiMessages: oe([...i.uiMessages, g])
|
|
2529
2526
|
}));
|
|
2530
2527
|
}, []), f = F((g) => {
|
|
2531
|
-
|
|
2528
|
+
n((i) => ({
|
|
2532
2529
|
...i,
|
|
2533
2530
|
suggestions: g
|
|
2534
2531
|
}));
|
|
2535
2532
|
}, []), I = F(() => {
|
|
2536
|
-
|
|
2533
|
+
n((g) => ({
|
|
2537
2534
|
...g,
|
|
2538
2535
|
suggestions: []
|
|
2539
2536
|
}));
|
|
2540
2537
|
}, []);
|
|
2541
2538
|
se(() => {
|
|
2542
|
-
|
|
2539
|
+
n((g) => {
|
|
2543
2540
|
if (g.clientMessages.length === 0)
|
|
2544
2541
|
return g;
|
|
2545
2542
|
const i = d(g.clientMessages), T = new Set(
|
|
2546
2543
|
g.clientMessages.map((w) => w.messageId)
|
|
2547
2544
|
), x = g.uiMessages.filter(
|
|
2548
|
-
(w) =>
|
|
2549
|
-
var P;
|
|
2550
|
-
return !T.has(w.id) && ((P = w.content[0]) == null ? void 0 : P.type) === "component";
|
|
2551
|
-
}
|
|
2545
|
+
(w) => !T.has(w.id) && w.role !== "user"
|
|
2552
2546
|
);
|
|
2553
2547
|
return {
|
|
2554
2548
|
...g,
|
|
@@ -2571,7 +2565,7 @@ function Bt(e) {
|
|
|
2571
2565
|
const i = Q(), T = t.agentId;
|
|
2572
2566
|
await i.replaceMessages(T, g);
|
|
2573
2567
|
const x = d(g);
|
|
2574
|
-
|
|
2568
|
+
n((w) => ({
|
|
2575
2569
|
...w,
|
|
2576
2570
|
clientMessages: g,
|
|
2577
2571
|
uiMessages: x
|
|
@@ -2581,12 +2575,12 @@ function Bt(e) {
|
|
|
2581
2575
|
);
|
|
2582
2576
|
return {
|
|
2583
2577
|
// AgentUI props
|
|
2584
|
-
messages:
|
|
2585
|
-
isProcessing:
|
|
2586
|
-
error:
|
|
2578
|
+
messages: a.uiMessages,
|
|
2579
|
+
isProcessing: a.isProcessing,
|
|
2580
|
+
error: a.error,
|
|
2587
2581
|
onSubmit: p,
|
|
2588
|
-
suggestions:
|
|
2589
|
-
progressMessage:
|
|
2582
|
+
suggestions: a.suggestions,
|
|
2583
|
+
progressMessage: a.progressMessage,
|
|
2590
2584
|
// UI management methods
|
|
2591
2585
|
registerSuggestions: f,
|
|
2592
2586
|
clearSuggestions: I,
|
|
@@ -2605,22 +2599,22 @@ function Bt(e) {
|
|
|
2605
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 || {});
|
|
2606
2600
|
const Te = "jetpack-ai-jwt-token", Rt = 30 * 60 * 1e3;
|
|
2607
2601
|
function Et() {
|
|
2608
|
-
var s,
|
|
2609
|
-
return ((
|
|
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);
|
|
2610
2604
|
}
|
|
2611
2605
|
async function Pt(e, t = !0) {
|
|
2612
2606
|
var l, u;
|
|
2613
2607
|
const s = localStorage.getItem(Te);
|
|
2614
|
-
let
|
|
2608
|
+
let a;
|
|
2615
2609
|
if (s)
|
|
2616
2610
|
try {
|
|
2617
|
-
|
|
2611
|
+
a = JSON.parse(s);
|
|
2618
2612
|
} catch (d) {
|
|
2619
2613
|
M("Invalid cached Jetpack token: %O", d);
|
|
2620
2614
|
}
|
|
2621
|
-
if (
|
|
2622
|
-
return
|
|
2623
|
-
const
|
|
2615
|
+
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && t)
|
|
2616
|
+
return a;
|
|
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;
|
|
2624
2618
|
let o = {
|
|
2625
2619
|
token: "",
|
|
2626
2620
|
blog_id: ""
|
|
@@ -2633,7 +2627,7 @@ async function Pt(e, t = !0) {
|
|
|
2633
2627
|
path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
|
|
2634
2628
|
credentials: "same-origin",
|
|
2635
2629
|
headers: {
|
|
2636
|
-
"X-WP-Nonce":
|
|
2630
|
+
"X-WP-Nonce": n || ""
|
|
2637
2631
|
},
|
|
2638
2632
|
method: "POST"
|
|
2639
2633
|
});
|
|
@@ -2688,8 +2682,8 @@ function zt(e) {
|
|
|
2688
2682
|
return (e == null ? void 0 : e._source) === "wordpress-ability";
|
|
2689
2683
|
}
|
|
2690
2684
|
function Gt(e, t = "agent", s = "wpcom") {
|
|
2691
|
-
const
|
|
2692
|
-
return `${s}-${t}-${
|
|
2685
|
+
const a = e.replace(/-/g, "_");
|
|
2686
|
+
return `${s}-${t}-${a}`;
|
|
2693
2687
|
}
|
|
2694
2688
|
function Ot(e) {
|
|
2695
2689
|
const t = e.split("-");
|
|
@@ -2697,15 +2691,15 @@ function Ot(e) {
|
|
|
2697
2691
|
throw new Error(
|
|
2698
2692
|
`Invalid Odie bot ID format: ${e}. Expected format: {product}-{type}-{slug}`
|
|
2699
2693
|
);
|
|
2700
|
-
const s = t[0],
|
|
2701
|
-
if (!["agent", "workflow", "chain"].includes(
|
|
2694
|
+
const s = t[0], a = t[1];
|
|
2695
|
+
if (!["agent", "workflow", "chain"].includes(a))
|
|
2702
2696
|
throw new Error(
|
|
2703
|
-
`Invalid Odie bot type: ${
|
|
2697
|
+
`Invalid Odie bot type: ${a}. Expected one of: agent, workflow, chain`
|
|
2704
2698
|
);
|
|
2705
|
-
const
|
|
2699
|
+
const n = a, r = t.slice(2).join("-"), o = r.replace(/_/g, "-");
|
|
2706
2700
|
return {
|
|
2707
2701
|
product: s,
|
|
2708
|
-
type:
|
|
2702
|
+
type: n,
|
|
2709
2703
|
slug: r,
|
|
2710
2704
|
agentId: o
|
|
2711
2705
|
};
|
|
@@ -2729,7 +2723,7 @@ export {
|
|
|
2729
2723
|
Fe as createRequestId,
|
|
2730
2724
|
je as createTaskId,
|
|
2731
2725
|
ie as createTextMessage,
|
|
2732
|
-
|
|
2726
|
+
j as extractTextFromMessage,
|
|
2733
2727
|
L as extractToolCallsFromMessage,
|
|
2734
2728
|
Q as getAgentManager,
|
|
2735
2729
|
Qt as isOdieBotId,
|