@automattic/agenttic-client 0.1.22 → 0.1.24
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 +869 -879
- 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.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
|
+
), u = i === -1 ? a.substring(o) : a.substring(o, i);
|
|
292
|
+
if (u.startsWith("data:"))
|
|
293
|
+
n !== "" && (n += `
|
|
294
|
+
`), n += u.substring(
|
|
295
|
+
u.startsWith("data: ") ? 6 : 5
|
|
308
296
|
);
|
|
309
|
-
else if (
|
|
297
|
+
else if (u.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 u, 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: m, value: p } = await a.read();
|
|
319
|
+
if (m)
|
|
332
320
|
break;
|
|
333
|
-
const
|
|
334
|
-
if (
|
|
335
|
-
for (let
|
|
336
|
-
const
|
|
337
|
-
if (
|
|
338
|
-
requestAnimationFrame(() =>
|
|
339
|
-
}),
|
|
321
|
+
const S = n.decode(p, { stream: !0 }), { events: c, nextBuffer: d } = jt(S, r);
|
|
322
|
+
if (c && Array.isArray(c))
|
|
323
|
+
for (let w = 0; w < c.length; w++) {
|
|
324
|
+
const f = c[w];
|
|
325
|
+
if (w > 0 && f.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((y) => {
|
|
326
|
+
requestAnimationFrame(() => y(void 0));
|
|
327
|
+
}), f.error)
|
|
340
328
|
throw new Error(
|
|
341
|
-
`Streaming error: ${
|
|
329
|
+
`Streaming error: ${f.error.message}`
|
|
342
330
|
);
|
|
343
|
-
if (s &&
|
|
344
|
-
const
|
|
331
|
+
if (s && f.method === "message/delta" && ((u = f.params) != null && u.delta)) {
|
|
332
|
+
const y = f.params.delta;
|
|
345
333
|
try {
|
|
346
|
-
if (
|
|
347
|
-
|
|
348
|
-
), !
|
|
349
|
-
const
|
|
334
|
+
if (y.deltaType === "content" && (o.processContentDelta(
|
|
335
|
+
y.content
|
|
336
|
+
), !l && f.params.id && (l = f.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
|
|
364
|
-
id:
|
|
365
|
-
status:
|
|
366
|
-
final:
|
|
351
|
+
} else f.result && f.result.status ? (l = f.result.id, i = f.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset(), yield {
|
|
352
|
+
id: f.result.id,
|
|
353
|
+
status: f.result.status,
|
|
354
|
+
final: f.result.status.state === "completed" || f.result.status.state === "failed" || f.result.status.state === "canceled",
|
|
367
355
|
text: D(
|
|
368
|
-
((
|
|
356
|
+
((g = f.result.status) == null ? void 0 : g.message) || {
|
|
369
357
|
role: "agent",
|
|
370
358
|
parts: []
|
|
371
359
|
}
|
|
372
360
|
)
|
|
373
|
-
}) :
|
|
374
|
-
id:
|
|
375
|
-
status:
|
|
376
|
-
final:
|
|
361
|
+
}) : f.id && f.result && (l = f.result.id, f.result.status && (yield {
|
|
362
|
+
id: f.result.id,
|
|
363
|
+
status: f.result.status,
|
|
364
|
+
final: f.result.status.state === "completed" || f.result.status.state === "failed" || f.result.status.state === "canceled",
|
|
377
365
|
text: D(
|
|
378
|
-
((
|
|
366
|
+
((h = f.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 = d;
|
|
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,98 @@ 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: u } = t, { agentId: g, agentUrl: h, authProvider: m, proxy: p } = e, { isStreaming: S = !1, enableTokenStreaming: c = !1 } = s, d = l || r, w = Vt(h, g), f = await Ut(
|
|
542
530
|
o,
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
),
|
|
531
|
+
a,
|
|
532
|
+
n
|
|
533
|
+
), y = Nt(
|
|
546
534
|
{
|
|
547
535
|
id: i,
|
|
548
|
-
sessionId:
|
|
549
|
-
message:
|
|
550
|
-
metadata:
|
|
536
|
+
sessionId: d,
|
|
537
|
+
message: f,
|
|
538
|
+
metadata: u
|
|
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:
|
|
559
|
-
enhancedMessage:
|
|
560
|
-
effectiveSessionId:
|
|
561
|
-
fullAgentUrl:
|
|
543
|
+
), x = await zt(m, S);
|
|
544
|
+
return Bt("POST", w, x, y), {
|
|
545
|
+
request: y,
|
|
546
|
+
headers: x,
|
|
547
|
+
enhancedMessage: f,
|
|
548
|
+
effectiveSessionId: d,
|
|
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: u } = xt(
|
|
566
554
|
o,
|
|
567
555
|
"request"
|
|
568
|
-
),
|
|
556
|
+
), g = l ? bt(u.signal, l) : u.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 m = await fetch(r, h);
|
|
568
|
+
clearTimeout(i), Ct(m, "request");
|
|
569
|
+
const p = await m.json();
|
|
570
|
+
return v(
|
|
583
571
|
"Response from %s: %d %O",
|
|
584
572
|
r,
|
|
585
|
-
|
|
586
|
-
wt(
|
|
587
|
-
),
|
|
588
|
-
} catch (
|
|
589
|
-
Tt(
|
|
573
|
+
m.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: u, 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 m = JSON.stringify(a), p = Mt(n, m, h), S = await fetch(r, p);
|
|
591
|
+
if (clearTimeout(u), 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 (m) {
|
|
600
|
+
Tt(m, u, "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
|
+
const i = {
|
|
614
|
+
...s,
|
|
615
|
+
...a && { messageId: a }
|
|
616
|
+
}, u = await o.callback(i), g = (u == null ? void 0 : u.returnToAgent) !== void 0 ? u.returnToAgent : !0;
|
|
617
|
+
return { result: u, returnToAgent: g };
|
|
626
618
|
} catch (i) {
|
|
627
|
-
return
|
|
619
|
+
return v(
|
|
628
620
|
"Error executing ability %s: %O",
|
|
629
621
|
o.name,
|
|
630
622
|
i
|
|
@@ -643,7 +635,7 @@ async function X(t, e, s, n, a) {
|
|
|
643
635
|
s
|
|
644
636
|
), returnToAgent: !0 };
|
|
645
637
|
} catch (i) {
|
|
646
|
-
return
|
|
638
|
+
return v(
|
|
647
639
|
"Error executing ability %s: %O",
|
|
648
640
|
o.name,
|
|
649
641
|
i
|
|
@@ -665,8 +657,8 @@ async function X(t, e, s, n, a) {
|
|
|
665
657
|
return await t.executeTool(
|
|
666
658
|
e,
|
|
667
659
|
s,
|
|
668
|
-
|
|
669
|
-
|
|
660
|
+
a,
|
|
661
|
+
n
|
|
670
662
|
);
|
|
671
663
|
throw new Error(
|
|
672
664
|
`No handler found for tool: ${e}. Tool provider must implement executeTool for non-ability tools.`
|
|
@@ -680,10 +672,10 @@ async function Xt(t, e) {
|
|
|
680
672
|
if (s.length === 0)
|
|
681
673
|
return !1;
|
|
682
674
|
try {
|
|
683
|
-
const
|
|
684
|
-
for (const
|
|
685
|
-
if (
|
|
686
|
-
(o) => o.id ===
|
|
675
|
+
const a = await t.getAvailableTools();
|
|
676
|
+
for (const n of s)
|
|
677
|
+
if (a.some(
|
|
678
|
+
(o) => o.id === n.data.toolId
|
|
687
679
|
))
|
|
688
680
|
return !0;
|
|
689
681
|
} catch {
|
|
@@ -691,76 +683,76 @@ async function Xt(t, e) {
|
|
|
691
683
|
}
|
|
692
684
|
return !1;
|
|
693
685
|
}
|
|
694
|
-
function
|
|
686
|
+
function Gt() {
|
|
695
687
|
lt.clear();
|
|
696
688
|
}
|
|
697
|
-
function
|
|
689
|
+
function Yt(t) {
|
|
698
690
|
return t.map((e) => {
|
|
699
|
-
const s = e.data.toolCallId,
|
|
700
|
-
if (
|
|
701
|
-
const
|
|
702
|
-
return
|
|
691
|
+
const s = e.data.toolCallId, a = lt.get(s);
|
|
692
|
+
if (a && a.resolvedValue !== null) {
|
|
693
|
+
const n = a.resolvedValue;
|
|
694
|
+
return n.error ? j(
|
|
703
695
|
s,
|
|
704
696
|
e.data.toolId,
|
|
705
697
|
void 0,
|
|
706
|
-
|
|
698
|
+
n.error
|
|
707
699
|
) : j(
|
|
708
700
|
s,
|
|
709
701
|
e.data.toolId,
|
|
710
|
-
|
|
702
|
+
n
|
|
711
703
|
);
|
|
712
704
|
}
|
|
713
705
|
return e;
|
|
714
706
|
});
|
|
715
707
|
}
|
|
716
708
|
async function vt(t, e, s) {
|
|
717
|
-
const
|
|
709
|
+
const a = [], n = [];
|
|
718
710
|
let r = !1;
|
|
719
711
|
for (const o of t) {
|
|
720
|
-
const { toolCallId:
|
|
712
|
+
const { toolCallId: l, toolId: i, arguments: u } = o.data;
|
|
721
713
|
try {
|
|
722
|
-
const
|
|
714
|
+
const g = await G(
|
|
723
715
|
e,
|
|
724
716
|
i,
|
|
725
|
-
|
|
717
|
+
u,
|
|
726
718
|
s,
|
|
727
|
-
|
|
728
|
-
), { result:
|
|
729
|
-
|
|
719
|
+
l
|
|
720
|
+
), { result: h, returnToAgent: m, agentMessage: p } = it(g);
|
|
721
|
+
m && (r = !0), p && n.push(W(p)), a.push(
|
|
730
722
|
j(
|
|
731
|
-
|
|
723
|
+
l,
|
|
732
724
|
i,
|
|
733
|
-
|
|
725
|
+
h
|
|
734
726
|
)
|
|
735
727
|
);
|
|
736
|
-
} catch (
|
|
737
|
-
r = !0,
|
|
728
|
+
} catch (g) {
|
|
729
|
+
r = !0, a.push(
|
|
738
730
|
j(
|
|
739
|
-
|
|
731
|
+
l,
|
|
740
732
|
i,
|
|
741
733
|
void 0,
|
|
742
|
-
|
|
734
|
+
g instanceof Error ? g.message : String(g)
|
|
743
735
|
)
|
|
744
736
|
);
|
|
745
737
|
}
|
|
746
738
|
}
|
|
747
|
-
return { results:
|
|
739
|
+
return { results: a, shouldReturnToAgent: r, agentMessages: n };
|
|
748
740
|
}
|
|
749
741
|
function gt(t) {
|
|
750
742
|
const e = [];
|
|
751
743
|
for (const s of t)
|
|
752
|
-
for (const
|
|
753
|
-
|
|
744
|
+
for (const a of s.parts)
|
|
745
|
+
a.type === "text" ? e.push({
|
|
754
746
|
type: "data",
|
|
755
747
|
data: {
|
|
756
748
|
role: s.role,
|
|
757
|
-
text:
|
|
749
|
+
text: a.text
|
|
758
750
|
}
|
|
759
|
-
}) :
|
|
751
|
+
}) : a.type === "data" && e.push(a);
|
|
760
752
|
return e;
|
|
761
753
|
}
|
|
762
|
-
async function et(t, e, s,
|
|
763
|
-
const i = await
|
|
754
|
+
async function et(t, e, s, a, n, r, o) {
|
|
755
|
+
const i = await X(
|
|
764
756
|
{
|
|
765
757
|
message: e,
|
|
766
758
|
taskId: t,
|
|
@@ -769,37 +761,37 @@ async function et(t, e, s, n, a, r, o) {
|
|
|
769
761
|
},
|
|
770
762
|
s,
|
|
771
763
|
{ isStreaming: !1 },
|
|
772
|
-
n,
|
|
773
764
|
a,
|
|
765
|
+
n,
|
|
774
766
|
r
|
|
775
767
|
);
|
|
776
768
|
return await At(i, s, {
|
|
777
769
|
abortSignal: o
|
|
778
770
|
});
|
|
779
771
|
}
|
|
780
|
-
async function ft(t, e, s,
|
|
781
|
-
const
|
|
772
|
+
async function ft(t, e, s, a, n, r, o, l, i = []) {
|
|
773
|
+
const u = {
|
|
782
774
|
message: e,
|
|
783
775
|
taskId: t,
|
|
784
776
|
sessionId: void 0
|
|
785
777
|
// Use task's session
|
|
786
|
-
},
|
|
787
|
-
|
|
778
|
+
}, g = l || { isStreaming: !0 }, h = await X(
|
|
779
|
+
u,
|
|
788
780
|
s,
|
|
789
781
|
{
|
|
790
|
-
...
|
|
782
|
+
...g
|
|
791
783
|
},
|
|
792
|
-
n,
|
|
793
784
|
a,
|
|
785
|
+
n,
|
|
794
786
|
r
|
|
795
|
-
),
|
|
796
|
-
...
|
|
787
|
+
), m = St(h, s, {
|
|
788
|
+
...g,
|
|
797
789
|
abortSignal: o
|
|
798
790
|
});
|
|
799
791
|
return kt(
|
|
800
|
-
|
|
801
|
-
n,
|
|
792
|
+
m,
|
|
802
793
|
a,
|
|
794
|
+
n,
|
|
803
795
|
s,
|
|
804
796
|
r,
|
|
805
797
|
!0,
|
|
@@ -807,163 +799,161 @@ async function ft(t, e, s, n, a, r, o, c, i = []) {
|
|
|
807
799
|
i,
|
|
808
800
|
// preserve conversation parts across continuation
|
|
809
801
|
o,
|
|
810
|
-
|
|
802
|
+
g
|
|
811
803
|
// Pass through the same request options
|
|
812
804
|
);
|
|
813
805
|
}
|
|
814
|
-
async function* kt(t, e, s,
|
|
815
|
-
var
|
|
816
|
-
for await (const
|
|
817
|
-
if (yield
|
|
806
|
+
async function* kt(t, e, s, a, n, r = !0, o = [], l, i) {
|
|
807
|
+
var u, g, h, m, p, S, c, d, w, f, y, x;
|
|
808
|
+
for await (const I of t) {
|
|
809
|
+
if (yield I, I.status.state === "running" && I.status.message && e && await Xt(
|
|
818
810
|
e,
|
|
819
|
-
|
|
811
|
+
I.status.message
|
|
820
812
|
)) {
|
|
821
813
|
const P = F(
|
|
822
|
-
|
|
814
|
+
I.status.message
|
|
823
815
|
);
|
|
824
816
|
for (const T of P) {
|
|
825
|
-
const { toolCallId:
|
|
826
|
-
|
|
817
|
+
const { toolCallId: b, toolId: k, arguments: M } = T.data;
|
|
818
|
+
G(
|
|
827
819
|
e,
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
(
|
|
831
|
-
|
|
832
|
-
).catch((
|
|
833
|
-
|
|
834
|
-
`Tool execution failed for ${v}:`,
|
|
835
|
-
S
|
|
836
|
-
);
|
|
820
|
+
k,
|
|
821
|
+
M,
|
|
822
|
+
(g = (u = I.status) == null ? void 0 : u.message) == null ? void 0 : g.messageId,
|
|
823
|
+
b
|
|
824
|
+
).catch((C) => {
|
|
825
|
+
v("Tool execution failed for %s: %O", k, C);
|
|
837
826
|
});
|
|
838
827
|
}
|
|
839
828
|
yield {
|
|
840
|
-
id:
|
|
829
|
+
id: I.id,
|
|
841
830
|
status: {
|
|
842
831
|
state: "running",
|
|
843
832
|
message: {
|
|
844
833
|
role: "agent",
|
|
845
834
|
kind: "message",
|
|
846
835
|
parts: P,
|
|
847
|
-
messageId:
|
|
836
|
+
messageId: N()
|
|
848
837
|
}
|
|
849
838
|
},
|
|
850
839
|
final: !1,
|
|
851
840
|
text: ""
|
|
852
841
|
};
|
|
853
842
|
}
|
|
854
|
-
if (
|
|
843
|
+
if (I.status.state === "input-required" && I.status.message && e) {
|
|
855
844
|
const P = F(
|
|
856
|
-
|
|
845
|
+
I.status.message
|
|
857
846
|
);
|
|
858
847
|
if (P.length > 0) {
|
|
859
848
|
const T = [];
|
|
860
|
-
let
|
|
861
|
-
const
|
|
862
|
-
for (const
|
|
849
|
+
let b = !1;
|
|
850
|
+
const k = [], M = [];
|
|
851
|
+
for (const C of P) {
|
|
863
852
|
const {
|
|
864
|
-
toolCallId:
|
|
865
|
-
toolId:
|
|
866
|
-
arguments:
|
|
867
|
-
} =
|
|
853
|
+
toolCallId: A,
|
|
854
|
+
toolId: q,
|
|
855
|
+
arguments: _
|
|
856
|
+
} = C.data;
|
|
868
857
|
try {
|
|
869
|
-
const E = await
|
|
858
|
+
const E = await G(
|
|
870
859
|
e,
|
|
860
|
+
q,
|
|
871
861
|
_,
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
if (O && (x = !0), J && C.push(
|
|
862
|
+
(m = (h = I.status) == null ? void 0 : h.message) == null ? void 0 : m.messageId,
|
|
863
|
+
A
|
|
864
|
+
), { result: R, returnToAgent: O, agentMessage: J } = it(E);
|
|
865
|
+
if (O && (b = !0), J && M.push(
|
|
877
866
|
W(J)
|
|
878
|
-
),
|
|
879
|
-
const
|
|
880
|
-
promise:
|
|
867
|
+
), R.result instanceof Promise) {
|
|
868
|
+
const B = R.result, K = {
|
|
869
|
+
promise: B,
|
|
881
870
|
resolvedValue: null
|
|
882
871
|
};
|
|
883
872
|
lt.set(
|
|
884
|
-
|
|
873
|
+
A,
|
|
885
874
|
K
|
|
886
|
-
),
|
|
875
|
+
), B.then((H) => {
|
|
887
876
|
K.resolvedValue = H;
|
|
888
877
|
}).catch((H) => {
|
|
889
|
-
|
|
890
|
-
|
|
878
|
+
v(
|
|
879
|
+
"Promise rejected for tool call %s: %O",
|
|
880
|
+
A,
|
|
891
881
|
H
|
|
892
882
|
), K.resolvedValue = {
|
|
893
883
|
error: H instanceof Error ? H.message : String(H)
|
|
894
884
|
};
|
|
895
885
|
});
|
|
896
886
|
}
|
|
897
|
-
const
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
887
|
+
const V = j(
|
|
888
|
+
A,
|
|
889
|
+
q,
|
|
890
|
+
R
|
|
901
891
|
);
|
|
902
|
-
T.push(
|
|
892
|
+
T.push(V), k.push(V);
|
|
903
893
|
} catch (E) {
|
|
904
|
-
const
|
|
905
|
-
|
|
906
|
-
|
|
894
|
+
const R = j(
|
|
895
|
+
A,
|
|
896
|
+
q,
|
|
907
897
|
void 0,
|
|
908
898
|
E instanceof Error ? E.message : String(E)
|
|
909
899
|
);
|
|
910
|
-
T.push(
|
|
900
|
+
T.push(R), k.push(R);
|
|
911
901
|
}
|
|
912
902
|
}
|
|
913
|
-
if (o.push(
|
|
903
|
+
if (o.push(I.status.message), T.length > 0 && o.push({
|
|
914
904
|
role: "agent",
|
|
915
905
|
kind: "message",
|
|
916
906
|
parts: T,
|
|
917
|
-
messageId:
|
|
918
|
-
}),
|
|
919
|
-
const
|
|
907
|
+
messageId: N()
|
|
908
|
+
}), b) {
|
|
909
|
+
const C = gt(o), A = Q(
|
|
920
910
|
[],
|
|
921
911
|
// Empty array - tool results are already in historyDataParts
|
|
922
|
-
|
|
912
|
+
C
|
|
923
913
|
);
|
|
924
914
|
yield {
|
|
925
|
-
id:
|
|
915
|
+
id: I.id,
|
|
926
916
|
status: {
|
|
927
917
|
state: "working",
|
|
928
|
-
message:
|
|
918
|
+
message: A
|
|
929
919
|
},
|
|
930
920
|
final: !1,
|
|
931
921
|
text: ""
|
|
932
922
|
};
|
|
933
|
-
const
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
923
|
+
const q = await ft(
|
|
924
|
+
I.id,
|
|
925
|
+
A,
|
|
926
|
+
a,
|
|
937
927
|
e,
|
|
938
928
|
s,
|
|
939
|
-
|
|
940
|
-
|
|
929
|
+
n,
|
|
930
|
+
l,
|
|
941
931
|
i,
|
|
942
932
|
o
|
|
943
933
|
);
|
|
944
|
-
let
|
|
945
|
-
for await (const O of
|
|
946
|
-
O.final ?
|
|
947
|
-
if (!
|
|
934
|
+
let _ = null;
|
|
935
|
+
for await (const O of q)
|
|
936
|
+
O.final ? _ = O : yield O;
|
|
937
|
+
if (!_)
|
|
948
938
|
throw new Error(
|
|
949
939
|
"Continue task stream ended without final result"
|
|
950
940
|
);
|
|
951
|
-
let E = (
|
|
952
|
-
|
|
953
|
-
) : [],
|
|
941
|
+
let E = (p = _.status) != null && p.message ? F(
|
|
942
|
+
_.status.message
|
|
943
|
+
) : [], R = _;
|
|
954
944
|
if (E.length > 0)
|
|
955
945
|
for (yield {
|
|
956
|
-
...
|
|
946
|
+
..._,
|
|
957
947
|
final: !1,
|
|
958
948
|
text: D(
|
|
959
|
-
((
|
|
949
|
+
((S = _.status) == null ? void 0 : S.message) || {
|
|
960
950
|
parts: [],
|
|
961
|
-
messageId:
|
|
951
|
+
messageId: N()
|
|
962
952
|
}
|
|
963
953
|
)
|
|
964
954
|
}; E.length > 0; ) {
|
|
965
|
-
(
|
|
966
|
-
|
|
955
|
+
(c = R.status) != null && c.message && o.push(
|
|
956
|
+
R.status.message
|
|
967
957
|
);
|
|
968
958
|
const {
|
|
969
959
|
results: O,
|
|
@@ -971,36 +961,36 @@ async function* kt(t, e, s, n, a, r = !0, o = [], c, i) {
|
|
|
971
961
|
} = await vt(
|
|
972
962
|
E,
|
|
973
963
|
e,
|
|
974
|
-
(
|
|
964
|
+
(w = (d = R.status) == null ? void 0 : d.message) == null ? void 0 : w.messageId
|
|
975
965
|
);
|
|
976
966
|
if (O.length > 0 && (yield {
|
|
977
|
-
id:
|
|
967
|
+
id: R.id,
|
|
978
968
|
status: {
|
|
979
969
|
state: "working",
|
|
980
970
|
message: {
|
|
981
971
|
role: "agent",
|
|
982
972
|
kind: "message",
|
|
983
973
|
parts: O,
|
|
984
|
-
messageId:
|
|
974
|
+
messageId: N()
|
|
985
975
|
}
|
|
986
976
|
// Simple message with just the results
|
|
987
977
|
},
|
|
988
978
|
final: !1,
|
|
989
979
|
text: ""
|
|
990
980
|
}), J) {
|
|
991
|
-
const
|
|
981
|
+
const V = r ? gt(
|
|
992
982
|
o
|
|
993
|
-
) : [],
|
|
983
|
+
) : [], B = Q(
|
|
994
984
|
O,
|
|
995
|
-
|
|
985
|
+
V
|
|
996
986
|
), K = await ft(
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
987
|
+
R.id,
|
|
988
|
+
B,
|
|
989
|
+
a,
|
|
1000
990
|
e,
|
|
1001
991
|
s,
|
|
1002
|
-
|
|
1003
|
-
|
|
992
|
+
n,
|
|
993
|
+
l,
|
|
1004
994
|
i,
|
|
1005
995
|
o
|
|
1006
996
|
);
|
|
@@ -1011,16 +1001,16 @@ async function* kt(t, e, s, n, a, r = !0, o = [], c, i) {
|
|
|
1011
1001
|
throw new Error(
|
|
1012
1002
|
"Continue task stream ended without final result"
|
|
1013
1003
|
);
|
|
1014
|
-
|
|
1015
|
-
|
|
1004
|
+
R = H, E = (f = R.status) != null && f.message ? F(
|
|
1005
|
+
R.status.message
|
|
1016
1006
|
) : [], E.length > 0 && (yield {
|
|
1017
|
-
id:
|
|
1018
|
-
status:
|
|
1007
|
+
id: R.id,
|
|
1008
|
+
status: R.status,
|
|
1019
1009
|
final: !1,
|
|
1020
1010
|
text: D(
|
|
1021
|
-
((
|
|
1011
|
+
((y = R.status) == null ? void 0 : y.message) || {
|
|
1022
1012
|
parts: [],
|
|
1023
|
-
messageId:
|
|
1013
|
+
messageId: N()
|
|
1024
1014
|
}
|
|
1025
1015
|
)
|
|
1026
1016
|
});
|
|
@@ -1028,39 +1018,39 @@ async function* kt(t, e, s, n, a, r = !0, o = [], c, i) {
|
|
|
1028
1018
|
break;
|
|
1029
1019
|
}
|
|
1030
1020
|
yield {
|
|
1031
|
-
...
|
|
1021
|
+
...R,
|
|
1032
1022
|
final: !0,
|
|
1033
1023
|
text: D(
|
|
1034
|
-
((
|
|
1024
|
+
((x = R.status) == null ? void 0 : x.message) || {
|
|
1035
1025
|
parts: [],
|
|
1036
|
-
messageId:
|
|
1026
|
+
messageId: N()
|
|
1037
1027
|
}
|
|
1038
1028
|
)
|
|
1039
1029
|
};
|
|
1040
1030
|
} else {
|
|
1041
|
-
const
|
|
1042
|
-
...
|
|
1043
|
-
parts:
|
|
1044
|
-
},
|
|
1045
|
-
...
|
|
1031
|
+
const C = {
|
|
1032
|
+
...I.status.message,
|
|
1033
|
+
parts: k
|
|
1034
|
+
}, A = {
|
|
1035
|
+
...I,
|
|
1046
1036
|
status: {
|
|
1047
|
-
...
|
|
1048
|
-
message:
|
|
1037
|
+
...I.status,
|
|
1038
|
+
message: C
|
|
1049
1039
|
},
|
|
1050
|
-
final:
|
|
1040
|
+
final: M.length === 0,
|
|
1051
1041
|
// Only final if no agent messages to follow
|
|
1052
|
-
text: D(
|
|
1042
|
+
text: D(C)
|
|
1053
1043
|
};
|
|
1054
|
-
if (yield
|
|
1055
|
-
const
|
|
1044
|
+
if (yield A, M.length > 0) {
|
|
1045
|
+
const q = M.map((E) => D(E)).join(" "), _ = W(q);
|
|
1056
1046
|
yield {
|
|
1057
|
-
id:
|
|
1047
|
+
id: A.id,
|
|
1058
1048
|
status: {
|
|
1059
1049
|
state: "completed",
|
|
1060
|
-
message:
|
|
1050
|
+
message: _
|
|
1061
1051
|
},
|
|
1062
1052
|
final: !0,
|
|
1063
|
-
text:
|
|
1053
|
+
text: q
|
|
1064
1054
|
};
|
|
1065
1055
|
}
|
|
1066
1056
|
}
|
|
@@ -1068,257 +1058,257 @@ async function* kt(t, e, s, n, a, r = !0, o = [], c, i) {
|
|
|
1068
1058
|
}
|
|
1069
1059
|
}
|
|
1070
1060
|
}
|
|
1071
|
-
function
|
|
1061
|
+
function Zt(t) {
|
|
1072
1062
|
const {
|
|
1073
1063
|
agentId: e,
|
|
1074
1064
|
agentUrl: s,
|
|
1075
|
-
authProvider:
|
|
1076
|
-
defaultSessionId:
|
|
1065
|
+
authProvider: a,
|
|
1066
|
+
defaultSessionId: n,
|
|
1077
1067
|
timeout: r = Qt,
|
|
1078
1068
|
toolProvider: o,
|
|
1079
|
-
contextProvider:
|
|
1069
|
+
contextProvider: l,
|
|
1080
1070
|
enableStreaming: i = !1
|
|
1081
|
-
} = t,
|
|
1071
|
+
} = t, u = {
|
|
1082
1072
|
agentId: e,
|
|
1083
1073
|
agentUrl: s,
|
|
1084
|
-
authProvider:
|
|
1074
|
+
authProvider: a,
|
|
1085
1075
|
timeout: r
|
|
1086
1076
|
};
|
|
1087
1077
|
return {
|
|
1088
|
-
async sendMessage(
|
|
1089
|
-
var
|
|
1090
|
-
const {
|
|
1091
|
-
|
|
1092
|
-
const
|
|
1078
|
+
async sendMessage(g) {
|
|
1079
|
+
var f, y;
|
|
1080
|
+
const { abortSignal: h } = g, m = g.sessionId || n || void 0, p = [];
|
|
1081
|
+
p.push(g.message);
|
|
1082
|
+
const S = await X(
|
|
1083
|
+
g,
|
|
1093
1084
|
u,
|
|
1094
|
-
f,
|
|
1095
1085
|
{ isStreaming: !1 },
|
|
1096
1086
|
o,
|
|
1097
|
-
|
|
1098
|
-
|
|
1087
|
+
l,
|
|
1088
|
+
m
|
|
1099
1089
|
);
|
|
1100
|
-
let
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
{ abortSignal:
|
|
1090
|
+
let c = await At(
|
|
1091
|
+
S,
|
|
1092
|
+
u,
|
|
1093
|
+
{ abortSignal: h }
|
|
1104
1094
|
);
|
|
1105
|
-
const
|
|
1106
|
-
for (;
|
|
1107
|
-
const
|
|
1108
|
-
|
|
1095
|
+
const d = [], w = [];
|
|
1096
|
+
for (; c.status.message && o; ) {
|
|
1097
|
+
const x = F(
|
|
1098
|
+
c.status.message
|
|
1109
1099
|
);
|
|
1110
|
-
if (
|
|
1100
|
+
if (x.length === 0)
|
|
1111
1101
|
break;
|
|
1112
|
-
|
|
1113
|
-
const
|
|
1114
|
-
let
|
|
1115
|
-
for (const
|
|
1102
|
+
d.push(...x);
|
|
1103
|
+
const I = [];
|
|
1104
|
+
let P = !1;
|
|
1105
|
+
for (const T of x) {
|
|
1116
1106
|
const {
|
|
1117
|
-
toolCallId:
|
|
1118
|
-
toolId:
|
|
1119
|
-
arguments:
|
|
1120
|
-
} =
|
|
1107
|
+
toolCallId: b,
|
|
1108
|
+
toolId: k,
|
|
1109
|
+
arguments: M
|
|
1110
|
+
} = T.data;
|
|
1121
1111
|
try {
|
|
1122
|
-
const
|
|
1112
|
+
const C = await G(
|
|
1123
1113
|
o,
|
|
1124
|
-
|
|
1125
|
-
|
|
1126
|
-
), { result:
|
|
1127
|
-
|
|
1128
|
-
W(
|
|
1114
|
+
k,
|
|
1115
|
+
M
|
|
1116
|
+
), { result: A, returnToAgent: q, agentMessage: _ } = it(C);
|
|
1117
|
+
q && (P = !0), _ && w.push(
|
|
1118
|
+
W(_)
|
|
1129
1119
|
);
|
|
1130
|
-
const
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1120
|
+
const E = j(
|
|
1121
|
+
b,
|
|
1122
|
+
k,
|
|
1123
|
+
A
|
|
1134
1124
|
);
|
|
1135
|
-
|
|
1136
|
-
} catch (
|
|
1137
|
-
const
|
|
1138
|
-
|
|
1139
|
-
|
|
1125
|
+
I.push(E), d.push(E);
|
|
1126
|
+
} catch (C) {
|
|
1127
|
+
const A = j(
|
|
1128
|
+
b,
|
|
1129
|
+
k,
|
|
1140
1130
|
void 0,
|
|
1141
|
-
|
|
1131
|
+
C instanceof Error ? C.message : String(C)
|
|
1142
1132
|
);
|
|
1143
|
-
|
|
1133
|
+
I.push(A), d.push(A);
|
|
1144
1134
|
}
|
|
1145
1135
|
}
|
|
1146
|
-
if (
|
|
1147
|
-
const
|
|
1148
|
-
|
|
1149
|
-
|
|
1150
|
-
|
|
1151
|
-
|
|
1136
|
+
if (p.push(c.status.message), P) {
|
|
1137
|
+
const T = Q(I);
|
|
1138
|
+
c = await et(
|
|
1139
|
+
c.id,
|
|
1140
|
+
T,
|
|
1141
|
+
u,
|
|
1152
1142
|
o,
|
|
1153
|
-
|
|
1154
|
-
|
|
1155
|
-
|
|
1143
|
+
l,
|
|
1144
|
+
m,
|
|
1145
|
+
h
|
|
1156
1146
|
);
|
|
1157
1147
|
} else
|
|
1158
1148
|
break;
|
|
1159
1149
|
}
|
|
1160
|
-
if (
|
|
1161
|
-
const
|
|
1162
|
-
...
|
|
1163
|
-
parts:
|
|
1150
|
+
if (d.length > 0 && (f = c.status) != null && f.message) {
|
|
1151
|
+
const x = {
|
|
1152
|
+
...c.status.message,
|
|
1153
|
+
parts: d
|
|
1164
1154
|
};
|
|
1165
|
-
|
|
1166
|
-
...
|
|
1155
|
+
c = {
|
|
1156
|
+
...c,
|
|
1167
1157
|
status: {
|
|
1168
|
-
...
|
|
1169
|
-
message:
|
|
1158
|
+
...c.status,
|
|
1159
|
+
message: x
|
|
1170
1160
|
}
|
|
1171
1161
|
};
|
|
1172
1162
|
}
|
|
1173
|
-
if (
|
|
1174
|
-
const
|
|
1163
|
+
if (w.length > 0) {
|
|
1164
|
+
const x = w.map((P) => D(P)).join(" "), I = W(x);
|
|
1175
1165
|
return {
|
|
1176
|
-
...
|
|
1166
|
+
...c,
|
|
1177
1167
|
// Keep the enhanced message with tool results
|
|
1178
1168
|
// The agent message will be handled separately by the caller
|
|
1179
|
-
text:
|
|
1180
|
-
agentMessage:
|
|
1169
|
+
text: x,
|
|
1170
|
+
agentMessage: I
|
|
1181
1171
|
// Add this for the caller to handle
|
|
1182
1172
|
};
|
|
1183
1173
|
}
|
|
1184
1174
|
return {
|
|
1185
|
-
...
|
|
1175
|
+
...c,
|
|
1186
1176
|
text: D(
|
|
1187
|
-
((
|
|
1177
|
+
((y = c.status) == null ? void 0 : y.message) || {
|
|
1188
1178
|
parts: [],
|
|
1189
|
-
messageId:
|
|
1179
|
+
messageId: N()
|
|
1190
1180
|
}
|
|
1191
1181
|
)
|
|
1192
1182
|
};
|
|
1193
1183
|
},
|
|
1194
|
-
async *sendMessageStream(
|
|
1184
|
+
async *sendMessageStream(g) {
|
|
1195
1185
|
const {
|
|
1196
|
-
withHistory:
|
|
1197
|
-
abortSignal:
|
|
1198
|
-
enableStreaming:
|
|
1199
|
-
} =
|
|
1200
|
-
|
|
1201
|
-
const
|
|
1186
|
+
withHistory: h = !0,
|
|
1187
|
+
abortSignal: m,
|
|
1188
|
+
enableStreaming: p
|
|
1189
|
+
} = g, S = g.sessionId || n || void 0, c = p ?? i, d = [];
|
|
1190
|
+
d.push(g.message);
|
|
1191
|
+
const w = await X(
|
|
1192
|
+
g,
|
|
1202
1193
|
u,
|
|
1203
|
-
f,
|
|
1204
1194
|
{
|
|
1205
1195
|
isStreaming: !0,
|
|
1206
1196
|
// Always use message/stream endpoint for SSE
|
|
1207
|
-
enableTokenStreaming:
|
|
1197
|
+
enableTokenStreaming: c
|
|
1208
1198
|
},
|
|
1209
1199
|
o,
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
),
|
|
1213
|
-
|
|
1214
|
-
|
|
1200
|
+
l,
|
|
1201
|
+
S
|
|
1202
|
+
), f = St(
|
|
1203
|
+
w,
|
|
1204
|
+
u,
|
|
1215
1205
|
{
|
|
1216
|
-
enableTokenStreaming:
|
|
1206
|
+
enableTokenStreaming: c,
|
|
1217
1207
|
// Token streaming is optional
|
|
1218
1208
|
streamingTimeout: r,
|
|
1219
|
-
abortSignal:
|
|
1209
|
+
abortSignal: m
|
|
1220
1210
|
}
|
|
1221
1211
|
);
|
|
1222
1212
|
yield* kt(
|
|
1223
|
-
d,
|
|
1224
|
-
o,
|
|
1225
|
-
c,
|
|
1226
1213
|
f,
|
|
1227
|
-
|
|
1228
|
-
p,
|
|
1214
|
+
o,
|
|
1229
1215
|
l,
|
|
1230
|
-
|
|
1216
|
+
u,
|
|
1217
|
+
S,
|
|
1218
|
+
h,
|
|
1219
|
+
d,
|
|
1220
|
+
m,
|
|
1231
1221
|
{
|
|
1232
1222
|
isStreaming: !0,
|
|
1233
|
-
enableTokenStreaming:
|
|
1223
|
+
enableTokenStreaming: c,
|
|
1234
1224
|
streamingTimeout: r
|
|
1235
1225
|
}
|
|
1236
1226
|
);
|
|
1237
1227
|
},
|
|
1238
|
-
async continueTask(
|
|
1239
|
-
var
|
|
1240
|
-
const
|
|
1241
|
-
let
|
|
1228
|
+
async continueTask(g, h, m) {
|
|
1229
|
+
var d;
|
|
1230
|
+
const p = nt(h);
|
|
1231
|
+
let c = await et(
|
|
1232
|
+
g,
|
|
1233
|
+
p,
|
|
1242
1234
|
u,
|
|
1243
|
-
h,
|
|
1244
|
-
f,
|
|
1245
1235
|
o,
|
|
1246
|
-
|
|
1247
|
-
|
|
1236
|
+
l,
|
|
1237
|
+
m
|
|
1248
1238
|
);
|
|
1249
|
-
for (;
|
|
1250
|
-
const
|
|
1251
|
-
|
|
1239
|
+
for (; c.status.state === "input-required" && c.status.message && o; ) {
|
|
1240
|
+
const w = F(
|
|
1241
|
+
c.status.message
|
|
1252
1242
|
);
|
|
1253
|
-
if (
|
|
1243
|
+
if (w.length === 0)
|
|
1254
1244
|
break;
|
|
1255
|
-
const { results:
|
|
1256
|
-
if (
|
|
1257
|
-
const
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
|
|
1261
|
-
|
|
1245
|
+
const { results: f, shouldReturnToAgent: y } = await vt(w, o);
|
|
1246
|
+
if (y) {
|
|
1247
|
+
const x = Q(f);
|
|
1248
|
+
c = await et(
|
|
1249
|
+
c.id,
|
|
1250
|
+
x,
|
|
1251
|
+
u,
|
|
1262
1252
|
o,
|
|
1263
|
-
|
|
1264
|
-
|
|
1253
|
+
l,
|
|
1254
|
+
m
|
|
1265
1255
|
);
|
|
1266
1256
|
} else
|
|
1267
1257
|
break;
|
|
1268
1258
|
}
|
|
1269
1259
|
return {
|
|
1270
|
-
...
|
|
1260
|
+
...c,
|
|
1271
1261
|
text: D(
|
|
1272
|
-
((
|
|
1262
|
+
((d = c.status) == null ? void 0 : d.message) || {
|
|
1273
1263
|
parts: [],
|
|
1274
|
-
messageId:
|
|
1264
|
+
messageId: N()
|
|
1275
1265
|
}
|
|
1276
1266
|
)
|
|
1277
1267
|
};
|
|
1278
1268
|
},
|
|
1279
|
-
async getTask(
|
|
1269
|
+
async getTask() {
|
|
1280
1270
|
throw new Error("getTask not implemented yet");
|
|
1281
1271
|
},
|
|
1282
|
-
async cancelTask(
|
|
1272
|
+
async cancelTask() {
|
|
1283
1273
|
throw new Error("cancelTask not implemented yet");
|
|
1284
1274
|
}
|
|
1285
1275
|
};
|
|
1286
1276
|
}
|
|
1287
1277
|
const ct = "a8c_agenttic_conversation_history";
|
|
1288
|
-
function
|
|
1289
|
-
var
|
|
1278
|
+
function te(t) {
|
|
1279
|
+
var g, h;
|
|
1290
1280
|
const e = t.parts.filter(
|
|
1291
|
-
(
|
|
1292
|
-
), s = e.map((
|
|
1293
|
-
`),
|
|
1294
|
-
(
|
|
1295
|
-
var
|
|
1296
|
-
return ((
|
|
1281
|
+
(m) => m.type === "text"
|
|
1282
|
+
), s = e.map((m) => m.text).join(`
|
|
1283
|
+
`), a = e.some(
|
|
1284
|
+
(m) => {
|
|
1285
|
+
var p;
|
|
1286
|
+
return ((p = m.metadata) == null ? void 0 : p.contentType) === "context";
|
|
1297
1287
|
}
|
|
1298
|
-
) ? "context" : void 0,
|
|
1299
|
-
(
|
|
1300
|
-
).map((
|
|
1301
|
-
toolCallId:
|
|
1302
|
-
toolId:
|
|
1303
|
-
arguments:
|
|
1288
|
+
) ? "context" : void 0, n = t.parts.filter(
|
|
1289
|
+
(m) => m.type === "data" && "toolCallId" in m.data && "arguments" in m.data
|
|
1290
|
+
).map((m) => ({
|
|
1291
|
+
toolCallId: m.data.toolCallId,
|
|
1292
|
+
toolId: m.data.toolId,
|
|
1293
|
+
arguments: m.data.arguments
|
|
1304
1294
|
})), r = t.parts.filter(
|
|
1305
|
-
(
|
|
1306
|
-
).map((
|
|
1307
|
-
toolCallId:
|
|
1308
|
-
result:
|
|
1309
|
-
error:
|
|
1310
|
-
})),
|
|
1295
|
+
(m) => m.type === "data" && "toolCallId" in m.data && "result" in m.data
|
|
1296
|
+
).map((m) => ({
|
|
1297
|
+
toolCallId: m.data.toolCallId,
|
|
1298
|
+
result: m.data.result,
|
|
1299
|
+
error: m.data.error
|
|
1300
|
+
})), l = n.length > 0 || r.length > 0 ? "agent" : t.role, i = ((g = t.metadata) == null ? void 0 : g.timestamp) ?? Date.now(), u = ((h = t.metadata) == null ? void 0 : h.archived) ?? void 0;
|
|
1311
1301
|
return {
|
|
1312
|
-
role:
|
|
1302
|
+
role: l,
|
|
1313
1303
|
content: s || "(No text content)",
|
|
1314
1304
|
timestamp: i,
|
|
1315
|
-
...
|
|
1316
|
-
...
|
|
1317
|
-
...
|
|
1305
|
+
...u !== void 0 && { archived: u },
|
|
1306
|
+
...a && { contentType: a },
|
|
1307
|
+
...n.length > 0 && { toolCalls: n },
|
|
1318
1308
|
...r.length > 0 && { toolResults: r }
|
|
1319
1309
|
};
|
|
1320
1310
|
}
|
|
1321
|
-
function
|
|
1311
|
+
function ee(t) {
|
|
1322
1312
|
const e = [];
|
|
1323
1313
|
if (t.content && t.content !== "(No text content)" && e.push({
|
|
1324
1314
|
type: "text",
|
|
@@ -1352,7 +1342,7 @@ function se(t) {
|
|
|
1352
1342
|
role: t.role,
|
|
1353
1343
|
kind: "message",
|
|
1354
1344
|
parts: e,
|
|
1355
|
-
messageId:
|
|
1345
|
+
messageId: N(),
|
|
1356
1346
|
metadata: {
|
|
1357
1347
|
timestamp: t.timestamp,
|
|
1358
1348
|
// only store archived if it was already present.
|
|
@@ -1362,65 +1352,65 @@ function se(t) {
|
|
|
1362
1352
|
}
|
|
1363
1353
|
};
|
|
1364
1354
|
}
|
|
1365
|
-
const U = /* @__PURE__ */ new Map(),
|
|
1355
|
+
const U = /* @__PURE__ */ new Map(), se = 50;
|
|
1366
1356
|
async function ae(t, e, s) {
|
|
1367
|
-
const
|
|
1368
|
-
if (U.set(
|
|
1369
|
-
const
|
|
1370
|
-
|
|
1357
|
+
const a = s || t;
|
|
1358
|
+
if (U.set(a, [...e]), U.size > se) {
|
|
1359
|
+
const n = U.keys().next().value;
|
|
1360
|
+
n && U.delete(n);
|
|
1371
1361
|
}
|
|
1372
1362
|
if (!(typeof sessionStorage > "u"))
|
|
1373
1363
|
try {
|
|
1374
|
-
const
|
|
1375
|
-
storageKey:
|
|
1376
|
-
messages: e.map(
|
|
1364
|
+
const n = {
|
|
1365
|
+
storageKey: a,
|
|
1366
|
+
messages: e.map(te),
|
|
1377
1367
|
lastUpdated: Date.now()
|
|
1378
1368
|
};
|
|
1379
1369
|
sessionStorage.setItem(
|
|
1380
|
-
`${ct}_${
|
|
1381
|
-
JSON.stringify(
|
|
1370
|
+
`${ct}_${a}`,
|
|
1371
|
+
JSON.stringify(n)
|
|
1382
1372
|
);
|
|
1383
|
-
} catch (
|
|
1384
|
-
|
|
1373
|
+
} catch (n) {
|
|
1374
|
+
v(
|
|
1385
1375
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1386
|
-
|
|
1387
|
-
|
|
1376
|
+
a,
|
|
1377
|
+
n
|
|
1388
1378
|
);
|
|
1389
1379
|
}
|
|
1390
1380
|
}
|
|
1391
|
-
async function
|
|
1381
|
+
async function ne(t, e) {
|
|
1392
1382
|
const s = e || t;
|
|
1393
1383
|
if (U.has(s))
|
|
1394
1384
|
return [...U.get(s)];
|
|
1395
1385
|
if (typeof sessionStorage > "u")
|
|
1396
1386
|
return [];
|
|
1397
1387
|
try {
|
|
1398
|
-
const
|
|
1388
|
+
const a = sessionStorage.getItem(
|
|
1399
1389
|
`${ct}_${s}`
|
|
1400
1390
|
);
|
|
1401
|
-
if (
|
|
1402
|
-
const r = JSON.parse(
|
|
1391
|
+
if (a) {
|
|
1392
|
+
const r = JSON.parse(a).messages.map(ee);
|
|
1403
1393
|
return U.set(s, r), [...r];
|
|
1404
1394
|
}
|
|
1405
|
-
} catch (
|
|
1406
|
-
|
|
1395
|
+
} catch (a) {
|
|
1396
|
+
v(
|
|
1407
1397
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1408
1398
|
s,
|
|
1409
|
-
|
|
1399
|
+
a
|
|
1410
1400
|
);
|
|
1411
1401
|
}
|
|
1412
1402
|
return [];
|
|
1413
1403
|
}
|
|
1414
|
-
async function
|
|
1404
|
+
async function oe(t, e) {
|
|
1415
1405
|
const s = e || t;
|
|
1416
1406
|
if (U.delete(s), !(typeof sessionStorage > "u"))
|
|
1417
1407
|
try {
|
|
1418
1408
|
sessionStorage.removeItem(`${ct}_${s}`);
|
|
1419
|
-
} catch (
|
|
1420
|
-
|
|
1409
|
+
} catch (a) {
|
|
1410
|
+
v(
|
|
1421
1411
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1422
1412
|
s,
|
|
1423
|
-
|
|
1413
|
+
a
|
|
1424
1414
|
);
|
|
1425
1415
|
}
|
|
1426
1416
|
}
|
|
@@ -1435,27 +1425,27 @@ function L(t) {
|
|
|
1435
1425
|
}
|
|
1436
1426
|
};
|
|
1437
1427
|
}
|
|
1438
|
-
function
|
|
1428
|
+
function re(t) {
|
|
1439
1429
|
const e = [];
|
|
1440
1430
|
for (const s of t)
|
|
1441
|
-
for (const
|
|
1442
|
-
if (
|
|
1431
|
+
for (const a of s.parts)
|
|
1432
|
+
if (a.type === "text")
|
|
1443
1433
|
e.push({
|
|
1444
1434
|
type: "data",
|
|
1445
1435
|
data: {
|
|
1446
1436
|
role: s.role,
|
|
1447
|
-
text:
|
|
1437
|
+
text: a.text
|
|
1448
1438
|
}
|
|
1449
1439
|
});
|
|
1450
|
-
else if (
|
|
1451
|
-
if ("role" in
|
|
1440
|
+
else if (a.type === "data") {
|
|
1441
|
+
if ("role" in a.data && "text" in a.data)
|
|
1452
1442
|
continue;
|
|
1453
|
-
if ("toolCallId" in
|
|
1454
|
-
e.push(
|
|
1443
|
+
if ("toolCallId" in a.data && "arguments" in a.data) {
|
|
1444
|
+
e.push(a);
|
|
1455
1445
|
continue;
|
|
1456
1446
|
}
|
|
1457
|
-
if ("toolCallId" in
|
|
1458
|
-
e.push(
|
|
1447
|
+
if ("toolCallId" in a.data && "result" in a.data) {
|
|
1448
|
+
e.push(a);
|
|
1459
1449
|
continue;
|
|
1460
1450
|
}
|
|
1461
1451
|
}
|
|
@@ -1465,92 +1455,92 @@ function mt(t, e = []) {
|
|
|
1465
1455
|
return {
|
|
1466
1456
|
role: "user",
|
|
1467
1457
|
parts: [
|
|
1468
|
-
...
|
|
1458
|
+
...re(e),
|
|
1469
1459
|
{
|
|
1470
1460
|
type: "text",
|
|
1471
1461
|
text: t
|
|
1472
1462
|
}
|
|
1473
1463
|
],
|
|
1474
1464
|
kind: "message",
|
|
1475
|
-
messageId:
|
|
1465
|
+
messageId: N(),
|
|
1476
1466
|
metadata: {
|
|
1477
1467
|
timestamp: Date.now()
|
|
1478
1468
|
}
|
|
1479
1469
|
};
|
|
1480
1470
|
}
|
|
1481
|
-
function
|
|
1471
|
+
function ie(t) {
|
|
1482
1472
|
return t != null && t.parts ? t.parts.filter(
|
|
1483
1473
|
(e) => e.type === "data" && "toolCallId" in e.data && "result" in e.data
|
|
1484
1474
|
) : [];
|
|
1485
1475
|
}
|
|
1486
|
-
async function
|
|
1476
|
+
async function le(t) {
|
|
1487
1477
|
const e = [];
|
|
1488
1478
|
for (const s of t)
|
|
1489
1479
|
if (s.parts && Array.isArray(s.parts))
|
|
1490
1480
|
if (s.parts.some(
|
|
1491
|
-
(
|
|
1481
|
+
(n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
|
|
1492
1482
|
)) {
|
|
1493
|
-
const
|
|
1483
|
+
const n = Yt(
|
|
1494
1484
|
s.parts
|
|
1495
1485
|
);
|
|
1496
1486
|
e.push({
|
|
1497
1487
|
...s,
|
|
1498
|
-
parts:
|
|
1488
|
+
parts: n
|
|
1499
1489
|
});
|
|
1500
1490
|
} else
|
|
1501
1491
|
e.push(s);
|
|
1502
1492
|
else
|
|
1503
1493
|
e.push(s);
|
|
1504
|
-
return
|
|
1494
|
+
return Gt(), e;
|
|
1505
1495
|
}
|
|
1506
|
-
function
|
|
1496
|
+
function ce() {
|
|
1507
1497
|
const t = /* @__PURE__ */ new Map();
|
|
1508
|
-
async function e(s,
|
|
1509
|
-
const
|
|
1510
|
-
if (
|
|
1498
|
+
async function e(s, a) {
|
|
1499
|
+
const n = t.get(s);
|
|
1500
|
+
if (n != null && n.sessionId)
|
|
1511
1501
|
try {
|
|
1512
1502
|
await ae(
|
|
1513
|
-
|
|
1514
|
-
|
|
1515
|
-
|
|
1503
|
+
n.sessionId,
|
|
1504
|
+
a,
|
|
1505
|
+
n.conversationStorageKey
|
|
1516
1506
|
);
|
|
1517
1507
|
} catch (r) {
|
|
1518
|
-
|
|
1508
|
+
ut(
|
|
1519
1509
|
`Failed to persist conversation history for agent ${s}:`,
|
|
1520
1510
|
r
|
|
1521
1511
|
);
|
|
1522
1512
|
}
|
|
1523
1513
|
}
|
|
1524
1514
|
return {
|
|
1525
|
-
async createAgent(s,
|
|
1515
|
+
async createAgent(s, a) {
|
|
1526
1516
|
if (t.has(s))
|
|
1527
1517
|
return t.get(s).client;
|
|
1528
|
-
const
|
|
1529
|
-
let
|
|
1518
|
+
const n = Zt(a), r = a.sessionId || null, o = a.conversationStorageKey;
|
|
1519
|
+
let l = [];
|
|
1530
1520
|
if (r)
|
|
1531
1521
|
try {
|
|
1532
|
-
|
|
1522
|
+
l = await ne(
|
|
1533
1523
|
r,
|
|
1534
1524
|
o
|
|
1535
1525
|
);
|
|
1536
|
-
} catch (
|
|
1537
|
-
|
|
1526
|
+
} catch (u) {
|
|
1527
|
+
ut(
|
|
1538
1528
|
`Failed to load conversation history for agent ${s} with session ${r}:`,
|
|
1539
|
-
|
|
1529
|
+
u
|
|
1540
1530
|
);
|
|
1541
1531
|
}
|
|
1542
1532
|
const i = {
|
|
1543
|
-
client:
|
|
1533
|
+
client: n,
|
|
1544
1534
|
sessionId: r,
|
|
1545
1535
|
conversationStorageKey: o,
|
|
1546
|
-
conversationHistory:
|
|
1536
|
+
conversationHistory: l,
|
|
1547
1537
|
currentAbortController: null
|
|
1548
1538
|
};
|
|
1549
|
-
return t.set(s, i),
|
|
1539
|
+
return t.set(s, i), n;
|
|
1550
1540
|
},
|
|
1551
1541
|
getAgent(s) {
|
|
1552
|
-
const
|
|
1553
|
-
return (
|
|
1542
|
+
const a = t.get(s);
|
|
1543
|
+
return (a == null ? void 0 : a.client) || null;
|
|
1554
1544
|
},
|
|
1555
1545
|
hasAgent(s) {
|
|
1556
1546
|
return t.has(s);
|
|
@@ -1558,257 +1548,257 @@ function ue() {
|
|
|
1558
1548
|
removeAgent(s) {
|
|
1559
1549
|
return t.delete(s);
|
|
1560
1550
|
},
|
|
1561
|
-
async sendMessage(s,
|
|
1562
|
-
var
|
|
1551
|
+
async sendMessage(s, a, n = {}) {
|
|
1552
|
+
var c;
|
|
1563
1553
|
const r = t.get(s);
|
|
1564
1554
|
if (!r)
|
|
1565
1555
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1566
|
-
const { withHistory: o = !0, ...
|
|
1567
|
-
message:
|
|
1556
|
+
const { withHistory: o = !0, ...l } = n, { client: i, conversationHistory: u } = r, g = n.message || mt(a, u), h = await i.sendMessage({
|
|
1557
|
+
message: g,
|
|
1568
1558
|
withHistory: o,
|
|
1569
|
-
...
|
|
1559
|
+
...l
|
|
1570
1560
|
});
|
|
1571
|
-
let
|
|
1572
|
-
if ((
|
|
1573
|
-
const
|
|
1574
|
-
(
|
|
1575
|
-
),
|
|
1576
|
-
(
|
|
1561
|
+
let m = null;
|
|
1562
|
+
if ((c = h.status) != null && c.message) {
|
|
1563
|
+
const d = h.status.message.parts.filter(
|
|
1564
|
+
(f) => f.type === "data" && "toolCallId" in f.data && ("arguments" in f.data || "result" in f.data)
|
|
1565
|
+
), w = h.status.message.parts.filter(
|
|
1566
|
+
(f) => f.type === "text"
|
|
1577
1567
|
);
|
|
1578
|
-
|
|
1568
|
+
m = {
|
|
1579
1569
|
role: "agent",
|
|
1580
1570
|
kind: "message",
|
|
1581
|
-
parts: [...
|
|
1582
|
-
messageId:
|
|
1571
|
+
parts: [...d, ...w],
|
|
1572
|
+
messageId: N(),
|
|
1583
1573
|
metadata: {
|
|
1584
1574
|
timestamp: Date.now()
|
|
1585
1575
|
}
|
|
1586
1576
|
};
|
|
1587
1577
|
}
|
|
1588
|
-
const
|
|
1589
|
-
...
|
|
1578
|
+
const p = [
|
|
1579
|
+
...u,
|
|
1590
1580
|
// Store only the new content from the user message (without history parts)
|
|
1591
|
-
|
|
1581
|
+
nt(a),
|
|
1592
1582
|
// Add complete agent response with tool calls/results if present
|
|
1593
|
-
...
|
|
1583
|
+
...m ? [L(m)] : []
|
|
1594
1584
|
];
|
|
1595
|
-
let
|
|
1596
|
-
if (
|
|
1597
|
-
const
|
|
1598
|
-
|
|
1585
|
+
let S = p;
|
|
1586
|
+
if (h.agentMessage) {
|
|
1587
|
+
const d = L(
|
|
1588
|
+
h.agentMessage
|
|
1599
1589
|
);
|
|
1600
|
-
|
|
1601
|
-
...
|
|
1602
|
-
|
|
1590
|
+
S = [
|
|
1591
|
+
...p,
|
|
1592
|
+
d
|
|
1603
1593
|
];
|
|
1604
1594
|
}
|
|
1605
|
-
return r.conversationHistory =
|
|
1595
|
+
return r.conversationHistory = S, o && await e(
|
|
1606
1596
|
s,
|
|
1607
|
-
|
|
1608
|
-
),
|
|
1597
|
+
S
|
|
1598
|
+
), h;
|
|
1609
1599
|
},
|
|
1610
|
-
async *sendMessageStream(s,
|
|
1611
|
-
var
|
|
1600
|
+
async *sendMessageStream(s, a, n = {}) {
|
|
1601
|
+
var f, y, x, I, P, T;
|
|
1612
1602
|
const r = t.get(s);
|
|
1613
1603
|
if (!r)
|
|
1614
1604
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1615
1605
|
const {
|
|
1616
1606
|
withHistory: o = !0,
|
|
1617
|
-
abortSignal:
|
|
1607
|
+
abortSignal: l,
|
|
1618
1608
|
metadata: i,
|
|
1619
|
-
...
|
|
1620
|
-
} =
|
|
1621
|
-
r.currentAbortController =
|
|
1609
|
+
...u
|
|
1610
|
+
} = n, { client: g } = r, h = i ? (({ contentType: b, ...k }) => k)(i) : void 0, m = new AbortController();
|
|
1611
|
+
r.currentAbortController = m, l && l.addEventListener(
|
|
1622
1612
|
"abort",
|
|
1623
|
-
() =>
|
|
1613
|
+
() => m.abort()
|
|
1624
1614
|
);
|
|
1625
|
-
let
|
|
1615
|
+
let p = [
|
|
1626
1616
|
...r.conversationHistory
|
|
1627
|
-
],
|
|
1628
|
-
const
|
|
1629
|
-
|
|
1617
|
+
], S = [];
|
|
1618
|
+
const c = await le(
|
|
1619
|
+
p
|
|
1630
1620
|
);
|
|
1631
|
-
r.conversationHistory =
|
|
1621
|
+
r.conversationHistory = c, p = c, o && await e(
|
|
1632
1622
|
s,
|
|
1633
|
-
|
|
1623
|
+
c
|
|
1634
1624
|
);
|
|
1635
|
-
const
|
|
1636
|
-
|
|
1637
|
-
|
|
1625
|
+
const d = n.message || mt(
|
|
1626
|
+
a,
|
|
1627
|
+
c
|
|
1638
1628
|
);
|
|
1639
|
-
if (
|
|
1640
|
-
const { contentType:
|
|
1641
|
-
if (
|
|
1642
|
-
const
|
|
1643
|
-
|
|
1644
|
-
...
|
|
1645
|
-
contentType:
|
|
1629
|
+
if (n.metadata && !n.message) {
|
|
1630
|
+
const { contentType: b, ...k } = n.metadata;
|
|
1631
|
+
if (b) {
|
|
1632
|
+
const M = d.parts[d.parts.length - 1];
|
|
1633
|
+
M && M.type === "text" && (M.metadata = {
|
|
1634
|
+
...M.metadata,
|
|
1635
|
+
contentType: b
|
|
1646
1636
|
});
|
|
1647
1637
|
}
|
|
1648
|
-
Object.keys(
|
|
1649
|
-
...
|
|
1650
|
-
...
|
|
1638
|
+
Object.keys(k).length > 0 && (d.metadata = {
|
|
1639
|
+
...d.metadata,
|
|
1640
|
+
...k
|
|
1651
1641
|
});
|
|
1652
1642
|
}
|
|
1653
|
-
const
|
|
1654
|
-
|
|
1655
|
-
...
|
|
1656
|
-
|
|
1657
|
-
], r.conversationHistory =
|
|
1643
|
+
const w = nt(a, n.metadata);
|
|
1644
|
+
p = [
|
|
1645
|
+
...p,
|
|
1646
|
+
w
|
|
1647
|
+
], r.conversationHistory = p, o && await e(
|
|
1658
1648
|
s,
|
|
1659
|
-
|
|
1649
|
+
p
|
|
1660
1650
|
);
|
|
1661
|
-
for await (const
|
|
1662
|
-
message:
|
|
1651
|
+
for await (const b of g.sendMessageStream({
|
|
1652
|
+
message: d,
|
|
1663
1653
|
withHistory: o,
|
|
1664
|
-
abortSignal:
|
|
1665
|
-
...
|
|
1666
|
-
...
|
|
1667
|
-
metadata:
|
|
1654
|
+
abortSignal: m.signal,
|
|
1655
|
+
...u,
|
|
1656
|
+
...h && Object.keys(h).length > 0 && {
|
|
1657
|
+
metadata: h
|
|
1668
1658
|
}
|
|
1669
1659
|
})) {
|
|
1670
|
-
if (((
|
|
1671
|
-
|
|
1672
|
-
|
|
1660
|
+
if (((f = b.status) == null ? void 0 : f.state) === "input-required" && ((y = b.status) != null && y.message)) {
|
|
1661
|
+
S = F(
|
|
1662
|
+
b.status.message
|
|
1673
1663
|
).map(
|
|
1674
|
-
(
|
|
1664
|
+
(C) => C.data.toolCallId
|
|
1675
1665
|
);
|
|
1676
|
-
const
|
|
1677
|
-
|
|
1666
|
+
const M = L(
|
|
1667
|
+
b.status.message
|
|
1678
1668
|
);
|
|
1679
|
-
|
|
1680
|
-
...
|
|
1681
|
-
|
|
1682
|
-
], r.conversationHistory =
|
|
1669
|
+
p = [
|
|
1670
|
+
...p,
|
|
1671
|
+
M
|
|
1672
|
+
], r.conversationHistory = p, o && await e(
|
|
1683
1673
|
s,
|
|
1684
|
-
|
|
1674
|
+
p
|
|
1685
1675
|
);
|
|
1686
1676
|
}
|
|
1687
|
-
if (((
|
|
1688
|
-
const
|
|
1689
|
-
|
|
1677
|
+
if (((x = b.status) == null ? void 0 : x.state) === "working" && ((I = b.status) != null && I.message) && !b.final) {
|
|
1678
|
+
const M = ie(
|
|
1679
|
+
b.status.message
|
|
1690
1680
|
).filter(
|
|
1691
|
-
(
|
|
1692
|
-
|
|
1681
|
+
(C) => S.includes(
|
|
1682
|
+
C.data.toolCallId
|
|
1693
1683
|
)
|
|
1694
1684
|
);
|
|
1695
|
-
if (
|
|
1696
|
-
const
|
|
1685
|
+
if (M.length > 0) {
|
|
1686
|
+
const C = {
|
|
1697
1687
|
role: "agent",
|
|
1698
1688
|
kind: "message",
|
|
1699
|
-
parts:
|
|
1700
|
-
messageId:
|
|
1689
|
+
parts: M,
|
|
1690
|
+
messageId: N()
|
|
1701
1691
|
};
|
|
1702
|
-
|
|
1703
|
-
...
|
|
1704
|
-
L(
|
|
1705
|
-
], r.conversationHistory =
|
|
1692
|
+
p = [
|
|
1693
|
+
...p,
|
|
1694
|
+
L(C)
|
|
1695
|
+
], r.conversationHistory = p, o && await e(
|
|
1706
1696
|
s,
|
|
1707
|
-
|
|
1697
|
+
p
|
|
1708
1698
|
);
|
|
1709
1699
|
}
|
|
1710
1700
|
}
|
|
1711
|
-
if (
|
|
1712
|
-
|
|
1713
|
-
let
|
|
1714
|
-
(T =
|
|
1715
|
-
|
|
1716
|
-
),
|
|
1717
|
-
...
|
|
1718
|
-
|
|
1719
|
-
], r.conversationHistory =
|
|
1701
|
+
if (b.final && ((P = b.status) == null ? void 0 : P.state) !== "input-required") {
|
|
1702
|
+
S = [];
|
|
1703
|
+
let k = null;
|
|
1704
|
+
(T = b.status) != null && T.message && (k = L(
|
|
1705
|
+
b.status.message
|
|
1706
|
+
), p = [
|
|
1707
|
+
...p,
|
|
1708
|
+
k
|
|
1709
|
+
], r.conversationHistory = p, o && await e(
|
|
1720
1710
|
s,
|
|
1721
|
-
|
|
1711
|
+
p
|
|
1722
1712
|
));
|
|
1723
1713
|
}
|
|
1724
|
-
yield
|
|
1714
|
+
yield b;
|
|
1725
1715
|
}
|
|
1726
1716
|
r.currentAbortController = null;
|
|
1727
1717
|
},
|
|
1728
1718
|
async resetConversation(s) {
|
|
1729
|
-
const
|
|
1730
|
-
if (!
|
|
1719
|
+
const a = t.get(s);
|
|
1720
|
+
if (!a)
|
|
1731
1721
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1732
|
-
|
|
1733
|
-
|
|
1734
|
-
|
|
1722
|
+
a.conversationHistory = [], a.sessionId && await oe(
|
|
1723
|
+
a.sessionId,
|
|
1724
|
+
a.conversationStorageKey
|
|
1735
1725
|
);
|
|
1736
1726
|
},
|
|
1737
1727
|
getConversationHistory(s) {
|
|
1738
|
-
const
|
|
1739
|
-
if (!
|
|
1728
|
+
const a = t.get(s);
|
|
1729
|
+
if (!a)
|
|
1740
1730
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1741
|
-
return [...
|
|
1731
|
+
return [...a.conversationHistory];
|
|
1742
1732
|
},
|
|
1743
1733
|
abortCurrentRequest(s) {
|
|
1744
|
-
const
|
|
1745
|
-
if (!
|
|
1734
|
+
const a = t.get(s);
|
|
1735
|
+
if (!a)
|
|
1746
1736
|
throw new Error(`Agent with key "${s}" not found`);
|
|
1747
|
-
|
|
1737
|
+
a.currentAbortController && (a.currentAbortController.abort(), a.currentAbortController = null);
|
|
1748
1738
|
},
|
|
1749
1739
|
clear() {
|
|
1750
1740
|
t.clear();
|
|
1751
1741
|
}
|
|
1752
1742
|
};
|
|
1753
1743
|
}
|
|
1754
|
-
const
|
|
1744
|
+
const ue = ce();
|
|
1755
1745
|
function st() {
|
|
1756
|
-
return
|
|
1746
|
+
return ue;
|
|
1757
1747
|
}
|
|
1758
|
-
function
|
|
1748
|
+
function de() {
|
|
1759
1749
|
const [t, e] = yt([]), s = $(
|
|
1760
1750
|
(r) => {
|
|
1761
1751
|
e((o) => {
|
|
1762
|
-
const
|
|
1752
|
+
const l = o.findIndex(
|
|
1763
1753
|
(i) => i.id === r.id
|
|
1764
1754
|
);
|
|
1765
|
-
if (
|
|
1755
|
+
if (l >= 0) {
|
|
1766
1756
|
const i = [...o];
|
|
1767
|
-
return i[
|
|
1757
|
+
return i[l] = r, i;
|
|
1768
1758
|
}
|
|
1769
1759
|
return [...o, r];
|
|
1770
1760
|
});
|
|
1771
1761
|
},
|
|
1772
1762
|
[]
|
|
1773
|
-
),
|
|
1774
|
-
e((o) => o.filter((
|
|
1775
|
-
}, []),
|
|
1763
|
+
), a = $((r) => {
|
|
1764
|
+
e((o) => o.filter((l) => l.id !== r));
|
|
1765
|
+
}, []), n = $(() => {
|
|
1776
1766
|
e([]);
|
|
1777
1767
|
}, []);
|
|
1778
1768
|
return {
|
|
1779
1769
|
registerMessageActions: s,
|
|
1780
|
-
unregisterMessageActions:
|
|
1781
|
-
clearAllMessageActions:
|
|
1770
|
+
unregisterMessageActions: a,
|
|
1771
|
+
clearAllMessageActions: n,
|
|
1782
1772
|
registrations: t
|
|
1783
1773
|
};
|
|
1784
1774
|
}
|
|
1785
|
-
function
|
|
1786
|
-
return e.flatMap((
|
|
1787
|
-
id:
|
|
1788
|
-
label:
|
|
1789
|
-
icon:
|
|
1790
|
-
onClick:
|
|
1791
|
-
tooltip:
|
|
1792
|
-
disabled:
|
|
1793
|
-
pressed:
|
|
1794
|
-
showLabel:
|
|
1775
|
+
function ge(t, e) {
|
|
1776
|
+
return e.flatMap((n) => typeof n.actions == "function" ? n.actions(t) : n.actions).filter((n) => !(n.condition && !n.condition(t))).map((n) => ({
|
|
1777
|
+
id: n.id,
|
|
1778
|
+
label: n.label,
|
|
1779
|
+
icon: n.icon,
|
|
1780
|
+
onClick: n.onClick,
|
|
1781
|
+
tooltip: n.tooltip,
|
|
1782
|
+
disabled: n.disabled || !1,
|
|
1783
|
+
pressed: n.pressed,
|
|
1784
|
+
showLabel: n.showLabel
|
|
1795
1785
|
}));
|
|
1796
1786
|
}
|
|
1797
|
-
const
|
|
1798
|
-
var o,
|
|
1787
|
+
const at = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), z = (t, e = []) => {
|
|
1788
|
+
var o, l;
|
|
1799
1789
|
if (t.parts.some((i) => {
|
|
1800
1790
|
if (i.type === "data") {
|
|
1801
|
-
const
|
|
1802
|
-
return
|
|
1791
|
+
const u = i.data;
|
|
1792
|
+
return u.toolCallId || u.toolId || u.result;
|
|
1803
1793
|
}
|
|
1804
1794
|
return !1;
|
|
1805
1795
|
}))
|
|
1806
1796
|
return null;
|
|
1807
|
-
const
|
|
1808
|
-
var
|
|
1797
|
+
const a = t.parts.map((i) => {
|
|
1798
|
+
var u;
|
|
1809
1799
|
if (i.type === "text")
|
|
1810
1800
|
return {
|
|
1811
|
-
type: ((
|
|
1801
|
+
type: ((u = i.metadata) == null ? void 0 : u.contentType) || "text",
|
|
1812
1802
|
text: i.text
|
|
1813
1803
|
};
|
|
1814
1804
|
if (i.type === "file")
|
|
@@ -1817,55 +1807,55 @@ const nt = (t) => [...t].sort((e, s) => e.timestamp - s.timestamp), z = (t, e =
|
|
|
1817
1807
|
image_url: i.file.uri || `data:${i.file.mimeType};base64,${i.file.bytes}`
|
|
1818
1808
|
};
|
|
1819
1809
|
if (i.type === "data") {
|
|
1820
|
-
const
|
|
1821
|
-
return
|
|
1810
|
+
const g = i.data;
|
|
1811
|
+
return g.component && g.componentProps ? {
|
|
1822
1812
|
type: "component",
|
|
1823
|
-
component:
|
|
1824
|
-
componentProps:
|
|
1813
|
+
component: g.component,
|
|
1814
|
+
componentProps: g.componentProps
|
|
1825
1815
|
} : {
|
|
1826
1816
|
type: "text",
|
|
1827
|
-
text: JSON.stringify(
|
|
1817
|
+
text: JSON.stringify(g)
|
|
1828
1818
|
};
|
|
1829
1819
|
}
|
|
1830
1820
|
return {
|
|
1831
1821
|
type: "text",
|
|
1832
1822
|
text: "[Unsupported content]"
|
|
1833
1823
|
};
|
|
1834
|
-
}),
|
|
1824
|
+
}), n = ((o = t.metadata) == null ? void 0 : o.timestamp) ?? Date.now(), r = {
|
|
1835
1825
|
id: t.messageId,
|
|
1836
1826
|
role: t.role === "agent" ? "agent" : "user",
|
|
1837
|
-
content:
|
|
1838
|
-
timestamp:
|
|
1839
|
-
archived: !!((
|
|
1827
|
+
content: a,
|
|
1828
|
+
timestamp: n,
|
|
1829
|
+
archived: !!((l = t.metadata) != null && l.archived),
|
|
1840
1830
|
showIcon: t.role === "agent",
|
|
1841
1831
|
icon: t.role === "agent" ? "assistant" : void 0
|
|
1842
1832
|
};
|
|
1843
1833
|
if (t.role === "agent" && e.length > 0) {
|
|
1844
|
-
const i =
|
|
1834
|
+
const i = ge(
|
|
1845
1835
|
r,
|
|
1846
1836
|
e
|
|
1847
1837
|
);
|
|
1848
1838
|
i.length > 0 && (r.actions = i);
|
|
1849
1839
|
}
|
|
1850
1840
|
return r;
|
|
1851
|
-
},
|
|
1841
|
+
}, fe = () => ({
|
|
1852
1842
|
getClientContext: () => ({})
|
|
1853
|
-
}),
|
|
1843
|
+
}), me = () => ({
|
|
1854
1844
|
getAvailableTools: async () => [],
|
|
1855
1845
|
executeTool: async () => ({
|
|
1856
1846
|
success: !0,
|
|
1857
1847
|
result: "No tools available"
|
|
1858
1848
|
})
|
|
1859
1849
|
}), pe = (t) => ["agentId", "agentUrl", "sessionId"].every((s) => {
|
|
1860
|
-
const
|
|
1861
|
-
return typeof
|
|
1850
|
+
const a = t[s];
|
|
1851
|
+
return typeof a == "string" && a.trim().length > 0;
|
|
1862
1852
|
});
|
|
1863
1853
|
function Ee(t) {
|
|
1864
1854
|
const e = {
|
|
1865
1855
|
agentId: t.agentId,
|
|
1866
1856
|
agentUrl: t.agentUrl,
|
|
1867
1857
|
sessionId: t.sessionId
|
|
1868
|
-
}, s = pe(e), [
|
|
1858
|
+
}, s = pe(e), [a, n] = yt({
|
|
1869
1859
|
clientMessages: [],
|
|
1870
1860
|
uiMessages: [],
|
|
1871
1861
|
isProcessing: !1,
|
|
@@ -1874,38 +1864,38 @@ function Ee(t) {
|
|
|
1874
1864
|
}), {
|
|
1875
1865
|
registerMessageActions: r,
|
|
1876
1866
|
unregisterMessageActions: o,
|
|
1877
|
-
clearAllMessageActions:
|
|
1867
|
+
clearAllMessageActions: l,
|
|
1878
1868
|
registrations: i
|
|
1879
|
-
} =
|
|
1869
|
+
} = de(), u = Ot(i);
|
|
1880
1870
|
tt(() => {
|
|
1881
|
-
|
|
1871
|
+
u.current = i;
|
|
1882
1872
|
}, [i]), tt(() => {
|
|
1883
1873
|
if (!s)
|
|
1884
1874
|
return;
|
|
1885
1875
|
(async () => {
|
|
1886
1876
|
if (e.sessionId) {
|
|
1887
|
-
const
|
|
1888
|
-
|
|
1877
|
+
const d = st(), w = `${e.agentId}-${e.sessionId}`;
|
|
1878
|
+
d.hasAgent(w) || await d.createAgent(w, {
|
|
1889
1879
|
agentId: e.agentId,
|
|
1890
1880
|
agentUrl: e.agentUrl,
|
|
1891
1881
|
sessionId: e.sessionId,
|
|
1892
|
-
contextProvider: t.contextProvider ||
|
|
1893
|
-
toolProvider: t.toolProvider ||
|
|
1882
|
+
contextProvider: t.contextProvider || fe(),
|
|
1883
|
+
toolProvider: t.toolProvider || me(),
|
|
1894
1884
|
authProvider: t.authProvider,
|
|
1895
1885
|
enableStreaming: t.enableStreaming
|
|
1896
1886
|
});
|
|
1897
|
-
const
|
|
1898
|
-
|
|
1899
|
-
const
|
|
1900
|
-
(
|
|
1901
|
-
|
|
1902
|
-
|
|
1887
|
+
const f = d.getConversationHistory(w);
|
|
1888
|
+
n((y) => {
|
|
1889
|
+
const x = f.map(
|
|
1890
|
+
(I) => z(
|
|
1891
|
+
I,
|
|
1892
|
+
u.current
|
|
1903
1893
|
)
|
|
1904
|
-
).filter((
|
|
1894
|
+
).filter((I) => I !== null);
|
|
1905
1895
|
return {
|
|
1906
|
-
...
|
|
1907
|
-
clientMessages:
|
|
1908
|
-
uiMessages:
|
|
1896
|
+
...y,
|
|
1897
|
+
clientMessages: f,
|
|
1898
|
+
uiMessages: x
|
|
1909
1899
|
};
|
|
1910
1900
|
});
|
|
1911
1901
|
}
|
|
@@ -1920,277 +1910,277 @@ function Ee(t) {
|
|
|
1920
1910
|
t.enableStreaming,
|
|
1921
1911
|
s
|
|
1922
1912
|
]);
|
|
1923
|
-
const
|
|
1924
|
-
async (
|
|
1913
|
+
const g = $(
|
|
1914
|
+
async (c, d) => {
|
|
1925
1915
|
var P;
|
|
1926
1916
|
if (!s)
|
|
1927
1917
|
throw new Error("Invalid agent configuration");
|
|
1928
|
-
const
|
|
1929
|
-
id: `user-${
|
|
1918
|
+
const w = st(), f = `${e.agentId}-${e.sessionId}`, y = Date.now(), x = (d == null ? void 0 : d.type) || "text", I = {
|
|
1919
|
+
id: `user-${y}`,
|
|
1930
1920
|
role: "user",
|
|
1931
|
-
content: [{ type:
|
|
1932
|
-
timestamp:
|
|
1933
|
-
archived: (
|
|
1921
|
+
content: [{ type: x, text: c }],
|
|
1922
|
+
timestamp: y,
|
|
1923
|
+
archived: (d == null ? void 0 : d.archived) ?? !1,
|
|
1934
1924
|
showIcon: !1
|
|
1935
1925
|
};
|
|
1936
|
-
|
|
1926
|
+
n((T) => ({
|
|
1937
1927
|
...T,
|
|
1938
|
-
uiMessages: [...T.uiMessages,
|
|
1928
|
+
uiMessages: [...T.uiMessages, I],
|
|
1939
1929
|
isProcessing: !0,
|
|
1940
1930
|
error: null
|
|
1941
1931
|
}));
|
|
1942
1932
|
try {
|
|
1943
|
-
let T = null,
|
|
1944
|
-
const
|
|
1945
|
-
(
|
|
1946
|
-
...(
|
|
1947
|
-
...(
|
|
1933
|
+
let T = null, b = !1;
|
|
1934
|
+
const k = {};
|
|
1935
|
+
(d != null && d.archived || d != null && d.type) && (k.metadata = {
|
|
1936
|
+
...(d == null ? void 0 : d.archived) && { archived: !0 },
|
|
1937
|
+
...(d == null ? void 0 : d.type) && { contentType: d.type }
|
|
1948
1938
|
});
|
|
1949
|
-
for await (const
|
|
1950
|
-
|
|
1951
|
-
|
|
1952
|
-
|
|
1939
|
+
for await (const M of w.sendMessageStream(
|
|
1940
|
+
f,
|
|
1941
|
+
c,
|
|
1942
|
+
k
|
|
1953
1943
|
)) {
|
|
1954
|
-
if (!
|
|
1944
|
+
if (!M.final && M.text)
|
|
1955
1945
|
if (T)
|
|
1956
|
-
|
|
1957
|
-
...
|
|
1958
|
-
uiMessages:
|
|
1959
|
-
(
|
|
1960
|
-
...
|
|
1946
|
+
n((C) => ({
|
|
1947
|
+
...C,
|
|
1948
|
+
uiMessages: C.uiMessages.map(
|
|
1949
|
+
(A) => A.id === T ? {
|
|
1950
|
+
...A,
|
|
1961
1951
|
content: [
|
|
1962
1952
|
{
|
|
1963
1953
|
type: "text",
|
|
1964
|
-
text:
|
|
1954
|
+
text: M.text
|
|
1965
1955
|
}
|
|
1966
1956
|
]
|
|
1967
|
-
} :
|
|
1957
|
+
} : A
|
|
1968
1958
|
)
|
|
1969
1959
|
}));
|
|
1970
1960
|
else {
|
|
1971
1961
|
T = `agent-streaming-${Date.now()}`;
|
|
1972
|
-
const
|
|
1962
|
+
const C = {
|
|
1973
1963
|
id: T,
|
|
1974
1964
|
role: "agent",
|
|
1975
1965
|
content: [
|
|
1976
|
-
{ type: "text", text:
|
|
1966
|
+
{ type: "text", text: M.text }
|
|
1977
1967
|
],
|
|
1978
1968
|
timestamp: Date.now(),
|
|
1979
1969
|
archived: !1,
|
|
1980
1970
|
showIcon: !0,
|
|
1981
1971
|
icon: "assistant"
|
|
1982
1972
|
};
|
|
1983
|
-
|
|
1984
|
-
...
|
|
1973
|
+
n((A) => ({
|
|
1974
|
+
...A,
|
|
1985
1975
|
uiMessages: [
|
|
1986
|
-
...
|
|
1987
|
-
|
|
1976
|
+
...A.uiMessages,
|
|
1977
|
+
C
|
|
1988
1978
|
]
|
|
1989
1979
|
}));
|
|
1990
1980
|
}
|
|
1991
|
-
if (
|
|
1992
|
-
|
|
1993
|
-
const
|
|
1994
|
-
|
|
1995
|
-
|
|
1981
|
+
if (M.final && ((P = M.status) != null && P.message) && T) {
|
|
1982
|
+
b = !0;
|
|
1983
|
+
const C = T, A = z(
|
|
1984
|
+
M.status.message,
|
|
1985
|
+
u.current
|
|
1996
1986
|
);
|
|
1997
|
-
|
|
1998
|
-
const
|
|
1999
|
-
(
|
|
2000
|
-
), E =
|
|
2001
|
-
|
|
1987
|
+
A && n((q) => {
|
|
1988
|
+
const _ = q.uiMessages.map(
|
|
1989
|
+
(R) => R.id === C ? A : R
|
|
1990
|
+
), E = w.getConversationHistory(
|
|
1991
|
+
f
|
|
2002
1992
|
);
|
|
2003
1993
|
return {
|
|
2004
|
-
...
|
|
1994
|
+
...q,
|
|
2005
1995
|
clientMessages: E,
|
|
2006
|
-
uiMessages:
|
|
1996
|
+
uiMessages: _,
|
|
2007
1997
|
isProcessing: !1
|
|
2008
1998
|
};
|
|
2009
1999
|
}), T = null;
|
|
2010
2000
|
}
|
|
2011
2001
|
}
|
|
2012
|
-
if (!
|
|
2013
|
-
const
|
|
2014
|
-
|
|
2015
|
-
let
|
|
2016
|
-
T && (
|
|
2002
|
+
if (!b) {
|
|
2003
|
+
const M = w.getConversationHistory(f);
|
|
2004
|
+
n((C) => {
|
|
2005
|
+
let A = C.uiMessages;
|
|
2006
|
+
T && (A = C.uiMessages.filter(
|
|
2017
2007
|
(O) => O.id !== T
|
|
2018
2008
|
));
|
|
2019
|
-
const
|
|
2009
|
+
const q = M.map(
|
|
2020
2010
|
(O) => z(
|
|
2021
2011
|
O,
|
|
2022
|
-
|
|
2012
|
+
u.current
|
|
2023
2013
|
)
|
|
2024
2014
|
).filter(
|
|
2025
2015
|
(O) => O !== null
|
|
2026
|
-
),
|
|
2027
|
-
|
|
2028
|
-
), E =
|
|
2016
|
+
), _ = new Set(
|
|
2017
|
+
M.map((O) => O.messageId)
|
|
2018
|
+
), E = A.filter(
|
|
2029
2019
|
(O) => {
|
|
2030
2020
|
var J;
|
|
2031
|
-
return !
|
|
2021
|
+
return !_.has(O.id) && ((J = O.content[0]) == null ? void 0 : J.type) === "component";
|
|
2032
2022
|
}
|
|
2033
|
-
),
|
|
2034
|
-
...
|
|
2023
|
+
), R = at([
|
|
2024
|
+
...q,
|
|
2035
2025
|
...E
|
|
2036
2026
|
]);
|
|
2037
2027
|
return {
|
|
2038
|
-
...
|
|
2039
|
-
clientMessages:
|
|
2040
|
-
uiMessages:
|
|
2028
|
+
...C,
|
|
2029
|
+
clientMessages: M,
|
|
2030
|
+
uiMessages: R,
|
|
2041
2031
|
isProcessing: !1
|
|
2042
2032
|
};
|
|
2043
2033
|
});
|
|
2044
2034
|
}
|
|
2045
2035
|
} catch (T) {
|
|
2046
2036
|
if (T instanceof Error && T.name === "AbortError") {
|
|
2047
|
-
|
|
2048
|
-
...
|
|
2037
|
+
v("Request was aborted by user"), n((k) => ({
|
|
2038
|
+
...k,
|
|
2049
2039
|
isProcessing: !1,
|
|
2050
2040
|
error: null
|
|
2051
2041
|
// Don't show error for user-initiated abort
|
|
2052
2042
|
}));
|
|
2053
2043
|
return;
|
|
2054
2044
|
}
|
|
2055
|
-
const
|
|
2056
|
-
throw
|
|
2057
|
-
...
|
|
2045
|
+
const b = T instanceof Error ? T.message : "Failed to send message";
|
|
2046
|
+
throw n((k) => ({
|
|
2047
|
+
...k,
|
|
2058
2048
|
isProcessing: !1,
|
|
2059
|
-
error:
|
|
2049
|
+
error: b
|
|
2060
2050
|
})), T;
|
|
2061
2051
|
}
|
|
2062
2052
|
},
|
|
2063
2053
|
[e.agentId, e.sessionId, s]
|
|
2064
|
-
),
|
|
2065
|
-
|
|
2066
|
-
...
|
|
2067
|
-
uiMessages:
|
|
2054
|
+
), h = $((c) => {
|
|
2055
|
+
n((d) => ({
|
|
2056
|
+
...d,
|
|
2057
|
+
uiMessages: at([...d.uiMessages, c])
|
|
2068
2058
|
}));
|
|
2069
|
-
}, []),
|
|
2070
|
-
|
|
2071
|
-
...
|
|
2072
|
-
suggestions:
|
|
2059
|
+
}, []), m = $((c) => {
|
|
2060
|
+
n((d) => ({
|
|
2061
|
+
...d,
|
|
2062
|
+
suggestions: c
|
|
2073
2063
|
}));
|
|
2074
|
-
}, []),
|
|
2075
|
-
|
|
2076
|
-
...
|
|
2064
|
+
}, []), p = $(() => {
|
|
2065
|
+
n((c) => ({
|
|
2066
|
+
...c,
|
|
2077
2067
|
suggestions: []
|
|
2078
2068
|
}));
|
|
2079
2069
|
}, []);
|
|
2080
2070
|
tt(() => {
|
|
2081
|
-
|
|
2082
|
-
if (
|
|
2083
|
-
return
|
|
2084
|
-
const
|
|
2085
|
-
(
|
|
2086
|
-
).filter((
|
|
2087
|
-
|
|
2088
|
-
),
|
|
2089
|
-
(
|
|
2090
|
-
var
|
|
2091
|
-
return !
|
|
2071
|
+
n((c) => {
|
|
2072
|
+
if (c.clientMessages.length === 0)
|
|
2073
|
+
return c;
|
|
2074
|
+
const d = c.clientMessages.map(
|
|
2075
|
+
(y) => z(y, u.current)
|
|
2076
|
+
).filter((y) => y !== null), w = new Set(
|
|
2077
|
+
c.clientMessages.map((y) => y.messageId)
|
|
2078
|
+
), f = c.uiMessages.filter(
|
|
2079
|
+
(y) => {
|
|
2080
|
+
var x;
|
|
2081
|
+
return !w.has(y.id) && ((x = y.content[0]) == null ? void 0 : x.type) === "component";
|
|
2092
2082
|
}
|
|
2093
2083
|
);
|
|
2094
2084
|
return {
|
|
2095
|
-
...
|
|
2096
|
-
uiMessages:
|
|
2097
|
-
...
|
|
2098
|
-
...
|
|
2085
|
+
...c,
|
|
2086
|
+
uiMessages: at([
|
|
2087
|
+
...d,
|
|
2088
|
+
...f
|
|
2099
2089
|
])
|
|
2100
2090
|
};
|
|
2101
2091
|
});
|
|
2102
2092
|
}, [i]);
|
|
2103
|
-
const
|
|
2093
|
+
const S = $(() => {
|
|
2104
2094
|
if (!s)
|
|
2105
2095
|
return;
|
|
2106
|
-
const
|
|
2107
|
-
|
|
2096
|
+
const c = st(), d = `${e.agentId}-${e.sessionId}`;
|
|
2097
|
+
c.abortCurrentRequest(d);
|
|
2108
2098
|
}, [e.agentId, e.sessionId, s]);
|
|
2109
2099
|
return {
|
|
2110
2100
|
// AgentUI props
|
|
2111
|
-
messages:
|
|
2112
|
-
isProcessing:
|
|
2113
|
-
error:
|
|
2114
|
-
onSubmit:
|
|
2115
|
-
suggestions:
|
|
2101
|
+
messages: a.uiMessages,
|
|
2102
|
+
isProcessing: a.isProcessing,
|
|
2103
|
+
error: a.error,
|
|
2104
|
+
onSubmit: g,
|
|
2105
|
+
suggestions: a.suggestions,
|
|
2116
2106
|
// UI management methods
|
|
2117
|
-
registerSuggestions:
|
|
2118
|
-
clearSuggestions:
|
|
2107
|
+
registerSuggestions: m,
|
|
2108
|
+
clearSuggestions: p,
|
|
2119
2109
|
// Message actions methods
|
|
2120
2110
|
registerMessageActions: r,
|
|
2121
2111
|
unregisterMessageActions: o,
|
|
2122
|
-
clearAllMessageActions:
|
|
2112
|
+
clearAllMessageActions: l,
|
|
2123
2113
|
// Tool integration
|
|
2124
|
-
addMessage:
|
|
2114
|
+
addMessage: h,
|
|
2125
2115
|
// Abort control
|
|
2126
|
-
abortCurrentRequest:
|
|
2116
|
+
abortCurrentRequest: S
|
|
2127
2117
|
};
|
|
2128
2118
|
}
|
|
2129
|
-
var
|
|
2130
|
-
const
|
|
2131
|
-
function
|
|
2132
|
-
var s;
|
|
2133
|
-
return window.JP_CONNECTION_INITIAL_STATE ? !1 : !!((
|
|
2119
|
+
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 || {});
|
|
2120
|
+
const pt = "jetpack-ai-jwt-token", ye = 30 * 60 * 1e3;
|
|
2121
|
+
function we() {
|
|
2122
|
+
var s, a, n;
|
|
2123
|
+
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
2124
|
}
|
|
2135
|
-
async function
|
|
2136
|
-
var i,
|
|
2137
|
-
const s = localStorage.getItem(
|
|
2138
|
-
let
|
|
2125
|
+
async function Ie(t, e = !0) {
|
|
2126
|
+
var i, u;
|
|
2127
|
+
const s = localStorage.getItem(pt);
|
|
2128
|
+
let a;
|
|
2139
2129
|
if (s)
|
|
2140
2130
|
try {
|
|
2141
|
-
|
|
2142
|
-
} catch (
|
|
2143
|
-
|
|
2131
|
+
a = JSON.parse(s);
|
|
2132
|
+
} catch (g) {
|
|
2133
|
+
v("Invalid cached Jetpack token: %O", g);
|
|
2144
2134
|
}
|
|
2145
|
-
if (
|
|
2146
|
-
return
|
|
2147
|
-
const
|
|
2135
|
+
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && e)
|
|
2136
|
+
return a;
|
|
2137
|
+
const n = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (u = window.Jetpack_Editor_Initial_State) == null ? void 0 : u.wpcomBlogId;
|
|
2148
2138
|
let o = {
|
|
2149
2139
|
token: "",
|
|
2150
2140
|
blog_id: ""
|
|
2151
2141
|
};
|
|
2152
2142
|
try {
|
|
2153
|
-
|
|
2143
|
+
we() ? o = await dt({
|
|
2154
2144
|
path: "/wpcom/v2/sites/" + r + "/jetpack-openai-query/jwt",
|
|
2155
2145
|
method: "POST"
|
|
2156
|
-
}) : o = await
|
|
2146
|
+
}) : o = await dt({
|
|
2157
2147
|
path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
|
|
2158
2148
|
credentials: "same-origin",
|
|
2159
2149
|
headers: {
|
|
2160
|
-
"X-WP-Nonce":
|
|
2150
|
+
"X-WP-Nonce": n || ""
|
|
2161
2151
|
},
|
|
2162
2152
|
method: "POST"
|
|
2163
2153
|
});
|
|
2164
|
-
} catch (
|
|
2165
|
-
throw
|
|
2154
|
+
} catch (g) {
|
|
2155
|
+
throw v("Failed to fetch Jetpack token: %O", g), new Error(t(g));
|
|
2166
2156
|
}
|
|
2167
2157
|
if (!(o != null && o.token))
|
|
2168
2158
|
throw new Error(
|
|
2169
2159
|
"Authentication failed. Please ensure Jetpack is properly connected and try again."
|
|
2170
2160
|
);
|
|
2171
|
-
const
|
|
2161
|
+
const l = {
|
|
2172
2162
|
token: o.token,
|
|
2173
2163
|
blogId: o.blog_id || "",
|
|
2174
|
-
expire: Date.now() +
|
|
2164
|
+
expire: Date.now() + ye
|
|
2175
2165
|
};
|
|
2176
2166
|
try {
|
|
2177
|
-
localStorage.setItem(
|
|
2178
|
-
} catch (
|
|
2179
|
-
|
|
2167
|
+
localStorage.setItem(pt, JSON.stringify(l));
|
|
2168
|
+
} catch (g) {
|
|
2169
|
+
v("Error storing token in localStorage: %O", g);
|
|
2180
2170
|
}
|
|
2181
|
-
return
|
|
2171
|
+
return l;
|
|
2182
2172
|
}
|
|
2183
2173
|
const Oe = (t) => async () => {
|
|
2184
2174
|
const e = {};
|
|
2185
2175
|
try {
|
|
2186
|
-
const s = await
|
|
2176
|
+
const s = await Ie(t);
|
|
2187
2177
|
s != null && s.token && (e.Authorization = `${s.token}`);
|
|
2188
2178
|
} catch (s) {
|
|
2189
|
-
throw
|
|
2179
|
+
throw v("Failed to get Jetpack token for auth: %O", s), s;
|
|
2190
2180
|
}
|
|
2191
2181
|
return e;
|
|
2192
2182
|
};
|
|
2193
|
-
function
|
|
2183
|
+
function Te(t) {
|
|
2194
2184
|
const e = {
|
|
2195
2185
|
type: "object",
|
|
2196
2186
|
properties: {}
|
|
@@ -2206,21 +2196,21 @@ function Ce(t) {
|
|
|
2206
2196
|
};
|
|
2207
2197
|
}
|
|
2208
2198
|
function _e(t) {
|
|
2209
|
-
return t.map(
|
|
2199
|
+
return t.map(Te);
|
|
2210
2200
|
}
|
|
2211
2201
|
function Pe(t) {
|
|
2212
2202
|
return (t == null ? void 0 : t._source) === "wordpress-ability";
|
|
2213
2203
|
}
|
|
2214
2204
|
export {
|
|
2215
|
-
|
|
2205
|
+
he as A2AErrorCodes,
|
|
2216
2206
|
_e as convertAbilitiesToTools,
|
|
2217
|
-
|
|
2207
|
+
Te as convertAbilityToTool,
|
|
2218
2208
|
Re as createAbortController,
|
|
2219
|
-
|
|
2209
|
+
Zt as createClient,
|
|
2220
2210
|
Oe as createJetpackAuthProvider,
|
|
2221
|
-
|
|
2222
|
-
|
|
2223
|
-
|
|
2211
|
+
_t as createRequestId,
|
|
2212
|
+
Pt as createTaskId,
|
|
2213
|
+
nt as createTextMessage,
|
|
2224
2214
|
D as extractTextFromMessage,
|
|
2225
2215
|
F as extractToolCallsFromMessage,
|
|
2226
2216
|
st as getAgentManager,
|
|
@@ -2230,5 +2220,5 @@ export {
|
|
|
2230
2220
|
Ae as useClientContext,
|
|
2231
2221
|
Se as useClientTools,
|
|
2232
2222
|
ke as useClientToolsWithAbilities,
|
|
2233
|
-
|
|
2223
|
+
de as useMessageActions
|
|
2234
2224
|
};
|