@automattic/agenttic-client 0.1.21 → 0.1.23
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/auth/jetpack.d.ts +1 -0
- package/dist/auth/jetpack.d.ts.map +1 -1
- package/dist/client/index.d.ts +8 -1
- package/dist/client/index.d.ts.map +1 -1
- package/dist/index.js +848 -862
- package/dist/logger-aKHbTlwk.js +18 -0
- package/dist/mocks/MockSalesGraph.d.ts.map +1 -1
- package/dist/mocks/mockTools.d.ts.map +1 -1
- package/dist/mocks.js +134 -128
- package/dist/react/useAgentChat.d.ts +1 -1
- package/dist/react/useAgentChat.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,28 +1,16 @@
|
|
|
1
1
|
var Rt = Object.defineProperty;
|
|
2
2
|
var Et = (t, e, s) => e in t ? Rt(t, e, { enumerable: !0, configurable: !0, writable: !0, value: s }) : t[e] = s;
|
|
3
3
|
var Z = (t, e, s) => Et(t, typeof e != "symbol" ? e + "" : e, s);
|
|
4
|
-
import { useMemo as
|
|
5
|
-
import ut from "
|
|
6
|
-
|
|
7
|
-
_t() && console.log(`[agenttic-client] ${t}`, ...e);
|
|
8
|
-
};
|
|
9
|
-
function _t() {
|
|
10
|
-
var t;
|
|
11
|
-
return typeof globalThis < "u" && "window" in globalThis && ((t = globalThis.window) == null ? void 0 : t.DEBUG) === "agenttic-client";
|
|
12
|
-
}
|
|
13
|
-
function wt(t) {
|
|
14
|
-
return JSON.stringify(t, null, 2);
|
|
15
|
-
}
|
|
16
|
-
function dt(t, ...e) {
|
|
17
|
-
console.log(`[agenttic-client] ${t}`, ...e);
|
|
18
|
-
}
|
|
4
|
+
import { useMemo as ht, useCallback as $, useState as yt, useRef as Ot, useEffect as tt } from "react";
|
|
5
|
+
import { l as v, f as wt, a as ut } from "./logger-aKHbTlwk.js";
|
|
6
|
+
import dt from "@wordpress/api-fetch";
|
|
19
7
|
function Ae(t) {
|
|
20
|
-
return
|
|
8
|
+
return ht(() => t ? {
|
|
21
9
|
getClientContext: () => {
|
|
22
10
|
try {
|
|
23
11
|
return t() || {};
|
|
24
|
-
} catch (
|
|
25
|
-
return
|
|
12
|
+
} catch (a) {
|
|
13
|
+
return v("Error getting client context: %O", a), {};
|
|
26
14
|
}
|
|
27
15
|
}
|
|
28
16
|
} : void 0, [t]);
|
|
@@ -32,36 +20,36 @@ function ot({
|
|
|
32
20
|
executeTool: e,
|
|
33
21
|
getAbilities: s
|
|
34
22
|
}) {
|
|
35
|
-
const
|
|
23
|
+
const a = $(async () => {
|
|
36
24
|
const o = [];
|
|
37
25
|
if (t)
|
|
38
26
|
try {
|
|
39
|
-
const
|
|
40
|
-
o.push(...
|
|
41
|
-
} catch (
|
|
42
|
-
|
|
27
|
+
const l = await t();
|
|
28
|
+
o.push(...l);
|
|
29
|
+
} catch (l) {
|
|
30
|
+
v("Error getting available tools: %O", l);
|
|
43
31
|
}
|
|
44
32
|
return o;
|
|
45
|
-
}, [t]),
|
|
46
|
-
async (o,
|
|
33
|
+
}, [t]), n = $(
|
|
34
|
+
async (o, l) => {
|
|
47
35
|
if (!e)
|
|
48
36
|
throw new Error("No executeTool callback provided");
|
|
49
37
|
try {
|
|
50
|
-
return await e(o,
|
|
38
|
+
return await e(o, l);
|
|
51
39
|
} catch (i) {
|
|
52
|
-
throw
|
|
40
|
+
throw v("Error executing tool %s: %O", o, i), i;
|
|
53
41
|
}
|
|
54
42
|
},
|
|
55
43
|
[e]
|
|
56
44
|
);
|
|
57
|
-
return
|
|
45
|
+
return ht(() => {
|
|
58
46
|
if (!t && !s)
|
|
59
47
|
return;
|
|
60
48
|
const o = {};
|
|
61
|
-
return t && (o.getAvailableTools =
|
|
49
|
+
return t && (o.getAvailableTools = a), e && (o.executeTool = n), s && (o.getAbilities = s), o;
|
|
62
50
|
}, [
|
|
63
|
-
n,
|
|
64
51
|
a,
|
|
52
|
+
n,
|
|
65
53
|
t,
|
|
66
54
|
e,
|
|
67
55
|
s
|
|
@@ -82,8 +70,8 @@ function ve(t) {
|
|
|
82
70
|
});
|
|
83
71
|
}
|
|
84
72
|
function ke(t) {
|
|
85
|
-
const { getClientTools: e, executeTool: s, getAbilities:
|
|
86
|
-
if (!e && !
|
|
73
|
+
const { getClientTools: e, executeTool: s, getAbilities: a } = t;
|
|
74
|
+
if (!e && !a)
|
|
87
75
|
throw new Error(
|
|
88
76
|
"At least one of getClientTools or getAbilities must be provided to useClientToolsWithAbilities."
|
|
89
77
|
);
|
|
@@ -94,7 +82,7 @@ function ke(t) {
|
|
|
94
82
|
return ot({
|
|
95
83
|
getClientTools: e,
|
|
96
84
|
executeTool: s,
|
|
97
|
-
getAbilities:
|
|
85
|
+
getAbilities: a
|
|
98
86
|
});
|
|
99
87
|
}
|
|
100
88
|
function rt() {
|
|
@@ -104,13 +92,13 @@ function rt() {
|
|
|
104
92
|
e += t.charAt(Math.floor(Math.random() * t.length));
|
|
105
93
|
return e;
|
|
106
94
|
}
|
|
107
|
-
function
|
|
95
|
+
function N() {
|
|
108
96
|
return rt();
|
|
109
97
|
}
|
|
110
|
-
function
|
|
98
|
+
function _t() {
|
|
111
99
|
return `req-${rt()}`;
|
|
112
100
|
}
|
|
113
|
-
function
|
|
101
|
+
function Pt() {
|
|
114
102
|
return `task-${rt()}`;
|
|
115
103
|
}
|
|
116
104
|
function It(t, e) {
|
|
@@ -120,22 +108,22 @@ function It(t, e) {
|
|
|
120
108
|
...e && { metadata: e }
|
|
121
109
|
};
|
|
122
110
|
}
|
|
123
|
-
function
|
|
124
|
-
const
|
|
111
|
+
function Nt(t, e = "message/send", s = !1) {
|
|
112
|
+
const a = {
|
|
125
113
|
jsonrpc: "2.0",
|
|
126
|
-
id:
|
|
114
|
+
id: _t(),
|
|
127
115
|
method: e,
|
|
128
116
|
params: {
|
|
129
|
-
id: t.id ||
|
|
117
|
+
id: t.id || Pt(),
|
|
130
118
|
...t
|
|
131
119
|
}
|
|
132
120
|
};
|
|
133
|
-
return s && e === "message/stream" && (
|
|
121
|
+
return s && e === "message/stream" && (a.tokenStreaming = !0), a;
|
|
134
122
|
}
|
|
135
123
|
function D(t) {
|
|
136
124
|
return !t || !t.parts || !Array.isArray(t.parts) ? "" : t.parts.filter((e) => e.type === "text").map((e) => e.text).join(" ");
|
|
137
125
|
}
|
|
138
|
-
function
|
|
126
|
+
function qt(t) {
|
|
139
127
|
return {
|
|
140
128
|
type: "data",
|
|
141
129
|
data: {
|
|
@@ -147,7 +135,7 @@ function Ht(t) {
|
|
|
147
135
|
metadata: {}
|
|
148
136
|
};
|
|
149
137
|
}
|
|
150
|
-
function
|
|
138
|
+
function Ht(t) {
|
|
151
139
|
return {
|
|
152
140
|
type: "data",
|
|
153
141
|
data: {
|
|
@@ -167,7 +155,7 @@ function F(t) {
|
|
|
167
155
|
(e) => e.type === "data" && "toolCallId" in e.data && "toolId" in e.data && "arguments" in e.data
|
|
168
156
|
);
|
|
169
157
|
}
|
|
170
|
-
function j(t, e, s,
|
|
158
|
+
function j(t, e, s, a) {
|
|
171
159
|
return {
|
|
172
160
|
type: "data",
|
|
173
161
|
data: {
|
|
@@ -175,10 +163,10 @@ function j(t, e, s, n) {
|
|
|
175
163
|
toolId: e,
|
|
176
164
|
result: s
|
|
177
165
|
},
|
|
178
|
-
metadata:
|
|
166
|
+
metadata: a ? { error: a } : void 0
|
|
179
167
|
};
|
|
180
168
|
}
|
|
181
|
-
function
|
|
169
|
+
function $t(t) {
|
|
182
170
|
return {
|
|
183
171
|
type: "data",
|
|
184
172
|
data: {
|
|
@@ -187,16 +175,16 @@ function Dt(t) {
|
|
|
187
175
|
metadata: {}
|
|
188
176
|
};
|
|
189
177
|
}
|
|
190
|
-
function
|
|
191
|
-
const { contentType: s, ...
|
|
178
|
+
function nt(t, e) {
|
|
179
|
+
const { contentType: s, ...a } = e || {};
|
|
192
180
|
return {
|
|
193
181
|
role: "user",
|
|
194
182
|
parts: [It(t, s ? { contentType: s } : void 0)],
|
|
195
183
|
kind: "message",
|
|
196
|
-
messageId:
|
|
184
|
+
messageId: N(),
|
|
197
185
|
metadata: {
|
|
198
186
|
timestamp: Date.now(),
|
|
199
|
-
...
|
|
187
|
+
...a
|
|
200
188
|
}
|
|
201
189
|
};
|
|
202
190
|
}
|
|
@@ -205,7 +193,7 @@ function W(t) {
|
|
|
205
193
|
role: "agent",
|
|
206
194
|
parts: [It(t)],
|
|
207
195
|
kind: "message",
|
|
208
|
-
messageId:
|
|
196
|
+
messageId: N(),
|
|
209
197
|
metadata: {
|
|
210
198
|
timestamp: Date.now()
|
|
211
199
|
}
|
|
@@ -223,12 +211,12 @@ function it(t) {
|
|
|
223
211
|
returnToAgent: !0
|
|
224
212
|
};
|
|
225
213
|
}
|
|
226
|
-
function
|
|
214
|
+
function Q(t, e = []) {
|
|
227
215
|
return {
|
|
228
216
|
role: "user",
|
|
229
217
|
kind: "message",
|
|
230
218
|
parts: [...e, ...t],
|
|
231
|
-
messageId:
|
|
219
|
+
messageId: N(),
|
|
232
220
|
metadata: {
|
|
233
221
|
timestamp: Date.now()
|
|
234
222
|
}
|
|
@@ -237,23 +225,23 @@ function G(t, e = []) {
|
|
|
237
225
|
function Re() {
|
|
238
226
|
return new AbortController();
|
|
239
227
|
}
|
|
240
|
-
async function
|
|
228
|
+
async function Dt(t, e) {
|
|
241
229
|
if (!e)
|
|
242
230
|
return t;
|
|
243
231
|
try {
|
|
244
232
|
const s = [];
|
|
245
233
|
if (e.getAvailableTools) {
|
|
246
|
-
const
|
|
247
|
-
if (
|
|
248
|
-
const
|
|
249
|
-
s.push(...
|
|
234
|
+
const a = await e.getAvailableTools();
|
|
235
|
+
if (a.length > 0) {
|
|
236
|
+
const n = a.map(qt);
|
|
237
|
+
s.push(...n);
|
|
250
238
|
}
|
|
251
239
|
}
|
|
252
240
|
if (e.getAbilities) {
|
|
253
|
-
const
|
|
254
|
-
if (
|
|
255
|
-
const
|
|
256
|
-
s.push(...
|
|
241
|
+
const a = await e.getAbilities();
|
|
242
|
+
if (a.length > 0) {
|
|
243
|
+
const n = a.map(Ht);
|
|
244
|
+
s.push(...n);
|
|
257
245
|
}
|
|
258
246
|
}
|
|
259
247
|
return s.length === 0 ? t : {
|
|
@@ -261,134 +249,134 @@ async function Ft(t, e) {
|
|
|
261
249
|
parts: [...t.parts, ...s]
|
|
262
250
|
};
|
|
263
251
|
} catch (s) {
|
|
264
|
-
return
|
|
252
|
+
return v("Warning: Failed to get tools: %s", s), t;
|
|
265
253
|
}
|
|
266
254
|
}
|
|
267
|
-
function
|
|
255
|
+
function Ft(t, e) {
|
|
268
256
|
if (!e)
|
|
269
257
|
return t;
|
|
270
258
|
try {
|
|
271
259
|
const s = e.getClientContext();
|
|
272
260
|
if (!s || Object.keys(s).length === 0)
|
|
273
261
|
return t;
|
|
274
|
-
const
|
|
262
|
+
const a = $t(s);
|
|
275
263
|
return {
|
|
276
264
|
...t,
|
|
277
|
-
parts: [...t.parts,
|
|
265
|
+
parts: [...t.parts, a]
|
|
278
266
|
};
|
|
279
267
|
} catch (s) {
|
|
280
|
-
return
|
|
268
|
+
return v("Warning: Failed to get context: %s", s), t;
|
|
281
269
|
}
|
|
282
270
|
}
|
|
283
|
-
async function
|
|
284
|
-
let
|
|
271
|
+
async function Ut(t, e, s) {
|
|
272
|
+
let a = await Dt(
|
|
285
273
|
t,
|
|
286
274
|
e
|
|
287
275
|
);
|
|
288
|
-
|
|
289
|
-
|
|
276
|
+
a = Ft(
|
|
277
|
+
a,
|
|
290
278
|
s
|
|
291
279
|
);
|
|
292
|
-
const { metadata:
|
|
280
|
+
const { metadata: n, ...r } = a;
|
|
293
281
|
return r;
|
|
294
282
|
}
|
|
295
|
-
function
|
|
296
|
-
const s = [],
|
|
297
|
-
let
|
|
298
|
-
for (; o <
|
|
299
|
-
const i =
|
|
283
|
+
function jt(t, e = "") {
|
|
284
|
+
const s = [], a = e + t;
|
|
285
|
+
let n = "", r = 0, o = 0;
|
|
286
|
+
for (; o < a.length; ) {
|
|
287
|
+
const i = a.indexOf(
|
|
300
288
|
`
|
|
301
289
|
`,
|
|
302
290
|
o
|
|
303
|
-
),
|
|
304
|
-
if (
|
|
305
|
-
|
|
306
|
-
`),
|
|
307
|
-
|
|
291
|
+
), m = i === -1 ? a.substring(o) : a.substring(o, i);
|
|
292
|
+
if (m.startsWith("data:"))
|
|
293
|
+
n !== "" && (n += `
|
|
294
|
+
`), n += m.substring(
|
|
295
|
+
m.startsWith("data: ") ? 6 : 5
|
|
308
296
|
);
|
|
309
|
-
else if (
|
|
297
|
+
else if (m.trim() === "" && n) {
|
|
310
298
|
try {
|
|
311
|
-
s.push(JSON.parse(
|
|
312
|
-
} catch (
|
|
313
|
-
|
|
299
|
+
s.push(JSON.parse(n)), r = i === -1 ? a.length : i + 1;
|
|
300
|
+
} catch (g) {
|
|
301
|
+
v("Failed to parse SSE event: %o", g), v("Problematic payload: %s", n);
|
|
314
302
|
}
|
|
315
|
-
|
|
303
|
+
n = "";
|
|
316
304
|
}
|
|
317
|
-
i === -1 ? o =
|
|
305
|
+
i === -1 ? o = a.length : o = i + 1;
|
|
318
306
|
}
|
|
319
|
-
const
|
|
320
|
-
return { events: s, nextBuffer:
|
|
307
|
+
const l = a.substring(r);
|
|
308
|
+
return { events: s, nextBuffer: l };
|
|
321
309
|
}
|
|
322
|
-
async function*
|
|
323
|
-
var
|
|
324
|
-
const { supportDeltas: s = !1 } = e,
|
|
310
|
+
async function* Jt(t, e = {}) {
|
|
311
|
+
var m, g, h;
|
|
312
|
+
const { supportDeltas: s = !1 } = e, a = t.getReader(), n = new TextDecoder();
|
|
325
313
|
let r = "";
|
|
326
|
-
const o = new
|
|
327
|
-
let
|
|
314
|
+
const o = new Kt();
|
|
315
|
+
let l = null, i = null;
|
|
328
316
|
try {
|
|
329
317
|
for (; ; ) {
|
|
330
|
-
const { done:
|
|
331
|
-
if (
|
|
318
|
+
const { done: f, value: p } = await a.read();
|
|
319
|
+
if (f)
|
|
332
320
|
break;
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
335
|
-
for (let
|
|
336
|
-
const d =
|
|
337
|
-
if (
|
|
338
|
-
requestAnimationFrame(() =>
|
|
321
|
+
const S = n.decode(p, { stream: !0 }), { events: c, nextBuffer: u } = jt(S, r);
|
|
322
|
+
if (c && Array.isArray(c))
|
|
323
|
+
for (let w = 0; w < c.length; w++) {
|
|
324
|
+
const d = c[w];
|
|
325
|
+
if (w > 0 && d.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((y) => {
|
|
326
|
+
requestAnimationFrame(() => y(void 0));
|
|
339
327
|
}), d.error)
|
|
340
328
|
throw new Error(
|
|
341
329
|
`Streaming error: ${d.error.message}`
|
|
342
330
|
);
|
|
343
|
-
if (s && d.method === "message/delta" && ((
|
|
344
|
-
const
|
|
331
|
+
if (s && d.method === "message/delta" && ((m = d.params) != null && m.delta)) {
|
|
332
|
+
const y = d.params.delta;
|
|
345
333
|
try {
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
-
), !
|
|
349
|
-
const
|
|
334
|
+
if (y.deltaType === "content" && (o.processContentDelta(
|
|
335
|
+
y.content
|
|
336
|
+
), !l && d.params.id && (l = d.params.id), l)) {
|
|
337
|
+
const x = o.getCurrentMessage();
|
|
350
338
|
yield {
|
|
351
|
-
id:
|
|
339
|
+
id: l,
|
|
352
340
|
status: {
|
|
353
341
|
state: "working",
|
|
354
|
-
message:
|
|
342
|
+
message: x
|
|
355
343
|
},
|
|
356
344
|
final: !1,
|
|
357
345
|
text: o.getTextContent()
|
|
358
346
|
};
|
|
359
347
|
}
|
|
360
|
-
} catch (
|
|
361
|
-
|
|
348
|
+
} catch (x) {
|
|
349
|
+
v("Failed to process delta: %o", x);
|
|
362
350
|
}
|
|
363
|
-
} else d.result && d.result.status ? (
|
|
351
|
+
} else d.result && d.result.status ? (l = d.result.id, i = d.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset(), yield {
|
|
364
352
|
id: d.result.id,
|
|
365
353
|
status: d.result.status,
|
|
366
354
|
final: d.result.status.state === "completed" || d.result.status.state === "failed" || d.result.status.state === "canceled",
|
|
367
355
|
text: D(
|
|
368
|
-
((
|
|
356
|
+
((g = d.result.status) == null ? void 0 : g.message) || {
|
|
369
357
|
role: "agent",
|
|
370
358
|
parts: []
|
|
371
359
|
}
|
|
372
360
|
)
|
|
373
|
-
}) : d.id && d.result && (
|
|
361
|
+
}) : d.id && d.result && (l = d.result.id, d.result.status && (yield {
|
|
374
362
|
id: d.result.id,
|
|
375
363
|
status: d.result.status,
|
|
376
364
|
final: d.result.status.state === "completed" || d.result.status.state === "failed" || d.result.status.state === "canceled",
|
|
377
365
|
text: D(
|
|
378
|
-
((
|
|
366
|
+
((h = d.result.status) == null ? void 0 : h.message) || {
|
|
379
367
|
role: "agent",
|
|
380
368
|
parts: []
|
|
381
369
|
}
|
|
382
370
|
)
|
|
383
371
|
}));
|
|
384
372
|
}
|
|
385
|
-
r =
|
|
373
|
+
r = u;
|
|
386
374
|
}
|
|
387
375
|
} finally {
|
|
388
|
-
|
|
376
|
+
a.releaseLock();
|
|
389
377
|
}
|
|
390
378
|
}
|
|
391
|
-
class
|
|
379
|
+
class Kt {
|
|
392
380
|
constructor() {
|
|
393
381
|
Z(this, "textContent", "");
|
|
394
382
|
Z(this, "toolCalls", /* @__PURE__ */ new Map());
|
|
@@ -443,9 +431,9 @@ class Lt {
|
|
|
443
431
|
type: "text",
|
|
444
432
|
text: this.textContent
|
|
445
433
|
});
|
|
446
|
-
for (const [
|
|
447
|
-
if (
|
|
448
|
-
const r =
|
|
434
|
+
for (const [a, n] of this.toolCalls)
|
|
435
|
+
if (n.toolName) {
|
|
436
|
+
const r = n.argumentFragments.join("");
|
|
449
437
|
let o = {};
|
|
450
438
|
if (r)
|
|
451
439
|
try {
|
|
@@ -456,8 +444,8 @@ class Lt {
|
|
|
456
444
|
s.push({
|
|
457
445
|
type: "data",
|
|
458
446
|
data: {
|
|
459
|
-
toolCallId:
|
|
460
|
-
toolId:
|
|
447
|
+
toolCallId: n.toolCallId,
|
|
448
|
+
toolId: n.toolName,
|
|
461
449
|
arguments: o
|
|
462
450
|
}
|
|
463
451
|
});
|
|
@@ -466,7 +454,7 @@ class Lt {
|
|
|
466
454
|
role: e,
|
|
467
455
|
parts: s,
|
|
468
456
|
kind: "message",
|
|
469
|
-
messageId:
|
|
457
|
+
messageId: N()
|
|
470
458
|
};
|
|
471
459
|
}
|
|
472
460
|
/**
|
|
@@ -477,20 +465,20 @@ class Lt {
|
|
|
477
465
|
}
|
|
478
466
|
}
|
|
479
467
|
function Tt(t, e, s = "request") {
|
|
480
|
-
throw clearTimeout(e),
|
|
468
|
+
throw clearTimeout(e), v("%s failed with error: %O", s, t), t instanceof Error && (v("Error message: %s", t.message), v("Error stack: %s", t.stack)), t;
|
|
481
469
|
}
|
|
482
470
|
function Ct(t, e = "request") {
|
|
483
471
|
if (!t.ok)
|
|
484
472
|
throw new Error(`HTTP error! status: ${t.status}`);
|
|
485
473
|
}
|
|
486
|
-
function
|
|
474
|
+
function Lt(t, e = "request") {
|
|
487
475
|
if (t.error)
|
|
488
476
|
throw new Error(`A2A ${e} error: ${t.error.message}`);
|
|
489
477
|
if (!t.result)
|
|
490
478
|
throw new Error(`No result in ${e} response`);
|
|
491
479
|
return t.result;
|
|
492
480
|
}
|
|
493
|
-
function
|
|
481
|
+
function Wt(t, e = "streaming request") {
|
|
494
482
|
if (Ct(t, e), !t.body)
|
|
495
483
|
throw new Error(`No response body for ${e}`);
|
|
496
484
|
}
|
|
@@ -504,28 +492,28 @@ function xt(t, e = "request") {
|
|
|
504
492
|
function Vt(t, e) {
|
|
505
493
|
return `${t}/${e}`;
|
|
506
494
|
}
|
|
507
|
-
function
|
|
508
|
-
|
|
495
|
+
function Bt(t, e, s, a) {
|
|
496
|
+
v("Request: %s %s", t, e), v("Headers: %o", s), a && v("Body: %s", wt(a));
|
|
509
497
|
}
|
|
510
|
-
async function
|
|
498
|
+
async function zt(t, e = !1) {
|
|
511
499
|
const s = {
|
|
512
500
|
"Content-Type": "application/json"
|
|
513
501
|
};
|
|
514
502
|
if (e && (s.Accept = "text/event-stream"), t) {
|
|
515
|
-
const
|
|
516
|
-
return { ...s, ...
|
|
503
|
+
const a = await t();
|
|
504
|
+
return { ...s, ...a };
|
|
517
505
|
}
|
|
518
506
|
return s;
|
|
519
507
|
}
|
|
520
508
|
function bt(t, e) {
|
|
521
509
|
if (!e)
|
|
522
510
|
return t;
|
|
523
|
-
const s = new AbortController(),
|
|
524
|
-
s.signal.aborted || s.abort(
|
|
511
|
+
const s = new AbortController(), a = (n) => {
|
|
512
|
+
s.signal.aborted || s.abort(n.reason);
|
|
525
513
|
};
|
|
526
|
-
return t.aborted ? s.abort(t.reason) : t.addEventListener("abort", () =>
|
|
514
|
+
return t.aborted ? s.abort(t.reason) : t.addEventListener("abort", () => a(t), {
|
|
527
515
|
once: !0
|
|
528
|
-
}), e.aborted ? s.abort(e.reason) : e.addEventListener("abort", () =>
|
|
516
|
+
}), e.aborted ? s.abort(e.reason) : e.addEventListener("abort", () => a(e), {
|
|
529
517
|
once: !0
|
|
530
518
|
}), s.signal;
|
|
531
519
|
}
|
|
@@ -537,94 +525,94 @@ function Mt(t, e, s) {
|
|
|
537
525
|
signal: s
|
|
538
526
|
};
|
|
539
527
|
}
|
|
540
|
-
async function
|
|
541
|
-
const { message: o, sessionId:
|
|
528
|
+
async function X(t, e, s, a, n, r) {
|
|
529
|
+
const { message: o, sessionId: l, taskId: i, metadata: m } = t, { agentId: g, agentUrl: h, authProvider: f, proxy: p } = e, { isStreaming: S = !1, enableTokenStreaming: c = !1 } = s, u = l || r, w = Vt(h, g), d = await Ut(
|
|
542
530
|
o,
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
),
|
|
531
|
+
a,
|
|
532
|
+
n
|
|
533
|
+
), y = Nt(
|
|
546
534
|
{
|
|
547
535
|
id: i,
|
|
548
|
-
sessionId:
|
|
536
|
+
sessionId: u,
|
|
549
537
|
message: d,
|
|
550
|
-
metadata:
|
|
538
|
+
metadata: m
|
|
551
539
|
},
|
|
552
|
-
|
|
553
|
-
|
|
540
|
+
S ? "message/stream" : "message/send",
|
|
541
|
+
c && S
|
|
554
542
|
// Only enable token streaming if using SSE
|
|
555
|
-
),
|
|
556
|
-
return
|
|
557
|
-
request:
|
|
558
|
-
headers:
|
|
543
|
+
), x = await zt(f, S);
|
|
544
|
+
return Bt("POST", w, x, y), {
|
|
545
|
+
request: y,
|
|
546
|
+
headers: x,
|
|
559
547
|
enhancedMessage: d,
|
|
560
|
-
effectiveSessionId:
|
|
561
|
-
fullAgentUrl:
|
|
548
|
+
effectiveSessionId: u,
|
|
549
|
+
fullAgentUrl: w
|
|
562
550
|
};
|
|
563
551
|
}
|
|
564
552
|
async function At(t, e, s = {}) {
|
|
565
|
-
const { request:
|
|
553
|
+
const { request: a, headers: n, fullAgentUrl: r } = t, { timeout: o } = e, { abortSignal: l } = s, { timeoutId: i, controller: m } = xt(
|
|
566
554
|
o,
|
|
567
555
|
"request"
|
|
568
|
-
),
|
|
556
|
+
), g = l ? bt(m.signal, l) : m.signal;
|
|
569
557
|
try {
|
|
570
|
-
const
|
|
571
|
-
|
|
572
|
-
JSON.stringify(
|
|
573
|
-
|
|
558
|
+
const h = Mt(
|
|
559
|
+
n,
|
|
560
|
+
JSON.stringify(a),
|
|
561
|
+
g
|
|
574
562
|
);
|
|
575
|
-
|
|
576
|
-
method:
|
|
577
|
-
headers:
|
|
563
|
+
v("Making request to %s with options: %O", r, {
|
|
564
|
+
method: h.method,
|
|
565
|
+
headers: h.headers
|
|
578
566
|
});
|
|
579
|
-
const
|
|
580
|
-
clearTimeout(i), Ct(
|
|
581
|
-
const
|
|
582
|
-
return
|
|
567
|
+
const f = await fetch(r, h);
|
|
568
|
+
clearTimeout(i), Ct(f, "request");
|
|
569
|
+
const p = await f.json();
|
|
570
|
+
return v(
|
|
583
571
|
"Response from %s: %d %O",
|
|
584
572
|
r,
|
|
585
|
-
|
|
586
|
-
wt(
|
|
587
|
-
),
|
|
588
|
-
} catch (
|
|
589
|
-
Tt(
|
|
573
|
+
f.status,
|
|
574
|
+
wt(p)
|
|
575
|
+
), Lt(p, "request");
|
|
576
|
+
} catch (h) {
|
|
577
|
+
Tt(h, i, "request");
|
|
590
578
|
}
|
|
591
579
|
}
|
|
592
580
|
async function* St(t, e, s) {
|
|
593
|
-
const { request:
|
|
581
|
+
const { request: a, headers: n, fullAgentUrl: r } = t, {
|
|
594
582
|
streamingTimeout: o = 6e4,
|
|
595
|
-
abortSignal:
|
|
583
|
+
abortSignal: l,
|
|
596
584
|
enableTokenStreaming: i = !1
|
|
597
|
-
} = s, { timeoutId:
|
|
585
|
+
} = s, { timeoutId: m, controller: g } = xt(
|
|
598
586
|
o,
|
|
599
587
|
"streaming request"
|
|
600
|
-
),
|
|
588
|
+
), h = l ? bt(g.signal, l) : g.signal;
|
|
601
589
|
try {
|
|
602
|
-
const
|
|
603
|
-
if (clearTimeout(
|
|
590
|
+
const f = JSON.stringify(a), p = Mt(n, f, h), S = await fetch(r, p);
|
|
591
|
+
if (clearTimeout(m), Wt(S, "streaming request"), !S.body)
|
|
604
592
|
throw new Error(
|
|
605
593
|
"Response body is null - server may not support streaming"
|
|
606
594
|
);
|
|
607
|
-
const
|
|
608
|
-
yield*
|
|
609
|
-
supportDeltas:
|
|
595
|
+
const c = i && a.tokenStreaming === !0;
|
|
596
|
+
yield* Jt(S.body, {
|
|
597
|
+
supportDeltas: c
|
|
610
598
|
});
|
|
611
|
-
} catch (
|
|
612
|
-
Tt(
|
|
599
|
+
} catch (f) {
|
|
600
|
+
Tt(f, m, "streaming request");
|
|
613
601
|
}
|
|
614
602
|
}
|
|
615
603
|
const Qt = 12e4;
|
|
616
|
-
async function
|
|
604
|
+
async function G(t, e, s, a, n) {
|
|
617
605
|
if (t.getAbilities) {
|
|
618
606
|
const r = await t.getAbilities();
|
|
619
607
|
if (r.length > 0)
|
|
620
608
|
for (const o of r) {
|
|
621
|
-
const
|
|
622
|
-
if (e ===
|
|
609
|
+
const l = o.name.replace(/\//g, "__").replace(/-/g, "_");
|
|
610
|
+
if (e === l || e === o.name) {
|
|
623
611
|
if (o.callback)
|
|
624
612
|
try {
|
|
625
613
|
return { result: await o.callback(s), returnToAgent: !0 };
|
|
626
614
|
} catch (i) {
|
|
627
|
-
return
|
|
615
|
+
return v(
|
|
628
616
|
"Error executing ability %s: %O",
|
|
629
617
|
o.name,
|
|
630
618
|
i
|
|
@@ -643,7 +631,7 @@ async function X(t, e, s, n, a) {
|
|
|
643
631
|
s
|
|
644
632
|
), returnToAgent: !0 };
|
|
645
633
|
} catch (i) {
|
|
646
|
-
return
|
|
634
|
+
return v(
|
|
647
635
|
"Error executing ability %s: %O",
|
|
648
636
|
o.name,
|
|
649
637
|
i
|
|
@@ -665,8 +653,8 @@ async function X(t, e, s, n, a) {
|
|
|
665
653
|
return await t.executeTool(
|
|
666
654
|
e,
|
|
667
655
|
s,
|
|
668
|
-
|
|
669
|
-
|
|
656
|
+
a,
|
|
657
|
+
n
|
|
670
658
|
);
|
|
671
659
|
throw new Error(
|
|
672
660
|
`No handler found for tool: ${e}. Tool provider must implement executeTool for non-ability tools.`
|
|
@@ -680,10 +668,10 @@ async function Xt(t, e) {
|
|
|
680
668
|
if (s.length === 0)
|
|
681
669
|
return !1;
|
|
682
670
|
try {
|
|
683
|
-
const
|
|
684
|
-
for (const
|
|
685
|
-
if (
|
|
686
|
-
(o) => o.id ===
|
|
671
|
+
const a = await t.getAvailableTools();
|
|
672
|
+
for (const n of s)
|
|
673
|
+
if (a.some(
|
|
674
|
+
(o) => o.id === n.data.toolId
|
|
687
675
|
))
|
|
688
676
|
return !0;
|
|
689
677
|
} catch {
|
|
@@ -691,76 +679,76 @@ async function Xt(t, e) {
|
|
|
691
679
|
}
|
|
692
680
|
return !1;
|
|
693
681
|
}
|
|
694
|
-
function
|
|
682
|
+
function Gt() {
|
|
695
683
|
lt.clear();
|
|
696
684
|
}
|
|
697
|
-
function
|
|
685
|
+
function Yt(t) {
|
|
698
686
|
return t.map((e) => {
|
|
699
|
-
const s = e.data.toolCallId,
|
|
700
|
-
if (
|
|
701
|
-
const
|
|
702
|
-
return
|
|
687
|
+
const s = e.data.toolCallId, a = lt.get(s);
|
|
688
|
+
if (a && a.resolvedValue !== null) {
|
|
689
|
+
const n = a.resolvedValue;
|
|
690
|
+
return n.error ? j(
|
|
703
691
|
s,
|
|
704
692
|
e.data.toolId,
|
|
705
693
|
void 0,
|
|
706
|
-
|
|
694
|
+
n.error
|
|
707
695
|
) : j(
|
|
708
696
|
s,
|
|
709
697
|
e.data.toolId,
|
|
710
|
-
|
|
698
|
+
n
|
|
711
699
|
);
|
|
712
700
|
}
|
|
713
701
|
return e;
|
|
714
702
|
});
|
|
715
703
|
}
|
|
716
704
|
async function vt(t, e, s) {
|
|
717
|
-
const
|
|
705
|
+
const a = [], n = [];
|
|
718
706
|
let r = !1;
|
|
719
707
|
for (const o of t) {
|
|
720
|
-
const { toolCallId:
|
|
708
|
+
const { toolCallId: l, toolId: i, arguments: m } = o.data;
|
|
721
709
|
try {
|
|
722
|
-
const
|
|
710
|
+
const g = await G(
|
|
723
711
|
e,
|
|
724
712
|
i,
|
|
725
|
-
|
|
713
|
+
m,
|
|
726
714
|
s,
|
|
727
|
-
|
|
728
|
-
), { result:
|
|
729
|
-
|
|
715
|
+
l
|
|
716
|
+
), { result: h, returnToAgent: f, agentMessage: p } = it(g);
|
|
717
|
+
f && (r = !0), p && n.push(W(p)), a.push(
|
|
730
718
|
j(
|
|
731
|
-
|
|
719
|
+
l,
|
|
732
720
|
i,
|
|
733
|
-
|
|
721
|
+
h
|
|
734
722
|
)
|
|
735
723
|
);
|
|
736
|
-
} catch (
|
|
737
|
-
r = !0,
|
|
724
|
+
} catch (g) {
|
|
725
|
+
r = !0, a.push(
|
|
738
726
|
j(
|
|
739
|
-
|
|
727
|
+
l,
|
|
740
728
|
i,
|
|
741
729
|
void 0,
|
|
742
|
-
|
|
730
|
+
g instanceof Error ? g.message : String(g)
|
|
743
731
|
)
|
|
744
732
|
);
|
|
745
733
|
}
|
|
746
734
|
}
|
|
747
|
-
return { results:
|
|
735
|
+
return { results: a, shouldReturnToAgent: r, agentMessages: n };
|
|
748
736
|
}
|
|
749
737
|
function gt(t) {
|
|
750
738
|
const e = [];
|
|
751
739
|
for (const s of t)
|
|
752
|
-
for (const
|
|
753
|
-
|
|
740
|
+
for (const a of s.parts)
|
|
741
|
+
a.type === "text" ? e.push({
|
|
754
742
|
type: "data",
|
|
755
743
|
data: {
|
|
756
744
|
role: s.role,
|
|
757
|
-
text:
|
|
745
|
+
text: a.text
|
|
758
746
|
}
|
|
759
|
-
}) :
|
|
747
|
+
}) : a.type === "data" && e.push(a);
|
|
760
748
|
return e;
|
|
761
749
|
}
|
|
762
|
-
async function et(t, e, s,
|
|
763
|
-
const i = await
|
|
750
|
+
async function et(t, e, s, a, n, r, o) {
|
|
751
|
+
const i = await X(
|
|
764
752
|
{
|
|
765
753
|
message: e,
|
|
766
754
|
taskId: t,
|
|
@@ -769,37 +757,37 @@ async function et(t, e, s, n, a, r, o) {
|
|
|
769
757
|
},
|
|
770
758
|
s,
|
|
771
759
|
{ isStreaming: !1 },
|
|
772
|
-
n,
|
|
773
760
|
a,
|
|
761
|
+
n,
|
|
774
762
|
r
|
|
775
763
|
);
|
|
776
764
|
return await At(i, s, {
|
|
777
765
|
abortSignal: o
|
|
778
766
|
});
|
|
779
767
|
}
|
|
780
|
-
async function ft(t, e, s,
|
|
781
|
-
const
|
|
768
|
+
async function ft(t, e, s, a, n, r, o, l, i = []) {
|
|
769
|
+
const m = {
|
|
782
770
|
message: e,
|
|
783
771
|
taskId: t,
|
|
784
772
|
sessionId: void 0
|
|
785
773
|
// Use task's session
|
|
786
|
-
},
|
|
787
|
-
|
|
774
|
+
}, g = l || { isStreaming: !0 }, h = await X(
|
|
775
|
+
m,
|
|
788
776
|
s,
|
|
789
777
|
{
|
|
790
|
-
...
|
|
778
|
+
...g
|
|
791
779
|
},
|
|
792
|
-
n,
|
|
793
780
|
a,
|
|
781
|
+
n,
|
|
794
782
|
r
|
|
795
|
-
),
|
|
796
|
-
...
|
|
783
|
+
), f = St(h, s, {
|
|
784
|
+
...g,
|
|
797
785
|
abortSignal: o
|
|
798
786
|
});
|
|
799
787
|
return kt(
|
|
800
|
-
|
|
801
|
-
n,
|
|
788
|
+
f,
|
|
802
789
|
a,
|
|
790
|
+
n,
|
|
803
791
|
s,
|
|
804
792
|
r,
|
|
805
793
|
!0,
|
|
@@ -807,163 +795,161 @@ async function ft(t, e, s, n, a, r, o, c, i = []) {
|
|
|
807
795
|
i,
|
|
808
796
|
// preserve conversation parts across continuation
|
|
809
797
|
o,
|
|
810
|
-
|
|
798
|
+
g
|
|
811
799
|
// Pass through the same request options
|
|
812
800
|
);
|
|
813
801
|
}
|
|
814
|
-
async function* kt(t, e, s,
|
|
815
|
-
var
|
|
816
|
-
for await (const
|
|
817
|
-
if (yield
|
|
802
|
+
async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
803
|
+
var m, g, h, f, p, S, c, u, w, d, y, x;
|
|
804
|
+
for await (const I of t) {
|
|
805
|
+
if (yield I, I.status.state === "running" && I.status.message && e && await Xt(
|
|
818
806
|
e,
|
|
819
|
-
|
|
807
|
+
I.status.message
|
|
820
808
|
)) {
|
|
821
809
|
const P = F(
|
|
822
|
-
|
|
810
|
+
I.status.message
|
|
823
811
|
);
|
|
824
812
|
for (const T of P) {
|
|
825
|
-
const { toolCallId:
|
|
826
|
-
|
|
813
|
+
const { toolCallId: b, toolId: k, arguments: M } = T.data;
|
|
814
|
+
G(
|
|
827
815
|
e,
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
(
|
|
831
|
-
|
|
832
|
-
).catch((
|
|
833
|
-
|
|
834
|
-
`Tool execution failed for ${v}:`,
|
|
835
|
-
S
|
|
836
|
-
);
|
|
816
|
+
k,
|
|
817
|
+
M,
|
|
818
|
+
(g = (m = I.status) == null ? void 0 : m.message) == null ? void 0 : g.messageId,
|
|
819
|
+
b
|
|
820
|
+
).catch((C) => {
|
|
821
|
+
v("Tool execution failed for %s: %O", k, C);
|
|
837
822
|
});
|
|
838
823
|
}
|
|
839
824
|
yield {
|
|
840
|
-
id:
|
|
825
|
+
id: I.id,
|
|
841
826
|
status: {
|
|
842
827
|
state: "running",
|
|
843
828
|
message: {
|
|
844
829
|
role: "agent",
|
|
845
830
|
kind: "message",
|
|
846
831
|
parts: P,
|
|
847
|
-
messageId:
|
|
832
|
+
messageId: N()
|
|
848
833
|
}
|
|
849
834
|
},
|
|
850
835
|
final: !1,
|
|
851
836
|
text: ""
|
|
852
837
|
};
|
|
853
838
|
}
|
|
854
|
-
if (
|
|
839
|
+
if (I.status.state === "input-required" && I.status.message && e) {
|
|
855
840
|
const P = F(
|
|
856
|
-
|
|
841
|
+
I.status.message
|
|
857
842
|
);
|
|
858
843
|
if (P.length > 0) {
|
|
859
844
|
const T = [];
|
|
860
|
-
let
|
|
861
|
-
const
|
|
862
|
-
for (const
|
|
845
|
+
let b = !1;
|
|
846
|
+
const k = [], M = [];
|
|
847
|
+
for (const C of P) {
|
|
863
848
|
const {
|
|
864
|
-
toolCallId:
|
|
865
|
-
toolId:
|
|
866
|
-
arguments:
|
|
867
|
-
} =
|
|
849
|
+
toolCallId: A,
|
|
850
|
+
toolId: q,
|
|
851
|
+
arguments: _
|
|
852
|
+
} = C.data;
|
|
868
853
|
try {
|
|
869
|
-
const E = await
|
|
854
|
+
const E = await G(
|
|
870
855
|
e,
|
|
856
|
+
q,
|
|
871
857
|
_,
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
if (O && (x = !0), J && C.push(
|
|
858
|
+
(f = (h = I.status) == null ? void 0 : h.message) == null ? void 0 : f.messageId,
|
|
859
|
+
A
|
|
860
|
+
), { result: R, returnToAgent: O, agentMessage: J } = it(E);
|
|
861
|
+
if (O && (b = !0), J && M.push(
|
|
877
862
|
W(J)
|
|
878
|
-
),
|
|
879
|
-
const
|
|
880
|
-
promise:
|
|
863
|
+
), R.result instanceof Promise) {
|
|
864
|
+
const B = R.result, K = {
|
|
865
|
+
promise: B,
|
|
881
866
|
resolvedValue: null
|
|
882
867
|
};
|
|
883
868
|
lt.set(
|
|
884
|
-
|
|
869
|
+
A,
|
|
885
870
|
K
|
|
886
|
-
),
|
|
871
|
+
), B.then((H) => {
|
|
887
872
|
K.resolvedValue = H;
|
|
888
873
|
}).catch((H) => {
|
|
889
|
-
|
|
890
|
-
|
|
874
|
+
v(
|
|
875
|
+
"Promise rejected for tool call %s: %O",
|
|
876
|
+
A,
|
|
891
877
|
H
|
|
892
878
|
), K.resolvedValue = {
|
|
893
879
|
error: H instanceof Error ? H.message : String(H)
|
|
894
880
|
};
|
|
895
881
|
});
|
|
896
882
|
}
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
883
|
+
const V = j(
|
|
884
|
+
A,
|
|
885
|
+
q,
|
|
886
|
+
R
|
|
901
887
|
);
|
|
902
|
-
T.push(
|
|
888
|
+
T.push(V), k.push(V);
|
|
903
889
|
} catch (E) {
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
890
|
+
const R = j(
|
|
891
|
+
A,
|
|
892
|
+
q,
|
|
907
893
|
void 0,
|
|
908
894
|
E instanceof Error ? E.message : String(E)
|
|
909
895
|
);
|
|
910
|
-
T.push(
|
|
896
|
+
T.push(R), k.push(R);
|
|
911
897
|
}
|
|
912
898
|
}
|
|
913
|
-
if (o.push(
|
|
899
|
+
if (o.push(I.status.message), T.length > 0 && o.push({
|
|
914
900
|
role: "agent",
|
|
915
901
|
kind: "message",
|
|
916
902
|
parts: T,
|
|
917
|
-
messageId:
|
|
918
|
-
}),
|
|
919
|
-
const
|
|
903
|
+
messageId: N()
|
|
904
|
+
}), b) {
|
|
905
|
+
const C = gt(o), A = Q(
|
|
920
906
|
[],
|
|
921
907
|
// Empty array - tool results are already in historyDataParts
|
|
922
|
-
|
|
908
|
+
C
|
|
923
909
|
);
|
|
924
910
|
yield {
|
|
925
|
-
id:
|
|
911
|
+
id: I.id,
|
|
926
912
|
status: {
|
|
927
913
|
state: "working",
|
|
928
|
-
message:
|
|
914
|
+
message: A
|
|
929
915
|
},
|
|
930
916
|
final: !1,
|
|
931
917
|
text: ""
|
|
932
918
|
};
|
|
933
|
-
const
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
919
|
+
const q = await ft(
|
|
920
|
+
I.id,
|
|
921
|
+
A,
|
|
922
|
+
a,
|
|
937
923
|
e,
|
|
938
924
|
s,
|
|
939
|
-
|
|
940
|
-
|
|
925
|
+
n,
|
|
926
|
+
l,
|
|
941
927
|
i,
|
|
942
928
|
o
|
|
943
929
|
);
|
|
944
|
-
let
|
|
945
|
-
for await (const O of
|
|
946
|
-
O.final ?
|
|
947
|
-
if (!
|
|
930
|
+
let _ = null;
|
|
931
|
+
for await (const O of q)
|
|
932
|
+
O.final ? _ = O : yield O;
|
|
933
|
+
if (!_)
|
|
948
934
|
throw new Error(
|
|
949
935
|
"Continue task stream ended without final result"
|
|
950
936
|
);
|
|
951
|
-
let E = (
|
|
952
|
-
|
|
953
|
-
) : [],
|
|
937
|
+
let E = (p = _.status) != null && p.message ? F(
|
|
938
|
+
_.status.message
|
|
939
|
+
) : [], R = _;
|
|
954
940
|
if (E.length > 0)
|
|
955
941
|
for (yield {
|
|
956
|
-
...
|
|
942
|
+
..._,
|
|
957
943
|
final: !1,
|
|
958
944
|
text: D(
|
|
959
|
-
((
|
|
945
|
+
((S = _.status) == null ? void 0 : S.message) || {
|
|
960
946
|
parts: [],
|
|
961
|
-
messageId:
|
|
947
|
+
messageId: N()
|
|
962
948
|
}
|
|
963
949
|
)
|
|
964
950
|
}; E.length > 0; ) {
|
|
965
|
-
(
|
|
966
|
-
|
|
951
|
+
(c = R.status) != null && c.message && o.push(
|
|
952
|
+
R.status.message
|
|
967
953
|
);
|
|
968
954
|
const {
|
|
969
955
|
results: O,
|
|
@@ -971,36 +957,36 @@ async function* kt(t, e, s, n, a, r = !0, o = [], c, i) {
|
|
|
971
957
|
} = await vt(
|
|
972
958
|
E,
|
|
973
959
|
e,
|
|
974
|
-
(
|
|
960
|
+
(w = (u = R.status) == null ? void 0 : u.message) == null ? void 0 : w.messageId
|
|
975
961
|
);
|
|
976
962
|
if (O.length > 0 && (yield {
|
|
977
|
-
id:
|
|
963
|
+
id: R.id,
|
|
978
964
|
status: {
|
|
979
965
|
state: "working",
|
|
980
966
|
message: {
|
|
981
967
|
role: "agent",
|
|
982
968
|
kind: "message",
|
|
983
969
|
parts: O,
|
|
984
|
-
messageId:
|
|
970
|
+
messageId: N()
|
|
985
971
|
}
|
|
986
972
|
// Simple message with just the results
|
|
987
973
|
},
|
|
988
974
|
final: !1,
|
|
989
975
|
text: ""
|
|
990
976
|
}), J) {
|
|
991
|
-
const
|
|
977
|
+
const V = r ? gt(
|
|
992
978
|
o
|
|
993
|
-
) : [],
|
|
979
|
+
) : [], B = Q(
|
|
994
980
|
O,
|
|
995
|
-
|
|
981
|
+
V
|
|
996
982
|
), K = await ft(
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
983
|
+
R.id,
|
|
984
|
+
B,
|
|
985
|
+
a,
|
|
1000
986
|
e,
|
|
1001
987
|
s,
|
|
1002
|
-
|
|
1003
|
-
|
|
988
|
+
n,
|
|
989
|
+
l,
|
|
1004
990
|
i,
|
|
1005
991
|
o
|
|
1006
992
|
);
|
|
@@ -1011,16 +997,16 @@ async function* kt(t, e, s, n, a, r = !0, o = [], c, i) {
|
|
|
1011
997
|
throw new Error(
|
|
1012
998
|
"Continue task stream ended without final result"
|
|
1013
999
|
);
|
|
1014
|
-
|
|
1015
|
-
|
|
1000
|
+
R = H, E = (d = R.status) != null && d.message ? F(
|
|
1001
|
+
R.status.message
|
|
1016
1002
|
) : [], E.length > 0 && (yield {
|
|
1017
|
-
id:
|
|
1018
|
-
status:
|
|
1003
|
+
id: R.id,
|
|
1004
|
+
status: R.status,
|
|
1019
1005
|
final: !1,
|
|
1020
1006
|
text: D(
|
|
1021
|
-
((
|
|
1007
|
+
((y = R.status) == null ? void 0 : y.message) || {
|
|
1022
1008
|
parts: [],
|
|
1023
|
-
messageId:
|
|
1009
|
+
messageId: N()
|
|
1024
1010
|
}
|
|
1025
1011
|
)
|
|
1026
1012
|
});
|
|
@@ -1028,39 +1014,39 @@ async function* kt(t, e, s, n, a, r = !0, o = [], c, i) {
|
|
|
1028
1014
|
break;
|
|
1029
1015
|
}
|
|
1030
1016
|
yield {
|
|
1031
|
-
...
|
|
1017
|
+
...R,
|
|
1032
1018
|
final: !0,
|
|
1033
1019
|
text: D(
|
|
1034
|
-
((
|
|
1020
|
+
((x = R.status) == null ? void 0 : x.message) || {
|
|
1035
1021
|
parts: [],
|
|
1036
|
-
messageId:
|
|
1022
|
+
messageId: N()
|
|
1037
1023
|
}
|
|
1038
1024
|
)
|
|
1039
1025
|
};
|
|
1040
1026
|
} else {
|
|
1041
|
-
const
|
|
1042
|
-
...
|
|
1043
|
-
parts:
|
|
1044
|
-
},
|
|
1045
|
-
...
|
|
1027
|
+
const C = {
|
|
1028
|
+
...I.status.message,
|
|
1029
|
+
parts: k
|
|
1030
|
+
}, A = {
|
|
1031
|
+
...I,
|
|
1046
1032
|
status: {
|
|
1047
|
-
...
|
|
1048
|
-
message:
|
|
1033
|
+
...I.status,
|
|
1034
|
+
message: C
|
|
1049
1035
|
},
|
|
1050
|
-
final:
|
|
1036
|
+
final: M.length === 0,
|
|
1051
1037
|
// Only final if no agent messages to follow
|
|
1052
|
-
text: D(
|
|
1038
|
+
text: D(C)
|
|
1053
1039
|
};
|
|
1054
|
-
if (yield
|
|
1055
|
-
const
|
|
1040
|
+
if (yield A, M.length > 0) {
|
|
1041
|
+
const q = M.map((E) => D(E)).join(" "), _ = W(q);
|
|
1056
1042
|
yield {
|
|
1057
|
-
id:
|
|
1043
|
+
id: A.id,
|
|
1058
1044
|
status: {
|
|
1059
1045
|
state: "completed",
|
|
1060
|
-
message:
|
|
1046
|
+
message: _
|
|
1061
1047
|
},
|
|
1062
1048
|
final: !0,
|
|
1063
|
-
text:
|
|
1049
|
+
text: q
|
|
1064
1050
|
};
|
|
1065
1051
|
}
|
|
1066
1052
|
}
|
|
@@ -1068,257 +1054,257 @@ async function* kt(t, e, s, n, a, r = !0, o = [], c, i) {
|
|
|
1068
1054
|
}
|
|
1069
1055
|
}
|
|
1070
1056
|
}
|
|
1071
|
-
function
|
|
1057
|
+
function Zt(t) {
|
|
1072
1058
|
const {
|
|
1073
1059
|
agentId: e,
|
|
1074
1060
|
agentUrl: s,
|
|
1075
|
-
authProvider:
|
|
1076
|
-
defaultSessionId:
|
|
1061
|
+
authProvider: a,
|
|
1062
|
+
defaultSessionId: n,
|
|
1077
1063
|
timeout: r = Qt,
|
|
1078
1064
|
toolProvider: o,
|
|
1079
|
-
contextProvider:
|
|
1065
|
+
contextProvider: l,
|
|
1080
1066
|
enableStreaming: i = !1
|
|
1081
|
-
} = t,
|
|
1067
|
+
} = t, m = {
|
|
1082
1068
|
agentId: e,
|
|
1083
1069
|
agentUrl: s,
|
|
1084
|
-
authProvider:
|
|
1070
|
+
authProvider: a,
|
|
1085
1071
|
timeout: r
|
|
1086
1072
|
};
|
|
1087
1073
|
return {
|
|
1088
|
-
async sendMessage(
|
|
1089
|
-
var
|
|
1090
|
-
const {
|
|
1091
|
-
|
|
1092
|
-
const
|
|
1093
|
-
|
|
1094
|
-
|
|
1074
|
+
async sendMessage(g) {
|
|
1075
|
+
var d, y;
|
|
1076
|
+
const { abortSignal: h } = g, f = g.sessionId || n || void 0, p = [];
|
|
1077
|
+
p.push(g.message);
|
|
1078
|
+
const S = await X(
|
|
1079
|
+
g,
|
|
1080
|
+
m,
|
|
1095
1081
|
{ isStreaming: !1 },
|
|
1096
1082
|
o,
|
|
1097
|
-
|
|
1098
|
-
|
|
1083
|
+
l,
|
|
1084
|
+
f
|
|
1099
1085
|
);
|
|
1100
|
-
let
|
|
1086
|
+
let c = await At(
|
|
1087
|
+
S,
|
|
1101
1088
|
m,
|
|
1102
|
-
|
|
1103
|
-
{ abortSignal: g }
|
|
1089
|
+
{ abortSignal: h }
|
|
1104
1090
|
);
|
|
1105
|
-
const
|
|
1106
|
-
for (;
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1091
|
+
const u = [], w = [];
|
|
1092
|
+
for (; c.status.message && o; ) {
|
|
1093
|
+
const x = F(
|
|
1094
|
+
c.status.message
|
|
1109
1095
|
);
|
|
1110
|
-
if (
|
|
1096
|
+
if (x.length === 0)
|
|
1111
1097
|
break;
|
|
1112
|
-
|
|
1113
|
-
const
|
|
1114
|
-
let
|
|
1115
|
-
for (const
|
|
1098
|
+
u.push(...x);
|
|
1099
|
+
const I = [];
|
|
1100
|
+
let P = !1;
|
|
1101
|
+
for (const T of x) {
|
|
1116
1102
|
const {
|
|
1117
|
-
toolCallId:
|
|
1118
|
-
toolId:
|
|
1119
|
-
arguments:
|
|
1120
|
-
} =
|
|
1103
|
+
toolCallId: b,
|
|
1104
|
+
toolId: k,
|
|
1105
|
+
arguments: M
|
|
1106
|
+
} = T.data;
|
|
1121
1107
|
try {
|
|
1122
|
-
const
|
|
1108
|
+
const C = await G(
|
|
1123
1109
|
o,
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
), { result:
|
|
1127
|
-
|
|
1128
|
-
W(
|
|
1110
|
+
k,
|
|
1111
|
+
M
|
|
1112
|
+
), { result: A, returnToAgent: q, agentMessage: _ } = it(C);
|
|
1113
|
+
q && (P = !0), _ && w.push(
|
|
1114
|
+
W(_)
|
|
1129
1115
|
);
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1116
|
+
const E = j(
|
|
1117
|
+
b,
|
|
1118
|
+
k,
|
|
1119
|
+
A
|
|
1134
1120
|
);
|
|
1135
|
-
|
|
1136
|
-
} catch (
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1139
|
-
|
|
1121
|
+
I.push(E), u.push(E);
|
|
1122
|
+
} catch (C) {
|
|
1123
|
+
const A = j(
|
|
1124
|
+
b,
|
|
1125
|
+
k,
|
|
1140
1126
|
void 0,
|
|
1141
|
-
|
|
1127
|
+
C instanceof Error ? C.message : String(C)
|
|
1142
1128
|
);
|
|
1143
|
-
|
|
1129
|
+
I.push(A), u.push(A);
|
|
1144
1130
|
}
|
|
1145
1131
|
}
|
|
1146
|
-
if (
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1132
|
+
if (p.push(c.status.message), P) {
|
|
1133
|
+
const T = Q(I);
|
|
1134
|
+
c = await et(
|
|
1135
|
+
c.id,
|
|
1136
|
+
T,
|
|
1137
|
+
m,
|
|
1152
1138
|
o,
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1139
|
+
l,
|
|
1140
|
+
f,
|
|
1141
|
+
h
|
|
1156
1142
|
);
|
|
1157
1143
|
} else
|
|
1158
1144
|
break;
|
|
1159
1145
|
}
|
|
1160
|
-
if (
|
|
1161
|
-
const
|
|
1162
|
-
...
|
|
1163
|
-
parts:
|
|
1146
|
+
if (u.length > 0 && (d = c.status) != null && d.message) {
|
|
1147
|
+
const x = {
|
|
1148
|
+
...c.status.message,
|
|
1149
|
+
parts: u
|
|
1164
1150
|
};
|
|
1165
|
-
|
|
1166
|
-
...
|
|
1151
|
+
c = {
|
|
1152
|
+
...c,
|
|
1167
1153
|
status: {
|
|
1168
|
-
...
|
|
1169
|
-
message:
|
|
1154
|
+
...c.status,
|
|
1155
|
+
message: x
|
|
1170
1156
|
}
|
|
1171
1157
|
};
|
|
1172
1158
|
}
|
|
1173
|
-
if (
|
|
1174
|
-
const
|
|
1159
|
+
if (w.length > 0) {
|
|
1160
|
+
const x = w.map((P) => D(P)).join(" "), I = W(x);
|
|
1175
1161
|
return {
|
|
1176
|
-
...
|
|
1162
|
+
...c,
|
|
1177
1163
|
// Keep the enhanced message with tool results
|
|
1178
1164
|
// The agent message will be handled separately by the caller
|
|
1179
|
-
text:
|
|
1180
|
-
agentMessage:
|
|
1165
|
+
text: x,
|
|
1166
|
+
agentMessage: I
|
|
1181
1167
|
// Add this for the caller to handle
|
|
1182
1168
|
};
|
|
1183
1169
|
}
|
|
1184
1170
|
return {
|
|
1185
|
-
...
|
|
1171
|
+
...c,
|
|
1186
1172
|
text: D(
|
|
1187
|
-
((
|
|
1173
|
+
((y = c.status) == null ? void 0 : y.message) || {
|
|
1188
1174
|
parts: [],
|
|
1189
|
-
messageId:
|
|
1175
|
+
messageId: N()
|
|
1190
1176
|
}
|
|
1191
1177
|
)
|
|
1192
1178
|
};
|
|
1193
1179
|
},
|
|
1194
|
-
async *sendMessageStream(
|
|
1180
|
+
async *sendMessageStream(g) {
|
|
1195
1181
|
const {
|
|
1196
|
-
withHistory:
|
|
1197
|
-
abortSignal:
|
|
1198
|
-
enableStreaming:
|
|
1199
|
-
} =
|
|
1200
|
-
|
|
1201
|
-
const
|
|
1202
|
-
|
|
1203
|
-
|
|
1182
|
+
withHistory: h = !0,
|
|
1183
|
+
abortSignal: f,
|
|
1184
|
+
enableStreaming: p
|
|
1185
|
+
} = g, S = g.sessionId || n || void 0, c = p ?? i, u = [];
|
|
1186
|
+
u.push(g.message);
|
|
1187
|
+
const w = await X(
|
|
1188
|
+
g,
|
|
1189
|
+
m,
|
|
1204
1190
|
{
|
|
1205
1191
|
isStreaming: !0,
|
|
1206
1192
|
// Always use message/stream endpoint for SSE
|
|
1207
|
-
enableTokenStreaming:
|
|
1193
|
+
enableTokenStreaming: c
|
|
1208
1194
|
},
|
|
1209
1195
|
o,
|
|
1210
|
-
|
|
1211
|
-
|
|
1196
|
+
l,
|
|
1197
|
+
S
|
|
1212
1198
|
), d = St(
|
|
1213
|
-
|
|
1214
|
-
|
|
1199
|
+
w,
|
|
1200
|
+
m,
|
|
1215
1201
|
{
|
|
1216
|
-
enableTokenStreaming:
|
|
1202
|
+
enableTokenStreaming: c,
|
|
1217
1203
|
// Token streaming is optional
|
|
1218
1204
|
streamingTimeout: r,
|
|
1219
|
-
abortSignal:
|
|
1205
|
+
abortSignal: f
|
|
1220
1206
|
}
|
|
1221
1207
|
);
|
|
1222
1208
|
yield* kt(
|
|
1223
1209
|
d,
|
|
1224
1210
|
o,
|
|
1225
|
-
c,
|
|
1226
|
-
f,
|
|
1227
|
-
M,
|
|
1228
|
-
p,
|
|
1229
1211
|
l,
|
|
1230
|
-
|
|
1212
|
+
m,
|
|
1213
|
+
S,
|
|
1214
|
+
h,
|
|
1215
|
+
u,
|
|
1216
|
+
f,
|
|
1231
1217
|
{
|
|
1232
1218
|
isStreaming: !0,
|
|
1233
|
-
enableTokenStreaming:
|
|
1219
|
+
enableTokenStreaming: c,
|
|
1234
1220
|
streamingTimeout: r
|
|
1235
1221
|
}
|
|
1236
1222
|
);
|
|
1237
1223
|
},
|
|
1238
|
-
async continueTask(
|
|
1239
|
-
var
|
|
1240
|
-
const
|
|
1241
|
-
let
|
|
1242
|
-
|
|
1243
|
-
|
|
1244
|
-
|
|
1224
|
+
async continueTask(g, h, f) {
|
|
1225
|
+
var u;
|
|
1226
|
+
const p = nt(h);
|
|
1227
|
+
let c = await et(
|
|
1228
|
+
g,
|
|
1229
|
+
p,
|
|
1230
|
+
m,
|
|
1245
1231
|
o,
|
|
1246
|
-
|
|
1247
|
-
|
|
1232
|
+
l,
|
|
1233
|
+
f
|
|
1248
1234
|
);
|
|
1249
|
-
for (;
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1235
|
+
for (; c.status.state === "input-required" && c.status.message && o; ) {
|
|
1236
|
+
const w = F(
|
|
1237
|
+
c.status.message
|
|
1252
1238
|
);
|
|
1253
|
-
if (
|
|
1239
|
+
if (w.length === 0)
|
|
1254
1240
|
break;
|
|
1255
|
-
const { results: d, shouldReturnToAgent:
|
|
1256
|
-
if (
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1241
|
+
const { results: d, shouldReturnToAgent: y } = await vt(w, o);
|
|
1242
|
+
if (y) {
|
|
1243
|
+
const x = Q(d);
|
|
1244
|
+
c = await et(
|
|
1245
|
+
c.id,
|
|
1246
|
+
x,
|
|
1247
|
+
m,
|
|
1262
1248
|
o,
|
|
1263
|
-
|
|
1264
|
-
|
|
1249
|
+
l,
|
|
1250
|
+
f
|
|
1265
1251
|
);
|
|
1266
1252
|
} else
|
|
1267
1253
|
break;
|
|
1268
1254
|
}
|
|
1269
1255
|
return {
|
|
1270
|
-
...
|
|
1256
|
+
...c,
|
|
1271
1257
|
text: D(
|
|
1272
|
-
((
|
|
1258
|
+
((u = c.status) == null ? void 0 : u.message) || {
|
|
1273
1259
|
parts: [],
|
|
1274
|
-
messageId:
|
|
1260
|
+
messageId: N()
|
|
1275
1261
|
}
|
|
1276
1262
|
)
|
|
1277
1263
|
};
|
|
1278
1264
|
},
|
|
1279
|
-
async getTask(
|
|
1265
|
+
async getTask() {
|
|
1280
1266
|
throw new Error("getTask not implemented yet");
|
|
1281
1267
|
},
|
|
1282
|
-
async cancelTask(
|
|
1268
|
+
async cancelTask() {
|
|
1283
1269
|
throw new Error("cancelTask not implemented yet");
|
|
1284
1270
|
}
|
|
1285
1271
|
};
|
|
1286
1272
|
}
|
|
1287
1273
|
const ct = "a8c_agenttic_conversation_history";
|
|
1288
|
-
function
|
|
1289
|
-
var
|
|
1274
|
+
function te(t) {
|
|
1275
|
+
var g, h;
|
|
1290
1276
|
const e = t.parts.filter(
|
|
1291
|
-
(
|
|
1292
|
-
), s = e.map((
|
|
1293
|
-
`),
|
|
1294
|
-
(
|
|
1295
|
-
var
|
|
1296
|
-
return ((
|
|
1277
|
+
(f) => f.type === "text"
|
|
1278
|
+
), s = e.map((f) => f.text).join(`
|
|
1279
|
+
`), a = e.some(
|
|
1280
|
+
(f) => {
|
|
1281
|
+
var p;
|
|
1282
|
+
return ((p = f.metadata) == null ? void 0 : p.contentType) === "context";
|
|
1297
1283
|
}
|
|
1298
|
-
) ? "context" : void 0,
|
|
1299
|
-
(
|
|
1300
|
-
).map((
|
|
1301
|
-
toolCallId:
|
|
1302
|
-
toolId:
|
|
1303
|
-
arguments:
|
|
1284
|
+
) ? "context" : void 0, n = t.parts.filter(
|
|
1285
|
+
(f) => f.type === "data" && "toolCallId" in f.data && "arguments" in f.data
|
|
1286
|
+
).map((f) => ({
|
|
1287
|
+
toolCallId: f.data.toolCallId,
|
|
1288
|
+
toolId: f.data.toolId,
|
|
1289
|
+
arguments: f.data.arguments
|
|
1304
1290
|
})), r = t.parts.filter(
|
|
1305
|
-
(
|
|
1306
|
-
).map((
|
|
1307
|
-
toolCallId:
|
|
1308
|
-
result:
|
|
1309
|
-
error:
|
|
1310
|
-
})),
|
|
1291
|
+
(f) => f.type === "data" && "toolCallId" in f.data && "result" in f.data
|
|
1292
|
+
).map((f) => ({
|
|
1293
|
+
toolCallId: f.data.toolCallId,
|
|
1294
|
+
result: f.data.result,
|
|
1295
|
+
error: f.data.error
|
|
1296
|
+
})), l = n.length > 0 || r.length > 0 ? "agent" : t.role, i = ((g = t.metadata) == null ? void 0 : g.timestamp) ?? Date.now(), m = ((h = t.metadata) == null ? void 0 : h.archived) ?? void 0;
|
|
1311
1297
|
return {
|
|
1312
|
-
role:
|
|
1298
|
+
role: l,
|
|
1313
1299
|
content: s || "(No text content)",
|
|
1314
1300
|
timestamp: i,
|
|
1315
|
-
...
|
|
1316
|
-
...
|
|
1317
|
-
...
|
|
1301
|
+
...m !== void 0 && { archived: m },
|
|
1302
|
+
...a && { contentType: a },
|
|
1303
|
+
...n.length > 0 && { toolCalls: n },
|
|
1318
1304
|
...r.length > 0 && { toolResults: r }
|
|
1319
1305
|
};
|
|
1320
1306
|
}
|
|
1321
|
-
function
|
|
1307
|
+
function ee(t) {
|
|
1322
1308
|
const e = [];
|
|
1323
1309
|
if (t.content && t.content !== "(No text content)" && e.push({
|
|
1324
1310
|
type: "text",
|
|
@@ -1352,7 +1338,7 @@ function se(t) {
|
|
|
1352
1338
|
role: t.role,
|
|
1353
1339
|
kind: "message",
|
|
1354
1340
|
parts: e,
|
|
1355
|
-
messageId:
|
|
1341
|
+
messageId: N(),
|
|
1356
1342
|
metadata: {
|
|
1357
1343
|
timestamp: t.timestamp,
|
|
1358
1344
|
// only store archived if it was already present.
|
|
@@ -1362,65 +1348,65 @@ function se(t) {
|
|
|
1362
1348
|
}
|
|
1363
1349
|
};
|
|
1364
1350
|
}
|
|
1365
|
-
const U = /* @__PURE__ */ new Map(),
|
|
1351
|
+
const U = /* @__PURE__ */ new Map(), se = 50;
|
|
1366
1352
|
async function ae(t, e, s) {
|
|
1367
|
-
const
|
|
1368
|
-
if (U.set(
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1353
|
+
const a = s || t;
|
|
1354
|
+
if (U.set(a, [...e]), U.size > se) {
|
|
1355
|
+
const n = U.keys().next().value;
|
|
1356
|
+
n && U.delete(n);
|
|
1371
1357
|
}
|
|
1372
1358
|
if (!(typeof sessionStorage > "u"))
|
|
1373
1359
|
try {
|
|
1374
|
-
const
|
|
1375
|
-
storageKey:
|
|
1376
|
-
messages: e.map(
|
|
1360
|
+
const n = {
|
|
1361
|
+
storageKey: a,
|
|
1362
|
+
messages: e.map(te),
|
|
1377
1363
|
lastUpdated: Date.now()
|
|
1378
1364
|
};
|
|
1379
1365
|
sessionStorage.setItem(
|
|
1380
|
-
`${ct}_${
|
|
1381
|
-
JSON.stringify(
|
|
1366
|
+
`${ct}_${a}`,
|
|
1367
|
+
JSON.stringify(n)
|
|
1382
1368
|
);
|
|
1383
|
-
} catch (
|
|
1384
|
-
|
|
1369
|
+
} catch (n) {
|
|
1370
|
+
v(
|
|
1385
1371
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1386
|
-
|
|
1387
|
-
|
|
1372
|
+
a,
|
|
1373
|
+
n
|
|
1388
1374
|
);
|
|
1389
1375
|
}
|
|
1390
1376
|
}
|
|
1391
|
-
async function
|
|
1377
|
+
async function ne(t, e) {
|
|
1392
1378
|
const s = e || t;
|
|
1393
1379
|
if (U.has(s))
|
|
1394
1380
|
return [...U.get(s)];
|
|
1395
1381
|
if (typeof sessionStorage > "u")
|
|
1396
1382
|
return [];
|
|
1397
1383
|
try {
|
|
1398
|
-
const
|
|
1384
|
+
const a = sessionStorage.getItem(
|
|
1399
1385
|
`${ct}_${s}`
|
|
1400
1386
|
);
|
|
1401
|
-
if (
|
|
1402
|
-
const r = JSON.parse(
|
|
1387
|
+
if (a) {
|
|
1388
|
+
const r = JSON.parse(a).messages.map(ee);
|
|
1403
1389
|
return U.set(s, r), [...r];
|
|
1404
1390
|
}
|
|
1405
|
-
} catch (
|
|
1406
|
-
|
|
1391
|
+
} catch (a) {
|
|
1392
|
+
v(
|
|
1407
1393
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1408
1394
|
s,
|
|
1409
|
-
|
|
1395
|
+
a
|
|
1410
1396
|
);
|
|
1411
1397
|
}
|
|
1412
1398
|
return [];
|
|
1413
1399
|
}
|
|
1414
|
-
async function
|
|
1400
|
+
async function oe(t, e) {
|
|
1415
1401
|
const s = e || t;
|
|
1416
1402
|
if (U.delete(s), !(typeof sessionStorage > "u"))
|
|
1417
1403
|
try {
|
|
1418
1404
|
sessionStorage.removeItem(`${ct}_${s}`);
|
|
1419
|
-
} catch (
|
|
1420
|
-
|
|
1405
|
+
} catch (a) {
|
|
1406
|
+
v(
|
|
1421
1407
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1422
1408
|
s,
|
|
1423
|
-
|
|
1409
|
+
a
|
|
1424
1410
|
);
|
|
1425
1411
|
}
|
|
1426
1412
|
}
|
|
@@ -1435,27 +1421,27 @@ function L(t) {
|
|
|
1435
1421
|
}
|
|
1436
1422
|
};
|
|
1437
1423
|
}
|
|
1438
|
-
function
|
|
1424
|
+
function re(t) {
|
|
1439
1425
|
const e = [];
|
|
1440
1426
|
for (const s of t)
|
|
1441
|
-
for (const
|
|
1442
|
-
if (
|
|
1427
|
+
for (const a of s.parts)
|
|
1428
|
+
if (a.type === "text")
|
|
1443
1429
|
e.push({
|
|
1444
1430
|
type: "data",
|
|
1445
1431
|
data: {
|
|
1446
1432
|
role: s.role,
|
|
1447
|
-
text:
|
|
1433
|
+
text: a.text
|
|
1448
1434
|
}
|
|
1449
1435
|
});
|
|
1450
|
-
else if (
|
|
1451
|
-
if ("role" in
|
|
1436
|
+
else if (a.type === "data") {
|
|
1437
|
+
if ("role" in a.data && "text" in a.data)
|
|
1452
1438
|
continue;
|
|
1453
|
-
if ("toolCallId" in
|
|
1454
|
-
e.push(
|
|
1439
|
+
if ("toolCallId" in a.data && "arguments" in a.data) {
|
|
1440
|
+
e.push(a);
|
|
1455
1441
|
continue;
|
|
1456
1442
|
}
|
|
1457
|
-
if ("toolCallId" in
|
|
1458
|
-
e.push(
|
|
1443
|
+
if ("toolCallId" in a.data && "result" in a.data) {
|
|
1444
|
+
e.push(a);
|
|
1459
1445
|
continue;
|
|
1460
1446
|
}
|
|
1461
1447
|
}
|
|
@@ -1465,92 +1451,92 @@ function mt(t, e = []) {
|
|
|
1465
1451
|
return {
|
|
1466
1452
|
role: "user",
|
|
1467
1453
|
parts: [
|
|
1468
|
-
...
|
|
1454
|
+
...re(e),
|
|
1469
1455
|
{
|
|
1470
1456
|
type: "text",
|
|
1471
1457
|
text: t
|
|
1472
1458
|
}
|
|
1473
1459
|
],
|
|
1474
1460
|
kind: "message",
|
|
1475
|
-
messageId:
|
|
1461
|
+
messageId: N(),
|
|
1476
1462
|
metadata: {
|
|
1477
1463
|
timestamp: Date.now()
|
|
1478
1464
|
}
|
|
1479
1465
|
};
|
|
1480
1466
|
}
|
|
1481
|
-
function
|
|
1467
|
+
function ie(t) {
|
|
1482
1468
|
return t != null && t.parts ? t.parts.filter(
|
|
1483
1469
|
(e) => e.type === "data" && "toolCallId" in e.data && "result" in e.data
|
|
1484
1470
|
) : [];
|
|
1485
1471
|
}
|
|
1486
|
-
async function
|
|
1472
|
+
async function le(t) {
|
|
1487
1473
|
const e = [];
|
|
1488
1474
|
for (const s of t)
|
|
1489
1475
|
if (s.parts && Array.isArray(s.parts))
|
|
1490
1476
|
if (s.parts.some(
|
|
1491
|
-
(
|
|
1477
|
+
(n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
|
|
1492
1478
|
)) {
|
|
1493
|
-
const
|
|
1479
|
+
const n = Yt(
|
|
1494
1480
|
s.parts
|
|
1495
1481
|
);
|
|
1496
1482
|
e.push({
|
|
1497
1483
|
...s,
|
|
1498
|
-
parts:
|
|
1484
|
+
parts: n
|
|
1499
1485
|
});
|
|
1500
1486
|
} else
|
|
1501
1487
|
e.push(s);
|
|
1502
1488
|
else
|
|
1503
1489
|
e.push(s);
|
|
1504
|
-
return
|
|
1490
|
+
return Gt(), e;
|
|
1505
1491
|
}
|
|
1506
|
-
function
|
|
1492
|
+
function ce() {
|
|
1507
1493
|
const t = /* @__PURE__ */ new Map();
|
|
1508
|
-
async function e(s,
|
|
1509
|
-
const
|
|
1510
|
-
if (
|
|
1494
|
+
async function e(s, a) {
|
|
1495
|
+
const n = t.get(s);
|
|
1496
|
+
if (n != null && n.sessionId)
|
|
1511
1497
|
try {
|
|
1512
1498
|
await ae(
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1499
|
+
n.sessionId,
|
|
1500
|
+
a,
|
|
1501
|
+
n.conversationStorageKey
|
|
1516
1502
|
);
|
|
1517
1503
|
} catch (r) {
|
|
1518
|
-
|
|
1504
|
+
ut(
|
|
1519
1505
|
`Failed to persist conversation history for agent ${s}:`,
|
|
1520
1506
|
r
|
|
1521
1507
|
);
|
|
1522
1508
|
}
|
|
1523
1509
|
}
|
|
1524
1510
|
return {
|
|
1525
|
-
async createAgent(s,
|
|
1511
|
+
async createAgent(s, a) {
|
|
1526
1512
|
if (t.has(s))
|
|
1527
1513
|
return t.get(s).client;
|
|
1528
|
-
const
|
|
1529
|
-
let
|
|
1514
|
+
const n = Zt(a), r = a.sessionId || null, o = a.conversationStorageKey;
|
|
1515
|
+
let l = [];
|
|
1530
1516
|
if (r)
|
|
1531
1517
|
try {
|
|
1532
|
-
|
|
1518
|
+
l = await ne(
|
|
1533
1519
|
r,
|
|
1534
1520
|
o
|
|
1535
1521
|
);
|
|
1536
|
-
} catch (
|
|
1537
|
-
|
|
1522
|
+
} catch (m) {
|
|
1523
|
+
ut(
|
|
1538
1524
|
`Failed to load conversation history for agent ${s} with session ${r}:`,
|
|
1539
|
-
|
|
1525
|
+
m
|
|
1540
1526
|
);
|
|
1541
1527
|
}
|
|
1542
1528
|
const i = {
|
|
1543
|
-
client:
|
|
1529
|
+
client: n,
|
|
1544
1530
|
sessionId: r,
|
|
1545
1531
|
conversationStorageKey: o,
|
|
1546
|
-
conversationHistory:
|
|
1532
|
+
conversationHistory: l,
|
|
1547
1533
|
currentAbortController: null
|
|
1548
1534
|
};
|
|
1549
|
-
return t.set(s, i),
|
|
1535
|
+
return t.set(s, i), n;
|
|
1550
1536
|
},
|
|
1551
1537
|
getAgent(s) {
|
|
1552
|
-
const
|
|
1553
|
-
return (
|
|
1538
|
+
const a = t.get(s);
|
|
1539
|
+
return (a == null ? void 0 : a.client) || null;
|
|
1554
1540
|
},
|
|
1555
1541
|
hasAgent(s) {
|
|
1556
1542
|
return t.has(s);
|
|
@@ -1558,257 +1544,257 @@ function ue() {
|
|
|
1558
1544
|
removeAgent(s) {
|
|
1559
1545
|
return t.delete(s);
|
|
1560
1546
|
},
|
|
1561
|
-
async sendMessage(s,
|
|
1562
|
-
var
|
|
1547
|
+
async sendMessage(s, a, n = {}) {
|
|
1548
|
+
var c;
|
|
1563
1549
|
const r = t.get(s);
|
|
1564
1550
|
if (!r)
|
|
1565
1551
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1566
|
-
const { withHistory: o = !0, ...
|
|
1567
|
-
message:
|
|
1552
|
+
const { withHistory: o = !0, ...l } = n, { client: i, conversationHistory: m } = r, g = n.message || mt(a, m), h = await i.sendMessage({
|
|
1553
|
+
message: g,
|
|
1568
1554
|
withHistory: o,
|
|
1569
|
-
...
|
|
1555
|
+
...l
|
|
1570
1556
|
});
|
|
1571
|
-
let
|
|
1572
|
-
if ((
|
|
1573
|
-
const
|
|
1557
|
+
let f = null;
|
|
1558
|
+
if ((c = h.status) != null && c.message) {
|
|
1559
|
+
const u = h.status.message.parts.filter(
|
|
1574
1560
|
(d) => d.type === "data" && "toolCallId" in d.data && ("arguments" in d.data || "result" in d.data)
|
|
1575
|
-
),
|
|
1561
|
+
), w = h.status.message.parts.filter(
|
|
1576
1562
|
(d) => d.type === "text"
|
|
1577
1563
|
);
|
|
1578
|
-
|
|
1564
|
+
f = {
|
|
1579
1565
|
role: "agent",
|
|
1580
1566
|
kind: "message",
|
|
1581
|
-
parts: [...
|
|
1582
|
-
messageId:
|
|
1567
|
+
parts: [...u, ...w],
|
|
1568
|
+
messageId: N(),
|
|
1583
1569
|
metadata: {
|
|
1584
1570
|
timestamp: Date.now()
|
|
1585
1571
|
}
|
|
1586
1572
|
};
|
|
1587
1573
|
}
|
|
1588
|
-
const
|
|
1589
|
-
...
|
|
1574
|
+
const p = [
|
|
1575
|
+
...m,
|
|
1590
1576
|
// Store only the new content from the user message (without history parts)
|
|
1591
|
-
|
|
1577
|
+
nt(a),
|
|
1592
1578
|
// Add complete agent response with tool calls/results if present
|
|
1593
|
-
...
|
|
1579
|
+
...f ? [L(f)] : []
|
|
1594
1580
|
];
|
|
1595
|
-
let
|
|
1596
|
-
if (
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1581
|
+
let S = p;
|
|
1582
|
+
if (h.agentMessage) {
|
|
1583
|
+
const u = L(
|
|
1584
|
+
h.agentMessage
|
|
1599
1585
|
);
|
|
1600
|
-
|
|
1601
|
-
...
|
|
1602
|
-
|
|
1586
|
+
S = [
|
|
1587
|
+
...p,
|
|
1588
|
+
u
|
|
1603
1589
|
];
|
|
1604
1590
|
}
|
|
1605
|
-
return r.conversationHistory =
|
|
1591
|
+
return r.conversationHistory = S, o && await e(
|
|
1606
1592
|
s,
|
|
1607
|
-
|
|
1608
|
-
),
|
|
1593
|
+
S
|
|
1594
|
+
), h;
|
|
1609
1595
|
},
|
|
1610
|
-
async *sendMessageStream(s,
|
|
1611
|
-
var d,
|
|
1596
|
+
async *sendMessageStream(s, a, n = {}) {
|
|
1597
|
+
var d, y, x, I, P, T;
|
|
1612
1598
|
const r = t.get(s);
|
|
1613
1599
|
if (!r)
|
|
1614
1600
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1615
1601
|
const {
|
|
1616
1602
|
withHistory: o = !0,
|
|
1617
|
-
abortSignal:
|
|
1603
|
+
abortSignal: l,
|
|
1618
1604
|
metadata: i,
|
|
1619
|
-
...
|
|
1620
|
-
} =
|
|
1621
|
-
r.currentAbortController =
|
|
1605
|
+
...m
|
|
1606
|
+
} = n, { client: g } = r, h = i ? (({ contentType: b, ...k }) => k)(i) : void 0, f = new AbortController();
|
|
1607
|
+
r.currentAbortController = f, l && l.addEventListener(
|
|
1622
1608
|
"abort",
|
|
1623
|
-
() =>
|
|
1609
|
+
() => f.abort()
|
|
1624
1610
|
);
|
|
1625
|
-
let
|
|
1611
|
+
let p = [
|
|
1626
1612
|
...r.conversationHistory
|
|
1627
|
-
],
|
|
1628
|
-
const
|
|
1629
|
-
|
|
1613
|
+
], S = [];
|
|
1614
|
+
const c = await le(
|
|
1615
|
+
p
|
|
1630
1616
|
);
|
|
1631
|
-
r.conversationHistory =
|
|
1617
|
+
r.conversationHistory = c, p = c, o && await e(
|
|
1632
1618
|
s,
|
|
1633
|
-
|
|
1619
|
+
c
|
|
1634
1620
|
);
|
|
1635
|
-
const
|
|
1636
|
-
|
|
1637
|
-
|
|
1621
|
+
const u = n.message || mt(
|
|
1622
|
+
a,
|
|
1623
|
+
c
|
|
1638
1624
|
);
|
|
1639
|
-
if (
|
|
1640
|
-
const { contentType:
|
|
1641
|
-
if (
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1644
|
-
...
|
|
1645
|
-
contentType:
|
|
1625
|
+
if (n.metadata && !n.message) {
|
|
1626
|
+
const { contentType: b, ...k } = n.metadata;
|
|
1627
|
+
if (b) {
|
|
1628
|
+
const M = u.parts[u.parts.length - 1];
|
|
1629
|
+
M && M.type === "text" && (M.metadata = {
|
|
1630
|
+
...M.metadata,
|
|
1631
|
+
contentType: b
|
|
1646
1632
|
});
|
|
1647
1633
|
}
|
|
1648
|
-
Object.keys(
|
|
1649
|
-
...
|
|
1650
|
-
...
|
|
1634
|
+
Object.keys(k).length > 0 && (u.metadata = {
|
|
1635
|
+
...u.metadata,
|
|
1636
|
+
...k
|
|
1651
1637
|
});
|
|
1652
1638
|
}
|
|
1653
|
-
const
|
|
1654
|
-
|
|
1655
|
-
...
|
|
1656
|
-
|
|
1657
|
-
], r.conversationHistory =
|
|
1639
|
+
const w = nt(a, n.metadata);
|
|
1640
|
+
p = [
|
|
1641
|
+
...p,
|
|
1642
|
+
w
|
|
1643
|
+
], r.conversationHistory = p, o && await e(
|
|
1658
1644
|
s,
|
|
1659
|
-
|
|
1645
|
+
p
|
|
1660
1646
|
);
|
|
1661
|
-
for await (const
|
|
1662
|
-
message:
|
|
1647
|
+
for await (const b of g.sendMessageStream({
|
|
1648
|
+
message: u,
|
|
1663
1649
|
withHistory: o,
|
|
1664
|
-
abortSignal:
|
|
1665
|
-
...
|
|
1666
|
-
...
|
|
1667
|
-
metadata:
|
|
1650
|
+
abortSignal: f.signal,
|
|
1651
|
+
...m,
|
|
1652
|
+
...h && Object.keys(h).length > 0 && {
|
|
1653
|
+
metadata: h
|
|
1668
1654
|
}
|
|
1669
1655
|
})) {
|
|
1670
|
-
if (((d =
|
|
1671
|
-
|
|
1672
|
-
|
|
1656
|
+
if (((d = b.status) == null ? void 0 : d.state) === "input-required" && ((y = b.status) != null && y.message)) {
|
|
1657
|
+
S = F(
|
|
1658
|
+
b.status.message
|
|
1673
1659
|
).map(
|
|
1674
|
-
(
|
|
1660
|
+
(C) => C.data.toolCallId
|
|
1675
1661
|
);
|
|
1676
|
-
const
|
|
1677
|
-
|
|
1662
|
+
const M = L(
|
|
1663
|
+
b.status.message
|
|
1678
1664
|
);
|
|
1679
|
-
|
|
1680
|
-
...
|
|
1681
|
-
|
|
1682
|
-
], r.conversationHistory =
|
|
1665
|
+
p = [
|
|
1666
|
+
...p,
|
|
1667
|
+
M
|
|
1668
|
+
], r.conversationHistory = p, o && await e(
|
|
1683
1669
|
s,
|
|
1684
|
-
|
|
1670
|
+
p
|
|
1685
1671
|
);
|
|
1686
1672
|
}
|
|
1687
|
-
if (((
|
|
1688
|
-
const
|
|
1689
|
-
|
|
1673
|
+
if (((x = b.status) == null ? void 0 : x.state) === "working" && ((I = b.status) != null && I.message) && !b.final) {
|
|
1674
|
+
const M = ie(
|
|
1675
|
+
b.status.message
|
|
1690
1676
|
).filter(
|
|
1691
|
-
(
|
|
1692
|
-
|
|
1677
|
+
(C) => S.includes(
|
|
1678
|
+
C.data.toolCallId
|
|
1693
1679
|
)
|
|
1694
1680
|
);
|
|
1695
|
-
if (
|
|
1696
|
-
const
|
|
1681
|
+
if (M.length > 0) {
|
|
1682
|
+
const C = {
|
|
1697
1683
|
role: "agent",
|
|
1698
1684
|
kind: "message",
|
|
1699
|
-
parts:
|
|
1700
|
-
messageId:
|
|
1685
|
+
parts: M,
|
|
1686
|
+
messageId: N()
|
|
1701
1687
|
};
|
|
1702
|
-
|
|
1703
|
-
...
|
|
1704
|
-
L(
|
|
1705
|
-
], r.conversationHistory =
|
|
1688
|
+
p = [
|
|
1689
|
+
...p,
|
|
1690
|
+
L(C)
|
|
1691
|
+
], r.conversationHistory = p, o && await e(
|
|
1706
1692
|
s,
|
|
1707
|
-
|
|
1693
|
+
p
|
|
1708
1694
|
);
|
|
1709
1695
|
}
|
|
1710
1696
|
}
|
|
1711
|
-
if (
|
|
1712
|
-
|
|
1713
|
-
let
|
|
1714
|
-
(T =
|
|
1715
|
-
|
|
1716
|
-
),
|
|
1717
|
-
...
|
|
1718
|
-
|
|
1719
|
-
], r.conversationHistory =
|
|
1697
|
+
if (b.final && ((P = b.status) == null ? void 0 : P.state) !== "input-required") {
|
|
1698
|
+
S = [];
|
|
1699
|
+
let k = null;
|
|
1700
|
+
(T = b.status) != null && T.message && (k = L(
|
|
1701
|
+
b.status.message
|
|
1702
|
+
), p = [
|
|
1703
|
+
...p,
|
|
1704
|
+
k
|
|
1705
|
+
], r.conversationHistory = p, o && await e(
|
|
1720
1706
|
s,
|
|
1721
|
-
|
|
1707
|
+
p
|
|
1722
1708
|
));
|
|
1723
1709
|
}
|
|
1724
|
-
yield
|
|
1710
|
+
yield b;
|
|
1725
1711
|
}
|
|
1726
1712
|
r.currentAbortController = null;
|
|
1727
1713
|
},
|
|
1728
1714
|
async resetConversation(s) {
|
|
1729
|
-
const
|
|
1730
|
-
if (!
|
|
1715
|
+
const a = t.get(s);
|
|
1716
|
+
if (!a)
|
|
1731
1717
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1718
|
+
a.conversationHistory = [], a.sessionId && await oe(
|
|
1719
|
+
a.sessionId,
|
|
1720
|
+
a.conversationStorageKey
|
|
1735
1721
|
);
|
|
1736
1722
|
},
|
|
1737
1723
|
getConversationHistory(s) {
|
|
1738
|
-
const
|
|
1739
|
-
if (!
|
|
1724
|
+
const a = t.get(s);
|
|
1725
|
+
if (!a)
|
|
1740
1726
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1741
|
-
return [...
|
|
1727
|
+
return [...a.conversationHistory];
|
|
1742
1728
|
},
|
|
1743
1729
|
abortCurrentRequest(s) {
|
|
1744
|
-
const
|
|
1745
|
-
if (!
|
|
1730
|
+
const a = t.get(s);
|
|
1731
|
+
if (!a)
|
|
1746
1732
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1747
|
-
|
|
1733
|
+
a.currentAbortController && (a.currentAbortController.abort(), a.currentAbortController = null);
|
|
1748
1734
|
},
|
|
1749
1735
|
clear() {
|
|
1750
1736
|
t.clear();
|
|
1751
1737
|
}
|
|
1752
1738
|
};
|
|
1753
1739
|
}
|
|
1754
|
-
const
|
|
1740
|
+
const ue = ce();
|
|
1755
1741
|
function st() {
|
|
1756
|
-
return
|
|
1742
|
+
return ue;
|
|
1757
1743
|
}
|
|
1758
|
-
function
|
|
1744
|
+
function de() {
|
|
1759
1745
|
const [t, e] = yt([]), s = $(
|
|
1760
1746
|
(r) => {
|
|
1761
1747
|
e((o) => {
|
|
1762
|
-
const
|
|
1748
|
+
const l = o.findIndex(
|
|
1763
1749
|
(i) => i.id === r.id
|
|
1764
1750
|
);
|
|
1765
|
-
if (
|
|
1751
|
+
if (l >= 0) {
|
|
1766
1752
|
const i = [...o];
|
|
1767
|
-
return i[
|
|
1753
|
+
return i[l] = r, i;
|
|
1768
1754
|
}
|
|
1769
1755
|
return [...o, r];
|
|
1770
1756
|
});
|
|
1771
1757
|
},
|
|
1772
1758
|
[]
|
|
1773
|
-
),
|
|
1774
|
-
e((o) => o.filter((
|
|
1775
|
-
}, []),
|
|
1759
|
+
), a = $((r) => {
|
|
1760
|
+
e((o) => o.filter((l) => l.id !== r));
|
|
1761
|
+
}, []), n = $(() => {
|
|
1776
1762
|
e([]);
|
|
1777
1763
|
}, []);
|
|
1778
1764
|
return {
|
|
1779
1765
|
registerMessageActions: s,
|
|
1780
|
-
unregisterMessageActions:
|
|
1781
|
-
clearAllMessageActions:
|
|
1766
|
+
unregisterMessageActions: a,
|
|
1767
|
+
clearAllMessageActions: n,
|
|
1782
1768
|
registrations: t
|
|
1783
1769
|
};
|
|
1784
1770
|
}
|
|
1785
|
-
function
|
|
1786
|
-
return e.flatMap((
|
|
1787
|
-
id:
|
|
1788
|
-
label:
|
|
1789
|
-
icon:
|
|
1790
|
-
onClick:
|
|
1791
|
-
tooltip:
|
|
1792
|
-
disabled:
|
|
1793
|
-
pressed:
|
|
1794
|
-
showLabel:
|
|
1771
|
+
function ge(t, e) {
|
|
1772
|
+
return e.flatMap((n) => typeof n.actions == "function" ? n.actions(t) : n.actions).filter((n) => !(n.condition && !n.condition(t))).map((n) => ({
|
|
1773
|
+
id: n.id,
|
|
1774
|
+
label: n.label,
|
|
1775
|
+
icon: n.icon,
|
|
1776
|
+
onClick: n.onClick,
|
|
1777
|
+
tooltip: n.tooltip,
|
|
1778
|
+
disabled: n.disabled || !1,
|
|
1779
|
+
pressed: n.pressed,
|
|
1780
|
+
showLabel: n.showLabel
|
|
1795
1781
|
}));
|
|
1796
1782
|
}
|
|
1797
|
-
const
|
|
1798
|
-
var o,
|
|
1783
|
+
const at = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), z = (t, e = []) => {
|
|
1784
|
+
var o, l;
|
|
1799
1785
|
if (t.parts.some((i) => {
|
|
1800
1786
|
if (i.type === "data") {
|
|
1801
|
-
const
|
|
1802
|
-
return
|
|
1787
|
+
const m = i.data;
|
|
1788
|
+
return m.toolCallId || m.toolId || m.result;
|
|
1803
1789
|
}
|
|
1804
1790
|
return !1;
|
|
1805
1791
|
}))
|
|
1806
1792
|
return null;
|
|
1807
|
-
const
|
|
1808
|
-
var
|
|
1793
|
+
const a = t.parts.map((i) => {
|
|
1794
|
+
var m;
|
|
1809
1795
|
if (i.type === "text")
|
|
1810
1796
|
return {
|
|
1811
|
-
type: ((
|
|
1797
|
+
type: ((m = i.metadata) == null ? void 0 : m.contentType) || "text",
|
|
1812
1798
|
text: i.text
|
|
1813
1799
|
};
|
|
1814
1800
|
if (i.type === "file")
|
|
@@ -1817,55 +1803,55 @@ const nt = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), z = (t, e =
|
|
|
1817
1803
|
image_url: i.file.uri || `data:${i.file.mimeType};base64,${i.file.bytes}`
|
|
1818
1804
|
};
|
|
1819
1805
|
if (i.type === "data") {
|
|
1820
|
-
const
|
|
1821
|
-
return
|
|
1806
|
+
const g = i.data;
|
|
1807
|
+
return g.component && g.componentProps ? {
|
|
1822
1808
|
type: "component",
|
|
1823
|
-
component:
|
|
1824
|
-
componentProps:
|
|
1809
|
+
component: g.component,
|
|
1810
|
+
componentProps: g.componentProps
|
|
1825
1811
|
} : {
|
|
1826
1812
|
type: "text",
|
|
1827
|
-
text: JSON.stringify(
|
|
1813
|
+
text: JSON.stringify(g)
|
|
1828
1814
|
};
|
|
1829
1815
|
}
|
|
1830
1816
|
return {
|
|
1831
1817
|
type: "text",
|
|
1832
1818
|
text: "[Unsupported content]"
|
|
1833
1819
|
};
|
|
1834
|
-
}),
|
|
1820
|
+
}), n = ((o = t.metadata) == null ? void 0 : o.timestamp) ?? Date.now(), r = {
|
|
1835
1821
|
id: t.messageId,
|
|
1836
1822
|
role: t.role === "agent" ? "agent" : "user",
|
|
1837
|
-
content:
|
|
1838
|
-
timestamp:
|
|
1839
|
-
archived: !!((
|
|
1823
|
+
content: a,
|
|
1824
|
+
timestamp: n,
|
|
1825
|
+
archived: !!((l = t.metadata) != null && l.archived),
|
|
1840
1826
|
showIcon: t.role === "agent",
|
|
1841
1827
|
icon: t.role === "agent" ? "assistant" : void 0
|
|
1842
1828
|
};
|
|
1843
1829
|
if (t.role === "agent" && e.length > 0) {
|
|
1844
|
-
const i =
|
|
1830
|
+
const i = ge(
|
|
1845
1831
|
r,
|
|
1846
1832
|
e
|
|
1847
1833
|
);
|
|
1848
1834
|
i.length > 0 && (r.actions = i);
|
|
1849
1835
|
}
|
|
1850
1836
|
return r;
|
|
1851
|
-
},
|
|
1837
|
+
}, fe = () => ({
|
|
1852
1838
|
getClientContext: () => ({})
|
|
1853
|
-
}),
|
|
1839
|
+
}), me = () => ({
|
|
1854
1840
|
getAvailableTools: async () => [],
|
|
1855
1841
|
executeTool: async () => ({
|
|
1856
1842
|
success: !0,
|
|
1857
1843
|
result: "No tools available"
|
|
1858
1844
|
})
|
|
1859
1845
|
}), pe = (t) => ["agentId", "agentUrl", "sessionId"].every((s) => {
|
|
1860
|
-
const
|
|
1861
|
-
return typeof
|
|
1846
|
+
const a = t[s];
|
|
1847
|
+
return typeof a == "string" && a.trim().length > 0;
|
|
1862
1848
|
});
|
|
1863
1849
|
function Ee(t) {
|
|
1864
1850
|
const e = {
|
|
1865
1851
|
agentId: t.agentId,
|
|
1866
1852
|
agentUrl: t.agentUrl,
|
|
1867
1853
|
sessionId: t.sessionId
|
|
1868
|
-
}, s = pe(e), [
|
|
1854
|
+
}, s = pe(e), [a, n] = yt({
|
|
1869
1855
|
clientMessages: [],
|
|
1870
1856
|
uiMessages: [],
|
|
1871
1857
|
isProcessing: !1,
|
|
@@ -1874,38 +1860,38 @@ function Ee(t) {
|
|
|
1874
1860
|
}), {
|
|
1875
1861
|
registerMessageActions: r,
|
|
1876
1862
|
unregisterMessageActions: o,
|
|
1877
|
-
clearAllMessageActions:
|
|
1863
|
+
clearAllMessageActions: l,
|
|
1878
1864
|
registrations: i
|
|
1879
|
-
} =
|
|
1865
|
+
} = de(), m = Ot(i);
|
|
1880
1866
|
tt(() => {
|
|
1881
|
-
|
|
1867
|
+
m.current = i;
|
|
1882
1868
|
}, [i]), tt(() => {
|
|
1883
1869
|
if (!s)
|
|
1884
1870
|
return;
|
|
1885
1871
|
(async () => {
|
|
1886
1872
|
if (e.sessionId) {
|
|
1887
|
-
const
|
|
1888
|
-
|
|
1873
|
+
const u = st(), w = `${e.agentId}-${e.sessionId}`;
|
|
1874
|
+
u.hasAgent(w) || await u.createAgent(w, {
|
|
1889
1875
|
agentId: e.agentId,
|
|
1890
1876
|
agentUrl: e.agentUrl,
|
|
1891
1877
|
sessionId: e.sessionId,
|
|
1892
|
-
contextProvider: t.contextProvider ||
|
|
1893
|
-
toolProvider: t.toolProvider ||
|
|
1878
|
+
contextProvider: t.contextProvider || fe(),
|
|
1879
|
+
toolProvider: t.toolProvider || me(),
|
|
1894
1880
|
authProvider: t.authProvider,
|
|
1895
1881
|
enableStreaming: t.enableStreaming
|
|
1896
1882
|
});
|
|
1897
|
-
const d =
|
|
1898
|
-
|
|
1899
|
-
const
|
|
1900
|
-
(
|
|
1901
|
-
|
|
1902
|
-
|
|
1883
|
+
const d = u.getConversationHistory(w);
|
|
1884
|
+
n((y) => {
|
|
1885
|
+
const x = d.map(
|
|
1886
|
+
(I) => z(
|
|
1887
|
+
I,
|
|
1888
|
+
m.current
|
|
1903
1889
|
)
|
|
1904
|
-
).filter((
|
|
1890
|
+
).filter((I) => I !== null);
|
|
1905
1891
|
return {
|
|
1906
|
-
...
|
|
1892
|
+
...y,
|
|
1907
1893
|
clientMessages: d,
|
|
1908
|
-
uiMessages:
|
|
1894
|
+
uiMessages: x
|
|
1909
1895
|
};
|
|
1910
1896
|
});
|
|
1911
1897
|
}
|
|
@@ -1920,277 +1906,277 @@ function Ee(t) {
|
|
|
1920
1906
|
t.enableStreaming,
|
|
1921
1907
|
s
|
|
1922
1908
|
]);
|
|
1923
|
-
const
|
|
1924
|
-
async (
|
|
1909
|
+
const g = $(
|
|
1910
|
+
async (c, u) => {
|
|
1925
1911
|
var P;
|
|
1926
1912
|
if (!s)
|
|
1927
1913
|
throw new Error("Invalid agent configuration");
|
|
1928
|
-
const
|
|
1929
|
-
id: `user-${
|
|
1914
|
+
const w = st(), d = `${e.agentId}-${e.sessionId}`, y = Date.now(), x = (u == null ? void 0 : u.type) || "text", I = {
|
|
1915
|
+
id: `user-${y}`,
|
|
1930
1916
|
role: "user",
|
|
1931
|
-
content: [{ type:
|
|
1932
|
-
timestamp:
|
|
1933
|
-
archived: (
|
|
1917
|
+
content: [{ type: x, text: c }],
|
|
1918
|
+
timestamp: y,
|
|
1919
|
+
archived: (u == null ? void 0 : u.archived) ?? !1,
|
|
1934
1920
|
showIcon: !1
|
|
1935
1921
|
};
|
|
1936
|
-
|
|
1922
|
+
n((T) => ({
|
|
1937
1923
|
...T,
|
|
1938
|
-
uiMessages: [...T.uiMessages,
|
|
1924
|
+
uiMessages: [...T.uiMessages, I],
|
|
1939
1925
|
isProcessing: !0,
|
|
1940
1926
|
error: null
|
|
1941
1927
|
}));
|
|
1942
1928
|
try {
|
|
1943
|
-
let T = null,
|
|
1944
|
-
const
|
|
1945
|
-
(
|
|
1946
|
-
...(
|
|
1947
|
-
...(
|
|
1929
|
+
let T = null, b = !1;
|
|
1930
|
+
const k = {};
|
|
1931
|
+
(u != null && u.archived || u != null && u.type) && (k.metadata = {
|
|
1932
|
+
...(u == null ? void 0 : u.archived) && { archived: !0 },
|
|
1933
|
+
...(u == null ? void 0 : u.type) && { contentType: u.type }
|
|
1948
1934
|
});
|
|
1949
|
-
for await (const
|
|
1935
|
+
for await (const M of w.sendMessageStream(
|
|
1950
1936
|
d,
|
|
1951
|
-
|
|
1952
|
-
|
|
1937
|
+
c,
|
|
1938
|
+
k
|
|
1953
1939
|
)) {
|
|
1954
|
-
if (!
|
|
1940
|
+
if (!M.final && M.text)
|
|
1955
1941
|
if (T)
|
|
1956
|
-
|
|
1957
|
-
...
|
|
1958
|
-
uiMessages:
|
|
1959
|
-
(
|
|
1960
|
-
...
|
|
1942
|
+
n((C) => ({
|
|
1943
|
+
...C,
|
|
1944
|
+
uiMessages: C.uiMessages.map(
|
|
1945
|
+
(A) => A.id === T ? {
|
|
1946
|
+
...A,
|
|
1961
1947
|
content: [
|
|
1962
1948
|
{
|
|
1963
1949
|
type: "text",
|
|
1964
|
-
text:
|
|
1950
|
+
text: M.text
|
|
1965
1951
|
}
|
|
1966
1952
|
]
|
|
1967
|
-
} :
|
|
1953
|
+
} : A
|
|
1968
1954
|
)
|
|
1969
1955
|
}));
|
|
1970
1956
|
else {
|
|
1971
1957
|
T = `agent-streaming-${Date.now()}`;
|
|
1972
|
-
const
|
|
1958
|
+
const C = {
|
|
1973
1959
|
id: T,
|
|
1974
1960
|
role: "agent",
|
|
1975
1961
|
content: [
|
|
1976
|
-
{ type: "text", text:
|
|
1962
|
+
{ type: "text", text: M.text }
|
|
1977
1963
|
],
|
|
1978
1964
|
timestamp: Date.now(),
|
|
1979
1965
|
archived: !1,
|
|
1980
1966
|
showIcon: !0,
|
|
1981
1967
|
icon: "assistant"
|
|
1982
1968
|
};
|
|
1983
|
-
|
|
1984
|
-
...
|
|
1969
|
+
n((A) => ({
|
|
1970
|
+
...A,
|
|
1985
1971
|
uiMessages: [
|
|
1986
|
-
...
|
|
1987
|
-
|
|
1972
|
+
...A.uiMessages,
|
|
1973
|
+
C
|
|
1988
1974
|
]
|
|
1989
1975
|
}));
|
|
1990
1976
|
}
|
|
1991
|
-
if (
|
|
1992
|
-
|
|
1993
|
-
const
|
|
1994
|
-
|
|
1995
|
-
|
|
1977
|
+
if (M.final && ((P = M.status) != null && P.message) && T) {
|
|
1978
|
+
b = !0;
|
|
1979
|
+
const C = T, A = z(
|
|
1980
|
+
M.status.message,
|
|
1981
|
+
m.current
|
|
1996
1982
|
);
|
|
1997
|
-
|
|
1998
|
-
const
|
|
1999
|
-
(
|
|
2000
|
-
), E =
|
|
1983
|
+
A && n((q) => {
|
|
1984
|
+
const _ = q.uiMessages.map(
|
|
1985
|
+
(R) => R.id === C ? A : R
|
|
1986
|
+
), E = w.getConversationHistory(
|
|
2001
1987
|
d
|
|
2002
1988
|
);
|
|
2003
1989
|
return {
|
|
2004
|
-
...
|
|
1990
|
+
...q,
|
|
2005
1991
|
clientMessages: E,
|
|
2006
|
-
uiMessages:
|
|
1992
|
+
uiMessages: _,
|
|
2007
1993
|
isProcessing: !1
|
|
2008
1994
|
};
|
|
2009
1995
|
}), T = null;
|
|
2010
1996
|
}
|
|
2011
1997
|
}
|
|
2012
|
-
if (!
|
|
2013
|
-
const
|
|
2014
|
-
|
|
2015
|
-
let
|
|
2016
|
-
T && (
|
|
1998
|
+
if (!b) {
|
|
1999
|
+
const M = w.getConversationHistory(d);
|
|
2000
|
+
n((C) => {
|
|
2001
|
+
let A = C.uiMessages;
|
|
2002
|
+
T && (A = C.uiMessages.filter(
|
|
2017
2003
|
(O) => O.id !== T
|
|
2018
2004
|
));
|
|
2019
|
-
const
|
|
2005
|
+
const q = M.map(
|
|
2020
2006
|
(O) => z(
|
|
2021
2007
|
O,
|
|
2022
|
-
|
|
2008
|
+
m.current
|
|
2023
2009
|
)
|
|
2024
2010
|
).filter(
|
|
2025
2011
|
(O) => O !== null
|
|
2026
|
-
),
|
|
2027
|
-
|
|
2028
|
-
), E =
|
|
2012
|
+
), _ = new Set(
|
|
2013
|
+
M.map((O) => O.messageId)
|
|
2014
|
+
), E = A.filter(
|
|
2029
2015
|
(O) => {
|
|
2030
2016
|
var J;
|
|
2031
|
-
return !
|
|
2017
|
+
return !_.has(O.id) && ((J = O.content[0]) == null ? void 0 : J.type) === "component";
|
|
2032
2018
|
}
|
|
2033
|
-
),
|
|
2034
|
-
...
|
|
2019
|
+
), R = at([
|
|
2020
|
+
...q,
|
|
2035
2021
|
...E
|
|
2036
2022
|
]);
|
|
2037
2023
|
return {
|
|
2038
|
-
...
|
|
2039
|
-
clientMessages:
|
|
2040
|
-
uiMessages:
|
|
2024
|
+
...C,
|
|
2025
|
+
clientMessages: M,
|
|
2026
|
+
uiMessages: R,
|
|
2041
2027
|
isProcessing: !1
|
|
2042
2028
|
};
|
|
2043
2029
|
});
|
|
2044
2030
|
}
|
|
2045
2031
|
} catch (T) {
|
|
2046
2032
|
if (T instanceof Error && T.name === "AbortError") {
|
|
2047
|
-
|
|
2048
|
-
...
|
|
2033
|
+
v("Request was aborted by user"), n((k) => ({
|
|
2034
|
+
...k,
|
|
2049
2035
|
isProcessing: !1,
|
|
2050
2036
|
error: null
|
|
2051
2037
|
// Don't show error for user-initiated abort
|
|
2052
2038
|
}));
|
|
2053
2039
|
return;
|
|
2054
2040
|
}
|
|
2055
|
-
const
|
|
2056
|
-
throw
|
|
2057
|
-
...
|
|
2041
|
+
const b = T instanceof Error ? T.message : "Failed to send message";
|
|
2042
|
+
throw n((k) => ({
|
|
2043
|
+
...k,
|
|
2058
2044
|
isProcessing: !1,
|
|
2059
|
-
error:
|
|
2045
|
+
error: b
|
|
2060
2046
|
})), T;
|
|
2061
2047
|
}
|
|
2062
2048
|
},
|
|
2063
2049
|
[e.agentId, e.sessionId, s]
|
|
2064
|
-
),
|
|
2065
|
-
|
|
2066
|
-
...
|
|
2067
|
-
uiMessages:
|
|
2050
|
+
), h = $((c) => {
|
|
2051
|
+
n((u) => ({
|
|
2052
|
+
...u,
|
|
2053
|
+
uiMessages: at([...u.uiMessages, c])
|
|
2068
2054
|
}));
|
|
2069
|
-
}, []),
|
|
2070
|
-
|
|
2071
|
-
...
|
|
2072
|
-
suggestions:
|
|
2055
|
+
}, []), f = $((c) => {
|
|
2056
|
+
n((u) => ({
|
|
2057
|
+
...u,
|
|
2058
|
+
suggestions: c
|
|
2073
2059
|
}));
|
|
2074
|
-
}, []),
|
|
2075
|
-
|
|
2076
|
-
...
|
|
2060
|
+
}, []), p = $(() => {
|
|
2061
|
+
n((c) => ({
|
|
2062
|
+
...c,
|
|
2077
2063
|
suggestions: []
|
|
2078
2064
|
}));
|
|
2079
2065
|
}, []);
|
|
2080
2066
|
tt(() => {
|
|
2081
|
-
|
|
2082
|
-
if (
|
|
2083
|
-
return
|
|
2084
|
-
const
|
|
2085
|
-
(
|
|
2086
|
-
).filter((
|
|
2087
|
-
|
|
2088
|
-
), d =
|
|
2089
|
-
(
|
|
2090
|
-
var
|
|
2091
|
-
return !
|
|
2067
|
+
n((c) => {
|
|
2068
|
+
if (c.clientMessages.length === 0)
|
|
2069
|
+
return c;
|
|
2070
|
+
const u = c.clientMessages.map(
|
|
2071
|
+
(y) => z(y, m.current)
|
|
2072
|
+
).filter((y) => y !== null), w = new Set(
|
|
2073
|
+
c.clientMessages.map((y) => y.messageId)
|
|
2074
|
+
), d = c.uiMessages.filter(
|
|
2075
|
+
(y) => {
|
|
2076
|
+
var x;
|
|
2077
|
+
return !w.has(y.id) && ((x = y.content[0]) == null ? void 0 : x.type) === "component";
|
|
2092
2078
|
}
|
|
2093
2079
|
);
|
|
2094
2080
|
return {
|
|
2095
|
-
...
|
|
2096
|
-
uiMessages:
|
|
2097
|
-
...
|
|
2081
|
+
...c,
|
|
2082
|
+
uiMessages: at([
|
|
2083
|
+
...u,
|
|
2098
2084
|
...d
|
|
2099
2085
|
])
|
|
2100
2086
|
};
|
|
2101
2087
|
});
|
|
2102
2088
|
}, [i]);
|
|
2103
|
-
const
|
|
2089
|
+
const S = $(() => {
|
|
2104
2090
|
if (!s)
|
|
2105
2091
|
return;
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2092
|
+
const c = st(), u = `${e.agentId}-${e.sessionId}`;
|
|
2093
|
+
c.abortCurrentRequest(u);
|
|
2108
2094
|
}, [e.agentId, e.sessionId, s]);
|
|
2109
2095
|
return {
|
|
2110
2096
|
// AgentUI props
|
|
2111
|
-
messages:
|
|
2112
|
-
isProcessing:
|
|
2113
|
-
error:
|
|
2114
|
-
onSubmit:
|
|
2115
|
-
suggestions:
|
|
2097
|
+
messages: a.uiMessages,
|
|
2098
|
+
isProcessing: a.isProcessing,
|
|
2099
|
+
error: a.error,
|
|
2100
|
+
onSubmit: g,
|
|
2101
|
+
suggestions: a.suggestions,
|
|
2116
2102
|
// UI management methods
|
|
2117
|
-
registerSuggestions:
|
|
2118
|
-
clearSuggestions:
|
|
2103
|
+
registerSuggestions: f,
|
|
2104
|
+
clearSuggestions: p,
|
|
2119
2105
|
// Message actions methods
|
|
2120
2106
|
registerMessageActions: r,
|
|
2121
2107
|
unregisterMessageActions: o,
|
|
2122
|
-
clearAllMessageActions:
|
|
2108
|
+
clearAllMessageActions: l,
|
|
2123
2109
|
// Tool integration
|
|
2124
|
-
addMessage:
|
|
2110
|
+
addMessage: h,
|
|
2125
2111
|
// Abort control
|
|
2126
|
-
abortCurrentRequest:
|
|
2112
|
+
abortCurrentRequest: S
|
|
2127
2113
|
};
|
|
2128
2114
|
}
|
|
2129
|
-
var
|
|
2130
|
-
const
|
|
2131
|
-
function
|
|
2132
|
-
var s;
|
|
2133
|
-
return window.JP_CONNECTION_INITIAL_STATE ? !1 : !!((
|
|
2115
|
+
var he = /* @__PURE__ */ ((t) => (t[t.PARSE_ERROR = -32700] = "PARSE_ERROR", t[t.INVALID_REQUEST = -32600] = "INVALID_REQUEST", t[t.METHOD_NOT_FOUND = -32601] = "METHOD_NOT_FOUND", t[t.INVALID_PARAMS = -32602] = "INVALID_PARAMS", t[t.INTERNAL_ERROR = -32603] = "INTERNAL_ERROR", t[t.SERVER_ERROR = -32e3] = "SERVER_ERROR", t))(he || {});
|
|
2116
|
+
const pt = "jetpack-ai-jwt-token", ye = 30 * 60 * 1e3;
|
|
2117
|
+
function we() {
|
|
2118
|
+
var s, a, n;
|
|
2119
|
+
return ((a = (s = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : s.connectionStatus) == null ? void 0 : a.isRegistered) ? !1 : !!((n = window.Jetpack_Editor_Initial_State) != null && n.wpcomBlogId);
|
|
2134
2120
|
}
|
|
2135
|
-
async function
|
|
2136
|
-
var i,
|
|
2137
|
-
const s = localStorage.getItem(
|
|
2138
|
-
let
|
|
2121
|
+
async function Ie(t, e = !0) {
|
|
2122
|
+
var i, m;
|
|
2123
|
+
const s = localStorage.getItem(pt);
|
|
2124
|
+
let a;
|
|
2139
2125
|
if (s)
|
|
2140
2126
|
try {
|
|
2141
|
-
|
|
2142
|
-
} catch (
|
|
2143
|
-
|
|
2127
|
+
a = JSON.parse(s);
|
|
2128
|
+
} catch (g) {
|
|
2129
|
+
v("Invalid cached Jetpack token: %O", g);
|
|
2144
2130
|
}
|
|
2145
|
-
if (
|
|
2146
|
-
return
|
|
2147
|
-
const
|
|
2131
|
+
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && e)
|
|
2132
|
+
return a;
|
|
2133
|
+
const n = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (m = window.Jetpack_Editor_Initial_State) == null ? void 0 : m.wpcomBlogId;
|
|
2148
2134
|
let o = {
|
|
2149
2135
|
token: "",
|
|
2150
2136
|
blog_id: ""
|
|
2151
2137
|
};
|
|
2152
2138
|
try {
|
|
2153
|
-
|
|
2139
|
+
we() ? o = await dt({
|
|
2154
2140
|
path: "/wpcom/v2/sites/" + r + "/jetpack-openai-query/jwt",
|
|
2155
2141
|
method: "POST"
|
|
2156
|
-
}) : o = await
|
|
2142
|
+
}) : o = await dt({
|
|
2157
2143
|
path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
|
|
2158
2144
|
credentials: "same-origin",
|
|
2159
2145
|
headers: {
|
|
2160
|
-
"X-WP-Nonce":
|
|
2146
|
+
"X-WP-Nonce": n || ""
|
|
2161
2147
|
},
|
|
2162
2148
|
method: "POST"
|
|
2163
2149
|
});
|
|
2164
|
-
} catch (
|
|
2165
|
-
throw
|
|
2150
|
+
} catch (g) {
|
|
2151
|
+
throw v("Failed to fetch Jetpack token: %O", g), new Error(t(g));
|
|
2166
2152
|
}
|
|
2167
2153
|
if (!(o != null && o.token))
|
|
2168
2154
|
throw new Error(
|
|
2169
2155
|
"Authentication failed. Please ensure Jetpack is properly connected and try again."
|
|
2170
2156
|
);
|
|
2171
|
-
const
|
|
2157
|
+
const l = {
|
|
2172
2158
|
token: o.token,
|
|
2173
2159
|
blogId: o.blog_id || "",
|
|
2174
|
-
expire: Date.now() +
|
|
2160
|
+
expire: Date.now() + ye
|
|
2175
2161
|
};
|
|
2176
2162
|
try {
|
|
2177
|
-
localStorage.setItem(
|
|
2178
|
-
} catch (
|
|
2179
|
-
|
|
2163
|
+
localStorage.setItem(pt, JSON.stringify(l));
|
|
2164
|
+
} catch (g) {
|
|
2165
|
+
v("Error storing token in localStorage: %O", g);
|
|
2180
2166
|
}
|
|
2181
|
-
return
|
|
2167
|
+
return l;
|
|
2182
2168
|
}
|
|
2183
2169
|
const Oe = (t) => async () => {
|
|
2184
2170
|
const e = {};
|
|
2185
2171
|
try {
|
|
2186
|
-
const s = await
|
|
2172
|
+
const s = await Ie(t);
|
|
2187
2173
|
s != null && s.token && (e.Authorization = `${s.token}`);
|
|
2188
2174
|
} catch (s) {
|
|
2189
|
-
throw
|
|
2175
|
+
throw v("Failed to get Jetpack token for auth: %O", s), s;
|
|
2190
2176
|
}
|
|
2191
2177
|
return e;
|
|
2192
2178
|
};
|
|
2193
|
-
function
|
|
2179
|
+
function Te(t) {
|
|
2194
2180
|
const e = {
|
|
2195
2181
|
type: "object",
|
|
2196
2182
|
properties: {}
|
|
@@ -2206,21 +2192,21 @@ function Ce(t) {
|
|
|
2206
2192
|
};
|
|
2207
2193
|
}
|
|
2208
2194
|
function _e(t) {
|
|
2209
|
-
return t.map(
|
|
2195
|
+
return t.map(Te);
|
|
2210
2196
|
}
|
|
2211
2197
|
function Pe(t) {
|
|
2212
2198
|
return (t == null ? void 0 : t._source) === "wordpress-ability";
|
|
2213
2199
|
}
|
|
2214
2200
|
export {
|
|
2215
|
-
|
|
2201
|
+
he as A2AErrorCodes,
|
|
2216
2202
|
_e as convertAbilitiesToTools,
|
|
2217
|
-
|
|
2203
|
+
Te as convertAbilityToTool,
|
|
2218
2204
|
Re as createAbortController,
|
|
2219
|
-
|
|
2205
|
+
Zt as createClient,
|
|
2220
2206
|
Oe as createJetpackAuthProvider,
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2207
|
+
_t as createRequestId,
|
|
2208
|
+
Pt as createTaskId,
|
|
2209
|
+
nt as createTextMessage,
|
|
2224
2210
|
D as extractTextFromMessage,
|
|
2225
2211
|
F as extractToolCallsFromMessage,
|
|
2226
2212
|
st as getAgentManager,
|
|
@@ -2230,5 +2216,5 @@ export {
|
|
|
2230
2216
|
Ae as useClientContext,
|
|
2231
2217
|
Se as useClientTools,
|
|
2232
2218
|
ke as useClientToolsWithAbilities,
|
|
2233
|
-
|
|
2219
|
+
de as useMessageActions
|
|
2234
2220
|
};
|