@automattic/agenttic-client 0.1.64 → 0.1.65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +189 -186
- package/dist/react/useAgentChat.d.ts +1 -0
- package/dist/react/useAgentChat.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
var He = Object.defineProperty;
|
|
2
2
|
var Fe = (e, s, t) => s in e ? He(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
3
|
var te = (e, s, t) => Fe(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
-
import De, { useMemo as
|
|
4
|
+
import De, { useMemo as Se, useCallback as H, useState as ve, useRef as pe, useEffect as se } from "react";
|
|
5
5
|
import { l as A, f as Ae, a as L } from "./logger-aKHbTlwk.js";
|
|
6
6
|
import he from "@wordpress/api-fetch";
|
|
7
7
|
function Dt(e) {
|
|
8
|
-
return
|
|
8
|
+
return Se(() => e ? {
|
|
9
9
|
getClientContext: () => {
|
|
10
10
|
try {
|
|
11
11
|
return e() || {};
|
|
@@ -42,7 +42,7 @@ function ce({
|
|
|
42
42
|
},
|
|
43
43
|
[s]
|
|
44
44
|
);
|
|
45
|
-
return
|
|
45
|
+
return Se(() => {
|
|
46
46
|
if (!e && !t)
|
|
47
47
|
return;
|
|
48
48
|
const o = {};
|
|
@@ -318,7 +318,7 @@ function Qe(e, s = "") {
|
|
|
318
318
|
return { events: t, nextBuffer: c };
|
|
319
319
|
}
|
|
320
320
|
async function* Xe(e, s = {}) {
|
|
321
|
-
var g, u,
|
|
321
|
+
var g, u, m;
|
|
322
322
|
const { supportDeltas: t = !1 } = s, a = e.getReader(), n = new TextDecoder();
|
|
323
323
|
let r = "";
|
|
324
324
|
const o = new Ze();
|
|
@@ -330,9 +330,9 @@ async function* Xe(e, s = {}) {
|
|
|
330
330
|
break;
|
|
331
331
|
const f = n.decode(v, { stream: !0 }), { events: h, nextBuffer: I } = Qe(f, r);
|
|
332
332
|
if (h && Array.isArray(h))
|
|
333
|
-
for (let
|
|
334
|
-
const d = h[
|
|
335
|
-
if (
|
|
333
|
+
for (let S = 0; S < h.length; S++) {
|
|
334
|
+
const d = h[S];
|
|
335
|
+
if (S > 0 && d.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((l) => {
|
|
336
336
|
requestAnimationFrame(() => l(void 0));
|
|
337
337
|
}), d.error)
|
|
338
338
|
throw new Error(
|
|
@@ -374,7 +374,7 @@ async function* Xe(e, s = {}) {
|
|
|
374
374
|
kind: "status"
|
|
375
375
|
};
|
|
376
376
|
} else if (d.id && d.result && (c = d.result.id, d.result.status)) {
|
|
377
|
-
const l = ((
|
|
377
|
+
const l = ((m = d.result.status) == null ? void 0 : m.message) || {
|
|
378
378
|
role: "agent",
|
|
379
379
|
parts: []
|
|
380
380
|
}, w = ye(l);
|
|
@@ -566,7 +566,7 @@ function Pe(e, s, t, a) {
|
|
|
566
566
|
return a !== void 0 && (n.credentials = a), n;
|
|
567
567
|
}
|
|
568
568
|
async function Z(e, s, t, a, n, r) {
|
|
569
|
-
const { message: o, sessionId: c, taskId: i, metadata: g } = e, { agentId: u, agentUrl:
|
|
569
|
+
const { message: o, sessionId: c, taskId: i, metadata: g } = e, { agentId: u, agentUrl: m, authProvider: y, proxy: v } = s, { isStreaming: f = !1, enableTokenStreaming: h = !1 } = t, I = c || r, S = st(m, u), d = await Ge(
|
|
570
570
|
o,
|
|
571
571
|
a,
|
|
572
572
|
n
|
|
@@ -582,24 +582,24 @@ async function Z(e, s, t, a, n, r) {
|
|
|
582
582
|
h && f
|
|
583
583
|
// Only enable token streaming if using SSE
|
|
584
584
|
), T = await nt(y, f);
|
|
585
|
-
return at("POST",
|
|
585
|
+
return at("POST", S, T, w), {
|
|
586
586
|
request: w,
|
|
587
587
|
headers: T,
|
|
588
588
|
enhancedMessage: d,
|
|
589
589
|
effectiveSessionId: I,
|
|
590
|
-
fullAgentUrl:
|
|
590
|
+
fullAgentUrl: S
|
|
591
591
|
};
|
|
592
592
|
}
|
|
593
593
|
async function _e(e, s, t = {}) {
|
|
594
594
|
const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o, credentials: c } = s, { abortSignal: i } = t, { timeoutId: g, controller: u } = ke(
|
|
595
595
|
o,
|
|
596
596
|
"request"
|
|
597
|
-
),
|
|
597
|
+
), m = i ? Re(u.signal, i) : u.signal;
|
|
598
598
|
try {
|
|
599
599
|
const y = Pe(
|
|
600
600
|
n,
|
|
601
601
|
JSON.stringify(a),
|
|
602
|
-
|
|
602
|
+
m,
|
|
603
603
|
c
|
|
604
604
|
);
|
|
605
605
|
A("Making request to %s with options: %O", r, {
|
|
@@ -624,10 +624,10 @@ async function* Ee(e, s, t) {
|
|
|
624
624
|
streamingTimeout: c = 6e4,
|
|
625
625
|
abortSignal: i,
|
|
626
626
|
enableTokenStreaming: g = !1
|
|
627
|
-
} = t, { timeoutId: u, controller:
|
|
627
|
+
} = t, { timeoutId: u, controller: m } = ke(
|
|
628
628
|
c,
|
|
629
629
|
"streaming request"
|
|
630
|
-
), y = i ? Re(
|
|
630
|
+
), y = i ? Re(m.signal, i) : m.signal;
|
|
631
631
|
try {
|
|
632
632
|
const v = JSON.stringify(a), f = Pe(
|
|
633
633
|
n,
|
|
@@ -772,12 +772,12 @@ async function Oe(e, s, t) {
|
|
|
772
772
|
g,
|
|
773
773
|
t,
|
|
774
774
|
c
|
|
775
|
-
), { result:
|
|
775
|
+
), { result: m, returnToAgent: y, agentMessage: v } = de(u);
|
|
776
776
|
y && (r = !0), v && n.push(Q(v)), a.push(
|
|
777
777
|
j(
|
|
778
778
|
c,
|
|
779
779
|
i,
|
|
780
|
-
|
|
780
|
+
m
|
|
781
781
|
)
|
|
782
782
|
);
|
|
783
783
|
} catch (u) {
|
|
@@ -830,7 +830,7 @@ async function we(e, s, t, a, n, r, o, c, i = []) {
|
|
|
830
830
|
taskId: e,
|
|
831
831
|
sessionId: r
|
|
832
832
|
// Use the provided sessionId to maintain conversation continuity
|
|
833
|
-
}, u = c || { isStreaming: !0 },
|
|
833
|
+
}, u = c || { isStreaming: !0 }, m = await Z(
|
|
834
834
|
g,
|
|
835
835
|
t,
|
|
836
836
|
{
|
|
@@ -839,7 +839,7 @@ async function we(e, s, t, a, n, r, o, c, i = []) {
|
|
|
839
839
|
a,
|
|
840
840
|
n,
|
|
841
841
|
r
|
|
842
|
-
), y = Ee(
|
|
842
|
+
), y = Ee(m, t, {
|
|
843
843
|
...u,
|
|
844
844
|
abortSignal: o
|
|
845
845
|
});
|
|
@@ -859,7 +859,7 @@ async function we(e, s, t, a, n, r, o, c, i = []) {
|
|
|
859
859
|
);
|
|
860
860
|
}
|
|
861
861
|
async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
862
|
-
var g, u,
|
|
862
|
+
var g, u, m, y, v, f, h, I, S, d, l, w;
|
|
863
863
|
for await (const T of e) {
|
|
864
864
|
if (T.sessionId && !n && (n = T.sessionId), yield T, T.status.state === "running" && T.status.message && s && await rt(
|
|
865
865
|
s,
|
|
@@ -869,11 +869,11 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
869
869
|
T.status.message
|
|
870
870
|
);
|
|
871
871
|
for (const E of b) {
|
|
872
|
-
const { toolCallId: $, toolId: U, arguments:
|
|
872
|
+
const { toolCallId: $, toolId: U, arguments: p } = E.data;
|
|
873
873
|
ee(
|
|
874
874
|
s,
|
|
875
875
|
U,
|
|
876
|
-
|
|
876
|
+
p,
|
|
877
877
|
(u = (g = T.status) == null ? void 0 : g.message) == null ? void 0 : u.messageId,
|
|
878
878
|
$
|
|
879
879
|
).catch((C) => {
|
|
@@ -902,10 +902,10 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
902
902
|
if (b.length > 0) {
|
|
903
903
|
const E = [];
|
|
904
904
|
let $ = !1;
|
|
905
|
-
const U = [],
|
|
905
|
+
const U = [], p = [];
|
|
906
906
|
for (const C of b) {
|
|
907
907
|
const {
|
|
908
|
-
toolCallId:
|
|
908
|
+
toolCallId: M,
|
|
909
909
|
toolId: R,
|
|
910
910
|
arguments: N
|
|
911
911
|
} = C.data;
|
|
@@ -914,10 +914,10 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
914
914
|
s,
|
|
915
915
|
R,
|
|
916
916
|
N,
|
|
917
|
-
(y = (
|
|
918
|
-
|
|
917
|
+
(y = (m = T.status) == null ? void 0 : m.message) == null ? void 0 : y.messageId,
|
|
918
|
+
M
|
|
919
919
|
), { result: x, returnToAgent: P, agentMessage: D } = de(k);
|
|
920
|
-
if (P && ($ = !0), D &&
|
|
920
|
+
if (P && ($ = !0), D && p.push(
|
|
921
921
|
Q(D)
|
|
922
922
|
), x.result instanceof Promise) {
|
|
923
923
|
const K = x.result, q = {
|
|
@@ -925,14 +925,14 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
925
925
|
resolvedValue: null
|
|
926
926
|
};
|
|
927
927
|
ge.set(
|
|
928
|
-
|
|
928
|
+
M,
|
|
929
929
|
q
|
|
930
930
|
), K.then((_) => {
|
|
931
931
|
q.resolvedValue = _;
|
|
932
932
|
}).catch((_) => {
|
|
933
933
|
A(
|
|
934
934
|
"Promise rejected for tool call %s: %O",
|
|
935
|
-
|
|
935
|
+
M,
|
|
936
936
|
_
|
|
937
937
|
), q.resolvedValue = {
|
|
938
938
|
error: _ instanceof Error ? _.message : String(_)
|
|
@@ -940,14 +940,14 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
940
940
|
});
|
|
941
941
|
}
|
|
942
942
|
const J = j(
|
|
943
|
-
|
|
943
|
+
M,
|
|
944
944
|
R,
|
|
945
945
|
x
|
|
946
946
|
);
|
|
947
947
|
E.push(J), U.push(J);
|
|
948
948
|
} catch (k) {
|
|
949
949
|
const x = j(
|
|
950
|
-
|
|
950
|
+
M,
|
|
951
951
|
R,
|
|
952
952
|
void 0,
|
|
953
953
|
k instanceof Error ? k.message : String(k)
|
|
@@ -961,7 +961,7 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
961
961
|
parts: E,
|
|
962
962
|
messageId: O()
|
|
963
963
|
}), $) {
|
|
964
|
-
const C = Ie(o),
|
|
964
|
+
const C = Ie(o), M = Y(
|
|
965
965
|
[],
|
|
966
966
|
// Empty array - tool results are already in historyDataParts
|
|
967
967
|
C
|
|
@@ -970,14 +970,14 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
970
970
|
id: T.id,
|
|
971
971
|
status: {
|
|
972
972
|
state: "working",
|
|
973
|
-
message:
|
|
973
|
+
message: M
|
|
974
974
|
},
|
|
975
975
|
final: !1,
|
|
976
976
|
text: ""
|
|
977
977
|
};
|
|
978
978
|
const R = await we(
|
|
979
979
|
T.id,
|
|
980
|
-
|
|
980
|
+
M,
|
|
981
981
|
a,
|
|
982
982
|
s,
|
|
983
983
|
t,
|
|
@@ -1016,7 +1016,7 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
1016
1016
|
} = await Oe(
|
|
1017
1017
|
k,
|
|
1018
1018
|
s,
|
|
1019
|
-
(
|
|
1019
|
+
(S = (I = x.status) == null ? void 0 : I.message) == null ? void 0 : S.messageId
|
|
1020
1020
|
);
|
|
1021
1021
|
if (P.length > 0 && (yield {
|
|
1022
1022
|
id: x.id,
|
|
@@ -1086,20 +1086,20 @@ async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
|
1086
1086
|
const C = {
|
|
1087
1087
|
...T.status.message,
|
|
1088
1088
|
parts: U
|
|
1089
|
-
},
|
|
1089
|
+
}, M = {
|
|
1090
1090
|
...T,
|
|
1091
1091
|
status: {
|
|
1092
1092
|
...T.status,
|
|
1093
1093
|
message: C
|
|
1094
1094
|
},
|
|
1095
|
-
final:
|
|
1095
|
+
final: p.length === 0,
|
|
1096
1096
|
// Only final if no agent messages to follow
|
|
1097
1097
|
text: F(C)
|
|
1098
1098
|
};
|
|
1099
|
-
if (yield
|
|
1100
|
-
const R =
|
|
1099
|
+
if (yield M, p.length > 0) {
|
|
1100
|
+
const R = p.map((k) => F(k)).join(" "), N = Q(R);
|
|
1101
1101
|
yield {
|
|
1102
|
-
id:
|
|
1102
|
+
id: M.id,
|
|
1103
1103
|
status: {
|
|
1104
1104
|
state: "completed",
|
|
1105
1105
|
message: N
|
|
@@ -1132,12 +1132,12 @@ function ct(e) {
|
|
|
1132
1132
|
credentials: g
|
|
1133
1133
|
};
|
|
1134
1134
|
return {
|
|
1135
|
-
async sendMessage(
|
|
1135
|
+
async sendMessage(m) {
|
|
1136
1136
|
var l, w;
|
|
1137
|
-
const { abortSignal: y } =
|
|
1138
|
-
f.push(
|
|
1137
|
+
const { abortSignal: y } = m, v = m.sessionId || n || void 0, f = [];
|
|
1138
|
+
f.push(m.message);
|
|
1139
1139
|
const h = await Z(
|
|
1140
|
-
|
|
1140
|
+
m,
|
|
1141
1141
|
u,
|
|
1142
1142
|
{ isStreaming: !1 },
|
|
1143
1143
|
o,
|
|
@@ -1149,45 +1149,45 @@ function ct(e) {
|
|
|
1149
1149
|
u,
|
|
1150
1150
|
{ abortSignal: y }
|
|
1151
1151
|
);
|
|
1152
|
-
const
|
|
1152
|
+
const S = [], d = [];
|
|
1153
1153
|
for (; I.status.message && o; ) {
|
|
1154
1154
|
const T = B(
|
|
1155
1155
|
I.status.message
|
|
1156
1156
|
);
|
|
1157
1157
|
if (T.length === 0)
|
|
1158
1158
|
break;
|
|
1159
|
-
|
|
1159
|
+
S.push(...T);
|
|
1160
1160
|
const b = [];
|
|
1161
1161
|
let E = !1;
|
|
1162
1162
|
for (const $ of T) {
|
|
1163
1163
|
const {
|
|
1164
1164
|
toolCallId: U,
|
|
1165
|
-
toolId:
|
|
1165
|
+
toolId: p,
|
|
1166
1166
|
arguments: C
|
|
1167
1167
|
} = $.data;
|
|
1168
1168
|
try {
|
|
1169
|
-
const
|
|
1169
|
+
const M = await ee(
|
|
1170
1170
|
o,
|
|
1171
|
-
|
|
1171
|
+
p,
|
|
1172
1172
|
C
|
|
1173
|
-
), { result: R, returnToAgent: N, agentMessage: k } = de(
|
|
1173
|
+
), { result: R, returnToAgent: N, agentMessage: k } = de(M);
|
|
1174
1174
|
N && (E = !0), k && d.push(
|
|
1175
1175
|
Q(k)
|
|
1176
1176
|
);
|
|
1177
1177
|
const x = j(
|
|
1178
1178
|
U,
|
|
1179
|
-
|
|
1179
|
+
p,
|
|
1180
1180
|
R
|
|
1181
1181
|
);
|
|
1182
|
-
b.push(x),
|
|
1183
|
-
} catch (
|
|
1182
|
+
b.push(x), S.push(x);
|
|
1183
|
+
} catch (M) {
|
|
1184
1184
|
const R = j(
|
|
1185
1185
|
U,
|
|
1186
|
-
|
|
1186
|
+
p,
|
|
1187
1187
|
void 0,
|
|
1188
|
-
|
|
1188
|
+
M instanceof Error ? M.message : String(M)
|
|
1189
1189
|
);
|
|
1190
|
-
b.push(R),
|
|
1190
|
+
b.push(R), S.push(R);
|
|
1191
1191
|
}
|
|
1192
1192
|
}
|
|
1193
1193
|
if (f.push(I.status.message), E) {
|
|
@@ -1204,10 +1204,10 @@ function ct(e) {
|
|
|
1204
1204
|
} else
|
|
1205
1205
|
break;
|
|
1206
1206
|
}
|
|
1207
|
-
if (
|
|
1207
|
+
if (S.length > 0 && (l = I.status) != null && l.message) {
|
|
1208
1208
|
const T = {
|
|
1209
1209
|
...I.status.message,
|
|
1210
|
-
parts:
|
|
1210
|
+
parts: S
|
|
1211
1211
|
};
|
|
1212
1212
|
I = {
|
|
1213
1213
|
...I,
|
|
@@ -1238,15 +1238,15 @@ function ct(e) {
|
|
|
1238
1238
|
)
|
|
1239
1239
|
};
|
|
1240
1240
|
},
|
|
1241
|
-
async *sendMessageStream(
|
|
1241
|
+
async *sendMessageStream(m) {
|
|
1242
1242
|
const {
|
|
1243
1243
|
withHistory: y = !0,
|
|
1244
1244
|
abortSignal: v,
|
|
1245
1245
|
enableStreaming: f
|
|
1246
|
-
} =
|
|
1247
|
-
|
|
1246
|
+
} = m, h = m.sessionId || n || void 0, I = f ?? i, S = [];
|
|
1247
|
+
S.push(m.message);
|
|
1248
1248
|
const d = await Z(
|
|
1249
|
-
|
|
1249
|
+
m,
|
|
1250
1250
|
u,
|
|
1251
1251
|
{
|
|
1252
1252
|
isStreaming: !0,
|
|
@@ -1273,7 +1273,7 @@ function ct(e) {
|
|
|
1273
1273
|
u,
|
|
1274
1274
|
h,
|
|
1275
1275
|
y,
|
|
1276
|
-
|
|
1276
|
+
S,
|
|
1277
1277
|
v,
|
|
1278
1278
|
{
|
|
1279
1279
|
isStreaming: !0,
|
|
@@ -1282,11 +1282,11 @@ function ct(e) {
|
|
|
1282
1282
|
}
|
|
1283
1283
|
);
|
|
1284
1284
|
},
|
|
1285
|
-
async continueTask(
|
|
1286
|
-
var
|
|
1285
|
+
async continueTask(m, y, v) {
|
|
1286
|
+
var S;
|
|
1287
1287
|
const f = ie(y);
|
|
1288
1288
|
let I = await ae(
|
|
1289
|
-
|
|
1289
|
+
m,
|
|
1290
1290
|
f,
|
|
1291
1291
|
u,
|
|
1292
1292
|
o,
|
|
@@ -1316,7 +1316,7 @@ function ct(e) {
|
|
|
1316
1316
|
return {
|
|
1317
1317
|
...I,
|
|
1318
1318
|
text: F(
|
|
1319
|
-
((
|
|
1319
|
+
((S = I.status) == null ? void 0 : S.message) || {
|
|
1320
1320
|
parts: [],
|
|
1321
1321
|
messageId: O()
|
|
1322
1322
|
}
|
|
@@ -1392,7 +1392,7 @@ function dt(e) {
|
|
|
1392
1392
|
}
|
|
1393
1393
|
function gt(e, s = !1) {
|
|
1394
1394
|
var r, o, c, i, g, u;
|
|
1395
|
-
const a = e.messages.filter((
|
|
1395
|
+
const a = e.messages.filter((m) => m.role === "tool_call" ? !1 : m.role === "tool_result" ? !(!s || dt(m)) : !0).map(ut), n = {
|
|
1396
1396
|
currentPage: ((r = e.metadata) == null ? void 0 : r.current_page) ?? 1,
|
|
1397
1397
|
itemsPerPage: ((o = e.metadata) == null ? void 0 : o.items_per_page) ?? 10,
|
|
1398
1398
|
totalPages: ((c = e.metadata) == null ? void 0 : c.total_pages) ?? 1,
|
|
@@ -1429,16 +1429,16 @@ async function le(e, s, t = 1, a = 50, n = !1) {
|
|
|
1429
1429
|
i
|
|
1430
1430
|
);
|
|
1431
1431
|
try {
|
|
1432
|
-
const
|
|
1432
|
+
const m = {
|
|
1433
1433
|
"Content-Type": "application/json"
|
|
1434
1434
|
};
|
|
1435
1435
|
if (c) {
|
|
1436
1436
|
const h = await c();
|
|
1437
|
-
Object.assign(
|
|
1437
|
+
Object.assign(m, h);
|
|
1438
1438
|
}
|
|
1439
1439
|
const y = await fetch(u.toString(), {
|
|
1440
1440
|
method: "GET",
|
|
1441
|
-
headers:
|
|
1441
|
+
headers: m
|
|
1442
1442
|
});
|
|
1443
1443
|
if (!y.ok) {
|
|
1444
1444
|
const h = await y.text();
|
|
@@ -1448,12 +1448,12 @@ async function le(e, s, t = 1, a = 50, n = !1) {
|
|
|
1448
1448
|
d.message && (I = d.message);
|
|
1449
1449
|
} catch {
|
|
1450
1450
|
}
|
|
1451
|
-
const
|
|
1451
|
+
const S = new z(
|
|
1452
1452
|
I,
|
|
1453
1453
|
y.status,
|
|
1454
1454
|
h
|
|
1455
1455
|
);
|
|
1456
|
-
throw A("Failed to load conversation from server: %O",
|
|
1456
|
+
throw A("Failed to load conversation from server: %O", S), S;
|
|
1457
1457
|
}
|
|
1458
1458
|
const v = await y.json(), f = gt(v, n);
|
|
1459
1459
|
return A(
|
|
@@ -1462,15 +1462,15 @@ async function le(e, s, t = 1, a = 50, n = !1) {
|
|
|
1462
1462
|
f.pagination.currentPage,
|
|
1463
1463
|
f.pagination.totalPages
|
|
1464
1464
|
), f;
|
|
1465
|
-
} catch (
|
|
1466
|
-
if (
|
|
1467
|
-
throw
|
|
1465
|
+
} catch (m) {
|
|
1466
|
+
if (m instanceof z)
|
|
1467
|
+
throw m;
|
|
1468
1468
|
const y = new z(
|
|
1469
|
-
`Network error loading conversation: ${
|
|
1469
|
+
`Network error loading conversation: ${m.message}`,
|
|
1470
1470
|
void 0,
|
|
1471
|
-
|
|
1471
|
+
m
|
|
1472
1472
|
);
|
|
1473
|
-
throw A("Network error loading conversation: %O",
|
|
1473
|
+
throw A("Network error loading conversation: %O", m), y;
|
|
1474
1474
|
}
|
|
1475
1475
|
}
|
|
1476
1476
|
async function Bt(e, s, t = !1) {
|
|
@@ -1496,12 +1496,12 @@ async function Bt(e, s, t = !1) {
|
|
|
1496
1496
|
headers: o
|
|
1497
1497
|
});
|
|
1498
1498
|
if (!c.ok) {
|
|
1499
|
-
const g = await c.text(), u = `Failed to list conversations: ${c.status} ${c.statusText}`,
|
|
1499
|
+
const g = await c.text(), u = `Failed to list conversations: ${c.status} ${c.statusText}`, m = new z(
|
|
1500
1500
|
u,
|
|
1501
1501
|
c.status,
|
|
1502
1502
|
g
|
|
1503
1503
|
);
|
|
1504
|
-
throw A("Failed to list conversations: %O",
|
|
1504
|
+
throw A("Failed to list conversations: %O", m), m;
|
|
1505
1505
|
}
|
|
1506
1506
|
const i = await c.json();
|
|
1507
1507
|
return A("Loaded %d conversations from server", i.length), i;
|
|
@@ -1596,12 +1596,12 @@ function ft(e) {
|
|
|
1596
1596
|
break;
|
|
1597
1597
|
}
|
|
1598
1598
|
}
|
|
1599
|
-
const g = n.length > 0 || r.length > 0 ? "agent" : e.role, u = ((y = e.metadata) == null ? void 0 : y.timestamp) ?? Date.now(),
|
|
1599
|
+
const g = n.length > 0 || r.length > 0 ? "agent" : e.role, u = ((y = e.metadata) == null ? void 0 : y.timestamp) ?? Date.now(), m = ((v = e.metadata) == null ? void 0 : v.archived) ?? void 0;
|
|
1600
1600
|
return {
|
|
1601
1601
|
role: g,
|
|
1602
1602
|
content: t || "(No text content)",
|
|
1603
1603
|
timestamp: u,
|
|
1604
|
-
...
|
|
1604
|
+
...m !== void 0 && { archived: m },
|
|
1605
1605
|
...a && { contentType: a },
|
|
1606
1606
|
...o.length > 0 && { files: o },
|
|
1607
1607
|
...n.length > 0 && { toolCalls: n },
|
|
@@ -1836,7 +1836,7 @@ function Te(e, s = [], t = []) {
|
|
|
1836
1836
|
}
|
|
1837
1837
|
};
|
|
1838
1838
|
}
|
|
1839
|
-
function
|
|
1839
|
+
function Mt(e) {
|
|
1840
1840
|
return e != null && e.parts ? e.parts.filter(
|
|
1841
1841
|
(s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
|
|
1842
1842
|
) : [];
|
|
@@ -1875,7 +1875,7 @@ function ne(e, s) {
|
|
|
1875
1875
|
);
|
|
1876
1876
|
}
|
|
1877
1877
|
}
|
|
1878
|
-
async function
|
|
1878
|
+
async function St(e) {
|
|
1879
1879
|
const s = [];
|
|
1880
1880
|
for (const t of e)
|
|
1881
1881
|
if (t.parts && Array.isArray(t.parts))
|
|
@@ -1929,10 +1929,10 @@ function vt() {
|
|
|
1929
1929
|
o,
|
|
1930
1930
|
i
|
|
1931
1931
|
)).messages;
|
|
1932
|
-
} catch (
|
|
1932
|
+
} catch (m) {
|
|
1933
1933
|
L(
|
|
1934
1934
|
`Failed to load conversation history for agent ${t} with session ${r}:`,
|
|
1935
|
-
|
|
1935
|
+
m
|
|
1936
1936
|
);
|
|
1937
1937
|
}
|
|
1938
1938
|
const u = {
|
|
@@ -1961,21 +1961,21 @@ function vt() {
|
|
|
1961
1961
|
const r = e.get(t);
|
|
1962
1962
|
if (!r)
|
|
1963
1963
|
throw new Error(`Agent with key "${t}" not found`);
|
|
1964
|
-
const { withHistory: o = !0, sessionId: c, ...i } = n, { client: g, conversationHistory: u } = r,
|
|
1964
|
+
const { withHistory: o = !0, sessionId: c, ...i } = n, { client: g, conversationHistory: u } = r, m = n.message || Te(
|
|
1965
1965
|
a,
|
|
1966
1966
|
u,
|
|
1967
1967
|
n.imageUrls
|
|
1968
1968
|
), y = await g.sendMessage({
|
|
1969
|
-
message:
|
|
1969
|
+
message: m,
|
|
1970
1970
|
withHistory: o,
|
|
1971
1971
|
sessionId: c || r.sessionId || void 0,
|
|
1972
1972
|
...i
|
|
1973
1973
|
});
|
|
1974
1974
|
if (y.sessionId) {
|
|
1975
|
-
const
|
|
1976
|
-
r.sessionId = y.sessionId,
|
|
1975
|
+
const S = r.sessionId;
|
|
1976
|
+
r.sessionId = y.sessionId, S && y.sessionId && S !== y.sessionId && r.sessionIdStorageKey && (L(
|
|
1977
1977
|
"Session ID changed from %s to %s, updating localStorage",
|
|
1978
|
-
|
|
1978
|
+
S,
|
|
1979
1979
|
y.sessionId
|
|
1980
1980
|
), ne(
|
|
1981
1981
|
r.sessionIdStorageKey,
|
|
@@ -1984,7 +1984,7 @@ function vt() {
|
|
|
1984
1984
|
}
|
|
1985
1985
|
let v = null;
|
|
1986
1986
|
if ((I = y.status) != null && I.message) {
|
|
1987
|
-
const
|
|
1987
|
+
const S = y.status.message.parts.filter(
|
|
1988
1988
|
(l) => l.type === "data" && "toolCallId" in l.data && ("arguments" in l.data || "result" in l.data)
|
|
1989
1989
|
), d = y.status.message.parts.filter(
|
|
1990
1990
|
(l) => l.type === "text"
|
|
@@ -1992,7 +1992,7 @@ function vt() {
|
|
|
1992
1992
|
v = {
|
|
1993
1993
|
role: "agent",
|
|
1994
1994
|
kind: "message",
|
|
1995
|
-
parts: [...
|
|
1995
|
+
parts: [...S, ...d],
|
|
1996
1996
|
messageId: O(),
|
|
1997
1997
|
metadata: {
|
|
1998
1998
|
timestamp: Date.now()
|
|
@@ -2008,12 +2008,12 @@ function vt() {
|
|
|
2008
2008
|
];
|
|
2009
2009
|
let h = f;
|
|
2010
2010
|
if (y.agentMessage) {
|
|
2011
|
-
const
|
|
2011
|
+
const S = G(
|
|
2012
2012
|
y.agentMessage
|
|
2013
2013
|
);
|
|
2014
2014
|
h = [
|
|
2015
2015
|
...f,
|
|
2016
|
-
|
|
2016
|
+
S
|
|
2017
2017
|
];
|
|
2018
2018
|
}
|
|
2019
2019
|
return r.conversationHistory = h, o && await s(
|
|
@@ -2032,8 +2032,8 @@ function vt() {
|
|
|
2032
2032
|
metadata: i,
|
|
2033
2033
|
sessionId: g,
|
|
2034
2034
|
message: u,
|
|
2035
|
-
...
|
|
2036
|
-
} = n, { client: y } = r, v = i ? (({ contentType:
|
|
2035
|
+
...m
|
|
2036
|
+
} = n, { client: y } = r, v = i ? (({ contentType: p, ...C }) => C)(i) : void 0, f = new AbortController();
|
|
2037
2037
|
r.currentAbortController = f, c && c.addEventListener(
|
|
2038
2038
|
"abort",
|
|
2039
2039
|
() => f.abort()
|
|
@@ -2041,35 +2041,35 @@ function vt() {
|
|
|
2041
2041
|
let h = [
|
|
2042
2042
|
...r.conversationHistory
|
|
2043
2043
|
], I = [];
|
|
2044
|
-
const
|
|
2044
|
+
const S = await St(
|
|
2045
2045
|
h
|
|
2046
2046
|
);
|
|
2047
|
-
r.conversationHistory =
|
|
2047
|
+
r.conversationHistory = S, h = S, o && await s(
|
|
2048
2048
|
t,
|
|
2049
|
-
|
|
2049
|
+
S
|
|
2050
2050
|
);
|
|
2051
2051
|
let d;
|
|
2052
2052
|
if (u) {
|
|
2053
|
-
const
|
|
2054
|
-
|
|
2053
|
+
const p = $e(
|
|
2054
|
+
S
|
|
2055
2055
|
);
|
|
2056
2056
|
d = {
|
|
2057
2057
|
...u,
|
|
2058
|
-
parts: [...
|
|
2058
|
+
parts: [...p, ...u.parts]
|
|
2059
2059
|
};
|
|
2060
2060
|
} else
|
|
2061
2061
|
d = Te(
|
|
2062
2062
|
a,
|
|
2063
|
-
|
|
2063
|
+
S,
|
|
2064
2064
|
n.imageUrls
|
|
2065
2065
|
);
|
|
2066
2066
|
if (n.metadata && !u) {
|
|
2067
|
-
const { contentType:
|
|
2068
|
-
if (
|
|
2069
|
-
const
|
|
2070
|
-
|
|
2071
|
-
...
|
|
2072
|
-
contentType:
|
|
2067
|
+
const { contentType: p, ...C } = n.metadata;
|
|
2068
|
+
if (p) {
|
|
2069
|
+
const M = d.parts[d.parts.length - 1];
|
|
2070
|
+
M && M.type === "text" && (M.metadata = {
|
|
2071
|
+
...M.metadata,
|
|
2072
|
+
contentType: p
|
|
2073
2073
|
});
|
|
2074
2074
|
}
|
|
2075
2075
|
Object.keys(C).length > 0 && (d.metadata = {
|
|
@@ -2079,21 +2079,21 @@ function vt() {
|
|
|
2079
2079
|
}
|
|
2080
2080
|
const l = u || ie(a, n.metadata);
|
|
2081
2081
|
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
2082
|
-
const
|
|
2082
|
+
const p = n.imageUrls.map(
|
|
2083
2083
|
(C) => {
|
|
2084
|
-
const
|
|
2084
|
+
const M = typeof C == "string" ? C : C.url, R = typeof C == "string" ? void 0 : C.metadata, N = (R == null ? void 0 : R.fileType) || "image/jpeg";
|
|
2085
2085
|
return {
|
|
2086
2086
|
type: "file",
|
|
2087
2087
|
file: {
|
|
2088
2088
|
name: (R == null ? void 0 : R.fileName) || "image",
|
|
2089
2089
|
mimeType: N,
|
|
2090
|
-
uri:
|
|
2090
|
+
uri: M
|
|
2091
2091
|
},
|
|
2092
2092
|
metadata: R
|
|
2093
2093
|
};
|
|
2094
2094
|
}
|
|
2095
2095
|
);
|
|
2096
|
-
l.parts.push(...
|
|
2096
|
+
l.parts.push(...p);
|
|
2097
2097
|
}
|
|
2098
2098
|
h = [
|
|
2099
2099
|
...h,
|
|
@@ -2102,56 +2102,56 @@ function vt() {
|
|
|
2102
2102
|
t,
|
|
2103
2103
|
h
|
|
2104
2104
|
);
|
|
2105
|
-
for await (const
|
|
2105
|
+
for await (const p of y.sendMessageStream({
|
|
2106
2106
|
message: d,
|
|
2107
2107
|
withHistory: o,
|
|
2108
2108
|
sessionId: g || r.sessionId || void 0,
|
|
2109
2109
|
abortSignal: f.signal,
|
|
2110
|
-
...
|
|
2110
|
+
...m,
|
|
2111
2111
|
...v && Object.keys(v).length > 0 && {
|
|
2112
2112
|
metadata: v
|
|
2113
2113
|
}
|
|
2114
2114
|
})) {
|
|
2115
|
-
if (
|
|
2115
|
+
if (p.sessionId) {
|
|
2116
2116
|
const C = r.sessionId;
|
|
2117
|
-
r.sessionId =
|
|
2117
|
+
r.sessionId = p.sessionId, p.sessionId && C !== p.sessionId && r.sessionIdStorageKey && (L(
|
|
2118
2118
|
"Session ID %s, updating localStorage",
|
|
2119
|
-
C ? `changed from ${C} to ${
|
|
2119
|
+
C ? `changed from ${C} to ${p.sessionId}` : `received: ${p.sessionId}`
|
|
2120
2120
|
), ne(
|
|
2121
2121
|
r.sessionIdStorageKey,
|
|
2122
|
-
|
|
2122
|
+
p.sessionId
|
|
2123
2123
|
));
|
|
2124
2124
|
}
|
|
2125
|
-
if (((w =
|
|
2125
|
+
if (((w = p.status) == null ? void 0 : w.state) === "input-required" && ((T = p.status) != null && T.message)) {
|
|
2126
2126
|
I = B(
|
|
2127
|
-
|
|
2127
|
+
p.status.message
|
|
2128
2128
|
).map(
|
|
2129
2129
|
(R) => R.data.toolCallId
|
|
2130
2130
|
);
|
|
2131
|
-
const
|
|
2132
|
-
|
|
2131
|
+
const M = G(
|
|
2132
|
+
p.status.message
|
|
2133
2133
|
);
|
|
2134
2134
|
h = [
|
|
2135
2135
|
...h,
|
|
2136
|
-
|
|
2136
|
+
M
|
|
2137
2137
|
], r.conversationHistory = h, o && await s(
|
|
2138
2138
|
t,
|
|
2139
2139
|
h
|
|
2140
2140
|
);
|
|
2141
2141
|
}
|
|
2142
|
-
if (((b =
|
|
2143
|
-
const
|
|
2144
|
-
|
|
2142
|
+
if (((b = p.status) == null ? void 0 : b.state) === "working" && ((E = p.status) != null && E.message) && !p.final) {
|
|
2143
|
+
const M = Mt(
|
|
2144
|
+
p.status.message
|
|
2145
2145
|
).filter(
|
|
2146
2146
|
(R) => I.includes(
|
|
2147
2147
|
R.data.toolCallId
|
|
2148
2148
|
)
|
|
2149
2149
|
);
|
|
2150
|
-
if (
|
|
2150
|
+
if (M.length > 0) {
|
|
2151
2151
|
const R = {
|
|
2152
2152
|
role: "agent",
|
|
2153
2153
|
kind: "message",
|
|
2154
|
-
parts:
|
|
2154
|
+
parts: M,
|
|
2155
2155
|
messageId: O()
|
|
2156
2156
|
};
|
|
2157
2157
|
h = [
|
|
@@ -2163,11 +2163,11 @@ function vt() {
|
|
|
2163
2163
|
);
|
|
2164
2164
|
}
|
|
2165
2165
|
}
|
|
2166
|
-
if (
|
|
2166
|
+
if (p.final && (($ = p.status) == null ? void 0 : $.state) !== "input-required") {
|
|
2167
2167
|
I = [];
|
|
2168
2168
|
let C = null;
|
|
2169
|
-
(U =
|
|
2170
|
-
|
|
2169
|
+
(U = p.status) != null && U.message && (C = G(
|
|
2170
|
+
p.status.message
|
|
2171
2171
|
), h = [
|
|
2172
2172
|
...h,
|
|
2173
2173
|
C
|
|
@@ -2176,7 +2176,7 @@ function vt() {
|
|
|
2176
2176
|
h
|
|
2177
2177
|
));
|
|
2178
2178
|
}
|
|
2179
|
-
yield
|
|
2179
|
+
yield p;
|
|
2180
2180
|
}
|
|
2181
2181
|
r.currentAbortController = null;
|
|
2182
2182
|
},
|
|
@@ -2357,16 +2357,18 @@ const oe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ue = (e, s =
|
|
|
2357
2357
|
} : Array.isArray(u.sources) && u.sources.length > 0 ? {
|
|
2358
2358
|
type: "data",
|
|
2359
2359
|
data: u
|
|
2360
|
-
} :
|
|
2361
|
-
type: "text",
|
|
2362
|
-
text: JSON.stringify(u)
|
|
2363
|
-
};
|
|
2360
|
+
} : (A("Dropping unrecognized data part", u), null);
|
|
2364
2361
|
}
|
|
2365
2362
|
return {
|
|
2366
2363
|
type: "text",
|
|
2367
2364
|
text: "[Unsupported content]"
|
|
2368
2365
|
};
|
|
2369
|
-
})
|
|
2366
|
+
}).filter(
|
|
2367
|
+
(i) => i !== null
|
|
2368
|
+
);
|
|
2369
|
+
if (a.length === 0)
|
|
2370
|
+
return null;
|
|
2371
|
+
const n = ((o = e.metadata) == null ? void 0 : o.timestamp) ?? Date.now(), r = {
|
|
2370
2372
|
id: e.messageId,
|
|
2371
2373
|
role: e.role === "agent" ? "agent" : "user",
|
|
2372
2374
|
content: a,
|
|
@@ -2418,7 +2420,7 @@ function Vt(e) {
|
|
|
2418
2420
|
se(() => {
|
|
2419
2421
|
u.current = i;
|
|
2420
2422
|
}, [i]);
|
|
2421
|
-
const
|
|
2423
|
+
const m = H(
|
|
2422
2424
|
(d) => d.map(
|
|
2423
2425
|
(l) => re(l, u.current)
|
|
2424
2426
|
).filter((l) => l !== null),
|
|
@@ -2455,7 +2457,7 @@ function Vt(e) {
|
|
|
2455
2457
|
}), s.sessionId) {
|
|
2456
2458
|
const b = l.getConversationHistory(w);
|
|
2457
2459
|
n((E) => {
|
|
2458
|
-
const $ =
|
|
2460
|
+
const $ = m(b);
|
|
2459
2461
|
return {
|
|
2460
2462
|
...E,
|
|
2461
2463
|
clientMessages: b,
|
|
@@ -2480,7 +2482,8 @@ function Vt(e) {
|
|
|
2480
2482
|
e.enableStreaming,
|
|
2481
2483
|
e.odieBotId,
|
|
2482
2484
|
e.credentials,
|
|
2483
|
-
t
|
|
2485
|
+
t,
|
|
2486
|
+
m
|
|
2484
2487
|
]);
|
|
2485
2488
|
const y = H(
|
|
2486
2489
|
async (d, l) => {
|
|
@@ -2497,20 +2500,20 @@ function Vt(e) {
|
|
|
2497
2500
|
);
|
|
2498
2501
|
const T = X(), b = s.agentId, E = Date.now();
|
|
2499
2502
|
if (w)
|
|
2500
|
-
n((
|
|
2501
|
-
...
|
|
2503
|
+
n((p) => ({
|
|
2504
|
+
...p,
|
|
2502
2505
|
isProcessing: !0,
|
|
2503
2506
|
error: null
|
|
2504
2507
|
}));
|
|
2505
2508
|
else {
|
|
2506
|
-
const
|
|
2509
|
+
const p = (l == null ? void 0 : l.type) || "text", C = {
|
|
2507
2510
|
id: `user-${E}`,
|
|
2508
2511
|
role: "user",
|
|
2509
2512
|
content: [
|
|
2510
|
-
{ type:
|
|
2513
|
+
{ type: p, text: d },
|
|
2511
2514
|
// Map image URLs to component content parts
|
|
2512
|
-
...(($ = l == null ? void 0 : l.imageUrls) == null ? void 0 : $.map((
|
|
2513
|
-
const R = typeof
|
|
2515
|
+
...(($ = l == null ? void 0 : l.imageUrls) == null ? void 0 : $.map((M) => {
|
|
2516
|
+
const R = typeof M == "string" ? M : M.url;
|
|
2514
2517
|
return Ue(R);
|
|
2515
2518
|
})) ?? []
|
|
2516
2519
|
],
|
|
@@ -2518,30 +2521,30 @@ function Vt(e) {
|
|
|
2518
2521
|
archived: (l == null ? void 0 : l.archived) ?? !1,
|
|
2519
2522
|
showIcon: !1
|
|
2520
2523
|
};
|
|
2521
|
-
n((
|
|
2522
|
-
...
|
|
2523
|
-
uiMessages: [...
|
|
2524
|
+
n((M) => ({
|
|
2525
|
+
...M,
|
|
2526
|
+
uiMessages: [...M.uiMessages, C],
|
|
2524
2527
|
isProcessing: !0,
|
|
2525
2528
|
error: null
|
|
2526
2529
|
}));
|
|
2527
2530
|
}
|
|
2528
2531
|
try {
|
|
2529
|
-
let
|
|
2530
|
-
const
|
|
2531
|
-
(l != null && l.archived || R) && (
|
|
2532
|
+
let p = null, C = !1;
|
|
2533
|
+
const M = {}, R = !!(l != null && l.type) && !w;
|
|
2534
|
+
(l != null && l.archived || R) && (M.metadata = {
|
|
2532
2535
|
...(l == null ? void 0 : l.archived) && { archived: !0 },
|
|
2533
2536
|
...R && { contentType: l.type }
|
|
2534
|
-
}), l != null && l.sessionId && (
|
|
2537
|
+
}), l != null && l.sessionId && (M.sessionId = l.sessionId), l != null && l.imageUrls && (M.imageUrls = l.imageUrls);
|
|
2535
2538
|
const N = w ? T.sendToolResult(
|
|
2536
2539
|
b,
|
|
2537
2540
|
l.toolCallId,
|
|
2538
2541
|
l.toolId,
|
|
2539
2542
|
{ success: !0, message: d },
|
|
2540
|
-
|
|
2543
|
+
M
|
|
2541
2544
|
) : T.sendMessageStream(
|
|
2542
2545
|
b,
|
|
2543
2546
|
d,
|
|
2544
|
-
|
|
2547
|
+
M
|
|
2545
2548
|
);
|
|
2546
2549
|
for await (const k of N) {
|
|
2547
2550
|
if ((k.progressMessage || k.progressPhase) && n((x) => ({
|
|
@@ -2549,11 +2552,11 @@ function Vt(e) {
|
|
|
2549
2552
|
progressMessage: k.progressMessage || null,
|
|
2550
2553
|
progressPhase: k.progressPhase || null
|
|
2551
2554
|
})), !k.final && k.text) {
|
|
2552
|
-
if (
|
|
2555
|
+
if (p)
|
|
2553
2556
|
n((x) => ({
|
|
2554
2557
|
...x,
|
|
2555
2558
|
uiMessages: x.uiMessages.map(
|
|
2556
|
-
(P) => P.id ===
|
|
2559
|
+
(P) => P.id === p ? {
|
|
2557
2560
|
...P,
|
|
2558
2561
|
content: [
|
|
2559
2562
|
{
|
|
@@ -2565,9 +2568,9 @@ function Vt(e) {
|
|
|
2565
2568
|
)
|
|
2566
2569
|
}));
|
|
2567
2570
|
else {
|
|
2568
|
-
|
|
2571
|
+
p = `agent-streaming-${Date.now()}`;
|
|
2569
2572
|
const x = {
|
|
2570
|
-
id:
|
|
2573
|
+
id: p,
|
|
2571
2574
|
role: "agent",
|
|
2572
2575
|
content: [
|
|
2573
2576
|
{ type: "text", text: k.text }
|
|
@@ -2576,7 +2579,7 @@ function Vt(e) {
|
|
|
2576
2579
|
archived: !1,
|
|
2577
2580
|
showIcon: !0,
|
|
2578
2581
|
icon: "assistant",
|
|
2579
|
-
reactKey:
|
|
2582
|
+
reactKey: p
|
|
2580
2583
|
// Stable key for React rendering
|
|
2581
2584
|
};
|
|
2582
2585
|
n((P) => ({
|
|
@@ -2587,11 +2590,11 @@ function Vt(e) {
|
|
|
2587
2590
|
]
|
|
2588
2591
|
}));
|
|
2589
2592
|
}
|
|
2590
|
-
k.kind === "status" && (
|
|
2593
|
+
k.kind === "status" && (p = null);
|
|
2591
2594
|
}
|
|
2592
|
-
if (k.final && ((U = k.status) != null && U.message) &&
|
|
2595
|
+
if (k.final && ((U = k.status) != null && U.message) && p) {
|
|
2593
2596
|
C = !0;
|
|
2594
|
-
const x =
|
|
2597
|
+
const x = p, P = re(
|
|
2595
2598
|
k.status.message,
|
|
2596
2599
|
u.current
|
|
2597
2600
|
);
|
|
@@ -2621,15 +2624,15 @@ function Vt(e) {
|
|
|
2621
2624
|
progressMessage: null,
|
|
2622
2625
|
progressPhase: null
|
|
2623
2626
|
};
|
|
2624
|
-
}),
|
|
2627
|
+
}), p = null;
|
|
2625
2628
|
}
|
|
2626
2629
|
}
|
|
2627
2630
|
if (!C) {
|
|
2628
2631
|
const k = T.getConversationHistory(b);
|
|
2629
2632
|
n((x) => {
|
|
2630
2633
|
let P = x.uiMessages;
|
|
2631
|
-
|
|
2632
|
-
(_) => _.id !==
|
|
2634
|
+
p && (P = x.uiMessages.filter(
|
|
2635
|
+
(_) => _.id !== p
|
|
2633
2636
|
));
|
|
2634
2637
|
const D = k.map(
|
|
2635
2638
|
(_) => re(
|
|
@@ -2656,10 +2659,10 @@ function Vt(e) {
|
|
|
2656
2659
|
};
|
|
2657
2660
|
});
|
|
2658
2661
|
}
|
|
2659
|
-
} catch (
|
|
2660
|
-
if (
|
|
2661
|
-
A("Request was aborted by user"), n((
|
|
2662
|
-
...
|
|
2662
|
+
} catch (p) {
|
|
2663
|
+
if (p instanceof Error && p.name === "AbortError") {
|
|
2664
|
+
A("Request was aborted by user"), n((M) => ({
|
|
2665
|
+
...M,
|
|
2663
2666
|
isProcessing: !1,
|
|
2664
2667
|
progressMessage: null,
|
|
2665
2668
|
progressPhase: null,
|
|
@@ -2668,14 +2671,14 @@ function Vt(e) {
|
|
|
2668
2671
|
}));
|
|
2669
2672
|
return;
|
|
2670
2673
|
}
|
|
2671
|
-
const C =
|
|
2672
|
-
throw n((
|
|
2673
|
-
...
|
|
2674
|
+
const C = p instanceof Error ? p.message : "Failed to send message";
|
|
2675
|
+
throw n((M) => ({
|
|
2676
|
+
...M,
|
|
2674
2677
|
isProcessing: !1,
|
|
2675
2678
|
progressMessage: null,
|
|
2676
2679
|
progressPhase: null,
|
|
2677
2680
|
error: C
|
|
2678
|
-
})),
|
|
2681
|
+
})), p;
|
|
2679
2682
|
} finally {
|
|
2680
2683
|
g.current = !1;
|
|
2681
2684
|
}
|
|
@@ -2701,7 +2704,7 @@ function Vt(e) {
|
|
|
2701
2704
|
n((d) => {
|
|
2702
2705
|
if (d.clientMessages.length === 0)
|
|
2703
2706
|
return d;
|
|
2704
|
-
const l =
|
|
2707
|
+
const l = m(d.clientMessages), w = new Set(
|
|
2705
2708
|
d.clientMessages.map((b) => b.messageId)
|
|
2706
2709
|
), T = d.uiMessages.filter(
|
|
2707
2710
|
(b) => !w.has(b.id) && b.role !== "user"
|
|
@@ -2714,26 +2717,26 @@ function Vt(e) {
|
|
|
2714
2717
|
])
|
|
2715
2718
|
};
|
|
2716
2719
|
});
|
|
2717
|
-
}, [i]);
|
|
2720
|
+
}, [i, m]);
|
|
2718
2721
|
const I = H(() => {
|
|
2719
2722
|
if (!t)
|
|
2720
2723
|
return;
|
|
2721
2724
|
const d = X(), l = s.agentId;
|
|
2722
2725
|
d.abortCurrentRequest(l);
|
|
2723
|
-
}, [s.agentId, t]),
|
|
2726
|
+
}, [s.agentId, t]), S = H(
|
|
2724
2727
|
async (d) => {
|
|
2725
2728
|
if (!t)
|
|
2726
2729
|
return;
|
|
2727
2730
|
const l = X(), w = s.agentId;
|
|
2728
2731
|
await l.replaceMessages(w, d);
|
|
2729
|
-
const T =
|
|
2732
|
+
const T = m(d);
|
|
2730
2733
|
n((b) => ({
|
|
2731
2734
|
...b,
|
|
2732
2735
|
clientMessages: d,
|
|
2733
2736
|
uiMessages: T
|
|
2734
2737
|
}));
|
|
2735
2738
|
},
|
|
2736
|
-
[s.agentId, t]
|
|
2739
|
+
[s.agentId, t, m]
|
|
2737
2740
|
);
|
|
2738
2741
|
return {
|
|
2739
2742
|
// AgentUI props
|
|
@@ -2756,18 +2759,18 @@ function Vt(e) {
|
|
|
2756
2759
|
// Abort control
|
|
2757
2760
|
abortCurrentRequest: I,
|
|
2758
2761
|
// Conversation loading
|
|
2759
|
-
loadMessages:
|
|
2762
|
+
loadMessages: S
|
|
2760
2763
|
};
|
|
2761
2764
|
}
|
|
2762
2765
|
var Pt = /* @__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))(Pt || {});
|
|
2763
|
-
const
|
|
2766
|
+
const Me = "jetpack-ai-jwt-token", _t = 30 * 60 * 1e3;
|
|
2764
2767
|
function Et() {
|
|
2765
2768
|
var t, a, n;
|
|
2766
2769
|
return ((a = (t = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : t.connectionStatus) == null ? void 0 : a.isRegistered) ? !1 : !!((n = window.Jetpack_Editor_Initial_State) != null && n.wpcomBlogId);
|
|
2767
2770
|
}
|
|
2768
2771
|
async function Ot(e, s = !0) {
|
|
2769
2772
|
var i, g;
|
|
2770
|
-
const t = localStorage.getItem(
|
|
2773
|
+
const t = localStorage.getItem(Me);
|
|
2771
2774
|
let a;
|
|
2772
2775
|
if (t)
|
|
2773
2776
|
try {
|
|
@@ -2807,7 +2810,7 @@ async function Ot(e, s = !0) {
|
|
|
2807
2810
|
expire: Date.now() + _t
|
|
2808
2811
|
};
|
|
2809
2812
|
try {
|
|
2810
|
-
localStorage.setItem(
|
|
2813
|
+
localStorage.setItem(Me, JSON.stringify(c));
|
|
2811
2814
|
} catch (u) {
|
|
2812
2815
|
A("Error storing token in localStorage: %O", u);
|
|
2813
2816
|
}
|
|
@@ -85,6 +85,7 @@ export interface UseMessageActionsReturn {
|
|
|
85
85
|
unregisterMessageActions: (id: string) => void;
|
|
86
86
|
clearAllMessageActions: () => void;
|
|
87
87
|
}
|
|
88
|
+
export declare const transformClientMessageToUI: (clientMessage: ClientMessage, messageActionsRegistrations?: MessageActionsRegistration[]) => UIMessage | null;
|
|
88
89
|
export interface UseAgentChatConfig {
|
|
89
90
|
agentId: string;
|
|
90
91
|
agentUrl: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useAgentChat.d.ts","sourceRoot":"","sources":["../../src/react/useAgentChat.ts"],"names":[],"mappings":"AAAA,OAAO,KAAmD,MAAM,OAAO,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAEvC,OAAO,KAAK,EACX,YAAY,EACZ,OAAO,IAAI,aAAa,EACxB,WAAW,EACX,eAAe,EACf,YAAY,EACZ,MAAM,uBAAuB,CAAC;AAiC/B,MAAM,WAAW,UAAU;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,OAAO,GAAG,OAAO,CAAE,OAAO,CAAE,CAAC;CAC5C;AAGD,MAAM,WAAW,SAAS;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,QAAQ,CAAC,EAAE,MAAM,CAAE,MAAM,EAAE,OAAO,CAAE,CAAC;CACrC;AAGD,MAAM,WAAW,aAAa;IAC7B,IAAI,CAAC,EAAE,WAAW,GAAG,aAAa,CAAC;IACnC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAE,MAAM,GAAG,SAAS,CAAE,EAAE,CAAC;IACrC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,MAAM,CAAC,EAAE,MAAM,CAAC;CAChB;AAGD,MAAM,WAAW,SAAS;IACzB,EAAE,EAAE,MAAM,CAAC;IACX,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC;IACvB,OAAO,EAAE,KAAK,CAAE;QACf,IAAI,E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