@fencyai/react 0.1.121 → 0.1.123

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 (79) hide show
  1. package/dist/agent-task/AgentTaskProgress.d.ts +1 -0
  2. package/dist/agent-task/AgentTaskProgress.d.ts.map +1 -0
  3. package/dist/agent-task/AgentTaskProgressSimple.d.ts +1 -0
  4. package/dist/agent-task/AgentTaskProgressSimple.d.ts.map +1 -0
  5. package/dist/agent-task/AgentTaskProgressVerbose.d.ts +1 -0
  6. package/dist/agent-task/AgentTaskProgressVerbose.d.ts.map +1 -0
  7. package/dist/agent-task/ProgressViewItem.d.ts +1 -0
  8. package/dist/agent-task/ProgressViewItem.d.ts.map +1 -0
  9. package/dist/agent-task/ShimmeringText.d.ts +1 -0
  10. package/dist/agent-task/ShimmeringText.d.ts.map +1 -0
  11. package/dist/agent-task/data-types/StreamingChatCompletionText.d.ts +1 -0
  12. package/dist/agent-task/data-types/StreamingChatCompletionText.d.ts.map +1 -0
  13. package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionExploreMemory.d.ts +1 -0
  14. package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionExploreMemory.d.ts.map +1 -0
  15. package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionFindSources.d.ts +1 -0
  16. package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionFindSources.d.ts.map +1 -0
  17. package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionSearch.d.ts +1 -0
  18. package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionSearch.d.ts.map +1 -0
  19. package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionSourcesResult.d.ts +1 -0
  20. package/dist/agent-task/data-types/StreamingMemoryTypeChatCompletionSourcesResult.d.ts.map +1 -0
  21. package/dist/agent-task/data-types/StructuredChatCompletionJson.d.ts +1 -0
  22. package/dist/agent-task/data-types/StructuredChatCompletionJson.d.ts.map +1 -0
  23. package/dist/agent-task/hooks/useContentEditable.d.ts +1 -0
  24. package/dist/agent-task/hooks/useContentEditable.d.ts.map +1 -0
  25. package/dist/agent-task/hooks/useMentionParser.d.ts +1 -0
  26. package/dist/agent-task/hooks/useMentionParser.d.ts.map +1 -0
  27. package/dist/agent-task/hooks/useMentionRenderer.d.ts +1 -0
  28. package/dist/agent-task/hooks/useMentionRenderer.d.ts.map +1 -0
  29. package/dist/agent-task/hooks/useMentionState.d.ts +1 -0
  30. package/dist/agent-task/hooks/useMentionState.d.ts.map +1 -0
  31. package/dist/hooks/useAgentTasks/index.d.ts +1 -0
  32. package/dist/hooks/useAgentTasks/index.d.ts.map +1 -0
  33. package/dist/{provider/useFencyContext.d.ts → hooks/useFencyContext/index.d.ts} +2 -1
  34. package/dist/hooks/useFencyContext/index.d.ts.map +1 -0
  35. package/dist/hooks/useFencyEventSource/index.d.ts +1 -0
  36. package/dist/hooks/useFencyEventSource/index.d.ts.map +1 -0
  37. package/dist/hooks/useStream/index.d.ts +1 -0
  38. package/dist/hooks/useStream/index.d.ts.map +1 -0
  39. package/dist/hooks/useStream/toStreamData.d.ts +1 -0
  40. package/dist/hooks/useStream/toStreamData.d.ts.map +1 -0
  41. package/dist/index.d.ts +2 -14
  42. package/dist/index.d.ts.map +1 -0
  43. package/dist/index.js +591 -749
  44. package/dist/provider/FencyContextValue.d.ts +1 -0
  45. package/dist/provider/FencyContextValue.d.ts.map +1 -0
  46. package/dist/provider/FencyProvider.d.ts +1 -0
  47. package/dist/provider/FencyProvider.d.ts.map +1 -0
  48. package/dist/provider/StreamEventManager.d.ts +1 -0
  49. package/dist/provider/StreamEventManager.d.ts.map +1 -0
  50. package/dist/types/AgentTask.d.ts +1 -0
  51. package/dist/types/AgentTask.d.ts.map +1 -0
  52. package/dist/types/AgentTaskData.d.ts +1 -0
  53. package/dist/types/AgentTaskData.d.ts.map +1 -0
  54. package/dist/types/CreateAgentTaskParams.d.ts +1 -0
  55. package/dist/types/CreateAgentTaskParams.d.ts.map +1 -0
  56. package/dist/types/CreateAgentTaskResponse.d.ts +1 -0
  57. package/dist/types/CreateAgentTaskResponse.d.ts.map +1 -0
  58. package/dist/types/CreateStreamResponse.d.ts +1 -0
  59. package/dist/types/CreateStreamResponse.d.ts.map +1 -0
  60. package/dist/types/FencyContext.d.ts +1 -0
  61. package/dist/types/FencyContext.d.ts.map +1 -0
  62. package/dist/types/FencyProviderProps.d.ts +1 -0
  63. package/dist/types/FencyProviderProps.d.ts.map +1 -0
  64. package/dist/types/StreamData.d.ts +1 -0
  65. package/dist/types/StreamData.d.ts.map +1 -0
  66. package/dist/types/StreamError.d.ts +1 -0
  67. package/dist/types/StreamError.d.ts.map +1 -0
  68. package/dist/types/UseAgentTasks.d.ts +1 -0
  69. package/dist/types/UseAgentTasks.d.ts.map +1 -0
  70. package/dist/types/UseAgentTasksProps.d.ts +1 -0
  71. package/dist/types/UseAgentTasksProps.d.ts.map +1 -0
  72. package/dist/types/UseStream.d.ts +1 -0
  73. package/dist/types/UseStream.d.ts.map +1 -0
  74. package/dist/types/UseStreamProps.d.ts +1 -0
  75. package/dist/types/UseStreamProps.d.ts.map +1 -0
  76. package/dist/types/index.d.ts +9 -7
  77. package/dist/types/index.d.ts.map +1 -0
  78. package/package.json +7 -5
  79. package/dist/hooks/usePaginatedQuery/index.d.ts +0 -56
package/dist/index.js CHANGED
@@ -1,47 +1,310 @@
1
- import { createAgentTask as G, createStream as J } from "@fencyai/js";
2
- import { createContext as V, useContext as q, useState as k, useRef as p, useEffect as E, useCallback as W, useMemo as $ } from "react";
3
- import { jsx as c, jsxs as x, Fragment as X } from "react/jsx-runtime";
4
- import { useInView as Q, motion as v, AnimatePresence as B } from "motion/react";
1
+ import { jsxs as k, jsx as i } from "react/jsx-runtime";
2
+ import { createStream as K, isStreamTimeoutEventDto as _, isStreamNotFoundEventDto as J, isAgentTaskProgressItemUpdatedEventDto as V, createAgentTask as q } from "@fencyai/js";
3
+ import { createContext as G, useState as w, useRef as A, useEffect as E, useCallback as W, useContext as X, useMemo as U } from "react";
4
+ import { useInView as Q, motion as v, AnimatePresence as L } from "motion/react";
5
5
  import Y from "react-markdown";
6
- import { Prism as L } from "react-syntax-highlighter";
6
+ import { Prism as $ } from "react-syntax-highlighter";
7
7
  import Z from "remark-gfm";
