@automattic/agenttic-client 0.1.24 → 0.1.25
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/client/index.d.ts.map +1 -1
- package/dist/index.js +231 -225
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,MAAM,EACN,YAAY,EAEZ,OAAO,EACP,iBAAiB,EAEjB,UAAU,EAIV,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/client/index.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACX,MAAM,EACN,YAAY,EAEZ,OAAO,EACP,iBAAiB,EAEjB,UAAU,EAIV,MAAM,eAAe,CAAC;AAuMvB;;GAEG;AACH,iBAAS,uBAAuB,IAAI,IAAI,CAEvC;AAED;;;;GAIG;AACH,iBAAS,qCAAqC,CAAE,WAAW,EAAE,GAAG,EAAE,GAAI,GAAG,EAAE,CA4B1E;AAkED;;;;;GAKG;AACH,wBAAgB,0BAA0B,CAAE,OAAO,EAAE,OAAO,GAAI,OAAO,EAAE,CAmDxE;AA2kBD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,OAAO,EAAE,qCAAqC,EAAE,uBAAuB,EAAE,CAAC;AAE1E,wBAAgB,YAAY,CAAE,MAAM,EAAE,YAAY,GAAI,MAAM,CAuV3D;AAED;;;;GAIG;AACH,wBAAsB,kBAAkB,CACvC,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,iBAAiB,GACvB,OAAO,CAAE,UAAU,CAAE,CAavB"}
|
package/dist/index.js
CHANGED
|
@@ -24,18 +24,18 @@ function ot({
|
|
|
24
24
|
const o = [];
|
|
25
25
|
if (t)
|
|
26
26
|
try {
|
|
27
|
-
const
|
|
28
|
-
o.push(...
|
|
29
|
-
} catch (
|
|
30
|
-
v("Error getting available tools: %O",
|
|
27
|
+
const c = await t();
|
|
28
|
+
o.push(...c);
|
|
29
|
+
} catch (c) {
|
|
30
|
+
v("Error getting available tools: %O", c);
|
|
31
31
|
}
|
|
32
32
|
return o;
|
|
33
33
|
}, [t]), n = $(
|
|
34
|
-
async (o,
|
|
34
|
+
async (o, c) => {
|
|
35
35
|
if (!e)
|
|
36
36
|
throw new Error("No executeTool callback provided");
|
|
37
37
|
try {
|
|
38
|
-
return await e(o,
|
|
38
|
+
return await e(o, c);
|
|
39
39
|
} catch (i) {
|
|
40
40
|
throw v("Error executing tool %s: %O", o, i), i;
|
|
41
41
|
}
|
|
@@ -288,55 +288,55 @@ function jt(t, e = "") {
|
|
|
288
288
|
`
|
|
289
289
|
`,
|
|
290
290
|
o
|
|
291
|
-
),
|
|
292
|
-
if (
|
|
291
|
+
), l = i === -1 ? a.substring(o) : a.substring(o, i);
|
|
292
|
+
if (l.startsWith("data:"))
|
|
293
293
|
n !== "" && (n += `
|
|
294
|
-
`), n +=
|
|
295
|
-
|
|
294
|
+
`), n += l.substring(
|
|
295
|
+
l.startsWith("data: ") ? 6 : 5
|
|
296
296
|
);
|
|
297
|
-
else if (
|
|
297
|
+
else if (l.trim() === "" && n) {
|
|
298
298
|
try {
|
|
299
299
|
s.push(JSON.parse(n)), r = i === -1 ? a.length : i + 1;
|
|
300
|
-
} catch (
|
|
301
|
-
v("Failed to parse SSE event: %o",
|
|
300
|
+
} catch (f) {
|
|
301
|
+
v("Failed to parse SSE event: %o", f), v("Problematic payload: %s", n);
|
|
302
302
|
}
|
|
303
303
|
n = "";
|
|
304
304
|
}
|
|
305
305
|
i === -1 ? o = a.length : o = i + 1;
|
|
306
306
|
}
|
|
307
|
-
const
|
|
308
|
-
return { events: s, nextBuffer:
|
|
307
|
+
const c = a.substring(r);
|
|
308
|
+
return { events: s, nextBuffer: c };
|
|
309
309
|
}
|
|
310
310
|
async function* Jt(t, e = {}) {
|
|
311
|
-
var
|
|
311
|
+
var l, f, h;
|
|
312
312
|
const { supportDeltas: s = !1 } = e, a = t.getReader(), n = new TextDecoder();
|
|
313
313
|
let r = "";
|
|
314
314
|
const o = new Kt();
|
|
315
|
-
let
|
|
315
|
+
let c = null, i = null;
|
|
316
316
|
try {
|
|
317
317
|
for (; ; ) {
|
|
318
318
|
const { done: m, value: p } = await a.read();
|
|
319
319
|
if (m)
|
|
320
320
|
break;
|
|
321
|
-
const S = n.decode(p, { stream: !0 }), { events:
|
|
322
|
-
if (
|
|
323
|
-
for (let w = 0; w <
|
|
324
|
-
const
|
|
325
|
-
if (w > 0 &&
|
|
321
|
+
const S = n.decode(p, { stream: !0 }), { events: u, nextBuffer: d } = jt(S, r);
|
|
322
|
+
if (u && Array.isArray(u))
|
|
323
|
+
for (let w = 0; w < u.length; w++) {
|
|
324
|
+
const g = u[w];
|
|
325
|
+
if (w > 0 && g.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((y) => {
|
|
326
326
|
requestAnimationFrame(() => y(void 0));
|
|
327
|
-
}),
|
|
327
|
+
}), g.error)
|
|
328
328
|
throw new Error(
|
|
329
|
-
`Streaming error: ${
|
|
329
|
+
`Streaming error: ${g.error.message}`
|
|
330
330
|
);
|
|
331
|
-
if (s &&
|
|
332
|
-
const y =
|
|
331
|
+
if (s && g.method === "message/delta" && ((l = g.params) != null && l.delta)) {
|
|
332
|
+
const y = g.params.delta;
|
|
333
333
|
try {
|
|
334
334
|
if (y.deltaType === "content" && (o.processContentDelta(
|
|
335
335
|
y.content
|
|
336
|
-
), !
|
|
336
|
+
), !c && g.params.id && (c = g.params.id), c)) {
|
|
337
337
|
const x = o.getCurrentMessage();
|
|
338
338
|
yield {
|
|
339
|
-
id:
|
|
339
|
+
id: c,
|
|
340
340
|
status: {
|
|
341
341
|
state: "working",
|
|
342
342
|
message: x
|
|
@@ -348,22 +348,22 @@ async function* Jt(t, e = {}) {
|
|
|
348
348
|
} catch (x) {
|
|
349
349
|
v("Failed to process delta: %o", x);
|
|
350
350
|
}
|
|
351
|
-
} else
|
|
352
|
-
id:
|
|
353
|
-
status:
|
|
354
|
-
final:
|
|
351
|
+
} else g.result && g.result.status ? (c = g.result.id, i = g.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset(), yield {
|
|
352
|
+
id: g.result.id,
|
|
353
|
+
status: g.result.status,
|
|
354
|
+
final: g.result.status.state === "completed" || g.result.status.state === "failed" || g.result.status.state === "canceled",
|
|
355
355
|
text: D(
|
|
356
|
-
((
|
|
356
|
+
((f = g.result.status) == null ? void 0 : f.message) || {
|
|
357
357
|
role: "agent",
|
|
358
358
|
parts: []
|
|
359
359
|
}
|
|
360
360
|
)
|
|
361
|
-
}) :
|
|
362
|
-
id:
|
|
363
|
-
status:
|
|
364
|
-
final:
|
|
361
|
+
}) : g.id && g.result && (c = g.result.id, g.result.status && (yield {
|
|
362
|
+
id: g.result.id,
|
|
363
|
+
status: g.result.status,
|
|
364
|
+
final: g.result.status.state === "completed" || g.result.status.state === "failed" || g.result.status.state === "canceled",
|
|
365
365
|
text: D(
|
|
366
|
-
((h =
|
|
366
|
+
((h = g.result.status) == null ? void 0 : h.message) || {
|
|
367
367
|
role: "agent",
|
|
368
368
|
parts: []
|
|
369
369
|
}
|
|
@@ -526,7 +526,7 @@ function Mt(t, e, s) {
|
|
|
526
526
|
};
|
|
527
527
|
}
|
|
528
528
|
async function X(t, e, s, a, n, r) {
|
|
529
|
-
const { message: o, sessionId:
|
|
529
|
+
const { message: o, sessionId: c, taskId: i, metadata: l } = t, { agentId: f, agentUrl: h, authProvider: m, proxy: p } = e, { isStreaming: S = !1, enableTokenStreaming: u = !1 } = s, d = c || r, w = Vt(h, f), g = await Ut(
|
|
530
530
|
o,
|
|
531
531
|
a,
|
|
532
532
|
n
|
|
@@ -534,31 +534,31 @@ async function X(t, e, s, a, n, r) {
|
|
|
534
534
|
{
|
|
535
535
|
id: i,
|
|
536
536
|
sessionId: d,
|
|
537
|
-
message:
|
|
538
|
-
metadata:
|
|
537
|
+
message: g,
|
|
538
|
+
metadata: l
|
|
539
539
|
},
|
|
540
540
|
S ? "message/stream" : "message/send",
|
|
541
|
-
|
|
541
|
+
u && S
|
|
542
542
|
// Only enable token streaming if using SSE
|
|
543
543
|
), x = await zt(m, S);
|
|
544
544
|
return Bt("POST", w, x, y), {
|
|
545
545
|
request: y,
|
|
546
546
|
headers: x,
|
|
547
|
-
enhancedMessage:
|
|
547
|
+
enhancedMessage: g,
|
|
548
548
|
effectiveSessionId: d,
|
|
549
549
|
fullAgentUrl: w
|
|
550
550
|
};
|
|
551
551
|
}
|
|
552
552
|
async function At(t, e, s = {}) {
|
|
553
|
-
const { request: a, headers: n, fullAgentUrl: r } = t, { timeout: o } = e, { abortSignal:
|
|
553
|
+
const { request: a, headers: n, fullAgentUrl: r } = t, { timeout: o } = e, { abortSignal: c } = s, { timeoutId: i, controller: l } = xt(
|
|
554
554
|
o,
|
|
555
555
|
"request"
|
|
556
|
-
),
|
|
556
|
+
), f = c ? bt(l.signal, c) : l.signal;
|
|
557
557
|
try {
|
|
558
558
|
const h = Mt(
|
|
559
559
|
n,
|
|
560
560
|
JSON.stringify(a),
|
|
561
|
-
|
|
561
|
+
f
|
|
562
562
|
);
|
|
563
563
|
v("Making request to %s with options: %O", r, {
|
|
564
564
|
method: h.method,
|
|
@@ -580,24 +580,24 @@ async function At(t, e, s = {}) {
|
|
|
580
580
|
async function* St(t, e, s) {
|
|
581
581
|
const { request: a, headers: n, fullAgentUrl: r } = t, {
|
|
582
582
|
streamingTimeout: o = 6e4,
|
|
583
|
-
abortSignal:
|
|
583
|
+
abortSignal: c,
|
|
584
584
|
enableTokenStreaming: i = !1
|
|
585
|
-
} = s, { timeoutId:
|
|
585
|
+
} = s, { timeoutId: l, controller: f } = xt(
|
|
586
586
|
o,
|
|
587
587
|
"streaming request"
|
|
588
|
-
), h =
|
|
588
|
+
), h = c ? bt(f.signal, c) : f.signal;
|
|
589
589
|
try {
|
|
590
590
|
const m = JSON.stringify(a), p = Mt(n, m, h), S = await fetch(r, p);
|
|
591
|
-
if (clearTimeout(
|
|
591
|
+
if (clearTimeout(l), Wt(S, "streaming request"), !S.body)
|
|
592
592
|
throw new Error(
|
|
593
593
|
"Response body is null - server may not support streaming"
|
|
594
594
|
);
|
|
595
|
-
const
|
|
595
|
+
const u = i && a.tokenStreaming === !0;
|
|
596
596
|
yield* Jt(S.body, {
|
|
597
|
-
supportDeltas:
|
|
597
|
+
supportDeltas: u
|
|
598
598
|
});
|
|
599
599
|
} catch (m) {
|
|
600
|
-
Tt(m,
|
|
600
|
+
Tt(m, l, "streaming request");
|
|
601
601
|
}
|
|
602
602
|
}
|
|
603
603
|
const Qt = 12e4;
|
|
@@ -606,15 +606,21 @@ async function G(t, e, s, a, n) {
|
|
|
606
606
|
const r = await t.getAbilities();
|
|
607
607
|
if (r.length > 0)
|
|
608
608
|
for (const o of r) {
|
|
609
|
-
const
|
|
610
|
-
if (e ===
|
|
609
|
+
const c = o.name.replace(/\//g, "__").replace(/-/g, "_");
|
|
610
|
+
if (e === c || e === o.name) {
|
|
611
611
|
if (o.callback)
|
|
612
612
|
try {
|
|
613
613
|
const i = {
|
|
614
614
|
...s,
|
|
615
615
|
...a && { messageId: a }
|
|
616
|
-
},
|
|
617
|
-
return {
|
|
616
|
+
}, l = await o.callback(i);
|
|
617
|
+
return {
|
|
618
|
+
result: l,
|
|
619
|
+
returnToAgent: (l == null ? void 0 : l.returnToAgent) !== void 0 ? l.returnToAgent : !0,
|
|
620
|
+
...(l == null ? void 0 : l.agentMessage) && {
|
|
621
|
+
agentMessage: l.agentMessage
|
|
622
|
+
}
|
|
623
|
+
};
|
|
618
624
|
} catch (i) {
|
|
619
625
|
return v(
|
|
620
626
|
"Error executing ability %s: %O",
|
|
@@ -709,29 +715,29 @@ async function vt(t, e, s) {
|
|
|
709
715
|
const a = [], n = [];
|
|
710
716
|
let r = !1;
|
|
711
717
|
for (const o of t) {
|
|
712
|
-
const { toolCallId:
|
|
718
|
+
const { toolCallId: c, toolId: i, arguments: l } = o.data;
|
|
713
719
|
try {
|
|
714
|
-
const
|
|
720
|
+
const f = await G(
|
|
715
721
|
e,
|
|
716
722
|
i,
|
|
717
|
-
|
|
723
|
+
l,
|
|
718
724
|
s,
|
|
719
|
-
|
|
720
|
-
), { result: h, returnToAgent: m, agentMessage: p } = it(
|
|
725
|
+
c
|
|
726
|
+
), { result: h, returnToAgent: m, agentMessage: p } = it(f);
|
|
721
727
|
m && (r = !0), p && n.push(W(p)), a.push(
|
|
722
728
|
j(
|
|
723
|
-
|
|
729
|
+
c,
|
|
724
730
|
i,
|
|
725
731
|
h
|
|
726
732
|
)
|
|
727
733
|
);
|
|
728
|
-
} catch (
|
|
734
|
+
} catch (f) {
|
|
729
735
|
r = !0, a.push(
|
|
730
736
|
j(
|
|
731
|
-
|
|
737
|
+
c,
|
|
732
738
|
i,
|
|
733
739
|
void 0,
|
|
734
|
-
|
|
740
|
+
f instanceof Error ? f.message : String(f)
|
|
735
741
|
)
|
|
736
742
|
);
|
|
737
743
|
}
|
|
@@ -769,23 +775,23 @@ async function et(t, e, s, a, n, r, o) {
|
|
|
769
775
|
abortSignal: o
|
|
770
776
|
});
|
|
771
777
|
}
|
|
772
|
-
async function ft(t, e, s, a, n, r, o,
|
|
773
|
-
const
|
|
778
|
+
async function ft(t, e, s, a, n, r, o, c, i = []) {
|
|
779
|
+
const l = {
|
|
774
780
|
message: e,
|
|
775
781
|
taskId: t,
|
|
776
782
|
sessionId: void 0
|
|
777
783
|
// Use task's session
|
|
778
|
-
},
|
|
779
|
-
|
|
784
|
+
}, f = c || { isStreaming: !0 }, h = await X(
|
|
785
|
+
l,
|
|
780
786
|
s,
|
|
781
787
|
{
|
|
782
|
-
...
|
|
788
|
+
...f
|
|
783
789
|
},
|
|
784
790
|
a,
|
|
785
791
|
n,
|
|
786
792
|
r
|
|
787
793
|
), m = St(h, s, {
|
|
788
|
-
...
|
|
794
|
+
...f,
|
|
789
795
|
abortSignal: o
|
|
790
796
|
});
|
|
791
797
|
return kt(
|
|
@@ -799,12 +805,12 @@ async function ft(t, e, s, a, n, r, o, l, i = []) {
|
|
|
799
805
|
i,
|
|
800
806
|
// preserve conversation parts across continuation
|
|
801
807
|
o,
|
|
802
|
-
|
|
808
|
+
f
|
|
803
809
|
// Pass through the same request options
|
|
804
810
|
);
|
|
805
811
|
}
|
|
806
|
-
async function* kt(t, e, s, a, n, r = !0, o = [],
|
|
807
|
-
var
|
|
812
|
+
async function* kt(t, e, s, a, n, r = !0, o = [], c, i) {
|
|
813
|
+
var l, f, h, m, p, S, u, d, w, g, y, x;
|
|
808
814
|
for await (const I of t) {
|
|
809
815
|
if (yield I, I.status.state === "running" && I.status.message && e && await Xt(
|
|
810
816
|
e,
|
|
@@ -819,7 +825,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
819
825
|
e,
|
|
820
826
|
k,
|
|
821
827
|
M,
|
|
822
|
-
(
|
|
828
|
+
(f = (l = I.status) == null ? void 0 : l.message) == null ? void 0 : f.messageId,
|
|
823
829
|
b
|
|
824
830
|
).catch((C) => {
|
|
825
831
|
v("Tool execution failed for %s: %O", k, C);
|
|
@@ -927,7 +933,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
927
933
|
e,
|
|
928
934
|
s,
|
|
929
935
|
n,
|
|
930
|
-
|
|
936
|
+
c,
|
|
931
937
|
i,
|
|
932
938
|
o
|
|
933
939
|
);
|
|
@@ -952,7 +958,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
952
958
|
}
|
|
953
959
|
)
|
|
954
960
|
}; E.length > 0; ) {
|
|
955
|
-
(
|
|
961
|
+
(u = R.status) != null && u.message && o.push(
|
|
956
962
|
R.status.message
|
|
957
963
|
);
|
|
958
964
|
const {
|
|
@@ -990,7 +996,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
990
996
|
e,
|
|
991
997
|
s,
|
|
992
998
|
n,
|
|
993
|
-
|
|
999
|
+
c,
|
|
994
1000
|
i,
|
|
995
1001
|
o
|
|
996
1002
|
);
|
|
@@ -1001,7 +1007,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
1001
1007
|
throw new Error(
|
|
1002
1008
|
"Continue task stream ended without final result"
|
|
1003
1009
|
);
|
|
1004
|
-
R = H, E = (
|
|
1010
|
+
R = H, E = (g = R.status) != null && g.message ? F(
|
|
1005
1011
|
R.status.message
|
|
1006
1012
|
) : [], E.length > 0 && (yield {
|
|
1007
1013
|
id: R.id,
|
|
@@ -1066,36 +1072,36 @@ function Zt(t) {
|
|
|
1066
1072
|
defaultSessionId: n,
|
|
1067
1073
|
timeout: r = Qt,
|
|
1068
1074
|
toolProvider: o,
|
|
1069
|
-
contextProvider:
|
|
1075
|
+
contextProvider: c,
|
|
1070
1076
|
enableStreaming: i = !1
|
|
1071
|
-
} = t,
|
|
1077
|
+
} = t, l = {
|
|
1072
1078
|
agentId: e,
|
|
1073
1079
|
agentUrl: s,
|
|
1074
1080
|
authProvider: a,
|
|
1075
1081
|
timeout: r
|
|
1076
1082
|
};
|
|
1077
1083
|
return {
|
|
1078
|
-
async sendMessage(
|
|
1079
|
-
var
|
|
1080
|
-
const { abortSignal: h } =
|
|
1081
|
-
p.push(
|
|
1084
|
+
async sendMessage(f) {
|
|
1085
|
+
var g, y;
|
|
1086
|
+
const { abortSignal: h } = f, m = f.sessionId || n || void 0, p = [];
|
|
1087
|
+
p.push(f.message);
|
|
1082
1088
|
const S = await X(
|
|
1083
|
-
|
|
1084
|
-
|
|
1089
|
+
f,
|
|
1090
|
+
l,
|
|
1085
1091
|
{ isStreaming: !1 },
|
|
1086
1092
|
o,
|
|
1087
|
-
|
|
1093
|
+
c,
|
|
1088
1094
|
m
|
|
1089
1095
|
);
|
|
1090
|
-
let
|
|
1096
|
+
let u = await At(
|
|
1091
1097
|
S,
|
|
1092
|
-
|
|
1098
|
+
l,
|
|
1093
1099
|
{ abortSignal: h }
|
|
1094
1100
|
);
|
|
1095
1101
|
const d = [], w = [];
|
|
1096
|
-
for (;
|
|
1102
|
+
for (; u.status.message && o; ) {
|
|
1097
1103
|
const x = F(
|
|
1098
|
-
|
|
1104
|
+
u.status.message
|
|
1099
1105
|
);
|
|
1100
1106
|
if (x.length === 0)
|
|
1101
1107
|
break;
|
|
@@ -1133,29 +1139,29 @@ function Zt(t) {
|
|
|
1133
1139
|
I.push(A), d.push(A);
|
|
1134
1140
|
}
|
|
1135
1141
|
}
|
|
1136
|
-
if (p.push(
|
|
1142
|
+
if (p.push(u.status.message), P) {
|
|
1137
1143
|
const T = Q(I);
|
|
1138
|
-
|
|
1139
|
-
|
|
1144
|
+
u = await et(
|
|
1145
|
+
u.id,
|
|
1140
1146
|
T,
|
|
1141
|
-
u,
|
|
1142
|
-
o,
|
|
1143
1147
|
l,
|
|
1148
|
+
o,
|
|
1149
|
+
c,
|
|
1144
1150
|
m,
|
|
1145
1151
|
h
|
|
1146
1152
|
);
|
|
1147
1153
|
} else
|
|
1148
1154
|
break;
|
|
1149
1155
|
}
|
|
1150
|
-
if (d.length > 0 && (
|
|
1156
|
+
if (d.length > 0 && (g = u.status) != null && g.message) {
|
|
1151
1157
|
const x = {
|
|
1152
|
-
...
|
|
1158
|
+
...u.status.message,
|
|
1153
1159
|
parts: d
|
|
1154
1160
|
};
|
|
1155
|
-
|
|
1156
|
-
...
|
|
1161
|
+
u = {
|
|
1162
|
+
...u,
|
|
1157
1163
|
status: {
|
|
1158
|
-
...
|
|
1164
|
+
...u.status,
|
|
1159
1165
|
message: x
|
|
1160
1166
|
}
|
|
1161
1167
|
};
|
|
@@ -1163,7 +1169,7 @@ function Zt(t) {
|
|
|
1163
1169
|
if (w.length > 0) {
|
|
1164
1170
|
const x = w.map((P) => D(P)).join(" "), I = W(x);
|
|
1165
1171
|
return {
|
|
1166
|
-
...
|
|
1172
|
+
...u,
|
|
1167
1173
|
// Keep the enhanced message with tool results
|
|
1168
1174
|
// The agent message will be handled separately by the caller
|
|
1169
1175
|
text: x,
|
|
@@ -1172,94 +1178,94 @@ function Zt(t) {
|
|
|
1172
1178
|
};
|
|
1173
1179
|
}
|
|
1174
1180
|
return {
|
|
1175
|
-
...
|
|
1181
|
+
...u,
|
|
1176
1182
|
text: D(
|
|
1177
|
-
((y =
|
|
1183
|
+
((y = u.status) == null ? void 0 : y.message) || {
|
|
1178
1184
|
parts: [],
|
|
1179
1185
|
messageId: N()
|
|
1180
1186
|
}
|
|
1181
1187
|
)
|
|
1182
1188
|
};
|
|
1183
1189
|
},
|
|
1184
|
-
async *sendMessageStream(
|
|
1190
|
+
async *sendMessageStream(f) {
|
|
1185
1191
|
const {
|
|
1186
1192
|
withHistory: h = !0,
|
|
1187
1193
|
abortSignal: m,
|
|
1188
1194
|
enableStreaming: p
|
|
1189
|
-
} =
|
|
1190
|
-
d.push(
|
|
1195
|
+
} = f, S = f.sessionId || n || void 0, u = p ?? i, d = [];
|
|
1196
|
+
d.push(f.message);
|
|
1191
1197
|
const w = await X(
|
|
1192
|
-
|
|
1193
|
-
|
|
1198
|
+
f,
|
|
1199
|
+
l,
|
|
1194
1200
|
{
|
|
1195
1201
|
isStreaming: !0,
|
|
1196
1202
|
// Always use message/stream endpoint for SSE
|
|
1197
|
-
enableTokenStreaming:
|
|
1203
|
+
enableTokenStreaming: u
|
|
1198
1204
|
},
|
|
1199
1205
|
o,
|
|
1200
|
-
|
|
1206
|
+
c,
|
|
1201
1207
|
S
|
|
1202
|
-
),
|
|
1208
|
+
), g = St(
|
|
1203
1209
|
w,
|
|
1204
|
-
|
|
1210
|
+
l,
|
|
1205
1211
|
{
|
|
1206
|
-
enableTokenStreaming:
|
|
1212
|
+
enableTokenStreaming: u,
|
|
1207
1213
|
// Token streaming is optional
|
|
1208
1214
|
streamingTimeout: r,
|
|
1209
1215
|
abortSignal: m
|
|
1210
1216
|
}
|
|
1211
1217
|
);
|
|
1212
1218
|
yield* kt(
|
|
1213
|
-
|
|
1219
|
+
g,
|
|
1214
1220
|
o,
|
|
1221
|
+
c,
|
|
1215
1222
|
l,
|
|
1216
|
-
u,
|
|
1217
1223
|
S,
|
|
1218
1224
|
h,
|
|
1219
1225
|
d,
|
|
1220
1226
|
m,
|
|
1221
1227
|
{
|
|
1222
1228
|
isStreaming: !0,
|
|
1223
|
-
enableTokenStreaming:
|
|
1229
|
+
enableTokenStreaming: u,
|
|
1224
1230
|
streamingTimeout: r
|
|
1225
1231
|
}
|
|
1226
1232
|
);
|
|
1227
1233
|
},
|
|
1228
|
-
async continueTask(
|
|
1234
|
+
async continueTask(f, h, m) {
|
|
1229
1235
|
var d;
|
|
1230
1236
|
const p = nt(h);
|
|
1231
|
-
let
|
|
1232
|
-
|
|
1237
|
+
let u = await et(
|
|
1238
|
+
f,
|
|
1233
1239
|
p,
|
|
1234
|
-
u,
|
|
1235
|
-
o,
|
|
1236
1240
|
l,
|
|
1241
|
+
o,
|
|
1242
|
+
c,
|
|
1237
1243
|
m
|
|
1238
1244
|
);
|
|
1239
|
-
for (;
|
|
1245
|
+
for (; u.status.state === "input-required" && u.status.message && o; ) {
|
|
1240
1246
|
const w = F(
|
|
1241
|
-
|
|
1247
|
+
u.status.message
|
|
1242
1248
|
);
|
|
1243
1249
|
if (w.length === 0)
|
|
1244
1250
|
break;
|
|
1245
|
-
const { results:
|
|
1251
|
+
const { results: g, shouldReturnToAgent: y } = await vt(w, o);
|
|
1246
1252
|
if (y) {
|
|
1247
|
-
const x = Q(
|
|
1248
|
-
|
|
1249
|
-
|
|
1253
|
+
const x = Q(g);
|
|
1254
|
+
u = await et(
|
|
1255
|
+
u.id,
|
|
1250
1256
|
x,
|
|
1251
|
-
u,
|
|
1252
|
-
o,
|
|
1253
1257
|
l,
|
|
1258
|
+
o,
|
|
1259
|
+
c,
|
|
1254
1260
|
m
|
|
1255
1261
|
);
|
|
1256
1262
|
} else
|
|
1257
1263
|
break;
|
|
1258
1264
|
}
|
|
1259
1265
|
return {
|
|
1260
|
-
...
|
|
1266
|
+
...u,
|
|
1261
1267
|
text: D(
|
|
1262
|
-
((d =
|
|
1268
|
+
((d = u.status) == null ? void 0 : d.message) || {
|
|
1263
1269
|
parts: [],
|
|
1264
1270
|
messageId: N()
|
|
1265
1271
|
}
|
|
@@ -1276,7 +1282,7 @@ function Zt(t) {
|
|
|
1276
1282
|
}
|
|
1277
1283
|
const ct = "a8c_agenttic_conversation_history";
|
|
1278
1284
|
function te(t) {
|
|
1279
|
-
var
|
|
1285
|
+
var f, h;
|
|
1280
1286
|
const e = t.parts.filter(
|
|
1281
1287
|
(m) => m.type === "text"
|
|
1282
1288
|
), s = e.map((m) => m.text).join(`
|
|
@@ -1297,12 +1303,12 @@ function te(t) {
|
|
|
1297
1303
|
toolCallId: m.data.toolCallId,
|
|
1298
1304
|
result: m.data.result,
|
|
1299
1305
|
error: m.data.error
|
|
1300
|
-
})),
|
|
1306
|
+
})), c = n.length > 0 || r.length > 0 ? "agent" : t.role, i = ((f = t.metadata) == null ? void 0 : f.timestamp) ?? Date.now(), l = ((h = t.metadata) == null ? void 0 : h.archived) ?? void 0;
|
|
1301
1307
|
return {
|
|
1302
|
-
role:
|
|
1308
|
+
role: c,
|
|
1303
1309
|
content: s || "(No text content)",
|
|
1304
1310
|
timestamp: i,
|
|
1305
|
-
...
|
|
1311
|
+
...l !== void 0 && { archived: l },
|
|
1306
1312
|
...a && { contentType: a },
|
|
1307
1313
|
...n.length > 0 && { toolCalls: n },
|
|
1308
1314
|
...r.length > 0 && { toolResults: r }
|
|
@@ -1516,24 +1522,24 @@ function ce() {
|
|
|
1516
1522
|
if (t.has(s))
|
|
1517
1523
|
return t.get(s).client;
|
|
1518
1524
|
const n = Zt(a), r = a.sessionId || null, o = a.conversationStorageKey;
|
|
1519
|
-
let
|
|
1525
|
+
let c = [];
|
|
1520
1526
|
if (r)
|
|
1521
1527
|
try {
|
|
1522
|
-
|
|
1528
|
+
c = await ne(
|
|
1523
1529
|
r,
|
|
1524
1530
|
o
|
|
1525
1531
|
);
|
|
1526
|
-
} catch (
|
|
1532
|
+
} catch (l) {
|
|
1527
1533
|
ut(
|
|
1528
1534
|
`Failed to load conversation history for agent ${s} with session ${r}:`,
|
|
1529
|
-
|
|
1535
|
+
l
|
|
1530
1536
|
);
|
|
1531
1537
|
}
|
|
1532
1538
|
const i = {
|
|
1533
1539
|
client: n,
|
|
1534
1540
|
sessionId: r,
|
|
1535
1541
|
conversationStorageKey: o,
|
|
1536
|
-
conversationHistory:
|
|
1542
|
+
conversationHistory: c,
|
|
1537
1543
|
currentAbortController: null
|
|
1538
1544
|
};
|
|
1539
1545
|
return t.set(s, i), n;
|
|
@@ -1549,21 +1555,21 @@ function ce() {
|
|
|
1549
1555
|
return t.delete(s);
|
|
1550
1556
|
},
|
|
1551
1557
|
async sendMessage(s, a, n = {}) {
|
|
1552
|
-
var
|
|
1558
|
+
var u;
|
|
1553
1559
|
const r = t.get(s);
|
|
1554
1560
|
if (!r)
|
|
1555
1561
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1556
|
-
const { withHistory: o = !0, ...
|
|
1557
|
-
message:
|
|
1562
|
+
const { withHistory: o = !0, ...c } = n, { client: i, conversationHistory: l } = r, f = n.message || mt(a, l), h = await i.sendMessage({
|
|
1563
|
+
message: f,
|
|
1558
1564
|
withHistory: o,
|
|
1559
|
-
...
|
|
1565
|
+
...c
|
|
1560
1566
|
});
|
|
1561
1567
|
let m = null;
|
|
1562
|
-
if ((
|
|
1568
|
+
if ((u = h.status) != null && u.message) {
|
|
1563
1569
|
const d = h.status.message.parts.filter(
|
|
1564
|
-
(
|
|
1570
|
+
(g) => g.type === "data" && "toolCallId" in g.data && ("arguments" in g.data || "result" in g.data)
|
|
1565
1571
|
), w = h.status.message.parts.filter(
|
|
1566
|
-
(
|
|
1572
|
+
(g) => g.type === "text"
|
|
1567
1573
|
);
|
|
1568
1574
|
m = {
|
|
1569
1575
|
role: "agent",
|
|
@@ -1576,7 +1582,7 @@ function ce() {
|
|
|
1576
1582
|
};
|
|
1577
1583
|
}
|
|
1578
1584
|
const p = [
|
|
1579
|
-
...
|
|
1585
|
+
...l,
|
|
1580
1586
|
// Store only the new content from the user message (without history parts)
|
|
1581
1587
|
nt(a),
|
|
1582
1588
|
// Add complete agent response with tool calls/results if present
|
|
@@ -1598,33 +1604,33 @@ function ce() {
|
|
|
1598
1604
|
), h;
|
|
1599
1605
|
},
|
|
1600
1606
|
async *sendMessageStream(s, a, n = {}) {
|
|
1601
|
-
var
|
|
1607
|
+
var g, y, x, I, P, T;
|
|
1602
1608
|
const r = t.get(s);
|
|
1603
1609
|
if (!r)
|
|
1604
1610
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1605
1611
|
const {
|
|
1606
1612
|
withHistory: o = !0,
|
|
1607
|
-
abortSignal:
|
|
1613
|
+
abortSignal: c,
|
|
1608
1614
|
metadata: i,
|
|
1609
|
-
...
|
|
1610
|
-
} = n, { client:
|
|
1611
|
-
r.currentAbortController = m,
|
|
1615
|
+
...l
|
|
1616
|
+
} = n, { client: f } = r, h = i ? (({ contentType: b, ...k }) => k)(i) : void 0, m = new AbortController();
|
|
1617
|
+
r.currentAbortController = m, c && c.addEventListener(
|
|
1612
1618
|
"abort",
|
|
1613
1619
|
() => m.abort()
|
|
1614
1620
|
);
|
|
1615
1621
|
let p = [
|
|
1616
1622
|
...r.conversationHistory
|
|
1617
1623
|
], S = [];
|
|
1618
|
-
const
|
|
1624
|
+
const u = await le(
|
|
1619
1625
|
p
|
|
1620
1626
|
);
|
|
1621
|
-
r.conversationHistory =
|
|
1627
|
+
r.conversationHistory = u, p = u, o && await e(
|
|
1622
1628
|
s,
|
|
1623
|
-
|
|
1629
|
+
u
|
|
1624
1630
|
);
|
|
1625
1631
|
const d = n.message || mt(
|
|
1626
1632
|
a,
|
|
1627
|
-
|
|
1633
|
+
u
|
|
1628
1634
|
);
|
|
1629
1635
|
if (n.metadata && !n.message) {
|
|
1630
1636
|
const { contentType: b, ...k } = n.metadata;
|
|
@@ -1648,16 +1654,16 @@ function ce() {
|
|
|
1648
1654
|
s,
|
|
1649
1655
|
p
|
|
1650
1656
|
);
|
|
1651
|
-
for await (const b of
|
|
1657
|
+
for await (const b of f.sendMessageStream({
|
|
1652
1658
|
message: d,
|
|
1653
1659
|
withHistory: o,
|
|
1654
1660
|
abortSignal: m.signal,
|
|
1655
|
-
...
|
|
1661
|
+
...l,
|
|
1656
1662
|
...h && Object.keys(h).length > 0 && {
|
|
1657
1663
|
metadata: h
|
|
1658
1664
|
}
|
|
1659
1665
|
})) {
|
|
1660
|
-
if (((
|
|
1666
|
+
if (((g = b.status) == null ? void 0 : g.state) === "input-required" && ((y = b.status) != null && y.message)) {
|
|
1661
1667
|
S = F(
|
|
1662
1668
|
b.status.message
|
|
1663
1669
|
).map(
|
|
@@ -1749,19 +1755,19 @@ function de() {
|
|
|
1749
1755
|
const [t, e] = yt([]), s = $(
|
|
1750
1756
|
(r) => {
|
|
1751
1757
|
e((o) => {
|
|
1752
|
-
const
|
|
1758
|
+
const c = o.findIndex(
|
|
1753
1759
|
(i) => i.id === r.id
|
|
1754
1760
|
);
|
|
1755
|
-
if (
|
|
1761
|
+
if (c >= 0) {
|
|
1756
1762
|
const i = [...o];
|
|
1757
|
-
return i[
|
|
1763
|
+
return i[c] = r, i;
|
|
1758
1764
|
}
|
|
1759
1765
|
return [...o, r];
|
|
1760
1766
|
});
|
|
1761
1767
|
},
|
|
1762
1768
|
[]
|
|
1763
1769
|
), a = $((r) => {
|
|
1764
|
-
e((o) => o.filter((
|
|
1770
|
+
e((o) => o.filter((c) => c.id !== r));
|
|
1765
1771
|
}, []), n = $(() => {
|
|
1766
1772
|
e([]);
|
|
1767
1773
|
}, []);
|
|
@@ -1785,20 +1791,20 @@ function ge(t, e) {
|
|
|
1785
1791
|
}));
|
|
1786
1792
|
}
|
|
1787
1793
|
const at = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), z = (t, e = []) => {
|
|
1788
|
-
var o,
|
|
1794
|
+
var o, c;
|
|
1789
1795
|
if (t.parts.some((i) => {
|
|
1790
1796
|
if (i.type === "data") {
|
|
1791
|
-
const
|
|
1792
|
-
return
|
|
1797
|
+
const l = i.data;
|
|
1798
|
+
return l.toolCallId || l.toolId || l.result;
|
|
1793
1799
|
}
|
|
1794
1800
|
return !1;
|
|
1795
1801
|
}))
|
|
1796
1802
|
return null;
|
|
1797
1803
|
const a = t.parts.map((i) => {
|
|
1798
|
-
var
|
|
1804
|
+
var l;
|
|
1799
1805
|
if (i.type === "text")
|
|
1800
1806
|
return {
|
|
1801
|
-
type: ((
|
|
1807
|
+
type: ((l = i.metadata) == null ? void 0 : l.contentType) || "text",
|
|
1802
1808
|
text: i.text
|
|
1803
1809
|
};
|
|
1804
1810
|
if (i.type === "file")
|
|
@@ -1807,14 +1813,14 @@ const at = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), z = (t, e =
|
|
|
1807
1813
|
image_url: i.file.uri || `data:${i.file.mimeType};base64,${i.file.bytes}`
|
|
1808
1814
|
};
|
|
1809
1815
|
if (i.type === "data") {
|
|
1810
|
-
const
|
|
1811
|
-
return
|
|
1816
|
+
const f = i.data;
|
|
1817
|
+
return f.component && f.componentProps ? {
|
|
1812
1818
|
type: "component",
|
|
1813
|
-
component:
|
|
1814
|
-
componentProps:
|
|
1819
|
+
component: f.component,
|
|
1820
|
+
componentProps: f.componentProps
|
|
1815
1821
|
} : {
|
|
1816
1822
|
type: "text",
|
|
1817
|
-
text: JSON.stringify(
|
|
1823
|
+
text: JSON.stringify(f)
|
|
1818
1824
|
};
|
|
1819
1825
|
}
|
|
1820
1826
|
return {
|
|
@@ -1826,7 +1832,7 @@ const at = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), z = (t, e =
|
|
|
1826
1832
|
role: t.role === "agent" ? "agent" : "user",
|
|
1827
1833
|
content: a,
|
|
1828
1834
|
timestamp: n,
|
|
1829
|
-
archived: !!((
|
|
1835
|
+
archived: !!((c = t.metadata) != null && c.archived),
|
|
1830
1836
|
showIcon: t.role === "agent",
|
|
1831
1837
|
icon: t.role === "agent" ? "assistant" : void 0
|
|
1832
1838
|
};
|
|
@@ -1864,11 +1870,11 @@ function Ee(t) {
|
|
|
1864
1870
|
}), {
|
|
1865
1871
|
registerMessageActions: r,
|
|
1866
1872
|
unregisterMessageActions: o,
|
|
1867
|
-
clearAllMessageActions:
|
|
1873
|
+
clearAllMessageActions: c,
|
|
1868
1874
|
registrations: i
|
|
1869
|
-
} = de(),
|
|
1875
|
+
} = de(), l = Ot(i);
|
|
1870
1876
|
tt(() => {
|
|
1871
|
-
|
|
1877
|
+
l.current = i;
|
|
1872
1878
|
}, [i]), tt(() => {
|
|
1873
1879
|
if (!s)
|
|
1874
1880
|
return;
|
|
@@ -1884,17 +1890,17 @@ function Ee(t) {
|
|
|
1884
1890
|
authProvider: t.authProvider,
|
|
1885
1891
|
enableStreaming: t.enableStreaming
|
|
1886
1892
|
});
|
|
1887
|
-
const
|
|
1893
|
+
const g = d.getConversationHistory(w);
|
|
1888
1894
|
n((y) => {
|
|
1889
|
-
const x =
|
|
1895
|
+
const x = g.map(
|
|
1890
1896
|
(I) => z(
|
|
1891
1897
|
I,
|
|
1892
|
-
|
|
1898
|
+
l.current
|
|
1893
1899
|
)
|
|
1894
1900
|
).filter((I) => I !== null);
|
|
1895
1901
|
return {
|
|
1896
1902
|
...y,
|
|
1897
|
-
clientMessages:
|
|
1903
|
+
clientMessages: g,
|
|
1898
1904
|
uiMessages: x
|
|
1899
1905
|
};
|
|
1900
1906
|
});
|
|
@@ -1910,15 +1916,15 @@ function Ee(t) {
|
|
|
1910
1916
|
t.enableStreaming,
|
|
1911
1917
|
s
|
|
1912
1918
|
]);
|
|
1913
|
-
const
|
|
1914
|
-
async (
|
|
1919
|
+
const f = $(
|
|
1920
|
+
async (u, d) => {
|
|
1915
1921
|
var P;
|
|
1916
1922
|
if (!s)
|
|
1917
1923
|
throw new Error("Invalid agent configuration");
|
|
1918
|
-
const w = st(),
|
|
1924
|
+
const w = st(), g = `${e.agentId}-${e.sessionId}`, y = Date.now(), x = (d == null ? void 0 : d.type) || "text", I = {
|
|
1919
1925
|
id: `user-${y}`,
|
|
1920
1926
|
role: "user",
|
|
1921
|
-
content: [{ type: x, text:
|
|
1927
|
+
content: [{ type: x, text: u }],
|
|
1922
1928
|
timestamp: y,
|
|
1923
1929
|
archived: (d == null ? void 0 : d.archived) ?? !1,
|
|
1924
1930
|
showIcon: !1
|
|
@@ -1937,8 +1943,8 @@ function Ee(t) {
|
|
|
1937
1943
|
...(d == null ? void 0 : d.type) && { contentType: d.type }
|
|
1938
1944
|
});
|
|
1939
1945
|
for await (const M of w.sendMessageStream(
|
|
1940
|
-
|
|
1941
|
-
|
|
1946
|
+
g,
|
|
1947
|
+
u,
|
|
1942
1948
|
k
|
|
1943
1949
|
)) {
|
|
1944
1950
|
if (!M.final && M.text)
|
|
@@ -1982,13 +1988,13 @@ function Ee(t) {
|
|
|
1982
1988
|
b = !0;
|
|
1983
1989
|
const C = T, A = z(
|
|
1984
1990
|
M.status.message,
|
|
1985
|
-
|
|
1991
|
+
l.current
|
|
1986
1992
|
);
|
|
1987
1993
|
A && n((q) => {
|
|
1988
1994
|
const _ = q.uiMessages.map(
|
|
1989
1995
|
(R) => R.id === C ? A : R
|
|
1990
1996
|
), E = w.getConversationHistory(
|
|
1991
|
-
|
|
1997
|
+
g
|
|
1992
1998
|
);
|
|
1993
1999
|
return {
|
|
1994
2000
|
...q,
|
|
@@ -2000,7 +2006,7 @@ function Ee(t) {
|
|
|
2000
2006
|
}
|
|
2001
2007
|
}
|
|
2002
2008
|
if (!b) {
|
|
2003
|
-
const M = w.getConversationHistory(
|
|
2009
|
+
const M = w.getConversationHistory(g);
|
|
2004
2010
|
n((C) => {
|
|
2005
2011
|
let A = C.uiMessages;
|
|
2006
2012
|
T && (A = C.uiMessages.filter(
|
|
@@ -2009,7 +2015,7 @@ function Ee(t) {
|
|
|
2009
2015
|
const q = M.map(
|
|
2010
2016
|
(O) => z(
|
|
2011
2017
|
O,
|
|
2012
|
-
|
|
2018
|
+
l.current
|
|
2013
2019
|
)
|
|
2014
2020
|
).filter(
|
|
2015
2021
|
(O) => O !== null
|
|
@@ -2051,41 +2057,41 @@ function Ee(t) {
|
|
|
2051
2057
|
}
|
|
2052
2058
|
},
|
|
2053
2059
|
[e.agentId, e.sessionId, s]
|
|
2054
|
-
), h = $((
|
|
2060
|
+
), h = $((u) => {
|
|
2055
2061
|
n((d) => ({
|
|
2056
2062
|
...d,
|
|
2057
|
-
uiMessages: at([...d.uiMessages,
|
|
2063
|
+
uiMessages: at([...d.uiMessages, u])
|
|
2058
2064
|
}));
|
|
2059
|
-
}, []), m = $((
|
|
2065
|
+
}, []), m = $((u) => {
|
|
2060
2066
|
n((d) => ({
|
|
2061
2067
|
...d,
|
|
2062
|
-
suggestions:
|
|
2068
|
+
suggestions: u
|
|
2063
2069
|
}));
|
|
2064
2070
|
}, []), p = $(() => {
|
|
2065
|
-
n((
|
|
2066
|
-
...
|
|
2071
|
+
n((u) => ({
|
|
2072
|
+
...u,
|
|
2067
2073
|
suggestions: []
|
|
2068
2074
|
}));
|
|
2069
2075
|
}, []);
|
|
2070
2076
|
tt(() => {
|
|
2071
|
-
n((
|
|
2072
|
-
if (
|
|
2073
|
-
return
|
|
2074
|
-
const d =
|
|
2075
|
-
(y) => z(y,
|
|
2077
|
+
n((u) => {
|
|
2078
|
+
if (u.clientMessages.length === 0)
|
|
2079
|
+
return u;
|
|
2080
|
+
const d = u.clientMessages.map(
|
|
2081
|
+
(y) => z(y, l.current)
|
|
2076
2082
|
).filter((y) => y !== null), w = new Set(
|
|
2077
|
-
|
|
2078
|
-
),
|
|
2083
|
+
u.clientMessages.map((y) => y.messageId)
|
|
2084
|
+
), g = u.uiMessages.filter(
|
|
2079
2085
|
(y) => {
|
|
2080
2086
|
var x;
|
|
2081
2087
|
return !w.has(y.id) && ((x = y.content[0]) == null ? void 0 : x.type) === "component";
|
|
2082
2088
|
}
|
|
2083
2089
|
);
|
|
2084
2090
|
return {
|
|
2085
|
-
...
|
|
2091
|
+
...u,
|
|
2086
2092
|
uiMessages: at([
|
|
2087
2093
|
...d,
|
|
2088
|
-
...
|
|
2094
|
+
...g
|
|
2089
2095
|
])
|
|
2090
2096
|
};
|
|
2091
2097
|
});
|
|
@@ -2093,15 +2099,15 @@ function Ee(t) {
|
|
|
2093
2099
|
const S = $(() => {
|
|
2094
2100
|
if (!s)
|
|
2095
2101
|
return;
|
|
2096
|
-
const
|
|
2097
|
-
|
|
2102
|
+
const u = st(), d = `${e.agentId}-${e.sessionId}`;
|
|
2103
|
+
u.abortCurrentRequest(d);
|
|
2098
2104
|
}, [e.agentId, e.sessionId, s]);
|
|
2099
2105
|
return {
|
|
2100
2106
|
// AgentUI props
|
|
2101
2107
|
messages: a.uiMessages,
|
|
2102
2108
|
isProcessing: a.isProcessing,
|
|
2103
2109
|
error: a.error,
|
|
2104
|
-
onSubmit:
|
|
2110
|
+
onSubmit: f,
|
|
2105
2111
|
suggestions: a.suggestions,
|
|
2106
2112
|
// UI management methods
|
|
2107
2113
|
registerSuggestions: m,
|
|
@@ -2109,7 +2115,7 @@ function Ee(t) {
|
|
|
2109
2115
|
// Message actions methods
|
|
2110
2116
|
registerMessageActions: r,
|
|
2111
2117
|
unregisterMessageActions: o,
|
|
2112
|
-
clearAllMessageActions:
|
|
2118
|
+
clearAllMessageActions: c,
|
|
2113
2119
|
// Tool integration
|
|
2114
2120
|
addMessage: h,
|
|
2115
2121
|
// Abort control
|
|
@@ -2123,18 +2129,18 @@ function we() {
|
|
|
2123
2129
|
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);
|
|
2124
2130
|
}
|
|
2125
2131
|
async function Ie(t, e = !0) {
|
|
2126
|
-
var i,
|
|
2132
|
+
var i, l;
|
|
2127
2133
|
const s = localStorage.getItem(pt);
|
|
2128
2134
|
let a;
|
|
2129
2135
|
if (s)
|
|
2130
2136
|
try {
|
|
2131
2137
|
a = JSON.parse(s);
|
|
2132
|
-
} catch (
|
|
2133
|
-
v("Invalid cached Jetpack token: %O",
|
|
2138
|
+
} catch (f) {
|
|
2139
|
+
v("Invalid cached Jetpack token: %O", f);
|
|
2134
2140
|
}
|
|
2135
2141
|
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && e)
|
|
2136
2142
|
return a;
|
|
2137
|
-
const n = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (
|
|
2143
|
+
const n = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (l = window.Jetpack_Editor_Initial_State) == null ? void 0 : l.wpcomBlogId;
|
|
2138
2144
|
let o = {
|
|
2139
2145
|
token: "",
|
|
2140
2146
|
blog_id: ""
|
|
@@ -2151,24 +2157,24 @@ async function Ie(t, e = !0) {
|
|
|
2151
2157
|
},
|
|
2152
2158
|
method: "POST"
|
|
2153
2159
|
});
|
|
2154
|
-
} catch (
|
|
2155
|
-
throw v("Failed to fetch Jetpack token: %O",
|
|
2160
|
+
} catch (f) {
|
|
2161
|
+
throw v("Failed to fetch Jetpack token: %O", f), new Error(t(f));
|
|
2156
2162
|
}
|
|
2157
2163
|
if (!(o != null && o.token))
|
|
2158
2164
|
throw new Error(
|
|
2159
2165
|
"Authentication failed. Please ensure Jetpack is properly connected and try again."
|
|
2160
2166
|
);
|
|
2161
|
-
const
|
|
2167
|
+
const c = {
|
|
2162
2168
|
token: o.token,
|
|
2163
2169
|
blogId: o.blog_id || "",
|
|
2164
2170
|
expire: Date.now() + ye
|
|
2165
2171
|
};
|
|
2166
2172
|
try {
|
|
2167
|
-
localStorage.setItem(pt, JSON.stringify(
|
|
2168
|
-
} catch (
|
|
2169
|
-
v("Error storing token in localStorage: %O",
|
|
2173
|
+
localStorage.setItem(pt, JSON.stringify(c));
|
|
2174
|
+
} catch (f) {
|
|
2175
|
+
v("Error storing token in localStorage: %O", f);
|
|
2170
2176
|
}
|
|
2171
|
-
return
|
|
2177
|
+
return c;
|
|
2172
2178
|
}
|
|
2173
2179
|
const Oe = (t) => async () => {
|
|
2174
2180
|
const e = {};
|