@automattic/agenttic-client 0.1.53 → 0.1.55
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
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var $e = Object.defineProperty;
|
|
2
|
-
var Ue = (e,
|
|
3
|
-
var te = (e,
|
|
4
|
-
import qe, { useMemo as Se, useCallback as F, useState as
|
|
5
|
-
import { l as
|
|
2
|
+
var Ue = (e, s, t) => s in e ? $e(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
|
+
var te = (e, s, t) => Ue(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
import qe, { useMemo as Se, useCallback as F, useState as Ae, useRef as He, useEffect as se } from "react";
|
|
5
|
+
import { l as M, f as ve, a as K } from "./logger-aKHbTlwk.js";
|
|
6
6
|
import pe from "@wordpress/api-fetch";
|
|
7
7
|
function Ht(e) {
|
|
8
8
|
return Se(() => e ? {
|
|
@@ -10,15 +10,15 @@ function Ht(e) {
|
|
|
10
10
|
try {
|
|
11
11
|
return e() || {};
|
|
12
12
|
} catch (a) {
|
|
13
|
-
return
|
|
13
|
+
return M("Error getting client context: %O", a), {};
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
} : void 0, [e]);
|
|
17
17
|
}
|
|
18
18
|
function ce({
|
|
19
19
|
getClientTools: e,
|
|
20
|
-
executeTool:
|
|
21
|
-
getAbilities:
|
|
20
|
+
executeTool: s,
|
|
21
|
+
getAbilities: t
|
|
22
22
|
}) {
|
|
23
23
|
const a = F(async () => {
|
|
24
24
|
const o = [];
|
|
@@ -27,38 +27,38 @@ function ce({
|
|
|
27
27
|
const c = await e();
|
|
28
28
|
o.push(...c);
|
|
29
29
|
} catch (c) {
|
|
30
|
-
|
|
30
|
+
M("Error getting available tools: %O", c);
|
|
31
31
|
}
|
|
32
32
|
return o;
|
|
33
33
|
}, [e]), n = F(
|
|
34
34
|
async (o, c) => {
|
|
35
|
-
if (!
|
|
35
|
+
if (!s)
|
|
36
36
|
throw new Error("No executeTool callback provided");
|
|
37
37
|
try {
|
|
38
|
-
return await
|
|
38
|
+
return await s(o, c);
|
|
39
39
|
} catch (l) {
|
|
40
|
-
throw
|
|
40
|
+
throw M("Error executing tool %s: %O", o, l), l;
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
|
-
[
|
|
43
|
+
[s]
|
|
44
44
|
);
|
|
45
45
|
return Se(() => {
|
|
46
|
-
if (!e && !
|
|
46
|
+
if (!e && !t)
|
|
47
47
|
return;
|
|
48
48
|
const o = {};
|
|
49
|
-
return e && (o.getAvailableTools = a),
|
|
49
|
+
return e && (o.getAvailableTools = a), s && (o.executeTool = n), t && (o.getAbilities = t), o;
|
|
50
50
|
}, [
|
|
51
51
|
a,
|
|
52
52
|
n,
|
|
53
53
|
e,
|
|
54
|
-
|
|
55
|
-
|
|
54
|
+
s,
|
|
55
|
+
t
|
|
56
56
|
]);
|
|
57
57
|
}
|
|
58
|
-
function Ft(e,
|
|
58
|
+
function Ft(e, s) {
|
|
59
59
|
return ce({
|
|
60
60
|
getClientTools: e,
|
|
61
|
-
executeTool:
|
|
61
|
+
executeTool: s,
|
|
62
62
|
getAbilities: void 0
|
|
63
63
|
});
|
|
64
64
|
}
|
|
@@ -70,27 +70,27 @@ function jt(e) {
|
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
72
|
function Dt(e) {
|
|
73
|
-
const { getClientTools:
|
|
74
|
-
if (!
|
|
73
|
+
const { getClientTools: s, executeTool: t, getAbilities: a } = e;
|
|
74
|
+
if (!s && !a)
|
|
75
75
|
throw new Error(
|
|
76
76
|
"At least one of getClientTools or getAbilities must be provided to useClientToolsWithAbilities."
|
|
77
77
|
);
|
|
78
|
-
if (
|
|
78
|
+
if (s && !t)
|
|
79
79
|
throw new Error(
|
|
80
80
|
"executeTool is required when providing getClientTools."
|
|
81
81
|
);
|
|
82
82
|
return ce({
|
|
83
|
-
getClientTools:
|
|
84
|
-
executeTool:
|
|
83
|
+
getClientTools: s,
|
|
84
|
+
executeTool: t,
|
|
85
85
|
getAbilities: a
|
|
86
86
|
});
|
|
87
87
|
}
|
|
88
88
|
function ue() {
|
|
89
89
|
const e = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
90
|
-
let
|
|
91
|
-
for (let
|
|
92
|
-
|
|
93
|
-
return
|
|
90
|
+
let s = "";
|
|
91
|
+
for (let t = 0; t < 8; t++)
|
|
92
|
+
s += e.charAt(Math.floor(Math.random() * e.length));
|
|
93
|
+
return s;
|
|
94
94
|
}
|
|
95
95
|
function N() {
|
|
96
96
|
return ue();
|
|
@@ -101,36 +101,36 @@ function Fe() {
|
|
|
101
101
|
function je() {
|
|
102
102
|
return `task-${ue()}`;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function Me(e, s) {
|
|
105
105
|
return {
|
|
106
106
|
type: "text",
|
|
107
107
|
text: e,
|
|
108
|
-
...
|
|
108
|
+
...s && { metadata: s }
|
|
109
109
|
};
|
|
110
110
|
}
|
|
111
|
-
function De(e,
|
|
111
|
+
function De(e, s = "message/send", t = !1) {
|
|
112
112
|
const a = {
|
|
113
113
|
jsonrpc: "2.0",
|
|
114
114
|
id: Fe(),
|
|
115
|
-
method:
|
|
115
|
+
method: s,
|
|
116
116
|
params: {
|
|
117
117
|
id: e.id || je(),
|
|
118
118
|
...e
|
|
119
119
|
}
|
|
120
120
|
};
|
|
121
|
-
return
|
|
121
|
+
return t && s === "message/stream" && (a.tokenStreaming = !0), a;
|
|
122
122
|
}
|
|
123
123
|
function j(e) {
|
|
124
|
-
return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((
|
|
124
|
+
return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
|
|
125
125
|
}
|
|
126
126
|
function he(e) {
|
|
127
127
|
if (!e || !e.parts || !Array.isArray(e.parts))
|
|
128
128
|
return;
|
|
129
|
-
const
|
|
130
|
-
if (
|
|
129
|
+
const s = e.parts.find((t) => t.type === "progress" ? !0 : t.type === "data" ? "summary" in t.data && typeof t.data.summary == "string" : !1);
|
|
130
|
+
if (s)
|
|
131
131
|
return {
|
|
132
|
-
summary:
|
|
133
|
-
phase:
|
|
132
|
+
summary: s.data.summary,
|
|
133
|
+
phase: s.data.phase
|
|
134
134
|
};
|
|
135
135
|
}
|
|
136
136
|
function Je(e) {
|
|
@@ -162,16 +162,16 @@ function Ke(e) {
|
|
|
162
162
|
}
|
|
163
163
|
function L(e) {
|
|
164
164
|
return !e || !e.parts || !Array.isArray(e.parts) ? [] : e.parts.filter(
|
|
165
|
-
(
|
|
165
|
+
(s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
|
|
166
166
|
);
|
|
167
167
|
}
|
|
168
|
-
function W(e,
|
|
168
|
+
function W(e, s, t, a) {
|
|
169
169
|
return {
|
|
170
170
|
type: "data",
|
|
171
171
|
data: {
|
|
172
172
|
toolCallId: e,
|
|
173
|
-
toolId:
|
|
174
|
-
result:
|
|
173
|
+
toolId: s,
|
|
174
|
+
result: t
|
|
175
175
|
},
|
|
176
176
|
metadata: a ? { error: a } : void 0
|
|
177
177
|
};
|
|
@@ -185,11 +185,11 @@ function Le(e) {
|
|
|
185
185
|
metadata: {}
|
|
186
186
|
};
|
|
187
187
|
}
|
|
188
|
-
function ie(e,
|
|
189
|
-
const { contentType:
|
|
188
|
+
function ie(e, s) {
|
|
189
|
+
const { contentType: t, ...a } = s || {};
|
|
190
190
|
return {
|
|
191
191
|
role: "user",
|
|
192
|
-
parts: [
|
|
192
|
+
parts: [Me(e, t ? { contentType: t } : void 0)],
|
|
193
193
|
kind: "message",
|
|
194
194
|
messageId: N(),
|
|
195
195
|
metadata: {
|
|
@@ -201,7 +201,7 @@ function ie(e, t) {
|
|
|
201
201
|
function G(e) {
|
|
202
202
|
return {
|
|
203
203
|
role: "agent",
|
|
204
|
-
parts: [
|
|
204
|
+
parts: [Me(e)],
|
|
205
205
|
kind: "message",
|
|
206
206
|
messageId: N(),
|
|
207
207
|
metadata: {
|
|
@@ -221,11 +221,11 @@ function de(e) {
|
|
|
221
221
|
returnToAgent: !0
|
|
222
222
|
};
|
|
223
223
|
}
|
|
224
|
-
function X(e,
|
|
224
|
+
function X(e, s = []) {
|
|
225
225
|
return {
|
|
226
226
|
role: "user",
|
|
227
227
|
kind: "message",
|
|
228
|
-
parts: [...
|
|
228
|
+
parts: [...s, ...e],
|
|
229
229
|
messageId: N(),
|
|
230
230
|
metadata: {
|
|
231
231
|
timestamp: Date.now()
|
|
@@ -235,63 +235,63 @@ function X(e, t = []) {
|
|
|
235
235
|
function Jt() {
|
|
236
236
|
return new AbortController();
|
|
237
237
|
}
|
|
238
|
-
async function Be(e,
|
|
239
|
-
if (!
|
|
238
|
+
async function Be(e, s) {
|
|
239
|
+
if (!s)
|
|
240
240
|
return e;
|
|
241
241
|
try {
|
|
242
|
-
const
|
|
243
|
-
if (
|
|
244
|
-
const a = await
|
|
242
|
+
const t = [];
|
|
243
|
+
if (s.getAvailableTools) {
|
|
244
|
+
const a = await s.getAvailableTools();
|
|
245
245
|
if (a.length > 0) {
|
|
246
246
|
const n = a.map(Je);
|
|
247
|
-
|
|
247
|
+
t.push(...n);
|
|
248
248
|
}
|
|
249
249
|
}
|
|
250
|
-
if (
|
|
251
|
-
const a = await
|
|
250
|
+
if (s.getAbilities) {
|
|
251
|
+
const a = await s.getAbilities();
|
|
252
252
|
if (a.length > 0) {
|
|
253
253
|
const n = a.map(Ke);
|
|
254
|
-
|
|
254
|
+
t.push(...n);
|
|
255
255
|
}
|
|
256
256
|
}
|
|
257
|
-
return
|
|
257
|
+
return t.length === 0 ? e : {
|
|
258
258
|
...e,
|
|
259
|
-
parts: [...e.parts, ...
|
|
259
|
+
parts: [...e.parts, ...t]
|
|
260
260
|
};
|
|
261
|
-
} catch (
|
|
262
|
-
return
|
|
261
|
+
} catch (t) {
|
|
262
|
+
return M("Warning: Failed to get tools: %s", t), e;
|
|
263
263
|
}
|
|
264
264
|
}
|
|
265
|
-
function We(e,
|
|
266
|
-
if (!
|
|
265
|
+
function We(e, s) {
|
|
266
|
+
if (!s)
|
|
267
267
|
return e;
|
|
268
268
|
try {
|
|
269
|
-
const
|
|
270
|
-
if (!
|
|
269
|
+
const t = s.getClientContext();
|
|
270
|
+
if (!t || Object.keys(t).length === 0)
|
|
271
271
|
return e;
|
|
272
|
-
const a = Le(
|
|
272
|
+
const a = Le(t);
|
|
273
273
|
return {
|
|
274
274
|
...e,
|
|
275
275
|
parts: [...e.parts, a]
|
|
276
276
|
};
|
|
277
|
-
} catch (
|
|
278
|
-
return
|
|
277
|
+
} catch (t) {
|
|
278
|
+
return M("Warning: Failed to get context: %s", t), e;
|
|
279
279
|
}
|
|
280
280
|
}
|
|
281
|
-
async function Ve(e,
|
|
281
|
+
async function Ve(e, s, t) {
|
|
282
282
|
let a = await Be(
|
|
283
283
|
e,
|
|
284
|
-
|
|
284
|
+
s
|
|
285
285
|
);
|
|
286
286
|
a = We(
|
|
287
287
|
a,
|
|
288
|
-
|
|
288
|
+
t
|
|
289
289
|
);
|
|
290
290
|
const { metadata: n, ...r } = a;
|
|
291
291
|
return r;
|
|
292
292
|
}
|
|
293
|
-
function ze(e,
|
|
294
|
-
const
|
|
293
|
+
function ze(e, s = "") {
|
|
294
|
+
const t = [], a = s + e;
|
|
295
295
|
let n = "", r = 0, o = 0;
|
|
296
296
|
for (; o < a.length; ) {
|
|
297
297
|
const l = a.indexOf(
|
|
@@ -306,20 +306,20 @@ function ze(e, t = "") {
|
|
|
306
306
|
);
|
|
307
307
|
else if (d.trim() === "" && n) {
|
|
308
308
|
try {
|
|
309
|
-
|
|
309
|
+
t.push(JSON.parse(n)), r = l === -1 ? a.length : l + 1;
|
|
310
310
|
} catch (u) {
|
|
311
|
-
|
|
311
|
+
M("Failed to parse SSE event: %o", u), M("Problematic payload: %s", n);
|
|
312
312
|
}
|
|
313
313
|
n = "";
|
|
314
314
|
}
|
|
315
315
|
l === -1 ? o = a.length : o = l + 1;
|
|
316
316
|
}
|
|
317
317
|
const c = a.substring(r);
|
|
318
|
-
return { events:
|
|
318
|
+
return { events: t, nextBuffer: c };
|
|
319
319
|
}
|
|
320
|
-
async function* Ge(e,
|
|
320
|
+
async function* Ge(e, s = {}) {
|
|
321
321
|
var d, u, p;
|
|
322
|
-
const { supportDeltas:
|
|
322
|
+
const { supportDeltas: t = !1 } = s, a = e.getReader(), n = new TextDecoder();
|
|
323
323
|
let r = "";
|
|
324
324
|
const o = new Qe();
|
|
325
325
|
let c = null, l = null;
|
|
@@ -328,7 +328,7 @@ async function* Ge(e, t = {}) {
|
|
|
328
328
|
const { done: m, value: f } = await a.read();
|
|
329
329
|
if (m)
|
|
330
330
|
break;
|
|
331
|
-
const w = n.decode(f, { stream: !0 }), { events: h, nextBuffer:
|
|
331
|
+
const w = n.decode(f, { stream: !0 }), { events: h, nextBuffer: x } = ze(w, r);
|
|
332
332
|
if (h && Array.isArray(h))
|
|
333
333
|
for (let g = 0; g < h.length; g++) {
|
|
334
334
|
const i = h[g];
|
|
@@ -338,7 +338,7 @@ async function* Ge(e, t = {}) {
|
|
|
338
338
|
throw new Error(
|
|
339
339
|
`Streaming error: ${i.error.message}`
|
|
340
340
|
);
|
|
341
|
-
if (
|
|
341
|
+
if (t && i.method === "message/delta" && ((d = i.params) != null && d.delta)) {
|
|
342
342
|
const T = i.params.delta;
|
|
343
343
|
try {
|
|
344
344
|
if (T.deltaType === "content" && (o.processContentDelta(
|
|
@@ -356,7 +356,7 @@ async function* Ge(e, t = {}) {
|
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
358
|
} catch (S) {
|
|
359
|
-
|
|
359
|
+
M("Failed to process delta: %o", S);
|
|
360
360
|
}
|
|
361
361
|
} else if (i.result && i.result.status) {
|
|
362
362
|
c = i.result.id, l = i.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset();
|
|
@@ -389,7 +389,7 @@ async function* Ge(e, t = {}) {
|
|
|
389
389
|
};
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
|
-
r =
|
|
392
|
+
r = x;
|
|
393
393
|
}
|
|
394
394
|
} finally {
|
|
395
395
|
a.releaseLock();
|
|
@@ -404,33 +404,33 @@ class Qe {
|
|
|
404
404
|
* Process a simple content delta (server's actual format)
|
|
405
405
|
* @param content - The text content to append
|
|
406
406
|
*/
|
|
407
|
-
processContentDelta(
|
|
408
|
-
this.textContent +=
|
|
407
|
+
processContentDelta(s) {
|
|
408
|
+
this.textContent += s;
|
|
409
409
|
}
|
|
410
410
|
/**
|
|
411
411
|
* Process a delta message and accumulate the content (original format)
|
|
412
412
|
* @param delta - The delta message to process
|
|
413
413
|
*/
|
|
414
|
-
processDelta(
|
|
415
|
-
switch (
|
|
414
|
+
processDelta(s) {
|
|
415
|
+
switch (s.type) {
|
|
416
416
|
case "content":
|
|
417
|
-
this.textContent +=
|
|
417
|
+
this.textContent += s.content;
|
|
418
418
|
break;
|
|
419
419
|
case "tool_name":
|
|
420
|
-
this.toolCalls.has(
|
|
421
|
-
toolCallId:
|
|
420
|
+
this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
|
|
421
|
+
toolCallId: s.toolCallId,
|
|
422
422
|
toolName: "",
|
|
423
423
|
argumentFragments: []
|
|
424
424
|
});
|
|
425
|
-
const
|
|
426
|
-
|
|
425
|
+
const t = this.toolCalls.get(s.toolCallIndex);
|
|
426
|
+
t.toolName += s.content;
|
|
427
427
|
break;
|
|
428
428
|
case "tool_argument":
|
|
429
|
-
this.toolCalls.has(
|
|
430
|
-
toolCallId:
|
|
429
|
+
this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
|
|
430
|
+
toolCallId: s.toolCallId,
|
|
431
431
|
toolName: "",
|
|
432
432
|
argumentFragments: []
|
|
433
|
-
}), this.toolCalls.get(
|
|
433
|
+
}), this.toolCalls.get(s.toolCallIndex).argumentFragments.push(s.content);
|
|
434
434
|
break;
|
|
435
435
|
}
|
|
436
436
|
}
|
|
@@ -444,9 +444,9 @@ class Qe {
|
|
|
444
444
|
* Get the current accumulated message
|
|
445
445
|
* @param role - The role for the message (default: 'agent')
|
|
446
446
|
*/
|
|
447
|
-
getCurrentMessage(
|
|
448
|
-
const
|
|
449
|
-
this.textContent &&
|
|
447
|
+
getCurrentMessage(s = "agent") {
|
|
448
|
+
const t = [];
|
|
449
|
+
this.textContent && t.push({
|
|
450
450
|
type: "text",
|
|
451
451
|
text: this.textContent
|
|
452
452
|
});
|
|
@@ -460,7 +460,7 @@ class Qe {
|
|
|
460
460
|
} catch {
|
|
461
461
|
o = { _raw: r };
|
|
462
462
|
}
|
|
463
|
-
|
|
463
|
+
t.push({
|
|
464
464
|
type: "data",
|
|
465
465
|
data: {
|
|
466
466
|
toolCallId: n.toolCallId,
|
|
@@ -470,8 +470,8 @@ class Qe {
|
|
|
470
470
|
});
|
|
471
471
|
}
|
|
472
472
|
return {
|
|
473
|
-
role:
|
|
474
|
-
parts:
|
|
473
|
+
role: s,
|
|
474
|
+
parts: t,
|
|
475
475
|
kind: "message",
|
|
476
476
|
messageId: N()
|
|
477
477
|
};
|
|
@@ -483,71 +483,71 @@ class Qe {
|
|
|
483
483
|
this.textContent = "", this.toolCalls.clear();
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
|
-
function
|
|
487
|
-
throw clearTimeout(
|
|
486
|
+
function xe(e, s, t = "request") {
|
|
487
|
+
throw clearTimeout(s), M("%s failed with error: %O", t, e), e instanceof Error && (M("Error message: %s", e.message), M("Error stack: %s", e.stack)), e;
|
|
488
488
|
}
|
|
489
|
-
function Ce(e,
|
|
489
|
+
function Ce(e, s = "request") {
|
|
490
490
|
if (!e.ok)
|
|
491
491
|
throw new Error(`HTTP error! status: ${e.status}`);
|
|
492
492
|
}
|
|
493
|
-
function Xe(e,
|
|
493
|
+
function Xe(e, s = "request") {
|
|
494
494
|
if (e.error)
|
|
495
495
|
throw new Error(
|
|
496
|
-
`Protocol ${
|
|
496
|
+
`Protocol ${s} error: ${e.error.message}`
|
|
497
497
|
);
|
|
498
498
|
if (!e.result)
|
|
499
|
-
throw new Error(`No result in ${
|
|
499
|
+
throw new Error(`No result in ${s} response`);
|
|
500
500
|
return e.result;
|
|
501
501
|
}
|
|
502
|
-
function Ye(e,
|
|
503
|
-
if (Ce(e,
|
|
504
|
-
throw new Error(`No response body for ${
|
|
502
|
+
function Ye(e, s = "streaming request") {
|
|
503
|
+
if (Ce(e, s), !e.body)
|
|
504
|
+
throw new Error(`No response body for ${s}`);
|
|
505
505
|
}
|
|
506
|
-
function be(e,
|
|
507
|
-
const
|
|
506
|
+
function be(e, s = "request") {
|
|
507
|
+
const t = new AbortController();
|
|
508
508
|
return { timeoutId: setTimeout(
|
|
509
|
-
() =>
|
|
509
|
+
() => t.abort(),
|
|
510
510
|
e
|
|
511
|
-
), controller:
|
|
511
|
+
), controller: t };
|
|
512
512
|
}
|
|
513
|
-
function Ze(e,
|
|
514
|
-
return `${e}/${
|
|
513
|
+
function Ze(e, s) {
|
|
514
|
+
return `${e}/${s}`;
|
|
515
515
|
}
|
|
516
|
-
function et(e,
|
|
517
|
-
|
|
516
|
+
function et(e, s, t, a) {
|
|
517
|
+
M("Request: %s %s", e, s), M("Headers: %o", t), a && M("Body: %s", ve(a));
|
|
518
518
|
}
|
|
519
|
-
async function tt(e,
|
|
520
|
-
const
|
|
519
|
+
async function tt(e, s = !1) {
|
|
520
|
+
const t = {
|
|
521
521
|
"Content-Type": "application/json"
|
|
522
522
|
};
|
|
523
|
-
if (
|
|
523
|
+
if (s && (t.Accept = "text/event-stream"), e) {
|
|
524
524
|
const a = await e();
|
|
525
|
-
return { ...
|
|
525
|
+
return { ...t, ...a };
|
|
526
526
|
}
|
|
527
|
-
return
|
|
527
|
+
return t;
|
|
528
528
|
}
|
|
529
|
-
function ke(e,
|
|
530
|
-
if (!
|
|
529
|
+
function ke(e, s) {
|
|
530
|
+
if (!s)
|
|
531
531
|
return e;
|
|
532
|
-
const
|
|
533
|
-
|
|
532
|
+
const t = new AbortController(), a = (n) => {
|
|
533
|
+
t.signal.aborted || t.abort(n.reason);
|
|
534
534
|
};
|
|
535
|
-
return e.aborted ?
|
|
535
|
+
return e.aborted ? t.abort(e.reason) : e.addEventListener("abort", () => a(e), {
|
|
536
536
|
once: !0
|
|
537
|
-
}),
|
|
537
|
+
}), s.aborted ? t.abort(s.reason) : s.addEventListener("abort", () => a(s), {
|
|
538
538
|
once: !0
|
|
539
|
-
}),
|
|
539
|
+
}), t.signal;
|
|
540
540
|
}
|
|
541
|
-
function
|
|
541
|
+
function Pe(e, s, t) {
|
|
542
542
|
return {
|
|
543
543
|
method: "POST",
|
|
544
544
|
headers: e,
|
|
545
|
-
body:
|
|
546
|
-
signal:
|
|
545
|
+
body: s,
|
|
546
|
+
signal: t
|
|
547
547
|
};
|
|
548
548
|
}
|
|
549
|
-
async function Y(e,
|
|
550
|
-
const { message: o, sessionId: c, taskId: l, metadata: d } = e, { agentId: u, agentUrl: p, authProvider: m, proxy: f } =
|
|
549
|
+
async function Y(e, s, t, a, n, r) {
|
|
550
|
+
const { message: o, sessionId: c, taskId: l, metadata: d } = e, { agentId: u, agentUrl: p, authProvider: m, proxy: f } = s, { isStreaming: w = !1, enableTokenStreaming: h = !1 } = t, x = c || r, g = Ze(p, u), i = await Ve(
|
|
551
551
|
o,
|
|
552
552
|
a,
|
|
553
553
|
n
|
|
@@ -556,7 +556,7 @@ async function Y(e, t, s, a, n, r) {
|
|
|
556
556
|
message: i,
|
|
557
557
|
metadata: d
|
|
558
558
|
};
|
|
559
|
-
|
|
559
|
+
x && (T.sessionId = x);
|
|
560
560
|
const S = De(
|
|
561
561
|
T,
|
|
562
562
|
w ? "message/stream" : "message/send",
|
|
@@ -567,49 +567,49 @@ async function Y(e, t, s, a, n, r) {
|
|
|
567
567
|
request: S,
|
|
568
568
|
headers: I,
|
|
569
569
|
enhancedMessage: i,
|
|
570
|
-
effectiveSessionId:
|
|
570
|
+
effectiveSessionId: x,
|
|
571
571
|
fullAgentUrl: g
|
|
572
572
|
};
|
|
573
573
|
}
|
|
574
|
-
async function
|
|
575
|
-
const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o } =
|
|
574
|
+
async function Re(e, s, t = {}) {
|
|
575
|
+
const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o } = s, { abortSignal: c } = t, { timeoutId: l, controller: d } = be(
|
|
576
576
|
o,
|
|
577
577
|
"request"
|
|
578
578
|
), u = c ? ke(d.signal, c) : d.signal;
|
|
579
579
|
try {
|
|
580
|
-
const p =
|
|
580
|
+
const p = Pe(
|
|
581
581
|
n,
|
|
582
582
|
JSON.stringify(a),
|
|
583
583
|
u
|
|
584
584
|
);
|
|
585
|
-
|
|
585
|
+
M("Making request to %s with options: %O", r, {
|
|
586
586
|
method: p.method,
|
|
587
587
|
headers: p.headers
|
|
588
588
|
});
|
|
589
589
|
const m = await fetch(r, p);
|
|
590
590
|
clearTimeout(l), Ce(m, "request");
|
|
591
591
|
const f = await m.json();
|
|
592
|
-
return
|
|
592
|
+
return M(
|
|
593
593
|
"Response from %s: %d %O",
|
|
594
594
|
r,
|
|
595
595
|
m.status,
|
|
596
|
-
|
|
596
|
+
ve(f)
|
|
597
597
|
), Xe(f, "request");
|
|
598
598
|
} catch (p) {
|
|
599
|
-
|
|
599
|
+
xe(p, l, "request");
|
|
600
600
|
}
|
|
601
601
|
}
|
|
602
|
-
async function* _e(e,
|
|
602
|
+
async function* _e(e, s, t) {
|
|
603
603
|
const { request: a, headers: n, fullAgentUrl: r } = e, {
|
|
604
604
|
streamingTimeout: o = 6e4,
|
|
605
605
|
abortSignal: c,
|
|
606
606
|
enableTokenStreaming: l = !1
|
|
607
|
-
} =
|
|
607
|
+
} = t, { timeoutId: d, controller: u } = be(
|
|
608
608
|
o,
|
|
609
609
|
"streaming request"
|
|
610
610
|
), p = c ? ke(u.signal, c) : u.signal;
|
|
611
611
|
try {
|
|
612
|
-
const m = JSON.stringify(a), f =
|
|
612
|
+
const m = JSON.stringify(a), f = Pe(n, m, p), w = await fetch(r, f);
|
|
613
613
|
if (clearTimeout(d), Ye(w, "streaming request"), !w.body)
|
|
614
614
|
throw new Error(
|
|
615
615
|
"Response body is null - server may not support streaming"
|
|
@@ -619,21 +619,21 @@ async function* _e(e, t, s) {
|
|
|
619
619
|
supportDeltas: h
|
|
620
620
|
});
|
|
621
621
|
} catch (m) {
|
|
622
|
-
|
|
622
|
+
xe(m, d, "streaming request");
|
|
623
623
|
}
|
|
624
624
|
}
|
|
625
625
|
const st = 12e4;
|
|
626
|
-
async function Z(e,
|
|
626
|
+
async function Z(e, s, t, a, n) {
|
|
627
627
|
if (e.getAbilities) {
|
|
628
628
|
const r = await e.getAbilities();
|
|
629
629
|
if (r.length > 0)
|
|
630
630
|
for (const o of r) {
|
|
631
631
|
const c = o.name.replace(/\//g, "__").replace(/-/g, "_");
|
|
632
|
-
if (
|
|
632
|
+
if (s === c || s === o.name) {
|
|
633
633
|
if (o.callback)
|
|
634
634
|
try {
|
|
635
635
|
const l = {
|
|
636
|
-
...
|
|
636
|
+
...t,
|
|
637
637
|
...a && { messageId: a }
|
|
638
638
|
}, d = await o.callback(l);
|
|
639
639
|
return {
|
|
@@ -644,7 +644,7 @@ async function Z(e, t, s, a, n) {
|
|
|
644
644
|
}
|
|
645
645
|
};
|
|
646
646
|
} catch (l) {
|
|
647
|
-
return
|
|
647
|
+
return M(
|
|
648
648
|
"Error executing ability %s: %O",
|
|
649
649
|
o.name,
|
|
650
650
|
l
|
|
@@ -660,10 +660,10 @@ async function Z(e, t, s, a, n) {
|
|
|
660
660
|
try {
|
|
661
661
|
return { result: await e.executeAbility(
|
|
662
662
|
o.name,
|
|
663
|
-
|
|
663
|
+
t
|
|
664
664
|
), returnToAgent: !0 };
|
|
665
665
|
} catch (l) {
|
|
666
|
-
return
|
|
666
|
+
return M(
|
|
667
667
|
"Error executing ability %s: %O",
|
|
668
668
|
o.name,
|
|
669
669
|
l
|
|
@@ -683,25 +683,25 @@ async function Z(e, t, s, a, n) {
|
|
|
683
683
|
}
|
|
684
684
|
if (e.executeTool)
|
|
685
685
|
return await e.executeTool(
|
|
686
|
-
t,
|
|
687
686
|
s,
|
|
687
|
+
t,
|
|
688
688
|
a,
|
|
689
689
|
n
|
|
690
690
|
);
|
|
691
691
|
throw new Error(
|
|
692
|
-
`No handler found for tool: ${
|
|
692
|
+
`No handler found for tool: ${s}. Tool provider must implement executeTool for non-ability tools.`
|
|
693
693
|
);
|
|
694
694
|
}
|
|
695
695
|
const ge = /* @__PURE__ */ new Map();
|
|
696
|
-
async function at(e,
|
|
697
|
-
if (!e || !
|
|
696
|
+
async function at(e, s) {
|
|
697
|
+
if (!e || !s || !e.getAvailableTools)
|
|
698
698
|
return !1;
|
|
699
|
-
const
|
|
700
|
-
if (
|
|
699
|
+
const t = L(s);
|
|
700
|
+
if (t.length === 0)
|
|
701
701
|
return !1;
|
|
702
702
|
try {
|
|
703
703
|
const a = await e.getAvailableTools();
|
|
704
|
-
for (const n of
|
|
704
|
+
for (const n of t)
|
|
705
705
|
if (a.some(
|
|
706
706
|
(o) => o.id === n.data.toolId
|
|
707
707
|
))
|
|
@@ -715,35 +715,35 @@ function nt() {
|
|
|
715
715
|
ge.clear();
|
|
716
716
|
}
|
|
717
717
|
function ot(e) {
|
|
718
|
-
return e.map((
|
|
719
|
-
const
|
|
718
|
+
return e.map((s) => {
|
|
719
|
+
const t = s.data.toolCallId, a = ge.get(t);
|
|
720
720
|
if (a && a.resolvedValue !== null) {
|
|
721
721
|
const n = a.resolvedValue;
|
|
722
722
|
return n.error ? W(
|
|
723
|
-
|
|
724
|
-
|
|
723
|
+
t,
|
|
724
|
+
s.data.toolId,
|
|
725
725
|
void 0,
|
|
726
726
|
n.error
|
|
727
727
|
) : W(
|
|
728
|
-
|
|
729
|
-
|
|
728
|
+
t,
|
|
729
|
+
s.data.toolId,
|
|
730
730
|
n
|
|
731
731
|
);
|
|
732
732
|
}
|
|
733
|
-
return
|
|
733
|
+
return s;
|
|
734
734
|
});
|
|
735
735
|
}
|
|
736
|
-
async function Ee(e,
|
|
736
|
+
async function Ee(e, s, t) {
|
|
737
737
|
const a = [], n = [];
|
|
738
738
|
let r = !1;
|
|
739
739
|
for (const o of e) {
|
|
740
740
|
const { toolCallId: c, toolId: l, arguments: d } = o.data;
|
|
741
741
|
try {
|
|
742
742
|
const u = await Z(
|
|
743
|
-
|
|
743
|
+
s,
|
|
744
744
|
l,
|
|
745
745
|
d,
|
|
746
|
-
|
|
746
|
+
t,
|
|
747
747
|
c
|
|
748
748
|
), { result: p, returnToAgent: m, agentMessage: f } = de(u);
|
|
749
749
|
m && (r = !0), f && n.push(G(f)), a.push(
|
|
@@ -767,52 +767,52 @@ async function Ee(e, t, s) {
|
|
|
767
767
|
return { results: a, shouldReturnToAgent: r, agentMessages: n };
|
|
768
768
|
}
|
|
769
769
|
function ye(e) {
|
|
770
|
-
const
|
|
771
|
-
for (const
|
|
772
|
-
for (const a of
|
|
773
|
-
a.type === "text" ?
|
|
770
|
+
const s = [];
|
|
771
|
+
for (const t of e)
|
|
772
|
+
for (const a of t.parts)
|
|
773
|
+
a.type === "text" ? s.push({
|
|
774
774
|
type: "data",
|
|
775
775
|
data: {
|
|
776
|
-
role:
|
|
776
|
+
role: t.role,
|
|
777
777
|
text: a.text
|
|
778
778
|
}
|
|
779
|
-
}) : (a.type === "data" || a.type === "file") &&
|
|
780
|
-
return
|
|
779
|
+
}) : (a.type === "data" || a.type === "file") && s.push(a);
|
|
780
|
+
return s;
|
|
781
781
|
}
|
|
782
|
-
async function ae(e,
|
|
782
|
+
async function ae(e, s, t, a, n, r, o) {
|
|
783
783
|
const l = await Y(
|
|
784
784
|
{
|
|
785
|
-
message:
|
|
785
|
+
message: s,
|
|
786
786
|
taskId: e,
|
|
787
787
|
sessionId: void 0
|
|
788
788
|
// Use task's session
|
|
789
789
|
},
|
|
790
|
-
|
|
790
|
+
t,
|
|
791
791
|
{ isStreaming: !1 },
|
|
792
792
|
a,
|
|
793
793
|
n,
|
|
794
794
|
r
|
|
795
795
|
);
|
|
796
|
-
return await
|
|
796
|
+
return await Re(l, t, {
|
|
797
797
|
abortSignal: o
|
|
798
798
|
});
|
|
799
799
|
}
|
|
800
|
-
async function Ie(e,
|
|
800
|
+
async function Ie(e, s, t, a, n, r, o, c, l = []) {
|
|
801
801
|
const d = {
|
|
802
|
-
message:
|
|
802
|
+
message: s,
|
|
803
803
|
taskId: e,
|
|
804
804
|
sessionId: r
|
|
805
805
|
// Use the provided sessionId to maintain conversation continuity
|
|
806
806
|
}, u = c || { isStreaming: !0 }, p = await Y(
|
|
807
807
|
d,
|
|
808
|
-
|
|
808
|
+
t,
|
|
809
809
|
{
|
|
810
810
|
...u
|
|
811
811
|
},
|
|
812
812
|
a,
|
|
813
813
|
n,
|
|
814
814
|
r
|
|
815
|
-
), m = _e(p,
|
|
815
|
+
), m = _e(p, t, {
|
|
816
816
|
...u,
|
|
817
817
|
abortSignal: o
|
|
818
818
|
});
|
|
@@ -820,7 +820,7 @@ async function Ie(e, t, s, a, n, r, o, c, l = []) {
|
|
|
820
820
|
m,
|
|
821
821
|
a,
|
|
822
822
|
n,
|
|
823
|
-
|
|
823
|
+
t,
|
|
824
824
|
r,
|
|
825
825
|
!0,
|
|
826
826
|
// withHistory
|
|
@@ -831,26 +831,26 @@ async function Ie(e, t, s, a, n, r, o, c, l = []) {
|
|
|
831
831
|
// Pass through the same request options
|
|
832
832
|
);
|
|
833
833
|
}
|
|
834
|
-
async function* Oe(e,
|
|
835
|
-
var d, u, p, m, f, w, h,
|
|
834
|
+
async function* Oe(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
835
|
+
var d, u, p, m, f, w, h, x, g, i, T, S;
|
|
836
836
|
for await (const I of e) {
|
|
837
|
-
if (I.sessionId && !n && (n = I.sessionId), yield I, I.status.state === "running" && I.status.message &&
|
|
838
|
-
|
|
837
|
+
if (I.sessionId && !n && (n = I.sessionId), yield I, I.status.state === "running" && I.status.message && s && await at(
|
|
838
|
+
s,
|
|
839
839
|
I.status.message
|
|
840
840
|
)) {
|
|
841
841
|
const _ = L(
|
|
842
842
|
I.status.message
|
|
843
843
|
);
|
|
844
844
|
for (const O of _) {
|
|
845
|
-
const { toolCallId: $, toolId:
|
|
845
|
+
const { toolCallId: $, toolId: A, arguments: y } = O.data;
|
|
846
846
|
Z(
|
|
847
|
-
|
|
848
|
-
|
|
847
|
+
s,
|
|
848
|
+
A,
|
|
849
849
|
y,
|
|
850
850
|
(u = (d = I.status) == null ? void 0 : d.message) == null ? void 0 : u.messageId,
|
|
851
851
|
$
|
|
852
852
|
).catch((C) => {
|
|
853
|
-
|
|
853
|
+
M("Tool execution failed for %s: %O", A, C);
|
|
854
854
|
});
|
|
855
855
|
}
|
|
856
856
|
yield {
|
|
@@ -868,44 +868,44 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
868
868
|
text: ""
|
|
869
869
|
};
|
|
870
870
|
}
|
|
871
|
-
if (I.status.state === "input-required" && I.status.message &&
|
|
871
|
+
if (I.status.state === "input-required" && I.status.message && s) {
|
|
872
872
|
const _ = L(
|
|
873
873
|
I.status.message
|
|
874
874
|
);
|
|
875
875
|
if (_.length > 0) {
|
|
876
876
|
const O = [];
|
|
877
877
|
let $ = !1;
|
|
878
|
-
const
|
|
878
|
+
const A = [], y = [];
|
|
879
879
|
for (const C of _) {
|
|
880
880
|
const {
|
|
881
|
-
toolCallId:
|
|
882
|
-
toolId:
|
|
881
|
+
toolCallId: v,
|
|
882
|
+
toolId: P,
|
|
883
883
|
arguments: k
|
|
884
884
|
} = C.data;
|
|
885
885
|
try {
|
|
886
886
|
const b = await Z(
|
|
887
|
-
|
|
888
|
-
|
|
887
|
+
s,
|
|
888
|
+
P,
|
|
889
889
|
k,
|
|
890
890
|
(m = (p = I.status) == null ? void 0 : p.message) == null ? void 0 : m.messageId,
|
|
891
|
-
|
|
892
|
-
), { result:
|
|
891
|
+
v
|
|
892
|
+
), { result: R, returnToAgent: U, agentMessage: D } = de(b);
|
|
893
893
|
if (U && ($ = !0), D && y.push(
|
|
894
894
|
G(D)
|
|
895
|
-
),
|
|
896
|
-
const E =
|
|
895
|
+
), R.result instanceof Promise) {
|
|
896
|
+
const E = R.result, J = {
|
|
897
897
|
promise: E,
|
|
898
898
|
resolvedValue: null
|
|
899
899
|
};
|
|
900
900
|
ge.set(
|
|
901
|
-
|
|
901
|
+
v,
|
|
902
902
|
J
|
|
903
903
|
), E.then((H) => {
|
|
904
904
|
J.resolvedValue = H;
|
|
905
905
|
}).catch((H) => {
|
|
906
|
-
|
|
906
|
+
M(
|
|
907
907
|
"Promise rejected for tool call %s: %O",
|
|
908
|
-
|
|
908
|
+
v,
|
|
909
909
|
H
|
|
910
910
|
), J.resolvedValue = {
|
|
911
911
|
error: H instanceof Error ? H.message : String(H)
|
|
@@ -913,19 +913,19 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
913
913
|
});
|
|
914
914
|
}
|
|
915
915
|
const q = W(
|
|
916
|
-
|
|
917
|
-
|
|
918
|
-
|
|
916
|
+
v,
|
|
917
|
+
P,
|
|
918
|
+
R
|
|
919
919
|
);
|
|
920
|
-
O.push(q),
|
|
920
|
+
O.push(q), A.push(q);
|
|
921
921
|
} catch (b) {
|
|
922
|
-
const
|
|
923
|
-
|
|
924
|
-
|
|
922
|
+
const R = W(
|
|
923
|
+
v,
|
|
924
|
+
P,
|
|
925
925
|
void 0,
|
|
926
926
|
b instanceof Error ? b.message : String(b)
|
|
927
927
|
);
|
|
928
|
-
O.push(
|
|
928
|
+
O.push(R), A.push(R);
|
|
929
929
|
}
|
|
930
930
|
}
|
|
931
931
|
if (o.push(I.status.message), O.length > 0 && o.push({
|
|
@@ -934,7 +934,7 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
934
934
|
parts: O,
|
|
935
935
|
messageId: N()
|
|
936
936
|
}), $) {
|
|
937
|
-
const C = ye(o),
|
|
937
|
+
const C = ye(o), v = X(
|
|
938
938
|
[],
|
|
939
939
|
// Empty array - tool results are already in historyDataParts
|
|
940
940
|
C
|
|
@@ -943,24 +943,24 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
943
943
|
id: I.id,
|
|
944
944
|
status: {
|
|
945
945
|
state: "working",
|
|
946
|
-
message:
|
|
946
|
+
message: v
|
|
947
947
|
},
|
|
948
948
|
final: !1,
|
|
949
949
|
text: ""
|
|
950
950
|
};
|
|
951
|
-
const
|
|
951
|
+
const P = await Ie(
|
|
952
952
|
I.id,
|
|
953
|
-
|
|
953
|
+
v,
|
|
954
954
|
a,
|
|
955
|
-
t,
|
|
956
955
|
s,
|
|
956
|
+
t,
|
|
957
957
|
n,
|
|
958
958
|
c,
|
|
959
959
|
l,
|
|
960
960
|
o
|
|
961
961
|
);
|
|
962
962
|
let k = null;
|
|
963
|
-
for await (const U of
|
|
963
|
+
for await (const U of P)
|
|
964
964
|
U.final ? k = U : yield U;
|
|
965
965
|
if (!k)
|
|
966
966
|
throw new Error(
|
|
@@ -968,7 +968,7 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
968
968
|
);
|
|
969
969
|
let b = (f = k.status) != null && f.message ? L(
|
|
970
970
|
k.status.message
|
|
971
|
-
) : [],
|
|
971
|
+
) : [], R = k;
|
|
972
972
|
if (b.length > 0)
|
|
973
973
|
for (yield {
|
|
974
974
|
...k,
|
|
@@ -980,19 +980,19 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
980
980
|
}
|
|
981
981
|
)
|
|
982
982
|
}; b.length > 0; ) {
|
|
983
|
-
(h =
|
|
984
|
-
|
|
983
|
+
(h = R.status) != null && h.message && o.push(
|
|
984
|
+
R.status.message
|
|
985
985
|
);
|
|
986
986
|
const {
|
|
987
987
|
results: U,
|
|
988
988
|
shouldReturnToAgent: D
|
|
989
989
|
} = await Ee(
|
|
990
990
|
b,
|
|
991
|
-
|
|
992
|
-
(g = (
|
|
991
|
+
s,
|
|
992
|
+
(g = (x = R.status) == null ? void 0 : x.message) == null ? void 0 : g.messageId
|
|
993
993
|
);
|
|
994
994
|
if (U.length > 0 && (yield {
|
|
995
|
-
id:
|
|
995
|
+
id: R.id,
|
|
996
996
|
status: {
|
|
997
997
|
state: "working",
|
|
998
998
|
message: {
|
|
@@ -1012,11 +1012,11 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1012
1012
|
U,
|
|
1013
1013
|
q
|
|
1014
1014
|
), J = await Ie(
|
|
1015
|
-
|
|
1015
|
+
R.id,
|
|
1016
1016
|
E,
|
|
1017
1017
|
a,
|
|
1018
|
-
t,
|
|
1019
1018
|
s,
|
|
1019
|
+
t,
|
|
1020
1020
|
n,
|
|
1021
1021
|
c,
|
|
1022
1022
|
l,
|
|
@@ -1029,14 +1029,14 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1029
1029
|
throw new Error(
|
|
1030
1030
|
"Continue task stream ended without final result"
|
|
1031
1031
|
);
|
|
1032
|
-
|
|
1033
|
-
|
|
1032
|
+
R = H, b = (i = R.status) != null && i.message ? L(
|
|
1033
|
+
R.status.message
|
|
1034
1034
|
) : [], b.length > 0 && (yield {
|
|
1035
|
-
id:
|
|
1036
|
-
status:
|
|
1035
|
+
id: R.id,
|
|
1036
|
+
status: R.status,
|
|
1037
1037
|
final: !1,
|
|
1038
1038
|
text: j(
|
|
1039
|
-
((T =
|
|
1039
|
+
((T = R.status) == null ? void 0 : T.message) || {
|
|
1040
1040
|
parts: [],
|
|
1041
1041
|
messageId: N()
|
|
1042
1042
|
}
|
|
@@ -1046,10 +1046,10 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1046
1046
|
break;
|
|
1047
1047
|
}
|
|
1048
1048
|
yield {
|
|
1049
|
-
...
|
|
1049
|
+
...R,
|
|
1050
1050
|
final: !0,
|
|
1051
1051
|
text: j(
|
|
1052
|
-
((S =
|
|
1052
|
+
((S = R.status) == null ? void 0 : S.message) || {
|
|
1053
1053
|
parts: [],
|
|
1054
1054
|
messageId: N()
|
|
1055
1055
|
}
|
|
@@ -1058,8 +1058,8 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1058
1058
|
} else {
|
|
1059
1059
|
const C = {
|
|
1060
1060
|
...I.status.message,
|
|
1061
|
-
parts:
|
|
1062
|
-
},
|
|
1061
|
+
parts: A
|
|
1062
|
+
}, v = {
|
|
1063
1063
|
...I,
|
|
1064
1064
|
status: {
|
|
1065
1065
|
...I.status,
|
|
@@ -1069,16 +1069,16 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1069
1069
|
// Only final if no agent messages to follow
|
|
1070
1070
|
text: j(C)
|
|
1071
1071
|
};
|
|
1072
|
-
if (yield
|
|
1073
|
-
const
|
|
1072
|
+
if (yield v, y.length > 0) {
|
|
1073
|
+
const P = y.map((b) => j(b)).join(" "), k = G(P);
|
|
1074
1074
|
yield {
|
|
1075
|
-
id:
|
|
1075
|
+
id: v.id,
|
|
1076
1076
|
status: {
|
|
1077
1077
|
state: "completed",
|
|
1078
1078
|
message: k
|
|
1079
1079
|
},
|
|
1080
1080
|
final: !0,
|
|
1081
|
-
text:
|
|
1081
|
+
text: P
|
|
1082
1082
|
};
|
|
1083
1083
|
}
|
|
1084
1084
|
}
|
|
@@ -1088,8 +1088,8 @@ async function* Oe(e, t, s, a, n, r = !0, o = [], c, l) {
|
|
|
1088
1088
|
}
|
|
1089
1089
|
function rt(e) {
|
|
1090
1090
|
const {
|
|
1091
|
-
agentId:
|
|
1092
|
-
agentUrl:
|
|
1091
|
+
agentId: s,
|
|
1092
|
+
agentUrl: t,
|
|
1093
1093
|
authProvider: a,
|
|
1094
1094
|
defaultSessionId: n,
|
|
1095
1095
|
timeout: r = st,
|
|
@@ -1097,8 +1097,8 @@ function rt(e) {
|
|
|
1097
1097
|
contextProvider: c,
|
|
1098
1098
|
enableStreaming: l = !1
|
|
1099
1099
|
} = e, d = {
|
|
1100
|
-
agentId:
|
|
1101
|
-
agentUrl:
|
|
1100
|
+
agentId: s,
|
|
1101
|
+
agentUrl: t,
|
|
1102
1102
|
authProvider: a,
|
|
1103
1103
|
timeout: r
|
|
1104
1104
|
};
|
|
@@ -1115,50 +1115,50 @@ function rt(e) {
|
|
|
1115
1115
|
c,
|
|
1116
1116
|
m
|
|
1117
1117
|
);
|
|
1118
|
-
let h = await
|
|
1118
|
+
let h = await Re(
|
|
1119
1119
|
w,
|
|
1120
1120
|
d,
|
|
1121
1121
|
{ abortSignal: p }
|
|
1122
1122
|
);
|
|
1123
|
-
const
|
|
1123
|
+
const x = [], g = [];
|
|
1124
1124
|
for (; h.status.message && o; ) {
|
|
1125
1125
|
const S = L(
|
|
1126
1126
|
h.status.message
|
|
1127
1127
|
);
|
|
1128
1128
|
if (S.length === 0)
|
|
1129
1129
|
break;
|
|
1130
|
-
|
|
1130
|
+
x.push(...S);
|
|
1131
1131
|
const I = [];
|
|
1132
1132
|
let _ = !1;
|
|
1133
1133
|
for (const O of S) {
|
|
1134
1134
|
const {
|
|
1135
1135
|
toolCallId: $,
|
|
1136
|
-
toolId:
|
|
1136
|
+
toolId: A,
|
|
1137
1137
|
arguments: y
|
|
1138
1138
|
} = O.data;
|
|
1139
1139
|
try {
|
|
1140
1140
|
const C = await Z(
|
|
1141
1141
|
o,
|
|
1142
|
-
|
|
1142
|
+
A,
|
|
1143
1143
|
y
|
|
1144
|
-
), { result:
|
|
1145
|
-
|
|
1144
|
+
), { result: v, returnToAgent: P, agentMessage: k } = de(C);
|
|
1145
|
+
P && (_ = !0), k && g.push(
|
|
1146
1146
|
G(k)
|
|
1147
1147
|
);
|
|
1148
1148
|
const b = W(
|
|
1149
1149
|
$,
|
|
1150
|
-
|
|
1151
|
-
|
|
1150
|
+
A,
|
|
1151
|
+
v
|
|
1152
1152
|
);
|
|
1153
|
-
I.push(b),
|
|
1153
|
+
I.push(b), x.push(b);
|
|
1154
1154
|
} catch (C) {
|
|
1155
|
-
const
|
|
1155
|
+
const v = W(
|
|
1156
1156
|
$,
|
|
1157
|
-
|
|
1157
|
+
A,
|
|
1158
1158
|
void 0,
|
|
1159
1159
|
C instanceof Error ? C.message : String(C)
|
|
1160
1160
|
);
|
|
1161
|
-
I.push(
|
|
1161
|
+
I.push(v), x.push(v);
|
|
1162
1162
|
}
|
|
1163
1163
|
}
|
|
1164
1164
|
if (f.push(h.status.message), _) {
|
|
@@ -1175,10 +1175,10 @@ function rt(e) {
|
|
|
1175
1175
|
} else
|
|
1176
1176
|
break;
|
|
1177
1177
|
}
|
|
1178
|
-
if (
|
|
1178
|
+
if (x.length > 0 && (i = h.status) != null && i.message) {
|
|
1179
1179
|
const S = {
|
|
1180
1180
|
...h.status.message,
|
|
1181
|
-
parts:
|
|
1181
|
+
parts: x
|
|
1182
1182
|
};
|
|
1183
1183
|
h = {
|
|
1184
1184
|
...h,
|
|
@@ -1214,8 +1214,8 @@ function rt(e) {
|
|
|
1214
1214
|
withHistory: p = !0,
|
|
1215
1215
|
abortSignal: m,
|
|
1216
1216
|
enableStreaming: f
|
|
1217
|
-
} = u, w = u.sessionId || n || void 0, h = f ?? l,
|
|
1218
|
-
|
|
1217
|
+
} = u, w = u.sessionId || n || void 0, h = f ?? l, x = [];
|
|
1218
|
+
x.push(u.message);
|
|
1219
1219
|
const g = await Y(
|
|
1220
1220
|
u,
|
|
1221
1221
|
d,
|
|
@@ -1244,7 +1244,7 @@ function rt(e) {
|
|
|
1244
1244
|
d,
|
|
1245
1245
|
w,
|
|
1246
1246
|
p,
|
|
1247
|
-
|
|
1247
|
+
x,
|
|
1248
1248
|
m,
|
|
1249
1249
|
{
|
|
1250
1250
|
isStreaming: !0,
|
|
@@ -1254,7 +1254,7 @@ function rt(e) {
|
|
|
1254
1254
|
);
|
|
1255
1255
|
},
|
|
1256
1256
|
async continueTask(u, p, m) {
|
|
1257
|
-
var
|
|
1257
|
+
var x;
|
|
1258
1258
|
const f = ie(p);
|
|
1259
1259
|
let h = await ae(
|
|
1260
1260
|
u,
|
|
@@ -1287,7 +1287,7 @@ function rt(e) {
|
|
|
1287
1287
|
return {
|
|
1288
1288
|
...h,
|
|
1289
1289
|
text: j(
|
|
1290
|
-
((
|
|
1290
|
+
((x = h.status) == null ? void 0 : x.message) || {
|
|
1291
1291
|
parts: [],
|
|
1292
1292
|
messageId: N()
|
|
1293
1293
|
}
|
|
@@ -1303,17 +1303,17 @@ function rt(e) {
|
|
|
1303
1303
|
};
|
|
1304
1304
|
}
|
|
1305
1305
|
function it(e) {
|
|
1306
|
-
const
|
|
1306
|
+
const s = [];
|
|
1307
1307
|
if (e.content) {
|
|
1308
1308
|
const r = {
|
|
1309
1309
|
type: "text",
|
|
1310
1310
|
text: e.content
|
|
1311
1311
|
};
|
|
1312
|
-
|
|
1312
|
+
s.push(r);
|
|
1313
1313
|
}
|
|
1314
|
-
const
|
|
1315
|
-
if (
|
|
1316
|
-
for (const r of
|
|
1314
|
+
const t = e.context;
|
|
1315
|
+
if (t && !Array.isArray(t) && Array.isArray(t.file_parts)) {
|
|
1316
|
+
for (const r of t.file_parts)
|
|
1317
1317
|
if (r != null && r.uri) {
|
|
1318
1318
|
const o = {
|
|
1319
1319
|
type: "file",
|
|
@@ -1324,16 +1324,23 @@ function it(e) {
|
|
|
1324
1324
|
// Pass attachment ID in metadata if available
|
|
1325
1325
|
metadata: r.id ? { id: r.id } : void 0
|
|
1326
1326
|
};
|
|
1327
|
-
|
|
1327
|
+
s.push(o);
|
|
1328
1328
|
}
|
|
1329
1329
|
}
|
|
1330
|
+
if (t && !Array.isArray(t) && Array.isArray(t.sources) && t.sources.length > 0) {
|
|
1331
|
+
const r = {
|
|
1332
|
+
type: "data",
|
|
1333
|
+
data: { sources: t.sources }
|
|
1334
|
+
};
|
|
1335
|
+
s.push(r);
|
|
1336
|
+
}
|
|
1330
1337
|
const a = e.role === "user" ? "user" : "agent", n = e.ts ? e.ts * 1e3 : (/* @__PURE__ */ new Date(
|
|
1331
1338
|
e.created_at.replace(" ", "T") + "Z"
|
|
1332
1339
|
)).getTime();
|
|
1333
1340
|
return {
|
|
1334
1341
|
role: a,
|
|
1335
1342
|
kind: "message",
|
|
1336
|
-
parts:
|
|
1343
|
+
parts: s,
|
|
1337
1344
|
messageId: N(),
|
|
1338
1345
|
metadata: {
|
|
1339
1346
|
timestamp: n,
|
|
@@ -1351,9 +1358,9 @@ function lt(e) {
|
|
|
1351
1358
|
return !1;
|
|
1352
1359
|
}
|
|
1353
1360
|
}
|
|
1354
|
-
function ct(e,
|
|
1361
|
+
function ct(e, s = !1) {
|
|
1355
1362
|
var r, o, c, l, d, u;
|
|
1356
|
-
const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!
|
|
1363
|
+
const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!s || lt(p)) : !0).map(it), n = {
|
|
1357
1364
|
currentPage: ((r = e.metadata) == null ? void 0 : r.current_page) ?? 1,
|
|
1358
1365
|
itemsPerPage: ((o = e.metadata) == null ? void 0 : o.items_per_page) ?? 10,
|
|
1359
1366
|
totalPages: ((c = e.metadata) == null ? void 0 : c.total_pages) ?? 1,
|
|
@@ -1368,23 +1375,23 @@ function ct(e, t = !1) {
|
|
|
1368
1375
|
};
|
|
1369
1376
|
}
|
|
1370
1377
|
class V extends Error {
|
|
1371
|
-
constructor(
|
|
1372
|
-
super(
|
|
1378
|
+
constructor(s, t, a) {
|
|
1379
|
+
super(s), this.statusCode = t, this.details = a, this.name = "ServerConversationError";
|
|
1373
1380
|
}
|
|
1374
1381
|
}
|
|
1375
1382
|
const fe = "https://public-api.wordpress.com";
|
|
1376
|
-
async function le(e,
|
|
1377
|
-
const { botId: r, apiBaseUrl: o = fe, authProvider: c } =
|
|
1383
|
+
async function le(e, s, t = 1, a = 50, n = !1) {
|
|
1384
|
+
const { botId: r, apiBaseUrl: o = fe, authProvider: c } = s;
|
|
1378
1385
|
if (!e || !r)
|
|
1379
1386
|
throw new Error(
|
|
1380
1387
|
"chatId and botId are required to load conversation from server"
|
|
1381
1388
|
);
|
|
1382
|
-
const l = Math.max(1, Math.min(
|
|
1389
|
+
const l = Math.max(1, Math.min(t, 100)), d = Math.max(1, Math.min(a, 100)), u = new URL(
|
|
1383
1390
|
`${o}/wpcom/v2/odie/chat/${encodeURIComponent(
|
|
1384
1391
|
r
|
|
1385
1392
|
)}/${encodeURIComponent(e)}`
|
|
1386
1393
|
);
|
|
1387
|
-
u.searchParams.set("page_number", l.toString()), u.searchParams.set("items_per_page", d.toString()),
|
|
1394
|
+
u.searchParams.set("page_number", l.toString()), u.searchParams.set("items_per_page", d.toString()), M(
|
|
1388
1395
|
"Loading conversation from server: %s (page %d)",
|
|
1389
1396
|
e,
|
|
1390
1397
|
l
|
|
@@ -1403,21 +1410,21 @@ async function le(e, t, s = 1, a = 50, n = !1) {
|
|
|
1403
1410
|
});
|
|
1404
1411
|
if (!m.ok) {
|
|
1405
1412
|
const h = await m.text();
|
|
1406
|
-
let
|
|
1413
|
+
let x = `Failed to load conversation from server: ${m.status} ${m.statusText}`;
|
|
1407
1414
|
try {
|
|
1408
1415
|
const i = JSON.parse(h);
|
|
1409
|
-
i.message && (
|
|
1416
|
+
i.message && (x = i.message);
|
|
1410
1417
|
} catch {
|
|
1411
1418
|
}
|
|
1412
1419
|
const g = new V(
|
|
1413
|
-
|
|
1420
|
+
x,
|
|
1414
1421
|
m.status,
|
|
1415
1422
|
h
|
|
1416
1423
|
);
|
|
1417
|
-
throw
|
|
1424
|
+
throw M("Failed to load conversation from server: %O", g), g;
|
|
1418
1425
|
}
|
|
1419
1426
|
const f = await m.json(), w = ct(f, n);
|
|
1420
|
-
return
|
|
1427
|
+
return M(
|
|
1421
1428
|
"Loaded %d messages from server (page %d/%d)",
|
|
1422
1429
|
w.messages.length,
|
|
1423
1430
|
w.pagination.currentPage,
|
|
@@ -1431,19 +1438,19 @@ async function le(e, t, s = 1, a = 50, n = !1) {
|
|
|
1431
1438
|
void 0,
|
|
1432
1439
|
p
|
|
1433
1440
|
);
|
|
1434
|
-
throw
|
|
1441
|
+
throw M("Network error loading conversation: %O", p), m;
|
|
1435
1442
|
}
|
|
1436
1443
|
}
|
|
1437
|
-
async function Kt(e,
|
|
1438
|
-
const { apiBaseUrl: a = fe, authProvider: n } =
|
|
1444
|
+
async function Kt(e, s, t = !1) {
|
|
1445
|
+
const { apiBaseUrl: a = fe, authProvider: n } = s, r = new URL(
|
|
1439
1446
|
`${a}/wpcom/v2/odie/conversations/${encodeURIComponent(
|
|
1440
1447
|
e
|
|
1441
1448
|
)}`
|
|
1442
1449
|
);
|
|
1443
1450
|
r.searchParams.set(
|
|
1444
1451
|
"truncation_method",
|
|
1445
|
-
|
|
1446
|
-
),
|
|
1452
|
+
t ? "first_message" : "last_message"
|
|
1453
|
+
), M("Listing conversations from server for bot: %s", e);
|
|
1447
1454
|
try {
|
|
1448
1455
|
const o = {
|
|
1449
1456
|
"Content-Type": "application/json"
|
|
@@ -1462,10 +1469,10 @@ async function Kt(e, t, s = !1) {
|
|
|
1462
1469
|
c.status,
|
|
1463
1470
|
d
|
|
1464
1471
|
);
|
|
1465
|
-
throw
|
|
1472
|
+
throw M("Failed to list conversations: %O", p), p;
|
|
1466
1473
|
}
|
|
1467
1474
|
const l = await c.json();
|
|
1468
|
-
return
|
|
1475
|
+
return M("Loaded %d conversations from server", l.length), l;
|
|
1469
1476
|
} catch (o) {
|
|
1470
1477
|
if (o instanceof V)
|
|
1471
1478
|
throw o;
|
|
@@ -1474,13 +1481,13 @@ async function Kt(e, t, s = !1) {
|
|
|
1474
1481
|
void 0,
|
|
1475
1482
|
o
|
|
1476
1483
|
);
|
|
1477
|
-
throw
|
|
1484
|
+
throw M("Network error listing conversations: %O", o), c;
|
|
1478
1485
|
}
|
|
1479
1486
|
}
|
|
1480
|
-
async function Lt(e,
|
|
1487
|
+
async function Lt(e, s, t = 10, a = !1) {
|
|
1481
1488
|
const n = await le(
|
|
1482
1489
|
e,
|
|
1483
|
-
|
|
1490
|
+
s,
|
|
1484
1491
|
1,
|
|
1485
1492
|
50,
|
|
1486
1493
|
a
|
|
@@ -1489,11 +1496,11 @@ async function Lt(e, t, s = 10, a = !1) {
|
|
|
1489
1496
|
return n;
|
|
1490
1497
|
const r = Math.min(
|
|
1491
1498
|
n.pagination.totalPages,
|
|
1492
|
-
|
|
1499
|
+
t
|
|
1493
1500
|
), o = [...n.messages], c = [];
|
|
1494
1501
|
for (let l = 2; l <= r; l++)
|
|
1495
1502
|
c.push(
|
|
1496
|
-
le(e,
|
|
1503
|
+
le(e, s, l, 50, a)
|
|
1497
1504
|
);
|
|
1498
1505
|
try {
|
|
1499
1506
|
const l = await Promise.all(c);
|
|
@@ -1509,7 +1516,7 @@ async function Lt(e, t, s = 10, a = !1) {
|
|
|
1509
1516
|
chatId: n.chatId
|
|
1510
1517
|
};
|
|
1511
1518
|
} catch (l) {
|
|
1512
|
-
return
|
|
1519
|
+
return M("Failed to load all pages: %O", l), {
|
|
1513
1520
|
messages: o,
|
|
1514
1521
|
pagination: n.pagination,
|
|
1515
1522
|
chatId: n.chatId
|
|
@@ -1519,10 +1526,10 @@ async function Lt(e, t, s = 10, a = !1) {
|
|
|
1519
1526
|
const me = "a8c_agenttic_conversation_history";
|
|
1520
1527
|
function ut(e) {
|
|
1521
1528
|
var p, m;
|
|
1522
|
-
const
|
|
1529
|
+
const s = e.parts.filter(
|
|
1523
1530
|
(f) => f.type === "text"
|
|
1524
|
-
),
|
|
1525
|
-
`), a =
|
|
1531
|
+
), t = s.map((f) => f.text).join(`
|
|
1532
|
+
`), a = s.some(
|
|
1526
1533
|
(f) => {
|
|
1527
1534
|
var w;
|
|
1528
1535
|
return ((w = f.metadata) == null ? void 0 : w.contentType) === "context";
|
|
@@ -1546,7 +1553,7 @@ function ut(e) {
|
|
|
1546
1553
|
})), l = n.length > 0 || r.length > 0 ? "agent" : e.role, d = ((p = e.metadata) == null ? void 0 : p.timestamp) ?? Date.now(), u = ((m = e.metadata) == null ? void 0 : m.archived) ?? void 0;
|
|
1547
1554
|
return {
|
|
1548
1555
|
role: l,
|
|
1549
|
-
content:
|
|
1556
|
+
content: t || "(No text content)",
|
|
1550
1557
|
timestamp: d,
|
|
1551
1558
|
...u !== void 0 && { archived: u },
|
|
1552
1559
|
...a && { contentType: a },
|
|
@@ -1556,8 +1563,8 @@ function ut(e) {
|
|
|
1556
1563
|
};
|
|
1557
1564
|
}
|
|
1558
1565
|
function dt(e) {
|
|
1559
|
-
const
|
|
1560
|
-
if (e.content && e.content !== "(No text content)" &&
|
|
1566
|
+
const s = [];
|
|
1567
|
+
if (e.content && e.content !== "(No text content)" && s.push({
|
|
1561
1568
|
type: "text",
|
|
1562
1569
|
text: e.content,
|
|
1563
1570
|
...e.contentType && {
|
|
@@ -1566,39 +1573,39 @@ function dt(e) {
|
|
|
1566
1573
|
}
|
|
1567
1574
|
}
|
|
1568
1575
|
}), e.files)
|
|
1569
|
-
for (const
|
|
1570
|
-
|
|
1576
|
+
for (const t of e.files)
|
|
1577
|
+
s.push({
|
|
1571
1578
|
type: "file",
|
|
1572
1579
|
file: {
|
|
1573
|
-
name:
|
|
1574
|
-
mimeType:
|
|
1575
|
-
uri:
|
|
1580
|
+
name: t.name,
|
|
1581
|
+
mimeType: t.mimeType,
|
|
1582
|
+
uri: t.uri
|
|
1576
1583
|
}
|
|
1577
1584
|
});
|
|
1578
1585
|
if (e.toolCalls)
|
|
1579
|
-
for (const
|
|
1580
|
-
|
|
1586
|
+
for (const t of e.toolCalls)
|
|
1587
|
+
s.push({
|
|
1581
1588
|
type: "data",
|
|
1582
1589
|
data: {
|
|
1583
|
-
toolCallId:
|
|
1584
|
-
toolId:
|
|
1585
|
-
arguments:
|
|
1590
|
+
toolCallId: t.toolCallId,
|
|
1591
|
+
toolId: t.toolId,
|
|
1592
|
+
arguments: t.arguments
|
|
1586
1593
|
}
|
|
1587
1594
|
});
|
|
1588
1595
|
if (e.toolResults)
|
|
1589
|
-
for (const
|
|
1590
|
-
|
|
1596
|
+
for (const t of e.toolResults)
|
|
1597
|
+
s.push({
|
|
1591
1598
|
type: "data",
|
|
1592
1599
|
data: {
|
|
1593
|
-
toolCallId:
|
|
1594
|
-
result:
|
|
1595
|
-
...
|
|
1600
|
+
toolCallId: t.toolCallId,
|
|
1601
|
+
result: t.result,
|
|
1602
|
+
...t.error && { error: t.error }
|
|
1596
1603
|
}
|
|
1597
1604
|
});
|
|
1598
1605
|
return {
|
|
1599
1606
|
role: e.role,
|
|
1600
1607
|
kind: "message",
|
|
1601
|
-
parts:
|
|
1608
|
+
parts: s,
|
|
1602
1609
|
messageId: N(),
|
|
1603
1610
|
metadata: {
|
|
1604
1611
|
timestamp: e.timestamp,
|
|
@@ -1610,9 +1617,9 @@ function dt(e) {
|
|
|
1610
1617
|
};
|
|
1611
1618
|
}
|
|
1612
1619
|
const B = /* @__PURE__ */ new Map(), gt = 50;
|
|
1613
|
-
async function ft(e,
|
|
1614
|
-
const a =
|
|
1615
|
-
if (B.set(a, [...
|
|
1620
|
+
async function ft(e, s, t) {
|
|
1621
|
+
const a = t || e;
|
|
1622
|
+
if (B.set(a, [...s]), B.size > gt) {
|
|
1616
1623
|
const n = B.keys().next().value;
|
|
1617
1624
|
n && B.delete(n);
|
|
1618
1625
|
}
|
|
@@ -1620,7 +1627,7 @@ async function ft(e, t, s) {
|
|
|
1620
1627
|
try {
|
|
1621
1628
|
const n = {
|
|
1622
1629
|
storageKey: a,
|
|
1623
|
-
messages:
|
|
1630
|
+
messages: s.map(ut),
|
|
1624
1631
|
lastUpdated: Date.now()
|
|
1625
1632
|
};
|
|
1626
1633
|
sessionStorage.setItem(
|
|
@@ -1628,36 +1635,36 @@ async function ft(e, t, s) {
|
|
|
1628
1635
|
JSON.stringify(n)
|
|
1629
1636
|
);
|
|
1630
1637
|
} catch (n) {
|
|
1631
|
-
|
|
1638
|
+
M(
|
|
1632
1639
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1633
1640
|
a,
|
|
1634
1641
|
n
|
|
1635
1642
|
);
|
|
1636
1643
|
}
|
|
1637
1644
|
}
|
|
1638
|
-
async function mt(e,
|
|
1639
|
-
return
|
|
1645
|
+
async function mt(e, s, t) {
|
|
1646
|
+
return t != null && t.odieBotId ? pt(e, t) : ht(
|
|
1640
1647
|
e,
|
|
1641
|
-
|
|
1648
|
+
s
|
|
1642
1649
|
);
|
|
1643
1650
|
}
|
|
1644
|
-
async function pt(e,
|
|
1645
|
-
const { odieBotId:
|
|
1646
|
-
if (!
|
|
1651
|
+
async function pt(e, s) {
|
|
1652
|
+
const { odieBotId: t, authProvider: a } = s;
|
|
1653
|
+
if (!t)
|
|
1647
1654
|
throw new Error("odieBotId is required for server storage");
|
|
1648
1655
|
const n = fe;
|
|
1649
1656
|
try {
|
|
1650
1657
|
const o = await le(
|
|
1651
1658
|
e,
|
|
1652
1659
|
{
|
|
1653
|
-
botId:
|
|
1660
|
+
botId: t,
|
|
1654
1661
|
apiBaseUrl: n,
|
|
1655
1662
|
authProvider: a
|
|
1656
1663
|
},
|
|
1657
1664
|
1,
|
|
1658
1665
|
50
|
|
1659
1666
|
);
|
|
1660
|
-
return
|
|
1667
|
+
return M(
|
|
1661
1668
|
"Loaded conversation from server: %s (%d messages, page %d/%d)",
|
|
1662
1669
|
e,
|
|
1663
1670
|
o.messages.length,
|
|
@@ -1668,52 +1675,52 @@ async function pt(e, t) {
|
|
|
1668
1675
|
pagination: o.pagination
|
|
1669
1676
|
};
|
|
1670
1677
|
} catch (r) {
|
|
1671
|
-
throw
|
|
1678
|
+
throw M("Failed to load conversation from server: %O", r), r;
|
|
1672
1679
|
}
|
|
1673
1680
|
}
|
|
1674
|
-
async function ht(e,
|
|
1675
|
-
const
|
|
1676
|
-
if (B.has(
|
|
1681
|
+
async function ht(e, s) {
|
|
1682
|
+
const t = s || e;
|
|
1683
|
+
if (B.has(t))
|
|
1677
1684
|
return {
|
|
1678
|
-
messages: [...B.get(
|
|
1685
|
+
messages: [...B.get(t)]
|
|
1679
1686
|
};
|
|
1680
1687
|
if (typeof sessionStorage > "u")
|
|
1681
1688
|
return { messages: [] };
|
|
1682
1689
|
try {
|
|
1683
1690
|
const a = sessionStorage.getItem(
|
|
1684
|
-
`${me}_${
|
|
1691
|
+
`${me}_${t}`
|
|
1685
1692
|
);
|
|
1686
1693
|
if (a) {
|
|
1687
1694
|
const r = JSON.parse(a).messages.map(dt);
|
|
1688
|
-
return B.set(
|
|
1695
|
+
return B.set(t, r), { messages: [...r] };
|
|
1689
1696
|
}
|
|
1690
1697
|
} catch (a) {
|
|
1691
|
-
|
|
1698
|
+
M(
|
|
1692
1699
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1693
|
-
|
|
1700
|
+
t,
|
|
1694
1701
|
a
|
|
1695
1702
|
);
|
|
1696
1703
|
}
|
|
1697
1704
|
return { messages: [] };
|
|
1698
1705
|
}
|
|
1699
|
-
async function yt(e,
|
|
1700
|
-
const
|
|
1701
|
-
if (B.delete(
|
|
1706
|
+
async function yt(e, s) {
|
|
1707
|
+
const t = s || e;
|
|
1708
|
+
if (B.delete(t), !(typeof sessionStorage > "u"))
|
|
1702
1709
|
try {
|
|
1703
|
-
sessionStorage.removeItem(`${me}_${
|
|
1710
|
+
sessionStorage.removeItem(`${me}_${t}`);
|
|
1704
1711
|
} catch (a) {
|
|
1705
|
-
|
|
1712
|
+
M(
|
|
1706
1713
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1707
|
-
|
|
1714
|
+
t,
|
|
1708
1715
|
a
|
|
1709
1716
|
);
|
|
1710
1717
|
}
|
|
1711
1718
|
}
|
|
1712
1719
|
function z(e) {
|
|
1713
|
-
const
|
|
1720
|
+
const s = e.parts.filter((t) => t.type === "text" ? !0 : t.type === "data" ? "role" in t.data && "text" in t.data ? !1 : !!("toolCallId" in t.data && "arguments" in t.data || "flags" in t.data && t.data.flags && typeof t.data.flags == "object" && "forward_to_human_support" in t.data.flags || "sources" in t.data && Array.isArray(t.data.sources) && t.data.sources.length > 0 || "toolCallId" in t.data && "result" in t.data) : !0);
|
|
1714
1721
|
return {
|
|
1715
1722
|
...e,
|
|
1716
|
-
parts:
|
|
1723
|
+
parts: s,
|
|
1717
1724
|
// Preserve metadata if it exists, otherwise add timestamp
|
|
1718
1725
|
metadata: e.metadata || {
|
|
1719
1726
|
timestamp: Date.now()
|
|
@@ -1721,35 +1728,35 @@ function z(e) {
|
|
|
1721
1728
|
};
|
|
1722
1729
|
}
|
|
1723
1730
|
function It(e) {
|
|
1724
|
-
const
|
|
1725
|
-
for (const
|
|
1726
|
-
for (const a of
|
|
1731
|
+
const s = [];
|
|
1732
|
+
for (const t of e)
|
|
1733
|
+
for (const a of t.parts)
|
|
1727
1734
|
if (a.type === "text")
|
|
1728
|
-
|
|
1735
|
+
s.push({
|
|
1729
1736
|
type: "data",
|
|
1730
1737
|
data: {
|
|
1731
|
-
role:
|
|
1738
|
+
role: t.role,
|
|
1732
1739
|
text: a.text
|
|
1733
1740
|
}
|
|
1734
1741
|
});
|
|
1735
1742
|
else if (a.type === "file")
|
|
1736
|
-
|
|
1743
|
+
s.push(a);
|
|
1737
1744
|
else if (a.type === "data") {
|
|
1738
1745
|
if ("role" in a.data && "text" in a.data)
|
|
1739
1746
|
continue;
|
|
1740
1747
|
if ("toolCallId" in a.data && "arguments" in a.data) {
|
|
1741
|
-
|
|
1748
|
+
s.push(a);
|
|
1742
1749
|
continue;
|
|
1743
1750
|
}
|
|
1744
1751
|
if ("toolCallId" in a.data && "result" in a.data) {
|
|
1745
|
-
|
|
1752
|
+
s.push(a);
|
|
1746
1753
|
continue;
|
|
1747
1754
|
}
|
|
1748
1755
|
}
|
|
1749
|
-
return
|
|
1756
|
+
return s;
|
|
1750
1757
|
}
|
|
1751
|
-
function we(e,
|
|
1752
|
-
const a = It(
|
|
1758
|
+
function we(e, s = [], t = []) {
|
|
1759
|
+
const a = It(s), n = t.map((r) => {
|
|
1753
1760
|
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";
|
|
1754
1761
|
return {
|
|
1755
1762
|
type: "file",
|
|
@@ -1780,67 +1787,67 @@ function we(e, t = [], s = []) {
|
|
|
1780
1787
|
}
|
|
1781
1788
|
function wt(e) {
|
|
1782
1789
|
return e != null && e.parts ? e.parts.filter(
|
|
1783
|
-
(
|
|
1790
|
+
(s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
|
|
1784
1791
|
) : [];
|
|
1785
1792
|
}
|
|
1786
|
-
function ne(e,
|
|
1793
|
+
function ne(e, s) {
|
|
1787
1794
|
if (typeof localStorage > "u") {
|
|
1788
1795
|
K("localStorage not available, cannot update session ID");
|
|
1789
1796
|
return;
|
|
1790
1797
|
}
|
|
1791
1798
|
try {
|
|
1792
|
-
const
|
|
1793
|
-
if (
|
|
1794
|
-
const a = JSON.parse(
|
|
1795
|
-
a.sessionId =
|
|
1799
|
+
const t = localStorage.getItem(e);
|
|
1800
|
+
if (t) {
|
|
1801
|
+
const a = JSON.parse(t), n = a.sessionId;
|
|
1802
|
+
a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)), K(
|
|
1796
1803
|
"Updated localStorage[%s] session ID: %s -> %s",
|
|
1797
1804
|
e,
|
|
1798
1805
|
n,
|
|
1799
|
-
|
|
1806
|
+
s
|
|
1800
1807
|
);
|
|
1801
1808
|
} else {
|
|
1802
1809
|
const a = {
|
|
1803
|
-
sessionId:
|
|
1810
|
+
sessionId: s,
|
|
1804
1811
|
timestamp: Date.now()
|
|
1805
1812
|
};
|
|
1806
1813
|
localStorage.setItem(e, JSON.stringify(a)), K(
|
|
1807
1814
|
"Created new session in localStorage[%s]: %s",
|
|
1808
1815
|
e,
|
|
1809
|
-
|
|
1816
|
+
s
|
|
1810
1817
|
);
|
|
1811
1818
|
}
|
|
1812
|
-
} catch (
|
|
1819
|
+
} catch (t) {
|
|
1813
1820
|
K(
|
|
1814
1821
|
"Failed to update localStorage sessionId to %s: %O",
|
|
1815
|
-
|
|
1816
|
-
|
|
1822
|
+
s,
|
|
1823
|
+
t
|
|
1817
1824
|
);
|
|
1818
1825
|
}
|
|
1819
1826
|
}
|
|
1820
1827
|
async function Tt(e) {
|
|
1821
|
-
const
|
|
1822
|
-
for (const
|
|
1823
|
-
if (
|
|
1824
|
-
if (
|
|
1828
|
+
const s = [];
|
|
1829
|
+
for (const t of e)
|
|
1830
|
+
if (t.parts && Array.isArray(t.parts))
|
|
1831
|
+
if (t.parts.some(
|
|
1825
1832
|
(n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
|
|
1826
1833
|
)) {
|
|
1827
1834
|
const n = ot(
|
|
1828
|
-
|
|
1835
|
+
t.parts
|
|
1829
1836
|
);
|
|
1830
|
-
|
|
1831
|
-
...
|
|
1837
|
+
s.push({
|
|
1838
|
+
...t,
|
|
1832
1839
|
parts: n
|
|
1833
1840
|
});
|
|
1834
1841
|
} else
|
|
1835
|
-
|
|
1842
|
+
s.push(t);
|
|
1836
1843
|
else
|
|
1837
|
-
|
|
1838
|
-
return nt(),
|
|
1844
|
+
s.push(t);
|
|
1845
|
+
return nt(), s;
|
|
1839
1846
|
}
|
|
1840
1847
|
function St() {
|
|
1841
1848
|
const e = /* @__PURE__ */ new Map();
|
|
1842
|
-
async function t
|
|
1843
|
-
const n = e.get(
|
|
1849
|
+
async function s(t, a) {
|
|
1850
|
+
const n = e.get(t);
|
|
1844
1851
|
if (n != null && n.sessionId)
|
|
1845
1852
|
try {
|
|
1846
1853
|
await ft(
|
|
@@ -1850,15 +1857,15 @@ function St() {
|
|
|
1850
1857
|
);
|
|
1851
1858
|
} catch (r) {
|
|
1852
1859
|
K(
|
|
1853
|
-
`Failed to persist conversation history for agent ${
|
|
1860
|
+
`Failed to persist conversation history for agent ${t}:`,
|
|
1854
1861
|
r
|
|
1855
1862
|
);
|
|
1856
1863
|
}
|
|
1857
1864
|
}
|
|
1858
1865
|
return {
|
|
1859
|
-
async createAgent(
|
|
1860
|
-
if (e.has(
|
|
1861
|
-
return e.get(
|
|
1866
|
+
async createAgent(t, a) {
|
|
1867
|
+
if (e.has(t))
|
|
1868
|
+
return e.get(t).client;
|
|
1862
1869
|
const n = rt(a), r = a.sessionId || null, o = a.conversationStorageKey, c = a.sessionIdStorageKey, l = {
|
|
1863
1870
|
odieBotId: a.odieBotId,
|
|
1864
1871
|
authProvider: a.authProvider
|
|
@@ -1873,7 +1880,7 @@ function St() {
|
|
|
1873
1880
|
)).messages;
|
|
1874
1881
|
} catch (p) {
|
|
1875
1882
|
K(
|
|
1876
|
-
`Failed to load conversation history for agent ${
|
|
1883
|
+
`Failed to load conversation history for agent ${t} with session ${r}:`,
|
|
1877
1884
|
p
|
|
1878
1885
|
);
|
|
1879
1886
|
}
|
|
@@ -1886,23 +1893,23 @@ function St() {
|
|
|
1886
1893
|
conversationHistory: d,
|
|
1887
1894
|
currentAbortController: null
|
|
1888
1895
|
};
|
|
1889
|
-
return e.set(
|
|
1896
|
+
return e.set(t, u), n;
|
|
1890
1897
|
},
|
|
1891
|
-
getAgent(
|
|
1892
|
-
const a = e.get(
|
|
1898
|
+
getAgent(t) {
|
|
1899
|
+
const a = e.get(t);
|
|
1893
1900
|
return (a == null ? void 0 : a.client) || null;
|
|
1894
1901
|
},
|
|
1895
|
-
hasAgent(
|
|
1896
|
-
return e.has(
|
|
1902
|
+
hasAgent(t) {
|
|
1903
|
+
return e.has(t);
|
|
1897
1904
|
},
|
|
1898
|
-
removeAgent(
|
|
1899
|
-
return e.delete(
|
|
1905
|
+
removeAgent(t) {
|
|
1906
|
+
return e.delete(t);
|
|
1900
1907
|
},
|
|
1901
|
-
async sendMessage(
|
|
1902
|
-
var
|
|
1903
|
-
const r = e.get(
|
|
1908
|
+
async sendMessage(t, a, n = {}) {
|
|
1909
|
+
var x;
|
|
1910
|
+
const r = e.get(t);
|
|
1904
1911
|
if (!r)
|
|
1905
|
-
throw new Error(`Agent with key "${
|
|
1912
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
1906
1913
|
const { withHistory: o = !0, sessionId: c, ...l } = n, { client: d, conversationHistory: u } = r, p = n.message || we(
|
|
1907
1914
|
a,
|
|
1908
1915
|
u,
|
|
@@ -1925,7 +1932,7 @@ function St() {
|
|
|
1925
1932
|
));
|
|
1926
1933
|
}
|
|
1927
1934
|
let f = null;
|
|
1928
|
-
if ((
|
|
1935
|
+
if ((x = m.status) != null && x.message) {
|
|
1929
1936
|
const g = m.status.message.parts.filter(
|
|
1930
1937
|
(T) => T.type === "data" && "toolCallId" in T.data && ("arguments" in T.data || "result" in T.data)
|
|
1931
1938
|
), i = m.status.message.parts.filter(
|
|
@@ -1958,23 +1965,23 @@ function St() {
|
|
|
1958
1965
|
g
|
|
1959
1966
|
];
|
|
1960
1967
|
}
|
|
1961
|
-
return r.conversationHistory = h, o && await
|
|
1962
|
-
|
|
1968
|
+
return r.conversationHistory = h, o && await s(
|
|
1969
|
+
t,
|
|
1963
1970
|
h
|
|
1964
1971
|
), m;
|
|
1965
1972
|
},
|
|
1966
|
-
async *sendMessageStream(
|
|
1973
|
+
async *sendMessageStream(t, a, n = {}) {
|
|
1967
1974
|
var T, S, I, _, O, $;
|
|
1968
|
-
const r = e.get(
|
|
1975
|
+
const r = e.get(t);
|
|
1969
1976
|
if (!r)
|
|
1970
|
-
throw new Error(`Agent with key "${
|
|
1977
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
1971
1978
|
const {
|
|
1972
1979
|
withHistory: o = !0,
|
|
1973
1980
|
abortSignal: c,
|
|
1974
1981
|
metadata: l,
|
|
1975
1982
|
sessionId: d,
|
|
1976
1983
|
...u
|
|
1977
|
-
} = n, { client: p } = r, m = l ? (({ contentType:
|
|
1984
|
+
} = n, { client: p } = r, m = l ? (({ contentType: A, ...y }) => y)(l) : void 0, f = new AbortController();
|
|
1978
1985
|
r.currentAbortController = f, c && c.addEventListener(
|
|
1979
1986
|
"abort",
|
|
1980
1987
|
() => f.abort()
|
|
@@ -1982,25 +1989,25 @@ function St() {
|
|
|
1982
1989
|
let w = [
|
|
1983
1990
|
...r.conversationHistory
|
|
1984
1991
|
], h = [];
|
|
1985
|
-
const
|
|
1992
|
+
const x = await Tt(
|
|
1986
1993
|
w
|
|
1987
1994
|
);
|
|
1988
|
-
r.conversationHistory =
|
|
1989
|
-
|
|
1990
|
-
|
|
1995
|
+
r.conversationHistory = x, w = x, o && await s(
|
|
1996
|
+
t,
|
|
1997
|
+
x
|
|
1991
1998
|
);
|
|
1992
1999
|
const g = n.message || we(
|
|
1993
2000
|
a,
|
|
1994
|
-
|
|
2001
|
+
x,
|
|
1995
2002
|
n.imageUrls
|
|
1996
2003
|
);
|
|
1997
2004
|
if (n.metadata && !n.message) {
|
|
1998
|
-
const { contentType:
|
|
1999
|
-
if (
|
|
2005
|
+
const { contentType: A, ...y } = n.metadata;
|
|
2006
|
+
if (A) {
|
|
2000
2007
|
const C = g.parts[g.parts.length - 1];
|
|
2001
2008
|
C && C.type === "text" && (C.metadata = {
|
|
2002
2009
|
...C.metadata,
|
|
2003
|
-
contentType:
|
|
2010
|
+
contentType: A
|
|
2004
2011
|
});
|
|
2005
2012
|
}
|
|
2006
2013
|
Object.keys(y).length > 0 && (g.metadata = {
|
|
@@ -2010,30 +2017,30 @@ function St() {
|
|
|
2010
2017
|
}
|
|
2011
2018
|
const i = ie(a, n.metadata);
|
|
2012
2019
|
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
2013
|
-
const
|
|
2020
|
+
const A = n.imageUrls.map(
|
|
2014
2021
|
(y) => {
|
|
2015
|
-
const C = typeof y == "string" ? y : y.url,
|
|
2022
|
+
const C = typeof y == "string" ? y : y.url, v = typeof y == "string" ? void 0 : y.metadata, P = (v == null ? void 0 : v.fileType) || "image/jpeg";
|
|
2016
2023
|
return {
|
|
2017
2024
|
type: "file",
|
|
2018
2025
|
file: {
|
|
2019
|
-
name: (
|
|
2020
|
-
mimeType:
|
|
2026
|
+
name: (v == null ? void 0 : v.fileName) || "image",
|
|
2027
|
+
mimeType: P,
|
|
2021
2028
|
uri: C
|
|
2022
2029
|
},
|
|
2023
|
-
metadata:
|
|
2030
|
+
metadata: v
|
|
2024
2031
|
};
|
|
2025
2032
|
}
|
|
2026
2033
|
);
|
|
2027
|
-
i.parts.push(...
|
|
2034
|
+
i.parts.push(...A);
|
|
2028
2035
|
}
|
|
2029
2036
|
w = [
|
|
2030
2037
|
...w,
|
|
2031
2038
|
i
|
|
2032
|
-
], r.conversationHistory = w, o && await
|
|
2033
|
-
|
|
2039
|
+
], r.conversationHistory = w, o && await s(
|
|
2040
|
+
t,
|
|
2034
2041
|
w
|
|
2035
2042
|
);
|
|
2036
|
-
for await (const
|
|
2043
|
+
for await (const A of p.sendMessageStream({
|
|
2037
2044
|
message: g,
|
|
2038
2045
|
withHistory: o,
|
|
2039
2046
|
sessionId: d || r.sessionId || void 0,
|
|
@@ -2043,43 +2050,43 @@ function St() {
|
|
|
2043
2050
|
metadata: m
|
|
2044
2051
|
}
|
|
2045
2052
|
})) {
|
|
2046
|
-
if (
|
|
2053
|
+
if (A.sessionId) {
|
|
2047
2054
|
const y = r.sessionId;
|
|
2048
|
-
r.sessionId =
|
|
2055
|
+
r.sessionId = A.sessionId, A.sessionId && y !== A.sessionId && r.sessionIdStorageKey && (K(
|
|
2049
2056
|
"Session ID %s, updating localStorage",
|
|
2050
|
-
y ? `changed from ${y} to ${
|
|
2057
|
+
y ? `changed from ${y} to ${A.sessionId}` : `received: ${A.sessionId}`
|
|
2051
2058
|
), ne(
|
|
2052
2059
|
r.sessionIdStorageKey,
|
|
2053
|
-
|
|
2060
|
+
A.sessionId
|
|
2054
2061
|
));
|
|
2055
2062
|
}
|
|
2056
|
-
if (((T =
|
|
2063
|
+
if (((T = A.status) == null ? void 0 : T.state) === "input-required" && ((S = A.status) != null && S.message)) {
|
|
2057
2064
|
h = L(
|
|
2058
|
-
|
|
2065
|
+
A.status.message
|
|
2059
2066
|
).map(
|
|
2060
|
-
(
|
|
2067
|
+
(v) => v.data.toolCallId
|
|
2061
2068
|
);
|
|
2062
2069
|
const C = z(
|
|
2063
|
-
|
|
2070
|
+
A.status.message
|
|
2064
2071
|
);
|
|
2065
2072
|
w = [
|
|
2066
2073
|
...w,
|
|
2067
2074
|
C
|
|
2068
|
-
], r.conversationHistory = w, o && await
|
|
2069
|
-
|
|
2075
|
+
], r.conversationHistory = w, o && await s(
|
|
2076
|
+
t,
|
|
2070
2077
|
w
|
|
2071
2078
|
);
|
|
2072
2079
|
}
|
|
2073
|
-
if (((I =
|
|
2080
|
+
if (((I = A.status) == null ? void 0 : I.state) === "working" && ((_ = A.status) != null && _.message) && !A.final) {
|
|
2074
2081
|
const C = wt(
|
|
2075
|
-
|
|
2082
|
+
A.status.message
|
|
2076
2083
|
).filter(
|
|
2077
|
-
(
|
|
2078
|
-
|
|
2084
|
+
(v) => h.includes(
|
|
2085
|
+
v.data.toolCallId
|
|
2079
2086
|
)
|
|
2080
2087
|
);
|
|
2081
2088
|
if (C.length > 0) {
|
|
2082
|
-
const
|
|
2089
|
+
const v = {
|
|
2083
2090
|
role: "agent",
|
|
2084
2091
|
kind: "message",
|
|
2085
2092
|
parts: C,
|
|
@@ -2087,64 +2094,64 @@ function St() {
|
|
|
2087
2094
|
};
|
|
2088
2095
|
w = [
|
|
2089
2096
|
...w,
|
|
2090
|
-
z(
|
|
2091
|
-
], r.conversationHistory = w, o && await
|
|
2092
|
-
|
|
2097
|
+
z(v)
|
|
2098
|
+
], r.conversationHistory = w, o && await s(
|
|
2099
|
+
t,
|
|
2093
2100
|
w
|
|
2094
2101
|
);
|
|
2095
2102
|
}
|
|
2096
2103
|
}
|
|
2097
|
-
if (
|
|
2104
|
+
if (A.final && ((O = A.status) == null ? void 0 : O.state) !== "input-required") {
|
|
2098
2105
|
h = [];
|
|
2099
2106
|
let y = null;
|
|
2100
|
-
($ =
|
|
2101
|
-
|
|
2107
|
+
($ = A.status) != null && $.message && (y = z(
|
|
2108
|
+
A.status.message
|
|
2102
2109
|
), w = [
|
|
2103
2110
|
...w,
|
|
2104
2111
|
y
|
|
2105
|
-
], r.conversationHistory = w, o && await
|
|
2106
|
-
|
|
2112
|
+
], r.conversationHistory = w, o && await s(
|
|
2113
|
+
t,
|
|
2107
2114
|
w
|
|
2108
2115
|
));
|
|
2109
2116
|
}
|
|
2110
|
-
yield
|
|
2117
|
+
yield A;
|
|
2111
2118
|
}
|
|
2112
2119
|
r.currentAbortController = null;
|
|
2113
2120
|
},
|
|
2114
|
-
async resetConversation(
|
|
2115
|
-
const a = e.get(
|
|
2121
|
+
async resetConversation(t) {
|
|
2122
|
+
const a = e.get(t);
|
|
2116
2123
|
if (!a)
|
|
2117
|
-
throw new Error(`Agent with key "${
|
|
2124
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2118
2125
|
a.conversationHistory = [], a.sessionId && await yt(
|
|
2119
2126
|
a.sessionId,
|
|
2120
2127
|
a.conversationStorageKey
|
|
2121
2128
|
);
|
|
2122
2129
|
},
|
|
2123
|
-
async replaceMessages(
|
|
2124
|
-
const n = e.get(
|
|
2130
|
+
async replaceMessages(t, a) {
|
|
2131
|
+
const n = e.get(t);
|
|
2125
2132
|
if (!n)
|
|
2126
|
-
throw new Error(`Agent with key "${
|
|
2127
|
-
n.conversationHistory = [...a], n.sessionId && await t
|
|
2133
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2134
|
+
n.conversationHistory = [...a], n.sessionId && await s(t, a);
|
|
2128
2135
|
},
|
|
2129
|
-
getConversationHistory(
|
|
2130
|
-
const a = e.get(
|
|
2136
|
+
getConversationHistory(t) {
|
|
2137
|
+
const a = e.get(t);
|
|
2131
2138
|
if (!a)
|
|
2132
|
-
throw new Error(`Agent with key "${
|
|
2139
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2133
2140
|
return [...a.conversationHistory];
|
|
2134
2141
|
},
|
|
2135
|
-
updateSessionId(
|
|
2136
|
-
const n = e.get(
|
|
2142
|
+
updateSessionId(t, a) {
|
|
2143
|
+
const n = e.get(t);
|
|
2137
2144
|
if (!n)
|
|
2138
|
-
throw new Error(`Agent with key "${
|
|
2145
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2139
2146
|
n.sessionId = a, n.sessionIdStorageKey && ne(
|
|
2140
2147
|
n.sessionIdStorageKey,
|
|
2141
2148
|
a
|
|
2142
2149
|
);
|
|
2143
2150
|
},
|
|
2144
|
-
abortCurrentRequest(
|
|
2145
|
-
const a = e.get(
|
|
2151
|
+
abortCurrentRequest(t) {
|
|
2152
|
+
const a = e.get(t);
|
|
2146
2153
|
if (!a)
|
|
2147
|
-
throw new Error(`Agent with key "${
|
|
2154
|
+
throw new Error(`Agent with key "${t}" not found`);
|
|
2148
2155
|
a.currentAbortController && (a.currentAbortController.abort(), a.currentAbortController = null);
|
|
2149
2156
|
},
|
|
2150
2157
|
clear() {
|
|
@@ -2152,14 +2159,14 @@ function St() {
|
|
|
2152
2159
|
}
|
|
2153
2160
|
};
|
|
2154
2161
|
}
|
|
2155
|
-
const
|
|
2162
|
+
const At = St();
|
|
2156
2163
|
function Q() {
|
|
2157
|
-
return
|
|
2164
|
+
return At;
|
|
2158
2165
|
}
|
|
2159
|
-
function
|
|
2160
|
-
const [e,
|
|
2166
|
+
function vt() {
|
|
2167
|
+
const [e, s] = Ae([]), t = F(
|
|
2161
2168
|
(r) => {
|
|
2162
|
-
|
|
2169
|
+
s((o) => {
|
|
2163
2170
|
const c = o.findIndex(
|
|
2164
2171
|
(l) => l.id === r.id
|
|
2165
2172
|
);
|
|
@@ -2172,19 +2179,19 @@ function Mt() {
|
|
|
2172
2179
|
},
|
|
2173
2180
|
[]
|
|
2174
2181
|
), a = F((r) => {
|
|
2175
|
-
|
|
2182
|
+
s((o) => o.filter((c) => c.id !== r));
|
|
2176
2183
|
}, []), n = F(() => {
|
|
2177
|
-
|
|
2184
|
+
s([]);
|
|
2178
2185
|
}, []);
|
|
2179
2186
|
return {
|
|
2180
|
-
registerMessageActions:
|
|
2187
|
+
registerMessageActions: t,
|
|
2181
2188
|
unregisterMessageActions: a,
|
|
2182
2189
|
clearAllMessageActions: n,
|
|
2183
2190
|
registrations: e
|
|
2184
2191
|
};
|
|
2185
2192
|
}
|
|
2186
|
-
function
|
|
2187
|
-
return
|
|
2193
|
+
function Mt(e, s) {
|
|
2194
|
+
return s.flatMap((n) => typeof n.actions == "function" ? n.actions(e) : n.actions).filter((n) => !(n.condition && !n.condition(e))).map((n) => ({
|
|
2188
2195
|
id: n.id,
|
|
2189
2196
|
label: n.label,
|
|
2190
2197
|
icon: n.icon,
|
|
@@ -2195,13 +2202,13 @@ function xt(e, t) {
|
|
|
2195
2202
|
showLabel: n.showLabel
|
|
2196
2203
|
}));
|
|
2197
2204
|
}
|
|
2198
|
-
const oe = (e) => [...e].sort((
|
|
2205
|
+
const oe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ne = (e, s = "40%") => ({
|
|
2199
2206
|
type: "component",
|
|
2200
2207
|
component: () => qe.createElement("img", {
|
|
2201
2208
|
src: e,
|
|
2202
2209
|
alt: "Uploaded image",
|
|
2203
2210
|
style: {
|
|
2204
|
-
maxWidth:
|
|
2211
|
+
maxWidth: s,
|
|
2205
2212
|
height: "auto",
|
|
2206
2213
|
borderRadius: "8px",
|
|
2207
2214
|
marginTop: "8px",
|
|
@@ -2209,7 +2216,7 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
|
|
|
2209
2216
|
display: "inline-block"
|
|
2210
2217
|
}
|
|
2211
2218
|
})
|
|
2212
|
-
}), re = (e,
|
|
2219
|
+
}), re = (e, s = []) => {
|
|
2213
2220
|
var o, c;
|
|
2214
2221
|
if (e.parts.some((l) => {
|
|
2215
2222
|
if (l.type === "data") {
|
|
@@ -2240,6 +2247,9 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
|
|
|
2240
2247
|
} : u.flags && typeof u.flags == "object" && "forward_to_human_support" in u.flags ? {
|
|
2241
2248
|
type: "data",
|
|
2242
2249
|
data: u
|
|
2250
|
+
} : Array.isArray(u.sources) && u.sources.length > 0 ? {
|
|
2251
|
+
type: "data",
|
|
2252
|
+
data: u
|
|
2243
2253
|
} : {
|
|
2244
2254
|
type: "text",
|
|
2245
2255
|
text: JSON.stringify(u)
|
|
@@ -2258,15 +2268,15 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
|
|
|
2258
2268
|
showIcon: e.role === "agent",
|
|
2259
2269
|
icon: e.role === "agent" ? "assistant" : void 0
|
|
2260
2270
|
};
|
|
2261
|
-
if (e.role === "agent" &&
|
|
2262
|
-
const l =
|
|
2271
|
+
if (e.role === "agent" && s.length > 0) {
|
|
2272
|
+
const l = Mt(
|
|
2263
2273
|
r,
|
|
2264
|
-
|
|
2274
|
+
s
|
|
2265
2275
|
);
|
|
2266
2276
|
l.length > 0 && (r.actions = l);
|
|
2267
2277
|
}
|
|
2268
2278
|
return r;
|
|
2269
|
-
},
|
|
2279
|
+
}, xt = () => ({
|
|
2270
2280
|
getClientContext: () => ({})
|
|
2271
2281
|
}), Ct = () => ({
|
|
2272
2282
|
getAvailableTools: async () => [],
|
|
@@ -2274,21 +2284,21 @@ const oe = (e) => [...e].sort((t, s) => t.timestamp - s.timestamp), Ne = (e, t =
|
|
|
2274
2284
|
success: !0,
|
|
2275
2285
|
result: "No tools available"
|
|
2276
2286
|
})
|
|
2277
|
-
}), bt = (e) => ["agentId", "agentUrl"].every((
|
|
2278
|
-
const a = e[
|
|
2287
|
+
}), bt = (e) => ["agentId", "agentUrl"].every((t) => {
|
|
2288
|
+
const a = e[t];
|
|
2279
2289
|
return typeof a == "string" && a.trim().length > 0;
|
|
2280
2290
|
});
|
|
2281
2291
|
function Bt(e) {
|
|
2282
|
-
const
|
|
2292
|
+
const s = {
|
|
2283
2293
|
agentId: e.agentId,
|
|
2284
2294
|
agentUrl: e.agentUrl,
|
|
2285
2295
|
sessionId: e.sessionId,
|
|
2286
2296
|
sessionIdStorageKey: e.sessionIdStorageKey
|
|
2287
|
-
},
|
|
2297
|
+
}, t = bt(s), [a, n] = Ae({
|
|
2288
2298
|
clientMessages: [],
|
|
2289
2299
|
uiMessages: [],
|
|
2290
2300
|
isProcessing: !1,
|
|
2291
|
-
error:
|
|
2301
|
+
error: t ? null : "Invalid agent configuration",
|
|
2292
2302
|
suggestions: [],
|
|
2293
2303
|
progressMessage: null,
|
|
2294
2304
|
progressPhase: null
|
|
@@ -2297,7 +2307,7 @@ function Bt(e) {
|
|
|
2297
2307
|
unregisterMessageActions: o,
|
|
2298
2308
|
clearAllMessageActions: c,
|
|
2299
2309
|
registrations: l
|
|
2300
|
-
} =
|
|
2310
|
+
} = vt(), d = He(l);
|
|
2301
2311
|
se(() => {
|
|
2302
2312
|
d.current = l;
|
|
2303
2313
|
}, [l]);
|
|
@@ -2309,12 +2319,12 @@ function Bt(e) {
|
|
|
2309
2319
|
// registrationsRef is stable, so no deps needed
|
|
2310
2320
|
);
|
|
2311
2321
|
se(() => {
|
|
2312
|
-
if (!
|
|
2322
|
+
if (!t)
|
|
2313
2323
|
return;
|
|
2314
2324
|
(async () => {
|
|
2315
|
-
const i = Q(), T =
|
|
2325
|
+
const i = Q(), T = s.agentId;
|
|
2316
2326
|
if (i.hasAgent(T))
|
|
2317
|
-
|
|
2327
|
+
s.sessionId ? (i.updateSessionId(T, s.sessionId), i.getConversationHistory(T).length === 0 && n((_) => ({
|
|
2318
2328
|
..._,
|
|
2319
2329
|
clientMessages: [],
|
|
2320
2330
|
uiMessages: []
|
|
@@ -2324,17 +2334,17 @@ function Bt(e) {
|
|
|
2324
2334
|
uiMessages: []
|
|
2325
2335
|
})));
|
|
2326
2336
|
else if (await i.createAgent(T, {
|
|
2327
|
-
agentId:
|
|
2328
|
-
agentUrl:
|
|
2329
|
-
sessionId:
|
|
2337
|
+
agentId: s.agentId,
|
|
2338
|
+
agentUrl: s.agentUrl,
|
|
2339
|
+
sessionId: s.sessionId,
|
|
2330
2340
|
// Can be empty for new chats
|
|
2331
|
-
sessionIdStorageKey:
|
|
2332
|
-
contextProvider: e.contextProvider ||
|
|
2341
|
+
sessionIdStorageKey: s.sessionIdStorageKey,
|
|
2342
|
+
contextProvider: e.contextProvider || xt(),
|
|
2333
2343
|
toolProvider: e.toolProvider || Ct(),
|
|
2334
2344
|
authProvider: e.authProvider,
|
|
2335
2345
|
enableStreaming: e.enableStreaming,
|
|
2336
2346
|
odieBotId: e.odieBotId
|
|
2337
|
-
}),
|
|
2347
|
+
}), s.sessionId) {
|
|
2338
2348
|
const I = i.getConversationHistory(T);
|
|
2339
2349
|
n((_) => {
|
|
2340
2350
|
const O = u(I);
|
|
@@ -2352,23 +2362,23 @@ function Bt(e) {
|
|
|
2352
2362
|
}));
|
|
2353
2363
|
})();
|
|
2354
2364
|
}, [
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2365
|
+
s.sessionId,
|
|
2366
|
+
s.agentId,
|
|
2367
|
+
s.agentUrl,
|
|
2368
|
+
s.sessionIdStorageKey,
|
|
2359
2369
|
e.contextProvider,
|
|
2360
2370
|
e.toolProvider,
|
|
2361
2371
|
e.authProvider,
|
|
2362
2372
|
e.enableStreaming,
|
|
2363
2373
|
e.odieBotId,
|
|
2364
|
-
|
|
2374
|
+
t
|
|
2365
2375
|
]);
|
|
2366
2376
|
const p = F(
|
|
2367
2377
|
async (g, i) => {
|
|
2368
|
-
var $,
|
|
2369
|
-
if (!
|
|
2378
|
+
var $, A;
|
|
2379
|
+
if (!t)
|
|
2370
2380
|
throw new Error("Invalid agent configuration");
|
|
2371
|
-
const T = Q(), S =
|
|
2381
|
+
const T = Q(), S = s.agentId, I = Date.now(), _ = (i == null ? void 0 : i.type) || "text", O = {
|
|
2372
2382
|
id: `user-${I}`,
|
|
2373
2383
|
role: "user",
|
|
2374
2384
|
content: [
|
|
@@ -2391,21 +2401,21 @@ function Bt(e) {
|
|
|
2391
2401
|
}));
|
|
2392
2402
|
try {
|
|
2393
2403
|
let y = null, C = !1;
|
|
2394
|
-
const
|
|
2395
|
-
(i != null && i.archived || i != null && i.type) && (
|
|
2404
|
+
const v = {};
|
|
2405
|
+
(i != null && i.archived || i != null && i.type) && (v.metadata = {
|
|
2396
2406
|
...(i == null ? void 0 : i.archived) && { archived: !0 },
|
|
2397
2407
|
...(i == null ? void 0 : i.type) && { contentType: i.type }
|
|
2398
|
-
}), i != null && i.sessionId && (
|
|
2399
|
-
for await (const
|
|
2408
|
+
}), i != null && i.sessionId && (v.sessionId = i.sessionId), i != null && i.imageUrls && (v.imageUrls = i.imageUrls);
|
|
2409
|
+
for await (const P of T.sendMessageStream(
|
|
2400
2410
|
S,
|
|
2401
2411
|
g,
|
|
2402
|
-
|
|
2412
|
+
v
|
|
2403
2413
|
)) {
|
|
2404
|
-
if ((
|
|
2414
|
+
if ((P.progressMessage || P.progressPhase) && n((k) => ({
|
|
2405
2415
|
...k,
|
|
2406
|
-
progressMessage:
|
|
2407
|
-
progressPhase:
|
|
2408
|
-
})), !
|
|
2416
|
+
progressMessage: P.progressMessage || null,
|
|
2417
|
+
progressPhase: P.progressPhase || null
|
|
2418
|
+
})), !P.final && P.text)
|
|
2409
2419
|
if (y)
|
|
2410
2420
|
n((k) => ({
|
|
2411
2421
|
...k,
|
|
@@ -2415,7 +2425,7 @@ function Bt(e) {
|
|
|
2415
2425
|
content: [
|
|
2416
2426
|
{
|
|
2417
2427
|
type: "text",
|
|
2418
|
-
text:
|
|
2428
|
+
text: P.text
|
|
2419
2429
|
}
|
|
2420
2430
|
]
|
|
2421
2431
|
} : b
|
|
@@ -2427,7 +2437,7 @@ function Bt(e) {
|
|
|
2427
2437
|
id: y,
|
|
2428
2438
|
role: "agent",
|
|
2429
2439
|
content: [
|
|
2430
|
-
{ type: "text", text:
|
|
2440
|
+
{ type: "text", text: P.text }
|
|
2431
2441
|
],
|
|
2432
2442
|
timestamp: Date.now(),
|
|
2433
2443
|
archived: !1,
|
|
@@ -2444,14 +2454,14 @@ function Bt(e) {
|
|
|
2444
2454
|
]
|
|
2445
2455
|
}));
|
|
2446
2456
|
}
|
|
2447
|
-
if (
|
|
2457
|
+
if (P.final && ((A = P.status) != null && A.message) && y) {
|
|
2448
2458
|
C = !0;
|
|
2449
2459
|
const k = y, b = re(
|
|
2450
|
-
|
|
2460
|
+
P.status.message,
|
|
2451
2461
|
d.current
|
|
2452
2462
|
);
|
|
2453
|
-
b && n((
|
|
2454
|
-
const U =
|
|
2463
|
+
b && n((R) => {
|
|
2464
|
+
const U = R.uiMessages.map(
|
|
2455
2465
|
(q) => {
|
|
2456
2466
|
var E, J;
|
|
2457
2467
|
if (q.id === k) {
|
|
@@ -2469,7 +2479,7 @@ function Bt(e) {
|
|
|
2469
2479
|
S
|
|
2470
2480
|
);
|
|
2471
2481
|
return {
|
|
2472
|
-
...
|
|
2482
|
+
...R,
|
|
2473
2483
|
clientMessages: D,
|
|
2474
2484
|
uiMessages: U,
|
|
2475
2485
|
isProcessing: !1,
|
|
@@ -2480,13 +2490,13 @@ function Bt(e) {
|
|
|
2480
2490
|
}
|
|
2481
2491
|
}
|
|
2482
2492
|
if (!C) {
|
|
2483
|
-
const
|
|
2493
|
+
const P = T.getConversationHistory(S);
|
|
2484
2494
|
n((k) => {
|
|
2485
2495
|
let b = k.uiMessages;
|
|
2486
2496
|
y && (b = k.uiMessages.filter(
|
|
2487
2497
|
(E) => E.id !== y
|
|
2488
2498
|
));
|
|
2489
|
-
const
|
|
2499
|
+
const R = P.map(
|
|
2490
2500
|
(E) => re(
|
|
2491
2501
|
E,
|
|
2492
2502
|
d.current
|
|
@@ -2494,16 +2504,16 @@ function Bt(e) {
|
|
|
2494
2504
|
).filter(
|
|
2495
2505
|
(E) => E !== null
|
|
2496
2506
|
), U = new Set(
|
|
2497
|
-
|
|
2507
|
+
P.map((E) => E.messageId)
|
|
2498
2508
|
), D = b.filter(
|
|
2499
2509
|
(E) => !U.has(E.id) && E.role !== "user"
|
|
2500
2510
|
), q = oe([
|
|
2501
|
-
...
|
|
2511
|
+
...R,
|
|
2502
2512
|
...D
|
|
2503
2513
|
]);
|
|
2504
2514
|
return {
|
|
2505
2515
|
...k,
|
|
2506
|
-
clientMessages:
|
|
2516
|
+
clientMessages: P,
|
|
2507
2517
|
uiMessages: q,
|
|
2508
2518
|
isProcessing: !1,
|
|
2509
2519
|
progressMessage: null,
|
|
@@ -2513,8 +2523,8 @@ function Bt(e) {
|
|
|
2513
2523
|
}
|
|
2514
2524
|
} catch (y) {
|
|
2515
2525
|
if (y instanceof Error && y.name === "AbortError") {
|
|
2516
|
-
|
|
2517
|
-
...
|
|
2526
|
+
M("Request was aborted by user"), n((v) => ({
|
|
2527
|
+
...v,
|
|
2518
2528
|
isProcessing: !1,
|
|
2519
2529
|
progressMessage: null,
|
|
2520
2530
|
progressPhase: null,
|
|
@@ -2524,8 +2534,8 @@ function Bt(e) {
|
|
|
2524
2534
|
return;
|
|
2525
2535
|
}
|
|
2526
2536
|
const C = y instanceof Error ? y.message : "Failed to send message";
|
|
2527
|
-
throw n((
|
|
2528
|
-
...
|
|
2537
|
+
throw n((v) => ({
|
|
2538
|
+
...v,
|
|
2529
2539
|
isProcessing: !1,
|
|
2530
2540
|
progressMessage: null,
|
|
2531
2541
|
progressPhase: null,
|
|
@@ -2533,7 +2543,7 @@ function Bt(e) {
|
|
|
2533
2543
|
})), y;
|
|
2534
2544
|
}
|
|
2535
2545
|
},
|
|
2536
|
-
[
|
|
2546
|
+
[s.agentId, t]
|
|
2537
2547
|
), m = F((g) => {
|
|
2538
2548
|
n((i) => ({
|
|
2539
2549
|
...i,
|
|
@@ -2569,15 +2579,15 @@ function Bt(e) {
|
|
|
2569
2579
|
});
|
|
2570
2580
|
}, [l]);
|
|
2571
2581
|
const h = F(() => {
|
|
2572
|
-
if (!
|
|
2582
|
+
if (!t)
|
|
2573
2583
|
return;
|
|
2574
|
-
const g = Q(), i =
|
|
2584
|
+
const g = Q(), i = s.agentId;
|
|
2575
2585
|
g.abortCurrentRequest(i);
|
|
2576
|
-
}, [
|
|
2586
|
+
}, [s.agentId, t]), x = F(
|
|
2577
2587
|
async (g) => {
|
|
2578
|
-
if (!
|
|
2588
|
+
if (!t)
|
|
2579
2589
|
return;
|
|
2580
|
-
const i = Q(), T =
|
|
2590
|
+
const i = Q(), T = s.agentId;
|
|
2581
2591
|
await i.replaceMessages(T, g);
|
|
2582
2592
|
const S = u(g);
|
|
2583
2593
|
n((I) => ({
|
|
@@ -2586,7 +2596,7 @@ function Bt(e) {
|
|
|
2586
2596
|
uiMessages: S
|
|
2587
2597
|
}));
|
|
2588
2598
|
},
|
|
2589
|
-
[
|
|
2599
|
+
[s.agentId, t]
|
|
2590
2600
|
);
|
|
2591
2601
|
return {
|
|
2592
2602
|
// AgentUI props
|
|
@@ -2609,26 +2619,26 @@ function Bt(e) {
|
|
|
2609
2619
|
// Abort control
|
|
2610
2620
|
abortCurrentRequest: h,
|
|
2611
2621
|
// Conversation loading
|
|
2612
|
-
loadMessages:
|
|
2622
|
+
loadMessages: x
|
|
2613
2623
|
};
|
|
2614
2624
|
}
|
|
2615
2625
|
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 || {});
|
|
2616
|
-
const Te = "jetpack-ai-jwt-token",
|
|
2617
|
-
function
|
|
2618
|
-
var
|
|
2619
|
-
return ((a = (
|
|
2626
|
+
const Te = "jetpack-ai-jwt-token", Pt = 30 * 60 * 1e3;
|
|
2627
|
+
function Rt() {
|
|
2628
|
+
var t, a, n;
|
|
2629
|
+
return ((a = (t = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : t.connectionStatus) == null ? void 0 : a.isRegistered) ? !1 : !!((n = window.Jetpack_Editor_Initial_State) != null && n.wpcomBlogId);
|
|
2620
2630
|
}
|
|
2621
|
-
async function _t(e,
|
|
2631
|
+
async function _t(e, s = !0) {
|
|
2622
2632
|
var l, d;
|
|
2623
|
-
const
|
|
2633
|
+
const t = localStorage.getItem(Te);
|
|
2624
2634
|
let a;
|
|
2625
|
-
if (
|
|
2635
|
+
if (t)
|
|
2626
2636
|
try {
|
|
2627
|
-
a = JSON.parse(
|
|
2637
|
+
a = JSON.parse(t);
|
|
2628
2638
|
} catch (u) {
|
|
2629
|
-
|
|
2639
|
+
M("Invalid cached Jetpack token: %O", u);
|
|
2630
2640
|
}
|
|
2631
|
-
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() &&
|
|
2641
|
+
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && s)
|
|
2632
2642
|
return a;
|
|
2633
2643
|
const n = (l = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : l.apiNonce, r = (d = window.Jetpack_Editor_Initial_State) == null ? void 0 : d.wpcomBlogId;
|
|
2634
2644
|
let o = {
|
|
@@ -2636,7 +2646,7 @@ async function _t(e, t = !0) {
|
|
|
2636
2646
|
blog_id: ""
|
|
2637
2647
|
};
|
|
2638
2648
|
try {
|
|
2639
|
-
|
|
2649
|
+
Rt() ? o = await pe({
|
|
2640
2650
|
path: "/wpcom/v2/sites/" + r + "/jetpack-openai-query/jwt",
|
|
2641
2651
|
method: "POST"
|
|
2642
2652
|
}) : o = await pe({
|
|
@@ -2648,7 +2658,7 @@ async function _t(e, t = !0) {
|
|
|
2648
2658
|
method: "POST"
|
|
2649
2659
|
});
|
|
2650
2660
|
} catch (u) {
|
|
2651
|
-
throw
|
|
2661
|
+
throw M("Failed to fetch Jetpack token: %O", u), new Error(e(u));
|
|
2652
2662
|
}
|
|
2653
2663
|
if (!(o != null && o.token))
|
|
2654
2664
|
throw new Error(
|
|
@@ -2657,27 +2667,27 @@ async function _t(e, t = !0) {
|
|
|
2657
2667
|
const c = {
|
|
2658
2668
|
token: o.token,
|
|
2659
2669
|
blogId: o.blog_id || "",
|
|
2660
|
-
expire: Date.now() +
|
|
2670
|
+
expire: Date.now() + Pt
|
|
2661
2671
|
};
|
|
2662
2672
|
try {
|
|
2663
2673
|
localStorage.setItem(Te, JSON.stringify(c));
|
|
2664
2674
|
} catch (u) {
|
|
2665
|
-
|
|
2675
|
+
M("Error storing token in localStorage: %O", u);
|
|
2666
2676
|
}
|
|
2667
2677
|
return c;
|
|
2668
2678
|
}
|
|
2669
2679
|
const Wt = (e) => async () => {
|
|
2670
|
-
const
|
|
2680
|
+
const s = {};
|
|
2671
2681
|
try {
|
|
2672
|
-
const
|
|
2673
|
-
|
|
2674
|
-
} catch (
|
|
2675
|
-
throw
|
|
2682
|
+
const t = await _t(e);
|
|
2683
|
+
t != null && t.token && (s.Authorization = `${t.token}`);
|
|
2684
|
+
} catch (t) {
|
|
2685
|
+
throw M("Failed to get Jetpack token for auth: %O", t), t;
|
|
2676
2686
|
}
|
|
2677
|
-
return
|
|
2687
|
+
return s;
|
|
2678
2688
|
};
|
|
2679
2689
|
function Et(e) {
|
|
2680
|
-
const
|
|
2690
|
+
const s = {
|
|
2681
2691
|
type: "object",
|
|
2682
2692
|
properties: {}
|
|
2683
2693
|
};
|
|
@@ -2685,7 +2695,7 @@ function Et(e) {
|
|
|
2685
2695
|
id: e.name.replace(/\//g, "-"),
|
|
2686
2696
|
name: e.label,
|
|
2687
2697
|
description: e.description,
|
|
2688
|
-
input_schema: e.input_schema ||
|
|
2698
|
+
input_schema: e.input_schema || s,
|
|
2689
2699
|
// Store metadata for detection and execution
|
|
2690
2700
|
_source: "wordpress-ability",
|
|
2691
2701
|
_originalAbility: e
|
|
@@ -2697,24 +2707,24 @@ function Vt(e) {
|
|
|
2697
2707
|
function zt(e) {
|
|
2698
2708
|
return (e == null ? void 0 : e._source) === "wordpress-ability";
|
|
2699
2709
|
}
|
|
2700
|
-
function Gt(e,
|
|
2710
|
+
function Gt(e, s = "agent", t = "wpcom") {
|
|
2701
2711
|
const a = e.replace(/-/g, "_");
|
|
2702
|
-
return `${
|
|
2712
|
+
return `${t}-${s}-${a}`;
|
|
2703
2713
|
}
|
|
2704
2714
|
function Ot(e) {
|
|
2705
|
-
const
|
|
2706
|
-
if (
|
|
2715
|
+
const s = e.split("-");
|
|
2716
|
+
if (s.length < 3)
|
|
2707
2717
|
throw new Error(
|
|
2708
2718
|
`Invalid Odie bot ID format: ${e}. Expected format: {product}-{type}-{slug}`
|
|
2709
2719
|
);
|
|
2710
|
-
const
|
|
2720
|
+
const t = s[0], a = s[1];
|
|
2711
2721
|
if (!["agent", "workflow", "chain"].includes(a))
|
|
2712
2722
|
throw new Error(
|
|
2713
2723
|
`Invalid Odie bot type: ${a}. Expected one of: agent, workflow, chain`
|
|
2714
2724
|
);
|
|
2715
|
-
const n = a, r =
|
|
2725
|
+
const n = a, r = s.slice(2).join("-"), o = r.replace(/_/g, "-");
|
|
2716
2726
|
return {
|
|
2717
|
-
product:
|
|
2727
|
+
product: t,
|
|
2718
2728
|
type: n,
|
|
2719
2729
|
slug: r,
|
|
2720
2730
|
agentId: o
|
|
@@ -2722,8 +2732,8 @@ function Ot(e) {
|
|
|
2722
2732
|
}
|
|
2723
2733
|
function Qt(e) {
|
|
2724
2734
|
try {
|
|
2725
|
-
const
|
|
2726
|
-
return
|
|
2735
|
+
const s = Ot(e);
|
|
2736
|
+
return s.product.length > 0 && ["agent", "workflow", "chain"].includes(s.type) && s.slug.length > 0;
|
|
2727
2737
|
} catch {
|
|
2728
2738
|
return !1;
|
|
2729
2739
|
}
|
|
@@ -2753,5 +2763,5 @@ export {
|
|
|
2753
2763
|
Ht as useClientContext,
|
|
2754
2764
|
Ft as useClientTools,
|
|
2755
2765
|
Dt as useClientToolsWithAbilities,
|
|
2756
|
-
|
|
2766
|
+
vt as useMessageActions
|
|
2757
2767
|
};
|