@automattic/agenttic-client 0.1.38 → 0.1.40
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.js +345 -331
- package/dist/react/useAgentChat.d.ts +1 -0
- package/dist/react/useAgentChat.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
var $e = Object.defineProperty;
|
|
2
2
|
var Ue = (e, s, t) => s in e ? $e(e, s, { enumerable: !0, configurable: !0, writable: !0, value: t }) : e[s] = t;
|
|
3
3
|
var te = (e, s, t) => Ue(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
-
import qe, { useMemo as Se, useCallback as
|
|
5
|
-
import { l as
|
|
4
|
+
import qe, { useMemo as Se, useCallback as F, useState as ve, useRef as He, useEffect as se } from "react";
|
|
5
|
+
import { l as M, f as Me, a as K } from "./logger-aKHbTlwk.js";
|
|
6
6
|
import pe from "@wordpress/api-fetch";
|
|
7
7
|
function qt(e) {
|
|
8
8
|
return Se(() => e ? {
|
|
@@ -10,7 +10,7 @@ function qt(e) {
|
|
|
10
10
|
try {
|
|
11
11
|
return e() || {};
|
|
12
12
|
} catch (a) {
|
|
13
|
-
return
|
|
13
|
+
return M("Error getting client context: %O", a), {};
|
|
14
14
|
}
|
|
15
15
|
}
|
|
16
16
|
} : void 0, [e]);
|
|
@@ -20,24 +20,24 @@ function ce({
|
|
|
20
20
|
executeTool: s,
|
|
21
21
|
getAbilities: t
|
|
22
22
|
}) {
|
|
23
|
-
const a =
|
|
23
|
+
const a = F(async () => {
|
|
24
24
|
const o = [];
|
|
25
25
|
if (e)
|
|
26
26
|
try {
|
|
27
27
|
const c = await e();
|
|
28
28
|
o.push(...c);
|
|
29
29
|
} catch (c) {
|
|
30
|
-
|
|
30
|
+
M("Error getting available tools: %O", c);
|
|
31
31
|
}
|
|
32
32
|
return o;
|
|
33
|
-
}, [e]), n =
|
|
33
|
+
}, [e]), n = F(
|
|
34
34
|
async (o, c) => {
|
|
35
35
|
if (!s)
|
|
36
36
|
throw new Error("No executeTool callback provided");
|
|
37
37
|
try {
|
|
38
38
|
return await s(o, c);
|
|
39
39
|
} catch (l) {
|
|
40
|
-
throw
|
|
40
|
+
throw M("Error executing tool %s: %O", o, l), l;
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
[s]
|
|
@@ -92,7 +92,7 @@ function ue() {
|
|
|
92
92
|
s += e.charAt(Math.floor(Math.random() * e.length));
|
|
93
93
|
return s;
|
|
94
94
|
}
|
|
95
|
-
function
|
|
95
|
+
function N() {
|
|
96
96
|
return ue();
|
|
97
97
|
}
|
|
98
98
|
function Fe() {
|
|
@@ -101,7 +101,7 @@ function Fe() {
|
|
|
101
101
|
function je() {
|
|
102
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,7 +120,7 @@ function De(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 D(e) {
|
|
124
124
|
return !e || !e.parts || !Array.isArray(e.parts) ? "" : e.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
|
|
125
125
|
}
|
|
126
126
|
function he(e) {
|
|
@@ -141,7 +141,7 @@ function Je(e) {
|
|
|
141
141
|
metadata: {}
|
|
142
142
|
};
|
|
143
143
|
}
|
|
144
|
-
function
|
|
144
|
+
function Ke(e) {
|
|
145
145
|
return {
|
|
146
146
|
type: "data",
|
|
147
147
|
data: {
|
|
@@ -156,7 +156,7 @@ function Le(e) {
|
|
|
156
156
|
metadata: {}
|
|
157
157
|
};
|
|
158
158
|
}
|
|
159
|
-
function
|
|
159
|
+
function L(e) {
|
|
160
160
|
return !e || !e.parts || !Array.isArray(e.parts) ? [] : e.parts.filter(
|
|
161
161
|
(s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
|
|
162
162
|
);
|
|
@@ -172,7 +172,7 @@ function W(e, s, t, a) {
|
|
|
172
172
|
metadata: a ? { error: a } : void 0
|
|
173
173
|
};
|
|
174
174
|
}
|
|
175
|
-
function
|
|
175
|
+
function Le(e) {
|
|
176
176
|
return {
|
|
177
177
|
type: "data",
|
|
178
178
|
data: {
|
|
@@ -185,9 +185,9 @@ function ie(e, s) {
|
|
|
185
185
|
const { contentType: t, ...a } = s || {};
|
|
186
186
|
return {
|
|
187
187
|
role: "user",
|
|
188
|
-
parts: [
|
|
188
|
+
parts: [xe(e, t ? { contentType: t } : void 0)],
|
|
189
189
|
kind: "message",
|
|
190
|
-
messageId:
|
|
190
|
+
messageId: N(),
|
|
191
191
|
metadata: {
|
|
192
192
|
timestamp: Date.now(),
|
|
193
193
|
...a
|
|
@@ -197,9 +197,9 @@ function ie(e, s) {
|
|
|
197
197
|
function G(e) {
|
|
198
198
|
return {
|
|
199
199
|
role: "agent",
|
|
200
|
-
parts: [
|
|
200
|
+
parts: [xe(e)],
|
|
201
201
|
kind: "message",
|
|
202
|
-
messageId:
|
|
202
|
+
messageId: N(),
|
|
203
203
|
metadata: {
|
|
204
204
|
timestamp: Date.now()
|
|
205
205
|
}
|
|
@@ -222,7 +222,7 @@ function X(e, s = []) {
|
|
|
222
222
|
role: "user",
|
|
223
223
|
kind: "message",
|
|
224
224
|
parts: [...s, ...e],
|
|
225
|
-
messageId:
|
|
225
|
+
messageId: N(),
|
|
226
226
|
metadata: {
|
|
227
227
|
timestamp: Date.now()
|
|
228
228
|
}
|
|
@@ -231,7 +231,7 @@ function X(e, s = []) {
|
|
|
231
231
|
function Dt() {
|
|
232
232
|
return new AbortController();
|
|
233
233
|
}
|
|
234
|
-
async function
|
|
234
|
+
async function Be(e, s) {
|
|
235
235
|
if (!s)
|
|
236
236
|
return e;
|
|
237
237
|
try {
|
|
@@ -246,7 +246,7 @@ async function Ke(e, s) {
|
|
|
246
246
|
if (s.getAbilities) {
|
|
247
247
|
const a = await s.getAbilities();
|
|
248
248
|
if (a.length > 0) {
|
|
249
|
-
const n = a.map(
|
|
249
|
+
const n = a.map(Ke);
|
|
250
250
|
t.push(...n);
|
|
251
251
|
}
|
|
252
252
|
}
|
|
@@ -255,7 +255,7 @@ async function Ke(e, s) {
|
|
|
255
255
|
parts: [...e.parts, ...t]
|
|
256
256
|
};
|
|
257
257
|
} catch (t) {
|
|
258
|
-
return
|
|
258
|
+
return M("Warning: Failed to get tools: %s", t), e;
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
function We(e, s) {
|
|
@@ -265,17 +265,17 @@ function We(e, s) {
|
|
|
265
265
|
const t = s.getClientContext();
|
|
266
266
|
if (!t || Object.keys(t).length === 0)
|
|
267
267
|
return e;
|
|
268
|
-
const a =
|
|
268
|
+
const a = Le(t);
|
|
269
269
|
return {
|
|
270
270
|
...e,
|
|
271
271
|
parts: [...e.parts, a]
|
|
272
272
|
};
|
|
273
273
|
} catch (t) {
|
|
274
|
-
return
|
|
274
|
+
return M("Warning: Failed to get context: %s", t), e;
|
|
275
275
|
}
|
|
276
276
|
}
|
|
277
277
|
async function Ve(e, s, t) {
|
|
278
|
-
let a = await
|
|
278
|
+
let a = await Be(
|
|
279
279
|
e,
|
|
280
280
|
s
|
|
281
281
|
);
|
|
@@ -304,7 +304,7 @@ function ze(e, s = "") {
|
|
|
304
304
|
try {
|
|
305
305
|
t.push(JSON.parse(n)), r = l === -1 ? a.length : l + 1;
|
|
306
306
|
} catch (u) {
|
|
307
|
-
|
|
307
|
+
M("Failed to parse SSE event: %o", u), M("Problematic payload: %s", n);
|
|
308
308
|
}
|
|
309
309
|
n = "";
|
|
310
310
|
}
|
|
@@ -321,10 +321,10 @@ async function* Ge(e, s = {}) {
|
|
|
321
321
|
let c = null, l = null;
|
|
322
322
|
try {
|
|
323
323
|
for (; ; ) {
|
|
324
|
-
const { done:
|
|
325
|
-
if (
|
|
324
|
+
const { done: p, value: g } = await a.read();
|
|
325
|
+
if (p)
|
|
326
326
|
break;
|
|
327
|
-
const y = n.decode(g, { stream: !0 }), { events: I, nextBuffer:
|
|
327
|
+
const y = n.decode(g, { stream: !0 }), { events: I, nextBuffer: A } = ze(y, r);
|
|
328
328
|
if (I && Array.isArray(I))
|
|
329
329
|
for (let f = 0; f < I.length; f++) {
|
|
330
330
|
const i = I[f];
|
|
@@ -340,19 +340,19 @@ async function* Ge(e, s = {}) {
|
|
|
340
340
|
if (T.deltaType === "content" && (o.processContentDelta(
|
|
341
341
|
T.content
|
|
342
342
|
), !c && i.params.id && (c = i.params.id), c)) {
|
|
343
|
-
const
|
|
343
|
+
const x = o.getCurrentMessage();
|
|
344
344
|
yield {
|
|
345
345
|
id: c,
|
|
346
346
|
status: {
|
|
347
347
|
state: "working",
|
|
348
|
-
message:
|
|
348
|
+
message: x
|
|
349
349
|
},
|
|
350
350
|
final: !1,
|
|
351
351
|
text: o.getTextContent()
|
|
352
352
|
};
|
|
353
353
|
}
|
|
354
|
-
} catch (
|
|
355
|
-
|
|
354
|
+
} catch (x) {
|
|
355
|
+
M("Failed to process delta: %o", x);
|
|
356
356
|
}
|
|
357
357
|
} else if (i.result && i.result.status) {
|
|
358
358
|
c = i.result.id, l = i.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset();
|
|
@@ -365,7 +365,7 @@ async function* Ge(e, s = {}) {
|
|
|
365
365
|
sessionId: i.result.sessionId,
|
|
366
366
|
status: i.result.status,
|
|
367
367
|
final: i.result.status.state === "completed" || i.result.status.state === "failed" || i.result.status.state === "canceled",
|
|
368
|
-
text:
|
|
368
|
+
text: D(T),
|
|
369
369
|
progressMessage: he(T)
|
|
370
370
|
};
|
|
371
371
|
} else if (i.id && i.result && (c = i.result.id, i.result.status)) {
|
|
@@ -378,12 +378,12 @@ async function* Ge(e, s = {}) {
|
|
|
378
378
|
sessionId: i.result.sessionId,
|
|
379
379
|
status: i.result.status,
|
|
380
380
|
final: i.result.status.state === "completed" || i.result.status.state === "failed" || i.result.status.state === "canceled",
|
|
381
|
-
text:
|
|
381
|
+
text: D(T),
|
|
382
382
|
progressMessage: he(T)
|
|
383
383
|
};
|
|
384
384
|
}
|
|
385
385
|
}
|
|
386
|
-
r =
|
|
386
|
+
r = A;
|
|
387
387
|
}
|
|
388
388
|
} finally {
|
|
389
389
|
a.releaseLock();
|
|
@@ -467,7 +467,7 @@ class Qe {
|
|
|
467
467
|
role: s,
|
|
468
468
|
parts: t,
|
|
469
469
|
kind: "message",
|
|
470
|
-
messageId:
|
|
470
|
+
messageId: N()
|
|
471
471
|
};
|
|
472
472
|
}
|
|
473
473
|
/**
|
|
@@ -477,8 +477,8 @@ class Qe {
|
|
|
477
477
|
this.textContent = "", this.toolCalls.clear();
|
|
478
478
|
}
|
|
479
479
|
}
|
|
480
|
-
function
|
|
481
|
-
throw clearTimeout(s),
|
|
480
|
+
function Ae(e, s, t = "request") {
|
|
481
|
+
throw clearTimeout(s), M("%s failed with error: %O", t, e), e instanceof Error && (M("Error message: %s", e.message), M("Error stack: %s", e.stack)), e;
|
|
482
482
|
}
|
|
483
483
|
function Ce(e, s = "request") {
|
|
484
484
|
if (!e.ok)
|
|
@@ -508,7 +508,7 @@ function Ze(e, s) {
|
|
|
508
508
|
return `${e}/${s}`;
|
|
509
509
|
}
|
|
510
510
|
function et(e, s, t, a) {
|
|
511
|
-
|
|
511
|
+
M("Request: %s %s", e, s), M("Headers: %o", t), a && M("Body: %s", Me(a));
|
|
512
512
|
}
|
|
513
513
|
async function tt(e, s = !1) {
|
|
514
514
|
const t = {
|
|
@@ -541,7 +541,7 @@ function Re(e, s, t) {
|
|
|
541
541
|
};
|
|
542
542
|
}
|
|
543
543
|
async function Y(e, s, t, a, n, r) {
|
|
544
|
-
const { message: o, sessionId: c, taskId: l, metadata: d } = e, { agentId: u, agentUrl: h, authProvider:
|
|
544
|
+
const { message: o, sessionId: c, taskId: l, metadata: d } = e, { agentId: u, agentUrl: h, authProvider: p, proxy: g } = s, { isStreaming: y = !1, enableTokenStreaming: I = !1 } = t, A = c || r, f = Ze(h, u), i = await Ve(
|
|
545
545
|
o,
|
|
546
546
|
a,
|
|
547
547
|
n
|
|
@@ -550,18 +550,18 @@ async function Y(e, s, t, a, n, r) {
|
|
|
550
550
|
message: i,
|
|
551
551
|
metadata: d
|
|
552
552
|
};
|
|
553
|
-
|
|
554
|
-
const
|
|
553
|
+
A && (T.sessionId = A);
|
|
554
|
+
const x = De(
|
|
555
555
|
T,
|
|
556
556
|
y ? "message/stream" : "message/send",
|
|
557
557
|
I && y
|
|
558
558
|
// Only enable token streaming if using SSE
|
|
559
|
-
), w = await tt(
|
|
560
|
-
return et("POST", f, w,
|
|
561
|
-
request:
|
|
559
|
+
), w = await tt(p, y);
|
|
560
|
+
return et("POST", f, w, x), {
|
|
561
|
+
request: x,
|
|
562
562
|
headers: w,
|
|
563
563
|
enhancedMessage: i,
|
|
564
|
-
effectiveSessionId:
|
|
564
|
+
effectiveSessionId: A,
|
|
565
565
|
fullAgentUrl: f
|
|
566
566
|
};
|
|
567
567
|
}
|
|
@@ -576,21 +576,21 @@ async function Ee(e, s, t = {}) {
|
|
|
576
576
|
JSON.stringify(a),
|
|
577
577
|
u
|
|
578
578
|
);
|
|
579
|
-
|
|
579
|
+
M("Making request to %s with options: %O", r, {
|
|
580
580
|
method: h.method,
|
|
581
581
|
headers: h.headers
|
|
582
582
|
});
|
|
583
|
-
const
|
|
584
|
-
clearTimeout(l), Ce(
|
|
585
|
-
const g = await
|
|
586
|
-
return
|
|
583
|
+
const p = await fetch(r, h);
|
|
584
|
+
clearTimeout(l), Ce(p, "request");
|
|
585
|
+
const g = await p.json();
|
|
586
|
+
return M(
|
|
587
587
|
"Response from %s: %d %O",
|
|
588
588
|
r,
|
|
589
|
-
|
|
590
|
-
|
|
589
|
+
p.status,
|
|
590
|
+
Me(g)
|
|
591
591
|
), Xe(g, "request");
|
|
592
592
|
} catch (h) {
|
|
593
|
-
|
|
593
|
+
Ae(h, l, "request");
|
|
594
594
|
}
|
|
595
595
|
}
|
|
596
596
|
async function* Pe(e, s, t) {
|
|
@@ -603,7 +603,7 @@ async function* Pe(e, s, t) {
|
|
|
603
603
|
"streaming request"
|
|
604
604
|
), h = c ? ke(u.signal, c) : u.signal;
|
|
605
605
|
try {
|
|
606
|
-
const
|
|
606
|
+
const p = JSON.stringify(a), g = Re(n, p, h), y = await fetch(r, g);
|
|
607
607
|
if (clearTimeout(d), Ye(y, "streaming request"), !y.body)
|
|
608
608
|
throw new Error(
|
|
609
609
|
"Response body is null - server may not support streaming"
|
|
@@ -612,8 +612,8 @@ async function* Pe(e, s, t) {
|
|
|
612
612
|
yield* Ge(y.body, {
|
|
613
613
|
supportDeltas: I
|
|
614
614
|
});
|
|
615
|
-
} catch (
|
|
616
|
-
|
|
615
|
+
} catch (p) {
|
|
616
|
+
Ae(p, d, "streaming request");
|
|
617
617
|
}
|
|
618
618
|
}
|
|
619
619
|
const st = 12e4;
|
|
@@ -638,7 +638,7 @@ async function Z(e, s, t, a, n) {
|
|
|
638
638
|
}
|
|
639
639
|
};
|
|
640
640
|
} catch (l) {
|
|
641
|
-
return
|
|
641
|
+
return M(
|
|
642
642
|
"Error executing ability %s: %O",
|
|
643
643
|
o.name,
|
|
644
644
|
l
|
|
@@ -657,7 +657,7 @@ async function Z(e, s, t, a, n) {
|
|
|
657
657
|
t
|
|
658
658
|
), returnToAgent: !0 };
|
|
659
659
|
} catch (l) {
|
|
660
|
-
return
|
|
660
|
+
return M(
|
|
661
661
|
"Error executing ability %s: %O",
|
|
662
662
|
o.name,
|
|
663
663
|
l
|
|
@@ -690,7 +690,7 @@ const ge = /* @__PURE__ */ new Map();
|
|
|
690
690
|
async function at(e, s) {
|
|
691
691
|
if (!e || !s || !e.getAvailableTools)
|
|
692
692
|
return !1;
|
|
693
|
-
const t =
|
|
693
|
+
const t = L(s);
|
|
694
694
|
if (t.length === 0)
|
|
695
695
|
return !1;
|
|
696
696
|
try {
|
|
@@ -739,8 +739,8 @@ async function Oe(e, s, t) {
|
|
|
739
739
|
d,
|
|
740
740
|
t,
|
|
741
741
|
c
|
|
742
|
-
), { result: h, returnToAgent:
|
|
743
|
-
|
|
742
|
+
), { result: h, returnToAgent: p, agentMessage: g } = de(u);
|
|
743
|
+
p && (r = !0), g && n.push(G(g)), a.push(
|
|
744
744
|
W(
|
|
745
745
|
c,
|
|
746
746
|
l,
|
|
@@ -806,12 +806,12 @@ async function Ie(e, s, t, a, n, r, o, c, l = []) {
|
|
|
806
806
|
a,
|
|
807
807
|
n,
|
|
808
808
|
r
|
|
809
|
-
),
|
|
809
|
+
), p = Pe(h, t, {
|
|
810
810
|
...u,
|
|
811
811
|
abortSignal: o
|
|
812
812
|
});
|
|
813
813
|
return _e(
|
|
814
|
-
|
|
814
|
+
p,
|
|
815
815
|
a,
|
|
816
816
|
n,
|
|
817
817
|
t,
|
|
@@ -826,25 +826,25 @@ async function Ie(e, s, t, a, n, r, o, c, l = []) {
|
|
|
826
826
|
);
|
|
827
827
|
}
|
|
828
828
|
async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
829
|
-
var d, u, h,
|
|
829
|
+
var d, u, h, p, g, y, I, A, f, i, T, x;
|
|
830
830
|
for await (const w of e) {
|
|
831
831
|
if (w.sessionId && !n && (n = w.sessionId), yield w, w.status.state === "running" && w.status.message && s && await at(
|
|
832
832
|
s,
|
|
833
833
|
w.status.message
|
|
834
834
|
)) {
|
|
835
|
-
const P =
|
|
835
|
+
const P = L(
|
|
836
836
|
w.status.message
|
|
837
837
|
);
|
|
838
|
-
for (const
|
|
839
|
-
const { toolCallId: $, toolId: S, arguments:
|
|
838
|
+
for (const _ of P) {
|
|
839
|
+
const { toolCallId: $, toolId: S, arguments: m } = _.data;
|
|
840
840
|
Z(
|
|
841
841
|
s,
|
|
842
842
|
S,
|
|
843
|
-
|
|
843
|
+
m,
|
|
844
844
|
(u = (d = w.status) == null ? void 0 : d.message) == null ? void 0 : u.messageId,
|
|
845
845
|
$
|
|
846
846
|
).catch((C) => {
|
|
847
|
-
|
|
847
|
+
M("Tool execution failed for %s: %O", S, C);
|
|
848
848
|
});
|
|
849
849
|
}
|
|
850
850
|
yield {
|
|
@@ -855,7 +855,7 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
855
855
|
role: "agent",
|
|
856
856
|
kind: "message",
|
|
857
857
|
parts: P,
|
|
858
|
-
messageId:
|
|
858
|
+
messageId: N()
|
|
859
859
|
}
|
|
860
860
|
},
|
|
861
861
|
final: !1,
|
|
@@ -863,16 +863,16 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
863
863
|
};
|
|
864
864
|
}
|
|
865
865
|
if (w.status.state === "input-required" && w.status.message && s) {
|
|
866
|
-
const P =
|
|
866
|
+
const P = L(
|
|
867
867
|
w.status.message
|
|
868
868
|
);
|
|
869
869
|
if (P.length > 0) {
|
|
870
|
-
const
|
|
870
|
+
const _ = [];
|
|
871
871
|
let $ = !1;
|
|
872
|
-
const S = [],
|
|
872
|
+
const S = [], m = [];
|
|
873
873
|
for (const C of P) {
|
|
874
874
|
const {
|
|
875
|
-
toolCallId:
|
|
875
|
+
toolCallId: v,
|
|
876
876
|
toolId: R,
|
|
877
877
|
arguments: k
|
|
878
878
|
} = C.data;
|
|
@@ -881,54 +881,54 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
881
881
|
s,
|
|
882
882
|
R,
|
|
883
883
|
k,
|
|
884
|
-
(
|
|
885
|
-
|
|
886
|
-
), { result: E, returnToAgent: U, agentMessage:
|
|
887
|
-
if (U && ($ = !0),
|
|
888
|
-
G(
|
|
884
|
+
(p = (h = w.status) == null ? void 0 : h.message) == null ? void 0 : p.messageId,
|
|
885
|
+
v
|
|
886
|
+
), { result: E, returnToAgent: U, agentMessage: J } = de(b);
|
|
887
|
+
if (U && ($ = !0), J && m.push(
|
|
888
|
+
G(J)
|
|
889
889
|
), E.result instanceof Promise) {
|
|
890
|
-
const
|
|
891
|
-
promise:
|
|
890
|
+
const O = E.result, j = {
|
|
891
|
+
promise: O,
|
|
892
892
|
resolvedValue: null
|
|
893
893
|
};
|
|
894
894
|
ge.set(
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
),
|
|
898
|
-
|
|
895
|
+
v,
|
|
896
|
+
j
|
|
897
|
+
), O.then((H) => {
|
|
898
|
+
j.resolvedValue = H;
|
|
899
899
|
}).catch((H) => {
|
|
900
|
-
|
|
900
|
+
M(
|
|
901
901
|
"Promise rejected for tool call %s: %O",
|
|
902
|
-
|
|
902
|
+
v,
|
|
903
903
|
H
|
|
904
|
-
),
|
|
904
|
+
), j.resolvedValue = {
|
|
905
905
|
error: H instanceof Error ? H.message : String(H)
|
|
906
906
|
};
|
|
907
907
|
});
|
|
908
908
|
}
|
|
909
|
-
const
|
|
910
|
-
|
|
909
|
+
const q = W(
|
|
910
|
+
v,
|
|
911
911
|
R,
|
|
912
912
|
E
|
|
913
913
|
);
|
|
914
|
-
|
|
914
|
+
_.push(q), S.push(q);
|
|
915
915
|
} catch (b) {
|
|
916
916
|
const E = W(
|
|
917
|
-
|
|
917
|
+
v,
|
|
918
918
|
R,
|
|
919
919
|
void 0,
|
|
920
920
|
b instanceof Error ? b.message : String(b)
|
|
921
921
|
);
|
|
922
|
-
|
|
922
|
+
_.push(E), S.push(E);
|
|
923
923
|
}
|
|
924
924
|
}
|
|
925
|
-
if (o.push(w.status.message),
|
|
925
|
+
if (o.push(w.status.message), _.length > 0 && o.push({
|
|
926
926
|
role: "agent",
|
|
927
927
|
kind: "message",
|
|
928
|
-
parts:
|
|
929
|
-
messageId:
|
|
928
|
+
parts: _,
|
|
929
|
+
messageId: N()
|
|
930
930
|
}), $) {
|
|
931
|
-
const C = ye(o),
|
|
931
|
+
const C = ye(o), v = X(
|
|
932
932
|
[],
|
|
933
933
|
// Empty array - tool results are already in historyDataParts
|
|
934
934
|
C
|
|
@@ -937,14 +937,14 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
937
937
|
id: w.id,
|
|
938
938
|
status: {
|
|
939
939
|
state: "working",
|
|
940
|
-
message:
|
|
940
|
+
message: v
|
|
941
941
|
},
|
|
942
942
|
final: !1,
|
|
943
943
|
text: ""
|
|
944
944
|
};
|
|
945
945
|
const R = await Ie(
|
|
946
946
|
w.id,
|
|
947
|
-
|
|
947
|
+
v,
|
|
948
948
|
a,
|
|
949
949
|
s,
|
|
950
950
|
t,
|
|
@@ -960,17 +960,17 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
960
960
|
throw new Error(
|
|
961
961
|
"Continue task stream ended without final result"
|
|
962
962
|
);
|
|
963
|
-
let b = (g = k.status) != null && g.message ?
|
|
963
|
+
let b = (g = k.status) != null && g.message ? L(
|
|
964
964
|
k.status.message
|
|
965
965
|
) : [], E = k;
|
|
966
966
|
if (b.length > 0)
|
|
967
967
|
for (yield {
|
|
968
968
|
...k,
|
|
969
969
|
final: !1,
|
|
970
|
-
text:
|
|
970
|
+
text: D(
|
|
971
971
|
((y = k.status) == null ? void 0 : y.message) || {
|
|
972
972
|
parts: [],
|
|
973
|
-
messageId:
|
|
973
|
+
messageId: N()
|
|
974
974
|
}
|
|
975
975
|
)
|
|
976
976
|
}; b.length > 0; ) {
|
|
@@ -979,11 +979,11 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
979
979
|
);
|
|
980
980
|
const {
|
|
981
981
|
results: U,
|
|
982
|
-
shouldReturnToAgent:
|
|
982
|
+
shouldReturnToAgent: J
|
|
983
983
|
} = await Oe(
|
|
984
984
|
b,
|
|
985
985
|
s,
|
|
986
|
-
(f = (
|
|
986
|
+
(f = (A = E.status) == null ? void 0 : A.message) == null ? void 0 : f.messageId
|
|
987
987
|
);
|
|
988
988
|
if (U.length > 0 && (yield {
|
|
989
989
|
id: E.id,
|
|
@@ -993,21 +993,21 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
993
993
|
role: "agent",
|
|
994
994
|
kind: "message",
|
|
995
995
|
parts: U,
|
|
996
|
-
messageId:
|
|
996
|
+
messageId: N()
|
|
997
997
|
}
|
|
998
998
|
// Simple message with just the results
|
|
999
999
|
},
|
|
1000
1000
|
final: !1,
|
|
1001
1001
|
text: ""
|
|
1002
|
-
}),
|
|
1003
|
-
const
|
|
1002
|
+
}), J) {
|
|
1003
|
+
const q = r ? ye(
|
|
1004
1004
|
o
|
|
1005
|
-
) : [],
|
|
1005
|
+
) : [], O = X(
|
|
1006
1006
|
U,
|
|
1007
|
-
|
|
1008
|
-
),
|
|
1007
|
+
q
|
|
1008
|
+
), j = await Ie(
|
|
1009
1009
|
E.id,
|
|
1010
|
-
|
|
1010
|
+
O,
|
|
1011
1011
|
a,
|
|
1012
1012
|
s,
|
|
1013
1013
|
t,
|
|
@@ -1017,22 +1017,22 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
1017
1017
|
o
|
|
1018
1018
|
);
|
|
1019
1019
|
let H = null;
|
|
1020
|
-
for await (const ee of
|
|
1020
|
+
for await (const ee of j)
|
|
1021
1021
|
ee.final ? H = ee : yield ee;
|
|
1022
1022
|
if (!H)
|
|
1023
1023
|
throw new Error(
|
|
1024
1024
|
"Continue task stream ended without final result"
|
|
1025
1025
|
);
|
|
1026
|
-
E = H, b = (i = E.status) != null && i.message ?
|
|
1026
|
+
E = H, b = (i = E.status) != null && i.message ? L(
|
|
1027
1027
|
E.status.message
|
|
1028
1028
|
) : [], b.length > 0 && (yield {
|
|
1029
1029
|
id: E.id,
|
|
1030
1030
|
status: E.status,
|
|
1031
1031
|
final: !1,
|
|
1032
|
-
text:
|
|
1032
|
+
text: D(
|
|
1033
1033
|
((T = E.status) == null ? void 0 : T.message) || {
|
|
1034
1034
|
parts: [],
|
|
1035
|
-
messageId:
|
|
1035
|
+
messageId: N()
|
|
1036
1036
|
}
|
|
1037
1037
|
)
|
|
1038
1038
|
});
|
|
@@ -1042,10 +1042,10 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
1042
1042
|
yield {
|
|
1043
1043
|
...E,
|
|
1044
1044
|
final: !0,
|
|
1045
|
-
text:
|
|
1046
|
-
((
|
|
1045
|
+
text: D(
|
|
1046
|
+
((x = E.status) == null ? void 0 : x.message) || {
|
|
1047
1047
|
parts: [],
|
|
1048
|
-
messageId:
|
|
1048
|
+
messageId: N()
|
|
1049
1049
|
}
|
|
1050
1050
|
)
|
|
1051
1051
|
};
|
|
@@ -1053,20 +1053,20 @@ async function* _e(e, s, t, a, n, r = !0, o = [], c, l) {
|
|
|
1053
1053
|
const C = {
|
|
1054
1054
|
...w.status.message,
|
|
1055
1055
|
parts: S
|
|
1056
|
-
},
|
|
1056
|
+
}, v = {
|
|
1057
1057
|
...w,
|
|
1058
1058
|
status: {
|
|
1059
1059
|
...w.status,
|
|
1060
1060
|
message: C
|
|
1061
1061
|
},
|
|
1062
|
-
final:
|
|
1062
|
+
final: m.length === 0,
|
|
1063
1063
|
// Only final if no agent messages to follow
|
|
1064
|
-
text:
|
|
1064
|
+
text: D(C)
|
|
1065
1065
|
};
|
|
1066
|
-
if (yield
|
|
1067
|
-
const R =
|
|
1066
|
+
if (yield v, m.length > 0) {
|
|
1067
|
+
const R = m.map((b) => D(b)).join(" "), k = G(R);
|
|
1068
1068
|
yield {
|
|
1069
|
-
id:
|
|
1069
|
+
id: v.id,
|
|
1070
1070
|
status: {
|
|
1071
1071
|
state: "completed",
|
|
1072
1072
|
message: k
|
|
@@ -1099,7 +1099,7 @@ function rt(e) {
|
|
|
1099
1099
|
return {
|
|
1100
1100
|
async sendMessage(u) {
|
|
1101
1101
|
var i, T;
|
|
1102
|
-
const { abortSignal: h } = u,
|
|
1102
|
+
const { abortSignal: h } = u, p = u.sessionId || n || void 0, g = [];
|
|
1103
1103
|
g.push(u.message);
|
|
1104
1104
|
const y = await Y(
|
|
1105
1105
|
u,
|
|
@@ -1107,98 +1107,98 @@ function rt(e) {
|
|
|
1107
1107
|
{ isStreaming: !1 },
|
|
1108
1108
|
o,
|
|
1109
1109
|
c,
|
|
1110
|
-
|
|
1110
|
+
p
|
|
1111
1111
|
);
|
|
1112
1112
|
let I = await Ee(
|
|
1113
1113
|
y,
|
|
1114
1114
|
d,
|
|
1115
1115
|
{ abortSignal: h }
|
|
1116
1116
|
);
|
|
1117
|
-
const
|
|
1117
|
+
const A = [], f = [];
|
|
1118
1118
|
for (; I.status.message && o; ) {
|
|
1119
|
-
const
|
|
1119
|
+
const x = L(
|
|
1120
1120
|
I.status.message
|
|
1121
1121
|
);
|
|
1122
|
-
if (
|
|
1122
|
+
if (x.length === 0)
|
|
1123
1123
|
break;
|
|
1124
|
-
|
|
1124
|
+
A.push(...x);
|
|
1125
1125
|
const w = [];
|
|
1126
1126
|
let P = !1;
|
|
1127
|
-
for (const
|
|
1127
|
+
for (const _ of x) {
|
|
1128
1128
|
const {
|
|
1129
1129
|
toolCallId: $,
|
|
1130
1130
|
toolId: S,
|
|
1131
|
-
arguments:
|
|
1132
|
-
} =
|
|
1131
|
+
arguments: m
|
|
1132
|
+
} = _.data;
|
|
1133
1133
|
try {
|
|
1134
1134
|
const C = await Z(
|
|
1135
1135
|
o,
|
|
1136
1136
|
S,
|
|
1137
|
-
|
|
1138
|
-
), { result:
|
|
1137
|
+
m
|
|
1138
|
+
), { result: v, returnToAgent: R, agentMessage: k } = de(C);
|
|
1139
1139
|
R && (P = !0), k && f.push(
|
|
1140
1140
|
G(k)
|
|
1141
1141
|
);
|
|
1142
1142
|
const b = W(
|
|
1143
1143
|
$,
|
|
1144
1144
|
S,
|
|
1145
|
-
|
|
1145
|
+
v
|
|
1146
1146
|
);
|
|
1147
|
-
w.push(b),
|
|
1147
|
+
w.push(b), A.push(b);
|
|
1148
1148
|
} catch (C) {
|
|
1149
|
-
const
|
|
1149
|
+
const v = W(
|
|
1150
1150
|
$,
|
|
1151
1151
|
S,
|
|
1152
1152
|
void 0,
|
|
1153
1153
|
C instanceof Error ? C.message : String(C)
|
|
1154
1154
|
);
|
|
1155
|
-
w.push(
|
|
1155
|
+
w.push(v), A.push(v);
|
|
1156
1156
|
}
|
|
1157
1157
|
}
|
|
1158
1158
|
if (g.push(I.status.message), P) {
|
|
1159
|
-
const
|
|
1159
|
+
const _ = X(w);
|
|
1160
1160
|
I = await ae(
|
|
1161
1161
|
I.id,
|
|
1162
|
-
|
|
1162
|
+
_,
|
|
1163
1163
|
d,
|
|
1164
1164
|
o,
|
|
1165
1165
|
c,
|
|
1166
|
-
|
|
1166
|
+
p,
|
|
1167
1167
|
h
|
|
1168
1168
|
);
|
|
1169
1169
|
} else
|
|
1170
1170
|
break;
|
|
1171
1171
|
}
|
|
1172
|
-
if (
|
|
1173
|
-
const
|
|
1172
|
+
if (A.length > 0 && (i = I.status) != null && i.message) {
|
|
1173
|
+
const x = {
|
|
1174
1174
|
...I.status.message,
|
|
1175
|
-
parts:
|
|
1175
|
+
parts: A
|
|
1176
1176
|
};
|
|
1177
1177
|
I = {
|
|
1178
1178
|
...I,
|
|
1179
1179
|
status: {
|
|
1180
1180
|
...I.status,
|
|
1181
|
-
message:
|
|
1181
|
+
message: x
|
|
1182
1182
|
}
|
|
1183
1183
|
};
|
|
1184
1184
|
}
|
|
1185
1185
|
if (f.length > 0) {
|
|
1186
|
-
const
|
|
1186
|
+
const x = f.map((P) => D(P)).join(" "), w = G(x);
|
|
1187
1187
|
return {
|
|
1188
1188
|
...I,
|
|
1189
1189
|
// Keep the enhanced message with tool results
|
|
1190
1190
|
// The agent message will be handled separately by the caller
|
|
1191
|
-
text:
|
|
1191
|
+
text: x,
|
|
1192
1192
|
agentMessage: w
|
|
1193
1193
|
// Add this for the caller to handle
|
|
1194
1194
|
};
|
|
1195
1195
|
}
|
|
1196
1196
|
return {
|
|
1197
1197
|
...I,
|
|
1198
|
-
text:
|
|
1198
|
+
text: D(
|
|
1199
1199
|
((T = I.status) == null ? void 0 : T.message) || {
|
|
1200
1200
|
parts: [],
|
|
1201
|
-
messageId:
|
|
1201
|
+
messageId: N()
|
|
1202
1202
|
}
|
|
1203
1203
|
)
|
|
1204
1204
|
};
|
|
@@ -1206,10 +1206,10 @@ function rt(e) {
|
|
|
1206
1206
|
async *sendMessageStream(u) {
|
|
1207
1207
|
const {
|
|
1208
1208
|
withHistory: h = !0,
|
|
1209
|
-
abortSignal:
|
|
1209
|
+
abortSignal: p,
|
|
1210
1210
|
enableStreaming: g
|
|
1211
|
-
} = u, y = u.sessionId || n || void 0, I = g ?? l,
|
|
1212
|
-
|
|
1211
|
+
} = u, y = u.sessionId || n || void 0, I = g ?? l, A = [];
|
|
1212
|
+
A.push(u.message);
|
|
1213
1213
|
const f = await Y(
|
|
1214
1214
|
u,
|
|
1215
1215
|
d,
|
|
@@ -1228,7 +1228,7 @@ function rt(e) {
|
|
|
1228
1228
|
enableTokenStreaming: I,
|
|
1229
1229
|
// Token streaming is optional
|
|
1230
1230
|
streamingTimeout: r,
|
|
1231
|
-
abortSignal:
|
|
1231
|
+
abortSignal: p
|
|
1232
1232
|
}
|
|
1233
1233
|
);
|
|
1234
1234
|
yield* _e(
|
|
@@ -1238,8 +1238,8 @@ function rt(e) {
|
|
|
1238
1238
|
d,
|
|
1239
1239
|
y,
|
|
1240
1240
|
h,
|
|
1241
|
-
|
|
1242
|
-
|
|
1241
|
+
A,
|
|
1242
|
+
p,
|
|
1243
1243
|
{
|
|
1244
1244
|
isStreaming: !0,
|
|
1245
1245
|
enableTokenStreaming: I,
|
|
@@ -1247,8 +1247,8 @@ function rt(e) {
|
|
|
1247
1247
|
}
|
|
1248
1248
|
);
|
|
1249
1249
|
},
|
|
1250
|
-
async continueTask(u, h,
|
|
1251
|
-
var
|
|
1250
|
+
async continueTask(u, h, p) {
|
|
1251
|
+
var A;
|
|
1252
1252
|
const g = ie(h);
|
|
1253
1253
|
let I = await ae(
|
|
1254
1254
|
u,
|
|
@@ -1256,34 +1256,34 @@ function rt(e) {
|
|
|
1256
1256
|
d,
|
|
1257
1257
|
o,
|
|
1258
1258
|
c,
|
|
1259
|
-
|
|
1259
|
+
p
|
|
1260
1260
|
);
|
|
1261
1261
|
for (; I.status.state === "input-required" && I.status.message && o; ) {
|
|
1262
|
-
const f =
|
|
1262
|
+
const f = L(
|
|
1263
1263
|
I.status.message
|
|
1264
1264
|
);
|
|
1265
1265
|
if (f.length === 0)
|
|
1266
1266
|
break;
|
|
1267
1267
|
const { results: i, shouldReturnToAgent: T } = await Oe(f, o);
|
|
1268
1268
|
if (T) {
|
|
1269
|
-
const
|
|
1269
|
+
const x = X(i);
|
|
1270
1270
|
I = await ae(
|
|
1271
1271
|
I.id,
|
|
1272
|
-
|
|
1272
|
+
x,
|
|
1273
1273
|
d,
|
|
1274
1274
|
o,
|
|
1275
1275
|
c,
|
|
1276
|
-
|
|
1276
|
+
p
|
|
1277
1277
|
);
|
|
1278
1278
|
} else
|
|
1279
1279
|
break;
|
|
1280
1280
|
}
|
|
1281
1281
|
return {
|
|
1282
1282
|
...I,
|
|
1283
|
-
text:
|
|
1284
|
-
((
|
|
1283
|
+
text: D(
|
|
1284
|
+
((A = I.status) == null ? void 0 : A.message) || {
|
|
1285
1285
|
parts: [],
|
|
1286
|
-
messageId:
|
|
1286
|
+
messageId: N()
|
|
1287
1287
|
}
|
|
1288
1288
|
)
|
|
1289
1289
|
};
|
|
@@ -1328,7 +1328,7 @@ function it(e) {
|
|
|
1328
1328
|
role: a,
|
|
1329
1329
|
kind: "message",
|
|
1330
1330
|
parts: s,
|
|
1331
|
-
messageId:
|
|
1331
|
+
messageId: N(),
|
|
1332
1332
|
metadata: {
|
|
1333
1333
|
timestamp: n,
|
|
1334
1334
|
serverId: e.message_id,
|
|
@@ -1371,7 +1371,7 @@ async function le(e, s, t = 1, a = 50) {
|
|
|
1371
1371
|
n
|
|
1372
1372
|
)}/${encodeURIComponent(e)}`
|
|
1373
1373
|
);
|
|
1374
|
-
d.searchParams.set("page_number", c.toString()), d.searchParams.set("items_per_page", l.toString()),
|
|
1374
|
+
d.searchParams.set("page_number", c.toString()), d.searchParams.set("items_per_page", l.toString()), M(
|
|
1375
1375
|
"Loading conversation from server: %s (page %d)",
|
|
1376
1376
|
e,
|
|
1377
1377
|
c
|
|
@@ -1396,15 +1396,15 @@ async function le(e, s, t = 1, a = 50) {
|
|
|
1396
1396
|
f.message && (I = f.message);
|
|
1397
1397
|
} catch {
|
|
1398
1398
|
}
|
|
1399
|
-
const
|
|
1399
|
+
const A = new V(
|
|
1400
1400
|
I,
|
|
1401
1401
|
h.status,
|
|
1402
1402
|
y
|
|
1403
1403
|
);
|
|
1404
|
-
throw
|
|
1404
|
+
throw M("Failed to load conversation from server: %O", A), A;
|
|
1405
1405
|
}
|
|
1406
|
-
const
|
|
1407
|
-
return
|
|
1406
|
+
const p = await h.json(), g = lt(p);
|
|
1407
|
+
return M(
|
|
1408
1408
|
"Loaded %d messages from server (page %d/%d)",
|
|
1409
1409
|
g.messages.length,
|
|
1410
1410
|
g.pagination.currentPage,
|
|
@@ -1418,7 +1418,7 @@ async function le(e, s, t = 1, a = 50) {
|
|
|
1418
1418
|
void 0,
|
|
1419
1419
|
u
|
|
1420
1420
|
);
|
|
1421
|
-
throw
|
|
1421
|
+
throw M("Network error loading conversation: %O", u), h;
|
|
1422
1422
|
}
|
|
1423
1423
|
}
|
|
1424
1424
|
async function Jt(e, s, t = !1) {
|
|
@@ -1430,7 +1430,7 @@ async function Jt(e, s, t = !1) {
|
|
|
1430
1430
|
r.searchParams.set(
|
|
1431
1431
|
"truncation_method",
|
|
1432
1432
|
t ? "first_message" : "last_message"
|
|
1433
|
-
),
|
|
1433
|
+
), M("Listing conversations from server for bot: %s", e);
|
|
1434
1434
|
try {
|
|
1435
1435
|
const o = {
|
|
1436
1436
|
"Content-Type": "application/json"
|
|
@@ -1449,10 +1449,10 @@ async function Jt(e, s, t = !1) {
|
|
|
1449
1449
|
c.status,
|
|
1450
1450
|
d
|
|
1451
1451
|
);
|
|
1452
|
-
throw
|
|
1452
|
+
throw M("Failed to list conversations: %O", h), h;
|
|
1453
1453
|
}
|
|
1454
1454
|
const l = await c.json();
|
|
1455
|
-
return
|
|
1455
|
+
return M("Loaded %d conversations from server", l.length), l;
|
|
1456
1456
|
} catch (o) {
|
|
1457
1457
|
if (o instanceof V)
|
|
1458
1458
|
throw o;
|
|
@@ -1461,10 +1461,10 @@ async function Jt(e, s, t = !1) {
|
|
|
1461
1461
|
void 0,
|
|
1462
1462
|
o
|
|
1463
1463
|
);
|
|
1464
|
-
throw
|
|
1464
|
+
throw M("Network error listing conversations: %O", o), c;
|
|
1465
1465
|
}
|
|
1466
1466
|
}
|
|
1467
|
-
async function
|
|
1467
|
+
async function Kt(e, s, t = 10) {
|
|
1468
1468
|
const a = await le(e, s, 1, 50);
|
|
1469
1469
|
if (!a.pagination.hasMore)
|
|
1470
1470
|
return a;
|
|
@@ -1488,7 +1488,7 @@ async function Lt(e, s, t = 10) {
|
|
|
1488
1488
|
chatId: a.chatId
|
|
1489
1489
|
};
|
|
1490
1490
|
} catch (c) {
|
|
1491
|
-
return
|
|
1491
|
+
return M("Failed to load all pages: %O", c), {
|
|
1492
1492
|
messages: r,
|
|
1493
1493
|
pagination: a.pagination,
|
|
1494
1494
|
chatId: a.chatId
|
|
@@ -1497,7 +1497,7 @@ async function Lt(e, s, t = 10) {
|
|
|
1497
1497
|
}
|
|
1498
1498
|
const me = "a8c_agenttic_conversation_history";
|
|
1499
1499
|
function ct(e) {
|
|
1500
|
-
var h,
|
|
1500
|
+
var h, p;
|
|
1501
1501
|
const s = e.parts.filter(
|
|
1502
1502
|
(g) => g.type === "text"
|
|
1503
1503
|
), t = s.map((g) => g.text).join(`
|
|
@@ -1522,7 +1522,7 @@ function ct(e) {
|
|
|
1522
1522
|
name: g.file.name,
|
|
1523
1523
|
mimeType: g.file.mimeType,
|
|
1524
1524
|
uri: g.file.uri
|
|
1525
|
-
})), l = n.length > 0 || r.length > 0 ? "agent" : e.role, d = ((h = e.metadata) == null ? void 0 : h.timestamp) ?? Date.now(), u = ((
|
|
1525
|
+
})), l = n.length > 0 || r.length > 0 ? "agent" : e.role, d = ((h = e.metadata) == null ? void 0 : h.timestamp) ?? Date.now(), u = ((p = e.metadata) == null ? void 0 : p.archived) ?? void 0;
|
|
1526
1526
|
return {
|
|
1527
1527
|
role: l,
|
|
1528
1528
|
content: t || "(No text content)",
|
|
@@ -1578,7 +1578,7 @@ function ut(e) {
|
|
|
1578
1578
|
role: e.role,
|
|
1579
1579
|
kind: "message",
|
|
1580
1580
|
parts: s,
|
|
1581
|
-
messageId:
|
|
1581
|
+
messageId: N(),
|
|
1582
1582
|
metadata: {
|
|
1583
1583
|
timestamp: e.timestamp,
|
|
1584
1584
|
// only store archived if it was already present.
|
|
@@ -1588,12 +1588,12 @@ function ut(e) {
|
|
|
1588
1588
|
}
|
|
1589
1589
|
};
|
|
1590
1590
|
}
|
|
1591
|
-
const
|
|
1591
|
+
const B = /* @__PURE__ */ new Map(), dt = 50;
|
|
1592
1592
|
async function gt(e, s, t) {
|
|
1593
1593
|
const a = t || e;
|
|
1594
|
-
if (
|
|
1595
|
-
const n =
|
|
1596
|
-
n &&
|
|
1594
|
+
if (B.set(a, [...s]), B.size > dt) {
|
|
1595
|
+
const n = B.keys().next().value;
|
|
1596
|
+
n && B.delete(n);
|
|
1597
1597
|
}
|
|
1598
1598
|
if (!(typeof sessionStorage > "u"))
|
|
1599
1599
|
try {
|
|
@@ -1607,7 +1607,7 @@ async function gt(e, s, t) {
|
|
|
1607
1607
|
JSON.stringify(n)
|
|
1608
1608
|
);
|
|
1609
1609
|
} catch (n) {
|
|
1610
|
-
|
|
1610
|
+
M(
|
|
1611
1611
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1612
1612
|
a,
|
|
1613
1613
|
n
|
|
@@ -1636,7 +1636,7 @@ async function mt(e, s) {
|
|
|
1636
1636
|
1,
|
|
1637
1637
|
50
|
|
1638
1638
|
);
|
|
1639
|
-
return
|
|
1639
|
+
return M(
|
|
1640
1640
|
"Loaded conversation from server: %s (%d messages, page %d/%d)",
|
|
1641
1641
|
e,
|
|
1642
1642
|
o.messages.length,
|
|
@@ -1647,14 +1647,14 @@ async function mt(e, s) {
|
|
|
1647
1647
|
pagination: o.pagination
|
|
1648
1648
|
};
|
|
1649
1649
|
} catch (r) {
|
|
1650
|
-
throw
|
|
1650
|
+
throw M("Failed to load conversation from server: %O", r), r;
|
|
1651
1651
|
}
|
|
1652
1652
|
}
|
|
1653
1653
|
async function pt(e, s) {
|
|
1654
1654
|
const t = s || e;
|
|
1655
|
-
if (
|
|
1655
|
+
if (B.has(t))
|
|
1656
1656
|
return {
|
|
1657
|
-
messages: [...
|
|
1657
|
+
messages: [...B.get(t)]
|
|
1658
1658
|
};
|
|
1659
1659
|
if (typeof sessionStorage > "u")
|
|
1660
1660
|
return { messages: [] };
|
|
@@ -1664,10 +1664,10 @@ async function pt(e, s) {
|
|
|
1664
1664
|
);
|
|
1665
1665
|
if (a) {
|
|
1666
1666
|
const r = JSON.parse(a).messages.map(ut);
|
|
1667
|
-
return
|
|
1667
|
+
return B.set(t, r), { messages: [...r] };
|
|
1668
1668
|
}
|
|
1669
1669
|
} catch (a) {
|
|
1670
|
-
|
|
1670
|
+
M(
|
|
1671
1671
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1672
1672
|
t,
|
|
1673
1673
|
a
|
|
@@ -1677,11 +1677,11 @@ async function pt(e, s) {
|
|
|
1677
1677
|
}
|
|
1678
1678
|
async function ht(e, s) {
|
|
1679
1679
|
const t = s || e;
|
|
1680
|
-
if (
|
|
1680
|
+
if (B.delete(t), !(typeof sessionStorage > "u"))
|
|
1681
1681
|
try {
|
|
1682
1682
|
sessionStorage.removeItem(`${me}_${t}`);
|
|
1683
1683
|
} catch (a) {
|
|
1684
|
-
|
|
1684
|
+
M(
|
|
1685
1685
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1686
1686
|
t,
|
|
1687
1687
|
a
|
|
@@ -1751,7 +1751,7 @@ function we(e, s = [], t = []) {
|
|
|
1751
1751
|
...n
|
|
1752
1752
|
],
|
|
1753
1753
|
kind: "message",
|
|
1754
|
-
messageId:
|
|
1754
|
+
messageId: N(),
|
|
1755
1755
|
metadata: {
|
|
1756
1756
|
timestamp: Date.now()
|
|
1757
1757
|
}
|
|
@@ -1764,14 +1764,14 @@ function It(e) {
|
|
|
1764
1764
|
}
|
|
1765
1765
|
function ne(e, s) {
|
|
1766
1766
|
if (typeof localStorage > "u") {
|
|
1767
|
-
|
|
1767
|
+
K("localStorage not available, cannot update session ID");
|
|
1768
1768
|
return;
|
|
1769
1769
|
}
|
|
1770
1770
|
try {
|
|
1771
1771
|
const t = localStorage.getItem(e);
|
|
1772
1772
|
if (t) {
|
|
1773
1773
|
const a = JSON.parse(t), n = a.sessionId;
|
|
1774
|
-
a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)),
|
|
1774
|
+
a.sessionId = s, localStorage.setItem(e, JSON.stringify(a)), K(
|
|
1775
1775
|
"Updated localStorage[%s] session ID: %s -> %s",
|
|
1776
1776
|
e,
|
|
1777
1777
|
n,
|
|
@@ -1782,14 +1782,14 @@ function ne(e, s) {
|
|
|
1782
1782
|
sessionId: s,
|
|
1783
1783
|
timestamp: Date.now()
|
|
1784
1784
|
};
|
|
1785
|
-
localStorage.setItem(e, JSON.stringify(a)),
|
|
1785
|
+
localStorage.setItem(e, JSON.stringify(a)), K(
|
|
1786
1786
|
"Created new session in localStorage[%s]: %s",
|
|
1787
1787
|
e,
|
|
1788
1788
|
s
|
|
1789
1789
|
);
|
|
1790
1790
|
}
|
|
1791
1791
|
} catch (t) {
|
|
1792
|
-
|
|
1792
|
+
K(
|
|
1793
1793
|
"Failed to update localStorage sessionId to %s: %O",
|
|
1794
1794
|
s,
|
|
1795
1795
|
t
|
|
@@ -1828,7 +1828,7 @@ function Tt() {
|
|
|
1828
1828
|
n.conversationStorageKey
|
|
1829
1829
|
);
|
|
1830
1830
|
} catch (r) {
|
|
1831
|
-
|
|
1831
|
+
K(
|
|
1832
1832
|
`Failed to persist conversation history for agent ${t}:`,
|
|
1833
1833
|
r
|
|
1834
1834
|
);
|
|
@@ -1851,7 +1851,7 @@ function Tt() {
|
|
|
1851
1851
|
l
|
|
1852
1852
|
)).messages;
|
|
1853
1853
|
} catch (h) {
|
|
1854
|
-
|
|
1854
|
+
K(
|
|
1855
1855
|
`Failed to load conversation history for agent ${t} with session ${r}:`,
|
|
1856
1856
|
h
|
|
1857
1857
|
);
|
|
@@ -1878,7 +1878,7 @@ function Tt() {
|
|
|
1878
1878
|
return e.delete(t);
|
|
1879
1879
|
},
|
|
1880
1880
|
async sendMessage(t, a, n = {}) {
|
|
1881
|
-
var
|
|
1881
|
+
var A;
|
|
1882
1882
|
const r = e.get(t);
|
|
1883
1883
|
if (!r)
|
|
1884
1884
|
throw new Error(`Agent with key "${t}" not found`);
|
|
@@ -1886,35 +1886,35 @@ function Tt() {
|
|
|
1886
1886
|
a,
|
|
1887
1887
|
u,
|
|
1888
1888
|
n.imageUrls
|
|
1889
|
-
),
|
|
1889
|
+
), p = await d.sendMessage({
|
|
1890
1890
|
message: h,
|
|
1891
1891
|
withHistory: o,
|
|
1892
1892
|
sessionId: c || r.sessionId || void 0,
|
|
1893
1893
|
...l
|
|
1894
1894
|
});
|
|
1895
|
-
if (
|
|
1895
|
+
if (p.sessionId) {
|
|
1896
1896
|
const f = r.sessionId;
|
|
1897
|
-
r.sessionId =
|
|
1897
|
+
r.sessionId = p.sessionId, f && p.sessionId && f !== p.sessionId && r.sessionIdStorageKey && (K(
|
|
1898
1898
|
"Session ID changed from %s to %s, updating localStorage",
|
|
1899
1899
|
f,
|
|
1900
|
-
|
|
1900
|
+
p.sessionId
|
|
1901
1901
|
), ne(
|
|
1902
1902
|
r.sessionIdStorageKey,
|
|
1903
|
-
|
|
1903
|
+
p.sessionId
|
|
1904
1904
|
));
|
|
1905
1905
|
}
|
|
1906
1906
|
let g = null;
|
|
1907
|
-
if ((
|
|
1908
|
-
const f =
|
|
1907
|
+
if ((A = p.status) != null && A.message) {
|
|
1908
|
+
const f = p.status.message.parts.filter(
|
|
1909
1909
|
(T) => T.type === "data" && "toolCallId" in T.data && ("arguments" in T.data || "result" in T.data)
|
|
1910
|
-
), i =
|
|
1910
|
+
), i = p.status.message.parts.filter(
|
|
1911
1911
|
(T) => T.type === "text"
|
|
1912
1912
|
);
|
|
1913
1913
|
g = {
|
|
1914
1914
|
role: "agent",
|
|
1915
1915
|
kind: "message",
|
|
1916
1916
|
parts: [...f, ...i],
|
|
1917
|
-
messageId:
|
|
1917
|
+
messageId: N(),
|
|
1918
1918
|
metadata: {
|
|
1919
1919
|
timestamp: Date.now()
|
|
1920
1920
|
}
|
|
@@ -1928,9 +1928,9 @@ function Tt() {
|
|
|
1928
1928
|
...g ? [z(g)] : []
|
|
1929
1929
|
];
|
|
1930
1930
|
let I = y;
|
|
1931
|
-
if (
|
|
1931
|
+
if (p.agentMessage) {
|
|
1932
1932
|
const f = z(
|
|
1933
|
-
|
|
1933
|
+
p.agentMessage
|
|
1934
1934
|
);
|
|
1935
1935
|
I = [
|
|
1936
1936
|
...y,
|
|
@@ -1940,10 +1940,10 @@ function Tt() {
|
|
|
1940
1940
|
return r.conversationHistory = I, o && await s(
|
|
1941
1941
|
t,
|
|
1942
1942
|
I
|
|
1943
|
-
),
|
|
1943
|
+
), p;
|
|
1944
1944
|
},
|
|
1945
1945
|
async *sendMessageStream(t, a, n = {}) {
|
|
1946
|
-
var T,
|
|
1946
|
+
var T, x, w, P, _, $;
|
|
1947
1947
|
const r = e.get(t);
|
|
1948
1948
|
if (!r)
|
|
1949
1949
|
throw new Error(`Agent with key "${t}" not found`);
|
|
@@ -1953,7 +1953,7 @@ function Tt() {
|
|
|
1953
1953
|
metadata: l,
|
|
1954
1954
|
sessionId: d,
|
|
1955
1955
|
...u
|
|
1956
|
-
} = n, { client: h } = r,
|
|
1956
|
+
} = n, { client: h } = r, p = l ? (({ contentType: S, ...m }) => m)(l) : void 0, g = new AbortController();
|
|
1957
1957
|
r.currentAbortController = g, c && c.addEventListener(
|
|
1958
1958
|
"abort",
|
|
1959
1959
|
() => g.abort()
|
|
@@ -1961,20 +1961,20 @@ function Tt() {
|
|
|
1961
1961
|
let y = [
|
|
1962
1962
|
...r.conversationHistory
|
|
1963
1963
|
], I = [];
|
|
1964
|
-
const
|
|
1964
|
+
const A = await wt(
|
|
1965
1965
|
y
|
|
1966
1966
|
);
|
|
1967
|
-
r.conversationHistory =
|
|
1967
|
+
r.conversationHistory = A, y = A, o && await s(
|
|
1968
1968
|
t,
|
|
1969
|
-
|
|
1969
|
+
A
|
|
1970
1970
|
);
|
|
1971
1971
|
const f = n.message || we(
|
|
1972
1972
|
a,
|
|
1973
|
-
|
|
1973
|
+
A,
|
|
1974
1974
|
n.imageUrls
|
|
1975
1975
|
);
|
|
1976
1976
|
if (n.metadata && !n.message) {
|
|
1977
|
-
const { contentType: S, ...
|
|
1977
|
+
const { contentType: S, ...m } = n.metadata;
|
|
1978
1978
|
if (S) {
|
|
1979
1979
|
const C = f.parts[f.parts.length - 1];
|
|
1980
1980
|
C && C.type === "text" && (C.metadata = {
|
|
@@ -1982,24 +1982,24 @@ function Tt() {
|
|
|
1982
1982
|
contentType: S
|
|
1983
1983
|
});
|
|
1984
1984
|
}
|
|
1985
|
-
Object.keys(
|
|
1985
|
+
Object.keys(m).length > 0 && (f.metadata = {
|
|
1986
1986
|
...f.metadata,
|
|
1987
|
-
...
|
|
1987
|
+
...m
|
|
1988
1988
|
});
|
|
1989
1989
|
}
|
|
1990
1990
|
const i = ie(a, n.metadata);
|
|
1991
1991
|
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
1992
1992
|
const S = n.imageUrls.map(
|
|
1993
|
-
(
|
|
1994
|
-
const C = typeof
|
|
1993
|
+
(m) => {
|
|
1994
|
+
const C = typeof m == "string" ? m : m.url, v = typeof m == "string" ? void 0 : m.metadata, R = (v == null ? void 0 : v.fileType) || "image/jpeg";
|
|
1995
1995
|
return {
|
|
1996
1996
|
type: "file",
|
|
1997
1997
|
file: {
|
|
1998
|
-
name: (
|
|
1998
|
+
name: (v == null ? void 0 : v.fileName) || "image",
|
|
1999
1999
|
mimeType: R,
|
|
2000
2000
|
uri: C
|
|
2001
2001
|
},
|
|
2002
|
-
metadata:
|
|
2002
|
+
metadata: v
|
|
2003
2003
|
};
|
|
2004
2004
|
}
|
|
2005
2005
|
);
|
|
@@ -2018,25 +2018,25 @@ function Tt() {
|
|
|
2018
2018
|
sessionId: d || r.sessionId || void 0,
|
|
2019
2019
|
abortSignal: g.signal,
|
|
2020
2020
|
...u,
|
|
2021
|
-
...
|
|
2022
|
-
metadata:
|
|
2021
|
+
...p && Object.keys(p).length > 0 && {
|
|
2022
|
+
metadata: p
|
|
2023
2023
|
}
|
|
2024
2024
|
})) {
|
|
2025
2025
|
if (S.sessionId) {
|
|
2026
|
-
const
|
|
2027
|
-
r.sessionId = S.sessionId, S.sessionId &&
|
|
2026
|
+
const m = r.sessionId;
|
|
2027
|
+
r.sessionId = S.sessionId, S.sessionId && m !== S.sessionId && r.sessionIdStorageKey && (K(
|
|
2028
2028
|
"Session ID %s, updating localStorage",
|
|
2029
|
-
|
|
2029
|
+
m ? `changed from ${m} to ${S.sessionId}` : `received: ${S.sessionId}`
|
|
2030
2030
|
), ne(
|
|
2031
2031
|
r.sessionIdStorageKey,
|
|
2032
2032
|
S.sessionId
|
|
2033
2033
|
));
|
|
2034
2034
|
}
|
|
2035
|
-
if (((T = S.status) == null ? void 0 : T.state) === "input-required" && ((
|
|
2036
|
-
I =
|
|
2035
|
+
if (((T = S.status) == null ? void 0 : T.state) === "input-required" && ((x = S.status) != null && x.message)) {
|
|
2036
|
+
I = L(
|
|
2037
2037
|
S.status.message
|
|
2038
2038
|
).map(
|
|
2039
|
-
(
|
|
2039
|
+
(v) => v.data.toolCallId
|
|
2040
2040
|
);
|
|
2041
2041
|
const C = z(
|
|
2042
2042
|
S.status.message
|
|
@@ -2053,34 +2053,34 @@ function Tt() {
|
|
|
2053
2053
|
const C = It(
|
|
2054
2054
|
S.status.message
|
|
2055
2055
|
).filter(
|
|
2056
|
-
(
|
|
2057
|
-
|
|
2056
|
+
(v) => I.includes(
|
|
2057
|
+
v.data.toolCallId
|
|
2058
2058
|
)
|
|
2059
2059
|
);
|
|
2060
2060
|
if (C.length > 0) {
|
|
2061
|
-
const
|
|
2061
|
+
const v = {
|
|
2062
2062
|
role: "agent",
|
|
2063
2063
|
kind: "message",
|
|
2064
2064
|
parts: C,
|
|
2065
|
-
messageId:
|
|
2065
|
+
messageId: N()
|
|
2066
2066
|
};
|
|
2067
2067
|
y = [
|
|
2068
2068
|
...y,
|
|
2069
|
-
z(
|
|
2069
|
+
z(v)
|
|
2070
2070
|
], r.conversationHistory = y, o && await s(
|
|
2071
2071
|
t,
|
|
2072
2072
|
y
|
|
2073
2073
|
);
|
|
2074
2074
|
}
|
|
2075
2075
|
}
|
|
2076
|
-
if (S.final && ((
|
|
2076
|
+
if (S.final && ((_ = S.status) == null ? void 0 : _.state) !== "input-required") {
|
|
2077
2077
|
I = [];
|
|
2078
|
-
let
|
|
2079
|
-
($ = S.status) != null && $.message && (
|
|
2078
|
+
let m = null;
|
|
2079
|
+
($ = S.status) != null && $.message && (m = z(
|
|
2080
2080
|
S.status.message
|
|
2081
2081
|
), y = [
|
|
2082
2082
|
...y,
|
|
2083
|
-
|
|
2083
|
+
m
|
|
2084
2084
|
], r.conversationHistory = y, o && await s(
|
|
2085
2085
|
t,
|
|
2086
2086
|
y
|
|
@@ -2135,8 +2135,8 @@ const St = Tt();
|
|
|
2135
2135
|
function Q() {
|
|
2136
2136
|
return St;
|
|
2137
2137
|
}
|
|
2138
|
-
function
|
|
2139
|
-
const [e, s] =
|
|
2138
|
+
function vt() {
|
|
2139
|
+
const [e, s] = ve([]), t = F(
|
|
2140
2140
|
(r) => {
|
|
2141
2141
|
s((o) => {
|
|
2142
2142
|
const c = o.findIndex(
|
|
@@ -2150,9 +2150,9 @@ function Mt() {
|
|
|
2150
2150
|
});
|
|
2151
2151
|
},
|
|
2152
2152
|
[]
|
|
2153
|
-
), a =
|
|
2153
|
+
), a = F((r) => {
|
|
2154
2154
|
s((o) => o.filter((c) => c.id !== r));
|
|
2155
|
-
}, []), n =
|
|
2155
|
+
}, []), n = F(() => {
|
|
2156
2156
|
s([]);
|
|
2157
2157
|
}, []);
|
|
2158
2158
|
return {
|
|
@@ -2162,7 +2162,7 @@ function Mt() {
|
|
|
2162
2162
|
registrations: e
|
|
2163
2163
|
};
|
|
2164
2164
|
}
|
|
2165
|
-
function
|
|
2165
|
+
function Mt(e, s) {
|
|
2166
2166
|
return s.flatMap((n) => typeof n.actions == "function" ? n.actions(e) : n.actions).filter((n) => !(n.condition && !n.condition(e))).map((n) => ({
|
|
2167
2167
|
id: n.id,
|
|
2168
2168
|
label: n.label,
|
|
@@ -2235,16 +2235,16 @@ const oe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ne = (e, s =
|
|
|
2235
2235
|
icon: e.role === "agent" ? "assistant" : void 0
|
|
2236
2236
|
};
|
|
2237
2237
|
if (e.role === "agent" && s.length > 0) {
|
|
2238
|
-
const l =
|
|
2238
|
+
const l = Mt(
|
|
2239
2239
|
r,
|
|
2240
2240
|
s
|
|
2241
2241
|
);
|
|
2242
2242
|
l.length > 0 && (r.actions = l);
|
|
2243
2243
|
}
|
|
2244
2244
|
return r;
|
|
2245
|
-
},
|
|
2245
|
+
}, xt = () => ({
|
|
2246
2246
|
getClientContext: () => ({})
|
|
2247
|
-
}),
|
|
2247
|
+
}), At = () => ({
|
|
2248
2248
|
getAvailableTools: async () => [],
|
|
2249
2249
|
executeTool: async () => ({
|
|
2250
2250
|
success: !0,
|
|
@@ -2254,13 +2254,13 @@ const oe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ne = (e, s =
|
|
|
2254
2254
|
const a = e[t];
|
|
2255
2255
|
return typeof a == "string" && a.trim().length > 0;
|
|
2256
2256
|
});
|
|
2257
|
-
function
|
|
2257
|
+
function Lt(e) {
|
|
2258
2258
|
const s = {
|
|
2259
2259
|
agentId: e.agentId,
|
|
2260
2260
|
agentUrl: e.agentUrl,
|
|
2261
2261
|
sessionId: e.sessionId,
|
|
2262
2262
|
sessionIdStorageKey: e.sessionIdStorageKey
|
|
2263
|
-
}, t = Ct(s), [a, n] =
|
|
2263
|
+
}, t = Ct(s), [a, n] = ve({
|
|
2264
2264
|
clientMessages: [],
|
|
2265
2265
|
uiMessages: [],
|
|
2266
2266
|
isProcessing: !1,
|
|
@@ -2272,11 +2272,11 @@ function Bt(e) {
|
|
|
2272
2272
|
unregisterMessageActions: o,
|
|
2273
2273
|
clearAllMessageActions: c,
|
|
2274
2274
|
registrations: l
|
|
2275
|
-
} =
|
|
2275
|
+
} = vt(), d = He(l);
|
|
2276
2276
|
se(() => {
|
|
2277
2277
|
d.current = l;
|
|
2278
2278
|
}, [l]);
|
|
2279
|
-
const u =
|
|
2279
|
+
const u = F(
|
|
2280
2280
|
(f) => f.map(
|
|
2281
2281
|
(i) => re(i, d.current)
|
|
2282
2282
|
).filter((i) => i !== null),
|
|
@@ -2304,19 +2304,19 @@ function Bt(e) {
|
|
|
2304
2304
|
sessionId: s.sessionId,
|
|
2305
2305
|
// Can be empty for new chats
|
|
2306
2306
|
sessionIdStorageKey: s.sessionIdStorageKey,
|
|
2307
|
-
contextProvider: e.contextProvider ||
|
|
2308
|
-
toolProvider: e.toolProvider ||
|
|
2307
|
+
contextProvider: e.contextProvider || xt(),
|
|
2308
|
+
toolProvider: e.toolProvider || At(),
|
|
2309
2309
|
authProvider: e.authProvider,
|
|
2310
2310
|
enableStreaming: e.enableStreaming,
|
|
2311
2311
|
odieBotId: e.odieBotId
|
|
2312
2312
|
}), s.sessionId) {
|
|
2313
2313
|
const w = i.getConversationHistory(T);
|
|
2314
2314
|
n((P) => {
|
|
2315
|
-
const
|
|
2315
|
+
const _ = u(w);
|
|
2316
2316
|
return {
|
|
2317
2317
|
...P,
|
|
2318
2318
|
clientMessages: w,
|
|
2319
|
-
uiMessages:
|
|
2319
|
+
uiMessages: _
|
|
2320
2320
|
};
|
|
2321
2321
|
});
|
|
2322
2322
|
} else
|
|
@@ -2338,19 +2338,19 @@ function Bt(e) {
|
|
|
2338
2338
|
e.odieBotId,
|
|
2339
2339
|
t
|
|
2340
2340
|
]);
|
|
2341
|
-
const h =
|
|
2341
|
+
const h = F(
|
|
2342
2342
|
async (f, i) => {
|
|
2343
2343
|
var $, S;
|
|
2344
2344
|
if (!t)
|
|
2345
2345
|
throw new Error("Invalid agent configuration");
|
|
2346
|
-
const T = Q(),
|
|
2346
|
+
const T = Q(), x = s.agentId, w = Date.now(), P = (i == null ? void 0 : i.type) || "text", _ = {
|
|
2347
2347
|
id: `user-${w}`,
|
|
2348
2348
|
role: "user",
|
|
2349
2349
|
content: [
|
|
2350
2350
|
{ type: P, text: f },
|
|
2351
2351
|
// Map image URLs to component content parts
|
|
2352
|
-
...(($ = i == null ? void 0 : i.imageUrls) == null ? void 0 : $.map((
|
|
2353
|
-
const C = typeof
|
|
2352
|
+
...(($ = i == null ? void 0 : i.imageUrls) == null ? void 0 : $.map((m) => {
|
|
2353
|
+
const C = typeof m == "string" ? m : m.url;
|
|
2354
2354
|
return Ne(C);
|
|
2355
2355
|
})) ?? []
|
|
2356
2356
|
],
|
|
@@ -2358,33 +2358,33 @@ function Bt(e) {
|
|
|
2358
2358
|
archived: (i == null ? void 0 : i.archived) ?? !1,
|
|
2359
2359
|
showIcon: !1
|
|
2360
2360
|
};
|
|
2361
|
-
n((
|
|
2362
|
-
...
|
|
2363
|
-
uiMessages: [...
|
|
2361
|
+
n((m) => ({
|
|
2362
|
+
...m,
|
|
2363
|
+
uiMessages: [...m.uiMessages, _],
|
|
2364
2364
|
isProcessing: !0,
|
|
2365
2365
|
error: null
|
|
2366
2366
|
}));
|
|
2367
2367
|
try {
|
|
2368
|
-
let
|
|
2369
|
-
const
|
|
2370
|
-
(i != null && i.archived || i != null && i.type) && (
|
|
2368
|
+
let m = null, C = !1;
|
|
2369
|
+
const v = {};
|
|
2370
|
+
(i != null && i.archived || i != null && i.type) && (v.metadata = {
|
|
2371
2371
|
...(i == null ? void 0 : i.archived) && { archived: !0 },
|
|
2372
2372
|
...(i == null ? void 0 : i.type) && { contentType: i.type }
|
|
2373
|
-
}), i != null && i.sessionId && (
|
|
2373
|
+
}), i != null && i.sessionId && (v.sessionId = i.sessionId), i != null && i.imageUrls && (v.imageUrls = i.imageUrls);
|
|
2374
2374
|
for await (const R of T.sendMessageStream(
|
|
2375
|
-
|
|
2375
|
+
x,
|
|
2376
2376
|
f,
|
|
2377
|
-
|
|
2377
|
+
v
|
|
2378
2378
|
)) {
|
|
2379
2379
|
if (R.progressMessage && n((k) => ({
|
|
2380
2380
|
...k,
|
|
2381
2381
|
progressMessage: R.progressMessage || null
|
|
2382
2382
|
})), !R.final && R.text)
|
|
2383
|
-
if (
|
|
2383
|
+
if (m)
|
|
2384
2384
|
n((k) => ({
|
|
2385
2385
|
...k,
|
|
2386
2386
|
uiMessages: k.uiMessages.map(
|
|
2387
|
-
(b) => b.id ===
|
|
2387
|
+
(b) => b.id === m ? {
|
|
2388
2388
|
...b,
|
|
2389
2389
|
content: [
|
|
2390
2390
|
{
|
|
@@ -2396,9 +2396,9 @@ function Bt(e) {
|
|
|
2396
2396
|
)
|
|
2397
2397
|
}));
|
|
2398
2398
|
else {
|
|
2399
|
-
|
|
2399
|
+
m = `agent-streaming-${Date.now()}`;
|
|
2400
2400
|
const k = {
|
|
2401
|
-
id:
|
|
2401
|
+
id: m,
|
|
2402
2402
|
role: "agent",
|
|
2403
2403
|
content: [
|
|
2404
2404
|
{ type: "text", text: R.text }
|
|
@@ -2406,7 +2406,9 @@ function Bt(e) {
|
|
|
2406
2406
|
timestamp: Date.now(),
|
|
2407
2407
|
archived: !1,
|
|
2408
2408
|
showIcon: !0,
|
|
2409
|
-
icon: "assistant"
|
|
2409
|
+
icon: "assistant",
|
|
2410
|
+
reactKey: m
|
|
2411
|
+
// Stable key for React rendering
|
|
2410
2412
|
};
|
|
2411
2413
|
n((b) => ({
|
|
2412
2414
|
...b,
|
|
@@ -2416,66 +2418,78 @@ function Bt(e) {
|
|
|
2416
2418
|
]
|
|
2417
2419
|
}));
|
|
2418
2420
|
}
|
|
2419
|
-
if (R.final && ((S = R.status) != null && S.message) &&
|
|
2421
|
+
if (R.final && ((S = R.status) != null && S.message) && m) {
|
|
2420
2422
|
C = !0;
|
|
2421
|
-
const k =
|
|
2423
|
+
const k = m, b = re(
|
|
2422
2424
|
R.status.message,
|
|
2423
2425
|
d.current
|
|
2424
2426
|
);
|
|
2425
2427
|
b && n((E) => {
|
|
2426
2428
|
const U = E.uiMessages.map(
|
|
2427
|
-
(
|
|
2428
|
-
|
|
2429
|
-
|
|
2429
|
+
(q) => {
|
|
2430
|
+
var O, j;
|
|
2431
|
+
if (q.id === k) {
|
|
2432
|
+
const H = b.content.length > 0 && ((O = b.content[0]) == null ? void 0 : O.text) && ((j = q.content[0]) == null ? void 0 : j.text) && b.content[0].text.length > q.content[0].text.length;
|
|
2433
|
+
return {
|
|
2434
|
+
...b,
|
|
2435
|
+
reactKey: q.reactKey || k,
|
|
2436
|
+
// Keep stable reactKey
|
|
2437
|
+
content: H ? b.content : q.content
|
|
2438
|
+
};
|
|
2439
|
+
}
|
|
2440
|
+
return q;
|
|
2441
|
+
}
|
|
2442
|
+
), J = T.getConversationHistory(
|
|
2443
|
+
x
|
|
2430
2444
|
);
|
|
2431
2445
|
return {
|
|
2432
2446
|
...E,
|
|
2433
|
-
clientMessages:
|
|
2447
|
+
clientMessages: J,
|
|
2434
2448
|
uiMessages: U,
|
|
2435
2449
|
isProcessing: !1,
|
|
2436
2450
|
progressMessage: null
|
|
2437
2451
|
};
|
|
2438
|
-
}),
|
|
2452
|
+
}), m = null;
|
|
2439
2453
|
}
|
|
2440
2454
|
}
|
|
2441
2455
|
if (!C) {
|
|
2442
|
-
const R = T.getConversationHistory(
|
|
2456
|
+
const R = T.getConversationHistory(x);
|
|
2443
2457
|
n((k) => {
|
|
2444
2458
|
let b = k.uiMessages;
|
|
2445
|
-
|
|
2446
|
-
(
|
|
2459
|
+
m && (b = k.uiMessages.filter(
|
|
2460
|
+
(O) => O.id !== m
|
|
2447
2461
|
));
|
|
2448
2462
|
const E = R.map(
|
|
2449
|
-
(
|
|
2450
|
-
|
|
2463
|
+
(O) => re(
|
|
2464
|
+
O,
|
|
2451
2465
|
d.current
|
|
2452
2466
|
)
|
|
2453
2467
|
).filter(
|
|
2454
|
-
(
|
|
2468
|
+
(O) => O !== null
|
|
2455
2469
|
), U = new Set(
|
|
2456
|
-
R.map((
|
|
2457
|
-
),
|
|
2458
|
-
(
|
|
2459
|
-
var
|
|
2460
|
-
return !U.has(
|
|
2470
|
+
R.map((O) => O.messageId)
|
|
2471
|
+
), J = b.filter(
|
|
2472
|
+
(O) => {
|
|
2473
|
+
var j;
|
|
2474
|
+
return !U.has(O.id) && ((j = O.content[0]) == null ? void 0 : j.type) === "component";
|
|
2461
2475
|
}
|
|
2462
|
-
),
|
|
2476
|
+
), q = oe([
|
|
2463
2477
|
...E,
|
|
2464
|
-
...
|
|
2478
|
+
...J
|
|
2465
2479
|
]);
|
|
2466
2480
|
return {
|
|
2467
2481
|
...k,
|
|
2468
2482
|
clientMessages: R,
|
|
2469
|
-
uiMessages:
|
|
2483
|
+
uiMessages: q,
|
|
2470
2484
|
isProcessing: !1,
|
|
2471
2485
|
progressMessage: null
|
|
2472
2486
|
};
|
|
2473
2487
|
});
|
|
2474
2488
|
}
|
|
2475
|
-
} catch (
|
|
2476
|
-
if (
|
|
2477
|
-
|
|
2478
|
-
...
|
|
2489
|
+
} catch (m) {
|
|
2490
|
+
if (m instanceof Error && m.name === "AbortError") {
|
|
2491
|
+
M("Request was aborted by user"), n((v) => ({
|
|
2492
|
+
...v,
|
|
2479
2493
|
isProcessing: !1,
|
|
2480
2494
|
progressMessage: null,
|
|
2481
2495
|
error: null
|
|
@@ -2483,27 +2497,27 @@ function Bt(e) {
|
|
|
2483
2497
|
}));
|
|
2484
2498
|
return;
|
|
2485
2499
|
}
|
|
2486
|
-
const C =
|
|
2487
|
-
throw n((
|
|
2488
|
-
...
|
|
2500
|
+
const C = m instanceof Error ? m.message : "Failed to send message";
|
|
2501
|
+
throw n((v) => ({
|
|
2502
|
+
...v,
|
|
2489
2503
|
isProcessing: !1,
|
|
2490
2504
|
progressMessage: null,
|
|
2491
2505
|
error: C
|
|
2492
|
-
})),
|
|
2506
|
+
})), m;
|
|
2493
2507
|
}
|
|
2494
2508
|
},
|
|
2495
2509
|
[s.agentId, t]
|
|
2496
|
-
),
|
|
2510
|
+
), p = F((f) => {
|
|
2497
2511
|
n((i) => ({
|
|
2498
2512
|
...i,
|
|
2499
2513
|
uiMessages: oe([...i.uiMessages, f])
|
|
2500
2514
|
}));
|
|
2501
|
-
}, []), g =
|
|
2515
|
+
}, []), g = F((f) => {
|
|
2502
2516
|
n((i) => ({
|
|
2503
2517
|
...i,
|
|
2504
2518
|
suggestions: f
|
|
2505
2519
|
}));
|
|
2506
|
-
}, []), y =
|
|
2520
|
+
}, []), y = F(() => {
|
|
2507
2521
|
n((f) => ({
|
|
2508
2522
|
...f,
|
|
2509
2523
|
suggestions: []
|
|
@@ -2515,7 +2529,7 @@ function Bt(e) {
|
|
|
2515
2529
|
return f;
|
|
2516
2530
|
const i = u(f.clientMessages), T = new Set(
|
|
2517
2531
|
f.clientMessages.map((w) => w.messageId)
|
|
2518
|
-
),
|
|
2532
|
+
), x = f.uiMessages.filter(
|
|
2519
2533
|
(w) => {
|
|
2520
2534
|
var P;
|
|
2521
2535
|
return !T.has(w.id) && ((P = w.content[0]) == null ? void 0 : P.type) === "component";
|
|
@@ -2525,27 +2539,27 @@ function Bt(e) {
|
|
|
2525
2539
|
...f,
|
|
2526
2540
|
uiMessages: oe([
|
|
2527
2541
|
...i,
|
|
2528
|
-
...
|
|
2542
|
+
...x
|
|
2529
2543
|
])
|
|
2530
2544
|
};
|
|
2531
2545
|
});
|
|
2532
2546
|
}, [l]);
|
|
2533
|
-
const I =
|
|
2547
|
+
const I = F(() => {
|
|
2534
2548
|
if (!t)
|
|
2535
2549
|
return;
|
|
2536
2550
|
const f = Q(), i = s.agentId;
|
|
2537
2551
|
f.abortCurrentRequest(i);
|
|
2538
|
-
}, [s.agentId, t]),
|
|
2552
|
+
}, [s.agentId, t]), A = F(
|
|
2539
2553
|
async (f) => {
|
|
2540
2554
|
if (!t)
|
|
2541
2555
|
return;
|
|
2542
2556
|
const i = Q(), T = s.agentId;
|
|
2543
2557
|
await i.replaceMessages(T, f);
|
|
2544
|
-
const
|
|
2558
|
+
const x = u(f);
|
|
2545
2559
|
n((w) => ({
|
|
2546
2560
|
...w,
|
|
2547
2561
|
clientMessages: f,
|
|
2548
|
-
uiMessages:
|
|
2562
|
+
uiMessages: x
|
|
2549
2563
|
}));
|
|
2550
2564
|
},
|
|
2551
2565
|
[s.agentId, t]
|
|
@@ -2566,11 +2580,11 @@ function Bt(e) {
|
|
|
2566
2580
|
unregisterMessageActions: o,
|
|
2567
2581
|
clearAllMessageActions: c,
|
|
2568
2582
|
// Tool integration
|
|
2569
|
-
addMessage:
|
|
2583
|
+
addMessage: p,
|
|
2570
2584
|
// Abort control
|
|
2571
2585
|
abortCurrentRequest: I,
|
|
2572
2586
|
// Conversation loading
|
|
2573
|
-
loadMessages:
|
|
2587
|
+
loadMessages: A
|
|
2574
2588
|
};
|
|
2575
2589
|
}
|
|
2576
2590
|
var bt = /* @__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))(bt || {});
|
|
@@ -2587,7 +2601,7 @@ async function Et(e, s = !0) {
|
|
|
2587
2601
|
try {
|
|
2588
2602
|
a = JSON.parse(t);
|
|
2589
2603
|
} catch (u) {
|
|
2590
|
-
|
|
2604
|
+
M("Invalid cached Jetpack token: %O", u);
|
|
2591
2605
|
}
|
|
2592
2606
|
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && s)
|
|
2593
2607
|
return a;
|
|
@@ -2609,7 +2623,7 @@ async function Et(e, s = !0) {
|
|
|
2609
2623
|
method: "POST"
|
|
2610
2624
|
});
|
|
2611
2625
|
} catch (u) {
|
|
2612
|
-
throw
|
|
2626
|
+
throw M("Failed to fetch Jetpack token: %O", u), new Error(e(u));
|
|
2613
2627
|
}
|
|
2614
2628
|
if (!(o != null && o.token))
|
|
2615
2629
|
throw new Error(
|
|
@@ -2623,17 +2637,17 @@ async function Et(e, s = !0) {
|
|
|
2623
2637
|
try {
|
|
2624
2638
|
localStorage.setItem(Te, JSON.stringify(c));
|
|
2625
2639
|
} catch (u) {
|
|
2626
|
-
|
|
2640
|
+
M("Error storing token in localStorage: %O", u);
|
|
2627
2641
|
}
|
|
2628
2642
|
return c;
|
|
2629
2643
|
}
|
|
2630
|
-
const
|
|
2644
|
+
const Bt = (e) => async () => {
|
|
2631
2645
|
const s = {};
|
|
2632
2646
|
try {
|
|
2633
2647
|
const t = await Et(e);
|
|
2634
2648
|
t != null && t.token && (s.Authorization = `${t.token}`);
|
|
2635
2649
|
} catch (t) {
|
|
2636
|
-
throw
|
|
2650
|
+
throw M("Failed to get Jetpack token for auth: %O", t), t;
|
|
2637
2651
|
}
|
|
2638
2652
|
return s;
|
|
2639
2653
|
};
|
|
@@ -2695,24 +2709,24 @@ export {
|
|
|
2695
2709
|
Pt as convertAbilityToTool,
|
|
2696
2710
|
Dt as createAbortController,
|
|
2697
2711
|
rt as createClient,
|
|
2698
|
-
|
|
2712
|
+
Bt as createJetpackAuthProvider,
|
|
2699
2713
|
zt as createOdieBotId,
|
|
2700
2714
|
Fe as createRequestId,
|
|
2701
2715
|
je as createTaskId,
|
|
2702
2716
|
ie as createTextMessage,
|
|
2703
|
-
|
|
2704
|
-
|
|
2717
|
+
D as extractTextFromMessage,
|
|
2718
|
+
L as extractToolCallsFromMessage,
|
|
2705
2719
|
Q as getAgentManager,
|
|
2706
2720
|
Gt as isOdieBotId,
|
|
2707
2721
|
Vt as isWordPressAbility,
|
|
2708
2722
|
Jt as listConversationsFromServer,
|
|
2709
|
-
|
|
2723
|
+
Kt as loadAllMessagesFromServer,
|
|
2710
2724
|
le as loadChatFromServer,
|
|
2711
2725
|
Ot as parseOdieBotId,
|
|
2712
|
-
|
|
2726
|
+
Lt as useAgentChat,
|
|
2713
2727
|
Ft as useClientAbilities,
|
|
2714
2728
|
qt as useClientContext,
|
|
2715
2729
|
Ht as useClientTools,
|
|
2716
2730
|
jt as useClientToolsWithAbilities,
|
|
2717
|
-
|
|
2731
|
+
vt as useMessageActions
|
|
2718
2732
|
};
|