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