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