@fencyai/react 0.1.112 → 0.1.114

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