@fencyai/react 0.1.138 → 0.1.139

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,78 +1,78 @@
1
- import { jsxs as x, jsx as i } from "react/jsx-runtime";
2
- import { createStream as G, isStreamTimeoutEvent as J, isStreamNotFoundEvent as V, isAgentTaskProgressItemUpdatedEvent as X, createAgentTask as q } from "@fencyai/js";
3
- import { createContext as Y, useState as v, useRef as w, useEffect as E, useCallback as _, useContext as Q, useMemo as z } from "react";
4
- import { useInView as Z, motion as k, AnimatePresence as $ } from "motion/react";
1
+ import { jsxs as v, jsx as i } from "react/jsx-runtime";
2
+ import { createStream as G, isStreamTimeoutEvent as J, isStreamNotFoundEvent as V, isAgentTaskProgressItemUpdatedEvent as X, createAgentTask as Y } from "@fencyai/js";
3
+ import { createContext as q, useState as C, useRef as A, useEffect as w, useCallback as _, useContext as Q, useMemo as $ } from "react";
4
+ import { useInView as Z, motion as T, AnimatePresence as W } from "motion/react";
5
5
  import ee from "react-markdown";
6
6
  import { Prism as j } from "react-syntax-highlighter";
7
7
  import te from "remark-gfm";
