@fencyai/react 0.1.119 → 0.1.121

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