@fencyai/react 0.1.111 → 0.1.113

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