8
- import './assets/index.css';const _ = V(
8
+ import './assets/index.css';const N = G(
9
9
  void 0
10
10
  );
11
- function N() {
12
- const e = q(_);
11
+ async function ee(e, t) {
12
+ const r = e.getReader();
13
+ let n;
14
+ for (; !(n = await r.read()).done; )
15
+ t(n.value);
16
+ }
17
+ function te(e) {
18
+ let t, r, n, l = !1;
19
+ return function(s) {
20
+ t === void 0 ? (t = s, r = 0, n = -1) : t = re(t, s);
21
+ const c = t.length;
22
+ let d = 0;
23
+ for (; r < c; ) {
24
+ l && (t[r] === 10 && (d = ++r), l = !1);
25
+ let o = -1;
26
+ for (; r < c && o === -1; ++r)
27
+ switch (t[r]) {
28
+ case 58:
29
+ n === -1 && (n = r - d);
30
+ break;
31
+ case 13:
32
+ l = !0;
33
+ case 10:
34
+ o = r;
35
+ break;
36
+ }
37
+ if (o === -1)
38
+ break;
39
+ e(t.subarray(d, o), n), d = r, n = -1;
40
+ }
41
+ d === c ? t = void 0 : d !== 0 && (t = t.subarray(d), r -= d);
42
+ };
43
+ }
44
+ function ne(e, t, r) {
45
+ let n = P();
46
+ const l = new TextDecoder();
47
+ return function(s, c) {
48
+ if (s.length === 0)
49
+ r == null || r(n), n = P();
50
+ else if (c > 0) {
51
+ const d = l.decode(s.subarray(0, c)), o = c + (s[c + 1] === 32 ? 2 : 1), a = l.decode(s.subarray(o));
52
+ switch (d) {
53
+ case "data":
54
+ n.data = n.data ? n.data + `
55
+ ` + a : a;
56
+ break;
57
+ case "event":
58
+ n.event = a;
59
+ break;
60
+ case "id":
61
+ e(n.id = a);
62
+ break;
63
+ case "retry":
64
+ const y = parseInt(a, 10);
65
+ isNaN(y) || t(n.retry = y);
66
+ break;
67
+ }
68
+ }
69
+ };
70
+ }
71
+ function re(e, t) {
72
+ const r = new Uint8Array(e.length + t.length);
73
+ return r.set(e), r.set(t, e.length), r;
74
+ }
75
+ function P() {
76
+ return {
77
+ data: "",
78
+ event: "",
79
+ id: "",
80
+ retry: void 0
81
+ };
82
+ }
83
+ var oe = function(e, t) {
84
+ var r = {};
85
+ for (var n in e) Object.prototype.hasOwnProperty.call(e, n) && t.indexOf(n) < 0 && (r[n] = e[n]);
86
+ if (e != null && typeof Object.getOwnPropertySymbols == "function")
87
+ for (var l = 0, n = Object.getOwnPropertySymbols(e); l < n.length; l++)
88
+ t.indexOf(n[l]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[l]) && (r[n[l]] = e[n[l]]);
89
+ return r;
90
+ };
91
+ const R = "text/event-stream", ae = 1e3, O = "last-event-id";
92
+ function ie(e, t) {
93
+ var { signal: r, headers: n, onopen: l, onmessage: u, onclose: s, onerror: c, openWhenHidden: d, fetch: o } = t, a = oe(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
94
+ return new Promise((y, g) => {
95
+ const h = Object.assign({}, n);
96
+ h.accept || (h.accept = R);
97
+ let m;
98
+ function S() {
99
+ m.abort(), document.hidden || I();
100
+ }
101
+ d || document.addEventListener("visibilitychange", S);
102
+ let f = ae, b = 0;
103
+ function C() {
104
+ document.removeEventListener("visibilitychange", S), window.clearTimeout(b), m.abort();
105
+ }
106
+ r == null || r.addEventListener("abort", () => {
107
+ C(), y();
108
+ });
109
+ const p = o ?? window.fetch, x = l ?? se;
110
+ async function I() {
111
+ var D;
112
+ m = new AbortController();
113
+ try {
114
+ const M = await p(e, Object.assign(Object.assign({}, a), { headers: h, signal: m.signal }));
115
+ await x(M), await ee(M.body, te(ne((T) => {
116
+ T ? h[O] = T : delete h[O];
117
+ }, (T) => {
118
+ f = T;
119
+ }, u))), s == null || s(), C(), y();
120
+ } catch (M) {
121
+ if (!m.signal.aborted)
122
+ try {
123
+ const T = (D = c == null ? void 0 : c(M)) !== null && D !== void 0 ? D : f;
124
+ window.clearTimeout(b), b = window.setTimeout(I, T);
125
+ } catch (T) {
126
+ C(), g(T);
127
+ }
128
+ }
129
+ }
130
+ I();
131
+ });
132
+ }
133
+ function se(e) {
134
+ const t = e.headers.get("content-type");
135
+ if (!(t != null && t.startsWith(R)))
136
+ throw new Error(`Expected content-type to be ${R}, Actual: ${t}`);
137
+ }
138
+ function le(e) {
139
+ const t = atob(e), r = new Uint8Array(t.length);
140
+ for (let n = 0; n < t.length; n++)
141
+ r[n] = t.charCodeAt(n);
142
+ return new TextDecoder("utf-8").decode(r);
143
+ }
144
+ class ce {
145
+ constructor(t) {
146
+ this.eventSources = /* @__PURE__ */ new Map(), this.subscribers = /* @__PURE__ */ new Map(), this.fency = t;
147
+ }
148
+ /**
149
+ * Called by FencyProvider when activeStreams changes.
150
+ * Creates new connections and removes old ones.
151
+ */
152
+ updateStreams(t) {
153
+ t.forEach((n) => {
154
+ const l = n.stream.id;
155
+ this.eventSources.has(l) || this.connectStream(n);
156
+ });
157
+ const r = new Set(t.map((n) => n.stream.id));
158
+ this.eventSources.forEach((n, l) => {
159
+ r.has(l) || (n.abort(), this.eventSources.delete(l));
160
+ });
161
+ }
162
+ connectStream(t) {
163
+ const r = t.stream.id, n = new AbortController();
164
+ this.eventSources.set(r, n);
165
+ const l = `${this.fency.baseUrl}/sse/streams/${r}`, u = {
166
+ "X-Fency-Publishable-Key": this.fency.publishableKey,
167
+ "X-Fency-Stream-Token": t.stream.token
168
+ };
169
+ ie(l, {
170
+ headers: u,
171
+ signal: n.signal,
172
+ async onopen(s) {
173
+ if (!s.ok && s.status >= 400 && s.status < 500 && s.status !== 429)
174
+ throw new Error(`Client error ${s.status}`);
175
+ },
176
+ onmessage: (s) => {
177
+ if (s.data) {
178
+ const c = le(s.data);
179
+ this.broadcast(c, r);
180
+ }
181
+ },
182
+ onerror: (s) => {
183
+ throw console.error("EventSource error for stream", r, ":", s), this.broadcastError(r), s;
184
+ },
185
+ onclose() {
186
+ }
187
+ });
188
+ }
189
+ /**
190
+ * Subscribe to events from all active streams.
191
+ * Returns an unsubscribe function.
192
+ */
193
+ subscribe(t, r) {
194
+ return this.subscribers.set(t, r), () => {
195
+ this.subscribers.delete(t);
196
+ };
197
+ }
198
+ broadcast(t, r) {
199
+ this.subscribers.forEach((n) => {
200
+ n.onMessage(t, r);
201
+ });
202
+ }
203
+ broadcastError(t) {
204
+ this.subscribers.forEach((r) => {
205
+ r.onError(t);
206
+ });
207
+ }
208
+ /**
209
+ * Cleanup all connections and subscriptions
210
+ */
211
+ cleanup() {
212
+ this.eventSources.forEach((t) => t.abort()), this.eventSources.clear(), this.subscribers.clear();
213
+ }
214
+ }
215
+ const de = 12e4, ue = (e) => {
216
+ const t = Date.now();
217
+ return e.filter((r) => t - r.createdAt < de);
218
+ };
219
+ function We({ fency: e, fetchCreateStreamClientToken: t, children: r }) {
220
+ const [n, l] = w(
221
+ null
222
+ ), [u, s] = w(!0), [c, d] = w(null), [o, a] = w([]), y = A(null), g = A(null);
223
+ E(() => {
224
+ e.then((f) => {
225
+ l(f), s(!1);
226
+ }).catch((f) => {
227
+ d(f), s(!1);
228
+ });
229
+ }, [e]), E(() => {
230
+ n && !g.current && (g.current = new ce(n));
231
+ }, [n]), E(() => {
232
+ g.current && g.current.updateStreams(o);
233
+ }, [o]), E(() => () => {
234
+ var f;
235
+ (f = g.current) == null || f.cleanup();
236
+ }, []);
237
+ const h = W(
238
+ async (f = 3e4) => {
239
+ if (y.current)
240
+ return y.current;
241
+ const b = Date.now(), C = o.length > 0 ? o[o.length - 1] : null;
242
+ if (C && b - C.createdAt < f)
243
+ return C.stream;
244
+ const p = (async () => {
245
+ if (!n)
246
+ throw new Error("Fency instance not initialized");
247
+ const x = await t(), I = await K({
248
+ pk: n.publishableKey,
249
+ baseUrl: n.baseUrl,
250
+ clientToken: (x == null ? void 0 : x.clientToken) ?? ""
251
+ });
252
+ if (I.type === "success") {
253
+ const D = {
254
+ stream: I.stream,
255
+ createdAt: Date.now()
256
+ };
257
+ return a((M) => {
258
+ const T = [...M, D];
259
+ return ue(T);
260
+ }), y.current = null, I.stream;
261
+ } else
262
+ throw y.current = null, new Error("Failed to create stream");
263
+ })();
264
+ return y.current = p, p;
265
+ },
266
+ [n, o]
267
+ );
268
+ if (c)
269
+ return /* @__PURE__ */ k("div", { children: [
270
+ "Fency error: ",
271
+ c.message
272
+ ] });
273
+ if (!n)
274
+ return null;
275
+ const m = o.length > 0 ? o[o.length - 1] : null, S = {
276
+ fency: n,
277
+ loading: u,
278
+ error: c,
279
+ activeStreams: o,
280
+ latestStream: m,
281
+ eventManager: g.current,
282
+ getOrCreateStream: h
283
+ };
284
+ return /* @__PURE__ */ i(N.Provider, { value: S, children: r });
285
+ }
286
+ function H() {
287
+ const e = X(N);
13
288
  if (e === void 0)
14
289
  throw new Error("useFencyContext must be used within a FencyProvider");
15
290
  return e;
16
291
  }
17
- const ee = (e) => {
292
+ const me = (e) => {
18
293
  try {
19
294
  const t = JSON.parse(e);
20
- return te(t);
295
+ return ge(t);
21
296
  } catch (t) {
22
297
  return console.error("Error parsing message:", t), null;
23
298
  }
24
- }, te = (e) => {
25
- if (!(typeof e == "object" && e !== null && "type" in e && "streamId" in e && "timestamp" in e))
26
- return null;
27
- switch (e.type) {
28
- case "StreamTimeout":
29
- return ne(e);
30
- case "StreamNotFound":
31
- return re(e);
32
- case "AgentTaskProgressItemUpdated":
33
- return ae(e);
34
- }
35
- return null;
36
- }, ne = (e) => ({
299
+ }, ge = (e) => _(e) ? ye(e) : J(e) ? fe(e) : V(e) ? he(e) : null, ye = (e) => ({
37
300
  type: "StreamTimeout",
38
301
  streamId: e.streamId,
39
302
  timestamp: e.timestamp
40
- }), re = (e) => ({
303
+ }), fe = (e) => ({
41
304
  type: "StreamNotFound",
42
305
  streamId: e.streamId,
43
306
  timestamp: e.timestamp
44
- }), ae = (e) => ({
307
+ }), he = (e) => ({
45
308
  type: "AgentTaskProgressItemUpdated",
46
309
  streamId: e.streamId,
47
310
  agentTaskId: e.agentTaskId,
@@ -49,45 +312,45 @@ const ee = (e) => {
49
312
  timestamp: e.timestamp,
50
313
  createdAt: e.createdAt,
51
314
  data: JSON.parse(e.data)
52
- }), oe = (e) => {
53
- const t = N(), [n, r] = k(null), a = p(`subscriber-${Math.random().toString(36).substr(2, 9)}`);
315
+ }), Se = (e) => {
316
+ const t = H(), [r, n] = w(null), l = A(`subscriber-${Math.random().toString(36).substr(2, 9)}`);
54
317
  return E(() => {
55
318
  if (!t.eventManager) return;
56
319
  const s = {
57
320
  onMessage: (d, o) => {
58
- var m, u, S, y, T, f, h, b, I, w;
59
- const i = ee(d);
60
- if (i)
61
- switch (i.type) {
321
+ var y, g, h, m, S, f, b, C, p, x;
322
+ const a = me(d);
323
+ if (a)
324
+ switch (a.type) {
62
325
  case "NewChatCompletionStreamChunk":
63
- (m = e == null ? void 0 : e.onNewChatCompletionStreamChunk) == null || m.call(e, i);
326
+ (y = e == null ? void 0 : e.onNewChatCompletionStreamChunk) == null || y.call(e, a);
64
327
  break;
65
328
  case "ChatCompletionStreamCompleted":
66
- (u = e == null ? void 0 : e.onChatCompletionStreamCompleted) == null || u.call(e, i);
329
+ (g = e == null ? void 0 : e.onChatCompletionStreamCompleted) == null || g.call(e, a);
67
330
  break;
68
331
  case "StreamTimeout":
69
- (S = e == null ? void 0 : e.onStreamTimeout) == null || S.call(e, i);
332
+ (h = e == null ? void 0 : e.onStreamTimeout) == null || h.call(e, a);
70
333
  break;
71
334
  case "StreamNotFound":
72
- (y = e == null ? void 0 : e.onStreamNotFound) == null || y.call(e, i);
335
+ (m = e == null ? void 0 : e.onStreamNotFound) == null || m.call(e, a);
73
336
  break;
74
337
  case "FileUploadCompleted":
75
- (T = e == null ? void 0 : e.onFileUploadCompleted) == null || T.call(e, i);
338
+ (S = e == null ? void 0 : e.onFileUploadCompleted) == null || S.call(e, a);
76
339
  break;
77
340
  case "FileTextContentReady":
78
- (f = e == null ? void 0 : e.onFileTextContentReady) == null || f.call(e, i);
341
+ (f = e == null ? void 0 : e.onFileTextContentReady) == null || f.call(e, a);
79
342
  break;
80
343
  case "WebsiteHtmlContentReady":
81
- (h = e == null ? void 0 : e.onWebsiteHtmlContentReady) == null || h.call(e, i);
344
+ (b = e == null ? void 0 : e.onWebsiteHtmlContentReady) == null || b.call(e, a);
82
345
  break;
83
346
  case "WebsiteTextContentReady":
84
- (b = e == null ? void 0 : e.onWebsiteTextContentReady) == null || b.call(e, i);
347
+ (C = e == null ? void 0 : e.onWebsiteTextContentReady) == null || C.call(e, a);
85
348
  break;
86
349
  case "FileSearchIndexReady":
87
- (I = e == null ? void 0 : e.onFileSearchIndexReady) == null || I.call(e, i);
350
+ (p = e == null ? void 0 : e.onFileSearchIndexReady) == null || p.call(e, a);
88
351
  break;
89
352
  case "AgentTaskProgressItemUpdated":
90
- (w = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || w.call(e, i);
353
+ (x = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || x.call(e, a);
91
354
  break;
92
355
  }
93
356
  },
@@ -103,14 +366,14 @@ const ee = (e) => {
103
366
  }
104
367
  };
105
368
  return t.eventManager.subscribe(
106
- a.current,
369
+ l.current,
107
370
  s
108
371
  );
109
372
  }, [t.eventManager, e]), {
110
373
  createStream: async () => {
111
374
  try {
112
375
  const s = await t.getOrCreateStream(3e4);
113
- return r(s), {
376
+ return n(s), {
114
377
  type: "success",
115
378
  stream: s
116
379
  };
@@ -124,66 +387,66 @@ const ee = (e) => {
124
387
  };
125
388
  }
126
389
  },
127
- stream: n
390
+ stream: r
128
391
  };
129
- }, ze = (e) => {
130
- const t = N(), [n, r] = k([]), a = p(/* @__PURE__ */ new Set()), g = p(/* @__PURE__ */ new Map()), { createStream: s } = oe({
392
+ }, Ue = (e) => {
393
+ const t = H(), [r, n] = w([]), l = A(/* @__PURE__ */ new Set()), u = A(/* @__PURE__ */ new Map()), { createStream: s } = Se({
131
394
  onAgentTaskProgressItemUpdated: (o) => {
132
- var u;
133
- if (!a.current.has(o.agentTaskId)) return;
134
- const i = o.data;
135
- if (i.taskType === "StreamingChatCompletion" && i.eventType === "Completed" || i.taskType === "StructuredChatCompletion" && i.eventType === "Completed" || i.taskType === "StreamingMemoryTypeChatCompletion" && i.eventType === "Completed") {
136
- const S = g.current.get(
395
+ var g;
396
+ if (!l.current.has(o.agentTaskId)) return;
397
+ const a = o.data;
398
+ if (a.taskType === "StreamingChatCompletion" && a.eventType === "Completed" || a.taskType === "StructuredChatCompletion" && a.eventType === "Completed" || a.taskType === "StreamingMemoryTypeChatCompletion" && a.eventType === "Completed") {
399
+ const h = u.current.get(
137
400
  o.agentTaskId
138
401
  );
139
- S && (g.current.delete(o.agentTaskId), S(i));
402
+ h && (u.current.delete(o.agentTaskId), h(a));
140
403
  return;
141
404
  }
142
- (u = e.onAgentTaskProgressItemUpdated) == null || u.call(e, o), r(
143
- (S) => S.map((y) => {
144
- var h;
145
- if (((h = y.confirmedData) == null ? void 0 : h.taskId) !== o.agentTaskId)
146
- return y;
147
- const f = y.progressItems.some(
148
- (b) => b.progressItemId === o.progressItemId
149
- ) ? y.progressItems.map(
150
- (b) => b.progressItemId === o.progressItemId ? o : b
151
- ) : [...y.progressItems, o];
152
- return { ...y, progressItems: f };
405
+ (g = e.onAgentTaskProgressItemUpdated) == null || g.call(e, o), n(
406
+ (h) => h.map((m) => {
407
+ var b;
408
+ if (((b = m.confirmedData) == null ? void 0 : b.taskId) !== o.agentTaskId)
409
+ return m;
410
+ const f = m.progressItems.some(
411
+ (C) => C.progressItemId === o.progressItemId
412
+ ) ? m.progressItems.map(
413
+ (C) => C.progressItemId === o.progressItemId ? o : C
414
+ ) : [...m.progressItems, o];
415
+ return { ...m, progressItems: f };
153
416
  })
154
417
  );
155
418
  },
156
419
  onStreamError: (o) => {
157
- var i;
158
- (i = e == null ? void 0 : e.onStreamError) == null || i.call(e, o), r((m) => {
159
- const u = m.find((S) => S.streamId === o.streamId);
160
- return u ? [
161
- ...m.filter((S) => S.streamId !== o.streamId),
420
+ var a;
421
+ (a = e == null ? void 0 : e.onStreamError) == null || a.call(e, o), n((y) => {
422
+ const g = y.find((h) => h.streamId === o.streamId);
423
+ return g ? [
424
+ ...y.filter((h) => h.streamId !== o.streamId),
162
425
  {
163
- ...u,
426
+ ...g,
164
427
  loading: !1,
165
428
  error: o.error
166
429
  }
167
- ] : m;
430
+ ] : y;
168
431
  });
169
432
  },
170
433
  onStreamNotFound: (o) => {
171
- var i;
172
- (i = e == null ? void 0 : e.onStreamNotFound) == null || i.call(e, o);
434
+ var a;
435
+ (a = e == null ? void 0 : e.onStreamNotFound) == null || a.call(e, o);
173
436
  },
174
437
  onStreamTimeout: (o) => {
175
- var i;
176
- (i = e == null ? void 0 : e.onStreamTimeout) == null || i.call(e, o);
438
+ var a;
439
+ (a = e == null ? void 0 : e.onStreamTimeout) == null || a.call(e, o);
177
440
  }
178
- }), l = W(
179
- async (o, i) => {
180
- const m = `task-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, u = await s();
181
- if (u.type === "success") {
182
- r([
183
- ...n,
441
+ }), c = W(
442
+ async (o, a) => {
443
+ const y = `task-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, g = await s();
444
+ if (g.type === "success") {
445
+ n([
446
+ ...r,
184
447
  {
185
- taskKey: m,
186
- streamId: u.stream.id,
448
+ taskKey: y,
449
+ streamId: g.stream.id,
187
450
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
188
451
  confirmedData: null,
189
452
  error: null,
@@ -191,14 +454,14 @@ const ee = (e) => {
191
454
  progressItems: [],
192
455
  loading: !0,
193
456
  doneStreaming: !1,
194
- loadingText: i == null ? void 0 : i.loadingText
457
+ loadingText: a == null ? void 0 : a.loadingText
195
458
  }
196
459
  ]);
197
- const { clientToken: S } = await e.fetchCreateAgentTaskClientToken(o.type), y = await G({
460
+ const { clientToken: h } = await e.fetchCreateAgentTaskClientToken(o.type), m = await q({
198
461
  pk: t.fency.publishableKey,
199
462
  baseUrl: t.fency.baseUrl,
200
- clientToken: S,
201
- streamToken: u.stream.token,
463
+ clientToken: h,
464
+ streamToken: g.stream.token,
202
465
  request: {
203
466
  streamingChatCompletionTask: o.type === "streamingChatCompletion" ? {
204
467
  messages: o.messages,
@@ -215,407 +478,139 @@ const ee = (e) => {
215
478
  } : void 0
216
479
  }
217
480
  });
218
- if (y.type === "success" && y.agentTask) {
219
- a.current.add(
220
- y.agentTask.id
221
- ), r((f) => [
222
- ...f.filter((h) => h.taskKey !== m),
481
+ if (m.type === "success" && m.agentTask) {
482
+ l.current.add(
483
+ m.agentTask.id
484
+ ), n((f) => [
485
+ ...f.filter((b) => b.taskKey !== y),
223
486
  {
224
- taskKey: m,
225
- streamId: u.stream.id,
487
+ taskKey: y,
488
+ streamId: g.stream.id,
226
489
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
227
- taskId: y.agentTask.id,
228
- createdAt: y.agentTask.createdAt,
490
+ taskId: m.agentTask.id,
491
+ createdAt: m.agentTask.createdAt,
229
492
  error: null,
230
493
  params: o,
231
494
  progressItems: [],
232
495
  doneStreaming: !1,
233
496
  loading: !0,
234
- loadingText: i == null ? void 0 : i.loadingText,
497
+ loadingText: a == null ? void 0 : a.loadingText,
235
498
  confirmedData: {
236
- taskId: y.agentTask.id,
237
- createdAt: y.agentTask.createdAt
499
+ taskId: m.agentTask.id,
500
+ createdAt: m.agentTask.createdAt
238
501
  }
239
502
  }
240
503
  ]);
241
- const T = await new Promise((f) => {
242
- g.current.set(
243
- y.agentTask.id,
504
+ const S = await new Promise((f) => {
505
+ u.current.set(
506
+ m.agentTask.id,
244
507
  f
245
508
  );
246
509
  });
247
510
  return {
248
511
  type: "success",
249
- streamId: u.stream.id,
250
- agentTaskId: y.agentTask.id,
251
- response: T
512
+ streamId: g.stream.id,
513
+ agentTaskId: m.agentTask.id,
514
+ response: S
252
515
  };
253
516
  } else {
254
- if (y.type === "error")
255
- return r((T) => [
256
- ...T.filter((f) => f.taskKey !== m),
517
+ if (m.type === "error")
518
+ return n((S) => [
519
+ ...S.filter((f) => f.taskKey !== y),
257
520
  {
258
- taskKey: m,
521
+ taskKey: y,
259
522
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
260
- streamId: u.stream.id,
523
+ streamId: g.stream.id,
261
524
  params: o,
262
- error: y.error,
525
+ error: m.error,
263
526
  progressItems: [],
264
527
  loading: !1,
265
528
  doneStreaming: !1,
266
- loadingText: i == null ? void 0 : i.loadingText,
529
+ loadingText: a == null ? void 0 : a.loadingText,
267
530
  confirmedData: null
268
531
  }
269
532
  ]), {
270
533
  type: "error",
271
- error: y.error
534
+ error: m.error
272
535
  };
273
536
  {
274
- const T = {
537
+ const S = {
275
538
  message: "No response received",
276
539
  code: "UnknownError"
277
540
  };
278
- return r((f) => [
279
- ...f.filter((h) => h.taskKey !== m),
541
+ return n((f) => [
542
+ ...f.filter((b) => b.taskKey !== y),
280
543
  {
281
- taskKey: m,
544
+ taskKey: y,
282
545
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
283
- streamId: u.stream.id,
284
- error: T,
546
+ streamId: g.stream.id,
547
+ error: S,
285
548
  params: o,
286
549
  progressItems: [],
287
550
  loading: !1,
288
551
  doneStreaming: !1,
289
- loadingText: i == null ? void 0 : i.loadingText,
552
+ loadingText: a == null ? void 0 : a.loadingText,
290
553
  confirmedData: null
291
554
  }
292
555
  ]), {
293
556
  type: "error",
294
- error: T
557
+ error: S
295
558
  };
296
559
  }
297
560
  }
298
561
  } else
299
- return console.error(u.error), u;
562
+ return console.error(g.error), g;
300
563
  },
301
- [t, n, s]
302
- ), d = $(() => {
303
- if (n.length !== 0)
304
- return [...n].sort((o, i) => new Date(i.triggeredAt).getTime() - new Date(o.triggeredAt).getTime())[0];
305
- }, [n]);
564
+ [t, r, s]
565
+ ), d = U(() => {
566
+ if (r.length !== 0)
567
+ return [...r].sort((o, a) => new Date(a.triggeredAt).getTime() - new Date(o.triggeredAt).getTime())[0];
568
+ }, [r]);
306
569
  return E(() => () => {
307
- a.current.clear(), g.current.clear();
570
+ l.current.clear(), u.current.clear();
308
571
  }, []), {
309
- agentTasks: n,
310
- createAgentTask: l,
572
+ agentTasks: r,
573
+ createAgentTask: c,
311
574
  latest: d
312
575
  };
313
576
  };
314
- async function ie(e, t) {
315
- const n = e.getReader();
316
- let r;
317
- for (; !(r = await n.read()).done; )
318
- t(r.value);
319
- }
320
- function se(e) {
321
- let t, n, r, a = !1;
322
- return function(s) {
323
- t === void 0 ? (t = s, n = 0, r = -1) : t = le(t, s);
324
- const l = t.length;
325
- let d = 0;
326
- for (; n < l; ) {
327
- a && (t[n] === 10 && (d = ++n), a = !1);
328
- let o = -1;
329
- for (; n < l && o === -1; ++n)
330
- switch (t[n]) {
331
- case 58:
332
- r === -1 && (r = n - d);
333
- break;
334
- case 13:
335
- a = !0;
336
- case 10:
337
- o = n;
338
- break;
339
- }
340
- if (o === -1)
341
- break;
342
- e(t.subarray(d, o), r), d = n, r = -1;
343
- }
344
- d === l ? t = void 0 : d !== 0 && (t = t.subarray(d), n -= d);
345
- };
346
- }
347
- function ce(e, t, n) {
348
- let r = O();
349
- const a = new TextDecoder();
350
- return function(s, l) {
351
- if (s.length === 0)
352
- n == null || n(r), r = O();
353
- else if (l > 0) {
354
- const d = a.decode(s.subarray(0, l)), o = l + (s[l + 1] === 32 ? 2 : 1), i = a.decode(s.subarray(o));
355
- switch (d) {
356
- case "data":
357
- r.data = r.data ? r.data + `
358
- ` + i : i;
359
- break;
360
- case "event":
361
- r.event = i;
362
- break;
363
- case "id":
364
- e(r.id = i);
365
- break;
366
- case "retry":
367
- const m = parseInt(i, 10);
368
- isNaN(m) || t(r.retry = m);
369
- break;
370
- }
371
- }
372
- };
373
- }
374
- function le(e, t) {
375
- const n = new Uint8Array(e.length + t.length);
376
- return n.set(e), n.set(t, e.length), n;
377
- }
378
- function O() {
379
- return {
380
- data: "",
381
- event: "",
382
- id: "",
383
- retry: void 0
384
- };
385
- }
386
- var de = function(e, t) {
387
- var n = {};
388
- for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]);
389
- if (e != null && typeof Object.getOwnPropertySymbols == "function")
390
- for (var a = 0, r = Object.getOwnPropertySymbols(e); a < r.length; a++)
391
- t.indexOf(r[a]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[a]) && (n[r[a]] = e[r[a]]);
392
- return n;
393
- };
394
- const F = "text/event-stream", ue = 1e3, D = "last-event-id";
395
- function j(e, t) {
396
- var { signal: n, headers: r, onopen: a, onmessage: g, onclose: s, onerror: l, openWhenHidden: d, fetch: o } = t, i = de(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
397
- return new Promise((m, u) => {
398
- const S = Object.assign({}, r);
399
- S.accept || (S.accept = F);
400
- let y;
401
- function T() {
402
- y.abort(), document.hidden || A();
403
- }
404
- d || document.addEventListener("visibilitychange", T);
405
- let f = ue, h = 0;
406
- function b() {
407
- document.removeEventListener("visibilitychange", T), window.clearTimeout(h), y.abort();
408
- }
409
- n == null || n.addEventListener("abort", () => {
410
- b(), m();
411
- });
412
- const I = o ?? window.fetch, w = a ?? me;
413
- async function A() {
414
- var M;
415
- y = new AbortController();
416
- try {
417
- const P = await I(e, Object.assign(Object.assign({}, i), { headers: S, signal: y.signal }));
418
- await w(P), await ie(P.body, se(ce((C) => {
419
- C ? S[D] = C : delete S[D];
420
- }, (C) => {
421
- f = C;
422
- }, g))), s == null || s(), b(), m();
423
- } catch (P) {
424
- if (!y.signal.aborted)
425
- try {
426
- const C = (M = l == null ? void 0 : l(P)) !== null && M !== void 0 ? M : f;
427
- window.clearTimeout(h), h = window.setTimeout(A, C);
428
- } catch (C) {
429
- b(), u(C);
430
- }
431
- }
432
- }
433
- A();
434
- });
435
- }
436
- function me(e) {
437
- const t = e.headers.get("content-type");
438
- if (!(t != null && t.startsWith(F)))
439
- throw new Error(`Expected content-type to be ${F}, Actual: ${t}`);
440
- }
441
- function We(e) {
442
- const [t, n] = k(null);
443
- return E(() => {
444
- if (!t)
445
- return;
446
- const r = new AbortController();
447
- return j(t, {
448
- headers: e == null ? void 0 : e.headers,
449
- signal: r.signal,
450
- async onopen(a) {
451
- if (!a.ok && a.status >= 400 && a.status < 500 && a.status !== 429)
452
- throw new Error(`Client error ${a.status}`);
453
- },
454
- onmessage(a) {
455
- a.data && (e == null || e.onMessage({
456
- url: t,
457
- data: H(a.data)
458
- }));
459
- },
460
- onerror(a) {
461
- throw console.error("EventSource error:", a), e == null || e.onError(t), n(null), a;
462
- },
463
- onclose() {
464
- }
465
- }), () => {
466
- r.abort();
467
- };
468
- }, [t, e == null ? void 0 : e.headers]), {
469
- setSourceUrl: n,
470
- sourceUrl: t
471
- };
472
- }
473
- function H(e) {
474
- const t = atob(e), n = new Uint8Array(t.length);
475
- for (let r = 0; r < t.length; r++)
476
- n[r] = t.charCodeAt(r);
477
- return new TextDecoder("utf-8").decode(n);
478
- }
479
- function $e(e, t) {
480
- const [n, r] = k(
481
- null
482
- ), [a, g] = k(
483
- null
484
- ), s = N(), l = async (m) => {
485
- const u = await m.fetchTokens(), { fetchTokens: S, nextPageToken: y, previousPageToken: T, ...f } = m, h = await e({
486
- pk: s.fency.publishableKey,
487
- clientToken: u.clientToken,
488
- streamToken: u.streamToken,
489
- request: {
490
- ...f,
491
- limit: (t == null ? void 0 : t.pageSize) ?? 50,
492
- pagination: {
493
- nextPageToken: y,
494
- previousPageToken: T
495
- }
496
- },
497
- baseUrl: s.fency.baseUrl
498
- });
499
- return h.type === "success" && h.items && h.pagination ? {
500
- type: "success",
501
- page: {
502
- items: h.items,
503
- hasNextPage: h.pagination.nextPageToken != null,
504
- hasPreviousPage: h.pagination.previousPageToken != null,
505
- pagination: h.pagination
506
- }
507
- } : {
508
- type: "error",
509
- error: h.error ?? {
510
- code: "UNKNOWN_ERROR",
511
- message: "An unknown error occurred"
512
- }
513
- };
514
- };
515
- return {
516
- fetchFirstPage: async (m) => {
517
- const u = await l({
518
- ...m,
519
- nextPageToken: void 0,
520
- previousPageToken: void 0
521
- });
522
- return u.type === "success" && (g(u.page), r(m)), u;
523
- },
524
- fetchNextPage: async (m) => {
525
- if (a == null)
526
- return {
527
- type: "error",
528
- error: {
529
- code: "NO_CURRENT_PAGE",
530
- message: "No current page"
531
- }
532
- };
533
- if (a.pagination.nextPageToken == null)
534
- return {
535
- type: "error",
536
- error: {
537
- code: "NO_NEXT_PAGE",
538
- message: "No next page"
539
- }
540
- };
541
- const u = await l({
542
- ...m,
543
- nextPageToken: a.pagination.nextPageToken,
544
- previousPageToken: void 0
545
- });
546
- return u.type === "success" && (g(u.page), r(m)), u;
547
- },
548
- fetchPreviousPage: async (m) => {
549
- if (a == null)
550
- return {
551
- type: "error",
552
- error: {
553
- code: "NO_CURRENT_PAGE",
554
- message: "No current page"
555
- }
556
- };
557
- if (a.pagination.previousPageToken == null)
558
- return {
559
- type: "error",
560
- error: {
561
- code: "NO_PREVIOUS_PAGE",
562
- message: "No previous page"
563
- }
564
- };
565
- const u = await l({
566
- ...m,
567
- nextPageToken: void 0,
568
- previousPageToken: a.pagination.previousPageToken
569
- });
570
- return u.type === "success" && (g(u.page), r(m)), u;
571
- },
572
- refetchCurrentPage: async () => n == null ? {
573
- type: "error",
574
- error: {
575
- code: "NO_CURRENT_PAGE",
576
- message: "No current page, please call fetchFirstPage first."
577
- }
578
- } : l(n),
579
- currentPage: a
580
- };
581
- }
582
- function ge(e) {
583
- return e.progressItems.map((t, n) => {
584
- const r = e.progressItems[n + 1], a = r != null;
585
- let g;
586
- if (r != null && r.createdAt) {
587
- const s = new Date(t.createdAt).getTime(), l = new Date(r.createdAt).getTime();
588
- g = Math.round((l - s) / 1e3);
577
+ function be(e) {
578
+ return e.progressItems.map((t, r) => {
579
+ const n = e.progressItems[r + 1], l = n != null;
580
+ let u;
581
+ if (n != null && n.createdAt) {
582
+ const s = new Date(t.createdAt).getTime(), c = new Date(n.createdAt).getTime();
583
+ u = Math.round((c - s) / 1e3);
589
584
  }
590
585
  return {
591
586
  item: t,
592
- completed: a,
593
- isLatest: n === e.progressItems.length - 1,
594
- durationSeconds: g
587
+ completed: l,
588
+ isLatest: r === e.progressItems.length - 1,
589
+ durationSeconds: u
595
590
  };
596
591
  });
597
592
  }
598
- function R({
593
+ function F({
599
594
  text: e,
600
595
  duration: t = 2,
601
- delay: n = 0,
602
- repeat: r = !0,
603
- repeatDelay: a = 0.5,
604
- className: g,
596
+ delay: r = 0,
597
+ repeat: n = !0,
598
+ repeatDelay: l = 0.5,
599
+ className: u,
605
600
  startOnView: s = !1,
606
- once: l = !1,
601
+ once: c = !1,
607
602
  inViewMargin: d,
608
603
  spread: o = 2,
609
- color: i = "#999",
610
- shimmerColor: m = "#000",
611
- direction: u = "fromBottom"
604
+ color: a = "#999",
605
+ shimmerColor: y = "#000",
606
+ direction: g = "fromBottom"
612
607
  }) {
613
- const S = p(null), y = Q(S, { once: l, margin: d }), T = $(() => e.length * o, [e, o]), f = !s || y, h = u === "fromBottom" ? "100% center" : "-100% center", b = u === "fromBottom" ? "0% center" : "200% center";
614
- return /* @__PURE__ */ c(
608
+ const h = A(null), m = Q(h, { once: c, margin: d }), S = U(() => e.length * o, [e, o]), f = !s || m, b = g === "fromBottom" ? "100% center" : "-100% center", C = g === "fromBottom" ? "0% center" : "200% center";
609
+ return /* @__PURE__ */ i(
615
610
  v.span,
616
611
  {
617
- ref: S,
618
- className: g,
612
+ ref: h,
613
+ className: u,
619
614
  style: {
620
615
  position: "relative",
621
616
  display: "inline-block",
@@ -625,38 +620,38 @@ function R({
625
620
  color: "transparent",
626
621
  WebkitTextFillColor: "transparent",
627
622
  backgroundRepeat: "no-repeat, padding-box",
628
- "--spread": `${T}px`,
629
- "--base-color": i,
630
- "--shimmer-color": m,
623
+ "--spread": `${S}px`,
624
+ "--base-color": a,
625
+ "--shimmer-color": y,
631
626
  "--shimmer-bg": "linear-gradient(90deg, transparent calc(50% - var(--spread)), var(--shimmer-color), transparent calc(50% + var(--spread)))",
632
627
  backgroundImage: "var(--shimmer-bg), linear-gradient(var(--base-color), var(--base-color))"
633
628
  },
634
629
  initial: {
635
- backgroundPosition: h,
630
+ backgroundPosition: b,
636
631
  opacity: 0
637
632
  },
638
633
  animate: f ? {
639
- backgroundPosition: b,
634
+ backgroundPosition: C,
640
635
  opacity: 1
641
636
  } : {},
642
637
  transition: {
643
638
  backgroundPosition: {
644
- repeat: r ? 1 / 0 : 0,
639
+ repeat: n ? 1 / 0 : 0,
645
640
  duration: t,
646
- delay: n,
647
- repeatDelay: a,
641
+ delay: r,
642
+ repeatDelay: l,
648
643
  ease: "linear"
649
644
  },
650
645
  opacity: {
651
646
  duration: 0.3,
652
- delay: n
647
+ delay: r
653
648
  }
654
649
  },
655
650
  children: e
656
651
  }
657
652
  );
658
653
  }
659
- function ye(e) {
654
+ function Ce(e) {
660
655
  const t = e.item.data;
661
656
  if (t.taskType === "StreamingChatCompletion") {
662
657
  if (t.eventType === "Text") return "Streaming...";
@@ -687,28 +682,28 @@ function ye(e) {
687
682
  }
688
683
  return "Processing...";
689
684
  }
690
- const fe = ({ progressViewItems: e }) => {
685
+ const Te = ({ progressViewItems: e }) => {
691
686
  const t = e[e.length - 1];
692
687
  if (!t) return null;
693
- const n = ye(t);
694
- return /* @__PURE__ */ c("div", { className: "simple-mode-container", children: /* @__PURE__ */ c(B, { mode: "wait", children: /* @__PURE__ */ c(
688
+ const r = Ce(t);
689
+ return /* @__PURE__ */ i("div", { className: "simple-mode-container", children: /* @__PURE__ */ i(L, { mode: "wait", children: /* @__PURE__ */ i(
695
690
  v.div,
696
691
  {
697
692
  initial: { opacity: 0, y: 10 },
698
693
  animate: { opacity: 1, y: 0 },
699
694
  exit: { opacity: 0, y: -10 },
700
695
  transition: { duration: 0.3 },
701
- children: t.completed ? /* @__PURE__ */ c(
696
+ children: t.completed ? /* @__PURE__ */ i(
702
697
  "div",
703
698
  {
704
699
  className: "simple-mode-title",
705
700
  style: { color: "#666" },
706
- children: n
701
+ children: r
707
702
  }
708
- ) : /* @__PURE__ */ c(
709
- R,
703
+ ) : /* @__PURE__ */ i(
704
+ F,
710
705
  {
711
- text: n,
706
+ text: r,
712
707
  className: "simple-mode-title",
713
708
  duration: 2.5,
714
709
  repeat: !0,
@@ -719,7 +714,7 @@ const fe = ({ progressViewItems: e }) => {
719
714
  },
720
715
  t.item.progressItemId
721
716
  ) }) });
722
- }, K = {
717
+ }, j = {
723
718
  'code[class*="language-"]': {
724
719
  color: "#f8f8f2",
725
720
  background: "none",
@@ -870,53 +865,53 @@ const fe = ({ progressViewItems: e }) => {
870
865
  italic: {
871
866
  fontStyle: "italic"
872
867
  }
873
- }, U = ({
868
+ }, z = ({
874
869
  text: e
875
- }) => /* @__PURE__ */ c("div", { style: { padding: "16px" }, children: /* @__PURE__ */ c(
870
+ }) => /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ i(
876
871
  v.div,
877
872
  {
878
873
  className: "fency-markdown-body-raw",
879
874
  initial: { opacity: 0, y: -10 },
880
875
  animate: { opacity: 1, y: 0 },
881
876
  transition: { duration: 0.3, delay: 0 },
882
- children: /* @__PURE__ */ c(
877
+ children: /* @__PURE__ */ i(
883
878
  Y,
884
879
  {
885
880
  remarkPlugins: [Z],
886
881
  components: {
887
882
  code(t) {
888
- const { children: n, className: r, node: a, ref: g, ...s } = t, l = /language-(\w+)/.exec(r || "");
889
- return l ? /* @__PURE__ */ c(
890
- L,
883
+ const { children: r, className: n, node: l, ref: u, ...s } = t, c = /language-(\w+)/.exec(n || "");
884
+ return c ? /* @__PURE__ */ i(
885
+ $,
891
886
  {
892
887
  ...s,
893
888
  PreTag: "div",
894
- children: String(n).replace(/\n$/, ""),
895
- language: l[1],
896
- style: K
889
+ children: String(r).replace(/\n$/, ""),
890
+ language: c[1],
891
+ style: j
897
892
  }
898
- ) : /* @__PURE__ */ c("code", { ...s, className: r, children: String(n) });
893
+ ) : /* @__PURE__ */ i("code", { ...s, className: n, children: String(r) });
899
894
  }
900
895
  },
901
896
  children: e
902
897
  }
903
898
  )
904
899
  }
905
- ) }), he = ({ data: e }) => {
900
+ ) }), ve = ({ data: e }) => {
906
901
  const t = JSON.stringify(e.json, null, 2);
907
- return /* @__PURE__ */ c("div", { id: "structured-chat-completion-response", children: /* @__PURE__ */ c(
902
+ return /* @__PURE__ */ i("div", { id: "structured-chat-completion-response", children: /* @__PURE__ */ i(
908
903
  v.div,
909
904
  {
910
905
  initial: { opacity: 0, y: -10 },
911
906
  animate: { opacity: 1, y: 0 },
912
907
  transition: { duration: 0.3, delay: 0 },
913
- children: /* @__PURE__ */ c(L, { language: "json", style: K, PreTag: "div", children: t })
908
+ children: /* @__PURE__ */ i($, { language: "json", style: j, PreTag: "div", children: t })
914
909
  }
915
910
  ) });
916
- }, Se = ({ data: e, isLatest: t = !1, durationSeconds: n }) => {
917
- const r = `Searching: ${e.queryDescription}`;
918
- return /* @__PURE__ */ x("div", { style: { padding: "16px" }, children: [
919
- /* @__PURE__ */ c(
911
+ }, ke = ({ data: e, isLatest: t = !1, durationSeconds: r }) => {
912
+ const n = `Searching: ${e.queryDescription}`;
913
+ return /* @__PURE__ */ k("div", { style: { padding: "16px" }, children: [
914
+ /* @__PURE__ */ i(
920
915
  v.div,
921
916
  {
922
917
  style: {
@@ -928,19 +923,19 @@ const fe = ({ progressViewItems: e }) => {
928
923
  initial: { opacity: 0, y: -10 },
929
924
  animate: { opacity: 1, y: 0 },
930
925
  transition: { duration: 0.3, delay: 0 },
931
- children: t && !n ? /* @__PURE__ */ c(
932
- R,
926
+ children: t && !r ? /* @__PURE__ */ i(
927
+ F,
933
928
  {
934
- text: r,
929
+ text: n,
935
930
  duration: 2.5,
936
931
  repeat: !0,
937
932
  color: "#999",
938
933
  shimmerColor: "#000"
939
934
  }
940
- ) : /* @__PURE__ */ c("span", { style: { color: "#666" }, children: r })
935
+ ) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: n })
941
936
  }
942
937
  ),
943
- n !== void 0 && /* @__PURE__ */ x(
938
+ r !== void 0 && /* @__PURE__ */ k(
944
939
  "div",
945
940
  {
946
941
  style: {
@@ -951,16 +946,16 @@ const fe = ({ progressViewItems: e }) => {
951
946
  },
952
947
  children: [
953
948
  "Took ",
954
- n,
949
+ r,
955
950
  " seconds"
956
951
  ]
957
952
  }
958
953
  )
959
954
  ] });
960
- }, Te = ({ isLatest: e = !1, durationSeconds: t }) => {
961
- const n = "Adding sources...";
962
- return /* @__PURE__ */ x("div", { style: { padding: "16px" }, children: [
963
- /* @__PURE__ */ c(
955
+ }, xe = ({ isLatest: e = !1, durationSeconds: t }) => {
956
+ const r = "Adding sources...";
957
+ return /* @__PURE__ */ k("div", { style: { padding: "16px" }, children: [
958
+ /* @__PURE__ */ i(
964
959
  v.div,
965
960
  {
966
961
  style: {
@@ -972,19 +967,19 @@ const fe = ({ progressViewItems: e }) => {
972
967
  initial: { opacity: 0, y: -10 },
973
968
  animate: { opacity: 1, y: 0 },
974
969
  transition: { duration: 0.3, delay: 0 },
975
- children: e && !t ? /* @__PURE__ */ c(
976
- R,
970
+ children: e && !t ? /* @__PURE__ */ i(
971
+ F,
977
972
  {
978
- text: n,
973
+ text: r,
979
974
  duration: 2.5,
980
975
  repeat: !0,
981
976
  color: "#999",
982
977
  shimmerColor: "#000"
983
978
  }
984
- ) : /* @__PURE__ */ c("span", { style: { color: "#666" }, children: n })
979
+ ) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: r })
985
980
  }
986
981
  ),
987
- t !== void 0 && /* @__PURE__ */ x(
982
+ t !== void 0 && /* @__PURE__ */ k(
988
983
  "div",
989
984
  {
990
985
  style: {
@@ -1001,120 +996,122 @@ const fe = ({ progressViewItems: e }) => {
1001
996
  }
1002
997
  )
1003
998
  ] });
1004
- }, be = ({ data: e, onSourceClick: t }) => /* @__PURE__ */ x("div", { style: { padding: "16px" }, children: [
1005
- /* @__PURE__ */ c(
999
+ }, we = ({ data: e, onSourceClick: t }) => /* @__PURE__ */ k("div", { style: { padding: "16px" }, children: [
1000
+ /* @__PURE__ */ i(
1006
1001
  v.div,
1007
1002
  {
1008
- style: { color: "#666", marginBottom: "10px", fontSize: "14px" },
1003
+ style: {
1004
+ marginBottom: "10px",
1005
+ fontSize: "11px",
1006
+ fontWeight: 500,
1007
+ letterSpacing: "0.05em",
1008
+ textTransform: "uppercase",
1009
+ color: "#999"
1010
+ },
1009
1011
  initial: { opacity: 0, y: -10 },
1010
1012
  animate: { opacity: 1, y: 0 },
1011
1013
  transition: { duration: 0.3, delay: 0 },
1012
1014
  children: "Sources"
1013
1015
  }
1014
1016
  ),
1015
- /* @__PURE__ */ c("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: e.sources.length === 0 ? /* @__PURE__ */ c("span", { style: { fontSize: "13px", color: "#888" }, children: "No sources" }) : e.sources.map((n, r) => /* @__PURE__ */ c(
1016
- Ce,
1017
+ /* @__PURE__ */ i("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: e.sources.length === 0 ? /* @__PURE__ */ i("span", { style: { fontSize: "13px", color: "#888" }, children: "No sources" }) : e.sources.map((r, n) => /* @__PURE__ */ i(
1018
+ Ie,
1017
1019
  {
1018
- source: n,
1019
- index: r,
1020
+ source: r,
1021
+ index: n,
1020
1022
  onSourceClick: t
1021
1023
  },
1022
- n.memoryId
1024
+ r.memoryId
1023
1025
  )) })
1024
1026
  ] });
1025
- function ke(e, t) {
1026
- if (t.length === 0) return e;
1027
- if (t.length === 1) return `${e} page ${t[0]}`;
1028
- if (t.length === 2)
1029
- return `${e} pages ${t[0]} and ${t[1]}`;
1030
- const n = t[t.length - 1], r = t.slice(0, -1).join(", ");
1031
- return `${e} pages ${r} and ${n}`;
1027
+ function pe(e) {
1028
+ if (e.length === 0) return "";
1029
+ if (e.length === 1) return `page ${e[0]}`;
1030
+ if (e.length === 2)
1031
+ return `pages ${e[0]} and ${e[1]}`;
1032
+ const t = e[e.length - 1];
1033
+ return `pages ${e.slice(0, -1).join(", ")} and ${t}`;
1032
1034
  }
1033
- const Ce = ({ source: e, index: t, onSourceClick: n }) => {
1034
- const [r, a] = k(!1), g = !!n, s = ke(e.memoryTitle, e.pageNumbers);
1035
- return /* @__PURE__ */ c(
1035
+ const Ie = ({ source: e, index: t, onSourceClick: r }) => {
1036
+ const [n, l] = w(!1), u = !!r, s = e.pageNumbers ?? [], c = pe(s);
1037
+ return /* @__PURE__ */ k(
1036
1038
  v.div,
1037
1039
  {
1038
1040
  initial: { opacity: 0, scale: 0.9 },
1039
1041
  animate: { opacity: 1, scale: 1 },
1040
1042
  transition: { duration: 0.25, delay: t * 0.05 },
1041
- onClick: g ? () => n(e.memoryId) : void 0,
1042
- onMouseEnter: g ? () => a(!0) : void 0,
1043
- onMouseLeave: g ? () => a(!1) : void 0,
1043
+ onClick: u ? () => r(e.memoryId) : void 0,
1044
+ onMouseEnter: u ? () => l(!0) : void 0,
1045
+ onMouseLeave: u ? () => l(!1) : void 0,
1044
1046
  style: {
1045
1047
  display: "inline-flex",
1046
1048
  flexDirection: "column",
1047
1049
  gap: "4px",
1048
1050
  padding: "8px 12px",
1049
- borderRadius: "8px",
1051
+ borderRadius: "6px",
1050
1052
  border: "1px solid #e0e0e0",
1051
- backgroundColor: r ? "#f0f0f0" : "#f9f9f9",
1052
- cursor: g ? "pointer" : "default",
1053
+ backgroundColor: n ? "#f5f5f5" : "transparent",
1054
+ cursor: u ? "pointer" : "default",
1053
1055
  transition: "background-color 0.15s ease",
1054
1056
  userSelect: "none"
1055
1057
  },
1056
- children: /* @__PURE__ */ c("span", { style: { fontSize: "13px", fontWeight: 500, color: "#333" }, children: s })
1058
+ children: [
1059
+ /* @__PURE__ */ i("span", { style: { fontSize: "13px", fontWeight: 500, color: "#333" }, children: e.memoryTitle }),
1060
+ c && /* @__PURE__ */ i("span", { style: { fontSize: "12px", color: "#666" }, children: c })
1061
+ ]
1057
1062
  }
1058
1063
  );
1059
- }, ve = `
1060
- @keyframes explore-memory-spinner {
1061
- to { transform: rotate(360deg); }
1064
+ };
1065
+ function Ee({
1066
+ eventType: e,
1067
+ completed: t
1068
+ }) {
1069
+ return e === "ExploreMemoryError" ? /* @__PURE__ */ i("span", { style: { color: "#c62828", fontSize: 14, fontWeight: 600 }, children: "✗" }) : e === "ExploreMemoryResult" ? /* @__PURE__ */ i("span", { style: { color: "#999", fontSize: 14, fontWeight: 600 }, children: "✓" }) : e === "ExploreMemoryStart" && t ? /* @__PURE__ */ i("span", { style: { color: "#999", fontSize: 14, fontWeight: 600 }, children: "✓" }) : null;
1062
1070
  }
1063
- `;
1064
- function xe() {
1065
- return /* @__PURE__ */ x(X, { children: [
1066
- /* @__PURE__ */ c("style", { children: ve }),
1067
- /* @__PURE__ */ c(
1071
+ const B = 80, Ae = ({ data: e, completed: t, isLatest: r = !1 }) => {
1072
+ const [n, l] = w(!1), u = e.eventType === "ExploreMemoryResult" ? e.result : void 0, s = u != null && u.length > B, c = u != null ? n || !s ? u : `${u.slice(0, B)}...` : void 0, d = s;
1073
+ if (e.eventType === "ExploreMemoryStart" && !t) {
1074
+ const a = `Exploring ${e.memoryTitle}...`;
1075
+ return /* @__PURE__ */ i(
1068
1076
  "div",
1069
1077
  {
1070
1078
  style: {
1071
- width: 12,
1072
- height: 12,
1073
- border: "2px solid #e0e0e0",
1074
- borderTopColor: "#666",
1075
- borderRadius: "50%",
1076
- animation: "explore-memory-spinner 0.8s linear infinite"
1077
- }
1079
+ padding: "16px",
1080
+ display: "flex",
1081
+ alignItems: "center"
1082
+ },
1083
+ children: r ? /* @__PURE__ */ i(
1084
+ F,
1085
+ {
1086
+ text: a,
1087
+ duration: 2.5,
1088
+ repeat: !0,
1089
+ color: "#999",
1090
+ shimmerColor: "#000"
1091
+ }
1092
+ ) : /* @__PURE__ */ i("span", { style: { fontSize: 13, color: "#999" }, children: a })
1078
1093
  }
1079
- )
1080
- ] });
1081
- }
1082
- function we({
1083
- eventType: e,
1084
- completed: t
1085
- }) {
1086
- return e === "ExploreMemoryError" ? /* @__PURE__ */ c("span", { style: { color: "#c62828", fontSize: 14, fontWeight: 600 }, children: "✗" }) : e === "ExploreMemoryResult" ? /* @__PURE__ */ c("span", { style: { color: "#2e7d32", fontSize: 14, fontWeight: 600 }, children: "✓" }) : e === "ExploreMemoryStart" ? t ? /* @__PURE__ */ c("span", { style: { color: "#2e7d32", fontSize: 14, fontWeight: 600 }, children: "✓" }) : /* @__PURE__ */ c(xe, {}) : null;
1087
- }
1088
- const z = 80, Ee = ({ data: e, completed: t }) => {
1089
- const [n, r] = k(!1), a = e.eventType === "ExploreMemoryResult" ? e.result : void 0, g = a != null && a.length > z, s = a != null ? n || !g ? a : `${a.slice(0, z)}...` : void 0, l = g;
1090
- return /* @__PURE__ */ c("div", { style: { padding: "16px" }, children: /* @__PURE__ */ x(
1094
+ );
1095
+ }
1096
+ return /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ k(
1091
1097
  v.div,
1092
1098
  {
1093
- initial: { opacity: 0, scale: 0.9 },
1094
- animate: { opacity: 1, scale: 1 },
1095
- transition: { duration: 0.25, delay: 0 },
1096
- onClick: l ? () => r((d) => !d) : void 0,
1099
+ initial: { opacity: 0 },
1100
+ animate: { opacity: 1 },
1101
+ transition: { duration: 0.25 },
1102
+ onClick: d ? () => l((a) => !a) : void 0,
1097
1103
  style: {
1098
- display: "inline-flex",
1104
+ paddingBottom: "12px",
1105
+ borderBottom: "1px solid #eee",
1106
+ display: "flex",
1099
1107
  flexDirection: "row",
1100
1108
  alignItems: "flex-start",
1101
1109
  gap: "10px",
1102
- padding: "8px 12px",
1103
- borderRadius: "8px",
1104
- border: "1px solid #e0e0e0",
1105
- backgroundColor: "#f9f9f9",
1106
1110
  minWidth: 0,
1107
- cursor: l ? "pointer" : "default",
1108
- transition: "background-color 0.15s ease"
1111
+ cursor: d ? "pointer" : "default"
1109
1112
  },
1110
- onMouseEnter: l ? (d) => {
1111
- d.currentTarget.style.backgroundColor = "#f0f0f0";
1112
- } : void 0,
1113
- onMouseLeave: l ? (d) => {
1114
- d.currentTarget.style.backgroundColor = "#f9f9f9";
1115
- } : void 0,
1116
1113
  children: [
1117
- /* @__PURE__ */ c(
1114
+ /* @__PURE__ */ i(
1118
1115
  "div",
1119
1116
  {
1120
1117
  style: {
@@ -1124,10 +1121,10 @@ const z = 80, Ee = ({ data: e, completed: t }) => {
1124
1121
  flexShrink: 0,
1125
1122
  width: 20
1126
1123
  },
1127
- children: /* @__PURE__ */ c(we, { eventType: e.eventType, completed: t })
1124
+ children: /* @__PURE__ */ i(Ee, { eventType: e.eventType, completed: t })
1128
1125
  }
1129
1126
  ),
1130
- /* @__PURE__ */ x(
1127
+ /* @__PURE__ */ k(
1131
1128
  "div",
1132
1129
  {
1133
1130
  style: {
@@ -1137,8 +1134,8 @@ const z = 80, Ee = ({ data: e, completed: t }) => {
1137
1134
  minWidth: 0
1138
1135
  },
1139
1136
  children: [
1140
- /* @__PURE__ */ c("span", { style: { fontSize: 13, fontWeight: 500, color: "#333" }, children: e.memoryTitle }),
1141
- s != null && /* @__PURE__ */ c(
1137
+ /* @__PURE__ */ i("span", { style: { fontSize: 13, fontWeight: 500, color: "#333" }, children: e.memoryTitle }),
1138
+ c != null && /* @__PURE__ */ i(
1142
1139
  "span",
1143
1140
  {
1144
1141
  style: {
@@ -1147,10 +1144,10 @@ const z = 80, Ee = ({ data: e, completed: t }) => {
1147
1144
  lineHeight: 1.4,
1148
1145
  whiteSpace: n ? "pre-wrap" : void 0
1149
1146
  },
1150
- children: s
1147
+ children: c
1151
1148
  }
1152
1149
  ),
1153
- l && /* @__PURE__ */ c(
1150
+ d && /* @__PURE__ */ i(
1154
1151
  "span",
1155
1152
  {
1156
1153
  style: {
@@ -1167,62 +1164,62 @@ const z = 80, Ee = ({ data: e, completed: t }) => {
1167
1164
  ]
1168
1165
  }
1169
1166
  ) });
1170
- }, Ie = ({
1167
+ }, Me = ({
1171
1168
  progressViewItems: e,
1172
1169
  streamToken: t,
1173
- fetchClientToken: n,
1174
- loadingText: r,
1175
- onSourceClick: a
1170
+ fetchClientToken: r,
1171
+ loadingText: n,
1172
+ onSourceClick: l
1176
1173
  }) => {
1177
- const g = p(null);
1174
+ const u = A(null);
1178
1175
  E(() => {
1179
- g.current && (g.current.scrollTop = g.current.scrollHeight);
1176
+ u.current && (u.current.scrollTop = u.current.scrollHeight);
1180
1177
  }, [e.length]);
1181
- const s = (l) => {
1182
- const d = l.item.data;
1178
+ const s = (c) => {
1179
+ const d = c.item.data;
1183
1180
  if (d.taskType === "StreamingChatCompletion" && d.eventType === "Text")
1184
- return /* @__PURE__ */ c(U, { text: d.text });
1181
+ return /* @__PURE__ */ i(z, { text: d.text });
1185
1182
  if (d.taskType === "StructuredChatCompletion" && d.eventType === "Json")
1186
- return /* @__PURE__ */ c(he, { data: d });
1183
+ return /* @__PURE__ */ i(ve, { data: d });
1187
1184
  if (d.taskType === "StreamingMemoryTypeChatCompletion")
1188
1185
  switch (d.eventType) {
1189
1186
  case "Text":
1190
- return /* @__PURE__ */ c(U, { text: d.text });
1187
+ return /* @__PURE__ */ i(z, { text: d.text });
1191
1188
  case "Search":
1192
- return /* @__PURE__ */ c(
1193
- Se,
1189
+ return /* @__PURE__ */ i(
1190
+ ke,
1194
1191
  {
1195
1192
  data: d,
1196
- isLatest: l.isLatest,
1197
- durationSeconds: l.durationSeconds
1193
+ isLatest: c.isLatest,
1194
+ durationSeconds: c.durationSeconds
1198
1195
  }
1199
1196
  );
1200
1197
  case "FindSources":
1201
- return /* @__PURE__ */ c(
1202
- Te,
1198
+ return /* @__PURE__ */ i(
1199
+ xe,
1203
1200
  {
1204
1201
  data: d,
1205
- isLatest: l.isLatest,
1206
- durationSeconds: l.durationSeconds
1202
+ isLatest: c.isLatest,
1203
+ durationSeconds: c.durationSeconds
1207
1204
  }
1208
1205
  );
1209
1206
  case "SourcesResult":
1210
- return /* @__PURE__ */ c(
1211
- be,
1207
+ return /* @__PURE__ */ i(
1208
+ we,
1212
1209
  {
1213
1210
  data: d,
1214
- onSourceClick: a
1211
+ onSourceClick: l
1215
1212
  }
1216
1213
  );
1217
1214
  case "ExploreMemoryStart":
1218
1215
  case "ExploreMemoryResult":
1219
1216
  case "ExploreMemoryError":
1220
- return /* @__PURE__ */ c(
1221
- Ee,
1217
+ return /* @__PURE__ */ i(
1218
+ Ae,
1222
1219
  {
1223
1220
  data: d,
1224
- completed: l.completed,
1225
- isLatest: l.isLatest
1221
+ completed: c.completed,
1222
+ isLatest: c.isLatest
1226
1223
  }
1227
1224
  );
1228
1225
  case "Completed":
@@ -1230,20 +1227,20 @@ const z = 80, Ee = ({ data: e, completed: t }) => {
1230
1227
  }
1231
1228
  return d.taskType === "StreamingChatCompletion" && d.eventType === "Completed" || d.taskType === "StructuredChatCompletion" && d.eventType === "Completed", null;
1232
1229
  };
1233
- return e.length === 0 ? /* @__PURE__ */ c("div", { style: { width: "fit-content" }, children: /* @__PURE__ */ c(
1234
- R,
1230
+ return e.length === 0 ? /* @__PURE__ */ i("div", { style: { width: "fit-content" }, children: /* @__PURE__ */ i(
1231
+ F,
1235
1232
  {
1236
- text: r ?? "Processing your task...",
1233
+ text: n ?? "Processing your task...",
1237
1234
  duration: 1.5,
1238
1235
  repeat: !0,
1239
1236
  repeatDelay: 0,
1240
1237
  color: "#999",
1241
1238
  shimmerColor: "#000"
1242
1239
  }
1243
- ) }) : /* @__PURE__ */ c("div", { id: "agent-task-progress-verbose", ref: g, children: /* @__PURE__ */ c(B, { children: e.map((l, d) => /* @__PURE__ */ c(
1240
+ ) }) : /* @__PURE__ */ i("div", { id: "agent-task-progress-verbose", ref: u, children: /* @__PURE__ */ i(L, { children: e.map((c, d) => /* @__PURE__ */ i(
1244
1241
  v.div,
1245
1242
  {
1246
- id: `agent-task-progress-item-${l.item.progressItemId}`,
1243
+ id: `agent-task-progress-item-${c.item.progressItemId}`,
1247
1244
  initial: { opacity: 0, y: -20 },
1248
1245
  animate: { opacity: 1, y: 0 },
1249
1246
  transition: {
@@ -1251,186 +1248,31 @@ const z = 80, Ee = ({ data: e, completed: t }) => {
1251
1248
  delay: d * 0.1,
1252
1249
  ease: "easeOut"
1253
1250
  },
1254
- children: s(l)
1251
+ children: s(c)
1255
1252
  },
1256
- l.item.progressItemId
1253
+ c.item.progressItemId
1257
1254
  )) }) });
1258
- }, Be = ({
1255
+ }, Le = ({
1259
1256
  agentTask: e,
1260
1257
  mode: t = "verbose",
1261
- streamToken: n,
1262
- fetchClientToken: r,
1263
- onSourceClick: a
1258
+ streamToken: r,
1259
+ fetchClientToken: n,
1260
+ onSourceClick: l
1264
1261
  }) => {
1265
- const g = ge(e);
1266
- return t === "simple" ? /* @__PURE__ */ c(fe, { progressViewItems: g }) : /* @__PURE__ */ c(
1267
- Ie,
1262
+ const u = be(e);
1263
+ return t === "simple" ? /* @__PURE__ */ i(Te, { progressViewItems: u }) : /* @__PURE__ */ i(
1264
+ Me,
1268
1265
  {
1269
- progressViewItems: g,
1270
- streamToken: n,
1271
- fetchClientToken: r,
1266
+ progressViewItems: u,
1267
+ streamToken: r,
1268
+ fetchClientToken: n,
1272
1269
  loadingText: e.loadingText,
1273
- onSourceClick: a
1270
+ onSourceClick: l
1274
1271
  }
1275
1272
  );
1276
1273
  };
1277
- class Ae {
1278
- constructor(t) {
1279
- this.eventSources = /* @__PURE__ */ new Map(), this.subscribers = /* @__PURE__ */ new Map(), this.fency = t;
1280
- }
1281
- /**
1282
- * Called by FencyProvider when activeStreams changes.
1283
- * Creates new connections and removes old ones.
1284
- */
1285
- updateStreams(t) {
1286
- t.forEach((r) => {
1287
- const a = r.stream.id;
1288
- this.eventSources.has(a) || this.connectStream(r);
1289
- });
1290
- const n = new Set(t.map((r) => r.stream.id));
1291
- this.eventSources.forEach((r, a) => {
1292
- n.has(a) || (r.abort(), this.eventSources.delete(a));
1293
- });
1294
- }
1295
- connectStream(t) {
1296
- const n = t.stream.id, r = new AbortController();
1297
- this.eventSources.set(n, r);
1298
- const a = `${this.fency.baseUrl}/sse/streams/${n}`, g = {
1299
- "X-Fency-Publishable-Key": this.fency.publishableKey,
1300
- "X-Fency-Stream-Token": t.stream.token
1301
- };
1302
- j(a, {
1303
- headers: g,
1304
- signal: r.signal,
1305
- async onopen(s) {
1306
- if (!s.ok && s.status >= 400 && s.status < 500 && s.status !== 429)
1307
- throw new Error(`Client error ${s.status}`);
1308
- },
1309
- onmessage: (s) => {
1310
- if (s.data) {
1311
- const l = H(s.data);
1312
- this.broadcast(l, n);
1313
- }
1314
- },
1315
- onerror: (s) => {
1316
- throw console.error("EventSource error for stream", n, ":", s), this.broadcastError(n), s;
1317
- },
1318
- onclose() {
1319
- }
1320
- });
1321
- }
1322
- /**
1323
- * Subscribe to events from all active streams.
1324
- * Returns an unsubscribe function.
1325
- */
1326
- subscribe(t, n) {
1327
- return this.subscribers.set(t, n), () => {
1328
- this.subscribers.delete(t);
1329
- };
1330
- }
1331
- broadcast(t, n) {
1332
- this.subscribers.forEach((r) => {
1333
- r.onMessage(t, n);
1334
- });
1335
- }
1336
- broadcastError(t) {
1337
- this.subscribers.forEach((n) => {
1338
- n.onError(t);
1339
- });
1340
- }
1341
- /**
1342
- * Cleanup all connections and subscriptions
1343
- */
1344
- cleanup() {
1345
- this.eventSources.forEach((t) => t.abort()), this.eventSources.clear(), this.subscribers.clear();
1346
- }
1347
- }
1348
- const pe = 12e4, Pe = (e) => {
1349
- const t = Date.now();
1350
- return e.filter((n) => t - n.createdAt < pe);
1351
- };
1352
- function Le({ fency: e, fetchCreateStreamClientToken: t, children: n }) {
1353
- const [r, a] = k(
1354
- null
1355
- ), [g, s] = k(!0), [l, d] = k(null), [o, i] = k([]), m = p(null), u = p(null);
1356
- E(() => {
1357
- e.then((f) => {
1358
- a(f), s(!1);
1359
- }).catch((f) => {
1360
- d(f), s(!1);
1361
- });
1362
- }, [e]), E(() => {
1363
- r && !u.current && (u.current = new Ae(r));
1364
- }, [r]), E(() => {
1365
- u.current && u.current.updateStreams(o);
1366
- }, [o]), E(() => () => {
1367
- var f;
1368
- (f = u.current) == null || f.cleanup();
1369
- }, []);
1370
- const S = W(
1371
- async (f = 3e4) => {
1372
- if (m.current)
1373
- return m.current;
1374
- const h = Date.now(), b = o.length > 0 ? o[o.length - 1] : null;
1375
- if (b && h - b.createdAt < f)
1376
- return b.stream;
1377
- const I = (async () => {
1378
- if (!r)
1379
- throw new Error("Fency instance not initialized");
1380
- const w = await t(), A = await J({
1381
- pk: r.publishableKey,
1382
- baseUrl: r.baseUrl,
1383
- clientToken: (w == null ? void 0 : w.clientToken) ?? ""
1384
- });
1385
- if (A.type === "success") {
1386
- const M = {
1387
- stream: A.stream,
1388
- createdAt: Date.now()
1389
- };
1390
- return i((P) => {
1391
- const C = [...P, M];
1392
- return Pe(C);
1393
- }), m.current = null, A.stream;
1394
- } else
1395
- throw m.current = null, new Error("Failed to create stream");
1396
- })();
1397
- return m.current = I, I;
1398
- },
1399
- [r, o]
1400
- );
1401
- if (l)
1402
- return /* @__PURE__ */ x("div", { children: [
1403
- "Fency error: ",
1404
- l.message
1405
- ] });
1406
- if (!r)
1407
- return null;
1408
- const y = o.length > 0 ? o[o.length - 1] : null, T = {
1409
- fency: r,
1410
- loading: g,
1411
- error: l,
1412
- activeStreams: o,
1413
- latestStream: y,
1414
- eventManager: u.current,
1415
- getOrCreateStream: S
1416
- };
1417
- return /* @__PURE__ */ c(_.Provider, { value: T, children: n });
1418
- }
1419
1274
  export {
1420
- Be as AgentTaskProgress,
1421
- fe as AgentTaskProgressSimple,
1422
- Ie as AgentTaskProgressVerbose,
1423
- Le as FencyProvider,
1424
- R as ShimmeringText,
1425
- U as StreamingChatCompletionText,
1426
- Ee as StreamingMemoryTypeChatCompletionExploreMemory,
1427
- Te as StreamingMemoryTypeChatCompletionFindSources,
1428
- Se as StreamingMemoryTypeChatCompletionSearch,
1429
- be as StreamingMemoryTypeChatCompletionSourcesResult,
1430
- he as StructuredChatCompletionJson,
1431
- ze as useAgentTasks,
1432
- N as useFencyContext,
1433
- We as useFencyEventSource,
1434
- $e as usePaginatedQuery,
1435
- oe as useStream
1275
+ Le as AgentTaskProgress,
1276
+ We as FencyProvider,
1277
+ Ue as useAgentTasks
1436
1278
  };