@fencyai/react 0.1.138 → 0.1.140

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 m = 0;
23
+ for (; n < l; ) {
24
+ s && (t[n] === 10 && (m = ++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 - m);
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(m, a), r), m = n, r = -1;
40
40
  }
41
- y === l ? t = void 0 : y !== 0 && (t = t.subarray(y), r -= y);
41
+ m === l ? t = void 0 : m !== 0 && (t = t.subarray(m), n -= m);
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 m = s.decode(o.subarray(0, l)), a = l + (o[l + 1] === 32 ? 2 : 1), c = s.decode(o.subarray(a));
52
+ switch (m) {
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 y = parseInt(c, 10);
65
+ isNaN(y) || t(r.retry = y);
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: m, fetch: a } = t, c = ie(t, ["signal", "headers", "onopen", "onmessage", "onclose", "onerror", "openWhenHidden", "fetch"]);
94
+ return new Promise((y, g) => {
95
+ const h = Object.assign({}, r);
96
+ h.accept || (h.accept = F);
97
+ let u;
98
+ function p() {
99
+ u.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
+ m || document.addEventListener("visibilitychange", p);
102
+ let f = se, S = 0;
103
+ function k() {
104
+ document.removeEventListener("visibilitychange", p), window.clearTimeout(S), u.abort();
105
105
  }
106
- r == null || r.addEventListener("abort", () => {
107
- T(), m();
106
+ n == null || n.addEventListener("abort", () => {
107
+ k(), y();
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
+ u = 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: h, signal: u.signal }));
115
+ await M(I), await ne(I.body, re(oe((b) => {
116
+ b ? h[L] = b : delete h[L];
117
117
  }, (b) => {
118
- p = b;
119
- }, d))), o == null || o(), T(), m();
120
- } catch (A) {
121
- if (!g.signal.aborted)
118
+ f = b;
119
+ }, d))), o == null || o(), k(), y();
120
+ } catch (I) {
121
+ if (!u.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 : f;
124
+ window.clearTimeout(S), S = window.setTimeout(E, b);
125
125
  } catch (b) {
126
- T(), u(b);
126
+ k(), g(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, m] = C(null), [a, c] = C([]), y = A(null), g = A(null);
223
+ w(() => {
224
+ e.then((f) => {
225
+ s(f), o(!1);
226
+ }).catch((f) => {
227
+ m(f), 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 && !g.current && (g.current = new ue(r));
231
+ }, [r]), w(() => {
232
+ g.current && g.current.updateStreams(a);
233
+ }, [a]), w(() => () => {
234
+ var f;
235
+ (f = g.current) == null || f.cleanup();
236
236
  }, []);
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;
237
+ const h = _(
238
+ async (f = 3e4) => {
239
+ if (y.current)
240
+ return y.current;
241
+ const S = Date.now(), k = a.length > 0 ? a[a.length - 1] : null;
242
+ if (k && S - k.createdAt < f)
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
+ }), y.current = null, E.stream;
261
261
  } else
262
- throw m.current = null, new Error("Failed to create stream");
262
+ throw y.current = null, new Error("Failed to create stream");
263
263
  })();
264
- return m.current = P, P;
264
+ return y.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 u = 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,
282
- getOrCreateStream: f
280
+ latestStream: u,
281
+ eventManager: g.current,
282
+ getOrCreateStream: h
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: (m, a) => {
321
+ var y, g, h;
322
+ const c = ye(m);
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
+ (y = e == null ? void 0 : e.onStreamTimeout) == null || y.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
+ (g = e == null ? void 0 : e.onStreamNotFound) == null || g.call(e, c);
330
330
  break;
331
331
  case "AGENT_TASK_PROGRESS_ITEM_UPDATED":
332
- (f = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || f.call(e, c);
332
+ (h = e == null ? void 0 : e.onAgentTaskProgressItemUpdated) == null || h.call(e, c);
333
333
  break;
334
334
  }
335
335
  },
336
- onError: (y) => {
336
+ onError: (m) => {
337
337
  var a;
338
338
  (a = e == null ? void 0 : e.onStreamError) == null || a.call(e, {
339
- streamId: y,
339
+ streamId: m,
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,47 +366,55 @@ 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 g;
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") {
378
- const f = d.current.get(
378
+ r(
379
+ (u) => u.map(
380
+ (p) => {
381
+ var f;
382
+ return ((f = p.confirmedData) == null ? void 0 : f.taskId) === a.agentTaskId ? { ...p, loading: !1 } : p;
383
+ }
384
+ )
385
+ );
386
+ const h = d.current.get(
379
387
  a.agentTaskId
380
388
  );
381
- f && (d.current.delete(a.agentTaskId), f(c));
389
+ h && (d.current.delete(a.agentTaskId), h(c));
382
390
  return;
383
391
  }
384
- (u = e.onAgentTaskProgressItemUpdated) == null || u.call(e, a), n(
385
- (f) => f.map((g) => {
392
+ (g = e.onAgentTaskProgressItemUpdated) == null || g.call(e, a), r(
393
+ (h) => h.map((u) => {
386
394
  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 };
395
+ if (((S = u.confirmedData) == null ? void 0 : S.taskId) !== a.agentTaskId)
396
+ return u;
397
+ const f = u.progressItems.some(
398
+ (k) => k.progressItemId === a.progressItemId
399
+ ) ? u.progressItems.map(
400
+ (k) => k.progressItemId === a.progressItemId ? a : k
401
+ ) : [...u.progressItems, a];
402
+ return { ...u, progressItems: f };
395
403
  })
396
404
  );
397
405
  },
398
406
  onStreamError: (a) => {
399
407
  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),
408
+ (c = e == null ? void 0 : e.onStreamError) == null || c.call(e, a), r((y) => {
409
+ const g = y.find((h) => h.streamId === a.streamId);
410
+ return g ? [
411
+ ...y.filter((h) => h.streamId !== a.streamId),
404
412
  {
405
- ...u,
413
+ ...g,
406
414
  loading: !1,
407
415
  error: a.error
408
416
  }
409
- ] : m;
417
+ ] : y;
410
418
  });
411
419
  },
412
420
  onStreamNotFound: (a) => {
@@ -419,13 +427,13 @@ const ye = (e) => {
419
427
  }
420
428
  }), l = _(
421
429
  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,
430
+ const y = `task-${Date.now()}-${Math.random().toString(36).slice(2, 9)}`, g = await o();
431
+ if (g.type === "success") {
432
+ r([
433
+ ...n,
426
434
  {
427
- taskKey: m,
428
- streamId: u.stream.id,
435
+ taskKey: y,
436
+ streamId: g.stream.id,
429
437
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
430
438
  confirmedData: null,
431
439
  error: null,
@@ -435,11 +443,11 @@ const ye = (e) => {
435
443
  loadingText: c == null ? void 0 : c.loadingText
436
444
  }
437
445
  ]);
438
- const { clientToken: f } = await e.fetchCreateAgentTaskClientToken(a.type), g = await q({
446
+ const { clientToken: h } = await e.fetchCreateAgentTaskClientToken(a.type), u = await Y({
439
447
  pk: t.fency.publishableKey,
440
448
  baseUrl: t.fency.baseUrl,
441
- clientToken: f,
442
- streamToken: u.stream.token,
449
+ clientToken: h,
450
+ streamToken: g.stream.token,
443
451
  request: {
444
452
  streamingChatCompletionTask: a.type === "StreamingChatCompletion" ? {
445
453
  messages: a.messages,
@@ -459,50 +467,50 @@ const ye = (e) => {
459
467
  } : void 0
460
468
  }
461
469
  });
462
- if (g.type === "success" && g.agentTask) {
470
+ if (u.type === "success" && u.agentTask) {
463
471
  s.current.add(
464
- g.agentTask.id
465
- ), n((p) => [
466
- ...p.filter((S) => S.taskKey !== m),
472
+ u.agentTask.id
473
+ ), r((f) => [
474
+ ...f.filter((S) => S.taskKey !== y),
467
475
  {
468
- taskKey: m,
469
- streamId: u.stream.id,
476
+ taskKey: y,
477
+ streamId: g.stream.id,
470
478
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
471
- taskId: g.agentTask.id,
472
- createdAt: g.agentTask.createdAt,
479
+ taskId: u.agentTask.id,
480
+ createdAt: u.agentTask.createdAt,
473
481
  error: null,
474
482
  params: a,
475
483
  progressItems: [],
476
484
  loading: !0,
477
485
  loadingText: c == null ? void 0 : c.loadingText,
478
486
  confirmedData: {
479
- taskId: g.agentTask.id,
480
- createdAt: g.agentTask.createdAt
487
+ taskId: u.agentTask.id,
488
+ createdAt: u.agentTask.createdAt
481
489
  }
482
490
  }
483
491
  ]);
484
- const h = await new Promise((p) => {
492
+ const p = await new Promise((f) => {
485
493
  d.current.set(
486
- g.agentTask.id,
487
- p
494
+ u.agentTask.id,
495
+ f
488
496
  );
489
497
  });
490
498
  return {
491
499
  type: "success",
492
- streamId: u.stream.id,
493
- agentTaskId: g.agentTask.id,
494
- response: h
500
+ streamId: g.stream.id,
501
+ agentTaskId: u.agentTask.id,
502
+ response: p
495
503
  };
496
504
  } else {
497
- if (g.type === "error")
498
- return n((h) => [
499
- ...h.filter((p) => p.taskKey !== m),
505
+ if (u.type === "error")
506
+ return r((p) => [
507
+ ...p.filter((f) => f.taskKey !== y),
500
508
  {
501
- taskKey: m,
509
+ taskKey: y,
502
510
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
503
- streamId: u.stream.id,
511
+ streamId: g.stream.id,
504
512
  params: a,
505
- error: g.error,
513
+ error: u.error,
506
514
  progressItems: [],
507
515
  loading: !1,
508
516
  loadingText: c == null ? void 0 : c.loadingText,
@@ -510,20 +518,20 @@ const ye = (e) => {
510
518
  }
511
519
  ]), {
512
520
  type: "error",
513
- error: g.error
521
+ error: u.error
514
522
  };
515
523
  {
516
- const h = {
524
+ const p = {
517
525
  message: "No response received",
518
526
  code: "UnknownError"
519
527
  };
520
- return n((p) => [
521
- ...p.filter((S) => S.taskKey !== m),
528
+ return r((f) => [
529
+ ...f.filter((S) => S.taskKey !== y),
522
530
  {
523
- taskKey: m,
531
+ taskKey: y,
524
532
  triggeredAt: (/* @__PURE__ */ new Date()).toISOString(),
525
- streamId: u.stream.id,
526
- error: h,
533
+ streamId: g.stream.id,
534
+ error: p,
527
535
  params: a,
528
536
  progressItems: [],
529
537
  loading: !1,
@@ -532,62 +540,62 @@ const ye = (e) => {
532
540
  }
533
541
  ]), {
534
542
  type: "error",
535
- error: h
543
+ error: p
536
544
  };
537
545
  }
538
546
  }
539
547
  } else
540
- return console.error(u.error), u;
548
+ return console.error(g.error), g;
541
549
  },
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(() => () => {
550
+ [t, n, o]
551
+ ), m = $(() => {
552
+ if (n.length !== 0)
553
+ return [...n].sort((a, c) => new Date(c.triggeredAt).getTime() - new Date(a.triggeredAt).getTime())[0];
554
+ }, [n]);
555
+ return w(() => () => {
548
556
  s.current.clear(), d.current.clear();
549
557
  }, []), {
550
- agentTasks: r,
558
+ agentTasks: n,
551
559
  createAgentTask: l,
552
- latest: y
560
+ latest: m
553
561
  };
554
562
  };
555
- function ke(e) {
556
- return e.progressItems.map((t, r) => {
557
- const n = e.progressItems[r + 1], s = n != null;
563
+ function Te(e) {
564
+ return e.progressItems.map((t, n) => {
565
+ const r = e.progressItems[n + 1], s = r != null;
558
566
  let d;
559
- if (n != null && n.createdAt) {
560
- const o = new Date(t.createdAt).getTime(), l = new Date(n.createdAt).getTime();
567
+ if (r != null && r.createdAt) {
568
+ const o = new Date(t.createdAt).getTime(), l = new Date(r.createdAt).getTime();
561
569
  d = Math.round((l - o) / 1e3);
562
570
  }
563
571
  return {
564
572
  item: t,
565
573
  completed: s,
566
- isLatest: r === e.progressItems.length - 1,
574
+ isLatest: n === e.progressItems.length - 1,
567
575
  durationSeconds: d
568
576
  };
569
577
  });
570
578
  }
571
- function O({
579
+ function R({
572
580
  text: e,
573
581
  duration: t = 2,
574
- delay: r = 0,
575
- repeat: n = !0,
582
+ delay: n = 0,
583
+ repeat: r = !0,
576
584
  repeatDelay: s = 0.5,
577
585
  className: d,
578
586
  startOnView: o = !1,
579
587
  once: l = !1,
580
- inViewMargin: y,
588
+ inViewMargin: m,
581
589
  spread: a = 2,
582
590
  color: c = "#999",
583
- shimmerColor: m = "#000",
584
- direction: u = "fromBottom"
591
+ shimmerColor: y = "#000",
592
+ direction: g = "fromBottom"
585
593
  }) {
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";
594
+ const h = A(null), u = Z(h, { once: l, margin: m }), p = $(() => e.length * a, [e, a]), f = !o || u, S = g === "fromBottom" ? "100% center" : "-100% center", k = g === "fromBottom" ? "0% center" : "200% center";
587
595
  return /* @__PURE__ */ i(
588
- k.span,
596
+ T.span,
589
597
  {
590
- ref: f,
598
+ ref: h,
591
599
  className: d,
592
600
  style: {
593
601
  position: "relative",
@@ -598,9 +606,9 @@ function O({
598
606
  color: "transparent",
599
607
  WebkitTextFillColor: "transparent",
600
608
  backgroundRepeat: "no-repeat, padding-box",
601
- "--spread": `${h}px`,
609
+ "--spread": `${p}px`,
602
610
  "--base-color": c,
603
- "--shimmer-color": m,
611
+ "--shimmer-color": y,
604
612
  "--shimmer-bg": "linear-gradient(90deg, transparent calc(50% - var(--spread)), var(--shimmer-color), transparent calc(50% + var(--spread)))",
605
613
  backgroundImage: "var(--shimmer-bg), linear-gradient(var(--base-color), var(--base-color))"
606
614
  },
@@ -608,41 +616,41 @@ function O({
608
616
  backgroundPosition: S,
609
617
  opacity: 0
610
618
  },
611
- animate: p ? {
612
- backgroundPosition: T,
619
+ animate: f ? {
620
+ backgroundPosition: k,
613
621
  opacity: 1
614
622
  } : {},
615
623
  transition: {
616
624
  backgroundPosition: {
617
- repeat: n ? 1 / 0 : 0,
625
+ repeat: r ? 1 / 0 : 0,
618
626
  duration: t,
619
- delay: r,
627
+ delay: n,
620
628
  repeatDelay: s,
621
629
  ease: "linear"
622
630
  },
623
631
  opacity: {
624
632
  duration: 0.3,
625
- delay: r
633
+ delay: n
626
634
  }
627
635
  },
628
636
  children: e
629
637
  }
630
638
  );
631
639
  }
632
- function be(e, t) {
633
- const r = e.item.data;
634
- if (r.eventType === "Error" && "message" in r)
640
+ function ve(e, t) {
641
+ const n = e.item.data;
642
+ if (n.eventType === "Error" && "message" in n)
635
643
  return t.error;
636
- if (r.taskType === "StreamingChatCompletion") {
637
- if (r.eventType === "Text") return t.streaming;
638
- if (r.eventType === "Completed") return t.completed;
644
+ if (n.taskType === "StreamingChatCompletion") {
645
+ if (n.eventType === "Text") return t.streaming;
646
+ if (n.eventType === "Completed") return t.completed;
639
647
  }
640
- if (r.taskType === "StructuredChatCompletion") {
641
- if (r.eventType === "Json") return t.generating;
642
- if (r.eventType === "Completed") return t.completed;
648
+ if (n.taskType === "StructuredChatCompletion") {
649
+ if (n.eventType === "Json") return t.generating;
650
+ if (n.eventType === "Completed") return t.completed;
643
651
  }
644
- if (r.taskType === "MemoryChatCompletion")
645
- switch (r.eventType) {
652
+ if (n.taskType === "MemoryChatCompletion")
653
+ switch (n.eventType) {
646
654
  case "Text":
647
655
  return t.streaming;
648
656
  case "Search":
@@ -657,33 +665,35 @@ function be(e, t) {
657
665
  return t.memoryExplored;
658
666
  case "ExploreMemoryError":
659
667
  return t.memoryExplorationFailed;
668
+ case "ChunkResult":
669
+ return t.chunksRetrieved;
660
670
  case "Completed":
661
671
  return t.completed;
662
672
  }
663
673
  return t.processing;
664
674
  }
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,
675
+ const be = ({ progressViewItems: e, t }) => {
676
+ const n = e[e.length - 1];
677
+ if (!n) return null;
678
+ const r = ve(n, t);
679
+ return /* @__PURE__ */ i("div", { className: "simple-mode-container", children: /* @__PURE__ */ i(W, { mode: "wait", children: /* @__PURE__ */ i(
680
+ T.div,
671
681
  {
672
682
  initial: { opacity: 0, y: 10 },
673
683
  animate: { opacity: 1, y: 0 },
674
684
  exit: { opacity: 0, y: -10 },
675
685
  transition: { duration: 0.3 },
676
- children: r.completed ? /* @__PURE__ */ i(
686
+ children: n.completed ? /* @__PURE__ */ i(
677
687
  "div",
678
688
  {
679
689
  className: "simple-mode-title",
680
690
  style: { color: "#666" },
681
- children: n
691
+ children: r
682
692
  }
683
693
  ) : /* @__PURE__ */ i(
684
- O,
694
+ R,
685
695
  {
686
- text: n,
696
+ text: r,
687
697
  className: "simple-mode-title",
688
698
  duration: 2.5,
689
699
  repeat: !0,
@@ -692,7 +702,7 @@ const ve = ({ progressViewItems: e, t }) => {
692
702
  }
693
703
  )
694
704
  },
695
- r.item.progressItemId
705
+ n.item.progressItemId
696
706
  ) }) });
697
707
  }, K = {
698
708
  'code[class*="language-"]': {
@@ -845,10 +855,10 @@ const ve = ({ progressViewItems: e, t }) => {
845
855
  italic: {
846
856
  fontStyle: "italic"
847
857
  }
848
- }, L = ({
858
+ }, B = ({
849
859
  text: e
850
860
  }) => /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ i(
851
- k.div,
861
+ T.div,
852
862
  {
853
863
  className: "fency-markdown-body-raw",
854
864
  initial: { opacity: 0, y: -10 },
@@ -860,7 +870,7 @@ const ve = ({ progressViewItems: e, t }) => {
860
870
  remarkPlugins: [te],
861
871
  components: {
862
872
  code(t) {
863
- const { children: r, className: n, node: s, ref: d, ...o } = t, l = /language-(\w+)/.exec(n || "");
873
+ const { children: n, className: r, node: s, ref: d, ...o } = t, l = /language-(\w+)/.exec(r || "");
864
874
  return l ? (
865
875
  // @ts-expect-error react-syntax-highlighter types incompatible with @types/react 18
866
876
  /* @__PURE__ */ i(
@@ -868,12 +878,12 @@ const ve = ({ progressViewItems: e, t }) => {
868
878
  {
869
879
  ...o,
870
880
  PreTag: "div",
871
- children: String(r).replace(/\n$/, ""),
881
+ children: String(n).replace(/\n$/, ""),
872
882
  language: l[1],
873
883
  style: K
874
884
  }
875
885
  )
876
- ) : /* @__PURE__ */ i("code", { ...o, className: n, children: String(r) });
886
+ ) : /* @__PURE__ */ i("code", { ...o, className: r, children: String(n) });
877
887
  }
878
888
  },
879
889
  children: e
@@ -883,7 +893,7 @@ const ve = ({ progressViewItems: e, t }) => {
883
893
  ) }), xe = ({ data: e }) => {
884
894
  const t = JSON.stringify(e.json, null, 2);
885
895
  return /* @__PURE__ */ i("div", { id: "structured-chat-completion-response", children: /* @__PURE__ */ i(
886
- k.div,
896
+ T.div,
887
897
  {
888
898
  initial: { opacity: 0, y: -10 },
889
899
  animate: { opacity: 1, y: 0 },
@@ -913,7 +923,11 @@ const ve = ({ progressViewItems: e, t }) => {
913
923
  pageTwo: "pages {a} and {b}",
914
924
  pageMultiple: "pages {list} and {n}",
915
925
  clickToCollapse: "Click to collapse",
916
- clickToExpand: "Click to expand"
926
+ clickToExpand: "Click to expand",
927
+ chunkFound: "1 chunk found",
928
+ chunksFound: "{n} chunks found",
929
+ chunksRetrieved: "Chunks retrieved",
930
+ scoreLabel: "score: {n}"
917
931
  },
918
932
  no: {
919
933
  error: "Feil",
@@ -936,23 +950,27 @@ const ve = ({ progressViewItems: e, t }) => {
936
950
  pageTwo: "side {a} og {b}",
937
951
  pageMultiple: "side {list} og {n}",
938
952
  clickToCollapse: "Klikk for å skjule",
939
- clickToExpand: "Klikk for å utvide"
953
+ clickToExpand: "Klikk for å utvide",
954
+ chunkFound: "1 del funnet",
955
+ chunksFound: "{n} deler funnet",
956
+ chunksRetrieved: "Deler hentet",
957
+ scoreLabel: "poeng: {n}"
940
958
  }
941
959
  };
942
960
  function Ee(e) {
943
961
  return Ce[e];
944
962
  }
945
- function D(e, t) {
963
+ function x(e, t) {
946
964
  return Object.entries(t).reduce(
947
- (r, [n, s]) => r.replace(`{${n}}`, String(s)),
965
+ (n, [r, s]) => n.replace(`{${r}}`, String(s)),
948
966
  e
949
967
  );
950
968
  }
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: [
969
+ const we = ({ data: e, isLatest: t = !1, durationSeconds: n, t: r }) => {
970
+ const s = `${r.searchingPrefix}${e.queryDescription}`;
971
+ return /* @__PURE__ */ v("div", { style: { padding: "16px" }, children: [
954
972
  /* @__PURE__ */ i(
955
- k.div,
973
+ T.div,
956
974
  {
957
975
  style: {
958
976
  display: "flex",
@@ -963,8 +981,8 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
963
981
  initial: { opacity: 0, y: -10 },
964
982
  animate: { opacity: 1, y: 0 },
965
983
  transition: { duration: 0.3, delay: 0 },
966
- children: t && !r ? /* @__PURE__ */ i(
967
- O,
984
+ children: t && !n ? /* @__PURE__ */ i(
985
+ R,
968
986
  {
969
987
  text: s,
970
988
  duration: 2.5,
@@ -975,7 +993,7 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
975
993
  ) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: s })
976
994
  }
977
995
  ),
978
- r !== void 0 && /* @__PURE__ */ i(
996
+ n !== void 0 && /* @__PURE__ */ i(
979
997
  "div",
980
998
  {
981
999
  style: {
@@ -984,15 +1002,15 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
984
1002
  marginTop: "4px",
985
1003
  fontStyle: "italic"
986
1004
  },
987
- children: D(n.tookSeconds, { n: r })
1005
+ children: x(r.tookSeconds, { n })
988
1006
  }
989
1007
  )
990
1008
  ] });
991
- }, Ae = ({ isLatest: e = !1, durationSeconds: t, t: r }) => {
992
- const n = r.addingSources;
993
- return /* @__PURE__ */ x("div", { style: { padding: "16px" }, children: [
1009
+ }, Ae = ({ isLatest: e = !1, durationSeconds: t, t: n }) => {
1010
+ const r = n.addingSources;
1011
+ return /* @__PURE__ */ v("div", { style: { padding: "16px" }, children: [
994
1012
  /* @__PURE__ */ i(
995
- k.div,
1013
+ T.div,
996
1014
  {
997
1015
  style: {
998
1016
  display: "flex",
@@ -1004,15 +1022,15 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
1004
1022
  animate: { opacity: 1, y: 0 },
1005
1023
  transition: { duration: 0.3, delay: 0 },
1006
1024
  children: e && !t ? /* @__PURE__ */ i(
1007
- O,
1025
+ R,
1008
1026
  {
1009
- text: n,
1027
+ text: r,
1010
1028
  duration: 2.5,
1011
1029
  repeat: !0,
1012
1030
  color: "#999",
1013
1031
  shimmerColor: "#000"
1014
1032
  }
1015
- ) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: n })
1033
+ ) : /* @__PURE__ */ i("span", { style: { color: "#666" }, children: r })
1016
1034
  }
1017
1035
  ),
1018
1036
  t !== void 0 && /* @__PURE__ */ i(
@@ -1024,7 +1042,7 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
1024
1042
  marginTop: "4px",
1025
1043
  fontStyle: "italic"
1026
1044
  },
1027
- children: D(r.tookSeconds, { n: t })
1045
+ children: x(n.tookSeconds, { n: t })
1028
1046
  }
1029
1047
  )
1030
1048
  ] });
@@ -1032,18 +1050,18 @@ const we = ({ data: e, isLatest: t = !1, durationSeconds: r, t: n }) => {
1032
1050
  function Ie(e, t) {
1033
1051
  if (e.length === 0) return "";
1034
1052
  if (e.length === 1)
1035
- return D(t.pageSingle, { n: e[0] });
1053
+ return x(t.pageSingle, { n: e[0] });
1036
1054
  if (e.length === 2)
1037
- return D(t.pageTwo, {
1055
+ return x(t.pageTwo, {
1038
1056
  a: e[0],
1039
1057
  b: e[1]
1040
1058
  });
1041
- const r = e[e.length - 1], n = e.slice(0, -1).join(", ");
1042
- return D(t.pageMultiple, { list: n, n: r });
1059
+ const n = e[e.length - 1], r = e.slice(0, -1).join(", ");
1060
+ return x(t.pageMultiple, { list: r, n });
1043
1061
  }
1044
- const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { style: { padding: "16px" }, children: [
1062
+ const Me = ({ data: e, onSourceClick: t, t: n }) => /* @__PURE__ */ v("div", { style: { padding: "16px" }, children: [
1045
1063
  /* @__PURE__ */ i(
1046
- k.div,
1064
+ T.div,
1047
1065
  {
1048
1066
  style: {
1049
1067
  marginBottom: "10px",
@@ -1056,33 +1074,33 @@ const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { s
1056
1074
  initial: { opacity: 0, y: -10 },
1057
1075
  animate: { opacity: 1, y: 0 },
1058
1076
  transition: { duration: 0.3, delay: 0 },
1059
- children: r.sources
1077
+ children: n.sources
1060
1078
  }
1061
1079
  ),
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(
1080
+ /* @__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
1081
  De,
1064
1082
  {
1065
- source: n,
1083
+ source: r,
1066
1084
  index: s,
1067
1085
  onSourceClick: t,
1068
- t: r
1086
+ t: n
1069
1087
  },
1070
- n.memoryId
1088
+ r.memoryId
1071
1089
  )) })
1072
1090
  ] }), De = ({
1073
1091
  source: e,
1074
1092
  index: t,
1075
- onSourceClick: r,
1076
- t: n
1093
+ onSourceClick: n,
1094
+ t: r
1077
1095
  }) => {
1078
- const [s, d] = v(!1), o = !!r, l = e.pageNumbers ?? [], y = Ie(l, n);
1079
- return /* @__PURE__ */ x(
1080
- k.div,
1096
+ const [s, d] = C(!1), o = !!n, l = e.pageNumbers ?? [], m = Ie(l, r);
1097
+ return /* @__PURE__ */ v(
1098
+ T.div,
1081
1099
  {
1082
1100
  initial: { opacity: 0, scale: 0.9 },
1083
1101
  animate: { opacity: 1, scale: 1 },
1084
1102
  transition: { duration: 0.25, delay: t * 0.05 },
1085
- onClick: o ? () => r(e.memoryId) : void 0,
1103
+ onClick: o ? () => n(e.memoryId) : void 0,
1086
1104
  onMouseEnter: o ? () => d(!0) : void 0,
1087
1105
  onMouseLeave: o ? () => d(!1) : void 0,
1088
1106
  style: {
@@ -1099,16 +1117,16 @@ const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { s
1099
1117
  },
1100
1118
  children: [
1101
1119
  /* @__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 })
1120
+ m && /* @__PURE__ */ i("span", { style: { fontSize: "12px", color: "#666" }, children: m })
1103
1121
  ]
1104
1122
  }
1105
1123
  );
1106
1124
  }, U = ({
1107
1125
  color: e = "#78b13f",
1108
1126
  size: t = 24,
1109
- borderWidth: r = 7
1127
+ borderWidth: n = 7
1110
1128
  }) => {
1111
- const n = t * 0.5;
1129
+ const r = t * 0.5;
1112
1130
  return /* @__PURE__ */ i(
1113
1131
  "span",
1114
1132
  {
@@ -1116,26 +1134,26 @@ const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { s
1116
1134
  display: "inline-block",
1117
1135
  transform: "rotate(45deg)",
1118
1136
  height: t,
1119
- width: n,
1120
- borderBottom: `${r}px solid ${e}`,
1121
- borderRight: `${r}px solid ${e}`
1137
+ width: r,
1138
+ borderBottom: `${n}px solid ${e}`,
1139
+ borderRight: `${n}px solid ${e}`
1122
1140
  }
1123
1141
  }
1124
1142
  );
1125
1143
  }, Pe = ({
1126
1144
  color: e = "#333",
1127
1145
  size: t = 32,
1128
- lineWidth: r = 2
1146
+ lineWidth: n = 2
1129
1147
  }) => {
1130
- const n = t + 1, s = (t - r) / 2, d = (t - n) / 2, o = {
1148
+ const r = t + 1, s = (t - n) / 2, d = (t - r) / 2, o = {
1131
1149
  position: "absolute",
1132
1150
  left: s,
1133
1151
  top: d,
1134
- width: r,
1135
- height: n,
1152
+ width: n,
1153
+ height: r,
1136
1154
  backgroundColor: e
1137
1155
  };
1138
- return /* @__PURE__ */ x(
1156
+ return /* @__PURE__ */ v(
1139
1157
  "span",
1140
1158
  {
1141
1159
  style: {
@@ -1167,16 +1185,16 @@ const Me = ({ data: e, onSourceClick: t, t: r }) => /* @__PURE__ */ x("div", { s
1167
1185
  }
1168
1186
  );
1169
1187
  };
1170
- function Oe({
1188
+ function Re({
1171
1189
  eventType: e,
1172
1190
  completed: t
1173
1191
  }) {
1174
1192
  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
1193
  }
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,
1194
+ const z = 80, Fe = ({ data: e, completed: t, isLatest: n = !1, t: r }) => {
1195
+ const [s, d] = C(!1), o = e.eventType === "ExploreMemoryResult" ? e.result : void 0, l = o != null && o.length > z, m = o != null ? s || !l ? o : `${o.slice(0, z)}...` : void 0, a = l;
1196
+ return /* @__PURE__ */ i("div", { style: { padding: "10px" }, children: /* @__PURE__ */ v(
1197
+ T.div,
1180
1198
  {
1181
1199
  initial: { opacity: 0 },
1182
1200
  animate: { opacity: 1 },
@@ -1204,7 +1222,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1204
1222
  width: 32
1205
1223
  },
1206
1224
  children: /* @__PURE__ */ i(
1207
- Oe,
1225
+ Re,
1208
1226
  {
1209
1227
  eventType: e.eventType,
1210
1228
  completed: t
@@ -1212,7 +1230,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1212
1230
  )
1213
1231
  }
1214
1232
  ),
1215
- /* @__PURE__ */ x(
1233
+ /* @__PURE__ */ v(
1216
1234
  "div",
1217
1235
  {
1218
1236
  style: {
@@ -1229,7 +1247,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1229
1247
  children: e.memoryTitle
1230
1248
  }
1231
1249
  ),
1232
- y != null && /* @__PURE__ */ i(
1250
+ m != null && /* @__PURE__ */ i(
1233
1251
  "span",
1234
1252
  {
1235
1253
  style: {
@@ -1238,7 +1256,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1238
1256
  lineHeight: 1.4,
1239
1257
  whiteSpace: s ? "pre-wrap" : void 0
1240
1258
  },
1241
- children: y
1259
+ children: m
1242
1260
  }
1243
1261
  ),
1244
1262
  a && /* @__PURE__ */ i(
@@ -1249,7 +1267,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1249
1267
  color: "#999",
1250
1268
  marginTop: 2
1251
1269
  },
1252
- children: s ? n.clickToCollapse : n.clickToExpand
1270
+ children: s ? r.clickToCollapse : r.clickToExpand
1253
1271
  }
1254
1272
  )
1255
1273
  ]
@@ -1258,8 +1276,124 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1258
1276
  ]
1259
1277
  }
1260
1278
  ) });
1261
- }, Fe = ({ message: e }) => /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ i(
1262
- k.div,
1279
+ };
1280
+ function Oe(e, t) {
1281
+ if (e.length === 0) return "";
1282
+ if (e.length === 1)
1283
+ return x(t.pageSingle, { n: e[0] });
1284
+ if (e.length === 2)
1285
+ return x(t.pageTwo, {
1286
+ a: e[0],
1287
+ b: e[1]
1288
+ });
1289
+ const n = e[e.length - 1], r = e.slice(0, -1).join(", ");
1290
+ return x(t.pageMultiple, { list: r, n });
1291
+ }
1292
+ function Le(e, t) {
1293
+ return e === 1 ? t.chunkFound : x(t.chunksFound, { n: e });
1294
+ }
1295
+ const Be = ({ data: e, t }) => {
1296
+ const [n, r] = C(!1), s = e.chunks.length, d = s > 0;
1297
+ return /* @__PURE__ */ v("div", { style: { padding: "10px" }, children: [
1298
+ /* @__PURE__ */ v(
1299
+ T.div,
1300
+ {
1301
+ initial: { opacity: 0 },
1302
+ animate: { opacity: 1 },
1303
+ transition: { duration: 0.25 },
1304
+ onClick: d ? () => r((o) => !o) : void 0,
1305
+ style: {
1306
+ paddingBottom: n ? "12px" : 0,
1307
+ borderBottom: n ? "1px solid #eee" : void 0,
1308
+ display: "flex",
1309
+ flexDirection: "column",
1310
+ gap: "4px",
1311
+ minWidth: 0,
1312
+ cursor: d ? "pointer" : "default"
1313
+ },
1314
+ children: [
1315
+ /* @__PURE__ */ i("span", { style: { fontSize: 13, fontWeight: 500, color: "#333" }, children: e.memoryTitle }),
1316
+ /* @__PURE__ */ i("span", { style: { fontSize: 12, color: "#666" }, children: Le(s, t) }),
1317
+ d && /* @__PURE__ */ i(
1318
+ "span",
1319
+ {
1320
+ style: {
1321
+ fontSize: 11,
1322
+ color: "#999",
1323
+ marginTop: 2
1324
+ },
1325
+ children: n ? t.clickToCollapse : t.clickToExpand
1326
+ }
1327
+ )
1328
+ ]
1329
+ }
1330
+ ),
1331
+ n && d && /* @__PURE__ */ i(
1332
+ T.div,
1333
+ {
1334
+ initial: { opacity: 0, height: 0 },
1335
+ animate: { opacity: 1, height: "auto" },
1336
+ transition: { duration: 0.2 },
1337
+ style: {
1338
+ maxHeight: 220,
1339
+ overflowY: "auto",
1340
+ marginTop: 12,
1341
+ display: "flex",
1342
+ flexDirection: "column",
1343
+ gap: 8
1344
+ },
1345
+ children: e.chunks.map((o, l) => {
1346
+ const m = o.pageNumbers ?? [], a = Oe(m, t);
1347
+ return /* @__PURE__ */ v(
1348
+ "div",
1349
+ {
1350
+ style: {
1351
+ padding: "8px 12px",
1352
+ borderRadius: 6,
1353
+ border: "1px solid #e0e0e0",
1354
+ backgroundColor: "#fafafa"
1355
+ },
1356
+ children: [
1357
+ /* @__PURE__ */ i(
1358
+ "span",
1359
+ {
1360
+ style: {
1361
+ fontSize: 12,
1362
+ color: "#333",
1363
+ lineHeight: 1.4,
1364
+ display: "block",
1365
+ marginBottom: 4
1366
+ },
1367
+ children: o.content
1368
+ }
1369
+ ),
1370
+ /* @__PURE__ */ v(
1371
+ "div",
1372
+ {
1373
+ style: {
1374
+ display: "flex",
1375
+ gap: 8,
1376
+ fontSize: 11,
1377
+ color: "#666"
1378
+ },
1379
+ children: [
1380
+ a && /* @__PURE__ */ i("span", { children: a }),
1381
+ /* @__PURE__ */ i("span", { children: x(t.scoreLabel, {
1382
+ n: o.score
1383
+ }) })
1384
+ ]
1385
+ }
1386
+ )
1387
+ ]
1388
+ },
1389
+ l
1390
+ );
1391
+ })
1392
+ }
1393
+ )
1394
+ ] });
1395
+ }, Ue = ({ message: e }) => /* @__PURE__ */ i("div", { style: { padding: "16px" }, children: /* @__PURE__ */ i(
1396
+ T.div,
1263
1397
  {
1264
1398
  initial: { opacity: 0, y: -10 },
1265
1399
  animate: { opacity: 1, y: 0 },
@@ -1281,26 +1415,26 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1281
1415
  }
1282
1416
  )
1283
1417
  }
1284
- ) }), Be = ({
1418
+ ) }), ze = ({
1285
1419
  progressViewItems: e,
1286
1420
  loadingText: t,
1287
- t: r,
1288
- onSourceClick: n
1421
+ t: n,
1422
+ onSourceClick: r
1289
1423
  }) => {
1290
- const s = w(null);
1291
- E(() => {
1424
+ const s = A(null);
1425
+ w(() => {
1292
1426
  s.current && (s.current.scrollTop = s.current.scrollHeight);
1293
1427
  }, [e.length]);
1294
1428
  const d = (o) => {
1295
1429
  const l = o.item.data;
1296
1430
  if (l.taskType === "StreamingChatCompletion" && l.eventType === "Text")
1297
- return /* @__PURE__ */ i(L, { text: l.text });
1431
+ return /* @__PURE__ */ i(B, { text: l.text });
1298
1432
  if (l.taskType === "StructuredChatCompletion" && l.eventType === "Json")
1299
1433
  return /* @__PURE__ */ i(xe, { data: l });
1300
1434
  if (l.taskType === "MemoryChatCompletion")
1301
1435
  switch (l.eventType) {
1302
1436
  case "Text":
1303
- return /* @__PURE__ */ i(L, { text: l.text });
1437
+ return /* @__PURE__ */ i(B, { text: l.text });
1304
1438
  case "Search":
1305
1439
  return /* @__PURE__ */ i(
1306
1440
  we,
@@ -1308,7 +1442,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1308
1442
  data: l,
1309
1443
  isLatest: o.isLatest,
1310
1444
  durationSeconds: o.durationSeconds,
1311
- t: r
1445
+ t: n
1312
1446
  }
1313
1447
  );
1314
1448
  case "FindSources":
@@ -1318,7 +1452,7 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1318
1452
  data: l,
1319
1453
  isLatest: o.isLatest,
1320
1454
  durationSeconds: o.durationSeconds,
1321
- t: r
1455
+ t: n
1322
1456
  }
1323
1457
  );
1324
1458
  case "SourcesResult":
@@ -1326,39 +1460,41 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1326
1460
  Me,
1327
1461
  {
1328
1462
  data: l,
1329
- onSourceClick: n,
1330
- t: r
1463
+ onSourceClick: r,
1464
+ t: n
1331
1465
  }
1332
1466
  );
1333
1467
  case "ExploreMemoryStart":
1334
1468
  case "ExploreMemoryResult":
1335
1469
  case "ExploreMemoryError":
1336
1470
  return /* @__PURE__ */ i(
1337
- Re,
1471
+ Fe,
1338
1472
  {
1339
1473
  data: l,
1340
1474
  completed: o.completed,
1341
1475
  isLatest: o.isLatest,
1342
- t: r
1476
+ t: n
1343
1477
  }
1344
1478
  );
1479
+ case "ChunkResult":
1480
+ return /* @__PURE__ */ i(Be, { data: l, t: n });
1345
1481
  case "Completed":
1346
1482
  return null;
1347
1483
  }
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;
1484
+ 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
1485
  };
1350
1486
  return e.length === 0 ? /* @__PURE__ */ i("div", { style: { width: "fit-content" }, children: /* @__PURE__ */ i(
1351
- O,
1487
+ R,
1352
1488
  {
1353
- text: t ?? r.processingYourTask,
1489
+ text: t ?? n.processingYourTask,
1354
1490
  duration: 1.5,
1355
1491
  repeat: !0,
1356
1492
  repeatDelay: 0,
1357
1493
  color: "#999",
1358
1494
  shimmerColor: "#000"
1359
1495
  }
1360
- ) }) : /* @__PURE__ */ i("div", { id: "agent-task-progress-verbose", ref: s, children: /* @__PURE__ */ i($, { children: e.map((o, l) => /* @__PURE__ */ i(
1361
- k.div,
1496
+ ) }) : /* @__PURE__ */ i("div", { id: "agent-task-progress-verbose", ref: s, children: /* @__PURE__ */ i(W, { children: e.map((o, l) => /* @__PURE__ */ i(
1497
+ T.div,
1362
1498
  {
1363
1499
  id: `agent-task-progress-item-${o.item.progressItemId}`,
1364
1500
  initial: { opacity: 0, y: -20 },
@@ -1372,33 +1508,33 @@ const N = 80, Re = ({ data: e, completed: t, isLatest: r = !1, t: n }) => {
1372
1508
  },
1373
1509
  o.item.progressItemId
1374
1510
  )) }) });
1375
- }, Ke = ({
1511
+ }, Ve = ({
1376
1512
  agentTask: e,
1377
1513
  mode: t = "verbose",
1378
- language: r,
1379
- onSourceClick: n
1514
+ language: n,
1515
+ onSourceClick: r
1380
1516
  }) => {
1381
- const s = ke(e), d = e.params.type === "MemoryChatCompletion" && "language" in e.params ? e.params.language ?? "en" : r ?? "en", o = Ee(d);
1517
+ const s = Te(e), d = e.params.type === "MemoryChatCompletion" && "language" in e.params ? e.params.language ?? "en" : n ?? "en", o = Ee(d);
1382
1518
  return t === "simple" ? /* @__PURE__ */ i(
1383
- ve,
1519
+ be,
1384
1520
  {
1385
1521
  progressViewItems: s,
1386
1522
  t: o
1387
1523
  }
1388
1524
  ) : /* @__PURE__ */ i(
1389
- Be,
1525
+ ze,
1390
1526
  {
1391
1527
  progressViewItems: s,
1392
1528
  loadingText: e.loadingText,
1393
1529
  t: o,
1394
- onSourceClick: n
1530
+ onSourceClick: r
1395
1531
  }
1396
1532
  );
1397
1533
  };
1398
1534
  export {
1399
- Ke as AgentTaskProgress,
1535
+ Ve as AgentTaskProgress,
1400
1536
  U as Checkmark,
1401
- We as FencyProvider,
1537
+ Ge as FencyProvider,
1402
1538
  Pe as XMark,
1403
- He as useAgentTasks
1539
+ Je as useAgentTasks
1404
1540
  };