8
- import './assets/index.css';const W = Y(
8
+ import './assets/index.css';const H = q(
9
9
  void 0
10
10
  );
11
- async function re(e, t) {
12
- const r = e.getReader();
13
- let n;
14
- for (; !(n = await r.read()).done; )
15
- t(n.value);
11
+ async function ne(e, t) {
12
+ const n = e.getReader();
13
+ let r;
14
+ for (; !(r = await n.read()).done; )
15
+ t(r.value);
16
16
  }
17
- function ne(e) {
18
- let t, r, n, s = !1;
17
+ function re(e) {
18
+ let t, n, r, s = !1;
19
19
  return function(o) {
20
- t === void 0 ? (t = o, r = 0, n = -1) : t = ae(t, o);
20
+ t === void 0 ? (t = o, n = 0, r = -1) : t = ae(t, o);
21
21
  const l = t.length;
22
- let y = 0;
23
- for (; r < l; ) {
24
- s && (t[r] === 10 && (y = ++r), s = !1);
22
+ let u = 0;
23
+ for (; n < l; ) {
24
+ s && (t[n] === 10 && (u = ++n), s = !1);
25
25
  let a = -1;
26
- for (; r < l && a === -1; ++r)
27
- switch (t[r]) {
26
+ for (; n < l && a === -1; ++n)
27
+ switch (t[n]) {
28
28
  case 58:
29
- n === -1 && (n = r - y);
29
+ r === -1 && (r = n - u);
30
30
  break;
31
31
  case 13:
32
32
  s = !0;
33
33
  case 10:
34
- a = r;
34
+ a = n;
35
35
  break;
36
36
  }
37
37
  if (a === -1)
38
38
  break;
39
- e(t.subarray(y, a), n), y = r, n = -1;
39
+ e(t.subarray(u, a), r), u = n, r = -1;
40
40
  }
41
- y === l ? t = void 0 : y !== 0 && (t = t.subarray(y), r -= y);
41
+ u === l ? t = void 0 : u !== 0 && (t = t.subarray(u), n -= u);
42
42
  };
43
43
  }
44
- function oe(e, t, r) {
45
- let n = F();
44
+ function oe(e, t, n) {
45
+ let r = O();
46
46
  const s = new TextDecoder();
47
47
  return function(o, l) {
48
48
  if (o.length === 0)
49
- r == null || r(n), n = F();
49
+ n == null || n(r), r = O();
50
50
  else if (l > 0) {
51
- const y = s.decode(o.subarray(0, l)), a = l + (o[l + 1] === 32 ? 2 : 1), c = s.decode(o.subarray(a));
52
- switch (y) {
51
+ const u = s.decode(o.subarray(0, l)), a = l + (o[l + 1] === 32 ? 2 : 1), c = s.decode(o.subarray(a));
52
+ switch (u) {
53
53
  case "data":
54
- n.data = n.data ? n.data + `
54
+ r.data = r.data ? r.data + `
55
55
  ` + c : c;
56
56
  break;
57
57
  case "event":
58
- n.event = c;
58
+ r.event = c;
59
59
  break;
60
60
  case "id":
61
- e(n.id = c);
61
+ e(r.id = c);
62
62
  break;
63
63
  case "retry":
64
- const m = parseInt(c, 10);
65
- isNaN(m) || t(n.retry = m);
64
+ const g = parseInt(c, 10);
65
+ isNaN(g) || t(r.retry = g);
66
66
  break;
67
67
  }
68
68
  }
69
69
  };
70
70
  }
71
71
  function ae(e, t) {
72
- const r = new Uint8Array(e.length + t.length);
73
- return r.set(e), r.set(t, e.length), r;
72
+ const n = new Uint8Array(e.length + t.length);
73
+ return n.set(e), n.set(t, e.length), n;
74
74
  }
75
- function F() {
75
+ function O() {
76
76
  return {
77
77
  data: "",
78
78
  event: "",
@@ -80,66 +80,66 @@ function F() {
80
80
  retry: void 0
81
81
  };
82
82
  }
83
- var se = 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]);
83
+ var ie = function(e, t) {
84
+ var n = {};
85
+ for (var r in e) Object.prototype.hasOwnProperty.call(e, r) && t.indexOf(r) < 0 && (n[r] = e[r]);
86
86
  if (e != null && typeof Object.getOwnPropertySymbols == "function")
87
- for (var s = 0, n = Object.getOwnPropertySymbols(e); s < n.length; s++)
88
- t.indexOf(n[s]) < 0 && Object.prototype.propertyIsEnumerable.call(e, n[s]) && (r[n[s]] = e[n[s]]);
89
- return r;
87
+ for (var s = 0, r = Object.getOwnPropertySymbols(e); s < r.length; s++)
88
+ t.indexOf(r[s]) < 0 && Object.prototype.propertyIsEnumerable.call(e, r[s]) && (n[r[s]] = e[r[s]]);
89
+ return n;
90
90
  };
91
- const R = "text/event-stream", ie = 1e3, B = "last-event-id";
91
+ const F = "text/event-stream", se = 1e3, L = "last-event-id";
92
92
  function le(e, t) {
93
- var { signal: r, headers: n, onopen: s, onmessage: d, onclose: o, onerror: l, openWhenHidden: y, fetch: a } = t, c = se(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
94
- return new Promise((m, u) => {
95
- const f = Object.assign({}, n);
96
- f.accept || (f.accept = R);
97
- let g;
98
- function h() {
99
- g.abort(), document.hidden || C();
93
+ var { signal: n, headers: r, onopen: s, onmessage: d, onclose: o, onerror: l, openWhenHidden: u, fetch: a } = t, c = ie(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
94
+ return new Promise((g, m) => {
95
+ const f = Object.assign({}, r);
96
+ f.accept || (f.accept = F);
97
+ let y;
98
+ function p() {
99
+ y.abort(), document.hidden || E();
100
100
  }
101
- y || document.addEventListener("visibilitychange", h);
102
- let p = ie, S = 0;
103
- function T() {
104
- document.removeEventListener("visibilitychange", h), window.clearTimeout(S), g.abort();
101
+ u || document.addEventListener("visibilitychange", p);
102
+ let h = se, S = 0;
103
+ function k() {
104
+ document.removeEventListener("visibilitychange", p), window.clearTimeout(S), y.abort();
105
105
  }
106
- r == null || r.addEventListener("abort", () => {
107
- T(), m();
106
+ n == null || n.addEventListener("abort", () => {
107
+ k(), g();
108
108
  });
109
- const P = a ?? window.fetch, I = s ?? ce;
110
- async function C() {
111
- var M;
112
- g = new AbortController();
109
+ const P = a ?? window.fetch, M = s ?? ce;
110
+ async function E() {
111
+ var D;
112
+ y = new AbortController();
113
113
  try {
114
- const A = await P(e, Object.assign(Object.assign({}, c), { headers: f, signal: g.signal }));
115
- await I(A), await re(A.body, ne(oe((b) => {
116
- b ? f[B] = b : delete f[B];
114
+ const I = await P(e, Object.assign(Object.assign({}, c), { headers: f, signal: y.signal }));
115
+ await M(I), await ne(I.body, re(oe((b) => {
116
+ b ? f[L] = b : delete f[L];
117
117
  }, (b) => {
118
- p = b;
119
- }, d))), o == null || o(), T(), m();
120
- } catch (A) {
121
- if (!g.signal.aborted)
118
+ h = b;
119
+ }, d))), o == null || o(), k(), g();
120
+ } catch (I) {
121
+ if (!y.signal.aborted)
122
122
  try {
123
- const b = (M = l == null ? void 0 : l(A)) !== null && M !== void 0 ? M : p;
124
- window.clearTimeout(S), S = window.setTimeout(C, b);
123
+ const b = (D = l == null ? void 0 : l(I)) !== null && D !== void 0 ? D : h;
124
+ window.clearTimeout(S), S = window.setTimeout(E, b);
125
125
  } catch (b) {
126
- T(), u(b);
126
+ k(), m(b);
127
127
  }
128
128
  }
129
129
  }
130
- C();
130
+ E();
131
131
  });
132
132
  }
133
133
  function ce(e) {
134
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}`);
135
+ if (!(t != null && t.startsWith(F)))
136
+ throw new Error(`Expected content-type to be ${F}, Actual: ${t}`);
137
137
  }
138
138
  function de(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);
139
+ const t = atob(e), n = new Uint8Array(t.length);
140
+ for (let r = 0; r < t.length; r++)
141
+ n[r] = t.charCodeAt(r);
142
+ return new TextDecoder("utf-8").decode(n);
143
143
  }
144
144
  class ue {
145
145
  constructor(t) {
@@ -150,25 +150,25 @@ class ue {
150
150
  * Creates new connections and removes old ones.
151
151
  */
152
152
  updateStreams(t) {
153
- t.forEach((n) => {
154
- const s = n.stream.id;
155
- this.eventSources.has(s) || this.connectStream(n);
153
+ t.forEach((r) => {
154
+ const s = r.stream.id;
155
+ this.eventSources.has(s) || this.connectStream(r);
156
156
  });
157
- const r = new Set(t.map((n) => n.stream.id));
158
- this.eventSources.forEach((n, s) => {
159
- r.has(s) || (n.abort(), this.eventSources.delete(s));
157
+ const n = new Set(t.map((r) => r.stream.id));
158
+ this.eventSources.forEach((r, s) => {
159
+ n.has(s) || (r.abort(), this.eventSources.delete(s));
160
160
  });
161
161
  }
162
162
  connectStream(t) {
163
- const r = t.stream.id, n = new AbortController();
164
- this.eventSources.set(r, n);
165
- const s = `${this.fency.baseUrl}/sse/streams/${r}`, d = {
163
+ const n = t.stream.id, r = new AbortController();
164
+ this.eventSources.set(n, r);
165
+ const s = `${this.fency.baseUrl}/sse/streams/${n}`, d = {
166
166
  "X-Fency-Publishable-Key": this.fency.publishableKey,
167
167
  "X-Fency-Stream-Token": t.stream.token
168
168
  };
169
169
  le(s, {
170
170
  headers: d,
171
- signal: n.signal,
171
+ signal: r.signal,
172
172
  async onopen(o) {
173
173
  if (!o.ok && o.status >= 400 && o.status < 500 && o.status !== 429)
174
174
  throw new Error(`Client error ${o.status}`);
@@ -176,11 +176,11 @@ class ue {
176
176
  onmessage: (o) => {
177
177
  if (o.data) {
178
178
  const l = de(o.data);
179
- this.broadcast(l, r);
179
+ this.broadcast(l, n);
180
180
  }
181
181
  },
182
182
  onerror: (o) => {
183
- throw console.error("EventSource error for stream", r, ":", o), this.broadcastError(r), o;
183
+ throw console.error("EventSource error for stream", n, ":", o), this.broadcastError(n), o;
184
184
  },
185
185
  onclose() {
186
186
  }
@@ -190,19 +190,19 @@ class ue {
190
190
  * Subscribe to events from all active streams.
191
191
  * Returns an unsubscribe function.
192
192
  */
193
- subscribe(t, r) {
194
- return this.subscribers.set(t, r), () => {
193
+ subscribe(t, n) {
194
+ return this.subscribers.set(t, n), () => {
195
195
  this.subscribers.delete(t);
196
196
  };
197
197
  }
198
- broadcast(t, r) {
199
- this.subscribers.forEach((n) => {
200
- n.onMessage(t, r);
198
+ broadcast(t, n) {
199
+ this.subscribers.forEach((r) => {
200
+ r.onMessage(t, n);
201
201
  });
202
202
  }
203
203
  broadcastError(t) {
204
- this.subscribers.forEach((r) => {
205
- r.onError(t);
204
+ this.subscribers.forEach((n) => {
205
+ n.onError(t);
206
206
  });
207
207
  }
208
208
  /**
@@ -214,77 +214,77 @@ class ue {
214
214
  }
215
215
  const me = 12e4, ge = (e) => {
216
216
  const t = Date.now();
217
- return e.filter((r) => t - r.createdAt < me);
217
+ return e.filter((n) => t - n.createdAt < me);
218
218
  };
219
- function We({ fency: e, fetchCreateStreamClientToken: t, children: r }) {
220
- const [n, s] = v(
219
+ function Ge({ fency: e, fetchCreateStreamClientToken: t, children: n }) {
220
+ const [r, s] = C(
221
221
  null
222
- ), [d, o] = v(!0), [l, y] = v(null), [a, c] = v([]), m = w(null), u = w(null);
223
- E(() => {
224
- e.then((p) => {
225
- s(p), o(!1);
226
- }).catch((p) => {
227
- y(p), o(!1);
222
+ ), [d, o] = C(!0), [l, u] = C(null), [a, c] = C([]), g = A(null), m = A(null);
223
+ w(() => {
224
+ e.then((h) => {
225
+ s(h), o(!1);
226
+ }).catch((h) => {
227
+ u(h), o(!1);
228
228
  });
229
- }, [e]), E(() => {
230
- n && !u.current && (u.current = new ue(n));
231
- }, [n]), E(() => {
232
- u.current && u.current.updateStreams(a);
233
- }, [a]), E(() => () => {
234
- var p;
235
- (p = u.current) == null || p.cleanup();
229
+ }, [e]), w(() => {
230
+ r && !m.current && (m.current = new ue(r));
231
+ }, [r]), w(() => {
232
+ m.current && m.current.updateStreams(a);
233
+ }, [a]), w(() => () => {
234
+ var h;
235
+ (h = m.current) == null || h.cleanup();
236
236
  }, []);
237
237
  const f = _(
238
- async (p = 3e4) => {
239
- if (m.current)
240
- return m.current;
241
- const S = Date.now(), T = a.length > 0 ? a[a.length - 1] : null;
242
- if (T && S - T.createdAt < p)
243
- return T.stream;
238
+ async (h = 3e4) => {
239
+ if (g.current)
240
+ return g.current;
241
+ const S = Date.now(), k = a.length > 0 ? a[a.length - 1] : null;
242
+ if (k && S - k.createdAt < h)
243
+ return k.stream;
244
244
  const P = (async () => {
245
- if (!n)
245
+ if (!r)
246
246
  throw new Error("Fency instance not initialized");
247
- const I = await t(), C = await G({
248
- pk: n.publishableKey,
249
- baseUrl: n.baseUrl,
250
- clientToken: (I == null ? void 0 : I.clientToken) ?? ""
247
+ const M = await t(), E = await G({
248
+ pk: r.publishableKey,
249
+ baseUrl: r.baseUrl,
250
+ clientToken: (M == null ? void 0 : M.clientToken) ?? ""
251
251
  });
252
- if (C.type === "success") {
253
- const M = {
254
- stream: C.stream,
252
+ if (E.type === "success") {
253
+ const D = {
254
+ stream: E.stream,
255
255
  createdAt: Date.now()
256
256
  };
257
- return c((A) => {
258
- const b = [...A, M];
257
+ return c((I) => {
258
+ const b = [...I, D];
259
259
  return ge(b);
260
- }), m.current = null, C.stream;
260
+ }), g.current = null, E.stream;
261
261
  } else
262
- throw m.current = null, new Error("Failed to create stream");
262
+ throw g.current = null, new Error("Failed to create stream");
263
263
  })();
264
- return m.current = P, P;
264
+ return g.current = P, P;
265
265
  },
266
- [n, a]
266
+ [r, a]
267
267
  );
268
268
  if (l)
269
- return /* @__PURE__ */ x("div", { children: [
269
+ return /* @__PURE__ */ v("div", { children: [
270
270
  "Fency error: ",
271
271
  l.message
272
272
  ] });
273
- if (!n)
273
+ if (!r)
274
274
  return null;
275
- const g = a.length > 0 ? a[a.length - 1] : null, h = {
276
- fency: n,
275
+ const y = a.length > 0 ? a[a.length - 1] : null, p = {
276
+ fency: r,
277
277
  loading: d,
278
278
  error: l,
279
279
  activeStreams: a,
280
- latestStream: g,
281
- eventManager: u.current,
280
+ latestStream: y,
281
+ eventManager: m.current,
282
282
  getOrCreateStream: f
283
283
  };
284
- return /* @__PURE__ */ i(W.Provider, { value: h, children: r });
284
+ return /* @__PURE__ */ i(H.Provider, { value: p, children: n });
285
285
  }
286
- function H() {
287
- const e = Q(W);
286
+ function N() {
287
+ const e = Q(H);
288
288
  if (e === void 0)
289
289
  throw new Error("useFencyContext must be used within a FencyProvider");
290
290
  return e;
@@ -296,11 +296,11 @@ const ye = (e) => {
296
296
  } catch (t) {
297
297
  return console.error("Error parsing message:", t), null;
298
298
  }
299
- }, fe = (e) => J(e) ? pe(e) : V(e) ? he(e) : X(e) ? Se(e) : null, pe = (e) => ({
299
+ }, fe = (e) => J(e) ? he(e) : V(e) ? pe(e) : X(e) ? Se(e) : null, he = (e) => ({
300
300
  type: "STREAM_TIMEOUT",
301
301
  streamId: e.streamId,
302
302
  timestamp: e.timestamp
303
- }), he = (e) => ({
303
+ }), pe = (e) => ({
304
304
  type: "STREAM_NOT_FOUND",
305
305
  streamId: e.streamId,
306
306
  timestamp: e.timestamp
@@ -312,31 +312,31 @@ const ye = (e) => {
312
312
  timestamp: e.timestamp,
313
313
  createdAt: e.createdAt,
314
314
  data: JSON.parse(e.data)
315
- }), Te = (e) => {
316
- const t = H(), [r, n] = v(null), s = w(`subscriber-${Math.random().toString(36).substr(2, 9)}`);
317
- return E(() => {
315
+ }), ke = (e) => {
316
+ const t = N(), [n, r] = C(null), s = A(`subscriber-${Math.random().toString(36).substr(2, 9)}`);
317
+ return w(() => {
318
318
  if (!t.eventManager) return;
319
319
  const o = {
320
- onMessage: (y, a) => {
321
- var m, u, f;
322
- const c = ye(y);
320
+ onMessage: (u, a) => {
321
+ var g, m, f;
322
+ const c = ye(u);
323
323
  if (c)
324
324
  switch (c.type) {
325
325
  case "STREAM_TIMEOUT":
326
- (m = e == null ? void 0 : e.onStreamTimeout) == null || m.call(e, c);
326
+ (g = e == null ? void 0 : e.onStreamTimeout) == null || g.call(e, c);
327
327
  break;
328
328
  case "STREAM_NOT_FOUND":
329
- (u = e == null ? void 0 : e.onStreamNotFound) == null || u.call(e, c);
329
+ (m = e == null ? void 0 : e.onStreamNotFound) == null || m.call(e, c);
330
330
  break;
331
331
  case "AGENT_TASK_PROGRESS_ITEM_UPDATED":
332
332
  (f = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || f.call(e, c);
333
333
  break;
334
334
  }
335
335
  },
336
- onError: (y) => {
336
+ onError: (u) => {
337
337
  var a;
338
338
  (a = e == null ? void 0 : e.onStreamError) == null || a.call(e, {
339
- streamId: y,
339
+ streamId: u,
340
340
  error: {
341
341
  code: "UnknownError",
342
342
  message: "Unknown error in useStream"
@@ -352,7 +352,7 @@ const ye = (e) => {
352
352
  createStream: async () => {
353
353
  try {
354
354
  const o = await t.getOrCreateStream(3e4);
355
- return n(o), {
355
+ return r(o), {
356
356
  type: "success",
357
357
  stream: o
358
358
  };
@@ -366,12 +366,12 @@ const ye = (e) => {
366
366
  };
367
367
  }
368
368
  },
369
- stream: r
369
+ stream: n
370
370
  };
371
- }, He = (e) => {
372
- const t = H(), [r, n] = v([]), s = w(/* @__PURE__ */ new Set()), d = w(/* @__PURE__ */ new Map()), { createStream: o } = Te({
371
+ }, Je = (e) => {
372
+ const t = N(), [n, r] = C([]), s = A(/* @__PURE__ */ new Set()), d = A(/* @__PURE__ */ new Map()), { createStream: o } = ke({
373
373
  onAgentTaskProgressItemUpdated: (a) => {
374
- var u;
374
+ var m;
375
375
  if (!s.current.has(a.agentTaskId)) return;
376
376
  const c = a.data;
377
377
  if (c.taskType === "StreamingChatCompletion" && c.eventType === "Completed" || c.taskType === "StructuredChatCompletion" && c.eventType === "Completed" || c.taskType === "MemoryChatCompletion" && c.eventType === "Completed") {
@@ -381,32 +381,32 @@ const ye = (e) => {
381
381
  f && (d.current.delete(a.agentTaskId), f(c));
382
382
  return;
383
383
  }
384
- (u = e.onAgentTaskProgressItemUpdated) == null || u.call(e, a), n(
385
- (f) => f.map((g) => {
384
+ (m = e.onAgentTaskProgressItemUpdated) == null || m.call(e, a), r(
385
+ (f) => f.map((y) => {
386
386
  var S;
387
- if (((S = g.confirmedData) == null ? void 0 : S.taskId) !== a.agentTaskId)
388
- return g;
389
- const p = g.progressItems.some(
390
- (T) => T.progressItemId === a.progressItemId
391
- ) ? g.progressItems.map(
392
- (T) => T.progressItemId === a.progressItemId ? a : T
393
- ) : [...g.progressItems, a];
394
- return { ...g, progressItems: p };
387
+ if (((S = y.confirmedData) == null ? void 0 : S.taskId) !== a.agentTaskId)
388
+ return y;
389
+ const h = y.progressItems.some(
390
+ (k) => k.progressItemId === a.progressItemId
391
+ ) ? y.progressItems.map(
392
+ (k) => k.progressItemId === a.progressItemId ? a : k
393
+ ) : [...y.progressItems, a];
394
+ return { ...y, progressItems: h };
395
395
  })
396
396
  );
397
397
  },
398
398
  onStreamError: (a) => {
399
399
  var c;
400
- (c = e == null ? void 0 : e.onStreamError) == null || c.call(e, a), n((m) => {
401
- const u = m.find((f) => f.streamId === a.streamId);
402
- return u ? [
403
- ...m.filter((f) => f.streamId !== a.streamId),
400
+ (c = e == null ? void 0 : e.onStreamError) == null || c.call(e, a), r((g) => {
401
+ const m = g.find((f) => f.streamId === a.streamId);
402
+ return m ? [
403
+ ...g.filter((f) => f.streamId !== a.streamId),
404
404
  {
405
- ...u,
405
+ ...m,
406
406
  loading: !1,
407
407
  error: a.error
408
408
  }
409
- ] : m;
409
+ ] : g;
410
410
  });
411
411
  },
412
412
  onStreamNotFound: (a) => {
@@ -419,13 +419,13 @@ const ye = (e) => {
419
419
  }
420
420
  }), l = _(
421
421
  async (a, c) => {
422
- const m = `task-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, u = await o();
423
- if (u.type === "success") {
424
- n([
425
- ...r,
422
+ const g = `task-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, m = await o();
423
+ if (m.type === "success") {
424
+ r([
425
+ ...n,
426
426
  {
427
- taskKey: m,
428
- streamId: u.stream.id,
427
+ taskKey: g,
428
+ streamId: m.stream.id,
429
429
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
430
430
  confirmedData: null,
431
431
  error: null,
@@ -435,11 +435,11 @@ const ye = (e) => {
435
435
  loadingText: c == null ? void 0 : c.loadingText
436
436
  }
437
437
  ]);
438
- const { clientToken: f } = await e.fetchCreateAgentTaskClientToken(a.type), g = await q({
438
+ const { clientToken: f } = await e.fetchCreateAgentTaskClientToken(a.type), y = await Y({
439
439
  pk: t.fency.publishableKey,
440
440
  baseUrl: t.fency.baseUrl,
441
441
  clientToken: f,
442
- streamToken: u.stream.token,
442
+ streamToken: m.stream.token,
443
443
  request: {
444
444
  streamingChatCompletionTask: a.type === "StreamingChatCompletion" ? {
445
445
  messages: a.messages,
@@ -459,50 +459,50 @@ const ye = (e) => {
459
459
  } : void 0
460
460
  }
461
461
  });
462
- if (g.type === "success" && g.agentTask) {
462
+ if (y.type === "success" && y.agentTask) {
463
463
  s.current.add(
464
- g.agentTask.id
465
- ), n((p) => [
466
- ...p.filter((S) => S.taskKey !== m),
464
+ y.agentTask.id
465
+ ), r((h) => [
466
+ ...h.filter((S) => S.taskKey !== g),
467
467
  {
468
- taskKey: m,
469
- streamId: u.stream.id,
468
+ taskKey: g,
469
+ streamId: m.stream.id,
470
470
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
471
- taskId: g.agentTask.id,
472
- createdAt: g.agentTask.createdAt,
471
+ taskId: y.agentTask.id,
472
+ createdAt: y.agentTask.createdAt,
473
473
  error: null,
474
474
  params: a,
475
475
  progressItems: [],
476
476
  loading: !0,
477
477
  loadingText: c == null ? void 0 : c.loadingText,
478
478
  confirmedData: {
479
- taskId: g.agentTask.id,
480
- createdAt: g.agentTask.createdAt
479
+ taskId: y.agentTask.id,
480
+ createdAt: y.agentTask.createdAt
481
481
  }
482
482
  }
483
483
  ]);
484
- const h = await new Promise((p) => {
484
+ const p = await new Promise((h) => {
485
485
  d.current.set(
486
- g.agentTask.id,
487
- p
486
+ y.agentTask.id,
487
+ h
488
488
  );
489
489
  });
490
490
  return {
491
491
  type: "success",
492
- streamId: u.stream.id,
493
- agentTaskId: g.agentTask.id,
494
- response: h
492
+ streamId: m.stream.id,
493
+ agentTaskId: y.agentTask.id,
494
+ response: p
495
495
  };
496
496
  } else {
497
- if (g.type === "error")
498
- return n((h) => [
499
- ...h.filter((p) => p.taskKey !== m),
497
+ if (y.type === "error")
498
+ return r((p) => [
499
+ ...p.filter((h) => h.taskKey !== g),
500
500
  {
501
- taskKey: m,
501
+ taskKey: g,
502
502
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
503
- streamId: u.stream.id,
503
+ streamId: m.stream.id,
504
504
  params: a,
505
- error: g.error,
505
+ error: y.error,
506
506
  progressItems: [],
507
507
  loading: !1,
508
508
  loadingText: c == null ? void 0 : c.loadingText,
@@ -510,20 +510,20 @@ const ye = (e) => {
510
510
  }
511
511
  ]), {
512
512
  type: "error",
513
- error: g.error
513
+ error: y.error
514
514
  };
515
515
  {
516
- const h = {
516
+ const p = {
517
517
  message: "No response received",
518
518
  code: "UnknownError"
519
519
  };
520
- return n((p) => [
521
- ...p.filter((S) => S.taskKey !== m),
520
+ return r((h) => [
521
+ ...h.filter((S) => S.taskKey !== g),
522
522
  {
523
- taskKey: m,
523
+ taskKey: g,
524
524
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
525
- streamId: u.stream.id,
526
- error: h,
525
+ streamId: m.stream.id,
526
+ error: p,
527
527
  params: a,
528
528
  progressItems: [],
529
529
  loading: !1,
@@ -532,60 +532,60 @@ const ye = (e) => {
532
532
  }
533
533
  ]), {
534
534
  type: "error",
535
- error: h
535
+ error: p
536
536
  };
537
537
  }
538
538
  }
539
539
  } else
540
- return console.error(u.error), u;
540
+ return console.error(m.error), m;
541
541
  },
542
- [t, r, o]
543
- ), y = z(() => {
544
- if (r.length !== 0)
545
- return [...r].sort((a, c) => new Date(c.triggeredAt).getTime() - new Date(a.triggeredAt).getTime())[0];
546
- }, [r]);
547
- return E(() => () => {
542
+ [t, n, o]
543
+ ), u = $(() => {
544
+ if (n.length !== 0)
545
+ return [...n].sort((a, c) => new Date(c.triggeredAt).getTime() - new Date(a.triggeredAt).getTime())[0];
546
+ }, [n]);
547
+ return w(() => () => {
548
548
  s.current.clear(), d.current.clear();
549
549
  }, []), {
550
- agentTasks: r,
550
+ agentTasks: n,
551
551
  createAgentTask: l,
552
- latest: y
552
+ latest: u
553
553
  };
554
554
  };
555
- function ke(e) {
556
- return e.progressItems.map((t, r) => {
557
- const n = e.progressItems[r + 1], s = n != null;
555
+ function Te(e) {
556
+ return e.progressItems.map((t, n) => {
557
+ const r = e.progressItems[n + 1], s = r != null;
558
558
  let d;
559
- if (n != null && n.createdAt) {
560
- const o = new Date(t.createdAt).getTime(), l = new Date(n.createdAt).getTime();
559
+ if (r != null && r.createdAt) {
560
+ const o = new Date(t.createdAt).getTime(), l = new Date(r.createdAt).getTime();
561
561
  d = Math.round((l - o) / 1e3);
562
562
  }
563
563
  return {
564
564
  item: t,
565
565
  completed: s,
566
- isLatest: r === e.progressItems.length - 1,
566
+ isLatest: n === e.progressItems.length - 1,
567
567
  durationSeconds: d
568
568
  };
569
569
  });
570
570
  }
571
- function O({
571
+ function R({
572
572
  text: e,
573
573
  duration: t = 2,
574
- delay: r = 0,
575
- repeat: n = !0,
574
+ delay: n = 0,
575
+ repeat: r = !0,
576
576
  repeatDelay: s = 0.5,
577
577
  className: d,
578
578
  startOnView: o = !1,
579
579
  once: l = !1,
580
- inViewMargin: y,
580
+ inViewMargin: u,
581
581
  spread: a = 2,
582
582
  color: c = "#999",
583
- shimmerColor: m = "#000",
584
- direction: u = "fromBottom"
583
+ shimmerColor: g = "#000",
584
+ direction: m = "fromBottom"
585
585
  }) {
586
- const f = w(null), g = Z(f, { once: l, margin: y }), h = z(() => e.length * a, [e, a]), p = !o || g, S = u === "fromBottom" ? "100% center" : "-100% center", T = u === "fromBottom" ? "0% center" : "200% center";
586
+ const f = A(null), y = Z(f, { once: l, margin: u }), p = $(() => e.length * a, [e, a]), h = !o || y, S = m === "fromBottom" ? "100% center" : "-100% center", k = m === "fromBottom" ? "0% center" : "200% center";
587
587
  return /* @__PURE__ */ i(
588
- k.span,
588
+ T.span,
589
589
  {
590
590
  ref: f,
591
591
  className: d,
@@ -598,9 +598,9 @@ function O({
598
598
  color: "transparent",
599
599
  WebkitTextFillColor: "transparent",
600
600
  backgroundRepeat: "no-repeat, padding-box",
601
- "--spread": `${h}px`,
601
+ "--spread": `${p}px`,
602
602
  "--base-color": c,
603
- "--shimmer-color": m,
603
+ "--shimmer-color": g,
604
604
  "--shimmer-bg": "linear-gradient(90deg, transparent calc(50% - var(--spread)), var(--shimmer-color), transparent calc(50% + var(--spread)))",
605
605
  backgroundImage: "var(--shimmer-bg), linear-gradient(var(--base-color), var(--base-color))"
606
606
  },
@@ -608,41 +608,41 @@ function O({
608
608
  backgroundPosition: S,
609
609
  opacity: 0
610
610
  },
611
- animate: p ? {
612
- backgroundPosition: T,
611
+ animate: h ? {
612
+ backgroundPosition: k,
613
613
  opacity: 1
614
614
  } : {},
615
615
  transition: {
616
616
  backgroundPosition: {
617
- repeat: n ? 1 / 0 : 0,
617
+ repeat: r ? 1 / 0 : 0,
618
618
  duration: t,
619
- delay: r,
619
+ delay: n,
620
620
  repeatDelay: s,
621
621
  ease: "linear"
622
622
  },
623
623
  opacity: {
624
624
  duration: 0.3,
625
- delay: r
625
+ delay: n
626
626
  }
627
627
  },
628
628
  children: e
629
629
  }
630
630
  );
631
631
  }
632
- function be(e, t) {
633
- const r = e.item.data;
634
- if (r.eventType === "Error" && "message" in r)
632
+ function ve(e, t) {
633
+ const n = e.item.data;
634
+ if (n.eventType === "Error" && "message" in n)
635
635
  return t.error;
636
- if (r.taskType === "StreamingChatCompletion") {
637
- if (r.eventType === "Text") return t.streaming;
638
- if (r.eventType === "Completed") return t.completed;
636
+ if (n.taskType === "StreamingChatCompletion") {
637
+ if (n.eventType === "Text") return t.streaming;
638
+ if (n.eventType === "Completed") return t.completed;
639
639
  }
640
- if (r.taskType === "StructuredChatCompletion") {
641
- if (r.eventType === "Json") return t.generating;
642
- if (r.eventType === "Completed") return t.completed;
640
+ if (n.taskType === "StructuredChatCompletion") {
641
+ if (n.eventType === "Json") return t.generating;
642
+ if (n.eventType === "Completed") return t.completed;
643
643
  }
644
- if (r.taskType === "MemoryChatCompletion")
645
- switch (r.eventType) {
644
+ if (n.taskType === "MemoryChatCompletion")
645
+ switch (n.eventType) {
646
646
  case "Text":
647
647
  return t.streaming;
648
648
  case "Search":
@@ -657,33 +657,35 @@ function be(e, t) {
657
657
  return t.memoryExplored;
658
658
  case "ExploreMemoryError":
659
659
  return t.memoryExplorationFailed;
660
+ case "ChunkResult":
661
+ return t.chunksRetrieved;
660
662
  case "Completed":
661
663
  return t.completed;
662
664
  }
663
665
  return t.processing;
664
666
  }
665
- const ve = ({ progressViewItems: e, t }) => {
666
- const r = e[e.length - 1];
667
- if (!r) return null;
668
- const n = be(r, t);
669
- return /* @__PURE__ */ i("div", { className: "simple-mode-container", children: /* @__PURE__ */ i($, { mode: "wait", children: /* @__PURE__ */ i(
670
- k.div,
667
+ const be = ({ progressViewItems: e, t }) => {
668
+ const n = e[e.length - 1];
669
+ if (!n) return null;
670
+ const r = ve(n, t);
671
+ return /* @__PURE__ */ i("div", { className: "simple-mode-container", children: /* @__PURE__ */ i(W, { mode: "wait", children: /* @__PURE__ */ i(
672
+ T.div,
671
673
  {
672
674
  initial: { opacity: 0, y: 10 },
673
675
  animate: { opacity: 1, y: 0 },
674
676
  exit: { opacity: 0, y: -10 },
675
677
  transition: { duration: 0.3 },
676
- children: r.completed ? /* @__PURE__ */ i(
678
+ children: n.completed ? /* @__PURE__ */ i(
677
679
  "div",
678
680
  {
679
681
  className: "simple-mode-title",
680
682
  style: { color: "#666" },
681
- children: n
683
+ children: r
682
684
  }
683
685
  ) : /* @__PURE__ */ i(
684
- O,
686
+ R,
685
687
  {
686
- text: n,
688
+ text: r,
687
689
  className: "simple-mode-title",
688
690
  duration: 2.5,
689
691
  repeat: !0,
@@ -692,7 +694,7 @@ const ve = ({ progressViewItems: e, t }) => {
692
694
  }
693
695
  )
694
696
  },
695
- r.item.progressItemId
697
+ n.item.progressItemId
696
698
  ) }) });
697
699
  }, K = {
698
700
  'code[class*="language-"]': {
@@ -845,10 +847,10 @@ const ve = ({ progressViewItems: e, t }) => {
845
847
  italic: {
846
848
  fontStyle: "italic"
847
849
  }
848
- }, L = ({
850
+ }, B = ({
849
851
  text: e
850
852
  }) => /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ i(
851
- k.div,
853
+ T.div,
852
854
  {
853
855
  className: "fency-markdown-body-raw",
854
856
  initial: { opacity: 0, y: -10 },
@@ -860,7 +862,7 @@ const ve = ({ progressViewItems: e, t }) => {
860
862
  remarkPlugins: [te],
861
863
  components: {
862
864
  code(t) {
863
- const { children: r, className: n, node: s, ref: d, ...o } = t, l = /language-(\w+)/.exec(n || "");
865
+ const { children: n, className: r, node: s, ref: d, ...o } = t, l = /language-(\w+)/.exec(r || "");
864
866
  return l ? (
865
867
  // @ts-expect-error react-syntax-highlighter types incompatible with @types/react 18
866
868
  /* @__PURE__ */ i(
@@ -868,12 +870,12 @@ const ve = ({ progressViewItems: e, t }) => {
868
870
  {
869
871
  ...o,
870
872
  PreTag: "div",
871
- children: String(r).replace(/\n$/, ""),
873
+ children: String(n).replace(/\n$/, ""),
872
874
  language: l[1],
873
875
  style: K
874
876
  }
875
877
  )
876
- ) : /* @__PURE__ */ i("code", { ...o, className: n, children: String(r) });
878
+ ) : /* @__PURE__ */ i("code", { ...o, className: r, children: String(n) });
877
879
  }
878
880
  },
879
881
  children: e
@@ -883,7 +885,7 @@ const ve = ({ progressViewItems: e, t }) => {
883
885
  ) }), xe = ({ data: e }) => {
884
886
  const t = JSON.stringify(e.json, null, 2);
885
887
  return /* @__PURE__ */ i("div", { id: "structured-chat-completion-response", children: /* @__PURE__ */ i(
886
- k.div,
888
+ T.div,
887
889
  {
888
890
  initial: { opacity: 0, y: -10 },
889
891
  animate: { opacity: 1, y: 0 },
@@ -913,7 +915,11 @@ const ve = ({ progressViewItems: e, t }) => {
913
915
  pageTwo: "pages {a} and {b}",
914
916
  pageMultiple: "pages {list} and {n}",
915
917
  clickToCollapse: "Click to collapse",
916
- clickToExpand: "Click to expand"
918
+ clickToExpand: "Click to expand",
919
+ chunkFound: "1 chunk found",
920
+ chunksFound: "{n} chunks found",
921
+ chunksRetrieved: "Chunks retrieved",
922
+ scoreLabel: "score: {n}"
917
923
  },
918
924
  no: {
919
925
  error: "Feil",
@@ -936,23 +942,27 @@ const ve = ({ progressViewItems: e, t }) => {
936
942
  pageTwo: "side {a} og {b}",
937
943
  pageMultiple: "side {list} og {n}",
938
944
  clickToCollapse: "Klikk for å skjule",
939
- clickToExpand: "Klikk for å utvide"
945
+ clickToExpand: "Klikk for å utvide",
946
+ chunkFound: "1 del funnet",
947
+ chunksFound: "{n} deler funnet",
948
+ chunksRetrieved: "Deler hentet",
949
+ scoreLabel: "poeng: {n}"
940
950
  }
941
951
  };
942
952
  function Ee(e) {
943
953
  return Ce[e];
944
954
  }
945
- function D(e, t) {
955
+ function x(e, t) {
946
956
  return Object.entries(t).reduce(
947
- (r, [n, s]) => r.replace(`{${n}}`, String(s)),
957
+ (n, [r, s]) => n.replace(`{${r}}`, String(s)),
948
958
  e
949
959
  );
950
960
  }
951
- const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
952
- const s = `${n.searchingPrefix}${e.queryDescription}`;
953
- return /* @__PURE__ */ x("div", { style: { padding: "16px" }, children: [
961
+ const we = ({ data: e, isLatest: t = !1, durationSeconds: n, t: r }) => {
962
+ const s = `${r.searchingPrefix}${e.queryDescription}`;
963
+ return /* @__PURE__ */ v("div", { style: { padding: "16px" }, children: [
954
964
  /* @__PURE__ */ i(
955
- k.div,
965
+ T.div,
956
966
  {
957
967
  style: {
958
968
  display: "flex",
@@ -963,8 +973,8 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
963
973
  initial: { opacity: 0, y: -10 },
964
974
  animate: { opacity: 1, y: 0 },
965
975
  transition: { duration: 0.3, delay: 0 },
966
- children: t && !r ? /* @__PURE__ */ i(
967
- O,
976
+ children: t && !n ? /* @__PURE__ */ i(
977
+ R,
968
978
  {
969
979
  text: s,
970
980
  duration: 2.5,
@@ -975,7 +985,7 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
975
985
  ) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: s })
976
986
  }
977
987
  ),
978
- r !== void 0 && /* @__PURE__ */ i(
988
+ n !== void 0 && /* @__PURE__ */ i(
979
989
  "div",
980
990
  {
981
991
  style: {
@@ -984,15 +994,15 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
984
994
  marginTop: "4px",
985
995
  fontStyle: "italic"
986
996
  },
987
- children: D(n.tookSeconds, { n: r })
997
+ children: x(r.tookSeconds, { n })
988
998
  }
989
999
  )
990
1000
  ] });
991
- }, Ae = ({ isLatest: e = !1, durationSeconds: t, t: r }) => {
992
- const n = r.addingSources;
993
- return /* @__PURE__ */ x("div", { style: { padding: "16px" }, children: [
1001
+ }, Ae = ({ isLatest: e = !1, durationSeconds: t, t: n }) => {
1002
+ const r = n.addingSources;
1003
+ return /* @__PURE__ */ v("div", { style: { padding: "16px" }, children: [
994
1004
  /* @__PURE__ */ i(
995
- k.div,
1005
+ T.div,
996
1006
  {
997
1007
  style: {
998
1008
  display: "flex",
@@ -1004,15 +1014,15 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
1004
1014
  animate: { opacity: 1, y: 0 },
1005
1015
  transition: { duration: 0.3, delay: 0 },
1006
1016
  children: e && !t ? /* @__PURE__ */ i(
1007
- O,
1017
+ R,
1008
1018
  {
1009
- text: n,
1019
+ text: r,
1010
1020
  duration: 2.5,
1011
1021
  repeat: !0,
1012
1022
  color: "#999",
1013
1023
  shimmerColor: "#000"
1014
1024
  }
1015
- ) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: n })
1025
+ ) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: r })
1016
1026
  }
1017
1027
  ),
1018
1028
  t !== void 0 && /* @__PURE__ */ i(
@@ -1024,7 +1034,7 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
1024
1034
  marginTop: "4px",
1025
1035
  fontStyle: "italic"
1026
1036
  },
1027
- children: D(r.tookSeconds, { n: t })
1037
+ children: x(n.tookSeconds, { n: t })
1028
1038
  }
1029
1039
  )
1030
1040
  ] });
@@ -1032,18 +1042,18 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
1032
1042
  function Ie(e, t) {
1033
1043
  if (e.length === 0) return "";
1034
1044
  if (e.length === 1)
1035
- return D(t.pageSingle, { n: e[0] });
1045
+ return x(t.pageSingle, { n: e[0] });
1036
1046
  if (e.length === 2)
1037
- return D(t.pageTwo, {
1047
+ return x(t.pageTwo, {
1038
1048
  a: e[0],
1039
1049
  b: e[1]
1040
1050
  });
1041
- const r = e[e.length - 1], n = e.slice(0, -1).join(", ");
1042
- return D(t.pageMultiple, { list: n, n: r });
1051
+ const n = e[e.length - 1], r = e.slice(0, -1).join(", ");
1052
+ return x(t.pageMultiple, { list: r, n });
1043
1053
  }
1044
- const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { style: { padding: "16px" }, children: [
1054
+ const Me = ({ data: e, onSourceClick: t, t: n }) => /* @__PURE__ */ v("div", { style: { padding: "16px" }, children: [
1045
1055
  /* @__PURE__ */ i(
1046
- k.div,
1056
+ T.div,
1047
1057
  {
1048
1058
  style: {
1049
1059
  marginBottom: "10px",
@@ -1056,33 +1066,33 @@ const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { s
1056
1066
  initial: { opacity: 0, y: -10 },
1057
1067
  animate: { opacity: 1, y: 0 },
1058
1068
  transition: { duration: 0.3, delay: 0 },
1059
- children: r.sources
1069
+ children: n.sources
1060
1070
  }
1061
1071
  ),
1062
- /* @__PURE__ */ i("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: e.sources.length === 0 ? /* @__PURE__ */ i("span", { style: { fontSize: "13px", color: "#888" }, children: r.noSources }) : e.sources.map((n, s) => /* @__PURE__ */ i(
1072
+ /* @__PURE__ */ i("div", { style: { display: "flex", flexWrap: "wrap", gap: "8px" }, children: e.sources.length === 0 ? /* @__PURE__ */ i("span", { style: { fontSize: "13px", color: "#888" }, children: n.noSources }) : e.sources.map((r, s) => /* @__PURE__ */ i(
1063
1073
  De,
1064
1074
  {
1065
- source: n,
1075
+ source: r,
1066
1076
  index: s,
1067
1077
  onSourceClick: t,
1068
- t: r
1078
+ t: n
1069
1079
  },
1070
- n.memoryId
1080
+ r.memoryId
1071
1081
  )) })
1072
1082
  ] }), De = ({
1073
1083
  source: e,
1074
1084
  index: t,
1075
- onSourceClick: r,
1076
- t: n
1085
+ onSourceClick: n,
1086
+ t: r
1077
1087
  }) => {
1078
- const [s, d] = v(!1), o = !!r, l = e.pageNumbers ?? [], y = Ie(l, n);
1079
- return /* @__PURE__ */ x(
1080
- k.div,
1088
+ const [s, d] = C(!1), o = !!n, l = e.pageNumbers ?? [], u = Ie(l, r);
1089
+ return /* @__PURE__ */ v(
1090
+ T.div,
1081
1091
  {
1082
1092
  initial: { opacity: 0, scale: 0.9 },
1083
1093
  animate: { opacity: 1, scale: 1 },
1084
1094
  transition: { duration: 0.25, delay: t * 0.05 },
1085
- onClick: o ? () => r(e.memoryId) : void 0,
1095
+ onClick: o ? () => n(e.memoryId) : void 0,
1086
1096
  onMouseEnter: o ? () => d(!0) : void 0,
1087
1097
  onMouseLeave: o ? () => d(!1) : void 0,
1088
1098
  style: {
@@ -1099,16 +1109,16 @@ const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { s
1099
1109
  },
1100
1110
  children: [
1101
1111
  /* @__PURE__ */ i("span", { style: { fontSize: "13px", fontWeight: 500, color: "#333" }, children: e.memoryTitle }),
1102
- y && /* @__PURE__ */ i("span", { style: { fontSize: "12px", color: "#666" }, children: y })
1112
+ u && /* @__PURE__ */ i("span", { style: { fontSize: "12px", color: "#666" }, children: u })
1103
1113
  ]
1104
1114
  }
1105
1115
  );
1106
1116
  }, U = ({
1107
1117
  color: e = "#78b13f",
1108
1118
  size: t = 24,
1109
- borderWidth: r = 7
1119
+ borderWidth: n = 7
1110
1120
  }) => {
1111
- const n = t * 0.5;
1121
+ const r = t * 0.5;
1112
1122
  return /* @__PURE__ */ i(
1113
1123
  "span",
1114
1124
  {
@@ -1116,26 +1126,26 @@ const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { s
1116
1126
  display: "inline-block",
1117
1127
  transform: "rotate(45deg)",
1118
1128
  height: t,
1119
- width: n,
1120
- borderBottom: `${r}px solid ${e}`,
1121
- borderRight: `${r}px solid ${e}`
1129
+ width: r,
1130
+ borderBottom: `${n}px solid ${e}`,
1131
+ borderRight: `${n}px solid ${e}`
1122
1132
  }
1123
1133
  }
1124
1134
  );
1125
1135
  }, Pe = ({
1126
1136
  color: e = "#333",
1127
1137
  size: t = 32,
1128
- lineWidth: r = 2
1138
+ lineWidth: n = 2
1129
1139
  }) => {
1130
- const n = t + 1, s = (t - r) / 2, d = (t - n) / 2, o = {
1140
+ const r = t + 1, s = (t - n) / 2, d = (t - r) / 2, o = {
1131
1141
  position: "absolute",
1132
1142
  left: s,
1133
1143
  top: d,
1134
- width: r,
1135
- height: n,
1144
+ width: n,
1145
+ height: r,
1136
1146
  backgroundColor: e
1137
1147
  };
1138
- return /* @__PURE__ */ x(
1148
+ return /* @__PURE__ */ v(
1139
1149
  "span",
1140
1150
  {
1141
1151
  style: {
@@ -1167,16 +1177,16 @@ const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { s
1167
1177
  }
1168
1178
  );
1169
1179
  };
1170
- function Oe({
1180
+ function Re({
1171
1181
  eventType: e,
1172
1182
  completed: t
1173
1183
  }) {
1174
1184
  return e === "ExploreMemoryError" ? /* @__PURE__ */ i(Pe, { color: "#c62828", size: 15, lineWidth: 2 }) : e === "ExploreMemoryResult" ? /* @__PURE__ */ i(U, { color: "#999", size: 15, borderWidth: 2 }) : e === "ExploreMemoryStart" ? t ? /* @__PURE__ */ i(U, { color: "#999", size: 15, borderWidth: 2 }) : /* @__PURE__ */ i("span", { className: "explore-memory-loader" }) : null;
1175
1185
  }
1176
- const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1177
- const [s, d] = v(!1), o = e.eventType === "ExploreMemoryResult" ? e.result : void 0, l = o != null && o.length > N, y = o != null ? s || !l ? o : `${o.slice(0, N)}...` : void 0, a = l;
1178
- return /* @__PURE__ */ i("div", { style: { padding: "10px" }, children: /* @__PURE__ */ x(
1179
- k.div,
1186
+ const z = 80, Fe = ({ data: e, completed: t, isLatest: n = !1, t: r }) => {
1187
+ const [s, d] = C(!1), o = e.eventType === "ExploreMemoryResult" ? e.result : void 0, l = o != null && o.length > z, u = o != null ? s || !l ? o : `${o.slice(0, z)}...` : void 0, a = l;
1188
+ return /* @__PURE__ */ i("div", { style: { padding: "10px" }, children: /* @__PURE__ */ v(
1189
+ T.div,
1180
1190
  {
1181
1191
  initial: { opacity: 0 },
1182
1192
  animate: { opacity: 1 },
@@ -1204,7 +1214,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1204
1214
  width: 32
1205
1215
  },
1206
1216
  children: /* @__PURE__ */ i(
1207
- Oe,
1217
+ Re,
1208
1218
  {
1209
1219
  eventType: e.eventType,
1210
1220
  completed: t
@@ -1212,7 +1222,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1212
1222
  )
1213
1223
  }
1214
1224
  ),
1215
- /* @__PURE__ */ x(
1225
+ /* @__PURE__ */ v(
1216
1226
  "div",
1217
1227
  {
1218
1228
  style: {
@@ -1229,7 +1239,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1229
1239
  children: e.memoryTitle
1230
1240
  }
1231
1241
  ),
1232
- y != null && /* @__PURE__ */ i(
1242
+ u != null && /* @__PURE__ */ i(
1233
1243
  "span",
1234
1244
  {
1235
1245
  style: {
@@ -1238,7 +1248,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1238
1248
  lineHeight: 1.4,
1239
1249
  whiteSpace: s ? "pre-wrap" : void 0
1240
1250
  },
1241
- children: y
1251
+ children: u
1242
1252
  }
1243
1253
  ),
1244
1254
  a && /* @__PURE__ */ i(
@@ -1249,7 +1259,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1249
1259
  color: "#999",
1250
1260
  marginTop: 2
1251
1261
  },
1252
- children: s ? n.clickToCollapse : n.clickToExpand
1262
+ children: s ? r.clickToCollapse : r.clickToExpand
1253
1263
  }
1254
1264
  )
1255
1265
  ]
@@ -1258,8 +1268,124 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1258
1268
  ]
1259
1269
  }
1260
1270
  ) });
1261
- }, Fe = ({ message: e }) => /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ i(
1262
- k.div,
1271
+ };
1272
+ function Oe(e, t) {
1273
+ if (e.length === 0) return "";
1274
+ if (e.length === 1)
1275
+ return x(t.pageSingle, { n: e[0] });
1276
+ if (e.length === 2)
1277
+ return x(t.pageTwo, {
1278
+ a: e[0],
1279
+ b: e[1]
1280
+ });
1281
+ const n = e[e.length - 1], r = e.slice(0, -1).join(", ");
1282
+ return x(t.pageMultiple, { list: r, n });
1283
+ }
1284
+ function Le(e, t) {
1285
+ return e === 1 ? t.chunkFound : x(t.chunksFound, { n: e });
1286
+ }
1287
+ const Be = ({ data: e, t }) => {
1288
+ const [n, r] = C(!1), s = e.chunks.length, d = s > 0;
1289
+ return /* @__PURE__ */ v("div", { style: { padding: "10px" }, children: [
1290
+ /* @__PURE__ */ v(
1291
+ T.div,
1292
+ {
1293
+ initial: { opacity: 0 },
1294
+ animate: { opacity: 1 },
1295
+ transition: { duration: 0.25 },
1296
+ onClick: d ? () => r((o) => !o) : void 0,
1297
+ style: {
1298
+ paddingBottom: n ? "12px" : 0,
1299
+ borderBottom: n ? "1px solid #eee" : void 0,
1300
+ display: "flex",
1301
+ flexDirection: "column",
1302
+ gap: "4px",
1303
+ minWidth: 0,
1304
+ cursor: d ? "pointer" : "default"
1305
+ },
1306
+ children: [
1307
+ /* @__PURE__ */ i("span", { style: { fontSize: 13, fontWeight: 500, color: "#333" }, children: e.memoryTitle }),
1308
+ /* @__PURE__ */ i("span", { style: { fontSize: 12, color: "#666" }, children: Le(s, t) }),
1309
+ d && /* @__PURE__ */ i(
1310
+ "span",
1311
+ {
1312
+ style: {
1313
+ fontSize: 11,
1314
+ color: "#999",
1315
+ marginTop: 2
1316
+ },
1317
+ children: n ? t.clickToCollapse : t.clickToExpand
1318
+ }
1319
+ )
1320
+ ]
1321
+ }
1322
+ ),
1323
+ n && d && /* @__PURE__ */ i(
1324
+ T.div,
1325
+ {
1326
+ initial: { opacity: 0, height: 0 },
1327
+ animate: { opacity: 1, height: "auto" },
1328
+ transition: { duration: 0.2 },
1329
+ style: {
1330
+ maxHeight: 220,
1331
+ overflowY: "auto",
1332
+ marginTop: 12,
1333
+ display: "flex",
1334
+ flexDirection: "column",
1335
+ gap: 8
1336
+ },
1337
+ children: e.chunks.map((o, l) => {
1338
+ const u = o.pageNumbers ?? [], a = Oe(u, t);
1339
+ return /* @__PURE__ */ v(
1340
+ "div",
1341
+ {
1342
+ style: {
1343
+ padding: "8px 12px",
1344
+ borderRadius: 6,
1345
+ border: "1px solid #e0e0e0",
1346
+ backgroundColor: "#fafafa"
1347
+ },
1348
+ children: [
1349
+ /* @__PURE__ */ i(
1350
+ "span",
1351
+ {
1352
+ style: {
1353
+ fontSize: 12,
1354
+ color: "#333",
1355
+ lineHeight: 1.4,
1356
+ display: "block",
1357
+ marginBottom: 4
1358
+ },
1359
+ children: o.content
1360
+ }
1361
+ ),
1362
+ /* @__PURE__ */ v(
1363
+ "div",
1364
+ {
1365
+ style: {
1366
+ display: "flex",
1367
+ gap: 8,
1368
+ fontSize: 11,
1369
+ color: "#666"
1370
+ },
1371
+ children: [
1372
+ a && /* @__PURE__ */ i("span", { children: a }),
1373
+ /* @__PURE__ */ i("span", { children: x(t.scoreLabel, {
1374
+ n: o.score
1375
+ }) })
1376
+ ]
1377
+ }
1378
+ )
1379
+ ]
1380
+ },
1381
+ l
1382
+ );
1383
+ })
1384
+ }
1385
+ )
1386
+ ] });
1387
+ }, Ue = ({ message: e }) => /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ i(
1388
+ T.div,
1263
1389
  {
1264
1390
  initial: { opacity: 0, y: -10 },
1265
1391
  animate: { opacity: 1, y: 0 },
@@ -1281,26 +1407,26 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1281
1407
  }
1282
1408
  )
1283
1409
  }
1284
- ) }), Be = ({
1410
+ ) }), ze = ({
1285
1411
  progressViewItems: e,
1286
1412
  loadingText: t,
1287
- t: r,
1288
- onSourceClick: n
1413
+ t: n,
1414
+ onSourceClick: r
1289
1415
  }) => {
1290
- const s = w(null);
1291
- E(() => {
1416
+ const s = A(null);
1417
+ w(() => {
1292
1418
  s.current && (s.current.scrollTop = s.current.scrollHeight);
1293
1419
  }, [e.length]);
1294
1420
  const d = (o) => {
1295
1421
  const l = o.item.data;
1296
1422
  if (l.taskType === "StreamingChatCompletion" && l.eventType === "Text")
1297
- return /* @__PURE__ */ i(L, { text: l.text });
1423
+ return /* @__PURE__ */ i(B, { text: l.text });
1298
1424
  if (l.taskType === "StructuredChatCompletion" && l.eventType === "Json")
1299
1425
  return /* @__PURE__ */ i(xe, { data: l });
1300
1426
  if (l.taskType === "MemoryChatCompletion")
1301
1427
  switch (l.eventType) {
1302
1428
  case "Text":
1303
- return /* @__PURE__ */ i(L, { text: l.text });
1429
+ return /* @__PURE__ */ i(B, { text: l.text });
1304
1430
  case "Search":
1305
1431
  return /* @__PURE__ */ i(
1306
1432
  we,
@@ -1308,7 +1434,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1308
1434
  data: l,
1309
1435
  isLatest: o.isLatest,
1310
1436
  durationSeconds: o.durationSeconds,
1311
- t: r
1437
+ t: n
1312
1438
  }
1313
1439
  );
1314
1440
  case "FindSources":
@@ -1318,7 +1444,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1318
1444
  data: l,
1319
1445
  isLatest: o.isLatest,
1320
1446
  durationSeconds: o.durationSeconds,
1321
- t: r
1447
+ t: n
1322
1448
  }
1323
1449
  );
1324
1450
  case "SourcesResult":
@@ -1326,39 +1452,41 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1326
1452
  Me,
1327
1453
  {
1328
1454
  data: l,
1329
- onSourceClick: n,
1330
- t: r
1455
+ onSourceClick: r,
1456
+ t: n
1331
1457
  }
1332
1458
  );
1333
1459
  case "ExploreMemoryStart":
1334
1460
  case "ExploreMemoryResult":
1335
1461
  case "ExploreMemoryError":
1336
1462
  return /* @__PURE__ */ i(
1337
- Re,
1463
+ Fe,
1338
1464
  {
1339
1465
  data: l,
1340
1466
  completed: o.completed,
1341
1467
  isLatest: o.isLatest,
1342
- t: r
1468
+ t: n
1343
1469
  }
1344
1470
  );
1471
+ case "ChunkResult":
1472
+ return /* @__PURE__ */ i(Be, { data: l, t: n });
1345
1473
  case "Completed":
1346
1474
  return null;
1347
1475
  }
1348
- return l.taskType === "StreamingChatCompletion" && l.eventType === "Completed" || l.taskType === "StructuredChatCompletion" && l.eventType === "Completed" ? null : l.eventType === "Error" && "message" in l ? /* @__PURE__ */ i(Fe, { message: l.message }) : null;
1476
+ return l.taskType === "StreamingChatCompletion" && l.eventType === "Completed" || l.taskType === "StructuredChatCompletion" && l.eventType === "Completed" ? null : l.eventType === "Error" && "message" in l ? /* @__PURE__ */ i(Ue, { message: l.message }) : null;
1349
1477
  };
1350
1478
  return e.length === 0 ? /* @__PURE__ */ i("div", { style: { width: "fit-content" }, children: /* @__PURE__ */ i(
1351
- O,
1479
+ R,
1352
1480
  {
1353
- text: t ?? r.processingYourTask,
1481
+ text: t ?? n.processingYourTask,
1354
1482
  duration: 1.5,
1355
1483
  repeat: !0,
1356
1484
  repeatDelay: 0,
1357
1485
  color: "#999",
1358
1486
  shimmerColor: "#000"
1359
1487
  }
1360
- ) }) : /* @__PURE__ */ i("div", { id: "agent-task-progress-verbose", ref: s, children: /* @__PURE__ */ i($, { children: e.map((o, l) => /* @__PURE__ */ i(
1361
- k.div,
1488
+ ) }) : /* @__PURE__ */ i("div", { id: "agent-task-progress-verbose", ref: s, children: /* @__PURE__ */ i(W, { children: e.map((o, l) => /* @__PURE__ */ i(
1489
+ T.div,
1362
1490
  {
1363
1491
  id: `agent-task-progress-item-${o.item.progressItemId}`,
1364
1492
  initial: { opacity: 0, y: -20 },
@@ -1372,33 +1500,33 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1372
1500
  },
1373
1501
  o.item.progressItemId
1374
1502
  )) }) });
1375
- }, Ke = ({
1503
+ }, Ve = ({
1376
1504
  agentTask: e,
1377
1505
  mode: t = "verbose",
1378
- language: r,
1379
- onSourceClick: n
1506
+ language: n,
1507
+ onSourceClick: r
1380
1508
  }) => {
1381
- const s = ke(e), d = e.params.type === "MemoryChatCompletion" && "language" in e.params ? e.params.language ?? "en" : r ?? "en", o = Ee(d);
1509
+ const s = Te(e), d = e.params.type === "MemoryChatCompletion" && "language" in e.params ? e.params.language ?? "en" : n ?? "en", o = Ee(d);
1382
1510
  return t === "simple" ? /* @__PURE__ */ i(
1383
- ve,
1511
+ be,
1384
1512
  {
1385
1513
  progressViewItems: s,
1386
1514
  t: o
1387
1515
  }
1388
1516
  ) : /* @__PURE__ */ i(
1389
- Be,
1517
+ ze,
1390
1518
  {
1391
1519
  progressViewItems: s,
1392
1520
  loadingText: e.loadingText,
1393
1521
  t: o,
1394
- onSourceClick: n
1522
+ onSourceClick: r
1395
1523
  }
1396
1524
  );
1397
1525
  };
1398
1526
  export {
1399
- Ke as AgentTaskProgress,
1527
+ Ve as AgentTaskProgress,
1400
1528
  U as Checkmark,
1401
- We as FencyProvider,
1529
+ Ge as FencyProvider,
1402
1530
  Pe as XMark,
1403
- He as useAgentTasks
1531
+ Je as useAgentTasks
1404
1532
  };