@fencyai/react 0.1.112 → 0.1.113
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/agent-task/data-types/StreamingChatCompletionResponse.d.ts +8 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +492 -462
- package/dist/provider/FencyProvider.d.ts +1 -1
- package/dist/types/AgentTaskEventData.d.ts +3 -0
- package/dist/types/CreateAgentTaskParams.d.ts +7 -4
- package/dist/types/FencyContext.d.ts +1 -4
- package/dist/types/FencyProviderProps.d.ts +3 -0
- package/dist/types/UseAgentTasksProps.d.ts +1 -5
- package/dist/types/UseStreamProps.d.ts +0 -4
- package/package.json +4 -4
package/dist/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { createAgentTask as q, createFileDownloadLink as V, createStream as X } from "@fencyai/js";
|
|
2
|
-
import { createContext as J, useContext as Y, useState as
|
|
3
|
-
import { jsx as g, jsxs as
|
|
4
|
-
import { useInView as Q, motion as
|
|
5
|
-
import
|
|
6
|
-
import { Prism as
|
|
7
|
-
import
|
|
2
|
+
import { createContext as J, useContext as Y, useState as w, useRef as P, useEffect as T, useCallback as U, useMemo as L } from "react";
|
|
3
|
+
import { jsx as g, jsxs as E } from "react/jsx-runtime";
|
|
4
|
+
import { useInView as Q, motion as A, AnimatePresence as W } from "motion/react";
|
|
5
|
+
import D from "react-markdown";
|
|
6
|
+
import { Prism as M } from "react-syntax-highlighter";
|
|
7
|
+
import B from "remark-gfm";
|
|
8
8
|
import './assets/index.css';const j = J(
|
|
9
9
|
void 0
|
|
10
10
|
);
|
|
11
|
-
function
|
|
11
|
+
function F() {
|
|
12
12
|
const e = Y(j);
|
|
13
13
|
if (e === void 0)
|
|
14
14
|
throw new Error("useFencyContext must be used within a FencyProvider");
|
|
@@ -50,50 +50,50 @@ const Z = (e) => {
|
|
|
50
50
|
createdAt: e.createdAt,
|
|
51
51
|
data: JSON.parse(e.data)
|
|
52
52
|
}), re = (e) => {
|
|
53
|
-
const t =
|
|
54
|
-
return
|
|
53
|
+
const t = F(), [r, n] = w(null), a = P(`subscriber-${Math.random().toString(36).substr(2, 9)}`);
|
|
54
|
+
return T(() => {
|
|
55
55
|
if (!t.eventManager) return;
|
|
56
|
-
const
|
|
57
|
-
onMessage: (o,
|
|
58
|
-
var
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
switch (
|
|
56
|
+
const c = {
|
|
57
|
+
onMessage: (o, i) => {
|
|
58
|
+
var s, d, f, y, S, b, h, k, I, C;
|
|
59
|
+
const m = Z(o);
|
|
60
|
+
if (m)
|
|
61
|
+
switch (m.type) {
|
|
62
62
|
case "NewChatCompletionStreamChunk":
|
|
63
|
-
(
|
|
63
|
+
(s = e == null ? void 0 : e.onNewChatCompletionStreamChunk) == null || s.call(e, m);
|
|
64
64
|
break;
|
|
65
65
|
case "ChatCompletionStreamCompleted":
|
|
66
|
-
(
|
|
66
|
+
(d = e == null ? void 0 : e.onChatCompletionStreamCompleted) == null || d.call(e, m);
|
|
67
67
|
break;
|
|
68
68
|
case "StreamTimeout":
|
|
69
|
-
(
|
|
69
|
+
(f = e == null ? void 0 : e.onStreamTimeout) == null || f.call(e, m);
|
|
70
70
|
break;
|
|
71
71
|
case "StreamNotFound":
|
|
72
|
-
(
|
|
72
|
+
(y = e == null ? void 0 : e.onStreamNotFound) == null || y.call(e, m);
|
|
73
73
|
break;
|
|
74
74
|
case "FileUploadCompleted":
|
|
75
|
-
(
|
|
75
|
+
(S = e == null ? void 0 : e.onFileUploadCompleted) == null || S.call(e, m);
|
|
76
76
|
break;
|
|
77
77
|
case "FileTextContentReady":
|
|
78
|
-
(
|
|
78
|
+
(b = e == null ? void 0 : e.onFileTextContentReady) == null || b.call(e, m);
|
|
79
79
|
break;
|
|
80
80
|
case "WebsiteHtmlContentReady":
|
|
81
|
-
(
|
|
81
|
+
(h = e == null ? void 0 : e.onWebsiteHtmlContentReady) == null || h.call(e, m);
|
|
82
82
|
break;
|
|
83
83
|
case "WebsiteTextContentReady":
|
|
84
|
-
(k = e == null ? void 0 : e.onWebsiteTextContentReady) == null || k.call(e,
|
|
84
|
+
(k = e == null ? void 0 : e.onWebsiteTextContentReady) == null || k.call(e, m);
|
|
85
85
|
break;
|
|
86
86
|
case "FileSearchIndexReady":
|
|
87
|
-
(
|
|
87
|
+
(I = e == null ? void 0 : e.onFileSearchIndexReady) == null || I.call(e, m);
|
|
88
88
|
break;
|
|
89
89
|
case "AgentTaskProgressItemUpdated":
|
|
90
|
-
(
|
|
90
|
+
(C = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || C.call(e, m);
|
|
91
91
|
break;
|
|
92
92
|
}
|
|
93
93
|
},
|
|
94
94
|
onError: (o) => {
|
|
95
|
-
var
|
|
96
|
-
(
|
|
95
|
+
var i;
|
|
96
|
+
(i = e == null ? void 0 : e.onStreamError) == null || i.call(e, {
|
|
97
97
|
streamId: o,
|
|
98
98
|
error: {
|
|
99
99
|
code: "UnknownError",
|
|
@@ -104,91 +104,74 @@ const Z = (e) => {
|
|
|
104
104
|
};
|
|
105
105
|
return t.eventManager.subscribe(
|
|
106
106
|
a.current,
|
|
107
|
-
|
|
107
|
+
c
|
|
108
108
|
);
|
|
109
109
|
}, [t.eventManager, e]), {
|
|
110
110
|
createStream: async () => {
|
|
111
111
|
try {
|
|
112
|
-
const
|
|
113
|
-
return
|
|
112
|
+
const c = await t.getOrCreateStream(3e4);
|
|
113
|
+
return n(c), {
|
|
114
114
|
type: "success",
|
|
115
|
-
stream:
|
|
115
|
+
stream: c
|
|
116
116
|
};
|
|
117
|
-
} catch (
|
|
117
|
+
} catch (c) {
|
|
118
118
|
return {
|
|
119
119
|
type: "error",
|
|
120
120
|
error: {
|
|
121
121
|
code: "UnknownError",
|
|
122
|
-
message:
|
|
122
|
+
message: c instanceof Error ? c.message : "Failed to create stream"
|
|
123
123
|
}
|
|
124
124
|
};
|
|
125
125
|
}
|
|
126
126
|
},
|
|
127
|
-
stream:
|
|
127
|
+
stream: r
|
|
128
128
|
};
|
|
129
|
-
},
|
|
130
|
-
const t =
|
|
131
|
-
fetchTokens: e.fetchCreateStreamTokens,
|
|
129
|
+
}, Re = (e) => {
|
|
130
|
+
const t = F(), [r, n] = w([]), a = P(/* @__PURE__ */ new Set()), { createStream: u } = re({
|
|
132
131
|
onAgentTaskProgressItemUpdated: (o) => {
|
|
133
|
-
var
|
|
134
|
-
a.current.has(o.agentTaskId) && ((
|
|
135
|
-
|
|
136
|
-
(
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
{
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
(m) => m.progressItemId === o.progressItemId ? o : m
|
|
146
|
-
)
|
|
147
|
-
}
|
|
148
|
-
] : [
|
|
149
|
-
...l.filter(
|
|
150
|
-
(m) => m.streamId !== o.streamId
|
|
151
|
-
),
|
|
152
|
-
{
|
|
153
|
-
...i,
|
|
154
|
-
progressItems: [
|
|
155
|
-
...i.progressItems,
|
|
156
|
-
o
|
|
157
|
-
]
|
|
158
|
-
}
|
|
159
|
-
] : l;
|
|
160
|
-
}));
|
|
132
|
+
var i;
|
|
133
|
+
a.current.has(o.agentTaskId) && ((i = e.onAgentTaskProgressItemUpdated) == null || i.call(e, o), n(
|
|
134
|
+
(m) => m.map((s) => {
|
|
135
|
+
if (s.streamId !== o.streamId) return s;
|
|
136
|
+
const f = s.progressItems.some(
|
|
137
|
+
(y) => y.progressItemId === o.progressItemId
|
|
138
|
+
) ? s.progressItems.map(
|
|
139
|
+
(y) => y.progressItemId === o.progressItemId ? o : y
|
|
140
|
+
) : [...s.progressItems, o];
|
|
141
|
+
return { ...s, progressItems: f };
|
|
142
|
+
})
|
|
143
|
+
));
|
|
161
144
|
},
|
|
162
145
|
onStreamError: (o) => {
|
|
163
|
-
var
|
|
164
|
-
(
|
|
165
|
-
const
|
|
166
|
-
return
|
|
167
|
-
...
|
|
146
|
+
var i;
|
|
147
|
+
(i = e == null ? void 0 : e.onStreamError) == null || i.call(e, o), n((m) => {
|
|
148
|
+
const s = m.find((d) => d.streamId === o.streamId);
|
|
149
|
+
return s ? [
|
|
150
|
+
...m.filter((d) => d.streamId !== o.streamId),
|
|
168
151
|
{
|
|
169
|
-
...
|
|
152
|
+
...s,
|
|
170
153
|
loading: !1,
|
|
171
154
|
error: o.error
|
|
172
155
|
}
|
|
173
|
-
] :
|
|
156
|
+
] : m;
|
|
174
157
|
});
|
|
175
158
|
},
|
|
176
159
|
onStreamNotFound: (o) => {
|
|
177
|
-
var
|
|
178
|
-
(
|
|
160
|
+
var i;
|
|
161
|
+
(i = e == null ? void 0 : e.onStreamNotFound) == null || i.call(e, o);
|
|
179
162
|
},
|
|
180
163
|
onStreamTimeout: (o) => {
|
|
181
|
-
var
|
|
182
|
-
(
|
|
164
|
+
var i;
|
|
165
|
+
(i = e == null ? void 0 : e.onStreamTimeout) == null || i.call(e, o);
|
|
183
166
|
}
|
|
184
|
-
}),
|
|
167
|
+
}), c = U(
|
|
185
168
|
async (o) => {
|
|
186
|
-
const
|
|
187
|
-
if (
|
|
188
|
-
|
|
189
|
-
...
|
|
169
|
+
const i = await u();
|
|
170
|
+
if (i.type === "success") {
|
|
171
|
+
n([
|
|
172
|
+
...r,
|
|
190
173
|
{
|
|
191
|
-
streamId:
|
|
174
|
+
streamId: i.stream.id,
|
|
192
175
|
triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
193
176
|
confirmedData: null,
|
|
194
177
|
error: null,
|
|
@@ -198,53 +181,53 @@ const Z = (e) => {
|
|
|
198
181
|
doneStreaming: !1
|
|
199
182
|
}
|
|
200
183
|
]);
|
|
201
|
-
const { clientToken:
|
|
184
|
+
const { clientToken: m } = await e.fetchCreateAgentTaskClientToken(o.type), s = await q({
|
|
202
185
|
pk: t.fency.publishableKey,
|
|
203
186
|
baseUrl: t.fency.baseUrl,
|
|
204
|
-
clientToken:
|
|
205
|
-
streamToken:
|
|
187
|
+
clientToken: m,
|
|
188
|
+
streamToken: i.stream.token,
|
|
206
189
|
request: {
|
|
207
|
-
genericTask: {
|
|
208
|
-
|
|
209
|
-
jsonSchema: o.jsonSchema
|
|
210
|
-
}
|
|
190
|
+
genericTask: o.type === "genericAgentTask" ? { queryText: o.query, jsonSchema: o.jsonSchema } : void 0,
|
|
191
|
+
streamingChatCompletionTask: o.type === "streamingChatCompletion" ? { prompt: o.prompt } : void 0
|
|
211
192
|
}
|
|
212
193
|
});
|
|
213
|
-
if (
|
|
214
|
-
return a.current.add(
|
|
215
|
-
|
|
216
|
-
|
|
194
|
+
if (s.type === "success" && s.agentTask)
|
|
195
|
+
return a.current.add(
|
|
196
|
+
s.agentTask.id
|
|
197
|
+
), n((d) => [
|
|
198
|
+
...d.filter(
|
|
199
|
+
(f) => f.streamId !== i.stream.id
|
|
217
200
|
),
|
|
218
201
|
{
|
|
219
|
-
streamId:
|
|
202
|
+
streamId: i.stream.id,
|
|
220
203
|
triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
221
|
-
taskId:
|
|
222
|
-
createdAt:
|
|
204
|
+
taskId: s.agentTask.id,
|
|
205
|
+
createdAt: s.agentTask.createdAt,
|
|
223
206
|
error: null,
|
|
224
207
|
params: o,
|
|
225
208
|
progressItems: [],
|
|
226
209
|
doneStreaming: !1,
|
|
227
210
|
loading: !0,
|
|
228
211
|
confirmedData: {
|
|
229
|
-
taskId:
|
|
230
|
-
createdAt:
|
|
212
|
+
taskId: s.agentTask.id,
|
|
213
|
+
createdAt: s.agentTask.createdAt
|
|
231
214
|
}
|
|
232
215
|
}
|
|
233
216
|
]), {
|
|
234
217
|
type: "success",
|
|
235
|
-
streamId:
|
|
236
|
-
agentTaskId:
|
|
218
|
+
streamId: i.stream.id,
|
|
219
|
+
agentTaskId: s.agentTask.id
|
|
237
220
|
};
|
|
238
|
-
if (
|
|
239
|
-
return
|
|
240
|
-
...
|
|
241
|
-
(
|
|
221
|
+
if (s.type === "error")
|
|
222
|
+
return n((d) => [
|
|
223
|
+
...d.filter(
|
|
224
|
+
(f) => f.streamId !== i.stream.id
|
|
242
225
|
),
|
|
243
226
|
{
|
|
244
227
|
triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
245
|
-
streamId:
|
|
228
|
+
streamId: i.stream.id,
|
|
246
229
|
params: o,
|
|
247
|
-
error:
|
|
230
|
+
error: s.error,
|
|
248
231
|
progressItems: [],
|
|
249
232
|
loading: !1,
|
|
250
233
|
doneStreaming: !1,
|
|
@@ -252,21 +235,21 @@ const Z = (e) => {
|
|
|
252
235
|
}
|
|
253
236
|
]), {
|
|
254
237
|
type: "error",
|
|
255
|
-
error:
|
|
238
|
+
error: s.error
|
|
256
239
|
};
|
|
257
240
|
{
|
|
258
|
-
const
|
|
241
|
+
const d = {
|
|
259
242
|
message: "No response received",
|
|
260
243
|
code: "UnknownError"
|
|
261
244
|
};
|
|
262
|
-
return
|
|
263
|
-
...
|
|
264
|
-
(
|
|
245
|
+
return n((f) => [
|
|
246
|
+
...f.filter(
|
|
247
|
+
(y) => y.streamId !== i.stream.id
|
|
265
248
|
),
|
|
266
249
|
{
|
|
267
250
|
triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
268
|
-
streamId:
|
|
269
|
-
error:
|
|
251
|
+
streamId: i.stream.id,
|
|
252
|
+
error: d,
|
|
270
253
|
params: o,
|
|
271
254
|
progressItems: [],
|
|
272
255
|
loading: !1,
|
|
@@ -275,87 +258,87 @@ const Z = (e) => {
|
|
|
275
258
|
}
|
|
276
259
|
]), {
|
|
277
260
|
type: "error",
|
|
278
|
-
error:
|
|
261
|
+
error: d
|
|
279
262
|
};
|
|
280
263
|
}
|
|
281
264
|
} else
|
|
282
|
-
return console.error(
|
|
265
|
+
return console.error(i.error), i;
|
|
283
266
|
},
|
|
284
|
-
[t,
|
|
285
|
-
),
|
|
286
|
-
return
|
|
267
|
+
[t, r, u]
|
|
268
|
+
), l = L(() => r.sort((o, i) => new Date(i.triggeredAt).getTime() - new Date(o.triggeredAt).getTime())[0], [r]);
|
|
269
|
+
return T(() => () => {
|
|
287
270
|
a.current.clear();
|
|
288
271
|
}, []), {
|
|
289
|
-
agentTasks:
|
|
290
|
-
createAgentTask:
|
|
291
|
-
latest:
|
|
272
|
+
agentTasks: r,
|
|
273
|
+
createAgentTask: c,
|
|
274
|
+
latest: l
|
|
292
275
|
};
|
|
293
276
|
};
|
|
294
277
|
async function ae(e, t) {
|
|
295
|
-
const
|
|
296
|
-
let
|
|
297
|
-
for (; !(
|
|
298
|
-
t(
|
|
278
|
+
const r = e.getReader();
|
|
279
|
+
let n;
|
|
280
|
+
for (; !(n = await r.read()).done; )
|
|
281
|
+
t(n.value);
|
|
299
282
|
}
|
|
300
283
|
function oe(e) {
|
|
301
|
-
let t,
|
|
302
|
-
return function(
|
|
303
|
-
t === void 0 ? (t =
|
|
304
|
-
const
|
|
284
|
+
let t, r, n, a = !1;
|
|
285
|
+
return function(c) {
|
|
286
|
+
t === void 0 ? (t = c, r = 0, n = -1) : t = se(t, c);
|
|
287
|
+
const l = t.length;
|
|
305
288
|
let o = 0;
|
|
306
|
-
for (;
|
|
307
|
-
a && (t[
|
|
308
|
-
let
|
|
309
|
-
for (;
|
|
310
|
-
switch (t[
|
|
289
|
+
for (; r < l; ) {
|
|
290
|
+
a && (t[r] === 10 && (o = ++r), a = !1);
|
|
291
|
+
let i = -1;
|
|
292
|
+
for (; r < l && i === -1; ++r)
|
|
293
|
+
switch (t[r]) {
|
|
311
294
|
case 58:
|
|
312
|
-
|
|
295
|
+
n === -1 && (n = r - o);
|
|
313
296
|
break;
|
|
314
297
|
case 13:
|
|
315
298
|
a = !0;
|
|
316
299
|
case 10:
|
|
317
|
-
|
|
300
|
+
i = r;
|
|
318
301
|
break;
|
|
319
302
|
}
|
|
320
|
-
if (
|
|
303
|
+
if (i === -1)
|
|
321
304
|
break;
|
|
322
|
-
e(t.subarray(o,
|
|
305
|
+
e(t.subarray(o, i), n), o = r, n = -1;
|
|
323
306
|
}
|
|
324
|
-
o ===
|
|
307
|
+
o === l ? t = void 0 : o !== 0 && (t = t.subarray(o), r -= o);
|
|
325
308
|
};
|
|
326
309
|
}
|
|
327
|
-
function ie(e, t,
|
|
328
|
-
let
|
|
310
|
+
function ie(e, t, r) {
|
|
311
|
+
let n = H();
|
|
329
312
|
const a = new TextDecoder();
|
|
330
|
-
return function(
|
|
331
|
-
if (
|
|
332
|
-
|
|
333
|
-
else if (
|
|
334
|
-
const o = a.decode(
|
|
313
|
+
return function(c, l) {
|
|
314
|
+
if (c.length === 0)
|
|
315
|
+
r == null || r(n), n = H();
|
|
316
|
+
else if (l > 0) {
|
|
317
|
+
const o = a.decode(c.subarray(0, l)), i = l + (c[l + 1] === 32 ? 2 : 1), m = a.decode(c.subarray(i));
|
|
335
318
|
switch (o) {
|
|
336
319
|
case "data":
|
|
337
|
-
|
|
338
|
-
` +
|
|
320
|
+
n.data = n.data ? n.data + `
|
|
321
|
+
` + m : m;
|
|
339
322
|
break;
|
|
340
323
|
case "event":
|
|
341
|
-
|
|
324
|
+
n.event = m;
|
|
342
325
|
break;
|
|
343
326
|
case "id":
|
|
344
|
-
e(
|
|
327
|
+
e(n.id = m);
|
|
345
328
|
break;
|
|
346
329
|
case "retry":
|
|
347
|
-
const
|
|
348
|
-
isNaN(
|
|
330
|
+
const s = parseInt(m, 10);
|
|
331
|
+
isNaN(s) || t(n.retry = s);
|
|
349
332
|
break;
|
|
350
333
|
}
|
|
351
334
|
}
|
|
352
335
|
};
|
|
353
336
|
}
|
|
354
337
|
function se(e, t) {
|
|
355
|
-
const
|
|
356
|
-
return
|
|
338
|
+
const r = new Uint8Array(e.length + t.length);
|
|
339
|
+
return r.set(e), r.set(t, e.length), r;
|
|
357
340
|
}
|
|
358
|
-
function
|
|
341
|
+
function H() {
|
|
359
342
|
return {
|
|
360
343
|
data: "",
|
|
361
344
|
event: "",
|
|
@@ -364,49 +347,49 @@ function D() {
|
|
|
364
347
|
};
|
|
365
348
|
}
|
|
366
349
|
var ce = function(e, t) {
|
|
367
|
-
var
|
|
368
|
-
for (var
|
|
350
|
+
var r = {};
|
|
351
|
+
for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
|
|
369
352
|
if (e != null && typeof Object.getOwnPropertySymbols == "function")
|
|
370
|
-
for (var a = 0,
|
|
371
|
-
t.indexOf(
|
|
372
|
-
return
|
|
353
|
+
for (var a = 0, n = Object.getOwnPropertySymbols(e); a < n.length; a++)
|
|
354
|
+
t.indexOf(n[a]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[a]) && (r[n[a]] = e[n[a]]);
|
|
355
|
+
return r;
|
|
373
356
|
};
|
|
374
|
-
const O = "text/event-stream", le = 1e3,
|
|
375
|
-
function
|
|
376
|
-
var { signal:
|
|
377
|
-
return new Promise((
|
|
378
|
-
const
|
|
379
|
-
|
|
380
|
-
let
|
|
381
|
-
function
|
|
382
|
-
|
|
357
|
+
const O = "text/event-stream", le = 1e3, G = "last-event-id";
|
|
358
|
+
function $(e, t) {
|
|
359
|
+
var { signal: r, headers: n, onopen: a, onmessage: u, onclose: c, onerror: l, openWhenHidden: o, fetch: i } = t, m = ce(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
|
|
360
|
+
return new Promise((s, d) => {
|
|
361
|
+
const f = Object.assign({}, n);
|
|
362
|
+
f.accept || (f.accept = O);
|
|
363
|
+
let y;
|
|
364
|
+
function S() {
|
|
365
|
+
y.abort(), document.hidden || x();
|
|
383
366
|
}
|
|
384
|
-
o || document.addEventListener("visibilitychange",
|
|
385
|
-
let
|
|
367
|
+
o || document.addEventListener("visibilitychange", S);
|
|
368
|
+
let b = le, h = 0;
|
|
386
369
|
function k() {
|
|
387
|
-
document.removeEventListener("visibilitychange",
|
|
370
|
+
document.removeEventListener("visibilitychange", S), window.clearTimeout(h), y.abort();
|
|
388
371
|
}
|
|
389
|
-
|
|
390
|
-
k(),
|
|
372
|
+
r == null || r.addEventListener("abort", () => {
|
|
373
|
+
k(), s();
|
|
391
374
|
});
|
|
392
|
-
const
|
|
375
|
+
const I = i ?? window.fetch, C = a ?? de;
|
|
393
376
|
async function x() {
|
|
394
377
|
var N;
|
|
395
|
-
|
|
378
|
+
y = new AbortController();
|
|
396
379
|
try {
|
|
397
|
-
const
|
|
398
|
-
await
|
|
399
|
-
|
|
400
|
-
}, (
|
|
401
|
-
|
|
402
|
-
},
|
|
403
|
-
} catch (
|
|
404
|
-
if (!
|
|
380
|
+
const R = await I(e, Object.assign(Object.assign({}, m), { headers: f, signal: y.signal }));
|
|
381
|
+
await C(R), await ae(R.body, oe(ie((v) => {
|
|
382
|
+
v ? f[G] = v : delete f[G];
|
|
383
|
+
}, (v) => {
|
|
384
|
+
b = v;
|
|
385
|
+
}, u))), c == null || c(), k(), s();
|
|
386
|
+
} catch (R) {
|
|
387
|
+
if (!y.signal.aborted)
|
|
405
388
|
try {
|
|
406
|
-
const
|
|
407
|
-
window.clearTimeout(
|
|
408
|
-
} catch (
|
|
409
|
-
k(),
|
|
389
|
+
const v = (N = l == null ? void 0 : l(R)) !== null && N !== void 0 ? N : b;
|
|
390
|
+
window.clearTimeout(h), h = window.setTimeout(x, v);
|
|
391
|
+
} catch (v) {
|
|
392
|
+
k(), d(v);
|
|
410
393
|
}
|
|
411
394
|
}
|
|
412
395
|
}
|
|
@@ -418,15 +401,15 @@ function de(e) {
|
|
|
418
401
|
if (!(t != null && t.startsWith(O)))
|
|
419
402
|
throw new Error(`Expected content-type to be ${O}, Actual: ${t}`);
|
|
420
403
|
}
|
|
421
|
-
function
|
|
422
|
-
const [t,
|
|
423
|
-
return
|
|
404
|
+
function Ne(e) {
|
|
405
|
+
const [t, r] = w(null);
|
|
406
|
+
return T(() => {
|
|
424
407
|
if (!t)
|
|
425
408
|
return;
|
|
426
|
-
const
|
|
427
|
-
return
|
|
409
|
+
const n = new AbortController();
|
|
410
|
+
return $(t, {
|
|
428
411
|
headers: e == null ? void 0 : e.headers,
|
|
429
|
-
signal:
|
|
412
|
+
signal: n.signal,
|
|
430
413
|
async onopen(a) {
|
|
431
414
|
if (!a.ok && a.status >= 400 && a.status < 500 && a.status !== 429)
|
|
432
415
|
throw new Error(`Client error ${a.status}`);
|
|
@@ -434,74 +417,74 @@ function Fe(e) {
|
|
|
434
417
|
onmessage(a) {
|
|
435
418
|
a.data && (e == null || e.onMessage({
|
|
436
419
|
url: t,
|
|
437
|
-
data:
|
|
420
|
+
data: K(a.data)
|
|
438
421
|
}));
|
|
439
422
|
},
|
|
440
423
|
onerror(a) {
|
|
441
|
-
throw console.error("EventSource error:", a), e == null || e.onError(t),
|
|
424
|
+
throw console.error("EventSource error:", a), e == null || e.onError(t), r(null), a;
|
|
442
425
|
},
|
|
443
426
|
onclose() {
|
|
444
427
|
}
|
|
445
428
|
}), () => {
|
|
446
|
-
|
|
429
|
+
n.abort();
|
|
447
430
|
};
|
|
448
431
|
}, [t, e == null ? void 0 : e.headers]), {
|
|
449
|
-
setSourceUrl:
|
|
432
|
+
setSourceUrl: r,
|
|
450
433
|
sourceUrl: t
|
|
451
434
|
};
|
|
452
435
|
}
|
|
453
|
-
function
|
|
454
|
-
const t = atob(e),
|
|
455
|
-
for (let
|
|
456
|
-
n
|
|
457
|
-
return new TextDecoder("utf-8").decode(
|
|
436
|
+
function K(e) {
|
|
437
|
+
const t = atob(e), r = new Uint8Array(t.length);
|
|
438
|
+
for (let n = 0; n < t.length; n++)
|
|
439
|
+
r[n] = t.charCodeAt(n);
|
|
440
|
+
return new TextDecoder("utf-8").decode(r);
|
|
458
441
|
}
|
|
459
|
-
function
|
|
460
|
-
const [
|
|
442
|
+
function Fe(e, t) {
|
|
443
|
+
const [r, n] = w(
|
|
461
444
|
null
|
|
462
|
-
), [a,
|
|
445
|
+
), [a, u] = w(
|
|
463
446
|
null
|
|
464
|
-
),
|
|
465
|
-
const
|
|
466
|
-
pk:
|
|
467
|
-
clientToken:
|
|
468
|
-
streamToken:
|
|
447
|
+
), c = F(), l = async (s) => {
|
|
448
|
+
const d = await s.fetchTokens(), { fetchTokens: f, nextPageToken: y, previousPageToken: S, ...b } = s, h = await e({
|
|
449
|
+
pk: c.fency.publishableKey,
|
|
450
|
+
clientToken: d.clientToken,
|
|
451
|
+
streamToken: d.streamToken,
|
|
469
452
|
request: {
|
|
470
|
-
...
|
|
453
|
+
...b,
|
|
471
454
|
limit: (t == null ? void 0 : t.pageSize) ?? 50,
|
|
472
455
|
pagination: {
|
|
473
|
-
nextPageToken:
|
|
474
|
-
previousPageToken:
|
|
456
|
+
nextPageToken: y,
|
|
457
|
+
previousPageToken: S
|
|
475
458
|
}
|
|
476
459
|
},
|
|
477
|
-
baseUrl:
|
|
460
|
+
baseUrl: c.fency.baseUrl
|
|
478
461
|
});
|
|
479
|
-
return
|
|
462
|
+
return h.type === "success" && h.items && h.pagination ? {
|
|
480
463
|
type: "success",
|
|
481
464
|
page: {
|
|
482
|
-
items:
|
|
483
|
-
hasNextPage:
|
|
484
|
-
hasPreviousPage:
|
|
485
|
-
pagination:
|
|
465
|
+
items: h.items,
|
|
466
|
+
hasNextPage: h.pagination.nextPageToken != null,
|
|
467
|
+
hasPreviousPage: h.pagination.previousPageToken != null,
|
|
468
|
+
pagination: h.pagination
|
|
486
469
|
}
|
|
487
470
|
} : {
|
|
488
471
|
type: "error",
|
|
489
|
-
error:
|
|
472
|
+
error: h.error ?? {
|
|
490
473
|
code: "UNKNOWN_ERROR",
|
|
491
474
|
message: "An unknown error occurred"
|
|
492
475
|
}
|
|
493
476
|
};
|
|
494
477
|
};
|
|
495
478
|
return {
|
|
496
|
-
fetchFirstPage: async (
|
|
497
|
-
const
|
|
498
|
-
...
|
|
479
|
+
fetchFirstPage: async (s) => {
|
|
480
|
+
const d = await l({
|
|
481
|
+
...s,
|
|
499
482
|
nextPageToken: void 0,
|
|
500
483
|
previousPageToken: void 0
|
|
501
484
|
});
|
|
502
|
-
return
|
|
485
|
+
return d.type === "success" && (u(d.page), n(s)), d;
|
|
503
486
|
},
|
|
504
|
-
fetchNextPage: async (
|
|
487
|
+
fetchNextPage: async (s) => {
|
|
505
488
|
if (a == null)
|
|
506
489
|
return {
|
|
507
490
|
type: "error",
|
|
@@ -518,14 +501,14 @@ function Ne(e, t) {
|
|
|
518
501
|
message: "No next page"
|
|
519
502
|
}
|
|
520
503
|
};
|
|
521
|
-
const
|
|
522
|
-
...
|
|
504
|
+
const d = await l({
|
|
505
|
+
...s,
|
|
523
506
|
nextPageToken: a.pagination.nextPageToken,
|
|
524
507
|
previousPageToken: void 0
|
|
525
508
|
});
|
|
526
|
-
return
|
|
509
|
+
return d.type === "success" && (u(d.page), n(s)), d;
|
|
527
510
|
},
|
|
528
|
-
fetchPreviousPage: async (
|
|
511
|
+
fetchPreviousPage: async (s) => {
|
|
529
512
|
if (a == null)
|
|
530
513
|
return {
|
|
531
514
|
type: "error",
|
|
@@ -542,60 +525,60 @@ function Ne(e, t) {
|
|
|
542
525
|
message: "No previous page"
|
|
543
526
|
}
|
|
544
527
|
};
|
|
545
|
-
const
|
|
546
|
-
...
|
|
528
|
+
const d = await l({
|
|
529
|
+
...s,
|
|
547
530
|
nextPageToken: void 0,
|
|
548
531
|
previousPageToken: a.pagination.previousPageToken
|
|
549
532
|
});
|
|
550
|
-
return
|
|
533
|
+
return d.type === "success" && (u(d.page), n(s)), d;
|
|
551
534
|
},
|
|
552
|
-
refetchCurrentPage: async () =>
|
|
535
|
+
refetchCurrentPage: async () => r == null ? {
|
|
553
536
|
type: "error",
|
|
554
537
|
error: {
|
|
555
538
|
code: "NO_CURRENT_PAGE",
|
|
556
539
|
message: "No current page, please call fetchFirstPage first."
|
|
557
540
|
}
|
|
558
|
-
} :
|
|
541
|
+
} : l(r),
|
|
559
542
|
currentPage: a
|
|
560
543
|
};
|
|
561
544
|
}
|
|
562
545
|
function ue(e) {
|
|
563
|
-
return e.progressItems.map((t,
|
|
564
|
-
const
|
|
565
|
-
let
|
|
566
|
-
if (
|
|
567
|
-
const
|
|
568
|
-
|
|
546
|
+
return e.progressItems.map((t, r) => {
|
|
547
|
+
const n = e.progressItems[r + 1], a = n != null;
|
|
548
|
+
let u;
|
|
549
|
+
if (n != null && n.createdAt) {
|
|
550
|
+
const c = new Date(t.createdAt).getTime(), l = new Date(n.createdAt).getTime();
|
|
551
|
+
u = Math.round((l - c) / 1e3);
|
|
569
552
|
}
|
|
570
553
|
return {
|
|
571
554
|
item: t,
|
|
572
555
|
completed: a,
|
|
573
|
-
isLatest:
|
|
574
|
-
durationSeconds:
|
|
556
|
+
isLatest: r === e.progressItems.length - 1,
|
|
557
|
+
durationSeconds: u
|
|
575
558
|
};
|
|
576
559
|
});
|
|
577
560
|
}
|
|
578
|
-
function
|
|
561
|
+
function _({
|
|
579
562
|
text: e,
|
|
580
563
|
duration: t = 2,
|
|
581
|
-
delay:
|
|
582
|
-
repeat:
|
|
564
|
+
delay: r = 0,
|
|
565
|
+
repeat: n = !0,
|
|
583
566
|
repeatDelay: a = 0.5,
|
|
584
|
-
className:
|
|
585
|
-
startOnView:
|
|
586
|
-
once:
|
|
567
|
+
className: u,
|
|
568
|
+
startOnView: c = !1,
|
|
569
|
+
once: l = !1,
|
|
587
570
|
inViewMargin: o,
|
|
588
|
-
spread:
|
|
589
|
-
color:
|
|
590
|
-
shimmerColor:
|
|
591
|
-
direction:
|
|
571
|
+
spread: i = 2,
|
|
572
|
+
color: m = "#999",
|
|
573
|
+
shimmerColor: s = "#000",
|
|
574
|
+
direction: d = "fromBottom"
|
|
592
575
|
}) {
|
|
593
|
-
const
|
|
576
|
+
const f = P(null), y = Q(f, { once: l, margin: o }), S = L(() => e.length * i, [e, i]), b = !c || y, h = d === "fromBottom" ? "100% center" : "-100% center", k = d === "fromBottom" ? "0% center" : "200% center";
|
|
594
577
|
return /* @__PURE__ */ g(
|
|
595
|
-
|
|
578
|
+
A.span,
|
|
596
579
|
{
|
|
597
|
-
ref:
|
|
598
|
-
className:
|
|
580
|
+
ref: f,
|
|
581
|
+
className: u,
|
|
599
582
|
style: {
|
|
600
583
|
position: "relative",
|
|
601
584
|
display: "inline-block",
|
|
@@ -605,31 +588,31 @@ function M({
|
|
|
605
588
|
color: "transparent",
|
|
606
589
|
WebkitTextFillColor: "transparent",
|
|
607
590
|
backgroundRepeat: "no-repeat, padding-box",
|
|
608
|
-
"--spread": `${
|
|
609
|
-
"--base-color":
|
|
610
|
-
"--shimmer-color":
|
|
591
|
+
"--spread": `${S}px`,
|
|
592
|
+
"--base-color": m,
|
|
593
|
+
"--shimmer-color": s,
|
|
611
594
|
"--shimmer-bg": "linear-gradient(90deg, transparent calc(50% - var(--spread)), var(--shimmer-color), transparent calc(50% + var(--spread)))",
|
|
612
595
|
backgroundImage: "var(--shimmer-bg), linear-gradient(var(--base-color), var(--base-color))"
|
|
613
596
|
},
|
|
614
597
|
initial: {
|
|
615
|
-
backgroundPosition:
|
|
598
|
+
backgroundPosition: h,
|
|
616
599
|
opacity: 0
|
|
617
600
|
},
|
|
618
|
-
animate:
|
|
601
|
+
animate: b ? {
|
|
619
602
|
backgroundPosition: k,
|
|
620
603
|
opacity: 1
|
|
621
604
|
} : {},
|
|
622
605
|
transition: {
|
|
623
606
|
backgroundPosition: {
|
|
624
|
-
repeat:
|
|
607
|
+
repeat: n ? 1 / 0 : 0,
|
|
625
608
|
duration: t,
|
|
626
|
-
delay:
|
|
609
|
+
delay: r,
|
|
627
610
|
repeatDelay: a,
|
|
628
611
|
ease: "linear"
|
|
629
612
|
},
|
|
630
613
|
opacity: {
|
|
631
614
|
duration: 0.3,
|
|
632
|
-
delay:
|
|
615
|
+
delay: r
|
|
633
616
|
}
|
|
634
617
|
},
|
|
635
618
|
children: e
|
|
@@ -638,25 +621,34 @@ function M({
|
|
|
638
621
|
}
|
|
639
622
|
function me(e) {
|
|
640
623
|
const t = e.item.data;
|
|
641
|
-
|
|
624
|
+
switch (t.type) {
|
|
625
|
+
case "GenericAgentTaskExecution":
|
|
626
|
+
return t.title;
|
|
627
|
+
case "GenericAgentTaskReasoning":
|
|
628
|
+
return t.title;
|
|
629
|
+
case "GenericAgentTaskFinalResponse":
|
|
630
|
+
return "Generating answer...";
|
|
631
|
+
case "StreamingChatCompletionResponse":
|
|
632
|
+
return "Streaming...";
|
|
633
|
+
}
|
|
642
634
|
}
|
|
643
635
|
const ge = ({
|
|
644
636
|
progressViewItems: e
|
|
645
637
|
}) => {
|
|
646
638
|
const t = e[e.length - 1];
|
|
647
639
|
if (!t) return null;
|
|
648
|
-
const
|
|
649
|
-
return /* @__PURE__ */ g("div", { className: "simple-mode-container", children: /* @__PURE__ */ g(
|
|
650
|
-
|
|
640
|
+
const r = me(t);
|
|
641
|
+
return /* @__PURE__ */ g("div", { className: "simple-mode-container", children: /* @__PURE__ */ g(W, { mode: "wait", children: /* @__PURE__ */ g(
|
|
642
|
+
A.div,
|
|
651
643
|
{
|
|
652
644
|
initial: { opacity: 0, y: 10 },
|
|
653
645
|
animate: { opacity: 1, y: 0 },
|
|
654
646
|
exit: { opacity: 0, y: -10 },
|
|
655
647
|
transition: { duration: 0.3 },
|
|
656
|
-
children: t.completed ? /* @__PURE__ */ g("div", { className: "simple-mode-title", style: { color: "#666" }, children:
|
|
657
|
-
|
|
648
|
+
children: t.completed ? /* @__PURE__ */ g("div", { className: "simple-mode-title", style: { color: "#666" }, children: r }) : /* @__PURE__ */ g(
|
|
649
|
+
_,
|
|
658
650
|
{
|
|
659
|
-
text:
|
|
651
|
+
text: r,
|
|
660
652
|
className: "simple-mode-title",
|
|
661
653
|
duration: 2.5,
|
|
662
654
|
repeat: !0,
|
|
@@ -670,10 +662,10 @@ const ge = ({
|
|
|
670
662
|
}, fe = ({
|
|
671
663
|
data: e,
|
|
672
664
|
isLatest: t = !1,
|
|
673
|
-
durationSeconds:
|
|
674
|
-
}) => /* @__PURE__ */
|
|
665
|
+
durationSeconds: r
|
|
666
|
+
}) => /* @__PURE__ */ E("div", { style: { padding: "16px" }, children: [
|
|
675
667
|
/* @__PURE__ */ g(
|
|
676
|
-
|
|
668
|
+
A.div,
|
|
677
669
|
{
|
|
678
670
|
style: {
|
|
679
671
|
display: "flex",
|
|
@@ -684,8 +676,8 @@ const ge = ({
|
|
|
684
676
|
initial: { opacity: 0, y: -10 },
|
|
685
677
|
animate: { opacity: 1, y: 0 },
|
|
686
678
|
transition: { duration: 0.3, delay: 0 },
|
|
687
|
-
children: t && !
|
|
688
|
-
|
|
679
|
+
children: t && !r ? /* @__PURE__ */ g(
|
|
680
|
+
_,
|
|
689
681
|
{
|
|
690
682
|
text: e.title,
|
|
691
683
|
duration: 2.5,
|
|
@@ -696,7 +688,7 @@ const ge = ({
|
|
|
696
688
|
) : /* @__PURE__ */ g("span", { style: { color: "#666" }, children: e.title })
|
|
697
689
|
}
|
|
698
690
|
),
|
|
699
|
-
|
|
691
|
+
r !== void 0 && /* @__PURE__ */ E(
|
|
700
692
|
"div",
|
|
701
693
|
{
|
|
702
694
|
style: {
|
|
@@ -707,12 +699,12 @@ const ge = ({
|
|
|
707
699
|
},
|
|
708
700
|
children: [
|
|
709
701
|
"Took ",
|
|
710
|
-
|
|
702
|
+
r,
|
|
711
703
|
" seconds"
|
|
712
704
|
]
|
|
713
705
|
}
|
|
714
706
|
)
|
|
715
|
-
] }),
|
|
707
|
+
] }), z = {
|
|
716
708
|
'code[class*="language-"]': {
|
|
717
709
|
color: "#f8f8f2",
|
|
718
710
|
background: "none",
|
|
@@ -866,67 +858,67 @@ const ge = ({
|
|
|
866
858
|
}, ye = ({
|
|
867
859
|
data: e,
|
|
868
860
|
streamToken: t,
|
|
869
|
-
fetchClientToken:
|
|
870
|
-
durationSeconds:
|
|
861
|
+
fetchClientToken: r,
|
|
862
|
+
durationSeconds: n
|
|
871
863
|
}) => {
|
|
872
|
-
const { fency: a } =
|
|
873
|
-
async (
|
|
864
|
+
const { fency: a } = F(), u = U(
|
|
865
|
+
async (c) => {
|
|
874
866
|
try {
|
|
875
|
-
const { clientToken:
|
|
867
|
+
const { clientToken: l } = await r(), o = await V({
|
|
876
868
|
pk: a.publishableKey,
|
|
877
869
|
baseUrl: a.baseUrl,
|
|
878
|
-
clientToken:
|
|
870
|
+
clientToken: l,
|
|
879
871
|
streamToken: t,
|
|
880
|
-
request: { fileId:
|
|
872
|
+
request: { fileId: c }
|
|
881
873
|
});
|
|
882
874
|
o.type === "success" && window.open(o.downloadLink, "_blank");
|
|
883
|
-
} catch (
|
|
884
|
-
console.error("Failed to download file:",
|
|
875
|
+
} catch (l) {
|
|
876
|
+
console.error("Failed to download file:", l);
|
|
885
877
|
}
|
|
886
878
|
},
|
|
887
|
-
[a, t,
|
|
879
|
+
[a, t, r]
|
|
888
880
|
);
|
|
889
|
-
return /* @__PURE__ */
|
|
881
|
+
return /* @__PURE__ */ E("div", { style: { padding: "16px" }, children: [
|
|
890
882
|
/* @__PURE__ */ g(
|
|
891
|
-
|
|
883
|
+
A.div,
|
|
892
884
|
{
|
|
893
885
|
className: "fency-markdown-body-raw",
|
|
894
886
|
initial: { opacity: 0, y: -10 },
|
|
895
887
|
animate: { opacity: 1, y: 0 },
|
|
896
888
|
transition: { duration: 0.3, delay: 0 },
|
|
897
889
|
children: /* @__PURE__ */ g(
|
|
898
|
-
|
|
890
|
+
D,
|
|
899
891
|
{
|
|
900
|
-
remarkPlugins: [
|
|
892
|
+
remarkPlugins: [B],
|
|
901
893
|
components: {
|
|
902
|
-
code(
|
|
903
|
-
const { children:
|
|
904
|
-
return
|
|
905
|
-
|
|
894
|
+
code(c) {
|
|
895
|
+
const { children: l, className: o, node: i, ref: m, ...s } = c, d = /language-(\w+)/.exec(o || "");
|
|
896
|
+
return d ? /* @__PURE__ */ g(
|
|
897
|
+
M,
|
|
906
898
|
{
|
|
907
|
-
...
|
|
899
|
+
...s,
|
|
908
900
|
PreTag: "div",
|
|
909
|
-
children: String(
|
|
910
|
-
language:
|
|
911
|
-
style:
|
|
901
|
+
children: String(l).replace(/\n$/, ""),
|
|
902
|
+
language: d[1],
|
|
903
|
+
style: z
|
|
912
904
|
}
|
|
913
|
-
) : /* @__PURE__ */ g("code", { ...
|
|
905
|
+
) : /* @__PURE__ */ g("code", { ...s, className: o, children: String(l) });
|
|
914
906
|
},
|
|
915
|
-
a(
|
|
916
|
-
const { children:
|
|
907
|
+
a(c) {
|
|
908
|
+
const { children: l, href: o, ...i } = c;
|
|
917
909
|
return /* @__PURE__ */ g(
|
|
918
910
|
"a",
|
|
919
911
|
{
|
|
920
|
-
...
|
|
912
|
+
...i,
|
|
921
913
|
href: o,
|
|
922
|
-
onClick: (
|
|
914
|
+
onClick: (m) => {
|
|
923
915
|
if (!o) return;
|
|
924
|
-
const
|
|
916
|
+
const s = o.match(
|
|
925
917
|
/\/files\/(fil_[a-zA-Z0-9]+)\/download/
|
|
926
918
|
);
|
|
927
|
-
|
|
919
|
+
s && (m.preventDefault(), u(s[1]));
|
|
928
920
|
},
|
|
929
|
-
children:
|
|
921
|
+
children: l
|
|
930
922
|
}
|
|
931
923
|
);
|
|
932
924
|
}
|
|
@@ -936,7 +928,7 @@ const ge = ({
|
|
|
936
928
|
)
|
|
937
929
|
}
|
|
938
930
|
),
|
|
939
|
-
|
|
931
|
+
n !== void 0 && /* @__PURE__ */ E(
|
|
940
932
|
"div",
|
|
941
933
|
{
|
|
942
934
|
style: {
|
|
@@ -947,7 +939,7 @@ const ge = ({
|
|
|
947
939
|
},
|
|
948
940
|
children: [
|
|
949
941
|
"Thought for ",
|
|
950
|
-
|
|
942
|
+
n,
|
|
951
943
|
" seconds"
|
|
952
944
|
]
|
|
953
945
|
}
|
|
@@ -956,22 +948,22 @@ const ge = ({
|
|
|
956
948
|
}, he = ({
|
|
957
949
|
data: e,
|
|
958
950
|
completed: t,
|
|
959
|
-
isLatest:
|
|
960
|
-
durationSeconds:
|
|
951
|
+
isLatest: r = !1,
|
|
952
|
+
durationSeconds: n
|
|
961
953
|
}) => {
|
|
962
954
|
const a = P(null);
|
|
963
|
-
return
|
|
955
|
+
return T(() => {
|
|
964
956
|
a.current && !t && (a.current.scrollTop = a.current.scrollHeight);
|
|
965
|
-
}, [e.reasoning, t]), /* @__PURE__ */
|
|
957
|
+
}, [e.reasoning, t]), /* @__PURE__ */ E("div", { style: { padding: "16px" }, children: [
|
|
966
958
|
/* @__PURE__ */ g(
|
|
967
|
-
|
|
959
|
+
A.h3,
|
|
968
960
|
{
|
|
969
961
|
style: { marginBottom: "10px", color: "#666" },
|
|
970
962
|
initial: { opacity: 0, y: -10 },
|
|
971
963
|
animate: { opacity: 1, y: 0 },
|
|
972
964
|
transition: { duration: 0.3, delay: 0 },
|
|
973
|
-
children:
|
|
974
|
-
|
|
965
|
+
children: r && !n ? /* @__PURE__ */ g(
|
|
966
|
+
_,
|
|
975
967
|
{
|
|
976
968
|
text: e.title,
|
|
977
969
|
duration: 2.5,
|
|
@@ -983,7 +975,7 @@ const ge = ({
|
|
|
983
975
|
}
|
|
984
976
|
),
|
|
985
977
|
/* @__PURE__ */ g(
|
|
986
|
-
|
|
978
|
+
A.div,
|
|
987
979
|
{
|
|
988
980
|
ref: a,
|
|
989
981
|
style: {
|
|
@@ -999,22 +991,22 @@ const ge = ({
|
|
|
999
991
|
animate: { opacity: 0.5, y: 0 },
|
|
1000
992
|
transition: { duration: 0.3, delay: 0.1 },
|
|
1001
993
|
children: /* @__PURE__ */ g("div", { className: "fency-markdown-body-raw", children: /* @__PURE__ */ g(
|
|
1002
|
-
|
|
994
|
+
D,
|
|
1003
995
|
{
|
|
1004
|
-
remarkPlugins: [
|
|
996
|
+
remarkPlugins: [B],
|
|
1005
997
|
components: {
|
|
1006
|
-
code(
|
|
1007
|
-
const { children:
|
|
1008
|
-
return
|
|
1009
|
-
|
|
998
|
+
code(u) {
|
|
999
|
+
const { children: c, className: l, node: o, ref: i, ...m } = u, s = /language-(\w+)/.exec(l || "");
|
|
1000
|
+
return s ? /* @__PURE__ */ g(
|
|
1001
|
+
M,
|
|
1010
1002
|
{
|
|
1011
|
-
...
|
|
1003
|
+
...m,
|
|
1012
1004
|
PreTag: "div",
|
|
1013
|
-
children: String(
|
|
1014
|
-
language:
|
|
1015
|
-
style:
|
|
1005
|
+
children: String(c).replace(/\n$/, ""),
|
|
1006
|
+
language: s[1],
|
|
1007
|
+
style: z
|
|
1016
1008
|
}
|
|
1017
|
-
) : /* @__PURE__ */ g("code", { ...
|
|
1009
|
+
) : /* @__PURE__ */ g("code", { ...m, className: l, children: String(c) });
|
|
1018
1010
|
}
|
|
1019
1011
|
},
|
|
1020
1012
|
children: e.reasoning
|
|
@@ -1022,7 +1014,7 @@ const ge = ({
|
|
|
1022
1014
|
) })
|
|
1023
1015
|
}
|
|
1024
1016
|
),
|
|
1025
|
-
|
|
1017
|
+
n !== void 0 && /* @__PURE__ */ E(
|
|
1026
1018
|
"div",
|
|
1027
1019
|
{
|
|
1028
1020
|
style: {
|
|
@@ -1033,90 +1025,127 @@ const ge = ({
|
|
|
1033
1025
|
},
|
|
1034
1026
|
children: [
|
|
1035
1027
|
"Thought for ",
|
|
1036
|
-
|
|
1028
|
+
n,
|
|
1037
1029
|
" seconds"
|
|
1038
1030
|
]
|
|
1039
1031
|
}
|
|
1040
1032
|
)
|
|
1041
1033
|
] });
|
|
1042
1034
|
}, be = ({
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1035
|
+
data: e
|
|
1036
|
+
}) => /* @__PURE__ */ g("div", { style: { padding: "16px" }, children: /* @__PURE__ */ g(
|
|
1037
|
+
A.div,
|
|
1038
|
+
{
|
|
1039
|
+
className: "fency-markdown-body-raw",
|
|
1040
|
+
initial: { opacity: 0, y: -10 },
|
|
1041
|
+
animate: { opacity: 1, y: 0 },
|
|
1042
|
+
transition: { duration: 0.3, delay: 0 },
|
|
1043
|
+
children: /* @__PURE__ */ g(
|
|
1044
|
+
D,
|
|
1045
|
+
{
|
|
1046
|
+
remarkPlugins: [B],
|
|
1047
|
+
components: {
|
|
1048
|
+
code(t) {
|
|
1049
|
+
const { children: r, className: n, node: a, ref: u, ...c } = t, l = /language-(\w+)/.exec(n || "");
|
|
1050
|
+
return l ? /* @__PURE__ */ g(
|
|
1051
|
+
M,
|
|
1052
|
+
{
|
|
1053
|
+
...c,
|
|
1054
|
+
PreTag: "div",
|
|
1055
|
+
children: String(r).replace(/\n$/, ""),
|
|
1056
|
+
language: l[1],
|
|
1057
|
+
style: z
|
|
1058
|
+
}
|
|
1059
|
+
) : /* @__PURE__ */ g("code", { ...c, className: n, children: String(r) });
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1062
|
+
children: e.response
|
|
1063
|
+
}
|
|
1064
|
+
)
|
|
1065
|
+
}
|
|
1066
|
+
) }), ke = ({ progressViewItems: e, streamToken: t, fetchClientToken: r }) => {
|
|
1067
|
+
const n = P(null);
|
|
1068
|
+
T(() => {
|
|
1069
|
+
n.current && (n.current.scrollTop = n.current.scrollHeight);
|
|
1070
|
+
}, [e.length]);
|
|
1071
|
+
const a = (u) => {
|
|
1072
|
+
switch (u.item.data.type) {
|
|
1073
|
+
case "GenericAgentTaskExecution":
|
|
1074
|
+
return /* @__PURE__ */ g(
|
|
1075
|
+
fe,
|
|
1076
|
+
{
|
|
1077
|
+
data: u.item.data,
|
|
1078
|
+
completed: u.completed,
|
|
1079
|
+
isLatest: u.isLatest,
|
|
1080
|
+
durationSeconds: u.durationSeconds
|
|
1081
|
+
}
|
|
1082
|
+
);
|
|
1083
|
+
case "GenericAgentTaskReasoning":
|
|
1084
|
+
return /* @__PURE__ */ g(
|
|
1085
|
+
he,
|
|
1086
|
+
{
|
|
1087
|
+
data: u.item.data,
|
|
1088
|
+
completed: u.completed,
|
|
1089
|
+
isLatest: u.isLatest,
|
|
1090
|
+
durationSeconds: u.durationSeconds
|
|
1091
|
+
}
|
|
1092
|
+
);
|
|
1093
|
+
case "GenericAgentTaskFinalResponse":
|
|
1094
|
+
return /* @__PURE__ */ g(
|
|
1095
|
+
ye,
|
|
1096
|
+
{
|
|
1097
|
+
data: u.item.data,
|
|
1098
|
+
streamToken: t,
|
|
1099
|
+
fetchClientToken: r,
|
|
1100
|
+
durationSeconds: u.durationSeconds
|
|
1101
|
+
}
|
|
1102
|
+
);
|
|
1103
|
+
case "StreamingChatCompletionResponse":
|
|
1104
|
+
return /* @__PURE__ */ g(be, { data: u.item.data });
|
|
1105
|
+
}
|
|
1106
|
+
};
|
|
1107
|
+
return /* @__PURE__ */ g(
|
|
1051
1108
|
"div",
|
|
1052
1109
|
{
|
|
1053
|
-
ref:
|
|
1110
|
+
ref: n,
|
|
1054
1111
|
style: {
|
|
1055
1112
|
flex: 1,
|
|
1056
1113
|
overflowY: "auto",
|
|
1057
1114
|
minHeight: 0
|
|
1058
1115
|
},
|
|
1059
|
-
children: /* @__PURE__ */ g(
|
|
1060
|
-
|
|
1116
|
+
children: /* @__PURE__ */ g(W, { children: e.map((u, c) => /* @__PURE__ */ g(
|
|
1117
|
+
A.div,
|
|
1061
1118
|
{
|
|
1062
1119
|
initial: { opacity: 0, y: -20 },
|
|
1063
1120
|
animate: { opacity: 1, y: 0 },
|
|
1064
1121
|
transition: {
|
|
1065
1122
|
duration: 0.4,
|
|
1066
|
-
delay:
|
|
1123
|
+
delay: c * 0.1,
|
|
1067
1124
|
ease: "easeOut"
|
|
1068
1125
|
},
|
|
1069
|
-
children:
|
|
1070
|
-
a.data.type === "GenericAgentTaskExecution" && /* @__PURE__ */ g(
|
|
1071
|
-
fe,
|
|
1072
|
-
{
|
|
1073
|
-
data: a.data,
|
|
1074
|
-
completed: f,
|
|
1075
|
-
isLatest: s,
|
|
1076
|
-
durationSeconds: d
|
|
1077
|
-
}
|
|
1078
|
-
),
|
|
1079
|
-
a.data.type === "GenericAgentTaskReasoning" && /* @__PURE__ */ g(
|
|
1080
|
-
he,
|
|
1081
|
-
{
|
|
1082
|
-
data: a.data,
|
|
1083
|
-
completed: f,
|
|
1084
|
-
isLatest: s,
|
|
1085
|
-
durationSeconds: d
|
|
1086
|
-
}
|
|
1087
|
-
),
|
|
1088
|
-
a.data.type === "GenericAgentTaskFinalResponse" && /* @__PURE__ */ g(
|
|
1089
|
-
ye,
|
|
1090
|
-
{
|
|
1091
|
-
data: a.data,
|
|
1092
|
-
streamToken: t,
|
|
1093
|
-
fetchClientToken: n,
|
|
1094
|
-
durationSeconds: d
|
|
1095
|
-
}
|
|
1096
|
-
)
|
|
1097
|
-
]
|
|
1126
|
+
children: a(u)
|
|
1098
1127
|
},
|
|
1099
|
-
|
|
1128
|
+
u.item.progressItemId
|
|
1100
1129
|
)) })
|
|
1101
1130
|
}
|
|
1102
1131
|
);
|
|
1103
|
-
},
|
|
1132
|
+
}, Oe = ({
|
|
1104
1133
|
agentTask: e,
|
|
1105
1134
|
mode: t = "verbose",
|
|
1106
|
-
streamToken:
|
|
1107
|
-
fetchClientToken:
|
|
1135
|
+
streamToken: r,
|
|
1136
|
+
fetchClientToken: n
|
|
1108
1137
|
}) => {
|
|
1109
1138
|
const a = ue(e);
|
|
1110
1139
|
return t === "simple" ? /* @__PURE__ */ g(ge, { progressViewItems: a }) : /* @__PURE__ */ g(
|
|
1111
|
-
|
|
1140
|
+
ke,
|
|
1112
1141
|
{
|
|
1113
1142
|
progressViewItems: a,
|
|
1114
|
-
streamToken:
|
|
1115
|
-
fetchClientToken:
|
|
1143
|
+
streamToken: r,
|
|
1144
|
+
fetchClientToken: n
|
|
1116
1145
|
}
|
|
1117
1146
|
);
|
|
1118
1147
|
};
|
|
1119
|
-
class
|
|
1148
|
+
class Se {
|
|
1120
1149
|
constructor(t) {
|
|
1121
1150
|
this.eventSources = /* @__PURE__ */ new Map(), this.subscribers = /* @__PURE__ */ new Map(), this.fency = t;
|
|
1122
1151
|
}
|
|
@@ -1125,37 +1154,37 @@ class ke {
|
|
|
1125
1154
|
* Creates new connections and removes old ones.
|
|
1126
1155
|
*/
|
|
1127
1156
|
updateStreams(t) {
|
|
1128
|
-
t.forEach((
|
|
1129
|
-
const a =
|
|
1130
|
-
this.eventSources.has(a) || this.connectStream(
|
|
1157
|
+
t.forEach((n) => {
|
|
1158
|
+
const a = n.stream.id;
|
|
1159
|
+
this.eventSources.has(a) || this.connectStream(n);
|
|
1131
1160
|
});
|
|
1132
|
-
const
|
|
1133
|
-
this.eventSources.forEach((
|
|
1134
|
-
|
|
1161
|
+
const r = new Set(t.map((n) => n.stream.id));
|
|
1162
|
+
this.eventSources.forEach((n, a) => {
|
|
1163
|
+
r.has(a) || (n.abort(), this.eventSources.delete(a));
|
|
1135
1164
|
});
|
|
1136
1165
|
}
|
|
1137
1166
|
connectStream(t) {
|
|
1138
|
-
const
|
|
1139
|
-
this.eventSources.set(
|
|
1140
|
-
const a = `${this.fency.baseUrl}/sse/streams/${
|
|
1167
|
+
const r = t.stream.id, n = new AbortController();
|
|
1168
|
+
this.eventSources.set(r, n);
|
|
1169
|
+
const a = `${this.fency.baseUrl}/sse/streams/${r}`, u = {
|
|
1141
1170
|
"X-Fency-Publishable-Key": this.fency.publishableKey,
|
|
1142
1171
|
"X-Fency-Stream-Token": t.stream.token
|
|
1143
1172
|
};
|
|
1144
|
-
|
|
1145
|
-
headers:
|
|
1146
|
-
signal:
|
|
1147
|
-
async onopen(
|
|
1148
|
-
if (!
|
|
1149
|
-
throw new Error(`Client error ${
|
|
1173
|
+
$(a, {
|
|
1174
|
+
headers: u,
|
|
1175
|
+
signal: n.signal,
|
|
1176
|
+
async onopen(c) {
|
|
1177
|
+
if (!c.ok && c.status >= 400 && c.status < 500 && c.status !== 429)
|
|
1178
|
+
throw new Error(`Client error ${c.status}`);
|
|
1150
1179
|
},
|
|
1151
|
-
onmessage: (
|
|
1152
|
-
if (
|
|
1153
|
-
const
|
|
1154
|
-
this.broadcast(
|
|
1180
|
+
onmessage: (c) => {
|
|
1181
|
+
if (c.data) {
|
|
1182
|
+
const l = K(c.data);
|
|
1183
|
+
this.broadcast(l, r);
|
|
1155
1184
|
}
|
|
1156
1185
|
},
|
|
1157
|
-
onerror: (
|
|
1158
|
-
throw console.error("EventSource error for stream",
|
|
1186
|
+
onerror: (c) => {
|
|
1187
|
+
throw console.error("EventSource error for stream", r, ":", c), this.broadcastError(r), c;
|
|
1159
1188
|
},
|
|
1160
1189
|
onclose() {
|
|
1161
1190
|
}
|
|
@@ -1165,19 +1194,19 @@ class ke {
|
|
|
1165
1194
|
* Subscribe to events from all active streams.
|
|
1166
1195
|
* Returns an unsubscribe function.
|
|
1167
1196
|
*/
|
|
1168
|
-
subscribe(t,
|
|
1169
|
-
return this.subscribers.set(t,
|
|
1197
|
+
subscribe(t, r) {
|
|
1198
|
+
return this.subscribers.set(t, r), () => {
|
|
1170
1199
|
this.subscribers.delete(t);
|
|
1171
1200
|
};
|
|
1172
1201
|
}
|
|
1173
|
-
broadcast(t,
|
|
1174
|
-
this.subscribers.forEach((
|
|
1175
|
-
|
|
1202
|
+
broadcast(t, r) {
|
|
1203
|
+
this.subscribers.forEach((n) => {
|
|
1204
|
+
n.onMessage(t, r);
|
|
1176
1205
|
});
|
|
1177
1206
|
}
|
|
1178
1207
|
broadcastError(t) {
|
|
1179
|
-
this.subscribers.forEach((
|
|
1180
|
-
|
|
1208
|
+
this.subscribers.forEach((r) => {
|
|
1209
|
+
r.onError(t);
|
|
1181
1210
|
});
|
|
1182
1211
|
}
|
|
1183
1212
|
/**
|
|
@@ -1187,89 +1216,90 @@ class ke {
|
|
|
1187
1216
|
this.eventSources.forEach((t) => t.abort()), this.eventSources.clear(), this.subscribers.clear();
|
|
1188
1217
|
}
|
|
1189
1218
|
}
|
|
1190
|
-
const
|
|
1219
|
+
const ve = 12e4, we = (e) => {
|
|
1191
1220
|
const t = Date.now();
|
|
1192
|
-
return e.filter((
|
|
1221
|
+
return e.filter((r) => t - r.createdAt < ve);
|
|
1193
1222
|
};
|
|
1194
|
-
function
|
|
1195
|
-
const [n,
|
|
1223
|
+
function Ue({ fency: e, fetchCreateStreamClientToken: t, children: r }) {
|
|
1224
|
+
const [n, a] = w(
|
|
1196
1225
|
null
|
|
1197
|
-
), [
|
|
1198
|
-
|
|
1199
|
-
e.then((
|
|
1200
|
-
|
|
1201
|
-
}).catch((
|
|
1202
|
-
|
|
1226
|
+
), [u, c] = w(!0), [l, o] = w(null), [i, m] = w([]), s = P(null), d = P(null);
|
|
1227
|
+
T(() => {
|
|
1228
|
+
e.then((b) => {
|
|
1229
|
+
a(b), c(!1);
|
|
1230
|
+
}).catch((b) => {
|
|
1231
|
+
o(b), c(!1);
|
|
1203
1232
|
});
|
|
1204
|
-
}, [e]),
|
|
1205
|
-
n && !
|
|
1206
|
-
}, [n]),
|
|
1207
|
-
|
|
1208
|
-
}, [
|
|
1209
|
-
var
|
|
1210
|
-
(
|
|
1233
|
+
}, [e]), T(() => {
|
|
1234
|
+
n && !d.current && (d.current = new Se(n));
|
|
1235
|
+
}, [n]), T(() => {
|
|
1236
|
+
d.current && d.current.updateStreams(i);
|
|
1237
|
+
}, [i]), T(() => () => {
|
|
1238
|
+
var b;
|
|
1239
|
+
(b = d.current) == null || b.cleanup();
|
|
1211
1240
|
}, []);
|
|
1212
|
-
const
|
|
1213
|
-
async (
|
|
1214
|
-
if (
|
|
1215
|
-
return
|
|
1216
|
-
const
|
|
1217
|
-
if (k &&
|
|
1241
|
+
const f = U(
|
|
1242
|
+
async (b = 3e4) => {
|
|
1243
|
+
if (s.current)
|
|
1244
|
+
return s.current;
|
|
1245
|
+
const h = Date.now(), k = i.length > 0 ? i[i.length - 1] : null;
|
|
1246
|
+
if (k && h - k.createdAt < b)
|
|
1218
1247
|
return k.stream;
|
|
1219
|
-
const
|
|
1248
|
+
const I = (async () => {
|
|
1220
1249
|
if (!n)
|
|
1221
1250
|
throw new Error("Fency instance not initialized");
|
|
1222
|
-
const
|
|
1251
|
+
const C = await t(), x = await X({
|
|
1223
1252
|
pk: n.publishableKey,
|
|
1224
1253
|
baseUrl: n.baseUrl,
|
|
1225
|
-
clientToken: (
|
|
1254
|
+
clientToken: (C == null ? void 0 : C.clientToken) ?? ""
|
|
1226
1255
|
});
|
|
1227
1256
|
if (x.type === "success") {
|
|
1228
1257
|
const N = {
|
|
1229
1258
|
stream: x.stream,
|
|
1230
1259
|
createdAt: Date.now()
|
|
1231
1260
|
};
|
|
1232
|
-
return
|
|
1233
|
-
const
|
|
1234
|
-
return
|
|
1235
|
-
}),
|
|
1261
|
+
return m((R) => {
|
|
1262
|
+
const v = [...R, N];
|
|
1263
|
+
return we(v);
|
|
1264
|
+
}), s.current = null, x.stream;
|
|
1236
1265
|
} else
|
|
1237
|
-
throw
|
|
1266
|
+
throw s.current = null, new Error("Failed to create stream");
|
|
1238
1267
|
})();
|
|
1239
|
-
return
|
|
1268
|
+
return s.current = I, I;
|
|
1240
1269
|
},
|
|
1241
|
-
[n,
|
|
1270
|
+
[n, i]
|
|
1242
1271
|
);
|
|
1243
|
-
if (
|
|
1244
|
-
return /* @__PURE__ */
|
|
1272
|
+
if (l)
|
|
1273
|
+
return /* @__PURE__ */ E("div", { children: [
|
|
1245
1274
|
"Fency error: ",
|
|
1246
|
-
|
|
1275
|
+
l.message
|
|
1247
1276
|
] });
|
|
1248
1277
|
if (!n)
|
|
1249
1278
|
return null;
|
|
1250
|
-
const
|
|
1279
|
+
const y = i.length > 0 ? i[i.length - 1] : null, S = {
|
|
1251
1280
|
fency: n,
|
|
1252
|
-
loading:
|
|
1253
|
-
error:
|
|
1254
|
-
activeStreams:
|
|
1255
|
-
latestStream:
|
|
1256
|
-
eventManager:
|
|
1257
|
-
getOrCreateStream:
|
|
1281
|
+
loading: u,
|
|
1282
|
+
error: l,
|
|
1283
|
+
activeStreams: i,
|
|
1284
|
+
latestStream: y,
|
|
1285
|
+
eventManager: d.current,
|
|
1286
|
+
getOrCreateStream: f
|
|
1258
1287
|
};
|
|
1259
|
-
return /* @__PURE__ */ g(j.Provider, { value:
|
|
1288
|
+
return /* @__PURE__ */ g(j.Provider, { value: S, children: r });
|
|
1260
1289
|
}
|
|
1261
1290
|
export {
|
|
1262
|
-
|
|
1291
|
+
Oe as AgentTaskProgress,
|
|
1263
1292
|
ge as AgentTaskProgressSimple,
|
|
1264
|
-
|
|
1265
|
-
|
|
1293
|
+
ke as AgentTaskProgressVerbose,
|
|
1294
|
+
Ue as FencyProvider,
|
|
1266
1295
|
fe as GenericAgentTaskExecution,
|
|
1267
1296
|
ye as GenericAgentTaskFinalResponse,
|
|
1268
1297
|
he as GenericAgentTaskReasoning,
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
Ne as
|
|
1298
|
+
_ as ShimmeringText,
|
|
1299
|
+
be as StreamingChatCompletionResponse,
|
|
1300
|
+
Re as useAgentTasks,
|
|
1301
|
+
F as useFencyContext,
|
|
1302
|
+
Ne as useFencyEventSource,
|
|
1303
|
+
Fe as usePaginatedQuery,
|
|
1274
1304
|
re as useStream
|
|
1275
1305
|
};
|