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