@automattic/agenttic-client 0.1.13 → 0.1.15
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/index.d.ts.map +1 -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 +1189 -1591
- 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/agentManager.d.ts +1 -0
- package/dist/react/agentManager.d.ts.map +1 -1
- 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 +6 -11
- package/dist/BarChart-Cid6YH81.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/message-actions/factories.d.ts +0 -16
- package/dist/message-actions/factories.d.ts.map +0 -1
- package/dist/utils/createMessageRenderer.d.ts +0 -25
- package/dist/utils/createMessageRenderer.d.ts.map +0 -1
- package/dist/utils/markdownParser.d.ts +0 -25
- package/dist/utils/markdownParser.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 H, sprintf as ft } from "@wordpress/i18n";
|
|
9
|
-
import { LineChart as Bt } from "@automattic/charts";
|
|
10
|
-
import mt from "@wordpress/api-fetch";
|
|
11
|
-
const N = (t, ...e) => {
|
|
12
|
-
Jt() && 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
|
+
});
|
|
130
|
+
}
|
|
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
|
+
});
|
|
63
151
|
}
|
|
64
|
-
function
|
|
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 Vt(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 zt(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 ct(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:
|
|
315
|
+
const { metadata: o, ...r } = n;
|
|
228
316
|
return r;
|
|
229
317
|
}
|
|
230
|
-
function
|
|
231
|
-
const
|
|
232
|
-
let
|
|
233
|
-
for (;
|
|
234
|
-
const
|
|
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
|
-
|
|
247
|
-
} catch (
|
|
248
|
-
|
|
334
|
+
e.push(JSON.parse(o)), r = i === -1 ? n.length : i + 1;
|
|
335
|
+
} catch (c) {
|
|
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:
|
|
342
|
+
const l = n.substring(r);
|
|
343
|
+
return { events: e, nextBuffer: l };
|
|
256
344
|
}
|
|
257
|
-
async function*
|
|
258
|
-
var c, g
|
|
259
|
-
const { supportDeltas:
|
|
345
|
+
async function* Kt(t, s = {}) {
|
|
346
|
+
var d, c, g;
|
|
347
|
+
const { supportDeltas: e = !1 } = s, n = t.getReader(), o = new TextDecoder();
|
|
260
348
|
let r = "";
|
|
261
|
-
const
|
|
262
|
-
let
|
|
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
|
|
271
|
-
const u =
|
|
272
|
-
if (
|
|
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:
|
|
303
|
-
((
|
|
390
|
+
text: $(
|
|
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
|
-
r =
|
|
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 te {
|
|
|
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 r =
|
|
384
|
-
let
|
|
469
|
+
for (const [n, o] of this.toolCalls)
|
|
470
|
+
if (o.toolName) {
|
|
471
|
+
const r = o.argumentFragments.join("");
|
|
472
|
+
let a = {};
|
|
385
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 te {
|
|
|
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:
|
|
496
|
-
fullAgentUrl:
|
|
583
|
+
effectiveSessionId: m,
|
|
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
|
-
),
|
|
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
607
|
r,
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
),
|
|
523
|
-
} catch (
|
|
524
|
-
|
|
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,146 +654,146 @@ async function ie(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 = [],
|
|
679
|
+
async function At(t, s, e) {
|
|
680
|
+
const n = [], o = [];
|
|
593
681
|
let r = !1;
|
|
594
|
-
for (const
|
|
595
|
-
const { toolCallId:
|
|
682
|
+
for (const a of t) {
|
|
683
|
+
const { toolCallId: l, toolId: i, arguments: d } = a.data;
|
|
596
684
|
try {
|
|
597
|
-
const
|
|
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
|
-
} catch (
|
|
698
|
+
} catch (c) {
|
|
611
699
|
r = !0, n.push(
|
|
612
|
-
|
|
613
|
-
i,
|
|
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: r, agentMessages:
|
|
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
|
-
|
|
735
|
+
o,
|
|
648
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
|
-
|
|
755
|
+
o,
|
|
668
756
|
r
|
|
669
|
-
),
|
|
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
|
-
|
|
677
|
-
|
|
764
|
+
o,
|
|
765
|
+
e,
|
|
678
766
|
r,
|
|
679
767
|
!0,
|
|
680
768
|
// withHistory
|
|
681
|
-
|
|
682
|
-
//
|
|
683
|
-
|
|
769
|
+
i,
|
|
770
|
+
// preserve conversation parts across continuation
|
|
771
|
+
a,
|
|
684
772
|
c
|
|
685
773
|
// Pass through the same request options
|
|
686
774
|
);
|
|
687
775
|
}
|
|
688
|
-
async function*
|
|
689
|
-
var c, g,
|
|
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;
|
|
690
778
|
for await (const f of t) {
|
|
691
|
-
if (yield f, f.status.state === "running" && f.status.message &&
|
|
692
|
-
|
|
779
|
+
if (yield f, f.status.state === "running" && f.status.message && s && await Xt(
|
|
780
|
+
s,
|
|
693
781
|
f.status.message
|
|
694
782
|
)) {
|
|
695
|
-
const
|
|
783
|
+
const C = F(
|
|
696
784
|
f.status.message
|
|
697
785
|
);
|
|
698
|
-
for (const I of
|
|
699
|
-
const { toolCallId:
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
(
|
|
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
|
}
|
|
@@ -716,182 +804,183 @@ async function* Ot(t, e, s, n, a, r = !0, o = [], i, l) {
|
|
|
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 (f.status.state === "input-required" && f.status.message &&
|
|
728
|
-
const
|
|
815
|
+
if (f.status.state === "input-required" && f.status.message && s) {
|
|
816
|
+
const C = F(
|
|
729
817
|
f.status.message
|
|
730
818
|
);
|
|
731
|
-
if (
|
|
819
|
+
if (C.length > 0) {
|
|
732
820
|
const I = [];
|
|
733
|
-
let
|
|
734
|
-
const
|
|
735
|
-
for (const
|
|
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: v, returnToAgent:
|
|
748
|
-
if (
|
|
749
|
-
|
|
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)
|
|
750
838
|
), v.result instanceof Promise) {
|
|
751
|
-
const
|
|
752
|
-
promise:
|
|
839
|
+
const B = v.result, j = {
|
|
840
|
+
promise: B,
|
|
753
841
|
resolvedValue: null
|
|
754
842
|
};
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
),
|
|
759
|
-
|
|
843
|
+
lt.set(
|
|
844
|
+
R,
|
|
845
|
+
j
|
|
846
|
+
), B.then((q) => {
|
|
847
|
+
j.resolvedValue = q;
|
|
760
848
|
}).catch((q) => {
|
|
761
849
|
console.error(
|
|
762
|
-
`Promise rejected for tool call ${
|
|
850
|
+
`Promise rejected for tool call ${R}:`,
|
|
763
851
|
q
|
|
764
|
-
),
|
|
852
|
+
), j.resolvedValue = {
|
|
765
853
|
error: q instanceof Error ? q.message : String(q)
|
|
766
854
|
};
|
|
767
855
|
});
|
|
768
856
|
}
|
|
769
|
-
const
|
|
770
|
-
|
|
771
|
-
|
|
857
|
+
const V = J(
|
|
858
|
+
R,
|
|
859
|
+
P,
|
|
772
860
|
v
|
|
773
861
|
);
|
|
774
|
-
I.push(
|
|
775
|
-
} catch (
|
|
776
|
-
const v =
|
|
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
|
-
I.push(v),
|
|
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
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
|
|
893
|
+
const P = await ft(
|
|
800
894
|
f.id,
|
|
801
|
-
|
|
895
|
+
R,
|
|
802
896
|
n,
|
|
803
|
-
e,
|
|
804
897
|
s,
|
|
805
|
-
|
|
898
|
+
e,
|
|
899
|
+
o,
|
|
900
|
+
l,
|
|
806
901
|
i,
|
|
807
|
-
|
|
902
|
+
a
|
|
808
903
|
);
|
|
809
|
-
let
|
|
810
|
-
for await (const
|
|
811
|
-
|
|
812
|
-
if (!
|
|
904
|
+
let A = null;
|
|
905
|
+
for await (const D of P)
|
|
906
|
+
D.final ? A = D : yield D;
|
|
907
|
+
if (!A)
|
|
813
908
|
throw new Error(
|
|
814
909
|
"Continue task stream ended without final result"
|
|
815
910
|
);
|
|
816
|
-
let
|
|
817
|
-
|
|
818
|
-
) : [];
|
|
819
|
-
|
|
820
|
-
role: "agent",
|
|
821
|
-
kind: "message",
|
|
822
|
-
parts: I,
|
|
823
|
-
messageId: D()
|
|
824
|
-
});
|
|
825
|
-
let v = R;
|
|
826
|
-
if (O.length > 0)
|
|
911
|
+
let E = (T = A.status) != null && T.message ? F(
|
|
912
|
+
A.status.message
|
|
913
|
+
) : [], v = A;
|
|
914
|
+
if (E.length > 0)
|
|
827
915
|
for (yield {
|
|
828
|
-
...
|
|
916
|
+
...A,
|
|
829
917
|
final: !1,
|
|
830
|
-
text:
|
|
831
|
-
((
|
|
918
|
+
text: $(
|
|
919
|
+
((M = A.status) == null ? void 0 : M.message) || {
|
|
832
920
|
parts: [],
|
|
833
|
-
messageId:
|
|
921
|
+
messageId: O()
|
|
834
922
|
}
|
|
835
923
|
)
|
|
836
|
-
};
|
|
837
|
-
(
|
|
924
|
+
}; E.length > 0; ) {
|
|
925
|
+
(p = v.status) != null && p.message && a.push(
|
|
838
926
|
v.status.message
|
|
839
927
|
);
|
|
840
928
|
const {
|
|
841
|
-
results:
|
|
842
|
-
shouldReturnToAgent:
|
|
843
|
-
} = await
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
(
|
|
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
|
|
847
935
|
);
|
|
848
|
-
if (
|
|
936
|
+
if (D.length > 0 && (yield {
|
|
849
937
|
id: v.id,
|
|
850
938
|
status: {
|
|
851
939
|
state: "working",
|
|
852
940
|
message: {
|
|
853
941
|
role: "agent",
|
|
854
942
|
kind: "message",
|
|
855
|
-
parts:
|
|
856
|
-
messageId:
|
|
943
|
+
parts: D,
|
|
944
|
+
messageId: O()
|
|
857
945
|
}
|
|
858
946
|
// Simple message with just the results
|
|
859
947
|
},
|
|
860
948
|
final: !1,
|
|
861
949
|
text: ""
|
|
862
|
-
}),
|
|
863
|
-
const
|
|
864
|
-
|
|
865
|
-
) : [],
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
),
|
|
950
|
+
}), W) {
|
|
951
|
+
const V = r ? gt(
|
|
952
|
+
a
|
|
953
|
+
) : [], B = Q(
|
|
954
|
+
D,
|
|
955
|
+
V
|
|
956
|
+
), j = await ft(
|
|
869
957
|
v.id,
|
|
870
|
-
|
|
958
|
+
B,
|
|
871
959
|
n,
|
|
872
|
-
e,
|
|
873
960
|
s,
|
|
874
|
-
|
|
961
|
+
e,
|
|
962
|
+
o,
|
|
963
|
+
l,
|
|
875
964
|
i,
|
|
876
|
-
|
|
965
|
+
a
|
|
877
966
|
);
|
|
878
967
|
let q = null;
|
|
879
|
-
for await (const
|
|
880
|
-
|
|
968
|
+
for await (const Y of j)
|
|
969
|
+
Y.final ? q = Y : yield Y;
|
|
881
970
|
if (!q)
|
|
882
971
|
throw new Error(
|
|
883
972
|
"Continue task stream ended without final result"
|
|
884
973
|
);
|
|
885
|
-
v = q,
|
|
974
|
+
v = q, E = (u = v.status) != null && u.message ? F(
|
|
886
975
|
v.status.message
|
|
887
|
-
) : [],
|
|
976
|
+
) : [], E.length > 0 && (yield {
|
|
888
977
|
id: v.id,
|
|
889
978
|
status: v.status,
|
|
890
979
|
final: !1,
|
|
891
|
-
text:
|
|
892
|
-
((
|
|
980
|
+
text: $(
|
|
981
|
+
((w = v.status) == null ? void 0 : w.message) || {
|
|
893
982
|
parts: [],
|
|
894
|
-
messageId:
|
|
983
|
+
messageId: O()
|
|
895
984
|
}
|
|
896
985
|
)
|
|
897
986
|
});
|
|
@@ -901,37 +990,37 @@ async function* Ot(t, e, s, n, a, r = !0, o = [], i, l) {
|
|
|
901
990
|
yield {
|
|
902
991
|
...v,
|
|
903
992
|
final: !0,
|
|
904
|
-
text:
|
|
905
|
-
((
|
|
993
|
+
text: $(
|
|
994
|
+
((S = v.status) == null ? void 0 : S.message) || {
|
|
906
995
|
parts: [],
|
|
907
|
-
messageId:
|
|
996
|
+
messageId: O()
|
|
908
997
|
}
|
|
909
998
|
)
|
|
910
999
|
};
|
|
911
1000
|
} else {
|
|
912
|
-
const
|
|
1001
|
+
const N = {
|
|
913
1002
|
...f.status.message,
|
|
914
|
-
parts:
|
|
915
|
-
},
|
|
1003
|
+
parts: x
|
|
1004
|
+
}, R = {
|
|
916
1005
|
...f,
|
|
917
1006
|
status: {
|
|
918
1007
|
...f.status,
|
|
919
|
-
message:
|
|
1008
|
+
message: N
|
|
920
1009
|
},
|
|
921
|
-
final:
|
|
1010
|
+
final: _.length === 0,
|
|
922
1011
|
// Only final if no agent messages to follow
|
|
923
|
-
text:
|
|
1012
|
+
text: $(N)
|
|
924
1013
|
};
|
|
925
|
-
if (yield
|
|
926
|
-
const
|
|
1014
|
+
if (yield R, _.length > 0) {
|
|
1015
|
+
const P = _.map((E) => $(E)).join(" "), A = L(P);
|
|
927
1016
|
yield {
|
|
928
|
-
id:
|
|
1017
|
+
id: R.id,
|
|
929
1018
|
status: {
|
|
930
1019
|
state: "completed",
|
|
931
|
-
message:
|
|
1020
|
+
message: A
|
|
932
1021
|
},
|
|
933
1022
|
final: !0,
|
|
934
|
-
text:
|
|
1023
|
+
text: P
|
|
935
1024
|
};
|
|
936
1025
|
}
|
|
937
1026
|
}
|
|
@@ -939,363 +1028,363 @@ async function* Ot(t, e, s, n, a, r = !0, o = [], i, l) {
|
|
|
939
1028
|
}
|
|
940
1029
|
}
|
|
941
1030
|
}
|
|
942
|
-
function
|
|
1031
|
+
function te(t) {
|
|
943
1032
|
const {
|
|
944
|
-
agentId:
|
|
945
|
-
agentUrl:
|
|
1033
|
+
agentId: s,
|
|
1034
|
+
agentUrl: e,
|
|
946
1035
|
authProvider: n,
|
|
947
|
-
defaultSessionId:
|
|
948
|
-
timeout: r =
|
|
949
|
-
toolProvider:
|
|
950
|
-
contextProvider:
|
|
951
|
-
enableStreaming:
|
|
952
|
-
} = t,
|
|
953
|
-
agentId:
|
|
954
|
-
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,
|
|
955
1044
|
authProvider: n,
|
|
956
1045
|
timeout: r
|
|
957
1046
|
};
|
|
958
1047
|
return {
|
|
959
|
-
async sendMessage(
|
|
960
|
-
var
|
|
961
|
-
const { withHistory:
|
|
962
|
-
|
|
963
|
-
const
|
|
964
|
-
g,
|
|
1048
|
+
async sendMessage(c) {
|
|
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(
|
|
965
1053
|
c,
|
|
1054
|
+
d,
|
|
966
1055
|
{ isStreaming: !1 },
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
1056
|
+
a,
|
|
1057
|
+
l,
|
|
1058
|
+
T
|
|
970
1059
|
);
|
|
971
|
-
let
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
{ abortSignal:
|
|
1060
|
+
let m = await St(
|
|
1061
|
+
p,
|
|
1062
|
+
d,
|
|
1063
|
+
{ abortSignal: h }
|
|
975
1064
|
);
|
|
976
|
-
const
|
|
977
|
-
for (;
|
|
978
|
-
const f =
|
|
979
|
-
|
|
1065
|
+
const y = [], u = [];
|
|
1066
|
+
for (; m.status.message && a; ) {
|
|
1067
|
+
const f = F(
|
|
1068
|
+
m.status.message
|
|
980
1069
|
);
|
|
981
1070
|
if (f.length === 0)
|
|
982
1071
|
break;
|
|
983
|
-
|
|
984
|
-
const
|
|
1072
|
+
y.push(...f);
|
|
1073
|
+
const C = [];
|
|
985
1074
|
let I = !1;
|
|
986
|
-
for (const
|
|
1075
|
+
for (const b of f) {
|
|
987
1076
|
const {
|
|
988
|
-
toolCallId:
|
|
989
|
-
toolId:
|
|
990
|
-
arguments:
|
|
991
|
-
} =
|
|
1077
|
+
toolCallId: x,
|
|
1078
|
+
toolId: _,
|
|
1079
|
+
arguments: N
|
|
1080
|
+
} = b.data;
|
|
992
1081
|
try {
|
|
993
|
-
const
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
), { result:
|
|
997
|
-
|
|
998
|
-
|
|
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)
|
|
999
1088
|
);
|
|
1000
|
-
const v =
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1089
|
+
const v = J(
|
|
1090
|
+
x,
|
|
1091
|
+
_,
|
|
1092
|
+
P
|
|
1004
1093
|
);
|
|
1005
|
-
|
|
1006
|
-
} catch (
|
|
1007
|
-
const
|
|
1008
|
-
|
|
1009
|
-
|
|
1094
|
+
C.push(v), y.push(v);
|
|
1095
|
+
} catch (R) {
|
|
1096
|
+
const P = J(
|
|
1097
|
+
x,
|
|
1098
|
+
_,
|
|
1010
1099
|
void 0,
|
|
1011
|
-
|
|
1100
|
+
R instanceof Error ? R.message : String(R)
|
|
1012
1101
|
);
|
|
1013
|
-
|
|
1102
|
+
C.push(P), y.push(P);
|
|
1014
1103
|
}
|
|
1015
1104
|
}
|
|
1016
|
-
if (
|
|
1017
|
-
const
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
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
|
|
1026
1115
|
);
|
|
1027
1116
|
} else
|
|
1028
1117
|
break;
|
|
1029
1118
|
}
|
|
1030
|
-
if (
|
|
1119
|
+
if (y.length > 0 && (w = m.status) != null && w.message) {
|
|
1031
1120
|
const f = {
|
|
1032
|
-
...
|
|
1033
|
-
parts:
|
|
1121
|
+
...m.status.message,
|
|
1122
|
+
parts: y
|
|
1034
1123
|
};
|
|
1035
|
-
|
|
1036
|
-
...
|
|
1124
|
+
m = {
|
|
1125
|
+
...m,
|
|
1037
1126
|
status: {
|
|
1038
|
-
...
|
|
1127
|
+
...m.status,
|
|
1039
1128
|
message: f
|
|
1040
1129
|
}
|
|
1041
1130
|
};
|
|
1042
1131
|
}
|
|
1043
1132
|
if (u.length > 0) {
|
|
1044
|
-
const f = u.map((I) =>
|
|
1133
|
+
const f = u.map((I) => $(I)).join(" "), C = L(f);
|
|
1045
1134
|
return {
|
|
1046
|
-
...
|
|
1135
|
+
...m,
|
|
1047
1136
|
// Keep the enhanced message with tool results
|
|
1048
1137
|
// The agent message will be handled separately by the caller
|
|
1049
1138
|
text: f,
|
|
1050
|
-
agentMessage:
|
|
1139
|
+
agentMessage: C
|
|
1051
1140
|
// Add this for the caller to handle
|
|
1052
1141
|
};
|
|
1053
1142
|
}
|
|
1054
1143
|
return {
|
|
1055
|
-
...
|
|
1056
|
-
text:
|
|
1057
|
-
((
|
|
1144
|
+
...m,
|
|
1145
|
+
text: $(
|
|
1146
|
+
((S = m.status) == null ? void 0 : S.message) || {
|
|
1058
1147
|
parts: [],
|
|
1059
|
-
messageId:
|
|
1148
|
+
messageId: O()
|
|
1060
1149
|
}
|
|
1061
1150
|
)
|
|
1062
1151
|
};
|
|
1063
1152
|
},
|
|
1064
|
-
async *sendMessageStream(
|
|
1153
|
+
async *sendMessageStream(c) {
|
|
1065
1154
|
const {
|
|
1066
|
-
withHistory:
|
|
1067
|
-
abortSignal:
|
|
1068
|
-
enableStreaming:
|
|
1069
|
-
} =
|
|
1070
|
-
|
|
1071
|
-
const
|
|
1072
|
-
g,
|
|
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(
|
|
1073
1161
|
c,
|
|
1162
|
+
d,
|
|
1074
1163
|
{
|
|
1075
1164
|
isStreaming: !0,
|
|
1076
1165
|
// Always use message/stream endpoint for SSE
|
|
1077
|
-
enableTokenStreaming:
|
|
1166
|
+
enableTokenStreaming: p
|
|
1078
1167
|
},
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
|
|
1082
|
-
), u =
|
|
1083
|
-
|
|
1084
|
-
|
|
1168
|
+
a,
|
|
1169
|
+
l,
|
|
1170
|
+
M
|
|
1171
|
+
), u = bt(
|
|
1172
|
+
y,
|
|
1173
|
+
d,
|
|
1085
1174
|
{
|
|
1086
|
-
enableTokenStreaming:
|
|
1175
|
+
enableTokenStreaming: p,
|
|
1087
1176
|
// Token streaming is optional
|
|
1088
1177
|
streamingTimeout: r,
|
|
1089
|
-
abortSignal:
|
|
1178
|
+
abortSignal: h
|
|
1090
1179
|
}
|
|
1091
1180
|
);
|
|
1092
|
-
yield*
|
|
1181
|
+
yield* vt(
|
|
1093
1182
|
u,
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1183
|
+
a,
|
|
1184
|
+
l,
|
|
1185
|
+
d,
|
|
1186
|
+
M,
|
|
1187
|
+
g,
|
|
1188
|
+
m,
|
|
1189
|
+
h,
|
|
1101
1190
|
{
|
|
1102
1191
|
isStreaming: !0,
|
|
1103
|
-
enableTokenStreaming:
|
|
1192
|
+
enableTokenStreaming: p,
|
|
1104
1193
|
streamingTimeout: r
|
|
1105
1194
|
}
|
|
1106
1195
|
);
|
|
1107
1196
|
},
|
|
1108
|
-
async continueTask(
|
|
1109
|
-
var
|
|
1110
|
-
const
|
|
1111
|
-
let
|
|
1112
|
-
g,
|
|
1113
|
-
A,
|
|
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
|
-
|
|
1202
|
+
T,
|
|
1203
|
+
d,
|
|
1204
|
+
a,
|
|
1205
|
+
l,
|
|
1206
|
+
h
|
|
1118
1207
|
);
|
|
1119
|
-
for (;
|
|
1120
|
-
const
|
|
1121
|
-
|
|
1208
|
+
for (; p.status.state === "input-required" && p.status.message && a; ) {
|
|
1209
|
+
const y = F(
|
|
1210
|
+
p.status.message
|
|
1122
1211
|
);
|
|
1123
|
-
if (
|
|
1212
|
+
if (y.length === 0)
|
|
1124
1213
|
break;
|
|
1125
|
-
const { results: u, shouldReturnToAgent:
|
|
1126
|
-
if (
|
|
1127
|
-
const
|
|
1128
|
-
|
|
1129
|
-
|
|
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,
|
|
1130
1220
|
d,
|
|
1131
|
-
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
b
|
|
1221
|
+
a,
|
|
1222
|
+
l,
|
|
1223
|
+
h
|
|
1135
1224
|
);
|
|
1136
1225
|
} else
|
|
1137
1226
|
break;
|
|
1138
1227
|
}
|
|
1139
1228
|
return {
|
|
1140
|
-
...
|
|
1141
|
-
text:
|
|
1142
|
-
((
|
|
1229
|
+
...p,
|
|
1230
|
+
text: $(
|
|
1231
|
+
((m = p.status) == null ? void 0 : m.message) || {
|
|
1143
1232
|
parts: [],
|
|
1144
|
-
messageId:
|
|
1233
|
+
messageId: O()
|
|
1145
1234
|
}
|
|
1146
1235
|
)
|
|
1147
1236
|
};
|
|
1148
1237
|
},
|
|
1149
|
-
async getTask(
|
|
1238
|
+
async getTask(c) {
|
|
1150
1239
|
throw new Error("getTask not implemented yet");
|
|
1151
1240
|
},
|
|
1152
|
-
async cancelTask(
|
|
1241
|
+
async cancelTask(c) {
|
|
1153
1242
|
throw new Error("cancelTask not implemented yet");
|
|
1154
1243
|
}
|
|
1155
1244
|
};
|
|
1156
1245
|
}
|
|
1157
|
-
const
|
|
1158
|
-
function
|
|
1159
|
-
var
|
|
1160
|
-
const
|
|
1161
|
-
`),
|
|
1162
|
-
(
|
|
1163
|
-
).map((
|
|
1164
|
-
toolCallId:
|
|
1165
|
-
toolId:
|
|
1166
|
-
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
|
|
1167
1256
|
})), n = t.parts.filter(
|
|
1168
|
-
(
|
|
1169
|
-
).map((
|
|
1170
|
-
toolCallId:
|
|
1171
|
-
result:
|
|
1172
|
-
error:
|
|
1173
|
-
})), r =
|
|
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();
|
|
1174
1263
|
return {
|
|
1175
1264
|
role: r,
|
|
1176
|
-
content:
|
|
1177
|
-
timestamp:
|
|
1178
|
-
...
|
|
1265
|
+
content: s || "(No text content)",
|
|
1266
|
+
timestamp: a,
|
|
1267
|
+
...e.length > 0 && { toolCalls: e },
|
|
1179
1268
|
...n.length > 0 && { toolResults: n }
|
|
1180
1269
|
};
|
|
1181
1270
|
}
|
|
1182
|
-
function
|
|
1183
|
-
const
|
|
1184
|
-
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({
|
|
1185
1274
|
type: "text",
|
|
1186
1275
|
text: t.content
|
|
1187
1276
|
}), t.toolCalls)
|
|
1188
|
-
for (const
|
|
1189
|
-
|
|
1277
|
+
for (const e of t.toolCalls)
|
|
1278
|
+
s.push({
|
|
1190
1279
|
type: "data",
|
|
1191
1280
|
data: {
|
|
1192
|
-
toolCallId:
|
|
1193
|
-
toolId:
|
|
1194
|
-
arguments:
|
|
1281
|
+
toolCallId: e.toolCallId,
|
|
1282
|
+
toolId: e.toolId,
|
|
1283
|
+
arguments: e.arguments
|
|
1195
1284
|
}
|
|
1196
1285
|
});
|
|
1197
1286
|
if (t.toolResults)
|
|
1198
|
-
for (const
|
|
1199
|
-
|
|
1287
|
+
for (const e of t.toolResults)
|
|
1288
|
+
s.push({
|
|
1200
1289
|
type: "data",
|
|
1201
1290
|
data: {
|
|
1202
|
-
toolCallId:
|
|
1203
|
-
result:
|
|
1204
|
-
...
|
|
1291
|
+
toolCallId: e.toolCallId,
|
|
1292
|
+
result: e.result,
|
|
1293
|
+
...e.error && { error: e.error }
|
|
1205
1294
|
}
|
|
1206
1295
|
});
|
|
1207
1296
|
return {
|
|
1208
1297
|
role: t.role,
|
|
1209
1298
|
kind: "message",
|
|
1210
|
-
parts:
|
|
1211
|
-
messageId:
|
|
1299
|
+
parts: s,
|
|
1300
|
+
messageId: O(),
|
|
1212
1301
|
metadata: {
|
|
1213
1302
|
timestamp: t.timestamp
|
|
1214
1303
|
}
|
|
1215
1304
|
};
|
|
1216
1305
|
}
|
|
1217
|
-
const
|
|
1218
|
-
async function
|
|
1219
|
-
const n =
|
|
1220
|
-
if (
|
|
1221
|
-
const
|
|
1222
|
-
|
|
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);
|
|
1223
1312
|
}
|
|
1224
1313
|
if (!(typeof sessionStorage > "u"))
|
|
1225
1314
|
try {
|
|
1226
|
-
const
|
|
1315
|
+
const o = {
|
|
1227
1316
|
storageKey: n,
|
|
1228
|
-
messages:
|
|
1317
|
+
messages: s.map(ee),
|
|
1229
1318
|
lastUpdated: Date.now()
|
|
1230
1319
|
};
|
|
1231
1320
|
sessionStorage.setItem(
|
|
1232
|
-
`${
|
|
1233
|
-
JSON.stringify(
|
|
1321
|
+
`${ct}_${n}`,
|
|
1322
|
+
JSON.stringify(o)
|
|
1234
1323
|
);
|
|
1235
|
-
} catch (
|
|
1236
|
-
|
|
1324
|
+
} catch (o) {
|
|
1325
|
+
k(
|
|
1237
1326
|
"Failed to store conversation in sessionStorage for key %s: %O",
|
|
1238
1327
|
n,
|
|
1239
|
-
|
|
1328
|
+
o
|
|
1240
1329
|
);
|
|
1241
1330
|
}
|
|
1242
1331
|
}
|
|
1243
|
-
async function
|
|
1244
|
-
const
|
|
1245
|
-
if (
|
|
1246
|
-
return [...
|
|
1332
|
+
async function ae(t, s) {
|
|
1333
|
+
const e = s || t;
|
|
1334
|
+
if (U.has(e))
|
|
1335
|
+
return [...U.get(e)];
|
|
1247
1336
|
if (typeof sessionStorage > "u")
|
|
1248
1337
|
return [];
|
|
1249
1338
|
try {
|
|
1250
1339
|
const n = sessionStorage.getItem(
|
|
1251
|
-
`${
|
|
1340
|
+
`${ct}_${e}`
|
|
1252
1341
|
);
|
|
1253
1342
|
if (n) {
|
|
1254
|
-
const r = JSON.parse(n).messages.map(
|
|
1255
|
-
return
|
|
1343
|
+
const r = JSON.parse(n).messages.map(se);
|
|
1344
|
+
return U.set(e, r), [...r];
|
|
1256
1345
|
}
|
|
1257
1346
|
} catch (n) {
|
|
1258
|
-
|
|
1347
|
+
k(
|
|
1259
1348
|
"Failed to load conversation from sessionStorage for key %s: %O",
|
|
1260
|
-
|
|
1349
|
+
e,
|
|
1261
1350
|
n
|
|
1262
1351
|
);
|
|
1263
1352
|
}
|
|
1264
1353
|
return [];
|
|
1265
1354
|
}
|
|
1266
|
-
async function
|
|
1267
|
-
const
|
|
1268
|
-
if (
|
|
1355
|
+
async function re(t, s) {
|
|
1356
|
+
const e = s || t;
|
|
1357
|
+
if (U.delete(e), !(typeof sessionStorage > "u"))
|
|
1269
1358
|
try {
|
|
1270
|
-
sessionStorage.removeItem(`${
|
|
1359
|
+
sessionStorage.removeItem(`${ct}_${e}`);
|
|
1271
1360
|
} catch (n) {
|
|
1272
|
-
|
|
1361
|
+
k(
|
|
1273
1362
|
"Failed to clear conversation from sessionStorage for key %s: %O",
|
|
1274
|
-
|
|
1363
|
+
e,
|
|
1275
1364
|
n
|
|
1276
1365
|
);
|
|
1277
1366
|
}
|
|
1278
1367
|
}
|
|
1279
|
-
function
|
|
1280
|
-
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);
|
|
1281
1370
|
return {
|
|
1282
1371
|
...t,
|
|
1283
|
-
parts:
|
|
1372
|
+
parts: s,
|
|
1284
1373
|
// Preserve metadata if it exists, otherwise add timestamp
|
|
1285
1374
|
metadata: t.metadata || {
|
|
1286
1375
|
timestamp: Date.now()
|
|
1287
1376
|
}
|
|
1288
1377
|
};
|
|
1289
1378
|
}
|
|
1290
|
-
function
|
|
1291
|
-
const
|
|
1292
|
-
for (const
|
|
1293
|
-
for (const n of
|
|
1379
|
+
function ie(t) {
|
|
1380
|
+
const s = [];
|
|
1381
|
+
for (const e of t)
|
|
1382
|
+
for (const n of e.parts)
|
|
1294
1383
|
if (n.type === "text")
|
|
1295
|
-
|
|
1384
|
+
s.push({
|
|
1296
1385
|
type: "data",
|
|
1297
1386
|
data: {
|
|
1298
|
-
role:
|
|
1387
|
+
role: e.role,
|
|
1299
1388
|
text: n.text
|
|
1300
1389
|
}
|
|
1301
1390
|
});
|
|
@@ -1303,1232 +1392,741 @@ function ye(t) {
|
|
|
1303
1392
|
if ("role" in n.data && "text" in n.data)
|
|
1304
1393
|
continue;
|
|
1305
1394
|
if ("toolCallId" in n.data && "arguments" in n.data) {
|
|
1306
|
-
|
|
1395
|
+
s.push(n);
|
|
1307
1396
|
continue;
|
|
1308
1397
|
}
|
|
1309
1398
|
if ("toolCallId" in n.data && "result" in n.data) {
|
|
1310
|
-
|
|
1399
|
+
s.push(n);
|
|
1311
1400
|
continue;
|
|
1312
1401
|
}
|
|
1313
1402
|
}
|
|
1314
|
-
return
|
|
1403
|
+
return s;
|
|
1315
1404
|
}
|
|
1316
|
-
function
|
|
1405
|
+
function mt(t, s = []) {
|
|
1317
1406
|
return {
|
|
1318
1407
|
role: "user",
|
|
1319
1408
|
parts: [
|
|
1320
|
-
...
|
|
1409
|
+
...ie(s),
|
|
1321
1410
|
{
|
|
1322
1411
|
type: "text",
|
|
1323
1412
|
text: t
|
|
1324
1413
|
}
|
|
1325
1414
|
],
|
|
1326
1415
|
kind: "message",
|
|
1327
|
-
messageId:
|
|
1416
|
+
messageId: O(),
|
|
1328
1417
|
metadata: {
|
|
1329
1418
|
timestamp: Date.now()
|
|
1330
1419
|
}
|
|
1331
1420
|
};
|
|
1332
1421
|
}
|
|
1333
|
-
function
|
|
1422
|
+
function le(t) {
|
|
1334
1423
|
return t != null && t.parts ? t.parts.filter(
|
|
1335
|
-
(
|
|
1424
|
+
(s) => s.type === "data" && "toolCallId" in s.data && "result" in s.data
|
|
1336
1425
|
) : [];
|
|
1337
1426
|
}
|
|
1338
|
-
async function
|
|
1339
|
-
const
|
|
1340
|
-
for (const
|
|
1341
|
-
if (
|
|
1342
|
-
if (
|
|
1343
|
-
(
|
|
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
|
|
1344
1433
|
)) {
|
|
1345
|
-
const
|
|
1346
|
-
|
|
1434
|
+
const o = Zt(
|
|
1435
|
+
e.parts
|
|
1347
1436
|
);
|
|
1348
|
-
|
|
1349
|
-
...
|
|
1350
|
-
parts:
|
|
1437
|
+
s.push({
|
|
1438
|
+
...e,
|
|
1439
|
+
parts: o
|
|
1351
1440
|
});
|
|
1352
1441
|
} else
|
|
1353
|
-
|
|
1442
|
+
s.push(e);
|
|
1354
1443
|
else
|
|
1355
|
-
|
|
1356
|
-
return
|
|
1444
|
+
s.push(e);
|
|
1445
|
+
return Yt(), s;
|
|
1357
1446
|
}
|
|
1358
|
-
function
|
|
1447
|
+
function ue() {
|
|
1359
1448
|
const t = /* @__PURE__ */ new Map();
|
|
1360
|
-
async function e
|
|
1361
|
-
const
|
|
1362
|
-
if (
|
|
1449
|
+
async function s(e, n) {
|
|
1450
|
+
const o = t.get(e);
|
|
1451
|
+
if (o != null && o.sessionId)
|
|
1363
1452
|
try {
|
|
1364
|
-
await
|
|
1365
|
-
|
|
1453
|
+
await oe(
|
|
1454
|
+
o.sessionId,
|
|
1366
1455
|
n,
|
|
1367
|
-
|
|
1456
|
+
o.conversationStorageKey
|
|
1368
1457
|
);
|
|
1369
1458
|
} catch (r) {
|
|
1370
|
-
|
|
1371
|
-
`Failed to persist conversation history for agent ${
|
|
1459
|
+
dt(
|
|
1460
|
+
`Failed to persist conversation history for agent ${e}:`,
|
|
1372
1461
|
r
|
|
1373
1462
|
);
|
|
1374
1463
|
}
|
|
1375
1464
|
}
|
|
1376
1465
|
return {
|
|
1377
|
-
async createAgent(
|
|
1378
|
-
if (t.has(
|
|
1379
|
-
return t.get(
|
|
1380
|
-
const
|
|
1381
|
-
let
|
|
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 = [];
|
|
1382
1471
|
if (r)
|
|
1383
1472
|
try {
|
|
1384
|
-
|
|
1473
|
+
l = await ae(
|
|
1385
1474
|
r,
|
|
1386
|
-
|
|
1475
|
+
a
|
|
1387
1476
|
);
|
|
1388
|
-
} catch (
|
|
1389
|
-
|
|
1390
|
-
`Failed to load conversation history for agent ${
|
|
1391
|
-
|
|
1477
|
+
} catch (d) {
|
|
1478
|
+
dt(
|
|
1479
|
+
`Failed to load conversation history for agent ${e} with session ${r}:`,
|
|
1480
|
+
d
|
|
1392
1481
|
);
|
|
1393
1482
|
}
|
|
1394
|
-
const
|
|
1395
|
-
client:
|
|
1483
|
+
const i = {
|
|
1484
|
+
client: o,
|
|
1396
1485
|
sessionId: r,
|
|
1397
|
-
conversationStorageKey:
|
|
1398
|
-
conversationHistory:
|
|
1486
|
+
conversationStorageKey: a,
|
|
1487
|
+
conversationHistory: l,
|
|
1488
|
+
currentAbortController: null
|
|
1399
1489
|
};
|
|
1400
|
-
return t.set(
|
|
1490
|
+
return t.set(e, i), o;
|
|
1401
1491
|
},
|
|
1402
|
-
getAgent(
|
|
1403
|
-
const n = t.get(
|
|
1492
|
+
getAgent(e) {
|
|
1493
|
+
const n = t.get(e);
|
|
1404
1494
|
return (n == null ? void 0 : n.client) || null;
|
|
1405
1495
|
},
|
|
1406
|
-
hasAgent(
|
|
1407
|
-
return t.has(
|
|
1496
|
+
hasAgent(e) {
|
|
1497
|
+
return t.has(e);
|
|
1408
1498
|
},
|
|
1409
|
-
removeAgent(
|
|
1410
|
-
return t.delete(
|
|
1499
|
+
removeAgent(e) {
|
|
1500
|
+
return t.delete(e);
|
|
1411
1501
|
},
|
|
1412
|
-
async sendMessage(
|
|
1413
|
-
var
|
|
1414
|
-
const r = t.get(
|
|
1502
|
+
async sendMessage(e, n, o = {}) {
|
|
1503
|
+
var p;
|
|
1504
|
+
const r = t.get(e);
|
|
1415
1505
|
if (!r)
|
|
1416
|
-
throw new Error(`Agent with key "${
|
|
1417
|
-
const { withHistory:
|
|
1418
|
-
message:
|
|
1419
|
-
withHistory:
|
|
1420
|
-
...
|
|
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({
|
|
1508
|
+
message: c,
|
|
1509
|
+
withHistory: a,
|
|
1510
|
+
...l
|
|
1421
1511
|
});
|
|
1422
|
-
let
|
|
1423
|
-
if ((
|
|
1424
|
-
const
|
|
1512
|
+
let h = null;
|
|
1513
|
+
if ((p = g.status) != null && p.message) {
|
|
1514
|
+
const m = g.status.message.parts.filter(
|
|
1425
1515
|
(u) => u.type === "data" && "toolCallId" in u.data && ("arguments" in u.data || "result" in u.data)
|
|
1426
|
-
),
|
|
1516
|
+
), y = g.status.message.parts.filter(
|
|
1427
1517
|
(u) => u.type === "text"
|
|
1428
1518
|
);
|
|
1429
|
-
|
|
1519
|
+
h = {
|
|
1430
1520
|
role: "agent",
|
|
1431
1521
|
kind: "message",
|
|
1432
|
-
parts: [...
|
|
1433
|
-
messageId:
|
|
1522
|
+
parts: [...m, ...y],
|
|
1523
|
+
messageId: O(),
|
|
1434
1524
|
metadata: {
|
|
1435
1525
|
timestamp: Date.now()
|
|
1436
1526
|
}
|
|
1437
1527
|
};
|
|
1438
1528
|
}
|
|
1439
|
-
const
|
|
1440
|
-
...
|
|
1529
|
+
const T = [
|
|
1530
|
+
...d,
|
|
1441
1531
|
// Store only the new content from the user message (without history parts)
|
|
1442
|
-
|
|
1532
|
+
ot(n),
|
|
1443
1533
|
// Add complete agent response with tool calls/results if present
|
|
1444
|
-
...
|
|
1534
|
+
...h ? [K(h)] : []
|
|
1445
1535
|
];
|
|
1446
|
-
let
|
|
1447
|
-
if (
|
|
1448
|
-
const
|
|
1449
|
-
|
|
1536
|
+
let M = T;
|
|
1537
|
+
if (g.agentMessage) {
|
|
1538
|
+
const m = K(
|
|
1539
|
+
g.agentMessage
|
|
1450
1540
|
);
|
|
1451
|
-
|
|
1452
|
-
...
|
|
1453
|
-
|
|
1541
|
+
M = [
|
|
1542
|
+
...T,
|
|
1543
|
+
m
|
|
1454
1544
|
];
|
|
1455
1545
|
}
|
|
1456
|
-
return r.conversationHistory =
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
),
|
|
1546
|
+
return r.conversationHistory = M, a && await s(
|
|
1547
|
+
e,
|
|
1548
|
+
M
|
|
1549
|
+
), g;
|
|
1460
1550
|
},
|
|
1461
|
-
async *sendMessageStream(
|
|
1462
|
-
var
|
|
1463
|
-
const r = t.get(
|
|
1551
|
+
async *sendMessageStream(e, n, o = {}) {
|
|
1552
|
+
var m, y, u, w, S, f;
|
|
1553
|
+
const r = t.get(e);
|
|
1464
1554
|
if (!r)
|
|
1465
|
-
throw new Error(`Agent with key "${
|
|
1466
|
-
const {
|
|
1467
|
-
|
|
1555
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1556
|
+
const {
|
|
1557
|
+
withHistory: a = !0,
|
|
1558
|
+
abortSignal: l,
|
|
1559
|
+
...i
|
|
1560
|
+
} = o, { client: d } = r, c = new AbortController();
|
|
1561
|
+
r.currentAbortController = c, l && l.addEventListener(
|
|
1562
|
+
"abort",
|
|
1563
|
+
() => c.abort()
|
|
1564
|
+
);
|
|
1565
|
+
let g = [
|
|
1468
1566
|
...r.conversationHistory
|
|
1469
|
-
],
|
|
1470
|
-
const
|
|
1471
|
-
|
|
1567
|
+
], h = [];
|
|
1568
|
+
const T = await ce(
|
|
1569
|
+
g
|
|
1472
1570
|
);
|
|
1473
|
-
r.conversationHistory =
|
|
1474
|
-
|
|
1475
|
-
|
|
1571
|
+
r.conversationHistory = T, g = T, a && await s(
|
|
1572
|
+
e,
|
|
1573
|
+
T
|
|
1476
1574
|
);
|
|
1477
|
-
const
|
|
1575
|
+
const M = o.message || mt(
|
|
1478
1576
|
n,
|
|
1479
|
-
|
|
1480
|
-
),
|
|
1481
|
-
|
|
1482
|
-
...
|
|
1483
|
-
|
|
1484
|
-
], r.conversationHistory =
|
|
1485
|
-
|
|
1486
|
-
|
|
1577
|
+
T
|
|
1578
|
+
), p = ot(n);
|
|
1579
|
+
g = [
|
|
1580
|
+
...g,
|
|
1581
|
+
p
|
|
1582
|
+
], r.conversationHistory = g, a && await s(
|
|
1583
|
+
e,
|
|
1584
|
+
g
|
|
1487
1585
|
);
|
|
1488
|
-
for await (const
|
|
1489
|
-
message:
|
|
1490
|
-
withHistory:
|
|
1586
|
+
for await (const C of d.sendMessageStream({
|
|
1587
|
+
message: M,
|
|
1588
|
+
withHistory: a,
|
|
1589
|
+
abortSignal: c.signal,
|
|
1491
1590
|
...i
|
|
1492
1591
|
})) {
|
|
1493
|
-
if (((
|
|
1494
|
-
|
|
1495
|
-
|
|
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
|
|
1496
1595
|
).map(
|
|
1497
|
-
(
|
|
1596
|
+
(x) => x.data.toolCallId
|
|
1498
1597
|
);
|
|
1499
|
-
const
|
|
1500
|
-
|
|
1598
|
+
const b = K(
|
|
1599
|
+
C.status.message
|
|
1501
1600
|
);
|
|
1502
|
-
|
|
1503
|
-
...
|
|
1504
|
-
|
|
1505
|
-
], r.conversationHistory =
|
|
1506
|
-
|
|
1507
|
-
|
|
1601
|
+
g = [
|
|
1602
|
+
...g,
|
|
1603
|
+
b
|
|
1604
|
+
], r.conversationHistory = g, a && await s(
|
|
1605
|
+
e,
|
|
1606
|
+
g
|
|
1508
1607
|
);
|
|
1509
1608
|
}
|
|
1510
|
-
if (((
|
|
1511
|
-
const
|
|
1512
|
-
|
|
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
|
|
1513
1612
|
).filter(
|
|
1514
|
-
(
|
|
1515
|
-
|
|
1613
|
+
(x) => h.includes(
|
|
1614
|
+
x.data.toolCallId
|
|
1516
1615
|
)
|
|
1517
1616
|
);
|
|
1518
|
-
if (
|
|
1519
|
-
const
|
|
1617
|
+
if (b.length > 0) {
|
|
1618
|
+
const x = {
|
|
1520
1619
|
role: "agent",
|
|
1521
1620
|
kind: "message",
|
|
1522
|
-
parts:
|
|
1523
|
-
messageId:
|
|
1621
|
+
parts: b,
|
|
1622
|
+
messageId: O()
|
|
1524
1623
|
};
|
|
1525
|
-
|
|
1526
|
-
...
|
|
1527
|
-
|
|
1528
|
-
], r.conversationHistory =
|
|
1529
|
-
|
|
1530
|
-
|
|
1624
|
+
g = [
|
|
1625
|
+
...g,
|
|
1626
|
+
K(x)
|
|
1627
|
+
], r.conversationHistory = g, a && await s(
|
|
1628
|
+
e,
|
|
1629
|
+
g
|
|
1531
1630
|
);
|
|
1532
1631
|
}
|
|
1533
1632
|
}
|
|
1534
|
-
if (
|
|
1535
|
-
|
|
1536
|
-
let
|
|
1537
|
-
(
|
|
1538
|
-
|
|
1539
|
-
),
|
|
1540
|
-
...
|
|
1541
|
-
|
|
1542
|
-
], r.conversationHistory =
|
|
1543
|
-
|
|
1544
|
-
|
|
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
|
|
1545
1644
|
));
|
|
1546
1645
|
}
|
|
1547
|
-
yield
|
|
1646
|
+
yield C;
|
|
1548
1647
|
}
|
|
1648
|
+
r.currentAbortController = null;
|
|
1549
1649
|
},
|
|
1550
|
-
async resetConversation(
|
|
1551
|
-
const n = t.get(
|
|
1650
|
+
async resetConversation(e) {
|
|
1651
|
+
const n = t.get(e);
|
|
1552
1652
|
if (!n)
|
|
1553
|
-
throw new Error(`Agent with key "${
|
|
1554
|
-
n.conversationHistory = [], n.sessionId && await
|
|
1653
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1654
|
+
n.conversationHistory = [], n.sessionId && await re(
|
|
1555
1655
|
n.sessionId,
|
|
1556
1656
|
n.conversationStorageKey
|
|
1557
1657
|
);
|
|
1558
1658
|
},
|
|
1559
|
-
getConversationHistory(
|
|
1560
|
-
const n = t.get(
|
|
1659
|
+
getConversationHistory(e) {
|
|
1660
|
+
const n = t.get(e);
|
|
1561
1661
|
if (!n)
|
|
1562
|
-
throw new Error(`Agent with key "${
|
|
1662
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1563
1663
|
return [...n.conversationHistory];
|
|
1564
1664
|
},
|
|
1665
|
+
abortCurrentRequest(e) {
|
|
1666
|
+
const n = t.get(e);
|
|
1667
|
+
if (!n)
|
|
1668
|
+
throw new Error(`Agent with key "${e}" not found`);
|
|
1669
|
+
n.currentAbortController && (n.currentAbortController.abort(), n.currentAbortController = null);
|
|
1670
|
+
},
|
|
1565
1671
|
clear() {
|
|
1566
1672
|
t.clear();
|
|
1567
1673
|
}
|
|
1568
1674
|
};
|
|
1569
1675
|
}
|
|
1570
|
-
const
|
|
1571
|
-
function
|
|
1572
|
-
return
|
|
1573
|
-
}
|
|
1574
|
-
class Me extends Dt {
|
|
1575
|
-
constructor(e) {
|
|
1576
|
-
super(e), this.state = {
|
|
1577
|
-
hasError: !1,
|
|
1578
|
-
error: null,
|
|
1579
|
-
errorInfo: null
|
|
1580
|
-
};
|
|
1581
|
-
}
|
|
1582
|
-
static getDerivedStateFromError(e) {
|
|
1583
|
-
return {
|
|
1584
|
-
hasError: !0,
|
|
1585
|
-
error: e,
|
|
1586
|
-
errorInfo: null
|
|
1587
|
-
};
|
|
1588
|
-
}
|
|
1589
|
-
componentDidCatch(e, s) {
|
|
1590
|
-
if (console.error("Chart rendering error:", e), console.error("Error info:", s), this.props.chartData) {
|
|
1591
|
-
console.error(
|
|
1592
|
-
"Chart data that caused the error:",
|
|
1593
|
-
this.props.chartData
|
|
1594
|
-
);
|
|
1595
|
-
try {
|
|
1596
|
-
const n = JSON.parse(this.props.chartData);
|
|
1597
|
-
console.error("Parsed chart data:", n);
|
|
1598
|
-
} catch {
|
|
1599
|
-
console.error("Could not parse chart data as JSON");
|
|
1600
|
-
}
|
|
1601
|
-
}
|
|
1602
|
-
this.setState({
|
|
1603
|
-
errorInfo: s
|
|
1604
|
-
});
|
|
1605
|
-
}
|
|
1606
|
-
render() {
|
|
1607
|
-
var e;
|
|
1608
|
-
if (this.state.hasError) {
|
|
1609
|
-
const s = ((e = this.state.error) == null ? void 0 : e.message) || "An error occurred while rendering the chart", n = [
|
|
1610
|
-
"The chart could not be rendered due to an error.",
|
|
1611
|
-
"The error has been logged to the console."
|
|
1612
|
-
];
|
|
1613
|
-
return /* @__PURE__ */ $.jsx(
|
|
1614
|
-
tt,
|
|
1615
|
-
{
|
|
1616
|
-
message: s,
|
|
1617
|
-
details: n.join(`
|
|
1618
|
-
`)
|
|
1619
|
-
}
|
|
1620
|
-
);
|
|
1621
|
-
}
|
|
1622
|
-
return this.props.children;
|
|
1623
|
-
}
|
|
1676
|
+
const de = ue();
|
|
1677
|
+
function st() {
|
|
1678
|
+
return de;
|
|
1624
1679
|
}
|
|
1625
|
-
|
|
1626
|
-
const
|
|
1627
|
-
data: e,
|
|
1628
|
-
currency: s,
|
|
1629
|
-
showLegend: n = !0,
|
|
1630
|
-
withTooltips: a = !0,
|
|
1631
|
-
renderTooltip: r,
|
|
1632
|
-
margin: o,
|
|
1633
|
-
withGradientFill: i = !0,
|
|
1634
|
-
error: l,
|
|
1635
|
-
...c
|
|
1636
|
-
} = t, g = {
|
|
1637
|
-
..._t(),
|
|
1638
|
-
bottom: 80
|
|
1639
|
-
}, y = {
|
|
1640
|
-
data: e,
|
|
1641
|
-
withTooltips: a,
|
|
1642
|
-
renderTooltip: r,
|
|
1643
|
-
showLegend: n,
|
|
1644
|
-
withGradientFill: i,
|
|
1645
|
-
withLegendGlyph: !1,
|
|
1646
|
-
legendOrientation: "horizontal",
|
|
1647
|
-
legendAlignmentHorizontal: "center",
|
|
1648
|
-
legendAlignmentVertical: "bottom",
|
|
1649
|
-
margin: g,
|
|
1650
|
-
options: {
|
|
1651
|
-
xScale: {
|
|
1652
|
-
type: "time"
|
|
1653
|
-
},
|
|
1654
|
-
axis: {
|
|
1655
|
-
x: {
|
|
1656
|
-
...jt(e)
|
|
1657
|
-
}
|
|
1658
|
-
}
|
|
1659
|
-
},
|
|
1660
|
-
...s && { currency: s },
|
|
1661
|
-
...c
|
|
1662
|
-
};
|
|
1663
|
-
return /* @__PURE__ */ $.jsx(Ft, { error: l, children: /* @__PURE__ */ $.jsx(Bt, { ...y }) });
|
|
1664
|
-
}, be = ({
|
|
1665
|
-
data: t,
|
|
1666
|
-
className: e = "",
|
|
1667
|
-
config: s
|
|
1668
|
-
}) => {
|
|
1669
|
-
const [n, a] = X(null), [r, o] = X(
|
|
1670
|
-
null
|
|
1671
|
-
), [i, l] = X(300), c = xt(null), g = j(
|
|
1672
|
-
(p) => {
|
|
1673
|
-
var P;
|
|
1674
|
-
const { tooltipData: u } = p, h = (P = u == null ? void 0 : u.nearestDatum) == null ? void 0 : P.datum;
|
|
1675
|
-
if (!h)
|
|
1676
|
-
return null;
|
|
1677
|
-
const d = (w) => {
|
|
1678
|
-
if (r != null && r.currency) {
|
|
1679
|
-
const { symbol: m, symbolPosition: k } = r.currency;
|
|
1680
|
-
let C;
|
|
1681
|
-
return w >= 1e6 ? C = `${(w / 1e6).toFixed(
|
|
1682
|
-
1
|
|
1683
|
-
)}M` : w >= 1e3 ? C = `${(w / 1e3).toFixed(1)}K` : C = w.toLocaleString(), k === "right" ? `${C}${m}` : `${m}${C}`;
|
|
1684
|
-
}
|
|
1685
|
-
return w >= 1e6 ? `${(w / 1e6).toFixed(1)}M` : w >= 1e3 ? `${(w / 1e3).toFixed(1)}K` : w.toLocaleString();
|
|
1686
|
-
}, f = (w) => {
|
|
1687
|
-
const k = Math.floor(
|
|
1688
|
-
((/* @__PURE__ */ new Date()).getTime() - w.getTime()) / (1e3 * 60 * 60 * 24)
|
|
1689
|
-
);
|
|
1690
|
-
return k === 0 ? H("Today", "a8c-agenttic") : k === 1 ? H("Yesterday", "a8c-agenttic") : k < 7 ? ft(
|
|
1691
|
-
/* translators: %d: number of days */
|
|
1692
|
-
H("%d days ago", "a8c-agenttic"),
|
|
1693
|
-
k
|
|
1694
|
-
) : w.toLocaleDateString("en-US", {
|
|
1695
|
-
year: "numeric",
|
|
1696
|
-
month: "short",
|
|
1697
|
-
day: "numeric"
|
|
1698
|
-
});
|
|
1699
|
-
}, T = h.label, I = Object.entries(
|
|
1700
|
-
(u == null ? void 0 : u.datumByKey) || {}
|
|
1701
|
-
).map(([w, m]) => {
|
|
1702
|
-
const k = m.datum;
|
|
1703
|
-
return {
|
|
1704
|
-
key: w,
|
|
1705
|
-
value: k.value
|
|
1706
|
-
};
|
|
1707
|
-
}).sort((w, m) => m.value - w.value);
|
|
1708
|
-
return /* @__PURE__ */ $.jsxs("div", { children: [
|
|
1709
|
-
T && /* @__PURE__ */ $.jsx(
|
|
1710
|
-
"div",
|
|
1711
|
-
{
|
|
1712
|
-
style: {
|
|
1713
|
-
fontSize: "12px",
|
|
1714
|
-
fontWeight: "bold",
|
|
1715
|
-
marginBottom: "4px",
|
|
1716
|
-
color: "#1e1e1e",
|
|
1717
|
-
borderBottom: "1px solid #eee",
|
|
1718
|
-
paddingBottom: "2px"
|
|
1719
|
-
},
|
|
1720
|
-
children: T
|
|
1721
|
-
}
|
|
1722
|
-
),
|
|
1723
|
-
h.date && /* @__PURE__ */ $.jsx(
|
|
1724
|
-
"div",
|
|
1725
|
-
{
|
|
1726
|
-
style: {
|
|
1727
|
-
fontSize: "10px",
|
|
1728
|
-
opacity: 0.8,
|
|
1729
|
-
marginBottom: "4px"
|
|
1730
|
-
},
|
|
1731
|
-
children: f(h.date)
|
|
1732
|
-
}
|
|
1733
|
-
),
|
|
1734
|
-
I.map((w) => /* @__PURE__ */ $.jsxs(
|
|
1735
|
-
"div",
|
|
1736
|
-
{
|
|
1737
|
-
style: { marginBottom: "2px" },
|
|
1738
|
-
children: [
|
|
1739
|
-
/* @__PURE__ */ $.jsxs("strong", { children: [
|
|
1740
|
-
w.key,
|
|
1741
|
-
":"
|
|
1742
|
-
] }),
|
|
1743
|
-
" ",
|
|
1744
|
-
d(w.value)
|
|
1745
|
-
]
|
|
1746
|
-
},
|
|
1747
|
-
w.key
|
|
1748
|
-
))
|
|
1749
|
-
] });
|
|
1750
|
-
},
|
|
1751
|
-
[r == null ? void 0 : r.currency]
|
|
1752
|
-
);
|
|
1753
|
-
Y(() => {
|
|
1754
|
-
if (a(null), o(null), !t || typeof t != "string") {
|
|
1755
|
-
a({
|
|
1756
|
-
message: H("Invalid chart data provided", "a8c-agenttic"),
|
|
1757
|
-
details: `Input data: ${t}`
|
|
1758
|
-
});
|
|
1759
|
-
return;
|
|
1760
|
-
}
|
|
1761
|
-
try {
|
|
1762
|
-
const p = JSON.parse(t.trim());
|
|
1763
|
-
if (!p.chartType) {
|
|
1764
|
-
a({
|
|
1765
|
-
message: H(
|
|
1766
|
-
"Chart data must include chartType",
|
|
1767
|
-
"a8c-agenttic"
|
|
1768
|
-
),
|
|
1769
|
-
details: H("Available types: line, bar", "a8c-agenttic")
|
|
1770
|
-
});
|
|
1771
|
-
return;
|
|
1772
|
-
}
|
|
1773
|
-
if (!p.data || !Array.isArray(p.data)) {
|
|
1774
|
-
a({
|
|
1775
|
-
message: H(
|
|
1776
|
-
"Chart data must include a data array",
|
|
1777
|
-
"a8c-agenttic"
|
|
1778
|
-
),
|
|
1779
|
-
details: `Input data: ${t}`
|
|
1780
|
-
});
|
|
1781
|
-
return;
|
|
1782
|
-
}
|
|
1783
|
-
if (p.data.length === 0) {
|
|
1784
|
-
a({
|
|
1785
|
-
message: H(
|
|
1786
|
-
"No data points found for chart",
|
|
1787
|
-
"a8c-agenttic"
|
|
1788
|
-
),
|
|
1789
|
-
details: `Input data: ${t}`
|
|
1790
|
-
});
|
|
1791
|
-
return;
|
|
1792
|
-
}
|
|
1793
|
-
const u = p.data.map((d) => ({
|
|
1794
|
-
...d,
|
|
1795
|
-
data: d.data.map((f) => {
|
|
1796
|
-
if (f.date) {
|
|
1797
|
-
const T = new Date(f.date);
|
|
1798
|
-
return isNaN(T.getTime()) ? (console.warn(
|
|
1799
|
-
`Invalid date string: "${f.date}" in series "${d.label}"`
|
|
1800
|
-
), {
|
|
1801
|
-
label: f.label,
|
|
1802
|
-
value: f.value,
|
|
1803
|
-
date: void 0
|
|
1804
|
-
}) : {
|
|
1805
|
-
label: f.label,
|
|
1806
|
-
value: f.value,
|
|
1807
|
-
date: T
|
|
1808
|
-
};
|
|
1809
|
-
}
|
|
1810
|
-
return {
|
|
1811
|
-
label: f.label,
|
|
1812
|
-
value: f.value,
|
|
1813
|
-
date: void 0
|
|
1814
|
-
};
|
|
1815
|
-
})
|
|
1816
|
-
})), h = {
|
|
1817
|
-
chartType: p.chartType,
|
|
1818
|
-
title: p.title,
|
|
1819
|
-
data: u,
|
|
1820
|
-
currency: p.currency,
|
|
1821
|
-
mode: p.mode || "time-comparison"
|
|
1822
|
-
};
|
|
1823
|
-
o(h);
|
|
1824
|
-
} catch {
|
|
1825
|
-
a({
|
|
1826
|
-
message: H(
|
|
1827
|
-
"Failed to parse chart data as JSON",
|
|
1828
|
-
"a8c-agenttic"
|
|
1829
|
-
),
|
|
1830
|
-
details: `Input data: ${t}`
|
|
1831
|
-
});
|
|
1832
|
-
}
|
|
1833
|
-
}, [t]);
|
|
1834
|
-
const y = j((p) => {
|
|
1835
|
-
if (c.current && c.current.disconnect(), p) {
|
|
1836
|
-
const { width: u } = p.getBoundingClientRect(), h = Math.max(280, u - 4);
|
|
1837
|
-
l(h), c.current = new ResizeObserver((d) => {
|
|
1838
|
-
for (const f of d) {
|
|
1839
|
-
const T = f.contentRect.width, I = Math.max(
|
|
1840
|
-
280,
|
|
1841
|
-
T - 4
|
|
1842
|
-
);
|
|
1843
|
-
l(I);
|
|
1844
|
-
}
|
|
1845
|
-
}), c.current.observe(p);
|
|
1846
|
-
}
|
|
1847
|
-
}, []);
|
|
1848
|
-
if (Y(() => () => {
|
|
1849
|
-
c.current && (c.current.disconnect(), c.current = null);
|
|
1850
|
-
}, []), n)
|
|
1851
|
-
return /* @__PURE__ */ $.jsx(tt, { message: n.message, details: n.details });
|
|
1852
|
-
if (!r)
|
|
1853
|
-
return /* @__PURE__ */ $.jsx(
|
|
1854
|
-
tt,
|
|
1855
|
-
{
|
|
1856
|
-
message: H("No chart data available", "a8c-agenttic")
|
|
1857
|
-
}
|
|
1858
|
-
);
|
|
1859
|
-
const A = r.data.length > 1, S = i, M = {
|
|
1860
|
-
data: r.data,
|
|
1861
|
-
currency: r.currency,
|
|
1862
|
-
showLegend: A,
|
|
1863
|
-
withTooltips: !0,
|
|
1864
|
-
renderTooltip: g,
|
|
1865
|
-
error: null,
|
|
1866
|
-
maxWidth: S,
|
|
1867
|
-
aspectRatio: 1.2,
|
|
1868
|
-
resizeDebounceTime: 300
|
|
1869
|
-
}, x = () => {
|
|
1870
|
-
switch (r.chartType) {
|
|
1871
|
-
case "line":
|
|
1872
|
-
return /* @__PURE__ */ $.jsx(Te, { ...M });
|
|
1873
|
-
case "bar":
|
|
1874
|
-
return /* @__PURE__ */ $.jsx(
|
|
1875
|
-
Ht,
|
|
1876
|
-
{
|
|
1877
|
-
...M,
|
|
1878
|
-
mode: r.mode
|
|
1879
|
-
}
|
|
1880
|
-
);
|
|
1881
|
-
default:
|
|
1882
|
-
return /* @__PURE__ */ $.jsx(
|
|
1883
|
-
tt,
|
|
1884
|
-
{
|
|
1885
|
-
message: ft(
|
|
1886
|
-
/* translators: %s: chart type name */
|
|
1887
|
-
H("Unsupported chart type: %s", "a8c-agenttic"),
|
|
1888
|
-
r.chartType
|
|
1889
|
-
)
|
|
1890
|
-
}
|
|
1891
|
-
);
|
|
1892
|
-
}
|
|
1893
|
-
};
|
|
1894
|
-
return /* @__PURE__ */ $.jsx(Me, { chartData: t, children: /* @__PURE__ */ $.jsxs(
|
|
1895
|
-
"div",
|
|
1896
|
-
{
|
|
1897
|
-
ref: y,
|
|
1898
|
-
className: `chart-block ${e}`,
|
|
1899
|
-
children: [
|
|
1900
|
-
r.title && /* @__PURE__ */ $.jsx("h3", { className: "chart-block-title", children: r.title }),
|
|
1901
|
-
/* @__PURE__ */ $.jsx("div", { className: "chart-container", children: x() })
|
|
1902
|
-
]
|
|
1903
|
-
}
|
|
1904
|
-
) });
|
|
1905
|
-
};
|
|
1906
|
-
function Se(t) {
|
|
1907
|
-
return function(s) {
|
|
1908
|
-
const { children: n, className: a, ...r } = s;
|
|
1909
|
-
if (!(a == null ? void 0 : a.includes("language-chart")))
|
|
1910
|
-
return gt.createElement(
|
|
1911
|
-
"code",
|
|
1912
|
-
{ className: a, ...r },
|
|
1913
|
-
n
|
|
1914
|
-
);
|
|
1915
|
-
const i = typeof n == "string" ? n : "";
|
|
1916
|
-
return gt.createElement(be, {
|
|
1917
|
-
data: i,
|
|
1918
|
-
className: "markdown-chart",
|
|
1919
|
-
config: t
|
|
1920
|
-
});
|
|
1921
|
-
};
|
|
1922
|
-
}
|
|
1923
|
-
function ke(t) {
|
|
1924
|
-
var n, a;
|
|
1925
|
-
const e = {}, s = [];
|
|
1926
|
-
return (n = t == null ? void 0 : t.charts) != null && n.enabled && (e.code = Se(t.charts.config)), (a = t == null ? void 0 : t.gfm) != null && a.enabled && s.push(Ut), { components: e, remarkPlugins: s };
|
|
1927
|
-
}
|
|
1928
|
-
function Ae(t, e = {}) {
|
|
1929
|
-
return {
|
|
1930
|
-
...t,
|
|
1931
|
-
...e
|
|
1932
|
-
};
|
|
1933
|
-
}
|
|
1934
|
-
function ve(t = {}) {
|
|
1935
|
-
const { components: e = {}, extensions: s = {}, remarkPlugins: n = [] } = t, a = ke(s), r = Ae(
|
|
1936
|
-
a.components,
|
|
1937
|
-
e
|
|
1938
|
-
), o = [...a.remarkPlugins, ...n];
|
|
1939
|
-
return function({ children: l }) {
|
|
1940
|
-
return /* @__PURE__ */ $.jsx(
|
|
1941
|
-
qt,
|
|
1942
|
-
{
|
|
1943
|
-
components: r,
|
|
1944
|
-
remarkPlugins: o,
|
|
1945
|
-
children: l
|
|
1946
|
-
}
|
|
1947
|
-
);
|
|
1948
|
-
};
|
|
1949
|
-
}
|
|
1950
|
-
const Re = (t) => {
|
|
1951
|
-
const e = t.condition || (() => !0), s = {}, n = [], a = () => {
|
|
1952
|
-
n.forEach((o) => o());
|
|
1953
|
-
}, r = async (o, i) => {
|
|
1954
|
-
s[o] = i, await t.onFeedback(o, i), a();
|
|
1955
|
-
};
|
|
1956
|
-
return {
|
|
1957
|
-
getActionsForMessage: (o) => {
|
|
1958
|
-
if (!e(o))
|
|
1959
|
-
return [];
|
|
1960
|
-
const i = s[o.id], l = [];
|
|
1961
|
-
return l.push({
|
|
1962
|
-
id: "feedback-up",
|
|
1963
|
-
icon: t.icons.up,
|
|
1964
|
-
label: "Good response",
|
|
1965
|
-
onClick: async () => {
|
|
1966
|
-
i === "up" ? delete s[o.id] : await r(o.id, "up"), a();
|
|
1967
|
-
},
|
|
1968
|
-
tooltip: "This response was helpful",
|
|
1969
|
-
pressed: i === "up",
|
|
1970
|
-
disabled: i === "down"
|
|
1971
|
-
// Disable if other is selected
|
|
1972
|
-
}), l.push({
|
|
1973
|
-
id: "feedback-down",
|
|
1974
|
-
icon: t.icons.down,
|
|
1975
|
-
label: "Bad response",
|
|
1976
|
-
onClick: async () => {
|
|
1977
|
-
i === "down" ? delete s[o.id] : await r(o.id, "down"), a();
|
|
1978
|
-
},
|
|
1979
|
-
tooltip: "This response was not helpful",
|
|
1980
|
-
pressed: i === "down",
|
|
1981
|
-
disabled: i === "up"
|
|
1982
|
-
// Disable if other is selected
|
|
1983
|
-
}), l;
|
|
1984
|
-
},
|
|
1985
|
-
clearFeedback: (o) => {
|
|
1986
|
-
delete s[o], a();
|
|
1987
|
-
},
|
|
1988
|
-
clearAllFeedback: () => {
|
|
1989
|
-
Object.keys(s).forEach((o) => {
|
|
1990
|
-
delete s[o];
|
|
1991
|
-
}), a();
|
|
1992
|
-
},
|
|
1993
|
-
onChange: (o) => {
|
|
1994
|
-
n.push(o);
|
|
1995
|
-
},
|
|
1996
|
-
offChange: (o) => {
|
|
1997
|
-
const i = n.indexOf(o);
|
|
1998
|
-
i > -1 && n.splice(i, 1);
|
|
1999
|
-
}
|
|
2000
|
-
};
|
|
2001
|
-
};
|
|
2002
|
-
function Ee() {
|
|
2003
|
-
const [t, e] = X([]), s = j(
|
|
1680
|
+
function ge() {
|
|
1681
|
+
const [t, s] = ht([]), e = H(
|
|
2004
1682
|
(r) => {
|
|
2005
|
-
|
|
2006
|
-
const
|
|
2007
|
-
(
|
|
1683
|
+
s((a) => {
|
|
1684
|
+
const l = a.findIndex(
|
|
1685
|
+
(i) => i.id === r.id
|
|
2008
1686
|
);
|
|
2009
|
-
if (
|
|
2010
|
-
const
|
|
2011
|
-
return l
|
|
1687
|
+
if (l >= 0) {
|
|
1688
|
+
const i = [...a];
|
|
1689
|
+
return i[l] = r, i;
|
|
2012
1690
|
}
|
|
2013
|
-
return [...
|
|
1691
|
+
return [...a, r];
|
|
2014
1692
|
});
|
|
2015
1693
|
},
|
|
2016
1694
|
[]
|
|
2017
|
-
), n =
|
|
2018
|
-
|
|
2019
|
-
}, []),
|
|
2020
|
-
|
|
1695
|
+
), n = H((r) => {
|
|
1696
|
+
s((a) => a.filter((l) => l.id !== r));
|
|
1697
|
+
}, []), o = H(() => {
|
|
1698
|
+
s([]);
|
|
2021
1699
|
}, []);
|
|
2022
1700
|
return {
|
|
2023
|
-
registerMessageActions:
|
|
1701
|
+
registerMessageActions: e,
|
|
2024
1702
|
unregisterMessageActions: n,
|
|
2025
|
-
clearAllMessageActions:
|
|
2026
|
-
createFeedbackActions: Re,
|
|
1703
|
+
clearAllMessageActions: o,
|
|
2027
1704
|
registrations: t
|
|
2028
1705
|
};
|
|
2029
1706
|
}
|
|
2030
|
-
function
|
|
2031
|
-
return
|
|
2032
|
-
id:
|
|
2033
|
-
label:
|
|
2034
|
-
icon:
|
|
2035
|
-
onClick:
|
|
2036
|
-
tooltip:
|
|
2037
|
-
disabled:
|
|
2038
|
-
pressed:
|
|
2039
|
-
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
|
|
2040
1717
|
}));
|
|
2041
1718
|
}
|
|
2042
|
-
const
|
|
2043
|
-
var
|
|
2044
|
-
if (t.parts.some((
|
|
2045
|
-
if (
|
|
2046
|
-
const
|
|
2047
|
-
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;
|
|
2048
1725
|
}
|
|
2049
1726
|
return !1;
|
|
2050
1727
|
}))
|
|
2051
1728
|
return null;
|
|
2052
|
-
const n = t.parts.map((
|
|
2053
|
-
if (
|
|
1729
|
+
const n = t.parts.map((l) => {
|
|
1730
|
+
if (l.type === "text")
|
|
2054
1731
|
return {
|
|
2055
1732
|
type: "text",
|
|
2056
|
-
text:
|
|
1733
|
+
text: l.text
|
|
2057
1734
|
};
|
|
2058
|
-
if (
|
|
1735
|
+
if (l.type === "file")
|
|
2059
1736
|
return {
|
|
2060
1737
|
type: "image_url",
|
|
2061
|
-
image_url:
|
|
1738
|
+
image_url: l.file.uri || `data:${l.file.mimeType};base64,${l.file.bytes}`
|
|
2062
1739
|
};
|
|
2063
|
-
if (
|
|
2064
|
-
const
|
|
2065
|
-
return
|
|
1740
|
+
if (l.type === "data") {
|
|
1741
|
+
const i = l.data;
|
|
1742
|
+
return i.component && i.componentProps ? {
|
|
2066
1743
|
type: "component",
|
|
2067
|
-
component:
|
|
2068
|
-
componentProps:
|
|
1744
|
+
component: i.component,
|
|
1745
|
+
componentProps: i.componentProps
|
|
2069
1746
|
} : {
|
|
2070
1747
|
type: "text",
|
|
2071
|
-
text: JSON.stringify(
|
|
1748
|
+
text: JSON.stringify(i)
|
|
2072
1749
|
};
|
|
2073
1750
|
}
|
|
2074
1751
|
return {
|
|
2075
1752
|
type: "text",
|
|
2076
1753
|
text: "[Unsupported content]"
|
|
2077
1754
|
};
|
|
2078
|
-
}),
|
|
1755
|
+
}), o = ((a = t.metadata) == null ? void 0 : a.timestamp) ?? Date.now(), r = {
|
|
2079
1756
|
id: t.messageId,
|
|
2080
1757
|
role: t.role === "agent" ? "agent" : "user",
|
|
2081
1758
|
content: n,
|
|
2082
|
-
timestamp:
|
|
1759
|
+
timestamp: o,
|
|
2083
1760
|
archived: !1,
|
|
2084
1761
|
showIcon: t.role === "agent",
|
|
2085
1762
|
icon: t.role === "agent" ? "assistant" : void 0
|
|
2086
1763
|
};
|
|
2087
|
-
if (t.role === "agent" &&
|
|
2088
|
-
const
|
|
1764
|
+
if (t.role === "agent" && s.length > 0) {
|
|
1765
|
+
const l = fe(
|
|
2089
1766
|
r,
|
|
2090
|
-
|
|
1767
|
+
s
|
|
2091
1768
|
);
|
|
2092
|
-
|
|
1769
|
+
l.length > 0 && (r.actions = l);
|
|
2093
1770
|
}
|
|
2094
1771
|
return r;
|
|
2095
|
-
},
|
|
1772
|
+
}, me = () => ({
|
|
2096
1773
|
getClientContext: () => ({})
|
|
2097
|
-
}),
|
|
1774
|
+
}), pe = () => ({
|
|
2098
1775
|
getAvailableTools: async () => [],
|
|
2099
1776
|
executeTool: async () => ({
|
|
2100
1777
|
success: !0,
|
|
2101
1778
|
result: "No tools available"
|
|
2102
1779
|
})
|
|
2103
|
-
}),
|
|
2104
|
-
const n = t[
|
|
1780
|
+
}), he = (t) => ["agentId", "agentUrl", "sessionId"].every((e) => {
|
|
1781
|
+
const n = t[e];
|
|
2105
1782
|
return typeof n == "string" && n.trim().length > 0;
|
|
2106
1783
|
});
|
|
2107
|
-
function
|
|
2108
|
-
const
|
|
1784
|
+
function Ee(t) {
|
|
1785
|
+
const s = {
|
|
2109
1786
|
agentId: t.agentId,
|
|
2110
1787
|
agentUrl: t.agentUrl,
|
|
2111
1788
|
sessionId: t.sessionId
|
|
2112
|
-
},
|
|
1789
|
+
}, e = he(s), [n, o] = ht({
|
|
2113
1790
|
clientMessages: [],
|
|
2114
1791
|
uiMessages: [],
|
|
2115
1792
|
isProcessing: !1,
|
|
2116
|
-
error:
|
|
2117
|
-
suggestions: []
|
|
2118
|
-
markdownComponents: {},
|
|
2119
|
-
markdownExtensions: {},
|
|
2120
|
-
currentAbortController: null
|
|
1793
|
+
error: e ? null : "Invalid agent configuration",
|
|
1794
|
+
suggestions: []
|
|
2121
1795
|
}), {
|
|
2122
1796
|
registerMessageActions: r,
|
|
2123
|
-
unregisterMessageActions:
|
|
2124
|
-
clearAllMessageActions:
|
|
2125
|
-
|
|
2126
|
-
|
|
2127
|
-
|
|
2128
|
-
|
|
2129
|
-
|
|
2130
|
-
|
|
2131
|
-
if (!s)
|
|
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)
|
|
2132
1805
|
return;
|
|
2133
1806
|
(async () => {
|
|
2134
|
-
if (
|
|
2135
|
-
const
|
|
2136
|
-
if (!
|
|
2137
|
-
await
|
|
2138
|
-
agentId:
|
|
2139
|
-
agentUrl:
|
|
2140
|
-
sessionId:
|
|
2141
|
-
contextProvider: t.contextProvider ||
|
|
2142
|
-
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(),
|
|
2143
1816
|
authProvider: t.authProvider,
|
|
2144
1817
|
enableStreaming: t.enableStreaming
|
|
2145
1818
|
});
|
|
2146
|
-
const
|
|
2147
|
-
|
|
2148
|
-
const
|
|
2149
|
-
(
|
|
2150
|
-
|
|
2151
|
-
|
|
1819
|
+
const u = m.getConversationHistory(y);
|
|
1820
|
+
o((w) => {
|
|
1821
|
+
const S = u.map(
|
|
1822
|
+
(f) => z(
|
|
1823
|
+
f,
|
|
1824
|
+
d.current
|
|
2152
1825
|
)
|
|
2153
1826
|
).filter(
|
|
2154
|
-
(
|
|
1827
|
+
(f) => f !== null
|
|
2155
1828
|
);
|
|
2156
1829
|
return {
|
|
2157
|
-
...
|
|
2158
|
-
clientMessages:
|
|
2159
|
-
uiMessages:
|
|
1830
|
+
...w,
|
|
1831
|
+
clientMessages: u,
|
|
1832
|
+
uiMessages: S
|
|
2160
1833
|
};
|
|
2161
1834
|
});
|
|
2162
1835
|
}
|
|
2163
1836
|
}
|
|
2164
1837
|
})();
|
|
2165
1838
|
}, [
|
|
2166
|
-
|
|
2167
|
-
|
|
2168
|
-
|
|
1839
|
+
s.sessionId,
|
|
1840
|
+
s.agentId,
|
|
1841
|
+
s.agentUrl,
|
|
2169
1842
|
t.contextProvider,
|
|
2170
1843
|
t.toolProvider,
|
|
2171
1844
|
t.authProvider,
|
|
2172
1845
|
t.enableStreaming,
|
|
2173
|
-
|
|
1846
|
+
e
|
|
2174
1847
|
]);
|
|
2175
|
-
const
|
|
2176
|
-
async (
|
|
2177
|
-
var
|
|
2178
|
-
if (!
|
|
1848
|
+
const c = H(
|
|
1849
|
+
async (p) => {
|
|
1850
|
+
var S;
|
|
1851
|
+
if (!e)
|
|
2179
1852
|
throw new Error("Invalid agent configuration");
|
|
2180
|
-
const
|
|
2181
|
-
id: `user-${
|
|
1853
|
+
const m = st(), y = `${s.agentId}-${s.sessionId}`, u = Date.now(), w = {
|
|
1854
|
+
id: `user-${u}`,
|
|
2182
1855
|
role: "user",
|
|
2183
|
-
content: [{ type: "text", text:
|
|
2184
|
-
timestamp:
|
|
1856
|
+
content: [{ type: "text", text: p }],
|
|
1857
|
+
timestamp: u,
|
|
2185
1858
|
archived: !1,
|
|
2186
1859
|
showIcon: !1
|
|
2187
|
-
}
|
|
2188
|
-
|
|
2189
|
-
...
|
|
2190
|
-
uiMessages: [...
|
|
1860
|
+
};
|
|
1861
|
+
o((f) => ({
|
|
1862
|
+
...f,
|
|
1863
|
+
uiMessages: [...f.uiMessages, w],
|
|
2191
1864
|
isProcessing: !0,
|
|
2192
|
-
error: null
|
|
2193
|
-
currentAbortController: P
|
|
1865
|
+
error: null
|
|
2194
1866
|
}));
|
|
2195
1867
|
try {
|
|
2196
|
-
let
|
|
2197
|
-
for await (const
|
|
2198
|
-
|
|
2199
|
-
|
|
2200
|
-
{
|
|
2201
|
-
abortSignal: P.signal
|
|
2202
|
-
}
|
|
1868
|
+
let f = null, C = !1;
|
|
1869
|
+
for await (const I of m.sendMessageStream(
|
|
1870
|
+
y,
|
|
1871
|
+
p
|
|
2203
1872
|
)) {
|
|
2204
|
-
if (!
|
|
2205
|
-
if (
|
|
2206
|
-
|
|
2207
|
-
...
|
|
2208
|
-
uiMessages:
|
|
2209
|
-
(
|
|
2210
|
-
...
|
|
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,
|
|
2211
1880
|
content: [
|
|
2212
1881
|
{
|
|
2213
1882
|
type: "text",
|
|
2214
|
-
text:
|
|
1883
|
+
text: I.text
|
|
2215
1884
|
}
|
|
2216
1885
|
]
|
|
2217
|
-
} :
|
|
1886
|
+
} : x
|
|
2218
1887
|
)
|
|
2219
1888
|
}));
|
|
2220
1889
|
else {
|
|
2221
|
-
|
|
2222
|
-
const
|
|
2223
|
-
id:
|
|
1890
|
+
f = `agent-streaming-${Date.now()}`;
|
|
1891
|
+
const b = {
|
|
1892
|
+
id: f,
|
|
2224
1893
|
role: "agent",
|
|
2225
1894
|
content: [
|
|
2226
|
-
{ type: "text", text:
|
|
1895
|
+
{ type: "text", text: I.text }
|
|
2227
1896
|
],
|
|
2228
1897
|
timestamp: Date.now(),
|
|
2229
1898
|
archived: !1,
|
|
2230
1899
|
showIcon: !0,
|
|
2231
1900
|
icon: "assistant"
|
|
2232
1901
|
};
|
|
2233
|
-
|
|
2234
|
-
...
|
|
1902
|
+
o((x) => ({
|
|
1903
|
+
...x,
|
|
2235
1904
|
uiMessages: [
|
|
2236
|
-
...
|
|
2237
|
-
|
|
1905
|
+
...x.uiMessages,
|
|
1906
|
+
b
|
|
2238
1907
|
]
|
|
2239
1908
|
}));
|
|
2240
1909
|
}
|
|
2241
|
-
if (
|
|
2242
|
-
|
|
2243
|
-
const
|
|
2244
|
-
|
|
2245
|
-
|
|
1910
|
+
if (I.final && ((S = I.status) != null && S.message) && f) {
|
|
1911
|
+
C = !0;
|
|
1912
|
+
const b = f, x = z(
|
|
1913
|
+
I.status.message,
|
|
1914
|
+
d.current
|
|
2246
1915
|
);
|
|
2247
|
-
|
|
2248
|
-
const
|
|
2249
|
-
(
|
|
2250
|
-
),
|
|
2251
|
-
|
|
1916
|
+
x && o((_) => {
|
|
1917
|
+
const N = _.uiMessages.map(
|
|
1918
|
+
(P) => P.id === b ? x : P
|
|
1919
|
+
), R = m.getConversationHistory(
|
|
1920
|
+
y
|
|
2252
1921
|
);
|
|
2253
1922
|
return {
|
|
2254
|
-
...
|
|
2255
|
-
clientMessages:
|
|
2256
|
-
uiMessages:
|
|
2257
|
-
isProcessing: !1
|
|
2258
|
-
currentAbortController: null
|
|
1923
|
+
..._,
|
|
1924
|
+
clientMessages: R,
|
|
1925
|
+
uiMessages: N,
|
|
1926
|
+
isProcessing: !1
|
|
2259
1927
|
};
|
|
2260
|
-
}),
|
|
1928
|
+
}), f = null;
|
|
2261
1929
|
}
|
|
2262
1930
|
}
|
|
2263
|
-
if (!
|
|
2264
|
-
const
|
|
2265
|
-
|
|
2266
|
-
let
|
|
2267
|
-
|
|
2268
|
-
(
|
|
1931
|
+
if (!C) {
|
|
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
|
|
2269
1937
|
));
|
|
2270
|
-
const
|
|
2271
|
-
(
|
|
2272
|
-
|
|
2273
|
-
|
|
1938
|
+
const _ = I.map(
|
|
1939
|
+
(A) => z(
|
|
1940
|
+
A,
|
|
1941
|
+
d.current
|
|
2274
1942
|
)
|
|
2275
1943
|
).filter(
|
|
2276
|
-
(
|
|
2277
|
-
),
|
|
2278
|
-
|
|
2279
|
-
),
|
|
2280
|
-
(
|
|
2281
|
-
var
|
|
2282
|
-
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";
|
|
2283
1951
|
}
|
|
2284
|
-
),
|
|
2285
|
-
...
|
|
2286
|
-
...
|
|
1952
|
+
), P = nt([
|
|
1953
|
+
..._,
|
|
1954
|
+
...R
|
|
2287
1955
|
]);
|
|
2288
1956
|
return {
|
|
2289
|
-
...
|
|
2290
|
-
clientMessages:
|
|
2291
|
-
uiMessages:
|
|
2292
|
-
isProcessing: !1
|
|
2293
|
-
currentAbortController: null
|
|
1957
|
+
...b,
|
|
1958
|
+
clientMessages: I,
|
|
1959
|
+
uiMessages: P,
|
|
1960
|
+
isProcessing: !1
|
|
2294
1961
|
};
|
|
2295
1962
|
});
|
|
2296
1963
|
}
|
|
2297
|
-
} catch (
|
|
2298
|
-
if (
|
|
2299
|
-
console.log("Request was aborted by user"),
|
|
2300
|
-
...
|
|
1964
|
+
} catch (f) {
|
|
1965
|
+
if (f instanceof Error && f.name === "AbortError") {
|
|
1966
|
+
console.log("Request was aborted by user"), o((I) => ({
|
|
1967
|
+
...I,
|
|
2301
1968
|
isProcessing: !1,
|
|
2302
|
-
error: null
|
|
1969
|
+
error: null
|
|
2303
1970
|
// Don't show error for user-initiated abort
|
|
2304
|
-
currentAbortController: null
|
|
2305
1971
|
}));
|
|
2306
1972
|
return;
|
|
2307
1973
|
}
|
|
2308
|
-
const
|
|
2309
|
-
throw
|
|
2310
|
-
...
|
|
1974
|
+
const C = f instanceof Error ? f.message : "Failed to send message";
|
|
1975
|
+
throw o((I) => ({
|
|
1976
|
+
...I,
|
|
2311
1977
|
isProcessing: !1,
|
|
2312
|
-
error:
|
|
2313
|
-
|
|
2314
|
-
})), m;
|
|
1978
|
+
error: C
|
|
1979
|
+
})), f;
|
|
2315
1980
|
}
|
|
2316
1981
|
},
|
|
2317
|
-
[
|
|
2318
|
-
),
|
|
2319
|
-
|
|
2320
|
-
...
|
|
2321
|
-
uiMessages:
|
|
1982
|
+
[s.agentId, s.sessionId, e]
|
|
1983
|
+
), g = H((p) => {
|
|
1984
|
+
o((m) => ({
|
|
1985
|
+
...m,
|
|
1986
|
+
uiMessages: nt([...m.uiMessages, p])
|
|
2322
1987
|
}));
|
|
2323
|
-
}, []),
|
|
2324
|
-
|
|
2325
|
-
...
|
|
2326
|
-
suggestions:
|
|
1988
|
+
}, []), h = H((p) => {
|
|
1989
|
+
o((m) => ({
|
|
1990
|
+
...m,
|
|
1991
|
+
suggestions: p
|
|
2327
1992
|
}));
|
|
2328
|
-
}, []),
|
|
2329
|
-
|
|
2330
|
-
...
|
|
1993
|
+
}, []), T = H(() => {
|
|
1994
|
+
o((p) => ({
|
|
1995
|
+
...p,
|
|
2331
1996
|
suggestions: []
|
|
2332
1997
|
}));
|
|
2333
|
-
}, [])
|
|
2334
|
-
|
|
2335
|
-
|
|
2336
|
-
|
|
2337
|
-
|
|
2338
|
-
|
|
2339
|
-
|
|
2340
|
-
|
|
2341
|
-
|
|
2342
|
-
|
|
2343
|
-
|
|
2344
|
-
|
|
2345
|
-
|
|
2346
|
-
), P = d.uiMessages.filter(
|
|
2347
|
-
(m) => {
|
|
2348
|
-
var k;
|
|
2349
|
-
return !I.has(m.id) && ((k = m.content[0]) == null ? void 0 : k.type) === "component";
|
|
2350
|
-
}
|
|
2351
|
-
), w = Q([
|
|
2352
|
-
...T,
|
|
2353
|
-
...P
|
|
2354
|
-
]);
|
|
2355
|
-
return {
|
|
2356
|
-
...d,
|
|
2357
|
-
markdownComponents: f,
|
|
2358
|
-
uiMessages: w
|
|
2359
|
-
};
|
|
2360
|
-
});
|
|
2361
|
-
},
|
|
2362
|
-
[]
|
|
2363
|
-
), x = j(
|
|
2364
|
-
(h) => {
|
|
2365
|
-
a((d) => {
|
|
2366
|
-
const f = {
|
|
2367
|
-
...d.markdownExtensions,
|
|
2368
|
-
...h
|
|
2369
|
-
}, T = d.clientMessages.map(
|
|
2370
|
-
(m) => V(
|
|
2371
|
-
m,
|
|
2372
|
-
g.current
|
|
2373
|
-
)
|
|
2374
|
-
).filter((m) => m !== null), I = new Set(
|
|
2375
|
-
d.clientMessages.map((m) => m.messageId)
|
|
2376
|
-
), P = d.uiMessages.filter(
|
|
2377
|
-
(m) => {
|
|
2378
|
-
var k;
|
|
2379
|
-
return !I.has(m.id) && ((k = m.content[0]) == null ? void 0 : k.type) === "component";
|
|
2380
|
-
}
|
|
2381
|
-
), w = Q([
|
|
2382
|
-
...T,
|
|
2383
|
-
...P
|
|
2384
|
-
]);
|
|
2385
|
-
return {
|
|
2386
|
-
...d,
|
|
2387
|
-
markdownExtensions: f,
|
|
2388
|
-
uiMessages: w
|
|
2389
|
-
};
|
|
2390
|
-
});
|
|
2391
|
-
},
|
|
2392
|
-
[]
|
|
2393
|
-
);
|
|
2394
|
-
Y(() => {
|
|
2395
|
-
a((h) => {
|
|
2396
|
-
if (h.clientMessages.length === 0)
|
|
2397
|
-
return h;
|
|
2398
|
-
const d = h.clientMessages.map(
|
|
2399
|
-
(I) => V(I, g.current)
|
|
2400
|
-
).filter((I) => I !== null), f = new Set(
|
|
2401
|
-
h.clientMessages.map((I) => I.messageId)
|
|
2402
|
-
), T = h.uiMessages.filter(
|
|
2403
|
-
(I) => {
|
|
2404
|
-
var P;
|
|
2405
|
-
return !f.has(I.id) && ((P = I.content[0]) == null ? void 0 : P.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";
|
|
2406
2011
|
}
|
|
2407
2012
|
);
|
|
2408
2013
|
return {
|
|
2409
|
-
...
|
|
2410
|
-
uiMessages:
|
|
2411
|
-
...
|
|
2412
|
-
...
|
|
2014
|
+
...p,
|
|
2015
|
+
uiMessages: nt([
|
|
2016
|
+
...m,
|
|
2017
|
+
...u
|
|
2413
2018
|
])
|
|
2414
2019
|
};
|
|
2415
2020
|
});
|
|
2416
|
-
}, [
|
|
2417
|
-
const
|
|
2418
|
-
()
|
|
2419
|
-
|
|
2420
|
-
|
|
2421
|
-
|
|
2422
|
-
|
|
2423
|
-
), u = j(() => {
|
|
2424
|
-
a((h) => (h.currentAbortController && h.currentAbortController.abort(), h));
|
|
2425
|
-
}, []);
|
|
2021
|
+
}, [i]);
|
|
2022
|
+
const M = H(() => {
|
|
2023
|
+
if (!e)
|
|
2024
|
+
return;
|
|
2025
|
+
const p = st(), m = `${s.agentId}-${s.sessionId}`;
|
|
2026
|
+
p.abortCurrentRequest(m);
|
|
2027
|
+
}, [s.agentId, s.sessionId, e]);
|
|
2426
2028
|
return {
|
|
2427
2029
|
// AgentUI props
|
|
2428
2030
|
messages: n.uiMessages,
|
|
2429
2031
|
isProcessing: n.isProcessing,
|
|
2430
2032
|
error: n.error,
|
|
2431
|
-
onSubmit:
|
|
2033
|
+
onSubmit: c,
|
|
2432
2034
|
suggestions: n.suggestions,
|
|
2433
|
-
messageRenderer: p,
|
|
2434
2035
|
// UI management methods
|
|
2435
|
-
registerSuggestions:
|
|
2436
|
-
clearSuggestions:
|
|
2437
|
-
registerMarkdownComponents: M,
|
|
2438
|
-
registerMarkdownExtensions: x,
|
|
2036
|
+
registerSuggestions: h,
|
|
2037
|
+
clearSuggestions: T,
|
|
2439
2038
|
// Message actions methods
|
|
2440
2039
|
registerMessageActions: r,
|
|
2441
|
-
unregisterMessageActions:
|
|
2442
|
-
clearAllMessageActions:
|
|
2443
|
-
createFeedbackActions: l,
|
|
2040
|
+
unregisterMessageActions: a,
|
|
2041
|
+
clearAllMessageActions: l,
|
|
2444
2042
|
// Tool integration
|
|
2445
|
-
addMessage:
|
|
2043
|
+
addMessage: g,
|
|
2446
2044
|
// Abort control
|
|
2447
|
-
abortCurrentRequest:
|
|
2045
|
+
abortCurrentRequest: M
|
|
2448
2046
|
};
|
|
2449
2047
|
}
|
|
2450
|
-
var
|
|
2451
|
-
const
|
|
2452
|
-
function
|
|
2453
|
-
var
|
|
2454
|
-
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);
|
|
2455
2053
|
}
|
|
2456
|
-
async function
|
|
2457
|
-
var
|
|
2458
|
-
const
|
|
2054
|
+
async function Te(t, s = !0) {
|
|
2055
|
+
var i, d;
|
|
2056
|
+
const e = localStorage.getItem(pt);
|
|
2459
2057
|
let n;
|
|
2460
|
-
if (
|
|
2058
|
+
if (e)
|
|
2461
2059
|
try {
|
|
2462
|
-
n = JSON.parse(
|
|
2463
|
-
} catch (
|
|
2464
|
-
console.warn("Invalid cached Jetpack token:",
|
|
2060
|
+
n = JSON.parse(e);
|
|
2061
|
+
} catch (c) {
|
|
2062
|
+
console.warn("Invalid cached Jetpack token:", c);
|
|
2465
2063
|
}
|
|
2466
|
-
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)
|
|
2467
2065
|
return n;
|
|
2468
|
-
const
|
|
2469
|
-
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 = {
|
|
2470
2068
|
token: "",
|
|
2471
2069
|
blog_id: ""
|
|
2472
2070
|
};
|
|
2473
2071
|
try {
|
|
2474
|
-
|
|
2072
|
+
Ie() ? a = await ut({
|
|
2475
2073
|
path: "/wpcom/v2/sites/" + r + "/jetpack-openai-query/jwt",
|
|
2476
2074
|
method: "POST"
|
|
2477
|
-
}) :
|
|
2075
|
+
}) : a = await ut({
|
|
2478
2076
|
path: "/jetpack/v4/jetpack-ai-jwt?_cacheBuster=" + Date.now(),
|
|
2479
2077
|
credentials: "same-origin",
|
|
2480
2078
|
headers: {
|
|
2481
|
-
"X-WP-Nonce":
|
|
2079
|
+
"X-WP-Nonce": o || ""
|
|
2482
2080
|
},
|
|
2483
2081
|
method: "POST"
|
|
2484
2082
|
});
|
|
2485
|
-
} catch (
|
|
2486
|
-
throw console.log("Failed to fetch Jetpack token:",
|
|
2083
|
+
} catch (c) {
|
|
2084
|
+
throw console.log("Failed to fetch Jetpack token:", c), new Error(t(c));
|
|
2487
2085
|
}
|
|
2488
|
-
if (!(
|
|
2086
|
+
if (!(a != null && a.token))
|
|
2489
2087
|
throw new Error(
|
|
2490
2088
|
"Authentication failed. Please ensure Jetpack is properly connected and try again."
|
|
2491
2089
|
);
|
|
2492
|
-
const
|
|
2493
|
-
token:
|
|
2494
|
-
blogId:
|
|
2495
|
-
expire: Date.now() +
|
|
2090
|
+
const l = {
|
|
2091
|
+
token: a.token,
|
|
2092
|
+
blogId: a.blog_id || "",
|
|
2093
|
+
expire: Date.now() + we
|
|
2496
2094
|
};
|
|
2497
2095
|
try {
|
|
2498
|
-
localStorage.setItem(
|
|
2499
|
-
} catch (
|
|
2500
|
-
console.log("Error storing token in localStorage:",
|
|
2096
|
+
localStorage.setItem(pt, JSON.stringify(l));
|
|
2097
|
+
} catch (c) {
|
|
2098
|
+
console.log("Error storing token in localStorage:", c);
|
|
2501
2099
|
}
|
|
2502
|
-
return
|
|
2100
|
+
return l;
|
|
2503
2101
|
}
|
|
2504
|
-
const
|
|
2505
|
-
const
|
|
2102
|
+
const Pe = (t) => async () => {
|
|
2103
|
+
const s = {};
|
|
2506
2104
|
try {
|
|
2507
|
-
const
|
|
2508
|
-
|
|
2509
|
-
} catch (
|
|
2510
|
-
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;
|
|
2511
2109
|
}
|
|
2512
|
-
return
|
|
2110
|
+
return s;
|
|
2513
2111
|
};
|
|
2514
2112
|
export {
|
|
2515
|
-
|
|
2516
|
-
|
|
2517
|
-
|
|
2518
|
-
|
|
2519
|
-
|
|
2520
|
-
|
|
2521
|
-
|
|
2522
|
-
|
|
2523
|
-
|
|
2524
|
-
|
|
2525
|
-
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
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
|
|
2534
2132
|
};
|