@fencyai/react 0.1.117 → 0.1.119

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