@fencyai/react 0.1.119 → 0.1.120

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