@fencyai/react 0.1.107 → 0.1.109

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.
Files changed (50) hide show
  1. package/dist/assets/index.css +1 -1
  2. package/dist/chat/AgentTaskProgress.d.ts +3 -2
  3. package/dist/chat/ChatResponse.d.ts +3 -2
  4. package/dist/chat/ChatResponseComplete.d.ts +3 -2
  5. package/dist/hooks/useFencyEventSource/index.d.ts +1 -0
  6. package/dist/hooks/usePaginatedQuery/index.d.ts +10 -4
  7. package/dist/index.d.ts +1 -5
  8. package/dist/index.js +559 -1201
  9. package/dist/types/FencyContext.d.ts +3 -2
  10. package/dist/types/UseAgentTasksProps.d.ts +5 -4
  11. package/dist/types/UseStreamProps.d.ts +3 -2
  12. package/dist/types/index.d.ts +0 -24
  13. package/package.json +7 -4
  14. package/dist/chat/Chat.d.ts +0 -20
  15. package/dist/chat/MentionCategory.d.ts +0 -5
  16. package/dist/chat/MentionInput.d.ts +0 -24
  17. package/dist/chat/MentionOption.d.ts +0 -5
  18. package/dist/chat/MentionPopover.d.ts +0 -14
  19. package/dist/chat/hooks/useKeyboardNavigation.d.ts +0 -10
  20. package/dist/hooks/useListMemoryTypes/index.d.ts +0 -2
  21. package/dist/hooks/useSearchMemories/index.d.ts +0 -2
  22. package/dist/types/AiModel.d.ts +0 -2
  23. package/dist/types/BasicChatCompletion.d.ts +0 -8
  24. package/dist/types/BasicChatCompletionData.d.ts +0 -5
  25. package/dist/types/BasicChatCompletionResponse.d.ts +0 -9
  26. package/dist/types/CreateBasicChatCompletionParams.d.ts +0 -10
  27. package/dist/types/CreateClaudeChatCompletionParams.d.ts +0 -9
  28. package/dist/types/CreateGeminiChatCompletionParams.d.ts +0 -9
  29. package/dist/types/CreateGenericChatCompletionParams.d.ts +0 -14
  30. package/dist/types/CreateOpenAiChatCompletionParams.d.ts +0 -7
  31. package/dist/types/CreateStreamingChatCompletionParams.d.ts +0 -10
  32. package/dist/types/CreateStreamingChatCompletionResponse.d.ts +0 -9
  33. package/dist/types/CreateStructuredChatCompletionParams.d.ts +0 -12
  34. package/dist/types/ListMemoryTypesPage.d.ts +0 -7
  35. package/dist/types/ListMemoryTypesParams.d.ts +0 -5
  36. package/dist/types/ListMemoryTypesResult.d.ts +0 -9
  37. package/dist/types/SearchMemoriesParams.d.ts +0 -7
  38. package/dist/types/SearchMemoriesResult.d.ts +0 -8
  39. package/dist/types/StreamingChatCompletion.d.ts +0 -23
  40. package/dist/types/StreamingChatCompletionData.d.ts +0 -5
  41. package/dist/types/StructuredChatCompletion.d.ts +0 -9
  42. package/dist/types/StructuredChatCompletionData.d.ts +0 -7
  43. package/dist/types/StructuredChatCompletionResponse.d.ts +0 -10
  44. package/dist/types/UseBasicChatCompletions.d.ts +0 -8
  45. package/dist/types/UseListMemoryTypes.d.ts +0 -10
  46. package/dist/types/UseListMemoryTypesProps.d.ts +0 -3
  47. package/dist/types/UseSearchMemories.d.ts +0 -5
  48. package/dist/types/UseStreamingChatCompletions.d.ts +0 -8
  49. package/dist/types/UseStreamingChatCompletionsProps.d.ts +0 -12
  50. package/dist/types/UseStructuredChatCompletions.d.ts +0 -9
