@fencyai/react 0.1.122 → 0.1.124
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/AgentTaskProgress.d.ts +1 -0
- package/dist/agent-task/AgentTaskProgress.d.ts.map +1 -0
- package/dist/agent-task/AgentTaskProgressSimple.d.ts +1 -0
- package/dist/agent-task/AgentTaskProgressSimple.d.ts.map +1 -0
- package/dist/agent-task/AgentTaskProgressVerbose.d.ts +1 -0
- package/dist/agent-task/AgentTaskProgressVerbose.d.ts.map +1 -0
- package/dist/agent-task/ProgressViewItem.d.ts +1 -0
- package/dist/agent-task/ProgressViewItem.d.ts.map +1 -0
- package/dist/agent-task/ShimmeringText.d.ts +1 -0
- package/dist/agent-task/ShimmeringText.d.ts.map +1 -0
- package/dist/agent-task/data-types/StreamingChatCompletionText.d.ts +1 -0
- package/dist/agent-task/data-types/StreamingChatCompletionText.d.ts.map +1 -0
- package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionExploreMemory.d.ts +1 -0
- package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionExploreMemory.d.ts.map +1 -0
- package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionFindSources.d.ts +1 -0
- package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionFindSources.d.ts.map +1 -0
- package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionSearch.d.ts +1 -0
- package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionSearch.d.ts.map +1 -0
- package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionSourcesResult.d.ts +1 -0
- package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionSourcesResult.d.ts.map +1 -0
- package/dist/agent-task/data-types/StructuredChatCompletionJson.d.ts +1 -0
- package/dist/agent-task/data-types/StructuredChatCompletionJson.d.ts.map +1 -0
- package/dist/agent-task/hooks/useContentEditable.d.ts +1 -0
- package/dist/agent-task/hooks/useContentEditable.d.ts.map +1 -0
- package/dist/agent-task/hooks/useMentionParser.d.ts +1 -0
- package/dist/agent-task/hooks/useMentionParser.d.ts.map +1 -0
- package/dist/agent-task/hooks/useMentionRenderer.d.ts +1 -0
- package/dist/agent-task/hooks/useMentionRenderer.d.ts.map +1 -0
- package/dist/agent-task/hooks/useMentionState.d.ts +1 -0
- package/dist/agent-task/hooks/useMentionState.d.ts.map +1 -0
- package/dist/hooks/useAgentTasks/index.d.ts +1 -0
- package/dist/hooks/useAgentTasks/index.d.ts.map +1 -0
- package/dist/{provider/useFencyContext.d.ts → hooks/useFencyContext/index.d.ts} +2 -1
- package/dist/hooks/useFencyContext/index.d.ts.map +1 -0
- package/dist/hooks/useFencyEventSource/index.d.ts +1 -0
- package/dist/hooks/useFencyEventSource/index.d.ts.map +1 -0
- package/dist/hooks/useStream/index.d.ts +1 -0
- package/dist/hooks/useStream/index.d.ts.map +1 -0
- package/dist/hooks/useStream/toStreamData.d.ts +1 -0
- package/dist/hooks/useStream/toStreamData.d.ts.map +1 -0
- package/dist/index.d.ts +2 -14
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +514 -674
- package/dist/provider/FencyContextValue.d.ts +1 -0
- package/dist/provider/FencyContextValue.d.ts.map +1 -0
- package/dist/provider/FencyProvider.d.ts +1 -0
- package/dist/provider/FencyProvider.d.ts.map +1 -0
- package/dist/provider/StreamEventManager.d.ts +1 -0
- package/dist/provider/StreamEventManager.d.ts.map +1 -0
- package/dist/types/AgentTask.d.ts +1 -0
- package/dist/types/AgentTask.d.ts.map +1 -0
- package/dist/types/AgentTaskData.d.ts +1 -0
- package/dist/types/AgentTaskData.d.ts.map +1 -0
- package/dist/types/CreateAgentTaskParams.d.ts +1 -0
- package/dist/types/CreateAgentTaskParams.d.ts.map +1 -0
- package/dist/types/CreateAgentTaskResponse.d.ts +1 -0
- package/dist/types/CreateAgentTaskResponse.d.ts.map +1 -0
- package/dist/types/CreateStreamResponse.d.ts +1 -0
- package/dist/types/CreateStreamResponse.d.ts.map +1 -0
- package/dist/types/FencyContext.d.ts +1 -0
- package/dist/types/FencyContext.d.ts.map +1 -0
- package/dist/types/FencyProviderProps.d.ts +1 -0
- package/dist/types/FencyProviderProps.d.ts.map +1 -0
- package/dist/types/StreamData.d.ts +1 -0
- package/dist/types/StreamData.d.ts.map +1 -0
- package/dist/types/StreamError.d.ts +1 -0
- package/dist/types/StreamError.d.ts.map +1 -0
- package/dist/types/UseAgentTasks.d.ts +1 -0
- package/dist/types/UseAgentTasks.d.ts.map +1 -0
- package/dist/types/UseAgentTasksProps.d.ts +1 -0
- package/dist/types/UseAgentTasksProps.d.ts.map +1 -0
- package/dist/types/UseStream.d.ts +1 -0
- package/dist/types/UseStream.d.ts.map +1 -0
- package/dist/types/UseStreamProps.d.ts +1 -0
- package/dist/types/UseStreamProps.d.ts.map +1 -0
- package/dist/types/index.d.ts +9 -7
- package/dist/types/index.d.ts.map +1 -0
- package/package.json +7 -5
- package/dist/hooks/usePaginatedQuery/index.d.ts +0 -56
package/dist/index.js
CHANGED
|
@@ -1,47 +1,310 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { useInView as
|
|
5
|
-
import
|
|
1
|
+
import { jsxs as k, jsx as i } from "react/jsx-runtime";
|
|
2
|
+
import { createStream as K, isStreamTimeoutEvent as _, isStreamNotFoundEvent as J, isAgentTaskProgressItemUpdatedEvent as V, createAgentTask as q } from "@fencyai/js";
|
|
3
|
+
import { createContext as G, useState as w, useRef as A, useEffect as E, useCallback as W, useContext as X, useMemo as U } from "react";
|
|
4
|
+
import { useInView as Q, motion as v, AnimatePresence as L } from "motion/react";
|
|
5
|
+
import Y from "react-markdown";
|
|
6
6
|
import { Prism as $ } from "react-syntax-highlighter";
|
|
7
|
-
import
|
|
8
|
-
import './assets/index.css';const
|
|
7
|
+
import Z from "remark-gfm";
|
|
8
|
+
import './assets/index.css';const N = G(
|
|
9
9
|
void 0
|
|
10
10
|
);
|
|
11
|
-
function
|
|
12
|
-
const
|
|
11
|
+
async function ee(e, t) {
|
|
12
|
+
const r = e.getReader();
|
|
13
|
+
let n;
|
|
14
|
+
for (; !(n = await r.read()).done; )
|
|
15
|
+
t(n.value);
|
|
16
|
+
}
|
|
17
|
+
function te(e) {
|
|
18
|
+
let t, r, n, l = !1;
|
|
19
|
+
return function(s) {
|
|
20
|
+
t === void 0 ? (t = s, r = 0, n = -1) : t = re(t, s);
|
|
21
|
+
const c = t.length;
|
|
22
|
+
let d = 0;
|
|
23
|
+
for (; r < c; ) {
|
|
24
|
+
l && (t[r] === 10 && (d = ++r), l = !1);
|
|
25
|
+
let a = -1;
|
|
26
|
+
for (; r < c && a === -1; ++r)
|
|
27
|
+
switch (t[r]) {
|
|
28
|
+
case 58:
|
|
29
|
+
n === -1 && (n = r - d);
|
|
30
|
+
break;
|
|
31
|
+
case 13:
|
|
32
|
+
l = !0;
|
|
33
|
+
case 10:
|
|
34
|
+
a = r;
|
|
35
|
+
break;
|
|
36
|
+
}
|
|
37
|
+
if (a === -1)
|
|
38
|
+
break;
|
|
39
|
+
e(t.subarray(d, a), n), d = r, n = -1;
|
|
40
|
+
}
|
|
41
|
+
d === c ? t = void 0 : d !== 0 && (t = t.subarray(d), r -= d);
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function ne(e, t, r) {
|
|
45
|
+
let n = P();
|
|
46
|
+
const l = new TextDecoder();
|
|
47
|
+
return function(s, c) {
|
|
48
|
+
if (s.length === 0)
|
|
49
|
+
r == null || r(n), n = P();
|
|
50
|
+
else if (c > 0) {
|
|
51
|
+
const d = l.decode(s.subarray(0, c)), a = c + (s[c + 1] === 32 ? 2 : 1), o = l.decode(s.subarray(a));
|
|
52
|
+
switch (d) {
|
|
53
|
+
case "data":
|
|
54
|
+
n.data = n.data ? n.data + `
|
|
55
|
+
` + o : o;
|
|
56
|
+
break;
|
|
57
|
+
case "event":
|
|
58
|
+
n.event = o;
|
|
59
|
+
break;
|
|
60
|
+
case "id":
|
|
61
|
+
e(n.id = o);
|
|
62
|
+
break;
|
|
63
|
+
case "retry":
|
|
64
|
+
const y = parseInt(o, 10);
|
|
65
|
+
isNaN(y) || t(n.retry = y);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
function re(e, t) {
|
|
72
|
+
const r = new Uint8Array(e.length + t.length);
|
|
73
|
+
return r.set(e), r.set(t, e.length), r;
|
|
74
|
+
}
|
|
75
|
+
function P() {
|
|
76
|
+
return {
|
|
77
|
+
data: "",
|
|
78
|
+
event: "",
|
|
79
|
+
id: "",
|
|
80
|
+
retry: void 0
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
var ae = function(e, t) {
|
|
84
|
+
var r = {};
|
|
85
|
+
for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
|
|
86
|
+
if (e != null && typeof Object.getOwnPropertySymbols == "function")
|
|
87
|
+
for (var l = 0, n = Object.getOwnPropertySymbols(e); l < n.length; l++)
|
|
88
|
+
t.indexOf(n[l]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[l]) && (r[n[l]] = e[n[l]]);
|
|
89
|
+
return r;
|
|
90
|
+
};
|
|
91
|
+
const R = "text/event-stream", oe = 1e3, O = "last-event-id";
|
|
92
|
+
function ie(e, t) {
|
|
93
|
+
var { signal: r, headers: n, onopen: l, onmessage: u, onclose: s, onerror: c, openWhenHidden: d, fetch: a } = t, o = ae(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
|
|
94
|
+
return new Promise((y, g) => {
|
|
95
|
+
const h = Object.assign({}, n);
|
|
96
|
+
h.accept || (h.accept = R);
|
|
97
|
+
let m;
|
|
98
|
+
function S() {
|
|
99
|
+
m.abort(), document.hidden || I();
|
|
100
|
+
}
|
|
101
|
+
d || document.addEventListener("visibilitychange", S);
|
|
102
|
+
let f = oe, b = 0;
|
|
103
|
+
function C() {
|
|
104
|
+
document.removeEventListener("visibilitychange", S), window.clearTimeout(b), m.abort();
|
|
105
|
+
}
|
|
106
|
+
r == null || r.addEventListener("abort", () => {
|
|
107
|
+
C(), y();
|
|
108
|
+
});
|
|
109
|
+
const p = a ?? window.fetch, x = l ?? se;
|
|
110
|
+
async function I() {
|
|
111
|
+
var D;
|
|
112
|
+
m = new AbortController();
|
|
113
|
+
try {
|
|
114
|
+
const M = await p(e, Object.assign(Object.assign({}, o), { headers: h, signal: m.signal }));
|
|
115
|
+
await x(M), await ee(M.body, te(ne((T) => {
|
|
116
|
+
T ? h[O] = T : delete h[O];
|
|
117
|
+
}, (T) => {
|
|
118
|
+
f = T;
|
|
119
|
+
}, u))), s == null || s(), C(), y();
|
|
120
|
+
} catch (M) {
|
|
121
|
+
if (!m.signal.aborted)
|
|
122
|
+
try {
|
|
123
|
+
const T = (D = c == null ? void 0 : c(M)) !== null && D !== void 0 ? D : f;
|
|
124
|
+
window.clearTimeout(b), b = window.setTimeout(I, T);
|
|
125
|
+
} catch (T) {
|
|
126
|
+
C(), g(T);
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
I();
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
function se(e) {
|
|
134
|
+
const t = e.headers.get("content-type");
|
|
135
|
+
if (!(t != null && t.startsWith(R)))
|
|
136
|
+
throw new Error(`Expected content-type to be ${R}, Actual: ${t}`);
|
|
137
|
+
}
|
|
138
|
+
function le(e) {
|
|
139
|
+
const t = atob(e), r = new Uint8Array(t.length);
|
|
140
|
+
for (let n = 0; n < t.length; n++)
|
|
141
|
+
r[n] = t.charCodeAt(n);
|
|
142
|
+
return new TextDecoder("utf-8").decode(r);
|
|
143
|
+
}
|
|
144
|
+
class ce {
|
|
145
|
+
constructor(t) {
|
|
146
|
+
this.eventSources = /* @__PURE__ */ new Map(), this.subscribers = /* @__PURE__ */ new Map(), this.fency = t;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* Called by FencyProvider when activeStreams changes.
|
|
150
|
+
* Creates new connections and removes old ones.
|
|
151
|
+
*/
|
|
152
|
+
updateStreams(t) {
|
|
153
|
+
t.forEach((n) => {
|
|
154
|
+
const l = n.stream.id;
|
|
155
|
+
this.eventSources.has(l) || this.connectStream(n);
|
|
156
|
+
});
|
|
157
|
+
const r = new Set(t.map((n) => n.stream.id));
|
|
158
|
+
this.eventSources.forEach((n, l) => {
|
|
159
|
+
r.has(l) || (n.abort(), this.eventSources.delete(l));
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
connectStream(t) {
|
|
163
|
+
const r = t.stream.id, n = new AbortController();
|
|
164
|
+
this.eventSources.set(r, n);
|
|
165
|
+
const l = `${this.fency.baseUrl}/sse/streams/${r}`, u = {
|
|
166
|
+
"X-Fency-Publishable-Key": this.fency.publishableKey,
|
|
167
|
+
"X-Fency-Stream-Token": t.stream.token
|
|
168
|
+
};
|
|
169
|
+
ie(l, {
|
|
170
|
+
headers: u,
|
|
171
|
+
signal: n.signal,
|
|
172
|
+
async onopen(s) {
|
|
173
|
+
if (!s.ok && s.status >= 400 && s.status < 500 && s.status !== 429)
|
|
174
|
+
throw new Error(`Client error ${s.status}`);
|
|
175
|
+
},
|
|
176
|
+
onmessage: (s) => {
|
|
177
|
+
if (s.data) {
|
|
178
|
+
const c = le(s.data);
|
|
179
|
+
this.broadcast(c, r);
|
|
180
|
+
}
|
|
181
|
+
},
|
|
182
|
+
onerror: (s) => {
|
|
183
|
+
throw console.error("EventSource error for stream", r, ":", s), this.broadcastError(r), s;
|
|
184
|
+
},
|
|
185
|
+
onclose() {
|
|
186
|
+
}
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Subscribe to events from all active streams.
|
|
191
|
+
* Returns an unsubscribe function.
|
|
192
|
+
*/
|
|
193
|
+
subscribe(t, r) {
|
|
194
|
+
return this.subscribers.set(t, r), () => {
|
|
195
|
+
this.subscribers.delete(t);
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
broadcast(t, r) {
|
|
199
|
+
this.subscribers.forEach((n) => {
|
|
200
|
+
n.onMessage(t, r);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
broadcastError(t) {
|
|
204
|
+
this.subscribers.forEach((r) => {
|
|
205
|
+
r.onError(t);
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Cleanup all connections and subscriptions
|
|
210
|
+
*/
|
|
211
|
+
cleanup() {
|
|
212
|
+
this.eventSources.forEach((t) => t.abort()), this.eventSources.clear(), this.subscribers.clear();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
const de = 12e4, ue = (e) => {
|
|
216
|
+
const t = Date.now();
|
|
217
|
+
return e.filter((r) => t - r.createdAt < de);
|
|
218
|
+
};
|
|
219
|
+
function We({ fency: e, fetchCreateStreamClientToken: t, children: r }) {
|
|
220
|
+
const [n, l] = w(
|
|
221
|
+
null
|
|
222
|
+
), [u, s] = w(!0), [c, d] = w(null), [a, o] = w([]), y = A(null), g = A(null);
|
|
223
|
+
E(() => {
|
|
224
|
+
e.then((f) => {
|
|
225
|
+
l(f), s(!1);
|
|
226
|
+
}).catch((f) => {
|
|
227
|
+
d(f), s(!1);
|
|
228
|
+
});
|
|
229
|
+
}, [e]), E(() => {
|
|
230
|
+
n && !g.current && (g.current = new ce(n));
|
|
231
|
+
}, [n]), E(() => {
|
|
232
|
+
g.current && g.current.updateStreams(a);
|
|
233
|
+
}, [a]), E(() => () => {
|
|
234
|
+
var f;
|
|
235
|
+
(f = g.current) == null || f.cleanup();
|
|
236
|
+
}, []);
|
|
237
|
+
const h = W(
|
|
238
|
+
async (f = 3e4) => {
|
|
239
|
+
if (y.current)
|
|
240
|
+
return y.current;
|
|
241
|
+
const b = Date.now(), C = a.length > 0 ? a[a.length - 1] : null;
|
|
242
|
+
if (C && b - C.createdAt < f)
|
|
243
|
+
return C.stream;
|
|
244
|
+
const p = (async () => {
|
|
245
|
+
if (!n)
|
|
246
|
+
throw new Error("Fency instance not initialized");
|
|
247
|
+
const x = await t(), I = await K({
|
|
248
|
+
pk: n.publishableKey,
|
|
249
|
+
baseUrl: n.baseUrl,
|
|
250
|
+
clientToken: (x == null ? void 0 : x.clientToken) ?? ""
|
|
251
|
+
});
|
|
252
|
+
if (I.type === "success") {
|
|
253
|
+
const D = {
|
|
254
|
+
stream: I.stream,
|
|
255
|
+
createdAt: Date.now()
|
|
256
|
+
};
|
|
257
|
+
return o((M) => {
|
|
258
|
+
const T = [...M, D];
|
|
259
|
+
return ue(T);
|
|
260
|
+
}), y.current = null, I.stream;
|
|
261
|
+
} else
|
|
262
|
+
throw y.current = null, new Error("Failed to create stream");
|
|
263
|
+
})();
|
|
264
|
+
return y.current = p, p;
|
|
265
|
+
},
|
|
266
|
+
[n, a]
|
|
267
|
+
);
|
|
268
|
+
if (c)
|
|
269
|
+
return /* @__PURE__ */ k("div", { children: [
|
|
270
|
+
"Fency error: ",
|
|
271
|
+
c.message
|
|
272
|
+
] });
|
|
273
|
+
if (!n)
|
|
274
|
+
return null;
|
|
275
|
+
const m = a.length > 0 ? a[a.length - 1] : null, S = {
|
|
276
|
+
fency: n,
|
|
277
|
+
loading: u,
|
|
278
|
+
error: c,
|
|
279
|
+
activeStreams: a,
|
|
280
|
+
latestStream: m,
|
|
281
|
+
eventManager: g.current,
|
|
282
|
+
getOrCreateStream: h
|
|
283
|
+
};
|
|
284
|
+
return /* @__PURE__ */ i(N.Provider, { value: S, children: r });
|
|
285
|
+
}
|
|
286
|
+
function H() {
|
|
287
|
+
const e = X(N);
|
|
13
288
|
if (e === void 0)
|
|
14
289
|
throw new Error("useFencyContext must be used within a FencyProvider");
|
|
15
290
|
return e;
|
|
16
291
|
}
|
|
17
|
-
const
|
|
292
|
+
const me = (e) => {
|
|
18
293
|
try {
|
|
19
294
|
const t = JSON.parse(e);
|
|
20
|
-
return
|
|
295
|
+
return ge(t);
|
|
21
296
|
} catch (t) {
|
|
22
297
|
return console.error("Error parsing message:", t), null;
|
|
23
298
|
}
|
|
24
|
-
},
|
|
25
|
-
if (!(typeof e == "object" && e !== null && "type" in e && "streamId" in e && "timestamp" in e))
|
|
26
|
-
return null;
|
|
27
|
-
switch (e.type) {
|
|
28
|
-
case "StreamTimeout":
|
|
29
|
-
return te(e);
|
|
30
|
-
case "StreamNotFound":
|
|
31
|
-
return ne(e);
|
|
32
|
-
case "AgentTaskProgressItemUpdated":
|
|
33
|
-
return re(e);
|
|
34
|
-
}
|
|
35
|
-
return null;
|
|
36
|
-
}, te = (e) => ({
|
|
299
|
+
}, ge = (e) => _(e) ? ye(e) : J(e) ? fe(e) : V(e) ? he(e) : null, ye = (e) => ({
|
|
37
300
|
type: "StreamTimeout",
|
|
38
301
|
streamId: e.streamId,
|
|
39
302
|
timestamp: e.timestamp
|
|
40
|
-
}),
|
|
303
|
+
}), fe = (e) => ({
|
|
41
304
|
type: "StreamNotFound",
|
|
42
305
|
streamId: e.streamId,
|
|
43
306
|
timestamp: e.timestamp
|
|
44
|
-
}),
|
|
307
|
+
}), he = (e) => ({
|
|
45
308
|
type: "AgentTaskProgressItemUpdated",
|
|
46
309
|
streamId: e.streamId,
|
|
47
310
|
agentTaskId: e.agentTaskId,
|
|
@@ -49,45 +312,45 @@ const Z = (e) => {
|
|
|
49
312
|
timestamp: e.timestamp,
|
|
50
313
|
createdAt: e.createdAt,
|
|
51
314
|
data: JSON.parse(e.data)
|
|
52
|
-
}),
|
|
53
|
-
const t =
|
|
315
|
+
}), Se = (e) => {
|
|
316
|
+
const t = H(), [r, n] = w(null), l = A(`subscriber-${Math.random().toString(36).substr(2, 9)}`);
|
|
54
317
|
return E(() => {
|
|
55
318
|
if (!t.eventManager) return;
|
|
56
319
|
const s = {
|
|
57
320
|
onMessage: (d, a) => {
|
|
58
|
-
var
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
switch (
|
|
321
|
+
var y, g, h, m, S, f, b, C, p, x;
|
|
322
|
+
const o = me(d);
|
|
323
|
+
if (o)
|
|
324
|
+
switch (o.type) {
|
|
62
325
|
case "NewChatCompletionStreamChunk":
|
|
63
|
-
(
|
|
326
|
+
(y = e == null ? void 0 : e.onNewChatCompletionStreamChunk) == null || y.call(e, o);
|
|
64
327
|
break;
|
|
65
328
|
case "ChatCompletionStreamCompleted":
|
|
66
|
-
(
|
|
329
|
+
(g = e == null ? void 0 : e.onChatCompletionStreamCompleted) == null || g.call(e, o);
|
|
67
330
|
break;
|
|
68
331
|
case "StreamTimeout":
|
|
69
|
-
(
|
|
332
|
+
(h = e == null ? void 0 : e.onStreamTimeout) == null || h.call(e, o);
|
|
70
333
|
break;
|
|
71
334
|
case "StreamNotFound":
|
|
72
|
-
(
|
|
335
|
+
(m = e == null ? void 0 : e.onStreamNotFound) == null || m.call(e, o);
|
|
73
336
|
break;
|
|
74
337
|
case "FileUploadCompleted":
|
|
75
|
-
(
|
|
338
|
+
(S = e == null ? void 0 : e.onFileUploadCompleted) == null || S.call(e, o);
|
|
76
339
|
break;
|
|
77
340
|
case "FileTextContentReady":
|
|
78
|
-
(f = e == null ? void 0 : e.onFileTextContentReady) == null || f.call(e,
|
|
341
|
+
(f = e == null ? void 0 : e.onFileTextContentReady) == null || f.call(e, o);
|
|
79
342
|
break;
|
|
80
343
|
case "WebsiteHtmlContentReady":
|
|
81
|
-
(
|
|
344
|
+
(b = e == null ? void 0 : e.onWebsiteHtmlContentReady) == null || b.call(e, o);
|
|
82
345
|
break;
|
|
83
346
|
case "WebsiteTextContentReady":
|
|
84
|
-
(
|
|
347
|
+
(C = e == null ? void 0 : e.onWebsiteTextContentReady) == null || C.call(e, o);
|
|
85
348
|
break;
|
|
86
349
|
case "FileSearchIndexReady":
|
|
87
|
-
(
|
|
350
|
+
(p = e == null ? void 0 : e.onFileSearchIndexReady) == null || p.call(e, o);
|
|
88
351
|
break;
|
|
89
352
|
case "AgentTaskProgressItemUpdated":
|
|
90
|
-
(
|
|
353
|
+
(x = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || x.call(e, o);
|
|
91
354
|
break;
|
|
92
355
|
}
|
|
93
356
|
},
|
|
@@ -103,7 +366,7 @@ const Z = (e) => {
|
|
|
103
366
|
}
|
|
104
367
|
};
|
|
105
368
|
return t.eventManager.subscribe(
|
|
106
|
-
|
|
369
|
+
l.current,
|
|
107
370
|
s
|
|
108
371
|
);
|
|
109
372
|
}, [t.eventManager, e]), {
|
|
@@ -126,64 +389,64 @@ const Z = (e) => {
|
|
|
126
389
|
},
|
|
127
390
|
stream: r
|
|
128
391
|
};
|
|
129
|
-
},
|
|
130
|
-
const t =
|
|
392
|
+
}, Ue = (e) => {
|
|
393
|
+
const t = H(), [r, n] = w([]), l = A(/* @__PURE__ */ new Set()), u = A(/* @__PURE__ */ new Map()), { createStream: s } = Se({
|
|
131
394
|
onAgentTaskProgressItemUpdated: (a) => {
|
|
132
|
-
var
|
|
133
|
-
if (!
|
|
134
|
-
const
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
395
|
+
var g;
|
|
396
|
+
if (!l.current.has(a.agentTaskId)) return;
|
|
397
|
+
const o = a.data;
|
|
398
|
+
if (o.taskType === "StreamingChatCompletion" && o.eventType === "Completed" || o.taskType === "StructuredChatCompletion" && o.eventType === "Completed" || o.taskType === "StreamingMemoryTypeChatCompletion" && o.eventType === "Completed") {
|
|
399
|
+
const h = u.current.get(
|
|
137
400
|
a.agentTaskId
|
|
138
401
|
);
|
|
139
|
-
|
|
402
|
+
h && (u.current.delete(a.agentTaskId), h(o));
|
|
140
403
|
return;
|
|
141
404
|
}
|
|
142
|
-
(
|
|
143
|
-
(
|
|
144
|
-
var
|
|
145
|
-
if (((
|
|
146
|
-
return
|
|
147
|
-
const f =
|
|
148
|
-
(
|
|
149
|
-
) ?
|
|
150
|
-
(
|
|
151
|
-
) : [...
|
|
152
|
-
return { ...
|
|
405
|
+
(g = e.onAgentTaskProgressItemUpdated) == null || g.call(e, a), n(
|
|
406
|
+
(h) => h.map((m) => {
|
|
407
|
+
var b;
|
|
408
|
+
if (((b = m.confirmedData) == null ? void 0 : b.taskId) !== a.agentTaskId)
|
|
409
|
+
return m;
|
|
410
|
+
const f = m.progressItems.some(
|
|
411
|
+
(C) => C.progressItemId === a.progressItemId
|
|
412
|
+
) ? m.progressItems.map(
|
|
413
|
+
(C) => C.progressItemId === a.progressItemId ? a : C
|
|
414
|
+
) : [...m.progressItems, a];
|
|
415
|
+
return { ...m, progressItems: f };
|
|
153
416
|
})
|
|
154
417
|
);
|
|
155
418
|
},
|
|
156
419
|
onStreamError: (a) => {
|
|
157
|
-
var
|
|
158
|
-
(
|
|
159
|
-
const
|
|
160
|
-
return
|
|
161
|
-
...
|
|
420
|
+
var o;
|
|
421
|
+
(o = e == null ? void 0 : e.onStreamError) == null || o.call(e, a), n((y) => {
|
|
422
|
+
const g = y.find((h) => h.streamId === a.streamId);
|
|
423
|
+
return g ? [
|
|
424
|
+
...y.filter((h) => h.streamId !== a.streamId),
|
|
162
425
|
{
|
|
163
|
-
...
|
|
426
|
+
...g,
|
|
164
427
|
loading: !1,
|
|
165
428
|
error: a.error
|
|
166
429
|
}
|
|
167
|
-
] :
|
|
430
|
+
] : y;
|
|
168
431
|
});
|
|
169
432
|
},
|
|
170
433
|
onStreamNotFound: (a) => {
|
|
171
|
-
var
|
|
172
|
-
(
|
|
434
|
+
var o;
|
|
435
|
+
(o = e == null ? void 0 : e.onStreamNotFound) == null || o.call(e, a);
|
|
173
436
|
},
|
|
174
437
|
onStreamTimeout: (a) => {
|
|
175
|
-
var
|
|
176
|
-
(
|
|
438
|
+
var o;
|
|
439
|
+
(o = e == null ? void 0 : e.onStreamTimeout) == null || o.call(e, a);
|
|
177
440
|
}
|
|
178
|
-
}),
|
|
179
|
-
async (a,
|
|
180
|
-
const
|
|
181
|
-
if (
|
|
441
|
+
}), c = W(
|
|
442
|
+
async (a, o) => {
|
|
443
|
+
const y = `task-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, g = await s();
|
|
444
|
+
if (g.type === "success") {
|
|
182
445
|
n([
|
|
183
446
|
...r,
|
|
184
447
|
{
|
|
185
|
-
taskKey:
|
|
186
|
-
streamId:
|
|
448
|
+
taskKey: y,
|
|
449
|
+
streamId: g.stream.id,
|
|
187
450
|
triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
188
451
|
confirmedData: null,
|
|
189
452
|
error: null,
|
|
@@ -191,14 +454,14 @@ const Z = (e) => {
|
|
|
191
454
|
progressItems: [],
|
|
192
455
|
loading: !0,
|
|
193
456
|
doneStreaming: !1,
|
|
194
|
-
loadingText:
|
|
457
|
+
loadingText: o == null ? void 0 : o.loadingText
|
|
195
458
|
}
|
|
196
459
|
]);
|
|
197
|
-
const { clientToken:
|
|
460
|
+
const { clientToken: h } = await e.fetchCreateAgentTaskClientToken(a.type), m = await q({
|
|
198
461
|
pk: t.fency.publishableKey,
|
|
199
462
|
baseUrl: t.fency.baseUrl,
|
|
200
|
-
clientToken:
|
|
201
|
-
streamToken:
|
|
463
|
+
clientToken: h,
|
|
464
|
+
streamToken: g.stream.token,
|
|
202
465
|
request: {
|
|
203
466
|
streamingChatCompletionTask: a.type === "streamingChatCompletion" ? {
|
|
204
467
|
messages: a.messages,
|
|
@@ -215,407 +478,139 @@ const Z = (e) => {
|
|
|
215
478
|
} : void 0
|
|
216
479
|
}
|
|
217
480
|
});
|
|
218
|
-
if (
|
|
219
|
-
|
|
220
|
-
|
|
481
|
+
if (m.type === "success" && m.agentTask) {
|
|
482
|
+
l.current.add(
|
|
483
|
+
m.agentTask.id
|
|
221
484
|
), n((f) => [
|
|
222
|
-
...f.filter((
|
|
485
|
+
...f.filter((b) => b.taskKey !== y),
|
|
223
486
|
{
|
|
224
|
-
taskKey:
|
|
225
|
-
streamId:
|
|
487
|
+
taskKey: y,
|
|
488
|
+
streamId: g.stream.id,
|
|
226
489
|
triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
227
|
-
taskId:
|
|
228
|
-
createdAt:
|
|
490
|
+
taskId: m.agentTask.id,
|
|
491
|
+
createdAt: m.agentTask.createdAt,
|
|
229
492
|
error: null,
|
|
230
493
|
params: a,
|
|
231
494
|
progressItems: [],
|
|
232
495
|
doneStreaming: !1,
|
|
233
496
|
loading: !0,
|
|
234
|
-
loadingText:
|
|
497
|
+
loadingText: o == null ? void 0 : o.loadingText,
|
|
235
498
|
confirmedData: {
|
|
236
|
-
taskId:
|
|
237
|
-
createdAt:
|
|
499
|
+
taskId: m.agentTask.id,
|
|
500
|
+
createdAt: m.agentTask.createdAt
|
|
238
501
|
}
|
|
239
502
|
}
|
|
240
503
|
]);
|
|
241
|
-
const
|
|
242
|
-
|
|
243
|
-
|
|
504
|
+
const S = await new Promise((f) => {
|
|
505
|
+
u.current.set(
|
|
506
|
+
m.agentTask.id,
|
|
244
507
|
f
|
|
245
508
|
);
|
|
246
509
|
});
|
|
247
510
|
return {
|
|
248
511
|
type: "success",
|
|
249
|
-
streamId:
|
|
250
|
-
agentTaskId:
|
|
251
|
-
response:
|
|
512
|
+
streamId: g.stream.id,
|
|
513
|
+
agentTaskId: m.agentTask.id,
|
|
514
|
+
response: S
|
|
252
515
|
};
|
|
253
516
|
} else {
|
|
254
|
-
if (
|
|
255
|
-
return n((
|
|
256
|
-
...
|
|
517
|
+
if (m.type === "error")
|
|
518
|
+
return n((S) => [
|
|
519
|
+
...S.filter((f) => f.taskKey !== y),
|
|
257
520
|
{
|
|
258
|
-
taskKey:
|
|
521
|
+
taskKey: y,
|
|
259
522
|
triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
260
|
-
streamId:
|
|
523
|
+
streamId: g.stream.id,
|
|
261
524
|
params: a,
|
|
262
|
-
error:
|
|
525
|
+
error: m.error,
|
|
263
526
|
progressItems: [],
|
|
264
527
|
loading: !1,
|
|
265
528
|
doneStreaming: !1,
|
|
266
|
-
loadingText:
|
|
529
|
+
loadingText: o == null ? void 0 : o.loadingText,
|
|
267
530
|
confirmedData: null
|
|
268
531
|
}
|
|
269
532
|
]), {
|
|
270
533
|
type: "error",
|
|
271
|
-
error:
|
|
534
|
+
error: m.error
|
|
272
535
|
};
|
|
273
536
|
{
|
|
274
|
-
const
|
|
537
|
+
const S = {
|
|
275
538
|
message: "No response received",
|
|
276
539
|
code: "UnknownError"
|
|
277
540
|
};
|
|
278
541
|
return n((f) => [
|
|
279
|
-
...f.filter((
|
|
542
|
+
...f.filter((b) => b.taskKey !== y),
|
|
280
543
|
{
|
|
281
|
-
taskKey:
|
|
544
|
+
taskKey: y,
|
|
282
545
|
triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
|
|
283
|
-
streamId:
|
|
284
|
-
error:
|
|
546
|
+
streamId: g.stream.id,
|
|
547
|
+
error: S,
|
|
285
548
|
params: a,
|
|
286
549
|
progressItems: [],
|
|
287
550
|
loading: !1,
|
|
288
551
|
doneStreaming: !1,
|
|
289
|
-
loadingText:
|
|
552
|
+
loadingText: o == null ? void 0 : o.loadingText,
|
|
290
553
|
confirmedData: null
|
|
291
554
|
}
|
|
292
555
|
]), {
|
|
293
556
|
type: "error",
|
|
294
|
-
error:
|
|
557
|
+
error: S
|
|
295
558
|
};
|
|
296
559
|
}
|
|
297
560
|
}
|
|
298
561
|
} else
|
|
299
|
-
return console.error(
|
|
562
|
+
return console.error(g.error), g;
|
|
300
563
|
},
|
|
301
564
|
[t, r, s]
|
|
302
|
-
), d =
|
|
565
|
+
), d = U(() => {
|
|
303
566
|
if (r.length !== 0)
|
|
304
|
-
return [...r].sort((a,
|
|
567
|
+
return [...r].sort((a, o) => new Date(o.triggeredAt).getTime() - new Date(a.triggeredAt).getTime())[0];
|
|
305
568
|
}, [r]);
|
|
306
569
|
return E(() => () => {
|
|
307
|
-
|
|
570
|
+
l.current.clear(), u.current.clear();
|
|
308
571
|
}, []), {
|
|
309
572
|
agentTasks: r,
|
|
310
|
-
createAgentTask:
|
|
573
|
+
createAgentTask: c,
|
|
311
574
|
latest: d
|
|
312
575
|
};
|
|
313
576
|
};
|
|
314
|
-
|
|
315
|
-
const r = e.getReader();
|
|
316
|
-
let n;
|
|
317
|
-
for (; !(n = await r.read()).done; )
|
|
318
|
-
t(n.value);
|
|
319
|
-
}
|
|
320
|
-
function ie(e) {
|
|
321
|
-
let t, r, n, o = !1;
|
|
322
|
-
return function(s) {
|
|
323
|
-
t === void 0 ? (t = s, r = 0, n = -1) : t = ce(t, s);
|
|
324
|
-
const l = t.length;
|
|
325
|
-
let d = 0;
|
|
326
|
-
for (; r < l; ) {
|
|
327
|
-
o && (t[r] === 10 && (d = ++r), o = !1);
|
|
328
|
-
let a = -1;
|
|
329
|
-
for (; r < l && a === -1; ++r)
|
|
330
|
-
switch (t[r]) {
|
|
331
|
-
case 58:
|
|
332
|
-
n === -1 && (n = r - d);
|
|
333
|
-
break;
|
|
334
|
-
case 13:
|
|
335
|
-
o = !0;
|
|
336
|
-
case 10:
|
|
337
|
-
a = r;
|
|
338
|
-
break;
|
|
339
|
-
}
|
|
340
|
-
if (a === -1)
|
|
341
|
-
break;
|
|
342
|
-
e(t.subarray(d, a), n), d = r, n = -1;
|
|
343
|
-
}
|
|
344
|
-
d === l ? t = void 0 : d !== 0 && (t = t.subarray(d), r -= d);
|
|
345
|
-
};
|
|
346
|
-
}
|
|
347
|
-
function se(e, t, r) {
|
|
348
|
-
let n = O();
|
|
349
|
-
const o = new TextDecoder();
|
|
350
|
-
return function(s, l) {
|
|
351
|
-
if (s.length === 0)
|
|
352
|
-
r == null || r(n), n = O();
|
|
353
|
-
else if (l > 0) {
|
|
354
|
-
const d = o.decode(s.subarray(0, l)), a = l + (s[l + 1] === 32 ? 2 : 1), i = o.decode(s.subarray(a));
|
|
355
|
-
switch (d) {
|
|
356
|
-
case "data":
|
|
357
|
-
n.data = n.data ? n.data + `
|
|
358
|
-
` + i : i;
|
|
359
|
-
break;
|
|
360
|
-
case "event":
|
|
361
|
-
n.event = i;
|
|
362
|
-
break;
|
|
363
|
-
case "id":
|
|
364
|
-
e(n.id = i);
|
|
365
|
-
break;
|
|
366
|
-
case "retry":
|
|
367
|
-
const g = parseInt(i, 10);
|
|
368
|
-
isNaN(g) || t(n.retry = g);
|
|
369
|
-
break;
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
};
|
|
373
|
-
}
|
|
374
|
-
function ce(e, t) {
|
|
375
|
-
const r = new Uint8Array(e.length + t.length);
|
|
376
|
-
return r.set(e), r.set(t, e.length), r;
|
|
377
|
-
}
|
|
378
|
-
function O() {
|
|
379
|
-
return {
|
|
380
|
-
data: "",
|
|
381
|
-
event: "",
|
|
382
|
-
id: "",
|
|
383
|
-
retry: void 0
|
|
384
|
-
};
|
|
385
|
-
}
|
|
386
|
-
var le = function(e, t) {
|
|
387
|
-
var r = {};
|
|
388
|
-
for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
|
|
389
|
-
if (e != null && typeof Object.getOwnPropertySymbols == "function")
|
|
390
|
-
for (var o = 0, n = Object.getOwnPropertySymbols(e); o < n.length; o++)
|
|
391
|
-
t.indexOf(n[o]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[o]) && (r[n[o]] = e[n[o]]);
|
|
392
|
-
return r;
|
|
393
|
-
};
|
|
394
|
-
const F = "text/event-stream", de = 1e3, D = "last-event-id";
|
|
395
|
-
function j(e, t) {
|
|
396
|
-
var { signal: r, headers: n, onopen: o, onmessage: m, onclose: s, onerror: l, openWhenHidden: d, fetch: a } = t, i = le(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
|
|
397
|
-
return new Promise((g, u) => {
|
|
398
|
-
const S = Object.assign({}, n);
|
|
399
|
-
S.accept || (S.accept = F);
|
|
400
|
-
let y;
|
|
401
|
-
function T() {
|
|
402
|
-
y.abort(), document.hidden || p();
|
|
403
|
-
}
|
|
404
|
-
d || document.addEventListener("visibilitychange", T);
|
|
405
|
-
let f = de, h = 0;
|
|
406
|
-
function b() {
|
|
407
|
-
document.removeEventListener("visibilitychange", T), window.clearTimeout(h), y.abort();
|
|
408
|
-
}
|
|
409
|
-
r == null || r.addEventListener("abort", () => {
|
|
410
|
-
b(), g();
|
|
411
|
-
});
|
|
412
|
-
const I = a ?? window.fetch, w = o ?? ue;
|
|
413
|
-
async function p() {
|
|
414
|
-
var M;
|
|
415
|
-
y = new AbortController();
|
|
416
|
-
try {
|
|
417
|
-
const P = await I(e, Object.assign(Object.assign({}, i), { headers: S, signal: y.signal }));
|
|
418
|
-
await w(P), await oe(P.body, ie(se((k) => {
|
|
419
|
-
k ? S[D] = k : delete S[D];
|
|
420
|
-
}, (k) => {
|
|
421
|
-
f = k;
|
|
422
|
-
}, m))), s == null || s(), b(), g();
|
|
423
|
-
} catch (P) {
|
|
424
|
-
if (!y.signal.aborted)
|
|
425
|
-
try {
|
|
426
|
-
const k = (M = l == null ? void 0 : l(P)) !== null && M !== void 0 ? M : f;
|
|
427
|
-
window.clearTimeout(h), h = window.setTimeout(p, k);
|
|
428
|
-
} catch (k) {
|
|
429
|
-
b(), u(k);
|
|
430
|
-
}
|
|
431
|
-
}
|
|
432
|
-
}
|
|
433
|
-
p();
|
|
434
|
-
});
|
|
435
|
-
}
|
|
436
|
-
function ue(e) {
|
|
437
|
-
const t = e.headers.get("content-type");
|
|
438
|
-
if (!(t != null && t.startsWith(F)))
|
|
439
|
-
throw new Error(`Expected content-type to be ${F}, Actual: ${t}`);
|
|
440
|
-
}
|
|
441
|
-
function De(e) {
|
|
442
|
-
const [t, r] = C(null);
|
|
443
|
-
return E(() => {
|
|
444
|
-
if (!t)
|
|
445
|
-
return;
|
|
446
|
-
const n = new AbortController();
|
|
447
|
-
return j(t, {
|
|
448
|
-
headers: e == null ? void 0 : e.headers,
|
|
449
|
-
signal: n.signal,
|
|
450
|
-
async onopen(o) {
|
|
451
|
-
if (!o.ok && o.status >= 400 && o.status < 500 && o.status !== 429)
|
|
452
|
-
throw new Error(`Client error ${o.status}`);
|
|
453
|
-
},
|
|
454
|
-
onmessage(o) {
|
|
455
|
-
o.data && (e == null || e.onMessage({
|
|
456
|
-
url: t,
|
|
457
|
-
data: H(o.data)
|
|
458
|
-
}));
|
|
459
|
-
},
|
|
460
|
-
onerror(o) {
|
|
461
|
-
throw console.error("EventSource error:", o), e == null || e.onError(t), r(null), o;
|
|
462
|
-
},
|
|
463
|
-
onclose() {
|
|
464
|
-
}
|
|
465
|
-
}), () => {
|
|
466
|
-
n.abort();
|
|
467
|
-
};
|
|
468
|
-
}, [t, e == null ? void 0 : e.headers]), {
|
|
469
|
-
setSourceUrl: r,
|
|
470
|
-
sourceUrl: t
|
|
471
|
-
};
|
|
472
|
-
}
|
|
473
|
-
function H(e) {
|
|
474
|
-
const t = atob(e), r = new Uint8Array(t.length);
|
|
475
|
-
for (let n = 0; n < t.length; n++)
|
|
476
|
-
r[n] = t.charCodeAt(n);
|
|
477
|
-
return new TextDecoder("utf-8").decode(r);
|
|
478
|
-
}
|
|
479
|
-
function Ue(e, t) {
|
|
480
|
-
const [r, n] = C(
|
|
481
|
-
null
|
|
482
|
-
), [o, m] = C(
|
|
483
|
-
null
|
|
484
|
-
), s = N(), l = async (g) => {
|
|
485
|
-
const u = await g.fetchTokens(), { fetchTokens: S, nextPageToken: y, previousPageToken: T, ...f } = g, h = await e({
|
|
486
|
-
pk: s.fency.publishableKey,
|
|
487
|
-
clientToken: u.clientToken,
|
|
488
|
-
streamToken: u.streamToken,
|
|
489
|
-
request: {
|
|
490
|
-
...f,
|
|
491
|
-
limit: (t == null ? void 0 : t.pageSize) ?? 50,
|
|
492
|
-
pagination: {
|
|
493
|
-
nextPageToken: y,
|
|
494
|
-
previousPageToken: T
|
|
495
|
-
}
|
|
496
|
-
},
|
|
497
|
-
baseUrl: s.fency.baseUrl
|
|
498
|
-
});
|
|
499
|
-
return h.type === "success" && h.items && h.pagination ? {
|
|
500
|
-
type: "success",
|
|
501
|
-
page: {
|
|
502
|
-
items: h.items,
|
|
503
|
-
hasNextPage: h.pagination.nextPageToken != null,
|
|
504
|
-
hasPreviousPage: h.pagination.previousPageToken != null,
|
|
505
|
-
pagination: h.pagination
|
|
506
|
-
}
|
|
507
|
-
} : {
|
|
508
|
-
type: "error",
|
|
509
|
-
error: h.error ?? {
|
|
510
|
-
code: "UNKNOWN_ERROR",
|
|
511
|
-
message: "An unknown error occurred"
|
|
512
|
-
}
|
|
513
|
-
};
|
|
514
|
-
};
|
|
515
|
-
return {
|
|
516
|
-
fetchFirstPage: async (g) => {
|
|
517
|
-
const u = await l({
|
|
518
|
-
...g,
|
|
519
|
-
nextPageToken: void 0,
|
|
520
|
-
previousPageToken: void 0
|
|
521
|
-
});
|
|
522
|
-
return u.type === "success" && (m(u.page), n(g)), u;
|
|
523
|
-
},
|
|
524
|
-
fetchNextPage: async (g) => {
|
|
525
|
-
if (o == null)
|
|
526
|
-
return {
|
|
527
|
-
type: "error",
|
|
528
|
-
error: {
|
|
529
|
-
code: "NO_CURRENT_PAGE",
|
|
530
|
-
message: "No current page"
|
|
531
|
-
}
|
|
532
|
-
};
|
|
533
|
-
if (o.pagination.nextPageToken == null)
|
|
534
|
-
return {
|
|
535
|
-
type: "error",
|
|
536
|
-
error: {
|
|
537
|
-
code: "NO_NEXT_PAGE",
|
|
538
|
-
message: "No next page"
|
|
539
|
-
}
|
|
540
|
-
};
|
|
541
|
-
const u = await l({
|
|
542
|
-
...g,
|
|
543
|
-
nextPageToken: o.pagination.nextPageToken,
|
|
544
|
-
previousPageToken: void 0
|
|
545
|
-
});
|
|
546
|
-
return u.type === "success" && (m(u.page), n(g)), u;
|
|
547
|
-
},
|
|
548
|
-
fetchPreviousPage: async (g) => {
|
|
549
|
-
if (o == null)
|
|
550
|
-
return {
|
|
551
|
-
type: "error",
|
|
552
|
-
error: {
|
|
553
|
-
code: "NO_CURRENT_PAGE",
|
|
554
|
-
message: "No current page"
|
|
555
|
-
}
|
|
556
|
-
};
|
|
557
|
-
if (o.pagination.previousPageToken == null)
|
|
558
|
-
return {
|
|
559
|
-
type: "error",
|
|
560
|
-
error: {
|
|
561
|
-
code: "NO_PREVIOUS_PAGE",
|
|
562
|
-
message: "No previous page"
|
|
563
|
-
}
|
|
564
|
-
};
|
|
565
|
-
const u = await l({
|
|
566
|
-
...g,
|
|
567
|
-
nextPageToken: void 0,
|
|
568
|
-
previousPageToken: o.pagination.previousPageToken
|
|
569
|
-
});
|
|
570
|
-
return u.type === "success" && (m(u.page), n(g)), u;
|
|
571
|
-
},
|
|
572
|
-
refetchCurrentPage: async () => r == null ? {
|
|
573
|
-
type: "error",
|
|
574
|
-
error: {
|
|
575
|
-
code: "NO_CURRENT_PAGE",
|
|
576
|
-
message: "No current page, please call fetchFirstPage first."
|
|
577
|
-
}
|
|
578
|
-
} : l(r),
|
|
579
|
-
currentPage: o
|
|
580
|
-
};
|
|
581
|
-
}
|
|
582
|
-
function me(e) {
|
|
577
|
+
function be(e) {
|
|
583
578
|
return e.progressItems.map((t, r) => {
|
|
584
|
-
const n = e.progressItems[r + 1],
|
|
585
|
-
let
|
|
579
|
+
const n = e.progressItems[r + 1], l = n != null;
|
|
580
|
+
let u;
|
|
586
581
|
if (n != null && n.createdAt) {
|
|
587
|
-
const s = new Date(t.createdAt).getTime(),
|
|
588
|
-
|
|
582
|
+
const s = new Date(t.createdAt).getTime(), c = new Date(n.createdAt).getTime();
|
|
583
|
+
u = Math.round((c - s) / 1e3);
|
|
589
584
|
}
|
|
590
585
|
return {
|
|
591
586
|
item: t,
|
|
592
|
-
completed:
|
|
587
|
+
completed: l,
|
|
593
588
|
isLatest: r === e.progressItems.length - 1,
|
|
594
|
-
durationSeconds:
|
|
589
|
+
durationSeconds: u
|
|
595
590
|
};
|
|
596
591
|
});
|
|
597
592
|
}
|
|
598
|
-
function
|
|
593
|
+
function F({
|
|
599
594
|
text: e,
|
|
600
595
|
duration: t = 2,
|
|
601
596
|
delay: r = 0,
|
|
602
597
|
repeat: n = !0,
|
|
603
|
-
repeatDelay:
|
|
604
|
-
className:
|
|
598
|
+
repeatDelay: l = 0.5,
|
|
599
|
+
className: u,
|
|
605
600
|
startOnView: s = !1,
|
|
606
|
-
once:
|
|
601
|
+
once: c = !1,
|
|
607
602
|
inViewMargin: d,
|
|
608
603
|
spread: a = 2,
|
|
609
|
-
color:
|
|
610
|
-
shimmerColor:
|
|
611
|
-
direction:
|
|
604
|
+
color: o = "#999",
|
|
605
|
+
shimmerColor: y = "#000",
|
|
606
|
+
direction: g = "fromBottom"
|
|
612
607
|
}) {
|
|
613
|
-
const
|
|
614
|
-
return /* @__PURE__ */
|
|
608
|
+
const h = A(null), m = Q(h, { once: c, margin: d }), S = U(() => e.length * a, [e, a]), f = !s || m, b = g === "fromBottom" ? "100% center" : "-100% center", C = g === "fromBottom" ? "0% center" : "200% center";
|
|
609
|
+
return /* @__PURE__ */ i(
|
|
615
610
|
v.span,
|
|
616
611
|
{
|
|
617
|
-
ref:
|
|
618
|
-
className:
|
|
612
|
+
ref: h,
|
|
613
|
+
className: u,
|
|
619
614
|
style: {
|
|
620
615
|
position: "relative",
|
|
621
616
|
display: "inline-block",
|
|
@@ -625,18 +620,18 @@ function R({
|
|
|
625
620
|
color: "transparent",
|
|
626
621
|
WebkitTextFillColor: "transparent",
|
|
627
622
|
backgroundRepeat: "no-repeat, padding-box",
|
|
628
|
-
"--spread": `${
|
|
629
|
-
"--base-color":
|
|
630
|
-
"--shimmer-color":
|
|
623
|
+
"--spread": `${S}px`,
|
|
624
|
+
"--base-color": o,
|
|
625
|
+
"--shimmer-color": y,
|
|
631
626
|
"--shimmer-bg": "linear-gradient(90deg, transparent calc(50% - var(--spread)), var(--shimmer-color), transparent calc(50% + var(--spread)))",
|
|
632
627
|
backgroundImage: "var(--shimmer-bg), linear-gradient(var(--base-color), var(--base-color))"
|
|
633
628
|
},
|
|
634
629
|
initial: {
|
|
635
|
-
backgroundPosition:
|
|
630
|
+
backgroundPosition: b,
|
|
636
631
|
opacity: 0
|
|
637
632
|
},
|
|
638
633
|
animate: f ? {
|
|
639
|
-
backgroundPosition:
|
|
634
|
+
backgroundPosition: C,
|
|
640
635
|
opacity: 1
|
|
641
636
|
} : {},
|
|
642
637
|
transition: {
|
|
@@ -644,7 +639,7 @@ function R({
|
|
|
644
639
|
repeat: n ? 1 / 0 : 0,
|
|
645
640
|
duration: t,
|
|
646
641
|
delay: r,
|
|
647
|
-
repeatDelay:
|
|
642
|
+
repeatDelay: l,
|
|
648
643
|
ease: "linear"
|
|
649
644
|
},
|
|
650
645
|
opacity: {
|
|
@@ -656,7 +651,7 @@ function R({
|
|
|
656
651
|
}
|
|
657
652
|
);
|
|
658
653
|
}
|
|
659
|
-
function
|
|
654
|
+
function Ce(e) {
|
|
660
655
|
const t = e.item.data;
|
|
661
656
|
if (t.taskType === "StreamingChatCompletion") {
|
|
662
657
|
if (t.eventType === "Text") return "Streaming...";
|
|
@@ -687,26 +682,26 @@ function ge(e) {
|
|
|
687
682
|
}
|
|
688
683
|
return "Processing...";
|
|
689
684
|
}
|
|
690
|
-
const
|
|
685
|
+
const Te = ({ progressViewItems: e }) => {
|
|
691
686
|
const t = e[e.length - 1];
|
|
692
687
|
if (!t) return null;
|
|
693
|
-
const r =
|
|
694
|
-
return /* @__PURE__ */
|
|
688
|
+
const r = Ce(t);
|
|
689
|
+
return /* @__PURE__ */ i("div", { className: "simple-mode-container", children: /* @__PURE__ */ i(L, { mode: "wait", children: /* @__PURE__ */ i(
|
|
695
690
|
v.div,
|
|
696
691
|
{
|
|
697
692
|
initial: { opacity: 0, y: 10 },
|
|
698
693
|
animate: { opacity: 1, y: 0 },
|
|
699
694
|
exit: { opacity: 0, y: -10 },
|
|
700
695
|
transition: { duration: 0.3 },
|
|
701
|
-
children: t.completed ? /* @__PURE__ */
|
|
696
|
+
children: t.completed ? /* @__PURE__ */ i(
|
|
702
697
|
"div",
|
|
703
698
|
{
|
|
704
699
|
className: "simple-mode-title",
|
|
705
700
|
style: { color: "#666" },
|
|
706
701
|
children: r
|
|
707
702
|
}
|
|
708
|
-
) : /* @__PURE__ */
|
|
709
|
-
|
|
703
|
+
) : /* @__PURE__ */ i(
|
|
704
|
+
F,
|
|
710
705
|
{
|
|
711
706
|
text: r,
|
|
712
707
|
className: "simple-mode-title",
|
|
@@ -719,7 +714,7 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
719
714
|
},
|
|
720
715
|
t.item.progressItemId
|
|
721
716
|
) }) });
|
|
722
|
-
},
|
|
717
|
+
}, j = {
|
|
723
718
|
'code[class*="language-"]': {
|
|
724
719
|
color: "#f8f8f2",
|
|
725
720
|
background: "none",
|
|
@@ -870,53 +865,53 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
870
865
|
italic: {
|
|
871
866
|
fontStyle: "italic"
|
|
872
867
|
}
|
|
873
|
-
},
|
|
868
|
+
}, z = ({
|
|
874
869
|
text: e
|
|
875
|
-
}) => /* @__PURE__ */
|
|
870
|
+
}) => /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ i(
|
|
876
871
|
v.div,
|
|
877
872
|
{
|
|
878
873
|
className: "fency-markdown-body-raw",
|
|
879
874
|
initial: { opacity: 0, y: -10 },
|
|
880
875
|
animate: { opacity: 1, y: 0 },
|
|
881
876
|
transition: { duration: 0.3, delay: 0 },
|
|
882
|
-
children: /* @__PURE__ */
|
|
883
|
-
|
|
877
|
+
children: /* @__PURE__ */ i(
|
|
878
|
+
Y,
|
|
884
879
|
{
|
|
885
|
-
remarkPlugins: [
|
|
880
|
+
remarkPlugins: [Z],
|
|
886
881
|
components: {
|
|
887
882
|
code(t) {
|
|
888
|
-
const { children: r, className: n, node:
|
|
889
|
-
return
|
|
883
|
+
const { children: r, className: n, node: l, ref: u, ...s } = t, c = /language-(\w+)/.exec(n || "");
|
|
884
|
+
return c ? /* @__PURE__ */ i(
|
|
890
885
|
$,
|
|
891
886
|
{
|
|
892
887
|
...s,
|
|
893
888
|
PreTag: "div",
|
|
894
889
|
children: String(r).replace(/\n$/, ""),
|
|
895
|
-
language:
|
|
896
|
-
style:
|
|
890
|
+
language: c[1],
|
|
891
|
+
style: j
|
|
897
892
|
}
|
|
898
|
-
) : /* @__PURE__ */
|
|
893
|
+
) : /* @__PURE__ */ i("code", { ...s, className: n, children: String(r) });
|
|
899
894
|
}
|
|
900
895
|
},
|
|
901
896
|
children: e
|
|
902
897
|
}
|
|
903
898
|
)
|
|
904
899
|
}
|
|
905
|
-
) }),
|
|
900
|
+
) }), ve = ({ data: e }) => {
|
|
906
901
|
const t = JSON.stringify(e.json, null, 2);
|
|
907
|
-
return /* @__PURE__ */
|
|
902
|
+
return /* @__PURE__ */ i("div", { id: "structured-chat-completion-response", children: /* @__PURE__ */ i(
|
|
908
903
|
v.div,
|
|
909
904
|
{
|
|
910
905
|
initial: { opacity: 0, y: -10 },
|
|
911
906
|
animate: { opacity: 1, y: 0 },
|
|
912
907
|
transition: { duration: 0.3, delay: 0 },
|
|
913
|
-
children: /* @__PURE__ */
|
|
908
|
+
children: /* @__PURE__ */ i($, { language: "json", style: j, PreTag: "div", children: t })
|
|
914
909
|
}
|
|
915
910
|
) });
|
|
916
|
-
},
|
|
911
|
+
}, ke = ({ data: e, isLatest: t = !1, durationSeconds: r }) => {
|
|
917
912
|
const n = `Searching: ${e.queryDescription}`;
|
|
918
|
-
return /* @__PURE__ */
|
|
919
|
-
/* @__PURE__ */
|
|
913
|
+
return /* @__PURE__ */ k("div", { style: { padding: "16px" }, children: [
|
|
914
|
+
/* @__PURE__ */ i(
|
|
920
915
|
v.div,
|
|
921
916
|
{
|
|
922
917
|
style: {
|
|
@@ -928,8 +923,8 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
928
923
|
initial: { opacity: 0, y: -10 },
|
|
929
924
|
animate: { opacity: 1, y: 0 },
|
|
930
925
|
transition: { duration: 0.3, delay: 0 },
|
|
931
|
-
children: t && !r ? /* @__PURE__ */
|
|
932
|
-
|
|
926
|
+
children: t && !r ? /* @__PURE__ */ i(
|
|
927
|
+
F,
|
|
933
928
|
{
|
|
934
929
|
text: n,
|
|
935
930
|
duration: 2.5,
|
|
@@ -937,10 +932,10 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
937
932
|
color: "#999",
|
|
938
933
|
shimmerColor: "#000"
|
|
939
934
|
}
|
|
940
|
-
) : /* @__PURE__ */
|
|
935
|
+
) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: n })
|
|
941
936
|
}
|
|
942
937
|
),
|
|
943
|
-
r !== void 0 && /* @__PURE__ */
|
|
938
|
+
r !== void 0 && /* @__PURE__ */ k(
|
|
944
939
|
"div",
|
|
945
940
|
{
|
|
946
941
|
style: {
|
|
@@ -957,10 +952,10 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
957
952
|
}
|
|
958
953
|
)
|
|
959
954
|
] });
|
|
960
|
-
},
|
|
955
|
+
}, xe = ({ isLatest: e = !1, durationSeconds: t }) => {
|
|
961
956
|
const r = "Adding sources...";
|
|
962
|
-
return /* @__PURE__ */
|
|
963
|
-
/* @__PURE__ */
|
|
957
|
+
return /* @__PURE__ */ k("div", { style: { padding: "16px" }, children: [
|
|
958
|
+
/* @__PURE__ */ i(
|
|
964
959
|
v.div,
|
|
965
960
|
{
|
|
966
961
|
style: {
|
|
@@ -972,8 +967,8 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
972
967
|
initial: { opacity: 0, y: -10 },
|
|
973
968
|
animate: { opacity: 1, y: 0 },
|
|
974
969
|
transition: { duration: 0.3, delay: 0 },
|
|
975
|
-
children: e && !t ? /* @__PURE__ */
|
|
976
|
-
|
|
970
|
+
children: e && !t ? /* @__PURE__ */ i(
|
|
971
|
+
F,
|
|
977
972
|
{
|
|
978
973
|
text: r,
|
|
979
974
|
duration: 2.5,
|
|
@@ -981,10 +976,10 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
981
976
|
color: "#999",
|
|
982
977
|
shimmerColor: "#000"
|
|
983
978
|
}
|
|
984
|
-
) : /* @__PURE__ */
|
|
979
|
+
) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: r })
|
|
985
980
|
}
|
|
986
981
|
),
|
|
987
|
-
t !== void 0 && /* @__PURE__ */
|
|
982
|
+
t !== void 0 && /* @__PURE__ */ k(
|
|
988
983
|
"div",
|
|
989
984
|
{
|
|
990
985
|
style: {
|
|
@@ -1001,8 +996,8 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
1001
996
|
}
|
|
1002
997
|
)
|
|
1003
998
|
] });
|
|
1004
|
-
},
|
|
1005
|
-
/* @__PURE__ */
|
|
999
|
+
}, we = ({ data: e, onSourceClick: t }) => /* @__PURE__ */ k("div", { style: { padding: "16px" }, children: [
|
|
1000
|
+
/* @__PURE__ */ i(
|
|
1006
1001
|
v.div,
|
|
1007
1002
|
{
|
|
1008
1003
|
style: {
|
|
@@ -1019,8 +1014,8 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
1019
1014
|
children: "Sources"
|
|
1020
1015
|
}
|
|
1021
1016
|
),
|
|
1022
|
-
/* @__PURE__ */
|
|
1023
|
-
|
|
1017
|
+
/* @__PURE__ */ i("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: e.sources.length === 0 ? /* @__PURE__ */ i("span", { style: { fontSize: "13px", color: "#888" }, children: "No sources" }) : e.sources.map((r, n) => /* @__PURE__ */ i(
|
|
1018
|
+
Ie,
|
|
1024
1019
|
{
|
|
1025
1020
|
source: r,
|
|
1026
1021
|
index: n,
|
|
@@ -1029,7 +1024,7 @@ const ye = ({ progressViewItems: e }) => {
|
|
|
1029
1024
|
r.memoryId
|
|
1030
1025
|
)) })
|
|
1031
1026
|
] });
|
|
1032
|
-
function
|
|
1027
|
+
function pe(e) {
|
|
1033
1028
|
if (e.length === 0) return "";
|
|
1034
1029
|
if (e.length === 1) return `page ${e[0]}`;
|
|
1035
1030
|
if (e.length === 2)
|
|
@@ -1037,17 +1032,17 @@ function be(e) {
|
|
|
1037
1032
|
const t = e[e.length - 1];
|
|
1038
1033
|
return `pages ${e.slice(0, -1).join(", ")} and ${t}`;
|
|
1039
1034
|
}
|
|
1040
|
-
const
|
|
1041
|
-
const [n,
|
|
1042
|
-
return /* @__PURE__ */
|
|
1035
|
+
const Ie = ({ source: e, index: t, onSourceClick: r }) => {
|
|
1036
|
+
const [n, l] = w(!1), u = !!r, s = e.pageNumbers ?? [], c = pe(s);
|
|
1037
|
+
return /* @__PURE__ */ k(
|
|
1043
1038
|
v.div,
|
|
1044
1039
|
{
|
|
1045
1040
|
initial: { opacity: 0, scale: 0.9 },
|
|
1046
1041
|
animate: { opacity: 1, scale: 1 },
|
|
1047
1042
|
transition: { duration: 0.25, delay: t * 0.05 },
|
|
1048
|
-
onClick:
|
|
1049
|
-
onMouseEnter:
|
|
1050
|
-
onMouseLeave:
|
|
1043
|
+
onClick: u ? () => r(e.memoryId) : void 0,
|
|
1044
|
+
onMouseEnter: u ? () => l(!0) : void 0,
|
|
1045
|
+
onMouseLeave: u ? () => l(!1) : void 0,
|
|
1051
1046
|
style: {
|
|
1052
1047
|
display: "inline-flex",
|
|
1053
1048
|
flexDirection: "column",
|
|
@@ -1056,28 +1051,28 @@ const Ce = ({ source: e, index: t, onSourceClick: r }) => {
|
|
|
1056
1051
|
borderRadius: "6px",
|
|
1057
1052
|
border: "1px solid #e0e0e0",
|
|
1058
1053
|
backgroundColor: n ? "#f5f5f5" : "transparent",
|
|
1059
|
-
cursor:
|
|
1054
|
+
cursor: u ? "pointer" : "default",
|
|
1060
1055
|
transition: "background-color 0.15s ease",
|
|
1061
1056
|
userSelect: "none"
|
|
1062
1057
|
},
|
|
1063
1058
|
children: [
|
|
1064
|
-
/* @__PURE__ */
|
|
1065
|
-
|
|
1059
|
+
/* @__PURE__ */ i("span", { style: { fontSize: "13px", fontWeight: 500, color: "#333" }, children: e.memoryTitle }),
|
|
1060
|
+
c && /* @__PURE__ */ i("span", { style: { fontSize: "12px", color: "#666" }, children: c })
|
|
1066
1061
|
]
|
|
1067
1062
|
}
|
|
1068
1063
|
);
|
|
1069
1064
|
};
|
|
1070
|
-
function
|
|
1065
|
+
function Ee({
|
|
1071
1066
|
eventType: e,
|
|
1072
1067
|
completed: t
|
|
1073
1068
|
}) {
|
|
1074
|
-
return e === "ExploreMemoryError" ? /* @__PURE__ */
|
|
1069
|
+
return e === "ExploreMemoryError" ? /* @__PURE__ */ i("span", { style: { color: "#c62828", fontSize: 14, fontWeight: 600 }, children: "✗" }) : e === "ExploreMemoryResult" ? /* @__PURE__ */ i("span", { style: { color: "#999", fontSize: 14, fontWeight: 600 }, children: "✓" }) : e === "ExploreMemoryStart" && t ? /* @__PURE__ */ i("span", { style: { color: "#999", fontSize: 14, fontWeight: 600 }, children: "✓" }) : null;
|
|
1075
1070
|
}
|
|
1076
|
-
const
|
|
1077
|
-
const [n,
|
|
1071
|
+
const B = 80, Ae = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
1072
|
+
const [n, l] = w(!1), u = e.eventType === "ExploreMemoryResult" ? e.result : void 0, s = u != null && u.length > B, c = u != null ? n || !s ? u : `${u.slice(0, B)}...` : void 0, d = s;
|
|
1078
1073
|
if (e.eventType === "ExploreMemoryStart" && !t) {
|
|
1079
|
-
const
|
|
1080
|
-
return /* @__PURE__ */
|
|
1074
|
+
const o = `Exploring ${e.memoryTitle}...`;
|
|
1075
|
+
return /* @__PURE__ */ i(
|
|
1081
1076
|
"div",
|
|
1082
1077
|
{
|
|
1083
1078
|
style: {
|
|
@@ -1085,26 +1080,26 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1085
1080
|
display: "flex",
|
|
1086
1081
|
alignItems: "center"
|
|
1087
1082
|
},
|
|
1088
|
-
children: r ? /* @__PURE__ */
|
|
1089
|
-
|
|
1083
|
+
children: r ? /* @__PURE__ */ i(
|
|
1084
|
+
F,
|
|
1090
1085
|
{
|
|
1091
|
-
text:
|
|
1086
|
+
text: o,
|
|
1092
1087
|
duration: 2.5,
|
|
1093
1088
|
repeat: !0,
|
|
1094
1089
|
color: "#999",
|
|
1095
1090
|
shimmerColor: "#000"
|
|
1096
1091
|
}
|
|
1097
|
-
) : /* @__PURE__ */
|
|
1092
|
+
) : /* @__PURE__ */ i("span", { style: { fontSize: 13, color: "#999" }, children: o })
|
|
1098
1093
|
}
|
|
1099
1094
|
);
|
|
1100
1095
|
}
|
|
1101
|
-
return /* @__PURE__ */
|
|
1096
|
+
return /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ k(
|
|
1102
1097
|
v.div,
|
|
1103
1098
|
{
|
|
1104
1099
|
initial: { opacity: 0 },
|
|
1105
1100
|
animate: { opacity: 1 },
|
|
1106
1101
|
transition: { duration: 0.25 },
|
|
1107
|
-
onClick: d ? () =>
|
|
1102
|
+
onClick: d ? () => l((o) => !o) : void 0,
|
|
1108
1103
|
style: {
|
|
1109
1104
|
paddingBottom: "12px",
|
|
1110
1105
|
borderBottom: "1px solid #eee",
|
|
@@ -1116,7 +1111,7 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1116
1111
|
cursor: d ? "pointer" : "default"
|
|
1117
1112
|
},
|
|
1118
1113
|
children: [
|
|
1119
|
-
/* @__PURE__ */
|
|
1114
|
+
/* @__PURE__ */ i(
|
|
1120
1115
|
"div",
|
|
1121
1116
|
{
|
|
1122
1117
|
style: {
|
|
@@ -1126,10 +1121,10 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1126
1121
|
flexShrink: 0,
|
|
1127
1122
|
width: 20
|
|
1128
1123
|
},
|
|
1129
|
-
children: /* @__PURE__ */
|
|
1124
|
+
children: /* @__PURE__ */ i(Ee, { eventType: e.eventType, completed: t })
|
|
1130
1125
|
}
|
|
1131
1126
|
),
|
|
1132
|
-
/* @__PURE__ */
|
|
1127
|
+
/* @__PURE__ */ k(
|
|
1133
1128
|
"div",
|
|
1134
1129
|
{
|
|
1135
1130
|
style: {
|
|
@@ -1139,8 +1134,8 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1139
1134
|
minWidth: 0
|
|
1140
1135
|
},
|
|
1141
1136
|
children: [
|
|
1142
|
-
/* @__PURE__ */
|
|
1143
|
-
|
|
1137
|
+
/* @__PURE__ */ i("span", { style: { fontSize: 13, fontWeight: 500, color: "#333" }, children: e.memoryTitle }),
|
|
1138
|
+
c != null && /* @__PURE__ */ i(
|
|
1144
1139
|
"span",
|
|
1145
1140
|
{
|
|
1146
1141
|
style: {
|
|
@@ -1149,10 +1144,10 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1149
1144
|
lineHeight: 1.4,
|
|
1150
1145
|
whiteSpace: n ? "pre-wrap" : void 0
|
|
1151
1146
|
},
|
|
1152
|
-
children:
|
|
1147
|
+
children: c
|
|
1153
1148
|
}
|
|
1154
1149
|
),
|
|
1155
|
-
d && /* @__PURE__ */
|
|
1150
|
+
d && /* @__PURE__ */ i(
|
|
1156
1151
|
"span",
|
|
1157
1152
|
{
|
|
1158
1153
|
style: {
|
|
@@ -1169,62 +1164,62 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1169
1164
|
]
|
|
1170
1165
|
}
|
|
1171
1166
|
) });
|
|
1172
|
-
},
|
|
1167
|
+
}, Me = ({
|
|
1173
1168
|
progressViewItems: e,
|
|
1174
1169
|
streamToken: t,
|
|
1175
1170
|
fetchClientToken: r,
|
|
1176
1171
|
loadingText: n,
|
|
1177
|
-
onSourceClick:
|
|
1172
|
+
onSourceClick: l
|
|
1178
1173
|
}) => {
|
|
1179
|
-
const
|
|
1174
|
+
const u = A(null);
|
|
1180
1175
|
E(() => {
|
|
1181
|
-
|
|
1176
|
+
u.current && (u.current.scrollTop = u.current.scrollHeight);
|
|
1182
1177
|
}, [e.length]);
|
|
1183
|
-
const s = (
|
|
1184
|
-
const d =
|
|
1178
|
+
const s = (c) => {
|
|
1179
|
+
const d = c.item.data;
|
|
1185
1180
|
if (d.taskType === "StreamingChatCompletion" && d.eventType === "Text")
|
|
1186
|
-
return /* @__PURE__ */
|
|
1181
|
+
return /* @__PURE__ */ i(z, { text: d.text });
|
|
1187
1182
|
if (d.taskType === "StructuredChatCompletion" && d.eventType === "Json")
|
|
1188
|
-
return /* @__PURE__ */
|
|
1183
|
+
return /* @__PURE__ */ i(ve, { data: d });
|
|
1189
1184
|
if (d.taskType === "StreamingMemoryTypeChatCompletion")
|
|
1190
1185
|
switch (d.eventType) {
|
|
1191
1186
|
case "Text":
|
|
1192
|
-
return /* @__PURE__ */
|
|
1187
|
+
return /* @__PURE__ */ i(z, { text: d.text });
|
|
1193
1188
|
case "Search":
|
|
1194
|
-
return /* @__PURE__ */
|
|
1195
|
-
|
|
1189
|
+
return /* @__PURE__ */ i(
|
|
1190
|
+
ke,
|
|
1196
1191
|
{
|
|
1197
1192
|
data: d,
|
|
1198
|
-
isLatest:
|
|
1199
|
-
durationSeconds:
|
|
1193
|
+
isLatest: c.isLatest,
|
|
1194
|
+
durationSeconds: c.durationSeconds
|
|
1200
1195
|
}
|
|
1201
1196
|
);
|
|
1202
1197
|
case "FindSources":
|
|
1203
|
-
return /* @__PURE__ */
|
|
1204
|
-
|
|
1198
|
+
return /* @__PURE__ */ i(
|
|
1199
|
+
xe,
|
|
1205
1200
|
{
|
|
1206
1201
|
data: d,
|
|
1207
|
-
isLatest:
|
|
1208
|
-
durationSeconds:
|
|
1202
|
+
isLatest: c.isLatest,
|
|
1203
|
+
durationSeconds: c.durationSeconds
|
|
1209
1204
|
}
|
|
1210
1205
|
);
|
|
1211
1206
|
case "SourcesResult":
|
|
1212
|
-
return /* @__PURE__ */
|
|
1213
|
-
|
|
1207
|
+
return /* @__PURE__ */ i(
|
|
1208
|
+
we,
|
|
1214
1209
|
{
|
|
1215
1210
|
data: d,
|
|
1216
|
-
onSourceClick:
|
|
1211
|
+
onSourceClick: l
|
|
1217
1212
|
}
|
|
1218
1213
|
);
|
|
1219
1214
|
case "ExploreMemoryStart":
|
|
1220
1215
|
case "ExploreMemoryResult":
|
|
1221
1216
|
case "ExploreMemoryError":
|
|
1222
|
-
return /* @__PURE__ */
|
|
1223
|
-
|
|
1217
|
+
return /* @__PURE__ */ i(
|
|
1218
|
+
Ae,
|
|
1224
1219
|
{
|
|
1225
1220
|
data: d,
|
|
1226
|
-
completed:
|
|
1227
|
-
isLatest:
|
|
1221
|
+
completed: c.completed,
|
|
1222
|
+
isLatest: c.isLatest
|
|
1228
1223
|
}
|
|
1229
1224
|
);
|
|
1230
1225
|
case "Completed":
|
|
@@ -1232,8 +1227,8 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1232
1227
|
}
|
|
1233
1228
|
return d.taskType === "StreamingChatCompletion" && d.eventType === "Completed" || d.taskType === "StructuredChatCompletion" && d.eventType === "Completed", null;
|
|
1234
1229
|
};
|
|
1235
|
-
return e.length === 0 ? /* @__PURE__ */
|
|
1236
|
-
|
|
1230
|
+
return e.length === 0 ? /* @__PURE__ */ i("div", { style: { width: "fit-content" }, children: /* @__PURE__ */ i(
|
|
1231
|
+
F,
|
|
1237
1232
|
{
|
|
1238
1233
|
text: n ?? "Processing your task...",
|
|
1239
1234
|
duration: 1.5,
|
|
@@ -1242,10 +1237,10 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1242
1237
|
color: "#999",
|
|
1243
1238
|
shimmerColor: "#000"
|
|
1244
1239
|
}
|
|
1245
|
-
) }) : /* @__PURE__ */
|
|
1240
|
+
) }) : /* @__PURE__ */ i("div", { id: "agent-task-progress-verbose", ref: u, children: /* @__PURE__ */ i(L, { children: e.map((c, d) => /* @__PURE__ */ i(
|
|
1246
1241
|
v.div,
|
|
1247
1242
|
{
|
|
1248
|
-
id: `agent-task-progress-item-${
|
|
1243
|
+
id: `agent-task-progress-item-${c.item.progressItemId}`,
|
|
1249
1244
|
initial: { opacity: 0, y: -20 },
|
|
1250
1245
|
animate: { opacity: 1, y: 0 },
|
|
1251
1246
|
transition: {
|
|
@@ -1253,186 +1248,31 @@ const z = 80, ve = ({ data: e, completed: t, isLatest: r = !1 }) => {
|
|
|
1253
1248
|
delay: d * 0.1,
|
|
1254
1249
|
ease: "easeOut"
|
|
1255
1250
|
},
|
|
1256
|
-
children: s(
|
|
1251
|
+
children: s(c)
|
|
1257
1252
|
},
|
|
1258
|
-
|
|
1253
|
+
c.item.progressItemId
|
|
1259
1254
|
)) }) });
|
|
1260
|
-
},
|
|
1255
|
+
}, Le = ({
|
|
1261
1256
|
agentTask: e,
|
|
1262
1257
|
mode: t = "verbose",
|
|
1263
1258
|
streamToken: r,
|
|
1264
1259
|
fetchClientToken: n,
|
|
1265
|
-
onSourceClick:
|
|
1260
|
+
onSourceClick: l
|
|
1266
1261
|
}) => {
|
|
1267
|
-
const
|
|
1268
|
-
return t === "simple" ? /* @__PURE__ */
|
|
1269
|
-
|
|
1262
|
+
const u = be(e);
|
|
1263
|
+
return t === "simple" ? /* @__PURE__ */ i(Te, { progressViewItems: u }) : /* @__PURE__ */ i(
|
|
1264
|
+
Me,
|
|
1270
1265
|
{
|
|
1271
|
-
progressViewItems:
|
|
1266
|
+
progressViewItems: u,
|
|
1272
1267
|
streamToken: r,
|
|
1273
1268
|
fetchClientToken: n,
|
|
1274
1269
|
loadingText: e.loadingText,
|
|
1275
|
-
onSourceClick:
|
|
1270
|
+
onSourceClick: l
|
|
1276
1271
|
}
|
|
1277
1272
|
);
|
|
1278
1273
|
};
|
|
1279
|
-
class we {
|
|
1280
|
-
constructor(t) {
|
|
1281
|
-
this.eventSources = /* @__PURE__ */ new Map(), this.subscribers = /* @__PURE__ */ new Map(), this.fency = t;
|
|
1282
|
-
}
|
|
1283
|
-
/**
|
|
1284
|
-
* Called by FencyProvider when activeStreams changes.
|
|
1285
|
-
* Creates new connections and removes old ones.
|
|
1286
|
-
*/
|
|
1287
|
-
updateStreams(t) {
|
|
1288
|
-
t.forEach((n) => {
|
|
1289
|
-
const o = n.stream.id;
|
|
1290
|
-
this.eventSources.has(o) || this.connectStream(n);
|
|
1291
|
-
});
|
|
1292
|
-
const r = new Set(t.map((n) => n.stream.id));
|
|
1293
|
-
this.eventSources.forEach((n, o) => {
|
|
1294
|
-
r.has(o) || (n.abort(), this.eventSources.delete(o));
|
|
1295
|
-
});
|
|
1296
|
-
}
|
|
1297
|
-
connectStream(t) {
|
|
1298
|
-
const r = t.stream.id, n = new AbortController();
|
|
1299
|
-
this.eventSources.set(r, n);
|
|
1300
|
-
const o = `${this.fency.baseUrl}/sse/streams/${r}`, m = {
|
|
1301
|
-
"X-Fency-Publishable-Key": this.fency.publishableKey,
|
|
1302
|
-
"X-Fency-Stream-Token": t.stream.token
|
|
1303
|
-
};
|
|
1304
|
-
j(o, {
|
|
1305
|
-
headers: m,
|
|
1306
|
-
signal: n.signal,
|
|
1307
|
-
async onopen(s) {
|
|
1308
|
-
if (!s.ok && s.status >= 400 && s.status < 500 && s.status !== 429)
|
|
1309
|
-
throw new Error(`Client error ${s.status}`);
|
|
1310
|
-
},
|
|
1311
|
-
onmessage: (s) => {
|
|
1312
|
-
if (s.data) {
|
|
1313
|
-
const l = H(s.data);
|
|
1314
|
-
this.broadcast(l, r);
|
|
1315
|
-
}
|
|
1316
|
-
},
|
|
1317
|
-
onerror: (s) => {
|
|
1318
|
-
throw console.error("EventSource error for stream", r, ":", s), this.broadcastError(r), s;
|
|
1319
|
-
},
|
|
1320
|
-
onclose() {
|
|
1321
|
-
}
|
|
1322
|
-
});
|
|
1323
|
-
}
|
|
1324
|
-
/**
|
|
1325
|
-
* Subscribe to events from all active streams.
|
|
1326
|
-
* Returns an unsubscribe function.
|
|
1327
|
-
*/
|
|
1328
|
-
subscribe(t, r) {
|
|
1329
|
-
return this.subscribers.set(t, r), () => {
|
|
1330
|
-
this.subscribers.delete(t);
|
|
1331
|
-
};
|
|
1332
|
-
}
|
|
1333
|
-
broadcast(t, r) {
|
|
1334
|
-
this.subscribers.forEach((n) => {
|
|
1335
|
-
n.onMessage(t, r);
|
|
1336
|
-
});
|
|
1337
|
-
}
|
|
1338
|
-
broadcastError(t) {
|
|
1339
|
-
this.subscribers.forEach((r) => {
|
|
1340
|
-
r.onError(t);
|
|
1341
|
-
});
|
|
1342
|
-
}
|
|
1343
|
-
/**
|
|
1344
|
-
* Cleanup all connections and subscriptions
|
|
1345
|
-
*/
|
|
1346
|
-
cleanup() {
|
|
1347
|
-
this.eventSources.forEach((t) => t.abort()), this.eventSources.clear(), this.subscribers.clear();
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
const Ee = 12e4, Ie = (e) => {
|
|
1351
|
-
const t = Date.now();
|
|
1352
|
-
return e.filter((r) => t - r.createdAt < Ee);
|
|
1353
|
-
};
|
|
1354
|
-
function We({ fency: e, fetchCreateStreamClientToken: t, children: r }) {
|
|
1355
|
-
const [n, o] = C(
|
|
1356
|
-
null
|
|
1357
|
-
), [m, s] = C(!0), [l, d] = C(null), [a, i] = C([]), g = A(null), u = A(null);
|
|
1358
|
-
E(() => {
|
|
1359
|
-
e.then((f) => {
|
|
1360
|
-
o(f), s(!1);
|
|
1361
|
-
}).catch((f) => {
|
|
1362
|
-
d(f), s(!1);
|
|
1363
|
-
});
|
|
1364
|
-
}, [e]), E(() => {
|
|
1365
|
-
n && !u.current && (u.current = new we(n));
|
|
1366
|
-
}, [n]), E(() => {
|
|
1367
|
-
u.current && u.current.updateStreams(a);
|
|
1368
|
-
}, [a]), E(() => () => {
|
|
1369
|
-
var f;
|
|
1370
|
-
(f = u.current) == null || f.cleanup();
|
|
1371
|
-
}, []);
|
|
1372
|
-
const S = W(
|
|
1373
|
-
async (f = 3e4) => {
|
|
1374
|
-
if (g.current)
|
|
1375
|
-
return g.current;
|
|
1376
|
-
const h = Date.now(), b = a.length > 0 ? a[a.length - 1] : null;
|
|
1377
|
-
if (b && h - b.createdAt < f)
|
|
1378
|
-
return b.stream;
|
|
1379
|
-
const I = (async () => {
|
|
1380
|
-
if (!n)
|
|
1381
|
-
throw new Error("Fency instance not initialized");
|
|
1382
|
-
const w = await t(), p = await J({
|
|
1383
|
-
pk: n.publishableKey,
|
|
1384
|
-
baseUrl: n.baseUrl,
|
|
1385
|
-
clientToken: (w == null ? void 0 : w.clientToken) ?? ""
|
|
1386
|
-
});
|
|
1387
|
-
if (p.type === "success") {
|
|
1388
|
-
const M = {
|
|
1389
|
-
stream: p.stream,
|
|
1390
|
-
createdAt: Date.now()
|
|
1391
|
-
};
|
|
1392
|
-
return i((P) => {
|
|
1393
|
-
const k = [...P, M];
|
|
1394
|
-
return Ie(k);
|
|
1395
|
-
}), g.current = null, p.stream;
|
|
1396
|
-
} else
|
|
1397
|
-
throw g.current = null, new Error("Failed to create stream");
|
|
1398
|
-
})();
|
|
1399
|
-
return g.current = I, I;
|
|
1400
|
-
},
|
|
1401
|
-
[n, a]
|
|
1402
|
-
);
|
|
1403
|
-
if (l)
|
|
1404
|
-
return /* @__PURE__ */ x("div", { children: [
|
|
1405
|
-
"Fency error: ",
|
|
1406
|
-
l.message
|
|
1407
|
-
] });
|
|
1408
|
-
if (!n)
|
|
1409
|
-
return null;
|
|
1410
|
-
const y = a.length > 0 ? a[a.length - 1] : null, T = {
|
|
1411
|
-
fency: n,
|
|
1412
|
-
loading: m,
|
|
1413
|
-
error: l,
|
|
1414
|
-
activeStreams: a,
|
|
1415
|
-
latestStream: y,
|
|
1416
|
-
eventManager: u.current,
|
|
1417
|
-
getOrCreateStream: S
|
|
1418
|
-
};
|
|
1419
|
-
return /* @__PURE__ */ c(_.Provider, { value: T, children: r });
|
|
1420
|
-
}
|
|
1421
1274
|
export {
|
|
1422
|
-
|
|
1423
|
-
ye as AgentTaskProgressSimple,
|
|
1424
|
-
xe as AgentTaskProgressVerbose,
|
|
1275
|
+
Le as AgentTaskProgress,
|
|
1425
1276
|
We as FencyProvider,
|
|
1426
|
-
|
|
1427
|
-
U as StreamingChatCompletionText,
|
|
1428
|
-
ve as StreamingMemoryTypeChatCompletionExploreMemory,
|
|
1429
|
-
Se as StreamingMemoryTypeChatCompletionFindSources,
|
|
1430
|
-
he as StreamingMemoryTypeChatCompletionSearch,
|
|
1431
|
-
Te as StreamingMemoryTypeChatCompletionSourcesResult,
|
|
1432
|
-
fe as StructuredChatCompletionJson,
|
|
1433
|
-
Oe as useAgentTasks,
|
|
1434
|
-
N as useFencyContext,
|
|
1435
|
-
De as useFencyEventSource,
|
|
1436
|
-
Ue as usePaginatedQuery,
|
|
1437
|
-
ae as useStream
|
|
1277
|
+
Ue as useAgentTasks
|
|
1438
1278
|
};
|