@automattic/agenttic-client 0.1.66 → 0.1.68
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/agents-api/index.d.ts +7 -0
- package/dist/agents-api/index.d.ts.map +1 -0
- package/dist/agents-api/index.js +20 -0
- package/dist/agents-api/normalizer.d.ts +19 -0
- package/dist/agents-api/normalizer.d.ts.map +1 -0
- package/dist/agents-api/rest.d.ts +17 -0
- package/dist/agents-api/rest.d.ts.map +1 -0
- package/dist/agents-api/run-control.d.ts +5 -0
- package/dist/agents-api/run-control.d.ts.map +1 -0
- package/dist/agents-api/tool-rendering.d.ts +3 -0
- package/dist/agents-api/tool-rendering.d.ts.map +1 -0
- package/dist/agents-api/types.d.ts +145 -0
- package/dist/agents-api/types.d.ts.map +1 -0
- package/dist/agents-api/useAgentsApiChat.d.ts +3 -0
- package/dist/agents-api/useAgentsApiChat.d.ts.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +354 -336
- package/dist/useAgentsApiChat-cj7ngIA5.js +314 -0
- package/package.json +5 -1
package/dist/index.js
CHANGED
|
@@ -2,15 +2,16 @@ var Ge = Object.defineProperty;
|
|
|
2
2
|
var Qe = (e, s, t) => s in e ? Ge(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
3
|
var ce = (e, s, t) => Qe(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
4
|
import Xe, { useMemo as _e, useCallback as D, useState as Ee, useRef as ue, useEffect as ae } from "react";
|
|
5
|
-
import { l as
|
|
6
|
-
import
|
|
5
|
+
import { l as v, f as Ne, a as z } from "./logger-aKHbTlwk.js";
|
|
6
|
+
import Se from "@wordpress/api-fetch";
|
|
7
|
+
import { m as ws, l as Ms, i as Ts, j as As, k as vs, h as Ss, f as Cs, o as xs, g as bs, n as Rs, a as ks, d as Ps, e as _s, b as Es, c as Ns, r as Hs, u as Os } from "./useAgentsApiChat-cj7ngIA5.js";
|
|
7
8
|
function ns(e) {
|
|
8
9
|
return _e(() => e ? {
|
|
9
10
|
getClientContext: () => {
|
|
10
11
|
try {
|
|
11
12
|
return e() || {};
|
|
12
13
|
} catch (a) {
|
|
13
|
-
return
|
|
14
|
+
return v("Error getting client context: %O", a), {};
|
|
14
15
|
}
|
|
15
16
|
}
|
|
16
17
|
} : void 0, [e]);
|
|
@@ -27,7 +28,7 @@ function he({
|
|
|
27
28
|
const l = await e();
|
|
28
29
|
r.push(...l);
|
|
29
30
|
} catch (l) {
|
|
30
|
-
|
|
31
|
+
v("Error getting available tools: %O", l);
|
|
31
32
|
}
|
|
32
33
|
return r;
|
|
33
34
|
}, [e]), n = D(
|
|
@@ -37,7 +38,7 @@ function he({
|
|
|
37
38
|
try {
|
|
38
39
|
return await s(r, l);
|
|
39
40
|
} catch (i) {
|
|
40
|
-
throw
|
|
41
|
+
throw v("Error executing tool %s: %O", r, i), i;
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
[s]
|
|
@@ -120,10 +121,10 @@ function et(e, s = "message/send", t = !1) {
|
|
|
120
121
|
};
|
|
121
122
|
return t && s === "message/stream" && (a.tokenStreaming = !0), a;
|
|
122
123
|
}
|
|
123
|
-
function
|
|
124
|
+
function L(e) {
|
|
124
125
|
return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
|
|
125
126
|
}
|
|
126
|
-
function
|
|
127
|
+
function Ce(e) {
|
|
127
128
|
if (!e || !e.parts || !Array.isArray(e.parts))
|
|
128
129
|
return;
|
|
129
130
|
const s = e.parts.find((t) => t.type === "progress" ? !0 : t.type === "data" ? "summary" in t.data && typeof t.data.summary == "string" : !1);
|
|
@@ -160,7 +161,7 @@ function st(e) {
|
|
|
160
161
|
metadata: {}
|
|
161
162
|
};
|
|
162
163
|
}
|
|
163
|
-
function
|
|
164
|
+
function V(e) {
|
|
164
165
|
return !e || !e.parts || !Array.isArray(e.parts) ? [] : e.parts.filter(
|
|
165
166
|
(s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
|
|
166
167
|
);
|
|
@@ -259,7 +260,7 @@ async function nt(e, s) {
|
|
|
259
260
|
parts: [...e.parts, ...t]
|
|
260
261
|
};
|
|
261
262
|
} catch (t) {
|
|
262
|
-
return
|
|
263
|
+
return v("Warning: Failed to get tools: %s", t), e;
|
|
263
264
|
}
|
|
264
265
|
}
|
|
265
266
|
function rt(e, s) {
|
|
@@ -275,7 +276,7 @@ function rt(e, s) {
|
|
|
275
276
|
parts: [...e.parts, a]
|
|
276
277
|
};
|
|
277
278
|
} catch (t) {
|
|
278
|
-
return
|
|
279
|
+
return v("Warning: Failed to get context: %s", t), e;
|
|
279
280
|
}
|
|
280
281
|
}
|
|
281
282
|
async function ot(e, s, t) {
|
|
@@ -308,7 +309,7 @@ function it(e, s = "") {
|
|
|
308
309
|
try {
|
|
309
310
|
t.push(JSON.parse(n)), o = i === -1 ? a.length : i + 1;
|
|
310
311
|
} catch (c) {
|
|
311
|
-
|
|
312
|
+
v("Failed to parse SSE event: %o", c), v("Problematic payload: %s", n);
|
|
312
313
|
}
|
|
313
314
|
n = "";
|
|
314
315
|
}
|
|
@@ -325,26 +326,26 @@ async function* lt(e, s = {}) {
|
|
|
325
326
|
let l = null, i = null;
|
|
326
327
|
try {
|
|
327
328
|
for (; ; ) {
|
|
328
|
-
const { done:
|
|
329
|
-
if (
|
|
329
|
+
const { done: d, value: A } = await a.read();
|
|
330
|
+
if (d)
|
|
330
331
|
break;
|
|
331
|
-
const f = n.decode(
|
|
332
|
+
const f = n.decode(A, { stream: !0 }), { events: h, nextBuffer: I } = it(f, o);
|
|
332
333
|
if (h && Array.isArray(h))
|
|
333
|
-
for (let
|
|
334
|
-
const y = h[
|
|
335
|
-
if (
|
|
336
|
-
requestAnimationFrame(() =>
|
|
334
|
+
for (let S = 0; S < h.length; S++) {
|
|
335
|
+
const y = h[S];
|
|
336
|
+
if (S > 0 && y.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((C) => {
|
|
337
|
+
requestAnimationFrame(() => C(void 0));
|
|
337
338
|
}), y.error)
|
|
338
339
|
throw new Error(
|
|
339
340
|
`Streaming error: ${y.error.message}`
|
|
340
341
|
);
|
|
341
342
|
if (t && y.method === "message/delta" && ((u = y.params) != null && u.delta)) {
|
|
342
|
-
const
|
|
343
|
+
const C = y.params.delta;
|
|
343
344
|
try {
|
|
344
|
-
let
|
|
345
|
-
ct(
|
|
346
|
-
|
|
347
|
-
),
|
|
345
|
+
let x = !1;
|
|
346
|
+
ct(C) ? (r.processToolCallDelta(C), x = !0) : C.deltaType === "content" && (r.processContentDelta(
|
|
347
|
+
C.content
|
|
348
|
+
), x = !0), x && (!l && y.params.id && (l = y.params.id), l && (yield {
|
|
348
349
|
id: l,
|
|
349
350
|
status: {
|
|
350
351
|
state: "working",
|
|
@@ -354,38 +355,38 @@ async function* lt(e, s = {}) {
|
|
|
354
355
|
text: r.getTextContent(),
|
|
355
356
|
kind: "delta"
|
|
356
357
|
}));
|
|
357
|
-
} catch (
|
|
358
|
-
|
|
358
|
+
} catch (x) {
|
|
359
|
+
v("Failed to process delta: %o", x);
|
|
359
360
|
}
|
|
360
361
|
} else if (y.result && y.result.status) {
|
|
361
362
|
l = y.result.id, i = y.result.status, (r.getTextContent() || r.getCurrentMessage().parts.length > 0) && r.reset();
|
|
362
|
-
const
|
|
363
|
+
const C = ((c = y.result.status) == null ? void 0 : c.message) || {
|
|
363
364
|
role: "agent",
|
|
364
365
|
parts: []
|
|
365
|
-
},
|
|
366
|
+
}, x = Ce(C);
|
|
366
367
|
yield {
|
|
367
368
|
id: y.result.id,
|
|
368
369
|
sessionId: y.result.sessionId,
|
|
369
370
|
status: y.result.status,
|
|
370
371
|
final: y.result.status.state === "completed" || y.result.status.state === "failed" || y.result.status.state === "canceled",
|
|
371
|
-
text:
|
|
372
|
-
progressMessage:
|
|
373
|
-
progressPhase:
|
|
372
|
+
text: L(C),
|
|
373
|
+
progressMessage: x == null ? void 0 : x.summary,
|
|
374
|
+
progressPhase: x == null ? void 0 : x.phase,
|
|
374
375
|
kind: "status"
|
|
375
376
|
};
|
|
376
377
|
} else if (y.id && y.result && (l = y.result.id, y.result.status)) {
|
|
377
|
-
const
|
|
378
|
+
const C = ((p = y.result.status) == null ? void 0 : p.message) || {
|
|
378
379
|
role: "agent",
|
|
379
380
|
parts: []
|
|
380
|
-
},
|
|
381
|
+
}, x = Ce(C);
|
|
381
382
|
yield {
|
|
382
383
|
id: y.result.id,
|
|
383
384
|
sessionId: y.result.sessionId,
|
|
384
385
|
status: y.result.status,
|
|
385
386
|
final: y.result.status.state === "completed" || y.result.status.state === "failed" || y.result.status.state === "canceled",
|
|
386
|
-
text:
|
|
387
|
-
progressMessage:
|
|
388
|
-
progressPhase:
|
|
387
|
+
text: L(C),
|
|
388
|
+
progressMessage: x == null ? void 0 : x.summary,
|
|
389
|
+
progressPhase: x == null ? void 0 : x.phase,
|
|
389
390
|
kind: "status"
|
|
390
391
|
};
|
|
391
392
|
}
|
|
@@ -502,13 +503,13 @@ class ut {
|
|
|
502
503
|
}
|
|
503
504
|
}
|
|
504
505
|
function Oe(e, s, t = "request") {
|
|
505
|
-
throw clearTimeout(s),
|
|
506
|
+
throw clearTimeout(s), v("%s failed with error: %O", t, e), e instanceof Error && (v("Error message: %s", e.message), v("Error stack: %s", e.stack)), e;
|
|
506
507
|
}
|
|
507
508
|
function Ue(e, s = "request") {
|
|
508
509
|
if (!e.ok)
|
|
509
510
|
throw new Error(`HTTP error! status: ${e.status}`);
|
|
510
511
|
}
|
|
511
|
-
function
|
|
512
|
+
function gt(e, s = "request") {
|
|
512
513
|
if (e.error)
|
|
513
514
|
throw new Error(
|
|
514
515
|
`Protocol ${s} error: ${e.error.message}`
|
|
@@ -517,7 +518,7 @@ function dt(e, s = "request") {
|
|
|
517
518
|
throw new Error(`No result in ${s} response`);
|
|
518
519
|
return e.result;
|
|
519
520
|
}
|
|
520
|
-
function
|
|
521
|
+
function dt(e, s = "streaming request") {
|
|
521
522
|
if (Ue(e, s), !e.body)
|
|
522
523
|
throw new Error(`No response body for ${s}`);
|
|
523
524
|
}
|
|
@@ -532,7 +533,7 @@ function ft(e, s) {
|
|
|
532
533
|
return `${e}/${s}`;
|
|
533
534
|
}
|
|
534
535
|
function mt(e, s, t, a) {
|
|
535
|
-
|
|
536
|
+
v("Request: %s %s", e, s), v("Headers: %o", t), a && v("Body: %s", Ne(a));
|
|
536
537
|
}
|
|
537
538
|
async function pt(e, s = !1) {
|
|
538
539
|
const t = {
|
|
@@ -566,28 +567,28 @@ function Fe(e, s, t, a) {
|
|
|
566
567
|
return a !== void 0 && (n.credentials = a), n;
|
|
567
568
|
}
|
|
568
569
|
async function oe(e, s, t, a, n, o) {
|
|
569
|
-
const { message: r, sessionId: l, taskId: i, metadata: u } = e, { agentId: c, agentUrl: p, authProvider:
|
|
570
|
+
const { message: r, sessionId: l, taskId: i, metadata: u } = e, { agentId: c, agentUrl: p, authProvider: d, proxy: A } = s, { isStreaming: f = !1, enableTokenStreaming: h = !1 } = t, I = l || o, S = ft(p, c), y = await ot(
|
|
570
571
|
r,
|
|
571
572
|
a,
|
|
572
573
|
n
|
|
573
|
-
),
|
|
574
|
+
), C = {
|
|
574
575
|
id: i,
|
|
575
576
|
message: y,
|
|
576
577
|
metadata: u
|
|
577
578
|
};
|
|
578
|
-
I && (
|
|
579
|
-
const
|
|
580
|
-
|
|
579
|
+
I && (C.sessionId = I);
|
|
580
|
+
const x = et(
|
|
581
|
+
C,
|
|
581
582
|
f ? "message/stream" : "message/send",
|
|
582
583
|
h && f
|
|
583
584
|
// Only enable token streaming if using SSE
|
|
584
|
-
), m = await pt(
|
|
585
|
-
return mt("POST",
|
|
586
|
-
request:
|
|
585
|
+
), m = await pt(d, f);
|
|
586
|
+
return mt("POST", S, m, x), {
|
|
587
|
+
request: x,
|
|
587
588
|
headers: m,
|
|
588
589
|
enhancedMessage: y,
|
|
589
590
|
effectiveSessionId: I,
|
|
590
|
-
fullAgentUrl:
|
|
591
|
+
fullAgentUrl: S
|
|
591
592
|
};
|
|
592
593
|
}
|
|
593
594
|
async function De(e, s, t = {}) {
|
|
@@ -596,27 +597,27 @@ async function De(e, s, t = {}) {
|
|
|
596
597
|
"request"
|
|
597
598
|
), p = i ? qe(c.signal, i) : c.signal;
|
|
598
599
|
try {
|
|
599
|
-
const
|
|
600
|
+
const d = Fe(
|
|
600
601
|
n,
|
|
601
602
|
JSON.stringify(a),
|
|
602
603
|
p,
|
|
603
604
|
l
|
|
604
605
|
);
|
|
605
|
-
|
|
606
|
-
method:
|
|
607
|
-
headers:
|
|
606
|
+
v("Making request to %s with options: %O", o, {
|
|
607
|
+
method: d.method,
|
|
608
|
+
headers: d.headers
|
|
608
609
|
});
|
|
609
|
-
const
|
|
610
|
-
clearTimeout(u), Ue(
|
|
611
|
-
const f = await
|
|
612
|
-
return
|
|
610
|
+
const A = await fetch(o, d);
|
|
611
|
+
clearTimeout(u), Ue(A, "request");
|
|
612
|
+
const f = await A.json();
|
|
613
|
+
return v(
|
|
613
614
|
"Response from %s: %d %O",
|
|
614
615
|
o,
|
|
615
|
-
|
|
616
|
+
A.status,
|
|
616
617
|
Ne(f)
|
|
617
|
-
),
|
|
618
|
-
} catch (
|
|
619
|
-
Oe(
|
|
618
|
+
), gt(f, "request");
|
|
619
|
+
} catch (d) {
|
|
620
|
+
Oe(d, u, "request");
|
|
620
621
|
}
|
|
621
622
|
}
|
|
622
623
|
async function* je(e, s, t) {
|
|
@@ -627,15 +628,15 @@ async function* je(e, s, t) {
|
|
|
627
628
|
} = t, { timeoutId: c, controller: p } = $e(
|
|
628
629
|
l,
|
|
629
630
|
"streaming request"
|
|
630
|
-
),
|
|
631
|
+
), d = i ? qe(p.signal, i) : p.signal;
|
|
631
632
|
try {
|
|
632
|
-
const
|
|
633
|
+
const A = JSON.stringify(a), f = Fe(
|
|
633
634
|
n,
|
|
634
|
-
|
|
635
|
-
|
|
635
|
+
A,
|
|
636
|
+
d,
|
|
636
637
|
r
|
|
637
638
|
), h = await fetch(o, f);
|
|
638
|
-
if (clearTimeout(c),
|
|
639
|
+
if (clearTimeout(c), dt(h, "streaming request"), !h.body)
|
|
639
640
|
throw new Error(
|
|
640
641
|
"Response body is null - server may not support streaming"
|
|
641
642
|
);
|
|
@@ -643,8 +644,8 @@ async function* je(e, s, t) {
|
|
|
643
644
|
yield* lt(h.body, {
|
|
644
645
|
supportDeltas: I
|
|
645
646
|
});
|
|
646
|
-
} catch (
|
|
647
|
-
Oe(
|
|
647
|
+
} catch (A) {
|
|
648
|
+
Oe(A, c, "streaming request");
|
|
648
649
|
}
|
|
649
650
|
}
|
|
650
651
|
const ht = 12e4;
|
|
@@ -671,7 +672,7 @@ async function ie(e, s, t, a, n) {
|
|
|
671
672
|
}
|
|
672
673
|
};
|
|
673
674
|
} catch (i) {
|
|
674
|
-
return
|
|
675
|
+
return v(
|
|
675
676
|
"Error executing ability %s: %O",
|
|
676
677
|
r.name,
|
|
677
678
|
i
|
|
@@ -690,7 +691,7 @@ async function ie(e, s, t, a, n) {
|
|
|
690
691
|
t
|
|
691
692
|
), returnToAgent: !0 };
|
|
692
693
|
} catch (i) {
|
|
693
|
-
return
|
|
694
|
+
return v(
|
|
694
695
|
"Error executing ability %s: %O",
|
|
695
696
|
r.name,
|
|
696
697
|
i
|
|
@@ -723,7 +724,7 @@ const we = /* @__PURE__ */ new Map();
|
|
|
723
724
|
async function yt(e, s) {
|
|
724
725
|
if (!e || !s || !e.getAvailableTools)
|
|
725
726
|
return !1;
|
|
726
|
-
const t =
|
|
727
|
+
const t = V(s);
|
|
727
728
|
if (t.length === 0)
|
|
728
729
|
return !1;
|
|
729
730
|
try {
|
|
@@ -760,7 +761,7 @@ function wt(e) {
|
|
|
760
761
|
return s;
|
|
761
762
|
});
|
|
762
763
|
}
|
|
763
|
-
async function
|
|
764
|
+
async function Le(e, s, t) {
|
|
764
765
|
const a = [], n = [];
|
|
765
766
|
let o = !1;
|
|
766
767
|
for (const r of e) {
|
|
@@ -772,8 +773,8 @@ async function Je(e, s, t) {
|
|
|
772
773
|
u,
|
|
773
774
|
t,
|
|
774
775
|
l
|
|
775
|
-
), { result: p, returnToAgent:
|
|
776
|
-
|
|
776
|
+
), { result: p, returnToAgent: d, agentMessage: A } = Ie(c);
|
|
777
|
+
d && (o = !0), A && n.push(Y(A)), a.push(
|
|
777
778
|
B(
|
|
778
779
|
l,
|
|
779
780
|
i,
|
|
@@ -793,7 +794,7 @@ async function Je(e, s, t) {
|
|
|
793
794
|
}
|
|
794
795
|
return { results: a, shouldReturnToAgent: o, agentMessages: n };
|
|
795
796
|
}
|
|
796
|
-
function
|
|
797
|
+
function xe(e) {
|
|
797
798
|
const s = [];
|
|
798
799
|
for (const t of e)
|
|
799
800
|
for (const a of t.parts)
|
|
@@ -806,7 +807,7 @@ function Ce(e) {
|
|
|
806
807
|
}) : (a.type === "data" || a.type === "file") && s.push(a);
|
|
807
808
|
return s;
|
|
808
809
|
}
|
|
809
|
-
async function
|
|
810
|
+
async function ge(e, s, t, a, n, o, r) {
|
|
810
811
|
const i = await oe(
|
|
811
812
|
{
|
|
812
813
|
message: s,
|
|
@@ -839,12 +840,12 @@ async function be(e, s, t, a, n, o, r, l, i = []) {
|
|
|
839
840
|
a,
|
|
840
841
|
n,
|
|
841
842
|
o
|
|
842
|
-
),
|
|
843
|
+
), d = je(p, t, {
|
|
843
844
|
...c,
|
|
844
845
|
abortSignal: r
|
|
845
846
|
});
|
|
846
|
-
return
|
|
847
|
-
|
|
847
|
+
return Je(
|
|
848
|
+
d,
|
|
848
849
|
a,
|
|
849
850
|
n,
|
|
850
851
|
t,
|
|
@@ -858,17 +859,17 @@ async function be(e, s, t, a, n, o, r, l, i = []) {
|
|
|
858
859
|
// Pass through the same request options
|
|
859
860
|
);
|
|
860
861
|
}
|
|
861
|
-
async function*
|
|
862
|
-
var u, c, p,
|
|
862
|
+
async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
863
|
+
var u, c, p, d, A, f, h, I, S, y, C, x;
|
|
863
864
|
for await (const m of e) {
|
|
864
865
|
if (m.sessionId && !n && (n = m.sessionId), yield m, m.status.state === "running" && m.status.message && s && await yt(
|
|
865
866
|
s,
|
|
866
867
|
m.status.message
|
|
867
868
|
)) {
|
|
868
|
-
const
|
|
869
|
+
const g = V(
|
|
869
870
|
m.status.message
|
|
870
871
|
);
|
|
871
|
-
for (const w of
|
|
872
|
+
for (const w of g) {
|
|
872
873
|
const { toolCallId: O, toolId: R, arguments: M } = w.data;
|
|
873
874
|
ie(
|
|
874
875
|
s,
|
|
@@ -877,7 +878,7 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
877
878
|
(c = (u = m.status) == null ? void 0 : u.message) == null ? void 0 : c.messageId,
|
|
878
879
|
O
|
|
879
880
|
).catch((b) => {
|
|
880
|
-
|
|
881
|
+
v("Tool execution failed for %s: %O", R, b);
|
|
881
882
|
});
|
|
882
883
|
}
|
|
883
884
|
yield {
|
|
@@ -887,7 +888,7 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
887
888
|
message: {
|
|
888
889
|
role: "agent",
|
|
889
890
|
kind: "message",
|
|
890
|
-
parts:
|
|
891
|
+
parts: g,
|
|
891
892
|
messageId: q()
|
|
892
893
|
}
|
|
893
894
|
},
|
|
@@ -896,14 +897,14 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
896
897
|
};
|
|
897
898
|
}
|
|
898
899
|
if (m.status.state === "input-required" && m.status.message && s) {
|
|
899
|
-
const
|
|
900
|
+
const g = V(
|
|
900
901
|
m.status.message
|
|
901
902
|
);
|
|
902
|
-
if (
|
|
903
|
+
if (g.length > 0) {
|
|
903
904
|
const w = [];
|
|
904
905
|
let O = !1;
|
|
905
906
|
const R = [], M = [];
|
|
906
|
-
for (const b of
|
|
907
|
+
for (const b of g) {
|
|
907
908
|
const {
|
|
908
909
|
toolCallId: k,
|
|
909
910
|
toolId: P,
|
|
@@ -914,7 +915,7 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
914
915
|
s,
|
|
915
916
|
P,
|
|
916
917
|
F,
|
|
917
|
-
(
|
|
918
|
+
(d = (p = m.status) == null ? void 0 : p.message) == null ? void 0 : d.messageId,
|
|
918
919
|
k
|
|
919
920
|
), { result: T, returnToAgent: E, agentMessage: _ } = Ie(U);
|
|
920
921
|
if (E && (O = !0), _ && M.push(
|
|
@@ -930,7 +931,7 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
930
931
|
), W.then((N) => {
|
|
931
932
|
H.resolvedValue = N;
|
|
932
933
|
}).catch((N) => {
|
|
933
|
-
|
|
934
|
+
v(
|
|
934
935
|
"Promise rejected for tool call %s: %O",
|
|
935
936
|
k,
|
|
936
937
|
N
|
|
@@ -961,7 +962,7 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
961
962
|
parts: w,
|
|
962
963
|
messageId: q()
|
|
963
964
|
}), O) {
|
|
964
|
-
const b =
|
|
965
|
+
const b = xe(r), k = re(
|
|
965
966
|
[],
|
|
966
967
|
// Empty array - tool results are already in historyDataParts
|
|
967
968
|
b
|
|
@@ -976,7 +977,7 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
976
977
|
text: ""
|
|
977
978
|
};
|
|
978
979
|
for (const E of M) {
|
|
979
|
-
const _ =
|
|
980
|
+
const _ = L(E);
|
|
980
981
|
yield {
|
|
981
982
|
id: m.id,
|
|
982
983
|
status: {
|
|
@@ -1005,14 +1006,14 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1005
1006
|
throw new Error(
|
|
1006
1007
|
"Continue task stream ended without final result"
|
|
1007
1008
|
);
|
|
1008
|
-
let U = (
|
|
1009
|
+
let U = (A = F.status) != null && A.message ? V(
|
|
1009
1010
|
F.status.message
|
|
1010
1011
|
) : [], T = F;
|
|
1011
1012
|
if (U.length > 0)
|
|
1012
1013
|
for (yield {
|
|
1013
1014
|
...F,
|
|
1014
1015
|
final: !1,
|
|
1015
|
-
text:
|
|
1016
|
+
text: L(
|
|
1016
1017
|
((f = F.status) == null ? void 0 : f.message) || {
|
|
1017
1018
|
parts: [],
|
|
1018
1019
|
messageId: q()
|
|
@@ -1025,10 +1026,10 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1025
1026
|
const {
|
|
1026
1027
|
results: E,
|
|
1027
1028
|
shouldReturnToAgent: _
|
|
1028
|
-
} = await
|
|
1029
|
+
} = await Le(
|
|
1029
1030
|
U,
|
|
1030
1031
|
s,
|
|
1031
|
-
(
|
|
1032
|
+
(S = (I = T.status) == null ? void 0 : I.message) == null ? void 0 : S.messageId
|
|
1032
1033
|
);
|
|
1033
1034
|
if (E.length > 0 && (yield {
|
|
1034
1035
|
id: T.id,
|
|
@@ -1045,7 +1046,7 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1045
1046
|
final: !1,
|
|
1046
1047
|
text: ""
|
|
1047
1048
|
}), _) {
|
|
1048
|
-
const j = o ?
|
|
1049
|
+
const j = o ? xe(
|
|
1049
1050
|
r
|
|
1050
1051
|
) : [], W = re(
|
|
1051
1052
|
E,
|
|
@@ -1068,14 +1069,14 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1068
1069
|
throw new Error(
|
|
1069
1070
|
"Continue task stream ended without final result"
|
|
1070
1071
|
);
|
|
1071
|
-
T = N, U = (y = T.status) != null && y.message ?
|
|
1072
|
+
T = N, U = (y = T.status) != null && y.message ? V(
|
|
1072
1073
|
T.status.message
|
|
1073
1074
|
) : [], U.length > 0 && (yield {
|
|
1074
1075
|
id: T.id,
|
|
1075
1076
|
status: T.status,
|
|
1076
1077
|
final: !1,
|
|
1077
|
-
text:
|
|
1078
|
-
((
|
|
1078
|
+
text: L(
|
|
1079
|
+
((C = T.status) == null ? void 0 : C.message) || {
|
|
1079
1080
|
parts: [],
|
|
1080
1081
|
messageId: q()
|
|
1081
1082
|
}
|
|
@@ -1087,8 +1088,8 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1087
1088
|
yield {
|
|
1088
1089
|
...T,
|
|
1089
1090
|
final: !0,
|
|
1090
|
-
text:
|
|
1091
|
-
((
|
|
1091
|
+
text: L(
|
|
1092
|
+
((x = T.status) == null ? void 0 : x.message) || {
|
|
1092
1093
|
parts: [],
|
|
1093
1094
|
messageId: q()
|
|
1094
1095
|
}
|
|
@@ -1106,10 +1107,10 @@ async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1106
1107
|
},
|
|
1107
1108
|
final: M.length === 0,
|
|
1108
1109
|
// Only final if no agent messages to follow
|
|
1109
|
-
text:
|
|
1110
|
+
text: L(b)
|
|
1110
1111
|
};
|
|
1111
1112
|
if (yield k, M.length > 0) {
|
|
1112
|
-
const P = M.map((U) =>
|
|
1113
|
+
const P = M.map((U) => L(U)).join(" "), F = Y(P);
|
|
1113
1114
|
yield {
|
|
1114
1115
|
id: k.id,
|
|
1115
1116
|
status: {
|
|
@@ -1145,8 +1146,8 @@ function Mt(e) {
|
|
|
1145
1146
|
};
|
|
1146
1147
|
return {
|
|
1147
1148
|
async sendMessage(p) {
|
|
1148
|
-
var
|
|
1149
|
-
const { abortSignal:
|
|
1149
|
+
var C, x;
|
|
1150
|
+
const { abortSignal: d } = p, A = p.sessionId || n || void 0, f = [];
|
|
1150
1151
|
f.push(p.message);
|
|
1151
1152
|
const h = await oe(
|
|
1152
1153
|
p,
|
|
@@ -1154,22 +1155,22 @@ function Mt(e) {
|
|
|
1154
1155
|
{ isStreaming: !1 },
|
|
1155
1156
|
r,
|
|
1156
1157
|
l,
|
|
1157
|
-
|
|
1158
|
+
A
|
|
1158
1159
|
);
|
|
1159
1160
|
let I = await De(
|
|
1160
1161
|
h,
|
|
1161
1162
|
c,
|
|
1162
|
-
{ abortSignal:
|
|
1163
|
+
{ abortSignal: d }
|
|
1163
1164
|
);
|
|
1164
|
-
const
|
|
1165
|
+
const S = [], y = [];
|
|
1165
1166
|
for (; I.status.message && r; ) {
|
|
1166
|
-
const m =
|
|
1167
|
+
const m = V(
|
|
1167
1168
|
I.status.message
|
|
1168
1169
|
);
|
|
1169
1170
|
if (m.length === 0)
|
|
1170
1171
|
break;
|
|
1171
|
-
|
|
1172
|
-
const
|
|
1172
|
+
S.push(...m);
|
|
1173
|
+
const g = [];
|
|
1173
1174
|
let w = !1;
|
|
1174
1175
|
for (const O of m) {
|
|
1175
1176
|
const {
|
|
@@ -1191,7 +1192,7 @@ function Mt(e) {
|
|
|
1191
1192
|
M,
|
|
1192
1193
|
P
|
|
1193
1194
|
);
|
|
1194
|
-
|
|
1195
|
+
g.push(T), S.push(T);
|
|
1195
1196
|
} catch (k) {
|
|
1196
1197
|
const P = B(
|
|
1197
1198
|
R,
|
|
@@ -1199,27 +1200,27 @@ function Mt(e) {
|
|
|
1199
1200
|
void 0,
|
|
1200
1201
|
k instanceof Error ? k.message : String(k)
|
|
1201
1202
|
);
|
|
1202
|
-
|
|
1203
|
+
g.push(P), S.push(P);
|
|
1203
1204
|
}
|
|
1204
1205
|
}
|
|
1205
1206
|
if (f.push(I.status.message), w) {
|
|
1206
|
-
const O = re(
|
|
1207
|
-
I = await
|
|
1207
|
+
const O = re(g);
|
|
1208
|
+
I = await ge(
|
|
1208
1209
|
I.id,
|
|
1209
1210
|
O,
|
|
1210
1211
|
c,
|
|
1211
1212
|
r,
|
|
1212
1213
|
l,
|
|
1213
|
-
|
|
1214
|
-
|
|
1214
|
+
A,
|
|
1215
|
+
d
|
|
1215
1216
|
);
|
|
1216
1217
|
} else
|
|
1217
1218
|
break;
|
|
1218
1219
|
}
|
|
1219
|
-
if (
|
|
1220
|
+
if (S.length > 0 && (C = I.status) != null && C.message) {
|
|
1220
1221
|
const m = {
|
|
1221
1222
|
...I.status.message,
|
|
1222
|
-
parts:
|
|
1223
|
+
parts: S
|
|
1223
1224
|
};
|
|
1224
1225
|
I = {
|
|
1225
1226
|
...I,
|
|
@@ -1230,20 +1231,20 @@ function Mt(e) {
|
|
|
1230
1231
|
};
|
|
1231
1232
|
}
|
|
1232
1233
|
if (y.length > 0) {
|
|
1233
|
-
const m = y.map((w) =>
|
|
1234
|
+
const m = y.map((w) => L(w)).join(" "), g = Y(m);
|
|
1234
1235
|
return {
|
|
1235
1236
|
...I,
|
|
1236
1237
|
// Keep the enhanced message with tool results
|
|
1237
1238
|
// The agent message will be handled separately by the caller
|
|
1238
1239
|
text: m,
|
|
1239
|
-
agentMessage:
|
|
1240
|
+
agentMessage: g
|
|
1240
1241
|
// Add this for the caller to handle
|
|
1241
1242
|
};
|
|
1242
1243
|
}
|
|
1243
1244
|
return {
|
|
1244
1245
|
...I,
|
|
1245
|
-
text:
|
|
1246
|
-
((
|
|
1246
|
+
text: L(
|
|
1247
|
+
((x = I.status) == null ? void 0 : x.message) || {
|
|
1247
1248
|
parts: [],
|
|
1248
1249
|
messageId: q()
|
|
1249
1250
|
}
|
|
@@ -1252,11 +1253,11 @@ function Mt(e) {
|
|
|
1252
1253
|
},
|
|
1253
1254
|
async *sendMessageStream(p) {
|
|
1254
1255
|
const {
|
|
1255
|
-
withHistory:
|
|
1256
|
-
abortSignal:
|
|
1256
|
+
withHistory: d = !0,
|
|
1257
|
+
abortSignal: A,
|
|
1257
1258
|
enableStreaming: f
|
|
1258
|
-
} = p, h = p.sessionId || n || void 0, I = f ?? i,
|
|
1259
|
-
|
|
1259
|
+
} = p, h = p.sessionId || n || void 0, I = f ?? i, S = [];
|
|
1260
|
+
S.push(p.message);
|
|
1260
1261
|
const y = await oe(
|
|
1261
1262
|
p,
|
|
1262
1263
|
c,
|
|
@@ -1268,25 +1269,25 @@ function Mt(e) {
|
|
|
1268
1269
|
r,
|
|
1269
1270
|
l,
|
|
1270
1271
|
h
|
|
1271
|
-
),
|
|
1272
|
+
), C = je(
|
|
1272
1273
|
y,
|
|
1273
1274
|
c,
|
|
1274
1275
|
{
|
|
1275
1276
|
enableTokenStreaming: I,
|
|
1276
1277
|
// Token streaming is optional
|
|
1277
1278
|
streamingTimeout: o,
|
|
1278
|
-
abortSignal:
|
|
1279
|
+
abortSignal: A
|
|
1279
1280
|
}
|
|
1280
1281
|
);
|
|
1281
|
-
yield*
|
|
1282
|
-
|
|
1282
|
+
yield* Je(
|
|
1283
|
+
C,
|
|
1283
1284
|
r,
|
|
1284
1285
|
l,
|
|
1285
1286
|
c,
|
|
1286
1287
|
h,
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1288
|
+
d,
|
|
1289
|
+
S,
|
|
1290
|
+
A,
|
|
1290
1291
|
{
|
|
1291
1292
|
isStreaming: !0,
|
|
1292
1293
|
enableTokenStreaming: I,
|
|
@@ -1294,41 +1295,41 @@ function Mt(e) {
|
|
|
1294
1295
|
}
|
|
1295
1296
|
);
|
|
1296
1297
|
},
|
|
1297
|
-
async continueTask(p,
|
|
1298
|
-
var
|
|
1299
|
-
const f = me(
|
|
1300
|
-
let I = await
|
|
1298
|
+
async continueTask(p, d, A) {
|
|
1299
|
+
var S;
|
|
1300
|
+
const f = me(d);
|
|
1301
|
+
let I = await ge(
|
|
1301
1302
|
p,
|
|
1302
1303
|
f,
|
|
1303
1304
|
c,
|
|
1304
1305
|
r,
|
|
1305
1306
|
l,
|
|
1306
|
-
|
|
1307
|
+
A
|
|
1307
1308
|
);
|
|
1308
1309
|
for (; I.status.state === "input-required" && I.status.message && r; ) {
|
|
1309
|
-
const y =
|
|
1310
|
+
const y = V(
|
|
1310
1311
|
I.status.message
|
|
1311
1312
|
);
|
|
1312
1313
|
if (y.length === 0)
|
|
1313
1314
|
break;
|
|
1314
|
-
const { results:
|
|
1315
|
-
if (
|
|
1316
|
-
const m = re(
|
|
1317
|
-
I = await
|
|
1315
|
+
const { results: C, shouldReturnToAgent: x } = await Le(y, r);
|
|
1316
|
+
if (x) {
|
|
1317
|
+
const m = re(C);
|
|
1318
|
+
I = await ge(
|
|
1318
1319
|
I.id,
|
|
1319
1320
|
m,
|
|
1320
1321
|
c,
|
|
1321
1322
|
r,
|
|
1322
1323
|
l,
|
|
1323
|
-
|
|
1324
|
+
A
|
|
1324
1325
|
);
|
|
1325
1326
|
} else
|
|
1326
1327
|
break;
|
|
1327
1328
|
}
|
|
1328
1329
|
return {
|
|
1329
1330
|
...I,
|
|
1330
|
-
text:
|
|
1331
|
-
((
|
|
1331
|
+
text: L(
|
|
1332
|
+
((S = I.status) == null ? void 0 : S.message) || {
|
|
1332
1333
|
parts: [],
|
|
1333
1334
|
messageId: q()
|
|
1334
1335
|
}
|
|
@@ -1395,7 +1396,7 @@ function Tt(e) {
|
|
|
1395
1396
|
}
|
|
1396
1397
|
};
|
|
1397
1398
|
}
|
|
1398
|
-
function
|
|
1399
|
+
function At(e) {
|
|
1399
1400
|
if (e.role !== "tool_call" && e.role !== "tool_result")
|
|
1400
1401
|
return !1;
|
|
1401
1402
|
try {
|
|
@@ -1404,9 +1405,9 @@ function vt(e) {
|
|
|
1404
1405
|
return !1;
|
|
1405
1406
|
}
|
|
1406
1407
|
}
|
|
1407
|
-
function
|
|
1408
|
+
function vt(e, s = !1) {
|
|
1408
1409
|
var o, r, l, i, u, c;
|
|
1409
|
-
const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!s ||
|
|
1410
|
+
const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!s || At(p)) : !0).map(Tt), n = {
|
|
1410
1411
|
currentPage: ((o = e.metadata) == null ? void 0 : o.current_page) ?? 1,
|
|
1411
1412
|
itemsPerPage: ((r = e.metadata) == null ? void 0 : r.items_per_page) ?? 10,
|
|
1412
1413
|
totalPages: ((l = e.metadata) == null ? void 0 : l.total_pages) ?? 1,
|
|
@@ -1437,7 +1438,7 @@ async function pe(e, s, t = 1, a = 50, n = !1) {
|
|
|
1437
1438
|
o
|
|
1438
1439
|
)}/${encodeURIComponent(e)}`
|
|
1439
1440
|
);
|
|
1440
|
-
c.searchParams.set("page_number", i.toString()), c.searchParams.set("items_per_page", u.toString()),
|
|
1441
|
+
c.searchParams.set("page_number", i.toString()), c.searchParams.set("items_per_page", u.toString()), v(
|
|
1441
1442
|
"Loading conversation from server: %s (page %d)",
|
|
1442
1443
|
e,
|
|
1443
1444
|
i
|
|
@@ -1450,27 +1451,27 @@ async function pe(e, s, t = 1, a = 50, n = !1) {
|
|
|
1450
1451
|
const h = await l();
|
|
1451
1452
|
Object.assign(p, h);
|
|
1452
1453
|
}
|
|
1453
|
-
const
|
|
1454
|
+
const d = await fetch(c.toString(), {
|
|
1454
1455
|
method: "GET",
|
|
1455
1456
|
headers: p
|
|
1456
1457
|
});
|
|
1457
|
-
if (!
|
|
1458
|
-
const h = await
|
|
1459
|
-
let I = `Failed to load conversation from server: ${
|
|
1458
|
+
if (!d.ok) {
|
|
1459
|
+
const h = await d.text();
|
|
1460
|
+
let I = `Failed to load conversation from server: ${d.status} ${d.statusText}`;
|
|
1460
1461
|
try {
|
|
1461
1462
|
const y = JSON.parse(h);
|
|
1462
1463
|
y.message && (I = y.message);
|
|
1463
1464
|
} catch {
|
|
1464
1465
|
}
|
|
1465
|
-
const
|
|
1466
|
+
const S = new Z(
|
|
1466
1467
|
I,
|
|
1467
|
-
|
|
1468
|
+
d.status,
|
|
1468
1469
|
h
|
|
1469
1470
|
);
|
|
1470
|
-
throw
|
|
1471
|
+
throw v("Failed to load conversation from server: %O", S), S;
|
|
1471
1472
|
}
|
|
1472
|
-
const
|
|
1473
|
-
return
|
|
1473
|
+
const A = await d.json(), f = vt(A, n);
|
|
1474
|
+
return v(
|
|
1474
1475
|
"Loaded %d messages from server (page %d/%d)",
|
|
1475
1476
|
f.messages.length,
|
|
1476
1477
|
f.pagination.currentPage,
|
|
@@ -1479,12 +1480,12 @@ async function pe(e, s, t = 1, a = 50, n = !1) {
|
|
|
1479
1480
|
} catch (p) {
|
|
1480
1481
|
if (p instanceof Z)
|
|
1481
1482
|
throw p;
|
|
1482
|
-
const
|
|
1483
|
+
const d = new Z(
|
|
1483
1484
|
`Network error loading conversation: ${p.message}`,
|
|
1484
1485
|
void 0,
|
|
1485
1486
|
p
|
|
1486
1487
|
);
|
|
1487
|
-
throw
|
|
1488
|
+
throw v("Network error loading conversation: %O", p), d;
|
|
1488
1489
|
}
|
|
1489
1490
|
}
|
|
1490
1491
|
async function cs(e, s, t = !1) {
|
|
@@ -1496,7 +1497,7 @@ async function cs(e, s, t = !1) {
|
|
|
1496
1497
|
o.searchParams.set(
|
|
1497
1498
|
"truncation_method",
|
|
1498
1499
|
t ? "first_message" : "last_message"
|
|
1499
|
-
),
|
|
1500
|
+
), v("Listing conversations from server for bot: %s", e);
|
|
1500
1501
|
try {
|
|
1501
1502
|
const r = {
|
|
1502
1503
|
"Content-Type": "application/json"
|
|
@@ -1515,10 +1516,10 @@ async function cs(e, s, t = !1) {
|
|
|
1515
1516
|
l.status,
|
|
1516
1517
|
u
|
|
1517
1518
|
);
|
|
1518
|
-
throw
|
|
1519
|
+
throw v("Failed to list conversations: %O", p), p;
|
|
1519
1520
|
}
|
|
1520
1521
|
const i = await l.json();
|
|
1521
|
-
return
|
|
1522
|
+
return v("Loaded %d conversations from server", i.length), i;
|
|
1522
1523
|
} catch (r) {
|
|
1523
1524
|
if (r instanceof Z)
|
|
1524
1525
|
throw r;
|
|
@@ -1527,7 +1528,7 @@ async function cs(e, s, t = !1) {
|
|
|
1527
1528
|
void 0,
|
|
1528
1529
|
r
|
|
1529
1530
|
);
|
|
1530
|
-
throw
|
|
1531
|
+
throw v("Network error listing conversations: %O", r), l;
|
|
1531
1532
|
}
|
|
1532
1533
|
}
|
|
1533
1534
|
async function us(e, s, t = 10, a = !1) {
|
|
@@ -1562,7 +1563,7 @@ async function us(e, s, t = 10, a = !1) {
|
|
|
1562
1563
|
chatId: n.chatId
|
|
1563
1564
|
};
|
|
1564
1565
|
} catch (i) {
|
|
1565
|
-
return
|
|
1566
|
+
return v("Failed to load all pages: %O", i), {
|
|
1566
1567
|
messages: r,
|
|
1567
1568
|
pagination: n.pagination,
|
|
1568
1569
|
chatId: n.chatId
|
|
@@ -1570,8 +1571,8 @@ async function us(e, s, t = 10, a = !1) {
|
|
|
1570
1571
|
}
|
|
1571
1572
|
}
|
|
1572
1573
|
const Te = "a8c_agenttic_conversation_history";
|
|
1573
|
-
function
|
|
1574
|
-
var
|
|
1574
|
+
function St(e) {
|
|
1575
|
+
var d, A;
|
|
1575
1576
|
const s = e.parts.filter(
|
|
1576
1577
|
(f) => f.type === "text"
|
|
1577
1578
|
), t = s.map((f) => f.text).join(`
|
|
@@ -1610,7 +1611,7 @@ function xt(e) {
|
|
|
1610
1611
|
break;
|
|
1611
1612
|
}
|
|
1612
1613
|
}
|
|
1613
|
-
const u = n.length > 0 || o.length > 0 ? "agent" : e.role, c = ((
|
|
1614
|
+
const u = n.length > 0 || o.length > 0 ? "agent" : e.role, c = ((d = e.metadata) == null ? void 0 : d.timestamp) ?? Date.now(), p = ((A = e.metadata) == null ? void 0 : A.archived) ?? void 0;
|
|
1614
1615
|
return {
|
|
1615
1616
|
role: u,
|
|
1616
1617
|
content: t || "(No text content)",
|
|
@@ -1623,7 +1624,7 @@ function xt(e) {
|
|
|
1623
1624
|
...l && { agentMessageData: l }
|
|
1624
1625
|
};
|
|
1625
1626
|
}
|
|
1626
|
-
function
|
|
1627
|
+
function Ct(e) {
|
|
1627
1628
|
const s = [];
|
|
1628
1629
|
if (e.content && e.content !== "(No text content)" && s.push({
|
|
1629
1630
|
type: "text",
|
|
@@ -1681,10 +1682,10 @@ function At(e) {
|
|
|
1681
1682
|
}
|
|
1682
1683
|
};
|
|
1683
1684
|
}
|
|
1684
|
-
const G = /* @__PURE__ */ new Map(),
|
|
1685
|
+
const G = /* @__PURE__ */ new Map(), xt = 50;
|
|
1685
1686
|
async function bt(e, s, t) {
|
|
1686
1687
|
const a = t || e;
|
|
1687
|
-
if (G.set(a, [...s]), G.size >
|
|
1688
|
+
if (G.set(a, [...s]), G.size > xt) {
|
|
1688
1689
|
const n = G.keys().next().value;
|
|
1689
1690
|
n && G.delete(n);
|
|
1690
1691
|
}
|
|
@@ -1692,7 +1693,7 @@ async function bt(e, s, t) {
|
|
|
1692
1693
|
try {
|
|
1693
1694
|
const n = {
|
|
1694
1695
|
storageKey: a,
|
|
1695
|
-
messages: s.map(
|
|
1696
|
+
messages: s.map(St),
|
|
1696
1697
|
lastUpdated: Date.now()
|
|
1697
1698
|
};
|
|
1698
1699
|
sessionStorage.setItem(
|
|
@@ -1700,7 +1701,7 @@ async function bt(e, s, t) {
|
|
|
1700
1701
|
JSON.stringify(n)
|
|
1701
1702
|
);
|
|
1702
1703
|
} catch (n) {
|
|
1703
|
-
|
|
1704
|
+
v(
|
|
1704
1705
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1705
1706
|
a,
|
|
1706
1707
|
n
|
|
@@ -1729,7 +1730,7 @@ async function kt(e, s) {
|
|
|
1729
1730
|
1,
|
|
1730
1731
|
50
|
|
1731
1732
|
);
|
|
1732
|
-
return
|
|
1733
|
+
return v(
|
|
1733
1734
|
"Loaded conversation from server: %s (%d messages, page %d/%d)",
|
|
1734
1735
|
e,
|
|
1735
1736
|
r.messages.length,
|
|
@@ -1740,7 +1741,7 @@ async function kt(e, s) {
|
|
|
1740
1741
|
pagination: r.pagination
|
|
1741
1742
|
};
|
|
1742
1743
|
} catch (o) {
|
|
1743
|
-
throw
|
|
1744
|
+
throw v("Failed to load conversation from server: %O", o), o;
|
|
1744
1745
|
}
|
|
1745
1746
|
}
|
|
1746
1747
|
async function Pt(e, s) {
|
|
@@ -1756,11 +1757,11 @@ async function Pt(e, s) {
|
|
|
1756
1757
|
`${Te}_${t}`
|
|
1757
1758
|
);
|
|
1758
1759
|
if (a) {
|
|
1759
|
-
const o = JSON.parse(a).messages.map(
|
|
1760
|
+
const o = JSON.parse(a).messages.map(Ct);
|
|
1760
1761
|
return G.set(t, o), { messages: [...o] };
|
|
1761
1762
|
}
|
|
1762
1763
|
} catch (a) {
|
|
1763
|
-
|
|
1764
|
+
v(
|
|
1764
1765
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1765
1766
|
t,
|
|
1766
1767
|
a
|
|
@@ -1774,7 +1775,7 @@ async function _t(e, s) {
|
|
|
1774
1775
|
try {
|
|
1775
1776
|
sessionStorage.removeItem(`${Te}_${t}`);
|
|
1776
1777
|
} catch (a) {
|
|
1777
|
-
|
|
1778
|
+
v(
|
|
1778
1779
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1779
1780
|
t,
|
|
1780
1781
|
a
|
|
@@ -1792,7 +1793,7 @@ function Q(e) {
|
|
|
1792
1793
|
}
|
|
1793
1794
|
};
|
|
1794
1795
|
}
|
|
1795
|
-
function
|
|
1796
|
+
function Ke(e) {
|
|
1796
1797
|
const s = [];
|
|
1797
1798
|
for (const t of e)
|
|
1798
1799
|
for (const a of t.parts)
|
|
@@ -1821,7 +1822,7 @@ function Le(e) {
|
|
|
1821
1822
|
return s;
|
|
1822
1823
|
}
|
|
1823
1824
|
function Re(e, s = [], t = []) {
|
|
1824
|
-
const a =
|
|
1825
|
+
const a = Ke(s), n = t.map((o) => {
|
|
1825
1826
|
const r = typeof o == "string" ? o : o.url, l = typeof o == "object" ? o.metadata : void 0, i = (l == null ? void 0 : l.fileType) || "image/jpeg";
|
|
1826
1827
|
return {
|
|
1827
1828
|
type: "file",
|
|
@@ -1869,16 +1870,16 @@ function Nt(e) {
|
|
|
1869
1870
|
return !1;
|
|
1870
1871
|
}
|
|
1871
1872
|
}
|
|
1872
|
-
function
|
|
1873
|
+
function de(e, s) {
|
|
1873
1874
|
if (typeof localStorage > "u") {
|
|
1874
|
-
|
|
1875
|
+
z("localStorage not available, cannot update session ID");
|
|
1875
1876
|
return;
|
|
1876
1877
|
}
|
|
1877
1878
|
try {
|
|
1878
1879
|
const t = localStorage.getItem(e);
|
|
1879
1880
|
if (t) {
|
|
1880
1881
|
const a = JSON.parse(t), n = a.sessionId;
|
|
1881
|
-
a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)),
|
|
1882
|
+
a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)), z(
|
|
1882
1883
|
"Updated localStorage[%s] session ID: %s -> %s",
|
|
1883
1884
|
e,
|
|
1884
1885
|
n,
|
|
@@ -1889,14 +1890,14 @@ function ge(e, s) {
|
|
|
1889
1890
|
sessionId: s,
|
|
1890
1891
|
timestamp: Date.now()
|
|
1891
1892
|
};
|
|
1892
|
-
localStorage.setItem(e, JSON.stringify(a)),
|
|
1893
|
+
localStorage.setItem(e, JSON.stringify(a)), z(
|
|
1893
1894
|
"Created new session in localStorage[%s]: %s",
|
|
1894
1895
|
e,
|
|
1895
1896
|
s
|
|
1896
1897
|
);
|
|
1897
1898
|
}
|
|
1898
1899
|
} catch (t) {
|
|
1899
|
-
|
|
1900
|
+
z(
|
|
1900
1901
|
"Failed to update localStorage sessionId to %s: %O",
|
|
1901
1902
|
s,
|
|
1902
1903
|
t
|
|
@@ -1935,7 +1936,7 @@ function Ot() {
|
|
|
1935
1936
|
n.conversationStorageKey
|
|
1936
1937
|
);
|
|
1937
1938
|
} catch (o) {
|
|
1938
|
-
|
|
1939
|
+
z(
|
|
1939
1940
|
`Failed to persist conversation history for agent ${t}:`,
|
|
1940
1941
|
o
|
|
1941
1942
|
);
|
|
@@ -1958,7 +1959,7 @@ function Ot() {
|
|
|
1958
1959
|
i
|
|
1959
1960
|
)).messages;
|
|
1960
1961
|
} catch (p) {
|
|
1961
|
-
|
|
1962
|
+
z(
|
|
1962
1963
|
`Failed to load conversation history for agent ${t} with session ${o}:`,
|
|
1963
1964
|
p
|
|
1964
1965
|
);
|
|
@@ -1993,34 +1994,34 @@ function Ot() {
|
|
|
1993
1994
|
a,
|
|
1994
1995
|
c,
|
|
1995
1996
|
n.imageUrls
|
|
1996
|
-
),
|
|
1997
|
+
), d = await u.sendMessage({
|
|
1997
1998
|
message: p,
|
|
1998
1999
|
withHistory: r,
|
|
1999
2000
|
sessionId: l || o.sessionId || void 0,
|
|
2000
2001
|
...i
|
|
2001
2002
|
});
|
|
2002
|
-
if (
|
|
2003
|
-
const
|
|
2004
|
-
o.sessionId =
|
|
2003
|
+
if (d.sessionId) {
|
|
2004
|
+
const S = o.sessionId;
|
|
2005
|
+
o.sessionId = d.sessionId, S && d.sessionId && S !== d.sessionId && o.sessionIdStorageKey && (z(
|
|
2005
2006
|
"Session ID changed from %s to %s, updating localStorage",
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
),
|
|
2007
|
+
S,
|
|
2008
|
+
d.sessionId
|
|
2009
|
+
), de(
|
|
2009
2010
|
o.sessionIdStorageKey,
|
|
2010
|
-
|
|
2011
|
+
d.sessionId
|
|
2011
2012
|
));
|
|
2012
2013
|
}
|
|
2013
|
-
let
|
|
2014
|
-
if ((I =
|
|
2015
|
-
const
|
|
2016
|
-
(
|
|
2017
|
-
), y =
|
|
2018
|
-
(
|
|
2014
|
+
let A = null;
|
|
2015
|
+
if ((I = d.status) != null && I.message) {
|
|
2016
|
+
const S = d.status.message.parts.filter(
|
|
2017
|
+
(C) => C.type === "data" && "toolCallId" in C.data && ("arguments" in C.data || "result" in C.data)
|
|
2018
|
+
), y = d.status.message.parts.filter(
|
|
2019
|
+
(C) => C.type === "text"
|
|
2019
2020
|
);
|
|
2020
|
-
|
|
2021
|
+
A = {
|
|
2021
2022
|
role: "agent",
|
|
2022
2023
|
kind: "message",
|
|
2023
|
-
parts: [...
|
|
2024
|
+
parts: [...S, ...y],
|
|
2024
2025
|
messageId: q(),
|
|
2025
2026
|
metadata: {
|
|
2026
2027
|
timestamp: Date.now()
|
|
@@ -2032,25 +2033,25 @@ function Ot() {
|
|
|
2032
2033
|
// Store only the new content from the user message (without history parts)
|
|
2033
2034
|
me(a),
|
|
2034
2035
|
// Add complete agent response with tool calls/results if present
|
|
2035
|
-
...
|
|
2036
|
+
...A ? [Q(A)] : []
|
|
2036
2037
|
];
|
|
2037
2038
|
let h = f;
|
|
2038
|
-
if (
|
|
2039
|
-
const
|
|
2040
|
-
|
|
2039
|
+
if (d.agentMessage) {
|
|
2040
|
+
const S = Q(
|
|
2041
|
+
d.agentMessage
|
|
2041
2042
|
);
|
|
2042
2043
|
h = [
|
|
2043
2044
|
...f,
|
|
2044
|
-
|
|
2045
|
+
S
|
|
2045
2046
|
];
|
|
2046
2047
|
}
|
|
2047
2048
|
return o.conversationHistory = h, r && await s(
|
|
2048
2049
|
t,
|
|
2049
2050
|
h
|
|
2050
|
-
),
|
|
2051
|
+
), d;
|
|
2051
2052
|
},
|
|
2052
2053
|
async *sendMessageStream(t, a, n = {}) {
|
|
2053
|
-
var
|
|
2054
|
+
var x, m, g, w, O, R;
|
|
2054
2055
|
const o = e.get(t);
|
|
2055
2056
|
if (!o)
|
|
2056
2057
|
throw new Error(`Agent with key "${t}" not found`);
|
|
@@ -2061,7 +2062,7 @@ function Ot() {
|
|
|
2061
2062
|
sessionId: u,
|
|
2062
2063
|
message: c,
|
|
2063
2064
|
...p
|
|
2064
|
-
} = n, { client:
|
|
2065
|
+
} = n, { client: d } = o, A = i ? (({ contentType: M, ...b }) => b)(i) : void 0, f = new AbortController();
|
|
2065
2066
|
o.currentAbortController = f, l && l.addEventListener(
|
|
2066
2067
|
"abort",
|
|
2067
2068
|
() => f.abort()
|
|
@@ -2069,17 +2070,17 @@ function Ot() {
|
|
|
2069
2070
|
let h = [
|
|
2070
2071
|
...o.conversationHistory
|
|
2071
2072
|
], I = [];
|
|
2072
|
-
const
|
|
2073
|
+
const S = await Ht(
|
|
2073
2074
|
h
|
|
2074
2075
|
);
|
|
2075
|
-
o.conversationHistory =
|
|
2076
|
+
o.conversationHistory = S, h = S, r && await s(
|
|
2076
2077
|
t,
|
|
2077
|
-
|
|
2078
|
+
S
|
|
2078
2079
|
);
|
|
2079
2080
|
let y;
|
|
2080
2081
|
if (c) {
|
|
2081
|
-
const M =
|
|
2082
|
-
|
|
2082
|
+
const M = Ke(
|
|
2083
|
+
S
|
|
2083
2084
|
);
|
|
2084
2085
|
y = {
|
|
2085
2086
|
...c,
|
|
@@ -2088,7 +2089,7 @@ function Ot() {
|
|
|
2088
2089
|
} else
|
|
2089
2090
|
y = Re(
|
|
2090
2091
|
a,
|
|
2091
|
-
|
|
2092
|
+
S,
|
|
2092
2093
|
n.imageUrls
|
|
2093
2094
|
);
|
|
2094
2095
|
if (n.metadata && !c) {
|
|
@@ -2105,7 +2106,7 @@ function Ot() {
|
|
|
2105
2106
|
...b
|
|
2106
2107
|
});
|
|
2107
2108
|
}
|
|
2108
|
-
const
|
|
2109
|
+
const C = c || me(a, n.metadata);
|
|
2109
2110
|
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
2110
2111
|
const M = n.imageUrls.map(
|
|
2111
2112
|
(b) => {
|
|
@@ -2121,37 +2122,37 @@ function Ot() {
|
|
|
2121
2122
|
};
|
|
2122
2123
|
}
|
|
2123
2124
|
);
|
|
2124
|
-
|
|
2125
|
+
C.parts.push(...M);
|
|
2125
2126
|
}
|
|
2126
2127
|
h = [
|
|
2127
2128
|
...h,
|
|
2128
|
-
|
|
2129
|
+
C
|
|
2129
2130
|
], o.conversationHistory = h, r && await s(
|
|
2130
2131
|
t,
|
|
2131
2132
|
h
|
|
2132
2133
|
);
|
|
2133
|
-
for await (const M of
|
|
2134
|
+
for await (const M of d.sendMessageStream({
|
|
2134
2135
|
message: y,
|
|
2135
2136
|
withHistory: r,
|
|
2136
2137
|
sessionId: u || o.sessionId || void 0,
|
|
2137
2138
|
abortSignal: f.signal,
|
|
2138
2139
|
...p,
|
|
2139
|
-
...
|
|
2140
|
-
metadata:
|
|
2140
|
+
...A && Object.keys(A).length > 0 && {
|
|
2141
|
+
metadata: A
|
|
2141
2142
|
}
|
|
2142
2143
|
})) {
|
|
2143
2144
|
if (M.sessionId) {
|
|
2144
2145
|
const b = o.sessionId;
|
|
2145
|
-
o.sessionId = M.sessionId, M.sessionId && b !== M.sessionId && o.sessionIdStorageKey && (
|
|
2146
|
+
o.sessionId = M.sessionId, M.sessionId && b !== M.sessionId && o.sessionIdStorageKey && (z(
|
|
2146
2147
|
"Session ID %s, updating localStorage",
|
|
2147
2148
|
b ? `changed from ${b} to ${M.sessionId}` : `received: ${M.sessionId}`
|
|
2148
|
-
),
|
|
2149
|
+
), de(
|
|
2149
2150
|
o.sessionIdStorageKey,
|
|
2150
2151
|
M.sessionId
|
|
2151
2152
|
));
|
|
2152
2153
|
}
|
|
2153
|
-
if (((
|
|
2154
|
-
I =
|
|
2154
|
+
if (((x = M.status) == null ? void 0 : x.state) === "input-required" && ((m = M.status) != null && m.message)) {
|
|
2155
|
+
I = V(
|
|
2155
2156
|
M.status.message
|
|
2156
2157
|
).map(
|
|
2157
2158
|
(P) => P.data.toolCallId
|
|
@@ -2167,7 +2168,7 @@ function Ot() {
|
|
|
2167
2168
|
h
|
|
2168
2169
|
);
|
|
2169
2170
|
}
|
|
2170
|
-
if (((
|
|
2171
|
+
if (((g = M.status) == null ? void 0 : g.state) === "working" && ((w = M.status) != null && w.message) && !M.final) {
|
|
2171
2172
|
const k = Et(
|
|
2172
2173
|
M.status.message
|
|
2173
2174
|
).filter(
|
|
@@ -2278,7 +2279,7 @@ function Ot() {
|
|
|
2278
2279
|
const n = e.get(t);
|
|
2279
2280
|
if (!n)
|
|
2280
2281
|
throw new Error(`Agent with key "${t}" not found`);
|
|
2281
|
-
n.sessionId = a, n.sessionIdStorageKey &&
|
|
2282
|
+
n.sessionId = a, n.sessionIdStorageKey && de(
|
|
2282
2283
|
n.sessionIdStorageKey,
|
|
2283
2284
|
a
|
|
2284
2285
|
);
|
|
@@ -2390,7 +2391,7 @@ const Ft = (e) => e.type === "text" ? {
|
|
|
2390
2391
|
userMessage: n,
|
|
2391
2392
|
prompt: o
|
|
2392
2393
|
} : null;
|
|
2393
|
-
},
|
|
2394
|
+
}, Lt = (e, s) => {
|
|
2394
2395
|
const t = Be(e, s);
|
|
2395
2396
|
return t ? {
|
|
2396
2397
|
...t,
|
|
@@ -2404,7 +2405,7 @@ const Ft = (e) => e.type === "text" ? {
|
|
|
2404
2405
|
}
|
|
2405
2406
|
return null;
|
|
2406
2407
|
};
|
|
2407
|
-
function
|
|
2408
|
+
function Jt({
|
|
2408
2409
|
agentId: e,
|
|
2409
2410
|
isValidConfig: s,
|
|
2410
2411
|
isSendingRef: t,
|
|
@@ -2419,32 +2420,32 @@ function Kt({
|
|
|
2419
2420
|
const c = X().getConversationHistory(e), p = (i == null ? void 0 : i.id) ?? ke(c);
|
|
2420
2421
|
if (!p)
|
|
2421
2422
|
return;
|
|
2422
|
-
const
|
|
2423
|
+
const d = Lt(
|
|
2423
2424
|
c,
|
|
2424
2425
|
p
|
|
2425
2426
|
);
|
|
2426
|
-
if (!
|
|
2427
|
+
if (!d)
|
|
2427
2428
|
return;
|
|
2428
|
-
const
|
|
2429
|
+
const A = {
|
|
2429
2430
|
clientMessages: c,
|
|
2430
2431
|
uiMessages: a.current.uiMessages
|
|
2431
2432
|
}, f = n(
|
|
2432
|
-
|
|
2433
|
+
d.baseHistory
|
|
2433
2434
|
);
|
|
2434
2435
|
try {
|
|
2435
|
-
await o(
|
|
2436
|
+
await o(d.prompt, void 0, {
|
|
2436
2437
|
initialClientMessages: [
|
|
2437
|
-
...
|
|
2438
|
-
|
|
2438
|
+
...d.baseHistory,
|
|
2439
|
+
d.userMessage
|
|
2439
2440
|
],
|
|
2440
2441
|
initialUiMessages: f,
|
|
2441
|
-
messageOverride:
|
|
2442
|
+
messageOverride: d.userMessage,
|
|
2442
2443
|
preserveUiOnlyMessages: !1,
|
|
2443
|
-
truncateHistoryTo:
|
|
2444
|
-
restoreOnError:
|
|
2444
|
+
truncateHistoryTo: d.baseHistory,
|
|
2445
|
+
restoreOnError: A
|
|
2445
2446
|
});
|
|
2446
2447
|
} catch (h) {
|
|
2447
|
-
|
|
2448
|
+
v("Regenerate failed; conversation restored", h);
|
|
2448
2449
|
}
|
|
2449
2450
|
},
|
|
2450
2451
|
[
|
|
@@ -2458,18 +2459,18 @@ function Kt({
|
|
|
2458
2459
|
);
|
|
2459
2460
|
return { getRegenerateHandler: D(
|
|
2460
2461
|
(i) => {
|
|
2461
|
-
const u = a.current, c = X(), p = c.hasAgent(e) ? c.getConversationHistory(e) : u.clientMessages,
|
|
2462
|
-
return !s || i && i.role !== "agent" || !
|
|
2462
|
+
const u = a.current, c = X(), p = c.hasAgent(e) ? c.getConversationHistory(e) : u.clientMessages, d = (i == null ? void 0 : i.id) ?? ke(p);
|
|
2463
|
+
return !s || i && i.role !== "agent" || !d || !We(
|
|
2463
2464
|
p,
|
|
2464
|
-
|
|
2465
|
+
d
|
|
2465
2466
|
) ? null : () => r(i);
|
|
2466
2467
|
},
|
|
2467
2468
|
[e, r, s, a]
|
|
2468
2469
|
) };
|
|
2469
2470
|
}
|
|
2470
|
-
const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp),
|
|
2471
|
+
const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s) => e.filter(
|
|
2471
2472
|
(t) => !s.has(t.id) && t.role !== "user"
|
|
2472
|
-
),
|
|
2473
|
+
), ze = (e, s = "40%") => ({
|
|
2473
2474
|
type: "component",
|
|
2474
2475
|
component: () => Xe.createElement("img", {
|
|
2475
2476
|
src: e,
|
|
@@ -2503,7 +2504,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Lt = (e, s)
|
|
|
2503
2504
|
if (i.type === "file") {
|
|
2504
2505
|
const c = i.file.uri || (i.file.mimeType && i.file.bytes ? `data:${i.file.mimeType};base64,${i.file.bytes}` : void 0);
|
|
2505
2506
|
if (c)
|
|
2506
|
-
return
|
|
2507
|
+
return ze(c);
|
|
2507
2508
|
}
|
|
2508
2509
|
if (i.type === "data") {
|
|
2509
2510
|
const c = i.data;
|
|
@@ -2517,7 +2518,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Lt = (e, s)
|
|
|
2517
2518
|
} : Array.isArray(c.sources) && c.sources.length > 0 ? {
|
|
2518
2519
|
type: "data",
|
|
2519
2520
|
data: c
|
|
2520
|
-
} : (
|
|
2521
|
+
} : (v("Dropping unrecognized data part", c), null);
|
|
2521
2522
|
}
|
|
2522
2523
|
return {
|
|
2523
2524
|
type: "text",
|
|
@@ -2553,17 +2554,17 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Lt = (e, s)
|
|
|
2553
2554
|
success: !0,
|
|
2554
2555
|
result: "No tools available"
|
|
2555
2556
|
})
|
|
2556
|
-
}),
|
|
2557
|
+
}), zt = (e) => ["agentId", "agentUrl"].every((t) => {
|
|
2557
2558
|
const a = e[t];
|
|
2558
2559
|
return typeof a == "string" && a.trim().length > 0;
|
|
2559
2560
|
});
|
|
2560
|
-
function
|
|
2561
|
+
function gs(e) {
|
|
2561
2562
|
const s = {
|
|
2562
2563
|
agentId: e.agentId,
|
|
2563
2564
|
agentUrl: e.agentUrl,
|
|
2564
2565
|
sessionId: e.sessionId,
|
|
2565
2566
|
sessionIdStorageKey: e.sessionIdStorageKey
|
|
2566
|
-
}, t =
|
|
2567
|
+
}, t = zt(s), [a, n] = Ee({
|
|
2567
2568
|
clientMessages: [],
|
|
2568
2569
|
uiMessages: [],
|
|
2569
2570
|
isProcessing: !1,
|
|
@@ -2584,10 +2585,10 @@ function ds(e) {
|
|
|
2584
2585
|
ae(() => {
|
|
2585
2586
|
p.current = i;
|
|
2586
2587
|
}, [i]);
|
|
2587
|
-
const
|
|
2588
|
+
const d = D(
|
|
2588
2589
|
(m) => m.map(
|
|
2589
|
-
(
|
|
2590
|
-
).filter((
|
|
2590
|
+
(g) => ne(g, p.current)
|
|
2591
|
+
).filter((g) => g !== null),
|
|
2591
2592
|
[]
|
|
2592
2593
|
// registrationsRef is stable, so no deps needed
|
|
2593
2594
|
);
|
|
@@ -2595,18 +2596,18 @@ function ds(e) {
|
|
|
2595
2596
|
if (!t)
|
|
2596
2597
|
return;
|
|
2597
2598
|
(async () => {
|
|
2598
|
-
const
|
|
2599
|
-
if (
|
|
2600
|
-
s.sessionId ? (
|
|
2599
|
+
const g = X(), w = s.agentId;
|
|
2600
|
+
if (g.hasAgent(w))
|
|
2601
|
+
s.sessionId ? (g.updateSessionId(w, s.sessionId), g.getConversationHistory(w).length === 0 && n((M) => ({
|
|
2601
2602
|
...M,
|
|
2602
2603
|
clientMessages: [],
|
|
2603
2604
|
uiMessages: []
|
|
2604
|
-
}))) : (
|
|
2605
|
+
}))) : (g.updateSessionId(w, ""), await g.replaceMessages(w, []), n((R) => ({
|
|
2605
2606
|
...R,
|
|
2606
2607
|
clientMessages: [],
|
|
2607
2608
|
uiMessages: []
|
|
2608
2609
|
})));
|
|
2609
|
-
else if (await
|
|
2610
|
+
else if (await g.createAgent(w, {
|
|
2610
2611
|
agentId: s.agentId,
|
|
2611
2612
|
agentUrl: s.agentUrl,
|
|
2612
2613
|
sessionId: s.sessionId,
|
|
@@ -2619,9 +2620,9 @@ function ds(e) {
|
|
|
2619
2620
|
odieBotId: e.odieBotId,
|
|
2620
2621
|
credentials: e.credentials
|
|
2621
2622
|
}), s.sessionId) {
|
|
2622
|
-
const R =
|
|
2623
|
+
const R = g.getConversationHistory(w);
|
|
2623
2624
|
n((M) => {
|
|
2624
|
-
const b =
|
|
2625
|
+
const b = d(R);
|
|
2625
2626
|
return {
|
|
2626
2627
|
...M,
|
|
2627
2628
|
clientMessages: R,
|
|
@@ -2647,18 +2648,18 @@ function ds(e) {
|
|
|
2647
2648
|
e.odieBotId,
|
|
2648
2649
|
e.credentials,
|
|
2649
2650
|
t,
|
|
2650
|
-
|
|
2651
|
+
d
|
|
2651
2652
|
]);
|
|
2652
|
-
const
|
|
2653
|
-
async (m,
|
|
2653
|
+
const A = D(
|
|
2654
|
+
async (m, g, w) => {
|
|
2654
2655
|
var F, U;
|
|
2655
2656
|
if (!t)
|
|
2656
2657
|
throw new Error("Invalid agent configuration");
|
|
2657
2658
|
if (u.current)
|
|
2658
2659
|
return;
|
|
2659
2660
|
u.current = !0;
|
|
2660
|
-
const O = (
|
|
2661
|
-
if (O && (!(
|
|
2661
|
+
const O = (g == null ? void 0 : g.type) === "tool_result";
|
|
2662
|
+
if (O && (!(g != null && g.toolCallId) || !(g != null && g.toolId)))
|
|
2662
2663
|
throw new Error(
|
|
2663
2664
|
"`toolCallId` and `toolId` are required when type is `tool_result`"
|
|
2664
2665
|
);
|
|
@@ -2672,7 +2673,7 @@ function ds(e) {
|
|
|
2672
2673
|
E.clientMessages
|
|
2673
2674
|
);
|
|
2674
2675
|
} catch (_) {
|
|
2675
|
-
|
|
2676
|
+
v(
|
|
2676
2677
|
"Failed to restore conversation history after a failed send",
|
|
2677
2678
|
_
|
|
2678
2679
|
);
|
|
@@ -2694,7 +2695,7 @@ function ds(e) {
|
|
|
2694
2695
|
error: null
|
|
2695
2696
|
}));
|
|
2696
2697
|
else {
|
|
2697
|
-
const T = (
|
|
2698
|
+
const T = (g == null ? void 0 : g.type) || "text", E = w != null && w.messageOverride ? ne(
|
|
2698
2699
|
w.messageOverride,
|
|
2699
2700
|
[]
|
|
2700
2701
|
) : {
|
|
@@ -2703,13 +2704,13 @@ function ds(e) {
|
|
|
2703
2704
|
content: [
|
|
2704
2705
|
{ type: T, text: m },
|
|
2705
2706
|
// Map image URLs to component content parts
|
|
2706
|
-
...((F =
|
|
2707
|
+
...((F = g == null ? void 0 : g.imageUrls) == null ? void 0 : F.map((_) => {
|
|
2707
2708
|
const j = typeof _ == "string" ? _ : _.url;
|
|
2708
|
-
return
|
|
2709
|
+
return ze(j);
|
|
2709
2710
|
})) ?? []
|
|
2710
2711
|
],
|
|
2711
2712
|
timestamp: P,
|
|
2712
|
-
archived: (
|
|
2713
|
+
archived: (g == null ? void 0 : g.archived) ?? !1,
|
|
2713
2714
|
showIcon: !1
|
|
2714
2715
|
};
|
|
2715
2716
|
n((_) => ({
|
|
@@ -2729,15 +2730,15 @@ function ds(e) {
|
|
|
2729
2730
|
w.truncateHistoryTo
|
|
2730
2731
|
);
|
|
2731
2732
|
let T = null, E = !1;
|
|
2732
|
-
const _ = {}, j = !!(
|
|
2733
|
-
(
|
|
2734
|
-
...(
|
|
2735
|
-
...j && { contentType:
|
|
2736
|
-
}),
|
|
2733
|
+
const _ = {}, j = !!(g != null && g.type) && !O;
|
|
2734
|
+
(g != null && g.archived || j) && (_.metadata = {
|
|
2735
|
+
...(g == null ? void 0 : g.archived) && { archived: !0 },
|
|
2736
|
+
...j && { contentType: g.type }
|
|
2737
|
+
}), g != null && g.sessionId && (_.sessionId = g.sessionId), g != null && g.imageUrls && (_.imageUrls = g.imageUrls), w != null && w.messageOverride && (_.message = w.messageOverride);
|
|
2737
2738
|
const W = O ? R.sendToolResult(
|
|
2738
2739
|
M,
|
|
2739
|
-
|
|
2740
|
-
|
|
2740
|
+
g.toolCallId,
|
|
2741
|
+
g.toolId,
|
|
2741
2742
|
{ success: !0, message: m },
|
|
2742
2743
|
_
|
|
2743
2744
|
) : R.sendMessageStream(
|
|
@@ -2799,32 +2800,32 @@ function ds(e) {
|
|
|
2799
2800
|
);
|
|
2800
2801
|
$ && n((ee) => {
|
|
2801
2802
|
const te = ee.uiMessages.map(
|
|
2802
|
-
(
|
|
2803
|
-
var
|
|
2804
|
-
if (
|
|
2805
|
-
const
|
|
2803
|
+
(J) => {
|
|
2804
|
+
var Ae, ve;
|
|
2805
|
+
if (J.id === N) {
|
|
2806
|
+
const Ve = $.content.length > 0 && ((Ae = $.content[0]) == null ? void 0 : Ae.text) && ((ve = J.content[0]) == null ? void 0 : ve.text) && $.content[0].text.length > J.content[0].text.length;
|
|
2806
2807
|
return {
|
|
2807
2808
|
...$,
|
|
2808
|
-
reactKey:
|
|
2809
|
+
reactKey: J.reactKey || N,
|
|
2809
2810
|
// Keep stable reactKey
|
|
2810
|
-
content:
|
|
2811
|
+
content: Ve ? $.content : J.content
|
|
2811
2812
|
};
|
|
2812
2813
|
}
|
|
2813
|
-
return
|
|
2814
|
+
return J;
|
|
2814
2815
|
}
|
|
2815
2816
|
), se = R.getConversationHistory(
|
|
2816
2817
|
M
|
|
2817
2818
|
), le = new Set(
|
|
2818
2819
|
se.map(
|
|
2819
|
-
(
|
|
2820
|
+
(J) => J.messageId
|
|
2820
2821
|
)
|
|
2821
|
-
),
|
|
2822
|
-
(
|
|
2822
|
+
), K = b ? te : te.filter(
|
|
2823
|
+
(J) => le.has(J.id)
|
|
2823
2824
|
);
|
|
2824
2825
|
return {
|
|
2825
2826
|
...ee,
|
|
2826
2827
|
clientMessages: se,
|
|
2827
|
-
uiMessages:
|
|
2828
|
+
uiMessages: K,
|
|
2828
2829
|
isProcessing: !1,
|
|
2829
2830
|
progressMessage: null,
|
|
2830
2831
|
progressPhase: null
|
|
@@ -2837,18 +2838,18 @@ function ds(e) {
|
|
|
2837
2838
|
n((N) => {
|
|
2838
2839
|
let $ = N.uiMessages;
|
|
2839
2840
|
T && ($ = N.uiMessages.filter(
|
|
2840
|
-
(
|
|
2841
|
+
(K) => K.id !== T
|
|
2841
2842
|
));
|
|
2842
2843
|
const ee = H.map(
|
|
2843
|
-
(
|
|
2844
|
-
|
|
2844
|
+
(K) => ne(
|
|
2845
|
+
K,
|
|
2845
2846
|
p.current
|
|
2846
2847
|
)
|
|
2847
2848
|
).filter(
|
|
2848
|
-
(
|
|
2849
|
+
(K) => K !== null
|
|
2849
2850
|
), te = new Set(
|
|
2850
|
-
H.map((
|
|
2851
|
-
), se = b ?
|
|
2851
|
+
H.map((K) => K.messageId)
|
|
2852
|
+
), se = b ? Kt(
|
|
2852
2853
|
$,
|
|
2853
2854
|
te
|
|
2854
2855
|
) : [], le = fe([
|
|
@@ -2867,7 +2868,7 @@ function ds(e) {
|
|
|
2867
2868
|
}
|
|
2868
2869
|
} catch (T) {
|
|
2869
2870
|
if (T instanceof Error && T.name === "AbortError") {
|
|
2870
|
-
|
|
2871
|
+
v("Request was aborted by user"), await k(null) || n((W) => ({
|
|
2871
2872
|
...W,
|
|
2872
2873
|
isProcessing: !1,
|
|
2873
2874
|
progressMessage: null,
|
|
@@ -2891,19 +2892,19 @@ function ds(e) {
|
|
|
2891
2892
|
},
|
|
2892
2893
|
[s.agentId, t]
|
|
2893
2894
|
), f = D(
|
|
2894
|
-
(m,
|
|
2895
|
-
[
|
|
2895
|
+
(m, g) => A(m, g),
|
|
2896
|
+
[A]
|
|
2896
2897
|
), h = D((m) => {
|
|
2897
|
-
n((
|
|
2898
|
-
...
|
|
2899
|
-
uiMessages: fe([...
|
|
2898
|
+
n((g) => ({
|
|
2899
|
+
...g,
|
|
2900
|
+
uiMessages: fe([...g.uiMessages, m])
|
|
2900
2901
|
}));
|
|
2901
2902
|
}, []), I = D((m) => {
|
|
2902
|
-
n((
|
|
2903
|
-
...
|
|
2903
|
+
n((g) => ({
|
|
2904
|
+
...g,
|
|
2904
2905
|
suggestions: m
|
|
2905
2906
|
}));
|
|
2906
|
-
}, []),
|
|
2907
|
+
}, []), S = D(() => {
|
|
2907
2908
|
n((m) => ({
|
|
2908
2909
|
...m,
|
|
2909
2910
|
suggestions: []
|
|
@@ -2913,7 +2914,7 @@ function ds(e) {
|
|
|
2913
2914
|
n((m) => {
|
|
2914
2915
|
if (u.current || m.clientMessages.length === 0)
|
|
2915
2916
|
return m;
|
|
2916
|
-
const
|
|
2917
|
+
const g = d(m.clientMessages), w = new Set(
|
|
2917
2918
|
m.clientMessages.map((R) => R.messageId)
|
|
2918
2919
|
), O = m.uiMessages.filter(
|
|
2919
2920
|
(R) => !w.has(R.id) && R.role !== "user"
|
|
@@ -2921,38 +2922,38 @@ function ds(e) {
|
|
|
2921
2922
|
return {
|
|
2922
2923
|
...m,
|
|
2923
2924
|
uiMessages: fe([
|
|
2924
|
-
...
|
|
2925
|
+
...g,
|
|
2925
2926
|
...O
|
|
2926
2927
|
])
|
|
2927
2928
|
};
|
|
2928
2929
|
});
|
|
2929
|
-
}, [i,
|
|
2930
|
+
}, [i, d]);
|
|
2930
2931
|
const y = D(() => {
|
|
2931
2932
|
if (!t)
|
|
2932
2933
|
return;
|
|
2933
|
-
const m = X(),
|
|
2934
|
-
m.abortCurrentRequest(
|
|
2935
|
-
}, [s.agentId, t]),
|
|
2934
|
+
const m = X(), g = s.agentId;
|
|
2935
|
+
m.abortCurrentRequest(g);
|
|
2936
|
+
}, [s.agentId, t]), C = D(
|
|
2936
2937
|
async (m) => {
|
|
2937
2938
|
if (!t)
|
|
2938
2939
|
return;
|
|
2939
|
-
const
|
|
2940
|
-
await
|
|
2941
|
-
const O =
|
|
2940
|
+
const g = X(), w = s.agentId;
|
|
2941
|
+
await g.replaceMessages(w, m);
|
|
2942
|
+
const O = d(m);
|
|
2942
2943
|
n((R) => ({
|
|
2943
2944
|
...R,
|
|
2944
2945
|
clientMessages: m,
|
|
2945
2946
|
uiMessages: O
|
|
2946
2947
|
}));
|
|
2947
2948
|
},
|
|
2948
|
-
[s.agentId, t,
|
|
2949
|
-
), { getRegenerateHandler:
|
|
2949
|
+
[s.agentId, t, d]
|
|
2950
|
+
), { getRegenerateHandler: x } = Jt({
|
|
2950
2951
|
agentId: s.agentId,
|
|
2951
2952
|
isValidConfig: t,
|
|
2952
2953
|
isSendingRef: u,
|
|
2953
2954
|
stateRef: c,
|
|
2954
|
-
transformMessages:
|
|
2955
|
-
sendMessage:
|
|
2955
|
+
transformMessages: d,
|
|
2956
|
+
sendMessage: A
|
|
2956
2957
|
});
|
|
2957
2958
|
return {
|
|
2958
2959
|
// AgentUI props
|
|
@@ -2965,21 +2966,21 @@ function ds(e) {
|
|
|
2965
2966
|
progressPhase: a.progressPhase,
|
|
2966
2967
|
// UI management methods
|
|
2967
2968
|
registerSuggestions: I,
|
|
2968
|
-
clearSuggestions:
|
|
2969
|
+
clearSuggestions: S,
|
|
2969
2970
|
// Message actions methods
|
|
2970
2971
|
registerMessageActions: o,
|
|
2971
2972
|
unregisterMessageActions: r,
|
|
2972
2973
|
clearAllMessageActions: l,
|
|
2973
|
-
getRegenerateHandler:
|
|
2974
|
+
getRegenerateHandler: x,
|
|
2974
2975
|
// Tool integration
|
|
2975
2976
|
addMessage: h,
|
|
2976
2977
|
// Abort control
|
|
2977
2978
|
abortCurrentRequest: y,
|
|
2978
2979
|
// Conversation loading
|
|
2979
|
-
loadMessages:
|
|
2980
|
+
loadMessages: C
|
|
2980
2981
|
};
|
|
2981
2982
|
}
|
|
2982
|
-
var
|
|
2983
|
+
var Vt = /* @__PURE__ */ ((e) => (e[e.PARSE_ERROR = -32700] = "PARSE_ERROR", e[e.INVALID_REQUEST = -32600] = "INVALID_REQUEST", e[e.METHOD_NOT_FOUND = -32601] = "METHOD_NOT_FOUND", e[e.INVALID_PARAMS = -32602] = "INVALID_PARAMS", e[e.INTERNAL_ERROR = -32603] = "INTERNAL_ERROR", e[e.SERVER_ERROR = -32e3] = "SERVER_ERROR", e))(Vt || {});
|
|
2983
2984
|
const Pe = "jetpack-ai-jwt-token", Gt = 30 * 60 * 1e3;
|
|
2984
2985
|
function Qt() {
|
|
2985
2986
|
var t, a, n;
|
|
@@ -2993,7 +2994,7 @@ async function Xt(e, s = !0) {
|
|
|
2993
2994
|
try {
|
|
2994
2995
|
a = JSON.parse(t);
|
|
2995
2996
|
} catch (c) {
|
|
2996
|
-
|
|
2997
|
+
v("Invalid cached Jetpack token: %O", c);
|
|
2997
2998
|
}
|
|
2998
2999
|
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && s)
|
|
2999
3000
|
return a;
|
|
@@ -3003,10 +3004,10 @@ async function Xt(e, s = !0) {
|
|
|
3003
3004
|
blog_id: ""
|
|
3004
3005
|
};
|
|
3005
3006
|
try {
|
|
3006
|
-
Qt() ? r = await
|
|
3007
|
+
Qt() ? r = await Se({
|
|
3007
3008
|
path: "/wpcom/v2/sites/" + o + "/jetpack-openai-query/jwt",
|
|
3008
3009
|
method: "POST"
|
|
3009
|
-
}) : r = await
|
|
3010
|
+
}) : r = await Se({
|
|
3010
3011
|
path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
|
|
3011
3012
|
credentials: "same-origin",
|
|
3012
3013
|
headers: {
|
|
@@ -3015,7 +3016,7 @@ async function Xt(e, s = !0) {
|
|
|
3015
3016
|
method: "POST"
|
|
3016
3017
|
});
|
|
3017
3018
|
} catch (c) {
|
|
3018
|
-
throw
|
|
3019
|
+
throw v("Failed to fetch Jetpack token: %O", c), new Error(e(c));
|
|
3019
3020
|
}
|
|
3020
3021
|
if (!(r != null && r.token))
|
|
3021
3022
|
throw new Error(
|
|
@@ -3029,17 +3030,17 @@ async function Xt(e, s = !0) {
|
|
|
3029
3030
|
try {
|
|
3030
3031
|
localStorage.setItem(Pe, JSON.stringify(l));
|
|
3031
3032
|
} catch (c) {
|
|
3032
|
-
|
|
3033
|
+
v("Error storing token in localStorage: %O", c);
|
|
3033
3034
|
}
|
|
3034
3035
|
return l;
|
|
3035
3036
|
}
|
|
3036
|
-
const
|
|
3037
|
+
const ds = (e) => async () => {
|
|
3037
3038
|
const s = {};
|
|
3038
3039
|
try {
|
|
3039
3040
|
const t = await Xt(e);
|
|
3040
3041
|
t != null && t.token && (s.Authorization = `${t.token}`);
|
|
3041
3042
|
} catch (t) {
|
|
3042
|
-
throw
|
|
3043
|
+
throw v("Failed to get Jetpack token for auth: %O", t), t;
|
|
3043
3044
|
}
|
|
3044
3045
|
return s;
|
|
3045
3046
|
};
|
|
@@ -3096,26 +3097,43 @@ function hs(e) {
|
|
|
3096
3097
|
}
|
|
3097
3098
|
}
|
|
3098
3099
|
export {
|
|
3099
|
-
|
|
3100
|
+
Vt as ErrorCodes,
|
|
3101
|
+
ws as agentsApiContinueResponse,
|
|
3102
|
+
Ms as agentsApiDeleteSession,
|
|
3103
|
+
Ts as agentsApiListSessions,
|
|
3104
|
+
As as agentsApiLoadSession,
|
|
3105
|
+
vs as agentsApiMarkSessionRead,
|
|
3106
|
+
Ss as agentsApiSendMessage,
|
|
3100
3107
|
fs as convertAbilitiesToTools,
|
|
3101
3108
|
Yt as convertAbilityToTool,
|
|
3102
3109
|
ls as createAbortController,
|
|
3110
|
+
Cs as createAgentsApiChatAdapter,
|
|
3111
|
+
xs as createAgentsApiRunControlAdapter,
|
|
3103
3112
|
Mt as createClient,
|
|
3104
|
-
|
|
3113
|
+
ds as createJetpackAuthProvider,
|
|
3105
3114
|
ps as createOdieBotId,
|
|
3106
3115
|
Ye as createRequestId,
|
|
3107
3116
|
Ze as createTaskId,
|
|
3108
3117
|
me as createTextMessage,
|
|
3109
|
-
|
|
3110
|
-
|
|
3118
|
+
L as extractTextFromMessage,
|
|
3119
|
+
V as extractToolCallsFromMessage,
|
|
3111
3120
|
X as getAgentManager,
|
|
3121
|
+
bs as groupToolMessages,
|
|
3112
3122
|
hs as isOdieBotId,
|
|
3113
3123
|
ms as isWordPressAbility,
|
|
3114
3124
|
cs as listConversationsFromServer,
|
|
3115
3125
|
us as loadAllMessagesFromServer,
|
|
3116
3126
|
pe as loadChatFromServer,
|
|
3127
|
+
Rs as normalizeAgentsApiMessage,
|
|
3128
|
+
ks as normalizeConversation,
|
|
3129
|
+
Ps as normalizeLoadedSession,
|
|
3130
|
+
_s as normalizeRunEvent,
|
|
3131
|
+
Es as normalizeSendResponse,
|
|
3132
|
+
Ns as normalizeSessions,
|
|
3117
3133
|
Zt as parseOdieBotId,
|
|
3118
|
-
|
|
3134
|
+
Hs as renderToolGroups,
|
|
3135
|
+
gs as useAgentChat,
|
|
3136
|
+
Os as useAgentsApiChat,
|
|
3119
3137
|
os as useClientAbilities,
|
|
3120
3138
|
ns as useClientContext,
|
|
3121
3139
|
rs as useClientTools,
|