@automattic/agenttic-client 0.1.23 → 0.1.24
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 +178 -174
- 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;AAkMvB;;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
|
@@ -288,13 +288,13 @@ function jt(t, e = "") {
|
|
|
288
288
|
`
|
|
289
289
|
`,
|
|
290
290
|
o
|
|
291
|
-
),
|
|
292
|
-
if (
|
|
291
|
+
), u = i === -1 ? a.substring(o) : a.substring(o, i);
|
|
292
|
+
if (u.startsWith("data:"))
|
|
293
293
|
n !== "" && (n += `
|
|
294
|
-
`), n +=
|
|
295
|
-
|
|
294
|
+
`), n += u.substring(
|
|
295
|
+
u.startsWith("data: ") ? 6 : 5
|
|
296
296
|
);
|
|
297
|
-
else if (
|
|
297
|
+
else if (u.trim() === "" && n) {
|
|
298
298
|
try {
|
|
299
299
|
s.push(JSON.parse(n)), r = i === -1 ? a.length : i + 1;
|
|
300
300
|
} catch (g) {
|
|
@@ -308,32 +308,32 @@ function jt(t, e = "") {
|
|
|
308
308
|
return { events: s, nextBuffer: l };
|
|
309
309
|
}
|
|
310
310
|
async function* Jt(t, e = {}) {
|
|
311
|
-
var
|
|
311
|
+
var u, g, 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
315
|
let l = null, i = null;
|
|
316
316
|
try {
|
|
317
317
|
for (; ; ) {
|
|
318
|
-
const { done:
|
|
319
|
-
if (
|
|
318
|
+
const { done: m, value: p } = await a.read();
|
|
319
|
+
if (m)
|
|
320
320
|
break;
|
|
321
|
-
const S = n.decode(p, { stream: !0 }), { events: c, nextBuffer:
|
|
321
|
+
const S = n.decode(p, { stream: !0 }), { events: c, nextBuffer: d } = jt(S, r);
|
|
322
322
|
if (c && Array.isArray(c))
|
|
323
323
|
for (let w = 0; w < c.length; w++) {
|
|
324
|
-
const
|
|
325
|
-
if (w > 0 &&
|
|
324
|
+
const f = c[w];
|
|
325
|
+
if (w > 0 && f.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((y) => {
|
|
326
326
|
requestAnimationFrame(() => y(void 0));
|
|
327
|
-
}),
|
|
327
|
+
}), f.error)
|
|
328
328
|
throw new Error(
|
|
329
|
-
`Streaming error: ${
|
|
329
|
+
`Streaming error: ${f.error.message}`
|
|
330
330
|
);
|
|
331
|
-
if (s &&
|
|
332
|
-
const y =
|
|
331
|
+
if (s && f.method === "message/delta" && ((u = f.params) != null && u.delta)) {
|
|
332
|
+
const y = f.params.delta;
|
|
333
333
|
try {
|
|
334
334
|
if (y.deltaType === "content" && (o.processContentDelta(
|
|
335
335
|
y.content
|
|
336
|
-
), !l &&
|
|
336
|
+
), !l && f.params.id && (l = f.params.id), l)) {
|
|
337
337
|
const x = o.getCurrentMessage();
|
|
338
338
|
yield {
|
|
339
339
|
id: l,
|
|
@@ -348,29 +348,29 @@ 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 f.result && f.result.status ? (l = f.result.id, i = f.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset(), yield {
|
|
352
|
+
id: f.result.id,
|
|
353
|
+
status: f.result.status,
|
|
354
|
+
final: f.result.status.state === "completed" || f.result.status.state === "failed" || f.result.status.state === "canceled",
|
|
355
355
|
text: D(
|
|
356
|
-
((g =
|
|
356
|
+
((g = f.result.status) == null ? void 0 : g.message) || {
|
|
357
357
|
role: "agent",
|
|
358
358
|
parts: []
|
|
359
359
|
}
|
|
360
360
|
)
|
|
361
|
-
}) :
|
|
362
|
-
id:
|
|
363
|
-
status:
|
|
364
|
-
final:
|
|
361
|
+
}) : f.id && f.result && (l = f.result.id, f.result.status && (yield {
|
|
362
|
+
id: f.result.id,
|
|
363
|
+
status: f.result.status,
|
|
364
|
+
final: f.result.status.state === "completed" || f.result.status.state === "failed" || f.result.status.state === "canceled",
|
|
365
365
|
text: D(
|
|
366
|
-
((h =
|
|
366
|
+
((h = f.result.status) == null ? void 0 : h.message) || {
|
|
367
367
|
role: "agent",
|
|
368
368
|
parts: []
|
|
369
369
|
}
|
|
370
370
|
)
|
|
371
371
|
}));
|
|
372
372
|
}
|
|
373
|
-
r =
|
|
373
|
+
r = d;
|
|
374
374
|
}
|
|
375
375
|
} finally {
|
|
376
376
|
a.releaseLock();
|
|
@@ -526,34 +526,34 @@ 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: l, taskId: i, metadata:
|
|
529
|
+
const { message: o, sessionId: l, taskId: i, metadata: u } = t, { agentId: g, agentUrl: h, authProvider: m, proxy: p } = e, { isStreaming: S = !1, enableTokenStreaming: c = !1 } = s, d = l || r, w = Vt(h, g), f = await Ut(
|
|
530
530
|
o,
|
|
531
531
|
a,
|
|
532
532
|
n
|
|
533
533
|
), y = Nt(
|
|
534
534
|
{
|
|
535
535
|
id: i,
|
|
536
|
-
sessionId:
|
|
537
|
-
message:
|
|
538
|
-
metadata:
|
|
536
|
+
sessionId: d,
|
|
537
|
+
message: f,
|
|
538
|
+
metadata: u
|
|
539
539
|
},
|
|
540
540
|
S ? "message/stream" : "message/send",
|
|
541
541
|
c && S
|
|
542
542
|
// Only enable token streaming if using SSE
|
|
543
|
-
), x = await zt(
|
|
543
|
+
), x = await zt(m, S);
|
|
544
544
|
return Bt("POST", w, x, y), {
|
|
545
545
|
request: y,
|
|
546
546
|
headers: x,
|
|
547
|
-
enhancedMessage:
|
|
548
|
-
effectiveSessionId:
|
|
547
|
+
enhancedMessage: f,
|
|
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: l } = s, { timeoutId: i, controller:
|
|
553
|
+
const { request: a, headers: n, fullAgentUrl: r } = t, { timeout: o } = e, { abortSignal: l } = s, { timeoutId: i, controller: u } = xt(
|
|
554
554
|
o,
|
|
555
555
|
"request"
|
|
556
|
-
), g = l ? bt(
|
|
556
|
+
), g = l ? bt(u.signal, l) : u.signal;
|
|
557
557
|
try {
|
|
558
558
|
const h = Mt(
|
|
559
559
|
n,
|
|
@@ -564,13 +564,13 @@ async function At(t, e, s = {}) {
|
|
|
564
564
|
method: h.method,
|
|
565
565
|
headers: h.headers
|
|
566
566
|
});
|
|
567
|
-
const
|
|
568
|
-
clearTimeout(i), Ct(
|
|
569
|
-
const p = await
|
|
567
|
+
const m = await fetch(r, h);
|
|
568
|
+
clearTimeout(i), Ct(m, "request");
|
|
569
|
+
const p = await m.json();
|
|
570
570
|
return v(
|
|
571
571
|
"Response from %s: %d %O",
|
|
572
572
|
r,
|
|
573
|
-
|
|
573
|
+
m.status,
|
|
574
574
|
wt(p)
|
|
575
575
|
), Lt(p, "request");
|
|
576
576
|
} catch (h) {
|
|
@@ -582,13 +582,13 @@ async function* St(t, e, s) {
|
|
|
582
582
|
streamingTimeout: o = 6e4,
|
|
583
583
|
abortSignal: l,
|
|
584
584
|
enableTokenStreaming: i = !1
|
|
585
|
-
} = s, { timeoutId:
|
|
585
|
+
} = s, { timeoutId: u, controller: g } = xt(
|
|
586
586
|
o,
|
|
587
587
|
"streaming request"
|
|
588
588
|
), h = l ? bt(g.signal, l) : g.signal;
|
|
589
589
|
try {
|
|
590
|
-
const
|
|
591
|
-
if (clearTimeout(
|
|
590
|
+
const m = JSON.stringify(a), p = Mt(n, m, h), S = await fetch(r, p);
|
|
591
|
+
if (clearTimeout(u), Wt(S, "streaming request"), !S.body)
|
|
592
592
|
throw new Error(
|
|
593
593
|
"Response body is null - server may not support streaming"
|
|
594
594
|
);
|
|
@@ -596,8 +596,8 @@ async function* St(t, e, s) {
|
|
|
596
596
|
yield* Jt(S.body, {
|
|
597
597
|
supportDeltas: c
|
|
598
598
|
});
|
|
599
|
-
} catch (
|
|
600
|
-
Tt(
|
|
599
|
+
} catch (m) {
|
|
600
|
+
Tt(m, u, "streaming request");
|
|
601
601
|
}
|
|
602
602
|
}
|
|
603
603
|
const Qt = 12e4;
|
|
@@ -610,7 +610,11 @@ async function G(t, e, s, a, n) {
|
|
|
610
610
|
if (e === l || e === o.name) {
|
|
611
611
|
if (o.callback)
|
|
612
612
|
try {
|
|
613
|
-
|
|
613
|
+
const i = {
|
|
614
|
+
...s,
|
|
615
|
+
...a && { messageId: a }
|
|
616
|
+
}, u = await o.callback(i), g = (u == null ? void 0 : u.returnToAgent) !== void 0 ? u.returnToAgent : !0;
|
|
617
|
+
return { result: u, returnToAgent: g };
|
|
614
618
|
} catch (i) {
|
|
615
619
|
return v(
|
|
616
620
|
"Error executing ability %s: %O",
|
|
@@ -705,16 +709,16 @@ async function vt(t, e, s) {
|
|
|
705
709
|
const a = [], n = [];
|
|
706
710
|
let r = !1;
|
|
707
711
|
for (const o of t) {
|
|
708
|
-
const { toolCallId: l, toolId: i, arguments:
|
|
712
|
+
const { toolCallId: l, toolId: i, arguments: u } = o.data;
|
|
709
713
|
try {
|
|
710
714
|
const g = await G(
|
|
711
715
|
e,
|
|
712
716
|
i,
|
|
713
|
-
|
|
717
|
+
u,
|
|
714
718
|
s,
|
|
715
719
|
l
|
|
716
|
-
), { result: h, returnToAgent:
|
|
717
|
-
|
|
720
|
+
), { result: h, returnToAgent: m, agentMessage: p } = it(g);
|
|
721
|
+
m && (r = !0), p && n.push(W(p)), a.push(
|
|
718
722
|
j(
|
|
719
723
|
l,
|
|
720
724
|
i,
|
|
@@ -766,13 +770,13 @@ async function et(t, e, s, a, n, r, o) {
|
|
|
766
770
|
});
|
|
767
771
|
}
|
|
768
772
|
async function ft(t, e, s, a, n, r, o, l, i = []) {
|
|
769
|
-
const
|
|
773
|
+
const u = {
|
|
770
774
|
message: e,
|
|
771
775
|
taskId: t,
|
|
772
776
|
sessionId: void 0
|
|
773
777
|
// Use task's session
|
|
774
778
|
}, g = l || { isStreaming: !0 }, h = await X(
|
|
775
|
-
|
|
779
|
+
u,
|
|
776
780
|
s,
|
|
777
781
|
{
|
|
778
782
|
...g
|
|
@@ -780,12 +784,12 @@ async function ft(t, e, s, a, n, r, o, l, i = []) {
|
|
|
780
784
|
a,
|
|
781
785
|
n,
|
|
782
786
|
r
|
|
783
|
-
),
|
|
787
|
+
), m = St(h, s, {
|
|
784
788
|
...g,
|
|
785
789
|
abortSignal: o
|
|
786
790
|
});
|
|
787
791
|
return kt(
|
|
788
|
-
|
|
792
|
+
m,
|
|
789
793
|
a,
|
|
790
794
|
n,
|
|
791
795
|
s,
|
|
@@ -800,7 +804,7 @@ async function ft(t, e, s, a, n, r, o, l, i = []) {
|
|
|
800
804
|
);
|
|
801
805
|
}
|
|
802
806
|
async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
803
|
-
var
|
|
807
|
+
var u, g, h, m, p, S, c, d, w, f, y, x;
|
|
804
808
|
for await (const I of t) {
|
|
805
809
|
if (yield I, I.status.state === "running" && I.status.message && e && await Xt(
|
|
806
810
|
e,
|
|
@@ -815,7 +819,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
815
819
|
e,
|
|
816
820
|
k,
|
|
817
821
|
M,
|
|
818
|
-
(g = (
|
|
822
|
+
(g = (u = I.status) == null ? void 0 : u.message) == null ? void 0 : g.messageId,
|
|
819
823
|
b
|
|
820
824
|
).catch((C) => {
|
|
821
825
|
v("Tool execution failed for %s: %O", k, C);
|
|
@@ -855,7 +859,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
855
859
|
e,
|
|
856
860
|
q,
|
|
857
861
|
_,
|
|
858
|
-
(
|
|
862
|
+
(m = (h = I.status) == null ? void 0 : h.message) == null ? void 0 : m.messageId,
|
|
859
863
|
A
|
|
860
864
|
), { result: R, returnToAgent: O, agentMessage: J } = it(E);
|
|
861
865
|
if (O && (b = !0), J && M.push(
|
|
@@ -957,7 +961,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
957
961
|
} = await vt(
|
|
958
962
|
E,
|
|
959
963
|
e,
|
|
960
|
-
(w = (
|
|
964
|
+
(w = (d = R.status) == null ? void 0 : d.message) == null ? void 0 : w.messageId
|
|
961
965
|
);
|
|
962
966
|
if (O.length > 0 && (yield {
|
|
963
967
|
id: R.id,
|
|
@@ -997,7 +1001,7 @@ async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
|
997
1001
|
throw new Error(
|
|
998
1002
|
"Continue task stream ended without final result"
|
|
999
1003
|
);
|
|
1000
|
-
R = H, E = (
|
|
1004
|
+
R = H, E = (f = R.status) != null && f.message ? F(
|
|
1001
1005
|
R.status.message
|
|
1002
1006
|
) : [], E.length > 0 && (yield {
|
|
1003
1007
|
id: R.id,
|
|
@@ -1064,7 +1068,7 @@ function Zt(t) {
|
|
|
1064
1068
|
toolProvider: o,
|
|
1065
1069
|
contextProvider: l,
|
|
1066
1070
|
enableStreaming: i = !1
|
|
1067
|
-
} = t,
|
|
1071
|
+
} = t, u = {
|
|
1068
1072
|
agentId: e,
|
|
1069
1073
|
agentUrl: s,
|
|
1070
1074
|
authProvider: a,
|
|
@@ -1072,30 +1076,30 @@ function Zt(t) {
|
|
|
1072
1076
|
};
|
|
1073
1077
|
return {
|
|
1074
1078
|
async sendMessage(g) {
|
|
1075
|
-
var
|
|
1076
|
-
const { abortSignal: h } = g,
|
|
1079
|
+
var f, y;
|
|
1080
|
+
const { abortSignal: h } = g, m = g.sessionId || n || void 0, p = [];
|
|
1077
1081
|
p.push(g.message);
|
|
1078
1082
|
const S = await X(
|
|
1079
1083
|
g,
|
|
1080
|
-
|
|
1084
|
+
u,
|
|
1081
1085
|
{ isStreaming: !1 },
|
|
1082
1086
|
o,
|
|
1083
1087
|
l,
|
|
1084
|
-
|
|
1088
|
+
m
|
|
1085
1089
|
);
|
|
1086
1090
|
let c = await At(
|
|
1087
1091
|
S,
|
|
1088
|
-
|
|
1092
|
+
u,
|
|
1089
1093
|
{ abortSignal: h }
|
|
1090
1094
|
);
|
|
1091
|
-
const
|
|
1095
|
+
const d = [], w = [];
|
|
1092
1096
|
for (; c.status.message && o; ) {
|
|
1093
1097
|
const x = F(
|
|
1094
1098
|
c.status.message
|
|
1095
1099
|
);
|
|
1096
1100
|
if (x.length === 0)
|
|
1097
1101
|
break;
|
|
1098
|
-
|
|
1102
|
+
d.push(...x);
|
|
1099
1103
|
const I = [];
|
|
1100
1104
|
let P = !1;
|
|
1101
1105
|
for (const T of x) {
|
|
@@ -1118,7 +1122,7 @@ function Zt(t) {
|
|
|
1118
1122
|
k,
|
|
1119
1123
|
A
|
|
1120
1124
|
);
|
|
1121
|
-
I.push(E),
|
|
1125
|
+
I.push(E), d.push(E);
|
|
1122
1126
|
} catch (C) {
|
|
1123
1127
|
const A = j(
|
|
1124
1128
|
b,
|
|
@@ -1126,7 +1130,7 @@ function Zt(t) {
|
|
|
1126
1130
|
void 0,
|
|
1127
1131
|
C instanceof Error ? C.message : String(C)
|
|
1128
1132
|
);
|
|
1129
|
-
I.push(A),
|
|
1133
|
+
I.push(A), d.push(A);
|
|
1130
1134
|
}
|
|
1131
1135
|
}
|
|
1132
1136
|
if (p.push(c.status.message), P) {
|
|
@@ -1134,19 +1138,19 @@ function Zt(t) {
|
|
|
1134
1138
|
c = await et(
|
|
1135
1139
|
c.id,
|
|
1136
1140
|
T,
|
|
1137
|
-
|
|
1141
|
+
u,
|
|
1138
1142
|
o,
|
|
1139
1143
|
l,
|
|
1140
|
-
|
|
1144
|
+
m,
|
|
1141
1145
|
h
|
|
1142
1146
|
);
|
|
1143
1147
|
} else
|
|
1144
1148
|
break;
|
|
1145
1149
|
}
|
|
1146
|
-
if (
|
|
1150
|
+
if (d.length > 0 && (f = c.status) != null && f.message) {
|
|
1147
1151
|
const x = {
|
|
1148
1152
|
...c.status.message,
|
|
1149
|
-
parts:
|
|
1153
|
+
parts: d
|
|
1150
1154
|
};
|
|
1151
1155
|
c = {
|
|
1152
1156
|
...c,
|
|
@@ -1180,13 +1184,13 @@ function Zt(t) {
|
|
|
1180
1184
|
async *sendMessageStream(g) {
|
|
1181
1185
|
const {
|
|
1182
1186
|
withHistory: h = !0,
|
|
1183
|
-
abortSignal:
|
|
1187
|
+
abortSignal: m,
|
|
1184
1188
|
enableStreaming: p
|
|
1185
|
-
} = g, S = g.sessionId || n || void 0, c = p ?? i,
|
|
1186
|
-
|
|
1189
|
+
} = g, S = g.sessionId || n || void 0, c = p ?? i, d = [];
|
|
1190
|
+
d.push(g.message);
|
|
1187
1191
|
const w = await X(
|
|
1188
1192
|
g,
|
|
1189
|
-
|
|
1193
|
+
u,
|
|
1190
1194
|
{
|
|
1191
1195
|
isStreaming: !0,
|
|
1192
1196
|
// Always use message/stream endpoint for SSE
|
|
@@ -1195,25 +1199,25 @@ function Zt(t) {
|
|
|
1195
1199
|
o,
|
|
1196
1200
|
l,
|
|
1197
1201
|
S
|
|
1198
|
-
),
|
|
1202
|
+
), f = St(
|
|
1199
1203
|
w,
|
|
1200
|
-
|
|
1204
|
+
u,
|
|
1201
1205
|
{
|
|
1202
1206
|
enableTokenStreaming: c,
|
|
1203
1207
|
// Token streaming is optional
|
|
1204
1208
|
streamingTimeout: r,
|
|
1205
|
-
abortSignal:
|
|
1209
|
+
abortSignal: m
|
|
1206
1210
|
}
|
|
1207
1211
|
);
|
|
1208
1212
|
yield* kt(
|
|
1209
|
-
|
|
1213
|
+
f,
|
|
1210
1214
|
o,
|
|
1211
1215
|
l,
|
|
1212
|
-
|
|
1216
|
+
u,
|
|
1213
1217
|
S,
|
|
1214
1218
|
h,
|
|
1215
|
-
|
|
1216
|
-
|
|
1219
|
+
d,
|
|
1220
|
+
m,
|
|
1217
1221
|
{
|
|
1218
1222
|
isStreaming: !0,
|
|
1219
1223
|
enableTokenStreaming: c,
|
|
@@ -1221,16 +1225,16 @@ function Zt(t) {
|
|
|
1221
1225
|
}
|
|
1222
1226
|
);
|
|
1223
1227
|
},
|
|
1224
|
-
async continueTask(g, h,
|
|
1225
|
-
var
|
|
1228
|
+
async continueTask(g, h, m) {
|
|
1229
|
+
var d;
|
|
1226
1230
|
const p = nt(h);
|
|
1227
1231
|
let c = await et(
|
|
1228
1232
|
g,
|
|
1229
1233
|
p,
|
|
1230
|
-
|
|
1234
|
+
u,
|
|
1231
1235
|
o,
|
|
1232
1236
|
l,
|
|
1233
|
-
|
|
1237
|
+
m
|
|
1234
1238
|
);
|
|
1235
1239
|
for (; c.status.state === "input-required" && c.status.message && o; ) {
|
|
1236
1240
|
const w = F(
|
|
@@ -1238,16 +1242,16 @@ function Zt(t) {
|
|
|
1238
1242
|
);
|
|
1239
1243
|
if (w.length === 0)
|
|
1240
1244
|
break;
|
|
1241
|
-
const { results:
|
|
1245
|
+
const { results: f, shouldReturnToAgent: y } = await vt(w, o);
|
|
1242
1246
|
if (y) {
|
|
1243
|
-
const x = Q(
|
|
1247
|
+
const x = Q(f);
|
|
1244
1248
|
c = await et(
|
|
1245
1249
|
c.id,
|
|
1246
1250
|
x,
|
|
1247
|
-
|
|
1251
|
+
u,
|
|
1248
1252
|
o,
|
|
1249
1253
|
l,
|
|
1250
|
-
|
|
1254
|
+
m
|
|
1251
1255
|
);
|
|
1252
1256
|
} else
|
|
1253
1257
|
break;
|
|
@@ -1255,7 +1259,7 @@ function Zt(t) {
|
|
|
1255
1259
|
return {
|
|
1256
1260
|
...c,
|
|
1257
1261
|
text: D(
|
|
1258
|
-
((
|
|
1262
|
+
((d = c.status) == null ? void 0 : d.message) || {
|
|
1259
1263
|
parts: [],
|
|
1260
1264
|
messageId: N()
|
|
1261
1265
|
}
|
|
@@ -1274,31 +1278,31 @@ const ct = "a8c_agenttic_conversation_history";
|
|
|
1274
1278
|
function te(t) {
|
|
1275
1279
|
var g, h;
|
|
1276
1280
|
const e = t.parts.filter(
|
|
1277
|
-
(
|
|
1278
|
-
), s = e.map((
|
|
1281
|
+
(m) => m.type === "text"
|
|
1282
|
+
), s = e.map((m) => m.text).join(`
|
|
1279
1283
|
`), a = e.some(
|
|
1280
|
-
(
|
|
1284
|
+
(m) => {
|
|
1281
1285
|
var p;
|
|
1282
|
-
return ((p =
|
|
1286
|
+
return ((p = m.metadata) == null ? void 0 : p.contentType) === "context";
|
|
1283
1287
|
}
|
|
1284
1288
|
) ? "context" : void 0, n = t.parts.filter(
|
|
1285
|
-
(
|
|
1286
|
-
).map((
|
|
1287
|
-
toolCallId:
|
|
1288
|
-
toolId:
|
|
1289
|
-
arguments:
|
|
1289
|
+
(m) => m.type === "data" && "toolCallId" in m.data && "arguments" in m.data
|
|
1290
|
+
).map((m) => ({
|
|
1291
|
+
toolCallId: m.data.toolCallId,
|
|
1292
|
+
toolId: m.data.toolId,
|
|
1293
|
+
arguments: m.data.arguments
|
|
1290
1294
|
})), r = t.parts.filter(
|
|
1291
|
-
(
|
|
1292
|
-
).map((
|
|
1293
|
-
toolCallId:
|
|
1294
|
-
result:
|
|
1295
|
-
error:
|
|
1296
|
-
})), l = n.length > 0 || r.length > 0 ? "agent" : t.role, i = ((g = t.metadata) == null ? void 0 : g.timestamp) ?? Date.now(),
|
|
1295
|
+
(m) => m.type === "data" && "toolCallId" in m.data && "result" in m.data
|
|
1296
|
+
).map((m) => ({
|
|
1297
|
+
toolCallId: m.data.toolCallId,
|
|
1298
|
+
result: m.data.result,
|
|
1299
|
+
error: m.data.error
|
|
1300
|
+
})), l = n.length > 0 || r.length > 0 ? "agent" : t.role, i = ((g = t.metadata) == null ? void 0 : g.timestamp) ?? Date.now(), u = ((h = t.metadata) == null ? void 0 : h.archived) ?? void 0;
|
|
1297
1301
|
return {
|
|
1298
1302
|
role: l,
|
|
1299
1303
|
content: s || "(No text content)",
|
|
1300
1304
|
timestamp: i,
|
|
1301
|
-
...
|
|
1305
|
+
...u !== void 0 && { archived: u },
|
|
1302
1306
|
...a && { contentType: a },
|
|
1303
1307
|
...n.length > 0 && { toolCalls: n },
|
|
1304
1308
|
...r.length > 0 && { toolResults: r }
|
|
@@ -1519,10 +1523,10 @@ function ce() {
|
|
|
1519
1523
|
r,
|
|
1520
1524
|
o
|
|
1521
1525
|
);
|
|
1522
|
-
} catch (
|
|
1526
|
+
} catch (u) {
|
|
1523
1527
|
ut(
|
|
1524
1528
|
`Failed to load conversation history for agent ${s} with session ${r}:`,
|
|
1525
|
-
|
|
1529
|
+
u
|
|
1526
1530
|
);
|
|
1527
1531
|
}
|
|
1528
1532
|
const i = {
|
|
@@ -1549,22 +1553,22 @@ function ce() {
|
|
|
1549
1553
|
const r = t.get(s);
|
|
1550
1554
|
if (!r)
|
|
1551
1555
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1552
|
-
const { withHistory: o = !0, ...l } = n, { client: i, conversationHistory:
|
|
1556
|
+
const { withHistory: o = !0, ...l } = n, { client: i, conversationHistory: u } = r, g = n.message || mt(a, u), h = await i.sendMessage({
|
|
1553
1557
|
message: g,
|
|
1554
1558
|
withHistory: o,
|
|
1555
1559
|
...l
|
|
1556
1560
|
});
|
|
1557
|
-
let
|
|
1561
|
+
let m = null;
|
|
1558
1562
|
if ((c = h.status) != null && c.message) {
|
|
1559
|
-
const
|
|
1560
|
-
(
|
|
1563
|
+
const d = h.status.message.parts.filter(
|
|
1564
|
+
(f) => f.type === "data" && "toolCallId" in f.data && ("arguments" in f.data || "result" in f.data)
|
|
1561
1565
|
), w = h.status.message.parts.filter(
|
|
1562
|
-
(
|
|
1566
|
+
(f) => f.type === "text"
|
|
1563
1567
|
);
|
|
1564
|
-
|
|
1568
|
+
m = {
|
|
1565
1569
|
role: "agent",
|
|
1566
1570
|
kind: "message",
|
|
1567
|
-
parts: [...
|
|
1571
|
+
parts: [...d, ...w],
|
|
1568
1572
|
messageId: N(),
|
|
1569
1573
|
metadata: {
|
|
1570
1574
|
timestamp: Date.now()
|
|
@@ -1572,20 +1576,20 @@ function ce() {
|
|
|
1572
1576
|
};
|
|
1573
1577
|
}
|
|
1574
1578
|
const p = [
|
|
1575
|
-
...
|
|
1579
|
+
...u,
|
|
1576
1580
|
// Store only the new content from the user message (without history parts)
|
|
1577
1581
|
nt(a),
|
|
1578
1582
|
// Add complete agent response with tool calls/results if present
|
|
1579
|
-
...
|
|
1583
|
+
...m ? [L(m)] : []
|
|
1580
1584
|
];
|
|
1581
1585
|
let S = p;
|
|
1582
1586
|
if (h.agentMessage) {
|
|
1583
|
-
const
|
|
1587
|
+
const d = L(
|
|
1584
1588
|
h.agentMessage
|
|
1585
1589
|
);
|
|
1586
1590
|
S = [
|
|
1587
1591
|
...p,
|
|
1588
|
-
|
|
1592
|
+
d
|
|
1589
1593
|
];
|
|
1590
1594
|
}
|
|
1591
1595
|
return r.conversationHistory = S, o && await e(
|
|
@@ -1594,7 +1598,7 @@ function ce() {
|
|
|
1594
1598
|
), h;
|
|
1595
1599
|
},
|
|
1596
1600
|
async *sendMessageStream(s, a, n = {}) {
|
|
1597
|
-
var
|
|
1601
|
+
var f, y, x, I, P, T;
|
|
1598
1602
|
const r = t.get(s);
|
|
1599
1603
|
if (!r)
|
|
1600
1604
|
throw new Error(`Agent with key "${s}" not found`);
|
|
@@ -1602,11 +1606,11 @@ function ce() {
|
|
|
1602
1606
|
withHistory: o = !0,
|
|
1603
1607
|
abortSignal: l,
|
|
1604
1608
|
metadata: i,
|
|
1605
|
-
...
|
|
1606
|
-
} = n, { client: g } = r, h = i ? (({ contentType: b, ...k }) => k)(i) : void 0,
|
|
1607
|
-
r.currentAbortController =
|
|
1609
|
+
...u
|
|
1610
|
+
} = n, { client: g } = r, h = i ? (({ contentType: b, ...k }) => k)(i) : void 0, m = new AbortController();
|
|
1611
|
+
r.currentAbortController = m, l && l.addEventListener(
|
|
1608
1612
|
"abort",
|
|
1609
|
-
() =>
|
|
1613
|
+
() => m.abort()
|
|
1610
1614
|
);
|
|
1611
1615
|
let p = [
|
|
1612
1616
|
...r.conversationHistory
|
|
@@ -1618,21 +1622,21 @@ function ce() {
|
|
|
1618
1622
|
s,
|
|
1619
1623
|
c
|
|
1620
1624
|
);
|
|
1621
|
-
const
|
|
1625
|
+
const d = n.message || mt(
|
|
1622
1626
|
a,
|
|
1623
1627
|
c
|
|
1624
1628
|
);
|
|
1625
1629
|
if (n.metadata && !n.message) {
|
|
1626
1630
|
const { contentType: b, ...k } = n.metadata;
|
|
1627
1631
|
if (b) {
|
|
1628
|
-
const M =
|
|
1632
|
+
const M = d.parts[d.parts.length - 1];
|
|
1629
1633
|
M && M.type === "text" && (M.metadata = {
|
|
1630
1634
|
...M.metadata,
|
|
1631
1635
|
contentType: b
|
|
1632
1636
|
});
|
|
1633
1637
|
}
|
|
1634
|
-
Object.keys(k).length > 0 && (
|
|
1635
|
-
...
|
|
1638
|
+
Object.keys(k).length > 0 && (d.metadata = {
|
|
1639
|
+
...d.metadata,
|
|
1636
1640
|
...k
|
|
1637
1641
|
});
|
|
1638
1642
|
}
|
|
@@ -1645,15 +1649,15 @@ function ce() {
|
|
|
1645
1649
|
p
|
|
1646
1650
|
);
|
|
1647
1651
|
for await (const b of g.sendMessageStream({
|
|
1648
|
-
message:
|
|
1652
|
+
message: d,
|
|
1649
1653
|
withHistory: o,
|
|
1650
|
-
abortSignal:
|
|
1651
|
-
...
|
|
1654
|
+
abortSignal: m.signal,
|
|
1655
|
+
...u,
|
|
1652
1656
|
...h && Object.keys(h).length > 0 && {
|
|
1653
1657
|
metadata: h
|
|
1654
1658
|
}
|
|
1655
1659
|
})) {
|
|
1656
|
-
if (((
|
|
1660
|
+
if (((f = b.status) == null ? void 0 : f.state) === "input-required" && ((y = b.status) != null && y.message)) {
|
|
1657
1661
|
S = F(
|
|
1658
1662
|
b.status.message
|
|
1659
1663
|
).map(
|
|
@@ -1784,17 +1788,17 @@ const at = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), z = (t, e =
|
|
|
1784
1788
|
var o, l;
|
|
1785
1789
|
if (t.parts.some((i) => {
|
|
1786
1790
|
if (i.type === "data") {
|
|
1787
|
-
const
|
|
1788
|
-
return
|
|
1791
|
+
const u = i.data;
|
|
1792
|
+
return u.toolCallId || u.toolId || u.result;
|
|
1789
1793
|
}
|
|
1790
1794
|
return !1;
|
|
1791
1795
|
}))
|
|
1792
1796
|
return null;
|
|
1793
1797
|
const a = t.parts.map((i) => {
|
|
1794
|
-
var
|
|
1798
|
+
var u;
|
|
1795
1799
|
if (i.type === "text")
|
|
1796
1800
|
return {
|
|
1797
|
-
type: ((
|
|
1801
|
+
type: ((u = i.metadata) == null ? void 0 : u.contentType) || "text",
|
|
1798
1802
|
text: i.text
|
|
1799
1803
|
};
|
|
1800
1804
|
if (i.type === "file")
|
|
@@ -1862,16 +1866,16 @@ function Ee(t) {
|
|
|
1862
1866
|
unregisterMessageActions: o,
|
|
1863
1867
|
clearAllMessageActions: l,
|
|
1864
1868
|
registrations: i
|
|
1865
|
-
} = de(),
|
|
1869
|
+
} = de(), u = Ot(i);
|
|
1866
1870
|
tt(() => {
|
|
1867
|
-
|
|
1871
|
+
u.current = i;
|
|
1868
1872
|
}, [i]), tt(() => {
|
|
1869
1873
|
if (!s)
|
|
1870
1874
|
return;
|
|
1871
1875
|
(async () => {
|
|
1872
1876
|
if (e.sessionId) {
|
|
1873
|
-
const
|
|
1874
|
-
|
|
1877
|
+
const d = st(), w = `${e.agentId}-${e.sessionId}`;
|
|
1878
|
+
d.hasAgent(w) || await d.createAgent(w, {
|
|
1875
1879
|
agentId: e.agentId,
|
|
1876
1880
|
agentUrl: e.agentUrl,
|
|
1877
1881
|
sessionId: e.sessionId,
|
|
@@ -1880,17 +1884,17 @@ function Ee(t) {
|
|
|
1880
1884
|
authProvider: t.authProvider,
|
|
1881
1885
|
enableStreaming: t.enableStreaming
|
|
1882
1886
|
});
|
|
1883
|
-
const
|
|
1887
|
+
const f = d.getConversationHistory(w);
|
|
1884
1888
|
n((y) => {
|
|
1885
|
-
const x =
|
|
1889
|
+
const x = f.map(
|
|
1886
1890
|
(I) => z(
|
|
1887
1891
|
I,
|
|
1888
|
-
|
|
1892
|
+
u.current
|
|
1889
1893
|
)
|
|
1890
1894
|
).filter((I) => I !== null);
|
|
1891
1895
|
return {
|
|
1892
1896
|
...y,
|
|
1893
|
-
clientMessages:
|
|
1897
|
+
clientMessages: f,
|
|
1894
1898
|
uiMessages: x
|
|
1895
1899
|
};
|
|
1896
1900
|
});
|
|
@@ -1907,16 +1911,16 @@ function Ee(t) {
|
|
|
1907
1911
|
s
|
|
1908
1912
|
]);
|
|
1909
1913
|
const g = $(
|
|
1910
|
-
async (c,
|
|
1914
|
+
async (c, d) => {
|
|
1911
1915
|
var P;
|
|
1912
1916
|
if (!s)
|
|
1913
1917
|
throw new Error("Invalid agent configuration");
|
|
1914
|
-
const w = st(),
|
|
1918
|
+
const w = st(), f = `${e.agentId}-${e.sessionId}`, y = Date.now(), x = (d == null ? void 0 : d.type) || "text", I = {
|
|
1915
1919
|
id: `user-${y}`,
|
|
1916
1920
|
role: "user",
|
|
1917
1921
|
content: [{ type: x, text: c }],
|
|
1918
1922
|
timestamp: y,
|
|
1919
|
-
archived: (
|
|
1923
|
+
archived: (d == null ? void 0 : d.archived) ?? !1,
|
|
1920
1924
|
showIcon: !1
|
|
1921
1925
|
};
|
|
1922
1926
|
n((T) => ({
|
|
@@ -1928,12 +1932,12 @@ function Ee(t) {
|
|
|
1928
1932
|
try {
|
|
1929
1933
|
let T = null, b = !1;
|
|
1930
1934
|
const k = {};
|
|
1931
|
-
(
|
|
1932
|
-
...(
|
|
1933
|
-
...(
|
|
1935
|
+
(d != null && d.archived || d != null && d.type) && (k.metadata = {
|
|
1936
|
+
...(d == null ? void 0 : d.archived) && { archived: !0 },
|
|
1937
|
+
...(d == null ? void 0 : d.type) && { contentType: d.type }
|
|
1934
1938
|
});
|
|
1935
1939
|
for await (const M of w.sendMessageStream(
|
|
1936
|
-
|
|
1940
|
+
f,
|
|
1937
1941
|
c,
|
|
1938
1942
|
k
|
|
1939
1943
|
)) {
|
|
@@ -1978,13 +1982,13 @@ function Ee(t) {
|
|
|
1978
1982
|
b = !0;
|
|
1979
1983
|
const C = T, A = z(
|
|
1980
1984
|
M.status.message,
|
|
1981
|
-
|
|
1985
|
+
u.current
|
|
1982
1986
|
);
|
|
1983
1987
|
A && n((q) => {
|
|
1984
1988
|
const _ = q.uiMessages.map(
|
|
1985
1989
|
(R) => R.id === C ? A : R
|
|
1986
1990
|
), E = w.getConversationHistory(
|
|
1987
|
-
|
|
1991
|
+
f
|
|
1988
1992
|
);
|
|
1989
1993
|
return {
|
|
1990
1994
|
...q,
|
|
@@ -1996,7 +2000,7 @@ function Ee(t) {
|
|
|
1996
2000
|
}
|
|
1997
2001
|
}
|
|
1998
2002
|
if (!b) {
|
|
1999
|
-
const M = w.getConversationHistory(
|
|
2003
|
+
const M = w.getConversationHistory(f);
|
|
2000
2004
|
n((C) => {
|
|
2001
2005
|
let A = C.uiMessages;
|
|
2002
2006
|
T && (A = C.uiMessages.filter(
|
|
@@ -2005,7 +2009,7 @@ function Ee(t) {
|
|
|
2005
2009
|
const q = M.map(
|
|
2006
2010
|
(O) => z(
|
|
2007
2011
|
O,
|
|
2008
|
-
|
|
2012
|
+
u.current
|
|
2009
2013
|
)
|
|
2010
2014
|
).filter(
|
|
2011
2015
|
(O) => O !== null
|
|
@@ -2048,13 +2052,13 @@ function Ee(t) {
|
|
|
2048
2052
|
},
|
|
2049
2053
|
[e.agentId, e.sessionId, s]
|
|
2050
2054
|
), h = $((c) => {
|
|
2051
|
-
n((
|
|
2052
|
-
...
|
|
2053
|
-
uiMessages: at([...
|
|
2055
|
+
n((d) => ({
|
|
2056
|
+
...d,
|
|
2057
|
+
uiMessages: at([...d.uiMessages, c])
|
|
2054
2058
|
}));
|
|
2055
|
-
}, []),
|
|
2056
|
-
n((
|
|
2057
|
-
...
|
|
2059
|
+
}, []), m = $((c) => {
|
|
2060
|
+
n((d) => ({
|
|
2061
|
+
...d,
|
|
2058
2062
|
suggestions: c
|
|
2059
2063
|
}));
|
|
2060
2064
|
}, []), p = $(() => {
|
|
@@ -2067,11 +2071,11 @@ function Ee(t) {
|
|
|
2067
2071
|
n((c) => {
|
|
2068
2072
|
if (c.clientMessages.length === 0)
|
|
2069
2073
|
return c;
|
|
2070
|
-
const
|
|
2071
|
-
(y) => z(y,
|
|
2074
|
+
const d = c.clientMessages.map(
|
|
2075
|
+
(y) => z(y, u.current)
|
|
2072
2076
|
).filter((y) => y !== null), w = new Set(
|
|
2073
2077
|
c.clientMessages.map((y) => y.messageId)
|
|
2074
|
-
),
|
|
2078
|
+
), f = c.uiMessages.filter(
|
|
2075
2079
|
(y) => {
|
|
2076
2080
|
var x;
|
|
2077
2081
|
return !w.has(y.id) && ((x = y.content[0]) == null ? void 0 : x.type) === "component";
|
|
@@ -2080,8 +2084,8 @@ function Ee(t) {
|
|
|
2080
2084
|
return {
|
|
2081
2085
|
...c,
|
|
2082
2086
|
uiMessages: at([
|
|
2083
|
-
...
|
|
2084
|
-
...
|
|
2087
|
+
...d,
|
|
2088
|
+
...f
|
|
2085
2089
|
])
|
|
2086
2090
|
};
|
|
2087
2091
|
});
|
|
@@ -2089,8 +2093,8 @@ function Ee(t) {
|
|
|
2089
2093
|
const S = $(() => {
|
|
2090
2094
|
if (!s)
|
|
2091
2095
|
return;
|
|
2092
|
-
const c = st(),
|
|
2093
|
-
c.abortCurrentRequest(
|
|
2096
|
+
const c = st(), d = `${e.agentId}-${e.sessionId}`;
|
|
2097
|
+
c.abortCurrentRequest(d);
|
|
2094
2098
|
}, [e.agentId, e.sessionId, s]);
|
|
2095
2099
|
return {
|
|
2096
2100
|
// AgentUI props
|
|
@@ -2100,7 +2104,7 @@ function Ee(t) {
|
|
|
2100
2104
|
onSubmit: g,
|
|
2101
2105
|
suggestions: a.suggestions,
|
|
2102
2106
|
// UI management methods
|
|
2103
|
-
registerSuggestions:
|
|
2107
|
+
registerSuggestions: m,
|
|
2104
2108
|
clearSuggestions: p,
|
|
2105
2109
|
// Message actions methods
|
|
2106
2110
|
registerMessageActions: r,
|
|
@@ -2119,7 +2123,7 @@ function we() {
|
|
|
2119
2123
|
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);
|
|
2120
2124
|
}
|
|
2121
2125
|
async function Ie(t, e = !0) {
|
|
2122
|
-
var i,
|
|
2126
|
+
var i, u;
|
|
2123
2127
|
const s = localStorage.getItem(pt);
|
|
2124
2128
|
let a;
|
|
2125
2129
|
if (s)
|
|
@@ -2130,7 +2134,7 @@ async function Ie(t, e = !0) {
|
|
|
2130
2134
|
}
|
|
2131
2135
|
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && e)
|
|
2132
2136
|
return a;
|
|
2133
|
-
const n = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (
|
|
2137
|
+
const n = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (u = window.Jetpack_Editor_Initial_State) == null ? void 0 : u.wpcomBlogId;
|
|
2134
2138
|
let o = {
|
|
2135
2139
|
token: "",
|
|
2136
2140
|
blog_id: ""
|