@fencyai/react 0.1.112 → 0.1.113

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,14 +1,14 @@
1
1
  import { createAgentTask as q, createFileDownloadLink as V, createStream as X } from "@fencyai/js";
2
- import { createContext as J, useContext as Y, useState as S, useRef as P, useEffect as v, useCallback as U, useMemo as _ } from "react";
3
- import { jsx as g, jsxs as A } from "react/jsx-runtime";
4
- import { useInView as Q, motion as E, AnimatePresence as z } from "motion/react";
5
- import H from "react-markdown";
6
- import { Prism as W } from "react-syntax-highlighter";
7
- import G from "remark-gfm";
2
+ import { createContext as J, useContext as Y, useState as w, useRef as P, useEffect as T, useCallback as U, useMemo as L } from "react";
3
+ import { jsx as g, jsxs as E } from "react/jsx-runtime";
4
+ import { useInView as Q, motion as A, AnimatePresence as W } from "motion/react";
5
+ import D from "react-markdown";
6
+ import { Prism as M } from "react-syntax-highlighter";
7
+ import B from "remark-gfm";
8
8
  import './assets/index.css';const j = J(
9
9
  void 0
10
10
  );
11
- function R() {
11
+ function F() {
12
12
  const e = Y(j);
13
13
  if (e === void 0)
14
14
  throw new Error("useFencyContext must be used within a FencyProvider");
@@ -50,50 +50,50 @@ const Z = (e) => {
50
50
  createdAt: e.createdAt,
51
51
  data: JSON.parse(e.data)
52
52
  }), re = (e) => {
53
- const t = R(), [n, r] = S(null), a = P(`subscriber-${Math.random().toString(36).substr(2, 9)}`);
54
- return v(() => {
53
+ const t = F(), [r, n] = w(null), a = P(`subscriber-${Math.random().toString(36).substr(2, 9)}`);
54
+ return T(() => {
55
55
  if (!t.eventManager) return;
56
- const s = {
57
- onMessage: (o, c) => {
58
- var i, u, m, b, h, w, y, k, C, I;
59
- const l = Z(o);
60
- if (l)
61
- switch (l.type) {
56
+ const c = {
57
+ onMessage: (o, i) => {
58
+ var s, d, f, y, S, b, h, k, I, C;
59
+ const m = Z(o);
60
+ if (m)
61
+ switch (m.type) {
62
62
  case "NewChatCompletionStreamChunk":
63
- (i = e == null ? void 0 : e.onNewChatCompletionStreamChunk) == null || i.call(e, l);
63
+ (s = e == null ? void 0 : e.onNewChatCompletionStreamChunk) == null || s.call(e, m);
64
64
  break;
65
65
  case "ChatCompletionStreamCompleted":
66
- (u = e == null ? void 0 : e.onChatCompletionStreamCompleted) == null || u.call(e, l);
66
+ (d = e == null ? void 0 : e.onChatCompletionStreamCompleted) == null || d.call(e, m);
67
67
  break;
68
68
  case "StreamTimeout":
69
- (m = e == null ? void 0 : e.onStreamTimeout) == null || m.call(e, l);
69
+ (f = e == null ? void 0 : e.onStreamTimeout) == null || f.call(e, m);
70
70
  break;
71
71
  case "StreamNotFound":
72
- (b = e == null ? void 0 : e.onStreamNotFound) == null || b.call(e, l);
72
+ (y = e == null ? void 0 : e.onStreamNotFound) == null || y.call(e, m);
73
73
  break;
74
74
  case "FileUploadCompleted":
75
- (h = e == null ? void 0 : e.onFileUploadCompleted) == null || h.call(e, l);
75
+ (S = e == null ? void 0 : e.onFileUploadCompleted) == null || S.call(e, m);
76
76
  break;
77
77
  case "FileTextContentReady":
78
- (w = e == null ? void 0 : e.onFileTextContentReady) == null || w.call(e, l);
78
+ (b = e == null ? void 0 : e.onFileTextContentReady) == null || b.call(e, m);
79
79
  break;
80
80
  case "WebsiteHtmlContentReady":
81
- (y = e == null ? void 0 : e.onWebsiteHtmlContentReady) == null || y.call(e, l);
81
+ (h = e == null ? void 0 : e.onWebsiteHtmlContentReady) == null || h.call(e, m);
82
82
  break;
83
83
  case "WebsiteTextContentReady":
84
- (k = e == null ? void 0 : e.onWebsiteTextContentReady) == null || k.call(e, l);
84
+ (k = e == null ? void 0 : e.onWebsiteTextContentReady) == null || k.call(e, m);
85
85
  break;
86
86
  case "FileSearchIndexReady":
87
- (C = e == null ? void 0 : e.onFileSearchIndexReady) == null || C.call(e, l);
87
+ (I = e == null ? void 0 : e.onFileSearchIndexReady) == null || I.call(e, m);
88
88
  break;
89
89
  case "AgentTaskProgressItemUpdated":
90
- (I = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || I.call(e, l);
90
+ (C = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || C.call(e, m);
91
91
  break;
92
92
  }
93
93
  },
94
94
  onError: (o) => {
95
- var c;
96
- (c = e == null ? void 0 : e.onStreamError) == null || c.call(e, {
95
+ var i;
96
+ (i = e == null ? void 0 : e.onStreamError) == null || i.call(e, {
97
97
  streamId: o,
98
98
  error: {
99
99
  code: "UnknownError",
@@ -104,91 +104,74 @@ const Z = (e) => {
104
104
  };
105
105
  return t.eventManager.subscribe(
106
106
  a.current,
107
- s
107
+ c
108
108
  );
109
109
  }, [t.eventManager, e]), {
110
110
  createStream: async () => {
111
111
  try {
112
- const s = await t.getOrCreateStream(e.fetchTokens, 3e4);
113
- return r(s), {
112
+ const c = await t.getOrCreateStream(3e4);
113
+ return n(c), {
114
114
  type: "success",
115
- stream: s
115
+ stream: c
116
116
  };
117
- } catch (s) {
117
+ } catch (c) {
118
118
  return {
119
119
  type: "error",
120
120
  error: {
121
121
  code: "UnknownError",
122
- message: s instanceof Error ? s.message : "Failed to create stream"
122
+ message: c instanceof Error ? c.message : "Failed to create stream"
123
123
  }
124
124
  };
125
125
  }
126
126
  },
127
- stream: n
127
+ stream: r
128
128
  };
129
- }, Ee = (e) => {
130
- const t = R(), [n, r] = S([]), a = P(/* @__PURE__ */ new Set()), { createStream: f } = re({
131
- fetchTokens: e.fetchCreateStreamTokens,
129
+ }, Re = (e) => {
130
+ const t = F(), [r, n] = w([]), a = P(/* @__PURE__ */ new Set()), { createStream: u } = re({
132
131
  onAgentTaskProgressItemUpdated: (o) => {
133
- var c;
134
- a.current.has(o.agentTaskId) && ((c = e.onAgentTaskProgressItemUpdated) == null || c.call(e, o), r((l) => {
135
- const i = l.find(
136
- (m) => m.streamId === o.streamId
137
- );
138
- return i ? i.progressItems.map(
139
- (m) => m.progressItemId
140
- ).includes(o.progressItemId) ? [
141
- ...l.filter((m) => m.streamId !== o.streamId),
142
- {
143
- ...i,
144
- progressItems: i.progressItems.map(
145
- (m) => m.progressItemId === o.progressItemId ? o : m
146
- )
147
- }
148
- ] : [
149
- ...l.filter(
150
- (m) => m.streamId !== o.streamId
151
- ),
152
- {
153
- ...i,
154
- progressItems: [
155
- ...i.progressItems,
156
- o
157
- ]
158
- }
159
- ] : l;
160
- }));
132
+ var i;
133
+ a.current.has(o.agentTaskId) && ((i = e.onAgentTaskProgressItemUpdated) == null || i.call(e, o), n(
134
+ (m) => m.map((s) => {
135
+ if (s.streamId !== o.streamId) return s;
136
+ const f = s.progressItems.some(
137
+ (y) => y.progressItemId === o.progressItemId
138
+ ) ? s.progressItems.map(
139
+ (y) => y.progressItemId === o.progressItemId ? o : y
140
+ ) : [...s.progressItems, o];
141
+ return { ...s, progressItems: f };
142
+ })
143
+ ));
161
144
  },
162
145
  onStreamError: (o) => {
163
- var c;
164
- (c = e == null ? void 0 : e.onStreamError) == null || c.call(e, o), r((l) => {
165
- const i = l.find((u) => u.streamId === o.streamId);
166
- return i ? [
167
- ...l.filter((u) => u.streamId !== o.streamId),
146
+ var i;
147
+ (i = e == null ? void 0 : e.onStreamError) == null || i.call(e, o), n((m) => {
148
+ const s = m.find((d) => d.streamId === o.streamId);
149
+ return s ? [
150
+ ...m.filter((d) => d.streamId !== o.streamId),
168
151
  {
169
- ...i,
152
+ ...s,
170
153
  loading: !1,
171
154
  error: o.error
172
155
  }
173
- ] : l;
156
+ ] : m;
174
157
  });
175
158
  },
176
159
  onStreamNotFound: (o) => {
177
- var c;
178
- (c = e == null ? void 0 : e.onStreamNotFound) == null || c.call(e, o);
160
+ var i;
161
+ (i = e == null ? void 0 : e.onStreamNotFound) == null || i.call(e, o);
179
162
  },
180
163
  onStreamTimeout: (o) => {
181
- var c;
182
- (c = e == null ? void 0 : e.onStreamTimeout) == null || c.call(e, o);
164
+ var i;
165
+ (i = e == null ? void 0 : e.onStreamTimeout) == null || i.call(e, o);
183
166
  }
184
- }), s = U(
167
+ }), c = U(
185
168
  async (o) => {
186
- const c = await f();
187
- if (c.type === "success") {
188
- r([
189
- ...n,
169
+ const i = await u();
170
+ if (i.type === "success") {
171
+ n([
172
+ ...r,
190
173
  {
191
- streamId: c.stream.id,
174
+ streamId: i.stream.id,
192
175
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
193
176
  confirmedData: null,
194
177
  error: null,
@@ -198,53 +181,53 @@ const Z = (e) => {
198
181
  doneStreaming: !1
199
182
  }
200
183
  ]);
201
- const { clientToken: l } = await e.fetchClientToken(), i = await q({
184
+ const { clientToken: m } = await e.fetchCreateAgentTaskClientToken(o.type), s = await q({
202
185
  pk: t.fency.publishableKey,
203
186
  baseUrl: t.fency.baseUrl,
204
- clientToken: l,
205
- streamToken: c.stream.token,
187
+ clientToken: m,
188
+ streamToken: i.stream.token,
206
189
  request: {
207
- genericTask: {
208
- queryText: o.queryText,
209
- jsonSchema: o.jsonSchema
210
- }
190
+ genericTask: o.type === "genericAgentTask" ? { queryText: o.query, jsonSchema: o.jsonSchema } : void 0,
191
+ streamingChatCompletionTask: o.type === "streamingChatCompletion" ? { prompt: o.prompt } : void 0
211
192
  }
212
193
  });
213
- if (i.type === "success" && i.agentTask)
214
- return a.current.add(i.agentTask.id), r((u) => [
215
- ...u.filter(
216
- (m) => m.streamId !== c.stream.id
194
+ if (s.type === "success" && s.agentTask)
195
+ return a.current.add(
196
+ s.agentTask.id
197
+ ), n((d) => [
198
+ ...d.filter(
199
+ (f) => f.streamId !== i.stream.id
217
200
  ),
218
201
  {
219
- streamId: c.stream.id,
202
+ streamId: i.stream.id,
220
203
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
221
- taskId: i.agentTask.id,
222
- createdAt: i.agentTask.createdAt,
204
+ taskId: s.agentTask.id,
205
+ createdAt: s.agentTask.createdAt,
223
206
  error: null,
224
207
  params: o,
225
208
  progressItems: [],
226
209
  doneStreaming: !1,
227
210
  loading: !0,
228
211
  confirmedData: {
229
- taskId: i.agentTask.id,
230
- createdAt: i.agentTask.createdAt
212
+ taskId: s.agentTask.id,
213
+ createdAt: s.agentTask.createdAt
231
214
  }
232
215
  }
233
216
  ]), {
234
217
  type: "success",
235
- streamId: c.stream.id,
236
- agentTaskId: i.agentTask.id
218
+ streamId: i.stream.id,
219
+ agentTaskId: s.agentTask.id
237
220
  };
238
- if (i.type === "error")
239
- return r((u) => [
240
- ...u.filter(
241
- (m) => m.streamId !== c.stream.id
221
+ if (s.type === "error")
222
+ return n((d) => [
223
+ ...d.filter(
224
+ (f) => f.streamId !== i.stream.id
242
225
  ),
243
226
  {
244
227
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
245
- streamId: c.stream.id,
228
+ streamId: i.stream.id,
246
229
  params: o,
247
- error: i.error,
230
+ error: s.error,
248
231
  progressItems: [],
249
232
  loading: !1,
250
233
  doneStreaming: !1,
@@ -252,21 +235,21 @@ const Z = (e) => {
252
235
  }
253
236
  ]), {
254
237
  type: "error",
255
- error: i.error
238
+ error: s.error
256
239
  };
257
240
  {
258
- const u = {
241
+ const d = {
259
242
  message: "No response received",
260
243
  code: "UnknownError"
261
244
  };
262
- return r((m) => [
263
- ...m.filter(
264
- (b) => b.streamId !== c.stream.id
245
+ return n((f) => [
246
+ ...f.filter(
247
+ (y) => y.streamId !== i.stream.id
265
248
  ),
266
249
  {
267
250
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
268
- streamId: c.stream.id,
269
- error: u,
251
+ streamId: i.stream.id,
252
+ error: d,
270
253
  params: o,
271
254
  progressItems: [],
272
255
  loading: !1,
@@ -275,87 +258,87 @@ const Z = (e) => {
275
258
  }
276
259
  ]), {
277
260
  type: "error",
278
- error: u
261
+ error: d
279
262
  };
280
263
  }
281
264
  } else
282
- return console.error(c.error), c;
265
+ return console.error(i.error), i;
283
266
  },
284
- [t, n, f]
285
- ), d = _(() => n.sort((o, c) => new Date(c.triggeredAt).getTime() - new Date(o.triggeredAt).getTime())[0], [n]);
286
- return v(() => () => {
267
+ [t, r, u]
268
+ ), l = L(() => r.sort((o, i) => new Date(i.triggeredAt).getTime() - new Date(o.triggeredAt).getTime())[0], [r]);
269
+ return T(() => () => {
287
270
  a.current.clear();
288
271
  }, []), {
289
- agentTasks: n,
290
- createAgentTask: s,
291
- latest: d
272
+ agentTasks: r,
273
+ createAgentTask: c,
274
+ latest: l
292
275
  };
293
276
  };
294
277
  async function ae(e, t) {
295
- const n = e.getReader();
296
- let r;
297
- for (; !(r = await n.read()).done; )
298
- t(r.value);
278
+ const r = e.getReader();
279
+ let n;
280
+ for (; !(n = await r.read()).done; )
281
+ t(n.value);
299
282
  }
300
283
  function oe(e) {
301
- let t, n, r, a = !1;
302
- return function(s) {
303
- t === void 0 ? (t = s, n = 0, r = -1) : t = se(t, s);
304
- const d = t.length;
284
+ let t, r, n, a = !1;
285
+ return function(c) {
286
+ t === void 0 ? (t = c, r = 0, n = -1) : t = se(t, c);
287
+ const l = t.length;
305
288
  let o = 0;
306
- for (; n < d; ) {
307
- a && (t[n] === 10 && (o = ++n), a = !1);
308
- let c = -1;
309
- for (; n < d && c === -1; ++n)
310
- switch (t[n]) {
289
+ for (; r < l; ) {
290
+ a && (t[r] === 10 && (o = ++r), a = !1);
291
+ let i = -1;
292
+ for (; r < l && i === -1; ++r)
293
+ switch (t[r]) {
311
294
  case 58:
312
- r === -1 && (r = n - o);
295
+ n === -1 && (n = r - o);
313
296
  break;
314
297
  case 13:
315
298
  a = !0;
316
299
  case 10:
317
- c = n;
300
+ i = r;
318
301
  break;
319
302
  }
320
- if (c === -1)
303
+ if (i === -1)
321
304
  break;
322
- e(t.subarray(o, c), r), o = n, r = -1;
305
+ e(t.subarray(o, i), n), o = r, n = -1;
323
306
  }
324
- o === d ? t = void 0 : o !== 0 && (t = t.subarray(o), n -= o);
307
+ o === l ? t = void 0 : o !== 0 && (t = t.subarray(o), r -= o);
325
308
  };
326
309
  }
327
- function ie(e, t, n) {
328
- let r = D();
310
+ function ie(e, t, r) {
311
+ let n = H();
329
312
  const a = new TextDecoder();
330
- return function(s, d) {
331
- if (s.length === 0)
332
- n == null || n(r), r = D();
333
- else if (d > 0) {
334
- const o = a.decode(s.subarray(0, d)), c = d + (s[d + 1] === 32 ? 2 : 1), l = a.decode(s.subarray(c));
313
+ return function(c, l) {
314
+ if (c.length === 0)
315
+ r == null || r(n), n = H();
316
+ else if (l > 0) {
317
+ const o = a.decode(c.subarray(0, l)), i = l + (c[l + 1] === 32 ? 2 : 1), m = a.decode(c.subarray(i));
335
318
  switch (o) {
336
319
  case "data":
337
- r.data = r.data ? r.data + `
338
- ` + l : l;
320
+ n.data = n.data ? n.data + `
321
+ ` + m : m;
339
322
  break;
340
323
  case "event":
341
- r.event = l;
324
+ n.event = m;
342
325
  break;
343
326
  case "id":
344
- e(r.id = l);
327
+ e(n.id = m);
345
328
  break;
346
329
  case "retry":
347
- const i = parseInt(l, 10);
348
- isNaN(i) || t(r.retry = i);
330
+ const s = parseInt(m, 10);
331
+ isNaN(s) || t(n.retry = s);
349
332
  break;
350
333
  }
351
334
  }
352
335
  };
353
336
  }
354
337
  function se(e, t) {
355
- const n = new Uint8Array(e.length + t.length);
356
- return n.set(e), n.set(t, e.length), n;
338
+ const r = new Uint8Array(e.length + t.length);
339
+ return r.set(e), r.set(t, e.length), r;
357
340
  }
358
- function D() {
341
+ function H() {
359
342
  return {
360
343
  data: "",
361
344
  event: "",
@@ -364,49 +347,49 @@ function D() {
364
347
  };
365
348
  }
366
349
  var ce = function(e, t) {
367
- var n = {};
368
- for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]);
350
+ var r = {};
351
+ for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
369
352
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
370
- for (var a = 0, r = Object.getOwnPropertySymbols(e); a < r.length; a++)
371
- t.indexOf(r[a]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[a]) && (n[r[a]] = e[r[a]]);
372
- return n;
353
+ for (var a = 0, n = Object.getOwnPropertySymbols(e); a < n.length; a++)
354
+ t.indexOf(n[a]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[a]) && (r[n[a]] = e[n[a]]);
355
+ return r;
373
356
  };
374
- const O = "text/event-stream", le = 1e3, B = "last-event-id";
375
- function L(e, t) {
376
- var { signal: n, headers: r, onopen: a, onmessage: f, onclose: s, onerror: d, openWhenHidden: o, fetch: c } = t, l = ce(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
377
- return new Promise((i, u) => {
378
- const m = Object.assign({}, r);
379
- m.accept || (m.accept = O);
380
- let b;
381
- function h() {
382
- b.abort(), document.hidden || x();
357
+ const O = "text/event-stream", le = 1e3, G = "last-event-id";
358
+ function $(e, t) {
359
+ var { signal: r, headers: n, onopen: a, onmessage: u, onclose: c, onerror: l, openWhenHidden: o, fetch: i } = t, m = ce(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
360
+ return new Promise((s, d) => {
361
+ const f = Object.assign({}, n);
362
+ f.accept || (f.accept = O);
363
+ let y;
364
+ function S() {
365
+ y.abort(), document.hidden || x();
383
366
  }
384
- o || document.addEventListener("visibilitychange", h);
385
- let w = le, y = 0;
367
+ o || document.addEventListener("visibilitychange", S);
368
+ let b = le, h = 0;
386
369
  function k() {
387
- document.removeEventListener("visibilitychange", h), window.clearTimeout(y), b.abort();
370
+ document.removeEventListener("visibilitychange", S), window.clearTimeout(h), y.abort();
388
371
  }
389
- n == null || n.addEventListener("abort", () => {
390
- k(), i();
372
+ r == null || r.addEventListener("abort", () => {
373
+ k(), s();
391
374
  });
392
- const C = c ?? window.fetch, I = a ?? de;
375
+ const I = i ?? window.fetch, C = a ?? de;
393
376
  async function x() {
394
377
  var N;
395
- b = new AbortController();
378
+ y = new AbortController();
396
379
  try {
397
- const F = await C(e, Object.assign(Object.assign({}, l), { headers: m, signal: b.signal }));
398
- await I(F), await ae(F.body, oe(ie((T) => {
399
- T ? m[B] = T : delete m[B];
400
- }, (T) => {
401
- w = T;
402
- }, f))), s == null || s(), k(), i();
403
- } catch (F) {
404
- if (!b.signal.aborted)
380
+ const R = await I(e, Object.assign(Object.assign({}, m), { headers: f, signal: y.signal }));
381
+ await C(R), await ae(R.body, oe(ie((v) => {
382
+ v ? f[G] = v : delete f[G];
383
+ }, (v) => {
384
+ b = v;
385
+ }, u))), c == null || c(), k(), s();
386
+ } catch (R) {
387
+ if (!y.signal.aborted)
405
388
  try {
406
- const T = (N = d == null ? void 0 : d(F)) !== null && N !== void 0 ? N : w;
407
- window.clearTimeout(y), y = window.setTimeout(x, T);
408
- } catch (T) {
409
- k(), u(T);
389
+ const v = (N = l == null ? void 0 : l(R)) !== null && N !== void 0 ? N : b;
390
+ window.clearTimeout(h), h = window.setTimeout(x, v);
391
+ } catch (v) {
392
+ k(), d(v);
410
393
  }
411
394
  }
412
395
  }
@@ -418,15 +401,15 @@ function de(e) {
418
401
  if (!(t != null && t.startsWith(O)))
419
402
  throw new Error(`Expected content-type to be ${O}, Actual: ${t}`);
420
403
  }
421
- function Fe(e) {
422
- const [t, n] = S(null);
423
- return v(() => {
404
+ function Ne(e) {
405
+ const [t, r] = w(null);
406
+ return T(() => {
424
407
  if (!t)
425
408
  return;
426
- const r = new AbortController();
427
- return L(t, {
409
+ const n = new AbortController();
410
+ return $(t, {
428
411
  headers: e == null ? void 0 : e.headers,
429
- signal: r.signal,
412
+ signal: n.signal,
430
413
  async onopen(a) {
431
414
  if (!a.ok && a.status >= 400 && a.status < 500 && a.status !== 429)
432
415
  throw new Error(`Client error ${a.status}`);
@@ -434,74 +417,74 @@ function Fe(e) {
434
417
  onmessage(a) {
435
418
  a.data && (e == null || e.onMessage({
436
419
  url: t,
437
- data: $(a.data)
420
+ data: K(a.data)
438
421
  }));
439
422
  },
440
423
  onerror(a) {
441
- throw console.error("EventSource error:", a), e == null || e.onError(t), n(null), a;
424
+ throw console.error("EventSource error:", a), e == null || e.onError(t), r(null), a;
442
425
  },
443
426
  onclose() {
444
427
  }
445
428
  }), () => {
446
- r.abort();
429
+ n.abort();
447
430
  };
448
431
  }, [t, e == null ? void 0 : e.headers]), {
449
- setSourceUrl: n,
432
+ setSourceUrl: r,
450
433
  sourceUrl: t
451
434
  };
452
435
  }
453
- function $(e) {
454
- const t = atob(e), n = new Uint8Array(t.length);
455
- for (let r = 0; r < t.length; r++)
456
- n[r] = t.charCodeAt(r);
457
- return new TextDecoder("utf-8").decode(n);
436
+ function K(e) {
437
+ const t = atob(e), r = new Uint8Array(t.length);
438
+ for (let n = 0; n < t.length; n++)
439
+ r[n] = t.charCodeAt(n);
440
+ return new TextDecoder("utf-8").decode(r);
458
441
  }
459
- function Ne(e, t) {
460
- const [n, r] = S(
442
+ function Fe(e, t) {
443
+ const [r, n] = w(
461
444
  null
462
- ), [a, f] = S(
445
+ ), [a, u] = w(
463
446
  null
464
- ), s = R(), d = async (i) => {
465
- const u = await i.fetchTokens(), { fetchTokens: m, nextPageToken: b, previousPageToken: h, ...w } = i, y = await e({
466
- pk: s.fency.publishableKey,
467
- clientToken: u.clientToken,
468
- streamToken: u.streamToken,
447
+ ), c = F(), l = async (s) => {
448
+ const d = await s.fetchTokens(), { fetchTokens: f, nextPageToken: y, previousPageToken: S, ...b } = s, h = await e({
449
+ pk: c.fency.publishableKey,
450
+ clientToken: d.clientToken,
451
+ streamToken: d.streamToken,
469
452
  request: {
470
- ...w,
453
+ ...b,
471
454
  limit: (t == null ? void 0 : t.pageSize) ?? 50,
472
455
  pagination: {
473
- nextPageToken: b,
474
- previousPageToken: h
456
+ nextPageToken: y,
457
+ previousPageToken: S
475
458
  }
476
459
  },
477
- baseUrl: s.fency.baseUrl
460
+ baseUrl: c.fency.baseUrl
478
461
  });
479
- return y.type === "success" && y.items && y.pagination ? {
462
+ return h.type === "success" && h.items && h.pagination ? {
480
463
  type: "success",
481
464
  page: {
482
- items: y.items,
483
- hasNextPage: y.pagination.nextPageToken != null,
484
- hasPreviousPage: y.pagination.previousPageToken != null,
485
- pagination: y.pagination
465
+ items: h.items,
466
+ hasNextPage: h.pagination.nextPageToken != null,
467
+ hasPreviousPage: h.pagination.previousPageToken != null,
468
+ pagination: h.pagination
486
469
  }
487
470
  } : {
488
471
  type: "error",
489
- error: y.error ?? {
472
+ error: h.error ?? {
490
473
  code: "UNKNOWN_ERROR",
491
474
  message: "An unknown error occurred"
492
475
  }
493
476
  };
494
477
  };
495
478
  return {
496
- fetchFirstPage: async (i) => {
497
- const u = await d({
498
- ...i,
479
+ fetchFirstPage: async (s) => {
480
+ const d = await l({
481
+ ...s,
499
482
  nextPageToken: void 0,
500
483
  previousPageToken: void 0
501
484
  });
502
- return u.type === "success" && (f(u.page), r(i)), u;
485
+ return d.type === "success" && (u(d.page), n(s)), d;
503
486
  },
504
- fetchNextPage: async (i) => {
487
+ fetchNextPage: async (s) => {
505
488
  if (a == null)
506
489
  return {
507
490
  type: "error",
@@ -518,14 +501,14 @@ function Ne(e, t) {
518
501
  message: "No next page"
519
502
  }
520
503
  };
521
- const u = await d({
522
- ...i,
504
+ const d = await l({
505
+ ...s,
523
506
  nextPageToken: a.pagination.nextPageToken,
524
507
  previousPageToken: void 0
525
508
  });
526
- return u.type === "success" && (f(u.page), r(i)), u;
509
+ return d.type === "success" && (u(d.page), n(s)), d;
527
510
  },
528
- fetchPreviousPage: async (i) => {
511
+ fetchPreviousPage: async (s) => {
529
512
  if (a == null)
530
513
  return {
531
514
  type: "error",
@@ -542,60 +525,60 @@ function Ne(e, t) {
542
525
  message: "No previous page"
543
526
  }
544
527
  };
545
- const u = await d({
546
- ...i,
528
+ const d = await l({
529
+ ...s,
547
530
  nextPageToken: void 0,
548
531
  previousPageToken: a.pagination.previousPageToken
549
532
  });
550
- return u.type === "success" && (f(u.page), r(i)), u;
533
+ return d.type === "success" && (u(d.page), n(s)), d;
551
534
  },
552
- refetchCurrentPage: async () => n == null ? {
535
+ refetchCurrentPage: async () => r == null ? {
553
536
  type: "error",
554
537
  error: {
555
538
  code: "NO_CURRENT_PAGE",
556
539
  message: "No current page, please call fetchFirstPage first."
557
540
  }
558
- } : d(n),
541
+ } : l(r),
559
542
  currentPage: a
560
543
  };
561
544
  }
562
545
  function ue(e) {
563
- return e.progressItems.map((t, n) => {
564
- const r = e.progressItems[n + 1], a = r != null;
565
- let f;
566
- if (r != null && r.createdAt) {
567
- const s = new Date(t.createdAt).getTime(), d = new Date(r.createdAt).getTime();
568
- f = Math.round((d - s) / 1e3);
546
+ return e.progressItems.map((t, r) => {
547
+ const n = e.progressItems[r + 1], a = n != null;
548
+ let u;
549
+ if (n != null && n.createdAt) {
550
+ const c = new Date(t.createdAt).getTime(), l = new Date(n.createdAt).getTime();
551
+ u = Math.round((l - c) / 1e3);
569
552
  }
570
553
  return {
571
554
  item: t,
572
555
  completed: a,
573
- isLatest: n === e.progressItems.length - 1,
574
- durationSeconds: f
556
+ isLatest: r === e.progressItems.length - 1,
557
+ durationSeconds: u
575
558
  };
576
559
  });
577
560
  }
578
- function M({
561
+ function _({
579
562
  text: e,
580
563
  duration: t = 2,
581
- delay: n = 0,
582
- repeat: r = !0,
564
+ delay: r = 0,
565
+ repeat: n = !0,
583
566
  repeatDelay: a = 0.5,
584
- className: f,
585
- startOnView: s = !1,
586
- once: d = !1,
567
+ className: u,
568
+ startOnView: c = !1,
569
+ once: l = !1,
587
570
  inViewMargin: o,
588
- spread: c = 2,
589
- color: l = "#999",
590
- shimmerColor: i = "#000",
591
- direction: u = "fromBottom"
571
+ spread: i = 2,
572
+ color: m = "#999",
573
+ shimmerColor: s = "#000",
574
+ direction: d = "fromBottom"
592
575
  }) {
593
- const m = P(null), b = Q(m, { once: d, margin: o }), h = _(() => e.length * c, [e, c]), w = !s || b, y = u === "fromBottom" ? "100% center" : "-100% center", k = u === "fromBottom" ? "0% center" : "200% center";
576
+ const f = P(null), y = Q(f, { once: l, margin: o }), S = L(() => e.length * i, [e, i]), b = !c || y, h = d === "fromBottom" ? "100% center" : "-100% center", k = d === "fromBottom" ? "0% center" : "200% center";
594
577
  return /* @__PURE__ */ g(
595
- E.span,
578
+ A.span,
596
579
  {
597
- ref: m,
598
- className: f,
580
+ ref: f,
581
+ className: u,
599
582
  style: {
600
583
  position: "relative",
601
584
  display: "inline-block",
@@ -605,31 +588,31 @@ function M({
605
588
  color: "transparent",
606
589
  WebkitTextFillColor: "transparent",
607
590
  backgroundRepeat: "no-repeat, padding-box",
608
- "--spread": `${h}px`,
609
- "--base-color": l,
610
- "--shimmer-color": i,
591
+ "--spread": `${S}px`,
592
+ "--base-color": m,
593
+ "--shimmer-color": s,
611
594
  "--shimmer-bg": "linear-gradient(90deg, transparent calc(50% - var(--spread)), var(--shimmer-color), transparent calc(50% + var(--spread)))",
612
595
  backgroundImage: "var(--shimmer-bg), linear-gradient(var(--base-color), var(--base-color))"
613
596
  },
614
597
  initial: {
615
- backgroundPosition: y,
598
+ backgroundPosition: h,
616
599
  opacity: 0
617
600
  },
618
- animate: w ? {
601
+ animate: b ? {
619
602
  backgroundPosition: k,
620
603
  opacity: 1
621
604
  } : {},
622
605
  transition: {
623
606
  backgroundPosition: {
624
- repeat: r ? 1 / 0 : 0,
607
+ repeat: n ? 1 / 0 : 0,
625
608
  duration: t,
626
- delay: n,
609
+ delay: r,
627
610
  repeatDelay: a,
628
611
  ease: "linear"
629
612
  },
630
613
  opacity: {
631
614
  duration: 0.3,
632
- delay: n
615
+ delay: r
633
616
  }
634
617
  },
635
618
  children: e
@@ -638,25 +621,34 @@ function M({
638
621
  }
639
622
  function me(e) {
640
623
  const t = e.item.data;
641
- return t.type === "GenericAgentTaskExecution" || t.type === "GenericAgentTaskReasoning" ? t.title : t.type === "GenericAgentTaskFinalResponse" ? "Done" : "Processing";
624
+ switch (t.type) {
625
+ case "GenericAgentTaskExecution":
626
+ return t.title;
627
+ case "GenericAgentTaskReasoning":
628
+ return t.title;
629
+ case "GenericAgentTaskFinalResponse":
630
+ return "Generating answer...";
631
+ case "StreamingChatCompletionResponse":
632
+ return "Streaming...";
633
+ }
642
634
  }
643
635
  const ge = ({
644
636
  progressViewItems: e
645
637
  }) => {
646
638
  const t = e[e.length - 1];
647
639
  if (!t) return null;
648
- const n = me(t);
649
- return /* @__PURE__ */ g("div", { className: "simple-mode-container", children: /* @__PURE__ */ g(z, { mode: "wait", children: /* @__PURE__ */ g(
650
- E.div,
640
+ const r = me(t);
641
+ return /* @__PURE__ */ g("div", { className: "simple-mode-container", children: /* @__PURE__ */ g(W, { mode: "wait", children: /* @__PURE__ */ g(
642
+ A.div,
651
643
  {
652
644
  initial: { opacity: 0, y: 10 },
653
645
  animate: { opacity: 1, y: 0 },
654
646
  exit: { opacity: 0, y: -10 },
655
647
  transition: { duration: 0.3 },
656
- children: t.completed ? /* @__PURE__ */ g("div", { className: "simple-mode-title", style: { color: "#666" }, children: n }) : /* @__PURE__ */ g(
657
- M,
648
+ children: t.completed ? /* @__PURE__ */ g("div", { className: "simple-mode-title", style: { color: "#666" }, children: r }) : /* @__PURE__ */ g(
649
+ _,
658
650
  {
659
- text: n,
651
+ text: r,
660
652
  className: "simple-mode-title",
661
653
  duration: 2.5,
662
654
  repeat: !0,
@@ -670,10 +662,10 @@ const ge = ({
670
662
  }, fe = ({
671
663
  data: e,
672
664
  isLatest: t = !1,
673
- durationSeconds: n
674
- }) => /* @__PURE__ */ A("div", { style: { padding: "16px" }, children: [
665
+ durationSeconds: r
666
+ }) => /* @__PURE__ */ E("div", { style: { padding: "16px" }, children: [
675
667
  /* @__PURE__ */ g(
676
- E.div,
668
+ A.div,
677
669
  {
678
670
  style: {
679
671
  display: "flex",
@@ -684,8 +676,8 @@ const ge = ({
684
676
  initial: { opacity: 0, y: -10 },
685
677
  animate: { opacity: 1, y: 0 },
686
678
  transition: { duration: 0.3, delay: 0 },
687
- children: t && !n ? /* @__PURE__ */ g(
688
- M,
679
+ children: t && !r ? /* @__PURE__ */ g(
680
+ _,
689
681
  {
690
682
  text: e.title,
691
683
  duration: 2.5,
@@ -696,7 +688,7 @@ const ge = ({
696
688
  ) : /* @__PURE__ */ g("span", { style: { color: "#666" }, children: e.title })
697
689
  }
698
690
  ),
699
- n !== void 0 && /* @__PURE__ */ A(
691
+ r !== void 0 && /* @__PURE__ */ E(
700
692
  "div",
701
693
  {
702
694
  style: {
@@ -707,12 +699,12 @@ const ge = ({
707
699
  },
708
700
  children: [
709
701
  "Took ",
710
- n,
702
+ r,
711
703
  " seconds"
712
704
  ]
713
705
  }
714
706
  )
715
- ] }), K = {
707
+ ] }), z = {
716
708
  'code[class*="language-"]': {
717
709
  color: "#f8f8f2",
718
710
  background: "none",
@@ -866,67 +858,67 @@ const ge = ({
866
858
  }, ye = ({
867
859
  data: e,
868
860
  streamToken: t,
869
- fetchClientToken: n,
870
- durationSeconds: r
861
+ fetchClientToken: r,
862
+ durationSeconds: n
871
863
  }) => {
872
- const { fency: a } = R(), f = U(
873
- async (s) => {
864
+ const { fency: a } = F(), u = U(
865
+ async (c) => {
874
866
  try {
875
- const { clientToken: d } = await n(), o = await V({
867
+ const { clientToken: l } = await r(), o = await V({
876
868
  pk: a.publishableKey,
877
869
  baseUrl: a.baseUrl,
878
- clientToken: d,
870
+ clientToken: l,
879
871
  streamToken: t,
880
- request: { fileId: s }
872
+ request: { fileId: c }
881
873
  });
882
874
  o.type === "success" && window.open(o.downloadLink, "_blank");
883
- } catch (d) {
884
- console.error("Failed to download file:", d);
875
+ } catch (l) {
876
+ console.error("Failed to download file:", l);
885
877
  }
886
878
  },
887
- [a, t, n]
879
+ [a, t, r]
888
880
  );
889
- return /* @__PURE__ */ A("div", { style: { padding: "16px" }, children: [
881
+ return /* @__PURE__ */ E("div", { style: { padding: "16px" }, children: [
890
882
  /* @__PURE__ */ g(
891
- E.div,
883
+ A.div,
892
884
  {
893
885
  className: "fency-markdown-body-raw",
894
886
  initial: { opacity: 0, y: -10 },
895
887
  animate: { opacity: 1, y: 0 },
896
888
  transition: { duration: 0.3, delay: 0 },
897
889
  children: /* @__PURE__ */ g(
898
- H,
890
+ D,
899
891
  {
900
- remarkPlugins: [G],
892
+ remarkPlugins: [B],
901
893
  components: {
902
- code(s) {
903
- const { children: d, className: o, node: c, ref: l, ...i } = s, u = /language-(\w+)/.exec(o || "");
904
- return u ? /* @__PURE__ */ g(
905
- W,
894
+ code(c) {
895
+ const { children: l, className: o, node: i, ref: m, ...s } = c, d = /language-(\w+)/.exec(o || "");
896
+ return d ? /* @__PURE__ */ g(
897
+ M,
906
898
  {
907
- ...i,
899
+ ...s,
908
900
  PreTag: "div",
909
- children: String(d).replace(/\n$/, ""),
910
- language: u[1],
911
- style: K
901
+ children: String(l).replace(/\n$/, ""),
902
+ language: d[1],
903
+ style: z
912
904
  }
913
- ) : /* @__PURE__ */ g("code", { ...i, className: o, children: String(d) });
905
+ ) : /* @__PURE__ */ g("code", { ...s, className: o, children: String(l) });
914
906
  },
915
- a(s) {
916
- const { children: d, href: o, ...c } = s;
907
+ a(c) {
908
+ const { children: l, href: o, ...i } = c;
917
909
  return /* @__PURE__ */ g(
918
910
  "a",
919
911
  {
920
- ...c,
912
+ ...i,
921
913
  href: o,
922
- onClick: (l) => {
914
+ onClick: (m) => {
923
915
  if (!o) return;
924
- const i = o.match(
916
+ const s = o.match(
925
917
  /\/files\/(fil_[a-zA-Z0-9]+)\/download/
926
918
  );
927
- i && (l.preventDefault(), f(i[1]));
919
+ s && (m.preventDefault(), u(s[1]));
928
920
  },
929
- children: d
921
+ children: l
930
922
  }
931
923
  );
932
924
  }
@@ -936,7 +928,7 @@ const ge = ({
936
928
  )
937
929
  }
938
930
  ),
939
- r !== void 0 && /* @__PURE__ */ A(
931
+ n !== void 0 && /* @__PURE__ */ E(
940
932
  "div",
941
933
  {
942
934
  style: {
@@ -947,7 +939,7 @@ const ge = ({
947
939
  },
948
940
  children: [
949
941
  "Thought for ",
950
- r,
942
+ n,
951
943
  " seconds"
952
944
  ]
953
945
  }
@@ -956,22 +948,22 @@ const ge = ({
956
948
  }, he = ({
957
949
  data: e,
958
950
  completed: t,
959
- isLatest: n = !1,
960
- durationSeconds: r
951
+ isLatest: r = !1,
952
+ durationSeconds: n
961
953
  }) => {
962
954
  const a = P(null);
963
- return v(() => {
955
+ return T(() => {
964
956
  a.current && !t && (a.current.scrollTop = a.current.scrollHeight);
965
- }, [e.reasoning, t]), /* @__PURE__ */ A("div", { style: { padding: "16px" }, children: [
957
+ }, [e.reasoning, t]), /* @__PURE__ */ E("div", { style: { padding: "16px" }, children: [
966
958
  /* @__PURE__ */ g(
967
- E.h3,
959
+ A.h3,
968
960
  {
969
961
  style: { marginBottom: "10px", color: "#666" },
970
962
  initial: { opacity: 0, y: -10 },
971
963
  animate: { opacity: 1, y: 0 },
972
964
  transition: { duration: 0.3, delay: 0 },
973
- children: n && !r ? /* @__PURE__ */ g(
974
- M,
965
+ children: r && !n ? /* @__PURE__ */ g(
966
+ _,
975
967
  {
976
968
  text: e.title,
977
969
  duration: 2.5,
@@ -983,7 +975,7 @@ const ge = ({
983
975
  }
984
976
  ),
985
977
  /* @__PURE__ */ g(
986
- E.div,
978
+ A.div,
987
979
  {
988
980
  ref: a,
989
981
  style: {
@@ -999,22 +991,22 @@ const ge = ({
999
991
  animate: { opacity: 0.5, y: 0 },
1000
992
  transition: { duration: 0.3, delay: 0.1 },
1001
993
  children: /* @__PURE__ */ g("div", { className: "fency-markdown-body-raw", children: /* @__PURE__ */ g(
1002
- H,
994
+ D,
1003
995
  {
1004
- remarkPlugins: [G],
996
+ remarkPlugins: [B],
1005
997
  components: {
1006
- code(f) {
1007
- const { children: s, className: d, node: o, ref: c, ...l } = f, i = /language-(\w+)/.exec(d || "");
1008
- return i ? /* @__PURE__ */ g(
1009
- W,
998
+ code(u) {
999
+ const { children: c, className: l, node: o, ref: i, ...m } = u, s = /language-(\w+)/.exec(l || "");
1000
+ return s ? /* @__PURE__ */ g(
1001
+ M,
1010
1002
  {
1011
- ...l,
1003
+ ...m,
1012
1004
  PreTag: "div",
1013
- children: String(s).replace(/\n$/, ""),
1014
- language: i[1],
1015
- style: K
1005
+ children: String(c).replace(/\n$/, ""),
1006
+ language: s[1],
1007
+ style: z
1016
1008
  }
1017
- ) : /* @__PURE__ */ g("code", { ...l, className: d, children: String(s) });
1009
+ ) : /* @__PURE__ */ g("code", { ...m, className: l, children: String(c) });
1018
1010
  }
1019
1011
  },
1020
1012
  children: e.reasoning
@@ -1022,7 +1014,7 @@ const ge = ({
1022
1014
  ) })
1023
1015
  }
1024
1016
  ),
1025
- r !== void 0 && /* @__PURE__ */ A(
1017
+ n !== void 0 && /* @__PURE__ */ E(
1026
1018
  "div",
1027
1019
  {
1028
1020
  style: {
@@ -1033,90 +1025,127 @@ const ge = ({
1033
1025
  },
1034
1026
  children: [
1035
1027
  "Thought for ",
1036
- r,
1028
+ n,
1037
1029
  " seconds"
1038
1030
  ]
1039
1031
  }
1040
1032
  )
1041
1033
  ] });
1042
1034
  }, be = ({
1043
- progressViewItems: e,
1044
- streamToken: t,
1045
- fetchClientToken: n
1046
- }) => {
1047
- const r = P(null);
1048
- return v(() => {
1049
- r.current && (r.current.scrollTop = r.current.scrollHeight);
1050
- }, [e.length]), /* @__PURE__ */ g(
1035
+ data: e
1036
+ }) => /* @__PURE__ */ g("div", { style: { padding: "16px" }, children: /* @__PURE__ */ g(
1037
+ A.div,
1038
+ {
1039
+ className: "fency-markdown-body-raw",
1040
+ initial: { opacity: 0, y: -10 },
1041
+ animate: { opacity: 1, y: 0 },
1042
+ transition: { duration: 0.3, delay: 0 },
1043
+ children: /* @__PURE__ */ g(
1044
+ D,
1045
+ {
1046
+ remarkPlugins: [B],
1047
+ components: {
1048
+ code(t) {
1049
+ const { children: r, className: n, node: a, ref: u, ...c } = t, l = /language-(\w+)/.exec(n || "");
1050
+ return l ? /* @__PURE__ */ g(
1051
+ M,
1052
+ {
1053
+ ...c,
1054
+ PreTag: "div",
1055
+ children: String(r).replace(/\n$/, ""),
1056
+ language: l[1],
1057
+ style: z
1058
+ }
1059
+ ) : /* @__PURE__ */ g("code", { ...c, className: n, children: String(r) });
1060
+ }
1061
+ },
1062
+ children: e.response
1063
+ }
1064
+ )
1065
+ }
1066
+ ) }), ke = ({ progressViewItems: e, streamToken: t, fetchClientToken: r }) => {
1067
+ const n = P(null);
1068
+ T(() => {
1069
+ n.current && (n.current.scrollTop = n.current.scrollHeight);
1070
+ }, [e.length]);
1071
+ const a = (u) => {
1072
+ switch (u.item.data.type) {
1073
+ case "GenericAgentTaskExecution":
1074
+ return /* @__PURE__ */ g(
1075
+ fe,
1076
+ {
1077
+ data: u.item.data,
1078
+ completed: u.completed,
1079
+ isLatest: u.isLatest,
1080
+ durationSeconds: u.durationSeconds
1081
+ }
1082
+ );
1083
+ case "GenericAgentTaskReasoning":
1084
+ return /* @__PURE__ */ g(
1085
+ he,
1086
+ {
1087
+ data: u.item.data,
1088
+ completed: u.completed,
1089
+ isLatest: u.isLatest,
1090
+ durationSeconds: u.durationSeconds
1091
+ }
1092
+ );
1093
+ case "GenericAgentTaskFinalResponse":
1094
+ return /* @__PURE__ */ g(
1095
+ ye,
1096
+ {
1097
+ data: u.item.data,
1098
+ streamToken: t,
1099
+ fetchClientToken: r,
1100
+ durationSeconds: u.durationSeconds
1101
+ }
1102
+ );
1103
+ case "StreamingChatCompletionResponse":
1104
+ return /* @__PURE__ */ g(be, { data: u.item.data });
1105
+ }
1106
+ };
1107
+ return /* @__PURE__ */ g(
1051
1108
  "div",
1052
1109
  {
1053
- ref: r,
1110
+ ref: n,
1054
1111
  style: {
1055
1112
  flex: 1,
1056
1113
  overflowY: "auto",
1057
1114
  minHeight: 0
1058
1115
  },
1059
- children: /* @__PURE__ */ g(z, { children: e.map(({ item: a, completed: f, isLatest: s, durationSeconds: d }, o) => /* @__PURE__ */ A(
1060
- E.div,
1116
+ children: /* @__PURE__ */ g(W, { children: e.map((u, c) => /* @__PURE__ */ g(
1117
+ A.div,
1061
1118
  {
1062
1119
  initial: { opacity: 0, y: -20 },
1063
1120
  animate: { opacity: 1, y: 0 },
1064
1121
  transition: {
1065
1122
  duration: 0.4,
1066
- delay: o * 0.1,
1123
+ delay: c * 0.1,
1067
1124
  ease: "easeOut"
1068
1125
  },
1069
- children: [
1070
- a.data.type === "GenericAgentTaskExecution" && /* @__PURE__ */ g(
1071
- fe,
1072
- {
1073
- data: a.data,
1074
- completed: f,
1075
- isLatest: s,
1076
- durationSeconds: d
1077
- }
1078
- ),
1079
- a.data.type === "GenericAgentTaskReasoning" && /* @__PURE__ */ g(
1080
- he,
1081
- {
1082
- data: a.data,
1083
- completed: f,
1084
- isLatest: s,
1085
- durationSeconds: d
1086
- }
1087
- ),
1088
- a.data.type === "GenericAgentTaskFinalResponse" && /* @__PURE__ */ g(
1089
- ye,
1090
- {
1091
- data: a.data,
1092
- streamToken: t,
1093
- fetchClientToken: n,
1094
- durationSeconds: d
1095
- }
1096
- )
1097
- ]
1126
+ children: a(u)
1098
1127
  },
1099
- a.progressItemId
1128
+ u.item.progressItemId
1100
1129
  )) })
1101
1130
  }
1102
1131
  );
1103
- }, Re = ({
1132
+ }, Oe = ({
1104
1133
  agentTask: e,
1105
1134
  mode: t = "verbose",
1106
- streamToken: n,
1107
- fetchClientToken: r
1135
+ streamToken: r,
1136
+ fetchClientToken: n
1108
1137
  }) => {
1109
1138
  const a = ue(e);
1110
1139
  return t === "simple" ? /* @__PURE__ */ g(ge, { progressViewItems: a }) : /* @__PURE__ */ g(
1111
- be,
1140
+ ke,
1112
1141
  {
1113
1142
  progressViewItems: a,
1114
- streamToken: n,
1115
- fetchClientToken: r
1143
+ streamToken: r,
1144
+ fetchClientToken: n
1116
1145
  }
1117
1146
  );
1118
1147
  };
1119
- class ke {
1148
+ class Se {
1120
1149
  constructor(t) {
1121
1150
  this.eventSources = /* @__PURE__ */ new Map(), this.subscribers = /* @__PURE__ */ new Map(), this.fency = t;
1122
1151
  }
@@ -1125,37 +1154,37 @@ class ke {
1125
1154
  * Creates new connections and removes old ones.
1126
1155
  */
1127
1156
  updateStreams(t) {
1128
- t.forEach((r) => {
1129
- const a = r.stream.id;
1130
- this.eventSources.has(a) || this.connectStream(r);
1157
+ t.forEach((n) => {
1158
+ const a = n.stream.id;
1159
+ this.eventSources.has(a) || this.connectStream(n);
1131
1160
  });
1132
- const n = new Set(t.map((r) => r.stream.id));
1133
- this.eventSources.forEach((r, a) => {
1134
- n.has(a) || (r.abort(), this.eventSources.delete(a));
1161
+ const r = new Set(t.map((n) => n.stream.id));
1162
+ this.eventSources.forEach((n, a) => {
1163
+ r.has(a) || (n.abort(), this.eventSources.delete(a));
1135
1164
  });
1136
1165
  }
1137
1166
  connectStream(t) {
1138
- const n = t.stream.id, r = new AbortController();
1139
- this.eventSources.set(n, r);
1140
- const a = `${this.fency.baseUrl}/sse/streams/${n}`, f = {
1167
+ const r = t.stream.id, n = new AbortController();
1168
+ this.eventSources.set(r, n);
1169
+ const a = `${this.fency.baseUrl}/sse/streams/${r}`, u = {
1141
1170
  "X-Fency-Publishable-Key": this.fency.publishableKey,
1142
1171
  "X-Fency-Stream-Token": t.stream.token
1143
1172
  };
1144
- L(a, {
1145
- headers: f,
1146
- signal: r.signal,
1147
- async onopen(s) {
1148
- if (!s.ok && s.status >= 400 && s.status < 500 && s.status !== 429)
1149
- throw new Error(`Client error ${s.status}`);
1173
+ $(a, {
1174
+ headers: u,
1175
+ signal: n.signal,
1176
+ async onopen(c) {
1177
+ if (!c.ok && c.status >= 400 && c.status < 500 && c.status !== 429)
1178
+ throw new Error(`Client error ${c.status}`);
1150
1179
  },
1151
- onmessage: (s) => {
1152
- if (s.data) {
1153
- const d = $(s.data);
1154
- this.broadcast(d, n);
1180
+ onmessage: (c) => {
1181
+ if (c.data) {
1182
+ const l = K(c.data);
1183
+ this.broadcast(l, r);
1155
1184
  }
1156
1185
  },
1157
- onerror: (s) => {
1158
- throw console.error("EventSource error for stream", n, ":", s), this.broadcastError(n), s;
1186
+ onerror: (c) => {
1187
+ throw console.error("EventSource error for stream", r, ":", c), this.broadcastError(r), c;
1159
1188
  },
1160
1189
  onclose() {
1161
1190
  }
@@ -1165,19 +1194,19 @@ class ke {
1165
1194
  * Subscribe to events from all active streams.
1166
1195
  * Returns an unsubscribe function.
1167
1196
  */
1168
- subscribe(t, n) {
1169
- return this.subscribers.set(t, n), () => {
1197
+ subscribe(t, r) {
1198
+ return this.subscribers.set(t, r), () => {
1170
1199
  this.subscribers.delete(t);
1171
1200
  };
1172
1201
  }
1173
- broadcast(t, n) {
1174
- this.subscribers.forEach((r) => {
1175
- r.onMessage(t, n);
1202
+ broadcast(t, r) {
1203
+ this.subscribers.forEach((n) => {
1204
+ n.onMessage(t, r);
1176
1205
  });
1177
1206
  }
1178
1207
  broadcastError(t) {
1179
- this.subscribers.forEach((n) => {
1180
- n.onError(t);
1208
+ this.subscribers.forEach((r) => {
1209
+ r.onError(t);
1181
1210
  });
1182
1211
  }
1183
1212
  /**
@@ -1187,89 +1216,90 @@ class ke {
1187
1216
  this.eventSources.forEach((t) => t.abort()), this.eventSources.clear(), this.subscribers.clear();
1188
1217
  }
1189
1218
  }
1190
- const we = 12e4, Te = (e) => {
1219
+ const ve = 12e4, we = (e) => {
1191
1220
  const t = Date.now();
1192
- return e.filter((n) => t - n.createdAt < we);
1221
+ return e.filter((r) => t - r.createdAt < ve);
1193
1222
  };
1194
- function Oe({ fency: e, children: t }) {
1195
- const [n, r] = S(
1223
+ function Ue({ fency: e, fetchCreateStreamClientToken: t, children: r }) {
1224
+ const [n, a] = w(
1196
1225
  null
1197
- ), [a, f] = S(!0), [s, d] = S(null), [o, c] = S([]), l = P(null), i = P(null);
1198
- v(() => {
1199
- e.then((h) => {
1200
- r(h), f(!1);
1201
- }).catch((h) => {
1202
- d(h), f(!1);
1226
+ ), [u, c] = w(!0), [l, o] = w(null), [i, m] = w([]), s = P(null), d = P(null);
1227
+ T(() => {
1228
+ e.then((b) => {
1229
+ a(b), c(!1);
1230
+ }).catch((b) => {
1231
+ o(b), c(!1);
1203
1232
  });
1204
- }, [e]), v(() => {
1205
- n && !i.current && (i.current = new ke(n));
1206
- }, [n]), v(() => {
1207
- i.current && i.current.updateStreams(o);
1208
- }, [o]), v(() => () => {
1209
- var h;
1210
- (h = i.current) == null || h.cleanup();
1233
+ }, [e]), T(() => {
1234
+ n && !d.current && (d.current = new Se(n));
1235
+ }, [n]), T(() => {
1236
+ d.current && d.current.updateStreams(i);
1237
+ }, [i]), T(() => () => {
1238
+ var b;
1239
+ (b = d.current) == null || b.cleanup();
1211
1240
  }, []);
1212
- const u = U(
1213
- async (h, w = 3e4) => {
1214
- if (l.current)
1215
- return l.current;
1216
- const y = Date.now(), k = o.length > 0 ? o[o.length - 1] : null;
1217
- if (k && y - k.createdAt < w)
1241
+ const f = U(
1242
+ async (b = 3e4) => {
1243
+ if (s.current)
1244
+ return s.current;
1245
+ const h = Date.now(), k = i.length > 0 ? i[i.length - 1] : null;
1246
+ if (k && h - k.createdAt < b)
1218
1247
  return k.stream;
1219
- const C = (async () => {
1248
+ const I = (async () => {
1220
1249
  if (!n)
1221
1250
  throw new Error("Fency instance not initialized");
1222
- const I = await h(), x = await X({
1251
+ const C = await t(), x = await X({
1223
1252
  pk: n.publishableKey,
1224
1253
  baseUrl: n.baseUrl,
1225
- clientToken: (I == null ? void 0 : I.clientToken) ?? ""
1254
+ clientToken: (C == null ? void 0 : C.clientToken) ?? ""
1226
1255
  });
1227
1256
  if (x.type === "success") {
1228
1257
  const N = {
1229
1258
  stream: x.stream,
1230
1259
  createdAt: Date.now()
1231
1260
  };
1232
- return c((F) => {
1233
- const T = [...F, N];
1234
- return Te(T);
1235
- }), l.current = null, x.stream;
1261
+ return m((R) => {
1262
+ const v = [...R, N];
1263
+ return we(v);
1264
+ }), s.current = null, x.stream;
1236
1265
  } else
1237
- throw l.current = null, new Error("Failed to create stream");
1266
+ throw s.current = null, new Error("Failed to create stream");
1238
1267
  })();
1239
- return l.current = C, C;
1268
+ return s.current = I, I;
1240
1269
  },
1241
- [n, o]
1270
+ [n, i]
1242
1271
  );
1243
- if (s)
1244
- return /* @__PURE__ */ A("div", { children: [
1272
+ if (l)
1273
+ return /* @__PURE__ */ E("div", { children: [
1245
1274
  "Fency error: ",
1246
- s.message
1275
+ l.message
1247
1276
  ] });
1248
1277
  if (!n)
1249
1278
  return null;
1250
- const m = o.length > 0 ? o[o.length - 1] : null, b = {
1279
+ const y = i.length > 0 ? i[i.length - 1] : null, S = {
1251
1280
  fency: n,
1252
- loading: a,
1253
- error: s,
1254
- activeStreams: o,
1255
- latestStream: m,
1256
- eventManager: i.current,
1257
- getOrCreateStream: u
1281
+ loading: u,
1282
+ error: l,
1283
+ activeStreams: i,
1284
+ latestStream: y,
1285
+ eventManager: d.current,
1286
+ getOrCreateStream: f
1258
1287
  };
1259
- return /* @__PURE__ */ g(j.Provider, { value: b, children: t });
1288
+ return /* @__PURE__ */ g(j.Provider, { value: S, children: r });
1260
1289
  }
1261
1290
  export {
1262
- Re as AgentTaskProgress,
1291
+ Oe as AgentTaskProgress,
1263
1292
  ge as AgentTaskProgressSimple,
1264
- be as AgentTaskProgressVerbose,
1265
- Oe as FencyProvider,
1293
+ ke as AgentTaskProgressVerbose,
1294
+ Ue as FencyProvider,
1266
1295
  fe as GenericAgentTaskExecution,
1267
1296
  ye as GenericAgentTaskFinalResponse,
1268
1297
  he as GenericAgentTaskReasoning,
1269
- M as ShimmeringText,
1270
- Ee as useAgentTasks,
1271
- R as useFencyContext,
1272
- Fe as useFencyEventSource,
1273
- Ne as usePaginatedQuery,
1298
+ _ as ShimmeringText,
1299
+ be as StreamingChatCompletionResponse,
1300
+ Re as useAgentTasks,
1301
+ F as useFencyContext,
1302
+ Ne as useFencyEventSource,
1303
+ Fe as usePaginatedQuery,
1274
1304
  re as useStream
1275
1305
  };