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