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