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