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