@automattic/agenttic-client 0.1.69 → 0.1.70
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +902 -889
- package/dist/react/useAgentChat.d.ts +2 -1
- package/dist/react/useAgentChat.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,49 +1,49 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import { l as
|
|
6
|
-
import
|
|
7
|
-
import { m as
|
|
8
|
-
function
|
|
9
|
-
return
|
|
1
|
+
var Ge = Object.defineProperty;
|
|
2
|
+
var Xe = (e, s, t) => s in e ? Ge(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
|
+
var de = (e, s, t) => Xe(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
+
import Ye, { useMemo as Ee, useCallback as j, useState as Ne, useRef as re, useEffect as te } from "react";
|
|
5
|
+
import { l as A, f as Ue, a as V } from "./logger-aKHbTlwk.js";
|
|
6
|
+
import Ce from "@wordpress/api-fetch";
|
|
7
|
+
import { m as Ms, l as Ts, i as As, j as vs, k as Ss, h as Cs, f as xs, o as bs, q as Rs, s as ks, g as Ps, n as _s, a as Es, d as Ns, p as Us, e as Hs, b as Os, c as $s, r as qs, u as Fs } from "./useAgentsApiChat-BK33Zwmv.js";
|
|
8
|
+
function rs(e) {
|
|
9
|
+
return Ee(() => e ? {
|
|
10
10
|
getClientContext: () => {
|
|
11
11
|
try {
|
|
12
12
|
return e() || {};
|
|
13
13
|
} catch (a) {
|
|
14
|
-
return
|
|
14
|
+
return A("Error getting client context: %O", a), {};
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
} : void 0, [e]);
|
|
18
18
|
}
|
|
19
|
-
function
|
|
19
|
+
function ye({
|
|
20
20
|
getClientTools: e,
|
|
21
21
|
executeTool: s,
|
|
22
22
|
getAbilities: t
|
|
23
23
|
}) {
|
|
24
|
-
const a =
|
|
24
|
+
const a = j(async () => {
|
|
25
25
|
const r = [];
|
|
26
26
|
if (e)
|
|
27
27
|
try {
|
|
28
28
|
const l = await e();
|
|
29
29
|
r.push(...l);
|
|
30
30
|
} catch (l) {
|
|
31
|
-
|
|
31
|
+
A("Error getting available tools: %O", l);
|
|
32
32
|
}
|
|
33
33
|
return r;
|
|
34
|
-
}, [e]), n =
|
|
34
|
+
}, [e]), n = j(
|
|
35
35
|
async (r, l) => {
|
|
36
36
|
if (!s)
|
|
37
37
|
throw new Error("No executeTool callback provided");
|
|
38
38
|
try {
|
|
39
39
|
return await s(r, l);
|
|
40
40
|
} catch (i) {
|
|
41
|
-
throw
|
|
41
|
+
throw A("Error executing tool %s: %O", r, i), i;
|
|
42
42
|
}
|
|
43
43
|
},
|
|
44
44
|
[s]
|
|
45
45
|
);
|
|
46
|
-
return
|
|
46
|
+
return Ee(() => {
|
|
47
47
|
if (!e && !t)
|
|
48
48
|
return;
|
|
49
49
|
const r = {};
|
|
@@ -56,21 +56,21 @@ function he({
|
|
|
56
56
|
t
|
|
57
57
|
]);
|
|
58
58
|
}
|
|
59
|
-
function
|
|
60
|
-
return
|
|
59
|
+
function os(e, s) {
|
|
60
|
+
return ye({
|
|
61
61
|
getClientTools: e,
|
|
62
62
|
executeTool: s,
|
|
63
63
|
getAbilities: void 0
|
|
64
64
|
});
|
|
65
65
|
}
|
|
66
|
-
function
|
|
67
|
-
return
|
|
66
|
+
function is(e) {
|
|
67
|
+
return ye({
|
|
68
68
|
getClientTools: void 0,
|
|
69
69
|
executeTool: void 0,
|
|
70
70
|
getAbilities: e
|
|
71
71
|
});
|
|
72
72
|
}
|
|
73
|
-
function
|
|
73
|
+
function ls(e) {
|
|
74
74
|
const { getClientTools: s, executeTool: t, getAbilities: a } = e;
|
|
75
75
|
if (!s && !a)
|
|
76
76
|
throw new Error(
|
|
@@ -80,13 +80,13 @@ function is(e) {
|
|
|
80
80
|
throw new Error(
|
|
81
81
|
"executeTool is required when providing getClientTools."
|
|
82
82
|
);
|
|
83
|
-
return
|
|
83
|
+
return ye({
|
|
84
84
|
getClientTools: s,
|
|
85
85
|
executeTool: t,
|
|
86
86
|
getAbilities: a
|
|
87
87
|
});
|
|
88
88
|
}
|
|
89
|
-
function
|
|
89
|
+
function Ie() {
|
|
90
90
|
const e = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
91
91
|
let s = "";
|
|
92
92
|
for (let t = 0; t < 8; t++)
|
|
@@ -94,13 +94,13 @@ function ye() {
|
|
|
94
94
|
return s;
|
|
95
95
|
}
|
|
96
96
|
function q() {
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
function Ye() {
|
|
100
|
-
return `req-${ye()}`;
|
|
97
|
+
return Ie();
|
|
101
98
|
}
|
|
102
99
|
function Ze() {
|
|
103
|
-
return `
|
|
100
|
+
return `req-${Ie()}`;
|
|
101
|
+
}
|
|
102
|
+
function et() {
|
|
103
|
+
return `task-${Ie()}`;
|
|
104
104
|
}
|
|
105
105
|
function He(e, s) {
|
|
106
106
|
return {
|
|
@@ -109,22 +109,22 @@ function He(e, s) {
|
|
|
109
109
|
...s && { metadata: s }
|
|
110
110
|
};
|
|
111
111
|
}
|
|
112
|
-
function
|
|
112
|
+
function tt(e, s = "message/send", t = !1) {
|
|
113
113
|
const a = {
|
|
114
114
|
jsonrpc: "2.0",
|
|
115
|
-
id:
|
|
115
|
+
id: Ze(),
|
|
116
116
|
method: s,
|
|
117
117
|
params: {
|
|
118
|
-
id: e.id ||
|
|
118
|
+
id: e.id || et(),
|
|
119
119
|
...e
|
|
120
120
|
}
|
|
121
121
|
};
|
|
122
122
|
return t && s === "message/stream" && (a.tokenStreaming = !0), a;
|
|
123
123
|
}
|
|
124
|
-
function
|
|
124
|
+
function J(e) {
|
|
125
125
|
return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
|
|
126
126
|
}
|
|
127
|
-
function
|
|
127
|
+
function xe(e) {
|
|
128
128
|
if (!e || !e.parts || !Array.isArray(e.parts))
|
|
129
129
|
return;
|
|
130
130
|
const s = e.parts.find((t) => t.type === "progress" ? !0 : t.type === "data" ? "summary" in t.data && typeof t.data.summary == "string" : !1);
|
|
@@ -134,7 +134,7 @@ function Ce(e) {
|
|
|
134
134
|
phase: s.data.phase
|
|
135
135
|
};
|
|
136
136
|
}
|
|
137
|
-
function
|
|
137
|
+
function st(e) {
|
|
138
138
|
return {
|
|
139
139
|
type: "data",
|
|
140
140
|
data: {
|
|
@@ -146,7 +146,7 @@ function tt(e) {
|
|
|
146
146
|
metadata: {}
|
|
147
147
|
};
|
|
148
148
|
}
|
|
149
|
-
function
|
|
149
|
+
function at(e) {
|
|
150
150
|
return {
|
|
151
151
|
type: "data",
|
|
152
152
|
data: {
|
|
@@ -161,12 +161,12 @@ function st(e) {
|
|
|
161
161
|
metadata: {}
|
|
162
162
|
};
|
|
163
163
|
}
|
|
164
|
-
function
|
|
164
|
+
function Q(e) {
|
|
165
165
|
return !e || !e.parts || !Array.isArray(e.parts) ? [] : e.parts.filter(
|
|
166
166
|
(s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
|
|
167
167
|
);
|
|
168
168
|
}
|
|
169
|
-
function
|
|
169
|
+
function z(e, s, t, a) {
|
|
170
170
|
return {
|
|
171
171
|
type: "data",
|
|
172
172
|
data: {
|
|
@@ -177,7 +177,7 @@ function B(e, s, t, a) {
|
|
|
177
177
|
metadata: a ? { error: a } : void 0
|
|
178
178
|
};
|
|
179
179
|
}
|
|
180
|
-
function
|
|
180
|
+
function nt(e) {
|
|
181
181
|
return {
|
|
182
182
|
type: "data",
|
|
183
183
|
data: {
|
|
@@ -186,7 +186,7 @@ function at(e) {
|
|
|
186
186
|
metadata: {}
|
|
187
187
|
};
|
|
188
188
|
}
|
|
189
|
-
function
|
|
189
|
+
function pe(e, s) {
|
|
190
190
|
const { contentType: t, ...a } = s || {};
|
|
191
191
|
return {
|
|
192
192
|
role: "user",
|
|
@@ -199,7 +199,7 @@ function me(e, s) {
|
|
|
199
199
|
}
|
|
200
200
|
};
|
|
201
201
|
}
|
|
202
|
-
function
|
|
202
|
+
function Z(e) {
|
|
203
203
|
return {
|
|
204
204
|
role: "agent",
|
|
205
205
|
parts: [He(e)],
|
|
@@ -210,7 +210,7 @@ function Y(e) {
|
|
|
210
210
|
}
|
|
211
211
|
};
|
|
212
212
|
}
|
|
213
|
-
function
|
|
213
|
+
function we(e) {
|
|
214
214
|
return e && typeof e == "object" && "result" in e ? {
|
|
215
215
|
result: e.result,
|
|
216
216
|
returnToAgent: e.returnToAgent !== !1,
|
|
@@ -222,7 +222,7 @@ function Ie(e) {
|
|
|
222
222
|
returnToAgent: !0
|
|
223
223
|
};
|
|
224
224
|
}
|
|
225
|
-
function
|
|
225
|
+
function ie(e, s = []) {
|
|
226
226
|
return {
|
|
227
227
|
role: "user",
|
|
228
228
|
kind: "message",
|
|
@@ -233,10 +233,10 @@ function re(e, s = []) {
|
|
|
233
233
|
}
|
|
234
234
|
};
|
|
235
235
|
}
|
|
236
|
-
function
|
|
236
|
+
function cs() {
|
|
237
237
|
return new AbortController();
|
|
238
238
|
}
|
|
239
|
-
async function
|
|
239
|
+
async function rt(e, s) {
|
|
240
240
|
if (!s)
|
|
241
241
|
return e;
|
|
242
242
|
try {
|
|
@@ -244,14 +244,14 @@ async function nt(e, s) {
|
|
|
244
244
|
if (s.getAvailableTools) {
|
|
245
245
|
const a = await s.getAvailableTools();
|
|
246
246
|
if (a.length > 0) {
|
|
247
|
-
const n = a.map(
|
|
247
|
+
const n = a.map(st);
|
|
248
248
|
t.push(...n);
|
|
249
249
|
}
|
|
250
250
|
}
|
|
251
251
|
if (s.getAbilities) {
|
|
252
252
|
const a = await s.getAbilities();
|
|
253
253
|
if (a.length > 0) {
|
|
254
|
-
const n = a.map(
|
|
254
|
+
const n = a.map(at);
|
|
255
255
|
t.push(...n);
|
|
256
256
|
}
|
|
257
257
|
}
|
|
@@ -260,38 +260,38 @@ async function nt(e, s) {
|
|
|
260
260
|
parts: [...e.parts, ...t]
|
|
261
261
|
};
|
|
262
262
|
} catch (t) {
|
|
263
|
-
return
|
|
263
|
+
return A("Warning: Failed to get tools: %s", t), e;
|
|
264
264
|
}
|
|
265
265
|
}
|
|
266
|
-
function
|
|
266
|
+
function ot(e, s) {
|
|
267
267
|
if (!s)
|
|
268
268
|
return e;
|
|
269
269
|
try {
|
|
270
270
|
const t = s.getClientContext();
|
|
271
271
|
if (!t || Object.keys(t).length === 0)
|
|
272
272
|
return e;
|
|
273
|
-
const a =
|
|
273
|
+
const a = nt(t);
|
|
274
274
|
return {
|
|
275
275
|
...e,
|
|
276
276
|
parts: [...e.parts, a]
|
|
277
277
|
};
|
|
278
278
|
} catch (t) {
|
|
279
|
-
return
|
|
279
|
+
return A("Warning: Failed to get context: %s", t), e;
|
|
280
280
|
}
|
|
281
281
|
}
|
|
282
|
-
async function
|
|
283
|
-
let a = await
|
|
282
|
+
async function it(e, s, t) {
|
|
283
|
+
let a = await rt(
|
|
284
284
|
e,
|
|
285
285
|
s
|
|
286
286
|
);
|
|
287
|
-
a =
|
|
287
|
+
a = ot(
|
|
288
288
|
a,
|
|
289
289
|
t
|
|
290
290
|
);
|
|
291
291
|
const { metadata: n, ...o } = a;
|
|
292
292
|
return o;
|
|
293
293
|
}
|
|
294
|
-
function
|
|
294
|
+
function lt(e, s = "") {
|
|
295
295
|
const t = [], a = s + e;
|
|
296
296
|
let n = "", o = 0, r = 0;
|
|
297
297
|
for (; r < a.length; ) {
|
|
@@ -309,7 +309,7 @@ function it(e, s = "") {
|
|
|
309
309
|
try {
|
|
310
310
|
t.push(JSON.parse(n)), o = i === -1 ? a.length : i + 1;
|
|
311
311
|
} catch (c) {
|
|
312
|
-
|
|
312
|
+
A("Failed to parse SSE event: %o", c), A("Problematic payload: %s", n);
|
|
313
313
|
}
|
|
314
314
|
n = "";
|
|
315
315
|
}
|
|
@@ -318,34 +318,34 @@ function it(e, s = "") {
|
|
|
318
318
|
const l = a.substring(o);
|
|
319
319
|
return { events: t, nextBuffer: l };
|
|
320
320
|
}
|
|
321
|
-
async function*
|
|
322
|
-
var u, c,
|
|
321
|
+
async function* ct(e, s = {}) {
|
|
322
|
+
var u, c, m;
|
|
323
323
|
const { supportDeltas: t = !1 } = s, a = e.getReader(), n = new TextDecoder();
|
|
324
324
|
let o = "";
|
|
325
|
-
const r = new
|
|
325
|
+
const r = new dt();
|
|
326
326
|
let l = null, i = null;
|
|
327
327
|
try {
|
|
328
328
|
for (; ; ) {
|
|
329
|
-
const { done:
|
|
330
|
-
if (
|
|
329
|
+
const { done: f, value: M } = await a.read();
|
|
330
|
+
if (f)
|
|
331
331
|
break;
|
|
332
|
-
const
|
|
332
|
+
const g = n.decode(M, { stream: !0 }), { events: h, nextBuffer: I } = lt(g, o);
|
|
333
333
|
if (h && Array.isArray(h))
|
|
334
|
-
for (let
|
|
335
|
-
const y = h[
|
|
336
|
-
if (
|
|
337
|
-
requestAnimationFrame(() =>
|
|
334
|
+
for (let v = 0; v < h.length; v++) {
|
|
335
|
+
const y = h[v];
|
|
336
|
+
if (v > 0 && y.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((x) => {
|
|
337
|
+
requestAnimationFrame(() => x(void 0));
|
|
338
338
|
}), y.error)
|
|
339
339
|
throw new Error(
|
|
340
340
|
`Streaming error: ${y.error.message}`
|
|
341
341
|
);
|
|
342
342
|
if (t && y.method === "message/delta" && ((u = y.params) != null && u.delta)) {
|
|
343
|
-
const
|
|
343
|
+
const x = y.params.delta;
|
|
344
344
|
try {
|
|
345
|
-
let
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
),
|
|
345
|
+
let b = !1;
|
|
346
|
+
ut(x) ? (r.processToolCallDelta(x), b = !0) : x.deltaType === "content" && (r.processContentDelta(
|
|
347
|
+
x.content
|
|
348
|
+
), b = !0), b && (!l && y.params.id && (l = y.params.id), l && (yield {
|
|
349
349
|
id: l,
|
|
350
350
|
status: {
|
|
351
351
|
state: "working",
|
|
@@ -355,38 +355,38 @@ async function* lt(e, s = {}) {
|
|
|
355
355
|
text: r.getTextContent(),
|
|
356
356
|
kind: "delta"
|
|
357
357
|
}));
|
|
358
|
-
} catch (
|
|
359
|
-
|
|
358
|
+
} catch (b) {
|
|
359
|
+
A("Failed to process delta: %o", b);
|
|
360
360
|
}
|
|
361
361
|
} else if (y.result && y.result.status) {
|
|
362
362
|
l = y.result.id, i = y.result.status, (r.getTextContent() || r.getCurrentMessage().parts.length > 0) && r.reset();
|
|
363
|
-
const
|
|
363
|
+
const x = ((c = y.result.status) == null ? void 0 : c.message) || {
|
|
364
364
|
role: "agent",
|
|
365
365
|
parts: []
|
|
366
|
-
},
|
|
366
|
+
}, b = xe(x);
|
|
367
367
|
yield {
|
|
368
368
|
id: y.result.id,
|
|
369
369
|
sessionId: y.result.sessionId,
|
|
370
370
|
status: y.result.status,
|
|
371
371
|
final: y.result.status.state === "completed" || y.result.status.state === "failed" || y.result.status.state === "canceled",
|
|
372
|
-
text:
|
|
373
|
-
progressMessage:
|
|
374
|
-
progressPhase:
|
|
372
|
+
text: J(x),
|
|
373
|
+
progressMessage: b == null ? void 0 : b.summary,
|
|
374
|
+
progressPhase: b == null ? void 0 : b.phase,
|
|
375
375
|
kind: "status"
|
|
376
376
|
};
|
|
377
377
|
} else if (y.id && y.result && (l = y.result.id, y.result.status)) {
|
|
378
|
-
const
|
|
378
|
+
const x = ((m = y.result.status) == null ? void 0 : m.message) || {
|
|
379
379
|
role: "agent",
|
|
380
380
|
parts: []
|
|
381
|
-
},
|
|
381
|
+
}, b = xe(x);
|
|
382
382
|
yield {
|
|
383
383
|
id: y.result.id,
|
|
384
384
|
sessionId: y.result.sessionId,
|
|
385
385
|
status: y.result.status,
|
|
386
386
|
final: y.result.status.state === "completed" || y.result.status.state === "failed" || y.result.status.state === "canceled",
|
|
387
|
-
text:
|
|
388
|
-
progressMessage:
|
|
389
|
-
progressPhase:
|
|
387
|
+
text: J(x),
|
|
388
|
+
progressMessage: b == null ? void 0 : b.summary,
|
|
389
|
+
progressPhase: b == null ? void 0 : b.phase,
|
|
390
390
|
kind: "status"
|
|
391
391
|
};
|
|
392
392
|
}
|
|
@@ -397,13 +397,13 @@ async function* lt(e, s = {}) {
|
|
|
397
397
|
a.releaseLock();
|
|
398
398
|
}
|
|
399
399
|
}
|
|
400
|
-
function
|
|
400
|
+
function ut(e) {
|
|
401
401
|
return e.deltaType === "tool_argument" || e.deltaType === "tool_name";
|
|
402
402
|
}
|
|
403
|
-
class
|
|
403
|
+
class dt {
|
|
404
404
|
constructor() {
|
|
405
|
-
|
|
406
|
-
|
|
405
|
+
de(this, "textContent", "");
|
|
406
|
+
de(this, "toolCalls", /* @__PURE__ */ new Map());
|
|
407
407
|
}
|
|
408
408
|
/**
|
|
409
409
|
* Process a simple content delta (server's actual format)
|
|
@@ -503,13 +503,13 @@ class ut {
|
|
|
503
503
|
}
|
|
504
504
|
}
|
|
505
505
|
function Oe(e, s, t = "request") {
|
|
506
|
-
throw clearTimeout(s),
|
|
506
|
+
throw clearTimeout(s), A("%s failed with error: %O", t, e), e instanceof Error && (A("Error message: %s", e.message), A("Error stack: %s", e.stack)), e;
|
|
507
507
|
}
|
|
508
|
-
function
|
|
508
|
+
function $e(e, s = "request") {
|
|
509
509
|
if (!e.ok)
|
|
510
510
|
throw new Error(`HTTP error! status: ${e.status}`);
|
|
511
511
|
}
|
|
512
|
-
function
|
|
512
|
+
function gt(e, s = "request") {
|
|
513
513
|
if (e.error)
|
|
514
514
|
throw new Error(
|
|
515
515
|
`Protocol ${s} error: ${e.error.message}`
|
|
@@ -518,24 +518,24 @@ function dt(e, s = "request") {
|
|
|
518
518
|
throw new Error(`No result in ${s} response`);
|
|
519
519
|
return e.result;
|
|
520
520
|
}
|
|
521
|
-
function
|
|
522
|
-
if (
|
|
521
|
+
function ft(e, s = "streaming request") {
|
|
522
|
+
if ($e(e, s), !e.body)
|
|
523
523
|
throw new Error(`No response body for ${s}`);
|
|
524
524
|
}
|
|
525
|
-
function
|
|
525
|
+
function qe(e, s = "request") {
|
|
526
526
|
const t = new AbortController();
|
|
527
527
|
return { timeoutId: setTimeout(
|
|
528
528
|
() => t.abort(),
|
|
529
529
|
e
|
|
530
530
|
), controller: t };
|
|
531
531
|
}
|
|
532
|
-
function
|
|
532
|
+
function mt(e, s) {
|
|
533
533
|
return `${e}/${s}`;
|
|
534
534
|
}
|
|
535
|
-
function
|
|
536
|
-
|
|
535
|
+
function pt(e, s, t, a) {
|
|
536
|
+
A("Request: %s %s", e, s), A("Headers: %o", t), a && A("Body: %s", Ue(a));
|
|
537
537
|
}
|
|
538
|
-
async function
|
|
538
|
+
async function ht(e, s = !1) {
|
|
539
539
|
const t = {
|
|
540
540
|
"Content-Type": "application/json"
|
|
541
541
|
};
|
|
@@ -545,7 +545,7 @@ async function pt(e, s = !1) {
|
|
|
545
545
|
}
|
|
546
546
|
return t;
|
|
547
547
|
}
|
|
548
|
-
function
|
|
548
|
+
function Fe(e, s) {
|
|
549
549
|
if (!s)
|
|
550
550
|
return e;
|
|
551
551
|
const t = new AbortController(), a = (n) => {
|
|
@@ -557,7 +557,7 @@ function qe(e, s) {
|
|
|
557
557
|
once: !0
|
|
558
558
|
}), t.signal;
|
|
559
559
|
}
|
|
560
|
-
function
|
|
560
|
+
function De(e, s, t, a) {
|
|
561
561
|
const n = {
|
|
562
562
|
method: "POST",
|
|
563
563
|
headers: e,
|
|
@@ -566,90 +566,90 @@ function Fe(e, s, t, a) {
|
|
|
566
566
|
};
|
|
567
567
|
return a !== void 0 && (n.credentials = a), n;
|
|
568
568
|
}
|
|
569
|
-
async function
|
|
570
|
-
const { message: r, sessionId: l, taskId: i, metadata: u } = e, { agentId: c, agentUrl:
|
|
569
|
+
async function le(e, s, t, a, n, o) {
|
|
570
|
+
const { message: r, sessionId: l, taskId: i, metadata: u } = e, { agentId: c, agentUrl: m, authProvider: f, proxy: M } = s, { isStreaming: g = !1, enableTokenStreaming: h = !1 } = t, I = l || o, v = mt(m, c), y = await it(
|
|
571
571
|
r,
|
|
572
572
|
a,
|
|
573
573
|
n
|
|
574
|
-
),
|
|
574
|
+
), x = {
|
|
575
575
|
id: i,
|
|
576
576
|
message: y,
|
|
577
577
|
metadata: u
|
|
578
578
|
};
|
|
579
|
-
I && (
|
|
580
|
-
const
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
h &&
|
|
579
|
+
I && (x.sessionId = I);
|
|
580
|
+
const b = tt(
|
|
581
|
+
x,
|
|
582
|
+
g ? "message/stream" : "message/send",
|
|
583
|
+
h && g
|
|
584
584
|
// Only enable token streaming if using SSE
|
|
585
|
-
),
|
|
586
|
-
return
|
|
587
|
-
request:
|
|
588
|
-
headers:
|
|
585
|
+
), S = await ht(f, g);
|
|
586
|
+
return pt("POST", v, S, b), {
|
|
587
|
+
request: b,
|
|
588
|
+
headers: S,
|
|
589
589
|
enhancedMessage: y,
|
|
590
590
|
effectiveSessionId: I,
|
|
591
|
-
fullAgentUrl:
|
|
591
|
+
fullAgentUrl: v
|
|
592
592
|
};
|
|
593
593
|
}
|
|
594
|
-
async function
|
|
595
|
-
const { request: a, headers: n, fullAgentUrl: o } = e, { timeout: r, credentials: l } = s, { abortSignal: i } = t, { timeoutId: u, controller: c } =
|
|
594
|
+
async function je(e, s, t = {}) {
|
|
595
|
+
const { request: a, headers: n, fullAgentUrl: o } = e, { timeout: r, credentials: l } = s, { abortSignal: i } = t, { timeoutId: u, controller: c } = qe(
|
|
596
596
|
r,
|
|
597
597
|
"request"
|
|
598
|
-
),
|
|
598
|
+
), m = i ? Fe(c.signal, i) : c.signal;
|
|
599
599
|
try {
|
|
600
|
-
const
|
|
600
|
+
const f = De(
|
|
601
601
|
n,
|
|
602
602
|
JSON.stringify(a),
|
|
603
|
-
|
|
603
|
+
m,
|
|
604
604
|
l
|
|
605
605
|
);
|
|
606
|
-
|
|
607
|
-
method:
|
|
608
|
-
headers:
|
|
606
|
+
A("Making request to %s with options: %O", o, {
|
|
607
|
+
method: f.method,
|
|
608
|
+
headers: f.headers
|
|
609
609
|
});
|
|
610
|
-
const
|
|
611
|
-
clearTimeout(u),
|
|
612
|
-
const
|
|
613
|
-
return
|
|
610
|
+
const M = await fetch(o, f);
|
|
611
|
+
clearTimeout(u), $e(M, "request");
|
|
612
|
+
const g = await M.json();
|
|
613
|
+
return A(
|
|
614
614
|
"Response from %s: %d %O",
|
|
615
615
|
o,
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
),
|
|
619
|
-
} catch (
|
|
620
|
-
Oe(
|
|
616
|
+
M.status,
|
|
617
|
+
Ue(g)
|
|
618
|
+
), gt(g, "request");
|
|
619
|
+
} catch (f) {
|
|
620
|
+
Oe(f, u, "request");
|
|
621
621
|
}
|
|
622
622
|
}
|
|
623
|
-
async function*
|
|
623
|
+
async function* Le(e, s, t) {
|
|
624
624
|
const { request: a, headers: n, fullAgentUrl: o } = e, { credentials: r } = s, {
|
|
625
625
|
streamingTimeout: l = 6e4,
|
|
626
626
|
abortSignal: i,
|
|
627
627
|
enableTokenStreaming: u = !1
|
|
628
|
-
} = t, { timeoutId: c, controller:
|
|
628
|
+
} = t, { timeoutId: c, controller: m } = qe(
|
|
629
629
|
l,
|
|
630
630
|
"streaming request"
|
|
631
|
-
),
|
|
631
|
+
), f = i ? Fe(m.signal, i) : m.signal;
|
|
632
632
|
try {
|
|
633
|
-
const
|
|
633
|
+
const M = JSON.stringify(a), g = De(
|
|
634
634
|
n,
|
|
635
|
-
|
|
636
|
-
|
|
635
|
+
M,
|
|
636
|
+
f,
|
|
637
637
|
r
|
|
638
|
-
), h = await fetch(o,
|
|
639
|
-
if (clearTimeout(c),
|
|
638
|
+
), h = await fetch(o, g);
|
|
639
|
+
if (clearTimeout(c), ft(h, "streaming request"), !h.body)
|
|
640
640
|
throw new Error(
|
|
641
641
|
"Response body is null - server may not support streaming"
|
|
642
642
|
);
|
|
643
643
|
const I = u && a.tokenStreaming === !0;
|
|
644
|
-
yield*
|
|
644
|
+
yield* ct(h.body, {
|
|
645
645
|
supportDeltas: I
|
|
646
646
|
});
|
|
647
|
-
} catch (
|
|
648
|
-
Oe(
|
|
647
|
+
} catch (M) {
|
|
648
|
+
Oe(M, c, "streaming request");
|
|
649
649
|
}
|
|
650
650
|
}
|
|
651
|
-
const
|
|
652
|
-
async function
|
|
651
|
+
const yt = 12e4;
|
|
652
|
+
async function ce(e, s, t, a, n) {
|
|
653
653
|
if (e.getAbilities) {
|
|
654
654
|
const o = await e.getAbilities();
|
|
655
655
|
if (o.length > 0)
|
|
@@ -672,7 +672,7 @@ async function ie(e, s, t, a, n) {
|
|
|
672
672
|
}
|
|
673
673
|
};
|
|
674
674
|
} catch (i) {
|
|
675
|
-
return
|
|
675
|
+
return A(
|
|
676
676
|
"Error executing ability %s: %O",
|
|
677
677
|
r.name,
|
|
678
678
|
i
|
|
@@ -691,7 +691,7 @@ async function ie(e, s, t, a, n) {
|
|
|
691
691
|
t
|
|
692
692
|
), returnToAgent: !0 };
|
|
693
693
|
} catch (i) {
|
|
694
|
-
return
|
|
694
|
+
return A(
|
|
695
695
|
"Error executing ability %s: %O",
|
|
696
696
|
r.name,
|
|
697
697
|
i
|
|
@@ -720,11 +720,11 @@ async function ie(e, s, t, a, n) {
|
|
|
720
720
|
`No handler found for tool: ${s}. Tool provider must implement executeTool for non-ability tools.`
|
|
721
721
|
);
|
|
722
722
|
}
|
|
723
|
-
const
|
|
724
|
-
async function
|
|
723
|
+
const Me = /* @__PURE__ */ new Map();
|
|
724
|
+
async function It(e, s) {
|
|
725
725
|
if (!e || !s || !e.getAvailableTools)
|
|
726
726
|
return !1;
|
|
727
|
-
const t =
|
|
727
|
+
const t = Q(s);
|
|
728
728
|
if (t.length === 0)
|
|
729
729
|
return !1;
|
|
730
730
|
try {
|
|
@@ -739,20 +739,20 @@ async function yt(e, s) {
|
|
|
739
739
|
}
|
|
740
740
|
return !1;
|
|
741
741
|
}
|
|
742
|
-
function
|
|
743
|
-
|
|
742
|
+
function wt() {
|
|
743
|
+
Me.clear();
|
|
744
744
|
}
|
|
745
|
-
function
|
|
745
|
+
function Mt(e) {
|
|
746
746
|
return e.map((s) => {
|
|
747
|
-
const t = s.data.toolCallId, a =
|
|
747
|
+
const t = s.data.toolCallId, a = Me.get(t);
|
|
748
748
|
if (a && a.resolvedValue !== null) {
|
|
749
749
|
const n = a.resolvedValue;
|
|
750
|
-
return n.error ?
|
|
750
|
+
return n.error ? z(
|
|
751
751
|
t,
|
|
752
752
|
s.data.toolId,
|
|
753
753
|
void 0,
|
|
754
754
|
n.error
|
|
755
|
-
) :
|
|
755
|
+
) : z(
|
|
756
756
|
t,
|
|
757
757
|
s.data.toolId,
|
|
758
758
|
n
|
|
@@ -761,29 +761,29 @@ function wt(e) {
|
|
|
761
761
|
return s;
|
|
762
762
|
});
|
|
763
763
|
}
|
|
764
|
-
async function
|
|
764
|
+
async function Je(e, s, t) {
|
|
765
765
|
const a = [], n = [];
|
|
766
766
|
let o = !1;
|
|
767
767
|
for (const r of e) {
|
|
768
768
|
const { toolCallId: l, toolId: i, arguments: u } = r.data;
|
|
769
769
|
try {
|
|
770
|
-
const c = await
|
|
770
|
+
const c = await ce(
|
|
771
771
|
s,
|
|
772
772
|
i,
|
|
773
773
|
u,
|
|
774
774
|
t,
|
|
775
775
|
l
|
|
776
|
-
), { result:
|
|
777
|
-
|
|
778
|
-
|
|
776
|
+
), { result: m, returnToAgent: f, agentMessage: M } = we(c);
|
|
777
|
+
f && (o = !0), M && n.push(Z(M)), a.push(
|
|
778
|
+
z(
|
|
779
779
|
l,
|
|
780
780
|
i,
|
|
781
|
-
|
|
781
|
+
m
|
|
782
782
|
)
|
|
783
783
|
);
|
|
784
784
|
} catch (c) {
|
|
785
785
|
o = !0, a.push(
|
|
786
|
-
|
|
786
|
+
z(
|
|
787
787
|
l,
|
|
788
788
|
i,
|
|
789
789
|
void 0,
|
|
@@ -794,7 +794,7 @@ async function Le(e, s, t) {
|
|
|
794
794
|
}
|
|
795
795
|
return { results: a, shouldReturnToAgent: o, agentMessages: n };
|
|
796
796
|
}
|
|
797
|
-
function
|
|
797
|
+
function be(e) {
|
|
798
798
|
const s = [];
|
|
799
799
|
for (const t of e)
|
|
800
800
|
for (const a of t.parts)
|
|
@@ -807,8 +807,8 @@ function xe(e) {
|
|
|
807
807
|
}) : (a.type === "data" || a.type === "file") && s.push(a);
|
|
808
808
|
return s;
|
|
809
809
|
}
|
|
810
|
-
async function
|
|
811
|
-
const i = await
|
|
810
|
+
async function ge(e, s, t, a, n, o, r) {
|
|
811
|
+
const i = await le(
|
|
812
812
|
{
|
|
813
813
|
message: s,
|
|
814
814
|
taskId: e,
|
|
@@ -821,17 +821,17 @@ async function de(e, s, t, a, n, o, r) {
|
|
|
821
821
|
n,
|
|
822
822
|
o
|
|
823
823
|
);
|
|
824
|
-
return await
|
|
824
|
+
return await je(i, t, {
|
|
825
825
|
abortSignal: r
|
|
826
826
|
});
|
|
827
827
|
}
|
|
828
|
-
async function
|
|
828
|
+
async function Re(e, s, t, a, n, o, r, l, i = []) {
|
|
829
829
|
const u = {
|
|
830
830
|
message: s,
|
|
831
831
|
taskId: e,
|
|
832
832
|
sessionId: o
|
|
833
833
|
// Use the provided sessionId to maintain conversation continuity
|
|
834
|
-
}, c = l || { isStreaming: !0 },
|
|
834
|
+
}, c = l || { isStreaming: !0 }, m = await le(
|
|
835
835
|
u,
|
|
836
836
|
t,
|
|
837
837
|
{
|
|
@@ -840,12 +840,12 @@ async function be(e, s, t, a, n, o, r, l, i = []) {
|
|
|
840
840
|
a,
|
|
841
841
|
n,
|
|
842
842
|
o
|
|
843
|
-
),
|
|
843
|
+
), f = Le(m, t, {
|
|
844
844
|
...c,
|
|
845
845
|
abortSignal: r
|
|
846
846
|
});
|
|
847
|
-
return
|
|
848
|
-
|
|
847
|
+
return Ke(
|
|
848
|
+
f,
|
|
849
849
|
a,
|
|
850
850
|
n,
|
|
851
851
|
t,
|
|
@@ -859,36 +859,36 @@ async function be(e, s, t, a, n, o, r, l, i = []) {
|
|
|
859
859
|
// Pass through the same request options
|
|
860
860
|
);
|
|
861
861
|
}
|
|
862
|
-
async function*
|
|
863
|
-
var u, c,
|
|
864
|
-
for await (const
|
|
865
|
-
if (
|
|
862
|
+
async function* Ke(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
863
|
+
var u, c, m, f, M, g, h, I, v, y, x, b;
|
|
864
|
+
for await (const S of e) {
|
|
865
|
+
if (S.sessionId && !n && (n = S.sessionId), yield S, S.status.state === "running" && S.status.message && s && await It(
|
|
866
866
|
s,
|
|
867
|
-
|
|
867
|
+
S.status.message
|
|
868
868
|
)) {
|
|
869
|
-
const
|
|
870
|
-
|
|
869
|
+
const T = Q(
|
|
870
|
+
S.status.message
|
|
871
871
|
);
|
|
872
|
-
for (const
|
|
873
|
-
const { toolCallId:
|
|
874
|
-
|
|
872
|
+
for (const d of T) {
|
|
873
|
+
const { toolCallId: w, toolId: U, arguments: p } = d.data;
|
|
874
|
+
ce(
|
|
875
875
|
s,
|
|
876
|
-
|
|
877
|
-
|
|
878
|
-
(c = (u =
|
|
879
|
-
|
|
880
|
-
).catch((
|
|
881
|
-
|
|
876
|
+
U,
|
|
877
|
+
p,
|
|
878
|
+
(c = (u = S.status) == null ? void 0 : u.message) == null ? void 0 : c.messageId,
|
|
879
|
+
w
|
|
880
|
+
).catch((C) => {
|
|
881
|
+
A("Tool execution failed for %s: %O", U, C);
|
|
882
882
|
});
|
|
883
883
|
}
|
|
884
884
|
yield {
|
|
885
|
-
id:
|
|
885
|
+
id: S.id,
|
|
886
886
|
status: {
|
|
887
887
|
state: "running",
|
|
888
888
|
message: {
|
|
889
889
|
role: "agent",
|
|
890
890
|
kind: "message",
|
|
891
|
-
parts:
|
|
891
|
+
parts: T,
|
|
892
892
|
messageId: q()
|
|
893
893
|
}
|
|
894
894
|
},
|
|
@@ -896,79 +896,79 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
896
896
|
text: ""
|
|
897
897
|
};
|
|
898
898
|
}
|
|
899
|
-
if (
|
|
900
|
-
const
|
|
901
|
-
|
|
899
|
+
if (S.status.state === "input-required" && S.status.message && s) {
|
|
900
|
+
const T = Q(
|
|
901
|
+
S.status.message
|
|
902
902
|
);
|
|
903
|
-
if (
|
|
904
|
-
const
|
|
905
|
-
let
|
|
906
|
-
const
|
|
907
|
-
for (const
|
|
903
|
+
if (T.length > 0) {
|
|
904
|
+
const d = [];
|
|
905
|
+
let w = !1;
|
|
906
|
+
const U = [], p = [];
|
|
907
|
+
for (const C of T) {
|
|
908
908
|
const {
|
|
909
909
|
toolCallId: k,
|
|
910
910
|
toolId: P,
|
|
911
911
|
arguments: F
|
|
912
|
-
} =
|
|
912
|
+
} = C.data;
|
|
913
913
|
try {
|
|
914
|
-
const
|
|
914
|
+
const O = await ce(
|
|
915
915
|
s,
|
|
916
916
|
P,
|
|
917
917
|
F,
|
|
918
|
-
(
|
|
918
|
+
(f = (m = S.status) == null ? void 0 : m.message) == null ? void 0 : f.messageId,
|
|
919
919
|
k
|
|
920
|
-
), { result:
|
|
921
|
-
if (
|
|
922
|
-
|
|
923
|
-
),
|
|
924
|
-
const
|
|
925
|
-
promise:
|
|
920
|
+
), { result: E, returnToAgent: R, agentMessage: H } = we(O);
|
|
921
|
+
if (R && (w = !0), H && p.push(
|
|
922
|
+
Z(H)
|
|
923
|
+
), E.result instanceof Promise) {
|
|
924
|
+
const L = E.result, B = {
|
|
925
|
+
promise: L,
|
|
926
926
|
resolvedValue: null
|
|
927
927
|
};
|
|
928
|
-
|
|
928
|
+
Me.set(
|
|
929
929
|
k,
|
|
930
|
-
|
|
931
|
-
),
|
|
932
|
-
|
|
933
|
-
}).catch((
|
|
934
|
-
|
|
930
|
+
B
|
|
931
|
+
), L.then((_) => {
|
|
932
|
+
B.resolvedValue = _;
|
|
933
|
+
}).catch((_) => {
|
|
934
|
+
A(
|
|
935
935
|
"Promise rejected for tool call %s: %O",
|
|
936
936
|
k,
|
|
937
|
-
|
|
938
|
-
),
|
|
939
|
-
error:
|
|
937
|
+
_
|
|
938
|
+
), B.resolvedValue = {
|
|
939
|
+
error: _ instanceof Error ? _.message : String(_)
|
|
940
940
|
};
|
|
941
941
|
});
|
|
942
942
|
}
|
|
943
|
-
const
|
|
943
|
+
const N = z(
|
|
944
944
|
k,
|
|
945
945
|
P,
|
|
946
|
-
|
|
946
|
+
E
|
|
947
947
|
);
|
|
948
|
-
|
|
949
|
-
} catch (
|
|
950
|
-
const
|
|
948
|
+
d.push(N), U.push(N);
|
|
949
|
+
} catch (O) {
|
|
950
|
+
const E = z(
|
|
951
951
|
k,
|
|
952
952
|
P,
|
|
953
953
|
void 0,
|
|
954
|
-
|
|
954
|
+
O instanceof Error ? O.message : String(O)
|
|
955
955
|
);
|
|
956
|
-
|
|
956
|
+
d.push(E), U.push(E);
|
|
957
957
|
}
|
|
958
958
|
}
|
|
959
|
-
if (r.push(
|
|
959
|
+
if (r.push(S.status.message), d.length > 0 && r.push({
|
|
960
960
|
role: "agent",
|
|
961
961
|
kind: "message",
|
|
962
|
-
parts:
|
|
962
|
+
parts: d,
|
|
963
963
|
messageId: q()
|
|
964
|
-
}),
|
|
965
|
-
const
|
|
964
|
+
}), w) {
|
|
965
|
+
const C = be(r), k = ie(
|
|
966
966
|
[],
|
|
967
967
|
// Empty array - tool results are already in historyDataParts
|
|
968
|
-
|
|
968
|
+
C
|
|
969
969
|
);
|
|
970
970
|
yield {
|
|
971
|
-
id:
|
|
971
|
+
id: S.id,
|
|
972
972
|
status: {
|
|
973
973
|
state: "working",
|
|
974
974
|
message: k
|
|
@@ -976,20 +976,20 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
976
976
|
final: !1,
|
|
977
977
|
text: ""
|
|
978
978
|
};
|
|
979
|
-
for (const
|
|
980
|
-
const
|
|
979
|
+
for (const R of p) {
|
|
980
|
+
const H = J(R);
|
|
981
981
|
yield {
|
|
982
|
-
id:
|
|
982
|
+
id: S.id,
|
|
983
983
|
status: {
|
|
984
984
|
state: "working",
|
|
985
|
-
message:
|
|
985
|
+
message: Z(H)
|
|
986
986
|
},
|
|
987
987
|
final: !1,
|
|
988
|
-
text:
|
|
988
|
+
text: H
|
|
989
989
|
};
|
|
990
990
|
}
|
|
991
|
-
const P = await
|
|
992
|
-
|
|
991
|
+
const P = await Re(
|
|
992
|
+
S.id,
|
|
993
993
|
k,
|
|
994
994
|
a,
|
|
995
995
|
s,
|
|
@@ -1000,60 +1000,60 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1000
1000
|
r
|
|
1001
1001
|
);
|
|
1002
1002
|
let F = null;
|
|
1003
|
-
for await (const
|
|
1004
|
-
|
|
1003
|
+
for await (const R of P)
|
|
1004
|
+
R.final ? F = R : yield R;
|
|
1005
1005
|
if (!F)
|
|
1006
1006
|
throw new Error(
|
|
1007
1007
|
"Continue task stream ended without final result"
|
|
1008
1008
|
);
|
|
1009
|
-
let
|
|
1009
|
+
let O = (M = F.status) != null && M.message ? Q(
|
|
1010
1010
|
F.status.message
|
|
1011
|
-
) : [],
|
|
1012
|
-
if (
|
|
1011
|
+
) : [], E = F;
|
|
1012
|
+
if (O.length > 0)
|
|
1013
1013
|
for (yield {
|
|
1014
1014
|
...F,
|
|
1015
1015
|
final: !1,
|
|
1016
|
-
text:
|
|
1017
|
-
((
|
|
1016
|
+
text: J(
|
|
1017
|
+
((g = F.status) == null ? void 0 : g.message) || {
|
|
1018
1018
|
parts: [],
|
|
1019
1019
|
messageId: q()
|
|
1020
1020
|
}
|
|
1021
1021
|
)
|
|
1022
|
-
};
|
|
1023
|
-
(h =
|
|
1024
|
-
|
|
1022
|
+
}; O.length > 0; ) {
|
|
1023
|
+
(h = E.status) != null && h.message && r.push(
|
|
1024
|
+
E.status.message
|
|
1025
1025
|
);
|
|
1026
1026
|
const {
|
|
1027
|
-
results:
|
|
1028
|
-
shouldReturnToAgent:
|
|
1029
|
-
} = await
|
|
1030
|
-
|
|
1027
|
+
results: R,
|
|
1028
|
+
shouldReturnToAgent: H
|
|
1029
|
+
} = await Je(
|
|
1030
|
+
O,
|
|
1031
1031
|
s,
|
|
1032
|
-
(
|
|
1032
|
+
(v = (I = E.status) == null ? void 0 : I.message) == null ? void 0 : v.messageId
|
|
1033
1033
|
);
|
|
1034
|
-
if (
|
|
1035
|
-
id:
|
|
1034
|
+
if (R.length > 0 && (yield {
|
|
1035
|
+
id: E.id,
|
|
1036
1036
|
status: {
|
|
1037
1037
|
state: "working",
|
|
1038
1038
|
message: {
|
|
1039
1039
|
role: "agent",
|
|
1040
1040
|
kind: "message",
|
|
1041
|
-
parts:
|
|
1041
|
+
parts: R,
|
|
1042
1042
|
messageId: q()
|
|
1043
1043
|
}
|
|
1044
1044
|
// Simple message with just the results
|
|
1045
1045
|
},
|
|
1046
1046
|
final: !1,
|
|
1047
1047
|
text: ""
|
|
1048
|
-
}),
|
|
1049
|
-
const
|
|
1048
|
+
}), H) {
|
|
1049
|
+
const N = o ? be(
|
|
1050
1050
|
r
|
|
1051
|
-
) : [],
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
),
|
|
1055
|
-
|
|
1056
|
-
|
|
1051
|
+
) : [], L = ie(
|
|
1052
|
+
R,
|
|
1053
|
+
N
|
|
1054
|
+
), B = await Re(
|
|
1055
|
+
E.id,
|
|
1056
|
+
L,
|
|
1057
1057
|
a,
|
|
1058
1058
|
s,
|
|
1059
1059
|
t,
|
|
@@ -1062,21 +1062,21 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1062
1062
|
i,
|
|
1063
1063
|
r
|
|
1064
1064
|
);
|
|
1065
|
-
let
|
|
1066
|
-
for await (const $ of
|
|
1067
|
-
$.final ?
|
|
1068
|
-
if (!
|
|
1065
|
+
let _ = null;
|
|
1066
|
+
for await (const $ of B)
|
|
1067
|
+
$.final ? _ = $ : yield $;
|
|
1068
|
+
if (!_)
|
|
1069
1069
|
throw new Error(
|
|
1070
1070
|
"Continue task stream ended without final result"
|
|
1071
1071
|
);
|
|
1072
|
-
|
|
1073
|
-
|
|
1074
|
-
) : [],
|
|
1075
|
-
id:
|
|
1076
|
-
status:
|
|
1072
|
+
E = _, O = (y = E.status) != null && y.message ? Q(
|
|
1073
|
+
E.status.message
|
|
1074
|
+
) : [], O.length > 0 && (yield {
|
|
1075
|
+
id: E.id,
|
|
1076
|
+
status: E.status,
|
|
1077
1077
|
final: !1,
|
|
1078
|
-
text:
|
|
1079
|
-
((
|
|
1078
|
+
text: J(
|
|
1079
|
+
((x = E.status) == null ? void 0 : x.message) || {
|
|
1080
1080
|
parts: [],
|
|
1081
1081
|
messageId: q()
|
|
1082
1082
|
}
|
|
@@ -1086,31 +1086,31 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1086
1086
|
break;
|
|
1087
1087
|
}
|
|
1088
1088
|
yield {
|
|
1089
|
-
...
|
|
1089
|
+
...E,
|
|
1090
1090
|
final: !0,
|
|
1091
|
-
text:
|
|
1092
|
-
((
|
|
1091
|
+
text: J(
|
|
1092
|
+
((b = E.status) == null ? void 0 : b.message) || {
|
|
1093
1093
|
parts: [],
|
|
1094
1094
|
messageId: q()
|
|
1095
1095
|
}
|
|
1096
1096
|
)
|
|
1097
1097
|
};
|
|
1098
1098
|
} else {
|
|
1099
|
-
const
|
|
1100
|
-
...
|
|
1101
|
-
parts:
|
|
1099
|
+
const C = {
|
|
1100
|
+
...S.status.message,
|
|
1101
|
+
parts: U
|
|
1102
1102
|
}, k = {
|
|
1103
|
-
...
|
|
1103
|
+
...S,
|
|
1104
1104
|
status: {
|
|
1105
|
-
...
|
|
1106
|
-
message:
|
|
1105
|
+
...S.status,
|
|
1106
|
+
message: C
|
|
1107
1107
|
},
|
|
1108
|
-
final:
|
|
1108
|
+
final: p.length === 0,
|
|
1109
1109
|
// Only final if no agent messages to follow
|
|
1110
|
-
text:
|
|
1110
|
+
text: J(C)
|
|
1111
1111
|
};
|
|
1112
|
-
if (yield k,
|
|
1113
|
-
const P =
|
|
1112
|
+
if (yield k, p.length > 0) {
|
|
1113
|
+
const P = p.map((O) => J(O)).join(" "), F = Z(P);
|
|
1114
1114
|
yield {
|
|
1115
1115
|
id: k.id,
|
|
1116
1116
|
status: {
|
|
@@ -1126,13 +1126,13 @@ async function* Je(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1126
1126
|
}
|
|
1127
1127
|
}
|
|
1128
1128
|
}
|
|
1129
|
-
function
|
|
1129
|
+
function Tt(e) {
|
|
1130
1130
|
const {
|
|
1131
1131
|
agentId: s,
|
|
1132
1132
|
agentUrl: t,
|
|
1133
1133
|
authProvider: a,
|
|
1134
1134
|
defaultSessionId: n,
|
|
1135
|
-
timeout: o =
|
|
1135
|
+
timeout: o = yt,
|
|
1136
1136
|
toolProvider: r,
|
|
1137
1137
|
contextProvider: l,
|
|
1138
1138
|
enableStreaming: i = !1,
|
|
@@ -1145,121 +1145,121 @@ function Mt(e) {
|
|
|
1145
1145
|
credentials: u
|
|
1146
1146
|
};
|
|
1147
1147
|
return {
|
|
1148
|
-
async sendMessage(
|
|
1149
|
-
var
|
|
1150
|
-
const { abortSignal:
|
|
1151
|
-
|
|
1152
|
-
const h = await
|
|
1153
|
-
|
|
1148
|
+
async sendMessage(m) {
|
|
1149
|
+
var x, b;
|
|
1150
|
+
const { abortSignal: f } = m, M = m.sessionId || n || void 0, g = [];
|
|
1151
|
+
g.push(m.message);
|
|
1152
|
+
const h = await le(
|
|
1153
|
+
m,
|
|
1154
1154
|
c,
|
|
1155
1155
|
{ isStreaming: !1 },
|
|
1156
1156
|
r,
|
|
1157
1157
|
l,
|
|
1158
|
-
|
|
1158
|
+
M
|
|
1159
1159
|
);
|
|
1160
|
-
let I = await
|
|
1160
|
+
let I = await je(
|
|
1161
1161
|
h,
|
|
1162
1162
|
c,
|
|
1163
|
-
{ abortSignal:
|
|
1163
|
+
{ abortSignal: f }
|
|
1164
1164
|
);
|
|
1165
|
-
const
|
|
1165
|
+
const v = [], y = [];
|
|
1166
1166
|
for (; I.status.message && r; ) {
|
|
1167
|
-
const
|
|
1167
|
+
const S = Q(
|
|
1168
1168
|
I.status.message
|
|
1169
1169
|
);
|
|
1170
|
-
if (
|
|
1170
|
+
if (S.length === 0)
|
|
1171
1171
|
break;
|
|
1172
|
-
|
|
1173
|
-
const
|
|
1174
|
-
let
|
|
1175
|
-
for (const
|
|
1172
|
+
v.push(...S);
|
|
1173
|
+
const T = [];
|
|
1174
|
+
let d = !1;
|
|
1175
|
+
for (const w of S) {
|
|
1176
1176
|
const {
|
|
1177
|
-
toolCallId:
|
|
1178
|
-
toolId:
|
|
1179
|
-
arguments:
|
|
1180
|
-
} =
|
|
1177
|
+
toolCallId: U,
|
|
1178
|
+
toolId: p,
|
|
1179
|
+
arguments: C
|
|
1180
|
+
} = w.data;
|
|
1181
1181
|
try {
|
|
1182
|
-
const k = await
|
|
1182
|
+
const k = await ce(
|
|
1183
1183
|
r,
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
), { result: P, returnToAgent: F, agentMessage:
|
|
1187
|
-
F && (
|
|
1188
|
-
|
|
1184
|
+
p,
|
|
1185
|
+
C
|
|
1186
|
+
), { result: P, returnToAgent: F, agentMessage: O } = we(k);
|
|
1187
|
+
F && (d = !0), O && y.push(
|
|
1188
|
+
Z(O)
|
|
1189
1189
|
);
|
|
1190
|
-
const
|
|
1191
|
-
|
|
1192
|
-
|
|
1190
|
+
const E = z(
|
|
1191
|
+
U,
|
|
1192
|
+
p,
|
|
1193
1193
|
P
|
|
1194
1194
|
);
|
|
1195
|
-
|
|
1195
|
+
T.push(E), v.push(E);
|
|
1196
1196
|
} catch (k) {
|
|
1197
|
-
const P =
|
|
1198
|
-
|
|
1199
|
-
|
|
1197
|
+
const P = z(
|
|
1198
|
+
U,
|
|
1199
|
+
p,
|
|
1200
1200
|
void 0,
|
|
1201
1201
|
k instanceof Error ? k.message : String(k)
|
|
1202
1202
|
);
|
|
1203
|
-
|
|
1203
|
+
T.push(P), v.push(P);
|
|
1204
1204
|
}
|
|
1205
1205
|
}
|
|
1206
|
-
if (
|
|
1207
|
-
const
|
|
1208
|
-
I = await
|
|
1206
|
+
if (g.push(I.status.message), d) {
|
|
1207
|
+
const w = ie(T);
|
|
1208
|
+
I = await ge(
|
|
1209
1209
|
I.id,
|
|
1210
|
-
|
|
1210
|
+
w,
|
|
1211
1211
|
c,
|
|
1212
1212
|
r,
|
|
1213
1213
|
l,
|
|
1214
|
-
|
|
1215
|
-
|
|
1214
|
+
M,
|
|
1215
|
+
f
|
|
1216
1216
|
);
|
|
1217
1217
|
} else
|
|
1218
1218
|
break;
|
|
1219
1219
|
}
|
|
1220
|
-
if (
|
|
1221
|
-
const
|
|
1220
|
+
if (v.length > 0 && (x = I.status) != null && x.message) {
|
|
1221
|
+
const S = {
|
|
1222
1222
|
...I.status.message,
|
|
1223
|
-
parts:
|
|
1223
|
+
parts: v
|
|
1224
1224
|
};
|
|
1225
1225
|
I = {
|
|
1226
1226
|
...I,
|
|
1227
1227
|
status: {
|
|
1228
1228
|
...I.status,
|
|
1229
|
-
message:
|
|
1229
|
+
message: S
|
|
1230
1230
|
}
|
|
1231
1231
|
};
|
|
1232
1232
|
}
|
|
1233
1233
|
if (y.length > 0) {
|
|
1234
|
-
const
|
|
1234
|
+
const S = y.map((d) => J(d)).join(" "), T = Z(S);
|
|
1235
1235
|
return {
|
|
1236
1236
|
...I,
|
|
1237
1237
|
// Keep the enhanced message with tool results
|
|
1238
1238
|
// The agent message will be handled separately by the caller
|
|
1239
|
-
text:
|
|
1240
|
-
agentMessage:
|
|
1239
|
+
text: S,
|
|
1240
|
+
agentMessage: T
|
|
1241
1241
|
// Add this for the caller to handle
|
|
1242
1242
|
};
|
|
1243
1243
|
}
|
|
1244
1244
|
return {
|
|
1245
1245
|
...I,
|
|
1246
|
-
text:
|
|
1247
|
-
((
|
|
1246
|
+
text: J(
|
|
1247
|
+
((b = I.status) == null ? void 0 : b.message) || {
|
|
1248
1248
|
parts: [],
|
|
1249
1249
|
messageId: q()
|
|
1250
1250
|
}
|
|
1251
1251
|
)
|
|
1252
1252
|
};
|
|
1253
1253
|
},
|
|
1254
|
-
async *sendMessageStream(
|
|
1254
|
+
async *sendMessageStream(m) {
|
|
1255
1255
|
const {
|
|
1256
|
-
withHistory:
|
|
1257
|
-
abortSignal:
|
|
1258
|
-
enableStreaming:
|
|
1259
|
-
} =
|
|
1260
|
-
|
|
1261
|
-
const y = await
|
|
1262
|
-
|
|
1256
|
+
withHistory: f = !0,
|
|
1257
|
+
abortSignal: M,
|
|
1258
|
+
enableStreaming: g
|
|
1259
|
+
} = m, h = m.sessionId || n || void 0, I = g ?? i, v = [];
|
|
1260
|
+
v.push(m.message);
|
|
1261
|
+
const y = await le(
|
|
1262
|
+
m,
|
|
1263
1263
|
c,
|
|
1264
1264
|
{
|
|
1265
1265
|
isStreaming: !0,
|
|
@@ -1269,25 +1269,25 @@ function Mt(e) {
|
|
|
1269
1269
|
r,
|
|
1270
1270
|
l,
|
|
1271
1271
|
h
|
|
1272
|
-
),
|
|
1272
|
+
), x = Le(
|
|
1273
1273
|
y,
|
|
1274
1274
|
c,
|
|
1275
1275
|
{
|
|
1276
1276
|
enableTokenStreaming: I,
|
|
1277
1277
|
// Token streaming is optional
|
|
1278
1278
|
streamingTimeout: o,
|
|
1279
|
-
abortSignal:
|
|
1279
|
+
abortSignal: M
|
|
1280
1280
|
}
|
|
1281
1281
|
);
|
|
1282
|
-
yield*
|
|
1283
|
-
|
|
1282
|
+
yield* Ke(
|
|
1283
|
+
x,
|
|
1284
1284
|
r,
|
|
1285
1285
|
l,
|
|
1286
1286
|
c,
|
|
1287
1287
|
h,
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
|
|
1288
|
+
f,
|
|
1289
|
+
v,
|
|
1290
|
+
M,
|
|
1291
1291
|
{
|
|
1292
1292
|
isStreaming: !0,
|
|
1293
1293
|
enableTokenStreaming: I,
|
|
@@ -1295,41 +1295,41 @@ function Mt(e) {
|
|
|
1295
1295
|
}
|
|
1296
1296
|
);
|
|
1297
1297
|
},
|
|
1298
|
-
async continueTask(
|
|
1299
|
-
var
|
|
1300
|
-
const
|
|
1301
|
-
let I = await
|
|
1302
|
-
|
|
1303
|
-
|
|
1298
|
+
async continueTask(m, f, M) {
|
|
1299
|
+
var v;
|
|
1300
|
+
const g = pe(f);
|
|
1301
|
+
let I = await ge(
|
|
1302
|
+
m,
|
|
1303
|
+
g,
|
|
1304
1304
|
c,
|
|
1305
1305
|
r,
|
|
1306
1306
|
l,
|
|
1307
|
-
|
|
1307
|
+
M
|
|
1308
1308
|
);
|
|
1309
1309
|
for (; I.status.state === "input-required" && I.status.message && r; ) {
|
|
1310
|
-
const y =
|
|
1310
|
+
const y = Q(
|
|
1311
1311
|
I.status.message
|
|
1312
1312
|
);
|
|
1313
1313
|
if (y.length === 0)
|
|
1314
1314
|
break;
|
|
1315
|
-
const { results:
|
|
1316
|
-
if (
|
|
1317
|
-
const
|
|
1318
|
-
I = await
|
|
1315
|
+
const { results: x, shouldReturnToAgent: b } = await Je(y, r);
|
|
1316
|
+
if (b) {
|
|
1317
|
+
const S = ie(x);
|
|
1318
|
+
I = await ge(
|
|
1319
1319
|
I.id,
|
|
1320
|
-
|
|
1320
|
+
S,
|
|
1321
1321
|
c,
|
|
1322
1322
|
r,
|
|
1323
1323
|
l,
|
|
1324
|
-
|
|
1324
|
+
M
|
|
1325
1325
|
);
|
|
1326
1326
|
} else
|
|
1327
1327
|
break;
|
|
1328
1328
|
}
|
|
1329
1329
|
return {
|
|
1330
1330
|
...I,
|
|
1331
|
-
text:
|
|
1332
|
-
((
|
|
1331
|
+
text: J(
|
|
1332
|
+
((v = I.status) == null ? void 0 : v.message) || {
|
|
1333
1333
|
parts: [],
|
|
1334
1334
|
messageId: q()
|
|
1335
1335
|
}
|
|
@@ -1344,7 +1344,7 @@ function Mt(e) {
|
|
|
1344
1344
|
}
|
|
1345
1345
|
};
|
|
1346
1346
|
}
|
|
1347
|
-
function
|
|
1347
|
+
function At(e) {
|
|
1348
1348
|
const s = [], t = e.context, a = !!t && !Array.isArray(t) && !!t.flags && typeof t.flags == "object" && t.flags.context_only === !0;
|
|
1349
1349
|
if (e.content) {
|
|
1350
1350
|
const r = {
|
|
@@ -1396,7 +1396,7 @@ function Tt(e) {
|
|
|
1396
1396
|
}
|
|
1397
1397
|
};
|
|
1398
1398
|
}
|
|
1399
|
-
function
|
|
1399
|
+
function vt(e) {
|
|
1400
1400
|
if (e.role !== "tool_call" && e.role !== "tool_result")
|
|
1401
1401
|
return !1;
|
|
1402
1402
|
try {
|
|
@@ -1405,9 +1405,9 @@ function At(e) {
|
|
|
1405
1405
|
return !1;
|
|
1406
1406
|
}
|
|
1407
1407
|
}
|
|
1408
|
-
function
|
|
1408
|
+
function St(e, s = !1) {
|
|
1409
1409
|
var o, r, l, i, u, c;
|
|
1410
|
-
const a = e.messages.filter((
|
|
1410
|
+
const a = e.messages.filter((m) => m.role === "tool_call" ? !1 : m.role === "tool_result" ? !(!s || vt(m)) : !0).map(At), n = {
|
|
1411
1411
|
currentPage: ((o = e.metadata) == null ? void 0 : o.current_page) ?? 1,
|
|
1412
1412
|
itemsPerPage: ((r = e.metadata) == null ? void 0 : r.items_per_page) ?? 10,
|
|
1413
1413
|
totalPages: ((l = e.metadata) == null ? void 0 : l.total_pages) ?? 1,
|
|
@@ -1421,14 +1421,14 @@ function vt(e, s = !1) {
|
|
|
1421
1421
|
sessionId: e.session_id
|
|
1422
1422
|
};
|
|
1423
1423
|
}
|
|
1424
|
-
class
|
|
1424
|
+
class ee extends Error {
|
|
1425
1425
|
constructor(s, t, a) {
|
|
1426
1426
|
super(s), this.statusCode = t, this.details = a, this.name = "ServerConversationError";
|
|
1427
1427
|
}
|
|
1428
1428
|
}
|
|
1429
|
-
const
|
|
1430
|
-
async function
|
|
1431
|
-
const { botId: o, apiBaseUrl: r =
|
|
1429
|
+
const Te = "https://public-api.wordpress.com";
|
|
1430
|
+
async function he(e, s, t = 1, a = 50, n = !1) {
|
|
1431
|
+
const { botId: o, apiBaseUrl: r = Te, authProvider: l } = s;
|
|
1432
1432
|
if (!e || !o)
|
|
1433
1433
|
throw new Error(
|
|
1434
1434
|
"chatId and botId are required to load conversation from server"
|
|
@@ -1438,58 +1438,58 @@ async function pe(e, s, t = 1, a = 50, n = !1) {
|
|
|
1438
1438
|
o
|
|
1439
1439
|
)}/${encodeURIComponent(e)}`
|
|
1440
1440
|
);
|
|
1441
|
-
c.searchParams.set("page_number", i.toString()), c.searchParams.set("items_per_page", u.toString()),
|
|
1441
|
+
c.searchParams.set("page_number", i.toString()), c.searchParams.set("items_per_page", u.toString()), A(
|
|
1442
1442
|
"Loading conversation from server: %s (page %d)",
|
|
1443
1443
|
e,
|
|
1444
1444
|
i
|
|
1445
1445
|
);
|
|
1446
1446
|
try {
|
|
1447
|
-
const
|
|
1447
|
+
const m = {
|
|
1448
1448
|
"Content-Type": "application/json"
|
|
1449
1449
|
};
|
|
1450
1450
|
if (l) {
|
|
1451
1451
|
const h = await l();
|
|
1452
|
-
Object.assign(
|
|
1452
|
+
Object.assign(m, h);
|
|
1453
1453
|
}
|
|
1454
|
-
const
|
|
1454
|
+
const f = await fetch(c.toString(), {
|
|
1455
1455
|
method: "GET",
|
|
1456
|
-
headers:
|
|
1456
|
+
headers: m
|
|
1457
1457
|
});
|
|
1458
|
-
if (!
|
|
1459
|
-
const h = await
|
|
1460
|
-
let I = `Failed to load conversation from server: ${
|
|
1458
|
+
if (!f.ok) {
|
|
1459
|
+
const h = await f.text();
|
|
1460
|
+
let I = `Failed to load conversation from server: ${f.status} ${f.statusText}`;
|
|
1461
1461
|
try {
|
|
1462
1462
|
const y = JSON.parse(h);
|
|
1463
1463
|
y.message && (I = y.message);
|
|
1464
1464
|
} catch {
|
|
1465
1465
|
}
|
|
1466
|
-
const
|
|
1466
|
+
const v = new ee(
|
|
1467
1467
|
I,
|
|
1468
|
-
|
|
1468
|
+
f.status,
|
|
1469
1469
|
h
|
|
1470
1470
|
);
|
|
1471
|
-
throw
|
|
1471
|
+
throw A("Failed to load conversation from server: %O", v), v;
|
|
1472
1472
|
}
|
|
1473
|
-
const
|
|
1474
|
-
return
|
|
1473
|
+
const M = await f.json(), g = St(M, n);
|
|
1474
|
+
return A(
|
|
1475
1475
|
"Loaded %d messages from server (page %d/%d)",
|
|
1476
|
-
|
|
1477
|
-
|
|
1478
|
-
|
|
1479
|
-
),
|
|
1480
|
-
} catch (
|
|
1481
|
-
if (
|
|
1482
|
-
throw
|
|
1483
|
-
const
|
|
1484
|
-
`Network error loading conversation: ${
|
|
1476
|
+
g.messages.length,
|
|
1477
|
+
g.pagination.currentPage,
|
|
1478
|
+
g.pagination.totalPages
|
|
1479
|
+
), g;
|
|
1480
|
+
} catch (m) {
|
|
1481
|
+
if (m instanceof ee)
|
|
1482
|
+
throw m;
|
|
1483
|
+
const f = new ee(
|
|
1484
|
+
`Network error loading conversation: ${m.message}`,
|
|
1485
1485
|
void 0,
|
|
1486
|
-
|
|
1486
|
+
m
|
|
1487
1487
|
);
|
|
1488
|
-
throw
|
|
1488
|
+
throw A("Network error loading conversation: %O", m), f;
|
|
1489
1489
|
}
|
|
1490
1490
|
}
|
|
1491
|
-
async function
|
|
1492
|
-
const { apiBaseUrl: a =
|
|
1491
|
+
async function us(e, s, t = !1) {
|
|
1492
|
+
const { apiBaseUrl: a = Te, authProvider: n } = s, o = new URL(
|
|
1493
1493
|
`${a}/wpcom/v2/odie/conversations/${encodeURIComponent(
|
|
1494
1494
|
e
|
|
1495
1495
|
)}`
|
|
@@ -1497,7 +1497,7 @@ async function cs(e, s, t = !1) {
|
|
|
1497
1497
|
o.searchParams.set(
|
|
1498
1498
|
"truncation_method",
|
|
1499
1499
|
t ? "first_message" : "last_message"
|
|
1500
|
-
),
|
|
1500
|
+
), A("Listing conversations from server for bot: %s", e);
|
|
1501
1501
|
try {
|
|
1502
1502
|
const r = {
|
|
1503
1503
|
"Content-Type": "application/json"
|
|
@@ -1511,28 +1511,28 @@ async function cs(e, s, t = !1) {
|
|
|
1511
1511
|
headers: r
|
|
1512
1512
|
});
|
|
1513
1513
|
if (!l.ok) {
|
|
1514
|
-
const u = await l.text(), c = `Failed to list conversations: ${l.status} ${l.statusText}`,
|
|
1514
|
+
const u = await l.text(), c = `Failed to list conversations: ${l.status} ${l.statusText}`, m = new ee(
|
|
1515
1515
|
c,
|
|
1516
1516
|
l.status,
|
|
1517
1517
|
u
|
|
1518
1518
|
);
|
|
1519
|
-
throw
|
|
1519
|
+
throw A("Failed to list conversations: %O", m), m;
|
|
1520
1520
|
}
|
|
1521
1521
|
const i = await l.json();
|
|
1522
|
-
return
|
|
1522
|
+
return A("Loaded %d conversations from server", i.length), i;
|
|
1523
1523
|
} catch (r) {
|
|
1524
|
-
if (r instanceof
|
|
1524
|
+
if (r instanceof ee)
|
|
1525
1525
|
throw r;
|
|
1526
|
-
const l = new
|
|
1526
|
+
const l = new ee(
|
|
1527
1527
|
`Network error listing conversations: ${r.message}`,
|
|
1528
1528
|
void 0,
|
|
1529
1529
|
r
|
|
1530
1530
|
);
|
|
1531
|
-
throw
|
|
1531
|
+
throw A("Network error listing conversations: %O", r), l;
|
|
1532
1532
|
}
|
|
1533
1533
|
}
|
|
1534
|
-
async function
|
|
1535
|
-
const n = await
|
|
1534
|
+
async function ds(e, s, t = 10, a = !1) {
|
|
1535
|
+
const n = await he(
|
|
1536
1536
|
e,
|
|
1537
1537
|
s,
|
|
1538
1538
|
1,
|
|
@@ -1547,7 +1547,7 @@ async function us(e, s, t = 10, a = !1) {
|
|
|
1547
1547
|
), r = [...n.messages], l = [];
|
|
1548
1548
|
for (let i = 2; i <= o; i++)
|
|
1549
1549
|
l.push(
|
|
1550
|
-
|
|
1550
|
+
he(e, s, i, 50, a)
|
|
1551
1551
|
);
|
|
1552
1552
|
try {
|
|
1553
1553
|
const i = await Promise.all(l);
|
|
@@ -1563,46 +1563,46 @@ async function us(e, s, t = 10, a = !1) {
|
|
|
1563
1563
|
chatId: n.chatId
|
|
1564
1564
|
};
|
|
1565
1565
|
} catch (i) {
|
|
1566
|
-
return
|
|
1566
|
+
return A("Failed to load all pages: %O", i), {
|
|
1567
1567
|
messages: r,
|
|
1568
1568
|
pagination: n.pagination,
|
|
1569
1569
|
chatId: n.chatId
|
|
1570
1570
|
};
|
|
1571
1571
|
}
|
|
1572
1572
|
}
|
|
1573
|
-
const
|
|
1574
|
-
function
|
|
1575
|
-
var
|
|
1573
|
+
const Ae = "a8c_agenttic_conversation_history";
|
|
1574
|
+
function Ct(e) {
|
|
1575
|
+
var f, M;
|
|
1576
1576
|
const s = e.parts.filter(
|
|
1577
|
-
(
|
|
1578
|
-
), t = s.map((
|
|
1577
|
+
(g) => g.type === "text"
|
|
1578
|
+
), t = s.map((g) => g.text).join(`
|
|
1579
1579
|
`), a = s.some(
|
|
1580
|
-
(
|
|
1580
|
+
(g) => {
|
|
1581
1581
|
var h;
|
|
1582
|
-
return ((h =
|
|
1582
|
+
return ((h = g.metadata) == null ? void 0 : h.contentType) === "context";
|
|
1583
1583
|
}
|
|
1584
1584
|
) ? "context" : void 0, n = e.parts.filter(
|
|
1585
|
-
(
|
|
1586
|
-
).map((
|
|
1587
|
-
toolCallId:
|
|
1588
|
-
toolId:
|
|
1589
|
-
arguments:
|
|
1585
|
+
(g) => g.type === "data" && "toolCallId" in g.data && "arguments" in g.data
|
|
1586
|
+
).map((g) => ({
|
|
1587
|
+
toolCallId: g.data.toolCallId,
|
|
1588
|
+
toolId: g.data.toolId,
|
|
1589
|
+
arguments: g.data.arguments
|
|
1590
1590
|
})), o = e.parts.filter(
|
|
1591
|
-
(
|
|
1592
|
-
).map((
|
|
1593
|
-
toolCallId:
|
|
1594
|
-
result:
|
|
1595
|
-
error:
|
|
1596
|
-
})), r = e.parts.filter((
|
|
1597
|
-
name:
|
|
1598
|
-
mimeType:
|
|
1599
|
-
uri:
|
|
1591
|
+
(g) => g.type === "data" && "toolCallId" in g.data && "result" in g.data
|
|
1592
|
+
).map((g) => ({
|
|
1593
|
+
toolCallId: g.data.toolCallId,
|
|
1594
|
+
result: g.data.result,
|
|
1595
|
+
error: g.data.error
|
|
1596
|
+
})), r = e.parts.filter((g) => g.type === "file").map((g) => ({
|
|
1597
|
+
name: g.file.name,
|
|
1598
|
+
mimeType: g.file.mimeType,
|
|
1599
|
+
uri: g.file.uri
|
|
1600
1600
|
}));
|
|
1601
1601
|
let l;
|
|
1602
|
-
for (const
|
|
1603
|
-
if (
|
|
1602
|
+
for (const g of e.parts) {
|
|
1603
|
+
if (g.type !== "data" || !g.data || typeof g.data != "object" || "toolCallId" in g.data)
|
|
1604
1604
|
continue;
|
|
1605
|
-
const h =
|
|
1605
|
+
const h = g.data, I = h.flags;
|
|
1606
1606
|
if (I && typeof I == "object" && I !== null && "forward_to_human_support" in I) {
|
|
1607
1607
|
l = {
|
|
1608
1608
|
flags: I,
|
|
@@ -1611,12 +1611,12 @@ function St(e) {
|
|
|
1611
1611
|
break;
|
|
1612
1612
|
}
|
|
1613
1613
|
}
|
|
1614
|
-
const u = n.length > 0 || o.length > 0 ? "agent" : e.role, c = ((
|
|
1614
|
+
const u = n.length > 0 || o.length > 0 ? "agent" : e.role, c = ((f = e.metadata) == null ? void 0 : f.timestamp) ?? Date.now(), m = ((M = e.metadata) == null ? void 0 : M.archived) ?? void 0;
|
|
1615
1615
|
return {
|
|
1616
1616
|
role: u,
|
|
1617
1617
|
content: t || "(No text content)",
|
|
1618
1618
|
timestamp: c,
|
|
1619
|
-
...
|
|
1619
|
+
...m !== void 0 && { archived: m },
|
|
1620
1620
|
...a && { contentType: a },
|
|
1621
1621
|
...r.length > 0 && { files: r },
|
|
1622
1622
|
...n.length > 0 && { toolCalls: n },
|
|
@@ -1624,7 +1624,7 @@ function St(e) {
|
|
|
1624
1624
|
...l && { agentMessageData: l }
|
|
1625
1625
|
};
|
|
1626
1626
|
}
|
|
1627
|
-
function
|
|
1627
|
+
function xt(e) {
|
|
1628
1628
|
const s = [];
|
|
1629
1629
|
if (e.content && e.content !== "(No text content)" && s.push({
|
|
1630
1630
|
type: "text",
|
|
@@ -1682,45 +1682,45 @@ function Ct(e) {
|
|
|
1682
1682
|
}
|
|
1683
1683
|
};
|
|
1684
1684
|
}
|
|
1685
|
-
const
|
|
1686
|
-
async function
|
|
1685
|
+
const G = /* @__PURE__ */ new Map(), bt = 50;
|
|
1686
|
+
async function Rt(e, s, t) {
|
|
1687
1687
|
const a = t || e;
|
|
1688
|
-
if (
|
|
1689
|
-
const n =
|
|
1690
|
-
n &&
|
|
1688
|
+
if (G.set(a, [...s]), G.size > bt) {
|
|
1689
|
+
const n = G.keys().next().value;
|
|
1690
|
+
n && G.delete(n);
|
|
1691
1691
|
}
|
|
1692
1692
|
if (!(typeof sessionStorage > "u"))
|
|
1693
1693
|
try {
|
|
1694
1694
|
const n = {
|
|
1695
1695
|
storageKey: a,
|
|
1696
|
-
messages: s.map(
|
|
1696
|
+
messages: s.map(Ct),
|
|
1697
1697
|
lastUpdated: Date.now()
|
|
1698
1698
|
};
|
|
1699
1699
|
sessionStorage.setItem(
|
|
1700
|
-
`${
|
|
1700
|
+
`${Ae}_${a}`,
|
|
1701
1701
|
JSON.stringify(n)
|
|
1702
1702
|
);
|
|
1703
1703
|
} catch (n) {
|
|
1704
|
-
|
|
1704
|
+
A(
|
|
1705
1705
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1706
1706
|
a,
|
|
1707
1707
|
n
|
|
1708
1708
|
);
|
|
1709
1709
|
}
|
|
1710
1710
|
}
|
|
1711
|
-
async function
|
|
1712
|
-
return t != null && t.odieBotId ?
|
|
1711
|
+
async function kt(e, s, t) {
|
|
1712
|
+
return t != null && t.odieBotId ? Pt(e, t) : _t(
|
|
1713
1713
|
e,
|
|
1714
1714
|
s
|
|
1715
1715
|
);
|
|
1716
1716
|
}
|
|
1717
|
-
async function
|
|
1717
|
+
async function Pt(e, s) {
|
|
1718
1718
|
const { odieBotId: t, authProvider: a } = s;
|
|
1719
1719
|
if (!t)
|
|
1720
1720
|
throw new Error("odieBotId is required for server storage");
|
|
1721
|
-
const n =
|
|
1721
|
+
const n = Te;
|
|
1722
1722
|
try {
|
|
1723
|
-
const r = await
|
|
1723
|
+
const r = await he(
|
|
1724
1724
|
e,
|
|
1725
1725
|
{
|
|
1726
1726
|
botId: t,
|
|
@@ -1730,7 +1730,7 @@ async function kt(e, s) {
|
|
|
1730
1730
|
1,
|
|
1731
1731
|
50
|
|
1732
1732
|
);
|
|
1733
|
-
return
|
|
1733
|
+
return A(
|
|
1734
1734
|
"Loaded conversation from server: %s (%d messages, page %d/%d)",
|
|
1735
1735
|
e,
|
|
1736
1736
|
r.messages.length,
|
|
@@ -1741,27 +1741,27 @@ async function kt(e, s) {
|
|
|
1741
1741
|
pagination: r.pagination
|
|
1742
1742
|
};
|
|
1743
1743
|
} catch (o) {
|
|
1744
|
-
throw
|
|
1744
|
+
throw A("Failed to load conversation from server: %O", o), o;
|
|
1745
1745
|
}
|
|
1746
1746
|
}
|
|
1747
|
-
async function
|
|
1747
|
+
async function _t(e, s) {
|
|
1748
1748
|
const t = s || e;
|
|
1749
|
-
if (
|
|
1749
|
+
if (G.has(t))
|
|
1750
1750
|
return {
|
|
1751
|
-
messages: [...
|
|
1751
|
+
messages: [...G.get(t)]
|
|
1752
1752
|
};
|
|
1753
1753
|
if (typeof sessionStorage > "u")
|
|
1754
1754
|
return { messages: [] };
|
|
1755
1755
|
try {
|
|
1756
1756
|
const a = sessionStorage.getItem(
|
|
1757
|
-
`${
|
|
1757
|
+
`${Ae}_${t}`
|
|
1758
1758
|
);
|
|
1759
1759
|
if (a) {
|
|
1760
|
-
const o = JSON.parse(a).messages.map(
|
|
1761
|
-
return
|
|
1760
|
+
const o = JSON.parse(a).messages.map(xt);
|
|
1761
|
+
return G.set(t, o), { messages: [...o] };
|
|
1762
1762
|
}
|
|
1763
1763
|
} catch (a) {
|
|
1764
|
-
|
|
1764
|
+
A(
|
|
1765
1765
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1766
1766
|
t,
|
|
1767
1767
|
a
|
|
@@ -1769,20 +1769,20 @@ async function Pt(e, s) {
|
|
|
1769
1769
|
}
|
|
1770
1770
|
return { messages: [] };
|
|
1771
1771
|
}
|
|
1772
|
-
async function
|
|
1772
|
+
async function Et(e, s) {
|
|
1773
1773
|
const t = s || e;
|
|
1774
|
-
if (
|
|
1774
|
+
if (G.delete(t), !(typeof sessionStorage > "u"))
|
|
1775
1775
|
try {
|
|
1776
|
-
sessionStorage.removeItem(`${
|
|
1776
|
+
sessionStorage.removeItem(`${Ae}_${t}`);
|
|
1777
1777
|
} catch (a) {
|
|
1778
|
-
|
|
1778
|
+
A(
|
|
1779
1779
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1780
1780
|
t,
|
|
1781
1781
|
a
|
|
1782
1782
|
);
|
|
1783
1783
|
}
|
|
1784
1784
|
}
|
|
1785
|
-
function
|
|
1785
|
+
function X(e) {
|
|
1786
1786
|
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);
|
|
1787
1787
|
return {
|
|
1788
1788
|
...e,
|
|
@@ -1793,7 +1793,7 @@ function G(e) {
|
|
|
1793
1793
|
}
|
|
1794
1794
|
};
|
|
1795
1795
|
}
|
|
1796
|
-
function
|
|
1796
|
+
function Be(e) {
|
|
1797
1797
|
const s = [];
|
|
1798
1798
|
for (const t of e)
|
|
1799
1799
|
for (const a of t.parts)
|
|
@@ -1821,8 +1821,8 @@ function Ke(e) {
|
|
|
1821
1821
|
}
|
|
1822
1822
|
return s;
|
|
1823
1823
|
}
|
|
1824
|
-
function
|
|
1825
|
-
const a =
|
|
1824
|
+
function ke(e, s = [], t = []) {
|
|
1825
|
+
const a = Be(s), n = t.map((o) => {
|
|
1826
1826
|
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";
|
|
1827
1827
|
return {
|
|
1828
1828
|
type: "file",
|
|
@@ -1851,12 +1851,12 @@ function Re(e, s = [], t = []) {
|
|
|
1851
1851
|
}
|
|
1852
1852
|
};
|
|
1853
1853
|
}
|
|
1854
|
-
function
|
|
1854
|
+
function Nt(e) {
|
|
1855
1855
|
return e != null && e.parts ? e.parts.filter(
|
|
1856
1856
|
(s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
|
|
1857
1857
|
) : [];
|
|
1858
1858
|
}
|
|
1859
|
-
function
|
|
1859
|
+
function Ut(e) {
|
|
1860
1860
|
var t, a;
|
|
1861
1861
|
const s = (a = (t = e == null ? void 0 : e.parts) == null ? void 0 : t.find(
|
|
1862
1862
|
(n) => n.type === "text"
|
|
@@ -1870,16 +1870,16 @@ function Nt(e) {
|
|
|
1870
1870
|
return !1;
|
|
1871
1871
|
}
|
|
1872
1872
|
}
|
|
1873
|
-
function
|
|
1873
|
+
function fe(e, s) {
|
|
1874
1874
|
if (typeof localStorage > "u") {
|
|
1875
|
-
|
|
1875
|
+
V("localStorage not available, cannot update session ID");
|
|
1876
1876
|
return;
|
|
1877
1877
|
}
|
|
1878
1878
|
try {
|
|
1879
1879
|
const t = localStorage.getItem(e);
|
|
1880
1880
|
if (t) {
|
|
1881
1881
|
const a = JSON.parse(t), n = a.sessionId;
|
|
1882
|
-
a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)),
|
|
1882
|
+
a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)), V(
|
|
1883
1883
|
"Updated localStorage[%s] session ID: %s -> %s",
|
|
1884
1884
|
e,
|
|
1885
1885
|
n,
|
|
@@ -1890,14 +1890,14 @@ function ge(e, s) {
|
|
|
1890
1890
|
sessionId: s,
|
|
1891
1891
|
timestamp: Date.now()
|
|
1892
1892
|
};
|
|
1893
|
-
localStorage.setItem(e, JSON.stringify(a)),
|
|
1893
|
+
localStorage.setItem(e, JSON.stringify(a)), V(
|
|
1894
1894
|
"Created new session in localStorage[%s]: %s",
|
|
1895
1895
|
e,
|
|
1896
1896
|
s
|
|
1897
1897
|
);
|
|
1898
1898
|
}
|
|
1899
1899
|
} catch (t) {
|
|
1900
|
-
|
|
1900
|
+
V(
|
|
1901
1901
|
"Failed to update localStorage sessionId to %s: %O",
|
|
1902
1902
|
s,
|
|
1903
1903
|
t
|
|
@@ -1911,7 +1911,7 @@ async function Ht(e) {
|
|
|
1911
1911
|
if (t.parts.some(
|
|
1912
1912
|
(n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
|
|
1913
1913
|
)) {
|
|
1914
|
-
const n =
|
|
1914
|
+
const n = Mt(
|
|
1915
1915
|
t.parts
|
|
1916
1916
|
);
|
|
1917
1917
|
s.push({
|
|
@@ -1922,7 +1922,7 @@ async function Ht(e) {
|
|
|
1922
1922
|
s.push(t);
|
|
1923
1923
|
else
|
|
1924
1924
|
s.push(t);
|
|
1925
|
-
return
|
|
1925
|
+
return wt(), s;
|
|
1926
1926
|
}
|
|
1927
1927
|
function Ot() {
|
|
1928
1928
|
const e = /* @__PURE__ */ new Map();
|
|
@@ -1930,13 +1930,13 @@ function Ot() {
|
|
|
1930
1930
|
const n = e.get(t);
|
|
1931
1931
|
if (n != null && n.sessionId)
|
|
1932
1932
|
try {
|
|
1933
|
-
await
|
|
1933
|
+
await Rt(
|
|
1934
1934
|
n.sessionId,
|
|
1935
1935
|
a,
|
|
1936
1936
|
n.conversationStorageKey
|
|
1937
1937
|
);
|
|
1938
1938
|
} catch (o) {
|
|
1939
|
-
|
|
1939
|
+
V(
|
|
1940
1940
|
`Failed to persist conversation history for agent ${t}:`,
|
|
1941
1941
|
o
|
|
1942
1942
|
);
|
|
@@ -1946,22 +1946,22 @@ function Ot() {
|
|
|
1946
1946
|
async createAgent(t, a) {
|
|
1947
1947
|
if (e.has(t))
|
|
1948
1948
|
return e.get(t).client;
|
|
1949
|
-
const n =
|
|
1949
|
+
const n = Tt(a), o = a.sessionId || null, r = a.conversationStorageKey, l = a.sessionIdStorageKey, i = {
|
|
1950
1950
|
odieBotId: a.odieBotId,
|
|
1951
1951
|
authProvider: a.authProvider
|
|
1952
1952
|
};
|
|
1953
1953
|
let u = [];
|
|
1954
1954
|
if (o)
|
|
1955
1955
|
try {
|
|
1956
|
-
u = (await
|
|
1956
|
+
u = (await kt(
|
|
1957
1957
|
o,
|
|
1958
1958
|
r,
|
|
1959
1959
|
i
|
|
1960
1960
|
)).messages;
|
|
1961
|
-
} catch (
|
|
1962
|
-
|
|
1961
|
+
} catch (m) {
|
|
1962
|
+
V(
|
|
1963
1963
|
`Failed to load conversation history for agent ${t} with session ${o}:`,
|
|
1964
|
-
|
|
1964
|
+
m
|
|
1965
1965
|
);
|
|
1966
1966
|
}
|
|
1967
1967
|
const c = {
|
|
@@ -1990,68 +1990,68 @@ function Ot() {
|
|
|
1990
1990
|
const o = e.get(t);
|
|
1991
1991
|
if (!o)
|
|
1992
1992
|
throw new Error(`Agent with key "${t}" not found`);
|
|
1993
|
-
const { withHistory: r = !0, sessionId: l, ...i } = n, { client: u, conversationHistory: c } = o,
|
|
1993
|
+
const { withHistory: r = !0, sessionId: l, ...i } = n, { client: u, conversationHistory: c } = o, m = n.message || ke(
|
|
1994
1994
|
a,
|
|
1995
1995
|
c,
|
|
1996
1996
|
n.imageUrls
|
|
1997
|
-
),
|
|
1998
|
-
message:
|
|
1997
|
+
), f = await u.sendMessage({
|
|
1998
|
+
message: m,
|
|
1999
1999
|
withHistory: r,
|
|
2000
2000
|
sessionId: l || o.sessionId || void 0,
|
|
2001
2001
|
...i
|
|
2002
2002
|
});
|
|
2003
|
-
if (
|
|
2004
|
-
const
|
|
2005
|
-
o.sessionId =
|
|
2003
|
+
if (f.sessionId) {
|
|
2004
|
+
const v = o.sessionId;
|
|
2005
|
+
o.sessionId = f.sessionId, v && f.sessionId && v !== f.sessionId && o.sessionIdStorageKey && (V(
|
|
2006
2006
|
"Session ID changed from %s to %s, updating localStorage",
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
),
|
|
2007
|
+
v,
|
|
2008
|
+
f.sessionId
|
|
2009
|
+
), fe(
|
|
2010
2010
|
o.sessionIdStorageKey,
|
|
2011
|
-
|
|
2011
|
+
f.sessionId
|
|
2012
2012
|
));
|
|
2013
2013
|
}
|
|
2014
|
-
let
|
|
2015
|
-
if ((I =
|
|
2016
|
-
const
|
|
2017
|
-
(
|
|
2018
|
-
), y =
|
|
2019
|
-
(
|
|
2014
|
+
let M = null;
|
|
2015
|
+
if ((I = f.status) != null && I.message) {
|
|
2016
|
+
const v = f.status.message.parts.filter(
|
|
2017
|
+
(x) => x.type === "data" && "toolCallId" in x.data && ("arguments" in x.data || "result" in x.data)
|
|
2018
|
+
), y = f.status.message.parts.filter(
|
|
2019
|
+
(x) => x.type === "text"
|
|
2020
2020
|
);
|
|
2021
|
-
|
|
2021
|
+
M = {
|
|
2022
2022
|
role: "agent",
|
|
2023
2023
|
kind: "message",
|
|
2024
|
-
parts: [...
|
|
2024
|
+
parts: [...v, ...y],
|
|
2025
2025
|
messageId: q(),
|
|
2026
2026
|
metadata: {
|
|
2027
2027
|
timestamp: Date.now()
|
|
2028
2028
|
}
|
|
2029
2029
|
};
|
|
2030
2030
|
}
|
|
2031
|
-
const
|
|
2031
|
+
const g = [
|
|
2032
2032
|
...c,
|
|
2033
2033
|
// Store only the new content from the user message (without history parts)
|
|
2034
|
-
|
|
2034
|
+
pe(a),
|
|
2035
2035
|
// Add complete agent response with tool calls/results if present
|
|
2036
|
-
...
|
|
2036
|
+
...M ? [X(M)] : []
|
|
2037
2037
|
];
|
|
2038
|
-
let h =
|
|
2039
|
-
if (
|
|
2040
|
-
const
|
|
2041
|
-
|
|
2038
|
+
let h = g;
|
|
2039
|
+
if (f.agentMessage) {
|
|
2040
|
+
const v = X(
|
|
2041
|
+
f.agentMessage
|
|
2042
2042
|
);
|
|
2043
2043
|
h = [
|
|
2044
|
-
...
|
|
2045
|
-
|
|
2044
|
+
...g,
|
|
2045
|
+
v
|
|
2046
2046
|
];
|
|
2047
2047
|
}
|
|
2048
2048
|
return o.conversationHistory = h, r && await s(
|
|
2049
2049
|
t,
|
|
2050
2050
|
h
|
|
2051
|
-
),
|
|
2051
|
+
), f;
|
|
2052
2052
|
},
|
|
2053
2053
|
async *sendMessageStream(t, a, n = {}) {
|
|
2054
|
-
var
|
|
2054
|
+
var b, S, T, d, w, U;
|
|
2055
2055
|
const o = e.get(t);
|
|
2056
2056
|
if (!o)
|
|
2057
2057
|
throw new Error(`Agent with key "${t}" not found`);
|
|
@@ -2061,56 +2061,56 @@ function Ot() {
|
|
|
2061
2061
|
metadata: i,
|
|
2062
2062
|
sessionId: u,
|
|
2063
2063
|
message: c,
|
|
2064
|
-
...
|
|
2065
|
-
} = n, { client:
|
|
2066
|
-
o.currentAbortController =
|
|
2064
|
+
...m
|
|
2065
|
+
} = n, { client: f } = o, M = i ? (({ contentType: p, ...C }) => C)(i) : void 0, g = new AbortController();
|
|
2066
|
+
o.currentAbortController = g, l && l.addEventListener(
|
|
2067
2067
|
"abort",
|
|
2068
|
-
() =>
|
|
2068
|
+
() => g.abort()
|
|
2069
2069
|
);
|
|
2070
2070
|
let h = [
|
|
2071
2071
|
...o.conversationHistory
|
|
2072
2072
|
], I = [];
|
|
2073
|
-
const
|
|
2073
|
+
const v = await Ht(
|
|
2074
2074
|
h
|
|
2075
2075
|
);
|
|
2076
|
-
o.conversationHistory =
|
|
2076
|
+
o.conversationHistory = v, h = v, r && await s(
|
|
2077
2077
|
t,
|
|
2078
|
-
|
|
2078
|
+
v
|
|
2079
2079
|
);
|
|
2080
2080
|
let y;
|
|
2081
2081
|
if (c) {
|
|
2082
|
-
const
|
|
2083
|
-
|
|
2082
|
+
const p = Be(
|
|
2083
|
+
v
|
|
2084
2084
|
);
|
|
2085
2085
|
y = {
|
|
2086
2086
|
...c,
|
|
2087
|
-
parts: [...
|
|
2087
|
+
parts: [...p, ...c.parts]
|
|
2088
2088
|
};
|
|
2089
2089
|
} else
|
|
2090
|
-
y =
|
|
2090
|
+
y = ke(
|
|
2091
2091
|
a,
|
|
2092
|
-
|
|
2092
|
+
v,
|
|
2093
2093
|
n.imageUrls
|
|
2094
2094
|
);
|
|
2095
2095
|
if (n.metadata && !c) {
|
|
2096
|
-
const { contentType:
|
|
2097
|
-
if (
|
|
2096
|
+
const { contentType: p, ...C } = n.metadata;
|
|
2097
|
+
if (p) {
|
|
2098
2098
|
const k = y.parts[y.parts.length - 1];
|
|
2099
2099
|
k && k.type === "text" && (k.metadata = {
|
|
2100
2100
|
...k.metadata,
|
|
2101
|
-
contentType:
|
|
2101
|
+
contentType: p
|
|
2102
2102
|
});
|
|
2103
2103
|
}
|
|
2104
|
-
Object.keys(
|
|
2104
|
+
Object.keys(C).length > 0 && (y.metadata = {
|
|
2105
2105
|
...y.metadata,
|
|
2106
|
-
...
|
|
2106
|
+
...C
|
|
2107
2107
|
});
|
|
2108
2108
|
}
|
|
2109
|
-
const
|
|
2109
|
+
const x = c || pe(a, n.metadata);
|
|
2110
2110
|
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
2111
|
-
const
|
|
2112
|
-
(
|
|
2113
|
-
const k = typeof
|
|
2111
|
+
const p = n.imageUrls.map(
|
|
2112
|
+
(C) => {
|
|
2113
|
+
const k = typeof C == "string" ? C : C.url, P = typeof C == "string" ? void 0 : C.metadata, F = (P == null ? void 0 : P.fileType) || "image/jpeg";
|
|
2114
2114
|
return {
|
|
2115
2115
|
type: "file",
|
|
2116
2116
|
file: {
|
|
@@ -2122,43 +2122,43 @@ function Ot() {
|
|
|
2122
2122
|
};
|
|
2123
2123
|
}
|
|
2124
2124
|
);
|
|
2125
|
-
|
|
2125
|
+
x.parts.push(...p);
|
|
2126
2126
|
}
|
|
2127
2127
|
h = [
|
|
2128
2128
|
...h,
|
|
2129
|
-
|
|
2129
|
+
x
|
|
2130
2130
|
], o.conversationHistory = h, r && await s(
|
|
2131
2131
|
t,
|
|
2132
2132
|
h
|
|
2133
2133
|
);
|
|
2134
|
-
for await (const
|
|
2134
|
+
for await (const p of f.sendMessageStream({
|
|
2135
2135
|
message: y,
|
|
2136
2136
|
withHistory: r,
|
|
2137
2137
|
sessionId: u || o.sessionId || void 0,
|
|
2138
|
-
abortSignal:
|
|
2139
|
-
...
|
|
2140
|
-
...
|
|
2141
|
-
metadata:
|
|
2138
|
+
abortSignal: g.signal,
|
|
2139
|
+
...m,
|
|
2140
|
+
...M && Object.keys(M).length > 0 && {
|
|
2141
|
+
metadata: M
|
|
2142
2142
|
}
|
|
2143
2143
|
})) {
|
|
2144
|
-
if (
|
|
2145
|
-
const
|
|
2146
|
-
o.sessionId =
|
|
2144
|
+
if (p.sessionId) {
|
|
2145
|
+
const C = o.sessionId;
|
|
2146
|
+
o.sessionId = p.sessionId, p.sessionId && C !== p.sessionId && o.sessionIdStorageKey && (V(
|
|
2147
2147
|
"Session ID %s, updating localStorage",
|
|
2148
|
-
|
|
2149
|
-
),
|
|
2148
|
+
C ? `changed from ${C} to ${p.sessionId}` : `received: ${p.sessionId}`
|
|
2149
|
+
), fe(
|
|
2150
2150
|
o.sessionIdStorageKey,
|
|
2151
|
-
|
|
2151
|
+
p.sessionId
|
|
2152
2152
|
));
|
|
2153
2153
|
}
|
|
2154
|
-
if (((
|
|
2155
|
-
I =
|
|
2156
|
-
|
|
2154
|
+
if (((b = p.status) == null ? void 0 : b.state) === "input-required" && ((S = p.status) != null && S.message)) {
|
|
2155
|
+
I = Q(
|
|
2156
|
+
p.status.message
|
|
2157
2157
|
).map(
|
|
2158
2158
|
(P) => P.data.toolCallId
|
|
2159
2159
|
);
|
|
2160
|
-
const k =
|
|
2161
|
-
|
|
2160
|
+
const k = X(
|
|
2161
|
+
p.status.message
|
|
2162
2162
|
);
|
|
2163
2163
|
h = [
|
|
2164
2164
|
...h,
|
|
@@ -2168,9 +2168,9 @@ function Ot() {
|
|
|
2168
2168
|
h
|
|
2169
2169
|
);
|
|
2170
2170
|
}
|
|
2171
|
-
if (((
|
|
2172
|
-
const k =
|
|
2173
|
-
|
|
2171
|
+
if (((T = p.status) == null ? void 0 : T.state) === "working" && ((d = p.status) != null && d.message) && !p.final) {
|
|
2172
|
+
const k = Nt(
|
|
2173
|
+
p.status.message
|
|
2174
2174
|
).filter(
|
|
2175
2175
|
(P) => I.includes(
|
|
2176
2176
|
P.data.toolCallId
|
|
@@ -2185,35 +2185,35 @@ function Ot() {
|
|
|
2185
2185
|
};
|
|
2186
2186
|
h = [
|
|
2187
2187
|
...h,
|
|
2188
|
-
|
|
2188
|
+
X(P)
|
|
2189
2189
|
], o.conversationHistory = h, r && await s(
|
|
2190
2190
|
t,
|
|
2191
2191
|
h
|
|
2192
2192
|
);
|
|
2193
|
-
} else
|
|
2193
|
+
} else Ut(p.status.message) && (h = [
|
|
2194
2194
|
...h,
|
|
2195
|
-
|
|
2196
|
-
|
|
2195
|
+
X(
|
|
2196
|
+
p.status.message
|
|
2197
2197
|
)
|
|
2198
2198
|
], o.conversationHistory = h, r && await s(
|
|
2199
2199
|
t,
|
|
2200
2200
|
h
|
|
2201
2201
|
));
|
|
2202
2202
|
}
|
|
2203
|
-
if (
|
|
2203
|
+
if (p.final && ((w = p.status) == null ? void 0 : w.state) !== "input-required") {
|
|
2204
2204
|
I = [];
|
|
2205
|
-
let
|
|
2206
|
-
(
|
|
2207
|
-
|
|
2205
|
+
let C = null;
|
|
2206
|
+
(U = p.status) != null && U.message && (C = X(
|
|
2207
|
+
p.status.message
|
|
2208
2208
|
), h = [
|
|
2209
2209
|
...h,
|
|
2210
|
-
|
|
2210
|
+
C
|
|
2211
2211
|
], o.conversationHistory = h, r && await s(
|
|
2212
2212
|
t,
|
|
2213
2213
|
h
|
|
2214
2214
|
));
|
|
2215
2215
|
}
|
|
2216
|
-
yield
|
|
2216
|
+
yield p;
|
|
2217
2217
|
}
|
|
2218
2218
|
o.currentAbortController = null;
|
|
2219
2219
|
},
|
|
@@ -2248,7 +2248,7 @@ function Ot() {
|
|
|
2248
2248
|
role: "user",
|
|
2249
2249
|
kind: "message",
|
|
2250
2250
|
parts: [
|
|
2251
|
-
|
|
2251
|
+
z(a, n, o)
|
|
2252
2252
|
],
|
|
2253
2253
|
messageId: q()
|
|
2254
2254
|
}
|
|
@@ -2258,7 +2258,7 @@ function Ot() {
|
|
|
2258
2258
|
const a = e.get(t);
|
|
2259
2259
|
if (!a)
|
|
2260
2260
|
throw new Error(`Agent with key "${t}" not found`);
|
|
2261
|
-
a.conversationHistory = [], a.sessionId && await
|
|
2261
|
+
a.conversationHistory = [], a.sessionId && await Et(
|
|
2262
2262
|
a.sessionId,
|
|
2263
2263
|
a.conversationStorageKey
|
|
2264
2264
|
);
|
|
@@ -2279,7 +2279,7 @@ function Ot() {
|
|
|
2279
2279
|
const n = e.get(t);
|
|
2280
2280
|
if (!n)
|
|
2281
2281
|
throw new Error(`Agent with key "${t}" not found`);
|
|
2282
|
-
n.sessionId = a, n.sessionIdStorageKey &&
|
|
2282
|
+
n.sessionId = a, n.sessionIdStorageKey && fe(
|
|
2283
2283
|
n.sessionIdStorageKey,
|
|
2284
2284
|
a
|
|
2285
2285
|
);
|
|
@@ -2295,12 +2295,12 @@ function Ot() {
|
|
|
2295
2295
|
}
|
|
2296
2296
|
};
|
|
2297
2297
|
}
|
|
2298
|
-
const
|
|
2299
|
-
function
|
|
2300
|
-
return
|
|
2298
|
+
const $t = Ot();
|
|
2299
|
+
function Y() {
|
|
2300
|
+
return $t;
|
|
2301
2301
|
}
|
|
2302
|
-
function
|
|
2303
|
-
const [e, s] =
|
|
2302
|
+
function qt() {
|
|
2303
|
+
const [e, s] = Ne([]), t = j(
|
|
2304
2304
|
(o) => {
|
|
2305
2305
|
s((r) => {
|
|
2306
2306
|
const l = r.findIndex(
|
|
@@ -2314,9 +2314,9 @@ function $t() {
|
|
|
2314
2314
|
});
|
|
2315
2315
|
},
|
|
2316
2316
|
[]
|
|
2317
|
-
), a =
|
|
2317
|
+
), a = j((o) => {
|
|
2318
2318
|
s((r) => r.filter((l) => l.id !== o));
|
|
2319
|
-
}, []), n =
|
|
2319
|
+
}, []), n = j(() => {
|
|
2320
2320
|
s([]);
|
|
2321
2321
|
}, []);
|
|
2322
2322
|
return {
|
|
@@ -2326,7 +2326,7 @@ function $t() {
|
|
|
2326
2326
|
registrations: e
|
|
2327
2327
|
};
|
|
2328
2328
|
}
|
|
2329
|
-
function
|
|
2329
|
+
function Ft(e, s) {
|
|
2330
2330
|
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" ? {
|
|
2331
2331
|
type: "component",
|
|
2332
2332
|
id: n.id,
|
|
@@ -2346,7 +2346,7 @@ function qt(e, s) {
|
|
|
2346
2346
|
order: n.order
|
|
2347
2347
|
}).sort((n, o) => (n.order ?? 1 / 0) - (o.order ?? 1 / 0));
|
|
2348
2348
|
}
|
|
2349
|
-
const
|
|
2349
|
+
const Dt = (e) => e.type === "text" ? {
|
|
2350
2350
|
...e,
|
|
2351
2351
|
metadata: e.metadata ? { ...e.metadata } : void 0
|
|
2352
2352
|
} : e.type === "file" ? {
|
|
@@ -2357,21 +2357,21 @@ const Ft = (e) => e.type === "text" ? {
|
|
|
2357
2357
|
...e,
|
|
2358
2358
|
data: { ...e.data },
|
|
2359
2359
|
metadata: e.metadata ? { ...e.metadata } : void 0
|
|
2360
|
-
},
|
|
2360
|
+
}, jt = (e) => e.parts.filter(
|
|
2361
2361
|
(s) => {
|
|
2362
2362
|
var t;
|
|
2363
2363
|
return s.type === "text" && ((t = s.metadata) == null ? void 0 : t.contentType) !== "context";
|
|
2364
2364
|
}
|
|
2365
2365
|
).map((s) => s.text).join(`
|
|
2366
|
-
`).trim(),
|
|
2366
|
+
`).trim(), Lt = (e) => ({
|
|
2367
2367
|
...e,
|
|
2368
2368
|
messageId: q(),
|
|
2369
2369
|
metadata: {
|
|
2370
2370
|
...e.metadata || {},
|
|
2371
2371
|
timestamp: Date.now()
|
|
2372
2372
|
},
|
|
2373
|
-
parts: e.parts.map(
|
|
2374
|
-
}),
|
|
2373
|
+
parts: e.parts.map(Dt)
|
|
2374
|
+
}), We = (e, s) => {
|
|
2375
2375
|
const t = e.findIndex(
|
|
2376
2376
|
(r) => r.messageId === s && r.role === "agent"
|
|
2377
2377
|
);
|
|
@@ -2385,27 +2385,27 @@ const Ft = (e) => e.type === "text" ? {
|
|
|
2385
2385
|
}
|
|
2386
2386
|
if (a === -1)
|
|
2387
2387
|
return null;
|
|
2388
|
-
const n = e[a], o =
|
|
2388
|
+
const n = e[a], o = jt(n);
|
|
2389
2389
|
return o ? {
|
|
2390
2390
|
baseHistory: e.slice(0, a),
|
|
2391
2391
|
userMessage: n,
|
|
2392
2392
|
prompt: o
|
|
2393
2393
|
} : null;
|
|
2394
|
-
},
|
|
2395
|
-
const t =
|
|
2394
|
+
}, Jt = (e, s) => {
|
|
2395
|
+
const t = We(e, s);
|
|
2396
2396
|
return t ? {
|
|
2397
2397
|
...t,
|
|
2398
|
-
userMessage:
|
|
2398
|
+
userMessage: Lt(t.userMessage)
|
|
2399
2399
|
} : null;
|
|
2400
|
-
},
|
|
2400
|
+
}, ze = (e, s) => !!We(e, s), Pe = (e) => {
|
|
2401
2401
|
for (let s = e.length - 1; s >= 0; s--) {
|
|
2402
2402
|
const t = e[s];
|
|
2403
|
-
if (t.role === "agent" &&
|
|
2403
|
+
if (t.role === "agent" && ze(e, t.messageId))
|
|
2404
2404
|
return t.messageId;
|
|
2405
2405
|
}
|
|
2406
2406
|
return null;
|
|
2407
2407
|
};
|
|
2408
|
-
function
|
|
2408
|
+
function Kt({
|
|
2409
2409
|
agentId: e,
|
|
2410
2410
|
isValidConfig: s,
|
|
2411
2411
|
isSendingRef: t,
|
|
@@ -2413,39 +2413,39 @@ function Jt({
|
|
|
2413
2413
|
transformMessages: n,
|
|
2414
2414
|
sendMessage: o
|
|
2415
2415
|
}) {
|
|
2416
|
-
const r =
|
|
2416
|
+
const r = j(
|
|
2417
2417
|
async (i) => {
|
|
2418
2418
|
if (!s || t.current)
|
|
2419
2419
|
return;
|
|
2420
|
-
const c =
|
|
2421
|
-
if (!
|
|
2420
|
+
const c = Y().getConversationHistory(e), m = (i == null ? void 0 : i.id) ?? Pe(c);
|
|
2421
|
+
if (!m)
|
|
2422
2422
|
return;
|
|
2423
|
-
const
|
|
2423
|
+
const f = Jt(
|
|
2424
2424
|
c,
|
|
2425
|
-
|
|
2425
|
+
m
|
|
2426
2426
|
);
|
|
2427
|
-
if (!
|
|
2427
|
+
if (!f)
|
|
2428
2428
|
return;
|
|
2429
|
-
const
|
|
2429
|
+
const M = {
|
|
2430
2430
|
clientMessages: c,
|
|
2431
2431
|
uiMessages: a.current.uiMessages
|
|
2432
|
-
},
|
|
2433
|
-
|
|
2432
|
+
}, g = n(
|
|
2433
|
+
f.baseHistory
|
|
2434
2434
|
);
|
|
2435
2435
|
try {
|
|
2436
|
-
await o(
|
|
2436
|
+
await o(f.prompt, void 0, {
|
|
2437
2437
|
initialClientMessages: [
|
|
2438
|
-
...
|
|
2439
|
-
|
|
2438
|
+
...f.baseHistory,
|
|
2439
|
+
f.userMessage
|
|
2440
2440
|
],
|
|
2441
|
-
initialUiMessages:
|
|
2442
|
-
messageOverride:
|
|
2441
|
+
initialUiMessages: g,
|
|
2442
|
+
messageOverride: f.userMessage,
|
|
2443
2443
|
preserveUiOnlyMessages: !1,
|
|
2444
|
-
truncateHistoryTo:
|
|
2445
|
-
restoreOnError:
|
|
2444
|
+
truncateHistoryTo: f.baseHistory,
|
|
2445
|
+
restoreOnError: M
|
|
2446
2446
|
});
|
|
2447
2447
|
} catch (h) {
|
|
2448
|
-
|
|
2448
|
+
A("Regenerate failed; conversation restored", h);
|
|
2449
2449
|
}
|
|
2450
2450
|
},
|
|
2451
2451
|
[
|
|
@@ -2457,22 +2457,22 @@ function Jt({
|
|
|
2457
2457
|
n
|
|
2458
2458
|
]
|
|
2459
2459
|
);
|
|
2460
|
-
return { getRegenerateHandler:
|
|
2460
|
+
return { getRegenerateHandler: j(
|
|
2461
2461
|
(i) => {
|
|
2462
|
-
const u = a.current, c =
|
|
2463
|
-
return !s || i && i.role !== "agent" || !
|
|
2464
|
-
|
|
2465
|
-
|
|
2462
|
+
const u = a.current, c = Y(), m = c.hasAgent(e) ? c.getConversationHistory(e) : u.clientMessages, f = (i == null ? void 0 : i.id) ?? Pe(m);
|
|
2463
|
+
return !s || i && i.role !== "agent" || !f || !ze(
|
|
2464
|
+
m,
|
|
2465
|
+
f
|
|
2466
2466
|
) ? null : () => r(i);
|
|
2467
2467
|
},
|
|
2468
2468
|
[e, r, s, a]
|
|
2469
2469
|
) };
|
|
2470
2470
|
}
|
|
2471
|
-
const
|
|
2471
|
+
const me = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Bt = (e, s) => e.filter(
|
|
2472
2472
|
(t) => !s.has(t.id) && t.role !== "user"
|
|
2473
|
-
),
|
|
2473
|
+
), Ve = (e, s = "40%") => ({
|
|
2474
2474
|
type: "component",
|
|
2475
|
-
component: () =>
|
|
2475
|
+
component: () => Ye.createElement("img", {
|
|
2476
2476
|
src: e,
|
|
2477
2477
|
alt: "Uploaded image",
|
|
2478
2478
|
style: {
|
|
@@ -2484,7 +2484,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
|
|
|
2484
2484
|
display: "inline-block"
|
|
2485
2485
|
}
|
|
2486
2486
|
})
|
|
2487
|
-
}),
|
|
2487
|
+
}), oe = (e, s = []) => {
|
|
2488
2488
|
var r, l;
|
|
2489
2489
|
if (e.parts.some((i) => {
|
|
2490
2490
|
if (i.type === "data") {
|
|
@@ -2504,7 +2504,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
|
|
|
2504
2504
|
if (i.type === "file") {
|
|
2505
2505
|
const c = i.file.uri || (i.file.mimeType && i.file.bytes ? `data:${i.file.mimeType};base64,${i.file.bytes}` : void 0);
|
|
2506
2506
|
if (c)
|
|
2507
|
-
return
|
|
2507
|
+
return Ve(c);
|
|
2508
2508
|
}
|
|
2509
2509
|
if (i.type === "data") {
|
|
2510
2510
|
const c = i.data;
|
|
@@ -2518,7 +2518,7 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
|
|
|
2518
2518
|
} : Array.isArray(c.sources) && c.sources.length > 0 ? {
|
|
2519
2519
|
type: "data",
|
|
2520
2520
|
data: c
|
|
2521
|
-
} : (
|
|
2521
|
+
} : (A("Dropping unrecognized data part", c), null);
|
|
2522
2522
|
}
|
|
2523
2523
|
return {
|
|
2524
2524
|
type: "text",
|
|
@@ -2539,32 +2539,32 @@ const fe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Kt = (e, s)
|
|
|
2539
2539
|
icon: e.role === "agent" ? "assistant" : void 0
|
|
2540
2540
|
};
|
|
2541
2541
|
if (e.role === "agent" && s.length > 0) {
|
|
2542
|
-
const i =
|
|
2542
|
+
const i = Ft(
|
|
2543
2543
|
o,
|
|
2544
2544
|
s
|
|
2545
2545
|
);
|
|
2546
2546
|
i.length > 0 && (o.actions = i);
|
|
2547
2547
|
}
|
|
2548
2548
|
return o;
|
|
2549
|
-
},
|
|
2549
|
+
}, Wt = () => ({
|
|
2550
2550
|
getClientContext: () => ({})
|
|
2551
|
-
}),
|
|
2551
|
+
}), zt = () => ({
|
|
2552
2552
|
getAvailableTools: async () => [],
|
|
2553
2553
|
executeTool: async () => ({
|
|
2554
2554
|
success: !0,
|
|
2555
2555
|
result: "No tools available"
|
|
2556
2556
|
})
|
|
2557
|
-
}),
|
|
2557
|
+
}), Vt = (e) => ["agentId", "agentUrl"].every((t) => {
|
|
2558
2558
|
const a = e[t];
|
|
2559
2559
|
return typeof a == "string" && a.trim().length > 0;
|
|
2560
2560
|
});
|
|
2561
|
-
function
|
|
2561
|
+
function gs(e) {
|
|
2562
2562
|
const s = {
|
|
2563
2563
|
agentId: e.agentId,
|
|
2564
2564
|
agentUrl: e.agentUrl,
|
|
2565
2565
|
sessionId: e.sessionId,
|
|
2566
2566
|
sessionIdStorageKey: e.sessionIdStorageKey
|
|
2567
|
-
}, t =
|
|
2567
|
+
}, t = Vt(s), [a, n] = Ne({
|
|
2568
2568
|
clientMessages: [],
|
|
2569
2569
|
uiMessages: [],
|
|
2570
2570
|
isProcessing: !1,
|
|
@@ -2577,33 +2577,37 @@ function ds(e) {
|
|
|
2577
2577
|
unregisterMessageActions: r,
|
|
2578
2578
|
clearAllMessageActions: l,
|
|
2579
2579
|
registrations: i
|
|
2580
|
-
} =
|
|
2581
|
-
|
|
2580
|
+
} = qt(), u = re(!1), c = re(a);
|
|
2581
|
+
te(() => {
|
|
2582
2582
|
c.current = a;
|
|
2583
2583
|
}, [a]);
|
|
2584
|
-
const
|
|
2585
|
-
|
|
2586
|
-
|
|
2584
|
+
const m = re(e.onTaskUpdate);
|
|
2585
|
+
te(() => {
|
|
2586
|
+
m.current = e.onTaskUpdate;
|
|
2587
|
+
}, [e.onTaskUpdate]);
|
|
2588
|
+
const f = re(i);
|
|
2589
|
+
te(() => {
|
|
2590
|
+
f.current = i;
|
|
2587
2591
|
}, [i]);
|
|
2588
|
-
const
|
|
2589
|
-
(
|
|
2590
|
-
(d) =>
|
|
2592
|
+
const M = j(
|
|
2593
|
+
(T) => T.map(
|
|
2594
|
+
(d) => oe(d, f.current)
|
|
2591
2595
|
).filter((d) => d !== null),
|
|
2592
2596
|
[]
|
|
2593
2597
|
// registrationsRef is stable, so no deps needed
|
|
2594
2598
|
);
|
|
2595
|
-
|
|
2599
|
+
te(() => {
|
|
2596
2600
|
if (!t)
|
|
2597
2601
|
return;
|
|
2598
2602
|
(async () => {
|
|
2599
|
-
const d =
|
|
2603
|
+
const d = Y(), w = s.agentId;
|
|
2600
2604
|
if (d.hasAgent(w))
|
|
2601
|
-
s.sessionId ? (d.updateSessionId(w, s.sessionId), d.getConversationHistory(w).length === 0 && n((
|
|
2602
|
-
...
|
|
2605
|
+
s.sessionId ? (d.updateSessionId(w, s.sessionId), d.getConversationHistory(w).length === 0 && n((C) => ({
|
|
2606
|
+
...C,
|
|
2603
2607
|
clientMessages: [],
|
|
2604
2608
|
uiMessages: []
|
|
2605
|
-
}))) : (d.updateSessionId(w, ""), await d.replaceMessages(w, []), n((
|
|
2606
|
-
...
|
|
2609
|
+
}))) : (d.updateSessionId(w, ""), await d.replaceMessages(w, []), n((p) => ({
|
|
2610
|
+
...p,
|
|
2607
2611
|
clientMessages: [],
|
|
2608
2612
|
uiMessages: []
|
|
2609
2613
|
})));
|
|
@@ -2613,25 +2617,25 @@ function ds(e) {
|
|
|
2613
2617
|
sessionId: s.sessionId,
|
|
2614
2618
|
// Can be empty for new chats
|
|
2615
2619
|
sessionIdStorageKey: s.sessionIdStorageKey,
|
|
2616
|
-
contextProvider: e.contextProvider ||
|
|
2617
|
-
toolProvider: e.toolProvider ||
|
|
2620
|
+
contextProvider: e.contextProvider || Wt(),
|
|
2621
|
+
toolProvider: e.toolProvider || zt(),
|
|
2618
2622
|
authProvider: e.authProvider,
|
|
2619
2623
|
enableStreaming: e.enableStreaming,
|
|
2620
2624
|
odieBotId: e.odieBotId,
|
|
2621
2625
|
credentials: e.credentials
|
|
2622
2626
|
}), s.sessionId) {
|
|
2623
|
-
const
|
|
2624
|
-
n((
|
|
2625
|
-
const
|
|
2627
|
+
const p = d.getConversationHistory(w);
|
|
2628
|
+
n((C) => {
|
|
2629
|
+
const k = M(p);
|
|
2626
2630
|
return {
|
|
2627
|
-
...
|
|
2628
|
-
clientMessages:
|
|
2629
|
-
uiMessages:
|
|
2631
|
+
...C,
|
|
2632
|
+
clientMessages: p,
|
|
2633
|
+
uiMessages: k
|
|
2630
2634
|
};
|
|
2631
2635
|
});
|
|
2632
2636
|
} else
|
|
2633
|
-
n((
|
|
2634
|
-
...
|
|
2637
|
+
n((p) => ({
|
|
2638
|
+
...p,
|
|
2635
2639
|
clientMessages: [],
|
|
2636
2640
|
uiMessages: []
|
|
2637
2641
|
}));
|
|
@@ -2648,228 +2652,237 @@ function ds(e) {
|
|
|
2648
2652
|
e.odieBotId,
|
|
2649
2653
|
e.credentials,
|
|
2650
2654
|
t,
|
|
2651
|
-
|
|
2655
|
+
M
|
|
2652
2656
|
]);
|
|
2653
|
-
const
|
|
2654
|
-
async (
|
|
2655
|
-
var
|
|
2657
|
+
const g = j(
|
|
2658
|
+
async (T, d, w) => {
|
|
2659
|
+
var O, E;
|
|
2656
2660
|
if (!t)
|
|
2657
2661
|
throw new Error("Invalid agent configuration");
|
|
2658
2662
|
if (u.current)
|
|
2659
2663
|
return;
|
|
2660
2664
|
u.current = !0;
|
|
2661
|
-
const
|
|
2662
|
-
if (
|
|
2665
|
+
const U = (d == null ? void 0 : d.type) === "tool_result";
|
|
2666
|
+
if (U && (!(d != null && d.toolCallId) || !(d != null && d.toolId)))
|
|
2663
2667
|
throw new Error(
|
|
2664
2668
|
"`toolCallId` and `toolId` are required when type is `tool_result`"
|
|
2665
2669
|
);
|
|
2666
|
-
const
|
|
2667
|
-
const
|
|
2668
|
-
if (!
|
|
2670
|
+
const p = Y(), C = s.agentId, k = (w == null ? void 0 : w.preserveUiOnlyMessages) ?? !0, P = async (R) => {
|
|
2671
|
+
const H = w == null ? void 0 : w.restoreOnError;
|
|
2672
|
+
if (!H)
|
|
2669
2673
|
return !1;
|
|
2670
2674
|
try {
|
|
2671
|
-
await
|
|
2672
|
-
|
|
2673
|
-
|
|
2675
|
+
await p.replaceMessages(
|
|
2676
|
+
C,
|
|
2677
|
+
H.clientMessages
|
|
2674
2678
|
);
|
|
2675
|
-
} catch (
|
|
2676
|
-
|
|
2679
|
+
} catch (N) {
|
|
2680
|
+
A(
|
|
2677
2681
|
"Failed to restore conversation history after a failed send",
|
|
2678
|
-
|
|
2682
|
+
N
|
|
2679
2683
|
);
|
|
2680
2684
|
}
|
|
2681
|
-
return n((
|
|
2682
|
-
...
|
|
2683
|
-
clientMessages:
|
|
2684
|
-
uiMessages:
|
|
2685
|
+
return n((N) => ({
|
|
2686
|
+
...N,
|
|
2687
|
+
clientMessages: H.clientMessages,
|
|
2688
|
+
uiMessages: H.uiMessages,
|
|
2685
2689
|
isProcessing: !1,
|
|
2686
2690
|
progressMessage: null,
|
|
2687
2691
|
progressPhase: null,
|
|
2688
|
-
error:
|
|
2692
|
+
error: R
|
|
2689
2693
|
})), !0;
|
|
2690
|
-
},
|
|
2691
|
-
if (
|
|
2692
|
-
n((
|
|
2693
|
-
...
|
|
2694
|
+
}, F = Date.now();
|
|
2695
|
+
if (U)
|
|
2696
|
+
n((R) => ({
|
|
2697
|
+
...R,
|
|
2694
2698
|
isProcessing: !0,
|
|
2695
2699
|
error: null
|
|
2696
2700
|
}));
|
|
2697
2701
|
else {
|
|
2698
|
-
const
|
|
2702
|
+
const R = (d == null ? void 0 : d.type) || "text", H = w != null && w.messageOverride ? oe(
|
|
2699
2703
|
w.messageOverride,
|
|
2700
2704
|
[]
|
|
2701
2705
|
) : {
|
|
2702
|
-
id: `user-${
|
|
2706
|
+
id: `user-${F}`,
|
|
2703
2707
|
role: "user",
|
|
2704
2708
|
content: [
|
|
2705
|
-
{ type:
|
|
2709
|
+
{ type: R, text: T },
|
|
2706
2710
|
// Map image URLs to component content parts
|
|
2707
|
-
...((
|
|
2708
|
-
const
|
|
2709
|
-
return
|
|
2711
|
+
...((O = d == null ? void 0 : d.imageUrls) == null ? void 0 : O.map((N) => {
|
|
2712
|
+
const L = typeof N == "string" ? N : N.url;
|
|
2713
|
+
return Ve(L);
|
|
2710
2714
|
})) ?? []
|
|
2711
2715
|
],
|
|
2712
|
-
timestamp:
|
|
2716
|
+
timestamp: F,
|
|
2713
2717
|
archived: (d == null ? void 0 : d.archived) ?? !1,
|
|
2714
2718
|
showIcon: !1
|
|
2715
2719
|
};
|
|
2716
|
-
n((
|
|
2717
|
-
...
|
|
2718
|
-
clientMessages: (w == null ? void 0 : w.initialClientMessages) ??
|
|
2719
|
-
uiMessages:
|
|
2720
|
-
...(w == null ? void 0 : w.initialUiMessages) ??
|
|
2721
|
-
|
|
2722
|
-
] : (w == null ? void 0 : w.initialUiMessages) ??
|
|
2720
|
+
n((N) => ({
|
|
2721
|
+
...N,
|
|
2722
|
+
clientMessages: (w == null ? void 0 : w.initialClientMessages) ?? N.clientMessages,
|
|
2723
|
+
uiMessages: H ? [
|
|
2724
|
+
...(w == null ? void 0 : w.initialUiMessages) ?? N.uiMessages,
|
|
2725
|
+
H
|
|
2726
|
+
] : (w == null ? void 0 : w.initialUiMessages) ?? N.uiMessages,
|
|
2723
2727
|
isProcessing: !0,
|
|
2724
2728
|
error: null
|
|
2725
2729
|
}));
|
|
2726
2730
|
}
|
|
2727
2731
|
try {
|
|
2728
|
-
w != null && w.truncateHistoryTo && await
|
|
2729
|
-
|
|
2732
|
+
w != null && w.truncateHistoryTo && await p.replaceMessages(
|
|
2733
|
+
C,
|
|
2730
2734
|
w.truncateHistoryTo
|
|
2731
2735
|
);
|
|
2732
|
-
let
|
|
2733
|
-
const
|
|
2734
|
-
(d != null && d.archived ||
|
|
2736
|
+
let R = null, H = !1;
|
|
2737
|
+
const N = {}, L = !!(d != null && d.type) && !U;
|
|
2738
|
+
(d != null && d.archived || L) && (N.metadata = {
|
|
2735
2739
|
...(d == null ? void 0 : d.archived) && { archived: !0 },
|
|
2736
|
-
...
|
|
2737
|
-
}), d != null && d.sessionId && (
|
|
2738
|
-
const
|
|
2739
|
-
|
|
2740
|
+
...L && { contentType: d.type }
|
|
2741
|
+
}), d != null && d.sessionId && (N.sessionId = d.sessionId), d != null && d.imageUrls && (N.imageUrls = d.imageUrls), w != null && w.messageOverride && (N.message = w.messageOverride);
|
|
2742
|
+
const B = U ? p.sendToolResult(
|
|
2743
|
+
C,
|
|
2740
2744
|
d.toolCallId,
|
|
2741
2745
|
d.toolId,
|
|
2742
|
-
{ success: !0, message:
|
|
2743
|
-
|
|
2744
|
-
) :
|
|
2745
|
-
|
|
2746
|
-
|
|
2747
|
-
|
|
2746
|
+
{ success: !0, message: T },
|
|
2747
|
+
N
|
|
2748
|
+
) : p.sendMessageStream(
|
|
2749
|
+
C,
|
|
2750
|
+
T,
|
|
2751
|
+
N
|
|
2748
2752
|
);
|
|
2749
|
-
for await (const
|
|
2750
|
-
if (
|
|
2751
|
-
|
|
2752
|
-
|
|
2753
|
-
|
|
2754
|
-
|
|
2755
|
-
|
|
2756
|
-
|
|
2757
|
-
|
|
2758
|
-
|
|
2759
|
-
|
|
2760
|
-
|
|
2753
|
+
for await (const _ of B) {
|
|
2754
|
+
if (m.current)
|
|
2755
|
+
try {
|
|
2756
|
+
await m.current(_);
|
|
2757
|
+
} catch ($) {
|
|
2758
|
+
A(
|
|
2759
|
+
"Error in onTaskUpdate callback: %O",
|
|
2760
|
+
$
|
|
2761
|
+
);
|
|
2762
|
+
}
|
|
2763
|
+
if ((_.progressMessage || _.progressPhase) && n(($) => ({
|
|
2764
|
+
...$,
|
|
2765
|
+
progressMessage: _.progressMessage || null,
|
|
2766
|
+
progressPhase: _.progressPhase || null
|
|
2767
|
+
})), !_.final && _.text) {
|
|
2768
|
+
if (R)
|
|
2769
|
+
n(($) => ({
|
|
2770
|
+
...$,
|
|
2771
|
+
uiMessages: $.uiMessages.map(
|
|
2772
|
+
(D) => D.id === R ? {
|
|
2773
|
+
...D,
|
|
2761
2774
|
content: [
|
|
2762
2775
|
{
|
|
2763
2776
|
type: "text",
|
|
2764
|
-
text:
|
|
2777
|
+
text: _.text
|
|
2765
2778
|
}
|
|
2766
2779
|
]
|
|
2767
|
-
} :
|
|
2780
|
+
} : D
|
|
2768
2781
|
)
|
|
2769
2782
|
}));
|
|
2770
2783
|
else {
|
|
2771
|
-
|
|
2772
|
-
const
|
|
2773
|
-
id:
|
|
2784
|
+
R = `agent-streaming-${Date.now()}`;
|
|
2785
|
+
const $ = {
|
|
2786
|
+
id: R,
|
|
2774
2787
|
role: "agent",
|
|
2775
2788
|
content: [
|
|
2776
|
-
{ type: "text", text:
|
|
2789
|
+
{ type: "text", text: _.text }
|
|
2777
2790
|
],
|
|
2778
2791
|
timestamp: Date.now(),
|
|
2779
2792
|
archived: !1,
|
|
2780
2793
|
showIcon: !0,
|
|
2781
2794
|
icon: "assistant",
|
|
2782
|
-
reactKey:
|
|
2795
|
+
reactKey: R
|
|
2783
2796
|
// Stable key for React rendering
|
|
2784
2797
|
};
|
|
2785
|
-
n((
|
|
2786
|
-
|
|
2798
|
+
n((D) => ({
|
|
2799
|
+
...D,
|
|
2787
2800
|
uiMessages: [
|
|
2788
|
-
|
|
2789
|
-
|
|
2801
|
+
...D.uiMessages,
|
|
2802
|
+
$
|
|
2790
2803
|
]
|
|
2791
2804
|
}));
|
|
2792
2805
|
}
|
|
2793
|
-
|
|
2806
|
+
_.kind === "status" && (R = null);
|
|
2794
2807
|
}
|
|
2795
|
-
if (
|
|
2796
|
-
|
|
2797
|
-
const
|
|
2798
|
-
|
|
2799
|
-
|
|
2808
|
+
if (_.final && ((E = _.status) != null && E.message) && R) {
|
|
2809
|
+
H = !0;
|
|
2810
|
+
const $ = R, D = oe(
|
|
2811
|
+
_.status.message,
|
|
2812
|
+
f.current
|
|
2800
2813
|
);
|
|
2801
|
-
|
|
2802
|
-
const
|
|
2803
|
-
(
|
|
2804
|
-
var
|
|
2805
|
-
if (
|
|
2806
|
-
const
|
|
2814
|
+
D && n((se) => {
|
|
2815
|
+
const ae = se.uiMessages.map(
|
|
2816
|
+
(K) => {
|
|
2817
|
+
var ve, Se;
|
|
2818
|
+
if (K.id === $) {
|
|
2819
|
+
const Qe = D.content.length > 0 && ((ve = D.content[0]) == null ? void 0 : ve.text) && ((Se = K.content[0]) == null ? void 0 : Se.text) && D.content[0].text.length > K.content[0].text.length;
|
|
2807
2820
|
return {
|
|
2808
|
-
|
|
2809
|
-
reactKey:
|
|
2821
|
+
...D,
|
|
2822
|
+
reactKey: K.reactKey || $,
|
|
2810
2823
|
// Keep stable reactKey
|
|
2811
|
-
content:
|
|
2824
|
+
content: Qe ? D.content : K.content
|
|
2812
2825
|
};
|
|
2813
2826
|
}
|
|
2814
|
-
return
|
|
2827
|
+
return K;
|
|
2815
2828
|
}
|
|
2816
|
-
),
|
|
2817
|
-
|
|
2818
|
-
),
|
|
2819
|
-
|
|
2820
|
-
(
|
|
2829
|
+
), ne = p.getConversationHistory(
|
|
2830
|
+
C
|
|
2831
|
+
), ue = new Set(
|
|
2832
|
+
ne.map(
|
|
2833
|
+
(K) => K.messageId
|
|
2821
2834
|
)
|
|
2822
|
-
),
|
|
2823
|
-
(
|
|
2835
|
+
), W = k ? ae : ae.filter(
|
|
2836
|
+
(K) => ue.has(K.id)
|
|
2824
2837
|
);
|
|
2825
2838
|
return {
|
|
2826
|
-
...
|
|
2827
|
-
clientMessages:
|
|
2828
|
-
uiMessages:
|
|
2839
|
+
...se,
|
|
2840
|
+
clientMessages: ne,
|
|
2841
|
+
uiMessages: W,
|
|
2829
2842
|
isProcessing: !1,
|
|
2830
2843
|
progressMessage: null,
|
|
2831
2844
|
progressPhase: null
|
|
2832
2845
|
};
|
|
2833
|
-
}),
|
|
2846
|
+
}), R = null;
|
|
2834
2847
|
}
|
|
2835
2848
|
}
|
|
2836
|
-
if (!
|
|
2837
|
-
const
|
|
2838
|
-
n((
|
|
2839
|
-
let
|
|
2840
|
-
|
|
2841
|
-
(
|
|
2849
|
+
if (!H) {
|
|
2850
|
+
const _ = p.getConversationHistory(C);
|
|
2851
|
+
n(($) => {
|
|
2852
|
+
let D = $.uiMessages;
|
|
2853
|
+
R && (D = $.uiMessages.filter(
|
|
2854
|
+
(W) => W.id !== R
|
|
2842
2855
|
));
|
|
2843
|
-
const
|
|
2844
|
-
(
|
|
2845
|
-
|
|
2846
|
-
|
|
2856
|
+
const se = _.map(
|
|
2857
|
+
(W) => oe(
|
|
2858
|
+
W,
|
|
2859
|
+
f.current
|
|
2847
2860
|
)
|
|
2848
2861
|
).filter(
|
|
2849
|
-
(
|
|
2850
|
-
),
|
|
2851
|
-
|
|
2852
|
-
),
|
|
2853
|
-
|
|
2854
|
-
|
|
2855
|
-
) : [],
|
|
2856
|
-
...
|
|
2857
|
-
...
|
|
2862
|
+
(W) => W !== null
|
|
2863
|
+
), ae = new Set(
|
|
2864
|
+
_.map((W) => W.messageId)
|
|
2865
|
+
), ne = k ? Bt(
|
|
2866
|
+
D,
|
|
2867
|
+
ae
|
|
2868
|
+
) : [], ue = me([
|
|
2869
|
+
...se,
|
|
2870
|
+
...ne
|
|
2858
2871
|
]);
|
|
2859
2872
|
return {
|
|
2860
|
-
|
|
2861
|
-
clientMessages:
|
|
2862
|
-
uiMessages:
|
|
2873
|
+
...$,
|
|
2874
|
+
clientMessages: _,
|
|
2875
|
+
uiMessages: ue,
|
|
2863
2876
|
isProcessing: !1,
|
|
2864
2877
|
progressMessage: null,
|
|
2865
2878
|
progressPhase: null
|
|
2866
2879
|
};
|
|
2867
2880
|
});
|
|
2868
2881
|
}
|
|
2869
|
-
} catch (
|
|
2870
|
-
if (
|
|
2871
|
-
|
|
2872
|
-
...
|
|
2882
|
+
} catch (R) {
|
|
2883
|
+
if (R instanceof Error && R.name === "AbortError") {
|
|
2884
|
+
A("Request was aborted by user"), await P(null) || n((B) => ({
|
|
2885
|
+
...B,
|
|
2873
2886
|
isProcessing: !1,
|
|
2874
2887
|
progressMessage: null,
|
|
2875
2888
|
progressPhase: null,
|
|
@@ -2878,123 +2891,123 @@ function ds(e) {
|
|
|
2878
2891
|
}));
|
|
2879
2892
|
return;
|
|
2880
2893
|
}
|
|
2881
|
-
const
|
|
2882
|
-
throw await
|
|
2883
|
-
...
|
|
2894
|
+
const H = R instanceof Error ? R.message : "Failed to send message";
|
|
2895
|
+
throw await P(H) || n((L) => ({
|
|
2896
|
+
...L,
|
|
2884
2897
|
isProcessing: !1,
|
|
2885
2898
|
progressMessage: null,
|
|
2886
2899
|
progressPhase: null,
|
|
2887
|
-
error:
|
|
2888
|
-
})),
|
|
2900
|
+
error: H
|
|
2901
|
+
})), R;
|
|
2889
2902
|
} finally {
|
|
2890
2903
|
u.current = !1;
|
|
2891
2904
|
}
|
|
2892
2905
|
},
|
|
2893
2906
|
[s.agentId, t]
|
|
2894
|
-
),
|
|
2895
|
-
(
|
|
2896
|
-
[
|
|
2897
|
-
),
|
|
2907
|
+
), h = j(
|
|
2908
|
+
(T, d) => g(T, d),
|
|
2909
|
+
[g]
|
|
2910
|
+
), I = j((T) => {
|
|
2898
2911
|
n((d) => ({
|
|
2899
2912
|
...d,
|
|
2900
|
-
uiMessages:
|
|
2913
|
+
uiMessages: me([...d.uiMessages, T])
|
|
2901
2914
|
}));
|
|
2902
|
-
}, []),
|
|
2915
|
+
}, []), v = j((T) => {
|
|
2903
2916
|
n((d) => ({
|
|
2904
2917
|
...d,
|
|
2905
|
-
suggestions:
|
|
2918
|
+
suggestions: T
|
|
2906
2919
|
}));
|
|
2907
|
-
}, []),
|
|
2908
|
-
n((
|
|
2909
|
-
...
|
|
2920
|
+
}, []), y = j(() => {
|
|
2921
|
+
n((T) => ({
|
|
2922
|
+
...T,
|
|
2910
2923
|
suggestions: []
|
|
2911
2924
|
}));
|
|
2912
2925
|
}, []);
|
|
2913
|
-
|
|
2914
|
-
n((
|
|
2915
|
-
if (u.current ||
|
|
2916
|
-
return
|
|
2917
|
-
const d =
|
|
2918
|
-
|
|
2919
|
-
),
|
|
2920
|
-
(
|
|
2926
|
+
te(() => {
|
|
2927
|
+
n((T) => {
|
|
2928
|
+
if (u.current || T.clientMessages.length === 0)
|
|
2929
|
+
return T;
|
|
2930
|
+
const d = M(T.clientMessages), w = new Set(
|
|
2931
|
+
T.clientMessages.map((p) => p.messageId)
|
|
2932
|
+
), U = T.uiMessages.filter(
|
|
2933
|
+
(p) => !w.has(p.id) && p.role !== "user"
|
|
2921
2934
|
);
|
|
2922
2935
|
return {
|
|
2923
|
-
...
|
|
2924
|
-
uiMessages:
|
|
2936
|
+
...T,
|
|
2937
|
+
uiMessages: me([
|
|
2925
2938
|
...d,
|
|
2926
|
-
...
|
|
2939
|
+
...U
|
|
2927
2940
|
])
|
|
2928
2941
|
};
|
|
2929
2942
|
});
|
|
2930
|
-
}, [i,
|
|
2931
|
-
const
|
|
2943
|
+
}, [i, M]);
|
|
2944
|
+
const x = j(() => {
|
|
2932
2945
|
if (!t)
|
|
2933
2946
|
return;
|
|
2934
|
-
const
|
|
2935
|
-
|
|
2936
|
-
}, [s.agentId, t]),
|
|
2937
|
-
async (
|
|
2947
|
+
const T = Y(), d = s.agentId;
|
|
2948
|
+
T.abortCurrentRequest(d);
|
|
2949
|
+
}, [s.agentId, t]), b = j(
|
|
2950
|
+
async (T) => {
|
|
2938
2951
|
if (!t)
|
|
2939
2952
|
return;
|
|
2940
|
-
const d =
|
|
2941
|
-
await d.replaceMessages(w,
|
|
2942
|
-
const
|
|
2943
|
-
n((
|
|
2944
|
-
...
|
|
2945
|
-
clientMessages:
|
|
2946
|
-
uiMessages:
|
|
2953
|
+
const d = Y(), w = s.agentId;
|
|
2954
|
+
await d.replaceMessages(w, T);
|
|
2955
|
+
const U = M(T);
|
|
2956
|
+
n((p) => ({
|
|
2957
|
+
...p,
|
|
2958
|
+
clientMessages: T,
|
|
2959
|
+
uiMessages: U
|
|
2947
2960
|
}));
|
|
2948
2961
|
},
|
|
2949
|
-
[s.agentId, t,
|
|
2950
|
-
), { getRegenerateHandler:
|
|
2962
|
+
[s.agentId, t, M]
|
|
2963
|
+
), { getRegenerateHandler: S } = Kt({
|
|
2951
2964
|
agentId: s.agentId,
|
|
2952
2965
|
isValidConfig: t,
|
|
2953
2966
|
isSendingRef: u,
|
|
2954
2967
|
stateRef: c,
|
|
2955
|
-
transformMessages:
|
|
2956
|
-
sendMessage:
|
|
2968
|
+
transformMessages: M,
|
|
2969
|
+
sendMessage: g
|
|
2957
2970
|
});
|
|
2958
2971
|
return {
|
|
2959
2972
|
// AgentUI props
|
|
2960
2973
|
messages: a.uiMessages,
|
|
2961
2974
|
isProcessing: a.isProcessing,
|
|
2962
2975
|
error: a.error,
|
|
2963
|
-
onSubmit:
|
|
2976
|
+
onSubmit: h,
|
|
2964
2977
|
suggestions: a.suggestions,
|
|
2965
2978
|
progressMessage: a.progressMessage,
|
|
2966
2979
|
progressPhase: a.progressPhase,
|
|
2967
2980
|
// UI management methods
|
|
2968
|
-
registerSuggestions:
|
|
2969
|
-
clearSuggestions:
|
|
2981
|
+
registerSuggestions: v,
|
|
2982
|
+
clearSuggestions: y,
|
|
2970
2983
|
// Message actions methods
|
|
2971
2984
|
registerMessageActions: o,
|
|
2972
2985
|
unregisterMessageActions: r,
|
|
2973
2986
|
clearAllMessageActions: l,
|
|
2974
|
-
getRegenerateHandler:
|
|
2987
|
+
getRegenerateHandler: S,
|
|
2975
2988
|
// Tool integration
|
|
2976
|
-
addMessage:
|
|
2989
|
+
addMessage: I,
|
|
2977
2990
|
// Abort control
|
|
2978
|
-
abortCurrentRequest:
|
|
2991
|
+
abortCurrentRequest: x,
|
|
2979
2992
|
// Conversation loading
|
|
2980
|
-
loadMessages:
|
|
2993
|
+
loadMessages: b
|
|
2981
2994
|
};
|
|
2982
2995
|
}
|
|
2983
|
-
var
|
|
2984
|
-
const
|
|
2985
|
-
function
|
|
2996
|
+
var Qt = /* @__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))(Qt || {});
|
|
2997
|
+
const _e = "jetpack-ai-jwt-token", Gt = 30 * 60 * 1e3;
|
|
2998
|
+
function Xt() {
|
|
2986
2999
|
var t, a, n;
|
|
2987
3000
|
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);
|
|
2988
3001
|
}
|
|
2989
|
-
async function
|
|
3002
|
+
async function Yt(e, s = !0) {
|
|
2990
3003
|
var i, u;
|
|
2991
|
-
const t = localStorage.getItem(
|
|
3004
|
+
const t = localStorage.getItem(_e);
|
|
2992
3005
|
let a;
|
|
2993
3006
|
if (t)
|
|
2994
3007
|
try {
|
|
2995
3008
|
a = JSON.parse(t);
|
|
2996
3009
|
} catch (c) {
|
|
2997
|
-
|
|
3010
|
+
A("Invalid cached Jetpack token: %O", c);
|
|
2998
3011
|
}
|
|
2999
3012
|
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && s)
|
|
3000
3013
|
return a;
|
|
@@ -3004,10 +3017,10 @@ async function Xt(e, s = !0) {
|
|
|
3004
3017
|
blog_id: ""
|
|
3005
3018
|
};
|
|
3006
3019
|
try {
|
|
3007
|
-
|
|
3020
|
+
Xt() ? r = await Ce({
|
|
3008
3021
|
path: "/wpcom/v2/sites/" + o + "/jetpack-openai-query/jwt",
|
|
3009
3022
|
method: "POST"
|
|
3010
|
-
}) : r = await
|
|
3023
|
+
}) : r = await Ce({
|
|
3011
3024
|
path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
|
|
3012
3025
|
credentials: "same-origin",
|
|
3013
3026
|
headers: {
|
|
@@ -3016,7 +3029,7 @@ async function Xt(e, s = !0) {
|
|
|
3016
3029
|
method: "POST"
|
|
3017
3030
|
});
|
|
3018
3031
|
} catch (c) {
|
|
3019
|
-
throw
|
|
3032
|
+
throw A("Failed to fetch Jetpack token: %O", c), new Error(e(c));
|
|
3020
3033
|
}
|
|
3021
3034
|
if (!(r != null && r.token))
|
|
3022
3035
|
throw new Error(
|
|
@@ -3025,26 +3038,26 @@ async function Xt(e, s = !0) {
|
|
|
3025
3038
|
const l = {
|
|
3026
3039
|
token: r.token,
|
|
3027
3040
|
blogId: r.blog_id || "",
|
|
3028
|
-
expire: Date.now() +
|
|
3041
|
+
expire: Date.now() + Gt
|
|
3029
3042
|
};
|
|
3030
3043
|
try {
|
|
3031
|
-
localStorage.setItem(
|
|
3044
|
+
localStorage.setItem(_e, JSON.stringify(l));
|
|
3032
3045
|
} catch (c) {
|
|
3033
|
-
|
|
3046
|
+
A("Error storing token in localStorage: %O", c);
|
|
3034
3047
|
}
|
|
3035
3048
|
return l;
|
|
3036
3049
|
}
|
|
3037
|
-
const
|
|
3050
|
+
const fs = (e) => async () => {
|
|
3038
3051
|
const s = {};
|
|
3039
3052
|
try {
|
|
3040
|
-
const t = await
|
|
3053
|
+
const t = await Yt(e);
|
|
3041
3054
|
t != null && t.token && (s.Authorization = `${t.token}`);
|
|
3042
3055
|
} catch (t) {
|
|
3043
|
-
throw
|
|
3056
|
+
throw A("Failed to get Jetpack token for auth: %O", t), t;
|
|
3044
3057
|
}
|
|
3045
3058
|
return s;
|
|
3046
3059
|
};
|
|
3047
|
-
function
|
|
3060
|
+
function Zt(e) {
|
|
3048
3061
|
const s = {
|
|
3049
3062
|
type: "object",
|
|
3050
3063
|
properties: {}
|
|
@@ -3059,17 +3072,17 @@ function Yt(e) {
|
|
|
3059
3072
|
_originalAbility: e
|
|
3060
3073
|
};
|
|
3061
3074
|
}
|
|
3062
|
-
function fs(e) {
|
|
3063
|
-
return e.map(Yt);
|
|
3064
|
-
}
|
|
3065
3075
|
function ms(e) {
|
|
3076
|
+
return e.map(Zt);
|
|
3077
|
+
}
|
|
3078
|
+
function ps(e) {
|
|
3066
3079
|
return (e == null ? void 0 : e._source) === "wordpress-ability";
|
|
3067
3080
|
}
|
|
3068
|
-
function
|
|
3081
|
+
function hs(e, s = "agent", t = "wpcom") {
|
|
3069
3082
|
const a = e.replace(/-/g, "_");
|
|
3070
3083
|
return `${t}-${s}-${a}`;
|
|
3071
3084
|
}
|
|
3072
|
-
function
|
|
3085
|
+
function es(e) {
|
|
3073
3086
|
const s = e.split("-");
|
|
3074
3087
|
if (s.length < 3)
|
|
3075
3088
|
throw new Error(
|
|
@@ -3088,58 +3101,58 @@ function Zt(e) {
|
|
|
3088
3101
|
agentId: r
|
|
3089
3102
|
};
|
|
3090
3103
|
}
|
|
3091
|
-
function
|
|
3104
|
+
function ys(e) {
|
|
3092
3105
|
try {
|
|
3093
|
-
const s =
|
|
3106
|
+
const s = es(e);
|
|
3094
3107
|
return s.product.length > 0 && ["agent", "workflow", "chain"].includes(s.type) && s.slug.length > 0;
|
|
3095
3108
|
} catch {
|
|
3096
3109
|
return !1;
|
|
3097
3110
|
}
|
|
3098
3111
|
}
|
|
3099
3112
|
export {
|
|
3100
|
-
|
|
3101
|
-
|
|
3102
|
-
|
|
3103
|
-
|
|
3104
|
-
|
|
3105
|
-
|
|
3106
|
-
|
|
3107
|
-
|
|
3108
|
-
|
|
3109
|
-
|
|
3110
|
-
|
|
3111
|
-
|
|
3112
|
-
|
|
3113
|
-
|
|
3114
|
-
|
|
3115
|
-
|
|
3116
|
-
|
|
3117
|
-
|
|
3118
|
-
|
|
3119
|
-
|
|
3120
|
-
|
|
3121
|
-
|
|
3122
|
-
|
|
3123
|
-
|
|
3124
|
-
|
|
3125
|
-
|
|
3126
|
-
|
|
3127
|
-
|
|
3128
|
-
|
|
3129
|
-
|
|
3130
|
-
|
|
3131
|
-
|
|
3132
|
-
|
|
3113
|
+
Qt as ErrorCodes,
|
|
3114
|
+
Ms as agentsApiContinueResponse,
|
|
3115
|
+
Ts as agentsApiDeleteSession,
|
|
3116
|
+
As as agentsApiListSessions,
|
|
3117
|
+
vs as agentsApiLoadSession,
|
|
3118
|
+
Ss as agentsApiMarkSessionRead,
|
|
3119
|
+
Cs as agentsApiSendMessage,
|
|
3120
|
+
ms as convertAbilitiesToTools,
|
|
3121
|
+
Zt as convertAbilityToTool,
|
|
3122
|
+
cs as createAbortController,
|
|
3123
|
+
xs as createAgentsApiChatAdapter,
|
|
3124
|
+
bs as createAgentsApiRunControlAdapter,
|
|
3125
|
+
Tt as createClient,
|
|
3126
|
+
fs as createJetpackAuthProvider,
|
|
3127
|
+
hs as createOdieBotId,
|
|
3128
|
+
Rs as createPresentQuestionRenderer,
|
|
3129
|
+
ks as createPresentQuestionToolRenderers,
|
|
3130
|
+
Ze as createRequestId,
|
|
3131
|
+
et as createTaskId,
|
|
3132
|
+
pe as createTextMessage,
|
|
3133
|
+
J as extractTextFromMessage,
|
|
3134
|
+
Q as extractToolCallsFromMessage,
|
|
3135
|
+
Y as getAgentManager,
|
|
3136
|
+
Ps as groupToolMessages,
|
|
3137
|
+
ys as isOdieBotId,
|
|
3138
|
+
ps as isWordPressAbility,
|
|
3139
|
+
us as listConversationsFromServer,
|
|
3140
|
+
ds as loadAllMessagesFromServer,
|
|
3141
|
+
he as loadChatFromServer,
|
|
3142
|
+
_s as normalizeAgentsApiMessage,
|
|
3143
|
+
Es as normalizeConversation,
|
|
3144
|
+
Ns as normalizeLoadedSession,
|
|
3145
|
+
Us as normalizePresentQuestionPrompt,
|
|
3133
3146
|
Hs as normalizeRunEvent,
|
|
3134
3147
|
Os as normalizeSendResponse,
|
|
3135
|
-
|
|
3136
|
-
|
|
3137
|
-
|
|
3138
|
-
|
|
3139
|
-
|
|
3140
|
-
|
|
3141
|
-
|
|
3142
|
-
|
|
3143
|
-
|
|
3144
|
-
|
|
3148
|
+
$s as normalizeSessions,
|
|
3149
|
+
es as parseOdieBotId,
|
|
3150
|
+
qs as renderToolGroups,
|
|
3151
|
+
gs as useAgentChat,
|
|
3152
|
+
Fs as useAgentsApiChat,
|
|
3153
|
+
is as useClientAbilities,
|
|
3154
|
+
rs as useClientContext,
|
|
3155
|
+
os as useClientTools,
|
|
3156
|
+
ls as useClientToolsWithAbilities,
|
|
3157
|
+
qt as useMessageActions
|
|
3145
3158
|
};
|