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