package/dist/index.js CHANGED
@@ -1,106 +1,212 @@
1
- import { createAgentTask as ke, searchMemories as Ae, listMemoryTypes as Pe, createFileDownloadLink as Ee, AgentTaskProgressItemType as ee, createStream as Ne } from "@fencyai/js";
2
- import { createContext as Me, useContext as _e, useState as x, useEffect as N, useCallback as I, useMemo as G, useRef as _, useLayoutEffect as pe } from "react";
3
- import { jsxs as A, jsx as f, Fragment as fe } from "react/jsx-runtime";
4
- import { motion as $, useInView as Fe, AnimatePresence as ye } from "motion/react";
5
- import be from "react-markdown";
6
- import { Prism as Ce } from "react-syntax-highlighter";
7
- import Se from "remark-gfm";
8
- import * as Z from "@radix-ui/react-popover";
9
- import './assets/index.css';const we = Me(
1
+ import { createAgentTask as q, createFileDownloadLink as G, AgentTaskProgressItemType as O, createStream as V } from "@fencyai/js";
2
+ import { createContext as X, useContext as Y, useState as T, useEffect as x, useMemo as B, useCallback as D, useRef as F } from "react";
3
+ import { jsxs as I, jsx as g } from "react/jsx-runtime";
4
+ import { motion as C, useInView as J, AnimatePresence as _ } from "motion/react";
5
+ import W from "react-markdown";
6
+ import { Prism as j } from "react-syntax-highlighter";
7
+ import L from "remark-gfm";
8
+ import './assets/index.css';const $ = X(
10
9
  void 0
11
10
  );
12
- function H() {
13
- const e = _e(we);
11
+ function R() {
12
+ const e = Y($);
14
13
  if (e === void 0)
15
14
  throw new Error("useFencyContext must be used within a FencyProvider");
16
15
  return e;
17
16
  }
18
- function Re(e) {
19
- const [a, s] = x(null);
20
- return N(() => {
21
- if (!a)
17
+ async function Q(e, t) {
18
+ const o = e.getReader();
19
+ let i;
20
+ for (; !(i = await o.read()).done; )
21
+ t(i.value);
22
+ }
23
+ function Z(e) {
24
+ let t, o, i, s = !1;
25
+ return function(u) {
26
+ t === void 0 ? (t = u, o = 0, i = -1) : t = ee(t, u);
27
+ const a = t.length;
28
+ let n = 0;
29
+ for (; o < a; ) {
30
+ s && (t[o] === 10 && (n = ++o), s = !1);
31
+ let d = -1;
32
+ for (; o < a && d === -1; ++o)
33
+ switch (t[o]) {
34
+ case 58:
35
+ i === -1 && (i = o - n);
36
+ break;
37
+ case 13:
38
+ s = !0;
39
+ case 10:
40
+ d = o;
41
+ break;
42
+ }
43
+ if (d === -1)
44
+ break;
45
+ e(t.subarray(n, d), i), n = o, i = -1;
46
+ }
47
+ n === a ? t = void 0 : n !== 0 && (t = t.subarray(n), o -= n);
48
+ };
49
+ }
50
+ function p(e, t, o) {
51
+ let i = z();
52
+ const s = new TextDecoder();
53
+ return function(u, a) {
54
+ if (u.length === 0)
55
+ o == null || o(i), i = z();
56
+ else if (a > 0) {
57
+ const n = s.decode(u.subarray(0, a)), d = a + (u[a + 1] === 32 ? 2 : 1), l = s.decode(u.subarray(d));
58
+ switch (n) {
59
+ case "data":
60
+ i.data = i.data ? i.data + `
61
+ ` + l : l;
62
+ break;
63
+ case "event":
64
+ i.event = l;
65
+ break;
66
+ case "id":
67
+ e(i.id = l);
68
+ break;
69
+ case "retry":
70
+ const c = parseInt(l, 10);
71
+ isNaN(c) || t(i.retry = c);
72
+ break;
73
+ }
74
+ }
75
+ };
76
+ }
77
+ function ee(e, t) {
78
+ const o = new Uint8Array(e.length + t.length);
79
+ return o.set(e), o.set(t, e.length), o;
80
+ }
81
+ function z() {
82
+ return {
83
+ data: "",
84
+ event: "",
85
+ id: "",
86
+ retry: void 0
87
+ };
88
+ }
89
+ var te = function(e, t) {
90
+ var o = {};
91
+ for (var i in e) Object.prototype.hasOwnProperty.call(e, i) && t.indexOf(i) < 0 && (o[i] = e[i]);
92
+ if (e != null && typeof Object.getOwnPropertySymbols == "function")
93
+ for (var s = 0, i = Object.getOwnPropertySymbols(e); s < i.length; s++)
94
+ t.indexOf(i[s]) < 0 && Object.prototype.propertyIsEnumerable.call(e, i[s]) && (o[i[s]] = e[i[s]]);
95
+ return o;
96
+ };
97
+ const U = "text/event-stream", ne = 1e3, H = "last-event-id";
98
+ function re(e, t) {
99
+ var { signal: o, headers: i, onopen: s, onmessage: m, onclose: u, onerror: a, openWhenHidden: n, fetch: d } = t, l = te(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
100
+ return new Promise((c, r) => {
101
+ const f = Object.assign({}, i);
102
+ f.accept || (f.accept = U);
103
+ let h;
104
+ function b() {
105
+ h.abort(), document.hidden || A();
106
+ }
107
+ n || document.addEventListener("visibilitychange", b);
108
+ let w = ne, y = 0;
109
+ function k() {
110
+ document.removeEventListener("visibilitychange", b), window.clearTimeout(y), h.abort();
111
+ }
112
+ o == null || o.addEventListener("abort", () => {
113
+ k(), c();
114
+ });
115
+ const v = d ?? window.fetch, E = s ?? oe;
116
+ async function A() {
117
+ var P;
118
+ h = new AbortController();
119
+ try {
120
+ const N = await v(e, Object.assign(Object.assign({}, l), { headers: f, signal: h.signal }));
121
+ await E(N), await Q(N.body, Z(p((S) => {
122
+ S ? f[H] = S : delete f[H];
123
+ }, (S) => {
124
+ w = S;
125
+ }, m))), u == null || u(), k(), c();
126
+ } catch (N) {
127
+ if (!h.signal.aborted)
128
+ try {
129
+ const S = (P = a == null ? void 0 : a(N)) !== null && P !== void 0 ? P : w;
130
+ window.clearTimeout(y), y = window.setTimeout(A, S);
131
+ } catch (S) {
132
+ k(), r(S);
133
+ }
134
+ }
135
+ }
136
+ A();
137
+ });
138
+ }
139
+ function oe(e) {
140
+ const t = e.headers.get("content-type");
141
+ if (!(t != null && t.startsWith(U)))
142
+ throw new Error(`Expected content-type to be ${U}, Actual: ${t}`);
143
+ }
144
+ function ae(e) {
145
+ const [t, o] = T(null);
146
+ return x(() => {
147
+ if (!t)
22
148
  return;
23
- const c = new EventSource(a);
24
- return c.onmessage = (i) => {
25
- e == null || e.onMessage({
26
- url: a,
27
- data: Oe(i.data)
28
- });
29
- }, c.onerror = (i) => {
30
- console.error("EventSource error:", i), e == null || e.onError(a), s(null);
31
- }, () => {
32
- c.close();
149
+ const i = new AbortController();
150
+ return re(t, {
151
+ headers: e == null ? void 0 : e.headers,
152
+ signal: i.signal,
153
+ async onopen(s) {
154
+ if (!s.ok && s.status >= 400 && s.status < 500 && s.status !== 429)
155
+ throw new Error(`Client error ${s.status}`);
156
+ },
157
+ onmessage(s) {
158
+ s.data && (e == null || e.onMessage({
159
+ url: t,
160
+ data: ie(s.data)
161
+ }));
162
+ },
163
+ onerror(s) {
164
+ throw console.error("EventSource error:", s), e == null || e.onError(t), o(null), s;
165
+ },
166
+ onclose() {
167
+ }
168
+ }), () => {
169
+ i.abort();
33
170
  };
34
- }, [a]), {
35
- setSourceUrl: s,
36
- sourceUrl: a
171
+ }, [t, e == null ? void 0 : e.headers]), {
172
+ setSourceUrl: o,
173
+ sourceUrl: t
37
174
  };
38
175
  }
39
- function Oe(e) {
40
- const a = atob(e), s = new Uint8Array(a.length);
41
- for (let c = 0; c < a.length; c++)
42
- s[c] = a.charCodeAt(c);
43
- return new TextDecoder("utf-8").decode(s);
176
+ function ie(e) {
177
+ const t = atob(e), o = new Uint8Array(t.length);
178
+ for (let i = 0; i < t.length; i++)
179
+ o[i] = t.charCodeAt(i);
180
+ return new TextDecoder("utf-8").decode(o);
44
181
  }
45
- const Ue = (e) => {
182
+ const se = (e) => {
46
183
  try {
47
- const a = JSON.parse(e);
48
- return De(a);
49
- } catch (a) {
50
- return console.error("Error parsing message:", a), null;
184
+ const t = JSON.parse(e);
185
+ return ce(t);
186
+ } catch (t) {
187
+ return console.error("Error parsing message:", t), null;
51
188
  }
52
- }, De = (e) => {
189
+ }, ce = (e) => {
53
190
  if (!(typeof e == "object" && e !== null && "type" in e && "streamId" in e && "timestamp" in e))
54
191
  return null;
55
192
  switch (e.type) {
56
- case "NewChatCompletionStreamChunk":
57
- return $e(e);
58
- case "ChatCompletionStreamCompleted":
59
- return We(e);
60
193
  case "StreamTimeout":
61
- return Be(e);
194
+ return le(e);
62
195
  case "StreamNotFound":
63
- return Le(e);
64
- case "FileUploadCompleted":
65
- return He(e);
66
- case "FileTextContentReady":
67
- return ze(e);
196
+ return de(e);
68
197
  case "AgentTaskProgressItemUpdated":
69
- return qe(e);
198
+ return ue(e);
70
199
  }
71
200
  return null;
72
- }, $e = (e) => ({
73
- type: "NewChatCompletionStreamChunk",
74
- streamId: e.streamId,
75
- chatCompletionId: e.chatCompletionId,
76
- timestamp: e.timestamp,
77
- content: e.content
78
- }), We = (e) => ({
79
- type: "ChatCompletionStreamCompleted",
80
- streamId: e.streamId,
81
- chatCompletionId: e.chatCompletionId,
82
- timestamp: e.timestamp
83
- }), Be = (e) => ({
201
+ }, le = (e) => ({
84
202
  type: "StreamTimeout",
85
203
  streamId: e.streamId,
86
204
  timestamp: e.timestamp
87
- }), Le = (e) => ({
205
+ }), de = (e) => ({
88
206
  type: "StreamNotFound",
89
207
  streamId: e.streamId,
90
208
  timestamp: e.timestamp
91
- }), He = (e) => ({
92
- type: "FileUploadCompleted",
93
- streamId: e.streamId,
94
- uploadId: e.fileId,
95
- fileId: e.fileId,
96
- timestamp: e.timestamp
97
- }), ze = (e) => ({
98
- type: "FileTextContentReady",
99
- streamId: e.streamId,
100
- fileId: e.fileId,
101
- textContent: e.textContent,
102
- timestamp: e.timestamp
103
- }), qe = (e) => ({
209
+ }), ue = (e) => ({
104
210
  type: "AgentTaskProgressItemUpdated",
105
211
  streamId: e.streamId,
106
212
  agentTaskId: e.agentTaskId,
@@ -110,168 +216,177 @@ const Ue = (e) => {
110
216
  completedAt: e.completedAt || void 0,
111
217
  response: e.response,
112
218
  progressItemType: e.progressItemType
113
- }), Ke = (e) => {
114
- const a = H(), [s, c] = x(null), i = Re({
115
- onError: (u) => {
116
- var t;
117
- console.error("Stream error:", u), (t = e == null ? void 0 : e.onStreamError) == null || t.call(e, {
118
- streamId: u,
219
+ }), me = (e) => {
220
+ const t = R(), [o, i] = T(null), [s, m] = T(null), [u, a] = T(null), n = B(() => {
221
+ if (s)
222
+ return {
223
+ "X-Fency-Publishable-Key": t.fency.publishableKey,
224
+ "X-Fency-Stream-Token": s
225
+ };
226
+ }, [s, t.fency.publishableKey]), d = ae({
227
+ headers: n,
228
+ onError: (c) => {
229
+ var r;
230
+ console.error("Stream error:", c), (r = e == null ? void 0 : e.onStreamError) == null || r.call(e, {
231
+ streamId: c,
119
232
  error: {
120
233
  code: "UnknownError",
121
234
  message: "Unknown error in useStream"
122
235
  }
123
236
  });
124
237
  },
125
- onMessage: (u) => {
126
- var n, h, m, r, o, l, g, p, C, y;
127
- const t = Ue(u.data);
128
- if (!t)
238
+ onMessage: (c) => {
239
+ var f, h, b, w, y, k, v, E, A, P;
240
+ const r = se(c.data);
241
+ if (!r)
129
242
  return !1;
130
- switch (t.type) {
243
+ switch (r.type) {
131
244
  case "NewChatCompletionStreamChunk":
132
- return (n = e == null ? void 0 : e.onNewChatCompletionStreamChunk) == null || n.call(e, t), !0;
245
+ return (f = e == null ? void 0 : e.onNewChatCompletionStreamChunk) == null || f.call(e, r), !0;
133
246
  case "ChatCompletionStreamCompleted":
134
- return (h = e == null ? void 0 : e.onChatCompletionStreamCompleted) == null || h.call(e, t), !0;
247
+ return (h = e == null ? void 0 : e.onChatCompletionStreamCompleted) == null || h.call(e, r), !0;
135
248
  case "StreamTimeout":
136
- return (m = e == null ? void 0 : e.onStreamTimeout) == null || m.call(e, t), !0;
249
+ return (b = e == null ? void 0 : e.onStreamTimeout) == null || b.call(e, r), !0;
137
250
  case "StreamNotFound":
138
- return (r = e == null ? void 0 : e.onStreamNotFound) == null || r.call(e, t), !0;
251
+ return (w = e == null ? void 0 : e.onStreamNotFound) == null || w.call(e, r), !0;
139
252
  case "FileUploadCompleted":
140
- return (o = e == null ? void 0 : e.onFileUploadCompleted) == null || o.call(e, t), !0;
253
+ return (y = e == null ? void 0 : e.onFileUploadCompleted) == null || y.call(e, r), !0;
141
254
  case "FileTextContentReady":
142
- return (l = e == null ? void 0 : e.onFileTextContentReady) == null || l.call(e, t), !0;
255
+ return (k = e == null ? void 0 : e.onFileTextContentReady) == null || k.call(e, r), !0;
143
256
  case "WebsiteHtmlContentReady":
144
- return (g = e == null ? void 0 : e.onWebsiteHtmlContentReady) == null || g.call(e, t), !0;
257
+ return (v = e == null ? void 0 : e.onWebsiteHtmlContentReady) == null || v.call(e, r), !0;
145
258
  case "WebsiteTextContentReady":
146
- return (p = e == null ? void 0 : e.onWebsiteTextContentReady) == null || p.call(e, t), !0;
259
+ return (E = e == null ? void 0 : e.onWebsiteTextContentReady) == null || E.call(e, r), !0;
147
260
  case "FileSearchIndexReady":
148
- return (C = e == null ? void 0 : e.onFileSearchIndexReady) == null || C.call(e, t), !0;
261
+ return (A = e == null ? void 0 : e.onFileSearchIndexReady) == null || A.call(e, r), !0;
149
262
  case "AgentTaskProgressItemUpdated":
150
- return (y = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || y.call(e, t), !0;
263
+ return (P = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || P.call(e, r), !0;
151
264
  }
152
265
  }
153
266
  });
154
- return {
267
+ return x(() => {
268
+ u && s && o && (d.setSourceUrl(u), a(null));
269
+ }, [u, s, o]), {
155
270
  createStream: async () => {
156
271
  try {
157
- const u = await a.getOrCreateStream(e.fetchClientSecret, 3e4);
158
- c(u);
159
- const t = `${a.fency.baseUrl}/v1/pub/streams/${u.id}?pk=${a.fency.publishableKey}`;
160
- return i.setSourceUrl(t), {
272
+ const c = await t.getOrCreateStream(e.fetchTokens, 3e4);
273
+ i(c), m(c.token);
274
+ const r = `${t.fency.baseUrl}/sse/streams/${c.id}`;
275
+ return a(r), {
161
276
  type: "success",
162
- stream: u
277
+ stream: c
163
278
  };
164
- } catch (u) {
279
+ } catch (c) {
165
280
  return {
166
281
  type: "error",
167
282
  error: {
168
283
  code: "UnknownError",
169
- message: u instanceof Error ? u.message : "Failed to create stream"
284
+ message: c instanceof Error ? c.message : "Failed to create stream"
170
285
  }
171
286
  };
172
287
  }
173
288
  },
174
- stream: s
289
+ stream: o
175
290
  };
176
- }, je = (e) => {
177
- const a = H(), [s, c] = x([]), { createStream: i } = Ke({
178
- fetchClientSecret: e.fetchCreateStreamClientSecret,
179
- onAgentTaskProgressItemUpdated: (t) => {
291
+ }, Ce = (e) => {
292
+ const t = R(), [o, i] = T([]), { createStream: s } = me({
293
+ fetchTokens: e.fetchCreateStreamTokens,
294
+ onAgentTaskProgressItemUpdated: (a) => {
180
295
  var n;
181
- (n = e.onAgentTaskProgressItemUpdated) == null || n.call(e, t), c((h) => {
182
- const m = h.find(
183
- (o) => o.streamId === t.streamId
296
+ (n = e.onAgentTaskProgressItemUpdated) == null || n.call(e, a), i((d) => {
297
+ const l = d.find(
298
+ (r) => r.streamId === a.streamId
184
299
  );
185
- return m ? m.progressItems.map(
186
- (o) => o.progressItemId
187
- ).includes(t.progressItemId) ? [
188
- ...h.filter((o) => o.streamId !== t.streamId),
300
+ return l ? l.progressItems.map(
301
+ (r) => r.progressItemId
302
+ ).includes(a.progressItemId) ? [
303
+ ...d.filter((r) => r.streamId !== a.streamId),
189
304
  {
190
- ...m,
191
- progressItems: m.progressItems.map(
192
- (o) => o.progressItemId === t.progressItemId ? t : o
305
+ ...l,
306
+ progressItems: l.progressItems.map(
307
+ (r) => r.progressItemId === a.progressItemId ? a : r
193
308
  )
194
309
  }
195
310
  ] : [
196
- ...h.filter(
197
- (o) => o.streamId !== t.streamId
311
+ ...d.filter(
312
+ (r) => r.streamId !== a.streamId
198
313
  ),
199
314
  {
200
- ...m,
315
+ ...l,
201
316
  progressItems: [
202
- ...m.progressItems,
203
- t
317
+ ...l.progressItems,
318
+ a
204
319
  ]
205
320
  }
206
- ] : h;
321
+ ] : d;
207
322
  });
208
323
  },
209
- onStreamError: (t) => {
324
+ onStreamError: (a) => {
210
325
  var n;
211
- (n = e == null ? void 0 : e.onStreamError) == null || n.call(e, t), c((h) => {
212
- const m = h.find((r) => r.streamId === t.streamId);
213
- return m ? [
214
- ...h.filter((r) => r.streamId !== t.streamId),
326
+ (n = e == null ? void 0 : e.onStreamError) == null || n.call(e, a), i((d) => {
327
+ const l = d.find((c) => c.streamId === a.streamId);
328
+ return l ? [
329
+ ...d.filter((c) => c.streamId !== a.streamId),
215
330
  {
216
- ...m,
331
+ ...l,
217
332
  loading: !1,
218
- error: t.error
333
+ error: a.error
219
334
  }
220
- ] : h;
335
+ ] : d;
221
336
  });
222
337
  },
223
- onStreamNotFound: (t) => {
338
+ onStreamNotFound: (a) => {
224
339
  var n;
225
- (n = e == null ? void 0 : e.onStreamNotFound) == null || n.call(e, t);
340
+ (n = e == null ? void 0 : e.onStreamNotFound) == null || n.call(e, a);
226
341
  },
227
- onStreamTimeout: (t) => {
342
+ onStreamTimeout: (a) => {
228
343
  var n;
229
- (n = e == null ? void 0 : e.onStreamTimeout) == null || n.call(e, t);
344
+ (n = e == null ? void 0 : e.onStreamTimeout) == null || n.call(e, a);
230
345
  }
231
- }), d = I(
232
- async (t) => {
233
- var h;
234
- const n = await i();
346
+ }), m = D(
347
+ async (a) => {
348
+ const n = await s();
235
349
  if (n.type === "success") {
236
- c([
237
- ...s,
350
+ i([
351
+ ...o,
238
352
  {
239
353
  streamId: n.stream.id,
240
354
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
241
355
  data: null,
242
356
  error: null,
243
- prompt: t,
357
+ prompt: a,
244
358
  progressItems: [],
245
359
  loading: !0,
246
360
  doneStreaming: !1
247
361
  }
248
362
  ]);
249
- const m = await ((h = e == null ? void 0 : e.fetchCreateAgentTaskClientSecret) == null ? void 0 : h.call(e)), r = await ke({
250
- pk: a.fency.publishableKey,
251
- baseUrl: a.fency.baseUrl,
252
- clientSecret: m == null ? void 0 : m.clientSecret,
363
+ const { clientToken: d } = await e.fetchClientToken(), l = await q({
364
+ pk: t.fency.publishableKey,
365
+ baseUrl: t.fency.baseUrl,
366
+ clientToken: d,
367
+ streamToken: n.stream.token,
253
368
  request: {
254
369
  streamId: n.stream.id,
255
- queryText: t.queryText,
256
- jsonSchema: t.jsonSchema,
257
- todos: t.todos
370
+ queryText: a.queryText,
371
+ jsonSchema: a.jsonSchema,
372
+ todos: a.todos
258
373
  }
259
374
  });
260
- if (r.type === "success" && r.agentTask)
261
- return c((o) => [
262
- ...o.filter(
263
- (l) => l.streamId !== n.stream.id
375
+ if (l.type === "success" && l.agentTask)
376
+ return i((c) => [
377
+ ...c.filter(
378
+ (r) => r.streamId !== n.stream.id
264
379
  ),
265
380
  {
266
381
  streamId: n.stream.id,
267
382
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
268
383
  data: {
269
- id: r.agentTask.id,
270
- createdAt: r.agentTask.createdAt,
384
+ id: l.agentTask.id,
385
+ createdAt: l.agentTask.createdAt,
271
386
  streamId: n.stream.id
272
387
  },
273
388
  error: null,
274
- prompt: t,
389
+ prompt: a,
275
390
  progressItems: [],
276
391
  doneStreaming: !1,
277
392
  loading: !0
@@ -279,18 +394,18 @@ const Ue = (e) => {
279
394
  ]), {
280
395
  type: "success",
281
396
  streamId: n.stream.id,
282
- agentTaskId: r.agentTask.id
397
+ agentTaskId: l.agentTask.id
283
398
  };
284
- if (r.type === "error")
285
- return c((o) => [
286
- ...o.filter(
287
- (l) => l.streamId !== n.stream.id
399
+ if (l.type === "error")
400
+ return i((c) => [
401
+ ...c.filter(
402
+ (r) => r.streamId !== n.stream.id
288
403
  ),
289
404
  {
290
405
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
291
406
  streamId: n.stream.id,
292
- prompt: t,
293
- error: r.error,
407
+ prompt: a,
408
+ error: l.error,
294
409
  progressItems: [],
295
410
  loading: !1,
296
411
  doneStreaming: !1,
@@ -298,22 +413,22 @@ const Ue = (e) => {
298
413
  }
299
414
  ]), {
300
415
  type: "error",
301
- error: r.error
416
+ error: l.error
302
417
  };
303
418
  {
304
- const o = {
419
+ const c = {
305
420
  message: "No response received",
306
421
  code: "UnknownError"
307
422
  };
308
- return c((l) => [
309
- ...l.filter(
310
- (g) => g.streamId !== n.stream.id
423
+ return i((r) => [
424
+ ...r.filter(
425
+ (f) => f.streamId !== n.stream.id
311
426
  ),
312
427
  {
313
428
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
314
429
  streamId: n.stream.id,
315
- error: o,
316
- prompt: t,
430
+ error: c,
431
+ prompt: a,
317
432
  progressItems: [],
318
433
  loading: !1,
319
434
  doneStreaming: !1,
@@ -321,68 +436,36 @@ const Ue = (e) => {
321
436
  }
322
437
  ]), {
323
438
  type: "error",
324
- error: o
439
+ error: c
325
440
  };
326
441
  }
327
442
  } else
328
443
  return console.error(n.error), n;
329
444
  },
330
- [a, s, i]
331
- ), u = G(() => s.sort((t, n) => new Date(n.triggeredAt).getTime() - new Date(t.triggeredAt).getTime())[0], [s]);
445
+ [t, o, s]
446
+ ), u = B(() => o.sort((a, n) => new Date(n.triggeredAt).getTime() - new Date(a.triggeredAt).getTime())[0], [o]);
332
447
  return {
333
- agentTasks: s,
334
- createAgentTask: d,
448
+ agentTasks: o,
449
+ createAgentTask: m,
335
450
  latest: u
336
451
  };
337
452
  };
338
- function Ge() {
339
- const e = H();
340
- return {
341
- search: async (s) => {
342
- try {
343
- const { clientSecret: c } = await s.fetchClientSecret(), i = await Ae({
344
- pk: e.fency.publishableKey,
345
- clientSecret: c,
346
- request: {
347
- memoryTypeId: s.memoryTypeId,
348
- title: s.title
349
- },
350
- baseUrl: e.fency.baseUrl
351
- });
352
- return i.type === "success" ? {
353
- type: "success",
354
- items: i.items
355
- } : {
356
- type: "error",
357
- error: i.error
358
- };
359
- } catch (c) {
360
- return {
361
- type: "error",
362
- error: {
363
- code: "UNKNOWN_ERROR",
364
- message: c instanceof Error ? c.message : "An unknown error occurred"
365
- }
366
- };
367
- }
368
- }
369
- };
370
- }
371
- function Ve(e, a) {
372
- const [s, c] = x(
453
+ function Ae(e, t) {
454
+ const [o, i] = T(
373
455
  null
374
- ), [i, d] = x(
456
+ ), [s, m] = T(
375
457
  null
376
- ), u = H(), t = async (r) => {
377
- const o = await r.fetchClientSecret(), { fetchClientSecret: l, nextPageToken: g, previousPageToken: p, ...C } = r, y = await e({
458
+ ), u = R(), a = async (c) => {
459
+ const r = await c.fetchTokens(), { fetchTokens: f, nextPageToken: h, previousPageToken: b, ...w } = c, y = await e({
378
460
  pk: u.fency.publishableKey,
379
- clientSecret: o.clientSecret,
461
+ clientToken: r.clientToken,
462
+ streamToken: r.streamToken,
380
463
  request: {
381
- ...C,
382
- limit: (a == null ? void 0 : a.pageSize) ?? 50,
464
+ ...w,
465
+ limit: (t == null ? void 0 : t.pageSize) ?? 50,
383
466
  pagination: {
384
- nextPageToken: g,
385
- previousPageToken: p
467
+ nextPageToken: h,
468
+ previousPageToken: b
386
469
  }
387
470
  },
388
471
  baseUrl: u.fency.baseUrl
@@ -404,16 +487,16 @@ function Ve(e, a) {
404
487
  };
405
488
  };
406
489
  return {
407
- fetchFirstPage: async (r) => {
408
- const o = await t({
409
- ...r,
490
+ fetchFirstPage: async (c) => {
491
+ const r = await a({
492
+ ...c,
410
493
  nextPageToken: void 0,
411
494
  previousPageToken: void 0
412
495
  });
413
- return o.type === "success" && (d(o.page), c(r)), o;
496
+ return r.type === "success" && (m(r.page), i(c)), r;
414
497
  },
415
- fetchNextPage: async (r) => {
416
- if (i == null)
498
+ fetchNextPage: async (c) => {
499
+ if (s == null)
417
500
  return {
418
501
  type: "error",
419
502
  error: {
@@ -421,7 +504,7 @@ function Ve(e, a) {
421
504
  message: "No current page"
422
505
  }
423
506
  };
424
- if (i.pagination.nextPageToken == null)
507
+ if (s.pagination.nextPageToken == null)
425
508
  return {
426
509
  type: "error",
427
510
  error: {
@@ -429,15 +512,15 @@ function Ve(e, a) {
429
512
  message: "No next page"
430
513
  }
431
514
  };
432
- const o = await t({
433
- ...r,
434
- nextPageToken: i.pagination.nextPageToken,
515
+ const r = await a({
516
+ ...c,
517
+ nextPageToken: s.pagination.nextPageToken,
435
518
  previousPageToken: void 0
436
519
  });
437
- return o.type === "success" && (d(o.page), c(r)), o;
520
+ return r.type === "success" && (m(r.page), i(c)), r;
438
521
  },
439
- fetchPreviousPage: async (r) => {
440
- if (i == null)
522
+ fetchPreviousPage: async (c) => {
523
+ if (s == null)
441
524
  return {
442
525
  type: "error",
443
526
  error: {
@@ -445,7 +528,7 @@ function Ve(e, a) {
445
528
  message: "No current page"
446
529
  }
447
530
  };
448
- if (i.pagination.previousPageToken == null)
531
+ if (s.pagination.previousPageToken == null)
449
532
  return {
450
533
  type: "error",
451
534
  error: {
@@ -453,44 +536,24 @@ function Ve(e, a) {
453
536
  message: "No previous page"
454
537
  }
455
538
  };
456
- const o = await t({
457
- ...r,
539
+ const r = await a({
540
+ ...c,
458
541
  nextPageToken: void 0,
459
- previousPageToken: i.pagination.previousPageToken
542
+ previousPageToken: s.pagination.previousPageToken
460
543
  });
461
- return o.type === "success" && (d(o.page), c(r)), o;
544
+ return r.type === "success" && (m(r.page), i(c)), r;
462
545
  },
463
- refetchCurrentPage: async () => s == null ? {
546
+ refetchCurrentPage: async () => o == null ? {
464
547
  type: "error",
465
548
  error: {
466
549
  code: "NO_CURRENT_PAGE",
467
550
  message: "No current page, please call fetchFirstPage first."
468
551
  }
469
- } : t(s),
470
- currentPage: i
471
- };
472
- }
473
- function Qe() {
474
- const e = H(), a = async (t) => Pe({
475
- pk: e.fency.publishableKey,
476
- clientSecret: t.clientSecret,
477
- baseUrl: e.fency.baseUrl
478
- }), {
479
- fetchFirstPage: s,
480
- fetchNextPage: c,
481
- fetchPreviousPage: i,
482
- refetchCurrentPage: d,
483
- currentPage: u
484
- } = Ve(a);
485
- return {
486
- listFirstPage: s,
487
- listNextPage: c,
488
- listPreviousPage: i,
489
- refetchCurrentPage: d,
490
- currentPage: u
552
+ } : a(o),
553
+ currentPage: s
491
554
  };
492
555
  }
493
- const xe = {
556
+ const K = {
494
557
  'code[class*="language-"]': {
495
558
  color: "#f8f8f2",
496
559
  background: "none",
@@ -641,81 +704,83 @@ const xe = {
641
704
  italic: {
642
705
  fontStyle: "italic"
643
706
  }
644
- }, Xe = ({
707
+ }, ge = ({
645
708
  markdown: e,
646
- fetchGetDownloadLinkClientSecret: a,
647
- durationSeconds: s
709
+ streamToken: t,
710
+ fetchClientToken: o,
711
+ durationSeconds: i
648
712
  }) => {
649
- const { fency: c } = H(), i = I(
650
- async (d) => {
713
+ const { fency: s } = R(), m = D(
714
+ async (u) => {
651
715
  try {
652
- const { clientSecret: u } = await a(d), t = await Ee({
653
- pk: c.publishableKey,
654
- baseUrl: c.baseUrl,
655
- clientSecret: u,
716
+ const { clientToken: a } = await o(), n = await G({
717
+ pk: s.publishableKey,
718
+ baseUrl: s.baseUrl,
719
+ clientToken: a,
720
+ streamToken: t,
656
721
  request: {
657
- fileId: d
722
+ fileId: u
658
723
  }
659
724
  });
660
- t.type === "success" && window.open(t.downloadLink, "_blank");
661
- } catch (u) {
662
- console.error("Failed to download file:", u);
725
+ n.type === "success" && window.open(n.downloadLink, "_blank");
726
+ } catch (a) {
727
+ console.error("Failed to download file:", a);
663
728
  }
664
729
  },
665
- [c, a]
730
+ [s, t, o]
666
731
  );
667
- return /* @__PURE__ */ A(
732
+ return /* @__PURE__ */ I(
668
733
  "div",
669
734
  {
670
735
  style: {
671
736
  padding: "16px"
672
737
  },
673
738
  children: [
674
- /* @__PURE__ */ f(
675
- $.div,
739
+ /* @__PURE__ */ g(
740
+ C.div,
676
741
  {
677
742
  className: "fency-markdown-body-raw",
678
743
  initial: { opacity: 0, y: -10 },
679
744
  animate: { opacity: 1, y: 0 },
680
745
  transition: { duration: 0.3, delay: 0 },
681
- children: /* @__PURE__ */ f(
682
- be,
746
+ children: /* @__PURE__ */ g(
747
+ W,
683
748
  {
684
- remarkPlugins: [Se],
749
+ remarkPlugins: [L],
685
750
  components: {
686
- code(d) {
687
- const { children: u, className: t, node: n, ref: h, ...m } = d, r = /language-(\w+)/.exec(t || "");
688
- return r ? /* @__PURE__ */ f(
689
- Ce,
751
+ code(u) {
752
+ const { children: a, className: n, node: d, ref: l, ...c } = u, r = /language-(\w+)/.exec(n || "");
753
+ return r ? /* @__PURE__ */ g(
754
+ j,
690
755
  {
691
- ...m,
756
+ ...c,
692
757
  PreTag: "div",
693
- children: String(u).replace(
758
+ children: String(a).replace(
694
759
  /\n$/,
695
760
  ""
696
761
  ),
697
762
  language: r[1],
698
- style: xe
763
+ style: K
699
764
  }
700
- ) : /* @__PURE__ */ f("code", { ...m, className: t, children: String(u) });
765
+ ) : /* @__PURE__ */ g("code", { ...c, className: n, children: String(a) });
701
766
  },
702
- a(d) {
703
- const { children: u, href: t, ...n } = d;
704
- return /* @__PURE__ */ f(
767
+ a(u) {
768
+ const { children: a, href: n, ...d } = u;
769
+ return /* @__PURE__ */ g(
705
770
  "a",
706
771
  {
707
- ...n,
708
- href: t,
709
- onClick: (h) => {
710
- if (!t) return;
711
- const m = t.match(/\/files\/(fil_[a-zA-Z0-9]+)\/download/);
712
- if (m) {
713
- h.preventDefault();
714
- const r = m[1];
715
- i(r);
772
+ ...d,
773
+ href: n,
774
+ onClick: (l) => {
775
+ if (!n) return;
776
+ const c = n.match(/\/files\/(fil_[a-zA-Z0-9]+)\/download/);
777
+ if (c) {
778
+ l.preventDefault();
779
+ const r = c[1];
780
+ m(r);
716
781
  }
717
782
  },
718
- children: u
783
+ children: a
719
784
  }
720
785
  );
721
786
  }
@@ -725,7 +790,7 @@ const xe = {
725
790
  )
726
791
  }
727
792
  ),
728
- s !== void 0 && /* @__PURE__ */ A(
793
+ i !== void 0 && /* @__PURE__ */ I(
729
794
  "div",
730
795
  {
731
796
  style: {
@@ -736,7 +801,7 @@ const xe = {
736
801
  },
737
802
  children: [
738
803
  "Thought for ",
739
- s,
804
+ i,
740
805
  " seconds"
741
806
  ]
742
807
  }
@@ -745,27 +810,27 @@ const xe = {
745
810
  }
746
811
  );
747
812
  };
748
- function se({
813
+ function M({
749
814
  text: e,
750
- duration: a = 2,
751
- delay: s = 0,
752
- repeat: c = !0,
753
- repeatDelay: i = 0.5,
754
- className: d,
815
+ duration: t = 2,
816
+ delay: o = 0,
817
+ repeat: i = !0,
818
+ repeatDelay: s = 0.5,
819
+ className: m,
755
820
  startOnView: u = !1,
756
- once: t = !1,
821
+ once: a = !1,
757
822
  inViewMargin: n,
758
- spread: h = 2,
759
- color: m = "#999",
760
- shimmerColor: r = "#000",
761
- direction: o = "fromBottom"
823
+ spread: d = 2,
824
+ color: l = "#999",
825
+ shimmerColor: c = "#000",
826
+ direction: r = "fromBottom"
762
827
  }) {
763
- const l = _(null), g = Fe(l, { once: t, margin: n }), p = G(() => e.length * h, [e, h]), C = !u || g, y = o === "fromBottom" ? "100% center" : "-100% center", S = o === "fromBottom" ? "0% center" : "200% center";
764
- return /* @__PURE__ */ f(
765
- $.span,
828
+ const f = F(null), h = J(f, { once: a, margin: n }), b = B(() => e.length * d, [e, d]), w = !u || h, y = r === "fromBottom" ? "100% center" : "-100% center", k = r === "fromBottom" ? "0% center" : "200% center";
829
+ return /* @__PURE__ */ g(
830
+ C.span,
766
831
  {
767
- ref: l,
768
- className: d,
832
+ ref: f,
833
+ className: m,
769
834
  style: {
770
835
  position: "relative",
771
836
  display: "inline-block",
@@ -775,9 +840,9 @@ function se({
775
840
  color: "transparent",
776
841
  WebkitTextFillColor: "transparent",
777
842
  backgroundRepeat: "no-repeat, padding-box",
778
- "--spread": `${p}px`,
779
- "--base-color": m,
780
- "--shimmer-color": r,
843
+ "--spread": `${b}px`,
844
+ "--base-color": l,
845
+ "--shimmer-color": c,
781
846
  "--shimmer-bg": "linear-gradient(90deg, transparent calc(50% - var(--spread)), var(--shimmer-color), transparent calc(50% + var(--spread)))",
782
847
  backgroundImage: "var(--shimmer-bg), linear-gradient(var(--base-color), var(--base-color))"
783
848
  },
@@ -785,41 +850,41 @@ function se({
785
850
  backgroundPosition: y,
786
851
  opacity: 0
787
852
  },
788
- animate: C ? {
789
- backgroundPosition: S,
853
+ animate: w ? {
854
+ backgroundPosition: k,
790
855
  opacity: 1
791
856
  } : {},
792
857
  transition: {
793
858
  backgroundPosition: {
794
- repeat: c ? 1 / 0 : 0,
795
- duration: a,
796
- delay: s,
797
- repeatDelay: i,
859
+ repeat: i ? 1 / 0 : 0,
860
+ duration: t,
861
+ delay: o,
862
+ repeatDelay: s,
798
863
  ease: "linear"
799
864
  },
800
865
  opacity: {
801
866
  duration: 0.3,
802
- delay: s
867
+ delay: o
803
868
  }
804
869
  },
805
870
  children: e
806
871
  }
807
872
  );
808
873
  }
809
- const Je = ({
874
+ const fe = ({
810
875
  title: e,
811
- completed: a,
812
- isLatest: s = !1,
813
- durationSeconds: c
814
- }) => /* @__PURE__ */ A(
876
+ completed: t,
877
+ isLatest: o = !1,
878
+ durationSeconds: i
879
+ }) => /* @__PURE__ */ I(
815
880
  "div",
816
881
  {
817
882
  style: {
818
883
  padding: "16px"
819
884
  },
820
885
  children: [
821
- /* @__PURE__ */ f(
822
- $.div,
886
+ /* @__PURE__ */ g(
887
+ C.div,
823
888
  {
824
889
  style: {
825
890
  display: "flex",
@@ -830,8 +895,8 @@ const Je = ({
830
895
  initial: { opacity: 0, y: -10 },
831
896
  animate: { opacity: 1, y: 0 },
832
897
  transition: { duration: 0.3, delay: 0 },
833
- children: s && !c ? /* @__PURE__ */ f(
834
- se,
898
+ children: o && !i ? /* @__PURE__ */ g(
899
+ M,
835
900
  {
836
901
  text: e,
837
902
  duration: 2.5,
@@ -839,10 +904,10 @@ const Je = ({
839
904
  color: "#999",
840
905
  shimmerColor: "#000"
841
906
  }
842
- ) : /* @__PURE__ */ f("span", { style: { color: "#666" }, children: e })
907
+ ) : /* @__PURE__ */ g("span", { style: { color: "#666" }, children: e })
843
908
  }
844
909
  ),
845
- c !== void 0 && /* @__PURE__ */ A(
910
+ i !== void 0 && /* @__PURE__ */ I(
846
911
  "div",
847
912
  {
848
913
  style: {
@@ -853,44 +918,44 @@ const Je = ({
853
918
  },
854
919
  children: [
855
920
  "Thought for ",
856
- c,
921
+ i,
857
922
  " seconds"
858
923
  ]
859
924
  }
860
925
  ),
861
- /* @__PURE__ */ f("style", { children: `
926
+ /* @__PURE__ */ g("style", { children: `
862
927
  @keyframes spin {
863
928
  to { transform: rotate(360deg); }
864
929
  }
865
930
  ` })
866
931
  ]
867
932
  }
868
- ), Ye = ({
933
+ ), ye = ({
869
934
  title: e,
870
- markdown: a,
871
- completed: s,
872
- isLatest: c = !1,
873
- durationSeconds: i
935
+ markdown: t,
936
+ completed: o,
937
+ isLatest: i = !1,
938
+ durationSeconds: s
874
939
  }) => {
875
- const d = _(null);
876
- return N(() => {
877
- d.current && !s && (d.current.scrollTop = d.current.scrollHeight);
878
- }, [a, s]), /* @__PURE__ */ A(
940
+ const m = F(null);
941
+ return x(() => {
942
+ m.current && !o && (m.current.scrollTop = m.current.scrollHeight);
943
+ }, [t, o]), /* @__PURE__ */ I(
879
944
  "div",
880
945
  {
881
946
  style: {
882
947
  padding: "16px"
883
948
  },
884
949
  children: [
885
- /* @__PURE__ */ f(
886
- $.h3,
950
+ /* @__PURE__ */ g(
951
+ C.h3,
887
952
  {
888
953
  style: { marginBottom: "10px", color: "#666" },
889
954
  initial: { opacity: 0, y: -10 },
890
955
  animate: { opacity: 1, y: 0 },
891
956
  transition: { duration: 0.3, delay: 0 },
892
- children: c && !i ? /* @__PURE__ */ f(
893
- se,
957
+ children: i && !s ? /* @__PURE__ */ g(
958
+ M,
894
959
  {
895
960
  text: e,
896
961
  duration: 2.5,
@@ -901,10 +966,10 @@ const Je = ({
901
966
  ) : e
902
967
  }
903
968
  ),
904
- /* @__PURE__ */ f(
905
- $.div,
969
+ /* @__PURE__ */ g(
970
+ C.div,
906
971
  {
907
- ref: d,
972
+ ref: m,
908
973
  style: {
909
974
  maxHeight: "100px",
910
975
  overflowY: "auto",
@@ -917,42 +982,42 @@ const Je = ({
917
982
  initial: { opacity: 0, y: -10 },
918
983
  animate: { opacity: 0.5, y: 0 },
919
984
  transition: { duration: 0.3, delay: 0.1 },
920
- children: /* @__PURE__ */ f("div", { className: "fency-markdown-body-raw", children: /* @__PURE__ */ f(
921
- be,
985
+ children: /* @__PURE__ */ g("div", { className: "fency-markdown-body-raw", children: /* @__PURE__ */ g(
986
+ W,
922
987
  {
923
- remarkPlugins: [Se],
988
+ remarkPlugins: [L],
924
989
  components: {
925
990
  code(u) {
926
991
  const {
927
- children: t,
992
+ children: a,
928
993
  className: n,
929
- node: h,
930
- ref: m,
931
- ...r
932
- } = u, o = /language-(\w+)/.exec(
994
+ node: d,
995
+ ref: l,
996
+ ...c
997
+ } = u, r = /language-(\w+)/.exec(
933
998
  n || ""
934
999
  );
935
- return o ? /* @__PURE__ */ f(
936
- Ce,
1000
+ return r ? /* @__PURE__ */ g(
1001
+ j,
937
1002
  {
938
- ...r,
1003
+ ...c,
939
1004
  PreTag: "div",
940
- children: String(t).replace(
1005
+ children: String(a).replace(
941
1006
  /\n$/,
942
1007
  ""
943
1008
  ),
944
- language: o[1],
945
- style: xe
1009
+ language: r[1],
1010
+ style: K
946
1011
  }
947
- ) : /* @__PURE__ */ f("code", { ...r, className: n, children: String(t) });
1012
+ ) : /* @__PURE__ */ g("code", { ...c, className: n, children: String(a) });
948
1013
  }
949
1014
  },
950
- children: a
1015
+ children: t
951
1016
  }
952
1017
  ) })
953
1018
  }
954
1019
  ),
955
- i !== void 0 && /* @__PURE__ */ A(
1020
+ s !== void 0 && /* @__PURE__ */ I(
956
1021
  "div",
957
1022
  {
958
1023
  style: {
@@ -963,7 +1028,7 @@ const Je = ({
963
1028
  },
964
1029
  children: [
965
1030
  "Thought for ",
966
- i,
1031
+ s,
967
1032
  " seconds"
968
1033
  ]
969
1034
  }
@@ -971,108 +1036,110 @@ const Je = ({
971
1036
  ]
972
1037
  }
973
1038
  );
974
- }, Ze = ({ message: e, isLatest: a = !1, fetchGetDownloadLinkClientSecret: s }) => {
975
- const c = e.state || "complete";
976
- if (c === ee.EXECUTION)
977
- return /* @__PURE__ */ f(
978
- Je,
1039
+ }, he = ({ message: e, isLatest: t = !1, streamToken: o, fetchClientToken: i }) => {
1040
+ const s = e.state || "complete";
1041
+ if (s === O.EXECUTION)
1042
+ return /* @__PURE__ */ g(
1043
+ fe,
979
1044
  {
980
1045
  title: e.title,
981
1046
  completed: e.completed,
982
- isLatest: a,
1047
+ isLatest: t,
983
1048
  durationSeconds: e.durationSeconds
984
1049
  }
985
1050
  );
986
- if (c === ee.REASONING)
987
- return /* @__PURE__ */ f(
988
- Ye,
1051
+ if (s === O.REASONING)
1052
+ return /* @__PURE__ */ g(
1053
+ ye,
989
1054
  {
990
1055
  title: e.title,
991
1056
  markdown: e.markdown,
992
1057
  completed: e.completed,
993
- isLatest: a,
1058
+ isLatest: t,
994
1059
  durationSeconds: e.durationSeconds
995
1060
  }
996
1061
  );
997
- if (c === ee.FINAL_RESPONSE)
998
- return /* @__PURE__ */ f(
999
- Xe,
1062
+ if (s === O.FINAL_RESPONSE)
1063
+ return /* @__PURE__ */ g(
1064
+ ge,
1000
1065
  {
1001
1066
  markdown: e.markdown,
1002
- fetchGetDownloadLinkClientSecret: s,
1067
+ streamToken: o,
1068
+ fetchClientToken: i,
1003
1069
  durationSeconds: e.durationSeconds
1004
1070
  }
1005
1071
  );
1006
- throw new Error(`Unknown state: ${c}`);
1007
- }, et = ({
1072
+ throw new Error(`Unknown state: ${s}`);
1073
+ }, Pe = ({
1008
1074
  agentTask: e,
1009
- mode: a = "verbose",
1010
- placeholderMessage: s = "Processing your request",
1011
- fetchGetDownloadLinkClientSecret: c
1075
+ mode: t = "verbose",
1076
+ placeholderMessage: o = "Processing your request",
1077
+ streamToken: i,
1078
+ fetchClientToken: s
1012
1079
  }) => {
1013
- const [i, d] = x([]), u = _(null);
1014
- if (N(() => {
1015
- const t = e.progressItems.map((r, o) => {
1016
- let l;
1017
- const g = e.progressItems[o + 1];
1018
- if (g != null && g.startedAt) {
1019
- const C = new Date(r.startedAt).getTime(), y = new Date(g.startedAt).getTime();
1020
- l = Math.round((y - C) / 1e3);
1080
+ const [m, u] = T([]), a = F(null);
1081
+ if (x(() => {
1082
+ const n = e.progressItems.map((r, f) => {
1083
+ let h;
1084
+ const b = e.progressItems[f + 1];
1085
+ if (b != null && b.startedAt) {
1086
+ const y = new Date(r.startedAt).getTime(), k = new Date(b.startedAt).getTime();
1087
+ h = Math.round((k - y) / 1e3);
1021
1088
  }
1022
- const p = g != null;
1089
+ const w = b != null;
1023
1090
  return {
1024
1091
  id: r.progressItemId,
1025
1092
  title: r.title,
1026
1093
  markdown: r.response || "",
1027
1094
  state: r.progressItemType,
1028
- completed: p,
1095
+ completed: w,
1029
1096
  startedAt: r.startedAt,
1030
1097
  completedAt: r.completedAt,
1031
- durationSeconds: l
1098
+ durationSeconds: h
1032
1099
  };
1033
1100
  });
1034
- let n;
1035
- const h = e.progressItems[0];
1036
- if (h != null && h.startedAt) {
1037
- const r = new Date(e.triggeredAt).getTime(), o = new Date(h.startedAt).getTime();
1038
- n = Math.round((o - r) / 1e3);
1101
+ let d;
1102
+ const l = e.progressItems[0];
1103
+ if (l != null && l.startedAt) {
1104
+ const r = new Date(e.triggeredAt).getTime(), f = new Date(l.startedAt).getTime();
1105
+ d = Math.round((f - r) / 1e3);
1039
1106
  }
1040
- const m = {
1107
+ const c = {
1041
1108
  id: "placeholder",
1042
- title: s,
1109
+ title: o,
1043
1110
  markdown: "",
1044
- state: ee.EXECUTION,
1045
- completed: h != null,
1046
- durationSeconds: n
1111
+ state: O.EXECUTION,
1112
+ completed: l != null,
1113
+ durationSeconds: d
1047
1114
  };
1048
- d([m, ...t]);
1049
- }, [e, s]), N(() => {
1050
- a === "verbose" && u.current && (u.current.scrollTop = u.current.scrollHeight);
1051
- }, [i, a]), a === "simple") {
1052
- const t = i[i.length - 1];
1053
- if (!t)
1115
+ u([c, ...n]);
1116
+ }, [e, o]), x(() => {
1117
+ t === "verbose" && a.current && (a.current.scrollTop = a.current.scrollHeight);
1118
+ }, [m, t]), t === "simple") {
1119
+ const n = m[m.length - 1];
1120
+ if (!n)
1054
1121
  return null;
1055
- const n = t.completed;
1056
- return /* @__PURE__ */ f("div", { className: "simple-mode-container", children: /* @__PURE__ */ f(ye, { mode: "wait", children: /* @__PURE__ */ f(
1057
- $.div,
1122
+ const d = n.completed;
1123
+ return /* @__PURE__ */ g("div", { className: "simple-mode-container", children: /* @__PURE__ */ g(_, { mode: "wait", children: /* @__PURE__ */ g(
1124
+ C.div,
1058
1125
  {
1059
1126
  initial: { opacity: 0, y: 10 },
1060
1127
  animate: { opacity: 1, y: 0 },
1061
1128
  exit: { opacity: 0, y: -10 },
1062
1129
  transition: { duration: 0.3 },
1063
- children: n ? /* @__PURE__ */ f(
1130
+ children: d ? /* @__PURE__ */ g(
1064
1131
  "div",
1065
1132
  {
1066
1133
  className: "simple-mode-title",
1067
1134
  style: {
1068
1135
  color: "#666"
1069
1136
  },
1070
- children: t.title
1137
+ children: n.title
1071
1138
  }
1072
- ) : /* @__PURE__ */ f(
1073
- se,
1139
+ ) : /* @__PURE__ */ g(
1140
+ M,
1074
1141
  {
1075
- text: t.title,
1142
+ text: n.title,
1076
1143
  className: "simple-mode-title",
1077
1144
  duration: 2.5,
1078
1145
  repeat: !0,
@@ -1081,820 +1148,111 @@ const Je = ({
1081
1148
  }
1082
1149
  )
1083
1150
  },
1084
- t.id
1151
+ n.id
1085
1152
  ) }) });
1086
1153
  }
1087
- return /* @__PURE__ */ f(
1154
+ return /* @__PURE__ */ g(
1088
1155
  "div",
1089
1156
  {
1090
- ref: u,
1157
+ ref: a,
1091
1158
  style: {
1092
1159
  flex: 1,
1093
1160
  overflowY: "auto",
1094
1161
  minHeight: 0
1095
1162
  // Important for flex scroll
1096
1163
  },
1097
- children: /* @__PURE__ */ f(ye, { children: i.length > 0 && i.map((t, n) => /* @__PURE__ */ f(
1098
- $.div,
1164
+ children: /* @__PURE__ */ g(_, { children: m.length > 0 && m.map((n, d) => /* @__PURE__ */ g(
1165
+ C.div,
1099
1166
  {
1100
1167
  initial: { opacity: 0, y: -20 },
1101
1168
  animate: { opacity: 1, y: 0 },
1102
1169
  transition: {
1103
1170
  duration: 0.4,
1104
- delay: n * 0.1,
1171
+ delay: d * 0.1,
1105
1172
  // Stagger effect
1106
1173
  ease: "easeOut"
1107
1174
  },
1108
- children: /* @__PURE__ */ f(
1109
- Ze,
1175
+ children: /* @__PURE__ */ g(
1176
+ he,
1110
1177
  {
1111
- message: t,
1112
- isLatest: n === i.length - 1,
1113
- fetchGetDownloadLinkClientSecret: c
1178
+ message: n,
1179
+ isLatest: d === m.length - 1,
1180
+ streamToken: i,
1181
+ fetchClientToken: s
1114
1182
  }
1115
1183
  )
1116
1184
  },
1117
- t.id
1185
+ n.id
1118
1186
  )) })
1119
1187
  }
1120
1188
  );
1121
- }, tt = "_wrapper_nvp45_1", nt = "_editable_nvp45_12", rt = "_mention_nvp45_48", ot = "_ghostWrapper_nvp45_58", at = "_ghost_nvp45_58", V = {
1122
- wrapper: tt,
1123
- editable: nt,
1124
- mention: rt,
1125
- ghostWrapper: ot,
1126
- ghost: at
1127
- }, st = ({
1128
- editableRef: e,
1129
- onInput: a,
1130
- onKeyDown: s,
1131
- isComposingRef: c,
1132
- handleInput: i,
1133
- placeholder: d = "Type your question or task and press Enter…"
1134
- }) => {
1135
- const [u, t] = x(!0);
1136
- return N(() => {
1137
- const n = () => {
1138
- if (e.current) {
1139
- const m = e.current.textContent || "";
1140
- t(m.trim().length === 0);
1141
- }
1142
- };
1143
- n();
1144
- const h = new MutationObserver(n);
1145
- return e.current && h.observe(e.current, {
1146
- childList: !0,
1147
- characterData: !0,
1148
- subtree: !0
1149
- }), () => h.disconnect();
1150
- }, [e]), /* @__PURE__ */ f(
1151
- "div",
1152
- {
1153
- ref: e,
1154
- contentEditable: !0,
1155
- onInput: a,
1156
- onKeyDown: s,
1157
- onCompositionStart: () => {
1158
- c.current = !0;
1159
- },
1160
- onCompositionEnd: () => {
1161
- c.current = !1, i();
1162
- },
1163
- className: V.editable,
1164
- "data-placeholder": d,
1165
- "data-empty": u ? "true" : "false",
1166
- suppressContentEditableWarning: !0
1167
- }
1168
- );
1169
- }, ct = ({
1170
- ghostRef: e,
1171
- isOpen: a,
1172
- value: s,
1173
- atPosition: c,
1174
- caretPos: i
1175
- }) => /* @__PURE__ */ f("div", { className: V.ghostWrapper, children: /* @__PURE__ */ f("div", { ref: e, className: V.ghost, children: (() => {
1176
- if (a) {
1177
- const d = s.slice(0, c), u = s.slice(c);
1178
- return /* @__PURE__ */ A(fe, { children: [
1179
- d,
1180
- /* @__PURE__ */ f("span", { "data-at-marker": !0, children: "@" }),
1181
- u.slice(1),
1182
- " "
1183
- ] });
1184
- } else {
1185
- const d = s.slice(0, i), u = s.slice(i);
1186
- return /* @__PURE__ */ A(fe, { children: [
1187
- d,
1188
- /* @__PURE__ */ f("span", { "data-caret": !0, children: "|" }),
1189
- u
1190
- ] });
1191
- }
1192
- })() }) });
1193
- function it(e) {
1194
- const a = I(() => {
1195
- const i = window.getSelection();
1196
- if (!i || i.rangeCount === 0 || !e.current) return 0;
1197
- const d = i.getRangeAt(0), u = d.cloneRange();
1198
- return u.selectNodeContents(e.current), u.setEnd(d.endContainer, d.endOffset), u.toString().length;
1199
- }, [e]), s = I((i) => {
1200
- var r;
1201
- if (!e.current) return;
1202
- const d = window.getSelection();
1203
- if (!d) return;
1204
- let u = 0;
1205
- const t = [e.current];
1206
- let n, h = null, m = 0;
1207
- for (; n = t.pop(); )
1208
- if (n.nodeType === Node.TEXT_NODE) {
1209
- const o = n, l = u + (((r = o.textContent) == null ? void 0 : r.length) || 0);
1210
- if (i <= l) {
1211
- h = o, m = i - u;
1212
- break;
1213
- }
1214
- u = l;
1215
- } else
1216
- for (let o = n.childNodes.length - 1; o >= 0; o--)
1217
- t.push(n.childNodes[o]);
1218
- if (h) {
1219
- const o = document.createRange();
1220
- o.setStart(h, m), o.collapse(!0), d.removeAllRanges(), d.addRange(o);
1221
- }
1222
- }, [e]), c = I(() => {
1223
- if (!e.current) return "";
1224
- const i = e.current.cloneNode(!0);
1225
- return i.querySelectorAll("br").forEach((d) => {
1226
- d.replaceWith(`
1227
- `);
1228
- }), i.textContent || "";
1229
- }, [e]);
1230
- return {
1231
- getCaretPosition: a,
1232
- setCaretPosition: s,
1233
- getPlainText: c
1234
- };
1235
- }
1236
- function lt({
1237
- onArrowDown: e,
1238
- onArrowUp: a,
1239
- onEnter: s,
1240
- onEscape: c
1241
- }) {
1242
- return {
1243
- handleKeyDown: I(
1244
- (d) => d.key === "ArrowUp" ? (d.preventDefault(), a(), !0) : d.key === "ArrowDown" ? (d.preventDefault(), e(), !0) : d.key === "Enter" && !d.shiftKey ? (d.preventDefault(), s(), !0) : d.key === "Escape" ? (d.preventDefault(), c(), !0) : !1,
1245
- [e, a, s, c]
1246
- )
1247
- };
1248
- }
1249
- function ut({
1250
- options: e,
1251
- onMentionChange: a,
1252
- onChangeMentionPlaceholders: s
1253
- }) {
1254
- const c = _([]), i = I(
1255
- (t) => {
1256
- const n = /* @__PURE__ */ new Set();
1257
- if (e.length > 0) {
1258
- const h = [...e].sort((r, o) => o.label.length - r.label.length), m = [];
1259
- h.forEach((r) => {
1260
- const o = r.label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), l = new RegExp(`@${o}(?=\\s|$)`, "g");
1261
- let g;
1262
- for (; (g = l.exec(t)) !== null; )
1263
- m.some((p) => Math.abs(p - g.index) < r.label.length) || (n.add(r.id), m.push(g.index));
1264
- });
1265
- }
1266
- return Array.from(n);
1267
- },
1268
- [e]
1269
- ), d = I(
1270
- (t) => {
1271
- let n = t;
1272
- if (e.length > 0) {
1273
- const h = [...e].sort((r, o) => o.label.length - r.label.length), m = [];
1274
- h.forEach((r) => {
1275
- const o = r.label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), l = new RegExp(`@${o}(?=\\s|$)`, "g");
1276
- let g;
1277
- for (; (g = l.exec(t)) !== null; )
1278
- m.some(
1279
- (C) => g.index >= C.start && g.index < C.end
1280
- ) || m.push({
1281
- start: g.index,
1282
- end: g.index + g[0].length,
1283
- placeholder: `{{{{${r.id}}}}}`
1284
- });
1285
- }), m.sort((r, o) => o.start - r.start), m.forEach((r) => {
1286
- n = n.slice(0, r.start) + r.placeholder + n.slice(r.end);
1287
- });
1288
- }
1289
- return n;
1290
- },
1291
- [e]
1292
- ), u = I(
1293
- (t) => {
1294
- const n = i(t), h = c.current;
1295
- (n.length !== h.length || n.some((l, g) => l !== h[g])) && (c.current = n, a(n));
1296
- const r = n.map((l) => e.find((g) => g.id === l)).filter((l) => l !== void 0), o = d(t);
1297
- s(o, r);
1298
- },
1299
- [
1300
- i,
1301
- d,
1302
- a,
1303
- s,
1304
- e
1305
- ]
1306
- );
1307
- return {
1308
- extractMentionIds: i,
1309
- buildPlaceholderText: d,
1310
- processText: u
1311
- };
1312
- }
1313
- function dt({
1314
- editableRef: e,
1315
- options: a,
1316
- mentionClassName: s,
1317
- getCaretPosition: c,
1318
- setCaretPosition: i
1319
- }) {
1320
- const d = _(""), u = I((r) => r.replace(/</g, "&lt;").replace(/>/g, "&gt;").replace(/\n/g, "<br>"), []), t = I((r, o = !1) => {
1321
- if (!e.current) return;
1322
- const l = o ? c() : 0;
1323
- let g = "";
1324
- const p = [];
1325
- if (a.length > 0) {
1326
- [...a].sort((S, M) => M.label.length - S.label.length).forEach((S) => {
1327
- const M = S.label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), W = new RegExp(`@${M}(?=\\s|$)`, "g");
1328
- let E;
1329
- for (; (E = W.exec(r)) !== null; )
1330
- p.some(
1331
- (U) => E.index >= U.start && E.index < U.end
1332
- ) || p.push({
1333
- start: E.index,
1334
- end: E.index + E[0].length,
1335
- html: `<span class="${s}" data-mention="${S.label}">${E[0]}</span>`
1336
- });
1337
- }), p.sort((S, M) => S.start - M.start);
1338
- let y = 0;
1339
- p.forEach((S) => {
1340
- g += u(r.slice(y, S.start)), g += S.html, y = S.end;
1341
- }), g += u(r.slice(y));
1342
- } else
1343
- g = u(r);
1344
- if (e.current.innerHTML = g || "<br>", !g || g === "<br>") {
1345
- const C = window.getSelection();
1346
- if (C && e.current) {
1347
- e.current.innerHTML = "", e.current.innerHTML = "<br>";
1348
- const y = document.createRange();
1349
- y.setStart(e.current, 0), y.collapse(!0), C.removeAllRanges(), C.addRange(y);
1350
- }
1351
- }
1352
- o && requestAnimationFrame(() => {
1353
- i(l);
1354
- });
1355
- }, [e, a, s, c, i, u]), n = I((r) => {
1356
- const o = [];
1357
- if (a.length > 0) {
1358
- const l = [...a].sort((p, C) => C.label.length - p.label.length), g = [];
1359
- l.forEach((p) => {
1360
- const C = p.label.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"), y = new RegExp(`@${C}(?=\\s|$)`, "g");
1361
- let S;
1362
- for (; (S = y.exec(r)) !== null; )
1363
- g.some((M) => Math.abs(M - S.index) < p.label.length) || (o.push(`${S.index}:${S[0]}`), g.push(S.index));
1364
- });
1365
- }
1366
- return o.sort().join(",");
1367
- }, [a]), h = I((r) => {
1368
- const o = n(r), l = o !== d.current;
1369
- return l && (d.current = o), l;
1370
- }, [n]), m = I((r) => {
1371
- d.current = n(r);
1372
- }, [n]);
1373
- return {
1374
- updateContent: t,
1375
- haveMentionsChanged: h,
1376
- updateMentionSignature: m
1377
- };
1378
- }
1379
- function mt({ setQuery: e, setIsOpen: a, setAtPosition: s }) {
1380
- const c = I((d, u) => {
1381
- const t = d.slice(0, u), n = t.lastIndexOf("@");
1382
- if (n === -1) {
1383
- a(!1), e("");
1384
- return;
1385
- }
1386
- const h = t.slice(n + 1);
1387
- if (/\s/.test(h)) {
1388
- a(!1), e("");
1389
- return;
1390
- }
1391
- e(h), s(n), a(!0);
1392
- }, []), i = I(() => {
1393
- a(!1), e("");
1394
- }, []);
1395
- return {
1396
- updateMention: c,
1397
- closePopup: i
1398
- };
1399
- }
1400
- const gt = "data:image/svg+xml,%3csvg%20xmlns='http://www.w3.org/2000/svg'%20width='24'%20height='24'%20viewBox='0%200%2024%2024'%20fill='none'%20stroke='currentColor'%20stroke-width='2'%20stroke-linecap='round'%20stroke-linejoin='round'%20class='icon%20icon-tabler%20icons-tabler-outline%20icon-tabler-arrow-right'%3e%3cpath%20stroke='none'%20d='M0%200h24v24H0z'%20fill='none'/%3e%3cpath%20d='M5%2012l14%200'%20/%3e%3cpath%20d='M13%2018l6%20-6'%20/%3e%3cpath%20d='M13%206l6%206'%20/%3e%3c/svg%3e", ht = ({ name: e }) => /* @__PURE__ */ A(
1401
- "div",
1402
- {
1403
- style: {
1404
- display: "flex",
1405
- alignItems: "center",
1406
- justifyContent: "space-between",
1407
- fontSize: "14px"
1408
- },
1409
- children: [
1410
- /* @__PURE__ */ f("div", { style: { color: "black", opacity: 0.7 }, children: e }),
1411
- /* @__PURE__ */ f(
1412
- "img",
1413
- {
1414
- src: gt,
1415
- alt: "arrow",
1416
- style: {
1417
- width: "16px",
1418
- height: "16px",
1419
- color: "black",
1420
- opacity: 0.7
1421
- }
1422
- }
1423
- )
1424
- ]
1425
- }
1426
- ), ft = ({ name: e }) => /* @__PURE__ */ f("div", { children: e }), yt = "_popup_1en4y_2", pt = "_option_1en4y_16", bt = "_optionActive_1en4y_27", Ct = "_emptyState_1en4y_35", St = "_typeToSearch_1en4y_42", wt = "_breadcrumb_1en4y_49", xt = "_breadcrumbLink_1en4y_57", vt = "_breadcrumbSeparator_1en4y_67", It = "_breadcrumbCurrent_1en4y_72", k = {
1427
- popup: yt,
1428
- option: pt,
1429
- optionActive: bt,
1430
- emptyState: Ct,
1431
- typeToSearch: St,
1432
- breadcrumb: wt,
1433
- breadcrumbLink: xt,
1434
- breadcrumbSeparator: vt,
1435
- breadcrumbCurrent: It
1436
- }, Tt = ({
1437
- isOpen: e,
1438
- options: a,
1439
- highlightedIndex: s,
1440
- onSelect: c,
1441
- caretElement: i,
1442
- query: d,
1443
- isInCategory: u,
1444
- categoryName: t,
1445
- onResetQuery: n
1446
- }) => {
1447
- const h = _(null), m = _([]);
1448
- if (pe(() => {
1449
- if (!i || !h.current) return;
1450
- i.getBoundingClientRect();
1451
- const l = i.getBoundingClientRect(), g = h.current;
1452
- g.style.position = "fixed", g.style.top = `${l.top}px`, g.style.left = `${l.left}px`, g.style.width = "1px", g.style.height = `${l.height}px`;
1453
- }, [i, e, a.length]), N(() => {
1454
- if (s >= 0 && s < m.current.length) {
1455
- const l = m.current[s];
1456
- l && l.scrollIntoView({
1457
- block: "nearest",
1458
- behavior: "instant"
1459
- });
1460
- }
1461
- }, [s]), !e || !i) return null;
1462
- const r = a.filter((l) => l.type === "option"), o = a.filter((l) => l.type === "category");
1463
- return /* @__PURE__ */ A(Z.Root, { open: e, children: [
1464
- /* @__PURE__ */ f(Z.Anchor, { asChild: !0, children: /* @__PURE__ */ f(
1465
- "div",
1466
- {
1467
- ref: h,
1468
- style: {
1469
- position: "fixed",
1470
- pointerEvents: "none",
1471
- width: 0,
1472
- height: 0
1473
- }
1474
- }
1475
- ) }),
1476
- /* @__PURE__ */ f(Z.Portal, { children: /* @__PURE__ */ A(
1477
- Z.Content,
1478
- {
1479
- className: k.popup,
1480
- sideOffset: 2,
1481
- side: "bottom",
1482
- align: "start",
1483
- collisionPadding: 16,
1484
- avoidCollisions: !0,
1485
- hideWhenDetached: !1,
1486
- onOpenAutoFocus: (l) => {
1487
- l.preventDefault();
1488
- },
1489
- onInteractOutside: (l) => {
1490
- l.preventDefault();
1491
- },
1492
- children: [
1493
- !u && d !== "" && /* @__PURE__ */ A("div", { className: k.breadcrumb, children: [
1494
- /* @__PURE__ */ f(
1495
- "span",
1496
- {
1497
- className: k.breadcrumbLink,
1498
- onMouseDown: (l) => {
1499
- l.preventDefault(), n();
1500
- },
1501
- children: "All items"
1502
- }
1503
- ),
1504
- /* @__PURE__ */ f("span", { className: k.breadcrumbSeparator, children: " / " }),
1505
- /* @__PURE__ */ f("span", { className: k.breadcrumbCurrent, children: "search" })
1506
- ] }),
1507
- u && t && /* @__PURE__ */ A("div", { className: k.breadcrumb, children: [
1508
- /* @__PURE__ */ f(
1509
- "span",
1510
- {
1511
- className: k.breadcrumbLink,
1512
- onMouseDown: (l) => {
1513
- l.preventDefault(), n();
1514
- },
1515
- children: "All items"
1516
- }
1517
- ),
1518
- /* @__PURE__ */ f("span", { className: k.breadcrumbSeparator, children: " / " }),
1519
- /* @__PURE__ */ f("span", { className: k.breadcrumbCurrent, children: t })
1520
- ] }),
1521
- d === "" && r.length === 0 && o.length > 0 && /* @__PURE__ */ f("div", { className: k.typeToSearch, children: "Type to search" }),
1522
- r.length > 0 && /* @__PURE__ */ f("div", { className: k.section, children: r.map((l) => {
1523
- const g = a.indexOf(l);
1524
- return /* @__PURE__ */ f(
1525
- "div",
1526
- {
1527
- ref: (p) => {
1528
- m.current[g] = p;
1529
- },
1530
- className: `${k.option} ${g === s ? k.optionActive : ""}`,
1531
- onMouseDown: (p) => {
1532
- p.preventDefault(), c(g);
1533
- },
1534
- onMouseEnter: () => {
1535
- },
1536
- children: /* @__PURE__ */ f(ft, { name: l.label })
1537
- },
1538
- l.id
1539
- );
1540
- }) }),
1541
- o.length > 0 && /* @__PURE__ */ f("div", { className: k.section, children: o.map((l) => {
1542
- const g = a.indexOf(l);
1543
- return /* @__PURE__ */ f(
1544
- "div",
1545
- {
1546
- ref: (p) => {
1547
- m.current[g] = p;
1548
- },
1549
- className: `${k.option} ${g === s ? k.optionActive : ""}`,
1550
- onMouseDown: (p) => {
1551
- p.preventDefault(), c(g);
1552
- },
1553
- onMouseEnter: () => {
1554
- },
1555
- children: /* @__PURE__ */ f(ht, { name: l.label })
1556
- },
1557
- l.id
1558
- );
1559
- }) }),
1560
- o.length === 0 && r.length === 0 && /* @__PURE__ */ f("div", { className: k.emptyState, children: u ? "No memories found" : "No memory types have been added" })
1561
- ]
1562
- }
1563
- ) })
1564
- ] });
1565
- }, kt = ({
1566
- onChange: e,
1567
- onMemoryTypeChange: a,
1568
- onTitleQueryChange: s,
1569
- onMentionChange: c,
1570
- onChangeMentionPlaceholders: i,
1571
- onSubmit: d,
1572
- memoryTypes: u,
1573
- memories: t
1574
- }) => {
1575
- var ge;
1576
- const [n, h] = x(""), [m, r] = x(""), [o, l] = x(""), [g, p] = x(!1), [C, y] = x(0), [S, M] = x(0), [W, E] = x(null), [v, U] = x(0), [P, Q] = x(null), D = _(null), X = _(null), te = _(!1), [ce, At] = x([]), ne = _(/* @__PURE__ */ new Map()), re = G(() => {
1577
- const b = /* @__PURE__ */ new Map();
1578
- return ne.current.forEach((w, O) => {
1579
- b.set(O, w);
1580
- }), t.forEach((w) => {
1581
- b.set(w.id, w);
1582
- }), Array.from(b.values()).map((w) => ({
1583
- id: w.id,
1584
- label: w.title ?? ""
1585
- }));
1586
- }, [t]);
1587
- N(() => {
1588
- const b = setTimeout(() => {
1589
- l(m);
1590
- }, 300);
1591
- return () => {
1592
- clearTimeout(b);
1593
- };
1594
- }, [m]);
1595
- const z = G(() => {
1596
- const b = P !== null || m !== "", w = P === null && m === "";
1597
- return [
1598
- ...b ? t.map((T) => ({
1599
- type: "option",
1600
- id: T.id,
1601
- label: T.title ?? ""
1602
- })) : ce.map((T) => ({
1603
- type: "option",
1604
- id: T.id,
1605
- label: T.label
1606
- })),
1607
- ...w ? u.map((T) => ({
1608
- type: "category",
1609
- id: T.id,
1610
- label: T.name
1611
- })) : []
1612
- ];
1613
- }, [ce, u, P, t, m]), { processText: q, extractMentionIds: ve, buildPlaceholderText: Ie } = ut({
1614
- options: re,
1615
- onMentionChange: c,
1616
- onChangeMentionPlaceholders: i
1617
- }), { updateMention: ie, closePopup: le } = mt({
1618
- setQuery: r,
1619
- setIsOpen: p,
1620
- setAtPosition: M
1621
- });
1622
- N(() => {
1623
- a(P), P && s("");
1624
- }, [P, a, s]), N(() => {
1625
- (o !== "" || P !== null) && s(o);
1626
- }, [o, P, s]);
1627
- const { getCaretPosition: oe, setCaretPosition: ae, getPlainText: J } = it(D), { updateContent: R, haveMentionsChanged: ue, updateMentionSignature: K } = dt({
1628
- editableRef: D,
1629
- options: re,
1630
- mentionClassName: V.mention,
1631
- getCaretPosition: oe,
1632
- setCaretPosition: ae
1633
- });
1634
- function de(b) {
1635
- const w = z[b];
1636
- if (!w) return;
1637
- if (w.type === "category") {
1638
- Q(w.id), r("");
1639
- return;
1640
- }
1641
- Q(null);
1642
- const O = t.find((Y) => Y.id === w.id);
1643
- O && ne.current.set(O.id, O);
1644
- const T = n, F = T.slice(0, C), B = T.slice(C), L = F.lastIndexOf("@");
1645
- if (L === -1) return;
1646
- const j = F.slice(0, L) + "@" + w.label + " " + B, he = F.slice(0, L).length + w.label.length + 2;
1647
- h(j), e(j), q(j), le(), K(j), requestAnimationFrame(() => {
1648
- R(j, !1), requestAnimationFrame(() => {
1649
- var Y;
1650
- (Y = D.current) == null || Y.focus(), ae(he), y(he);
1651
- });
1652
- });
1653
- }
1654
- const { handleKeyDown: Te } = lt({
1655
- onArrowDown: () => {
1656
- U(
1657
- (b) => (b + 1) % z.length
1658
- );
1659
- },
1660
- onArrowUp: () => {
1661
- U(
1662
- (b) => (b - 1 + z.length) % z.length
1663
- );
1664
- },
1665
- onEnter: () => {
1666
- de(v);
1667
- },
1668
- onEscape: () => {
1669
- P ? Q(null) : le();
1670
- }
1671
- }), me = I(() => {
1672
- if (te.current) return;
1673
- const b = J(), w = oe();
1674
- h(b), e(b), q(b), y(w), ie(b, w), (ue(b) || b.trim() === "") && R(b, !0);
1675
- }, [
1676
- J,
1677
- oe,
1678
- ie,
1679
- e,
1680
- q,
1681
- ue,
1682
- R,
1683
- y
1684
- ]);
1685
- return N(() => {
1686
- D.current && !D.current.textContent && (K(n), R(n, !1));
1687
- }, [n, R, K]), N(() => {
1688
- if (!D.current) return;
1689
- J() !== n && !te.current && (K(n), R(n, !0));
1690
- }, [n, J, R, K]), pe(() => {
1691
- if (!g || !X.current) {
1692
- E(null);
1693
- return;
1694
- }
1695
- const w = X.current.querySelector("span[data-at-marker]");
1696
- w instanceof HTMLElement ? E(w) : E(null);
1697
- }, [C, m, g, n, X, E]), /* @__PURE__ */ A("div", { className: V.wrapper, children: [
1698
- /* @__PURE__ */ f(
1699
- st,
1700
- {
1701
- editableRef: D,
1702
- onInput: me,
1703
- onKeyDown: (b) => {
1704
- if (!(g && Te(b)) && b.key === "Enter" && !b.shiftKey && !g) {
1705
- if (b.preventDefault(), d && n.trim()) {
1706
- const w = Ie(n), T = ve(n).map((F) => re.find((B) => B.id === F)).filter((F) => F !== void 0);
1707
- d(n, w, T), h(""), e(""), q(""), R("", !1), ne.current.clear();
1708
- }
1709
- return;
1710
- }
1711
- },
1712
- isComposingRef: te,
1713
- handleInput: me
1714
- }
1715
- ),
1716
- /* @__PURE__ */ f(
1717
- ct,
1718
- {
1719
- ghostRef: X,
1720
- isOpen: g,
1721
- value: n,
1722
- atPosition: S,
1723
- caretPos: C
1724
- }
1725
- ),
1726
- /* @__PURE__ */ f(
1727
- Tt,
1728
- {
1729
- isOpen: g,
1730
- options: z,
1731
- highlightedIndex: v,
1732
- onSelect: de,
1733
- caretElement: W,
1734
- query: m,
1735
- isInCategory: P !== null,
1736
- categoryName: P && ((ge = u.find((b) => b.id === P)) == null ? void 0 : ge.name) || null,
1737
- onResetQuery: () => {
1738
- r(""), l(""), P && Q(null);
1739
- const b = n, w = b.slice(0, C), O = b.slice(C), T = w.lastIndexOf("@");
1740
- if (T !== -1) {
1741
- const F = b.slice(0, T + 1) + O, B = T + 1;
1742
- h(F), e(F), q(F), requestAnimationFrame(() => {
1743
- R(F, !1), requestAnimationFrame(() => {
1744
- var L;
1745
- (L = D.current) == null || L.focus(), ae(B), y(B);
1746
- });
1747
- });
1748
- }
1749
- }
1750
- }
1751
- )
1752
- ] });
1753
- }, Ot = ({
1754
- height: e = "100vh",
1755
- fetchListMemoryTypesClientSecret: a,
1756
- fetchSearchMemoriesClientSecret: s,
1757
- fetchCreateAgentTaskClientSecret: c,
1758
- fetchCreateStreamClientSecret: i,
1759
- fetchGetDownloadLinkClientSecret: d
1760
- }) => {
1761
- const { createAgentTask: u, agentTasks: t } = je({
1762
- fetchCreateStreamClientSecret: i,
1763
- fetchCreateAgentTaskClientSecret: c
1764
- }), [n, h] = x(""), [m, r] = x(null), [o, l] = x(null), { listFirstPage: g } = Qe(), { search: p } = Ge(), [C, y] = x(
1765
- null
1766
- ), [S, M] = x(null), W = _(!1);
1767
- N(() => {
1768
- W.current || (W.current = !0, g({
1769
- fetchClientSecret: a
1770
- }).then((v) => {
1771
- v.type === "success" && y(v.page.items);
1772
- }));
1773
- }, [g, a]), N(() => {
1774
- m === null && n === "" || p({
1775
- fetchClientSecret: s,
1776
- memoryTypeId: m ?? void 0,
1777
- title: n
1778
- }).then((v) => {
1779
- v.type === "success" && M(v.items);
1780
- });
1781
- }, [m, o, n]);
1782
- const E = G(() => t.flatMap((v) => /* @__PURE__ */ f(et, { agentTask: v, fetchGetDownloadLinkClientSecret: d }, v.streamId)), [t]);
1783
- return /* @__PURE__ */ A(
1784
- "div",
1785
- {
1786
- style: {
1787
- display: "flex",
1788
- flexDirection: "column",
1789
- height: e,
1790
- maxWidth: "100vw",
1791
- overflow: "hidden"
1792
- },
1793
- children: [
1794
- E,
1795
- /* @__PURE__ */ f(
1796
- kt,
1797
- {
1798
- memoryTypes: C ?? [],
1799
- memories: S ?? [],
1800
- onMemoryTypeChange: (v) => {
1801
- r(v);
1802
- },
1803
- onTitleQueryChange: (v) => {
1804
- h(v);
1805
- },
1806
- onChange: (v) => {
1807
- },
1808
- onMentionChange: (v) => {
1809
- l(v);
1810
- },
1811
- onChangeMentionPlaceholders: (v, U) => {
1812
- },
1813
- onSubmit: (v, U, P) => {
1814
- u({
1815
- queryText: `
1816
- ${U}
1817
-
1818
- ${JSON.stringify(P, null, 2)}
1819
- `.trim()
1820
- });
1821
- }
1822
- }
1823
- )
1824
- ]
1825
- }
1826
- );
1827
1189
  };
1828
- function Ut({ fency: e, children: a }) {
1829
- const [s, c] = x(
1190
+ function xe({ fency: e, children: t }) {
1191
+ const [o, i] = T(
1830
1192
  null
1831
- ), [i, d] = x(!0), [u, t] = x(null), [n, h] = x(null), m = _(null);
1832
- N(() => {
1833
- e.then((l) => {
1834
- c(l), d(!1);
1835
- }).catch((l) => {
1836
- t(l), d(!1);
1193
+ ), [s, m] = T(!0), [u, a] = T(null), [n, d] = T(null), l = F(null);
1194
+ x(() => {
1195
+ e.then((f) => {
1196
+ i(f), m(!1);
1197
+ }).catch((f) => {
1198
+ a(f), m(!1);
1837
1199
  });
1838
1200
  }, [e]);
1839
- const r = I(
1840
- async (l, g = 3e4) => {
1841
- if (m.current)
1842
- return m.current;
1843
- const p = Date.now();
1844
- if (n && p - n.createdAt < g)
1201
+ const c = D(
1202
+ async (f, h = 3e4) => {
1203
+ if (l.current)
1204
+ return l.current;
1205
+ const b = Date.now();
1206
+ if (n && b - n.createdAt < h)
1845
1207
  return n.stream;
1846
- const C = (async () => {
1847
- if (!s)
1208
+ const w = (async () => {
1209
+ if (!o)
1848
1210
  throw new Error("Fency instance not initialized");
1849
- const y = await l(), S = await Ne({
1850
- pk: s.publishableKey,
1851
- baseUrl: s.baseUrl,
1852
- clientSecret: y == null ? void 0 : y.clientSecret
1211
+ const y = await f(), k = await V({
1212
+ pk: o.publishableKey,
1213
+ baseUrl: o.baseUrl,
1214
+ clientToken: (y == null ? void 0 : y.clientToken) ?? ""
1853
1215
  });
1854
- if (S.type === "success") {
1855
- const M = {
1856
- stream: S.stream,
1216
+ if (k.type === "success") {
1217
+ const v = {
1218
+ stream: k.stream,
1857
1219
  createdAt: Date.now()
1858
1220
  };
1859
- return h(M), m.current = null, S.stream;
1221
+ return d(v), l.current = null, k.stream;
1860
1222
  } else
1861
- throw m.current = null, new Error("Failed to create stream");
1223
+ throw l.current = null, new Error("Failed to create stream");
1862
1224
  })();
1863
- return m.current = C, C;
1225
+ return l.current = w, w;
1864
1226
  },
1865
- [s, n]
1227
+ [o, n]
1866
1228
  );
1867
1229
  if (u)
1868
- return /* @__PURE__ */ A("div", { children: [
1230
+ return /* @__PURE__ */ I("div", { children: [
1869
1231
  "Fency error: ",
1870
1232
  u.message
1871
1233
  ] });
1872
- if (!s)
1234
+ if (!o)
1873
1235
  return null;
1874
- const o = {
1875
- fency: s,
1876
- loading: i,
1236
+ const r = {
1237
+ fency: o,
1238
+ loading: s,
1877
1239
  error: u,
1878
1240
  activeStream: n,
1879
- getOrCreateStream: r
1241
+ getOrCreateStream: c
1880
1242
  };
1881
- return /* @__PURE__ */ f(we.Provider, { value: o, children: a });
1243
+ return /* @__PURE__ */ g($.Provider, { value: r, children: t });
1882
1244
  }
1883
1245
  export {
1884
- et as AgentTaskProgress,
1885
- Ot as Chat,
1886
- Ze as ChatResponse,
1887
- Xe as ChatResponseComplete,
1888
- Je as ChatResponseLoading,
1889
- Ye as ChatResponseThinking,
1890
- Ut as FencyProvider,
1891
- kt as MentionInput,
1892
- Tt as MentionPopover,
1893
- se as ShimmeringText,
1894
- je as useAgentTasks,
1895
- Re as useFencyEventSource,
1896
- Qe as useListMemoryTypes,
1897
- Ve as usePaginatedQuery,
1898
- Ge as useSearchMemories,
1899
- Ke as useStream
1246
+ Pe as AgentTaskProgress,
1247
+ he as ChatResponse,
1248
+ ge as ChatResponseComplete,
1249
+ fe as ChatResponseLoading,
1250
+ ye as ChatResponseThinking,
1251
+ xe as FencyProvider,
1252
+ M as ShimmeringText,
1253
+ Ce as useAgentTasks,
1254
+ R as useFencyContext,
1255
+ ae as useFencyEventSource,
1256
+ Ae as usePaginatedQuery,
1257
+ me as useStream
1900
1258
  };