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