@arcteninc/core 0.0.177 → 0.0.178

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.mjs CHANGED
@@ -1,192 +1,193 @@
1
- import { useRef as z, useState as N, useMemo as O, useEffect as R, useCallback as pe } from "react";
2
- import { useChat as Ze } from "@ai-sdk/react";
3
- import { DefaultChatTransport as et, lastAssistantMessageIsCompleteWithToolCalls as tt } from "ai";
4
- const I = Symbol.for("@arcteninc/core:originalName");
5
- function ft(l, c) {
6
- return l[I] = c, l;
1
+ import { useRef as z, useState as _, useMemo as v, useEffect as R, useCallback as ye } from "react";
2
+ import { useChat as nt } from "@ai-sdk/react";
3
+ import { DefaultChatTransport as st, lastAssistantMessageIsCompleteWithToolCalls as at } from "ai";
4
+ const B = Symbol.for("@arcteninc/core:originalName");
5
+ function gt(u, c) {
6
+ return u[B] = c, u;
7
7
  }
8
- function ot(l, c, m, y) {
9
- if (typeof l != "function") return null;
10
- const w = l[I];
11
- if (w) {
12
- const T = c[w];
13
- if (T && !m.has(T.name))
14
- return { fn: l, meta: T };
8
+ function it(u, c, m, g) {
9
+ if (typeof u != "function") return null;
10
+ const y = u[B];
11
+ if (y) {
12
+ const $ = c[y];
13
+ if ($ && !m.has($.name))
14
+ return { fn: u, meta: $ };
15
15
  }
16
- const u = l.name;
17
- let a;
18
- if (u && (a = c[u], a && !m.has(a.name)))
19
- return l[I] = a.name, { fn: l, meta: a };
20
- if (y && y.length > 0) {
21
- for (const T of y)
22
- if (!m.has(T) && (a = c[T], a))
23
- return l[I] = a.name, { fn: l, meta: a };
24
- } else if (a = Object.values(c).find(
16
+ const f = u.name;
17
+ let i;
18
+ if (f && (i = c[f], i && !m.has(i.name)))
19
+ return u[B] = i.name, { fn: u, meta: i };
20
+ if (g && g.length > 0) {
21
+ for (const $ of g)
22
+ if (!m.has($) && (i = c[$], i))
23
+ return u[B] = i.name, { fn: u, meta: i };
24
+ } else if (i = Object.values(c).find(
25
25
  (x) => !m.has(x.name)
26
- ), a)
27
- return l[I] = a.name, { fn: l, meta: a };
26
+ ), i)
27
+ return u[B] = i.name, { fn: u, meta: i };
28
28
  return null;
29
29
  }
30
- function rt(l, c) {
30
+ function ct(u, c) {
31
31
  if (!c)
32
32
  return [];
33
- let m, y;
33
+ let m, g;
34
34
  if ("functions" in c && typeof c.functions == "object") {
35
- const u = c;
36
- m = u.functions, y = u.toolOrder;
35
+ const f = c;
36
+ m = f.functions, g = f.toolOrder;
37
37
  } else
38
- m = c, y = void 0;
39
- const w = /* @__PURE__ */ new Set();
40
- return l.map((u) => {
41
- const a = ot(
42
- u,
38
+ m = c, g = void 0;
39
+ const y = /* @__PURE__ */ new Set();
40
+ return u.map((f) => {
41
+ const i = it(
42
+ f,
43
43
  m,
44
- w,
45
- y
44
+ y,
45
+ g
46
46
  );
47
- if (!a) {
48
- const T = u.name, M = u[I] || T || "unnamed";
47
+ if (!i) {
48
+ const $ = f.name, M = f[B] || $ || "unnamed";
49
49
  return typeof process < "u" && (process.env.NODE_ENV === "development" || process.env.NODE_ENV !== "production") && typeof console < "u" && console.warn && console.warn(
50
50
  `⚠️ [@arcteninc/core] No metadata found for tool "${M}". This tool will be excluded.
51
51
  To fix: Run "arcten-extract-types ." and ensure "${M}" is used in ArctenAgent/useAgent.`
52
52
  ), null;
53
53
  }
54
- return w.add(a.meta.name), {
55
- name: a.meta.name,
54
+ return y.add(i.meta.name), {
55
+ name: i.meta.name,
56
56
  // Use original name from metadata, not minified fn.name
57
- description: a.meta.description,
58
- jsonSchema: a.meta.parameters
57
+ description: i.meta.description,
58
+ jsonSchema: i.meta.parameters
59
59
  };
60
- }).filter((u) => u !== null);
60
+ }).filter((f) => f !== null);
61
61
  }
62
- const A = process.env.NODE_ENV === "development";
63
- function se(l) {
64
- if (typeof l == "string")
62
+ const j = process.env.NODE_ENV === "development";
63
+ function ae(u) {
64
+ if (typeof u == "string")
65
65
  try {
66
- const c = JSON.parse(l);
67
- return se(c);
66
+ const c = JSON.parse(u);
67
+ return ae(c);
68
68
  } catch {
69
- return l;
69
+ return u;
70
70
  }
71
- if (Array.isArray(l))
72
- return l.map(se);
73
- if (l && typeof l == "object") {
71
+ if (Array.isArray(u))
72
+ return u.map(ae);
73
+ if (u && typeof u == "object") {
74
74
  const c = {};
75
- for (const [m, y] of Object.entries(l))
76
- c[m] = se(y);
75
+ for (const [m, g] of Object.entries(u))
76
+ c[m] = ae(g);
77
77
  return c;
78
78
  }
79
- return l;
79
+ return u;
80
80
  }
81
- function nt(l) {
82
- if (typeof l == "string") {
81
+ function lt(u) {
82
+ if (typeof u == "string") {
83
83
  try {
84
- const c = JSON.parse(l);
84
+ const c = JSON.parse(u);
85
85
  if (c && typeof c == "object" && !Array.isArray(c))
86
- return se(c);
86
+ return ae(c);
87
87
  } catch {
88
88
  }
89
89
  return {};
90
90
  }
91
- return l && typeof l == "object" && !Array.isArray(l) ? se(l) : {};
91
+ return u && typeof u == "object" && !Array.isArray(u) ? ae(u) : {};
92
92
  }
93
- function st(l, c) {
94
- if (!l || l.length === 0)
93
+ function ut(u, c) {
94
+ if (!u || u.length === 0)
95
95
  return c;
96
96
  const m = /* @__PURE__ */ new Map();
97
- c.forEach((u) => {
98
- const a = u[I] || u.name;
99
- a && m.set(a, u);
97
+ c.forEach((f) => {
98
+ const i = f[B] || f.name;
99
+ i && m.set(i, f);
100
100
  });
101
- const y = new Map(l.map((u) => [u.name, u])), w = [];
102
- return l.forEach((u) => {
103
- const a = m.get(u.name);
104
- if (!a) {
105
- A && console.log(`[useAgent] Skipping server-only tool: ${u.name}`);
101
+ const g = new Map(u.map((f) => [f.name, f])), y = [];
102
+ return u.forEach((f) => {
103
+ const i = m.get(f.name);
104
+ if (!i) {
105
+ j && console.log(`[useAgent] Skipping server-only tool: ${f.name}`);
106
106
  return;
107
107
  }
108
- if (!u.isEnabled && !u.isOverridable) {
109
- A && console.log(
110
- `[useAgent] Blocking non-overridable disabled tool: ${u.name}`
108
+ if (!f.isEnabled && !f.isOverridable) {
109
+ j && console.log(
110
+ `[useAgent] Blocking non-overridable disabled tool: ${f.name}`
111
111
  );
112
112
  return;
113
113
  }
114
- if (!u.isEnabled && u.isOverridable && a) {
115
- A && console.log(
116
- `[useAgent] Allowing overridable disabled tool with local implementation: ${u.name}`
117
- ), w.push(a);
114
+ if (!f.isEnabled && f.isOverridable && i) {
115
+ j && console.log(
116
+ `[useAgent] Allowing overridable disabled tool with local implementation: ${f.name}`
117
+ ), y.push(i);
118
118
  return;
119
119
  }
120
- u.isEnabled && a && w.push(a);
121
- }), c.forEach((u) => {
122
- const a = u[I] || u.name;
123
- a && !y.has(a) && (A && console.log(
124
- `[useAgent] Allowing client-only tool (forward compatible): ${a}`
125
- ), w.push(u));
126
- }), w;
120
+ f.isEnabled && i && y.push(i);
121
+ }), c.forEach((f) => {
122
+ const i = f[B] || f.name;
123
+ i && !g.has(i) && (j && console.log(
124
+ `[useAgent] Allowing client-only tool (forward compatible): ${i}`
125
+ ), y.push(f));
126
+ }), y;
127
127
  }
128
- function dt({
129
- apiBaseUrl: l = "https://api.arcten.com",
128
+ function yt({
129
+ apiBaseUrl: u = "https://api.arcten.com",
130
130
  tokenEndpoint: c = "/api/arcten/token",
131
131
  clientToken: m,
132
- skipTokenFetch: y = !1,
133
- user: w,
134
- tools: u = [],
135
- safeTools: a = [],
136
- safeToolNames: T,
132
+ skipTokenFetch: g = !1,
133
+ user: y,
134
+ tools: f = [],
135
+ safeTools: i = [],
136
+ safeToolNames: $,
137
137
  toolMetadata: x,
138
138
  // NOTE: systemPrompt is deprecated; prompts are managed server-side per project/agent.
139
139
  systemPrompt: M = "",
140
- agentId: P,
140
+ agentId: W,
141
141
  agentName: Z,
142
- projectId: _,
143
- enableRemoteConfig: $,
142
+ projectId: D,
143
+ enableRemoteConfig: T,
144
144
  remoteConfigUrl: k,
145
- initialMessages: D = [],
145
+ initialMessages: U = [],
146
146
  conversationId: ee,
147
- state: W,
148
- onToolCall: U,
147
+ state: q,
148
+ onToolCall: I,
149
149
  onFinish: F,
150
- sources: v,
151
- ragConfig: ae,
152
- ragFilters: q
150
+ sources: O,
151
+ ragConfig: ie,
152
+ ragFilters: L,
153
153
  // Deprecated: use ragConfig or sources instead
154
+ planning: S = !1
154
155
  } = {}) {
155
- const L = z(W), C = l.replace(/\/+$/, ""), [g, ge] = N(null), [at, ve] = N(!1), [ct, je] = N(
156
+ const te = z(q), w = u.replace(/\/+$/, ""), [E, we] = _(null), [ft, _e] = _(!1), [dt, xe] = _(
156
157
  null
157
- ), ce = O(() => {
158
- const t = v || [], e = g?.config?.sources || [];
158
+ ), ce = v(() => {
159
+ const t = O || [], e = E?.config?.sources || [];
159
160
  return [.../* @__PURE__ */ new Set([...t, ...e])];
160
- }, [v, g]), S = O(() => ae !== void 0 ? ae : q ? { enabled: !0, filters: q } : ce && ce.length > 0 ? {
161
+ }, [O, E]), A = v(() => ie !== void 0 ? ie : L ? { enabled: !0, filters: L } : ce && ce.length > 0 ? {
161
162
  enabled: !0,
162
163
  organizationId: ce[0],
163
164
  // Use first source as default
164
165
  autoExecute: !0,
165
166
  filters: void 0
166
- } : { enabled: !1 }, [ce, ae, q]), Oe = O(() => $ === !1 ? !1 : !!_, [_, $]);
167
+ } : { enabled: !1 }, [ce, ie, L]), Me = v(() => T === !1 ? !1 : !!D, [D, T]);
167
168
  R(() => {
168
- if (!Oe || !E.current)
169
+ if (!Me || !C.current)
169
170
  return;
170
171
  (async () => {
171
- ve(!0), je(null);
172
+ _e(!0), xe(null);
172
173
  try {
173
- const o = `${k || C.replace("/chat", "").replace(/\/$/, "")}/convex/api/query`, r = await fetch(o, {
174
+ const o = `${k || w.replace("/chat", "").replace(/\/$/, "")}/convex/api/query`, r = await fetch(o, {
174
175
  method: "POST",
175
176
  headers: {
176
177
  "Content-Type": "application/json",
177
- Authorization: `Bearer ${E.current}`
178
+ Authorization: `Bearer ${C.current}`
178
179
  },
179
180
  body: JSON.stringify({
180
181
  path: "agents:getConfigForClient",
181
- args: { projectId: _, agentName: Z, agentId: P },
182
+ args: { projectId: D, agentName: Z, agentId: W },
182
183
  format: "json"
183
184
  })
184
185
  });
185
186
  if (!r.ok) {
186
187
  if (r.status === 404) {
187
- A && console.warn(
188
+ j && console.warn(
188
189
  "[useAgent] Remote config endpoint not found (404), using local tools only"
189
- ), ge(null);
190
+ ), we(null);
190
191
  return;
191
192
  }
192
193
  const s = await r.text().catch(() => "Unknown error");
@@ -195,50 +196,54 @@ function dt({
195
196
  );
196
197
  }
197
198
  const n = await r.json();
198
- ge(n?.value || null), A && console.log(
199
+ we(n?.value || null), j && console.log(
199
200
  "[useAgent] Remote config loaded successfully:",
200
201
  n?.value
201
202
  );
202
203
  } catch (e) {
203
204
  console.error("[useAgent] Failed to fetch remote config:", e);
204
205
  const o = e instanceof Error ? e : new Error(String(e));
205
- je(o), ge(null);
206
+ xe(o), we(null);
206
207
  } finally {
207
- ve(!1);
208
+ _e(!1);
208
209
  }
209
210
  })();
210
211
  }, [
211
- Oe,
212
- _,
212
+ Me,
213
+ D,
213
214
  Z,
214
- P,
215
- C,
215
+ W,
216
+ w,
216
217
  k
217
218
  ]);
218
- const [G, me] = N(
219
+ const [G, be] = _(
219
220
  m || null
220
- ), E = z(m || null);
221
+ ), C = z(m || null);
221
222
  R(() => {
222
- L.current = W;
223
- }, [W]);
224
- const [Je, re] = N(null), [te, ye] = N(null), H = z(null), [Ne, xe] = N([]), [we, Me] = N(
223
+ te.current = q;
224
+ }, [q]);
225
+ const [qe, ne] = _(null), [oe, ke] = _(null), H = z(null), [Re, De] = _([]), [Te, Ue] = _(
225
226
  ee || (typeof window < "u" ? crypto.randomUUID() : null)
226
- ), [ze, ie] = N(!1), [be, ke] = N(/* @__PURE__ */ new Map()), le = z(/* @__PURE__ */ new Set()), $e = z(/* @__PURE__ */ new Set()), ue = z(/* @__PURE__ */ new Set());
227
+ ), [Fe, le] = _(!1), [$e, Se] = _(/* @__PURE__ */ new Map()), ue = z(/* @__PURE__ */ new Set()), Ee = z(/* @__PURE__ */ new Set()), fe = z(/* @__PURE__ */ new Set());
227
228
  R(() => {
228
- L.current = W;
229
- }, [W]);
230
- const V = O(() => S?.enabled ? async function(e, o = 20, r) {
229
+ te.current = q;
230
+ }, [q]);
231
+ const [Ae, Le] = _([]), de = v(() => S ? async function() {
232
+ return { todos: Ae };
233
+ } : null, [S, Ae]), he = v(() => S ? async function(e) {
234
+ return Le(e), { success: !0, todos: e };
235
+ } : null, [S]), V = v(() => A?.enabled ? async function(e, o = 20, r) {
231
236
  const n = {
232
- ...S.filters,
237
+ ...A.filters,
233
238
  ...r
234
239
  };
235
- if (v && v.length > 1) {
236
- const f = v.map(
237
- (h) => fetch(`${C}/search`, {
240
+ if (O && O.length > 1) {
241
+ const a = O.map(
242
+ (h) => fetch(`${w}/search`, {
238
243
  method: "POST",
239
244
  headers: {
240
245
  "Content-Type": "application/json",
241
- ...E.current ? { Authorization: `Bearer ${E.current}` } : {}
246
+ ...C.current ? { Authorization: `Bearer ${C.current}` } : {}
242
247
  },
243
248
  body: JSON.stringify({
244
249
  q: e,
@@ -247,21 +252,21 @@ function dt({
247
252
  ...Object.keys(n).length > 0 ? { filters: n } : {}
248
253
  })
249
254
  }).then((p) => p.ok ? p.json() : null)
250
- ), d = await Promise.all(f), i = [];
255
+ ), d = await Promise.all(a), l = [];
251
256
  for (const h of d)
252
- h?.candidates && i.push(...h.candidates);
253
- i.sort((h, p) => {
254
- const j = h.scores?.rerank || h.scores?.dense || 0;
255
- return (p.scores?.rerank || p.scores?.dense || 0) - j;
257
+ h?.candidates && l.push(...h.candidates);
258
+ l.sort((h, p) => {
259
+ const N = h.scores?.rerank || h.scores?.dense || 0;
260
+ return (p.scores?.rerank || p.scores?.dense || 0) - N;
256
261
  });
257
- const b = i.slice(0, o).map((h, p) => {
258
- const j = h.citation || h.url;
262
+ const b = l.slice(0, o).map((h, p) => {
263
+ const N = h.citation || h.url;
259
264
  return {
260
265
  rank: p + 1,
261
266
  doc_id: h.doc_id,
262
267
  block_id: h.block_id,
263
268
  url: h.url,
264
- citation: j,
269
+ citation: N,
265
270
  title: h.title || "Untitled",
266
271
  snippet: h.snippet,
267
272
  score: h.scores?.rerank || h.scores?.dense || 0,
@@ -275,43 +280,43 @@ function dt({
275
280
  return {
276
281
  success: !0,
277
282
  query: e,
278
- total: i.length,
283
+ total: l.length,
279
284
  results: b,
280
- summary: `Found ${i.length} relevant results across ${v.length} source(s) for "${e}". Top result: ${b[0]?.title || "N/A"}`
285
+ summary: `Found ${l.length} relevant results across ${O.length} source(s) for "${e}". Top result: ${b[0]?.title || "N/A"}`
281
286
  };
282
287
  }
283
- const s = S.organizationId && S.organizationId !== "default" ? S.organizationId : v && v.length > 0 ? v[0] : void 0;
288
+ const s = A.organizationId && A.organizationId !== "default" ? A.organizationId : O && O.length > 0 ? O[0] : void 0;
284
289
  try {
285
- const f = {
290
+ const a = {
286
291
  q: e,
287
292
  k: Math.min(o, 100)
288
293
  };
289
- s && (f.organizationId = s), Object.keys(n).length > 0 && (f.filters = n);
294
+ s && (a.organizationId = s), Object.keys(n).length > 0 && (a.filters = n);
290
295
  const d = {
291
296
  "Content-Type": "application/json"
292
297
  };
293
- E.current && (d.Authorization = `Bearer ${E.current}`);
294
- const i = await fetch(`${C}/search`, {
298
+ C.current && (d.Authorization = `Bearer ${C.current}`);
299
+ const l = await fetch(`${w}/search`, {
295
300
  method: "POST",
296
301
  headers: d,
297
- body: JSON.stringify(f)
302
+ body: JSON.stringify(a)
298
303
  });
299
- if (!i.ok) {
300
- const p = await i.text();
304
+ if (!l.ok) {
305
+ const p = await l.text();
301
306
  return {
302
307
  success: !1,
303
- error: `Search failed: ${i.status} ${p}`
308
+ error: `Search failed: ${l.status} ${p}`
304
309
  };
305
310
  }
306
- const b = await i.json(), h = b.candidates.map(
307
- (p, j) => {
308
- const he = p.citation || p.url;
311
+ const b = await l.json(), h = b.candidates.map(
312
+ (p, N) => {
313
+ const ge = p.citation || p.url;
309
314
  return {
310
- rank: j + 1,
315
+ rank: N + 1,
311
316
  doc_id: p.doc_id,
312
317
  block_id: p.block_id,
313
318
  url: p.url,
314
- citation: he,
319
+ citation: ge,
315
320
  title: p.title || "Untitled",
316
321
  snippet: p.snippet,
317
322
  score: p.scores?.rerank || p.scores?.dense || 0,
@@ -330,20 +335,20 @@ function dt({
330
335
  results: h,
331
336
  summary: `Found ${b.total} relevant results for "${e}". Top result: ${h[0]?.title || "N/A"}`
332
337
  };
333
- } catch (f) {
338
+ } catch (a) {
334
339
  return {
335
340
  success: !1,
336
- error: f instanceof Error ? f.message : "Unknown error occurred"
341
+ error: a instanceof Error ? a.message : "Unknown error occurred"
337
342
  };
338
343
  }
339
- } : null, [S, C, E]), Y = O(() => S?.enabled ? async function(e, o) {
340
- const r = S.organizationId && S.organizationId !== "default" ? S.organizationId : v && v.length > 0 ? v[0] : void 0;
344
+ } : null, [A, w, C]), Y = v(() => A?.enabled ? async function(e, o) {
345
+ const r = A.organizationId && A.organizationId !== "default" ? A.organizationId : O && O.length > 0 ? O[0] : void 0;
341
346
  try {
342
347
  const n = {
343
348
  "Content-Type": "application/json"
344
349
  };
345
- E.current && (n.Authorization = `Bearer ${E.current}`);
346
- const s = await fetch(`${C}/fetch`, {
350
+ C.current && (n.Authorization = `Bearer ${C.current}`);
351
+ const s = await fetch(`${w}/fetch`, {
347
352
  method: "POST",
348
353
  headers: n,
349
354
  body: JSON.stringify({
@@ -359,14 +364,14 @@ function dt({
359
364
  error: `Fetch failed: ${s.status} ${d}`
360
365
  };
361
366
  }
362
- const f = await s.json();
367
+ const a = await s.json();
363
368
  return {
364
369
  success: !0,
365
- blocks: f.blocks || [],
366
- fullContent: f.fullContent || "",
367
- pageUrl: f.pageUrl || "",
368
- pageTitle: f.pageTitle || "",
369
- summary: `Fetched ${f.blocks?.length || 0} blocks from ${f.pageTitle || e}`
370
+ blocks: a.blocks || [],
371
+ fullContent: a.fullContent || "",
372
+ pageUrl: a.pageUrl || "",
373
+ pageTitle: a.pageTitle || "",
374
+ summary: `Fetched ${a.blocks?.length || 0} blocks from ${a.pageTitle || e}`
370
375
  };
371
376
  } catch (n) {
372
377
  return {
@@ -374,37 +379,37 @@ function dt({
374
379
  error: n instanceof Error ? n.message : "Unknown error occurred"
375
380
  };
376
381
  }
377
- } : null, [S, C, E]), fe = O(() => {
378
- if (g && g.config?.tools) {
379
- const t = st(g.config.tools, u);
380
- return A && console.log("[useAgent] Merged remote config:", {
381
- remoteToolCount: g.config.tools.length,
382
- localToolCount: u.length,
382
+ } : null, [A, w, C]), pe = v(() => {
383
+ if (E && E.config?.tools) {
384
+ const t = ut(E.config.tools, f);
385
+ return j && console.log("[useAgent] Merged remote config:", {
386
+ remoteToolCount: E.config.tools.length,
387
+ localToolCount: f.length,
383
388
  mergedToolCount: t.length
384
389
  }), t;
385
390
  }
386
- return u;
387
- }, [g, u]), B = g?.enableRagTools ?? S?.enabled ?? !1, Re = O(() => {
388
- const t = [...fe, ...a];
389
- return B && (V && t.push(V), Y && t.push(Y)), t;
391
+ return f;
392
+ }, [E, f]), J = E?.enableRagTools ?? A?.enabled ?? !1, Ie = v(() => {
393
+ const t = [...pe, ...i];
394
+ return J && (V && t.push(V), Y && t.push(Y)), t;
390
395
  }, [
391
- fe,
392
- a,
396
+ pe,
397
+ i,
393
398
  V,
394
399
  Y,
395
- B
396
- ]), _e = O(
397
- () => [...fe, ...a],
398
- [fe, a]
399
- ), K = O(
400
- () => rt(_e, x),
401
- [_e, x]
402
- ), ne = O(() => {
400
+ J
401
+ ]), Be = v(
402
+ () => [...pe, ...i],
403
+ [pe, i]
404
+ ), K = v(
405
+ () => ct(Be, x),
406
+ [Be, x]
407
+ ), se = v(() => {
403
408
  const t = /* @__PURE__ */ new Map(), e = new Map(K.map((o) => [o.name, o]));
404
- return S?.enabled && (V && t.set("searchDocs", V), Y && t.set("fetchDocContent", Y)), Re.forEach((o) => {
405
- if (o === V || o === Y)
409
+ return A?.enabled && (V && t.set("searchDocs", V), Y && t.set("fetchDocContent", Y)), S && (de && t.set("todo_read", de), he && t.set("todo_write", he)), Ie.forEach((o) => {
410
+ if (o === V || o === Y || o === de || o === he)
406
411
  return;
407
- const r = o[I];
412
+ const r = o[B];
408
413
  if (r) {
409
414
  const s = e.get(r);
410
415
  if (s) {
@@ -416,14 +421,17 @@ function dt({
416
421
  n && t.set(n.name, o);
417
422
  }), t;
418
423
  }, [
419
- Re,
424
+ Ie,
420
425
  K,
421
426
  V,
422
427
  Y,
423
- S
424
- ]), De = O(() => new Set(K.map((t) => t.name)), [K]), Ue = O(() => {
428
+ A,
429
+ S,
430
+ de,
431
+ he
432
+ ]), Je = v(() => new Set(K.map((t) => t.name)), [K]), Pe = v(() => {
425
433
  const t = [];
426
- B && t.push(
434
+ J && t.push(
427
435
  {
428
436
  name: "searchDocs",
429
437
  description: "Search documentation using semantic search. Returns relevant results with snippets and scores. Use this first to find relevant documentation. Default returns 20 results - use higher k values (30-50) when you need to find many sources.",
@@ -475,51 +483,97 @@ function dt({
475
483
  }
476
484
  );
477
485
  const e = [];
478
- return g?.config?.workflows && g.config.workflows.forEach((o) => {
479
- const r = {}, n = [];
480
- o.parameters && o.parameters.forEach((s) => {
481
- r[s.name] = {
482
- type: s.type || "string",
483
- description: s.description
484
- }, s.required && n.push(s.name);
486
+ E?.config?.workflows && E.config.workflows.forEach((r) => {
487
+ const n = {}, s = [];
488
+ r.parameters && r.parameters.forEach((a) => {
489
+ n[a.name] = {
490
+ type: a.type || "string",
491
+ description: a.description
492
+ }, a.required && s.push(a.name);
485
493
  }), e.push({
486
- name: `workflow_${o.name.replace(/\s+/g, "_").toLowerCase()}`,
487
- description: o.description || `Execute the "${o.name}" workflow. ${o.contentPlaintext?.slice(0, 200) || ""}`,
494
+ name: `workflow_${r.name.replace(/\s+/g, "_").toLowerCase()}`,
495
+ description: r.description || `Execute the "${r.name}" workflow. ${r.contentPlaintext?.slice(0, 200) || ""}`,
488
496
  jsonSchema: {
489
497
  type: "object",
490
- properties: r,
491
- required: n
498
+ properties: n,
499
+ required: s
492
500
  },
493
501
  // Store workflow metadata for execution
494
- _workflow: o
502
+ _workflow: r
495
503
  });
496
- }), [...K, ...t, ...e];
497
- }, [K, B, g]), oe = O(() => Ue.filter((t) => t.name === "searchDocs" || t.name === "fetchDocContent" ? B : t.name.startsWith("workflow_") ? !0 : De.has(t.name)), [Ue, De, B]), de = O(() => {
504
+ });
505
+ const o = [];
506
+ return S && o.push(
507
+ {
508
+ name: "todo_read",
509
+ description: "Read the current todo list. Returns all todo items with their status (pending, in_progress, completed).",
510
+ jsonSchema: {
511
+ type: "object",
512
+ properties: {},
513
+ required: []
514
+ }
515
+ },
516
+ {
517
+ name: "todo_write",
518
+ description: "Write/update the todo list. Pass the complete list of todos to replace the current list. Each todo must have id, content, and status (pending, in_progress, completed).",
519
+ jsonSchema: {
520
+ type: "object",
521
+ properties: {
522
+ todoList: {
523
+ type: "array",
524
+ description: "The complete list of todo items",
525
+ items: {
526
+ type: "object",
527
+ properties: {
528
+ id: {
529
+ type: "string",
530
+ description: "Unique identifier for the todo item"
531
+ },
532
+ content: {
533
+ type: "string",
534
+ description: "The content/description of the todo item"
535
+ },
536
+ status: {
537
+ type: "string",
538
+ enum: ["pending", "in_progress", "completed"],
539
+ description: "The current status of the todo item"
540
+ }
541
+ },
542
+ required: ["id", "content", "status"]
543
+ }
544
+ }
545
+ },
546
+ required: ["todoList"]
547
+ }
548
+ }
549
+ ), [...K, ...t, ...e, ...o];
550
+ }, [K, J, E, S]), re = v(() => Pe.filter((t) => t.name === "searchDocs" || t.name === "fetchDocContent" ? J : t.name.startsWith("workflow_") ? !0 : t.name === "todo_read" || t.name === "todo_write" ? S : Je.has(t.name)), [Pe, Je, J, S]), me = v(() => {
498
551
  const t = /* @__PURE__ */ new Set();
499
- return B && S?.autoExecute !== !1 && (t.add("searchDocs"), t.add("fetchDocContent")), g?.config?.tools ? g.config.tools.forEach((e) => {
552
+ return J && A?.autoExecute !== !1 && (t.add("searchDocs"), t.add("fetchDocContent")), S && (t.add("todo_read"), t.add("todo_write")), E?.config?.tools ? E.config.tools.forEach((e) => {
500
553
  e.isEnabled && !e.requiresApproval && t.add(e.name);
501
- }) : (a.forEach((e) => {
502
- for (const [o, r] of ne.entries())
554
+ }) : (i.forEach((e) => {
555
+ for (const [o, r] of se.entries())
503
556
  if (r === e) {
504
557
  t.add(o);
505
558
  break;
506
559
  }
507
- }), T && Array.isArray(T) && T.forEach((e) => {
560
+ }), $ && Array.isArray($) && $.forEach((e) => {
508
561
  typeof e == "string" && t.add(e);
509
- })), g?.config?.workflows && g.config.workflows.forEach((e) => {
562
+ })), E?.config?.workflows && E.config.workflows.forEach((e) => {
510
563
  const o = `workflow_${e.name.replace(/\s+/g, "_").toLowerCase()}`;
511
564
  e.requiresApproval || t.add(o);
512
565
  }), t;
513
566
  }, [
514
- g,
515
- a,
516
- T,
517
- ne,
518
- B,
567
+ E,
568
+ i,
569
+ $,
570
+ se,
571
+ J,
572
+ A,
519
573
  S
520
574
  ]);
521
575
  R(() => {
522
- if (y || m)
576
+ if (g || m)
523
577
  return;
524
578
  let t = !1, e = null;
525
579
  const o = async (r = 1, n = 3) => {
@@ -531,24 +585,24 @@ function dt({
531
585
  "Content-Type": "application/json"
532
586
  },
533
587
  body: JSON.stringify({
534
- user: w
588
+ user: y
535
589
  })
536
590
  });
537
591
  if (!s.ok)
538
592
  throw new Error("Failed to fetch token");
539
- const f = await s.json();
540
- t || (me(f.clientToken), E.current = f.clientToken, ye(f.expiresAt), re(null));
593
+ const a = await s.json();
594
+ t || (be(a.clientToken), C.current = a.clientToken, ke(a.expiresAt), ne(null));
541
595
  } catch (s) {
542
596
  if (console.error(
543
597
  `[useAgent] Token fetch failed (attempt ${r}/${n}):`,
544
598
  s
545
599
  ), r < n && !t) {
546
- const f = Math.pow(2, r - 1) * 1e3;
600
+ const a = Math.pow(2, r - 1) * 1e3;
547
601
  e = setTimeout(
548
602
  () => o(r + 1, n),
549
- f
603
+ a
550
604
  );
551
- } else t || re(
605
+ } else t || ne(
552
606
  s instanceof Error ? s.message : "Failed to fetch token"
553
607
  );
554
608
  }
@@ -556,11 +610,11 @@ function dt({
556
610
  return o(), () => {
557
611
  t = !0, e && clearTimeout(e), H.current && clearTimeout(H.current);
558
612
  };
559
- }, [c, JSON.stringify(w), y, m]), R(() => {
560
- if (!te || y || m)
613
+ }, [c, JSON.stringify(y), g, m]), R(() => {
614
+ if (!oe || g || m)
561
615
  return;
562
616
  H.current && clearTimeout(H.current);
563
- const t = async (s = 1, f = 3) => {
617
+ const t = async (s = 1, a = 3) => {
564
618
  try {
565
619
  const d = await fetch(c, {
566
620
  method: "POST",
@@ -568,26 +622,26 @@ function dt({
568
622
  "Content-Type": "application/json"
569
623
  },
570
624
  body: JSON.stringify({
571
- user: w
625
+ user: y
572
626
  })
573
627
  });
574
628
  if (!d.ok)
575
629
  throw new Error("Failed to refresh token");
576
- const i = await d.json();
577
- me(i.clientToken), E.current = i.clientToken, ye(i.expiresAt), re(null);
630
+ const l = await d.json();
631
+ be(l.clientToken), C.current = l.clientToken, ke(l.expiresAt), ne(null);
578
632
  } catch (d) {
579
633
  if (console.error(
580
- `[useAgent] Token refresh failed (attempt ${s}/${f}):`,
634
+ `[useAgent] Token refresh failed (attempt ${s}/${a}):`,
581
635
  d
582
- ), s < f) {
583
- const i = Math.pow(2, s - 1) * 1e3;
584
- setTimeout(() => t(s + 1, f), i);
636
+ ), s < a) {
637
+ const l = Math.pow(2, s - 1) * 1e3;
638
+ setTimeout(() => t(s + 1, a), l);
585
639
  } else
586
- re(
640
+ ne(
587
641
  d instanceof Error ? d.message : "Failed to refresh token"
588
642
  );
589
643
  }
590
- }, e = Math.floor(Date.now() / 1e3), o = te - e, n = Math.max(0, o - 5);
644
+ }, e = Math.floor(Date.now() / 1e3), o = oe - e, n = Math.max(0, o - 5);
591
645
  return H.current = setTimeout(
592
646
  () => t(),
593
647
  n * 1e3
@@ -595,28 +649,28 @@ function dt({
595
649
  H.current && clearTimeout(H.current);
596
650
  };
597
651
  }, [
598
- te,
652
+ oe,
599
653
  c,
600
- JSON.stringify(w),
601
- y,
654
+ JSON.stringify(y),
655
+ g,
602
656
  m
603
657
  ]), R(() => {
604
- if (y || m)
658
+ if (g || m)
605
659
  return;
606
660
  const t = async () => {
607
661
  if (document.visibilityState !== "visible") return;
608
662
  const e = Math.floor(Date.now() / 1e3);
609
- if (!te || te <= e + 5) {
610
- A && console.log("[useAgent] Tab visible, token expired - refreshing");
663
+ if (!oe || oe <= e + 5) {
664
+ j && console.log("[useAgent] Tab visible, token expired - refreshing");
611
665
  try {
612
666
  const r = await fetch(c, {
613
667
  method: "POST",
614
668
  headers: { "Content-Type": "application/json" },
615
- body: JSON.stringify({ user: w })
669
+ body: JSON.stringify({ user: y })
616
670
  });
617
671
  if (r.ok) {
618
672
  const n = await r.json();
619
- me(n.clientToken), E.current = n.clientToken, ye(n.expiresAt), re(null);
673
+ be(n.clientToken), C.current = n.clientToken, ke(n.expiresAt), ne(null);
620
674
  }
621
675
  } catch (r) {
622
676
  console.error(
@@ -629,43 +683,43 @@ function dt({
629
683
  return document.addEventListener("visibilitychange", t), () => document.removeEventListener("visibilitychange", t);
630
684
  }, [
631
685
  c,
632
- JSON.stringify(w),
633
- te,
634
- y,
686
+ JSON.stringify(y),
687
+ oe,
688
+ g,
635
689
  m
636
690
  ]);
637
- const Pe = async (t, e = {}) => {
691
+ const Ge = async (t, e = {}) => {
638
692
  const o = e.headers ? new Headers(e.headers) : new Headers();
639
693
  return o.delete("user-agent"), o.delete("User-Agent"), fetch(t, { ...e, headers: o });
640
- }, Te = z(null), We = `${C}/chat`, {
641
- messages: J,
642
- sendMessage: Fe,
643
- status: Se,
644
- error: Ee,
645
- stop: qe,
646
- addToolResult: Ae,
647
- setMessages: Ce
648
- } = Ze({
649
- id: we || void 0,
650
- messages: D,
651
- transport: new et({
652
- api: We,
653
- fetch: Pe,
694
+ }, Ce = z(null), He = `${w}/chat`, {
695
+ messages: P,
696
+ sendMessage: Ve,
697
+ status: ve,
698
+ error: je,
699
+ stop: Ye,
700
+ addToolResult: Oe,
701
+ setMessages: Ne
702
+ } = nt({
703
+ id: Te || void 0,
704
+ messages: U,
705
+ transport: new st({
706
+ api: He,
707
+ fetch: Ge,
654
708
  headers: () => {
655
709
  const t = {};
656
- return E.current && (t.Authorization = `Bearer ${E.current}`), t;
710
+ return C.current && (t.Authorization = `Bearer ${C.current}`), t;
657
711
  },
658
712
  body: () => {
659
- const t = oe.map((o) => ({
713
+ const t = re.map((o) => ({
660
714
  name: o.name,
661
715
  description: o.description,
662
716
  inputSchema: o.jsonSchema
663
- })), e = L.current;
717
+ })), e = te.current;
664
718
  return {
665
719
  tools: t,
666
- ...P && { agentId: P },
720
+ ...W && { agentId: W },
667
721
  ...Z && { agentName: Z },
668
- ...q && { ragFilters: q },
722
+ ...L && { ragFilters: L },
669
723
  ...e && { state: e }
670
724
  };
671
725
  }
@@ -674,43 +728,43 @@ function dt({
674
728
  const e = t.messages;
675
729
  if (e[e.length - 1]?.role !== "assistant")
676
730
  return !1;
677
- const n = [...e].reverse().find((f) => f.role === "user")?.id;
678
- if (n && Te.current === n)
731
+ const n = [...e].reverse().find((a) => a.role === "user")?.id;
732
+ if (n && Ce.current === n)
679
733
  return !1;
680
- const s = tt(t);
681
- return s && n && (Te.current = n), s;
734
+ const s = at(t);
735
+ return s && n && (Ce.current = n), s;
682
736
  }
683
- }), Ie = Fe, Le = pe(
684
- (t) => (Te.current = null, ue.current = /* @__PURE__ */ new Set(), Ie(t)),
685
- [Ie]
686
- ), Q = pe(
737
+ }), ze = Ve, Ke = ye(
738
+ (t) => (Ce.current = null, fe.current = /* @__PURE__ */ new Set(), ze(t)),
739
+ [ze]
740
+ ), Q = ye(
687
741
  (t, e, o) => {
688
- Ae({
742
+ Oe({
689
743
  toolCallId: e,
690
744
  tool: t,
691
745
  output: o
692
746
  });
693
747
  },
694
- [Ae]
748
+ [Oe]
695
749
  );
696
750
  R(() => {
697
- J.forEach((t) => {
751
+ P.forEach((t) => {
698
752
  t.role === "assistant" && t.parts.forEach((e) => {
699
753
  if (!e.type?.startsWith("tool-") || e.state !== "input-available") return;
700
754
  const o = e.type.replace("tool-", ""), r = e.toolCallId;
701
- if (le.current.has(r) || $e.current.has(r)) {
702
- A && console.log(
755
+ if (ue.current.has(r) || Ee.current.has(r)) {
756
+ j && console.log(
703
757
  `[useAgent] Skipping ${o} (${r}) - already processing or completed`
704
758
  );
705
759
  return;
706
760
  }
707
- A && console.log(`[useAgent] Starting ${o} (${r})`), le.current.add(r);
761
+ j && console.log(`[useAgent] Starting ${o} (${r})`), ue.current.add(r);
708
762
  const n = (d) => {
709
- A && console.log(`[useAgent] Completed ${o} (${d})`), $e.current.add(d), le.current.delete(d);
710
- }, s = nt(e.input), f = `${o}:${JSON.stringify(s)}`;
711
- if (ue.current.has(f)) {
712
- A && console.log(
713
- `[useAgent] Skipping duplicate tool call: ${f}`
763
+ j && console.log(`[useAgent] Completed ${o} (${d})`), Ee.current.add(d), ue.current.delete(d);
764
+ }, s = lt(e.input), a = `${o}:${JSON.stringify(s)}`;
765
+ if (fe.current.has(a)) {
766
+ j && console.log(
767
+ `[useAgent] Skipping duplicate tool call: ${a}`
714
768
  ), Q(
715
769
  o,
716
770
  r,
@@ -718,50 +772,50 @@ function dt({
718
772
  ), n(r);
719
773
  return;
720
774
  }
721
- if (o.startsWith("workflow_") && de.has(o)) {
775
+ if (o.startsWith("workflow_") && me.has(o)) {
722
776
  (async () => {
723
777
  try {
724
- const i = oe.find(
778
+ const l = re.find(
725
779
  (h) => h.name === o
726
780
  )?._workflow;
727
- if (!i)
781
+ if (!l)
728
782
  throw new Error(`Workflow metadata not found for ${o}`);
729
783
  let b;
730
- if (i.webhook?.url) {
784
+ if (l.webhook?.url) {
731
785
  let h = s;
732
- if (i.webhook.bodyTemplate) {
733
- let j = i.webhook.bodyTemplate;
734
- Object.entries(s).forEach(([he, Xe]) => {
735
- j = j.replace(
736
- new RegExp(`\\{\\{${he}\\}\\}`, "g"),
737
- String(Xe)
786
+ if (l.webhook.bodyTemplate) {
787
+ let N = l.webhook.bodyTemplate;
788
+ Object.entries(s).forEach(([ge, rt]) => {
789
+ N = N.replace(
790
+ new RegExp(`\\{\\{${ge}\\}\\}`, "g"),
791
+ String(rt)
738
792
  );
739
- }), h = JSON.parse(j);
793
+ }), h = JSON.parse(N);
740
794
  }
741
- const p = await fetch(i.webhook.url, {
742
- method: i.webhook.method || "POST",
795
+ const p = await fetch(l.webhook.url, {
796
+ method: l.webhook.method || "POST",
743
797
  headers: {
744
798
  "Content-Type": "application/json",
745
- ...i.webhook.headers || {}
799
+ ...l.webhook.headers || {}
746
800
  },
747
801
  body: JSON.stringify(h)
748
802
  });
749
803
  if (p.ok)
750
804
  b = { success: !0, data: await p.json().catch(() => ({ success: !0 })) };
751
805
  else {
752
- const j = await p.text();
806
+ const N = await p.text();
753
807
  b = {
754
808
  success: !1,
755
- error: `Webhook failed: ${p.status} ${j}`
809
+ error: `Webhook failed: ${p.status} ${N}`
756
810
  };
757
811
  }
758
812
  } else
759
813
  b = {
760
814
  success: !0,
761
- message: `Workflow "${i.name}" acknowledged. Follow the workflow instructions to proceed.`,
762
- instructions: i.contentPlaintext
815
+ message: `Workflow "${l.name}" acknowledged. Follow the workflow instructions to proceed.`,
816
+ instructions: l.contentPlaintext
763
817
  };
764
- n(r), Q(o, r, b), ue.current.add(f);
818
+ n(r), Q(o, r, b), fe.current.add(a);
765
819
  } catch (d) {
766
820
  console.error(
767
821
  `[useAgent] Error executing workflow ${o}:`,
@@ -771,43 +825,43 @@ function dt({
771
825
  })();
772
826
  return;
773
827
  }
774
- if (de.has(o)) {
775
- const d = ne.get(o);
828
+ if (me.has(o)) {
829
+ const d = se.get(o);
776
830
  d ? (async () => {
777
831
  try {
778
- const i = oe.find(
832
+ const l = re.find(
779
833
  (h) => h.name === o
780
834
  );
781
835
  let b;
782
- if (i && i.jsonSchema?.properties) {
836
+ if (l && l.jsonSchema?.properties) {
783
837
  const p = Object.keys(
784
- i.jsonSchema.properties
838
+ l.jsonSchema.properties
785
839
  ).map(
786
- (j) => s[j]
840
+ (N) => s[N]
787
841
  );
788
842
  b = await d(...p);
789
843
  } else
790
844
  b = await d(...Object.values(s));
791
- n(r), Q(o, r, b), ue.current.add(f);
792
- } catch (i) {
845
+ n(r), Q(o, r, b), fe.current.add(a);
846
+ } catch (l) {
793
847
  console.error(
794
848
  `[useAgent] Error executing tool ${o}:`,
795
- i
796
- ), n(r), Q(o, r, `Error: ${i}`);
849
+ l
850
+ ), n(r), Q(o, r, `Error: ${l}`);
797
851
  }
798
- })() : (A && console.warn(`[useAgent] Tool ${o} not found in toolsMap`), Q(
852
+ })() : (j && console.warn(`[useAgent] Tool ${o} not found in toolsMap`), Q(
799
853
  o,
800
854
  r,
801
855
  `Error: Tool "${o}" not found. The tool may not be registered or available.`
802
856
  ), n(r));
803
- } else if (o.startsWith("workflow_") && U)
804
- U({ toolCall: {
857
+ } else if (o.startsWith("workflow_") && I)
858
+ I({ toolCall: {
805
859
  toolCallId: r,
806
860
  toolName: o,
807
861
  args: s
808
862
  } });
809
- else if (U)
810
- U({ toolCall: {
863
+ else if (I)
864
+ I({ toolCall: {
811
865
  toolCallId: r,
812
866
  toolName: o,
813
867
  args: s
@@ -818,116 +872,116 @@ function dt({
818
872
  toolName: o,
819
873
  args: s
820
874
  };
821
- ke((i) => {
822
- const b = new Map(i);
875
+ Se((l) => {
876
+ const b = new Map(l);
823
877
  return b.set(r, d), b;
824
878
  });
825
879
  }
826
880
  });
827
881
  });
828
882
  }, [
829
- J,
830
- de,
831
- ne,
832
- U,
883
+ P,
884
+ me,
885
+ se,
886
+ I,
833
887
  Q,
834
- oe
888
+ re
835
889
  ]), R(() => {
836
- if (Se === "ready" && J.length > 0 && F) {
837
- const t = J[J.length - 1];
890
+ if (ve === "ready" && P.length > 0 && F) {
891
+ const t = P[P.length - 1];
838
892
  t && t.role === "assistant" && F({
839
893
  message: t,
840
- messages: J,
894
+ messages: P,
841
895
  isAbort: !1,
842
896
  isDisconnect: !1,
843
- isError: !!Ee
897
+ isError: !!je
844
898
  });
845
899
  }
846
- }, [Se, J, Ee, F]);
847
- async function Ge() {
848
- if (!(!w?.id || !G)) {
849
- ie(!0);
900
+ }, [ve, P, je, F]);
901
+ async function Qe() {
902
+ if (!(!y?.id || !G)) {
903
+ le(!0);
850
904
  try {
851
- const e = await (await fetch(`${C}/conversations`, {
905
+ const e = await (await fetch(`${w}/conversations`, {
852
906
  headers: {
853
907
  Authorization: `Bearer ${G}`
854
908
  }
855
909
  })).json();
856
- xe(e.conversations || []);
910
+ De(e.conversations || []);
857
911
  } catch (t) {
858
912
  console.error("Failed to fetch conversations:", t);
859
913
  } finally {
860
- ie(!1);
914
+ le(!1);
861
915
  }
862
916
  }
863
917
  }
864
918
  R(() => {
865
- w?.id && G && Ge();
866
- }, [JSON.stringify(w), G, C]);
867
- async function He(t) {
868
- Me(t), ie(!0);
919
+ y?.id && G && Qe();
920
+ }, [JSON.stringify(y), G, w]);
921
+ async function Xe(t) {
922
+ Ue(t), le(!0);
869
923
  try {
870
924
  const e = await fetch(
871
- `${C}/conversations/${t}/messages`,
925
+ `${w}/conversations/${t}/messages`,
872
926
  {
873
927
  headers: {
874
- Authorization: `Bearer ${E.current}`
928
+ Authorization: `Bearer ${C.current}`
875
929
  }
876
930
  }
877
931
  );
878
932
  if (!e.ok)
879
933
  throw new Error(`Failed to fetch messages: ${e.statusText}`);
880
934
  const r = (await e.json()).messages || [];
881
- Ce(r);
935
+ Ne(r);
882
936
  } catch (e) {
883
937
  console.error("Failed to load conversation messages:", e);
884
938
  } finally {
885
- ie(!1);
939
+ le(!1);
886
940
  }
887
941
  }
888
- async function Ve(t) {
942
+ async function Ze(t) {
889
943
  if (G)
890
944
  try {
891
- await fetch(`${C}/conversations/${t}`, {
945
+ await fetch(`${w}/conversations/${t}`, {
892
946
  method: "DELETE",
893
947
  headers: {
894
948
  Authorization: `Bearer ${G}`
895
949
  }
896
- }), xe(Ne.filter((e) => e._id !== t)), t === we && Be();
950
+ }), De(Re.filter((e) => e._id !== t)), t === Te && We();
897
951
  } catch (e) {
898
952
  console.error("Failed to delete conversation:", e);
899
953
  }
900
954
  }
901
- function Be() {
955
+ function We() {
902
956
  const t = crypto.randomUUID();
903
- Me(t), Ce([]), le.current = /* @__PURE__ */ new Set(), $e.current = /* @__PURE__ */ new Set();
957
+ Ue(t), Ne([]), ue.current = /* @__PURE__ */ new Set(), Ee.current = /* @__PURE__ */ new Set();
904
958
  }
905
959
  function X(t) {
906
960
  const e = t.tool || "unknown-tool";
907
- Ae({
961
+ Oe({
908
962
  toolCallId: t.toolCallId,
909
963
  tool: e,
910
964
  output: t.output
911
965
  });
912
966
  }
913
- async function Ye(t, e, o) {
967
+ async function et(t, e, o) {
914
968
  if (!e.startsWith("workflow_"))
915
969
  throw new Error(`${e} is not a workflow tool`);
916
970
  try {
917
- const n = oe.find((f) => f.name === e)?._workflow;
971
+ const n = re.find((a) => a.name === e)?._workflow;
918
972
  if (!n)
919
973
  throw new Error(`Workflow metadata not found for ${e}`);
920
974
  let s;
921
975
  if (n.webhook?.url) {
922
- let f = o;
976
+ let a = o;
923
977
  if (n.webhook.bodyTemplate) {
924
- let i = n.webhook.bodyTemplate;
978
+ let l = n.webhook.bodyTemplate;
925
979
  Object.entries(o).forEach(([b, h]) => {
926
- i = i.replace(
980
+ l = l.replace(
927
981
  new RegExp(`\\{\\{${b}\\}\\}`, "g"),
928
982
  String(h)
929
983
  );
930
- }), f = JSON.parse(i);
984
+ }), a = JSON.parse(l);
931
985
  }
932
986
  const d = await fetch(n.webhook.url, {
933
987
  method: n.webhook.method || "POST",
@@ -935,15 +989,15 @@ function dt({
935
989
  "Content-Type": "application/json",
936
990
  ...n.webhook.headers || {}
937
991
  },
938
- body: JSON.stringify(f)
992
+ body: JSON.stringify(a)
939
993
  });
940
994
  if (d.ok)
941
995
  s = { success: !0, data: await d.json().catch(() => ({ success: !0 })) };
942
996
  else {
943
- const i = await d.text();
997
+ const l = await d.text();
944
998
  s = {
945
999
  success: !1,
946
- error: `Webhook failed: ${d.status} ${i}`
1000
+ error: `Webhook failed: ${d.status} ${l}`
947
1001
  };
948
1002
  }
949
1003
  } else
@@ -958,24 +1012,24 @@ function dt({
958
1012
  throw X({ toolCallId: t, tool: e, output: n }), r;
959
1013
  }
960
1014
  }
961
- async function Ke(t) {
962
- const e = be.get(t);
1015
+ async function tt(t) {
1016
+ const e = $e.get(t);
963
1017
  if (!e) {
964
- A && console.warn(`[useAgent] Tool call ${t} not found in pending approvals`);
1018
+ j && console.warn(`[useAgent] Tool call ${t} not found in pending approvals`);
965
1019
  return;
966
1020
  }
967
- ke((r) => {
1021
+ Se((r) => {
968
1022
  const n = new Map(r);
969
1023
  return n.delete(t), n;
970
1024
  });
971
- const o = ne.get(e.toolName);
1025
+ const o = se.get(e.toolName);
972
1026
  if (o)
973
1027
  try {
974
- const r = oe.find((s) => s.name === e.toolName);
1028
+ const r = re.find((s) => s.name === e.toolName);
975
1029
  let n;
976
1030
  if (r && r.jsonSchema?.properties) {
977
- const f = Object.keys(r.jsonSchema.properties).map((d) => e.args[d]);
978
- n = await o(...f);
1031
+ const a = Object.keys(r.jsonSchema.properties).map((d) => e.args[d]);
1032
+ n = await o(...a);
979
1033
  } else
980
1034
  n = await o(...Object.values(e.args));
981
1035
  X({
@@ -991,19 +1045,19 @@ function dt({
991
1045
  });
992
1046
  }
993
1047
  else
994
- A && console.warn(`[useAgent] Tool ${e.toolName} not found in toolsMap`), X({
1048
+ j && console.warn(`[useAgent] Tool ${e.toolName} not found in toolsMap`), X({
995
1049
  toolCallId: e.toolCallId,
996
1050
  tool: e.toolName,
997
1051
  output: `Error: Tool "${e.toolName}" not found`
998
1052
  });
999
1053
  }
1000
- function Qe(t) {
1001
- const e = be.get(t);
1054
+ function ot(t) {
1055
+ const e = $e.get(t);
1002
1056
  if (!e) {
1003
- A && console.warn(`[useAgent] Tool call ${t} not found in pending approvals`);
1057
+ j && console.warn(`[useAgent] Tool call ${t} not found in pending approvals`);
1004
1058
  return;
1005
1059
  }
1006
- ke((o) => {
1060
+ Se((o) => {
1007
1061
  const r = new Map(o);
1008
1062
  return r.delete(t), r;
1009
1063
  }), X({
@@ -1013,151 +1067,153 @@ function dt({
1013
1067
  });
1014
1068
  }
1015
1069
  return {
1016
- id: we,
1017
- messages: J,
1018
- status: Se,
1019
- error: Ee,
1020
- sendMessage: Le,
1021
- stop: qe,
1070
+ id: Te,
1071
+ messages: P,
1072
+ status: ve,
1073
+ error: je,
1074
+ sendMessage: Ke,
1075
+ stop: Ye,
1022
1076
  addToolOutput: X,
1023
- executeWorkflowTool: Ye,
1077
+ executeWorkflowTool: et,
1024
1078
  // Execute workflow tools that require approval
1025
- setMessages: Ce,
1026
- conversations: Ne,
1027
- loadConversation: He,
1028
- deleteConversation: Ve,
1029
- startNewConversation: Be,
1030
- isLoadingConversations: ze,
1079
+ setMessages: Ne,
1080
+ conversations: Re,
1081
+ loadConversation: Xe,
1082
+ deleteConversation: Ze,
1083
+ startNewConversation: We,
1084
+ isLoadingConversations: Fe,
1031
1085
  clientToken: G,
1032
- tokenError: Je,
1086
+ tokenError: qe,
1033
1087
  // Tool approval management
1034
- pendingToolApprovals: Array.from(be.values()),
1035
- approveToolCall: Ke,
1036
- denyToolCall: Qe,
1088
+ pendingToolApprovals: Array.from($e.values()),
1089
+ approveToolCall: tt,
1090
+ denyToolCall: ot,
1037
1091
  // Tool safety classification (from server config or fallback to props)
1038
- safeToolNames: de
1092
+ safeToolNames: me,
1093
+ // Todo list planning (when planning=true)
1094
+ todos: Ae
1039
1095
  };
1040
1096
  }
1041
- function ht(l = {}) {
1097
+ function wt(u = {}) {
1042
1098
  const {
1043
1099
  apiBaseUrl: c = "https://api.arcten.com",
1044
1100
  tokenEndpoint: m = "/token",
1045
- clientToken: y,
1046
- skipTokenFetch: w = !1
1047
- } = l, [u, a] = N(!1), [T, x] = N(null), M = z(y || null);
1101
+ clientToken: g,
1102
+ skipTokenFetch: y = !1
1103
+ } = u, [f, i] = _(!1), [$, x] = _(null), M = z(g || null);
1048
1104
  R(() => {
1049
- if (y) {
1050
- M.current = y;
1105
+ if (g) {
1106
+ M.current = g;
1051
1107
  return;
1052
1108
  }
1053
- if (w) return;
1109
+ if (y) return;
1054
1110
  (async () => {
1055
1111
  try {
1056
- const $ = await fetch(`${c}${m}`, {
1112
+ const T = await fetch(`${c}${m}`, {
1057
1113
  method: "POST",
1058
1114
  headers: { "Content-Type": "application/json" }
1059
1115
  });
1060
- if ($.ok) {
1061
- const k = await $.json();
1116
+ if (T.ok) {
1117
+ const k = await T.json();
1062
1118
  M.current = k.token;
1063
1119
  }
1064
- } catch ($) {
1065
- console.error("[useGenerate] Failed to fetch token:", $);
1120
+ } catch (T) {
1121
+ console.error("[useGenerate] Failed to fetch token:", T);
1066
1122
  }
1067
1123
  })();
1068
- }, [c, m, y, w]);
1069
- const P = pe(
1070
- async (_) => {
1071
- a(!0), x(null);
1124
+ }, [c, m, g, y]);
1125
+ const W = ye(
1126
+ async (D) => {
1127
+ i(!0), x(null);
1072
1128
  try {
1073
- const $ = {
1129
+ const T = {
1074
1130
  "Content-Type": "application/json"
1075
1131
  };
1076
- M.current && ($.Authorization = `Bearer ${M.current}`);
1132
+ M.current && (T.Authorization = `Bearer ${M.current}`);
1077
1133
  const k = await fetch(`${c}/generate`, {
1078
1134
  method: "POST",
1079
- headers: $,
1080
- body: JSON.stringify(_)
1135
+ headers: T,
1136
+ body: JSON.stringify(D)
1081
1137
  });
1082
1138
  if (!k.ok) {
1083
1139
  const ee = await k.json().catch(() => ({}));
1084
1140
  throw new Error(ee.error || `HTTP ${k.status}`);
1085
1141
  }
1086
1142
  return await k.json();
1087
- } catch ($) {
1088
- const k = $ instanceof Error ? $.message : String($);
1089
- throw x(k), $;
1143
+ } catch (T) {
1144
+ const k = T instanceof Error ? T.message : String(T);
1145
+ throw x(k), T;
1090
1146
  } finally {
1091
- a(!1);
1147
+ i(!1);
1092
1148
  }
1093
1149
  },
1094
1150
  [c]
1095
- ), Z = pe(
1096
- async (_, $) => {
1097
- a(!0), x(null);
1151
+ ), Z = ye(
1152
+ async (D, T) => {
1153
+ i(!0), x(null);
1098
1154
  try {
1099
1155
  const k = {
1100
1156
  "Content-Type": "application/json"
1101
1157
  };
1102
1158
  M.current && (k.Authorization = `Bearer ${M.current}`);
1103
- const D = await fetch(`${c}/generate/stream`, {
1159
+ const U = await fetch(`${c}/generate/stream`, {
1104
1160
  method: "POST",
1105
1161
  headers: k,
1106
- body: JSON.stringify(_)
1162
+ body: JSON.stringify(D)
1107
1163
  });
1108
- if (!D.ok) {
1109
- const F = await D.json().catch(() => ({}));
1110
- throw new Error(F.error || `HTTP ${D.status}`);
1164
+ if (!U.ok) {
1165
+ const F = await U.json().catch(() => ({}));
1166
+ throw new Error(F.error || `HTTP ${U.status}`);
1111
1167
  }
1112
- const ee = D.body?.getReader();
1168
+ const ee = U.body?.getReader();
1113
1169
  if (!ee)
1114
1170
  throw new Error("No response body");
1115
- const W = new TextDecoder();
1116
- let U = null;
1171
+ const q = new TextDecoder();
1172
+ let I = null;
1117
1173
  for (; ; ) {
1118
- const { done: F, value: v } = await ee.read();
1174
+ const { done: F, value: O } = await ee.read();
1119
1175
  if (F) break;
1120
- const q = W.decode(v, { stream: !0 }).split(`
1121
- `).filter((L) => L.startsWith("data: "));
1122
- for (const L of q) {
1123
- const C = L.slice(6).trim();
1124
- if (C)
1176
+ const L = q.decode(O, { stream: !0 }).split(`
1177
+ `).filter((S) => S.startsWith("data: "));
1178
+ for (const S of L) {
1179
+ const te = S.slice(6).trim();
1180
+ if (te)
1125
1181
  try {
1126
- const g = JSON.parse(C);
1127
- if (g.error)
1128
- throw new Error(g.error);
1129
- g.done && g.object ? U = {
1130
- object: g.object,
1131
- usage: g.usage,
1132
- finishReason: g.finishReason
1133
- } : g.partial && $ && $(g.partial);
1182
+ const w = JSON.parse(te);
1183
+ if (w.error)
1184
+ throw new Error(w.error);
1185
+ w.done && w.object ? I = {
1186
+ object: w.object,
1187
+ usage: w.usage,
1188
+ finishReason: w.finishReason
1189
+ } : w.partial && T && T(w.partial);
1134
1190
  } catch {
1135
1191
  }
1136
1192
  }
1137
1193
  }
1138
- if (!U)
1194
+ if (!I)
1139
1195
  throw new Error("Stream ended without final result");
1140
- return U;
1196
+ return I;
1141
1197
  } catch (k) {
1142
- const D = k instanceof Error ? k.message : String(k);
1143
- throw x(D), k;
1198
+ const U = k instanceof Error ? k.message : String(k);
1199
+ throw x(U), k;
1144
1200
  } finally {
1145
- a(!1);
1201
+ i(!1);
1146
1202
  }
1147
1203
  },
1148
1204
  [c]
1149
1205
  );
1150
1206
  return {
1151
- generate: P,
1207
+ generate: W,
1152
1208
  streamGenerate: Z,
1153
- isLoading: u,
1154
- error: T
1209
+ isLoading: f,
1210
+ error: $
1155
1211
  };
1156
1212
  }
1157
1213
  export {
1158
- I as ARCTEN_ORIGINAL_NAME,
1159
- rt as extractToolsMetadata,
1160
- ft as preserveToolName,
1161
- dt as useAgent,
1162
- ht as useGenerate
1214
+ B as ARCTEN_ORIGINAL_NAME,
1215
+ ct as extractToolsMetadata,
1216
+ gt as preserveToolName,
1217
+ yt as useAgent,
1218
+ wt as useGenerate
1163
1219
  };