@automattic/agenttic-client 0.1.31 → 0.1.33
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/types/index.d.ts +13 -1
- package/dist/client/types/index.d.ts.map +1 -1
- package/dist/client/utils/core.d.ts +6 -0
- package/dist/client/utils/core.d.ts.map +1 -1
- package/dist/client/utils/index.d.ts +1 -1
- package/dist/client/utils/index.d.ts.map +1 -1
- package/dist/client/utils/internal/streaming.d.ts.map +1 -1
- package/dist/index.js +692 -672
- 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,24 +1,24 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var te = (e,
|
|
4
|
-
import
|
|
5
|
-
import { l as
|
|
1
|
+
var $e = Object.defineProperty;
|
|
2
|
+
var Ue = (e, s, t) => s in e ? $e(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
|
+
var te = (e, s, t) => Ue(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
import qe, { useMemo as Se, useCallback as q, useState as Me, useRef as He, useEffect as se } from "react";
|
|
5
|
+
import { l as v, f as ve, a as L } from "./logger-aKHbTlwk.js";
|
|
6
6
|
import pe from "@wordpress/api-fetch";
|
|
7
|
-
function
|
|
8
|
-
return
|
|
7
|
+
function qt(e) {
|
|
8
|
+
return Se(() => e ? {
|
|
9
9
|
getClientContext: () => {
|
|
10
10
|
try {
|
|
11
11
|
return e() || {};
|
|
12
12
|
} catch (a) {
|
|
13
|
-
return
|
|
13
|
+
return v("Error getting client context: %O", a), {};
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
} : void 0, [e]);
|
|
17
17
|
}
|
|
18
18
|
function ce({
|
|
19
19
|
getClientTools: e,
|
|
20
|
-
executeTool:
|
|
21
|
-
getAbilities:
|
|
20
|
+
executeTool: s,
|
|
21
|
+
getAbilities: t
|
|
22
22
|
}) {
|
|
23
23
|
const a = q(async () => {
|
|
24
24
|
const o = [];
|
|
@@ -27,103 +27,109 @@ function ce({
|
|
|
27
27
|
const c = await e();
|
|
28
28
|
o.push(...c);
|
|
29
29
|
} catch (c) {
|
|
30
|
-
|
|
30
|
+
v("Error getting available tools: %O", c);
|
|
31
31
|
}
|
|
32
32
|
return o;
|
|
33
33
|
}, [e]), n = q(
|
|
34
34
|
async (o, c) => {
|
|
35
|
-
if (!
|
|
35
|
+
if (!s)
|
|
36
36
|
throw new Error("No executeTool callback provided");
|
|
37
37
|
try {
|
|
38
|
-
return await
|
|
38
|
+
return await s(o, c);
|
|
39
39
|
} catch (l) {
|
|
40
|
-
throw
|
|
40
|
+
throw v("Error executing tool %s: %O", o, l), l;
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
-
[
|
|
43
|
+
[s]
|
|
44
44
|
);
|
|
45
|
-
return
|
|
46
|
-
if (!e && !
|
|
45
|
+
return Se(() => {
|
|
46
|
+
if (!e && !t)
|
|
47
47
|
return;
|
|
48
48
|
const o = {};
|
|
49
|
-
return e && (o.getAvailableTools = a),
|
|
49
|
+
return e && (o.getAvailableTools = a), s && (o.executeTool = n), t && (o.getAbilities = t), o;
|
|
50
50
|
}, [
|
|
51
51
|
a,
|
|
52
52
|
n,
|
|
53
53
|
e,
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
s,
|
|
55
|
+
t
|
|
56
56
|
]);
|
|
57
57
|
}
|
|
58
|
-
function
|
|
58
|
+
function Ht(e, s) {
|
|
59
59
|
return ce({
|
|
60
60
|
getClientTools: e,
|
|
61
|
-
executeTool:
|
|
61
|
+
executeTool: s,
|
|
62
62
|
getAbilities: void 0
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function Ft(e) {
|
|
66
66
|
return ce({
|
|
67
67
|
getClientTools: void 0,
|
|
68
68
|
executeTool: void 0,
|
|
69
69
|
getAbilities: e
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
function
|
|
73
|
-
const { getClientTools:
|
|
74
|
-
if (!
|
|
72
|
+
function jt(e) {
|
|
73
|
+
const { getClientTools: s, executeTool: t, getAbilities: a } = e;
|
|
74
|
+
if (!s && !a)
|
|
75
75
|
throw new Error(
|
|
76
76
|
"At least one of getClientTools or getAbilities must be provided to useClientToolsWithAbilities."
|
|
77
77
|
);
|
|
78
|
-
if (
|
|
78
|
+
if (s && !t)
|
|
79
79
|
throw new Error(
|
|
80
80
|
"executeTool is required when providing getClientTools."
|
|
81
81
|
);
|
|
82
82
|
return ce({
|
|
83
|
-
getClientTools:
|
|
84
|
-
executeTool:
|
|
83
|
+
getClientTools: s,
|
|
84
|
+
executeTool: t,
|
|
85
85
|
getAbilities: a
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
function ue() {
|
|
89
89
|
const e = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
90
|
-
let
|
|
91
|
-
for (let
|
|
92
|
-
|
|
93
|
-
return
|
|
90
|
+
let s = "";
|
|
91
|
+
for (let t = 0; t < 8; t++)
|
|
92
|
+
s += e.charAt(Math.floor(Math.random() * e.length));
|
|
93
|
+
return s;
|
|
94
94
|
}
|
|
95
95
|
function _() {
|
|
96
96
|
return ue();
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function Fe() {
|
|
99
99
|
return `req-${ue()}`;
|
|
100
100
|
}
|
|
101
|
-
function
|
|
101
|
+
function je() {
|
|
102
102
|
return `task-${ue()}`;
|
|
103
103
|
}
|
|
104
|
-
function Ae(e,
|
|
104
|
+
function Ae(e, s) {
|
|
105
105
|
return {
|
|
106
106
|
type: "text",
|
|
107
107
|
text: e,
|
|
108
|
-
...
|
|
108
|
+
...s && { metadata: s }
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
-
function
|
|
111
|
+
function De(e, s = "message/send", t = !1) {
|
|
112
112
|
const a = {
|
|
113
113
|
jsonrpc: "2.0",
|
|
114
|
-
id:
|
|
115
|
-
method:
|
|
114
|
+
id: Fe(),
|
|
115
|
+
method: s,
|
|
116
116
|
params: {
|
|
117
|
-
id: e.id ||
|
|
117
|
+
id: e.id || je(),
|
|
118
118
|
...e
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
|
-
return
|
|
121
|
+
return t && s === "message/stream" && (a.tokenStreaming = !0), a;
|
|
122
122
|
}
|
|
123
123
|
function F(e) {
|
|
124
|
-
return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((
|
|
124
|
+
return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
|
|
125
125
|
}
|
|
126
|
-
function
|
|
126
|
+
function he(e) {
|
|
127
|
+
if (!e || !e.parts || !Array.isArray(e.parts))
|
|
128
|
+
return;
|
|
129
|
+
const s = e.parts.find((t) => t.type === "progress" ? !0 : t.type === "data" ? "summary" in t.data && typeof t.data.summary == "string" : !1);
|
|
130
|
+
return s ? s.data.summary : void 0;
|
|
131
|
+
}
|
|
132
|
+
function Je(e) {
|
|
127
133
|
return {
|
|
128
134
|
type: "data",
|
|
129
135
|
data: {
|
|
@@ -135,7 +141,7 @@ function De(e) {
|
|
|
135
141
|
metadata: {}
|
|
136
142
|
};
|
|
137
143
|
}
|
|
138
|
-
function
|
|
144
|
+
function Le(e) {
|
|
139
145
|
return {
|
|
140
146
|
type: "data",
|
|
141
147
|
data: {
|
|
@@ -152,21 +158,21 @@ function Je(e) {
|
|
|
152
158
|
}
|
|
153
159
|
function B(e) {
|
|
154
160
|
return !e || !e.parts || !Array.isArray(e.parts) ? [] : e.parts.filter(
|
|
155
|
-
(
|
|
161
|
+
(s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
|
|
156
162
|
);
|
|
157
163
|
}
|
|
158
|
-
function W(e,
|
|
164
|
+
function W(e, s, t, a) {
|
|
159
165
|
return {
|
|
160
166
|
type: "data",
|
|
161
167
|
data: {
|
|
162
168
|
toolCallId: e,
|
|
163
|
-
toolId:
|
|
164
|
-
result:
|
|
169
|
+
toolId: s,
|
|
170
|
+
result: t
|
|
165
171
|
},
|
|
166
172
|
metadata: a ? { error: a } : void 0
|
|
167
173
|
};
|
|
168
174
|
}
|
|
169
|
-
function
|
|
175
|
+
function Be(e) {
|
|
170
176
|
return {
|
|
171
177
|
type: "data",
|
|
172
178
|
data: {
|
|
@@ -175,11 +181,11 @@ function Le(e) {
|
|
|
175
181
|
metadata: {}
|
|
176
182
|
};
|
|
177
183
|
}
|
|
178
|
-
function ie(e,
|
|
179
|
-
const { contentType:
|
|
184
|
+
function ie(e, s) {
|
|
185
|
+
const { contentType: t, ...a } = s || {};
|
|
180
186
|
return {
|
|
181
187
|
role: "user",
|
|
182
|
-
parts: [Ae(e,
|
|
188
|
+
parts: [Ae(e, t ? { contentType: t } : void 0)],
|
|
183
189
|
kind: "message",
|
|
184
190
|
messageId: _(),
|
|
185
191
|
metadata: {
|
|
@@ -211,77 +217,77 @@ function de(e) {
|
|
|
211
217
|
returnToAgent: !0
|
|
212
218
|
};
|
|
213
219
|
}
|
|
214
|
-
function X(e,
|
|
220
|
+
function X(e, s = []) {
|
|
215
221
|
return {
|
|
216
222
|
role: "user",
|
|
217
223
|
kind: "message",
|
|
218
|
-
parts: [...
|
|
224
|
+
parts: [...s, ...e],
|
|
219
225
|
messageId: _(),
|
|
220
226
|
metadata: {
|
|
221
227
|
timestamp: Date.now()
|
|
222
228
|
}
|
|
223
229
|
};
|
|
224
230
|
}
|
|
225
|
-
function
|
|
231
|
+
function Dt() {
|
|
226
232
|
return new AbortController();
|
|
227
233
|
}
|
|
228
|
-
async function
|
|
229
|
-
if (!
|
|
234
|
+
async function Ke(e, s) {
|
|
235
|
+
if (!s)
|
|
230
236
|
return e;
|
|
231
237
|
try {
|
|
232
|
-
const
|
|
233
|
-
if (
|
|
234
|
-
const a = await
|
|
238
|
+
const t = [];
|
|
239
|
+
if (s.getAvailableTools) {
|
|
240
|
+
const a = await s.getAvailableTools();
|
|
235
241
|
if (a.length > 0) {
|
|
236
|
-
const n = a.map(
|
|
237
|
-
|
|
242
|
+
const n = a.map(Je);
|
|
243
|
+
t.push(...n);
|
|
238
244
|
}
|
|
239
245
|
}
|
|
240
|
-
if (
|
|
241
|
-
const a = await
|
|
246
|
+
if (s.getAbilities) {
|
|
247
|
+
const a = await s.getAbilities();
|
|
242
248
|
if (a.length > 0) {
|
|
243
|
-
const n = a.map(
|
|
244
|
-
|
|
249
|
+
const n = a.map(Le);
|
|
250
|
+
t.push(...n);
|
|
245
251
|
}
|
|
246
252
|
}
|
|
247
|
-
return
|
|
253
|
+
return t.length === 0 ? e : {
|
|
248
254
|
...e,
|
|
249
|
-
parts: [...e.parts, ...
|
|
255
|
+
parts: [...e.parts, ...t]
|
|
250
256
|
};
|
|
251
|
-
} catch (
|
|
252
|
-
return
|
|
257
|
+
} catch (t) {
|
|
258
|
+
return v("Warning: Failed to get tools: %s", t), e;
|
|
253
259
|
}
|
|
254
260
|
}
|
|
255
|
-
function
|
|
256
|
-
if (!
|
|
261
|
+
function We(e, s) {
|
|
262
|
+
if (!s)
|
|
257
263
|
return e;
|
|
258
264
|
try {
|
|
259
|
-
const
|
|
260
|
-
if (!
|
|
265
|
+
const t = s.getClientContext();
|
|
266
|
+
if (!t || Object.keys(t).length === 0)
|
|
261
267
|
return e;
|
|
262
|
-
const a =
|
|
268
|
+
const a = Be(t);
|
|
263
269
|
return {
|
|
264
270
|
...e,
|
|
265
271
|
parts: [...e.parts, a]
|
|
266
272
|
};
|
|
267
|
-
} catch (
|
|
268
|
-
return
|
|
273
|
+
} catch (t) {
|
|
274
|
+
return v("Warning: Failed to get context: %s", t), e;
|
|
269
275
|
}
|
|
270
276
|
}
|
|
271
|
-
async function
|
|
272
|
-
let a = await
|
|
277
|
+
async function Ve(e, s, t) {
|
|
278
|
+
let a = await Ke(
|
|
273
279
|
e,
|
|
274
|
-
|
|
280
|
+
s
|
|
275
281
|
);
|
|
276
|
-
a =
|
|
282
|
+
a = We(
|
|
277
283
|
a,
|
|
278
|
-
|
|
284
|
+
t
|
|
279
285
|
);
|
|
280
286
|
const { metadata: n, ...r } = a;
|
|
281
287
|
return r;
|
|
282
288
|
}
|
|
283
|
-
function
|
|
284
|
-
const
|
|
289
|
+
function ze(e, s = "") {
|
|
290
|
+
const t = [], a = s + e;
|
|
285
291
|
let n = "", r = 0, o = 0;
|
|
286
292
|
for (; o < a.length; ) {
|
|
287
293
|
const l = a.indexOf(
|
|
@@ -296,29 +302,29 @@ function Ve(e, t = "") {
|
|
|
296
302
|
);
|
|
297
303
|
else if (d.trim() === "" && n) {
|
|
298
304
|
try {
|
|
299
|
-
|
|
305
|
+
t.push(JSON.parse(n)), r = l === -1 ? a.length : l + 1;
|
|
300
306
|
} catch (u) {
|
|
301
|
-
|
|
307
|
+
v("Failed to parse SSE event: %o", u), v("Problematic payload: %s", n);
|
|
302
308
|
}
|
|
303
309
|
n = "";
|
|
304
310
|
}
|
|
305
311
|
l === -1 ? o = a.length : o = l + 1;
|
|
306
312
|
}
|
|
307
313
|
const c = a.substring(r);
|
|
308
|
-
return { events:
|
|
314
|
+
return { events: t, nextBuffer: c };
|
|
309
315
|
}
|
|
310
|
-
async function*
|
|
316
|
+
async function* Ge(e, s = {}) {
|
|
311
317
|
var d, u, w;
|
|
312
|
-
const { supportDeltas:
|
|
318
|
+
const { supportDeltas: t = !1 } = s, a = e.getReader(), n = new TextDecoder();
|
|
313
319
|
let r = "";
|
|
314
|
-
const o = new
|
|
320
|
+
const o = new Qe();
|
|
315
321
|
let c = null, l = null;
|
|
316
322
|
try {
|
|
317
323
|
for (; ; ) {
|
|
318
324
|
const { done: m, value: g } = await a.read();
|
|
319
325
|
if (m)
|
|
320
326
|
break;
|
|
321
|
-
const h = n.decode(g, { stream: !0 }), { events: y, nextBuffer: x } =
|
|
327
|
+
const h = n.decode(g, { stream: !0 }), { events: y, nextBuffer: x } = ze(h, r);
|
|
322
328
|
if (y && Array.isArray(y))
|
|
323
329
|
for (let f = 0; f < y.length; f++) {
|
|
324
330
|
const i = y[f];
|
|
@@ -328,49 +334,54 @@ async function* ze(e, t = {}) {
|
|
|
328
334
|
throw new Error(
|
|
329
335
|
`Streaming error: ${i.error.message}`
|
|
330
336
|
);
|
|
331
|
-
if (
|
|
337
|
+
if (t && i.method === "message/delta" && ((d = i.params) != null && d.delta)) {
|
|
332
338
|
const T = i.params.delta;
|
|
333
339
|
try {
|
|
334
340
|
if (T.deltaType === "content" && (o.processContentDelta(
|
|
335
341
|
T.content
|
|
336
342
|
), !c && i.params.id && (c = i.params.id), c)) {
|
|
337
|
-
const
|
|
343
|
+
const A = o.getCurrentMessage();
|
|
338
344
|
yield {
|
|
339
345
|
id: c,
|
|
340
346
|
status: {
|
|
341
347
|
state: "working",
|
|
342
|
-
message:
|
|
348
|
+
message: A
|
|
343
349
|
},
|
|
344
350
|
final: !1,
|
|
345
351
|
text: o.getTextContent()
|
|
346
352
|
};
|
|
347
353
|
}
|
|
348
|
-
} catch (
|
|
349
|
-
|
|
354
|
+
} catch (A) {
|
|
355
|
+
v("Failed to process delta: %o", A);
|
|
350
356
|
}
|
|
351
|
-
} else
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
357
|
+
} else if (i.result && i.result.status) {
|
|
358
|
+
c = i.result.id, l = i.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset();
|
|
359
|
+
const T = ((u = i.result.status) == null ? void 0 : u.message) || {
|
|
360
|
+
role: "agent",
|
|
361
|
+
parts: []
|
|
362
|
+
};
|
|
363
|
+
yield {
|
|
364
|
+
id: i.result.id,
|
|
365
|
+
sessionId: i.result.sessionId,
|
|
366
|
+
status: i.result.status,
|
|
367
|
+
final: i.result.status.state === "completed" || i.result.status.state === "failed" || i.result.status.state === "canceled",
|
|
368
|
+
text: F(T),
|
|
369
|
+
progressMessage: he(T)
|
|
370
|
+
};
|
|
371
|
+
} else if (i.id && i.result && (c = i.result.id, i.result.status)) {
|
|
372
|
+
const T = ((w = i.result.status) == null ? void 0 : w.message) || {
|
|
373
|
+
role: "agent",
|
|
374
|
+
parts: []
|
|
375
|
+
};
|
|
376
|
+
yield {
|
|
377
|
+
id: i.result.id,
|
|
378
|
+
sessionId: i.result.sessionId,
|
|
379
|
+
status: i.result.status,
|
|
380
|
+
final: i.result.status.state === "completed" || i.result.status.state === "failed" || i.result.status.state === "canceled",
|
|
381
|
+
text: F(T),
|
|
382
|
+
progressMessage: he(T)
|
|
383
|
+
};
|
|
384
|
+
}
|
|
374
385
|
}
|
|
375
386
|
r = x;
|
|
376
387
|
}
|
|
@@ -378,7 +389,7 @@ async function* ze(e, t = {}) {
|
|
|
378
389
|
a.releaseLock();
|
|
379
390
|
}
|
|
380
391
|
}
|
|
381
|
-
class
|
|
392
|
+
class Qe {
|
|
382
393
|
constructor() {
|
|
383
394
|
te(this, "textContent", "");
|
|
384
395
|
te(this, "toolCalls", /* @__PURE__ */ new Map());
|
|
@@ -387,33 +398,33 @@ class Ge {
|
|
|
387
398
|
* Process a simple content delta (server's actual format)
|
|
388
399
|
* @param content - The text content to append
|
|
389
400
|
*/
|
|
390
|
-
processContentDelta(
|
|
391
|
-
this.textContent +=
|
|
401
|
+
processContentDelta(s) {
|
|
402
|
+
this.textContent += s;
|
|
392
403
|
}
|
|
393
404
|
/**
|
|
394
405
|
* Process a delta message and accumulate the content (original format)
|
|
395
406
|
* @param delta - The delta message to process
|
|
396
407
|
*/
|
|
397
|
-
processDelta(
|
|
398
|
-
switch (
|
|
408
|
+
processDelta(s) {
|
|
409
|
+
switch (s.type) {
|
|
399
410
|
case "content":
|
|
400
|
-
this.textContent +=
|
|
411
|
+
this.textContent += s.content;
|
|
401
412
|
break;
|
|
402
413
|
case "tool_name":
|
|
403
|
-
this.toolCalls.has(
|
|
404
|
-
toolCallId:
|
|
414
|
+
this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
|
|
415
|
+
toolCallId: s.toolCallId,
|
|
405
416
|
toolName: "",
|
|
406
417
|
argumentFragments: []
|
|
407
418
|
});
|
|
408
|
-
const
|
|
409
|
-
|
|
419
|
+
const t = this.toolCalls.get(s.toolCallIndex);
|
|
420
|
+
t.toolName += s.content;
|
|
410
421
|
break;
|
|
411
422
|
case "tool_argument":
|
|
412
|
-
this.toolCalls.has(
|
|
413
|
-
toolCallId:
|
|
423
|
+
this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
|
|
424
|
+
toolCallId: s.toolCallId,
|
|
414
425
|
toolName: "",
|
|
415
426
|
argumentFragments: []
|
|
416
|
-
}), this.toolCalls.get(
|
|
427
|
+
}), this.toolCalls.get(s.toolCallIndex).argumentFragments.push(s.content);
|
|
417
428
|
break;
|
|
418
429
|
}
|
|
419
430
|
}
|
|
@@ -427,9 +438,9 @@ class Ge {
|
|
|
427
438
|
* Get the current accumulated message
|
|
428
439
|
* @param role - The role for the message (default: 'agent')
|
|
429
440
|
*/
|
|
430
|
-
getCurrentMessage(
|
|
431
|
-
const
|
|
432
|
-
this.textContent &&
|
|
441
|
+
getCurrentMessage(s = "agent") {
|
|
442
|
+
const t = [];
|
|
443
|
+
this.textContent && t.push({
|
|
433
444
|
type: "text",
|
|
434
445
|
text: this.textContent
|
|
435
446
|
});
|
|
@@ -443,7 +454,7 @@ class Ge {
|
|
|
443
454
|
} catch {
|
|
444
455
|
o = { _raw: r };
|
|
445
456
|
}
|
|
446
|
-
|
|
457
|
+
t.push({
|
|
447
458
|
type: "data",
|
|
448
459
|
data: {
|
|
449
460
|
toolCallId: n.toolCallId,
|
|
@@ -453,8 +464,8 @@ class Ge {
|
|
|
453
464
|
});
|
|
454
465
|
}
|
|
455
466
|
return {
|
|
456
|
-
role:
|
|
457
|
-
parts:
|
|
467
|
+
role: s,
|
|
468
|
+
parts: t,
|
|
458
469
|
kind: "message",
|
|
459
470
|
messageId: _()
|
|
460
471
|
};
|
|
@@ -466,71 +477,71 @@ class Ge {
|
|
|
466
477
|
this.textContent = "", this.toolCalls.clear();
|
|
467
478
|
}
|
|
468
479
|
}
|
|
469
|
-
function xe(e,
|
|
470
|
-
throw clearTimeout(
|
|
480
|
+
function xe(e, s, t = "request") {
|
|
481
|
+
throw clearTimeout(s), v("%s failed with error: %O", t, e), e instanceof Error && (v("Error message: %s", e.message), v("Error stack: %s", e.stack)), e;
|
|
471
482
|
}
|
|
472
|
-
function
|
|
483
|
+
function Ce(e, s = "request") {
|
|
473
484
|
if (!e.ok)
|
|
474
485
|
throw new Error(`HTTP error! status: ${e.status}`);
|
|
475
486
|
}
|
|
476
|
-
function
|
|
487
|
+
function Xe(e, s = "request") {
|
|
477
488
|
if (e.error)
|
|
478
489
|
throw new Error(
|
|
479
|
-
`Protocol ${
|
|
490
|
+
`Protocol ${s} error: ${e.error.message}`
|
|
480
491
|
);
|
|
481
492
|
if (!e.result)
|
|
482
|
-
throw new Error(`No result in ${
|
|
493
|
+
throw new Error(`No result in ${s} response`);
|
|
483
494
|
return e.result;
|
|
484
495
|
}
|
|
485
|
-
function
|
|
486
|
-
if (
|
|
487
|
-
throw new Error(`No response body for ${
|
|
496
|
+
function Ye(e, s = "streaming request") {
|
|
497
|
+
if (Ce(e, s), !e.body)
|
|
498
|
+
throw new Error(`No response body for ${s}`);
|
|
488
499
|
}
|
|
489
|
-
function
|
|
490
|
-
const
|
|
500
|
+
function be(e, s = "request") {
|
|
501
|
+
const t = new AbortController();
|
|
491
502
|
return { timeoutId: setTimeout(
|
|
492
|
-
() =>
|
|
503
|
+
() => t.abort(),
|
|
493
504
|
e
|
|
494
|
-
), controller:
|
|
505
|
+
), controller: t };
|
|
495
506
|
}
|
|
496
|
-
function
|
|
497
|
-
return `${e}/${
|
|
507
|
+
function Ze(e, s) {
|
|
508
|
+
return `${e}/${s}`;
|
|
498
509
|
}
|
|
499
|
-
function
|
|
500
|
-
|
|
510
|
+
function et(e, s, t, a) {
|
|
511
|
+
v("Request: %s %s", e, s), v("Headers: %o", t), a && v("Body: %s", ve(a));
|
|
501
512
|
}
|
|
502
|
-
async function
|
|
503
|
-
const
|
|
513
|
+
async function tt(e, s = !1) {
|
|
514
|
+
const t = {
|
|
504
515
|
"Content-Type": "application/json"
|
|
505
516
|
};
|
|
506
|
-
if (
|
|
517
|
+
if (s && (t.Accept = "text/event-stream"), e) {
|
|
507
518
|
const a = await e();
|
|
508
|
-
return { ...
|
|
519
|
+
return { ...t, ...a };
|
|
509
520
|
}
|
|
510
|
-
return
|
|
521
|
+
return t;
|
|
511
522
|
}
|
|
512
|
-
function
|
|
513
|
-
if (!
|
|
523
|
+
function ke(e, s) {
|
|
524
|
+
if (!s)
|
|
514
525
|
return e;
|
|
515
|
-
const
|
|
516
|
-
|
|
526
|
+
const t = new AbortController(), a = (n) => {
|
|
527
|
+
t.signal.aborted || t.abort(n.reason);
|
|
517
528
|
};
|
|
518
|
-
return e.aborted ?
|
|
529
|
+
return e.aborted ? t.abort(e.reason) : e.addEventListener("abort", () => a(e), {
|
|
519
530
|
once: !0
|
|
520
|
-
}),
|
|
531
|
+
}), s.aborted ? t.abort(s.reason) : s.addEventListener("abort", () => a(s), {
|
|
521
532
|
once: !0
|
|
522
|
-
}),
|
|
533
|
+
}), t.signal;
|
|
523
534
|
}
|
|
524
|
-
function
|
|
535
|
+
function Re(e, s, t) {
|
|
525
536
|
return {
|
|
526
537
|
method: "POST",
|
|
527
538
|
headers: e,
|
|
528
|
-
body:
|
|
529
|
-
signal:
|
|
539
|
+
body: s,
|
|
540
|
+
signal: t
|
|
530
541
|
};
|
|
531
542
|
}
|
|
532
|
-
async function Y(e,
|
|
533
|
-
const { message: o, sessionId: c, taskId: l, metadata: d } = e, { agentId: u, agentUrl: w, authProvider: m, proxy: g } =
|
|
543
|
+
async function Y(e, s, t, a, n, r) {
|
|
544
|
+
const { message: o, sessionId: c, taskId: l, metadata: d } = e, { agentId: u, agentUrl: w, authProvider: m, proxy: g } = s, { isStreaming: h = !1, enableTokenStreaming: y = !1 } = t, x = c || r, f = Ze(w, u), i = await Ve(
|
|
534
545
|
o,
|
|
535
546
|
a,
|
|
536
547
|
n
|
|
@@ -540,83 +551,83 @@ async function Y(e, t, s, a, n, r) {
|
|
|
540
551
|
metadata: d
|
|
541
552
|
};
|
|
542
553
|
x && (T.sessionId = x);
|
|
543
|
-
const
|
|
554
|
+
const A = De(
|
|
544
555
|
T,
|
|
545
556
|
h ? "message/stream" : "message/send",
|
|
546
557
|
y && h
|
|
547
558
|
// Only enable token streaming if using SSE
|
|
548
|
-
), I = await
|
|
549
|
-
return
|
|
550
|
-
request:
|
|
559
|
+
), I = await tt(m, h);
|
|
560
|
+
return et("POST", f, I, A), {
|
|
561
|
+
request: A,
|
|
551
562
|
headers: I,
|
|
552
563
|
enhancedMessage: i,
|
|
553
564
|
effectiveSessionId: x,
|
|
554
565
|
fullAgentUrl: f
|
|
555
566
|
};
|
|
556
567
|
}
|
|
557
|
-
async function
|
|
558
|
-
const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o } =
|
|
568
|
+
async function Ee(e, s, t = {}) {
|
|
569
|
+
const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o } = s, { abortSignal: c } = t, { timeoutId: l, controller: d } = be(
|
|
559
570
|
o,
|
|
560
571
|
"request"
|
|
561
|
-
), u = c ?
|
|
572
|
+
), u = c ? ke(d.signal, c) : d.signal;
|
|
562
573
|
try {
|
|
563
|
-
const w =
|
|
574
|
+
const w = Re(
|
|
564
575
|
n,
|
|
565
576
|
JSON.stringify(a),
|
|
566
577
|
u
|
|
567
578
|
);
|
|
568
|
-
|
|
579
|
+
v("Making request to %s with options: %O", r, {
|
|
569
580
|
method: w.method,
|
|
570
581
|
headers: w.headers
|
|
571
582
|
});
|
|
572
583
|
const m = await fetch(r, w);
|
|
573
|
-
clearTimeout(l),
|
|
584
|
+
clearTimeout(l), Ce(m, "request");
|
|
574
585
|
const g = await m.json();
|
|
575
|
-
return
|
|
586
|
+
return v(
|
|
576
587
|
"Response from %s: %d %O",
|
|
577
588
|
r,
|
|
578
589
|
m.status,
|
|
579
590
|
ve(g)
|
|
580
|
-
),
|
|
591
|
+
), Xe(g, "request");
|
|
581
592
|
} catch (w) {
|
|
582
593
|
xe(w, l, "request");
|
|
583
594
|
}
|
|
584
595
|
}
|
|
585
|
-
async function*
|
|
596
|
+
async function* Pe(e, s, t) {
|
|
586
597
|
const { request: a, headers: n, fullAgentUrl: r } = e, {
|
|
587
598
|
streamingTimeout: o = 6e4,
|
|
588
599
|
abortSignal: c,
|
|
589
600
|
enableTokenStreaming: l = !1
|
|
590
|
-
} =
|
|
601
|
+
} = t, { timeoutId: d, controller: u } = be(
|
|
591
602
|
o,
|
|
592
603
|
"streaming request"
|
|
593
|
-
), w = c ?
|
|
604
|
+
), w = c ? ke(u.signal, c) : u.signal;
|
|
594
605
|
try {
|
|
595
|
-
const m = JSON.stringify(a), g =
|
|
596
|
-
if (clearTimeout(d),
|
|
606
|
+
const m = JSON.stringify(a), g = Re(n, m, w), h = await fetch(r, g);
|
|
607
|
+
if (clearTimeout(d), Ye(h, "streaming request"), !h.body)
|
|
597
608
|
throw new Error(
|
|
598
609
|
"Response body is null - server may not support streaming"
|
|
599
610
|
);
|
|
600
611
|
const y = l && a.tokenStreaming === !0;
|
|
601
|
-
yield*
|
|
612
|
+
yield* Ge(h.body, {
|
|
602
613
|
supportDeltas: y
|
|
603
614
|
});
|
|
604
615
|
} catch (m) {
|
|
605
616
|
xe(m, d, "streaming request");
|
|
606
617
|
}
|
|
607
618
|
}
|
|
608
|
-
const
|
|
609
|
-
async function Z(e,
|
|
619
|
+
const st = 12e4;
|
|
620
|
+
async function Z(e, s, t, a, n) {
|
|
610
621
|
if (e.getAbilities) {
|
|
611
622
|
const r = await e.getAbilities();
|
|
612
623
|
if (r.length > 0)
|
|
613
624
|
for (const o of r) {
|
|
614
625
|
const c = o.name.replace(/\//g, "__").replace(/-/g, "_");
|
|
615
|
-
if (
|
|
626
|
+
if (s === c || s === o.name) {
|
|
616
627
|
if (o.callback)
|
|
617
628
|
try {
|
|
618
629
|
const l = {
|
|
619
|
-
...
|
|
630
|
+
...t,
|
|
620
631
|
...a && { messageId: a }
|
|
621
632
|
}, d = await o.callback(l);
|
|
622
633
|
return {
|
|
@@ -627,7 +638,7 @@ async function Z(e, t, s, a, n) {
|
|
|
627
638
|
}
|
|
628
639
|
};
|
|
629
640
|
} catch (l) {
|
|
630
|
-
return
|
|
641
|
+
return v(
|
|
631
642
|
"Error executing ability %s: %O",
|
|
632
643
|
o.name,
|
|
633
644
|
l
|
|
@@ -643,10 +654,10 @@ async function Z(e, t, s, a, n) {
|
|
|
643
654
|
try {
|
|
644
655
|
return { result: await e.executeAbility(
|
|
645
656
|
o.name,
|
|
646
|
-
|
|
657
|
+
t
|
|
647
658
|
), returnToAgent: !0 };
|
|
648
659
|
} catch (l) {
|
|
649
|
-
return
|
|
660
|
+
return v(
|
|
650
661
|
"Error executing ability %s: %O",
|
|
651
662
|
o.name,
|
|
652
663
|
l
|
|
@@ -666,25 +677,25 @@ async function Z(e, t, s, a, n) {
|
|
|
666
677
|
}
|
|
667
678
|
if (e.executeTool)
|
|
668
679
|
return await e.executeTool(
|
|
669
|
-
t,
|
|
670
680
|
s,
|
|
681
|
+
t,
|
|
671
682
|
a,
|
|
672
683
|
n
|
|
673
684
|
);
|
|
674
685
|
throw new Error(
|
|
675
|
-
`No handler found for tool: ${
|
|
686
|
+
`No handler found for tool: ${s}. Tool provider must implement executeTool for non-ability tools.`
|
|
676
687
|
);
|
|
677
688
|
}
|
|
678
689
|
const ge = /* @__PURE__ */ new Map();
|
|
679
|
-
async function
|
|
680
|
-
if (!e || !
|
|
690
|
+
async function at(e, s) {
|
|
691
|
+
if (!e || !s || !e.getAvailableTools)
|
|
681
692
|
return !1;
|
|
682
|
-
const
|
|
683
|
-
if (
|
|
693
|
+
const t = B(s);
|
|
694
|
+
if (t.length === 0)
|
|
684
695
|
return !1;
|
|
685
696
|
try {
|
|
686
697
|
const a = await e.getAvailableTools();
|
|
687
|
-
for (const n of
|
|
698
|
+
for (const n of t)
|
|
688
699
|
if (a.some(
|
|
689
700
|
(o) => o.id === n.data.toolId
|
|
690
701
|
))
|
|
@@ -694,39 +705,39 @@ async function st(e, t) {
|
|
|
694
705
|
}
|
|
695
706
|
return !1;
|
|
696
707
|
}
|
|
697
|
-
function
|
|
708
|
+
function nt() {
|
|
698
709
|
ge.clear();
|
|
699
710
|
}
|
|
700
|
-
function
|
|
701
|
-
return e.map((
|
|
702
|
-
const
|
|
711
|
+
function ot(e) {
|
|
712
|
+
return e.map((s) => {
|
|
713
|
+
const t = s.data.toolCallId, a = ge.get(t);
|
|
703
714
|
if (a && a.resolvedValue !== null) {
|
|
704
715
|
const n = a.resolvedValue;
|
|
705
716
|
return n.error ? W(
|
|
706
|
-
|
|
707
|
-
|
|
717
|
+
t,
|
|
718
|
+
s.data.toolId,
|
|
708
719
|
void 0,
|
|
709
720
|
n.error
|
|
710
721
|
) : W(
|
|
711
|
-
|
|
712
|
-
|
|
722
|
+
t,
|
|
723
|
+
s.data.toolId,
|
|
713
724
|
n
|
|
714
725
|
);
|
|
715
726
|
}
|
|
716
|
-
return
|
|
727
|
+
return s;
|
|
717
728
|
});
|
|
718
729
|
}
|
|
719
|
-
async function
|
|
730
|
+
async function Oe(e, s, t) {
|
|
720
731
|
const a = [], n = [];
|
|
721
732
|
let r = !1;
|
|
722
733
|
for (const o of e) {
|
|
723
734
|
const { toolCallId: c, toolId: l, arguments: d } = o.data;
|
|
724
735
|
try {
|
|
725
736
|
const u = await Z(
|
|
726
|
-
|
|
737
|
+
s,
|
|
727
738
|
l,
|
|
728
739
|
d,
|
|
729
|
-
|
|
740
|
+
t,
|
|
730
741
|
c
|
|
731
742
|
), { result: w, returnToAgent: m, agentMessage: g } = de(u);
|
|
732
743
|
m && (r = !0), g && n.push(G(g)), a.push(
|
|
@@ -749,61 +760,61 @@ async function Pe(e, t, s) {
|
|
|
749
760
|
}
|
|
750
761
|
return { results: a, shouldReturnToAgent: r, agentMessages: n };
|
|
751
762
|
}
|
|
752
|
-
function
|
|
753
|
-
const
|
|
754
|
-
for (const
|
|
755
|
-
for (const a of
|
|
756
|
-
a.type === "text" ?
|
|
763
|
+
function ye(e) {
|
|
764
|
+
const s = [];
|
|
765
|
+
for (const t of e)
|
|
766
|
+
for (const a of t.parts)
|
|
767
|
+
a.type === "text" ? s.push({
|
|
757
768
|
type: "data",
|
|
758
769
|
data: {
|
|
759
|
-
role:
|
|
770
|
+
role: t.role,
|
|
760
771
|
text: a.text
|
|
761
772
|
}
|
|
762
|
-
}) : a.type === "data" &&
|
|
763
|
-
return
|
|
773
|
+
}) : a.type === "data" && s.push(a);
|
|
774
|
+
return s;
|
|
764
775
|
}
|
|
765
|
-
async function ae(e,
|
|
776
|
+
async function ae(e, s, t, a, n, r, o) {
|
|
766
777
|
const l = await Y(
|
|
767
778
|
{
|
|
768
|
-
message:
|
|
779
|
+
message: s,
|
|
769
780
|
taskId: e,
|
|
770
781
|
sessionId: void 0
|
|
771
782
|
// Use task's session
|
|
772
783
|
},
|
|
773
|
-
|
|
784
|
+
t,
|
|
774
785
|
{ isStreaming: !1 },
|
|
775
786
|
a,
|
|
776
787
|
n,
|
|
777
788
|
r
|
|
778
789
|
);
|
|
779
|
-
return await
|
|
790
|
+
return await Ee(l, t, {
|
|
780
791
|
abortSignal: o
|
|
781
792
|
});
|
|
782
793
|
}
|
|
783
|
-
async function
|
|
794
|
+
async function Ie(e, s, t, a, n, r, o, c, l = []) {
|
|
784
795
|
const d = {
|
|
785
|
-
message:
|
|
796
|
+
message: s,
|
|
786
797
|
taskId: e,
|
|
787
798
|
sessionId: r
|
|
788
799
|
// Use the provided sessionId to maintain conversation continuity
|
|
789
800
|
}, u = c || { isStreaming: !0 }, w = await Y(
|
|
790
801
|
d,
|
|
791
|
-
|
|
802
|
+
t,
|
|
792
803
|
{
|
|
793
804
|
...u
|
|
794
805
|
},
|
|
795
806
|
a,
|
|
796
807
|
n,
|
|
797
808
|
r
|
|
798
|
-
), m =
|
|
809
|
+
), m = Pe(w, t, {
|
|
799
810
|
...u,
|
|
800
811
|
abortSignal: o
|
|
801
812
|
});
|
|
802
|
-
return
|
|
813
|
+
return _e(
|
|
803
814
|
m,
|
|
804
815
|
a,
|
|
805
816
|
n,
|
|
806
|
-
|
|
817
|
+
t,
|
|
807
818
|
r,
|
|
808
819
|
!0,
|
|
809
820
|
// withHistory
|
|
@@ -814,11 +825,11 @@ async function ye(e, t, s, a, n, r, o, c, l = []) {
|
|
|
814
825
|
// Pass through the same request options
|
|
815
826
|
);
|
|
816
827
|
}
|
|
817
|
-
async function*
|
|
818
|
-
var d, u, w, m, g, h, y, x, f, i, T,
|
|
828
|
+
async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
829
|
+
var d, u, w, m, g, h, y, x, f, i, T, A;
|
|
819
830
|
for await (const I of e) {
|
|
820
|
-
if (I.sessionId && !n && (n = I.sessionId), yield I, I.status.state === "running" && I.status.message &&
|
|
821
|
-
|
|
831
|
+
if (I.sessionId && !n && (n = I.sessionId), yield I, I.status.state === "running" && I.status.message && s && await at(
|
|
832
|
+
s,
|
|
822
833
|
I.status.message
|
|
823
834
|
)) {
|
|
824
835
|
const P = B(
|
|
@@ -827,13 +838,13 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
827
838
|
for (const O of P) {
|
|
828
839
|
const { toolCallId: $, toolId: S, arguments: p } = O.data;
|
|
829
840
|
Z(
|
|
830
|
-
|
|
841
|
+
s,
|
|
831
842
|
S,
|
|
832
843
|
p,
|
|
833
844
|
(u = (d = I.status) == null ? void 0 : d.message) == null ? void 0 : u.messageId,
|
|
834
845
|
$
|
|
835
|
-
).catch((
|
|
836
|
-
|
|
846
|
+
).catch((C) => {
|
|
847
|
+
v("Tool execution failed for %s: %O", S, C);
|
|
837
848
|
});
|
|
838
849
|
}
|
|
839
850
|
yield {
|
|
@@ -851,7 +862,7 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
851
862
|
text: ""
|
|
852
863
|
};
|
|
853
864
|
}
|
|
854
|
-
if (I.status.state === "input-required" && I.status.message &&
|
|
865
|
+
if (I.status.state === "input-required" && I.status.message && s) {
|
|
855
866
|
const P = B(
|
|
856
867
|
I.status.message
|
|
857
868
|
);
|
|
@@ -859,36 +870,36 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
859
870
|
const O = [];
|
|
860
871
|
let $ = !1;
|
|
861
872
|
const S = [], p = [];
|
|
862
|
-
for (const
|
|
873
|
+
for (const C of P) {
|
|
863
874
|
const {
|
|
864
|
-
toolCallId:
|
|
865
|
-
toolId:
|
|
875
|
+
toolCallId: M,
|
|
876
|
+
toolId: R,
|
|
866
877
|
arguments: k
|
|
867
|
-
} =
|
|
878
|
+
} = C.data;
|
|
868
879
|
try {
|
|
869
880
|
const b = await Z(
|
|
870
|
-
|
|
871
|
-
|
|
881
|
+
s,
|
|
882
|
+
R,
|
|
872
883
|
k,
|
|
873
884
|
(m = (w = I.status) == null ? void 0 : w.message) == null ? void 0 : m.messageId,
|
|
874
|
-
|
|
875
|
-
), { result:
|
|
885
|
+
M
|
|
886
|
+
), { result: E, returnToAgent: U, agentMessage: D } = de(b);
|
|
876
887
|
if (U && ($ = !0), D && p.push(
|
|
877
888
|
G(D)
|
|
878
|
-
),
|
|
879
|
-
const N =
|
|
889
|
+
), E.result instanceof Promise) {
|
|
890
|
+
const N = E.result, J = {
|
|
880
891
|
promise: N,
|
|
881
892
|
resolvedValue: null
|
|
882
893
|
};
|
|
883
894
|
ge.set(
|
|
884
|
-
|
|
895
|
+
M,
|
|
885
896
|
J
|
|
886
897
|
), N.then((H) => {
|
|
887
898
|
J.resolvedValue = H;
|
|
888
899
|
}).catch((H) => {
|
|
889
|
-
|
|
900
|
+
v(
|
|
890
901
|
"Promise rejected for tool call %s: %O",
|
|
891
|
-
|
|
902
|
+
M,
|
|
892
903
|
H
|
|
893
904
|
), J.resolvedValue = {
|
|
894
905
|
error: H instanceof Error ? H.message : String(H)
|
|
@@ -896,19 +907,19 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
896
907
|
});
|
|
897
908
|
}
|
|
898
909
|
const j = W(
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
910
|
+
M,
|
|
911
|
+
R,
|
|
912
|
+
E
|
|
902
913
|
);
|
|
903
914
|
O.push(j), S.push(j);
|
|
904
915
|
} catch (b) {
|
|
905
|
-
const
|
|
906
|
-
|
|
907
|
-
|
|
916
|
+
const E = W(
|
|
917
|
+
M,
|
|
918
|
+
R,
|
|
908
919
|
void 0,
|
|
909
920
|
b instanceof Error ? b.message : String(b)
|
|
910
921
|
);
|
|
911
|
-
O.push(
|
|
922
|
+
O.push(E), S.push(E);
|
|
912
923
|
}
|
|
913
924
|
}
|
|
914
925
|
if (o.push(I.status.message), O.length > 0 && o.push({
|
|
@@ -917,33 +928,33 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
917
928
|
parts: O,
|
|
918
929
|
messageId: _()
|
|
919
930
|
}), $) {
|
|
920
|
-
const
|
|
931
|
+
const C = ye(o), M = X(
|
|
921
932
|
[],
|
|
922
933
|
// Empty array - tool results are already in historyDataParts
|
|
923
|
-
|
|
934
|
+
C
|
|
924
935
|
);
|
|
925
936
|
yield {
|
|
926
937
|
id: I.id,
|
|
927
938
|
status: {
|
|
928
939
|
state: "working",
|
|
929
|
-
message:
|
|
940
|
+
message: M
|
|
930
941
|
},
|
|
931
942
|
final: !1,
|
|
932
943
|
text: ""
|
|
933
944
|
};
|
|
934
|
-
const
|
|
945
|
+
const R = await Ie(
|
|
935
946
|
I.id,
|
|
936
|
-
|
|
947
|
+
M,
|
|
937
948
|
a,
|
|
938
|
-
t,
|
|
939
949
|
s,
|
|
950
|
+
t,
|
|
940
951
|
n,
|
|
941
952
|
c,
|
|
942
953
|
l,
|
|
943
954
|
o
|
|
944
955
|
);
|
|
945
956
|
let k = null;
|
|
946
|
-
for await (const U of
|
|
957
|
+
for await (const U of R)
|
|
947
958
|
U.final ? k = U : yield U;
|
|
948
959
|
if (!k)
|
|
949
960
|
throw new Error(
|
|
@@ -951,7 +962,7 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
951
962
|
);
|
|
952
963
|
let b = (g = k.status) != null && g.message ? B(
|
|
953
964
|
k.status.message
|
|
954
|
-
) : [],
|
|
965
|
+
) : [], E = k;
|
|
955
966
|
if (b.length > 0)
|
|
956
967
|
for (yield {
|
|
957
968
|
...k,
|
|
@@ -963,19 +974,19 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
963
974
|
}
|
|
964
975
|
)
|
|
965
976
|
}; b.length > 0; ) {
|
|
966
|
-
(y =
|
|
967
|
-
|
|
977
|
+
(y = E.status) != null && y.message && o.push(
|
|
978
|
+
E.status.message
|
|
968
979
|
);
|
|
969
980
|
const {
|
|
970
981
|
results: U,
|
|
971
982
|
shouldReturnToAgent: D
|
|
972
|
-
} = await
|
|
983
|
+
} = await Oe(
|
|
973
984
|
b,
|
|
974
|
-
|
|
975
|
-
(f = (x =
|
|
985
|
+
s,
|
|
986
|
+
(f = (x = E.status) == null ? void 0 : x.message) == null ? void 0 : f.messageId
|
|
976
987
|
);
|
|
977
988
|
if (U.length > 0 && (yield {
|
|
978
|
-
id:
|
|
989
|
+
id: E.id,
|
|
979
990
|
status: {
|
|
980
991
|
state: "working",
|
|
981
992
|
message: {
|
|
@@ -989,17 +1000,17 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
989
1000
|
final: !1,
|
|
990
1001
|
text: ""
|
|
991
1002
|
}), D) {
|
|
992
|
-
const j = r ?
|
|
1003
|
+
const j = r ? ye(
|
|
993
1004
|
o
|
|
994
1005
|
) : [], N = X(
|
|
995
1006
|
U,
|
|
996
1007
|
j
|
|
997
|
-
), J = await
|
|
998
|
-
|
|
1008
|
+
), J = await Ie(
|
|
1009
|
+
E.id,
|
|
999
1010
|
N,
|
|
1000
1011
|
a,
|
|
1001
|
-
t,
|
|
1002
1012
|
s,
|
|
1013
|
+
t,
|
|
1003
1014
|
n,
|
|
1004
1015
|
c,
|
|
1005
1016
|
l,
|
|
@@ -1012,14 +1023,14 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1012
1023
|
throw new Error(
|
|
1013
1024
|
"Continue task stream ended without final result"
|
|
1014
1025
|
);
|
|
1015
|
-
|
|
1016
|
-
|
|
1026
|
+
E = H, b = (i = E.status) != null && i.message ? B(
|
|
1027
|
+
E.status.message
|
|
1017
1028
|
) : [], b.length > 0 && (yield {
|
|
1018
|
-
id:
|
|
1019
|
-
status:
|
|
1029
|
+
id: E.id,
|
|
1030
|
+
status: E.status,
|
|
1020
1031
|
final: !1,
|
|
1021
1032
|
text: F(
|
|
1022
|
-
((T =
|
|
1033
|
+
((T = E.status) == null ? void 0 : T.message) || {
|
|
1023
1034
|
parts: [],
|
|
1024
1035
|
messageId: _()
|
|
1025
1036
|
}
|
|
@@ -1029,39 +1040,39 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1029
1040
|
break;
|
|
1030
1041
|
}
|
|
1031
1042
|
yield {
|
|
1032
|
-
...
|
|
1043
|
+
...E,
|
|
1033
1044
|
final: !0,
|
|
1034
1045
|
text: F(
|
|
1035
|
-
((
|
|
1046
|
+
((A = E.status) == null ? void 0 : A.message) || {
|
|
1036
1047
|
parts: [],
|
|
1037
1048
|
messageId: _()
|
|
1038
1049
|
}
|
|
1039
1050
|
)
|
|
1040
1051
|
};
|
|
1041
1052
|
} else {
|
|
1042
|
-
const
|
|
1053
|
+
const C = {
|
|
1043
1054
|
...I.status.message,
|
|
1044
1055
|
parts: S
|
|
1045
|
-
},
|
|
1056
|
+
}, M = {
|
|
1046
1057
|
...I,
|
|
1047
1058
|
status: {
|
|
1048
1059
|
...I.status,
|
|
1049
|
-
message:
|
|
1060
|
+
message: C
|
|
1050
1061
|
},
|
|
1051
1062
|
final: p.length === 0,
|
|
1052
1063
|
// Only final if no agent messages to follow
|
|
1053
|
-
text: F(
|
|
1064
|
+
text: F(C)
|
|
1054
1065
|
};
|
|
1055
|
-
if (yield
|
|
1056
|
-
const
|
|
1066
|
+
if (yield M, p.length > 0) {
|
|
1067
|
+
const R = p.map((b) => F(b)).join(" "), k = G(R);
|
|
1057
1068
|
yield {
|
|
1058
|
-
id:
|
|
1069
|
+
id: M.id,
|
|
1059
1070
|
status: {
|
|
1060
1071
|
state: "completed",
|
|
1061
1072
|
message: k
|
|
1062
1073
|
},
|
|
1063
1074
|
final: !0,
|
|
1064
|
-
text:
|
|
1075
|
+
text: R
|
|
1065
1076
|
};
|
|
1066
1077
|
}
|
|
1067
1078
|
}
|
|
@@ -1069,19 +1080,19 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1069
1080
|
}
|
|
1070
1081
|
}
|
|
1071
1082
|
}
|
|
1072
|
-
function
|
|
1083
|
+
function rt(e) {
|
|
1073
1084
|
const {
|
|
1074
|
-
agentId:
|
|
1075
|
-
agentUrl:
|
|
1085
|
+
agentId: s,
|
|
1086
|
+
agentUrl: t,
|
|
1076
1087
|
authProvider: a,
|
|
1077
1088
|
defaultSessionId: n,
|
|
1078
|
-
timeout: r =
|
|
1089
|
+
timeout: r = st,
|
|
1079
1090
|
toolProvider: o,
|
|
1080
1091
|
contextProvider: c,
|
|
1081
1092
|
enableStreaming: l = !1
|
|
1082
1093
|
} = e, d = {
|
|
1083
|
-
agentId:
|
|
1084
|
-
agentUrl:
|
|
1094
|
+
agentId: s,
|
|
1095
|
+
agentUrl: t,
|
|
1085
1096
|
authProvider: a,
|
|
1086
1097
|
timeout: r
|
|
1087
1098
|
};
|
|
@@ -1098,50 +1109,50 @@ function ot(e) {
|
|
|
1098
1109
|
c,
|
|
1099
1110
|
m
|
|
1100
1111
|
);
|
|
1101
|
-
let y = await
|
|
1112
|
+
let y = await Ee(
|
|
1102
1113
|
h,
|
|
1103
1114
|
d,
|
|
1104
1115
|
{ abortSignal: w }
|
|
1105
1116
|
);
|
|
1106
1117
|
const x = [], f = [];
|
|
1107
1118
|
for (; y.status.message && o; ) {
|
|
1108
|
-
const
|
|
1119
|
+
const A = B(
|
|
1109
1120
|
y.status.message
|
|
1110
1121
|
);
|
|
1111
|
-
if (
|
|
1122
|
+
if (A.length === 0)
|
|
1112
1123
|
break;
|
|
1113
|
-
x.push(...
|
|
1124
|
+
x.push(...A);
|
|
1114
1125
|
const I = [];
|
|
1115
1126
|
let P = !1;
|
|
1116
|
-
for (const O of
|
|
1127
|
+
for (const O of A) {
|
|
1117
1128
|
const {
|
|
1118
1129
|
toolCallId: $,
|
|
1119
1130
|
toolId: S,
|
|
1120
1131
|
arguments: p
|
|
1121
1132
|
} = O.data;
|
|
1122
1133
|
try {
|
|
1123
|
-
const
|
|
1134
|
+
const C = await Z(
|
|
1124
1135
|
o,
|
|
1125
1136
|
S,
|
|
1126
1137
|
p
|
|
1127
|
-
), { result:
|
|
1128
|
-
|
|
1138
|
+
), { result: M, returnToAgent: R, agentMessage: k } = de(C);
|
|
1139
|
+
R && (P = !0), k && f.push(
|
|
1129
1140
|
G(k)
|
|
1130
1141
|
);
|
|
1131
1142
|
const b = W(
|
|
1132
1143
|
$,
|
|
1133
1144
|
S,
|
|
1134
|
-
|
|
1145
|
+
M
|
|
1135
1146
|
);
|
|
1136
1147
|
I.push(b), x.push(b);
|
|
1137
|
-
} catch (
|
|
1138
|
-
const
|
|
1148
|
+
} catch (C) {
|
|
1149
|
+
const M = W(
|
|
1139
1150
|
$,
|
|
1140
1151
|
S,
|
|
1141
1152
|
void 0,
|
|
1142
|
-
|
|
1153
|
+
C instanceof Error ? C.message : String(C)
|
|
1143
1154
|
);
|
|
1144
|
-
I.push(
|
|
1155
|
+
I.push(M), x.push(M);
|
|
1145
1156
|
}
|
|
1146
1157
|
}
|
|
1147
1158
|
if (g.push(y.status.message), P) {
|
|
@@ -1159,7 +1170,7 @@ function ot(e) {
|
|
|
1159
1170
|
break;
|
|
1160
1171
|
}
|
|
1161
1172
|
if (x.length > 0 && (i = y.status) != null && i.message) {
|
|
1162
|
-
const
|
|
1173
|
+
const A = {
|
|
1163
1174
|
...y.status.message,
|
|
1164
1175
|
parts: x
|
|
1165
1176
|
};
|
|
@@ -1167,17 +1178,17 @@ function ot(e) {
|
|
|
1167
1178
|
...y,
|
|
1168
1179
|
status: {
|
|
1169
1180
|
...y.status,
|
|
1170
|
-
message:
|
|
1181
|
+
message: A
|
|
1171
1182
|
}
|
|
1172
1183
|
};
|
|
1173
1184
|
}
|
|
1174
1185
|
if (f.length > 0) {
|
|
1175
|
-
const
|
|
1186
|
+
const A = f.map((P) => F(P)).join(" "), I = G(A);
|
|
1176
1187
|
return {
|
|
1177
1188
|
...y,
|
|
1178
1189
|
// Keep the enhanced message with tool results
|
|
1179
1190
|
// The agent message will be handled separately by the caller
|
|
1180
|
-
text:
|
|
1191
|
+
text: A,
|
|
1181
1192
|
agentMessage: I
|
|
1182
1193
|
// Add this for the caller to handle
|
|
1183
1194
|
};
|
|
@@ -1210,7 +1221,7 @@ function ot(e) {
|
|
|
1210
1221
|
o,
|
|
1211
1222
|
c,
|
|
1212
1223
|
h
|
|
1213
|
-
), i =
|
|
1224
|
+
), i = Pe(
|
|
1214
1225
|
f,
|
|
1215
1226
|
d,
|
|
1216
1227
|
{
|
|
@@ -1220,7 +1231,7 @@ function ot(e) {
|
|
|
1220
1231
|
abortSignal: m
|
|
1221
1232
|
}
|
|
1222
1233
|
);
|
|
1223
|
-
yield*
|
|
1234
|
+
yield* _e(
|
|
1224
1235
|
i,
|
|
1225
1236
|
o,
|
|
1226
1237
|
c,
|
|
@@ -1253,12 +1264,12 @@ function ot(e) {
|
|
|
1253
1264
|
);
|
|
1254
1265
|
if (f.length === 0)
|
|
1255
1266
|
break;
|
|
1256
|
-
const { results: i, shouldReturnToAgent: T } = await
|
|
1267
|
+
const { results: i, shouldReturnToAgent: T } = await Oe(f, o);
|
|
1257
1268
|
if (T) {
|
|
1258
|
-
const
|
|
1269
|
+
const A = X(i);
|
|
1259
1270
|
y = await ae(
|
|
1260
1271
|
y.id,
|
|
1261
|
-
|
|
1272
|
+
A,
|
|
1262
1273
|
d,
|
|
1263
1274
|
o,
|
|
1264
1275
|
c,
|
|
@@ -1285,18 +1296,18 @@ function ot(e) {
|
|
|
1285
1296
|
}
|
|
1286
1297
|
};
|
|
1287
1298
|
}
|
|
1288
|
-
function
|
|
1289
|
-
const
|
|
1299
|
+
function it(e) {
|
|
1300
|
+
const s = [];
|
|
1290
1301
|
if (e.content) {
|
|
1291
1302
|
const r = {
|
|
1292
1303
|
type: "text",
|
|
1293
1304
|
text: e.content
|
|
1294
1305
|
};
|
|
1295
|
-
|
|
1306
|
+
s.push(r);
|
|
1296
1307
|
}
|
|
1297
|
-
const
|
|
1298
|
-
if (
|
|
1299
|
-
for (const r of
|
|
1308
|
+
const t = e.context;
|
|
1309
|
+
if (t && !Array.isArray(t) && Array.isArray(t.file_parts)) {
|
|
1310
|
+
for (const r of t.file_parts)
|
|
1300
1311
|
if (r != null && r.uri) {
|
|
1301
1312
|
const o = {
|
|
1302
1313
|
type: "file",
|
|
@@ -1307,7 +1318,7 @@ function rt(e) {
|
|
|
1307
1318
|
// Pass attachment ID in metadata if available
|
|
1308
1319
|
metadata: r.id ? { id: r.id } : void 0
|
|
1309
1320
|
};
|
|
1310
|
-
|
|
1321
|
+
s.push(o);
|
|
1311
1322
|
}
|
|
1312
1323
|
}
|
|
1313
1324
|
const a = e.role === "user" ? "user" : "agent", n = e.ts ? e.ts * 1e3 : (/* @__PURE__ */ new Date(
|
|
@@ -1316,7 +1327,7 @@ function rt(e) {
|
|
|
1316
1327
|
return {
|
|
1317
1328
|
role: a,
|
|
1318
1329
|
kind: "message",
|
|
1319
|
-
parts:
|
|
1330
|
+
parts: s,
|
|
1320
1331
|
messageId: _(),
|
|
1321
1332
|
metadata: {
|
|
1322
1333
|
timestamp: n,
|
|
@@ -1325,42 +1336,42 @@ function rt(e) {
|
|
|
1325
1336
|
}
|
|
1326
1337
|
};
|
|
1327
1338
|
}
|
|
1328
|
-
function
|
|
1339
|
+
function lt(e) {
|
|
1329
1340
|
var n, r, o, c, l, d;
|
|
1330
|
-
const
|
|
1341
|
+
const t = e.messages.filter(
|
|
1331
1342
|
(u) => u.role !== "tool_call" && u.role !== "tool_result"
|
|
1332
|
-
).map(
|
|
1343
|
+
).map(it), a = {
|
|
1333
1344
|
currentPage: ((n = e.metadata) == null ? void 0 : n.current_page) ?? 1,
|
|
1334
1345
|
itemsPerPage: ((r = e.metadata) == null ? void 0 : r.items_per_page) ?? 10,
|
|
1335
1346
|
totalPages: ((o = e.metadata) == null ? void 0 : o.total_pages) ?? 1,
|
|
1336
|
-
totalMessages: ((c = e.metadata) == null ? void 0 : c.total_messages) ??
|
|
1347
|
+
totalMessages: ((c = e.metadata) == null ? void 0 : c.total_messages) ?? t.length,
|
|
1337
1348
|
hasMore: (((l = e.metadata) == null ? void 0 : l.current_page) ?? 1) < (((d = e.metadata) == null ? void 0 : d.total_pages) ?? 1)
|
|
1338
1349
|
};
|
|
1339
1350
|
return {
|
|
1340
|
-
messages:
|
|
1351
|
+
messages: t,
|
|
1341
1352
|
pagination: a,
|
|
1342
1353
|
chatId: e.chat_id,
|
|
1343
1354
|
sessionId: e.session_id
|
|
1344
1355
|
};
|
|
1345
1356
|
}
|
|
1346
1357
|
class V extends Error {
|
|
1347
|
-
constructor(
|
|
1348
|
-
super(
|
|
1358
|
+
constructor(s, t, a) {
|
|
1359
|
+
super(s), this.statusCode = t, this.details = a, this.name = "ServerConversationError";
|
|
1349
1360
|
}
|
|
1350
1361
|
}
|
|
1351
1362
|
const fe = "https://public-api.wordpress.com";
|
|
1352
|
-
async function le(e,
|
|
1353
|
-
const { botId: n, apiBaseUrl: r = fe, authProvider: o } =
|
|
1363
|
+
async function le(e, s, t = 1, a = 50) {
|
|
1364
|
+
const { botId: n, apiBaseUrl: r = fe, authProvider: o } = s;
|
|
1354
1365
|
if (!e || !n)
|
|
1355
1366
|
throw new Error(
|
|
1356
1367
|
"chatId and botId are required to load conversation from server"
|
|
1357
1368
|
);
|
|
1358
|
-
const c = Math.max(1, Math.min(
|
|
1369
|
+
const c = Math.max(1, Math.min(t, 100)), l = Math.max(1, Math.min(a, 100)), d = new URL(
|
|
1359
1370
|
`${r}/wpcom/v2/odie/chat/${encodeURIComponent(
|
|
1360
1371
|
n
|
|
1361
1372
|
)}/${encodeURIComponent(e)}`
|
|
1362
1373
|
);
|
|
1363
|
-
d.searchParams.set("page_number", c.toString()), d.searchParams.set("items_per_page", l.toString()),
|
|
1374
|
+
d.searchParams.set("page_number", c.toString()), d.searchParams.set("items_per_page", l.toString()), v(
|
|
1364
1375
|
"Loading conversation from server: %s (page %d)",
|
|
1365
1376
|
e,
|
|
1366
1377
|
c
|
|
@@ -1390,10 +1401,10 @@ async function le(e, t, s = 1, a = 50) {
|
|
|
1390
1401
|
w.status,
|
|
1391
1402
|
h
|
|
1392
1403
|
);
|
|
1393
|
-
throw
|
|
1404
|
+
throw v("Failed to load conversation from server: %O", x), x;
|
|
1394
1405
|
}
|
|
1395
|
-
const m = await w.json(), g =
|
|
1396
|
-
return
|
|
1406
|
+
const m = await w.json(), g = lt(m);
|
|
1407
|
+
return v(
|
|
1397
1408
|
"Loaded %d messages from server (page %d/%d)",
|
|
1398
1409
|
g.messages.length,
|
|
1399
1410
|
g.pagination.currentPage,
|
|
@@ -1407,16 +1418,16 @@ async function le(e, t, s = 1, a = 50) {
|
|
|
1407
1418
|
void 0,
|
|
1408
1419
|
u
|
|
1409
1420
|
);
|
|
1410
|
-
throw
|
|
1421
|
+
throw v("Network error loading conversation: %O", u), w;
|
|
1411
1422
|
}
|
|
1412
1423
|
}
|
|
1413
|
-
async function
|
|
1414
|
-
const { apiBaseUrl:
|
|
1415
|
-
`${
|
|
1424
|
+
async function Jt(e, s) {
|
|
1425
|
+
const { apiBaseUrl: t = fe, authProvider: a } = s, n = new URL(
|
|
1426
|
+
`${t}/wpcom/v2/odie/conversations/${encodeURIComponent(
|
|
1416
1427
|
e
|
|
1417
1428
|
)}`
|
|
1418
1429
|
);
|
|
1419
|
-
|
|
1430
|
+
v("Listing conversations from server for bot: %s", e);
|
|
1420
1431
|
try {
|
|
1421
1432
|
const r = {
|
|
1422
1433
|
"Content-Type": "application/json"
|
|
@@ -1435,10 +1446,10 @@ async function Dt(e, t) {
|
|
|
1435
1446
|
o.status,
|
|
1436
1447
|
l
|
|
1437
1448
|
);
|
|
1438
|
-
throw
|
|
1449
|
+
throw v("Failed to list conversations: %O", u), u;
|
|
1439
1450
|
}
|
|
1440
1451
|
const c = await o.json();
|
|
1441
|
-
return
|
|
1452
|
+
return v("Loaded %d conversations from server", c.length), c;
|
|
1442
1453
|
} catch (r) {
|
|
1443
1454
|
if (r instanceof V)
|
|
1444
1455
|
throw r;
|
|
@@ -1447,19 +1458,19 @@ async function Dt(e, t) {
|
|
|
1447
1458
|
void 0,
|
|
1448
1459
|
r
|
|
1449
1460
|
);
|
|
1450
|
-
throw
|
|
1461
|
+
throw v("Network error listing conversations: %O", r), o;
|
|
1451
1462
|
}
|
|
1452
1463
|
}
|
|
1453
|
-
async function
|
|
1454
|
-
const a = await le(e,
|
|
1464
|
+
async function Lt(e, s, t = 10) {
|
|
1465
|
+
const a = await le(e, s, 1, 50);
|
|
1455
1466
|
if (!a.pagination.hasMore)
|
|
1456
1467
|
return a;
|
|
1457
1468
|
const n = Math.min(
|
|
1458
1469
|
a.pagination.totalPages,
|
|
1459
|
-
|
|
1470
|
+
t
|
|
1460
1471
|
), r = [...a.messages], o = [];
|
|
1461
1472
|
for (let c = 2; c <= n; c++)
|
|
1462
|
-
o.push(le(e,
|
|
1473
|
+
o.push(le(e, s, c, 50));
|
|
1463
1474
|
try {
|
|
1464
1475
|
const c = await Promise.all(o);
|
|
1465
1476
|
for (const l of c)
|
|
@@ -1474,7 +1485,7 @@ async function Jt(e, t, s = 10) {
|
|
|
1474
1485
|
chatId: a.chatId
|
|
1475
1486
|
};
|
|
1476
1487
|
} catch (c) {
|
|
1477
|
-
return
|
|
1488
|
+
return v("Failed to load all pages: %O", c), {
|
|
1478
1489
|
messages: r,
|
|
1479
1490
|
pagination: a.pagination,
|
|
1480
1491
|
chatId: a.chatId
|
|
@@ -1482,12 +1493,12 @@ async function Jt(e, t, s = 10) {
|
|
|
1482
1493
|
}
|
|
1483
1494
|
}
|
|
1484
1495
|
const me = "a8c_agenttic_conversation_history";
|
|
1485
|
-
function
|
|
1496
|
+
function ct(e) {
|
|
1486
1497
|
var w, m;
|
|
1487
|
-
const
|
|
1498
|
+
const s = e.parts.filter(
|
|
1488
1499
|
(g) => g.type === "text"
|
|
1489
|
-
),
|
|
1490
|
-
`), a =
|
|
1500
|
+
), t = s.map((g) => g.text).join(`
|
|
1501
|
+
`), a = s.some(
|
|
1491
1502
|
(g) => {
|
|
1492
1503
|
var h;
|
|
1493
1504
|
return ((h = g.metadata) == null ? void 0 : h.contentType) === "context";
|
|
@@ -1511,7 +1522,7 @@ function lt(e) {
|
|
|
1511
1522
|
})), l = n.length > 0 || r.length > 0 ? "agent" : e.role, d = ((w = e.metadata) == null ? void 0 : w.timestamp) ?? Date.now(), u = ((m = e.metadata) == null ? void 0 : m.archived) ?? void 0;
|
|
1512
1523
|
return {
|
|
1513
1524
|
role: l,
|
|
1514
|
-
content:
|
|
1525
|
+
content: t || "(No text content)",
|
|
1515
1526
|
timestamp: d,
|
|
1516
1527
|
...u !== void 0 && { archived: u },
|
|
1517
1528
|
...a && { contentType: a },
|
|
@@ -1520,9 +1531,9 @@ function lt(e) {
|
|
|
1520
1531
|
...r.length > 0 && { toolResults: r }
|
|
1521
1532
|
};
|
|
1522
1533
|
}
|
|
1523
|
-
function
|
|
1524
|
-
const
|
|
1525
|
-
if (e.content && e.content !== "(No text content)" &&
|
|
1534
|
+
function ut(e) {
|
|
1535
|
+
const s = [];
|
|
1536
|
+
if (e.content && e.content !== "(No text content)" && s.push({
|
|
1526
1537
|
type: "text",
|
|
1527
1538
|
text: e.content,
|
|
1528
1539
|
...e.contentType && {
|
|
@@ -1531,39 +1542,39 @@ function ct(e) {
|
|
|
1531
1542
|
}
|
|
1532
1543
|
}
|
|
1533
1544
|
}), e.files)
|
|
1534
|
-
for (const
|
|
1535
|
-
|
|
1545
|
+
for (const t of e.files)
|
|
1546
|
+
s.push({
|
|
1536
1547
|
type: "file",
|
|
1537
1548
|
file: {
|
|
1538
|
-
name:
|
|
1539
|
-
mimeType:
|
|
1540
|
-
uri:
|
|
1549
|
+
name: t.name,
|
|
1550
|
+
mimeType: t.mimeType,
|
|
1551
|
+
uri: t.uri
|
|
1541
1552
|
}
|
|
1542
1553
|
});
|
|
1543
1554
|
if (e.toolCalls)
|
|
1544
|
-
for (const
|
|
1545
|
-
|
|
1555
|
+
for (const t of e.toolCalls)
|
|
1556
|
+
s.push({
|
|
1546
1557
|
type: "data",
|
|
1547
1558
|
data: {
|
|
1548
|
-
toolCallId:
|
|
1549
|
-
toolId:
|
|
1550
|
-
arguments:
|
|
1559
|
+
toolCallId: t.toolCallId,
|
|
1560
|
+
toolId: t.toolId,
|
|
1561
|
+
arguments: t.arguments
|
|
1551
1562
|
}
|
|
1552
1563
|
});
|
|
1553
1564
|
if (e.toolResults)
|
|
1554
|
-
for (const
|
|
1555
|
-
|
|
1565
|
+
for (const t of e.toolResults)
|
|
1566
|
+
s.push({
|
|
1556
1567
|
type: "data",
|
|
1557
1568
|
data: {
|
|
1558
|
-
toolCallId:
|
|
1559
|
-
result:
|
|
1560
|
-
...
|
|
1569
|
+
toolCallId: t.toolCallId,
|
|
1570
|
+
result: t.result,
|
|
1571
|
+
...t.error && { error: t.error }
|
|
1561
1572
|
}
|
|
1562
1573
|
});
|
|
1563
1574
|
return {
|
|
1564
1575
|
role: e.role,
|
|
1565
1576
|
kind: "message",
|
|
1566
|
-
parts:
|
|
1577
|
+
parts: s,
|
|
1567
1578
|
messageId: _(),
|
|
1568
1579
|
metadata: {
|
|
1569
1580
|
timestamp: e.timestamp,
|
|
@@ -1574,10 +1585,10 @@ function ct(e) {
|
|
|
1574
1585
|
}
|
|
1575
1586
|
};
|
|
1576
1587
|
}
|
|
1577
|
-
const K = /* @__PURE__ */ new Map(),
|
|
1578
|
-
async function
|
|
1579
|
-
const a =
|
|
1580
|
-
if (K.set(a, [...
|
|
1588
|
+
const K = /* @__PURE__ */ new Map(), dt = 50;
|
|
1589
|
+
async function gt(e, s, t) {
|
|
1590
|
+
const a = t || e;
|
|
1591
|
+
if (K.set(a, [...s]), K.size > dt) {
|
|
1581
1592
|
const n = K.keys().next().value;
|
|
1582
1593
|
n && K.delete(n);
|
|
1583
1594
|
}
|
|
@@ -1585,7 +1596,7 @@ async function dt(e, t, s) {
|
|
|
1585
1596
|
try {
|
|
1586
1597
|
const n = {
|
|
1587
1598
|
storageKey: a,
|
|
1588
|
-
messages:
|
|
1599
|
+
messages: s.map(ct),
|
|
1589
1600
|
lastUpdated: Date.now()
|
|
1590
1601
|
};
|
|
1591
1602
|
sessionStorage.setItem(
|
|
@@ -1593,36 +1604,36 @@ async function dt(e, t, s) {
|
|
|
1593
1604
|
JSON.stringify(n)
|
|
1594
1605
|
);
|
|
1595
1606
|
} catch (n) {
|
|
1596
|
-
|
|
1607
|
+
v(
|
|
1597
1608
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1598
1609
|
a,
|
|
1599
1610
|
n
|
|
1600
1611
|
);
|
|
1601
1612
|
}
|
|
1602
1613
|
}
|
|
1603
|
-
async function
|
|
1604
|
-
return
|
|
1614
|
+
async function ft(e, s, t) {
|
|
1615
|
+
return t != null && t.odieBotId ? mt(e, t) : pt(
|
|
1605
1616
|
e,
|
|
1606
|
-
|
|
1617
|
+
s
|
|
1607
1618
|
);
|
|
1608
1619
|
}
|
|
1609
|
-
async function
|
|
1610
|
-
const { odieBotId:
|
|
1611
|
-
if (!
|
|
1620
|
+
async function mt(e, s) {
|
|
1621
|
+
const { odieBotId: t, authProvider: a } = s;
|
|
1622
|
+
if (!t)
|
|
1612
1623
|
throw new Error("odieBotId is required for server storage");
|
|
1613
1624
|
const n = fe;
|
|
1614
1625
|
try {
|
|
1615
1626
|
const o = await le(
|
|
1616
1627
|
e,
|
|
1617
1628
|
{
|
|
1618
|
-
botId:
|
|
1629
|
+
botId: t,
|
|
1619
1630
|
apiBaseUrl: n,
|
|
1620
1631
|
authProvider: a
|
|
1621
1632
|
},
|
|
1622
1633
|
1,
|
|
1623
1634
|
50
|
|
1624
1635
|
);
|
|
1625
|
-
return
|
|
1636
|
+
return v(
|
|
1626
1637
|
"Loaded conversation from server: %s (%d messages, page %d/%d)",
|
|
1627
1638
|
e,
|
|
1628
1639
|
o.messages.length,
|
|
@@ -1633,88 +1644,88 @@ async function ft(e, t) {
|
|
|
1633
1644
|
pagination: o.pagination
|
|
1634
1645
|
};
|
|
1635
1646
|
} catch (r) {
|
|
1636
|
-
throw
|
|
1647
|
+
throw v("Failed to load conversation from server: %O", r), r;
|
|
1637
1648
|
}
|
|
1638
1649
|
}
|
|
1639
|
-
async function
|
|
1640
|
-
const
|
|
1641
|
-
if (K.has(
|
|
1650
|
+
async function pt(e, s) {
|
|
1651
|
+
const t = s || e;
|
|
1652
|
+
if (K.has(t))
|
|
1642
1653
|
return {
|
|
1643
|
-
messages: [...K.get(
|
|
1654
|
+
messages: [...K.get(t)]
|
|
1644
1655
|
};
|
|
1645
1656
|
if (typeof sessionStorage > "u")
|
|
1646
1657
|
return { messages: [] };
|
|
1647
1658
|
try {
|
|
1648
1659
|
const a = sessionStorage.getItem(
|
|
1649
|
-
`${me}_${
|
|
1660
|
+
`${me}_${t}`
|
|
1650
1661
|
);
|
|
1651
1662
|
if (a) {
|
|
1652
|
-
const r = JSON.parse(a).messages.map(
|
|
1653
|
-
return K.set(
|
|
1663
|
+
const r = JSON.parse(a).messages.map(ut);
|
|
1664
|
+
return K.set(t, r), { messages: [...r] };
|
|
1654
1665
|
}
|
|
1655
1666
|
} catch (a) {
|
|
1656
|
-
|
|
1667
|
+
v(
|
|
1657
1668
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1658
|
-
|
|
1669
|
+
t,
|
|
1659
1670
|
a
|
|
1660
1671
|
);
|
|
1661
1672
|
}
|
|
1662
1673
|
return { messages: [] };
|
|
1663
1674
|
}
|
|
1664
|
-
async function
|
|
1665
|
-
const
|
|
1666
|
-
if (K.delete(
|
|
1675
|
+
async function ht(e, s) {
|
|
1676
|
+
const t = s || e;
|
|
1677
|
+
if (K.delete(t), !(typeof sessionStorage > "u"))
|
|
1667
1678
|
try {
|
|
1668
|
-
sessionStorage.removeItem(`${me}_${
|
|
1679
|
+
sessionStorage.removeItem(`${me}_${t}`);
|
|
1669
1680
|
} catch (a) {
|
|
1670
|
-
|
|
1681
|
+
v(
|
|
1671
1682
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1672
|
-
|
|
1683
|
+
t,
|
|
1673
1684
|
a
|
|
1674
1685
|
);
|
|
1675
1686
|
}
|
|
1676
1687
|
}
|
|
1677
1688
|
function z(e) {
|
|
1678
|
-
const
|
|
1689
|
+
const s = e.parts.filter((t) => t.type === "text" ? !0 : t.type === "data" ? "role" in t.data && "text" in t.data ? !1 : "toolCallId" in t.data && "arguments" in t.data || "toolCallId" in t.data && "result" in t.data : !0);
|
|
1679
1690
|
return {
|
|
1680
1691
|
...e,
|
|
1681
|
-
parts:
|
|
1692
|
+
parts: s,
|
|
1682
1693
|
// Preserve metadata if it exists, otherwise add timestamp
|
|
1683
1694
|
metadata: e.metadata || {
|
|
1684
1695
|
timestamp: Date.now()
|
|
1685
1696
|
}
|
|
1686
1697
|
};
|
|
1687
1698
|
}
|
|
1688
|
-
function
|
|
1689
|
-
const
|
|
1690
|
-
for (const
|
|
1691
|
-
for (const a of
|
|
1699
|
+
function yt(e) {
|
|
1700
|
+
const s = [];
|
|
1701
|
+
for (const t of e)
|
|
1702
|
+
for (const a of t.parts)
|
|
1692
1703
|
if (a.type === "text")
|
|
1693
|
-
|
|
1704
|
+
s.push({
|
|
1694
1705
|
type: "data",
|
|
1695
1706
|
data: {
|
|
1696
|
-
role:
|
|
1707
|
+
role: t.role,
|
|
1697
1708
|
text: a.text
|
|
1698
1709
|
}
|
|
1699
1710
|
});
|
|
1700
1711
|
else if (a.type === "file")
|
|
1701
|
-
|
|
1712
|
+
s.push(a);
|
|
1702
1713
|
else if (a.type === "data") {
|
|
1703
1714
|
if ("role" in a.data && "text" in a.data)
|
|
1704
1715
|
continue;
|
|
1705
1716
|
if ("toolCallId" in a.data && "arguments" in a.data) {
|
|
1706
|
-
|
|
1717
|
+
s.push(a);
|
|
1707
1718
|
continue;
|
|
1708
1719
|
}
|
|
1709
1720
|
if ("toolCallId" in a.data && "result" in a.data) {
|
|
1710
|
-
|
|
1721
|
+
s.push(a);
|
|
1711
1722
|
continue;
|
|
1712
1723
|
}
|
|
1713
1724
|
}
|
|
1714
|
-
return
|
|
1725
|
+
return s;
|
|
1715
1726
|
}
|
|
1716
|
-
function
|
|
1717
|
-
const a =
|
|
1727
|
+
function we(e, s = [], t = []) {
|
|
1728
|
+
const a = yt(s), n = t.map((r) => {
|
|
1718
1729
|
const o = typeof r == "string" ? r : r.url, c = typeof r == "object" ? r.metadata : void 0, l = (c == null ? void 0 : c.fileType) || "image/jpeg";
|
|
1719
1730
|
return {
|
|
1720
1731
|
type: "file",
|
|
@@ -1743,102 +1754,102 @@ function Ie(e, t = [], s = []) {
|
|
|
1743
1754
|
}
|
|
1744
1755
|
};
|
|
1745
1756
|
}
|
|
1746
|
-
function
|
|
1757
|
+
function It(e) {
|
|
1747
1758
|
return e != null && e.parts ? e.parts.filter(
|
|
1748
|
-
(
|
|
1759
|
+
(s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
|
|
1749
1760
|
) : [];
|
|
1750
1761
|
}
|
|
1751
|
-
function ne(e,
|
|
1762
|
+
function ne(e, s) {
|
|
1752
1763
|
if (typeof localStorage > "u") {
|
|
1753
1764
|
L("localStorage not available, cannot update session ID");
|
|
1754
1765
|
return;
|
|
1755
1766
|
}
|
|
1756
1767
|
try {
|
|
1757
|
-
const
|
|
1758
|
-
if (
|
|
1759
|
-
const a = JSON.parse(
|
|
1760
|
-
a.sessionId =
|
|
1768
|
+
const t = localStorage.getItem(e);
|
|
1769
|
+
if (t) {
|
|
1770
|
+
const a = JSON.parse(t), n = a.sessionId;
|
|
1771
|
+
a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)), L(
|
|
1761
1772
|
"Updated localStorage[%s] session ID: %s -> %s",
|
|
1762
1773
|
e,
|
|
1763
1774
|
n,
|
|
1764
|
-
|
|
1775
|
+
s
|
|
1765
1776
|
);
|
|
1766
1777
|
} else {
|
|
1767
1778
|
const a = {
|
|
1768
|
-
sessionId:
|
|
1779
|
+
sessionId: s,
|
|
1769
1780
|
timestamp: Date.now()
|
|
1770
1781
|
};
|
|
1771
1782
|
localStorage.setItem(e, JSON.stringify(a)), L(
|
|
1772
1783
|
"Created new session in localStorage[%s]: %s",
|
|
1773
1784
|
e,
|
|
1774
|
-
|
|
1785
|
+
s
|
|
1775
1786
|
);
|
|
1776
1787
|
}
|
|
1777
|
-
} catch (
|
|
1788
|
+
} catch (t) {
|
|
1778
1789
|
L(
|
|
1779
1790
|
"Failed to update localStorage sessionId to %s: %O",
|
|
1780
|
-
|
|
1781
|
-
|
|
1791
|
+
s,
|
|
1792
|
+
t
|
|
1782
1793
|
);
|
|
1783
1794
|
}
|
|
1784
1795
|
}
|
|
1785
|
-
async function
|
|
1786
|
-
const
|
|
1787
|
-
for (const
|
|
1788
|
-
if (
|
|
1789
|
-
if (
|
|
1796
|
+
async function wt(e) {
|
|
1797
|
+
const s = [];
|
|
1798
|
+
for (const t of e)
|
|
1799
|
+
if (t.parts && Array.isArray(t.parts))
|
|
1800
|
+
if (t.parts.some(
|
|
1790
1801
|
(n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
|
|
1791
1802
|
)) {
|
|
1792
|
-
const n =
|
|
1793
|
-
|
|
1803
|
+
const n = ot(
|
|
1804
|
+
t.parts
|
|
1794
1805
|
);
|
|
1795
|
-
|
|
1796
|
-
...
|
|
1806
|
+
s.push({
|
|
1807
|
+
...t,
|
|
1797
1808
|
parts: n
|
|
1798
1809
|
});
|
|
1799
1810
|
} else
|
|
1800
|
-
|
|
1811
|
+
s.push(t);
|
|
1801
1812
|
else
|
|
1802
|
-
|
|
1803
|
-
return
|
|
1813
|
+
s.push(t);
|
|
1814
|
+
return nt(), s;
|
|
1804
1815
|
}
|
|
1805
|
-
function
|
|
1816
|
+
function Tt() {
|
|
1806
1817
|
const e = /* @__PURE__ */ new Map();
|
|
1807
|
-
async function t
|
|
1808
|
-
const n = e.get(
|
|
1818
|
+
async function s(t, a) {
|
|
1819
|
+
const n = e.get(t);
|
|
1809
1820
|
if (n != null && n.sessionId)
|
|
1810
1821
|
try {
|
|
1811
|
-
await
|
|
1822
|
+
await gt(
|
|
1812
1823
|
n.sessionId,
|
|
1813
1824
|
a,
|
|
1814
1825
|
n.conversationStorageKey
|
|
1815
1826
|
);
|
|
1816
1827
|
} catch (r) {
|
|
1817
1828
|
L(
|
|
1818
|
-
`Failed to persist conversation history for agent ${
|
|
1829
|
+
`Failed to persist conversation history for agent ${t}:`,
|
|
1819
1830
|
r
|
|
1820
1831
|
);
|
|
1821
1832
|
}
|
|
1822
1833
|
}
|
|
1823
1834
|
return {
|
|
1824
|
-
async createAgent(
|
|
1825
|
-
if (e.has(
|
|
1826
|
-
return e.get(
|
|
1827
|
-
const n =
|
|
1835
|
+
async createAgent(t, a) {
|
|
1836
|
+
if (e.has(t))
|
|
1837
|
+
return e.get(t).client;
|
|
1838
|
+
const n = rt(a), r = a.sessionId || null, o = a.conversationStorageKey, c = a.sessionIdStorageKey, l = {
|
|
1828
1839
|
odieBotId: a.odieBotId,
|
|
1829
1840
|
authProvider: a.authProvider
|
|
1830
1841
|
};
|
|
1831
1842
|
let d = [];
|
|
1832
1843
|
if (r)
|
|
1833
1844
|
try {
|
|
1834
|
-
d = (await
|
|
1845
|
+
d = (await ft(
|
|
1835
1846
|
r,
|
|
1836
1847
|
o,
|
|
1837
1848
|
l
|
|
1838
1849
|
)).messages;
|
|
1839
1850
|
} catch (w) {
|
|
1840
1851
|
L(
|
|
1841
|
-
`Failed to load conversation history for agent ${
|
|
1852
|
+
`Failed to load conversation history for agent ${t} with session ${r}:`,
|
|
1842
1853
|
w
|
|
1843
1854
|
);
|
|
1844
1855
|
}
|
|
@@ -1851,24 +1862,24 @@ function wt() {
|
|
|
1851
1862
|
conversationHistory: d,
|
|
1852
1863
|
currentAbortController: null
|
|
1853
1864
|
};
|
|
1854
|
-
return e.set(
|
|
1865
|
+
return e.set(t, u), n;
|
|
1855
1866
|
},
|
|
1856
|
-
getAgent(
|
|
1857
|
-
const a = e.get(
|
|
1867
|
+
getAgent(t) {
|
|
1868
|
+
const a = e.get(t);
|
|
1858
1869
|
return (a == null ? void 0 : a.client) || null;
|
|
1859
1870
|
},
|
|
1860
|
-
hasAgent(
|
|
1861
|
-
return e.has(
|
|
1871
|
+
hasAgent(t) {
|
|
1872
|
+
return e.has(t);
|
|
1862
1873
|
},
|
|
1863
|
-
removeAgent(
|
|
1864
|
-
return e.delete(
|
|
1874
|
+
removeAgent(t) {
|
|
1875
|
+
return e.delete(t);
|
|
1865
1876
|
},
|
|
1866
|
-
async sendMessage(
|
|
1877
|
+
async sendMessage(t, a, n = {}) {
|
|
1867
1878
|
var x;
|
|
1868
|
-
const r = e.get(
|
|
1879
|
+
const r = e.get(t);
|
|
1869
1880
|
if (!r)
|
|
1870
|
-
throw new Error(`Agent with key "${
|
|
1871
|
-
const { withHistory: o = !0, sessionId: c, ...l } = n, { client: d, conversationHistory: u } = r, w = n.message ||
|
|
1881
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
1882
|
+
const { withHistory: o = !0, sessionId: c, ...l } = n, { client: d, conversationHistory: u } = r, w = n.message || we(
|
|
1872
1883
|
a,
|
|
1873
1884
|
u,
|
|
1874
1885
|
n.imageUrls
|
|
@@ -1923,16 +1934,16 @@ function wt() {
|
|
|
1923
1934
|
f
|
|
1924
1935
|
];
|
|
1925
1936
|
}
|
|
1926
|
-
return r.conversationHistory = y, o && await
|
|
1927
|
-
|
|
1937
|
+
return r.conversationHistory = y, o && await s(
|
|
1938
|
+
t,
|
|
1928
1939
|
y
|
|
1929
1940
|
), m;
|
|
1930
1941
|
},
|
|
1931
|
-
async *sendMessageStream(
|
|
1932
|
-
var T,
|
|
1933
|
-
const r = e.get(
|
|
1942
|
+
async *sendMessageStream(t, a, n = {}) {
|
|
1943
|
+
var T, A, I, P, O, $;
|
|
1944
|
+
const r = e.get(t);
|
|
1934
1945
|
if (!r)
|
|
1935
|
-
throw new Error(`Agent with key "${
|
|
1946
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
1936
1947
|
const {
|
|
1937
1948
|
withHistory: o = !0,
|
|
1938
1949
|
abortSignal: c,
|
|
@@ -1947,14 +1958,14 @@ function wt() {
|
|
|
1947
1958
|
let h = [
|
|
1948
1959
|
...r.conversationHistory
|
|
1949
1960
|
], y = [];
|
|
1950
|
-
const x = await
|
|
1961
|
+
const x = await wt(
|
|
1951
1962
|
h
|
|
1952
1963
|
);
|
|
1953
|
-
r.conversationHistory = x, h = x, o && await
|
|
1954
|
-
|
|
1964
|
+
r.conversationHistory = x, h = x, o && await s(
|
|
1965
|
+
t,
|
|
1955
1966
|
x
|
|
1956
1967
|
);
|
|
1957
|
-
const f = n.message ||
|
|
1968
|
+
const f = n.message || we(
|
|
1958
1969
|
a,
|
|
1959
1970
|
x,
|
|
1960
1971
|
n.imageUrls
|
|
@@ -1962,9 +1973,9 @@ function wt() {
|
|
|
1962
1973
|
if (n.metadata && !n.message) {
|
|
1963
1974
|
const { contentType: S, ...p } = n.metadata;
|
|
1964
1975
|
if (S) {
|
|
1965
|
-
const
|
|
1966
|
-
|
|
1967
|
-
...
|
|
1976
|
+
const C = f.parts[f.parts.length - 1];
|
|
1977
|
+
C && C.type === "text" && (C.metadata = {
|
|
1978
|
+
...C.metadata,
|
|
1968
1979
|
contentType: S
|
|
1969
1980
|
});
|
|
1970
1981
|
}
|
|
@@ -1977,15 +1988,15 @@ function wt() {
|
|
|
1977
1988
|
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
1978
1989
|
const S = n.imageUrls.map(
|
|
1979
1990
|
(p) => {
|
|
1980
|
-
const
|
|
1991
|
+
const C = typeof p == "string" ? p : p.url, M = typeof p == "string" ? void 0 : p.metadata, R = (M == null ? void 0 : M.fileType) || "image/jpeg";
|
|
1981
1992
|
return {
|
|
1982
1993
|
type: "file",
|
|
1983
1994
|
file: {
|
|
1984
|
-
name: (
|
|
1985
|
-
mimeType:
|
|
1986
|
-
uri:
|
|
1995
|
+
name: (M == null ? void 0 : M.fileName) || "image",
|
|
1996
|
+
mimeType: R,
|
|
1997
|
+
uri: C
|
|
1987
1998
|
},
|
|
1988
|
-
metadata:
|
|
1999
|
+
metadata: M
|
|
1989
2000
|
};
|
|
1990
2001
|
}
|
|
1991
2002
|
);
|
|
@@ -1994,8 +2005,8 @@ function wt() {
|
|
|
1994
2005
|
h = [
|
|
1995
2006
|
...h,
|
|
1996
2007
|
i
|
|
1997
|
-
], r.conversationHistory = h, o && await
|
|
1998
|
-
|
|
2008
|
+
], r.conversationHistory = h, o && await s(
|
|
2009
|
+
t,
|
|
1999
2010
|
h
|
|
2000
2011
|
);
|
|
2001
2012
|
for await (const S of w.sendMessageStream({
|
|
@@ -2018,43 +2029,43 @@ function wt() {
|
|
|
2018
2029
|
S.sessionId
|
|
2019
2030
|
));
|
|
2020
2031
|
}
|
|
2021
|
-
if (((T = S.status) == null ? void 0 : T.state) === "input-required" && ((
|
|
2032
|
+
if (((T = S.status) == null ? void 0 : T.state) === "input-required" && ((A = S.status) != null && A.message)) {
|
|
2022
2033
|
y = B(
|
|
2023
2034
|
S.status.message
|
|
2024
2035
|
).map(
|
|
2025
|
-
(
|
|
2036
|
+
(M) => M.data.toolCallId
|
|
2026
2037
|
);
|
|
2027
|
-
const
|
|
2038
|
+
const C = z(
|
|
2028
2039
|
S.status.message
|
|
2029
2040
|
);
|
|
2030
2041
|
h = [
|
|
2031
2042
|
...h,
|
|
2032
|
-
|
|
2033
|
-
], r.conversationHistory = h, o && await
|
|
2034
|
-
|
|
2043
|
+
C
|
|
2044
|
+
], r.conversationHistory = h, o && await s(
|
|
2045
|
+
t,
|
|
2035
2046
|
h
|
|
2036
2047
|
);
|
|
2037
2048
|
}
|
|
2038
2049
|
if (((I = S.status) == null ? void 0 : I.state) === "working" && ((P = S.status) != null && P.message) && !S.final) {
|
|
2039
|
-
const
|
|
2050
|
+
const C = It(
|
|
2040
2051
|
S.status.message
|
|
2041
2052
|
).filter(
|
|
2042
|
-
(
|
|
2043
|
-
|
|
2053
|
+
(M) => y.includes(
|
|
2054
|
+
M.data.toolCallId
|
|
2044
2055
|
)
|
|
2045
2056
|
);
|
|
2046
|
-
if (
|
|
2047
|
-
const
|
|
2057
|
+
if (C.length > 0) {
|
|
2058
|
+
const M = {
|
|
2048
2059
|
role: "agent",
|
|
2049
2060
|
kind: "message",
|
|
2050
|
-
parts:
|
|
2061
|
+
parts: C,
|
|
2051
2062
|
messageId: _()
|
|
2052
2063
|
};
|
|
2053
2064
|
h = [
|
|
2054
2065
|
...h,
|
|
2055
|
-
z(
|
|
2056
|
-
], r.conversationHistory = h, o && await
|
|
2057
|
-
|
|
2066
|
+
z(M)
|
|
2067
|
+
], r.conversationHistory = h, o && await s(
|
|
2068
|
+
t,
|
|
2058
2069
|
h
|
|
2059
2070
|
);
|
|
2060
2071
|
}
|
|
@@ -2067,8 +2078,8 @@ function wt() {
|
|
|
2067
2078
|
), h = [
|
|
2068
2079
|
...h,
|
|
2069
2080
|
p
|
|
2070
|
-
], r.conversationHistory = h, o && await
|
|
2071
|
-
|
|
2081
|
+
], r.conversationHistory = h, o && await s(
|
|
2082
|
+
t,
|
|
2072
2083
|
h
|
|
2073
2084
|
));
|
|
2074
2085
|
}
|
|
@@ -2076,40 +2087,40 @@ function wt() {
|
|
|
2076
2087
|
}
|
|
2077
2088
|
r.currentAbortController = null;
|
|
2078
2089
|
},
|
|
2079
|
-
async resetConversation(
|
|
2080
|
-
const a = e.get(
|
|
2090
|
+
async resetConversation(t) {
|
|
2091
|
+
const a = e.get(t);
|
|
2081
2092
|
if (!a)
|
|
2082
|
-
throw new Error(`Agent with key "${
|
|
2083
|
-
a.conversationHistory = [], a.sessionId && await
|
|
2093
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2094
|
+
a.conversationHistory = [], a.sessionId && await ht(
|
|
2084
2095
|
a.sessionId,
|
|
2085
2096
|
a.conversationStorageKey
|
|
2086
2097
|
);
|
|
2087
2098
|
},
|
|
2088
|
-
async replaceMessages(
|
|
2089
|
-
const n = e.get(
|
|
2099
|
+
async replaceMessages(t, a) {
|
|
2100
|
+
const n = e.get(t);
|
|
2090
2101
|
if (!n)
|
|
2091
|
-
throw new Error(`Agent with key "${
|
|
2092
|
-
n.conversationHistory = [...a], n.sessionId && await t
|
|
2102
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2103
|
+
n.conversationHistory = [...a], n.sessionId && await s(t, a);
|
|
2093
2104
|
},
|
|
2094
|
-
getConversationHistory(
|
|
2095
|
-
const a = e.get(
|
|
2105
|
+
getConversationHistory(t) {
|
|
2106
|
+
const a = e.get(t);
|
|
2096
2107
|
if (!a)
|
|
2097
|
-
throw new Error(`Agent with key "${
|
|
2108
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2098
2109
|
return [...a.conversationHistory];
|
|
2099
2110
|
},
|
|
2100
|
-
updateSessionId(
|
|
2101
|
-
const n = e.get(
|
|
2111
|
+
updateSessionId(t, a) {
|
|
2112
|
+
const n = e.get(t);
|
|
2102
2113
|
if (!n)
|
|
2103
|
-
throw new Error(`Agent with key "${
|
|
2114
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2104
2115
|
n.sessionId = a, n.sessionIdStorageKey && ne(
|
|
2105
2116
|
n.sessionIdStorageKey,
|
|
2106
2117
|
a
|
|
2107
2118
|
);
|
|
2108
2119
|
},
|
|
2109
|
-
abortCurrentRequest(
|
|
2110
|
-
const a = e.get(
|
|
2120
|
+
abortCurrentRequest(t) {
|
|
2121
|
+
const a = e.get(t);
|
|
2111
2122
|
if (!a)
|
|
2112
|
-
throw new Error(`Agent with key "${
|
|
2123
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2113
2124
|
a.currentAbortController && (a.currentAbortController.abort(), a.currentAbortController = null);
|
|
2114
2125
|
},
|
|
2115
2126
|
clear() {
|
|
@@ -2117,14 +2128,14 @@ function wt() {
|
|
|
2117
2128
|
}
|
|
2118
2129
|
};
|
|
2119
2130
|
}
|
|
2120
|
-
const
|
|
2131
|
+
const St = Tt();
|
|
2121
2132
|
function Q() {
|
|
2122
|
-
return
|
|
2133
|
+
return St;
|
|
2123
2134
|
}
|
|
2124
|
-
function
|
|
2125
|
-
const [e,
|
|
2135
|
+
function Mt() {
|
|
2136
|
+
const [e, s] = Me([]), t = q(
|
|
2126
2137
|
(r) => {
|
|
2127
|
-
|
|
2138
|
+
s((o) => {
|
|
2128
2139
|
const c = o.findIndex(
|
|
2129
2140
|
(l) => l.id === r.id
|
|
2130
2141
|
);
|
|
@@ -2137,19 +2148,19 @@ function St() {
|
|
|
2137
2148
|
},
|
|
2138
2149
|
[]
|
|
2139
2150
|
), a = q((r) => {
|
|
2140
|
-
|
|
2151
|
+
s((o) => o.filter((c) => c.id !== r));
|
|
2141
2152
|
}, []), n = q(() => {
|
|
2142
|
-
|
|
2153
|
+
s([]);
|
|
2143
2154
|
}, []);
|
|
2144
2155
|
return {
|
|
2145
|
-
registerMessageActions:
|
|
2156
|
+
registerMessageActions: t,
|
|
2146
2157
|
unregisterMessageActions: a,
|
|
2147
2158
|
clearAllMessageActions: n,
|
|
2148
2159
|
registrations: e
|
|
2149
2160
|
};
|
|
2150
2161
|
}
|
|
2151
|
-
function vt(e,
|
|
2152
|
-
return
|
|
2162
|
+
function vt(e, s) {
|
|
2163
|
+
return s.flatMap((n) => typeof n.actions == "function" ? n.actions(e) : n.actions).filter((n) => !(n.condition && !n.condition(e))).map((n) => ({
|
|
2153
2164
|
id: n.id,
|
|
2154
2165
|
label: n.label,
|
|
2155
2166
|
icon: n.icon,
|
|
@@ -2160,13 +2171,13 @@ function vt(e, t) {
|
|
|
2160
2171
|
showLabel: n.showLabel
|
|
2161
2172
|
}));
|
|
2162
2173
|
}
|
|
2163
|
-
const oe = (e) => [...e].sort((
|
|
2174
|
+
const oe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ne = (e, s = "40%") => ({
|
|
2164
2175
|
type: "component",
|
|
2165
|
-
component: () =>
|
|
2176
|
+
component: () => qe.createElement("img", {
|
|
2166
2177
|
src: e,
|
|
2167
2178
|
alt: "Uploaded image",
|
|
2168
2179
|
style: {
|
|
2169
|
-
maxWidth:
|
|
2180
|
+
maxWidth: s,
|
|
2170
2181
|
height: "auto",
|
|
2171
2182
|
borderRadius: "8px",
|
|
2172
2183
|
marginTop: "8px",
|
|
@@ -2174,7 +2185,7 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), _e = (e, t =
|
|
|
2174
2185
|
display: "inline-block"
|
|
2175
2186
|
}
|
|
2176
2187
|
})
|
|
2177
|
-
}), re = (e,
|
|
2188
|
+
}), re = (e, s = []) => {
|
|
2178
2189
|
var o, c;
|
|
2179
2190
|
if (e.parts.some((l) => {
|
|
2180
2191
|
if (l.type === "data") {
|
|
@@ -2194,7 +2205,7 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), _e = (e, t =
|
|
|
2194
2205
|
if (l.type === "file") {
|
|
2195
2206
|
const u = l.file.uri || (l.file.mimeType && l.file.bytes ? `data:${l.file.mimeType};base64,${l.file.bytes}` : void 0);
|
|
2196
2207
|
if (u)
|
|
2197
|
-
return
|
|
2208
|
+
return Ne(u);
|
|
2198
2209
|
}
|
|
2199
2210
|
if (l.type === "data") {
|
|
2200
2211
|
const u = l.data;
|
|
@@ -2220,10 +2231,10 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), _e = (e, t =
|
|
|
2220
2231
|
showIcon: e.role === "agent",
|
|
2221
2232
|
icon: e.role === "agent" ? "assistant" : void 0
|
|
2222
2233
|
};
|
|
2223
|
-
if (e.role === "agent" &&
|
|
2234
|
+
if (e.role === "agent" && s.length > 0) {
|
|
2224
2235
|
const l = vt(
|
|
2225
2236
|
r,
|
|
2226
|
-
|
|
2237
|
+
s
|
|
2227
2238
|
);
|
|
2228
2239
|
l.length > 0 && (r.actions = l);
|
|
2229
2240
|
}
|
|
@@ -2236,28 +2247,29 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), _e = (e, t =
|
|
|
2236
2247
|
success: !0,
|
|
2237
2248
|
result: "No tools available"
|
|
2238
2249
|
})
|
|
2239
|
-
}),
|
|
2240
|
-
const a = e[
|
|
2250
|
+
}), Ct = (e) => ["agentId", "agentUrl"].every((t) => {
|
|
2251
|
+
const a = e[t];
|
|
2241
2252
|
return typeof a == "string" && a.trim().length > 0;
|
|
2242
2253
|
});
|
|
2243
|
-
function
|
|
2244
|
-
const
|
|
2254
|
+
function Bt(e) {
|
|
2255
|
+
const s = {
|
|
2245
2256
|
agentId: e.agentId,
|
|
2246
2257
|
agentUrl: e.agentUrl,
|
|
2247
2258
|
sessionId: e.sessionId,
|
|
2248
2259
|
sessionIdStorageKey: e.sessionIdStorageKey
|
|
2249
|
-
},
|
|
2260
|
+
}, t = Ct(s), [a, n] = Me({
|
|
2250
2261
|
clientMessages: [],
|
|
2251
2262
|
uiMessages: [],
|
|
2252
2263
|
isProcessing: !1,
|
|
2253
|
-
error:
|
|
2254
|
-
suggestions: []
|
|
2264
|
+
error: t ? null : "Invalid agent configuration",
|
|
2265
|
+
suggestions: [],
|
|
2266
|
+
progressMessage: null
|
|
2255
2267
|
}), {
|
|
2256
2268
|
registerMessageActions: r,
|
|
2257
2269
|
unregisterMessageActions: o,
|
|
2258
2270
|
clearAllMessageActions: c,
|
|
2259
2271
|
registrations: l
|
|
2260
|
-
} =
|
|
2272
|
+
} = Mt(), d = He(l);
|
|
2261
2273
|
se(() => {
|
|
2262
2274
|
d.current = l;
|
|
2263
2275
|
}, [l]);
|
|
@@ -2269,12 +2281,12 @@ function Lt(e) {
|
|
|
2269
2281
|
// registrationsRef is stable, so no deps needed
|
|
2270
2282
|
);
|
|
2271
2283
|
se(() => {
|
|
2272
|
-
if (!
|
|
2284
|
+
if (!t)
|
|
2273
2285
|
return;
|
|
2274
2286
|
(async () => {
|
|
2275
|
-
const i = Q(), T =
|
|
2287
|
+
const i = Q(), T = s.agentId;
|
|
2276
2288
|
if (i.hasAgent(T))
|
|
2277
|
-
|
|
2289
|
+
s.sessionId ? (i.updateSessionId(T, s.sessionId), i.getConversationHistory(T).length === 0 && n((P) => ({
|
|
2278
2290
|
...P,
|
|
2279
2291
|
clientMessages: [],
|
|
2280
2292
|
uiMessages: []
|
|
@@ -2284,17 +2296,17 @@ function Lt(e) {
|
|
|
2284
2296
|
uiMessages: []
|
|
2285
2297
|
})));
|
|
2286
2298
|
else if (await i.createAgent(T, {
|
|
2287
|
-
agentId:
|
|
2288
|
-
agentUrl:
|
|
2289
|
-
sessionId:
|
|
2299
|
+
agentId: s.agentId,
|
|
2300
|
+
agentUrl: s.agentUrl,
|
|
2301
|
+
sessionId: s.sessionId,
|
|
2290
2302
|
// Can be empty for new chats
|
|
2291
|
-
sessionIdStorageKey:
|
|
2303
|
+
sessionIdStorageKey: s.sessionIdStorageKey,
|
|
2292
2304
|
contextProvider: e.contextProvider || At(),
|
|
2293
2305
|
toolProvider: e.toolProvider || xt(),
|
|
2294
2306
|
authProvider: e.authProvider,
|
|
2295
2307
|
enableStreaming: e.enableStreaming,
|
|
2296
2308
|
odieBotId: e.odieBotId
|
|
2297
|
-
}),
|
|
2309
|
+
}), s.sessionId) {
|
|
2298
2310
|
const I = i.getConversationHistory(T);
|
|
2299
2311
|
n((P) => {
|
|
2300
2312
|
const O = u(I);
|
|
@@ -2312,31 +2324,31 @@ function Lt(e) {
|
|
|
2312
2324
|
}));
|
|
2313
2325
|
})();
|
|
2314
2326
|
}, [
|
|
2315
|
-
|
|
2316
|
-
|
|
2317
|
-
|
|
2318
|
-
|
|
2327
|
+
s.sessionId,
|
|
2328
|
+
s.agentId,
|
|
2329
|
+
s.agentUrl,
|
|
2330
|
+
s.sessionIdStorageKey,
|
|
2319
2331
|
e.contextProvider,
|
|
2320
2332
|
e.toolProvider,
|
|
2321
2333
|
e.authProvider,
|
|
2322
2334
|
e.enableStreaming,
|
|
2323
2335
|
e.odieBotId,
|
|
2324
|
-
|
|
2336
|
+
t
|
|
2325
2337
|
]);
|
|
2326
2338
|
const w = q(
|
|
2327
2339
|
async (f, i) => {
|
|
2328
2340
|
var $, S;
|
|
2329
|
-
if (!
|
|
2341
|
+
if (!t)
|
|
2330
2342
|
throw new Error("Invalid agent configuration");
|
|
2331
|
-
const T = Q(),
|
|
2343
|
+
const T = Q(), A = s.agentId, I = Date.now(), P = (i == null ? void 0 : i.type) || "text", O = {
|
|
2332
2344
|
id: `user-${I}`,
|
|
2333
2345
|
role: "user",
|
|
2334
2346
|
content: [
|
|
2335
2347
|
{ type: P, text: f },
|
|
2336
2348
|
// Map image URLs to component content parts
|
|
2337
2349
|
...(($ = i == null ? void 0 : i.imageUrls) == null ? void 0 : $.map((p) => {
|
|
2338
|
-
const
|
|
2339
|
-
return
|
|
2350
|
+
const C = typeof p == "string" ? p : p.url;
|
|
2351
|
+
return Ne(C);
|
|
2340
2352
|
})) ?? []
|
|
2341
2353
|
],
|
|
2342
2354
|
timestamp: I,
|
|
@@ -2350,18 +2362,21 @@ function Lt(e) {
|
|
|
2350
2362
|
error: null
|
|
2351
2363
|
}));
|
|
2352
2364
|
try {
|
|
2353
|
-
let p = null,
|
|
2354
|
-
const
|
|
2355
|
-
(i != null && i.archived || i != null && i.type) && (
|
|
2365
|
+
let p = null, C = !1;
|
|
2366
|
+
const M = {};
|
|
2367
|
+
(i != null && i.archived || i != null && i.type) && (M.metadata = {
|
|
2356
2368
|
...(i == null ? void 0 : i.archived) && { archived: !0 },
|
|
2357
2369
|
...(i == null ? void 0 : i.type) && { contentType: i.type }
|
|
2358
|
-
}), i != null && i.sessionId && (
|
|
2359
|
-
for await (const
|
|
2360
|
-
|
|
2370
|
+
}), i != null && i.sessionId && (M.sessionId = i.sessionId), i != null && i.imageUrls && (M.imageUrls = i.imageUrls);
|
|
2371
|
+
for await (const R of T.sendMessageStream(
|
|
2372
|
+
A,
|
|
2361
2373
|
f,
|
|
2362
|
-
|
|
2374
|
+
M
|
|
2363
2375
|
)) {
|
|
2364
|
-
if (
|
|
2376
|
+
if (R.progressMessage && n((k) => ({
|
|
2377
|
+
...k,
|
|
2378
|
+
progressMessage: R.progressMessage || null
|
|
2379
|
+
})), !R.final && R.text)
|
|
2365
2380
|
if (p)
|
|
2366
2381
|
n((k) => ({
|
|
2367
2382
|
...k,
|
|
@@ -2371,7 +2386,7 @@ function Lt(e) {
|
|
|
2371
2386
|
content: [
|
|
2372
2387
|
{
|
|
2373
2388
|
type: "text",
|
|
2374
|
-
text:
|
|
2389
|
+
text: R.text
|
|
2375
2390
|
}
|
|
2376
2391
|
]
|
|
2377
2392
|
} : b
|
|
@@ -2383,7 +2398,7 @@ function Lt(e) {
|
|
|
2383
2398
|
id: p,
|
|
2384
2399
|
role: "agent",
|
|
2385
2400
|
content: [
|
|
2386
|
-
{ type: "text", text:
|
|
2401
|
+
{ type: "text", text: R.text }
|
|
2387
2402
|
],
|
|
2388
2403
|
timestamp: Date.now(),
|
|
2389
2404
|
archived: !1,
|
|
@@ -2398,35 +2413,36 @@ function Lt(e) {
|
|
|
2398
2413
|
]
|
|
2399
2414
|
}));
|
|
2400
2415
|
}
|
|
2401
|
-
if (
|
|
2402
|
-
|
|
2416
|
+
if (R.final && ((S = R.status) != null && S.message) && p) {
|
|
2417
|
+
C = !0;
|
|
2403
2418
|
const k = p, b = re(
|
|
2404
|
-
|
|
2419
|
+
R.status.message,
|
|
2405
2420
|
d.current
|
|
2406
2421
|
);
|
|
2407
|
-
b && n((
|
|
2408
|
-
const U =
|
|
2422
|
+
b && n((E) => {
|
|
2423
|
+
const U = E.uiMessages.map(
|
|
2409
2424
|
(j) => j.id === k ? b : j
|
|
2410
2425
|
), D = T.getConversationHistory(
|
|
2411
|
-
|
|
2426
|
+
A
|
|
2412
2427
|
);
|
|
2413
2428
|
return {
|
|
2414
|
-
...
|
|
2429
|
+
...E,
|
|
2415
2430
|
clientMessages: D,
|
|
2416
2431
|
uiMessages: U,
|
|
2417
|
-
isProcessing: !1
|
|
2432
|
+
isProcessing: !1,
|
|
2433
|
+
progressMessage: null
|
|
2418
2434
|
};
|
|
2419
2435
|
}), p = null;
|
|
2420
2436
|
}
|
|
2421
2437
|
}
|
|
2422
|
-
if (!
|
|
2423
|
-
const
|
|
2438
|
+
if (!C) {
|
|
2439
|
+
const R = T.getConversationHistory(A);
|
|
2424
2440
|
n((k) => {
|
|
2425
2441
|
let b = k.uiMessages;
|
|
2426
2442
|
p && (b = k.uiMessages.filter(
|
|
2427
2443
|
(N) => N.id !== p
|
|
2428
2444
|
));
|
|
2429
|
-
const
|
|
2445
|
+
const E = R.map(
|
|
2430
2446
|
(N) => re(
|
|
2431
2447
|
N,
|
|
2432
2448
|
d.current
|
|
@@ -2434,43 +2450,46 @@ function Lt(e) {
|
|
|
2434
2450
|
).filter(
|
|
2435
2451
|
(N) => N !== null
|
|
2436
2452
|
), U = new Set(
|
|
2437
|
-
|
|
2453
|
+
R.map((N) => N.messageId)
|
|
2438
2454
|
), D = b.filter(
|
|
2439
2455
|
(N) => {
|
|
2440
2456
|
var J;
|
|
2441
2457
|
return !U.has(N.id) && ((J = N.content[0]) == null ? void 0 : J.type) === "component";
|
|
2442
2458
|
}
|
|
2443
2459
|
), j = oe([
|
|
2444
|
-
...
|
|
2460
|
+
...E,
|
|
2445
2461
|
...D
|
|
2446
2462
|
]);
|
|
2447
2463
|
return {
|
|
2448
2464
|
...k,
|
|
2449
|
-
clientMessages:
|
|
2465
|
+
clientMessages: R,
|
|
2450
2466
|
uiMessages: j,
|
|
2451
|
-
isProcessing: !1
|
|
2467
|
+
isProcessing: !1,
|
|
2468
|
+
progressMessage: null
|
|
2452
2469
|
};
|
|
2453
2470
|
});
|
|
2454
2471
|
}
|
|
2455
2472
|
} catch (p) {
|
|
2456
2473
|
if (p instanceof Error && p.name === "AbortError") {
|
|
2457
|
-
|
|
2458
|
-
...
|
|
2474
|
+
v("Request was aborted by user"), n((M) => ({
|
|
2475
|
+
...M,
|
|
2459
2476
|
isProcessing: !1,
|
|
2477
|
+
progressMessage: null,
|
|
2460
2478
|
error: null
|
|
2461
2479
|
// Don't show error for user-initiated abort
|
|
2462
2480
|
}));
|
|
2463
2481
|
return;
|
|
2464
2482
|
}
|
|
2465
|
-
const
|
|
2466
|
-
throw n((
|
|
2467
|
-
...
|
|
2483
|
+
const C = p instanceof Error ? p.message : "Failed to send message";
|
|
2484
|
+
throw n((M) => ({
|
|
2485
|
+
...M,
|
|
2468
2486
|
isProcessing: !1,
|
|
2469
|
-
|
|
2487
|
+
progressMessage: null,
|
|
2488
|
+
error: C
|
|
2470
2489
|
})), p;
|
|
2471
2490
|
}
|
|
2472
2491
|
},
|
|
2473
|
-
[
|
|
2492
|
+
[s.agentId, t]
|
|
2474
2493
|
), m = q((f) => {
|
|
2475
2494
|
n((i) => ({
|
|
2476
2495
|
...i,
|
|
@@ -2493,7 +2512,7 @@ function Lt(e) {
|
|
|
2493
2512
|
return f;
|
|
2494
2513
|
const i = u(f.clientMessages), T = new Set(
|
|
2495
2514
|
f.clientMessages.map((I) => I.messageId)
|
|
2496
|
-
),
|
|
2515
|
+
), A = f.uiMessages.filter(
|
|
2497
2516
|
(I) => {
|
|
2498
2517
|
var P;
|
|
2499
2518
|
return !T.has(I.id) && ((P = I.content[0]) == null ? void 0 : P.type) === "component";
|
|
@@ -2503,30 +2522,30 @@ function Lt(e) {
|
|
|
2503
2522
|
...f,
|
|
2504
2523
|
uiMessages: oe([
|
|
2505
2524
|
...i,
|
|
2506
|
-
...
|
|
2525
|
+
...A
|
|
2507
2526
|
])
|
|
2508
2527
|
};
|
|
2509
2528
|
});
|
|
2510
2529
|
}, [l]);
|
|
2511
2530
|
const y = q(() => {
|
|
2512
|
-
if (!
|
|
2531
|
+
if (!t)
|
|
2513
2532
|
return;
|
|
2514
|
-
const f = Q(), i =
|
|
2533
|
+
const f = Q(), i = s.agentId;
|
|
2515
2534
|
f.abortCurrentRequest(i);
|
|
2516
|
-
}, [
|
|
2535
|
+
}, [s.agentId, t]), x = q(
|
|
2517
2536
|
async (f) => {
|
|
2518
|
-
if (!
|
|
2537
|
+
if (!t)
|
|
2519
2538
|
return;
|
|
2520
|
-
const i = Q(), T =
|
|
2539
|
+
const i = Q(), T = s.agentId;
|
|
2521
2540
|
await i.replaceMessages(T, f);
|
|
2522
|
-
const
|
|
2541
|
+
const A = u(f);
|
|
2523
2542
|
n((I) => ({
|
|
2524
2543
|
...I,
|
|
2525
2544
|
clientMessages: f,
|
|
2526
|
-
uiMessages:
|
|
2545
|
+
uiMessages: A
|
|
2527
2546
|
}));
|
|
2528
2547
|
},
|
|
2529
|
-
[
|
|
2548
|
+
[s.agentId, t]
|
|
2530
2549
|
);
|
|
2531
2550
|
return {
|
|
2532
2551
|
// AgentUI props
|
|
@@ -2535,6 +2554,7 @@ function Lt(e) {
|
|
|
2535
2554
|
error: a.error,
|
|
2536
2555
|
onSubmit: w,
|
|
2537
2556
|
suggestions: a.suggestions,
|
|
2557
|
+
progressMessage: a.progressMessage,
|
|
2538
2558
|
// UI management methods
|
|
2539
2559
|
registerSuggestions: g,
|
|
2540
2560
|
clearSuggestions: h,
|
|
@@ -2550,23 +2570,23 @@ function Lt(e) {
|
|
|
2550
2570
|
loadMessages: x
|
|
2551
2571
|
};
|
|
2552
2572
|
}
|
|
2553
|
-
var
|
|
2554
|
-
const
|
|
2555
|
-
function
|
|
2556
|
-
var
|
|
2557
|
-
return ((a = (
|
|
2573
|
+
var bt = /* @__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))(bt || {});
|
|
2574
|
+
const Te = "jetpack-ai-jwt-token", kt = 30 * 60 * 1e3;
|
|
2575
|
+
function Rt() {
|
|
2576
|
+
var t, a, n;
|
|
2577
|
+
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);
|
|
2558
2578
|
}
|
|
2559
|
-
async function
|
|
2579
|
+
async function Et(e, s = !0) {
|
|
2560
2580
|
var l, d;
|
|
2561
|
-
const
|
|
2581
|
+
const t = localStorage.getItem(Te);
|
|
2562
2582
|
let a;
|
|
2563
|
-
if (
|
|
2583
|
+
if (t)
|
|
2564
2584
|
try {
|
|
2565
|
-
a = JSON.parse(
|
|
2585
|
+
a = JSON.parse(t);
|
|
2566
2586
|
} catch (u) {
|
|
2567
|
-
|
|
2587
|
+
v("Invalid cached Jetpack token: %O", u);
|
|
2568
2588
|
}
|
|
2569
|
-
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() &&
|
|
2589
|
+
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && s)
|
|
2570
2590
|
return a;
|
|
2571
2591
|
const n = (l = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : l.apiNonce, r = (d = window.Jetpack_Editor_Initial_State) == null ? void 0 : d.wpcomBlogId;
|
|
2572
2592
|
let o = {
|
|
@@ -2574,7 +2594,7 @@ async function Rt(e, t = !0) {
|
|
|
2574
2594
|
blog_id: ""
|
|
2575
2595
|
};
|
|
2576
2596
|
try {
|
|
2577
|
-
|
|
2597
|
+
Rt() ? o = await pe({
|
|
2578
2598
|
path: "/wpcom/v2/sites/" + r + "/jetpack-openai-query/jwt",
|
|
2579
2599
|
method: "POST"
|
|
2580
2600
|
}) : o = await pe({
|
|
@@ -2586,7 +2606,7 @@ async function Rt(e, t = !0) {
|
|
|
2586
2606
|
method: "POST"
|
|
2587
2607
|
});
|
|
2588
2608
|
} catch (u) {
|
|
2589
|
-
throw
|
|
2609
|
+
throw v("Failed to fetch Jetpack token: %O", u), new Error(e(u));
|
|
2590
2610
|
}
|
|
2591
2611
|
if (!(o != null && o.token))
|
|
2592
2612
|
throw new Error(
|
|
@@ -2595,27 +2615,27 @@ async function Rt(e, t = !0) {
|
|
|
2595
2615
|
const c = {
|
|
2596
2616
|
token: o.token,
|
|
2597
2617
|
blogId: o.blog_id || "",
|
|
2598
|
-
expire: Date.now() +
|
|
2618
|
+
expire: Date.now() + kt
|
|
2599
2619
|
};
|
|
2600
2620
|
try {
|
|
2601
|
-
localStorage.setItem(
|
|
2621
|
+
localStorage.setItem(Te, JSON.stringify(c));
|
|
2602
2622
|
} catch (u) {
|
|
2603
|
-
|
|
2623
|
+
v("Error storing token in localStorage: %O", u);
|
|
2604
2624
|
}
|
|
2605
2625
|
return c;
|
|
2606
2626
|
}
|
|
2607
|
-
const
|
|
2608
|
-
const
|
|
2627
|
+
const Kt = (e) => async () => {
|
|
2628
|
+
const s = {};
|
|
2609
2629
|
try {
|
|
2610
|
-
const
|
|
2611
|
-
|
|
2612
|
-
} catch (
|
|
2613
|
-
throw
|
|
2630
|
+
const t = await Et(e);
|
|
2631
|
+
t != null && t.token && (s.Authorization = `${t.token}`);
|
|
2632
|
+
} catch (t) {
|
|
2633
|
+
throw v("Failed to get Jetpack token for auth: %O", t), t;
|
|
2614
2634
|
}
|
|
2615
|
-
return
|
|
2635
|
+
return s;
|
|
2616
2636
|
};
|
|
2617
|
-
function
|
|
2618
|
-
const
|
|
2637
|
+
function Pt(e) {
|
|
2638
|
+
const s = {
|
|
2619
2639
|
type: "object",
|
|
2620
2640
|
properties: {}
|
|
2621
2641
|
};
|
|
@@ -2623,73 +2643,73 @@ function Et(e) {
|
|
|
2623
2643
|
id: e.name.replace(/\//g, "-"),
|
|
2624
2644
|
name: e.label,
|
|
2625
2645
|
description: e.description,
|
|
2626
|
-
input_schema: e.input_schema ||
|
|
2646
|
+
input_schema: e.input_schema || s,
|
|
2627
2647
|
// Store metadata for detection and execution
|
|
2628
2648
|
_source: "wordpress-ability",
|
|
2629
2649
|
_originalAbility: e
|
|
2630
2650
|
};
|
|
2631
2651
|
}
|
|
2632
|
-
function Kt(e) {
|
|
2633
|
-
return e.map(Et);
|
|
2634
|
-
}
|
|
2635
2652
|
function Wt(e) {
|
|
2653
|
+
return e.map(Pt);
|
|
2654
|
+
}
|
|
2655
|
+
function Vt(e) {
|
|
2636
2656
|
return (e == null ? void 0 : e._source) === "wordpress-ability";
|
|
2637
2657
|
}
|
|
2638
|
-
function
|
|
2658
|
+
function zt(e, s = "agent", t = "wpcom") {
|
|
2639
2659
|
const a = e.replace(/-/g, "_");
|
|
2640
|
-
return `${
|
|
2660
|
+
return `${t}-${s}-${a}`;
|
|
2641
2661
|
}
|
|
2642
|
-
function
|
|
2643
|
-
const
|
|
2644
|
-
if (
|
|
2662
|
+
function Ot(e) {
|
|
2663
|
+
const s = e.split("-");
|
|
2664
|
+
if (s.length < 3)
|
|
2645
2665
|
throw new Error(
|
|
2646
2666
|
`Invalid Odie bot ID format: ${e}. Expected format: {product}-{type}-{slug}`
|
|
2647
2667
|
);
|
|
2648
|
-
const
|
|
2668
|
+
const t = s[0], a = s[1];
|
|
2649
2669
|
if (!["agent", "workflow", "chain"].includes(a))
|
|
2650
2670
|
throw new Error(
|
|
2651
2671
|
`Invalid Odie bot type: ${a}. Expected one of: agent, workflow, chain`
|
|
2652
2672
|
);
|
|
2653
|
-
const n = a, r =
|
|
2673
|
+
const n = a, r = s.slice(2).join("-"), o = r.replace(/_/g, "-");
|
|
2654
2674
|
return {
|
|
2655
|
-
product:
|
|
2675
|
+
product: t,
|
|
2656
2676
|
type: n,
|
|
2657
2677
|
slug: r,
|
|
2658
2678
|
agentId: o
|
|
2659
2679
|
};
|
|
2660
2680
|
}
|
|
2661
|
-
function
|
|
2681
|
+
function Gt(e) {
|
|
2662
2682
|
try {
|
|
2663
|
-
const
|
|
2664
|
-
return
|
|
2683
|
+
const s = Ot(e);
|
|
2684
|
+
return s.product.length > 0 && ["agent", "workflow", "chain"].includes(s.type) && s.slug.length > 0;
|
|
2665
2685
|
} catch {
|
|
2666
2686
|
return !1;
|
|
2667
2687
|
}
|
|
2668
2688
|
}
|
|
2669
2689
|
export {
|
|
2670
|
-
|
|
2671
|
-
|
|
2672
|
-
|
|
2673
|
-
|
|
2674
|
-
|
|
2675
|
-
|
|
2676
|
-
|
|
2677
|
-
|
|
2678
|
-
|
|
2690
|
+
bt as ErrorCodes,
|
|
2691
|
+
Wt as convertAbilitiesToTools,
|
|
2692
|
+
Pt as convertAbilityToTool,
|
|
2693
|
+
Dt as createAbortController,
|
|
2694
|
+
rt as createClient,
|
|
2695
|
+
Kt as createJetpackAuthProvider,
|
|
2696
|
+
zt as createOdieBotId,
|
|
2697
|
+
Fe as createRequestId,
|
|
2698
|
+
je as createTaskId,
|
|
2679
2699
|
ie as createTextMessage,
|
|
2680
2700
|
F as extractTextFromMessage,
|
|
2681
2701
|
B as extractToolCallsFromMessage,
|
|
2682
2702
|
Q as getAgentManager,
|
|
2683
|
-
|
|
2684
|
-
|
|
2685
|
-
|
|
2686
|
-
|
|
2703
|
+
Gt as isOdieBotId,
|
|
2704
|
+
Vt as isWordPressAbility,
|
|
2705
|
+
Jt as listConversationsFromServer,
|
|
2706
|
+
Lt as loadAllMessagesFromServer,
|
|
2687
2707
|
le as loadChatFromServer,
|
|
2688
|
-
|
|
2689
|
-
|
|
2690
|
-
|
|
2691
|
-
|
|
2692
|
-
|
|
2693
|
-
|
|
2694
|
-
|
|
2708
|
+
Ot as parseOdieBotId,
|
|
2709
|
+
Bt as useAgentChat,
|
|
2710
|
+
Ft as useClientAbilities,
|
|
2711
|
+
qt as useClientContext,
|
|
2712
|
+
Ht as useClientTools,
|
|
2713
|
+
jt as useClientToolsWithAbilities,
|
|
2714
|
+
Mt as useMessageActions
|
|
2695
2715
|
};
|