@personaai/react 0.11.0 → 0.15.0

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.cjs CHANGED
@@ -35,7 +35,9 @@ __export(index_exports, {
35
35
  useChat: () => useChat,
36
36
  useConnection: () => useConnection,
37
37
  useFiles: () => useFiles,
38
+ useKnowledgeBases: () => useKnowledgeBases,
38
39
  useMcp: () => useMcp,
40
+ useMcpAdmin: () => useMcpAdmin,
39
41
  useMcpConnections: () => useMcpConnections,
40
42
  useMemory: () => useMemory,
41
43
  usePersonaContext: () => usePersonaContext,
@@ -46,7 +48,8 @@ __export(index_exports, {
46
48
  useWorkflow: () => useWorkflow,
47
49
  useWorkflowRuns: () => useWorkflowRuns,
48
50
  useWorkflowStream: () => useWorkflowStream,
49
- useWorkflows: () => useWorkflows
51
+ useWorkflows: () => useWorkflows,
52
+ useWorkspaceFiles: () => useWorkspaceFiles
50
53
  });
51
54
  module.exports = __toCommonJS(index_exports);
52
55
 
@@ -1941,8 +1944,110 @@ function useThreads(autoFetch = true) {
1941
1944
  };
1942
1945
  }
1943
1946
 
1944
- // src/hooks/useVoice.ts
1947
+ // src/hooks/useWorkspaceFiles.ts
1945
1948
  var import_react6 = require("react");
1949
+ function useWorkspaceFiles(threadId, autoFetch = true) {
1950
+ const { fetchWithAuth } = usePersonaContext();
1951
+ const [files, setFiles] = (0, import_react6.useState)({});
1952
+ const [isLoading, setIsLoading] = (0, import_react6.useState)(false);
1953
+ const [isSaving, setIsSaving] = (0, import_react6.useState)(false);
1954
+ const [error, setError] = (0, import_react6.useState)(null);
1955
+ const fetchFiles = (0, import_react6.useCallback)(async () => {
1956
+ if (!threadId) return {};
1957
+ setIsLoading(true);
1958
+ setError(null);
1959
+ try {
1960
+ const res = await fetchWithAuth(`/threads/${threadId}/files`);
1961
+ if (!res.ok) throw new Error(`Failed to list workspace files: ${res.statusText}`);
1962
+ const data = await res.json();
1963
+ const normalized = normalizeWorkspaceFiles(data?.data ?? data ?? {});
1964
+ setFiles(normalized);
1965
+ return normalized;
1966
+ } catch (err) {
1967
+ const errorObj = err instanceof Error ? err : new Error(String(err));
1968
+ setError(errorObj);
1969
+ return {};
1970
+ } finally {
1971
+ setIsLoading(false);
1972
+ }
1973
+ }, [fetchWithAuth, threadId]);
1974
+ const getFile = (0, import_react6.useCallback)(
1975
+ async (path) => {
1976
+ if (!threadId) throw new Error("useWorkspaceFiles: no threadId set");
1977
+ const res = await fetchWithAuth(
1978
+ `/threads/${threadId}/file?path=${encodeURIComponent(path)}`
1979
+ );
1980
+ if (!res.ok) throw new Error(`Failed to read workspace file: ${res.statusText}`);
1981
+ const data = await res.json();
1982
+ const raw = data?.data ?? data;
1983
+ return normalizeWorkspaceFiles({ [path]: raw })[path];
1984
+ },
1985
+ [fetchWithAuth, threadId]
1986
+ );
1987
+ const writeFile = (0, import_react6.useCallback)(
1988
+ async (path, content) => {
1989
+ if (!threadId) throw new Error("useWorkspaceFiles: no threadId set");
1990
+ setIsSaving(true);
1991
+ setError(null);
1992
+ try {
1993
+ const res = await fetchWithAuth(`/threads/${threadId}/file`, {
1994
+ method: "PUT",
1995
+ headers: { "Content-Type": "application/json" },
1996
+ body: JSON.stringify({ path, content })
1997
+ });
1998
+ if (!res.ok) throw new Error(`Failed to write workspace file: ${res.statusText}`);
1999
+ const data = await res.json();
2000
+ const raw = data?.data ?? data;
2001
+ const file = normalizeWorkspaceFiles({ [path]: raw })[path];
2002
+ setFiles((prev) => ({ ...prev, [path]: file }));
2003
+ return file;
2004
+ } catch (err) {
2005
+ const errorObj = err instanceof Error ? err : new Error(String(err));
2006
+ setError(errorObj);
2007
+ throw errorObj;
2008
+ } finally {
2009
+ setIsSaving(false);
2010
+ }
2011
+ },
2012
+ [fetchWithAuth, threadId]
2013
+ );
2014
+ const deleteFile = (0, import_react6.useCallback)(
2015
+ async (path) => {
2016
+ if (!threadId) throw new Error("useWorkspaceFiles: no threadId set");
2017
+ const res = await fetchWithAuth(
2018
+ `/threads/${threadId}/file?path=${encodeURIComponent(path)}`,
2019
+ { method: "DELETE" }
2020
+ );
2021
+ if (!res.ok) throw new Error(`Failed to delete workspace file: ${res.statusText}`);
2022
+ setFiles((prev) => {
2023
+ const next = { ...prev };
2024
+ delete next[path];
2025
+ return next;
2026
+ });
2027
+ },
2028
+ [fetchWithAuth, threadId]
2029
+ );
2030
+ (0, import_react6.useEffect)(() => {
2031
+ if (autoFetch && threadId) {
2032
+ void fetchFiles();
2033
+ } else if (!threadId) {
2034
+ setFiles({});
2035
+ }
2036
+ }, [autoFetch, threadId, fetchFiles]);
2037
+ return {
2038
+ files,
2039
+ isLoading,
2040
+ isSaving,
2041
+ error,
2042
+ refetch: fetchFiles,
2043
+ getFile,
2044
+ writeFile,
2045
+ deleteFile
2046
+ };
2047
+ }
2048
+
2049
+ // src/hooks/useVoice.ts
2050
+ var import_react7 = require("react");
1946
2051
 
1947
2052
  // src/hooks/voiceWorklets.ts
1948
2053
  var RECORDER_WORKLET_SOURCE = `
@@ -2045,42 +2150,42 @@ function mergeTranscriptText(prev, next) {
2045
2150
  }
2046
2151
  function useVoice(options = {}) {
2047
2152
  const { defaultAgentId, fetchWithAuth, logger } = usePersonaContext();
2048
- const voiceLogger = (0, import_react6.useMemo)(() => logger.child("voice"), [logger]);
2153
+ const voiceLogger = (0, import_react7.useMemo)(() => logger.child("voice"), [logger]);
2049
2154
  const agentId = options.agentId || defaultAgentId;
2050
2155
  const threadId = options.threadId;
2051
2156
  const contextOverride = options.contextOverride;
2052
2157
  const context = options.context;
2053
- const [state, setState] = (0, import_react6.useState)("idle");
2054
- const [isMuted, setIsMuted] = (0, import_react6.useState)(false);
2055
- const [transcript, setTranscript] = (0, import_react6.useState)(
2158
+ const [state, setState] = (0, import_react7.useState)("idle");
2159
+ const [isMuted, setIsMuted] = (0, import_react7.useState)(false);
2160
+ const [transcript, setTranscript] = (0, import_react7.useState)(
2056
2161
  []
2057
2162
  );
2058
- const [partial, setPartial] = (0, import_react6.useState)(
2163
+ const [partial, setPartial] = (0, import_react7.useState)(
2059
2164
  null
2060
2165
  );
2061
- const [toolCalls, setToolCalls] = (0, import_react6.useState)([]);
2062
- const [error, setError] = (0, import_react6.useState)(null);
2063
- const [endReason, setEndReason] = (0, import_react6.useState)(
2166
+ const [toolCalls, setToolCalls] = (0, import_react7.useState)([]);
2167
+ const [error, setError] = (0, import_react7.useState)(null);
2168
+ const [endReason, setEndReason] = (0, import_react7.useState)(
2064
2169
  null
2065
2170
  );
2066
- const wsRef = (0, import_react6.useRef)(null);
2067
- const streamRef = (0, import_react6.useRef)(null);
2068
- const inputCtxRef = (0, import_react6.useRef)(null);
2069
- const outputCtxRef = (0, import_react6.useRef)(null);
2070
- const recorderNodeRef = (0, import_react6.useRef)(null);
2071
- const playerNodeRef = (0, import_react6.useRef)(null);
2072
- const acceptedTurnSeqRef = (0, import_react6.useRef)(0);
2073
- const mountedRef = (0, import_react6.useRef)(true);
2074
- const lastFinalTurnRef = (0, import_react6.useRef)(
2171
+ const wsRef = (0, import_react7.useRef)(null);
2172
+ const streamRef = (0, import_react7.useRef)(null);
2173
+ const inputCtxRef = (0, import_react7.useRef)(null);
2174
+ const outputCtxRef = (0, import_react7.useRef)(null);
2175
+ const recorderNodeRef = (0, import_react7.useRef)(null);
2176
+ const playerNodeRef = (0, import_react7.useRef)(null);
2177
+ const acceptedTurnSeqRef = (0, import_react7.useRef)(0);
2178
+ const mountedRef = (0, import_react7.useRef)(true);
2179
+ const lastFinalTurnRef = (0, import_react7.useRef)(
2075
2180
  null
2076
2181
  );
2077
- (0, import_react6.useEffect)(() => {
2182
+ (0, import_react7.useEffect)(() => {
2078
2183
  mountedRef.current = true;
2079
2184
  return () => {
2080
2185
  mountedRef.current = false;
2081
2186
  };
2082
2187
  }, []);
2083
- const teardownAudio = (0, import_react6.useCallback)(() => {
2188
+ const teardownAudio = (0, import_react7.useCallback)(() => {
2084
2189
  try {
2085
2190
  streamRef.current?.getTracks().forEach((track) => track.stop());
2086
2191
  } catch {
@@ -2107,7 +2212,7 @@ function useVoice(options = {}) {
2107
2212
  }
2108
2213
  outputCtxRef.current = null;
2109
2214
  }, []);
2110
- const stop = (0, import_react6.useCallback)(() => {
2215
+ const stop = (0, import_react7.useCallback)(() => {
2111
2216
  voiceLogger.debug("stop() called");
2112
2217
  try {
2113
2218
  wsRef.current?.close(1e3, "client_stop");
@@ -2117,8 +2222,8 @@ function useVoice(options = {}) {
2117
2222
  teardownAudio();
2118
2223
  if (mountedRef.current) setState("idle");
2119
2224
  }, [teardownAudio, voiceLogger]);
2120
- (0, import_react6.useEffect)(() => stop, [stop]);
2121
- const startCapture = (0, import_react6.useCallback)(async (inputSampleRate) => {
2225
+ (0, import_react7.useEffect)(() => stop, [stop]);
2226
+ const startCapture = (0, import_react7.useCallback)(async (inputSampleRate) => {
2122
2227
  const stream = await navigator.mediaDevices.getUserMedia({
2123
2228
  audio: {
2124
2229
  echoCancellation: true,
@@ -2144,7 +2249,7 @@ function useVoice(options = {}) {
2144
2249
  recorderNodeRef.current = recorderNode;
2145
2250
  source.connect(recorderNode);
2146
2251
  }, []);
2147
- const setupPlayback = (0, import_react6.useCallback)(async (outputSampleRate) => {
2252
+ const setupPlayback = (0, import_react7.useCallback)(async (outputSampleRate) => {
2148
2253
  const outputCtx = new AudioContext({ sampleRate: outputSampleRate });
2149
2254
  outputCtxRef.current = outputCtx;
2150
2255
  await outputCtx.audioWorklet.addModule(playerWorkletUrl());
@@ -2152,7 +2257,7 @@ function useVoice(options = {}) {
2152
2257
  playerNode.connect(outputCtx.destination);
2153
2258
  playerNodeRef.current = playerNode;
2154
2259
  }, []);
2155
- const upsertToolCall = (0, import_react6.useCallback)(
2260
+ const upsertToolCall = (0, import_react7.useCallback)(
2156
2261
  (id, patch) => {
2157
2262
  setToolCalls((prev) => {
2158
2263
  const idx = prev.findIndex((t) => t.id === id);
@@ -2164,7 +2269,7 @@ function useVoice(options = {}) {
2164
2269
  },
2165
2270
  []
2166
2271
  );
2167
- const handleTranscript = (0, import_react6.useCallback)((value) => {
2272
+ const handleTranscript = (0, import_react7.useCallback)((value) => {
2168
2273
  const { speaker, text, isFinal, turnSeq } = value;
2169
2274
  if (!isFinal) {
2170
2275
  setPartial({ id: "partial", speaker, text });
@@ -2187,7 +2292,7 @@ function useVoice(options = {}) {
2187
2292
  });
2188
2293
  lastFinalTurnRef.current = { speaker, turnSeq };
2189
2294
  }, []);
2190
- const handleCustomEvent = (0, import_react6.useCallback)(
2295
+ const handleCustomEvent = (0, import_react7.useCallback)(
2191
2296
  (name, value) => {
2192
2297
  switch (name) {
2193
2298
  case "voice_session_ready":
@@ -2245,7 +2350,7 @@ function useVoice(options = {}) {
2245
2350
  },
2246
2351
  [handleTranscript, setupPlayback, startCapture, teardownAudio, voiceLogger]
2247
2352
  );
2248
- const handleMessage = (0, import_react6.useCallback)(
2353
+ const handleMessage = (0, import_react7.useCallback)(
2249
2354
  (event) => {
2250
2355
  if (typeof event.data !== "string") {
2251
2356
  const buf = event.data;
@@ -2303,7 +2408,7 @@ function useVoice(options = {}) {
2303
2408
  },
2304
2409
  [handleCustomEvent, upsertToolCall, voiceLogger]
2305
2410
  );
2306
- const start = (0, import_react6.useCallback)(async () => {
2411
+ const start = (0, import_react7.useCallback)(async () => {
2307
2412
  if (!agentId) {
2308
2413
  const err = new Error(
2309
2414
  "useVoice: no agentId provided and no defaultAgentId set on PersonaProvider"
@@ -2370,17 +2475,17 @@ function useVoice(options = {}) {
2370
2475
  teardownAudio();
2371
2476
  }
2372
2477
  }, [agentId, threadId, contextOverride, context, fetchWithAuth, handleMessage, teardownAudio, voiceLogger]);
2373
- const mute = (0, import_react6.useCallback)((muted) => {
2478
+ const mute = (0, import_react7.useCallback)((muted) => {
2374
2479
  setIsMuted(muted);
2375
2480
  streamRef.current?.getAudioTracks().forEach((track) => {
2376
2481
  track.enabled = !muted;
2377
2482
  });
2378
2483
  }, []);
2379
- const sendText = (0, import_react6.useCallback)((text) => {
2484
+ const sendText = (0, import_react7.useCallback)((text) => {
2380
2485
  if (!text?.trim() || wsRef.current?.readyState !== WebSocket.OPEN) return;
2381
2486
  wsRef.current.send(JSON.stringify({ type: "voice.text", text }));
2382
2487
  }, []);
2383
- const updateContext = (0, import_react6.useCallback)((newContext) => {
2488
+ const updateContext = (0, import_react7.useCallback)((newContext) => {
2384
2489
  if (wsRef.current?.readyState !== WebSocket.OPEN) return;
2385
2490
  wsRef.current.send(JSON.stringify({ type: "voice.context", context: newContext }));
2386
2491
  }, []);
@@ -2401,14 +2506,14 @@ function useVoice(options = {}) {
2401
2506
  }
2402
2507
 
2403
2508
  // src/hooks/useFiles.ts
2404
- var import_react7 = require("react");
2509
+ var import_react8 = require("react");
2405
2510
  function useFiles(autoFetch = true) {
2406
2511
  const { fetchWithAuth } = usePersonaContext();
2407
- const [files, setFiles] = (0, import_react7.useState)([]);
2408
- const [isLoading, setIsLoading] = (0, import_react7.useState)(false);
2409
- const [isUploading, setIsUploading] = (0, import_react7.useState)(false);
2410
- const [error, setError] = (0, import_react7.useState)(null);
2411
- const fetchFiles = (0, import_react7.useCallback)(async () => {
2512
+ const [files, setFiles] = (0, import_react8.useState)([]);
2513
+ const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
2514
+ const [isUploading, setIsUploading] = (0, import_react8.useState)(false);
2515
+ const [error, setError] = (0, import_react8.useState)(null);
2516
+ const fetchFiles = (0, import_react8.useCallback)(async () => {
2412
2517
  setIsLoading(true);
2413
2518
  setError(null);
2414
2519
  try {
@@ -2426,7 +2531,7 @@ function useFiles(autoFetch = true) {
2426
2531
  setIsLoading(false);
2427
2532
  }
2428
2533
  }, [fetchWithAuth]);
2429
- const uploadFile = (0, import_react7.useCallback)(
2534
+ const uploadFile = (0, import_react8.useCallback)(
2430
2535
  async (fileOrFormData) => {
2431
2536
  setIsUploading(true);
2432
2537
  setError(null);
@@ -2459,7 +2564,7 @@ function useFiles(autoFetch = true) {
2459
2564
  },
2460
2565
  [fetchWithAuth, fetchFiles]
2461
2566
  );
2462
- const deleteFile = (0, import_react7.useCallback)(
2567
+ const deleteFile = (0, import_react8.useCallback)(
2463
2568
  async (fileId) => {
2464
2569
  const res = await fetchWithAuth(`/files/${fileId}`, { method: "DELETE" });
2465
2570
  if (!res.ok) throw new Error(`Failed to delete file: ${res.statusText}`);
@@ -2467,7 +2572,7 @@ function useFiles(autoFetch = true) {
2467
2572
  },
2468
2573
  [fetchWithAuth]
2469
2574
  );
2470
- const bulkDeleteFiles = (0, import_react7.useCallback)(
2575
+ const bulkDeleteFiles = (0, import_react8.useCallback)(
2471
2576
  async (fileIds) => {
2472
2577
  const res = await fetchWithAuth("/files/bulk-delete", {
2473
2578
  method: "POST",
@@ -2482,10 +2587,10 @@ function useFiles(autoFetch = true) {
2482
2587
  },
2483
2588
  [fetchWithAuth]
2484
2589
  );
2485
- const getDownloadUrl = (0, import_react7.useCallback)((fileId) => {
2590
+ const getDownloadUrl = (0, import_react8.useCallback)((fileId) => {
2486
2591
  return `/files/${fileId}`;
2487
2592
  }, []);
2488
- (0, import_react7.useEffect)(() => {
2593
+ (0, import_react8.useEffect)(() => {
2489
2594
  if (autoFetch) {
2490
2595
  void fetchFiles();
2491
2596
  }
@@ -2504,21 +2609,21 @@ function useFiles(autoFetch = true) {
2504
2609
  }
2505
2610
 
2506
2611
  // src/hooks/useAgents.ts
2507
- var import_react8 = require("react");
2612
+ var import_react9 = require("react");
2508
2613
  function useAgents(options = true) {
2509
2614
  const opts = typeof options === "boolean" ? { autoFetch: options } : options;
2510
2615
  const { autoFetch = true, page, limit, search, category, scope } = opts;
2511
2616
  const { fetchWithAuth } = usePersonaContext();
2512
- const [agents, setAgents] = (0, import_react8.useState)([]);
2513
- const [pagination, setPagination] = (0, import_react8.useState)({
2617
+ const [agents, setAgents] = (0, import_react9.useState)([]);
2618
+ const [pagination, setPagination] = (0, import_react9.useState)({
2514
2619
  total: 0,
2515
2620
  page: page ?? 1,
2516
2621
  limit: limit ?? 20,
2517
2622
  pages: 0
2518
2623
  });
2519
- const [isLoading, setIsLoading] = (0, import_react8.useState)(false);
2520
- const [error, setError] = (0, import_react8.useState)(null);
2521
- const fetchAgents = (0, import_react8.useCallback)(async () => {
2624
+ const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
2625
+ const [error, setError] = (0, import_react9.useState)(null);
2626
+ const fetchAgents = (0, import_react9.useCallback)(async () => {
2522
2627
  setIsLoading(true);
2523
2628
  setError(null);
2524
2629
  try {
@@ -2546,7 +2651,7 @@ function useAgents(options = true) {
2546
2651
  setIsLoading(false);
2547
2652
  }
2548
2653
  }, [fetchWithAuth, page, limit, search, category, scope]);
2549
- const getAgent = (0, import_react8.useCallback)(
2654
+ const getAgent = (0, import_react9.useCallback)(
2550
2655
  async (agentId) => {
2551
2656
  const res = await fetchWithAuth(`/agents/${agentId}`);
2552
2657
  if (!res.ok) throw new Error(`Failed to fetch agent: ${res.statusText}`);
@@ -2554,7 +2659,7 @@ function useAgents(options = true) {
2554
2659
  },
2555
2660
  [fetchWithAuth]
2556
2661
  );
2557
- const createAgent = (0, import_react8.useCallback)(
2662
+ const createAgent = (0, import_react9.useCallback)(
2558
2663
  async (input) => {
2559
2664
  setError(null);
2560
2665
  try {
@@ -2578,7 +2683,7 @@ function useAgents(options = true) {
2578
2683
  },
2579
2684
  [fetchWithAuth]
2580
2685
  );
2581
- const updateAgent = (0, import_react8.useCallback)(
2686
+ const updateAgent = (0, import_react9.useCallback)(
2582
2687
  async (agentId, input) => {
2583
2688
  setError(null);
2584
2689
  try {
@@ -2602,7 +2707,7 @@ function useAgents(options = true) {
2602
2707
  },
2603
2708
  [fetchWithAuth]
2604
2709
  );
2605
- const deleteAgent = (0, import_react8.useCallback)(
2710
+ const deleteAgent = (0, import_react9.useCallback)(
2606
2711
  async (agentId) => {
2607
2712
  setError(null);
2608
2713
  try {
@@ -2620,7 +2725,7 @@ function useAgents(options = true) {
2620
2725
  },
2621
2726
  [fetchWithAuth]
2622
2727
  );
2623
- const bulkDeleteAgents = (0, import_react8.useCallback)(
2728
+ const bulkDeleteAgents = (0, import_react9.useCallback)(
2624
2729
  async (ids) => {
2625
2730
  setError(null);
2626
2731
  try {
@@ -2645,7 +2750,7 @@ function useAgents(options = true) {
2645
2750
  },
2646
2751
  [fetchWithAuth]
2647
2752
  );
2648
- (0, import_react8.useEffect)(() => {
2753
+ (0, import_react9.useEffect)(() => {
2649
2754
  if (autoFetch) void fetchAgents();
2650
2755
  }, [autoFetch, fetchAgents]);
2651
2756
  return {
@@ -2663,13 +2768,13 @@ function useAgents(options = true) {
2663
2768
  }
2664
2769
 
2665
2770
  // src/hooks/useConnection.ts
2666
- var import_react9 = require("react");
2771
+ var import_react10 = require("react");
2667
2772
  function useConnection(autoCheck = true) {
2668
2773
  const { fetchWithAuth } = usePersonaContext();
2669
- const [health, setHealth] = (0, import_react9.useState)(null);
2670
- const [isConnected, setIsConnected] = (0, import_react9.useState)(false);
2671
- const [isLoading, setIsLoading] = (0, import_react9.useState)(false);
2672
- const checkHealth = (0, import_react9.useCallback)(async () => {
2774
+ const [health, setHealth] = (0, import_react10.useState)(null);
2775
+ const [isConnected, setIsConnected] = (0, import_react10.useState)(false);
2776
+ const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
2777
+ const checkHealth = (0, import_react10.useCallback)(async () => {
2673
2778
  setIsLoading(true);
2674
2779
  try {
2675
2780
  const res = await fetchWithAuth("/health");
@@ -2688,7 +2793,7 @@ function useConnection(autoCheck = true) {
2688
2793
  setIsLoading(false);
2689
2794
  }
2690
2795
  }, [fetchWithAuth]);
2691
- (0, import_react9.useEffect)(() => {
2796
+ (0, import_react10.useEffect)(() => {
2692
2797
  if (autoCheck) {
2693
2798
  void checkHealth();
2694
2799
  }
@@ -2702,15 +2807,15 @@ function useConnection(autoCheck = true) {
2702
2807
  }
2703
2808
 
2704
2809
  // src/hooks/useMcpConnections.ts
2705
- var import_react10 = require("react");
2810
+ var import_react11 = require("react");
2706
2811
  function useMcpConnections(options = {}) {
2707
2812
  const { defaultAgentId, fetchWithAuth } = usePersonaContext();
2708
2813
  const agentId = options.agentId ?? defaultAgentId;
2709
2814
  const autoFetch = options.autoFetch ?? true;
2710
- const [connections, setConnections] = (0, import_react10.useState)([]);
2711
- const [isLoading, setIsLoading] = (0, import_react10.useState)(false);
2712
- const [error, setError] = (0, import_react10.useState)(null);
2713
- const fetchConnections = (0, import_react10.useCallback)(async () => {
2815
+ const [connections, setConnections] = (0, import_react11.useState)([]);
2816
+ const [isLoading, setIsLoading] = (0, import_react11.useState)(false);
2817
+ const [error, setError] = (0, import_react11.useState)(null);
2818
+ const fetchConnections = (0, import_react11.useCallback)(async () => {
2714
2819
  if (!agentId) return [];
2715
2820
  setIsLoading(true);
2716
2821
  setError(null);
@@ -2734,8 +2839,8 @@ function useMcpConnections(options = {}) {
2734
2839
  setIsLoading(false);
2735
2840
  }
2736
2841
  }, [agentId, fetchWithAuth, options.returnTo]);
2737
- const [isDisconnecting, setIsDisconnecting] = (0, import_react10.useState)(false);
2738
- const disconnect = (0, import_react10.useCallback)(
2842
+ const [isDisconnecting, setIsDisconnecting] = (0, import_react11.useState)(false);
2843
+ const disconnect = (0, import_react11.useCallback)(
2739
2844
  async (mcpId) => {
2740
2845
  setIsDisconnecting(true);
2741
2846
  setError(null);
@@ -2761,7 +2866,7 @@ function useMcpConnections(options = {}) {
2761
2866
  },
2762
2867
  [fetchWithAuth, fetchConnections]
2763
2868
  );
2764
- (0, import_react10.useEffect)(() => {
2869
+ (0, import_react11.useEffect)(() => {
2765
2870
  if (autoFetch) void fetchConnections();
2766
2871
  }, [autoFetch, fetchConnections]);
2767
2872
  return {
@@ -2777,11 +2882,11 @@ function useMcpConnections(options = {}) {
2777
2882
  }
2778
2883
 
2779
2884
  // src/hooks/useMcp.ts
2780
- var import_react11 = require("react");
2885
+ var import_react12 = require("react");
2781
2886
  function useMcp(options = {}) {
2782
2887
  const { fetchWithAuth } = usePersonaContext();
2783
2888
  const defaultMcpId = options.mcpId;
2784
- const readResource = (0, import_react11.useCallback)(
2889
+ const readResource = (0, import_react12.useCallback)(
2785
2890
  async (uri, mcpId) => {
2786
2891
  const id = mcpId ?? defaultMcpId;
2787
2892
  if (!id) throw new Error("MCP server ID is required to read resource");
@@ -2795,7 +2900,7 @@ function useMcp(options = {}) {
2795
2900
  },
2796
2901
  [fetchWithAuth, defaultMcpId]
2797
2902
  );
2798
- const callTool = (0, import_react11.useCallback)(
2903
+ const callTool = (0, import_react12.useCallback)(
2799
2904
  async (name, args, mcpId) => {
2800
2905
  const id = mcpId ?? defaultMcpId;
2801
2906
  if (!id) throw new Error("MCP server ID is required to call tool");
@@ -2818,20 +2923,20 @@ function useMcp(options = {}) {
2818
2923
  }
2819
2924
 
2820
2925
  // src/hooks/useSkills.ts
2821
- var import_react12 = require("react");
2926
+ var import_react13 = require("react");
2822
2927
  function useSkills(options = {}) {
2823
2928
  const { autoFetch = true, page, limit, search, scope } = options;
2824
2929
  const { fetchWithAuth } = usePersonaContext();
2825
- const [skills, setSkills] = (0, import_react12.useState)([]);
2826
- const [pagination, setPagination] = (0, import_react12.useState)({
2930
+ const [skills, setSkills] = (0, import_react13.useState)([]);
2931
+ const [pagination, setPagination] = (0, import_react13.useState)({
2827
2932
  total: 0,
2828
2933
  page: page ?? 1,
2829
2934
  limit: limit ?? 20,
2830
2935
  pages: 0
2831
2936
  });
2832
- const [isLoading, setIsLoading] = (0, import_react12.useState)(false);
2833
- const [error, setError] = (0, import_react12.useState)(null);
2834
- const fetchSkills = (0, import_react12.useCallback)(async () => {
2937
+ const [isLoading, setIsLoading] = (0, import_react13.useState)(false);
2938
+ const [error, setError] = (0, import_react13.useState)(null);
2939
+ const fetchSkills = (0, import_react13.useCallback)(async () => {
2835
2940
  setIsLoading(true);
2836
2941
  setError(null);
2837
2942
  try {
@@ -2858,7 +2963,7 @@ function useSkills(options = {}) {
2858
2963
  setIsLoading(false);
2859
2964
  }
2860
2965
  }, [fetchWithAuth, page, limit, search, scope]);
2861
- const getSkill = (0, import_react12.useCallback)(
2966
+ const getSkill = (0, import_react13.useCallback)(
2862
2967
  async (skillId) => {
2863
2968
  const res = await fetchWithAuth(`/skills/${skillId}`);
2864
2969
  if (!res.ok) throw new Error(`Failed to fetch skill: ${res.statusText}`);
@@ -2866,7 +2971,7 @@ function useSkills(options = {}) {
2866
2971
  },
2867
2972
  [fetchWithAuth]
2868
2973
  );
2869
- const createSkill = (0, import_react12.useCallback)(
2974
+ const createSkill = (0, import_react13.useCallback)(
2870
2975
  async (input) => {
2871
2976
  setError(null);
2872
2977
  try {
@@ -2890,7 +2995,7 @@ function useSkills(options = {}) {
2890
2995
  },
2891
2996
  [fetchWithAuth]
2892
2997
  );
2893
- const updateSkill = (0, import_react12.useCallback)(
2998
+ const updateSkill = (0, import_react13.useCallback)(
2894
2999
  async (skillId, input) => {
2895
3000
  setError(null);
2896
3001
  try {
@@ -2914,7 +3019,7 @@ function useSkills(options = {}) {
2914
3019
  },
2915
3020
  [fetchWithAuth]
2916
3021
  );
2917
- const deleteSkill = (0, import_react12.useCallback)(
3022
+ const deleteSkill = (0, import_react13.useCallback)(
2918
3023
  async (skillId) => {
2919
3024
  setError(null);
2920
3025
  try {
@@ -2932,7 +3037,7 @@ function useSkills(options = {}) {
2932
3037
  },
2933
3038
  [fetchWithAuth]
2934
3039
  );
2935
- const bulkDeleteSkills = (0, import_react12.useCallback)(
3040
+ const bulkDeleteSkills = (0, import_react13.useCallback)(
2936
3041
  async (ids) => {
2937
3042
  setError(null);
2938
3043
  try {
@@ -2957,7 +3062,7 @@ function useSkills(options = {}) {
2957
3062
  },
2958
3063
  [fetchWithAuth]
2959
3064
  );
2960
- const getSkillUsage = (0, import_react12.useCallback)(
3065
+ const getSkillUsage = (0, import_react13.useCallback)(
2961
3066
  async (skillId) => {
2962
3067
  const res = await fetchWithAuth(`/skills/${skillId}/usage`);
2963
3068
  if (!res.ok) throw new Error(`Failed to fetch skill usage: ${res.statusText}`);
@@ -2965,7 +3070,7 @@ function useSkills(options = {}) {
2965
3070
  },
2966
3071
  [fetchWithAuth]
2967
3072
  );
2968
- (0, import_react12.useEffect)(() => {
3073
+ (0, import_react13.useEffect)(() => {
2969
3074
  if (autoFetch) void fetchSkills();
2970
3075
  }, [autoFetch, fetchSkills]);
2971
3076
  return {
@@ -2984,20 +3089,20 @@ function useSkills(options = {}) {
2984
3089
  }
2985
3090
 
2986
3091
  // src/hooks/useRcpSources.ts
2987
- var import_react13 = require("react");
3092
+ var import_react14 = require("react");
2988
3093
  function useRcpSources(options = {}) {
2989
3094
  const { autoFetch = true, page, limit, search } = options;
2990
3095
  const { fetchWithAuth } = usePersonaContext();
2991
- const [rcpSources, setRcpSources] = (0, import_react13.useState)([]);
2992
- const [pagination, setPagination] = (0, import_react13.useState)({
3096
+ const [rcpSources, setRcpSources] = (0, import_react14.useState)([]);
3097
+ const [pagination, setPagination] = (0, import_react14.useState)({
2993
3098
  total: 0,
2994
3099
  page: page ?? 1,
2995
3100
  limit: limit ?? 20,
2996
3101
  pages: 0
2997
3102
  });
2998
- const [isLoading, setIsLoading] = (0, import_react13.useState)(false);
2999
- const [error, setError] = (0, import_react13.useState)(null);
3000
- const fetchRcpSources = (0, import_react13.useCallback)(async () => {
3103
+ const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
3104
+ const [error, setError] = (0, import_react14.useState)(null);
3105
+ const fetchRcpSources = (0, import_react14.useCallback)(async () => {
3001
3106
  setIsLoading(true);
3002
3107
  setError(null);
3003
3108
  try {
@@ -3023,7 +3128,7 @@ function useRcpSources(options = {}) {
3023
3128
  setIsLoading(false);
3024
3129
  }
3025
3130
  }, [fetchWithAuth, page, limit, search]);
3026
- const getRcpSource = (0, import_react13.useCallback)(
3131
+ const getRcpSource = (0, import_react14.useCallback)(
3027
3132
  async (sourceId) => {
3028
3133
  const res = await fetchWithAuth(`/rcp-sources/${sourceId}`);
3029
3134
  if (!res.ok) throw new Error(`Failed to fetch RCP source: ${res.statusText}`);
@@ -3031,7 +3136,7 @@ function useRcpSources(options = {}) {
3031
3136
  },
3032
3137
  [fetchWithAuth]
3033
3138
  );
3034
- const createRcpSource = (0, import_react13.useCallback)(
3139
+ const createRcpSource = (0, import_react14.useCallback)(
3035
3140
  async (input) => {
3036
3141
  setError(null);
3037
3142
  try {
@@ -3055,7 +3160,7 @@ function useRcpSources(options = {}) {
3055
3160
  },
3056
3161
  [fetchWithAuth]
3057
3162
  );
3058
- const updateRcpSource = (0, import_react13.useCallback)(
3163
+ const updateRcpSource = (0, import_react14.useCallback)(
3059
3164
  async (sourceId, input) => {
3060
3165
  setError(null);
3061
3166
  try {
@@ -3079,7 +3184,7 @@ function useRcpSources(options = {}) {
3079
3184
  },
3080
3185
  [fetchWithAuth]
3081
3186
  );
3082
- const deleteRcpSource = (0, import_react13.useCallback)(
3187
+ const deleteRcpSource = (0, import_react14.useCallback)(
3083
3188
  async (sourceId) => {
3084
3189
  setError(null);
3085
3190
  try {
@@ -3097,7 +3202,7 @@ function useRcpSources(options = {}) {
3097
3202
  },
3098
3203
  [fetchWithAuth]
3099
3204
  );
3100
- const bulkDeleteRcpSources = (0, import_react13.useCallback)(
3205
+ const bulkDeleteRcpSources = (0, import_react14.useCallback)(
3101
3206
  async (ids) => {
3102
3207
  setError(null);
3103
3208
  try {
@@ -3122,7 +3227,7 @@ function useRcpSources(options = {}) {
3122
3227
  },
3123
3228
  [fetchWithAuth]
3124
3229
  );
3125
- const getRcpSourceUsage = (0, import_react13.useCallback)(
3230
+ const getRcpSourceUsage = (0, import_react14.useCallback)(
3126
3231
  async (sourceId) => {
3127
3232
  const res = await fetchWithAuth(`/rcp-sources/${sourceId}/usage`);
3128
3233
  if (!res.ok) throw new Error(`Failed to fetch RCP source usage: ${res.statusText}`);
@@ -3130,7 +3235,7 @@ function useRcpSources(options = {}) {
3130
3235
  },
3131
3236
  [fetchWithAuth]
3132
3237
  );
3133
- const testRcpSourceConnection = (0, import_react13.useCallback)(
3238
+ const testRcpSourceConnection = (0, import_react14.useCallback)(
3134
3239
  async (sourceId) => {
3135
3240
  setError(null);
3136
3241
  try {
@@ -3154,7 +3259,7 @@ function useRcpSources(options = {}) {
3154
3259
  },
3155
3260
  [fetchWithAuth]
3156
3261
  );
3157
- (0, import_react13.useEffect)(() => {
3262
+ (0, import_react14.useEffect)(() => {
3158
3263
  if (autoFetch) void fetchRcpSources();
3159
3264
  }, [autoFetch, fetchRcpSources]);
3160
3265
  return {
@@ -3173,28 +3278,475 @@ function useRcpSources(options = {}) {
3173
3278
  };
3174
3279
  }
3175
3280
 
3281
+ // src/hooks/useKnowledgeBases.ts
3282
+ var import_react15 = require("react");
3283
+ function useKnowledgeBases(options = {}) {
3284
+ const { autoFetch = true, page, limit, search, scope } = options;
3285
+ const { fetchWithAuth } = usePersonaContext();
3286
+ const [knowledgeBases, setKnowledgeBases] = (0, import_react15.useState)([]);
3287
+ const [pagination, setPagination] = (0, import_react15.useState)({
3288
+ total: 0,
3289
+ page: page ?? 1,
3290
+ limit: limit ?? 20,
3291
+ pages: 0
3292
+ });
3293
+ const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
3294
+ const [isUploading, setIsUploading] = (0, import_react15.useState)(false);
3295
+ const [error, setError] = (0, import_react15.useState)(null);
3296
+ const fetchKnowledgeBases = (0, import_react15.useCallback)(async () => {
3297
+ setIsLoading(true);
3298
+ setError(null);
3299
+ try {
3300
+ const query = new URLSearchParams();
3301
+ if (page) query.set("page", String(page));
3302
+ if (limit) query.set("limit", String(limit));
3303
+ if (search) query.set("search", search);
3304
+ if (scope) query.set("scope", scope);
3305
+ const queryStr = query.toString() ? `?${query.toString()}` : "";
3306
+ const res = await fetchWithAuth(`/knowledge${queryStr}`);
3307
+ if (!res.ok) throw new Error(`Failed to list knowledge bases: ${res.statusText}`);
3308
+ const data = await res.json();
3309
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3310
+ setKnowledgeBases(items);
3311
+ setPagination(
3312
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
3313
+ );
3314
+ return items;
3315
+ } catch (err) {
3316
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3317
+ setError(errorObj);
3318
+ return [];
3319
+ } finally {
3320
+ setIsLoading(false);
3321
+ }
3322
+ }, [fetchWithAuth, page, limit, search, scope]);
3323
+ const getKnowledgeBase = (0, import_react15.useCallback)(
3324
+ async (kbId) => {
3325
+ const res = await fetchWithAuth(`/knowledge/${kbId}`);
3326
+ if (!res.ok) throw new Error(`Failed to fetch knowledge base: ${res.statusText}`);
3327
+ return res.json();
3328
+ },
3329
+ [fetchWithAuth]
3330
+ );
3331
+ const createKnowledgeBase = (0, import_react15.useCallback)(
3332
+ async (input) => {
3333
+ setError(null);
3334
+ try {
3335
+ const res = await fetchWithAuth("/knowledge", {
3336
+ method: "POST",
3337
+ headers: { "Content-Type": "application/json" },
3338
+ body: JSON.stringify(input)
3339
+ });
3340
+ if (!res.ok) {
3341
+ const errText = await res.text().catch(() => res.statusText);
3342
+ throw new Error(`Failed to create knowledge base (${res.status}): ${errText}`);
3343
+ }
3344
+ const created = await res.json();
3345
+ setKnowledgeBases((prev) => [created, ...prev]);
3346
+ return created;
3347
+ } catch (err) {
3348
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3349
+ setError(errorObj);
3350
+ throw errorObj;
3351
+ }
3352
+ },
3353
+ [fetchWithAuth]
3354
+ );
3355
+ const updateKnowledgeBase = (0, import_react15.useCallback)(
3356
+ async (kbId, input) => {
3357
+ setError(null);
3358
+ try {
3359
+ const res = await fetchWithAuth(`/knowledge/${kbId}`, {
3360
+ method: "PATCH",
3361
+ headers: { "Content-Type": "application/json" },
3362
+ body: JSON.stringify(input)
3363
+ });
3364
+ if (!res.ok) {
3365
+ const errText = await res.text().catch(() => res.statusText);
3366
+ throw new Error(`Failed to update knowledge base (${res.status}): ${errText}`);
3367
+ }
3368
+ const updated = await res.json();
3369
+ setKnowledgeBases((prev) => prev.map((kb) => kb._id === kbId ? updated : kb));
3370
+ return updated;
3371
+ } catch (err) {
3372
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3373
+ setError(errorObj);
3374
+ throw errorObj;
3375
+ }
3376
+ },
3377
+ [fetchWithAuth]
3378
+ );
3379
+ const deleteKnowledgeBase = (0, import_react15.useCallback)(
3380
+ async (kbId) => {
3381
+ setError(null);
3382
+ try {
3383
+ const res = await fetchWithAuth(`/knowledge/${kbId}`, { method: "DELETE" });
3384
+ if (!res.ok) {
3385
+ const errText = await res.text().catch(() => res.statusText);
3386
+ throw new Error(`Failed to delete knowledge base (${res.status}): ${errText}`);
3387
+ }
3388
+ setKnowledgeBases((prev) => prev.filter((kb) => kb._id !== kbId));
3389
+ } catch (err) {
3390
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3391
+ setError(errorObj);
3392
+ throw errorObj;
3393
+ }
3394
+ },
3395
+ [fetchWithAuth]
3396
+ );
3397
+ const bulkDeleteKnowledgeBases = (0, import_react15.useCallback)(
3398
+ async (ids) => {
3399
+ setError(null);
3400
+ try {
3401
+ const res = await fetchWithAuth("/knowledge/bulk-delete", {
3402
+ method: "POST",
3403
+ headers: { "Content-Type": "application/json" },
3404
+ body: JSON.stringify({ ids })
3405
+ });
3406
+ if (!res.ok) {
3407
+ const errText = await res.text().catch(() => res.statusText);
3408
+ throw new Error(`Failed to bulk-delete knowledge bases (${res.status}): ${errText}`);
3409
+ }
3410
+ const result = await res.json();
3411
+ const deletedSet = new Set(result.deleted);
3412
+ setKnowledgeBases((prev) => prev.filter((kb) => !deletedSet.has(kb._id)));
3413
+ return result;
3414
+ } catch (err) {
3415
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3416
+ setError(errorObj);
3417
+ throw errorObj;
3418
+ }
3419
+ },
3420
+ [fetchWithAuth]
3421
+ );
3422
+ const getKnowledgeBaseUsage = (0, import_react15.useCallback)(
3423
+ async (kbId) => {
3424
+ const res = await fetchWithAuth(`/knowledge/${kbId}/usage`);
3425
+ if (!res.ok) throw new Error(`Failed to fetch knowledge base usage: ${res.statusText}`);
3426
+ return res.json();
3427
+ },
3428
+ [fetchWithAuth]
3429
+ );
3430
+ const uploadDocuments = (0, import_react15.useCallback)(
3431
+ async (kbId, files) => {
3432
+ setIsUploading(true);
3433
+ setError(null);
3434
+ try {
3435
+ const body = new FormData();
3436
+ for (const file of files) {
3437
+ if (file.content instanceof Blob) {
3438
+ body.append("files", file.content, file.filename);
3439
+ } else {
3440
+ body.append("files", {
3441
+ uri: file.content.uri,
3442
+ name: file.content.name ?? file.filename,
3443
+ type: file.content.type ?? file.contentType
3444
+ });
3445
+ }
3446
+ }
3447
+ const res = await fetchWithAuth(`/knowledge/${kbId}/documents`, {
3448
+ method: "POST",
3449
+ body
3450
+ });
3451
+ if (!res.ok) {
3452
+ const errText = await res.text().catch(() => res.statusText);
3453
+ throw new Error(`Failed to upload documents (${res.status}): ${errText}`);
3454
+ }
3455
+ const result = await res.json();
3456
+ setKnowledgeBases(
3457
+ (prev) => prev.map(
3458
+ (kb) => kb._id === kbId ? { ...kb, documentCount: result.documentCount, chunkCount: result.chunkCount } : kb
3459
+ )
3460
+ );
3461
+ return result;
3462
+ } catch (err) {
3463
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3464
+ setError(errorObj);
3465
+ throw errorObj;
3466
+ } finally {
3467
+ setIsUploading(false);
3468
+ }
3469
+ },
3470
+ [fetchWithAuth]
3471
+ );
3472
+ const listDocuments = (0, import_react15.useCallback)(
3473
+ async (kbId) => {
3474
+ const res = await fetchWithAuth(`/knowledge/${kbId}/documents`);
3475
+ if (!res.ok) throw new Error(`Failed to list documents: ${res.statusText}`);
3476
+ return res.json();
3477
+ },
3478
+ [fetchWithAuth]
3479
+ );
3480
+ const deleteDocument = (0, import_react15.useCallback)(
3481
+ async (kbId, sourceName) => {
3482
+ setError(null);
3483
+ try {
3484
+ const res = await fetchWithAuth(
3485
+ `/knowledge/${kbId}/documents/${encodeURIComponent(sourceName)}`,
3486
+ { method: "DELETE" }
3487
+ );
3488
+ if (!res.ok) {
3489
+ const errText = await res.text().catch(() => res.statusText);
3490
+ throw new Error(`Failed to delete document (${res.status}): ${errText}`);
3491
+ }
3492
+ const result = await res.json();
3493
+ setKnowledgeBases(
3494
+ (prev) => prev.map(
3495
+ (kb) => kb._id === kbId ? { ...kb, documentCount: result.remainingDocuments, chunkCount: result.remainingChunks } : kb
3496
+ )
3497
+ );
3498
+ return result;
3499
+ } catch (err) {
3500
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3501
+ setError(errorObj);
3502
+ throw errorObj;
3503
+ }
3504
+ },
3505
+ [fetchWithAuth]
3506
+ );
3507
+ const searchKnowledgeBase = (0, import_react15.useCallback)(
3508
+ async (kbId, query, opts) => {
3509
+ const res = await fetchWithAuth(`/knowledge/${kbId}/search`, {
3510
+ method: "POST",
3511
+ headers: { "Content-Type": "application/json" },
3512
+ body: JSON.stringify({ query, topK: opts?.topK })
3513
+ });
3514
+ if (!res.ok) {
3515
+ const errText = await res.text().catch(() => res.statusText);
3516
+ throw new Error(`Failed to search knowledge base (${res.status}): ${errText}`);
3517
+ }
3518
+ return res.json();
3519
+ },
3520
+ [fetchWithAuth]
3521
+ );
3522
+ (0, import_react15.useEffect)(() => {
3523
+ if (autoFetch) void fetchKnowledgeBases();
3524
+ }, [autoFetch, fetchKnowledgeBases]);
3525
+ return {
3526
+ knowledgeBases,
3527
+ pagination,
3528
+ isLoading,
3529
+ isUploading,
3530
+ error,
3531
+ refetch: fetchKnowledgeBases,
3532
+ getKnowledgeBase,
3533
+ createKnowledgeBase,
3534
+ updateKnowledgeBase,
3535
+ deleteKnowledgeBase,
3536
+ bulkDeleteKnowledgeBases,
3537
+ getKnowledgeBaseUsage,
3538
+ uploadDocuments,
3539
+ listDocuments,
3540
+ deleteDocument,
3541
+ search: searchKnowledgeBase
3542
+ };
3543
+ }
3544
+
3545
+ // src/hooks/useMcpAdmin.ts
3546
+ var import_react16 = require("react");
3547
+ function useMcpAdmin(options = {}) {
3548
+ const { autoFetch = true, page, limit, search } = options;
3549
+ const { fetchWithAuth } = usePersonaContext();
3550
+ const [mcps, setMcps] = (0, import_react16.useState)([]);
3551
+ const [pagination, setPagination] = (0, import_react16.useState)({
3552
+ total: 0,
3553
+ page: page ?? 1,
3554
+ limit: limit ?? 20,
3555
+ pages: 0
3556
+ });
3557
+ const [isLoading, setIsLoading] = (0, import_react16.useState)(false);
3558
+ const [error, setError] = (0, import_react16.useState)(null);
3559
+ const fetchMcps = (0, import_react16.useCallback)(async () => {
3560
+ setIsLoading(true);
3561
+ setError(null);
3562
+ try {
3563
+ const query = new URLSearchParams();
3564
+ if (page) query.set("page", String(page));
3565
+ if (limit) query.set("limit", String(limit));
3566
+ if (search) query.set("search", search);
3567
+ query.set("scope", "mine");
3568
+ const res = await fetchWithAuth(`/mcps?${query.toString()}`);
3569
+ if (!res.ok) throw new Error(`Failed to list MCPs: ${res.statusText}`);
3570
+ const data = await res.json();
3571
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3572
+ setMcps(items);
3573
+ setPagination(
3574
+ data?.pagination ?? { total: items.length, page: 1, limit: items.length, pages: 1 }
3575
+ );
3576
+ return items;
3577
+ } catch (err) {
3578
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3579
+ setError(errorObj);
3580
+ return [];
3581
+ } finally {
3582
+ setIsLoading(false);
3583
+ }
3584
+ }, [fetchWithAuth, page, limit, search]);
3585
+ const getMcp = (0, import_react16.useCallback)(
3586
+ async (mcpId) => {
3587
+ const res = await fetchWithAuth(`/mcps/${mcpId}`);
3588
+ if (!res.ok) throw new Error(`Failed to fetch MCP: ${res.statusText}`);
3589
+ return res.json();
3590
+ },
3591
+ [fetchWithAuth]
3592
+ );
3593
+ const createMcp = (0, import_react16.useCallback)(
3594
+ async (input) => {
3595
+ setError(null);
3596
+ try {
3597
+ const res = await fetchWithAuth("/mcps", {
3598
+ method: "POST",
3599
+ headers: { "Content-Type": "application/json" },
3600
+ body: JSON.stringify(input)
3601
+ });
3602
+ if (!res.ok) {
3603
+ const errText = await res.text().catch(() => res.statusText);
3604
+ throw new Error(`Failed to create MCP (${res.status}): ${errText}`);
3605
+ }
3606
+ const created = await res.json();
3607
+ setMcps((prev) => [created, ...prev]);
3608
+ return created;
3609
+ } catch (err) {
3610
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3611
+ setError(errorObj);
3612
+ throw errorObj;
3613
+ }
3614
+ },
3615
+ [fetchWithAuth]
3616
+ );
3617
+ const updateMcp = (0, import_react16.useCallback)(
3618
+ async (mcpId, input) => {
3619
+ setError(null);
3620
+ try {
3621
+ const res = await fetchWithAuth(`/mcps/${mcpId}`, {
3622
+ method: "PATCH",
3623
+ headers: { "Content-Type": "application/json" },
3624
+ body: JSON.stringify(input)
3625
+ });
3626
+ if (!res.ok) {
3627
+ const errText = await res.text().catch(() => res.statusText);
3628
+ throw new Error(`Failed to update MCP (${res.status}): ${errText}`);
3629
+ }
3630
+ const updated = await res.json();
3631
+ setMcps((prev) => prev.map((m) => m._id === mcpId ? updated : m));
3632
+ return updated;
3633
+ } catch (err) {
3634
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3635
+ setError(errorObj);
3636
+ throw errorObj;
3637
+ }
3638
+ },
3639
+ [fetchWithAuth]
3640
+ );
3641
+ const deleteMcp = (0, import_react16.useCallback)(
3642
+ async (mcpId) => {
3643
+ setError(null);
3644
+ try {
3645
+ const res = await fetchWithAuth(`/mcps/${mcpId}`, { method: "DELETE" });
3646
+ if (!res.ok) {
3647
+ const errText = await res.text().catch(() => res.statusText);
3648
+ throw new Error(`Failed to delete MCP (${res.status}): ${errText}`);
3649
+ }
3650
+ setMcps((prev) => prev.filter((m) => m._id !== mcpId));
3651
+ } catch (err) {
3652
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3653
+ setError(errorObj);
3654
+ throw errorObj;
3655
+ }
3656
+ },
3657
+ [fetchWithAuth]
3658
+ );
3659
+ const bulkDeleteMcps = (0, import_react16.useCallback)(
3660
+ async (ids) => {
3661
+ setError(null);
3662
+ try {
3663
+ const res = await fetchWithAuth("/mcps/bulk-delete", {
3664
+ method: "POST",
3665
+ headers: { "Content-Type": "application/json" },
3666
+ body: JSON.stringify({ ids })
3667
+ });
3668
+ if (!res.ok) {
3669
+ const errText = await res.text().catch(() => res.statusText);
3670
+ throw new Error(`Failed to bulk-delete MCPs (${res.status}): ${errText}`);
3671
+ }
3672
+ const result = await res.json();
3673
+ const deletedSet = new Set(result.deleted);
3674
+ setMcps((prev) => prev.filter((m) => !deletedSet.has(m._id)));
3675
+ return result;
3676
+ } catch (err) {
3677
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3678
+ setError(errorObj);
3679
+ throw errorObj;
3680
+ }
3681
+ },
3682
+ [fetchWithAuth]
3683
+ );
3684
+ const testConnection = (0, import_react16.useCallback)(
3685
+ async (mcpId) => {
3686
+ setError(null);
3687
+ try {
3688
+ const res = await fetchWithAuth(`/mcps/${mcpId}/test`, { method: "POST" });
3689
+ if (!res.ok) {
3690
+ const errText = await res.text().catch(() => res.statusText);
3691
+ throw new Error(`Failed to test MCP connection (${res.status}): ${errText}`);
3692
+ }
3693
+ const result = await res.json();
3694
+ setMcps(
3695
+ (prev) => prev.map(
3696
+ (m) => m._id === mcpId ? { ...m, tools: result.tools, resources: result.resources, resourceTemplates: result.resourceTemplates } : m
3697
+ )
3698
+ );
3699
+ return result;
3700
+ } catch (err) {
3701
+ const errorObj = err instanceof Error ? err : new Error(String(err));
3702
+ setError(errorObj);
3703
+ throw errorObj;
3704
+ }
3705
+ },
3706
+ [fetchWithAuth]
3707
+ );
3708
+ (0, import_react16.useEffect)(() => {
3709
+ if (autoFetch) void fetchMcps();
3710
+ }, [autoFetch, fetchMcps]);
3711
+ return {
3712
+ mcps,
3713
+ pagination,
3714
+ isLoading,
3715
+ error,
3716
+ refetch: fetchMcps,
3717
+ getMcp,
3718
+ createMcp,
3719
+ updateMcp,
3720
+ deleteMcp,
3721
+ bulkDeleteMcps,
3722
+ testConnection
3723
+ };
3724
+ }
3725
+
3176
3726
  // src/hooks/useWorkflows.ts
3177
- var import_react14 = require("react");
3727
+ var import_react17 = require("react");
3178
3728
  function useWorkflows(options) {
3179
3729
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
3180
- const { autoFetch = true, search, status, page, limit } = opts;
3730
+ const { autoFetch = true, search, scope, visibility, isEnabled, page, limit } = opts;
3181
3731
  const { fetchWithAuth } = usePersonaContext();
3182
- const [workflows, setWorkflows] = (0, import_react14.useState)([]);
3183
- const [pagination, setPagination] = (0, import_react14.useState)({
3732
+ const [workflows, setWorkflows] = (0, import_react17.useState)([]);
3733
+ const [pagination, setPagination] = (0, import_react17.useState)({
3184
3734
  page: page ?? 1,
3185
3735
  limit: limit ?? 20,
3186
3736
  total: 0,
3187
3737
  totalPages: 0
3188
3738
  });
3189
- const [isLoading, setIsLoading] = (0, import_react14.useState)(false);
3190
- const [error, setError] = (0, import_react14.useState)(null);
3191
- const fetchWorkflows = (0, import_react14.useCallback)(async () => {
3739
+ const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
3740
+ const [error, setError] = (0, import_react17.useState)(null);
3741
+ const fetchWorkflows = (0, import_react17.useCallback)(async () => {
3192
3742
  setIsLoading(true);
3193
3743
  setError(null);
3194
3744
  try {
3195
3745
  const params = new URLSearchParams();
3196
3746
  if (search) params.set("search", search);
3197
- if (status) params.set("status", status);
3747
+ if (scope) params.set("scope", scope);
3748
+ if (visibility) params.set("visibility", visibility);
3749
+ if (isEnabled !== void 0) params.set("isEnabled", String(isEnabled));
3198
3750
  if (page) params.set("page", String(page));
3199
3751
  if (limit) params.set("limit", String(limit));
3200
3752
  const queryStr = params.toString() ? `?${params.toString()}` : "";
@@ -3203,7 +3755,7 @@ function useWorkflows(options) {
3203
3755
  throw new Error(`Failed to list workflows: ${res.statusText}`);
3204
3756
  }
3205
3757
  const data = await res.json();
3206
- const items = Array.isArray(data) ? data : data?.items || data?.workflows || [];
3758
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3207
3759
  setWorkflows(items);
3208
3760
  if (data?.pagination) {
3209
3761
  setPagination({
@@ -3231,8 +3783,8 @@ function useWorkflows(options) {
3231
3783
  } finally {
3232
3784
  setIsLoading(false);
3233
3785
  }
3234
- }, [fetchWithAuth, search, status, page, limit]);
3235
- const createWorkflow = (0, import_react14.useCallback)(
3786
+ }, [fetchWithAuth, search, scope, visibility, isEnabled, page, limit]);
3787
+ const createWorkflow = (0, import_react17.useCallback)(
3236
3788
  async (input) => {
3237
3789
  setError(null);
3238
3790
  try {
@@ -3256,7 +3808,7 @@ function useWorkflows(options) {
3256
3808
  },
3257
3809
  [fetchWithAuth]
3258
3810
  );
3259
- (0, import_react14.useEffect)(() => {
3811
+ (0, import_react17.useEffect)(() => {
3260
3812
  if (autoFetch) {
3261
3813
  void fetchWorkflows();
3262
3814
  }
@@ -3272,17 +3824,17 @@ function useWorkflows(options) {
3272
3824
  }
3273
3825
 
3274
3826
  // src/hooks/useWorkflow.ts
3275
- var import_react15 = require("react");
3827
+ var import_react18 = require("react");
3276
3828
  function useWorkflow(workflowId, options) {
3277
3829
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
3278
3830
  const { autoFetch = true } = opts;
3279
3831
  const { fetchWithAuth } = usePersonaContext();
3280
- const [workflow, setWorkflow] = (0, import_react15.useState)(null);
3281
- const [versions, setVersions] = (0, import_react15.useState)([]);
3282
- const [mermaid, setMermaid] = (0, import_react15.useState)(null);
3283
- const [isLoading, setIsLoading] = (0, import_react15.useState)(false);
3284
- const [error, setError] = (0, import_react15.useState)(null);
3285
- const fetchWorkflow = (0, import_react15.useCallback)(async () => {
3832
+ const [workflow, setWorkflow] = (0, import_react18.useState)(null);
3833
+ const [versions, setVersions] = (0, import_react18.useState)([]);
3834
+ const [mermaid, setMermaid] = (0, import_react18.useState)(null);
3835
+ const [isLoading, setIsLoading] = (0, import_react18.useState)(false);
3836
+ const [error, setError] = (0, import_react18.useState)(null);
3837
+ const fetchWorkflow = (0, import_react18.useCallback)(async () => {
3286
3838
  if (!workflowId) return null;
3287
3839
  setIsLoading(true);
3288
3840
  setError(null);
@@ -3302,20 +3854,31 @@ function useWorkflow(workflowId, options) {
3302
3854
  setIsLoading(false);
3303
3855
  }
3304
3856
  }, [fetchWithAuth, workflowId]);
3305
- const fetchVersions = (0, import_react15.useCallback)(async () => {
3857
+ const fetchVersions = (0, import_react18.useCallback)(async () => {
3306
3858
  if (!workflowId) return [];
3307
3859
  try {
3308
3860
  const res = await fetchWithAuth(`/workflows/${workflowId}/versions`);
3309
3861
  if (!res.ok) return [];
3310
3862
  const data = await res.json();
3311
- const items = Array.isArray(data) ? data : data?.items || [];
3863
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3312
3864
  setVersions(items);
3313
3865
  return items;
3314
3866
  } catch {
3315
3867
  return [];
3316
3868
  }
3317
3869
  }, [fetchWithAuth, workflowId]);
3318
- const fetchMermaid = (0, import_react15.useCallback)(async () => {
3870
+ const getVersion = (0, import_react18.useCallback)(
3871
+ async (version) => {
3872
+ if (!workflowId) throw new Error("Workflow ID is required");
3873
+ const res = await fetchWithAuth(`/workflows/${workflowId}/versions/${version}`);
3874
+ if (!res.ok) {
3875
+ throw new Error(`Failed to fetch workflow version (${res.status}): ${res.statusText}`);
3876
+ }
3877
+ return await res.json();
3878
+ },
3879
+ [fetchWithAuth, workflowId]
3880
+ );
3881
+ const fetchMermaid = (0, import_react18.useCallback)(async () => {
3319
3882
  if (!workflowId) return "";
3320
3883
  try {
3321
3884
  const res = await fetchWithAuth(`/workflows/${workflowId}/mermaid`);
@@ -3328,18 +3891,18 @@ function useWorkflow(workflowId, options) {
3328
3891
  return "";
3329
3892
  }
3330
3893
  }, [fetchWithAuth, workflowId]);
3331
- const saveDraft = (0, import_react15.useCallback)(
3332
- async (draft) => {
3894
+ const updateWorkflow = (0, import_react18.useCallback)(
3895
+ async (input) => {
3333
3896
  if (!workflowId) throw new Error("Workflow ID is required");
3334
3897
  setError(null);
3335
- const res = await fetchWithAuth(`/workflows/${workflowId}/draft`, {
3336
- method: "POST",
3898
+ const res = await fetchWithAuth(`/workflows/${workflowId}`, {
3899
+ method: "PATCH",
3337
3900
  headers: { "Content-Type": "application/json" },
3338
- body: JSON.stringify({ draft })
3901
+ body: JSON.stringify(input)
3339
3902
  });
3340
3903
  if (!res.ok) {
3341
3904
  const errText = await res.text().catch(() => res.statusText);
3342
- throw new Error(`Failed to save draft (${res.status}): ${errText}`);
3905
+ throw new Error(`Failed to update workflow (${res.status}): ${errText}`);
3343
3906
  }
3344
3907
  const updated = await res.json();
3345
3908
  setWorkflow(updated);
@@ -3347,27 +3910,41 @@ function useWorkflow(workflowId, options) {
3347
3910
  },
3348
3911
  [fetchWithAuth, workflowId]
3349
3912
  );
3350
- const publish = (0, import_react15.useCallback)(
3351
- async (summary) => {
3913
+ const saveDraft = (0, import_react18.useCallback)(
3914
+ async (draft) => {
3352
3915
  if (!workflowId) throw new Error("Workflow ID is required");
3353
3916
  setError(null);
3354
- const res = await fetchWithAuth(`/workflows/${workflowId}/publish`, {
3355
- method: "POST",
3917
+ const res = await fetchWithAuth(`/workflows/${workflowId}/draft`, {
3918
+ method: "PUT",
3356
3919
  headers: { "Content-Type": "application/json" },
3357
- body: JSON.stringify(summary ? { summary } : {})
3920
+ body: JSON.stringify(draft)
3358
3921
  });
3359
3922
  if (!res.ok) {
3360
3923
  const errText = await res.text().catch(() => res.statusText);
3361
- throw new Error(`Failed to publish workflow (${res.status}): ${errText}`);
3924
+ throw new Error(`Failed to save draft (${res.status}): ${errText}`);
3362
3925
  }
3363
- const versionResult = await res.json();
3364
- void fetchWorkflow();
3365
- void fetchVersions();
3366
- return versionResult;
3926
+ const updated = await res.json();
3927
+ setWorkflow(updated);
3928
+ return updated;
3367
3929
  },
3368
- [fetchWithAuth, workflowId, fetchWorkflow, fetchVersions]
3930
+ [fetchWithAuth, workflowId]
3369
3931
  );
3370
- const deleteWorkflow = (0, import_react15.useCallback)(async () => {
3932
+ const publish = (0, import_react18.useCallback)(async () => {
3933
+ if (!workflowId) throw new Error("Workflow ID is required");
3934
+ setError(null);
3935
+ const res = await fetchWithAuth(`/workflows/${workflowId}/publish`, {
3936
+ method: "POST"
3937
+ });
3938
+ if (!res.ok) {
3939
+ const errText = await res.text().catch(() => res.statusText);
3940
+ throw new Error(`Failed to publish workflow (${res.status}): ${errText}`);
3941
+ }
3942
+ const versionResult = await res.json();
3943
+ void fetchWorkflow();
3944
+ void fetchVersions();
3945
+ return versionResult;
3946
+ }, [fetchWithAuth, workflowId, fetchWorkflow, fetchVersions]);
3947
+ const deleteWorkflow = (0, import_react18.useCallback)(async () => {
3371
3948
  if (!workflowId) throw new Error("Workflow ID is required");
3372
3949
  setError(null);
3373
3950
  const res = await fetchWithAuth(`/workflows/${workflowId}`, {
@@ -3378,7 +3955,7 @@ function useWorkflow(workflowId, options) {
3378
3955
  }
3379
3956
  setWorkflow(null);
3380
3957
  }, [fetchWithAuth, workflowId]);
3381
- (0, import_react15.useEffect)(() => {
3958
+ (0, import_react18.useEffect)(() => {
3382
3959
  if (autoFetch && workflowId) {
3383
3960
  void fetchWorkflow();
3384
3961
  }
@@ -3391,7 +3968,9 @@ function useWorkflow(workflowId, options) {
3391
3968
  error,
3392
3969
  refetch: fetchWorkflow,
3393
3970
  fetchVersions,
3971
+ getVersion,
3394
3972
  fetchMermaid,
3973
+ updateWorkflow,
3395
3974
  saveDraft,
3396
3975
  publish,
3397
3976
  deleteWorkflow
@@ -3399,25 +3978,25 @@ function useWorkflow(workflowId, options) {
3399
3978
  }
3400
3979
 
3401
3980
  // src/hooks/useWorkflowStream.ts
3402
- var import_react16 = require("react");
3981
+ var import_react19 = require("react");
3403
3982
  function useWorkflowStream(workflowId, options) {
3404
3983
  const { baseUrl, getAuthToken, fetchWithAuth, logger } = usePersonaContext();
3405
- const [status, setStatus] = (0, import_react16.useState)("idle");
3406
- const [runId, setRunId] = (0, import_react16.useState)(null);
3407
- const [activeNodeId, setActiveNodeId] = (0, import_react16.useState)(null);
3408
- const [nodeRuns, setNodeRuns] = (0, import_react16.useState)(
3984
+ const [status, setStatus] = (0, import_react19.useState)("idle");
3985
+ const [runId, setRunId] = (0, import_react19.useState)(null);
3986
+ const [activeNodeId, setActiveNodeId] = (0, import_react19.useState)(null);
3987
+ const [nodeRuns, setNodeRuns] = (0, import_react19.useState)(
3409
3988
  {}
3410
3989
  );
3411
- const [text, setText] = (0, import_react16.useState)("");
3412
- const [output, setOutput] = (0, import_react16.useState)(null);
3413
- const [error, setError] = (0, import_react16.useState)(null);
3414
- const [events, setEvents] = (0, import_react16.useState)([]);
3415
- const abortControllerRef = (0, import_react16.useRef)(null);
3416
- const currentRunIdRef = (0, import_react16.useRef)(null);
3990
+ const [text, setText] = (0, import_react19.useState)("");
3991
+ const [output, setOutput] = (0, import_react19.useState)(null);
3992
+ const [error, setError] = (0, import_react19.useState)(null);
3993
+ const [events, setEvents] = (0, import_react19.useState)([]);
3994
+ const abortControllerRef = (0, import_react19.useRef)(null);
3995
+ const currentRunIdRef = (0, import_react19.useRef)(null);
3417
3996
  currentRunIdRef.current = runId;
3418
- const optionsRef = (0, import_react16.useRef)(options);
3997
+ const optionsRef = (0, import_react19.useRef)(options);
3419
3998
  optionsRef.current = options;
3420
- const cancel = (0, import_react16.useCallback)(async () => {
3999
+ const cancel = (0, import_react19.useCallback)(async () => {
3421
4000
  if (abortControllerRef.current) {
3422
4001
  abortControllerRef.current.abort();
3423
4002
  abortControllerRef.current = null;
@@ -3438,7 +4017,7 @@ function useWorkflowStream(workflowId, options) {
3438
4017
  setStatus("cancelled");
3439
4018
  setActiveNodeId(null);
3440
4019
  }, [fetchWithAuth, logger]);
3441
- const reset = (0, import_react16.useCallback)(() => {
4020
+ const reset = (0, import_react19.useCallback)(() => {
3442
4021
  if (abortControllerRef.current) {
3443
4022
  abortControllerRef.current.abort();
3444
4023
  abortControllerRef.current = null;
@@ -3452,7 +4031,7 @@ function useWorkflowStream(workflowId, options) {
3452
4031
  setError(null);
3453
4032
  setEvents([]);
3454
4033
  }, []);
3455
- const processStream = (0, import_react16.useCallback)(
4034
+ const processStream = (0, import_react19.useCallback)(
3456
4035
  async (url, method, body, targetRunId) => {
3457
4036
  if (abortControllerRef.current) {
3458
4037
  abortControllerRef.current.abort();
@@ -3617,7 +4196,7 @@ function useWorkflowStream(workflowId, options) {
3617
4196
  },
3618
4197
  [getAuthToken]
3619
4198
  );
3620
- const start = (0, import_react16.useCallback)(
4199
+ const start = (0, import_react19.useCallback)(
3621
4200
  async (input, opts) => {
3622
4201
  const targetWfId = opts?.workflowId || workflowId;
3623
4202
  if (!targetWfId) {
@@ -3638,7 +4217,7 @@ function useWorkflowStream(workflowId, options) {
3638
4217
  },
3639
4218
  [workflowId, baseUrl, processStream]
3640
4219
  );
3641
- const resume = (0, import_react16.useCallback)(
4220
+ const resume = (0, import_react19.useCallback)(
3642
4221
  async (targetRunId, sinceSeq) => {
3643
4222
  if (!targetRunId) {
3644
4223
  throw new Error("Run ID is required to resume stream");
@@ -3651,7 +4230,7 @@ function useWorkflowStream(workflowId, options) {
3651
4230
  },
3652
4231
  [baseUrl, processStream]
3653
4232
  );
3654
- (0, import_react16.useEffect)(() => {
4233
+ (0, import_react19.useEffect)(() => {
3655
4234
  return () => {
3656
4235
  if (abortControllerRef.current) {
3657
4236
  abortControllerRef.current.abort();
@@ -3676,21 +4255,21 @@ function useWorkflowStream(workflowId, options) {
3676
4255
  }
3677
4256
 
3678
4257
  // src/hooks/useWorkflowRuns.ts
3679
- var import_react17 = require("react");
4258
+ var import_react20 = require("react");
3680
4259
  function useWorkflowRuns(workflowId, options) {
3681
4260
  const opts = typeof options === "boolean" ? { autoFetch: options } : options ?? {};
3682
4261
  const { autoFetch = true, page = 1, limit = 20 } = opts;
3683
4262
  const { fetchWithAuth } = usePersonaContext();
3684
- const [runs, setRuns] = (0, import_react17.useState)([]);
3685
- const [pagination, setPagination] = (0, import_react17.useState)({
4263
+ const [runs, setRuns] = (0, import_react20.useState)([]);
4264
+ const [pagination, setPagination] = (0, import_react20.useState)({
3686
4265
  page,
3687
4266
  limit,
3688
4267
  total: 0,
3689
4268
  totalPages: 0
3690
4269
  });
3691
- const [isLoading, setIsLoading] = (0, import_react17.useState)(false);
3692
- const [error, setError] = (0, import_react17.useState)(null);
3693
- const fetchRuns = (0, import_react17.useCallback)(async () => {
4270
+ const [isLoading, setIsLoading] = (0, import_react20.useState)(false);
4271
+ const [error, setError] = (0, import_react20.useState)(null);
4272
+ const fetchRuns = (0, import_react20.useCallback)(async () => {
3694
4273
  if (!workflowId) return [];
3695
4274
  setIsLoading(true);
3696
4275
  setError(null);
@@ -3701,14 +4280,16 @@ function useWorkflowRuns(workflowId, options) {
3701
4280
  throw new Error(`Failed to list workflow runs: ${res.statusText}`);
3702
4281
  }
3703
4282
  const data = await res.json();
3704
- const items = Array.isArray(data) ? data : data?.items || data?.runs || [];
4283
+ const items = Array.isArray(data) ? data : data?.items ?? [];
3705
4284
  setRuns(items);
3706
4285
  if (data?.pagination) {
3707
4286
  setPagination({
3708
4287
  page: data.pagination.page ?? page,
3709
4288
  limit: data.pagination.limit ?? limit,
3710
4289
  total: data.pagination.total ?? items.length,
3711
- totalPages: data.pagination.totalPages ?? 1
4290
+ // Backend's paginationEnvelope() names this field `pages`, not
4291
+ // `totalPages`.
4292
+ totalPages: data.pagination.pages ?? 1
3712
4293
  });
3713
4294
  }
3714
4295
  return items;
@@ -3720,7 +4301,7 @@ function useWorkflowRuns(workflowId, options) {
3720
4301
  setIsLoading(false);
3721
4302
  }
3722
4303
  }, [fetchWithAuth, workflowId, page, limit]);
3723
- const getRun = (0, import_react17.useCallback)(
4304
+ const getRun = (0, import_react20.useCallback)(
3724
4305
  async (runId) => {
3725
4306
  if (!runId) throw new Error("Run ID is required");
3726
4307
  const res = await fetchWithAuth(`/workflows/runs/${runId}`);
@@ -3731,7 +4312,7 @@ function useWorkflowRuns(workflowId, options) {
3731
4312
  },
3732
4313
  [fetchWithAuth]
3733
4314
  );
3734
- const cancelRun = (0, import_react17.useCallback)(
4315
+ const cancelRun = (0, import_react20.useCallback)(
3735
4316
  async (runId) => {
3736
4317
  if (!runId) throw new Error("Run ID is required");
3737
4318
  const res = await fetchWithAuth(`/workflows/runs/${runId}/cancel`, {
@@ -3746,7 +4327,7 @@ function useWorkflowRuns(workflowId, options) {
3746
4327
  },
3747
4328
  [fetchWithAuth]
3748
4329
  );
3749
- (0, import_react17.useEffect)(() => {
4330
+ (0, import_react20.useEffect)(() => {
3750
4331
  if (autoFetch && workflowId) {
3751
4332
  void fetchRuns();
3752
4333
  }
@@ -3782,7 +4363,9 @@ var VERSION = "0.10.0";
3782
4363
  useChat,
3783
4364
  useConnection,
3784
4365
  useFiles,
4366
+ useKnowledgeBases,
3785
4367
  useMcp,
4368
+ useMcpAdmin,
3786
4369
  useMcpConnections,
3787
4370
  useMemory,
3788
4371
  usePersonaContext,
@@ -3793,6 +4376,7 @@ var VERSION = "0.10.0";
3793
4376
  useWorkflow,
3794
4377
  useWorkflowRuns,
3795
4378
  useWorkflowStream,
3796
- useWorkflows
4379
+ useWorkflows,
4380
+ useWorkspaceFiles
3797
4381
  });
3798
4382
  //# sourceMappingURL=index.cjs.map