@fencyai/react 0.1.136 → 0.1.138

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