@arcteninc/core 0.0.177 → 0.0.179

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 S = c[y];
13
+ if (S && !m.has(S.name))
14
+ return { fn: u, meta: S };
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 S of g)
22
+ if (!m.has(S) && (i = c[S], 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 S = f.name, M = f[B] || S || "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: S,
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: $ = !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(() => $ ? async function() {
232
+ return { todos: Ae };
233
+ } : null, [$, Ae]), he = v(() => $ ? async function(e) {
234
+ return Le(e), { success: !0, todos: e };
235
+ } : null, [$]), 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)), $ && (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
+ $,
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 $ && 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, $]), 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" ? $ : Je.has(t.name)), [Pe, Je, J, $]), 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")), $ && (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
+ }), S && Array.isArray(S) && S.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,
519
- S
567
+ E,
568
+ i,
569
+ S,
570
+ se,
571
+ J,
572
+ A,
573
+ $
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,44 +683,45 @@ 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 },
669
- ...e && { state: e }
722
+ ...L && { ragFilters: L },
723
+ ...e && { state: e },
724
+ ...$ && { planning: !0 }
670
725
  };
671
726
  }
672
727
  }),
@@ -674,43 +729,43 @@ function dt({
674
729
  const e = t.messages;
675
730
  if (e[e.length - 1]?.role !== "assistant")
676
731
  return !1;
677
- const n = [...e].reverse().find((f) => f.role === "user")?.id;
678
- if (n && Te.current === n)
732
+ const n = [...e].reverse().find((a) => a.role === "user")?.id;
733
+ if (n && Ce.current === n)
679
734
  return !1;
680
- const s = tt(t);
681
- return s && n && (Te.current = n), s;
735
+ const s = at(t);
736
+ return s && n && (Ce.current = n), s;
682
737
  }
683
- }), Ie = Fe, Le = pe(
684
- (t) => (Te.current = null, ue.current = /* @__PURE__ */ new Set(), Ie(t)),
685
- [Ie]
686
- ), Q = pe(
738
+ }), ze = Ve, Ke = ye(
739
+ (t) => (Ce.current = null, fe.current = /* @__PURE__ */ new Set(), ze(t)),
740
+ [ze]
741
+ ), Q = ye(
687
742
  (t, e, o) => {
688
- Ae({
743
+ Oe({
689
744
  toolCallId: e,
690
745
  tool: t,
691
746
  output: o
692
747
  });
693
748
  },
694
- [Ae]
749
+ [Oe]
695
750
  );
696
751
  R(() => {
697
- J.forEach((t) => {
752
+ P.forEach((t) => {
698
753
  t.role === "assistant" && t.parts.forEach((e) => {
699
754
  if (!e.type?.startsWith("tool-") || e.state !== "input-available") return;
700
755
  const o = e.type.replace("tool-", ""), r = e.toolCallId;
701
- if (le.current.has(r) || $e.current.has(r)) {
702
- A && console.log(
756
+ if (ue.current.has(r) || Ee.current.has(r)) {
757
+ j && console.log(
703
758
  `[useAgent] Skipping ${o} (${r}) - already processing or completed`
704
759
  );
705
760
  return;
706
761
  }
707
- A && console.log(`[useAgent] Starting ${o} (${r})`), le.current.add(r);
762
+ j && console.log(`[useAgent] Starting ${o} (${r})`), ue.current.add(r);
708
763
  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}`
764
+ j && console.log(`[useAgent] Completed ${o} (${d})`), Ee.current.add(d), ue.current.delete(d);
765
+ }, s = lt(e.input), a = `${o}:${JSON.stringify(s)}`;
766
+ if (fe.current.has(a)) {
767
+ j && console.log(
768
+ `[useAgent] Skipping duplicate tool call: ${a}`
714
769
  ), Q(
715
770
  o,
716
771
  r,
@@ -718,50 +773,50 @@ function dt({
718
773
  ), n(r);
719
774
  return;
720
775
  }
721
- if (o.startsWith("workflow_") && de.has(o)) {
776
+ if (o.startsWith("workflow_") && me.has(o)) {
722
777
  (async () => {
723
778
  try {
724
- const i = oe.find(
779
+ const l = re.find(
725
780
  (h) => h.name === o
726
781
  )?._workflow;
727
- if (!i)
782
+ if (!l)
728
783
  throw new Error(`Workflow metadata not found for ${o}`);
729
784
  let b;
730
- if (i.webhook?.url) {
785
+ if (l.webhook?.url) {
731
786
  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)
787
+ if (l.webhook.bodyTemplate) {
788
+ let N = l.webhook.bodyTemplate;
789
+ Object.entries(s).forEach(([ge, rt]) => {
790
+ N = N.replace(
791
+ new RegExp(`\\{\\{${ge}\\}\\}`, "g"),
792
+ String(rt)
738
793
  );
739
- }), h = JSON.parse(j);
794
+ }), h = JSON.parse(N);
740
795
  }
741
- const p = await fetch(i.webhook.url, {
742
- method: i.webhook.method || "POST",
796
+ const p = await fetch(l.webhook.url, {
797
+ method: l.webhook.method || "POST",
743
798
  headers: {
744
799
  "Content-Type": "application/json",
745
- ...i.webhook.headers || {}
800
+ ...l.webhook.headers || {}
746
801
  },
747
802
  body: JSON.stringify(h)
748
803
  });
749
804
  if (p.ok)
750
805
  b = { success: !0, data: await p.json().catch(() => ({ success: !0 })) };
751
806
  else {
752
- const j = await p.text();
807
+ const N = await p.text();
753
808
  b = {
754
809
  success: !1,
755
- error: `Webhook failed: ${p.status} ${j}`
810
+ error: `Webhook failed: ${p.status} ${N}`
756
811
  };
757
812
  }
758
813
  } else
759
814
  b = {
760
815
  success: !0,
761
- message: `Workflow "${i.name}" acknowledged. Follow the workflow instructions to proceed.`,
762
- instructions: i.contentPlaintext
816
+ message: `Workflow "${l.name}" acknowledged. Follow the workflow instructions to proceed.`,
817
+ instructions: l.contentPlaintext
763
818
  };
764
- n(r), Q(o, r, b), ue.current.add(f);
819
+ n(r), Q(o, r, b), fe.current.add(a);
765
820
  } catch (d) {
766
821
  console.error(
767
822
  `[useAgent] Error executing workflow ${o}:`,
@@ -771,43 +826,43 @@ function dt({
771
826
  })();
772
827
  return;
773
828
  }
774
- if (de.has(o)) {
775
- const d = ne.get(o);
829
+ if (me.has(o)) {
830
+ const d = se.get(o);
776
831
  d ? (async () => {
777
832
  try {
778
- const i = oe.find(
833
+ const l = re.find(
779
834
  (h) => h.name === o
780
835
  );
781
836
  let b;
782
- if (i && i.jsonSchema?.properties) {
837
+ if (l && l.jsonSchema?.properties) {
783
838
  const p = Object.keys(
784
- i.jsonSchema.properties
839
+ l.jsonSchema.properties
785
840
  ).map(
786
- (j) => s[j]
841
+ (N) => s[N]
787
842
  );
788
843
  b = await d(...p);
789
844
  } else
790
845
  b = await d(...Object.values(s));
791
- n(r), Q(o, r, b), ue.current.add(f);
792
- } catch (i) {
846
+ n(r), Q(o, r, b), fe.current.add(a);
847
+ } catch (l) {
793
848
  console.error(
794
849
  `[useAgent] Error executing tool ${o}:`,
795
- i
796
- ), n(r), Q(o, r, `Error: ${i}`);
850
+ l
851
+ ), n(r), Q(o, r, `Error: ${l}`);
797
852
  }
798
- })() : (A && console.warn(`[useAgent] Tool ${o} not found in toolsMap`), Q(
853
+ })() : (j && console.warn(`[useAgent] Tool ${o} not found in toolsMap`), Q(
799
854
  o,
800
855
  r,
801
856
  `Error: Tool "${o}" not found. The tool may not be registered or available.`
802
857
  ), n(r));
803
- } else if (o.startsWith("workflow_") && U)
804
- U({ toolCall: {
858
+ } else if (o.startsWith("workflow_") && I)
859
+ I({ toolCall: {
805
860
  toolCallId: r,
806
861
  toolName: o,
807
862
  args: s
808
863
  } });
809
- else if (U)
810
- U({ toolCall: {
864
+ else if (I)
865
+ I({ toolCall: {
811
866
  toolCallId: r,
812
867
  toolName: o,
813
868
  args: s
@@ -818,116 +873,116 @@ function dt({
818
873
  toolName: o,
819
874
  args: s
820
875
  };
821
- ke((i) => {
822
- const b = new Map(i);
876
+ Se((l) => {
877
+ const b = new Map(l);
823
878
  return b.set(r, d), b;
824
879
  });
825
880
  }
826
881
  });
827
882
  });
828
883
  }, [
829
- J,
830
- de,
831
- ne,
832
- U,
884
+ P,
885
+ me,
886
+ se,
887
+ I,
833
888
  Q,
834
- oe
889
+ re
835
890
  ]), R(() => {
836
- if (Se === "ready" && J.length > 0 && F) {
837
- const t = J[J.length - 1];
891
+ if (ve === "ready" && P.length > 0 && F) {
892
+ const t = P[P.length - 1];
838
893
  t && t.role === "assistant" && F({
839
894
  message: t,
840
- messages: J,
895
+ messages: P,
841
896
  isAbort: !1,
842
897
  isDisconnect: !1,
843
- isError: !!Ee
898
+ isError: !!je
844
899
  });
845
900
  }
846
- }, [Se, J, Ee, F]);
847
- async function Ge() {
848
- if (!(!w?.id || !G)) {
849
- ie(!0);
901
+ }, [ve, P, je, F]);
902
+ async function Qe() {
903
+ if (!(!y?.id || !G)) {
904
+ le(!0);
850
905
  try {
851
- const e = await (await fetch(`${C}/conversations`, {
906
+ const e = await (await fetch(`${w}/conversations`, {
852
907
  headers: {
853
908
  Authorization: `Bearer ${G}`
854
909
  }
855
910
  })).json();
856
- xe(e.conversations || []);
911
+ De(e.conversations || []);
857
912
  } catch (t) {
858
913
  console.error("Failed to fetch conversations:", t);
859
914
  } finally {
860
- ie(!1);
915
+ le(!1);
861
916
  }
862
917
  }
863
918
  }
864
919
  R(() => {
865
- w?.id && G && Ge();
866
- }, [JSON.stringify(w), G, C]);
867
- async function He(t) {
868
- Me(t), ie(!0);
920
+ y?.id && G && Qe();
921
+ }, [JSON.stringify(y), G, w]);
922
+ async function Xe(t) {
923
+ Ue(t), le(!0);
869
924
  try {
870
925
  const e = await fetch(
871
- `${C}/conversations/${t}/messages`,
926
+ `${w}/conversations/${t}/messages`,
872
927
  {
873
928
  headers: {
874
- Authorization: `Bearer ${E.current}`
929
+ Authorization: `Bearer ${C.current}`
875
930
  }
876
931
  }
877
932
  );
878
933
  if (!e.ok)
879
934
  throw new Error(`Failed to fetch messages: ${e.statusText}`);
880
935
  const r = (await e.json()).messages || [];
881
- Ce(r);
936
+ Ne(r);
882
937
  } catch (e) {
883
938
  console.error("Failed to load conversation messages:", e);
884
939
  } finally {
885
- ie(!1);
940
+ le(!1);
886
941
  }
887
942
  }
888
- async function Ve(t) {
943
+ async function Ze(t) {
889
944
  if (G)
890
945
  try {
891
- await fetch(`${C}/conversations/${t}`, {
946
+ await fetch(`${w}/conversations/${t}`, {
892
947
  method: "DELETE",
893
948
  headers: {
894
949
  Authorization: `Bearer ${G}`
895
950
  }
896
- }), xe(Ne.filter((e) => e._id !== t)), t === we && Be();
951
+ }), De(Re.filter((e) => e._id !== t)), t === Te && We();
897
952
  } catch (e) {
898
953
  console.error("Failed to delete conversation:", e);
899
954
  }
900
955
  }
901
- function Be() {
956
+ function We() {
902
957
  const t = crypto.randomUUID();
903
- Me(t), Ce([]), le.current = /* @__PURE__ */ new Set(), $e.current = /* @__PURE__ */ new Set();
958
+ Ue(t), Ne([]), ue.current = /* @__PURE__ */ new Set(), Ee.current = /* @__PURE__ */ new Set();
904
959
  }
905
960
  function X(t) {
906
961
  const e = t.tool || "unknown-tool";
907
- Ae({
962
+ Oe({
908
963
  toolCallId: t.toolCallId,
909
964
  tool: e,
910
965
  output: t.output
911
966
  });
912
967
  }
913
- async function Ye(t, e, o) {
968
+ async function et(t, e, o) {
914
969
  if (!e.startsWith("workflow_"))
915
970
  throw new Error(`${e} is not a workflow tool`);
916
971
  try {
917
- const n = oe.find((f) => f.name === e)?._workflow;
972
+ const n = re.find((a) => a.name === e)?._workflow;
918
973
  if (!n)
919
974
  throw new Error(`Workflow metadata not found for ${e}`);
920
975
  let s;
921
976
  if (n.webhook?.url) {
922
- let f = o;
977
+ let a = o;
923
978
  if (n.webhook.bodyTemplate) {
924
- let i = n.webhook.bodyTemplate;
979
+ let l = n.webhook.bodyTemplate;
925
980
  Object.entries(o).forEach(([b, h]) => {
926
- i = i.replace(
981
+ l = l.replace(
927
982
  new RegExp(`\\{\\{${b}\\}\\}`, "g"),
928
983
  String(h)
929
984
  );
930
- }), f = JSON.parse(i);
985
+ }), a = JSON.parse(l);
931
986
  }
932
987
  const d = await fetch(n.webhook.url, {
933
988
  method: n.webhook.method || "POST",
@@ -935,15 +990,15 @@ function dt({
935
990
  "Content-Type": "application/json",
936
991
  ...n.webhook.headers || {}
937
992
  },
938
- body: JSON.stringify(f)
993
+ body: JSON.stringify(a)
939
994
  });
940
995
  if (d.ok)
941
996
  s = { success: !0, data: await d.json().catch(() => ({ success: !0 })) };
942
997
  else {
943
- const i = await d.text();
998
+ const l = await d.text();
944
999
  s = {
945
1000
  success: !1,
946
- error: `Webhook failed: ${d.status} ${i}`
1001
+ error: `Webhook failed: ${d.status} ${l}`
947
1002
  };
948
1003
  }
949
1004
  } else
@@ -958,24 +1013,24 @@ function dt({
958
1013
  throw X({ toolCallId: t, tool: e, output: n }), r;
959
1014
  }
960
1015
  }
961
- async function Ke(t) {
962
- const e = be.get(t);
1016
+ async function tt(t) {
1017
+ const e = $e.get(t);
963
1018
  if (!e) {
964
- A && console.warn(`[useAgent] Tool call ${t} not found in pending approvals`);
1019
+ j && console.warn(`[useAgent] Tool call ${t} not found in pending approvals`);
965
1020
  return;
966
1021
  }
967
- ke((r) => {
1022
+ Se((r) => {
968
1023
  const n = new Map(r);
969
1024
  return n.delete(t), n;
970
1025
  });
971
- const o = ne.get(e.toolName);
1026
+ const o = se.get(e.toolName);
972
1027
  if (o)
973
1028
  try {
974
- const r = oe.find((s) => s.name === e.toolName);
1029
+ const r = re.find((s) => s.name === e.toolName);
975
1030
  let n;
976
1031
  if (r && r.jsonSchema?.properties) {
977
- const f = Object.keys(r.jsonSchema.properties).map((d) => e.args[d]);
978
- n = await o(...f);
1032
+ const a = Object.keys(r.jsonSchema.properties).map((d) => e.args[d]);
1033
+ n = await o(...a);
979
1034
  } else
980
1035
  n = await o(...Object.values(e.args));
981
1036
  X({
@@ -991,19 +1046,19 @@ function dt({
991
1046
  });
992
1047
  }
993
1048
  else
994
- A && console.warn(`[useAgent] Tool ${e.toolName} not found in toolsMap`), X({
1049
+ j && console.warn(`[useAgent] Tool ${e.toolName} not found in toolsMap`), X({
995
1050
  toolCallId: e.toolCallId,
996
1051
  tool: e.toolName,
997
1052
  output: `Error: Tool "${e.toolName}" not found`
998
1053
  });
999
1054
  }
1000
- function Qe(t) {
1001
- const e = be.get(t);
1055
+ function ot(t) {
1056
+ const e = $e.get(t);
1002
1057
  if (!e) {
1003
- A && console.warn(`[useAgent] Tool call ${t} not found in pending approvals`);
1058
+ j && console.warn(`[useAgent] Tool call ${t} not found in pending approvals`);
1004
1059
  return;
1005
1060
  }
1006
- ke((o) => {
1061
+ Se((o) => {
1007
1062
  const r = new Map(o);
1008
1063
  return r.delete(t), r;
1009
1064
  }), X({
@@ -1013,151 +1068,153 @@ function dt({
1013
1068
  });
1014
1069
  }
1015
1070
  return {
1016
- id: we,
1017
- messages: J,
1018
- status: Se,
1019
- error: Ee,
1020
- sendMessage: Le,
1021
- stop: qe,
1071
+ id: Te,
1072
+ messages: P,
1073
+ status: ve,
1074
+ error: je,
1075
+ sendMessage: Ke,
1076
+ stop: Ye,
1022
1077
  addToolOutput: X,
1023
- executeWorkflowTool: Ye,
1078
+ executeWorkflowTool: et,
1024
1079
  // Execute workflow tools that require approval
1025
- setMessages: Ce,
1026
- conversations: Ne,
1027
- loadConversation: He,
1028
- deleteConversation: Ve,
1029
- startNewConversation: Be,
1030
- isLoadingConversations: ze,
1080
+ setMessages: Ne,
1081
+ conversations: Re,
1082
+ loadConversation: Xe,
1083
+ deleteConversation: Ze,
1084
+ startNewConversation: We,
1085
+ isLoadingConversations: Fe,
1031
1086
  clientToken: G,
1032
- tokenError: Je,
1087
+ tokenError: qe,
1033
1088
  // Tool approval management
1034
- pendingToolApprovals: Array.from(be.values()),
1035
- approveToolCall: Ke,
1036
- denyToolCall: Qe,
1089
+ pendingToolApprovals: Array.from($e.values()),
1090
+ approveToolCall: tt,
1091
+ denyToolCall: ot,
1037
1092
  // Tool safety classification (from server config or fallback to props)
1038
- safeToolNames: de
1093
+ safeToolNames: me,
1094
+ // Todo list planning (when planning=true)
1095
+ todos: Ae
1039
1096
  };
1040
1097
  }
1041
- function ht(l = {}) {
1098
+ function wt(u = {}) {
1042
1099
  const {
1043
1100
  apiBaseUrl: c = "https://api.arcten.com",
1044
1101
  tokenEndpoint: m = "/token",
1045
- clientToken: y,
1046
- skipTokenFetch: w = !1
1047
- } = l, [u, a] = N(!1), [T, x] = N(null), M = z(y || null);
1102
+ clientToken: g,
1103
+ skipTokenFetch: y = !1
1104
+ } = u, [f, i] = _(!1), [S, x] = _(null), M = z(g || null);
1048
1105
  R(() => {
1049
- if (y) {
1050
- M.current = y;
1106
+ if (g) {
1107
+ M.current = g;
1051
1108
  return;
1052
1109
  }
1053
- if (w) return;
1110
+ if (y) return;
1054
1111
  (async () => {
1055
1112
  try {
1056
- const $ = await fetch(`${c}${m}`, {
1113
+ const T = await fetch(`${c}${m}`, {
1057
1114
  method: "POST",
1058
1115
  headers: { "Content-Type": "application/json" }
1059
1116
  });
1060
- if ($.ok) {
1061
- const k = await $.json();
1117
+ if (T.ok) {
1118
+ const k = await T.json();
1062
1119
  M.current = k.token;
1063
1120
  }
1064
- } catch ($) {
1065
- console.error("[useGenerate] Failed to fetch token:", $);
1121
+ } catch (T) {
1122
+ console.error("[useGenerate] Failed to fetch token:", T);
1066
1123
  }
1067
1124
  })();
1068
- }, [c, m, y, w]);
1069
- const P = pe(
1070
- async (_) => {
1071
- a(!0), x(null);
1125
+ }, [c, m, g, y]);
1126
+ const W = ye(
1127
+ async (D) => {
1128
+ i(!0), x(null);
1072
1129
  try {
1073
- const $ = {
1130
+ const T = {
1074
1131
  "Content-Type": "application/json"
1075
1132
  };
1076
- M.current && ($.Authorization = `Bearer ${M.current}`);
1133
+ M.current && (T.Authorization = `Bearer ${M.current}`);
1077
1134
  const k = await fetch(`${c}/generate`, {
1078
1135
  method: "POST",
1079
- headers: $,
1080
- body: JSON.stringify(_)
1136
+ headers: T,
1137
+ body: JSON.stringify(D)
1081
1138
  });
1082
1139
  if (!k.ok) {
1083
1140
  const ee = await k.json().catch(() => ({}));
1084
1141
  throw new Error(ee.error || `HTTP ${k.status}`);
1085
1142
  }
1086
1143
  return await k.json();
1087
- } catch ($) {
1088
- const k = $ instanceof Error ? $.message : String($);
1089
- throw x(k), $;
1144
+ } catch (T) {
1145
+ const k = T instanceof Error ? T.message : String(T);
1146
+ throw x(k), T;
1090
1147
  } finally {
1091
- a(!1);
1148
+ i(!1);
1092
1149
  }
1093
1150
  },
1094
1151
  [c]
1095
- ), Z = pe(
1096
- async (_, $) => {
1097
- a(!0), x(null);
1152
+ ), Z = ye(
1153
+ async (D, T) => {
1154
+ i(!0), x(null);
1098
1155
  try {
1099
1156
  const k = {
1100
1157
  "Content-Type": "application/json"
1101
1158
  };
1102
1159
  M.current && (k.Authorization = `Bearer ${M.current}`);
1103
- const D = await fetch(`${c}/generate/stream`, {
1160
+ const U = await fetch(`${c}/generate/stream`, {
1104
1161
  method: "POST",
1105
1162
  headers: k,
1106
- body: JSON.stringify(_)
1163
+ body: JSON.stringify(D)
1107
1164
  });
1108
- if (!D.ok) {
1109
- const F = await D.json().catch(() => ({}));
1110
- throw new Error(F.error || `HTTP ${D.status}`);
1165
+ if (!U.ok) {
1166
+ const F = await U.json().catch(() => ({}));
1167
+ throw new Error(F.error || `HTTP ${U.status}`);
1111
1168
  }
1112
- const ee = D.body?.getReader();
1169
+ const ee = U.body?.getReader();
1113
1170
  if (!ee)
1114
1171
  throw new Error("No response body");
1115
- const W = new TextDecoder();
1116
- let U = null;
1172
+ const q = new TextDecoder();
1173
+ let I = null;
1117
1174
  for (; ; ) {
1118
- const { done: F, value: v } = await ee.read();
1175
+ const { done: F, value: O } = await ee.read();
1119
1176
  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)
1177
+ const L = q.decode(O, { stream: !0 }).split(`
1178
+ `).filter(($) => $.startsWith("data: "));
1179
+ for (const $ of L) {
1180
+ const te = $.slice(6).trim();
1181
+ if (te)
1125
1182
  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);
1183
+ const w = JSON.parse(te);
1184
+ if (w.error)
1185
+ throw new Error(w.error);
1186
+ w.done && w.object ? I = {
1187
+ object: w.object,
1188
+ usage: w.usage,
1189
+ finishReason: w.finishReason
1190
+ } : w.partial && T && T(w.partial);
1134
1191
  } catch {
1135
1192
  }
1136
1193
  }
1137
1194
  }
1138
- if (!U)
1195
+ if (!I)
1139
1196
  throw new Error("Stream ended without final result");
1140
- return U;
1197
+ return I;
1141
1198
  } catch (k) {
1142
- const D = k instanceof Error ? k.message : String(k);
1143
- throw x(D), k;
1199
+ const U = k instanceof Error ? k.message : String(k);
1200
+ throw x(U), k;
1144
1201
  } finally {
1145
- a(!1);
1202
+ i(!1);
1146
1203
  }
1147
1204
  },
1148
1205
  [c]
1149
1206
  );
1150
1207
  return {
1151
- generate: P,
1208
+ generate: W,
1152
1209
  streamGenerate: Z,
1153
- isLoading: u,
1154
- error: T
1210
+ isLoading: f,
1211
+ error: S
1155
1212
  };
1156
1213
  }
1157
1214
  export {
1158
- I as ARCTEN_ORIGINAL_NAME,
1159
- rt as extractToolsMetadata,
1160
- ft as preserveToolName,
1161
- dt as useAgent,
1162
- ht as useGenerate
1215
+ B as ARCTEN_ORIGINAL_NAME,
1216
+ ct as extractToolsMetadata,
1217
+ gt as preserveToolName,
1218
+ yt as useAgent,
1219
+ wt as useGenerate
1163
1220
  };