@fencyai/react 0.1.114 → 0.1.115

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