@fencyai/react 0.1.111 → 0.1.112

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