@automattic/agenttic-client 0.1.61 → 0.1.63
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/types/index.d.ts +7 -1
- package/dist/client/types/index.d.ts.map +1 -1
- package/dist/client/utils/internal/streaming.d.ts +33 -1
- package/dist/client/utils/internal/streaming.d.ts.map +1 -1
- package/dist/index.js +627 -610
- package/dist/react/__tests__/useAgentChat.credentials.test.d.ts +2 -0
- package/dist/react/__tests__/useAgentChat.credentials.test.d.ts.map +1 -0
- package/dist/react/useAgentChat.d.ts +1 -0
- package/dist/react/useAgentChat.d.ts.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
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
3
|
var te = (e, s, t) => Fe(e, typeof s != "symbol" ? s + "" : s, t);
|
|
4
|
-
import
|
|
4
|
+
import De, { useMemo as Me, useCallback as H, useState as ve, useRef as pe, useEffect as se } from "react";
|
|
5
5
|
import { l as A, f as Ae, a as L } from "./logger-aKHbTlwk.js";
|
|
6
6
|
import he from "@wordpress/api-fetch";
|
|
7
|
-
function
|
|
8
|
-
return
|
|
7
|
+
function Dt(e) {
|
|
8
|
+
return Me(() => e ? {
|
|
9
9
|
getClientContext: () => {
|
|
10
10
|
try {
|
|
11
11
|
return e() || {};
|
|
@@ -21,32 +21,32 @@ function ce({
|
|
|
21
21
|
getAbilities: t
|
|
22
22
|
}) {
|
|
23
23
|
const a = H(async () => {
|
|
24
|
-
const
|
|
24
|
+
const o = [];
|
|
25
25
|
if (e)
|
|
26
26
|
try {
|
|
27
|
-
const
|
|
28
|
-
|
|
29
|
-
} catch (
|
|
30
|
-
A("Error getting available tools: %O",
|
|
27
|
+
const c = await e();
|
|
28
|
+
o.push(...c);
|
|
29
|
+
} catch (c) {
|
|
30
|
+
A("Error getting available tools: %O", c);
|
|
31
31
|
}
|
|
32
|
-
return
|
|
32
|
+
return o;
|
|
33
33
|
}, [e]), n = H(
|
|
34
|
-
async (
|
|
34
|
+
async (o, c) => {
|
|
35
35
|
if (!s)
|
|
36
36
|
throw new Error("No executeTool callback provided");
|
|
37
37
|
try {
|
|
38
|
-
return await s(
|
|
38
|
+
return await s(o, c);
|
|
39
39
|
} catch (i) {
|
|
40
|
-
throw A("Error executing tool %s: %O",
|
|
40
|
+
throw A("Error executing tool %s: %O", o, i), i;
|
|
41
41
|
}
|
|
42
42
|
},
|
|
43
43
|
[s]
|
|
44
44
|
);
|
|
45
|
-
return
|
|
45
|
+
return Me(() => {
|
|
46
46
|
if (!e && !t)
|
|
47
47
|
return;
|
|
48
|
-
const
|
|
49
|
-
return e && (
|
|
48
|
+
const o = {};
|
|
49
|
+
return e && (o.getAvailableTools = a), s && (o.executeTool = n), t && (o.getAbilities = t), o;
|
|
50
50
|
}, [
|
|
51
51
|
a,
|
|
52
52
|
n,
|
|
@@ -62,14 +62,14 @@ function jt(e, s) {
|
|
|
62
62
|
getAbilities: void 0
|
|
63
63
|
});
|
|
64
64
|
}
|
|
65
|
-
function
|
|
65
|
+
function Jt(e) {
|
|
66
66
|
return ce({
|
|
67
67
|
getClientTools: void 0,
|
|
68
68
|
executeTool: void 0,
|
|
69
69
|
getAbilities: e
|
|
70
70
|
});
|
|
71
71
|
}
|
|
72
|
-
function
|
|
72
|
+
function Kt(e) {
|
|
73
73
|
const { getClientTools: s, executeTool: t, getAbilities: a } = e;
|
|
74
74
|
if (!s && !a)
|
|
75
75
|
throw new Error(
|
|
@@ -95,13 +95,13 @@ function ue() {
|
|
|
95
95
|
function O() {
|
|
96
96
|
return ue();
|
|
97
97
|
}
|
|
98
|
-
function
|
|
98
|
+
function je() {
|
|
99
99
|
return `req-${ue()}`;
|
|
100
100
|
}
|
|
101
101
|
function Je() {
|
|
102
102
|
return `task-${ue()}`;
|
|
103
103
|
}
|
|
104
|
-
function
|
|
104
|
+
function Ce(e, s) {
|
|
105
105
|
return {
|
|
106
106
|
type: "text",
|
|
107
107
|
text: e,
|
|
@@ -111,7 +111,7 @@ function xe(e, s) {
|
|
|
111
111
|
function Ke(e, s = "message/send", t = !1) {
|
|
112
112
|
const a = {
|
|
113
113
|
jsonrpc: "2.0",
|
|
114
|
-
id:
|
|
114
|
+
id: je(),
|
|
115
115
|
method: s,
|
|
116
116
|
params: {
|
|
117
117
|
id: e.id || Je(),
|
|
@@ -165,7 +165,7 @@ function B(e) {
|
|
|
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 j(e, s, t, a) {
|
|
169
169
|
return {
|
|
170
170
|
type: "data",
|
|
171
171
|
data: {
|
|
@@ -189,7 +189,7 @@ function ie(e, s) {
|
|
|
189
189
|
const { contentType: t, ...a } = s || {};
|
|
190
190
|
return {
|
|
191
191
|
role: "user",
|
|
192
|
-
parts: [
|
|
192
|
+
parts: [Ce(e, t ? { contentType: t } : void 0)],
|
|
193
193
|
kind: "message",
|
|
194
194
|
messageId: O(),
|
|
195
195
|
metadata: {
|
|
@@ -201,7 +201,7 @@ function ie(e, s) {
|
|
|
201
201
|
function Q(e) {
|
|
202
202
|
return {
|
|
203
203
|
role: "agent",
|
|
204
|
-
parts: [
|
|
204
|
+
parts: [Ce(e)],
|
|
205
205
|
kind: "message",
|
|
206
206
|
messageId: O(),
|
|
207
207
|
metadata: {
|
|
@@ -232,7 +232,7 @@ function Y(e, s = []) {
|
|
|
232
232
|
}
|
|
233
233
|
};
|
|
234
234
|
}
|
|
235
|
-
function
|
|
235
|
+
function Lt() {
|
|
236
236
|
return new AbortController();
|
|
237
237
|
}
|
|
238
238
|
async function Ve(e, s) {
|
|
@@ -287,18 +287,18 @@ async function Ge(e, s, t) {
|
|
|
287
287
|
a,
|
|
288
288
|
t
|
|
289
289
|
);
|
|
290
|
-
const { metadata: n, ...
|
|
291
|
-
return
|
|
290
|
+
const { metadata: n, ...r } = a;
|
|
291
|
+
return r;
|
|
292
292
|
}
|
|
293
293
|
function Qe(e, s = "") {
|
|
294
294
|
const t = [], a = s + e;
|
|
295
|
-
let n = "",
|
|
296
|
-
for (;
|
|
295
|
+
let n = "", r = 0, o = 0;
|
|
296
|
+
for (; o < a.length; ) {
|
|
297
297
|
const i = a.indexOf(
|
|
298
298
|
`
|
|
299
299
|
`,
|
|
300
|
-
|
|
301
|
-
), g = i === -1 ? a.substring(
|
|
300
|
+
o
|
|
301
|
+
), g = i === -1 ? a.substring(o) : a.substring(o, i);
|
|
302
302
|
if (g.startsWith("data:"))
|
|
303
303
|
n !== "" && (n += `
|
|
304
304
|
`), n += g.substring(
|
|
@@ -306,96 +306,97 @@ function Qe(e, s = "") {
|
|
|
306
306
|
);
|
|
307
307
|
else if (g.trim() === "" && n) {
|
|
308
308
|
try {
|
|
309
|
-
t.push(JSON.parse(n)),
|
|
309
|
+
t.push(JSON.parse(n)), r = 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
|
}
|
|
315
|
-
i === -1 ?
|
|
315
|
+
i === -1 ? o = a.length : o = i + 1;
|
|
316
316
|
}
|
|
317
|
-
const
|
|
318
|
-
return { events: t, nextBuffer:
|
|
317
|
+
const c = a.substring(r);
|
|
318
|
+
return { events: t, nextBuffer: c };
|
|
319
319
|
}
|
|
320
320
|
async function* Xe(e, s = {}) {
|
|
321
321
|
var g, u, p;
|
|
322
322
|
const { supportDeltas: t = !1 } = s, a = e.getReader(), n = new TextDecoder();
|
|
323
|
-
let
|
|
324
|
-
const
|
|
325
|
-
let
|
|
323
|
+
let r = "";
|
|
324
|
+
const o = new Ze();
|
|
325
|
+
let c = null, i = null;
|
|
326
326
|
try {
|
|
327
327
|
for (; ; ) {
|
|
328
328
|
const { done: y, value: v } = await a.read();
|
|
329
329
|
if (y)
|
|
330
330
|
break;
|
|
331
|
-
const f = n.decode(v, { stream: !0 }), { events: h, nextBuffer: I } = Qe(f,
|
|
331
|
+
const f = n.decode(v, { stream: !0 }), { events: h, nextBuffer: I } = Qe(f, r);
|
|
332
332
|
if (h && Array.isArray(h))
|
|
333
|
-
for (let
|
|
334
|
-
const d = h[
|
|
335
|
-
if (
|
|
336
|
-
requestAnimationFrame(() =>
|
|
333
|
+
for (let M = 0; M < h.length; M++) {
|
|
334
|
+
const d = h[M];
|
|
335
|
+
if (M > 0 && d.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((l) => {
|
|
336
|
+
requestAnimationFrame(() => l(void 0));
|
|
337
337
|
}), d.error)
|
|
338
338
|
throw new Error(
|
|
339
339
|
`Streaming error: ${d.error.message}`
|
|
340
340
|
);
|
|
341
341
|
if (t && d.method === "message/delta" && ((g = d.params) != null && g.delta)) {
|
|
342
|
-
const
|
|
342
|
+
const l = d.params.delta;
|
|
343
343
|
try {
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
};
|
|
357
|
-
}
|
|
344
|
+
let w = !1;
|
|
345
|
+
Ye(l) ? (o.processToolCallDelta(l), w = !0) : l.deltaType === "content" && (o.processContentDelta(
|
|
346
|
+
l.content
|
|
347
|
+
), w = !0), w && (!c && d.params.id && (c = d.params.id), c && (yield {
|
|
348
|
+
id: c,
|
|
349
|
+
status: {
|
|
350
|
+
state: "working",
|
|
351
|
+
message: o.getCurrentMessage()
|
|
352
|
+
},
|
|
353
|
+
final: !1,
|
|
354
|
+
text: o.getTextContent()
|
|
355
|
+
}));
|
|
358
356
|
} catch (w) {
|
|
359
357
|
A("Failed to process delta: %o", w);
|
|
360
358
|
}
|
|
361
359
|
} else if (d.result && d.result.status) {
|
|
362
|
-
|
|
363
|
-
const
|
|
360
|
+
c = d.result.id, i = d.result.status, (o.getTextContent() || o.getCurrentMessage().parts.length > 0) && o.reset();
|
|
361
|
+
const l = ((u = d.result.status) == null ? void 0 : u.message) || {
|
|
364
362
|
role: "agent",
|
|
365
363
|
parts: []
|
|
366
|
-
}, w = ye(
|
|
364
|
+
}, w = ye(l);
|
|
367
365
|
yield {
|
|
368
366
|
id: d.result.id,
|
|
369
367
|
sessionId: d.result.sessionId,
|
|
370
368
|
status: d.result.status,
|
|
371
369
|
final: d.result.status.state === "completed" || d.result.status.state === "failed" || d.result.status.state === "canceled",
|
|
372
|
-
text: F(
|
|
370
|
+
text: F(l),
|
|
373
371
|
progressMessage: w == null ? void 0 : w.summary,
|
|
374
372
|
progressPhase: w == null ? void 0 : w.phase
|
|
375
373
|
};
|
|
376
|
-
} else if (d.id && d.result && (
|
|
377
|
-
const
|
|
374
|
+
} else if (d.id && d.result && (c = d.result.id, d.result.status)) {
|
|
375
|
+
const l = ((p = d.result.status) == null ? void 0 : p.message) || {
|
|
378
376
|
role: "agent",
|
|
379
377
|
parts: []
|
|
380
|
-
}, w = ye(
|
|
378
|
+
}, w = ye(l);
|
|
381
379
|
yield {
|
|
382
380
|
id: d.result.id,
|
|
383
381
|
sessionId: d.result.sessionId,
|
|
384
382
|
status: d.result.status,
|
|
385
383
|
final: d.result.status.state === "completed" || d.result.status.state === "failed" || d.result.status.state === "canceled",
|
|
386
|
-
text: F(
|
|
384
|
+
text: F(l),
|
|
387
385
|
progressMessage: w == null ? void 0 : w.summary,
|
|
388
386
|
progressPhase: w == null ? void 0 : w.phase
|
|
389
387
|
};
|
|
390
388
|
}
|
|
391
389
|
}
|
|
392
|
-
|
|
390
|
+
r = I;
|
|
393
391
|
}
|
|
394
392
|
} finally {
|
|
395
393
|
a.releaseLock();
|
|
396
394
|
}
|
|
397
395
|
}
|
|
398
|
-
|
|
396
|
+
function Ye(e) {
|
|
397
|
+
return e.deltaType === "tool_argument" || e.deltaType === "tool_name";
|
|
398
|
+
}
|
|
399
|
+
class Ze {
|
|
399
400
|
constructor() {
|
|
400
401
|
te(this, "textContent", "");
|
|
401
402
|
te(this, "toolCalls", /* @__PURE__ */ new Map());
|
|
@@ -407,6 +408,20 @@ class Ye {
|
|
|
407
408
|
processContentDelta(s) {
|
|
408
409
|
this.textContent += s;
|
|
409
410
|
}
|
|
411
|
+
/**
|
|
412
|
+
* Process the server's live tool-call delta format.
|
|
413
|
+
* @param delta - The tool delta emitted by the streaming endpoint
|
|
414
|
+
*/
|
|
415
|
+
processToolCallDelta(s) {
|
|
416
|
+
const t = s.toolCallId;
|
|
417
|
+
this.toolCalls.has(t) || this.toolCalls.set(t, {
|
|
418
|
+
toolCallId: s.toolCallId,
|
|
419
|
+
toolName: "",
|
|
420
|
+
argumentFragments: []
|
|
421
|
+
});
|
|
422
|
+
const a = this.toolCalls.get(t);
|
|
423
|
+
s.toolCallName ? a.toolName = s.toolCallName : s.deltaType === "tool_name" && (a.toolName += s.content), s.deltaType === "tool_argument" && s.content.length > 0 && a.argumentFragments.push(s.content);
|
|
424
|
+
}
|
|
410
425
|
/**
|
|
411
426
|
* Process a delta message and accumulate the content (original format)
|
|
412
427
|
* @param delta - The delta message to process
|
|
@@ -452,20 +467,20 @@ class Ye {
|
|
|
452
467
|
});
|
|
453
468
|
for (const [a, n] of this.toolCalls)
|
|
454
469
|
if (n.toolName) {
|
|
455
|
-
const
|
|
456
|
-
let
|
|
457
|
-
if (
|
|
470
|
+
const r = n.argumentFragments.join("");
|
|
471
|
+
let o = {};
|
|
472
|
+
if (r)
|
|
458
473
|
try {
|
|
459
|
-
|
|
474
|
+
o = JSON.parse(r);
|
|
460
475
|
} catch {
|
|
461
|
-
|
|
476
|
+
o = { _raw: r };
|
|
462
477
|
}
|
|
463
478
|
t.push({
|
|
464
479
|
type: "data",
|
|
465
480
|
data: {
|
|
466
481
|
toolCallId: n.toolCallId,
|
|
467
482
|
toolId: n.toolName,
|
|
468
|
-
arguments:
|
|
483
|
+
arguments: o
|
|
469
484
|
}
|
|
470
485
|
});
|
|
471
486
|
}
|
|
@@ -483,14 +498,14 @@ class Ye {
|
|
|
483
498
|
this.textContent = "", this.toolCalls.clear();
|
|
484
499
|
}
|
|
485
500
|
}
|
|
486
|
-
function
|
|
501
|
+
function xe(e, s, t = "request") {
|
|
487
502
|
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
503
|
}
|
|
489
504
|
function be(e, s = "request") {
|
|
490
505
|
if (!e.ok)
|
|
491
506
|
throw new Error(`HTTP error! status: ${e.status}`);
|
|
492
507
|
}
|
|
493
|
-
function
|
|
508
|
+
function et(e, s = "request") {
|
|
494
509
|
if (e.error)
|
|
495
510
|
throw new Error(
|
|
496
511
|
`Protocol ${s} error: ${e.error.message}`
|
|
@@ -499,24 +514,24 @@ function Ze(e, s = "request") {
|
|
|
499
514
|
throw new Error(`No result in ${s} response`);
|
|
500
515
|
return e.result;
|
|
501
516
|
}
|
|
502
|
-
function
|
|
517
|
+
function tt(e, s = "streaming request") {
|
|
503
518
|
if (be(e, s), !e.body)
|
|
504
519
|
throw new Error(`No response body for ${s}`);
|
|
505
520
|
}
|
|
506
|
-
function
|
|
521
|
+
function ke(e, s = "request") {
|
|
507
522
|
const t = new AbortController();
|
|
508
523
|
return { timeoutId: setTimeout(
|
|
509
524
|
() => t.abort(),
|
|
510
525
|
e
|
|
511
526
|
), controller: t };
|
|
512
527
|
}
|
|
513
|
-
function
|
|
528
|
+
function st(e, s) {
|
|
514
529
|
return `${e}/${s}`;
|
|
515
530
|
}
|
|
516
|
-
function
|
|
531
|
+
function at(e, s, t, a) {
|
|
517
532
|
A("Request: %s %s", e, s), A("Headers: %o", t), a && A("Body: %s", Ae(a));
|
|
518
533
|
}
|
|
519
|
-
async function
|
|
534
|
+
async function nt(e, s = !1) {
|
|
520
535
|
const t = {
|
|
521
536
|
"Content-Type": "application/json"
|
|
522
537
|
};
|
|
@@ -526,7 +541,7 @@ async function at(e, s = !1) {
|
|
|
526
541
|
}
|
|
527
542
|
return t;
|
|
528
543
|
}
|
|
529
|
-
function
|
|
544
|
+
function Re(e, s) {
|
|
530
545
|
if (!s)
|
|
531
546
|
return e;
|
|
532
547
|
const t = new AbortController(), a = (n) => {
|
|
@@ -547,77 +562,77 @@ function Pe(e, s, t, a) {
|
|
|
547
562
|
};
|
|
548
563
|
return a !== void 0 && (n.credentials = a), n;
|
|
549
564
|
}
|
|
550
|
-
async function Z(e, s, t, a, n,
|
|
551
|
-
const { message:
|
|
552
|
-
|
|
565
|
+
async function Z(e, s, t, a, n, r) {
|
|
566
|
+
const { message: o, sessionId: c, taskId: i, metadata: g } = e, { agentId: u, agentUrl: p, authProvider: y, proxy: v } = s, { isStreaming: f = !1, enableTokenStreaming: h = !1 } = t, I = c || r, M = st(p, u), d = await Ge(
|
|
567
|
+
o,
|
|
553
568
|
a,
|
|
554
569
|
n
|
|
555
|
-
),
|
|
570
|
+
), l = {
|
|
556
571
|
id: i,
|
|
557
572
|
message: d,
|
|
558
573
|
metadata: g
|
|
559
574
|
};
|
|
560
|
-
I && (
|
|
575
|
+
I && (l.sessionId = I);
|
|
561
576
|
const w = Ke(
|
|
562
|
-
|
|
577
|
+
l,
|
|
563
578
|
f ? "message/stream" : "message/send",
|
|
564
579
|
h && f
|
|
565
580
|
// Only enable token streaming if using SSE
|
|
566
|
-
), T = await
|
|
567
|
-
return
|
|
581
|
+
), T = await nt(y, f);
|
|
582
|
+
return at("POST", M, T, w), {
|
|
568
583
|
request: w,
|
|
569
584
|
headers: T,
|
|
570
585
|
enhancedMessage: d,
|
|
571
586
|
effectiveSessionId: I,
|
|
572
|
-
fullAgentUrl:
|
|
587
|
+
fullAgentUrl: M
|
|
573
588
|
};
|
|
574
589
|
}
|
|
575
590
|
async function _e(e, s, t = {}) {
|
|
576
|
-
const { request: a, headers: n, fullAgentUrl:
|
|
577
|
-
|
|
591
|
+
const { request: a, headers: n, fullAgentUrl: r } = e, { timeout: o, credentials: c } = s, { abortSignal: i } = t, { timeoutId: g, controller: u } = ke(
|
|
592
|
+
o,
|
|
578
593
|
"request"
|
|
579
|
-
), p = i ?
|
|
594
|
+
), p = i ? Re(u.signal, i) : u.signal;
|
|
580
595
|
try {
|
|
581
596
|
const y = Pe(
|
|
582
597
|
n,
|
|
583
598
|
JSON.stringify(a),
|
|
584
599
|
p,
|
|
585
|
-
|
|
600
|
+
c
|
|
586
601
|
);
|
|
587
|
-
A("Making request to %s with options: %O",
|
|
602
|
+
A("Making request to %s with options: %O", r, {
|
|
588
603
|
method: y.method,
|
|
589
604
|
headers: y.headers
|
|
590
605
|
});
|
|
591
|
-
const v = await fetch(
|
|
606
|
+
const v = await fetch(r, y);
|
|
592
607
|
clearTimeout(g), be(v, "request");
|
|
593
608
|
const f = await v.json();
|
|
594
609
|
return A(
|
|
595
610
|
"Response from %s: %d %O",
|
|
596
|
-
|
|
611
|
+
r,
|
|
597
612
|
v.status,
|
|
598
613
|
Ae(f)
|
|
599
|
-
),
|
|
614
|
+
), et(f, "request");
|
|
600
615
|
} catch (y) {
|
|
601
|
-
|
|
616
|
+
xe(y, g, "request");
|
|
602
617
|
}
|
|
603
618
|
}
|
|
604
619
|
async function* Ee(e, s, t) {
|
|
605
|
-
const { request: a, headers: n, fullAgentUrl:
|
|
606
|
-
streamingTimeout:
|
|
620
|
+
const { request: a, headers: n, fullAgentUrl: r } = e, { credentials: o } = s, {
|
|
621
|
+
streamingTimeout: c = 6e4,
|
|
607
622
|
abortSignal: i,
|
|
608
623
|
enableTokenStreaming: g = !1
|
|
609
|
-
} = t, { timeoutId: u, controller: p } =
|
|
610
|
-
|
|
624
|
+
} = t, { timeoutId: u, controller: p } = ke(
|
|
625
|
+
c,
|
|
611
626
|
"streaming request"
|
|
612
|
-
), y = i ?
|
|
627
|
+
), y = i ? Re(p.signal, i) : p.signal;
|
|
613
628
|
try {
|
|
614
629
|
const v = JSON.stringify(a), f = Pe(
|
|
615
630
|
n,
|
|
616
631
|
v,
|
|
617
632
|
y,
|
|
618
|
-
|
|
619
|
-
), h = await fetch(
|
|
620
|
-
if (clearTimeout(u),
|
|
633
|
+
o
|
|
634
|
+
), h = await fetch(r, f);
|
|
635
|
+
if (clearTimeout(u), tt(h, "streaming request"), !h.body)
|
|
621
636
|
throw new Error(
|
|
622
637
|
"Response body is null - server may not support streaming"
|
|
623
638
|
);
|
|
@@ -626,25 +641,25 @@ async function* Ee(e, s, t) {
|
|
|
626
641
|
supportDeltas: I
|
|
627
642
|
});
|
|
628
643
|
} catch (v) {
|
|
629
|
-
|
|
644
|
+
xe(v, u, "streaming request");
|
|
630
645
|
}
|
|
631
646
|
}
|
|
632
|
-
const
|
|
647
|
+
const ot = 12e4;
|
|
633
648
|
async function ee(e, s, t, a, n) {
|
|
634
649
|
if (e.getAbilities) {
|
|
635
|
-
const
|
|
636
|
-
if (
|
|
637
|
-
for (const
|
|
638
|
-
const
|
|
639
|
-
if (s ===
|
|
640
|
-
if (
|
|
650
|
+
const r = await e.getAbilities();
|
|
651
|
+
if (r.length > 0)
|
|
652
|
+
for (const o of r) {
|
|
653
|
+
const c = o.name.replace(/\//g, "__").replace(/-/g, "_");
|
|
654
|
+
if (s === c || s === o.name) {
|
|
655
|
+
if (o.callback)
|
|
641
656
|
try {
|
|
642
657
|
const i = {
|
|
643
658
|
...t,
|
|
644
659
|
...a && { messageId: a },
|
|
645
660
|
...n && { toolCallId: n },
|
|
646
661
|
...s && { toolId: s }
|
|
647
|
-
}, g = await
|
|
662
|
+
}, g = await o.callback(i);
|
|
648
663
|
return {
|
|
649
664
|
result: g,
|
|
650
665
|
returnToAgent: (g == null ? void 0 : g.returnToAgent) !== void 0 ? g.returnToAgent : !0,
|
|
@@ -655,7 +670,7 @@ async function ee(e, s, t, a, n) {
|
|
|
655
670
|
} catch (i) {
|
|
656
671
|
return A(
|
|
657
672
|
"Error executing ability %s: %O",
|
|
658
|
-
|
|
673
|
+
o.name,
|
|
659
674
|
i
|
|
660
675
|
), {
|
|
661
676
|
result: {
|
|
@@ -665,16 +680,16 @@ async function ee(e, s, t, a, n) {
|
|
|
665
680
|
returnToAgent: !0
|
|
666
681
|
};
|
|
667
682
|
}
|
|
668
|
-
if (!
|
|
683
|
+
if (!o.callback && e.executeAbility)
|
|
669
684
|
try {
|
|
670
685
|
return { result: await e.executeAbility(
|
|
671
|
-
|
|
686
|
+
o.name,
|
|
672
687
|
t
|
|
673
688
|
), returnToAgent: !0 };
|
|
674
689
|
} catch (i) {
|
|
675
690
|
return A(
|
|
676
691
|
"Error executing ability %s: %O",
|
|
677
|
-
|
|
692
|
+
o.name,
|
|
678
693
|
i
|
|
679
694
|
), {
|
|
680
695
|
result: {
|
|
@@ -685,7 +700,7 @@ async function ee(e, s, t, a, n) {
|
|
|
685
700
|
};
|
|
686
701
|
}
|
|
687
702
|
throw new Error(
|
|
688
|
-
`Ability ${
|
|
703
|
+
`Ability ${o.name} has no callback and no handler`
|
|
689
704
|
);
|
|
690
705
|
}
|
|
691
706
|
}
|
|
@@ -712,7 +727,7 @@ async function rt(e, s) {
|
|
|
712
727
|
const a = await e.getAvailableTools();
|
|
713
728
|
for (const n of t)
|
|
714
729
|
if (a.some(
|
|
715
|
-
(
|
|
730
|
+
(o) => o.id === n.data.toolId
|
|
716
731
|
))
|
|
717
732
|
return !0;
|
|
718
733
|
} catch {
|
|
@@ -720,20 +735,20 @@ async function rt(e, s) {
|
|
|
720
735
|
}
|
|
721
736
|
return !1;
|
|
722
737
|
}
|
|
723
|
-
function
|
|
738
|
+
function it() {
|
|
724
739
|
ge.clear();
|
|
725
740
|
}
|
|
726
|
-
function
|
|
741
|
+
function lt(e) {
|
|
727
742
|
return e.map((s) => {
|
|
728
743
|
const t = s.data.toolCallId, a = ge.get(t);
|
|
729
744
|
if (a && a.resolvedValue !== null) {
|
|
730
745
|
const n = a.resolvedValue;
|
|
731
|
-
return n.error ?
|
|
746
|
+
return n.error ? j(
|
|
732
747
|
t,
|
|
733
748
|
s.data.toolId,
|
|
734
749
|
void 0,
|
|
735
750
|
n.error
|
|
736
|
-
) :
|
|
751
|
+
) : j(
|
|
737
752
|
t,
|
|
738
753
|
s.data.toolId,
|
|
739
754
|
n
|
|
@@ -744,28 +759,28 @@ function it(e) {
|
|
|
744
759
|
}
|
|
745
760
|
async function Oe(e, s, t) {
|
|
746
761
|
const a = [], n = [];
|
|
747
|
-
let
|
|
748
|
-
for (const
|
|
749
|
-
const { toolCallId:
|
|
762
|
+
let r = !1;
|
|
763
|
+
for (const o of e) {
|
|
764
|
+
const { toolCallId: c, toolId: i, arguments: g } = o.data;
|
|
750
765
|
try {
|
|
751
766
|
const u = await ee(
|
|
752
767
|
s,
|
|
753
768
|
i,
|
|
754
769
|
g,
|
|
755
770
|
t,
|
|
756
|
-
|
|
771
|
+
c
|
|
757
772
|
), { result: p, returnToAgent: y, agentMessage: v } = de(u);
|
|
758
|
-
y && (
|
|
759
|
-
|
|
760
|
-
|
|
773
|
+
y && (r = !0), v && n.push(Q(v)), a.push(
|
|
774
|
+
j(
|
|
775
|
+
c,
|
|
761
776
|
i,
|
|
762
777
|
p
|
|
763
778
|
)
|
|
764
779
|
);
|
|
765
780
|
} catch (u) {
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
781
|
+
r = !0, a.push(
|
|
782
|
+
j(
|
|
783
|
+
c,
|
|
769
784
|
i,
|
|
770
785
|
void 0,
|
|
771
786
|
u instanceof Error ? u.message : String(u)
|
|
@@ -773,7 +788,7 @@ async function Oe(e, s, t) {
|
|
|
773
788
|
);
|
|
774
789
|
}
|
|
775
790
|
}
|
|
776
|
-
return { results: a, shouldReturnToAgent:
|
|
791
|
+
return { results: a, shouldReturnToAgent: r, agentMessages: n };
|
|
777
792
|
}
|
|
778
793
|
function Ie(e) {
|
|
779
794
|
const s = [];
|
|
@@ -788,7 +803,7 @@ function Ie(e) {
|
|
|
788
803
|
}) : (a.type === "data" || a.type === "file") && s.push(a);
|
|
789
804
|
return s;
|
|
790
805
|
}
|
|
791
|
-
async function ae(e, s, t, a, n,
|
|
806
|
+
async function ae(e, s, t, a, n, r, o) {
|
|
792
807
|
const i = await Z(
|
|
793
808
|
{
|
|
794
809
|
message: s,
|
|
@@ -800,19 +815,19 @@ async function ae(e, s, t, a, n, o, r) {
|
|
|
800
815
|
{ isStreaming: !1 },
|
|
801
816
|
a,
|
|
802
817
|
n,
|
|
803
|
-
|
|
818
|
+
r
|
|
804
819
|
);
|
|
805
820
|
return await _e(i, t, {
|
|
806
|
-
abortSignal:
|
|
821
|
+
abortSignal: o
|
|
807
822
|
});
|
|
808
823
|
}
|
|
809
|
-
async function we(e, s, t, a, n,
|
|
824
|
+
async function we(e, s, t, a, n, r, o, c, i = []) {
|
|
810
825
|
const g = {
|
|
811
826
|
message: s,
|
|
812
827
|
taskId: e,
|
|
813
|
-
sessionId:
|
|
828
|
+
sessionId: r
|
|
814
829
|
// Use the provided sessionId to maintain conversation continuity
|
|
815
|
-
}, u =
|
|
830
|
+
}, u = c || { isStreaming: !0 }, p = await Z(
|
|
816
831
|
g,
|
|
817
832
|
t,
|
|
818
833
|
{
|
|
@@ -820,28 +835,28 @@ async function we(e, s, t, a, n, o, r, l, i = []) {
|
|
|
820
835
|
},
|
|
821
836
|
a,
|
|
822
837
|
n,
|
|
823
|
-
|
|
838
|
+
r
|
|
824
839
|
), y = Ee(p, t, {
|
|
825
840
|
...u,
|
|
826
|
-
abortSignal:
|
|
841
|
+
abortSignal: o
|
|
827
842
|
});
|
|
828
843
|
return Ne(
|
|
829
844
|
y,
|
|
830
845
|
a,
|
|
831
846
|
n,
|
|
832
847
|
t,
|
|
833
|
-
|
|
848
|
+
r,
|
|
834
849
|
!0,
|
|
835
850
|
// withHistory
|
|
836
851
|
i,
|
|
837
852
|
// preserve conversation parts across continuation
|
|
838
|
-
|
|
853
|
+
o,
|
|
839
854
|
u
|
|
840
855
|
// Pass through the same request options
|
|
841
856
|
);
|
|
842
857
|
}
|
|
843
|
-
async function* Ne(e, s, t, a, n,
|
|
844
|
-
var g, u, p, y, v, f, h, I,
|
|
858
|
+
async function* Ne(e, s, t, a, n, r = !0, o = [], c, i) {
|
|
859
|
+
var g, u, p, y, v, f, h, I, M, d, l, w;
|
|
845
860
|
for await (const T of e) {
|
|
846
861
|
if (T.sessionId && !n && (n = T.sessionId), yield T, T.status.state === "running" && T.status.message && s && await rt(
|
|
847
862
|
s,
|
|
@@ -858,8 +873,8 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
858
873
|
m,
|
|
859
874
|
(u = (g = T.status) == null ? void 0 : g.message) == null ? void 0 : u.messageId,
|
|
860
875
|
$
|
|
861
|
-
).catch((
|
|
862
|
-
A("Tool execution failed for %s: %O", U,
|
|
876
|
+
).catch((C) => {
|
|
877
|
+
A("Tool execution failed for %s: %O", U, C);
|
|
863
878
|
});
|
|
864
879
|
}
|
|
865
880
|
yield {
|
|
@@ -885,100 +900,100 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
885
900
|
const E = [];
|
|
886
901
|
let $ = !1;
|
|
887
902
|
const U = [], m = [];
|
|
888
|
-
for (const
|
|
903
|
+
for (const C of b) {
|
|
889
904
|
const {
|
|
890
|
-
toolCallId:
|
|
891
|
-
toolId:
|
|
905
|
+
toolCallId: S,
|
|
906
|
+
toolId: R,
|
|
892
907
|
arguments: N
|
|
893
|
-
} =
|
|
908
|
+
} = C.data;
|
|
894
909
|
try {
|
|
895
|
-
const
|
|
910
|
+
const k = await ee(
|
|
896
911
|
s,
|
|
897
|
-
|
|
912
|
+
R,
|
|
898
913
|
N,
|
|
899
914
|
(y = (p = T.status) == null ? void 0 : p.message) == null ? void 0 : y.messageId,
|
|
900
|
-
|
|
901
|
-
), { result:
|
|
902
|
-
if (P && ($ = !0),
|
|
903
|
-
Q(
|
|
904
|
-
),
|
|
905
|
-
const K =
|
|
915
|
+
S
|
|
916
|
+
), { result: x, returnToAgent: P, agentMessage: D } = de(k);
|
|
917
|
+
if (P && ($ = !0), D && m.push(
|
|
918
|
+
Q(D)
|
|
919
|
+
), x.result instanceof Promise) {
|
|
920
|
+
const K = x.result, q = {
|
|
906
921
|
promise: K,
|
|
907
922
|
resolvedValue: null
|
|
908
923
|
};
|
|
909
924
|
ge.set(
|
|
910
|
-
|
|
925
|
+
S,
|
|
911
926
|
q
|
|
912
927
|
), K.then((_) => {
|
|
913
928
|
q.resolvedValue = _;
|
|
914
929
|
}).catch((_) => {
|
|
915
930
|
A(
|
|
916
931
|
"Promise rejected for tool call %s: %O",
|
|
917
|
-
|
|
932
|
+
S,
|
|
918
933
|
_
|
|
919
934
|
), q.resolvedValue = {
|
|
920
935
|
error: _ instanceof Error ? _.message : String(_)
|
|
921
936
|
};
|
|
922
937
|
});
|
|
923
938
|
}
|
|
924
|
-
const J =
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
939
|
+
const J = j(
|
|
940
|
+
S,
|
|
941
|
+
R,
|
|
942
|
+
x
|
|
928
943
|
);
|
|
929
944
|
E.push(J), U.push(J);
|
|
930
|
-
} catch (
|
|
931
|
-
const
|
|
932
|
-
|
|
933
|
-
|
|
945
|
+
} catch (k) {
|
|
946
|
+
const x = j(
|
|
947
|
+
S,
|
|
948
|
+
R,
|
|
934
949
|
void 0,
|
|
935
|
-
|
|
950
|
+
k instanceof Error ? k.message : String(k)
|
|
936
951
|
);
|
|
937
|
-
E.push(
|
|
952
|
+
E.push(x), U.push(x);
|
|
938
953
|
}
|
|
939
954
|
}
|
|
940
|
-
if (
|
|
955
|
+
if (o.push(T.status.message), E.length > 0 && o.push({
|
|
941
956
|
role: "agent",
|
|
942
957
|
kind: "message",
|
|
943
958
|
parts: E,
|
|
944
959
|
messageId: O()
|
|
945
960
|
}), $) {
|
|
946
|
-
const
|
|
961
|
+
const C = Ie(o), S = Y(
|
|
947
962
|
[],
|
|
948
963
|
// Empty array - tool results are already in historyDataParts
|
|
949
|
-
|
|
964
|
+
C
|
|
950
965
|
);
|
|
951
966
|
yield {
|
|
952
967
|
id: T.id,
|
|
953
968
|
status: {
|
|
954
969
|
state: "working",
|
|
955
|
-
message:
|
|
970
|
+
message: S
|
|
956
971
|
},
|
|
957
972
|
final: !1,
|
|
958
973
|
text: ""
|
|
959
974
|
};
|
|
960
|
-
const
|
|
975
|
+
const R = await we(
|
|
961
976
|
T.id,
|
|
962
|
-
|
|
977
|
+
S,
|
|
963
978
|
a,
|
|
964
979
|
s,
|
|
965
980
|
t,
|
|
966
981
|
n,
|
|
967
|
-
|
|
982
|
+
c,
|
|
968
983
|
i,
|
|
969
|
-
|
|
984
|
+
o
|
|
970
985
|
);
|
|
971
986
|
let N = null;
|
|
972
|
-
for await (const P of
|
|
987
|
+
for await (const P of R)
|
|
973
988
|
P.final ? N = P : yield P;
|
|
974
989
|
if (!N)
|
|
975
990
|
throw new Error(
|
|
976
991
|
"Continue task stream ended without final result"
|
|
977
992
|
);
|
|
978
|
-
let
|
|
993
|
+
let k = (v = N.status) != null && v.message ? B(
|
|
979
994
|
N.status.message
|
|
980
|
-
) : [],
|
|
981
|
-
if (
|
|
995
|
+
) : [], x = N;
|
|
996
|
+
if (k.length > 0)
|
|
982
997
|
for (yield {
|
|
983
998
|
...N,
|
|
984
999
|
final: !1,
|
|
@@ -988,20 +1003,20 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
988
1003
|
messageId: O()
|
|
989
1004
|
}
|
|
990
1005
|
)
|
|
991
|
-
};
|
|
992
|
-
(h =
|
|
993
|
-
|
|
1006
|
+
}; k.length > 0; ) {
|
|
1007
|
+
(h = x.status) != null && h.message && o.push(
|
|
1008
|
+
x.status.message
|
|
994
1009
|
);
|
|
995
1010
|
const {
|
|
996
1011
|
results: P,
|
|
997
|
-
shouldReturnToAgent:
|
|
1012
|
+
shouldReturnToAgent: D
|
|
998
1013
|
} = await Oe(
|
|
999
|
-
|
|
1014
|
+
k,
|
|
1000
1015
|
s,
|
|
1001
|
-
(
|
|
1016
|
+
(M = (I = x.status) == null ? void 0 : I.message) == null ? void 0 : M.messageId
|
|
1002
1017
|
);
|
|
1003
1018
|
if (P.length > 0 && (yield {
|
|
1004
|
-
id:
|
|
1019
|
+
id: x.id,
|
|
1005
1020
|
status: {
|
|
1006
1021
|
state: "working",
|
|
1007
1022
|
message: {
|
|
@@ -1014,22 +1029,22 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1014
1029
|
},
|
|
1015
1030
|
final: !1,
|
|
1016
1031
|
text: ""
|
|
1017
|
-
}),
|
|
1018
|
-
const J =
|
|
1019
|
-
|
|
1032
|
+
}), D) {
|
|
1033
|
+
const J = r ? Ie(
|
|
1034
|
+
o
|
|
1020
1035
|
) : [], K = Y(
|
|
1021
1036
|
P,
|
|
1022
1037
|
J
|
|
1023
1038
|
), q = await we(
|
|
1024
|
-
|
|
1039
|
+
x.id,
|
|
1025
1040
|
K,
|
|
1026
1041
|
a,
|
|
1027
1042
|
s,
|
|
1028
1043
|
t,
|
|
1029
1044
|
n,
|
|
1030
|
-
|
|
1045
|
+
c,
|
|
1031
1046
|
i,
|
|
1032
|
-
|
|
1047
|
+
o
|
|
1033
1048
|
);
|
|
1034
1049
|
let _ = null;
|
|
1035
1050
|
for await (const V of q)
|
|
@@ -1038,14 +1053,14 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1038
1053
|
throw new Error(
|
|
1039
1054
|
"Continue task stream ended without final result"
|
|
1040
1055
|
);
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
) : [],
|
|
1044
|
-
id:
|
|
1045
|
-
status:
|
|
1056
|
+
x = _, k = (d = x.status) != null && d.message ? B(
|
|
1057
|
+
x.status.message
|
|
1058
|
+
) : [], k.length > 0 && (yield {
|
|
1059
|
+
id: x.id,
|
|
1060
|
+
status: x.status,
|
|
1046
1061
|
final: !1,
|
|
1047
1062
|
text: F(
|
|
1048
|
-
((
|
|
1063
|
+
((l = x.status) == null ? void 0 : l.message) || {
|
|
1049
1064
|
parts: [],
|
|
1050
1065
|
messageId: O()
|
|
1051
1066
|
}
|
|
@@ -1055,39 +1070,39 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1055
1070
|
break;
|
|
1056
1071
|
}
|
|
1057
1072
|
yield {
|
|
1058
|
-
...
|
|
1073
|
+
...x,
|
|
1059
1074
|
final: !0,
|
|
1060
1075
|
text: F(
|
|
1061
|
-
((w =
|
|
1076
|
+
((w = x.status) == null ? void 0 : w.message) || {
|
|
1062
1077
|
parts: [],
|
|
1063
1078
|
messageId: O()
|
|
1064
1079
|
}
|
|
1065
1080
|
)
|
|
1066
1081
|
};
|
|
1067
1082
|
} else {
|
|
1068
|
-
const
|
|
1083
|
+
const C = {
|
|
1069
1084
|
...T.status.message,
|
|
1070
1085
|
parts: U
|
|
1071
|
-
},
|
|
1086
|
+
}, S = {
|
|
1072
1087
|
...T,
|
|
1073
1088
|
status: {
|
|
1074
1089
|
...T.status,
|
|
1075
|
-
message:
|
|
1090
|
+
message: C
|
|
1076
1091
|
},
|
|
1077
1092
|
final: m.length === 0,
|
|
1078
1093
|
// Only final if no agent messages to follow
|
|
1079
|
-
text: F(
|
|
1094
|
+
text: F(C)
|
|
1080
1095
|
};
|
|
1081
|
-
if (yield
|
|
1082
|
-
const
|
|
1096
|
+
if (yield S, m.length > 0) {
|
|
1097
|
+
const R = m.map((k) => F(k)).join(" "), N = Q(R);
|
|
1083
1098
|
yield {
|
|
1084
|
-
id:
|
|
1099
|
+
id: S.id,
|
|
1085
1100
|
status: {
|
|
1086
1101
|
state: "completed",
|
|
1087
1102
|
message: N
|
|
1088
1103
|
},
|
|
1089
1104
|
final: !0,
|
|
1090
|
-
text:
|
|
1105
|
+
text: R
|
|
1091
1106
|
};
|
|
1092
1107
|
}
|
|
1093
1108
|
}
|
|
@@ -1095,35 +1110,35 @@ async function* Ne(e, s, t, a, n, o = !0, r = [], l, i) {
|
|
|
1095
1110
|
}
|
|
1096
1111
|
}
|
|
1097
1112
|
}
|
|
1098
|
-
function
|
|
1113
|
+
function ct(e) {
|
|
1099
1114
|
const {
|
|
1100
1115
|
agentId: s,
|
|
1101
1116
|
agentUrl: t,
|
|
1102
1117
|
authProvider: a,
|
|
1103
1118
|
defaultSessionId: n,
|
|
1104
|
-
timeout:
|
|
1105
|
-
toolProvider:
|
|
1106
|
-
contextProvider:
|
|
1119
|
+
timeout: r = ot,
|
|
1120
|
+
toolProvider: o,
|
|
1121
|
+
contextProvider: c,
|
|
1107
1122
|
enableStreaming: i = !1,
|
|
1108
1123
|
credentials: g
|
|
1109
1124
|
} = e, u = {
|
|
1110
1125
|
agentId: s,
|
|
1111
1126
|
agentUrl: t,
|
|
1112
1127
|
authProvider: a,
|
|
1113
|
-
timeout:
|
|
1128
|
+
timeout: r,
|
|
1114
1129
|
credentials: g
|
|
1115
1130
|
};
|
|
1116
1131
|
return {
|
|
1117
1132
|
async sendMessage(p) {
|
|
1118
|
-
var
|
|
1133
|
+
var l, w;
|
|
1119
1134
|
const { abortSignal: y } = p, v = p.sessionId || n || void 0, f = [];
|
|
1120
1135
|
f.push(p.message);
|
|
1121
1136
|
const h = await Z(
|
|
1122
1137
|
p,
|
|
1123
1138
|
u,
|
|
1124
1139
|
{ isStreaming: !1 },
|
|
1125
|
-
|
|
1126
|
-
|
|
1140
|
+
o,
|
|
1141
|
+
c,
|
|
1127
1142
|
v
|
|
1128
1143
|
);
|
|
1129
1144
|
let I = await _e(
|
|
@@ -1131,45 +1146,45 @@ function lt(e) {
|
|
|
1131
1146
|
u,
|
|
1132
1147
|
{ abortSignal: y }
|
|
1133
1148
|
);
|
|
1134
|
-
const
|
|
1135
|
-
for (; I.status.message &&
|
|
1149
|
+
const M = [], d = [];
|
|
1150
|
+
for (; I.status.message && o; ) {
|
|
1136
1151
|
const T = B(
|
|
1137
1152
|
I.status.message
|
|
1138
1153
|
);
|
|
1139
1154
|
if (T.length === 0)
|
|
1140
1155
|
break;
|
|
1141
|
-
|
|
1156
|
+
M.push(...T);
|
|
1142
1157
|
const b = [];
|
|
1143
1158
|
let E = !1;
|
|
1144
1159
|
for (const $ of T) {
|
|
1145
1160
|
const {
|
|
1146
1161
|
toolCallId: U,
|
|
1147
1162
|
toolId: m,
|
|
1148
|
-
arguments:
|
|
1163
|
+
arguments: C
|
|
1149
1164
|
} = $.data;
|
|
1150
1165
|
try {
|
|
1151
|
-
const
|
|
1152
|
-
|
|
1166
|
+
const S = await ee(
|
|
1167
|
+
o,
|
|
1153
1168
|
m,
|
|
1154
|
-
|
|
1155
|
-
), { result:
|
|
1156
|
-
N && (E = !0),
|
|
1157
|
-
Q(
|
|
1169
|
+
C
|
|
1170
|
+
), { result: R, returnToAgent: N, agentMessage: k } = de(S);
|
|
1171
|
+
N && (E = !0), k && d.push(
|
|
1172
|
+
Q(k)
|
|
1158
1173
|
);
|
|
1159
|
-
const
|
|
1174
|
+
const x = j(
|
|
1160
1175
|
U,
|
|
1161
1176
|
m,
|
|
1162
|
-
|
|
1177
|
+
R
|
|
1163
1178
|
);
|
|
1164
|
-
b.push(
|
|
1165
|
-
} catch (
|
|
1166
|
-
const
|
|
1179
|
+
b.push(x), M.push(x);
|
|
1180
|
+
} catch (S) {
|
|
1181
|
+
const R = j(
|
|
1167
1182
|
U,
|
|
1168
1183
|
m,
|
|
1169
1184
|
void 0,
|
|
1170
|
-
|
|
1185
|
+
S instanceof Error ? S.message : String(S)
|
|
1171
1186
|
);
|
|
1172
|
-
b.push(
|
|
1187
|
+
b.push(R), M.push(R);
|
|
1173
1188
|
}
|
|
1174
1189
|
}
|
|
1175
1190
|
if (f.push(I.status.message), E) {
|
|
@@ -1178,18 +1193,18 @@ function lt(e) {
|
|
|
1178
1193
|
I.id,
|
|
1179
1194
|
$,
|
|
1180
1195
|
u,
|
|
1181
|
-
|
|
1182
|
-
|
|
1196
|
+
o,
|
|
1197
|
+
c,
|
|
1183
1198
|
v,
|
|
1184
1199
|
y
|
|
1185
1200
|
);
|
|
1186
1201
|
} else
|
|
1187
1202
|
break;
|
|
1188
1203
|
}
|
|
1189
|
-
if (
|
|
1204
|
+
if (M.length > 0 && (l = I.status) != null && l.message) {
|
|
1190
1205
|
const T = {
|
|
1191
1206
|
...I.status.message,
|
|
1192
|
-
parts:
|
|
1207
|
+
parts: M
|
|
1193
1208
|
};
|
|
1194
1209
|
I = {
|
|
1195
1210
|
...I,
|
|
@@ -1225,8 +1240,8 @@ function lt(e) {
|
|
|
1225
1240
|
withHistory: y = !0,
|
|
1226
1241
|
abortSignal: v,
|
|
1227
1242
|
enableStreaming: f
|
|
1228
|
-
} = p, h = p.sessionId || n || void 0, I = f ?? i,
|
|
1229
|
-
|
|
1243
|
+
} = p, h = p.sessionId || n || void 0, I = f ?? i, M = [];
|
|
1244
|
+
M.push(p.message);
|
|
1230
1245
|
const d = await Z(
|
|
1231
1246
|
p,
|
|
1232
1247
|
u,
|
|
@@ -1235,61 +1250,61 @@ function lt(e) {
|
|
|
1235
1250
|
// Always use message/stream endpoint for SSE
|
|
1236
1251
|
enableTokenStreaming: I
|
|
1237
1252
|
},
|
|
1238
|
-
|
|
1239
|
-
|
|
1253
|
+
o,
|
|
1254
|
+
c,
|
|
1240
1255
|
h
|
|
1241
|
-
),
|
|
1256
|
+
), l = Ee(
|
|
1242
1257
|
d,
|
|
1243
1258
|
u,
|
|
1244
1259
|
{
|
|
1245
1260
|
enableTokenStreaming: I,
|
|
1246
1261
|
// Token streaming is optional
|
|
1247
|
-
streamingTimeout:
|
|
1262
|
+
streamingTimeout: r,
|
|
1248
1263
|
abortSignal: v
|
|
1249
1264
|
}
|
|
1250
1265
|
);
|
|
1251
1266
|
yield* Ne(
|
|
1252
|
-
c,
|
|
1253
|
-
r,
|
|
1254
1267
|
l,
|
|
1268
|
+
o,
|
|
1269
|
+
c,
|
|
1255
1270
|
u,
|
|
1256
1271
|
h,
|
|
1257
1272
|
y,
|
|
1258
|
-
|
|
1273
|
+
M,
|
|
1259
1274
|
v,
|
|
1260
1275
|
{
|
|
1261
1276
|
isStreaming: !0,
|
|
1262
1277
|
enableTokenStreaming: I,
|
|
1263
|
-
streamingTimeout:
|
|
1278
|
+
streamingTimeout: r
|
|
1264
1279
|
}
|
|
1265
1280
|
);
|
|
1266
1281
|
},
|
|
1267
1282
|
async continueTask(p, y, v) {
|
|
1268
|
-
var
|
|
1283
|
+
var M;
|
|
1269
1284
|
const f = ie(y);
|
|
1270
1285
|
let I = await ae(
|
|
1271
1286
|
p,
|
|
1272
1287
|
f,
|
|
1273
1288
|
u,
|
|
1274
|
-
|
|
1275
|
-
|
|
1289
|
+
o,
|
|
1290
|
+
c,
|
|
1276
1291
|
v
|
|
1277
1292
|
);
|
|
1278
|
-
for (; I.status.state === "input-required" && I.status.message &&
|
|
1293
|
+
for (; I.status.state === "input-required" && I.status.message && o; ) {
|
|
1279
1294
|
const d = B(
|
|
1280
1295
|
I.status.message
|
|
1281
1296
|
);
|
|
1282
1297
|
if (d.length === 0)
|
|
1283
1298
|
break;
|
|
1284
|
-
const { results:
|
|
1299
|
+
const { results: l, shouldReturnToAgent: w } = await Oe(d, o);
|
|
1285
1300
|
if (w) {
|
|
1286
|
-
const T = Y(
|
|
1301
|
+
const T = Y(l);
|
|
1287
1302
|
I = await ae(
|
|
1288
1303
|
I.id,
|
|
1289
1304
|
T,
|
|
1290
1305
|
u,
|
|
1291
|
-
|
|
1292
|
-
|
|
1306
|
+
o,
|
|
1307
|
+
c,
|
|
1293
1308
|
v
|
|
1294
1309
|
);
|
|
1295
1310
|
} else
|
|
@@ -1298,7 +1313,7 @@ function lt(e) {
|
|
|
1298
1313
|
return {
|
|
1299
1314
|
...I,
|
|
1300
1315
|
text: F(
|
|
1301
|
-
((
|
|
1316
|
+
((M = I.status) == null ? void 0 : M.message) || {
|
|
1302
1317
|
parts: [],
|
|
1303
1318
|
messageId: O()
|
|
1304
1319
|
}
|
|
@@ -1313,36 +1328,36 @@ function lt(e) {
|
|
|
1313
1328
|
}
|
|
1314
1329
|
};
|
|
1315
1330
|
}
|
|
1316
|
-
function
|
|
1331
|
+
function ut(e) {
|
|
1317
1332
|
const s = [];
|
|
1318
1333
|
if (e.content) {
|
|
1319
|
-
const
|
|
1334
|
+
const r = {
|
|
1320
1335
|
type: "text",
|
|
1321
1336
|
text: e.content
|
|
1322
1337
|
};
|
|
1323
|
-
s.push(
|
|
1338
|
+
s.push(r);
|
|
1324
1339
|
}
|
|
1325
1340
|
const t = e.context;
|
|
1326
1341
|
if (t && !Array.isArray(t) && Array.isArray(t.file_parts)) {
|
|
1327
|
-
for (const
|
|
1328
|
-
if (
|
|
1329
|
-
const
|
|
1342
|
+
for (const r of t.file_parts)
|
|
1343
|
+
if (r != null && r.uri) {
|
|
1344
|
+
const o = {
|
|
1330
1345
|
type: "file",
|
|
1331
1346
|
file: {
|
|
1332
1347
|
name: "image",
|
|
1333
|
-
uri:
|
|
1348
|
+
uri: r.uri
|
|
1334
1349
|
},
|
|
1335
1350
|
// Pass attachment ID in metadata if available
|
|
1336
|
-
metadata:
|
|
1351
|
+
metadata: r.id ? { id: r.id } : void 0
|
|
1337
1352
|
};
|
|
1338
|
-
s.push(
|
|
1353
|
+
s.push(o);
|
|
1339
1354
|
}
|
|
1340
1355
|
}
|
|
1341
1356
|
if (t && !Array.isArray(t)) {
|
|
1342
|
-
const
|
|
1343
|
-
if (
|
|
1357
|
+
const r = t, o = r.flags && typeof r.flags == "object" && r.flags !== null, c = Array.isArray(r.sources) && r.sources.length > 0;
|
|
1358
|
+
if (o || c) {
|
|
1344
1359
|
const i = {};
|
|
1345
|
-
|
|
1360
|
+
o && (i.flags = r.flags), c && (i.sources = r.sources), s.push({
|
|
1346
1361
|
type: "data",
|
|
1347
1362
|
data: i
|
|
1348
1363
|
});
|
|
@@ -1363,7 +1378,7 @@ function ct(e) {
|
|
|
1363
1378
|
}
|
|
1364
1379
|
};
|
|
1365
1380
|
}
|
|
1366
|
-
function
|
|
1381
|
+
function dt(e) {
|
|
1367
1382
|
if (e.role !== "tool_call" && e.role !== "tool_result")
|
|
1368
1383
|
return !1;
|
|
1369
1384
|
try {
|
|
@@ -1372,12 +1387,12 @@ function ut(e) {
|
|
|
1372
1387
|
return !1;
|
|
1373
1388
|
}
|
|
1374
1389
|
}
|
|
1375
|
-
function
|
|
1376
|
-
var
|
|
1377
|
-
const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!s ||
|
|
1378
|
-
currentPage: ((
|
|
1379
|
-
itemsPerPage: ((
|
|
1380
|
-
totalPages: ((
|
|
1390
|
+
function gt(e, s = !1) {
|
|
1391
|
+
var r, o, c, i, g, u;
|
|
1392
|
+
const a = e.messages.filter((p) => p.role === "tool_call" ? !1 : p.role === "tool_result" ? !(!s || dt(p)) : !0).map(ut), n = {
|
|
1393
|
+
currentPage: ((r = e.metadata) == null ? void 0 : r.current_page) ?? 1,
|
|
1394
|
+
itemsPerPage: ((o = e.metadata) == null ? void 0 : o.items_per_page) ?? 10,
|
|
1395
|
+
totalPages: ((c = e.metadata) == null ? void 0 : c.total_pages) ?? 1,
|
|
1381
1396
|
totalMessages: ((i = e.metadata) == null ? void 0 : i.total_messages) ?? a.length,
|
|
1382
1397
|
hasMore: (((g = e.metadata) == null ? void 0 : g.current_page) ?? 1) < (((u = e.metadata) == null ? void 0 : u.total_pages) ?? 1)
|
|
1383
1398
|
};
|
|
@@ -1395,14 +1410,14 @@ class z extends Error {
|
|
|
1395
1410
|
}
|
|
1396
1411
|
const fe = "https://public-api.wordpress.com";
|
|
1397
1412
|
async function le(e, s, t = 1, a = 50, n = !1) {
|
|
1398
|
-
const { botId:
|
|
1399
|
-
if (!e || !
|
|
1413
|
+
const { botId: r, apiBaseUrl: o = fe, authProvider: c } = s;
|
|
1414
|
+
if (!e || !r)
|
|
1400
1415
|
throw new Error(
|
|
1401
1416
|
"chatId and botId are required to load conversation from server"
|
|
1402
1417
|
);
|
|
1403
1418
|
const i = Math.max(1, Math.min(t, 100)), g = Math.max(1, Math.min(a, 100)), u = new URL(
|
|
1404
|
-
`${
|
|
1405
|
-
|
|
1419
|
+
`${o}/wpcom/v2/odie/chat/${encodeURIComponent(
|
|
1420
|
+
r
|
|
1406
1421
|
)}/${encodeURIComponent(e)}`
|
|
1407
1422
|
);
|
|
1408
1423
|
u.searchParams.set("page_number", i.toString()), u.searchParams.set("items_per_page", g.toString()), A(
|
|
@@ -1414,8 +1429,8 @@ async function le(e, s, t = 1, a = 50, n = !1) {
|
|
|
1414
1429
|
const p = {
|
|
1415
1430
|
"Content-Type": "application/json"
|
|
1416
1431
|
};
|
|
1417
|
-
if (
|
|
1418
|
-
const h = await
|
|
1432
|
+
if (c) {
|
|
1433
|
+
const h = await c();
|
|
1419
1434
|
Object.assign(p, h);
|
|
1420
1435
|
}
|
|
1421
1436
|
const y = await fetch(u.toString(), {
|
|
@@ -1430,14 +1445,14 @@ async function le(e, s, t = 1, a = 50, n = !1) {
|
|
|
1430
1445
|
d.message && (I = d.message);
|
|
1431
1446
|
} catch {
|
|
1432
1447
|
}
|
|
1433
|
-
const
|
|
1448
|
+
const M = new z(
|
|
1434
1449
|
I,
|
|
1435
1450
|
y.status,
|
|
1436
1451
|
h
|
|
1437
1452
|
);
|
|
1438
|
-
throw A("Failed to load conversation from server: %O",
|
|
1453
|
+
throw A("Failed to load conversation from server: %O", M), M;
|
|
1439
1454
|
}
|
|
1440
|
-
const v = await y.json(), f =
|
|
1455
|
+
const v = await y.json(), f = gt(v, n);
|
|
1441
1456
|
return A(
|
|
1442
1457
|
"Loaded %d messages from server (page %d/%d)",
|
|
1443
1458
|
f.messages.length,
|
|
@@ -1455,50 +1470,50 @@ async function le(e, s, t = 1, a = 50, n = !1) {
|
|
|
1455
1470
|
throw A("Network error loading conversation: %O", p), y;
|
|
1456
1471
|
}
|
|
1457
1472
|
}
|
|
1458
|
-
async function
|
|
1459
|
-
const { apiBaseUrl: a = fe, authProvider: n } = s,
|
|
1473
|
+
async function Bt(e, s, t = !1) {
|
|
1474
|
+
const { apiBaseUrl: a = fe, authProvider: n } = s, r = new URL(
|
|
1460
1475
|
`${a}/wpcom/v2/odie/conversations/${encodeURIComponent(
|
|
1461
1476
|
e
|
|
1462
1477
|
)}`
|
|
1463
1478
|
);
|
|
1464
|
-
|
|
1479
|
+
r.searchParams.set(
|
|
1465
1480
|
"truncation_method",
|
|
1466
1481
|
t ? "first_message" : "last_message"
|
|
1467
1482
|
), A("Listing conversations from server for bot: %s", e);
|
|
1468
1483
|
try {
|
|
1469
|
-
const
|
|
1484
|
+
const o = {
|
|
1470
1485
|
"Content-Type": "application/json"
|
|
1471
1486
|
};
|
|
1472
1487
|
if (n) {
|
|
1473
1488
|
const g = await n();
|
|
1474
|
-
Object.assign(
|
|
1489
|
+
Object.assign(o, g);
|
|
1475
1490
|
}
|
|
1476
|
-
const
|
|
1491
|
+
const c = await fetch(r.toString(), {
|
|
1477
1492
|
method: "GET",
|
|
1478
|
-
headers:
|
|
1493
|
+
headers: o
|
|
1479
1494
|
});
|
|
1480
|
-
if (!
|
|
1481
|
-
const g = await
|
|
1495
|
+
if (!c.ok) {
|
|
1496
|
+
const g = await c.text(), u = `Failed to list conversations: ${c.status} ${c.statusText}`, p = new z(
|
|
1482
1497
|
u,
|
|
1483
|
-
|
|
1498
|
+
c.status,
|
|
1484
1499
|
g
|
|
1485
1500
|
);
|
|
1486
1501
|
throw A("Failed to list conversations: %O", p), p;
|
|
1487
1502
|
}
|
|
1488
|
-
const i = await
|
|
1503
|
+
const i = await c.json();
|
|
1489
1504
|
return A("Loaded %d conversations from server", i.length), i;
|
|
1490
|
-
} catch (
|
|
1491
|
-
if (
|
|
1492
|
-
throw
|
|
1493
|
-
const
|
|
1494
|
-
`Network error listing conversations: ${
|
|
1505
|
+
} catch (o) {
|
|
1506
|
+
if (o instanceof z)
|
|
1507
|
+
throw o;
|
|
1508
|
+
const c = new z(
|
|
1509
|
+
`Network error listing conversations: ${o.message}`,
|
|
1495
1510
|
void 0,
|
|
1496
|
-
|
|
1511
|
+
o
|
|
1497
1512
|
);
|
|
1498
|
-
throw A("Network error listing conversations: %O",
|
|
1513
|
+
throw A("Network error listing conversations: %O", o), c;
|
|
1499
1514
|
}
|
|
1500
1515
|
}
|
|
1501
|
-
async function
|
|
1516
|
+
async function Wt(e, s, t = 10, a = !1) {
|
|
1502
1517
|
const n = await le(
|
|
1503
1518
|
e,
|
|
1504
1519
|
s,
|
|
@@ -1508,37 +1523,37 @@ async function Bt(e, s, t = 10, a = !1) {
|
|
|
1508
1523
|
);
|
|
1509
1524
|
if (!n.pagination.hasMore)
|
|
1510
1525
|
return n;
|
|
1511
|
-
const
|
|
1526
|
+
const r = Math.min(
|
|
1512
1527
|
n.pagination.totalPages,
|
|
1513
1528
|
t
|
|
1514
|
-
),
|
|
1515
|
-
for (let i = 2; i <=
|
|
1516
|
-
|
|
1529
|
+
), o = [...n.messages], c = [];
|
|
1530
|
+
for (let i = 2; i <= r; i++)
|
|
1531
|
+
c.push(
|
|
1517
1532
|
le(e, s, i, 50, a)
|
|
1518
1533
|
);
|
|
1519
1534
|
try {
|
|
1520
|
-
const i = await Promise.all(
|
|
1535
|
+
const i = await Promise.all(c);
|
|
1521
1536
|
for (const g of i)
|
|
1522
|
-
|
|
1537
|
+
o.push(...g.messages);
|
|
1523
1538
|
return {
|
|
1524
|
-
messages:
|
|
1539
|
+
messages: o,
|
|
1525
1540
|
pagination: {
|
|
1526
1541
|
...n.pagination,
|
|
1527
|
-
currentPage:
|
|
1528
|
-
hasMore:
|
|
1542
|
+
currentPage: r,
|
|
1543
|
+
hasMore: r < n.pagination.totalPages
|
|
1529
1544
|
},
|
|
1530
1545
|
chatId: n.chatId
|
|
1531
1546
|
};
|
|
1532
1547
|
} catch (i) {
|
|
1533
1548
|
return A("Failed to load all pages: %O", i), {
|
|
1534
|
-
messages:
|
|
1549
|
+
messages: o,
|
|
1535
1550
|
pagination: n.pagination,
|
|
1536
1551
|
chatId: n.chatId
|
|
1537
1552
|
};
|
|
1538
1553
|
}
|
|
1539
1554
|
}
|
|
1540
1555
|
const me = "a8c_agenttic_conversation_history";
|
|
1541
|
-
function
|
|
1556
|
+
function ft(e) {
|
|
1542
1557
|
var y, v;
|
|
1543
1558
|
const s = e.parts.filter(
|
|
1544
1559
|
(f) => f.type === "text"
|
|
@@ -1554,44 +1569,44 @@ function gt(e) {
|
|
|
1554
1569
|
toolCallId: f.data.toolCallId,
|
|
1555
1570
|
toolId: f.data.toolId,
|
|
1556
1571
|
arguments: f.data.arguments
|
|
1557
|
-
})),
|
|
1572
|
+
})), r = e.parts.filter(
|
|
1558
1573
|
(f) => f.type === "data" && "toolCallId" in f.data && "result" in f.data
|
|
1559
1574
|
).map((f) => ({
|
|
1560
1575
|
toolCallId: f.data.toolCallId,
|
|
1561
1576
|
result: f.data.result,
|
|
1562
1577
|
error: f.data.error
|
|
1563
|
-
})),
|
|
1578
|
+
})), o = e.parts.filter((f) => f.type === "file").map((f) => ({
|
|
1564
1579
|
name: f.file.name,
|
|
1565
1580
|
mimeType: f.file.mimeType,
|
|
1566
1581
|
uri: f.file.uri
|
|
1567
1582
|
}));
|
|
1568
|
-
let
|
|
1583
|
+
let c;
|
|
1569
1584
|
for (const f of e.parts) {
|
|
1570
1585
|
if (f.type !== "data" || !f.data || typeof f.data != "object" || "toolCallId" in f.data)
|
|
1571
1586
|
continue;
|
|
1572
1587
|
const h = f.data, I = h.flags;
|
|
1573
1588
|
if (I && typeof I == "object" && I !== null && "forward_to_human_support" in I) {
|
|
1574
|
-
|
|
1589
|
+
c = {
|
|
1575
1590
|
flags: I,
|
|
1576
1591
|
..."sources" in h && { sources: h.sources }
|
|
1577
1592
|
};
|
|
1578
1593
|
break;
|
|
1579
1594
|
}
|
|
1580
1595
|
}
|
|
1581
|
-
const g = n.length > 0 ||
|
|
1596
|
+
const g = n.length > 0 || r.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;
|
|
1582
1597
|
return {
|
|
1583
1598
|
role: g,
|
|
1584
1599
|
content: t || "(No text content)",
|
|
1585
1600
|
timestamp: u,
|
|
1586
1601
|
...p !== void 0 && { archived: p },
|
|
1587
1602
|
...a && { contentType: a },
|
|
1588
|
-
...
|
|
1603
|
+
...o.length > 0 && { files: o },
|
|
1589
1604
|
...n.length > 0 && { toolCalls: n },
|
|
1590
|
-
...
|
|
1591
|
-
...
|
|
1605
|
+
...r.length > 0 && { toolResults: r },
|
|
1606
|
+
...c && { agentMessageData: c }
|
|
1592
1607
|
};
|
|
1593
1608
|
}
|
|
1594
|
-
function
|
|
1609
|
+
function mt(e) {
|
|
1595
1610
|
const s = [];
|
|
1596
1611
|
if (e.content && e.content !== "(No text content)" && s.push({
|
|
1597
1612
|
type: "text",
|
|
@@ -1649,10 +1664,10 @@ function ft(e) {
|
|
|
1649
1664
|
}
|
|
1650
1665
|
};
|
|
1651
1666
|
}
|
|
1652
|
-
const W = /* @__PURE__ */ new Map(),
|
|
1653
|
-
async function
|
|
1667
|
+
const W = /* @__PURE__ */ new Map(), pt = 50;
|
|
1668
|
+
async function ht(e, s, t) {
|
|
1654
1669
|
const a = t || e;
|
|
1655
|
-
if (W.set(a, [...s]), W.size >
|
|
1670
|
+
if (W.set(a, [...s]), W.size > pt) {
|
|
1656
1671
|
const n = W.keys().next().value;
|
|
1657
1672
|
n && W.delete(n);
|
|
1658
1673
|
}
|
|
@@ -1660,7 +1675,7 @@ async function pt(e, s, t) {
|
|
|
1660
1675
|
try {
|
|
1661
1676
|
const n = {
|
|
1662
1677
|
storageKey: a,
|
|
1663
|
-
messages: s.map(
|
|
1678
|
+
messages: s.map(ft),
|
|
1664
1679
|
lastUpdated: Date.now()
|
|
1665
1680
|
};
|
|
1666
1681
|
sessionStorage.setItem(
|
|
@@ -1675,19 +1690,19 @@ async function pt(e, s, t) {
|
|
|
1675
1690
|
);
|
|
1676
1691
|
}
|
|
1677
1692
|
}
|
|
1678
|
-
async function
|
|
1679
|
-
return t != null && t.odieBotId ?
|
|
1693
|
+
async function yt(e, s, t) {
|
|
1694
|
+
return t != null && t.odieBotId ? It(e, t) : wt(
|
|
1680
1695
|
e,
|
|
1681
1696
|
s
|
|
1682
1697
|
);
|
|
1683
1698
|
}
|
|
1684
|
-
async function
|
|
1699
|
+
async function It(e, s) {
|
|
1685
1700
|
const { odieBotId: t, authProvider: a } = s;
|
|
1686
1701
|
if (!t)
|
|
1687
1702
|
throw new Error("odieBotId is required for server storage");
|
|
1688
1703
|
const n = fe;
|
|
1689
1704
|
try {
|
|
1690
|
-
const
|
|
1705
|
+
const o = await le(
|
|
1691
1706
|
e,
|
|
1692
1707
|
{
|
|
1693
1708
|
botId: t,
|
|
@@ -1700,18 +1715,18 @@ async function yt(e, s) {
|
|
|
1700
1715
|
return A(
|
|
1701
1716
|
"Loaded conversation from server: %s (%d messages, page %d/%d)",
|
|
1702
1717
|
e,
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1718
|
+
o.messages.length,
|
|
1719
|
+
o.pagination.currentPage,
|
|
1720
|
+
o.pagination.totalPages
|
|
1706
1721
|
), {
|
|
1707
|
-
messages:
|
|
1708
|
-
pagination:
|
|
1722
|
+
messages: o.messages,
|
|
1723
|
+
pagination: o.pagination
|
|
1709
1724
|
};
|
|
1710
|
-
} catch (
|
|
1711
|
-
throw A("Failed to load conversation from server: %O",
|
|
1725
|
+
} catch (r) {
|
|
1726
|
+
throw A("Failed to load conversation from server: %O", r), r;
|
|
1712
1727
|
}
|
|
1713
1728
|
}
|
|
1714
|
-
async function
|
|
1729
|
+
async function wt(e, s) {
|
|
1715
1730
|
const t = s || e;
|
|
1716
1731
|
if (W.has(t))
|
|
1717
1732
|
return {
|
|
@@ -1724,8 +1739,8 @@ async function It(e, s) {
|
|
|
1724
1739
|
`${me}_${t}`
|
|
1725
1740
|
);
|
|
1726
1741
|
if (a) {
|
|
1727
|
-
const
|
|
1728
|
-
return W.set(t,
|
|
1742
|
+
const r = JSON.parse(a).messages.map(mt);
|
|
1743
|
+
return W.set(t, r), { messages: [...r] };
|
|
1729
1744
|
}
|
|
1730
1745
|
} catch (a) {
|
|
1731
1746
|
A(
|
|
@@ -1736,7 +1751,7 @@ async function It(e, s) {
|
|
|
1736
1751
|
}
|
|
1737
1752
|
return { messages: [] };
|
|
1738
1753
|
}
|
|
1739
|
-
async function
|
|
1754
|
+
async function Tt(e, s) {
|
|
1740
1755
|
const t = s || e;
|
|
1741
1756
|
if (W.delete(t), !(typeof sessionStorage > "u"))
|
|
1742
1757
|
try {
|
|
@@ -1789,16 +1804,16 @@ function $e(e) {
|
|
|
1789
1804
|
return s;
|
|
1790
1805
|
}
|
|
1791
1806
|
function Te(e, s = [], t = []) {
|
|
1792
|
-
const a = $e(s), n = t.map((
|
|
1793
|
-
const
|
|
1807
|
+
const a = $e(s), n = t.map((r) => {
|
|
1808
|
+
const o = typeof r == "string" ? r : r.url, c = typeof r == "object" ? r.metadata : void 0, i = (c == null ? void 0 : c.fileType) || "image/jpeg";
|
|
1794
1809
|
return {
|
|
1795
1810
|
type: "file",
|
|
1796
1811
|
file: {
|
|
1797
|
-
name: (
|
|
1812
|
+
name: (c == null ? void 0 : c.fileName) || "image",
|
|
1798
1813
|
mimeType: i,
|
|
1799
|
-
uri:
|
|
1814
|
+
uri: o
|
|
1800
1815
|
},
|
|
1801
|
-
metadata:
|
|
1816
|
+
metadata: c
|
|
1802
1817
|
};
|
|
1803
1818
|
});
|
|
1804
1819
|
return {
|
|
@@ -1818,7 +1833,7 @@ function Te(e, s = [], t = []) {
|
|
|
1818
1833
|
}
|
|
1819
1834
|
};
|
|
1820
1835
|
}
|
|
1821
|
-
function
|
|
1836
|
+
function St(e) {
|
|
1822
1837
|
return e != null && e.parts ? e.parts.filter(
|
|
1823
1838
|
(s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
|
|
1824
1839
|
) : [];
|
|
@@ -1864,7 +1879,7 @@ async function Mt(e) {
|
|
|
1864
1879
|
if (t.parts.some(
|
|
1865
1880
|
(n) => n.type === "data" && "toolCallId" in n.data && "result" in n.data
|
|
1866
1881
|
)) {
|
|
1867
|
-
const n =
|
|
1882
|
+
const n = lt(
|
|
1868
1883
|
t.parts
|
|
1869
1884
|
);
|
|
1870
1885
|
s.push({
|
|
@@ -1875,23 +1890,23 @@ async function Mt(e) {
|
|
|
1875
1890
|
s.push(t);
|
|
1876
1891
|
else
|
|
1877
1892
|
s.push(t);
|
|
1878
|
-
return
|
|
1893
|
+
return it(), s;
|
|
1879
1894
|
}
|
|
1880
|
-
function
|
|
1895
|
+
function vt() {
|
|
1881
1896
|
const e = /* @__PURE__ */ new Map();
|
|
1882
1897
|
async function s(t, a) {
|
|
1883
1898
|
const n = e.get(t);
|
|
1884
1899
|
if (n != null && n.sessionId)
|
|
1885
1900
|
try {
|
|
1886
|
-
await
|
|
1901
|
+
await ht(
|
|
1887
1902
|
n.sessionId,
|
|
1888
1903
|
a,
|
|
1889
1904
|
n.conversationStorageKey
|
|
1890
1905
|
);
|
|
1891
|
-
} catch (
|
|
1906
|
+
} catch (r) {
|
|
1892
1907
|
L(
|
|
1893
1908
|
`Failed to persist conversation history for agent ${t}:`,
|
|
1894
|
-
|
|
1909
|
+
r
|
|
1895
1910
|
);
|
|
1896
1911
|
}
|
|
1897
1912
|
}
|
|
@@ -1899,29 +1914,29 @@ function St() {
|
|
|
1899
1914
|
async createAgent(t, a) {
|
|
1900
1915
|
if (e.has(t))
|
|
1901
1916
|
return e.get(t).client;
|
|
1902
|
-
const n =
|
|
1917
|
+
const n = ct(a), r = a.sessionId || null, o = a.conversationStorageKey, c = a.sessionIdStorageKey, i = {
|
|
1903
1918
|
odieBotId: a.odieBotId,
|
|
1904
1919
|
authProvider: a.authProvider
|
|
1905
1920
|
};
|
|
1906
1921
|
let g = [];
|
|
1907
|
-
if (
|
|
1922
|
+
if (r)
|
|
1908
1923
|
try {
|
|
1909
|
-
g = (await
|
|
1910
|
-
o,
|
|
1924
|
+
g = (await yt(
|
|
1911
1925
|
r,
|
|
1926
|
+
o,
|
|
1912
1927
|
i
|
|
1913
1928
|
)).messages;
|
|
1914
1929
|
} catch (p) {
|
|
1915
1930
|
L(
|
|
1916
|
-
`Failed to load conversation history for agent ${t} with session ${
|
|
1931
|
+
`Failed to load conversation history for agent ${t} with session ${r}:`,
|
|
1917
1932
|
p
|
|
1918
1933
|
);
|
|
1919
1934
|
}
|
|
1920
1935
|
const u = {
|
|
1921
1936
|
client: n,
|
|
1922
|
-
sessionId:
|
|
1923
|
-
conversationStorageKey:
|
|
1924
|
-
sessionIdStorageKey:
|
|
1937
|
+
sessionId: r,
|
|
1938
|
+
conversationStorageKey: o,
|
|
1939
|
+
sessionIdStorageKey: c,
|
|
1925
1940
|
storageConfig: i,
|
|
1926
1941
|
conversationHistory: g,
|
|
1927
1942
|
currentAbortController: null
|
|
@@ -1940,41 +1955,41 @@ function St() {
|
|
|
1940
1955
|
},
|
|
1941
1956
|
async sendMessage(t, a, n = {}) {
|
|
1942
1957
|
var I;
|
|
1943
|
-
const
|
|
1944
|
-
if (!
|
|
1958
|
+
const r = e.get(t);
|
|
1959
|
+
if (!r)
|
|
1945
1960
|
throw new Error(`Agent with key "${t}" not found`);
|
|
1946
|
-
const { withHistory:
|
|
1961
|
+
const { withHistory: o = !0, sessionId: c, ...i } = n, { client: g, conversationHistory: u } = r, p = n.message || Te(
|
|
1947
1962
|
a,
|
|
1948
1963
|
u,
|
|
1949
1964
|
n.imageUrls
|
|
1950
1965
|
), y = await g.sendMessage({
|
|
1951
1966
|
message: p,
|
|
1952
|
-
withHistory:
|
|
1953
|
-
sessionId:
|
|
1967
|
+
withHistory: o,
|
|
1968
|
+
sessionId: c || r.sessionId || void 0,
|
|
1954
1969
|
...i
|
|
1955
1970
|
});
|
|
1956
1971
|
if (y.sessionId) {
|
|
1957
|
-
const
|
|
1958
|
-
|
|
1972
|
+
const M = r.sessionId;
|
|
1973
|
+
r.sessionId = y.sessionId, M && y.sessionId && M !== y.sessionId && r.sessionIdStorageKey && (L(
|
|
1959
1974
|
"Session ID changed from %s to %s, updating localStorage",
|
|
1960
|
-
|
|
1975
|
+
M,
|
|
1961
1976
|
y.sessionId
|
|
1962
1977
|
), ne(
|
|
1963
|
-
|
|
1978
|
+
r.sessionIdStorageKey,
|
|
1964
1979
|
y.sessionId
|
|
1965
1980
|
));
|
|
1966
1981
|
}
|
|
1967
1982
|
let v = null;
|
|
1968
1983
|
if ((I = y.status) != null && I.message) {
|
|
1969
|
-
const
|
|
1970
|
-
(
|
|
1984
|
+
const M = y.status.message.parts.filter(
|
|
1985
|
+
(l) => l.type === "data" && "toolCallId" in l.data && ("arguments" in l.data || "result" in l.data)
|
|
1971
1986
|
), d = y.status.message.parts.filter(
|
|
1972
|
-
(
|
|
1987
|
+
(l) => l.type === "text"
|
|
1973
1988
|
);
|
|
1974
1989
|
v = {
|
|
1975
1990
|
role: "agent",
|
|
1976
1991
|
kind: "message",
|
|
1977
|
-
parts: [...
|
|
1992
|
+
parts: [...M, ...d],
|
|
1978
1993
|
messageId: O(),
|
|
1979
1994
|
metadata: {
|
|
1980
1995
|
timestamp: Date.now()
|
|
@@ -1990,50 +2005,50 @@ function St() {
|
|
|
1990
2005
|
];
|
|
1991
2006
|
let h = f;
|
|
1992
2007
|
if (y.agentMessage) {
|
|
1993
|
-
const
|
|
2008
|
+
const M = G(
|
|
1994
2009
|
y.agentMessage
|
|
1995
2010
|
);
|
|
1996
2011
|
h = [
|
|
1997
2012
|
...f,
|
|
1998
|
-
|
|
2013
|
+
M
|
|
1999
2014
|
];
|
|
2000
2015
|
}
|
|
2001
|
-
return
|
|
2016
|
+
return r.conversationHistory = h, o && await s(
|
|
2002
2017
|
t,
|
|
2003
2018
|
h
|
|
2004
2019
|
), y;
|
|
2005
2020
|
},
|
|
2006
2021
|
async *sendMessageStream(t, a, n = {}) {
|
|
2007
2022
|
var w, T, b, E, $, U;
|
|
2008
|
-
const
|
|
2009
|
-
if (!
|
|
2023
|
+
const r = e.get(t);
|
|
2024
|
+
if (!r)
|
|
2010
2025
|
throw new Error(`Agent with key "${t}" not found`);
|
|
2011
2026
|
const {
|
|
2012
|
-
withHistory:
|
|
2013
|
-
abortSignal:
|
|
2027
|
+
withHistory: o = !0,
|
|
2028
|
+
abortSignal: c,
|
|
2014
2029
|
metadata: i,
|
|
2015
2030
|
sessionId: g,
|
|
2016
2031
|
message: u,
|
|
2017
2032
|
...p
|
|
2018
|
-
} = n, { client: y } =
|
|
2019
|
-
|
|
2033
|
+
} = n, { client: y } = r, v = i ? (({ contentType: m, ...C }) => C)(i) : void 0, f = new AbortController();
|
|
2034
|
+
r.currentAbortController = f, c && c.addEventListener(
|
|
2020
2035
|
"abort",
|
|
2021
2036
|
() => f.abort()
|
|
2022
2037
|
);
|
|
2023
2038
|
let h = [
|
|
2024
|
-
...
|
|
2039
|
+
...r.conversationHistory
|
|
2025
2040
|
], I = [];
|
|
2026
|
-
const
|
|
2041
|
+
const M = await Mt(
|
|
2027
2042
|
h
|
|
2028
2043
|
);
|
|
2029
|
-
|
|
2044
|
+
r.conversationHistory = M, h = M, o && await s(
|
|
2030
2045
|
t,
|
|
2031
|
-
|
|
2046
|
+
M
|
|
2032
2047
|
);
|
|
2033
2048
|
let d;
|
|
2034
2049
|
if (u) {
|
|
2035
2050
|
const m = $e(
|
|
2036
|
-
|
|
2051
|
+
M
|
|
2037
2052
|
);
|
|
2038
2053
|
d = {
|
|
2039
2054
|
...u,
|
|
@@ -2042,52 +2057,52 @@ function St() {
|
|
|
2042
2057
|
} else
|
|
2043
2058
|
d = Te(
|
|
2044
2059
|
a,
|
|
2045
|
-
|
|
2060
|
+
M,
|
|
2046
2061
|
n.imageUrls
|
|
2047
2062
|
);
|
|
2048
2063
|
if (n.metadata && !u) {
|
|
2049
|
-
const { contentType: m, ...
|
|
2064
|
+
const { contentType: m, ...C } = n.metadata;
|
|
2050
2065
|
if (m) {
|
|
2051
|
-
const
|
|
2052
|
-
|
|
2053
|
-
...
|
|
2066
|
+
const S = d.parts[d.parts.length - 1];
|
|
2067
|
+
S && S.type === "text" && (S.metadata = {
|
|
2068
|
+
...S.metadata,
|
|
2054
2069
|
contentType: m
|
|
2055
2070
|
});
|
|
2056
2071
|
}
|
|
2057
|
-
Object.keys(
|
|
2072
|
+
Object.keys(C).length > 0 && (d.metadata = {
|
|
2058
2073
|
...d.metadata,
|
|
2059
|
-
...
|
|
2074
|
+
...C
|
|
2060
2075
|
});
|
|
2061
2076
|
}
|
|
2062
|
-
const
|
|
2077
|
+
const l = u || ie(a, n.metadata);
|
|
2063
2078
|
if (n.imageUrls && n.imageUrls.length > 0) {
|
|
2064
2079
|
const m = n.imageUrls.map(
|
|
2065
|
-
(
|
|
2066
|
-
const
|
|
2080
|
+
(C) => {
|
|
2081
|
+
const S = typeof C == "string" ? C : C.url, R = typeof C == "string" ? void 0 : C.metadata, N = (R == null ? void 0 : R.fileType) || "image/jpeg";
|
|
2067
2082
|
return {
|
|
2068
2083
|
type: "file",
|
|
2069
2084
|
file: {
|
|
2070
|
-
name: (
|
|
2085
|
+
name: (R == null ? void 0 : R.fileName) || "image",
|
|
2071
2086
|
mimeType: N,
|
|
2072
|
-
uri:
|
|
2087
|
+
uri: S
|
|
2073
2088
|
},
|
|
2074
|
-
metadata:
|
|
2089
|
+
metadata: R
|
|
2075
2090
|
};
|
|
2076
2091
|
}
|
|
2077
2092
|
);
|
|
2078
|
-
|
|
2093
|
+
l.parts.push(...m);
|
|
2079
2094
|
}
|
|
2080
2095
|
h = [
|
|
2081
2096
|
...h,
|
|
2082
|
-
|
|
2083
|
-
],
|
|
2097
|
+
l
|
|
2098
|
+
], r.conversationHistory = h, o && await s(
|
|
2084
2099
|
t,
|
|
2085
2100
|
h
|
|
2086
2101
|
);
|
|
2087
2102
|
for await (const m of y.sendMessageStream({
|
|
2088
2103
|
message: d,
|
|
2089
|
-
withHistory:
|
|
2090
|
-
sessionId: g ||
|
|
2104
|
+
withHistory: o,
|
|
2105
|
+
sessionId: g || r.sessionId || void 0,
|
|
2091
2106
|
abortSignal: f.signal,
|
|
2092
2107
|
...p,
|
|
2093
2108
|
...v && Object.keys(v).length > 0 && {
|
|
@@ -2095,12 +2110,12 @@ function St() {
|
|
|
2095
2110
|
}
|
|
2096
2111
|
})) {
|
|
2097
2112
|
if (m.sessionId) {
|
|
2098
|
-
const
|
|
2099
|
-
|
|
2113
|
+
const C = r.sessionId;
|
|
2114
|
+
r.sessionId = m.sessionId, m.sessionId && C !== m.sessionId && r.sessionIdStorageKey && (L(
|
|
2100
2115
|
"Session ID %s, updating localStorage",
|
|
2101
|
-
|
|
2116
|
+
C ? `changed from ${C} to ${m.sessionId}` : `received: ${m.sessionId}`
|
|
2102
2117
|
), ne(
|
|
2103
|
-
|
|
2118
|
+
r.sessionIdStorageKey,
|
|
2104
2119
|
m.sessionId
|
|
2105
2120
|
));
|
|
2106
2121
|
}
|
|
@@ -2108,38 +2123,38 @@ function St() {
|
|
|
2108
2123
|
I = B(
|
|
2109
2124
|
m.status.message
|
|
2110
2125
|
).map(
|
|
2111
|
-
(
|
|
2126
|
+
(R) => R.data.toolCallId
|
|
2112
2127
|
);
|
|
2113
|
-
const
|
|
2128
|
+
const S = G(
|
|
2114
2129
|
m.status.message
|
|
2115
2130
|
);
|
|
2116
2131
|
h = [
|
|
2117
2132
|
...h,
|
|
2118
|
-
|
|
2119
|
-
],
|
|
2133
|
+
S
|
|
2134
|
+
], r.conversationHistory = h, o && await s(
|
|
2120
2135
|
t,
|
|
2121
2136
|
h
|
|
2122
2137
|
);
|
|
2123
2138
|
}
|
|
2124
2139
|
if (((b = m.status) == null ? void 0 : b.state) === "working" && ((E = m.status) != null && E.message) && !m.final) {
|
|
2125
|
-
const
|
|
2140
|
+
const S = St(
|
|
2126
2141
|
m.status.message
|
|
2127
2142
|
).filter(
|
|
2128
|
-
(
|
|
2129
|
-
|
|
2143
|
+
(R) => I.includes(
|
|
2144
|
+
R.data.toolCallId
|
|
2130
2145
|
)
|
|
2131
2146
|
);
|
|
2132
|
-
if (
|
|
2133
|
-
const
|
|
2147
|
+
if (S.length > 0) {
|
|
2148
|
+
const R = {
|
|
2134
2149
|
role: "agent",
|
|
2135
2150
|
kind: "message",
|
|
2136
|
-
parts:
|
|
2151
|
+
parts: S,
|
|
2137
2152
|
messageId: O()
|
|
2138
2153
|
};
|
|
2139
2154
|
h = [
|
|
2140
2155
|
...h,
|
|
2141
|
-
G(
|
|
2142
|
-
],
|
|
2156
|
+
G(R)
|
|
2157
|
+
], r.conversationHistory = h, o && await s(
|
|
2143
2158
|
t,
|
|
2144
2159
|
h
|
|
2145
2160
|
);
|
|
@@ -2147,20 +2162,20 @@ function St() {
|
|
|
2147
2162
|
}
|
|
2148
2163
|
if (m.final && (($ = m.status) == null ? void 0 : $.state) !== "input-required") {
|
|
2149
2164
|
I = [];
|
|
2150
|
-
let
|
|
2151
|
-
(U = m.status) != null && U.message && (
|
|
2165
|
+
let C = null;
|
|
2166
|
+
(U = m.status) != null && U.message && (C = G(
|
|
2152
2167
|
m.status.message
|
|
2153
2168
|
), h = [
|
|
2154
2169
|
...h,
|
|
2155
|
-
|
|
2156
|
-
],
|
|
2170
|
+
C
|
|
2171
|
+
], r.conversationHistory = h, o && await s(
|
|
2157
2172
|
t,
|
|
2158
2173
|
h
|
|
2159
2174
|
));
|
|
2160
2175
|
}
|
|
2161
2176
|
yield m;
|
|
2162
2177
|
}
|
|
2163
|
-
|
|
2178
|
+
r.currentAbortController = null;
|
|
2164
2179
|
},
|
|
2165
2180
|
/**
|
|
2166
2181
|
* Send a tool result for a previously executed tool call.
|
|
@@ -2174,26 +2189,26 @@ function St() {
|
|
|
2174
2189
|
* @param result - The tool result payload
|
|
2175
2190
|
* @param options - Optional send message params
|
|
2176
2191
|
*/
|
|
2177
|
-
async *sendToolResult(t, a, n,
|
|
2178
|
-
const
|
|
2179
|
-
if (!
|
|
2192
|
+
async *sendToolResult(t, a, n, r, o = {}) {
|
|
2193
|
+
const c = e.get(t);
|
|
2194
|
+
if (!c)
|
|
2180
2195
|
throw new Error(`Agent with key "${t}" not found`);
|
|
2181
2196
|
const i = (g) => {
|
|
2182
2197
|
var u;
|
|
2183
2198
|
return g.type === "data" && ((u = g.data) == null ? void 0 : u.toolCallId) === a && "result" in g.data;
|
|
2184
2199
|
};
|
|
2185
|
-
|
|
2200
|
+
c.conversationHistory = c.conversationHistory.map((g) => ({
|
|
2186
2201
|
...g,
|
|
2187
2202
|
parts: g.parts.filter(
|
|
2188
2203
|
(u) => !i(u)
|
|
2189
2204
|
)
|
|
2190
2205
|
})).filter((g) => g.parts.length > 0), yield* this.sendMessageStream(t, "", {
|
|
2191
|
-
...
|
|
2206
|
+
...o,
|
|
2192
2207
|
message: {
|
|
2193
2208
|
role: "user",
|
|
2194
2209
|
kind: "message",
|
|
2195
2210
|
parts: [
|
|
2196
|
-
|
|
2211
|
+
j(a, n, r)
|
|
2197
2212
|
],
|
|
2198
2213
|
messageId: O()
|
|
2199
2214
|
}
|
|
@@ -2203,7 +2218,7 @@ function St() {
|
|
|
2203
2218
|
const a = e.get(t);
|
|
2204
2219
|
if (!a)
|
|
2205
2220
|
throw new Error(`Agent with key "${t}" not found`);
|
|
2206
|
-
a.conversationHistory = [], a.sessionId && await
|
|
2221
|
+
a.conversationHistory = [], a.sessionId && await Tt(
|
|
2207
2222
|
a.sessionId,
|
|
2208
2223
|
a.conversationStorageKey
|
|
2209
2224
|
);
|
|
@@ -2240,27 +2255,27 @@ function St() {
|
|
|
2240
2255
|
}
|
|
2241
2256
|
};
|
|
2242
2257
|
}
|
|
2243
|
-
const
|
|
2258
|
+
const At = vt();
|
|
2244
2259
|
function X() {
|
|
2245
|
-
return
|
|
2260
|
+
return At;
|
|
2246
2261
|
}
|
|
2247
|
-
function
|
|
2262
|
+
function Ct() {
|
|
2248
2263
|
const [e, s] = ve([]), t = H(
|
|
2249
|
-
(
|
|
2250
|
-
s((
|
|
2251
|
-
const
|
|
2252
|
-
(i) => i.id ===
|
|
2264
|
+
(r) => {
|
|
2265
|
+
s((o) => {
|
|
2266
|
+
const c = o.findIndex(
|
|
2267
|
+
(i) => i.id === r.id
|
|
2253
2268
|
);
|
|
2254
|
-
if (
|
|
2255
|
-
const i = [...
|
|
2256
|
-
return i[
|
|
2269
|
+
if (c >= 0) {
|
|
2270
|
+
const i = [...o];
|
|
2271
|
+
return i[c] = r, i;
|
|
2257
2272
|
}
|
|
2258
|
-
return [...
|
|
2273
|
+
return [...o, r];
|
|
2259
2274
|
});
|
|
2260
2275
|
},
|
|
2261
2276
|
[]
|
|
2262
|
-
), a = H((
|
|
2263
|
-
s((
|
|
2277
|
+
), a = H((r) => {
|
|
2278
|
+
s((o) => o.filter((c) => c.id !== r));
|
|
2264
2279
|
}, []), n = H(() => {
|
|
2265
2280
|
s([]);
|
|
2266
2281
|
}, []);
|
|
@@ -2289,11 +2304,11 @@ function xt(e, s) {
|
|
|
2289
2304
|
pressed: n.pressed,
|
|
2290
2305
|
showLabel: n.showLabel,
|
|
2291
2306
|
order: n.order
|
|
2292
|
-
}).sort((n,
|
|
2307
|
+
}).sort((n, r) => (n.order ?? 1 / 0) - (r.order ?? 1 / 0));
|
|
2293
2308
|
}
|
|
2294
|
-
const
|
|
2309
|
+
const oe = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ue = (e, s = "40%") => ({
|
|
2295
2310
|
type: "component",
|
|
2296
|
-
component: () =>
|
|
2311
|
+
component: () => De.createElement("img", {
|
|
2297
2312
|
src: e,
|
|
2298
2313
|
alt: "Uploaded image",
|
|
2299
2314
|
style: {
|
|
@@ -2305,8 +2320,8 @@ const re = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ue = (e, s =
|
|
|
2305
2320
|
display: "inline-block"
|
|
2306
2321
|
}
|
|
2307
2322
|
})
|
|
2308
|
-
}),
|
|
2309
|
-
var
|
|
2323
|
+
}), re = (e, s = []) => {
|
|
2324
|
+
var o, c;
|
|
2310
2325
|
if (e.parts.some((i) => {
|
|
2311
2326
|
if (i.type === "data") {
|
|
2312
2327
|
const g = i.data;
|
|
@@ -2348,26 +2363,26 @@ const re = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ue = (e, s =
|
|
|
2348
2363
|
type: "text",
|
|
2349
2364
|
text: "[Unsupported content]"
|
|
2350
2365
|
};
|
|
2351
|
-
}), n = ((
|
|
2366
|
+
}), n = ((o = e.metadata) == null ? void 0 : o.timestamp) ?? Date.now(), r = {
|
|
2352
2367
|
id: e.messageId,
|
|
2353
2368
|
role: e.role === "agent" ? "agent" : "user",
|
|
2354
2369
|
content: a,
|
|
2355
2370
|
timestamp: n,
|
|
2356
|
-
archived: !!((
|
|
2371
|
+
archived: !!((c = e.metadata) != null && c.archived),
|
|
2357
2372
|
showIcon: e.role === "agent",
|
|
2358
2373
|
icon: e.role === "agent" ? "assistant" : void 0
|
|
2359
2374
|
};
|
|
2360
2375
|
if (e.role === "agent" && s.length > 0) {
|
|
2361
2376
|
const i = xt(
|
|
2362
|
-
|
|
2377
|
+
r,
|
|
2363
2378
|
s
|
|
2364
2379
|
);
|
|
2365
|
-
i.length > 0 && (
|
|
2380
|
+
i.length > 0 && (r.actions = i);
|
|
2366
2381
|
}
|
|
2367
|
-
return
|
|
2368
|
-
},
|
|
2382
|
+
return r;
|
|
2383
|
+
}, bt = () => ({
|
|
2369
2384
|
getClientContext: () => ({})
|
|
2370
|
-
}),
|
|
2385
|
+
}), kt = () => ({
|
|
2371
2386
|
getAvailableTools: async () => [],
|
|
2372
2387
|
executeTool: async () => ({
|
|
2373
2388
|
success: !0,
|
|
@@ -2377,7 +2392,7 @@ const re = (e) => [...e].sort((s, t) => s.timestamp - t.timestamp), Ue = (e, s =
|
|
|
2377
2392
|
const a = e[t];
|
|
2378
2393
|
return typeof a == "string" && a.trim().length > 0;
|
|
2379
2394
|
});
|
|
2380
|
-
function
|
|
2395
|
+
function Vt(e) {
|
|
2381
2396
|
const s = {
|
|
2382
2397
|
agentId: e.agentId,
|
|
2383
2398
|
agentUrl: e.agentUrl,
|
|
@@ -2392,18 +2407,18 @@ function Wt(e) {
|
|
|
2392
2407
|
progressMessage: null,
|
|
2393
2408
|
progressPhase: null
|
|
2394
2409
|
}), {
|
|
2395
|
-
registerMessageActions:
|
|
2396
|
-
unregisterMessageActions:
|
|
2397
|
-
clearAllMessageActions:
|
|
2410
|
+
registerMessageActions: r,
|
|
2411
|
+
unregisterMessageActions: o,
|
|
2412
|
+
clearAllMessageActions: c,
|
|
2398
2413
|
registrations: i
|
|
2399
|
-
} =
|
|
2414
|
+
} = Ct(), g = pe(!1), u = pe(i);
|
|
2400
2415
|
se(() => {
|
|
2401
2416
|
u.current = i;
|
|
2402
2417
|
}, [i]);
|
|
2403
2418
|
const p = H(
|
|
2404
2419
|
(d) => d.map(
|
|
2405
|
-
(
|
|
2406
|
-
).filter((
|
|
2420
|
+
(l) => re(l, u.current)
|
|
2421
|
+
).filter((l) => l !== null),
|
|
2407
2422
|
[]
|
|
2408
2423
|
// registrationsRef is stable, so no deps needed
|
|
2409
2424
|
);
|
|
@@ -2411,30 +2426,31 @@ function Wt(e) {
|
|
|
2411
2426
|
if (!t)
|
|
2412
2427
|
return;
|
|
2413
2428
|
(async () => {
|
|
2414
|
-
const
|
|
2415
|
-
if (
|
|
2416
|
-
s.sessionId ? (
|
|
2429
|
+
const l = X(), w = s.agentId;
|
|
2430
|
+
if (l.hasAgent(w))
|
|
2431
|
+
s.sessionId ? (l.updateSessionId(w, s.sessionId), l.getConversationHistory(w).length === 0 && n((E) => ({
|
|
2417
2432
|
...E,
|
|
2418
2433
|
clientMessages: [],
|
|
2419
2434
|
uiMessages: []
|
|
2420
|
-
}))) : (
|
|
2435
|
+
}))) : (l.updateSessionId(w, ""), await l.replaceMessages(w, []), n((b) => ({
|
|
2421
2436
|
...b,
|
|
2422
2437
|
clientMessages: [],
|
|
2423
2438
|
uiMessages: []
|
|
2424
2439
|
})));
|
|
2425
|
-
else if (await
|
|
2440
|
+
else if (await l.createAgent(w, {
|
|
2426
2441
|
agentId: s.agentId,
|
|
2427
2442
|
agentUrl: s.agentUrl,
|
|
2428
2443
|
sessionId: s.sessionId,
|
|
2429
2444
|
// Can be empty for new chats
|
|
2430
2445
|
sessionIdStorageKey: s.sessionIdStorageKey,
|
|
2431
|
-
contextProvider: e.contextProvider ||
|
|
2432
|
-
toolProvider: e.toolProvider ||
|
|
2446
|
+
contextProvider: e.contextProvider || bt(),
|
|
2447
|
+
toolProvider: e.toolProvider || kt(),
|
|
2433
2448
|
authProvider: e.authProvider,
|
|
2434
2449
|
enableStreaming: e.enableStreaming,
|
|
2435
|
-
odieBotId: e.odieBotId
|
|
2450
|
+
odieBotId: e.odieBotId,
|
|
2451
|
+
credentials: e.credentials
|
|
2436
2452
|
}), s.sessionId) {
|
|
2437
|
-
const b =
|
|
2453
|
+
const b = l.getConversationHistory(w);
|
|
2438
2454
|
n((E) => {
|
|
2439
2455
|
const $ = p(b);
|
|
2440
2456
|
return {
|
|
@@ -2460,18 +2476,19 @@ function Wt(e) {
|
|
|
2460
2476
|
e.authProvider,
|
|
2461
2477
|
e.enableStreaming,
|
|
2462
2478
|
e.odieBotId,
|
|
2479
|
+
e.credentials,
|
|
2463
2480
|
t
|
|
2464
2481
|
]);
|
|
2465
2482
|
const y = H(
|
|
2466
|
-
async (d,
|
|
2483
|
+
async (d, l) => {
|
|
2467
2484
|
var $, U;
|
|
2468
2485
|
if (!t)
|
|
2469
2486
|
throw new Error("Invalid agent configuration");
|
|
2470
2487
|
if (g.current)
|
|
2471
2488
|
return;
|
|
2472
2489
|
g.current = !0;
|
|
2473
|
-
const w = (
|
|
2474
|
-
if (w && (!(
|
|
2490
|
+
const w = (l == null ? void 0 : l.type) === "tool_result";
|
|
2491
|
+
if (w && (!(l != null && l.toolCallId) || !(l != null && l.toolId)))
|
|
2475
2492
|
throw new Error(
|
|
2476
2493
|
"`toolCallId` and `toolId` are required when type is `tool_result`"
|
|
2477
2494
|
);
|
|
@@ -2483,62 +2500,62 @@ function Wt(e) {
|
|
|
2483
2500
|
error: null
|
|
2484
2501
|
}));
|
|
2485
2502
|
else {
|
|
2486
|
-
const m = (
|
|
2503
|
+
const m = (l == null ? void 0 : l.type) || "text", C = {
|
|
2487
2504
|
id: `user-${E}`,
|
|
2488
2505
|
role: "user",
|
|
2489
2506
|
content: [
|
|
2490
2507
|
{ type: m, text: d },
|
|
2491
2508
|
// Map image URLs to component content parts
|
|
2492
|
-
...(($ =
|
|
2493
|
-
const
|
|
2494
|
-
return Ue(
|
|
2509
|
+
...(($ = l == null ? void 0 : l.imageUrls) == null ? void 0 : $.map((S) => {
|
|
2510
|
+
const R = typeof S == "string" ? S : S.url;
|
|
2511
|
+
return Ue(R);
|
|
2495
2512
|
})) ?? []
|
|
2496
2513
|
],
|
|
2497
2514
|
timestamp: E,
|
|
2498
|
-
archived: (
|
|
2515
|
+
archived: (l == null ? void 0 : l.archived) ?? !1,
|
|
2499
2516
|
showIcon: !1
|
|
2500
2517
|
};
|
|
2501
|
-
n((
|
|
2502
|
-
...
|
|
2503
|
-
uiMessages: [...
|
|
2518
|
+
n((S) => ({
|
|
2519
|
+
...S,
|
|
2520
|
+
uiMessages: [...S.uiMessages, C],
|
|
2504
2521
|
isProcessing: !0,
|
|
2505
2522
|
error: null
|
|
2506
2523
|
}));
|
|
2507
2524
|
}
|
|
2508
2525
|
try {
|
|
2509
|
-
let m = null,
|
|
2510
|
-
const
|
|
2511
|
-
(
|
|
2512
|
-
...(
|
|
2513
|
-
...
|
|
2514
|
-
}),
|
|
2526
|
+
let m = null, C = !1;
|
|
2527
|
+
const S = {}, R = !!(l != null && l.type) && !w;
|
|
2528
|
+
(l != null && l.archived || R) && (S.metadata = {
|
|
2529
|
+
...(l == null ? void 0 : l.archived) && { archived: !0 },
|
|
2530
|
+
...R && { contentType: l.type }
|
|
2531
|
+
}), l != null && l.sessionId && (S.sessionId = l.sessionId), l != null && l.imageUrls && (S.imageUrls = l.imageUrls);
|
|
2515
2532
|
const N = w ? T.sendToolResult(
|
|
2516
2533
|
b,
|
|
2517
|
-
|
|
2518
|
-
|
|
2534
|
+
l.toolCallId,
|
|
2535
|
+
l.toolId,
|
|
2519
2536
|
{ success: !0, message: d },
|
|
2520
|
-
|
|
2537
|
+
S
|
|
2521
2538
|
) : T.sendMessageStream(
|
|
2522
2539
|
b,
|
|
2523
2540
|
d,
|
|
2524
|
-
|
|
2541
|
+
S
|
|
2525
2542
|
);
|
|
2526
|
-
for await (const
|
|
2527
|
-
if ((
|
|
2528
|
-
...
|
|
2529
|
-
progressMessage:
|
|
2530
|
-
progressPhase:
|
|
2531
|
-
})), !
|
|
2543
|
+
for await (const k of N) {
|
|
2544
|
+
if ((k.progressMessage || k.progressPhase) && n((x) => ({
|
|
2545
|
+
...x,
|
|
2546
|
+
progressMessage: k.progressMessage || null,
|
|
2547
|
+
progressPhase: k.progressPhase || null
|
|
2548
|
+
})), !k.final && k.text)
|
|
2532
2549
|
if (m)
|
|
2533
|
-
n((
|
|
2534
|
-
...
|
|
2535
|
-
uiMessages:
|
|
2550
|
+
n((x) => ({
|
|
2551
|
+
...x,
|
|
2552
|
+
uiMessages: x.uiMessages.map(
|
|
2536
2553
|
(P) => P.id === m ? {
|
|
2537
2554
|
...P,
|
|
2538
2555
|
content: [
|
|
2539
2556
|
{
|
|
2540
2557
|
type: "text",
|
|
2541
|
-
text:
|
|
2558
|
+
text: k.text
|
|
2542
2559
|
}
|
|
2543
2560
|
]
|
|
2544
2561
|
} : P
|
|
@@ -2546,11 +2563,11 @@ function Wt(e) {
|
|
|
2546
2563
|
}));
|
|
2547
2564
|
else {
|
|
2548
2565
|
m = `agent-streaming-${Date.now()}`;
|
|
2549
|
-
const
|
|
2566
|
+
const x = {
|
|
2550
2567
|
id: m,
|
|
2551
2568
|
role: "agent",
|
|
2552
2569
|
content: [
|
|
2553
|
-
{ type: "text", text:
|
|
2570
|
+
{ type: "text", text: k.text }
|
|
2554
2571
|
],
|
|
2555
2572
|
timestamp: Date.now(),
|
|
2556
2573
|
archived: !1,
|
|
@@ -2563,25 +2580,25 @@ function Wt(e) {
|
|
|
2563
2580
|
...P,
|
|
2564
2581
|
uiMessages: [
|
|
2565
2582
|
...P.uiMessages,
|
|
2566
|
-
|
|
2583
|
+
x
|
|
2567
2584
|
]
|
|
2568
2585
|
}));
|
|
2569
2586
|
}
|
|
2570
|
-
if (
|
|
2571
|
-
|
|
2572
|
-
const
|
|
2573
|
-
|
|
2587
|
+
if (k.final && ((U = k.status) != null && U.message) && m) {
|
|
2588
|
+
C = !0;
|
|
2589
|
+
const x = m, P = re(
|
|
2590
|
+
k.status.message,
|
|
2574
2591
|
u.current
|
|
2575
2592
|
);
|
|
2576
|
-
P && n((
|
|
2577
|
-
const J =
|
|
2593
|
+
P && n((D) => {
|
|
2594
|
+
const J = D.uiMessages.map(
|
|
2578
2595
|
(q) => {
|
|
2579
2596
|
var _, V;
|
|
2580
|
-
if (q.id ===
|
|
2597
|
+
if (q.id === x) {
|
|
2581
2598
|
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;
|
|
2582
2599
|
return {
|
|
2583
2600
|
...P,
|
|
2584
|
-
reactKey: q.reactKey ||
|
|
2601
|
+
reactKey: q.reactKey || x,
|
|
2585
2602
|
// Keep stable reactKey
|
|
2586
2603
|
content: qe ? P.content : q.content
|
|
2587
2604
|
};
|
|
@@ -2592,7 +2609,7 @@ function Wt(e) {
|
|
|
2592
2609
|
b
|
|
2593
2610
|
);
|
|
2594
2611
|
return {
|
|
2595
|
-
...
|
|
2612
|
+
...D,
|
|
2596
2613
|
clientMessages: K,
|
|
2597
2614
|
uiMessages: J,
|
|
2598
2615
|
isProcessing: !1,
|
|
@@ -2602,31 +2619,31 @@ function Wt(e) {
|
|
|
2602
2619
|
}), m = null;
|
|
2603
2620
|
}
|
|
2604
2621
|
}
|
|
2605
|
-
if (!
|
|
2606
|
-
const
|
|
2607
|
-
n((
|
|
2608
|
-
let P =
|
|
2609
|
-
m && (P =
|
|
2622
|
+
if (!C) {
|
|
2623
|
+
const k = T.getConversationHistory(b);
|
|
2624
|
+
n((x) => {
|
|
2625
|
+
let P = x.uiMessages;
|
|
2626
|
+
m && (P = x.uiMessages.filter(
|
|
2610
2627
|
(_) => _.id !== m
|
|
2611
2628
|
));
|
|
2612
|
-
const
|
|
2613
|
-
(_) =>
|
|
2629
|
+
const D = k.map(
|
|
2630
|
+
(_) => re(
|
|
2614
2631
|
_,
|
|
2615
2632
|
u.current
|
|
2616
2633
|
)
|
|
2617
2634
|
).filter(
|
|
2618
2635
|
(_) => _ !== null
|
|
2619
2636
|
), J = new Set(
|
|
2620
|
-
|
|
2637
|
+
k.map((_) => _.messageId)
|
|
2621
2638
|
), K = P.filter(
|
|
2622
2639
|
(_) => !J.has(_.id) && _.role !== "user"
|
|
2623
|
-
), q =
|
|
2624
|
-
...
|
|
2640
|
+
), q = oe([
|
|
2641
|
+
...D,
|
|
2625
2642
|
...K
|
|
2626
2643
|
]);
|
|
2627
2644
|
return {
|
|
2628
|
-
...
|
|
2629
|
-
clientMessages:
|
|
2645
|
+
...x,
|
|
2646
|
+
clientMessages: k,
|
|
2630
2647
|
uiMessages: q,
|
|
2631
2648
|
isProcessing: !1,
|
|
2632
2649
|
progressMessage: null,
|
|
@@ -2636,8 +2653,8 @@ function Wt(e) {
|
|
|
2636
2653
|
}
|
|
2637
2654
|
} catch (m) {
|
|
2638
2655
|
if (m instanceof Error && m.name === "AbortError") {
|
|
2639
|
-
A("Request was aborted by user"), n((
|
|
2640
|
-
...
|
|
2656
|
+
A("Request was aborted by user"), n((S) => ({
|
|
2657
|
+
...S,
|
|
2641
2658
|
isProcessing: !1,
|
|
2642
2659
|
progressMessage: null,
|
|
2643
2660
|
progressPhase: null,
|
|
@@ -2646,13 +2663,13 @@ function Wt(e) {
|
|
|
2646
2663
|
}));
|
|
2647
2664
|
return;
|
|
2648
2665
|
}
|
|
2649
|
-
const
|
|
2650
|
-
throw n((
|
|
2651
|
-
...
|
|
2666
|
+
const C = m instanceof Error ? m.message : "Failed to send message";
|
|
2667
|
+
throw n((S) => ({
|
|
2668
|
+
...S,
|
|
2652
2669
|
isProcessing: !1,
|
|
2653
2670
|
progressMessage: null,
|
|
2654
2671
|
progressPhase: null,
|
|
2655
|
-
error:
|
|
2672
|
+
error: C
|
|
2656
2673
|
})), m;
|
|
2657
2674
|
} finally {
|
|
2658
2675
|
g.current = !1;
|
|
@@ -2660,13 +2677,13 @@ function Wt(e) {
|
|
|
2660
2677
|
},
|
|
2661
2678
|
[s.agentId, t]
|
|
2662
2679
|
), v = H((d) => {
|
|
2663
|
-
n((
|
|
2664
|
-
...
|
|
2665
|
-
uiMessages:
|
|
2680
|
+
n((l) => ({
|
|
2681
|
+
...l,
|
|
2682
|
+
uiMessages: oe([...l.uiMessages, d])
|
|
2666
2683
|
}));
|
|
2667
2684
|
}, []), f = H((d) => {
|
|
2668
|
-
n((
|
|
2669
|
-
...
|
|
2685
|
+
n((l) => ({
|
|
2686
|
+
...l,
|
|
2670
2687
|
suggestions: d
|
|
2671
2688
|
}));
|
|
2672
2689
|
}, []), h = H(() => {
|
|
@@ -2679,15 +2696,15 @@ function Wt(e) {
|
|
|
2679
2696
|
n((d) => {
|
|
2680
2697
|
if (d.clientMessages.length === 0)
|
|
2681
2698
|
return d;
|
|
2682
|
-
const
|
|
2699
|
+
const l = p(d.clientMessages), w = new Set(
|
|
2683
2700
|
d.clientMessages.map((b) => b.messageId)
|
|
2684
2701
|
), T = d.uiMessages.filter(
|
|
2685
2702
|
(b) => !w.has(b.id) && b.role !== "user"
|
|
2686
2703
|
);
|
|
2687
2704
|
return {
|
|
2688
2705
|
...d,
|
|
2689
|
-
uiMessages:
|
|
2690
|
-
...
|
|
2706
|
+
uiMessages: oe([
|
|
2707
|
+
...l,
|
|
2691
2708
|
...T
|
|
2692
2709
|
])
|
|
2693
2710
|
};
|
|
@@ -2696,14 +2713,14 @@ function Wt(e) {
|
|
|
2696
2713
|
const I = H(() => {
|
|
2697
2714
|
if (!t)
|
|
2698
2715
|
return;
|
|
2699
|
-
const d = X(),
|
|
2700
|
-
d.abortCurrentRequest(
|
|
2701
|
-
}, [s.agentId, t]),
|
|
2716
|
+
const d = X(), l = s.agentId;
|
|
2717
|
+
d.abortCurrentRequest(l);
|
|
2718
|
+
}, [s.agentId, t]), M = H(
|
|
2702
2719
|
async (d) => {
|
|
2703
2720
|
if (!t)
|
|
2704
2721
|
return;
|
|
2705
|
-
const
|
|
2706
|
-
await
|
|
2722
|
+
const l = X(), w = s.agentId;
|
|
2723
|
+
await l.replaceMessages(w, d);
|
|
2707
2724
|
const T = p(d);
|
|
2708
2725
|
n((b) => ({
|
|
2709
2726
|
...b,
|
|
@@ -2726,26 +2743,26 @@ function Wt(e) {
|
|
|
2726
2743
|
registerSuggestions: f,
|
|
2727
2744
|
clearSuggestions: h,
|
|
2728
2745
|
// Message actions methods
|
|
2729
|
-
registerMessageActions:
|
|
2730
|
-
unregisterMessageActions:
|
|
2731
|
-
clearAllMessageActions:
|
|
2746
|
+
registerMessageActions: r,
|
|
2747
|
+
unregisterMessageActions: o,
|
|
2748
|
+
clearAllMessageActions: c,
|
|
2732
2749
|
// Tool integration
|
|
2733
2750
|
addMessage: v,
|
|
2734
2751
|
// Abort control
|
|
2735
2752
|
abortCurrentRequest: I,
|
|
2736
2753
|
// Conversation loading
|
|
2737
|
-
loadMessages:
|
|
2754
|
+
loadMessages: M
|
|
2738
2755
|
};
|
|
2739
2756
|
}
|
|
2740
|
-
var
|
|
2741
|
-
const
|
|
2742
|
-
function
|
|
2757
|
+
var Pt = /* @__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))(Pt || {});
|
|
2758
|
+
const Se = "jetpack-ai-jwt-token", _t = 30 * 60 * 1e3;
|
|
2759
|
+
function Et() {
|
|
2743
2760
|
var t, a, n;
|
|
2744
2761
|
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);
|
|
2745
2762
|
}
|
|
2746
|
-
async function
|
|
2763
|
+
async function Ot(e, s = !0) {
|
|
2747
2764
|
var i, g;
|
|
2748
|
-
const t = localStorage.getItem(
|
|
2765
|
+
const t = localStorage.getItem(Se);
|
|
2749
2766
|
let a;
|
|
2750
2767
|
if (t)
|
|
2751
2768
|
try {
|
|
@@ -2755,16 +2772,16 @@ async function Et(e, s = !0) {
|
|
|
2755
2772
|
}
|
|
2756
2773
|
if (a && (a != null && a.token) && (a != null && a.expire) && (a == null ? void 0 : a.expire) > Date.now() && s)
|
|
2757
2774
|
return a;
|
|
2758
|
-
const n = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce,
|
|
2759
|
-
let
|
|
2775
|
+
const n = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (g = window.Jetpack_Editor_Initial_State) == null ? void 0 : g.wpcomBlogId;
|
|
2776
|
+
let o = {
|
|
2760
2777
|
token: "",
|
|
2761
2778
|
blog_id: ""
|
|
2762
2779
|
};
|
|
2763
2780
|
try {
|
|
2764
|
-
|
|
2765
|
-
path: "/wpcom/v2/sites/" +
|
|
2781
|
+
Et() ? o = await he({
|
|
2782
|
+
path: "/wpcom/v2/sites/" + r + "/jetpack-openai-query/jwt",
|
|
2766
2783
|
method: "POST"
|
|
2767
|
-
}) :
|
|
2784
|
+
}) : o = await he({
|
|
2768
2785
|
path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
|
|
2769
2786
|
credentials: "same-origin",
|
|
2770
2787
|
headers: {
|
|
@@ -2775,33 +2792,33 @@ async function Et(e, s = !0) {
|
|
|
2775
2792
|
} catch (u) {
|
|
2776
2793
|
throw A("Failed to fetch Jetpack token: %O", u), new Error(e(u));
|
|
2777
2794
|
}
|
|
2778
|
-
if (!(
|
|
2795
|
+
if (!(o != null && o.token))
|
|
2779
2796
|
throw new Error(
|
|
2780
2797
|
"Authentication failed. Please ensure Jetpack is properly connected and try again."
|
|
2781
2798
|
);
|
|
2782
|
-
const
|
|
2783
|
-
token:
|
|
2784
|
-
blogId:
|
|
2785
|
-
expire: Date.now() +
|
|
2799
|
+
const c = {
|
|
2800
|
+
token: o.token,
|
|
2801
|
+
blogId: o.blog_id || "",
|
|
2802
|
+
expire: Date.now() + _t
|
|
2786
2803
|
};
|
|
2787
2804
|
try {
|
|
2788
|
-
localStorage.setItem(
|
|
2805
|
+
localStorage.setItem(Se, JSON.stringify(c));
|
|
2789
2806
|
} catch (u) {
|
|
2790
2807
|
A("Error storing token in localStorage: %O", u);
|
|
2791
2808
|
}
|
|
2792
|
-
return
|
|
2809
|
+
return c;
|
|
2793
2810
|
}
|
|
2794
|
-
const
|
|
2811
|
+
const zt = (e) => async () => {
|
|
2795
2812
|
const s = {};
|
|
2796
2813
|
try {
|
|
2797
|
-
const t = await
|
|
2814
|
+
const t = await Ot(e);
|
|
2798
2815
|
t != null && t.token && (s.Authorization = `${t.token}`);
|
|
2799
2816
|
} catch (t) {
|
|
2800
2817
|
throw A("Failed to get Jetpack token for auth: %O", t), t;
|
|
2801
2818
|
}
|
|
2802
2819
|
return s;
|
|
2803
2820
|
};
|
|
2804
|
-
function
|
|
2821
|
+
function Nt(e) {
|
|
2805
2822
|
const s = {
|
|
2806
2823
|
type: "object",
|
|
2807
2824
|
properties: {}
|
|
@@ -2816,17 +2833,17 @@ function Ot(e) {
|
|
|
2816
2833
|
_originalAbility: e
|
|
2817
2834
|
};
|
|
2818
2835
|
}
|
|
2819
|
-
function zt(e) {
|
|
2820
|
-
return e.map(Ot);
|
|
2821
|
-
}
|
|
2822
2836
|
function Gt(e) {
|
|
2837
|
+
return e.map(Nt);
|
|
2838
|
+
}
|
|
2839
|
+
function Qt(e) {
|
|
2823
2840
|
return (e == null ? void 0 : e._source) === "wordpress-ability";
|
|
2824
2841
|
}
|
|
2825
|
-
function
|
|
2842
|
+
function Xt(e, s = "agent", t = "wpcom") {
|
|
2826
2843
|
const a = e.replace(/-/g, "_");
|
|
2827
2844
|
return `${t}-${s}-${a}`;
|
|
2828
2845
|
}
|
|
2829
|
-
function
|
|
2846
|
+
function $t(e) {
|
|
2830
2847
|
const s = e.split("-");
|
|
2831
2848
|
if (s.length < 3)
|
|
2832
2849
|
throw new Error(
|
|
@@ -2837,46 +2854,46 @@ function Nt(e) {
|
|
|
2837
2854
|
throw new Error(
|
|
2838
2855
|
`Invalid Odie bot type: ${a}. Expected one of: agent, workflow, chain`
|
|
2839
2856
|
);
|
|
2840
|
-
const n = a,
|
|
2857
|
+
const n = a, r = s.slice(2).join("-"), o = r.replace(/_/g, "-");
|
|
2841
2858
|
return {
|
|
2842
2859
|
product: t,
|
|
2843
2860
|
type: n,
|
|
2844
|
-
slug:
|
|
2845
|
-
agentId:
|
|
2861
|
+
slug: r,
|
|
2862
|
+
agentId: o
|
|
2846
2863
|
};
|
|
2847
2864
|
}
|
|
2848
|
-
function
|
|
2865
|
+
function Yt(e) {
|
|
2849
2866
|
try {
|
|
2850
|
-
const s =
|
|
2867
|
+
const s = $t(e);
|
|
2851
2868
|
return s.product.length > 0 && ["agent", "workflow", "chain"].includes(s.type) && s.slug.length > 0;
|
|
2852
2869
|
} catch {
|
|
2853
2870
|
return !1;
|
|
2854
2871
|
}
|
|
2855
2872
|
}
|
|
2856
2873
|
export {
|
|
2857
|
-
|
|
2858
|
-
|
|
2859
|
-
|
|
2860
|
-
|
|
2861
|
-
|
|
2862
|
-
|
|
2863
|
-
|
|
2864
|
-
|
|
2874
|
+
Pt as ErrorCodes,
|
|
2875
|
+
Gt as convertAbilitiesToTools,
|
|
2876
|
+
Nt as convertAbilityToTool,
|
|
2877
|
+
Lt as createAbortController,
|
|
2878
|
+
ct as createClient,
|
|
2879
|
+
zt as createJetpackAuthProvider,
|
|
2880
|
+
Xt as createOdieBotId,
|
|
2881
|
+
je as createRequestId,
|
|
2865
2882
|
Je as createTaskId,
|
|
2866
2883
|
ie as createTextMessage,
|
|
2867
2884
|
F as extractTextFromMessage,
|
|
2868
2885
|
B as extractToolCallsFromMessage,
|
|
2869
2886
|
X as getAgentManager,
|
|
2870
|
-
|
|
2871
|
-
|
|
2872
|
-
|
|
2873
|
-
|
|
2887
|
+
Yt as isOdieBotId,
|
|
2888
|
+
Qt as isWordPressAbility,
|
|
2889
|
+
Bt as listConversationsFromServer,
|
|
2890
|
+
Wt as loadAllMessagesFromServer,
|
|
2874
2891
|
le as loadChatFromServer,
|
|
2875
|
-
|
|
2876
|
-
|
|
2877
|
-
|
|
2878
|
-
|
|
2892
|
+
$t as parseOdieBotId,
|
|
2893
|
+
Vt as useAgentChat,
|
|
2894
|
+
Jt as useClientAbilities,
|
|
2895
|
+
Dt as useClientContext,
|
|
2879
2896
|
jt as useClientTools,
|
|
2880
|
-
|
|
2881
|
-
|
|
2897
|
+
Kt as useClientToolsWithAbilities,
|
|
2898
|
+
Ct as useMessageActions
|
|
2882
2899
|
};
|