@automattic/agenttic-client 0.1.60 → 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 -0
- package/dist/client/types/index.d.ts.map +1 -1
- package/dist/client/utils/internal/requests.d.ts +1 -0
- package/dist/client/utils/internal/requests.d.ts.map +1 -1
- package/dist/index.js +578 -569
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -2,7 +2,7 @@ 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
3
|
var te = (e, s, t) => Fe(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
4
|
import je, { useMemo as Se, useCallback as H, useState as ve, useRef as pe, useEffect as se } from "react";
|
|
5
|
-
import { l as
|
|
5
|
+
import { l as A, f as Ae, a as L } from "./logger-aKHbTlwk.js";
|
|
6
6
|
import he from "@wordpress/api-fetch";
|
|
7
7
|
function Ft(e) {
|
|
8
8
|
return Se(() => e ? {
|
|
@@ -10,7 +10,7 @@ function Ft(e) {
|
|
|
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]);
|
|
@@ -27,7 +27,7 @@ function ce({
|
|
|
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
33
|
}, [e]), n = H(
|
|
@@ -37,7 +37,7 @@ function ce({
|
|
|
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]
|
|
@@ -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 O() {
|
|
96
96
|
return ue();
|
|
97
97
|
}
|
|
98
98
|
function De() {
|
|
@@ -191,7 +191,7 @@ function ie(e, s) {
|
|
|
191
191
|
role: "user",
|
|
192
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
|
|
@@ -203,7 +203,7 @@ function Q(e) {
|
|
|
203
203
|
role: "agent",
|
|
204
204
|
parts: [xe(e)],
|
|
205
205
|
kind: "message",
|
|
206
|
-
messageId:
|
|
206
|
+
messageId: O(),
|
|
207
207
|
metadata: {
|
|
208
208
|
timestamp: Date.now()
|
|
209
209
|
}
|
|
@@ -226,7 +226,7 @@ function Y(e, s = []) {
|
|
|
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,78 +318,78 @@ 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: y, value:
|
|
328
|
+
const { done: y, value: v } = await a.read();
|
|
329
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 &&
|
|
347
|
-
const
|
|
346
|
+
), !l && d.params.id && (l = d.params.id), l)) {
|
|
347
|
+
const w = r.getCurrentMessage();
|
|
348
348
|
yield {
|
|
349
349
|
id: l,
|
|
350
350
|
status: {
|
|
351
351
|
state: "working",
|
|
352
|
-
message:
|
|
352
|
+
message: w
|
|
353
353
|
},
|
|
354
354
|
final: !1,
|
|
355
355
|
text: r.getTextContent()
|
|
356
356
|
};
|
|
357
357
|
}
|
|
358
|
-
} catch (
|
|
359
|
-
|
|
358
|
+
} catch (w) {
|
|
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
|
-
},
|
|
366
|
+
}, w = ye(c);
|
|
367
367
|
yield {
|
|
368
|
-
id:
|
|
369
|
-
sessionId:
|
|
370
|
-
status:
|
|
371
|
-
final:
|
|
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
372
|
text: F(c),
|
|
373
|
-
progressMessage:
|
|
374
|
-
progressPhase:
|
|
373
|
+
progressMessage: w == null ? void 0 : w.summary,
|
|
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
|
-
},
|
|
380
|
+
}, w = ye(c);
|
|
381
381
|
yield {
|
|
382
|
-
id:
|
|
383
|
-
sessionId:
|
|
384
|
-
status:
|
|
385
|
-
final:
|
|
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
386
|
text: F(c),
|
|
387
|
-
progressMessage:
|
|
388
|
-
progressPhase:
|
|
387
|
+
progressMessage: w == null ? void 0 : w.summary,
|
|
388
|
+
progressPhase: w == null ? void 0 : w.phase
|
|
389
389
|
};
|
|
390
390
|
}
|
|
391
391
|
}
|
|
392
|
-
o =
|
|
392
|
+
o = I;
|
|
393
393
|
}
|
|
394
394
|
} finally {
|
|
395
395
|
a.releaseLock();
|
|
@@ -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
|
/**
|
|
@@ -484,7 +484,7 @@ class Ye {
|
|
|
484
484
|
}
|
|
485
485
|
}
|
|
486
486
|
function Ce(e, s, t = "request") {
|
|
487
|
-
throw clearTimeout(s),
|
|
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
489
|
function be(e, s = "request") {
|
|
490
490
|
if (!e.ok)
|
|
@@ -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 = {
|
|
@@ -538,88 +538,95 @@ function ke(e, s) {
|
|
|
538
538
|
once: !0
|
|
539
539
|
}), t.signal;
|
|
540
540
|
}
|
|
541
|
-
function Pe(e, s, t) {
|
|
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
550
|
async function Z(e, s, t, a, n, o) {
|
|
550
|
-
const { message: r, sessionId: l, taskId: i, metadata:
|
|
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
|
-
const
|
|
560
|
+
I && (c.sessionId = I);
|
|
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
|
-
), T = await at(y,
|
|
566
|
-
return st("POST",
|
|
567
|
-
request:
|
|
566
|
+
), T = await at(y, f);
|
|
567
|
+
return st("POST", S, T, w), {
|
|
568
|
+
request: w,
|
|
568
569
|
headers: T,
|
|
569
|
-
enhancedMessage:
|
|
570
|
-
effectiveSessionId:
|
|
571
|
-
fullAgentUrl:
|
|
570
|
+
enhancedMessage: d,
|
|
571
|
+
effectiveSessionId: I,
|
|
572
|
+
fullAgentUrl: S
|
|
572
573
|
};
|
|
573
574
|
}
|
|
574
575
|
async function _e(e, s, t = {}) {
|
|
575
|
-
const { request: a, headers: n, fullAgentUrl: o } = e, { timeout: r } = s, { abortSignal:
|
|
576
|
+
const { request: a, headers: n, fullAgentUrl: o } = e, { timeout: r, credentials: l } = s, { abortSignal: i } = t, { timeoutId: g, controller: u } = Re(
|
|
576
577
|
r,
|
|
577
578
|
"request"
|
|
578
|
-
),
|
|
579
|
+
), p = i ? ke(u.signal, i) : u.signal;
|
|
579
580
|
try {
|
|
580
|
-
const
|
|
581
|
+
const y = Pe(
|
|
581
582
|
n,
|
|
582
583
|
JSON.stringify(a),
|
|
583
|
-
|
|
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
596
|
o,
|
|
595
|
-
|
|
596
|
-
Ae(
|
|
597
|
-
), Ze(
|
|
598
|
-
} catch (
|
|
599
|
-
Ce(
|
|
597
|
+
v.status,
|
|
598
|
+
Ae(f)
|
|
599
|
+
), Ze(f, "request");
|
|
600
|
+
} catch (y) {
|
|
601
|
+
Ce(y, g, "request");
|
|
600
602
|
}
|
|
601
603
|
}
|
|
602
604
|
async function* Ee(e, s, t) {
|
|
603
|
-
const { request: a, headers: n, fullAgentUrl: o } = e, {
|
|
604
|
-
streamingTimeout:
|
|
605
|
-
abortSignal:
|
|
606
|
-
enableTokenStreaming:
|
|
607
|
-
} = t, { timeoutId:
|
|
608
|
-
|
|
605
|
+
const { request: a, headers: n, fullAgentUrl: o } = e, { credentials: r } = s, {
|
|
606
|
+
streamingTimeout: l = 6e4,
|
|
607
|
+
abortSignal: i,
|
|
608
|
+
enableTokenStreaming: g = !1
|
|
609
|
+
} = t, { timeoutId: u, controller: p } = Re(
|
|
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
|
|
618
|
-
yield* Xe(
|
|
619
|
-
supportDeltas:
|
|
624
|
+
const I = g && a.tokenStreaming === !0;
|
|
625
|
+
yield* Xe(h.body, {
|
|
626
|
+
supportDeltas: I
|
|
620
627
|
});
|
|
621
|
-
} catch (
|
|
622
|
-
Ce(
|
|
628
|
+
} catch (v) {
|
|
629
|
+
Ce(v, u, "streaming request");
|
|
623
630
|
}
|
|
624
631
|
}
|
|
625
632
|
const nt = 12e4;
|
|
@@ -637,16 +644,16 @@ async function ee(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 ee(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
|
|
@@ -739,20 +746,20 @@ 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
751
|
const u = await ee(
|
|
745
752
|
s,
|
|
746
753
|
i,
|
|
747
|
-
|
|
754
|
+
g,
|
|
748
755
|
t,
|
|
749
756
|
l
|
|
750
|
-
), { result:
|
|
751
|
-
y && (o = !0),
|
|
757
|
+
), { result: p, returnToAgent: y, agentMessage: v } = de(u);
|
|
758
|
+
y && (o = !0), v && n.push(Q(v)), a.push(
|
|
752
759
|
D(
|
|
753
760
|
l,
|
|
754
761
|
i,
|
|
755
|
-
|
|
762
|
+
p
|
|
756
763
|
)
|
|
757
764
|
);
|
|
758
765
|
} catch (u) {
|
|
@@ -800,13 +807,13 @@ async function ae(e, s, t, a, n, o, r) {
|
|
|
800
807
|
});
|
|
801
808
|
}
|
|
802
809
|
async function we(e, s, t, a, n, o, r, l, i = []) {
|
|
803
|
-
const
|
|
810
|
+
const g = {
|
|
804
811
|
message: s,
|
|
805
812
|
taskId: e,
|
|
806
813
|
sessionId: o
|
|
807
814
|
// Use the provided sessionId to maintain conversation continuity
|
|
808
|
-
}, u = l || { isStreaming: !0 },
|
|
809
|
-
|
|
815
|
+
}, u = l || { isStreaming: !0 }, p = await Z(
|
|
816
|
+
g,
|
|
810
817
|
t,
|
|
811
818
|
{
|
|
812
819
|
...u
|
|
@@ -814,7 +821,7 @@ async function we(e, s, t, a, n, o, r, l, i = []) {
|
|
|
814
821
|
a,
|
|
815
822
|
n,
|
|
816
823
|
o
|
|
817
|
-
), y = Ee(
|
|
824
|
+
), y = Ee(p, t, {
|
|
818
825
|
...u,
|
|
819
826
|
abortSignal: r
|
|
820
827
|
});
|
|
@@ -834,7 +841,7 @@ async function we(e, s, t, a, n, o, r, l, i = []) {
|
|
|
834
841
|
);
|
|
835
842
|
}
|
|
836
843
|
async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
837
|
-
var
|
|
844
|
+
var g, u, p, y, v, f, h, I, S, d, c, w;
|
|
838
845
|
for await (const T of e) {
|
|
839
846
|
if (T.sessionId && !n && (n = T.sessionId), yield T, T.status.state === "running" && T.status.message && s && await rt(
|
|
840
847
|
s,
|
|
@@ -844,15 +851,15 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
844
851
|
T.status.message
|
|
845
852
|
);
|
|
846
853
|
for (const E of b) {
|
|
847
|
-
const { toolCallId:
|
|
854
|
+
const { toolCallId: $, toolId: U, arguments: m } = E.data;
|
|
848
855
|
ee(
|
|
849
856
|
s,
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
(u = (
|
|
853
|
-
|
|
854
|
-
).catch((
|
|
855
|
-
|
|
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);
|
|
856
863
|
});
|
|
857
864
|
}
|
|
858
865
|
yield {
|
|
@@ -863,7 +870,7 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
863
870
|
role: "agent",
|
|
864
871
|
kind: "message",
|
|
865
872
|
parts: b,
|
|
866
|
-
messageId:
|
|
873
|
+
messageId: O()
|
|
867
874
|
}
|
|
868
875
|
},
|
|
869
876
|
final: !1,
|
|
@@ -876,23 +883,23 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
876
883
|
);
|
|
877
884
|
if (b.length > 0) {
|
|
878
885
|
const E = [];
|
|
879
|
-
let
|
|
880
|
-
const
|
|
881
|
-
for (const
|
|
886
|
+
let $ = !1;
|
|
887
|
+
const U = [], m = [];
|
|
888
|
+
for (const x of b) {
|
|
882
889
|
const {
|
|
883
|
-
toolCallId:
|
|
890
|
+
toolCallId: M,
|
|
884
891
|
toolId: k,
|
|
885
|
-
arguments:
|
|
886
|
-
} =
|
|
892
|
+
arguments: N
|
|
893
|
+
} = x.data;
|
|
887
894
|
try {
|
|
888
895
|
const R = await ee(
|
|
889
896
|
s,
|
|
890
897
|
k,
|
|
891
|
-
|
|
892
|
-
(y = (
|
|
893
|
-
|
|
898
|
+
N,
|
|
899
|
+
(y = (p = T.status) == null ? void 0 : p.message) == null ? void 0 : y.messageId,
|
|
900
|
+
M
|
|
894
901
|
), { result: C, returnToAgent: P, agentMessage: j } = de(R);
|
|
895
|
-
if (P && (
|
|
902
|
+
if (P && ($ = !0), j && m.push(
|
|
896
903
|
Q(j)
|
|
897
904
|
), C.result instanceof Promise) {
|
|
898
905
|
const K = C.result, q = {
|
|
@@ -900,14 +907,14 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
900
907
|
resolvedValue: null
|
|
901
908
|
};
|
|
902
909
|
ge.set(
|
|
903
|
-
|
|
910
|
+
M,
|
|
904
911
|
q
|
|
905
912
|
), K.then((_) => {
|
|
906
913
|
q.resolvedValue = _;
|
|
907
914
|
}).catch((_) => {
|
|
908
|
-
|
|
915
|
+
A(
|
|
909
916
|
"Promise rejected for tool call %s: %O",
|
|
910
|
-
|
|
917
|
+
M,
|
|
911
918
|
_
|
|
912
919
|
), q.resolvedValue = {
|
|
913
920
|
error: _ instanceof Error ? _.message : String(_)
|
|
@@ -915,44 +922,44 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
915
922
|
});
|
|
916
923
|
}
|
|
917
924
|
const J = D(
|
|
918
|
-
|
|
925
|
+
M,
|
|
919
926
|
k,
|
|
920
927
|
C
|
|
921
928
|
);
|
|
922
|
-
E.push(J),
|
|
929
|
+
E.push(J), U.push(J);
|
|
923
930
|
} catch (R) {
|
|
924
931
|
const C = D(
|
|
925
|
-
|
|
932
|
+
M,
|
|
926
933
|
k,
|
|
927
934
|
void 0,
|
|
928
935
|
R instanceof Error ? R.message : String(R)
|
|
929
936
|
);
|
|
930
|
-
E.push(C),
|
|
937
|
+
E.push(C), U.push(C);
|
|
931
938
|
}
|
|
932
939
|
}
|
|
933
940
|
if (r.push(T.status.message), E.length > 0 && r.push({
|
|
934
941
|
role: "agent",
|
|
935
942
|
kind: "message",
|
|
936
943
|
parts: E,
|
|
937
|
-
messageId:
|
|
938
|
-
}),
|
|
939
|
-
const
|
|
944
|
+
messageId: O()
|
|
945
|
+
}), $) {
|
|
946
|
+
const x = Ie(r), M = Y(
|
|
940
947
|
[],
|
|
941
948
|
// Empty array - tool results are already in historyDataParts
|
|
942
|
-
|
|
949
|
+
x
|
|
943
950
|
);
|
|
944
951
|
yield {
|
|
945
952
|
id: T.id,
|
|
946
953
|
status: {
|
|
947
954
|
state: "working",
|
|
948
|
-
message:
|
|
955
|
+
message: M
|
|
949
956
|
},
|
|
950
957
|
final: !1,
|
|
951
958
|
text: ""
|
|
952
959
|
};
|
|
953
960
|
const k = await we(
|
|
954
961
|
T.id,
|
|
955
|
-
|
|
962
|
+
M,
|
|
956
963
|
a,
|
|
957
964
|
s,
|
|
958
965
|
t,
|
|
@@ -961,28 +968,28 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
961
968
|
i,
|
|
962
969
|
r
|
|
963
970
|
);
|
|
964
|
-
let
|
|
971
|
+
let N = null;
|
|
965
972
|
for await (const P of k)
|
|
966
|
-
P.final ?
|
|
967
|
-
if (!
|
|
973
|
+
P.final ? N = P : yield P;
|
|
974
|
+
if (!N)
|
|
968
975
|
throw new Error(
|
|
969
976
|
"Continue task stream ended without final result"
|
|
970
977
|
);
|
|
971
|
-
let R = (
|
|
972
|
-
|
|
973
|
-
) : [], C =
|
|
978
|
+
let R = (v = N.status) != null && v.message ? B(
|
|
979
|
+
N.status.message
|
|
980
|
+
) : [], C = N;
|
|
974
981
|
if (R.length > 0)
|
|
975
982
|
for (yield {
|
|
976
|
-
...
|
|
983
|
+
...N,
|
|
977
984
|
final: !1,
|
|
978
985
|
text: F(
|
|
979
|
-
((
|
|
986
|
+
((f = N.status) == null ? void 0 : f.message) || {
|
|
980
987
|
parts: [],
|
|
981
|
-
messageId:
|
|
988
|
+
messageId: O()
|
|
982
989
|
}
|
|
983
990
|
)
|
|
984
991
|
}; R.length > 0; ) {
|
|
985
|
-
(
|
|
992
|
+
(h = C.status) != null && h.message && r.push(
|
|
986
993
|
C.status.message
|
|
987
994
|
);
|
|
988
995
|
const {
|
|
@@ -991,7 +998,7 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
991
998
|
} = await Oe(
|
|
992
999
|
R,
|
|
993
1000
|
s,
|
|
994
|
-
(
|
|
1001
|
+
(S = (I = C.status) == null ? void 0 : I.message) == null ? void 0 : S.messageId
|
|
995
1002
|
);
|
|
996
1003
|
if (P.length > 0 && (yield {
|
|
997
1004
|
id: C.id,
|
|
@@ -1001,7 +1008,7 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1001
1008
|
role: "agent",
|
|
1002
1009
|
kind: "message",
|
|
1003
1010
|
parts: P,
|
|
1004
|
-
messageId:
|
|
1011
|
+
messageId: O()
|
|
1005
1012
|
}
|
|
1006
1013
|
// Simple message with just the results
|
|
1007
1014
|
},
|
|
@@ -1031,7 +1038,7 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1031
1038
|
throw new Error(
|
|
1032
1039
|
"Continue task stream ended without final result"
|
|
1033
1040
|
);
|
|
1034
|
-
C = _, R = (
|
|
1041
|
+
C = _, R = (d = C.status) != null && d.message ? B(
|
|
1035
1042
|
C.status.message
|
|
1036
1043
|
) : [], R.length > 0 && (yield {
|
|
1037
1044
|
id: C.id,
|
|
@@ -1040,7 +1047,7 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1040
1047
|
text: F(
|
|
1041
1048
|
((c = C.status) == null ? void 0 : c.message) || {
|
|
1042
1049
|
parts: [],
|
|
1043
|
-
messageId:
|
|
1050
|
+
messageId: O()
|
|
1044
1051
|
}
|
|
1045
1052
|
)
|
|
1046
1053
|
});
|
|
@@ -1051,33 +1058,33 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1051
1058
|
...C,
|
|
1052
1059
|
final: !0,
|
|
1053
1060
|
text: F(
|
|
1054
|
-
((
|
|
1061
|
+
((w = C.status) == null ? void 0 : w.message) || {
|
|
1055
1062
|
parts: [],
|
|
1056
|
-
messageId:
|
|
1063
|
+
messageId: O()
|
|
1057
1064
|
}
|
|
1058
1065
|
)
|
|
1059
1066
|
};
|
|
1060
1067
|
} else {
|
|
1061
|
-
const
|
|
1068
|
+
const x = {
|
|
1062
1069
|
...T.status.message,
|
|
1063
|
-
parts:
|
|
1064
|
-
},
|
|
1070
|
+
parts: U
|
|
1071
|
+
}, M = {
|
|
1065
1072
|
...T,
|
|
1066
1073
|
status: {
|
|
1067
1074
|
...T.status,
|
|
1068
|
-
message:
|
|
1075
|
+
message: x
|
|
1069
1076
|
},
|
|
1070
|
-
final:
|
|
1077
|
+
final: m.length === 0,
|
|
1071
1078
|
// Only final if no agent messages to follow
|
|
1072
|
-
text: F(
|
|
1079
|
+
text: F(x)
|
|
1073
1080
|
};
|
|
1074
|
-
if (yield
|
|
1075
|
-
const k =
|
|
1081
|
+
if (yield M, m.length > 0) {
|
|
1082
|
+
const k = m.map((R) => F(R)).join(" "), N = Q(k);
|
|
1076
1083
|
yield {
|
|
1077
|
-
id:
|
|
1084
|
+
id: M.id,
|
|
1078
1085
|
status: {
|
|
1079
1086
|
state: "completed",
|
|
1080
|
-
message:
|
|
1087
|
+
message: N
|
|
1081
1088
|
},
|
|
1082
1089
|
final: !0,
|
|
1083
1090
|
text: k
|
|
@@ -1097,201 +1104,203 @@ function lt(e) {
|
|
|
1097
1104
|
timeout: o = nt,
|
|
1098
1105
|
toolProvider: r,
|
|
1099
1106
|
contextProvider: l,
|
|
1100
|
-
enableStreaming: i = !1
|
|
1101
|
-
|
|
1107
|
+
enableStreaming: i = !1,
|
|
1108
|
+
credentials: g
|
|
1109
|
+
} = e, u = {
|
|
1102
1110
|
agentId: s,
|
|
1103
1111
|
agentUrl: t,
|
|
1104
1112
|
authProvider: a,
|
|
1105
|
-
timeout: o
|
|
1113
|
+
timeout: o,
|
|
1114
|
+
credentials: g
|
|
1106
1115
|
};
|
|
1107
1116
|
return {
|
|
1108
|
-
async sendMessage(
|
|
1109
|
-
var
|
|
1110
|
-
const { abortSignal:
|
|
1111
|
-
|
|
1112
|
-
const
|
|
1117
|
+
async sendMessage(p) {
|
|
1118
|
+
var c, w;
|
|
1119
|
+
const { abortSignal: y } = p, v = p.sessionId || n || void 0, f = [];
|
|
1120
|
+
f.push(p.message);
|
|
1121
|
+
const h = await Z(
|
|
1122
|
+
p,
|
|
1113
1123
|
u,
|
|
1114
|
-
d,
|
|
1115
1124
|
{ isStreaming: !1 },
|
|
1116
1125
|
r,
|
|
1117
1126
|
l,
|
|
1118
|
-
|
|
1127
|
+
v
|
|
1119
1128
|
);
|
|
1120
|
-
let
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
{ abortSignal:
|
|
1129
|
+
let I = await _e(
|
|
1130
|
+
h,
|
|
1131
|
+
u,
|
|
1132
|
+
{ abortSignal: y }
|
|
1124
1133
|
);
|
|
1125
|
-
const
|
|
1126
|
-
for (;
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1134
|
+
const S = [], d = [];
|
|
1135
|
+
for (; I.status.message && r; ) {
|
|
1136
|
+
const T = B(
|
|
1137
|
+
I.status.message
|
|
1129
1138
|
);
|
|
1130
|
-
if (
|
|
1139
|
+
if (T.length === 0)
|
|
1131
1140
|
break;
|
|
1132
|
-
|
|
1133
|
-
const
|
|
1134
|
-
let
|
|
1135
|
-
for (const
|
|
1141
|
+
S.push(...T);
|
|
1142
|
+
const b = [];
|
|
1143
|
+
let E = !1;
|
|
1144
|
+
for (const $ of T) {
|
|
1136
1145
|
const {
|
|
1137
1146
|
toolCallId: U,
|
|
1138
|
-
toolId:
|
|
1139
|
-
arguments:
|
|
1140
|
-
} =
|
|
1147
|
+
toolId: m,
|
|
1148
|
+
arguments: x
|
|
1149
|
+
} = $.data;
|
|
1141
1150
|
try {
|
|
1142
1151
|
const M = await ee(
|
|
1143
1152
|
r,
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
), { result:
|
|
1147
|
-
|
|
1148
|
-
Q(
|
|
1153
|
+
m,
|
|
1154
|
+
x
|
|
1155
|
+
), { result: k, returnToAgent: N, agentMessage: R } = de(M);
|
|
1156
|
+
N && (E = !0), R && d.push(
|
|
1157
|
+
Q(R)
|
|
1149
1158
|
);
|
|
1150
|
-
const
|
|
1159
|
+
const C = D(
|
|
1151
1160
|
U,
|
|
1152
|
-
|
|
1153
|
-
|
|
1161
|
+
m,
|
|
1162
|
+
k
|
|
1154
1163
|
);
|
|
1155
|
-
|
|
1164
|
+
b.push(C), S.push(C);
|
|
1156
1165
|
} catch (M) {
|
|
1157
|
-
const
|
|
1166
|
+
const k = D(
|
|
1158
1167
|
U,
|
|
1159
|
-
|
|
1168
|
+
m,
|
|
1160
1169
|
void 0,
|
|
1161
1170
|
M instanceof Error ? M.message : String(M)
|
|
1162
1171
|
);
|
|
1163
|
-
|
|
1172
|
+
b.push(k), S.push(k);
|
|
1164
1173
|
}
|
|
1165
1174
|
}
|
|
1166
|
-
if (
|
|
1167
|
-
const
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1175
|
+
if (f.push(I.status.message), E) {
|
|
1176
|
+
const $ = Y(b);
|
|
1177
|
+
I = await ae(
|
|
1178
|
+
I.id,
|
|
1179
|
+
$,
|
|
1180
|
+
u,
|
|
1172
1181
|
r,
|
|
1173
1182
|
l,
|
|
1174
|
-
|
|
1175
|
-
|
|
1183
|
+
v,
|
|
1184
|
+
y
|
|
1176
1185
|
);
|
|
1177
1186
|
} else
|
|
1178
1187
|
break;
|
|
1179
1188
|
}
|
|
1180
|
-
if (
|
|
1181
|
-
const
|
|
1182
|
-
...
|
|
1183
|
-
parts:
|
|
1189
|
+
if (S.length > 0 && (c = I.status) != null && c.message) {
|
|
1190
|
+
const T = {
|
|
1191
|
+
...I.status.message,
|
|
1192
|
+
parts: S
|
|
1184
1193
|
};
|
|
1185
|
-
|
|
1186
|
-
...
|
|
1194
|
+
I = {
|
|
1195
|
+
...I,
|
|
1187
1196
|
status: {
|
|
1188
|
-
...
|
|
1189
|
-
message:
|
|
1197
|
+
...I.status,
|
|
1198
|
+
message: T
|
|
1190
1199
|
}
|
|
1191
1200
|
};
|
|
1192
1201
|
}
|
|
1193
|
-
if (
|
|
1194
|
-
const
|
|
1202
|
+
if (d.length > 0) {
|
|
1203
|
+
const T = d.map((E) => F(E)).join(" "), b = Q(T);
|
|
1195
1204
|
return {
|
|
1196
|
-
...
|
|
1205
|
+
...I,
|
|
1197
1206
|
// Keep the enhanced message with tool results
|
|
1198
1207
|
// The agent message will be handled separately by the caller
|
|
1199
|
-
text:
|
|
1200
|
-
agentMessage:
|
|
1208
|
+
text: T,
|
|
1209
|
+
agentMessage: b
|
|
1201
1210
|
// Add this for the caller to handle
|
|
1202
1211
|
};
|
|
1203
1212
|
}
|
|
1204
1213
|
return {
|
|
1205
|
-
...
|
|
1214
|
+
...I,
|
|
1206
1215
|
text: F(
|
|
1207
|
-
((
|
|
1216
|
+
((w = I.status) == null ? void 0 : w.message) || {
|
|
1208
1217
|
parts: [],
|
|
1209
|
-
messageId:
|
|
1218
|
+
messageId: O()
|
|
1210
1219
|
}
|
|
1211
1220
|
)
|
|
1212
1221
|
};
|
|
1213
1222
|
},
|
|
1214
|
-
async *sendMessageStream(
|
|
1223
|
+
async *sendMessageStream(p) {
|
|
1215
1224
|
const {
|
|
1216
|
-
withHistory:
|
|
1217
|
-
abortSignal:
|
|
1218
|
-
enableStreaming:
|
|
1219
|
-
} =
|
|
1220
|
-
|
|
1221
|
-
const
|
|
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,
|
|
1222
1232
|
u,
|
|
1223
|
-
d,
|
|
1224
1233
|
{
|
|
1225
1234
|
isStreaming: !0,
|
|
1226
1235
|
// Always use message/stream endpoint for SSE
|
|
1227
|
-
enableTokenStreaming:
|
|
1236
|
+
enableTokenStreaming: I
|
|
1228
1237
|
},
|
|
1229
1238
|
r,
|
|
1230
1239
|
l,
|
|
1231
|
-
|
|
1232
|
-
),
|
|
1233
|
-
A,
|
|
1240
|
+
h
|
|
1241
|
+
), c = Ee(
|
|
1234
1242
|
d,
|
|
1243
|
+
u,
|
|
1235
1244
|
{
|
|
1236
|
-
enableTokenStreaming:
|
|
1245
|
+
enableTokenStreaming: I,
|
|
1237
1246
|
// Token streaming is optional
|
|
1238
1247
|
streamingTimeout: o,
|
|
1239
|
-
abortSignal:
|
|
1248
|
+
abortSignal: v
|
|
1240
1249
|
}
|
|
1241
1250
|
);
|
|
1242
1251
|
yield* Ne(
|
|
1243
|
-
|
|
1252
|
+
c,
|
|
1244
1253
|
r,
|
|
1245
1254
|
l,
|
|
1246
|
-
|
|
1247
|
-
m,
|
|
1255
|
+
u,
|
|
1248
1256
|
h,
|
|
1249
|
-
v,
|
|
1250
1257
|
y,
|
|
1258
|
+
S,
|
|
1259
|
+
v,
|
|
1251
1260
|
{
|
|
1252
1261
|
isStreaming: !0,
|
|
1253
|
-
enableTokenStreaming:
|
|
1262
|
+
enableTokenStreaming: I,
|
|
1254
1263
|
streamingTimeout: o
|
|
1255
1264
|
}
|
|
1256
1265
|
);
|
|
1257
1266
|
},
|
|
1258
|
-
async continueTask(
|
|
1259
|
-
var
|
|
1260
|
-
const
|
|
1261
|
-
let
|
|
1267
|
+
async continueTask(p, y, v) {
|
|
1268
|
+
var S;
|
|
1269
|
+
const f = ie(y);
|
|
1270
|
+
let I = await ae(
|
|
1271
|
+
p,
|
|
1272
|
+
f,
|
|
1262
1273
|
u,
|
|
1263
|
-
x,
|
|
1264
|
-
d,
|
|
1265
1274
|
r,
|
|
1266
1275
|
l,
|
|
1267
|
-
|
|
1276
|
+
v
|
|
1268
1277
|
);
|
|
1269
|
-
for (;
|
|
1270
|
-
const
|
|
1271
|
-
|
|
1278
|
+
for (; I.status.state === "input-required" && I.status.message && r; ) {
|
|
1279
|
+
const d = B(
|
|
1280
|
+
I.status.message
|
|
1272
1281
|
);
|
|
1273
|
-
if (
|
|
1282
|
+
if (d.length === 0)
|
|
1274
1283
|
break;
|
|
1275
|
-
const { results:
|
|
1276
|
-
if (
|
|
1277
|
-
const
|
|
1278
|
-
|
|
1279
|
-
|
|
1280
|
-
|
|
1281
|
-
|
|
1284
|
+
const { results: c, shouldReturnToAgent: w } = await Oe(d, r);
|
|
1285
|
+
if (w) {
|
|
1286
|
+
const T = Y(c);
|
|
1287
|
+
I = await ae(
|
|
1288
|
+
I.id,
|
|
1289
|
+
T,
|
|
1290
|
+
u,
|
|
1282
1291
|
r,
|
|
1283
1292
|
l,
|
|
1284
|
-
|
|
1293
|
+
v
|
|
1285
1294
|
);
|
|
1286
1295
|
} else
|
|
1287
1296
|
break;
|
|
1288
1297
|
}
|
|
1289
1298
|
return {
|
|
1290
|
-
...
|
|
1299
|
+
...I,
|
|
1291
1300
|
text: F(
|
|
1292
|
-
((
|
|
1301
|
+
((S = I.status) == null ? void 0 : S.message) || {
|
|
1293
1302
|
parts: [],
|
|
1294
|
-
messageId:
|
|
1303
|
+
messageId: O()
|
|
1295
1304
|
}
|
|
1296
1305
|
)
|
|
1297
1306
|
};
|
|
@@ -1346,7 +1355,7 @@ function ct(e) {
|
|
|
1346
1355
|
role: a,
|
|
1347
1356
|
kind: "message",
|
|
1348
1357
|
parts: s,
|
|
1349
|
-
messageId:
|
|
1358
|
+
messageId: O(),
|
|
1350
1359
|
metadata: {
|
|
1351
1360
|
timestamp: n,
|
|
1352
1361
|
serverId: e.message_id,
|
|
@@ -1364,13 +1373,13 @@ function ut(e) {
|
|
|
1364
1373
|
}
|
|
1365
1374
|
}
|
|
1366
1375
|
function dt(e, s = !1) {
|
|
1367
|
-
var o, r, l, i,
|
|
1368
|
-
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 = {
|
|
1369
1378
|
currentPage: ((o = e.metadata) == null ? void 0 : o.current_page) ?? 1,
|
|
1370
1379
|
itemsPerPage: ((r = e.metadata) == null ? void 0 : r.items_per_page) ?? 10,
|
|
1371
1380
|
totalPages: ((l = e.metadata) == null ? void 0 : l.total_pages) ?? 1,
|
|
1372
1381
|
totalMessages: ((i = e.metadata) == null ? void 0 : i.total_messages) ?? a.length,
|
|
1373
|
-
hasMore: (((
|
|
1382
|
+
hasMore: (((g = e.metadata) == null ? void 0 : g.current_page) ?? 1) < (((u = e.metadata) == null ? void 0 : u.total_pages) ?? 1)
|
|
1374
1383
|
};
|
|
1375
1384
|
return {
|
|
1376
1385
|
messages: a,
|
|
@@ -1391,59 +1400,59 @@ async function le(e, s, t = 1, a = 50, n = !1) {
|
|
|
1391
1400
|
throw new Error(
|
|
1392
1401
|
"chatId and botId are required to load conversation from server"
|
|
1393
1402
|
);
|
|
1394
|
-
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(
|
|
1395
1404
|
`${r}/wpcom/v2/odie/chat/${encodeURIComponent(
|
|
1396
1405
|
o
|
|
1397
1406
|
)}/${encodeURIComponent(e)}`
|
|
1398
1407
|
);
|
|
1399
|
-
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(
|
|
1400
1409
|
"Loading conversation from server: %s (page %d)",
|
|
1401
1410
|
e,
|
|
1402
1411
|
i
|
|
1403
1412
|
);
|
|
1404
1413
|
try {
|
|
1405
|
-
const
|
|
1414
|
+
const p = {
|
|
1406
1415
|
"Content-Type": "application/json"
|
|
1407
1416
|
};
|
|
1408
1417
|
if (l) {
|
|
1409
|
-
const
|
|
1410
|
-
Object.assign(
|
|
1418
|
+
const h = await l();
|
|
1419
|
+
Object.assign(p, h);
|
|
1411
1420
|
}
|
|
1412
1421
|
const y = await fetch(u.toString(), {
|
|
1413
1422
|
method: "GET",
|
|
1414
|
-
headers:
|
|
1423
|
+
headers: p
|
|
1415
1424
|
});
|
|
1416
1425
|
if (!y.ok) {
|
|
1417
|
-
const
|
|
1418
|
-
let
|
|
1426
|
+
const h = await y.text();
|
|
1427
|
+
let I = `Failed to load conversation from server: ${y.status} ${y.statusText}`;
|
|
1419
1428
|
try {
|
|
1420
|
-
const
|
|
1421
|
-
|
|
1429
|
+
const d = JSON.parse(h);
|
|
1430
|
+
d.message && (I = d.message);
|
|
1422
1431
|
} catch {
|
|
1423
1432
|
}
|
|
1424
|
-
const
|
|
1425
|
-
|
|
1433
|
+
const S = new z(
|
|
1434
|
+
I,
|
|
1426
1435
|
y.status,
|
|
1427
|
-
|
|
1436
|
+
h
|
|
1428
1437
|
);
|
|
1429
|
-
throw
|
|
1438
|
+
throw A("Failed to load conversation from server: %O", S), S;
|
|
1430
1439
|
}
|
|
1431
|
-
const
|
|
1432
|
-
return
|
|
1440
|
+
const v = await y.json(), f = dt(v, n);
|
|
1441
|
+
return A(
|
|
1433
1442
|
"Loaded %d messages from server (page %d/%d)",
|
|
1434
|
-
|
|
1435
|
-
|
|
1436
|
-
|
|
1437
|
-
),
|
|
1438
|
-
} catch (
|
|
1439
|
-
if (
|
|
1440
|
-
throw
|
|
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;
|
|
1441
1450
|
const y = new z(
|
|
1442
|
-
`Network error loading conversation: ${
|
|
1451
|
+
`Network error loading conversation: ${p.message}`,
|
|
1443
1452
|
void 0,
|
|
1444
|
-
|
|
1453
|
+
p
|
|
1445
1454
|
);
|
|
1446
|
-
throw
|
|
1455
|
+
throw A("Network error loading conversation: %O", p), y;
|
|
1447
1456
|
}
|
|
1448
1457
|
}
|
|
1449
1458
|
async function Lt(e, s, t = !1) {
|
|
@@ -1455,29 +1464,29 @@ async function Lt(e, s, t = !1) {
|
|
|
1455
1464
|
o.searchParams.set(
|
|
1456
1465
|
"truncation_method",
|
|
1457
1466
|
t ? "first_message" : "last_message"
|
|
1458
|
-
),
|
|
1467
|
+
), A("Listing conversations from server for bot: %s", e);
|
|
1459
1468
|
try {
|
|
1460
1469
|
const r = {
|
|
1461
1470
|
"Content-Type": "application/json"
|
|
1462
1471
|
};
|
|
1463
1472
|
if (n) {
|
|
1464
|
-
const
|
|
1465
|
-
Object.assign(r,
|
|
1473
|
+
const g = await n();
|
|
1474
|
+
Object.assign(r, g);
|
|
1466
1475
|
}
|
|
1467
1476
|
const l = await fetch(o.toString(), {
|
|
1468
1477
|
method: "GET",
|
|
1469
1478
|
headers: r
|
|
1470
1479
|
});
|
|
1471
1480
|
if (!l.ok) {
|
|
1472
|
-
const
|
|
1481
|
+
const g = await l.text(), u = `Failed to list conversations: ${l.status} ${l.statusText}`, p = new z(
|
|
1473
1482
|
u,
|
|
1474
1483
|
l.status,
|
|
1475
|
-
|
|
1484
|
+
g
|
|
1476
1485
|
);
|
|
1477
|
-
throw
|
|
1486
|
+
throw A("Failed to list conversations: %O", p), p;
|
|
1478
1487
|
}
|
|
1479
1488
|
const i = await l.json();
|
|
1480
|
-
return
|
|
1489
|
+
return A("Loaded %d conversations from server", i.length), i;
|
|
1481
1490
|
} catch (r) {
|
|
1482
1491
|
if (r instanceof z)
|
|
1483
1492
|
throw r;
|
|
@@ -1486,7 +1495,7 @@ async function Lt(e, s, t = !1) {
|
|
|
1486
1495
|
void 0,
|
|
1487
1496
|
r
|
|
1488
1497
|
);
|
|
1489
|
-
throw
|
|
1498
|
+
throw A("Network error listing conversations: %O", r), l;
|
|
1490
1499
|
}
|
|
1491
1500
|
}
|
|
1492
1501
|
async function Bt(e, s, t = 10, a = !1) {
|
|
@@ -1509,8 +1518,8 @@ async function Bt(e, s, t = 10, a = !1) {
|
|
|
1509
1518
|
);
|
|
1510
1519
|
try {
|
|
1511
1520
|
const i = await Promise.all(l);
|
|
1512
|
-
for (const
|
|
1513
|
-
r.push(...
|
|
1521
|
+
for (const g of i)
|
|
1522
|
+
r.push(...g.messages);
|
|
1514
1523
|
return {
|
|
1515
1524
|
messages: r,
|
|
1516
1525
|
pagination: {
|
|
@@ -1521,7 +1530,7 @@ async function Bt(e, s, t = 10, a = !1) {
|
|
|
1521
1530
|
chatId: n.chatId
|
|
1522
1531
|
};
|
|
1523
1532
|
} catch (i) {
|
|
1524
|
-
return
|
|
1533
|
+
return A("Failed to load all pages: %O", i), {
|
|
1525
1534
|
messages: r,
|
|
1526
1535
|
pagination: n.pagination,
|
|
1527
1536
|
chatId: n.chatId
|
|
@@ -1530,51 +1539,51 @@ async function Bt(e, s, t = 10, a = !1) {
|
|
|
1530
1539
|
}
|
|
1531
1540
|
const me = "a8c_agenttic_conversation_history";
|
|
1532
1541
|
function gt(e) {
|
|
1533
|
-
var y,
|
|
1542
|
+
var y, v;
|
|
1534
1543
|
const s = e.parts.filter(
|
|
1535
|
-
(
|
|
1536
|
-
), t = s.map((
|
|
1544
|
+
(f) => f.type === "text"
|
|
1545
|
+
), t = s.map((f) => f.text).join(`
|
|
1537
1546
|
`), a = s.some(
|
|
1538
|
-
(
|
|
1539
|
-
var
|
|
1540
|
-
return ((
|
|
1547
|
+
(f) => {
|
|
1548
|
+
var h;
|
|
1549
|
+
return ((h = f.metadata) == null ? void 0 : h.contentType) === "context";
|
|
1541
1550
|
}
|
|
1542
1551
|
) ? "context" : void 0, n = e.parts.filter(
|
|
1543
|
-
(
|
|
1544
|
-
).map((
|
|
1545
|
-
toolCallId:
|
|
1546
|
-
toolId:
|
|
1547
|
-
arguments:
|
|
1552
|
+
(f) => f.type === "data" && "toolCallId" in f.data && "arguments" in f.data
|
|
1553
|
+
).map((f) => ({
|
|
1554
|
+
toolCallId: f.data.toolCallId,
|
|
1555
|
+
toolId: f.data.toolId,
|
|
1556
|
+
arguments: f.data.arguments
|
|
1548
1557
|
})), o = e.parts.filter(
|
|
1549
|
-
(
|
|
1550
|
-
).map((
|
|
1551
|
-
toolCallId:
|
|
1552
|
-
result:
|
|
1553
|
-
error:
|
|
1554
|
-
})), r = e.parts.filter((
|
|
1555
|
-
name:
|
|
1556
|
-
mimeType:
|
|
1557
|
-
uri:
|
|
1558
|
+
(f) => f.type === "data" && "toolCallId" in f.data && "result" in f.data
|
|
1559
|
+
).map((f) => ({
|
|
1560
|
+
toolCallId: f.data.toolCallId,
|
|
1561
|
+
result: f.data.result,
|
|
1562
|
+
error: f.data.error
|
|
1563
|
+
})), r = e.parts.filter((f) => f.type === "file").map((f) => ({
|
|
1564
|
+
name: f.file.name,
|
|
1565
|
+
mimeType: f.file.mimeType,
|
|
1566
|
+
uri: f.file.uri
|
|
1558
1567
|
}));
|
|
1559
1568
|
let l;
|
|
1560
|
-
for (const
|
|
1561
|
-
if (
|
|
1569
|
+
for (const f of e.parts) {
|
|
1570
|
+
if (f.type !== "data" || !f.data || typeof f.data != "object" || "toolCallId" in f.data)
|
|
1562
1571
|
continue;
|
|
1563
|
-
const
|
|
1564
|
-
if (
|
|
1572
|
+
const h = f.data, I = h.flags;
|
|
1573
|
+
if (I && typeof I == "object" && I !== null && "forward_to_human_support" in I) {
|
|
1565
1574
|
l = {
|
|
1566
|
-
flags:
|
|
1567
|
-
..."sources" in
|
|
1575
|
+
flags: I,
|
|
1576
|
+
..."sources" in h && { sources: h.sources }
|
|
1568
1577
|
};
|
|
1569
1578
|
break;
|
|
1570
1579
|
}
|
|
1571
1580
|
}
|
|
1572
|
-
const
|
|
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;
|
|
1573
1582
|
return {
|
|
1574
|
-
role:
|
|
1583
|
+
role: g,
|
|
1575
1584
|
content: t || "(No text content)",
|
|
1576
1585
|
timestamp: u,
|
|
1577
|
-
...
|
|
1586
|
+
...p !== void 0 && { archived: p },
|
|
1578
1587
|
...a && { contentType: a },
|
|
1579
1588
|
...r.length > 0 && { files: r },
|
|
1580
1589
|
...n.length > 0 && { toolCalls: n },
|
|
@@ -1630,7 +1639,7 @@ function ft(e) {
|
|
|
1630
1639
|
role: e.role,
|
|
1631
1640
|
kind: "message",
|
|
1632
1641
|
parts: s,
|
|
1633
|
-
messageId:
|
|
1642
|
+
messageId: O(),
|
|
1634
1643
|
metadata: {
|
|
1635
1644
|
timestamp: e.timestamp,
|
|
1636
1645
|
// only store archived if it was already present.
|
|
@@ -1659,7 +1668,7 @@ async function pt(e, s, t) {
|
|
|
1659
1668
|
JSON.stringify(n)
|
|
1660
1669
|
);
|
|
1661
1670
|
} catch (n) {
|
|
1662
|
-
|
|
1671
|
+
A(
|
|
1663
1672
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1664
1673
|
a,
|
|
1665
1674
|
n
|
|
@@ -1688,7 +1697,7 @@ async function yt(e, s) {
|
|
|
1688
1697
|
1,
|
|
1689
1698
|
50
|
|
1690
1699
|
);
|
|
1691
|
-
return
|
|
1700
|
+
return A(
|
|
1692
1701
|
"Loaded conversation from server: %s (%d messages, page %d/%d)",
|
|
1693
1702
|
e,
|
|
1694
1703
|
r.messages.length,
|
|
@@ -1699,7 +1708,7 @@ async function yt(e, s) {
|
|
|
1699
1708
|
pagination: r.pagination
|
|
1700
1709
|
};
|
|
1701
1710
|
} catch (o) {
|
|
1702
|
-
throw
|
|
1711
|
+
throw A("Failed to load conversation from server: %O", o), o;
|
|
1703
1712
|
}
|
|
1704
1713
|
}
|
|
1705
1714
|
async function It(e, s) {
|
|
@@ -1719,7 +1728,7 @@ async function It(e, s) {
|
|
|
1719
1728
|
return W.set(t, o), { messages: [...o] };
|
|
1720
1729
|
}
|
|
1721
1730
|
} catch (a) {
|
|
1722
|
-
|
|
1731
|
+
A(
|
|
1723
1732
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1724
1733
|
t,
|
|
1725
1734
|
a
|
|
@@ -1733,7 +1742,7 @@ async function wt(e, s) {
|
|
|
1733
1742
|
try {
|
|
1734
1743
|
sessionStorage.removeItem(`${me}_${t}`);
|
|
1735
1744
|
} catch (a) {
|
|
1736
|
-
|
|
1745
|
+
A(
|
|
1737
1746
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1738
1747
|
t,
|
|
1739
1748
|
a
|
|
@@ -1803,7 +1812,7 @@ function Te(e, s = [], t = []) {
|
|
|
1803
1812
|
...n
|
|
1804
1813
|
],
|
|
1805
1814
|
kind: "message",
|
|
1806
|
-
messageId:
|
|
1815
|
+
messageId: O(),
|
|
1807
1816
|
metadata: {
|
|
1808
1817
|
timestamp: Date.now()
|
|
1809
1818
|
}
|
|
@@ -1894,18 +1903,18 @@ function St() {
|
|
|
1894
1903
|
odieBotId: a.odieBotId,
|
|
1895
1904
|
authProvider: a.authProvider
|
|
1896
1905
|
};
|
|
1897
|
-
let
|
|
1906
|
+
let g = [];
|
|
1898
1907
|
if (o)
|
|
1899
1908
|
try {
|
|
1900
|
-
|
|
1909
|
+
g = (await ht(
|
|
1901
1910
|
o,
|
|
1902
1911
|
r,
|
|
1903
1912
|
i
|
|
1904
1913
|
)).messages;
|
|
1905
|
-
} catch (
|
|
1914
|
+
} catch (p) {
|
|
1906
1915
|
L(
|
|
1907
1916
|
`Failed to load conversation history for agent ${t} with session ${o}:`,
|
|
1908
|
-
|
|
1917
|
+
p
|
|
1909
1918
|
);
|
|
1910
1919
|
}
|
|
1911
1920
|
const u = {
|
|
@@ -1914,7 +1923,7 @@ function St() {
|
|
|
1914
1923
|
conversationStorageKey: r,
|
|
1915
1924
|
sessionIdStorageKey: l,
|
|
1916
1925
|
storageConfig: i,
|
|
1917
|
-
conversationHistory:
|
|
1926
|
+
conversationHistory: g,
|
|
1918
1927
|
currentAbortController: null
|
|
1919
1928
|
};
|
|
1920
1929
|
return e.set(t, u), n;
|
|
@@ -1930,72 +1939,72 @@ function St() {
|
|
|
1930
1939
|
return e.delete(t);
|
|
1931
1940
|
},
|
|
1932
1941
|
async sendMessage(t, a, n = {}) {
|
|
1933
|
-
var
|
|
1942
|
+
var I;
|
|
1934
1943
|
const o = e.get(t);
|
|
1935
1944
|
if (!o)
|
|
1936
1945
|
throw new Error(`Agent with key "${t}" not found`);
|
|
1937
|
-
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(
|
|
1938
1947
|
a,
|
|
1939
1948
|
u,
|
|
1940
1949
|
n.imageUrls
|
|
1941
|
-
), y = await
|
|
1942
|
-
message:
|
|
1950
|
+
), y = await g.sendMessage({
|
|
1951
|
+
message: p,
|
|
1943
1952
|
withHistory: r,
|
|
1944
1953
|
sessionId: l || o.sessionId || void 0,
|
|
1945
1954
|
...i
|
|
1946
1955
|
});
|
|
1947
1956
|
if (y.sessionId) {
|
|
1948
|
-
const
|
|
1949
|
-
o.sessionId = y.sessionId,
|
|
1957
|
+
const S = o.sessionId;
|
|
1958
|
+
o.sessionId = y.sessionId, S && y.sessionId && S !== y.sessionId && o.sessionIdStorageKey && (L(
|
|
1950
1959
|
"Session ID changed from %s to %s, updating localStorage",
|
|
1951
|
-
|
|
1960
|
+
S,
|
|
1952
1961
|
y.sessionId
|
|
1953
1962
|
), ne(
|
|
1954
1963
|
o.sessionIdStorageKey,
|
|
1955
1964
|
y.sessionId
|
|
1956
1965
|
));
|
|
1957
1966
|
}
|
|
1958
|
-
let
|
|
1959
|
-
if ((
|
|
1960
|
-
const
|
|
1967
|
+
let v = null;
|
|
1968
|
+
if ((I = y.status) != null && I.message) {
|
|
1969
|
+
const S = y.status.message.parts.filter(
|
|
1961
1970
|
(c) => c.type === "data" && "toolCallId" in c.data && ("arguments" in c.data || "result" in c.data)
|
|
1962
|
-
),
|
|
1971
|
+
), d = y.status.message.parts.filter(
|
|
1963
1972
|
(c) => c.type === "text"
|
|
1964
1973
|
);
|
|
1965
|
-
|
|
1974
|
+
v = {
|
|
1966
1975
|
role: "agent",
|
|
1967
1976
|
kind: "message",
|
|
1968
|
-
parts: [...
|
|
1969
|
-
messageId:
|
|
1977
|
+
parts: [...S, ...d],
|
|
1978
|
+
messageId: O(),
|
|
1970
1979
|
metadata: {
|
|
1971
1980
|
timestamp: Date.now()
|
|
1972
1981
|
}
|
|
1973
1982
|
};
|
|
1974
1983
|
}
|
|
1975
|
-
const
|
|
1984
|
+
const f = [
|
|
1976
1985
|
...u,
|
|
1977
1986
|
// Store only the new content from the user message (without history parts)
|
|
1978
1987
|
ie(a),
|
|
1979
1988
|
// Add complete agent response with tool calls/results if present
|
|
1980
|
-
...
|
|
1989
|
+
...v ? [G(v)] : []
|
|
1981
1990
|
];
|
|
1982
|
-
let
|
|
1991
|
+
let h = f;
|
|
1983
1992
|
if (y.agentMessage) {
|
|
1984
|
-
const
|
|
1993
|
+
const S = G(
|
|
1985
1994
|
y.agentMessage
|
|
1986
1995
|
);
|
|
1987
|
-
|
|
1988
|
-
...
|
|
1989
|
-
|
|
1996
|
+
h = [
|
|
1997
|
+
...f,
|
|
1998
|
+
S
|
|
1990
1999
|
];
|
|
1991
2000
|
}
|
|
1992
|
-
return o.conversationHistory =
|
|
2001
|
+
return o.conversationHistory = h, r && await s(
|
|
1993
2002
|
t,
|
|
1994
|
-
|
|
2003
|
+
h
|
|
1995
2004
|
), y;
|
|
1996
2005
|
},
|
|
1997
2006
|
async *sendMessageStream(t, a, n = {}) {
|
|
1998
|
-
var
|
|
2007
|
+
var w, T, b, E, $, U;
|
|
1999
2008
|
const o = e.get(t);
|
|
2000
2009
|
if (!o)
|
|
2001
2010
|
throw new Error(`Agent with key "${t}" not found`);
|
|
@@ -2003,153 +2012,153 @@ function St() {
|
|
|
2003
2012
|
withHistory: r = !0,
|
|
2004
2013
|
abortSignal: l,
|
|
2005
2014
|
metadata: i,
|
|
2006
|
-
sessionId:
|
|
2015
|
+
sessionId: g,
|
|
2007
2016
|
message: u,
|
|
2008
|
-
...
|
|
2009
|
-
} = n, { client: y } = o,
|
|
2010
|
-
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(
|
|
2011
2020
|
"abort",
|
|
2012
|
-
() =>
|
|
2021
|
+
() => f.abort()
|
|
2013
2022
|
);
|
|
2014
|
-
let
|
|
2023
|
+
let h = [
|
|
2015
2024
|
...o.conversationHistory
|
|
2016
|
-
],
|
|
2017
|
-
const
|
|
2018
|
-
|
|
2025
|
+
], I = [];
|
|
2026
|
+
const S = await Mt(
|
|
2027
|
+
h
|
|
2019
2028
|
);
|
|
2020
|
-
o.conversationHistory =
|
|
2029
|
+
o.conversationHistory = S, h = S, r && await s(
|
|
2021
2030
|
t,
|
|
2022
|
-
|
|
2031
|
+
S
|
|
2023
2032
|
);
|
|
2024
|
-
let
|
|
2033
|
+
let d;
|
|
2025
2034
|
if (u) {
|
|
2026
|
-
const
|
|
2027
|
-
|
|
2035
|
+
const m = $e(
|
|
2036
|
+
S
|
|
2028
2037
|
);
|
|
2029
|
-
|
|
2038
|
+
d = {
|
|
2030
2039
|
...u,
|
|
2031
|
-
parts: [...
|
|
2040
|
+
parts: [...m, ...u.parts]
|
|
2032
2041
|
};
|
|
2033
2042
|
} else
|
|
2034
|
-
|
|
2043
|
+
d = Te(
|
|
2035
2044
|
a,
|
|
2036
|
-
|
|
2045
|
+
S,
|
|
2037
2046
|
n.imageUrls
|
|
2038
2047
|
);
|
|
2039
2048
|
if (n.metadata && !u) {
|
|
2040
|
-
const { contentType:
|
|
2041
|
-
if (
|
|
2042
|
-
const
|
|
2043
|
-
|
|
2044
|
-
...
|
|
2045
|
-
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
|
|
2046
2055
|
});
|
|
2047
2056
|
}
|
|
2048
|
-
Object.keys(
|
|
2049
|
-
...
|
|
2050
|
-
...
|
|
2057
|
+
Object.keys(x).length > 0 && (d.metadata = {
|
|
2058
|
+
...d.metadata,
|
|
2059
|
+
...x
|
|
2051
2060
|
});
|
|
2052
2061
|
}
|
|
2053
2062
|
const c = u || ie(a, n.metadata);
|
|
2054
2063
|
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
2055
|
-
const
|
|
2056
|
-
(
|
|
2057
|
-
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";
|
|
2058
2067
|
return {
|
|
2059
2068
|
type: "file",
|
|
2060
2069
|
file: {
|
|
2061
2070
|
name: (k == null ? void 0 : k.fileName) || "image",
|
|
2062
|
-
mimeType:
|
|
2063
|
-
uri:
|
|
2071
|
+
mimeType: N,
|
|
2072
|
+
uri: M
|
|
2064
2073
|
},
|
|
2065
2074
|
metadata: k
|
|
2066
2075
|
};
|
|
2067
2076
|
}
|
|
2068
2077
|
);
|
|
2069
|
-
c.parts.push(...
|
|
2078
|
+
c.parts.push(...m);
|
|
2070
2079
|
}
|
|
2071
|
-
|
|
2072
|
-
...
|
|
2080
|
+
h = [
|
|
2081
|
+
...h,
|
|
2073
2082
|
c
|
|
2074
|
-
], o.conversationHistory =
|
|
2083
|
+
], o.conversationHistory = h, r && await s(
|
|
2075
2084
|
t,
|
|
2076
|
-
|
|
2085
|
+
h
|
|
2077
2086
|
);
|
|
2078
|
-
for await (const
|
|
2079
|
-
message:
|
|
2087
|
+
for await (const m of y.sendMessageStream({
|
|
2088
|
+
message: d,
|
|
2080
2089
|
withHistory: r,
|
|
2081
|
-
sessionId:
|
|
2082
|
-
abortSignal:
|
|
2083
|
-
...
|
|
2084
|
-
...
|
|
2085
|
-
metadata:
|
|
2090
|
+
sessionId: g || o.sessionId || void 0,
|
|
2091
|
+
abortSignal: f.signal,
|
|
2092
|
+
...p,
|
|
2093
|
+
...v && Object.keys(v).length > 0 && {
|
|
2094
|
+
metadata: v
|
|
2086
2095
|
}
|
|
2087
2096
|
})) {
|
|
2088
|
-
if (
|
|
2089
|
-
const
|
|
2090
|
-
o.sessionId =
|
|
2097
|
+
if (m.sessionId) {
|
|
2098
|
+
const x = o.sessionId;
|
|
2099
|
+
o.sessionId = m.sessionId, m.sessionId && x !== m.sessionId && o.sessionIdStorageKey && (L(
|
|
2091
2100
|
"Session ID %s, updating localStorage",
|
|
2092
|
-
|
|
2101
|
+
x ? `changed from ${x} to ${m.sessionId}` : `received: ${m.sessionId}`
|
|
2093
2102
|
), ne(
|
|
2094
2103
|
o.sessionIdStorageKey,
|
|
2095
|
-
|
|
2104
|
+
m.sessionId
|
|
2096
2105
|
));
|
|
2097
2106
|
}
|
|
2098
|
-
if (((
|
|
2099
|
-
|
|
2100
|
-
|
|
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
|
|
2101
2110
|
).map(
|
|
2102
2111
|
(k) => k.data.toolCallId
|
|
2103
2112
|
);
|
|
2104
|
-
const
|
|
2105
|
-
|
|
2113
|
+
const M = G(
|
|
2114
|
+
m.status.message
|
|
2106
2115
|
);
|
|
2107
|
-
|
|
2108
|
-
...
|
|
2109
|
-
|
|
2110
|
-
], o.conversationHistory =
|
|
2116
|
+
h = [
|
|
2117
|
+
...h,
|
|
2118
|
+
M
|
|
2119
|
+
], o.conversationHistory = h, r && await s(
|
|
2111
2120
|
t,
|
|
2112
|
-
|
|
2121
|
+
h
|
|
2113
2122
|
);
|
|
2114
2123
|
}
|
|
2115
|
-
if (((b =
|
|
2116
|
-
const
|
|
2117
|
-
|
|
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
|
|
2118
2127
|
).filter(
|
|
2119
|
-
(k) =>
|
|
2128
|
+
(k) => I.includes(
|
|
2120
2129
|
k.data.toolCallId
|
|
2121
2130
|
)
|
|
2122
2131
|
);
|
|
2123
|
-
if (
|
|
2132
|
+
if (M.length > 0) {
|
|
2124
2133
|
const k = {
|
|
2125
2134
|
role: "agent",
|
|
2126
2135
|
kind: "message",
|
|
2127
|
-
parts:
|
|
2128
|
-
messageId:
|
|
2136
|
+
parts: M,
|
|
2137
|
+
messageId: O()
|
|
2129
2138
|
};
|
|
2130
|
-
|
|
2131
|
-
...
|
|
2139
|
+
h = [
|
|
2140
|
+
...h,
|
|
2132
2141
|
G(k)
|
|
2133
|
-
], o.conversationHistory =
|
|
2142
|
+
], o.conversationHistory = h, r && await s(
|
|
2134
2143
|
t,
|
|
2135
|
-
|
|
2144
|
+
h
|
|
2136
2145
|
);
|
|
2137
2146
|
}
|
|
2138
2147
|
}
|
|
2139
|
-
if (
|
|
2140
|
-
|
|
2141
|
-
let
|
|
2142
|
-
(
|
|
2143
|
-
|
|
2144
|
-
),
|
|
2145
|
-
...
|
|
2146
|
-
|
|
2147
|
-
], o.conversationHistory =
|
|
2148
|
+
if (m.final && (($ = m.status) == null ? void 0 : $.state) !== "input-required") {
|
|
2149
|
+
I = [];
|
|
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(
|
|
2148
2157
|
t,
|
|
2149
|
-
|
|
2158
|
+
h
|
|
2150
2159
|
));
|
|
2151
2160
|
}
|
|
2152
|
-
yield
|
|
2161
|
+
yield m;
|
|
2153
2162
|
}
|
|
2154
2163
|
o.currentAbortController = null;
|
|
2155
2164
|
},
|
|
@@ -2169,16 +2178,16 @@ function St() {
|
|
|
2169
2178
|
const l = e.get(t);
|
|
2170
2179
|
if (!l)
|
|
2171
2180
|
throw new Error(`Agent with key "${t}" not found`);
|
|
2172
|
-
const i = (
|
|
2181
|
+
const i = (g) => {
|
|
2173
2182
|
var u;
|
|
2174
|
-
return
|
|
2183
|
+
return g.type === "data" && ((u = g.data) == null ? void 0 : u.toolCallId) === a && "result" in g.data;
|
|
2175
2184
|
};
|
|
2176
|
-
l.conversationHistory = l.conversationHistory.map((
|
|
2177
|
-
...
|
|
2178
|
-
parts:
|
|
2185
|
+
l.conversationHistory = l.conversationHistory.map((g) => ({
|
|
2186
|
+
...g,
|
|
2187
|
+
parts: g.parts.filter(
|
|
2179
2188
|
(u) => !i(u)
|
|
2180
2189
|
)
|
|
2181
|
-
})).filter((
|
|
2190
|
+
})).filter((g) => g.parts.length > 0), yield* this.sendMessageStream(t, "", {
|
|
2182
2191
|
...r,
|
|
2183
2192
|
message: {
|
|
2184
2193
|
role: "user",
|
|
@@ -2186,7 +2195,7 @@ function St() {
|
|
|
2186
2195
|
parts: [
|
|
2187
2196
|
D(a, n, o)
|
|
2188
2197
|
],
|
|
2189
|
-
messageId:
|
|
2198
|
+
messageId: O()
|
|
2190
2199
|
}
|
|
2191
2200
|
});
|
|
2192
2201
|
},
|
|
@@ -2300,17 +2309,17 @@ const re = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ue = (e, s =
|
|
|
2300
2309
|
var r, l;
|
|
2301
2310
|
if (e.parts.some((i) => {
|
|
2302
2311
|
if (i.type === "data") {
|
|
2303
|
-
const
|
|
2304
|
-
return
|
|
2312
|
+
const g = i.data;
|
|
2313
|
+
return g.toolCallId || g.toolId || g.result;
|
|
2305
2314
|
}
|
|
2306
2315
|
return !1;
|
|
2307
2316
|
}))
|
|
2308
2317
|
return null;
|
|
2309
2318
|
const a = e.parts.map((i) => {
|
|
2310
|
-
var
|
|
2319
|
+
var g;
|
|
2311
2320
|
if (i.type === "text")
|
|
2312
2321
|
return {
|
|
2313
|
-
type: ((
|
|
2322
|
+
type: ((g = i.metadata) == null ? void 0 : g.contentType) || "text",
|
|
2314
2323
|
text: i.text
|
|
2315
2324
|
};
|
|
2316
2325
|
if (i.type === "file") {
|
|
@@ -2387,12 +2396,12 @@ function Wt(e) {
|
|
|
2387
2396
|
unregisterMessageActions: r,
|
|
2388
2397
|
clearAllMessageActions: l,
|
|
2389
2398
|
registrations: i
|
|
2390
|
-
} = At(),
|
|
2399
|
+
} = At(), g = pe(!1), u = pe(i);
|
|
2391
2400
|
se(() => {
|
|
2392
2401
|
u.current = i;
|
|
2393
2402
|
}, [i]);
|
|
2394
|
-
const
|
|
2395
|
-
(
|
|
2403
|
+
const p = H(
|
|
2404
|
+
(d) => d.map(
|
|
2396
2405
|
(c) => oe(c, u.current)
|
|
2397
2406
|
).filter((c) => c !== null),
|
|
2398
2407
|
[]
|
|
@@ -2402,18 +2411,18 @@ function Wt(e) {
|
|
|
2402
2411
|
if (!t)
|
|
2403
2412
|
return;
|
|
2404
2413
|
(async () => {
|
|
2405
|
-
const c = X(),
|
|
2406
|
-
if (c.hasAgent(
|
|
2407
|
-
s.sessionId ? (c.updateSessionId(
|
|
2414
|
+
const c = X(), w = s.agentId;
|
|
2415
|
+
if (c.hasAgent(w))
|
|
2416
|
+
s.sessionId ? (c.updateSessionId(w, s.sessionId), c.getConversationHistory(w).length === 0 && n((E) => ({
|
|
2408
2417
|
...E,
|
|
2409
2418
|
clientMessages: [],
|
|
2410
2419
|
uiMessages: []
|
|
2411
|
-
}))) : (c.updateSessionId(
|
|
2420
|
+
}))) : (c.updateSessionId(w, ""), await c.replaceMessages(w, []), n((b) => ({
|
|
2412
2421
|
...b,
|
|
2413
2422
|
clientMessages: [],
|
|
2414
2423
|
uiMessages: []
|
|
2415
2424
|
})));
|
|
2416
|
-
else if (await c.createAgent(
|
|
2425
|
+
else if (await c.createAgent(w, {
|
|
2417
2426
|
agentId: s.agentId,
|
|
2418
2427
|
agentUrl: s.agentUrl,
|
|
2419
2428
|
sessionId: s.sessionId,
|
|
@@ -2425,13 +2434,13 @@ function Wt(e) {
|
|
|
2425
2434
|
enableStreaming: e.enableStreaming,
|
|
2426
2435
|
odieBotId: e.odieBotId
|
|
2427
2436
|
}), s.sessionId) {
|
|
2428
|
-
const b = c.getConversationHistory(
|
|
2437
|
+
const b = c.getConversationHistory(w);
|
|
2429
2438
|
n((E) => {
|
|
2430
|
-
const
|
|
2439
|
+
const $ = p(b);
|
|
2431
2440
|
return {
|
|
2432
2441
|
...E,
|
|
2433
2442
|
clientMessages: b,
|
|
2434
|
-
uiMessages:
|
|
2443
|
+
uiMessages: $
|
|
2435
2444
|
};
|
|
2436
2445
|
});
|
|
2437
2446
|
} else
|
|
@@ -2454,34 +2463,34 @@ function Wt(e) {
|
|
|
2454
2463
|
t
|
|
2455
2464
|
]);
|
|
2456
2465
|
const y = H(
|
|
2457
|
-
async (
|
|
2458
|
-
var U
|
|
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
|
-
|
|
2464
|
-
const
|
|
2465
|
-
if (
|
|
2472
|
+
g.current = !0;
|
|
2473
|
+
const w = (c == null ? void 0 : c.type) === "tool_result";
|
|
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
2478
|
const T = X(), b = s.agentId, E = Date.now();
|
|
2470
|
-
if (
|
|
2471
|
-
n((
|
|
2472
|
-
...
|
|
2479
|
+
if (w)
|
|
2480
|
+
n((m) => ({
|
|
2481
|
+
...m,
|
|
2473
2482
|
isProcessing: !0,
|
|
2474
2483
|
error: null
|
|
2475
2484
|
}));
|
|
2476
2485
|
else {
|
|
2477
|
-
const
|
|
2486
|
+
const m = (c == null ? void 0 : c.type) || "text", x = {
|
|
2478
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 k = typeof
|
|
2492
|
+
...(($ = c == null ? void 0 : c.imageUrls) == null ? void 0 : $.map((M) => {
|
|
2493
|
+
const k = typeof M == "string" ? M : M.url;
|
|
2485
2494
|
return Ue(k);
|
|
2486
2495
|
})) ?? []
|
|
2487
2496
|
],
|
|
@@ -2489,42 +2498,42 @@ function Wt(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 || k) && (
|
|
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
2513
|
...k && { contentType: c.type }
|
|
2505
|
-
}), c != null && c.sessionId && (
|
|
2506
|
-
const
|
|
2514
|
+
}), c != null && c.sessionId && (M.sessionId = c.sessionId), c != null && c.imageUrls && (M.imageUrls = c.imageUrls);
|
|
2515
|
+
const N = w ? T.sendToolResult(
|
|
2507
2516
|
b,
|
|
2508
2517
|
c.toolCallId,
|
|
2509
2518
|
c.toolId,
|
|
2510
|
-
{ success: !0, message:
|
|
2511
|
-
|
|
2519
|
+
{ success: !0, message: d },
|
|
2520
|
+
M
|
|
2512
2521
|
) : T.sendMessageStream(
|
|
2513
2522
|
b,
|
|
2514
|
-
|
|
2515
|
-
|
|
2523
|
+
d,
|
|
2524
|
+
M
|
|
2516
2525
|
);
|
|
2517
|
-
for await (const R of
|
|
2526
|
+
for await (const R of N) {
|
|
2518
2527
|
if ((R.progressMessage || R.progressPhase) && n((C) => ({
|
|
2519
2528
|
...C,
|
|
2520
2529
|
progressMessage: R.progressMessage || null,
|
|
2521
2530
|
progressPhase: R.progressPhase || null
|
|
2522
2531
|
})), !R.final && R.text)
|
|
2523
|
-
if (
|
|
2532
|
+
if (m)
|
|
2524
2533
|
n((C) => ({
|
|
2525
2534
|
...C,
|
|
2526
2535
|
uiMessages: C.uiMessages.map(
|
|
2527
|
-
(P) => P.id ===
|
|
2536
|
+
(P) => P.id === m ? {
|
|
2528
2537
|
...P,
|
|
2529
2538
|
content: [
|
|
2530
2539
|
{
|
|
@@ -2536,9 +2545,9 @@ function Wt(e) {
|
|
|
2536
2545
|
)
|
|
2537
2546
|
}));
|
|
2538
2547
|
else {
|
|
2539
|
-
|
|
2548
|
+
m = `agent-streaming-${Date.now()}`;
|
|
2540
2549
|
const C = {
|
|
2541
|
-
id:
|
|
2550
|
+
id: m,
|
|
2542
2551
|
role: "agent",
|
|
2543
2552
|
content: [
|
|
2544
2553
|
{ type: "text", text: R.text }
|
|
@@ -2547,7 +2556,7 @@ 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
2562
|
n((P) => ({
|
|
@@ -2558,9 +2567,9 @@ function Wt(e) {
|
|
|
2558
2567
|
]
|
|
2559
2568
|
}));
|
|
2560
2569
|
}
|
|
2561
|
-
if (R.final && ((
|
|
2562
|
-
|
|
2563
|
-
const C =
|
|
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
|
);
|
|
@@ -2590,15 +2599,15 @@ function Wt(e) {
|
|
|
2590
2599
|
progressMessage: null,
|
|
2591
2600
|
progressPhase: null
|
|
2592
2601
|
};
|
|
2593
|
-
}),
|
|
2602
|
+
}), m = null;
|
|
2594
2603
|
}
|
|
2595
2604
|
}
|
|
2596
|
-
if (!
|
|
2605
|
+
if (!x) {
|
|
2597
2606
|
const R = T.getConversationHistory(b);
|
|
2598
2607
|
n((C) => {
|
|
2599
2608
|
let P = C.uiMessages;
|
|
2600
|
-
|
|
2601
|
-
(_) => _.id !==
|
|
2609
|
+
m && (P = C.uiMessages.filter(
|
|
2610
|
+
(_) => _.id !== m
|
|
2602
2611
|
));
|
|
2603
2612
|
const j = R.map(
|
|
2604
2613
|
(_) => oe(
|
|
@@ -2625,10 +2634,10 @@ function Wt(e) {
|
|
|
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,46 +2646,46 @@ 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: re([...c.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
2678
|
se(() => {
|
|
2670
|
-
n((
|
|
2671
|
-
if (
|
|
2672
|
-
return
|
|
2673
|
-
const c =
|
|
2674
|
-
|
|
2675
|
-
), T =
|
|
2676
|
-
(b) => !
|
|
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
|
-
...
|
|
2688
|
+
...d,
|
|
2680
2689
|
uiMessages: re([
|
|
2681
2690
|
...c,
|
|
2682
2691
|
...T
|
|
@@ -2684,21 +2693,21 @@ function Wt(e) {
|
|
|
2684
2693
|
};
|
|
2685
2694
|
});
|
|
2686
2695
|
}, [i]);
|
|
2687
|
-
const
|
|
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 = X(),
|
|
2697
|
-
await c.replaceMessages(
|
|
2698
|
-
const T =
|
|
2705
|
+
const c = X(), w = s.agentId;
|
|
2706
|
+
await c.replaceMessages(w, d);
|
|
2707
|
+
const T = p(d);
|
|
2699
2708
|
n((b) => ({
|
|
2700
2709
|
...b,
|
|
2701
|
-
clientMessages:
|
|
2710
|
+
clientMessages: d,
|
|
2702
2711
|
uiMessages: T
|
|
2703
2712
|
}));
|
|
2704
2713
|
},
|
|
@@ -2714,18 +2723,18 @@ function Wt(e) {
|
|
|
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
|
-
abortCurrentRequest:
|
|
2735
|
+
abortCurrentRequest: I,
|
|
2727
2736
|
// Conversation loading
|
|
2728
|
-
loadMessages:
|
|
2737
|
+
loadMessages: S
|
|
2729
2738
|
};
|
|
2730
2739
|
}
|
|
2731
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 || {});
|
|
@@ -2735,18 +2744,18 @@ function _t() {
|
|
|
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,
|
|
2747
|
+
var i, g;
|
|
2739
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: ""
|
|
@@ -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(
|
|
@@ -2778,7 +2787,7 @@ async function Et(e, s = !0) {
|
|
|
2778
2787
|
try {
|
|
2779
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
|
};
|