@automattic/agenttic-client 0.1.14 → 0.1.16
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/README.md +78 -1
- package/dist/client/types/index.d.ts +55 -0
- package/dist/client/types/index.d.ts.map +1 -1
- package/dist/index.d.ts +5 -8
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1205 -1649
- package/dist/message-actions/index.d.ts +0 -2
- package/dist/message-actions/index.d.ts.map +1 -1
- package/dist/message-actions/useMessageActions.d.ts.map +1 -1
- package/dist/mocks/MockSalesGraph.d.ts.map +1 -1
- package/dist/mocks.js +672 -50
- package/dist/react/useAgentChat.d.ts +0 -18
- package/dist/react/useAgentChat.d.ts.map +1 -1
- package/dist/react/useClientTools.d.ts +65 -3
- package/dist/react/useClientTools.d.ts.map +1 -1
- package/dist/utils/wordpressAbilities.d.ts +37 -0
- package/dist/utils/wordpressAbilities.d.ts.map +1 -0
- package/package.json +3 -10
- package/dist/BarChart-CeqsqG1F.js +0 -801
- package/dist/BarChart.css +0 -1
- package/dist/markdown-extensions/charts/BarChart.d.ts +0 -16
- package/dist/markdown-extensions/charts/BarChart.d.ts.map +0 -1
- package/dist/markdown-extensions/charts/BaseChart.d.ts +0 -36
- package/dist/markdown-extensions/charts/BaseChart.d.ts.map +0 -1
- package/dist/markdown-extensions/charts/ChartBlock.d.ts +0 -34
- package/dist/markdown-extensions/charts/ChartBlock.d.ts.map +0 -1
- package/dist/markdown-extensions/charts/ChartError.d.ts +0 -17
- package/dist/markdown-extensions/charts/ChartError.d.ts.map +0 -1
- package/dist/markdown-extensions/charts/ChartErrorBoundary.d.ts +0 -30
- package/dist/markdown-extensions/charts/ChartErrorBoundary.d.ts.map +0 -1
- package/dist/markdown-extensions/charts/LineChart.d.ts +0 -14
- package/dist/markdown-extensions/charts/LineChart.d.ts.map +0 -1
- package/dist/markdown-extensions/charts/index.d.ts +0 -294
- package/dist/markdown-extensions/charts/index.d.ts.map +0 -1
- package/dist/markdown-extensions/charts/utils/chartUtils.d.ts +0 -56
- package/dist/markdown-extensions/charts/utils/chartUtils.d.ts.map +0 -1
- package/dist/markdown-extensions/index.d.ts +0 -34
- package/dist/markdown-extensions/index.d.ts.map +0 -1
- package/dist/markdown-extensions/types.d.ts +0 -52
- package/dist/markdown-extensions/types.d.ts.map +0 -1
- package/dist/marked.esm-CXPn2rbO.js +0 -1090
- package/dist/message-actions/factories.d.ts +0 -16
- package/dist/message-actions/factories.d.ts.map +0 -1
- package/dist/parseBlocks-DtWG2dnE.js +0 -34
- package/dist/parseIncompleteMarkdown-Di9Hun9H.js +0 -211
- package/dist/utils/createMessageRenderer.d.ts +0 -27
- package/dist/utils/createMessageRenderer.d.ts.map +0 -1
- package/dist/utils/streaming/parseBlocks.d.ts +0 -26
- package/dist/utils/streaming/parseBlocks.d.ts.map +0 -1
- package/dist/utils/streaming/parseIncompleteMarkdown.d.ts +0 -24
- package/dist/utils/streaming/parseIncompleteMarkdown.d.ts.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,104 +1,192 @@
|
|
|
1
|
-
var
|
|
2
|
-
var
|
|
3
|
-
var
|
|
4
|
-
import
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
import { __ as q, sprintf as ht } from "@wordpress/i18n";
|
|
9
|
-
import { LineChart as Lt } from "@automattic/charts";
|
|
10
|
-
import yt from "@wordpress/api-fetch";
|
|
11
|
-
const O = (t, ...e) => {
|
|
12
|
-
Wt() && console.log(`[agenttic-client] ${t}`, ...e);
|
|
1
|
+
var Rt = Object.defineProperty;
|
|
2
|
+
var kt = (t, s, e) => s in t ? Rt(t, s, { enumerable: !0, configurable: !0, writable: !0, value: e }) : t[s] = e;
|
|
3
|
+
var Z = (t, s, e) => kt(t, typeof s != "symbol" ? s + "" : s, e);
|
|
4
|
+
import { useMemo as G, useCallback as H, useState as ht, useRef as Et, useEffect as tt } from "react";
|
|
5
|
+
import ut from "@wordpress/api-fetch";
|
|
6
|
+
const k = (t, ...s) => {
|
|
7
|
+
Pt() && console.log(`[agenttic-client] ${t}`, ...s);
|
|
13
8
|
};
|
|
14
|
-
function
|
|
9
|
+
function Pt() {
|
|
15
10
|
var t;
|
|
16
11
|
return typeof globalThis < "u" && "window" in globalThis && ((t = globalThis.window) == null ? void 0 : t.DEBUG) === "agenttic-client";
|
|
17
12
|
}
|
|
18
|
-
function
|
|
13
|
+
function yt(t) {
|
|
19
14
|
return JSON.stringify(t, null, 2);
|
|
20
15
|
}
|
|
21
|
-
function
|
|
22
|
-
console.log(`[agenttic-client] ${t}`, ...
|
|
16
|
+
function dt(t, ...s) {
|
|
17
|
+
console.log(`[agenttic-client] ${t}`, ...s);
|
|
23
18
|
}
|
|
24
|
-
function
|
|
25
|
-
return
|
|
19
|
+
function Se(t) {
|
|
20
|
+
return G(() => t ? {
|
|
26
21
|
getClientContext: () => {
|
|
27
22
|
try {
|
|
28
23
|
return t() || {};
|
|
29
24
|
} catch (n) {
|
|
30
|
-
return
|
|
25
|
+
return k("Error getting client context: %O", n), {};
|
|
31
26
|
}
|
|
32
27
|
}
|
|
33
28
|
} : void 0, [t]);
|
|
34
29
|
}
|
|
35
|
-
function
|
|
36
|
-
const s =
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
30
|
+
function Ot(t) {
|
|
31
|
+
const s = {
|
|
32
|
+
type: "object",
|
|
33
|
+
properties: {}
|
|
34
|
+
};
|
|
35
|
+
return {
|
|
36
|
+
id: t.name.replace(/\//g, "-"),
|
|
37
|
+
name: t.label,
|
|
38
|
+
description: t.description,
|
|
39
|
+
input_schema: t.input_schema || s,
|
|
40
|
+
// Store metadata for detection and execution
|
|
41
|
+
_source: "wordpress-ability",
|
|
42
|
+
_originalAbility: t
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
function _t(t) {
|
|
46
|
+
return t.map(Ot);
|
|
47
|
+
}
|
|
48
|
+
function be(t) {
|
|
49
|
+
return (t == null ? void 0 : t._source) === "wordpress-ability";
|
|
50
|
+
}
|
|
51
|
+
function at({
|
|
52
|
+
getClientTools: t,
|
|
53
|
+
executeTool: s,
|
|
54
|
+
abilities: e,
|
|
55
|
+
executeAbility: n
|
|
56
|
+
}) {
|
|
57
|
+
const o = G(() => !e || e.length === 0 ? [] : _t(e), [e]), r = G(() => !e || e.length === 0 ? /* @__PURE__ */ new Map() : new Map(
|
|
58
|
+
e.map((d) => [d.name.replace(/\//g, "-"), d])
|
|
59
|
+
), [e]), a = H(async () => {
|
|
60
|
+
const d = [];
|
|
61
|
+
if (t)
|
|
62
|
+
try {
|
|
63
|
+
const c = await t();
|
|
64
|
+
d.push(...c);
|
|
65
|
+
} catch (c) {
|
|
66
|
+
k("Error getting available tools: %O", c);
|
|
67
|
+
}
|
|
68
|
+
return o.length > 0 && d.push(...o), d;
|
|
69
|
+
}, [t, o]), l = H(
|
|
70
|
+
async (d, c) => {
|
|
71
|
+
const g = r.get(d);
|
|
72
|
+
if (g)
|
|
73
|
+
try {
|
|
74
|
+
const h = await n(g.name, c);
|
|
75
|
+
return k(`Executed Ability: ${g.name}`), {
|
|
76
|
+
result: h,
|
|
77
|
+
returnToAgent: !0
|
|
78
|
+
};
|
|
79
|
+
} catch (h) {
|
|
80
|
+
return k(
|
|
81
|
+
"Error executing ability %s: %O",
|
|
82
|
+
g.name,
|
|
83
|
+
h
|
|
84
|
+
), {
|
|
85
|
+
result: {
|
|
86
|
+
error: h instanceof Error ? h.message : String(h),
|
|
87
|
+
success: !1
|
|
88
|
+
},
|
|
89
|
+
returnToAgent: !0
|
|
90
|
+
};
|
|
91
|
+
}
|
|
92
|
+
if (!s)
|
|
47
93
|
throw new Error("No executeTool callback provided");
|
|
48
94
|
try {
|
|
49
|
-
return await
|
|
50
|
-
} catch (
|
|
51
|
-
throw
|
|
95
|
+
return await s(d, c);
|
|
96
|
+
} catch (h) {
|
|
97
|
+
throw k("Error executing tool %s: %O", d, h), h;
|
|
52
98
|
}
|
|
53
99
|
},
|
|
54
|
-
[
|
|
100
|
+
[s, r, n]
|
|
55
101
|
);
|
|
56
|
-
return
|
|
57
|
-
if (t)
|
|
102
|
+
return G(() => {
|
|
103
|
+
if (!(!t && (!e || e.length === 0)))
|
|
58
104
|
return {
|
|
59
|
-
getAvailableTools:
|
|
60
|
-
executeTool:
|
|
105
|
+
getAvailableTools: a,
|
|
106
|
+
executeTool: l,
|
|
107
|
+
abilities: e
|
|
61
108
|
};
|
|
62
|
-
}, [
|
|
109
|
+
}, [a, l, t, e]);
|
|
110
|
+
}
|
|
111
|
+
function Ae(t, s) {
|
|
112
|
+
return at({
|
|
113
|
+
getClientTools: t,
|
|
114
|
+
executeTool: s,
|
|
115
|
+
abilities: void 0,
|
|
116
|
+
executeAbility: void 0
|
|
117
|
+
});
|
|
118
|
+
}
|
|
119
|
+
function ve(t, s) {
|
|
120
|
+
if (t.length > 0 && !s)
|
|
121
|
+
throw new Error(
|
|
122
|
+
"executeAbility is required when providing abilities. Please provide the executeAbility function from @wordpress/abilities."
|
|
123
|
+
);
|
|
124
|
+
return at({
|
|
125
|
+
getClientTools: void 0,
|
|
126
|
+
executeTool: void 0,
|
|
127
|
+
abilities: t,
|
|
128
|
+
executeAbility: s
|
|
129
|
+
});
|
|
63
130
|
}
|
|
64
|
-
function
|
|
131
|
+
function Re(t) {
|
|
132
|
+
const { getClientTools: s, executeTool: e, abilities: n, executeAbility: o } = t;
|
|
133
|
+
if (!s && (!n || n.length === 0))
|
|
134
|
+
throw new Error(
|
|
135
|
+
"At least one of getClientTools or abilities must be provided to useClientToolsWithAbilities."
|
|
136
|
+
);
|
|
137
|
+
if (s && !e)
|
|
138
|
+
throw new Error(
|
|
139
|
+
"executeTool is required when providing getClientTools."
|
|
140
|
+
);
|
|
141
|
+
if (n && n.length > 0 && !o)
|
|
142
|
+
throw new Error(
|
|
143
|
+
"executeAbility is required when providing abilities. Please provide the executeAbility function from @wordpress/abilities."
|
|
144
|
+
);
|
|
145
|
+
return at({
|
|
146
|
+
getClientTools: s,
|
|
147
|
+
executeTool: e,
|
|
148
|
+
abilities: n,
|
|
149
|
+
executeAbility: o
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
function rt() {
|
|
65
153
|
const t = "abcdefghijklmnopqrstuvwxyz0123456789";
|
|
66
|
-
let
|
|
67
|
-
for (let
|
|
68
|
-
|
|
69
|
-
return
|
|
154
|
+
let s = "";
|
|
155
|
+
for (let e = 0; e < 8; e++)
|
|
156
|
+
s += t.charAt(Math.floor(Math.random() * t.length));
|
|
157
|
+
return s;
|
|
70
158
|
}
|
|
71
|
-
function
|
|
72
|
-
return
|
|
159
|
+
function O() {
|
|
160
|
+
return rt();
|
|
73
161
|
}
|
|
74
|
-
function
|
|
75
|
-
return `req-${
|
|
162
|
+
function Nt() {
|
|
163
|
+
return `req-${rt()}`;
|
|
76
164
|
}
|
|
77
|
-
function
|
|
78
|
-
return `task-${
|
|
165
|
+
function qt() {
|
|
166
|
+
return `task-${rt()}`;
|
|
79
167
|
}
|
|
80
|
-
function
|
|
168
|
+
function wt(t) {
|
|
81
169
|
return {
|
|
82
170
|
type: "text",
|
|
83
171
|
text: t
|
|
84
172
|
};
|
|
85
173
|
}
|
|
86
|
-
function
|
|
174
|
+
function Ht(t, s = "message/send", e = !1) {
|
|
87
175
|
const n = {
|
|
88
176
|
jsonrpc: "2.0",
|
|
89
|
-
id:
|
|
90
|
-
method:
|
|
177
|
+
id: Nt(),
|
|
178
|
+
method: s,
|
|
91
179
|
params: {
|
|
92
|
-
id: t.id ||
|
|
180
|
+
id: t.id || qt(),
|
|
93
181
|
...t
|
|
94
182
|
}
|
|
95
183
|
};
|
|
96
|
-
return
|
|
184
|
+
return e && s === "message/stream" && (n.tokenStreaming = !0), n;
|
|
97
185
|
}
|
|
98
|
-
function
|
|
99
|
-
return !t || !t.parts || !Array.isArray(t.parts) ? "" : t.parts.filter((
|
|
186
|
+
function $(t) {
|
|
187
|
+
return !t || !t.parts || !Array.isArray(t.parts) ? "" : t.parts.filter((s) => s.type === "text").map((s) => s.text).join(" ");
|
|
100
188
|
}
|
|
101
|
-
function
|
|
189
|
+
function $t(t) {
|
|
102
190
|
return {
|
|
103
191
|
type: "data",
|
|
104
192
|
data: {
|
|
@@ -110,23 +198,23 @@ function Gt(t) {
|
|
|
110
198
|
metadata: {}
|
|
111
199
|
};
|
|
112
200
|
}
|
|
113
|
-
function
|
|
201
|
+
function F(t) {
|
|
114
202
|
return !t || !t.parts || !Array.isArray(t.parts) ? [] : t.parts.filter(
|
|
115
|
-
(
|
|
203
|
+
(s) => s.type === "data" && "toolCallId" in s.data && "toolId" in s.data && "arguments" in s.data
|
|
116
204
|
);
|
|
117
205
|
}
|
|
118
|
-
function
|
|
206
|
+
function J(t, s, e, n) {
|
|
119
207
|
return {
|
|
120
208
|
type: "data",
|
|
121
209
|
data: {
|
|
122
210
|
toolCallId: t,
|
|
123
|
-
toolId:
|
|
124
|
-
result:
|
|
211
|
+
toolId: s,
|
|
212
|
+
result: e
|
|
125
213
|
},
|
|
126
214
|
metadata: n ? { error: n } : void 0
|
|
127
215
|
};
|
|
128
216
|
}
|
|
129
|
-
function
|
|
217
|
+
function Dt(t) {
|
|
130
218
|
return {
|
|
131
219
|
type: "data",
|
|
132
220
|
data: {
|
|
@@ -135,29 +223,29 @@ function Qt(t) {
|
|
|
135
223
|
metadata: {}
|
|
136
224
|
};
|
|
137
225
|
}
|
|
138
|
-
function
|
|
226
|
+
function ot(t) {
|
|
139
227
|
return {
|
|
140
228
|
role: "user",
|
|
141
|
-
parts: [
|
|
229
|
+
parts: [wt(t)],
|
|
142
230
|
kind: "message",
|
|
143
|
-
messageId:
|
|
231
|
+
messageId: O(),
|
|
144
232
|
metadata: {
|
|
145
233
|
timestamp: Date.now()
|
|
146
234
|
}
|
|
147
235
|
};
|
|
148
236
|
}
|
|
149
|
-
function
|
|
237
|
+
function L(t) {
|
|
150
238
|
return {
|
|
151
239
|
role: "agent",
|
|
152
|
-
parts: [
|
|
240
|
+
parts: [wt(t)],
|
|
153
241
|
kind: "message",
|
|
154
|
-
messageId:
|
|
242
|
+
messageId: O(),
|
|
155
243
|
metadata: {
|
|
156
244
|
timestamp: Date.now()
|
|
157
245
|
}
|
|
158
246
|
};
|
|
159
247
|
}
|
|
160
|
-
function
|
|
248
|
+
function it(t) {
|
|
161
249
|
return t && typeof t == "object" && "result" in t ? {
|
|
162
250
|
result: t.result,
|
|
163
251
|
returnToAgent: t.returnToAgent !== !1,
|
|
@@ -169,196 +257,196 @@ function ft(t) {
|
|
|
169
257
|
returnToAgent: !0
|
|
170
258
|
};
|
|
171
259
|
}
|
|
172
|
-
function
|
|
260
|
+
function Q(t, s = []) {
|
|
173
261
|
return {
|
|
174
262
|
role: "user",
|
|
175
263
|
kind: "message",
|
|
176
|
-
parts: [...
|
|
177
|
-
messageId:
|
|
264
|
+
parts: [...s, ...t],
|
|
265
|
+
messageId: O(),
|
|
178
266
|
metadata: {
|
|
179
267
|
timestamp: Date.now()
|
|
180
268
|
}
|
|
181
269
|
};
|
|
182
270
|
}
|
|
183
|
-
function
|
|
271
|
+
function ke() {
|
|
184
272
|
return new AbortController();
|
|
185
273
|
}
|
|
186
|
-
async function
|
|
187
|
-
if (!
|
|
274
|
+
async function Ft(t, s) {
|
|
275
|
+
if (!s)
|
|
188
276
|
return t;
|
|
189
277
|
try {
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
278
|
+
const e = await s.getAvailableTools();
|
|
279
|
+
if (e.length === 0)
|
|
192
280
|
return t;
|
|
193
|
-
const n =
|
|
281
|
+
const n = e.map($t);
|
|
194
282
|
return {
|
|
195
283
|
...t,
|
|
196
284
|
parts: [...t.parts, ...n]
|
|
197
285
|
};
|
|
198
|
-
} catch (
|
|
199
|
-
return
|
|
286
|
+
} catch (e) {
|
|
287
|
+
return k("Warning: Failed to get tools: %s", e), t;
|
|
200
288
|
}
|
|
201
289
|
}
|
|
202
|
-
function
|
|
203
|
-
if (!
|
|
290
|
+
function Ut(t, s) {
|
|
291
|
+
if (!s)
|
|
204
292
|
return t;
|
|
205
293
|
try {
|
|
206
|
-
const
|
|
207
|
-
if (!
|
|
294
|
+
const e = s.getClientContext();
|
|
295
|
+
if (!e || Object.keys(e).length === 0)
|
|
208
296
|
return t;
|
|
209
|
-
const n =
|
|
297
|
+
const n = Dt(e);
|
|
210
298
|
return {
|
|
211
299
|
...t,
|
|
212
300
|
parts: [...t.parts, n]
|
|
213
301
|
};
|
|
214
|
-
} catch (
|
|
215
|
-
return
|
|
302
|
+
} catch (e) {
|
|
303
|
+
return k("Warning: Failed to get context: %s", e), t;
|
|
216
304
|
}
|
|
217
305
|
}
|
|
218
|
-
async function
|
|
219
|
-
let n = await
|
|
306
|
+
async function Jt(t, s, e) {
|
|
307
|
+
let n = await Ft(
|
|
220
308
|
t,
|
|
221
|
-
|
|
309
|
+
s
|
|
222
310
|
);
|
|
223
|
-
n =
|
|
311
|
+
n = Ut(
|
|
224
312
|
n,
|
|
225
|
-
|
|
313
|
+
e
|
|
226
314
|
);
|
|
227
|
-
const { metadata:
|
|
228
|
-
return
|
|
229
|
-
}
|
|
230
|
-
function
|
|
231
|
-
const
|
|
232
|
-
let
|
|
233
|
-
for (;
|
|
234
|
-
const
|
|
315
|
+
const { metadata: o, ...r } = n;
|
|
316
|
+
return r;
|
|
317
|
+
}
|
|
318
|
+
function jt(t, s = "") {
|
|
319
|
+
const e = [], n = s + t;
|
|
320
|
+
let o = "", r = 0, a = 0;
|
|
321
|
+
for (; a < n.length; ) {
|
|
322
|
+
const i = n.indexOf(
|
|
235
323
|
`
|
|
236
324
|
`,
|
|
237
|
-
|
|
238
|
-
),
|
|
239
|
-
if (
|
|
240
|
-
|
|
241
|
-
`),
|
|
242
|
-
|
|
325
|
+
a
|
|
326
|
+
), d = i === -1 ? n.substring(a) : n.substring(a, i);
|
|
327
|
+
if (d.startsWith("data:"))
|
|
328
|
+
o !== "" && (o += `
|
|
329
|
+
`), o += d.substring(
|
|
330
|
+
d.startsWith("data: ") ? 6 : 5
|
|
243
331
|
);
|
|
244
|
-
else if (
|
|
332
|
+
else if (d.trim() === "" && o) {
|
|
245
333
|
try {
|
|
246
|
-
|
|
334
|
+
e.push(JSON.parse(o)), r = i === -1 ? n.length : i + 1;
|
|
247
335
|
} catch (c) {
|
|
248
|
-
|
|
336
|
+
k("Failed to parse SSE event: %o", c), k("Problematic payload: %s", o);
|
|
249
337
|
}
|
|
250
|
-
|
|
338
|
+
o = "";
|
|
251
339
|
}
|
|
252
|
-
|
|
340
|
+
i === -1 ? a = n.length : a = i + 1;
|
|
253
341
|
}
|
|
254
|
-
const
|
|
255
|
-
return { events:
|
|
256
|
-
}
|
|
257
|
-
async function*
|
|
258
|
-
var
|
|
259
|
-
const { supportDeltas:
|
|
260
|
-
let
|
|
261
|
-
const
|
|
262
|
-
let
|
|
342
|
+
const l = n.substring(r);
|
|
343
|
+
return { events: e, nextBuffer: l };
|
|
344
|
+
}
|
|
345
|
+
async function* Kt(t, s = {}) {
|
|
346
|
+
var d, c, g;
|
|
347
|
+
const { supportDeltas: e = !1 } = s, n = t.getReader(), o = new TextDecoder();
|
|
348
|
+
let r = "";
|
|
349
|
+
const a = new Lt();
|
|
350
|
+
let l = null, i = null;
|
|
263
351
|
try {
|
|
264
352
|
for (; ; ) {
|
|
265
|
-
const { done:
|
|
266
|
-
if (
|
|
353
|
+
const { done: h, value: T } = await n.read();
|
|
354
|
+
if (h)
|
|
267
355
|
break;
|
|
268
|
-
const
|
|
269
|
-
if (
|
|
270
|
-
for (let y = 0; y <
|
|
271
|
-
const u =
|
|
272
|
-
if (y > 0 && u.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((
|
|
273
|
-
requestAnimationFrame(() =>
|
|
356
|
+
const M = o.decode(T, { stream: !0 }), { events: p, nextBuffer: m } = jt(M, r);
|
|
357
|
+
if (p && Array.isArray(p))
|
|
358
|
+
for (let y = 0; y < p.length; y++) {
|
|
359
|
+
const u = p[y];
|
|
360
|
+
if (y > 0 && u.method === "message/delta" && typeof requestAnimationFrame < "u" && await new Promise((w) => {
|
|
361
|
+
requestAnimationFrame(() => w(void 0));
|
|
274
362
|
}), u.error)
|
|
275
363
|
throw new Error(
|
|
276
364
|
`Streaming error: ${u.error.message}`
|
|
277
365
|
);
|
|
278
|
-
if (
|
|
279
|
-
const
|
|
366
|
+
if (e && u.method === "message/delta" && ((d = u.params) != null && d.delta)) {
|
|
367
|
+
const w = u.params.delta;
|
|
280
368
|
try {
|
|
281
|
-
if (
|
|
282
|
-
|
|
283
|
-
), !
|
|
284
|
-
const
|
|
369
|
+
if (w.deltaType === "content" && (a.processContentDelta(
|
|
370
|
+
w.content
|
|
371
|
+
), !l && u.params.id && (l = u.params.id), l)) {
|
|
372
|
+
const S = a.getCurrentMessage();
|
|
285
373
|
yield {
|
|
286
|
-
id:
|
|
374
|
+
id: l,
|
|
287
375
|
status: {
|
|
288
376
|
state: "working",
|
|
289
|
-
message:
|
|
377
|
+
message: S
|
|
290
378
|
},
|
|
291
379
|
final: !1,
|
|
292
|
-
text:
|
|
380
|
+
text: a.getTextContent()
|
|
293
381
|
};
|
|
294
382
|
}
|
|
295
|
-
} catch (
|
|
296
|
-
|
|
383
|
+
} catch (S) {
|
|
384
|
+
k("Failed to process delta: %o", S);
|
|
297
385
|
}
|
|
298
|
-
} else u.result && u.result.status ? (
|
|
386
|
+
} else u.result && u.result.status ? (l = u.result.id, i = u.result.status, (a.getTextContent() || a.getCurrentMessage().parts.length > 0) && a.reset(), yield {
|
|
299
387
|
id: u.result.id,
|
|
300
388
|
status: u.result.status,
|
|
301
389
|
final: u.result.status.state === "completed" || u.result.status.state === "failed" || u.result.status.state === "canceled",
|
|
302
|
-
text:
|
|
390
|
+
text: $(
|
|
303
391
|
((c = u.result.status) == null ? void 0 : c.message) || {
|
|
304
392
|
role: "agent",
|
|
305
393
|
parts: []
|
|
306
394
|
}
|
|
307
395
|
)
|
|
308
|
-
}) : u.id && u.result && (
|
|
396
|
+
}) : u.id && u.result && (l = u.result.id, u.result.status && (yield {
|
|
309
397
|
id: u.result.id,
|
|
310
398
|
status: u.result.status,
|
|
311
399
|
final: u.result.status.state === "completed" || u.result.status.state === "failed" || u.result.status.state === "canceled",
|
|
312
|
-
text:
|
|
313
|
-
((
|
|
400
|
+
text: $(
|
|
401
|
+
((g = u.result.status) == null ? void 0 : g.message) || {
|
|
314
402
|
role: "agent",
|
|
315
403
|
parts: []
|
|
316
404
|
}
|
|
317
405
|
)
|
|
318
406
|
}));
|
|
319
407
|
}
|
|
320
|
-
|
|
408
|
+
r = m;
|
|
321
409
|
}
|
|
322
410
|
} finally {
|
|
323
411
|
n.releaseLock();
|
|
324
412
|
}
|
|
325
413
|
}
|
|
326
|
-
class
|
|
414
|
+
class Lt {
|
|
327
415
|
constructor() {
|
|
328
|
-
|
|
329
|
-
|
|
416
|
+
Z(this, "textContent", "");
|
|
417
|
+
Z(this, "toolCalls", /* @__PURE__ */ new Map());
|
|
330
418
|
}
|
|
331
419
|
/**
|
|
332
420
|
* Process a simple content delta (server's actual format)
|
|
333
421
|
* @param content - The text content to append
|
|
334
422
|
*/
|
|
335
|
-
processContentDelta(
|
|
336
|
-
this.textContent +=
|
|
423
|
+
processContentDelta(s) {
|
|
424
|
+
this.textContent += s;
|
|
337
425
|
}
|
|
338
426
|
/**
|
|
339
427
|
* Process a delta message and accumulate the content (original format)
|
|
340
428
|
* @param delta - The delta message to process
|
|
341
429
|
*/
|
|
342
|
-
processDelta(
|
|
343
|
-
switch (
|
|
430
|
+
processDelta(s) {
|
|
431
|
+
switch (s.type) {
|
|
344
432
|
case "content":
|
|
345
|
-
this.textContent +=
|
|
433
|
+
this.textContent += s.content;
|
|
346
434
|
break;
|
|
347
435
|
case "tool_name":
|
|
348
|
-
this.toolCalls.has(
|
|
349
|
-
toolCallId:
|
|
436
|
+
this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
|
|
437
|
+
toolCallId: s.toolCallId,
|
|
350
438
|
toolName: "",
|
|
351
439
|
argumentFragments: []
|
|
352
440
|
});
|
|
353
|
-
const
|
|
354
|
-
|
|
441
|
+
const e = this.toolCalls.get(s.toolCallIndex);
|
|
442
|
+
e.toolName += s.content;
|
|
355
443
|
break;
|
|
356
444
|
case "tool_argument":
|
|
357
|
-
this.toolCalls.has(
|
|
358
|
-
toolCallId:
|
|
445
|
+
this.toolCalls.has(s.toolCallIndex) || this.toolCalls.set(s.toolCallIndex, {
|
|
446
|
+
toolCallId: s.toolCallId,
|
|
359
447
|
toolName: "",
|
|
360
448
|
argumentFragments: []
|
|
361
|
-
}), this.toolCalls.get(
|
|
449
|
+
}), this.toolCalls.get(s.toolCallIndex).argumentFragments.push(s.content);
|
|
362
450
|
break;
|
|
363
451
|
}
|
|
364
452
|
}
|
|
@@ -372,36 +460,36 @@ class se {
|
|
|
372
460
|
* Get the current accumulated message
|
|
373
461
|
* @param role - The role for the message (default: 'agent')
|
|
374
462
|
*/
|
|
375
|
-
getCurrentMessage(
|
|
376
|
-
const
|
|
377
|
-
this.textContent &&
|
|
463
|
+
getCurrentMessage(s = "agent") {
|
|
464
|
+
const e = [];
|
|
465
|
+
this.textContent && e.push({
|
|
378
466
|
type: "text",
|
|
379
467
|
text: this.textContent
|
|
380
468
|
});
|
|
381
|
-
for (const [n,
|
|
382
|
-
if (
|
|
383
|
-
const
|
|
384
|
-
let
|
|
385
|
-
if (
|
|
469
|
+
for (const [n, o] of this.toolCalls)
|
|
470
|
+
if (o.toolName) {
|
|
471
|
+
const r = o.argumentFragments.join("");
|
|
472
|
+
let a = {};
|
|
473
|
+
if (r)
|
|
386
474
|
try {
|
|
387
|
-
|
|
475
|
+
a = JSON.parse(r);
|
|
388
476
|
} catch {
|
|
389
|
-
|
|
477
|
+
a = { _raw: r };
|
|
390
478
|
}
|
|
391
|
-
|
|
479
|
+
e.push({
|
|
392
480
|
type: "data",
|
|
393
481
|
data: {
|
|
394
|
-
toolCallId:
|
|
395
|
-
toolId:
|
|
396
|
-
arguments:
|
|
482
|
+
toolCallId: o.toolCallId,
|
|
483
|
+
toolId: o.toolName,
|
|
484
|
+
arguments: a
|
|
397
485
|
}
|
|
398
486
|
});
|
|
399
487
|
}
|
|
400
488
|
return {
|
|
401
|
-
role:
|
|
402
|
-
parts:
|
|
489
|
+
role: s,
|
|
490
|
+
parts: e,
|
|
403
491
|
kind: "message",
|
|
404
|
-
messageId:
|
|
492
|
+
messageId: O()
|
|
405
493
|
};
|
|
406
494
|
}
|
|
407
495
|
/**
|
|
@@ -411,154 +499,154 @@ class se {
|
|
|
411
499
|
this.textContent = "", this.toolCalls.clear();
|
|
412
500
|
}
|
|
413
501
|
}
|
|
414
|
-
function
|
|
415
|
-
throw clearTimeout(
|
|
502
|
+
function It(t, s, e = "request") {
|
|
503
|
+
throw clearTimeout(s), k("%s failed with error: %O", e, t), t instanceof Error && (k("Error message: %s", t.message), k("Error stack: %s", t.stack)), t;
|
|
416
504
|
}
|
|
417
|
-
function
|
|
505
|
+
function Tt(t, s = "request") {
|
|
418
506
|
if (!t.ok)
|
|
419
507
|
throw new Error(`HTTP error! status: ${t.status}`);
|
|
420
508
|
}
|
|
421
|
-
function
|
|
509
|
+
function Wt(t, s = "request") {
|
|
422
510
|
if (t.error)
|
|
423
|
-
throw new Error(`A2A ${
|
|
511
|
+
throw new Error(`A2A ${s} error: ${t.error.message}`);
|
|
424
512
|
if (!t.result)
|
|
425
|
-
throw new Error(`No result in ${
|
|
513
|
+
throw new Error(`No result in ${s} response`);
|
|
426
514
|
return t.result;
|
|
427
515
|
}
|
|
428
|
-
function
|
|
429
|
-
if (
|
|
430
|
-
throw new Error(`No response body for ${
|
|
516
|
+
function Vt(t, s = "streaming request") {
|
|
517
|
+
if (Tt(t, s), !t.body)
|
|
518
|
+
throw new Error(`No response body for ${s}`);
|
|
431
519
|
}
|
|
432
|
-
function
|
|
433
|
-
const
|
|
520
|
+
function Ct(t, s = "request") {
|
|
521
|
+
const e = new AbortController();
|
|
434
522
|
return { timeoutId: setTimeout(
|
|
435
|
-
() =>
|
|
523
|
+
() => e.abort(),
|
|
436
524
|
t
|
|
437
|
-
), controller:
|
|
525
|
+
), controller: e };
|
|
438
526
|
}
|
|
439
|
-
function
|
|
440
|
-
return `${t}/${
|
|
527
|
+
function Bt(t, s) {
|
|
528
|
+
return `${t}/${s}`;
|
|
441
529
|
}
|
|
442
|
-
function
|
|
443
|
-
|
|
530
|
+
function zt(t, s, e, n) {
|
|
531
|
+
k("Request: %s %s", t, s), k("Headers: %o", e), n && k("Body: %s", yt(n));
|
|
444
532
|
}
|
|
445
|
-
async function
|
|
446
|
-
const
|
|
533
|
+
async function Gt(t, s = !1) {
|
|
534
|
+
const e = {
|
|
447
535
|
"Content-Type": "application/json"
|
|
448
536
|
};
|
|
449
|
-
if (
|
|
537
|
+
if (s && (e.Accept = "text/event-stream"), t) {
|
|
450
538
|
const n = await t();
|
|
451
|
-
return { ...
|
|
539
|
+
return { ...e, ...n };
|
|
452
540
|
}
|
|
453
|
-
return
|
|
541
|
+
return e;
|
|
454
542
|
}
|
|
455
|
-
function
|
|
456
|
-
if (!
|
|
543
|
+
function xt(t, s) {
|
|
544
|
+
if (!s)
|
|
457
545
|
return t;
|
|
458
|
-
const
|
|
459
|
-
|
|
546
|
+
const e = new AbortController(), n = (o) => {
|
|
547
|
+
e.signal.aborted || e.abort(o.reason);
|
|
460
548
|
};
|
|
461
|
-
return t.aborted ?
|
|
549
|
+
return t.aborted ? e.abort(t.reason) : t.addEventListener("abort", () => n(t), {
|
|
462
550
|
once: !0
|
|
463
|
-
}),
|
|
551
|
+
}), s.aborted ? e.abort(s.reason) : s.addEventListener("abort", () => n(s), {
|
|
464
552
|
once: !0
|
|
465
|
-
}),
|
|
553
|
+
}), e.signal;
|
|
466
554
|
}
|
|
467
|
-
function
|
|
555
|
+
function Mt(t, s, e) {
|
|
468
556
|
return {
|
|
469
557
|
method: "POST",
|
|
470
558
|
headers: t,
|
|
471
|
-
body:
|
|
472
|
-
signal:
|
|
559
|
+
body: s,
|
|
560
|
+
signal: e
|
|
473
561
|
};
|
|
474
562
|
}
|
|
475
|
-
async function
|
|
476
|
-
const { message:
|
|
477
|
-
|
|
563
|
+
async function X(t, s, e, n, o, r) {
|
|
564
|
+
const { message: a, sessionId: l, taskId: i, metadata: d } = t, { agentId: c, agentUrl: g, authProvider: h, proxy: T } = s, { isStreaming: M = !1, enableTokenStreaming: p = !1 } = e, m = l || r, y = Bt(g, c), u = await Jt(
|
|
565
|
+
a,
|
|
478
566
|
n,
|
|
479
|
-
|
|
480
|
-
),
|
|
567
|
+
o
|
|
568
|
+
), w = Ht(
|
|
481
569
|
{
|
|
482
|
-
id:
|
|
483
|
-
sessionId:
|
|
570
|
+
id: i,
|
|
571
|
+
sessionId: m,
|
|
484
572
|
message: u,
|
|
485
|
-
metadata:
|
|
573
|
+
metadata: d
|
|
486
574
|
},
|
|
487
|
-
|
|
488
|
-
|
|
575
|
+
M ? "message/stream" : "message/send",
|
|
576
|
+
p && M
|
|
489
577
|
// Only enable token streaming if using SSE
|
|
490
|
-
),
|
|
491
|
-
return
|
|
492
|
-
request:
|
|
493
|
-
headers:
|
|
578
|
+
), S = await Gt(h, M);
|
|
579
|
+
return zt("POST", y, S, w), {
|
|
580
|
+
request: w,
|
|
581
|
+
headers: S,
|
|
494
582
|
enhancedMessage: u,
|
|
495
|
-
effectiveSessionId:
|
|
583
|
+
effectiveSessionId: m,
|
|
496
584
|
fullAgentUrl: y
|
|
497
585
|
};
|
|
498
586
|
}
|
|
499
|
-
async function
|
|
500
|
-
const { request: n, headers:
|
|
501
|
-
|
|
587
|
+
async function St(t, s, e = {}) {
|
|
588
|
+
const { request: n, headers: o, fullAgentUrl: r } = t, { timeout: a } = s, { abortSignal: l } = e, { timeoutId: i, controller: d } = Ct(
|
|
589
|
+
a,
|
|
502
590
|
"request"
|
|
503
|
-
), c =
|
|
591
|
+
), c = l ? xt(d.signal, l) : d.signal;
|
|
504
592
|
try {
|
|
505
|
-
const
|
|
506
|
-
|
|
593
|
+
const g = Mt(
|
|
594
|
+
o,
|
|
507
595
|
JSON.stringify(n),
|
|
508
596
|
c
|
|
509
597
|
);
|
|
510
|
-
|
|
511
|
-
method:
|
|
512
|
-
headers:
|
|
598
|
+
k("Making request to %s with options: %O", r, {
|
|
599
|
+
method: g.method,
|
|
600
|
+
headers: g.headers
|
|
513
601
|
});
|
|
514
|
-
const
|
|
515
|
-
clearTimeout(
|
|
516
|
-
const
|
|
517
|
-
return
|
|
602
|
+
const h = await fetch(r, g);
|
|
603
|
+
clearTimeout(i), Tt(h, "request");
|
|
604
|
+
const T = await h.json();
|
|
605
|
+
return k(
|
|
518
606
|
"Response from %s: %d %O",
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
),
|
|
523
|
-
} catch (
|
|
524
|
-
|
|
607
|
+
r,
|
|
608
|
+
h.status,
|
|
609
|
+
yt(T)
|
|
610
|
+
), Wt(T, "request");
|
|
611
|
+
} catch (g) {
|
|
612
|
+
It(g, i, "request");
|
|
525
613
|
}
|
|
526
614
|
}
|
|
527
|
-
async function*
|
|
528
|
-
const { request: n, headers:
|
|
529
|
-
streamingTimeout:
|
|
530
|
-
abortSignal:
|
|
531
|
-
enableTokenStreaming:
|
|
532
|
-
} =
|
|
533
|
-
|
|
615
|
+
async function* bt(t, s, e) {
|
|
616
|
+
const { request: n, headers: o, fullAgentUrl: r } = t, {
|
|
617
|
+
streamingTimeout: a = 6e4,
|
|
618
|
+
abortSignal: l,
|
|
619
|
+
enableTokenStreaming: i = !1
|
|
620
|
+
} = e, { timeoutId: d, controller: c } = Ct(
|
|
621
|
+
a,
|
|
534
622
|
"streaming request"
|
|
535
|
-
),
|
|
623
|
+
), g = l ? xt(c.signal, l) : c.signal;
|
|
536
624
|
try {
|
|
537
|
-
const
|
|
538
|
-
if (clearTimeout(
|
|
625
|
+
const h = JSON.stringify(n), T = Mt(o, h, g), M = await fetch(r, T);
|
|
626
|
+
if (clearTimeout(d), Vt(M, "streaming request"), !M.body)
|
|
539
627
|
throw new Error(
|
|
540
628
|
"Response body is null - server may not support streaming"
|
|
541
629
|
);
|
|
542
|
-
const
|
|
543
|
-
yield*
|
|
544
|
-
supportDeltas:
|
|
630
|
+
const p = i && n.tokenStreaming === !0;
|
|
631
|
+
yield* Kt(M.body, {
|
|
632
|
+
supportDeltas: p
|
|
545
633
|
});
|
|
546
|
-
} catch (
|
|
547
|
-
|
|
634
|
+
} catch (h) {
|
|
635
|
+
It(h, d, "streaming request");
|
|
548
636
|
}
|
|
549
637
|
}
|
|
550
|
-
const
|
|
551
|
-
async function
|
|
552
|
-
if (!t || !
|
|
638
|
+
const Qt = 12e4, lt = /* @__PURE__ */ new Map();
|
|
639
|
+
async function Xt(t, s) {
|
|
640
|
+
if (!t || !s || !t.getAvailableTools)
|
|
553
641
|
return !1;
|
|
554
|
-
const
|
|
555
|
-
if (
|
|
642
|
+
const e = F(s);
|
|
643
|
+
if (e.length === 0)
|
|
556
644
|
return !1;
|
|
557
645
|
try {
|
|
558
646
|
const n = await t.getAvailableTools();
|
|
559
|
-
for (const
|
|
647
|
+
for (const o of e)
|
|
560
648
|
if (n.some(
|
|
561
|
-
(
|
|
649
|
+
(a) => a.id === o.data.toolId
|
|
562
650
|
))
|
|
563
651
|
return !0;
|
|
564
652
|
} catch {
|
|
@@ -566,334 +654,333 @@ async function ce(t, e) {
|
|
|
566
654
|
}
|
|
567
655
|
return !1;
|
|
568
656
|
}
|
|
569
|
-
function
|
|
570
|
-
|
|
657
|
+
function Yt() {
|
|
658
|
+
lt.clear();
|
|
571
659
|
}
|
|
572
|
-
function
|
|
573
|
-
return t.map((
|
|
574
|
-
const
|
|
660
|
+
function Zt(t) {
|
|
661
|
+
return t.map((s) => {
|
|
662
|
+
const e = s.data.toolCallId, n = lt.get(e);
|
|
575
663
|
if (n && n.resolvedValue !== null) {
|
|
576
|
-
const
|
|
577
|
-
return
|
|
578
|
-
|
|
579
|
-
|
|
664
|
+
const o = n.resolvedValue;
|
|
665
|
+
return o.error ? J(
|
|
666
|
+
e,
|
|
667
|
+
s.data.toolId,
|
|
580
668
|
void 0,
|
|
581
|
-
|
|
582
|
-
) :
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
669
|
+
o.error
|
|
670
|
+
) : J(
|
|
671
|
+
e,
|
|
672
|
+
s.data.toolId,
|
|
673
|
+
o
|
|
586
674
|
);
|
|
587
675
|
}
|
|
588
|
-
return
|
|
676
|
+
return s;
|
|
589
677
|
});
|
|
590
678
|
}
|
|
591
|
-
async function
|
|
592
|
-
const n = [],
|
|
593
|
-
let
|
|
594
|
-
for (const
|
|
595
|
-
const { toolCallId:
|
|
679
|
+
async function At(t, s, e) {
|
|
680
|
+
const n = [], o = [];
|
|
681
|
+
let r = !1;
|
|
682
|
+
for (const a of t) {
|
|
683
|
+
const { toolCallId: l, toolId: i, arguments: d } = a.data;
|
|
596
684
|
try {
|
|
597
|
-
const c = await
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
), { result:
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
i,
|
|
685
|
+
const c = await s.executeTool(
|
|
686
|
+
i,
|
|
687
|
+
d,
|
|
688
|
+
e,
|
|
689
|
+
l
|
|
690
|
+
), { result: g, returnToAgent: h, agentMessage: T } = it(c);
|
|
691
|
+
h && (r = !0), T && o.push(L(T)), n.push(
|
|
692
|
+
J(
|
|
606
693
|
l,
|
|
607
|
-
|
|
694
|
+
i,
|
|
695
|
+
g
|
|
608
696
|
)
|
|
609
697
|
);
|
|
610
698
|
} catch (c) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
i,
|
|
699
|
+
r = !0, n.push(
|
|
700
|
+
J(
|
|
614
701
|
l,
|
|
702
|
+
i,
|
|
615
703
|
void 0,
|
|
616
704
|
c instanceof Error ? c.message : String(c)
|
|
617
705
|
)
|
|
618
706
|
);
|
|
619
707
|
}
|
|
620
708
|
}
|
|
621
|
-
return { results: n, shouldReturnToAgent:
|
|
709
|
+
return { results: n, shouldReturnToAgent: r, agentMessages: o };
|
|
622
710
|
}
|
|
623
|
-
function
|
|
624
|
-
const
|
|
625
|
-
for (const
|
|
626
|
-
for (const n of
|
|
627
|
-
n.type === "text" ?
|
|
711
|
+
function gt(t) {
|
|
712
|
+
const s = [];
|
|
713
|
+
for (const e of t)
|
|
714
|
+
for (const n of e.parts)
|
|
715
|
+
n.type === "text" ? s.push({
|
|
628
716
|
type: "data",
|
|
629
717
|
data: {
|
|
630
|
-
role:
|
|
718
|
+
role: e.role,
|
|
631
719
|
text: n.text
|
|
632
720
|
}
|
|
633
|
-
}) : n.type === "data" &&
|
|
634
|
-
return
|
|
721
|
+
}) : n.type === "data" && s.push(n);
|
|
722
|
+
return s;
|
|
635
723
|
}
|
|
636
|
-
async function
|
|
637
|
-
const
|
|
724
|
+
async function et(t, s, e, n, o, r, a) {
|
|
725
|
+
const i = await X(
|
|
638
726
|
{
|
|
639
|
-
message:
|
|
727
|
+
message: s,
|
|
640
728
|
taskId: t,
|
|
641
729
|
sessionId: void 0
|
|
642
730
|
// Use task's session
|
|
643
731
|
},
|
|
644
|
-
|
|
732
|
+
e,
|
|
645
733
|
{ isStreaming: !1 },
|
|
646
734
|
n,
|
|
647
|
-
|
|
648
|
-
|
|
735
|
+
o,
|
|
736
|
+
r
|
|
649
737
|
);
|
|
650
|
-
return await
|
|
651
|
-
abortSignal:
|
|
738
|
+
return await St(i, e, {
|
|
739
|
+
abortSignal: a
|
|
652
740
|
});
|
|
653
741
|
}
|
|
654
|
-
async function
|
|
655
|
-
const
|
|
656
|
-
message:
|
|
742
|
+
async function ft(t, s, e, n, o, r, a, l, i = []) {
|
|
743
|
+
const d = {
|
|
744
|
+
message: s,
|
|
657
745
|
taskId: t,
|
|
658
746
|
sessionId: void 0
|
|
659
747
|
// Use task's session
|
|
660
|
-
}, c =
|
|
661
|
-
|
|
662
|
-
|
|
748
|
+
}, c = l || { isStreaming: !0 }, g = await X(
|
|
749
|
+
d,
|
|
750
|
+
e,
|
|
663
751
|
{
|
|
664
752
|
...c
|
|
665
753
|
},
|
|
666
754
|
n,
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
),
|
|
755
|
+
o,
|
|
756
|
+
r
|
|
757
|
+
), h = bt(g, e, {
|
|
670
758
|
...c,
|
|
671
|
-
abortSignal:
|
|
759
|
+
abortSignal: a
|
|
672
760
|
});
|
|
673
|
-
return
|
|
674
|
-
|
|
761
|
+
return vt(
|
|
762
|
+
h,
|
|
675
763
|
n,
|
|
676
|
-
a,
|
|
677
|
-
s,
|
|
678
764
|
o,
|
|
765
|
+
e,
|
|
766
|
+
r,
|
|
679
767
|
!0,
|
|
680
768
|
// withHistory
|
|
681
|
-
|
|
769
|
+
i,
|
|
682
770
|
// preserve conversation parts across continuation
|
|
683
|
-
|
|
771
|
+
a,
|
|
684
772
|
c
|
|
685
773
|
// Pass through the same request options
|
|
686
774
|
);
|
|
687
775
|
}
|
|
688
|
-
async function*
|
|
689
|
-
var
|
|
690
|
-
for await (const
|
|
691
|
-
if (yield
|
|
692
|
-
|
|
693
|
-
|
|
776
|
+
async function* vt(t, s, e, n, o, r = !0, a = [], l, i) {
|
|
777
|
+
var d, c, g, h, T, M, p, m, y, u, w, S;
|
|
778
|
+
for await (const f of t) {
|
|
779
|
+
if (yield f, f.status.state === "running" && f.status.message && s && await Xt(
|
|
780
|
+
s,
|
|
781
|
+
f.status.message
|
|
694
782
|
)) {
|
|
695
|
-
const
|
|
696
|
-
|
|
783
|
+
const C = F(
|
|
784
|
+
f.status.message
|
|
697
785
|
);
|
|
698
|
-
for (const
|
|
699
|
-
const { toolCallId:
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
(c = (
|
|
704
|
-
|
|
705
|
-
).catch((
|
|
786
|
+
for (const I of C) {
|
|
787
|
+
const { toolCallId: b, toolId: x, arguments: _ } = I.data;
|
|
788
|
+
s.executeTool(
|
|
789
|
+
x,
|
|
790
|
+
_,
|
|
791
|
+
(c = (d = f.status) == null ? void 0 : d.message) == null ? void 0 : c.messageId,
|
|
792
|
+
b
|
|
793
|
+
).catch((N) => {
|
|
706
794
|
console.error(
|
|
707
|
-
`Tool execution failed for ${
|
|
708
|
-
|
|
795
|
+
`Tool execution failed for ${x}:`,
|
|
796
|
+
N
|
|
709
797
|
);
|
|
710
798
|
});
|
|
711
799
|
}
|
|
712
800
|
yield {
|
|
713
|
-
id:
|
|
801
|
+
id: f.id,
|
|
714
802
|
status: {
|
|
715
803
|
state: "running",
|
|
716
804
|
message: {
|
|
717
805
|
role: "agent",
|
|
718
806
|
kind: "message",
|
|
719
|
-
parts:
|
|
720
|
-
messageId:
|
|
807
|
+
parts: C,
|
|
808
|
+
messageId: O()
|
|
721
809
|
}
|
|
722
810
|
},
|
|
723
811
|
final: !1,
|
|
724
812
|
text: ""
|
|
725
813
|
};
|
|
726
814
|
}
|
|
727
|
-
if (
|
|
728
|
-
const
|
|
729
|
-
|
|
815
|
+
if (f.status.state === "input-required" && f.status.message && s) {
|
|
816
|
+
const C = F(
|
|
817
|
+
f.status.message
|
|
730
818
|
);
|
|
731
|
-
if (
|
|
732
|
-
const
|
|
733
|
-
let
|
|
734
|
-
const
|
|
735
|
-
for (const
|
|
819
|
+
if (C.length > 0) {
|
|
820
|
+
const I = [];
|
|
821
|
+
let b = !1;
|
|
822
|
+
const x = [], _ = [];
|
|
823
|
+
for (const N of C) {
|
|
736
824
|
const {
|
|
737
|
-
toolCallId:
|
|
738
|
-
toolId:
|
|
739
|
-
arguments:
|
|
740
|
-
} =
|
|
825
|
+
toolCallId: R,
|
|
826
|
+
toolId: P,
|
|
827
|
+
arguments: A
|
|
828
|
+
} = N.data;
|
|
741
829
|
try {
|
|
742
|
-
const
|
|
743
|
-
|
|
744
|
-
|
|
745
|
-
(
|
|
746
|
-
|
|
747
|
-
), { result:
|
|
748
|
-
if (
|
|
749
|
-
|
|
750
|
-
),
|
|
751
|
-
const
|
|
752
|
-
promise:
|
|
830
|
+
const E = await s.executeTool(
|
|
831
|
+
P,
|
|
832
|
+
A,
|
|
833
|
+
(h = (g = f.status) == null ? void 0 : g.message) == null ? void 0 : h.messageId,
|
|
834
|
+
R
|
|
835
|
+
), { result: v, returnToAgent: D, agentMessage: W } = it(E);
|
|
836
|
+
if (D && (b = !0), W && _.push(
|
|
837
|
+
L(W)
|
|
838
|
+
), v.result instanceof Promise) {
|
|
839
|
+
const B = v.result, j = {
|
|
840
|
+
promise: B,
|
|
753
841
|
resolvedValue: null
|
|
754
842
|
};
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
),
|
|
759
|
-
|
|
760
|
-
}).catch((
|
|
843
|
+
lt.set(
|
|
844
|
+
R,
|
|
845
|
+
j
|
|
846
|
+
), B.then((q) => {
|
|
847
|
+
j.resolvedValue = q;
|
|
848
|
+
}).catch((q) => {
|
|
761
849
|
console.error(
|
|
762
|
-
`Promise rejected for tool call ${
|
|
763
|
-
|
|
764
|
-
),
|
|
765
|
-
error:
|
|
850
|
+
`Promise rejected for tool call ${R}:`,
|
|
851
|
+
q
|
|
852
|
+
), j.resolvedValue = {
|
|
853
|
+
error: q instanceof Error ? q.message : String(q)
|
|
766
854
|
};
|
|
767
855
|
});
|
|
768
856
|
}
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
857
|
+
const V = J(
|
|
858
|
+
R,
|
|
859
|
+
P,
|
|
860
|
+
v
|
|
773
861
|
);
|
|
774
|
-
|
|
775
|
-
} catch (
|
|
776
|
-
const
|
|
777
|
-
|
|
778
|
-
|
|
862
|
+
I.push(V), x.push(V);
|
|
863
|
+
} catch (E) {
|
|
864
|
+
const v = J(
|
|
865
|
+
R,
|
|
866
|
+
P,
|
|
779
867
|
void 0,
|
|
780
|
-
|
|
868
|
+
E instanceof Error ? E.message : String(E)
|
|
781
869
|
);
|
|
782
|
-
|
|
870
|
+
I.push(v), x.push(v);
|
|
783
871
|
}
|
|
784
872
|
}
|
|
785
|
-
if (
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
873
|
+
if (a.push(f.status.message), I.length > 0 && a.push({
|
|
874
|
+
role: "agent",
|
|
875
|
+
kind: "message",
|
|
876
|
+
parts: I,
|
|
877
|
+
messageId: O()
|
|
878
|
+
}), b) {
|
|
879
|
+
const N = gt(a), R = Q(
|
|
880
|
+
[],
|
|
881
|
+
// Empty array - tool results are already in historyDataParts
|
|
882
|
+
N
|
|
789
883
|
);
|
|
790
884
|
yield {
|
|
791
|
-
id:
|
|
885
|
+
id: f.id,
|
|
792
886
|
status: {
|
|
793
887
|
state: "working",
|
|
794
|
-
message:
|
|
888
|
+
message: R
|
|
795
889
|
},
|
|
796
890
|
final: !1,
|
|
797
891
|
text: ""
|
|
798
892
|
};
|
|
799
|
-
const
|
|
800
|
-
|
|
801
|
-
|
|
893
|
+
const P = await ft(
|
|
894
|
+
f.id,
|
|
895
|
+
R,
|
|
802
896
|
n,
|
|
803
|
-
e,
|
|
804
897
|
s,
|
|
805
|
-
|
|
806
|
-
|
|
898
|
+
e,
|
|
899
|
+
o,
|
|
807
900
|
l,
|
|
808
|
-
|
|
901
|
+
i,
|
|
902
|
+
a
|
|
809
903
|
);
|
|
810
|
-
let
|
|
811
|
-
for await (const
|
|
812
|
-
|
|
813
|
-
if (!
|
|
904
|
+
let A = null;
|
|
905
|
+
for await (const D of P)
|
|
906
|
+
D.final ? A = D : yield D;
|
|
907
|
+
if (!A)
|
|
814
908
|
throw new Error(
|
|
815
909
|
"Continue task stream ended without final result"
|
|
816
910
|
);
|
|
817
|
-
let
|
|
818
|
-
|
|
819
|
-
) : [];
|
|
820
|
-
|
|
821
|
-
role: "agent",
|
|
822
|
-
kind: "message",
|
|
823
|
-
parts: b,
|
|
824
|
-
messageId: D()
|
|
825
|
-
});
|
|
826
|
-
let R = N;
|
|
827
|
-
if (P.length > 0)
|
|
911
|
+
let E = (T = A.status) != null && T.message ? F(
|
|
912
|
+
A.status.message
|
|
913
|
+
) : [], v = A;
|
|
914
|
+
if (E.length > 0)
|
|
828
915
|
for (yield {
|
|
829
|
-
...
|
|
916
|
+
...A,
|
|
830
917
|
final: !1,
|
|
831
|
-
text:
|
|
832
|
-
((
|
|
918
|
+
text: $(
|
|
919
|
+
((M = A.status) == null ? void 0 : M.message) || {
|
|
833
920
|
parts: [],
|
|
834
|
-
messageId:
|
|
921
|
+
messageId: O()
|
|
835
922
|
}
|
|
836
923
|
)
|
|
837
|
-
};
|
|
838
|
-
(
|
|
839
|
-
|
|
924
|
+
}; E.length > 0; ) {
|
|
925
|
+
(p = v.status) != null && p.message && a.push(
|
|
926
|
+
v.status.message
|
|
840
927
|
);
|
|
841
928
|
const {
|
|
842
|
-
results:
|
|
843
|
-
shouldReturnToAgent:
|
|
844
|
-
} = await
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
(y = (
|
|
929
|
+
results: D,
|
|
930
|
+
shouldReturnToAgent: W
|
|
931
|
+
} = await At(
|
|
932
|
+
E,
|
|
933
|
+
s,
|
|
934
|
+
(y = (m = v.status) == null ? void 0 : m.message) == null ? void 0 : y.messageId
|
|
848
935
|
);
|
|
849
|
-
if (
|
|
850
|
-
id:
|
|
936
|
+
if (D.length > 0 && (yield {
|
|
937
|
+
id: v.id,
|
|
851
938
|
status: {
|
|
852
939
|
state: "working",
|
|
853
940
|
message: {
|
|
854
941
|
role: "agent",
|
|
855
942
|
kind: "message",
|
|
856
|
-
parts:
|
|
857
|
-
messageId:
|
|
943
|
+
parts: D,
|
|
944
|
+
messageId: O()
|
|
858
945
|
}
|
|
859
946
|
// Simple message with just the results
|
|
860
947
|
},
|
|
861
948
|
final: !1,
|
|
862
949
|
text: ""
|
|
863
|
-
}),
|
|
864
|
-
const
|
|
865
|
-
|
|
866
|
-
) : [],
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
),
|
|
870
|
-
|
|
871
|
-
|
|
950
|
+
}), W) {
|
|
951
|
+
const V = r ? gt(
|
|
952
|
+
a
|
|
953
|
+
) : [], B = Q(
|
|
954
|
+
D,
|
|
955
|
+
V
|
|
956
|
+
), j = await ft(
|
|
957
|
+
v.id,
|
|
958
|
+
B,
|
|
872
959
|
n,
|
|
873
|
-
e,
|
|
874
960
|
s,
|
|
875
|
-
|
|
876
|
-
|
|
961
|
+
e,
|
|
962
|
+
o,
|
|
877
963
|
l,
|
|
878
|
-
|
|
964
|
+
i,
|
|
965
|
+
a
|
|
879
966
|
);
|
|
880
|
-
let
|
|
881
|
-
for await (const
|
|
882
|
-
|
|
883
|
-
if (!
|
|
967
|
+
let q = null;
|
|
968
|
+
for await (const Y of j)
|
|
969
|
+
Y.final ? q = Y : yield Y;
|
|
970
|
+
if (!q)
|
|
884
971
|
throw new Error(
|
|
885
972
|
"Continue task stream ended without final result"
|
|
886
973
|
);
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
) : [],
|
|
890
|
-
id:
|
|
891
|
-
status:
|
|
974
|
+
v = q, E = (u = v.status) != null && u.message ? F(
|
|
975
|
+
v.status.message
|
|
976
|
+
) : [], E.length > 0 && (yield {
|
|
977
|
+
id: v.id,
|
|
978
|
+
status: v.status,
|
|
892
979
|
final: !1,
|
|
893
|
-
text:
|
|
894
|
-
((
|
|
980
|
+
text: $(
|
|
981
|
+
((w = v.status) == null ? void 0 : w.message) || {
|
|
895
982
|
parts: [],
|
|
896
|
-
messageId:
|
|
983
|
+
messageId: O()
|
|
897
984
|
}
|
|
898
985
|
)
|
|
899
986
|
});
|
|
@@ -901,39 +988,39 @@ async function* $t(t, e, s, n, a, o = !0, r = [], i, l) {
|
|
|
901
988
|
break;
|
|
902
989
|
}
|
|
903
990
|
yield {
|
|
904
|
-
...
|
|
991
|
+
...v,
|
|
905
992
|
final: !0,
|
|
906
|
-
text:
|
|
907
|
-
((
|
|
993
|
+
text: $(
|
|
994
|
+
((S = v.status) == null ? void 0 : S.message) || {
|
|
908
995
|
parts: [],
|
|
909
|
-
messageId:
|
|
996
|
+
messageId: O()
|
|
910
997
|
}
|
|
911
998
|
)
|
|
912
999
|
};
|
|
913
1000
|
} else {
|
|
914
|
-
const
|
|
915
|
-
...
|
|
916
|
-
parts:
|
|
917
|
-
},
|
|
918
|
-
...
|
|
1001
|
+
const N = {
|
|
1002
|
+
...f.status.message,
|
|
1003
|
+
parts: x
|
|
1004
|
+
}, R = {
|
|
1005
|
+
...f,
|
|
919
1006
|
status: {
|
|
920
|
-
...
|
|
921
|
-
message:
|
|
1007
|
+
...f.status,
|
|
1008
|
+
message: N
|
|
922
1009
|
},
|
|
923
|
-
final:
|
|
1010
|
+
final: _.length === 0,
|
|
924
1011
|
// Only final if no agent messages to follow
|
|
925
|
-
text:
|
|
1012
|
+
text: $(N)
|
|
926
1013
|
};
|
|
927
|
-
if (yield
|
|
928
|
-
const
|
|
1014
|
+
if (yield R, _.length > 0) {
|
|
1015
|
+
const P = _.map((E) => $(E)).join(" "), A = L(P);
|
|
929
1016
|
yield {
|
|
930
|
-
id:
|
|
1017
|
+
id: R.id,
|
|
931
1018
|
status: {
|
|
932
1019
|
state: "completed",
|
|
933
|
-
message:
|
|
1020
|
+
message: A
|
|
934
1021
|
},
|
|
935
1022
|
final: !0,
|
|
936
|
-
text:
|
|
1023
|
+
text: P
|
|
937
1024
|
};
|
|
938
1025
|
}
|
|
939
1026
|
}
|
|
@@ -941,209 +1028,209 @@ async function* $t(t, e, s, n, a, o = !0, r = [], i, l) {
|
|
|
941
1028
|
}
|
|
942
1029
|
}
|
|
943
1030
|
}
|
|
944
|
-
function
|
|
1031
|
+
function te(t) {
|
|
945
1032
|
const {
|
|
946
|
-
agentId:
|
|
947
|
-
agentUrl:
|
|
1033
|
+
agentId: s,
|
|
1034
|
+
agentUrl: e,
|
|
948
1035
|
authProvider: n,
|
|
949
|
-
defaultSessionId:
|
|
950
|
-
timeout:
|
|
951
|
-
toolProvider:
|
|
952
|
-
contextProvider:
|
|
953
|
-
enableStreaming:
|
|
954
|
-
} = t,
|
|
955
|
-
agentId:
|
|
956
|
-
agentUrl:
|
|
1036
|
+
defaultSessionId: o,
|
|
1037
|
+
timeout: r = Qt,
|
|
1038
|
+
toolProvider: a,
|
|
1039
|
+
contextProvider: l,
|
|
1040
|
+
enableStreaming: i = !1
|
|
1041
|
+
} = t, d = {
|
|
1042
|
+
agentId: s,
|
|
1043
|
+
agentUrl: e,
|
|
957
1044
|
authProvider: n,
|
|
958
|
-
timeout:
|
|
1045
|
+
timeout: r
|
|
959
1046
|
};
|
|
960
1047
|
return {
|
|
961
1048
|
async sendMessage(c) {
|
|
962
|
-
var
|
|
963
|
-
const { withHistory:
|
|
964
|
-
|
|
965
|
-
const
|
|
1049
|
+
var w, S;
|
|
1050
|
+
const { withHistory: g = !0, abortSignal: h } = c, T = c.sessionId || o || void 0, M = [];
|
|
1051
|
+
M.push(c.message);
|
|
1052
|
+
const p = await X(
|
|
966
1053
|
c,
|
|
967
|
-
|
|
1054
|
+
d,
|
|
968
1055
|
{ isStreaming: !1 },
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
1056
|
+
a,
|
|
1057
|
+
l,
|
|
1058
|
+
T
|
|
972
1059
|
);
|
|
973
|
-
let
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
{ abortSignal:
|
|
1060
|
+
let m = await St(
|
|
1061
|
+
p,
|
|
1062
|
+
d,
|
|
1063
|
+
{ abortSignal: h }
|
|
977
1064
|
);
|
|
978
1065
|
const y = [], u = [];
|
|
979
|
-
for (;
|
|
980
|
-
const
|
|
981
|
-
|
|
1066
|
+
for (; m.status.message && a; ) {
|
|
1067
|
+
const f = F(
|
|
1068
|
+
m.status.message
|
|
982
1069
|
);
|
|
983
|
-
if (
|
|
1070
|
+
if (f.length === 0)
|
|
984
1071
|
break;
|
|
985
|
-
y.push(...
|
|
986
|
-
const
|
|
987
|
-
let
|
|
988
|
-
for (const
|
|
1072
|
+
y.push(...f);
|
|
1073
|
+
const C = [];
|
|
1074
|
+
let I = !1;
|
|
1075
|
+
for (const b of f) {
|
|
989
1076
|
const {
|
|
990
|
-
toolCallId:
|
|
991
|
-
toolId:
|
|
992
|
-
arguments:
|
|
993
|
-
} =
|
|
1077
|
+
toolCallId: x,
|
|
1078
|
+
toolId: _,
|
|
1079
|
+
arguments: N
|
|
1080
|
+
} = b.data;
|
|
994
1081
|
try {
|
|
995
|
-
const
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
), { result:
|
|
999
|
-
|
|
1000
|
-
|
|
1082
|
+
const R = await a.executeTool(
|
|
1083
|
+
_,
|
|
1084
|
+
N
|
|
1085
|
+
), { result: P, returnToAgent: A, agentMessage: E } = it(R);
|
|
1086
|
+
A && (I = !0), E && u.push(
|
|
1087
|
+
L(E)
|
|
1001
1088
|
);
|
|
1002
|
-
const
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1089
|
+
const v = J(
|
|
1090
|
+
x,
|
|
1091
|
+
_,
|
|
1092
|
+
P
|
|
1006
1093
|
);
|
|
1007
|
-
|
|
1008
|
-
} catch (
|
|
1009
|
-
const
|
|
1010
|
-
|
|
1011
|
-
|
|
1094
|
+
C.push(v), y.push(v);
|
|
1095
|
+
} catch (R) {
|
|
1096
|
+
const P = J(
|
|
1097
|
+
x,
|
|
1098
|
+
_,
|
|
1012
1099
|
void 0,
|
|
1013
|
-
|
|
1100
|
+
R instanceof Error ? R.message : String(R)
|
|
1014
1101
|
);
|
|
1015
|
-
|
|
1102
|
+
C.push(P), y.push(P);
|
|
1016
1103
|
}
|
|
1017
1104
|
}
|
|
1018
|
-
if (
|
|
1019
|
-
const
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1105
|
+
if (M.push(m.status.message), I) {
|
|
1106
|
+
const b = Q(C);
|
|
1107
|
+
m = await et(
|
|
1108
|
+
m.id,
|
|
1109
|
+
b,
|
|
1110
|
+
d,
|
|
1111
|
+
a,
|
|
1112
|
+
l,
|
|
1113
|
+
T,
|
|
1114
|
+
h
|
|
1028
1115
|
);
|
|
1029
1116
|
} else
|
|
1030
1117
|
break;
|
|
1031
1118
|
}
|
|
1032
|
-
if (y.length > 0 && (
|
|
1033
|
-
const
|
|
1034
|
-
...
|
|
1119
|
+
if (y.length > 0 && (w = m.status) != null && w.message) {
|
|
1120
|
+
const f = {
|
|
1121
|
+
...m.status.message,
|
|
1035
1122
|
parts: y
|
|
1036
1123
|
};
|
|
1037
|
-
|
|
1038
|
-
...
|
|
1124
|
+
m = {
|
|
1125
|
+
...m,
|
|
1039
1126
|
status: {
|
|
1040
|
-
...
|
|
1041
|
-
message:
|
|
1127
|
+
...m.status,
|
|
1128
|
+
message: f
|
|
1042
1129
|
}
|
|
1043
1130
|
};
|
|
1044
1131
|
}
|
|
1045
1132
|
if (u.length > 0) {
|
|
1046
|
-
const
|
|
1133
|
+
const f = u.map((I) => $(I)).join(" "), C = L(f);
|
|
1047
1134
|
return {
|
|
1048
|
-
...
|
|
1135
|
+
...m,
|
|
1049
1136
|
// Keep the enhanced message with tool results
|
|
1050
1137
|
// The agent message will be handled separately by the caller
|
|
1051
|
-
text:
|
|
1052
|
-
agentMessage:
|
|
1138
|
+
text: f,
|
|
1139
|
+
agentMessage: C
|
|
1053
1140
|
// Add this for the caller to handle
|
|
1054
1141
|
};
|
|
1055
1142
|
}
|
|
1056
1143
|
return {
|
|
1057
|
-
...
|
|
1058
|
-
text:
|
|
1059
|
-
((
|
|
1144
|
+
...m,
|
|
1145
|
+
text: $(
|
|
1146
|
+
((S = m.status) == null ? void 0 : S.message) || {
|
|
1060
1147
|
parts: [],
|
|
1061
|
-
messageId:
|
|
1148
|
+
messageId: O()
|
|
1062
1149
|
}
|
|
1063
1150
|
)
|
|
1064
1151
|
};
|
|
1065
1152
|
},
|
|
1066
1153
|
async *sendMessageStream(c) {
|
|
1067
1154
|
const {
|
|
1068
|
-
withHistory:
|
|
1069
|
-
abortSignal:
|
|
1070
|
-
enableStreaming:
|
|
1071
|
-
} = c,
|
|
1072
|
-
|
|
1073
|
-
const y = await
|
|
1155
|
+
withHistory: g = !0,
|
|
1156
|
+
abortSignal: h,
|
|
1157
|
+
enableStreaming: T
|
|
1158
|
+
} = c, M = c.sessionId || o || void 0, p = T ?? i, m = [];
|
|
1159
|
+
m.push(c.message);
|
|
1160
|
+
const y = await X(
|
|
1074
1161
|
c,
|
|
1075
|
-
|
|
1162
|
+
d,
|
|
1076
1163
|
{
|
|
1077
1164
|
isStreaming: !0,
|
|
1078
1165
|
// Always use message/stream endpoint for SSE
|
|
1079
|
-
enableTokenStreaming:
|
|
1166
|
+
enableTokenStreaming: p
|
|
1080
1167
|
},
|
|
1081
|
-
|
|
1082
|
-
|
|
1083
|
-
|
|
1084
|
-
), u =
|
|
1168
|
+
a,
|
|
1169
|
+
l,
|
|
1170
|
+
M
|
|
1171
|
+
), u = bt(
|
|
1085
1172
|
y,
|
|
1086
|
-
|
|
1173
|
+
d,
|
|
1087
1174
|
{
|
|
1088
|
-
enableTokenStreaming:
|
|
1175
|
+
enableTokenStreaming: p,
|
|
1089
1176
|
// Token streaming is optional
|
|
1090
|
-
streamingTimeout:
|
|
1091
|
-
abortSignal:
|
|
1177
|
+
streamingTimeout: r,
|
|
1178
|
+
abortSignal: h
|
|
1092
1179
|
}
|
|
1093
1180
|
);
|
|
1094
|
-
yield*
|
|
1181
|
+
yield* vt(
|
|
1095
1182
|
u,
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
A,
|
|
1100
|
-
f,
|
|
1183
|
+
a,
|
|
1184
|
+
l,
|
|
1185
|
+
d,
|
|
1101
1186
|
M,
|
|
1102
|
-
|
|
1187
|
+
g,
|
|
1188
|
+
m,
|
|
1189
|
+
h,
|
|
1103
1190
|
{
|
|
1104
1191
|
isStreaming: !0,
|
|
1105
|
-
enableTokenStreaming:
|
|
1106
|
-
streamingTimeout:
|
|
1192
|
+
enableTokenStreaming: p,
|
|
1193
|
+
streamingTimeout: r
|
|
1107
1194
|
}
|
|
1108
1195
|
);
|
|
1109
1196
|
},
|
|
1110
|
-
async continueTask(c,
|
|
1111
|
-
var
|
|
1112
|
-
const
|
|
1113
|
-
let
|
|
1197
|
+
async continueTask(c, g, h) {
|
|
1198
|
+
var m;
|
|
1199
|
+
const T = ot(g);
|
|
1200
|
+
let p = await et(
|
|
1114
1201
|
c,
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
|
|
1118
|
-
|
|
1119
|
-
|
|
1202
|
+
T,
|
|
1203
|
+
d,
|
|
1204
|
+
a,
|
|
1205
|
+
l,
|
|
1206
|
+
h
|
|
1120
1207
|
);
|
|
1121
|
-
for (;
|
|
1122
|
-
const y =
|
|
1123
|
-
|
|
1208
|
+
for (; p.status.state === "input-required" && p.status.message && a; ) {
|
|
1209
|
+
const y = F(
|
|
1210
|
+
p.status.message
|
|
1124
1211
|
);
|
|
1125
1212
|
if (y.length === 0)
|
|
1126
1213
|
break;
|
|
1127
|
-
const { results: u, shouldReturnToAgent:
|
|
1128
|
-
if (
|
|
1129
|
-
const
|
|
1130
|
-
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
|
|
1135
|
-
|
|
1136
|
-
|
|
1214
|
+
const { results: u, shouldReturnToAgent: w } = await At(y, a);
|
|
1215
|
+
if (w) {
|
|
1216
|
+
const S = Q(u);
|
|
1217
|
+
p = await et(
|
|
1218
|
+
p.id,
|
|
1219
|
+
S,
|
|
1220
|
+
d,
|
|
1221
|
+
a,
|
|
1222
|
+
l,
|
|
1223
|
+
h
|
|
1137
1224
|
);
|
|
1138
1225
|
} else
|
|
1139
1226
|
break;
|
|
1140
1227
|
}
|
|
1141
1228
|
return {
|
|
1142
|
-
...
|
|
1143
|
-
text:
|
|
1144
|
-
((
|
|
1229
|
+
...p,
|
|
1230
|
+
text: $(
|
|
1231
|
+
((m = p.status) == null ? void 0 : m.message) || {
|
|
1145
1232
|
parts: [],
|
|
1146
|
-
messageId:
|
|
1233
|
+
messageId: O()
|
|
1147
1234
|
}
|
|
1148
1235
|
)
|
|
1149
1236
|
};
|
|
@@ -1156,148 +1243,148 @@ function ge(t) {
|
|
|
1156
1243
|
}
|
|
1157
1244
|
};
|
|
1158
1245
|
}
|
|
1159
|
-
const
|
|
1160
|
-
function
|
|
1161
|
-
var
|
|
1162
|
-
const
|
|
1163
|
-
`),
|
|
1164
|
-
(
|
|
1165
|
-
).map((
|
|
1166
|
-
toolCallId:
|
|
1167
|
-
toolId:
|
|
1168
|
-
arguments:
|
|
1246
|
+
const ct = "a8c_agenttic_conversation_history";
|
|
1247
|
+
function ee(t) {
|
|
1248
|
+
var l;
|
|
1249
|
+
const s = t.parts.filter((i) => i.type === "text").map((i) => i.text).join(`
|
|
1250
|
+
`), e = t.parts.filter(
|
|
1251
|
+
(i) => i.type === "data" && "toolCallId" in i.data && "arguments" in i.data
|
|
1252
|
+
).map((i) => ({
|
|
1253
|
+
toolCallId: i.data.toolCallId,
|
|
1254
|
+
toolId: i.data.toolId,
|
|
1255
|
+
arguments: i.data.arguments
|
|
1169
1256
|
})), n = t.parts.filter(
|
|
1170
|
-
(
|
|
1171
|
-
).map((
|
|
1172
|
-
toolCallId:
|
|
1173
|
-
result:
|
|
1174
|
-
error:
|
|
1175
|
-
})),
|
|
1257
|
+
(i) => i.type === "data" && "toolCallId" in i.data && "result" in i.data
|
|
1258
|
+
).map((i) => ({
|
|
1259
|
+
toolCallId: i.data.toolCallId,
|
|
1260
|
+
result: i.data.result,
|
|
1261
|
+
error: i.data.error
|
|
1262
|
+
})), r = e.length > 0 || n.length > 0 ? "agent" : t.role, a = ((l = t.metadata) == null ? void 0 : l.timestamp) ?? Date.now();
|
|
1176
1263
|
return {
|
|
1177
|
-
role:
|
|
1178
|
-
content:
|
|
1179
|
-
timestamp:
|
|
1180
|
-
...
|
|
1264
|
+
role: r,
|
|
1265
|
+
content: s || "(No text content)",
|
|
1266
|
+
timestamp: a,
|
|
1267
|
+
...e.length > 0 && { toolCalls: e },
|
|
1181
1268
|
...n.length > 0 && { toolResults: n }
|
|
1182
1269
|
};
|
|
1183
1270
|
}
|
|
1184
|
-
function
|
|
1185
|
-
const
|
|
1186
|
-
if (t.content && t.content !== "(No text content)" &&
|
|
1271
|
+
function se(t) {
|
|
1272
|
+
const s = [];
|
|
1273
|
+
if (t.content && t.content !== "(No text content)" && s.push({
|
|
1187
1274
|
type: "text",
|
|
1188
1275
|
text: t.content
|
|
1189
1276
|
}), t.toolCalls)
|
|
1190
|
-
for (const
|
|
1191
|
-
|
|
1277
|
+
for (const e of t.toolCalls)
|
|
1278
|
+
s.push({
|
|
1192
1279
|
type: "data",
|
|
1193
1280
|
data: {
|
|
1194
|
-
toolCallId:
|
|
1195
|
-
toolId:
|
|
1196
|
-
arguments:
|
|
1281
|
+
toolCallId: e.toolCallId,
|
|
1282
|
+
toolId: e.toolId,
|
|
1283
|
+
arguments: e.arguments
|
|
1197
1284
|
}
|
|
1198
1285
|
});
|
|
1199
1286
|
if (t.toolResults)
|
|
1200
|
-
for (const
|
|
1201
|
-
|
|
1287
|
+
for (const e of t.toolResults)
|
|
1288
|
+
s.push({
|
|
1202
1289
|
type: "data",
|
|
1203
1290
|
data: {
|
|
1204
|
-
toolCallId:
|
|
1205
|
-
result:
|
|
1206
|
-
...
|
|
1291
|
+
toolCallId: e.toolCallId,
|
|
1292
|
+
result: e.result,
|
|
1293
|
+
...e.error && { error: e.error }
|
|
1207
1294
|
}
|
|
1208
1295
|
});
|
|
1209
1296
|
return {
|
|
1210
1297
|
role: t.role,
|
|
1211
1298
|
kind: "message",
|
|
1212
|
-
parts:
|
|
1213
|
-
messageId:
|
|
1299
|
+
parts: s,
|
|
1300
|
+
messageId: O(),
|
|
1214
1301
|
metadata: {
|
|
1215
1302
|
timestamp: t.timestamp
|
|
1216
1303
|
}
|
|
1217
1304
|
};
|
|
1218
1305
|
}
|
|
1219
|
-
const
|
|
1220
|
-
async function
|
|
1221
|
-
const n =
|
|
1222
|
-
if (
|
|
1223
|
-
const
|
|
1224
|
-
|
|
1306
|
+
const U = /* @__PURE__ */ new Map(), ne = 50;
|
|
1307
|
+
async function oe(t, s, e) {
|
|
1308
|
+
const n = e || t;
|
|
1309
|
+
if (U.set(n, [...s]), U.size > ne) {
|
|
1310
|
+
const o = U.keys().next().value;
|
|
1311
|
+
o && U.delete(o);
|
|
1225
1312
|
}
|
|
1226
1313
|
if (!(typeof sessionStorage > "u"))
|
|
1227
1314
|
try {
|
|
1228
|
-
const
|
|
1315
|
+
const o = {
|
|
1229
1316
|
storageKey: n,
|
|
1230
|
-
messages:
|
|
1317
|
+
messages: s.map(ee),
|
|
1231
1318
|
lastUpdated: Date.now()
|
|
1232
1319
|
};
|
|
1233
1320
|
sessionStorage.setItem(
|
|
1234
|
-
`${
|
|
1235
|
-
JSON.stringify(
|
|
1321
|
+
`${ct}_${n}`,
|
|
1322
|
+
JSON.stringify(o)
|
|
1236
1323
|
);
|
|
1237
|
-
} catch (
|
|
1238
|
-
|
|
1324
|
+
} catch (o) {
|
|
1325
|
+
k(
|
|
1239
1326
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1240
1327
|
n,
|
|
1241
|
-
|
|
1328
|
+
o
|
|
1242
1329
|
);
|
|
1243
1330
|
}
|
|
1244
1331
|
}
|
|
1245
|
-
async function
|
|
1246
|
-
const
|
|
1247
|
-
if (
|
|
1248
|
-
return [...
|
|
1332
|
+
async function ae(t, s) {
|
|
1333
|
+
const e = s || t;
|
|
1334
|
+
if (U.has(e))
|
|
1335
|
+
return [...U.get(e)];
|
|
1249
1336
|
if (typeof sessionStorage > "u")
|
|
1250
1337
|
return [];
|
|
1251
1338
|
try {
|
|
1252
1339
|
const n = sessionStorage.getItem(
|
|
1253
|
-
`${
|
|
1340
|
+
`${ct}_${e}`
|
|
1254
1341
|
);
|
|
1255
1342
|
if (n) {
|
|
1256
|
-
const
|
|
1257
|
-
return
|
|
1343
|
+
const r = JSON.parse(n).messages.map(se);
|
|
1344
|
+
return U.set(e, r), [...r];
|
|
1258
1345
|
}
|
|
1259
1346
|
} catch (n) {
|
|
1260
|
-
|
|
1347
|
+
k(
|
|
1261
1348
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1262
|
-
|
|
1349
|
+
e,
|
|
1263
1350
|
n
|
|
1264
1351
|
);
|
|
1265
1352
|
}
|
|
1266
1353
|
return [];
|
|
1267
1354
|
}
|
|
1268
|
-
async function
|
|
1269
|
-
const
|
|
1270
|
-
if (
|
|
1355
|
+
async function re(t, s) {
|
|
1356
|
+
const e = s || t;
|
|
1357
|
+
if (U.delete(e), !(typeof sessionStorage > "u"))
|
|
1271
1358
|
try {
|
|
1272
|
-
sessionStorage.removeItem(`${
|
|
1359
|
+
sessionStorage.removeItem(`${ct}_${e}`);
|
|
1273
1360
|
} catch (n) {
|
|
1274
|
-
|
|
1361
|
+
k(
|
|
1275
1362
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1276
|
-
|
|
1363
|
+
e,
|
|
1277
1364
|
n
|
|
1278
1365
|
);
|
|
1279
1366
|
}
|
|
1280
1367
|
}
|
|
1281
|
-
function
|
|
1282
|
-
const
|
|
1368
|
+
function K(t) {
|
|
1369
|
+
const s = t.parts.filter((e) => e.type === "text" ? !0 : e.type === "data" ? "role" in e.data && "text" in e.data ? !1 : "toolCallId" in e.data && "arguments" in e.data || "toolCallId" in e.data && "result" in e.data : !0);
|
|
1283
1370
|
return {
|
|
1284
1371
|
...t,
|
|
1285
|
-
parts:
|
|
1372
|
+
parts: s,
|
|
1286
1373
|
// Preserve metadata if it exists, otherwise add timestamp
|
|
1287
1374
|
metadata: t.metadata || {
|
|
1288
1375
|
timestamp: Date.now()
|
|
1289
1376
|
}
|
|
1290
1377
|
};
|
|
1291
1378
|
}
|
|
1292
|
-
function
|
|
1293
|
-
const
|
|
1294
|
-
for (const
|
|
1295
|
-
for (const n of
|
|
1379
|
+
function ie(t) {
|
|
1380
|
+
const s = [];
|
|
1381
|
+
for (const e of t)
|
|
1382
|
+
for (const n of e.parts)
|
|
1296
1383
|
if (n.type === "text")
|
|
1297
|
-
|
|
1384
|
+
s.push({
|
|
1298
1385
|
type: "data",
|
|
1299
1386
|
data: {
|
|
1300
|
-
role:
|
|
1387
|
+
role: e.role,
|
|
1301
1388
|
text: n.text
|
|
1302
1389
|
}
|
|
1303
1390
|
});
|
|
@@ -1305,280 +1392,280 @@ function Ie(t) {
|
|
|
1305
1392
|
if ("role" in n.data && "text" in n.data)
|
|
1306
1393
|
continue;
|
|
1307
1394
|
if ("toolCallId" in n.data && "arguments" in n.data) {
|
|
1308
|
-
|
|
1395
|
+
s.push(n);
|
|
1309
1396
|
continue;
|
|
1310
1397
|
}
|
|
1311
1398
|
if ("toolCallId" in n.data && "result" in n.data) {
|
|
1312
|
-
|
|
1399
|
+
s.push(n);
|
|
1313
1400
|
continue;
|
|
1314
1401
|
}
|
|
1315
1402
|
}
|
|
1316
|
-
return
|
|
1403
|
+
return s;
|
|
1317
1404
|
}
|
|
1318
|
-
function
|
|
1405
|
+
function mt(t, s = []) {
|
|
1319
1406
|
return {
|
|
1320
1407
|
role: "user",
|
|
1321
1408
|
parts: [
|
|
1322
|
-
...
|
|
1409
|
+
...ie(s),
|
|
1323
1410
|
{
|
|
1324
1411
|
type: "text",
|
|
1325
1412
|
text: t
|
|
1326
1413
|
}
|
|
1327
1414
|
],
|
|
1328
1415
|
kind: "message",
|
|
1329
|
-
messageId:
|
|
1416
|
+
messageId: O(),
|
|
1330
1417
|
metadata: {
|
|
1331
1418
|
timestamp: Date.now()
|
|
1332
1419
|
}
|
|
1333
1420
|
};
|
|
1334
1421
|
}
|
|
1335
|
-
function
|
|
1422
|
+
function le(t) {
|
|
1336
1423
|
return t != null && t.parts ? t.parts.filter(
|
|
1337
|
-
(
|
|
1424
|
+
(s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
|
|
1338
1425
|
) : [];
|
|
1339
1426
|
}
|
|
1340
|
-
async function
|
|
1341
|
-
const
|
|
1342
|
-
for (const
|
|
1343
|
-
if (
|
|
1344
|
-
if (
|
|
1345
|
-
(
|
|
1427
|
+
async function ce(t) {
|
|
1428
|
+
const s = [];
|
|
1429
|
+
for (const e of t)
|
|
1430
|
+
if (e.parts && Array.isArray(e.parts))
|
|
1431
|
+
if (e.parts.some(
|
|
1432
|
+
(o) => o.type === "data" && "toolCallId" in o.data && "result" in o.data
|
|
1346
1433
|
)) {
|
|
1347
|
-
const
|
|
1348
|
-
|
|
1434
|
+
const o = Zt(
|
|
1435
|
+
e.parts
|
|
1349
1436
|
);
|
|
1350
|
-
|
|
1351
|
-
...
|
|
1352
|
-
parts:
|
|
1437
|
+
s.push({
|
|
1438
|
+
...e,
|
|
1439
|
+
parts: o
|
|
1353
1440
|
});
|
|
1354
1441
|
} else
|
|
1355
|
-
|
|
1442
|
+
s.push(e);
|
|
1356
1443
|
else
|
|
1357
|
-
|
|
1358
|
-
return
|
|
1444
|
+
s.push(e);
|
|
1445
|
+
return Yt(), s;
|
|
1359
1446
|
}
|
|
1360
|
-
function
|
|
1447
|
+
function ue() {
|
|
1361
1448
|
const t = /* @__PURE__ */ new Map();
|
|
1362
|
-
async function e
|
|
1363
|
-
const
|
|
1364
|
-
if (
|
|
1449
|
+
async function s(e, n) {
|
|
1450
|
+
const o = t.get(e);
|
|
1451
|
+
if (o != null && o.sessionId)
|
|
1365
1452
|
try {
|
|
1366
|
-
await
|
|
1367
|
-
|
|
1453
|
+
await oe(
|
|
1454
|
+
o.sessionId,
|
|
1368
1455
|
n,
|
|
1369
|
-
|
|
1456
|
+
o.conversationStorageKey
|
|
1370
1457
|
);
|
|
1371
|
-
} catch (
|
|
1372
|
-
|
|
1373
|
-
`Failed to persist conversation history for agent ${
|
|
1374
|
-
|
|
1458
|
+
} catch (r) {
|
|
1459
|
+
dt(
|
|
1460
|
+
`Failed to persist conversation history for agent ${e}:`,
|
|
1461
|
+
r
|
|
1375
1462
|
);
|
|
1376
1463
|
}
|
|
1377
1464
|
}
|
|
1378
1465
|
return {
|
|
1379
|
-
async createAgent(
|
|
1380
|
-
if (t.has(
|
|
1381
|
-
return t.get(
|
|
1382
|
-
const
|
|
1383
|
-
let
|
|
1384
|
-
if (
|
|
1466
|
+
async createAgent(e, n) {
|
|
1467
|
+
if (t.has(e))
|
|
1468
|
+
return t.get(e).client;
|
|
1469
|
+
const o = te(n), r = n.sessionId || null, a = n.conversationStorageKey;
|
|
1470
|
+
let l = [];
|
|
1471
|
+
if (r)
|
|
1385
1472
|
try {
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1473
|
+
l = await ae(
|
|
1474
|
+
r,
|
|
1475
|
+
a
|
|
1389
1476
|
);
|
|
1390
|
-
} catch (
|
|
1391
|
-
|
|
1392
|
-
`Failed to load conversation history for agent ${
|
|
1393
|
-
|
|
1477
|
+
} catch (d) {
|
|
1478
|
+
dt(
|
|
1479
|
+
`Failed to load conversation history for agent ${e} with session ${r}:`,
|
|
1480
|
+
d
|
|
1394
1481
|
);
|
|
1395
1482
|
}
|
|
1396
|
-
const
|
|
1397
|
-
client:
|
|
1398
|
-
sessionId:
|
|
1399
|
-
conversationStorageKey:
|
|
1400
|
-
conversationHistory:
|
|
1483
|
+
const i = {
|
|
1484
|
+
client: o,
|
|
1485
|
+
sessionId: r,
|
|
1486
|
+
conversationStorageKey: a,
|
|
1487
|
+
conversationHistory: l,
|
|
1401
1488
|
currentAbortController: null
|
|
1402
1489
|
};
|
|
1403
|
-
return t.set(
|
|
1490
|
+
return t.set(e, i), o;
|
|
1404
1491
|
},
|
|
1405
|
-
getAgent(
|
|
1406
|
-
const n = t.get(
|
|
1492
|
+
getAgent(e) {
|
|
1493
|
+
const n = t.get(e);
|
|
1407
1494
|
return (n == null ? void 0 : n.client) || null;
|
|
1408
1495
|
},
|
|
1409
|
-
hasAgent(
|
|
1410
|
-
return t.has(
|
|
1496
|
+
hasAgent(e) {
|
|
1497
|
+
return t.has(e);
|
|
1411
1498
|
},
|
|
1412
|
-
removeAgent(
|
|
1413
|
-
return t.delete(
|
|
1499
|
+
removeAgent(e) {
|
|
1500
|
+
return t.delete(e);
|
|
1414
1501
|
},
|
|
1415
|
-
async sendMessage(
|
|
1416
|
-
var
|
|
1417
|
-
const
|
|
1418
|
-
if (!
|
|
1419
|
-
throw new Error(`Agent with key "${
|
|
1420
|
-
const { withHistory:
|
|
1502
|
+
async sendMessage(e, n, o = {}) {
|
|
1503
|
+
var p;
|
|
1504
|
+
const r = t.get(e);
|
|
1505
|
+
if (!r)
|
|
1506
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1507
|
+
const { withHistory: a = !0, ...l } = o, { client: i, conversationHistory: d } = r, c = o.message || mt(n, d), g = await i.sendMessage({
|
|
1421
1508
|
message: c,
|
|
1422
|
-
withHistory:
|
|
1423
|
-
...
|
|
1509
|
+
withHistory: a,
|
|
1510
|
+
...l
|
|
1424
1511
|
});
|
|
1425
|
-
let
|
|
1426
|
-
if ((
|
|
1427
|
-
const
|
|
1512
|
+
let h = null;
|
|
1513
|
+
if ((p = g.status) != null && p.message) {
|
|
1514
|
+
const m = g.status.message.parts.filter(
|
|
1428
1515
|
(u) => u.type === "data" && "toolCallId" in u.data && ("arguments" in u.data || "result" in u.data)
|
|
1429
|
-
), y =
|
|
1516
|
+
), y = g.status.message.parts.filter(
|
|
1430
1517
|
(u) => u.type === "text"
|
|
1431
1518
|
);
|
|
1432
|
-
|
|
1519
|
+
h = {
|
|
1433
1520
|
role: "agent",
|
|
1434
1521
|
kind: "message",
|
|
1435
|
-
parts: [...
|
|
1436
|
-
messageId:
|
|
1522
|
+
parts: [...m, ...y],
|
|
1523
|
+
messageId: O(),
|
|
1437
1524
|
metadata: {
|
|
1438
1525
|
timestamp: Date.now()
|
|
1439
1526
|
}
|
|
1440
1527
|
};
|
|
1441
1528
|
}
|
|
1442
|
-
const
|
|
1443
|
-
...
|
|
1529
|
+
const T = [
|
|
1530
|
+
...d,
|
|
1444
1531
|
// Store only the new content from the user message (without history parts)
|
|
1445
|
-
|
|
1532
|
+
ot(n),
|
|
1446
1533
|
// Add complete agent response with tool calls/results if present
|
|
1447
|
-
...
|
|
1534
|
+
...h ? [K(h)] : []
|
|
1448
1535
|
];
|
|
1449
|
-
let
|
|
1450
|
-
if (
|
|
1451
|
-
const
|
|
1452
|
-
|
|
1536
|
+
let M = T;
|
|
1537
|
+
if (g.agentMessage) {
|
|
1538
|
+
const m = K(
|
|
1539
|
+
g.agentMessage
|
|
1453
1540
|
);
|
|
1454
|
-
|
|
1455
|
-
...
|
|
1456
|
-
|
|
1541
|
+
M = [
|
|
1542
|
+
...T,
|
|
1543
|
+
m
|
|
1457
1544
|
];
|
|
1458
1545
|
}
|
|
1459
|
-
return
|
|
1460
|
-
|
|
1461
|
-
|
|
1462
|
-
),
|
|
1546
|
+
return r.conversationHistory = M, a && await s(
|
|
1547
|
+
e,
|
|
1548
|
+
M
|
|
1549
|
+
), g;
|
|
1463
1550
|
},
|
|
1464
|
-
async *sendMessageStream(
|
|
1465
|
-
var
|
|
1466
|
-
const
|
|
1467
|
-
if (!
|
|
1468
|
-
throw new Error(`Agent with key "${
|
|
1551
|
+
async *sendMessageStream(e, n, o = {}) {
|
|
1552
|
+
var m, y, u, w, S, f;
|
|
1553
|
+
const r = t.get(e);
|
|
1554
|
+
if (!r)
|
|
1555
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1469
1556
|
const {
|
|
1470
|
-
withHistory:
|
|
1471
|
-
abortSignal:
|
|
1472
|
-
...
|
|
1473
|
-
} =
|
|
1474
|
-
|
|
1557
|
+
withHistory: a = !0,
|
|
1558
|
+
abortSignal: l,
|
|
1559
|
+
...i
|
|
1560
|
+
} = o, { client: d } = r, c = new AbortController();
|
|
1561
|
+
r.currentAbortController = c, l && l.addEventListener(
|
|
1475
1562
|
"abort",
|
|
1476
1563
|
() => c.abort()
|
|
1477
1564
|
);
|
|
1478
|
-
let
|
|
1479
|
-
...
|
|
1480
|
-
],
|
|
1481
|
-
const
|
|
1482
|
-
|
|
1565
|
+
let g = [
|
|
1566
|
+
...r.conversationHistory
|
|
1567
|
+
], h = [];
|
|
1568
|
+
const T = await ce(
|
|
1569
|
+
g
|
|
1483
1570
|
);
|
|
1484
|
-
|
|
1485
|
-
|
|
1486
|
-
|
|
1571
|
+
r.conversationHistory = T, g = T, a && await s(
|
|
1572
|
+
e,
|
|
1573
|
+
T
|
|
1487
1574
|
);
|
|
1488
|
-
const
|
|
1575
|
+
const M = o.message || mt(
|
|
1489
1576
|
n,
|
|
1490
|
-
k
|
|
1491
|
-
), T = ut(n);
|
|
1492
|
-
f = [
|
|
1493
|
-
...f,
|
|
1494
1577
|
T
|
|
1495
|
-
|
|
1496
|
-
|
|
1497
|
-
|
|
1578
|
+
), p = ot(n);
|
|
1579
|
+
g = [
|
|
1580
|
+
...g,
|
|
1581
|
+
p
|
|
1582
|
+
], r.conversationHistory = g, a && await s(
|
|
1583
|
+
e,
|
|
1584
|
+
g
|
|
1498
1585
|
);
|
|
1499
|
-
for await (const
|
|
1500
|
-
message:
|
|
1501
|
-
withHistory:
|
|
1586
|
+
for await (const C of d.sendMessageStream({
|
|
1587
|
+
message: M,
|
|
1588
|
+
withHistory: a,
|
|
1502
1589
|
abortSignal: c.signal,
|
|
1503
|
-
...
|
|
1590
|
+
...i
|
|
1504
1591
|
})) {
|
|
1505
|
-
if (((
|
|
1506
|
-
|
|
1507
|
-
|
|
1592
|
+
if (((m = C.status) == null ? void 0 : m.state) === "input-required" && ((y = C.status) != null && y.message)) {
|
|
1593
|
+
h = F(
|
|
1594
|
+
C.status.message
|
|
1508
1595
|
).map(
|
|
1509
|
-
(
|
|
1596
|
+
(x) => x.data.toolCallId
|
|
1510
1597
|
);
|
|
1511
|
-
const
|
|
1512
|
-
|
|
1598
|
+
const b = K(
|
|
1599
|
+
C.status.message
|
|
1513
1600
|
);
|
|
1514
|
-
|
|
1515
|
-
...
|
|
1516
|
-
|
|
1517
|
-
],
|
|
1518
|
-
|
|
1519
|
-
|
|
1601
|
+
g = [
|
|
1602
|
+
...g,
|
|
1603
|
+
b
|
|
1604
|
+
], r.conversationHistory = g, a && await s(
|
|
1605
|
+
e,
|
|
1606
|
+
g
|
|
1520
1607
|
);
|
|
1521
1608
|
}
|
|
1522
|
-
if (((u =
|
|
1523
|
-
const
|
|
1524
|
-
|
|
1609
|
+
if (((u = C.status) == null ? void 0 : u.state) === "working" && ((w = C.status) != null && w.message) && !C.final) {
|
|
1610
|
+
const b = le(
|
|
1611
|
+
C.status.message
|
|
1525
1612
|
).filter(
|
|
1526
|
-
(
|
|
1527
|
-
|
|
1613
|
+
(x) => h.includes(
|
|
1614
|
+
x.data.toolCallId
|
|
1528
1615
|
)
|
|
1529
1616
|
);
|
|
1530
|
-
if (
|
|
1531
|
-
const
|
|
1617
|
+
if (b.length > 0) {
|
|
1618
|
+
const x = {
|
|
1532
1619
|
role: "agent",
|
|
1533
1620
|
kind: "message",
|
|
1534
|
-
parts:
|
|
1535
|
-
messageId:
|
|
1621
|
+
parts: b,
|
|
1622
|
+
messageId: O()
|
|
1536
1623
|
};
|
|
1537
|
-
|
|
1538
|
-
...
|
|
1539
|
-
|
|
1540
|
-
],
|
|
1541
|
-
|
|
1542
|
-
|
|
1624
|
+
g = [
|
|
1625
|
+
...g,
|
|
1626
|
+
K(x)
|
|
1627
|
+
], r.conversationHistory = g, a && await s(
|
|
1628
|
+
e,
|
|
1629
|
+
g
|
|
1543
1630
|
);
|
|
1544
1631
|
}
|
|
1545
1632
|
}
|
|
1546
|
-
if (
|
|
1547
|
-
|
|
1548
|
-
let
|
|
1549
|
-
(
|
|
1550
|
-
|
|
1551
|
-
),
|
|
1552
|
-
...
|
|
1553
|
-
|
|
1554
|
-
],
|
|
1555
|
-
|
|
1556
|
-
|
|
1633
|
+
if (C.final && ((S = C.status) == null ? void 0 : S.state) !== "input-required") {
|
|
1634
|
+
h = [];
|
|
1635
|
+
let I = null;
|
|
1636
|
+
(f = C.status) != null && f.message && (I = K(
|
|
1637
|
+
C.status.message
|
|
1638
|
+
), g = [
|
|
1639
|
+
...g,
|
|
1640
|
+
I
|
|
1641
|
+
], r.conversationHistory = g, a && await s(
|
|
1642
|
+
e,
|
|
1643
|
+
g
|
|
1557
1644
|
));
|
|
1558
1645
|
}
|
|
1559
|
-
yield
|
|
1646
|
+
yield C;
|
|
1560
1647
|
}
|
|
1561
|
-
|
|
1648
|
+
r.currentAbortController = null;
|
|
1562
1649
|
},
|
|
1563
|
-
async resetConversation(
|
|
1564
|
-
const n = t.get(
|
|
1650
|
+
async resetConversation(e) {
|
|
1651
|
+
const n = t.get(e);
|
|
1565
1652
|
if (!n)
|
|
1566
|
-
throw new Error(`Agent with key "${
|
|
1567
|
-
n.conversationHistory = [], n.sessionId && await
|
|
1653
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1654
|
+
n.conversationHistory = [], n.sessionId && await re(
|
|
1568
1655
|
n.sessionId,
|
|
1569
1656
|
n.conversationStorageKey
|
|
1570
1657
|
);
|
|
1571
1658
|
},
|
|
1572
|
-
getConversationHistory(
|
|
1573
|
-
const n = t.get(
|
|
1659
|
+
getConversationHistory(e) {
|
|
1660
|
+
const n = t.get(e);
|
|
1574
1661
|
if (!n)
|
|
1575
|
-
throw new Error(`Agent with key "${
|
|
1662
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1576
1663
|
return [...n.conversationHistory];
|
|
1577
1664
|
},
|
|
1578
|
-
abortCurrentRequest(
|
|
1579
|
-
const n = t.get(
|
|
1665
|
+
abortCurrentRequest(e) {
|
|
1666
|
+
const n = t.get(e);
|
|
1580
1667
|
if (!n)
|
|
1581
|
-
throw new Error(`Agent with key "${
|
|
1668
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1582
1669
|
n.currentAbortController && (n.currentAbortController.abort(), n.currentAbortController = null);
|
|
1583
1670
|
},
|
|
1584
1671
|
clear() {
|
|
@@ -1586,991 +1673,460 @@ function Me() {
|
|
|
1586
1673
|
}
|
|
1587
1674
|
};
|
|
1588
1675
|
}
|
|
1589
|
-
const
|
|
1590
|
-
function
|
|
1591
|
-
return
|
|
1592
|
-
}
|
|
1593
|
-
class Te extends jt {
|
|
1594
|
-
constructor(e) {
|
|
1595
|
-
super(e), this.state = {
|
|
1596
|
-
hasError: !1,
|
|
1597
|
-
error: null,
|
|
1598
|
-
errorInfo: null
|
|
1599
|
-
};
|
|
1600
|
-
}
|
|
1601
|
-
static getDerivedStateFromError(e) {
|
|
1602
|
-
return {
|
|
1603
|
-
hasError: !0,
|
|
1604
|
-
error: e,
|
|
1605
|
-
errorInfo: null
|
|
1606
|
-
};
|
|
1607
|
-
}
|
|
1608
|
-
componentDidCatch(e, s) {
|
|
1609
|
-
if (console.error("Chart rendering error:", e), console.error("Error info:", s), this.props.chartData) {
|
|
1610
|
-
console.error(
|
|
1611
|
-
"Chart data that caused the error:",
|
|
1612
|
-
this.props.chartData
|
|
1613
|
-
);
|
|
1614
|
-
try {
|
|
1615
|
-
const n = JSON.parse(this.props.chartData);
|
|
1616
|
-
console.error("Parsed chart data:", n);
|
|
1617
|
-
} catch {
|
|
1618
|
-
console.error("Could not parse chart data as JSON");
|
|
1619
|
-
}
|
|
1620
|
-
}
|
|
1621
|
-
this.setState({
|
|
1622
|
-
errorInfo: s
|
|
1623
|
-
});
|
|
1624
|
-
}
|
|
1625
|
-
render() {
|
|
1626
|
-
var e;
|
|
1627
|
-
if (this.state.hasError) {
|
|
1628
|
-
const s = ((e = this.state.error) == null ? void 0 : e.message) || "An error occurred while rendering the chart", n = [
|
|
1629
|
-
"The chart could not be rendered due to an error.",
|
|
1630
|
-
"The error has been logged to the console."
|
|
1631
|
-
];
|
|
1632
|
-
return /* @__PURE__ */ $.jsx(
|
|
1633
|
-
st,
|
|
1634
|
-
{
|
|
1635
|
-
message: s,
|
|
1636
|
-
details: n.join(`
|
|
1637
|
-
`)
|
|
1638
|
-
}
|
|
1639
|
-
);
|
|
1640
|
-
}
|
|
1641
|
-
return this.props.children;
|
|
1642
|
-
}
|
|
1643
|
-
}
|
|
1644
|
-
const Se = (t) => {
|
|
1645
|
-
const {
|
|
1646
|
-
data: e,
|
|
1647
|
-
currency: s,
|
|
1648
|
-
showLegend: n = !0,
|
|
1649
|
-
withTooltips: a = !0,
|
|
1650
|
-
renderTooltip: o,
|
|
1651
|
-
margin: r,
|
|
1652
|
-
withGradientFill: i = !0,
|
|
1653
|
-
error: l,
|
|
1654
|
-
...g
|
|
1655
|
-
} = t, c = {
|
|
1656
|
-
...Ft(),
|
|
1657
|
-
bottom: 80
|
|
1658
|
-
}, f = {
|
|
1659
|
-
data: e,
|
|
1660
|
-
withTooltips: a,
|
|
1661
|
-
renderTooltip: o,
|
|
1662
|
-
showLegend: n,
|
|
1663
|
-
withGradientFill: i,
|
|
1664
|
-
withLegendGlyph: !1,
|
|
1665
|
-
legendOrientation: "horizontal",
|
|
1666
|
-
legendAlignmentHorizontal: "center",
|
|
1667
|
-
legendAlignmentVertical: "bottom",
|
|
1668
|
-
margin: c,
|
|
1669
|
-
options: {
|
|
1670
|
-
xScale: {
|
|
1671
|
-
type: "time"
|
|
1672
|
-
},
|
|
1673
|
-
axis: {
|
|
1674
|
-
x: {
|
|
1675
|
-
...qt(e)
|
|
1676
|
-
}
|
|
1677
|
-
}
|
|
1678
|
-
},
|
|
1679
|
-
...s && { currency: s },
|
|
1680
|
-
...g
|
|
1681
|
-
};
|
|
1682
|
-
return /* @__PURE__ */ $.jsx(Ht, { error: l, children: /* @__PURE__ */ $.jsx(Lt, { ...f }) });
|
|
1683
|
-
}, ke = ({
|
|
1684
|
-
data: t,
|
|
1685
|
-
className: e = "",
|
|
1686
|
-
config: s
|
|
1687
|
-
}) => {
|
|
1688
|
-
const [n, a] = Q(null), [o, r] = Q(
|
|
1689
|
-
null
|
|
1690
|
-
), [i, l] = Q(300), g = bt(null), c = F(
|
|
1691
|
-
(y) => {
|
|
1692
|
-
var v;
|
|
1693
|
-
const { tooltipData: u } = y, h = (v = u == null ? void 0 : u.nearestDatum) == null ? void 0 : v.datum;
|
|
1694
|
-
if (!h)
|
|
1695
|
-
return null;
|
|
1696
|
-
const p = (d) => {
|
|
1697
|
-
if (o != null && o.currency) {
|
|
1698
|
-
const { symbol: C, symbolPosition: x } = o.currency;
|
|
1699
|
-
let S;
|
|
1700
|
-
return d >= 1e6 ? S = `${(d / 1e6).toFixed(
|
|
1701
|
-
1
|
|
1702
|
-
)}M` : d >= 1e3 ? S = `${(d / 1e3).toFixed(1)}K` : S = d.toLocaleString(), x === "right" ? `${S}${C}` : `${C}${S}`;
|
|
1703
|
-
}
|
|
1704
|
-
return d >= 1e6 ? `${(d / 1e6).toFixed(1)}M` : d >= 1e3 ? `${(d / 1e3).toFixed(1)}K` : d.toLocaleString();
|
|
1705
|
-
}, m = (d) => {
|
|
1706
|
-
const x = Math.floor(
|
|
1707
|
-
((/* @__PURE__ */ new Date()).getTime() - d.getTime()) / (1e3 * 60 * 60 * 24)
|
|
1708
|
-
);
|
|
1709
|
-
return x === 0 ? q("Today", "a8c-agenttic") : x === 1 ? q("Yesterday", "a8c-agenttic") : x < 7 ? ht(
|
|
1710
|
-
/* translators: %d: number of days */
|
|
1711
|
-
q("%d days ago", "a8c-agenttic"),
|
|
1712
|
-
x
|
|
1713
|
-
) : d.toLocaleDateString("en-US", {
|
|
1714
|
-
year: "numeric",
|
|
1715
|
-
month: "short",
|
|
1716
|
-
day: "numeric"
|
|
1717
|
-
});
|
|
1718
|
-
}, w = h.label, b = Object.entries(
|
|
1719
|
-
(u == null ? void 0 : u.datumByKey) || {}
|
|
1720
|
-
).map(([d, C]) => {
|
|
1721
|
-
const x = C.datum;
|
|
1722
|
-
return {
|
|
1723
|
-
key: d,
|
|
1724
|
-
value: x.value
|
|
1725
|
-
};
|
|
1726
|
-
}).sort((d, C) => C.value - d.value);
|
|
1727
|
-
return /* @__PURE__ */ $.jsxs("div", { children: [
|
|
1728
|
-
w && /* @__PURE__ */ $.jsx(
|
|
1729
|
-
"div",
|
|
1730
|
-
{
|
|
1731
|
-
style: {
|
|
1732
|
-
fontSize: "12px",
|
|
1733
|
-
fontWeight: "bold",
|
|
1734
|
-
marginBottom: "4px",
|
|
1735
|
-
color: "#1e1e1e",
|
|
1736
|
-
borderBottom: "1px solid #eee",
|
|
1737
|
-
paddingBottom: "2px"
|
|
1738
|
-
},
|
|
1739
|
-
children: w
|
|
1740
|
-
}
|
|
1741
|
-
),
|
|
1742
|
-
h.date && /* @__PURE__ */ $.jsx(
|
|
1743
|
-
"div",
|
|
1744
|
-
{
|
|
1745
|
-
style: {
|
|
1746
|
-
fontSize: "10px",
|
|
1747
|
-
opacity: 0.8,
|
|
1748
|
-
marginBottom: "4px"
|
|
1749
|
-
},
|
|
1750
|
-
children: m(h.date)
|
|
1751
|
-
}
|
|
1752
|
-
),
|
|
1753
|
-
b.map((d) => /* @__PURE__ */ $.jsxs(
|
|
1754
|
-
"div",
|
|
1755
|
-
{
|
|
1756
|
-
style: { marginBottom: "2px" },
|
|
1757
|
-
children: [
|
|
1758
|
-
/* @__PURE__ */ $.jsxs("strong", { children: [
|
|
1759
|
-
d.key,
|
|
1760
|
-
":"
|
|
1761
|
-
] }),
|
|
1762
|
-
" ",
|
|
1763
|
-
p(d.value)
|
|
1764
|
-
]
|
|
1765
|
-
},
|
|
1766
|
-
d.key
|
|
1767
|
-
))
|
|
1768
|
-
] });
|
|
1769
|
-
},
|
|
1770
|
-
[o == null ? void 0 : o.currency]
|
|
1771
|
-
);
|
|
1772
|
-
X(() => {
|
|
1773
|
-
if (a(null), r(null), !t || typeof t != "string") {
|
|
1774
|
-
a({
|
|
1775
|
-
message: q("Invalid chart data provided", "a8c-agenttic"),
|
|
1776
|
-
details: `Input data: ${t}`
|
|
1777
|
-
});
|
|
1778
|
-
return;
|
|
1779
|
-
}
|
|
1780
|
-
try {
|
|
1781
|
-
const y = JSON.parse(t.trim());
|
|
1782
|
-
if (!y.chartType) {
|
|
1783
|
-
a({
|
|
1784
|
-
message: q(
|
|
1785
|
-
"Chart data must include chartType",
|
|
1786
|
-
"a8c-agenttic"
|
|
1787
|
-
),
|
|
1788
|
-
details: q("Available types: line, bar", "a8c-agenttic")
|
|
1789
|
-
});
|
|
1790
|
-
return;
|
|
1791
|
-
}
|
|
1792
|
-
if (!y.data || !Array.isArray(y.data)) {
|
|
1793
|
-
a({
|
|
1794
|
-
message: q(
|
|
1795
|
-
"Chart data must include a data array",
|
|
1796
|
-
"a8c-agenttic"
|
|
1797
|
-
),
|
|
1798
|
-
details: `Input data: ${t}`
|
|
1799
|
-
});
|
|
1800
|
-
return;
|
|
1801
|
-
}
|
|
1802
|
-
if (y.data.length === 0) {
|
|
1803
|
-
a({
|
|
1804
|
-
message: q(
|
|
1805
|
-
"No data points found for chart",
|
|
1806
|
-
"a8c-agenttic"
|
|
1807
|
-
),
|
|
1808
|
-
details: `Input data: ${t}`
|
|
1809
|
-
});
|
|
1810
|
-
return;
|
|
1811
|
-
}
|
|
1812
|
-
const u = y.data.map((p) => ({
|
|
1813
|
-
...p,
|
|
1814
|
-
data: p.data.map((m) => {
|
|
1815
|
-
if (m.date) {
|
|
1816
|
-
const w = new Date(m.date);
|
|
1817
|
-
return isNaN(w.getTime()) ? (console.warn(
|
|
1818
|
-
`Invalid date string: "${m.date}" in series "${p.label}"`
|
|
1819
|
-
), {
|
|
1820
|
-
label: m.label,
|
|
1821
|
-
value: m.value,
|
|
1822
|
-
date: void 0
|
|
1823
|
-
}) : {
|
|
1824
|
-
label: m.label,
|
|
1825
|
-
value: m.value,
|
|
1826
|
-
date: w
|
|
1827
|
-
};
|
|
1828
|
-
}
|
|
1829
|
-
return {
|
|
1830
|
-
label: m.label,
|
|
1831
|
-
value: m.value,
|
|
1832
|
-
date: void 0
|
|
1833
|
-
};
|
|
1834
|
-
})
|
|
1835
|
-
})), h = {
|
|
1836
|
-
chartType: y.chartType,
|
|
1837
|
-
title: y.title,
|
|
1838
|
-
data: u,
|
|
1839
|
-
currency: y.currency,
|
|
1840
|
-
mode: y.mode || "time-comparison"
|
|
1841
|
-
};
|
|
1842
|
-
r(h);
|
|
1843
|
-
} catch {
|
|
1844
|
-
a({
|
|
1845
|
-
message: q(
|
|
1846
|
-
"Failed to parse chart data as JSON",
|
|
1847
|
-
"a8c-agenttic"
|
|
1848
|
-
),
|
|
1849
|
-
details: `Input data: ${t}`
|
|
1850
|
-
});
|
|
1851
|
-
}
|
|
1852
|
-
}, [t]);
|
|
1853
|
-
const f = F((y) => {
|
|
1854
|
-
if (g.current && g.current.disconnect(), y) {
|
|
1855
|
-
const { width: u } = y.getBoundingClientRect(), h = Math.max(280, u - 4);
|
|
1856
|
-
l(h), g.current = new ResizeObserver((p) => {
|
|
1857
|
-
for (const m of p) {
|
|
1858
|
-
const w = m.contentRect.width, b = Math.max(
|
|
1859
|
-
280,
|
|
1860
|
-
w - 4
|
|
1861
|
-
);
|
|
1862
|
-
l(b);
|
|
1863
|
-
}
|
|
1864
|
-
}), g.current.observe(y);
|
|
1865
|
-
}
|
|
1866
|
-
}, []);
|
|
1867
|
-
if (X(() => () => {
|
|
1868
|
-
g.current && (g.current.disconnect(), g.current = null);
|
|
1869
|
-
}, []), n)
|
|
1870
|
-
return /* @__PURE__ */ $.jsx(st, { message: n.message, details: n.details });
|
|
1871
|
-
if (!o)
|
|
1872
|
-
return /* @__PURE__ */ $.jsx(
|
|
1873
|
-
st,
|
|
1874
|
-
{
|
|
1875
|
-
message: q("No chart data available", "a8c-agenttic")
|
|
1876
|
-
}
|
|
1877
|
-
);
|
|
1878
|
-
const k = o.data.length > 1, A = i, T = {
|
|
1879
|
-
data: o.data,
|
|
1880
|
-
currency: o.currency,
|
|
1881
|
-
showLegend: k,
|
|
1882
|
-
withTooltips: !0,
|
|
1883
|
-
renderTooltip: c,
|
|
1884
|
-
error: null,
|
|
1885
|
-
maxWidth: A,
|
|
1886
|
-
aspectRatio: 1.2,
|
|
1887
|
-
resizeDebounceTime: 300
|
|
1888
|
-
}, M = () => {
|
|
1889
|
-
switch (o.chartType) {
|
|
1890
|
-
case "line":
|
|
1891
|
-
return /* @__PURE__ */ $.jsx(Se, { ...T });
|
|
1892
|
-
case "bar":
|
|
1893
|
-
return /* @__PURE__ */ $.jsx(
|
|
1894
|
-
Ut,
|
|
1895
|
-
{
|
|
1896
|
-
...T,
|
|
1897
|
-
mode: o.mode
|
|
1898
|
-
}
|
|
1899
|
-
);
|
|
1900
|
-
default:
|
|
1901
|
-
return /* @__PURE__ */ $.jsx(
|
|
1902
|
-
st,
|
|
1903
|
-
{
|
|
1904
|
-
message: ht(
|
|
1905
|
-
/* translators: %s: chart type name */
|
|
1906
|
-
q("Unsupported chart type: %s", "a8c-agenttic"),
|
|
1907
|
-
o.chartType
|
|
1908
|
-
)
|
|
1909
|
-
}
|
|
1910
|
-
);
|
|
1911
|
-
}
|
|
1912
|
-
};
|
|
1913
|
-
return /* @__PURE__ */ $.jsx(Te, { chartData: t, children: /* @__PURE__ */ $.jsxs(
|
|
1914
|
-
"div",
|
|
1915
|
-
{
|
|
1916
|
-
ref: f,
|
|
1917
|
-
className: `chart-block ${e}`,
|
|
1918
|
-
children: [
|
|
1919
|
-
o.title && /* @__PURE__ */ $.jsx("h3", { className: "chart-block-title", children: o.title }),
|
|
1920
|
-
/* @__PURE__ */ $.jsx("div", { className: "chart-container", children: M() })
|
|
1921
|
-
]
|
|
1922
|
-
}
|
|
1923
|
-
) });
|
|
1924
|
-
};
|
|
1925
|
-
function Ae(t) {
|
|
1926
|
-
return function(s) {
|
|
1927
|
-
const { children: n, className: a, ...o } = s;
|
|
1928
|
-
if (!(a == null ? void 0 : a.includes("language-chart")))
|
|
1929
|
-
return nt.createElement(
|
|
1930
|
-
"code",
|
|
1931
|
-
{ className: a, ...o },
|
|
1932
|
-
n
|
|
1933
|
-
);
|
|
1934
|
-
const i = typeof n == "string" ? n : "";
|
|
1935
|
-
return nt.createElement(ke, {
|
|
1936
|
-
data: i,
|
|
1937
|
-
className: "markdown-chart",
|
|
1938
|
-
config: t
|
|
1939
|
-
});
|
|
1940
|
-
};
|
|
1941
|
-
}
|
|
1942
|
-
function ve(t) {
|
|
1943
|
-
var n, a;
|
|
1944
|
-
const e = {}, s = [];
|
|
1945
|
-
return (n = t == null ? void 0 : t.charts) != null && n.enabled && (e.code = Ae(t.charts.config)), (a = t == null ? void 0 : t.gfm) != null && a.enabled && s.push(Jt), { components: e, remarkPlugins: s };
|
|
1946
|
-
}
|
|
1947
|
-
function Re(t, e = {}) {
|
|
1948
|
-
return {
|
|
1949
|
-
...t,
|
|
1950
|
-
...e
|
|
1951
|
-
};
|
|
1676
|
+
const de = ue();
|
|
1677
|
+
function st() {
|
|
1678
|
+
return de;
|
|
1952
1679
|
}
|
|
1953
|
-
|
|
1954
|
-
|
|
1955
|
-
|
|
1956
|
-
|
|
1957
|
-
|
|
1958
|
-
|
|
1959
|
-
parseIncompleteMarkdown: t.parseIncompleteMarkdown,
|
|
1960
|
-
parseMarkdownIntoBlocks: e.parseMarkdownIntoBlocks
|
|
1961
|
-
}, tt)), et);
|
|
1962
|
-
}
|
|
1963
|
-
function Pe(t = {}) {
|
|
1964
|
-
const {
|
|
1965
|
-
components: e = {},
|
|
1966
|
-
extensions: s = {},
|
|
1967
|
-
remarkPlugins: n = [],
|
|
1968
|
-
enableStreaming: a = !1
|
|
1969
|
-
} = t, o = ve(s), r = Re(
|
|
1970
|
-
o.components,
|
|
1971
|
-
e
|
|
1972
|
-
), i = [...o.remarkPlugins, ...n];
|
|
1973
|
-
return function({ children: g }) {
|
|
1974
|
-
const [c, f] = nt.useState(g);
|
|
1975
|
-
return nt.useEffect(() => {
|
|
1976
|
-
a ? Ee().then(async (I) => {
|
|
1977
|
-
const A = (await I.parseMarkdownIntoBlocks(g)).map((T) => I.parseIncompleteMarkdown(
|
|
1978
|
-
T.trim()
|
|
1979
|
-
)).join(`
|
|
1980
|
-
|
|
1981
|
-
`);
|
|
1982
|
-
f(A);
|
|
1983
|
-
}).catch(() => {
|
|
1984
|
-
f(g);
|
|
1985
|
-
}) : f(g);
|
|
1986
|
-
}, [g]), /* @__PURE__ */ $.jsx(
|
|
1987
|
-
Bt,
|
|
1988
|
-
{
|
|
1989
|
-
components: r,
|
|
1990
|
-
remarkPlugins: i,
|
|
1991
|
-
children: c
|
|
1992
|
-
}
|
|
1993
|
-
);
|
|
1994
|
-
};
|
|
1995
|
-
}
|
|
1996
|
-
const Oe = (t) => {
|
|
1997
|
-
const e = t.condition || (() => !0), s = {}, n = [], a = () => {
|
|
1998
|
-
n.forEach((r) => r());
|
|
1999
|
-
}, o = async (r, i) => {
|
|
2000
|
-
s[r] = i, await t.onFeedback(r, i), a();
|
|
2001
|
-
};
|
|
2002
|
-
return {
|
|
2003
|
-
getActionsForMessage: (r) => {
|
|
2004
|
-
if (!e(r))
|
|
2005
|
-
return [];
|
|
2006
|
-
const i = s[r.id], l = [];
|
|
2007
|
-
return l.push({
|
|
2008
|
-
id: "feedback-up",
|
|
2009
|
-
icon: t.icons.up,
|
|
2010
|
-
label: "Good response",
|
|
2011
|
-
onClick: async () => {
|
|
2012
|
-
i === "up" ? delete s[r.id] : await o(r.id, "up"), a();
|
|
2013
|
-
},
|
|
2014
|
-
tooltip: "This response was helpful",
|
|
2015
|
-
pressed: i === "up",
|
|
2016
|
-
disabled: i === "down"
|
|
2017
|
-
// Disable if other is selected
|
|
2018
|
-
}), l.push({
|
|
2019
|
-
id: "feedback-down",
|
|
2020
|
-
icon: t.icons.down,
|
|
2021
|
-
label: "Bad response",
|
|
2022
|
-
onClick: async () => {
|
|
2023
|
-
i === "down" ? delete s[r.id] : await o(r.id, "down"), a();
|
|
2024
|
-
},
|
|
2025
|
-
tooltip: "This response was not helpful",
|
|
2026
|
-
pressed: i === "down",
|
|
2027
|
-
disabled: i === "up"
|
|
2028
|
-
// Disable if other is selected
|
|
2029
|
-
}), l;
|
|
2030
|
-
},
|
|
2031
|
-
clearFeedback: (r) => {
|
|
2032
|
-
delete s[r], a();
|
|
2033
|
-
},
|
|
2034
|
-
clearAllFeedback: () => {
|
|
2035
|
-
Object.keys(s).forEach((r) => {
|
|
2036
|
-
delete s[r];
|
|
2037
|
-
}), a();
|
|
2038
|
-
},
|
|
2039
|
-
onChange: (r) => {
|
|
2040
|
-
n.push(r);
|
|
2041
|
-
},
|
|
2042
|
-
offChange: (r) => {
|
|
2043
|
-
const i = n.indexOf(r);
|
|
2044
|
-
i > -1 && n.splice(i, 1);
|
|
2045
|
-
}
|
|
2046
|
-
};
|
|
2047
|
-
};
|
|
2048
|
-
function Ne() {
|
|
2049
|
-
const [t, e] = Q([]), s = F(
|
|
2050
|
-
(o) => {
|
|
2051
|
-
e((r) => {
|
|
2052
|
-
const i = r.findIndex(
|
|
2053
|
-
(l) => l.id === o.id
|
|
1680
|
+
function ge() {
|
|
1681
|
+
const [t, s] = ht([]), e = H(
|
|
1682
|
+
(r) => {
|
|
1683
|
+
s((a) => {
|
|
1684
|
+
const l = a.findIndex(
|
|
1685
|
+
(i) => i.id === r.id
|
|
2054
1686
|
);
|
|
2055
|
-
if (
|
|
2056
|
-
const
|
|
2057
|
-
return l
|
|
1687
|
+
if (l >= 0) {
|
|
1688
|
+
const i = [...a];
|
|
1689
|
+
return i[l] = r, i;
|
|
2058
1690
|
}
|
|
2059
|
-
return [...
|
|
1691
|
+
return [...a, r];
|
|
2060
1692
|
});
|
|
2061
1693
|
},
|
|
2062
1694
|
[]
|
|
2063
|
-
), n =
|
|
2064
|
-
|
|
2065
|
-
}, []),
|
|
2066
|
-
|
|
1695
|
+
), n = H((r) => {
|
|
1696
|
+
s((a) => a.filter((l) => l.id !== r));
|
|
1697
|
+
}, []), o = H(() => {
|
|
1698
|
+
s([]);
|
|
2067
1699
|
}, []);
|
|
2068
1700
|
return {
|
|
2069
|
-
registerMessageActions:
|
|
1701
|
+
registerMessageActions: e,
|
|
2070
1702
|
unregisterMessageActions: n,
|
|
2071
|
-
clearAllMessageActions:
|
|
2072
|
-
createFeedbackActions: Oe,
|
|
1703
|
+
clearAllMessageActions: o,
|
|
2073
1704
|
registrations: t
|
|
2074
1705
|
};
|
|
2075
1706
|
}
|
|
2076
|
-
function
|
|
2077
|
-
return
|
|
2078
|
-
id:
|
|
2079
|
-
label:
|
|
2080
|
-
icon:
|
|
2081
|
-
onClick:
|
|
2082
|
-
tooltip:
|
|
2083
|
-
disabled:
|
|
2084
|
-
pressed:
|
|
2085
|
-
showLabel:
|
|
1707
|
+
function fe(t, s) {
|
|
1708
|
+
return s.flatMap((o) => typeof o.actions == "function" ? o.actions(t) : o.actions).filter((o) => !(o.condition && !o.condition(t))).map((o) => ({
|
|
1709
|
+
id: o.id,
|
|
1710
|
+
label: o.label,
|
|
1711
|
+
icon: o.icon,
|
|
1712
|
+
onClick: o.onClick,
|
|
1713
|
+
tooltip: o.tooltip,
|
|
1714
|
+
disabled: o.disabled || !1,
|
|
1715
|
+
pressed: o.pressed,
|
|
1716
|
+
showLabel: o.showLabel
|
|
2086
1717
|
}));
|
|
2087
1718
|
}
|
|
2088
|
-
const
|
|
2089
|
-
var
|
|
2090
|
-
if (t.parts.some((
|
|
2091
|
-
if (
|
|
2092
|
-
const
|
|
2093
|
-
return
|
|
1719
|
+
const nt = (t) => [...t].sort((s, e) => s.timestamp - e.timestamp), z = (t, s = []) => {
|
|
1720
|
+
var a;
|
|
1721
|
+
if (t.parts.some((l) => {
|
|
1722
|
+
if (l.type === "data") {
|
|
1723
|
+
const i = l.data;
|
|
1724
|
+
return i.toolCallId || i.toolId || i.result;
|
|
2094
1725
|
}
|
|
2095
1726
|
return !1;
|
|
2096
1727
|
}))
|
|
2097
1728
|
return null;
|
|
2098
|
-
const n = t.parts.map((
|
|
2099
|
-
if (
|
|
1729
|
+
const n = t.parts.map((l) => {
|
|
1730
|
+
if (l.type === "text")
|
|
2100
1731
|
return {
|
|
2101
1732
|
type: "text",
|
|
2102
|
-
text:
|
|
1733
|
+
text: l.text
|
|
2103
1734
|
};
|
|
2104
|
-
if (
|
|
1735
|
+
if (l.type === "file")
|
|
2105
1736
|
return {
|
|
2106
1737
|
type: "image_url",
|
|
2107
|
-
image_url:
|
|
1738
|
+
image_url: l.file.uri || `data:${l.file.mimeType};base64,${l.file.bytes}`
|
|
2108
1739
|
};
|
|
2109
|
-
if (
|
|
2110
|
-
const
|
|
2111
|
-
return
|
|
1740
|
+
if (l.type === "data") {
|
|
1741
|
+
const i = l.data;
|
|
1742
|
+
return i.component && i.componentProps ? {
|
|
2112
1743
|
type: "component",
|
|
2113
|
-
component:
|
|
2114
|
-
componentProps:
|
|
1744
|
+
component: i.component,
|
|
1745
|
+
componentProps: i.componentProps
|
|
2115
1746
|
} : {
|
|
2116
1747
|
type: "text",
|
|
2117
|
-
text: JSON.stringify(
|
|
1748
|
+
text: JSON.stringify(i)
|
|
2118
1749
|
};
|
|
2119
1750
|
}
|
|
2120
1751
|
return {
|
|
2121
1752
|
type: "text",
|
|
2122
1753
|
text: "[Unsupported content]"
|
|
2123
1754
|
};
|
|
2124
|
-
}),
|
|
1755
|
+
}), o = ((a = t.metadata) == null ? void 0 : a.timestamp) ?? Date.now(), r = {
|
|
2125
1756
|
id: t.messageId,
|
|
2126
1757
|
role: t.role === "agent" ? "agent" : "user",
|
|
2127
1758
|
content: n,
|
|
2128
|
-
timestamp:
|
|
1759
|
+
timestamp: o,
|
|
2129
1760
|
archived: !1,
|
|
2130
1761
|
showIcon: t.role === "agent",
|
|
2131
1762
|
icon: t.role === "agent" ? "assistant" : void 0
|
|
2132
1763
|
};
|
|
2133
|
-
if (t.role === "agent" &&
|
|
2134
|
-
const
|
|
2135
|
-
|
|
2136
|
-
|
|
1764
|
+
if (t.role === "agent" && s.length > 0) {
|
|
1765
|
+
const l = fe(
|
|
1766
|
+
r,
|
|
1767
|
+
s
|
|
2137
1768
|
);
|
|
2138
|
-
|
|
1769
|
+
l.length > 0 && (r.actions = l);
|
|
2139
1770
|
}
|
|
2140
|
-
return
|
|
2141
|
-
},
|
|
1771
|
+
return r;
|
|
1772
|
+
}, me = () => ({
|
|
2142
1773
|
getClientContext: () => ({})
|
|
2143
|
-
}),
|
|
1774
|
+
}), pe = () => ({
|
|
2144
1775
|
getAvailableTools: async () => [],
|
|
2145
1776
|
executeTool: async () => ({
|
|
2146
1777
|
success: !0,
|
|
2147
1778
|
result: "No tools available"
|
|
2148
1779
|
})
|
|
2149
|
-
}),
|
|
2150
|
-
const n = t[
|
|
1780
|
+
}), he = (t) => ["agentId", "agentUrl", "sessionId"].every((e) => {
|
|
1781
|
+
const n = t[e];
|
|
2151
1782
|
return typeof n == "string" && n.trim().length > 0;
|
|
2152
1783
|
});
|
|
2153
|
-
function
|
|
2154
|
-
const
|
|
1784
|
+
function Ee(t) {
|
|
1785
|
+
const s = {
|
|
2155
1786
|
agentId: t.agentId,
|
|
2156
1787
|
agentUrl: t.agentUrl,
|
|
2157
1788
|
sessionId: t.sessionId
|
|
2158
|
-
},
|
|
1789
|
+
}, e = he(s), [n, o] = ht({
|
|
2159
1790
|
clientMessages: [],
|
|
2160
1791
|
uiMessages: [],
|
|
2161
1792
|
isProcessing: !1,
|
|
2162
|
-
error:
|
|
2163
|
-
suggestions: []
|
|
2164
|
-
markdownComponents: {},
|
|
2165
|
-
markdownExtensions: {}
|
|
1793
|
+
error: e ? null : "Invalid agent configuration",
|
|
1794
|
+
suggestions: []
|
|
2166
1795
|
}), {
|
|
2167
|
-
registerMessageActions:
|
|
2168
|
-
unregisterMessageActions:
|
|
2169
|
-
clearAllMessageActions:
|
|
2170
|
-
|
|
2171
|
-
|
|
2172
|
-
|
|
2173
|
-
|
|
2174
|
-
|
|
2175
|
-
|
|
2176
|
-
if (!s)
|
|
1796
|
+
registerMessageActions: r,
|
|
1797
|
+
unregisterMessageActions: a,
|
|
1798
|
+
clearAllMessageActions: l,
|
|
1799
|
+
registrations: i
|
|
1800
|
+
} = ge(), d = Et(i);
|
|
1801
|
+
tt(() => {
|
|
1802
|
+
d.current = i;
|
|
1803
|
+
}, [i]), tt(() => {
|
|
1804
|
+
if (!e)
|
|
2177
1805
|
return;
|
|
2178
1806
|
(async () => {
|
|
2179
|
-
if (
|
|
2180
|
-
const
|
|
2181
|
-
if (!
|
|
2182
|
-
await
|
|
2183
|
-
agentId:
|
|
2184
|
-
agentUrl:
|
|
2185
|
-
sessionId:
|
|
2186
|
-
contextProvider: t.contextProvider ||
|
|
2187
|
-
toolProvider: t.toolProvider ||
|
|
1807
|
+
if (s.sessionId) {
|
|
1808
|
+
const m = st(), y = `${s.agentId}-${s.sessionId}`;
|
|
1809
|
+
if (!m.hasAgent(y)) {
|
|
1810
|
+
await m.createAgent(y, {
|
|
1811
|
+
agentId: s.agentId,
|
|
1812
|
+
agentUrl: s.agentUrl,
|
|
1813
|
+
sessionId: s.sessionId,
|
|
1814
|
+
contextProvider: t.contextProvider || me(),
|
|
1815
|
+
toolProvider: t.toolProvider || pe(),
|
|
2188
1816
|
authProvider: t.authProvider,
|
|
2189
1817
|
enableStreaming: t.enableStreaming
|
|
2190
1818
|
});
|
|
2191
|
-
const
|
|
2192
|
-
|
|
2193
|
-
const
|
|
2194
|
-
(
|
|
2195
|
-
|
|
2196
|
-
|
|
1819
|
+
const u = m.getConversationHistory(y);
|
|
1820
|
+
o((w) => {
|
|
1821
|
+
const S = u.map(
|
|
1822
|
+
(f) => z(
|
|
1823
|
+
f,
|
|
1824
|
+
d.current
|
|
2197
1825
|
)
|
|
2198
1826
|
).filter(
|
|
2199
|
-
(
|
|
1827
|
+
(f) => f !== null
|
|
2200
1828
|
);
|
|
2201
1829
|
return {
|
|
2202
|
-
...
|
|
2203
|
-
clientMessages:
|
|
2204
|
-
uiMessages:
|
|
1830
|
+
...w,
|
|
1831
|
+
clientMessages: u,
|
|
1832
|
+
uiMessages: S
|
|
2205
1833
|
};
|
|
2206
1834
|
});
|
|
2207
1835
|
}
|
|
2208
1836
|
}
|
|
2209
1837
|
})();
|
|
2210
1838
|
}, [
|
|
2211
|
-
|
|
2212
|
-
|
|
2213
|
-
|
|
1839
|
+
s.sessionId,
|
|
1840
|
+
s.agentId,
|
|
1841
|
+
s.agentUrl,
|
|
2214
1842
|
t.contextProvider,
|
|
2215
1843
|
t.toolProvider,
|
|
2216
1844
|
t.authProvider,
|
|
2217
1845
|
t.enableStreaming,
|
|
2218
|
-
|
|
1846
|
+
e
|
|
2219
1847
|
]);
|
|
2220
|
-
const
|
|
2221
|
-
async (
|
|
2222
|
-
var
|
|
2223
|
-
if (!
|
|
1848
|
+
const c = H(
|
|
1849
|
+
async (p) => {
|
|
1850
|
+
var S;
|
|
1851
|
+
if (!e)
|
|
2224
1852
|
throw new Error("Invalid agent configuration");
|
|
2225
|
-
const
|
|
2226
|
-
id: `user-${
|
|
1853
|
+
const m = st(), y = `${s.agentId}-${s.sessionId}`, u = Date.now(), w = {
|
|
1854
|
+
id: `user-${u}`,
|
|
2227
1855
|
role: "user",
|
|
2228
|
-
content: [{ type: "text", text:
|
|
2229
|
-
timestamp:
|
|
1856
|
+
content: [{ type: "text", text: p }],
|
|
1857
|
+
timestamp: u,
|
|
2230
1858
|
archived: !1,
|
|
2231
1859
|
showIcon: !1
|
|
2232
1860
|
};
|
|
2233
|
-
|
|
2234
|
-
...
|
|
2235
|
-
uiMessages: [...
|
|
1861
|
+
o((f) => ({
|
|
1862
|
+
...f,
|
|
1863
|
+
uiMessages: [...f.uiMessages, w],
|
|
2236
1864
|
isProcessing: !0,
|
|
2237
1865
|
error: null
|
|
2238
1866
|
}));
|
|
2239
1867
|
try {
|
|
2240
|
-
let
|
|
2241
|
-
for await (const
|
|
2242
|
-
|
|
2243
|
-
|
|
1868
|
+
let f = null, C = !1;
|
|
1869
|
+
for await (const I of m.sendMessageStream(
|
|
1870
|
+
y,
|
|
1871
|
+
p
|
|
2244
1872
|
)) {
|
|
2245
|
-
if (!
|
|
2246
|
-
if (
|
|
2247
|
-
|
|
2248
|
-
...
|
|
2249
|
-
uiMessages:
|
|
2250
|
-
(
|
|
2251
|
-
...
|
|
1873
|
+
if (!I.final && I.text)
|
|
1874
|
+
if (f)
|
|
1875
|
+
o((b) => ({
|
|
1876
|
+
...b,
|
|
1877
|
+
uiMessages: b.uiMessages.map(
|
|
1878
|
+
(x) => x.id === f ? {
|
|
1879
|
+
...x,
|
|
2252
1880
|
content: [
|
|
2253
1881
|
{
|
|
2254
1882
|
type: "text",
|
|
2255
|
-
text:
|
|
1883
|
+
text: I.text
|
|
2256
1884
|
}
|
|
2257
1885
|
]
|
|
2258
|
-
} :
|
|
1886
|
+
} : x
|
|
2259
1887
|
)
|
|
2260
1888
|
}));
|
|
2261
1889
|
else {
|
|
2262
|
-
|
|
2263
|
-
const
|
|
2264
|
-
id:
|
|
1890
|
+
f = `agent-streaming-${Date.now()}`;
|
|
1891
|
+
const b = {
|
|
1892
|
+
id: f,
|
|
2265
1893
|
role: "agent",
|
|
2266
1894
|
content: [
|
|
2267
|
-
{ type: "text", text:
|
|
1895
|
+
{ type: "text", text: I.text }
|
|
2268
1896
|
],
|
|
2269
1897
|
timestamp: Date.now(),
|
|
2270
1898
|
archived: !1,
|
|
2271
1899
|
showIcon: !0,
|
|
2272
1900
|
icon: "assistant"
|
|
2273
1901
|
};
|
|
2274
|
-
|
|
2275
|
-
...
|
|
1902
|
+
o((x) => ({
|
|
1903
|
+
...x,
|
|
2276
1904
|
uiMessages: [
|
|
2277
|
-
...
|
|
2278
|
-
|
|
1905
|
+
...x.uiMessages,
|
|
1906
|
+
b
|
|
2279
1907
|
]
|
|
2280
1908
|
}));
|
|
2281
1909
|
}
|
|
2282
|
-
if (
|
|
1910
|
+
if (I.final && ((S = I.status) != null && S.message) && f) {
|
|
2283
1911
|
C = !0;
|
|
2284
|
-
const
|
|
2285
|
-
|
|
2286
|
-
|
|
1912
|
+
const b = f, x = z(
|
|
1913
|
+
I.status.message,
|
|
1914
|
+
d.current
|
|
2287
1915
|
);
|
|
2288
|
-
|
|
2289
|
-
const
|
|
2290
|
-
(
|
|
2291
|
-
), R =
|
|
2292
|
-
|
|
1916
|
+
x && o((_) => {
|
|
1917
|
+
const N = _.uiMessages.map(
|
|
1918
|
+
(P) => P.id === b ? x : P
|
|
1919
|
+
), R = m.getConversationHistory(
|
|
1920
|
+
y
|
|
2293
1921
|
);
|
|
2294
1922
|
return {
|
|
2295
|
-
...
|
|
1923
|
+
..._,
|
|
2296
1924
|
clientMessages: R,
|
|
2297
|
-
uiMessages:
|
|
1925
|
+
uiMessages: N,
|
|
2298
1926
|
isProcessing: !1
|
|
2299
1927
|
};
|
|
2300
|
-
}),
|
|
1928
|
+
}), f = null;
|
|
2301
1929
|
}
|
|
2302
1930
|
}
|
|
2303
1931
|
if (!C) {
|
|
2304
|
-
const
|
|
2305
|
-
|
|
2306
|
-
let
|
|
2307
|
-
|
|
2308
|
-
(
|
|
1932
|
+
const I = m.getConversationHistory(y);
|
|
1933
|
+
o((b) => {
|
|
1934
|
+
let x = b.uiMessages;
|
|
1935
|
+
f && (x = b.uiMessages.filter(
|
|
1936
|
+
(A) => A.id !== f
|
|
2309
1937
|
));
|
|
2310
|
-
const
|
|
2311
|
-
(
|
|
2312
|
-
|
|
2313
|
-
|
|
1938
|
+
const _ = I.map(
|
|
1939
|
+
(A) => z(
|
|
1940
|
+
A,
|
|
1941
|
+
d.current
|
|
2314
1942
|
)
|
|
2315
1943
|
).filter(
|
|
2316
|
-
(
|
|
2317
|
-
),
|
|
2318
|
-
|
|
2319
|
-
), R =
|
|
2320
|
-
(
|
|
2321
|
-
var
|
|
2322
|
-
return !
|
|
1944
|
+
(A) => A !== null
|
|
1945
|
+
), N = new Set(
|
|
1946
|
+
I.map((A) => A.messageId)
|
|
1947
|
+
), R = x.filter(
|
|
1948
|
+
(A) => {
|
|
1949
|
+
var E;
|
|
1950
|
+
return !N.has(A.id) && ((E = A.content[0]) == null ? void 0 : E.type) === "component";
|
|
2323
1951
|
}
|
|
2324
|
-
),
|
|
2325
|
-
...
|
|
1952
|
+
), P = nt([
|
|
1953
|
+
..._,
|
|
2326
1954
|
...R
|
|
2327
1955
|
]);
|
|
2328
1956
|
return {
|
|
2329
|
-
...
|
|
2330
|
-
clientMessages:
|
|
2331
|
-
uiMessages:
|
|
1957
|
+
...b,
|
|
1958
|
+
clientMessages: I,
|
|
1959
|
+
uiMessages: P,
|
|
2332
1960
|
isProcessing: !1
|
|
2333
1961
|
};
|
|
2334
1962
|
});
|
|
2335
1963
|
}
|
|
2336
|
-
} catch (
|
|
2337
|
-
if (
|
|
2338
|
-
console.log("Request was aborted by user"),
|
|
2339
|
-
...
|
|
1964
|
+
} catch (f) {
|
|
1965
|
+
if (f instanceof Error && f.name === "AbortError") {
|
|
1966
|
+
console.log("Request was aborted by user"), o((I) => ({
|
|
1967
|
+
...I,
|
|
2340
1968
|
isProcessing: !1,
|
|
2341
1969
|
error: null
|
|
2342
1970
|
// Don't show error for user-initiated abort
|
|
2343
1971
|
}));
|
|
2344
1972
|
return;
|
|
2345
1973
|
}
|
|
2346
|
-
const C =
|
|
2347
|
-
throw
|
|
2348
|
-
...
|
|
1974
|
+
const C = f instanceof Error ? f.message : "Failed to send message";
|
|
1975
|
+
throw o((I) => ({
|
|
1976
|
+
...I,
|
|
2349
1977
|
isProcessing: !1,
|
|
2350
1978
|
error: C
|
|
2351
|
-
})),
|
|
1979
|
+
})), f;
|
|
2352
1980
|
}
|
|
2353
1981
|
},
|
|
2354
|
-
[
|
|
2355
|
-
),
|
|
2356
|
-
|
|
2357
|
-
...
|
|
2358
|
-
uiMessages:
|
|
1982
|
+
[s.agentId, s.sessionId, e]
|
|
1983
|
+
), g = H((p) => {
|
|
1984
|
+
o((m) => ({
|
|
1985
|
+
...m,
|
|
1986
|
+
uiMessages: nt([...m.uiMessages, p])
|
|
2359
1987
|
}));
|
|
2360
|
-
}, []),
|
|
2361
|
-
|
|
2362
|
-
...
|
|
2363
|
-
suggestions:
|
|
1988
|
+
}, []), h = H((p) => {
|
|
1989
|
+
o((m) => ({
|
|
1990
|
+
...m,
|
|
1991
|
+
suggestions: p
|
|
2364
1992
|
}));
|
|
2365
|
-
}, []),
|
|
2366
|
-
|
|
2367
|
-
...
|
|
1993
|
+
}, []), T = H(() => {
|
|
1994
|
+
o((p) => ({
|
|
1995
|
+
...p,
|
|
2368
1996
|
suggestions: []
|
|
2369
1997
|
}));
|
|
2370
|
-
}, [])
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
), v = p.uiMessages.filter(
|
|
2384
|
-
(C) => {
|
|
2385
|
-
var x;
|
|
2386
|
-
return !b.has(C.id) && ((x = C.content[0]) == null ? void 0 : x.type) === "component";
|
|
2387
|
-
}
|
|
2388
|
-
), d = G([
|
|
2389
|
-
...w,
|
|
2390
|
-
...v
|
|
2391
|
-
]);
|
|
2392
|
-
return {
|
|
2393
|
-
...p,
|
|
2394
|
-
markdownComponents: m,
|
|
2395
|
-
uiMessages: d
|
|
2396
|
-
};
|
|
2397
|
-
});
|
|
2398
|
-
},
|
|
2399
|
-
[]
|
|
2400
|
-
), M = F(
|
|
2401
|
-
(h) => {
|
|
2402
|
-
a((p) => {
|
|
2403
|
-
const m = {
|
|
2404
|
-
...p.markdownExtensions,
|
|
2405
|
-
...h
|
|
2406
|
-
}, w = p.clientMessages.map(
|
|
2407
|
-
(C) => K(
|
|
2408
|
-
C,
|
|
2409
|
-
c.current
|
|
2410
|
-
)
|
|
2411
|
-
).filter((C) => C !== null), b = new Set(
|
|
2412
|
-
p.clientMessages.map((C) => C.messageId)
|
|
2413
|
-
), v = p.uiMessages.filter(
|
|
2414
|
-
(C) => {
|
|
2415
|
-
var x;
|
|
2416
|
-
return !b.has(C.id) && ((x = C.content[0]) == null ? void 0 : x.type) === "component";
|
|
2417
|
-
}
|
|
2418
|
-
), d = G([
|
|
2419
|
-
...w,
|
|
2420
|
-
...v
|
|
2421
|
-
]);
|
|
2422
|
-
return {
|
|
2423
|
-
...p,
|
|
2424
|
-
markdownExtensions: m,
|
|
2425
|
-
uiMessages: d
|
|
2426
|
-
};
|
|
2427
|
-
});
|
|
2428
|
-
},
|
|
2429
|
-
[]
|
|
2430
|
-
);
|
|
2431
|
-
X(() => {
|
|
2432
|
-
a((h) => {
|
|
2433
|
-
if (h.clientMessages.length === 0)
|
|
2434
|
-
return h;
|
|
2435
|
-
const p = h.clientMessages.map(
|
|
2436
|
-
(b) => K(b, c.current)
|
|
2437
|
-
).filter((b) => b !== null), m = new Set(
|
|
2438
|
-
h.clientMessages.map((b) => b.messageId)
|
|
2439
|
-
), w = h.uiMessages.filter(
|
|
2440
|
-
(b) => {
|
|
2441
|
-
var v;
|
|
2442
|
-
return !m.has(b.id) && ((v = b.content[0]) == null ? void 0 : v.type) === "component";
|
|
1998
|
+
}, []);
|
|
1999
|
+
tt(() => {
|
|
2000
|
+
o((p) => {
|
|
2001
|
+
if (p.clientMessages.length === 0)
|
|
2002
|
+
return p;
|
|
2003
|
+
const m = p.clientMessages.map(
|
|
2004
|
+
(w) => z(w, d.current)
|
|
2005
|
+
).filter((w) => w !== null), y = new Set(
|
|
2006
|
+
p.clientMessages.map((w) => w.messageId)
|
|
2007
|
+
), u = p.uiMessages.filter(
|
|
2008
|
+
(w) => {
|
|
2009
|
+
var S;
|
|
2010
|
+
return !y.has(w.id) && ((S = w.content[0]) == null ? void 0 : S.type) === "component";
|
|
2443
2011
|
}
|
|
2444
2012
|
);
|
|
2445
2013
|
return {
|
|
2446
|
-
...
|
|
2447
|
-
uiMessages:
|
|
2448
|
-
...
|
|
2449
|
-
...
|
|
2014
|
+
...p,
|
|
2015
|
+
uiMessages: nt([
|
|
2016
|
+
...m,
|
|
2017
|
+
...u
|
|
2450
2018
|
])
|
|
2451
2019
|
};
|
|
2452
2020
|
});
|
|
2453
|
-
}, [
|
|
2454
|
-
const
|
|
2455
|
-
|
|
2456
|
-
extensions: n.markdownExtensions,
|
|
2457
|
-
enableStreaming: t == null ? void 0 : t.enableStreaming
|
|
2458
|
-
}), [
|
|
2459
|
-
n.markdownComponents,
|
|
2460
|
-
n.markdownExtensions,
|
|
2461
|
-
t == null ? void 0 : t.enableStreaming
|
|
2462
|
-
]), u = F(() => {
|
|
2463
|
-
if (!s)
|
|
2021
|
+
}, [i]);
|
|
2022
|
+
const M = H(() => {
|
|
2023
|
+
if (!e)
|
|
2464
2024
|
return;
|
|
2465
|
-
const
|
|
2466
|
-
|
|
2467
|
-
}, [
|
|
2025
|
+
const p = st(), m = `${s.agentId}-${s.sessionId}`;
|
|
2026
|
+
p.abortCurrentRequest(m);
|
|
2027
|
+
}, [s.agentId, s.sessionId, e]);
|
|
2468
2028
|
return {
|
|
2469
2029
|
// AgentUI props
|
|
2470
2030
|
messages: n.uiMessages,
|
|
2471
2031
|
isProcessing: n.isProcessing,
|
|
2472
2032
|
error: n.error,
|
|
2473
|
-
onSubmit:
|
|
2033
|
+
onSubmit: c,
|
|
2474
2034
|
suggestions: n.suggestions,
|
|
2475
|
-
messageRenderer: y,
|
|
2476
2035
|
// UI management methods
|
|
2477
|
-
registerSuggestions:
|
|
2478
|
-
clearSuggestions:
|
|
2479
|
-
registerMarkdownComponents: T,
|
|
2480
|
-
registerMarkdownExtensions: M,
|
|
2036
|
+
registerSuggestions: h,
|
|
2037
|
+
clearSuggestions: T,
|
|
2481
2038
|
// Message actions methods
|
|
2482
|
-
registerMessageActions:
|
|
2483
|
-
unregisterMessageActions:
|
|
2484
|
-
clearAllMessageActions:
|
|
2485
|
-
createFeedbackActions: l,
|
|
2039
|
+
registerMessageActions: r,
|
|
2040
|
+
unregisterMessageActions: a,
|
|
2041
|
+
clearAllMessageActions: l,
|
|
2486
2042
|
// Tool integration
|
|
2487
|
-
addMessage:
|
|
2043
|
+
addMessage: g,
|
|
2488
2044
|
// Abort control
|
|
2489
|
-
abortCurrentRequest:
|
|
2045
|
+
abortCurrentRequest: M
|
|
2490
2046
|
};
|
|
2491
2047
|
}
|
|
2492
|
-
var
|
|
2493
|
-
const
|
|
2494
|
-
function
|
|
2495
|
-
var
|
|
2496
|
-
return window.JP_CONNECTION_INITIAL_STATE ? !1 : !!((
|
|
2048
|
+
var ye = /* @__PURE__ */ ((t) => (t[t.PARSE_ERROR = -32700] = "PARSE_ERROR", t[t.INVALID_REQUEST = -32600] = "INVALID_REQUEST", t[t.METHOD_NOT_FOUND = -32601] = "METHOD_NOT_FOUND", t[t.INVALID_PARAMS = -32602] = "INVALID_PARAMS", t[t.INTERNAL_ERROR = -32603] = "INTERNAL_ERROR", t[t.SERVER_ERROR = -32e3] = "SERVER_ERROR", t))(ye || {});
|
|
2049
|
+
const pt = "jetpack-ai-jwt-token", we = 30 * 60 * 1e3;
|
|
2050
|
+
function Ie() {
|
|
2051
|
+
var e;
|
|
2052
|
+
return window.JP_CONNECTION_INITIAL_STATE ? !1 : !!((e = window.Jetpack_Editor_Initial_State) != null && e.wpcomBlogId);
|
|
2497
2053
|
}
|
|
2498
|
-
async function
|
|
2499
|
-
var
|
|
2500
|
-
const
|
|
2054
|
+
async function Te(t, s = !0) {
|
|
2055
|
+
var i, d;
|
|
2056
|
+
const e = localStorage.getItem(pt);
|
|
2501
2057
|
let n;
|
|
2502
|
-
if (
|
|
2058
|
+
if (e)
|
|
2503
2059
|
try {
|
|
2504
|
-
n = JSON.parse(
|
|
2060
|
+
n = JSON.parse(e);
|
|
2505
2061
|
} catch (c) {
|
|
2506
2062
|
console.warn("Invalid cached Jetpack token:", c);
|
|
2507
2063
|
}
|
|
2508
|
-
if (n && (n != null && n.token) && (n != null && n.expire) && (n == null ? void 0 : n.expire) > Date.now() &&
|
|
2064
|
+
if (n && (n != null && n.token) && (n != null && n.expire) && (n == null ? void 0 : n.expire) > Date.now() && s)
|
|
2509
2065
|
return n;
|
|
2510
|
-
const
|
|
2511
|
-
let
|
|
2066
|
+
const o = (i = window.JP_CONNECTION_INITIAL_STATE) == null ? void 0 : i.apiNonce, r = (d = window.Jetpack_Editor_Initial_State) == null ? void 0 : d.wpcomBlogId;
|
|
2067
|
+
let a = {
|
|
2512
2068
|
token: "",
|
|
2513
2069
|
blog_id: ""
|
|
2514
2070
|
};
|
|
2515
2071
|
try {
|
|
2516
|
-
|
|
2517
|
-
path: "/wpcom/v2/sites/" +
|
|
2072
|
+
Ie() ? a = await ut({
|
|
2073
|
+
path: "/wpcom/v2/sites/" + r + "/jetpack-openai-query/jwt",
|
|
2518
2074
|
method: "POST"
|
|
2519
|
-
}) :
|
|
2075
|
+
}) : a = await ut({
|
|
2520
2076
|
path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
|
|
2521
2077
|
credentials: "same-origin",
|
|
2522
2078
|
headers: {
|
|
2523
|
-
"X-WP-Nonce":
|
|
2079
|
+
"X-WP-Nonce": o || ""
|
|
2524
2080
|
},
|
|
2525
2081
|
method: "POST"
|
|
2526
2082
|
});
|
|
2527
2083
|
} catch (c) {
|
|
2528
2084
|
throw console.log("Failed to fetch Jetpack token:", c), new Error(t(c));
|
|
2529
2085
|
}
|
|
2530
|
-
if (!(
|
|
2086
|
+
if (!(a != null && a.token))
|
|
2531
2087
|
throw new Error(
|
|
2532
2088
|
"Authentication failed. Please ensure Jetpack is properly connected and try again."
|
|
2533
2089
|
);
|
|
2534
|
-
const
|
|
2535
|
-
token:
|
|
2536
|
-
blogId:
|
|
2537
|
-
expire: Date.now() +
|
|
2090
|
+
const l = {
|
|
2091
|
+
token: a.token,
|
|
2092
|
+
blogId: a.blog_id || "",
|
|
2093
|
+
expire: Date.now() + we
|
|
2538
2094
|
};
|
|
2539
2095
|
try {
|
|
2540
|
-
localStorage.setItem(
|
|
2096
|
+
localStorage.setItem(pt, JSON.stringify(l));
|
|
2541
2097
|
} catch (c) {
|
|
2542
2098
|
console.log("Error storing token in localStorage:", c);
|
|
2543
2099
|
}
|
|
2544
|
-
return
|
|
2100
|
+
return l;
|
|
2545
2101
|
}
|
|
2546
|
-
const
|
|
2547
|
-
const
|
|
2102
|
+
const Pe = (t) => async () => {
|
|
2103
|
+
const s = {};
|
|
2548
2104
|
try {
|
|
2549
|
-
const
|
|
2550
|
-
|
|
2551
|
-
} catch (
|
|
2552
|
-
throw console.error("Failed to get Jetpack token for auth:",
|
|
2105
|
+
const e = await Te(t);
|
|
2106
|
+
e != null && e.token && (s.Authorization = `${e.token}`);
|
|
2107
|
+
} catch (e) {
|
|
2108
|
+
throw console.error("Failed to get Jetpack token for auth:", e), e;
|
|
2553
2109
|
}
|
|
2554
|
-
return
|
|
2110
|
+
return s;
|
|
2555
2111
|
};
|
|
2556
2112
|
export {
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
|
|
2570
|
-
|
|
2571
|
-
|
|
2572
|
-
|
|
2573
|
-
|
|
2574
|
-
|
|
2575
|
-
|
|
2113
|
+
ye as A2AErrorCodes,
|
|
2114
|
+
_t as convertAbilitiesToTools,
|
|
2115
|
+
Ot as convertAbilityToTool,
|
|
2116
|
+
ke as createAbortController,
|
|
2117
|
+
te as createClient,
|
|
2118
|
+
Pe as createJetpackAuthProvider,
|
|
2119
|
+
Nt as createRequestId,
|
|
2120
|
+
qt as createTaskId,
|
|
2121
|
+
ot as createTextMessage,
|
|
2122
|
+
$ as extractTextFromMessage,
|
|
2123
|
+
F as extractToolCallsFromMessage,
|
|
2124
|
+
st as getAgentManager,
|
|
2125
|
+
be as isWordPressAbility,
|
|
2126
|
+
Ee as useAgentChat,
|
|
2127
|
+
ve as useClientAbilities,
|
|
2128
|
+
Se as useClientContext,
|
|
2129
|
+
Ae as useClientTools,
|
|
2130
|
+
Re as useClientToolsWithAbilities,
|
|
2131
|
+
ge as useMessageActions
|
|
2576
2132
|
};
|